home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / CD32 / CD32_Support / examples / warnifpressed.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-06-06  |  2.8 KB  |  131 lines

  1. ;/* warnifpressed.c - Execute me to compile me with SAS C 5.10
  2. LC -b1 -cfistq -v -y -j73 warnifpressed.c
  3. Blink FROM LIB:c.o,warnifpressed.o TO warnifpressed LIBRARY LIB:LC.lib,LIB:Amiga.lib,LIB:debug.lib ND
  4. quit
  5. */
  6.  
  7. #include <exec/types.h>
  8. #include <libraries/lowlevel.h>
  9. #include <dos/dos.h>
  10.  
  11. #include <clib/exec_protos.h>
  12. #include <clib/dos_protos.h>
  13. #include <clib/lowlevel_protos.h>
  14.  
  15. extern struct Library *SysBase;
  16. extern struct Library *DOSBase;
  17.  
  18. #include <pragmas/exec_pragmas.h>
  19. #include <pragmas/dos_pragmas.h>
  20. #include <pragmas/lowlevel_pragmas.h>
  21.  
  22.  
  23. #include <stdlib.h>
  24. #include <stdio.h>
  25. #include <string.h>
  26.  
  27. #ifdef LATTICE
  28. int CXBRK(void)  { return(0); }  /* Disable Lattice CTRL/C handling */
  29. void chkabort(void) { return; }  /* really */
  30. #endif
  31.  
  32. #define MINARGS 2
  33.  
  34. UBYTE *vers = "\0$VER: warnifpressed 40.2";
  35. UBYTE *Copyright = 
  36.   "warnifpressed v40.2\n(c) Copyright 1993-1988 Amiga, Inc.  All Rights Reserved";
  37. UBYTE *usage =
  38. "Usage: warnifpressed button [button button...] [PORT0]\n"
  39. "RED(LMB) BLUE(RMB) GREEN YELLOW FORWARD(R_EAR) REVERSE(L_EAR) PLAY\n";
  40.  
  41.  
  42. UBYTE *names[] = {
  43. "RED", "LMB", "BLUE", "RMB",
  44. "GREEN", "YELLOW",
  45. "FORWARD", "R_EAR", "REVERSE", "L_EAR",
  46. "PLAY", NULL};
  47.  
  48. ULONG bits[] = {
  49. JPF_BUTTON_RED,JPF_BUTTON_RED,JPF_BUTTON_BLUE,JPF_BUTTON_BLUE,
  50. JPF_BUTTON_GREEN,JPF_BUTTON_YELLOW,
  51. JPF_BUTTON_FORWARD,JPF_BUTTON_FORWARD,JPF_BUTTON_REVERSE,JPF_BUTTON_REVERSE,
  52. JPF_BUTTON_PLAY, 0};
  53.  
  54. /**********    debug macros     ***********/
  55. #define MYDEBUG  0
  56. void kprintf(UBYTE *fmt,...);
  57. void dprintf(UBYTE *fmt,...);
  58. #define DEBTIME 0
  59. #define bug kprintf
  60. #if MYDEBUG
  61. #define D(x) (x); if(DEBTIME>0) Delay(DEBTIME);
  62. #define D2(x) ;
  63. #else
  64. #define D(x) ;
  65. #define D2(x) ;
  66. #endif /* MYDEBUG */
  67. /********** end of debug macros **********/
  68.  
  69. struct Library     *LowLevelBase = NULL;
  70.  
  71. void cleanup( void )
  72.     {
  73.     if(LowLevelBase)    CloseLibrary(LowLevelBase);
  74.     }
  75.  
  76. void bye(UBYTE *s, int e)
  77.     {
  78.     if(*s)    printf("%s\n",s);
  79.     cleanup();
  80.     exit(e);    
  81.     }
  82.  
  83.  
  84. void main(int argc, char **argv)
  85.     {
  86.     ULONG askstate, state, port;
  87.     int k,i,retval;
  88.  
  89.     if(((argc)&&(argc<MINARGS))||((argc>1)&&(argv[argc-1][0]=='?')))
  90.     {
  91.     printf("%s\n%s\n",Copyright,usage);
  92.     exit(RETURN_OK);
  93.     }
  94.  
  95.     port=1;
  96.     askstate = 0L;
  97.     for(k=1; k<argc; k++)
  98.     {
  99.     if(!(stricmp(argv[k],"PORT0")))    port=0;
  100.     else for(i=0; names[i]; i++)
  101.         {
  102.         if(!(stricmp(argv[k],names[i])))
  103.         {
  104.         askstate |= bits[i];
  105.         break;
  106.         }
  107.         }
  108.     }
  109.  
  110.     if(!(LowLevelBase = OpenLibrary("lowlevel.library",40)))
  111.     {
  112.     bye("Can't open lowlevel.library v40+",RETURN_FAIL);
  113.     }    
  114.  
  115.     /* Note - in startup-sequnece, single ReadJoyPort() did not
  116.      * return special game controller buttons
  117.      */
  118.  
  119.     state = ReadJoyPort(port);
  120.     Delay(10);
  121.     state = ReadJoyPort(port);
  122.     Delay(10);
  123.     state = ReadJoyPort(port);
  124.  
  125.  
  126.     retval = 0L;
  127.     if((state&askstate)==askstate)    retval = RETURN_WARN;
  128.  
  129.     bye("",retval);
  130.     }
  131.