summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--memory.c16
-rw-r--r--ppu.c4
2 files changed, 11 insertions, 9 deletions
diff --git a/memory.c b/memory.c
index 096189b..1eaf489 100644
--- a/memory.c
+++ b/memory.c
@@ -6,26 +6,28 @@ static inline uint8_t memory_read(struct nes_state *state, uint32_t offset) {
ppu_tick(state);
// apu_tick(state);
+ uint8_t result = 0;
+
if(offset >= 0x8000) { // MOST
- return state->mapper_function.prg_rom_read(state, offset);
+ result = state->mapper_function.prg_rom_read(state, offset);
- } else if((offset < 0x2000)) { // SECOND
- return state->ram[offset & 0x07ff];
+ } else if(offset < 0x2000) { // SECOND
+ result = state->ram[offset & 0x07ff];
} else if(offset < 0x4000) { // THIRD
- return ppu_read(state, offset);
+ result = ppu_read(state, offset);
} else if(offset >= 0x6000) {
- return state->mapper_function.prg_ram_read(state, offset);
+ result = state->mapper_function.prg_ram_read(state, offset);
} else if(offset == 0x4016 || offset == 0x4017) {
uint32_t index = offset & 1;
uint8_t value = (state->ppu.input_latch[index] >> state->ppu.input_bit[index]) & 1;
state->ppu.input_bit[index]++;
- return value | 0x40; // Bit 6 open bus high, bit 7 low
+ result = value | 0x40; // Bit 6 open bus high, bit 7 low
}
- return 0;
+ return result;
}
__attribute__((hot))
diff --git a/ppu.c b/ppu.c
index 8280265..570f3dd 100644
--- a/ppu.c
+++ b/ppu.c
@@ -28,7 +28,7 @@ __attribute__((hot))
static inline void ppu_evaluate_sprites(struct nes_state *state) {
struct ppu_state *restrict ppu = &state->ppu;
uint8_t sprite_height = (ppu->reg_ctrl & 0x20) ? 16 : 8;
- uint8_t n = 0;
+ uint32_t n = 0;
uint8_t * restrict src = ppu->oam;
uint8_t * restrict dst = ppu->secondary_oam;
@@ -47,7 +47,7 @@ static inline void ppu_evaluate_sprites(struct nes_state *state) {
dst += 4;
n++;
} else {
- ppu->reg_status |= 0x20;
+ ppu->reg_status |= 0x20; // NOTE(peter): sprite overflow
break;
}
}