]> git.the-white-hart.net Git - vhdl/commitdiff
Update writer test program with cursor
authorrs <>
Mon, 13 Oct 2025 02:46:44 +0000 (21:46 -0500)
committerrs <>
Mon, 13 Oct 2025 02:46:44 +0000 (21:46 -0500)
projects/cpu_0/asm/vga_console.asm

index 8f5345b9c5d75884581505564dd2832b8b404373..b095eb380f4cb04dc63a35c1f253f1e467be7a6f 100644 (file)
@@ -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