home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.pascal
- Path: sparky!uunet!munnari.oz.au!newsroom.utas.edu.au!pc_100.psychol.utas.edu.au!peter
- From: peter@psychnet.psychol.utas.edu.au (Peter R. Tattam)
- Subject: Re: High speed clock
- Message-ID: <peter.433.724490084@psychnet.psychol.utas.edu.au>
- Keywords: clock
- Sender: news@newsroom.utas.edu.au
- Organization: Psychology Department, University of Tasmania
- References: <1992Nov20.091212.24871@lth.se> <peter.422.723796479@psychnet.psychol.utas.edu.au> <Bz47zL.5sH@news.cso.uiuc.edu> <peter.430.724488284@psychnet.psychol.utas.edu.au>
- Date: Wed, 16 Dec 1992 07:14:44 GMT
- Lines: 101
-
- Well. Here 'tis.
- have fun.
- ------------------- cut here ----------------------
- { millisecond timer unit }
-
- unit msecs;
-
- interface
-
- var
- timer:word; { msec timer }
- idle:procedure; { you can change this to do something useful when delaying}
-
- procedure delay_ticks(t:word); { resume until t clock ticks have elapsed }
- procedure start_clock; { starts the 1 msec timer }
- procedure stop_clock; { stops the 1 msec timer }
-
- implementation
-
- uses dos;
-
- procedure delay_ticks(t:word);
- begin
- inc(t,timer);
- repeat idle until integer(timer - t) >= 0;
- end;
-
- const clock_active:boolean = false;
- one_msec = 1193;
- var save_clock:pointer;
- clocks:word;
-
- procedure tick_int; far; assembler;
- asm
- push ax
- push ds
- mov ax,seg @data
- mov ds,ax
- mov al,$20
- out $20,al
- inc [timer]
- add [clocks],one_msec
- jnc @1
- pushf
- call [save_clock]
- @1:
- pop ds
- pop ax
- iret
- end;
-
-
- procedure start_clock;
- begin
- if clock_active then exit;
- inc(clock_active);
- timer := 0;
- clocks := 0;
- getintvec($08,save_clock);
- setintvec($08,@tick_int);
- port[$43] := $36;
- port[$40] := lo(one_msec);
- port[$40] := hi(one_msec);
- end;
-
- procedure stop_clock;
- begin
- if not clock_active then exit;
- dec(clock_active);
- port[$43] := $36;
- port[$40] := 0;
- port[$40] := 0;
- setintvec($08,save_clock);
- end;
-
- procedure nothing; far;
- begin
- end;
-
- var saveexit:pointer;
-
- procedure uninstall; far;
- begin
- exitproc := saveexit;
- if clock_active then stop_clock;
- end;
-
- begin
- timer := 0;
- idle := nothing;
- saveexit := exitproc;
- exitproc := @uninstall;
- end.
-
-
- -------------------- cut here --------------------
- ----------------------------------------------------------------------------
- P.Tattam International Phone 61-02-202346
- Programmer, Psychology Department Australia Phone 002-202346
- University of Tasmania, Hobart, Tasmania, Australia
- ----------------------------------------------------------------------------
-