14using namespace MaxOS::drivers;
15using namespace MaxOS::drivers::video;
16using namespace MaxOS::hardwarecommunication;
24 m_crtc_index_port(0x3D4),
25 crtc_data_port(0x3D5),
26 m_sequence_index_port(0x3C4),
27 m_sequence_data_port(0x3C5),
28 m_graphics_controller_index_port(0x3CE),
29 m_graphics_controller_data_port(0x3CF),
30 m_attribute_controller_index_port(0x3C0),
31 m_attribute_controller_read_port(0x3C1),
32 m_attribute_controller_write_port(0x3C0),
33 m_attribute_controller_reset_port(0x3DA)
37VideoGraphicsArray::~VideoGraphicsArray() =
default;
44void VideoGraphicsArray::write_registers(uint8_t *registers) {
47 m_misc_port.
write(*(registers++));
50 for (uint8_t i = 0; i < 5; i++) {
51 m_sequence_index_port.
write(i);
52 m_sequence_data_port.
write(*(registers++));
56 m_crtc_index_port.
write(0x03);
57 crtc_data_port.
write(crtc_data_port.
read() | 0x80);
58 m_crtc_index_port.
write(0x11);
59 crtc_data_port.
write(crtc_data_port.
read() | ~0x80);
62 registers[0x03] = registers[0x03] | 0x80;
63 registers[0x11] = registers[0x11] & ~0x80;
66 for (uint8_t i = 0; i < 25; i++) {
67 m_crtc_index_port.
write(i);
68 crtc_data_port.
write(*(registers++));
72 for (uint8_t i = 0; i < 9; i++) {
73 m_graphics_controller_index_port.
write(i);
74 m_graphics_controller_data_port.
write(*(registers++));
78 for (uint8_t i = 0; i < 21; i++) {
79 m_attribute_controller_reset_port.
read();
80 m_attribute_controller_index_port.
write(i);
81 m_attribute_controller_write_port.
write(*(registers++));
85 m_attribute_controller_reset_port.
read();
86 m_attribute_controller_index_port.
write(0x20);
99 return width == 320 &&
height == 200 && colour_depth == 8;
111bool VideoGraphicsArray::internal_set_mode(uint32_t width, uint32_t height, uint32_t colour_depth) {
114 unsigned char g_320x200x256[] =
119 0x03, 0x01, 0x0F, 0x00, 0x0E,
121 0x5F, 0x4F, 0x50, 0x82, 0x54, 0x80, 0xBF, 0x1F,
122 0x00, 0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
123 0x9C, 0x0E, 0x8F, 0x28, 0x40, 0x96, 0xB9, 0xA3,
126 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x05, 0x0F,
129 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
130 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
131 0x41, 0x00, 0x0F, 0x00, 0x00
134 write_registers(g_320x200x256);
143uint8_t *VideoGraphicsArray::get_frame_buffer_segment() {
146 return (uint8_t *) 0xA0000;
149 m_graphics_controller_index_port.
write(0x06);
150 uint8_t segment_number =
151 m_graphics_controller_data_port.
read() &
153 switch (segment_number) {
156 return (uint8_t *)
nullptr;
158 return (uint8_t *) 0xA0000;
160 return (uint8_t *) 0xB0000;
162 return (uint8_t *) 0xB8000;
173void VideoGraphicsArray::render_pixel_8_bit(uint32_t x, uint32_t y, uint8_t colour) {
175 uint8_t *pixel_address = get_frame_buffer_segment() + 320 * y + x;
176 *pixel_address = colour;
186uint8_t VideoGraphicsArray::get_rendered_pixel_8_bit(uint32_t x, uint32_t y) {
188 uint8_t *pixel_address = get_frame_buffer_segment() + 320 * y + x;
189 return *pixel_address;
209 return "VGA compatible graphics card";
uint32_t width() const
Gets the width of the screen.
uint32_t height() const
Gets the height of the screen.
string vendor_name() final
Gets the name of the vendor.
bool supports_mode(uint32_t width, uint32_t height, uint32_t colour_depth) final
Checks if the specified resolution is supported.
string device_name() final
Gets the name of the device.
VideoGraphicsArray()
Constructs a new Video Graphics Array (VGA) driver object, initializing the necessary I/O ports for V...
virtual uint8_t read()
read a byte from the port
virtual void write(uint8_t data)
write a byte to the port
Defines a Video Graphics Array (VGA) driver for rendering graphics to the screen.