* mikeOS 16 bit and amd64 baremetal
[mascara-docs.git] / i86 / mikeos-4.1.2 / programs / keyboard.asm
blob20ef8ae49bdd8029b4cdd6f4365bacab5712927c
1 ; ------------------------------------------------------------------
2 ; Music keyboard -- Use the keyboard to play notes via the PC speaker
3 ; Use Z key rightwards for an octave
4 ; ------------------------------------------------------------------
7 BITS 16
8 %INCLUDE "mikedev.inc"
9 ORG 32768
12 start:
13 call os_hide_cursor
15 call os_clear_screen
17 mov ax, mus_kbd_title_msg ; Set up screen
18 mov bx, mus_kbd_footer_msg
19 mov cx, WHITE_ON_LIGHT_RED
20 call os_draw_background
22 mov bl, BLACK_ON_WHITE ; White block to draw keyboard on
23 mov dh, 4
24 mov dl, 5
25 mov si, 69
26 mov di, 21
27 call os_draw_block
31 ; Now lots of loops to draw the keyboard
33 mov dl, 24 ; Top line of box
34 mov dh, 6
35 call os_move_cursor
37 mov ah, 0Eh
38 mov al, 196
40 mov cx, 31
41 .loop1:
42 int 10h
43 loop .loop1
46 mov dl, 24 ; Bottom line of box
47 mov dh, 18
48 call os_move_cursor
50 mov ah, 0Eh
51 mov al, 196
53 mov cx, 31
54 .loop2:
55 int 10h
56 loop .loop2
60 mov dl, 23 ; Top-left corner
61 mov dh, 6
62 call os_move_cursor
64 mov al, 218
65 int 10h
68 mov dl, 55 ; Top-right corner
69 mov dh, 6
70 call os_move_cursor
72 mov al, 191
73 int 10h
76 mov dl, 23 ; Bottom-left corner
77 mov dh, 18
78 call os_move_cursor
80 mov al, 192
81 int 10h
84 mov dl, 55 ; Bottom-right corner
85 mov dh, 18
86 call os_move_cursor
88 mov al, 217
89 int 10h
92 mov dl, 23 ; Left-hand box line
93 mov dh, 7
94 mov al, 179
95 .loop3:
96 call os_move_cursor
97 int 10h
98 inc dh
99 cmp dh, 18
100 jne .loop3
103 mov dl, 55 ; Right-hand box line
104 mov dh, 7
105 mov al, 179
106 .loop4:
107 call os_move_cursor
108 int 10h
109 inc dh
110 cmp dh, 18
111 jne .loop4
114 mov dl, 23 ; Key-separating lines
115 .biggerloop:
116 add dl, 4
117 mov dh, 7
118 mov al, 179
119 .loop5:
120 call os_move_cursor
121 int 10h
122 inc dh
123 cmp dh, 18
124 jne .loop5
125 cmp dl, 51
126 jne .biggerloop
129 mov al, 194 ; Top of box line joiners
130 mov dh, 6
131 mov dl, 27
132 .loop6:
133 call os_move_cursor
134 int 10h
135 add dl, 4
136 cmp dl, 55
137 jne .loop6
140 mov al, 193 ; Bottom of box line joiners
141 mov dh, 18
142 mov dl, 27
143 .loop7:
144 call os_move_cursor
145 int 10h
146 add dl, 4
147 cmp dl, 55
148 jne .loop7
151 ; And now for the black keys...
153 mov bl, WHITE_ON_BLACK
155 mov dh, 6
156 mov dl, 26
157 mov si, 3
158 mov di, 13
159 call os_draw_block
161 mov dh, 6
162 mov dl, 30
163 mov si, 3
164 mov di, 13
165 call os_draw_block
167 mov dh, 6
168 mov dl, 38
169 mov si, 3
170 mov di, 13
171 call os_draw_block
173 mov dh, 6
174 mov dl, 42
175 mov si, 3
176 mov di, 13
177 call os_draw_block
179 mov dh, 6
180 mov dl, 46
181 mov si, 3
182 mov di, 13
183 call os_draw_block
187 ; And lastly, draw the labels on the keys indicating which
188 ; (computer!) keys to press to get notes
190 mov ah, 0Eh
192 mov dh, 17
193 mov dl, 25
194 call os_move_cursor
196 mov al, 'Z'
197 int 10h
199 add dl, 4
200 call os_move_cursor
201 mov al, 'X'
202 int 10h
204 add dl, 4
205 call os_move_cursor
206 mov al, 'C'
207 int 10h
209 add dl, 4
210 call os_move_cursor
211 mov al, 'V'
212 int 10h
214 add dl, 4
215 call os_move_cursor
216 mov al, 'B'
217 int 10h
219 add dl, 4
220 call os_move_cursor
221 mov al, 'N'
222 int 10h
224 add dl, 4
225 call os_move_cursor
226 mov al, 'M'
227 int 10h
229 add dl, 4
230 call os_move_cursor
231 mov al, ','
232 int 10h
236 ; Phew! We've drawn all the keys now
238 .retry:
239 call os_wait_for_key
241 .nokey: ; Matching keys with notes
242 cmp al, 'z'
243 jne .x
244 mov ax, 4000
245 mov bx, 0
246 call os_speaker_tone
247 jmp .retry
250 cmp al, 'x'
251 jne .c
252 mov ax, 3600
253 mov bx, 0
254 call os_speaker_tone
255 jmp .retry
258 cmp al, 'c'
259 jne .v
260 mov ax, 3200
261 mov bx, 0
262 call os_speaker_tone
263 jmp .retry
267 cmp al, 'v'
268 jne .b
269 mov ax, 3000
270 mov bx, 0
271 call os_speaker_tone
272 jmp .retry
275 cmp al, 'b'
276 jne .n
277 mov ax, 2700
278 mov bx, 0
279 call os_speaker_tone
280 jmp .retry
283 cmp al, 'n'
284 jne .m
285 mov ax, 2400
286 mov bx, 0
287 call os_speaker_tone
288 jmp .retry
291 cmp al, 'm'
292 jne .comma
293 mov ax, 2100
294 mov bx, 0
295 call os_speaker_tone
296 jmp .retry
298 .comma:
299 cmp al, ','
300 jne .space
301 mov ax, 2000
302 mov bx, 0
303 call os_speaker_tone
304 jmp .retry
306 .space:
307 cmp al, ' '
308 jne .q
309 call os_speaker_off
310 jmp .retry
313 cmp al, 'q'
314 je .end
315 cmp al, 'Q'
316 je .end
317 jmp .nowt
319 .nowt:
320 jmp .retry
322 .end:
323 call os_speaker_off
325 call os_clear_screen
327 call os_show_cursor
329 ret ; Back to OS
332 mus_kbd_title_msg db 'MikeOS Music Keyboard', 0
333 mus_kbd_footer_msg db 'Hit keys to play notes, space to silence a note, and Q to quit', 0
336 ; ------------------------------------------------------------------