aboutsummaryrefslogtreecommitdiff
path: root/devices/vga.c
blob: 983e630f3483dcf4a37ef12ae1182bcd9c101ad5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include "vga.h"
#include <stddef.h>
#include <stdint.h>

struct __attribute__((packed)) VGAEntry {
  unsigned char text;
  uint8_t foreground : 4;
  uint8_t background : 4;
};

_Static_assert(sizeof(struct VGAEntry) == 2);

const size_t width = 80;
const size_t height = 25;

struct VGAEntry *buffer;

void
vga_init()
{
  buffer = (struct VGAEntry *)0xc03ff000;
  vga_clear(VGA_COLOR_LIGHT_BLUE, VGA_COLOR_LIGHT_GREY);
}

void
vga_clear(enum vga_color foreground, enum vga_color background)
{
  for (size_t y = 0; y < height; ++y)
    for (size_t x = 0; x < width; ++x) {
      const size_t index = y * width + x;
      buffer[index].text = ' ';
      buffer[index].foreground = foreground;
      buffer[index].background = background;
    }
}