From 1ca15b4a4f2cbbf3df64892eea41cdefc0a1ceb0 Mon Sep 17 00:00:00 2001 From: Brandon Wright Date: Mon, 20 Aug 2018 12:53:20 -0500 Subject: [PATCH] Proper write-twice behavior for $2122. --- ppu.h | 18 +++++------------- snapshot.cpp | 1 + snapshot.h | 2 +- 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/ppu.h b/ppu.h index 2ad0aa15..8cce413d 100644 --- a/ppu.h +++ b/ppu.h @@ -294,6 +294,7 @@ struct SPPU bool8 CGFLIP; uint8 CGFLIPRead; uint8 CGADD; + uint8 CGSavedByte; uint16 CGDATA[256]; struct SOBJ OBJ[128]; @@ -719,12 +720,12 @@ static inline void REGISTER_2122 (uint8 Byte) { if (PPU.CGFLIP) { - if ((Byte & 0x7f) != (PPU.CGDATA[PPU.CGADD] >> 8)) + if ((Byte & 0x7f) != (PPU.CGDATA[PPU.CGADD] >> 8) || PPU.CGSavedByte != (uint8) (PPU.CGDATA[PPU.CGADD] & 0xff)) { FLUSH_REDRAW(); - PPU.CGDATA[PPU.CGADD] &= 0x00ff; - PPU.CGDATA[PPU.CGADD] |= (Byte & 0x7f) << 8; + PPU.CGDATA[PPU.CGADD] = (Byte & 0x7f) << 8 | PPU.CGSavedByte; IPPU.ColorsChanged = TRUE; + IPPU.Red[PPU.CGADD] = IPPU.XB[PPU.CGSavedByte & 0x1f]; IPPU.Blue[PPU.CGADD] = IPPU.XB[(Byte >> 2) & 0x1f]; IPPU.Green[PPU.CGADD] = IPPU.XB[(PPU.CGDATA[PPU.CGADD] >> 5) & 0x1f]; IPPU.ScreenColors[PPU.CGADD] = (uint16) BUILD_PIXEL(IPPU.Red[PPU.CGADD], IPPU.Green[PPU.CGADD], IPPU.Blue[PPU.CGADD]); @@ -734,16 +735,7 @@ static inline void REGISTER_2122 (uint8 Byte) } else { - if (Byte != (uint8) (PPU.CGDATA[PPU.CGADD] & 0xff)) - { - FLUSH_REDRAW(); - PPU.CGDATA[PPU.CGADD] &= 0x7f00; - PPU.CGDATA[PPU.CGADD] |= Byte; - IPPU.ColorsChanged = TRUE; - IPPU.Red[PPU.CGADD] = IPPU.XB[Byte & 0x1f]; - IPPU.Green[PPU.CGADD] = IPPU.XB[(PPU.CGDATA[PPU.CGADD] >> 5) & 0x1f]; - IPPU.ScreenColors[PPU.CGADD] = (uint16) BUILD_PIXEL(IPPU.Red[PPU.CGADD], IPPU.Green[PPU.CGADD], IPPU.Blue[PPU.CGADD]); - } + PPU.CGSavedByte = Byte; } PPU.CGFLIP ^= 1; diff --git a/snapshot.cpp b/snapshot.cpp index c62c5079..45974249 100644 --- a/snapshot.cpp +++ b/snapshot.cpp @@ -433,6 +433,7 @@ static FreezeData SnapPPU[] = INT_ENTRY(6, CGFLIP), INT_ENTRY(6, CGFLIPRead), INT_ENTRY(6, CGADD), + INT_ENTRY(11, CGSavedByte), ARRAY_ENTRY(6, CGDATA, 256, uint16_ARRAY_V), #define O(N) \ INT_ENTRY(6, OBJ[N].HPos), \ diff --git a/snapshot.h b/snapshot.h index a88d6123..c219fa70 100644 --- a/snapshot.h +++ b/snapshot.h @@ -198,7 +198,7 @@ #define SNAPSHOT_MAGIC "#!s9xsnp" #define SNAPSHOT_VERSION_IRQ 7 #define SNAPSHOT_VERSION_BAPU 8 -#define SNAPSHOT_VERSION 10 +#define SNAPSHOT_VERSION 11 #define SUCCESS 1 #define WRONG_FORMAT (-1)