Passing LIT

This commit is contained in:
Devine Lu Linvega 2024-06-29 19:26:05 -08:00
parent e89d67b8c1
commit 961fbfbf7c
2 changed files with 42 additions and 51 deletions

View File

@ -65,52 +65,11 @@ uxn_eval(Uint16 pc)
{
if(!pc || uxn.dev[0x0f]) return 0;
for(;;) {
Uint16 tt, a, b, c;
Uint8 t, kp, *sp, ins = uxn.ram[pc++];
/* 2 */ Uint8 m2 = ins & 0x20;
/* r */ Stack *s = ins & 0x40 ? &uxn.rst : &uxn.wst;
/* k */ if(ins & 0x80) kp = s->ptr, sp = &kp; else sp = &s->ptr;
switch(ins & 0x1f) {
case 0x00:
switch(ins) {
case 0x00: /* BRK */ return 1;
case 0x20: /* JCI */ POP1(b) if(!b) { pc += 2; break; } /* fall */
case 0x40: /* JMI */ a = uxn.ram[pc++] << 8 | uxn.ram[pc++]; pc += a; break;
case 0x60: /* JSI */ PUSH2(pc + 2) a = uxn.ram[pc++] << 8 | uxn.ram[pc++]; pc += a; break;
case 0xa0: case 0xe0: /* LIT2 */ PUSH1(uxn.ram[pc++]) /* fall */
case 0x80: case 0xc0: /* LIT */ PUSH1(uxn.ram[pc++]) break;
} break;
case 0x01: /* INC */ POPx(a) PUSHx(a + 1) break;
case 0x02: /* POP */ POPx(a) break;
case 0x03: /* NIP */ POPx(a) POPx(b) PUSHx(a) break;
case 0x04: /* SWP */ POPx(a) POPx(b) PUSHx(a) PUSHx(b) break;
case 0x05: /* ROT */ POPx(a) POPx(b) POPx(c) PUSHx(b) PUSHx(a) PUSHx(c) break;
case 0x06: /* DUP */ POPx(a) PUSHx(a) PUSHx(a) break;
case 0x07: /* OVR */ POPx(a) POPx(b) PUSHx(b) PUSHx(a) PUSHx(b) break;
case 0x08: /* EQU */ POPx(a) POPx(b) PUSH1(b == a) break;
case 0x09: /* NEQ */ POPx(a) POPx(b) PUSH1(b != a) break;
case 0x0a: /* GTH */ POPx(a) POPx(b) PUSH1(b > a) break;
case 0x0b: /* LTH */ POPx(a) POPx(b) PUSH1(b < a) break;
case 0x0c: /* JMP */ POPx(a) JUMP(a) break;
case 0x0d: /* JCN */ POPx(a) POP1(b) if(b) JUMP(a) break;
case 0x0e: /* JSR */ POPx(a) FLIP PUSH2(pc) JUMP(a) break;
case 0x0f: /* STH */ POPx(a) FLIP PUSHx(a) break;
case 0x10: /* LDZ */ POP1(a) PEEK(b, a, t) PUSHx(b) break;
case 0x11: /* STZ */ POP1(a) POPx(b) POKE(a, b, t) break;
case 0x12: /* LDR */ POP1(a) PEEK(b, pc + (Sint8)a, tt) PUSHx(b) break;
case 0x13: /* STR */ POP1(a) POPx(b) POKE(pc + (Sint8)a, b, tt) break;
case 0x14: /* LDA */ POP2(a) PEEK(b, a, tt) PUSHx(b) break;
case 0x15: /* STA */ POP2(a) POPx(b) POKE(a, b, tt) break;
case 0x16: /* DEI */ POP1(a) DEVR(b, a) PUSHx(b) break;
case 0x17: /* DEO */ POP1(a) POPx(b) DEVW(a, b) break;
case 0x18: /* ADD */ POPx(a) POPx(b) PUSHx(b + a) break;
case 0x19: /* SUB */ POPx(a) POPx(b) PUSHx(b - a) break;
case 0x1a: /* MUL */ POPx(a) POPx(b) PUSHx(b * a) break;
case 0x1b: /* DIV */ POPx(a) POPx(b) PUSHx(a ? b / a : 0) break;
case 0x1c: /* AND */ POPx(a) POPx(b) PUSHx(b & a) break;
case 0x1d: /* ORA */ POPx(a) POPx(b) PUSHx(b | a) break;
case 0x1e: /* EOR */ POPx(a) POPx(b) PUSHx(b ^ a) break;
case 0x1f: /* SFT */ POP1(a) POPx(b) PUSHx(b >> (a & 0xf) << (a >> 4)) break;
switch(uxn.ram[pc]) {
case 0x00: return 1;
case 0x01: pc++; break;
case 0x80: uxn.wst.dat[uxn.wst.ptr++] = uxn.ram[++pc]; pc++; break;
default: return 1;
}
system_inspect();
}
@ -120,11 +79,11 @@ int
main(int argc, char **argv)
{
/* test */
uxn.ram[0x100] = 0xa0;
uxn.ram[0x100] = 0x80;
uxn.ram[0x101] = 0x12;
uxn.ram[0x102] = 0x34;
uxn.ram[0x103] = 0x01;
uxn.ram[0x102] = 0x80;
uxn.ram[0x103] = 0x34;
uxn.ram[0x104] = 0x01;
if(uxn_eval(0x0100) && (uxn.dev[0x10] << 8 | uxn.dev[0x11]))
while(!uxn.dev[0x0f]) ;
return uxn.dev[0x0f] & 0x7f;

View File

@ -90,9 +90,33 @@
=op-brk =op-brk =op-brk =op-brk ]
@op-brk ( byte -- )
DUP #80 EQU ?op-lit
DUP #a0 EQU ?op-lit2
;dict/return <pstr>
POP JMP2r
@op-lit ( byte -- )
<dat>
[ LIT2 "[ 18 ] DEO
<ptr>
<inc>
[ LIT2 "] 18 ] DEO
<equ>
<ram>
[ LIT2 "[ 18 ] DEO
<inc>
<pc>
[ LIT2 "] 18 ] DEO
[ LIT2 "; 18 ] DEO
#2018 DEO
<pc>
<inc>
[ LIT2 "; 18 ] DEO
POP JMP2r
@op-lit2 ( byte -- )
POP JMP2r
@op-inc ( byte -- )
<dat>
[ LIT2 "[ 18 ] DEO
@ -211,6 +235,12 @@
DUP #40 AND ?{ ;dict/uxn-wst-ptr !<pstr> }
;dict/uxn-rst-ptr !<pstr>
@<ram> ( -- )
;dict/uxn-ram !<pstr>
@<pc> ( -- )
;dict/pc !<pstr>
(
@|utils )
@ -248,7 +278,7 @@
00 &jsi "JSI 00 ]
@dict ( strings )
&start "int 0a "uxn_eval(Uxn 20 "*u, 20 "Uint16 20 "pc) 20 "{ 0a 09 "Uint8 20 "*ram 20 "= 20 "u->ram; 0a 09 "switch(ram[pc]) 20 "{ $1
&start "int 0a "uxn_eval(Uint16 20 "pc) 20 "{ 0a 09 "Uint8 20 "*ram 20 "= 20 "u->ram; 0a 09 "switch(ram[pc]) 20 "{ $1
&end 09 "} 0a "} 0a $1
&case 09 "case 20 $1
&break "break; $1
@ -257,4 +287,6 @@
&uxn-wst-ptr "uxn.wst.ptr $1
&uxn-rst-dat "uxn.rst.dat $1
&uxn-rst-ptr "uxn.rst.ptr $1
&uxn-ram "uxn.ram $1
&pc "pc $1