Skip to content

Commit

Permalink
VBlank flag in RDNMI should clear when read
Browse files Browse the repository at this point in the history
  • Loading branch information
twvd committed Dec 9, 2023
1 parent fea79a4 commit 656a7ce
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/snes/bus/mainbus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ where
vtime: u16,
htime: u16,
timeup: Cell<bool>,

/// Clearable VBlank flag in RDNMI
rdnmi_vblank: Cell<bool>,
}

enum DMADirection {
Expand Down Expand Up @@ -261,6 +264,8 @@ where
htime: 0,
vtime: 0,
timeup: Cell::new(false),

rdnmi_vblank: Cell::new(false),
}
}

Expand Down Expand Up @@ -461,7 +466,8 @@ where
0x420D => Some(self.memsel),
// RDNMI - V-Blank NMI Flag and CPU Version Number
0x4210 => {
if self.ppu.in_vblank() {
if self.rdnmi_vblank.get() {
self.rdnmi_vblank.set(false);
Some(0x80 | 2 | (self.openbus.get() & 0x70))
} else {
Some(2 | (self.openbus.get() & 0x70))
Expand Down Expand Up @@ -796,8 +802,13 @@ where
self.hdma_run();
}

if entered_vblank && self.nmitimen & (1 << 7) != 0 {
self.intreq_nmi = true;
if entered_vblank {
if self.nmitimen & (1 << 7) != 0 {
self.intreq_nmi = true;
}
self.rdnmi_vblank.set(true);
} else if !self.ppu.in_vblank() {
self.rdnmi_vblank.set(false);
}

// H/V interrupt
Expand Down

0 comments on commit 656a7ce

Please sign in to comment.