0
0
Fork 0
mirror of https://git.sr.ht/~rabbits/uxn synced 2024-11-30 17:53:01 +00:00
uxn/projects/examples/demos/mandelbrot.tal

108 lines
2.9 KiB
Tal
Raw Normal View History

2022-02-07 23:52:22 +00:00
( mandelbrot )
%+ { ADD } %- { SUB } %* { MUL } %/ { DIV }
%< { LTH } %> { GTH } %= { EQU } %! { NEQ }
2022-02-08 00:59:34 +00:00
%GTS2 { #8000 ADD2 SWP2 #8000 ADD2 LTH2 }
2022-02-07 23:52:22 +00:00
%AUTO-X { #01 .Screen/auto DEO }
%NEXT-LINE { #0000 .Screen/x DEO2 .Screen/y DEI2k INC2 ROT DEO2 }
2022-02-08 00:59:34 +00:00
%WIDTH { #0280 }
%HEIGHT { #01e0 }
2022-02-07 23:52:22 +00:00
%XMIN { #de69 } ( -8601 )
%XMAX { #0b33 } ( 2867 )
%YMIN { #ecc7 } ( -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 )
2022-02-08 00:59:34 +00:00
%X { .x LDZ2 } %Y { .y LDZ2 }
2022-02-07 23:52:22 +00:00
%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
|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 ( -> )
( theme )
2022-02-08 00:59:34 +00:00
#0f0f .System/r DEO2
#0ff0 .System/g DEO2
#00ff .System/b DEO2
2022-02-07 23:52:22 +00:00
2022-02-08 00:59:34 +00:00
WIDTH .Screen/width DEO2 ( 640 )
HEIGHT .Screen/height DEO2 ( 480 )
2022-02-07 23:52:22 +00:00
AUTO-X
2022-02-08 00:59:34 +00:00
2022-02-07 23:52:22 +00:00
;draw-mandel JSR2
BRK
@draw-mandel ( -- )
YMAX YMIN
&ver
DUP2 ,&y STR2
XMAX XMIN
&hor
DUP2 ,&x STR2
#0000 DUP2k DUP2 .x STZ2 .y STZ2 .x2 STZ2 .y2 STZ2
2022-02-07 23:52:22 +00:00
MAXI #00
&loop
X Y ;smul2 JSR2 DUP2 ADD2 [ LIT2 &y $2 ] ADD2 .y STZ2
X2 Y2 SUB2 [ LIT2 &x $2 ] ADD2 .x STZ2
2022-02-08 00:59:34 +00:00
X DUP2 ;smul2 JSR2 .x2 STZ2
Y DUP2 ;smul2 JSR2 .y2 STZ2
X2 Y2 ADD2 #4000 GTH2 ,&end JCN
2022-02-07 23:52:22 +00:00
INC GTHk ,&loop JCN
&end
2022-02-08 00:59:34 +00:00
NIP .Screen/pixel DEO
DX ADD2 OVR2 OVR2 GTS2 ;&hor JCN2
2022-02-07 23:52:22 +00:00
POP2 POP2
NEXT-LINE
DY ADD2 OVR2 OVR2 GTS2 ;&ver JCN2
2022-02-07 23:52:22 +00:00
POP2 POP2
JMP2r
@smul2 ( a* b* -- c* )
2022-02-08 00:59:34 +00:00
LITr 00
DUP2 #8000 LTH2 ,&b-positive JCN
INCr DUP2k EOR2 SWP2 SUB2
&b-positive
2022-02-07 23:52:22 +00:00
SWP2
2022-02-08 00:59:34 +00:00
DUP2 #8000 LTH2 ,&a-positive JCN
INCr DUP2k EOR2 SWP2 SUB2
&a-positive
( ahi alo bhi blo )
LITr 00 STH ( ahi alo bhi / blo* )
OVRr STH ( ahi alo / blo* bhi* )
OVRr STH ( ahi / blo* bhi* alo* )
OVRr STH ( asign / blo* bhi* alo* ahi* )
ROT2r MUL2kr STH2r ( asign ahi-bhi* / blo* alo* ahi* bhi* )
ROT2r MUL2kr STH2r ( asign ahi-bhi* alo-bhi* / blo* ahi* bhi* alo* )
NIP2r ( asign ahi-bhi* alo-bhi* / blo* ahi* alo* )
ROT2r MUL2kr STH2r ( asign ahi-bhi* alo-bhi* alo-blo* / ahi* alo* blo* )
ROT2r MUL2r STH2r POP2r ( asign ahi-bhi* alo-bhi* alo-blo* ahi-blo* )
SWP2 ( asign ahi-bhi* alo-bhi* ahi-blo* alo-blo* )
( 32-bit result is [ r3 r2 r1 r0 ] )
POP #00 SWP ( asign ahi-bhi* alo-bhi* ahi-blo* r21* )
( r21 max is 00fe, ahi-blo max is 7e81, max sum is 7f7f )
ADD2 ( asign ahi-bhi* alo-bhi* r21'* )
( r21' max is 7f7f, alo-bhi max is 7e81, max sum is fe00 )
ADD2 ( asign ahi-bhi* r21"* )
( The result we want is bits 27-12 due to the fixed point representation we use. )
#04 SFT2 SWP2 #40 SFT2 ADD2
2022-02-08 01:32:41 +00:00
( saturate to +/-7.fff )
#7fff GTH2k JMP SWP2 NIP2
STHr #01 NEQ ,&result-positive JCN
DUP2k EOR2 SWP2 SUB2
&result-positive
2022-02-07 23:52:22 +00:00
JMP2r