pointless effect in boot2, just for fun
[bootcensus] / src / boot / boot2.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 # this is the second-stage boot loader
18         .code16
19         .section .boot2,"a"
20
21         .extern ser_putchar
22
23         mov $0x13, %ax
24         int $0x10
25
26         movb $10, %al
27         call ser_putchar
28
29         # copy palette
30         mov $logo_pal, %si
31         xor %cl, %cl
32
33 0:      xor %eax, %eax
34         mov $0x3c8, %dx
35         movb %cl, %al
36         outb %al, %dx
37         #### DBG
38         call ser_print_num
39         mov $58, %al
40         call ser_putchar
41         mov $32, %al
42         call ser_putchar
43         xor %eax, %eax
44         ####
45         inc %dx
46         # red
47         movb (%si), %al
48         inc %si
49         shr $2, %al
50         outb %al, %dx
51         #### DBG
52         call ser_print_num
53         mov $32, %al
54         call ser_putchar
55         xor %eax, %eax
56         ####
57         # green
58         movb (%si), %al
59         inc %si
60         shr $2, %al
61         outb %al, %dx
62         #### DBG
63         call ser_print_num
64         mov $32, %al
65         call ser_putchar
66         xor %eax, %eax
67         ####
68         # blue
69         movb (%si), %al
70         inc %si
71         shr $2, %al
72         outb %al, %dx
73         #### DBG
74         call ser_print_num
75         mov $32, %al
76         call ser_putchar
77         mov $10, %al
78         call ser_putchar
79         xor %eax, %eax
80         ####
81         add $1, %cl
82         jnc 0b
83
84         # copy pixels
85         pushw $0xa000
86         pop %es
87         mov $logo_pix, %eax
88         shr $4, %eax
89         #mov %ax, %ds
90         mov %ax, %gs
91         #mov $16000, %ecx
92         #rep movsl
93
94         mov $sintab, %eax
95         shr $4, %eax
96         mov %ax, %fs
97
98 .Lframeloop:
99         xor %di, %di
100
101         movw $0, yval
102 .Lyloop:
103         movw $0, xval
104 .Lxloop:
105         # calc src scanline address -> bx
106         mov yval, %bx
107         shl $2, %bx
108         add frameno, %bx
109         xor %bh, %bh
110         mov %fs:(%bx), %cl
111         xor %ch, %ch
112         shr $5, %cx
113
114         mov yval, %ax
115         add %cx, %ax
116         # bounds check
117         cmp $200, %ax
118         jl 0f
119         mov $199, %ax
120
121 0:      mov %ax, %bx
122         shl $8, %ax
123         shl $6, %bx
124         add %ax, %bx
125
126         # calc src x offset -> si
127         mov xval, %ax
128         shl $2, %ax
129         add frameno, %ax
130         xor %ah, %ah
131         mov %ax, %si
132         mov %fs:(%si), %cl
133         xor %ch, %ch
134         shr $5, %cx
135
136         mov xval, %ax
137         add %cx, %ax
138         # bounds check
139         cmp $320, %ax
140         jl 0f
141         mov $319, %ax
142
143 0:      mov %ax, %si
144
145         mov %gs:(%bx, %si), %al
146
147         mov %al, %es:(%di)
148         inc %di
149
150         incw xval
151         cmpw $320, xval
152         jnz .Lxloop
153
154         incw yval
155         cmpw $200, yval
156         jnz .Lyloop
157
158         incw frameno
159
160         # wait vsync
161         mov $0x3da, %dx
162 0:      in %dx, %al
163         and $8, %al
164         jnz 0b
165 0:      in %dx, %al
166         and $8, %al
167         jz 0b
168         jmp .Lframeloop
169
170         cli
171         hlt
172
173 xval: .word 0
174 yval: .word 0
175 frameno: .word 0
176
177         # expects string pointer in ds:si
178 ser_print_str:
179         pusha
180
181 0:      mov (%si), %al
182         cmp $0, %al
183         jz .Lend
184         call ser_putchar
185         inc %si
186         jmp 0b
187
188 .Lend:  popa
189         ret
190
191
192         # expects number in eax
193 ser_print_num:
194         # save registers
195         pusha
196
197         movw $numbuf + 16, %si
198         movb $0, (%si)
199         mov $10, %ebx
200 .Lconvloop:
201         xor %edx, %edx
202         div %ebx
203         add $48, %dl
204         dec %si
205         mov %dl, (%si)
206         cmp $0, %eax
207         jnz .Lconvloop
208
209         call ser_print_str
210
211         # restore regs
212         popa
213         ret
214
215 numbuf: .space 16
216
217 logo_pal:
218         .incbin "logo.pal"
219
220         .align 16
221 logo_pix:
222         .incbin "logo.raw"
223
224 sintab:
225         .byte 127
226         .byte 130
227         .byte 133
228         .byte 136
229         .byte 139
230         .byte 143
231         .byte 146
232         .byte 149
233         .byte 152
234         .byte 155
235         .byte 158
236         .byte 161
237         .byte 164
238         .byte 167
239         .byte 170
240         .byte 173
241         .byte 176
242         .byte 179
243         .byte 182
244         .byte 184
245         .byte 187
246         .byte 190
247         .byte 193
248         .byte 195
249         .byte 198
250         .byte 200
251         .byte 203
252         .byte 205
253         .byte 208
254         .byte 210
255         .byte 213
256         .byte 215
257         .byte 217
258         .byte 219
259         .byte 221
260         .byte 224
261         .byte 226
262         .byte 228
263         .byte 229
264         .byte 231
265         .byte 233
266         .byte 235
267         .byte 236
268         .byte 238
269         .byte 239
270         .byte 241
271         .byte 242
272         .byte 244
273         .byte 245
274         .byte 246
275         .byte 247
276         .byte 248
277         .byte 249
278         .byte 250
279         .byte 251
280         .byte 251
281         .byte 252
282         .byte 253
283         .byte 253
284         .byte 254
285         .byte 254
286         .byte 254
287         .byte 254
288         .byte 254
289         .byte 255
290         .byte 254
291         .byte 254
292         .byte 254
293         .byte 254
294         .byte 254
295         .byte 253
296         .byte 253
297         .byte 252
298         .byte 251
299         .byte 251
300         .byte 250
301         .byte 249
302         .byte 248
303         .byte 247
304         .byte 246
305         .byte 245
306         .byte 244
307         .byte 242
308         .byte 241
309         .byte 239
310         .byte 238
311         .byte 236
312         .byte 235
313         .byte 233
314         .byte 231
315         .byte 229
316         .byte 228
317         .byte 226
318         .byte 224
319         .byte 221
320         .byte 219
321         .byte 217
322         .byte 215
323         .byte 213
324         .byte 210
325         .byte 208
326         .byte 205
327         .byte 203
328         .byte 200
329         .byte 198
330         .byte 195
331         .byte 193
332         .byte 190
333         .byte 187
334         .byte 184
335         .byte 182
336         .byte 179
337         .byte 176
338         .byte 173
339         .byte 170
340         .byte 167
341         .byte 164
342         .byte 161
343         .byte 158
344         .byte 155
345         .byte 152
346         .byte 149
347         .byte 146
348         .byte 143
349         .byte 139
350         .byte 136
351         .byte 133
352         .byte 130
353         .byte 127
354         .byte 124
355         .byte 121
356         .byte 118
357         .byte 115
358         .byte 111
359         .byte 108
360         .byte 105
361         .byte 102
362         .byte 99
363         .byte 96
364         .byte 93
365         .byte 90
366         .byte 87
367         .byte 84
368         .byte 81
369         .byte 78
370         .byte 75
371         .byte 72
372         .byte 70
373         .byte 67
374         .byte 64
375         .byte 61
376         .byte 59
377         .byte 56
378         .byte 54
379         .byte 51
380         .byte 49
381         .byte 46
382         .byte 44
383         .byte 41
384         .byte 39
385         .byte 37
386         .byte 35
387         .byte 33
388         .byte 30
389         .byte 28
390         .byte 26
391         .byte 25
392         .byte 23
393         .byte 21
394         .byte 19
395         .byte 18
396         .byte 16
397         .byte 15
398         .byte 13
399         .byte 12
400         .byte 10
401         .byte 9
402         .byte 8
403         .byte 7
404         .byte 6
405         .byte 5
406         .byte 4
407         .byte 3
408         .byte 3
409         .byte 2
410         .byte 1
411         .byte 1
412         .byte 0
413         .byte 0
414         .byte 0
415         .byte 0
416         .byte 0
417         .byte 0
418         .byte 0
419         .byte 0
420         .byte 0
421         .byte 0
422         .byte 0
423         .byte 1
424         .byte 1
425         .byte 2
426         .byte 3
427         .byte 3
428         .byte 4
429         .byte 5
430         .byte 6
431         .byte 7
432         .byte 8
433         .byte 9
434         .byte 10
435         .byte 12
436         .byte 13
437         .byte 15
438         .byte 16
439         .byte 18
440         .byte 19
441         .byte 21
442         .byte 23
443         .byte 25
444         .byte 26
445         .byte 28
446         .byte 30
447         .byte 33
448         .byte 35
449         .byte 37
450         .byte 39
451         .byte 41
452         .byte 44
453         .byte 46
454         .byte 49
455         .byte 51
456         .byte 54
457         .byte 56
458         .byte 59
459         .byte 61
460         .byte 64
461         .byte 67
462         .byte 70
463         .byte 72
464         .byte 75
465         .byte 78
466         .byte 81
467         .byte 84
468         .byte 87
469         .byte 90
470         .byte 93
471         .byte 96
472         .byte 99
473         .byte 102
474         .byte 105
475         .byte 108
476         .byte 111
477         .byte 115
478         .byte 118
479         .byte 121
480         .byte 124