diff options
| author | Julian Blake Kongslie | 2022-10-15 12:11:29 -0700 |
|---|---|---|
| committer | Julian Blake Kongslie | 2022-10-15 12:11:29 -0700 |
| commit | e5240f276659a341c42e0b7da4d36bb8c150dfac (patch) | |
| tree | 33ace8ec2bd4072d432a6f9210e081f1c8b96431 /isa | |
| parent | Add Fibonacci program (which doesn't work yet) (diff) | |
| download | biggolf-e5240f276659a341c42e0b7da4d36bb8c150dfac.tar.xz | |
Implement most of the OPR instructions.
Diffstat (limited to 'isa')
| -rw-r--r-- | isa/decode.cpp | 90 |
1 files changed, 87 insertions, 3 deletions
diff --git a/isa/decode.cpp b/isa/decode.cpp index 5212ae7..1d46375 100644 --- a/isa/decode.cpp +++ b/isa/decode.cpp | |||
| @@ -66,14 +66,98 @@ instruction_context decode(unsigned int dfifb, unsigned int pc, unsigned int bit | |||
| 66 | }; | 66 | }; |
| 67 | break; | 67 | break; |
| 68 | case 6: // IOT | 68 | case 6: // IOT |
| 69 | inst.ef = [bits](auto &ctx) { | 69 | inst.ef = [](auto &ctx) { |
| 70 | assert(false); | 70 | assert(false); |
| 71 | }; | 71 | }; |
| 72 | break; | 72 | break; |
| 73 | case 7: // OPR | 73 | case 7: // OPR |
| 74 | inst.ef = [bits](auto &ctx) { | 74 | if ((bits & 0400) == 0000) { |
| 75 | bool cla = bits & 0200; | ||
| 76 | bool cll = bits & 0100; | ||
| 77 | bool cma = bits & 0040; | ||
| 78 | bool cml = bits & 0020; | ||
| 79 | bool rar = bits & 0010; | ||
| 80 | bool ral = bits & 0004; | ||
| 81 | bool bsw = bits & 0002; | ||
| 82 | bool iac = bits & 0001; | ||
| 83 | inst.need_read_acc = cma || rar || ral || bsw || iac; | ||
| 84 | inst.need_read_link = cml || rar || ral || iac; | ||
| 85 | inst.need_write_acc = cla || cma || rar || ral || bsw || iac; | ||
| 86 | inst.need_write_link = cll || cml || rar || ral || iac; | ||
| 87 | inst.ef = [cla, cll, cma, cml, rar, ral, bsw, iac](auto &ctx) { | ||
| 88 | if (cla) ctx.acc = 0; | ||
| 89 | if (cll) ctx.link = 0; | ||
| 90 | if (cma) ctx.acc = ~ctx.acc.value(); | ||
| 91 | if (cml) ctx.link = !ctx.link.value(); | ||
| 92 | if (iac) { | ||
| 93 | if (++ctx.acc.value() == 0) ctx.link = !ctx.link.value(); | ||
| 94 | } | ||
| 95 | if (rar && !ral) { | ||
| 96 | unsigned int x = (ctx.link.value() << 12) | ctx.acc.value(); | ||
| 97 | x = (x >> 1) | ((x & 1) << 12); | ||
| 98 | if (bsw) | ||
| 99 | x = (x >> 1) | ((x & 1) << 12); | ||
| 100 | ctx.link = x >> 12; | ||
| 101 | ctx.acc = x & 07777; | ||
| 102 | } | ||
| 103 | if (ral && !rar) { | ||
| 104 | unsigned int x = (ctx.link.value() << 12) | ctx.acc.value(); | ||
| 105 | x = ((x << 1) & 07777) | (x >> 12); | ||
| 106 | if (bsw) | ||
| 107 | x = ((x << 1) & 07777) | (x >> 12); | ||
| 108 | ctx.link = x >> 12; | ||
| 109 | ctx.acc = x & 07777; | ||
| 110 | } | ||
| 111 | if (bsw && !(rar || ral)) | ||
| 112 | ctx.acc = ((ctx.acc.value() & 00077) << 6) | (ctx.acc.value() >> 6); | ||
| 113 | }; | ||
| 114 | } else if ((bits & 0411) == 0400) { | ||
| 115 | bool cla = bits & 0200; | ||
| 116 | bool sma = bits & 0100; | ||
| 117 | bool sza = bits & 0040; | ||
| 118 | bool snl = bits & 0020; | ||
| 119 | bool osr = bits & 0004; | ||
| 120 | bool hlt = bits & 0002; | ||
| 121 | inst.need_read_acc = sma || sza; | ||
| 122 | inst.need_read_link = snl; | ||
| 123 | inst.need_write_acc = cla; | ||
| 124 | inst.possibly_redirects = true; | ||
| 125 | inst.ef = [cla, sma, sza, snl, osr, hlt](auto &ctx) { | ||
| 126 | bool skip = false; | ||
| 127 | if (sma && (ctx.acc.value() & 04000)) skip = true; | ||
| 128 | if (sza && (ctx.acc.value() == 0)) skip = true; | ||
| 129 | if (snl && ctx.link.value()) skip = true; | ||
| 130 | if (cla) ctx.acc = 0; | ||
| 131 | assert(!osr); | ||
| 132 | if (hlt) ctx.halt = true; | ||
| 133 | if (skip) | ||
| 134 | ctx.next_pc = (ctx.next_pc & 070000) | ((ctx.next_pc + 1) & 007777); | ||
| 135 | }; | ||
| 136 | } else if ((bits & 0411) == 0410) { | ||
| 137 | bool cla = bits & 0200; | ||
| 138 | bool spa = bits & 0100; | ||
| 139 | bool sna = bits & 0040; | ||
| 140 | bool szl = bits & 0020; | ||
| 141 | bool osr = bits & 0004; | ||
| 142 | bool hlt = bits & 0002; | ||
| 143 | inst.need_read_acc = spa || sna; | ||
| 144 | inst.need_read_link = szl; | ||
| 145 | inst.need_write_acc = cla; | ||
| 146 | inst.possibly_redirects = true; | ||
| 147 | inst.ef = [cla, spa, sna, szl, osr, hlt](auto &ctx) { | ||
| 148 | bool skip = true; | ||
| 149 | if (spa && (ctx.acc.value() & 04000)) skip = false; | ||
| 150 | if (sna && (ctx.acc.value() == 0)) skip = false; | ||
| 151 | if (szl && ctx.link.value()) skip = false; | ||
| 152 | if (cla) ctx.acc = 0; | ||
| 153 | assert(!osr); | ||
| 154 | if (hlt) ctx.halt = true; | ||
| 155 | if (skip) | ||
| 156 | ctx.next_pc = (ctx.next_pc & 070000) | ((ctx.next_pc + 1) & 007777); | ||
| 157 | }; | ||
| 158 | } else { | ||
| 75 | assert(false); | 159 | assert(false); |
| 76 | }; | 160 | } |
| 77 | break; | 161 | break; |
| 78 | } | 162 | } |
| 79 | 163 | ||
