1 #include "devices/vga.h"
6 #include "devices/speaker.h"
7 #include "threads/io.h"
8 #include "threads/interrupt.h"
9 #include "threads/vaddr.h"
11 /* VGA text screen support. See [FREEVGA] for more information. */
13 /* Number of columns and rows on the text display. */
17 /* Current cursor position. (0,0) is in the upper left corner of
21 /* Attribute value for gray text on a black background. */
22 #define GRAY_ON_BLACK 0x07
24 /* Framebuffer. See [FREEVGA] under "VGA Text Mode Operation".
25 The character at (x,y) is fb[y][x][0].
26 The attribute at (x,y) is fb[y][x][1]. */
27 static uint8_t (*fb)[COL_CNT][2];
29 static void clear_row (size_t y);
30 static void cls (void);
31 static void newline (void);
32 static void move_cursor (void);
33 static void find_cursor (size_t *x, size_t *y);
35 /* Initializes the VGA text display. */
39 /* Already initialized? */
44 find_cursor (&cx, &cy);
49 /* Writes C to the VGA text display, interpreting control
50 characters in the conventional ways. */
54 /* Disable interrupts to lock out interrupt handlers
55 that might write to the console. */
56 enum intr_level old_level = intr_disable ();
80 cx = ROUND_UP (cx + 1, 8);
86 intr_set_level (old_level);
93 fb[cy][cx][1] = GRAY_ON_BLACK;
99 /* Update cursor position. */
102 intr_set_level (old_level);
105 /* Clears the screen and moves the cursor to the upper left. */
111 for (y = 0; y < ROW_CNT; y++)
118 /* Clears row Y to spaces. */
124 for (x = 0; x < COL_CNT; x++)
127 fb[y][x][1] = GRAY_ON_BLACK;
131 /* Advances the cursor to the first column in the next line on
132 the screen. If the cursor is already on the last line on the
133 screen, scrolls the screen upward one line. */
142 memmove (&fb[0], &fb[1], sizeof fb[0] * (ROW_CNT - 1));
143 clear_row (ROW_CNT - 1);
147 /* Moves the hardware cursor to (cx,cy). */
151 /* See [FREEVGA] under "Manipulating the Text-mode Cursor". */
152 uint16_t cp = cx + COL_CNT * cy;
153 outw (0x3d4, 0x0e | (cp & 0xff00));
154 outw (0x3d4, 0x0f | (cp << 8));
157 /* Reads the current hardware cursor position into (*X,*Y). */
159 find_cursor (size_t *x, size_t *y)
161 /* See [FREEVGA] under "Manipulating the Text-mode Cursor". */
165 cp = inb (0x3d5) << 8;