1 #include "devices/vga.h"
6 #include "threads/io.h"
7 #include "threads/mmu.h"
9 /* VGA text screen support. See [FREEVGA] for more information. */
11 /* Number of columns and rows on the text display. */
15 /* Current cursor position. (0,0) is in the upper left corner of
19 /* Attribute value for gray text on a black background. */
20 #define GRAY_ON_BLACK 0x07
22 /* Framebuffer. See [FREEVGA] under "VGA Text Mode Operation".
23 The character at (x,y) is fb[y][x][0].
24 The attribute at (x,y) is fb[y][x][1]. */
25 static uint8_t (*fb)[COL_CNT][2];
27 static void clear_row (size_t y);
28 static void cls (void);
29 static void newline (void);
30 static void move_cursor (void);
32 /* Initializes the VGA text display and clears the screen. */
40 /* Writes C to the VGA text display, interpreting control
41 characters in the conventional ways. */
65 cx = ROUND_UP (cx + 1, 8);
72 fb[cy][cx][1] = GRAY_ON_BLACK;
78 /* Update cursor position. */
82 /* Clears the screen and moves the cursor to the upper left. */
88 for (y = 0; y < ROW_CNT; y++)
95 /* Clears row Y to spaces. */
101 for (x = 0; x < COL_CNT; x++)
104 fb[y][x][1] = GRAY_ON_BLACK;
108 /* Advances the cursor to the first column in the next line on
109 the screen. If the cursor is already on the last line on the
110 screen, scrolls the screen upward one line. */
119 memmove (&fb[0], &fb[1], sizeof fb[0] * (ROW_CNT - 1));
120 clear_row (ROW_CNT - 1);
124 /* Moves the hardware cursor to (cx,cy). */
128 /* See [FREEVGA] under "Manipulating the Text-mode Cursor". */
129 uint16_t cp = cx + COL_CNT * cy;
130 outw (0x3d4, 0x0e | (cp & 0xff00));
131 outw (0x3d4, 0x0f | (cp << 8));