215 lines
3.4 KiB
Tal
215 lines
3.4 KiB
Tal
( usage: uxnemu sand.rom
|
|
mouse1 water
|
|
mouse2 sand
|
|
mouse3 rock )
|
|
|
|
|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
|
|
|80 @Controller &vector $2 &button $1 &key $1
|
|
|90 @Mouse &vector $2 &x $2 &y $2 &state $1 &pad $3 &scrollx $2 &scrolly $2
|
|
|a0 @File &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2
|
|
|c0 @DateTime &year $2 &month $1 &day $1 &hour $1 &minute $1 &second $1 &dotw $1 &doty $2 &isdst $1
|
|
|
|
|0100
|
|
|
|
(
|
|
@|vectors )
|
|
|
|
@on-reset
|
|
|
|
( theme )
|
|
#07cf .System/r DEO2
|
|
#0caf .System/g DEO2
|
|
#0faf .System/b DEO2
|
|
|
|
#0100 .Screen/width DEO2
|
|
#0100 .Screen/height DEO2
|
|
|
|
;on-frame .Screen/vector DEO2
|
|
;on-mouse .Mouse/vector DEO2
|
|
|
|
prng-init
|
|
|
|
#010e DEO
|
|
|
|
BRK
|
|
|
|
@on-frame ( -> )
|
|
|
|
eval
|
|
redraw
|
|
|
|
BRK
|
|
|
|
@on-mouse ( -> )
|
|
|
|
[ LIT2 00 -Mouse/state ] DEI NEQ #41 ADD ;cursor-icn update-cursor
|
|
|
|
( read mouse state )
|
|
.Mouse/state DEI ?&on-touch BRK
|
|
|
|
&on-touch ( -> )
|
|
|
|
( A mouse button was pressed )
|
|
.Mouse/state DEI DUP #04 EQU SUB
|
|
.Mouse/y DEI2 NIP
|
|
.Mouse/x DEI2 NIP
|
|
set-cell
|
|
|
|
BRK
|
|
|
|
(
|
|
@|core )
|
|
|
|
@eval-sand ( y x cell -- y x )
|
|
|
|
POP
|
|
OVR #ff EQU ?eval/resume
|
|
( south )
|
|
SWPk INC SWP STH2k get-cell #01 GTH ?&has-s
|
|
DUP2 STH2r swap-cells !eval/resume
|
|
&has-s
|
|
POP2r
|
|
( south sides )
|
|
SWPk INC SWP #01ff prng ADD #01 AND [ JMP SWP POP ] ADD STH2k get-cell #01 GTH ?&has-s2
|
|
DUP2 STH2r swap-cells !eval/resume
|
|
&has-s2
|
|
POP2r
|
|
|
|
!eval/resume
|
|
|
|
@eval-water ( y x cell -- y x )
|
|
|
|
POP
|
|
OVR #ff EQU ?eval/resume
|
|
( south )
|
|
SWPk INC SWP STH2k get-cell ?&has-s
|
|
DUP2 STH2r swap-cells !eval/resume
|
|
&has-s
|
|
POP2r
|
|
( south sides )
|
|
DUP2 #01ff prng ADD #01 AND [ JMP SWP POP ] ADD STH2k get-cell ?&has-s2
|
|
DUP2 STH2r swap-cells !eval/resume
|
|
&has-s2
|
|
POP2r
|
|
|
|
!eval/resume
|
|
|
|
@eval-rock ( y x cell -- y x )
|
|
|
|
POP
|
|
OVR #ff EQU ?eval/resume
|
|
( south )
|
|
SWPk INC SWP STH2k get-cell #01 GTH ?&has-s
|
|
DUP2 STH2r swap-cells !eval/resume
|
|
&has-s
|
|
POP2r
|
|
|
|
!eval/resume
|
|
|
|
@eval ( -- )
|
|
|
|
#ffff
|
|
&l
|
|
DUP2 get-cell
|
|
DUP #01 EQU ?eval-water
|
|
DUP #02 EQU ?eval-sand
|
|
DUP #03 EQU ?eval-rock
|
|
POP
|
|
&resume
|
|
#0001 SUB2 ORAk ?&l
|
|
POP2
|
|
|
|
@redraw ( -- )
|
|
|
|
#0000
|
|
&l
|
|
DUP2 #00ff AND2 .Screen/x DEO2
|
|
DUP2 #0100 DIV2 .Screen/y DEO2
|
|
DUP2 get-cell .Screen/pixel DEO
|
|
INC2 ORAk ?&l
|
|
POP2
|
|
|
|
JMP2r
|
|
|
|
@swap-cells ( a* b* -- )
|
|
|
|
#02 SFT2 ;world ADD2 SWP2
|
|
#02 SFT2 ;world ADD2 mswap
|
|
|
|
JMP2r
|
|
|
|
@set-cell ( type y x -- )
|
|
|
|
#02 SFT2 ;world ADD2 STA
|
|
|
|
JMP2r
|
|
|
|
@get-cell ( y x -- type )
|
|
|
|
#02 SFT2 ;world ADD2 LDA
|
|
|
|
JMP2r
|
|
|
|
(
|
|
@|drawing )
|
|
|
|
@update-cursor ( color addr* -- )
|
|
|
|
[ LIT2 00 -Screen/auto ] DEO
|
|
#40 draw-cursor
|
|
.Mouse/x DEI2 ,draw-cursor/x STR2
|
|
.Mouse/y DEI2 ,draw-cursor/y STR2
|
|
.Screen/addr DEO2
|
|
|
|
@draw-cursor ( color -- )
|
|
|
|
[ LIT2 &x $2 ] .Screen/x DEO2
|
|
[ LIT2 &y $2 ] .Screen/y DEO2
|
|
.Screen/sprite DEO
|
|
|
|
JMP2r
|
|
|
|
(
|
|
@|stdlib )
|
|
|
|
@mswap ( a* b* -- )
|
|
|
|
SWP2k LDA STH STH2 LDA STH STH2 STAr STAr
|
|
|
|
JMP2r
|
|
|
|
@prng-init ( -- )
|
|
|
|
( seed )
|
|
#00 .DateTime/second DEI
|
|
#00 .DateTime/minute DEI #60 SFT2 EOR2
|
|
#00 .DateTime/hour DEI #c0 SFT2 EOR2 ,prng/x STR2
|
|
#00 .DateTime/hour DEI #04 SFT2
|
|
#00 .DateTime/day DEI #10 SFT2 EOR2
|
|
#00 .DateTime/month DEI #60 SFT2 EOR2
|
|
.DateTime/year DEI2 #a0 SFT2 EOR2 ,prng/y STR2
|
|
|
|
JMP2r
|
|
|
|
@prng ( -- number* )
|
|
|
|
LIT2 &x $2
|
|
DUP2 #50 SFT2 EOR2
|
|
DUP2 #03 SFT2 EOR2
|
|
LIT2 &y $2 DUP2 ,&x STR2
|
|
DUP2 #01 SFT2 EOR2 EOR2
|
|
,&y STR2k POP
|
|
|
|
JMP2r
|
|
|
|
(
|
|
@|assets )
|
|
|
|
@cursor-icn [
|
|
80c0 e0f0 f8e0 1000 ]
|
|
|
|
@world
|
|
|