|
|
@ -22,7 +22,7 @@ class LD_R_R(Insn): |
|
|
|
|
|
|
|
def exec(self, cpu: CPU) -> None: |
|
|
|
cpu.set_reg8(self.dst, cpu.get_reg8(self.src)) |
|
|
|
cpu.cycles += 4 |
|
|
|
cpu.state.cycles += 4 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return f"LD {self.dst.value}, {self.src.value}" |
|
|
@ -35,7 +35,7 @@ class LD_R_N8(Insn): |
|
|
|
|
|
|
|
def exec(self, cpu: CPU) -> None: |
|
|
|
cpu.set_reg8(self.dst, self.imm) |
|
|
|
cpu.cycles += 8 |
|
|
|
cpu.state.cycles += 8 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return f"LD {self.dst.value}, {hex(self.imm)}" |
|
|
@ -47,7 +47,7 @@ class LD_R_HL(Insn): |
|
|
|
|
|
|
|
def exec(self, cpu: CPU) -> None: |
|
|
|
cpu.set_reg8(self.dst, cpu.get_mem8(cpu.get_reg16(R16.HL))) |
|
|
|
cpu.cycles += 8 |
|
|
|
cpu.state.cycles += 8 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return f"LD {self.dst.value}, (HL)" |
|
|
@ -59,7 +59,7 @@ class LD_HL_R(Insn): |
|
|
|
|
|
|
|
def exec(self, cpu: CPU) -> None: |
|
|
|
cpu.deref_hl_set(cpu.get_reg8(self.src)) |
|
|
|
cpu.cycles += 8 |
|
|
|
cpu.state.cycles += 8 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return f"LD (HL), {self.src.value}" |
|
|
@ -71,7 +71,7 @@ class LD_HL_N(Insn): |
|
|
|
|
|
|
|
def exec(self, cpu: CPU) -> None: |
|
|
|
cpu.set_mem8(cpu.get_reg16(R16.HL), self.imm) |
|
|
|
cpu.cycles += 12 |
|
|
|
cpu.state.cycles += 12 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return f"LD (HL), {hex(self.imm & 0xff)}" |
|
|
@ -81,7 +81,7 @@ class LD_HL_N(Insn): |
|
|
|
class LD_A_BC(Insn): |
|
|
|
def exec(self, cpu: CPU) -> None: |
|
|
|
cpu.set_reg8(R8.A, cpu.get_mem8(cpu.get_reg16(R16.BC))) |
|
|
|
cpu.cycles += 8 |
|
|
|
cpu.state.cycles += 8 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return "LD A, (BC)" |
|
|
@ -91,7 +91,7 @@ class LD_A_BC(Insn): |
|
|
|
class LD_A_DE(Insn): |
|
|
|
def exec(self, cpu: CPU) -> None: |
|
|
|
cpu.set_reg8(R8.A, cpu.get_mem8(cpu.get_reg16(R16.DE))) |
|
|
|
cpu.cycles += 8 |
|
|
|
cpu.state.cycles += 8 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return "LD A, (DE)" |
|
|
@ -103,7 +103,7 @@ class LD_A_NN(Insn): |
|
|
|
|
|
|
|
def exec(self, cpu: CPU) -> None: |
|
|
|
cpu.set_reg8(R8.A, cpu.get_mem8(self.nn)) |
|
|
|
cpu.cycles += 16 |
|
|
|
cpu.state.cycles += 16 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return f"LD A, ({hex(self.nn)})" |
|
|
@ -113,7 +113,7 @@ class LD_A_NN(Insn): |
|
|
|
class LD_BC_A(Insn): |
|
|
|
def exec(self, cpu: CPU) -> None: |
|
|
|
cpu.set_mem8(cpu.get_reg16(R16.BC), cpu.get_reg8(R8.A)) |
|
|
|
cpu.cycles += 8 |
|
|
|
cpu.state.cycles += 8 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return "LD (BC), A" |
|
|
@ -123,7 +123,7 @@ class LD_BC_A(Insn): |
|
|
|
class LD_DE_A(Insn): |
|
|
|
def exec(self, cpu: CPU) -> None: |
|
|
|
cpu.set_mem8(cpu.get_reg16(R16.DE), cpu.get_reg8(R8.A)) |
|
|
|
cpu.cycles += 8 |
|
|
|
cpu.state.cycles += 8 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return "LD (DE), A" |
|
|
@ -135,7 +135,7 @@ class LD_NN_A(Insn): |
|
|
|
|
|
|
|
def exec(self, cpu: CPU) -> None: |
|
|
|
cpu.set_mem8(self.nn, cpu.get_reg8(R8.A)) |
|
|
|
cpu.cycles += 16 |
|
|
|
cpu.state.cycles += 16 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return f"LD ({hex(self.nn)}), A" |
|
|
@ -147,7 +147,7 @@ class LD_A_FF_N(Insn): |
|
|
|
|
|
|
|
def exec(self, cpu: CPU) -> None: |
|
|
|
cpu.set_reg8(R8.A, cpu.get_mem8(0xFF00 + self.n)) |
|
|
|
cpu.cycles += 12 |
|
|
|
cpu.state.cycles += 12 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return f"LD A, (0xFF00 + {hex(self.n)})" |
|
|
@ -159,7 +159,7 @@ class LD_FF_N_A(Insn): |
|
|
|
|
|
|
|
def exec(self, cpu: CPU) -> None: |
|
|
|
cpu.set_mem8(0xFF00 + self.n, cpu.get_reg8(R8.A)) |
|
|
|
cpu.cycles += 12 |
|
|
|
cpu.state.cycles += 12 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return f"LD (0xFF00 + {hex(self.n)}), A" |
|
|
@ -169,7 +169,7 @@ class LD_FF_N_A(Insn): |
|
|
|
class LD_A_FF_C(Insn): |
|
|
|
def exec(self, cpu: CPU) -> None: |
|
|
|
cpu.set_reg8(R8.A, cpu.get_mem8(0xFF00 + cpu.get_reg8(R8.C))) |
|
|
|
cpu.cycles += 8 |
|
|
|
cpu.state.cycles += 8 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return "LD A, (0xFF00 + C)" |
|
|
@ -179,7 +179,7 @@ class LD_A_FF_C(Insn): |
|
|
|
class LD_FF_C_A(Insn): |
|
|
|
def exec(self, cpu: CPU) -> None: |
|
|
|
cpu.set_mem8(0xFF00 + cpu.get_reg8(R8.C), cpu.get_reg8(R8.A)) |
|
|
|
cpu.cycles += 8 |
|
|
|
cpu.state.cycles += 8 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return "LD (0xFF00 + C), A" |
|
|
@ -191,7 +191,7 @@ class LDI_HL_A(Insn): |
|
|
|
hl = cpu.get_reg16(R16.HL) |
|
|
|
cpu.set_mem8(hl, cpu.get_reg8(R8.A)) |
|
|
|
cpu.set_reg16(R16.HL, hl + 1) |
|
|
|
cpu.cycles += 8 |
|
|
|
cpu.state.cycles += 8 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return "LDI (HL), A" |
|
|
@ -203,7 +203,7 @@ class LDI_A_HL(Insn): |
|
|
|
hl = cpu.get_reg16(R16.HL) |
|
|
|
cpu.set_reg8(R8.A, cpu.get_mem8(hl)) |
|
|
|
cpu.set_reg16(R16.HL, hl + 1) |
|
|
|
cpu.cycles += 8 |
|
|
|
cpu.state.cycles += 8 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return "LDI A, (HL)" |
|
|
@ -215,7 +215,7 @@ class LDD_HL_A(Insn): |
|
|
|
hl = cpu.get_reg16(R16.HL) |
|
|
|
cpu.set_mem8(hl, cpu.get_reg8(R8.A)) |
|
|
|
cpu.set_reg16(R16.HL, hl - 1) |
|
|
|
cpu.cycles += 8 |
|
|
|
cpu.state.cycles += 8 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return "LDD (HL), A" |
|
|
@ -227,7 +227,7 @@ class LDD_A_HL(Insn): |
|
|
|
hl = cpu.get_reg16(R16.HL) |
|
|
|
cpu.set_reg8(R8.A, cpu.get_mem8(hl)) |
|
|
|
cpu.set_reg16(R16.HL, hl - 1) |
|
|
|
cpu.cycles += 8 |
|
|
|
cpu.state.cycles += 8 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return "LDD A, (HL)" |
|
|
@ -240,7 +240,7 @@ class LD_RR_NN(Insn): |
|
|
|
|
|
|
|
def exec(self, cpu: CPU) -> None: |
|
|
|
cpu.set_reg16(self.rr, self.nn) |
|
|
|
cpu.cycles += 12 |
|
|
|
cpu.state.cycles += 12 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return f"LD {self.rr.value}, {hex(self.nn)}" |
|
|
@ -252,7 +252,7 @@ class LD_NN_SP(Insn): |
|
|
|
|
|
|
|
def exec(self, cpu: CPU) -> None: |
|
|
|
cpu.set_mem16(self.nn, cpu.get_reg16(R16.SP)) |
|
|
|
cpu.cycles += 20 |
|
|
|
cpu.state.cycles += 20 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return f"LD ({hex(self.nn)}), SP" |
|
|
@ -262,7 +262,7 @@ class LD_NN_SP(Insn): |
|
|
|
class LD_SP_HL(Insn): |
|
|
|
def exec(self, cpu: CPU) -> None: |
|
|
|
cpu.set_reg16(R16.SP, cpu.get_reg16(R16.HL)) |
|
|
|
cpu.cycles += 8 |
|
|
|
cpu.state.cycles += 8 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return "LD SP, HL" |
|
|
@ -278,7 +278,7 @@ class PUSH_RR(Insn): |
|
|
|
sp = cpu.get_reg16(R16.SP) - 2 |
|
|
|
cpu.set_reg16(R16.SP, sp) |
|
|
|
cpu.set_mem16(sp, cpu.get_reg16(self.rr)) |
|
|
|
cpu.cycles += 16 |
|
|
|
cpu.state.cycles += 16 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return f"PUSH {self.rr.value}" |
|
|
@ -292,7 +292,7 @@ class POP_RR(Insn): |
|
|
|
sp = cpu.get_reg16(R16.SP) |
|
|
|
cpu.set_reg16(self.rr, cpu.get_mem16(sp)) |
|
|
|
cpu.set_reg16(R16.SP, sp + 2) |
|
|
|
cpu.cycles += 12 |
|
|
|
cpu.state.cycles += 12 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return f"POP {self.rr.value}" |
|
|
@ -304,9 +304,9 @@ class ADD_A_R(Insn): |
|
|
|
|
|
|
|
def exec(self, cpu: CPU) -> None: |
|
|
|
a = cpu.get_reg8(R8.A) + cpu.get_reg8(self.r) |
|
|
|
cpu.carry = 1 if a > 0xFF else 0 |
|
|
|
cpu.state.carry = 1 if a > 0xFF else 0 |
|
|
|
cpu.set_reg8(R8.A, a) |
|
|
|
cpu.cycles += 4 |
|
|
|
cpu.state.cycles += 4 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return f"ADD A, {self.r.value}" |
|
|
@ -318,9 +318,9 @@ class ADD_A_N(Insn): |
|
|
|
|
|
|
|
def exec(self, cpu: CPU) -> None: |
|
|
|
a = cpu.get_reg8(R8.A) + self.n |
|
|
|
cpu.carry = 1 if a > 0xFF else 0 |
|
|
|
cpu.state.carry = 1 if a > 0xFF else 0 |
|
|
|
cpu.set_reg8(R8.A, a) |
|
|
|
cpu.cycles += 8 |
|
|
|
cpu.state.cycles += 8 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return f"ADD A, {hex(self.n)}" |
|
|
@ -330,9 +330,9 @@ class ADD_A_N(Insn): |
|
|
|
class ADD_A_HL(Insn): |
|
|
|
def exec(self, cpu: CPU) -> None: |
|
|
|
a = cpu.get_reg8(R8.A) + cpu.get_mem8(cpu.get_reg16(R16.HL)) |
|
|
|
cpu.carry = 1 if a > 0xFF else 0 |
|
|
|
cpu.state.carry = 1 if a > 0xFF else 0 |
|
|
|
cpu.set_reg8(R8.A, a) |
|
|
|
cpu.cycles += 8 |
|
|
|
cpu.state.cycles += 8 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return f"ADD A, (HL)" |
|
|
@ -343,10 +343,10 @@ class ADC_A_R(Insn): |
|
|
|
r: R8 |
|
|
|
|
|
|
|
def exec(self, cpu: CPU) -> None: |
|
|
|
a = cpu.get_reg8(R8.A) + cpu.get_reg8(self.r) + cpu.carry |
|
|
|
cpu.carry = 1 if a > 0xFF else 0 |
|
|
|
a = cpu.get_reg8(R8.A) + cpu.get_reg8(self.r) + cpu.state.carry |
|
|
|
cpu.state.carry = 1 if a > 0xFF else 0 |
|
|
|
cpu.set_reg8(R8.A, a) |
|
|
|
cpu.cycles += 4 |
|
|
|
cpu.state.cycles += 4 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return f"ADC A, {self.r.value}" |
|
|
@ -357,10 +357,10 @@ class ADC_A_N(Insn): |
|
|
|
n: int |
|
|
|
|
|
|
|
def exec(self, cpu: CPU) -> None: |
|
|
|
a = cpu.get_reg8(R8.A) + self.n + cpu.carry |
|
|
|
cpu.carry = 1 if a > 0xFF else 0 |
|
|
|
a = cpu.get_reg8(R8.A) + self.n + cpu.state.carry |
|
|
|
cpu.state.carry = 1 if a > 0xFF else 0 |
|
|
|
cpu.set_reg8(R8.A, a) |
|
|
|
cpu.cycles += 8 |
|
|
|
cpu.state.cycles += 8 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return f"ADC A, {hex(self.n)}" |
|
|
@ -369,10 +369,10 @@ class ADC_A_N(Insn): |
|
|
|
@dataclass |
|
|
|
class ADC_A_HL(Insn): |
|
|
|
def exec(self, cpu: CPU) -> None: |
|
|
|
a = cpu.get_reg8(R8.A) + cpu.get_mem8(cpu.get_reg16(R16.HL)) + cpu.carry |
|
|
|
cpu.carry = 1 if a > 0xFF else 0 |
|
|
|
a = cpu.get_reg8(R8.A) + cpu.get_mem8(cpu.get_reg16(R16.HL)) + cpu.state.carry |
|
|
|
cpu.state.carry = 1 if a > 0xFF else 0 |
|
|
|
cpu.set_reg8(R8.A, a) |
|
|
|
cpu.cycles += 8 |
|
|
|
cpu.state.cycles += 8 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return f"ADC A, (HL)" |
|
|
@ -384,9 +384,9 @@ class SUB_A_R(Insn): |
|
|
|
|
|
|
|
def exec(self, cpu: CPU) -> None: |
|
|
|
a = cpu.get_reg8(R8.A) - cpu.get_reg8(self.r) |
|
|
|
cpu.carry = 1 if a < 0 else 0 |
|
|
|
cpu.state.carry = 1 if a < 0 else 0 |
|
|
|
cpu.set_reg8(R8.A, a) |
|
|
|
cpu.cycles += 4 |
|
|
|
cpu.state.cycles += 4 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return f"SUB A, {self.r.value}" |
|
|
@ -398,9 +398,9 @@ class SUB_A_N(Insn): |
|
|
|
|
|
|
|
def exec(self, cpu: CPU) -> None: |
|
|
|
a = cpu.get_reg8(R8.A) - self.n |
|
|
|
cpu.carry = 1 if a < 0 else 0 |
|
|
|
cpu.state.carry = 1 if a < 0 else 0 |
|
|
|
cpu.set_reg8(R8.A, a) |
|
|
|
cpu.cycles += 8 |
|
|
|
cpu.state.cycles += 8 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return f"SUB A, {hex(self.n)}" |
|
|
@ -410,9 +410,9 @@ class SUB_A_N(Insn): |
|
|
|
class SUB_A_HL(Insn): |
|
|
|
def exec(self, cpu: CPU) -> None: |
|
|
|
a = cpu.get_reg8(R8.A) - cpu.get_mem8(cpu.get_reg16(R16.HL)) |
|
|
|
cpu.carry = 1 if a < 0 else 0 |
|
|
|
cpu.state.carry = 1 if a < 0 else 0 |
|
|
|
cpu.set_reg8(R8.A, a) |
|
|
|
cpu.cycles += 8 |
|
|
|
cpu.state.cycles += 8 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return "SUB A, (HL)" |
|
|
@ -423,10 +423,10 @@ class SBC_A_R(Insn): |
|
|
|
r: R8 |
|
|
|
|
|
|
|
def exec(self, cpu: CPU) -> None: |
|
|
|
a = cpu.get_reg8(R8.A) - cpu.get_reg8(self.r) - cpu.carry |
|
|
|
cpu.carry = 1 if a < 0 else 0 |
|
|
|
a = cpu.get_reg8(R8.A) - cpu.get_reg8(self.r) - cpu.state.carry |
|
|
|
cpu.state.carry = 1 if a < 0 else 0 |
|
|
|
cpu.set_reg8(R8.A, a) |
|
|
|
cpu.cycles += 4 |
|
|
|
cpu.state.cycles += 4 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return f"SBC A, {self.r.value}" |
|
|
@ -437,10 +437,10 @@ class SBC_A_N(Insn): |
|
|
|
n: int |
|
|
|
|
|
|
|
def exec(self, cpu: CPU) -> None: |
|
|
|
a = cpu.get_reg8(R8.A) - self.n - cpu.carry |
|
|
|
cpu.carry = 1 if a < 0 else 0 |
|
|
|
a = cpu.get_reg8(R8.A) - self.n - cpu.state.carry |
|
|
|
cpu.state.carry = 1 if a < 0 else 0 |
|
|
|
cpu.set_reg8(R8.A, a) |
|
|
|
cpu.cycles += 8 |
|
|
|
cpu.state.cycles += 8 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return f"SBC A, {hex(self.n)}" |
|
|
@ -449,10 +449,10 @@ class SBC_A_N(Insn): |
|
|
|
@dataclass |
|
|
|
class SBC_A_HL(Insn): |
|
|
|
def exec(self, cpu: CPU) -> None: |
|
|
|
a = cpu.get_reg8(R8.A) - cpu.get_mem8(cpu.get_reg16(R16.HL)) - cpu.carry |
|
|
|
cpu.carry = 1 if a < 0 else 0 |
|
|
|
a = cpu.get_reg8(R8.A) - cpu.get_mem8(cpu.get_reg16(R16.HL)) - cpu.state.carry |
|
|
|
cpu.state.carry = 1 if a < 0 else 0 |
|
|
|
cpu.set_reg8(R8.A, a) |
|
|
|
cpu.cycles += 8 |
|
|
|
cpu.state.cycles += 8 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return "SBC A, (HL)" |
|
|
@ -465,8 +465,8 @@ class AND_A_R(Insn): |
|
|
|
def exec(self, cpu: CPU) -> None: |
|
|
|
a = cpu.get_reg8(R8.A) & cpu.get_reg8(self.r) |
|
|
|
cpu.set_reg8(R8.A, a) |
|
|
|
cpu.carry = 0 |
|
|
|
cpu.cycles += 4 |
|
|
|
cpu.state.carry = 0 |
|
|
|
cpu.state.cycles += 4 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return f"AND A, {self.r.value}" |
|
|
@ -479,8 +479,8 @@ class AND_A_N(Insn): |
|
|
|
def exec(self, cpu: CPU) -> None: |
|
|
|
a = cpu.get_reg8(R8.A) & self.n |
|
|
|
cpu.set_reg8(R8.A, a) |
|
|
|
cpu.carry = 0 |
|
|
|
cpu.cycles += 8 |
|
|
|
cpu.state.carry = 0 |
|
|
|
cpu.state.cycles += 8 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return f"AND A, {hex(self.n)}" |
|
|
@ -491,8 +491,8 @@ class AND_A_HL(Insn): |
|
|
|
def exec(self, cpu: CPU) -> None: |
|
|
|
a = cpu.get_reg8(R8.A) & cpu.get_mem8(cpu.get_reg16(R16.HL)) |
|
|
|
cpu.set_reg8(R8.A, a) |
|
|
|
cpu.carry = 0 |
|
|
|
cpu.cycles += 8 |
|
|
|
cpu.state.carry = 0 |
|
|
|
cpu.state.cycles += 8 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return "AND A, (HL)" |
|
|
@ -505,8 +505,8 @@ class XOR_A_R(Insn): |
|
|
|
def exec(self, cpu: CPU) -> None: |
|
|
|
a = cpu.get_reg8(R8.A) ^ cpu.get_reg8(self.r) |
|
|
|
cpu.set_reg8(R8.A, a) |
|
|
|
cpu.carry = 0 |
|
|
|
cpu.cycles += 4 |
|
|
|
cpu.state.carry = 0 |
|
|
|
cpu.state.cycles += 4 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return f"XOR A, {self.r.value}" |
|
|
@ -519,8 +519,8 @@ class XOR_A_N(Insn): |
|
|
|
def exec(self, cpu: CPU) -> None: |
|
|
|
a = cpu.get_reg8(R8.A) ^ self.n |
|
|
|
cpu.set_reg8(R8.A, a) |
|
|
|
cpu.carry = 0 |
|
|
|
cpu.cycles += 8 |
|
|
|
cpu.state.carry = 0 |
|
|
|
cpu.state.cycles += 8 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return f"XOR A, {hex(self.n)}" |
|
|
@ -531,8 +531,8 @@ class XOR_A_HL(Insn): |
|
|
|
def exec(self, cpu: CPU) -> None: |
|
|
|
a = cpu.get_reg8(R8.A) ^ cpu.get_mem8(cpu.get_reg16(R16.HL)) |
|
|
|
cpu.set_reg8(R8.A, a) |
|
|
|
cpu.carry = 0 |
|
|
|
cpu.cycles += 8 |
|
|
|
cpu.state.carry = 0 |
|
|
|
cpu.state.cycles += 8 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return "XOR A, (HL)" |
|
|
@ -545,8 +545,8 @@ class OR_A_R(Insn): |
|
|
|
def exec(self, cpu: CPU) -> None: |
|
|
|
a = cpu.get_reg8(R8.A) | cpu.get_reg8(self.r) |
|
|
|
cpu.set_reg8(R8.A, a) |
|
|
|
cpu.carry = 0 |
|
|
|
cpu.cycles += 4 |
|
|
|
cpu.state.carry = 0 |
|
|
|
cpu.state.cycles += 4 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return f"OR A, {self.r.value}" |
|
|
@ -559,8 +559,8 @@ class OR_A_N(Insn): |
|
|
|
def exec(self, cpu: CPU) -> None: |
|
|
|
a = cpu.get_reg8(R8.A) | self.n |
|
|
|
cpu.set_reg8(R8.A, a) |
|
|
|
cpu.carry = 0 |
|
|
|
cpu.cycles += 8 |
|
|
|
cpu.state.carry = 0 |
|
|
|
cpu.state.cycles += 8 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return f"OR A, {hex(self.n)}" |
|
|
@ -571,8 +571,8 @@ class OR_A_HL(Insn): |
|
|
|
def exec(self, cpu: CPU) -> None: |
|
|
|
a = cpu.get_reg8(R8.A) | cpu.get_mem8(cpu.get_reg16(R16.HL)) |
|
|
|
cpu.set_reg8(R8.A, a) |
|
|
|
cpu.carry = 0 |
|
|
|
cpu.cycles += 8 |
|
|
|
cpu.state.carry = 0 |
|
|
|
cpu.state.cycles += 8 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return "OR A, (HL)" |
|
|
@ -583,8 +583,8 @@ class CP_A_R(Insn): |
|
|
|
r: R8 |
|
|
|
|
|
|
|
def exec(self, cpu: CPU) -> None: |
|
|
|
cpu.carry = 1 if cpu.get_reg8(R8.A) < cpu.get_reg8(self.r) else 0 |
|
|
|
cpu.cycles += 4 |
|
|
|
cpu.state.carry = 1 if cpu.get_reg8(R8.A) < cpu.get_reg8(self.r) else 0 |
|
|
|
cpu.state.cycles += 4 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return f"CP A, {self.r.value}" |
|
|
@ -595,8 +595,8 @@ class CP_A_N(Insn): |
|
|
|
n: int |
|
|
|
|
|
|
|
def exec(self, cpu: CPU) -> None: |
|
|
|
cpu.carry = 1 if cpu.get_reg8(R8.A) < self.n else 0 |
|
|
|
cpu.cycles += 8 |
|
|
|
cpu.state.carry = 1 if cpu.get_reg8(R8.A) < self.n else 0 |
|
|
|
cpu.state.cycles += 8 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return f"CP A, {hex(self.n)}" |
|
|
@ -605,8 +605,10 @@ class CP_A_N(Insn): |
|
|
|
@dataclass |
|
|
|
class CP_A_HL(Insn): |
|
|
|
def exec(self, cpu: CPU) -> None: |
|
|
|
cpu.carry = 1 if cpu.get_reg8(R8.A) < cpu.get_mem8(cpu.get_reg16(R16.HL)) else 0 |
|
|
|
cpu.cycles += 8 |
|
|
|
cpu.state.carry = ( |
|
|
|
1 if cpu.get_reg8(R8.A) < cpu.get_mem8(cpu.get_reg16(R16.HL)) else 0 |
|
|
|
) |
|
|
|
cpu.state.cycles += 8 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return "CP A, (HL)" |
|
|
@ -618,7 +620,7 @@ class INC_R(Insn): |
|
|
|
|
|
|
|
def exec(self, cpu: CPU) -> None: |
|
|
|
cpu.set_reg8(self.r, cpu.get_reg8(self.r) + 1) |
|
|
|
cpu.cycles += 4 |
|
|
|
cpu.state.cycles += 4 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return f"INC {self.r.value}" |
|
|
@ -631,7 +633,7 @@ class INC_HL(Insn): |
|
|
|
def exec(self, cpu: CPU) -> None: |
|
|
|
hl = cpu.get_reg16(R16.HL) |
|
|
|
cpu.set_mem8(hl, cpu.get_mem8(hl) + 1) |
|
|
|
cpu.cycles += 12 |
|
|
|
cpu.state.cycles += 12 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return "INC (HL)" |
|
|
@ -643,7 +645,7 @@ class DEC_R(Insn): |
|
|
|
|
|
|
|
def exec(self, cpu: CPU) -> None: |
|
|
|
cpu.set_reg8(self.r, cpu.get_reg8(self.r) - 1) |
|
|
|
cpu.cycles += 4 |
|
|
|
cpu.state.cycles += 4 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return f"DEC {self.r.value}" |
|
|
@ -656,7 +658,7 @@ class DEC_HL(Insn): |
|
|
|
def exec(self, cpu: CPU) -> None: |
|
|
|
hl = cpu.get_reg16(R16.HL) |
|
|
|
cpu.set_mem8(hl, cpu.get_mem8(hl) - 1) |
|
|
|
cpu.cycles += 12 |
|
|
|
cpu.state.cycles += 12 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return "DEC (HL)" |
|
|
@ -666,7 +668,7 @@ class DEC_HL(Insn): |
|
|
|
class CPL(Insn): |
|
|
|
def exec(self, cpu: CPU) -> None: |
|
|
|
cpu.set_reg8(R8.A, cpu.get_reg8(R8.A) ^ 0xFF) |
|
|
|
cpu.cycles += 4 |
|
|
|
cpu.state.cycles += 4 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return "CPL" |
|
|
@ -678,9 +680,9 @@ class ADD_HL_RR(Insn): |
|
|
|
|
|
|
|
def exec(self, cpu: CPU) -> None: |
|
|
|
hl = cpu.get_reg16(R16.HL) + cpu.get_reg16(self.rr) |
|
|
|
cpu.carry = 1 if hl > 0xFFFF else 0 |
|
|
|
cpu.state.carry = 1 if hl > 0xFFFF else 0 |
|
|
|
cpu.set_reg16(R16.HL, hl) |
|
|
|
cpu.cycles += 8 |
|
|
|
cpu.state.cycles += 8 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return f"ADD HL, {self.rr.value}" |
|
|
@ -692,7 +694,7 @@ class INC_RR(Insn): |
|
|
|
|
|
|
|
def exec(self, cpu: CPU) -> None: |
|
|
|
cpu.set_reg16(self.rr, cpu.get_reg16(self.rr) + 1) |
|
|
|
cpu.cycles += 8 |
|
|
|
cpu.state.cycles += 8 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return f"INC {self.rr.value}" |
|
|
@ -704,7 +706,7 @@ class DEC_RR(Insn): |
|
|
|
|
|
|
|
def exec(self, cpu: CPU) -> None: |
|
|
|
cpu.set_reg16(self.rr, cpu.get_reg16(self.rr) - 1) |
|
|
|
cpu.cycles += 8 |
|
|
|
cpu.state.cycles += 8 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return f"DEC {self.rr.value}" |
|
|
@ -716,9 +718,9 @@ class ADD_SP_DD(Insn): |
|
|
|
|
|
|
|
def exec(self, cpu: CPU) -> None: |
|
|
|
sp = cpu.get_reg16(R16.SP) + self.dd |
|
|
|
cpu.carry = 1 if sp > 0xFFFF or sp < 0 else 0 |
|
|
|
cpu.state.carry = 1 if sp > 0xFFFF or sp < 0 else 0 |
|
|
|
cpu.set_reg16(R16.SP, sp & 0xFFFF) |
|
|
|
cpu.cycles += 16 |
|
|
|
cpu.state.cycles += 16 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return f"ADD SP, {self.dd}" |
|
|
@ -730,9 +732,9 @@ class LD_HL_SP_DD(Insn): |
|
|
|
|
|
|
|
def exec(self, cpu: CPU) -> None: |
|
|
|
sp = cpu.get_reg16(R16.SP) + self.dd |
|
|
|
cpu.carry = 1 if sp > 0xFFFF or sp < 0 else 0 |
|
|
|
cpu.state.carry = 1 if sp > 0xFFFF or sp < 0 else 0 |
|
|
|
cpu.set_reg16(R16.HL, sp & 0xFFFF) |
|
|
|
cpu.cycles += 12 |
|
|
|
cpu.state.cycles += 12 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return f"LD HL, SP + {self.dd}" |
|
|
@ -742,9 +744,9 @@ class LD_HL_SP_DD(Insn): |
|
|
|
class RLCA(Insn): |
|
|
|
def exec(self, cpu: CPU) -> None: |
|
|
|
a = cpu.get_reg8(R8.A) |
|
|
|
cpu.carry = (a >> 7) & 1 |
|
|
|
cpu.set_reg8(R8.A, ((a << 1) & 0xFF) | cpu.carry) |
|
|
|
cpu.cycles += 4 |
|
|
|
cpu.state.carry = (a >> 7) & 1 |
|
|
|
cpu.set_reg8(R8.A, ((a << 1) & 0xFF) | cpu.state.carry) |
|
|
|
cpu.state.cycles += 4 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return "RLCA" |
|
|
@ -755,9 +757,9 @@ class RLA(Insn): |
|
|
|
def exec(self, cpu: CPU) -> None: |
|
|
|
a = cpu.get_reg8(R8.A) |
|
|
|
next_carry = (a >> 7) & 1 |
|
|
|
cpu.set_reg8(R8.A, ((a << 1) & 0xFF) | cpu.carry) |
|
|
|
cpu.carry = next_carry |
|
|
|
cpu.cycles += 4 |
|
|
|
cpu.set_reg8(R8.A, ((a << 1) & 0xFF) | cpu.state.carry) |
|
|
|
cpu.state.carry = next_carry |
|
|
|
cpu.state.cycles += 4 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return "RLA" |
|
|
@ -767,9 +769,9 @@ class RLA(Insn): |
|
|
|
class RRCA(Insn): |
|
|
|
def exec(self, cpu: CPU) -> None: |
|
|
|
a = cpu.get_reg8(R8.A) |
|
|
|
cpu.carry = a & 1 |
|
|
|
cpu.set_reg8(R8.A, (a >> 1) | (cpu.carry << 7)) |
|
|
|
cpu.cycles += 4 |
|
|
|
cpu.state.carry = a & 1 |
|
|
|
cpu.set_reg8(R8.A, (a >> 1) | (cpu.state.carry << 7)) |
|
|
|
cpu.state.cycles += 4 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return "RRCA" |
|
|
@ -780,9 +782,9 @@ class RRA(Insn): |
|
|
|
def exec(self, cpu: CPU) -> None: |
|
|
|
a = cpu.get_reg8(R8.A) |
|
|
|
next_carry = a & 1 |
|
|
|
cpu.set_reg8(R8.A, (a >> 1) | (cpu.carry << 7)) |
|
|
|
cpu.carry = next_carry |
|
|
|
cpu.cycles += 4 |
|
|
|
cpu.set_reg8(R8.A, (a >> 1) | (cpu.state.carry << 7)) |
|
|
|
cpu.state.carry = next_carry |
|
|
|
cpu.state.cycles += 4 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return "RRA" |
|
|
@ -794,9 +796,9 @@ class RLC_R(Insn): |
|
|
|
|
|
|
|
def exec(self, cpu: CPU) -> None: |
|
|
|
r = cpu.get_reg8(self.r) |
|
|
|
cpu.carry = (r >> 7) & 1 |
|
|
|
cpu.set_reg8(self.r, ((r << 1) & 0xFF) | cpu.carry) |
|
|
|
cpu.cycles += 8 |
|
|
|
cpu.state.carry = (r >> 7) & 1 |
|
|
|
cpu.set_reg8(self.r, ((r << 1) & 0xFF) | cpu.state.carry) |
|
|
|
cpu.state.cycles += 8 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return f"RLC {self.r.value}" |
|
|
@ -806,9 +808,9 @@ class RLC_R(Insn): |
|
|
|
class RLC_HL(Insn): |
|
|
|
def exec(self, cpu: CPU) -> None: |
|
|
|
hl = cpu.deref_hl() |
|
|
|
cpu.carry = (hl >> 7) & 1 |
|
|
|
cpu.deref_hl_set(((hl << 1) & 0xFF) | cpu.carry) |
|
|
|
cpu.cycles += 16 |
|
|
|
cpu.state.carry = (hl >> 7) & 1 |
|
|
|
cpu.deref_hl_set(((hl << 1) & 0xFF) | cpu.state.carry) |
|
|
|
cpu.state.cycles += 16 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return f"RLC (HL)" |
|
|
@ -821,9 +823,9 @@ class RL_R(Insn): |
|
|
|
def exec(self, cpu: CPU) -> None: |
|
|
|
r = cpu.get_reg8(self.r) |
|
|
|
next_carry = (r >> 7) & 1 |
|
|
|
cpu.set_reg8(self.r, ((r << 1) & 0xFF) | cpu.carry) |
|
|
|
cpu.carry = next_carry |
|
|
|
cpu.cycles += 8 |
|
|
|
cpu.set_reg8(self.r, ((r << 1) & 0xFF) | cpu.state.carry) |
|
|
|
cpu.state.carry = next_carry |
|
|
|
cpu.state.cycles += 8 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return f"RL {self.r.value}" |
|
|
@ -834,9 +836,9 @@ class RL_HL(Insn): |
|
|
|
def exec(self, cpu: CPU) -> None: |
|
|
|
hl = cpu.deref_hl() |
|
|
|
next_carry = (hl >> 7) & 1 |
|
|
|
cpu.deref_hl_set(((hl << 1) & 0xFF) | cpu.carry) |
|
|
|
cpu.carry = next_carry |
|
|
|
cpu.cycles += 16 |
|
|
|
cpu.deref_hl_set(((hl << 1) & 0xFF) | cpu.state.carry) |
|
|
|
cpu.state.carry = next_carry |
|
|
|
cpu.state.cycles += 16 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return "RL (HL)" |
|
|
@ -848,9 +850,9 @@ class RRC_R(Insn): |
|
|
|
|
|
|
|
def exec(self, cpu: CPU) -> None: |
|
|
|
r = cpu.get_reg8(self.r) |
|
|
|
cpu.carry = r & 1 |
|
|
|
cpu.set_reg8(self.r, (r >> 1) | (cpu.carry << 7)) |
|
|
|
cpu.cycles += 8 |
|
|
|
cpu.state.carry = r & 1 |
|
|
|
cpu.set_reg8(self.r, (r >> 1) | (cpu.state.carry << 7)) |
|
|
|
cpu.state.cycles += 8 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return f"RRC {self.r.value}" |
|
|
@ -860,9 +862,9 @@ class RRC_R(Insn): |
|
|
|
class RRC_HL(Insn): |
|
|
|
def exec(self, cpu: CPU) -> None: |
|
|
|
hl = cpu.deref_hl() |
|
|
|
cpu.carry = hl & 1 |
|
|
|
cpu.deref_hl_set((hl >> 1) | (cpu.carry << 7)) |
|
|
|
cpu.cycles += 16 |
|
|
|
cpu.state.carry = hl & 1 |
|
|
|
cpu.deref_hl_set((hl >> 1) | (cpu.state.carry << 7)) |
|
|
|
cpu.state.cycles += 16 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return "RRC (HL)" |
|
|
@ -875,9 +877,9 @@ class RR_R(Insn): |
|
|
|
def exec(self, cpu: CPU) -> None: |
|
|
|
r = cpu.get_reg8(self.r) |
|
|
|
next_carry = r & 1 |
|
|
|
cpu.set_reg8(self.r, (r >> 1) | (cpu.carry << 7)) |
|
|
|
cpu.carry = next_carry |
|
|
|
cpu.cycles += 8 |
|
|
|
cpu.set_reg8(self.r, (r >> 1) | (cpu.state.carry << 7)) |
|
|
|
cpu.state.carry = next_carry |
|
|
|
cpu.state.cycles += 8 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return f"RR {self.r.value}" |
|
|
@ -888,9 +890,9 @@ class RR_HL(Insn): |
|
|
|
def exec(self, cpu: CPU) -> None: |
|
|
|
hl = cpu.deref_hl() |
|
|
|
next_carry = hl & 1 |
|
|
|
cpu.deref_hl_set((hl >> 1) | (cpu.carry << 7)) |
|
|
|
cpu.carry = next_carry |
|
|
|
cpu.cycles += 16 |
|
|
|
cpu.deref_hl_set((hl >> 1) | (cpu.state.carry << 7)) |
|
|
|
cpu.state.carry = next_carry |
|
|
|
cpu.state.cycles += 16 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return "RR (HL)" |
|
|
@ -902,9 +904,9 @@ class SLA_R(Insn): |
|
|
|
|
|
|
|
def exec(self, cpu: CPU) -> None: |
|
|
|
r = cpu.get_reg8(self.r) |
|
|
|
cpu.carry = 1 if r & (1 << 7) else 0 |
|
|
|
cpu.state.carry = 1 if r & (1 << 7) else 0 |
|
|
|
cpu.set_reg8(self.r, (r << 1) & 0xFF) |
|
|
|
cpu.cycles += 8 |
|
|
|
cpu.state.cycles += 8 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return f"SLA {self.r.value}" |
|
|
@ -914,9 +916,9 @@ class SLA_R(Insn): |
|
|
|
class SLA_HL(Insn): |
|
|
|
def exec(self, cpu: CPU) -> None: |
|
|
|
hl = cpu.deref_hl() |
|
|
|
cpu.carry = 1 if hl & (1 << 7) else 0 |
|
|
|
cpu.state.carry = 1 if hl & (1 << 7) else 0 |
|
|
|
cpu.deref_hl_set((hl << 1) & 0xFF) |
|
|
|
cpu.cycles += 16 |
|
|
|
cpu.state.cycles += 16 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return "SLA (HL)" |
|
|
@ -929,8 +931,8 @@ class SWAP_R(Insn): |
|
|
|
def exec(self, cpu: CPU) -> None: |
|
|
|
r = cpu.get_reg8(self.r) |
|
|
|
cpu.set_reg8(self.r, ((r << 4) & 0xFF) | (r >> 4)) |
|
|
|
cpu.carry = 0 |
|
|
|
cpu.cycles += 8 |
|
|
|
cpu.state.carry = 0 |
|
|
|
cpu.state.cycles += 8 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return f"SWAP {self.r.value}" |
|
|
@ -941,8 +943,8 @@ class SWAP_HL(Insn): |
|
|
|
def exec(self, cpu: CPU) -> None: |
|
|
|
hl = cpu.deref_hl() |
|
|
|
cpu.deref_hl_set(((hl << 4) & 0xFF) | (hl >> 4)) |
|
|
|
cpu.carry = 0 |
|
|
|
cpu.cycles += 16 |
|
|
|
cpu.state.carry = 0 |
|
|
|
cpu.state.cycles += 16 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return "SWAP (HL)" |
|
|
@ -954,9 +956,9 @@ class SRA_R(Insn): |
|
|
|
|
|
|
|
def exec(self, cpu: CPU) -> None: |
|
|
|
r = cpu.get_reg8(self.r) |
|
|
|
cpu.carry = 1 if r & (1 << 0) else 0 |
|
|
|
cpu.state.carry = 1 if r & (1 << 0) else 0 |
|
|
|
cpu.set_reg8(self.r, (r >> 1) | (r & (1 << 7))) |
|
|
|
cpu.cycles += 8 |
|
|
|
cpu.state.cycles += 8 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return f"SRA {self.r.value}" |
|
|
@ -966,9 +968,9 @@ class SRA_R(Insn): |
|
|
|
class SRA_HL(Insn): |
|
|
|
def exec(self, cpu: CPU) -> None: |
|
|
|
hl = cpu.deref_hl() |
|
|
|
cpu.carry = 1 if hl & (1 << 0) else 0 |
|
|
|
cpu.state.carry = 1 if hl & (1 << 0) else 0 |
|
|
|
cpu.deref_hl_set((hl >> 1) | (hl & (1 << 7))) |
|
|
|
cpu.cycles += 16 |
|
|
|
cpu.state.cycles += 16 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return "SRA (HL)" |
|
|
@ -980,9 +982,9 @@ class SRL_R(Insn): |
|
|
|
|
|
|
|
def exec(self, cpu: CPU) -> None: |
|
|
|
r = cpu.get_reg8(self.r) |
|
|
|
cpu.carry = 1 if r & (1 << 0) else 0 |
|
|
|
cpu.state.carry = 1 if r & (1 << 0) else 0 |
|
|
|
cpu.set_reg8(self.r, r >> 1) |
|
|
|
cpu.cycles += 8 |
|
|
|
cpu.state.cycles += 8 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return f"SRL {self.r.value}" |
|
|
@ -992,9 +994,9 @@ class SRL_R(Insn): |
|
|
|
class SRL_HL(Insn): |
|
|
|
def exec(self, cpu: CPU) -> None: |
|
|
|
hl = cpu.deref_hl() |
|
|
|
cpu.carry = 1 if hl & (1 << 0) else 0 |
|
|
|
cpu.state.carry = 1 if hl & (1 << 0) else 0 |
|
|
|
cpu.deref_hl_set(hl >> 1) |
|
|
|
cpu.cycles += 16 |
|
|
|
cpu.state.cycles += 16 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return "SRL (HL)" |
|
|
@ -1007,7 +1009,7 @@ class SET_N_R(Insn): |
|
|
|
|
|
|
|
def exec(self, cpu: CPU) -> None: |
|
|
|
cpu.set_reg8(self.r, cpu.get_reg8(self.r) | (1 << self.n)) |
|
|
|
cpu.cycles += 8 |
|
|
|
cpu.state.cycles += 8 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return f"SET {self.n}, {self.r.value}" |
|
|
@ -1020,7 +1022,7 @@ class SET_N_HL(Insn): |
|
|
|
def exec(self, cpu: CPU) -> None: |
|
|
|
hl = cpu.get_reg16(R16.HL) |
|
|
|
cpu.set_mem8(hl, cpu.get_mem8(hl) | (1 << self.n)) |
|
|
|
cpu.cycles += 16 |
|
|
|
cpu.state.cycles += 16 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return f"SET {self.n}, (HL)" |
|
|
@ -1033,7 +1035,7 @@ class RES_N_R(Insn): |
|
|
|
|
|
|
|
def exec(self, cpu: CPU) -> None: |
|
|
|
cpu.set_reg8(self.r, cpu.get_reg8(self.r) & ~(1 << self.n)) |
|
|
|
cpu.cycles += 8 |
|
|
|
cpu.state.cycles += 8 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return f"RES {self.n}, (HL)" |
|
|
@ -1046,7 +1048,7 @@ class RES_N_HL(Insn): |
|
|
|
def exec(self, cpu: CPU) -> None: |
|
|
|
hl = cpu.get_reg16(R16.HL) |
|
|
|
cpu.set_mem8(hl, cpu.get_mem8(hl) & ~(1 << self.n)) |
|
|
|
cpu.cycles += 16 |
|
|
|
cpu.state.cycles += 16 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return f"RES {self.n}, (HL)" |
|
|
@ -1055,8 +1057,8 @@ class RES_N_HL(Insn): |
|
|
|
@dataclass |
|
|
|
class CCF(Insn): |
|
|
|
def exec(self, cpu: CPU) -> None: |
|
|
|
cpu.carry = cpu.carry ^ 1 |
|
|
|
cpu.cycles += 4 |
|
|
|
cpu.state.carry = cpu.state.carry ^ 1 |
|
|
|
cpu.state.cycles += 4 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return "CCF" |
|
|
@ -1065,8 +1067,8 @@ class CCF(Insn): |
|
|
|
@dataclass |
|
|
|
class SCF(Insn): |
|
|
|
def exec(self, cpu: CPU) -> None: |
|
|
|
cpu.carry = 1 |
|
|
|
cpu.cycles += 4 |
|
|
|
cpu.state.carry = 1 |
|
|
|
cpu.state.cycles += 4 |
|
|
|
|
|
|
|
def pretty(self) -> str: |
|
|
|
return "SCF" |
|
|
|