I've written a very short program to disassemble 65816 instructions from SNES ROM files. It is not a fully equipped disassembler and it doesn't generate assembly output that necessarily can be assembled by your favorite assembler tool. However, it does work fine as a very quick and easy way to dump out a short listing, if you know the address where it starts and have the ROM file handy.
You can get the tool here:
DISASM: My Quick Disassembler Tool (~16kb, executable, but in ZIP format, v2.0, MD5=8024BB592547D37B01A892302F475C6D) |
Download DISASM v1.0 from my hosting site |
Here is a session at the command line prompt to illustrate what it does. I wanted to dump out the division routine in Dragon Quest III. So I did this:
C:\>disasm DQ3.SMC -S $C0121C C0121C: 08 php C0121D: 78 sei C0121E: C2 20 rep #$20 C01220: 48 pha C01221: B5 00 lda $00,X C01223: 8F 04 42 00 sta $004204 C01227: 68 pla C01228: E2 20 sep #$20 C0122A: 8F 06 42 00 sta $004206 C0122E: C2 20 rep #$20 C01230: EA nop C01231: EA nop C01232: EA nop C01233: EA nop C01234: EA nop C01235: EA nop C01236: EA nop C01237: AF 14 42 00 lda $004214 C0123B: 95 00 sta $00,X C0123D: AF 16 42 00 lda $004216 C01241: 28 plp C01242: 6B rtl
As you can see, I merely specified the starting address and the ROM filename. The disassembler gave me a quick listing of the subroutine. It stopped when the subroutine was complete, too.
The program also would support a hex dump of the same routine:
C:\>disasm src.smc -S $C0121C -E $C01242 -D C01210: 08 78 C2 20 C01220: 48 B5 00 8F 04 42 00 68 E2 20 8F 06 42 00 C2 20 C01230: EA EA EA EA EA EA EA AF 14 42 00 95 00 AF 16 42 C01240: 00 28 6B
Same information, different format. In this case, though, I had to tell the disassembler where to end the listing, too. So I needed to add that address to the command line, as you can see above. I also added the -D parameter to the command line in order to tell the program to "dump" out the hexadecimal bytes.
Here is what the terse command line help says: <>
C:\>disasm disasm -- 65816 Quick Disassembler Disassembles short segments of 65C816 code from a binary ROM file. usage: disasm <filename> /H /A /T /S <startaddr> /E <endaddr> /L <length> /R <tblfilename> (- or / may be used; start, end, and length values may be decimal or hex) <filename> Specifies the ROM filename to examine -H Requests this help -R <tablefile> Specifies the address table filename -S <addr> Specifies the starting memory address to dump -E <addr> Specifies the ending memory address to dump -L <length> Specifies the length of the region to dump -A Assembler source code format (default) -D Hexadecimal format -T Specifies using special termination logic
You may use -S with -L, -S with -E, and -E with -L, to specify the code bytes to examine. You may also specify just the -S and the code will automatically try and figure out when the best time to stop may be. (This doesn't work when using -D, though, as the code isn't analyzing the source bytes as instructions when it is just dumping out data.)
Finally, there is the -R option. This allows you to include a file which defines symbols that the disassembler will then apply to the listings in generates. The file format looks like:
DTMSKY 0xC90566 FUNC { DB, DW, ADR, DW, ADR } Table: Fetch masked data (Y index) DTMSKX 0xC90572 FUNC { DB, DW, ADR, DW, ADR } Table: Fetch masked data (X index) SETFLG 0xC908F0 FUNC { ADR, DW } Set Flag GETFLG 0xC909AE FUNC { ADR, DW } Get Flag DIVIDE 0xC0121C FUNC { } Divides two values DIVIDEND 0x004204 DATA { } Dividend DIVISOR 0x004206 DATA { } Divisor QUOTIENT 0x004214 DATA { } Quotient REMAINDER 0x004216 DATA { } Remainder
The above is an example. Note that two kinds of labels can be declared: FUNC and DATA. These are just 24-bit addresses that either declare a function entry point or else a data item. The open and close set signs allows you to inform the disassembler about parameters that may follow a function call, included as in-line data. The disassembler will then automatically figure out and display the additional information included as in-line parameter values to the function call. Lastly, there is some description text that may also be included. If included, the text will appear as a comment on the source line, as well.
The current code is still a work in progress. It's just a quick tool I developed to allow me to quickly explore the source code or data that is located at some address I'm considering at the moment.
If the tool is useful to you, please feel free to use it.
Related Pages
|
Last updated 5/17/2016, 16:00 UT. You may contact me at jonk at infinitefactors dot org.