mirror of https://github.com/pret/pokeemerald.git
finish save.c
This commit is contained in:
parent
3c8091393c
commit
7b72c83762
164
asm/save.s
164
asm/save.s
|
@ -1,164 +0,0 @@
|
|||
.include "asm/macros.inc"
|
||||
.include "constants/constants.inc"
|
||||
|
||||
.syntax unified
|
||||
|
||||
.text
|
||||
|
||||
|
||||
thumb_func_start sub_8153688
|
||||
sub_8153688: @ 8153688
|
||||
push {r4,lr}
|
||||
lsls r0, 24
|
||||
lsrs r2, r0, 24
|
||||
lsls r0, r2, 2
|
||||
adds r0, r2
|
||||
lsls r0, 3
|
||||
ldr r1, =gTasks + 0x8
|
||||
adds r4, r0, r1
|
||||
movs r1, 0
|
||||
ldrsh r0, [r4, r1]
|
||||
cmp r0, 0xB
|
||||
bls _081536A2
|
||||
b _081537C2
|
||||
_081536A2:
|
||||
lsls r0, 2
|
||||
ldr r1, =_081536B4
|
||||
adds r0, r1
|
||||
ldr r0, [r0]
|
||||
mov pc, r0
|
||||
.pool
|
||||
.align 2, 0
|
||||
_081536B4:
|
||||
.4byte _081536E4
|
||||
.4byte _081536F4
|
||||
.4byte _081536FE
|
||||
.4byte _0815371A
|
||||
.4byte _0815372C
|
||||
.4byte _08153742
|
||||
.4byte _08153758
|
||||
.4byte _08153762
|
||||
.4byte _08153778
|
||||
.4byte _0815378C
|
||||
.4byte _08153796
|
||||
.4byte _081537A8
|
||||
_081536E4:
|
||||
ldr r0, =gSoftResetDisabled
|
||||
movs r1, 0x1
|
||||
strb r1, [r0]
|
||||
movs r0, 0x1
|
||||
strh r0, [r4]
|
||||
b _081537C2
|
||||
.pool
|
||||
_081536F4:
|
||||
bl sub_800ADF8
|
||||
movs r0, 0x2
|
||||
strh r0, [r4]
|
||||
b _081537C2
|
||||
_081536FE:
|
||||
bl sub_800A520
|
||||
lsls r0, 24
|
||||
cmp r0, 0
|
||||
beq _081537C2
|
||||
movs r1, 0x4
|
||||
ldrsh r0, [r4, r1]
|
||||
cmp r0, 0
|
||||
bne _08153714
|
||||
bl save_serialize_map
|
||||
_08153714:
|
||||
movs r0, 0x3
|
||||
strh r0, [r4]
|
||||
b _081537C2
|
||||
_0815371A:
|
||||
movs r1, 0x4
|
||||
ldrsh r0, [r4, r1]
|
||||
cmp r0, 0
|
||||
bne _08153726
|
||||
bl sub_8076D5C
|
||||
_08153726:
|
||||
bl sub_8153380
|
||||
b _08153752
|
||||
_0815372C:
|
||||
ldrh r0, [r4, 0x2]
|
||||
adds r0, 0x1
|
||||
strh r0, [r4, 0x2]
|
||||
lsls r0, 16
|
||||
asrs r1, r0, 16
|
||||
cmp r1, 0x5
|
||||
bne _081537C2
|
||||
movs r0, 0
|
||||
strh r0, [r4, 0x2]
|
||||
strh r1, [r4]
|
||||
b _081537C2
|
||||
_08153742:
|
||||
bl sub_81533AC
|
||||
lsls r0, 24
|
||||
cmp r0, 0
|
||||
beq _08153752
|
||||
movs r0, 0x6
|
||||
strh r0, [r4]
|
||||
b _081537C2
|
||||
_08153752:
|
||||
movs r0, 0x4
|
||||
strh r0, [r4]
|
||||
b _081537C2
|
||||
_08153758:
|
||||
bl sub_81533E0
|
||||
movs r0, 0x7
|
||||
strh r0, [r4]
|
||||
b _081537C2
|
||||
_08153762:
|
||||
movs r1, 0x4
|
||||
ldrsh r0, [r4, r1]
|
||||
cmp r0, 0
|
||||
bne _0815376E
|
||||
bl sav2_gender2_inplace_and_xFE
|
||||
_0815376E:
|
||||
bl sub_800ADF8
|
||||
movs r0, 0x8
|
||||
strh r0, [r4]
|
||||
b _081537C2
|
||||
_08153778:
|
||||
bl sub_800A520
|
||||
lsls r0, 24
|
||||
cmp r0, 0
|
||||
beq _081537C2
|
||||
bl sub_8153408
|
||||
movs r0, 0x9
|
||||
strh r0, [r4]
|
||||
b _081537C2
|
||||
_0815378C:
|
||||
bl sub_800ADF8
|
||||
movs r0, 0xA
|
||||
strh r0, [r4]
|
||||
b _081537C2
|
||||
_08153796:
|
||||
bl sub_800A520
|
||||
lsls r0, 24
|
||||
cmp r0, 0
|
||||
beq _081537C2
|
||||
ldrh r0, [r4]
|
||||
adds r0, 0x1
|
||||
strh r0, [r4]
|
||||
b _081537C2
|
||||
_081537A8:
|
||||
ldrh r0, [r4, 0x2]
|
||||
adds r0, 0x1
|
||||
strh r0, [r4, 0x2]
|
||||
lsls r0, 16
|
||||
asrs r0, 16
|
||||
cmp r0, 0x5
|
||||
ble _081537C2
|
||||
ldr r1, =gSoftResetDisabled
|
||||
movs r0, 0
|
||||
strb r0, [r1]
|
||||
adds r0, r2, 0
|
||||
bl DestroyTask
|
||||
_081537C2:
|
||||
pop {r4}
|
||||
pop {r0}
|
||||
bx r0
|
||||
.pool
|
||||
thumb_func_end sub_8153688
|
||||
|
||||
.align 2, 0 @ Don't pad with nop.
|
|
@ -200,7 +200,6 @@ SECTIONS {
|
|||
asm/roulette_util.o(.text);
|
||||
asm/cable_car_util.o(.text);
|
||||
src/save.o(.text);
|
||||
asm/save.o(.text);
|
||||
asm/mystery_event_script.o(.text);
|
||||
asm/field_effect_helpers.o(.text);
|
||||
asm/contest_ai.o(.text);
|
||||
|
|
162
src/save.c
162
src/save.c
|
@ -2,12 +2,15 @@
|
|||
#include "gba/flash_internal.h"
|
||||
#include "save.h"
|
||||
#include "game_stat.h"
|
||||
#include "task.h"
|
||||
|
||||
extern struct SaveSectionOffsets gSaveSectionOffsets[0xE];
|
||||
extern struct SaveSectionLocation gRamSaveSectionLocations[0xE];
|
||||
extern u8 gDecompressionBuffer[];
|
||||
extern u32 gFlashMemoryPresent;
|
||||
extern u16 gUnknown_03006294;
|
||||
extern bool8 gSoftResetDisabled;
|
||||
|
||||
extern const struct SaveSectionOffsets gSaveSectionOffsets[0xE];
|
||||
|
||||
extern void DoSaveFailedScreen(u8); // save_failed_screen
|
||||
extern void LoadSerializedGame(void); // load_save
|
||||
|
@ -576,84 +579,27 @@ u16 CalculateChecksum(void *data, u16 size)
|
|||
return ((checksum >> 16) + checksum);
|
||||
}
|
||||
|
||||
#ifdef NONMATCHING
|
||||
// the initial allocation of the pointer and toAdd variable doesnt match up with the original function. however, forcing it is impossible since gRamSaveSectionLocations is loaded first.
|
||||
void UpdateSaveAddresses(void)
|
||||
{
|
||||
int i = 0;
|
||||
gRamSaveSectionLocations[i].data = gSaveBlock2Ptr + gSaveSectionOffsets[0].toAdd;
|
||||
gRamSaveSectionLocations[i].size = gSaveSectionOffsets[0].size;
|
||||
|
||||
for(i = 1; i < 5; i++)
|
||||
gRamSaveSectionLocations[i].data = (void*)(gSaveBlock2Ptr) + gSaveSectionOffsets[i].toAdd;
|
||||
gRamSaveSectionLocations[i].size = gSaveSectionOffsets[i].size;
|
||||
|
||||
for (i = 1; i < 5; i++)
|
||||
{
|
||||
gRamSaveSectionLocations[i].data = gSaveBlock1Ptr + gSaveSectionOffsets[i].toAdd;
|
||||
gRamSaveSectionLocations[i].data = (void*)(gSaveBlock1Ptr) + gSaveSectionOffsets[i].toAdd;
|
||||
gRamSaveSectionLocations[i].size = gSaveSectionOffsets[i].size;
|
||||
}
|
||||
|
||||
for(i = 5; i < 14; i++)
|
||||
for (i = 5; i < 14; i++)
|
||||
{
|
||||
gRamSaveSectionLocations[i].data = gPokemonStoragePtr + gSaveSectionOffsets[i].toAdd;
|
||||
gRamSaveSectionLocations[i].data = (void*)(gPokemonStoragePtr) + gSaveSectionOffsets[i].toAdd;
|
||||
gRamSaveSectionLocations[i].size = gSaveSectionOffsets[i].size;
|
||||
|
||||
i++;i--; // needed to match
|
||||
}
|
||||
}
|
||||
#else
|
||||
__attribute__((naked))
|
||||
void UpdateSaveAddresses(void)
|
||||
{
|
||||
asm(".syntax unified\n\
|
||||
push {r4,r5,lr}\n\
|
||||
ldr r3, =gRamSaveSectionLocations\n\
|
||||
ldr r0, =gSaveBlock2Ptr\n\
|
||||
ldr r2, =gSaveSectionOffsets\n\
|
||||
ldrh r1, [r2]\n\
|
||||
ldr r0, [r0]\n\
|
||||
adds r0, r1\n\
|
||||
str r0, [r3]\n\
|
||||
ldrh r0, [r2, 0x2]\n\
|
||||
strh r0, [r3, 0x4]\n\
|
||||
ldr r5, =gSaveBlock1Ptr\n\
|
||||
adds r3, 0x8\n\
|
||||
adds r2, 0x4\n\
|
||||
movs r4, 0x3\n\
|
||||
_081531AC:\n\
|
||||
ldrh r0, [r2]\n\
|
||||
ldr r1, [r5]\n\
|
||||
adds r1, r0\n\
|
||||
str r1, [r3]\n\
|
||||
ldrh r0, [r2, 0x2]\n\
|
||||
strh r0, [r3, 0x4]\n\
|
||||
adds r3, 0x8\n\
|
||||
adds r2, 0x4\n\
|
||||
subs r4, 0x1\n\
|
||||
cmp r4, 0\n\
|
||||
bge _081531AC\n\
|
||||
movs r4, 0x5\n\
|
||||
ldr r1, =gRamSaveSectionLocations\n\
|
||||
ldr r5, =gPokemonStoragePtr\n\
|
||||
ldr r0, =gSaveSectionOffsets\n\
|
||||
adds r3, r1, 0\n\
|
||||
adds r3, 0x28\n\
|
||||
adds r2, r0, 0\n\
|
||||
adds r2, 0x14\n\
|
||||
_081531D2:\n\
|
||||
ldrh r0, [r2]\n\
|
||||
ldr r1, [r5]\n\
|
||||
adds r1, r0\n\
|
||||
str r1, [r3]\n\
|
||||
ldrh r0, [r2, 0x2]\n\
|
||||
strh r0, [r3, 0x4]\n\
|
||||
adds r3, 0x8\n\
|
||||
adds r2, 0x4\n\
|
||||
adds r4, 0x1\n\
|
||||
cmp r4, 0xD\n\
|
||||
ble _081531D2\n\
|
||||
pop {r4,r5}\n\
|
||||
pop {r0}\n\
|
||||
bx r0\n\
|
||||
.pool\n\
|
||||
.syntax divided");
|
||||
}
|
||||
#endif
|
||||
|
||||
extern u32 GetGameStat(u8 index); // rom4
|
||||
extern void IncrementGameStat(u8 index); // rom4
|
||||
|
@ -894,3 +840,85 @@ u32 sub_8153634(u8 sector, u8* src)
|
|||
return 0xFF;
|
||||
return 1;
|
||||
}
|
||||
|
||||
extern void save_serialize_map(void);
|
||||
extern void sub_8076D5C(void);
|
||||
extern void sav2_gender2_inplace_and_xFE(void);
|
||||
extern void sub_800ADF8(void);
|
||||
extern bool8 sub_800A520(void);
|
||||
|
||||
void sub_8153688(u8 taskId)
|
||||
{
|
||||
s16* taskData = gTasks[taskId].data;
|
||||
|
||||
switch (taskData[0])
|
||||
{
|
||||
case 0:
|
||||
gSoftResetDisabled = TRUE;
|
||||
taskData[0] = 1;
|
||||
break;
|
||||
case 1:
|
||||
sub_800ADF8();
|
||||
taskData[0] = 2;
|
||||
break;
|
||||
case 2:
|
||||
if (sub_800A520())
|
||||
{
|
||||
if (taskData[2] == 0)
|
||||
save_serialize_map();
|
||||
taskData[0] = 3;
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
if (taskData[2] == 0)
|
||||
sub_8076D5C();
|
||||
sub_8153380();
|
||||
taskData[0] = 4;
|
||||
break;
|
||||
case 4:
|
||||
if (++taskData[1] == 5)
|
||||
{
|
||||
taskData[1] = 0;
|
||||
taskData[0] = 5;
|
||||
}
|
||||
break;
|
||||
case 5:
|
||||
if (sub_81533AC())
|
||||
taskData[0] = 6;
|
||||
else
|
||||
taskData[0] = 4;
|
||||
break;
|
||||
case 6:
|
||||
sub_81533E0();
|
||||
taskData[0] = 7;
|
||||
break;
|
||||
case 7:
|
||||
if (taskData[2] == 0)
|
||||
sav2_gender2_inplace_and_xFE();
|
||||
sub_800ADF8();
|
||||
taskData[0] = 8;
|
||||
break;
|
||||
case 8:
|
||||
if (sub_800A520())
|
||||
{
|
||||
sub_8153408();
|
||||
taskData[0] = 9;
|
||||
}
|
||||
break;
|
||||
case 9:
|
||||
sub_800ADF8();
|
||||
taskData[0] = 10;
|
||||
break;
|
||||
case 10:
|
||||
if (sub_800A520())
|
||||
taskData[0]++;
|
||||
break;
|
||||
case 11:
|
||||
if (++taskData[1] > 5)
|
||||
{
|
||||
gSoftResetDisabled = FALSE;
|
||||
DestroyTask(taskId);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue