uxn

Varvara Ordinator, written in ANSI C(SDL2)
git clone https://git.eamoncaddigan.net/uxn.git
Log | Files | Refs | README | LICENSE

commit 6262078a047a710091be08546fd5e7ed3ff566a0
parent 7dfce364a5e334f41b086987a9cc9ea3728833c2
Author: Devine Lu Linvega <aliceffekt@gmail.com>
Date:   Sat, 20 Nov 2021 15:38:01 -0500

(logic.tal) Starting logic gates playground

Diffstat:
Aprojects/examples/demos/logic.tal | 186+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 186 insertions(+), 0 deletions(-)

diff --git a/projects/examples/demos/logic.tal b/projects/examples/demos/logic.tal @@ -0,0 +1,186 @@ +( a blank file ) + +%+ { ADD } %- { SUB } %/ { DIV } +%< { LTH } %> { GTH } %= { EQU } %! { NEQ } +%++ { ADD2 } %-- { SUB2 } %// { DIV2 } +%<< { LTH2 } %>> { GTH2 } %== { EQU2 } %!! { NEQ2 } + +%2* { #10 SFT } %2/ { #01 SFT } +%4* { #20 SFT } %4/ { #02 SFT } +%8* { #30 SFT } %8/ { #03 SFT } +%10* { #40 SFT } %10/ { #04 SFT } +%20* { #50 SFT } %20/ { #05 SFT } + +%2** { #10 SFT2 } %2// { #01 SFT2 } +%4** { #20 SFT2 } %4// { #02 SFT2 } +%8** { #30 SFT2 } %8// { #03 SFT2 } +%10** { #40 SFT2 } %10// { #04 SFT2 } +%20** { #50 SFT2 } %20// { #05 SFT2 } + +%DEBUG { ;print-hex JSR2 #0a .Console/write DEO } +%DEBUG2 { SWP ;print-hex JSR2 ;print-hex JSR2 #0a .Console/write DEO } + +%RTN { JMP2r } +%TOS { #00 SWP } + +( devices ) + +|00 @System [ &vector $2 &wst $1 &rst $1 &pad $4 &r $2 &g $2 &b $2 &debug $1 &halt $1 ] +|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 ] +|30 @Audio0 [ &vector $2 &position $2 &output $1 &pad $3 &adsr $2 &length $2 &addr $2 &volume $1 &pitch $1 ] +|40 @Audio1 [ &vector $2 &position $2 &output $1 &pad $3 &adsr $2 &length $2 &addr $2 &volume $1 &pitch $1 ] +|50 @Audio2 [ &vector $2 &position $2 &output $1 &pad $3 &adsr $2 &length $2 &addr $2 &volume $1 &pitch $1 ] +|60 @Audio3 [ &vector $2 &position $2 &output $1 &pad $3 &adsr $2 &length $2 &addr $2 &volume $1 &pitch $1 ] +|80 @Controller [ &vector $2 &button $1 &key $1 ] +|90 @Mouse [ &vector $2 &x $2 &y $2 &state $1 &wheel $1 ] +|a0 @File [ &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2 ] +|b0 @DateTime [ &year $2 &month $1 &day $1 &hour $1 &minute $1 &second $1 &dotw $1 &doty $2 &isdst $1 ] + +( variables ) + +|0000 + +@input + &a $1 &b $1 +@center + &x $2 &y $2 +@pointer + &x $2 &y $2 + +( program ) + +|0100 ( -> ) + + ( theme ) + #0fe5 .System/r DEO2 + #0fc5 .System/g DEO2 + #0f25 .System/b DEO2 + + ;on-mouse .Mouse/vector DEO2 + + .Screen/width DEI2 2// .center/x STZ2 + .Screen/height DEI2 2// .center/y STZ2 + + ;redraw JSR2 + +BRK + +@on-mouse ( -> ) + + ;draw-cursor JSR2 + + .Mouse/state DEI #00 ! JMP [ BRK ] + +BRK + +@redraw ( -- ) + + .center/x LDZ2 #0040 -- .Screen/x DEO2 + .center/y LDZ2 #0010 -- .Screen/y DEO2 + + #4f ;draw-byte JSR2 + + .center/x LDZ2 #0040 -- .Screen/x DEO2 + .center/y LDZ2 #0000 ++ .Screen/y DEO2 + + #e7 ;draw-byte JSR2 + +RTN + +@draw-byte ( value -- ) + + STH + #0800 + &loop + DUP STHkr SWP SFT #01 AND ;draw-bit JSR2 + INC GTHk ,&loop JCN + POP2 + .Screen/y DEI2 #0003 ++ .Screen/y DEO2 + STHr ;draw-hex JSR2 + +RTN + +@draw-bit ( value -- ) + + STH + + #05 .Screen/auto DEO + ;button-icns/off [ #00 STHkr 20* ++ ] .Screen/addr DEO2 + #01 .Screen/sprite DEO + #01 .Screen/sprite DEO + .Screen/y DEI2 #0008 ++ .Screen/y DEO2 + .Screen/x DEI2 #0010 -- .Screen/x DEO2 + + #01 .Screen/sprite DEO + #01 .Screen/sprite DEO + + #00 .Screen/auto DEO + .Screen/y DEI2 #0008 -- .Screen/y DEO2 + + POPr + +RTN + +@draw-hex ( value -- ) + + DUP #04 SFT TOS 8** ;font-hex ++ .Screen/addr DEO2 + .Screen/x DEI2 #0008 ++ .Screen/x DEO2 + ( draw ) #01 .Screen/sprite DEO + #0f AND TOS 8** ;font-hex ++ .Screen/addr DEO2 + .Screen/x DEI2 #0008 ++ .Screen/x DEO2 + ( draw ) #01 .Screen/sprite DEO + +RTN + +@draw-cursor ( -- ) + + ( clear last cursor ) + ;cursor .Screen/addr DEO2 + .pointer/x LDZ2 .Screen/x DEO2 + .pointer/y LDZ2 .Screen/y DEO2 + #40 .Screen/sprite DEO + ( record pointer positions ) + .Mouse/x DEI2 DUP2 .pointer/x STZ2 .Screen/x DEO2 + .Mouse/y DEI2 DUP2 .pointer/y STZ2 .Screen/y DEO2 + ( colorize on state ) + #41 [ .Mouse/state DEI #00 ! ] + .Screen/sprite DEO + +RTN + +@print-hex ( value -- ) + + STHk #04 SFT ,&parse JSR .Console/write DEO + STHr #0f AND ,&parse JSR .Console/write DEO + RTN + &parse ( value -- char ) + DUP #09 GTH ,&above JCN #30 ADD RTN &above #09 SUB #60 ADD RTN + +RTN + +@cursor + 80c0 e0f0 f8e0 1000 + +@button-icns + &off + 3f40 8080 8080 8080 + f804 0202 0202 0202 + 8080 8080 8040 3f00 + 0202 0202 0204 f800 + &on + 3f40 9fbf bfbf bfbf + f804 f2fa fafa fafa + bfbf bfbf 9f40 3f00 + fafa fafa f204 f800 + +@font-hex ( 0-F ) + 007c 8282 8282 827c 0030 1010 1010 1010 + 007c 8202 7c80 80fe 007c 8202 1c02 827c + 000c 1424 4484 fe04 00fe 8080 7c02 827c + 007c 8280 fc82 827c 007c 8202 1e02 0202 + 007c 8282 7c82 827c 007c 8282 7e02 827c + 007c 8202 7e82 827e 00fc 8282 fc82 82fc + 007c 8280 8080 827c 00fc 8282 8282 82fc + 007c 8280 f080 827c 007c 8280 f080 8080 + +