switch video mode hack by dropping to real mode to call the video bios works!
[bootcensus] / src / startup.s
1 # pcboot - bootable PC demo/game kernel
2 # Copyright (C) 2018  John Tsiombikas <nuclear@member.fsf.org>
3
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
8
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY, without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13
14 # You should have received a copy of the GNU General Public License
15 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
16
17         .code32
18         .section .startup,"ax"
19
20         .extern _bss_start
21         .extern _bss_end
22         .extern pcboot_main
23
24         # move the stack to the top of the conventional memory
25         movl $0x80000, %esp
26
27         # zero the BSS section
28         xor %eax, %eax
29         mov $_bss_start, %edi
30         mov $_bss_size, %ecx
31         cmp $0, %ecx
32         jz skip_bss_zero
33         shr $4, %ecx
34         rep stosl
35 skip_bss_zero:
36
37         call pcboot_main
38         # pcboot_main never returns
39 0:      cli
40         hlt
41         jmp 0b
42
43         .global logohack
44 logohack:
45         # copy palette
46         mov $logo_pal, %esi
47         xor %cl, %cl
48
49 0:      xor %eax, %eax
50         mov $0x3c8, %dx
51         movb %cl, %al
52         outb %al, %dx
53         inc %dx
54         # red
55         movb (%esi), %al
56         inc %esi
57         shr $2, %al
58         outb %al, %dx
59         # green
60         movb (%esi), %al
61         inc %esi
62         shr $2, %al
63         outb %al, %dx
64         # blue
65         movb (%esi), %al
66         inc %esi
67         shr $2, %al
68         outb %al, %dx
69         add $1, %cl
70         jnc 0b
71
72         # copy pixels
73         mov $sintab, %ebp
74         mov $logo_pix, %esi
75 frameloop:
76         mov $0xa0000, %edi
77         movl $0, yval
78 yloop:
79         movl $0, xval
80 xloop:
81         # calc src scanline address -> ebx
82         xor %ecx, %ecx
83         mov yval, %ebx
84         shl $2, %ebx
85         add frameno, %ebx
86         and $0xff, %ebx
87         mov (%ebp, %ebx), %cl
88         shr $5, %ecx
89
90         mov yval, %eax
91         add %ecx, %eax
92         # bounds check
93         cmp $200, %eax
94         jl 0f
95         mov $199, %eax
96
97 0:      mov %eax, %ebx
98         shl $8, %eax
99         shl $6, %ebx
100         add %eax, %ebx
101
102         # calc src x offset -> eax
103         xor %ecx, %ecx
104         mov xval, %eax
105         shl $2, %eax
106         add frameno, %eax
107         and $0xff, %eax
108         mov (%ebp, %eax), %cl
109         shr $5, %ecx
110
111         mov xval, %eax
112         add %ecx, %eax
113         # bounds check
114         cmp $320, %eax
115         jl 0f
116         mov $319, %eax
117
118 0:      add %eax, %ebx
119         mov (%ebx, %esi), %al
120
121         mov %al, (%edi)
122         inc %edi
123
124         incl xval
125         cmpl $320, xval
126         jnz xloop
127
128         incl yval
129         cmpl $200, yval
130         jnz yloop
131
132         incl frameno
133
134         # wait vsync
135         mov $0x3da, %dx
136 0:      in %dx, %al
137         and $8, %al
138         jnz 0b
139 0:      in %dx, %al
140         and $8, %al
141         jz 0b
142         jmp frameloop
143
144 xval: .long 0
145 yval: .long 0
146 frameno: .long 0
147
148 logo_pal:
149         .incbin "logo.pal"
150
151         .align 16
152 logo_pix:
153         .incbin "logo.raw"
154
155 sintab:
156         .byte 127
157         .byte 130
158         .byte 133
159         .byte 136
160         .byte 139
161         .byte 143
162         .byte 146
163         .byte 149
164         .byte 152
165         .byte 155
166         .byte 158
167         .byte 161
168         .byte 164
169         .byte 167
170         .byte 170
171         .byte 173
172         .byte 176
173         .byte 179
174         .byte 182
175         .byte 184
176         .byte 187
177         .byte 190
178         .byte 193
179         .byte 195
180         .byte 198
181         .byte 200
182         .byte 203
183         .byte 205
184         .byte 208
185         .byte 210
186         .byte 213
187         .byte 215
188         .byte 217
189         .byte 219
190         .byte 221
191         .byte 224
192         .byte 226
193         .byte 228
194         .byte 229
195         .byte 231
196         .byte 233
197         .byte 235
198         .byte 236
199         .byte 238
200         .byte 239
201         .byte 241
202         .byte 242
203         .byte 244
204         .byte 245
205         .byte 246
206         .byte 247
207         .byte 248
208         .byte 249
209         .byte 250
210         .byte 251
211         .byte 251
212         .byte 252
213         .byte 253
214         .byte 253
215         .byte 254
216         .byte 254
217         .byte 254
218         .byte 254
219         .byte 254
220         .byte 255
221         .byte 254
222         .byte 254
223         .byte 254
224         .byte 254
225         .byte 254
226         .byte 253
227         .byte 253
228         .byte 252
229         .byte 251
230         .byte 251
231         .byte 250
232         .byte 249
233         .byte 248
234         .byte 247
235         .byte 246
236         .byte 245
237         .byte 244
238         .byte 242
239         .byte 241
240         .byte 239
241         .byte 238
242         .byte 236
243         .byte 235
244         .byte 233
245         .byte 231
246         .byte 229
247         .byte 228
248         .byte 226
249         .byte 224
250         .byte 221
251         .byte 219
252         .byte 217
253         .byte 215
254         .byte 213
255         .byte 210
256         .byte 208
257         .byte 205
258         .byte 203
259         .byte 200
260         .byte 198
261         .byte 195
262         .byte 193
263         .byte 190
264         .byte 187
265         .byte 184
266         .byte 182
267         .byte 179
268         .byte 176
269         .byte 173
270         .byte 170
271         .byte 167
272         .byte 164
273         .byte 161
274         .byte 158
275         .byte 155
276         .byte 152
277         .byte 149
278         .byte 146
279         .byte 143
280         .byte 139
281         .byte 136
282         .byte 133
283         .byte 130
284         .byte 127
285         .byte 124
286         .byte 121
287         .byte 118
288         .byte 115
289         .byte 111
290         .byte 108
291         .byte 105
292         .byte 102
293         .byte 99
294         .byte 96
295         .byte 93
296         .byte 90
297         .byte 87
298         .byte 84
299         .byte 81
300         .byte 78
301         .byte 75
302         .byte 72
303         .byte 70
304         .byte 67
305         .byte 64
306         .byte 61
307         .byte 59
308         .byte 56
309         .byte 54
310         .byte 51
311         .byte 49
312         .byte 46
313         .byte 44
314         .byte 41
315         .byte 39
316         .byte 37
317         .byte 35
318         .byte 33
319         .byte 30
320         .byte 28
321         .byte 26
322         .byte 25
323         .byte 23
324         .byte 21
325         .byte 19
326         .byte 18
327         .byte 16
328         .byte 15
329         .byte 13
330         .byte 12
331         .byte 10
332         .byte 9
333         .byte 8
334         .byte 7
335         .byte 6
336         .byte 5
337         .byte 4
338         .byte 3
339         .byte 3
340         .byte 2
341         .byte 1
342         .byte 1
343         .byte 0
344         .byte 0
345         .byte 0
346         .byte 0
347         .byte 0
348         .byte 0
349         .byte 0
350         .byte 0
351         .byte 0
352         .byte 0
353         .byte 0
354         .byte 1
355         .byte 1
356         .byte 2
357         .byte 3
358         .byte 3
359         .byte 4
360         .byte 5
361         .byte 6
362         .byte 7
363         .byte 8
364         .byte 9
365         .byte 10
366         .byte 12
367         .byte 13
368         .byte 15
369         .byte 16
370         .byte 18
371         .byte 19
372         .byte 21
373         .byte 23
374         .byte 25
375         .byte 26
376         .byte 28
377         .byte 30
378         .byte 33
379         .byte 35
380         .byte 37
381         .byte 39
382         .byte 41
383         .byte 44
384         .byte 46
385         .byte 49
386         .byte 51
387         .byte 54
388         .byte 56
389         .byte 59
390         .byte 61
391         .byte 64
392         .byte 67
393         .byte 70
394         .byte 72
395         .byte 75
396         .byte 78
397         .byte 81
398         .byte 84
399         .byte 87
400         .byte 90
401         .byte 93
402         .byte 96
403         .byte 99
404         .byte 102
405         .byte 105
406         .byte 108
407         .byte 111
408         .byte 115
409         .byte 118
410         .byte 121
411         .byte 124