Acorn in a maze

Instructions:
You are an acorn in a maze. Find your way to the centre (the chequered square). You can only see the parts of the maze that you have already explored.
Keys: cursor keys

The emulator I used is an online one: JSBeeb - https://bbc.godbolt.org/

Simply copy and paste the source code into it and then type RUN

Technical information:
General:
The program assumes that it is stored at &1900 (i.e. PAGE=&1900, which is the default setting for JSBeeb).
On a cassette based BBC Micro, a program would normally be stored at &E00. If this is the case then change the &F73 in line 20 to &473.

The z=12 on the 1st line can be changed to give a different size maze.
z must be set to an even number between 4 to 16 (inclusive). 4 gives the smallest maze size and 16 the largest. For 4, 6 and 8 you should include a leading zero (i.e. 04, 06 and 08).

All variables are global except for the local x and y parameters in PROCa (global x and y variables also exist).

VDUx is equivalent to PRINT CHR$(x);

VDU31,x,y moves the cursor to x,y

VDU30 moves the cursor to 0,0 (top-left)

Referring to the expanded version of the program:
lines 10 to 32 are for initialisation
lines 33 to 52 are the main game loop
lines 53 to 69 are for the "game over"
lines 70 to 103 are the PROCa maze generation procedure. It uses a randomised depth first search algorithm.
line 104 is the graphics data

initialisation
10z=12
11m=z*2
12DIMg(m,m)
DIM initialises numeric arrays to 0
13FORy=1TOm-1
14FORx=1TOm-1
15g(y,x)=192
set all cells to be wall
16NEXT,

17FORa=&C00TO&C17
20?a=(a?&F73-32)*3
21NEXT
define the graphics characters for wall, finish and acorn from the REM data at the end of the program.

22r=RND(-TIME)
seed the pseudo random number generator (r will be negative)
23MODE4
24PROCa(z,z)
disable cursor, generate the maze

25VDU31,z-1,z-1,225
display the finish character
26*FX4,1
disable cursor keys for editing
30x=2
31y=2
set start position
32g(y,x)=194
put the acorn at that position

main game loop
33REPEAT
34FORb=-1TO1
35VDU31,x-2,y+b-1
36FORa=-1TO1
37v=g(y+b,x+a)
40VDU32+v
41NEXT,
display the part of the maze next to the acorn
42g(y,x)=0
blank out current position
43k=GET-136
44y=y-(k=3)*(g(y-1,x)=0)+(k=2)*(g(y+1,x)=0)
add/subtract one to y if down/up key was pressed and can go there
50x=x-(k=0)*(g(y,x-1)=0)+(k=1)*(g(y,x+1)=0)
add/subtract one to x if right/left key was pressed and can go there
51g(y,x)=194
put acorn at current position
52UNTIL(x=z)*(y=z)
until reached finish position

"game over"
53*FX4,0
enable cursor keys for editing
60VDU30
61FORy=1TOm-1
62FORx=1TOm-1
63VDU32+g(y,x)
64NEXT
65PRINT
66NEXT
display full maze
67r=0
68PROCa(2,2)
enable cursor
69END

maze generation
70DEFPROCa(x,y)
PROCa is called from 3 places: i. at the start to disable the cursor and generate the maze (r is negative), ii. from itself, i.e. recursively to generate more of the maze (r is positive) and iii. at the end to enable the cursor (r is zero).
71g(y,x)=0
blank out current cell
72v$=""
73IFr>0THENg(y-b,x-a)=0 ELSEVDU23,1,-(r=0);0;0;0;
if called from PROCa then blank out connecting cell else disable/enable cursor.
80FORr=1TO7STEP2
81b=r DIV3-1
82a=r MOD3-1
83IFg(y+b*2,x+a*2)<>0THENv$=v$+CHR$(r+64)
90NEXT
Make a list (in v$) of non-blank neighbouring cells. A=up, C=left, E=right and G=down
91l=LEN(v$)
92IFl=0THENENDPROC
If there are none then backtrack
93r=INT(RND(1)*l)+1
choose one at random (r is a number between 1 and l inclusive)
94r=ASC(MID$(v$,r,1))-64
100b=r DIV3-1
101a=r MOD3-1
102PROCa(x+a*2,y+b*2)
generate more maze in that direction
103GOTO80
check if there are more directions to go in

104REMmmm JJJ 11dd11dd(44JJ J4
graphics data for wall, finish and acorn
