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