MEGAMON
by John Mullins
from Your Computer, February 1986

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 un- documented Z80 instructions. All of the
controls are accessed through single key-presses so Megamon is easy to
understand and simple to use.

Listing 1 is the short loader program for Megamon. Type this in and
save it as the first thing on your tape as "MEGAMON". Listing 2 is the
standard hex-loader program. Simply type it in, save it, then run it.
When all of the bytes have been successfully entered then the loader
program will prompt you to hit any key when ready to save the code.
Ensure your tape is positioned after the Megamon basic loader.

To run the program rewind the tape and type
	LOAD "MEGAMON"
When the program has loaded the title screen will appear and you will
be asked for an address at which to load Megamon. This can be any
address from 7000H up to E000H.

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. [The startup program as listed in the mag doesn't actually
start up Megamon, it just loads it. JimG]

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,AXL. 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", ie. add A to I.

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 undocumented 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 function pad are used to move the Memory Pointer ">" within
the Memory Display in the appropriate 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 key press 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 entered
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).

B - Go: This allows you to execute the object code currently under
examination with the use of "breakpoints", ie. 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, ie. the address at which you wish your "break- point" 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 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 instruction 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'.
