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