Properly handle non-instruction bytes in the range 0xa0…0xbf
Previously address arguments were extracted without verifying the start byte corresponded to a valid instruction. In case of a non-instruction byte this would result in the two following bytes to be silently skipped.
This commit is contained in:
parent
57473ee34e
commit
66e28d6ef8
|
@ -0,0 +1 @@
|
||||||
|
*.bin
|
|
@ -41,23 +41,22 @@ def segment(binary, origin):
|
||||||
rx = (byte >> 2) & 3
|
rx = (byte >> 2) & 3
|
||||||
ry = byte & 3
|
ry = byte & 3
|
||||||
|
|
||||||
addr = None
|
|
||||||
if opcodes[opcode].addr:
|
|
||||||
addr = (binary[ip + 1] << 8) + binary[ip + 2]
|
|
||||||
|
|
||||||
valid = True
|
valid = True
|
||||||
if not opcodes[opcode].rx and rx != 0: valid = False
|
if not opcodes[opcode].rx and rx != 0: valid = False
|
||||||
if not opcodes[opcode].ry and ry != 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)
|
instruction = Instruction(opcode, rx, ry, addr)
|
||||||
statements.append(Statement(ip, instruction))
|
statements.append(Statement(ip, instruction))
|
||||||
|
ip += 3
|
||||||
else:
|
else:
|
||||||
statements.append(Statement(ip, Data(byte)))
|
instruction = Instruction(opcode, rx, ry, None)
|
||||||
|
statements.append(Statement(ip, instruction))
|
||||||
ip += 1
|
ip += 1
|
||||||
if opcodes[opcode].addr:
|
|
||||||
ip += 2
|
|
||||||
|
|
||||||
return statements
|
return statements
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue