Skip to content

Commit

Permalink
[NSF] Refined NMI interception (#386).
Browse files Browse the repository at this point in the history
  • Loading branch information
punesemu committed Mar 19, 2024
1 parent a51c9f4 commit b6dc62f
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/core/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -977,8 +977,8 @@ void cpu_exe_op(BYTE nidx) {
}
nes[nidx].c.cpu.cycles = 0;
break;
case 0x100: IMP(RD_OP, NMI) break; // NMI
case 0x200: IMP(RD_OP, IRQ(nes[nidx].c.cpu.SR & 0xEF)) break; // IRQ
case OP_NMI: IMP(RD_OP, NMI) break; // NMI
case OP_IRQ: IMP(RD_OP, IRQ(nes[nidx].c.cpu.SR & 0xEF)) break; // IRQ
}

// se presenti eseguo i restanti cicli di PPU e APU
Expand Down
2 changes: 2 additions & 0 deletions src/core/cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ enum interrupt_types {
INT_NMI = 0xFFFA,
INT_RESET = 0xFFFC,
INT_IRQ = 0xFFFE,
OP_NMI = 0x100,
OP_IRQ = 0x200,
APU_IRQ = 0x01,
DMC_IRQ = 0x02,
EXT_IRQ = 0x04,
Expand Down
5 changes: 2 additions & 3 deletions src/core/cpu_inline.h
Original file line number Diff line number Diff line change
Expand Up @@ -475,15 +475,14 @@ INLINE static void nsf_rd_mem(BYTE nidx, WORD address, BYTE made_tick) {
if (nsf.state & NSF_CHANGE_SONG) {
nes[nidx].c.cpu.openbus = NSF_ROUTINE_NSF_INIT & 0xFF;
return;
} else if (nsf.nmi.exec) {
} else if (nes[nidx].c.cpu.opcode == OP_NMI) {
nes[nidx].c.cpu.openbus = NSF_ROUTINE_NMI & 0xFF;
return;
}
break;
case 0xFFFB:
if ((nsf.state & NSF_CHANGE_SONG) || nsf.nmi.exec) {
if ((nsf.state & NSF_CHANGE_SONG) || (nes[nidx].c.cpu.opcode == OP_NMI)) {
nes[nidx].c.cpu.openbus = NSF_ROUTINE_START >> 8;
nsf.nmi.exec = FALSE;
return;
}
break;
Expand Down
3 changes: 0 additions & 3 deletions src/core/mappers/mapper_NSF.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ void map_init_NSF(void) {
select_region_NSF();
nsf.rate.count = nsf.rate.reload;
nsf.nmi.count = nsf.rate.reload;
nsf.nmi.exec = FALSE;
nsf.nmi.in_use = FALSE;

nsf.adr.loop = NSF_ROUTINE_LOOP;
Expand Down Expand Up @@ -130,7 +129,6 @@ BYTE extcl_save_mapper_NSF(BYTE mode, BYTE slot, FILE *fp) {

save_slot_ele(mode, slot, nsf.rate.count);

save_slot_ele(mode, slot, nsf.nmi.exec);
save_slot_ele(mode, slot, nsf.nmi.in_use);
save_slot_ele(mode, slot, nsf.nmi.count);

Expand Down Expand Up @@ -221,7 +219,6 @@ void extcl_cpu_every_cycle_NSF(BYTE nidx) {
nsf.nmi.count = nsf.nmi.reload;

nes[0].c.nmi.high = !nsf.nmi.in_use;
nsf.nmi.exec = nes[0].c.nmi.high;
nes[0].p.ppu.odd_frame = !nes[0].p.ppu.odd_frame;
nes[0].p.ppu.frames++;

Expand Down
1 change: 0 additions & 1 deletion src/core/nsf.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ typedef struct _nsf {
DBWORD reload;
} rate;
struct _nsf_nmi {
BYTE exec;
BYTE in_use;
DBWORD count;
DBWORD reload;
Expand Down

0 comments on commit b6dc62f

Please sign in to comment.