29f0e5c0ed94dca56c817534fc64f7303c80a6d8
[bootcard] / bootcard.asm
1 ; boot me!
2 ; nasm -f bin -o foo.img foo.asm
3 ; cat foo.img >/dev/<usbstick>
4
5         org 7c00h
6         bits 16
7
8 nticks  equ 7e00h
9 tmoffs  equ 7e04h
10 musptr  equ 7e08h
11 cmap    equ 7e14h
12
13 %macro stimer 2
14         mov al, (%1 << 6) | 36h
15         out 43h, al
16         mov ax, %2
17         out 40h + %1, al
18         mov al, ah
19         out 40h + %1, al
20 %endmacro
21
22 start:  xor ax, ax
23         mov ds, ax
24         mov es, ax
25         mov ss, ax
26         mov sp, 7c00h
27
28         mov di, nticks
29         mov cx, 16
30         rep stosw
31
32         cli
33         mov word [32], tintr
34         mov [34], ax
35         stimer 0, 5966
36
37         mov ax, 13h
38         int 10h
39         push 0a000h
40         pop es
41
42         mov al, 16
43         mov di, 48640
44         mov bx, 11
45 .bars:
46         mov cx, 1280
47         rep stosb
48         inc al
49         dec bx
50         jnz .bars
51
52         mov dx, 100ch
53         xor bx, bx
54         mov ah, 2
55         int 10h
56         mov si, str1
57 .txout: mov al, [si]
58         and al, al
59         jz .done
60         mov ah, 0eh
61         mov bx, 82
62         int 10h
63         inc si
64         jmp .txout
65 .done:
66         sti
67
68 mainloop:
69         mov dx, 3dah
70 .invb:  in al, dx
71         and al, 8
72         jnz .invb
73 .novb:  in al, dx
74         and al, 8
75         jz .novb
76
77 drawbg:
78         mov bx, 200
79         xor di, di
80 .fillgrad:
81         mov ax, bx
82         mov ah, al
83         mov cx, 2400
84         rep stosw
85         inc bx
86         cmp bx, 208
87         jnz .fillgrad
88
89         mov cx, 320
90         mov bp, sp
91 .mnt:   mov [bp - 2], cx
92         fild word [bp - 2]
93         fidiv word [w30]
94         fsincos
95         fiadd word [w5]
96         fimul word [w5]
97         fistp word [bp - 2]
98         fstp st0
99         mov bx, [bp - 2]
100         add bx, 84
101         imul bx, bx, 320
102         add bx, cx
103 .mntcol:
104         mov byte [es:bx], 0
105         add bx, 320
106         cmp bx, 128 * 320
107         jb .mntcol
108
109         dec cx
110         jnz .mnt
111
112         mov dx, 3c8h
113         mov al, 16
114         out dx, al
115         inc dx
116         mov si, cmap
117         mov cx, 16 * 3
118         rep outsb
119
120         jmp mainloop
121
122 tintr:
123         pusha
124         mov ax, [nticks]
125         inc ax
126         mov [nticks], ax
127
128         mov bx, [musptr]
129         cmp bx, 22*3
130         jnz .skiploop
131         xor bx, bx
132         mov [tmoffs], ax
133 .skiploop:
134         xor cx, cx
135         mov cl, [music + bx]
136         shl cx, 4
137         sub ax, [tmoffs]
138         cmp ax, cx
139         jb .end
140
141         mov ax, [music + 1 + bx]
142         add bx, 3
143         mov [musptr], bx
144         test ax, ax
145         jz .off
146
147         mov bx, ax
148         shr bx, 9
149         sub bx, 13
150         imul bx, bx, 3
151         mov byte [cmap + bx], 3fh
152         mov word [cmap + bx + 1], 2f2fh
153
154         mov bx, ax
155         stimer 2, bx
156         in al, 61h
157         or al, 3
158         out 61h, al
159         jmp .end
160
161 .off:   in al, 61h
162         and al, 0fch
163         out 61h, al
164
165 .end:   test word [nticks], 1
166         jnz .eoi
167         mov cx, 16 * 3
168         mov si, cmap
169 .fadecol:
170         lodsb
171         test al, al
172         jz .skipdec
173         dec al
174         mov [si-1], al
175 .skipdec:
176         dec cx
177         jnz .fadecol
178         
179 .eoi:   mov al, 20h
180         out 20h, al
181         popa
182         iret
183
184 str1:   db 'Michael ',3,' Athena',0
185
186 music:  dd 0a2f8f00h, 0a11123a1h, 23a11423h, 28000023h, 0be322f8fh, 25c0391fh
187         dd 4b23a13ch, 8f500000h, 23a15a2fh, 641ab161h, 476e1ab1h, 1fbe751ch
188         dd 8223a178h, 0a18925c0h, 1fbe8c23h, 0aa0000a0h
189         dw 0
190
191 w5:     dw 5
192 w30:    dw 30
193
194         times 446-($-$$) db 0
195         dd 00212080h
196         dd 0820280ch
197         dd 00000800h
198         dd 0001f800h
199
200         times 510-($-$$) db 0
201         dw 0aa55h