e582ebdd03f711b4606e6501135e8dbbb6ca8a6e
[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 %macro spkon 0
34         in al, KB_CTRL
35         or al, 3
36         out KB_CTRL, al
37 %endmacro
38 %macro spkoff 0
39         in al, KB_CTRL
40         and al, 0fch
41         out KB_CTRL, al
42 %endmacro
43 %macro settimer 2
44         mov al, (PIT_CMD_CHAN0 + (%1 << 6)) | PIT_CMD_HILO | PIT_CMD_SQWAVE
45         out PIT_CMD, al
46         mov ax, %2
47         out PIT_DATA0 + %1, al
48         mov al, ah
49         out PIT_DATA0 + %1, al
50 %endmacro
51
52         xor ax, ax
53         mov ds, ax
54         mov ss, ax
55         mov sp, 7c00h
56
57         mov dword [nticks], 0
58         mov dword [muscur], 0
59         mov word [32], timer_intr
60         mov word [34], 0
61
62         settimer 0, DIV_ROUND(osc_freq, 250)
63
64         mov ax, 13h
65         int 10h
66         mov ax, 0a000h
67         mov es, ax
68
69         mov ax, 0303h
70         mov cx, 32000
71         xor di, di
72         rep stosw
73
74         setcursor 10, 12
75         mov si, str1
76         call textout
77         setcursor 12, 13
78         mov si, str2
79         call textout
80
81         sti
82
83 infloop:
84         hlt
85         jmp infloop
86
87 textout:
88         mov al, [si]
89         and al, al
90         jz .done
91         mov ah, 0eh
92         mov bx, 0fh
93         int 10h
94         inc si
95         jmp textout
96 .done:  ret
97
98 timer_intr:
99         mov ax, [nticks]
100         inc ax
101         mov [nticks], ax
102
103         mov bx, [muscur]
104         shl bx, 2
105         mov cx, [music + bx]
106         cmp cx, 0ffffh
107         jz .off
108         cmp ax, cx
109         jb .eoi
110
111         inc dword [muscur]
112         mov ax, [music + 2 + bx] ; grab timeout
113         test ax, ax
114         jz .off
115         mov bx, ax
116
117         settimer 2, bx
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: