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

Author Topic: 6502 Newbie...Help Me Understand Backtracking a Value.  (Read 3440 times)

MiDKnighT

  • Jr. Member
  • **
  • Posts: 11
    • View Profile
6502 Newbie...Help Me Understand Backtracking a Value.
« on: October 09, 2011, 06:41:03 pm »
Hi Guys,

I'm trying to figure something out on the Destiny of an Emperor ROM and looking for help. 

Basically each character portrait is made up of 6 horizontal slices.  Each one is indexed with 00, 01, 02...all the way to FF.  However, because of this we are limited to a fixed number of unique portraits in the game.  Roughly 255/6.  Am hoping to find a way to add additional character portraits.  I can see 2 potential options:

1. Use a double pointer.  But from what I've heard this is very difficult.

or

2. Somehow expand the portrait pointer pic length. Ie... instead of the index grabbing 1 slice, it grabs 6 slices (the whole portrait).   That would allow for 255 unique portraits. 

So...the first thing I want to understand is how the ROM translates the portrait slice index (00, 01, 02...FF) to a hex address where the portrait is stored.  I have found that we store this portrait slice index in $0015 in memory.   In the below code we load the portrait index 0C in $0015 and then it somehow translates that to read the address $8C80.

Here's what I know so far...

1.  It stores the ROM address for the portrait in $001C and $001D. For example (character: Guan Yu) has "80 8C". His portrait is stored in 8C90 in the ROM (add 10).

2. It populates $001C from $0010:

3. It populates $001D by taking 88 and adding $0011 to it. Character Guan Yu example:

Code: [Select]
$CFF5:A9 88 LDA #$88 A:A0 X:03 Y:0D P:NvUbdIzc
$CFF7:65 11 ADC $0011 = #$05 A:88 X:03 Y:0D P:NvUbdIzc
$CFF9:85 1D STA $001D = #$8D A:8D X:03 Y:0D P:NvUbdIzc

With that said, can anybody look at this and tell me how it's getting for $0015=0C to coming up with 8C80?

Code: [Select]
$CFDA:85 15     STA $0015 = #$0A           A:0C X:01 Y:0A P:nVUbdIzc
$CFDC:A9 00     LDA #$00                   A:0C X:01 Y:0A P:nVUbdIzc
$CFDE:85 11     STA $0011 = #$07           A:00 X:01 Y:0A P:nVUbdIZc
$CFE0:A9 60     LDA #$60                   A:00 X:01 Y:0A P:nVUbdIZc
$CFE2:85 12     STA $0012 = #$00           A:60 X:01 Y:0A P:nVUbdIzc
$CFE4:85 10     STA $0010 = #$08           A:60 X:01 Y:0A P:nVUbdIzc
$CFE6:20 5B C1  JSR $C15B                  A:60 X:01 Y:0A P:nVUbdIzc
$C15B:A9 00     LDA #$00                   A:60 X:01 Y:0A P:nVUbdIzc
$C15D:85 14     STA $0014 = #$00           A:00 X:01 Y:0A P:nVUbdIZc
$C15F:A9 00     LDA #$00                   A:00 X:01 Y:0A P:nVUbdIZc
$C161:85 12     STA $0012 = #$60           A:00 X:01 Y:0A P:nVUbdIZc
$C163:A5 16     LDA $0016 = #$E8           A:00 X:01 Y:0A P:nVUbdIZc
$C165:48        PHA                        A:E8 X:01 Y:0A P:NVUbdIzc
$C166:A5 12     LDA $0012 = #$00           A:E8 X:01 Y:0A P:NVUbdIzc
$C168:85 16     STA $0016 = #$E8           A:00 X:01 Y:0A P:nVUbdIZc
$C16A:A5 11     LDA $0011 = #$00           A:00 X:01 Y:0A P:nVUbdIZc
$C16C:85 13     STA $0013 = #$00           A:00 X:01 Y:0A P:nVUbdIZc
$C16E:A5 10     LDA $0010 = #$60           A:00 X:01 Y:0A P:nVUbdIZc
$C170:85 12     STA $0012 = #$00           A:60 X:01 Y:0A P:nVUbdIzc
$C172:98        TYA                        A:60 X:01 Y:0A P:nVUbdIzc
$C173:48        PHA                        A:0A X:01 Y:0A P:nVUbdIzc
...
...continued...
...
$C199:88        DEY                        A:24 X:01 Y:05 P:nvUbdIZc
$C19A:D0 E0     BNE $C17C                  A:24 X:01 Y:04 P:nvUbdIzc
$C17C:06 10     ASL $0010 = #$00           A:24 X:01 Y:04 P:nvUbdIzc
$C17E:26 11     ROL $0011 = #$48           A:24 X:01 Y:04 P:nvUbdIZc
$C180:26 12     ROL $0012 = #$00           A:24 X:01 Y:04 P:NvUbdIzc
$C182:26 13     ROL $0013 = #$00           A:24 X:01 Y:04 P:nvUbdIZc
$C184:26 16     ROL $0016 = #$00           A:24 X:01 Y:04 P:nvUbdIZc
$C186:90 11     BCC $C199                  A:24 X:01 Y:04 P:nvUbdIZc
$C199:88        DEY                        A:24 X:01 Y:04 P:nvUbdIZc
$C19A:D0 E0     BNE $C17C                  A:24 X:01 Y:03 P:nvUbdIzc
$C17C:06 10     ASL $0010 = #$00           A:24 X:01 Y:03 P:nvUbdIzc
$C17E:26 11     ROL $0011 = #$90           A:24 X:01 Y:03 P:nvUbdIZc
$C180:26 12     ROL $0012 = #$00           A:24 X:01 Y:03 P:nvUbdIzC
$C182:26 13     ROL $0013 = #$00           A:24 X:01 Y:03 P:nvUbdIzc
$C184:26 16     ROL $0016 = #$00           A:24 X:01 Y:03 P:nvUbdIZc
$C186:90 11     BCC $C199                  A:24 X:01 Y:03 P:nvUbdIZc
$C199:88        DEY                        A:24 X:01 Y:03 P:nvUbdIZc
$C19A:D0 E0     BNE $C17C                  A:24 X:01 Y:02 P:nvUbdIzc
$C17C:06 10     ASL $0010 = #$00           A:24 X:01 Y:02 P:nvUbdIzc
$C17E:26 11     ROL $0011 = #$20           A:24 X:01 Y:02 P:nvUbdIZc
$C180:26 12     ROL $0012 = #$01           A:24 X:01 Y:02 P:nvUbdIzc
$C182:26 13     ROL $0013 = #$00           A:24 X:01 Y:02 P:nvUbdIzc
$C184:26 16     ROL $0016 = #$00           A:24 X:01 Y:02 P:nvUbdIZc
$C186:90 11     BCC $C199                  A:24 X:01 Y:02 P:nvUbdIZc
$C199:88        DEY                        A:24 X:01 Y:02 P:nvUbdIZc
$C19A:D0 E0     BNE $C17C                  A:24 X:01 Y:01 P:nvUbdIzc
$C17C:06 10     ASL $0010 = #$00           A:24 X:01 Y:01 P:nvUbdIzc
$C17E:26 11     ROL $0011 = #$40           A:24 X:01 Y:01 P:nvUbdIZc
$C180:26 12     ROL $0012 = #$02           A:24 X:01 Y:01 P:NvUbdIzc
$C182:26 13     ROL $0013 = #$00           A:24 X:01 Y:01 P:nvUbdIzc
$C184:26 16     ROL $0016 = #$00           A:24 X:01 Y:01 P:nvUbdIZc
$C186:90 11     BCC $C199                  A:24 X:01 Y:01 P:nvUbdIZc
$C199:88        DEY                        A:24 X:01 Y:01 P:nvUbdIZc
$C19A:D0 E0     BNE $C17C                  A:24 X:01 Y:00 P:nvUbdIZc
$C19C:A5 11     LDA $0011 = #$80           A:24 X:01 Y:00 P:nvUbdIZc
$C19E:85 10     STA $0010 = #$00           A:80 X:01 Y:00 P:NvUbdIzc
$C1A0:A5 12     LDA $0012 = #$04           A:80 X:01 Y:00 P:NvUbdIzc
$C1A2:85 11     STA $0011 = #$80           A:04 X:01 Y:00 P:nvUbdIzc
$C1A4:A5 13     LDA $0013 = #$00           A:04 X:01 Y:00 P:nvUbdIzc
$C1A6:85 12     STA $0012 = #$04           A:00 X:01 Y:00 P:nvUbdIZc
$C1A8:68        PLA                        A:00 X:01 Y:00 P:nvUbdIZc
$C1A9:A8        TAY                        A:0A X:01 Y:00 P:nvUbdIzc
$C1AA:68        PLA                        A:0A X:01 Y:0A P:nvUbdIzc
$C1AB:85 16     STA $0016 = #$00           A:E8 X:01 Y:0A P:NvUbdIzc
$C1AD:60        RTS                        A:E8 X:01 Y:0A P:NvUbdIzc
$CFE9:A5 F1     LDA $00F1 = #$02           A:E8 X:01 Y:0A P:NvUbdIzc
$CFEB:20 82 C4  JSR $C482                  A:02 X:01 Y:0A P:nvUbdIzc
$C482:85 44     STA $0044 = #$0C           A:02 X:01 Y:0A P:nvUbdIzc
$C484:85 ED     STA $00ED = #$0C           A:02 X:01 Y:0A P:nvUbdIzc
$C486:A9 01     LDA #$01                   A:02 X:01 Y:0A P:nvUbdIzc
$C488:85 EB     STA $00EB = #$00           A:01 X:01 Y:0A P:nvUbdIzc
$C48A:A5 ED     LDA $00ED = #$02           A:01 X:01 Y:0A P:nvUbdIzc
$C48C:20 B7 C4  JSR $C4B7                  A:02 X:01 Y:0A P:nvUbdIzc
$C4B7:8D F9 FF  STA $FFF9 = #$AC           A:02 X:01 Y:0A P:nvUbdIzc
$C4BA:4A        LSR                        A:02 X:01 Y:0A P:nvUbdIzc
$C4BB:8D F9 FF  STA $FFF9 = #$AC           A:01 X:01 Y:0A P:nvUbdIzc
$C4BE:4A        LSR                        A:01 X:01 Y:0A P:nvUbdIzc
$C4BF:8D F9 FF  STA $FFF9 = #$AC           A:00 X:01 Y:0A P:nvUbdIZC
$C4C2:4A        LSR                        A:00 X:01 Y:0A P:nvUbdIZC
$C4C3:8D F9 FF  STA $FFF9 = #$AC           A:00 X:01 Y:0A P:nvUbdIZc
$C4C6:4A        LSR                        A:00 X:01 Y:0A P:nvUbdIZc
$C4C7:8D F9 FF  STA $FFF9 = #$AC           A:00 X:01 Y:0A P:nvUbdIZc
$C4CA:60        RTS                        A:00 X:01 Y:0A P:nvUbdIZc
$C48F:A5 EB     LDA $00EB = #$01           A:00 X:01 Y:0A P:nvUbdIZc
$C491:D0 06     BNE $C499                  A:01 X:01 Y:0A P:nvUbdIzc
$C499:A9 00     LDA #$00                   A:01 X:01 Y:0A P:nvUbdIzc
$C49B:85 EB     STA $00EB = #$01           A:00 X:01 Y:0A P:nvUbdIZc
$C49D:60        RTS                        A:00 X:01 Y:0A P:nvUbdIZc
$CFEE:A9 00     LDA #$00                   A:00 X:01 Y:0A P:nvUbdIZc
$CFF0:18        CLC                        A:00 X:01 Y:0A P:nvUbdIZc
$CFF1:65 10     ADC $0010 = #$80           A:00 X:01 Y:0A P:nvUbdIZc
$CFF3:85 1C     STA $001C = #$0A           A:80 X:01 Y:0A P:NvUbdIzc
$CFF5:A9 88     LDA #$88                   A:80 X:01 Y:0A P:NvUbdIzc
$CFF7:65 11     ADC $0011 = #$04           A:88 X:01 Y:0A P:NvUbdIzc
$CFF9:85 1D     STA $001D = #$17           A:8C X:01 Y:0A P:NvUbdIzc
$CFFB:A5 F1     LDA $00F1 = #$02           A:8C X:01 Y:0A P:NvUbdIzc
$CFFD:20 82 C4  JSR $C482                  A:02 X:01 Y:0A P:nvUbdIzc
$C482:85 44     STA $0044 = #$02           A:02 X:01 Y:0A P:nvUbdIzc
$C484:85 ED     STA $00ED = #$02           A:02 X:01 Y:0A P:nvUbdIzc
$C486:A9 01     LDA #$01                   A:02 X:01 Y:0A P:nvUbdIzc
$C488:85 EB     STA $00EB = #$00           A:01 X:01 Y:0A P:nvUbdIzc
$C48A:A5 ED     LDA $00ED = #$02           A:01 X:01 Y:0A P:nvUbdIzc
$C48C:20 B7 C4  JSR $C4B7                  A:02 X:01 Y:0A P:nvUbdIzc
$C4B7:8D F9 FF  STA $FFF9 = #$AC           A:02 X:01 Y:0A P:nvUbdIzc
$C4BA:4A        LSR                        A:02 X:01 Y:0A P:nvUbdIzc
$C4BB:8D F9 FF  STA $FFF9 = #$AC           A:01 X:01 Y:0A P:nvUbdIzc
$C4BE:4A        LSR                        A:01 X:01 Y:0A P:nvUbdIzc
$C4BF:8D F9 FF  STA $FFF9 = #$AC           A:00 X:01 Y:0A P:nvUbdIZC
$C4C2:4A        LSR                        A:00 X:01 Y:0A P:nvUbdIZC
$C4C3:8D F9 FF  STA $FFF9 = #$AC           A:00 X:01 Y:0A P:nvUbdIZc
$C4C6:4A        LSR                        A:00 X:01 Y:0A P:nvUbdIZc
$C4C7:8D F9 FF  STA $FFF9 = #$AC           A:00 X:01 Y:0A P:nvUbdIZc
$C4CA:60        RTS                        A:00 X:01 Y:0A P:nvUbdIZc
$C48F:A5 EB     LDA $00EB = #$01           A:00 X:01 Y:0A P:nvUbdIZc
$C491:D0 06     BNE $C499                  A:01 X:01 Y:0A P:nvUbdIzc
$C499:A9 00     LDA #$00                   A:01 X:01 Y:0A P:nvUbdIzc
$C49B:85 EB     STA $00EB = #$01           A:00 X:01 Y:0A P:nvUbdIZc
$C49D:60        RTS                        A:00 X:01 Y:0A P:nvUbdIZc
$D000:A6 40     LDX $0040 = #$DA           A:00 X:01 Y:0A P:nvUbdIZc
$D002:A5 1F     LDA $001F = #$18           A:00 X:DA Y:0A P:NvUbdIzc
$D004:9D 00 04  STA $0400,X @ $04DA = #$00 A:18 X:DA Y:0A P:nvUbdIzc
$D007:E8        INX                        A:18 X:DA Y:0A P:nvUbdIzc
$D008:A5 1E     LDA $001E = #$00           A:18 X:DB Y:0A P:NvUbdIzc
$D00A:9D 00 04  STA $0400,X @ $04DB = #$70 A:00 X:DB Y:0A P:nvUbdIZc
$D00D:E8        INX                        A:00 X:DB Y:0A P:nvUbdIZc
$D00E:A9 60     LDA #$60                   A:00 X:DC Y:0A P:NvUbdIzc
$D010:9D 00 04  STA $0400,X @ $04DC = #$26 A:60 X:DC Y:0A P:nvUbdIzc
$D013:E8        INX                        A:60 X:DC Y:0A P:nvUbdIzc
$D014:A5 7A     LDA $007A = #$00           A:60 X:DD Y:0A P:NvUbdIzc
$D016:F0 06     BEQ $D01E                  A:00 X:DD Y:0A P:nvUbdIZc
$D01E:A0 00     LDY #$00                   A:00 X:DD Y:0A P:nvUbdIZc
$D020:B1 1C     LDA ($1C),Y @ $8C80 = #$10 A:00 X:DD Y:00 P:nvUbdIZc

I can post the missing code in "continued" if someone replies.  Post was too big.
« Last Edit: October 09, 2011, 06:47:26 pm by MiDKnighT »

Pennywise

  • Hero Member
  • *****
  • Posts: 2350
  • I'm curious
    • View Profile
    • Yojimbo's Translations
Re: 6502 Newbie...Help Me Understand Backtracking a Value.
« Reply #1 on: October 09, 2011, 08:18:12 pm »
I'm not following you son. Seems like you'd want to set write breakpoints to $0010 and $0011.

I also do not see any further use of this $0015 in the code. If you're convinced of a relationship just follow #$0C  and $0015 until all is revealed.

RedComet

  • Hero Member
  • *****
  • Posts: 3168
    • View Profile
    • Twilight Translations
Re: 6502 Newbie...Help Me Understand Backtracking a Value.
« Reply #2 on: October 10, 2011, 11:09:41 am »
Open up the PPU viewer in FCEUXD when the portrait is on the screen and find out where in the tilemap (name table) the portraits are referenced. Then set write breakpoints on those addresses and just work backwards until you find the point where the tile index is calculated.
Twilight Translations - More than just Dragonball Z. :P

MiDKnighT

  • Jr. Member
  • **
  • Posts: 11
    • View Profile
Re: 6502 Newbie...Help Me Understand Backtracking a Value.
« Reply #3 on: October 12, 2011, 10:21:12 am »
I got it guys.  Thanks.  I still don't know exactly how it does it but I got the jist of how it was calculating it and was able to use it to figure out what I needed to do.