home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / CD32 / CD32_Support / examples / SA_Examples / cd / CDTest / event.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-10-27  |  4.6 KB  |  210 lines

  1. /*
  2. **  cd.device Test
  3. **  Written by John J. Szucs
  4. **  Copyright © 1993-1999 Amiga, Inc.
  5. **  All Rights Reserved
  6. */
  7.  
  8. /*
  9. **  ANSI includes
  10. */
  11.  
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <string.h>
  15. #include <math.h>
  16.  
  17. /*
  18. **  System includes
  19. */
  20.  
  21. #include <exec/types.h>
  22. #include <exec/interrupts.h>
  23. #include <exec/io.h>
  24.  
  25. #include <dos/dos.h>
  26.  
  27. #include <devices/cd.h>
  28.  
  29. #include <rexx/rxslib.h>
  30. #include <rexx/storage.h>
  31. #include <rexx/errors.h>
  32.  
  33. #include <clib/exec_protos.h>
  34. #include <clib/dos_protos.h>
  35. #include <clib/rexxsyslib_protos.h>
  36. #include <clib/alib_protos.h>
  37.  
  38. /*
  39. **  Local includes
  40. */
  41.  
  42. #include "simplerexx.h"
  43. #include "cdtest.h"
  44.  
  45. /****** cd/eventLoop ******************************************
  46. *
  47. *   NAME
  48. *       eventLoop   -   event loop
  49. *
  50. *   SYNOPSIS
  51. *       eventLoop();
  52. *
  53. *       void eventLoop(void);
  54. *
  55. *   FUNCTION
  56. *       Event loop.
  57. *
  58. *   INPUTS
  59. *       None
  60. *
  61. *   RESULT
  62. *       None
  63. *
  64. *   EXAMPLE
  65. *
  66. *   NOTES
  67. *
  68. *   BUGS
  69. *
  70. *   SEE ALSO
  71. *
  72. ******************************************************************************
  73. *
  74. */
  75.  
  76. void eventLoop(void)
  77. {
  78.  
  79.     ULONG signalFlags;
  80.     struct RexxMsg *rxMsg;
  81.  
  82.     static struct commandEntry commandTable[] ={
  83.         /* cd.device commands */
  84.         "ADDCHANGEINT", cdAddChangeInt,
  85.         "ADDFRAMEINT", cdAddFrameInt,
  86.         "ATTENUATE", cdAttenuate,
  87.         "CHANGENUM", cdChangeNum,
  88.         "CHANGESTATE", cdChangeState,
  89.         "CONFIG", cdConfig,
  90.         "EJECT", cdEject,
  91.         "GETGEOMETRY", cdGetGeometry,
  92.         "INFO", cdInfo,
  93.         "MOTOR", cdMotor,
  94.         "PAUSE", cdPause,
  95.         "PLAYLSN", cdPlayLSN,
  96.         "PLAYMSF", cdPlayMSF,
  97.         "PLAYTRACK", cdPlayTrack,
  98.         "PROTSTATUS", cdProtStatus,
  99.         "QCODELSN", cdQCodeLSN,
  100.         "QCODEMSF", cdQCodeMSF,
  101.         "READ", cdRead,
  102.         "READXL", cdReadXL,
  103.         "REMCHANGEINT", cdRemChangeInt,
  104.         "REMFRAMEINT", cdRemFrameInt,
  105.         "SEARCH", cdSearch,
  106.         "SEEK", cdSeek,
  107.         "TOCLSN", cdTOCLSN,
  108.         "TOCMSF", cdTOCMSF,
  109.  
  110.         /* Support commands */
  111.         "GETCHANGEINT", getChangeInt,
  112.         "GETFRAMEINT", getFrameInt,
  113.  
  114.         /* Debugging commands */
  115.         "SETSTEMVARINT", testStemVarInt,
  116.  
  117.         NULL, NULL
  118.     };
  119.  
  120.     /* Infinite loop */
  121.     FOREVER {
  122.  
  123.         /* Wait for ... */
  124.         signalFlags=Wait(
  125.             SIGBREAKF_CTRL_C            /* Break ... */
  126.             |ARexxSignal(rexxContext)   /* ... or ARexx message */
  127.         );
  128.  
  129.         /* If ARexx message ... */
  130.         if (signalFlags&ARexxSignal(rexxContext)) {
  131.  
  132.             /* Process ARexx messages */
  133.             while (rxMsg=GetARexxMsg(rexxContext)) {
  134.  
  135.                 struct commandEntry *commandEntry;
  136.  
  137.                 char commandBuffer[REXXCOMMAND_LENGTH];
  138.                 char *nextChar;
  139.                 STRPTR result;
  140.                 LONG error;
  141.  
  142.                 /* Fetch command */
  143.                 nextChar=stptok(ARG0(rxMsg),commandBuffer,
  144.                     REXXCOMMAND_LENGTH," ,");
  145.                 if (*nextChar) {
  146.                     nextChar++;
  147.                 }
  148.  
  149.                 /* If "QUIT" ... */
  150.                 if (stricmp(commandBuffer,"QUIT")==0) {
  151.                     /* Reply to ARexx message */
  152.                     ReplyARexxMsg(rexxContext,rxMsg,NULL,RC_OK);
  153.                     /* Exit event loop */
  154.                     return;
  155.                 }
  156.  
  157.                 /* Look-up command */
  158.                 commandEntry=commandTable;
  159.                 while (commandEntry->command) {
  160.  
  161.                     if (stricmp(commandBuffer,commandEntry->command)==0) {
  162.  
  163.                         if (debugMode) {
  164.                             printf("Command %s\n",commandBuffer);
  165.                         }
  166.  
  167.                         /* Clear error value */
  168.                         error=RC_OK;
  169.  
  170.                         /* Execute command code */
  171.                         result=(commandEntry->function)(rxMsg,nextChar,&error);
  172.  
  173.                         /* Terminate look-up loop */
  174.                         break;
  175.  
  176.                     }
  177.                     commandEntry++;
  178.  
  179.                 }
  180.  
  181.                 /* If command not found ... */
  182.                 if (!commandEntry->command) {
  183.  
  184.                     /* Error */
  185.                     if (debugMode) {
  186.                         printf("Command %s not recognized\n",
  187.                             commandBuffer);
  188.                     }
  189.                     error=RC_ERROR;
  190.                     result=NULL;
  191.  
  192.                 }
  193.  
  194.                 /* Reply to ARexx message */
  195.                 ReplyARexxMsg(rexxContext,rxMsg,result,error);
  196.  
  197.             }
  198.  
  199.         }
  200.  
  201.         /* If break ... */
  202.         if (signalFlags&SIGBREAKF_CTRL_C) {
  203.             /* Return */
  204.             return;
  205.         }
  206.  
  207.     }
  208.  
  209. }
  210.