******************************** * * * PERFECT MAZE GENERATOR * * * ******************************** * ** ASSEMBLER DIRECTIVES * CYC AVE EXP ONLY ; TURN OFF LATER DSK MAKEMAZE TR ON OBJ $BFE0 ORG $6000 * PUT MIN.VARS.REQUIRED USE MIN.MAC.REQUIRED USE MIN.MAC.ARRAYS USE MIN.MAC.MATH USE MIN.MAC.STDIO PUT MIN.HOOKS.REQUIRED PUT MIN.HOOKS.STDIO PUT MIN.HOOKS.MATH PUT MIN.HOOKS.ARRAYS * ******************************** * * * CONSTANT DECLARATIONS * * * ******************************** * XLEN KBD "ENTER MAZE SIZE" XNUM EQU 2*XLEN BAS EQU $2000 ; BASE ADDRESS FOR ARRAYS YLEN EQU XLEN ; CURRENT ALGO ONLY DOES SQUARE XMAX EQU XLEN+1 ; ADD EXTRA COLUMN YMAX EQU YLEN+1 ; ADD EXTRA ROW ASZ EQU XMAX*YMAX+10 ; ARRAY SIZE+INFO BYTES XSTAKS EQU ASZ*2+1 ; COLUMN STACK SIZE; X * Y + 1 YSTAKS EQU ASZ*2+1 ; ROW STACK SIZE; X * Y + 1 * SOUTHW EQU BAS ; SOUTH WALLS ARRAY WESTW EQU ASZ+BAS ; WEST WALLS ARRAY VISITED EQU 2*ASZ+BAS ; CELLS VISITED XSTACK EQU 3*ASZ+BAS ; STACK FOR COLUMNS YSTACK EQU 3*ASZ+BAS+XSTAKS ; STACK FOR ROWS * ******************************** * * * MAIN PROGRAM LOOP * * * ******************************** * INIT * JSR HOME PRN "INITIALIZING...",8D * JSR :SETVARS JSR :OUTWALLS * ** GET RANDOM STARTING POINT * RNDB #2;#XLEN ; IF XLEN HIBYTE IS 0, CMP #0 ; THEN SKIP SETTING XX HIBYTE BEQ :SKIPHI LDA #>YLEN ; IF YLEN HIBYTE IS 0, CMP #0 ; THEN SKIP SETTING YY HIBYTE BEQ :SKIPHI RNDB #1;#>XLEN ; RANDOMLY SET XX HIBYTE STA XX+1 RNDB #1;#>YLEN ; RANDOMLY SET YY HIBYTE STA YY+1 JMP BUILD :SKIPHI ; JUST SET HIBYTES TO 0 LDA #0 STA XX+1 STA YY+1 * JMP BUILD * ******************************** * :SETVARS * ** DIM ARRAYS AND FILL * DIM162 #SOUTHW;#XMAX;#YMAX;#1;#1 DIM162 #WESTW;#XMAX;#YMAX;#1;#1 DIM162 #VISITED;#XMAX;#YMAX;#1;#0 DIM161 #XSTACK;#XSTAKS;#2;#0 DIM161 #YSTACK;#YSTAKS;#2;#0 * ** NOW ASSIGN VARIABLE VALUES * LDA #0 STA SPTR ; INIT STACK POINTER STA V0 LDA #1 STA V1 RTS * ******************************** * :OUTWALLS * ** MAKE COLUMN MIN AND MAX TO BE ALL ** WALL (CODE: 1). * LDA #0 ; CLEAR ALL TO 0 FIRST STA XX STA YY STA XX+1 STA YY+1 JMP :COLCONT ; SKIP FIRST INCREMENT * :COLEDGE LDA XX CLC ADC #1 STA XX BCC :COLCONT ; IF CARRY SET, THEN INC HIBYTE INC XX+1 :COLCONT PUT162 #V1;#VISITED;XX;#0 PUT162 #V1;#VISITED;XX;#YMAX-1 LDA XX CMP #XMAX ; IF XX HI < MAX HI, REPEAT BNE :COLEDGE * ** MAKE MIN AND MAX ROWS TO BE ALL WALL * JMP :ROWCONT ; SKIP FIRST INCREMENT * :ROWEDGE LDA YY CLC ADC #1 STA YY BCC :ROWCONT ; IF CARRY SET, INC HIBYTE INC YY+1 :ROWCONT PUT162 #V1;#VISITED;#0;YY PUT162 #V1;#VISITED;#XMAX-1;YY LDA YY CMP #YMAX ; IF YY HI < YMAX HI, REPEAT BNE :ROWEDGE RTS * ******************************** * * * BUILD THE MAZE * * * ******************************** * BUILD * PRN "BUILDING MAZE...",8D8D JMP CONTSPTR ; SKIP FIRST INC * ******************************** * STAKPUSH * LDA SPTR ; INCREMENT STACK POINTER CLC ADC #1 STA SPTR BCC CONTSPTR ; IF CARRY SET, INC POINTER HI INC SPTR+1 CONTSPTR PUT161 #XX;#XSTACK;SPTR ; PUT COL ON STACK PUT161 #YY;#YSTACK;SPTR ; PUT ROW ON STACK PUT162 #V1;#VISITED;XX;YY ; MARK BLOCK AS VISITED * ******************************** * CHECKALL * ** CHECKS ALL ADJACENT BLOCKS FOR A WALL. IF ** COMPLETELY SURROUNDED, POP THE STACK AND ** AND START OVER UNTIL. * LDA YY+1 ; COPY HI BYTES OF XX,YY FIRST STA YP1+1 STA YM1+1 LDA XX+1 STA XP1+1 STA XM1+1 * LDA YY ; CALC AND STORE YY+1 CLC ADC #1 STA YP1 BCC :YP1CNT ; IF CARRY SET, INC YYP1 HI INC YP1+1 :YP1CNT LDA XX ; CALC AND STORE XX+1 CLC ADC #1 STA XP1 BCC :XP1CNT ; IF CARRY SET, INC XP1 HI INC XP1+1 :XP1CNT LDA YY ; CALC AND STORE YY-1 SEC SBC #1 STA YM1 BCS :YM1CNT ; IF CARRY CLEAR, DEC YM1 HI DEC YM1+1 :YM1CNT LDA XX ; CALC AND STORE XX-1 SEC SBC #1 STA XM1 BCS :XM1CNT ; IF CARRY CLEAR, DEC XM1 HI DEC XM1+1 :XM1CNT *JSR CELLPOS * ** NOW CHECK ADJACENT CELLS FOR WALLS * :IF1 ; IF VISITED(XX,YY+1) = 1 LDA YY+1 ; IF YY HI BYTE = YMAX HI BYTE, CMP #>YMAX ; THEN TEST YY LOW BYTE BNE :IF1TEST LDA YY CMP #XMAX ; THEN TEST LOBYTE BNE :IF2TEST LDA XX ; IF XX LOBYTE = XMAX LOBYTE CMP # 0 CMP #0 ; THEN REPEAT MOVEMENT BNE :DOREPEAT LDA SPTR ; OTHERWISE, TEST LOBYTE CMP #1 ; IF STILL MORE ON STACK BEQ :DOREPEAT BCS :DOREPEAT ; THEN REPEAT MOVEMENT JMP DISPMAZE ; OTHERWISE, FINISHED! * :DOREPEAT JMP CHECKALL * ******************************** * DOMOVE * ** MOVE IN A RANDOM DIRECTION * JSR RAND8 CMP #64 ; IF RND < 64 BCC :MVDJ CMP #128 ; ELSE IF RND < 128 BCC :MVRJ CMP #192 ; ELSE IF RND < 192 BCC :MVUPJ JMP :MVLEFT ; ELSE RND IS > 191 :MVUPJ JMP :MVUP :MVRJ JMP :MVRIGHT :MVDJ JMP :MVDOWN * :MVDOWN LDA YY+1 ; IF YY HIBYTE = YMAX HIBYTE CMP #>YMAX ; THEN TEST LOBYTES BNE :DTEST ; OTHERWISE, TEST CELL BELOW LDA YY CMP #XMAX ; THEN TEST LOW BYTE BNE :RTEST ; ELSE CONTINUE CELL CHECK LDA XX CMP #XMAX BNE WLP ; THEN REPEAT LDA XX ; OTHERWISE, TEST LOWS CMP #XMAX ; IF HI != XMAX HI BNE SLP ; REPEAT LDA XX ; ELSE, TEST LOBYTE CMP #YMAX ; THEN NOT DONE; REPEAT LOOPS BNE REPT LDA YY ; ELSE IF YY LO != YMAX LO CMP #