diff --git a/Core/Ppu.cpp b/Core/Ppu.cpp index a0ffefc..e29a4ec 100644 --- a/Core/Ppu.cpp +++ b/Core/Ppu.cpp @@ -524,6 +524,7 @@ void Ppu::LatchLocationValues() { _horizontalLocation = _cycle; _verticalLocation = _scanline; + _locationLatched = true; } uint8_t Ppu::Read(uint16_t addr) @@ -606,6 +607,7 @@ uint8_t Ppu::Read(uint16_t addr) case 0x213E: + //STAT77 - PPU Status Flag and Version //TODO open bus on bit 4 //"The high/low selector is reset to elowf when $213f is read" @@ -615,9 +617,26 @@ uint8_t Ppu::Read(uint16_t addr) return ( (_timeOver ? 0x80 : 0) | (_rangeOver ? 0x40 : 0) | - 0x01 //PPU chip version + 0x01 //PPU (5c77) chip version ); + case 0x213F: { + //STAT78 - PPU Status Flag and Version + //TODO open bus on bit 5 + uint8_t value = ( + ((_frameCount & 0x01) ? 0x80 : 0) | + (_locationLatched ? 0x40 : 0) | + //TODO (_isPal ? 0x10 : 0) + 0x02 //PPU (5c78) chip version + ); + + if(_regs->GetIoPortOutput() & 0x80) { + _locationLatched = false; + } + + return value; + } + default: MessageManager::DisplayMessage("Debug", "Unimplemented register read: " + HexUtilities::ToHex(addr)); break; diff --git a/Core/Ppu.h b/Core/Ppu.h index b51dd21..498ee59 100644 --- a/Core/Ppu.h +++ b/Core/Ppu.h @@ -113,9 +113,9 @@ private: uint16_t _horizontalLocation = 0; bool _horizontalLocToggle = false; - uint16_t _verticalLocation = 0; bool _verticalLocationToggle = false; + bool _locationLatched = false; uint16_t _mode7MatrixA = 0; uint16_t _mode7MatrixB = 0;