diff options
Diffstat (limited to 'drivers/cga.h')
-rw-r--r-- | drivers/cga.h | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/drivers/cga.h b/drivers/cga.h new file mode 100644 index 0000000..f0ca412 --- /dev/null +++ b/drivers/cga.h @@ -0,0 +1,69 @@ +#pragma once +#include <stdlib.h> +#include "ports.h" + +/* + * CGA (Colour Graphics Adapter) + * + * useful links: + * https://www.seasip.info/VintagePC/cga.html + * https://www.lowlevel.eu/wiki/Color_Graphics_Adapter + * + * TODO: switching between modes + * TODO: cursor styling + */ + +class CGA : public Console { +public: + /* Hardware text mode colour constants. */ + enum Colour : uint8_t { + CGA_COLOR_BLACK = 0, + CGA_COLOR_BLUE = 1, + CGA_COLOR_GREEN = 2, + CGA_COLOR_CYAN = 3, + CGA_COLOR_RED = 4, + CGA_COLOR_MAGENTA = 5, + CGA_COLOR_BROWN = 6, + CGA_COLOR_LIGHT_GREY = 7, + CGA_COLOR_DARK_GREY = 8, + CGA_COLOR_LIGHT_BLUE = 9, + CGA_COLOR_LIGHT_GREEN = 10, + CGA_COLOR_LIGHT_CYAN = 11, + CGA_COLOR_LIGHT_RED = 12, + CGA_COLOR_LIGHT_MAGENTA = 13, + CGA_COLOR_LIGHT_BROWN = 14, + CGA_COLOR_WHITE = 15, + }; + + CGA(Colour fg = CGA_COLOR_BLACK, Colour bg = CGA_COLOR_LIGHT_GREY, uint32_t address = 0xB8000); + ~CGA() = default; + + void set_colour(Colour fg, Colour bg); + + void enable_cursor(uint8_t start, uint8_t end); + void disable_cursor(); + void update_cursor() override; + + void write(char c) override; + void write(ViewIterator& iter) override; + + + struct Entry { + char c; + Colour fg : 4; + Colour bg : 4; + } __attribute((packed)); + +private: + const size_t max_columns = 80, max_rows = 25; + size_t column = 0, row = 0; + + Colour colour_fg; + Colour colour_bg; + + Entry* buffer; + + // ports + cga_idx_port p_idx; + cga_dat_port p_dat; +}; |