- reduced the binary size by using bytes for music timestamps and looping
[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
13 %macro setcur 2
14         mov dx, %1 | (%2 << 8)
15         xor bx, bx
16         mov ah, 2
17         int 10h
18 %endmacro
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, 6
46         rep stosw
47
48         mov word [32], tintr
49         mov [34], ax
50
51         stimer 0, 5966
52
53         mov ax, 13h
54         int 10h
55         push 0a000h
56         pop es
57
58         setcur 10, 0
59         mov si, str1
60         call textout
61         setcur 12, 1
62         mov si, str2
63         call textout
64
65         sti
66
67 mainloop:
68         mov dx, 3dah
69 .invb:  in al, dx
70         and al, 8
71         jnz .invb
72 .novb:  in al, dx
73         and al, 8
74         jz .novb
75
76         call drawbg
77
78         jmp mainloop
79
80 drawbg:
81         mov bx, 200
82         mov di, 5120
83 .fillgrad:
84         mov ax, bx
85         mov ah, al
86         mov cx, 2400    ; 15 lines
87         rep stosw
88         inc bx
89         cmp bx, 208
90         jnz .fillgrad
91
92         ; mountains
93         mov cx, 320
94         mov bp, sp
95 .mnt:   mov [bp - 2], cx
96         fild word [bp - 2]
97         fidiv word [w30]
98         fsincos
99         fiadd word [w5]
100         fimul word [w5]
101         fistp word [bp - 2]
102         fstp st0
103         mov bx, [bp - 2]
104         add bx, 100
105         imul bx, bx, 320
106         add bx, cx
107 .mntcol:
108         mov byte [es:bx], 0
109         add bx, 320
110         cmp bx, 64000
111         jb .mntcol
112
113         dec cx
114         jnz .mnt
115         
116         ret
117
118
119 textout:
120         mov al, [si]
121         and al, al
122         jz .done
123         mov ah, 0eh
124         mov bx, 82
125         int 10h
126         inc si
127         jmp textout
128 .done:  ret
129
130 tintr:
131         pusha
132         mov ax, [nticks]
133         inc ax
134         mov [nticks], ax
135
136         mov bx, [musptr]
137         cmp bx, 23*3
138         jnz .skiploop
139         xor bx, bx
140         mov [tmoffs], ax
141 .skiploop:
142         xor cx, cx
143         mov cl, [music + bx]
144         shl cx, 4
145         sub ax, [tmoffs]
146         cmp ax, cx
147         jb .eoi
148
149         mov ax, [music + 1 + bx]
150         add bx, 3
151         mov [musptr], bx
152         test ax, ax
153         jz .off
154         mov bx, ax
155         stimer 2, bx
156         spkon
157         jmp .eoi
158
159 .off:   spkoff
160
161 .eoi:   mov al, 20h
162         out 20h, al
163         popa
164         iret
165
166 str1:   db 'message blah',0
167 str2:   db 'Michael & Athena',0
168
169 music:  dd 0a2f8f00h, 0a11123a1h, 23a11423h, 28000023h, 0be322f8fh, 25c0391fh
170         dd 4b23a13ch, 8f500000h, 23a15a2fh, 641ab161h, 476e1ab1h, 1fbe751ch
171         dd 8223a178h, 0a18925c0h, 1fbe8c23h, 0aa0000a0h
172         dw 0
173
174 w5:     dw 5
175 w30:    dw 30
176
177         times 446-($-$$) db 0
178         dd 00212080h
179         dd 0820280ch
180         dd 00000800h
181         dd 0001f800h
182
183         times 510-($-$$) db 0
184         dw 0aa55h
185
186 ; vi:ft=nasm ts=8 sts=8 sw=8: