home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 4 Drivers / 04-Drivers.zip / MIDI.ZIP / MIDIC.C next >
C/C++ Source or Header  |  1991-11-26  |  5KB  |  203 lines

  1. /****************************************************/
  2. /*                                                  */
  3. /*  Musical Instrument Digital Interface OS/2       */
  4. /*  Device Driver, primarily written in Microsoft   */
  5. /*  C (tm).                                         */
  6. /*                                                  */
  7. /*  Copyright IBM 1991.                             */
  8. /*                                                  */
  9. /*                                                  */
  10. /****************************************************/
  11.  
  12.  
  13.  
  14. #include "midic.h"
  15.  
  16. /***************************************************/
  17. /*                                                 */
  18. /* Device Header must be the FIRST data area       */
  19. /*                                                 */
  20. /***************************************************/
  21.  
  22. DeviceHeader devhdr = {
  23.   (void far *) -1,
  24.   (DAW_CHR | DAW_OPN | DAW_LEVEL),
  25.   (void near *) STRAT,
  26.   (void near *) 0,
  27.   {'M','I','D','I','$',' ',' ',' '},
  28.   {0}
  29. };
  30.  
  31. /****************************************************/
  32. /*                                                  */
  33. /* These next variables must be initialized all to  */
  34. /* zero.  Also, the MsgData is used not only to     */
  35. /* display the Device Driver message during the     */
  36. /* boot process, but is also used to write the end  */
  37. /* of data offset into the Request Header.          */
  38. /*                                                  */
  39. /****************************************************/
  40.  
  41. unsigned far *DevHlp=0L;/* Storage area for DevHlps */
  42. unsigned char rx_queue[10]={0}; /* receiver queue   */
  43. unsigned char tx_queue[10]={0}; /* transmitter queue*/
  44.  
  45. InitExit far  *InitExt=0L;   /* pointer to InitExit */
  46. DeviceRead far *DevRead=0L;  /* points to read strc */
  47. DeviceWrite far *DevWrite=0L;/* points to write str */
  48.  
  49. unsigned char MsgData[] = "Midi Device Driver  \r\n";
  50.  
  51.  
  52.  
  53. /*********************************/
  54. /*                               */
  55. /* Device Initialization Routine */
  56. /* is called only once during    */
  57. /* the OS/2 BOOT process.  The   */
  58. /* address of the DevHlp         */
  59. /*                               */
  60. /*********************************/
  61.  
  62. void Init(InitEntry far *InitPtr, int dev)
  63. {
  64.  
  65.     DevHlp = (unsigned far *)InitPtr->DevHlp;
  66.                                 /* callable DevHlp  */
  67.                                 /* entry point..    */
  68.  
  69.  
  70.  
  71.     /*********************************/
  72.     /*                               */
  73.     /* During Initialization we can  */
  74.     /* install the interrupt handler */
  75.     /* which will allow OS/2 to know */
  76.     /* where the code is that will   */
  77.     /* run, each time the interrupt  */
  78.     /* 9 happens.                    */
  79.     /*                               */
  80.     /*********************************/
  81.  
  82.     DOSPUTMESSAGE(1, 8, devhdr.name);
  83.     DOSPUTMESSAGE(1,strlen(MsgData),MsgData);
  84.  
  85.  
  86.     SetIRQ(9,(void near *)INT_HNDLR,0);
  87.  
  88.  
  89.     /* output initialization message */
  90.  
  91.     /* send back our cs and ds end values to os/2 */
  92.  
  93.     InitExt           = (InitExit far *)InitPtr;
  94.     InitExt->code_off = (unsigned short)last_code;
  95.     InitExt->data_off = (unsigned short)MsgData+
  96.                         strlen(MsgData);
  97.  
  98.     return;
  99. }
  100.  
  101. /* common entry point for calls to strat routines */
  102.  
  103. void main(ReqHeader far *rp, int dev )
  104. {
  105.  
  106.     switch(rp->req_cmd)
  107.     {
  108.       case INIT:
  109.  
  110.         Init((InitEntry far *)rp,dev);
  111.  
  112.         rp->req_stat = DONE;
  113.         return;
  114.  
  115.       case OPEN:
  116.  
  117.         /****************************/
  118.         /*                          */
  119.         /*  During OPEN, place MPU  */
  120.         /*  into "DUMB" mode.       */
  121.         /*                          */
  122.         /****************************/
  123.  
  124.         outp(MIDI_CMD,DUMB_MODE);
  125.  
  126.         rp->req_stat = DONE;
  127.         return;
  128.  
  129.       case CLOSE:
  130.  
  131.         /****************************/
  132.         /*                          */
  133.         /*  During CLOSE, reset MPU */
  134.         /*  mode.                   */
  135.         /*                          */
  136.         /****************************/
  137.  
  138.         outp(MIDI_CMD,MPU_RESET);
  139.         rp->req_stat = DONE;
  140.         return;
  141.  
  142.       case READ:
  143.  
  144.  
  145.         rx_queue[0] = inp(MIDI_DATA);
  146.         DevRead     = (DeviceRead far *)rp;
  147.  
  148.         ReadBytes((unsigned long)DevRead->buff_addr,
  149.                   (unsigned long)rx_queue,
  150.                   1);
  151.  
  152.         rp->req_stat = DONE;
  153.         return;
  154.  
  155.  
  156.       case WRITE:
  157.  
  158.         DevWrite = (DeviceWrite far *)rp;
  159.  
  160.         WriteBytes((unsigned long)DevWrite->buff_addr,
  161.                    (unsigned long)tx_queue,
  162.                    1);
  163.  
  164.         rp->req_stat = DONE;
  165.         return;
  166.  
  167.       case IOCTL:
  168.         rp->req_stat = DONE;
  169.         return;
  170.  
  171.       default:
  172.         rp->req_stat = DONE;
  173.         return;
  174.  
  175.     }
  176.  
  177. }
  178.  
  179. /***************************/
  180. /*                         */
  181. /* This interrupt handler  */
  182. /* is called by _INT_HNDLR */
  183. /* from the assembler pro- */
  184. /* cedure.  After return-  */
  185. /* ing, the DevHlp End of  */
  186. /* Interrupt function.     */
  187. /*                         */
  188. /***************************/
  189.  
  190. void near interrupt_handler ()
  191. {
  192.   rx_queue[0] = inp(0x0330);
  193. }
  194.  
  195. /**************************/
  196. /*                        */
  197. /* Last code offset....   */
  198. /*                        */
  199. /**************************/
  200.  
  201. void last_code() {}
  202.  
  203.