anonyboy
Pokemon Aerial Emerald Creator&Pokemon Hybrid Co-C
- 286
- Posts
- 11
- Years
- Israel
- Seen Mar 10, 2025
Could you make it work with prime-dialga's RTC? If you can would you please post the routines?Berry System in FireRed!
First of all, before you implement my system you need to insert:
JPAN's save block hack: https://www.pokecommunity.com/posts/6993092/
ShinyQuagsire's berry bag hack: https://www.pokecommunity.com/threads/295749
My code assumes that you've got all of this already implemented.
How to insert:
There's a lot of work to do before you can get this running. Trust me it was more work to create.
Compile each of the following routines and insert them into free space (KEEP TRACK OF WHERE YOU INSERT):
GetTreeData:
Spoiler:
Code:.text .align 2 .thumb .thumb_func main: push {r0-r2, lr} ldr r0, =(0x20370D0)@get tree data ldrh r0, [r0] ldr r1, .SAVEBLOCK mov r2, #0x6 mul r0, r0, r6 add r0, r0, r1 ldr r1, =(0x20370C2) @put values in vars ldrb r2, [r0] strb r2, [r1] @current stage add r0, r0, #0x1 add r1, r1, #0x2 ldrh r2, [r0] strh r2, [r1] @time planted add r0, r0, #0x2 add r1, r1, #0x2 ldrb r2, [r0] strb r2, [r1] @was watered add r0, r0, #0x1 add r1, r1, #0x2 ldrb r2, [r0] strb r2, [r1]@times watered add r0, r0, #0x1 add r1, r1, #0x2 ldrb r2, [r0] strb r2, [r1]@PlantID updateStage: @check time passed and update ldr r1, = (0x300500C) ldrh r2, [r1, #0xE] @hours mov r3, #0x3C mul r2, r2, r3 ldrb r3, [r1, #0x10]@minutes add r2, r2, r3 @current time in minutes ldr r3, =(0x20370C4) ldrh r3, [r3] sub r2, r2, r3 mov r3, #0x0 mov r1, #0x14 @CHANGE THIS TO CHANGE TIME BETWEEN PHASES loop: cmp r1, r2 blo setWater lsl r1, r1, #0x1 add r3, r3, #0x1 b loop setWater: ldr r1, =(0x20370C2) ldrh r1, [r1] cmp r3, r2 ble end ldr r2, =(0x20370C2) strb r3, [r2] ldr r2, =(0x20370C6) mov r3, #0x0 strb r3, [r2] pop {r0-r2, pc} .align 2 .SAVEBLOCK: .word 0x203C000
getYeild
Spoiler:
Code:.text .align 2 .thumb .thumb_func main: push {r0-r4, lr} ldr r0, =(0x202370B8) @max ldr r1, =(0x202370BA) @min ldrb r1, [r1] mov r2, r0 sub r2, r2, r1 @max -min bl generateRand mov r4, r3 add r4, r4, r1 @rand between min and max ldr r3, =(0x202370C8) ldrb r3, [r3] @times watered sub r3, r3, #0x1 mul r2, r2, r3 @apply DPPT berry yield formula add r2, r2, r4 lsr r2, r2, #0x2 add r2, r2, r1 ldr r1, =(0x202370D0) @store result in 0x800D strb r2, [r0] pop {r0-r4, pc} generateRand: push {r0-r2} ldr r3, =(0x8044EC8 +1) bl linker lsl r0, r0, #0x10 lsr r0, r0, #0x10 pop {r2} mov r1, r2 push {r2} ldr r3, =(0x81E4684 +1) bl linker ldrb r3, [r0] pop {r0-r2} bx lr linker: bx r3 .align 2
setTime:
Spoiler:
Code:.text .align 2 .thumb .thumb_func main: push {r0-r3, lr} ldr r1, =(0x300500C) ldrh r2, [r1, #0xE] mov r3, #0x3C mul r2, r2, r3 ldrb r3, [r1, #0x10] add r2, r2, r3 ldr r3, =(0x20370C4) strh r2, [r3] pop {r0-r3, pc} .align 2
setTreeData:
Spoiler:
Code:.text .align 2 .thumb .thumb_func main: push {r0-r2, lr} ldr r0, =(0x20370BC)@get tree data ldrh r0, [r0] ldr r1, .SAVEBLOCK mov r2, #0x6 mul r0, r0, r6 add r0, r0, r1 ldr r1, =(0x20370C2) @put values in vars ldrb r2, [r1] strb r2, [r0] @current stage add r0, r0, #0x1 add r1, r1, #0x2 ldrh r2, [r1] strh r2, [r0] @time planted add r0, r0, #0x2 add r1, r1, #0x2 ldrb r2, [r1] strb r2, [r0] @was watered add r0, r0, #0x1 add r1, r1, #0x2 ldrb r2, [r1] strb r2, [r0]@times watered add r0, r0, #0x1 add r1, r1, #0x2 ldrb r2, [r1] strb r2, [r0]@PlantID pop {r0-r2, pc} .align 2 .SAVEBLOCK: .word 0x203C000
Now, once you've compiled those routines into free space you will need to insert their pointers (not in reverse hex) into this script. Remember to add 1 to the pointer.
You'll notice that I've added comments, which in PKSV, are signified by the apostrophe. I.e
Code:'This is a comment
I've made sure to add comments everywhere there is a callasm command to one of my routines. You'll also notice that the names I call these routines are identical to the names I gave the spoilers. You need to match the call to the pointer to the name of the routine!
The PKSV script (sorry no XSE version, convert it yourself :P):
Spoiler:
Code:#dyn 0x740000 #org @start lock copyvar 0x8002 0x800D callasm 0xOffset +1'set tree data callasm 0xOffset + 1 'get tree data compare 0x8005 0x0 if == jump @nonePlanted compare 0x8005 0x1 if == jump @fresh compare 0x8005 0x2 if == jump @sprouted compare 0x8005 0x3 if == jump @growing compare 0x8005 0x4 if == jump @blooming callasm 0xOffset +1 'get yeild storevar 0x0 0x800D storevar 0x1 0x8009 additem 0x8009 0x800D msgbox @recieved callstd MSG_NORMAL setvar 0x8005 0x0 setvar 0x8006 0x0 setvar 0x8007 0x0 setvar 0x8008 0x0 setvar 0x8009 0x0 callasm 0xOffset +1 'set tree data msgbox @returned callstd MSG_NORMAL release end #org @nonePlanted msgbox @none callstd MSG_YESNO compare LASTRESULT 0x0 if == jump @end fadescreen 0x1 setvar 0x8000 0x7E setvar 0x800E 0x0 callasm 0x0A1881 pauseevent 0x0 setvar 0x8000 0x0 compare 0x800E 0x0 if == jump @end copyvar 0x8009 0x800E storeitem 0x0 0x8009 msgbox @addedBerry callstd MSG_NORMAL setvar 0x8005 0x1 setvar 0x8007 0x0 setvar 0x8008 0x0 callasm 0xOffset +1' set time callasm 0xOffset +1' set tree data removeitem 0x8009 0x1 release end #org @fresh storeitem 0x0 0x8009 msgbox @newplant callstd MSG_NORMAL compare 0x8007 0x0 if <= jump @water msgbox @wateredAlready callstd MSG_NORMAL release end #org @sprouted storeitem 0x0 0x8009 msgbox @sprouting callstd MSG_normal compare 0x8007 0x0 if <= jump @water msgbox @wateredAlready callstd MSG_NORMAL release end #org @growing storeitem 0x0 0x8009 msgbox @tall callstd MSG_NORMAL compare 0x8007 0x0 if <= jump @water msgbox @wateredAlready callstd MSG_NORMAL release end #org @blooming storeitem 0x0 0x8009 msgbox @bloom callstd MSG_NORMAL compare 0x8007 0x0 if <= jump @water msgbox @wateredAlready callstd MSG_NORMAL release end #org @water checkitem 0x1 0x1 'checks you have one masterball. Change 0x1 to your watering item if != jump @end msgbox @wantWater callstd MSG_YESNO compare LASTRESULT 0x0 if == jump @end msgbox @finishedWatering callstd MSG_NORMAL addvar 0x8007 0x1 addvar 0x8008 0x1 copyvar 0x800D 0x8005 callasm 0x800001 'set tree data release end #org @end release end #org @addedBerry = You planted a \v\h02 here. #org @returned = The soil returned to it's soft and\nloamy state. #org @newplant = A \v\h02 was planted here. #org @none = The soil is soft here[.]\nPlant a berry? #org @bloom = The \v\h02 plant is in bloom! #org @tall = The \v\h02 plant\nis growing bigger. #org @sprouting = The \v\h02 has sprouted. #org @wantWater = The plant can use some water[.]\nWould you like to water it? #org @wateredAlready = It's been watered already. #org @recieved = \v\h01 found \v\h02 \v\h03!
Usage:
After you've compiled the script, write down the offset of it as well. You will need to remember it.
Here is how you'll be using the script:
Code:#dyn 0x740000 #org @start setvar 0x8000 0x[max berry yield] setvar 0x8001 0x[min berry yield] setvar LASTRESULT 0x[Tree ID] jump 0x8[Offset where you compiled the above script]
Every tree should have a unique Tree ID. So if you want two trees, one can be 0x0, and the other can be 0x1. Set the tree ID to lastresult and then jump the script that handles the complicated stuff.
System Mechanics:
The beauty of the system is that it uses only temporary variables and derives their values from the RAM. Meaning you can go ahead and use those variables for anything, without having to save them for just the tree. Incase you are interested here's how the data is stored and the variable's significance:
Code:General variables: var 0x8000: Max berry yield for tree var 0x8001: Minimum berry yield for tree var 0x8005: Current stage var 0x8006: Time planted var 0x8007: Was watered var 0x8008: Times watered var 0x8009: ID of berry RAM Data storage: [Current Stage: 1 byte] [Time planted: 2 bytes] [Watered: 1 byte] [times watered: 1 byte] [ID of plant: 1 bytes]
System Algorithm:
The system works identical to that of DPPT. The only complication is that FR does not have an RTC. So I used play time to obtain as clock. The current system has 5 phases, each phase lasts 20 minutes playtime. You can Increase or decrease this time by going to the "getTreeData" routine, finding my comment in all caps and changing the constant 0x14 (20) to some other hex number you'd want.
Link to DPPT berry system: https://bulbapedia.bulbagarden.net/wiki/Berry#Formula