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);
33 /* Initializes the VGA text display and clears the screen. */
41 /* Writes C to the VGA text display, interpreting control
42 characters in the conventional ways. */
46 /* Disable interrupts to lock out interrupt handlers
47 that might write to the console. */
48 enum intr_level old_level = intr_disable ();
70 cx = ROUND_UP (cx + 1, 8);
77 fb[cy][cx][1] = GRAY_ON_BLACK;
83 /* Update cursor position. */
86 intr_set_level (old_level);
89 /* Clears the screen and moves the cursor to the upper left. */
95 for (y = 0; y < ROW_CNT; y++)
102 /* Clears row Y to spaces. */
108 for (x = 0; x < COL_CNT; x++)
111 fb[y][x][1] = GRAY_ON_BLACK;
115 /* Advances the cursor to the first column in the next line on
116 the screen. If the cursor is already on the last line on the
117 screen, scrolls the screen upward one line. */
126 memmove (&fb[0], &fb[1], sizeof fb[0] * (ROW_CNT - 1));
127 clear_row (ROW_CNT - 1);
131 /* Moves the hardware cursor to (cx,cy). */
135 /* See [FREEVGA] under "Manipulating the Text-mode Cursor". */
136 uint16_t cp = cx + COL_CNT * cy;
137 outw (0x3d4, 0x0e | (cp & 0xff00));
138 outw (0x3d4, 0x0f | (cp << 8));