From 2ddb257a8db9ac05abd85e2d33c074fbc9fe07dc Mon Sep 17 00:00:00 2001 From: Antoine GOHIN Date: Tue, 8 Sep 2026 11:34:50 +0200 Subject: [PATCH 1/7] NES: Rainbow - updates to match documentation and hardware behavior - fixed jitter counter logic - CHR reads (and debug reads) now target only first 4K of mapper RAM - removed reads from registers $412A-$412D, $412F - CHR modes 4, 5, 6, 7 are all 512B banking mode (4) - Windows Mode bank can only be 0, 1, 2 or 3 to address first 4K of mapper RAM - fixed register $412F: Attribute/Background extended mode - fixed debugger value ($4175, Scroll Y) - fixed debugger value ($4107/17, PRG-RAM Bank 1) - fixed $4011 output if IPCM is disabled - fixed Windows Split Mode: Y scroll capped to 239 and new value only updated during VBlank - fixed Wi-Fi IRQ condition - fixed register $4161 returned value (IRQ must be enable) --- Core/NES/Mappers/Homebrew/Rainbow.cpp | 90 ++++++++++++++---------- Core/NES/Mappers/Homebrew/Rainbow.h | 1 + Core/NES/Mappers/Homebrew/RainbowAudio.h | 7 ++ 3 files changed, 59 insertions(+), 39 deletions(-) diff --git a/Core/NES/Mappers/Homebrew/Rainbow.cpp b/Core/NES/Mappers/Homebrew/Rainbow.cpp index 1c6e9daea2..318a06c409 100644 --- a/Core/NES/Mappers/Homebrew/Rainbow.cpp +++ b/Core/NES/Mappers/Homebrew/Rainbow.cpp @@ -114,7 +114,7 @@ uint8_t Rainbow::ReadRam(uint16_t addr) if(_cpuIrqAckOn4011) { AckCpuIrq(); } - return (_audio->GetLastOutput() << 1); + return _audio->GetLastOutput4011(_console->GetMemoryManager()->GetOpenBus()); } return BaseMapper::InternalRead(addr); } @@ -264,7 +264,11 @@ void Rainbow::ProcessCpuClock() { BaseProcessCpuClock(); - _jitterCounter++; + if(_slIrqPending) { + _jitterCounter++; + } else { + _jitterCounter = 0; + } _parityCounter = !_parityCounter; _audio->Clock(); @@ -322,6 +326,10 @@ uint8_t Rainbow::MapperReadVram(uint16_t addr, MemoryOperationType memoryOperati } } + if(!_inFrame) { + _windowPosY = _windowScrollY; + } + _ppuReadCounter++; DetectScanlineStart(addr); @@ -346,6 +354,7 @@ uint8_t Rainbow::MapperReadVram(uint16_t addr, MemoryOperationType memoryOperati _ntFetchCounter++; if(_ntFetchCounter == 33) { _inHBlank = true; + _windowPosY = _windowPosY == 239 ? 0 : _windowPosY + 1; } _inWindow = false; @@ -358,14 +367,12 @@ uint8_t Rainbow::MapperReadVram(uint16_t addr, MemoryOperationType memoryOperati uint8_t shift = 0; if(_inWindow) { - uint8_t scanline = _ntFetchCounter >= 49 ? _scanlineCounter + 1 : _scanlineCounter; - uint8_t windowScanline = (scanline + _windowScrollY) % 240; uint8_t column = (_ntFetchCounter + 1) % 50; - uint16_t ntAddr = ((windowScanline / 8 * 32) + ((column + _windowScrollX) & 0x1F)); + uint16_t ntAddr = ((_windowPosY / 8 * 32) + ((column + _windowScrollX) & 0x1F)); if(!isAttributeFetch) { addr = ntAddr; } else { - addr = 0x3C0 + (((windowScanline >> 2) & 0xF8) | (((column + _windowScrollX) & 0x1F) >> 2)); + addr = 0x3C0 + (((_windowPosY >> 2) & 0xF8) | (((column + _windowScrollX) & 0x1F) >> 2)); shift = ((ntAddr >> 4) & 0x04) | (ntAddr & 0x02); } } @@ -402,13 +409,11 @@ uint8_t Rainbow::MapperReadVram(uint16_t addr, MemoryOperationType memoryOperati //Tile data fetches bool isBgFetch = _ntFetchCounter < 33 || _ntFetchCounter >= 49; if(_inWindow && isBgFetch) { - uint8_t scanline = _ntFetchCounter >= 49 ? _scanlineCounter + 1 : _scanlineCounter; - uint8_t windowScanline = (scanline + _windowScrollY) % 240; if(_overrideTileFetch) { - uint32_t fetchAddr = (addr & 0xFF8) | (windowScanline & 0x07) | ((_extData & 0x3F) << 12) | (_bgExtModeOffset << 18); + uint32_t fetchAddr = (addr & 0xFF8) | (_windowPosY & 0x07) | ((_extData & 0x3F) << 12) | (_bgExtModeOffset << 18); return ReadChr(fetchAddr, addr); } else { - uint32_t fetchAddr = (addr & 0x1FF8) | (windowScanline & 0x07); + uint32_t fetchAddr = (addr & 0x1FF8) | (_windowPosY & 0x07); return InternalReadVram(fetchAddr); } } else if(_overrideTileFetch && isBgFetch) { @@ -448,18 +453,16 @@ uint8_t Rainbow::ReadChr(uint32_t fetchAddr, uint16_t ppuAddr) default: case 0: return _chrRomSize ? _chrRom[fetchAddr & (_chrRomSize - 1)] : 0; case 1: return _chrRamSize ? _chrRam[fetchAddr & (_chrRamSize - 1)] : 0; - case 2: return _mapperRam[fetchAddr & 0x1FFF]; + case 2: return _mapperRam[fetchAddr & 0x0FFF]; case 3: return GetNametable((ppuAddr & 0x400) >> 10)[ppuAddr & 0x3FF]; } } void Rainbow::UpdateIrqStatus() { - bool active = (_cpuIrqEnabled && _cpuIrqPending) || (_slIrqEnabled && _slIrqPending); + _wifiIrqPending = _wifiIrqEnabled && _dataReceived; + bool active = (_cpuIrqEnabled && _cpuIrqPending) || (_slIrqEnabled && _slIrqPending) || _wifiIrqPending; if(active) { - if(!_console->GetCpu()->HasIrqSource(IRQSource::External)) { - _jitterCounter = 0; - } _console->GetCpu()->SetIrqSource(IRQSource::External); } else { _console->GetCpu()->ClearIrqSource(IRQSource::External); @@ -531,14 +534,6 @@ uint8_t Rainbow::ReadRegister(uint16_t addr) case 0x4100: return _highMode | (_lowMode << 7); case 0x4120: return _chrMode | ((uint8_t)_windowEnabled << 4) | ((uint8_t)_spriteExtMode << 5) | (_chrSource << 6); - case 0x412A: - case 0x412B: - case 0x412C: - case 0x412D: - return _ntControl[addr - 0x412A].ToByte(); - - case 0x412F: return _windowControl.ToByte(); - case 0x4150: return (uint8_t)_scanlineCounter; case 0x4151: @@ -551,7 +546,8 @@ uint8_t Rainbow::ReadRegister(uint16_t addr) case 0x4154: return _jitterCounter; case 0x4157: return ((uint8_t)_parityCounter << 7); - case 0x415F: { + case 0x415F: + { uint8_t value = _mapperRam[_fpgaRamAddr]; _fpgaRamAddr = (_fpgaRamAddr + _fpgaRamInc) & 0x1FFF; return value; @@ -559,10 +555,10 @@ uint8_t Rainbow::ReadRegister(uint16_t addr) case 0x4160: return MAPPER_VERSION; case 0x4161: - return ( - (uint8_t)_wifiIrqPending | - ((uint8_t)_cpuIrqPending << 6) | - ((uint8_t)_slIrqPending << 7)); + return + uint8_t(_wifiIrqEnabled && _dataReceived) | + (uint8_t(_cpuIrqEnabled && _cpuIrqPending) << 6) | + (uint8_t(_slIrqEnabled && _slIrqPending) << 7); case 0x4280: GenerateOamSlowUpdate(); break; case 0x4282: GenerateExtUpdate(); break; @@ -631,6 +627,7 @@ void Rainbow::WriteRegister(uint16_t addr, uint8_t value) case 0x4120: _chrMode = value & 0x07; + if(_chrMode > 4) _chrMode = 4; _windowEnabled = value & 0x10; _spriteExtMode = value & 0x20; _chrSource = (value & 0xC0) >> 6; @@ -641,18 +638,21 @@ void Rainbow::WriteRegister(uint16_t addr, uint8_t value) case 0x4124: _fillModeTileIndex = value; break; case 0x4125: _fillModeAttrIndex = value & 0x03; break; - case 0x412E: _windowBank = value; break; + case 0x412E: _windowBank = value & 0x03; break; case 0x412F: - _windowControl.BgExtMode = value & 0x01; - _windowControl.AttrExtMode = value & 0x02; + _windowControl.AttrExtMode = value & 0x01; + _windowControl.BgExtMode = value & 0x02; _windowControl.FpgaRamSrc = (value & 0x0C) >> 2; _windowControl.FillMode = value & 0x20; _windowControl.Source = (value & 0xC0) >> 6; //todo this is writeable/readable but ignored? break; case 0x4150: _slIrqScanline = value; break; - case 0x4151: _slIrqEnabled = true; break; + case 0x4151: + _slIrqEnabled = true; + UpdateIrqStatus(); + break; case 0x4152: _slIrqEnabled = false; @@ -707,11 +707,22 @@ void Rainbow::WriteRegister(uint16_t addr, uint8_t value) case 0x4172: _windowY1 = value; break; case 0x4173: _windowY2 = value; break; case 0x4174: _windowScrollX = value & 0x1F; break; - case 0x4175: _windowScrollY = value; break; + case 0x4175: + if(value < 240) _windowScrollY = value; + else _windowScrollY = 239; + break; case 0x4190: _espEnabled = value & 0x01; _wifiIrqEnabled = value & 0x02; + + if(!_espEnabled) { + _dataReceived = false; + _dataSent = true; + } + + UpdateIrqStatus(); + break; case 0x4191: _dataReceived = false; break; @@ -785,16 +796,16 @@ vector Rainbow::GetMapperStateEntries() case 2: source = "PRG-RAM"; break; case 3: source = "FPGA RAM"; break; } - entries.push_back(MapperStateEntry("$4116.6-7", "PRG-RAM Bank 0 Source", source)); + entries.push_back(MapperStateEntry("$4106.6-7", "PRG-RAM Bank 0 Source", source)); entries.push_back(MapperStateEntry("$4107/17", "PRG-RAM Bank 1", _lowBanks[1], MapperStateValueType::Number16)); - switch((_lowBanks[0] & 0xC000) >> 14) { + switch((_lowBanks[1] & 0xC000) >> 14) { case 0: case 1: source = "PRG-ROM"; break; case 2: source = "PRG-RAM"; break; case 3: source = "FPGA RAM"; break; } - entries.push_back(MapperStateEntry("$4117.6-7", "PRG-RAM Bank 1 Source", source)); + entries.push_back(MapperStateEntry("$4107.6-7", "PRG-RAM Bank 1 Source", source)); for(int i = 0; i < 8; i++) { entries.push_back(MapperStateEntry( @@ -804,7 +815,7 @@ vector Rainbow::GetMapperStateEntries() MapperStateValueType::Number16)); entries.push_back(MapperStateEntry( - HexUtilities::ToHex(0x4118 + i) + ".7", + HexUtilities::ToHex(0x4108 + i) + ".7", "ROM Bank " + std::to_string(i) + " Source", (string)((_highBanks[i] & 0x8000) ? "RAM" : "ROM"))); } @@ -901,7 +912,7 @@ vector Rainbow::GetMapperStateEntries() entries.push_back(MapperStateEntry("$4172", "Start Scanline", _windowY1, MapperStateValueType::Number8)); entries.push_back(MapperStateEntry("$4173", "End Scanline", _windowY2, MapperStateValueType::Number8)); entries.push_back(MapperStateEntry("$4174.0-4", "Scroll X", _windowScrollX, MapperStateValueType::Number8)); - entries.push_back(MapperStateEntry("$4175", "Scroll Y", _windowScrollX, MapperStateValueType::Number8)); + entries.push_back(MapperStateEntry("$4175", "Scroll Y", _windowScrollY, MapperStateValueType::Number8)); entries.push_back(MapperStateEntry("", "Wi-Fi")); entries.push_back(MapperStateEntry("$4190.0", "ESP Enabled", _espEnabled)); @@ -950,7 +961,7 @@ uint8_t Rainbow::DebugReadChr(ExtModeConfig& cfg, uint32_t addr) default: case 0: return _chrRomSize ? _chrRom[addr & (_chrRomSize - 1)] : 0; case 1: return _chrRamSize ? _chrRam[addr & (_chrRamSize - 1)] : 0; - case 2: return cfg.ExtRam[addr & 0x1FFF]; + case 2: return cfg.ExtRam[addr & 0x0FFF]; case 3: return GetNametable((addr & 0x400) >> 10)[addr & 0x3FF]; } } @@ -1050,6 +1061,7 @@ void Rainbow::Serialize(Serializer& s) SV(_windowY2); SV(_windowScrollX); SV(_windowScrollY); + SV(_windowPosY); SV(_inWindow); SV(_slIrqEnabled); SV(_slIrqPending); diff --git a/Core/NES/Mappers/Homebrew/Rainbow.h b/Core/NES/Mappers/Homebrew/Rainbow.h index 952e5b7e16..c52dd1740d 100644 --- a/Core/NES/Mappers/Homebrew/Rainbow.h +++ b/Core/NES/Mappers/Homebrew/Rainbow.h @@ -63,6 +63,7 @@ class Rainbow : public BaseMapper, public IExtModeMapperDebug uint8_t _windowY2 = 0; uint8_t _windowScrollX = 0; uint8_t _windowScrollY = 0; + uint8_t _windowPosY = 0; bool _inWindow = false; bool _slIrqEnabled = false; diff --git a/Core/NES/Mappers/Homebrew/RainbowAudio.h b/Core/NES/Mappers/Homebrew/RainbowAudio.h index f8dd4bba6f..a0c64be71c 100644 --- a/Core/NES/Mappers/Homebrew/RainbowAudio.h +++ b/Core/NES/Mappers/Homebrew/RainbowAudio.h @@ -68,6 +68,13 @@ class RainbowAudio final : public ISerializable return _lastOutput; } + uint8_t GetLastOutput4011(uint8_t openBus) + { + return _outputTo4011 + ? static_cast(_lastOutput << 1) + : openBus; + } + void WriteRegister(uint16_t addr, uint8_t value) { addr &= 0x0F; From e79cadc1312fdec2e1dd426c16527b5a27e8b138 Mon Sep 17 00:00:00 2001 From: Antoine GOHIN Date: Fri, 19 Dec 2025 16:43:10 +0100 Subject: [PATCH 2/7] NES: Rainbow - updated Window Split detection --- Core/NES/Mappers/Homebrew/Rainbow.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/Core/NES/Mappers/Homebrew/Rainbow.cpp b/Core/NES/Mappers/Homebrew/Rainbow.cpp index 318a06c409..903dc61ace 100644 --- a/Core/NES/Mappers/Homebrew/Rainbow.cpp +++ b/Core/NES/Mappers/Homebrew/Rainbow.cpp @@ -300,18 +300,22 @@ void Rainbow::UpdateInWindowFlag() bool yMatch; bool xMatch; - uint8_t scanline = _ntFetchCounter >= 49 ? _scanlineCounter + 1 : _scanlineCounter; - if(_windowY1 >= _windowY2) { - yMatch = scanline <= _windowY2 || scanline > _windowY1; - } else { + uint8_t scanline = _ntFetchCounter >= 41 ? _scanlineCounter + 1 : _scanlineCounter; + if(_windowY1 == _windowY2) { + yMatch = scanline == _windowY1; + } else if(_windowY1 < _windowY2) { yMatch = scanline >= _windowY1 && scanline <= _windowY2; + } else if(_windowY1 > _windowY2) { + yMatch = scanline <= _windowY2 || scanline >= _windowY1; } - uint8_t column = (_ntFetchCounter + 1) % 50; - if(_windowX1 >= _windowX2) { - xMatch = column <= _windowX2 || column > _windowX1; - } else { + uint8_t column = (_ntFetchCounter + 1) % 42; + if(_windowX1 == _windowX2) { + xMatch = column == _windowX1; + } else if(_windowX1 < _windowX2) { xMatch = column >= _windowX1 && column <= _windowX2; + } else if(_windowX1 > _windowX2) { + xMatch = column <= _windowX2 || column >= _windowX1; } _inWindow = xMatch && yMatch; From ce121008e80591a75f0231249ed23c8243f8fcb2 Mon Sep 17 00:00:00 2001 From: Antoine GOHIN Date: Thu, 4 Jun 2026 12:20:14 +0200 Subject: [PATCH 3/7] NES: Rainbow - fixed window split mode / in-window detection --- Core/NES/Mappers/Homebrew/Rainbow.cpp | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/Core/NES/Mappers/Homebrew/Rainbow.cpp b/Core/NES/Mappers/Homebrew/Rainbow.cpp index 903dc61ace..d9616c240f 100644 --- a/Core/NES/Mappers/Homebrew/Rainbow.cpp +++ b/Core/NES/Mappers/Homebrew/Rainbow.cpp @@ -300,22 +300,18 @@ void Rainbow::UpdateInWindowFlag() bool yMatch; bool xMatch; - uint8_t scanline = _ntFetchCounter >= 41 ? _scanlineCounter + 1 : _scanlineCounter; - if(_windowY1 == _windowY2) { - yMatch = scanline == _windowY1; - } else if(_windowY1 < _windowY2) { - yMatch = scanline >= _windowY1 && scanline <= _windowY2; - } else if(_windowY1 > _windowY2) { + uint8_t scanline = _ntFetchCounter >= 49 ? _scanlineCounter + 1 : _scanlineCounter; + if(_windowY1 > _windowY2) { yMatch = scanline <= _windowY2 || scanline >= _windowY1; + } else { + yMatch = scanline >= _windowY1 && scanline <= _windowY2; } - uint8_t column = (_ntFetchCounter + 1) % 42; - if(_windowX1 == _windowX2) { - xMatch = column == _windowX1; - } else if(_windowX1 < _windowX2) { - xMatch = column >= _windowX1 && column <= _windowX2; - } else if(_windowX1 > _windowX2) { + uint8_t column = (_ntFetchCounter + 1) % 50; + if(_windowX1 > _windowX2) { xMatch = column <= _windowX2 || column >= _windowX1; + } else { + xMatch = column >= _windowX1 && column <= _windowX2; } _inWindow = xMatch && yMatch; From 6ca8e65228c632a9e30a968b46986f95b3df3bed Mon Sep 17 00:00:00 2001 From: Antoine GOHIN Date: Mon, 16 Nov 2026 22:07:33 +0100 Subject: [PATCH 4/7] NES: Rainbow - Updated Window Split handler --- Core/NES/Mappers/Homebrew/Rainbow.cpp | 20 +++++++++----------- Core/NES/Mappers/Homebrew/Rainbow.h | 1 - 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/Core/NES/Mappers/Homebrew/Rainbow.cpp b/Core/NES/Mappers/Homebrew/Rainbow.cpp index d9616c240f..db0cc8006b 100644 --- a/Core/NES/Mappers/Homebrew/Rainbow.cpp +++ b/Core/NES/Mappers/Homebrew/Rainbow.cpp @@ -307,7 +307,7 @@ void Rainbow::UpdateInWindowFlag() yMatch = scanline >= _windowY1 && scanline <= _windowY2; } - uint8_t column = (_ntFetchCounter + 1) % 50; + uint8_t column = ((_ntFetchCounter + 1) % 50) & 0x1F; if(_windowX1 > _windowX2) { xMatch = column <= _windowX2 || column >= _windowX1; } else { @@ -326,10 +326,6 @@ uint8_t Rainbow::MapperReadVram(uint16_t addr, MemoryOperationType memoryOperati } } - if(!_inFrame) { - _windowPosY = _windowScrollY; - } - _ppuReadCounter++; DetectScanlineStart(addr); @@ -354,7 +350,6 @@ uint8_t Rainbow::MapperReadVram(uint16_t addr, MemoryOperationType memoryOperati _ntFetchCounter++; if(_ntFetchCounter == 33) { _inHBlank = true; - _windowPosY = _windowPosY == 239 ? 0 : _windowPosY + 1; } _inWindow = false; @@ -367,12 +362,14 @@ uint8_t Rainbow::MapperReadVram(uint16_t addr, MemoryOperationType memoryOperati uint8_t shift = 0; if(_inWindow) { + uint8_t scanline = _ntFetchCounter >= 49 ? _scanlineCounter + 1 : _scanlineCounter; + uint8_t windowScanline = (scanline + _windowScrollY) % 240; uint8_t column = (_ntFetchCounter + 1) % 50; - uint16_t ntAddr = ((_windowPosY / 8 * 32) + ((column + _windowScrollX) & 0x1F)); + uint16_t ntAddr = ((windowScanline / 8 * 32) + ((column + _windowScrollX) & 0x1F)); if(!isAttributeFetch) { addr = ntAddr; } else { - addr = 0x3C0 + (((_windowPosY >> 2) & 0xF8) | (((column + _windowScrollX) & 0x1F) >> 2)); + addr = 0x3C0 + (((windowScanline >> 2) & 0xF8) | (((column + _windowScrollX) & 0x1F) >> 2)); shift = ((ntAddr >> 4) & 0x04) | (ntAddr & 0x02); } } @@ -409,11 +406,13 @@ uint8_t Rainbow::MapperReadVram(uint16_t addr, MemoryOperationType memoryOperati //Tile data fetches bool isBgFetch = _ntFetchCounter < 33 || _ntFetchCounter >= 49; if(_inWindow && isBgFetch) { + uint8_t scanline = _ntFetchCounter >= 49 ? _scanlineCounter + 1 : _scanlineCounter; + uint8_t windowScanline = (scanline + _windowScrollY) % 240; if(_overrideTileFetch) { - uint32_t fetchAddr = (addr & 0xFF8) | (_windowPosY & 0x07) | ((_extData & 0x3F) << 12) | (_bgExtModeOffset << 18); + uint32_t fetchAddr = (addr & 0xFF8) | (windowScanline & 0x07) | ((_extData & 0x3F) << 12) | (_bgExtModeOffset << 18); return ReadChr(fetchAddr, addr); } else { - uint32_t fetchAddr = (addr & 0x1FF8) | (_windowPosY & 0x07); + uint32_t fetchAddr = (addr & 0x1FF8) | (windowScanline & 0x07); return InternalReadVram(fetchAddr); } } else if(_overrideTileFetch && isBgFetch) { @@ -1061,7 +1060,6 @@ void Rainbow::Serialize(Serializer& s) SV(_windowY2); SV(_windowScrollX); SV(_windowScrollY); - SV(_windowPosY); SV(_inWindow); SV(_slIrqEnabled); SV(_slIrqPending); diff --git a/Core/NES/Mappers/Homebrew/Rainbow.h b/Core/NES/Mappers/Homebrew/Rainbow.h index c52dd1740d..952e5b7e16 100644 --- a/Core/NES/Mappers/Homebrew/Rainbow.h +++ b/Core/NES/Mappers/Homebrew/Rainbow.h @@ -63,7 +63,6 @@ class Rainbow : public BaseMapper, public IExtModeMapperDebug uint8_t _windowY2 = 0; uint8_t _windowScrollX = 0; uint8_t _windowScrollY = 0; - uint8_t _windowPosY = 0; bool _inWindow = false; bool _slIrqEnabled = false; From d0b2fafaa056c0a7de7e49b10f43191790462173 Mon Sep 17 00:00:00 2001 From: Antoine GOHIN Date: Mon, 16 Nov 2026 22:12:13 +0100 Subject: [PATCH 5/7] NES: Rainbow - Removed OAM resets during rendering - Removed OAM address reset at frame start - Removed OAM mappings clear before sprite evaluation --- Core/NES/Mappers/Homebrew/Rainbow.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/Core/NES/Mappers/Homebrew/Rainbow.cpp b/Core/NES/Mappers/Homebrew/Rainbow.cpp index db0cc8006b..bd3057585b 100644 --- a/Core/NES/Mappers/Homebrew/Rainbow.cpp +++ b/Core/NES/Mappers/Homebrew/Rainbow.cpp @@ -290,7 +290,6 @@ void Rainbow::ProcessCpuClock() _scanlineCounter = -1; _ntFetchCounter = 0; _ntReadCounter = 0; - _oamAddr = 0; } } } @@ -481,8 +480,6 @@ void Rainbow::ProcessSpriteEval() int scanline = _scanlineCounter; int height = (_largeSprites ? 16 : 8); - memset(_oamMappings, 0, sizeof(_oamMappings)); - for(int i = 0; i < 64; i++) { uint8_t y = _oamPosY[i]; if(scanline >= y && scanline < y + height) { From 90d283485042117cf7ac0293a0e2db689d6c76f1 Mon Sep 17 00:00:00 2001 From: Antoine GOHIN Date: Mon, 16 Nov 2026 22:15:33 +0100 Subject: [PATCH 6/7] NES: Rainbow - Fixed scanline IRQ offset counting - Count the third identical nametable read as IRQ offset 1 - Initialize the PPU read counter to 1 when detecting scanline start --- Core/NES/Mappers/Homebrew/Rainbow.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Core/NES/Mappers/Homebrew/Rainbow.cpp b/Core/NES/Mappers/Homebrew/Rainbow.cpp index bd3057585b..50604cfb68 100644 --- a/Core/NES/Mappers/Homebrew/Rainbow.cpp +++ b/Core/NES/Mappers/Homebrew/Rainbow.cpp @@ -501,7 +501,8 @@ void Rainbow::DetectScanlineStart(uint16_t addr) _ntReadCounter++; if(_ntReadCounter >= 2) { - //After 3 identical NT reads, trigger IRQ when the following attribute byte is read + //The third consecutive read from the same NT address starts the scanline + //and counts as PPU read 1 for scanline IRQ timing if(!_inFrame) { _inFrame = true; _scanlineCounter = 0; @@ -512,7 +513,7 @@ void Rainbow::DetectScanlineStart(uint16_t addr) ProcessSpriteEval(); _ntFetchCounter = 0; - _ppuReadCounter = 0; + _ppuReadCounter = 1; _ntReadCounter = 0; _inHBlank = false; } From 19c0fab0d2256187359ae898f75585ba066cf179 Mon Sep 17 00:00:00 2001 From: Broke Studio Date: Tue, 17 Nov 2026 18:05:44 +0100 Subject: [PATCH 7/7] NES: Rainbow - align window source and initial send status with hardware --- Core/NES/Mappers/Homebrew/Rainbow.cpp | 2 +- Core/NES/Mappers/Homebrew/Rainbow.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Core/NES/Mappers/Homebrew/Rainbow.cpp b/Core/NES/Mappers/Homebrew/Rainbow.cpp index 50604cfb68..733d09bedd 100644 --- a/Core/NES/Mappers/Homebrew/Rainbow.cpp +++ b/Core/NES/Mappers/Homebrew/Rainbow.cpp @@ -642,7 +642,7 @@ void Rainbow::WriteRegister(uint16_t addr, uint8_t value) _windowControl.BgExtMode = value & 0x02; _windowControl.FpgaRamSrc = (value & 0x0C) >> 2; _windowControl.FillMode = value & 0x20; - _windowControl.Source = (value & 0xC0) >> 6; //todo this is writeable/readable but ignored? + _windowControl.Source = 0b10; // Forced to FPGA-RAM break; case 0x4150: _slIrqScanline = value; break; diff --git a/Core/NES/Mappers/Homebrew/Rainbow.h b/Core/NES/Mappers/Homebrew/Rainbow.h index 952e5b7e16..e28073f29f 100644 --- a/Core/NES/Mappers/Homebrew/Rainbow.h +++ b/Core/NES/Mappers/Homebrew/Rainbow.h @@ -116,7 +116,7 @@ class Rainbow : public BaseMapper, public IExtModeMapperDebug bool _espEnabled = false; bool _wifiIrqEnabled = false; bool _wifiIrqPending = false; - bool _dataSent = false; + bool _dataSent = true; bool _dataReceived = false; bool _dataReady = false; uint8_t _sendSrcAddr = 0;