home *** CD-ROM | disk | FTP | other *** search
/ Virtual Reality Zone / VRZONE.ISO / mac / PC / PCGLOVE / 386PG.TXT < prev    next >
Internet Message Format  |  1994-12-20  |  5KB

  1. From dirtybob@u.washington.edu  Tue Aug 20 22:40:17 1991
  2. Received: from milton.u.washington.edu by karazm.math.uh.edu id <AA01976@karazm.math.uh.edu>; Tue, 20 Aug 91 22:40:17 CDT
  3. Received: by milton.u.washington.edu
  4.     (5.65/UW-NDC Revision: 2.1 ) id AA21418; Tue, 20 Aug 91 20:37:26 -0700
  5. Date: Tue, 20 Aug 91 20:37:26 -0700
  6. From: Wendell Joost <dirtybob@u.washington.edu>
  7. Message-Id: <9108210337.AA21418@milton.u.washington.edu>
  8. Sender: dirtybob@milton.u.washington.edu
  9. To: glove-list@karazm.math.uh.edu
  10. Subject: Powerglove C Code (I hope!) provided this upload works ...
  11. Status: OR
  12.  
  13. Okay, here's (I hope) the C code for IBMPC 386.
  14. The Byte Box I referred to was merely a box containing the proper connections
  15. ala Byte magazine to interface the PG to a PC printer port.
  16. This was written by Bandit and MIchael Hevern, I merely poured the beer
  17. and kept the programming on track ...
  18.  
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. #include <dos.h>
  22.  
  23. #define                DELAY                delay_val
  24. #define                PORT_CTL        0x0378
  25. #define                PORT_DATA        0x0379
  26. #define                LATCH_LO        0
  27. #define                LATCH_HI        0x02
  28. #define                CLOCK_LO        0
  29. #define                CLOCK_HI        0x01
  30.  
  31. unsigned char        get_glove(void);
  32. void display_str( unsigned char );
  33. int               delay_val=100;
  34.  
  35. main()
  36. {
  37.         char        ch[20];
  38.         unsigned char
  39.                 x,
  40.                 last_x;
  41.  
  42.         x = 0;
  43.  
  44.         printf("Enter the delay[100] -> ");
  45.         delay_val = atoi(gets(ch));
  46.         while (1) {
  47.                 if( x != last_x )
  48.                 {
  49.                      /*        printf("X = %02x  ", x); */
  50.                         display_str( x );
  51. /*                        printf("Press key (q)-> ");
  52.                         ch = getche();
  53.                         if (ch == 'q')
  54.                                 break;
  55.                         if (ch == '+') 
  56.                           {delay_val++;
  57.                            printf("Delay Value = %d \n", delay_val);
  58.                         if (ch == '-') 
  59.                           {delay_val = delay_val - 1;
  60.                            printf("Delay Value = %d \n", delay_val);
  61.                           }
  62. */                }
  63.  
  64.                 last_x = x;
  65.                 x = get_glove();
  66.                 }
  67. }
  68.  
  69. #define IN_BYTE( xx )        { xx = inportb( PORT_DATA ); }
  70. #define OUT_BYTE( xx )        { outportb( PORT_CTL, xx ); \
  71.                                   for (delay=0; delay < DELAY; delay++); }
  72.  
  73. unsigned char        get_glove()
  74. {
  75.         unsigned char
  76.                 far        *ctl,
  77.                 far        *data,
  78.                 value;
  79.         unsigned char
  80.                 results;
  81.         int        x,
  82.                 delay;
  83.  
  84.         ctl = MK_FP(0, PORT_CTL);
  85.         data = MK_FP(0, PORT_DATA);
  86.  
  87.         /*        *ctl = LATCH_LO + CLOCK_HI;        */
  88.         OUT_BYTE( (LATCH_LO + CLOCK_HI) );
  89.         OUT_BYTE( (LATCH_HI + CLOCK_HI) );
  90.         OUT_BYTE( (LATCH_LO + CLOCK_HI) );
  91.  
  92.         for (results=0, x=0; x < 8; x++) {
  93.                 results <<= 1;
  94.                 IN_BYTE(value);
  95.                 if (value & 0x10)
  96.                         results |= 1;
  97.                 OUT_BYTE( (LATCH_LO + CLOCK_LO) );
  98.                 OUT_BYTE( (LATCH_LO + CLOCK_HI) );
  99.                 }
  100.         return( ~results );
  101. }
  102.  
  103. typedef struct
  104. {
  105.         unsigned char mask;
  106.         char *off_str;
  107.         char *on_str;
  108. } DISP_STRUCT;
  109.  
  110. DISP_STRUCT disp[] =
  111. {
  112.         {        0x80,        "  A_UP",        "A_DOWN"        },
  113.         {        0x40,        "  B_UP",        "B_DOWN"        },
  114.         {        0x20,        "NO_SEL",        "SELECT"        },
  115.         {        0x10,        "NO_SRT",        " START"        },
  116.         {        0x08,        "      ",        "    UP"        },
  117.         {        0x04,        "      ",        "  DOWN"        },
  118.         {        0x02,        "      ",        "  LEFT"        },
  119.         {        0x01,        "      ",        " RIGHT"        },
  120.  
  121. };
  122.  
  123. void display_str( unsigned char value )
  124. {
  125.         int i;
  126.         char *str;
  127.  
  128.         printf( " %02x:", value );
  129.  
  130.         for( i = 0; i < 8; i++ )
  131.         {
  132.                 if( value & disp[ i ].mask )        str = disp[i].on_str;
  133.                 else                                str = disp[i].off_str;
  134.  
  135.                 printf( " %s", str );
  136.         }
  137.         printf( "\n" );
  138. }
  139.  
  140. ********!!!!!!!
  141. Okay,
  142. that's it.  Good luck with it, and my best wishes to those of you working
  143. to decode High Resolution mode.  We're rooting for you here at UW!
  144.   
  145.  
  146.