achan1989 / ghidra-65816

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

lda is decoded incorrectly #12

Closed hellow554 closed 3 years ago

hellow554 commented 3 years ago
0080f9 a9 78           LDA        #$0x78=>LAB_0080f9+1
0080fb 22 40 b1 02     JSL        !>$DAT_02b140                                    = F0h

really should be

0080f9 a9 78 22    LDA    #$2278
0080fc 40          RTI
oziphantom commented 3 years ago

you need to check the processor options, you can also sometimes need to set the Register value. Make sure ctx_EF is 0. First clear the place where the SEP or REP is down. then modify the EF flag, then 'd' again and it should then track the SEP/REP. If you are jumping to code that assumes a different value from the code above, you will need to manually set the ctx_XF or ctx_MF flags either in the register settings window of the processor settings window. ( both in the right click context menu)

hellow554 commented 3 years ago

So in my case, where I try to disassemble a SNES game, the EF flag should always be set? Am I correct?

oziphantom commented 3 years ago

well not always. Some games do use emulation mode, but its very rare. Basically the 2 or 3 instruction from the emulation RESET vector will probably be clc xce and from then on EF will be 0

0 = 65816 mode 1 = 65C02 mode

also on MF/XF 1 = 8 bit 0 = 16 bit

oziphantom commented 3 years ago

but the initial state of the machine at RESET entry point is 1 for all 3. From there you will need to dissemble. Then follow the JSR/JSL/JMP/JML/BRX etc and trace out each code called and what the MF/XF flags need to be.

hellow554 commented 3 years ago

thanks for the answer. I try to take a look into this this week.