@ assembling directives for assembler thing
.text
.align 2 @ Code offset must be multiple of 2
.thumb @ we are writing THUMB code
.thumb_func
@ we're using RAM from 02030000 - 02030030
@ if we apply a hack that uses that RAM, we
@ must edit this ASM and re-insert it into
@ the game.
@ start execution, with a defined label
main:
@ backup registers
Push{r0-r7,lr}
@ script code
@ overwrite the personality value
@ based on the values of 0x8001
@ and 0x8002.
ldr r0, .VAR_8001
ldr r1, .DECRYPTED_POKEMON
str r0, [r1, #0x0]
@ find new arrangement
ldr r0, .DECRYPTED_POKEMON
@ store least significant byte of personality value
ldrb r0, [r0, #0x0]
mov r1, #24
@ division, using a BIOS function
swi #0x06
@ transfer result of r0 % r1 from r1 to r0
mov r0, r1
@ copy G data to an available place in RAM
ldr r1, .PTR_SUBSTRUCT_G
mov r2, #0x0C
ldr r3, .Cobb_storage
bl CopyDataChunk
ldr r1, .PTR_SUBSTRUCT_A
mov r2, #0x0C
ldr r3, .Cobb_storage
add r3, #0x0C
bl CopyDataChunk
ldr r1, .PTR_SUBSTRUCT_E
mov r2, #0x0C
ldr r3, .Cobb_storage
add r3, #0x18
bl CopyDataChunk
ldr r1, .PTR_SUBSTRUCT_M
mov r2, #0x0C
ldr r3, .Cobb_storage
add r3, #0x24
bl CopyDataChunk
b DoWriting
CopyDataChunk:
@ IN r1 pointer: source data chunk (as number value)
@ IN r2 length of source
@ IN r3 pointer: target data chunk (as number value)
@ r4 Throwaway variable, will be overwritten
ldr r4, [r1, #0x0]
str r4, [r3, #0x0]
add r1, #0x4
add r3, #0x4
sub r2, #0x4
cmp r2, #0x0
bne CopyDataChunk
pop {pc}
WriteSlot:
@ REQ CopyDataChunk
@ IN r1 data substructure slot to write to (1-4)
@ IN r2 data substructure (1-4 = G,A,E,M)
@ r3 Throwaway (parameter to subfunction)
@ r4 Throwaway (here and subfunction)
@ OUT r5 computed target address
mov r4, #0xC
mul r1, r4
sub r1, r4
mul r2, r4
sub r2, r4
mov r4, r1
ldr r3, .SUBSTRUCT_1
add r3, r1
mov r5, r3
ldr r1, .Cobb_storage
add r1, r2
mov r2, #0xC
bl CopyDataChunk
pop {pc}
WriteG:
@ REQ WriteSlot
@ > CopyDataChunk
@ IN r1 data substructure slot to write to (1-4)
@ r2 Throwaway (parameter to subfunction)
@ r3 Throwaway (parameter to subfunction)
@ r4 Throwaway (here and subfunction)
@ r5 address to write to one of JPAN's pointers
mov r2, #0x1
bl WriteSlot
ldr r4, .PTR_SUBSTRUCT_G
str r4, [r5, #0x0]
pop {pc}
WriteA:
mov r2, #0x2
bl WriteSlot
ldr r4, .PTR_SUBSTRUCT_A
str r4, [r5, #0x0]
pop {pc}
WriteE:
mov r2, #0x3
bl WriteSlot
ldr r4, .PTR_SUBSTRUCT_E
str r4, [r5, #0x0]
pop {pc}
WriteM:
mov r2, #0x4
bl WriteSlot
ldr r4, .PTR_SUBSTRUCT_M
str r4, [r5, #0x0]
pop {pc}
DoWriting:
@ BRANCH CALLS GO HERE
@ IN r0 New personality value modulo 24
@ r1 Throwaway (subfunction)
@ r2 Throwaway (subfunction)
@ r3 Throwaway (subfunction)
@ r4 Throwaway (subfunction)
@ r5 Throwaway (subfunction)
cmp r0, #0x00
beq Write_GAEM
cmp r0, #0x01
beq Write_GAME
cmp r0, #0x02
beq Write_GEAM
cmp r0, #0x03
beq Write_GEMA
cmp r0, #0x04
beq Write_GMAE
cmp r0, #0x05
beq Write_GMEA
cmp r0, #0x06
cmp r0, #0x07
beq Write_AGEM
cmp r0, #0x08
beq Write_AGME
cmp r0, #0x09
beq Write_AEGM
cmp r0, #0x0A
beq Write_AEMG
cmp r0, #0x0B
beq Write_AMGE
cmp r0, #0x0C
beq Write_AMEG
cmp r0, #0x0D
beq Write_EGAM
cmp r0, #0x0E
beq Write_EGMA
cmp r0, #0x0F
beq Write_EAGM
cmp r0, #0x10
beq Write_EAMG
cmp r0, #0x11
beq Write_EMGA
cmp r0, #0x12
beq Write_EMAG
cmp r0, #0x13
beq Write_MGAE
cmp r0, #0x14
beq Write_MGEA
cmp r0, #0x15
beq Write_MAGE
cmp r0, #0x16
beq Write_MAEG
cmp r0, #0x17
beq Write_MEGA
cmp r0, #0x18
beq Write_MEAG
b End
Write_GAEM:
@ G
mov r1, #0x1
bl WriteG
@ A
mov r1, #0x2
bl WriteA
@ E
mov r1, #0x3
bl WriteE
@ M
mov r1, #0x4
bl WriteM
b End
Write_GAME:
mov r1, #0x1
bl WriteG
mov r1, #0x2
bl WriteA
mov r1, #0x3
bl WriteM
mov r1, #0x4
bl WriteE
b End
Write_GEAM:
mov r1, #0x1
bl WriteG
mov r1, #0x2
bl WriteE
mov r1, #0x3
bl WriteA
mov r1, #0x4
bl WriteM
b End
Write_GEMA:
mov r1, #0x1
bl WriteG
mov r1, #0x2
bl WriteE
mov r1, #0x3
bl WriteM
mov r1, #0x4
bl WriteA
b End
Write_GMAE:
mov r1, #0x1
bl WriteG
mov r1, #0x2
bl WriteM
mov r1, #0x3
bl WriteA
mov r1, #0x4
bl WriteE
b End
Write_GMEA:
mov r1, #0x1
bl WriteG
mov r1, #0x2
bl WriteM
mov r1, #0x3
bl WriteE
mov r1, #0x4
bl WriteA
b End
Write_AGEM:
mov r1, #0x1
bl WriteA
mov r1, #0x2
bl WriteG
mov r1, #0x3
bl WriteE
mov r1, #0x4
bl WriteM
b End
Write_AGME:
mov r1, #0x1
bl WriteA
mov r1, #0x2
bl WriteG
mov r1, #0x3
bl WriteM
mov r1, #0x4
bl WriteE
b End
Write_AEGM:
mov r1, #0x1
bl WriteA
mov r1, #0x2
bl WriteE
mov r1, #0x3
bl WriteG
mov r1, #0x4
bl WriteM
b End
Write_AEMG:
mov r1, #0x1
bl WriteA
mov r1, #0x2
bl WriteE
mov r1, #0x3
bl WriteM
mov r1, #0x4
bl WriteG
b End
Write_AMGE:
mov r1, #0x1
bl WriteA
mov r1, #0x2
bl WriteM
mov r1, #0x3
bl WriteG
mov r1, #0x4
bl WriteE
b End
Write_AMEG:
mov r1, #0x1
bl WriteA
mov r1, #0x2
bl WriteM
mov r1, #0x3
bl WriteE
mov r1, #0x4
bl WriteG
b End
Write_EGAM:
mov r1, #0x1
bl WriteE
mov r1, #0x2
bl WriteG
mov r1, #0x3
bl WriteA
mov r1, #0x4
bl WriteM
b End
Write_EGMA:
mov r1, #0x1
bl WriteE
mov r1, #0x2
bl WriteG
mov r1, #0x3
bl WriteM
mov r1, #0x4
bl WriteA
b End
Write_EAGM:
mov r1, #0x1
bl WriteE
mov r1, #0x2
bl WriteA
mov r1, #0x3
bl WriteG
mov r1, #0x4
bl WriteM
b End
Write_EAMG:
mov r1, #0x1
bl WriteE
mov r1, #0x2
bl WriteA
mov r1, #0x3
bl WriteM
mov r1, #0x4
bl WriteG
b End
Write_EMGA:
mov r1, #0x1
bl WriteE
mov r1, #0x2
bl WriteM
mov r1, #0x3
bl WriteG
mov r1, #0x4
bl WriteA
b End
Write_EMAG:
mov r1, #0x1
bl WriteE
mov r1, #0x2
bl WriteM
mov r1, #0x3
bl WriteA
mov r1, #0x4
bl WriteG
b End
Write_MGAE:
mov r1, #0x1
bl WriteM
mov r1, #0x2
bl WriteG
mov r1, #0x3
bl WriteA
mov r1, #0x4
bl WriteE
b End
Write_MGEA:
mov r1, #0x1
bl WriteM
mov r1, #0x2
bl WriteG
mov r1, #0x3
bl WriteE
mov r1, #0x4
bl WriteA
b End
Write_MAGE:
mov r1, #0x1
bl WriteM
mov r1, #0x2
bl WriteA
mov r1, #0x3
bl WriteG
mov r1, #0x4
bl WriteE
b End
Write_MAEG:
mov r1, #0x1
bl WriteM
mov r1, #0x2
bl WriteA
mov r1, #0x3
bl WriteE
mov r1, #0x4
bl WriteG
b End
Write_MEGA:
mov r1, #0x1
bl WriteM
mov r1, #0x2
bl WriteE
mov r1, #0x3
bl WriteG
mov r1, #0x4
bl WriteA
b End
Write_MEAG:
mov r1, #0x1
bl WriteM
mov r1, #0x2
bl WriteE
mov r1, #0x3
bl WriteA
mov r1, #0x4
bl WriteG
b End
End:
@ restore registers and return
Pop{r0-r7,pc}
.align 2
.JPAN_storage:
.word 0x0203f400
.Cobb_storage:
.word 0x02030000
.DECRYPTED_POKEMON:
.word 0x0203F400
.PTR_SUBSTRUCT_G:
.word 0x0203F464
.PTR_SUBSTRUCT_A:
.word 0x0203F468
.PTR_SUBSTRUCT_E:
.word 0x0203F46C
.PTR_SUBSTRUCT_M:
.word 0x0203F470
.SUBSTRUCT_1:
.word 0x0203F432
.SUBSTRUCT_2:
.word 0x0203F43E
.SUBSTRUCT_3:
.word 0x0203F44A
.SUBSTRUCT_4:
.word 0x0203F458
.VAR_8001:
.word 0x020270B6 + (0x8001 * 2)
.VAR_8002:
.word 0x020270B6 + (0x8002 * 2)
.LASTRESULT:
.word 0x020270B6 + (0x800D * 2)