Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "drivers/port.h"
- #include "drivers/vga.h"
- void vga_set_cursor(unsigned offset) {
- port_byte_out(VGA_CTRL_REGISTER, VGA_OFFSET_HIGH);
- port_byte_out(VGA_DATA_REGISTER, offset >> 8);
- port_byte_out(VGA_CTRL_REGISTER, VGA_OFFSET_LOW);
- port_byte_out(VGA_DATA_REGISTER, offset & ((1 << 8) - 1));
- }
- void vga_putc(char c) {
- unsigned offset = vga_get_cursor();
- if (c == 0xa) {
- unsigned new_offset = ((offset) / COLS + 1) * COLS;
- vga_set_cursor(new_offset);
- offset = new_offset;
- } else {
- vga_set_char(offset, c);
- ++offset;
- }
- if (offset == ROWS * COLS) {
- for (int i = 0; i < ROWS * COLS; ++i) {
- if (i >= (ROWS - 1) * COLS) {
- vga_set_char(i, ' ');
- } else {
- video_memory[2 * i] = video_memory[2 * (i + COLS)];
- }
- }
- offset -= COLS;
- }
- vga_set_cursor(offset);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement