From 75b84e4b7c446cf42a2838834b5d50a4059709fe Mon Sep 17 00:00:00 2001 From: notaz Date: Sun, 1 Oct 2017 00:59:44 +0300 Subject: [PATCH] slightly better z80 vdp reads --- pico/memory.c | 32 +++++++++++++++--- pico/memory_amips.s | 2 +- pico/pico_int.h | 7 +++- pico/videoport.c | 79 ++++++++++++++++++++++++++------------------- 4 files changed, 79 insertions(+), 41 deletions(-) diff --git a/pico/memory.c b/pico/memory.c index 0907696..34ef99d 100644 --- a/pico/memory.c +++ b/pico/memory.c @@ -703,10 +703,21 @@ void PicoWrite16_io(u32 a, u32 d) // VDP area (0xc00000 - 0xdfffff) // TODO: verify if lower byte goes to PSG on word writes -static u32 PicoRead8_vdp(u32 a) +u32 PicoRead8_vdp(u32 a) { - if ((a & 0x00e0) == 0x0000) - return PicoVideoRead8(a); + if ((a & 0x00f0) == 0x0000) { + switch (a & 0x0d) + { + case 0x00: return PicoVideoRead8DataH(); + case 0x01: return PicoVideoRead8DataL(); + case 0x04: return PicoVideoRead8CtlH(); + case 0x05: return PicoVideoRead8CtlL(); + case 0x08: + case 0x0c: return PicoVideoRead8HV_H(); + case 0x09: + case 0x0d: return PicoVideoRead8HV_L(); + } + } elprintf(EL_UIO|EL_ANOMALY, "68k bad read [%06x] @%06x", a, SekPc); return 0; @@ -1184,8 +1195,19 @@ void PicoWrite16_32x(u32 a, u32 d) {} static unsigned char z80_md_vdp_read(unsigned short a) { - if ((a & 0x00e0) == 0x0000) - return PicoVideoRead8(a); // FIXME: depends on 68k cycles + if ((a & 0x00f0) == 0x0000) { + switch (a & 0x0d) + { + case 0x00: return PicoVideoRead8DataH(); + case 0x01: return PicoVideoRead8DataL(); + case 0x04: return PicoVideoRead8CtlH(); + case 0x05: return PicoVideoRead8CtlL(); + case 0x08: + case 0x0c: return get_scanline(1); // FIXME: make it proper + case 0x09: + case 0x0d: return Pico.m.rotate++; + } + } elprintf(EL_ANOMALY, "z80 invalid r8 [%06x] %02x", a, 0xff); return 0xff; diff --git a/pico/memory_amips.s b/pico/memory_amips.s index 4f09198..b11c2e2 100644 --- a/pico/memory_amips.s +++ b/pico/memory_amips.s @@ -468,7 +468,7 @@ m_read8_vdp: or $t0, $t1 bnez $t0, m_read_null # invalid address nop - j PicoVideoRead8 + j PicoRead8_vdp nop m_read8_ram: diff --git a/pico/pico_int.h b/pico/pico_int.h index 1276931..97b7b0e 100644 --- a/pico/pico_int.h +++ b/pico/pico_int.h @@ -793,7 +793,12 @@ void ym2612_unpack_state(void); extern int line_base_cycles; PICO_INTERNAL_ASM void PicoVideoWrite(unsigned int a,unsigned short d); PICO_INTERNAL_ASM unsigned int PicoVideoRead(unsigned int a); -PICO_INTERNAL_ASM unsigned int PicoVideoRead8(unsigned int a); +unsigned char PicoVideoRead8DataH(void); +unsigned char PicoVideoRead8DataL(void); +unsigned char PicoVideoRead8CtlH(void); +unsigned char PicoVideoRead8CtlL(void); +unsigned char PicoVideoRead8HV_H(void); +unsigned char PicoVideoRead8HV_L(void); extern int (*PicoDmaHook)(unsigned int source, int len, unsigned short **base, unsigned int *mask); // misc.c diff --git a/pico/videoport.c b/pico/videoport.c index fe96139..0af4bbc 100644 --- a/pico/videoport.c +++ b/pico/videoport.c @@ -563,43 +563,54 @@ PICO_INTERNAL_ASM unsigned int PicoVideoRead(unsigned int a) return 0; } -unsigned int PicoVideoRead8(unsigned int a) +unsigned char PicoVideoRead8DataH(void) { - unsigned int d; - a&=0x1d; + return VideoRead() >> 8; +} - switch (a) - { - case 0: return VideoRead() >> 8; - case 1: return VideoRead() & 0xff; - case 4: // control port/status reg - d = Pico.video.status >> 8; - if (d&1) Pico.video.status&=~0x100; // FIFO no longer full - Pico.video.pending = 0; - elprintf(EL_SR, "SR read (h): %02x @ %06x", d, SekPc); - return d; - case 5: - d = Pico.video.status & 0xff; - //if (PicoOpt&POPT_ALT_RENDERER) d|=0x0020; // sprite collision (Shadow of the Beast) - d |= ((Pico.video.reg[1]&0x40)^0x40) >> 3; // set V-Blank if display is disabled - d |= (Pico.video.pending_ints&0x20)<<2; // V-int pending? - if (SekCyclesDone() - line_base_cycles >= 488-88) d |= 4; // H-Blank - Pico.video.pending = 0; - elprintf(EL_SR, "SR read (l): %02x @ %06x", d, SekPc); - return d; - case 8: // hv counter - elprintf(EL_HVCNT, "vcounter: %02x (%i) @ %06x", Pico.video.v_counter, SekCyclesDone(), SekPc); - return Pico.video.v_counter; - case 9: - d = (SekCyclesDone() - line_base_cycles) & 0x1ff; // FIXME - if (Pico.video.reg[12]&1) - d = hcounts_40[d]; - else d = hcounts_32[d]; - elprintf(EL_HVCNT, "hcounter: %02x (%i) @ %06x", d, SekCyclesDone(), SekPc); - return d; - } +unsigned char PicoVideoRead8DataL(void) +{ + return VideoRead(); +} - return 0; +// FIXME: broken mess +unsigned char PicoVideoRead8CtlH(void) +{ + u8 d = (u8)(Pico.video.status >> 8); + if (d & 1) + Pico.video.status &= ~0x100; // FIFO no longer full + Pico.video.pending = 0; + elprintf(EL_SR, "SR read (h): %02x @ %06x", d, SekPc); + return d; +} + +unsigned char PicoVideoRead8CtlL(void) +{ + u8 d = (u8)Pico.video.status; + //if (PicoOpt&POPT_ALT_RENDERER) d|=0x0020; // sprite collision (Shadow of the Beast) + d |= ((Pico.video.reg[1]&0x40)^0x40) >> 3; // set V-Blank if display is disabled + d |= (Pico.video.pending_ints&0x20)<<2; // V-int pending? + if (SekCyclesDone() - line_base_cycles >= 488-88) d |= 4; // H-Blank + Pico.video.pending = 0; + elprintf(EL_SR, "SR read (l): %02x @ %06x", d, SekPc); + return d; +} + +unsigned char PicoVideoRead8HV_H(void) +{ + elprintf(EL_HVCNT, "vcounter: %02x (%i) @ %06x", Pico.video.v_counter, SekCyclesDone(), SekPc); + return Pico.video.v_counter; +} + +// FIXME: broken +unsigned char PicoVideoRead8HV_L(void) +{ + u32 d = (SekCyclesDone() - line_base_cycles) & 0x1ff; // FIXME + if (Pico.video.reg[12]&1) + d = hcounts_40[d]; + else d = hcounts_32[d]; + elprintf(EL_HVCNT, "hcounter: %02x (%i) @ %06x", d, SekCyclesDone(), SekPc); + return d; } // vim:shiftwidth=2:ts=2:expandtab -- 2.39.2