Skip to content

Instantly share code, notes, and snippets.

@ljmccarthy
Last active July 30, 2021 05:38
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ljmccarthy/3d842add94eebef4ad310a7e9fbe9fb8 to your computer and use it in GitHub Desktop.
Save ljmccarthy/3d842add94eebef4ad310a7e9fbe9fb8 to your computer and use it in GitHub Desktop.
Detect CGA, EGA, VGA or VESA BIOS in DOS.
format MZ
entry main:start
use16
segment main
start:
; detect EGA BIOS
mov ah, 0x12
mov bl, 0x10
int 0x10
cmp bl, 0x10
je .cga
; detect VGA BIOS
mov ax, 0x1a00
int 0x10
cmp al, 0x1a
jne .ega
; detect VESA BIOS
mov ax, vesa_info_buffer
mov es, ax
xor di, di
mov ax, 0x4f00
int 0x10
cmp ax, 0x004f
jne .vga
cmp word [es:di+0], 0x4556 ; 'VE'
jne .vga
cmp word [es:di+2], 0x4153 ; 'SA'
jne .vga
cmp word [es:di+4], 0x0102 ; version
jb .vga
.vesa:
mov dx, strings.vesa
jmp .print
.vga:
mov dx, strings.vga
jmp .print
.ega:
mov dx, strings.ega
jmp .print
.cga:
mov dx, strings.cga
.print:
mov ax, strings
mov ds, ax
mov ah, 0x09
int 0x21
mov ax, 0x4c00
int 0x21
segment strings
.cga db "CGA$"
.ega db "EGA$"
.vga db "VGA$"
.vesa db "VESA$"
segment vesa_info_buffer
rb 256
@fxttr
Copy link

fxttr commented Jul 30, 2021

Thanks, very useful. Your comment about VESA should make it clearer that you're trying to detect VESA SVGA and not VESA XGA. Only for the sake of completeness.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment