Skip to content

Commit

Permalink
NES: Make OAM decay more obvious by displaying a diagonal line of spr…
Browse files Browse the repository at this point in the history
…ites
  • Loading branch information
SourMesen committed Dec 3, 2023
1 parent 6142ba3 commit 08424ce
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 30 deletions.
15 changes: 9 additions & 6 deletions Core/Debugger/MemoryDumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,13 +231,16 @@ void MemoryDumper::SetMemoryValue(MemoryType memoryType, uint32_t address, uint8
//TODOv2 find a cleaner way to implement this
//Prevent invalid memory values
switch(memoryType) {
case MemoryType::SnesCgRam: if(address & 0x01) value &= 0x7F; break;
case MemoryType::NesPaletteRam: value &= 0x3F; break;
case MemoryType::PcePaletteRam: if(address & 0x01) value &= 0x01; break;
case MemoryType::SnesCgRam: src[address] = (address & 0x01) ? (value & 0x7F) : value; break;
case MemoryType::NesSpriteRam: case MemoryType::NesSecondarySpriteRam: src[address] = (address & 0x03) == 0x02 ? (value & 0xE3) : value; break;
case MemoryType::NesPaletteRam: src[address] = value & 0x3F; break;
case MemoryType::PcePaletteRam: src[address] = (address & 0x01) ? (value & 0x01) : value; break;

default:
src[address] = value;
invalidateCache();
break;
}

src[address] = value;
invalidateCache();
}
break;
}
Expand Down
25 changes: 8 additions & 17 deletions Core/NES/NesPpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1062,15 +1062,20 @@ template<class T> uint8_t NesPpu<T>::ReadSpriteRam(uint8_t addr)
uint64_t elapsedCycles = _console->GetCpu()->GetCycleCount() - _oamDecayCycles[addr >> 3];
if(elapsedCycles <= NesPpu<T>::OamDecayCycleCount) {
_oamDecayCycles[addr >> 3] = _console->GetCpu()->GetCycleCount();
return _spriteRam[addr];
} else {
if(_mask.SpritesEnabled) {
//When debugging with the break on decayed oam read flag turned on, break (only if sprite rendering is enabled to avoid false positives)
_emu->BreakIfDebugging(CpuType::Nes, BreakSource::NesBreakOnDecayedOamRead);
}
//If this 8-byte row hasn't been read/written to in over 3000 cpu cycles (~1.7ms), return 0x10 to simulate decay
return 0x10;

//If this 8-byte row hasn't been read/written to in over 3000 cpu cycles (~1.7ms),
//decay the row (set it to addr, clear the bits that don't exist on some bytes)
for(int i = 0; i < 8; i++) {
int sprAddr = (addr & 0xF8) | i;
_spriteRam[sprAddr] = (sprAddr & 0x03) == 0x02 ? (sprAddr & 0xE3) : sprAddr;
}
}
return _spriteRam[addr];
}
}

Expand Down Expand Up @@ -1428,20 +1433,6 @@ template<class T> void NesPpu<T>::UpdateState()
}
}

template<class T> uint8_t* NesPpu<T>::GetSpriteRam()
{
//Used by debugger
if(_enableOamDecay) {
for(int i = 0; i < 0x100; i++) {
//Apply OAM decay to sprite RAM before letting debugger access it
if((_console->GetCpu()->GetCycleCount() - _oamDecayCycles[i >> 3]) > NesPpu<T>::OamDecayCycleCount) {
_spriteRam[i] = 0x10;
}
}
}
return _spriteRam;
}

template<class T> uint32_t NesPpu<T>::GetPixelBrightness(uint8_t x, uint8_t y)
{
//Used by Zapper, gives a rough approximation of the brightness level of the specific pixel
Expand Down
7 changes: 0 additions & 7 deletions Core/NES/NesPpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,6 @@ class NesPpu : public BaseNesPpu
__forceinline void Exec();
void Run(uint64_t runTo) override;

uint8_t* GetSpriteRam();

uint8_t* GetSecondarySpriteRam()
{
return _secondarySpriteRam;
}

uint32_t GetPixelBrightness(uint8_t x, uint8_t y) override;

uint16_t GetPixel(uint8_t x, uint8_t y)
Expand Down

0 comments on commit 08424ce

Please sign in to comment.