home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / MENUMIN3.ZIP / CDD.C next >
Text File  |  1993-01-01  |  4KB  |  125 lines

  1. #define    INCL_BASE
  2. #include   <os2.h>
  3.  
  4. /* forward references */
  5. void far start(void);
  6. void _saveregs near realstart(int i);
  7. void initproc(void);
  8.  
  9. /* structure of an INIT device packet */
  10. typedef struct
  11. {
  12.    char    PktLen;             /* Lenght in bytes of packet            */
  13.    char    PktUnit;            /* Subunit number of block device       */
  14.    char    PktCmd;             /* Command code                         */
  15.    int     PktStatus;          /* Status word                          */
  16.    long    PktDOSLink;         /* Reserved                             */
  17.    long    PktDevLink;         /* Device multiple-request link         */
  18.    char    PktData[1];         /* Data pertaining to specific packet   */
  19.    int     codesize;           /* code size on INIT return             */
  20.    int     datasize;           /* data size on INIT return             */
  21. } PKT;
  22.  
  23. /* definitions of device driver return status */
  24. #define done   0x0100          /* Word representing the code for DONE  */
  25. #define error  0x8000          /* error return                         */
  26. #define general_failure 0xc    /* aaargh!                              */
  27.  
  28. /* structure of device header */
  29. typedef struct
  30. {
  31.    PSZ  ptr_to_next;           /* pointer to next device driver        */
  32.                                /* set to -1 OS/2 will fill it in       */
  33.    int  attributes;            /* attributes of device driver          */
  34.    PFN  strategy;              /* pointer to strategy routine          */
  35.                                /* + the ignored SEG part of strategy!  */
  36.    char name[8];               /* name of the device                   */
  37.    int rsvd[4];                /* used by OS/2                         */
  38. } DEVHDR;
  39.  
  40. /* definitions of some of the bits in the attribute word */
  41. #define devlev_1       0x0080  /* Bits 7-9 OS/2 1.x                    */
  42. #define dev_char_dev   0x8000  /* Bit 15: Device is a character device */
  43. #define dev_open       0x0800  /* Bit 11: Accepts Open/Close/Removable */
  44.  
  45. /* define this device */
  46. static DEVHDR devhdr =
  47. {
  48.    (PSZ) -1L,
  49.    devlev_1 | dev_char_dev | dev_open,
  50.    (PFN) start,
  51.    "CDD$    "
  52. };
  53.  
  54. /* definitions of the command values used */
  55. #define INIT   0
  56.  
  57. /* define _acrtused to prevent the C runtime startup code being linked in */
  58. int _acrtused = 0;
  59.  
  60. /* device driver entry point */
  61. /* ES:BX points to the device driver request packet */
  62. void far start(void)
  63. {
  64.    /* call the real entry point */
  65.    realstart(0);
  66. }
  67.  
  68. /* the 'real' device driver code - work around for the C5.1 bug */
  69. void _saveregs near realstart(int dummy)
  70. {
  71.    PKT far  *pkt;
  72.    int      *regptr;
  73.  
  74.    #define ES -11      /* offset for ES in saved registers */
  75.    #define BX -5       /* offset for BX in saved registers */
  76.  
  77.    regptr = &dummy;    /* get address of top of saved registers */
  78.  
  79.    pkt = MAKEP( regptr[ES], regptr[BX]);
  80.  
  81.    /* if not init command, return failure! */
  82.    if (pkt->PktCmd != INIT)
  83.    {
  84.        pkt->PktStatus = done + error + general_failure;
  85.        return;
  86.    }
  87.  
  88.    /* perform the initialisation function */
  89.    initproc();
  90.  
  91.    /* save code and data size to initialise as a device driver */
  92.    pkt->codesize  = (int)initproc;
  93.    pkt->datasize  = sizeof(DEVHDR);
  94.    pkt->PktStatus = done;
  95.  
  96. } /* realstart */
  97.  
  98. void initproc(void)
  99. {
  100.    static  KBDKEYINFO kbci;
  101.    RESULTCODES        res;
  102.  
  103.    /* initial read to kick things off - seems needed to wake up KBD subsystem */
  104.  
  105.      KbdPeek(&kbci, 0);
  106.  
  107.    /* tell the world we're ready */
  108.  
  109.    /* I know it is crazy, but if you eliminate the following VioWrtTTY
  110.       the system will trap when the driver is executed    boc */
  111.  
  112.      VioWrtTTY
  113.         ("   testing      testing     testing      testing  ", 50, 0);
  114.  
  115.      DosExecPgm(NULL,
  116.                   0,
  117.                   EXEC_SYNC,
  118.                   "cmd\0",                 /* no arguments            */
  119.                   NULL,                    /* inherit the environment */
  120.                   &res,                    /* resultcode              */
  121. /*                "C:\\os2\\cmd.exe"); */  /* program name            */
  122.                   "menumini.exe");     /* program name            */
  123.  
  124. } /* initproc */
  125.