basic movement
This commit is contained in:
parent
de4f979dbf
commit
c0c6e7b50a
74
maze.tal
74
maze.tal
|
@ -30,11 +30,11 @@
|
||||||
%SOUTH { COLS }
|
%SOUTH { COLS }
|
||||||
%WEST { #ffff }
|
%WEST { #ffff }
|
||||||
|
|
||||||
%CELL { SWP2 COLS MUL2 ADD2 } ( col* row* -> row*cols+col )
|
%CELL { SWP2 COLS MUL2 ADD2 } ( row* col* -> row*cols+col )
|
||||||
%LOAD { ;maze ADD2 LDA } ( cell* -> val^ )
|
%LOAD { ;maze ADD2 LDA } ( cell* -> val^ )
|
||||||
%STORE { ;maze ADD2 STA } ( val cell* -> )
|
%STORE { ;maze ADD2 STA } ( val cell* -> )
|
||||||
%XSTORE { ROT ROT STORE } ( cell* val -> )
|
%XSTORE { ROT ROT STORE } ( cell* val -> )
|
||||||
%IS-START { LOAD #04 AND #02 SFT } ( cell* -> bool^ )
|
%IS-OPEN { LOAD #01 AND }
|
||||||
%UNSEEN { LOAD #02 AND #00 EQU } ( cell* -> bool^ )
|
%UNSEEN { LOAD #02 AND #00 EQU } ( cell* -> bool^ )
|
||||||
%PATH { ADD2 #0002 DIV2 } ( cell1* cell2* -> cell3* )
|
%PATH { ADD2 #0002 DIV2 } ( cell1* cell2* -> cell3* )
|
||||||
|
|
||||||
|
@ -74,6 +74,10 @@
|
||||||
( boolean used to generate a new maze )
|
( boolean used to generate a new maze )
|
||||||
@regenerate $1
|
@regenerate $1
|
||||||
|
|
||||||
|
( cell occupied by the character )
|
||||||
|
@charx $2
|
||||||
|
@chary $2
|
||||||
|
|
||||||
|0100
|
|0100
|
||||||
|
|
||||||
( intialize rng )
|
( intialize rng )
|
||||||
|
@ -89,6 +93,10 @@
|
||||||
#02 .directions #02 ADD STZ
|
#02 .directions #02 ADD STZ
|
||||||
#03 .directions #03 ADD STZ
|
#03 .directions #03 ADD STZ
|
||||||
|
|
||||||
|
( initialize the character )
|
||||||
|
#0002 .charx STZ2
|
||||||
|
#0000 .chary STZ2
|
||||||
|
|
||||||
( initialize cell offsets - calculated based on #columns )
|
( initialize cell offsets - calculated based on #columns )
|
||||||
NORTH .cell-offsets #00 ADD STZ2
|
NORTH .cell-offsets #00 ADD STZ2
|
||||||
EAST .cell-offsets #02 ADD STZ2
|
EAST .cell-offsets #02 ADD STZ2
|
||||||
|
@ -142,9 +150,35 @@ BRK
|
||||||
&done
|
&done
|
||||||
BRK
|
BRK
|
||||||
|
|
||||||
|
%DIGIT { #00 SWP ;digits ADD2 LDA EMIT }
|
||||||
|
%EMIT-BYTE { DUP #04 SFT DIGIT #0f AND DIGIT }
|
||||||
|
%EMIT-SHORT { SWP EMIT-BYTE EMIT-BYTE }
|
||||||
|
|
||||||
|
@try-move ( drow dcol -> )
|
||||||
|
.charx LDZ2 ADD2 SWP2 ( col+dcol row+drow )
|
||||||
|
.chary LDZ2 ADD2 SWP2 ( row+drow dcol )
|
||||||
|
OVR2 OVR2 ( row col row col )
|
||||||
|
CELL LOAD ( col row val )
|
||||||
|
#01 AND ,&ok JCN
|
||||||
|
POP2 POP2 RTN
|
||||||
|
&ok .charx STZ2 .chary STZ2 RTN
|
||||||
|
|
||||||
@on-key ( -> )
|
@on-key ( -> )
|
||||||
#01 .regenerate STZ
|
.Controller/button DEI
|
||||||
BRK
|
DUP ,&move JCN
|
||||||
|
POP ( #01 .regenerate STZ ) BRK
|
||||||
|
|
||||||
|
&move-up #ffff #0000 ;try-move JSR2 POP BRK
|
||||||
|
&move-down #0001 #0000 ;try-move JSR2 POP BRK
|
||||||
|
&move-left #0000 #ffff ;try-move JSR2 POP BRK
|
||||||
|
&move-right #0000 #0001 ;try-move JSR2 POP BRK
|
||||||
|
|
||||||
|
&move
|
||||||
|
DUP #10 AND ,&move-up JCN
|
||||||
|
DUP #20 AND ,&move-down JCN
|
||||||
|
DUP #40 AND ,&move-left JCN
|
||||||
|
DUP #80 AND ,&move-right JCN
|
||||||
|
EMIT-BYTE NEWLINE BRK
|
||||||
|
|
||||||
@wall-sprite
|
@wall-sprite
|
||||||
ffff ffff ffff ffff
|
ffff ffff ffff ffff
|
||||||
|
@ -152,6 +186,9 @@ BRK
|
||||||
@open-sprite
|
@open-sprite
|
||||||
0000 0000 0000 0000
|
0000 0000 0000 0000
|
||||||
|
|
||||||
|
@char-sprite
|
||||||
|
0000 183c 3c18 0000
|
||||||
|
|
||||||
@draw-maze ( -> )
|
@draw-maze ( -> )
|
||||||
#0000 ( row )
|
#0000 ( row )
|
||||||
&loop
|
&loop
|
||||||
|
@ -175,14 +212,28 @@ RTN
|
||||||
@draw-cell ( row* col* -> )
|
@draw-cell ( row* col* -> )
|
||||||
SWP2 DUP2 #0008 MUL2 .Screen/y DEO2 ( draw at y=row*8 )
|
SWP2 DUP2 #0008 MUL2 .Screen/y DEO2 ( draw at y=row*8 )
|
||||||
SWP2 DUP2 #0008 MUL2 .Screen/x DEO2 ( draw at x=col*8 )
|
SWP2 DUP2 #0008 MUL2 .Screen/x DEO2 ( draw at x=col*8 )
|
||||||
CELL LOAD ( load cell byte at maze+index )
|
|
||||||
|
OVR2 OVR2
|
||||||
|
.charx LDZ2 EQU2 STH
|
||||||
|
.chary LDZ2 EQU2 STHr AND
|
||||||
|
,&draw-char JCN
|
||||||
|
|
||||||
|
( OVR2 OVR2 ) CELL LOAD ( load cell byte at maze+index )
|
||||||
#01 AND ( get bit 1, wall bit )
|
#01 AND ( get bit 1, wall bit )
|
||||||
|
,&draw-open JCN
|
||||||
|
( POP2 POP2 ) ;wall-sprite ,&end JMP
|
||||||
|
|
||||||
|
&draw-open
|
||||||
|
( .charx LDZ2 EQU2 STH
|
||||||
|
.chary LDZ2 EQU2 STHr AND
|
||||||
|
,&draw-char JCN )
|
||||||
|
;open-sprite ,&end JMP
|
||||||
|
|
||||||
|
&draw-char
|
||||||
|
[ POP2 POP2 ] ;char-sprite ,&end JMP
|
||||||
|
|
||||||
;open-sprite .Screen/addr DEO2 ( set to wall sprite initially )
|
|
||||||
,&end JCN ( if cell byte is non-zero, space is open )
|
|
||||||
;wall-sprite .Screen/addr DEO2 ( if we got here not a wall )
|
|
||||||
&end
|
&end
|
||||||
|
.Screen/addr DEO2
|
||||||
.tint LDZ .Screen/sprite DEO ( draw the cell )
|
.tint LDZ .Screen/sprite DEO ( draw the cell )
|
||||||
RTN
|
RTN
|
||||||
|
|
||||||
|
@ -337,3 +388,8 @@ we use the link to support backtracking without
|
||||||
needing a separate stack.
|
needing a separate stack.
|
||||||
)
|
)
|
||||||
@maze $2560
|
@maze $2560
|
||||||
|
|
||||||
|
( convenience for less branching when printing hex )
|
||||||
|
@digits
|
||||||
|
30 31 32 33 34 35 36 37
|
||||||
|
38 39 61 62 63 64 65 66
|
||||||
|
|
Loading…
Reference in New Issue