home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Club Amiga de Montreal - CAM
/
CAM_CD_1.iso
/
files
/
571.lha
/
AmigaPowerGloveHi-ResHack
/
glovehack
/
glove.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-10-12
|
13KB
|
789 lines
/**********************************************************************
This ugly hack is based on the ATARI 1040ST power glove
hack by manfredo@opal.cs.tu-berlin.de.
This program is without any WARRANTY use at your OWN risk
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
This Amiga hack was done by Alan Bland. It is not directly
compatible with the AC Tech hack, the BYTE hack, nor the
ATARI 1040ST hack, but you should be able to modify the
code to work with any of those hacks.
The Amiga code is ugly, as was the original ST code. The
parallel port hardware is accessed directly without knowledge
of the operating system.
Connect NINTENDO POWERGLOVE to Amiga parallel port
------
/ 1 |
| 5 2 |
| 6 3 |
| 7 4 |
--------
GLOVE AMIGA
===== =====
GND pin1 pin18 parallel port
clock pin2 pin2 parallel port
latch pin3 pin3 parallel port
data pin4 pin4 parallel port
+5V pin7 pin14 power +5V
Datapacket: (12 bytes)
1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12.
A0 X Y Z rot finger keys 00 00 3F FF FF
**********************************************************************/
#include <stdio.h>
#include <hardware/cia.h>
extern struct CIA far ciaa;
/* bits from parallel port -- Alan's hack */
#define GDATA 0x04 /* glove data in */
#define GLATCH 0x02 /* glove latch out */
#define GCLOCK 0x01 /* glove clock out */
#define GCLOLAT (GLATCH|GCLOCK) /* latch and clock */
#define getbit() (ciaa.ciaprb & GDATA) >> 2
#define initport() ciaa.ciaddrb = GCLOLAT
/* delays in microseconds */
#define D2BYTES 96
#define D2BITS 22
#define D2SLOW 14720
#define C0L0() ciaa.ciaprb = 0 /* clock 0 latch 0 */
#define C0L1() ciaa.ciaprb = GLATCH /* clock 0 latch 1 */
#define C1L0() ciaa.ciaprb = GCLOCK /* clock 1 latch 0 */
#define C1L1() ciaa.ciaprb = GCLOLAT /* clock 1 latch 1 */
#define setporta() delay(3)
#define setportb() delay(3)
void Hires (void);
unsigned char getbyte (void);
/* convert microseconds to cia ticks */
#define delay(usec) timersleep((usec*1397)/1000)
int control_c()
{
closetimer();
printf("<<goodbye>>\n");
return 1; /* causes exit */
}
void main ()
{
unsigned char buf[12];
register unsigned char *bp;
opentimer();
onbreak(control_c);
Hires (); /* set PG into 'hires' mode */
printf("Press ^C to stop\n\nx y z rot finger button\n");
for ( ; ; ) /* read 12 byte packets */
{
bp = buf;
*bp++ = getbyte ();
delay (D2BYTES);
*bp++ = getbyte ();
delay (D2BYTES);
*bp++ = getbyte ();
delay (D2BYTES);
*bp++ = getbyte ();
delay (D2BYTES);
*bp++ = getbyte ();
delay (D2BYTES);
*bp++ = getbyte ();
delay (D2BYTES);
*bp++ = getbyte ();
delay (D2BYTES);
*bp++ = getbyte ();
delay (D2SLOW);
*bp++ = getbyte ();
delay (D2SLOW);
*bp++ = getbyte ();
delay (D2SLOW);
*bp++ = getbyte ();
delay (D2SLOW);
*bp++ = getbyte ();
delay (D2SLOW);
/* Glove packet isn't quite as described above */
/* Let's see if we can figure it out */
{
int i,n;
/* look for FF FF A0 */
n = -1;
for (i=0; i<12; ++i) {
if (buf[i] == (unsigned char)0xff &&
buf[(i+1)%12] == (unsigned char)0xff &&
buf[(i+2)%12] == (unsigned char)0xa0) {
/* yah! */
n = (i+3)%12;
printf("%-3d %-3d %-3d %-3d %-2x %-2x\n",
buf[n], buf[(n+1)%12], buf[(n+2)%12],
buf[(n+3)%12],
buf[(n+4)%12],
buf[(n+5)%12]);
break;
}
}
if (n < 0) printf("\033[K\n");
printf ("Glove %-2x %-2x %-2x %-2x %-2x %-2x %-2x %-2x %-2x %-2x %-2x %-2x\r\033[A",
buf[0], buf[1], buf[2], buf[3], buf[4], buf[5],
buf[6], buf[7], buf[8], buf[9], buf[10], buf[11]);
}
}
}
unsigned char getbyte ()
{
register unsigned Glov = 0;
/* prepare port b as output port */
setportb ();
/* generate a reset (latch) pulse */
C1L0 ();
C1L1 ();
delay(5); /* 5 us delay */
C1L0 ();
/* configure port a as input */
setporta ();
/* read a bit */
Glov <<= 1;
Glov |= getbit();
/* prepare port b as output port */
setportb ();
/* generate a clock pulse */
C0L0 ();
C1L0 ();
/* configure port a as input */
setporta ();
/* read a bit */
Glov <<= 1;
Glov |= getbit();
/* prepare port b as output port */
setportb ();
/* generate a clock pulse */
C0L0 ();
C1L0 ();
/* configure port a as input */
setporta ();
/* read a bit */
Glov <<= 1;
Glov |= getbit();
/* prepare port b as output port */
setportb ();
/* generate a clock pulse */
C0L0 ();
C1L0 ();
/* configure port a as input */
setporta ();
/* read a bit */
Glov <<= 1;
Glov |= getbit();
/* prepare port b as output port */
setportb ();
/* generate a clock pulse */
C0L0 ();
C1L0 ();
/* configure port a as input */
setporta ();
/* read a bit */
Glov <<= 1;
Glov |= getbit();
/* prepare port b as output port */
setportb ();
/* generate a clock pulse */
C0L0 ();
C1L0 ();
/* configure port a as input */
setporta ();
/* read a bit */
Glov <<= 1;
Glov |= getbit();
/* prepare port b as output port */
setportb ();
/* generate a clock pulse */
C0L0 ();
C1L0 ();
/* configure port a as input */
setporta ();
/* read a bit */
Glov <<= 1;
Glov |= getbit();
/* prepare port b as output port */
setportb ();
/* generate a clock pulse */
C0L0 ();
C1L0 ();
/* configure port a as input */
setporta ();
/* read a bit */
Glov <<= 1;
Glov |= getbit();
/* prepare port b as output port */
setportb ();
/* generate a clock pulse */
C0L0 ();
C1L0 ();
return (unsigned char) Glov; /* return the byte */
}
void Hires ()
{
register unsigned char Glov = 0;
/* initialize hardware interface */
initport();
/* read 4 bits from glove */
setportb ();
/* generate a reset (latch) pulse */
C1L0 ();
C1L1 ();
delay(5); /* 5 us delay */
C1L0 ();
/* configure port a as input */
setporta ();
/* read a bit */
Glov <<= 1;
Glov |= getbit();
/* prepare port b as output port */
setportb ();
/* generate a clock pulse */
C0L0 ();
C1L0 ();
/* configure port a as input */
setporta ();
/* read a bit */
Glov <<= 1;
Glov |= getbit();
/* prepare port b as output port */
setportb ();
/* generate a clock pulse */
C0L0 ();
C1L0 ();
/* configure port a as input */
setporta ();
/* read a bit */
Glov <<= 1;
Glov |= getbit();
/* prepare port b as output port */
setportb ();
/* generate a clock pulse */
C0L0 ();
C1L0 ();
/* configure port a as input */
setporta ();
/* read a bit */
Glov <<= 1;
Glov |= getbit();
/* prepare port b as output port */
setportb ();
/* generate a clock pulse */
C0L0 ();
C1L0 ();
/* end of read 4 bits */
/* prepare port b as output port */
setportb ();
C1L0 ();
delay(7212);
/* delay (16950); /* 7212 us delay */
setportb ();
C1L1 ();
delay(2260);
/* delay (4750); /* 2260 us delay */
/* prepare port b as output port */
setportb ();
C1L0 (); /* Start of 1. Byte */
C0L0 ();
C1L0 ();
delay (D2BITS);
/* prepare port b as output port */
setportb ();
C0L0 ();
C1L0 ();
delay (D2BITS);
/* prepare port b as output port */
setportb ();
C0L0 ();
C1L0 ();
delay (D2BITS);
/* prepare port b as output port */
setportb ();
C0L0 ();
C1L0 ();
delay (D2BITS);
/* prepare port b as output port */
setportb ();
C0L0 ();
C1L0 ();
delay (D2BITS);
/* prepare port b as output port */
setportb ();
C1L1 ();
C0L1 ();
C1L1 ();
delay (D2BITS);
/* prepare port b as output port */
setportb ();
C0L1 ();
C1L1 ();
delay (D2BITS);
/* prepare port b as output port */
setportb ();
C1L0 ();
C0L0 ();
C1L0 ();
delay (D2BYTES);
/* prepare port b as output port */
setportb ();
C1L1 (); /* Start of 2. Byte */
C0L1 ();
C1L1 ();
delay (D2BITS);
/* prepare port b as output port */
setportb ();
C0L1 ();
C1L1 ();
delay (D2BITS);
/* prepare port b as output port */
setportb ();
C1L0 ();
C0L0 ();
C1L0 ();
delay (D2BITS);
/* prepare port b as output port */
setportb ();
C0L0 ();
C1L0 ();
delay (D2BITS);
/* prepare port b as output port */
setportb ();
C0L0 ();
C1L0 ();
delay (D2BITS);
/* prepare port b as output port */
setportb ();
C0L0 ();
C1L0 ();
delay (D2BITS);
/* prepare port b as output port */
setportb ();
C0L0 ();
C1L0 ();
delay (D2BITS);
/* prepare port b as output port */
setportb ();
C1L1 ();
C0L1 ();
C1L1 ();
delay (D2BYTES);
/* prepare port b as output port */
setportb ();
C1L0 (); /* Start of 3. Byte */
C0L0 ();
C1L0 ();
delay (D2BITS);
/* prepare port b as output port */
setportb ();
C0L0 ();
C1L0 ();
delay (D2BITS);
/* prepare port b as output port */
setportb ();
C0L0 ();
C1L0 ();
delay (D2BITS);
/* prepare port b as output port */
setportb ();
C0L0 ();
C1L0 ();
delay (D2BITS);
/* prepare port b as output port */
setportb ();
C1L1 ();
C0L1 ();
C1L1 ();
delay (D2BITS);
/* prepare port b as output port */
setportb ();
C1L0 ();
C0L0 ();
C1L0 ();
delay (D2BITS);
/* prepare port b as output port */
setportb ();
C0L0 ();
C1L0 ();
delay (D2BITS);
/* prepare port b as output port */
setportb ();
C0L0 ();
C1L0 ();
delay (D2BYTES);
/* prepare port b as output port */
setportb ();
C0L0 (); /* start of 4. byte */
C1L0 ();
delay (D2BITS);
/* prepare port b as output port */
setportb ();
C0L0 ();
C1L0 ();
delay (D2BITS);
/* prepare port b as output port */
setportb ();
C0L0 ();
C1L0 ();
delay (D2BITS);
/* prepare port b as output port */
setportb ();
C0L0 ();
C1L0 ();
delay (D2BITS);
/* prepare port b as output port */
setportb ();
C0L0 ();
C1L0 ();
delay (D2BITS);
/* prepare port b as output port */
setportb ();
C0L0 ();
C1L0 ();
delay (D2BITS);
/* prepare port b as output port */
setportb ();
C0L0 ();
C1L0 ();
delay (D2BITS);
/* prepare port b as output port */
setportb ();
C0L0 ();
C1L0 ();
delay (D2BYTES);
/* prepare port b as output port */
setportb ();
C0L0 (); /* start of 5. byte */
C1L0 ();
delay (D2BITS);
/* prepare port b as output port */
setportb ();
C0L0 ();
C1L0 ();
delay (D2BITS);
/* prepare port b as output port */
setportb ();
C0L0 ();
C1L0 ();
delay (D2BITS);
/* prepare port b as output port */
setportb ();
C0L0 ();
C1L0 ();
delay (D2BITS);
/* prepare port b as output port */
setportb ();
C0L0 ();
C1L0 ();
delay (D2BITS);
/* prepare port b as output port */
setportb ();
C0L0 ();
C1L0 ();
delay (D2BITS);
/* prepare port b as output port */
setportb ();
C1L1 ();
C0L1 ();
C1L1 ();
delay (D2BITS);
/* prepare port b as output port */
setportb ();
C1L0 ();
C0L0 ();
C1L0 ();
delay (D2BYTES);
/* prepare port b as output port */
setportb ();
C1L1 (); /* start of 6. byte */
C0L1 ();
C1L1 ();
delay (D2BITS);
/* prepare port b as output port */
setportb ();
C0L1 ();
C1L1 ();
delay (D2BITS);
/* prepare port b as output port */
setportb ();
C0L1 ();
C1L1 ();
delay (D2BITS);
/* prepare port b as output port */
setportb ();
C0L1 ();
C1L1 ();
delay (D2BITS);
/* prepare port b as output port */
setportb ();
C0L1 ();
C1L1 ();
delay (D2BITS);
/* prepare port b as output port */
setportb ();
C0L1 ();
C1L1 ();
delay (D2BITS);
/* prepare port b as output port */
setportb ();
C0L1 ();
C1L1 ();
delay (D2BITS);
/* prepare port b as output port */
setportb ();
C0L1 ();
C1L1 ();
delay (D2BYTES);
/* prepare port b as output port */
setportb ();
C1L0 (); /* start of 7. byte */
C0L0 ();
C1L0 ();
delay (D2BITS);
/* prepare port b as output port */
setportb ();
C0L0 ();
C1L0 ();
delay (D2BITS);
/* prepare port b as output port */
setportb ();
C0L0 ();
C1L0 ();
delay (D2BITS);
/* prepare port b as output port */
setportb ();
C0L0 ();
C1L0 ();
delay (D2BITS);
/* prepare port b as output port */
setportb ();
C0L0 ();
C1L0 ();
delay (D2BITS);
/* prepare port b as output port */
setportb ();
C0L0 ();
C1L0 ();
delay (D2BITS);
/* prepare port b as output port */
setportb ();
C0L0 ();
C1L0 ();
delay (D2BITS);
/* prepare port b as output port */
setportb ();
C1L1 ();
C0L1 ();
C1L1 ();
delay(892);
/* delay (1090); /* 892 us delay (end of 7. byte) */
/* prepare port b as output port */
setportb ();
C1L0 ();
delay(50000);
/* delay (60000); /* some time for the glove controller
to relax */
}