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