Megamon John Mullins' program takes you on a trip to the secret heart of the Spectrum Megamon is a sophisticated disassembler/monitor which works on the Sinclair Spectrum and Spectrum+. Among its many features are an intelligent move memory facility, read or write object code to tape, full memory dump to the printer and a disassembly that will even understand all of the 102 undocumented Z80 instructions. All of the controls are accessed through single key-presses, so Megamon is easy to understand and simple to use. When the program has loaded the title screen will appear and you will be asked for an address at which to load Mega- mon. This can be any address from 7000H up to E00H. [Which, since you can't enter hex addresses into a Basic INPUT, is from 28672 to 57344.] Once the address has been entered, the object code for Megamon is loaded and you will be presented with Megamon's Front Panel screen display. [Actually, you won't. The loader doesn't call the code it loads. In any other program I would have fixed this, but in a machine code monitor it can be actually useful to be able to enter other commands before running the program. For example, though you can load object code from within Megamon itself, you will often want to CLEAR to an address other than that at which you loaded Megamon. That can easily be done at this point. After you've CLEARed and LOADed whatever code you want to inspect, you should now RANDOMIZE USR
(or, if you haven't used CLEAR, you can use USR a) and then you _will_ see the Front Panel.] Z80 Registers - The top right of the screen shows the Z80 registers AF, BC, DE, HL, IX, IY together with the stack pointer (SP) and the program counter (PC). The register contents are shown (at start-up these are always zero) and then the contents of the memory location addressed by that register. There is also the register cursor (">"), which points to AF on start-up. Its use will be discussed shortly. Memory Display - The memory display occupies the bottom of the screen and its purpose is to display the bytes around the memory pointer, indicated by ">". The bytes can be displayed either as hex or as ASCII. PC Instruction - The instruction at the Program Counter is constantly displayed above and to the left of the Memory Display. List Display - The left of the screen above the Memory Display is taken up by the List Display. At start-up this display will be blank, but if you are eager to see it in action then for the moment press 'L' followed by a full- stop. You will see the 14 instructions from address zero disassembled for your perusal. Unfortunately space does not permit a detailed discussion of the undocumented instructions; needless to say their use is becoming much more frequent in many of today's top games. Disassemblers that can cope with them are rare and the format for displaying them varies. For example, look at the instruction ADD A,IXL. This means "add A to the low byte of IX", the "L" tagged on to indicate the low byte. Alternatively, you can use: ADD A,IXH. This means "add A to the high byte of IX", i.e. add A to I. [Sic - I and IX/IY are very different registers!] Megamon would display the two instructions above as follows: (i) ADD A,iX (ii) ADD A,Ix The letter in capitals indicates which byte of the register pair is being operated upon. The same applies to all un- documented instructions that use the IY register pair. Here is a list of the Megamon keys and a full explanation of their usage. The Four Cursor Keys (Shift and 5, 6, 7 or 8): The four cursor keys above the number keys are used to move the Memory Pointer ">" within the Memory Display in the appro- priate direction, allowing you to step up or down through the memory in steps of one or eight bytes at a time. The Full Stop (Symbol Shift and "m"): Pressing the full stop will advance the Register Cursor ">" on to the next register pair in the Register Display. B - Return to Basic: Pressing this key will produce the prompt "Are you sure?". In response to this, press "Y" if you wish to leave Megamon and return to basic. Any other keypress will return you back to Megamon itself. C - Clear List Window: The List Window can be cleared at any time by pressing the "C" key. D - Display Memory: This allows you to change the address around which the Memory Display works. You will be asked for a new address for the Memory Pointer - this must be entered as a hex number terminated by ENTER. If instead of a hex number you press the full stop key, then the Memory Pointer will be set to whatever address the Program Counter currently holds. The address is displayed along with its contents. You can either enter a new hex number for this location or press Symbol Shift and "z" (colon) to exit the memory change. When a new number is entered the memory pointer is advanced to the next location and your options are the same again. At any time during the input of a number you can press the colon keys to abort and leave the Memory Pointer unchanged. F - Fill Memory: The prompt "Fill >" appears and the number nentered here will be the "start" address for the program to use. You are then asked for the address at which the program will end its "fill" and finally the byte to fill the memory with. For example, if you enter 8000 in response to "Fill >", 8100 in response to "To >" and FF in response to "With >", the memory between 8000 hex and 8100 hex will be filled with FF (255 decimal). G - Go: This allows you to execute the object code cur- rently under examination with the use of "breakpoints", i.e., places at which the object code is stopped in its tracks and control returned to the monitor for you to examine the registers etc. The address which you enter in response to "Go >" will be the address at which the monitor starts execution of the object code. As usual with all prompts, if you press the colon keys then the operation will be aborted. You are then asked for an address "To >" at which control will be returned to Megamon, i.e. the address at which you wish your "breakpoint" to be inserted. When you have entered this address, Megamon will go off and execute the code. When the breakpoint has been reached, assuming that the code has not caused a fatal crash, a small line will be displayed on the screen and this means that Megamon is waiting for you to press any key before updating all of its displays. H - Search for String: The prompt "Search For >" is displayed. You can now enter a sequence of up to 255 bytes which will form the string which Megamon will search for. Each number should be entered by pressing ENTER and by pressing ENTER on its own you will terminate the string. At this stage, assuming the string can be found, Megamon will update the Memory Display and the Memory Pointer ">" will be pointing to the second byte of the input string. Also see the explanation of the next instruction, "A". A - Find Next Occurrence: Pressing the "A" key will tell Megamon to find the next occurrence of a string you have searched for using "H". I - Toggle between ASCII and Hex: By pressing the "I" key you can toggle the Memory Display so that it shows either Hex or the ASCII equivalents. L - List: You can enter a new address from which the dis- assembler will list its 14 instructions. But there are two other alternatives to entering a new address. If you press the full stop key in response to "List >" the disassembly will begin from the address currently held in the Program Counter. Alternatively, you can press ENTER in response to the prompt and the disassembly will continue from where it left off. M - Move a Block of Memory: The prompt "Move >" will be displayed and the address you enter will be the start of the memory block you wish to move. The prompt "End >" asks you for the end address of the memory block and the prompt "To >" asks you for the destination address for this block. The routine is "intelligent" so that if your destination address lies within the limits of the block you wish to move, Megamon takes this into account and performs the move correctly. O - Read Object Code: This reads a block of object code in from tape. YOu are prompted to enter a file name and then an address at which the code will be loaded. Obviously you should take care not to overwrite Megamon. P - Printer Disassembly: With this option you can produce a disassembly of any length to your printer; you could even list the Spectrum ROM. The first address you enter, in response to "Print >", is the start address for the dis- assembly, and the second address is the end. Assuming the printer is connected a disassembly will now appear on the printer which can be aborted at any time by pressing the Break key. R - Change Register: By pressing the "R" key you can change the value of the register pair currently pointed to by the register cursor ">". The register pair will take on the value you enter at the keyboard. S - Single Step: Megamon will execute the current in- struction at the Program Counter when you press the "S" key, allowing you to examine the effects of the code upon the registers and memory. This function will also single- step through a CALL instruction. T - Trace: If you press the "T" key Megamon will execute the instruction at the Program Counter in the same way as the "S" function above, except that using "T" allows you to execute a CALL instruction automatically, as opposed to single-stepping through it. W - Write Object Code: This writes a block of code to tape under a given filename. You are prompted to enter the filename and then the first and last (inclusive) addresses of the block you wish to write. X - Toggle Alternate Registers: Pressing the "X" key will toggle the Register Display between AF, BC, DE, HL and the alternate registers AF', BC', DE', HL'.