diff --git a/src/gbasm/gbasm.py b/src/gbasm/gbasm.py index 17bec8c..c2ac13b 100755 --- a/src/gbasm/gbasm.py +++ b/src/gbasm/gbasm.py @@ -4,13 +4,7 @@ import argparse import logging import sys -from .instructions import Instruction -from .instructions.inc import Inc -from .instructions.dec import Dec -from .instructions.nop import Nop -from .instructions.stop import Stop -from .instructions.jr import Jr -from .instructions.ld import Ld +from .instructions import Instruction. get_instructions from .arguments import ArgumentParser, Argument from typing import Callable, Dict, List, Optional @@ -20,21 +14,9 @@ logger = logging.getLogger(__name__) COMMENT_CHAR = "#" LABEL_SUFFIX = ":" -GB_INSTRUCTIONS = [ - Nop(), - Stop(), - Inc(), - Dec(), - Jr(), - Ld(), -] - def build_instruction_map() -> Dict[str, Instruction]: - d = {} # type: Dict[str, Instruction] - for i in GB_INSTRUCTIONS: - d[i.token] = i - return d + return {i.token: i for i in get_instructions()} # type: Dict[str, Instruction] def try_parse_arguments( diff --git a/src/gbasm/instructions/__init__.py b/src/gbasm/instructions/__init__.py index 1c18381..333feac 100755 --- a/src/gbasm/instructions/__init__.py +++ b/src/gbasm/instructions/__init__.py @@ -1 +1,28 @@ from .Instruction import Instruction +from .dec import Dec +from .inc import Inc +from .jr import Jr +from .ld import Ld +from .fixed import Ccf, Cpl, Daa, Di, Ei, Halt, Nop, Ret, Reti, Rla, Rlca, Rra, Scf, Stop + +def get_instructions() -> List[Instruction]: + return = [ + Ccf(), + Cpl(), + Daa(), + Dec(), + Di(), + Ei(), + Inc(), + Halt(), + Jr(), + Nop(), + Ret(), + Reti(), + Rla(), + Rlca(), + Rra(), + Scf(), + Stop(), + ] + diff --git a/src/gbasm/instructions/ld.py b/src/gbasm/instructions/ld.py index 87f27af..54f7842 100644 --- a/src/gbasm/instructions/ld.py +++ b/src/gbasm/instructions/ld.py @@ -16,7 +16,6 @@ class Ld(Instruction): def encode_reg_16(self, register: Register16, immediate: Immediate16) -> bytes: reg_dict = {"BC": 0x01, "DE": 0x11, "HL": 0x21, "SP": 0x31} imm = int(immediate.value, 0) - print("immediate", imm) out = bytearray() out.append(reg_dict[register.value]) out.extend(imm.to_bytes(2, "little", signed=imm < 0)) @@ -29,12 +28,6 @@ class Ld(Instruction): label_resolver: Callable[[str], int], ) -> bytes: - # print(arguments) - # print("Register16", type(arguments[0])) - # print("Immediate16", isinstance(arguments[1], Immediate16)) - - # if isinstance(arguments[0], Register16) and \ - # isinstance(arguments[1], Immediate16): return self.encode_reg_16(arguments[0], arguments[1]) raise TypeError("Unhandled argument types")