From d3e21d7463c4ef99cfb15f3d003912f40bebe887 Mon Sep 17 00:00:00 2001 From: OV2 Date: Sat, 25 Aug 2018 21:20:36 +0200 Subject: [PATCH] Move identical VRAMReadBuffer updates to inline function --- ppu.cpp | 40 ++++------------------------------------ ppu.h | 13 +++++++++++++ 2 files changed, 17 insertions(+), 36 deletions(-) diff --git a/ppu.cpp b/ppu.cpp index 7483c325..001a4a23 100644 --- a/ppu.cpp +++ b/ppu.cpp @@ -716,15 +716,7 @@ void S9xSetPPU (uint8 Byte, uint16 Address) PPU.VMA.Address &= 0xff00; PPU.VMA.Address |= Byte; - if (PPU.VMA.FullGraphicCount) - { - uint32 addr = PPU.VMA.Address; - uint32 rem = addr & PPU.VMA.Mask1; - uint32 address = (addr & ~PPU.VMA.Mask1) + (rem >> PPU.VMA.Shift) + ((rem & (PPU.VMA.FullGraphicCount - 1)) << 3); - PPU.VRAMReadBuffer = READ_WORD(Memory.VRAM + ((address << 1) & 0xffff)); - } - else - PPU.VRAMReadBuffer = READ_WORD(Memory.VRAM + ((PPU.VMA.Address << 1) & 0xffff)); + S9xUpdateVRAMReadBuffer(); break; @@ -732,15 +724,7 @@ void S9xSetPPU (uint8 Byte, uint16 Address) PPU.VMA.Address &= 0x00ff; PPU.VMA.Address |= Byte << 8; - if (PPU.VMA.FullGraphicCount) - { - uint32 addr = PPU.VMA.Address; - uint32 rem = addr & PPU.VMA.Mask1; - uint32 address = (addr & ~PPU.VMA.Mask1) + (rem >> PPU.VMA.Shift) + ((rem & (PPU.VMA.FullGraphicCount - 1)) << 3); - PPU.VRAMReadBuffer = READ_WORD(Memory.VRAM + ((address << 1) & 0xffff)); - } - else - PPU.VRAMReadBuffer = READ_WORD(Memory.VRAM + ((PPU.VMA.Address << 1) & 0xffff)); + S9xUpdateVRAMReadBuffer(); break; @@ -1311,15 +1295,7 @@ uint8 S9xGetPPU (uint16 Address) byte = PPU.VRAMReadBuffer & 0xff; if (!PPU.VMA.High) { - if (PPU.VMA.FullGraphicCount) - { - uint32 addr = PPU.VMA.Address; - uint32 rem = addr & PPU.VMA.Mask1; - uint32 address = (addr & ~PPU.VMA.Mask1) + (rem >> PPU.VMA.Shift) + ((rem & (PPU.VMA.FullGraphicCount - 1)) << 3); - PPU.VRAMReadBuffer = READ_WORD(Memory.VRAM + ((address << 1) & 0xffff)); - } - else - PPU.VRAMReadBuffer = READ_WORD(Memory.VRAM + ((PPU.VMA.Address << 1) & 0xffff)); + S9xUpdateVRAMReadBuffer(); PPU.VMA.Address += PPU.VMA.Increment; } @@ -1333,15 +1309,7 @@ uint8 S9xGetPPU (uint16 Address) byte = (PPU.VRAMReadBuffer >> 8) & 0xff; if (PPU.VMA.High) { - if (PPU.VMA.FullGraphicCount) - { - uint32 addr = PPU.VMA.Address; - uint32 rem = addr & PPU.VMA.Mask1; - uint32 address = (addr & ~PPU.VMA.Mask1) + (rem >> PPU.VMA.Shift) + ((rem & (PPU.VMA.FullGraphicCount - 1)) << 3); - PPU.VRAMReadBuffer = READ_WORD(Memory.VRAM + ((address << 1) & 0xffff)); - } - else - PPU.VRAMReadBuffer = READ_WORD(Memory.VRAM + ((PPU.VMA.Address << 1) & 0xffff)); + S9xUpdateVRAMReadBuffer(); PPU.VMA.Address += PPU.VMA.Increment; } diff --git a/ppu.h b/ppu.h index 136e6109..b4fcf1bc 100644 --- a/ppu.h +++ b/ppu.h @@ -420,6 +420,19 @@ static inline void FLUSH_REDRAW (void) S9xUpdateScreen(); } +static inline void S9xUpdateVRAMReadBuffer() +{ + if (PPU.VMA.FullGraphicCount) + { + uint32 addr = PPU.VMA.Address; + uint32 rem = addr & PPU.VMA.Mask1; + uint32 address = (addr & ~PPU.VMA.Mask1) + (rem >> PPU.VMA.Shift) + ((rem & (PPU.VMA.FullGraphicCount - 1)) << 3); + PPU.VRAMReadBuffer = READ_WORD(Memory.VRAM + ((address << 1) & 0xffff)); + } + else + PPU.VRAMReadBuffer = READ_WORD(Memory.VRAM + ((PPU.VMA.Address << 1) & 0xffff)); +} + static inline void REGISTER_2104 (uint8 Byte) { if (!(PPU.OAMFlip & 1))