Mercurial > repos > blastem
comparison vdp.c @ 1655:3128d4e0bc68
Fix some rendering bugs introduced in previous VDP optimizations
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sun, 30 Dec 2018 14:43:30 -0800 |
parents | 858d52140375 |
children | 8f2e78db0872 |
comparison
equal
deleted
inserted
replaced
1654:4637ab86be8c | 1655:3128d4e0bc68 |
---|---|
1210 } | 1210 } |
1211 uint8_t pal_priority = (col >> 9) & 0x70; | 1211 uint8_t pal_priority = (col >> 9) & 0x70; |
1212 uint32_t bits = *((uint32_t *)(&context->vdpmem[address])); | 1212 uint32_t bits = *((uint32_t *)(&context->vdpmem[address])); |
1213 if (col & MAP_BIT_H_FLIP) { | 1213 if (col & MAP_BIT_H_FLIP) { |
1214 uint32_t shift = 28; | 1214 uint32_t shift = 28; |
1215 for (int i = 0; i < 8; i++) | 1215 for (int i = 0; i < 4; i++) |
1216 { | 1216 { |
1217 uint8_t right = pal_priority | ((bits >> shift) & 0xF); | |
1218 shift -= 4; | |
1217 tmp_buf[offset++] = pal_priority | ((bits >> shift) & 0xF); | 1219 tmp_buf[offset++] = pal_priority | ((bits >> shift) & 0xF); |
1218 shift -= 4; | 1220 shift -= 4; |
1221 offset &= SCROLL_BUFFER_MASK; | |
1222 tmp_buf[offset++] = right; | |
1219 offset &= SCROLL_BUFFER_MASK; | 1223 offset &= SCROLL_BUFFER_MASK; |
1220 } | 1224 } |
1221 } else { | 1225 } else { |
1222 for (int i = 0; i < 4; i++) | 1226 for (int i = 0; i < 4; i++) |
1223 { | 1227 { |
1396 break; | 1400 break; |
1397 case 1: { | 1401 case 1: { |
1398 uint8_t *sprite_buf = context->linebuf + col * 8; | 1402 uint8_t *sprite_buf = context->linebuf + col * 8; |
1399 for (int i = 0; i < 16; i++) | 1403 for (int i = 0; i < 16; i++) |
1400 { | 1404 { |
1401 *(dst++) = *(sprite_buf++); | 1405 *(dst++) = context->colors[*(sprite_buf++) & 0x3F]; |
1402 *(debug_dst++) = DBG_SRC_S; | 1406 *(debug_dst++) = DBG_SRC_S; |
1403 } | 1407 } |
1404 break; | 1408 break; |
1405 } | 1409 } |
1406 case 2: | 1410 case 2: |
1407 for (int i = 0; i < 16; i++) | 1411 for (int i = 0; i < 16; i++) |
1408 { | 1412 { |
1409 *(dst++) = context->tmp_buf_a[(plane_a_off++) & SCROLL_BUFFER_MASK]; | 1413 *(dst++) = context->colors[context->tmp_buf_a[(plane_a_off++) & SCROLL_BUFFER_MASK] & 0x3F]; |
1410 *(debug_dst++) = DBG_SRC_A; | 1414 *(debug_dst++) = DBG_SRC_A; |
1411 } | 1415 } |
1412 break; | 1416 break; |
1413 case 3: | 1417 case 3: |
1414 for (int i = 0; i < 16; i++) | 1418 for (int i = 0; i < 16; i++) |
1415 { | 1419 { |
1416 *(dst++) = context->tmp_buf_a[(plane_a_off++) & SCROLL_BUFFER_MASK]; | 1420 *(dst++) = context->colors[context->tmp_buf_b[(plane_b_off++) & SCROLL_BUFFER_MASK] & 0x3F]; |
1417 *(debug_dst++) = DBG_SRC_B; | 1421 *(debug_dst++) = DBG_SRC_B; |
1418 } | 1422 } |
1419 break; | 1423 break; |
1420 } | 1424 } |
1421 } else { | 1425 } else { |
1491 } | 1495 } |
1492 } | 1496 } |
1493 | 1497 |
1494 static void render_testreg_highlight(vdp_context *context, int32_t col, uint32_t *dst, uint8_t *debug_dst, int plane_a_off, int plane_b_off, uint8_t output_disabled, uint8_t test_layer) | 1498 static void render_testreg_highlight(vdp_context *context, int32_t col, uint32_t *dst, uint8_t *debug_dst, int plane_a_off, int plane_b_off, uint8_t output_disabled, uint8_t test_layer) |
1495 { | 1499 { |
1496 if (output_disabled) { | 1500 int start = 0; |
1497 //TODO: confirm how this behaves when shadow/highlight is enabled | 1501 uint8_t *sprite_buf = context->linebuf + col * 8; |
1498 switch (test_layer) | 1502 if (!col && (context->regs[REG_MODE_1] & BIT_COL0_MASK)) { |
1503 //TODO: Confirm how test register interacts with column 0 blanking | |
1504 uint8_t pixel = context->regs[REG_BG_COLOR] & 0x3F; | |
1505 uint8_t src = DBG_SRC_BG | DBG_SHADOW; | |
1506 for (int i = 0; i < 8; ++i) | |
1499 { | 1507 { |
1500 case 0: | |
1501 for (int i = 0; i < 16; i++) | |
1502 { | |
1503 *(dst++) = 0x3F; //TODO: confirm this on hardware | |
1504 *(debug_dst++) = DBG_SRC_BG; | |
1505 } | |
1506 break; | |
1507 case 1: { | |
1508 uint8_t *sprite_buf = context->linebuf + col * 8; | |
1509 for (int i = 0; i < 16; i++) | |
1510 { | |
1511 *(dst++) = *(sprite_buf++); | |
1512 *(debug_dst++) = DBG_SRC_S; | |
1513 } | |
1514 break; | |
1515 } | |
1516 case 2: | |
1517 for (int i = 0; i < 16; i++) | |
1518 { | |
1519 *(dst++) = context->tmp_buf_a[(plane_a_off++) & SCROLL_BUFFER_MASK]; | |
1520 *(debug_dst++) = DBG_SRC_A; | |
1521 } | |
1522 break; | |
1523 case 3: | |
1524 for (int i = 0; i < 16; i++) | |
1525 { | |
1526 *(dst++) = context->tmp_buf_a[(plane_a_off++) & SCROLL_BUFFER_MASK]; | |
1527 *(debug_dst++) = DBG_SRC_B; | |
1528 } | |
1529 break; | |
1530 } | |
1531 } else { | |
1532 int start = 0; | |
1533 uint8_t *sprite_buf = context->linebuf + col * 8; | |
1534 if (!col && (context->regs[REG_MODE_1] & BIT_COL0_MASK)) { | |
1535 //TODO: Confirm how test register interacts with column 0 blanking | |
1536 uint8_t pixel = context->regs[REG_BG_COLOR] & 0x3F; | |
1537 uint8_t src = DBG_SRC_BG | DBG_SHADOW; | |
1538 for (int i = 0; i < 8; ++i) | |
1539 { | |
1540 switch (test_layer) | |
1541 { | |
1542 case 1: | |
1543 pixel &= sprite_buf[i]; | |
1544 if (pixel) { | |
1545 src = DBG_SRC_S | DBG_SHADOW; | |
1546 } | |
1547 break; | |
1548 case 2: | |
1549 pixel &= context->tmp_buf_a[(plane_a_off + i) & SCROLL_BUFFER_MASK]; | |
1550 if (pixel) { | |
1551 src = DBG_SRC_A | DBG_SHADOW; | |
1552 } | |
1553 break; | |
1554 case 3: | |
1555 pixel &= context->tmp_buf_b[(plane_b_off + i) & SCROLL_BUFFER_MASK]; | |
1556 if (pixel) { | |
1557 src = DBG_SRC_B | DBG_SHADOW; | |
1558 } | |
1559 break; | |
1560 } | |
1561 | |
1562 *(dst++) = context->colors[SHADOW_OFFSET + (pixel & 0x3F)]; | |
1563 *(debug_dst++) = src; | |
1564 } | |
1565 plane_a_off += 8; | |
1566 plane_b_off += 8; | |
1567 sprite_buf += 8; | |
1568 start = 8; | |
1569 } | |
1570 for (int i = start; i < 16; ++plane_a_off, ++plane_b_off, ++sprite_buf, ++i) | |
1571 { | |
1572 uint8_t sprite, plane_a, plane_b; | |
1573 plane_a = context->tmp_buf_a[plane_a_off & SCROLL_BUFFER_MASK]; | |
1574 plane_b = context->tmp_buf_b[plane_b_off & SCROLL_BUFFER_MASK]; | |
1575 sprite = *sprite_buf; | |
1576 sh_pixel pixel = composite_highlight(context, debug_dst, sprite, plane_a, plane_b, 0x3F); | |
1577 uint32_t *colors; | |
1578 if (pixel.intensity == BUF_BIT_PRIORITY << 1) { | |
1579 colors = context->colors + HIGHLIGHT_OFFSET; | |
1580 } else if (pixel.intensity) { | |
1581 colors = context->colors; | |
1582 } else { | |
1583 colors = context->colors + SHADOW_OFFSET; | |
1584 } | |
1585 switch (test_layer) | 1508 switch (test_layer) |
1586 { | 1509 { |
1587 case 1: | 1510 case 1: |
1588 pixel.index &= sprite; | 1511 pixel &= sprite_buf[i]; |
1589 if (pixel.index) { | 1512 if (pixel) { |
1590 *debug_dst = DBG_SRC_S; | 1513 src = DBG_SRC_S | DBG_SHADOW; |
1591 } | 1514 } |
1592 break; | 1515 break; |
1593 case 2: | 1516 case 2: |
1594 pixel.index &= plane_a; | 1517 pixel &= context->tmp_buf_a[(plane_a_off + i) & SCROLL_BUFFER_MASK]; |
1595 if (pixel.index) { | 1518 if (pixel) { |
1596 *debug_dst = DBG_SRC_A; | 1519 src = DBG_SRC_A | DBG_SHADOW; |
1597 } | 1520 } |
1598 break; | 1521 break; |
1599 case 3: | 1522 case 3: |
1600 pixel.index &= plane_b; | 1523 pixel &= context->tmp_buf_b[(plane_b_off + i) & SCROLL_BUFFER_MASK]; |
1601 if (pixel.index) { | 1524 if (pixel) { |
1602 *debug_dst = DBG_SRC_B; | 1525 src = DBG_SRC_B | DBG_SHADOW; |
1603 } | 1526 } |
1604 break; | 1527 break; |
1605 } | 1528 } |
1606 debug_dst++; | 1529 |
1607 *(dst++) = colors[pixel.index & 0x3F]; | 1530 *(dst++) = context->colors[SHADOW_OFFSET + (pixel & 0x3F)]; |
1608 } | 1531 *(debug_dst++) = src; |
1532 } | |
1533 plane_a_off += 8; | |
1534 plane_b_off += 8; | |
1535 sprite_buf += 8; | |
1536 start = 8; | |
1537 } | |
1538 for (int i = start; i < 16; ++plane_a_off, ++plane_b_off, ++sprite_buf, ++i) | |
1539 { | |
1540 uint8_t sprite, plane_a, plane_b; | |
1541 plane_a = context->tmp_buf_a[plane_a_off & SCROLL_BUFFER_MASK]; | |
1542 plane_b = context->tmp_buf_b[plane_b_off & SCROLL_BUFFER_MASK]; | |
1543 sprite = *sprite_buf; | |
1544 sh_pixel pixel = composite_highlight(context, debug_dst, sprite, plane_a, plane_b, 0x3F); | |
1545 uint32_t *colors; | |
1546 if (pixel.intensity == BUF_BIT_PRIORITY << 1) { | |
1547 colors = context->colors + HIGHLIGHT_OFFSET; | |
1548 } else if (pixel.intensity) { | |
1549 colors = context->colors; | |
1550 } else { | |
1551 colors = context->colors + SHADOW_OFFSET; | |
1552 } | |
1553 if (output_disabled) { | |
1554 pixel.index = 0x3F; | |
1555 } | |
1556 switch (test_layer) | |
1557 { | |
1558 case 1: | |
1559 pixel.index &= sprite; | |
1560 if (pixel.index) { | |
1561 *debug_dst = DBG_SRC_S; | |
1562 } | |
1563 break; | |
1564 case 2: | |
1565 pixel.index &= plane_a; | |
1566 if (pixel.index) { | |
1567 *debug_dst = DBG_SRC_A; | |
1568 } | |
1569 break; | |
1570 case 3: | |
1571 pixel.index &= plane_b; | |
1572 if (pixel.index) { | |
1573 *debug_dst = DBG_SRC_B; | |
1574 } | |
1575 break; | |
1576 } | |
1577 debug_dst++; | |
1578 *(dst++) = colors[pixel.index & 0x3F]; | |
1609 } | 1579 } |
1610 } | 1580 } |
1611 | 1581 |
1612 static void render_map_output(uint32_t line, int32_t col, vdp_context * context) | 1582 static void render_map_output(uint32_t line, int32_t col, vdp_context * context) |
1613 { | 1583 { |
1671 render_testreg(context, col, dst, debug_dst, plane_a_off, plane_b_off, output_disabled, test_layer); | 1641 render_testreg(context, col, dst, debug_dst, plane_a_off, plane_b_off, output_disabled, test_layer); |
1672 } else { | 1642 } else { |
1673 render_normal(context, col, dst, debug_dst, plane_a_off, plane_b_off); | 1643 render_normal(context, col, dst, debug_dst, plane_a_off, plane_b_off); |
1674 } | 1644 } |
1675 } | 1645 } |
1646 dst += 16; | |
1676 } else { | 1647 } else { |
1677 dst = context->output; | 1648 dst = context->output; |
1678 debug_dst = context->layer_debug_buf; | 1649 debug_dst = context->layer_debug_buf; |
1679 uint8_t pixel = context->regs[REG_BG_COLOR] & 0x3F; | 1650 uint8_t pixel = context->regs[REG_BG_COLOR] & 0x3F; |
1680 if (output_disabled) { | 1651 if (output_disabled) { |
1727 *dst = bg_color; | 1698 *dst = bg_color; |
1728 *debug_dst = DBG_SRC_BG; | 1699 *debug_dst = DBG_SRC_BG; |
1729 } | 1700 } |
1730 } | 1701 } |
1731 } | 1702 } |
1732 context->done_output = dst + 16; | 1703 context->done_output = dst; |
1733 context->buf_a_off = (context->buf_a_off + SCROLL_BUFFER_DRAW) & SCROLL_BUFFER_MASK; | 1704 context->buf_a_off = (context->buf_a_off + SCROLL_BUFFER_DRAW) & SCROLL_BUFFER_MASK; |
1734 context->buf_b_off = (context->buf_b_off + SCROLL_BUFFER_DRAW) & SCROLL_BUFFER_MASK; | 1705 context->buf_b_off = (context->buf_b_off + SCROLL_BUFFER_DRAW) & SCROLL_BUFFER_MASK; |
1735 } | 1706 } |
1736 | 1707 |
1737 static void render_map_mode4(uint32_t line, int32_t col, vdp_context * context) | 1708 static void render_map_mode4(uint32_t line, int32_t col, vdp_context * context) |