Mercurial > repos > blastem
comparison vdp.c @ 1161:c2210d586950
A bunch of Mode 4 fixes
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sun, 08 Jan 2017 13:39:44 -0800 |
parents | 5f119fe935e7 |
children | b251899f2b97 |
comparison
equal
deleted
inserted
replaced
1160:5f119fe935e7 | 1161:c2210d586950 |
---|---|
290 } while (current_index != 0 && count < 80); | 290 } while (current_index != 0 && count < 80); |
291 } else { | 291 } else { |
292 uint16_t sat_address = (context->regs[REG_SAT] & 0x7E) << 7; | 292 uint16_t sat_address = (context->regs[REG_SAT] & 0x7E) << 7; |
293 for (int i = 0; i < 64; i++) | 293 for (int i = 0; i < 64; i++) |
294 { | 294 { |
295 uint8_t y = context->vdpmem[sat_address + (i ^ 1)]; | 295 uint8_t y = context->vdpmem[mode4_address_map[sat_address + (i ^ 1)]]; |
296 if (y >= 0xD0) { | 296 if (y == 0xD0) { |
297 break; | 297 break; |
298 } | 298 } |
299 uint8_t x = context->vdpmem[sat_address + 0x80 + i*2 + 1]; | 299 uint8_t x = context->vdpmem[mode4_address_map[sat_address + 0x80 + i*2 + 1]]; |
300 uint16_t tile_address = context->vdpmem[sat_address + 0x80 + i*2] * 32 | 300 uint16_t tile_address = context->vdpmem[mode4_address_map[sat_address + 0x80 + i*2]] * 32 |
301 + (context->regs[REG_STILE_BASE] << 11 & 0x2000); | 301 + (context->regs[REG_STILE_BASE] << 11 & 0x2000); |
302 if (context->regs[REG_MODE_2] & BIT_SPRITE_SZ) { | 302 if (context->regs[REG_MODE_2] & BIT_SPRITE_SZ) { |
303 tile_address &= ~32; | 303 tile_address &= ~32; |
304 } | 304 } |
305 printf("Sprite %d: X=%d, Y=%d, Pat=%X\n", i, x, y, tile_address); | 305 printf("Sprite %d: X=%d, Y=%d, Pat=%X\n", i, x, y, tile_address); |
512 } | 512 } |
513 | 513 |
514 static void scan_sprite_table_mode4(vdp_context * context) | 514 static void scan_sprite_table_mode4(vdp_context * context) |
515 { | 515 { |
516 if (context->sprite_index < MAX_SPRITES_FRAME_H32) { | 516 if (context->sprite_index < MAX_SPRITES_FRAME_H32) { |
517 uint32_t line = context->vcounter + 1; | 517 uint32_t line = context->vcounter; |
518 line &= 0xFF; | 518 line &= 0xFF; |
519 | 519 |
520 uint32_t sat_address = mode4_address_map[(context->regs[REG_SAT] << 7 & 0x3F00) + context->sprite_index]; | 520 uint32_t sat_address = mode4_address_map[(context->regs[REG_SAT] << 7 & 0x3F00) + context->sprite_index]; |
521 uint32_t y = context->vdpmem[sat_address+1]; | 521 uint32_t y = context->vdpmem[sat_address+1]; |
522 uint32_t size = (context->regs[REG_MODE_2] & BIT_SPRITE_SZ) ? 16 : 8; | 522 uint32_t size = (context->regs[REG_MODE_2] & BIT_SPRITE_SZ) ? 16 : 8; |
523 | 523 |
524 if (y >= 0xd0) { | 524 if (y == 0xd0) { |
525 context->sprite_index = MAX_SPRITES_FRAME_H32; | 525 context->sprite_index = MAX_SPRITES_FRAME_H32; |
526 return; | 526 return; |
527 } else { | 527 } else { |
528 if (y <= line && line < (y + size)) { | 528 if (y <= line && line < (y + size)) { |
529 if (!context->slot_counter) { | 529 if (!context->slot_counter) { |
538 context->sprite_index++; | 538 context->sprite_index++; |
539 } | 539 } |
540 | 540 |
541 if (context->sprite_index < MAX_SPRITES_FRAME_H32) { | 541 if (context->sprite_index < MAX_SPRITES_FRAME_H32) { |
542 y = context->vdpmem[sat_address]; | 542 y = context->vdpmem[sat_address]; |
543 if (y >= 0xd0) { | 543 if (y == 0xd0) { |
544 context->sprite_index = MAX_SPRITES_FRAME_H32; | 544 context->sprite_index = MAX_SPRITES_FRAME_H32; |
545 return; | 545 return; |
546 } else { | 546 } else { |
547 if (y <= line && line < (y + size)) { | 547 if (y <= line && line < (y + size)) { |
548 if (!context->slot_counter) { | 548 if (!context->slot_counter) { |
1542 } else {\ | 1542 } else {\ |
1543 context->hslot++;\ | 1543 context->hslot++;\ |
1544 }\ | 1544 }\ |
1545 context->cycles += slot_cycles;\ | 1545 context->cycles += slot_cycles;\ |
1546 CHECK_ONLY | 1546 CHECK_ONLY |
1547 | 1547 |
1548 #define CALC_SLOT(slot, increment) ((slot+increment) > 147 && (slot+increment) < 233 ? (slot+increment-148+233): (slot+increment)) | |
1548 | 1549 |
1549 #define SPRITE_RENDER_H32_MODE4(slot) \ | 1550 #define SPRITE_RENDER_H32_MODE4(slot) \ |
1550 case slot:\ | 1551 case slot:\ |
1551 read_sprite_x_mode4(context);\ | 1552 read_sprite_x_mode4(context);\ |
1552 MODE4_CHECK_SLOT_LINE(slot)\ | 1553 MODE4_CHECK_SLOT_LINE(slot)\ |
1553 case (slot+1):\ | 1554 case CALC_SLOT(slot, 1):\ |
1554 read_sprite_x_mode4(context);\ | 1555 read_sprite_x_mode4(context);\ |
1555 MODE4_CHECK_SLOT_LINE(slot+1)\ | 1556 MODE4_CHECK_SLOT_LINE(CALC_SLOT(slot,1))\ |
1556 case (slot+2):\ | 1557 case CALC_SLOT(slot, 2):\ |
1557 fetch_sprite_cells_mode4(context);\ | 1558 fetch_sprite_cells_mode4(context);\ |
1558 MODE4_CHECK_SLOT_LINE(slot+2)\ | 1559 MODE4_CHECK_SLOT_LINE(CALC_SLOT(slot, 2))\ |
1559 case (slot+3):\ | 1560 case CALC_SLOT(slot, 3):\ |
1560 render_sprite_cells_mode4(context);\ | 1561 render_sprite_cells_mode4(context);\ |
1561 MODE4_CHECK_SLOT_LINE(slot+3)\ | 1562 MODE4_CHECK_SLOT_LINE(CALC_SLOT(slot, 3))\ |
1562 case (slot+4):\ | 1563 case CALC_SLOT(slot, 4):\ |
1563 fetch_sprite_cells_mode4(context);\ | 1564 fetch_sprite_cells_mode4(context);\ |
1564 MODE4_CHECK_SLOT_LINE(slot+4)\ | 1565 MODE4_CHECK_SLOT_LINE(CALC_SLOT(slot, 4))\ |
1565 case (slot+5):\ | 1566 case CALC_SLOT(slot, 5):\ |
1566 render_sprite_cells_mode4(context);\ | 1567 render_sprite_cells_mode4(context);\ |
1567 MODE4_CHECK_SLOT_LINE(slot+5) | 1568 MODE4_CHECK_SLOT_LINE(CALC_SLOT(slot, 5)) |
1568 | 1569 |
1569 static void vdp_h40(vdp_context * context, uint32_t target_cycles) | 1570 static void vdp_h40(vdp_context * context, uint32_t target_cycles) |
1570 { | 1571 { |
1571 uint16_t address; | 1572 uint16_t address; |
1572 uint32_t mask; | 1573 uint32_t mask; |
2076 memset(context->linebuf, 0, LINEBUF_SIZE); | 2077 memset(context->linebuf, 0, LINEBUF_SIZE); |
2077 } else if (context->hslot == 165) { | 2078 } else if (context->hslot == 165) { |
2078 context->sprite_index = 0x80; | 2079 context->sprite_index = 0x80; |
2079 context->slot_counter = MAX_SPRITES_LINE; | 2080 context->slot_counter = MAX_SPRITES_LINE; |
2080 } | 2081 } |
2081 } else { | 2082 } else if (mode_5){ |
2082 if (context->hslot == 128) { | 2083 if (context->hslot == 128) { |
2083 context->cur_slot = MAX_DRAWS_H32-1; | 2084 context->cur_slot = MAX_DRAWS_H32-1; |
2084 memset(context->linebuf, 0, LINEBUF_SIZE); | 2085 memset(context->linebuf, 0, LINEBUF_SIZE); |
2085 } else if (context->hslot == 132) { | 2086 } else if (context->hslot == 132) { |
2086 context->sprite_index = 0x80; | 2087 context->sprite_index = 0x80; |
2087 context->slot_counter = MAX_SPRITES_LINE_H32; | 2088 context->slot_counter = MAX_SPRITES_LINE_H32; |
2089 } | |
2090 } else { | |
2091 if (context->hslot == 253) { | |
2092 context->sprite_index = 0; | |
2093 context->slot_counter = MAX_DRAWS_H32_MODE4; | |
2094 } else if (context->hslot == 136) { | |
2095 memset(context->linebuf, 0, LINEBUF_SIZE); | |
2096 context->cur_slot = context->sprite_index = MAX_DRAWS_H32_MODE4-1; | |
2097 context->sprite_draws = MAX_DRAWS_H32_MODE4; | |
2088 } | 2098 } |
2089 } | 2099 } |
2090 if(context->vcounter == inactive_start) { | 2100 if(context->vcounter == inactive_start) { |
2091 uint32_t intslot = context->regs[REG_MODE_4] & BIT_H40 ? VINT_SLOT_H40 : VINT_SLOT_H32; | 2101 uint32_t intslot = context->regs[REG_MODE_4] & BIT_H40 ? VINT_SLOT_H40 : VINT_SLOT_H32; |
2092 if (context->hslot == intslot) { | 2102 if (context->hslot == intslot) { |
2125 } | 2135 } |
2126 } else if (context->hslot == 183) { | 2136 } else if (context->hslot == 183) { |
2127 context->hslot = 229; | 2137 context->hslot = 229; |
2128 } | 2138 } |
2129 } else { | 2139 } else { |
2130 if (context->hslot == LINE_CHANGE_H32) { | 2140 if (context->hslot == (mode_5 ? LINE_CHANGE_H32 : LINE_CHANGE_MODE4)) { |
2131 vdp_advance_line(context); | 2141 vdp_advance_line(context); |
2132 if (context->vcounter == (inactive_start + 8)) { | 2142 if (context->vcounter == (inactive_start + 8)) { |
2133 context->frame++; | 2143 context->frame++; |
2134 } | 2144 } |
2135 } else if (context->hslot == 148) { | 2145 } else if (context->hslot == 148) { |