Thread: Research: "Background" Scripts
View Single Post
Old October 19th, 2012 (11:02 PM).
tajaros's Avatar
tajaros tajaros is offline
Hi I'm dawg
    Join Date: Apr 2012
    Location: Philippines
    Age: 18
    Gender: Male
    Nature: Timid
    Posts: 857
    Originally Posted by Darthatron View Post
    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:
    ldr r2, .KeyStates
    ldrh r0, [r2, #2]
    mov r1, #3
    and r0, r1
    cmp r0, #0
    bne StartIsPressed
    .align 2
    	.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...
    Reply With Quote