Fixes tests + minor cleanup
This commit is contained in:
parent
27bca0afc1
commit
ab597fb9d2
|
@ -14,7 +14,7 @@ import java.util.concurrent.CountDownLatch
|
||||||
class CPU(val memory: Memory) : Display.Callbacks {
|
class CPU(val memory: Memory) : Display.Callbacks {
|
||||||
private val bgHandlerThread = HandlerThread("Screencast Thread")
|
private val bgHandlerThread = HandlerThread("Screencast Thread")
|
||||||
private val bgHandler: Handler
|
private val bgHandler: Handler
|
||||||
private var lock: CountDownLatch? = null
|
private var executionLock: CountDownLatch? = null
|
||||||
|
|
||||||
init {
|
init {
|
||||||
bgHandlerThread.start()
|
bgHandlerThread.start()
|
||||||
|
@ -36,7 +36,7 @@ class CPU(val memory: Memory) : Display.Callbacks {
|
||||||
private var debug = false
|
private var debug = false
|
||||||
private var monitoring = false
|
private var monitoring = false
|
||||||
private var TAG = "CPU"
|
private var TAG = "CPU"
|
||||||
val instructionList: HashMap<Int, InstructionTarget> = HashMap()
|
private val instructionList: HashMap<Int, InstructionTarget> = HashMap()
|
||||||
private val operationList: HashMap<Instruction, BaseInstruction> = hashMapOf(
|
private val operationList: HashMap<Instruction, BaseInstruction> = hashMapOf(
|
||||||
Pair(Instruction.ADC, ADC(this)),
|
Pair(Instruction.ADC, ADC(this)),
|
||||||
Pair(Instruction.AND, AND(this)),
|
Pair(Instruction.AND, AND(this)),
|
||||||
|
@ -72,30 +72,44 @@ class CPU(val memory: Memory) : Display.Callbacks {
|
||||||
Pair(Instruction.SBC, SBC(this)),
|
Pair(Instruction.SBC, SBC(this)),
|
||||||
Pair(Instruction.BCC, BCC(this)),
|
Pair(Instruction.BCC, BCC(this)),
|
||||||
Pair(Instruction.DEC, DEC(this))
|
Pair(Instruction.DEC, DEC(this))
|
||||||
// Pair(Instruction.BMI, BMI(this)),
|
//Pair(Instruction.BMI, BMI(this)),
|
||||||
// Pair(Instruction.BVC, BVC(this)),
|
//Pair(Instruction.BVC, BVC(this)),
|
||||||
// Pair(Instruction.BVS, BVS(this)),
|
//Pair(Instruction.BVS, BVS(this)),
|
||||||
// Pair(Instruction.CPY, CPY(this)),
|
//Pair(Instruction.CPY, CPY(this)),
|
||||||
// Pair(Instruction.EOR, EOR(this)),
|
//Pair(Instruction.EOR, EOR(this)),
|
||||||
// Pair(Instruction.CLI, CLI(this)),
|
//Pair(Instruction.CLI, CLI(this)),
|
||||||
// Pair(Instruction.CLV, CLV(this)),
|
//Pair(Instruction.CLV, CLV(this)),
|
||||||
// Pair(Instruction.CLD, CLD(this)),
|
//Pair(Instruction.CLD, CLD(this)),
|
||||||
// Pair(Instruction.SED, SED(this)),
|
//Pair(Instruction.SED, SED(this)),
|
||||||
// Pair(Instruction.TAY, TAY(this)),
|
//Pair(Instruction.TAY, TAY(this)),
|
||||||
// Pair(Instruction.TYA, TYA(this)),
|
//Pair(Instruction.TYA, TYA(this)),
|
||||||
// Pair(Instruction.INY, INY(this)),
|
//Pair(Instruction.INY, INY(this)),
|
||||||
// Pair(Instruction.ROR, ROR(this)),
|
//Pair(Instruction.ROR, ROR(this)),
|
||||||
// Pair(Instruction.ROL, ROL(this)),
|
//Pair(Instruction.ROL, ROL(this)),
|
||||||
// Pair(Instruction.RTI, RTI(this)),
|
//Pair(Instruction.RTI, RTI(this)),
|
||||||
// Pair(Instruction.TXS, TXS(this)),
|
//Pair(Instruction.TXS, TXS(this)),
|
||||||
// Pair(Instruction.TSX, TSX(this)),
|
//Pair(Instruction.TSX, TSX(this)),
|
||||||
// Pair(Instruction.PHA, PHA(this)),
|
//Pair(Instruction.PHA, PHA(this)),
|
||||||
// Pair(Instruction.PLA, PLA(this)),
|
//Pair(Instruction.PLA, PLA(this)),
|
||||||
// Pair(Instruction.PHP, PHP(this)),
|
//Pair(Instruction.PHP, PHP(this)),
|
||||||
// Pair(Instruction.PLP, PLP(this)),
|
//Pair(Instruction.PLP, PLP(this)),
|
||||||
// Pair(Instruction.STY, STY(this))
|
//Pair(Instruction.STY, STY(this))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// for testing only
|
||||||
|
fun testRun() {
|
||||||
|
isRunning = true
|
||||||
|
while (true) {
|
||||||
|
setRandomByte()
|
||||||
|
executeNextInstruction()
|
||||||
|
|
||||||
|
if (PC == 0 || !isRunning) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stop()
|
||||||
|
}
|
||||||
|
|
||||||
fun run() {
|
fun run() {
|
||||||
isRunning = true
|
isRunning = true
|
||||||
bgHandler.post { innerRun() }
|
bgHandler.post { innerRun() }
|
||||||
|
@ -155,7 +169,11 @@ class CPU(val memory: Memory) : Display.Callbacks {
|
||||||
P = 0x30
|
P = 0x30
|
||||||
}
|
}
|
||||||
|
|
||||||
fun popByte(): Int {
|
fun addInstruction(opcode: Int, target: InstructionTarget) {
|
||||||
|
instructionList.put(opcode, target)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun popByte(): Int {
|
||||||
return memory.get(PC++).and(0xff)
|
return memory.get(PC++).and(0xff)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -297,11 +315,11 @@ class CPU(val memory: Memory) : Display.Callbacks {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onUpdate() {
|
override fun onUpdate() {
|
||||||
lock = CountDownLatch(1)
|
executionLock = CountDownLatch(1)
|
||||||
lock?.await()
|
executionLock?.await()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDraw() {
|
override fun onDraw() {
|
||||||
lock?.countDown()
|
executionLock?.countDown()
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,9 +1,8 @@
|
||||||
package android.emu6502.instructions
|
package android.emu6502.instructions
|
||||||
|
|
||||||
import java.util.HashMap
|
import android.emu6502.CPU
|
||||||
|
|
||||||
open class BaseInstruction(val instruction: Instruction,
|
open class BaseInstruction(val instruction: Instruction, private val cpu: CPU) {
|
||||||
private val instructionList: HashMap<Int, InstructionTarget>) {
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
val opcodes: IntArray = Opcodes.MAP[instruction] as IntArray
|
val opcodes: IntArray = Opcodes.MAP[instruction] as IntArray
|
||||||
|
@ -12,7 +11,7 @@ open class BaseInstruction(val instruction: Instruction,
|
||||||
|
|
||||||
opcodes.forEachIndexed { i, opcode ->
|
opcodes.forEachIndexed { i, opcode ->
|
||||||
if (opcode != 0xff) {
|
if (opcode != 0xff) {
|
||||||
instructionList.put(opcodes[i], InstructionTarget(this, methods[i]))
|
cpu.addInstruction(opcodes[i], InstructionTarget(this, methods[i]))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import android.emu6502.instructions.BaseInstruction
|
||||||
import android.emu6502.instructions.Instruction
|
import android.emu6502.instructions.Instruction
|
||||||
|
|
||||||
/** ADd with Carry */
|
/** ADd with Carry */
|
||||||
class ADC(private val cpu: CPU) : BaseInstruction(Instruction.ADC, cpu.instructionList) {
|
class ADC(private val cpu: CPU) : BaseInstruction(Instruction.ADC, cpu) {
|
||||||
override fun immediate() {
|
override fun immediate() {
|
||||||
testADC(cpu.popByte())
|
testADC(cpu.popByte())
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import android.emu6502.instructions.BaseInstruction
|
||||||
import android.emu6502.instructions.Instruction
|
import android.emu6502.instructions.Instruction
|
||||||
|
|
||||||
/** bitwise AND with accumulator */
|
/** bitwise AND with accumulator */
|
||||||
class AND(private val cpu: CPU) : BaseInstruction(Instruction.AND, cpu.instructionList) {
|
class AND(private val cpu: CPU) : BaseInstruction(Instruction.AND, cpu) {
|
||||||
override fun immediate() {
|
override fun immediate() {
|
||||||
cpu.A = cpu.A.and(cpu.popByte())
|
cpu.A = cpu.A.and(cpu.popByte())
|
||||||
cpu.setSZFlagsForRegA()
|
cpu.setSZFlagsForRegA()
|
||||||
|
|
|
@ -5,5 +5,5 @@ import android.emu6502.instructions.BaseInstruction
|
||||||
import android.emu6502.instructions.Instruction
|
import android.emu6502.instructions.Instruction
|
||||||
|
|
||||||
/** Arithmetic Shift Left */
|
/** Arithmetic Shift Left */
|
||||||
class ASL(private val cpu: CPU) : BaseInstruction(Instruction.ASL, cpu.instructionList) {
|
class ASL(private val cpu: CPU) : BaseInstruction(Instruction.ASL, cpu) {
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import android.emu6502.instructions.BaseInstruction
|
||||||
import android.emu6502.instructions.Instruction
|
import android.emu6502.instructions.Instruction
|
||||||
|
|
||||||
/** Branch on Carry Clear */
|
/** Branch on Carry Clear */
|
||||||
final class BCC(private val cpu: CPU) : BaseInstruction(Instruction.BCC, cpu.instructionList) {
|
final class BCC(private val cpu: CPU) : BaseInstruction(Instruction.BCC, cpu) {
|
||||||
override fun branch() {
|
override fun branch() {
|
||||||
val offset = cpu.popByte()
|
val offset = cpu.popByte()
|
||||||
if (!cpu.carry()) {
|
if (!cpu.carry()) {
|
||||||
|
|
|
@ -5,7 +5,7 @@ import android.emu6502.instructions.BaseInstruction
|
||||||
import android.emu6502.instructions.Instruction
|
import android.emu6502.instructions.Instruction
|
||||||
|
|
||||||
/** Branch on Carry Set */
|
/** Branch on Carry Set */
|
||||||
final class BCS(private val cpu: CPU) : BaseInstruction(Instruction.BCS, cpu.instructionList) {
|
final class BCS(private val cpu: CPU) : BaseInstruction(Instruction.BCS, cpu) {
|
||||||
override fun branch() {
|
override fun branch() {
|
||||||
val offset = cpu.popByte()
|
val offset = cpu.popByte()
|
||||||
if (cpu.carry()) {
|
if (cpu.carry()) {
|
||||||
|
|
|
@ -5,7 +5,7 @@ import android.emu6502.instructions.BaseInstruction
|
||||||
import android.emu6502.instructions.Instruction
|
import android.emu6502.instructions.Instruction
|
||||||
|
|
||||||
/** Branch on EQual */
|
/** Branch on EQual */
|
||||||
class BEQ(private val cpu: CPU) : BaseInstruction(Instruction.BEQ, cpu.instructionList) {
|
class BEQ(private val cpu: CPU) : BaseInstruction(Instruction.BEQ, cpu) {
|
||||||
override fun branch() {
|
override fun branch() {
|
||||||
val offset = cpu.popByte()
|
val offset = cpu.popByte()
|
||||||
if (cpu.zero()) {
|
if (cpu.zero()) {
|
||||||
|
|
|
@ -5,7 +5,7 @@ import android.emu6502.instructions.BaseInstruction
|
||||||
import android.emu6502.instructions.Instruction
|
import android.emu6502.instructions.Instruction
|
||||||
|
|
||||||
/** test BITs */
|
/** test BITs */
|
||||||
class BIT(private val cpu: CPU) : BaseInstruction(Instruction.BIT, cpu.instructionList) {
|
class BIT(private val cpu: CPU) : BaseInstruction(Instruction.BIT, cpu) {
|
||||||
override fun zeroPage() {
|
override fun zeroPage() {
|
||||||
val value = cpu.memory.get(cpu.popByte())
|
val value = cpu.memory.get(cpu.popByte())
|
||||||
BIT(value)
|
BIT(value)
|
||||||
|
|
|
@ -5,7 +5,7 @@ import android.emu6502.instructions.BaseInstruction
|
||||||
import android.emu6502.instructions.Instruction
|
import android.emu6502.instructions.Instruction
|
||||||
|
|
||||||
/** Branch on Not Equal */
|
/** Branch on Not Equal */
|
||||||
final class BNE(private val cpu: CPU) : BaseInstruction(Instruction.BNE, cpu.instructionList) {
|
final class BNE(private val cpu: CPU) : BaseInstruction(Instruction.BNE, cpu) {
|
||||||
override fun branch() {
|
override fun branch() {
|
||||||
val offset = cpu.popByte()
|
val offset = cpu.popByte()
|
||||||
if (!cpu.zero()) {
|
if (!cpu.zero()) {
|
||||||
|
|
|
@ -5,7 +5,7 @@ import android.emu6502.instructions.BaseInstruction
|
||||||
import android.emu6502.instructions.Instruction
|
import android.emu6502.instructions.Instruction
|
||||||
|
|
||||||
/** Branch on PLus */
|
/** Branch on PLus */
|
||||||
final class BPL(private val cpu: CPU) : BaseInstruction(Instruction.BPL, cpu.instructionList) {
|
final class BPL(private val cpu: CPU) : BaseInstruction(Instruction.BPL, cpu) {
|
||||||
override fun branch() {
|
override fun branch() {
|
||||||
val offset = cpu.popByte()
|
val offset = cpu.popByte()
|
||||||
if (!cpu.negative()) {
|
if (!cpu.negative()) {
|
||||||
|
|
|
@ -5,7 +5,7 @@ import android.emu6502.instructions.BaseInstruction
|
||||||
import android.emu6502.instructions.Instruction
|
import android.emu6502.instructions.Instruction
|
||||||
|
|
||||||
/** BRreaK */
|
/** BRreaK */
|
||||||
final class BRK(private val cpu: CPU) : BaseInstruction(Instruction.BRK, cpu.instructionList) {
|
final class BRK(private val cpu: CPU) : BaseInstruction(Instruction.BRK, cpu) {
|
||||||
override fun single() {
|
override fun single() {
|
||||||
cpu.stop()
|
cpu.stop()
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import android.emu6502.instructions.BaseInstruction
|
||||||
import android.emu6502.instructions.Instruction
|
import android.emu6502.instructions.Instruction
|
||||||
|
|
||||||
/** CLear Carry */
|
/** CLear Carry */
|
||||||
final class CLC(private val cpu: CPU) : BaseInstruction(Instruction.CLC, cpu.instructionList) {
|
final class CLC(private val cpu: CPU) : BaseInstruction(Instruction.CLC, cpu) {
|
||||||
override fun single() {
|
override fun single() {
|
||||||
cpu.CLC()
|
cpu.CLC()
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import android.emu6502.instructions.BaseInstruction
|
||||||
import android.emu6502.instructions.Instruction
|
import android.emu6502.instructions.Instruction
|
||||||
|
|
||||||
/** CoMPare accumulator */
|
/** CoMPare accumulator */
|
||||||
final class CMP(private val cpu: CPU) : BaseInstruction(Instruction.CMP, cpu.instructionList) {
|
final class CMP(private val cpu: CPU) : BaseInstruction(Instruction.CMP, cpu) {
|
||||||
override fun immediate() {
|
override fun immediate() {
|
||||||
cpu.doCompare(cpu.A, cpu.popByte())
|
cpu.doCompare(cpu.A, cpu.popByte())
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import android.emu6502.instructions.BaseInstruction
|
||||||
import android.emu6502.instructions.Instruction
|
import android.emu6502.instructions.Instruction
|
||||||
|
|
||||||
/** ComPare X register */
|
/** ComPare X register */
|
||||||
class CPX(private val cpu: CPU) : BaseInstruction(Instruction.CPX, cpu.instructionList) {
|
class CPX(private val cpu: CPU) : BaseInstruction(Instruction.CPX, cpu) {
|
||||||
override fun immediate() {
|
override fun immediate() {
|
||||||
val value = cpu.popByte()
|
val value = cpu.popByte()
|
||||||
cpu.doCompare(cpu.X, value)
|
cpu.doCompare(cpu.X, value)
|
||||||
|
|
|
@ -5,7 +5,7 @@ import android.emu6502.instructions.BaseInstruction
|
||||||
import android.emu6502.instructions.Instruction
|
import android.emu6502.instructions.Instruction
|
||||||
|
|
||||||
/** DECrement memory */
|
/** DECrement memory */
|
||||||
class DEC(private val cpu: CPU) : BaseInstruction(Instruction.DEC, cpu.instructionList) {
|
class DEC(private val cpu: CPU) : BaseInstruction(Instruction.DEC, cpu) {
|
||||||
override fun zeroPage() {
|
override fun zeroPage() {
|
||||||
DEC(cpu.popByte())
|
DEC(cpu.popByte())
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import android.emu6502.instructions.BaseInstruction
|
||||||
import android.emu6502.instructions.Instruction
|
import android.emu6502.instructions.Instruction
|
||||||
|
|
||||||
/** DEcrement X */
|
/** DEcrement X */
|
||||||
class DEX(private val cpu: CPU) : BaseInstruction(Instruction.DEX, cpu.instructionList) {
|
class DEX(private val cpu: CPU) : BaseInstruction(Instruction.DEX, cpu) {
|
||||||
override fun single() {
|
override fun single() {
|
||||||
cpu.X = (cpu.X - 1).and(0xff)
|
cpu.X = (cpu.X - 1).and(0xff)
|
||||||
cpu.setSZflagsForRegX()
|
cpu.setSZflagsForRegX()
|
||||||
|
|
|
@ -5,7 +5,7 @@ import android.emu6502.instructions.BaseInstruction
|
||||||
import android.emu6502.instructions.Instruction
|
import android.emu6502.instructions.Instruction
|
||||||
|
|
||||||
/** DEcrement Y */
|
/** DEcrement Y */
|
||||||
class DEY(private val cpu: CPU) : BaseInstruction(Instruction.DEY, cpu.instructionList) {
|
class DEY(private val cpu: CPU) : BaseInstruction(Instruction.DEY, cpu) {
|
||||||
override fun single() {
|
override fun single() {
|
||||||
cpu.Y = (cpu.Y - 1).and(0xff)
|
cpu.Y = (cpu.Y - 1).and(0xff)
|
||||||
cpu.setSZflagsForRegY()
|
cpu.setSZflagsForRegY()
|
||||||
|
|
|
@ -5,7 +5,7 @@ import android.emu6502.instructions.BaseInstruction
|
||||||
import android.emu6502.instructions.Instruction
|
import android.emu6502.instructions.Instruction
|
||||||
|
|
||||||
/** INCrement memory */
|
/** INCrement memory */
|
||||||
final class INC(private val cpu: CPU) : BaseInstruction(Instruction.INC, cpu.instructionList) {
|
final class INC(private val cpu: CPU) : BaseInstruction(Instruction.INC, cpu) {
|
||||||
override fun zeroPage() {
|
override fun zeroPage() {
|
||||||
inc(cpu.popByte())
|
inc(cpu.popByte())
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import android.emu6502.instructions.BaseInstruction
|
||||||
import android.emu6502.instructions.Instruction
|
import android.emu6502.instructions.Instruction
|
||||||
|
|
||||||
/** INcrement X */
|
/** INcrement X */
|
||||||
class INX(private val cpu: CPU) : BaseInstruction(Instruction.INX, cpu.instructionList) {
|
class INX(private val cpu: CPU) : BaseInstruction(Instruction.INX, cpu) {
|
||||||
override fun single() {
|
override fun single() {
|
||||||
cpu.X = (cpu.X + 1).and(0xff)
|
cpu.X = (cpu.X + 1).and(0xff)
|
||||||
cpu.setSZflagsForRegX()
|
cpu.setSZflagsForRegX()
|
||||||
|
|
|
@ -5,7 +5,7 @@ import android.emu6502.instructions.BaseInstruction
|
||||||
import android.emu6502.instructions.Instruction
|
import android.emu6502.instructions.Instruction
|
||||||
|
|
||||||
/** JuMP */
|
/** JuMP */
|
||||||
class JMP(private val cpu: CPU) : BaseInstruction(Instruction.JMP, cpu.instructionList) {
|
class JMP(private val cpu: CPU) : BaseInstruction(Instruction.JMP, cpu) {
|
||||||
override fun absolute() {
|
override fun absolute() {
|
||||||
cpu.PC = cpu.popWord()
|
cpu.PC = cpu.popWord()
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import android.emu6502.instructions.BaseInstruction
|
||||||
import android.emu6502.instructions.Instruction
|
import android.emu6502.instructions.Instruction
|
||||||
|
|
||||||
/** Jump to SubRoutine */
|
/** Jump to SubRoutine */
|
||||||
class JSR(private val cpu: CPU) : BaseInstruction(Instruction.JSR, cpu.instructionList) {
|
class JSR(private val cpu: CPU) : BaseInstruction(Instruction.JSR, cpu) {
|
||||||
override fun absolute() {
|
override fun absolute() {
|
||||||
val addr = cpu.popWord()
|
val addr = cpu.popWord()
|
||||||
val currAddr = cpu.PC - 1
|
val currAddr = cpu.PC - 1
|
||||||
|
|
|
@ -5,7 +5,7 @@ import android.emu6502.instructions.BaseInstruction
|
||||||
import android.emu6502.instructions.Instruction
|
import android.emu6502.instructions.Instruction
|
||||||
|
|
||||||
/** LoaD Accumulator */
|
/** LoaD Accumulator */
|
||||||
class LDA(private val cpu: CPU) : BaseInstruction(Instruction.LDA, cpu.instructionList) {
|
class LDA(private val cpu: CPU) : BaseInstruction(Instruction.LDA, cpu) {
|
||||||
override fun immediate() {
|
override fun immediate() {
|
||||||
cpu.A = cpu.popByte()
|
cpu.A = cpu.popByte()
|
||||||
cpu.setSZFlagsForRegA()
|
cpu.setSZFlagsForRegA()
|
||||||
|
|
|
@ -5,7 +5,7 @@ import android.emu6502.instructions.BaseInstruction
|
||||||
import android.emu6502.instructions.Instruction
|
import android.emu6502.instructions.Instruction
|
||||||
|
|
||||||
/** LoaD X register */
|
/** LoaD X register */
|
||||||
class LDX(private val cpu: CPU) : BaseInstruction(Instruction.LDX, cpu.instructionList) {
|
class LDX(private val cpu: CPU) : BaseInstruction(Instruction.LDX, cpu) {
|
||||||
override fun immediate() {
|
override fun immediate() {
|
||||||
cpu.X = cpu.popByte()
|
cpu.X = cpu.popByte()
|
||||||
cpu.setSZflagsForRegX()
|
cpu.setSZflagsForRegX()
|
||||||
|
|
|
@ -5,7 +5,7 @@ import android.emu6502.instructions.BaseInstruction
|
||||||
import android.emu6502.instructions.Instruction
|
import android.emu6502.instructions.Instruction
|
||||||
|
|
||||||
/** LoaD Y register */
|
/** LoaD Y register */
|
||||||
class LDY(private val cpu: CPU) : BaseInstruction(Instruction.LDY, cpu.instructionList) {
|
class LDY(private val cpu: CPU) : BaseInstruction(Instruction.LDY, cpu) {
|
||||||
override fun immediate() {
|
override fun immediate() {
|
||||||
cpu.Y = cpu.popByte()
|
cpu.Y = cpu.popByte()
|
||||||
cpu.setSZflagsForRegY()
|
cpu.setSZflagsForRegY()
|
||||||
|
|
|
@ -5,7 +5,7 @@ import android.emu6502.instructions.BaseInstruction
|
||||||
import android.emu6502.instructions.Instruction
|
import android.emu6502.instructions.Instruction
|
||||||
|
|
||||||
/** Logical Shift Right */
|
/** Logical Shift Right */
|
||||||
final class LSR(private val cpu: CPU) : BaseInstruction(Instruction.LSR, cpu.instructionList) {
|
final class LSR(private val cpu: CPU) : BaseInstruction(Instruction.LSR, cpu) {
|
||||||
override fun single() {
|
override fun single() {
|
||||||
cpu.setCarryFlagFromBit0(cpu.A)
|
cpu.setCarryFlagFromBit0(cpu.A)
|
||||||
cpu.A = cpu.A.shr(1)
|
cpu.A = cpu.A.shr(1)
|
||||||
|
|
|
@ -5,7 +5,7 @@ import android.emu6502.instructions.BaseInstruction
|
||||||
import android.emu6502.instructions.Instruction
|
import android.emu6502.instructions.Instruction
|
||||||
|
|
||||||
/** No OPeration */
|
/** No OPeration */
|
||||||
class NOP(private val cpu: CPU) : BaseInstruction(Instruction.NOP, cpu.instructionList) {
|
class NOP(private val cpu: CPU) : BaseInstruction(Instruction.NOP, cpu) {
|
||||||
override fun single() {
|
override fun single() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,5 +5,5 @@ import android.emu6502.instructions.BaseInstruction
|
||||||
import android.emu6502.instructions.Instruction
|
import android.emu6502.instructions.Instruction
|
||||||
|
|
||||||
/** bitwise OR with Accumulator */
|
/** bitwise OR with Accumulator */
|
||||||
class ORA(cpu: CPU) : BaseInstruction(Instruction.ORA, cpu.instructionList) {
|
class ORA(cpu: CPU) : BaseInstruction(Instruction.ORA, cpu) {
|
||||||
}
|
}
|
|
@ -5,7 +5,7 @@ import android.emu6502.instructions.BaseInstruction
|
||||||
import android.emu6502.instructions.Instruction
|
import android.emu6502.instructions.Instruction
|
||||||
|
|
||||||
/** ReTurn from Subroutine */
|
/** ReTurn from Subroutine */
|
||||||
class RTS(private val cpu: CPU) : BaseInstruction(Instruction.RTS, cpu.instructionList) {
|
class RTS(private val cpu: CPU) : BaseInstruction(Instruction.RTS, cpu) {
|
||||||
override fun single() {
|
override fun single() {
|
||||||
cpu.PC = cpu.stackPop().or(cpu.stackPop().shl(8)) + 1
|
cpu.PC = cpu.stackPop().or(cpu.stackPop().shl(8)) + 1
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import android.emu6502.instructions.BaseInstruction
|
||||||
import android.emu6502.instructions.Instruction
|
import android.emu6502.instructions.Instruction
|
||||||
|
|
||||||
/** SuBtract with Carry */
|
/** SuBtract with Carry */
|
||||||
class SBC(private val cpu: CPU) : BaseInstruction(Instruction.SBC, cpu.instructionList) {
|
class SBC(private val cpu: CPU) : BaseInstruction(Instruction.SBC, cpu) {
|
||||||
override fun immediate() {
|
override fun immediate() {
|
||||||
testSBC(cpu.popByte())
|
testSBC(cpu.popByte())
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import android.emu6502.instructions.BaseInstruction
|
||||||
import android.emu6502.instructions.Instruction
|
import android.emu6502.instructions.Instruction
|
||||||
|
|
||||||
/** SEt Carry */
|
/** SEt Carry */
|
||||||
class SEC(private val cpu: CPU) : BaseInstruction(Instruction.SEC, cpu.instructionList) {
|
class SEC(private val cpu: CPU) : BaseInstruction(Instruction.SEC, cpu) {
|
||||||
override fun single() {
|
override fun single() {
|
||||||
cpu.carry()
|
cpu.carry()
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,6 @@ import android.emu6502.instructions.BaseInstruction
|
||||||
import android.emu6502.instructions.Instruction
|
import android.emu6502.instructions.Instruction
|
||||||
|
|
||||||
/** SEt Interrupt */
|
/** SEt Interrupt */
|
||||||
class SEI(private val cpu: CPU) : BaseInstruction(Instruction.SEI, cpu.instructionList) {
|
class SEI(private val cpu: CPU) : BaseInstruction(Instruction.SEI, cpu) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ import android.emu6502.instructions.Instruction
|
||||||
|
|
||||||
/** STore Accumulator */
|
/** STore Accumulator */
|
||||||
class STA(private val memory: Memory, private val cpu: CPU)
|
class STA(private val memory: Memory, private val cpu: CPU)
|
||||||
: BaseInstruction(Instruction.STA, cpu.instructionList) {
|
: BaseInstruction(Instruction.STA, cpu) {
|
||||||
|
|
||||||
override fun absolute() {
|
override fun absolute() {
|
||||||
memory.storeByte(cpu.popWord(), cpu.A)
|
memory.storeByte(cpu.popWord(), cpu.A)
|
||||||
|
|
|
@ -5,7 +5,7 @@ import android.emu6502.instructions.BaseInstruction
|
||||||
import android.emu6502.instructions.Instruction
|
import android.emu6502.instructions.Instruction
|
||||||
|
|
||||||
/** STore X register */
|
/** STore X register */
|
||||||
class STX(private val cpu: CPU) : BaseInstruction(Instruction.STX, cpu.instructionList) {
|
class STX(private val cpu: CPU) : BaseInstruction(Instruction.STX, cpu) {
|
||||||
override fun zeroPage() {
|
override fun zeroPage() {
|
||||||
cpu.memory.storeByte(cpu.popByte(), cpu.X)
|
cpu.memory.storeByte(cpu.popByte(), cpu.X)
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import android.emu6502.instructions.BaseInstruction
|
||||||
import android.emu6502.instructions.Instruction
|
import android.emu6502.instructions.Instruction
|
||||||
|
|
||||||
/** Transfer A to X */
|
/** Transfer A to X */
|
||||||
class TAX(private val cpu: CPU) : BaseInstruction(Instruction.TAX, cpu.instructionList) {
|
class TAX(private val cpu: CPU) : BaseInstruction(Instruction.TAX, cpu) {
|
||||||
override fun single() {
|
override fun single() {
|
||||||
cpu.X = cpu.A.and(0xFF)
|
cpu.X = cpu.A.and(0xFF)
|
||||||
cpu.setSZflagsForRegX()
|
cpu.setSZflagsForRegX()
|
||||||
|
|
|
@ -5,7 +5,7 @@ import android.emu6502.instructions.BaseInstruction
|
||||||
import android.emu6502.instructions.Instruction
|
import android.emu6502.instructions.Instruction
|
||||||
|
|
||||||
/** Transfer X to A */
|
/** Transfer X to A */
|
||||||
class TXA(private val cpu: CPU) : BaseInstruction(Instruction.TXA, cpu.instructionList) {
|
class TXA(private val cpu: CPU) : BaseInstruction(Instruction.TXA, cpu) {
|
||||||
override fun single() {
|
override fun single() {
|
||||||
cpu.A = cpu.X.and(0xff)
|
cpu.A = cpu.X.and(0xff)
|
||||||
cpu.setSZFlagsForRegA()
|
cpu.setSZFlagsForRegA()
|
||||||
|
|
|
@ -34,7 +34,7 @@ public class CPUTest {
|
||||||
"LDA #$08",
|
"LDA #$08",
|
||||||
"STA $0202");
|
"STA $0202");
|
||||||
assembler.assembleCode(lines);
|
assembler.assembleCode(lines);
|
||||||
cpu.run();
|
cpu.testRun();
|
||||||
assertThat(cpu.getA(), equalTo(0x08));
|
assertThat(cpu.getA(), equalTo(0x08));
|
||||||
assertThat(cpu.getX(), equalTo(0x00));
|
assertThat(cpu.getX(), equalTo(0x00));
|
||||||
assertThat(cpu.getY(), equalTo(0x00));
|
assertThat(cpu.getY(), equalTo(0x00));
|
||||||
|
@ -51,7 +51,7 @@ public class CPUTest {
|
||||||
"ADC #$c4 ;Add the hex value $c4 to the A register",
|
"ADC #$c4 ;Add the hex value $c4 to the A register",
|
||||||
"BRK ;Break - we're done");
|
"BRK ;Break - we're done");
|
||||||
assembler.assembleCode(lines);
|
assembler.assembleCode(lines);
|
||||||
cpu.run();
|
cpu.testRun();
|
||||||
assertThat(cpu.getA(), equalTo(0x84));
|
assertThat(cpu.getA(), equalTo(0x84));
|
||||||
assertThat(cpu.getX(), equalTo(0xC1));
|
assertThat(cpu.getX(), equalTo(0xC1));
|
||||||
assertThat(cpu.getY(), equalTo(0x00));
|
assertThat(cpu.getY(), equalTo(0x00));
|
||||||
|
@ -72,7 +72,7 @@ public class CPUTest {
|
||||||
"STX $0201",
|
"STX $0201",
|
||||||
"BRK");
|
"BRK");
|
||||||
assembler.assembleCode(lines);
|
assembler.assembleCode(lines);
|
||||||
cpu.run();
|
cpu.testRun();
|
||||||
assertThat(cpu.getA(), equalTo(0x00));
|
assertThat(cpu.getA(), equalTo(0x00));
|
||||||
assertThat(cpu.getX(), equalTo(0x03));
|
assertThat(cpu.getX(), equalTo(0x03));
|
||||||
assertThat(cpu.getY(), equalTo(0x00));
|
assertThat(cpu.getY(), equalTo(0x00));
|
||||||
|
@ -92,7 +92,7 @@ public class CPUTest {
|
||||||
"there:",
|
"there:",
|
||||||
"STA $0200");
|
"STA $0200");
|
||||||
assembler.assembleCode(lines);
|
assembler.assembleCode(lines);
|
||||||
cpu.run();
|
cpu.testRun();
|
||||||
assertThat(cpu.getA(), equalTo(0x03));
|
assertThat(cpu.getA(), equalTo(0x03));
|
||||||
assertThat(cpu.getX(), equalTo(0x00));
|
assertThat(cpu.getX(), equalTo(0x00));
|
||||||
assertThat(cpu.getY(), equalTo(0x00));
|
assertThat(cpu.getY(), equalTo(0x00));
|
||||||
|
@ -120,7 +120,7 @@ public class CPUTest {
|
||||||
"end:",
|
"end:",
|
||||||
"BRK");
|
"BRK");
|
||||||
assembler.assembleCode(lines);
|
assembler.assembleCode(lines);
|
||||||
cpu.run();
|
cpu.testRun();
|
||||||
assertThat(cpu.getA(), equalTo(0x00));
|
assertThat(cpu.getA(), equalTo(0x00));
|
||||||
assertThat(cpu.getX(), equalTo(0x05));
|
assertThat(cpu.getX(), equalTo(0x05));
|
||||||
assertThat(cpu.getY(), equalTo(0x00));
|
assertThat(cpu.getY(), equalTo(0x00));
|
||||||
|
@ -134,7 +134,7 @@ public class CPUTest {
|
||||||
"define a_dozen $0c ; a constant",
|
"define a_dozen $0c ; a constant",
|
||||||
"LDX #a_dozen ; equivalent to \"LDX #$0c\"");
|
"LDX #a_dozen ; equivalent to \"LDX #$0c\"");
|
||||||
assembler.assembleCode(lines);
|
assembler.assembleCode(lines);
|
||||||
cpu.run();
|
cpu.testRun();
|
||||||
assertThat(cpu.getA(), equalTo(0x00));
|
assertThat(cpu.getA(), equalTo(0x00));
|
||||||
assertThat(cpu.getX(), equalTo(0x0C));
|
assertThat(cpu.getX(), equalTo(0x0C));
|
||||||
assertThat(cpu.getY(), equalTo(0x00));
|
assertThat(cpu.getY(), equalTo(0x00));
|
||||||
|
@ -372,7 +372,7 @@ public class CPUTest {
|
||||||
" rts",
|
" rts",
|
||||||
"gameOver:", "\n");
|
"gameOver:", "\n");
|
||||||
assembler.assembleCode(lines);
|
assembler.assembleCode(lines);
|
||||||
cpu.run();
|
cpu.testRun();
|
||||||
assertThat(cpu.getA(), equalTo(0x1f));
|
assertThat(cpu.getA(), equalTo(0x1f));
|
||||||
assertThat(cpu.getX(), equalTo(0xff));
|
assertThat(cpu.getX(), equalTo(0xff));
|
||||||
assertThat(cpu.getY(), equalTo(0x00));
|
assertThat(cpu.getY(), equalTo(0x00));
|
||||||
|
|
Loading…
Reference in New Issue