Hi,
I'm coding a 6502 dissasembler and now i have a problem.
How identify if a byte is an Opcode or a piece of Data (like texts New Game, Press Start, etc..) ?
thxs...
You need context, since a single byte includes no extra information as to whether it's used as an opcode, operand, or data, or combination of these.
1) Disassemble continuously
2) Emulate game and keep track of which bytes were executed as opcodes
Ok, thxs blargg...
It's not easy to understand blargg...so, i'm very confused. I wondering if its happening with others coders around here and if is normal...and what about Kent Hansen's NESrev? It can detects the differences between code and data.
A tracing disassembler runs the code in a mini-simulator, marking bytes as code or data as it sees them.
At first I thought all a disassembler had to do to tell apart code and data was to take all possible branches and jumps. But it's just not that simple, because of indirect addressing and things like that.
I think only by actually playing through the whole emulated game and monitoring the bytes that have already been flagged as code or data one can correctly disassemble it.
I've noticed that the Z80 has more success with following the branches and calls for disassembly.
As far as I know, you must trace the game from the RESET vector. If mapper #0, it's easy. Take care about the branches and look for tables. Tables are usually loaded like "LDA $C186, X" - so, you mark the code at C186 as data. You might figure its loading size by looking an immediate branch as example. Plus, anything about a RTS instruction *might be* data.
Wow, thxs for the tips...i'll keep working...Fx3, i'm testing with mapper #0 and comparing with FCUXD Debugger, but i'm getting strange things like
LDA $8D8D
STY $8C8C
...anyway, i'll keep working and reading docs and testing your tips...
thxs...