Skip to content

Commit

Permalink
Minor README edit, PPU register access optimization, and adding some …
Browse files Browse the repository at this point in the history
…more cycles to blargg test

Still not even close to the full blargg test
  • Loading branch information
StardustGogeta committed Dec 24, 2023
1 parent a554052 commit 76e7520
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 6 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,5 @@ This will create a `bin` folder in the repository and build the project from the
- Explanation of mappers and bank switching: https://somethingnerdy.com/mappers-matter/
- NES test ROM collection: https://github.com/christopherpow/nes-test-roms
- NES input data and registers: https://stackoverflow.com/questions/66406934/whats-an-elegant-way-to-read-controller-input-for-nes-6502-assembly-on-ca65
- PPU registers: https://www.nesdev.org/wiki/PPU_registers
- List of NES mappers: https://www.nesdev.org/wiki/Mapper
39 changes: 35 additions & 4 deletions src/core/ppu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,41 @@ void PPU::start() {

void PPU::cycle() {
if (cyclesOnLine) {
if (cyclesOnLine < 321) {
// TODO: Get nametable byte, attribute table byte, pattern table data as appropriate

// Output a pixel to the screen
// The first cycle is idle and should be ignored
if (cyclesOnLine < 257) {
/*
We perform four memory accesses, each one taking two cycles.
The PPU memory should not be accessed at this time, so we can just populate everything at once when needed.
The four accesses are:
- Nametable byte
- Attribute table byte
- Pattern table tile low
- Pattern table tile high
*/
}
else if (cyclesOnLine < 321) {
/*
Now, we perform the following four memory accesses:
- Garbage nametable byte
- Garbage nametable byte
- Pattern table tile low
- Pattern table tile high
Each takes two cycles, and we repeat for each of the eight sprites.
*/
}
else if (cyclesOnLine < 337) {
/*
We perform four memory accesses, each one taking two cycles, for two tiles.
- Nametable byte
- Attribute table byte
- Pattern table tile low
- Pattern table tile high
*/
}
else {
/*
Two final nametable bytes are fetched. (Used for MMC5.)
*/
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/cpu/cpu_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ void runBlarggCpuTest5Official() {
std::this_thread::yield();
}

for (int i = 0; i < 22000; i++) {
for (int i = 0; i < 22650; i++) {
nes->cpu->cycle();
}

Expand Down
2 changes: 1 addition & 1 deletion src/memory/core_memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ addr_t CoreMemory::mapPPU(addr_t address) {
if (0x2000 > address || address >= 0x4000) {
throw std::runtime_error("Address is not in valid PPU register range!");
}
return (address - 0x2000) % 8;
return address % 8;
}

/*
Expand Down

0 comments on commit 76e7520

Please sign in to comment.