DISASM6 v1.5 - Nes oriented disassembler producing asm6 code

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems.

Moderator: Moderators

User avatar
koitsu
Posts: 4215
Joined: Sun Sep 19, 2004 9:28 pm
Location: A world gone mad

Post by koitsu » Wed Feb 09, 2011 9:02 pm

What you folks are now talking about is already accomplished using IDA Pro. It does have 6502 support, and can deal with the situations as described in the latter part of the thread.

frantik
Posts: 318
Joined: Tue Mar 03, 2009 3:56 pm

Post by frantik » Thu Feb 10, 2011 12:38 am

NESICIDE wrote:Yes...but....what about bankswitching?
well right now mappers are supported at all anyways

tepples
Posts: 21746
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

How high can Fortran RICH?

Post by tepples » Thu Feb 10, 2011 6:29 am

clueless wrote:And the FORTRAN thing.. I'm sorry if I touched a nerve. I was just teasing (just a little).
With the Fortran comment, I was almost expecting someone to pull out PUSH START TO RICH. Is Dian Shi Mali part of the corpus?
cartlemmy wrote:I'm sometimes astounded by the negativity that is thrown about on these forums.
Don't be astounded; it's expected. Normal person + pseudonymity + audience = dick (NSFW language).
koitsu wrote:IDA Pro
Who's buying? Linus Torvalds originally wrote Linux in part so that he wouldn't have to pay for Unix.

User avatar
Dwedit
Posts: 4236
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Post by Dwedit » Thu Feb 10, 2011 7:04 am

You know, I've had that Mario Lottery rom forever, and never had the "PUSH START TO RICH" event happen. I'm surprised that it spontaneously became a meme, just like Cheetahmen.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!

frantik
Posts: 318
Joined: Tue Mar 03, 2009 3:56 pm

Post by frantik » Thu Feb 10, 2011 10:51 pm

I got it to create all labels, but now i've run into a new problem.. it seems ASM6 forces ZP mode for things such as AND $0023,x .. in the original code it's 3D 23 00 but after using ASM6 it generates 35 23, basically the same thing as AND $23,x

is there a way to avoid using ZP mode in ASM6?

edit: heh looks like i'm not the 1st person to experience this

User avatar
koitsu
Posts: 4215
Joined: Sun Sep 19, 2004 9:28 pm
Location: A world gone mad

Post by koitsu » Fri Feb 11, 2011 12:57 am

frantik wrote:is there a way to avoid using ZP mode in ASM6?
This looks like a bug in asm6. Some people might argue it's a "funny way of doing auto-optimisation", but I disagree.

The parser appears to turn 16-bit absolute addresses with a high byte of zero ($00) into ZP. The assembler does use the correct opcode for the ZP mode, but that isn't what the user wants.

I also confirmed that tricks like "LDA $00ff+0" and "LDA 0+$00ff" do not work around the bug. Parens don't help either.

Loopy et al, can you comment on this?

frantik
Posts: 318
Joined: Tue Mar 03, 2009 3:56 pm

Post by frantik » Fri Feb 11, 2011 2:10 am

i looked at the asm6 code but it wasn't immediately apparent where it selects between ZP vs Absolute

for now i treated it similarly to invalid opcodes and just spit out .hex 3D 23 00.. most of the time it's actually data that is causing it anyways

User avatar
koitsu
Posts: 4215
Joined: Sun Sep 19, 2004 9:28 pm
Location: A world gone mad

Post by koitsu » Fri Feb 11, 2011 4:27 am

It (asm6) seems to do this with any absolute addressing mode (including indexed ones) where a 16-bit value is provided and the high byte is $00. So you'll need to use .DB workarounds for all the opcodes that have that addressing mode. I haven't checked things like JMP ($00FF) yet, but you can do so by writing the code and using "asm6 -l blah.asm", then looking at "blah.lst" to see what gets generated.

frantik
Posts: 318
Joined: Tue Mar 03, 2009 3:56 pm

Post by frantik » Fri Feb 11, 2011 5:20 am

JMP ($00XX) does not seem to affected

finishing up some changes.. it's now a FOUR pass disassembler but it produces code which can be immediately re-assembled into an identical copy of the original, so i got that going for me

tepples
Posts: 21746
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Post by tepples » Fri Feb 11, 2011 5:33 am

Here's how I understand it working in assemblers such as ASM6 and ca65: The values $23, $0023, and 35 all get turned into the same data type (integer). If the assembler can determine that the integer is smaller than $100 at compile time, it emits a zero page instruction; otherwise, it emits an absolute instruction. Why would you want to force absolute indexed over zero page indexed addressing, except A. to join the end of zero page with the beginning of the stack, or B. to program the Super NES (with its movable zero page) instead of the NES?

(Rereading) You mean C. to make NESASM-assembled code round-trippable, as NESASM treats all addresses as absolute unless forced with a zero page operator.

EDIT: For that you need whatever counterpart ASM6 has to ca65's a: address size modifier, which forces 16-bit addressing.

User avatar
Dwedit
Posts: 4236
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Post by Dwedit » Fri Feb 11, 2011 5:58 am

Maybe just create macros for the 16-bit instructions, and emit instances of them instead of the real instructions when you encounter a 16-bit instruction with an 8-bit value.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!

frantik
Posts: 318
Joined: Tue Mar 03, 2009 3:56 pm

Post by frantik » Fri Feb 11, 2011 6:00 am

tepples wrote:(Rereading) You mean C. to make NESASM-assembled code round-trippable, as NESASM treats all addresses as absolute unless forced with a zero page operator.
it's to make all code "round-trippable".. i just used .hex instead, though it would be nice if ASM6 allowed a way to force it to use the specific opcode that is implied by the code.

User avatar
Gilbert
Posts: 358
Joined: Sun Dec 12, 2010 10:27 pm
Location: Hong Kong
Contact:

Post by Gilbert » Fri Feb 11, 2011 6:03 am

This is a bit ironic, as some Japanese recently released a hacked version of NESASM, that you can force it to have the same behaviour as ASM6 when the -autozp option is used.

I now think about it though, apart from the other problematic quirks of NESASM, due to its origin as PCEAS, the "non-auto zero page" aspect of it was actually mandatory, since ZP for the PCE is located at $2000, so if you somehow want to code for both systems, especially when you want to reuse portions of codes in projects for both platforms, it will always be a good practice to manually specify when ZP addressing has to be used.

tepples
Posts: 21746
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Post by tepples » Fri Feb 11, 2011 7:44 am

And ZP for the 8080 derivative in the Game Boy is at $FF00. Both of these cases resemble the Super NES case.

frantik
Posts: 318
Joined: Tue Mar 03, 2009 3:56 pm

Post by frantik » Fri Feb 11, 2011 9:42 pm

i updated the disassembler to version 1.1.. updated the first post but here is the link:

Download Dasm6 v1.1

it's now a multi-pass disassembler, usually taking between 4-5 passes for the labels to "stabilize", with an add'l pass needed to generate the output. you can specify how many passes you want with -p or -passes, or just let it run its course.

i've not tested it with a ton of roms but so far every mapper 0 rom has assembled into a 1:1 copy of the original. For 16k games that have 2 copies in in the .nes file, it will tweak the iNes header from 2 prg banks to 1 unless you disable 16k checking

If you use the new -c or -chr option it will export the CHR data and include it from the assembly file so you can instantly check if the disassembly is valid. The -r or -registers option aliases the common nes registers with their text names instead of their memory addresses.

next i want to add support for custom external memory location/label names (should be easy) and also support the data/code mapping from fceudx.. the code mapping also tells you which bank the code was loaded in so that might be essential for automatic disassembly of more complex roms.
Last edited by frantik on Fri Feb 11, 2011 10:50 pm, edited 1 time in total.

Post Reply