commit 9addd15675031549f5963ad97dbcb6d074df9d98
parent 2880f598215ccb3f27548e300b80c54baa4a8e29
Author: neauoire <aliceffekt@gmail.com>
Date: Fri, 23 Apr 2021 11:17:17 -0700
Added bifurcan
Diffstat:
2 files changed, 179 insertions(+), 1 deletion(-)
diff --git a/build.sh b/build.sh
@@ -32,7 +32,7 @@ else
fi
echo "Assembling.."
-./bin/assembler projects/examples/devices/datetime.usm bin/boot.rom
+./bin/assembler projects/demos/bifurcan.usm bin/boot.rom
echo "Running.."
if [ "${2}" = '--cli' ];
diff --git a/projects/demos/bifurcan.usm b/projects/demos/bifurcan.usm
@@ -0,0 +1,178 @@
+( a blank file )
+
+%RTN { JMP2r }
+%8+ { #0008 ADD2 }
+%2/ { #0002 DIV2 }
+%MOD { DUP2 DIV MUL SUB }
+%INC { #01 ADD }
+%TOS { #00 SWP }
+
+( devices )
+
+|00 @System [ &vector $2 &pad $6 &r $2 &g $2 &b $2 ]
+|10 @Console [ &pad $8 &char $1 &byte $1 &short $2 &string $2 ]
+|20 @Screen [ &vector $2 &width $2 &height $2 &pad $2 &x $2 &y $2 &addr $2 &color $1 ]
+|60 @Mouse [ &vector $2 &x $2 &y $2 &state $1 &chord $1 ]
+|a0 @DateTime [ &year $2 &month $1 &day $1 &hour $1 &minute $1 &second $1 &dotw $1 &doty $2 &isdst $1 &refresh $1 ]
+
+( variables )
+
+|0000
+
+@last $1
+@color $1
+@style $1
+@pointer [ &x $2 &y $2 ]
+@center [ &x $2 &y $2 ]
+@anchor [ &x $2 &y $2 ]
+
+( program )
+
+|0100 ( -> )
+
+ ( theme )
+ #0f3a .System/r DEO2
+ #0fda .System/g DEO2
+ #0faa .System/b DEO2
+
+ ( vectors )
+ ;on-frame .Screen/vector DEO2
+ ;on-mouse .Mouse/vector DEO2
+
+ ( find center )
+ .Screen/width DEI2 2/ .center/x POK2
+ .Screen/height DEI2 2/ .center/y POK2
+
+ ( background )
+ ;tiles #21 ;cover-pattern JSR2
+ ;redraw JSR2
+
+BRK
+
+@on-frame ( -> )
+
+ #00 .DateTime/refresh DEO
+
+ ( only draw once per second )
+ .DateTime/second DEI .last PEK NEQ #01 JNZ [ BRK ]
+ .DateTime/second DEI .last POK
+
+ ;redraw JSR2
+
+BRK
+
+@on-mouse ( -> )
+
+ ;draw-cursor JSR2
+
+ .Mouse/state DEI #00 EQU ,&no-touch JNZ
+ .style PEK INC #03 MOD .style POK
+ .style PEK .Console/byte DEO
+ ;tiles .style PEK #10 MUL TOS ADD2 #21 ;cover-pattern JSR2
+ ;redraw JSR2
+ ( release ) #00 .Mouse/state DEO
+ &no-touch
+
+BRK
+
+@redraw ( -- )
+
+ ( hrs )
+ [ .center/x PEK2 #0018 SUB2 ]
+ [ .center/y PEK2 #0048 SUB2 ]
+ .DateTime/hour DEI #0a DIV ;draw-number JSR2
+ [ .center/x PEK2 #0008 ADD2 ]
+ [ .center/y PEK2 #0048 SUB2 ]
+ .DateTime/hour DEI #0a MOD ;draw-number JSR2
+ ( min )
+ [ .center/x PEK2 #0018 SUB2 ]
+ [ .center/y PEK2 #0018 SUB2 ]
+ .DateTime/minute DEI #0a DIV ;draw-number JSR2
+ [ .center/x PEK2 #0008 ADD2 ]
+ [ .center/y PEK2 #0018 SUB2 ]
+ .DateTime/minute DEI #0a MOD ;draw-number JSR2
+ ( sec )
+ [ .center/x PEK2 #0018 SUB2 ]
+ [ .center/y PEK2 #0018 ADD2 ]
+ .DateTime/second DEI #0a DIV
+ ;draw-number JSR2
+ [ .center/x PEK2 #0008 ADD2 ]
+ [ .center/y PEK2 #0018 ADD2 ]
+ .DateTime/second DEI #0a MOD
+ ;draw-number JSR2
+
+RTN
+
+@draw-number ( x y n -- )
+
+ STH
+ ( save pos ) .anchor/y POK2 .anchor/x POK2
+ #00 #0f
+ &loop
+ ( save-x ) OVR #03 MOD TOS #0008 MUL2 .anchor/x PEK2 ADD2 .Screen/x DEO2
+ ( save-y ) OVR #03 DIV TOS #0008 MUL2 .anchor/y PEK2 ADD2 .Screen/y DEO2
+ ( get digit* ) OVR DUPr STHr #02 MUL TOS ;digits ADD2 GET2
+ ( get bit ) ROT #0e SWP SUB TOS SFT2 #0001 AND2
+ ( set tile ) #0008 MUL2 ;tiles ADD2
+ ( set style ) .style PEK #10 MUL TOS ADD2
+ .Screen/addr DEO2
+ ( draw ) #21 .Screen/color DEO
+ ( incr ) SWP INC SWP
+ DUP2 LTH ,&loop JNZ
+ POP2
+ POPr
+
+RTN
+
+@cover-pattern ( addr color -- )
+
+ ( load ) .color POK .Screen/addr DEO2
+ #0000 .Screen/height DEI2
+ &ver
+ ( save ) OVR2 .Screen/y DEO2
+ #0000 .Screen/width DEI2
+ &hor
+ ( save ) OVR2 .Screen/x DEO2
+ ( draw ) .color PEK .Screen/color DEO
+ ( incr ) SWP2 8+ SWP2
+ OVR2 OVR2 LTH2 ,&hor JNZ
+ POP2 POP2
+ ( incr ) SWP2 8+ SWP2
+ OVR2 OVR2 LTH2 ,&ver JNZ
+ POP2 POP2
+
+RTN
+
+@draw-cursor ( -- )
+
+ ( clear last cursor )
+ ;clear .Screen/addr DEO2
+ .pointer/x PEK2 .Screen/x DEO2
+ .pointer/y PEK2 .Screen/y DEO2
+ #30 .Screen/color DEO
+ ( record pointer positions )
+ .Mouse/x DEI2 .pointer/x POK2
+ .Mouse/y DEI2 .pointer/y POK2
+ ( draw new cursor )
+ ;cursor .Screen/addr DEO2
+ .pointer/x PEK2 .Screen/x DEO2
+ .pointer/y PEK2 .Screen/y DEO2
+ ( colorize on state )
+ #31 [ .Mouse/state DEI #00 NEQ ] ADD .Screen/color DEO
+
+RTN
+
+@clear [
+ 0000 0000 0000 0000 ]
+@cursor [
+ 80c0 e0f0 f8e0 1000 ]
+@digits [
+ 7b6f 2492 73e7 73cf 5bc9
+ 79cf 49ef 7249 7bef 7bc9 ]
+@tiles [
+ 0102 0408 1020 4080
+ 8040 2010 0804 0201
+ 0718 2040 4080 8080
+ 0101 0102 0204 18e0
+ 0808 0810 e304 0808
+ 0808 0804 e310 0808 ]