aboutsummaryrefslogtreecommitdiffstats
path: root/atk16_emu/emu.py
diff options
context:
space:
mode:
authorJan Tuomi <jans.tuomi@gmail.com>2024-02-24 19:04:00 +0200
committerJan Tuomi <jans.tuomi@gmail.com>2024-02-24 19:04:00 +0200
commit0a2cf66672364ed555c85682e948cff0b54c8f35 (patch)
tree249a426faf5e7ba0d218176f651dca6c635a3705 /atk16_emu/emu.py
parent416e896956d3b05793337da6609fe1544797c0a9 (diff)
Fix bugs, add basic debugger
Diffstat (limited to 'atk16_emu/emu.py')
-rw-r--r--atk16_emu/emu.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/atk16_emu/emu.py b/atk16_emu/emu.py
index 591eeb5..8eeb6b1 100644
--- a/atk16_emu/emu.py
+++ b/atk16_emu/emu.py
@@ -208,6 +208,8 @@ class Machine:
instr = self.mem_read(pc_addr)
instruction = self.decode(instr)
+ #print(f"Executing instruction 0b{instr:>016b} (0x{instr:>04x}) at address 0x{pc_addr:>04x}")
+
try:
match instruction:
case ALR(target, left, right, alu_code):
@@ -254,6 +256,8 @@ class Machine:
self.pc.value = addr
case JPI(imm):
+ # convert imm from signed (twos complement) 9-bit to a python int
+ imm = (imm & (0b011111111)) - (imm & 0b100000000)
self.pc.value = (self.pc.value + imm) & 0xFFFF
case BRR(flag, addr_reg):
@@ -262,6 +266,8 @@ class Machine:
self.pc.value = addr
case BRI(flag, addr_imm):
+ # convert imm from signed (twos complement) 9-bit to a python int
+ addr_imm = (addr_imm & (0b011111111)) - (addr_imm & 0b100000000)
if self.check_nth_flag(flag):
self.pc.value = (self.pc.value + addr_imm) & 0xFFFF
@@ -288,7 +294,7 @@ class Machine:
self.running = False
except:
- print(f"Error while executing instruction {instr:>016b} ({instr:>04x}) at address {pc_addr:>04x}", file=sys.stderr)
+ print(f"Error while executing instruction 0b{instr:>016b} (0x{instr:>04x}) at address 0x{pc_addr:>04x}", file=sys.stderr)
raise
def decode(self, instr: int):