From 9edf75b646e607177929307714acb725d33f22c1 Mon Sep 17 00:00:00 2001 From: Keith Leonardo Date: Mon, 16 Oct 2023 00:14:25 +1100 Subject: [PATCH] Only allow writes to the PPU palette when rendering is disabled --- src/cpu_bus.c | 6 +++--- src/io.c | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/cpu_bus.c b/src/cpu_bus.c index 7ca8099..2157e09 100644 --- a/src/cpu_bus.c +++ b/src/cpu_bus.c @@ -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; } @@ -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; } @@ -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 { diff --git a/src/io.c b/src/io.c index 7720215..19c564b 100644 --- a/src/io.c +++ b/src/io.c @@ -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) {