#ifndef VGA_H #define VGA_H #include #include "string.h" #include #include "interrupts.h" #include "port.h" #include "driver.h" #define NOF_MODE_REGS 66 typedef enum { VGA_MODE_TYPE_TEXT, VGA_MODE_TYPE_GRAPHICS } vga_mode_type_t; typedef struct { vga_mode_type_t mode_type; int x; int y; int color_depth; uint8_t regs[NOF_MODE_REGS]; uint8_t *segment; size_t segment_size; } vga_mode_t; typedef struct { driver_t base; interrupt_t *interrupts; port8_t misc_port; port8_t crtc_index_port; port8_t crtc_data_port; port8_t sequencer_index_port; port8_t sequencer_data_port; port8_t graphics_controller_index_port; port8_t graphics_controller_data_port; port8_t attribute_controller_index_port; port8_t attribute_controller_read_port; port8_t attribute_controller_write_port; port8_t attribute_controller_reset_port; vga_mode_t mode; bool use_z_buffer; uint8_t *zbuffer; // stores either the address to the beginning of the segment // (real mapped I/O memory or the beginning of the Z buffer uint8_t *base_addr; } vga_t; typedef struct { driver_vtable_t base; } vga_vtable_t; void vga_init( vga_t *vga, interrupt_t *interrupt, void *context ); void vga_activate( void *obj ); void vga_deactivate( void *obj ); void vga_deinit( void *obj ); void vga_print_info( void *obj ); vga_mode_t vga_make_mode( const vga_mode_type_t mode_type, const int x, const int y, const int color_depth ); bool vga_set_mode( vga_t *vga, const vga_mode_t mode ); bool vga_supports_mode( const vga_mode_t mode ); typedef struct { int R; int G; int B; } vga_color_t; extern const vga_color_t VGA_COLOR_BLACK; extern const vga_color_t VGA_COLOR_BLUE; extern const vga_color_t VGA_COLOR_GREEN; extern const vga_color_t VGA_COLOR_CYAN; extern const vga_color_t VGA_COLOR_RED; extern const vga_color_t VGA_COLOR_MAGENTA; extern const vga_color_t VGA_COLOR_BROWN; extern const vga_color_t VGA_COLOR_LIGHT_GREY; extern const vga_color_t VGA_COLOR_WHITE; vga_color_t vga_make_RGB( int R, int G, int B ); void vga_set_pixel( vga_t *vga, const int x, const int y, const vga_color_t color ); void vga_draw_rectangle( vga_t *vga, const int x, const int y, const int w, const int h, const vga_color_t color ); void vga_clear_screen( vga_t *vga, const vga_color_t color ); void vga_draw_char( vga_t *vga, const unsigned char c, const int x, const int y, const vga_color_t background, const vga_color_t foreground ); void vga_wait_for_retrace( vga_t *vga ); void vga_use_z_buffer( vga_t *vga, bool use ); void vga_refresh( vga_t *vga ); #endif // VGA_H