summaryrefslogtreecommitdiff
path: root/memory.c
diff options
context:
space:
mode:
Diffstat (limited to 'memory.c')
-rw-r--r--memory.c24
1 files changed, 21 insertions, 3 deletions
diff --git a/memory.c b/memory.c
index 74b0a0f..6e0c6df 100644
--- a/memory.c
+++ b/memory.c
@@ -7,10 +7,27 @@ static uint8_t memory_read(struct nes_state *restrict state, uint32_t offset) {
ppu_tick(state);
// apu_tick(state);
- if(LIKELY(offset < 0x2000)) {
+ if(LIKELY(offset >= 0x6000)) { // MOST
+ return state->mapper.prg_read(state, offset);
+
+ } else if(LIKELY(offset < 0x2000)) { // SECOND
return state->ram[offset & 0x07ff];
- } else if(offset < 0x4000) {
+ } else if(offset < 0x4000) { // THIRD
+ return ppu_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
+ }
+
+#if 0
+ if(LIKELY(offset < 0x2000)) { // SECOND
+ return state->ram[offset & 0x07ff];
+
+ } else if(offset < 0x4000) { // THIRD
return ppu_read(state, offset);
} else if(offset == 0x4016 || offset == 0x4017) {
@@ -23,10 +40,11 @@ static uint8_t memory_read(struct nes_state *restrict state, uint32_t offset) {
// static uint32_t apuread = 0;
// // printf("%.5d apu\n", apuread++);
- } else if(LIKELY(offset >= 0x6000)) {
+ } else if(LIKELY(offset >= 0x6000)) { // MOST
return state->mapper.prg_read(state, offset);
}
+#endif
return 0;
}