Welcome to Data Crystal's new home! Data Crystal is now part of the TCRF family (sort of).
The wiki has recently moved; please report any issues in Discord. Pardon the dust.

Pokémon Mystery Dungeon: Red Rescue Team/Script Command Parsing Code

From Data Crystal
Jump to navigation Jump to search

This is a sub-page of Pokémon Mystery Dungeon: Red Rescue Team.

So very stubbly.
This page is rather stubbly and could use some expansion.
Are you a bad enough dude to rescue this article?
Script Command Parsing Code
Game Pokémon Mystery Dungeon: Red Rescue Team
Start Address 0x0809EACC
End Address 0x0809EB16
# of Entries 532 bytes (0x0214)
Entry Length 2 bytes (0x02)
Total Length 74 bytes (0x0428)
Back to the ROM map

This code is where most commands are read from scripts and redirected to their specific methods.

Once a command is executed, the value at [r9+2c] in RAM is the pointer to the start of the script. The value at [r9+24] is probably the pointer to the currently running command. r4 also sometimes has the command in the stack.

0809EACC B5F0     push    r4-r7,r14                               
0809EACE 4657     mov     r7,r10                                  
0809EAD0 464E     mov     r6,r9                                   
0809EAD2 4645     mov     r5,r8                                   
0809EAD4 B4E0     push    r5-r7                                   
0809EAD6 B0EF     add     sp,-1BCh           ;Method Initialization
0809EAD8 4681     mov     r9,r0              ;r9 is where the RAM structure starts
0809EADA 2024     mov     r0,24h             ;
0809EADC 4448     add     r0,r9              ;
0809EADE 4682     mov     r10,r0             ;
0809EAE0 4651     mov     r1,r10             ;loop start, r10 is the RAM location for command pointers
0809EAE2 684A     ldr     r2,[r1,4h]         ;retrieves next command in ROM pointer from ram
0809EAE4 61CA     str     r2,[r1,1Ch]        ;next pointer = current pointer
0809EAE6 A902     add     r1,sp,8h           ;r1 = Location of arguments on stack
0809EAE8 1C10     mov     r0,r2              ;r0 = next command pointer
0809EAEA C838     ldmia   [r0]!,r3-r5        ;Loads first three arguments of command 4 bytes at a time.
0809EAEC C138     stmia   [r1]!,r3-r5        ;Sends them to the stack.
0809EAEE 6800     ldr     r0,[r0]            ;Loads last (pointer) argument of command into r0.
0809EAF0 6008     str     r0,[r1]            ;Puts pointer argument in stack just above the other arguments.
0809EAF2 3210     add     r2,10h             ;Increments script index (r2 points to next command in the script)
0809EAF4 4650     mov     r0,r10                                  
0809EAF6 6042     str     r2,[r0,4h]         ;Stores new script index in RAM
0809EAF8 A802     add     r0,sp,8h           ;r0 = command byte index
0809EAFA 7800     ldrb    r0,[r0]            ;Load command byte into r0 (1 byte)
0809EAFC 4651     mov     r1,r10                                  
0809EAFE 3120     add     r1,20h                                  
0809EB00 7008     strb    r0,[r1]            ;Stores command byte in RAM
0809EB02 0600     lsl     r0,r0,18h          
0809EB04 0E00     lsr     r0,r0,18h          ;Shortens the value of the command byte to 8 bit. Not strictly necessary as it already is an 8-bit value
0809EB06 3801     sub     r0,1h              
0809EB08 1C0A     mov     r2,r1              ;Leaves a pointer to the command byte in r2
0809EB0A 28F5     cmp     r0,0F5h            ;If the command byte is F6 or greater,
0809EB0C D8E8     bhi     809EAE0h           ;Then move on to the next command
0809EB0E 0080     lsl     r0,r0,2h           ;else multiply command byte by 4
0809EB10 4901     ldr     r1,=809EB1Ch       ;r1=jump table start
0809EB12 1840     add     r0,r0,r1           ;r0 = location of pointer in jump table
0809EB14 6800     ldr     r0,[r0]            ;Loads command pointer into r0.
0809EB16 4687     mov     r15,r0             ;Changes Instruction Pointer to jump to the command's method.

The Instruction Pointer jumps to a specific command's method. The pointers to these methods are located directly below the last instruction, and point to the locations/methods listed here by index.

Command  Index
------- -------
00040	809EAE0
00096	809EAE0
000CC	809EAE0
000CD	809EAE0
000CE	809EAE0
000D0	809EAE0
000D1	809EAE0
000D9	809EAE0
000F2	809EAE0
000F3	809EAE0
000F4	809EAE0
000F5	809EAE0
000F6	809EAE0
00001	809EEF4
00002	809EF40
00003	809EFA2
00004	809EFD6
00006	809F02A
00005	809F064
00007	809F06C
000DD	809F0C4
000DE	809F0C4
000DF	809F0C4
000E0	809F0C4
000E1	809F0C4
000E2	809F0C4
00008	809F0D0
00009	809F0D0
0000A	809F1FC
0000B	809F2C8
0000C	809F2D6
0000D	809F2D6
0000E	809F2D6
0000F	809F2D6
00010	809F2D6
00011	809F2D6
00012	809F2D6
00013	809F2D6
00014	809F2D6
00015	809F2D6
00016	809F42A
00017	809F432
00018	809F43A
00019	809F442
0001A	809F4FE
0001C	809F5AE
0001B	809F5BE
0001D	809F5C6
0001E	809F5C6
0001F	809F660
00020	809F6EA
00021	809F786
00022	809F830
00023	809F842
00024	809F854
00025	809F872
00026	809F884
00027	809F896
00028	809F896
00029	809F8E8
0002A	809F8F4
0002B	809F900
0002C	809F90C
00030	809F92E
00031	809F936
0002D	809F93E
0002E	809FAF8
0002F	809FB10
00032	809FB28
00033	809FB28
00034	809FB28
00035	809FB28
00036	809FB28
00037	809FB28
00038	809FB28
00039	809FBDA
0003A	809FC12
0003C	809FC2E
0003B	809FC40
0003D	809FC46
0003E	809FCA4
0003F	809FCC4
00042	809FCE8
00043	809FCF0
00044	809FD0A
00045	809FD38
00046	809FD6C
00047	809FDA0
00048	809FDA8
00049	809FDC2
0004C	809FDC2
0004A	809FDD4
0004D	809FDD4
0004B	809FDE2
0004E	809FDE2
0004F	809FE04
00050	809FE28
00051	809FE86
00052	809FEBE
00053	809FED0
00054	809FF00
00055	809FF32
00056	809FF46
00057	809FF62
00058	809FF78
00059	809FF9A
0005A	809FFBA
0005B	809FFE4
0005C	80A0010
0005D	80A0064
0005E	80A0096
0005F	80A010E
00060	80A0186
00061	80A0198
00069	80A0198
00062	80A01B8
0006A	80A01B8
00063	80A01F0
0006B	80A01F0
00064	80A0220
0006C	80A0220
00065	80A0250
0006D	80A0250
00066	80A0282
00067	80A0282
0006E	80A0282
0006F	80A0282
00071	80A02B2
00077	80A02B2
0007D	80A02B2
00083	80A02B2
00072	80A0310
00078	80A0310
0007E	80A0310
00084	80A0310
00073	80A0370
00079	80A0370
0007F	80A0370
00085	80A0370
00074	80A03F8
0007A	80A03F8
00080	80A03F8
00086	80A03F8
00075	80A0462
0007B	80A0462
00081	80A0462
00087	80A0462
00076	80A04F2
0007C	80A04F2
00082	80A04F2
00088	80A04F2
00068	80A0560
00070	80A0560
00089	80A057C
0008A	80A05A4
0008B	80A05F0
0008C	80A060E
0008D	80A065C
0008E	80A068A
0008F	80A068A
00090	80A068A
00093	80A07C4
00094	80A07C4
00095	80A07C4
00091	80A07CA
00092	80A07DC
00097	80A080C
00098	80A081E
00099	80A086A
0009A	80A08BE
0009B	80A08CA
0009C	80A091E
0009D	80A0986
0009E	80A0998
0009F	80A09EA
000A0	80A0A52
000A1	80A0A64
000A2	80A0AB6
000A3	80A0B1E
000A4	80A0B30
000A5	80A0B42
000A6	80A0B54
000A7	80A0B6C
000A8	80A0B88
000A9	80A0BA2
000AA	80A0BB4
000AB	80A0BDA
000AC	80A0BF6
000AD	80A0C08
000AE	80A0C20
000AF	80A0C38
000B0	80A0C50
000B1	80A0C68
000B2	80A0C80
000B3	80A0C90
000B4	80A0CA2
000B5	80A0CC8
000B6	80A0CF2
000B7	80A0D16
000B8	80A0D40
000B9	80A0D6A
000BA	80A0D7A
000BB	80A0D94
000BC	80A0DAE
000BD	80A0DD6
000BF	80A0DE2
000BE	80A0E08
00041	80A0E3A
000C0	80A0E56
000C1	80A0E56
000C2	80A0E56
000C3	80A0E56
000C4	80A0E56
000C5	80A0E56
000C6	80A0E56
000C7	80A0E56
000C8	80A0E56
000C9	80A0E56
000CA	80A0E56
000CB	80A0E56
000CF	80A10A0
000D2	80A10F8
000D3	80A10F8
000D4	80A10F8
000D5	80A10F8
000D6	80A10F8
000D7	80A10F8
000D8	80A10F8
000DA	80A129E
000DB	80A12A8
000DC	80A12B4
000E3	80A12D0
000E4	80A12E6
000E5	80A12F4
000E6	80A1318
000E7	80A1324
000E8	80A1338
000E9	80A1344
000EA	80A1368
000EB	80A1374
000EC	80A13CA
000ED	80A13F8
000EE	80A1404
000EF	80A140C
000F0	80A1428
000F1	80A142C

The E7 command and probably some others call a function at 0x080A2428 that iterates through commands one by one starting at the start of the script, and looks for the given F4 label command.