aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Tuomi <jan@jantuomi.fi>2024-05-16 23:38:13 +0300
committerJan Tuomi <jan@jantuomi.fi>2024-05-16 23:38:13 +0300
commit51980405aa4c574845854c14bf31142ee5558f99 (patch)
treee99ea05333080a80f4ab0c3e70d14447c05eecd9
parenta568629bf316e3cb7fe9baa0e14c3e8ec398b682 (diff)
Make text memory readable
-rw-r--r--atk16_emu/emu.py8
-rw-r--r--atk16_emu/peripherals.py10
-rw-r--r--atk16_projects/monitor/monitor.atk1648
3 files changed, 43 insertions, 23 deletions
diff --git a/atk16_emu/emu.py b/atk16_emu/emu.py
index 67f63f1..b3a3500 100644
--- a/atk16_emu/emu.py
+++ b/atk16_emu/emu.py
@@ -208,6 +208,8 @@ class Machine:
else:
if addr == 0xE7F1:
return self.peripherals.keyboard.read()
+ elif 0xF800 <= addr <= 0xFFFF:
+ return self.peripherals.graphics.read(addr)
else:
return self.ram.read(addr & 0x7FFF)
@@ -453,9 +455,9 @@ class Machine:
reg_hex = C.OKBLUE + f"0x{value:>04x}" + C.ENDC
print(f"{reg_name.upper()}: {reg_hex} ({value})")
- for i in range(8):
- ram_hex = C.OKBLUE + f"0x{self.ram.read(i):>04x}" + C.ENDC
- print(f"RAM[{i}]: {ram_hex} ({self.ram.read(i)})")
+ # for i in range(8):
+ # ram_hex = C.OKBLUE + f"0x{self.ram.read(i):>04x}" + C.ENDC
+ # print(f"RAM[{i}]: {ram_hex} ({self.ram.read(i)})")
def as_num(b: bool) -> str:
return ((C.OKGREEN + "1") if b else (C.WARNING + "0")) + C.ENDC
diff --git a/atk16_emu/peripherals.py b/atk16_emu/peripherals.py
index b8a5b14..3bc0443 100644
--- a/atk16_emu/peripherals.py
+++ b/atk16_emu/peripherals.py
@@ -72,6 +72,9 @@ class TPU:
# address: 5 bits y, 6 bits x
self.text_mem.write(addr, char & 0xFF)
+ def read_char(self, addr: int) -> int:
+ return self.text_mem.read(addr)
+
class Graphics:
def __init__(self):
pygame.display.init()
@@ -111,6 +114,9 @@ class Graphics:
# take only the lower 11 bits
self.tpu.write_char(addr & 0x7FF, char)
+ def read(self, addr: int) -> int:
+ return self.tpu.read_char(addr & 0x7FF)
+
class DummyGraphics:
def __init__(self):
pass
@@ -130,6 +136,10 @@ class DummyGraphics:
def write(self, addr: int, char: int):
pass
+ def read(self, addr: int) -> int:
+ print("warning: reading from dummy graphics")
+ return 0
+
class Keyboard:
def __init__(self, set_irq_line: Callable[[int], None]):
# mimic electronic behaviour my assigning a random value at start
diff --git a/atk16_projects/monitor/monitor.atk16 b/atk16_projects/monitor/monitor.atk16
index a0d4e9d..4ec1205 100644
--- a/atk16_projects/monitor/monitor.atk16
+++ b/atk16_projects/monitor/monitor.atk16
@@ -7,12 +7,12 @@
; Constants
@data text_buffer_size 2048
-@data input_buffer_size 36 ; 40 chars row - 2 padding - 2 for prompt
+@data input_buffer_size 37 ; 1 word length + 40 chars row - 2 padding - 2 for prompt
; Global variable pointers
; 0xE800 - 0xEFFF: sprite buffer space that is unused in this program
@data text_cursor_p 0xE800
-@data input_buffer_p 0xE801
+@data input_string_p 0xE801
@data input_cursor_p 0xE802
@data input_entered_bool 0xE803
@@ -33,15 +33,15 @@
str RB RA
; END
- ; BEGIN input_buffer_p = alloc(input_buffer_size)
+ ; BEGIN input_string_p = alloc(input_buffer_size)
ldi input_buffer_size RA
calli bump_alloc
- ldi input_buffer_p RA
+ ldi input_string_p RA
ldr RA RA
str RG RA
; END
- ; BEGIN input_cursor_p = input_buffer_p
+ ; BEGIN input_cursor_p = input_string_p
ldi input_cursor_p RA
ldr RA RA
str RG RA
@@ -101,14 +101,15 @@
ldi 0 RB ; else, run this branch and set input_entered_bool = 0
str RB RA
-@data eval_output_string "command received!"
+@data eval_output_string "command received: "
ldi eval_output_string RA
calli put_string
- ; ldi input_buffer_p RA ; TODO!
- ; ldr RA RA
- ; ldr RA RA
- ; calli put_string
+ ldi input_string_p RA
+ ldr RA RA
+ ldr RA RA
+
+ calli put_string
m_newline RA RB
@@ -160,21 +161,26 @@
jpi keyboard_isr_end
@label keyboard_isr_newline
- m_newline RA RB
-
; note: RC = text_cursor_p, set in the beginning of the ISR
- ; BEGIN memcopy(last_line_p, input_buffer_p, input_buffer_size)
- slri RC 6 RC ; RC := RC >> 6, i.e. the row index
- slli RC 6 RC ; RC := RC << 6, i.e. index to the first character of the row
+ ldi row_index_mask RA
+ ldr RA RA
+ and RC RA RD ; RD := RC & 63, i.e. the position on the row
+ subi RD 3 RD ; RD = length of the command string
+
+ ldi input_string_p RB
+ ldr RB RB ; RB := &input_string_p
+ ldr RB RB ; RB := input_string_p
+ str RD RB ; input_string_p length := RD (length of command string)
+
+ ; BEGIN memcopy(last_line_p, input_string_p, input_buffer_size)
+ slri RC 6 RC ; RC := RC >> 6, i.e. the row index
+ slli RC 6 RC ; RC := RC << 6, i.e. index to the first character of the row
addi RC 3 RA ; RA := RC + 3, i.e. index to the first character of the input string
- ldi input_buffer_p RB
- ldr RB RB ; RB := &input_buffer_p
- ldr RB RB ; RB := input_buffer_p
+ addi RB 1 RB ; RB := input_string_p + 1, i.e. index to the first character of the input string
- ldi input_buffer_size RC
- ldr RC RC ; RC := input_buffer_size
+ mov RD RC
ldi memcopy RD
callr RD
@@ -187,6 +193,8 @@
str RB RA
; END
+ m_newline RA RB
+
ldi ${ord(" ")} RA
m_put_char RA RB RD