.NES to .ASM (Help)

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems. See the NESdev wiki for more information.

Moderator: Moderators

skillZz
Posts: 1
Joined: Tue Dec 11, 2018 5:13 pm

.NES to .ASM (Help)

Post by skillZz »

Hi guys,

I'm seeking for help because I made a big mistake. Long story short, I was using NESASM Assembly to make a NES game and I accidentally deleted for good my .ASM file (I was deleting a bunch of stuff for clarity & same with my bin however I had put it in... such a rookie mistake).

I often compiled so I have a .NES of my advancements. Is there any way that I could retrieve my .ASM from that .NES ?

Thanks,
User avatar
dougeff
Posts: 3079
Joined: Fri May 08, 2015 7:17 pm

Re: .NES to .ASM (Help)

Post by dougeff »

A disassembler. None of which export to NESASM syntax.

I like frantik's disasm6.

Also available is da65, which comes with cc65.
nesdoug.com -- blog/tutorial on programming for the NES
User avatar
rainwarrior
Posts: 8732
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: .NES to .ASM (Help)

Post by rainwarrior »

You can use a disassembler to recover some of the assembly code:
https://wiki.nesdev.com/w/index.php/Tools#Disassemblers

Unfortunately, all the label and variable names can't be recovered, because they are discarded when assembled into the .NES file.

If you can remember some of the names, with some disassemblers there is a way to feed your reconstructed labels and their addresses to the disassembler so it can apply them instead of just giving a number instead. You'll probably need to do this in several passes. Something like this:

1. Run disassembler.
2. Look for anonymous addresses, and think about what name they used to have.
3. Add address names to the list.
4. Repeat 1 until you've added everything you can manage.

You'll also need to tell the disassembler what parts are code, and what parts are just data, otherwise the data parts will come out as nonsense instructions. With most disassemblers that's done through a similar mechanism as giving it labels.

(Not sure which disassembler to suggest, but I like da65 that comes with the cc65 tools.)
lidnariq
Posts: 11432
Joined: Sun Apr 13, 2008 11:12 am

Re: .NES to .ASM (Help)

Post by lidnariq »

Bisqwit's nescom includes clever-disasm which will automatically do its best to trace execution and distinguish between data and code. I've found that it does a pretty good job... but you're still not getting names out of it.
User avatar
koitsu
Posts: 4201
Joined: Sun Sep 19, 2004 9:28 pm
Location: A world gone mad

Re: .NES to .ASM (Help)

Post by koitsu »

https://wiki.nesdev.com/w/index.php/Tools#Disassemblers may help you. Another (interactive) disassembly not mentioned there is is IDA Pro, but it's commercial and *very* expensive.

YMMV with every single disassembler listed there. Do not expect any of them to give you "original source" quality of output -- you will be expected to do a lot of clean-up (and fix many, many, many mistakes -- particularly for data vs. code) yourself; the simpler the game and mapper, the better (i.e. if your game was NROM with basic CHR-ROM, you should be able to get some tolerable code back, enough to let you rebuild stuff from scratch probably within a few hours of dedication). Whether or not it's better than starting over from scratch varies per project/game/thing.

I do not share lidnariq's opinion of clever-disasm, and I spent several hours with it, plus poked Bisqwit about it (WRT bugs/issues I found), but I was also working on a highly complex and large (256KB) commercial MMC1 title. I do like disasm6, but it has problems/quirks too (I've discussed those with franktik in PM recently). That is all I'm going to say because don't want to off-topic the thread. The point is that the tool may vary for the job, and everyone has their own opinion/preference as to what they like (I'm probably the odd man out in the sense that I don't really like any of them, and I even wrote one ;-) ).
tepples
Posts: 22708
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: .NES to .ASM (Help)

Post by tepples »

Several years ago, I used da65, part of the cc65 suite, to recover my DPCM Split demo after a laptop died.
User avatar
pubby
Posts: 583
Joined: Thu Mar 31, 2016 11:15 am

Re: .NES to .ASM (Help)

Post by pubby »

Heh I wonder if this guy's story is legit, or if he's just trying to hack something copyrighted. :lol:

Not that I care. Hope you figure it out.
User avatar
Sumez
Posts: 919
Joined: Thu Sep 15, 2016 6:29 am
Location: Denmark (PAL)

Re: .NES to .ASM (Help)

Post by Sumez »

Does NESASM not output a debug file with all the labels and such?

ca65's .dbg file is super useful, especially wih Mesen's label import feature - feels like a complete disassembly of my project (though it can be pretty funny with reused ZP variables)
User avatar
koitsu
Posts: 4201
Joined: Sun Sep 19, 2004 9:28 pm
Location: A world gone mad

Re: .NES to .ASM (Help)

Post by koitsu »

Sumez wrote:Does NESASM not output a debug file with all the labels and such?
Like with most (but not all) assembers, such file generation (equates/labels, symbols, and/or a listing) is usually not the default for performance reasons.

For nesasm 2.x and 3.x, use of the -l (dash-lowercase-ELL) flag or pseudo-op LIST in source will generate a listings file, and -s (basic info) or -S (more info) will display ROM layout/bank usage details (possibly to stdout, not sure).
Sour
Posts: 890
Joined: Sun Feb 07, 2016 6:16 pm

Re: .NES to .ASM (Help)

Post by Sour »

Sumez wrote:feels like a complete disassembly of my project (though it can be pretty funny with reused ZP variables)
Have you tried the "Source View" mode? (Right-click on code window -> Switch to source view)
This will load up your assembly source files into Mesen's debugger and allow you to debug using them rather than the disassembly (which as you say, ends up randomly one of the labels defined for any memory address).
User avatar
Sumez
Posts: 919
Joined: Thu Sep 15, 2016 6:29 am
Location: Denmark (PAL)

Re: .NES to .ASM (Help)

Post by Sumez »

Jesus christ, sour, your work keeps amazing me. :O
Sour
Posts: 890
Joined: Sun Feb 07, 2016 6:16 pm

Re: .NES to .ASM (Help)

Post by Sour »

Sumez wrote:Jesus christ, sour, your work keeps amazing me. :O
yaros wrote:Omg, Sour. Did I tell you that you are great and Mesen is amazing?
Thanks! ... And I guess this means that this particular feature could really use a bit more visibility beyond a right-click option in the code window.
yaros wrote:Is there a keystroke like Ctrl+T (Visual Studio 2017) or Ctrl-P (Visual Studio Code) to type file name instead of using mouse?
Not at the moment, but being an abusive user of Ctrl+T myself (can't remember the last time I looked at the project tree to find a file), that's definitely something that would be worth implementing. Could also be used to navigate to a label's definition, too (rather than just limiting it to file names)
User avatar
Banshaku
Posts: 2417
Joined: Tue Jun 24, 2008 8:38 pm
Location: Japan
Contact:

Re: .NES to .ASM (Help)

Post by Banshaku »

We are derailing the thread :lol:

@sour

only asm code can be mapped in the viewer, right? Now that I'm using a mix of the 2 and didn't know about that feature, I want to see how I can use it.
Sour
Posts: 890
Joined: Sun Feb 07, 2016 6:16 pm

Re: .NES to .ASM (Help)

Post by Sour »

Banshaku wrote:only asm code can be mapped in the viewer, right? Now that I'm using a mix of the 2 and didn't know about that feature, I want to see how I can use it.
Both C and assembly files should work, although it can be somewhat unintuitive to step through the C code (since you'll have to step multiple times to reach the next statement, etc) and there is no syntax highlighting, etc.
qalle
Posts: 50
Joined: Wed Aug 16, 2017 12:15 am

Re: .NES to .ASM (Help)

Post by qalle »

Edit: I'm not a spambot. The question mark blocks in SMB are 16*16 pixels.
skillZz wrote:accidentally deleted
Have you tried a file recovery program (like Recuva)?
Post Reply