News:

As a consequence of the forum being updated and repaired, the chatbox has been lost.
However, you can still come say hi on our Discord server!

Main Menu

THUMB code question

Started by Charon, 18, February, 2009, 06:25:00 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Charon

I'm just wondering - is there any way that I can add a THUMB code that checks whether or not you talk to an NPC with the L button? I think I figured out a solution to my whole "telepathy" problem but I'll need a callasm command to check whether the L button was pressed to talk to an NPC. When done, I want it to set a certain variable (like 0x8041 or something) after that, but I don't know if I should just do that with with scripting or with the code...

Basically, what I have in mind is this.

1) The game checks whether or not the NPC was talked to using the L button or not (under L=A)

2) If the L button was pressed, it sets a variable number to 03FF.

3) If the variable is 1, the script jumps right to telepathy. If not, the NPC talks like normal.

Is there any way I can do this? As I said before, I can do steps 2 and 3 with simple scripting; it's the code I'm having issues with.

I went through the memory viewer and it turns out that the "button press" word is at 0x4000130. When the L button is pressed, it displays "0x01FF", when the A button is pressed, it displays "0x03FE" and when no button is being pressed it displays "0x03FF". Is there any way to put this number into a variable and activate this event?

What I got is this:
.text
.align 2
.thumb
.thumb_func
.global lesson1

main:
push {r0-r1, lr}
ldr r0, .PLAYER_DATA
ldr r1, .VAR
ldrh r0, [r0, #0xC]
strh r0, [r1]
pop {r0-r1, pc}


.align 2
.PLAYER_DATA:
.word 0x04000130
.VAR:
.word 0x0201E8C2 + (0x800D * 2)

(actually I just took a THUMB code that checks a kind of data associated with the player and changed the offset to 0x04000130, so that's why it says player_data), but for some reason, when I check it in VBA's dissassembler, it's not actually setting the variable to the proper value...

...help?  

Atrius (He/Him)

Well... I usually do my THUMB editing from VBA's memory editor, but I believe the problem is at "ldrh r0, [r0, #0xC]"

The number after the comma in the brackets is an offset, so you're reading from the location 12 bytes after r0 when you want to read exactly at r0.


Also the variable it's stored in is actually located at 0x0202E8DC, right?
[sprite=220,4,0]I'm shaking my head in general disapproval of everything[/sprite]

Charon

Okay, thanks, I'll see if that helps.

Yes, that's the Lastresult variable, which is used in a lot of functions. If I wanted to set it to 0x8001, it's just be me changing the D to 1, instead of changing the whole offset, which is a pain. Go convinience XD

I just learned about this today, lol, so that's why I seem like such a n00b. Most of the other stuff I discovered via Trial and error.

Atrius (He/Him)

It'll be useful to learn THUMB code anyway, most of the code for cut scenes in Golden Sun is in it.  There's already a THUMB disassembler for the code in the map viewer actually.
[sprite=220,4,0]I'm shaking my head in general disapproval of everything[/sprite]

Charon

So wait, is it possible to load a pallate using a THUMB code? I have a pallete I want to load for the player's sprite, but I'm having difficulty (again). The game freezes whenever I load the code...

I need a tutorial on this... I think I'll search online for a list of commands or something.

Atrius (He/Him)

Here you go, it get's pretty technical though.  That's actually the page I used as a reference when writing the THUMB disassembler for the map viewer.


Palette data is stored at 0x05000000 for backgrounds, and 0x05000200 for sprites.
[sprite=220,4,0]I'm shaking my head in general disapproval of everything[/sprite]

Charon

WHEW! That document is HUGE! I think I just went braindead =P

EDIT: I got it to work, but I've got another problem - I want the colours to hold until I have another callasm command that resets the pallate to the original pallate and holds it until it is changed by another callasm command again. It won't hold and I have absolutely no clue what to do with the commands (and the link is maybe a bit to wordy for me.)

Also, is there a way to load a pallette in such a way that it runs through a spectrum? I'm thinking about changing the entire "Background" pallatte with a  pallete that cycles though a spectrum, like in GS. I found that when a 16 colour pallette is cycled (like when the Psychic-type move background is used) that it displays at 0x04000050 0x3F40 (which I think is telling BG3 to cycle through its pallette; the 0x04 being the layer and the 0x3F being the cycle command). I'm wondering is if there is a way I could apply this to all of the background pallettes at once, using the same animation.

Once I get good with this, though, I'm gonna have so much fun with this in cutscenes... I can probably even muster out 256 colours, which the Pokemon roms seem to absolutely despise =D

Atrius (He/Him)

0x04000050 is for special blend modes.  0x3F40 would tell it to draw background 0 (I think, it doesn't actually specify which layer here) over all of the others with a transparency that would be specified at 0x04000052.

As for the problem with it holding the palette, there must be some code somewhere else in the Pokemon engine that's changing it back.  I can't really help you with that, since I don't know that much about it.
[sprite=220,4,0]I'm shaking my head in general disapproval of everything[/sprite]

Charon

=P this stuff is HARD...

Hmmm... I'll see if I can find some data on it by following pointers. It could be possible to probably do some kind of lighting effect, though.

Atrius (He/Him)

Using the value at 0x04000050?  Yeah, that's how Golden Sun does the light coming in the windows in houses, around fireplaces, e.t.c.  Also the sun rays in Madra, and Champa.
[sprite=220,4,0]I'm shaking my head in general disapproval of everything[/sprite]