home *** CD-ROM | disk | FTP | other *** search
- /*---------------------------------------------------------------------------
- * filename - delay.cas
- *
- * function(s)
- * delay - wait for specified period.
- *--------------------------------------------------------------------------*/
-
- /*[]------------------------------------------------------------[]*/
- /*| |*/
- /*| Turbo C Run Time Library - Version 3.0 |*/
- /*| |*/
- /*| |*/
- /*| Copyright (c) 1987,1988,1990 by Borland International |*/
- /*| All Rights Reserved. |*/
- /*| |*/
- /*[]------------------------------------------------------------[]*/
-
- #pragma inline
- #include <asmrules.h>
- #include <dos.h>
-
- static unsigned long readtimer( void )
- {
- asm xor ax,ax /* es points to BIOS data area */
- asm mov es,ax
- asm mov al,0Ah /* Ask to read irr */
- asm cli /* Disable interrupts */
- asm out 20h,al /* Address PIC ocw3 */
- asm mov al,0h /* Latch timer 0 */
- asm out 43h,al
- asm in al,20h /* Read irr */
- asm xchg di,ax /* Save it in DI */
- asm in al,40h /* Counter --> bx */
- asm mov bl,al /* LSB in BL */
- asm in al,40h
- asm mov bh,al /* MSB in BH */
- asm not bx /* Need ascending counter */
- asm in al,21h /* Read PIC imr */
- asm xchg si,ax /* Save it in SI */
- asm mov al,0FFh /* Mask all interrupts */
- asm out 21h,al
- asm mov dx,es:[46Ch] /* read low word of time from BIOS data area */
- asm xchg ax,si /* Restore imr from SI */
- asm out 21h,al
- asm sti /* Enable interrupts */
- asm xchg ax,di /* Retrieve old irr */
- asm test al,01h /* Counter hit 0? */
- asm jz done /* Jump if not */
- asm cmp bx,0FFh /* Counter > 0x0FF? */
- asm ja done /* Done if so */
- asm inc dx /* Else count int req. */
-
- done:
- asm xchg ax,bx /* set function result */
-
- return( MK_ULONG );
- }
-
-
- /*--------------------------------------------------------------------------*
-
- Name delay - wait for specified period.
-
- Usage void delay(unsigned milliseconds);
-
- Prototype in dos.h
-
- Description The current thread of execution is suspended for the specified
- number of milliseconds.
-
- Return value None
- *---------------------------------------------------------------------------*/
- void delay( unsigned milliseconds )
- {
- unsigned long start, stop;
-
- start = readtimer();
- stop = start + (milliseconds * 1193L);
-
- while( readtimer() < stop )
- ;
- }
-