Advertisement
pasholnahuy

Untitled

Feb 23rd, 2024 (edited)
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. #include "drivers/port.h"
  2. #include "drivers/vga.h"
  3.  
  4. void vga_set_cursor(unsigned offset) {
  5. port_byte_out(VGA_CTRL_REGISTER, VGA_OFFSET_HIGH);
  6. port_byte_out(VGA_DATA_REGISTER, offset >> 8);
  7. port_byte_out(VGA_CTRL_REGISTER, VGA_OFFSET_LOW);
  8. port_byte_out(VGA_DATA_REGISTER, offset & ((1 << 8) - 1));
  9. }
  10.  
  11. void vga_putc(char c) {
  12. unsigned offset = vga_get_cursor();
  13. if (c == 0xa) {
  14. unsigned new_offset = ((offset) / COLS + 1) * COLS;
  15. vga_set_cursor(new_offset);
  16. offset = new_offset;
  17. } else {
  18. vga_set_char(offset, c);
  19. ++offset;
  20. }
  21. if (offset == ROWS * COLS) {
  22. for (int i = 0; i < ROWS * COLS; ++i) {
  23. if (i >= (ROWS - 1) * COLS) {
  24. vga_set_char(i, ' ');
  25. } else {
  26. video_memory[2 * i] = video_memory[2 * (i + COLS)];
  27. }
  28. }
  29. offset -= COLS;
  30. }
  31. vga_set_cursor(offset);
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement