commit be360ffc1e5c1a41f2daae1ae04673079bf4175b
parent e2190d84d8e8cd32aee73b78d8de50556687f217
Author: Andrew Alderwick <andrew@alderwick.co.uk>
Date: Sun, 15 Aug 2021 21:22:01 +0100
Replaced NOP with NIP
Diffstat:
4 files changed, 144 insertions(+), 16 deletions(-)
diff --git a/projects/software/asma.tal b/projects/software/asma.tal
@@ -917,12 +917,12 @@
@asma-opcodes
&BRK :&AND :&DEI &_disasm "BRK 00
&_entry :&EQU :&ROT "LIT 00
- &NOP :&MUL :&OVR "NOP 00
+ &NIP :&MUL :&OVR "NIP 00
&POP $2 $2 "POP 00
&DUP :&DIV :&EOR "DUP 00
&SWP $2 $2 "SWP 00
&OVR :&ORA :&POP "OVR 00
- &ROT :&NOP :&STR "ROT 00
+ &ROT :&NIP :&STR "ROT 00
&EQU :&DEO :&JSR "EQU 00
&NEQ $2 $2 "NEQ 00
>H $2 $2 "GTH 00
diff --git a/src/uxn-fast.c b/src/uxn-fast.c
@@ -81,17 +81,19 @@ uxn_eval(Uxn *u, Uint16 vec)
u->wst.ptr += 1;
}
break;
- case 0x02: /* NOP */
- case 0x22: /* NOP2 */
- case 0x42: /* NOPr */
- case 0x62: /* NOP2r */
- case 0x82: /* NOPk */
- case 0xa2: /* NOP2k */
- case 0xc2: /* NOPkr */
- case 0xe2: /* NOP2kr */
- __asm__("evaluxn_02_NOP:");
+ case 0x02: /* NIP */
+ __asm__("evaluxn_02_NIP:");
{
- (void)u;
+ Uint8 a = u->wst.dat[u->wst.ptr - 1];
+ u->wst.dat[u->wst.ptr - 2];
+ u->wst.dat[u->wst.ptr - 2] = a;
+#ifndef NO_STACK_CHECKS
+ if(__builtin_expect(u->wst.ptr < 2, 0)) {
+ u->wst.error = 1;
+ goto error;
+ }
+#endif
+ u->wst.ptr -= 1;
}
break;
case 0x03: /* POP */
@@ -546,6 +548,22 @@ uxn_eval(Uxn *u, Uint16 vec)
u->wst.ptr += 2;
}
break;
+ case 0x22: /* NIP2 */
+ __asm__("evaluxn_22_NIP2:");
+ {
+ Uint16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8));
+ (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;
+#ifndef NO_STACK_CHECKS
+ if(__builtin_expect(u->wst.ptr < 4, 0)) {
+ u->wst.error = 1;
+ goto error;
+ }
+#endif
+ u->wst.ptr -= 2;
+ }
+ break;
case 0x23: /* POP2 */
__asm__("evaluxn_23_POP2:");
{
@@ -1031,6 +1049,21 @@ uxn_eval(Uxn *u, Uint16 vec)
u->rst.ptr += 1;
}
break;
+ case 0x42: /* NIPr */
+ __asm__("evaluxn_42_NIPr:");
+ {
+ Uint8 a = u->rst.dat[u->rst.ptr - 1];
+ u->rst.dat[u->rst.ptr - 2];
+ u->rst.dat[u->rst.ptr - 2] = a;
+#ifndef NO_STACK_CHECKS
+ if(__builtin_expect(u->rst.ptr < 2, 0)) {
+ u->rst.error = 1;
+ goto error;
+ }
+#endif
+ u->rst.ptr -= 1;
+ }
+ break;
case 0x43: /* POPr */
__asm__("evaluxn_43_POPr:");
{
@@ -1483,6 +1516,22 @@ uxn_eval(Uxn *u, Uint16 vec)
u->rst.ptr += 2;
}
break;
+ case 0x62: /* NIP2r */
+ __asm__("evaluxn_62_NIP2r:");
+ {
+ Uint16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8));
+ (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;
+#ifndef NO_STACK_CHECKS
+ if(__builtin_expect(u->rst.ptr < 4, 0)) {
+ u->rst.error = 1;
+ goto error;
+ }
+#endif
+ u->rst.ptr -= 2;
+ }
+ break;
case 0x63: /* POP2r */
__asm__("evaluxn_63_POP2r:");
{
@@ -1954,6 +2003,25 @@ uxn_eval(Uxn *u, Uint16 vec)
u->rst.ptr -= 1;
}
break;
+ case 0x82: /* NIPk */
+ __asm__("evaluxn_82_NIPk:");
+ {
+ Uint8 a = u->wst.dat[u->wst.ptr - 1];
+ u->wst.dat[u->wst.ptr - 2];
+ u->wst.dat[u->wst.ptr] = a;
+#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;
+ }
+ break;
case 0x83: /* POPk */
__asm__("evaluxn_83_POPk:");
{
@@ -2458,6 +2526,26 @@ uxn_eval(Uxn *u, Uint16 vec)
u->wst.ptr += 1;
}
break;
+ case 0xa2: /* NIP2k */
+ __asm__("evaluxn_a2_NIP2k:");
+ {
+ Uint16 a = (u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8));
+ (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;
+#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;
+ }
+ break;
case 0xa3: /* POP2k */
__asm__("evaluxn_a3_POP2k:");
{
@@ -2985,6 +3073,25 @@ uxn_eval(Uxn *u, Uint16 vec)
u->wst.ptr += 2;
}
break;
+ case 0xc2: /* NIPkr */
+ __asm__("evaluxn_c2_NIPkr:");
+ {
+ Uint8 a = u->rst.dat[u->rst.ptr - 1];
+ u->rst.dat[u->rst.ptr - 2];
+ u->rst.dat[u->rst.ptr] = a;
+#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;
+ }
+ break;
case 0xc3: /* POPkr */
__asm__("evaluxn_c3_POPkr:");
{
@@ -3489,6 +3596,26 @@ uxn_eval(Uxn *u, Uint16 vec)
u->rst.ptr += 1;
}
break;
+ case 0xe2: /* NIP2kr */
+ __asm__("evaluxn_e2_NIP2kr:");
+ {
+ Uint16 a = (u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8));
+ (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;
+#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;
+ }
+ break;
case 0xe3: /* POP2kr */
__asm__("evaluxn_e3_POP2kr:");
{
diff --git a/src/uxn.c b/src/uxn.c
@@ -34,8 +34,8 @@ static void devpoke16(Device *d, Uint8 a, Uint16 b) { devpoke8(d, a, b >> 8);
static Uint16 devpeek16(Device *d, Uint16 a) { return (devpeek8(d, a) << 8) + devpeek8(d, a + 1); }
/* Stack */
static void op_brk(Uxn *u) { u->ram.ptr = 0; }
-static void op_nop(Uxn *u) { (void)u; }
static void op_lit(Uxn *u) { push8(u->src, mempeek8(u->ram.dat, u->ram.ptr++)); }
+static void op_nip(Uxn *u) { Uint8 a = pop8(u->src); pop8(u->src); push8(u->src, a); }
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); }
@@ -70,6 +70,7 @@ static void op_eor(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->
static void op_sft(Uxn *u) { Uint8 a = pop8(u->src), b = pop8(u->src); push8(u->src, b >> (a & 0x07) << ((a & 0x70) >> 4)); }
/* Stack */
static void op_lit16(Uxn *u) { push16(u->src, mempeek16(u->ram.dat, u->ram.ptr++)); u->ram.ptr++; }
+static void op_nip16(Uxn *u) { Uint16 a = pop16(u->src); pop16(u->src); push16(u->src, a); }
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); }
@@ -104,12 +105,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_ovr, op_rot,
+ op_brk, op_lit, op_nip, 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_ovr16, op_rot16,
+ op_brk, op_lit16, op_nip16, 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
@@ -40,7 +40,7 @@ Program p;
/* clang-format off */
static char ops[][4] = {
- "BRK", "LIT", "NOP", "POP", "DUP", "SWP", "OVR", "ROT",
+ "BRK", "LIT", "NIP", "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"