diff options
| author | Jan Tuomi <jan@jantuomi.fi> | 2024-05-17 00:29:21 +0300 |
|---|---|---|
| committer | Jan Tuomi <jan@jantuomi.fi> | 2024-05-17 00:29:21 +0300 |
| commit | 0611d3d4b9b3644c1029440b9cccb9097184a569 (patch) | |
| tree | 2af44724c81536fcab13b75e1edfa0d68677990d | |
| parent | 51980405aa4c574845854c14bf31142ee5558f99 (diff) | |
Add help command eval
| -rw-r--r-- | atk16_asm/builtin_asm/std_mem.atk16 | 62 | ||||
| -rw-r--r-- | atk16_projects/monitor/monitor.atk16 | 64 |
2 files changed, 112 insertions, 14 deletions
diff --git a/atk16_asm/builtin_asm/std_mem.atk16 b/atk16_asm/builtin_asm/std_mem.atk16 index 43d00ea..5855879 100644 --- a/atk16_asm/builtin_asm/std_mem.atk16 +++ b/atk16_asm/builtin_asm/std_mem.atk16 @@ -41,3 +41,65 @@ @label memcopy_done stack_restore RD RE RF return + +@label memcompare + ; compares two blocks of memory + ; parameters: RA = src1 (source address 1) + ; RB = src2 (source address 2) + ; RC = n (number of words to compare) + ; returns: RG = 1 if the blocks are equal, 0 otherwise + stack_stash RA RB RC RD RE + ldi 0 RG ; RD := 0 (result) + +@label memcompare_loop + subi RC 0 RC + bri zero memcompare_result_equal ; exit the loop + + ldr RA RD ; RD := left value + ldr RB RE ; RE := right value + + sub RD RE RD ; RD := left - right + bri zero memcompare_continue ; if left == right, continue the loop + + jpi memcompare_end ; if left != right, exit the loop + +@label memcompare_continue + inc RA ; RA := RA + 1 + inc RB ; RB := RB + 1 + dec RC ; RC := RC - 1 + jpi memcompare_loop ; repeat the loop + +@label memcompare_result_equal + ldi 1 RG ; RG := 1 (result) + +@label memcompare_end + stack_restore RA RB RC RD RE + return + + +@label string_compare + ; compares two strings + ; parameters: RA = str1 (source address 1) + ; RB = str2 (source address 2) + ; returns: RG = 1 if the strings are equal, 0 otherwise + + stack_stash RA RB RC RD RE + ldi 0 RG ; RD := 0 (result) + + ldr RA RD ; RD := left string length + ldr RB RE ; RE := right string length + + sub RD RE RD ; RD := left length - right length + bri zero string_compare_same_length ; if equal length, use memcompare + + jpi string_compare_end ; else if different length, exit + +@label string_compare_same_length + inc RA + inc RB + mov RE RC + calli memcompare ; return value implicitly returned in RG + +@label string_compare_end + stack_restore RA RB RC RD RE + return diff --git a/atk16_projects/monitor/monitor.atk16 b/atk16_projects/monitor/monitor.atk16 index 4ec1205..65e83d1 100644 --- a/atk16_projects/monitor/monitor.atk16 +++ b/atk16_projects/monitor/monitor.atk16 @@ -13,12 +13,12 @@ ; 0xE800 - 0xEFFF: sprite buffer space that is unused in this program @data text_cursor_p 0xE800 @data input_string_p 0xE801 -@data input_cursor_p 0xE802 -@data input_entered_bool 0xE803 +@data input_entered_bool 0xE802 @data title_string " »» ATK16 monitor v0.1 »»" @data subtitle_string " Run [help] for a list of commands" @data prompt_string " > " +@data help_cmd_string "help" @label main ; initialize heap allocator @@ -41,12 +41,6 @@ str RG RA ; END - ; BEGIN input_cursor_p = input_string_p - ldi input_cursor_p RA - ldr RA RA - str RG RA - ; END - ; BEGIN input_entered_bool = 0 ldi input_entered_bool RA ldr RA RA @@ -80,8 +74,15 @@ calli put_string ; END - m_newline RA RB - m_newline RA RB + ; BEGIN print two newlines + ldi text_cursor_p RA + ldr RA RA + ldr RA RB + slri RB 6 RB + addi RB 2 RB + slli RB 6 RB + str RB RA + ; END ldi prompt_string RA calli put_string @@ -101,7 +102,17 @@ ldi 0 RB ; else, run this branch and set input_entered_bool = 0 str RB RA -@data eval_output_string "command received: " + ldi help_cmd_string RA + ldi input_string_p RB + ldr RB RB + ldr RB RB + + calli string_compare + subi RG 1 RG + bri zero loop_input_cmd_help + +@label loop_input_not_recognized +@data eval_output_string "Unknown command: " ldi eval_output_string RA calli put_string @@ -109,12 +120,26 @@ ldr RA RA ldr RA RA - calli put_string +@data put_string_p put_string + ldi put_string_p RB + ldr RB RB + callr RB + jpi loop_input_print_newline + +@label loop_input_cmd_help +@data help_cmd_output_0 "Available commands:\n help display this help message" + ldi help_cmd_output_0 RA + ldi put_string_p RB + ldr RB RB + callr RB +@label loop_input_print_newline m_newline RA RB ldi prompt_string RA - calli put_string + ldi put_string_p RB + ldr RB RB + callr RB @label loop_finally m_clear_critical RA RB @@ -142,7 +167,9 @@ subi RB 5 RB subi RB 3 RB - ldi keyboard_isr_backspace RD +@data keyboard_isr_backspace_p keyboard_isr_backspace + ldi keyboard_isr_backspace_p RD + ldr RD RD brr zero RD ldi row_index_mask RD ; else code is not special; write it to text buffer @@ -257,8 +284,17 @@ bri zero put_string_done ; i.e. no more characters to put ldr RC RA ; RA := character to put + subi RA 5 RD + subi RD 5 RD + bri zero put_string_newline + m_put_char RA RD RE ; inline the put_char subroutine to avoid function call overhead + jpi put_string_continue + +@label put_string_newline + m_newline RD RE +@label put_string_continue inc RC subi RB 1 RB jpi put_string_loop |
