2021-11-02 20:13:59 +00:00
|
|
|
( uxnasm projects/examples/demos/snake.tal bin/snake.rom && uxnemu bin/snake.rom )
|
|
|
|
|
|
|
|
( 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 ]
|
|
|
|
|80 @Controller [ &vector $2 &button $1 &key $1 ]
|
2022-03-17 18:57:22 +00:00
|
|
|
|c0 @DateTime [ &year $2 &month $1 &day $1 &hour $1 &minute $1 &second $1 &dotw $1 &doty $2 &isdst $1 ]
|
2021-11-02 20:13:59 +00:00
|
|
|
|
|
|
|
( variables )
|
|
|
|
|
|
|
|
|0000
|
|
|
|
|
|
|
|
( program )
|
|
|
|
|
|
|
|
@arena
|
|
|
|
&w $1 &h $1 &timer $1
|
|
|
|
@apple
|
|
|
|
&x $1 &y $1
|
|
|
|
@snake
|
2021-11-02 21:04:26 +00:00
|
|
|
&direction $1 &length $1 &dead $1
|
2021-11-02 20:13:59 +00:00
|
|
|
&x $1 &y $1
|
|
|
|
&tail
|
|
|
|
|
|
|
|
|0100 ( -> )
|
|
|
|
|
|
|
|
( theme )
|
2021-11-02 21:04:26 +00:00
|
|
|
#0f7e .System/r DEO2
|
|
|
|
#0fe6 .System/g DEO2
|
|
|
|
#0f62 .System/b DEO2
|
2021-11-02 20:13:59 +00:00
|
|
|
|
|
|
|
( vectors )
|
|
|
|
;on-frame .Screen/vector DEO2
|
|
|
|
;on-button .Controller/vector DEO2
|
|
|
|
|
|
|
|
( resize )
|
2021-11-02 21:04:26 +00:00
|
|
|
#00c8 .Screen/width DEO2
|
2021-11-02 20:13:59 +00:00
|
|
|
#0100 .Screen/height DEO2
|
|
|
|
|
2021-11-02 21:04:26 +00:00
|
|
|
( set arena )
|
2022-11-20 22:50:19 +00:00
|
|
|
.Screen/width DEI2 #03 SFT2 NIP .arena/w STZ
|
|
|
|
.Screen/height DEI2 #03 SFT2 NIP .arena/h STZ
|
2021-11-02 20:13:59 +00:00
|
|
|
|
2021-11-02 21:04:26 +00:00
|
|
|
;reset JSR2
|
2021-11-02 20:13:59 +00:00
|
|
|
|
|
|
|
BRK
|
|
|
|
|
|
|
|
@on-frame ( -> )
|
|
|
|
|
|
|
|
.arena/timer LDZ INC DUP .arena/timer STZ
|
2022-11-20 22:50:19 +00:00
|
|
|
#06 ( difficulty - lower value produces faster gameplay )
|
|
|
|
EQU JMP BRK
|
2021-11-02 20:13:59 +00:00
|
|
|
|
2021-11-02 21:04:26 +00:00
|
|
|
( clear ) #00 ;draw-snake JSR2
|
|
|
|
( update ) ;move JSR2
|
2022-11-10 22:49:53 +00:00
|
|
|
( draw ) #02 .snake/dead LDZ ADD ;draw-snake JSR2
|
2021-11-02 23:40:42 +00:00
|
|
|
#83 ;draw-apple JSR2
|
2021-11-02 23:40:19 +00:00
|
|
|
( score ) .snake/length LDZ #41 ;draw-score JSR2
|
2021-11-02 20:13:59 +00:00
|
|
|
( reset ) #00 .arena/timer STZ
|
|
|
|
|
|
|
|
BRK
|
|
|
|
|
|
|
|
@on-button ( -> )
|
|
|
|
|
2021-11-02 21:04:26 +00:00
|
|
|
.Controller/button DEI
|
2022-11-10 22:49:53 +00:00
|
|
|
DUP #08 NEQ ,&no-escape JCN
|
2021-11-02 21:04:26 +00:00
|
|
|
;reset JSR2
|
|
|
|
&no-escape
|
2022-11-10 21:54:32 +00:00
|
|
|
#04 SFT DUP #00 EQU ,&skip JCN
|
2021-11-02 20:13:59 +00:00
|
|
|
DUP .snake/direction STZ
|
|
|
|
&skip
|
|
|
|
POP
|
|
|
|
|
|
|
|
BRK
|
|
|
|
|
2021-11-02 21:04:26 +00:00
|
|
|
@reset ( -- )
|
|
|
|
|
|
|
|
#00 ;draw-snake JSR2
|
|
|
|
#00 ;draw-apple JSR2
|
|
|
|
|
2022-11-20 22:50:19 +00:00
|
|
|
.arena/w LDZ #01 SFT #01 SUB .snake/x STZ
|
|
|
|
.arena/h LDZ #01 SFT #01 SUB .snake/y STZ
|
2021-11-02 21:04:26 +00:00
|
|
|
#00 .snake/dead STZ
|
|
|
|
#00 .snake/length STZ
|
|
|
|
#00 .snake/direction STZ
|
|
|
|
|
|
|
|
#03 ;draw-snake JSR2
|
|
|
|
;add-apple JSR2
|
|
|
|
|
2022-11-20 22:50:19 +00:00
|
|
|
JMP2r
|
2021-11-02 21:04:26 +00:00
|
|
|
|
2021-11-02 20:13:59 +00:00
|
|
|
@move ( -- )
|
|
|
|
|
|
|
|
( tail )
|
|
|
|
.snake/x LDZ2 STH2
|
|
|
|
.snake/length LDZ #00
|
|
|
|
&loop
|
2022-11-20 22:50:19 +00:00
|
|
|
( pop ) DUPk ADD .snake/tail ADD LDZ2 STH2 SWP2r
|
|
|
|
( push ) DUPk ADD .snake/tail ADD STH2r ROT STZ2
|
2021-11-02 20:13:59 +00:00
|
|
|
INC GTHk ,&loop JCN
|
|
|
|
POP2
|
|
|
|
POP2r
|
|
|
|
|
2022-11-20 22:50:19 +00:00
|
|
|
.snake/dead LDZ #00 EQU JMP JMP2r
|
2021-11-02 21:04:26 +00:00
|
|
|
|
2021-11-02 20:13:59 +00:00
|
|
|
.snake/direction LDZ
|
2022-11-10 22:49:53 +00:00
|
|
|
DUP #01 NEQ ,&no-up JCN
|
2022-11-10 21:54:32 +00:00
|
|
|
.snake/y LDZ #01 SUB
|
2022-11-20 22:50:19 +00:00
|
|
|
.arena/h LDZ LTHk JMP SWP POP
|
2021-11-02 20:13:59 +00:00
|
|
|
.snake/y STZ
|
|
|
|
&no-up
|
2022-11-10 22:49:53 +00:00
|
|
|
DUP #02 NEQ ,&no-down JCN
|
2021-11-02 20:13:59 +00:00
|
|
|
.snake/y LDZ INC
|
2022-11-20 22:50:19 +00:00
|
|
|
.arena/h LDZ DIVk MUL SUB
|
2021-11-02 20:13:59 +00:00
|
|
|
.snake/y STZ
|
|
|
|
&no-down
|
2022-11-10 22:49:53 +00:00
|
|
|
DUP #04 NEQ ,&no-left JCN
|
2022-11-10 21:54:32 +00:00
|
|
|
.snake/x LDZ #01 SUB
|
2022-11-20 22:50:19 +00:00
|
|
|
.arena/w LDZ LTHk JMP SWP POP
|
2021-11-02 20:13:59 +00:00
|
|
|
.snake/x STZ
|
|
|
|
&no-left
|
2022-11-10 22:49:53 +00:00
|
|
|
DUP #08 NEQ ,&no-right JCN
|
2021-11-02 20:13:59 +00:00
|
|
|
.snake/x LDZ INC
|
2022-11-20 22:50:19 +00:00
|
|
|
.arena/w LDZ DIVk MUL SUB
|
2021-11-02 20:13:59 +00:00
|
|
|
.snake/x STZ
|
|
|
|
&no-right
|
|
|
|
POP
|
|
|
|
|
2021-11-02 21:04:26 +00:00
|
|
|
( detect collision with apple )
|
2021-11-11 14:22:07 +00:00
|
|
|
.snake/x LDZ2 .apple/x LDZ2 NEQ2 ,&no-collision-apple JCN
|
2021-11-02 20:13:59 +00:00
|
|
|
#00 ;draw-apple JSR2
|
2021-11-02 21:04:26 +00:00
|
|
|
.snake/length LDZ INC .snake/length STZ
|
2021-11-02 20:13:59 +00:00
|
|
|
;add-apple JSR2
|
|
|
|
;move JSR2
|
2021-11-02 21:04:26 +00:00
|
|
|
&no-collision-apple
|
|
|
|
|
|
|
|
.snake/length LDZ #01
|
|
|
|
&loop-body
|
2022-11-20 22:50:19 +00:00
|
|
|
( pop ) DUPk ADD .snake/tail ADD LDZ2
|
2021-11-11 14:22:07 +00:00
|
|
|
.snake/x LDZ2 NEQ2 ,&no-collision-body JCN
|
2021-11-02 21:04:26 +00:00
|
|
|
#01 .snake/dead STZ
|
|
|
|
#03 ;draw-snake JSR2
|
|
|
|
&no-collision-body
|
|
|
|
INC GTHk ,&loop-body JCN
|
|
|
|
POP2
|
|
|
|
|
2022-11-20 22:50:19 +00:00
|
|
|
JMP2r
|
2021-11-02 20:13:59 +00:00
|
|
|
|
|
|
|
@add-apple ( -- )
|
|
|
|
|
2022-11-10 22:49:53 +00:00
|
|
|
.DateTime/hour DEI2 .DateTime/minute DEI2 MUL2 #1234 MUL2 ADD
|
2022-11-20 22:50:19 +00:00
|
|
|
.arena/w LDZ DIVk MUL SUB .apple/x STZ
|
2022-11-10 22:49:53 +00:00
|
|
|
.DateTime/hour DEI2 .DateTime/minute DEI2 MUL2 #abcd MUL2 ADD
|
2022-11-20 22:50:19 +00:00
|
|
|
.arena/h LDZ DIVk MUL SUB .apple/y STZ
|
2021-11-02 20:13:59 +00:00
|
|
|
|
2022-11-20 22:50:19 +00:00
|
|
|
JMP2r
|
2021-11-02 20:13:59 +00:00
|
|
|
|
|
|
|
@draw-snake ( color -- )
|
|
|
|
|
2021-11-02 21:04:26 +00:00
|
|
|
STH
|
2021-11-02 20:13:59 +00:00
|
|
|
( draw tail )
|
2021-11-02 21:04:26 +00:00
|
|
|
;snake-icns .Screen/addr DEO2
|
2021-11-02 20:13:59 +00:00
|
|
|
.snake/length LDZ #00
|
|
|
|
&loop
|
2022-11-20 22:50:19 +00:00
|
|
|
DUPk ADD .snake/tail ADD LDZ #0005 SFT2 .Screen/x DEO2
|
|
|
|
DUPk ADD .snake/tail ADD INC LDZ #0005 SFT2 .Screen/y DEO2
|
2021-11-02 20:13:59 +00:00
|
|
|
STHkr .Screen/sprite DEO
|
|
|
|
INC GTHk ,&loop JCN
|
|
|
|
POP2
|
2021-11-02 21:04:26 +00:00
|
|
|
( draw head )
|
2022-11-20 22:50:19 +00:00
|
|
|
.snake/x LDZ #0005 SFT2 .Screen/x DEO2
|
|
|
|
.snake/y LDZ #0005 SFT2 .Screen/y DEO2
|
2021-11-02 21:04:26 +00:00
|
|
|
;snake-icns/face .Screen/addr DEO2
|
|
|
|
STHr .Screen/sprite DEO
|
2021-11-02 20:13:59 +00:00
|
|
|
|
2022-11-20 22:50:19 +00:00
|
|
|
JMP2r
|
2021-11-02 20:13:59 +00:00
|
|
|
|
|
|
|
@draw-apple ( color -- )
|
2021-11-02 21:04:26 +00:00
|
|
|
|
2022-11-20 22:50:19 +00:00
|
|
|
.apple/x LDZ #0005 SFT2 .Screen/x DEO2
|
|
|
|
.apple/y LDZ #0005 SFT2 .Screen/y DEO2
|
2021-11-02 21:04:26 +00:00
|
|
|
;apple-chr .Screen/addr DEO2
|
|
|
|
.Screen/sprite DEO
|
2021-11-02 20:13:59 +00:00
|
|
|
|
2022-11-20 22:50:19 +00:00
|
|
|
JMP2r
|
2021-11-02 20:13:59 +00:00
|
|
|
|
2021-11-02 21:04:26 +00:00
|
|
|
@draw-score ( score color -- )
|
|
|
|
|
|
|
|
STH
|
|
|
|
#0010 .Screen/x DEO2
|
|
|
|
#0010 .Screen/y DEO2
|
2022-11-20 22:50:19 +00:00
|
|
|
DUP #04 SFT #0005 SFT2 ;font-hex ADD2 .Screen/addr DEO2
|
2022-11-10 22:49:53 +00:00
|
|
|
.Screen/x DEI2 #0008 ADD2 .Screen/x DEO2
|
2021-11-02 21:04:26 +00:00
|
|
|
( draw ) STHkr .Screen/sprite DEO
|
2022-11-20 22:50:19 +00:00
|
|
|
#0f AND #0005 SFT2 ;font-hex ADD2 .Screen/addr DEO2
|
2022-11-10 22:49:53 +00:00
|
|
|
.Screen/x DEI2 #0008 ADD2 .Screen/x DEO2
|
2021-11-02 21:04:26 +00:00
|
|
|
( draw ) STHr .Screen/sprite DEO
|
2021-11-02 20:13:59 +00:00
|
|
|
|
2022-11-20 22:50:19 +00:00
|
|
|
JMP2r
|
2021-11-02 20:13:59 +00:00
|
|
|
|
|
|
|
( assets )
|
|
|
|
|
|
|
|
@snake-icns
|
2021-11-02 21:04:26 +00:00
|
|
|
7eff ffff ffff ff7e
|
|
|
|
&face
|
2021-11-11 14:10:45 +00:00
|
|
|
7eff ffdb ffe7 ff7e
|
2021-11-02 21:04:26 +00:00
|
|
|
@apple-chr
|
|
|
|
0000 76ff ffff 7e3c
|
|
|
|
1008 0000 0000 0000
|
|
|
|
@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
|
2021-11-02 20:13:59 +00:00
|
|
|
|