Teletype (console) screen text manipulation routines. More...
#include <core.h>#include <libc/stdio.h>#include <libc/string.h>#include <kernel/x86/cpu.h>#include <kernel/device/tty.h>Go to the source code of this file.
Data Structures | |
| struct | tty_t |
| Virtual console state. More... | |
Macros | |
| #define | CRTC_PORT_CMD 0x03d4 |
| Command port for CRT controller. More... | |
| #define | CRTC_PORT_DATA 0x03d5 |
| Data port for CRT controller. More... | |
| #define | CRTC_CMD_STARTADDR_HI 0x0c |
| Hi-byte of buffer start address. More... | |
| #define | CRTC_CMD_STARTADDR_LO 0x0d |
| Lo-byte of buffer start address. More... | |
| #define | CRTC_CMD_CURSORADDR_HI 0x0e |
| Hi-byte of cursor start address. More... | |
| #define | CRTC_CMD_CURSORADDR_LO 0x0f |
| Lo-byte of cursor start address. More... | |
| #define | SCREEN_ROWS 25 |
| #define | SCREEN_COLS 80 |
| #define | SCREEN_SIZE (SCREEN_ROWS * SCREEN_COLS) |
| #define | SCREEN_BUFFER 0x000b8000 |
Functions | |
| static uint16_t | color (textcolor_t fg, textcolor_t bg) |
| static void | update_buffer_offset () |
| static void | update_cursor () |
| void | tty_init () |
| Initialize all virtual consoles. More... | |
| void | tty_activate (int id) |
| Activate the requested virtual console. More... | |
| 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. More... | |
| void | tty_set_textcolor_fg (int id, textcolor_t fg) |
| Set the foreground color used to display text on the virtual console. More... | |
| void | tty_set_textcolor_bg (int id, textcolor_t bg) |
| Set the background color used to display text on the virtual console. More... | |
| textcolor_t | tty_get_textcolor_fg (int id) |
| Get the foreground color used to display text on the virtual console. More... | |
| textcolor_t | tty_get_textcolor_bg (int id) |
| Get the background color used to display text on the virtual console. More... | |
| void | tty_clear (int id) |
| Clear the virtual console screen's contents using the current text background color. More... | |
| void | tty_setpos (int id, screenpos_t pos) |
| Set the position of the cursor on the virtual console. More... | |
| void | tty_getpos (int id, screenpos_t *pos) |
| Get the current position of the cursor on the virtual console. More... | |
| static int | colorcode (char x, int orig) |
| static void | tty_printchar (tty_t *cons, const char **strptr) |
| 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 screen position. More... | |
| void | tty_printc (int id, char ch) |
| Output a single character to the virtual console using the console's current text color and screen position. More... | |
| 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 screen position. More... | |
Variables | |
| static tty_t | tty [MAX_TTYS] |
| All virtual consoles. More... | |
| static tty_t * | active_tty |
| The currently visible console. More... | |
Teletype (console) screen text manipulation routines.
Definition in file tty.c.
| struct tty |
| #define CRTC_PORT_CMD 0x03d4 |
Command port for CRT controller.
Definition at line 17 of file tty.c.
Referenced by update_buffer_offset(), and update_cursor().
| #define CRTC_PORT_DATA 0x03d5 |
Data port for CRT controller.
Definition at line 18 of file tty.c.
Referenced by update_buffer_offset(), and update_cursor().
| #define CRTC_CMD_STARTADDR_HI 0x0c |
Hi-byte of buffer start address.
Definition at line 21 of file tty.c.
Referenced by update_buffer_offset().
| #define CRTC_CMD_STARTADDR_LO 0x0d |
Lo-byte of buffer start address.
Definition at line 22 of file tty.c.
Referenced by update_buffer_offset().
| #define CRTC_CMD_CURSORADDR_HI 0x0e |
Hi-byte of cursor start address.
Definition at line 23 of file tty.c.
Referenced by update_cursor().
| #define CRTC_CMD_CURSORADDR_LO 0x0f |
Lo-byte of cursor start address.
Definition at line 24 of file tty.c.
Referenced by update_cursor().
| #define SCREEN_ROWS 25 |
Definition at line 27 of file tty.c.
Referenced by tty_printchar().
| #define SCREEN_COLS 80 |
Definition at line 28 of file tty.c.
Referenced by tty_printchar(), and update_cursor().
| #define SCREEN_SIZE (SCREEN_ROWS * SCREEN_COLS) |
Definition at line 29 of file tty.c.
Referenced by tty_clear(), and tty_printchar().
| #define SCREEN_BUFFER 0x000b8000 |
Definition at line 30 of file tty.c.
Referenced by tty_init(), update_buffer_offset(), and update_cursor().
|
inlinestatic |
Definition at line 49 of file tty.c.
Referenced by tty_init(), tty_set_textcolor(), tty_set_textcolor_bg(), and tty_set_textcolor_fg().
|
static |
Definition at line 55 of file tty.c.
Referenced by tty_activate(), tty_clear(), and tty_printchar().
|
static |
Definition at line 72 of file tty.c.
Referenced by tty_activate(), tty_clear(), tty_print(), tty_printc(), and tty_setpos().
| void tty_init | ( | ) |
| void tty_activate | ( | int | id | ) |
Activate the requested virtual console.
The virtual console's buffer is immediately displayed on the screen.
| [in] | id | Virtual tty id (0-3). |
Definition at line 107 of file tty.c.
Referenced by isr_fatal().
| 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.
| [in] | id | Virtual tty id (0-3). |
| [in] | fg | Foreground color. |
| [in] | bg | Background color. |
Definition at line 122 of file tty.c.
Referenced by isr_fatal(), and kmain().
| void tty_set_textcolor_fg | ( | int | id, |
| textcolor_t | fg | ||
| ) |
| void tty_set_textcolor_bg | ( | int | id, |
| textcolor_t | bg | ||
| ) |
| textcolor_t tty_get_textcolor_fg | ( | int | id | ) |
Get the foreground color used to display text on the virtual console.
| [in] | id | Virtual tty id (0-3). |
Definition at line 154 of file tty.c.
Referenced by tty_set_textcolor_bg().
| textcolor_t tty_get_textcolor_bg | ( | int | id | ) |
Get the background color used to display text on the virtual console.
| [in] | id | Virtual tty id (0-3). |
Definition at line 164 of file tty.c.
Referenced by tty_set_textcolor_fg().
| void tty_clear | ( | int | id | ) |
Clear the virtual console screen's contents using the current text background color.
| [in] | id | Virtual tty id (0-3). |
Definition at line 174 of file tty.c.
Referenced by isr_fatal(), and kmain().
| void tty_setpos | ( | int | id, |
| screenpos_t | pos | ||
| ) |
| void tty_getpos | ( | int | id, |
| screenpos_t * | pos | ||
| ) |
|
static |
Definition at line 218 of file tty.c.
Referenced by tty_printchar().
|
static |
Definition at line 240 of file tty.c.
Referenced by tty_print(), and tty_printc().
| 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 screen position.
A newline character (\n) causes the screen position to be updated as though a carriage return and line feed were performed.
To change the foreground color on the fly without having to call a console function, you may use the escape sequence \033[x], where x is a single character representing the foreground color to use for all following text. If x is a hexadecimal digit, then it represents one of the 16 textcolor codes. If x is '-', then it represents the console's original foreground color setting.
To change the background color on the fly, use the escape sequence \033{x}. The meaning of x is the same as with the foreground color escape sequence.
| [in] | id | Virtual tty id (0-3). |
| [in] | str | The null-terminated string to be printed. |
Definition at line 343 of file tty.c.
Referenced by cmd_display_apic(), cmd_display_help(), cmd_display_pcie(), cmd_switch_to_keycodes(), command_prompt(), dump_context(), isr_breakpoint(), kmain(), and tty_printf().
| void tty_printc | ( | int | id, |
| char | ch | ||
| ) |
Output a single character to the virtual console using the console's current text color and screen position.
See tty_print for further details.
| [in] | id | Virtual tty id (0-3). |
| [in] | ch | The character to be printed. |
Definition at line 357 of file tty.c.
Referenced by command_run().
| 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 screen position.
See tty_print for further details.
| [in] | id | Virtual tty id (0-3). |
| [in] | format | The null-terminated format string used to format the text to be printed. |
| [in] | ... | Variable arguments list to be initialized with va_start. |
Definition at line 372 of file tty.c.
Referenced by cmd_display_apic(), cmd_display_help(), cmd_display_pcie(), command_exec(), dump_context(), isr_fatal(), keycode_run(), and probe_function().
|
static |
The currently visible console.
Definition at line 46 of file tty.c.
Referenced by tty_activate(), tty_clear(), tty_init(), tty_print(), tty_printc(), tty_printchar(), tty_setpos(), update_buffer_offset(), and update_cursor().