diff --git a/examples/uxnSierpinski/header.tal b/examples/uxnSierpinski/header.tal new file mode 100644 index 0000000..6813e75 --- /dev/null +++ b/examples/uxnSierpinski/header.tal @@ -0,0 +1,3 @@ +|00 @System &vector $2 &pad $6 &r $2 &g $2 &b $2 +|10 @Console &vector $2 &read $1 &pad $5 &write $1 &error $1 +|20 @Screen &vector $2 &width $2 &height $2 &auto $1 &pad $1 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1 diff --git a/examples/uxnSierpinski/main.cal b/examples/uxnSierpinski/main.cal new file mode 100644 index 0000000..6f15c72 --- /dev/null +++ b/examples/uxnSierpinski/main.cal @@ -0,0 +1,68 @@ +# Compile with: +# cac main.cal -b uxn -i ../../std -h header.tal -o sierpinski.rom + +include "cores/select.cal" + +func init_palette begin asm + # 0f 0f 3f 0f 0e 0f + "#0f0f .System/r DEO2" + "#3f0f .System/g DEO2" + "#0e0f .System/b DEO2" +end end + +func set_screen_size begin asm # width, height + ".Screen/height DEO2" + ".Screen/width DEO2" +end end + +func get_screen_size begin asm # -> width, height + ".Screen/width DEI2" + ".Screen/height DEI2" +end end + +inline draw_pixel begin asm # colour, x, y + ".Screen/y DEO2" + ".Screen/x DEO2" + "NIP .Screen/pixel DEO" +end end + +func sierpinski begin + let cell n + let cell x + let cell y + let cell pad + let cell rowStart + 2 * n ! + + 0 y ! + n @ 2 / pad ! + + n @ 2 / n @ 2 / set_screen_size + + while y @ n @ 2 / < do + 0 x ! + + while x @ pad @ < do + x @ 1 + x ! + end + + x @ 2 / rowStart ! + 0 x ! + + while x @ n @ < do + if x @ n @ y @ 1 + - and then + + else + 1 x @ rowStart @ + y @ draw_pixel + end + + x @ 1 + x ! + end + + y @ 1 + y ! + pad @ 1 - pad ! + end +end + +init_palette +512 sierpinski diff --git a/source/app.d b/source/app.d index 7945b98..4f1fef6 100644 --- a/source/app.d +++ b/source/app.d @@ -301,10 +301,12 @@ int main(string[] args) { catch (PreprocessorError) { return 1; } - - /*auto codeRemover = new CodeRemover(); - codeRemover.Run(nodes); - nodes = codeRemover.res;*/ + + if (optimise) { + auto codeRemover = new CodeRemover(); + codeRemover.Run(nodes); + nodes = codeRemover.res; + } compiler.versions = preproc.versions; diff --git a/source/backends/uxn.d b/source/backends/uxn.d index 9d6c245..54cdd34 100644 --- a/source/backends/uxn.d +++ b/source/backends/uxn.d @@ -115,7 +115,6 @@ class BackendUXN : CompilerBackend { override long MaxInt() => 0xFFFF; override string DefaultHeader() => " - |0 @vsp $2 @arraySrc $2 @arrayDest $2 |10 @Console &vector $2 &read $1 &pad $5 &write $1 &error $1 "; @@ -153,7 +152,6 @@ class BackendUXN : CompilerBackend { override void Init() { output ~= "|0 @vsp $2 @arraySrc $2 @arrayDest $2\n"; - output ~= "|10 @Console &vector $2 &read $1 &pad $5 &write $1 &error $1\n"; output ~= "|100\n"; output ~= "@on-reset\n"; output ~= " #ffff .vsp STZ2\n";