home *** CD-ROM | disk | FTP | other *** search
-
- /*******************************************************************
- $CRT 31 Jul 1996 : hb
-
- $AUT Holger Burkarth
- $DAT >>DevAsLib.c<< 22 Feb 1997 08:44:31 - (C) ProDAD
- *******************************************************************/
-
- //##ex mcpp:cppc -gs -o pos:pos/Ex/DevAsLib p:pLib/StartCode.o p:/pOS_RKRM/pExec/DevAsLib.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:
- ***
- \*/
-
-
- #define __COMPUTER_AMIGA 1
- #define NOMYDEBUG
-
- #include "p:pExec/Types.h"
- #include "p:pDOS/ArgTags.h"
- #include "p:pDOS/DosSig.h"
- #include "p:pDOS/DosErrors.h"
- #include "p:pScreen/ScrTags.h"
- #include "p:pScreen/Window.h"
- #include "p:pScreen/Screen.h"
- #include "p:pIntui/IntuMsg.h"
- #include "p:pIntui/Tags.h"
- #include "p:proto/pLibExt.h"
- #include "p:proto/pExec2.h"
- #include "p:proto/pDOS2.h"
- #include "p:proto/pGFX2.h"
- #include "p:proto/pConsole2.h"
- #include "p:proto/pTimer2.h"
- #include "p:proto/pIntui2.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
-
-
- const CHAR *HelpText=
- ""
- ;
-
- const CHAR *PrgHeader=
- "";
-
- const CHAR *PrgVerText=
- "$VER: 1.0 ("__DATE2__") (Copyright 1996-97 by proDAD) (Created by Holger Burkarth)";
-
-
- struct pOS_IntuiDevice *gb_IntuiBase;
- struct pOS_TimerDevice *gb_TimerBase;
- struct pOS_ConsoleDevice *gb_ConsoleBase;
- struct pOS_GfxBase *gb_GfxBase;
-
-
- static const CHAR EmptyString[]=" ";
-
- /*----------------------------------
- -----------------------------------*/
- #ifdef __cplusplus
- extern "C"
- #endif
-
- VOID main()
- {
- struct pOS_DosArgs* Args;
- UWORD Err=0;
- ULONG Ops[1]={0};
-
- gb_IntuiBase=(pOS_IntuiDevice*)pOS_OpenLibrary("pintui.library",0);
- gb_GfxBase=(pOS_GfxBase*)pOS_OpenLibrary("pgraphics.library",0);
-
- Args=pOS_ReadDosArgs(
- // 0
- "",
- 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_Window *Win;
- struct pOS_Screen *Scr;
-
-
- /*\
- *** Öffnen der Devices als Libraries. pExec prüft über LIBF_DevAsLib, ob
- *** das Device dies erlaubt.
- \*/
- gb_TimerBase=(struct pOS_TimerDevice*)pOS_OpenLibrary("ptimer.library",0);
- gb_ConsoleBase=(struct pOS_ConsoleDevice*)pOS_OpenLibrary("pconsole.library",0);
-
- if(gb_TimerBase && gb_ConsoleBase) {
-
- if(Scr=pOS_LockPubScreen("Workbench")) {
- const struct pOS_DrawInfo *Dri=Scr->scr_DrawInfo;
-
- Win=pOS_OpenWindow(
- SCRTAG_Title, (ULONG)"Use Devices as Libraries",
- SCRTAG_Width, 400,
- SCRTAG_Height, 110,
- SCRTAG_PubName, (ULONG)"Workbench",
- SCRTAG_Flags, WINFLGF_DepthGadget | WINFLGF_SimpleRefresh |
- WINFLGF_Activate | WINFLGF_CloseGadget | WINFLGF_Dragbar,
- SCRTAG_IDCMP, IDCMP_CloseWindow | IDCMP_RawKey | IDCMP_IntuiTicks,
- TAG_DONE);
-
- if(Win) {
- struct pOS_TimeVal StartTime;
- struct pOS_IntuiMessage *Msg;
- BOOL Ende=FALSE;
-
- pOS_GetSysTime(&StartTime);
-
- pOS_SetAPen(Win->win_RastPort,1);
-
- while(!Ende) {
- pOS_WaitPort(Win->win_UserPort);
- while(Msg=(pOS_IntuiMessage*)pOS_GetMsg(Win->win_UserPort)) {
- switch(Msg->im_Class) {
-
- /*\
- *** convert pIntui-RawKey to Ansi-Key
- \*/
- case IDCMP_RawKey:
- {
- struct pOS_InputEvent IE;
- UBYTE Buffer[6],Buffer2[32];
- SLONG Size;
-
- IE.ie_NextEvent=NULL;
- IE.ie_Class =IECLASS_RAWKEY;
- IE.ie_Code =Msg->im_Code;
- IE.ie_Qualifier=Msg->im_Qualifier;
- IE.ie_DeadKey =(ULONG)Msg->im_IAddress;
- Size=pOS_RawKeyConvert(&IE,Buffer,sizeof(Buffer));
- if(Size>0) {
- pOS_SetPosition(Win->win_RastPort,10,60);
- pOS_DrawText(Win->win_RastPort,Buffer,Size);
- pOS_DrawText(Win->win_RastPort,EmptyString,6-Size); // Clear
- pOS_SPrintf(Buffer2,"Size=%ld %h",Size,Buffer);
- Size=strlen(Buffer2);
- pOS_DrawText(Win->win_RastPort,Buffer2,Size);
- pOS_DrawText(Win->win_RastPort,EmptyString,8); // Clear
- }
- pOS_SetPosition(Win->win_RastPort,10,80);
-
- pOS_SPrintf(Buffer2,"Raw=%2.2lx Q=%4.4lx",Msg->im_Code,Msg->im_Qualifier);
- Size=strlen(Buffer2);
- pOS_DrawText(Win->win_RastPort,Buffer2,Size);
- pOS_DrawText(Win->win_RastPort,EmptyString,16-Size); // Clear
- }
- break;
-
-
- /*\
- *** IDCMP_IntuiTicks
- \*/
- case IDCMP_IntuiTicks:
- {
- UBYTE Buffer[32];
- ULONG Size;
- struct pOS_TimeVal *TV=(struct pOS_TimeVal*)&Msg->im_Seconds;
- pOS_SubTime(TV,&StartTime);
-
- pOS_SPrintf(Buffer,"Secs=%ld %ld 1/10",TV->tv_Secs,TV->tv_Micro/100000);
- Size=strlen(Buffer);
- pOS_SetPosition(Win->win_RastPort,10,40);
- pOS_DrawText(Win->win_RastPort,Buffer,Size);
- pOS_DrawText(Win->win_RastPort,EmptyString,8); // Clear
- }
- break;
-
-
- case IDCMP_CloseWindow: Ende=TRUE; break;
- default: if(pOS_SysIMessage(Msg)) Msg=NULL;
- }
-
- if(Msg) pOS_ReplyMsg(&Msg->im_Message);
- }
- }
- pOS_CloseWindow(Win);
- }
- else printf("Cannot open window\n");
- pOS_UnlockPubScreen(Scr);
- }
- else printf("Cannot lock PubScreen\n");
- pOS_DeleteDosArgs(Args); /* Args freigeben */
- }
- else {
- printf("Cannot open, TimerBase=0x%lx ConsoleBase=0x%lx\n",gb_TimerBase,gb_ConsoleBase);
- }
- if(gb_TimerBase) pOS_CloseLibrary((struct pOS_Library*)gb_TimerBase);
- if(gb_ConsoleBase) pOS_CloseLibrary((struct pOS_Library*)gb_ConsoleBase);
- }
- else Err=DOSFAIL_FAIL; /* vollkommen fehlgeschlagen */
-
- pOS_SetShellFail(Err);
-
- pOS_CloseLibrary((pOS_Library*)gb_GfxBase);
- pOS_CloseLibrary((pOS_Library*)gb_IntuiBase);
- }
-