ef3cd38b443a03e5f435f420cd841d987ac70012
[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         .extern wait_vsync
24         .extern kb_getkey
25
26         # move the stack to the top of the conventional memory
27         cli
28         movl $0x80000, %esp
29
30         # zero the BSS section
31         xor %eax, %eax
32         mov $_bss_start, %edi
33         mov $_bss_size, %ecx
34         cmp $0, %ecx
35         jz skip_bss_zero
36         shr $4, %ecx
37         rep stosl
38 skip_bss_zero:
39
40         call pcboot_main
41         # pcboot_main never returns
42 0:      cli
43         hlt
44         jmp 0b
45
46         .global logohack
47 logohack:
48         pusha
49
50         # copy palette
51         mov $logo_pal, %esi
52         xor %cl, %cl
53
54 0:      xor %eax, %eax
55         mov $0x3c8, %dx
56         movb %cl, %al
57         outb %al, %dx
58         inc %dx
59         # red
60         movb (%esi), %al
61         inc %esi
62         shr $2, %al
63         outb %al, %dx
64         # green
65         movb (%esi), %al
66         inc %esi
67         shr $2, %al
68         outb %al, %dx
69         # blue
70         movb (%esi), %al
71         inc %esi
72         shr $2, %al
73         outb %al, %dx
74         add $1, %cl
75         jnc 0b
76
77         # copy pixels
78         mov $sintab, %ebp
79         mov $logo_pix, %esi
80 frameloop:
81         mov $0xa0000, %edi
82         movl $0, yval
83 yloop:
84         movl $0, xval
85 xloop:
86         # calc src scanline address -> ebx
87         xor %ecx, %ecx
88         mov yval, %ebx
89         shl $2, %ebx
90         add frameno, %ebx
91         and $0xff, %ebx
92         mov (%ebp, %ebx), %cl
93         shr $5, %ecx
94
95         mov yval, %eax
96         add %ecx, %eax
97         # bounds check
98         cmp $200, %eax
99         jl 0f
100         mov $199, %eax
101
102 0:      mov %eax, %ebx
103         shl $8, %eax
104         shl $6, %ebx
105         add %eax, %ebx
106
107         # calc src x offset -> eax
108         xor %ecx, %ecx
109         mov xval, %eax
110         shl $2, %eax
111         add frameno, %eax
112         and $0xff, %eax
113         mov (%ebp, %eax), %cl
114         shr $5, %ecx
115
116         mov xval, %eax
117         add %ecx, %eax
118         # bounds check
119         cmp $320, %eax
120         jl 0f
121         mov $319, %eax
122
123 0:      add %eax, %ebx
124         mov (%ebx, %esi), %al
125
126         mov %al, (%edi)
127         inc %edi
128
129         incl xval
130         cmpl $320, xval
131         jnz xloop
132
133         incl yval
134         cmpl $200, yval
135         jnz yloop
136
137         incl frameno
138
139         call wait_vsync
140
141         # check for escape keypress
142         call kb_getkey
143         cmp $27, %eax
144         jz 0f
145
146         jmp frameloop
147
148 0:      popa
149         ret
150
151 xval: .long 0
152 yval: .long 0
153 frameno: .long 0
154
155 logo_pal:
156         .incbin "logo.pal"
157
158         .align 16
159 logo_pix:
160         .incbin "logo.raw"
161
162 sintab:
163         .byte 127
164         .byte 130
165         .byte 133
166         .byte 136
167         .byte 139
168         .byte 143
169         .byte 146
170         .byte 149
171         .byte 152
172         .byte 155
173         .byte 158
174         .byte 161
175         .byte 164
176         .byte 167
177         .byte 170
178         .byte 173
179         .byte 176
180         .byte 179
181         .byte 182
182         .byte 184
183         .byte 187
184         .byte 190
185         .byte 193
186         .byte 195
187         .byte 198
188         .byte 200
189         .byte 203
190         .byte 205
191         .byte 208
192         .byte 210
193         .byte 213
194         .byte 215
195         .byte 217
196         .byte 219
197         .byte 221
198         .byte 224
199         .byte 226
200         .byte 228
201         .byte 229
202         .byte 231
203         .byte 233
204         .byte 235
205         .byte 236
206         .byte 238
207         .byte 239
208         .byte 241
209         .byte 242
210         .byte 244
211         .byte 245
212         .byte 246
213         .byte 247
214         .byte 248
215         .byte 249
216         .byte 250
217         .byte 251
218         .byte 251
219         .byte 252
220         .byte 253
221         .byte 253
222         .byte 254
223         .byte 254
224         .byte 254
225         .byte 254
226         .byte 254
227         .byte 255
228         .byte 254
229         .byte 254
230         .byte 254
231         .byte 254
232         .byte 254
233         .byte 253
234         .byte 253
235         .byte 252
236         .byte 251
237         .byte 251
238         .byte 250
239         .byte 249
240         .byte 248
241         .byte 247
242         .byte 246
243         .byte 245
244         .byte 244
245         .byte 242
246         .byte 241
247         .byte 239
248         .byte 238
249         .byte 236
250         .byte 235
251         .byte 233
252         .byte 231
253         .byte 229
254         .byte 228
255         .byte 226
256         .byte 224
257         .byte 221
258         .byte 219
259         .byte 217
260         .byte 215
261         .byte 213
262         .byte 210
263         .byte 208
264         .byte 205
265         .byte 203
266         .byte 200
267         .byte 198
268         .byte 195
269         .byte 193
270         .byte 190
271         .byte 187
272         .byte 184
273         .byte 182
274         .byte 179
275         .byte 176
276         .byte 173
277         .byte 170
278         .byte 167
279         .byte 164
280         .byte 161
281         .byte 158
282         .byte 155
283         .byte 152
284         .byte 149
285         .byte 146
286         .byte 143
287         .byte 139
288         .byte 136
289         .byte 133
290         .byte 130
291         .byte 127
292         .byte 124
293         .byte 121
294         .byte 118
295         .byte 115
296         .byte 111
297         .byte 108
298         .byte 105
299         .byte 102
300         .byte 99
301         .byte 96
302         .byte 93
303         .byte 90
304         .byte 87
305         .byte 84
306         .byte 81
307         .byte 78
308         .byte 75
309         .byte 72
310         .byte 70
311         .byte 67
312         .byte 64
313         .byte 61
314         .byte 59
315         .byte 56
316         .byte 54
317         .byte 51
318         .byte 49
319         .byte 46
320         .byte 44
321         .byte 41
322         .byte 39
323         .byte 37
324         .byte 35
325         .byte 33
326         .byte 30
327         .byte 28
328         .byte 26
329         .byte 25
330         .byte 23
331         .byte 21
332         .byte 19
333         .byte 18
334         .byte 16
335         .byte 15
336         .byte 13
337         .byte 12
338         .byte 10
339         .byte 9
340         .byte 8
341         .byte 7
342         .byte 6
343         .byte 5
344         .byte 4
345         .byte 3
346         .byte 3
347         .byte 2
348         .byte 1
349         .byte 1
350         .byte 0
351         .byte 0
352         .byte 0
353         .byte 0
354         .byte 0
355         .byte 0
356         .byte 0
357         .byte 0
358         .byte 0
359         .byte 0
360         .byte 0
361         .byte 1
362         .byte 1
363         .byte 2
364         .byte 3
365         .byte 3
366         .byte 4
367         .byte 5
368         .byte 6
369         .byte 7
370         .byte 8
371         .byte 9
372         .byte 10
373         .byte 12
374         .byte 13
375         .byte 15
376         .byte 16
377         .byte 18
378         .byte 19
379         .byte 21
380         .byte 23
381         .byte 25
382         .byte 26
383         .byte 28
384         .byte 30
385         .byte 33
386         .byte 35
387         .byte 37
388         .byte 39
389         .byte 41
390         .byte 44
391         .byte 46
392         .byte 49
393         .byte 51
394         .byte 54
395         .byte 56
396         .byte 59
397         .byte 61
398         .byte 64
399         .byte 67
400         .byte 70
401         .byte 72
402         .byte 75
403         .byte 78
404         .byte 81
405         .byte 84
406         .byte 87
407         .byte 90
408         .byte 93
409         .byte 96
410         .byte 99
411         .byte 102
412         .byte 105
413         .byte 108
414         .byte 111
415         .byte 115
416         .byte 118
417         .byte 121
418         .byte 124