Add some more sim goop
authorJoshua Wise <joshua@rebirth.joshuawise.com>
Sun, 4 May 2008 07:06:14 +0000 (03:06 -0400)
committerJoshua Wise <joshua@rebirth.joshuawise.com>
Sun, 4 May 2008 07:06:14 +0000 (03:06 -0400)
bootstrap.hex [new file with mode: 0644]
kill-unlink.c [new file with mode: 0644]
readout.c [new file with mode: 0644]
sim.cmd [new file with mode: 0644]

diff --git a/bootstrap.hex b/bootstrap.hex
new file mode 100644 (file)
index 0000000..bdea321
--- /dev/null
@@ -0,0 +1,256 @@
+31
+fe
+ff
+af
+21
+ff
+9f
+32
+cb
+7c
+20
+fb
+21
+26
+ff
+0e
+11
+3e
+80
+32
+e2
+0c
+3e
+f3
+e2
+32
+3e
+77
+32
+3e
+fc
+e0
+47
+11
+04
+01
+21
+10
+80
+1a
+cd
+95
+00
+cd
+96
+00
+13
+7b
+fe
+34
+20
+f3
+11
+d8
+00
+06
+08
+1a
+13
+22
+23
+05
+20
+f9
+3e
+19
+ea
+10
+99
+21
+2f
+99
+0e
+0c
+3d
+28
+08
+32
+0d
+20
+f9
+2e
+0f
+18
+f3
+67
+3e
+64
+57
+e0
+42
+3e
+91
+e0
+40
+04
+1e
+02
+0e
+0c
+f0
+44
+fe
+90
+20
+fa
+0d
+20
+f7
+1d
+20
+f2
+0e
+13
+24
+7c
+1e
+83
+fe
+62
+28
+06
+1e
+c1
+fe
+64
+20
+06
+7b
+e2
+0c
+3e
+87
+e2
+f0
+42
+90
+e0
+42
+15
+20
+d2
+05
+20
+4f
+16
+20
+18
+cb
+4f
+06
+04
+c5
+cb
+11
+17
+c1
+cb
+11
+17
+05
+20
+f5
+22
+23
+22
+23
+c9
+ce
+ed
+66
+66
+cc
+0d
+00
+0b
+03
+73
+00
+83
+00
+0c
+00
+0d
+00
+08
+11
+1f
+88
+89
+00
+0e
+dc
+cc
+6e
+e6
+dd
+dd
+d9
+99
+bb
+bb
+67
+63
+6e
+0e
+ec
+cc
+dd
+dc
+99
+9f
+bb
+b9
+33
+3e
+3c
+42
+b9
+a5
+b9
+a5
+42
+3c
+21
+04
+01
+11
+a8
+00
+1a
+13
+be
+20
+fe
+23
+7d
+fe
+34
+20
+f5
+06
+19
+78
+86
+23
+05
+20
+fb
+86
+20
+fe
+3e
+01
+e0
+50
diff --git a/kill-unlink.c b/kill-unlink.c
new file mode 100644 (file)
index 0000000..3fe5000
--- /dev/null
@@ -0,0 +1,4 @@
+int unlink(char *s)
+{
+  return 0;
+}
\ No newline at end of file
diff --git a/readout.c b/readout.c
new file mode 100644 (file)
index 0000000..34ade44
--- /dev/null
+++ b/readout.c
@@ -0,0 +1,191 @@
+#include <string.h>
+#include <SDL/SDL.h>
+
+#define WIN_X 800
+#define WIN_Y 600
+
+#define RINGSZ 528088
+
+char getone()
+{
+       unsigned char c;
+       static char ring[RINGSZ];
+       static int prod = 0, cons = 0;
+       int oldcons;
+       
+       if (prod == cons)
+       {
+               int r;
+               
+               /* Try to read some. */
+               while ((r = read(0, &(ring[prod]), RINGSZ-prod)) == 0)
+                       usleep(250000);
+               prod = (prod + r) % RINGSZ;
+       }
+       oldcons = cons;
+       cons = (cons + 1) % RINGSZ;
+       return ring[oldcons];
+}
+
+char *readline()
+{
+       static char s[2048];
+       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 {
+       char *vname, *var, *sub;
+       int val;
+};
+
+int *findvar(char *var, char *sub, struct vars *vars, int n)
+{
+       int i;
+       for (i=0; i<96*96; i++)
+               if (vars[i].var && !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();
+}
+
+int numname(char *s)
+{
+       int i = 0;
+       while(*s)
+       {
+               i *= 96;
+               i += *(s++) - '!' + 1;
+       }
+       return i;
+}
+
+void main()
+{
+       char *s;
+       struct vars vars[96*96];
+       int nvars = 0;
+       int readingdata = 0;
+       SDL_Surface *screen;
+       
+       if (SDL_Init(SDL_INIT_VIDEO) < 0)
+       {
+               printf("SDL init failed: %s\n", SDL_GetError());
+               return 1;
+       }
+       atexit(SDL_Quit);
+       screen = SDL_SetVideoMode(WIN_X, WIN_Y, 24, SDL_SWSURFACE);
+       if (!screen)
+       {
+               printf("Video init failed: %s\n", SDL_GetError());
+       }
+       
+       memset(vars, 0, sizeof(vars));
+       
+       while ((s = readline()))
+       {
+               if (s[0] == '$')
+               {
+                       if (!strcmp(s, "$dumpvars"))
+                       {
+                               readingdata = 1;
+                               printf("Var dump begin on %d vars\n", nvars);
+                       } else if (!strncmp(s, "$var", 4)) {
+                               char *t;
+                               char *vname, *var, *sub;\
+                               t = strtok(s, " ");
+                               t = strtok(NULL, " ");
+                               t = strtok(NULL, " ");
+                               t = strtok(NULL, " ");
+                               vname = t;
+                               t = strtok(NULL, " ");
+                               var = t;
+                               t = strtok(NULL, " ");
+                               if (strcmp(t, "$end"))
+                                       sub = t;
+                               else
+                                       sub = NULL;
+                               printf("Found: %s (%d) -> %s %s\n", vname, numname(vname), var, sub);
+                               
+                               vars[numname(vname)].vname = strdup(vname);
+                               vars[numname(vname)].var = strdup(var);
+                               vars[numname(vname)].sub = sub ? strdup(sub) : NULL;
+                               vars[numname(vname)].val = 0;
+                       }
+               } else if (s[0] == '#' || !s[0])
+                       ;
+               else if (readingdata)
+               {
+                       int val = (s[0] == '1');
+                       int i;
+                       static int *tclk;
+                       int oldclk = tclk ? *tclk : 0;
+                       static int pixn = 0;
+                       
+                       if (!tclk) tclk = findvar("vgaclk", NULL, vars, nvars);
+                       
+                       vars[numname(s+1)].val = val;
+                       
+                       if (*tclk != oldclk && ((pixn++) % 2)) {
+                               static int x = 0, y = 0;
+                               static int lasths;
+                               unsigned char *pixp;
+                               static int *r2 = NULL, *r1 = NULL, *r0 = NULL, *g2 = NULL, *g1 = NULL, *g0 = NULL, *b1 = NULL, *b0 = NULL, *vs = NULL, *hs = NULL;
+                               if (!r2) r2 = findvar("r", "[2]", vars, nvars);
+                               if (!r1) r1 = findvar("r", "[1]", vars, nvars);
+                               if (!r0) r0 = findvar("r", "[0]", vars, nvars);
+                               if (!g2) g2 = findvar("g", "[2]", vars, nvars);
+                               if (!g1) g1 = findvar("g", "[1]", vars, nvars);
+                               if (!g0) g0 = findvar("g", "[0]", vars, nvars);
+                               if (!b1) b1 = findvar("b", "[1]", vars, nvars);
+                               if (!b0) b0 = findvar("b", "[0]", vars, nvars);
+                               if (!vs) vs = findvar("vs", NULL, vars, nvars);
+                               if (!hs) hs = findvar("hs", NULL, vars, nvars);
+                               
+                               
+                               int r = *r2 << 7 | *r1 << 6 | *r0 << 5;
+                               int g = *g2 << 7 | *g1 << 6 | *g0 << 5;
+                               int b = *b1 << 7 | *b0 << 6;
+                               if (*vs)
+                                       y = 0;
+                               else {
+                                       if (*hs)
+                                       {
+                                               x = 0;
+                                               if (!lasths)
+                                                       y++;
+                                       } else
+                                               x++;
+                               }
+                               SDL_LockSurface(screen);
+                               pixp = screen->pixels + ((WIN_X * y + x) * 3);
+                               pixp[0] = b; pixp[1] = g; pixp[2] = r;
+                               SDL_UnlockSurface(screen);
+                               if (x == 0 && !lasths && y != 0)
+                               {
+                                       int i;
+                                       SDL_LockSurface(screen);
+                                       for (i = 1; i < WIN_X; i++)
+                                               pixp[0+i*3] = pixp[1+i*3] = pixp[2+i*3] = 0xFF;
+                                       SDL_UnlockSurface(screen);
+                                       SDL_UpdateRect(screen, 0, y-1, WIN_X, 2);
+                                       if (!(y % 3))
+                                               SDL_Flip(screen);
+                               }
+                               lasths = *hs;
+                       }
+               }
+       }
+}
diff --git a/sim.cmd b/sim.cmd
new file mode 100644 (file)
index 0000000..6870512
--- /dev/null
+++ b/sim.cmd
@@ -0,0 +1,3 @@
+vcd dumpfile output.vcd
+vcd dumpvars -m Dumpable
+run 1000ms
This page took 0.032027 seconds and 4 git commands to generate.