passes all Klaus tests up to decimal test

This commit is contained in:
Luigi Thirty 2017-07-25 23:18:47 -04:00
parent 4a15c6aff5
commit 7eb1982c5f
2 changed files with 21 additions and 24 deletions

View File

@ -89,7 +89,7 @@ class DebuggerViewController: NSViewController {
isRunning = true
cpuInstance.cycles = 0
cpuInstance.cyclesInBatch = 50000
cpuInstance.cyclesInBatch = 1000000
while(!cpuInstance.checkOutOfCycles() && isRunning) {
cpuStep()

View File

@ -173,14 +173,14 @@ func hex2bcd(hex: UInt8) -> UInt8 {
class Opcodes: NSObject {
static func _Add(state: CPU, operand: UInt8) {
static func _Add(state: CPU, operand: UInt8, isSubtract: Bool) {
if(state.accumulator == 0xFF) {
_ = 1
}
var t16: UInt16 = UInt16(state.accumulator &+ operand) + UInt16((state.status_register.carry ? UInt8(1) : UInt8(0)))
let t8: UInt8 = UInt8(t16 & 0xFF)
state.status_register.overflow = (~(state.accumulator ^ operand) & (state.accumulator ^ t8) & 0x80) == 0x80
state.status_register.overflow = (state.accumulator & 0x80) != (t8 & 0x80)
state.status_register.zero = (t8 == 0)
state.status_register.negative = (t8 & 0x80) == 0x80
@ -190,33 +190,30 @@ class Opcodes: NSObject {
state.status_register.carry = (t16 > 255)
}
state.accumulator = (UInt8(t16 & 0xFF))
state.accumulator = t8
}
static func ADC(state: CPU, addressingMode: AddressingMode) -> Void {
_Add(state: state, operand: UInt8(getOperandByteForAddressingMode(state: state, mode: addressingMode)))
/*
let operand = UInt8(getOperandByteForAddressingMode(state: state, mode: addressingMode))
var t16: UInt16 = UInt16(state.accumulator &+ operand) + UInt16((state.status_register.carry ? UInt8(1) : UInt8(0)))
let t8: UInt8 = UInt8(t16 & 0xFF)
state.status_register.overflow = (~(state.accumulator ^ operand) & (state.accumulator ^ t8) & 0x80) == 0x80
state.status_register.zero = (t8 == 0)
state.status_register.negative = (t8 & 0x80) == 0x80
if(state.status_register.decimal) {
t16 = UInt16(hex2bcd(hex: state.accumulator) + hex2bcd(hex: operand) + (state.status_register.carry ? UInt8(1) : UInt8(0)))
} else {
state.status_register.carry = (t16 > 255)
}
state.accumulator = (UInt8(t16 & 0xFF))
*/
_Add(state: state, operand: UInt8(getOperandByteForAddressingMode(state: state, mode: addressingMode)), isSubtract: false)
}
static func SBC(state: CPU, addressingMode: AddressingMode) -> Void {
_Add(state: state, operand: ~(UInt8(getOperandByteForAddressingMode(state: state, mode: addressingMode))))
let operand = UInt8(getOperandByteForAddressingMode(state: state, mode: addressingMode))
var t16: UInt16 = UInt16(state.accumulator &- operand) - UInt16((state.status_register.carry ? UInt8(0) : UInt8(1)))
let t8: UInt8 = UInt8(t16 & 0xFF)
state.cyclesInBatch = 0
state.status_register.overflow = (t8 >= 0x80 && t8 <= 0xFF)
if(state.status_register.decimal == true) {
t16 = UInt16(hex2bcd(hex: state.accumulator) + hex2bcd(hex: operand) + (state.status_register.carry ? UInt8(1) : UInt8(0)))
} else {
state.status_register.carry = (t16 >> 8) == 0 ? false : true
}
state.accumulator = t8
state.updateZeroFlag(value: t8)
state.updateNegativeFlag(value: t8)
}
static func LDA(state: CPU, addressingMode: AddressingMode) -> Void {