PPU: background rendering

This commit is contained in:
Andrew Glaze 2024-08-20 23:36:04 -04:00
parent be170bf750
commit f9efe23b0b
5 changed files with 15 additions and 8 deletions

View File

@ -157,9 +157,10 @@ class CPU {
func run(onCycle: @escaping () -> (), onComplete: @escaping () -> ()) {
let opcodes = OPCODES_MAP
while true {
if let _nmi = bus.pollNMI() {
if bus.pollNMI() != nil {
print(programCounter)
interrupt(.NMI)
print(programCounter)
}
processOpcodes(onCycle: onCycle, opcodes: opcodes) {
onComplete()

View File

@ -9,7 +9,7 @@ func dumpCpuState(_ cpu: CPU) -> String {
{
let (addr, _) = cpu.getAbsoluteAddress(opcode.mode, addr: cpu.programCounter + 1)
return (addr, cpu.memRead(addr))
return (addr, 0)//cpu.memRead(addr))
}()
}

View File

@ -32,7 +32,7 @@ class Bus {
}
func pollNMI() -> UInt8? {
ppu.nmiInterrupt
ppu.pollNMI()
}
}

View File

@ -18,7 +18,7 @@ class NesPPU {
var scanline: UInt16 = 0
var cycles: Int = 0
var nmiInterrupt: UInt8?
var nmiInterrupt: UInt8? = nil
init(_ chrRom: [UInt8], _ mirroring: Mirroring) {
self.chrRom = chrRom
@ -52,6 +52,12 @@ class NesPPU {
return false
}
func pollNMI() -> UInt8? {
let tmp = self.nmiInterrupt
self.nmiInterrupt = nil
return tmp
}
func writeToPPUAddr(_ value: UInt8) {
addr.update(value)
}
@ -110,7 +116,7 @@ class NesPPU {
func writeToData(_ data: UInt8) {
let addr = addr.get()
//print("\(addr): \(data)")
print("\(addr): \(data)")
switch addr {
case 0...0x1fff:
print("Attempt to write to chr rom space \(addr)!")

View File

@ -28,7 +28,7 @@ struct ControlRegister: OptionSet {
static let GENERATE_NMI = ControlRegister(rawValue: 0b10000000)
func vramAddrIncrement() -> UInt8 {
if self.contains(.VRAM_ADD_INCREMENT) {
if !self.contains(.VRAM_ADD_INCREMENT) {
1
} else {
32
@ -40,7 +40,7 @@ struct ControlRegister: OptionSet {
}
func backgroundPatternAddr() -> Int {
if self.contains(.BACKROUND_PATTERN_ADDR) {
if !self.contains(.BACKROUND_PATTERN_ADDR) {
0
} else {
0x1000