From: kub Date: Sun, 2 Mar 2025 19:10:28 +0000 (+0100) Subject: sms, improved vdp register latching X-Git-Tag: v2.04~32 X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4c10007b6902d15d9a8fd564ca6b50ddb3e0b65c;p=picodrive.git sms, improved vdp register latching --- diff --git a/pico/mode4.c b/pico/mode4.c index cc5c5883..43bc2556 100644 --- a/pico/mode4.c +++ b/pico/mode4.c @@ -26,7 +26,6 @@ static unsigned char sprites_map[2+256/8+2]; // collision detection map unsigned int sprites_status; int sprites_zoom; // latched sprite zoom flag -int sprites_sat, sprites_base; // latched sprite table data int xscroll; // horizontal scroll /* sprite collision detection */ @@ -169,14 +168,14 @@ static void ParseSpritesM4(int scanline) if (Pico.m.hardware & PMS_HW_LCD) xoff -= 48; // GG LCD, adjust to center 160 px - sat = (u8 *)PicoMem.vram + ((sprites_sat & 0x7e) << 7); + sat = (u8 *)PicoMem.vram + ((pv->reg[5] & 0x7e) << 7); if (sprites_zoom & 2) { addr_mask = 0xfe; h = 16; } else { addr_mask = 0xff; h = 8; } if (zoomed) h *= 2; - sprite_base = (sprites_base & 4) << (13-2-1); + sprite_base = (pv->reg[6] & 4) << (13-2-1); m = pv->status & SR_C; memset(sprites_map, 0, sizeof(sprites_map)); @@ -443,14 +442,14 @@ static void ParseSpritesTMS(int scanline) xoff = line_offset; - sat = (u8 *)PicoMem.vramb + ((sprites_sat & 0x7f) << 7); + sat = (u8 *)PicoMem.vramb + ((pv->reg[5] & 0x7f) << 7); if (sprites_zoom & 2) { addr_mask = 0xfc; h = 16; } else { addr_mask = 0xff; h = 8; } if (zoomed) h *= 2; - sprite_base = (sprites_base & 0x7) << 11; + sprite_base = (pv->reg[6] & 0x7) << 11; m = pv->status & SR_C; memset(sprites_map, 0, sizeof(sprites_map)); @@ -851,8 +850,6 @@ void PicoLineSMS(int line) // latch current register values (may be overwritten by VDP reg writes later) sprites_zoom = (Pico.video.reg[1] & 0x3) | (Pico.video.reg[0] & 0x8); - sprites_sat = Pico.video.reg[5]; - sprites_base = Pico.video.reg[6]; xscroll = Pico.video.reg[8]; if (FinalizeLineSMS != NULL) diff --git a/pico/sms.c b/pico/sms.c index 5bc9ebd9..214601f3 100644 --- a/pico/sms.c +++ b/pico/sms.c @@ -24,7 +24,7 @@ extern void YM2413_regWrite(unsigned reg); extern void YM2413_dataWrite(unsigned data); extern unsigned sprites_status; // TODO put in some hdr file! -extern int sprites_zoom, sprites_sat, sprites_base, xscroll; +extern int sprites_zoom, xscroll; static unsigned char vdp_data_read(void) { @@ -88,12 +88,16 @@ static void vdp_data_write(unsigned char d) // 23 px right border+blanking, // 26 px hsync, // 37 px left blanking+border -// VINT is at the beginning of hsync, and HINRT is one px later. Relative TO V/HINT: -// -10 px sprite mode latching (r1) -// -8 px sprite mode latching (r0) -// -6 px sprite attribute table latching (r5) -// -4 px sprite pattern table latching (r6) -// -2 px xscroll latching (r8) +// VINT is at the beginning of hsync, and HINT is one px later. Relative TO V/HINT: +// -18..-2 px 1st half of sprite attribute table (r5) scan +// -10 px sprite mode latching (r1,r0) +// -2 px hscroll latching (r8) +// hscroll is probably latched internally due to it depending on the horizontal +// scroll lock, which has this at 0 for the top 16 lines. +// I don't think the sprite mode is really latched. The SAT scan determines the +// relative y position within the sprite pattern, which will break since SAT +// scanning is done in one go here, while in reality it is distributed over +// several slots. Cache it here to avoid backward effects of later changes to r1 // TODO: off by 2 CPU cycles according to VDPTEST? static NOINLINE void vdp_reg_write(struct PicoVideo *pv, u8 a, u8 d) @@ -106,7 +110,7 @@ static NOINLINE void vdp_reg_write(struct PicoVideo *pv, u8 a, u8 d) l = pv->pending_ints & (d >> 3) & 2; elprintf(EL_INTS, "hint %d", l); z80_int_assert(l); - if (z80_cyclesDone() - Pico.t.z80c_line_start < 228 - (int)(8*1.5)+2) + if (z80_cyclesDone() - Pico.t.z80c_line_start < 228 - (int)(10*1.5)+2) sprites_zoom = (pv->reg[1] & 0x3) | (pv->reg[0] & 0x8); break; case 1: // mode control 2 @@ -116,14 +120,6 @@ static NOINLINE void vdp_reg_write(struct PicoVideo *pv, u8 a, u8 d) if (z80_cyclesDone() - Pico.t.z80c_line_start < 228 - (int)(10*1.5)+2) sprites_zoom = (pv->reg[1] & 0x3) | (pv->reg[0] & 0x8); break; - case 5: // sprite attribute table - if (z80_cyclesDone() - Pico.t.z80c_line_start < 228 - (int)(6*1.5)+2) - sprites_sat = d; - break; - case 6: // sprite pattern table - if (z80_cyclesDone() - Pico.t.z80c_line_start < 228 - (int)(4*1.5)+2) - sprites_base = d; - break; case 8: // horizontal scroll if (z80_cyclesDone() - Pico.t.z80c_line_start < 228 - (int)(2*1.5)+2) xscroll = d;