🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.os.msdos.programmer
Article #5011

Re: Generating delays

#5011
From: Mikel Lechner
Date: Tue, 05 Mar 1991 00:25
95 lines
2687 bytes
melling@cs.psu.edu (Michael D Mellinger) writes:

> I need to be able to generate delays of around 1/2 second.  Anyone
> have a good way of doing this?  I'm using MS C 6.0.  The best I can
> come up with is a 1 second delay.

Here's some assembler for doing a 10-second delay using DOS's int 21h
function 2ch call to retrieve the time.  You may be able to modify this
to use the hundredths field instead of the seconds field to get delays
of fractions of a second.  I haven't tried this.

One caveat, Ray Duncan's book "Advanced MS DOS Programming" says:

	On most IBM PC-compatible systems, the real-time clock does not
	have the resolution of single hundredths of seconds.  On such
	machines, the values returned by this function in register DL
	are discontinuous.

I interpret this to mean the hundredths position does not increment
by 1, but by a larger value.  Therefore a simple test for equality
will not suffice.  I've included this  snipit of assembler which may
give you a starting point to solve this problem.

;
; This program scans the keyboard for 10 seconds looking for a typed
; key.  If no key is pressed, exit is normal, otherwise, exit with
; non-zero exit code.
;
; Author:	Mikel Lechner
; Date:		2/18/91
;

_text	segment	word public 'CODE'
	assume	cs:_text,ds:_data,es:_data,ss:stack

main	proc	far

	mov	ax,_data	; Set up data segment registers
	mov	ds,ax
	mov	es,ax

	mov	ah,2ch		; Get time of day
	int	21h
	add	dh,10		; Compute 10 secs into future
	cmp	dh,60		;   modulo 60
	jl	noadj
	sub	dh,60
noadj:
	mov	when,dh

again:
	mov	ah,6		; Check for pressed keyboard key
	mov	dl,0ffh
	int	21h
	jnz	gotit		; Yep, exit with code 1

	mov	ah,2ch		; Check for target time (seconds)
	int	21h
	cmp	dh,when
	jne	again		; Loop again
	mov	al,0
	jmp	done

gotit:
	mov	al,1

done:
	mov	ah,4ch
	int	21h

main	endp

_text	ends

_data	segment word public 'DATA'

when	db	0

_data	ends


stksiz	equ	64

stack	segment	para stack 'STACK'
	db	stksiz dup (?)
stack	ends

	end	main


-- 
Mikel Lechner			UUCP:  teda!mikel
Teradyne EDA, Inc.
5155 Old Ironsides Drive	| If you explain so clearly that nobody
Santa Clara, Ca 95054		| can misunderstand, somebody will.
Technical Details
Message-ID: <21654@teda.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!zaphod.mps.ohio-state.edu!rphroy!caen!uwm.edu!bionet!ames!vsi1!teda!mikel
References: <sg2Gwuw?@cs.psu.edu> <1010@caslon.cs.arizona.edu> <404Gtqz?@cs.psu.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!zaphod.mps.ohio-state.edu!rphroy!caen!uwm.edu!bionet!ames!vsi1!teda!mikel
From: mikel@teda.UUCP (Mikel Lechner)
Newsgroups: comp.os.msdos.programmer
Subject: Re: Generating delays
Message-ID: <21654@teda.UUCP>
Date: 5 Mar 91 00:25:31 GMT
References: <sg2Gwuw?@cs.psu.edu> <1010@caslon.cs.arizona.edu> <404Gtqz?@cs.psu.edu>
Distribution: comp
Lines: 95