diff options
author | ftrvxmtrx <devnull@localhost> | 2014-06-01 01:21:00 +0200 |
---|---|---|
committer | ftrvxmtrx <devnull@localhost> | 2014-06-01 01:21:00 +0200 |
commit | 8061f30e559569943324a666ee2fcc74048785cd (patch) | |
tree | 8583c17a08eddf4f51f15d3e3e2f476740adfd62 /sys/src/games/nes/nes.c | |
parent | bf0d5c8abbe9d4e3a145df29bee8ef2758d01884 (diff) |
games/nes: support Battle City two players mode with joypads
Diffstat (limited to 'sys/src/games/nes/nes.c')
-rw-r--r-- | sys/src/games/nes/nes.c | 48 |
1 files changed, 47 insertions, 1 deletions
diff --git a/sys/src/games/nes/nes.c b/sys/src/games/nes/nes.c index 5cc6c1c3b..78c25adb3 100644 --- a/sys/src/games/nes/nes.c +++ b/sys/src/games/nes/nes.c @@ -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; @@ -125,6 +125,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 *) { int fd, k; @@ -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); |