mirror of
https://github.com/Candygoblen123/SwiftNES.git
synced 2025-09-10 12:42:02 -05:00
PPU: impl NMI interrupt
This commit is contained in:
@@ -15,17 +15,53 @@ class NesPPU {
|
||||
var oamAddr: UInt8 = 0
|
||||
var oamData = [UInt8](repeating: 0, count: 64 * 4)
|
||||
|
||||
var scanline: UInt16 = 0
|
||||
var cycles: Int = 0
|
||||
|
||||
var nmiInterrupt: UInt8?
|
||||
|
||||
init(_ chrRom: [UInt8], _ mirroring: Mirroring) {
|
||||
self.chrRom = chrRom
|
||||
self.mirroring = mirroring
|
||||
}
|
||||
|
||||
func tick(_ cycles: UInt8) -> Bool {
|
||||
self.cycles += Int(cycles)
|
||||
if self.cycles >= 341 {
|
||||
self.cycles = self.cycles - 341
|
||||
scanline += 1
|
||||
|
||||
if scanline == 241 {
|
||||
if self.ctrl.generateVblankNMI() {
|
||||
self.status.setVblankStatus(true)
|
||||
status.setSpriteZeroHit(false)
|
||||
if ctrl.generateVblankNMI() {
|
||||
nmiInterrupt = 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if scanline >= 262 {
|
||||
scanline = 0
|
||||
nmiInterrupt = nil
|
||||
status.setSpriteZeroHit(false)
|
||||
self.status.resetVblankStatus()
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func writeToPPUAddr(_ value: UInt8) {
|
||||
addr.update(value)
|
||||
}
|
||||
|
||||
func writeToCtrl(_ value: UInt8) {
|
||||
let beforeNmiStatus = ctrl.generateVblankNMI()
|
||||
ctrl.rawValue = value
|
||||
if !beforeNmiStatus && ctrl.generateVblankNMI() && status.isInVblank() {
|
||||
nmiInterrupt = 1
|
||||
}
|
||||
}
|
||||
|
||||
func incrememtVramAddr() {
|
||||
|
@@ -34,4 +34,8 @@ struct ControlRegister: OptionSet {
|
||||
32
|
||||
}
|
||||
}
|
||||
|
||||
func generateVblankNMI() -> Bool {
|
||||
self.contains(.GENERATE_NMI)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user