speaker & timer tests
[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 osc_freq        equ 1193182
11 PIT_DATA0       equ 40h
12 PIT_DATA2       equ 42h
13 PIT_CMD         equ 43h
14 PIT_CMD_CHAN0   equ 00h
15 PIT_CMD_CHAN1   equ 40h
16 PIT_CMD_CHAN2   equ 80h
17 PIT_CMD_HILO    equ 30h
18 PIT_CMD_SQWAVE  equ 06h
19 KB_CTRL         equ 61h
20
21 %define DIV_ROUND(a, b) ((a) / (b) + ((a) % (b)) / ((b) / 2))
22
23 %macro setcursor 2
24         mov dl, %1
25         mov dh, %2
26         xor bx, bx
27         mov ah, 2
28         int 10h
29 %endmacro
30
31 %macro spkon 0
32         in al, KB_CTRL
33         or al, 3
34         out KB_CTRL, al
35 %endmacro
36 %macro spkoff 0
37         in al, KB_CTRL
38         and al, 0fch
39         out KB_CTRL, al
40 %endmacro
41
42         xor ax, ax
43         mov ds, ax
44         mov ss, ax
45         mov sp, 7c00h
46
47         call init_spk
48
49         mov ax, 13h
50         int 10h
51         mov ax, 0a000h
52         mov es, ax
53
54         mov ax, 0303h
55         mov cx, 32000
56         xor di, di
57         rep stosw
58
59         setcursor 10, 12
60         mov si, str1
61         call textout
62         setcursor 12, 13
63         mov si, str2
64         call textout
65
66 infloop:
67         hlt
68         jmp infloop
69
70 init_spk:
71         xor ax, ax
72         mov [32], ax
73         mov word [34], timer_intr
74
75         mov al, PIT_CMD_CHAN2 | PIT_CMD_HILO | PIT_CMD_SQWAVE
76         out PIT_CMD, al
77         mov ax, DIV_ROUND(osc_freq, 440)
78         out PIT_DATA2, al
79         mov al, ah
80         out PIT_DATA2, al
81
82         spkon
83
84         sti
85         ret
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         spkoff
100         mov al, 20h
101         out 20h, al     ; EOI
102         iret
103
104 str1:   db 'message message blah',0
105 str2:   db 'Michael & Athina',0
106
107         times 446-($-$$) db 0
108         dd 00212080h
109         dd 0820280ch
110         dd 00000800h
111         dd 0001f800h
112         times 510-($-$$) db 0
113         dw 0aa55h
114
115 ; vi:ft=nasm ts=8 sts=8 sw=8: