home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C!T ROM 2
/
ctrom_ii_b.zip
/
ctrom_ii_b
/
PROGRAM
/
PASCAL
/
PARADIS1
/
DELAYP.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1992-04-27
|
3KB
|
103 lines
(11146) Mon 20 Apr 92 10:53
By: Wilbert Van.leijen
To: Matt Schuttloffel
Re: Delay Patch
St:
---------------------------------------------------------------------------
@MSGID: 2:500/12.10956 172E03D5
@REPLY: 1:170/806 3491809e
@PID: Dutched 2.91e 0013310373
** Quoting a message from Matt Schuttloffel to Dj Murdoch **
> I once saw some code that would time and delay within a millionth of a
> second accuracy. It somehow used a chip on the PC-Speaker to do it. I
> think I got it off of TurboCity, but I seemed to have lost it. :-(
Const
Timer0 = $40; { 8253 Timer 0 (Ticker timer) }
CtrlWord = $43; { 8253 Control Word }
Mode2 = $34; { Free running 16-bit counter }
TickLength = 55; { Tick length = 55 ms }
TickAddr = $46C; { Lower word in BIOS data area }
MiliSec = 1192; { Number of Timer 0 cycles in 1 ms }
{ Read out the current value of the timer 0 }
Procedure ReadTimer; Assembler;
ASM
IN AL, Timer0
XOR AH, AH
MOV DX, AX
IN AL, Timer0
XCHG AH, AL
ADD AX, DX
end; { ReadTimer }
{ Timed delay function }
Procedure Delay(time : Word); Assembler;
ASM
{ Clear DX to prevent divide overflow.
Devide DelayTime in ticks (blocks of 55 ms).
Store the offset in ticks in OfsTicks. }
XOR DX, DX
MOV AX, time
MOV CX, TickLength
DIV CX
MOV BX, AX
{ Reset timer for the sake of accuracy }
MOV AL, Mode2
OUT CtrlWord, AL
XOR AX, AX
OUT Timer0, AL
OUT Timer0, AL
{ Get the current value of the ticker timer at address 0000h:046Ch }
MOV ES, AX
MOV DI, TickAddr
MOV AX, ES:[DI]
ADD AX, BX
MOV SI, AX
{ Repeat
Until ticker timer value = SI; }
@1: MOV AX, ES:[DI]
CMP AX, SI
JNZ @1
{ Calculate remainder of delay time in cycles of Timer 0.
1192 cycles = 0.001 seconds
SI = (current value of Timer 0) - (1192*(DelayTime mod 55)); }
XCHG AX, DX
MOV CX, MiliSec
MUL CX
MOV BX, AX
CALL ReadTimer
SUB AX, BX
MOV SI, AX
{ Repeat }
@2: CALL ReadTimer
CMP AX, SI
JNB @2
{ Until Timer 0 value < SI }
end; { Delay }
Cheerio, Wilbert
--- Dutchie V2.91e
* Origin: Programming Art's Computer (2:500/12.10956)
@PATH: 500/12 2 9 512/0 1007