]>
Commit | Line | Data |
---|---|---|
5930552f JW |
1 | #include <string.h> |
2 | #include <SDL/SDL.h> | |
3 | ||
4 | #define WIN_X 1500 | |
5 | #define WIN_Y 768 | |
6 | ||
7 | char *readline() | |
8 | { | |
9 | static char s[2048]; | |
10 | return gets(s); /* Insecure, oh well, who cares, this will get replaced later */ | |
11 | } | |
12 | ||
13 | struct vars { | |
14 | char *vname, *var, *sub; | |
15 | int val; | |
16 | }; | |
17 | ||
18 | int *findvar(char *var, char *sub, struct vars *vars, int n) | |
19 | { | |
20 | int i; | |
21 | for (i=0; i<n; i++) | |
22 | if (!strcmp(vars[i].var, var) && ((!sub && !vars[i].sub) || !strcmp(vars[i].sub, sub))) | |
23 | return &vars[i].val; | |
24 | printf("Unknown var: %s %s\n", var, sub); | |
25 | } | |
26 | ||
27 | void main() | |
28 | { | |
29 | char *s; | |
30 | struct vars vars[512]; | |
31 | int nvars = 0; | |
32 | int readingdata = 0; | |
33 | SDL_Surface *screen; | |
34 | ||
35 | if (SDL_Init(SDL_INIT_VIDEO) < 0) | |
36 | { | |
37 | printf("SDL init failed: %s\n", SDL_GetError()); | |
38 | return 1; | |
39 | } | |
40 | atexit(SDL_Quit); | |
41 | screen = SDL_SetVideoMode(WIN_X, WIN_Y, 24, SDL_SWSURFACE); | |
42 | if (!screen) | |
43 | { | |
44 | printf("Video init failed: %s\n", SDL_GetError()); | |
45 | } | |
46 | ||
47 | while ((s = readline())) | |
48 | { | |
49 | if (s[0] == '$') | |
50 | { | |
51 | if (!strcmp(s, "$dumpvars")) | |
52 | { | |
53 | readingdata = 1; | |
54 | printf("Var dump begin on %d vars\n", nvars); | |
55 | } else if (!strncmp(s, "$var", 4)) { | |
56 | char *t; | |
57 | char *vname, *var, *sub;\ | |
58 | t = strtok(s, " "); | |
59 | t = strtok(NULL, " "); | |
60 | t = strtok(NULL, " "); | |
61 | t = strtok(NULL, " "); | |
62 | vname = t; | |
63 | t = strtok(NULL, " "); | |
64 | var = t; | |
65 | t = strtok(NULL, " "); | |
66 | if (strcmp(t, "$end")) | |
67 | sub = t; | |
68 | else | |
69 | sub = NULL; | |
70 | printf("Found: %s -> %s %s\n", vname, var, sub); | |
71 | ||
72 | vars[nvars].vname = strdup(vname); | |
73 | vars[nvars].var = strdup(var); | |
74 | vars[nvars].sub = sub ? strdup(sub) : NULL; | |
75 | vars[nvars].val = 0; | |
76 | nvars++; | |
77 | } | |
78 | } else if (s[0] == '#') | |
79 | ; | |
80 | else | |
81 | { | |
82 | int val = (s[0] == '1'); | |
83 | int i; | |
84 | int oldclk = *findvar("gclk", NULL, vars, nvars); | |
85 | static int pixn = 0; | |
86 | for (i=0; i<nvars; i++) | |
87 | { | |
88 | if (!strcmp(vars[i].vname, s+1)) | |
89 | { | |
90 | vars[i].val = val; | |
91 | break; | |
92 | } | |
93 | } | |
94 | if (i == nvars) | |
95 | printf("Unknown: %s\n", s); | |
96 | if (*findvar("gclk", NULL, vars, nvars) != oldclk && oldclk == 1 && ((pixn++) % 2)) | |
97 | { | |
98 | static int x = 0, y = 0; | |
99 | static int lasths; | |
100 | unsigned char *pixp; | |
101 | static int *r2 = NULL, *r1 = NULL, *r0 = NULL, *g2 = NULL, *g1 = NULL, *g0 = NULL, *b1 = NULL, *b0 = NULL, *vs = NULL, *hs = NULL; | |
102 | r2 = r2 ? r2 : findvar("red", "[2]", vars, nvars); | |
103 | r1 = r1 ? r1 : findvar("red", "[1]", vars, nvars); | |
104 | r0 = r0 ? r0 : findvar("red", "[0]", vars, nvars); | |
105 | g2 = g2 ? g2 : findvar("green", "[2]", vars, nvars); | |
106 | g1 = g1 ? g1 : findvar("green", "[1]", vars, nvars); | |
107 | g0 = g0 ? g0 : findvar("green", "[0]", vars, nvars); | |
108 | b1 = b1 ? b1 : findvar("blue", "[1]", vars, nvars); | |
109 | b0 = b0 ? b0 : findvar("blue", "[0]", vars, nvars); | |
110 | vs = vs ? vs : findvar("vs", NULL, vars, nvars); | |
111 | hs = hs ? hs : findvar("hs", NULL, vars, nvars); | |
112 | ||
113 | ||
114 | int r = *r2 << 7 | *r1 << 6 | *r0 << 5; | |
115 | int g = *g2 << 7 | *g1 << 6 | *g0 << 5; | |
116 | int b = *b1 << 7 | *b0 << 6; | |
117 | if (*vs) | |
118 | y = 0; | |
119 | else { | |
120 | if (*hs) | |
121 | { | |
122 | x = 0; | |
123 | if (!lasths) | |
124 | y++; | |
125 | } else | |
126 | x++; | |
127 | } | |
128 | lasths = *hs; | |
129 | SDL_LockSurface(screen); | |
130 | pixp = screen->pixels + ((WIN_X * y + x) * 3); | |
131 | pixp[0] = b; pixp[1] = g; pixp[2] = r; | |
132 | SDL_UnlockSurface(screen); | |
133 | if ((x % 5) == 4) | |
134 | SDL_UpdateRect(screen, x/5*5, y, 5, 1); | |
135 | } | |
136 | } | |
137 | } | |
138 | } |