aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--atk16_asm/asm_ops.py10
-rw-r--r--atk16_asm/builtin_asm/std_bump_alloc.atk162
-rw-r--r--atk16_asm/builtin_asm/std_math.atk162
-rw-r--r--atk16_asm/builtin_asm/std_mem.atk164
-rw-r--r--atk16_asm/builtin_asm/std_term.atk163
-rw-r--r--atk16_projects/monitor/monitor.atk168
6 files changed, 25 insertions, 4 deletions
diff --git a/atk16_asm/asm_ops.py b/atk16_asm/asm_ops.py
index 65cf0da..1da8cf0 100644
--- a/atk16_asm/asm_ops.py
+++ b/atk16_asm/asm_ops.py
@@ -346,6 +346,16 @@ def expand_calli(addr_imm: int | str) -> ExpandResult:
]
@register_macro
+def expand_call(label: str, clobber_r = "RF") -> ExpandResult:
+ """Convenience wrapper for ldi + ldr + callr, clobbers RF by default."""
+ pointer_label = f"{label}_p"
+ return [
+ ["ldi", pointer_label, clobber_r],
+ ["ldr", clobber_r, clobber_r],
+ *expand_callr(clobber_r),
+ ]
+
+@register_macro
def expand_return() -> ExpandResult:
return [
["str", "RG", "SP"], # store returned value on stack but don't increment SP
diff --git a/atk16_asm/builtin_asm/std_bump_alloc.atk16 b/atk16_asm/builtin_asm/std_bump_alloc.atk16
index 32516bc..28eefbc 100644
--- a/atk16_asm/builtin_asm/std_bump_alloc.atk16
+++ b/atk16_asm/builtin_asm/std_bump_alloc.atk16
@@ -24,6 +24,7 @@
@data bump_next_p heap_segment
@data bump_arena_start ${heap_segment - 1}
+@data bump_reset_p bump_reset
@label bump_reset
; reset the heap to its initial state (zero allocated blocks)
; can be used to initialize the bump allocator
@@ -42,6 +43,7 @@
stack_restore RA RB
return
+@data bump_alloc_p bump_alloc
@label bump_alloc
; allocate a block of memory from the heap, checking for overlap with the stack
; parameters: RA = n of words to allocate
diff --git a/atk16_asm/builtin_asm/std_math.atk16 b/atk16_asm/builtin_asm/std_math.atk16
index 6544b32..10b90c3 100644
--- a/atk16_asm/builtin_asm/std_math.atk16
+++ b/atk16_asm/builtin_asm/std_math.atk16
@@ -1,6 +1,7 @@
@data mul_sign_mask ${2 ** 15}
@data mul_not_mask 0xFFFF
+@data mul_p mul
@label mul
; multiply a signed (a) and a signed (b)
; parameters RA = a
@@ -71,6 +72,7 @@
; Calling convention is that arguments are in registers RA..RG (max 7 arguments since RH = SP)
; and the return value is in RG (note: overwriting arg in RG)
+@data fact_p fact
@label fact
; parameters RA = n
; return RG = factorial(n)
diff --git a/atk16_asm/builtin_asm/std_mem.atk16 b/atk16_asm/builtin_asm/std_mem.atk16
index 5855879..26aac45 100644
--- a/atk16_asm/builtin_asm/std_mem.atk16
+++ b/atk16_asm/builtin_asm/std_mem.atk16
@@ -1,3 +1,4 @@
+@data memset_p memset
@label memset
; sets a specified number of words in memory to a specified value
; parameters: RA = offset (offset in memory to start at)
@@ -19,6 +20,7 @@
stack_restore RD RE
return
+@data memcopy_p memcopy
@label memcopy
; copies a specified number of words from one location in memory to another
; parameters: RA = src (source address)
@@ -42,6 +44,7 @@
stack_restore RD RE RF
return
+@data memcompare_p memcompare
@label memcompare
; compares two blocks of memory
; parameters: RA = src1 (source address 1)
@@ -77,6 +80,7 @@
return
+@data string_compare_p string_compare
@label string_compare
; compares two strings
; parameters: RA = str1 (source address 1)
diff --git a/atk16_asm/builtin_asm/std_term.atk16 b/atk16_asm/builtin_asm/std_term.atk16
index b0c9f4f..9a7af5f 100644
--- a/atk16_asm/builtin_asm/std_term.atk16
+++ b/atk16_asm/builtin_asm/std_term.atk16
@@ -1,3 +1,4 @@
+@data log_term_char_p log_term_char
@label log_term_char
; send a character to the terminal
; parameters: RA = character code
@@ -11,7 +12,7 @@
return
-
+@data log_term_string_p log_term_string
@label log_term_string
; send a string to the terminal
; parameters: RA = address of string allocation
diff --git a/atk16_projects/monitor/monitor.atk16 b/atk16_projects/monitor/monitor.atk16
index 65e83d1..1b08ff0 100644
--- a/atk16_projects/monitor/monitor.atk16
+++ b/atk16_projects/monitor/monitor.atk16
@@ -2,7 +2,6 @@
@include %bootstrap
@include %std_mem
-@include %std_term
@include %std_bump_alloc
; Constants
@@ -64,7 +63,8 @@
; BEGIN put_string(title_string)
ldi title_string RA
- calli put_string
+@label debug
+ call put_string
; END
m_newline RA RB
@@ -120,7 +120,6 @@
ldr RA RA
ldr RA RA
-@data put_string_p put_string
ldi put_string_p RB
ldr RB RB
callr RB
@@ -251,6 +250,7 @@
;;; Subroutines
+@data newline_p newline
@label newline
; move cursor to the beginning of the next line
; parameters: none
@@ -261,6 +261,7 @@
stack_restore RA RB
return
+@data put_char_p put_char
@label put_char
; put a character at the current cursor position
; parameters: RA = character to put
@@ -271,6 +272,7 @@
stack_restore RB RC
return
+@data put_string_p put_string
@label put_string
; put a string at the current cursor position
; parameters: RA = string_p