commit f7580ca
Devine Lu Linvega
·
2025-04-19 17:59:32 +0000 UTC
parent d953f95
Removed old core
+1,
-1
1@@ -1,6 +1,6 @@
2 # Uxn11
3
4-An emulator for the [Uxn stack-machine](https://wiki.xxiivv.com/site/uxn.html), written in ANSI C. The emulator contains a few linux specific utilities in the Console device to allow for it to interface with the unix systems.
5+An emulator for the [Uxn CPU](https://wiki.xxiivv.com/site/uxn.html) and [Varvara Computer](https://wiki.xxiivv.com/site/varvara.html), written in ANSI C. The emulator contains a few linux specific utilities in the Console device to allow for it to interface with the unix systems.
6
7 ## Building
8
+0,
-94
1@@ -1,94 +0,0 @@
2-#include "uxn.h"
3-
4-/*
5-Copyright (u) 2022-2024 Devine Lu Linvega, Andrew Alderwick, Andrew Richards
6-
7-Permission to use, copy, modify, and distribute this software for any
8-purpose with or without fee is hereby granted, provided that the above
9-copyright notice and this permission notice appear in all copies.
10-
11-THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12-WITH REGARD TO THIS SOFTWARE.
13-*/
14-
15-#define OPC(opc, init, body) {\
16- case 0x00|opc: {const int _2=0,_r=0;init body;} break;\
17- case 0x20|opc: {const int _2=1,_r=0;init body;} break;\
18- case 0x40|opc: {const int _2=0,_r=1;init body;} break;\
19- case 0x60|opc: {const int _2=1,_r=1;init body;} break;\
20- case 0x80|opc: {const int _2=0,_r=0,k=uxn.wst.ptr;init uxn.wst.ptr=k;body;} break;\
21- case 0xa0|opc: {const int _2=1,_r=0,k=uxn.wst.ptr;init uxn.wst.ptr=k;body;} break;\
22- case 0xc0|opc: {const int _2=0,_r=1,k=uxn.rst.ptr;init uxn.rst.ptr=k;body;} break;\
23- case 0xe0|opc: {const int _2=1,_r=1,k=uxn.rst.ptr;init uxn.rst.ptr=k;body;} break;\
24-}
25-
26-/* Microcode */
27-
28-#define JMI a = uxn.ram[pc] << 8 | uxn.ram[pc + 1], pc += a + 2;
29-#define REM if(_r) uxn.rst.ptr -= 1 + _2; else uxn.wst.ptr -= 1 + _2;
30-#define INC(s) uxn.s.dat[uxn.s.ptr++]
31-#define DEC(s) uxn.s.dat[--uxn.s.ptr]
32-#define JMP(x) { if(_2) pc = x; else pc += (Sint8)x; }
33-#define PO1(o) { o = _r ? DEC(rst) : DEC(wst);}
34-#define PO2(o) { if(_r) o = DEC(rst), o |= DEC(rst) << 8; else o = DEC(wst), o |= DEC(wst) << 8; }
35-#define POx(o) { if(_2) PO2(o) else PO1(o) }
36-#define PU1(i) { if(_r) INC(rst) = i; else INC(wst) = i; }
37-#define RP1(i) { if(_r) INC(wst) = i; else INC(rst) = i; }
38-#define PUx(i) { if(_2) { c = (i); PU1(c >> 8) PU1(c) } else PU1(i) }
39-#define GET(o) { if(_2) PO1(o[1]) PO1(o[0]) }
40-#define PUT(i) { PU1(i[0]) if(_2) PU1(i[1]) }
41-#define DEI(i,o) o[0] = emu_dei(i); if(_2) o[1] = emu_dei(i + 1); PUT(o)
42-#define DEO(i,j) emu_deo(i, j[0]); if(_2) emu_deo(i + 1, j[1]);
43-#define PEK(i,o,m) o[0] = uxn.ram[i]; if(_2) o[1] = uxn.ram[(i + 1) & m]; PUT(o)
44-#define POK(i,j,m) uxn.ram[i] = j[0]; if(_2) uxn.ram[(i + 1) & m] = j[1];
45-
46-int
47-uxn_eval(Uint16 pc)
48-{
49- unsigned int a, b, c, x[2], y[2], z[2], step;
50- if(!pc || uxn.dev[0x0f]) return 0;
51- for(step = STEP_MAX; step; step--) {
52- switch(uxn.ram[pc++]) {
53- /* BRK */ case 0x00: return 1;
54- /* JCI */ case 0x20: if(DEC(wst)) { JMI break; } pc += 2; break;
55- /* JMI */ case 0x40: JMI break;
56- /* JSI */ case 0x60: c = pc + 2; INC(rst) = c >> 8; INC(rst) = c; JMI break;
57- /* LI2 */ case 0xa0: INC(wst) = uxn.ram[pc++]; /* fall-through */
58- /* LIT */ case 0x80: INC(wst) = uxn.ram[pc++]; break;
59- /* L2r */ case 0xe0: INC(rst) = uxn.ram[pc++]; /* fall-through */
60- /* LIr */ case 0xc0: INC(rst) = uxn.ram[pc++]; break;
61- /* INC */ OPC(0x01,POx(a),PUx(a + 1))
62- /* POP */ OPC(0x02,REM ,{})
63- /* NIP */ OPC(0x03,GET(x) REM ,PUT(x))
64- /* SWP */ OPC(0x04,GET(x) GET(y),PUT(x) PUT(y))
65- /* ROT */ OPC(0x05,GET(x) GET(y) GET(z),PUT(y) PUT(x) PUT(z))
66- /* DUP */ OPC(0x06,GET(x),PUT(x) PUT(x))
67- /* OVR */ OPC(0x07,GET(x) GET(y),PUT(y) PUT(x) PUT(y))
68- /* EQU */ OPC(0x08,POx(a) POx(b),PU1(b == a))
69- /* NEQ */ OPC(0x09,POx(a) POx(b),PU1(b != a))
70- /* GTH */ OPC(0x0a,POx(a) POx(b),PU1(b > a))
71- /* LTH */ OPC(0x0b,POx(a) POx(b),PU1(b < a))
72- /* JMP */ OPC(0x0c,POx(a),JMP(a))
73- /* JCN */ OPC(0x0d,POx(a) PO1(b),if(b) JMP(a))
74- /* JSR */ OPC(0x0e,POx(a),RP1(pc >> 8) RP1(pc) JMP(a))
75- /* STH */ OPC(0x0f,GET(x),RP1(x[0]) if(_2) RP1(x[1]))
76- /* LDZ */ OPC(0x10,PO1(a),PEK(a, x, 0xff))
77- /* STZ */ OPC(0x11,PO1(a) GET(y),POK(a, y, 0xff))
78- /* LDR */ OPC(0x12,PO1(a),PEK(pc + (Sint8)a, x, 0xffff))
79- /* STR */ OPC(0x13,PO1(a) GET(y),POK(pc + (Sint8)a, y, 0xffff))
80- /* LDA */ OPC(0x14,PO2(a),PEK(a, x, 0xffff))
81- /* STA */ OPC(0x15,PO2(a) GET(y),POK(a, y, 0xffff))
82- /* DEI */ OPC(0x16,PO1(a),DEI(a, x))
83- /* DEO */ OPC(0x17,PO1(a) GET(y),DEO(a, y))
84- /* ADD */ OPC(0x18,POx(a) POx(b),PUx(b + a))
85- /* SUB */ OPC(0x19,POx(a) POx(b),PUx(b - a))
86- /* MUL */ OPC(0x1a,POx(a) POx(b),PUx(b * a))
87- /* DIV */ OPC(0x1b,POx(a) POx(b),PUx(a ? b / a : 0))
88- /* AND */ OPC(0x1c,POx(a) POx(b),PUx(b & a))
89- /* ORA */ OPC(0x1d,POx(a) POx(b),PUx(b | a))
90- /* EOR */ OPC(0x1e,POx(a) POx(b),PUx(b ^ a))
91- /* SFT */ OPC(0x1f,PO1(a) POx(b),PUx(b >> (a & 0xf) << (a >> 4)))
92- }
93- }
94- return 0;
95-}