]> git.lizzy.rs Git - nyax.git/blob - stage2/vesa.asm
Page calculation
[nyax.git] / stage2 / vesa.asm
1 vesa:
2         ; print message
3         mov ebx, .msg
4         call print_str
5
6         ; get vesa bios info
7         mov eax, dword[.vbe2]
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
11         int 0x10
12
13         cmp ax, 0x004F           ; check ax for correct magic number
14         jne .fail_getinfo
15
16         mov eax, dword[.vesa]
17         cmp dword[VESAINFO], eax ; check if "VESA" is at start of stuct
18         jne .fail_getinfo
19
20         ; print select message
21         mov ebx, .select_msg
22         call print_str
23
24         ; get segment:offset pointer to video modes into gs:ebx
25         movzx ebx, word[VESAINFO+14]
26         mov    ax, word[VESAINFO+16]
27         mov gs, ax
28
29         ; convert modes to own structure
30
31         xor esi, esi        ; number of avail modes
32
33 .mode_loop:
34         ; get mode info
35         mov cx, [gs:ebx]    ; video mode into cx
36         cmp cx, 0xFFFF      ; 0xFFFF is terminator, no suitable mode has been found
37         je .mode_done
38         mov ax, 0x4F01      ; get VESA mode information
39         mov di, VESAMODE    ; vesa mode info struct buffer
40         int 0x10
41
42         cmp ax, 0x004F      ; check ax for correct magic number
43         jne .fail_modeinfo
44
45         mov al, byte[VESAMODE] ; get attributes
46         and al, 0b10000000     ; extract bit 7, indicates linear framebuffer support
47         jz .mode_next
48
49         mov al, byte[VESAMODE+25] ; get bpp (bits per pixel)
50         cmp al, 32
51         jne .mode_next
52
53         push ebx ; print_dec and print_str modify ebx
54
55         mov eax, esi
56         mov ebx, 12
57         mul ebx
58         mov edi, eax
59         add edi, OWNMODE
60
61         mov [edi+10], cx ; copy mode
62
63         ; print selector
64         mov al, '['
65         call print_chr
66
67         mov eax, esi
68         add eax, 'a'
69         call print_chr
70
71         mov al, ']'
72         call print_chr
73
74         mov al, ' '
75         call print_chr
76
77         mov ax, [VESAMODE+16] ; copy pitch
78         mov [edi+0], ax
79
80         movzx eax, word[VESAMODE+18] ; copy width
81         mov [edi+2], ax
82         call print_dec
83
84         mov al, 'x'
85         call print_chr
86
87         movzx eax, word[VESAMODE+20] ; copy height
88         mov [edi+4], ax
89         call print_dec
90         call newline
91
92         mov eax, [VESAMODE+40] ; copy framebuffer
93         mov [edi+6], eax
94
95         pop ebx
96
97         inc esi
98         cmp esi, 'z'-'a'   ; only print up to z
99         jg .mode_done
100
101 .mode_next:
102         add ebx, 2         ; increase mode pointer
103         jmp .mode_loop     ; loop
104
105 .mode_done:
106         cmp esi, 0
107         je .fail_nomode
108
109 .input:
110         mov ebx, .select_prompt
111         call print_str
112
113         mov ah, 0x00   ; get keypress, blocking
114         int 0x16
115
116         call print_chr ; echo user input
117
118         movzx edi, al  ; backup al
119         call newline
120
121         sub edi, 'a'
122         cmp edi, esi
123         jb .valid      ; check validity
124
125         mov ebx, .invalid
126         call print_str
127
128         jmp .input
129
130 .valid:
131         ; convert selected number to address
132         mov eax, edi
133         mov ebx, 12
134         mul ebx
135         add eax, OWNMODE
136
137         ; copy to final gfx info location
138         mov ebx, [eax+0]
139         mov [GFXINFO+0], ebx
140
141         mov ebx, [eax+4]
142         mov [GFXINFO+4], ebx
143
144         mov bx, [eax+8]
145         mov [GFXINFO+8], bx
146
147         ;mov edi, eax
148         ;mov eax, [edi+6]
149         ;call print_hex
150         ;call newline
151         ;mov eax, edi
152         ;jmp $
153
154         ; set mode
155         mov bx, [eax+10]           ; video mode in bx (first 13 bits)
156         or  bx, 1 << 14            ; set bit 14: enable linear frame buffer
157         and bx, 0b0111111111111111 ; clear deprecated bit 15
158         mov ax, 0x4F02             ; set VBE mode
159         int 0x10
160
161         ret
162
163 .msg: db "setting up vesa", 10, 13, 0
164 .vbe2: db "VBE2"
165 .vesa: db "VESA"
166 .select_msg: db "avaliable video modes:", 10, 13, 0
167 .select_prompt: db "select video mode: ", 0
168 .invalid: db "invalid input", 10, 13, 0
169
170 .fail_getinfo:
171         mov ebx, .fail_getinfo_msg
172         jmp .fail
173
174 .fail_modeinfo:
175         mov ebx, .fail_modeinfo_msg
176         jmp .fail
177
178 .fail_nomode:
179         mov ebx, .fail_nomode_msg
180         jmp .fail
181
182 .fail_getinfo_msg: db "failed getting vesa bios info", 10, 13, 0
183 .fail_modeinfo_msg: db "failed getting video mode info", 10, 13, 0
184 .fail_nomode_msg: db "no suitable video modes available", 10, 13, 0
185
186 .fail:
187         call print_str
188         jmp $