/* write a null terminated string at the current cursor position. handles \n for newlines. */ void terminal_write(char *string) { for (size_t index = 0; string[index] != 0; index++) { if (string[index] == '\n') { vga_move_cursor(0, ++cursor_row); } else { VGA_MEMORY[vga_cursor_memory_index()] = vga_character(string[index]); vga_move_cursor(++cursor_column, cursor_row); } } }
/* clear the terminal and move the cursor back to the top left */ void terminal_clear() { for (uint8_t row = 0; row < VGA_HEIGHT; row++) { for (uint8_t column = 0; column < VGA_WIDTH; column++) { VGA_MEMORY[row * VGA_WIDTH + column] = vga_character(' '); } } vga_move_cursor(0, 0); }
static void vga_clear(void) { memset(vga.base, 0, VGA_ROWS * VGA_COLUMNS * 2); vga_move_cursor(0, 0); }
int vga_putchar(int c) { uint_t row; uint_t column; int print_action; int post_action; int move_action; if (!initialized) { return EOF; } /* Retrieve the old cursor position */ row = vga.row; column = vga.column; print_action = 1; move_action = 1; post_action = 1; /* Pre-print action */ switch (c) { case '\a': /* Bell */ /* Missing */ break; case '\b': /* Back Space */ column = column - 1; c = ' '; print_action = 1; post_action = 0; break; case '\t': /* Tab */ column = column + 8; print_action = 0; post_action = 0; break; case '\v': /* Vertical Tab ? */ /* missing */ break; case '\n': /* New Line */ row = row + 1; column = 0; print_action = 0; post_action = 0; break; case '\f': /* Form Feed */ row = row + 1; print_action = 0; post_action = 0; break; case '\r': /* Line Feed */ column = 0; print_action = 0; post_action = 0; break; default: print_action = isprint(c); post_action = print_action; break; } check_bounds(&column, &row); /* Print */ if (print_action) { vga_putc(c, row, column); } /* Post-print action */ if (post_action) { switch (c) { default: column = column + 1; break; } } check_bounds(&column, &row); /* Move */ if (move_action) { vga_move_cursor(row, column); } /* Save the final cursor position */ vga.row = row; vga.column = column; return (unsigned char) c; }