Skip to content

Commit

Permalink
PPU: setup OBJ VRAM and OAM access stalling
Browse files Browse the repository at this point in the history
  • Loading branch information
fleroviux committed Aug 30, 2022
1 parent 2868db5 commit eab9098
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 6 deletions.
6 changes: 2 additions & 4 deletions src/nba/src/bus/bus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,7 @@ auto Bus::Read(u32 address, int access) -> T {
}
// OAM (object attribute map)
case 0x07: {
Step(1);
return hw.ppu.ReadOAM<T>(Align<T>(address));
return ReadOAM<T>(Align<T>(address));
}
// ROM (WS0, WS1, WS2)
case 0x08 ... 0x0D: {
Expand Down Expand Up @@ -208,8 +207,7 @@ void Bus::Write(u32 address, int access, T value) {
}
// OAM (object attribute map)
case 0x07: {
Step(1);
hw.ppu.WriteOAM<T>(Align<T>(address), value);
WriteOAM<T>(Align<T>(address), value);
break;
}
// ROM (WS0, WS1, WS2)
Expand Down
20 changes: 20 additions & 0 deletions src/nba/src/bus/bus.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,26 @@ struct Bus {
}
}

template<typename T>
auto ALWAYS_INLINE ReadOAM(u32 address) noexcept -> T {
do {
Step(1);
hw.ppu.Sync();
} while(hw.ppu.DidAccessOAM());

return hw.ppu.ReadOAM<T>(address);
}

template<typename T>
void ALWAYS_INLINE WriteOAM(u32 address, T value) noexcept {
do {
Step(1);
hw.ppu.Sync();
} while(hw.ppu.DidAccessOAM());

hw.ppu.WriteOAM<T>(address, value);
}

auto ReadBIOS(u32 address) -> u32;
auto ReadOpenBus(u32 address) -> u32;

Expand Down
8 changes: 7 additions & 1 deletion src/nba/src/hw/ppu/ppu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ void PPU::Reset() {

pram_access = false;
vram_bg_access = false;
vram_obj_access = false;
oam_access = false;
}

void PPU::LatchEnabledBGs() {
Expand Down Expand Up @@ -353,8 +355,10 @@ void PPU::InitLineRender() {
InitCompose();
}

vram_bg_access = false;
pram_access = false;
vram_bg_access = false;
vram_obj_access = false;
oam_access = false;
}

void PPU::SyncLineRender() {
Expand All @@ -376,6 +380,8 @@ void PPU::SyncLineRender() {

pram_access = false;
vram_bg_access = false;
vram_obj_access = false;
oam_access = false;

for (int id = 0; id < 4; id++) {
if (bg[id].engaged) {
Expand Down
8 changes: 7 additions & 1 deletion src/nba/src/hw/ppu/ppu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,11 @@ struct PPU {
}

bool ALWAYS_INLINE DidAccessVRAM_OBJ() const {
return false;
return vram_obj_access;
}

bool ALWAYS_INLINE DidAccessOAM() const {
return oam_access;
}

struct MMIO {
Expand Down Expand Up @@ -300,6 +304,8 @@ struct PPU {

bool pram_access;
bool vram_bg_access;
bool vram_obj_access;
bool oam_access;

Scheduler& scheduler;
IRQ& irq;
Expand Down

0 comments on commit eab9098

Please sign in to comment.