foo
[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 data_start      equ 7e00h
10 nticks          equ data_start
11 muscur          equ nticks + 4
12
13 osc_freq        equ 1193182
14 PIT_DATA0       equ 40h
15 PIT_DATA2       equ 42h
16 PIT_CMD         equ 43h
17 PIT_CMD_CHAN0   equ 00h
18 PIT_CMD_CHAN1   equ 40h
19 PIT_CMD_CHAN2   equ 80h
20 PIT_CMD_HILO    equ 30h
21 PIT_CMD_SQWAVE  equ 06h
22 KB_CTRL         equ 61h
23
24 %define DIV_ROUND(a, b) ((a) / (b) + ((a) % (b)) / ((b) / 2))
25
26 %macro setcursor 2
27         mov dl, %1
28         mov dh, %2
29         xor bx, bx
30         mov ah, 2
31         int 10h
32 %endmacro
33
34 %macro spkon 0
35         in al, KB_CTRL
36         or al, 3
37         out KB_CTRL, al
38 %endmacro
39 %macro spkoff 0
40         in al, KB_CTRL
41         and al, 0fch
42         out KB_CTRL, al
43 %endmacro
44
45         xor ax, ax
46         mov ds, ax
47         mov ss, ax
48         mov sp, 7c00h
49
50         mov dword [nticks], 0
51         mov dword [muscur], 0
52         call init_spk
53
54         mov ax, 13h
55         int 10h
56         mov ax, 0a000h
57         mov es, ax
58
59         mov ax, 0303h
60         mov cx, 32000
61         xor di, di
62         rep stosw
63
64         setcursor 10, 12
65         mov si, str1
66         call textout
67         setcursor 12, 13
68         mov si, str2
69         call textout
70
71         sti
72
73 infloop:
74         hlt
75         jmp infloop
76
77 init_spk:
78         mov word [32], timer_intr
79         mov word [34], 0
80         ret
81
82 textout:
83         mov al, [si]
84         and al, al
85         jz .done
86         mov ah, 0eh
87         mov bx, 0fh
88         int 10h
89         inc si
90         jmp textout
91 .done:  ret
92
93 timer_intr:
94         mov ax, [nticks]
95         inc ax
96         mov [nticks], ax
97
98         mov bx, [muscur]
99         shl bx, 2
100         mov cx, [music + bx]
101         cmp cx, 0ffffh
102         jz .off
103         cmp ax, cx
104         jb .eoi
105
106         inc dword [muscur]
107         mov ax, [music + 2 + bx] ; grab timeout
108         test ax, ax
109         jz .off
110         mov bx, ax
111
112         mov al, PIT_CMD_CHAN2 | PIT_CMD_HILO | PIT_CMD_SQWAVE
113         out PIT_CMD, al
114         mov ax, bx
115         out PIT_DATA2, al
116         mov al, ah
117         out PIT_DATA2, al
118         spkon
119         jmp .eoi
120
121 .off:   spkoff
122
123 .eoi:   mov al, 20h
124         out 20h, al     ; EOI
125         iret
126
127 str1:   db 'message message blah',0
128 str2:   db 'Michael & Athina',0
129
130 music:
131         dw 0, 500
132         dw 10, 0
133         dw 20, 2000
134         dw 30, 0
135         dw 40, 500
136         dw 50, 0
137         dw 60, 2000
138         dw 70, 0
139         dw 0ffffh, 0
140
141         times 446-($-$$) db 0
142         dd 00212080h
143         dd 0820280ch
144         dd 00000800h
145         dd 0001f800h
146         times 510-($-$$) db 0
147         dw 0aa55h
148
149 ; vi:ft=nasm ts=8 sts=8 sw=8: