diff options
author | Benji Dial <benji3.141@gmail.com> | 2020-05-16 09:53:58 -0400 |
---|---|---|
committer | Benji Dial <benji3.141@gmail.com> | 2020-05-16 09:53:58 -0400 |
commit | c0daede46df4f546639bd2d3e11dcf064d554966 (patch) | |
tree | 2042d915325dc66baf063238b8a3c685bb91d17b /src/kernel/vga.c | |
parent | f7820301d583ae190b683bdd1371ee6f7a35ac16 (diff) | |
download | portland-os-c0daede46df4f546639bd2d3e11dcf064d554966.tar.gz |
starting over
Diffstat (limited to 'src/kernel/vga.c')
-rw-r--r-- | src/kernel/vga.c | 146 |
1 files changed, 0 insertions, 146 deletions
diff --git a/src/kernel/vga.c b/src/kernel/vga.c deleted file mode 100644 index f83a2cf..0000000 --- a/src/kernel/vga.c +++ /dev/null @@ -1,146 +0,0 @@ -/* -Copyright 2019 Benji Dial - -Permission to use, copy, modify, and/or distribute this -software for any purpose with or without fee is hereby -granted, provided that the above copyright notice and this -permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS -ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO -EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, -INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER -RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE -OF THIS SOFTWARE. -*/ - -#include "vga.h" -#include "serial.h" -#include <stdbool.h> - -#define VGA_BUFFER ((uint8_t *)0x000b8000) -#define cols 80 -#define rows 25 -uint16_t cursor_pos = 0; -uint8_t color = 0x70; - -void clear(void) { - uint32_t fill = 0x00200020 | (color << 24) | (color << 8); - for (uint32_t *i = (uint32_t *)VGA_BUFFER; i < (uint32_t *)(VGA_BUFFER + rows * cols * 2); ++i) - *i = fill; - cursor_pos = 0; -} - -void scroll(void) { - cursor_pos -= cols * 2; - for (uint32_t *i = (uint32_t *)VGA_BUFFER; i < (uint32_t *)(VGA_BUFFER + (rows - 1) * cols * 2); ++i) - *i = *(i + cols / 2); - uint32_t fill = (color << 8) | (color << 24) | 0x00200020; - for (uint32_t *i = (uint32_t *)(VGA_BUFFER + (rows - 1) * cols * 2); i < (uint32_t *)(VGA_BUFFER + rows * cols * 2); ++i) - *i = fill; -} - -void put_char(uint8_t ch) { - send_byte(ch, COM2); - switch (ch) { - case '\b': - if (cursor_pos) - VGA_BUFFER[cursor_pos -= 2] = (uint8_t)' '; - break; - case '\t': - while ((cursor_pos % (cols * 2)) % 20) - put_char(' '); - break; - case '\n': - if ((cursor_pos = (cursor_pos / (cols * 2) + 1) * (cols * 2)) >= cols * rows * 2) - scroll(); - break; - default: - VGA_BUFFER[cursor_pos++] = ch; - VGA_BUFFER[cursor_pos++] = color; - if (cursor_pos == (cols * rows * 2)) - scroll(); - } -} - -void put_sz(uint8_t *sz) { - while (*sz) - put_char(*(sz++)); -} - -void put_32_hex(uint32_t n) { - for (uint8_t i = 0; i < 4; ++i) { - put_char("0123456789abcdef"[n >> 28]); - n <<= 4; - } - put_char('.'); - for (uint8_t i = 0; i < 4; ++i) { - put_char("0123456789abcdef"[n >> 28]); - n <<= 4; - } -} - -void put_16_hex(uint16_t n) { - for (uint8_t i = 0; i < 4; ++i) { - put_char("0123456789abcdef"[n >> 12]); - n <<= 4; - } -} - -void put_8_hex(uint8_t n) { - put_char("0123456789abcdef"[n >> 4]); - put_char("0123456789abcdef"[n & 0x0f]); -} - -void put_32_dec(uint32_t n) { - if (n) { - bool sig = false; - for (uint32_t m = 1000000000; m; m /= 10) { - if (((n / m) % 10) || sig) { - sig = true; - put_char((uint8_t)'0' + (n / m) % 10); - } - } - } - else - put_char('0'); -} - -void put_16_dec(uint16_t n) { - if (n) { - bool sig = false; - for (uint16_t m = 10000; m; m /= 10) { - if (((n / m) % 10) || sig) { - sig = true; - put_char((uint8_t)'0' + (n / m) % 10); - } - } - } - else - put_char('0'); -} - -void put_8_dec(uint8_t n) { - if (n) { - bool sig = false; - for (uint8_t m = 100; m; m /= 10) { - if (((n / m) % 10) || sig) { - sig = true; - put_char((uint8_t)'0' + (n / m) % 10); - } - } - } - else - put_char('0'); -} - -void move_cursor(uint8_t col, uint8_t row) { - cursor_pos = (col + row * cols) * 2; -} - -void set_color(uint8_t c) { - color = c; -} |