console cursor positioning
[3sys] / sys1 / kern / src / con.c
index b110272..6627f95 100644 (file)
@@ -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)