aboutsummaryrefslogtreecommitdiffstats
path: root/asm
diff options
context:
space:
mode:
authorJan Tuomi <jans.tuomi@gmail.com>2023-11-03 19:55:52 +0200
committerJan Tuomi <jans.tuomi@gmail.com>2023-11-03 19:55:52 +0200
commitabf6cbdecc8eb006a859205dee7500c2b70c0998 (patch)
tree4938cfaf270b6c83a77767de968845f704049205 /asm
parenta3b677bac00060393cc66f1bb3b350413282a4ae (diff)
Fix macros, add string I/O helpers
Diffstat (limited to 'asm')
-rw-r--r--asm/ext_string_io.py47
-rw-r--r--asm/text_mode.atk1659
2 files changed, 54 insertions, 52 deletions
diff --git a/asm/ext_string_io.py b/asm/ext_string_io.py
new file mode 100644
index 0000000..cf7d598
--- /dev/null
+++ b/asm/ext_string_io.py
@@ -0,0 +1,47 @@
+from asm_ops import *
+from ext_std import expand_addi
+
+def to_char_code(c: str):
+ if c == " " or c == "%SPACE": return 0
+ else: return ord(c) - 64
+
+_counter = 0
+def get_unique_name(prefix: str):
+ global _counter
+ ret = f"{prefix}_{_counter}"
+ _counter += 1
+ return ret
+
+def expand_put_char(cursor_reg: str, scratch_reg: str, c: str) -> ExpandResult:
+ return [
+ ["ldi", str(to_char_code(c)), scratch_reg],
+ ["str", scratch_reg, cursor_reg],
+ *expand_addi("RA", "1", "RA"),
+ ]
+
+def expand_put_string(cursor_reg: str, scratch_reg: str, *rest: str) -> ExpandResult:
+ string = " ".join(rest)
+ result: ExpandResult = []
+ for c in string:
+ result += expand_put_char(cursor_reg, scratch_reg, c)
+
+ return result
+
+def expand_cursor_to_line(cursor_reg: str, line: int) -> ExpandResult:
+ lbl_data = get_unique_name("cursor_to_line_data")
+ lbl_jmpover = get_unique_name("cursor_to_line_jmpover")
+ line_width = 64
+ return [
+ ["jpi", lbl_jmpover],
+ ["@label", lbl_data],
+ [f"text_mem + {line} * {line_width}"],
+ ["@label", lbl_jmpover],
+ ["ldi", lbl_data, cursor_reg],
+ ["ldr", cursor_reg, cursor_reg],
+ ]
+
+expansions: OpExpansionDict = {
+ "put_char": expand_put_char,
+ "cursor_to_line": expand_cursor_to_line,
+ "put_string": expand_put_string,
+} \ No newline at end of file
diff --git a/asm/text_mode.atk16 b/asm/text_mode.atk16
index ff84156..f4d84ae 100644
--- a/asm/text_mode.atk16
+++ b/asm/text_mode.atk16
@@ -1,61 +1,19 @@
@opt stack_pointer RF
@opt csr_scratch RH
@use ext_std:*
+@use ext_string_io:*
; bootstrap code (must be called to set up mandatory data)
; will jump to label main
@include bootstrap
@label main
- ldi vt_text_mem RA
- ldr RA RA
- ldi 8 RB ; letter H
- str RB RA
- addi RA 1 RA
- ldi 5 RB ; letter E
- str RB RA
- addi RA 1 RA
- ldi 12 RB ; letter L
- str RB RA
- addi RA 1 RA
- ldi 12 RB ; letter L
- str RB RA
- addi RA 1 RA
- ldi 15 RB ; letter O
- str RB RA
- addi RA 1 RA
- ldi 0 RB ; space
- str RB RA
- addi RA 1 RA
- ldi 3 RB ; letter C
- str RB RA
- addi RA 1 RA
- ldi 15 RB ; letter O
- str RB RA
- addi RA 1 RA
- ldi 18 RB ; letter R
- str RB RA
- addi RA 1 RA
- ldi 5 RB ; letter E
- str RB RA
- addi RA 1 RA
- ldi 3 RB ; letter C
- str RB RA
- addi RA 1 RA
- ldi 1 RB ; letter A
- str RB RA
- addi RA 1 RA
- ldi 13 RB ; letter M
- str RB RA
- addi RA 1 RA
- ldi 16 RB ; letter P
- str RB RA
- ldi offset RC
- ldr RC RC
- add RA RC RA
- ; ldi 20 RB ; letter A
- ; str RB RA
- ; addi RA 1 RA
+ cursor_to_line RA 1
+ put_char RA RB %SPACE
+ put_string RA RB HELLO CORECAMP
+ cursor_to_line RA 3
+ put_char RA RB %SPACE
+ put_string RA RB BY JAN
; set graphics mode to sprite mode
; set_graphics_mode gr_sprite_mode
@@ -63,6 +21,3 @@
@label loop
jpi loop
-
-@label offset
- 51