diff --git a/src/gbasm/instructions/fixed.py b/src/gbasm/instructions/fixed.py new file mode 100644 index 0000000..03cc365 --- /dev/null +++ b/src/gbasm/instructions/fixed.py @@ -0,0 +1,97 @@ +from .Instruction import Instruction +from ..arguments import Argument +from typing import Callable, List + + +class FixedInstruction(Instruction): + def __init__(self, token: str, data: bytes): + argtypes = [[]] + self.data = data + self.token = token + super().__init__(token, argtypes) + + def num_bytes(self, arguments) -> int: + return self.data + + def to_bytes( + self, + arguments: List[Argument], + instruction_addr: int, + label_resolver: Callable[[str], int], + ) -> bytes: + + if len(arguments) != 0: + raise ValueError(f"Incorrect number of arguments for instruction {self.token}") + + return self.data + + +class Ccf(FixedInstruction): + def __init__(self): + super().__init__("CCF", bytes([0x10])) + + +class Cpl(FixedInstruction): + def __init__(self): + super().__init__("CPL", bytes([0x10])) + + +class Daa(FixedInstruction): + def __init__(self): + super().__init__("DAA", bytes([0x10])) + + +class Di(FixedInstruction): + def __init__(self): + super().__init__("DI", bytes([0x10])) + + +class Ei(FixedInstruction): + def __init__(self): + super().__init__("EI", bytes([0x10])) + + +class Halt(FixedInstruction): + def __init__(self): + super().__init__("HALT", bytes([0x10])) + + +class Nop(FixedInstruction): + def __init__(self): + super().__init__("NOP", bytes([0x00])) + + +class Ret(FixedInstruction): + def __init__(self): + super().__init__("RET", bytes([0x10])) + + +class Reti(FixedInstruction): + def __init__(self): + super().__init__("RETI", bytes([0x10])) + + +class Rla(FixedInstruction): + def __init__(self): + super().__init__("RLA", bytes([0x10])) + + +class Rlca(FixedInstruction): + def __init__(self): + super().__init__("RLCA", bytes([0x10])) + + +class Rra(FixedInstruction): + def __init__(self): + super().__init__("RRCA", bytes([0x10])) + + +class Scf(FixedInstruction): + def __init__(self): + super().__init__("SCF", bytes([0x10])) + + +class Stop(FixedInstruction): + def __init__(self): + super().__init__("STOP", bytes([0x10])) +