From e721f801366a35bc7b71c96b21609c890ece6c30 Mon Sep 17 00:00:00 2001 From: kub Date: Mon, 21 Sep 2020 21:02:51 +0200 Subject: [PATCH] vdp, fix for gfx save/load menu bg --- pico/pico.h | 2 +- pico/pico_int.h | 3 ++- pico/state.c | 5 +++++ pico/videoport.c | 33 ++++++++++++++++++++------------- platform/common/emu.c | 1 + 5 files changed, 29 insertions(+), 15 deletions(-) diff --git a/pico/pico.h b/pico/pico.h index 4cc29433..3c800f6a 100644 --- a/pico/pico.h +++ b/pico/pico.h @@ -197,7 +197,7 @@ void PicoDrawSetCallbacks(int (*begin)(unsigned int num), int (*end)(unsigned in void vidConvCpyRGB565(void *to, void *from, int pixels); #endif void PicoDoHighPal555(int sh, int line, struct PicoEState *est); -// internals +// internals, NB must keep in sync with ASM draw functions #define PDRAW_SPRITES_MOVED (1<<0) // SAT address modified #define PDRAW_WND_DIFF_PRIO (1<<1) // not all window tiles use same priority #define PDRAW_PARSE_SPRITES (1<<2) // SAT needs parsing diff --git a/pico/pico_int.h b/pico/pico_int.h index 1a1205f8..86cfb778 100644 --- a/pico/pico_int.h +++ b/pico/pico_int.h @@ -846,7 +846,7 @@ void ym2612_unpack_state(void); extern unsigned SATaddr, SATmask; static __inline void UpdateSAT(u32 a, u32 d) { - unsigned num = (a-SATaddr) >> 3; + unsigned num = (a^SATaddr) >> 3; Pico.est.rendstatus |= PDRAW_DIRTY_SPRITES; if (!(a & 4) && num < 128) { @@ -876,6 +876,7 @@ void PicoVideoFIFOMode(int active, int h40); int PicoVideoFIFOWrite(int count, int byte_p, unsigned sr_mask, unsigned sr_flags); void PicoVideoSave(void); void PicoVideoLoad(void); +void PicoVideoCacheSAT(void); // misc.c PICO_INTERNAL_ASM void memcpy16bswap(unsigned short *dest, void *src, int count); diff --git a/pico/state.c b/pico/state.c index da6b6fd8..17164251 100644 --- a/pico/state.c +++ b/pico/state.c @@ -710,6 +710,8 @@ int PicoStateLoadGfx(const char *fname) areaRead(&Pico.video, 1, sizeof(Pico.video), afile); } areaClose(afile); + + PicoVideoCacheSAT(); return 0; } @@ -719,6 +721,7 @@ struct PicoTmp unsigned short vram[0x8000]; unsigned short cram[0x40]; unsigned short vsram[0x40]; + unsigned int satcache[0x80]; //struct PicoMisc m; struct PicoVideo video; @@ -741,6 +744,7 @@ void *PicoTmpStateSave(void) memcpy(t->vram, PicoMem.vram, sizeof(PicoMem.vram)); memcpy(t->cram, PicoMem.cram, sizeof(PicoMem.cram)); memcpy(t->vsram, PicoMem.vsram, sizeof(PicoMem.vsram)); + memcpy(t->satcache, VdpSATCache, sizeof(VdpSATCache)); memcpy(&t->video, &Pico.video, sizeof(Pico.video)); #ifndef NO_32X @@ -763,6 +767,7 @@ void PicoTmpStateRestore(void *data) memcpy(PicoMem.vram, t->vram, sizeof(PicoMem.vram)); memcpy(PicoMem.cram, t->cram, sizeof(PicoMem.cram)); memcpy(PicoMem.vsram, t->vsram, sizeof(PicoMem.vsram)); + memcpy(VdpSATCache, t->satcache, sizeof(VdpSATCache)); memcpy(&Pico.video, &t->video, sizeof(Pico.video)); Pico.m.dirtyPal = 1; diff --git a/pico/videoport.c b/pico/videoport.c index cbcc60d3..fec862f7 100644 --- a/pico/videoport.c +++ b/pico/videoport.c @@ -999,6 +999,25 @@ unsigned char PicoVideoRead8HV_L(void) return d; } +void PicoVideoCacheSAT(void) +{ + struct PicoVideo *pv = &Pico.video; + int l; + + SATaddr = ((pv->reg[5]&0x7f) << 9) | ((pv->reg[6]&0x20) << 11); + SATmask = ~0x1ff; + if (pv->reg[12]&1) + SATaddr &= ~0x200, SATmask &= ~0x200; // H40, zero lowest SAT bit + + // rebuild SAT cache XXX wrong since cache and memory can differ + for (l = 0; l < 80; l++) { + ((u16 *)VdpSATCache)[l*2 ] = PicoMem.vram[(SATaddr>>1) + l*4 ]; + ((u16 *)VdpSATCache)[l*2 + 1] = PicoMem.vram[(SATaddr>>1) + l*4 + 1]; + } + + Pico.est.rendstatus |= PDRAW_SPRITES_MOVED; +} + void PicoVideoSave(void) { struct VdpFIFO *vf = &VdpFIFO; @@ -1014,7 +1033,6 @@ void PicoVideoLoad(void) { struct VdpFIFO *vf = &VdpFIFO; struct PicoVideo *pv = &Pico.video; - int l; // convert former dma_xfers (why was this in PicoMisc anyway?) if (Pico.m.dma_xfers) { @@ -1023,17 +1041,6 @@ void PicoVideoLoad(void) vf->fifo_total = Pico.m.dma_xfers; Pico.m.dma_xfers = 0; } - - SATaddr = ((pv->reg[5]&0x7f) << 9) | ((pv->reg[6]&0x20) << 11); - SATmask = ~0x1ff; - if (pv->reg[12]&1) - SATaddr &= ~0x200, SATmask &= ~0x200; // H40, zero lowest SAT bit - - // rebuild SAT cache XXX wrong since cache and memory can differ - for (l = 0; l < 80; l++) { - *((u16 *)VdpSATCache + 2*l ) = PicoMem.vram[(SATaddr>>1) + l*4 ]; - *((u16 *)VdpSATCache + 2*l+1) = PicoMem.vram[(SATaddr>>1) + l*4 + 1]; - } + PicoVideoCacheSAT(); } - // vim:shiftwidth=2:ts=2:expandtab diff --git a/platform/common/emu.c b/platform/common/emu.c index 15aa5392..04e26bf4 100644 --- a/platform/common/emu.c +++ b/platform/common/emu.c @@ -1219,6 +1219,7 @@ void emu_cmn_forced_frame(int no_scale, int do_emu) PicoDrawSetOutFormat(PDF_RGB555, 1); Pico.m.dirtyPal = 1; + Pico.est.rendstatus |= PDRAW_DIRTY_SPRITES; if (do_emu) PicoFrame(); else -- 2.39.5