/* DirectPad Pro Joystick Scanning Code - V4.9 */ /* (c) Earle F. Philhower, III */ /* See http://www.ziplabel.com/dpadpro for more information */ #define OUTP(a,b) {int aa; for (aa=0; aa<3; aa++) _outp((a), (b));} #define OUTPS(a,b) {int i; for (i=0; i<8; i++) _outp((a),(b)); } #define SNES_PWR (128+64+32+16+8) #define SNES_CLK 1 // base+0 #define SNES_LAT 2 // base+0 #define SIN (negate?((_inp(base+1)&snes_din)?1:0):((_inp(base+1)&snes_din)?0:1)) #define SNESIT(a) {if (snesdelay==3) {int i; for (i=0; i<3; i++) _outp(base, (a));} else {int i; for (i=0; i<snesdelay; i++) _outp(base, (a));} } typedef struct mySNES { char dn; char up; char lf; char rt; char a, b; char x, y; char l, r; char sel, start; char vba, vbb; } mySNES; typedef struct myJAG { char dn; char up; char lf; char rt; char a, b, c, d; char pause; char opt; char kp[12]; } myJAG; typedef struct { char dn; char up; char lf; char rt; char start, select, box, cross, circle, triangle; char r1, l1, r2, l2, r3, l3; char lx, ly, rx, ry; } myPSX; typedef struct myTGFX { char dn; char up; char lf; char rt; char f1, f2, f3, f4, f5; } myTGFX; typedef struct mySATURN { char dn; char up; char lf; char rt; char a, b, c; char x, y, z; char start; char r,l; char a1, a2, a3; char ax, ay, az; } mySATURN; typedef struct myGENESIS { char dn; char up; char lf; char rt; char a, b, c; char start; char x, y, z, md; } myGENESIS; typedef struct myATARI { char up; char dn; char lf; char rt; char btn; char btn2; } myATARI; typedef struct { char dn; char up; char lf; char rt; char a, b, z, start, l, r; char cdn; char cup; char clf; char crt; char x, y; } myN64; void ScanN64(myN64 *n64, int base, int id, int snes_din, int negate) { int i; DWORD data; static myN64 last[6]; unsigned char on, off; unsigned short shtb; static unsigned char idon[5] = {0x00, 0xfe /*D0*/, 0xfb /*D2*/, 0xf7 /*D3*/, 0xef /*D4*/}; shtb = (unsigned short)base; off = 0xff; on = idon[id]; _disable(); //sti //mov dx, [shtb] //mov bl, [on] //mov al,0ffh _outp( shtb, 0xff ); //out dx,al //mov al,bl for (i=0; i<7; i++) { _outp( shtb, on ); //out dx,al _outp( shtb, on ); //out dx,al _outp( shtb, on ); //out dx,al _outp( shtb, on ); //out dx,al _outp( shtb, on ); //out dx,al _outp( shtb, on ); //out dx,al _outp( shtb, on ); //out dx,al //mov al,0ffh _outp( shtb, off ); //out dx,al _outp( shtb, off ); //out dx,al ; ready bit 0 // Super-dooper extended timing // _outp( shtb, off ); //out dx,al // _outp( shtb, off ); //out dx,al } for (i=7; i<9; i++) { _outp( shtb, on ); //out dx,al _outp( shtb, on ); //out dx,al //mov al,0ffh // Super-dooper extended timing // _outp( shtb, on ); //out dx,al // _outp( shtb, on ); //out dx,al _outp( shtb, off ); //out dx,al _outp( shtb, off ); //out dx,al _outp( shtb, off ); //out dx,al _outp( shtb, off ); //out dx,al _outp( shtb, off ); //out dx,al _outp( shtb, off ); //out dx,al _outp( shtb, off ); //out dx,al ; ready bit 7 //mov al,bl } _enable(); //cli for (i=0; i<0x90; i++) _outp( base, 0xff ); data = 0; for (i=0; i<32; i++) { data <<= 1; _outp( base, 0xfd ); _outp( base, 0xfd ); _outp( base, 0xfd ); data |= (SIN)?0:1; _outp( base, 0xff ); _outp( base, 0xff ); _outp( base, 0xff ); } if (((data>>23)&1)||((data>>22)&1)) // failed comm *n64 = last[id]; else { n64->a = (char)((data>>31) & 1); n64->b = (char)((data>>30) & 1); n64->z = (char)((data>>29) & 1); n64->start = (char)((data>>28) & 1); n64->up = (char)((data>>27) & 1); n64->dn = (char)((data>>26) & 1); n64->lf = (char)((data>>25) & 1); n64->rt = (char)((data>>24) & 1); n64->l = (char)((data>>21) & 1); n64->r = (char)((data>>20) & 1); n64->cup = (char)((data>>19) & 1); n64->cdn = (char)((data>>18) & 1); n64->clf = (char)((data>>17) & 1); n64->crt = (char)((data>>16) & 1); n64->x = (char)((data>>8) & 0xff); n64->y = (char)(data & 0xff); n64->y = - n64->y; last[id] = *n64; } } void ScanTGFX( myTGFX *tgfx, int num, int base ) { int k, l; OUTP( base+2, 0x04 ); // 4 extra inputs OUTP( base, 0xff ); // all out high OUTP( base, 0xff-( 1 << (7-num) ) ); k = _inp( base+1 ); l = _inp( base+2 ); tgfx->up = (k&16)?0:1; tgfx->dn = (k&32)?0:1; tgfx->lf = (k&64)?0:1; tgfx->rt = (k&128)?1:0; tgfx->f1 = (k&8)?0:1; tgfx->f2 = (l&2)?1:0; tgfx->f3 = (l&4)?0:1; tgfx->f4 = (l&1)?1:0; tgfx->f5 = (l&8)?1:0; } void ScanSaturn(mySATURN *saturn, int analog, int id, int base) { const unsigned char tl1 = 4; const unsigned char tr1 = 2; // pad 1 const unsigned char th1 = 1; // pad 1 const unsigned char gnd1 = 64;// pad 1 const unsigned char tl2 = 4; const unsigned char tr2 = 32; // pad 2 const unsigned char th2 = 16; // pad 2 const unsigned char gnd2 =128;// pad 2 const unsigned char r = 16; const unsigned char l = 32; const unsigned char d = 64; const unsigned char u = 128; // inverted! int s0, s1, s2, s3; int sel2, sel1, sel0, gnd; int ad[10]; unsigned char pwr; if (id==1) { sel2 = th1; sel1 = tr1; sel0 = tl1; gnd = gnd1; } else { sel2 = th2; sel1 = tr2; sel0 = tl2; gnd = gnd2; } pwr = 255 - (gnd + sel2 + sel1 + sel0); if (!analog) { OUTP( base, pwr+sel2+sel1+sel0 ); s0=_inp(base+1); OUTP( base, pwr +sel1+sel0 ); s1=_inp(base+1); OUTP( base, pwr+sel2 +sel0 ); s2=_inp(base+1); OUTP( base, pwr +sel0 ); s3=_inp(base+1); saturn->l = NEG(s0, r); saturn->rt = NEG(s1, r); saturn->lf = NEG(s1, l); saturn->dn = NEG(s1, d); saturn->up = POS(s1, u); saturn->start = NEG(s2, r); saturn->a = NEG(s2, l); saturn->c = NEG(s2, d); saturn->b = POS(s2, u); saturn->r = NEG(s3, r); saturn->x = NEG(s3, l); saturn->y = NEG(s3, d); saturn->z = POS(s3, u); } else { OUTPS( base, pwr+sel2+sel1+sel0 ); // 1st data OUTPS( base, pwr +sel1+sel0 ); // 2nd data OUTPS( base, pwr +sel0 ); OUTPS( base, pwr ); // 3rd OUTPS( base, pwr +sel1 ); OUTPS( base, pwr +sel1+sel0 ); // 4th OUTPS( base, pwr +sel0 ); OUTPS( base, pwr ); // 5th ad[0] = _inp(base+1); OUTPS( base, pwr +sel1 ); OUTPS( base, pwr +sel1+sel0 ); // 6th ad[1] = _inp(base+1); OUTPS( base, pwr +sel0 ); OUTPS( base, pwr ); // 7th ad[2] = _inp(base+1); OUTPS( base, pwr +sel1 ); OUTPS( base, pwr +sel1+sel0 ); // 8th ad[3] = _inp(base+1); OUTPS( base, pwr +sel0 ); OUTPS( base, pwr ); // 9th ad[4] = _inp(base+1); OUTPS( base, pwr +sel1 ); OUTPS( base, pwr +sel1+sel0 ); // 10th ad[5] = _inp(base+1); OUTPS( base, pwr +sel0 ); OUTPS( base, pwr ); // 11th ad[6] = _inp(base+1); OUTPS( base, pwr +sel1 ); OUTPS( base, pwr +sel1+sel0 ); // 12th ad[7] = _inp(base+1); OUTPS( base, pwr +sel0 ); OUTPS( base, pwr ); // 13th ad[8] = _inp(base+1); OUTPS( base, pwr +sel1 ); OUTPS( base, pwr +sel1+sel0 ); // 14th ad[9] = _inp(base+1); OUTPS( base, pwr +sel0 ); OUTPS( base, pwr ); // 15th OUTPS( base, pwr +sel1 ); OUTPS( base, pwr +sel1+sel0 ); // 16th OUTPS( base, pwr+sel2+sel1+sel0 ); saturn->rt = NEG(ad[0],r); saturn->lf = NEG(ad[0],l); saturn->dn = NEG(ad[0],d); saturn->up = POS(ad[0],u); saturn->start = NEG(ad[1],r); saturn->a = NEG(ad[1],l); saturn->c = NEG(ad[1],d); saturn->b = POS(ad[1],u); saturn->r = NEG(ad[2],r); saturn->x = NEG(ad[2],l); saturn->y = NEG(ad[2],d); saturn->z = POS(ad[2],u); saturn->l = NEG(ad[3],r); saturn->a1 = NEG(ad[3],l); saturn->a2 = NEG(ad[3],d); saturn->a3 = POS(ad[3],u); saturn->ax = POS(ad[4],r)*128 + POS(ad[4],l)*64 + POS(ad[4],d)*32 + NEG(ad[4],u)*16 + POS(ad[5],r)*8 + POS(ad[5],l)*4 + POS(ad[5],d)*2 + NEG(ad[5],u)*1; saturn->ay = POS(ad[6],r)*128 + POS(ad[6],l)*64 + POS(ad[6],d)*32 + NEG(ad[6],u)*16 + POS(ad[7],r)*8 + POS(ad[7],l)*4 + POS(ad[7],d)*2 + NEG(ad[7],u)*1; saturn->az = POS(ad[8],r)*128 + POS(ad[8],l)*64 + POS(ad[8],d)*32 + NEG(ad[8],u)*16 + POS(ad[9],r)*8 + POS(ad[9],l)*4 + POS(ad[9],d)*2 + NEG(ad[9],u)*1; } if (!joy[curJoy].power) OUTP(base,0); //power down gamepad } void ScanGenesis( myGENESIS *genesis, int base ) { int s0, s1, s2, c, c2; OUTP(base+2, 0x0c); OUTP(base, 254); // Power up, select=0 s0 = _inp(base+1); OUTP(base, 255); // Power up, select=1 s1 = _inp(base+1); c = _inp(base+2); if (joy[curJoy].name==GENESIS6) { _outp(base, 254); // sel=0; _outp(base, 254); // sel=0; _outp(base, 255); // sel=1; _outp(base, 255); // sel=1; _outp(base, 254); // sel=0; _outp(base, 254); // sel=0; _outp(base, 255); // sel=1; _outp(base, 255); // sel=1; s2=_inp(base+1); c2...
ludzka_swinia