Running the code now gives us a strange but not unexpected result.
As the routine I have written so far does not take the sorrounding of each tile into account it is not yet able to accurately show what we would expect to see. So let’s change that.
After a bit of thought I approached the storing of the map data a bit different than I first imagined.
Every map tile will be split in high and low nibbles. The low nibbles will contain the kind of tile (wall, door, etc) while the high nibbles will be used for additional data (maybe sprites for details like torches, etc).
As I traverse through the visible map I only take the low nibble and use the high nibble for information on its relation to its surrounding. This way I can have four kind of tiles and four states they can take (corner, straight, back, far). So a corner wall would look like this in binary: %10000001 or in hex $81.