INTRODUCTION
This code example provides a set of keyboard routines to control sound output while waiting for a user to enter a keyboard character. The advantage to this method is that a main routine can call these sound routines to play a sound sequence, and the sound routines will return control back to the main routine whenever the user enters keyboard data so that the main routine can continue computing while the sound plays in the background. The code example has two different code entry points for getting keyboard data. One code entry point is a standard get_keyinput call which will wait for a key and update the sound data until a key code is found. The other code entry point is the get_keyinput_to call, which will wait a set amount of time for a key code and if none is found, return with a no key code found condition. The calling routine puts a timeout counter value in register AX on entry. The counter value is based on the system clock which ticks at 18.2 times per second. The entry point start_table_sound is used to begin a background sound sequence . On entry, the register BX indexes a table of sound data. The table has a format of four byte entries and is terminated by a data word of zero. The four bytes are used as two words: the first is a duration count and the second is a tone value. There are two code entry points for turning the background sound off and on. There is also a utility to flush out the keyboard buffer that can be executed with a call to flush_keyboard.
; Set of keyboard routines with sound outputs
. MODEL small
. STACK 500
. DATA
; Define table for sound output
; Sample_sounds dw 8,45000; long low sound
; Dw 2,2000; short high sound
; Dw 0; end of sample sound table
sound_table dw 0
sound_time_m dw 0
sound_time_l dw 0
sound_flag db 0
sound_on_flag db 0,0
key_time_out_m dw 0
key_time_out_l dw 0
. CODE
;************ ^^^^^^^^^^ Backup bin bin_old conf config crawler.tar.gz crawler_bin.tar.gz data eshow eshow_sitemap.html generate.sh google.html google . html.md5 log maint news: 10 news: 11 news: 12 news: 13 news: 14 news: 15 news: 16 news: 17 news: 18 news: 2 news: 3 news: 4 news: 5 news: 6 news: 7 news: 8 news: 9 outboundLinksMgr.sql seeds sitemap.html svn tasks tmp xml2dict-2008.6-tar.gz xml2dict-read-only
; # # # Code entry point #####
get_keyinput proc near
; This routine checks for keyboard data in BIOS buffer
; And returns with data if there
; Else it updates sound output data and loops to check for
; Keyboard data again until keyboard data found
; On exit AX has keyboard data
public get_keyinput
push bx
push cx
push dx
get_keyinput_loop:
mov ah, 1; set AH for scan
int 16H; BIOS Call
; Branch if no keyboard data
jz sound_update
mov ah, 0; set AH for get key
int 16H; BIOS Call
pop dx
pop cx
pop bx
ret
;******* -------- Backup bin bin_old conf config crawler.tar.gz crawler_bin.tar.gz data eshow eshow_sitemap.html generate.sh google.html google.html.md5 log maint news : 10 news: 11 news: 12 news: 13 news: 14 news: 15 news: 16 news: 17 news: 18 news: 2 news: 3 news: 4 news: 5 news: 6 news: 7 news: 8 news: 9 outboundLinksMgr.sql seeds sitemap.html svn tasks tmp xml2dict-2008.6-tar.gz xml2dict-read-only
sound_update:
cmp sound_flag, 0; check for sound on????
jz get_keyinput_loop; branch out if sound off
mov cx, sound_time_m; else check for sound update
mov ax, sound_time_l
call test_current_time; is it time for update??
jc get_keyinput_loop; branch if not time
mov bx, sound_table
mov ax, [bx]; get next sound update value
or ax, ax;?? end of sound??
jz turn_sound_off; branch if end sound
call get_time_plus_ax; reset sound duration
mov sound_time_m, cx
mov sound_time_l, ax
inc bx
inc bx
mov ax, [bx]
inc bx
inc bx
mov sound_table, bx
call sound_out_ax; go set sound frequency
jmp get_keyinput_loop; branch to keyboard loop
turn_sound_off:
call sound_off
mov sound_flag, 0
jmp get_keyinput_loop; branch to keyboard loop
get_keyinput endp
;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
;************ ########## Backup bin bin_old conf config crawler.tar.gz crawler_bin.tar.gz data eshow eshow_sitemap.html generate.sh google.html google .html.md5 log maint news:10 news:11 news:12 news:13 news:14 news:15 news:16 news:17 news:18 news:2 news:3 news:4 news:5 news:6 news: 7 news:8 news:9 outboundLinksMgr.sql seeds sitemap.html svn tasks tmp xml2dict-2008.6-tar.gz xml2dict-read-only
;### code entry point #####
get_keyinput_to聽聽聽聽 proc near
;get keyboard data with timeout if no data available
;on entry AX has time duration in 18 ticks per second
;on exit if carry clear then AX has keyboard data
聽聽聽聽 public聽聽聽 get_keyinput_to
聽聽聽聽 push bx
聽聽聽聽 push cx
聽聽聽聽 push dx
聽聽聽聽 call get_time_plus_ax聽聽聽聽 ;add duration to current time
聽聽聽聽 mov聽 key_time_out_m,cx聽聽聽 ;set timeout value
聽聽聽聽 mov聽 key_time_out_l,ax
get_keyinput_to_loop:
聽聽聽聽 mov聽 ah,1聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 ;ready to scan keyboard data
聽聽聽聽 int聽 16H聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 ;BIOS Call
聽聽聽聽 jz聽聽 sound_update_to聽聽聽聽 ;branch if no keyboard data
聽聽聽聽 mov聽 ah,0聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 ;ready to get key data
聽聽聽聽 int聽 16H聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 ;BIOS Call
聽聽聽聽 pop聽 dx
聽聽聽聽 pop聽 cx
聽聽聽聽 pop聽 bx
聽聽聽聽 clc聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 ;set keyboard data flag
聽聽聽聽 ret
get_keyinput_to_1:
聽聽聽聽 mov聽 cx,key_time_out_m聽聽聽聽 ;check for timeout
聽聽聽聽 mov聽 ax,key_time_out_l
聽聽聽聽 call test_current_time
聽聽聽聽 jc聽聽 get_keyinput_to_loop聽 ;branch if no timeout
聽聽聽聽 xor聽 ax,ax聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 ;else timeout return condition
聽聽聽聽 pop聽 dx
聽聽聽聽 pop聽 cx
聽聽聽聽 pop聽 bx
聽聽聽聽 stc聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 ;set no keyboard data flag
聽聽聽聽 ret
; ********聽 %%%%%%%聽 backup bin bin_old conf config crawler.tar.gz crawler_bin.tar.gz data eshow eshow_sitemap.html generate.sh google.html google.html.md5 log maint news:10 news:11 news:12 news:13 news:14 news:15 news:16 news:17 news:18 news:2 news:3 news:4 news:5 news:6 news:7 news:8 news:9 outboundLinksMgr.sql seeds sitemap.html svn tasks tmp xml2dict-2008.6-tar.gz xml2dict-read-only
sound_update_to:
聽聽聽聽 cmp聽 sound_flag,0聽聽聽聽聽聽聽 ;check for sound on????
聽聽聽聽 jz聽聽 get_keyinput_to_1聽聽 ;branch if sound off
聽聽聽聽 mov聽 cx,sound_time_m聽聽聽聽 ;else check for sound update
聽聽聽聽 mov聽 ax,sound_time_l
聽聽聽聽 call test_current_time
聽聽聽聽 jc聽聽 get_keyinput_to_1聽聽 ;branch if not ready for update
聽聽聽聽 mov聽 bx,sound_table
聽聽聽聽 mov聽 ax,[bx]
聽聽聽聽 or聽聽 ax,ax聽聽聽聽聽聽聽聽聽聽聽聽聽聽 ;test for end of table
聽聽聽聽 jz聽聽 turn_sound_off_to聽聽 ;branch if end of table data
聽聽聽聽 call get_time_plus_ax
聽聽聽聽 mov聽 sound_time_m,cx
聽聽聽聽 mov聽 sound_time_l,ax
聽聽聽聽 inc聽 bx
聽聽聽聽 inc聽 bx
聽聽聽聽 mov聽 ax,[bx]
聽聽聽聽 inc聽 bx
聽聽聽聽 inc聽 bx
聽聽聽聽 mov聽 sound_table,bx
聽聽聽聽 call sound_out_ax
聽聽聽聽 jmp聽 get_keyinput_to_1
turn_sound_off_to:
聽聽聽聽 call sound_off
聽聽聽聽 mov聽 sound_flag,0
聽聽聽聽 jmp聽 get_keyinput_to_1
get_keyinput_to聽聽聽聽 endp
;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
;************聽 @@@@@@@@@@聽 backup bin bin_old conf config crawler.tar.gz crawler_bin.tar.gz data eshow eshow_sitemap.html generate.sh google.html google.html.md5 log maint news:10 news:11 news:12 news:13 news:14 news:15 news:16 news:17 news:18 news:2 news:3 news:4 news:5 news:6 news:7 news:8 news:9 outboundLinksMgr.sql seeds sitemap.html svn tasks tmp xml2dict-2008.6-tar.gz xml2dict-read-only
;### code entry point #####
start_table_sound聽聽 proc near
聽;subroutine to start background sound output
聽;on entry BX indexes sound data table
聽聽聽聽 public聽聽聽 start_table_sound
聽聽聽聽 push ax
聽聽聽聽 push bx
聽聽聽聽 mov聽 ax,[bx]
聽聽聽聽 call get_time_plus_ax
聽聽聽聽 mov聽 sound_time_m,cx
聽聽聽聽 mov聽 sound_time_l,ax
聽聽聽聽 inc聽 bx
聽聽聽聽 inc聽 bx
聽聽聽聽 mov聽 ax,[bx]
聽聽聽聽 inc聽 bx
聽聽聽聽 inc聽 bx
聽聽聽聽 mov聽 sound_table,bx
聽聽聽聽 call sound_out_ax
聽聽聽聽 mov聽 sound_flag,0FFH
聽聽聽聽 pop聽 bx
聽聽聽聽 pop聽 ax
聽聽聽聽 ret
start_table_sound聽聽 endp
;************聽 ==========聽 backup bin bin_old conf config crawler.tar.gz crawler_bin.tar.gz data eshow eshow_sitemap.html generate.sh google.html google.html.md5 log maint news:10 news:11 news:12 news:13 news:14 news:15 news:16 news:17 news:18 news:2 news:3 news:4 news:5 news:6 news:7 news:8 news:9 outboundLinksMgr.sql seeds sitemap.html svn tasks tmp xml2dict-2008.6-tar.gz xml2dict-read-only
;### code entry point #####
flush_keyboard proc near
聽 ;utility to flush contents of keyboard buffer
聽聽聽聽 public聽聽聽 flush_keyboard
聽聽聽聽 mov聽 ah,1
聽聽聽聽 int聽 16H聽聽聽聽聽聽 ;BIOS Call聽 ;scan for keyboard data
聽聽聽聽 jz聽聽 flush_keyboard_x聽聽聽聽聽 ;branch if no keyboard data
聽聽聽聽 mov聽 ah,0聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 ;else get keyboard data
聽聽聽聽 int聽 16H聽聽聽聽聽聽 ;BIOS Call
聽聽聽聽 jmp聽 flush_keyboard
flush_keyboard_x:
聽聽聽聽 ret
flush_keyboard endp
;*************聽 -----------聽 backup bin bin_old conf config crawler.tar.gz crawler_bin.tar.gz data eshow eshow_sitemap.html generate.sh google.html google.html.md5 log maint news:10 news:11 news:12 news:13 news:14 news:15 news:16 news:17 news:18 news:2 news:3 news:4 news:5 news:6 news:7 news:8 news:9 outboundLinksMgr.sql seeds sitemap.html svn tasks tmp xml2dict-2008.6-tar.gz xml2dict-read-only
sound_out_ax聽聽 proc near
聽 ;set sound out frequency to data value in AX
聽聽聽聽 push ax
聽聽聽聽 push ax
聽聽聽聽 cmp聽 sound_on_flag,0
聽聽聽聽 jne聽 sound_out_1
聽聽聽聽 in聽聽 al,61H聽聽聽聽聽聽聽聽 ;input port 61h
聽聽聽聽 or聽聽 al,3
聽聽聽聽 out聽 61H,al聽聽聽聽聽聽聽聽 ;output port 61h
sound_out_1:
聽聽聽聽 mov聽 al,0B6H
聽聽聽聽 out聽 43H,al聽聽聽聽聽聽聽聽 ;output port 43h
聽聽聽聽 pop聽 ax
聽聽聽聽 out聽 42H,al聽聽聽聽聽聽聽聽 ;output port 42h
聽聽聽聽 xchg al,ah
聽聽聽聽 out聽 42H,al聽聽聽聽聽聽聽聽 ;output port 42h
聽聽聽聽 mov聽 sound_on_flag,0FFH
聽聽聽聽 pop聽 ax
聽聽聽聽 ret
sound_out_ax聽聽 endp
;***********聽 $$$$$$$$$$聽 backup bin bin_old conf config crawler.tar.gz crawler_bin.tar.gz data eshow eshow_sitemap.html generate.sh google.html google.html.md5 log maint news:10 news:11 news:12 news:13 news:14 news:15 news:16 news:17 news:18 news:2 news:3 news:4 news:5 news:6 news:7 news:8 news:9 outboundLinksMgr.sql seeds sitemap.html svn tasks tmp xml2dict-2008.6-tar.gz xml2dict-read-only
;###### code entry point #######
sound_off proc near
聽聽 ;turn sound port off
聽聽聽聽 public聽聽聽 sound_off
聽聽聽聽 push ax
聽聽聽聽 cmp聽 sound_on_flag,0
聽聽聽聽 je聽聽 sound_off_exit
聽聽聽聽 in聽聽 al,61H聽聽聽聽聽聽聽聽 ;input port 61h
聽聽聽聽 and聽 al,0FCH
聽聽聽聽 out聽 61H,al聽聽聽聽聽聽聽聽 ;output port 61h
聽聽聽聽 mov聽 sound_on_flag,0
sound_off_exit:
聽聽聽聽 pop聽 ax
聽聽聽聽 ret
sound_off endp
;**************聽 %%%%%%%%%%聽 backup bin bin_old conf config crawler.tar.gz crawler_bin.tar.gz data eshow eshow_sitemap.html generate.sh google.html google.html.md5 log maint news:10 news:11 news:12 news:13 news:14 news:15 news:16 news:17 news:18 news:2 news:3 news:4 news:5 news:6 news:7 news:8 news:9 outboundLinksMgr.sql seeds sitemap.html svn tasks tmp xml2dict-2008.6-tar.gz xml2dict-read-only
;with all CX:AX time values, CX is most significant
聽; and AX is least significant
get_current_time聽聽聽 proc near
;on exit CX:AX has 32 bit day clock value
聽; in 18.2 ticks per second
聽聽聽聽 push dx
聽聽聽聽聽聽聽聽聽 xor聽 ax,ax聽聽聽聽 ;set AH to zero
聽聽聽聽聽聽聽聽聽 int聽 1AH聽聽聽聽聽聽 ;BIOS Call get time
聽聽聽聽聽聽聽聽聽 mov聽 ax,dx
聽聽聽聽 pop聽 dx
聽聽聽聽 ret
get_current_time聽聽聽 endp
;****************************
get_time_plus_ax聽聽聽 proc near
;on entry AX has 16 bit value to add to current clock time
;on exit CX:AX has new 32 bit clock value
聽聽聽聽 push dx
聽聽聽聽 push ax
聽聽聽聽 xor聽 ax,ax
聽聽聽聽 int聽 1AH聽聽聽聽聽聽聽聽聽聽聽 ;BIOS Call
聽聽聽聽 pop聽 ax
聽聽聽聽 add聽 ax,dx
聽聽聽聽 adc聽 cx,0
聽聽聽聽 pop聽 dx
聽聽聽聽 ret
get_time_plus_ax聽聽聽 endp
;************聽 ########聽 backup bin bin_old conf config crawler.tar.gz crawler_bin.tar.gz data eshow eshow_sitemap.html generate.sh google.html google.html.md5 log maint news:10 news:11 news:12 news:13 news:14 news:15 news:16 news:17 news:18 news:2 news:3 news:4 news:5 news:6 news:7 news:8 news:9 outboundLinksMgr.sql seeds sitemap.html svn tasks tmp xml2dict-2008.6-tar.gz xml2dict-read-only
test_current_time聽聽 proc near
;on entry CX:AX has time value
聽; to be subtracted from the current time
;on exit if carry set then current time
聽; is less than CX:AX time
聽聽聽聽 push dx
聽聽聽聽 push cx
聽聽聽聽 push ax
聽聽聽聽 xor聽 ax,ax
聽聽聽聽 int聽 1AH聽聽聽聽聽聽聽聽聽聽聽 ;BIOS Call
聽聽聽聽 cmp聽 dx,18
聽聽聽聽 jb聽聽 test_current_time_2
test_current_time_1:
聽聽聽聽 pop聽 ax
聽聽聽聽 sub聽 dx,ax
聽聽聽聽 pop聽 dx
聽聽聽聽 sbb聽 cx,dx
聽聽聽聽 mov聽 cx,dx
聽聽聽聽 pop聽 dx
聽聽聽聽 ret
test_current_time_2:
聽聽聽聽 or聽聽 cx,cx
聽聽聽聽 jnz聽 test_current_time_1
聽聽聽聽 pop聽 ax聽聽聽聽聽 ;this is fix code for midnight factor
聽聽聽聽 pop聽 dx
聽聽聽聽 pop聽 dx
聽聽聽聽 clc聽聽聽聽聽聽聽聽聽 ;clear carry condition
聽聽聽聽 ret
test_current_time聽聽 endp
;*****************************************
end
相关链接:
Compilation of various source - colps3 movie formatsStudents this year, real salary levels Jiemi freshPing command usageAvi to ps3Disaster Relief donation of: 3 million yuan Assistance ASUS quake donationsHealth WINE listed first off over fiveonline wav to mp3 converterComment IconsTop Casino And GamblingChinese VERSION of Firefox: Firefox for free to watch television withSony and NEC will merge the two departmentsRFID into the competition for the critical periodVirtuozzo Chinese name of the solicitation list of WINNERSIphone rmvb