cpu state

This commit is contained in:
Mark Canlas 2024-01-04 14:24:43 -05:00
parent 7120b60ae7
commit d50da49ea6
3 changed files with 51 additions and 0 deletions

View File

@ -37,6 +37,7 @@
- [Easy 6502](https://skilldrick.github.io/easy6502/)
- [Annotated Snake6502](https://gist.github.com/wkjagt/9043907)
- [Ultimate Commodore 64 Reference - 6502](https://www.pagetable.com/c64ref/6502/)
## Colophon

View File

@ -0,0 +1,35 @@
package com.htmlism.firepower.cpu
case class CpuState(
accumulator: UByte,
xRegister: UByte,
yRegister: UByte,
stackPointer: UByte,
programCounterLo: UByte,
programCounterHi: UByte,
negative: Boolean,
overflow: Boolean,
break: Boolean,
decimal: Boolean,
interruptsDisabled: Boolean,
zero: Boolean,
carry: Boolean
)
object CpuState:
val empty: CpuState =
CpuState(
accumulator = UByte(0),
xRegister = UByte(0),
yRegister = UByte(0),
stackPointer = UByte(0),
programCounterLo = UByte(0),
programCounterHi = UByte(0),
negative = false,
overflow = false,
break = false,
decimal = false,
interruptsDisabled = false,
zero = false,
carry = false
)

View File

@ -0,0 +1,15 @@
package com.htmlism.firepower.cpu
opaque type UByte =
Byte
extension (b: UByte)
def inc: UByte =
((b & 0xff) + 1).toByte
def dec: UByte =
((b & 0xff) - 1).toByte
object UByte:
def apply(n: Int): UByte =
n.toByte