From 8850b82644978468c2c7d13a531b4ca1b73cef4f Mon Sep 17 00:00:00 2001 From: rs <> Date: Sun, 12 Oct 2025 21:46:44 -0500 Subject: [PATCH] Update writer test program with cursor --- projects/cpu_0/asm/vga_console.asm | 82 ++++++++++++++++++++++++++---- 1 file changed, 73 insertions(+), 9 deletions(-) diff --git a/projects/cpu_0/asm/vga_console.asm b/projects/cpu_0/asm/vga_console.asm index 8f5345b..b095eb3 100644 --- a/projects/cpu_0/asm/vga_console.asm +++ b/projects/cpu_0/asm/vga_console.asm @@ -23,10 +23,13 @@ vga_reset: ( Initialize console ) #8 0x00i8 #32 vga_cursor_x !8 drop ( Set the cursor to the beginning of the screen ) #8 0x00i8 #32 vga_cursor_y !8 drop + #8 0x00i8 #32 vga_cursor_bx !8 drop + #8 0x00i8 #32 vga_cursor_by !8 drop #8 0x3bi8 #32 vga_cursor_col !8 drop ( Set the cursor color to light blue on dark blue ) ( Clear screen ) #32 vga_scr #32 0x00003b20i32 #32 4800i32 call mem_set_16 + call vga_draw_cursor ; @@ -35,11 +38,11 @@ vga_reset: ( c -- ) vga_console_putc: dup #8 0x20i8 - jp .ctrl - #32 vga_scr #32 vga_cursor_loc @32 + dup >r - !8 drop + #32 vga_cursor_y @8 #8 80i8 call mul_uu #32 vga_cursor_x @8 + shl #32 vga_scr + >r + r@ !8 drop #32 vga_cursor_col @8 r> #8 1i8 + !8 drop - #32 vga_cursor_loc dup @32 #8 0x02i8 + swap !32 drop - ; + #32 vga_cursor_x @8 #8 1i8 + #32 vga_cursor_x !8 drop + call vga_update_cursor ; .ctrl: dup + dup + #32 .ctrl_lut + @@ -47,15 +50,27 @@ vga_console_putc: .ctrl_nop: ; .ctrl_bel: ; .ctrl_bs: - ; + #32 vga_cursor_x @8 #8 1i8 swap - #32 vga_cursor_x !8 drop + call vga_update_cursor ; .ctrl_tab: - ; + #32 vga_cursor_x @8 #8 8i8 + #8 0x7i8 ~ & #32 vga_cursor_x !8 drop + call vga_update_cursor ; .ctrl_lf: + #32 vga_cursor_y @8 #8 1i8 + #32 vga_cursor_y !8 drop ( Fall through to CR ) .ctrl_cr: - ; + #8 0i8 #32 vga_cursor_x !8 drop + call vga_update_cursor ; .ctrl_ff: - ; + ( Clear the screen ) + #32 vga_scr + #32 vga_cursor_col @8 shl shl shl shl shl shl shl shl #8 0x20i8 | + #32 4800i32 + call mem_set_16 + + ( Reset the cursor ) + #8 0i8 #32 vga_cursor_x !8 #32 vga_cursor_y !8 drop + call vga_update_cursor ; align .ctrl_lut: @@ -94,7 +109,55 @@ align ( Wrap cursor and scroll screen ) +( -- ) vga_update_cursor: + call vga_undraw_cursor + + ( If x coordinate off the left, put it back at zero ) + #32 vga_cursor_x @8 #8 0x80i8 & jz .leftgood + #8 0i8 #32 vga_cursor_x !8 drop +.leftgood: + + ( If x coordinate off the right, wrap it and move to the next line ) + #32 vga_cursor_x @8 #8 80i8 swap - dup jn .rightgood + #32 vga_cursor_x !8 drop + #32 vga_cursor_y @8 #8 1i8 + #32 vga_cursor_y !8 +.rightgood: drop + + ( If y coordinate off the top, put it back at zero ) + #32 vga_cursor_y @8 #8 0x80i8 & jz .topgood + #8 0i8 #32 vga_cursor_y !8 drop +.topgood: + + ( If y coordinate off the bottom, scroll and pull it back ) + #32 vga_cursor_y @8 #8 60i8 swap - jn .botgood + #32 vga_scr + #32 vga_scr #8 80i8 shl + + #32 4800i32 #8 80i8 shl - + call mem_move + #32 vga_cursor_y @8 #8 1i8 swap - #32 vga_cursor_y !8 drop +.botgood: + + call vga_draw_cursor ; + + +( -- ) +vga_undraw_cursor: + #32 vga_cursor_col @8 + #32 vga_cursor_by @8 #8 80i8 call mul_uu + #32 vga_cursor_bx @8 + shl #8 1i8 + + #32 vga_scr + + !8 drop + ; + + +( -- ) +vga_draw_cursor: + #32 vga_cursor_y @8 #32 vga_cursor_by !8 #8 80i8 call mul_uu + #32 vga_cursor_x @8 #32 vga_cursor_bx !8 + shl #8 1i8 + + #32 vga_scr + >r + r@ @8 dup >r lsr lsr lsr lsr r> #8 0x0fi8 & shl shl shl shl | + r> !8 drop ; @@ -115,5 +178,6 @@ vga_console_puts: vga_cursor_x=0x01000000 vga_cursor_y=0x01000001 -vga_cursor_loc=0x01000008 +vga_cursor_bx=0x01000002 +vga_cursor_by=0x01000003 vga_cursor_col=0x01000004 -- 2.43.0