mirror of
https://github.com/Luigi30/FruitMachine-Swift.git
synced 2024-11-26 21:52:45 +00:00
more optimization of the CPU
This commit is contained in:
parent
b6a65d1eb7
commit
45e5c3c658
@ -58,7 +58,6 @@ class AppleI: NSObject {
|
||||
}
|
||||
|
||||
func runFrame() {
|
||||
|
||||
|
||||
CPU.sharedInstance.cycles = 0
|
||||
CPU.sharedInstance.cyclesInBatch = AppleI.CYCLES_PER_BATCH
|
||||
@ -69,17 +68,12 @@ class AppleI: NSObject {
|
||||
let pixelBase = CVPixelBufferGetBaseAddress(emulatorViewDelegate.pixels!)
|
||||
let buf = pixelBase?.assumingMemoryBound(to: BitmapPixelsBE555.PixelData.self)
|
||||
|
||||
let startTime = CFAbsoluteTimeGetCurrent()
|
||||
|
||||
for (cellNum, character) in terminal.characters.enumerated() {
|
||||
emulatorViewDelegate.putCharacterPixels(buffer: buf,
|
||||
charPixels: cg.getCharacterPixels(charIndex: character),
|
||||
pixelPosition: emulatorViewDelegate.getPixelOffset(charCellIndex: cellNum))
|
||||
}
|
||||
|
||||
let timeElapsed = CFAbsoluteTimeGetCurrent() - startTime
|
||||
print("Time elapsed for runFrame: \(timeElapsed) s.")
|
||||
|
||||
CVPixelBufferUnlockBaseAddress(emulatorViewDelegate.pixels!, CVPixelBufferLockFlags(rawValue: 0))
|
||||
|
||||
emulatorView.setNeedsDisplay(emulatorView.frame)
|
||||
|
@ -215,9 +215,7 @@ class CPU: NSObject {
|
||||
self.branch_was_taken = false
|
||||
}
|
||||
|
||||
if(operation!.mnemonic != "JMP" && operation!.mnemonic != "JSR" && operation!.mnemonic != "BRK" && operation!.mnemonic != "RTI") {
|
||||
self.program_counter = UInt16(Int(self.program_counter) + operation!.bytes)
|
||||
}
|
||||
self.program_counter = UInt16(Int(self.program_counter) + operation!.bytes)
|
||||
}
|
||||
|
||||
func outOfCycles() -> Bool {
|
||||
@ -254,6 +252,8 @@ class CPU: NSObject {
|
||||
}
|
||||
|
||||
func runCyclesBatch() {
|
||||
let startTime = CFAbsoluteTimeGetCurrent()
|
||||
|
||||
isRunning = true
|
||||
|
||||
while(!outOfCycles() && isRunning) {
|
||||
@ -264,6 +264,9 @@ class CPU: NSObject {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
let timeElapsed = CFAbsoluteTimeGetCurrent() - startTime
|
||||
print("Time elapsed for runFrame: \(timeElapsed) s.")
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -586,12 +586,12 @@ class Opcodes: NSObject {
|
||||
|
||||
//Misc
|
||||
static func JMP(state: CPU, addressingMode: AddressingMode) -> Void {
|
||||
state.program_counter = getOperandAddressForAddressingMode(state: state, mode: addressingMode)
|
||||
state.program_counter = getOperandAddressForAddressingMode(state: state, mode: addressingMode) - 3
|
||||
}
|
||||
|
||||
static func JSR(state: CPU, addressingMode: AddressingMode) -> Void {
|
||||
state.pushWord(data: state.program_counter + 2)
|
||||
state.program_counter = state.getOperandWord()
|
||||
state.program_counter = state.getOperandWord() - 3
|
||||
}
|
||||
|
||||
static func RTS(state: CPU, addressingMode: AddressingMode) -> Void {
|
||||
@ -600,7 +600,7 @@ class Opcodes: NSObject {
|
||||
|
||||
static func RTI(state: CPU, addressingMode: AddressingMode) -> Void {
|
||||
state.status_register.fromByte(state: state.popByte())
|
||||
state.program_counter = state.popWord()
|
||||
state.program_counter = state.popWord() - 1
|
||||
state.status_register.brk = false //RTI sets B to 0
|
||||
}
|
||||
|
||||
@ -610,7 +610,7 @@ class Opcodes: NSObject {
|
||||
state.pushWord(data: state.program_counter + 2)
|
||||
state.pushByte(data: sr.asByte())
|
||||
state.status_register.irq_disable = true //BRK disables interrupts before transferring control
|
||||
state.program_counter = state.memoryInterface.readWord(offset: 0xFFFE)
|
||||
state.program_counter = state.memoryInterface.readWord(offset: 0xFFFE) - 1
|
||||
}
|
||||
|
||||
static func NOP(state: CPU, addressingMode: AddressingMode) -> Void {}
|
||||
|
Loading…
Reference in New Issue
Block a user