12 static char ring[RINGSZ];
13 static int prod = 0, cons = 0;
20 /* Try to read some. */
21 while ((r = read(0, &(ring[prod]), RINGSZ-prod)) == 0)
23 prod = (prod + r) % RINGSZ;
26 cons = (cons + 1) % RINGSZ;
38 if (s[i] == '\r' || s[i] == '\n')
50 char *vname, *var, *sub;
54 int *findvar(char *var, char *sub, struct vars *vars, int n)
57 for (i=0; i<96*96; i++)
58 if (vars[i].var && !strcmp(vars[i].var, var) && ((!sub && !vars[i].sub) || !strcmp(vars[i].sub, sub)))
60 printf("Unknown var: %s %s\n", var, sub);
70 i += *(s++) - '!' + 1;
78 struct vars vars[96*96];
83 if (SDL_Init(SDL_INIT_VIDEO) < 0)
85 printf("SDL init failed: %s\n", SDL_GetError());
89 screen = SDL_SetVideoMode(WIN_X, WIN_Y, 24, SDL_SWSURFACE);
92 printf("Video init failed: %s\n", SDL_GetError());
95 memset(vars, 0, sizeof(vars));
97 while ((s = readline()))
101 if (!strcmp(s, "$dumpvars"))
104 printf("Var dump begin on %d vars\n", nvars);
105 } else if (!strncmp(s, "$var", 4)) {
107 char *vname, *var, *sub;\
109 t = strtok(NULL, " ");
110 t = strtok(NULL, " ");
111 t = strtok(NULL, " ");
113 t = strtok(NULL, " ");
115 t = strtok(NULL, " ");
116 if (strcmp(t, "$end"))
120 printf("Found: %s (%d) -> %s %s\n", vname, numname(vname), var, sub);
122 vars[numname(vname)].vname = strdup(vname);
123 vars[numname(vname)].var = strdup(var);
124 vars[numname(vname)].sub = sub ? strdup(sub) : NULL;
125 vars[numname(vname)].val = 0;
127 } else if (s[0] == '#' || !s[0])
129 else if (readingdata)
131 int val = (s[0] == '1');
134 int oldclk = tclk ? *tclk : 0;
137 if (!tclk) tclk = findvar("vgaclk", NULL, vars, nvars);
139 vars[numname(s+1)].val = val;
141 if (*tclk != oldclk && ((pixn++) % 2)) {
142 static int x = 0, y = 0;
145 static int *r2 = NULL, *r1 = NULL, *r0 = NULL, *g2 = NULL, *g1 = NULL, *g0 = NULL, *b1 = NULL, *b0 = NULL, *vs = NULL, *hs = NULL;
146 if (!r2) r2 = findvar("r", "[2]", vars, nvars);
147 if (!r1) r1 = findvar("r", "[1]", vars, nvars);
148 if (!r0) r0 = findvar("r", "[0]", vars, nvars);
149 if (!g2) g2 = findvar("g", "[2]", vars, nvars);
150 if (!g1) g1 = findvar("g", "[1]", vars, nvars);
151 if (!g0) g0 = findvar("g", "[0]", vars, nvars);
152 if (!b1) b1 = findvar("b", "[1]", vars, nvars);
153 if (!b0) b0 = findvar("b", "[0]", vars, nvars);
154 if (!vs) vs = findvar("vs", NULL, vars, nvars);
155 if (!hs) hs = findvar("hs", NULL, vars, nvars);
158 int r = *r2 << 7 | *r1 << 6 | *r0 << 5;
159 int g = *g2 << 7 | *g1 << 6 | *g0 << 5;
160 int b = *b1 << 7 | *b0 << 6;
172 SDL_LockSurface(screen);
173 pixp = screen->pixels + ((WIN_X * y + x) * 3);
174 pixp[0] = b; pixp[1] = g; pixp[2] = r;
175 SDL_UnlockSurface(screen);
176 if (x == 0 && !lasths && y != 0)
179 SDL_LockSurface(screen);
180 for (i = 1; i < WIN_X; i++)
181 pixp[0+i*3] = pixp[1+i*3] = pixp[2+i*3] = 0xFF;
182 SDL_UnlockSurface(screen);
183 SDL_UpdateRect(screen, 0, y-1, WIN_X, 2);