diff options
Diffstat (limited to 'src/main/kotlin')
| -rw-r--r-- | src/main/kotlin/cpu/opcodes/Arithmetic16Bit.kt | 28 | ||||
| -rw-r--r-- | src/main/kotlin/cpu/opcodes/Arithmetic8Bit.kt | 192 | ||||
| -rw-r--r-- | src/main/kotlin/cpu/opcodes/Bit.kt | 52 | ||||
| -rw-r--r-- | src/main/kotlin/cpu/opcodes/Calls.kt | 10 | ||||
| -rw-r--r-- | src/main/kotlin/cpu/opcodes/Jumps.kt | 22 | ||||
| -rw-r--r-- | src/main/kotlin/cpu/opcodes/Loads16Bit.kt | 42 | ||||
| -rw-r--r-- | src/main/kotlin/cpu/opcodes/Loads8Bit.kt | 197 | ||||
| -rw-r--r-- | src/main/kotlin/cpu/opcodes/Misc.kt | 42 | ||||
| -rw-r--r-- | src/main/kotlin/cpu/opcodes/Restarts.kt | 16 | ||||
| -rw-r--r-- | src/main/kotlin/cpu/opcodes/Returns.kt | 12 | ||||
| -rw-r--r-- | src/main/kotlin/cpu/opcodes/Rotates.kt | 78 | ||||
| -rw-r--r-- | src/main/kotlin/cpu/opcodes/Shifts.kt | 52 |
12 files changed, 371 insertions, 372 deletions
diff --git a/src/main/kotlin/cpu/opcodes/Arithmetic16Bit.kt b/src/main/kotlin/cpu/opcodes/Arithmetic16Bit.kt index 0eff88a..8d21224 100644 --- a/src/main/kotlin/cpu/opcodes/Arithmetic16Bit.kt +++ b/src/main/kotlin/cpu/opcodes/Arithmetic16Bit.kt @@ -7,12 +7,12 @@ import BitManipulation as bm var arithmetic16Bit = mapOf( - 0x09 to Operation("ADD HL,BC", 0, 8, {r, _, _ -> r.HL = add(r.HL, r.BC, r)}), - 0x19 to Operation("ADD HL,DE", 0, 8, {r, _, _ -> r.HL = add(r.HL, r.DE, r)}), - 0x29 to Operation("ADD HL,HL", 0, 8, {r, _, _ -> r.HL = add(r.HL, r.HL, r)}), - 0x39 to Operation("ADD HL,SP", 0, 8, {r, _, _ -> r.HL = add(r.HL, r.SP, r)}), + 0x09 to Operation("ADD HL,BC", 0, 8) { r, _, _ -> r.HL = add(r.HL, r.BC, r)}, + 0x19 to Operation("ADD HL,DE", 0, 8) { r, _, _ -> r.HL = add(r.HL, r.DE, r)}, + 0x29 to Operation("ADD HL,HL", 0, 8) { r, _, _ -> r.HL = add(r.HL, r.HL, r)}, + 0x39 to Operation("ADD HL,SP", 0, 8) { r, _, _ -> r.HL = add(r.HL, r.SP, r)}, - 0xE8 to Operation("ADD SP,n", 1, 16, {r, _, a -> + 0xE8 to Operation("ADD SP,n", 1, 16) { r, _, a -> r.clearFlags() val absoluteValue = bm.getAbsoluteValue(a[0]) @@ -27,17 +27,17 @@ var arithmetic16Bit = mapOf( r.setFlagFromBool(Flag.CARRY,(r.SP and 0xFF) + absoluteValue > 0xFF) r.SP = r.SP + absoluteValue } - }), + }, - 0x03 to Operation("INC BC", 0, 8, {r, _, _ -> r.BC = inc(r.BC)}), - 0x13 to Operation("INC DE", 0, 8, {r, _, _ -> r.DE = inc(r.DE)}), - 0x23 to Operation("INC HL", 0, 8, {r, _, _ -> r.HL = inc(r.HL)}), - 0x33 to Operation("INC SP", 0, 8, {r, _, _ -> r.SP = inc(r.SP)}), + 0x03 to Operation("INC BC", 0, 8) { r, _, _ -> r.BC = inc(r.BC)}, + 0x13 to Operation("INC DE", 0, 8) { r, _, _ -> r.DE = inc(r.DE)}, + 0x23 to Operation("INC HL", 0, 8) { r, _, _ -> r.HL = inc(r.HL)}, + 0x33 to Operation("INC SP", 0, 8) { r, _, _ -> r.SP = inc(r.SP)}, - 0x0B to Operation("DEC BC", 0, 8, {r, _, _ -> r.BC = dec(r.BC)}), - 0x1B to Operation("DEC DE", 0, 8, {r, _, _ -> r.DE = dec(r.DE)}), - 0x2B to Operation("DEC HL", 0, 8, {r, _, _ -> r.HL = dec(r.HL)}), - 0x3B to Operation("DEC SP", 0, 8, {r, _, _ -> r.SP = dec(r.SP)}) + 0x0B to Operation("DEC BC", 0, 8) { r, _, _ -> r.BC = dec(r.BC)}, + 0x1B to Operation("DEC DE", 0, 8) { r, _, _ -> r.DE = dec(r.DE)}, + 0x2B to Operation("DEC HL", 0, 8) { r, _, _ -> r.HL = dec(r.HL)}, + 0x3B to Operation("DEC SP", 0, 8) { r, _, _ -> r.SP = dec(r.SP)} ) diff --git a/src/main/kotlin/cpu/opcodes/Arithmetic8Bit.kt b/src/main/kotlin/cpu/opcodes/Arithmetic8Bit.kt index 6addc95..2df3b6c 100644 --- a/src/main/kotlin/cpu/opcodes/Arithmetic8Bit.kt +++ b/src/main/kotlin/cpu/opcodes/Arithmetic8Bit.kt @@ -7,105 +7,105 @@ import BitManipulation as bm var arithmetic8Bit = mapOf( - 0x87 to Operation("ADD A,A", 0, 4, {r, _, _ -> r.A = add(r.A, r.A, r)}), - 0x80 to Operation("ADD A,B", 0, 4, {r, _, _ -> r.A = add(r.A, r.B, r)}), - 0x81 to Operation("ADD A,C", 0, 4, {r, _, _ -> r.A = add(r.A, r.C, r)}), - 0x82 to Operation("ADD A,D", 0, 4, {r, _, _ -> r.A = add(r.A, r.D, r)}), - 0x83 to Operation("ADD A,E", 0, 4, {r, _, _ -> r.A = add(r.A, r.E, r)}), - 0x84 to Operation("ADD A,H", 0, 4, {r, _, _ -> r.A = add(r.A, r.H, r)}), - 0x85 to Operation("ADD A,L", 0, 4, {r, _, _ -> r.A = add(r.A, r.L, r)}), - 0x86 to Operation("ADD A,(HL)", 0, 8, {r, m, _ -> r.A = add(r.A, m.readByte(r.HL), r)}), - 0xC6 to Operation("ADD A,n", 1, 8, {r, _, a -> r.A = add(r.A, a[0], r)}), - - 0x8F to Operation("ADC A,A", 0, 4, {r, _, _ -> r.A = addWithCarry(r.A, r.A, r) }), - 0x88 to Operation("ADC A,B", 0, 4, {r, _, _ -> r.A = addWithCarry(r.A, r.B, r)}), - 0x89 to Operation("ADC A,C", 0, 4, {r, _, _ -> r.A = addWithCarry(r.A, r.C, r)}), - 0x8A to Operation("ADC A,D", 0, 4, {r, _, _ -> r.A = addWithCarry(r.A, r.D, r)}), - 0x8B to Operation("ADC A,E", 0, 4, {r, _, _ -> r.A = addWithCarry(r.A, r.E, r)}), - 0x8C to Operation("ADC A,H", 0, 4, {r, _, _ -> r.A = addWithCarry(r.A, r.H, r)}), - 0x8D to Operation("ADC A,L", 0, 4, {r, _, _ -> r.A = addWithCarry(r.A, r.L, r)}), - 0x8E to Operation("ADC A,(HL)", 0, 8, {r, m, _ -> r.A = addWithCarry(r.A, m.readByte(r.HL), r)}), - 0xCE to Operation("ADC A,n", 1, 8, {r, _, a -> r.A = addWithCarry(r.A, a[0], r)}), - - 0x97 to Operation("SUB A,A", 0, 4, {r, _, _ -> r.A = subtract(r.A, r.A, r)}), - 0x90 to Operation("SUB A,B", 0, 4, {r, _, _ -> r.A = subtract(r.A, r.B, r)}), - 0x91 to Operation("SUB A,C", 0, 4, {r, _, _ -> r.A = subtract(r.A, r.C, r)}), - 0x92 to Operation("SUB A,D", 0, 4, {r, _, _ -> r.A = subtract(r.A, r.D, r)}), - 0x93 to Operation("SUB A,E", 0, 4, {r, _, _ -> r.A = subtract(r.A, r.E, r)}), - 0x94 to Operation("SUB A,H", 0, 4, {r, _, _ -> r.A = subtract(r.A, r.H, r)}), - 0x95 to Operation("SUB A,L", 0, 4, {r, _, _ -> r.A = subtract(r.A, r.L, r)}), - 0x96 to Operation("SUB A,(HL)", 0, 8, {r, m, _ -> r.A = subtract(r.A, m.readByte(r.HL), r)}), - 0xD6 to Operation("SUB A,n", 1, 8, {r, _, a -> r.A = subtract(r.A, a[0], r)}), - - 0x9F to Operation("SBC A,A", 0, 4, {r, _, _ -> r.A = subtractWithCarry(r.A, r.A, r) }), - 0x98 to Operation("SBC A,B", 0, 4, {r, _, _ -> r.A = subtractWithCarry(r.A, r.B, r)}), - 0x99 to Operation("SBC A,C", 0, 4, {r, _, _ -> r.A = subtractWithCarry(r.A, r.C, r)}), - 0x9A to Operation("SBC A,D", 0, 4, {r, _, _ -> r.A = subtractWithCarry(r.A, r.D, r)}), - 0x9B to Operation("SBC A,E", 0, 4, {r, _, _ -> r.A = subtractWithCarry(r.A, r.E, r)}), - 0x9C to Operation("SBC A,H", 0, 4, {r, _, _ -> r.A = subtractWithCarry(r.A, r.H, r)}), - 0x9D to Operation("SBC A,L", 0, 4, {r, _, _ -> r.A = subtractWithCarry(r.A, r.L, r)}), - 0x9E to Operation("SBC A,(HL)", 0, 8, {r, m, _ -> r.A = subtractWithCarry(r.A, m.readByte(r.HL), r)}), + 0x87 to Operation("ADD A,A", 0, 4) { r, _, _ -> r.A = add(r.A, r.A, r)}, + 0x80 to Operation("ADD A,B", 0, 4) { r, _, _ -> r.A = add(r.A, r.B, r)}, + 0x81 to Operation("ADD A,C", 0, 4) { r, _, _ -> r.A = add(r.A, r.C, r)}, + 0x82 to Operation("ADD A,D", 0, 4) { r, _, _ -> r.A = add(r.A, r.D, r)}, + 0x83 to Operation("ADD A,E", 0, 4) { r, _, _ -> r.A = add(r.A, r.E, r)}, + 0x84 to Operation("ADD A,H", 0, 4) { r, _, _ -> r.A = add(r.A, r.H, r)}, + 0x85 to Operation("ADD A,L", 0, 4) { r, _, _ -> r.A = add(r.A, r.L, r)}, + 0x86 to Operation("ADD A,(HL)", 0, 8) { r, m, _ -> r.A = add(r.A, m.readByte(r.HL), r)}, + 0xC6 to Operation("ADD A,n", 1, 8) { r, _, a -> r.A = add(r.A, a[0], r)}, + + 0x8F to Operation("ADC A,A", 0, 4) { r, _, _ -> r.A = addWithCarry(r.A, r.A, r) }, + 0x88 to Operation("ADC A,B", 0, 4) { r, _, _ -> r.A = addWithCarry(r.A, r.B, r)}, + 0x89 to Operation("ADC A,C", 0, 4) { r, _, _ -> r.A = addWithCarry(r.A, r.C, r)}, + 0x8A to Operation("ADC A,D", 0, 4) { r, _, _ -> r.A = addWithCarry(r.A, r.D, r)}, + 0x8B to Operation("ADC A,E", 0, 4) { r, _, _ -> r.A = addWithCarry(r.A, r.E, r)}, + 0x8C to Operation("ADC A,H", 0, 4) { r, _, _ -> r.A = addWithCarry(r.A, r.H, r)}, + 0x8D to Operation("ADC A,L", 0, 4) { r, _, _ -> r.A = addWithCarry(r.A, r.L, r)}, + 0x8E to Operation("ADC A,(HL)", 0, 8) { r, m, _ -> r.A = addWithCarry(r.A, m.readByte(r.HL), r)}, + 0xCE to Operation("ADC A,n", 1, 8) { r, _, a -> r.A = addWithCarry(r.A, a[0], r)}, + + 0x97 to Operation("SUB A,A", 0, 4) { r, _, _ -> r.A = subtract(r.A, r.A, r)}, + 0x90 to Operation("SUB A,B", 0, 4) { r, _, _ -> r.A = subtract(r.A, r.B, r)}, + 0x91 to Operation("SUB A,C", 0, 4) { r, _, _ -> r.A = subtract(r.A, r.C, r)}, + 0x92 to Operation("SUB A,D", 0, 4) { r, _, _ -> r.A = subtract(r.A, r.D, r)}, + 0x93 to Operation("SUB A,E", 0, 4) { r, _, _ -> r.A = subtract(r.A, r.E, r)}, + 0x94 to Operation("SUB A,H", 0, 4) { r, _, _ -> r.A = subtract(r.A, r.H, r)}, + 0x95 to Operation("SUB A,L", 0, 4) { r, _, _ -> r.A = subtract(r.A, r.L, r)}, + 0x96 to Operation("SUB A,(HL)", 0, 8) { r, m, _ -> r.A = subtract(r.A, m.readByte(r.HL), r)}, + 0xD6 to Operation("SUB A,n", 1, 8) { r, _, a -> r.A = subtract(r.A, a[0], r)}, + + 0x9F to Operation("SBC A,A", 0, 4) { r, _, _ -> r.A = subtractWithCarry(r.A, r.A, r) }, + 0x98 to Operation("SBC A,B", 0, 4) { r, _, _ -> r.A = subtractWithCarry(r.A, r.B, r)}, + 0x99 to Operation("SBC A,C", 0, 4) { r, _, _ -> r.A = subtractWithCarry(r.A, r.C, r)}, + 0x9A to Operation("SBC A,D", 0, 4) { r, _, _ -> r.A = subtractWithCarry(r.A, r.D, r)}, + 0x9B to Operation("SBC A,E", 0, 4) { r, _, _ -> r.A = subtractWithCarry(r.A, r.E, r)}, + 0x9C to Operation("SBC A,H", 0, 4) { r, _, _ -> r.A = subtractWithCarry(r.A, r.H, r)}, + 0x9D to Operation("SBC A,L", 0, 4) { r, _, _ -> r.A = subtractWithCarry(r.A, r.L, r)}, + 0x9E to Operation("SBC A,(HL)", 0, 8) { r, m, _ -> r.A = subtractWithCarry(r.A, m.readByte(r.HL), r)}, // opcode missing in CPU manual? http://pastraiser.com/cpu/gameboy/gameboy_opcodes.html lists as 0xDE - 0xDE to Operation("SBC A,n", 1, 8, {r, _, a -> r.A = subtractWithCarry(r.A, a[0], r)}), - - 0xA7 to Operation("AND A,A", 0, 4, {r, _, _ -> r.A = and(r.A, r.A, r)}), - 0xA0 to Operation("AND A,B", 0, 4, {r, _, _ -> r.A = and(r.A, r.B, r)}), - 0xA1 to Operation("AND A,C", 0, 4, {r, _, _ -> r.A = and(r.A, r.C, r)}), - 0xA2 to Operation("AND A,D", 0, 4, {r, _, _ -> r.A = and(r.A, r.D, r)}), - 0xA3 to Operation("AND A,E", 0, 4, {r, _, _ -> r.A = and(r.A, r.E, r)}), - 0xA4 to Operation("AND A,H", 0, 4, {r, _, _ -> r.A = and(r.A, r.H, r)}), - 0xA5 to Operation("AND A,L", 0, 4, {r, _, _ -> r.A = and(r.A, r.L, r)}), - 0xA6 to Operation("AND A,(HL)", 0, 8, {r, m, _ -> r.A = and(r.A, m.readByte(r.HL), r)}), - 0xE6 to Operation("AND A,n", 1, 8, {r, _, a -> r.A = and(r.A, a[0], r)}), - - 0xB7 to Operation("OR A,A", 0, 4, {r, _, _ -> r.A = or(r.A, r.A, r)}), - 0xB0 to Operation("OR A,B", 0, 4, {r, _, _ -> r.A = or(r.A, r.B, r)}), - 0xB1 to Operation("OR A,C", 0, 4, {r, _, _ -> r.A = or(r.A, r.C, r)}), - 0xB2 to Operation("OR A,D", 0, 4, {r, _, _ -> r.A = or(r.A, r.D, r)}), - 0xB3 to Operation("OR A,E", 0, 4, {r, _, _ -> r.A = or(r.A, r.E, r)}), - 0xB4 to Operation("OR A,H", 0, 4, {r, _, _ -> r.A = or(r.A, r.H, r)}), - 0xB5 to Operation("OR A,L", 0, 4, {r, _, _ -> r.A = or(r.A, r.L, r)}), - 0xB6 to Operation("OR A,(HL)", 0, 8, {r, m, _ -> r.A = or(r.A, m.readByte(r.HL), r)}), - 0xF6 to Operation("OR A,n", 1, 8, {r, _, a -> r.A = or(r.A, a[0], r)}), - - 0xAF to Operation("XOR A,A", 0, 4, {r, _, _ -> r.A = xor(r.A, r.A, r)}), - 0xA8 to Operation("XOR A,B", 0, 4, {r, _, _ -> r.A = xor(r.A, r.B, r)}), - 0xA9 to Operation("XOR A,C", 0, 4, {r, _, _ -> r.A = xor(r.A, r.C, r)}), - 0xAA to Operation("XOR A,D", 0, 4, {r, _, _ -> r.A = xor(r.A, r.D, r)}), - 0xAB to Operation("XOR A,E", 0, 4, {r, _, _ -> r.A = xor(r.A, r.E, r)}), - 0xAC to Operation("XOR A,H", 0, 4, {r, _, _ -> r.A = xor(r.A, r.H, r)}), - 0xAD to Operation("XOR A,L", 0, 4, {r, _, _ -> r.A = xor(r.A, r.L, r)}), - 0xAE to Operation("XOR A,(HL)", 0, 8, {r, m, _ -> r.A = xor(r.A, m.readByte(r.HL), r)}), - 0xEE to Operation("XOR A,n", 1, 8, {r, _, a -> r.A = xor(r.A, a[0], r)}), + 0xDE to Operation("SBC A,n", 1, 8) { r, _, a -> r.A = subtractWithCarry(r.A, a[0], r)}, + + 0xA7 to Operation("AND A,A", 0, 4) { r, _, _ -> r.A = and(r.A, r.A, r)}, + 0xA0 to Operation("AND A,B", 0, 4) { r, _, _ -> r.A = and(r.A, r.B, r)}, + 0xA1 to Operation("AND A,C", 0, 4) { r, _, _ -> r.A = and(r.A, r.C, r)}, + 0xA2 to Operation("AND A,D", 0, 4) { r, _, _ -> r.A = and(r.A, r.D, r)}, + 0xA3 to Operation("AND A,E", 0, 4) { r, _, _ -> r.A = and(r.A, r.E, r)}, + 0xA4 to Operation("AND A,H", 0, 4) { r, _, _ -> r.A = and(r.A, r.H, r)}, + 0xA5 to Operation("AND A,L", 0, 4) { r, _, _ -> r.A = and(r.A, r.L, r)}, + 0xA6 to Operation("AND A,(HL)", 0, 8) { r, m, _ -> r.A = and(r.A, m.readByte(r.HL), r)}, + 0xE6 to Operation("AND A,n", 1, 8) { r, _, a -> r.A = and(r.A, a[0], r)}, + + 0xB7 to Operation("OR A,A", 0, 4) { r, _, _ -> r.A = or(r.A, r.A, r)}, + 0xB0 to Operation("OR A,B", 0, 4) { r, _, _ -> r.A = or(r.A, r.B, r)}, + 0xB1 to Operation("OR A,C", 0, 4) { r, _, _ -> r.A = or(r.A, r.C, r)}, + 0xB2 to Operation("OR A,D", 0, 4) { r, _, _ -> r.A = or(r.A, r.D, r)}, + 0xB3 to Operation("OR A,E", 0, 4) { r, _, _ -> r.A = or(r.A, r.E, r)}, + 0xB4 to Operation("OR A,H", 0, 4) { r, _, _ -> r.A = or(r.A, r.H, r)}, + 0xB5 to Operation("OR A,L", 0, 4) { r, _, _ -> r.A = or(r.A, r.L, r)}, + 0xB6 to Operation("OR A,(HL)", 0, 8) { r, m, _ -> r.A = or(r.A, m.readByte(r.HL), r)}, + 0xF6 to Operation("OR A,n", 1, 8) { r, _, a -> r.A = or(r.A, a[0], r)}, + + 0xAF to Operation("XOR A,A", 0, 4) { r, _, _ -> r.A = xor(r.A, r.A, r)}, + 0xA8 to Operation("XOR A,B", 0, 4) { r, _, _ -> r.A = xor(r.A, r.B, r)}, + 0xA9 to Operation("XOR A,C", 0, 4) { r, _, _ -> r.A = xor(r.A, r.C, r)}, + 0xAA to Operation("XOR A,D", 0, 4) { r, _, _ -> r.A = xor(r.A, r.D, r)}, + 0xAB to Operation("XOR A,E", 0, 4) { r, _, _ -> r.A = xor(r.A, r.E, r)}, + 0xAC to Operation("XOR A,H", 0, 4) { r, _, _ -> r.A = xor(r.A, r.H, r)}, + 0xAD to Operation("XOR A,L", 0, 4) { r, _, _ -> r.A = xor(r.A, r.L, r)}, + 0xAE to Operation("XOR A,(HL)", 0, 8) { r, m, _ -> r.A = xor(r.A, m.readByte(r.HL), r)}, + 0xEE to Operation("XOR A,n", 1, 8) { r, _, a -> r.A = xor(r.A, a[0], r)}, // Compare is just A - n but the result is discarded - 0xBF to Operation("CP A,A", 0, 4, {r, _, _ -> subtract(r.A, r.A, r)}), - 0xB8 to Operation("CP A,B", 0, 4, {r, _, _ -> subtract(r.A, r.B, r)}), - 0xB9 to Operation("CP A,C", 0, 4, {r, _, _ -> subtract(r.A, r.C, r)}), - 0xBA to Operation("CP A,D", 0, 4, {r, _, _ -> subtract(r.A, r.D, r)}), - 0xBB to Operation("CP A,E", 0, 4, {r, _, _ -> subtract(r.A, r.E, r)}), - 0xBC to Operation("CP A,H", 0, 4, {r, _, _ -> subtract(r.A, r.H, r)}), - 0xBD to Operation("CP A,L", 0, 4, {r, _, _ -> subtract(r.A, r.L, r)}), - 0xBE to Operation("CP A,(HL)", 0, 8, {r, m, _ -> subtract(r.A, m.readByte(r.HL), r)}), - 0xFE to Operation("CP A,n", 1, 8, {r, _, a -> subtract(r.A, a[0], r)}), - - 0x3C to Operation("INC A", 0, 4, {r, _, _ -> r.A = inc(r.A, r)}), - 0x04 to Operation("INC B", 0, 4, {r, _, _ -> r.B = inc(r.B, r)}), - 0x0C to Operation("INC C", 0, 4, {r, _, _ -> r.C = inc(r.C, r)}), - 0x14 to Operation("INC D", 0, 4, {r, _, _ -> r.D = inc(r.D, r)}), - 0x1C to Operation("INC E", 0, 4, {r, _, _ -> r.E = inc(r.E, r)}), - 0x24 to Operation("INC H", 0, 4, {r, _, _ -> r.H = inc(r.H, r)}), - 0x2C to Operation("INC L", 0, 4, {r, _, _ -> r.L = inc(r.L, r)}), - 0x34 to Operation("INC (HL)", 0, 12, {r, m, _ -> m.writeByte(r.HL, inc(m.readByte(r.HL), r))}), - - 0x3D to Operation("DEC A", 0, 4, {r, _, _ -> r.A = dec(r.A, r)}), - 0x05 to Operation("DEC B", 0, 4, {r, _, _ -> r.B = dec(r.B, r)}), - 0x0D to Operation("DEC C", 0, 4, {r, _, _ -> r.C = dec(r.C, r)}), - 0x15 to Operation("DEC D", 0, 4, {r, _, _ -> r.D = dec(r.D, r)}), - 0x1D to Operation("DEC E", 0, 4, {r, _, _ -> r.E = dec(r.E, r)}), - 0x25 to Operation("DEC H", 0, 4, {r, _, _ -> r.H = dec(r.H, r)}), - 0x2D to Operation("DEC L", 0, 4, {r, _, _ -> r.L = dec(r.L, r)}), - 0x35 to Operation("DEC (HL)", 0, 12, {r, m, _ -> m.writeByte(r.HL, dec(m.readByte(r.HL), r))}) + 0xBF to Operation("CP A,A", 0, 4) { r, _, _ -> subtract(r.A, r.A, r)}, + 0xB8 to Operation("CP A,B", 0, 4) { r, _, _ -> subtract(r.A, r.B, r)}, + 0xB9 to Operation("CP A,C", 0, 4) { r, _, _ -> subtract(r.A, r.C, r)}, + 0xBA to Operation("CP A,D", 0, 4) { r, _, _ -> subtract(r.A, r.D, r)}, + 0xBB to Operation("CP A,E", 0, 4) { r, _, _ -> subtract(r.A, r.E, r)}, + 0xBC to Operation("CP A,H", 0, 4) { r, _, _ -> subtract(r.A, r.H, r)}, + 0xBD to Operation("CP A,L", 0, 4) { r, _, _ -> subtract(r.A, r.L, r)}, + 0xBE to Operation("CP A,(HL)", 0, 8) { r, m, _ -> subtract(r.A, m.readByte(r.HL), r)}, + 0xFE to Operation("CP A,n", 1, 8) { r, _, a -> subtract(r.A, a[0], r)}, + + 0x3C to Operation("INC A", 0, 4) { r, _, _ -> r.A = inc(r.A, r)}, + 0x04 to Operation("INC B", 0, 4) { r, _, _ -> r.B = inc(r.B, r)}, + 0x0C to Operation("INC C", 0, 4) { r, _, _ -> r.C = inc(r.C, r)}, + 0x14 to Operation("INC D", 0, 4) { r, _, _ -> r.D = inc(r.D, r)}, + 0x1C to Operation("INC E", 0, 4) { r, _, _ -> r.E = inc(r.E, r)}, + 0x24 to Operation("INC H", 0, 4) { r, _, _ -> r.H = inc(r.H, r)}, + 0x2C to Operation("INC L", 0, 4) { r, _, _ -> r.L = inc(r.L, r)}, + 0x34 to Operation("INC (HL)", 0, 12) { r, m, _ -> m.writeByte(r.HL, inc(m.readByte(r.HL), r))}, + + 0x3D to Operation("DEC A", 0, 4) { r, _, _ -> r.A = dec(r.A, r)}, + 0x05 to Operation("DEC B", 0, 4) { r, _, _ -> r.B = dec(r.B, r)}, + 0x0D to Operation("DEC C", 0, 4) { r, _, _ -> r.C = dec(r.C, r)}, + 0x15 to Operation("DEC D", 0, 4) { r, _, _ -> r.D = dec(r.D, r)}, + 0x1D to Operation("DEC E", 0, 4) { r, _, _ -> r.E = dec(r.E, r)}, + 0x25 to Operation("DEC H", 0, 4) { r, _, _ -> r.H = dec(r.H, r)}, + 0x2D to Operation("DEC L", 0, 4) { r, _, _ -> r.L = dec(r.L, r)}, + 0x35 to Operation("DEC (HL)", 0, 12) { r, m, _ -> m.writeByte(r.HL, dec(m.readByte(r.HL), r))} ) private fun add(n1: Int, n2: Int, r: Registers): Int { diff --git a/src/main/kotlin/cpu/opcodes/Bit.kt b/src/main/kotlin/cpu/opcodes/Bit.kt index 9aaea4c..90510c8 100644 --- a/src/main/kotlin/cpu/opcodes/Bit.kt +++ b/src/main/kotlin/cpu/opcodes/Bit.kt @@ -9,32 +9,32 @@ fun generateExtendedBitOps(): Map<Int, Operation> { val bitOps = mutableMapOf<Int, Operation>() IntRange(0, 7).forEach{ i -> - bitOps[0x47 + (0x08 * i)] = Operation("BIT $i,A", 0, 8, {r, _, _ -> bit(r.A, i, r) }) - bitOps[0x40 + (0x08 * i)] = Operation("BIT $i,B", 0, 8, {r, _, _ -> bit(r.B, i, r) }) - bitOps[0x41 + (0x08 * i)] = Operation("BIT $i,C", 0, 8, {r, _, _ -> bit(r.C, i, r) }) - bitOps[0x42 + (0x08 * i)] = Operation("BIT $i,D", 0, 8, {r, _, _ -> bit(r.D, i, r) }) - bitOps[0x43 + (0x08 * i)] = Operation("BIT $i,E", 0, 8, {r, _, _ -> bit(r.E, i, r) }) - bitOps[0x44 + (0x08 * i)] = Operation("BIT $i,H", 0, 8, {r, _, _ -> bit(r.H, i, r) }) - bitOps[0x45 + (0x08 * i)] = Operation("BIT $i,L", 0, 8, {r, _, _ -> bit(r.L, i, r) }) - bitOps[0x46 + (0x08 * i)] = Operation("BIT $i,(HL)", 0, 16, {r, m, _ -> bit(m.readByte(r.HL), i, r) }) - - bitOps[0xC7 + (0x08 * i)] = Operation("SET $i,A", 0, 8, {r, _, _ -> r.A = set(r.A, i) }) - bitOps[0xC0 + (0x08 * i)] = Operation("SET $i,B", 0, 8, {r, _, _ -> r.B = set(r.B, i) }) - bitOps[0xC1 + (0x08 * i)] = Operation("SET $i,C", 0, 8, {r, _, _ -> r.C = set(r.C, i) }) - bitOps[0xC2 + (0x08 * i)] = Operation("SET $i,D", 0, 8, {r, _, _ -> r.D = set(r.D, i) }) - bitOps[0xC3 + (0x08 * i)] = Operation("SET $i,E", 0, 8, {r, _, _ -> r.E = set(r.E, i) }) - bitOps[0xC4 + (0x08 * i)] = Operation("SET $i,H", 0, 8, {r, _, _ -> r.H = set(r.H, i) }) - bitOps[0xC5 + (0x08 * i)] = Operation("SET $i,L", 0, 8, {r, _, _ -> r.L = set(r.L, i) }) - bitOps[0xC6 + (0x08 * i)] = Operation("SET $i,(HL)", 0, 16, {r, m, _ -> m.writeByte(r.HL, set(m.readByte(r.HL), i)) }) - - bitOps[0x87 + (0x08 * i)] = Operation("RES $i,A", 0, 8, {r, _, _ -> r.A = reset(r.A, i) }) - bitOps[0x80 + (0x08 * i)] = Operation("RES $i,B", 0, 8, {r, _, _ -> r.B = reset(r.B, i) }) - bitOps[0x81 + (0x08 * i)] = Operation("RES $i,C", 0, 8, {r, _, _ -> r.C = reset(r.C, i) }) - bitOps[0x82 + (0x08 * i)] = Operation("RES $i,D", 0, 8, {r, _, _ -> r.D = reset(r.D, i) }) - bitOps[0x83 + (0x08 * i)] = Operation("RES $i,E", 0, 8, {r, _, _ -> r.E = reset(r.E, i) }) - bitOps[0x84 + (0x08 * i)] = Operation("RES $i,H", 0, 8, {r, _, _ -> r.H = reset(r.H, i) }) - bitOps[0x85 + (0x08 * i)] = Operation("RES $i,L", 0, 8, {r, _, _ -> r.L = reset(r.L, i) }) - bitOps[0x86 + (0x08 * i)] = Operation("RES $i,(HL)", 0, 16, {r, m, _ -> m.writeByte(r.HL, reset(m.readByte(r.HL), i)) }) + bitOps[0x47 + (0x08 * i)] = Operation("BIT $i,A", 0, 8) { r, _, _ -> bit(r.A, i, r) } + bitOps[0x40 + (0x08 * i)] = Operation("BIT $i,B", 0, 8) { r, _, _ -> bit(r.B, i, r) } + bitOps[0x41 + (0x08 * i)] = Operation("BIT $i,C", 0, 8) { r, _, _ -> bit(r.C, i, r) } + bitOps[0x42 + (0x08 * i)] = Operation("BIT $i,D", 0, 8) { r, _, _ -> bit(r.D, i, r) } + bitOps[0x43 + (0x08 * i)] = Operation("BIT $i,E", 0, 8) { r, _, _ -> bit(r.E, i, r) } + bitOps[0x44 + (0x08 * i)] = Operation("BIT $i,H", 0, 8) { r, _, _ -> bit(r.H, i, r) } + bitOps[0x45 + (0x08 * i)] = Operation("BIT $i,L", 0, 8) { r, _, _ -> bit(r.L, i, r) } + bitOps[0x46 + (0x08 * i)] = Operation("BIT $i,(HL)", 0, 16) { r, m, _ -> bit(m.readByte(r.HL), i, r) } + + bitOps[0xC7 + (0x08 * i)] = Operation("SET $i,A", 0, 8) { r, _, _ -> r.A = set(r.A, i) } + bitOps[0xC0 + (0x08 * i)] = Operation("SET $i,B", 0, 8) { r, _, _ -> r.B = set(r.B, i) } + bitOps[0xC1 + (0x08 * i)] = Operation("SET $i,C", 0, 8) { r, _, _ -> r.C = set(r.C, i) } + bitOps[0xC2 + (0x08 * i)] = Operation("SET $i,D", 0, 8) { r, _, _ -> r.D = set(r.D, i) } + bitOps[0xC3 + (0x08 * i)] = Operation("SET $i,E", 0, 8) { r, _, _ -> r.E = set(r.E, i) } + bitOps[0xC4 + (0x08 * i)] = Operation("SET $i,H", 0, 8) { r, _, _ -> r.H = set(r.H, i) } + bitOps[0xC5 + (0x08 * i)] = Operation("SET $i,L", 0, 8) { r, _, _ -> r.L = set(r.L, i) } + bitOps[0xC6 + (0x08 * i)] = Operation("SET $i,(HL)", 0, 16) { r, m, _ -> m.writeByte(r.HL, set(m.readByte(r.HL), i)) } + + bitOps[0x87 + (0x08 * i)] = Operation("RES $i,A", 0, 8) { r, _, _ -> r.A = reset(r.A, i) } + bitOps[0x80 + (0x08 * i)] = Operation("RES $i,B", 0, 8) { r, _, _ -> r.B = reset(r.B, i) } + bitOps[0x81 + (0x08 * i)] = Operation("RES $i,C", 0, 8) { r, _, _ -> r.C = reset(r.C, i) } + bitOps[0x82 + (0x08 * i)] = Operation("RES $i,D", 0, 8) { r, _, _ -> r.D = reset(r.D, i) } + bitOps[0x83 + (0x08 * i)] = Operation("RES $i,E", 0, 8) { r, _, _ -> r.E = reset(r.E, i) } + bitOps[0x84 + (0x08 * i)] = Operation("RES $i,H", 0, 8) { r, _, _ -> r.H = reset(r.H, i) } + bitOps[0x85 + (0x08 * i)] = Operation("RES $i,L", 0, 8) { r, _, _ -> r.L = reset(r.L, i) } + bitOps[0x86 + (0x08 * i)] = Operation("RES $i,(HL)", 0, 16) { r, m, _ -> m.writeByte(r.HL, reset(m.readByte(r.HL), i)) } } return bitOps.toMap() diff --git a/src/main/kotlin/cpu/opcodes/Calls.kt b/src/main/kotlin/cpu/opcodes/Calls.kt index 697b56c..70ce3f0 100644 --- a/src/main/kotlin/cpu/opcodes/Calls.kt +++ b/src/main/kotlin/cpu/opcodes/Calls.kt @@ -8,12 +8,12 @@ import BitManipulation as bm val calls = mapOf( - 0xCD to Operation("CALL nn", 2, 12, {r, m, a -> call(bm.argsToWord(a), r, m)}), + 0xCD to Operation("CALL nn", 2, 12) { r, m, a -> call(bm.argsToWord(a), r, m)}, - 0xC4 to Operation("CALL NZ,nn", 2, 12, {r, m, a -> if(r.getFlag(Flag.ZERO) == 0) call(bm.argsToWord(a), r, m)}), - 0xCC to Operation("CALL Z,nn", 2, 12, {r, m, a -> if(r.getFlag(Flag.ZERO) == 1) call(bm.argsToWord(a), r, m)}), - 0xD4 to Operation("CALL NC,nn", 2, 12, {r, m, a -> if(r.getFlag(Flag.CARRY) == 0) call(bm.argsToWord(a), r, m)}), - 0xDC to Operation("CALL C,nn", 2, 12, {r, m, a -> if(r.getFlag(Flag.CARRY) == 1) call(bm.argsToWord(a), r, m)}) + 0xC4 to Operation("CALL NZ,nn", 2, 12) { r, m, a -> if(r.getFlag(Flag.ZERO) == 0) call(bm.argsToWord(a), r, m)}, + 0xCC to Operation("CALL Z,nn", 2, 12) { r, m, a -> if(r.getFlag(Flag.ZERO) == 1) call(bm.argsToWord(a), r, m)}, + 0xD4 to Operation("CALL NC,nn", 2, 12) { r, m, a -> if(r.getFlag(Flag.CARRY) == 0) call(bm.argsToWord(a), r, m)}, + 0xDC to Operation("CALL C,nn", 2, 12) { r, m, a -> if(r.getFlag(Flag.CARRY) == 1) call(bm.argsToWord(a), r, m)} ) diff --git a/src/main/kotlin/cpu/opcodes/Jumps.kt b/src/main/kotlin/cpu/opcodes/Jumps.kt index 6e0ea3e..a1b81e4 100644 --- a/src/main/kotlin/cpu/opcodes/Jumps.kt +++ b/src/main/kotlin/cpu/opcodes/Jumps.kt @@ -6,17 +6,17 @@ import BitManipulation as bm val jumps = mapOf( - 0xC3 to Operation("JP nn", 2, 12, {r, _, a -> r.PC = bm.argsToWord(a)}), - 0xC2 to Operation("JP NZ,nn", 2, 12, {r, _, a -> if(r.getFlag(Flag.ZERO) == 0) r.PC = bm.argsToWord(a)}), - 0xCA to Operation("JP Z,nn", 2, 12, {r, _, a -> if(r.getFlag(Flag.ZERO) == 1) r.PC = bm.argsToWord(a)}), - 0xD2 to Operation("JP NC,nn", 2, 12, {r, _, a -> if(r.getFlag(Flag.CARRY) == 0) r.PC = bm.argsToWord(a)}), - 0xDA to Operation("JP C,nn", 2, 12, {r, _, a -> if(r.getFlag(Flag.CARRY) == 1) r.PC = bm.argsToWord(a)}), - 0xE9 to Operation("JP (HL)", 0, 4, {r, m, _ -> r.PC = m.readByte(r.HL)}), + 0xC3 to Operation("JP nn", 2, 12) { r, _, a -> r.PC = bm.argsToWord(a)}, + 0xC2 to Operation("JP NZ,nn", 2, 12) { r, _, a -> if(r.getFlag(Flag.ZERO) == 0) r.PC = bm.argsToWord(a)}, + 0xCA to Operation("JP Z,nn", 2, 12) { r, _, a -> if(r.getFlag(Flag.ZERO) == 1) r.PC = bm.argsToWord(a)}, + 0xD2 to Operation("JP NC,nn", 2, 12) { r, _, a -> if(r.getFlag(Flag.CARRY) == 0) r.PC = bm.argsToWord(a)}, + 0xDA to Operation("JP C,nn", 2, 12) { r, _, a -> if(r.getFlag(Flag.CARRY) == 1) r.PC = bm.argsToWord(a)}, + 0xE9 to Operation("JP (HL)", 0, 4) { r, m, _ -> r.PC = m.readByte(r.HL)}, - 0x18 to Operation("JR n", 1, 8, {r, _, a -> r.addSignedByteToPC(a[0])}), - 0x20 to Operation("JR NZ,n", 1, 8, {r, _, a -> if(r.getFlag(Flag.ZERO) == 0) r.addSignedByteToPC(a[0])}), - 0x28 to Operation("JR Z,n", 1, 8, {r, _, a -> if(r.getFlag(Flag.ZERO) == 1) r.addSignedByteToPC(a[0])}), - 0x30 to Operation("JR NC,n", 1, 8, {r, _, a -> if(r.getFlag(Flag.CARRY) == 0) r.addSignedByteToPC(a[0])}), - 0x38 to Operation("JR C,n", 1, 8, {r, _, a -> if(r.getFlag(Flag.CARRY) == 1) r.addSignedByteToPC(a[0])}) + 0x18 to Operation("JR n", 1, 8) { r, _, a -> r.addSignedByteToPC(a[0])}, + 0x20 to Operation("JR NZ,n", 1, 8) { r, _, a -> if(r.getFlag(Flag.ZERO) == 0) r.addSignedByteToPC(a[0])}, + 0x28 to Operation("JR Z,n", 1, 8) { r, _, a -> if(r.getFlag(Flag.ZERO) == 1) r.addSignedByteToPC(a[0])}, + 0x30 to Operation("JR NC,n", 1, 8) { r, _, a -> if(r.getFlag(Flag.CARRY) == 0) r.addSignedByteToPC(a[0])}, + 0x38 to Operation("JR C,n", 1, 8) { r, _, a -> if(r.getFlag(Flag.CARRY) == 1) r.addSignedByteToPC(a[0])} )
\ No newline at end of file diff --git a/src/main/kotlin/cpu/opcodes/Loads16Bit.kt b/src/main/kotlin/cpu/opcodes/Loads16Bit.kt index 2f679c3..73e5363 100644 --- a/src/main/kotlin/cpu/opcodes/Loads16Bit.kt +++ b/src/main/kotlin/cpu/opcodes/Loads16Bit.kt @@ -8,14 +8,14 @@ import BitManipulation as bm var loads16Bit = mapOf( - 0x01 to Operation("LD BC,nn", 2, 12, {r, _, a -> r.BC = bm.argsToWord(a)}), - 0x11 to Operation("LD DE,nn", 2, 12, {r, _, a -> r.DE = bm.argsToWord(a)}), - 0x21 to Operation("LD HL,nn", 2, 12, {r, _, a -> r.HL = bm.argsToWord(a)}), - 0x31 to Operation("LD SP,nn", 2, 12, {r, _, a -> r.SP = bm.argsToWord(a)}), + 0x01 to Operation("LD BC,nn", 2, 12) { r, _, a -> r.BC = bm.argsToWord(a)}, + 0x11 to Operation("LD DE,nn", 2, 12) { r, _, a -> r.DE = bm.argsToWord(a)}, + 0x21 to Operation("LD HL,nn", 2, 12) { r, _, a -> r.HL = bm.argsToWord(a)}, + 0x31 to Operation("LD SP,nn", 2, 12) { r, _, a -> r.SP = bm.argsToWord(a)}, - 0xF9 to Operation("LD SP,HL", 0, 8, {r, _, _ -> r.SP = r.HL}), + 0xF9 to Operation("LD SP,HL", 0, 8) { r, _, _ -> r.SP = r.HL}, - 0xF8 to Operation("LDHL SP,n", 1, 12, {r, _, a -> + 0xF8 to Operation("LDHL SP,n", 1, 12) { r, _, a -> // https://stackoverflow.com/questions/5159603/gbz80-how-does-ld-hl-spe-affect-h-and-c-flags // the carry flag is set if there's an overflow from the 7th to 8th bit. @@ -35,34 +35,34 @@ var loads16Bit = mapOf( r.HL = r.SP + absoluteValue } - }), - 0x08 to Operation("LD (nn),SP", 2, 20, {r, m, a -> + }, + 0x08 to Operation("LD (nn),SP", 2, 20) { r, m, a -> m.writeByte(bm.argsToWord(a), bm.getLsb(r.SP)) m.writeByte(bm.argsToWord(a) + 1, bm.getMsb(r.SP)) // TODO - not sure if the lsb/msb order is right here - }), + }, - 0xF5 to Operation("PUSH AF", 0, 16, {r, m, _ -> + 0xF5 to Operation("PUSH AF", 0, 16) { r, m, _ -> m.writeByte(r.decrementAndGetSP(), bm.getMsb(r.AF)) m.writeByte(r.decrementAndGetSP(), bm.getLsb(r.AF)) - }), - 0xC5 to Operation("PUSH BC", 0, 16, {r, m, _ -> + }, + 0xC5 to Operation("PUSH BC", 0, 16) { r, m, _ -> m.writeByte(r.decrementAndGetSP(), bm.getMsb(r.BC)) m.writeByte(r.decrementAndGetSP(), bm.getLsb(r.BC)) - }), - 0xD5 to Operation("PUSH DE", 0, 16, {r, m, _ -> + }, + 0xD5 to Operation("PUSH DE", 0, 16) { r, m, _ -> m.writeByte(r.decrementAndGetSP(), bm.getMsb(r.DE)) m.writeByte(r.decrementAndGetSP(), bm.getLsb(r.DE)) - }), - 0xE5 to Operation("PUSH HL", 0, 16, {r, m, _ -> + }, + 0xE5 to Operation("PUSH HL", 0, 16) { r, m, _ -> m.writeByte(r.decrementAndGetSP(), bm.getMsb(r.HL)) m.writeByte(r.decrementAndGetSP(), bm.getLsb(r.HL)) - }), + }, - 0xF1 to Operation("POP AF", 0, 12, {r, m, _ -> r.AF = pop(r, m)}), - 0xC1 to Operation("POP BC", 0, 12, {r, m, _ -> r.BC = pop(r, m)}), - 0xD1 to Operation("POP DE", 0, 12, {r, m, _ -> r.DE = pop(r, m)}), - 0xE1 to Operation("POP HL", 0, 12, {r, m, _ -> r.HL = pop(r, m)}) + 0xF1 to Operation("POP AF", 0, 12) { r, m, _ -> r.AF = pop(r, m)}, + 0xC1 to Operation("POP BC", 0, 12) { r, m, _ -> r.BC = pop(r, m)}, + 0xD1 to Operation("POP DE", 0, 12) { r, m, _ -> r.DE = pop(r, m)}, + 0xE1 to Operation("POP HL", 0, 12) { r, m, _ -> r.HL = pop(r, m)} ) diff --git a/src/main/kotlin/cpu/opcodes/Loads8Bit.kt b/src/main/kotlin/cpu/opcodes/Loads8Bit.kt index 99eb933..ced3303 100644 --- a/src/main/kotlin/cpu/opcodes/Loads8Bit.kt +++ b/src/main/kotlin/cpu/opcodes/Loads8Bit.kt @@ -6,106 +6,105 @@ import BitManipulation as bm // 8-Bit Loads var loads8Bit = mapOf( - 0x06 to Operation("LD B,n", 1, 8, {r, _, a -> r.B = a[0]}), - 0x0E to Operation("LD C,n", 1, 8, {r, _, a -> r.C = a[0]}), - 0x16 to Operation("LD D,n", 1, 8, {r, _, a -> r.D = a[0]}), - 0x1E to Operation("LD E,n", 1, 8, {r, _, a -> r.E = a[0]}), - 0x26 to Operation("LD H,n", 1, 8, {r, _, a -> r.H = a[0]}), - 0x2E to Operation("LD L,n", 1, 8, {r, _, a -> r.L = a[0]}), - - 0x78 to Operation("LD A,B", 0, 4, {r, _, _ -> r.A = r.B}), - 0x79 to Operation("LD A,C", 0, 4, {r, _, _ -> r.A = r.C}), - 0x7A to Operation("LD A,D", 0, 4, {r, _, _ -> r.A = r.D}), - 0x7B to Operation("LD A,E", 0, 4, {r, _, _ -> r.A = r.E}), - 0x7C to Operation("LD A,H", 0, 4, {r, _, _ -> r.A = r.H}), - 0x7D to Operation("LD A,L", 0, 4, {r, _, _ -> r.A = r.L}), - 0x0A to Operation("LD A,(BC)", 0, 8, {r, m, _ -> r.A = m.readByte(r.BC)}), - 0x1A to Operation("LD A,(DE)", 0, 8, {r, m, _ -> r.A = m.readByte(r.DE)}), - 0x7E to Operation("LD A,(HL)", 0, 8, {r, m, _ -> r.A = m.readByte(r.HL)}), - 0x3E to Operation("LD A, n", 1, 8, {r, _, a -> r.A = a[0]}), - 0xFA to Operation("LD A,(nn)", 2, 16, {r, m, a -> r.A = m.readByte(bm.argsToWord(a))}), - - 0x40 to Operation("LD B,B", 0, 4, {r, _, _ -> r.B = r.B}), - 0x41 to Operation("LD B,C", 0, 4, {r, _, _ -> r.B = r.C}), - 0x42 to Operation("LD B,D", 0, 4, {r, _, _ -> r.B = r.D}), - 0x43 to Operation("LD B,E", 0, 4, {r, _, _ -> r.B = r.E}), - 0x44 to Operation("LD B,H", 0, 4, {r, _, _ -> r.B = r.H}), - 0x45 to Operation("LD B,L", 0, 4, {r, _, _ -> r.B = r.L}), - 0x46 to Operation("LD B,(HL)", 0, 8, {r, m, _ -> r.B = m.readByte(r.HL)}), - - 0x48 to Operation("LD C,B", 0, 4, {r, _, _ -> r.C = r.B}), - 0x49 to Operation("LD C,C", 0, 4, {r, _, _ -> r.C = r.C}), - 0x4A to Operation("LD C,D", 0, 4, {r, _, _ -> r.C = r.D}), - 0x4B to Operation("LD C,E", 0, 4, {r, _, _ -> r.C = r.E}), - 0x4C to Operation("LD C,H", 0, 4, {r, _, _ -> r.C = r.H}), - 0x4D to Operation("LD C,L", 0, 4, {r, _, _ -> r.C = r.L}), - 0x4E to Operation("LD C,(HL)", 0, 8, {r, m, _ -> r.C = m.readByte(r.HL)}), - - 0x50 to Operation("LD D,B", 0, 4, {r, _, _ -> r.D = r.B}), - 0x51 to Operation("LD D,C", 0, 4, {r, _, _ -> r.D = r.C}), - 0x52 to Operation("LD D,D", 0, 4, {r, _, _ -> r.D = r.D}), - 0x53 to Operation("LD D,E", 0, 4, {r, _, _ -> r.D = r.E}), - 0x54 to Operation("LD D,H", 0, 4, {r, _, _ -> r.D = r.H}), - 0x55 to Operation("LD D,L", 0, 4, {r, _, _ -> r.D = r.L}), - 0x56 to Operation("LD D,(HL)", 0, 8, {r, m, _ -> r.D = m.readByte(r.HL)}), - - 0x58 to Operation("LD E,B", 0, 4, {r, _, _ -> r.E = r.B}), - 0x59 to Operation("LD E,C", 0, 4, {r, _, _ -> r.E = r.C}), - 0x5A to Operation("LD E,D", 0, 4, {r, _, _ -> r.E = r.D}), - 0x5B to Operation("LD E,E", 0, 4, {r, _, _ -> r.E = r.E}), - 0x5C to Operation("LD E,H", 0, 4, {r, _, _ -> r.E = r.H}), - 0x5D to Operation("LD E,L", 0, 4, {r, _, _ -> r.E = r.L}), - 0x5E to Operation("LD E,(HL)", 0, 8, {r, m, _ -> r.E = m.readByte(r.HL)}), - - 0x60 to Operation("LD H,B", 0, 4, {r, _, _ -> r.H = r.B}), - 0x61 to Operation("LD H,C", 0, 4, {r, _, _ -> r.H = r.C}), - 0x62 to Operation("LD H,D", 0, 4, {r, _, _ -> r.H = r.D}), - 0x63 to Operation("LD H,E", 0, 4, {r, _, _ -> r.H = r.E}), - 0x64 to Operation("LD H,H", 0, 4, {r, _, _ -> r.H = r.H}), - 0x65 to Operation("LD H,L", 0, 4, {r, _, _ -> r.H = r.L}), - 0x66 to Operation("LD H,(HL)", 0, 8, {r, m, _ -> r.H = m.readByte(r.HL)}), - - 0x68 to Operation("LD L,B", 0, 4, {r, _, _ -> r.L = r.B}), - 0x69 to Operation("LD L,C", 0, 4, {r, _, _ -> r.L = r.C}), - 0x6A to Operation("LD L,D", 0, 4, {r, _, _ -> r.L = r.D}), - 0x6B to Operation("LD L,E", 0, 4, {r, _, _ -> r.L = r.E}), - 0x6C to Operation("LD L,H", 0, 4, {r, _, _ -> r.L = r.H}), - 0x6D to Operation("LD L,L", 0, 4, {r, _, _ -> r.L = r.L}), - 0x6E to Operation("LD L,(HL)", 0, 8, {r, m, _ -> r.L = m.readByte(r.HL)}), - - 0x70 to Operation("LD (HL),B", 0, 8, {r, m, _ -> m.writeByte(r.HL, r.B)}), - 0x71 to Operation("LD (HL),C", 0, 8, {r, m, _ -> m.writeByte(r.HL, r.C)}), - 0x72 to Operation("LD (HL),D", 0, 8, {r, m, _ -> m.writeByte(r.HL, r.D)}), - 0x73 to Operation("LD (HL),E", 0, 8, {r, m, _ -> m.writeByte(r.HL, r.E)}), - 0x74 to Operation("LD (HL),H", 0, 8, {r, m, _ -> m.writeByte(r.HL, r.H)}), - 0x75 to Operation("LD (HL),L", 0, 8, {r, m, _ -> m.writeByte(r.HL, r.L)}), + 0x06 to Operation("LD B,n", 1, 8) { r, _, a -> r.B = a[0]}, + 0x0E to Operation("LD C,n", 1, 8) { r, _, a -> r.C = a[0]}, + 0x16 to Operation("LD D,n", 1, 8) { r, _, a -> r.D = a[0]}, + 0x1E to Operation("LD E,n", 1, 8) { r, _, a -> r.E = a[0]}, + 0x26 to Operation("LD H,n", 1, 8) { r, _, a -> r.H = a[0]}, + 0x2E to Operation("LD L,n", 1, 8) { r, _, a -> r.L = a[0]}, + + 0x78 to Operation("LD A,B", 0, 4) { r, _, _ -> r.A = r.B}, + 0x79 to Operation("LD A,C", 0, 4) { r, _, _ -> r.A = r.C}, + 0x7A to Operation("LD A,D", 0, 4) { r, _, _ -> r.A = r.D}, + 0x7B to Operation("LD A,E", 0, 4) { r, _, _ -> r.A = r.E}, + 0x7C to Operation("LD A,H", 0, 4) { r, _, _ -> r.A = r.H}, + 0x7D to Operation("LD A,L", 0, 4) { r, _, _ -> r.A = r.L}, + 0x0A to Operation("LD A,(BC)", 0, 8) { r, m, _ -> r.A = m.readByte(r.BC)}, + 0x1A to Operation("LD A,(DE)", 0, 8) { r, m, _ -> r.A = m.readByte(r.DE)}, + 0x7E to Operation("LD A,(HL)", 0, 8) { r, m, _ -> r.A = m.readByte(r.HL)}, + 0x3E to Operation("LD A, n", 1, 8) { r, _, a -> r.A = a[0]}, + 0xFA to Operation("LD A,(nn)", 2, 16) { r, m, a -> r.A = m.readByte(bm.argsToWord(a))}, + + 0x40 to Operation("LD B,B", 0, 4) { r, _, _ -> r.B = r.B}, + 0x41 to Operation("LD B,C", 0, 4) { r, _, _ -> r.B = r.C}, + 0x42 to Operation("LD B,D", 0, 4) { r, _, _ -> r.B = r.D}, + 0x43 to Operation("LD B,E", 0, 4) { r, _, _ -> r.B = r.E}, + 0x44 to Operation("LD B,H", 0, 4) { r, _, _ -> r.B = r.H}, + 0x45 to Operation("LD B,L", 0, 4) { r, _, _ -> r.B = r.L}, + 0x46 to Operation("LD B,(HL)", 0, 8) { r, m, _ -> r.B = m.readByte(r.HL)}, + + 0x48 to Operation("LD C,B", 0, 4) { r, _, _ -> r.C = r.B}, + 0x49 to Operation("LD C,C", 0, 4) { r, _, _ -> r.C = r.C}, + 0x4A to Operation("LD C,D", 0, 4) { r, _, _ -> r.C = r.D}, + 0x4B to Operation("LD C,E", 0, 4) { r, _, _ -> r.C = r.E}, + 0x4C to Operation("LD C,H", 0, 4) { r, _, _ -> r.C = r.H}, + 0x4D to Operation("LD C,L", 0, 4) { r, _, _ -> r.C = r.L}, + 0x4E to Operation("LD C,(HL)", 0, 8) { r, m, _ -> r.C = m.readByte(r.HL)}, + + 0x50 to Operation("LD D,B", 0, 4) { r, _, _ -> r.D = r.B}, + 0x51 to Operation("LD D,C", 0, 4) { r, _, _ -> r.D = r.C}, + 0x52 to Operation("LD D,D", 0, 4) { r, _, _ -> r.D = r.D}, + 0x53 to Operation("LD D,E", 0, 4) { r, _, _ -> r.D = r.E}, + 0x54 to Operation("LD D,H", 0, 4) { r, _, _ -> r.D = r.H}, + 0x55 to Operation("LD D,L", 0, 4) { r, _, _ -> r.D = r.L}, + 0x56 to Operation("LD D,(HL)", 0, 8) { r, m, _ -> r.D = m.readByte(r.HL)}, + + 0x58 to Operation("LD E,B", 0, 4) { r, _, _ -> r.E = r.B}, + 0x59 to Operation("LD E,C", 0, 4) { r, _, _ -> r.E = r.C}, + 0x5A to Operation("LD E,D", 0, 4) { r, _, _ -> r.E = r.D}, + 0x5B to Operation("LD E,E", 0, 4) { r, _, _ -> r.E = r.E}, + 0x5C to Operation("LD E,H", 0, 4) { r, _, _ -> r.E = r.H}, + 0x5D to Operation("LD E,L", 0, 4) { r, _, _ -> r.E = r.L}, + 0x5E to Operation("LD E,(HL)", 0, 8) { r, m, _ -> r.E = m.readByte(r.HL)}, + + 0x60 to Operation("LD H,B", 0, 4) { r, _, _ -> r.H = r.B}, + 0x61 to Operation("LD H,C", 0, 4) { r, _, _ -> r.H = r.C}, + 0x62 to Operation("LD H,D", 0, 4) { r, _, _ -> r.H = r.D}, + 0x63 to Operation("LD H,E", 0, 4) { r, _, _ -> r.H = r.E}, + 0x64 to Operation("LD H,H", 0, 4) { r, _, _ -> r.H = r.H}, + 0x65 to Operation("LD H,L", 0, 4) { r, _, _ -> r.H = r.L}, + 0x66 to Operation("LD H,(HL)", 0, 8) { r, m, _ -> r.H = m.readByte(r.HL)}, + + 0x68 to Operation("LD L,B", 0, 4) { r, _, _ -> r.L = r.B}, + 0x69 to Operation("LD L,C", 0, 4) { r, _, _ -> r.L = r.C}, + 0x6A to Operation("LD L,D", 0, 4) { r, _, _ -> r.L = r.D}, + 0x6B to Operation("LD L,E", 0, 4) { r, _, _ -> r.L = r.E}, + 0x6C to Operation("LD L,H", 0, 4) { r, _, _ -> r.L = r.H}, + 0x6D to Operation("LD L,L", 0, 4) { r, _, _ -> r.L = r.L}, + 0x6E to Operation("LD L,(HL)", 0, 8) { r, m, _ -> r.L = m.readByte(r.HL)}, + + 0x70 to Operation("LD (HL),B", 0, 8) { r, m, _ -> m.writeByte(r.HL, r.B)}, + 0x71 to Operation("LD (HL),C", 0, 8) { r, m, _ -> m.writeByte(r.HL, r.C)}, + 0x72 to Operation("LD (HL),D", 0, 8) { r, m, _ -> m.writeByte(r.HL, r.D)}, + 0x73 to Operation("LD (HL),E", 0, 8) { r, m, _ -> m.writeByte(r.HL, r.E)}, + 0x74 to Operation("LD (HL),H", 0, 8) { r, m, _ -> m.writeByte(r.HL, r.H)}, + 0x75 to Operation("LD (HL),L", 0, 8) { r, m, _ -> m.writeByte(r.HL, r.L)}, // 36 is not a typo - 0x36 to Operation("LD (HL),n", 1, 12, {r, m, a -> m.writeByte(r.HL, a[0])}), - - 0x7F to Operation("LD A,A", 0, 4, {r, _, _ -> r.A = r.A}), - 0x47 to Operation("LD B,A", 0, 4, {r, _, _ -> r.B = r.A}), - 0x4F to Operation("LD C,A", 0, 4, {r, _, _ -> r.C = r.A}), - 0x57 to Operation("LD D,A", 0, 4, {r, _, _ -> r.D = r.A}), - 0x5F to Operation("LD E,A", 0, 4, {r, _, _ -> r.E = r.A}), - 0x67 to Operation("LD H,A", 0, 4, {r, _, _ -> r.H = r.A}), - 0x6F to Operation("LD L,A", 0, 4, {r, _, _ -> r.L = r.A}), - 0x02 to Operation("LD (BC),A", 0, 8, {r, m, _ -> m.writeByte(r.BC, r.A)}), |