1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
| bits 16 ; tell the assembler we want 16 bit code
org 0x7C00 ; add 0x7C00 to label addresses
portB equ 61h ; i/o port B
keybd2 equ 7h ; keyboard input, no echo
doscall equ 21h ; DOS interrupt
cont_c equ 03h ; control-c ASCII code
;***********************
; main
;***********************
main:
read_key:
mov ah, keybd2 ; keyboard, no echo
int doscall
mov dl,al ; print it
push ax
mov ah,2
int doscall
pop ax
sub al,31h ; get number
and al,00000111b ; mask off 5 bits
; get frequency for each number
cmp al,1d
jnz chk2
mov bx,1196h ; c
chk2:
cmp al,2d
jnz chk3
mov bx,0fach ; d
chk3:
cmp al,3d
jnz chk4
mov bx,0DF6h ; e
chk4:
cmp al,4d
jnz chk5
mov bx,0D47h ; f
chk5:
cmp al,5d
jnz chk6
mov bx,0BC1h ; g
chk6:
cmp al,6d
jnz chk7
mov bx,0A79h ; a
chk7:
cmp al,7d
jnz chk8
mov bx,953h ; b
chk8:
cmp al,8d
jnz chk9
mov bx,8CBh ; c
chk9:
cmp al,9d
jnz endchk
mov bx,7AAh ; d
endchk:
; put pitch in timer, turn on tone
mov al,10110110b ; magic number
out 43h,al ; in timer
mov ax,bx ; pitch
out 42h,al ; lsb into timer
mov al,ah
out 42h,al ; msb into timer
in al,portB
or al,3 ; turn on speaker
out portB,al
; wait, then turn off speaker
mov cx,0fh ; outer delay
more2:
push cx
mov cx,0ffffh ; delay
more:
loop more
pop cx
loop more2
in al,portB
and al,11111100b ; turn off speaker
out portB,al
jmp read_key ; return to start
times 510-($-$$) db 0
dw 0AA55h ; some BIOSes require this signature |
Partager