(mandelbrot.tal) Migrated to immediate opcodes
This commit is contained in:
parent
617e3d1f41
commit
895bfc8675
|
@ -1,80 +1,77 @@
|
||||||
( mandelbrot )
|
( mandelbrot )
|
||||||
|
|
||||||
%GTS2 { #8000 ADD2 SWP2 #8000 ADD2 LTH2 }
|
%WIDTH { #02a0 }
|
||||||
%AUTO-X { #01 .Screen/auto DEO }
|
%HEIGHT { #0200 }
|
||||||
%NEXT-LINE { #0000 .Screen/x DEO2 .Screen/y DEI2k INC2 ROT DEO2 }
|
|
||||||
|
|
||||||
%WIDTH { #0280 }
|
|
||||||
%HEIGHT { #01e0 }
|
|
||||||
|
|
||||||
%XMIN { #de69 } ( -8601 )
|
%XMIN { #de69 } ( -8601 )
|
||||||
%XMAX { #0b33 } ( 2867 )
|
%XMAX { #0b33 } ( 2867 )
|
||||||
%YMIN { #ecc7 } ( -4915 )
|
%YMIN { #ecc7 } ( -4915 )
|
||||||
%YMAX { #1333 } ( 4915 )
|
%YMAX { #1333 } ( 4915 )
|
||||||
%MAXI { #20 } ( 32 )
|
|
||||||
%DX { XMAX XMIN SUB2 WIDTH DIV2 } ( (XMAX-XMIN)/W )
|
|
||||||
%DY { YMAX YMIN SUB2 HEIGHT DIV2 } ( (YMAX-YMIN)/H )
|
|
||||||
%X { .x LDZ2 } %Y { .y LDZ2 }
|
|
||||||
%X2 { .x2 LDZ2 } %Y2 { .y2 LDZ2 }
|
|
||||||
|
|
||||||
|00 @System &vector $2 &wst $1 &rst $1 &eaddr $2 &ecode $1 &pad $1 &r $2 &g $2 &b $2 &debug $1 &halt $1
|
|00 @System &vector $2 &wst $1 &rst $1 &eaddr $2 &ecode $1 &pad $1 &r $2 &g $2 &b $2 &debug $1 &halt $1
|
||||||
|20 @Screen &vector $2 &width $2 &height $2 &auto $1 &pad $1 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1
|
|20 @Screen &vector $2 &width $2 &height $2 &auto $1 &pad $1 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1
|
||||||
|
|
||||||
|0000 ( zero-page )
|
|
||||||
|
|
||||||
@x $2 @y $2
|
|
||||||
@x2 $2 @y2 $2
|
|
||||||
|
|
||||||
|0100 ( -> )
|
|0100 ( -> )
|
||||||
|
|
||||||
( theme )
|
( theme )
|
||||||
#0f0f .System/r DEO2
|
#0f0f .System/r DEO2
|
||||||
#0ff0 .System/g DEO2
|
#0ff0 .System/g DEO2
|
||||||
#00ff .System/b DEO2
|
#00ff .System/b DEO2
|
||||||
|
|
||||||
WIDTH .Screen/width DEO2 ( 640 )
|
WIDTH .Screen/width DEO2 ( 640 )
|
||||||
HEIGHT .Screen/height DEO2 ( 480 )
|
HEIGHT .Screen/height DEO2 ( 480 )
|
||||||
|
|
||||||
AUTO-X
|
draw-mandel
|
||||||
|
|
||||||
;draw-mandel JSR2
|
|
||||||
|
|
||||||
BRK
|
BRK
|
||||||
|
|
||||||
@draw-mandel ( -- )
|
@draw-mandel ( -- )
|
||||||
|
|
||||||
|
XMAX XMIN SUB2 WIDTH DIV2 ;&dx STA2
|
||||||
|
YMAX YMIN SUB2 HEIGHT DIV2 ;&dy STA2
|
||||||
|
[ LIT2 01 -Screen/auto ] DEO
|
||||||
YMAX YMIN
|
YMAX YMIN
|
||||||
&ver
|
&ver
|
||||||
DUP2 ,&y STR2
|
DUP2 ,&y STR2
|
||||||
XMAX XMIN
|
XMAX XMIN
|
||||||
&hor
|
&hor
|
||||||
DUP2 ,&x STR2
|
DUP2 ,&x STR2
|
||||||
#0000 DUP2k DUP2 .x STZ2 .y STZ2 .x2 STZ2 .y2 STZ2
|
#0000
|
||||||
MAXI #00
|
DUP2 ,&x1 STR2
|
||||||
|
DUP2 ,&y1 STR2
|
||||||
|
DUP2 ,&x2 STR2
|
||||||
|
,&y2 STR2
|
||||||
|
( pixel )
|
||||||
|
#2000
|
||||||
&loop
|
&loop
|
||||||
X Y ;smul2 JSR2 DUP2 ADD2 [ LIT2 &y $2 ] ADD2 .y STZ2
|
[ LIT2 &x1 $2 ] [ LIT2 &y1 $2 ] smul2 DUP2 ADD2
|
||||||
X2 Y2 SUB2 [ LIT2 &x $2 ] ADD2 .x STZ2
|
[ LIT2 &y $2 ] ADD2 ,&y1 STR2
|
||||||
X DUP2 ;smul2 JSR2 .x2 STZ2
|
[ LIT2 &x2 $2 ] [ LIT2 &y2 $2 ] SUB2
|
||||||
Y DUP2 ;smul2 JSR2 .y2 STZ2
|
[ LIT2 &x $2 ] ADD2 ,&x1 STR2
|
||||||
X2 Y2 ADD2 #4000 GTH2 ,&end JCN
|
,&x1 LDR2 DUP2 smul2
|
||||||
INC GTHk ,&loop JCN
|
DUP2 ,&x2 STR2
|
||||||
|
,&y1 LDR2 DUP2 smul2
|
||||||
|
DUP2 ,&y2 STR2
|
||||||
|
ADD2 #4000 GTH2 ?&end
|
||||||
|
INC GTHk ?&loop
|
||||||
&end
|
&end
|
||||||
NIP .Screen/pixel DEO
|
NIP .Screen/pixel DEO
|
||||||
DX ADD2 OVR2 OVR2 GTS2 ;&hor JCN2
|
( done. )
|
||||||
|
[ LIT2 &dx $2 ] ADD2 OVR2 #8000 ADD2 OVR2 #8000 ADD2 SWP2 LTH2 ?&hor
|
||||||
POP2 POP2
|
POP2 POP2
|
||||||
NEXT-LINE
|
#0000 .Screen/x DEO2
|
||||||
DY ADD2 OVR2 OVR2 GTS2 ;&ver JCN2
|
.Screen/y DEI2k INC2 ROT DEO2
|
||||||
|
[ LIT2 &dy $2 ] ADD2 OVR2 #8000 ADD2 OVR2 #8000 ADD2 SWP2 LTH2 ?&ver
|
||||||
POP2 POP2
|
POP2 POP2
|
||||||
|
|
||||||
JMP2r
|
JMP2r
|
||||||
|
|
||||||
@smul2 ( a* b* -- c* )
|
@smul2 ( a* b* -- c* )
|
||||||
LITr 00
|
LITr 00
|
||||||
DUP2 #8000 LTH2 ,&b-positive JCN
|
DUP2 #8000 LTH2 ?&b-positive
|
||||||
INCr DUP2k EOR2 SWP2 SUB2
|
INCr DUP2k EOR2 SWP2 SUB2
|
||||||
&b-positive
|
&b-positive
|
||||||
SWP2
|
SWP2
|
||||||
DUP2 #8000 LTH2 ,&a-positive JCN
|
DUP2 #8000 LTH2 ?&a-positive
|
||||||
INCr DUP2k EOR2 SWP2 SUB2
|
INCr DUP2k EOR2 SWP2 SUB2
|
||||||
&a-positive
|
&a-positive
|
||||||
( ahi alo bhi blo )
|
( ahi alo bhi blo )
|
||||||
|
@ -97,8 +94,9 @@ JMP2r
|
||||||
( The result we want is bits 27-12 due to the fixed point representation we use. )
|
( The result we want is bits 27-12 due to the fixed point representation we use. )
|
||||||
#04 SFT2 SWP2 #40 SFT2 ADD2
|
#04 SFT2 SWP2 #40 SFT2 ADD2
|
||||||
( saturate to +/-7.fff )
|
( saturate to +/-7.fff )
|
||||||
#7fff GTH2k JMP SWP2 NIP2
|
#7fff GTH2k [ JMP SWP2 NIP2 ]
|
||||||
STHr #01 NEQ ,&result-positive JCN
|
STHr #01 NEQ ?&result-positive
|
||||||
DUP2k EOR2 SWP2 SUB2
|
DUP2k EOR2 SWP2 SUB2
|
||||||
&result-positive
|
&result-positive
|
||||||
JMP2r
|
JMP2r
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ WITH REGARD TO THIS SOFTWARE.
|
||||||
#define N2 PEEK16(s->dat+s->ptr-4)
|
#define N2 PEEK16(s->dat+s->ptr-4)
|
||||||
#define L2 PEEK16(s->dat+s->ptr-6)
|
#define L2 PEEK16(s->dat+s->ptr-6)
|
||||||
|
|
||||||
#define HALT(c) { return uxn_halt(u, instr, (c), pc - 1); }
|
#define HALT(c) { return uxn_halt(u, ins, (c), pc - 1); }
|
||||||
#define INC(mul, add) { if(mul > s->ptr) HALT(1) s->ptr += k * mul + add; if(s->ptr > 255) HALT(2) }
|
#define INC(mul, add) { if(mul > s->ptr) HALT(1) s->ptr += k * mul + add; if(s->ptr > 255) HALT(2) }
|
||||||
#define DEC(mul, sub) { if(mul > s->ptr) HALT(1) s->ptr -= !k * mul - sub; if(s->ptr > 255) HALT(2) }
|
#define DEC(mul, sub) { if(mul > s->ptr) HALT(1) s->ptr -= !k * mul - sub; if(s->ptr > 255) HALT(2) }
|
||||||
#define PUT(o, v) { s->dat[s->ptr - o - 1] = (v); }
|
#define PUT(o, v) { s->dat[s->ptr - o - 1] = (v); }
|
||||||
|
@ -40,17 +40,15 @@ WITH REGARD TO THIS SOFTWARE.
|
||||||
int
|
int
|
||||||
uxn_eval(Uxn *u, Uint16 pc)
|
uxn_eval(Uxn *u, Uint16 pc)
|
||||||
{
|
{
|
||||||
Uint8 instr, opc, k;
|
Uint8 ins, opc, k;
|
||||||
Uint16 t, n, l, tmp;
|
Uint16 t, n, l, tmp;
|
||||||
Stack *s;
|
Stack *s;
|
||||||
if(!pc || u->dev[0x0f]) return 0;
|
if(!pc || u->dev[0x0f]) return 0;
|
||||||
for(;;) {
|
for(;;) {
|
||||||
instr = u->ram[pc++];
|
ins = u->ram[pc++];
|
||||||
k = !!(instr & 0x80);
|
k = !!(ins & 0x80);
|
||||||
s = instr & 0x40 ? u->rst : u->wst;
|
s = ins & 0x40 ? u->rst : u->wst;
|
||||||
opc = instr & 0x3f;
|
opc = !(ins & 0x1f) ? 0 - (ins >> 5) : ins & 0x3f;
|
||||||
if(!(instr & 0x1f))
|
|
||||||
opc = 0 - (instr >> 5);
|
|
||||||
switch(opc) {
|
switch(opc) {
|
||||||
/* IMM */
|
/* IMM */
|
||||||
case 0x00: /* BRK */ return 1;
|
case 0x00: /* BRK */ return 1;
|
||||||
|
@ -90,8 +88,8 @@ uxn_eval(Uxn *u, Uint16 pc)
|
||||||
case 0x0d: /* JCN */ t=T;n=N; DEC(2, 0) pc += !!n * (Sint8)t; break;
|
case 0x0d: /* JCN */ t=T;n=N; DEC(2, 0) pc += !!n * (Sint8)t; break;
|
||||||
case 0x2e: /* JSR2 */ t=T2; DEC(2, 0) PUSH2(u->rst, pc) pc = t; break;
|
case 0x2e: /* JSR2 */ t=T2; DEC(2, 0) PUSH2(u->rst, pc) pc = t; break;
|
||||||
case 0x0e: /* JSR */ t=T; DEC(1, 0) PUSH2(u->rst, pc) pc += (Sint8)t; break;
|
case 0x0e: /* JSR */ t=T; DEC(1, 0) PUSH2(u->rst, pc) pc += (Sint8)t; break;
|
||||||
case 0x2f: /* STH2 */ t=T2; if(instr & 0x40){ u->rst->ptr -= !k * 2; PUSH2(u->wst, t); } else{ u->wst->ptr -= !k * 2; PUSH2(u->rst, t); } break;
|
case 0x2f: /* STH2 */ t=T2; if(ins & 0x40) { u->rst->ptr -= !k * 2; PUSH2(u->wst, t); } else{ u->wst->ptr -= !k * 2; PUSH2(u->rst, t); } break;
|
||||||
case 0x0f: /* STH */ t=T; if(instr & 0x40){ u->rst->ptr -= !k; PUSH(u->wst, t); } else{ u->wst->ptr -= !k; PUSH(u->rst, t); } break;
|
case 0x0f: /* STH */ t=T; if(ins & 0x40) { u->rst->ptr -= !k; PUSH(u->wst, t); } else{ u->wst->ptr -= !k; PUSH(u->rst, t); } break;
|
||||||
case 0x30: /* LDZ2 */ t=T; INC(1, 1) PUT2(0, PEEK16(u->ram + t)) break;
|
case 0x30: /* LDZ2 */ t=T; INC(1, 1) PUT2(0, PEEK16(u->ram + t)) break;
|
||||||
case 0x10: /* LDZ */ t=T; INC(1, 0) PUT(0, u->ram[t]) break;
|
case 0x10: /* LDZ */ t=T; INC(1, 0) PUT(0, u->ram[t]) break;
|
||||||
case 0x31: /* STZ2 */ t=T;n=H2; DEC(3, 0) POKE16(u->ram + t, n) break;
|
case 0x31: /* STZ2 */ t=T;n=H2; DEC(3, 0) POKE16(u->ram + t, n) break;
|
||||||
|
|
Loading…
Reference in New Issue