This is the disassembler I've been working on...
https://github.com/nesdougIt's stable now. And worked on 6 of 7 files that I tested. (Haven't had time to look into why the 1 didn't work. It seems to do great on smaller files). Definitely not 'finished'. Feel free, any of you, to make changes to this file, as you see fit. It works with Python 3, on Windows. May work on other platforms, IDK. Reassembles with asm6.
Known issues. For some reason, I made it absolutely require that the filesize match what the iNES header claims. In my tests, I have been having to edit the file in a hex editor, to remove signatures appended to the end of the ROM.EDIT - another issue, is filenames with spaces in them, asm6 was confused when I typed the name in...like each word of the name was a separate argument. Just remove spaces from the original name before disassembling.Other uses of this file.
1.It tells you (in the command line dialog) lots about the file. How many banks. What mapper. Mirroring. Etc. Some emulators do this too. No big deal.
2.It splits the PRG-ROM and CHR-ROM and saves them (minus the header) as 2 binary files. This might be useful to people planning to burn actual hardware ROMs.
Again, feel free, to fix or improve this file. I know nothing about Python. Also, read the usage for lots of ominous warnings about how it can delete / erase files if you are not careful.
EDIT - you will have to edit line 34 of the python script (path to file) to make this work. See usage for more info.
EDIT2 - This is a no brainer disassembler...you (maybe) will have to literally do nothing to the output file to get it to reassemble correctly with asm6.
EDIT3 - Only for whole .NES files. Won't work for anything else. Maybe I'll edit it later to be more general.
When I try to disassemble "Super Mario Bros 2. (U) (PRG0) [!].NES" as a test, It fails to disassemble due to the following:
"ERROR: couldn't find iNES header"
This is false, it has a "VALID" iNES 1.0 header, This may be a big problem with your code!
Then remove (or comment out) the lines "exit()". See what happens. Maybe something good. Maybe something bad. Nobody knows.
By the way. The only thing that part of the code is doing, is comparing the first 4 bytes of the ROM to $4E $45 $53 $1A. As "usage" says. I don't know Python. I don't know why it doesn't work. It works for me.
EDIT - actually, I left the debugging test there, just uncomment (remove the # from) line 886 that says...
print (workArray[i], " ", testarray[i])
I get... (printed in the command line box)...
78 78
69 69
83 83
26 26
What do you get?
I'm guessing Hamtaro used Python 2. In Python 2, file.read() returns a string. If you index into it, you will get another string (the character), not an int.
You could put something like assert sys.version_info[0] >= 3, "python 3 required" at the top of your source code (after import sys, of course).
If you want to go the 2/3 polyglot route:
In Python 2.6 or 2.7,
bytearray(file.read()) returns an object that behaves more like a Python 3
bytes.
If you want to mark a Python program as 3-only, test for the specific behaviors you're expecting:
Code:
#!/usr/bin/env python3
assert str is not bytes
On my Linux computer, which has both python 2 and 3, I had to type...
"python3 6502d.py"
...in the terminal.
Workes fine (I also had to edit the path, as usual, within the file).
tepples wrote:
If you want to mark a Python program as 3-only, test for the specific behaviors you're expecting
Why would you need to test for behaviours that Python 3 guarantees in a program that's only supposed to run on Python 3?
Also, to know what to test requires an encyclopedic knowledge of the differences between Python 2 and 3.
The hashbang line is very useful, though, because it can be used to automatically select Python 3 on systems with both 2 and 3 installed. I'd recommend that, combined with thefox's assert, which will give a helpful error in the case that Python 2 is used by mistake.
Code:
#!/usr/bin/env python3
import sys
assert sys.version_info[0] >= 3, "python 3 required"
wiLL tHE gREat pYtHON scHisM EvER ENd?This post was corrupted and has been reconstructed from memory.
Here's some more NES related python 3 tools (command line)...
http://dl.dropboxusercontent.com/s/ypfd ... /Tools.zipThe first one, Valid.py, is just a gutted version of the disassembler. And I added a little bit. It checks if valid header, and calculates the expected filesize, and warns you if it's different. (it doesn't do any disassembly)
Sample Output...
test.nes
filesize = 16400
PRGROM size = 1 = 16384
CHRROM size = 0 = 0
Header + PRGROM + CHRROM = 16400
filesize matches header, ok
Mapper number = 0 = NROM
horizontal mirroring
The second, Zero.py, counts the number of zeros, to help you figure how much empty space is left.
Sample output...
test.nes
filesize = 16400
bank size = ?
1 = 8192, 2 = 16384, 4 = 32768:1
number_banks = 2
bank 1 = 95.98% empty. Or, 7863 bytes of zero.
bank 2 = 99.96% empty. Or, 8189 bytes of zero.
You will have to (just like 6502d.py) edit line 29 with an actual path to the file. On windows, you can Shiftt+Right Click and choose 'copy as path' on the .NES file. Paste it on line 29 after the r like...
path = r"C:\Users\Doug\Desktop\PowerPak\py_backup\test.nes"
Neither one creates a new file, so they are safer to use than the 6502d disassembler.
Why not use the command line arguments to take the path of the ROM?
Code:
if len(sys.argv) < 2:
print("usage: 6502d <path>")
exit()
path = sys.argv[1]
because some NES ROMs have very hard to type names, or spaces in them.
But, feel free to edit the files as you see fit.
dougeff wrote:
because some NES ROMs have very hard to type names, or spaces in them.
But, feel free to edit the files as you see fit.
Command line argument systems usually let you put "" around an argument to include spaces. (The enclosing quotes do not become part of the argument string.)
e.g.: command "c:\my files\hello.doc"
This is neat, and I will give it a try. One backburner project of mine is to port Gimmick to Super Nintendo.
Dropbox is an unusual code-distribution mechanism. Would you be open to Github, or some other similar version control hosting system?
If you're making original free software available to the public, such as this disassembler, I second the recommendation of public version control hosting, such as Savannah, GitLab, GitHub, or the like.
I use GitHub, though
FSF has slammed GitHub and SourceForge for requiring users to run proprietary JavaScript.
But I wouldn't recommend GitHub for a Gimmick hack. Because GitHub is inherently public, it is a theoretically bigger target for copyright takedowns by Sunsoft than Dropbox would be.
tepples wrote:
But I wouldn't recommend GitHub for a Gimmick hack. Because GitHub is inherently public, it is a theoretically bigger target for copyright takedowns by Sunsoft than Dropbox would be.
GitHub private repositories are not public. I think the advice can be better generalized as "work that is potentially copyright-infringing is best kept out of public visibility."
The added benefit of GitHub is the fact that you can add some collaborators. I see some ways the output can be improved, like identifying the NMI and jump points, and labeling the PPU registers.
There seems to be plenty of NES-related code on GitHub already, so I doubt it would get taken down for copyright reasons. But in the event that it does, you could always move it to a less popular platform like GitLab.
https://github.com/nesdougThere. Is that better for you?
Thanks for uploading. I've made a few suggestions:
https://github.com/nesdoug/NES-DISASSEMBLER/pull/1
I'm new to github. I'm not sure the etiquette. Am I expected to merge your changes, or leave it as a separate fork?
Also, I never mentioned it, but the reason my disassembler won't output an absolute address in the zero page (instead outputs 3 bytes)...is asm6 always converts this to a zero page address, and it won't reassemble the same.
Example
LDA $0034
Becomes
.hex AD 34 00
Dunno about asm6, but in ca65 you can force absolute addressing with lda a:$34.
No way to force absolute addressing in ASM6, AFAIK. When I need that, I either type the instruction in hex (with the original instruction as a comment to make my intention clear) or I use a mirror (Variable+$800).
dougeff wrote:
I'm new to github. I'm not sure the etiquette. Am I expected to merge your changes, or leave it as a separate fork?
Also, I never mentioned it, but the reason my disassembler won't output an absolute address in the zero page (instead outputs 3 bytes)...is asm6 always converts this to a zero page address, and it won't reassemble the same.
Example
LDA $0034
Becomes
.hex AD 34 00
What you'd do on GitHub (and with collaboration-based source control in general) is review the changes on the pull request first. If you like the changes as-is, you may accept them and merge them. Otherwise (and more typically) you leave comments about what you'd want changed before you accept it.
In my case, I goofed a little, and allowed git to convert the line endings to unix-style, as opposed to the windows-style you had before, so the entire file appears to be changed even though I did not make such sweeping changes. Nothing will break here, since it will be converted back for you as you check it out in Git for Windows, but it makes the pull request review very difficult.
Since we're talking about github etiquette, usually the onus is on the person making the pull request to provide an easily reviewable change.
i.e. you should fix the line endings in your pull request branch, rather than requiring the puller to fix it.
Not that I think it matters or is a big deal in this specific case, but dougeff
was asking about github etiquette.
rainwarrior wrote:
Since we're talking about github etiquette, usually the onus is on the person making the pull request to provide an easily reviewable change.
i.e. you should fix the line endings in your pull request branch, rather than requiring the puller to fix it.
Not that I think it matters or is a big deal in this specific case, but dougeff
was asking about github etiquette.
Right, that's why I've acknowledged my mistake repeatedly, and worked on fixing it
Sorry, wasn't trying to cast shame on you or anything, I know you're fixing it, just wanted to illustrate the point about open source etiquette and thought it made a suitable example.
I know I'm very slow...
mikejmoffitt, I merged your pull request, but when I tested it, it output lots of errors that I didn't understand (cause I'm not sure all what you changed), so I reverted it, and just manually typed in the system args line.