17 #define CRTC_PORT_CMD 0x03d4 18 #define CRTC_PORT_DATA 0x03d5
21 #define CRTC_CMD_STARTADDR_HI 0x0c 22 #define CRTC_CMD_STARTADDR_LO 0x0d
23 #define CRTC_CMD_CURSORADDR_HI 0x0e
24 #define CRTC_CMD_CURSORADDR_LO 0x0f
27 #define SCREEN_ROWS 25 28 #define SCREEN_COLS 80 29 #define SCREEN_SIZE (SCREEN_ROWS * SCREEN_COLS) 30 #define SCREEN_BUFFER 0x000b8000 43 typedef struct tty tty_t;
48 static inline uint16_t
51 return (uint16_t)bg << 12 | (uint16_t)fg << 8;
93 for (
int id = 0;
id <
MAX_TTYS;
id++) {
200 int diff = (int)pos.y - (
int)
tty[id].
pos.y;
222 if ((code >=
'0') && (code <=
'9')) {
225 else if ((code >=
'a') && (code <=
'f')) {
226 return code -
'a' + 10;
228 else if ((code >=
'A') && (code <=
'F')) {
229 return code -
'A' + 10;
231 else if (code ==
'-') {
242 bool linefeed =
false;
244 const char *str = *strptr;
254 else if (ch ==
'\033') {
255 if ((str[1] ==
'[') && str[2] && (str[3] ==
']')) {
256 int code =
colorcode(str[2], (cons->textcolor_orig >> 8) & 0x0f);
258 cons->textcolor = (cons->textcolor & 0xf000) |
259 (uint16_t)(code << 8);
263 else if ((str[1] ==
'{') && str[2] && (str[3] ==
'}')) {
264 int code =
colorcode(str[2], (cons->textcolor_orig >> 12));
266 cons->textcolor = (cons->textcolor & 0x0f00) |
267 (uint16_t)(code << 12);
273 else if (ch ==
'\b') {
274 if (cons->pos.x > 0) {
275 int offset = cons->ybuf *
SCREEN_COLS + --cons->pos.x;
276 cons->screen[offset] = cons->textcolor |
' ';
281 uint16_t value = cons->textcolor | ch;
284 int offset = cons->ybuf *
SCREEN_COLS + cons->pos.x;
287 cons->screen[offset] = value;
327 cons->textcolor |
' ',
331 cons->tlcorner = cons->screen + (cons->ybuf + 1) *
SCREEN_COLS -
348 tty_t *cons = &
tty[id];
362 const char str[2] = { ch, 0 };
363 const char *ptr = str;
364 tty_t *cons = &
tty[id];
378 va_start(args, format);
379 char buffer[8 * 1024];
380 int result =
vsnprintf(buffer,
sizeof(buffer), format, args);
#define MAX_TTYS
The number of available virtual consoles.
textcolor
Color values used for tty text.
__forceinline uint8_t io_inb(uint16_t port)
__forceinline void io_outb(uint16_t port, uint8_t value)
String and memory operations.
textcolor_t tty_get_textcolor_fg(int id)
Get the foreground color used to display text on the virtual console.
void tty_set_textcolor(int id, textcolor_t fg, textcolor_t bg)
Set the foreground and background colors used to display text on the virtual console.
static uint16_t color(textcolor_t fg, textcolor_t bg)
void tty_getpos(int id, screenpos_t *pos)
Get the current position of the cursor on the virtual console.
void tty_set_textcolor_bg(int id, textcolor_t bg)
Set the background color used to display text on the virtual console.
uint16_t textcolor
Current fg/bg color (shifted).
int vsnprintf(char *buf, size_t n, const char *format, va_list arg)
Compose a printf-formatted string into the target buffer using a variable argument list...
uint16_t textcolor_orig
Original, non-override text color.
uint8_t ybuf
Virtual buffer y position.
uint16_t * tlcorner
Points to char in top-left corner.
enum textcolor textcolor_t
void tty_activate(int id)
Activate the requested virtual console.
#define CRTC_PORT_CMD
Command port for CRT controller.
void tty_init()
Initialize all virtual consoles.
static void tty_printchar(tty_t *cons, const char **strptr)
#define CRTC_CMD_STARTADDR_HI
Hi-byte of buffer start address.
textcolor_t tty_get_textcolor_bg(int id)
Get the background color used to display text on the virtual console.
#define CRTC_CMD_CURSORADDR_LO
Lo-byte of cursor start address.
#define CRTC_PORT_DATA
Data port for CRT controller.
static int colorcode(char x, int orig)
static tty_t * active_tty
The currently visible console.
x86 CPU-specific function implementations.
void tty_print(int id, const char *str)
Output a null-terminated string to the virtual console using the console's current text color and scr...
static void update_cursor()
screenpos_t pos
Current screen position.
int tty_printf(int id, const char *format,...)
Output a printf-formatted string to the virtual console using the console's current text color and sc...
Teletype (console) screen text manipulation routines.
#define CRTC_CMD_CURSORADDR_HI
Hi-byte of cursor start address.
void tty_set_textcolor_fg(int id, textcolor_t fg)
Set the foreground color used to display text on the virtual console.
static void update_buffer_offset()
void * memsetw(void *dst, int w, size_t num)
Fill a region of memory with a single 16-bit word value.
void tty_clear(int id)
Clear the virtual console screen's contents using the current text background color.
void tty_printc(int id, char ch)
Output a single character to the virtual console using the console's current text color and screen po...
#define CRTC_CMD_STARTADDR_LO
Lo-byte of buffer start address.
uint16_t * screen
Virtual screen buffer for 50 rows.
void tty_setpos(int id, screenpos_t pos)
Set the position of the cursor on the virtual console.
void * memcpy(void *dst, const void *src, size_t num)
Copy bytes from one memory region to another.