6502Android/app/src/main/kotlin/android/emu6502/instructions/BaseInstruction.kt

89 lines
2.6 KiB
Kotlin
Raw Normal View History

2015-06-09 17:21:49 +00:00
package android.emu6502.instructions
2015-06-30 07:35:06 +00:00
import android.emu6502.CPU
2015-06-09 17:21:49 +00:00
2015-06-30 07:35:06 +00:00
open class BaseInstruction(val instruction: Instruction, private val cpu: CPU) {
2015-06-09 17:21:49 +00:00
init {
val opcodes: IntArray = Opcodes.MAP[instruction] as IntArray
2017-03-08 05:30:12 +00:00
val methods = arrayOf(
this::immediate,
this::zeroPage,
this::zeroPageX,
this::zeroPageY,
this::absolute,
this::absoluteX,
this::absoluteY,
this::indirect,
this::indirectX,
this::indirectY,
this::single,
this::branch)
2015-06-09 17:21:49 +00:00
opcodes.forEachIndexed { i, opcode ->
if (opcode != 0xff) {
2015-06-30 07:35:06 +00:00
cpu.addInstruction(opcodes[i], InstructionTarget(this, methods[i]))
2015-06-09 17:21:49 +00:00
}
}
}
open fun immediate() {
2017-03-08 05:30:12 +00:00
throw IllegalStateException("Instruction " + javaClass.simpleName + " not implemented" +
2015-06-22 01:06:44 +00:00
" with immediate addressing")
2015-06-09 17:21:49 +00:00
}
open fun zeroPage() {
2017-03-08 05:30:12 +00:00
throw IllegalStateException("Instruction " + javaClass.simpleName + " not implemented" +
2015-06-22 01:06:44 +00:00
" with zeroPage addressing")
2015-06-09 17:21:49 +00:00
}
open fun zeroPageX() {
2017-03-08 05:30:12 +00:00
throw IllegalStateException("Instruction " + javaClass.simpleName + " not implemented" +
2015-06-22 01:06:44 +00:00
" with zeroPageX addressing")
2015-06-09 17:21:49 +00:00
}
open fun zeroPageY() {
2017-03-08 05:30:12 +00:00
throw IllegalStateException("Instruction " + javaClass.simpleName + " not implemented" +
2015-06-22 01:06:44 +00:00
" with zeroPageY addressing")
2015-06-09 17:21:49 +00:00
}
open fun absolute() {
2017-03-08 05:30:12 +00:00
throw IllegalStateException("Instruction " + javaClass.simpleName + " not implemented" +
2015-06-22 01:06:44 +00:00
" with absolute addressing")
2015-06-09 17:21:49 +00:00
}
open fun absoluteX() {
2017-03-08 05:30:12 +00:00
throw IllegalStateException("Instruction " + javaClass.simpleName + " not implemented" +
2015-06-22 01:06:44 +00:00
" with absoluteX addressing")
2015-06-09 17:21:49 +00:00
}
open fun absoluteY() {
2017-03-08 05:30:12 +00:00
throw IllegalStateException("Instruction " + javaClass.simpleName + " not implemented" +
2015-06-22 01:06:44 +00:00
" with absoluteY addressing")
2015-06-09 17:21:49 +00:00
}
open fun indirect() {
2017-03-08 05:30:12 +00:00
throw IllegalStateException("Instruction " + javaClass.simpleName + " not implemented" +
2015-06-22 01:06:44 +00:00
" with indirect addressing")
2015-06-09 17:21:49 +00:00
}
open fun indirectX() {
2017-03-08 05:30:12 +00:00
throw IllegalStateException("Instruction " + javaClass.simpleName + " not implemented" +
2015-06-22 01:06:44 +00:00
" with indirectX addressing")
2015-06-09 17:21:49 +00:00
}
open fun indirectY() {
2017-03-08 05:30:12 +00:00
throw IllegalStateException("Instruction " + javaClass.simpleName + " not implemented" +
2015-06-22 01:06:44 +00:00
" with indirectY addressing")
2015-06-09 17:21:49 +00:00
}
open fun single() {
2017-03-08 05:30:12 +00:00
throw IllegalStateException("Instruction " + javaClass.simpleName + " not implemented" +
2015-06-22 01:06:44 +00:00
" with single addressing")
2015-06-09 17:21:49 +00:00
}
open fun branch() {
2017-03-08 05:30:12 +00:00
throw IllegalStateException("Instruction " + javaClass.simpleName + " not implemented" +
2015-06-22 01:06:44 +00:00
" with branch addressing")
2015-06-09 17:21:49 +00:00
}
}