;syntax - CALL Pause(uSecs%)
;where uSecs% is the number of microseconds to pause
;Note: Maximum acceptable value is 27,500 microseconds.
; Checking is performed on entry.
.Model Medium,BASIC
.Code
Pause Proc, uSecs:Ptr
push si
mov si,uSecs ;get the address for uSecs%
lodsw ;put the number of microseconds into AX
cmp ax,27500 ;exit if value out of range
ja exit
mov bx,25 ;calculate number of timer
mul bx ; cycles equivalent to the
mov bx,21 ; specified number of
div bx ; microseconds
mov bx,ax ;transfer result to BX
;Disable timer 2.
in al,61h ;clear bit 0 of I/O port 61h
jmp short $+2
and al,0FEh
out 61h,al
jmp short $+2
;Initialize timer 2 for mode 0 operation with word-size initial count.
cli ;disable interrupts
mov al,0B0h ;output control byte
out 43h,al
jmp short $+2
mov al,bl ;send low byte of count
out 42h,al
jmp short $+2 ;tiny delay
mov al,bh ;then the high byte
out 42h,al
jmp short $+2 ;tiny delay
;Reinitialize timer 0 to make sure a time-of-day interrupt doesn't occur.
mov al,36h ;mode 3 with word-size divisor
out 43h,al
jmp short $+2
xor al,al ;set interrupts for every
out 40h,al ; 65,536 cycles
jmp short $+2
out 40h,al
jmp short $+2
sti ;enable interrupts
;Start the countdown by enabling timer 2.
in al,61h ;set bit 0 of I/O port 61h
jmp short $+2
or al,01h
out 61h,al
jmp short $+2
;Loop until the count has reached zero.
readloop:
mov al,80h ;latch timer 2
out 43h,al
jmp short $+2 ;tiny delay
in al,42h ;read count
jmp short $+2 ;tiny delay
mov ah,al
in al,42h
jmp short $+2 ;tiny delay
xchg al,ah
or ax,ax ;loop if count hasn't
jns readloop ; reached zero
Exit:
pop si
Ret ;return to VBASIC
Pause Endp
End