1 //#test return -293203597
4 int r0, r1, r2, r3, fr, pc, sp;
9 puts("FAIL [abort]\n");
16 3632, 9, 3584, 57, 3600, 16384, 3616, 65535, 11792, 20018, 19970, 24114, 592, 8, 3584, 10, 11792, 65535};
20 int crc32_update(int crc, int byte)
25 for (i = 0; i < 8; i += 1)
36 int muxreg(int reg, struct cpustate * s)
38 if (reg == 0) return s->r0;
39 if (reg == 1) return s->r1;
40 if (reg == 2) return s->r2;
41 if (reg == 3) return s->r3;
42 if (reg == 4) return s->fr;
43 if (reg == 5) return s->pc;
44 if (reg == 6) return s->sp;
48 int setreg(int reg, int d, struct cpustate *s)
50 if (reg == 0) s->r0 = d;
51 if (reg == 1) s->r1 = d;
52 if (reg == 2) s->r2 = d;
53 if (reg == 3) s->r3 = d;
54 if (reg == 4) s->fr = d;
55 if (reg == 5) s->pc = d;
56 if (reg == 6) s->sp = d;
60 int predcheck(int pred, struct cpustate *s)
62 if (pred == 0) return 0;
63 if (pred == 1) return !(s->fr & 4);
64 if (pred == 2) return (s->fr & 4);
65 if (pred == 3) return (s->fr & 1);
66 if (pred == 4) return (s->fr & 2);
67 if (pred == 7) return 1;
73 struct cpustate cs, *s;
74 int crc, iv, insn, pred, rt, rs, d;
97 crc = crc32_update(crc, s->r0);
98 crc = crc32_update(crc, s->r1);
99 crc = crc32_update(crc, s->r2);
100 crc = crc32_update(crc, s->r3);
101 crc = crc32_update(crc, s->fr);
102 crc = crc32_update(crc, s->sp);
103 crc = crc32_update(crc, s->pc);
108 if (!predcheck(pred, s))
116 } else if (insn == 1) {
118 if (!predcheck(pred, s))
120 d = rom[muxreg(rs, s)];
122 } else if (insn == 2) {
124 if (!predcheck(pred, s))
127 if (muxreg(rt, s) != 16384)
130 } else if (insn == 3) {
132 if (!predcheck(pred, s))
136 } else if (insn == 4) {
138 if (!predcheck(pred, s))
144 } else if (insn == 5) {
146 if (!predcheck(pred, s))
151 if (d == 0) s->fr |= 4;
152 if (d > 0) s->fr |= 1;
153 if (d < 0) s->fr |= 2;
154 } else if (insn == 6) {
156 if (!predcheck(pred, s))
161 } else if (insn == 7) {
163 if (!predcheck(pred, s))
172 if (crc != -293203597)