games/nes: support Battle City two players mode with joypads
This commit is contained in:
parent
bf0d5c8abb
commit
8061f30e55
5 changed files with 93 additions and 6 deletions
|
@ -4,7 +4,7 @@ extern u8int irq, nmi;
|
|||
extern uchar mem[32768], ppuram[16384], oam[256];
|
||||
extern u16int pput, ppuv;
|
||||
extern u8int ppusx, vrambuf;
|
||||
extern int mirr, ppux, ppuy, odd, vramlatch, keylatch;
|
||||
extern int mirr, ppux, ppuy, odd, vramlatch, keylatch, keylatch2;
|
||||
|
||||
extern int map, scale, mmc3hack, oflag;
|
||||
extern uchar *prg, *chr;
|
||||
|
@ -13,7 +13,7 @@ extern int nprg, nchr, map, chrram;
|
|||
extern u8int apuseq, apuctr[13];
|
||||
extern u16int dmcaddr, dmccnt;
|
||||
|
||||
extern int keys, clock, ppuclock, apuclock, dmcclock, dmcfreq, saveclock, paused;
|
||||
extern int keys, keys2, clock, ppuclock, apuclock, dmcclock, dmcfreq, saveclock, paused;
|
||||
|
||||
extern void (*mapper[])(int, u8int);
|
||||
|
||||
|
|
33
sys/src/games/nes/joynes
Executable file
33
sys/src/games/nes/joynes
Executable file
|
@ -0,0 +1,33 @@
|
|||
#!/bin/rc
|
||||
# run as "nusb/joy epX.Y | joynes N", where N=[1,2]
|
||||
|
||||
awk -safe -v 'joy='$1 '
|
||||
BEGIN { k[0] = "" }
|
||||
|
||||
/^axis 0 0/ { k[0] = "left " }
|
||||
/^axis 0 255/ { k[0] = "right " }
|
||||
/^axis 0 128/ { k[0] = "" }
|
||||
|
||||
/^axis 1 0/ { k[1] = "up " }
|
||||
/^axis 1 255/ { k[1] = "down " }
|
||||
/^axis 1 128/ { k[1] = "" }
|
||||
|
||||
/^down 7$/ { k[3] = "b " }
|
||||
/^down 8$/ { k[2] = "a " }
|
||||
/^down 1$/ { k[4] = "control " }
|
||||
/^down 2$/ { k[5] = "start " }
|
||||
|
||||
/^up 7$/ { k[3] = "" }
|
||||
/^up 8$/ { k[2] = "" }
|
||||
/^up 1$/ { k[4] = "" }
|
||||
/^up 2$/ { k[5] = "" }
|
||||
|
||||
{
|
||||
if(joy != "")
|
||||
printf "joy%s ", joy
|
||||
for(i = 0; i <= 5; i++)
|
||||
printf k[i]
|
||||
printf "\n"
|
||||
fflush
|
||||
}
|
||||
'
|
|
@ -11,7 +11,7 @@ uchar oam[256];
|
|||
uchar *prgb[16], *chrb[16];
|
||||
u16int pput, ppuv;
|
||||
u8int ppusx, vrambuf;
|
||||
int vramlatch = 1, keylatch = 0xFF;
|
||||
int vramlatch = 1, keylatch = 0xFF, keylatch2 = 0xFF;
|
||||
int prgsh, chrsh, mmc3hack;
|
||||
|
||||
static void
|
||||
|
@ -395,7 +395,11 @@ memread(u16int p)
|
|||
keylatch = (keylatch >> 1) | 0x80;
|
||||
return v | 0x40;
|
||||
case 0x4017:
|
||||
return 0x40;
|
||||
if((mem[p] & 1) != 0)
|
||||
return keys2 & 1;
|
||||
v = keylatch2 & 1;
|
||||
keylatch2 = (keylatch2 >> 1) | 0x80;
|
||||
return v | 0x40;
|
||||
}
|
||||
}
|
||||
if(p >= 0x8000){
|
||||
|
@ -489,8 +493,10 @@ memwrite(u16int p, u8int v)
|
|||
irq &= ~IRQDMC;
|
||||
break;
|
||||
case 0x4016:
|
||||
if((mem[p] & 1) != 0 && (v & 1) == 0)
|
||||
if((mem[p] & 1) != 0 && (v & 1) == 0){
|
||||
keylatch = keys;
|
||||
keylatch2 = keys2;
|
||||
}
|
||||
break;
|
||||
case APUFRAME:
|
||||
apuseq = 0;
|
||||
|
|
|
@ -15,7 +15,7 @@ Rectangle picr;
|
|||
Image *tmp, *bg;
|
||||
int clock, ppuclock, apuclock, dmcclock, dmcfreq, sampclock, msgclock, saveclock;
|
||||
Mousectl *mc;
|
||||
int keys, paused, savereq, loadreq, oflag, savefd = -1;
|
||||
int keys, keys2, paused, savereq, loadreq, oflag, savefd = -1;
|
||||
int mirr;
|
||||
QLock pauselock;
|
||||
|
||||
|
@ -124,6 +124,51 @@ loadrom(char *file, int sflag)
|
|||
|
||||
extern int trace;
|
||||
|
||||
void
|
||||
joyproc(void *)
|
||||
{
|
||||
char *s, *down[9];
|
||||
static char buf[64];
|
||||
int n, k, j;
|
||||
|
||||
j = 1;
|
||||
for(;;){
|
||||
n = read(0, buf, sizeof(buf) - 1);
|
||||
if(n <= 0)
|
||||
sysfatal("read: %r");
|
||||
buf[n] = 0;
|
||||
n = getfields(buf, down, nelem(down), 1, " ");
|
||||
k = 0;
|
||||
for(n--; n >= 0; n--){
|
||||
s = down[n];
|
||||
if(strcmp(s, "joy1") == 0)
|
||||
j = 1;
|
||||
else if(strcmp(s, "joy2") == 0)
|
||||
j = 2;
|
||||
else if(strcmp(s, "a") == 0)
|
||||
k |= 1<<0;
|
||||
else if(strcmp(s, "b") == 0)
|
||||
k |= 1<<1;
|
||||
else if(strcmp(s, "control") == 0)
|
||||
k |= 1<<2;
|
||||
else if(strcmp(s, "start") == 0)
|
||||
k |= 1<<3;
|
||||
else if(strcmp(s, "up") == 0)
|
||||
k |= 1<<4;
|
||||
else if(strcmp(s, "down") == 0)
|
||||
k |= 1<<5;
|
||||
else if(strcmp(s, "left") == 0)
|
||||
k |= 1<<6;
|
||||
else if(strcmp(s, "right") == 0)
|
||||
k |= 1<<7;
|
||||
}
|
||||
if(j == 2)
|
||||
keys2 = k;
|
||||
else
|
||||
keys = k;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
keyproc(void *)
|
||||
{
|
||||
|
@ -220,6 +265,7 @@ threadmain(int argc, char **argv)
|
|||
mc = initmouse(nil, screen);
|
||||
if(mc == nil)
|
||||
sysfatal("initmouse: %r");
|
||||
proccreate(joyproc, nil, 8192);
|
||||
proccreate(keyproc, nil, 8192);
|
||||
originwindow(screen, Pt(0, 0), screen->r.min);
|
||||
p = divpt(addpt(screen->r.min, screen->r.max), 2);
|
||||
|
|
|
@ -89,6 +89,7 @@ loadstate(char *file)
|
|||
odd = get8();
|
||||
vramlatch = get8();
|
||||
keylatch = get8();
|
||||
keylatch2 = get8();
|
||||
vrambuf = get8();
|
||||
clock = get32();
|
||||
ppuclock = get32();
|
||||
|
@ -130,6 +131,7 @@ savestate(char *file)
|
|||
put8(odd);
|
||||
put8(vramlatch);
|
||||
put8(keylatch);
|
||||
put8(keylatch2);
|
||||
put8(vrambuf);
|
||||
put32(clock);
|
||||
put32(ppuclock);
|
||||
|
|
Loading…
Reference in a new issue