Subject: Powerglove C Code (I hope!) provided this upload works ...

From: Wendell Joost <[email-masked]>
Date: Tue, 20 Aug 91 20:37:26 -0700

Okay, here's (I hope) the C code for IBMPC 386.
The Byte Box I referred to was merely a box containing the proper connections
ala Byte magazine to interface the PG to a PC printer port.
This was written by Bandit and MIchael Hevern, I merely poured the beer
and kept the programming on track ...

#include <stdio.h>
#include <stdlib.h>
#include <dos.h>
 
#define                DELAY                delay_val
#define                PORT_CTL        0x0378
#define                PORT_DATA        0x0379
#define                LATCH_LO        0
#define                LATCH_HI        0x02
#define                CLOCK_LO        0
#define                CLOCK_HI        0x01
 
unsigned char        get_glove(void);
void display_str( unsigned char );
int               delay_val=100;
 
main()
{
        char        ch[20];
        unsigned char
                x,
                last_x;
 
        x = 0;
 
        printf("Enter the delay[100] -> ");
        delay_val = atoi(gets(ch));
        while (1) {
                if( x != last_x )
                {
                     /*        printf("X = %02x  ", x); */
                        display_str( x );
/*                        printf("Press key (q)-> ");
                        ch = getche();
                        if (ch == 'q')
                                break;
                        if (ch == '+') 
                          {delay_val++;
                           printf("Delay Value = %d \n", delay_val);
                        if (ch == '-') 
                          {delay_val = delay_val - 1;
                           printf("Delay Value = %d \n", delay_val);
                          }
*/                }
 
                last_x = x;
                x = get_glove();
                }
}
 
#define IN_BYTE( xx )        { xx = inportb( PORT_DATA ); }
#define OUT_BYTE( xx )        { outportb( PORT_CTL, xx ); \
                                  for (delay=0; delay < DELAY; delay++); }
 
unsigned char        get_glove()
{
        unsigned char
                far        *ctl,
                far        *data,
                value;
        unsigned char
                results;
        int        x,
                delay;
 
        ctl = MK_FP(0, PORT_CTL);
        data = MK_FP(0, PORT_DATA);
 
        /*        *ctl = LATCH_LO + CLOCK_HI;        */
        OUT_BYTE( (LATCH_LO + CLOCK_HI) );
        OUT_BYTE( (LATCH_HI + CLOCK_HI) );
        OUT_BYTE( (LATCH_LO + CLOCK_HI) );
 
        for (results=0, x=0; x < 8; x++) {
                results <<= 1;
                IN_BYTE(value);
                if (value & 0x10)
                        results |= 1;
                OUT_BYTE( (LATCH_LO + CLOCK_LO) );
                OUT_BYTE( (LATCH_LO + CLOCK_HI) );
                }
        return( ~results );
}
 
typedef struct
{
        unsigned char mask;
        char *off_str;
        char *on_str;
} DISP_STRUCT;
 
DISP_STRUCT disp[] =
{
        {        0x80,        "  A_UP",        "A_DOWN"        },
        {        0x40,        "  B_UP",        "B_DOWN"        },
        {        0x20,        "NO_SEL",        "SELECT"        },
        {        0x10,        "NO_SRT",        " START"        },
        {        0x08,        "      ",        "    UP"        },
        {        0x04,        "      ",        "  DOWN"        },
        {        0x02,        "      ",        "  LEFT"        },
        {        0x01,        "      ",        " RIGHT"        },
 
};
 
void display_str( unsigned char value )
{
        int i;
        char *str;
 
        printf( " %02x:", value );
 
        for( i = 0; i < 8; i++ )
        {
                if( value & disp[ i ].mask )        str = disp[i].on_str;
                else                                str = disp[i].off_str;
 
                printf( " %s", str );
        }
        printf( "\n" );
}

********!!!!!!!
Okay,
that's it.  Good luck with it, and my best wishes to those of you working
to decode High Resolution mode.  We're rooting for you here at UW!