diff options
| author | Peter Fors <peter.fors@mindkiller.com> | 2025-10-16 04:19:32 +0200 |
|---|---|---|
| committer | Peter Fors <peter.fors@mindkiller.com> | 2025-10-16 04:19:32 +0200 |
| commit | a4c261c6ee3940099e653a6f448dc952dfd5899f (patch) | |
| tree | 7b14cfde56d735259f6e852a6d337228e00db0f5 /mknes_cpu.c | |
| parent | dcaf169691cfbb865241e96a4786af0862424701 (diff) | |
optimized, but bug with rasterdemos
Diffstat (limited to 'mknes_cpu.c')
| -rw-r--r-- | mknes_cpu.c | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/mknes_cpu.c b/mknes_cpu.c index 3c0a3f2..0eccf03 100644 --- a/mknes_cpu.c +++ b/mknes_cpu.c @@ -6,6 +6,7 @@ static inline uint8_t pack_flags(struct cpu_state *cpu) { return (cpu->n << 7) | (cpu->v << 6) | (1 << 5) | (cpu->d << 3) | (cpu->i << 2) | (cpu->z << 1) | cpu->c; } +__attribute__((always_inline)) static inline void unpack_flags(struct cpu_state *cpu, uint8_t value) { cpu->n = (value >> 7) & 1; cpu->v = (value >> 6) & 1; @@ -15,6 +16,8 @@ static inline void unpack_flags(struct cpu_state *cpu, uint8_t value) { cpu->c = value & 1; } + +__attribute__((always_inline)) static inline void update_zn(struct cpu_state *cpu, uint8_t result) { cpu->z = (result == 0); cpu->n = (result & 0x80) != 0; @@ -63,6 +66,7 @@ static inline void do_irq(struct nes_state *state) { cpu->i = 1; } +__attribute__((always_inline)) static inline void check_interrupts(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; @@ -86,7 +90,17 @@ static inline void cpu_reset(struct nes_state *state) { static inline void cpu_tick(struct nes_state *state) { struct cpu_state * restrict cpu = &state->cpu; - check_interrupts(state); + // check_interrupts(state); + if(state->cpu.nmi_pending) { + state->cpu.nmi_pending = 0; + do_nmi(state); + } + if(state->cpu.irq_pending && cpu->i == 0) { + state->cpu.irq_pending = 0; + do_irq(state); + } + + // printf("%4.4x: ", cpu->pc); uint8_t opcode = memory_read(state, cpu->pc++); |
