6502 Disassembler on an NES ROM

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
6502 Disassembler on an NES ROM
by on (#157019)
I'm sure this has been done before, but I wanted to share it anyway.

This a simple little project I've been working on that will eventually allow for any 4 kilobyte file to be interpreted as raw 6502 assembly code and disassembled accordingly.

However, all it can do right now is disassemble 28 bytes (Enough for a whole screen of implied instructions), so it isn't too useful yet. I want to add scrolling so that the entire 4Kb can be read. I'll also try to make the ROM size smaller, as it's gigantic right now. This may even allow for the disassembly of 8 Kb.

There are some limitations. It has no way of knowing what's code and what's data. The best thing I can think to do right now is, whenever it comes across something that isn't an opcode, it'll just display its byte. Of course this still has the potential for nonsense code to be displayed, but it's better than nothing.

To have something be disassembled, open it up in a hex editor, copy the bytes you want to be disassembled, and paste them at location $0010 (PRG location $8000) in the program's ROM file. (Be sure not to have it inserted, but rather be pasted over.) I'll make a program that'll do this automatically soon. Whatever is at $8000 should get disassembled on your TV or computer screen.

NES Disassembler-0.png
NES Disassembler-0.png [ 2.4 KiB | Viewed 2376 times ]

NES Disassembler-1.png
NES Disassembler-1.png [ 2.41 KiB | Viewed 2376 times ]

NES Disassembler v.01.nes [40.02 KiB]
Downloaded 155 times

Maybe this can be used for something
Re: 6502 Disassembler on an NES ROM
by on (#157149)
I find this type of program interesting, I'd really like to have something like this with the bootloader utilities for GTROM. I don't think anyone has written a disassembler that run on NES before.

The only similar program I can think of is Microbug by kevtris (at the bottom of this page): http://kevtris.org/Projects/copynes/copyware.html
It actually emulates the 6502 in the 6502 asm, which I thought was really cool. But the actual disassembly view that you see in those screenshots is done on the PC host side of the software. I'm glad I was reminded of this, because I had been meaning to ask kevtris if he can release the source to that, I know he originally intended to but overlooked it. So I did, and maybe we'll see it sometime soon.

It would be really neat to have Microbug combined with a disassembler such as yours. CopyNES had it kind of rough because it only had part of the stack available, so it works for almost any cartridge. A new program though could just reserve parts of RAM for debugger use, and do this natively on the NES.
Re: 6502 Disassembler on an NES ROM
by on (#157265)
kevtris uploaded it, here is the source code to the CopyNES ROM, which includes the 6502 and PPU emulator I mentioned.

I might not start on it for a couple weeks, but I'm wanting to change this to assemble with CA65 and try some stuff with it. I just think it'd be hilarious to run NES code in a virtual machine on the NES.