The final program is blown into a 250Kbit EPROM. During software development, to avoid continually programming and erasing EPROMS, I use a small assembly with a battery-backed RAM chip fitted with a program/read switch. Not an ideal system but it was the way I started! I work in DOS, write the program in XTPro and the code is assembled using the Starburst 51 Cross Assembler from Devantech Ltd.
There are 3 blocks of 256 bytes addressed in the RAM containing 1) the wall map, 2) the maze solving route map and 3) a record of whether the mouse has been to a square before or not.
Position. The maze is numbered 0 in the start square to 15 traveling east. Then 16 to 31 on the next row and so-on with 255 in the top right hand corner. Moving north or south will result in the maze number increasing or decreasing by 16. Moving east or west will alter the maze number by +1 or - 1.
Direction. West = 1, North = 4, East = 16, South = 64, so by twice using the instruction 'Rotate accumulator Left' or 'Rotate accumulator Right' the direction variable is easily updated at corners (or 4 times for reverse).
Wall map. An individual byte of the wall map holds a number dependant on the presence of NSE or W walls using the values of the direction variable above. After initializing at the start, all squares except those adjacent to the outer walls contain zero. e.g. square 0 would contain 64 + 1 (south wall + west wall). If a wall is sensed by, say, the right hand sensor, the current direction is copied to the accumulator and is Rotated Left twice i.e. giving the actual direction of the sensed wall. The resultant is used to OR the content of the wall map to update that square with the latest wall info. The square on the 'other side of the wall' is also updated accordingly. e.g. if square 34 had a North wall added (+4) then square 50 would have a south wall added (+64).
Maze solving. I use the excellent algorithm devised by Nick Smith which is briefly as follows: The route map squares are all initially given a number one with the exception of the target squares which are given a zero. The algorithm then moves sequentially through all squares asking the questions - Is there a wall, if not, does the touching square have a number less than mine? If the answer is yes, then the route map number is unaltered and move to the next square. If answer is no, then the route map number is incremented by one. Repeating this algorithm produces a pattern of numbers progressively increasing away from the target squares which indicates the optimum route. I had to write a basic program which displays this action before the penny dropped! (copy available).
Decision. When the movement in a square is complete, the sensors will be in the area of the next square (now the current square). Question: Is there a facing wall, if not, has the next square got a number less than mine? If yes, go straight forward one square. If a move straight forward is not possible then look right and if OK turn right, if not look left and if OK turn left and if not reverse. Position variable is updated, direction variable is updated and new action performed.
note: If the next square route number is zero, then you have reached the target!