Skip to content

Commit

Permalink
Only allow writes to the PPU palette when rendering is disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
SirBob01 committed Oct 15, 2023
1 parent ee59ecb commit 9edf75b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/cpu_bus.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ unsigned char read_cpu_bus(cpu_bus_t *bus, address_t address) {

// Read from OAMDATA (overwrite result with value from primary OAM)
if (ptr == &bus->ppu->oam_data) {
result = bus->ppu->primary_oam[bus->ppu->oam_addr];
result = read_primary_oam_ppu(bus->ppu, bus->ppu->oam_addr);
if ((bus->ppu->oam_addr % 4) == 2) {
result &= 0xE3;
}
Expand Down Expand Up @@ -202,7 +202,7 @@ void write_cpu_bus(cpu_bus_t *bus, address_t address, unsigned char value) {
// Write to OAMDATA
if (ptr == &bus->ppu->oam_data) {
if (is_rendering_ppu(bus->ppu)) {
bus->ppu->oam_addr += 0x04;
bus->ppu->oam_addr += 0x04; // Bump high 6 bits
} else {
bus->ppu->primary_oam[bus->ppu->oam_addr++] = value;
}
Expand Down Expand Up @@ -245,7 +245,7 @@ void write_cpu_bus(cpu_bus_t *bus, address_t address, unsigned char value) {

// Write to PPUDATA
if (ptr == &bus->ppu->data) {
if (bus->ppu->v >= PPU_MAP_PALETTE) {
if (bus->ppu->v >= PPU_MAP_PALETTE && !is_rendering_ppu(bus->ppu)) {
address_t palette_addr = bus->ppu->v & 0x1F;
write_palette_ppu(bus->ppu, palette_addr, value);
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ void debug_io(io_t *io, emulator_t *emu) {
unsigned char pixel = ((plane0 >> (7 - x)) & 1) |
(((plane1 >> (7 - x)) & 1) << 1);
vec2_t position = {
(i % 16) * 8 + x,
(unsigned)(i / 16) * 8 + y,
(i & 15) * 8 + x,
(unsigned)(i >> 4) * 8 + y,
};
color_t color = {0, 0, 0};
switch (pixel) {
Expand Down

0 comments on commit 9edf75b

Please sign in to comment.