I recommend that you actually look at the code in the !RunImage file if you want to know the file format - in fact, you might as well use the code from this, but give me a mention. It is rather inefficient however. If you want to use your own, I *THINK* that the following information is correct and will be of interest. Don't rely on this however, the actual code is more reliable.
The information is put into the file as a series of bytes.
Every section except for the actual map starts with one byte representing the number of bytes after this which the piece of information occupies.
Section One: 1 byte of length info, next four bytes are ASCII ("MAPM") to identify the file type.
Section Two: 1 byte of length info (x), next 'x' bytes are ASCII (for the horizontal size of the map)
Section Three: 1 byte of length info (x), next 'x' bytes are ASCII (for the vertical size of the map)
Section Four A: 1 byte of length info (x), next 'x' bytes are ASCII (the numerical equivalent of TRUE and FALSE in BASIC, which are -1 and 0 respectively) which identifies whether a password is stored or not.
Section Four B: If a password is stored, 1 byte of length info (x), next 'x' bytes are ASCII (the password)
Section Five A: 1 byte of length info (x), next 'x' bytes are ASCII - as in section 4A, but this determines whether information is stored or not.
Section Five B1: If info is stored, 1 byte of length info (x), next 'x' bytes are ASCII (the name of the level designer)
Section Five B2: If info is stored, 1 byte of length info (x), next 'x' bytes are ASCII (the title of the level)
Section Five B3: If info is stored, 1 byte of length info (x), next 'x' bytes are ASCII (the description of the level)
Section Six: This is the actual map. Every block type has a number from 0-63 by default to represent the 64 block types, although this can be reduced or increased. Every location on the map is represented by a single byte, limiting the number of block types to 256. This should be enough for almost any game, but by altering some code this could be increased.
The data is stored from left to right, doing each row in turn starting from the bottom (a bit like the graphics coordinates in BASIC, starting from the bottom left).
Section Seven: 1 byte of length info (x), the next 'x' bytes feature some information about the program used to create these maps.
Well done! You have managed to read through that lot without falling asleep!
To be honest, the file format is much simpler than it sounds. The description of the file format above is confusing, but I can't think of a better way of describing it. You could always have a look at a map file with something like !Zap, it would probably be helpful. This file format does ensure, however, that the map can be used in any language which the file to be read into memory, not just BASIC.