summaryrefslogtreecommitdiff
path: root/memory.c
diff options
context:
space:
mode:
authorPeter Fors <peter.fors@mindkiller.com>2025-05-03 01:00:10 +0200
committerPeter Fors <peter.fors@mindkiller.com>2025-05-03 01:00:10 +0200
commit8ed5a368077388c676a4ef27cca9f3a58d91e484 (patch)
tree7e96f35ac933fe97a69c2a8f66f8c22f7a9beb6a /memory.c
parent5808f00555c48e1cc1cc110af6a5cd73ddf13010 (diff)
cleanup and rewrite of memory_read()
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;
}