From 4ec4a0a75e38ca7046478258c6cbe7f8712445f5 Mon Sep 17 00:00:00 2001 From: d6 Date: Wed, 19 Jan 2022 01:00:49 -0500 Subject: [PATCH] it kind of works --- maze.tal | 67 +++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 47 insertions(+), 20 deletions(-) diff --git a/maze.tal b/maze.tal index ad84299..832a714 100644 --- a/maze.tal +++ b/maze.tal @@ -24,10 +24,11 @@ %ROWS { #0027 } ( rows of cells ) %COLS { #003f } ( columns of cells ) -%MAZEROWS { ROWS #0003 SUB2 #0002 DIV2 } -%MAZECOLS { COLS #0003 SUB2 #0002 DIV2 } -( %MAZEROWS { ROWS INC2 #0002 DIV2 } -%MAZECOLS { COLS INC2 #0002 DIV2 } ) +%CELLS { ROWS COLS MUL2 } +( %MAZEROWS { ROWS #0003 SUB2 #0002 DIV2 } +%MAZECOLS { COLS #0003 SUB2 #0002 DIV2 } ) +%MAZEROWS { ROWS INC2 #0002 DIV2 } +%MAZECOLS { COLS INC2 #0002 DIV2 } %NORTH { COLS NEGATE2 } %EAST { #0001 } %SOUTH { COLS } @@ -39,7 +40,8 @@ %XSTORE { ROT ROT STORE } ( cell* val -> ) %IS-OPEN { LOAD #01 AND } %UNSEEN { LOAD #02 AND #00 EQU } ( cell* -> bool^ ) -%PATH { ADD2 #0002 DIV2 } ( cell1* cell2* -> cell3* ) +( %PATH { ADD2 #0002 DIV2 } ( cell1* cell2* -> cell3* ) ) +%PATH { ADD2 #01 SFT2 } ( cell1* cell2* -> cell3* ) %DIGIT { #00 SWP ;digits ADD2 LDA EMIT } %EMIT-BYTE { DUP #04 SFT DIGIT #0f AND DIGIT } @@ -118,7 +120,7 @@ ;clear-maze JSR2 ( we mark the border as having been seen to simplify bounds checking ) - ;mark-border JSR2 +( ;mark-border JSR2 ) ( generate the maze ) ;create-maze JSR2 @@ -144,7 +146,7 @@ BRK ( if regenerate was true, then create a new maze ) #00 .regenerate STZ ;clear-maze JSR2 - ;mark-border JSR2 +( ;mark-border JSR2 ) ;create-maze JSR2 ;create-exits JSR2 ;draw-maze JSR2 @@ -275,6 +277,7 @@ RTN #01 XSTORE SOUTH ADD2 #01 XSTORE RTN +( initialize the entire maze memory to 0 values ) @clear-maze ( -> ) ROWS COLS MUL2 ( limit* ) #0000 #0000 CELL ( limit* cell* ) @@ -287,20 +290,42 @@ RTN ( a move is illegal if it changes both x and y. ) ( that occurs when the player wraps around the border. ) @illegal-move ( cell* -> bool^ ) + DUP2 CELLS LTH2 ,&inbounds JCN POP2 #01 RTN + &inbounds + DUP2 DUP2 COLS MOD2 ;focus LDA2 COLS MOD2 NEQ2 STH - ROWS DIV2 ;focus LDA2 ROWS DIV2 NEQ2 STHr + COLS DIV2 ;focus LDA2 COLS DIV2 NEQ2 STHr AND -RTN + STHk #20 ADD EMIT SPACE EMIT-SHORT SPACE ;focus LDA2 EMIT-SHORT NEWLINE STHr + RTN + +@log-focus + EMIT SPACE ;focus LDA2 EMIT-SHORT NEWLINE RTN + +@xstore + ROT ROT STORE RTN + +@is-unseen ( cell* -> bool^ ) + DUP2 + LOAD + DUP EMIT-BYTE SPACE + #02 AND #00 EQU + STHk #30 ADD EMIT SPACE EMIT-SHORT NEWLINE STHr + RTN @create-maze ( -> ) ( create starting pt, must have even coords ) - ;random-short JSR2 MAZEROWS MOD2 INC2 #0002 MUL2 ( row* ) - ;random-short JSR2 MAZECOLS MOD2 INC2 #0002 MUL2 ( row* col* ) +( ;random-short JSR2 MAZEROWS MOD2 INC2 #0002 MUL2 ( row* ) + ;random-short JSR2 MAZECOLS MOD2 INC2 #0002 MUL2 ( row* col* ) ) +( ;random-short JSR2 MAZEROWS MOD2 #0002 MUL2 ( row* ) + ;random-short JSR2 MAZECOLS MOD2 #0002 MUL2 ( row* col* ) ) + #0000 #0000 CELL DUP2 ;focus STA2 ( cell* ) #07 XSTORE ( ) &queue ( ) + #3f ;log-focus JSR2 ;shuffle-directions JSR2 ( ) #00 ( i^ ) @@ -309,7 +334,7 @@ RTN DUP #02 MUL .cell-offsets ADD LDZ2 ( i^ d^ off* ) DUP2 ;focus LDA2 ADD2 ADD2 ( i^ d^ cell2* ) DUP2 ;illegal-move JSR2 ,¬found JCN - DUP2 UNSEEN ( i^ d^ cell2* unseen^ ) + DUP2 ;is-unseen JSR2 ( i^ d^ cell2* unseen^ ) ,&found JCN ( i^ d^ cell2* ) ¬found POP2 POP INC ( j=i+1 ) @@ -317,13 +342,14 @@ RTN ,&search JCN ( j^ ) POP ( ) ,&backtrack JMP ( ) - ,&done JMP ( ) &found ( addr^ d^ cell2* ) - DUP2 #01 XSTORE + #2a ;log-focus JSR2 + DUP2 #01 ( XSTORE ) ;xstore JSR2 DUP2 ;focus LDA2 PATH ( addr^ d^ cell2* wall* ) - #01 XSTORE ( addr^ d^ cell2* ) + #01 ( XSTORE ) ;xstore JSR2 ( addr^ d^ cell2* ) ;focus STA2 ( addr^ d^ ) + #3e ;log-focus JSR2 #02 EOR #08 MUL ( addr^ link^ ) #03 ORA ;focus LDA2 ( addr^ data^ cell* ) STORE ( addr^ ) @@ -335,6 +361,7 @@ RTN ;focus LDA2 OVR2 ( offset* cell* offset* ) ADD2 ADD2 ( old-cell* ) DUP2 ;focus STA2 ( old-cell* ) + #3c ;log-focus JSR2 LOAD #04 AND #00 NEQ ( is-start^ ) ,&done JCN ;&queue JMP2 @@ -387,6 +414,11 @@ RTN POP RTN +( convenience for less branching when printing hex ) +@digits + 30 31 32 33 34 35 36 37 + 38 39 61 62 63 64 65 66 + |8000 ( 64x40 cells = 2560 bytes ) @@ -401,8 +433,3 @@ RTN ( we use the link to support backtracking without ) ( needing a separate stack. ) @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