diff options
Diffstat (limited to 'vga')
| -rw-r--r-- | vga/vga.ha | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/vga/vga.ha b/vga/vga.ha new file mode 100644 index 0000000..cf88221 --- /dev/null +++ b/vga/vga.ha @@ -0,0 +1,86 @@ +use term; + +export type vga_text = struct { + term: term::term, + address: *[*]u16, + pos: (size, size), + dim: (size, size), + colors: (term::color, term::color) +}; + +const vga_text_term: term::vtable = term::vtable { + setpos = &setpos, + getpos = &getpos, + setcolors = &setcolors, + getcolors = &getcolors, + putchar = &putchar, + getdim = &getdim +}; + +export fn attach(address: uintptr, xsize: size, ysize: size) vga_text = { + return vga_text { + term = &vga_text_term, + address = address: *[*]u16, + dim = (xsize, ysize), + pos = (0, 0), + colors = (term::color::LMAGENTA, term::color::BLACK) + }; +}; + +fn setpos(ctrl: *term::term, pos: (size, size)) void = { + let ctrl = ctrl: *vga_text; + + ctrl.pos = pos; +}; + +fn getpos(ctrl: *term::term) (size, size) = { + let ctrl = ctrl: *vga_text; + + return ctrl.pos; +}; + +fn setcolors(ctrl: *term::term, colors: (term::color, term::color)) void = { + let ctrl = ctrl: *vga_text; + + ctrl.colors = colors; +}; + +fn getcolors(ctrl: *term::term) (term::color, term::color) = { + let ctrl = ctrl: *vga_text; + + return ctrl.colors; +}; + +fn putchar(ctrl: *term::term, c: u8) void = { + let ctrl = ctrl: *vga_text; + + let attr: u16 = term_color_map(ctrl.colors.1) << 4 | term_color_map(ctrl.colors.0); + ctrl.address[ctrl.pos.1 * ctrl.dim.0 + ctrl.pos.0] = attr << 8 | c; +}; + +fn getdim(ctrl: *term::term) (size, size) = { + let ctrl = ctrl: *vga_text; + + return ctrl.dim; +}; + +fn term_color_map(col: term::color) u8 = { + switch (col) { + case term::color::BLACK => return 0x0; + case term::color::BLUE => return 0x1; + case term::color::GREEN => return 0x2; + case term::color::CYAN => return 0x3; + case term::color::RED => return 0x4; + case term::color::MAGENTA => return 0x5; + case term::color::BROWN => return 0x6; + case term::color::LGRAY => return 0x7; + case term::color::DGRAY => return 0x8; + case term::color::LBLUE => return 0x9; + case term::color::LGREEN => return 0xa; + case term::color::LCYAN => return 0xb; + case term::color::LRED => return 0xc; + case term::color::LMAGENTA => return 0xd; + case term::color::YELLOW => return 0xe; + case term::color::WHITE => return 0xf; + }; +}; |
