X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?p=pintos-anon;a=blobdiff_plain;f=src%2Fdevices%2Fvga.c;h=8255747244e641d599d686fadecb167a9fc6b4f7;hp=949dd975eaec8da2ae0e34551b7ca23765a14792;hb=53a7f5d0952a4595f252247f5ee3d017468eb57e;hpb=e5439c03526c8e2881b0430ddbfe02812bee2e68 diff --git a/src/devices/vga.c b/src/devices/vga.c index 949dd97..8255747 100644 --- a/src/devices/vga.c +++ b/src/devices/vga.c @@ -29,13 +29,20 @@ static void clear_row (size_t y); static void cls (void); static void newline (void); static void move_cursor (void); +static void find_cursor (size_t *x, size_t *y); -/* Initializes the VGA text display and clears the screen. */ -void -vga_init (void) +/* Initializes the VGA text display. */ +static void +init (void) { - fb = ptov (0xb8000); - cls (); + /* Already initialized? */ + static bool inited; + if (!inited) + { + fb = ptov (0xb8000); + find_cursor (&cx, &cy); + inited = true; + } } /* Writes C to the VGA text display, interpreting control @@ -47,6 +54,8 @@ vga_putc (int c) that might write to the console. */ enum intr_level old_level = intr_disable (); + init (); + switch (c) { case '\n': @@ -138,3 +147,19 @@ move_cursor (void) outw (0x3d4, 0x0f | (cp << 8)); } +/* Reads the current hardware cursor position into (*X,*Y). */ +static void +find_cursor (size_t *x, size_t *y) +{ + /* See [FREEVGA] under "Manipulating the Text-mode Cursor". */ + uint16_t cp; + + outb (0x3d4, 0x0e); + cp = inb (0x3d5) << 8; + + outb (0x3d4, 0x0f); + cp |= inb (0x3d5); + + *x = cp % COL_CNT; + *y = cp / COL_CNT; +}