From 8b977f9f9ebcb6df8237af64d8dd178e2415c955 Mon Sep 17 00:00:00 2001 From: Ry Date: Mon, 21 Nov 2022 21:43:58 -0800 Subject: [PATCH] terminal: Add various "control characters" --- terminal/stream.asm | 2 +- terminal/text.asm | 61 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 61 insertions(+), 2 deletions(-) diff --git a/terminal/stream.asm b/terminal/stream.asm index 2c0bf2a..afcd796 100644 --- a/terminal/stream.asm +++ b/terminal/stream.asm @@ -4,7 +4,7 @@ ; inputs: ; r0: pointer to ASCII character stream_write_to_terminal: - mov r0, [r0] + movz.8 r0, [r0] jmp print_character_to_terminal stream_get_input: diff --git a/terminal/text.asm b/terminal/text.asm index e5c930d..6da9208 100644 --- a/terminal/text.asm +++ b/terminal/text.asm @@ -8,10 +8,20 @@ const BACKGROUND_COLOR: 0xFF000000 ; print a single character to the terminal ; inputs: -; r0: ASCII character +; r0: ASCII character or control character ; outputs: ; none print_character_to_terminal: + ; if we're in a control state, or the char has the highest bit set + ; then handle it as a control character + ; allow character 0x8A (the block cursor itself) to pass through + cmp.8 r0, 0x8A + ifz jmp print_character_to_terminal_allow + cmp.8 [terminal_state], 0 + ifnz jmp handle_control_character + bts r0, 7 + ifnz jmp handle_control_character +print_character_to_terminal_allow: push r0 push r1 push r2 @@ -69,6 +79,51 @@ print_character_to_terminal_end: pop r0 ret +; control character state machine +; inputs: +; r0: control character or parameter +; outputs: +; none +handle_control_character: + cmp.8 [terminal_state], 0 ; got control character + ifz mov.8 [terminal_control_char], r0 + ifz mov.8 [terminal_state], 1 + ifz ret + cmp.8 [terminal_state], 1 ; got first parameter + ifz mov.8 [terminal_control_parameter_1], r0 + ifz mov.8 [terminal_state], 2 + ifz ret + cmp.8 [terminal_state], 2 ; got second parameter, now execute + ifz mov.8 [terminal_control_parameter_2], r0 + ifz mov.8 [terminal_state], 0 + + ; fill terminal + cmp.8 [terminal_control_char], 0xF0 + ifz jmp handle_control_character_fill_term + + ; set cursor position + cmp.8 [terminal_control_char], 0xF1 + ifz jmp handle_control_character_set_cursor_pos + + ret +handle_control_character_fill_term: + push r0 + push r31 + mov r0, terminal_text_buf + mov r31, 1000 +handle_control_character_fill_term_loop: + mov.8 [r0], [terminal_control_parameter_1] + inc r0 + loop handle_control_character_fill_term_loop + call redraw_terminal + pop r31 + pop r0 + ret +handle_control_character_set_cursor_pos: + mov.8 [terminal_x], [terminal_control_parameter_1] + mov.8 [terminal_y], [terminal_control_parameter_2] + ret + ; scroll the terminal ; inputs: ; none @@ -225,3 +280,7 @@ redraw_terminal_line_loop_x: terminal_x: data.8 0 terminal_y: data.8 0 terminal_text_buf: data.fill 0, 1000 ; 40x25 = 1000 bytes +terminal_state: data.8 0 ; 0: normal, 1: awaiting first control parameter, 2: awaiting second control parameter +terminal_control_char: data.8 0 +terminal_control_parameter_1: data.8 0 +terminal_control_parameter_2: data.8 0