From 9ab5ac3c13a0d4ea6189d280a7383fd10a3aab01 Mon Sep 17 00:00:00 2001 From: Lauchmelder Date: Sat, 30 Oct 2021 19:42:17 +0200 Subject: [PATCH] added ppu read latch --- NES Emulator/ppu.c | 6 ++++-- NES Emulator/ppu.h | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/NES Emulator/ppu.c b/NES Emulator/ppu.c index fb258ac..4e20927 100644 --- a/NES Emulator/ppu.c +++ b/NES Emulator/ppu.c @@ -131,7 +131,8 @@ Byte ppuRead(struct PPU* ppu, Word addr) { if (ppu->ppuAddress.raw < 0x2000) { - val = readCartridgePPU(ppu->bus->cartridge, ppu->ppuAddress.raw); + val = ppu->ppuReadLatch; + ppu->ppuReadLatch = readCartridgePPU(ppu->bus->cartridge, ppu->ppuAddress.raw); } else if (0x2000 <= ppu->ppuAddress.raw && ppu->ppuAddress.raw < 0x3F00) { @@ -140,7 +141,8 @@ Byte ppuRead(struct PPU* ppu, Word addr) if (effectiveAddress >= 0x2800) effectiveAddress -= 0x0400; - val = ppu->nameTables[0][(effectiveAddress - 0x2000) & 0x0FFF]; + val = ppu->ppuReadLatch; + ppu->ppuReadLatch = ppu->nameTables[0][(effectiveAddress - 0x2000) & 0x0FFF]; } else if (0x3F00 <= ppu->ppuAddress.raw && ppu->ppuAddress.raw < 0x4000) { diff --git a/NES Emulator/ppu.h b/NES Emulator/ppu.h index d0259cd..7d3c3bc 100644 --- a/NES Emulator/ppu.h +++ b/NES Emulator/ppu.h @@ -113,6 +113,7 @@ struct PPU Word raw; } ppuAddress; Byte ppuAddressWriteTarget; + Byte ppuReadLatch; Byte oamdma;