Mercurial > repos > blastem
comparison vdp.c @ 2612:7e04620c9dc1
Get tilemap debug view working for TMS graphics and text modes. Multicolor still TBD
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sat, 15 Feb 2025 23:29:51 -0800 |
parents | bd8d1babbfb5 |
children | dbff641a33df |
comparison
equal
deleted
inserted
replaced
2611:9bd90cd94000 | 2612:7e04620c9dc1 |
---|---|
2585 | 2585 |
2586 static void sprite_debug_mode4(uint32_t *fb, uint32_t pitch, vdp_context *context) | 2586 static void sprite_debug_mode4(uint32_t *fb, uint32_t pitch, vdp_context *context) |
2587 { | 2587 { |
2588 } | 2588 } |
2589 | 2589 |
2590 uint32_t tms_map_color(vdp_context *context, uint8_t color) | |
2591 { | |
2592 if (context->type == VDP_GAMEGEAR) { | |
2593 //Game Gear uses CRAM entries 16-31 for TMS9918A modes | |
2594 return context->colors[color + 16 + MODE4_OFFSET]; | |
2595 } else { | |
2596 color <<= 1; | |
2597 color = (color & 0xE) | (color << 1 & 0x20); | |
2598 return context->color_map[color | FBUF_TMS]; | |
2599 } | |
2600 } | |
2601 | |
2590 static void plane_debug_tms(uint32_t *fb, uint32_t pitch, vdp_context *context) | 2602 static void plane_debug_tms(uint32_t *fb, uint32_t pitch, vdp_context *context) |
2591 { | 2603 { |
2604 uint16_t table_address = context->regs[REG_SCROLL_A] << 10 & 0x3C00; | |
2605 uint16_t color_address = context->regs[REG_COLOR_TABLE] << 6; | |
2606 uint16_t pattern_address = context->regs[REG_PATTERN_GEN] << 11 & 0x3800; | |
2607 uint16_t upper_vcounter_mask; | |
2608 uint16_t upper_vcounter_pmask; | |
2609 uint16_t pattern_name_mask; | |
2610 if (context->type > VDP_SMS2) { | |
2611 //SMS1 and TMS9918A | |
2612 upper_vcounter_mask = color_address & 0x1800; | |
2613 upper_vcounter_pmask = pattern_address & 0x1800; | |
2614 pattern_name_mask = (color_address & 0x07C0) | 0x0038; | |
2615 } else { | |
2616 //SMS2 and Game Gear | |
2617 upper_vcounter_mask = 0x1800; | |
2618 upper_vcounter_pmask = 0x1800; | |
2619 pattern_name_mask = 0x07F8; | |
2620 } | |
2621 uint32_t cols, pixels; | |
2622 if (context->regs[REG_MODE_2] & BIT_M1) { | |
2623 //Text mode | |
2624 cols = 40; | |
2625 pixels = 12; | |
2626 } else { | |
2627 //Graphics/Multicolor | |
2628 cols = 32; | |
2629 pixels = 16; | |
2630 } | |
2631 uint32_t fg, bg; | |
2632 if (context->regs[REG_MODE_2] & BIT_M1) { | |
2633 //Text mode uses TC and BD colors | |
2634 fg = tms_map_color(context, context->regs[REG_BG_COLOR] >> 4); | |
2635 bg = tms_map_color(context, context->regs[REG_BG_COLOR] & 0xF); | |
2636 } | |
2637 for (uint32_t row = 0; row < 24; row++) | |
2638 { | |
2639 uint32_t *colfb = fb; | |
2640 for (uint32_t col = 0; col < cols; col++) | |
2641 { | |
2642 uint32_t *linefb = colfb; | |
2643 uint8_t pattern = context->vdpmem[mode4_address_map[table_address] ^ 1]; | |
2644 uint16_t caddress = color_address; | |
2645 uint16_t paddress = pattern_address; | |
2646 if (context->regs[REG_MODE_2] & BIT_M2) { | |
2647 } else { | |
2648 if (context->regs[REG_MODE_1] & BIT_M3) { | |
2649 //Graphics II | |
2650 caddress &= 0x2000; | |
2651 paddress &= 0x2000; | |
2652 caddress |= (row * 8) << 5 & upper_vcounter_mask; | |
2653 caddress |= pattern << 3 & pattern_name_mask; | |
2654 paddress |= (row * 8) << 5 & upper_vcounter_pmask; | |
2655 } else { | |
2656 caddress |= pattern >> 3; | |
2657 } | |
2658 paddress |= pattern << 3 & 0x7F8; | |
2659 for (uint32_t y = 0; y < 16; y++) | |
2660 { | |
2661 uint8_t bits = context->vdpmem[mode4_address_map[paddress] ^ 1]; | |
2662 if (!(context->regs[REG_MODE_2] & BIT_M1)) { | |
2663 uint8_t colors = context->vdpmem[mode4_address_map[caddress] ^ 1]; | |
2664 fg = tms_map_color(context, colors >> 4); | |
2665 bg = tms_map_color(context, colors & 0xF); | |
2666 } | |
2667 | |
2668 uint32_t *curfb = linefb; | |
2669 for (uint32_t x = 0; x < pixels; x++) | |
2670 { | |
2671 *(curfb++) = (bits & 0x80) ? fg : bg; | |
2672 if (x & 1) { | |
2673 bits <<= 1; | |
2674 } | |
2675 } | |
2676 linefb += pitch / sizeof(uint32_t); | |
2677 if (y & 1) { | |
2678 if (context->regs[REG_MODE_1] & BIT_M3) { | |
2679 caddress++; | |
2680 } | |
2681 paddress++; | |
2682 } | |
2683 } | |
2684 } | |
2685 table_address++; | |
2686 colfb += pixels; | |
2687 } | |
2688 fb += 16 * pitch / sizeof(uint32_t); | |
2689 } | |
2592 } | 2690 } |
2593 | 2691 |
2594 static void sprite_debug_tms(uint32_t *fb, uint32_t pitch, vdp_context *context) | 2692 static void sprite_debug_tms(uint32_t *fb, uint32_t pitch, vdp_context *context) |
2595 { | 2693 { |
2596 } | 2694 } |
4229 uint8_t color = tms_sprite_clock(context, 0); | 4327 uint8_t color = tms_sprite_clock(context, 0); |
4230 if (!context->output) { | 4328 if (!context->output) { |
4231 tms_sprite_clock(context, 1); | 4329 tms_sprite_clock(context, 1); |
4232 return; | 4330 return; |
4233 } | 4331 } |
4332 uint8_t fg,bg; | |
4333 if (context->regs[REG_MODE_2] & BIT_M1) { | |
4334 //Text mode uses TC and BD colors | |
4335 fg = context->regs[REG_BG_COLOR] >> 4; | |
4336 bg = context->regs[REG_BG_COLOR] & 0xF; | |
4337 } else { | |
4338 fg = context->tmp_buf_b[0] >> 4; | |
4339 bg = context->tmp_buf_b[0] & 0xF; | |
4340 if (!bg) { | |
4341 bg = context->regs[REG_BG_COLOR] & 0xF; | |
4342 } | |
4343 } | |
4234 uint8_t pattern = context->tmp_buf_a[0] & 0x80; | 4344 uint8_t pattern = context->tmp_buf_a[0] & 0x80; |
4235 context->tmp_buf_a[0] <<= 1; | 4345 context->tmp_buf_a[0] <<= 1; |
4236 if (!color) { | 4346 if (!color) { |
4237 uint8_t fg,bg; | |
4238 if (context->regs[REG_MODE_2] & BIT_M1) { | |
4239 //Text mode uses TC and BD colors | |
4240 fg = context->regs[REG_BG_COLOR] >> 4; | |
4241 bg = context->regs[REG_BG_COLOR] & 0xF; | |
4242 } else { | |
4243 fg = context->tmp_buf_b[0] >> 4; | |
4244 bg = context->tmp_buf_b[0] & 0xF; | |
4245 if (!bg) { | |
4246 bg = context->regs[REG_BG_COLOR] & 0xF; | |
4247 } | |
4248 } | |
4249 color = pattern ? fg : bg; | 4347 color = pattern ? fg : bg; |
4250 } | 4348 } |
4251 //TODO: composite debug output | 4349 //TODO: composite debug output |
4252 if (context->type == VDP_GAMEGEAR) { | 4350 context->output[context->hslot * 2 - 8 + BORDER_LEFT] = tms_map_color(context, color); |
4253 //Game Gear uses CRAM entries 16-31 for TMS9918A modes | |
4254 context->output[context->hslot * 2 - 8 + BORDER_LEFT] = context->colors[color + 16 + MODE4_OFFSET]; | |
4255 } else { | |
4256 color <<= 1; | |
4257 color = (color & 0xE) | (color << 1 & 0x20); | |
4258 context->output[context->hslot * 2 - 8 + BORDER_LEFT] = context->color_map[color | FBUF_TMS]; | |
4259 } | |
4260 color = tms_sprite_clock(context, 1); | 4351 color = tms_sprite_clock(context, 1); |
4261 pattern = context->tmp_buf_a[0] & 0x80; | 4352 pattern = context->tmp_buf_a[0] & 0x80; |
4262 context->tmp_buf_a[0] <<= 1; | 4353 context->tmp_buf_a[0] <<= 1; |
4263 if (!color) { | 4354 if (!color) { |
4264 uint8_t fg,bg; | |
4265 if (context->regs[REG_MODE_2] & BIT_M1) { | |
4266 //Text mode uses TC and BD colors | |
4267 fg = context->regs[REG_BG_COLOR] >> 4; | |
4268 bg = context->regs[REG_BG_COLOR] & 0xF; | |
4269 } else { | |
4270 fg = context->tmp_buf_b[0] >> 4; | |
4271 bg = context->tmp_buf_b[0] & 0xF; | |
4272 if (!bg) { | |
4273 bg = context->regs[REG_BG_COLOR] & 0xF; | |
4274 } | |
4275 } | |
4276 color = pattern ? fg : bg; | 4355 color = pattern ? fg : bg; |
4277 } | 4356 } |
4278 //TODO: composite debug output | 4357 //TODO: composite debug output |
4279 if (context->type == VDP_GAMEGEAR) { | 4358 context->output[context->hslot * 2 - 7 + BORDER_LEFT] = tms_map_color(context, color); |
4280 //Game Gear uses CRAM entries 16-31 for TMS9918A modes | |
4281 context->output[context->hslot * 2 - 7 + BORDER_LEFT] = context->colors[color + 16 + MODE4_OFFSET]; | |
4282 } else { | |
4283 color <<= 1; | |
4284 color = (color & 0xE) | (color << 1 & 0x20); | |
4285 context->output[context->hslot * 2 - 7 + BORDER_LEFT] = context->color_map[color | FBUF_TMS]; | |
4286 } | |
4287 } | 4359 } |
4288 | 4360 |
4289 #define TMS_OUTPUT(slot) if ((slot) < 4 || (slot) > (256 + BORDER_LEFT - 8) / 2) { tms_border(context); } else { tms_composite(context); } | 4361 #define TMS_OUTPUT(slot) if ((slot) < 4 || (slot) > (256 + BORDER_LEFT - 8) / 2) { tms_border(context); } else { tms_composite(context); } |
4290 #define TMS_OUTPUT_RIGHT(slot) \ | 4362 #define TMS_OUTPUT_RIGHT(slot) \ |
4291 if ((slot) < (256 + BORDER_LEFT - (BORDER_LEFT - 8))/2) {\ | 4363 if ((slot) < (256 + BORDER_LEFT - (BORDER_LEFT - 8))/2) {\ |