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