8 /* VGA text screen support. See [FREEVGA] for more information. */
10 /* Number of columns and rows on the text display. */
14 /* Current cursor position. (0,0) is in the upper left corner of
18 /* Attribute value for gray text on a black background. */
19 #define GRAY_ON_BLACK 0x07
21 /* Framebuffer. See [FREEVGA] under "VGA Text Mode Operation".
22 The character at (x,y) is fb[y][x][0].
23 The attribute at (x,y) is fb[y][x][1]. */
24 static uint8_t (*fb)[COL_CNT][2];
26 static void clear_row (size_t y);
27 static void cls (void);
28 static void newline (void);
29 static void move_cursor (void);
31 /* Initializes the VGA text display and clears the screen. */
39 /* Writes C to the VGA text display, interpreting control
40 characters in the conventional ways. */
64 cx = ROUND_UP (cx + 1, 8);
71 fb[cy][cx][1] = GRAY_ON_BLACK;
77 /* Update cursor position. */
81 /* Clears the screen and moves the cursor to the upper left. */
87 for (y = 0; y < ROW_CNT; y++)
94 /* Clears row Y to spaces. */
100 for (x = 0; x < COL_CNT; x++)
103 fb[y][x][1] = GRAY_ON_BLACK;
107 /* Advances the cursor to the first column in the next line on
108 the screen. If the cursor is already on the last line on the
109 screen, scrolls the screen upward one line. */
118 memmove (&fb[0], &fb[1], sizeof fb[0] * (ROW_CNT - 1));
119 clear_row (ROW_CNT - 1);
123 /* Moves the hardware cursor to (cx,cy). */
127 /* See [FREEVGA] under "Manipulating the Text-mode Cursor". */
128 uint16_t cp = cx + COL_CNT * cy;
129 outw (0x3d4, 0x0e | (cp & 0xff00));
130 outw (0x3d4, 0x0f | (cp << 8));