mirror of
https://github.com/felipecsl/6502Android.git
synced 2025-01-04 14:33:00 +00:00
Loop CPU execution
This commit is contained in:
parent
25cfd99dd2
commit
8f83e56e67
@ -85,32 +85,34 @@ class CPU(private val memory: Memory) {
|
||||
)
|
||||
|
||||
fun execute() {
|
||||
setRandomByte()
|
||||
executeNextInstruction()
|
||||
isRunning = true
|
||||
while (true) {
|
||||
setRandomByte()
|
||||
executeNextInstruction()
|
||||
|
||||
if (PC == 0 || !isRunning) {
|
||||
stop()
|
||||
Log.i(TAG, "Program end at PC=$" + (PC - 1).toHexString())
|
||||
if (PC == 0 || !isRunning) {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun stop() {
|
||||
isRunning = false
|
||||
Log.i(TAG, "Program end at PC=$" + (PC - 1).toHexString() + ", A=$" + A.toHexString() +
|
||||
", X=$" + X.toHexString() + ", Y=$" + Y.toHexString())
|
||||
}
|
||||
|
||||
private fun executeNextInstruction() {
|
||||
val instruction = Integer.valueOf(popByte().toInt().toString(), 16)
|
||||
val instruction = popByte()
|
||||
val target = instructionList.get(instruction)
|
||||
if (target != null) {
|
||||
val function = target.method
|
||||
target.operation.function()
|
||||
} else {
|
||||
Log.e(TAG, "Address $" + PC.toHexString() + " - unknown opcode " + instruction.toHexString())
|
||||
isRunning = false
|
||||
}
|
||||
}
|
||||
|
||||
fun popByte(): Int {
|
||||
return memory.get((PC++).and(0xff));
|
||||
return memory.get(PC++).and(0xff);
|
||||
}
|
||||
|
||||
private fun setRandomByte() {
|
||||
|
Loading…
Reference in New Issue
Block a user