grid-uxn/examples/basic.tal

77 lines
2.5 KiB
Tal

%RTN { JMP2r }
( 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 &pad $2 &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 &offset-hs $2 &offset-ls $2 &name $2 &length $2 &load $2 &save $2 ]
|b0 @DateTime [ &year $2 &month $1 &day $1 &hour $1 &minute $1 &second $1 &dotw $1 &doty $2 &isdst $1 ]
( variables )
|0000
( program )
|0100
( set colors )
#0f00 .System/r DEO2
( run the "read" routine when a byte comes in )
;read/run .Console/vector DEO2
BRK
( each time a byte comes in, store it in the message and increase the count. If the count is #02, a whole message is read, so do stuff with it.
grid messages are 3 bytes - state , x, and y )
@read
( initialise local variables for reading grid messages. Message stores the 3-byte message from the grid, count is how many bytes have been read )
&message $3
&count $1
&run
.Console/read DEI ,&count LDR #00 SWP ;&message ADD2 STA
,&count LDR #01 ADD ,&count STR
,&count LDR #03 EQU ,&process JCN
BRK
&process
#00 ,&count STR ( reset counter )
;&message #0001 ADD2 LDA ( get message X position )
#00 SWP ( convert to a short )
#0008 MUL2 .Screen/x DEO2 ( set display X position )
;&message #0002 ADD2 LDA ( get message Y position )
#00 SWP ( convert to a short )
#0008 MUL2 .Screen/y DEO2 ( set display Y position )
;block .Screen/addr DEO2 ( set sprite to a block )
;&message LDA .Screen/sprite DEO ( draw the sprite )
( output to the grid to change the square. Write a #00 to send a set message, then the x, y, and state )
#00 .Console/write DEO
;&message #0001 ADD2 LDA .Console/write DEO
;&message #0002 ADD2 LDA .Console/write DEO
;&message LDA .Console/write DEO
BRK
@block [ ffff ffff ffff ffff ]