summaryrefslogtreecommitdiff
path: root/sys/src/games
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@felloff.net>2016-04-03 22:54:22 +0200
committercinap_lenrek <cinap_lenrek@felloff.net>2016-04-03 22:54:22 +0200
commitce84082205f8367c1a4676c4810d92b30ae87f49 (patch)
tree1f33dee7fb1674e0c18dcafb5cb56b7ee92aa395 /sys/src/games
parentcd9cddf3dd64b01e7e54ba3a3371a8d0a5c70748 (diff)
change /dev/kbd to return multiple messages per read
Diffstat (limited to 'sys/src/games')
-rw-r--r--sys/src/games/c64/c64.c15
-rw-r--r--sys/src/games/doom/i_video.c15
-rw-r--r--sys/src/games/gb/gb.c15
-rw-r--r--sys/src/games/gba/gba.c15
-rw-r--r--sys/src/games/md/md.c15
-rw-r--r--sys/src/games/nes/nes.c15
-rw-r--r--sys/src/games/snes/snes.c15
7 files changed, 85 insertions, 20 deletions
diff --git a/sys/src/games/c64/c64.c b/sys/src/games/c64/c64.c
index 1bb7cad4a..054851813 100644
--- a/sys/src/games/c64/c64.c
+++ b/sys/src/games/c64/c64.c
@@ -131,7 +131,7 @@ loadtape(char *name)
static void
keyproc(void *)
{
- int fd, i, setnmi;
+ int fd, i, n, setnmi;
u16int j;
u64int k;
static Rune keymap[64] = {
@@ -152,8 +152,17 @@ keyproc(void *)
if(fd < 0)
sysfatal("open: %r");
for(;;){
- if(read(fd, buf, sizeof(buf) - 1) <= 0)
- sysfatal("read /dev/kbd: %r");
+ if(buf[0] != 0){
+ n = strlen(buf)+1;
+ memmove(buf, buf+n, sizeof(buf)-n);
+ }
+ if(buf[0] == 0){
+ n = read(fd, buf, sizeof(buf)-1);
+ if(n <= 0)
+ sysfatal("read /dev/kbd: %r");
+ buf[n-1] = 0;
+ buf[n] = 0;
+ }
if(buf[0] == 'c'){
if(utfrune(buf, Kend)){
close(fd);
diff --git a/sys/src/games/doom/i_video.c b/sys/src/games/doom/i_video.c
index 5ce432edf..941d7e676 100644
--- a/sys/src/games/doom/i_video.c
+++ b/sys/src/games/doom/i_video.c
@@ -257,8 +257,19 @@ kbdproc(void)
buf2[0] = 0;
buf2[1] = 0;
- while((n = read(kfd, buf, sizeof(buf))) > 0){
- buf[n-1] = 0;
+ buf[0] = 0;
+ for(;;){
+ if(buf[0] != 0){
+ n = strlen(buf)+1;
+ memmove(buf, buf+n, sizeof(buf)-n);
+ }
+ if(buf[0] == 0){
+ n = read(kfd, buf, sizeof(buf)-1);
+ if(n <= 0)
+ break;
+ buf[n-1] = 0;
+ buf[n] = 0;
+ }
e.data1 = -1;
e.data2 = -1;
diff --git a/sys/src/games/gb/gb.c b/sys/src/games/gb/gb.c
index e8bcdb459..79930ec63 100644
--- a/sys/src/games/gb/gb.c
+++ b/sys/src/games/gb/gb.c
@@ -218,7 +218,7 @@ screeninit(void)
void
keyproc(void *)
{
- int fd, k;
+ int fd, n, k;
static char buf[256];
char *s;
Rune r;
@@ -228,8 +228,17 @@ keyproc(void *)
if(fd < 0)
sysfatal("open: %r");
for(;;){
- if(read(fd, buf, sizeof(buf) - 1) <= 0)
- sysfatal("read /dev/kbd: %r");
+ if(buf[0] != 0){
+ n = strlen(buf)+1;
+ memmove(buf, buf+n, sizeof(buf)-n);
+ }
+ if(buf[0] == 0){
+ n = read(fd, buf, sizeof(buf)-1);
+ if(n <= 0)
+ sysfatal("read /dev/kbd: %r");
+ buf[n-1] = 0;
+ buf[n] = 0;
+ }
if(buf[0] == 'c'){
if(utfrune(buf, KF|5))
savereq = 1;
diff --git a/sys/src/games/gba/gba.c b/sys/src/games/gba/gba.c
index cebd1a830..50300af0b 100644
--- a/sys/src/games/gba/gba.c
+++ b/sys/src/games/gba/gba.c
@@ -226,7 +226,7 @@ screeninit(void)
void
keyproc(void *)
{
- int fd, k;
+ int fd, n, k;
static char buf[256];
char *s;
Rune r;
@@ -235,8 +235,17 @@ keyproc(void *)
if(fd < 0)
sysfatal("open: %r");
for(;;){
- if(read(fd, buf, sizeof(buf) - 1) <= 0)
- sysfatal("read /dev/kbd: %r");
+ if(buf[0] != 0){
+ n = strlen(buf)+1;
+ memmove(buf, buf+n, sizeof(buf)-n);
+ }
+ if(buf[0] == 0){
+ n = read(fd, buf, sizeof(buf)-1);
+ if(n <= 0)
+ sysfatal("read /dev/kbd: %r");
+ buf[n-1] = 0;
+ buf[n] = 0;
+ }
if(buf[0] == 'c'){
if(utfrune(buf, KF|5))
savereq = 1;
diff --git a/sys/src/games/md/md.c b/sys/src/games/md/md.c
index 27e292274..f8ffcc52c 100644
--- a/sys/src/games/md/md.c
+++ b/sys/src/games/md/md.c
@@ -180,7 +180,7 @@ screenproc(void *)
void
keyproc(void *)
{
- int fd, k;
+ int fd, n, k;
static char buf[256];
char *s;
Rune r;
@@ -189,8 +189,17 @@ keyproc(void *)
if(fd < 0)
sysfatal("open: %r");
for(;;){
- if(read(fd, buf, sizeof(buf) - 1) <= 0)
- sysfatal("read /dev/kbd: %r");
+ if(buf[0] != 0){
+ n = strlen(buf)+1;
+ memmove(buf, buf+n, sizeof(buf)-n);
+ }
+ if(buf[0] == 0){
+ n = read(fd, buf, sizeof(buf)-1);
+ if(n <= 0)
+ sysfatal("read /dev/kbd: %r");
+ buf[n-1] = 0;
+ buf[n] = 0;
+ }
if(buf[0] == 'c'){
if(utfrune(buf, Kdel)){
close(fd);
diff --git a/sys/src/games/nes/nes.c b/sys/src/games/nes/nes.c
index 78c25adb3..aa9c4fa2a 100644
--- a/sys/src/games/nes/nes.c
+++ b/sys/src/games/nes/nes.c
@@ -172,7 +172,7 @@ joyproc(void *)
void
keyproc(void *)
{
- int fd, k;
+ int fd, n, k;
static char buf[256];
char *s;
Rune r;
@@ -181,8 +181,17 @@ keyproc(void *)
if(fd < 0)
sysfatal("open: %r");
for(;;){
- if(read(fd, buf, sizeof(buf) - 1) <= 0)
- sysfatal("read /dev/kbd: %r");
+ if(buf[0] != 0){
+ n = strlen(buf)+1;
+ memmove(buf, buf+n, sizeof(buf)-n);
+ }
+ if(buf[0] == 0){
+ n = read(fd, buf, sizeof(buf)-1);
+ if(n <= 0)
+ sysfatal("read /dev/kbd: %r");
+ buf[n-1] = 0;
+ buf[n] = 0;
+ }
if(buf[0] == 'c'){
if(utfrune(buf, Kdel)){
close(fd);
diff --git a/sys/src/games/snes/snes.c b/sys/src/games/snes/snes.c
index a2b9266e9..863247fef 100644
--- a/sys/src/games/snes/snes.c
+++ b/sys/src/games/snes/snes.c
@@ -116,7 +116,7 @@ loadbat(char *file)
void
keyproc(void *)
{
- int fd, k;
+ int fd, n, k;
static char buf[256];
char *s;
Rune r;
@@ -125,8 +125,17 @@ keyproc(void *)
if(fd < 0)
sysfatal("open: %r");
for(;;){
- if(read(fd, buf, sizeof(buf) - 1) <= 0)
- sysfatal("read /dev/kbd: %r");
+ if(buf[0] != 0){
+ n = strlen(buf)+1;
+ memmove(buf, buf+n, sizeof(buf)-n);
+ }
+ if(buf[0] == 0){
+ n = read(fd, buf, sizeof(buf)-1);
+ if(n <= 0)
+ sysfatal("read /dev/kbd: %r");
+ buf[n-1] = 0;
+ buf[n] = 0;
+ }
if(buf[0] == 'c'){
if(utfrune(buf, KF|5))
savereq = 1;