diff options
| -rw-r--r-- | mknes_memory.c | 56 |
1 files changed, 20 insertions, 36 deletions
diff --git a/mknes_memory.c b/mknes_memory.c index 57f527e..7280f81 100644 --- a/mknes_memory.c +++ b/mknes_memory.c @@ -7,35 +7,31 @@ static inline uint8_t memory_read(struct nes_state *state, uint32_t offset) { apu_tick(state); ppu_tick(state); + uint8_t result = 0; if(offset <= 0x1fff) { - return state->ram[offset & 0x07ff]; - } + result = state->ram[offset & 0x07ff]; - if(offset >= 0x8000) { - return state->mapper_function.prg_rom_read(state, offset); - } + } else if(offset >= 0x8000) { + result = state->mapper_function.prg_rom_read(state, offset); - if(offset >= 0x2000 && offset <= 0x3fff) { - return ppu_read(state, offset); - } + } else if(offset >= 0x2000 && offset <= 0x3fff) { + result = ppu_read(state, offset); - if(offset == 0x4015) { - return apu_read4015(state); - } + } else if(offset == 0x4015) { + result = apu_read4015(state); - if(offset >= 0x4016 && offset <= 0x4017) { + } 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 - if(offset >= 0x6000 && offset <= 0x7fff) { - return state->mapper_function.prg_ram_read(state, offset); + } else if(offset >= 0x6000 && offset <= 0x7fff) { + result = state->mapper_function.prg_ram_read(state, offset); } - return 0; + return result; } __attribute__((always_inline, hot)) @@ -63,25 +59,17 @@ static inline void memory_write(struct nes_state *state, uint32_t offset, uint8_ if(offset <= 0x1fff) { state->ram[offset & 0x07ff] = value; - return; - } - if(offset >= 0x8000) { + } else if(offset >= 0x8000) { state->mapper_function.prg_rom_write(state, offset, value); - return; - } - if(offset >= 0x2000 && offset <= 0x3fff) { + } else if(offset >= 0x2000 && offset <= 0x3fff) { ppu_write(state, offset, value); - return; - } - if(offset == 0x4014) { + } else if(offset == 0x4014) { ppu_dma_4014(state, value); - return; - } - if(offset == 0x4016) { + } else if(offset == 0x4016) { // joypad strobe uint8_t s = value & 1; @@ -98,16 +86,12 @@ static inline void memory_write(struct nes_state *state, uint32_t offset, uint8_ state->ppu.input_bit[1] = 0; } // } - return; - } - if(offset >= 0x4000 && offset <= 0x4017) { + } else if(offset >= 0x4000 && offset <= 0x4017) { apu_write(state, offset, value); - return; - } - if(offset >= 0x6000 && offset <= 0x7fff) { + } else if(offset >= 0x6000 && offset <= 0x7fff) { state->mapper_function.prg_ram_write(state, offset, value); - return; + } } |
