1 //#test return -293203597
4 int r0, r1, r2, r3, fr, pc, sp;
9 puts("FAIL [abort]\n");
37 int crc32_update(int crc, int byte)
42 for (i = 0; i < 8; i += 1)
53 int muxreg(int reg, struct cpustate * s)
55 if (reg == 0) return s->r0;
56 if (reg == 1) return s->r1;
57 if (reg == 2) return s->r2;
58 if (reg == 3) return s->r3;
59 if (reg == 4) return s->fr;
60 if (reg == 5) return s->pc;
61 if (reg == 6) return s->sp;
65 int setreg(int reg, int d, struct cpustate *s)
67 if (reg == 0) s->r0 = d;
68 if (reg == 1) s->r1 = d;
69 if (reg == 2) s->r2 = d;
70 if (reg == 3) s->r3 = d;
71 if (reg == 4) s->fr = d;
72 if (reg == 5) s->pc = d;
73 if (reg == 6) s->sp = d;
77 int predcheck(int pred, struct cpustate *s)
79 if (pred == 0) return 0;
80 if (pred == 1) return !(s->fr & 4);
81 if (pred == 2) return (s->fr & 4);
82 if (pred == 3) return (s->fr & 1);
83 if (pred == 4) return (s->fr & 2);
84 if (pred == 7) return 1;
90 struct cpustate cs, *s;
91 int crc, iv, insn, pred, rt, rs, d;
111 pred = (iv >> 9) & 7;
114 crc = crc32_update(crc, s->r0);
115 crc = crc32_update(crc, s->r1);
116 crc = crc32_update(crc, s->r2);
117 crc = crc32_update(crc, s->r3);
118 crc = crc32_update(crc, s->fr);
119 crc = crc32_update(crc, s->sp);
120 crc = crc32_update(crc, s->pc);
125 if (!predcheck(pred, s))
133 } else if (insn == 1) {
135 if (!predcheck(pred, s))
137 d = rom[muxreg(rs, s)];
139 } else if (insn == 2) {
141 if (!predcheck(pred, s))
144 if (muxreg(rt, s) != 16384)
147 } else if (insn == 3) {
149 if (!predcheck(pred, s))
153 } else if (insn == 4) {
155 if (!predcheck(pred, s))
161 } else if (insn == 5) {
163 if (!predcheck(pred, s))
168 if (d == 0) s->fr |= 4;
169 if (d > 0) s->fr |= 1;
170 if (d < 0) s->fr |= 2;
171 } else if (insn == 6) {
173 if (!predcheck(pred, s))
178 } else if (insn == 7) {
180 if (!predcheck(pred, s))
189 if (crc != -293203597)