1 #include "devices/vga.h"
6 #include "threads/io.h"
7 #include "threads/interrupt.h"
8 #include "threads/vaddr.h"
10 /* VGA text screen support. See [FREEVGA] for more information. */
12 /* Number of columns and rows on the text display. */
16 /* Current cursor position. (0,0) is in the upper left corner of
20 /* Attribute value for gray text on a black background. */
21 #define GRAY_ON_BLACK 0x07
23 /* Framebuffer. See [FREEVGA] under "VGA Text Mode Operation".
24 The character at (x,y) is fb[y][x][0].
25 The attribute at (x,y) is fb[y][x][1]. */
26 static uint8_t (*fb)[COL_CNT][2];
28 static void clear_row (size_t y);
29 static void cls (void);
30 static void newline (void);
31 static void move_cursor (void);
32 static void find_cursor (size_t *x, size_t *y);
34 /* Initializes the VGA text display. */
38 /* Already initialized? */
43 find_cursor (&cx, &cy);
48 /* Writes C to the VGA text display, interpreting control
49 characters in the conventional ways. */
53 /* Disable interrupts to lock out interrupt handlers
54 that might write to the console. */
55 enum intr_level old_level = intr_disable ();
79 cx = ROUND_UP (cx + 1, 8);
86 fb[cy][cx][1] = GRAY_ON_BLACK;
92 /* Update cursor position. */
95 intr_set_level (old_level);
98 /* Clears the screen and moves the cursor to the upper left. */
104 for (y = 0; y < ROW_CNT; y++)
111 /* Clears row Y to spaces. */
117 for (x = 0; x < COL_CNT; x++)
120 fb[y][x][1] = GRAY_ON_BLACK;
124 /* Advances the cursor to the first column in the next line on
125 the screen. If the cursor is already on the last line on the
126 screen, scrolls the screen upward one line. */
135 memmove (&fb[0], &fb[1], sizeof fb[0] * (ROW_CNT - 1));
136 clear_row (ROW_CNT - 1);
140 /* Moves the hardware cursor to (cx,cy). */
144 /* See [FREEVGA] under "Manipulating the Text-mode Cursor". */
145 uint16_t cp = cx + COL_CNT * cy;
146 outw (0x3d4, 0x0e | (cp & 0xff00));
147 outw (0x3d4, 0x0f | (cp << 8));
150 /* Reads the current hardware cursor position into (*X,*Y). */
152 find_cursor (size_t *x, size_t *y)
154 /* See [FREEVGA] under "Manipulating the Text-mode Cursor". */
158 cp = inb (0x3d5) << 8;