News: 11 March 2016 - Forum Rules
Current Moderators - DarkSol, KingMike, MathOnNapkins, Azkadellia, Danke

Author Topic: Need some 65816 assistance  (Read 3140 times)

JCE3000GT

  • Sr. Member
  • ****
  • Posts: 433
    • View Profile
Need some 65816 assistance
« on: March 13, 2014, 05:58:28 pm »
Ok so I hope a) this is the right place and b) someone can help me.  I'm trying to expand my capabilities on modifying/using    
65816 assembly...but I'm still really a novice.  So this is my research/learning project on the subject. 

Ok here's the details of the ROM I'm working with--and all without spoiling what secret project I'm working on...and it isn't even a Final Fantasy.  :)
ROM Type: LoROM 00:8000 - 6F:FFFF
Hex offset example of a pointer table: 55800

Trace log of the JSR to and the routine in question:

Code: [Select]
$08/F9BC 20 D0 FA    JSR $FAD0  [$08:FAD0]   Jumps to the below...

$08/FAD0 EB          XBA                     
$08/FAD1 A9 00       LDA #$00               
$08/FAD3 EB          XBA                     
$08/FAD4 C2 20       REP #$20               
$08/FAD6 0A          ASL A                   
$08/FAD7 AA          TAX                     
$08/FAD8 BD 00 D8    LDA $D800,x[$0A:D846]   
$08/FADB 18          CLC                     
$08/FADC 69 00 D8    ADC #$D800             
$08/FADF AA          TAX                     
$08/FAE0 E2 20       SEP #$20               
$08/FAE2 60          RTS                     

So the LDA $D800 is what I'm focusing on.  According to the 65816 document I'm using for reference the LDA (BD) is "Absolute Indexed,X" where as the LDA (BF) is "Absolute Long Indexed,X".  Shouldn't BF allow me to point to the new place in the ROM outside of the assumed $0A (50000)?  I've relocated the JSR at the top to point to a new location in the ROM so I can relocate the above routine for expansion, and that part works perfectly.  My problem is I expanded the routine and attempted to change the LDA (BD 00 D8) to LDA (BF 00 D8 2A) and that of course didn't work.  I also did the same to the ADC (69 00 D8) by also changing it to ADC (6F 00 D8 2A).  Didn't work...

Ok so without laughing, what am I doing wrong? 

Nightcrawler

  • Hero Member
  • *****
  • Posts: 5789
    • View Profile
    • Nightcrawler's Translation Corporation
Re: Need some 65816 assistance
« Reply #1 on: March 13, 2014, 06:34:45 pm »
LDA (BF 00 D8 2A) is "LDA $2AD800,x". Is that what you want? For this to work as you instruct, you need to also relocate the data. Is your data now also in bank $2a? You were loading data from bank $0a, now it needs to be in bank $2a to work with the instructions you've given. Otherwise, you want to use LDA (BF 00 D8 0A) which is is "LDA $0AD800,x". That would pull the data from the old location while your routine resides in the new bank.

You can't use the ADC instruction in the manner you expect.  ADC (69 00 D8) is immediate. #$D800 means you're adding the immediate value $D800 to the accumulator. ADC (6F 00 D8 2A) is addressed, so it's actually ADC $2AD800 which means add the value STORED at location $2AD800, which of course is not what you want. If all you did was change the bank, you shouldn't need to change that ADC instruction.

I highly advise stepping through with the debugger to see what is actually happening and where data is being pulled from. This will help you learn better what is going on and what is going wrong.
TransCorp - Over 20 years of community dedication.
Dual Orb 2, Wozz, Emerald Dragon, Tenshi No Uta, Glory of Heracles IV SFC/SNES Translations

JCE3000GT

  • Sr. Member
  • ****
  • Posts: 433
    • View Profile
Re: Need some 65816 assistance
« Reply #2 on: March 13, 2014, 07:38:15 pm »
LDA (BF 00 D8 2A) is "LDA $2AD800,x". Is that what you want? For this to work as you instruct, you need to also relocate the data. Is your data now also in bank $2a? You were loading data from bank $0a, now it needs to be in bank $2a to work with the instructions you've given. Otherwise, you want to use LDA (BF 00 D8 0A) which is is "LDA $0AD800,x". That would pull the data from the old location while your routine resides in the new bank.

You can't use the ADC instruction in the manner you expect.  ADC (69 00 D8) is immediate. #$D800 means you're adding the immediate value $D800 to the accumulator. ADC (6F 00 D8 2A) is addressed, so it's actually ADC $2AD800 which means add the value STORED at location $2AD800, which of course is not what you want. If all you did was change the bank, you shouldn't need to change that ADC instruction.

I highly advise stepping through with the debugger to see what is actually happening and where data is being pulled from. This will help you learn better what is going on and what is going wrong.

Thank you for the reply.  Yes, I've already relocated the data to the new spot in $2A.  I corrected the ADC back to default and then changed the LDA and this is what came out of the debugger when I ran it again...

*snip edit*

I think it is all worked out.  There was an LDA #$0A and changed that over to #$2A and its working well so far.  :D  I appreciate the help!  Probably won't be my last time posting about assembly but it is nice to have something work that you're learning to do.  :)
« Last Edit: March 13, 2014, 08:39:01 pm by JCE3000GT »

Revenant

  • Full Member
  • ***
  • Posts: 205
    • View Profile
Re: Need some 65816 assistance
« Reply #3 on: March 14, 2014, 12:00:32 am »
Another minor suggestion: instead of this,
Code: [Select]
$08/FAD0 EB          XBA                     
$08/FAD1 A9 00       LDA #$00               
$08/FAD3 EB          XBA                     
$08/FAD4 C2 20       REP #$20           

why not this?

Code: [Select]
$08/FAD0 C2 20       REP #$20
$08/FAD2 29 FF 00    AND #$00FF

LightPhoenix

  • Jr. Member
  • **
  • Posts: 6
    • View Profile
Re: Need some 65816 assistance
« Reply #4 on: May 03, 2014, 04:22:00 pm »
One possible reason is that there's another JSR to the REP, skipping the XBA stuff.  Not saying this is what's going on, since I don't know the code (though I suspect I know the game).