From e289b359d865f205205dce7d4709752ccda2b056 Mon Sep 17 00:00:00 2001 From: neauoire Date: Sat, 15 May 2021 13:09:11 -0700 Subject: [PATCH] Ported automata --- build.sh | 2 +- projects/demos/automata.usm | 119 +++++++++++++++++++++++++++++++ projects/examples/gui/shapes.usm | 24 +++++++ 3 files changed, 144 insertions(+), 1 deletion(-) create mode 100644 projects/demos/automata.usm diff --git a/build.sh b/build.sh index b693f10..166cd25 100755 --- a/build.sh +++ b/build.sh @@ -42,7 +42,7 @@ then fi echo "Assembling.." -./bin/uxnasm projects/demos/polycat.usm bin/boot.rom +./bin/uxnasm projects/demos/life.usm bin/boot.rom echo "Running.." if [ "${2}" = '--cli' ]; diff --git a/projects/demos/automata.usm b/projects/demos/automata.usm new file mode 100644 index 0000000..f69de4c --- /dev/null +++ b/projects/demos/automata.usm @@ -0,0 +1,119 @@ +( Project by Alex Schroeder - https://alexschroeder.ch ) + +%RTN { JMP2r } +%INCR { SWP #01 ADD SWP } +%CELL { #1000 } +%NEXT { #2000 } + +( devices ) + +|00 @System [ &vector $2 &pad $6 &r $2 &g $2 &b $2 ] +|20 @Screen [ &vector $2 &width $2 &height $2 &pad $2 &x $2 &y $2 &addr $2 &color $1 ] +|b0 @DateTime [ &year $2 &month $1 &day $1 &hour $1 &minute $1 &second $1 &dotw $1 &doty $2 &isdst $1 ] + +|0000 + +( program ) + +@seed [ &x $1 &w $2 &s $2 ] + +|0100 ( -> ) + + ( theme ) + #2aac .System/r DEO2 + #269b .System/g DEO2 + #378d .System/b DEO2 + + ;seed-line JSR2 + + ( run for a few generations ) + #00 #ff + &loop + OVR #00 SWP ;print-line JSR2 + ;compute-next JSR2 + ;copy-next JSR2 + ( incr ) INCR + ( loop ) LTHk ,&loop JCN + POP2 + +BRK + +@print-line ( y -- ) + + ( set ) .Screen/y DEO2 + ( loop through cells ) + #00 #ff + &loop + ( copy ) OVR #00 SWP DUP2 + ( pos ) .Screen/x DEO2 + ( addr ) CELL ADD2 + ( draw ) LDA .Screen/color DEO + ( incr ) INCR + ( loop ) LTHk ,&loop JCN + POP2 + +RTN + +@compute-next ( -- ) + + ( loop through 62 cells ) + #01 #fe + &loop + OVR DUP DUP ( three copies of the counter ) + #01 SUB #00 SWP CELL ADD2 LDA + SWP + #01 ADD #00 SWP CELL ADD2 LDA + ( the cell dies if the neighbors are either both dead or both alive, i.e. Rule 90 ) + NEQ + ( one copy of the counter and the life value ) + SWP #00 SWP NEXT ADD2 STA + ( incr ) INCR + ( loop ) LTHk ,&loop JCN + POP2 + +RTN + +@copy-next ( -- ) + + ( loop through cells ) + #00 #ff + &loop + OVR DUP ( two copies of the counter ) + #00 SWP NEXT ADD2 LDA ( one copy of the counter and the value ) + SWP #00 SWP CELL ADD2 STA + ( incr ) INCR + ( loop ) LTHk ,&loop JCN + POP2 + +RTN + +@seed-line ( -- ) + + .DateTime/second DEI .seed/x STZ + #0000 .seed/w STZ2 + #e2a9 .seed/s STZ2 + ( loop through cells ) + #01 #fe + &loop + OVR ( one copy of the counter ) + ;rand JSR2 + #10 AND ( pick a bit ) + SWP #00 SWP CELL ADD2 STA + ( incr ) INCR + ( loop ) LTHk ,&loop JCN + POP2 + +RTN + +( https://en.wikipedia.org/wiki/Middle-square_method ) + +@rand ( -- 1 ) + + .seed/x LDZ #00 SWP DUP2 MUL2 + .seed/w LDZ2 .seed/s LDZ2 ADD2 + DUP2 .seed/w STZ2 + ADD2 + #04 SFT SWP #40 SFT ADD + DUP .seed/x STZ + +RTN \ No newline at end of file diff --git a/projects/examples/gui/shapes.usm b/projects/examples/gui/shapes.usm index 6e04c1c..31b5ec6 100644 --- a/projects/examples/gui/shapes.usm +++ b/projects/examples/gui/shapes.usm @@ -160,4 +160,28 @@ RTN RTN +@line-hor ( x0* x1* y* color -- ) + + STH .Screen/y DEO2 + &loop + ( save ) OVR2 .Screen/x DEO2 + ( draw ) STHkr .Screen/color DEO + ( incr ) SWP2 #0002 ++ SWP2 + LTH2k ,&loop JCN + POP2 POP2 POPr + +RTN + +@line-ver ( x* y0* y1* color -- ) + + STH ROT2 .Screen/x DEO2 + &loop + ( save ) OVR2 .Screen/y DEO2 + ( draw ) STHkr .Screen/color DEO + ( incr ) SWP2 #0002 ++ SWP2 + LTH2k ,&loop JCN + POP2 POP2 POPr + +RTN + @checker_icn [ f0f0 f0f0 0f0f 0f0f ]