home *** CD-ROM | disk | FTP | other *** search
-
- /*******************************************************************
- $CRT 01 Jun 1996 : hb
-
- $AUT Holger Burkarth
- $DAT >>SysTime.c<< 29 Jan 1997 13:19:52 - (C) ProDAD
- *******************************************************************/
-
- //##ex mcpp:cppc -gs -o pos:pos/Ex/systime p:pLib/StartCode.o p:/pOS_RKRM/pTimer/SysTime.c p:pLib/StdIO.o -l pOSStub -l pOS
-
- /***********************************************************
- pOS programing example - Copyright (C) 1995-97 proDAD
-
- This code was written as an easy to understand example,
- how to program pOS features. It is provided 'as-is',
- without any express or implied warranty.
-
- Permission is hereby granted to use, copy and modify
- this source code for any purpose, without fee, subject
- to the following conditions:
-
- (1) This notice may not be removed or altered from any
- source distribution.
-
- (2) Altered source versions must be plainly marked as
- such, and must not be misrepresented as being
- the original source code.
-
- (3) If only executable code is distributed, then the
- accompanying documentation have to state that
- "this software is based in part on examples of
- the pOS developer packet".
-
- (4) Permission for use of this code is granted only
- if the user accepts full responsibility for any
- undesirable consequences. proDAD accept NO LIABILITY
- for damages of any kind.
-
- ©proDAD
- ***********************************************************/
-
- /*\
- *** Example:
- *** struct pOS_TimeVal
- *** struct pOS_MsgPort
- *** struct pOS_TimerIO
- ***
- *** pOS_ConstructMsgPort
- *** pOS_CreateIORequest
- *** pOS_OpenDevice
- *** pOS_GetSysTime
- *** pOS_DoIO
- *** pOS_SendIO
- *** pOS_CheckIO
- *** pOS_WaitIO
- *** pOS_WaitSignal
- *** pOS_AbortIO
- *** pOS_SubTime
- *** pOS_CloseDevice
- *** pOS_DeleteIORequest
- *** pOS_DestructMsgPort
- ***
- \*/
-
-
- #define __COMPUTER_AMIGA 1
- #define NOMYDEBUG
-
- #include "p:pExec/Types.h"
- #include "p:Device/Timer.h"
- #include "p:pDOS/ArgTags.h"
- #include "p:pDOS/DosErrors.h"
- #include "p:pDOS/DosSig.h"
- #include "p:proto/pLibExt.h"
- #include "p:proto/pExec2.h"
- #include "p:proto/pDOS2.h"
- #include "p:proto/pTimer2.h"
-
- #ifdef _____ME_____
- #include "grund/inc_string.h"
- #include "grund/inc_stdio.h"
- #else
- #ifdef __cplusplus
- extern "C" {
- #endif
- #include <string.h>
- #include <stdio.h>
- #ifdef __cplusplus
- }
- #endif
- #endif
-
-
- struct pOS_TimerDevice *gb_TimerBase;
-
-
- const CHAR *HelpText=
- ""
- ;
-
- const CHAR *PrgHeader=
- "Simple pOS-Timer.device demo";
-
- const CHAR *PrgVerText=
- "$VER: 1.0 ("__DATE2__") (Copyright 1996 by proDAD) (Created by Holger Burkarth)";
-
-
-
- /*----------------------------------
- -----------------------------------*/
- #ifdef __cplusplus
- extern "C"
- #endif
-
- VOID main()
- {
- struct pOS_DosArgs* Args;
- UWORD Err=0;
- ULONG Ops[1]={0};
-
- Args=pOS_ReadDosArgs("",Ops,sizeof(Ops)/sizeof(ULONG),
- ARGTAG_PrgHeaderText, (ULONG)PrgHeader, /* kurze Programm-Beschreibung */
- ARGTAG_HelpText, (ULONG)HelpText, /* Help-Texte */
- ARGTAG_PrgVerText, (ULONG)PrgVerText, /* VER-String */
- TAG_END);
-
- if(Args) {
- struct pOS_TimeVal TV;
- struct pOS_MsgPort ReplyPort; /* Reply-Port für die Device-IOs */
- struct pOS_TimerIO* TimerIO; /* Timer-IO-Struct */
- ULONG days,hrs,secs,mins,mics;
-
- pOS_ConstructMsgPort(&ReplyPort); /* MsgPort initialisieren mit setzen vom Signal-Bit */
-
- if(TimerIO=(struct pOS_TimerIO*)pOS_CreateIORequest(&ReplyPort,sizeof(struct pOS_TimerIO))) {
- pOS_OpenDevice("ptimer.device",TIMERUNIT_VBlank,(struct pOS_IORequest*)TimerIO,0,0);
- if(TimerIO->tio_Error==0) {
- gb_TimerBase=TimerIO->tio_Device;
-
- // --------
- pOS_GetSysTime(&TV); /* aktuelle System-Time lesen */
-
- mics=TV.tv_Micro;
- secs=TV.tv_Secs;
-
- /* Compute days, hours, etc. */
- mins=secs / 60;
- hrs =mins / 60;
- days=hrs / 24;
- secs=secs % 60;
- mins=mins % 60;
- hrs =hrs % 24;
-
- printf("System Time (measured from 1.Jan.,1992)\n");
- printf(" Days Hours Minutes Seconds Microseconds\n");
- printf("%6ld %6ld %6ld %6ld %10ld\n\n\n",days,hrs,mins,secs,mics);
-
- // --------
- printf("Wait 2 Seconds ...");
-
- TimerIO->tio_Command=TRCMD_AddRequest;
- TimerIO->tio_Time.tv_Secs=2;
- TimerIO->tio_Time.tv_Micro=0;
- pOS_DoIO((struct pOS_IORequest*)TimerIO); /* Kommando synchron ausführen */
-
- printf("\n\n");
-
-
- // --------
- printf("Start 2 Seconds asynch. counting with cursor ...\n");
-
- TimerIO->tio_Command=TRCMD_AddRequest;
- TimerIO->tio_Time.tv_Secs=2;
- TimerIO->tio_Time.tv_Micro=0;
- pOS_SendIO((struct pOS_IORequest*)TimerIO); /* Kommando asynchron ausführen */
- mics=0; // counter;
- do {
- printf("\r%ld\033[K",++mics);
-
- /*\
- *** Der pOS_CheckIO() liefert so lange NULL, bis der IO bearbeitet ist
- *** (die 2 Sekunden verstrichen sind).
- *** Da jeder IO nach der Bearbeitung an den ReplyPort gesendet wird, muß
- *** der IO wieder vom ReplyPort entfernt werden. (ein Node kann nur gleichen
- *** Zeit nur in einer Liste Mitglied sein)
- *** Der einfachste Weg, einen fertigen IO vom ReplyPort zu entfernen ist
- *** pOS_WaitIO() aufzurufen.
- \*/
- } while( pOS_CheckIO((struct pOS_IORequest*)TimerIO)==NULL );
-
- pOS_WaitIO((struct pOS_IORequest*)TimerIO); /* remove IO-Reply */
- printf("\nDone\n");
-
- // --------
- printf("Start 2 Seconds asynch. counting without cursor ...\n");
- printf("\033[0 p"); // *** Cursor OFF
-
- TimerIO->tio_Command=TRCMD_AddRequest;
- TimerIO->tio_Time.tv_Secs=2;
- TimerIO->tio_Time.tv_Micro=0;
- pOS_SendIO((struct pOS_IORequest*)TimerIO); /* Kommando asynchron ausführen */
- mics=0; // counter;
- do {
- printf("\r%ld\033[K",++mics);
- } while( pOS_CheckIO((struct pOS_IORequest*)TimerIO)==NULL );
-
- pOS_WaitIO((struct pOS_IORequest*)TimerIO); /* remove IO-Reply */
- printf("\033[1 p"); // *** Cursor ON
- printf("\nDone\n");
-
-
-
- // --------
- printf("Forever Second-Counter ( Ctrl-C ) ...\n");
- printf("\033[0 p"); // *** Cursor OFF
-
- pOS_GetSysTime(&TV); /* Start-Zeitpunkt vermerken */
-
- for(;;) {
- ULONG Sig;
-
- TimerIO->tio_Command=TRCMD_AddRequest;
- TimerIO->tio_Time.tv_Secs=1;
- TimerIO->tio_Time.tv_Micro=0;
- pOS_SendIO((struct pOS_IORequest*)TimerIO); /* Kommando asynchron ausführen */
-
- Sig=pOS_WaitSignal(DOSSIGF_CTRL_C | (1<<ReplyPort.mp_SigBit));
- /*\
- *** Es wurde Ctrl-C gedrückt und der aktuell laufende TimerIO muß vorzeitig
- *** abgebrochen werden. pOS_AbortIO() bewirkt, daß der IO sofort aus der
- *** Bearbeitung entfernt wird und zum ReplyPort gesendet wird. Der folgende
- *** Aufruf von pOS_WaitIO() dient jediglich zum Entfernen vom TimerIO vom
- *** ReplyPort;
- \*/
- if(Sig & DOSSIGF_CTRL_C) {
- pOS_AbortIO((struct pOS_IORequest*)TimerIO);
- pOS_WaitIO((struct pOS_IORequest*)TimerIO);
- printf("\n^C\n");
- break;
- }
- else {
- pOS_TimeVal ActTV;
- pOS_WaitIO((struct pOS_IORequest*)TimerIO); /* remove IO-Reply */
-
- pOS_GetSysTime(&ActTV); /* aktuelle Zeit ermitteln */
- pOS_SubTime(&ActTV,&TV); /* ActTV = ActTV - TV => Verstrichene Zeit */
- printf("\r\033[KSec %ld",ActTV.tv_Secs);
- }
- }
- printf("\033[1 p"); // *** Cursor ON
-
-
- // --------
- pOS_CloseDevice((struct pOS_IORequest*)TimerIO); /* Device wieder schließen */
- }
- else printf("Cannot open ptimer.device, tio_Error=%ld\n",TimerIO->tio_Error);
- pOS_DeleteIORequest((struct pOS_IORequest*)TimerIO); /* Memory freigeben */
- }
- pOS_DestructMsgPort(&ReplyPort); /* Signal-Bit freigeben */
-
- pOS_DeleteDosArgs(Args); /* Args freigeben */
- }
- else Err=DOSFAIL_FAIL; /* vollkommen fehlgeschlagen */
-
- pOS_SetShellFail(Err);
- }
-