PDA

View Full Version : Research: "Background" Scripts


Spherical Ice
October 9th, 2012, 11:55 AM
Running Background Scripts
The following is referring to FireRed, BPRE.

Let me preface this with the fact that I know almost nothing about the game engine, how scripts are executed, and only understand the bare basics of ASM. I wonder, however, how possible it would be to execute scripts; level scripts, in particular; that run in the background without locking events such as the player.

The main purpose for this includes JPAN's engine's button checking specials running in the background which would activate a chain of events whenever you push a specific button/combination of buttons.

One theoretical problem I have thought of is lag: having a script constantly running in the background would surely cause lag, but would it be crippling? If so, are there other more direct ways of having an event occur from a button press in certain situations?

Hopefully this "brief" is enough to get some minds turning. I think this would open up loads of possibilities for minigamems, different types of gameplay, etc. I look forward to your ideas!

tajaros
October 19th, 2012, 03:16 AM
Hmm...

This is Interesting could be useful for some hacks...

Maybe we can learn how to do this if we knew how the Movement Types in A-map work and how they execute. It may also be called using callasm that will call the ASM Routine that would let us do that. Maybe some People like (Jambo51, Darthathron, shiny quagsire, etc.)

Spherical Ice
October 19th, 2012, 08:20 AM
Well, I think special 0xcb in JPAN's Hacked Engine allows you to set scripts upon button pressing but its really glitchy and I cant get it to work.

itman
October 19th, 2012, 08:53 AM
Well, I think special 0xcb in JPAN's Hacked Engine allows you to set scripts upon button pressing but its really glitchy and I cant get it to work.

You're supposed to make the script loop. Since you need to press the button at the "exact" second of execution (just the way the script was made). In his guide he shows how to make it loop so it'll get the button press. I've gotten it to work.


Speaking of the topic,
JPAN started this with his hack Engine, with having scripts activate everytime you take a step.
As he states in his guide, unfortunately, this CANNOT be used to make a follow me script, since it takes priority and has "lock" commands upon activating. Since script tiles naturally have a "lock" effect and that's what this feature was based on.

Jambo51 has made a successful follow me script (well, he says it's not completed, but it's the farthest anybody has gotten). Which means he understands running background scripts (from what I can see).
http://www.youtube.com/watch?v=y2hUoO2yxcA&list=UUrYOFkbLGlELKwwN3bfmAkw&index=24&feature=plcp

Spherical Ice
October 19th, 2012, 10:01 AM
No, you're thinking of a different special.

itman
October 19th, 2012, 11:37 AM
No, you're thinking of a different special.

I know which one you're referring to. I got it to work by making it loop. The guide that comes with it doesn't give a full example of how to use that special. -_-

Spherical Ice
October 19th, 2012, 12:26 PM
Well, wouldnt that defeat the purpose of that special? If it locks the player in place, its not really worth it haha.

Darthatron
October 19th, 2012, 08:32 PM
I know where the check for the L/R button press is. It'd be easy to call a script based on that. :) Either way, it's easy to check the buttons every frame anyway. Really easy. Calling scripts is also really easy.

tajaros
October 19th, 2012, 08:39 PM
I know where the check for the L/R button press is. It'd be easy to call a script based on that. :) Either way, it's easy to check the buttons every frame anyway. Really easy. Calling scripts is also really easy.Woah, you already know how to do this? Can you please share it to us? Please... :)

Darthatron
October 19th, 2012, 09:54 PM
Woah, you already know how to do this? Can you please share it to us? Please... :)
Sure thang.

Keypresses are handled as so:
03003118 in the RAM contains a halfword value if buttons are being held.
0300311A in the RAM contains a halfword value if buttons are being pressed this frame.
0300311C and 0300311E are then clones of this.
0300311E is the one used by the game mostly.

Bit Button
0 A (0 = Released, 1 = Pressed)
1 B
2 Select
3 Start
4 Right
5 Left
6 Up
7 Down
8 R
9 L
10-15 Not used

So, say you want to check if the button Start is being pressed this frame:
<enter code here>
ldr r2, .KeyStates
ldrh r0, [r2, #2]
mov r1, #3
and r0, r1
cmp r0, #0
bne StartIsPressed
<enter code here>

.align 2
.KeyStates:
.word 0x03003118

Calling scripts from ASM is also fairly simple:
You can run any script by calling 0x08069B48 with the script offset in the r0 register. This is how the game calls most scripts, such as level scripts and the flag setting script when you start a new game.

I hope this helps. :)

All offsets are for FireRed US (1.0) and may not work with other games or versions. Also, no code was tested. I just wrote it with the post.

tajaros
October 19th, 2012, 11:02 PM
Sure thang.

Keypresses are handled as so:
03003118 in the RAM contains a halfword value if buttons are being held.
0300311A in the RAM contains a halfword value if buttons are being pressed this frame.
0300311C and 0300311E are then clones of this.
0300311E is the one used by the game mostly.

Bit Button
0 A (0 = Released, 1 = Pressed)
1 B
2 Select
3 Start
4 Right
5 Left
6 Up
7 Down
8 R
9 L
10-15 Not used

So, say you want to check if the button Start is being pressed this frame:
<enter code here>
ldr r2, .KeyStates
ldrh r0, [r2, #2]
mov r1, #3
and r0, r1
cmp r0, #0
bne StartIsPressed
<enter code here>

.align 2
.KeyStates:
.word 0x03003118

Calling scripts from ASM is also fairly simple:
You can run any script by calling 0x08069B48 with the script offset in the r0 register. This is how the game calls most scripts, such as level scripts and the flag setting script when you start a new game.

I hope this helps. :)

All offsets are for FireRed US (1.0) and may not work with other games or versions. Also, no code was tested. I just wrote it with the post.

Cool, I'll be sure to try this out when I'm on my free time... :)