summaryrefslogtreecommitdiff
path: root/kernel/source/framebuffer.cpp
blob: ab1b3d7954a4940ff0ce21d3f15f1a2566360418 (plain) (blame)
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
36
37
38
39
40
#include <hilbert/kernel/application.hpp>
#include <hilbert/kernel/framebuffer.hpp>

namespace hilbert::kernel::framebuffer {

  uint64_t paddr;
  static uint32_t *vaddr;
  int width;
  int height;
  int dword_pitch;

  void init_framebuffer(uint64_t paddr, uint64_t vaddr,
    uint64_t width, uint64_t height, uint64_t pitch
  ) {

    //TODO: assumes 32-bpp rgb

    framebuffer::paddr = paddr;
    framebuffer::vaddr = (uint32_t *)vaddr;
    framebuffer::width = width;
    framebuffer::height = height;
    dword_pitch = pitch / 4;

  }

  color encode_color(uint8_t r, uint8_t g, uint8_t b) {
    return ((uint32_t)r << 16) | ((uint32_t)g << 8) | (uint32_t)b;
  }

  void set_pixel(int x, int y, color c) {
    vaddr[y * dword_pitch + x] = c;
  }

  void fill_color(color c) {
    for (int y = 0; y < height; ++y)
      for (int x = 0; x < width; ++x)
        vaddr[y * dword_pitch + x] = c;
  }

}