Skip to content

Commit 412f33d

Browse files
committed
memcard progress
1 parent 468697e commit 412f33d

File tree

6 files changed

+39
-38
lines changed

6 files changed

+39
-38
lines changed

decompile/WorkInProgress/src/MEMCARD/MEMCARD_FindFirstGhost.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
// param2 = BASCUS-94426G*
44
// TODO: 4 bytes over budget
5-
char *DECOMP_MEMCARD_FindFirstGhost(int slotIdx, char *srcString)
5+
char* DECOMP_MEMCARD_FindFirstGhost(int slotIdx, char *srcString)
66
{
7-
if (sdata->memcard_stage)
7+
if (sdata->memcard_stage != MC_STAGE_IDLE)
88
{
9-
return (char *)0;
9+
return 0;
1010
}
1111

1212
struct DIRENTRY *firstEntry;
@@ -16,9 +16,12 @@ char *DECOMP_MEMCARD_FindFirstGhost(int slotIdx, char *srcString)
1616
// string for directory and file of save that is in use
1717
firstEntry = firstfile(sdata->s_bu00_BASCUS_94426_slots, &someEntry);
1818

19+
// [error]
20+
// They cant be true, a firstfile pointer wont "equal" a stack pointer,
21+
// maybe compare the strings instead?
1922
if (firstEntry == &someEntry)
2023
{
21-
sdata->memcard_stage = 0xf;
24+
sdata->memcard_stage = MC_STAGE_GHOST_FOUND;
2225
strcpy(firstEntry->name, someEntry.name); // 0x80
2326
return &sdata->s_memcardFindGhostFile[0];
2427
}

decompile/WorkInProgress/src/MEMCARD/MEMCARD_FindNextGhost.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,19 @@ char* DECOMP_MEMCARD_FindNextGhost(void)
99
struct DIRENTRY *nextEntry;
1010
struct DIRENTRY someEntry;
1111

12-
if (sdata->memcard_stage == 0xf)
12+
if (sdata->memcard_stage != MC_STAGE_GHOST_FOUND)
1313
{
14-
nextEntry = nextfile(&someEntry);
15-
if (nextEntry == &someEntry)
16-
{
17-
strcpy(nextEntry->name, someEntry.name);
18-
return &sdata->s_memcardFindGhostFile[0];
19-
}
20-
sdata->memcard_stage = 0;
14+
return 0;
2115
}
2216

23-
return (char *)0;
17+
// [error]
18+
// They cant be true, a firstfile pointer wont "equal" a stack pointer,
19+
// maybe compare the strings instead?
20+
nextEntry = nextfile(&someEntry);
21+
if (nextEntry == &someEntry)
22+
{
23+
strcpy(nextEntry->name, someEntry.name);
24+
return &sdata->s_memcardFindGhostFile[0];
25+
}
26+
sdata->memcard_stage = MC_STAGE_IDLE;
2427
}
Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,19 @@
11
#include <common.h>
22

33
uint8_t DECOMP_MEMCARD_GetInfo(int slotIdx)
4-
54
{
6-
if (sdata->memcard_stage == 0)
7-
{
8-
MEMCARD_SkipEvents();
9-
sdata->memcard_stage = 1;
10-
sdata->memcardSlot = slotIdx;
11-
12-
// loop until check is "submitted",
13-
// result is not "returned", result
14-
// is found in SwCARD descriptor/event (see libref)
15-
while (_card_info(slotIdx) != 1)
16-
;
17-
18-
sdata->memcard_remainingAttempts = 8;
19-
return 7;
20-
}
21-
else
22-
{
5+
if (sdata->memcard_stage != MC_STAGE_IDLE)
236
return 1;
24-
}
7+
8+
// discard any pending events
9+
// submit a card_info request,
10+
// check the result of a GET INFO
11+
// 8 tries to see if it worked
12+
MEMCARD_SkipEvents();
13+
while (!_card_info(slotIdx));
14+
sdata->memcard_stage = MC_STAGE_GETINFO;
15+
sdata->memcard_remainingAttempts = 8;
16+
sdata->memcardSlot = slotIdx;
17+
18+
return 7;
2519
}

decompile/WorkInProgress/src/MEMCARD/MEMCARD_Load.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,11 @@
77
uint8_t MEMCARD_Load(int slotIdx, char *name, uint8_t *ptrMemcard, int memcardFileSize, unsigned int param5)
88

99
{
10-
if (sdata->memcard_stage != 0)
11-
{
10+
if (sdata->memcard_stage != MC_STAGE_IDLE)
1211
return 1;
13-
}
12+
1413
MEMCARD_NewTask(slotIdx, name, ptrMemcard, memcardFileSize, param5); // Too many params to NewTask. param5 is always 0
15-
// 800990a4
16-
// string for directory and file of save that is in use
14+
1715

1816
// 0x8001, in sys/fcntl.h
1917
// 0x8000 = FASYNC, for asynchronous I/O

ghidra/RefreshCard.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1189,7 +1189,8 @@ void FUN_80047a58(void)
11891189

11901190
iVar2 = 0;
11911191

1192-
// loop until you have gone through all memory card saves
1192+
// 0x0: MC_STAGE_IDLE (did not find ghost)
1193+
// 0xF: MC_STAGE_GHOST_FOUND (found ghost)
11931194
while (iVar3 != 0)
11941195
{
11951196
// If there are less than 7 ghosts loaded

include/namespace_Memcard.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ enum MC_STAGE
1818

1919
MC_STAGE_ERASE_FAIL = 13,
2020
MC_STAGE_ERASE_PASS = 14,
21+
22+
MC_STAGE_GHOST_FOUND = 15,
2123
};
2224

2325
enum MC_EVENT

0 commit comments

Comments
 (0)