Maze 80 (MSX) by Keith Erickson
A downloadable game
Maze 80
MSX BASIC 10-Liner by Keith Erickson, 2025
PUR-80 Category
This game started life as an extreme 256 entry, but after much effort, I somehow managed to squeeze it into 10 lines of 80 characters!
* Controls:
Use the Arrow Keys to move the dot through the maze
Use the Space Bar to start the game
The goal of the game is to navigate your orange dot from the left side of the maze to the orange dot on the right side of the maze before time runs out.
The maze is randomly generated, so it's never the same game twice!
* MAZE 80 Program Listing:
0 SCREEN1,,0:KEYOFF:DEFINTA-Z:FORI=1TO6:VPOKE14336+I,126:NEXT:READA$:FORI=0TO31 1 VPOKEI,VAL("&H"+MID$(+A$,1+(I\8)*4-2*(IMOD8>5),2)):NEXT:DATA3F003F3FFF00FF3F 2 COLOR4,1:L=60:LOCATE9,1:PRINT"HIT KEY":R=RND(TIME):IFNOTSTRIG(0)THEN2ELSEBEEP 3 CLS:VPOKE8192,68:FORJ=0TO23:FORI=0TO15:R=(RND(1)*2*(J>0))+(I=15):V=6276+J+I*32 4 IFR=0THENVPOKEV,1:C=C+1:NEXT:ELSEVPOKEV,0:R=RND(1)*C:TIME=0:B$="TIME UP! @RD:" 5 VPOKEV-R*32,VPEEK(V-R*32)-2*(J>0):C=1:NEXT:NEXT:COLOR4:R=RND(1)*13:F=R+1:X=0 6 PUTSPRITE1,(226,38+R*8),9,0:T=STICK(0):W=T<4:S=TMOD4:T=(ABS(T-4)>1)*2+1:K=60-L 7 M=(S=3)*T:N=(S=1)*T:V=VPEEK(6276+(Y+N*W)*32+X+M*W):X=X+(VMOD32>1)*M:C$="cegbb" 8 Y=Y-(VMOD2)*N:PUTSPRITE0,(33+X*8,30+Y*8),9:IFX=23ANDY=FTHENL=L-8:PLAYC$:GOTO3 9 LOCATE9,2:Z=TIME\55:PRINTL-Z:IFZ=LTHENPRINTB$+STR$(K\8+1):PLAY"gcc":GOTO2ELSE6
* MAZE 80 Program Explanation:
Line 0: SCREEN1,,0:KEYOFF:DEFINTA-Z:FORI=1TO6:VPOKE14336+I,126:NEXT:READA$:FORI=0TO31
Start the program by initializing Graphics Mode 1 with keyclick turned off, turn off the on-screen function key list and define all variables as integers.
FORI=1TO6:VPOKE14336+I,126:NEXT: This defines the sprite as a 6x6 square
READA$:FORI=0TO31: Start defining the maze characters (continued on line 1)
Line 1: VPOKEI,VAL("&H"+MID$(+A$,1+(I\8)*4-2*(IMOD8>5),2)):NEXT:DATA3F003F3FFF00FF3F
This line consists of the main chunk of the loop where I define characters 0 through 4 as the maze characters which look sort of like this: "|__", "| ", "___", "_ "
Read the data into string A$ and then via a convoluted equation, poke the compressed data into memory.
The character maze graphics are all 6 rows of the same followed by 2 rows of the same, so for example: "3F,3F,3F,3F,3F,3F,00,00" gets shortened to "3F,00" and the equation 1+(I\8)*4-2*(IMOD8>5) stretches it out to the correct sequence of bytes.
Line 2: COLOR4,1:L=60:LOCATE9,1:PRINT"HIT KEY":R=RND(TIME):IFNOTSTRIG(0)THEN2ELSEBEEP
This line is essentially the title screen.
Start by setting the screen color, setting L to 60 (This is the initial timer value), and printing the elaborate "HIT KEY" message on-screen.
Initialize the random seed based on the timer when you start the game R=RND(TIME). By initializing it once with time at the start, you can just use the shorter RND(1) through the rest of the program and get pretty good results.
Loop back to the start of this line until SPACE has been pressed, otherwise BEEP and continue to the next line.
Line 3: CLS:VPOKE8192,68:FORJ=0TO23:FORI=0TO15:R=(RND(1)*2*(J>0))+(I=15):V=6276+J+I*32
Clear the screen, then set the color of the maze tiles to solid blue so that you can't see what they are when the maze is being drawn: VPOKE8192,68
Next is a nested FOR loop which will be continued on lines 4 and 5.
This is where we actually draw the maze using a version of what's known as a "sidewinder" maze algorithm.
If you'd like to learn all about maze drawing algorithms, check out this site: https://weblog.jamisbuck.org/2011/2/7/maze-generation-algorithm-recap
R=(RND(1)*2*(J>0))+(I=15): This randomly sets R to either 0, -1 or -2 based on where you are in the loop. I'll explain the reason for this in the next line.
V=6276+J+I*32: In the maze draw loop, the maze characters will be vpoked to the screen starting at location 6276. This is just to save some space by precalculating the location.
Line 4: IFR=0THENVPOKEV,1:C=C+1:NEXT:ELSEVPOKEV,0:R=RND(1)*C:TIME=0:B$="TIME UP! @RD:"
IFR=0THENVPOKEV,1: The program draws the maze in columns going from left to right, top to bottom. In line 3, R is set to 0, -1, or -2, but we only check if R is 0 or not. If R is 0, then set the current character to 1 "| ". For the first column, we want everything to be set to 1 except for the bottom character which needs to be set to 0 "|__".
C=C+1: Everytime the program decides to open a path downwards (R=0), C gets incremented. This value is used to decide where to open up paths from the current column to the column on the left.
ELSEVPOKEV,0:R=RND(1)*C: If R isn't 0, then it's time to open a path up to the left. Set the current character to 0, then set R to a random number based on C. Maze drawing is continued in line 5.
B$ is where I define the game over text.
Line 5: VPOKEV-R*32,VPEEK(V-R*32)-2*(J>0):C=1:NEXT:NEXT:COLOR4:R=RND(1)*13:F=R+1:X=0
VPOKEV-R*32,VPEEK(V-R*32)-2*(J>0): This chooses a random opening in the current vertical path and sets the selected character to itself +2 unless the first column is being drawn. This changes a 0:"|__" to 2:"___", or a 1:"| " to 3:"_ ".
C=1:NEXT:NEXT: Reset C and increment the FOR loops
COLOR4: This resets the colors for all characters to Dark Blue / Black which causes the maze to become visible.
R=RND(1)*13:F=R+1:X=0: Set R to a random vertical location for the target dot, Set F to save a tiny bit of space later on and Set the starting position for the player's dot.
Line 6: PUTSPRITE1,(226,38+R*8),9,0:T=STICK(0):W=T<4:S=TMOD4:T=(ABS(T-4)>1)*2+1:K=60-L
PUTSPRITE1,(226,38+R*8),9,0: Place the target dot.
T=STICK(0):W=T<4:S=TMOD4:T=(ABS(T-4)>1)*2+1:K=60-L: Here's where the player movement and wall detection starts.
Start by setting T to the current value of the arrow keys.
Value W is used to decide whether to check your current location for walls or to check the tile ahead of you.
S is used to know if the direction is Up/Down (1), or Left/Right (3)
Set T to (ABS(T-4)>1)*2+1, this makes Up=-1, Down=1, Left=-1, Right=1. This is used for movement.
K is used for the timer.
Line 7: M=(S=3)*T:N=(S=1)*T:V=VPEEK(6276+(Y+N*W)*32+X+M*W):X=X+(VMOD32>1)*M:C$="cegbb"
M=(S=3)*T:N=(S=1)*T: These give us more movement values and makes the program slightly shorter.
V=VPEEK(6276+(Y+N*W)*32+X+M*W): This gives us the value of the character that we need to check to see if there is a wall blocking the player movement or not.
X=X+(VMOD32>1)*M: Move the player Left or Right if there is no wall in the way.
Define C$ to be used to play a sound later.
Line 8: Y=Y-(VMOD2)*N:PUTSPRITE0,(33+X*8,30+Y*8),9:IFX=23ANDY=FTHENL=L-8:PLAYC$:GOTO3
Y=Y-(VMOD2)*N: Move the player Up or Down if there is no wall in the way.
PUTSPRITE0,(33+X*8,30+Y*8),9: Place the player sprite at the current position.
IFX=23ANDY=FTHENL=L-8:PLAYC$:GOTO3: If the player has reached the target dot, then subtract 8 seconds from the stage timer, play a few notes and go to line 3 where the next maze will be drawn.
Line 9: LOCATE9,2:Z=TIME\55:PRINTL-Z:IFZ=LTHENPRINTB$+STR$(K\8+1):PLAY"gcc":GOTO2ELSE6
LOCATE9,2:Z=TIME\55:PRINTL-Z: This is where the timer is decremented and printed at the top of the maze.
IFZ=LTHENPRINTB$+STR$(K\8+1):PLAY"gcc":GOTO2ELSE6: If the timer has reached 0, Print "TIME UP! @RD: (current round #)", play a couple notes and go back to 2 ("Title screen").
Otherwise, loop back to line 6 to continue the game.
Install instructions
* Loading instructions:
Boot up MAZE80.DSK in your favorite MSX emulator and type LOAD"MAZE80.BAS", and then type RUN to start the program.
Leave a comment
Log in with itch.io to leave a comment.