]> Joshua Wise's Git repositories - mandelfpga.git/blobdiff - readout.c
Holy crap, dropped lut count to 7640, and slice count to 4253
[mandelfpga.git] / readout.c
index 9b92953f82eaad3bf1d9fbbe8fef5be5ae1a4665..4ecae1484b46df91c1a343f922f6d61e096b2132 100644 (file)
--- a/readout.c
+++ b/readout.c
@@ -1,13 +1,46 @@
 #include <string.h>
 #include <SDL/SDL.h>
 
-#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++;
                                }
This page took 0.023335 seconds and 4 git commands to generate.