summaryrefslogtreecommitdiff
path: root/memory.c
diff options
context:
space:
mode:
Diffstat (limited to 'memory.c')
-rw-r--r--memory.c48
1 files changed, 34 insertions, 14 deletions
diff --git a/memory.c b/memory.c
index 54962a5..e934136 100644
--- a/memory.c
+++ b/memory.c
@@ -5,6 +5,7 @@ __attribute__((hot))
static uint8_t memory_read(struct nes_state *restrict state, uint32_t offset) {
state->cycles++;
ppu_tick(state);
+ // apu_tick(state);
if(LIKELY(offset < 0x2000)) {
return state->ram[offset & 0x07ff];
@@ -18,6 +19,10 @@ static uint8_t memory_read(struct nes_state *restrict state, uint32_t offset) {
state->input_bit[index]++;
return value | 0x40; // Bit 6 open bus high, bit 7 low
+ // } else if(offset == 4015) {
+ // static uint32_t apuread = 0;
+ // // printf("%.5d apu\n", apuread++);
+
} else if(LIKELY(offset >= 0x6000)) {
return state->mapper.prg_read(state, offset);
@@ -29,6 +34,7 @@ __attribute__((hot))
static void memory_write(struct nes_state *restrict state, uint32_t offset, uint8_t value) {
state->cycles++;
ppu_tick(state);
+ // apu_tick(state);
if(LIKELY(offset < 0x2000)) {
state->ram[offset & 0x07ff] = value;
@@ -36,21 +42,34 @@ static void memory_write(struct nes_state *restrict state, uint32_t offset, uint
} else if(offset < 0x4000) {
ppu_write(state, offset, value);
- } else if(offset == 0x4014) {
- ppu_dma_4014(state, value);
-
- } else if(offset == 0x4016) {
- uint8_t prev = state->input_strobe;
- state->input_strobe = value & 1;
-
- if(prev == 1 && (value & 1) == 0) {
- // Latch current inputs
- state->input_latch[0] = state->input[0];
- state->input_latch[1] = state->input[1];
- state->input_bit[0] = 0;
- state->input_bit[1] = 0;
+ } else if(offset < 0x4018) {
+ // APU + joypad + DMA
+ if(offset == 0x4014) {
+ ppu_dma_4014(state, value);
+
+ // } else if(offset == 0x4015) { // DMC Enable (APU)
+ // state->apu.dmc_dma_enabled = (value & 0x10) ? 1 : 0;
+
+ } else if(offset == 0x4016) {
+ uint8_t prev = state->input_strobe;
+ state->input_strobe = value & 1;
+
+ if(prev == 1 && (value & 1) == 0) {
+ // Latch current inputs
+ state->input_latch[0] = state->input[0];
+ state->input_latch[1] = state->input[1];
+ state->input_bit[0] = 0;
+ state->input_bit[1] = 0;
+ }
+
+ // } else if(offset == 0x4017) { // Frame Counter (APU)
+ // state->apu.mode = (value >> 7) & 1;
+ // state->apu.irq_inhibit = (value >> 6) & 1;
+ // state->apu.frame_cycle = 0;
+ // if(state->apu.irq_inhibit) {
+ // state->apu.irq_pending = 0;
+ // }
}
-
} else if(offset >= 0x6000) {
state->mapper.prg_write(state, offset, value);
}
@@ -73,6 +92,7 @@ __attribute__((hot))
static uint8_t memory_read_dummy(struct nes_state *restrict state, uint32_t offset) {
state->cycles++;
ppu_tick(state);
+ // apu_tick(state);
if(UNLIKELY(offset >= 0x2000 && offset < 0x4000)) {
return ppu_read(state, offset);