aboutsummaryrefslogtreecommitdiffstats
path: root/src/uxn/opcodes.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/uxn/opcodes.c')
-rw-r--r--src/uxn/opcodes.c315
1 files changed, 0 insertions, 315 deletions
diff --git a/src/uxn/opcodes.c b/src/uxn/opcodes.c
deleted file mode 100644
index f80cd79..0000000
--- a/src/uxn/opcodes.c
+++ /dev/null
@@ -1,315 +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(u->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 pop8(u->src);
27} break;
28case UXN_OPC(0x04): { // dup
29 Uint8 a = pop8(u->src);
30 push8(u->src, a);
31 push8(u->src, a);
32} break;
33case UXN_OPC(0x05): { // swp
34 Uint8 a = pop8(u->src);
35 Uint8 b = pop8(u->src);
36 push8(u->src, a);
37 push8(u->src, b);
38} break;
39case UXN_OPC(0x06): { // ovr
40 Uint8 a = pop8(u->src);
41 Uint8 b = pop8(u->src);
42 push8(u->src, b);
43 push8(u->src, a);
44 push8(u->src, b);
45} break;
46case UXN_OPC(0x07): { // rot
47 Uint8 a = pop8(u->src);
48 Uint8 b = pop8(u->src);
49 Uint8 c = pop8(u->src);
50 push8(u->src, b);
51 push8(u->src, a);
52 push8(u->src, c);
53} break;
54case UXN_OPC(0x08): { // equ
55 Uint8 a = pop8(u->src);
56 Uint8 b = pop8(u->src);
57 push8(u->src, b == a);
58} break;
59case UXN_OPC(0x09): { // neg
60 Uint8 a = pop8(u->src);
61 Uint8 b = pop8(u->src);
62 push8(u->src, b != a);
63} break;
64case UXN_OPC(0x0A): { // gth
65 Uint8 a = pop8(u->src);
66 Uint8 b = pop8(u->src);
67 push8(u->src, b > a);
68} break;
69case UXN_OPC(0x0B): { // lth
70 Uint8 a = pop8(u->src);
71 Uint8 b = pop8(u->src);
72 push8(u->src, b < a);
73} break;
74case UXN_OPC(0x0C): { // jmp
75 Uint8 a = pop8(u->src);
76 u->ram.ptr += (Sint8)a;
77} break;
78case UXN_OPC(0x0D): { // jnz
79 Uint8 a = pop8(u->src);
80 if (pop8(u->src))
81 u->ram.ptr += (Sint8)a;
82} break;
83case UXN_OPC(0x0E): { // jsr
84 Uint8 a = pop8(u->src);
85 push16(u->dst, u->ram.ptr);
86 u->ram.ptr += (Sint8)a;
87} break;
88case UXN_OPC(0x0F): { // sth
89 Uint8 a = pop8(u->src);
90 push8(u->dst, a);
91} break;
92case UXN_OPC(0x10): { // pek
93 Uint8 a = pop8(u->src);
94 push8(u->src, mempeek8(u->ram.dat, a));
95} break;
96case UXN_OPC(0x11): { // pok
97 Uint8 a = pop8(u->src);
98 Uint8 b = pop8(u->src);
99 mempoke8(u->ram.dat, a, b);
100} break;
101case UXN_OPC(0x12): { // ldr
102 Uint8 a = pop8(u->src);
103 push8(u->src, mempeek8(u->ram.dat, u->ram.ptr + (Sint8)a));
104} break;
105case UXN_OPC(0x13): { // str
106 Uint8 a = pop8(u->src);
107 Uint8 b = pop8(u->src);
108 mempoke8(u->ram.dat, u->ram.ptr + (Sint8)a, b);
109} break;
110case UXN_OPC(0x14): { // lda
111 Uint16 a = pop16(u->src);
112 push8(u->src, mempeek8(u->ram.dat, a));
113} break;
114case UXN_OPC(0x15): { // sta
115 Uint16 a = pop16(u->src);
116 Uint8 b = pop8(u->src);
117 mempoke8(u->ram.dat, a, b);
118} break;
119case UXN_OPC(0x16): { // dei
120 Uint8 a = pop8(u->src);
121 push8(u->src, devpeek8(&u->dev[a >> 4], a));
122} break;
123case UXN_OPC(0x17): { // deo
124 Uint8 a = pop8(u->src);
125 Uint8 b = pop8(u->src);
126 devpoke8(&u->dev[a >> 4], a, b);
127} break;
128case UXN_OPC(0x18): { // add
129 Uint8 a = pop8(u->src);
130 Uint8 b = pop8(u->src);
131 push8(u->src, b + a);
132} break;
133case UXN_OPC(0x19): { // sub
134 Uint8 a = pop8(u->src);
135 Uint8 b = pop8(u->src);
136 push8(u->src, b - a);
137} break;
138case UXN_OPC(0x1A): { // mul
139 Uint8 a = pop8(u->src);
140 Uint8 b = pop8(u->src);
141 push8(u->src, b * a);
142} break;
143case UXN_OPC(0x1B): { // div
144 Uint8 a = pop8(u->src);
145 Uint8 b = pop8(u->src);
146 push8(u->src, b / a);
147} break;
148case UXN_OPC(0x1C): { // and
149 Uint8 a = pop8(u->src);
150 Uint8 b = pop8(u->src);
151 push8(u->src, b & a);
152} break;
153case UXN_OPC(0x1D): { // ora
154 Uint8 a = pop8(u->src);
155 Uint8 b = pop8(u->src);
156 push8(u->src, b | a);
157} break;
158case UXN_OPC(0x1E): { // eor
159 Uint8 a = pop8(u->src);
160 Uint8 b = pop8(u->src);
161 push8(u->src, b ^ a);
162} break;
163case UXN_OPC(0x1F): { // sft
164 Uint8 a = pop8(u->src);
165 Uint8 b = pop8(u->src);
166 push8(u->src, b >> (a & 0x07) << ((a & 0x70) >> 4));
167} break;
168
169/* 16-BIT OPCODES */
170
171case UXN_OPC(0x21): { // lit
172 push16(u->src, mempeek16_i(u->ram.dat, u->ram.ptr));
173 u->ram.ptr += 2;
174} break;
175case UXN_OPC(0x23): { // pop
176 pop16(u->src);
177} break;
178case UXN_OPC(0x24): { // dup
179 Uint16 a = pop16(u->src);
180 push16(u->src, a);
181 push16(u->src, a);
182} break;
183case UXN_OPC(0x25): { // swp
184 Uint16 a = pop16(u->src);
185 Uint16 b = pop16(u->src);
186 push16(u->src, a);
187 push16(u->src, b);
188} break;
189case UXN_OPC(0x26): { // ovr
190 Uint16 a = pop16(u->src);
191 Uint16 b = pop16(u->src);
192 push16(u->src, b);
193 push16(u->src, a);
194 push16(u->src, b);
195} break;
196case UXN_OPC(0x27): { // rot
197 Uint16 a = pop16(u->src);
198 Uint16 b = pop16(u->src);
199 Uint16 c = pop16(u->src);
200 push16(u->src, b);
201 push16(u->src, a);
202 push16(u->src, c);
203} break;
204case UXN_OPC(0x28): { // equ
205 Uint16 a = pop16(u->src);
206 Uint16 b = pop16(u->src);
207 push8(u->src, b == a);
208} break;
209case UXN_OPC(0x29): { // neg
210 Uint16 a = pop16(u->src);
211 Uint16 b = pop16(u->src);
212 push8(u->src, b != a);
213} break;
214case UXN_OPC(0x2A): { // gth
215 Uint16 a = pop16(u->src);
216 Uint16 b = pop16(u->src);
217 push8(u->src, b > a);
218} break;
219case UXN_OPC(0x2B): { // lth
220 Uint16 a = pop16(u->src);
221 Uint16 b = pop16(u->src);
222 push8(u->src, b < a);
223} break;
224case UXN_OPC(0x2C): { // jmp
225 u->ram.ptr = pop16(u->src);
226} break;
227case UXN_OPC(0x2D): { // jnz
228 Uint16 a = pop16(u->src);
229 if (pop8(u->src))
230 u->ram.ptr = a;
231} break;
232case UXN_OPC(0x2E): { // jsr
233 push16(u->dst, u->ram.ptr);
234 u->ram.ptr = pop16(u->src);
235} break;
236case UXN_OPC(0x2F): { // sth
237 Uint16 a = pop16(u->src);
238 push16(u->dst, a);
239} break;
240case UXN_OPC(0x30): { // pek
241 Uint8 a = pop8(u->src);
242 push16(u->src, mempeek16_i(u->ram.dat, a));
243} break;
244case UXN_OPC(0x31): { // pok
245 Uint8 a = pop8(u->src);
246 Uint16 b = pop16(u->src);
247 mempoke16_i(u->ram.dat, a, b);
248} break;
249case UXN_OPC(0x32): { // ldr
250 Uint8 a = pop8(u->src);
251 push16(u->src, mempeek16_i(u->ram.dat, u->ram.ptr + (Sint8)a));
252} break;
253case UXN_OPC(0x33): { // str
254 Uint8 a = pop8(u->src);
255 Uint16 b = pop16(u->src);
256 mempoke16_i(u->ram.dat, u->ram.ptr + (Sint8)a, b);
257} break;
258case UXN_OPC(0x34): { // lda
259 Uint16 a = pop16(u->src);
260 push16(u->src, mempeek16_i(u->ram.dat, a));
261} break;
262case UXN_OPC(0x35): { // sta
263 Uint16 a = pop16(u->src);
264 Uint16 b = pop16(u->src);
265 mempoke16_i(u->ram.dat, a, b);
266} break;
267case UXN_OPC(0x36): { // dei
268 Uint8 a = pop8(u->src);
269 push16(u->src, devpeek16(&u->dev[a >> 4], a));
270} break;
271case UXN_OPC(0x37): { // deo
272 Uint8 a = pop8(u->src);
273 Uint16 b = pop16(u->src);
274 devpoke16(&u->dev[a >> 4], a, b);
275} break;
276case UXN_OPC(0x38): { // add
277 Uint16 a = pop16(u->src);
278 Uint16 b = pop16(u->src);
279 push16(u->src, b + a);
280} break;
281case UXN_OPC(0x39): { // sub
282 Uint16 a = pop16(u->src);
283 Uint16 b = pop16(u->src);
284 push16(u->src, b - a);
285} break;
286case UXN_OPC(0x3A): { // mul
287 Uint16 a = pop16(u->src);
288 Uint16 b = pop16(u->src);
289 push16(u->src, b * a);
290} break;
291case UXN_OPC(0x3B): { // div
292 Uint16 a = pop16(u->src);
293 Uint16 b = pop16(u->src);
294 push16(u->src, b / a);
295} break;
296case UXN_OPC(0x3C): { // and
297 Uint16 a = pop16(u->src);
298 Uint16 b = pop16(u->src);
299 push16(u->src, b & a);
300} break;
301case UXN_OPC(0x3D): { // ora
302 Uint16 a = pop16(u->src);
303 Uint16 b = pop16(u->src);
304 push16(u->src, b | a);
305} break;
306case UXN_OPC(0x3E): { // eor
307 Uint16 a = pop16(u->src);
308 Uint16 b = pop16(u->src);
309 push16(u->src, b ^ a);
310} break;
311case UXN_OPC(0x3F): { // sft
312 Uint16 a = pop16(u->src);
313 Uint16 b = pop16(u->src);
314 push16(u->src, b >> (a & 0x000f) << ((a & 0x00f0) >> 4));
315} break;