Rearranged POP, DUP, NIP opcodes

This commit is contained in:
Andrew Alderwick 2021-08-15 21:34:33 +01:00
parent 93dae917fb
commit 107a59affa
4 changed files with 178 additions and 178 deletions

View File

@ -917,9 +917,9 @@
@asma-opcodes
&BRK :&AND :&DEI &_disasm "BRK 00
&_entry :&EQU :&ROT "LIT 00
&NIP :&MUL :&OVR "NIP 00
&POP $2 $2 "POP 00
&DUP :&DIV :&EOR "DUP 00
&NIP :&MUL :&OVR "NIP 00
&SWP $2 $2 "SWP 00
&OVR :&ORA :&POP "OVR 00
&ROT :&NIP :&STR "ROT 00

View File

@ -81,23 +81,8 @@ uxn_eval(Uxn *u, Uint16 vec)
u->wst.ptr += 1;
}
break;
case 0x02: /* NIP */
__asm__("evaluxn_02_NIP:");
{
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 */
__asm__("evaluxn_03_POP:");
case 0x02: /* POP */
__asm__("evaluxn_02_POP:");
{
u->wst.dat[u->wst.ptr - 1];
#ifndef NO_STACK_CHECKS
@ -109,8 +94,8 @@ uxn_eval(Uxn *u, Uint16 vec)
u->wst.ptr -= 1;
}
break;
case 0x04: /* DUP */
__asm__("evaluxn_04_DUP:");
case 0x03: /* DUP */
__asm__("evaluxn_03_DUP:");
{
Uint8 a = u->wst.dat[u->wst.ptr - 1];
u->wst.dat[u->wst.ptr] = a;
@ -127,6 +112,21 @@ uxn_eval(Uxn *u, Uint16 vec)
u->wst.ptr += 1;
}
break;
case 0x04: /* NIP */
__asm__("evaluxn_04_NIP:");
{
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 0x05: /* SWP */
__asm__("evaluxn_05_SWP:");
{
@ -548,24 +548,8 @@ 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:");
case 0x22: /* POP2 */
__asm__("evaluxn_22_POP2:");
{
(u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8));
#ifndef NO_STACK_CHECKS
@ -577,8 +561,8 @@ uxn_eval(Uxn *u, Uint16 vec)
u->wst.ptr -= 2;
}
break;
case 0x24: /* DUP2 */
__asm__("evaluxn_24_DUP2:");
case 0x23: /* DUP2 */
__asm__("evaluxn_23_DUP2:");
{
Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2];
u->wst.dat[u->wst.ptr] = b;
@ -596,6 +580,22 @@ uxn_eval(Uxn *u, Uint16 vec)
u->wst.ptr += 2;
}
break;
case 0x24: /* NIP2 */
__asm__("evaluxn_24_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 0x25: /* SWP2 */
__asm__("evaluxn_25_SWP2:");
{
@ -1049,23 +1049,8 @@ 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:");
case 0x42: /* POPr */
__asm__("evaluxn_42_POPr:");
{
u->rst.dat[u->rst.ptr - 1];
#ifndef NO_STACK_CHECKS
@ -1077,8 +1062,8 @@ uxn_eval(Uxn *u, Uint16 vec)
u->rst.ptr -= 1;
}
break;
case 0x44: /* DUPr */
__asm__("evaluxn_44_DUPr:");
case 0x43: /* DUPr */
__asm__("evaluxn_43_DUPr:");
{
Uint8 a = u->rst.dat[u->rst.ptr - 1];
u->rst.dat[u->rst.ptr] = a;
@ -1095,6 +1080,21 @@ uxn_eval(Uxn *u, Uint16 vec)
u->rst.ptr += 1;
}
break;
case 0x44: /* NIPr */
__asm__("evaluxn_44_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 0x45: /* SWPr */
__asm__("evaluxn_45_SWPr:");
{
@ -1516,24 +1516,8 @@ 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:");
case 0x62: /* POP2r */
__asm__("evaluxn_62_POP2r:");
{
(u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8));
#ifndef NO_STACK_CHECKS
@ -1545,8 +1529,8 @@ uxn_eval(Uxn *u, Uint16 vec)
u->rst.ptr -= 2;
}
break;
case 0x64: /* DUP2r */
__asm__("evaluxn_64_DUP2r:");
case 0x63: /* DUP2r */
__asm__("evaluxn_63_DUP2r:");
{
Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2];
u->rst.dat[u->rst.ptr] = b;
@ -1564,6 +1548,22 @@ uxn_eval(Uxn *u, Uint16 vec)
u->rst.ptr += 2;
}
break;
case 0x64: /* NIP2r */
__asm__("evaluxn_64_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 0x65: /* SWP2r */
__asm__("evaluxn_65_SWP2r:");
{
@ -2003,27 +2003,8 @@ 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:");
case 0x82: /* POPk */
__asm__("evaluxn_82_POPk:");
{
u->wst.dat[u->wst.ptr - 1];
#ifndef NO_STACK_CHECKS
@ -2034,8 +2015,8 @@ uxn_eval(Uxn *u, Uint16 vec)
#endif
}
break;
case 0x84: /* DUPk */
__asm__("evaluxn_84_DUPk:");
case 0x83: /* DUPk */
__asm__("evaluxn_83_DUPk:");
{
Uint8 a = u->wst.dat[u->wst.ptr - 1];
u->wst.dat[u->wst.ptr] = a;
@ -2053,6 +2034,25 @@ uxn_eval(Uxn *u, Uint16 vec)
u->wst.ptr += 2;
}
break;
case 0x84: /* NIPk */
__asm__("evaluxn_84_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 0x85: /* SWPk */
__asm__("evaluxn_85_SWPk:");
{
@ -2526,28 +2526,8 @@ 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:");
case 0xa2: /* POP2k */
__asm__("evaluxn_a2_POP2k:");
{
(u->wst.dat[u->wst.ptr - 1] | (u->wst.dat[u->wst.ptr - 2] << 8));
#ifndef NO_STACK_CHECKS
@ -2558,8 +2538,8 @@ uxn_eval(Uxn *u, Uint16 vec)
#endif
}
break;
case 0xa4: /* DUP2k */
__asm__("evaluxn_a4_DUP2k:");
case 0xa3: /* DUP2k */
__asm__("evaluxn_a3_DUP2k:");
{
Uint8 a = u->wst.dat[u->wst.ptr - 1], b = u->wst.dat[u->wst.ptr - 2];
u->wst.dat[u->wst.ptr] = b;
@ -2579,6 +2559,26 @@ uxn_eval(Uxn *u, Uint16 vec)
u->wst.ptr += 4;
}
break;
case 0xa4: /* NIP2k */
__asm__("evaluxn_a4_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 0xa5: /* SWP2k */
__asm__("evaluxn_a5_SWP2k:");
{
@ -3073,27 +3073,8 @@ 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:");
case 0xc2: /* POPkr */
__asm__("evaluxn_c2_POPkr:");
{
u->rst.dat[u->rst.ptr - 1];
#ifndef NO_STACK_CHECKS
@ -3104,8 +3085,8 @@ uxn_eval(Uxn *u, Uint16 vec)
#endif
}
break;
case 0xc4: /* DUPkr */
__asm__("evaluxn_c4_DUPkr:");
case 0xc3: /* DUPkr */
__asm__("evaluxn_c3_DUPkr:");
{
Uint8 a = u->rst.dat[u->rst.ptr - 1];
u->rst.dat[u->rst.ptr] = a;
@ -3123,6 +3104,25 @@ uxn_eval(Uxn *u, Uint16 vec)
u->rst.ptr += 2;
}
break;
case 0xc4: /* NIPkr */
__asm__("evaluxn_c4_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 0xc5: /* SWPkr */
__asm__("evaluxn_c5_SWPkr:");
{
@ -3596,28 +3596,8 @@ 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:");
case 0xe2: /* POP2kr */
__asm__("evaluxn_e2_POP2kr:");
{
(u->rst.dat[u->rst.ptr - 1] | (u->rst.dat[u->rst.ptr - 2] << 8));
#ifndef NO_STACK_CHECKS
@ -3628,8 +3608,8 @@ uxn_eval(Uxn *u, Uint16 vec)
#endif
}
break;
case 0xe4: /* DUP2kr */
__asm__("evaluxn_e4_DUP2kr:");
case 0xe3: /* DUP2kr */
__asm__("evaluxn_e3_DUP2kr:");
{
Uint8 a = u->rst.dat[u->rst.ptr - 1], b = u->rst.dat[u->rst.ptr - 2];
u->rst.dat[u->rst.ptr] = b;
@ -3649,6 +3629,26 @@ uxn_eval(Uxn *u, Uint16 vec)
u->rst.ptr += 4;
}
break;
case 0xe4: /* NIP2kr */
__asm__("evaluxn_e4_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 0xe5: /* SWP2kr */
__asm__("evaluxn_e5_SWP2kr:");
{

View File

@ -35,9 +35,9 @@ static Uint16 devpeek16(Device *d, Uint16 a) { return (devpeek8(d, a) << 8) + de
/* Stack */
static void op_brk(Uxn *u) { u->ram.ptr = 0; }
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_nip(Uxn *u) { Uint8 a = pop8(u->src); pop8(u->src); 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_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); }
@ -70,9 +70,9 @@ 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_nip16(Uxn *u) { Uint16 a = pop16(u->src); pop16(u->src); 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_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); }
@ -105,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_nip, op_pop, op_dup, op_swp, op_ovr, op_rot,
op_brk, op_lit, op_pop, op_dup, op_nip, 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_nip16, op_pop16, op_dup16, op_swp16, op_ovr16, op_rot16,
op_brk, op_lit16, op_pop16, op_dup16, op_nip16, 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

View File

@ -40,7 +40,7 @@ Program p;
/* clang-format off */
static char ops[][4] = {
"BRK", "LIT", "NIP", "POP", "DUP", "SWP", "OVR", "ROT",
"BRK", "LIT", "POP", "DUP", "NIP", "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"