10 static char ring[2048];
11 static int prod = 0, cons = 0;
17 /* Try to read some. */
18 while ((r = read(0, &(ring[prod]), 2048-prod)) == 0)
20 prod = (prod + r) % 2048;
23 cons = (cons + 1) % 2048;
35 if (s[i] == '\r' || s[i] == '\n')
47 char *vname, *var, *sub;
51 int *findvar(char *var, char *sub, struct vars *vars, int n)
55 if (!strcmp(vars[i].var, var) && ((!sub && !vars[i].sub) || !strcmp(vars[i].sub, sub)))
57 printf("Unknown var: %s %s\n", var, sub);
64 struct vars vars[512];
69 if (SDL_Init(SDL_INIT_VIDEO) < 0)
71 printf("SDL init failed: %s\n", SDL_GetError());
75 screen = SDL_SetVideoMode(WIN_X, WIN_Y, 24, SDL_SWSURFACE);
78 printf("Video init failed: %s\n", SDL_GetError());
81 while ((s = readline()))
85 if (!strcmp(s, "$dumpvars"))
88 printf("Var dump begin on %d vars\n", nvars);
89 } else if (!strncmp(s, "$var", 4)) {
91 char *vname, *var, *sub;\
93 t = strtok(NULL, " ");
94 t = strtok(NULL, " ");
95 t = strtok(NULL, " ");
97 t = strtok(NULL, " ");
99 t = strtok(NULL, " ");
100 if (strcmp(t, "$end"))
104 printf("Found: %s -> %s %s\n", vname, var, sub);
106 vars[nvars].vname = strdup(vname);
107 vars[nvars].var = strdup(var);
108 vars[nvars].sub = sub ? strdup(sub) : NULL;
112 } else if (s[0] == '#' || !s[0])
114 else if (readingdata)
116 int val = (s[0] == '1');
118 int oldclk = *findvar("gclk", NULL, vars, nvars);
120 for (i=0; i<nvars; i++)
122 if (!strcmp(vars[i].vname, s+1))
129 printf("Unknown: %s\n", s);
130 if (*findvar("gclk", NULL, vars, nvars) != oldclk && oldclk == 1 && ((pixn++) % 2))
132 static int x = 0, y = 0;
135 static int *r2 = NULL, *r1 = NULL, *r0 = NULL, *g2 = NULL, *g1 = NULL, *g0 = NULL, *b1 = NULL, *b0 = NULL, *vs = NULL, *hs = NULL;
136 r2 = r2 ? r2 : findvar("red", "[2]", vars, nvars);
137 r1 = r1 ? r1 : findvar("red", "[1]", vars, nvars);
138 r0 = r0 ? r0 : findvar("red", "[0]", vars, nvars);
139 g2 = g2 ? g2 : findvar("green", "[2]", vars, nvars);
140 g1 = g1 ? g1 : findvar("green", "[1]", vars, nvars);
141 g0 = g0 ? g0 : findvar("green", "[0]", vars, nvars);
142 b1 = b1 ? b1 : findvar("blue", "[1]", vars, nvars);
143 b0 = b0 ? b0 : findvar("blue", "[0]", vars, nvars);
144 vs = vs ? vs : findvar("vs", NULL, vars, nvars);
145 hs = hs ? hs : findvar("hs", NULL, vars, nvars);
148 int r = *r2 << 7 | *r1 << 6 | *r0 << 5;
149 int g = *g2 << 7 | *g1 << 6 | *g0 << 5;
150 int b = *b1 << 7 | *b0 << 6;
166 SDL_LockSurface(screen);
167 pixp = screen->pixels + ((WIN_X * y + x) * 3);
168 pixp[0] = b; pixp[1] = g; pixp[2] = r;
169 SDL_UnlockSurface(screen);
171 SDL_UpdateRect(screen, x/5*5, y, 5, 1);