Browse code

Reverted "Removed OVR opcode and replaced with NIP" and uxn-fast.c update.

This reverts commits 1afe39fba4a0fdba16b6e561b3fb4b38578ccbb1 and 3d3569bab7a65e581fb5d9e108be4355826daf31.

Andrew Alderwick authored on 15/08/2021 20:06:54
Showing 4 changed files
... ...
@@ -6,8 +6,7 @@
6 6
 %<< { LTH2 } %>> { GTH2 } %== { EQU2 } %!! { NEQ2 }
7 7
 
8 8
 %RTN  { JMP2r }
9
-%OVR  { NIPk } %OVR2  { NIP2k }
10
-%TOS  { #00 SWP } 
9
+%TOS  { #00 SWP } %TOB { SWP POP }
11 10
 %MOD  { DUP2 / * - }
12 11
 %LTS2 { #8000 ++ SWP2 #8000 ++ >> }
13 12
 %GTS2 { #8000 ++ SWP2 #8000 ++ << }
... ...
@@ -184,8 +183,8 @@ BRK
184 183
 
185 184
 @on-touch-octave-view ( -> )
186 185
 
187
-	.Mouse/x DEI2 .octave-view/x1 LDZ2 -- 8// NIP #09 ! ,&no-mod JCN
188
-		.Mouse/y DEI2 .octave-view/y1 LDZ2 -- 8// NIP 
186
+	.Mouse/x DEI2 .octave-view/x1 LDZ2 -- 8// TOB #09 ! ,&no-mod JCN
187
+		.Mouse/y DEI2 .octave-view/y1 LDZ2 -- 8// TOB 
189 188
 		DUP #00 ! ,&no-incr JCN
190 189
 			.octave LDZ #03 = ,&no-incr JCN
191 190
 			.octave LDZ #01 + .octave STZ &no-incr
... ...
@@ -198,7 +197,7 @@ BRK
198 197
 		BRK
199 198
 	&no-mod
200 199
 
201
-	.Mouse/x DEI2 .octave-view/x1 LDZ2 -- 8// NIP #06 > ,&no-key JCN
200
+	.Mouse/x DEI2 .octave-view/x1 LDZ2 -- 8// TOB #06 > ,&no-key JCN
202 201
 		.Mouse/x DEI2 .octave-view/x1 LDZ2 -- 8// ;notes ++ LDA .octave LDZ #0c * + ;play JSR2
203 202
 		( release ) #00 .Mouse/state DEO
204 203
 		;draw-octave JSR2
... ...
@@ -208,7 +207,7 @@ BRK
208 207
 
209 208
 @on-touch-adsr-view ( -> )
210 209
 
211
-	.Mouse/x DEI2 .adsr-view/x1 LDZ2 -- 8// NIP #03 /
210
+	.Mouse/x DEI2 .adsr-view/x1 LDZ2 -- 8// TOB #03 /
212 211
 	DUP #00 ! ,&no-a JCN
213 212
 		.Audio0/adsr DEI
214 213
 		#10 .Mouse/state DEI #10 = #e0 * + +
... ...
@@ -358,7 +357,7 @@ RTN
358 357
 		TOS 4// .wave-view/y1 LDZ2 ++ .Screen/y DEO2
359 358
 		.Screen/x DEI2 #0001 ++ .Screen/x DEO2
360 359
 		( draw ) DUP 
361
-			.Audio0/length DEI2 NIP > 
360
+			.Audio0/length DEI2 TOB > 
362 361
 			.Audio0/length DEI2 #0100 !! #0101 == #02 * #01 + .Screen/pixel DEO
363 362
 		#01 + GTHk ,&loop JCN
364 363
 	POP2
... ...
@@ -139,19 +139,22 @@ uxn_eval(Uxn *u, Uint16 vec)
139 139
 #endif
140 140
 			}
141 141
 			break;
142
-		case 0x06: /* NIP */
143
-			__asm__("evaluxn_06_NIP:");
142
+		case 0x06: /* OVR */
143
+			__asm__("evaluxn_06_OVR:");
144 144
 			{
145
-				Uint8 a;
146
-				u->wst.dat[u->wst.ptr - 1];
147
-				a = u->wst.dat[u->wst.ptr - 2];
145
+				Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2];
146
+				u->wst.dat[u->wst.ptr] = b;
148 147
 #ifndef NO_STACK_CHECKS
149 148
 				if(__builtin_expect(u->wst.ptr < 2, 0)) {
150 149
 					u->wst.error = 1;
151 150
 					goto error;
152 151
 				}
152
+				if(__builtin_expect(u->wst.ptr > 254, 0)) {
153
+					u->wst.error = 2;
154
+					goto error;
155
+				}
153 156
 #endif
154
-				u->wst.ptr -= 1;
157
+				u->wst.ptr += 1;
155 158
 			}
156 159
 			break;
157 160
 		case 0x07: /* ROT */
... ...
@@ -591,21 +594,23 @@ uxn_eval(Uxn *u, Uint16 vec)
591 594
 #endif
592 595
 			}
593 596
 			break;
594
-		case 0x26: /* NIP2 */
595
-			__asm__("evaluxn_26_NIP2:");
597
+		case 0x26: /* OVR2 */
598
+			__asm__("evaluxn_26_OVR2:");
596 599
 			{
597
-				Uint16 a;
598
-				(u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8));
599
-				a = (u->wst.dat[u->wst.ptr - 3] | (u->wst.dat[u->wst.ptr - 4] << 8));
600
-				u->wst.dat[u->wst.ptr - 4] = a >> 8;
601
-				u->wst.dat[u->wst.ptr - 3] = a & 0xff;
600
+				Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2], c = u->wst.dat[u->wst.ptr - 3], d = u->wst.dat[u->wst.ptr - 4];
601
+				u->wst.dat[u->wst.ptr] = d;
602
+				u->wst.dat[u->wst.ptr + 1] = c;
602 603
 #ifndef NO_STACK_CHECKS
603 604
 				if(__builtin_expect(u->wst.ptr < 4, 0)) {
604 605
 					u->wst.error = 1;
605 606
 					goto error;
606 607
 				}
608
+				if(__builtin_expect(u->wst.ptr > 253, 0)) {
609
+					u->wst.error = 2;
610
+					goto error;
611
+				}
607 612
 #endif
608
-				u->wst.ptr -= 2;
613
+				u->wst.ptr += 2;
609 614
 			}
610 615
 			break;
611 616
 		case 0x27: /* ROT2 */
... ...
@@ -1071,19 +1076,22 @@ uxn_eval(Uxn *u, Uint16 vec)
1071 1076
 #endif
1072 1077
 			}
1073 1078
 			break;
1074
-		case 0x46: /* NIPr */
1075
-			__asm__("evaluxn_46_NIPr:");
1079
+		case 0x46: /* OVRr */
1080
+			__asm__("evaluxn_46_OVRr:");
1076 1081
 			{
1077
-				Uint8 a;
1078
-				u->rst.dat[u->rst.ptr - 1];
1079
-				a = u->rst.dat[u->rst.ptr - 2];
1082
+				Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2];
1083
+				u->rst.dat[u->rst.ptr] = b;
1080 1084
 #ifndef NO_STACK_CHECKS
1081 1085
 				if(__builtin_expect(u->rst.ptr < 2, 0)) {
1082 1086
 					u->rst.error = 1;
1083 1087
 					goto error;
1084 1088
 				}
1089
+				if(__builtin_expect(u->rst.ptr > 254, 0)) {
1090
+					u->rst.error = 2;
1091
+					goto error;
1092
+				}
1085 1093
 #endif
1086
-				u->rst.ptr -= 1;
1094
+				u->rst.ptr += 1;
1087 1095
 			}
1088 1096
 			break;
1089 1097
 		case 0x47: /* ROTr */
... ...
@@ -1523,21 +1531,23 @@ uxn_eval(Uxn *u, Uint16 vec)
1523 1531
 #endif
1524 1532
 			}
1525 1533
 			break;
1526
-		case 0x66: /* NIP2r */
1527
-			__asm__("evaluxn_66_NIP2r:");
1534
+		case 0x66: /* OVR2r */
1535
+			__asm__("evaluxn_66_OVR2r:");
1528 1536
 			{
1529
-				Uint16 a;
1530
-				(u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8));
1531
-				a = (u->rst.dat[u->rst.ptr - 3] | (u->rst.dat[u->rst.ptr - 4] << 8));
1532
-				u->rst.dat[u->rst.ptr - 4] = a >> 8;
1533
-				u->rst.dat[u->rst.ptr - 3] = a & 0xff;
1537
+				Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2], c = u->rst.dat[u->rst.ptr - 3], d = u->rst.dat[u->rst.ptr - 4];
1538
+				u->rst.dat[u->rst.ptr] = d;
1539
+				u->rst.dat[u->rst.ptr + 1] = c;
1534 1540
 #ifndef NO_STACK_CHECKS
1535 1541
 				if(__builtin_expect(u->rst.ptr < 4, 0)) {
1536 1542
 					u->rst.error = 1;
1537 1543
 					goto error;
1538 1544
 				}
1545
+				if(__builtin_expect(u->rst.ptr > 253, 0)) {
1546
+					u->rst.error = 2;
1547
+					goto error;
1548
+				}
1539 1549
 #endif
1540
-				u->rst.ptr -= 2;
1550
+				u->rst.ptr += 2;
1541 1551
 			}
1542 1552
 			break;
1543 1553
 		case 0x67: /* ROT2r */
... ...
@@ -1994,24 +2004,24 @@ uxn_eval(Uxn *u, Uint16 vec)
1994 2004
 				u->wst.ptr += 2;
1995 2005
 			}
1996 2006
 			break;
1997
-		case 0x86: /* NIPk */
1998
-			__asm__("evaluxn_86_NIPk:");
2007
+		case 0x86: /* OVRk */
2008
+			__asm__("evaluxn_86_OVRk:");
1999 2009
 			{
2000
-				Uint8 a;
2001
-				u->wst.dat[u->wst.ptr - 1];
2002
-				a = u->wst.dat[u->wst.ptr - 2];
2003
-				u->wst.dat[u->wst.ptr] = a;
2010
+				Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2];
2011
+				u->wst.dat[u->wst.ptr] = b;
2012
+				u->wst.dat[u->wst.ptr + 1] = a;
2013
+				u->wst.dat[u->wst.ptr + 2] = b;
2004 2014
 #ifndef NO_STACK_CHECKS
2005 2015
 				if(__builtin_expect(u->wst.ptr < 2, 0)) {
2006 2016
 					u->wst.error = 1;
2007 2017
 					goto error;
2008 2018
 				}
2009
-				if(__builtin_expect(u->wst.ptr > 254, 0)) {
2019
+				if(__builtin_expect(u->wst.ptr > 252, 0)) {
2010 2020
 					u->wst.error = 2;
2011 2021
 					goto error;
2012 2022
 				}
2013 2023
 #endif
2014
-				u->wst.ptr += 1;
2024
+				u->wst.ptr += 3;
2015 2025
 			}
2016 2026
 			break;
2017 2027
 		case 0x87: /* ROTk */
... ...
@@ -2502,25 +2512,27 @@ uxn_eval(Uxn *u, Uint16 vec)
2502 2512
 				u->wst.ptr += 4;
2503 2513
 			}
2504 2514
 			break;
2505
-		case 0xa6: /* NIP2k */
2506
-			__asm__("evaluxn_a6_NIP2k:");
2515
+		case 0xa6: /* OVR2k */
2516
+			__asm__("evaluxn_a6_OVR2k:");
2507 2517
 			{
2508
-				Uint16 a;
2509
-				(u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8));
2510
-				a = (u->wst.dat[u->wst.ptr - 3] | (u->wst.dat[u->wst.ptr - 4] << 8));
2511
-				u->wst.dat[u->wst.ptr] = a >> 8;
2512
-				u->wst.dat[u->wst.ptr + 1] = a & 0xff;
2518
+				Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2], c = u->wst.dat[u->wst.ptr - 3], d = u->wst.dat[u->wst.ptr - 4];
2519
+				u->wst.dat[u->wst.ptr] = d;
2520
+				u->wst.dat[u->wst.ptr + 1] = c;
2521
+				u->wst.dat[u->wst.ptr + 2] = b;
2522
+				u->wst.dat[u->wst.ptr + 3] = a;
2523
+				u->wst.dat[u->wst.ptr + 4] = d;
2524
+				u->wst.dat[u->wst.ptr + 5] = c;
2513 2525
 #ifndef NO_STACK_CHECKS
2514 2526
 				if(__builtin_expect(u->wst.ptr < 4, 0)) {
2515 2527
 					u->wst.error = 1;
2516 2528
 					goto error;
2517 2529
 				}
2518
-				if(__builtin_expect(u->wst.ptr > 253, 0)) {
2530
+				if(__builtin_expect(u->wst.ptr > 249, 0)) {
2519 2531
 					u->wst.error = 2;
2520 2532
 					goto error;
2521 2533
 				}
2522 2534
 #endif
2523
-				u->wst.ptr += 2;
2535
+				u->wst.ptr += 6;
2524 2536
 			}
2525 2537
 			break;
2526 2538
 		case 0xa7: /* ROT2k */
... ...
@@ -3023,24 +3035,24 @@ uxn_eval(Uxn *u, Uint16 vec)
3023 3035
 				u->rst.ptr += 2;
3024 3036
 			}
3025 3037
 			break;
3026
-		case 0xc6: /* NIPkr */
3027
-			__asm__("evaluxn_c6_NIPkr:");
3038
+		case 0xc6: /* OVRkr */
3039
+			__asm__("evaluxn_c6_OVRkr:");
3028 3040
 			{
3029
-				Uint8 a;
3030
-				u->rst.dat[u->rst.ptr - 1];
3031
-				a = u->rst.dat[u->rst.ptr - 2];
3032
-				u->rst.dat[u->rst.ptr] = a;
3041
+				Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2];
3042
+				u->rst.dat[u->rst.ptr] = b;
3043
+				u->rst.dat[u->rst.ptr + 1] = a;
3044
+				u->rst.dat[u->rst.ptr + 2] = b;
3033 3045
 #ifndef NO_STACK_CHECKS
3034 3046
 				if(__builtin_expect(u->rst.ptr < 2, 0)) {
3035 3047
 					u->rst.error = 1;
3036 3048
 					goto error;
3037 3049
 				}
3038
-				if(__builtin_expect(u->rst.ptr > 254, 0)) {
3050
+				if(__builtin_expect(u->rst.ptr > 252, 0)) {
3039 3051
 					u->rst.error = 2;
3040 3052
 					goto error;
3041 3053
 				}
3042 3054
 #endif
3043
-				u->rst.ptr += 1;
3055
+				u->rst.ptr += 3;
3044 3056
 			}
3045 3057
 			break;
3046 3058
 		case 0xc7: /* ROTkr */
... ...
@@ -3531,25 +3543,27 @@ uxn_eval(Uxn *u, Uint16 vec)
3531 3543
 				u->rst.ptr += 4;
3532 3544
 			}
3533 3545
 			break;
3534
-		case 0xe6: /* NIP2kr */
3535
-			__asm__("evaluxn_e6_NIP2kr:");
3546
+		case 0xe6: /* OVR2kr */
3547
+			__asm__("evaluxn_e6_OVR2kr:");
3536 3548
 			{
3537
-				Uint16 a;
3538
-				(u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8));
3539
-				a = (u->rst.dat[u->rst.ptr - 3] | (u->rst.dat[u->rst.ptr - 4] << 8));
3540
-				u->rst.dat[u->rst.ptr] = a >> 8;
3541
-				u->rst.dat[u->rst.ptr + 1] = a & 0xff;
3549
+				Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2], c = u->rst.dat[u->rst.ptr - 3], d = u->rst.dat[u->rst.ptr - 4];
3550
+				u->rst.dat[u->rst.ptr] = d;
3551
+				u->rst.dat[u->rst.ptr + 1] = c;
3552
+				u->rst.dat[u->rst.ptr + 2] = b;
3553
+				u->rst.dat[u->rst.ptr + 3] = a;
3554
+				u->rst.dat[u->rst.ptr + 4] = d;
3555
+				u->rst.dat[u->rst.ptr + 5] = c;
3542 3556
 #ifndef NO_STACK_CHECKS
3543 3557
 				if(__builtin_expect(u->rst.ptr < 4, 0)) {
3544 3558
 					u->rst.error = 1;
3545 3559
 					goto error;
3546 3560
 				}
3547
-				if(__builtin_expect(u->rst.ptr > 253, 0)) {
3561
+				if(__builtin_expect(u->rst.ptr > 249, 0)) {
3548 3562
 					u->rst.error = 2;
3549 3563
 					goto error;
3550 3564
 				}
3551 3565
 #endif
3552
-				u->rst.ptr += 2;
3566
+				u->rst.ptr += 6;
3553 3567
 			}
3554 3568
 			break;
3555 3569
 		case 0xe7: /* ROT2kr */
... ...
@@ -39,7 +39,7 @@ static void op_lit(Uxn *u) { push8(u->src, mempeek8(u->ram.dat, u->ram.ptr++));
39 39
 static void op_pop(Uxn *u) { pop8(u->src); }
40 40
 static void op_dup(Uxn *u) { Uint8 a = pop8(u->src); push8(u->src, a); push8(u->src, a); }
41 41
 static void op_swp(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, a); push8(u->src, b); }
42
-static void op_nip(Uxn *u) { Uint8 a; pop8(u->src); a = pop8(u->src); push8(u->src, a); }
42
+static void op_ovr(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, b); push8(u->src, a); push8(u->src, b); }
43 43
 static void op_rot(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src), c = pop8(u->src); push8(u->src, b); push8(u->src, a); push8(u->src, c); }
44 44
 /* Logic */
45 45
 static void op_equ(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, b == a); }
... ...
@@ -73,7 +73,7 @@ static void op_lit16(Uxn *u) { push16(u->src, mempeek16(u->ram.dat, u->ram.ptr++
73 73
 static void op_pop16(Uxn *u) { pop16(u->src); }
74 74
 static void op_dup16(Uxn *u) { Uint16 a = pop16(u->src); push16(u->src, a); push16(u->src, a); }
75 75
 static void op_swp16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push16(u->src, a); push16(u->src, b); }
76
-static void op_nip16(Uxn *u) { Uint16 a; pop16(u->src); a = pop16(u->src); push16(u->src, a); }
76
+static void op_ovr16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push16(u->src, b); push16(u->src, a); push16(u->src, b); }
77 77
 static void op_rot16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src), c = pop16(u->src); push16(u->src, b); push16(u->src, a); push16(u->src, c); }
78 78
 /* Logic(16-bits) */
79 79
 static void op_equ16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push8(u->src, b == a); }
... ...
@@ -104,12 +104,12 @@ static void op_eor16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push
104 104
 static void op_sft16(Uxn *u) { Uint8 a = pop8(u->src); Uint16 b = pop16(u->src); push16(u->src, b >> (a & 0x0f) << ((a & 0xf0) >> 4)); }
105 105
 
106 106
 static void (*ops[])(Uxn *u) = {
107
-	op_brk, op_lit, op_nop, op_pop, op_dup, op_swp, op_nip, op_rot,
107
+	op_brk, op_lit, op_nop, op_pop, op_dup, op_swp, op_ovr, op_rot,
108 108
 	op_equ, op_neq, op_gth, op_lth, op_jmp, op_jnz, op_jsr, op_sth, 
109 109
 	op_pek, op_pok, op_ldr, op_str, op_lda, op_sta, op_dei, op_deo,
110 110
 	op_add, op_sub, op_mul, op_div, op_and, op_ora, op_eor, op_sft,
111 111
 	/* 16-bit */
112
-	op_brk,   op_lit16, op_nop,   op_pop16, op_dup16, op_swp16, op_nip16, op_rot16,
112
+	op_brk,   op_lit16, op_nop,   op_pop16, op_dup16, op_swp16, op_ovr16, op_rot16,
113 113
 	op_equ16, op_neq16, op_gth16, op_lth16, op_jmp16, op_jnz16, op_jsr16, op_sth16, 
114 114
 	op_pek16, op_pok16, op_ldr16, op_str16, op_lda16, op_sta16, op_dei16, op_deo16, 
115 115
 	op_add16, op_sub16, op_mul16, op_div16, op_and16, op_ora16, op_eor16, op_sft16
... ...
@@ -40,7 +40,7 @@ Program p;
40 40
 /* clang-format off */
41 41
 
42 42
 static char ops[][4] = {
43
-	"BRK", "LIT", "NOP", "POP", "DUP", "SWP", "NIP", "ROT",
43
+	"BRK", "LIT", "NOP", "POP", "DUP", "SWP", "OVR", "ROT",
44 44
 	"EQU", "NEQ", "GTH", "LTH", "JMP", "JCN", "JSR", "STH",
45 45
 	"LDZ", "STZ", "LDR", "STR", "LDA", "STA", "DEI", "DEO",
46 46
 	"ADD", "SUB", "MUL", "DIV", "AND", "ORA", "EOR", "SFT"