commit ddc7e08
zzo38
·
2023-10-30 02:05:32 +0000 UTC
parent 482fabd
Make the changes according to the newest specification of uxn/varvara.
3 files changed,
+15,
-20
M
main.c
+7,
-10
1@@ -1,5 +1,5 @@
2 #if 0
3-gcc -s -O2 -Wno-unused-result main.c `sdl-config --cflags --libs`
4+gcc -s -O2 -Wno-unused-result -fwrapv main.c `sdl-config --cflags --libs`
5 exit
6 #endif
7
8@@ -279,11 +279,11 @@ static void uxnerr(int n,int pc) {
9 errx(2,"Uxn error %d at 0x%04X",n,pc);
10 }
11
12-#define Push8(z) ({ if(s->p>254) {v=2; goto error;} s->d[s->p++]=(z); })
13-#define Push16(z) ({ if(s->p>253) {v=2; goto error;} s->d[s->p++]=(z)>>8; s->d[s->p++]=(z); })
14-#define Push(z) ({ if(s->p>(v&0x20?253:254)) {v=2; goto error;} if(v&0x20) s->d[s->p++]=(z)>>8; s->d[s->p++]=(z); })
15-#define Pop8(z) ({ if(!k) {v=1; goto error;} z=s->d[--k]; if(v<0x80) s->p=k; })
16-#define Pop16(z) ({ if(k<2) {v=1; goto error;} z=s->d[--k]; z|=s->d[--k]<<8; if(v<0x80) s->p=k; })
17+#define Push8(z) ({ s->d[s->p++]=(z); })
18+#define Push16(z) ({ s->d[s->p++]=(z)>>8; s->d[s->p++]=(z); })
19+#define Push(z) ({ if(v&0x20) s->d[s->p++]=(z)>>8; s->d[s->p++]=(z); })
20+#define Pop8(z) ({ z=s->d[0xFF&--k]; if(v<0x80) s->p=k; })
21+#define Pop16(z) ({ z=s->d[0xFF&--k]; z|=s->d[0xFF&--k]<<8; if(v<0x80) s->p=k; })
22 #define Pop(z) ({ if(v&0x20) Pop16(z); else Pop8(z); })
23
24 static void run(Uint16 pc) {
25@@ -341,7 +341,7 @@ static void run(Uint16 pc) {
26 case 0x18: Pop(x); Pop(y); Push(y+x); break;
27 case 0x19: Pop(x); Pop(y); Push(y-x); break;
28 case 0x1A: Pop(x); Pop(y); Push(y*x); break;
29- case 0x1B: Pop(x); Pop(y); if(!x) {v=3; goto error;} Push(y/x); break;
30+ case 0x1B: Pop(x); Pop(y); Push(x?y/x:0); break;
31 case 0x1C: Pop(x); Pop(y); Push(y&x); break;
32 case 0x1D: Pop(x); Pop(y); Push(y|x); break;
33 case 0x1E: Pop(x); Pop(y); Push(y^x); break;
34@@ -368,9 +368,6 @@ static void run(Uint16 pc) {
35 break_pc=pc-1;
36 }
37 fflush(outf);
38- return;
39- error:
40- uxnerr(v,pc);
41 }
42
43 static void load_rom(void) {
M
uxn.doc
+4,
-8
1@@ -14,7 +14,8 @@ there are no arithmetic overflow errors.
2 === Stacks ===
3
4 There are two stacks, which are the data stack and return stack. Each
5-stack can store at least 254 bytes of data.
6+stack stores 256 bytes of data, and is circular (so stack underflows and
7+stack overflows are impossible).
8
9 If a 16-bit value is in the stack, then the top will be the low 8-bits
10 of that value and beneath that will be the high 8-bits of that value.
11@@ -103,7 +104,8 @@ but if 8-bits then it is a signed relative address.
12 1A MUL ( a b -- c )
13 Multiplication.
14 1B DIV ( a b -- c )
15- Division. (Division by zero is an error.)
16+ Division (a by b). If you try to divide by zero, then the result will be
17+ zero (in previous versions of this specification it was an error).
18 1C AND ( a b -- c )
19 Bitwise AND.
20 1D ORA ( a b -- c )
21@@ -134,12 +136,6 @@ address immediately after, the two bytes giving the address, modulo 65536.
22 Unconditionally jump to a relative address, but also push the return
23 address to the return stack.
24
25-(There is some discussion about possibility of changing a few of the
26-instructions in future; the changed instructions will be: POPk, POP2k,
27-POPrk, POP2rk, NIPk, NIP2k, NIPrk, NIP2rk. So, these instructions should
28-not be used at this time in published programs, until this discussion of
29-these changes is concluded.)
30-
31
32 === Execution ===
33
+4,
-2
1@@ -1,4 +1,4 @@
2-This document describes the devices of Uxn virtual machine.
3+This document describes the devices of Uxn/Varvara virtual machine.
4
5 The high nybble of the port number selects one of the following devices:
6 0 = System
7@@ -37,7 +37,9 @@ In the below lists, asterisks indicate 16-bit ports.
8 0E = Debug
9 0F = Quit
10
11-Some implementations call the system vector if an error occurs.
12+The vector is unused. (In previous versions of this specification, the
13+vector was used to signal errors, but no error conditions are possible in
14+the current version of this specification.)
15
16 Writing an address to the expansion port will execute an expansion
17 operation, which is a record stored at that address; the first byte of