PPU: impl scrolling

This commit is contained in:
Andrew Glaze
2024-08-23 23:36:25 -04:00
parent af3be8d93d
commit 9f12bb2ba0
5 changed files with 119 additions and 35 deletions

View File

@@ -28,6 +28,9 @@ class NesPPU {
func tick(_ cycles: UInt8) -> Bool {
self.cycles += Int(cycles)
if self.cycles >= 341 {
if checkSprite0Hit(self.cycles) {
status.setSpriteZeroHit(true)
}
self.cycles = self.cycles - 341
self.scanline += 1
@@ -50,6 +53,12 @@ class NesPPU {
return false
}
func checkSprite0Hit(_ cycle: Int) -> Bool {
let y = Int(oamData[0])
let x = Int(oamData[0])
return (y == scanline) && x <= cycle && mask.showSprites()
}
func pollNMI() -> UInt8? {
let tmp = self.nmiInterrupt
self.nmiInterrupt = nil

View File

@@ -70,4 +70,19 @@ struct ControlRegister: OptionSet {
1
}
}
func nametableAddr() -> UInt16 {
switch rawValue & 0b11 {
case 0:
0x2000
case 1:
0x2400
case 2:
0x2800
case 3:
0x2c00
default:
fatalError("naemtableAddr: Not possible!")
}
}
}