Romhacking.net

Romhacking => Programming => Topic started by: 4lorn on December 06, 2011, 08:56:51 pm

Title: A little help seeing the bigger picture of these ASM instructions?
Post by: 4lorn on December 06, 2011, 08:56:51 pm
I guess desperate times call for desperate measures. As I've explained before, I'm trying to add one single letter to the "SCORE" readout of UN Squadron. I thought I had it down, but it took me a bit to realize I didn't. So I tried using ASMDEV to see what instructions were being loaded during the game, and I was wondering if my gut feeling (a poor replacement for better ASM knowledge, I know) was right.

Here's the relevant snippet, with notes I took (sorry for the mess, was typing them as I found them):

Code: [Select]
8F96 -   930A - STA ($0A), y             // Store accumulator to memory
                                                                               (but it's indirect - is it storing 0A to
                                                                               different addresses? maybe it explains
                                                                               why SCORE and LEVEL have the same acc.
                                                                               values?)
                                                                               (also, repointing this to another offset
                                                                               without the STA opcode doesn't seem to
                                                                               carry any problems, but it still requires
                                                                               the acc. value).
8F98 -   20414C  - JSR $4C41 // Jump to subroutine
                                                                               (4c 41 define horizontal/vertical position)
                                                                               (20 also defines where "SCORE" begins)
8F9B -   5343 - EOR ($43), y         // Exclusive (or accumulator)
                                                                               (53 43, beginning of "SCORE")
                                                                               (why isn't 53, the "S", mentioned first?)
8F9D -   4F52450A    - EOR $0A4552          //        "       "
                                                                               (4f 52 45, middle/end of "SCORE)
8FA1 - 204F4C - JSR $4C4F // Jump to subroutine
                                                                               (4c 4f define horizontal/vertical position)
                                                                               (20 also defines where "LEVEL" begins)
8FA4 -   4C4556        - JMP $5645 // Jump to location
                                                                               (4c 45 56, beginning/middle of "LEVEL")
8FA7 -   454C - EOR $4C // Exc. OR Acc.
                                                                               (45 4c, end of "LEVEL")
8FA9 -   0220          - COP #$20 // Coprocessor Empowerment (causes interrupt)
8FAB -   8F4C2402 - STA $02244C // Store acc. to mem.
                                                                               (4c defines screen position; 24 indicates $)
8FAF -   2487      - BIT $87         // Bit Test (this toggles horizontal pos.)
                                                                               (is it testing against the accumulator?)
                                                                               (87 defines horizontal position of scores)
8FB1 -  4C3002         - JMP $0230            // Jump to location
                                                                               (location 0230?)
                                                                               (4c defines screen position; 24 indicates $)
8FB4 -   2496            - BIT $96          // Bit Test
                                                                               (96 is another position parameter)
8FB6 -   4C3000         - JMP $0030 // Jump to location
                                                                               (jump to location 0030?)
8FB9 -   0624            - ASL $24 // Left shifts Accumulator, Memory
                                                                               (performs a shift left with... 24?)
                                                                               (06 as unknown as 02)
8FBB -   98                - TYA                       // Transfer Y to accumulator
                                                                               (98 is another position parameter)

As you can see, some things aren't clear to me. I'm assuming the first values of all lines are opcodes. But that would mean that in 8F9B, a 53 ("S") is actually required, so a "P" (a 50) would change that to a Branch. Unless that has no effect if there isn't some other required opcode following it, because I did made that change without a problem. It's also not clear to me why it needs to interrupt the processor (8FA9) - is it because it's dealing with a new value to store?

What, if any, optional code might help me here? I was thinking maybe of trying a different STA code, to take into account that one word will be bigger, but I can't think of a way to do this without making the lines even bigger, thus breaking the formatting again. Or a NOP, but then this doesn't seem like it would work either.

Title: Re: A little help seeing the bigger picture of these ASM instructions?
Post by: Mauron on December 07, 2011, 05:30:54 am
You're looking at data there, not code. The code reading that data starts at $00/CE8E.

As far as I can tell the 93 you recorded is something else.

0A is the number of letters read, multiplied by two. Change that to 0C to read one more letter.

20414C is layout data. I haven't figured it out exactly.

53434F5245, is as you suspected, the SCORE text.

After completing that, it moves on to the next length byte, which is again 0A.

204F4C is more layout data, followed by the five letters 4C4556454C (LEVEL).

It reads in a $ by itself, then two 0s.

When it starts to load the next length byte, it loads 00. That means that this block of text is over.
Title: Re: A little help seeing the bigger picture of these ASM instructions?
Post by: 4lorn on December 07, 2011, 06:07:19 am
You're looking at data there, not code. The code reading that data starts at $00/CE8E.

Sorry :/ The ASM was visible through ASMDEV's Code window, and I was using that terminology.

Quote
As far as I can tell the 93 you recorded is something else.

I think the 93 is, or should be the STA opcode. It's the bit of code right before the start of the HUD text. But it seems repointing this elsewhere - and ditching the 93 - carries the same result.

Quote
0A is the number of letters read, multiplied by two. Change that to 0C to read one more letter.

Very true:

(http://img853.imageshack.us/img853/3420/0000000y.png)

While I need to test it more, it seems to work flawlessly. I'm... Just not sure why. Or rather, I had already tried using 0C, but I guess I must've screwed up something elsewhere as it didn't work. In other words, I think I understand why it works, just not the how. I thought adding any extra values would go over the original formatting, thus making the rest of the HUD unreadable. I now see the problem wasn't the extra value, but the lack of a correct instruction suited to the extra text.

Quote
20414C is layout data. I haven't figured it out exactly.

These bits control screen positioning, basically. Every 20 in this bit of code determines from where textual HUD elements begin to be "printed" on screen (a 19 instead would pull SCORE one tile back, for instance, 21 would push it one forward, etc.), while 41 4c (thanks to KingMike and Gideon Zhi for this) are control data for the words themselves, storing/regulating horizontal and vertical values for where text appears.

I can't thank you enough for the help, Mauron :) Kind of a bittersweet victory, though - I'm no genius, but I realize I could probably have figured this if I hadn't simply assumed some things :/
Title: Re: A little help seeing the bigger picture of these ASM instructions?
Post by: Mauron on December 07, 2011, 01:39:10 pm
Sorry :/ The ASM was visible through ASMDEV's Code window, and I was using that terminology.

Code in an SNES ROM is stored the same way as other data. If you try to disassemble data, you'll likely get something, but it will be gibberish.

Use a debugging emulator in the future. I set a read breakpoint on $01/8F97, the start of the text control.

Quote
I think the 93 is, or should be the STA opcode. It's the bit of code right before the start of the HUD text. But it seems repointing this elsewhere - and ditching the 93 - carries the same result.

It could be, but in this case it's likely something else.
Title: Re: A little help seeing the bigger picture of these ASM instructions?
Post by: 4lorn on December 07, 2011, 02:10:13 pm
Code in an SNES ROM is stored the same way as other data. If you try to disassemble data, you'll likely get something, but it will be gibberish.

Use a debugging emulator in the future. I set a read breakpoint on $01/8F97, the start of the text control.

I see.

Well, I used Snes9x to track that text's pointer but at the time I wasn't even paying attention to the ASM :/ Serves me right!
Title: Re: A little help seeing the bigger picture of these ASM instructions?
Post by: Dr. Floppy on December 22, 2011, 02:26:37 am
$93 isn't anything in 6502 assembly; no opcode ends in a -3, -7, -B or -F. This is actually a good thing, as it helps narrow down what those bytes are by virtue of what they *can't* be!

http://badderhacksnet.ipage.com/badderhacks/index.php?option=com_content&view=article&id=253:introduction-to-6502-assembly-nes-programming&catid=14:dr-floppy&Itemid=7 (http://badderhacksnet.ipage.com/badderhacks/index.php?option=com_content&view=article&id=253:introduction-to-6502-assembly-nes-programming&catid=14:dr-floppy&Itemid=7)