X-Git-Url: http://git.joshuawise.com/mandelfpga.git/blobdiff_plain/5930552f09758b3ad5ea890e492fa76bb579b992..fd517766c57248a93d5dc2679fa8cdf6c211ee81:/readout.c?ds=sidebyside diff --git a/readout.c b/readout.c index 9b92953..4ecae14 100644 --- a/readout.c +++ b/readout.c @@ -1,13 +1,46 @@ #include #include -#define WIN_X 1500 -#define WIN_Y 768 +#define WIN_X 800 +#define WIN_Y 600 + +char getone() +{ + unsigned char c; + static char ring[2048]; + static int prod = 0, cons = 0; + int oldcons; + + if (prod == cons) + { + int r; + /* Try to read some. */ + while ((r = read(0, &(ring[prod]), 2048-prod)) == 0) + usleep(250000); + prod = (prod + r) % 2048; + } + oldcons = cons; + cons = (cons + 1) % 2048; + return ring[oldcons]; +} char *readline() { static char s[2048]; - return gets(s); /* Insecure, oh well, who cares, this will get replaced later */ + int i = 0; + + while (i < 2048) + { + s[i] = getone(); + if (s[i] == '\r' || s[i] == '\n') + { + s[i] = '\0'; + return s; + } + i++; + } + s[2047] = 0; + return s; } struct vars { @@ -22,6 +55,7 @@ int *findvar(char *var, char *sub, struct vars *vars, int n) if (!strcmp(vars[i].var, var) && ((!sub && !vars[i].sub) || !strcmp(vars[i].sub, sub))) return &vars[i].val; printf("Unknown var: %s %s\n", var, sub); + abort(); } void main() @@ -75,9 +109,9 @@ void main() vars[nvars].val = 0; nvars++; } - } else if (s[0] == '#') + } else if (s[0] == '#' || !s[0]) ; - else + else if (readingdata) { int val = (s[0] == '1'); int i; @@ -121,7 +155,10 @@ void main() { x = 0; if (!lasths) + { y++; + SDL_Flip(screen); + } } else x++; }