Skip to content

Commit

Permalink
add uxn sierpinski example
Browse files Browse the repository at this point in the history
  • Loading branch information
yeti0904 committed Jun 7, 2024
1 parent 05f2180 commit e1fb145
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 6 deletions.
3 changes: 3 additions & 0 deletions examples/uxnSierpinski/header.tal
Original file line number Diff line number Diff line change
@@ -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
68 changes: 68 additions & 0 deletions examples/uxnSierpinski/main.cal
Original file line number Diff line number Diff line change
@@ -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
10 changes: 6 additions & 4 deletions source/app.d
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 0 additions & 2 deletions source/backends/uxn.d
Original file line number Diff line number Diff line change
Expand Up @@ -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
";

Expand Down Expand Up @@ -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";
Expand Down

0 comments on commit e1fb145

Please sign in to comment.