📄 keyboardpinao.asm
字号:
; present date: 2003.10.17
; last modify date:2003.10.28
; auther : deng rui
; ver : 1.01
;functiong : press the 1 to 8 key then sound the tone, f6 pressed exit progarm
.model small
.stack
.code
;--------- main program is use to save int 09h and set 09 intrrupte to the
; sub progarm key_int ,then remain in ram and exit.
main proc far ; show intall message in screen
mov ax,@code
mov ds,ax
mov es,ax
mov dx,offset msg_install
mov ah,9h
int 21h
get_arrower: push es ; store the old 09h intrrupte arrower
mov ah,35h ; to the var key_arrower
mov al,09h
int 21h
mov si,offset key_arrower
mov [si],bx
mov [si+2],es
pop es
set_arrower: mov ax,seg key_int ;set the intrrupt 09h to the key_int
mov ds,ax ; sub program
mov dx ,offset key_int
mov al,09h
mov ah,25h
int 21h
exit: mov ah,31h
mov al,0
mov dx,((prog_length+15)/16)+16
int 21h
main endp
;---------- this is the new key_board intrrupt
key_int proc near
push ds
push ax
push bx
push es
push di
push bp
push cx
push dx
in al,60h ;read the data from the keyboard I/O port
push ax ;and reset the keyboard
in al,61h
mov ah,al
or al,80h
out 61h,al
xchg ah,al
out 61h,al
pop ax ;just whether the action is press or release key
test al,80h
jnz release
key_press: ;if the key pressed call set_tone sub function
cmp al,40h
jz restore ;if f6 pressed ,the exit the progarm
call set_tone ; call for set tone of speaker
jmp continue
release: ;if the key is released ,the turn off the sound
mov al,30h
out 61h,al
mov ax,@code ; update the last_key
mov ds,ax
mov bx,offset last_key
mov byte ptr [bx],0 ;set the last_key to zero
jmp continue
restore: ; if the f6 key pressed, then restore the
mov ax,@code ; 9 intrupte
mov ds,ax
mov bx,offset key_arrower
sub ax,ax
mov es,ax
mov di,24h
mov ax,[bx]
mov es:[di],ax
mov ax,[bx+2]
mov es:[di+2],ax
continue: mov al,20h
out 20h,al
pop dx
pop cx
pop bp
pop di
pop es
pop bx
pop ax
pop ds
iret
key_int endp
;---------- the sub is use to set the timer 2
set_tone proc near
push ax
push ds
push bx
push dx
push si
cmp al,02h ;just if the key of pressed is between 1-8
jl exit1
cmp al,09h
jg exit1
mov bx,@code ;just if the key is new key
mov ds,bx
mov bx, offset last_key
cmp al,[bx]
jnz new_key
jmp exit1
new_key: mov [bx],al ;store the new key
sub al,02h ; get the right table index
mov dl,02h
mul dl
mov si,ax
mov ax,@code ;set the music data in the table to ax
mov ds,ax
mov bx,offset table
mov ax,[bx][si]
push ax ; set the timer2 freq data
mov al,10111110b
out 43h,al
pop ax
out 42h,al
xchg ah,al
out 42h,al
mov al,3fh ; turn on the speaker
out 61h,al
exit1:
pop si
pop dx
pop bx
pop ds
pop ax
ret
set_tone endp
last_key db 10
table dw 523 ;1
dw 494 ;2
dw 440 ;3
dw 392 ;4
dw 349 ;5
dw 330 ;6
dw 294 ;7
dw 262 ;8
msg_install db 'The program installed! ',0dh,0ah,'$'
key_arrower dw 0,0
;msg db 'This is a sample string!',0dh,0ah,'$'
prog_length equ $-main
end main
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -