achan1989 / ghidra-65816

WDC 65816 processor module for Ghidra
MIT License
22 stars 3 forks source link

Base Accumulator Mode should be possible to change for Dissassembling or Patching. #8

Open MasterKnightDH opened 4 years ago

MasterKnightDH commented 4 years ago
                         LAB_1088bc+1                                    XREF[0,1]:   1088bc (R)   
      1088bc c0  e5  3d       CPY        #$0x3de5 =>LAB_1088bc+1
      1088bf 90  0c           BCC        $LAB_1088cc+1
                         LAB_1088c1+1                                    XREF[0,1]:   1088c1 (R)   
      1088c1 c0  e5  4f       CPY        #$0x4fe5 =>LAB_1088c1+1
      1088c4 b0  07           BCS        $LAB_1088cc+1
      1088c6 b9  14  00       LDA        !$0x14 ,Y
                         LAB_1088c9+1                                    XREF[0,2]:   1088c9 (R) , 1088c9 (R)   
                         LAB_1088c9+2
      1088c9 89  20  d0       BIT        #$0xd020 =>LAB_1088c9+1
                         LAB_1088cc+1                                    XREF[0,2]:   1088bf (j) , 1088c4 (j)   
      1088cc 25  8b           AND        <$0x8b
      1088ce 4b              PHK
      1088cf ab              PLB
      1088d0 c2  20           REP        #$0x20

This is from the ROM of Secret of Evermore. The OPCodes would be correct with a default of 8-Bit Accumulator Mode which is what the game uses in this instance and several surrounding ones; $1088C9 would be BIT #$0x20, then $1088CB would be BNE $#0x25, then $1088CD would be PHB. Unfortunately, since the Disassemble option assumes a default of 16-Bit Accumulator Mode, you get the spaghetti code above and the resulting error that I don't know how to fix properly.

Please provide a response to this.

achan1989 commented 4 years ago

The module should disassemble in whatever processor mode Ghidra tells it to. If you look at the readme you'll see the bit I wrote about processor options and register values, and the bit about "I don't know how well Ghidra will pick up on changes to the processor modes." This is particularly true across branches/jumps.

Unfortunately I can't help you much with getting Ghidra to set the right mode. When I tried to use this module myself I couldn't find a way to do it easily, and I did notice that Ghidra can sometimes get stuck into a particular processor mode. You might be able to see if this has happened by opening the register value view (orange diamond icon in the toolbar) and looking at the values of the mode register at addresses at or before the part you care about.

If it is in the wrong mode, I found undoing it to also be difficult. I can't remember exactly, but something like: clear the instructions in the function that is in the wrong mode, set the correct mode again, re-analyse the function. You'll have to experiment a bit, sorry.

achan1989 commented 4 years ago

@MasterKnightDH any luck with this?