         __                             __              ____
   | .  /\ \   __       __ _________   /\_\      .     /  \ \    .     |
  -*-  /  \ \ /\ \  .  /\ \\___  ___\ / / /     _____ / /\ \ \_____ -=o=-     
   |. / /\ \ \\ \ \    \ \ \__/\ \__// /_/_    /     \\ \ \ \ \  _ \ . |  .
      \/_/  \ \\ \ \  __\ \ \ \ \ \  \ \/\_\__/\  ___ \\ \ \ \ \ \\ \    
  .     / /\ \_\\ \ \/\_\\ \_\ \ \ \  \ \/_/\_\ \ \\ \ \\ \ \ \_\ \\ \   .
    .   \/_/ / / \ \/ / / \/_/_ \ \ \  \ \/ / /\ \ \\ \ \\ \/ / /\ \\ \  
          / / /   \  / /    /\_\ \ \_\  \  / /  \ \_\\ \_\\  / /\ \___\  *
          \/_/  .  \/_/     \/_/  \/_/   \/_/    \/_/ \/_/ \/_/  \/____/ 
                                                            ~ LoWLiFe ~
  o~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~o

 Famicom/Snes/Famicom/Snes/Famicom/Snes/Famicom/Snes/Famicom/Snes/Famicom/Snes


                     Call 1 of these cool BBS numbers !

  Hit & Run       (31) 405 742 36      World Hq    Atari ST/Snes-Famicom
  Risky Business  (44) 513 530 299     U.K. Hq     Atari ST/Snes-Famicom/Amiga
  Outer Region    (1)  303 766 2778    U.S.A. Hq   Atari ST/Snes-Famicom
            

 Snes/Famicom/Snes/Famicom/Snes/Famicom/Snes/Famicom/Snes/Famicom/Snes/Famicom

Hai you SNES fans,

This is version 1.1 of SNES debugger (c) M.C.A./ELITE
(has a lot of improvements!)
Developed with Devpack 3.0 (What would I do without it!?)

You have our permission to use/hack/steal/rip pieces of code from
our debugger, but give MCA or ELITE a little credit,
by putting us in your greetings.

The object of this tool is, to load a snesfile, edit a little, send to snes
and see the effect of your changes as fast as possible.(make trainers)
A real debugger has to be written in SNES code and run on the SNES.
So this is a sort of semi-debugger.

HOW DOES IT WORK?
~~~~~~~~~~~~~~~~~

FM_DEBUG.PRG is for mono and FC_DEBUG.PRG is for color.

Install Application:
--------------------
You can install an application in the desktop window so that files will
automatically load after clicking on them. I think this is a VERY useful
option. This is how to do it: 
Click once on fm_debug or fc_debug. (should be inverted now)
Click on Install Application in the gem desktop.
Fill in filetype (document type) like 'SMC'.
Always keep bootstatus NORMAL!
Set default directory to TOP WINDOW.(tos 2.x)
Application type to GEM.
Click on Ok.
And save the Desktop configuration.

Now every time you click on a *.smc file, it starts fm_debug.prg or the 
color version, passes drive, path & filename to the debugger which
will automaticly load the file and set drive & path to the chosen
filename.

Snes File Structure:
--------------------
On the Atari ST there are only LINEAIR adresses, these are adresses which
are all directly accesable. If you have for instance 4 meg, it is as
follows: {0,1,2,3,4,...,$400000} (until 4 meg). So all adresses are directly
accesable!

The Snes has SEGMENTED adressing. Total memory is divided into $40 banks of 
$8000 bytes each.  Direct adresses is only from {0,1,2,3,4,...,$fffe,$ffff}.
This has a limit of 64k. First part {0,...,$8000} is used as data area
or stack. Programs only are between {$8000,...,$ffff}.
It can get indirectly acces higher adresses but then Snes uses banks.
A bank is a 1 byte number from {0,...,$ff}. So Snes memory adresses have
a 24 bit adress, 8 bits bank number + 16 bits adress.

$228765 means adres $8765 in bank $22.

TAB
---
Switches between left and right window. Displays the current filename
at the top of screen. Lets you see which window is active, and what
file it contains. If 1 file loaded, both have the same name.
If 2 files are loaded, they might be different.

L = Load a file
---------------
Pops up the fileselector and let you choose a file. Cancel will return
to the debugger, nothing changed. When a correct file has been chosen,
it'll FREE the old reserved memory, check the new filelength, and reserves
the new space. If there is not enough memory at this point, there is a lot
of change when returning to the debugger. The old memory has been free'd
and previous loaded files can be corrupted! Same for file errors...  
Correctly loaded files will go to the 1st part of memory.
Then it gets the reset vector (intel format) and sets window 1 to where 
it points to. This is the START of the code (always between $8000-$ffff).
window 2 can now also be used to display file 1.

If loading a 2nd file there will be a prompt asking ...[L/R]
if you pick the [R] it will be loaded at window 2.
Now window 1 contains file number 1 and window 2 contains file number 2.
no mixing possible, this will also reserve extra space!
This option is made for file comparisons. (see C) 
If 2nd file is loaded at [L] it will overwrite file 1 in memory,
and also free file number 2!
Right load can be done without affecting number 1.

C=Compare 2 files
-----------------
If 2 files are loaded Left & Right, Compare option is active.
Set Left & Right window to $8000 (use tab) and press C
Every time there is a difference, the comparing...text will be replaced
by a decimal offset from the start of the header and the decimal contents
of the offset. Also the contents of each window will be updated. 
This I use to easily create BASELINE format trainer files.
Like bluesbrothers legend trainer, I load the legend file left and
the original file to the right, then press C each time and write down
all numbers, until I reach $108000 which is the start of the intro.
then I create a file using these numbers, add a few for header, length
etc.. and glue the intro.      
Compare starts at start of left window and start of right window.
If window 1 has reached file 2 it will show 'end of file reached'.

D = Decimal values
------------------
Display current offset from headerstart to top active window in decimal
value, and the contents of the byte inside.
Same as in compare.

H = Hex offset
--------------
Display current offset from headerstart to top active window in hex.

HELP = Help window
------------------
Short info about all functions, general info about vectors,registers,
opcodes with their meaning.
Each screen can be aborted back to the monitor by pressing ESC.
Other keys will display next screen (1-6).

A-X
---
The rep/sep/plp/rti instructions affect the processor status bits 4/5
(Flag X/M),these bits affect the width of various instructions.
In order to get a 100% correct disassembly you need to step through the
code in the same way as the snes would. This is almost impossible.
Therefore I have included the option to set your own width.
A = toggle accumulator immediate instructions between 8 and 16 bit.
affect lda #$12 - lda #$1234  adc/and/cmp/etc..
X = toggle x and y immediate instructions between 8 and 16 bit.
affect all cpx/cpy/ldx/etc..

G = Get or search for
---------------------
B = byte
W = word (2 bytes)
L = triple bytes (3 bytes)
T = text (case sensitive choice)
I = instruction

Search starts in active window at screen adres start.
ESC cancels search. Checks every 64 Kb for key.

N = Next search
---------------

Last entered string of G option stays in buffer. This will be 
searched for again.

M = Modify window adress
------------------------
This changes all typed number/symbols into fake SEGMENTED adresses.
Type any adres in range of $xx8000-$xxFFFF.
Adresses below $8000 are variable/stack/etc.. area's.
They are out of range for this debugger. (what's the use?)
If you enter $408000 it will display $8000
Every thing above segment $3fxxxx will be masked.
So $419314 will display $019314.

HEADER is used as a filestart symbol.
If you type HEADER it'll show strange adresses but it will
show the header bytes. Also very handy if you have hex offset adresses
and want to know where they are... So then type HEADER+9c334 or whatever.
It'll bring you to the right adress. 

O = various calculation
-----------------------
Enter any value or operator.

\ = decimal
$ = heximal (not needed is standard)
+ = plus
- = minus
* = times
/ = divide
! = or
~ = not
% = binary
& = and
^ = eor
> = shift right
< = shift left
also () and []
header = this symbol will display the linear actual filestart.
         If you want to know where the st keeps the program.

Alt-B = Binary Block Save
-------------------------
If Y is chosen, pick name with fileselector, next it'll ask the filelength.
Length is taken in hex, so a value of 20 will save 32 decimal bytes.
You also can save decimal lengths by putting a slash in front.
like: \32
The starting point of save, is at the top of the ACTIVE window.  

Alt-E = Edit
------------
Edit bytes, words, longs(triple bytes), or text. Escape to cancel.
Enter accepts & updates top left active window.

If you type 'G','L', and enter a 4 byte string instead of 3, like 12345678
it will write 345678 !! So the 1st byte is masked off.
123456 entered will work 100%.

Alt-I = Insert file
-------------------
On Y, pick file with fileselector, the file will overwrite the top active
window. It does NOT reserve any memory. Nice option to put an intro
INTO a game, of course you''l need to adapt the reset vector, and the
back jml's. Check with Contrl-G if reset has changed ok.   

Alt-S = Save file
-----------------
Save WHOLE file in active window, same length. Pick name with fileselector.

Control-A = Ascii/code toggle
-----------------------------
Switch between code display(default) and ascii display.
Works on both windows. Nice for Text hackin'.

Control-B = Set or Clear Breakpoint
-----------------------------------
This seems a little strange. Each Breakpoint (10 max) you set will
put a branch to itself at the top of the active window.
So if you run a game it stops at this point, sometimes this can be
handy to find what certain places do. I'd rather had a fast colorcycle
routine at this point, but I know too little about snes-coding to implement
this in my program as yet.
If a breakpoint is set on a place which has alreay be set, it will
be cleared.

Control-K = Kill all breakpoints
--------------------------------
Restores all old values to all breakpoints.         

Control-C = Quit all
--------------------
Go back to the Desktop.

Control-G = Go to start of file
-------------------------------
This gets the reset vector adres and sets the current window to
that adres.

Control-S = Send & Run file
---------------------------
Send active window (whole file) to snes and run it.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

If you have any suggestions on improving this tool, let us know!

All info for this SNES debugger is gathered from info on different
BBS's, A Lot of new Hardware registers by CYNIX and
65SC816 info from the Dutch book "Het Microprocessor data boek" from
P.Hoogeboom (elektuur), pages 129-138.
 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

