mirror of
https://github.com/felipecsl/6502Android.git
synced 2024-06-08 06:29:32 +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() {
|
fun execute() {
|
||||||
|
isRunning = true
|
||||||
|
while (true) {
|
||||||
setRandomByte()
|
setRandomByte()
|
||||||
executeNextInstruction()
|
executeNextInstruction()
|
||||||
|
|
||||||
if (PC == 0 || !isRunning) {
|
if (PC == 0 || !isRunning) {
|
||||||
stop()
|
break
|
||||||
Log.i(TAG, "Program end at PC=$" + (PC - 1).toHexString())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun stop() {
|
|
||||||
isRunning = false
|
isRunning = false
|
||||||
|
Log.i(TAG, "Program end at PC=$" + (PC - 1).toHexString() + ", A=$" + A.toHexString() +
|
||||||
|
", X=$" + X.toHexString() + ", Y=$" + Y.toHexString())
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun executeNextInstruction() {
|
private fun executeNextInstruction() {
|
||||||
val instruction = Integer.valueOf(popByte().toInt().toString(), 16)
|
val instruction = popByte()
|
||||||
val target = instructionList.get(instruction)
|
val target = instructionList.get(instruction)
|
||||||
if (target != null) {
|
if (target != null) {
|
||||||
val function = target.method
|
val function = target.method
|
||||||
target.operation.function()
|
target.operation.function()
|
||||||
} else {
|
} else {
|
||||||
Log.e(TAG, "Address $" + PC.toHexString() + " - unknown opcode " + instruction.toHexString())
|
Log.e(TAG, "Address $" + PC.toHexString() + " - unknown opcode " + instruction.toHexString())
|
||||||
|
isRunning = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun popByte(): Int {
|
fun popByte(): Int {
|
||||||
return memory.get((PC++).and(0xff));
|
return memory.get(PC++).and(0xff);
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setRandomByte() {
|
private fun setRandomByte() {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user