aboutsummaryrefslogtreecommitdiff
path: root/src/kernel/graphics/vesa.asm
blob: 9d8e2317832b4046ce89129c7959e23cb0d0db86 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
global find_mode
global best_video_mode

vbe_info_block:
	.signature					db "VBE2"	; indicate support for VBE 2.0+
	.version					dw 0
	.oem						dd 0
	.capabilities 				dd 0
	.video_modes				dd 0
	.video_memory				dw 0
	.software_rev				dw 0
	.vendor						dd 0
	.product_name				dd 0
	.product_rev				dd 0
	.reserved					times 222 db 0
	.oem_data					times 256 db 0

mode_info_block:
	.attributes					dw 0
	.window_a					db 0
	.window_b					db 0
	.granularity				dw 0
	.window_size				dw 0
	.segment_a					dw 0
	.segment_b					dw 0
	.win_func_ptr			 	dd 0
	.pitch						dw 0
	.width						dw 0
	.height						dw 0
	.w_char						db 0
	.y_char						db 0
	.planes						db 0
	.bpp						db 0
	.banks						db 0
	.memory_model				db 0
	.bank_size					db 0
	.image_pages				db 0
	.reserved0					db 0

	.red_mask					db 0
	.red_position				db 0
	.green_mask					db 0
	.green_position				db 0
	.blue_mask					db 0
	.blue_position				db 0
	.reserved_mask				db 0
	.reserved_position			db 0
	.direct_color_attributes	db 0

	.framebuffer				dd 0
	.off_screen_mem_off			dd 0
	.off_screen_mem_size		dw 0
	.reserved1					times 206 db 0

best_video_mode:
	.bpp db 0
	.height dw 0
	.width dw 0
	.mode dw 0
	.framebuffer dd 0
	.bytes_per_line dw 0
	.bytes_per_pixel dd 0
	.x_cur_max dw 0
	.y_cur_max dw 0

segments dw 0
offset  dw 0
mode 	dw 0

width equ 1024
height equ 768
bpp equ 32

search_video_mode:
    [bits 16]

    push es
    mov ax, 0x4F00
    mov di, vbe_info_block
    int 0x10
    pop es

    mov ax, word [vbe_info_block.video_modes]
    mov [offset], ax
    mov ax, word [vbe_info_block.video_modes+2]
    mov [segments], ax

    mov ax, [segments]
    mov fs, ax
    mov si, [offset]

    mov cx, 1
    push cx

find_mode:
	mov dx, [fs:si]
	add si, 2
	mov [offset], si
	mov [mode], dx
	mov ax, 0
	mov fs, ax

	push es
	mov ax, 0x4F01
	mov cx, [mode]
	mov di, mode_info_block
	int 0x10
	pop es

	cmp ax, 0x004F

	pop cx
	cmp cx, 4
	je reset_counter
	inc cx
	push cx

	check_mode:
		mov cx, 0
		mov bx, [best_video_mode.width]
		cmp bx, [mode_info_block.width]
		jl save_and_continue
		je compare_height
		jmp next_mode

	compare_height:
		mov bx, [best_video_mode.height]
		cmp bx, [mode_info_block.height]
		jl save_and_continue
		je compare_bpp
		jmp next_mode

	compare_bpp:
		mov dx, [best_video_mode.bpp]
		mov ax, [mode_info_block.bpp]
		and ax, 11111111b
		cmp dx, ax
		jl save_and_continue
		jmp next_mode

	save_and_continue:
		mov bx, [mode_info_block.width]
		mov [best_video_mode.width], bx

		shr bx,3
		dec bx
		mov [best_video_mode.x_cur_max], bx

		mov bx, [mode_info_block.height]
		mov [best_video_mode.height], bx

		shr bx, 4
		dec bx
		mov word [best_video_mode.y_cur_max], ax

		mov ebx, 0
		mov bl, [mode_info_block.bpp]
		mov byte [best_video_mode.bpp], bl
		shr ebx, 3
		mov dword [best_video_mode.bytes_per_pixel], ebx


		mov bx, [mode]
		mov [best_video_mode.mode], bx
		mov ebx, [mode_info_block.framebuffer]
		mov dword[best_video_mode.framebuffer], ebx
		mov bx, [mode_info_block.pitch]
		mov word [best_video_mode.bytes_per_line],bx
		jmp next_mode

pop es

jmp $

new_line_and_next_mode:
	mov cx,1
	push cx
	jmp next_mode

reset_counter:
	mov cx, 1
	push cx
	jmp check_mode

set_mode:
	push es
	mov ax, 0x4F02
	mov bx, [best_video_mode.mode]
	or bx, 0x4000
	mov di, 0
	int 0x10
	pop es

	cmp ax, 0x4F
	clc

next_mode:
	mov ax, [segments]
	mov fs, ax
	mov si, [offset]
	jmp find_mode