From: kub Date: Wed, 12 Jul 2023 20:35:33 +0000 (+0200) Subject: core, fix z80 vcounter value X-Git-Tag: v2.00~188 X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=702162215364848b4f7ebd86e7279437fdcd2f65;p=picodrive.git core, fix z80 vcounter value --- diff --git a/pico/memory.c b/pico/memory.c index 2016f48d..96a00744 100644 --- a/pico/memory.c +++ b/pico/memory.c @@ -1367,7 +1367,7 @@ static unsigned char z80_md_vdp_read(unsigned short a) case 0x04: return PicoVideoRead8CtlH(1); case 0x05: return PicoVideoRead8CtlL(1); case 0x08: - case 0x0c: return get_scanline(1); // FIXME: make it proper + case 0x0c: return PicoVideoGetV(get_scanline(1)); case 0x09: case 0x0d: return Pico.m.rotate++; } diff --git a/pico/pico.c b/pico/pico.c index 6b2124b3..ced4091e 100644 --- a/pico/pico.c +++ b/pico/pico.c @@ -225,6 +225,15 @@ void PicoLoopPrepare(void) // force setting possibly changed.. Pico.m.pal = (PicoIn.regionOverride == 2 || PicoIn.regionOverride == 8) ? 1 : 0; + if (Pico.m.pal) { + Pico.t.vcnt_wrap = 0x103; + Pico.t.vcnt_adj = 57; + } + else { + Pico.t.vcnt_wrap = 0xEB; + Pico.t.vcnt_adj = 6; + } + Pico.m.dirtyPal = 1; rendstatus_old = -1; diff --git a/pico/pico_cmn.c b/pico/pico_cmn.c index 40ce766e..a06573e1 100644 --- a/pico/pico_cmn.c +++ b/pico/pico_cmn.c @@ -136,7 +136,6 @@ static int PicoFrameHints(void) { struct PicoVideo *pv = &Pico.video; int lines, y, lines_vis, skip; - int vcnt_wrap, vcnt_adj; int hint; // Hint counter pevt_log_m68k_o(EVT_FRAME_START); @@ -144,7 +143,6 @@ static int PicoFrameHints(void) skip = PicoIn.skipFrame; Pico.t.m68c_frame_start = Pico.t.m68c_aim; - pv->v_counter = Pico.m.scanline = 0; z80_resetCycles(); PsndStartFrame(); @@ -153,16 +151,13 @@ static int PicoFrameHints(void) // === active display === pv->status |= PVS_ACTIVE; - for (y = 0; ; y++) + for (y = 0;; y++) { - pv->v_counter = Pico.m.scanline = y; - if ((pv->reg[12]&6) == 6) { // interlace mode 2 - pv->v_counter <<= 1; - pv->v_counter |= pv->v_counter >> 8; - pv->v_counter &= 0xff; - } + Pico.m.scanline = y; + pv->v_counter = PicoVideoGetV(y); - if ((y == 224 && !(pv->reg[1] & 8)) || y == 240) + lines_vis = (pv->reg[1] & 8) ? 240 : 224; + if (y == lines_vis) break; PAD_DELAY(); @@ -268,25 +263,11 @@ static int PicoFrameHints(void) pevt_log_m68k_o(EVT_NEXT_LINE); // === VBLANK === - if (Pico.m.pal) { - lines = 313; - vcnt_wrap = 0x103; - vcnt_adj = 57; - } - else { - lines = 262; - vcnt_wrap = 0xEB; - vcnt_adj = 6; - } - + lines = Pico.m.pal ? 313 : 262; for (y++; y < lines - 1; y++) { - pv->v_counter = Pico.m.scanline = y; - if (y >= vcnt_wrap) - pv->v_counter -= vcnt_adj; - if ((pv->reg[12]&6) == 6) - pv->v_counter = (pv->v_counter << 1) | 1; - pv->v_counter &= 0xff; + Pico.m.scanline = y; + pv->v_counter = PicoVideoGetV(y); PAD_DELAY(); diff --git a/pico/pico_int.h b/pico/pico_int.h index d3229149..dc35426b 100644 --- a/pico/pico_int.h +++ b/pico/pico_int.h @@ -454,6 +454,8 @@ struct PicoTiming int timer_a_next_oflow, timer_a_step; // in z80 cycles int timer_b_next_oflow, timer_b_step; + + int vcnt_wrap, vcnt_adj; }; struct PicoSound @@ -914,6 +916,13 @@ static __inline void VideoWriteVRAM(u32 a, u16 d) UpdateSAT(a, d); } +static __inline u8 PicoVideoGetV(int scanline) +{ + if (scanline >= Pico.t.vcnt_wrap) scanline -= Pico.t.vcnt_adj; + if ((Pico.video.reg[12]&6) == 6) scanline = (scanline<<1) | 1; + return scanline; +} + PICO_INTERNAL_ASM void PicoVideoWrite(u32 a,unsigned short d); PICO_INTERNAL_ASM u32 PicoVideoRead(u32 a); unsigned char PicoVideoRead8DataH(int is_from_z80);