home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Misc / DC-POS24.LZX / pOS / pOS_RKRM.lzx / pOS_RKRM / pExec / DevAsLib.c next >
Encoding:
C/C++ Source or Header  |  1997-03-18  |  7.5 KB  |  249 lines

  1.  
  2. /*******************************************************************
  3.  $CRT 31 Jul 1996 : hb
  4.  
  5.  $AUT Holger Burkarth
  6.  $DAT >>DevAsLib.c<<   22 Feb 1997    08:44:31 - (C) ProDAD
  7. *******************************************************************/
  8.  
  9. //##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
  10.  
  11. /***********************************************************
  12.   pOS programing example - Copyright (C) 1995-97 proDAD
  13.  
  14.   This code was written as an easy to understand example,
  15.   how to program pOS features. It is provided 'as-is',
  16.   without any express or implied warranty.
  17.  
  18.   Permission is hereby granted to use, copy and modify
  19.   this source code for any purpose, without fee, subject
  20.   to the following conditions:
  21.  
  22.     (1) This notice may not be removed or altered from any
  23.         source distribution.
  24.  
  25.     (2) Altered source versions must be plainly marked as
  26.         such, and must not be misrepresented as being
  27.         the original source code.
  28.  
  29.     (3) If only executable code is distributed, then the
  30.         accompanying documentation have to state that
  31.         "this software is based in part on examples of
  32.         the pOS developer packet".
  33.  
  34.     (4) Permission for use of this code is granted only
  35.         if the user accepts full responsibility for any
  36.         undesirable consequences. proDAD accept NO LIABILITY
  37.         for damages of any kind.
  38.  
  39.   ©proDAD
  40. ***********************************************************/
  41.  
  42. /*\
  43. *** Example:
  44. ***
  45. \*/
  46.  
  47.  
  48. #define __COMPUTER_AMIGA 1
  49. #define NOMYDEBUG
  50.  
  51. #include "p:pExec/Types.h"
  52. #include "p:pDOS/ArgTags.h"
  53. #include "p:pDOS/DosSig.h"
  54. #include "p:pDOS/DosErrors.h"
  55. #include "p:pScreen/ScrTags.h"
  56. #include "p:pScreen/Window.h"
  57. #include "p:pScreen/Screen.h"
  58. #include "p:pIntui/IntuMsg.h"
  59. #include "p:pIntui/Tags.h"
  60. #include "p:proto/pLibExt.h"
  61. #include "p:proto/pExec2.h"
  62. #include "p:proto/pDOS2.h"
  63. #include "p:proto/pGFX2.h"
  64. #include "p:proto/pConsole2.h"
  65. #include "p:proto/pTimer2.h"
  66. #include "p:proto/pIntui2.h"
  67.  
  68. #ifdef _____ME_____
  69.   #include "grund/inc_string.h"
  70.   #include "grund/inc_stdio.h"
  71. #else
  72.  #ifdef __cplusplus
  73.  extern "C" {
  74.  #endif
  75.   #include <string.h>
  76.   #include <stdio.h>
  77.  #ifdef __cplusplus
  78.  }
  79.  #endif
  80. #endif
  81.  
  82.  
  83. const CHAR *HelpText=
  84. ""
  85. ;
  86.  
  87. const CHAR *PrgHeader=
  88. "";
  89.  
  90. const CHAR *PrgVerText=
  91. "$VER: 1.0 ("__DATE2__") (Copyright 1996-97 by proDAD) (Created by Holger Burkarth)";
  92.  
  93.  
  94. struct pOS_IntuiDevice   *gb_IntuiBase;
  95. struct pOS_TimerDevice   *gb_TimerBase;
  96. struct pOS_ConsoleDevice *gb_ConsoleBase;
  97. struct pOS_GfxBase       *gb_GfxBase;
  98.  
  99.  
  100. static const CHAR EmptyString[]="                    ";
  101.  
  102. /*----------------------------------
  103. -----------------------------------*/
  104. #ifdef __cplusplus
  105. extern "C"
  106. #endif
  107.  
  108. VOID main()
  109. {
  110.   struct pOS_DosArgs* Args;
  111.   UWORD Err=0;
  112.   ULONG Ops[1]={0};
  113.  
  114.   gb_IntuiBase=(pOS_IntuiDevice*)pOS_OpenLibrary("pintui.library",0);
  115.   gb_GfxBase=(pOS_GfxBase*)pOS_OpenLibrary("pgraphics.library",0);
  116.  
  117.   Args=pOS_ReadDosArgs(
  118. // 0
  119. "",
  120. Ops,sizeof(Ops)/sizeof(ULONG),
  121.  
  122.     ARGTAG_PrgHeaderText, (ULONG)PrgHeader,    /* kurze Programm-Beschreibung */
  123.     ARGTAG_HelpText,      (ULONG)HelpText,     /* Help-Texte */
  124.     ARGTAG_PrgVerText,    (ULONG)PrgVerText,   /* VER-String */
  125.     TAG_END);
  126.  
  127.   if(Args) {
  128.     struct pOS_Window *Win;
  129.     struct pOS_Screen *Scr;
  130.  
  131.  
  132. /*\
  133. *** Öffnen der Devices als Libraries. pExec prüft über LIBF_DevAsLib, ob
  134. *** das Device dies erlaubt.
  135. \*/
  136.     gb_TimerBase=(struct pOS_TimerDevice*)pOS_OpenLibrary("ptimer.library",0);
  137.     gb_ConsoleBase=(struct pOS_ConsoleDevice*)pOS_OpenLibrary("pconsole.library",0);
  138.  
  139.     if(gb_TimerBase && gb_ConsoleBase) {
  140.  
  141.       if(Scr=pOS_LockPubScreen("Workbench")) {
  142.         const struct pOS_DrawInfo *Dri=Scr->scr_DrawInfo;
  143.  
  144.         Win=pOS_OpenWindow(
  145.             SCRTAG_Title,   (ULONG)"Use Devices as Libraries",
  146.             SCRTAG_Width,   400,
  147.             SCRTAG_Height,  110,
  148.             SCRTAG_PubName, (ULONG)"Workbench",
  149.             SCRTAG_Flags,   WINFLGF_DepthGadget | WINFLGF_SimpleRefresh |
  150.                             WINFLGF_Activate | WINFLGF_CloseGadget | WINFLGF_Dragbar,
  151.             SCRTAG_IDCMP,   IDCMP_CloseWindow | IDCMP_RawKey | IDCMP_IntuiTicks,
  152.             TAG_DONE);
  153.  
  154.         if(Win) {
  155.           struct pOS_TimeVal StartTime;
  156.           struct pOS_IntuiMessage *Msg;
  157.           BOOL Ende=FALSE;
  158.  
  159.           pOS_GetSysTime(&StartTime);
  160.  
  161.           pOS_SetAPen(Win->win_RastPort,1);
  162.  
  163.           while(!Ende) {
  164.             pOS_WaitPort(Win->win_UserPort);
  165.             while(Msg=(pOS_IntuiMessage*)pOS_GetMsg(Win->win_UserPort)) {
  166.               switch(Msg->im_Class) {
  167.  
  168. /*\
  169. *** convert pIntui-RawKey to Ansi-Key
  170. \*/
  171.                 case IDCMP_RawKey:
  172.                   {
  173.                     struct pOS_InputEvent IE;
  174.                     UBYTE Buffer[6],Buffer2[32];
  175.                     SLONG Size;
  176.  
  177.                     IE.ie_NextEvent=NULL;
  178.                     IE.ie_Class    =IECLASS_RAWKEY;
  179.                     IE.ie_Code     =Msg->im_Code;
  180.                     IE.ie_Qualifier=Msg->im_Qualifier;
  181.                     IE.ie_DeadKey  =(ULONG)Msg->im_IAddress;
  182.                     Size=pOS_RawKeyConvert(&IE,Buffer,sizeof(Buffer));
  183.                     if(Size>0) {
  184.                       pOS_SetPosition(Win->win_RastPort,10,60);
  185.                       pOS_DrawText(Win->win_RastPort,Buffer,Size);
  186.                       pOS_DrawText(Win->win_RastPort,EmptyString,6-Size); // Clear
  187.                       pOS_SPrintf(Buffer2,"Size=%ld %h",Size,Buffer);
  188.                       Size=strlen(Buffer2);
  189.                       pOS_DrawText(Win->win_RastPort,Buffer2,Size);
  190.                       pOS_DrawText(Win->win_RastPort,EmptyString,8); // Clear
  191.                     }
  192.                     pOS_SetPosition(Win->win_RastPort,10,80);
  193.  
  194.                     pOS_SPrintf(Buffer2,"Raw=%2.2lx Q=%4.4lx",Msg->im_Code,Msg->im_Qualifier);
  195.                     Size=strlen(Buffer2);
  196.                     pOS_DrawText(Win->win_RastPort,Buffer2,Size);
  197.                     pOS_DrawText(Win->win_RastPort,EmptyString,16-Size); // Clear
  198.                   }
  199.                   break;
  200.  
  201.  
  202. /*\
  203. *** IDCMP_IntuiTicks
  204. \*/
  205.                 case IDCMP_IntuiTicks:
  206.                   {
  207.                     UBYTE Buffer[32];
  208.                     ULONG Size;
  209.                     struct pOS_TimeVal *TV=(struct pOS_TimeVal*)&Msg->im_Seconds;
  210.                     pOS_SubTime(TV,&StartTime);
  211.  
  212.                     pOS_SPrintf(Buffer,"Secs=%ld  %ld 1/10",TV->tv_Secs,TV->tv_Micro/100000);
  213.                     Size=strlen(Buffer);
  214.                     pOS_SetPosition(Win->win_RastPort,10,40);
  215.                     pOS_DrawText(Win->win_RastPort,Buffer,Size);
  216.                     pOS_DrawText(Win->win_RastPort,EmptyString,8); // Clear
  217.                   }
  218.                   break;
  219.  
  220.  
  221.                 case IDCMP_CloseWindow:  Ende=TRUE; break;
  222.                 default: if(pOS_SysIMessage(Msg)) Msg=NULL;
  223.               }
  224.  
  225.               if(Msg) pOS_ReplyMsg(&Msg->im_Message);
  226.             }
  227.           }
  228.           pOS_CloseWindow(Win);
  229.         }
  230.         else printf("Cannot open window\n");
  231.         pOS_UnlockPubScreen(Scr);
  232.       }
  233.       else printf("Cannot lock PubScreen\n");
  234.       pOS_DeleteDosArgs(Args);  /* Args freigeben */
  235.     }
  236.     else {
  237.       printf("Cannot open, TimerBase=0x%lx ConsoleBase=0x%lx\n",gb_TimerBase,gb_ConsoleBase);
  238.     }
  239.     if(gb_TimerBase)   pOS_CloseLibrary((struct pOS_Library*)gb_TimerBase);
  240.     if(gb_ConsoleBase) pOS_CloseLibrary((struct pOS_Library*)gb_ConsoleBase);
  241.   }
  242.   else Err=DOSFAIL_FAIL;  /* vollkommen fehlgeschlagen */
  243.  
  244.   pOS_SetShellFail(Err);
  245.  
  246.   pOS_CloseLibrary((pOS_Library*)gb_GfxBase);
  247.   pOS_CloseLibrary((pOS_Library*)gb_IntuiBase);
  248. }
  249.