mirror of
https://github.com/Candygoblen123/SwiftNES.git
synced 2025-09-10 04:32:03 -05:00
fix tests
This commit is contained in:
@@ -103,18 +103,20 @@ class CPU {
|
||||
}
|
||||
|
||||
func run() {
|
||||
run {}
|
||||
run(onCycle: {}, onComplete: {})
|
||||
}
|
||||
|
||||
func run(callback: @escaping () -> ()) {
|
||||
func run(onCycle: @escaping () -> (), onComplete: @escaping () -> ()) {
|
||||
let opcodes = OPCODES_MAP
|
||||
Timer.scheduledTimer(withTimeInterval: 0.00007, repeats: true) { [self] timer in
|
||||
processOpcodes(callback: callback, opcodes: opcodes, timer: timer)
|
||||
processOpcodes(onCycle: onCycle, opcodes: opcodes, timer: timer) {
|
||||
onComplete()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func processOpcodes(callback: () -> (), opcodes: [UInt8: OpCode], timer: Timer) {
|
||||
callback()
|
||||
func processOpcodes(onCycle: () -> (), opcodes: [UInt8: OpCode], timer: Timer, onComplete: () -> ()) {
|
||||
onCycle()
|
||||
let code = memRead(programCounter)
|
||||
programCounter += 1
|
||||
|
||||
@@ -278,9 +280,7 @@ class CPU {
|
||||
/// BRK
|
||||
case 0x00:
|
||||
timer.invalidate()
|
||||
SDL_DestroyWindow(window)
|
||||
SDL_Quit()
|
||||
exit(0)
|
||||
onComplete()
|
||||
default: fatalError("TODO!")
|
||||
}
|
||||
|
||||
|
@@ -124,7 +124,7 @@ cpu.reset()
|
||||
var screenState = [UInt8](repeating: 0, count: 32 * 3 * 32)
|
||||
var rng = SystemRandomNumberGenerator()
|
||||
|
||||
cpu.run() {
|
||||
cpu.run(onCycle: {
|
||||
handleUserInput(cpu, event: &event)
|
||||
cpu.memWrite(0xfe, data: UInt8.random(in: 1...16, using: &rng))
|
||||
|
||||
@@ -133,7 +133,11 @@ cpu.run() {
|
||||
SDL_RenderCopy(canvas, texture, nil, nil)
|
||||
SDL_RenderPresent(canvas)
|
||||
}
|
||||
}
|
||||
}, onComplete: {
|
||||
SDL_DestroyWindow(window)
|
||||
SDL_Quit()
|
||||
exit(0)
|
||||
})
|
||||
|
||||
// Infinite loop otherwise the program will exit prematurely
|
||||
RunLoop.main.run()
|
||||
|
Reference in New Issue
Block a user