8 mov dword[VESAINFO], eax ; move "VBE2" to start of vesainfo struct
9 mov ax, 0x4F00 ; get VESA BIOS information
10 mov di, VESAINFO ; struct buffer
13 cmp ax, 0x004F ; check ax for correct magic number
17 cmp dword[VESAINFO], eax ; check if "VESA" is at start of stuct
20 ; print select message
24 ; get segment:offset pointer to video modes into gs:ebx
25 movzx ebx, word[VESAINFO+14]
26 mov ax, word[VESAINFO+16]
29 ; convert modes to own structure
31 xor esi, esi ; number of avail modes
35 mov cx, [gs:ebx] ; video mode into cx
36 cmp cx, 0xFFFF ; 0xFFFF is terminator, no suitable mode has been found
38 mov ax, 0x4F01 ; get VESA mode information
39 mov di, VESAMODE ; vesa mode info struct buffer
42 cmp ax, 0x004F ; check ax for correct magic number
45 mov al, byte[VESAMODE] ; get attributes
46 and al, 0b10000000 ; extract bit 7, indicates linear framebuffer support
49 mov al, byte[VESAMODE+25] ; get bpp (bits per pixel)
53 push ebx ; print_dec and print_str modify ebx
61 mov [edi+10], cx ; copy mode
77 mov ax, [VESAMODE+16] ; copy pitch
80 movzx eax, word[VESAMODE+18] ; copy width
87 movzx eax, word[VESAMODE+20] ; copy height
92 mov eax, [VESAMODE+40] ; copy framebuffer
98 cmp esi, 'z'-'a' ; only print up to z
102 add ebx, 2 ; increase mode pointer
103 jmp .mode_loop ; loop
110 mov ebx, .select_prompt
113 mov ah, 0x00 ; get keypress, blocking
116 call print_chr ; echo user input
118 movzx edi, al ; backup al
123 jb .valid ; check validity
131 ; convert selected number to address
137 ; copy to final gfx info location
157 mov bx, [eax+10] ; video mode in bx (first 13 bits)
158 or bx, 1 << 14 ; set bit 14: enable linear frame buffer
159 and bx, 0b0111111111111111 ; clear deprecated bit 15
160 mov ax, 0x4F02 ; set VBE mode
165 .msg: db "setting up vesa", 10, 13, 0
168 .select_msg: db "avaliable video modes:", 10, 13, 0
169 .select_prompt: db "select video mode: ", 0
170 .invalid: db "invalid input", 10, 13, 0
173 mov ebx, .fail_getinfo_msg
177 mov ebx, .fail_modeinfo_msg
181 mov ebx, .fail_nomode_msg
184 .fail_getinfo_msg: db "failed getting vesa bios info", 10, 13, 0
185 .fail_modeinfo_msg: db "failed getting video mode info", 10, 13, 0
186 .fail_nomode_msg: db "no suitable video modes available", 10, 13, 0