Area: Quik_Bas Msg: #395 Date: 12-25-92 10:59 (Public) From: Mark Rejhon To: Walton Dell Subject: Re: pause
> Could you post the asm source? Please!
; This is a library that allow speedier timer handling.
; These functions are between 3 and 100 times faster than QB's TIMER
; function. Compile using MASM 6.0 preferably (MASM 5.1 will work)
; Both TimePassed& and TickPassed& are midnight-smart, midnight-safe.
;
;
; ---------------- Add the below to "TICK.BI" or program -----------------
;
; DECLARE FUNCTION Time&
; '1/100 secs since midnight 3 times faster than TIMER.
; DECLARE FUNCTION TimePassed&(BYVAL OldTime&)
; 'Diff. btwn now and old Time& 8 times faster than similiar QB sub
; DECLARE FUNCTION Tick&
; '1/18.2 secs since midnight 30 times faster than TIMER.
; DECLARE FUNCTION TickPassed&(BYVAL OldTick&)
; 'Diff. btwn now and old Tick& 100 times faster than similiar QB sub.
;
;----------------------------------8<---------------------------------------
.MODEL MEDIUM, PASCAL, OS_DOS
.DATA
.CODE
;Long Int Function: Returns 1/100th seconds passed since midnight.
;Approximately 3 times faster than TIMER
Time PROC
pushf
push bx
push cx
mov ah, 2Ch
int 21h ;Get current time
mov bx, dx ;preserve dx because of mul instruct
mov ax, 0
mov al, bh ;Move seconds into ax
mov bh, 0
mov dx, 100
mul dx ;Multiply by 100 centisecs (1 second
add ax, bx ;Add centiseconds
mov bx, ax ;Copy back into bx
mov ax, 0
mov al, ch ;Move hours into ax
mov ch, 0
mov dx, 60
mul dx ;Multiply by 60 minutes
add ax, cx ;Add minutes
mov cx, 6000
mul cx ;Multiply by 6000 centisecs (1 minut
add ax, bx ;Add centisecs to ax
adc dx, 0 ;Carry to dx
pop cx
pop bx
popf
ret
Time ENDP
;Long Int Function: Number of hundredths of seconds passed between value in
;OldTime and the current time. Compensates for midnight wrap-around!
;Approximately 3 times faster than TIMER
TimePassed PROC OldTime:DWORD
pushf
push bx
push cx
mov ah, 2Ch
int 21h ;Get current time
mov bx, dx ;preserve dx because of mul instruc
mov ax, 0
mov al, bh ;Move seconds into ax
mov bh, 0
mov dx, 100
mul dx ;Multiply by 100 centisecs (1 secon
add ax, bx ;Add centiseconds
mov bx, ax ;Copy back into bx
mov ax, 0
mov al, ch ;Move hours into ax
mov ch, 0
mov dx, 60
mul dx ;Multiply by 60 minutes
add ax, cx ;Add minutes
mov cx, 6000
mul cx ;Multiply by 6000 centisecs (1 minute)
add ax, bx ;Add centisecs to ax
adc dx, 0 ;Carry to dx
mov bx, WORD PTR OldTime[0]
mov cx, WORD PTR OldTime[2]
test cx, 8000h ;Is it a negative value?
jz NotNeg
add bx, (8640000 AND 0FFFFh)
adc cx, (8640000 / 0FFFFh)
NotNeg:
sub ax, bx ;Compensate for midnight boundary
sbb dx, cx
jnc Done
add ax, (8640000 AND 0FFFFh)
adc dx, (8640000 / 0FFFFh)
Done:
pop cx
pop bx
popf
ret
TimePassed ENDP
;Long Int Function: Returns number of 1/18.2th second ticks since midnight.
;Approximately 30 times faster than TIMER
Tick PROC
pushf
push ds
mov ax, 0040h
mov ds, ax
mov ax, ds:[006Ch] ;From BIOS data table, the number of
mov dx, ds:[006Eh] ;ticks since midnight.
pop ds
popf
ret
Tick ENDP
;Long Int Function: Number of 1/18.2th seconds between value in OldTick
;and current value as in above Tick subroutine. Compensates for midnight.
;Approximately 30 times faster than TIMER, or 100 times faster than
;similiar midnight-compensating subroutine in QuickBASIC.
TickPassed PROC OldTick:DWORD
pushf
push bx
push cx
push es
mov ax, 0040h
mov es, ax
mov ax, es:[006Ch] ;Get current tick value
mov dx, es:[006Eh]
mov bx, WORD PTR OldTick[0] ;Get parameter
mov cx, WORD PTR OldTick[2]
test cx, 8000h ;Is it a negative value? (Used
jz NotNeg ; when math was used on parms)
add bx, (1573040 AND 0FFFFh) ;Then wrap back into the positive
adc cx, (1573040 / 0FFFFh)
NotNeg:
sub ax, bx ;Get difference
sbb dx, cx
jnc Done
add ax, (1573040 AND 0FFFFh) ;Midnight wraparound compensation
adc dx, (1573040 / 0FFFFh)
Done:
pop es
pop cx
pop bx
popf
ret
TickPassed ENDP
END
--- FMail 0.92
* Origin: +++ VIddIBBS +++ (613) 521-4486! (1:163/255)

Books at Amazon:
Back to BASIC: The History, Corruption, and Future of the Language
Hackers: Heroes of the Computer Revolution (including Tiny BASIC)
Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution
The Advent of the Algorithm: The Idea that Rules the World
Moths in the Machine: The Power and Perils of Programming
Mastering Visual Basic .NET