summaryrefslogtreecommitdiff
path: root/src/drivers/video/vga.h
blob: 69348565d7ca73ab58bb2d8414fdd57afdcd2ca0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#ifndef VGA_H
#define VGA_H

#include <stdbool.h>

#include "string.h"
#include <stddef.h>

#include "interrupts.h"
#include "port.h"

#include "video.h"

#define NOF_MODE_REGS 66

typedef struct {
	video_mode_t base;
	uint8_t regs[NOF_MODE_REGS];
	uint8_t *segment;
	size_t segment_size;
} vga_mode_t;

typedef struct {
	video_t base;
	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 {
	video_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 );

bool vga_switch_mode( void *obj, const video_mode_t *mode );

void vga_set_pixel( vga_t *vga, const int x, const int y, const video_rgb_color_t color );
void vga_draw_rectangle( vga_t *vga, const int x, const int y, const int w, const int h, const video_rgb_color_t color );
void vga_clear_screen( vga_t *vga, const video_rgb_color_t color );
void vga_draw_char( vga_t *vga, const unsigned char c, const int x, const int y, const video_rgb_color_t background, const video_rgb_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