aboutsummaryrefslogtreecommitdiffstats
path: root/src/uxn/uxn/opcodes.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/uxn/uxn/opcodes.c')
-rw-r--r--src/uxn/uxn/opcodes.c373
1 files changed, 0 insertions, 373 deletions
diff --git a/src/uxn/uxn/opcodes.c b/src/uxn/uxn/opcodes.c
deleted file mode 100644
index 947755f..0000000
--- a/src/uxn/uxn/opcodes.c
+++ /dev/null
@@ -1,373 +0,0 @@
1/*
2Copyright (u) 2021 Devine Lu Linvega
3Copyright (c) 2021 Adrian "asie" Siekierka
4
5Permission to use, copy, modify, and distribute this software for any
6purpose with or without fee is hereby granted, provided that the above
7copyright notice and this permission notice appear in all copies.
8
9THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10WITH REGARD TO THIS SOFTWARE.
11*/
12
13/* 8-BIT OPCODES */
14
15case UXN_OPC(0x00):
16case UXN_OPC(0x20): { // brk
17 u->ram.ptr = 0;
18} break;
19case UXN_OPC(0x01): { // lit
20 push8(UXN_SRC, mempeek8(u->ram.dat, u->ram.ptr++));
21} break;
22case UXN_OPC(0x02):
23case UXN_OPC(0x22): { // nop
24} break;
25case UXN_OPC(0x03): { // pop
26 UXN_KEEP_SYNC;
27 pop8(UXN_SRC);
28} break;
29case UXN_OPC(0x04): { // dup
30 UXN_KEEP_SYNC;
31 Uint8 a = pop8(UXN_SRC);
32 push8(UXN_SRC, a);
33 push8(UXN_SRC, a);
34} break;
35case UXN_OPC(0x05): { // swp
36 UXN_KEEP_SYNC;
37 Uint8 a = pop8(UXN_SRC);
38 Uint8 b = pop8(UXN_SRC);
39 push8(UXN_SRC, a);
40 push8(UXN_SRC, b);
41} break;
42case UXN_OPC(0x06): { // ovr
43 UXN_KEEP_SYNC;
44 Uint8 a = pop8(UXN_SRC);
45 Uint8 b = pop8(UXN_SRC);
46 push8(UXN_SRC, b);
47 push8(UXN_SRC, a);
48 push8(UXN_SRC, b);
49} break;
50case UXN_OPC(0x07): { // rot
51 UXN_KEEP_SYNC;
52 Uint8 a = pop8(UXN_SRC);
53 Uint8 b = pop8(UXN_SRC);
54 Uint8 c = pop8(UXN_SRC);
55 push8(UXN_SRC, b);
56 push8(UXN_SRC, a);
57 push8(UXN_SRC, c);
58} break;
59case UXN_OPC(0x08): { // equ
60 UXN_KEEP_SYNC;
61 Uint8 a = pop8(UXN_SRC);
62 Uint8 b = pop8(UXN_SRC);
63 push8(UXN_SRC, b == a);
64} break;
65case UXN_OPC(0x09): { // neg
66 UXN_KEEP_SYNC;
67 Uint8 a = pop8(UXN_SRC);
68 Uint8 b = pop8(UXN_SRC);
69 push8(UXN_SRC, b != a);
70} break;
71case UXN_OPC(0x0A): { // gth
72 UXN_KEEP_SYNC;
73 Uint8 a = pop8(UXN_SRC);
74 Uint8 b = pop8(UXN_SRC);
75 push8(UXN_SRC, b > a);
76} break;
77case UXN_OPC(0x0B): { // lth
78 UXN_KEEP_SYNC;
79 Uint8 a = pop8(UXN_SRC);
80 Uint8 b = pop8(UXN_SRC);
81 push8(UXN_SRC, b < a);
82} break;
83case UXN_OPC(0x0C): { // jmp
84 UXN_KEEP_SYNC;
85 Uint8 a = pop8(UXN_SRC);
86 u->ram.ptr += (Sint8)a;
87} break;
88case UXN_OPC(0x0D): { // jnz
89 UXN_KEEP_SYNC;
90 Uint8 a = pop8(UXN_SRC);
91 if (pop8(UXN_SRC))
92 u->ram.ptr += (Sint8)a;
93} break;
94case UXN_OPC(0x0E): { // jsr
95 UXN_KEEP_SYNC;
96 Uint8 a = pop8(UXN_SRC);
97 push16(UXN_DST, u->ram.ptr);
98 u->ram.ptr += (Sint8)a;
99} break;
100case UXN_OPC(0x0F): { // sth
101 UXN_KEEP_SYNC;
102 Uint8 a = pop8(UXN_SRC);
103 push8(UXN_DST, a);
104} break;
105case UXN_OPC(0x10): { // pek
106 UXN_KEEP_SYNC;
107 Uint8 a = pop8(UXN_SRC);
108 push8(UXN_SRC, mempeek8(u->ram.dat, a));
109} break;
110case UXN_OPC(0x11): { // pok
111 UXN_KEEP_SYNC;
112 Uint8 a = pop8(UXN_SRC);
113 Uint8 b = pop8(UXN_SRC);
114 mempoke8(u->ram.dat, a, b);
115} break;
116case UXN_OPC(0x12): { // ldr
117 UXN_KEEP_SYNC;
118 Uint8 a = pop8(UXN_SRC);
119 push8(UXN_SRC, mempeek8(u->ram.dat, u->ram.ptr + (Sint8)a));
120} break;
121case UXN_OPC(0x13): { // str
122 UXN_KEEP_SYNC;
123 Uint8 a = pop8(UXN_SRC);
124 Uint8 b = pop8(UXN_SRC);
125 mempoke8(u->ram.dat, u->ram.ptr + (Sint8)a, b);
126} break;
127case UXN_OPC(0x14): { // lda
128 UXN_KEEP_SYNC;
129 Uint16 a = pop16(UXN_SRC);
130 push8(UXN_SRC, mempeek8(u->ram.dat, a));
131} break;
132case UXN_OPC(0x15): { // sta
133 UXN_KEEP_SYNC;
134 Uint16 a = pop16(UXN_SRC);
135 Uint8 b = pop8(UXN_SRC);
136 mempoke8(u->ram.dat, a, b);
137} break;
138case UXN_OPC(0x16): { // dei
139 UXN_KEEP_SYNC;
140 Uint8 a = pop8(UXN_SRC);
141 push8(UXN_SRC, devpeek8(&u->dev[a >> 4], a));
142} break;
143case UXN_OPC(0x17): { // deo
144 UXN_KEEP_SYNC;
145 Uint8 a = pop8(UXN_SRC);
146 Uint8 b = pop8(UXN_SRC);
147 devpoke8(&u->dev[a >> 4], a, b);
148} break;
149case UXN_OPC(0x18): { // add
150 UXN_KEEP_SYNC;
151 Uint8 a = pop8(UXN_SRC);
152 Uint8 b = pop8(UXN_SRC);
153 push8(UXN_SRC, b + a);
154} break;
155case UXN_OPC(0x19): { // sub
156 UXN_KEEP_SYNC;
157 Uint8 a = pop8(UXN_SRC);
158 Uint8 b = pop8(UXN_SRC);
159 push8(UXN_SRC, b - a);
160} break;
161case UXN_OPC(0x1A): { // mul
162 UXN_KEEP_SYNC;
163 Uint8 a = pop8(UXN_SRC);
164 Uint8 b = pop8(UXN_SRC);
165 push8(UXN_SRC, b * a);
166} break;
167case UXN_OPC(0x1B): { // div
168 UXN_KEEP_SYNC;
169 Uint8 a = pop8(UXN_SRC);
170 Uint8 b = pop8(UXN_SRC);
171 push8(UXN_SRC, b / a);
172} break;
173case UXN_OPC(0x1C): { // and
174 UXN_KEEP_SYNC;
175 Uint8 a = pop8(UXN_SRC);
176 Uint8 b = pop8(UXN_SRC);
177 push8(UXN_SRC, b & a);
178} break;
179case UXN_OPC(0x1D): { // ora
180 UXN_KEEP_SYNC;
181 Uint8 a = pop8(UXN_SRC);
182 Uint8 b = pop8(UXN_SRC);
183 push8(UXN_SRC, b | a);
184} break;
185case UXN_OPC(0x1E): { // eor
186 UXN_KEEP_SYNC;
187 Uint8 a = pop8(UXN_SRC);
188 Uint8 b = pop8(UXN_SRC);
189 push8(UXN_SRC, b ^ a);
190} break;
191case UXN_OPC(0x1F): { // sft
192 UXN_KEEP_SYNC;
193 Uint8 a = pop8(UXN_SRC);
194 Uint8 b = pop8(UXN_SRC);
195 push8(UXN_SRC, b >> (a & 0x07) << ((a & 0x70) >> 4));
196} break;
197
198/* 16-BIT OPCODES */
199
200case UXN_OPC(0x21): { // lit
201 push16(UXN_SRC, mempeek16(u->ram.dat, u->ram.ptr));
202 u->ram.ptr += 2;
203} break;
204case UXN_OPC(0x23): { // pop
205 UXN_KEEP_SYNC;
206 pop16(UXN_SRC);
207} break;
208case UXN_OPC(0x24): { // dup
209 UXN_KEEP_SYNC;
210 Uint16 a = pop16(UXN_SRC);
211 push16(UXN_SRC, a);
212 push16(UXN_SRC, a);
213} break;
214case UXN_OPC(0x25): { // swp
215 UXN_KEEP_SYNC;
216 Uint16 a = pop16(UXN_SRC);
217 Uint16 b = pop16(UXN_SRC);
218 push16(UXN_SRC, a);
219 push16(UXN_SRC, b);
220} break;
221case UXN_OPC(0x26): { // ovr
222 UXN_KEEP_SYNC;
223 Uint16 a = pop16(UXN_SRC);
224 Uint16 b = pop16(UXN_SRC);
225 push16(UXN_SRC, b);
226 push16(UXN_SRC, a);
227 push16(UXN_SRC, b);
228} break;
229case UXN_OPC(0x27): { // rot
230 UXN_KEEP_SYNC;
231 Uint16 a = pop16(UXN_SRC);
232 Uint16 b = pop16(UXN_SRC);
233 Uint16 c = pop16(UXN_SRC);
234 push16(UXN_SRC, b);
235 push16(UXN_SRC, a);
236 push16(UXN_SRC, c);
237} break;
238case UXN_OPC(0x28): { // equ
239 UXN_KEEP_SYNC;
240 Uint16 a = pop16(UXN_SRC);
241 Uint16 b = pop16(UXN_SRC);
242 push8(UXN_SRC, b == a);
243} break;
244case UXN_OPC(0x29): { // neg
245 UXN_KEEP_SYNC;
246 Uint16 a = pop16(UXN_SRC);
247 Uint16 b = pop16(UXN_SRC);
248 push8(UXN_SRC, b != a);
249} break;
250case UXN_OPC(0x2A): { // gth
251 UXN_KEEP_SYNC;
252 Uint16 a = pop16(UXN_SRC);
253 Uint16 b = pop16(UXN_SRC);
254 push8(UXN_SRC, b > a);
255} break;
256case UXN_OPC(0x2B): { // lth
257 UXN_KEEP_SYNC;
258 Uint16 a = pop16(UXN_SRC);
259 Uint16 b = pop16(UXN_SRC);
260 push8(UXN_SRC, b < a);
261} break;
262case UXN_OPC(0x2C): { // jmp
263 UXN_KEEP_SYNC;
264 u->ram.ptr = pop16(UXN_SRC);
265} break;
266case UXN_OPC(0x2D): { // jnz
267 UXN_KEEP_SYNC;
268 Uint16 a = pop16(UXN_SRC);
269 if (pop8(UXN_SRC))
270 u->ram.ptr = a;
271} break;
272case UXN_OPC(0x2E): { // jsr
273 UXN_KEEP_SYNC;
274 push16(UXN_DST, u->ram.ptr);
275 u->ram.ptr = pop16(UXN_SRC);
276} break;
277case UXN_OPC(0x2F): { // sth
278 UXN_KEEP_SYNC;
279 Uint16 a = pop16(UXN_SRC);
280 push16(UXN_DST, a);
281} break;
282case UXN_OPC(0x30): { // pek
283 UXN_KEEP_SYNC;
284 Uint8 a = pop8(UXN_SRC);
285 push16(UXN_SRC, mempeek16(u->ram.dat, a));
286} break;
287case UXN_OPC(0x31): { // pok
288 UXN_KEEP_SYNC;
289 Uint8 a = pop8(UXN_SRC);
290 Uint16 b = pop16(UXN_SRC);
291 mempoke16(u->ram.dat, a, b);
292} break;
293case UXN_OPC(0x32): { // ldr
294 UXN_KEEP_SYNC;
295 Uint8 a = pop8(UXN_SRC);
296 push16(UXN_SRC, mempeek16(u->ram.dat, u->ram.ptr + (Sint8)a));
297} break;
298case UXN_OPC(0x33): { // str
299 UXN_KEEP_SYNC;
300 Uint8 a = pop8(UXN_SRC);
301 Uint16 b = pop16(UXN_SRC);
302 mempoke16(u->ram.dat, u->ram.ptr + (Sint8)a, b);
303} break;
304case UXN_OPC(0x34): { // lda
305 UXN_KEEP_SYNC;
306 Uint16 a = pop16(UXN_SRC);
307 push16(UXN_SRC, mempeek16(u->ram.dat, a));
308} break;
309case UXN_OPC(0x35): { // sta
310 UXN_KEEP_SYNC;
311 Uint16 a = pop16(UXN_SRC);
312 Uint16 b = pop16(UXN_SRC);
313 mempoke16(u->ram.dat, a, b);
314} break;
315case UXN_OPC(0x36): { // dei
316 UXN_KEEP_SYNC;
317 Uint8 a = pop8(UXN_SRC);
318 push16(UXN_SRC, devpeek16(&u->dev[a >> 4], a));
319} break;
320case UXN_OPC(0x37): { // deo
321 UXN_KEEP_SYNC;
322 Uint8 a = pop8(UXN_SRC);
323 Uint16 b = pop16(UXN_SRC);
324 devpoke16(&u->dev[a >> 4], a, b);
325} break;
326case UXN_OPC(0x38): { // add
327 UXN_KEEP_SYNC;
328 Uint16 a = pop16(UXN_SRC);
329 Uint16 b = pop16(UXN_SRC);
330 push16(UXN_SRC, b + a);
331} break;
332case UXN_OPC(0x39): { // sub
333 UXN_KEEP_SYNC;
334 Uint16 a = pop16(UXN_SRC);
335 Uint16 b = pop16(UXN_SRC);
336 push16(UXN_SRC, b - a);
337} break;
338case UXN_OPC(0x3A): { // mul
339 UXN_KEEP_SYNC;
340 Uint16 a = pop16(UXN_SRC);
341 Uint16 b = pop16(UXN_SRC);
342 push16(UXN_SRC, b * a);
343} break;
344case UXN_OPC(0x3B): { // div
345 UXN_KEEP_SYNC;
346 Uint16 a = pop16(UXN_SRC);
347 Uint16 b = pop16(UXN_SRC);
348 push16(UXN_SRC, b / a);
349} break;
350case UXN_OPC(0x3C): { // and
351 UXN_KEEP_SYNC;
352 Uint16 a = pop16(UXN_SRC);
353 Uint16 b = pop16(UXN_SRC);
354 push16(UXN_SRC, b & a);
355} break;
356case UXN_OPC(0x3D): { // ora
357 UXN_KEEP_SYNC;
358 Uint16 a = pop16(UXN_SRC);
359 Uint16 b = pop16(UXN_SRC);
360 push16(UXN_SRC, b | a);
361} break;
362case UXN_OPC(0x3E): { // eor
363 UXN_KEEP_SYNC;
364 Uint16 a = pop16(UXN_SRC);
365 Uint16 b = pop16(UXN_SRC);
366 push16(UXN_SRC, b ^ a);
367} break;
368case UXN_OPC(0x3F): { // sft
369 UXN_KEEP_SYNC;
370 Uint16 a = pop16(UXN_SRC);
371 Uint16 b = pop16(UXN_SRC);
372 push16(UXN_SRC, b >> (a & 0x000f) << ((a & 0x00f0) >> 4));
373} break;