summaryrefslogtreecommitdiff
path: root/src/drivers/video/vga.c
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2017-06-30 15:02:26 +0200
committerAndreas Baumann <mail@andreasbaumann.cc>2017-06-30 15:02:26 +0200
commit915dd4b023d0826166d4887100dbed64d46821a9 (patch)
tree7803f23f045e3bf9cb70c7430be3b304212f660f /src/drivers/video/vga.c
parentd2af238397ab523b2c1ba7d24875a186b4a8acc6 (diff)
downloadabaos-915dd4b023d0826166d4887100dbed64d46821a9.tar.gz
abaos-915dd4b023d0826166d4887100dbed64d46821a9.tar.bz2
playing with Z buffering in VGA driver
Diffstat (limited to 'src/drivers/video/vga.c')
-rw-r--r--src/drivers/video/vga.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/drivers/video/vga.c b/src/drivers/video/vga.c
index 9d540af..bcd4366 100644
--- a/src/drivers/video/vga.c
+++ b/src/drivers/video/vga.c
@@ -253,7 +253,7 @@ bool vga_set_mode( vga_t *vga, const vga_mode_t mode )
vga->mode = mode;
vga->mode.segment = get_frame_buffer_segment( vga );
- vga->use_z_buffer = false;
+ vga_use_z_buffer( vga, false );
return true;
}
@@ -317,7 +317,7 @@ void vga_set_pixel( vga_t *vga, const int x, const int y, const vga_color_t colo
uint8_t color_idx = get_color_index( color );
- uint8_t *addr = vga->mode.segment + vga->mode.x * y + x;
+ uint8_t *addr = vga->base_addr + vga->mode.x * y + x;
*addr = color_idx;
}
@@ -337,14 +337,14 @@ void vga_draw_rectangle( vga_t *vga, const int x, const int y, const int w, cons
uint8_t color_idx = get_color_index( color );
for( int yy = y; yy < y + h; yy++ ) {
- uint8_t *addr = vga->mode.segment + vga->mode.x * yy + x;
+ uint8_t *addr = vga->base_addr + vga->mode.x * yy + x;
memset( addr, color_idx, w );
}
}
void vga_clear_screen( vga_t *vga, const vga_color_t color )
{
- memset( vga->mode.segment, get_color_index( color ),
+ memset( vga->base_addr, get_color_index( color ),
vga->mode.x * vga->mode.y );
}
@@ -385,6 +385,19 @@ void vga_wait_for_retrace( vga_t *vga )
void vga_use_z_buffer( vga_t *vga, bool use )
{
vga->use_z_buffer = use;
+
+ if( vga->use_z_buffer ) {
+ vga->base_addr = &vga->zbuffer[0];
+ } else {
+ vga->base_addr = vga->mode.segment;
+ }
}
+void vga_refresh( vga_t *vga )
+{
+ if( vga->use_z_buffer ) {
+ vga_wait_for_retrace( vga );
+ memcpy( vga->mode.segment, vga->zbuffer, 65535 );
+ }
+}