( 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
;
( 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 +
.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:
( 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
;
vga_cursor_x=0x01000000
vga_cursor_y=0x01000001
-vga_cursor_loc=0x01000008
+vga_cursor_bx=0x01000002
+vga_cursor_by=0x01000003
vga_cursor_col=0x01000004