Add size and cycles to instructions

This commit is contained in:
Felipe Lima 2017-03-15 23:40:26 -07:00
parent 3950fea47c
commit c03b318c47
7 changed files with 208 additions and 86 deletions

View File

@ -99,43 +99,43 @@ class Assembler(private var memory: Memory, private val symbols: Symbols) {
return DCB(param)
}
val opcode = Opcodes.MAP.get(Instruction.valueOf(command))
val opcode = Opcodes.MAP[Instruction.valueOf(command)]
if (opcode != null) {
if (checkImmediate(param, opcode[0])) {
if (checkImmediate(param, opcode[0].opcode)) {
return true
}
if (checkZeroPage(param, opcode[1])) {
if (checkZeroPage(param, opcode[1].opcode)) {
return true
}
if (checkZeroPageX(param, opcode[2])) {
if (checkZeroPageX(param, opcode[2].opcode)) {
return true
}
if (checkZeroPageY(param, opcode[3])) {
if (checkZeroPageY(param, opcode[3].opcode)) {
return true
}
if (checkAbsolute(param, opcode[4])) {
if (checkAbsolute(param, opcode[4].opcode)) {
return true
}
if (checkAbsoluteX(param, opcode[5])) {
if (checkAbsoluteX(param, opcode[5].opcode)) {
return true
}
if (checkAbsoluteY(param, opcode[6])) {
if (checkAbsoluteY(param, opcode[6].opcode)) {
return true
}
if (checkIndirect(param, opcode[7])) {
if (checkIndirect(param, opcode[7].opcode)) {
return true
}
if (checkIndirectX(param, opcode[8])) {
if (checkIndirectX(param, opcode[8].opcode)) {
return true
}
if (checkIndirectY(param, opcode[9])) {
if (checkIndirectY(param, opcode[9].opcode)) {
return true
}
if (checkSingle(param, opcode[10])) {
if (checkSingle(param, opcode[10].opcode)) {
return true
}
if (checkBranch(param, opcode[11])) {
if (checkBranch(param, opcode[11].opcode)) {
return true
}
}

View File

@ -109,7 +109,7 @@ class CPU(val memory: Memory) : Display.Callbacks {
target.method.invoke()
} else {
val candidate = Opcodes.MAP.entries
.first { it.value.any { opcode -> opcode == instruction } }
.first { it.value.any { it.opcode == instruction } }
throw Exception(
"Address $${PC.toHexString()} - unknown opcode 0x${instruction.toHexString()} " +
"(instruction ${candidate.key.name})")

View File

@ -10,7 +10,7 @@ import android.view.View
open class Display(context: Context, attrs: AttributeSet) : View(context, attrs) {
private val numX = 32
private val numY = 32
private val matrix = Array(32, { IntArray(32) })
private val matrix = Array(numX, { IntArray(numY) })
private val palette = arrayOf(
"#000000", "#ffffff", "#880000", "#aaffee",
@ -22,14 +22,18 @@ open class Display(context: Context, attrs: AttributeSet) : View(context, attrs)
private val bgPaint: Paint = Paint()
private var listener: Callbacks? = null
init {
bgPaint.color = Color.BLACK
}
fun setOnDisplayCallback(callback: Callbacks) {
listener = callback
}
open fun updatePixel(addr: Int, value: Int) {
val offsetAddr = addr - 0x200
val x = offsetAddr % 32
val y = Math.floor((offsetAddr / 32).toDouble()).toInt()
val x = offsetAddr % numX
val y = Math.floor((offsetAddr / numY).toDouble()).toInt()
val color = palette[value]
matrix[x][y] = Color.parseColor(color)
postInvalidate()
@ -69,8 +73,4 @@ open class Display(context: Context, attrs: AttributeSet) : View(context, attrs)
}
postInvalidate()
}
init {
bgPaint.color = Color.BLACK
}
}

View File

@ -4,7 +4,7 @@ import android.emu6502.CPU
open class BaseInstruction(val instruction: Instruction, private val cpu: CPU) {
init {
val opcodes: IntArray = Opcodes.MAP[instruction] as IntArray
val opcodes = Opcodes.MAP[instruction]
val methods = arrayOf(
this::immediate,
this::zeroPage,
@ -19,9 +19,9 @@ open class BaseInstruction(val instruction: Instruction, private val cpu: CPU) {
this::single,
this::branch)
opcodes.forEachIndexed { i, opcode ->
if (opcode != 0xff) {
cpu.addInstruction(opcodes[i], InstructionTarget(this, methods[i]))
opcodes!!.forEachIndexed { i, opcode ->
if (opcode.opcode != 0xff) {
cpu.addInstruction(opcodes[i].opcode, InstructionTarget(this, methods[i]))
}
}
}

View File

@ -0,0 +1,3 @@
package android.emu6502.instructions
data class InstructionMode(val opcode: Int, val size: Int, val cycles: Int)

View File

@ -1,66 +1,181 @@
package android.emu6502.instructions
// http://www.obelisk.me.uk/6502/reference.html
class Opcodes {
companion object {
val MAP: Map<Instruction, IntArray> = hashMapOf(
/* Name, Imm, ZP, ZPX, ZPY, ABS, ABSX, ABSY, IND, INDX, INDY, SNGL, BRA */
Pair(Instruction.ADC, intArrayOf(0x69, 0x65, 0x75, 0xff, 0x6d, 0x7d, 0x79, 0xff, 0x61, 0x71, 0xff, 0xff)),
Pair(Instruction.AND, intArrayOf(0x29, 0x25, 0x35, 0xff, 0x2d, 0x3d, 0x39, 0xff, 0x21, 0x31, 0xff, 0xff)),
Pair(Instruction.ASL, intArrayOf(0xff, 0x06, 0x16, 0xff, 0x0e, 0x1e, 0xff, 0xff, 0xff, 0xff, 0x0a, 0xff)),
Pair(Instruction.BIT, intArrayOf(0xff, 0x24, 0xff, 0xff, 0x2c, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff)),
Pair(Instruction.BPL, intArrayOf(0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x10)),
Pair(Instruction.BMI, intArrayOf(0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x30)),
Pair(Instruction.BVC, intArrayOf(0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x50)),
Pair(Instruction.BVS, intArrayOf(0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x70)),
Pair(Instruction.BCC, intArrayOf(0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x90)),
Pair(Instruction.BCS, intArrayOf(0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xb0)),
Pair(Instruction.BNE, intArrayOf(0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xd0)),
Pair(Instruction.BEQ, intArrayOf(0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0)),
Pair(Instruction.BRK, intArrayOf(0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xff)),
Pair(Instruction.CMP, intArrayOf(0xc9, 0xc5, 0xd5, 0xff, 0xcd, 0xdd, 0xd9, 0xff, 0xc1, 0xd1, 0xff, 0xff)),
Pair(Instruction.CPX, intArrayOf(0xe0, 0xe4, 0xff, 0xff, 0xec, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff)),
Pair(Instruction.CPY, intArrayOf(0xc0, 0xc4, 0xff, 0xff, 0xcc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff)),
Pair(Instruction.DEC, intArrayOf(0xff, 0xc6, 0xd6, 0xff, 0xce, 0xde, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff)),
Pair(Instruction.EOR, intArrayOf(0x49, 0x45, 0x55, 0xff, 0x4d, 0x5d, 0x59, 0xff, 0x41, 0x51, 0xff, 0xff)),
Pair(Instruction.CLC, intArrayOf(0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x18, 0xff)),
Pair(Instruction.SEC, intArrayOf(0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x38, 0xff)),
Pair(Instruction.CLI, intArrayOf(0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x58, 0xff)),
Pair(Instruction.SEI, intArrayOf(0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x78, 0xff)),
Pair(Instruction.CLV, intArrayOf(0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xb8, 0xff)),
Pair(Instruction.CLD, intArrayOf(0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xd8, 0xff)),
Pair(Instruction.SED, intArrayOf(0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0xff)),
Pair(Instruction.INC, intArrayOf(0xff, 0xe6, 0xf6, 0xff, 0xee, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff)),
Pair(Instruction.JMP, intArrayOf(0xff, 0xff, 0xff, 0xff, 0x4c, 0xff, 0xff, 0x6c, 0xff, 0xff, 0xff, 0xff)),
Pair(Instruction.JSR, intArrayOf(0xff, 0xff, 0xff, 0xff, 0x20, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff)),
Pair(Instruction.LDA, intArrayOf(0xa9, 0xa5, 0xb5, 0xff, 0xad, 0xbd, 0xb9, 0xff, 0xa1, 0xb1, 0xff, 0xff)),
Pair(Instruction.LDX, intArrayOf(0xa2, 0xa6, 0xff, 0xb6, 0xae, 0xff, 0xbe, 0xff, 0xff, 0xff, 0xff, 0xff)),
Pair(Instruction.LDY, intArrayOf(0xa0, 0xa4, 0xb4, 0xff, 0xac, 0xbc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff)),
Pair(Instruction.LSR, intArrayOf(0xff, 0x46, 0x56, 0xff, 0x4e, 0x5e, 0xff, 0xff, 0xff, 0xff, 0x4a, 0xff)),
Pair(Instruction.NOP, intArrayOf(0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xea, 0xff)),
Pair(Instruction.ORA, intArrayOf(0x09, 0x05, 0x15, 0xff, 0x0d, 0x1d, 0x19, 0xff, 0x01, 0x11, 0xff, 0xff)),
Pair(Instruction.TAX, intArrayOf(0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xaa, 0xff)),
Pair(Instruction.TXA, intArrayOf(0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8a, 0xff)),
Pair(Instruction.DEX, intArrayOf(0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xca, 0xff)),
Pair(Instruction.INX, intArrayOf(0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe8, 0xff)),
Pair(Instruction.TAY, intArrayOf(0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xa8, 0xff)),
Pair(Instruction.TYA, intArrayOf(0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x98, 0xff)),
Pair(Instruction.DEY, intArrayOf(0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x88, 0xff)),
Pair(Instruction.INY, intArrayOf(0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc8, 0xff)),
Pair(Instruction.ROR, intArrayOf(0xff, 0x66, 0x76, 0xff, 0x6e, 0x7e, 0xff, 0xff, 0xff, 0xff, 0x6a, 0xff)),
Pair(Instruction.ROL, intArrayOf(0xff, 0x26, 0x36, 0xff, 0x2e, 0x3e, 0xff, 0xff, 0xff, 0xff, 0x2a, 0xff)),
Pair(Instruction.RTI, intArrayOf(0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x40, 0xff)),
Pair(Instruction.RTS, intArrayOf(0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x60, 0xff)),
Pair(Instruction.SBC, intArrayOf(0xe9, 0xe5, 0xf5, 0xff, 0xed, 0xfd, 0xf9, 0xff, 0xe1, 0xf1, 0xff, 0xff)),
Pair(Instruction.STA, intArrayOf(0xff, 0x85, 0x95, 0xff, 0x8d, 0x9d, 0x99, 0xff, 0x81, 0x91, 0xff, 0xff)),
Pair(Instruction.TXS, intArrayOf(0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x9a, 0xff)),
Pair(Instruction.TSX, intArrayOf(0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xba, 0xff)),
Pair(Instruction.PHA, intArrayOf(0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x48, 0xff)),
Pair(Instruction.PLA, intArrayOf(0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x68, 0xff)),
Pair(Instruction.PHP, intArrayOf(0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x08, 0xff)),
Pair(Instruction.PLP, intArrayOf(0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x28, 0xff)),
Pair(Instruction.STX, intArrayOf(0xff, 0x86, 0xff, 0x96, 0x8e, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff)),
Pair(Instruction.STY, intArrayOf(0xff, 0x84, 0x94, 0xff, 0x8c, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff)),
Pair(Instruction.XXX, intArrayOf(0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff))
)
private fun im(opcode: Int, size: Int, cycles: Int) = InstructionMode(opcode, size, cycles)
val MAP: Map<Instruction, Array<InstructionMode>> = hashMapOf(
Instruction.ADC to arrayOf(im(0x69, 2, 2), im(0x65, 2, 3), im(0x75, 2, 4), im(0xff, 0, 0),
im(0x6d, 3, 4), im(0x7d, 3, 4), im(0x79, 3, 4), im(0xff, 0, 0), im(0x61, 2, 6),
im(0x71, 2, 5), im(0xff, 0, 0), im(0xff, 0, 0)),
Instruction.AND to arrayOf(im(0x29, 2, 2), im(0x25, 2, 3), im(0x35, 2, 4), im(0xff, 0, 0),
im(0x2d, 3, 4), im(0x3d, 3, 4), im(0x39, 3, 4), im(0xff, 0, 0), im(0x21, 2, 6),
im(0x31, 2, 5), im(0xff, 0, 0), im(0xff, 0, 0)),
Instruction.ASL to arrayOf(im(0xff, 0, 0), im(0x06, 2, 5), im(0x16, 2, 6), im(0xff, 0, 0),
im(0x0e, 2, 5), im(0x1e, 3, 7), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xff, 0, 0), im(0x0a, 1, 2), im(0xff, 0, 0)),
Instruction.BIT to arrayOf(im(0xff, 0, 0), im(0x24, 2, 3), im(0xff, 0, 0), im(0xff, 0, 0),
im(0x2c, 3, 4), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0)),
Instruction.BPL to arrayOf(im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xff, 0, 0), im(0xff, 0, 0), im(0x10, 2, 2)),
Instruction.BMI to arrayOf(im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xff, 0, 0), im(0xff, 0, 0), im(0x30, 2, 2)),
Instruction.BVC to arrayOf(im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xff, 0, 0), im(0xff, 0, 0), im(0x50, 2, 2)),
Instruction.BVS to arrayOf(im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xff, 0, 0), im(0xff, 0, 0), im(0x70, 2, 2)),
Instruction.BCC to arrayOf(im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xff, 0, 0), im(0xff, 0, 0), im(0x90, 2, 2)),
Instruction.BCS to arrayOf(im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xff, 0, 0), im(0xff, 0, 0), im(0xb0, 2, 2)),
Instruction.BNE to arrayOf(im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xff, 0, 0), im(0xff, 0, 0), im(0xd0, 2, 2)),
Instruction.BEQ to arrayOf(im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xff, 0, 0), im(0xff, 0, 0), im(0xf0, 2, 2)),
Instruction.BRK to arrayOf(im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xff, 0, 0), im(0x00, 1, 7), im(0xff, 0, 0)),
Instruction.CMP to arrayOf(im(0xc9, 2, 2), im(0xc5, 2, 3), im(0xd5, 2, 4), im(0xff, 0, 0),
im(0xcd, 3, 4), im(0xdd, 3, 4), im(0xd9, 3, 4), im(0xff, 0, 0), im(0xc1, 2, 6),
im(0xd1, 2, 5), im(0xff, 0, 0), im(0xff, 0, 0)),
Instruction.CPX to arrayOf(im(0xe0, 2, 2), im(0xe4, 2, 3), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xec, 3, 4), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0)),
Instruction.CPY to arrayOf(im(0xc0, 2, 2), im(0xc4, 2, 3), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xcc, 3, 4), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0)),
Instruction.DEC to arrayOf(im(0xff, 0, 0), im(0xc6, 2, 5), im(0xd6, 2, 6), im(0xff, 0, 0),
im(0xce, 3, 6), im(0xde, 3, 7), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0)),
Instruction.EOR to arrayOf(im(0x49, 2, 2), im(0x45, 2, 3), im(0x55, 2, 4), im(0xff, 0, 0),
im(0x4d, 3, 4), im(0x5d, 3, 4), im(0x59, 3, 4), im(0xff, 0, 0), im(0x41, 2, 6),
im(0x51, 2, 5), im(0xff, 0, 0), im(0xff, 0, 0)),
Instruction.CLC to arrayOf(im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xff, 0, 0), im(0x18, 1, 2), im(0xff, 0, 0)),
Instruction.SEC to arrayOf(im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xff, 0, 0), im(0x38, 1, 2), im(0xff, 0, 0)),
Instruction.CLI to arrayOf(im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xff, 0, 0), im(0x58, 1, 2), im(0xff, 0, 0)),
Instruction.SEI to arrayOf(im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xff, 0, 0), im(0x78, 1, 2), im(0xff, 0, 0)),
Instruction.CLV to arrayOf(im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xff, 0, 0), im(0xb8, 1, 2), im(0xff, 0, 0)),
Instruction.CLD to arrayOf(im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xff, 0, 0), im(0xd8, 1, 2), im(0xff, 0, 0)),
Instruction.SED to arrayOf(im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xff, 0, 0), im(0xf8, 1, 2), im(0xff, 0, 0)),
Instruction.INC to arrayOf(im(0xff, 0, 0), im(0xe6, 2, 5), im(0xf6, 2, 6), im(0xff, 0, 0),
im(0xee, 3, 6), im(0xfe, 3, 7), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0)),
Instruction.JMP to arrayOf(im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0x4c, 3, 3), im(0xff, 0, 0), im(0xff, 0, 0), im(0x6c, 3, 5), im(0xff, 0, 0),
im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0)),
Instruction.JSR to arrayOf(im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0x20, 3, 6), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0)),
Instruction.LDA to arrayOf(im(0xa9, 2, 2), im(0xa5, 2, 3), im(0xb5, 2, 4), im(0xff, 0, 0),
im(0xad, 3, 4), im(0xbd, 3, 4), im(0xb9, 3, 4), im(0xff, 0, 0), im(0xa1, 2, 6),
im(0xb1, 2, 5), im(0xff, 0, 0), im(0xff, 0, 0)),
Instruction.LDX to arrayOf(im(0xa2, 2, 2), im(0xa6, 2, 3), im(0xff, 0, 0), im(0xb6, 2, 4),
im(0xae, 3, 4), im(0xff, 0, 0), im(0xbe, 3, 4), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0)),
Instruction.LDY to arrayOf(im(0xa0, 2, 2), im(0xa4, 2, 3), im(0xb4, 2, 4), im(0xff, 0, 0),
im(0xac, 3, 4), im(0xbc, 3, 4), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0)),
Instruction.LSR to arrayOf(im(0xff, 0, 0), im(0x46, 2, 5), im(0x56, 2, 6), im(0xff, 0, 0),
im(0x4e, 3, 6), im(0x5e, 3, 7), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xff, 0, 0), im(0x4a, 1, 2), im(0xff, 0, 0)),
Instruction.NOP to arrayOf(im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xff, 0, 0), im(0xea, 1, 2), im(0xff, 0, 0)),
Instruction.ORA to arrayOf(im(0x09, 2, 2), im(0x05, 2, 3), im(0x15, 2, 4), im(0xff, 0, 0),
im(0x0d, 3, 4), im(0x1d, 3, 4), im(0x19, 3, 4), im(0xff, 0, 0), im(0x01, 2, 6),
im(0x11, 2, 5), im(0xff, 0, 0), im(0xff, 0, 0)),
Instruction.TAX to arrayOf(im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xff, 0, 0), im(0xaa, 1, 2), im(0xff, 0, 0)),
Instruction.TXA to arrayOf(im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xff, 0, 0), im(0x8a, 1, 2), im(0xff, 0, 0)),
Instruction.DEX to arrayOf(im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xff, 0, 0), im(0xca, 1, 2), im(0xff, 0, 0)),
Instruction.INX to arrayOf(im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xff, 0, 0), im(0xe8, 1, 2), im(0xff, 0, 0)),
Instruction.TAY to arrayOf(im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xff, 0, 0), im(0xa8, 1, 2), im(0xff, 0, 0)),
Instruction.TYA to arrayOf(im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xff, 0, 0), im(0x98, 1, 2), im(0xff, 0, 0)),
Instruction.DEY to arrayOf(im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xff, 0, 0), im(0x88, 1, 2), im(0xff, 0, 0)),
Instruction.INY to arrayOf(im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xff, 0, 0), im(0xc8, 1, 2), im(0xff, 0, 0)),
Instruction.ROR to arrayOf(im(0xff, 0, 0), im(0x66, 2, 5), im(0x76, 2, 6), im(0xff, 0, 0),
im(0x6e, 3, 6), im(0x7e, 3, 7), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xff, 0, 0), im(0x6a, 1, 2), im(0xff, 0, 0)),
Instruction.ROL to arrayOf(im(0xff, 0, 0), im(0x26, 2, 5), im(0x36, 2, 6), im(0xff, 0, 0),
im(0x2e, 3, 6), im(0x3e, 3, 7), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xff, 0, 0), im(0x2a, 1, 2), im(0xff, 0, 0)),
Instruction.RTI to arrayOf(im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xff, 0, 0), im(0x40, 1, 6), im(0xff, 0, 0)),
Instruction.RTS to arrayOf(im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xff, 0, 0), im(0x60, 1, 6), im(0xff, 0, 0)),
Instruction.SBC to arrayOf(im(0xe9, 2, 2), im(0xe5, 2, 3), im(0xf5, 2, 4), im(0xff, 0, 0),
im(0xed, 3, 4), im(0xfd, 3, 4), im(0xf9, 3, 4), im(0xff, 0, 0), im(0xe1, 2, 6),
im(0xf1, 2, 5), im(0xff, 0, 0), im(0xff, 0, 0)),
Instruction.STA to arrayOf(im(0xff, 0, 0), im(0x85, 2, 3), im(0x95, 2, 4), im(0xff, 0, 0),
im(0x8d, 3, 4), im(0x9d, 3, 5), im(0x99, 3, 5), im(0xff, 0, 0), im(0x81, 2, 6),
im(0x91, 2, 6), im(0xff, 0, 0), im(0xff, 0, 0)),
Instruction.TXS to arrayOf(im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xff, 0, 0), im(0x9a, 1, 2), im(0xff, 0, 0)),
Instruction.TSX to arrayOf(im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xff, 0, 0), im(0xba, 1, 2), im(0xff, 0, 0)),
Instruction.PHA to arrayOf(im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xff, 0, 0), im(0x48, 1, 3), im(0xff, 0, 0)),
Instruction.PLA to arrayOf(im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xff, 0, 0), im(0x68, 1, 4), im(0xff, 0, 0)),
Instruction.PHP to arrayOf(im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xff, 0, 0), im(0xff, 0, 0), im(0x08, 1, 3), im(0xff, 0, 0)),
Instruction.PLP to arrayOf(im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xff, 0, 0), im(0xff, 0, 0), im(0x28, 1, 4), im(0xff, 0, 0)),
Instruction.STX to arrayOf(im(0xff, 0, 0), im(0x86, 2, 3), im(0xff, 0, 0), im(0x96, 2, 4),
im(0x8e, 3, 4), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0)),
Instruction.STY to arrayOf(im(0xff, 0, 0), im(0x84, 2, 3), im(0x94, 2, 4), im(0xff, 0, 0),
im(0x8c, 3, 4), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0)),
Instruction.XXX to arrayOf(im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0),
im(0xff, 0, 0), im(0xff, 0, 0), im(0xff, 0, 0)))
}
}
}

View File

@ -15,6 +15,10 @@ class Console(
val mapper: Mapper,
val ram: ByteArray = ByteArray(2048)
) {
fun step() {
}
companion object {
fun newConsole(cartridge: Cartridge, display: Display): Console {
val ppu = PPU()