mirror of
https://github.com/irmen/prog8.git
synced 2025-02-27 18:29:00 +00:00
fixes
This commit is contained in:
parent
900c2aea23
commit
e46982f652
@ -16,8 +16,11 @@ interface ICpu {
|
|||||||
val totalCycles: Int
|
val totalCycles: Int
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: add additional cycles to certain instructions and addressing modes
|
// TODO: add the optional additional cycles to certain instructions and addressing modes
|
||||||
// TODO: fix sbc and adc with BCD arithmetic.
|
// TODO: fix sbc and adc with BCD arithmetic.
|
||||||
|
// TODO: add IRQ and NMI signaling.
|
||||||
|
// TODO: make a 65c02 variant as well (and re-enable the unit tests for that).
|
||||||
|
|
||||||
|
|
||||||
class Cpu6502(private val illegalInstrsAllowed: Boolean) : BusComponent(), ICpu {
|
class Cpu6502(private val illegalInstrsAllowed: Boolean) : BusComponent(), ICpu {
|
||||||
override var tracing: Boolean = false
|
override var tracing: Boolean = false
|
||||||
@ -700,10 +703,10 @@ class Cpu6502(private val illegalInstrsAllowed: Boolean) : BusComponent(), ICpu
|
|||||||
if (lo and 0xff > 9) lo += 6
|
if (lo and 0xff > 9) lo += 6
|
||||||
var hi = (A shr 4) + (operand shr 4) + if (lo > 15) 1 else 0
|
var hi = (A shr 4) + (operand shr 4) + if (lo > 15) 1 else 0
|
||||||
if (hi and 0xff > 9) hi += 6
|
if (hi and 0xff > 9) hi += 6
|
||||||
var result = lo and 0x0f or (hi shl 4)
|
val result = lo and 0x0f or (hi shl 4)
|
||||||
result = result and 0xff
|
A = result and 0xff
|
||||||
Status.C = hi > 15
|
Status.C = hi > 15
|
||||||
Status.Z = result == 0
|
Status.Z = A == 0
|
||||||
Status.V = false // BCD never sets overflow flag
|
Status.V = false // BCD never sets overflow flag
|
||||||
Status.N = false // BCD is never negative on NMOS 6502 (bug)
|
Status.N = false // BCD is never negative on NMOS 6502 (bug)
|
||||||
} else {
|
} else {
|
||||||
@ -991,10 +994,10 @@ class Cpu6502(private val illegalInstrsAllowed: Boolean) : BusComponent(), ICpu
|
|||||||
if (Status.D) {
|
if (Status.D) {
|
||||||
var lo = (A and 0x0f) - (operand and 0x0f) - if (Status.C) 0 else 1
|
var lo = (A and 0x0f) - (operand and 0x0f) - if (Status.C) 0 else 1
|
||||||
if (lo and 0x10 != 0) lo -= 6
|
if (lo and 0x10 != 0) lo -= 6
|
||||||
var h = (A shr 4) - (operand shr 4) - if (lo and 0x10 != 0) 1 else 0
|
var hi = (A shr 4) - (operand shr 4) - if (lo and 0x10 != 0) 1 else 0
|
||||||
if (h and 0x10 != 0) h -= 6
|
if (hi and 0x10 != 0) hi -= 6
|
||||||
val result = lo and 0x0f or ((h shl 4) and 0xff)
|
val result = lo and 0x0f or ((hi shl 4) and 0xff)
|
||||||
Status.C = h and 255 < 15
|
Status.C = hi and 255 < 15
|
||||||
Status.Z = result == 0
|
Status.Z = result == 0
|
||||||
Status.V = false // BCD never sets overflow flag
|
Status.V = false // BCD never sets overflow flag
|
||||||
Status.N = false // BCD is never negative on NMOS 6502 (bug)
|
Status.N = false // BCD is never negative on NMOS 6502 (bug)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user