• About
  • Gallery of Images
  • Archives
  • Categories
  •   BBC Basic – Storing a level

    27/01/13 - 15:51

    My first computer was a BBC Model B micro-computer.

    beeb

    Sexy looking thing isn’t it? The baby had 32K of memory, could support 8 colours ( slightly more with various tricks ) and came installed with BBC Basic, my first programming language. In the dreamy days of the 1980s there were a lot of computer magazines – most of which featured source code listings of programs you could type in into your home computer and play with. This was very cool – however, the drawback was a lot of these programs where quite long – and typing them into the computer had all sorts of issues ( no copy and paste for one thing ). So, my Dad, upon seeing a program that he really wanted to type in decided to stick me in front of the computer and get me typing it out for him. I remember him telling Mum that it will teach me how to use a keyboard, which will be a valuable life lesson. How right he was. Personally, however, I think he was just being lazy 😉

    I became fascinated with typing in the programs I found in magazines and how by changing the code I could change the program ( and more often than not break it completely ). This of course started my life long love of coding. Recently, I’ve decided to learn HTML5, a far cry from BBC Basic, but I was feeling nostalgic and decided my first HTML5 game would actually be a remake of the first game I ever played – The Tomb of Tutankhamen. I remember spending many hours with my brother and sister playing this game. As an explorer you had to collect crowns, avoid spiders and escape a 16 room pyramid. Thanks to the wonders of the internet, I managed to find a copy of a magazine which contained the full source code of the game. The magazine was called Beebug ( might see a connection with my twitter name there 😉 ) and was a long running magazine aimed at people with BBC Microcomputers.

    So I sat down one snowy night and decided to try and extract the level data from the source code. After much consulting of very old manuals I managed to decode the game, and lots of it really, really impressed me. Without such structured programming as we have today and with such a small amount of memory, so many neat tricks and techniques were used. The one that I thought was uber cool was how the level data was saved.

    The game has 16 rooms, the code for one the rooms look like this :

    2850 DATA 2,2,2,2,2,6,0,16
    2860 DATA FF09ED21BD01FF01F5C511DD
    

    The first number, believe it or not, was the line number 🙂 DATA is the command to indicate that you are storing, well, data. Now the first numbers represent things like the colour used to draw the screen, where the enemy was on the screen, things like that. The actual structure of the level was stored in the long hex string.

    By looping through the hex string two at a time, you get the following :

    FF
    09
    ED
    21
    BD
    01
    FF
    01
    F5
    C5
    11
    DD

    How does that help us? Well, what if we converted these hex values to decimals ?

    255
    9
    237
    33
    189
    1
    255
    1
    245
    197
    211

    Hmmmmm, still doesn’t look like a level to me – lets try converting it into binary and pad out all strings with 0 where they are not 8 long

    11111111
    10010000
    11101101
    10000100
    10111101
    10000000
    11111111
    10000000
    11110101
    11000101
    10001000
    11011101

    Looks like a bunch of 1’s and 0’s. Here is a screenshot of a page I used as a programming jotter, to check my theory :

    maze

    We have a level! 🙂 now, piecing together all these DATA strings gives you a view of the entire map :

    maze2

    Now, I have no idea why the levels were encoded like this. Maybe it was to protect the level data, maybe it was to save space or memory, maybe it was to stop children from making mistakes typing in long lines of 1s and 0s when they had been sat infront of a computer by their father. But either way, I thought this was a very nifty and cool way of solving the problem of level storage 🙂

    lamentconfig
    Share

    3 Responses to “BBC Basic – Storing a level”

    1. Andrew says:

      That is so cool! I am in the middle of making a retro game too, and I find it fascinating the way technical limitations can sometimes actually be a stimulus for creativity.

    2. […] old trick ( the BBC used a similar idea to hold level data in hex values – I wrote about it here many years ago ). But it does mean that you can store 3d data in a png file. There are a couple of […]

    Leave a Reply to Andrew


    %d bloggers like this: