#pragma once #include #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() = default; ~CGA() = default; void set_buffer(uint32_t); void set_colour(Colour fg, Colour bg); void clear(); 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 = CGA_COLOR_BLACK; Colour colour_bg = CGA_COLOR_LIGHT_GREY; Entry* buffer; // ports cga_idx_port p_idx; cga_dat_port p_dat; };