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. See the NESdev wiki for more information.

Moderator: Moderators

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

Post by frantik »

Hamtaro126 wrote:the WORDs specified in my CDL turn to BYTEs.
what do you mean? CDL doesn't specify words anywhere, does it?
EDIT: Sorry if I reminded you, but aren't you still going to add minimal NSF support?
you suggested it but i dont think i made a comment. it's not a big priority but i may add it. is it any different from a regular rom besides the header?
tepples wrote: In LJ65
src/t.s#game_cycle
ok, got RTS tables working.. also got labels with +/- in them working properly as well

Code: Select all

@das_skip:  LDA $30,x                ; $c469: b5 30     
            ASL                      ; $c46b: 0a        
            TAX                      ; $c46c: aa        
            LDA state_RTSTable+1,x   ; $c46d: bd 77 c4  
            PHA                      ; $c470: 48        
            LDA state_RTSTable,x     ; $c471: bd 76 c4  
            PHA                      ; $c474: 48        
straight_rts:
            RTS                      ; $c475: 60        

;-------------------------------------------------------------------------------
state_RTSTable:
            .word wait_for_join-1    ; $c476: 8b c4         
            .word __c4f9-1           ; $c478: f8 c4         
            .word __c627-1           ; $c47a: 26 c6         
            .word __c6a3-1           ; $c47c: a2 c6         
            .word __c7a8-1           ; $c47e: a7 c7         
            .word __c7a8-1           ; $c480: a7 c7         
            .word __cbb5-1           ; $c482: b4 cb         
            .word __ccc7-1           ; $c484: c6 cc         
            .word __cd0b-1           ; $c486: 0a cd         
            .word __cd73-1           ; $c488: 72 cd         
            .word __ca10-1           ; $c48a: 0f ca         

;-------------------------------------------------------------------------------
wait_for_join:
            LDA $ad                  ; $c48c: a5 ad     
            BNE straight_rts         ; $c48e: d0 e5     
 
custom label file:

Code: Select all

@das_skip = $c469
straight_rts = $c475

state_RTSTable = $C476
state_RTSTable+1 = $C477

wait_for_join = $C48C
User avatar
Hamtaro126
Posts: 818
Joined: Thu Jan 19, 2006 5:08 pm

Post by Hamtaro126 »

frantik wrote: what do you mean? CDL doesn't specify words anywhere, does it?
I'm sure, It should say in the original specifications! Or maybe if there is none, a special build would do!
frantik wrote: you suggested it but i dont think i made a comment. it's not a big priority but i may add it. is it any different from a regular rom besides the header?

Code: Select all

;Please use Fixed-length Font before using!

;The NSF header is for the Wiki, What it is:

;It is 70 bytes for the header, Here is a short reference in my beta code:

;ASM6 Compatible Header Data

;---------------------------------------------------------------- 
; NSF header 
;---------------------------------------------------------------- 

   .db "NESM",$1a ;identification of the NSF header 
   .db $01,$7f,$01 ;NSF Format Version, # of tracks, Current Track #. 
   .dw Load    ;Load Address 
   .dw Init    ;Init Address 
   .dw Play    ;Play Address 
;       0000000000000000111111111111111
;       0123456789ABCDEF0123456789ABCDE
   .db "Yo! Wagyan by H126, (WIP Hack!)",$00 ;Title 
   .db "1987-2010 Capcom,Bandai-Namco  ",$00 ;Copyright
   .db "Maajyan HigaShio,NOW Production",$00 ;Programmer

   .dw $411A  ;Used as Init Verification, Needed for NSF to work
   
   ;Bank Select:
   .db $00,  $00,  $00,  $00,  $00,  $00,  $00,  $00
   ;   with  with  with  with  with  with  with  with 
   ;   $5ff8 $5ff9 $5ffa $5ffb $5ffc $5ffd $5ffe $5FFF
   ;   is    is    is    is    is    is    is    is
   ;   $8000 $9000 $A000 $B000 $C000 $D000 $E000 $F000

   .dw $0000           ;Pal Compatibility Crap (Shouldn't be touched)
   .db $00
   
   .db %00000000       ;Expansion bits: 
                       ;00000000=NONE (Normal/No Extras)
                       ;00000001=VRC6 (Konami VRC6)
                       ;00000010=VRC7 (Konami VRC7)
                       ;00000100=NFDS (Nintendo Famicom Disk System)
                       ;00001000=MMC5 (Nintendo MMC5)
                       ;00010000=N106 (Namcot 106)
                       ;00100000=FME7 (Sunsoft FME7/5B)
                       ;01000000=UNUS (Unused)
                       ;10000000=UNUS (Unused)

   .db $00,$00,$00,$00 ;Unused Bytes

                .base $8000
                .org $8000

;Note: Modify where the NSF Interrupts are from before use, as the NSF interrupts are LOAD, INIT and PLAY,

Load: ; Insert Code Here
Init: ; Insert Code Here
Play: ; Insert Code Here
Sorry if I did it to push buttons, frantik, This contributation (NSF header) is my gift to you,
frantik
Posts: 377
Joined: Tue Mar 03, 2009 3:56 pm

Post by frantik »

Hamtaro126 wrote:
frantik wrote: what do you mean? CDL doesn't specify words anywhere, does it?
I'm sure, It should say in the original specifications!
yeah i don't think CDL says anything about words:

Code: Select all

xPdcAADCC = Whether it was accessed as code.
D = Whether it was accessed as data.
AA = Into which ROM bank it was mapped when last accessed:
00 = $8000-$9FFF
01 = $A000-$BFFF
10 = $C000-$DFFF
11 = $E000-$FFFF
c = Whether indirectly accessed as code (e.g. as the destination of a JMP ($nnnn) instruction)
d = Whether indirectly accessed as data (e.g. as the destination of an LDA ($nn),Y instruction)
P = If logged as PCM audio data.
x = unused. 
no words.. but you can make it recognize jump tables if you make a custom label that ends with "JumpTable" (as seen in my excitebike output), or RTSTable as seen above
Sorry if I did it to push buttons, frantik, This contributation (NSF header) is my gift to you,
thanks.. so the rest of the file is just a regular rom though, right?
frantik
Posts: 377
Joined: Tue Mar 03, 2009 3:56 pm

Post by frantik »

heh, koitsu i found your feature request list from... 7 years ago
Most I've found suffer from the following idiocies:

* Expect specific binary sizes (i.e. 32K or 16K)
* Expect NES images (i.e. full game images with iNES header)
* Do not allow you to specify a src address offset (i.e. $E000 vs. the usual $8000 or $C000)
* Cannot disassemble to code that is easily re-assembled (i.e. without address labels / opcodes+operand bytes)
* Do not support lowercase mneumonics (i.e. all opcodes in uppercase)
* Do no form of proper code tracing (NESRev does this by implementing a small emulator-like pre-pass which generates pretty clean code)
* For those which insert inline comments for NES PPU registers / etc., do not allow you to disable this behaviour
* Do not include binaries for *IX platforms (or do not include source); I consider this a minor issue, though

If you look at all of the 6502 disassemblers out there, you won't find any which encompass all of the above -- or even HALF of the above.
i think i've got almost all of those things.. options to turn off the comments and allow for lowercase mnemonics have been on my mind, just not implemented.

i'm going to add options to specify where to start reading and how much to read.. you can already specify the origin and if there is no CHR, it should treat snippets of code correctly.
frantik
Posts: 377
Joined: Tue Mar 03, 2009 3:56 pm

Post by frantik »

here's version 1.4

changes in this version include

* option for lowercase opcodes
* options for processing arbitrary portions of the rom, either by file location or code location.
* all numeric parameters accept decimal, $hex, 0xhex and %binary forms
* Custom labels ending with "RTSTable" will be interpreted as RTS jump tables. (For any jump table stuff to work you also have to be using a CDL)
* Improved handling of relative labels (eg SomeLabel+1)
* fixed bugs

I'm planning on adding support for TableLow/TableHigh stuff in the next version

oh yeah i changed the name to DISASM6 cause i thought DASM was a generic term for disassembler, but apparently its not. I googled and there is an assembler called DASM and one called ASM6 so this should make it more clear this is a DISassembler, not an assembler.

i'll try to include a proper help file next time around too
User avatar
Dwedit
Posts: 4921
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Post by Dwedit »

How do I tell the disassembler that a memory range 8000-8A20 is data? (edit: figured it out, set the Code Start parameter)
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!
frantik
Posts: 377
Joined: Tue Mar 03, 2009 3:56 pm

Post by frantik »

Dwedit wrote:How do I tell the disassembler that a memory range 8000-8A20 is data? (edit: figured it out, set the Code Start parameter)
the code start parameter allows you to set where to start disassembling from

to explicitly tell it what is code and what is data, right now you have to use a CDL file generated by FCEU* .. i may add a way to indicate if a label is code or data but right now that is the only way. even incomplete CDL files will generate decent results

also, if you make a custom label like

Code: Select all

MyLabel = $8A21
then it will be sure to start processing the opcode at 8A21 even if the stuff above it is data
User avatar
Dwedit
Posts: 4921
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Post by Dwedit »

Mapper writes confuse the disassembler, for example, it thinks that A000 is data because there are writes pointing there. Also looks like FCEUX thought it was data too, because it was marked as both data and code in the CDL file. Maybe "code" should always trump "data".

Code: Select all

            ROL                ; $9ffb: 2a        
            LDY $05f8,x        ; $9ffc: bc f8 05  
            .hex c0            ; $9fff: c0        Suspected data

;-------------------------------------------------------------------------------
__a000:     .hex 01            ; $a000: 01            Data
__a001:     .hex 2a bc 6e 06   ; $a001: 2a bc 6e 06   Data

;-------------------------------------------------------------------------------
            CPY #$01           ; $a005: c0 01     
            ROL                ; $a007: 2a        
            TAY                ; $a008: a8        
Anyway, I think that labels should not interrupt known code, instead emit a label like
_a000 = $ - 1
or something like that.

edit:

Code: Select all

            .hex 90 7f         ; $c706: 90 7f     Illegal Branch - BCC #$7f
Since when are forward branches of 127 illegal?
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!
frantik
Posts: 377
Joined: Tue Mar 03, 2009 3:56 pm

Post by frantik »

Dwedit wrote:Mapper writes confuse the disassembler, for example, it thinks that A000 is data because there are writes pointing there. Also looks like FCEUX thought it was data too, because it was marked as both data and code in the CDL file. Maybe "code" should always trump "data".
ok i will look into that... i dont think i realized a byte could be marked as either code or data. what rom were you testing btw?
edit:

Code: Select all

            .hex 90 7f         ; $c706: 90 7f     Illegal Branch - BCC #$7f
Since when are forward branches of 127 illegal?
i seem to recall asm6 not liking brances to $7f so i did that... ill have to double check again..
yeah... so is this a bug in asm6?

Code: Select all

      90 7D                     BCC #$7F
*** Branch out of range.
edit.. nm, i think it only happens with you're using a constant instead of an addres.. the error message confused me
User avatar
Dwedit
Posts: 4921
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Post by Dwedit »

I was testing the program out on my Chu Chu Rocket game. Also, the quality of disassembly went way up when I made a Code-Data log before disassembling the game.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!
frantik
Posts: 377
Joined: Tue Mar 03, 2009 3:56 pm

Post by frantik »

Dwedit wrote:I was testing the program out on my Chu Chu Rocket game. Also, the quality of disassembly went way up when I made a Code-Data log before disassembling the game.
will this rom exhibit the problem? what are your command line options? (i'm trying to play the game to make an cdl but i can get it to consistently place the arrow tile down..? oh i see you have to hold the button then press the arrow key.... i was like wtf)

i've improved the output somewhat but i think i need to allow a way for users to specify memory locations that should not be interpreted as program code labels when using LDA/STA

Code: Select all

            RTS                ; $9ffc: 60        

;-------------------------------------------------------------------------------
__9ffd:     LDA __8980,y       ; $9ffd: b9 80 89  

;-------------------------------------------------------------------------------
__a000:     .hex 85            ; $a000: 85        Suspected data
__a001:     PHP                ; $a001: 08        

;-------------------------------------------------------------------------------
            LDA __89c0,y       ; $a002: b9 c0 89  
            STA $09            ; $a005: 85 09     
            LDA __8600,y       ; $a007: b9 00 86  
and yeah, using a CDL gives you much much better results. with the CDL it will make educated guesses.. in the future I would like to make the disassembler a little "smarter" when handling roms without a CDL too.
User avatar
koitsu
Posts: 4201
Joined: Sun Sep 19, 2004 9:28 pm
Location: A world gone mad

Post by koitsu »

frantik wrote:
edit:

Code: Select all

            .hex 90 7f         ; $c706: 90 7f     Illegal Branch - BCC #$7f
Since when are forward branches of 127 illegal?
i seem to recall asm6 not liking brances to $7f so i did that... ill have to double check again..
yeah... so is this a bug in asm6?

Code: Select all

      90 7D                     BCC #$7F
*** Branch out of range.
edit.. nm, i think it only happens with you're using a constant instead of an addres.. the error message confused me
"BCC #$7F" is invalid syntax, and whatever asm6 did there (assembled it to $90 7D) is incorrect. It should have just thrown an error and not shown any assembled opcode and operand values at all. I have no idea where it got $7D from. The correct syntax in your code would have been "BCC $7F". There is no immediate addressing mode on branch instructions (such would make no sense).

Furthermore, terminology complaint: The $7F in "BCC $7F" *is not* an address, it's an offset (sometimes called a nearlabel).

And yes, $7F is a valid branch range. It's the equivalent of +127. Branch instructions range from +127 to -128. It's just a signed 8-bit number.
frantik
Posts: 377
Joined: Tue Mar 03, 2009 3:56 pm

Post by frantik »

i thought it was strange.. regardless i've already removed the code for that from 1.5

edit... actually, i think it is an ASM6 bug.. it's treating it like an address

Code: Select all

                                 .org $c000
0C000 90 7A                     BCC $7C
*** Branch out of range.
0C002 90 7A                     BCC $7E
*** Branch out of range.
0C004 90 79                     BCC $7F
*** Branch out of range.
0C006 EA                        NOP
0C007 EA                        NOP
0C008 EA                        NOP
0C009 EA                        NOP
...

0C07D EA                        NOP
0C07E EA                        NOP
0C07F EA                        NOP
0C080 EA                        NOP
vs

Code: Select all

                                .org $00
00000 90 7A                     BCC $7C
00002 90 7A                     BCC $7E
00004 90 79                     BCC $7F
00006 EA                        NOP
00007 EA                        NOP
00008 EA                        NOP
00009 EA                        NOP
0000A EA                        NOP
Last edited by frantik on Fri Feb 25, 2011 8:21 pm, edited 1 time in total.
User avatar
Dwedit
Posts: 4921
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Post by Dwedit »

It's treating #$7F as an absolute address. If you never specify an origin address, it will default to 0000. So it emits the instruction to jump to address 7F relative to the address after the jump (0002), and there's your 7D.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!
frantik
Posts: 377
Joined: Tue Mar 03, 2009 3:56 pm

Post by frantik »

Dwedit wrote:It's treating #$7F as an absolute address. If you never specify an origin address, it will default to 0000. So it emits the instruction to jump to address 7F relative to the address after the jump (0002), and there's your 7D.
yeah that is what it is doing..

it shouldn't matter now though as far as the disassembler is concerned since it generates labels for branches but it seems like BCC $7F shouldn't be treated the same way as BCC SomeLabel where SomeLabel is $7F
Post Reply