diff --git a/ppu.cpp b/ppu.cpp index 129c0904..f7fd2862 100644 --- a/ppu.cpp +++ b/ppu.cpp @@ -485,7 +485,7 @@ void S9xSetPPU (uint8 Byte, uint16 Address) case 0x2102: // OAMADDL PPU.OAMAddr = ((Memory.FillRAM[0x2103] & 1) << 8) | Byte; - PPU.OAMFlip = 2; + PPU.OAMFlip = 0; PPU.OAMReadFlip = 0; PPU.SavedOAMAddr = PPU.OAMAddr; if (PPU.OAMPriorityRotation && PPU.FirstSprite != (PPU.OAMAddr >> 1)) diff --git a/ppu.h b/ppu.h index 4b0adc53..6346d325 100644 --- a/ppu.h +++ b/ppu.h @@ -419,6 +419,12 @@ static inline void FLUSH_REDRAW (void) static inline void REGISTER_2104 (uint8 Byte) { + if (!(PPU.OAMFlip & 1)) + { + PPU.OAMWriteRegister &= 0xff00; + PPU.OAMWriteRegister |= Byte; + } + if (PPU.OAMAddr & 0x100) { int addr = ((PPU.OAMAddr & 0x10f) << 1) + (PPU.OAMFlip & 1); @@ -440,33 +446,8 @@ static inline void REGISTER_2104 (uint8 Byte) pObj->Size = Byte & 128; } - PPU.OAMFlip ^= 1; - if (!(PPU.OAMFlip & 1)) - { - ++PPU.OAMAddr; - PPU.OAMAddr &= 0x1ff; - if (PPU.OAMPriorityRotation && PPU.FirstSprite != (PPU.OAMAddr >> 1)) - { - PPU.FirstSprite = (PPU.OAMAddr & 0xfe) >> 1; - IPPU.OBJChanged = TRUE; - } - } - else - { - if (PPU.OAMPriorityRotation && (PPU.OAMAddr & 1)) - IPPU.OBJChanged = TRUE; - } } - else - if (!(PPU.OAMFlip & 1)) - { - PPU.OAMWriteRegister &= 0xff00; - PPU.OAMWriteRegister |= Byte; - PPU.OAMFlip |= 1; - if (PPU.OAMPriorityRotation && (PPU.OAMAddr & 1)) - IPPU.OBJChanged = TRUE; - } - else + else if (PPU.OAMFlip & 1) { PPU.OAMWriteRegister &= 0x00ff; uint8 lowbyte = (uint8) (PPU.OAMWriteRegister); @@ -499,15 +480,24 @@ static inline void REGISTER_2104 (uint8 Byte) PPU.OBJ[addr].VPos = highbyte; } } + } - PPU.OAMFlip &= ~1; + PPU.OAMFlip ^= 1; + if (!(PPU.OAMFlip & 1)) + { ++PPU.OAMAddr; + PPU.OAMAddr &= 0x1ff; if (PPU.OAMPriorityRotation && PPU.FirstSprite != (PPU.OAMAddr >> 1)) { PPU.FirstSprite = (PPU.OAMAddr & 0xfe) >> 1; IPPU.OBJChanged = TRUE; } } + else + { + if (PPU.OAMPriorityRotation && (PPU.OAMAddr & 1)) + IPPU.OBJChanged = TRUE; + } } // This code is correct, however due to Snes9x's inaccurate timings, some games might be broken by this chage. :(