From cb6d24b838632e1269a5e4bb4e83425061f5d853 Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Thu, 8 Jun 2023 22:11:44 +0100 Subject: Detect the VGA card before setting mode 0x13 --- src/main.c | 6 +++++- src/vga.c | 12 +++++++++++- src/vga.h | 2 +- 3 files changed, 17 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/main.c b/src/main.c index c0e7dc3..672a478 100644 --- a/src/main.c +++ b/src/main.c @@ -17,7 +17,11 @@ int main(int argc, char *argv[]) atexit(keyb_free); /* set VGA 320x200, 256 col */ - set_mode(0x13); + if (!set_mode(0x13)) + { + fprintf(stderr, "ERROR: failed to init the VGA card\n"); + return 1; + } set_palette(binary_palette_start); diff --git a/src/vga.c b/src/vga.c index e90ebba..6b093c0 100644 --- a/src/vga.c +++ b/src/vga.c @@ -25,9 +25,17 @@ void close_framebuffer() __djgpp_nearptr_disable(); } -void set_mode(uint8_t mode) +uint8_t set_mode(uint8_t mode) { __dpmi_regs regs = { 0 }; + + /* detect VGA card */ + regs.x.ax = 0x1a00; + __dpmi_int(0x10, ®s); + if (regs.h.al != 0x1a) + return 0; + + memset(®s, 0, sizeof(regs)); regs.x.ax = mode; __dpmi_int(0x10, ®s); @@ -57,6 +65,8 @@ void set_mode(uint8_t mode) outportw(0x3d4, 0x8e11); /* restore retrace */ enable(); } + + return 1; } void wait_vsync() diff --git a/src/vga.h b/src/vga.h index a185974..8dae83d 100644 --- a/src/vga.h +++ b/src/vga.h @@ -14,7 +14,7 @@ typedef struct { uint8_t open_framebuffer(); void close_framebuffer(); -void set_mode(uint8_t mode); +uint8_t set_mode(uint8_t mode); void wait_vsync(); /* the palette is expected to be 8 bit per color, and will be converted to VGA's 6 bit per color */ -- cgit v1.2.3