From e2190d84d8e8cd32aee73b78d8de50556687f217 Mon Sep 17 00:00:00 2001 From: Andrew Alderwick Date: Sun, 15 Aug 2021 21:06:54 +0100 Subject: [PATCH] Reverted "Removed OVR opcode and replaced with NIP" and uxn-fast.c update. This reverts commits 1afe39fba4a0fdba16b6e561b3fb4b38578ccbb1 and 3d3569bab7a65e581fb5d9e108be4355826daf31. --- projects/examples/demos/piano.tal | 13 ++- src/uxn-fast.c | 138 ++++++++++++++++-------------- src/uxn.c | 8 +- src/uxnasm.c | 2 +- 4 files changed, 87 insertions(+), 74 deletions(-) diff --git a/projects/examples/demos/piano.tal b/projects/examples/demos/piano.tal index a4d5e33..7871bc2 100644 --- a/projects/examples/demos/piano.tal +++ b/projects/examples/demos/piano.tal @@ -6,8 +6,7 @@ %<< { LTH2 } %>> { GTH2 } %== { EQU2 } %!! { NEQ2 } %RTN { JMP2r } -%OVR { NIPk } %OVR2 { NIP2k } -%TOS { #00 SWP } +%TOS { #00 SWP } %TOB { SWP POP } %MOD { DUP2 / * - } %LTS2 { #8000 ++ SWP2 #8000 ++ >> } %GTS2 { #8000 ++ SWP2 #8000 ++ << } @@ -184,8 +183,8 @@ BRK @on-touch-octave-view ( -> ) - .Mouse/x DEI2 .octave-view/x1 LDZ2 -- 8// NIP #09 ! ,&no-mod JCN - .Mouse/y DEI2 .octave-view/y1 LDZ2 -- 8// NIP + .Mouse/x DEI2 .octave-view/x1 LDZ2 -- 8// TOB #09 ! ,&no-mod JCN + .Mouse/y DEI2 .octave-view/y1 LDZ2 -- 8// TOB DUP #00 ! ,&no-incr JCN .octave LDZ #03 = ,&no-incr JCN .octave LDZ #01 + .octave STZ &no-incr @@ -198,7 +197,7 @@ BRK BRK &no-mod - .Mouse/x DEI2 .octave-view/x1 LDZ2 -- 8// NIP #06 > ,&no-key JCN + .Mouse/x DEI2 .octave-view/x1 LDZ2 -- 8// TOB #06 > ,&no-key JCN .Mouse/x DEI2 .octave-view/x1 LDZ2 -- 8// ;notes ++ LDA .octave LDZ #0c * + ;play JSR2 ( release ) #00 .Mouse/state DEO ;draw-octave JSR2 @@ -208,7 +207,7 @@ BRK @on-touch-adsr-view ( -> ) - .Mouse/x DEI2 .adsr-view/x1 LDZ2 -- 8// NIP #03 / + .Mouse/x DEI2 .adsr-view/x1 LDZ2 -- 8// TOB #03 / DUP #00 ! ,&no-a JCN .Audio0/adsr DEI #10 .Mouse/state DEI #10 = #e0 * + + @@ -358,7 +357,7 @@ RTN TOS 4// .wave-view/y1 LDZ2 ++ .Screen/y DEO2 .Screen/x DEI2 #0001 ++ .Screen/x DEO2 ( draw ) DUP - .Audio0/length DEI2 NIP > + .Audio0/length DEI2 TOB > .Audio0/length DEI2 #0100 !! #0101 == #02 * #01 + .Screen/pixel DEO #01 + GTHk ,&loop JCN POP2 diff --git a/src/uxn-fast.c b/src/uxn-fast.c index bedb698..fdb26c3 100644 --- a/src/uxn-fast.c +++ b/src/uxn-fast.c @@ -139,19 +139,22 @@ uxn_eval(Uxn *u, Uint16 vec) #endif } break; - case 0x06: /* NIP */ - __asm__("evaluxn_06_NIP:"); + case 0x06: /* OVR */ + __asm__("evaluxn_06_OVR:"); { - Uint8 a; - u->wst.dat[u->wst.ptr - 1]; - a = u->wst.dat[u->wst.ptr - 2]; + Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; + u->wst.dat[u->wst.ptr] = b; #ifndef NO_STACK_CHECKS if(__builtin_expect(u->wst.ptr < 2, 0)) { u->wst.error = 1; goto error; } + if(__builtin_expect(u->wst.ptr > 254, 0)) { + u->wst.error = 2; + goto error; + } #endif - u->wst.ptr -= 1; + u->wst.ptr += 1; } break; case 0x07: /* ROT */ @@ -591,21 +594,23 @@ uxn_eval(Uxn *u, Uint16 vec) #endif } break; - case 0x26: /* NIP2 */ - __asm__("evaluxn_26_NIP2:"); + case 0x26: /* OVR2 */ + __asm__("evaluxn_26_OVR2:"); { - Uint16 a; - (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)); - a = (u->wst.dat[u->wst.ptr - 3] | (u->wst.dat[u->wst.ptr - 4] << 8)); - u->wst.dat[u->wst.ptr - 4] = a >> 8; - u->wst.dat[u->wst.ptr - 3] = a & 0xff; + 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]; + u->wst.dat[u->wst.ptr] = d; + u->wst.dat[u->wst.ptr + 1] = c; #ifndef NO_STACK_CHECKS if(__builtin_expect(u->wst.ptr < 4, 0)) { u->wst.error = 1; goto error; } + if(__builtin_expect(u->wst.ptr > 253, 0)) { + u->wst.error = 2; + goto error; + } #endif - u->wst.ptr -= 2; + u->wst.ptr += 2; } break; case 0x27: /* ROT2 */ @@ -1071,19 +1076,22 @@ uxn_eval(Uxn *u, Uint16 vec) #endif } break; - case 0x46: /* NIPr */ - __asm__("evaluxn_46_NIPr:"); + case 0x46: /* OVRr */ + __asm__("evaluxn_46_OVRr:"); { - Uint8 a; - u->rst.dat[u->rst.ptr - 1]; - a = u->rst.dat[u->rst.ptr - 2]; + Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; + u->rst.dat[u->rst.ptr] = b; #ifndef NO_STACK_CHECKS if(__builtin_expect(u->rst.ptr < 2, 0)) { u->rst.error = 1; goto error; } + if(__builtin_expect(u->rst.ptr > 254, 0)) { + u->rst.error = 2; + goto error; + } #endif - u->rst.ptr -= 1; + u->rst.ptr += 1; } break; case 0x47: /* ROTr */ @@ -1523,21 +1531,23 @@ uxn_eval(Uxn *u, Uint16 vec) #endif } break; - case 0x66: /* NIP2r */ - __asm__("evaluxn_66_NIP2r:"); + case 0x66: /* OVR2r */ + __asm__("evaluxn_66_OVR2r:"); { - Uint16 a; - (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)); - a = (u->rst.dat[u->rst.ptr - 3] | (u->rst.dat[u->rst.ptr - 4] << 8)); - u->rst.dat[u->rst.ptr - 4] = a >> 8; - u->rst.dat[u->rst.ptr - 3] = a & 0xff; + 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]; + u->rst.dat[u->rst.ptr] = d; + u->rst.dat[u->rst.ptr + 1] = c; #ifndef NO_STACK_CHECKS if(__builtin_expect(u->rst.ptr < 4, 0)) { u->rst.error = 1; goto error; } + if(__builtin_expect(u->rst.ptr > 253, 0)) { + u->rst.error = 2; + goto error; + } #endif - u->rst.ptr -= 2; + u->rst.ptr += 2; } break; case 0x67: /* ROT2r */ @@ -1994,24 +2004,24 @@ uxn_eval(Uxn *u, Uint16 vec) u->wst.ptr += 2; } break; - case 0x86: /* NIPk */ - __asm__("evaluxn_86_NIPk:"); + case 0x86: /* OVRk */ + __asm__("evaluxn_86_OVRk:"); { - Uint8 a; - u->wst.dat[u->wst.ptr - 1]; - a = u->wst.dat[u->wst.ptr - 2]; - u->wst.dat[u->wst.ptr] = a; + Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2]; + u->wst.dat[u->wst.ptr] = b; + u->wst.dat[u->wst.ptr + 1] = a; + u->wst.dat[u->wst.ptr + 2] = b; #ifndef NO_STACK_CHECKS if(__builtin_expect(u->wst.ptr < 2, 0)) { u->wst.error = 1; goto error; } - if(__builtin_expect(u->wst.ptr > 254, 0)) { + if(__builtin_expect(u->wst.ptr > 252, 0)) { u->wst.error = 2; goto error; } #endif - u->wst.ptr += 1; + u->wst.ptr += 3; } break; case 0x87: /* ROTk */ @@ -2502,25 +2512,27 @@ uxn_eval(Uxn *u, Uint16 vec) u->wst.ptr += 4; } break; - case 0xa6: /* NIP2k */ - __asm__("evaluxn_a6_NIP2k:"); + case 0xa6: /* OVR2k */ + __asm__("evaluxn_a6_OVR2k:"); { - Uint16 a; - (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8)); - a = (u->wst.dat[u->wst.ptr - 3] | (u->wst.dat[u->wst.ptr - 4] << 8)); - u->wst.dat[u->wst.ptr] = a >> 8; - u->wst.dat[u->wst.ptr + 1] = a & 0xff; + 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]; + u->wst.dat[u->wst.ptr] = d; + u->wst.dat[u->wst.ptr + 1] = c; + u->wst.dat[u->wst.ptr + 2] = b; + u->wst.dat[u->wst.ptr + 3] = a; + u->wst.dat[u->wst.ptr + 4] = d; + u->wst.dat[u->wst.ptr + 5] = c; #ifndef NO_STACK_CHECKS if(__builtin_expect(u->wst.ptr < 4, 0)) { u->wst.error = 1; goto error; } - if(__builtin_expect(u->wst.ptr > 253, 0)) { + if(__builtin_expect(u->wst.ptr > 249, 0)) { u->wst.error = 2; goto error; } #endif - u->wst.ptr += 2; + u->wst.ptr += 6; } break; case 0xa7: /* ROT2k */ @@ -3023,24 +3035,24 @@ uxn_eval(Uxn *u, Uint16 vec) u->rst.ptr += 2; } break; - case 0xc6: /* NIPkr */ - __asm__("evaluxn_c6_NIPkr:"); + case 0xc6: /* OVRkr */ + __asm__("evaluxn_c6_OVRkr:"); { - Uint8 a; - u->rst.dat[u->rst.ptr - 1]; - a = u->rst.dat[u->rst.ptr - 2]; - u->rst.dat[u->rst.ptr] = a; + Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2]; + u->rst.dat[u->rst.ptr] = b; + u->rst.dat[u->rst.ptr + 1] = a; + u->rst.dat[u->rst.ptr + 2] = b; #ifndef NO_STACK_CHECKS if(__builtin_expect(u->rst.ptr < 2, 0)) { u->rst.error = 1; goto error; } - if(__builtin_expect(u->rst.ptr > 254, 0)) { + if(__builtin_expect(u->rst.ptr > 252, 0)) { u->rst.error = 2; goto error; } #endif - u->rst.ptr += 1; + u->rst.ptr += 3; } break; case 0xc7: /* ROTkr */ @@ -3531,25 +3543,27 @@ uxn_eval(Uxn *u, Uint16 vec) u->rst.ptr += 4; } break; - case 0xe6: /* NIP2kr */ - __asm__("evaluxn_e6_NIP2kr:"); + case 0xe6: /* OVR2kr */ + __asm__("evaluxn_e6_OVR2kr:"); { - Uint16 a; - (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8)); - a = (u->rst.dat[u->rst.ptr - 3] | (u->rst.dat[u->rst.ptr - 4] << 8)); - u->rst.dat[u->rst.ptr] = a >> 8; - u->rst.dat[u->rst.ptr + 1] = a & 0xff; + 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]; + u->rst.dat[u->rst.ptr] = d; + u->rst.dat[u->rst.ptr + 1] = c; + u->rst.dat[u->rst.ptr + 2] = b; + u->rst.dat[u->rst.ptr + 3] = a; + u->rst.dat[u->rst.ptr + 4] = d; + u->rst.dat[u->rst.ptr + 5] = c; #ifndef NO_STACK_CHECKS if(__builtin_expect(u->rst.ptr < 4, 0)) { u->rst.error = 1; goto error; } - if(__builtin_expect(u->rst.ptr > 253, 0)) { + if(__builtin_expect(u->rst.ptr > 249, 0)) { u->rst.error = 2; goto error; } #endif - u->rst.ptr += 2; + u->rst.ptr += 6; } break; case 0xe7: /* ROT2kr */ diff --git a/src/uxn.c b/src/uxn.c index a703db1..bedb654 100644 --- a/src/uxn.c +++ b/src/uxn.c @@ -39,7 +39,7 @@ static void op_lit(Uxn *u) { push8(u->src, mempeek8(u->ram.dat, u->ram.ptr++)); static void op_pop(Uxn *u) { pop8(u->src); } static void op_dup(Uxn *u) { Uint8 a = pop8(u->src); push8(u->src, a); push8(u->src, a); } static void op_swp(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, a); push8(u->src, b); } -static void op_nip(Uxn *u) { Uint8 a; pop8(u->src); a = pop8(u->src); push8(u->src, a); } +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); } 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); } /* Logic */ 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++ static void op_pop16(Uxn *u) { pop16(u->src); } static void op_dup16(Uxn *u) { Uint16 a = pop16(u->src); push16(u->src, a); push16(u->src, a); } static void op_swp16(Uxn *u) { Uint16 a = pop16(u->src), b = pop16(u->src); push16(u->src, a); push16(u->src, b); } -static void op_nip16(Uxn *u) { Uint16 a; pop16(u->src); a = pop16(u->src); push16(u->src, a); } +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); } 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); } /* Logic(16-bits) */ 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 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)); } static void (*ops[])(Uxn *u) = { - op_brk, op_lit, op_nop, op_pop, op_dup, op_swp, op_nip, op_rot, + op_brk, op_lit, op_nop, op_pop, op_dup, op_swp, op_ovr, op_rot, op_equ, op_neq, op_gth, op_lth, op_jmp, op_jnz, op_jsr, op_sth, op_pek, op_pok, op_ldr, op_str, op_lda, op_sta, op_dei, op_deo, op_add, op_sub, op_mul, op_div, op_and, op_ora, op_eor, op_sft, /* 16-bit */ - op_brk, op_lit16, op_nop, op_pop16, op_dup16, op_swp16, op_nip16, op_rot16, + op_brk, op_lit16, op_nop, op_pop16, op_dup16, op_swp16, op_ovr16, op_rot16, op_equ16, op_neq16, op_gth16, op_lth16, op_jmp16, op_jnz16, op_jsr16, op_sth16, op_pek16, op_pok16, op_ldr16, op_str16, op_lda16, op_sta16, op_dei16, op_deo16, op_add16, op_sub16, op_mul16, op_div16, op_and16, op_ora16, op_eor16, op_sft16 diff --git a/src/uxnasm.c b/src/uxnasm.c index b274f7c..9b5ad73 100644 --- a/src/uxnasm.c +++ b/src/uxnasm.c @@ -40,7 +40,7 @@ Program p; /* clang-format off */ static char ops[][4] = { - "BRK", "LIT", "NOP", "POP", "DUP", "SWP", "NIP", "ROT", + "BRK", "LIT", "NOP", "POP", "DUP", "SWP", "OVR", "ROT", "EQU", "NEQ", "GTH", "LTH", "JMP", "JCN", "JSR", "STH", "LDZ", "STZ", "LDR", "STR", "LDA", "STA", "DEI", "DEO", "ADD", "SUB", "MUL", "DIV", "AND", "ORA", "EOR", "SFT"