diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a8a0dce --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.bin diff --git a/thingamajig_disasm.py b/thingamajig_disasm.py index 1655643..fda93b6 100644 --- a/thingamajig_disasm.py +++ b/thingamajig_disasm.py @@ -41,23 +41,22 @@ def segment(binary, origin): rx = (byte >> 2) & 3 ry = byte & 3 - addr = None - if opcodes[opcode].addr: - addr = (binary[ip + 1] << 8) + binary[ip + 2] - valid = True if not opcodes[opcode].rx and rx != 0: valid = False if not opcodes[opcode].ry and ry != 0: valid = False - if valid: + if not valid: + statements.append(Statement(ip, Data(byte))) + ip += 1 + elif opcodes[opcode].addr: + addr = (binary[ip + 1] << 8) + binary[ip + 2] instruction = Instruction(opcode, rx, ry, addr) statements.append(Statement(ip, instruction)) + ip += 3 else: - statements.append(Statement(ip, Data(byte))) - - ip += 1 - if opcodes[opcode].addr: - ip += 2 + instruction = Instruction(opcode, rx, ry, None) + statements.append(Statement(ip, instruction)) + ip += 1 return statements