Refactor imports
This commit is contained in:
@@ -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(
|
||||
|
||||
@@ -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(),
|
||||
]
|
||||
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user