aboutsummaryrefslogtreecommitdiffstats
path: root/resources/asm/monitor.atk16
diff options
context:
space:
mode:
authorJan Tuomi <jan@jantuomi.fi>2024-04-24 16:37:20 +0300
committerJan Tuomi <jan@jantuomi.fi>2024-04-24 16:37:20 +0300
commitab25aef8555476836ce6d329bb0cb8deca9ecba9 (patch)
tree3385f381f87183a9c37b276c1bcc254e8082c7c2 /resources/asm/monitor.atk16
parentfad7d9ff1b7f1cc736d775e03096a398a7e9719a (diff)
Add critical section logic to emu, develop monitor
Diffstat (limited to 'resources/asm/monitor.atk16')
-rw-r--r--resources/asm/monitor.atk1656
1 files changed, 44 insertions, 12 deletions
diff --git a/resources/asm/monitor.atk16 b/resources/asm/monitor.atk16
index 9a9484f..d3b8756 100644
--- a/resources/asm/monitor.atk16
+++ b/resources/asm/monitor.atk16
@@ -15,8 +15,9 @@
@data input_buffer_p 0xE801
@data input_cursor_p 0xE802
-@data title_string " »» ATK16 monitor v0.1 »»"
+@data title_string " »» ATK16 monitor v0.1 »»"
@data subtitle_string " Run [help] for a list of commands"
+@data prompt_string " > "
@label main
; initialize heap allocator
@@ -65,22 +66,33 @@
calli put_string
; END
+ m_newline RA RB
+ m_newline RA RB
+
+ ldi prompt_string RA
+ calli put_string
+
; loop forever
@label loop
- calli wait_for_input_newline
-
; BEGIN critical section
- ; disable_interrupts
- ; <work>
- ; enable_interrupts
- ; END
+ m_set_critical RA RB
+
+ calli is_newline_pressed
+ subi RG 1 RG ; if is_newline_pressed() == 1, then loop_newline_pressed
+ bri zero loop_newline_pressed
+ jpi loop_finally
+
+@label loop_newline_pressed
+ ; TODO
+ jpi loop_finally
+
+@label loop_finally
+ m_clear_critical RA RB
+ ; END critical section
jpi loop
;;; Subroutines
-; TODO: move the implementation body (between stack_stash and stack_restore) to
-; a macro so that it can be inlined without function call overhead when needed
-
@label newline
; move cursor to the beginning of the next line
; parameters: none
@@ -131,7 +143,7 @@
ldi 10 RB ; RB := newline character
@label wait_for_input_newline_loop
ldi input_cursor_p RA ; RA := data segment pointer
- ldr RA RA ; RA := &&char
+ ldr RA RA ; RA := 0xE802
ldr RA RA ; RA := &char
ldr RA RA ; RA := char
@@ -141,4 +153,24 @@
jpi wait_for_input_newline_loop
@label wait_for_input_newline_done
stack_restore RA RB
- return \ No newline at end of file
+ return
+
+@label is_newline_pressed
+ ; check if the last character in the input buffer is a newline
+ ; parameters: none
+ ; returns: RG = 1 if newline is pressed, 0 otherwise
+ stack_stash RA RB
+ ldi 10 RB ; RB := newline character
+
+ ldi input_cursor_p RA ; RA := data segment pointer
+ ldr RA RA ; RA := 0xE802
+ ldr RA RA ; RA := &char
+ ldr RA RA ; RA := char
+
+ ldi 1 RG ; RG := 1
+ sub RA RB RA ; if RA == newline, then return RG = 1
+ bri zero is_newline_pressed_done
+ ldi 0 RG ; else return RG = 0
+@label is_newline_pressed_done
+ stack_restore RA RB
+ return