aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Tuomi <jans.tuomi@gmail.com>2024-02-21 15:46:30 +0200
committerJan Tuomi <jans.tuomi@gmail.com>2024-02-21 15:46:30 +0200
commitaefe0cf3874c542669051b2b3cc21c9590aa970b (patch)
treee8e6d12b2a261fa0dbde21654c999a14f43824bb
parentf88be86978af5ebb92bc9f11e99015afc6b6c4f7 (diff)
Fix bugs
-rw-r--r--.vscode/launch.json6
-rw-r--r--Makefile6
-rw-r--r--atk16_emu/cli.py16
-rw-r--r--atk16_emu/emu.py8
4 files changed, 28 insertions, 8 deletions
diff --git a/.vscode/launch.json b/.vscode/launch.json
index a7efb5f..397ff70 100644
--- a/.vscode/launch.json
+++ b/.vscode/launch.json
@@ -5,13 +5,13 @@
"version": "0.2.0",
"configurations": [
{
- "name": "Python: Current File",
+ "name": "Python: emu module",
"type": "python",
"request": "launch",
- "program": "${file}",
+ "module": "atk16_emu.cli",
"console": "integratedTerminal",
"justMyCode": true,
- "args": ["out/just_hlt.bin"]
+ "args": ["out/sum.bin"]
}
]
} \ No newline at end of file
diff --git a/Makefile b/Makefile
index b11d03b..3c3ae26 100644
--- a/Makefile
+++ b/Makefile
@@ -38,9 +38,13 @@ bytecode-compile:
emu:
$(py) -m atk16_emu.cli $(in)
+# make test-digital-alu
+test-digital-alu:
+ $(py) atk16_asm/test_alu.py digital_diagrams/atk16_alu.dig
+
# make test
test:
- $(py) atk16_asm/test_alu.py digital_diagrams/atk16_alu.dig
+ pytest --ignore resources
run-single-test:
java -cp $(digital_path) CLI test -verbose -circ $(circ) -tests $(tests)
diff --git a/atk16_emu/cli.py b/atk16_emu/cli.py
index 2e4721d..113eb87 100644
--- a/atk16_emu/cli.py
+++ b/atk16_emu/cli.py
@@ -47,3 +47,19 @@ machine = Machine()
machine.load_rom_image(rom_image)
machine.reset()
machine.run_until_halted()
+
+print("Machine halted.")
+print("===============")
+
+for i in range(8):
+ reg_name = f"r{chr(ord('a') + i)}"
+ value = getattr(machine, reg_name).value
+ print(f"{reg_name.upper()}: 0x{value:>04x} ({value})")
+
+print(f"PC: 0x{machine.pc.value:>04x} ({machine.pc.value})")
+print(f"FR: carry={machine.fr.carry}\n "
+ f"overflow={machine.fr.overflow}\n "
+ f"zero={machine.fr.zero}\n "
+ f"sign={machine.fr.sign}")
+for i in range(8):
+ print(f"RAM[{i}]: 0x{machine.ram.read(i):>04x} ({machine.ram.read(i)})")
diff --git a/atk16_emu/emu.py b/atk16_emu/emu.py
index 2f5b79a..1596222 100644
--- a/atk16_emu/emu.py
+++ b/atk16_emu/emu.py
@@ -288,7 +288,7 @@ class Machine:
self.running = False
except:
- print(f"Error while executing instruction {instr:>016b} at address {pc_addr:>04x}", file=sys.stderr)
+ print(f"Error while executing instruction {instr:>016b} ({instr:>04x}) at address {pc_addr:>04x}", file=sys.stderr)
raise
def decode(self, instr: int):
@@ -305,8 +305,8 @@ class Machine:
alu_code=opdata & 0b000000000111)
case 0b0010: return LDR(to_reg=(opdata & 0b111000000000) >> 9,
addr_reg=(opdata & 0b000111000000) >> 6)
- case 0b0011: return STR(addr_reg=(opdata & 0b000111000000) >> 6,
- from_reg=(opdata & 0b000000111000) >> 3)
+ case 0b0011: return STR(from_reg=(opdata & 0b000111000000) >> 6,
+ addr_reg=(opdata & 0b000000111000) >> 3)
case 0b0100: return LDI(to_reg=(opdata & 0b111000000000) >> 9,
imm=opdata & 0b000111111111)
case 0b0101: return JPR(addr_reg=(opdata & 0b000111000000) >> 6)
@@ -323,4 +323,4 @@ class Machine:
case 0b1110: return RTI()
case 0b1111: return HLT()
- raise ValueError(f"Invalid instruction: {instr:>016b}")
+ raise ValueError(f"Invalid instruction: {instr:>016b} ({instr:>04x})")