From: John Tsiombikas Date: Sun, 13 Jun 2021 22:03:10 +0000 (+0300) Subject: console cursor positioning X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=commitdiff_plain;h=HEAD;p=3sys console cursor positioning --- diff --git a/sys1/kern/src/con.c b/sys1/kern/src/con.c index b110272..6627f95 100644 --- a/sys1/kern/src/con.c +++ b/sys1/kern/src/con.c @@ -13,6 +13,10 @@ static int tbuf_first, tbuf_last; static int curx, cury, scroll; +#define CURSTACK_SIZE 16 +static unsigned int savecur[CURSTACK_SIZE]; +static int savecur_top; + static void newline(void); @@ -29,6 +33,36 @@ void con_reset(void) curx = cury = scroll = 0; tbuf_first = tbuf_last = 0; memset(textbuf[0], 0, sizeof textbuf[0]); + + savecur_top = 0; +} + +void con_setcur(int x, int y) +{ + curx = x < 0 ? 0 : (x >= NCOLS ? NCOLS - 1 : x); + cury = y < 0 ? 0 : (y >= NROWS ? NROWS - 1 : y); +} + +void con_getcur(int *x, int *y) +{ + *x = curx; + *y = cury; +} + +void con_pushcur(void) +{ + if(savecur_top >= CURSTACK_SIZE) return; + + savecur[savecur_top++] = curx | (cury << 16); +} + +void con_popcur(void) +{ + if(savecur_top <= 0) return; + + savecur_top--; + curx = savecur[savecur_top] & 0xffff; + cury = savecur[savecur_top] >> 16; } void con_putchar(int c) diff --git a/sys1/kern/src/con.h b/sys1/kern/src/con.h index 5beb167..51cb544 100644 --- a/sys1/kern/src/con.h +++ b/sys1/kern/src/con.h @@ -6,7 +6,12 @@ void con_init(void); void con_reset(void); -#define con_color(fg, bg) vga_setcolor(fg, bg) +#define con_setcolor(fg, bg) vga_setcolor(fg, bg) + +void con_setcur(int x, int y); +void con_getcur(int *x, int *y); +void con_pushcur(void); +void con_popcur(void); void con_putchar(int c); diff --git a/sys1/kern/src/main.c b/sys1/kern/src/main.c index e45e929..3c93cab 100644 --- a/sys1/kern/src/main.c +++ b/sys1/kern/src/main.c @@ -19,11 +19,16 @@ void kmain(void) for(;;) { printf("line %d", line++); - for(i=0; i<65536 * 128; i++) { - if((i & 0x3ffff) == 0) { - con_putchar('.'); + con_pushcur(); + con_setcur(30, 0); + for(i=0; i<65536 * 300; i++) { + if((i & 0xfffff) == 0) { + con_setcolor(VGA_BRIGHT | (line & 7), VGA_BLACK); + con_putchar('>'); } } + con_setcolor(VGA_WHITE, VGA_BLACK); + con_popcur(); con_putchar('\n'); } }