diff --git a/src/hulk/framebuffer.d b/src/hulk/framebuffer.d new file mode 100644 index 0000000..02efcee --- /dev/null +++ b/src/hulk/framebuffer.d @@ -0,0 +1,56 @@ +/** + * HULK Framebuffer support. + */ +module hulk.framebuffer; + +import hos.memory; + +/** + * Represent a graphical frame buffer. + * + * TODO: Handle other pixel formats. Currently only ARGB is supported. + */ +struct Framebuffer +{ + /** Frame buffer base address. */ + private uint * m_buffer; + + /** Frame buffer width. */ + private uint m_width; + + /** Frame buffer height. */ + private uint m_height; + + /** Frame buffer stride. */ + private uint m_stride; + + /** Number of pixels in the frame buffer (whether visible or not). */ + private uint m_buffer_size; + + /** + * Initialize a frame buffer. + * + * @param buffer Frame buffer base address. + * @param width Frame buffer width. + * @param height Frame buffer height. + * @param stride Frame buffer stride. + */ + void initialize(uint * buffer, uint width, uint height, uint stride) + { + m_buffer = buffer; + m_width = width; + m_height = height; + m_stride = stride; + m_buffer_size = stride * height; + } + + /** + * Clear the frame buffer to the given color. + * + * @param color Color to clear to. + */ + void clear(uint color = 0u) + { + memset32(m_buffer, color, m_buffer_size); + } +} diff --git a/src/hulk/hulk.d b/src/hulk/hulk.d index cbb5510..4356199 100644 --- a/src/hulk/hulk.d +++ b/src/hulk/hulk.d @@ -5,9 +5,12 @@ module hulk.hulk; import hulk.header; import hulk.bootinfo; +import hulk.framebuffer; import hos.memory; import ldc.attributes; +private __gshared Framebuffer fb; + extern extern(C) __gshared ubyte _hulk_total_size; @(ldc.attributes.section(".hulk_header")) @@ -23,9 +26,12 @@ private __gshared Header hulk_header = { */ extern(C) void hulk_start(ulong rdi, ulong rsi, ulong rdx, BootInfo * bootinfo) { + fb.initialize(bootinfo.fb.buffer, bootinfo.fb.width, bootinfo.fb.height, bootinfo.fb.stride); + fb.clear(0xFF8800u); + for (size_t y = 100u; y < 120u; y++) { - memset32(&bootinfo.fb.buffer[y * bootinfo.fb.stride + 20u], 0xFF8800u, 20u); + memset32(&bootinfo.fb.buffer[y * bootinfo.fb.stride + 20u], 0x001199u, 20u); } for (;;)