Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!caen!sol.ctr.columbia.edu!ira.uka.de!fauern!NewsServ!tritsche From: tritsche@Informatik.TU-Muenchen.DE (Stefan Tritscher) Newsgroups: comp.lang.pascal Subject: Re: Help needed - ticking clock impl. Message-ID: <1991Apr17.082006.9933@Informatik.TU-Muenchen.DE> Date: 17 Apr 91 08:20:06 GMT References: <1991Apr16.124739.18124@hubcap.clemson.edu> Sender: news@Informatik.TU-Muenchen.DE Organization: Technische Universitaet Muenchen, Germany Lines: 193 In article <1991Apr16.124739.18124@hubcap.clemson.edu> asolima@hubcap.UUCP (abdel w soliman) writes: >Dear Netters, >I am writing a program in TP 5.5 and would like to implement a clock. I can >get the initial time by calling "GetTime" procedure, but I would like to make >it "tick" (on the screen) as my program is running. > >I got a program that does this (from uwassa- Prof. Salmi's program). >Unfortunatelly, only the executable file was available so I am puzzled and >eager to get something done but I have no idea how to start. > >I would appreciate any ideas, hints, code. I will summarize the replies to >the net so that others can benefit from it too. > >Beforehand Thankful, > > > >Adnan Zejnilovic (rcs76179@zach.fit.edu) > This is one which I wrote some time ago (works only in text mode): Have fun, Stefan --------snip, snip---------------------------------------- (******************************************************) (* UNIT CLOCK (C) 1990 Stefan Tritscher *) (* *) (* Declaration: *) (* PROCEDURE Start_Clock( X, Y : byte); *) (* PROCEDURE Stop_Clock; *) (* *) (* Description: *) (* Start_Clock concurrently displays the actual *) (* time at position X and Y of the screen. *) (* Stop_Clock stops the running Clock. *) (* *) (******************************************************) UNIT CLOCK; INTERFACE USES DOS,CRT; PROCEDURE Start_Clock( X, Y : byte); PROCEDURE Stop_Clock; IMPLEMENTATION VAR Hour : word; Minute : word; Second : word; Int_Count : byte; Correct : byte; XPos : byte; YPos : byte; SaveX : byte; SaveY : byte; Old_Int : pointer; Old_Exit : pointer; {$F+} PROCEDURE Clock_Handler; INTERRUPT; {$F-} (* This procedure is the interrupt handler for interrupt 1CH. *) (* It is called on every clock tick (18.2 per sec.). *) (* Every second the actual Time is recalculated an displayed *) (* at the screen. *) (* Be carefull not to use any DOS or BIOS call within an *) (* interrupt hander (reentrancy problem). For this reason *) (* the unit CRT is used for output, because it writes *) (* the output directly to video memory. *) BEGIN dec(Int_Count); IF Int_Count = 0 THEN BEGIN (* one second has passed *) dec(Correct); IF Correct = 0 THEN BEGIN (* every five seconds we must wait one tick longer *) (* because we get 18.2 ticks per second *) Correct := 5; Int_Count := 19; END ELSE Int_Count := 18; (* calculate new time *) inc(Second); IF Second = 60 THEN BEGIN Second := 0; inc(Minute); IF Minute = 60 THEN BEGIN Minute := 0; inc(Hour); IF Hour = 24 THEN Hour := 0; END; END; (* display new time *) SaveX := wherex; SaveY := wherey; gotoxy(XPos,YPos); IF Hour < 10 THEN write('0'); write(Hour,':'); IF Minute < 10 THEN write('0'); write(Minute,':'); IF Second < 10 THEN write('0'); write(second); gotoxy(SaveX,SaveY); (* done *) END; END; PROCEDURE Start_Clock( X, Y : byte ); (* Start the Clock. *) VAR Dummy : word; BEGIN Int_Count := 18; Correct := 5; XPos := X; YPos := Y; (* get time from DOS *) gettime(Hour, Minute, Second, Dummy); (* set up Clock_Handler as interrupt handeler for int 1CH *) setintvec($1C, @Clock_Handler); END; PROCEDURE Stop_Clock; (* Stop the Clock *) BEGIN (* simply restore old handler for int 1CH *) setintvec($1C, Old_Int); END; {$F+} PROCEDURE Error_Exit; {$F-} (* Called on errors in TURBO PASCAL *) BEGIN (* stop the clock before exit or the PC will crash. *) Stop_Clock; exitproc := Old_Exit; END; BEGIN checkbreak := FALSE; getintvec($1C, Old_Int); Old_Exit := exitproc; exitproc := @Error_Exit; END. ------snip, snip------------------------------------------------- {$R-,S+,I+,D+,F-,V+,B-,N-,L+ } {$M 1024,0,400 } PROGRAM Test; USES DOS, CLOCK; BEGIN (* start clock at upper right corner of screen *) Start_Clock(70,1); (* terminate but stay resident (TSR) *) Keep(0); END. ------snip, snip------------------------------------------------- / relay.cs.net (CS-NET, ARPA) tritsche%lan.informatik.tu-muenchen.dbp.de@ - unido.uucp (UUCP) unido.bitnet (BITNET) Munich University of Technology, Department of Computer Science, FRG