Mercurial > repos > blastem
comparison vdp.c @ 1643:6909c5d0bbb5
Removed old VDP debug functionality
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Mon, 19 Nov 2018 19:26:57 -0800 |
parents | c6b2c0f8cc61 |
children | cf4e387a8db6 |
comparison
equal
deleted
inserted
replaced
1642:c6b2c0f8cc61 | 1643:6909c5d0bbb5 |
---|---|
1300 { | 1300 { |
1301 col-=2; | 1301 col-=2; |
1302 dst = context->output + BORDER_LEFT + col * 8; | 1302 dst = context->output + BORDER_LEFT + col * 8; |
1303 debug_dst = context->layer_debug_buf + BORDER_LEFT + col * 8; | 1303 debug_dst = context->layer_debug_buf + BORDER_LEFT + col * 8; |
1304 | 1304 |
1305 if (context->debug < 2) { | 1305 sprite_buf = context->linebuf + col * 8; |
1306 sprite_buf = context->linebuf + col * 8; | 1306 uint8_t a_src, src; |
1307 uint8_t a_src, src; | 1307 if (context->flags & FLAG_WINDOW) { |
1308 if (context->flags & FLAG_WINDOW) { | 1308 plane_a_off = context->buf_a_off; |
1309 plane_a_off = context->buf_a_off; | 1309 a_src = DBG_SRC_W; |
1310 a_src = DBG_SRC_W; | 1310 } else { |
1311 } else { | 1311 plane_a_off = context->buf_a_off - (context->hscroll_a & 0xF); |
1312 plane_a_off = context->buf_a_off - (context->hscroll_a & 0xF); | 1312 a_src = DBG_SRC_A; |
1313 a_src = DBG_SRC_A; | 1313 } |
1314 } | 1314 plane_b_off = context->buf_b_off - (context->hscroll_b & 0xF); |
1315 plane_b_off = context->buf_b_off - (context->hscroll_b & 0xF); | 1315 //printf("A | tmp_buf offset: %d\n", 8 - (context->hscroll_a & 0x7)); |
1316 //printf("A | tmp_buf offset: %d\n", 8 - (context->hscroll_a & 0x7)); | 1316 |
1317 | 1317 if (context->regs[REG_MODE_4] & BIT_HILIGHT) { |
1318 if (context->regs[REG_MODE_4] & BIT_HILIGHT) { | 1318 for (int i = 0; i < 16; ++plane_a_off, ++plane_b_off, ++sprite_buf, ++i) { |
1319 for (int i = 0; i < 16; ++plane_a_off, ++plane_b_off, ++sprite_buf, ++i) { | 1319 plane_a = context->tmp_buf_a + (plane_a_off & SCROLL_BUFFER_MASK); |
1320 plane_a = context->tmp_buf_a + (plane_a_off & SCROLL_BUFFER_MASK); | 1320 plane_b = context->tmp_buf_b + (plane_b_off & SCROLL_BUFFER_MASK); |
1321 plane_b = context->tmp_buf_b + (plane_b_off & SCROLL_BUFFER_MASK); | 1321 uint8_t pixel = context->regs[REG_BG_COLOR]; |
1322 uint8_t pixel = context->regs[REG_BG_COLOR]; | 1322 uint32_t *colors = context->colors; |
1323 uint32_t *colors = context->colors; | 1323 src = DBG_SRC_BG; |
1324 src = DBG_SRC_BG; | 1324 uint8_t intensity = 0; |
1325 uint8_t intensity = 0; | 1325 if (col || !(context->regs[REG_MODE_1] & BIT_COL0_MASK) || i >= 8) { |
1326 if (*plane_b & 0xF) { | |
1327 pixel = *plane_b; | |
1328 src = DBG_SRC_B; | |
1329 } | |
1330 intensity = *plane_b & BUF_BIT_PRIORITY; | |
1331 if (*plane_a & 0xF && (*plane_a & BUF_BIT_PRIORITY) >= (pixel & BUF_BIT_PRIORITY)) { | |
1332 pixel = *plane_a; | |
1333 src = a_src; | |
1334 } | |
1335 intensity |= *plane_a & BUF_BIT_PRIORITY; | |
1336 if (*sprite_buf & 0xF && (*sprite_buf & BUF_BIT_PRIORITY) >= (pixel & BUF_BIT_PRIORITY)) { | |
1337 if ((*sprite_buf & 0x3F) == 0x3E) { | |
1338 intensity += BUF_BIT_PRIORITY; | |
1339 } else if ((*sprite_buf & 0x3F) == 0x3F) { | |
1340 intensity = 0; | |
1341 } else { | |
1342 pixel = *sprite_buf; | |
1343 src = DBG_SRC_S; | |
1344 if ((pixel & 0xF) == 0xE) { | |
1345 intensity = BUF_BIT_PRIORITY; | |
1346 } else { | |
1347 intensity |= pixel & BUF_BIT_PRIORITY; | |
1348 } | |
1349 } | |
1350 } | |
1351 } | |
1352 if (output_disabled) { | |
1353 pixel = 0x3F; | |
1354 } | |
1355 if (!intensity) { | |
1356 src |= DBG_SHADOW; | |
1357 colors += CRAM_SIZE; | |
1358 } else if (intensity == BUF_BIT_PRIORITY*2) { | |
1359 src |= DBG_HILIGHT; | |
1360 colors += CRAM_SIZE*2; | |
1361 } | |
1362 //TODO: Verify how test register stuff interacts with shadow/highlight | |
1363 //TODO: Simulate CRAM corruption from bus fight | |
1364 switch (test_layer) | |
1365 { | |
1366 case 1: | |
1367 pixel &= *sprite_buf; | |
1368 if (output_disabled && pixel) { | |
1369 src = DBG_SRC_S; | |
1370 } | |
1371 break; | |
1372 case 2: | |
1373 pixel &= *plane_a; | |
1374 if (output_disabled && pixel) { | |
1375 src = DBG_SRC_A; | |
1376 } | |
1377 break; | |
1378 case 3: | |
1379 pixel &= *plane_b; | |
1380 if (output_disabled && pixel) { | |
1381 src = DBG_SRC_B; | |
1382 } | |
1383 break; | |
1384 } | |
1385 *(debug_dst++) = src; | |
1386 *(dst++) = colors[pixel & 0x3F]; | |
1387 } | |
1388 } else { | |
1389 for (int i = 0; i < 16; ++plane_a_off, ++plane_b_off, ++sprite_buf, ++i) { | |
1390 plane_a = context->tmp_buf_a + (plane_a_off & SCROLL_BUFFER_MASK); | |
1391 plane_b = context->tmp_buf_b + (plane_b_off & SCROLL_BUFFER_MASK); | |
1392 uint8_t pixel = context->regs[REG_BG_COLOR]; | |
1393 src = DBG_SRC_BG; | |
1394 if (output_disabled) { | |
1395 pixel = 0x3F; | |
1396 } else { | |
1326 if (col || !(context->regs[REG_MODE_1] & BIT_COL0_MASK) || i >= 8) { | 1397 if (col || !(context->regs[REG_MODE_1] & BIT_COL0_MASK) || i >= 8) { |
1327 if (*plane_b & 0xF) { | 1398 if (*plane_b & 0xF) { |
1328 pixel = *plane_b; | 1399 pixel = *plane_b; |
1329 src = DBG_SRC_B; | 1400 src = DBG_SRC_B; |
1330 } | 1401 } |
1331 intensity = *plane_b & BUF_BIT_PRIORITY; | |
1332 if (*plane_a & 0xF && (*plane_a & BUF_BIT_PRIORITY) >= (pixel & BUF_BIT_PRIORITY)) { | 1402 if (*plane_a & 0xF && (*plane_a & BUF_BIT_PRIORITY) >= (pixel & BUF_BIT_PRIORITY)) { |
1333 pixel = *plane_a; | 1403 pixel = *plane_a; |
1334 src = a_src; | 1404 src = a_src; |
1335 } | 1405 } |
1336 intensity |= *plane_a & BUF_BIT_PRIORITY; | |
1337 if (*sprite_buf & 0xF && (*sprite_buf & BUF_BIT_PRIORITY) >= (pixel & BUF_BIT_PRIORITY)) { | 1406 if (*sprite_buf & 0xF && (*sprite_buf & BUF_BIT_PRIORITY) >= (pixel & BUF_BIT_PRIORITY)) { |
1338 if ((*sprite_buf & 0x3F) == 0x3E) { | 1407 pixel = *sprite_buf; |
1339 intensity += BUF_BIT_PRIORITY; | 1408 src = DBG_SRC_S; |
1340 } else if ((*sprite_buf & 0x3F) == 0x3F) { | |
1341 intensity = 0; | |
1342 } else { | |
1343 pixel = *sprite_buf; | |
1344 src = DBG_SRC_S; | |
1345 if ((pixel & 0xF) == 0xE) { | |
1346 intensity = BUF_BIT_PRIORITY; | |
1347 } else { | |
1348 intensity |= pixel & BUF_BIT_PRIORITY; | |
1349 } | |
1350 } | |
1351 } | 1409 } |
1352 } | 1410 } |
1353 if (output_disabled) { | 1411 } |
1354 pixel = 0x3F; | 1412 //TODO: Simulate CRAM corruption from bus fight |
1413 switch (test_layer) | |
1414 { | |
1415 case 1: | |
1416 pixel &= *sprite_buf; | |
1417 if (output_disabled && pixel) { | |
1418 src = DBG_SRC_S; | |
1355 } | 1419 } |
1356 if (!intensity) { | 1420 break; |
1357 src |= DBG_SHADOW; | 1421 case 2: |
1358 colors += CRAM_SIZE; | 1422 pixel &= *plane_a; |
1359 } else if (intensity == BUF_BIT_PRIORITY*2) { | 1423 if (output_disabled && pixel) { |
1360 src |= DBG_HILIGHT; | 1424 src = DBG_SRC_A; |
1361 colors += CRAM_SIZE*2; | |
1362 } | 1425 } |
1363 //TODO: Verify how test register stuff interacts with shadow/highlight | 1426 break; |
1364 //TODO: Simulate CRAM corruption from bus fight | 1427 case 3: |
1365 switch (test_layer) | 1428 pixel &= *plane_b; |
1366 { | 1429 if (output_disabled && pixel) { |
1367 case 1: | 1430 src = DBG_SRC_B; |
1368 pixel &= *sprite_buf; | |
1369 if (output_disabled && pixel) { | |
1370 src = DBG_SRC_S; | |
1371 } | |
1372 break; | |
1373 case 2: | |
1374 pixel &= *plane_a; | |
1375 if (output_disabled && pixel) { | |
1376 src = DBG_SRC_A; | |
1377 } | |
1378 break; | |
1379 case 3: | |
1380 pixel &= *plane_b; | |
1381 if (output_disabled && pixel) { | |
1382 src = DBG_SRC_B; | |
1383 } | |
1384 break; | |
1385 } | 1431 } |
1386 *(debug_dst++) = src; | 1432 break; |
1387 *(dst++) = colors[pixel & 0x3F]; | 1433 } |
1388 } | 1434 *(dst++) = context->colors[pixel & 0x3F]; |
1389 } else { | 1435 *(debug_dst++) = src; |
1390 for (int i = 0; i < 16; ++plane_a_off, ++plane_b_off, ++sprite_buf, ++i) { | |
1391 plane_a = context->tmp_buf_a + (plane_a_off & SCROLL_BUFFER_MASK); | |
1392 plane_b = context->tmp_buf_b + (plane_b_off & SCROLL_BUFFER_MASK); | |
1393 uint8_t pixel = context->regs[REG_BG_COLOR]; | |
1394 src = DBG_SRC_BG; | |
1395 if (output_disabled) { | |
1396 pixel = 0x3F; | |
1397 } else { | |
1398 if (col || !(context->regs[REG_MODE_1] & BIT_COL0_MASK) || i >= 8) { | |
1399 if (*plane_b & 0xF) { | |
1400 pixel = *plane_b; | |
1401 src = DBG_SRC_B; | |
1402 } | |
1403 if (*plane_a & 0xF && (*plane_a & BUF_BIT_PRIORITY) >= (pixel & BUF_BIT_PRIORITY)) { | |
1404 pixel = *plane_a; | |
1405 src = a_src; | |
1406 } | |
1407 if (*sprite_buf & 0xF && (*sprite_buf & BUF_BIT_PRIORITY) >= (pixel & BUF_BIT_PRIORITY)) { | |
1408 pixel = *sprite_buf; | |
1409 src = DBG_SRC_S; | |
1410 } | |
1411 } | |
1412 } | |
1413 //TODO: Simulate CRAM corruption from bus fight | |
1414 switch (test_layer) | |
1415 { | |
1416 case 1: | |
1417 pixel &= *sprite_buf; | |
1418 if (output_disabled && pixel) { | |
1419 src = DBG_SRC_S; | |
1420 } | |
1421 break; | |
1422 case 2: | |
1423 pixel &= *plane_a; | |
1424 if (output_disabled && pixel) { | |
1425 src = DBG_SRC_A; | |
1426 } | |
1427 break; | |
1428 case 3: | |
1429 pixel &= *plane_b; | |
1430 if (output_disabled && pixel) { | |
1431 src = DBG_SRC_B; | |
1432 } | |
1433 break; | |
1434 } | |
1435 *(dst++) = context->colors[pixel & 0x3F]; | |
1436 *(debug_dst++) = src; | |
1437 } | |
1438 } | |
1439 } else if (context->debug == 2) { | |
1440 if (col < 32) { | |
1441 *(dst++) = context->colors[col * 2]; | |
1442 *(dst++) = context->colors[col * 2]; | |
1443 *(dst++) = context->colors[col * 2]; | |
1444 *(dst++) = context->colors[col * 2]; | |
1445 *(dst++) = context->colors[col * 2 + 1]; | |
1446 *(dst++) = context->colors[col * 2 + 1]; | |
1447 *(dst++) = context->colors[col * 2 + 1]; | |
1448 *(dst++) = context->colors[col * 2 + 1]; | |
1449 *(dst++) = context->colors[col * 2 + 2]; | |
1450 *(dst++) = context->colors[col * 2 + 2]; | |
1451 *(dst++) = context->colors[col * 2 + 2]; | |
1452 *(dst++) = context->colors[col * 2 + 2]; | |
1453 *(dst++) = context->colors[col * 2 + 3]; | |
1454 *(dst++) = context->colors[col * 2 + 3]; | |
1455 *(dst++) = context->colors[col * 2 + 3]; | |
1456 *(dst++) = context->colors[col * 2 + 3]; | |
1457 } else if (col == 32 || line >= 192) { | |
1458 for (int32_t i = 0; i < 16; i ++) { | |
1459 *(dst++) = 0; | |
1460 } | |
1461 } else { | |
1462 for (int32_t i = 0; i < 16; i ++) { | |
1463 *(dst++) = context->colors[line / 3 + (col - 34) * 0x20]; | |
1464 } | |
1465 } | |
1466 } else { | |
1467 uint32_t base = (context->debug - 3) * 0x200; | |
1468 uint32_t cell = base + (line / 8) * (context->regs[REG_MODE_4] & BIT_H40 ? 40 : 32) + col; | |
1469 uint32_t address = (cell * 32 + (line % 8) * 4) & 0xFFFF; | |
1470 for (int32_t i = 0; i < 4; i ++) { | |
1471 *(dst++) = context->colors[(context->debug_pal << 4) | (context->vdpmem[address] >> 4)]; | |
1472 *(dst++) = context->colors[(context->debug_pal << 4) | (context->vdpmem[address] & 0xF)]; | |
1473 address++; | |
1474 } | |
1475 cell++; | |
1476 address = (cell * 32 + (line % 8) * 4) & 0xFFFF; | |
1477 for (int32_t i = 0; i < 4; i ++) { | |
1478 *(dst++) = context->colors[(context->debug_pal << 4) | (context->vdpmem[address] >> 4)]; | |
1479 *(dst++) = context->colors[(context->debug_pal << 4) | (context->vdpmem[address] & 0xF)]; | |
1480 address++; | |
1481 } | 1436 } |
1482 } | 1437 } |
1483 } else { | 1438 } else { |
1484 dst = context->output; | 1439 dst = context->output; |
1485 debug_dst = context->layer_debug_buf; | 1440 debug_dst = context->layer_debug_buf; |
1581 } | 1536 } |
1582 context->buf_a_off = (context->buf_a_off + 8) & 15; | 1537 context->buf_a_off = (context->buf_a_off + 8) & 15; |
1583 | 1538 |
1584 uint8_t bgcolor = 0x10 | (context->regs[REG_BG_COLOR] & 0xF) + CRAM_SIZE*3; | 1539 uint8_t bgcolor = 0x10 | (context->regs[REG_BG_COLOR] & 0xF) + CRAM_SIZE*3; |
1585 uint32_t *dst = context->output + col * 8 + BORDER_LEFT; | 1540 uint32_t *dst = context->output + col * 8 + BORDER_LEFT; |
1541 uint8_t *debug_dst = context->layer_debug_buf + col * 8 + BORDER_LEFT; | |
1586 if (context->state == PREPARING) { | 1542 if (context->state == PREPARING) { |
1587 for (int i = 0; i < 16; i++) | 1543 for (int i = 0; i < 16; i++) |
1588 { | 1544 { |
1589 *(dst++) = context->colors[bgcolor]; | 1545 *(dst++) = context->colors[bgcolor]; |
1590 } | 1546 } |
1591 context->done_output = dst; | 1547 context->done_output = dst; |
1592 return; | 1548 return; |
1593 } | 1549 } |
1594 if (context->debug < 2) { | 1550 |
1595 if (col || !(context->regs[REG_MODE_1] & BIT_COL0_MASK)) { | 1551 if (col || !(context->regs[REG_MODE_1] & BIT_COL0_MASK)) { |
1596 uint8_t *sprite_src = context->linebuf + col * 8; | 1552 uint8_t *sprite_src = context->linebuf + col * 8; |
1597 if (context->regs[REG_MODE_1] & BIT_SPRITE_8PX) { | 1553 if (context->regs[REG_MODE_1] & BIT_SPRITE_8PX) { |
1598 sprite_src += 8; | 1554 sprite_src += 8; |
1599 } | 1555 } |
1600 for (int i = 0; i < 8; i++, sprite_src++) | 1556 for (int i = 0; i < 8; i++, sprite_src++) |
1601 { | 1557 { |
1602 uint8_t *bg_src = context->tmp_buf_a + ((8 + i + col * 8 - (context->hscroll_a & 0x7)) & 15); | 1558 uint8_t *bg_src = context->tmp_buf_a + ((8 + i + col * 8 - (context->hscroll_a & 0x7)) & 15); |
1603 if ((*bg_src & 0x4F) > 0x40 || !*sprite_src) { | 1559 if ((*bg_src & 0x4F) > 0x40 || !*sprite_src) { |
1604 //background plane has priority and is opaque or sprite layer is transparent | 1560 //background plane has priority and is opaque or sprite layer is transparent |
1605 if (context->debug) { | 1561 *(dst++) = context->colors[(*bg_src & 0x1F) + CRAM_SIZE*3]; |
1606 *(dst++) = context->debugcolors[DBG_SRC_A]; | 1562 *(debug_dst++) = DBG_SRC_A; |
1607 } else { | 1563 } else { |
1608 *(dst++) = context->colors[(*bg_src & 0x1F) + CRAM_SIZE*3]; | 1564 //sprite layer is opaque and not covered by high priority BG pixels |
1609 } | 1565 *(dst++) = context->colors[*sprite_src | 0x10 + CRAM_SIZE*3]; |
1610 } else { | 1566 *(debug_dst++) = DBG_SRC_S; |
1611 //sprite layer is opaque and not covered by high priority BG pixels | 1567 } |
1612 if (context->debug) { | 1568 } |
1613 *(dst++) = context->debugcolors[DBG_SRC_S]; | 1569 } else { |
1614 } else { | |
1615 *(dst++) = context->colors[*sprite_src | 0x10 + CRAM_SIZE*3]; | |
1616 } | |
1617 } | |
1618 } | |
1619 } else { | |
1620 for (int i = 0; i < 8; i++) | |
1621 { | |
1622 *(dst++) = context->colors[bgcolor]; | |
1623 } | |
1624 } | |
1625 } else if (context->debug == 2) { | |
1626 for (int i = 0; i < 8; i++) | 1570 for (int i = 0; i < 8; i++) |
1627 { | 1571 { |
1628 *(dst++) = context->colors[CRAM_SIZE*3 + col]; | 1572 *(dst++) = context->colors[bgcolor]; |
1629 } | 1573 *(debug_dst++) = DBG_SRC_BG; |
1630 } else { | |
1631 uint32_t cell = (line / 8) * 32 + col; | |
1632 uint32_t address = cell * 32 + (line % 8) * 4; | |
1633 uint32_t m4_address = mode4_address_map[address & 0x3FFF]; | |
1634 uint32_t pixel = planar_to_chunky[context->vdpmem[m4_address]] << 1; | |
1635 pixel |= planar_to_chunky[context->vdpmem[m4_address + 1]]; | |
1636 m4_address = mode4_address_map[(address + 2) & 0x3FFF]; | |
1637 pixel |= planar_to_chunky[context->vdpmem[m4_address]] << 3; | |
1638 pixel |= planar_to_chunky[context->vdpmem[m4_address + 1]] << 2; | |
1639 if (context->debug_pal < 2) { | |
1640 for (int i = 28; i >= 0; i -= 4) | |
1641 { | |
1642 *(dst++) = context->colors[CRAM_SIZE*3 | (context->debug_pal << 4) | (pixel >> i & 0xF)]; | |
1643 } | |
1644 } else { | |
1645 for (int i = 28; i >= 0; i -= 4) | |
1646 { | |
1647 uint8_t value = (pixel >> i & 0xF) * 17; | |
1648 if (context->debug_pal == 3) { | |
1649 value = 255 - value; | |
1650 } | |
1651 *(dst++) = render_map_color(value, value, value); | |
1652 } | |
1653 } | 1574 } |
1654 } | 1575 } |
1655 context->done_output = dst; | 1576 context->done_output = dst; |
1656 } | 1577 } |
1657 | 1578 |
3987 | 3908 |
3988 void vdp_inc_debug_mode(vdp_context *context) | 3909 void vdp_inc_debug_mode(vdp_context *context) |
3989 { | 3910 { |
3990 uint8_t active = render_get_active_framebuffer(); | 3911 uint8_t active = render_get_active_framebuffer(); |
3991 if (active < FRAMEBUFFER_USER_START) { | 3912 if (active < FRAMEBUFFER_USER_START) { |
3992 context->debug++; | |
3993 if (context->debug == 7) { | |
3994 context->debug = 0; | |
3995 } | |
3996 return; | 3913 return; |
3997 } | 3914 } |
3998 for (int i = 0; i < VDP_NUM_DEBUG_TYPES; i++) | 3915 for (int i = 0; i < VDP_NUM_DEBUG_TYPES; i++) |
3999 { | 3916 { |
4000 if (context->enabled_debuggers & (1 << i) && context->debug_fb_indices[i] == active) { | 3917 if (context->enabled_debuggers & (1 << i) && context->debug_fb_indices[i] == active) { |