From eace3b5f238e5e4eaf4c2ffcbf741616a0d6a25f Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Sat, 17 Jun 2017 08:47:07 +0200 Subject: added the most complex VGA mode (640x480x4, only timings for now) added graphics and text mode type parameter to vga_mode_t --- src/Makefile | 6 +++--- src/boot/stage2_real_functions.asm | 2 +- src/drivers/video/vga.c | 34 +++++++++++++++++++++++++++++----- src/drivers/video/vga.h | 8 +++++++- src/kernel/kernel.c | 4 ++-- 5 files changed, 42 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/Makefile b/src/Makefile index cb72031..3b1964f 100644 --- a/src/Makefile +++ b/src/Makefile @@ -11,16 +11,16 @@ all: image.bin kernel.sym # truncate to correct number of sectors, we have # 512 (boot, stage 1) + N * 512 (N currenty is 5, stage 2) for boot.bin -# + M * 512 (M is currently 158) for kernel.bin +# + M * 512 (M is currently 159) for kernel.bin # (M + N + 1 is the number of sectors to be read in stage 2, as stage 1 # loads only the first sector, and stage 1 loads 5 sectors of stage 2, -# adapt NOF_LOAD_SECTORS to 158) +# adapt NOF_LOAD_SECTORS to 159) # then we make sure the image has the size of a 1.44 MB floppy # (emulators like qemu do some guess work for CHS resolution based # on the size of the image) image.bin: boot.bin kernel.bin magic.bin cat boot.bin kernel.bin > image.tmp - truncate -s 83456 image.tmp + truncate -s 83968 image.tmp cat image.tmp magic.bin > image.bin truncate -s 1474560 image.bin diff --git a/src/boot/stage2_real_functions.asm b/src/boot/stage2_real_functions.asm index e72b783..cc2ad26 100644 --- a/src/boot/stage2_real_functions.asm +++ b/src/boot/stage2_real_functions.asm @@ -2,7 +2,7 @@ ; (note: the first sector gets loaded by the BIOS, the ; next 5 sectors are read by the simple stage 1 loader, ; so subtract 6 here!) -NOF_LOAD_SECTORS equ 158 +NOF_LOAD_SECTORS equ 159 ; data sections used for reading the kernel from disk SECTORS_PER_CYLINDER: diff --git a/src/drivers/video/vga.c b/src/drivers/video/vga.c index bb73f1e..0d3c49a 100644 --- a/src/drivers/video/vga.c +++ b/src/drivers/video/vga.c @@ -101,10 +101,11 @@ static void write_registers( vga_t *vga, uint8_t *regs ) port8_write( &vga->attribute_controller_index_port, 0x20 ); } -vga_mode_t vga_make_mode( const int x, const int y, const int color_depth ) +vga_mode_t vga_make_mode( const vga_mode_type_t mode_type, const int x, const int y, const int color_depth ) { vga_mode_t mode; + mode.mode_type = mode_type; mode.x = x; mode.y = y; mode.color_depth = color_depth; @@ -114,7 +115,7 @@ vga_mode_t vga_make_mode( const int x, const int y, const int color_depth ) // from http://files.osdev.org/mirrors/geezer/osd/graphics/modes.c static vga_mode_t modes[] = { - { 640, 480, 4, + { VGA_MODE_TYPE_TEXT, 640, 480, 4, { /* MISC */ 0x67, @@ -135,7 +136,7 @@ static vga_mode_t modes[] = { }, NULL }, - { 320, 200, 8, + { VGA_MODE_TYPE_GRAPHICS, 320, 200, 8, { /* MISC */ 0x63, @@ -155,13 +156,35 @@ static vga_mode_t modes[] = { 0x41, 0x00, 0x0F, 0x00, 0x00 }, NULL + }, + { VGA_MODE_TYPE_GRAPHICS, 640, 480, 4, + { + /* MISC */ + 0xE3, + /* SEQ */ + 0x03, 0x01, 0x08, 0x00, 0x06, + /* CRTC */ + 0x5F, 0x4F, 0x50, 0x82, 0x54, 0x80, 0x0B, 0x3E, + 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xEA, 0x0C, 0xDF, 0x28, 0x00, 0xE7, 0x04, 0xE3, + 0xFF, + /* GC */ + 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x05, 0x0F, + 0xFF, + /* AC */ + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x14, 0x07, + 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, + 0x01, 0x00, 0x0F, 0x00, 0x00 + }, + NULL } }; bool vga_supports_mode( const vga_mode_t mode ) { for( int i = 0; modes[i].x != 0; i++ ) { - if( mode.x == modes[i].x && + if( mode.mode_type == modes[i].mode_type && + mode.x == modes[i].x && mode.y == modes[i].y && mode.color_depth == modes[i].color_depth ) { return true; @@ -174,7 +197,8 @@ bool vga_supports_mode( const vga_mode_t mode ) static int get_matching_mode_idx( const vga_mode_t mode ) { for( int i = 0; modes[i].x != 0; i++ ) { - if( mode.x == modes[i].x && + if( mode.mode_type == modes[i].mode_type && + mode.x == modes[i].x && mode.y == modes[i].y && mode.color_depth == modes[i].color_depth ) { return i; diff --git a/src/drivers/video/vga.h b/src/drivers/video/vga.h index 8b7ebdc..86897c4 100644 --- a/src/drivers/video/vga.h +++ b/src/drivers/video/vga.h @@ -12,7 +12,13 @@ #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; @@ -48,7 +54,7 @@ void vga_deactivate( void *obj ); void vga_deinit( void *obj ); void vga_print_info( void *obj ); -vga_mode_t vga_make_mode( const int x, const int y, const int color_depth ); +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 ); diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c index f36c2ff..e7f3e26 100644 --- a/src/kernel/kernel.c +++ b/src/kernel/kernel.c @@ -191,7 +191,7 @@ static void handle_keyboard_event( keyboard_event_t *event, void *context ) // for now when we enter the graphics mode we remain there switch( global_context->mode ) { case MODE_TEXT: - if( vga_set_mode( vga, vga_make_mode( 320, 200, 8 ) ) ) { + if( vga_set_mode( vga, vga_make_mode( VGA_MODE_TYPE_GRAPHICS, 320, 200, 8 ) ) ) { vga_clear_screen( vga, vga_make_RGB( 0x00, 0x00, 0xA8 ) ); vga_draw_char( vga, 'A', 100, 100, vga_make_RGB( 0x00, 0x00, 0xA8 ), vga_make_RGB( 0xFF, 0xFF, 0xFF ) ); @@ -212,7 +212,7 @@ static void handle_keyboard_event( keyboard_event_t *event, void *context ) break; case MODE_GRAPHICS: - if( vga_set_mode( vga, vga_make_mode( 640, 480, 4 ) ) ) { + if( vga_set_mode( vga, vga_make_mode( VGA_MODE_TYPE_TEXT, 640, 480, 4 ) ) ) { } global_context->mode = MODE_TEXT; break; -- cgit v1.2.3-54-g00ecf