Commit 6bc724ae authored by Brandon Warner's avatar Brandon Warner
Browse files

Implemented more instructions including relative jumps.

parent 5af8dbf0
......@@ -32,6 +32,38 @@ INSTS = [
{"inst":"rrca","size":1,"arg_re":None, "bytecode": 0x0F, "out":struct.Struct('<B')}, # rrca
{"inst":"djnz","size":2,"arg_re":re.compile("([^\\s]*)"), "bytecode": 0x10, "out":struct.Struct('<BB')}, # djnz *
{"inst":"ld","size":3,"arg_re":re.compile("de, *(0x[a-fA-F0-9]{1,4}|[A-Z_]+)"), "bytecode": 0x11, "out":struct.Struct('<BH')},# ld de,**
{"inst":"ld","size":1,"arg_re":re.compile("\\(de\\), *a"), "bytecode": 0x12, "out":struct.Struct('<B')}, # ld (de), a
{"inst":"inc","size":1,"arg_re":re.compile("de"), "bytecode": 0x13, "out":struct.Struct('<B')}, # inc de
{"inst":"inc","size":1,"arg_re":re.compile("d"), "bytecode": 0x14, "out":struct.Struct('<B')}, # inc d
{"inst":"dec","size":1,"arg_re":re.compile("d"), "bytecode": 0x15, "out":struct.Struct('<B')}, # dec d
{"inst":"ld","size":2,"arg_re":re.compile("d, *([^\\s]*)"), "bytecode": 0x16, "out":struct.Struct('<BB')}, # ld d, *
{"inst":"rla","size":1,"arg_re":None, "bytecode": 0x17, "out":struct.Struct('<B')}, # rla
{"inst":"jr","size":2,"arg_re":re.compile("([^\\s]*)"), "bytecode": 0x18, "out":struct.Struct('<Bb')}, # jr *
{"inst":"add","size":1,"arg_re":re.compile("hl, *de"), "bytecode": 0x19, "out":struct.Struct('<B')}, # add hl, de
{"inst":"ld","size":1,"arg_re":re.compile("a, *\\(de\\)"), "bytecode": 0x1A, "out":struct.Struct('<B')}, # ld a, (de)
{"inst":"dec","size":1,"arg_re":re.compile("de"), "bytecode": 0x1B, "out":struct.Struct('<B')}, # dec de
{"inst":"inc","size":1,"arg_re":re.compile("e"), "bytecode": 0x1C, "out":struct.Struct('<B')}, # inc e
{"inst":"dec","size":1,"arg_re":re.compile("e"), "bytecode": 0x1D, "out":struct.Struct('<B')}, # dec e
{"inst":"ld","size":2,"arg_re":re.compile("e, *([^\\s]*)"), "bytecode": 0x1E, "out":struct.Struct('<BB')}, # ld e, *
{"inst":"rra","size":1,"arg_re":None, "bytecode": 0x1F, "out":struct.Struct('<B')}, # rra
{"inst": "jr", "size": 2, "arg_re": re.compile("nz, *([^\\s]*)"), "bytecode": 0x20, "out": struct.Struct('<Bb')}, # jp nz, *
{"inst": "ld", "size": 3, "arg_re": re.compile("hl, *(0x[a-fA-F0-9]{1,4}|[A-Z_]+)"), "bytecode": 0x21, "out": struct.Struct('<BH')}, # ld hl,**
{"inst": "ld", "size": 1, "arg_re": re.compile("\\(hl\\), *a"), "bytecode": 0x22, "out": struct.Struct('<B')}, # ld (hl), a
{"inst": "inc", "size": 1, "arg_re": re.compile("hl"), "bytecode": 0x23, "out": struct.Struct('<B')}, # inc hl
{"inst": "inc", "size": 1, "arg_re": re.compile("h"), "bytecode": 0x24, "out": struct.Struct('<B')}, # inc h
{"inst": "dec", "size": 1, "arg_re": re.compile("h"), "bytecode": 0x25, "out": struct.Struct('<B')}, # dec h
{"inst": "ld", "size": 2, "arg_re": re.compile("h, *([^\\s]*)"), "bytecode": 0x26, "out": struct.Struct('<BB')}, # ld h, *
{"inst": "daa", "size": 1, "arg_re": None, "bytecode": 0x27, "out": struct.Struct('<B')}, # daa
{"inst": "jr", "size": 2, "arg_re": re.compile("z, *([^\\s]*)"), "bytecode": 0x28, "out": struct.Struct('<Bb')}, # jr z, *
{"inst": "add", "size": 1, "arg_re": re.compile("hl, *hl"), "bytecode": 0x29, "out": struct.Struct('<B')}, # add hl, hl
{"inst": "ld", "size": 3, "arg_re": re.compile("hl, *\\((0x[a-fA-F0-9]{1,4}|[A-Z_]+)\\)"), "bytecode": 0x2A, "out": struct.Struct('<BH')}, # ld hl, (**)
{"inst": "dec", "size": 1, "arg_re": re.compile("hl"), "bytecode": 0x2B, "out": struct.Struct('<B')}, # hl
{"inst": "inc", "size": 1, "arg_re": re.compile("l"), "bytecode": 0x2C, "out": struct.Struct('<B')}, # inc l
{"inst": "dec", "size": 1, "arg_re": re.compile("l"), "bytecode": 0x2D, "out": struct.Struct('<B')}, # dec l
{"inst": "ld", "size": 2, "arg_re": re.compile("l, *([^\\s]*)"), "bytecode": 0x2E, "out": struct.Struct('<BB')}, # ld l, *
{"inst": "cpl", "size": 1, "arg_re": None, "bytecode": 0x2F, "out": struct.Struct('<B')}, # cpl
HEX_RE = re.compile("0x[A-Fa-f0-9]+")
......@@ -170,7 +202,11 @@ def assemble(input, output):
for pl in parsed_lines:
if "id" in pl.keys() and pl["id"] is not None:
if "arg" in pl.keys():
pl["bin"] = pl["id"]["out"].pack(pl['id']['bytecode'],pl['arg'])
if pl['id']['inst'] == "jr":
pl['arg'] = (pl['addr'] + 2 - pl['arg']) * -1
pl["bin"] = pl["id"]["out"].pack(pl['id']['bytecode'], pl['arg'])
pl["bin"] = pl["id"]["out"].pack(pl['id']['bytecode'])
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment