Mercurial > repos > blastem
comparison vdp.c @ 923:8e012ece95c1
Perform the same slot mapping shift for H32 mode as I did for H40
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Tue, 02 Feb 2016 18:24:15 -0800 |
parents | 913a6336ce20 |
children | 1b86268a4cb3 |
comparison
equal
deleted
inserted
replaced
922:913a6336ce20 | 923:8e012ece95c1 |
---|---|
1027 case (startcyc+6):\ | 1027 case (startcyc+6):\ |
1028 render_map_3(context);\ | 1028 render_map_3(context);\ |
1029 CHECK_LIMIT\ | 1029 CHECK_LIMIT\ |
1030 case (startcyc+7):\ | 1030 case (startcyc+7):\ |
1031 render_map_output(context->vcounter, column, context);\ | 1031 render_map_output(context->vcounter, column, context);\ |
1032 if (column == 32 && startcyc == 124) {\ | |
1033 vdp_advance_line(context);\ | |
1034 }\ | |
1035 CHECK_LIMIT | 1032 CHECK_LIMIT |
1036 | 1033 |
1037 #define SPRITE_RENDER_H40(slot) \ | 1034 #define SPRITE_RENDER_H40(slot) \ |
1038 case slot:\ | 1035 case slot:\ |
1039 render_sprite_cells( context);\ | 1036 render_sprite_cells( context);\ |
1234 uint32_t const slot_cycles = MCLKS_SLOT_H32; | 1231 uint32_t const slot_cycles = MCLKS_SLOT_H32; |
1235 switch(context->hslot) | 1232 switch(context->hslot) |
1236 { | 1233 { |
1237 for (;;) | 1234 for (;;) |
1238 { | 1235 { |
1236 //sprite attribute table scan starts | |
1239 case 132: | 1237 case 132: |
1240 external_slot(context); | |
1241 CHECK_LIMIT | |
1242 case 133: | |
1243 external_slot(context); | |
1244 CHECK_LIMIT | |
1245 //sprite render to line buffer starts | |
1246 case 134: | |
1247 context->cur_slot = MAX_DRAWS_H32-1; | |
1248 memset(context->linebuf, 0, LINEBUF_SIZE); | |
1249 if (context->vcounter == 0x1FF) { | |
1250 external_slot(context); | |
1251 } else { | |
1252 render_sprite_cells(context); | |
1253 } | |
1254 CHECK_LIMIT | |
1255 case 135: | |
1256 if (context->vcounter == 0x1FF) { | |
1257 external_slot(context); | |
1258 } else { | |
1259 render_sprite_cells(context); | |
1260 } | |
1261 CHECK_LIMIT | |
1262 case 136: | |
1263 if (context->vcounter == 0x1FF) { | |
1264 external_slot(context); | |
1265 } else { | |
1266 render_sprite_cells(context); | |
1267 } | |
1268 CHECK_LIMIT | |
1269 case 137: | |
1270 if (context->vcounter == 0x1FF) { | |
1271 external_slot(context); | |
1272 } else { | |
1273 render_sprite_cells(context); | |
1274 if (context->vcounter == (context->latched_mode & BIT_PAL ? PAL_INACTIVE_START : NTSC_INACTIVE_START)) { | |
1275 context->hslot++; | |
1276 context->cycles += slot_cycles; | |
1277 return; | |
1278 } | |
1279 } | |
1280 CHECK_LIMIT | |
1281 //sprite attribute table scan starts | |
1282 case 138: | |
1283 context->sprite_index = 0x80; | 1238 context->sprite_index = 0x80; |
1284 context->slot_counter = MAX_SPRITES_LINE_H32; | 1239 context->slot_counter = MAX_SPRITES_LINE_H32; |
1285 render_sprite_cells( context); | 1240 render_sprite_cells( context); |
1286 scan_sprite_table(context->vcounter, context); | 1241 scan_sprite_table(context->vcounter, context); |
1287 CHECK_LIMIT | 1242 CHECK_LIMIT |
1243 SPRITE_RENDER_H32(133) | |
1244 SPRITE_RENDER_H32(134) | |
1245 SPRITE_RENDER_H32(135) | |
1246 SPRITE_RENDER_H32(136) | |
1247 SPRITE_RENDER_H32(137) | |
1248 SPRITE_RENDER_H32(138) | |
1288 SPRITE_RENDER_H32(139) | 1249 SPRITE_RENDER_H32(139) |
1289 SPRITE_RENDER_H32(140) | 1250 SPRITE_RENDER_H32(140) |
1290 SPRITE_RENDER_H32(141) | 1251 SPRITE_RENDER_H32(141) |
1291 SPRITE_RENDER_H32(142) | 1252 case 142: |
1253 external_slot(context); | |
1254 CHECK_LIMIT | |
1292 SPRITE_RENDER_H32(143) | 1255 SPRITE_RENDER_H32(143) |
1293 SPRITE_RENDER_H32(144) | 1256 SPRITE_RENDER_H32(144) |
1294 SPRITE_RENDER_H32(145) | 1257 SPRITE_RENDER_H32(145) |
1295 SPRITE_RENDER_H32(146) | 1258 SPRITE_RENDER_H32(146) |
1296 SPRITE_RENDER_H32(147) | 1259 SPRITE_RENDER_H32(147) |
1297 case 233: | 1260 //HSYNC start |
1298 external_slot(context); | 1261 SPRITE_RENDER_H32(233) |
1299 CHECK_LIMIT | |
1300 SPRITE_RENDER_H32(234) | 1262 SPRITE_RENDER_H32(234) |
1301 SPRITE_RENDER_H32(235) | 1263 SPRITE_RENDER_H32(235) |
1302 SPRITE_RENDER_H32(236) | 1264 SPRITE_RENDER_H32(236) |
1303 SPRITE_RENDER_H32(237) | 1265 SPRITE_RENDER_H32(237) |
1304 SPRITE_RENDER_H32(238) | 1266 SPRITE_RENDER_H32(238) |
1305 //HSYNC start | |
1306 SPRITE_RENDER_H32(239) | 1267 SPRITE_RENDER_H32(239) |
1307 SPRITE_RENDER_H32(240) | 1268 case 240: |
1308 SPRITE_RENDER_H32(241) | 1269 external_slot(context); |
1270 CHECK_LIMIT | |
1271 case 241: | |
1272 address = (context->regs[REG_HSCROLL] & 0x3F) << 10; | |
1273 mask = 0; | |
1274 if (context->regs[REG_MODE_3] & 0x2) { | |
1275 mask |= 0xF8; | |
1276 } | |
1277 if (context->regs[REG_MODE_3] & 0x1) { | |
1278 mask |= 0x7; | |
1279 } | |
1280 address += (context->vcounter & mask) * 4; | |
1281 context->hscroll_a = context->vdpmem[address] << 8 | context->vdpmem[address+1]; | |
1282 context->hscroll_b = context->vdpmem[address+2] << 8 | context->vdpmem[address+3]; | |
1283 //printf("%d: HScroll A: %d, HScroll B: %d\n", context->vcounter, context->hscroll_a, context->hscroll_b); | |
1284 CHECK_LIMIT | |
1309 SPRITE_RENDER_H32(242) | 1285 SPRITE_RENDER_H32(242) |
1310 SPRITE_RENDER_H32(243) | 1286 SPRITE_RENDER_H32(243) |
1311 SPRITE_RENDER_H32(244) | 1287 SPRITE_RENDER_H32(244) |
1312 SPRITE_RENDER_H32(245) | 1288 SPRITE_RENDER_H32(245) |
1289 //!HSYNC high | |
1313 case 246: | 1290 case 246: |
1314 external_slot(context); | |
1315 CHECK_LIMIT | |
1316 case 247: | |
1317 address = (context->regs[REG_HSCROLL] & 0x3F) << 10; | |
1318 mask = 0; | |
1319 if (context->regs[REG_MODE_3] & 0x2) { | |
1320 mask |= 0xF8; | |
1321 } | |
1322 if (context->regs[REG_MODE_3] & 0x1) { | |
1323 mask |= 0x7; | |
1324 } | |
1325 address += (context->vcounter & mask) * 4; | |
1326 context->hscroll_a = context->vdpmem[address] << 8 | context->vdpmem[address+1]; | |
1327 context->hscroll_b = context->vdpmem[address+2] << 8 | context->vdpmem[address+3]; | |
1328 //printf("%d: HScroll A: %d, HScroll B: %d\n", context->vcounter, context->hscroll_a, context->hscroll_b); | |
1329 CHECK_LIMIT | |
1330 SPRITE_RENDER_H32(248) | |
1331 SPRITE_RENDER_H32(249) | |
1332 SPRITE_RENDER_H32(250) | |
1333 SPRITE_RENDER_H32(251) | |
1334 //!HSYNC high | |
1335 case 252: | |
1336 read_map_scroll_a(0, context->vcounter, context); | 1291 read_map_scroll_a(0, context->vcounter, context); |
1337 CHECK_LIMIT | 1292 CHECK_LIMIT |
1338 SPRITE_RENDER_H32(253) | 1293 SPRITE_RENDER_H32(247) |
1339 case 254: | 1294 case 248: |
1340 render_map_1(context); | 1295 render_map_1(context); |
1341 scan_sprite_table(context->vcounter, context);//Just a guess | 1296 scan_sprite_table(context->vcounter, context);//Just a guess |
1342 CHECK_LIMIT | 1297 CHECK_LIMIT |
1343 case 255: | 1298 case 249: |
1344 render_map_2(context); | 1299 render_map_2(context); |
1345 scan_sprite_table(context->vcounter, context);//Just a guess | 1300 scan_sprite_table(context->vcounter, context);//Just a guess |
1346 if (context->flags & FLAG_DMA_RUN) { run_dma_src(context, context->hslot); } | 1301 CHECK_LIMIT |
1347 context->cycles += slot_cycles; | 1302 case 250: |
1348 context->hslot = 0; | |
1349 CHECK_ONLY | |
1350 case 0: | |
1351 read_map_scroll_b(0, context->vcounter, context); | 1303 read_map_scroll_b(0, context->vcounter, context); |
1352 CHECK_LIMIT | 1304 CHECK_LIMIT |
1353 case 1: | 1305 case 251: |
1354 render_sprite_cells(context); | 1306 render_sprite_cells(context); |
1355 scan_sprite_table(context->vcounter, context); | 1307 scan_sprite_table(context->vcounter, context); |
1356 CHECK_LIMIT | 1308 CHECK_LIMIT |
1357 case 2: | 1309 case 252: |
1358 render_map_3(context); | 1310 render_map_3(context); |
1359 scan_sprite_table(context->vcounter, context);//Just a guess | 1311 scan_sprite_table(context->vcounter, context);//Just a guess |
1360 CHECK_LIMIT | 1312 CHECK_LIMIT |
1361 case 3: | 1313 case 253: |
1362 render_map_output(context->vcounter, 0, context); | 1314 render_map_output(context->vcounter, 0, context); |
1363 scan_sprite_table(context->vcounter, context);//Just a guess | 1315 scan_sprite_table(context->vcounter, context);//Just a guess |
1364 //reverse context slot counter so it counts the number of sprite slots | 1316 //reverse context slot counter so it counts the number of sprite slots |
1365 //filled rather than the number of available slots | 1317 //filled rather than the number of available slots |
1366 //context->slot_counter = MAX_SPRITES_LINE - context->slot_counter; | 1318 //context->slot_counter = MAX_SPRITES_LINE - context->slot_counter; |
1367 context->cur_slot = MAX_SPRITES_LINE_H32-1; | 1319 context->cur_slot = MAX_SPRITES_LINE_H32-1; |
1368 context->sprite_draws = MAX_DRAWS_H32; | 1320 context->sprite_draws = MAX_DRAWS_H32; |
1369 context->flags &= (~FLAG_CAN_MASK & ~FLAG_MASKED); | 1321 context->flags &= (~FLAG_CAN_MASK & ~FLAG_MASKED); |
1370 CHECK_LIMIT | 1322 CHECK_LIMIT |
1371 COLUMN_RENDER_BLOCK(2, 4) | 1323 COLUMN_RENDER_BLOCK(2, 254) |
1372 COLUMN_RENDER_BLOCK(4, 12) | 1324 COLUMN_RENDER_BLOCK(4, 6) |
1373 COLUMN_RENDER_BLOCK(6, 20) | 1325 COLUMN_RENDER_BLOCK(6, 14) |
1374 COLUMN_RENDER_BLOCK_REFRESH(8, 28) | 1326 COLUMN_RENDER_BLOCK_REFRESH(8, 22) |
1375 COLUMN_RENDER_BLOCK(10, 36) | 1327 COLUMN_RENDER_BLOCK(10, 30) |
1376 COLUMN_RENDER_BLOCK(12, 44) | 1328 COLUMN_RENDER_BLOCK(12, 38) |
1377 COLUMN_RENDER_BLOCK(14, 52) | 1329 COLUMN_RENDER_BLOCK(14, 46) |
1378 COLUMN_RENDER_BLOCK_REFRESH(16, 60) | 1330 COLUMN_RENDER_BLOCK_REFRESH(16, 54) |
1379 COLUMN_RENDER_BLOCK(18, 68) | 1331 COLUMN_RENDER_BLOCK(18, 62) |
1380 COLUMN_RENDER_BLOCK(20, 76) | 1332 COLUMN_RENDER_BLOCK(20, 70) |
1381 COLUMN_RENDER_BLOCK(22, 84) | 1333 COLUMN_RENDER_BLOCK(22, 78) |
1382 COLUMN_RENDER_BLOCK_REFRESH(24, 92) | 1334 COLUMN_RENDER_BLOCK_REFRESH(24, 86) |
1383 COLUMN_RENDER_BLOCK(26, 100) | 1335 COLUMN_RENDER_BLOCK(26, 94) |
1384 COLUMN_RENDER_BLOCK(28, 108) | 1336 COLUMN_RENDER_BLOCK(28, 102) |
1385 COLUMN_RENDER_BLOCK(30, 116) | 1337 COLUMN_RENDER_BLOCK(30, 110) |
1386 COLUMN_RENDER_BLOCK_REFRESH(32, 124) | 1338 COLUMN_RENDER_BLOCK_REFRESH(32, 118) |
1339 case 126: | |
1340 external_slot(context); | |
1341 CHECK_LIMIT | |
1342 case 127: | |
1343 external_slot(context); | |
1344 CHECK_LIMIT | |
1345 //sprite render to line buffer starts | |
1346 case 128: | |
1347 context->cur_slot = MAX_DRAWS_H32-1; | |
1348 memset(context->linebuf, 0, LINEBUF_SIZE); | |
1349 render_sprite_cells(context); | |
1350 CHECK_LIMIT | |
1351 case 129: | |
1352 render_sprite_cells(context); | |
1353 CHECK_LIMIT | |
1354 case 130: | |
1355 render_sprite_cells(context); | |
1356 CHECK_LIMIT | |
1357 case 131: | |
1358 render_sprite_cells(context); | |
1359 vdp_advance_line(context); | |
1360 if (context->vcounter == (context->latched_mode & BIT_PAL ? PAL_INACTIVE_START : NTSC_INACTIVE_START)) { | |
1361 context->hslot++; | |
1362 context->cycles += slot_cycles; | |
1363 return; | |
1364 } | |
1365 CHECK_LIMIT | |
1387 } | 1366 } |
1388 default: | 1367 default: |
1389 context->hslot++; | 1368 context->hslot++; |
1390 context->cycles += MCLKS_SLOT_H32; | 1369 context->cycles += MCLKS_SLOT_H32; |
1391 } | 1370 } |
1427 { | 1406 { |
1428 uint32_t inactive_start = context->latched_mode & BIT_PAL ? PAL_INACTIVE_START : NTSC_INACTIVE_START; | 1407 uint32_t inactive_start = context->latched_mode & BIT_PAL ? PAL_INACTIVE_START : NTSC_INACTIVE_START; |
1429 //line 0x1FF is basically active even though it's not displayed | 1408 //line 0x1FF is basically active even though it's not displayed |
1430 uint8_t active_slot = context->vcounter < inactive_start || context->vcounter == 0x1FF; | 1409 uint8_t active_slot = context->vcounter < inactive_start || context->vcounter == 0x1FF; |
1431 uint8_t is_h40 = context->regs[REG_MODE_4] & BIT_H40; | 1410 uint8_t is_h40 = context->regs[REG_MODE_4] & BIT_H40; |
1432 if (context->vcounter == inactive_start) { | |
1433 if (!is_h40) { | |
1434 //the first inactive line behaves as an active one for the first few slots | |
1435 if (context->hslot > LINE_CHANGE_H32 && context->hslot < 138) { | |
1436 active_slot = 1; | |
1437 } | |
1438 } | |
1439 } | |
1440 if (context->regs[REG_MODE_2] & DISPLAY_ENABLE && active_slot) { | 1411 if (context->regs[REG_MODE_2] & DISPLAY_ENABLE && active_slot) { |
1441 if (is_h40) { | 1412 if (is_h40) { |
1442 vdp_h40(context, target_cycles); | 1413 vdp_h40(context, target_cycles); |
1443 } else { | 1414 } else { |
1444 vdp_h32(context, target_cycles); | 1415 vdp_h32(context, target_cycles); |
1451 } else if (context->hslot == 165) { | 1422 } else if (context->hslot == 165) { |
1452 context->sprite_index = 0x80; | 1423 context->sprite_index = 0x80; |
1453 context->slot_counter = MAX_SPRITES_LINE; | 1424 context->slot_counter = MAX_SPRITES_LINE; |
1454 } | 1425 } |
1455 } else { | 1426 } else { |
1456 if (context->hslot == 134) { | 1427 if (context->hslot == 128) { |
1457 context->cur_slot = MAX_DRAWS_H32-1; | 1428 context->cur_slot = MAX_DRAWS_H32-1; |
1458 memset(context->linebuf, 0, LINEBUF_SIZE); | 1429 memset(context->linebuf, 0, LINEBUF_SIZE); |
1459 } else if (context->hslot == 138) { | 1430 } else if (context->hslot == 132) { |
1460 context->sprite_index = 0x80; | 1431 context->sprite_index = 0x80; |
1461 context->slot_counter = MAX_SPRITES_LINE_H32; | 1432 context->slot_counter = MAX_SPRITES_LINE_H32; |
1462 } | 1433 } |
1463 } | 1434 } |
1464 if(context->vcounter == inactive_start) { | 1435 if(context->vcounter == inactive_start) { |
1489 if (context->flags & FLAG_DMA_RUN && !is_refresh(context, context->hslot)) { | 1460 if (context->flags & FLAG_DMA_RUN && !is_refresh(context, context->hslot)) { |
1490 run_dma_src(context, context->hslot); | 1461 run_dma_src(context, context->hslot); |
1491 } | 1462 } |
1492 context->cycles += inccycles; | 1463 context->cycles += inccycles; |
1493 context->hslot++; | 1464 context->hslot++; |
1494 context->hslot &= 0xFF; | |
1495 if (is_h40) { | 1465 if (is_h40) { |
1496 if (context->hslot == LINE_CHANGE_H40) { | 1466 if (context->hslot == LINE_CHANGE_H40) { |
1497 vdp_advance_line(context); | 1467 vdp_advance_line(context); |
1498 if (context->vcounter == (inactive_start + 8)) { | 1468 if (context->vcounter == (inactive_start + 8)) { |
1499 context->frame++; | 1469 context->frame++; |