Skip to content

Commit e5bcef8

Browse files
committed
memcard progress
1 parent 47c7e0a commit e5bcef8

File tree

3 files changed

+25
-24
lines changed

3 files changed

+25
-24
lines changed

decompile/General/MEMCARD/MEMCARD_22_IsFile.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,18 @@ int DECOMP_MEMCARD_IsFile(int slotIdx, char *save_name)
66

77
MEMCARD_StringSet(name, slotIdx, save_name);
88

9-
// 0x8002, in sys/fcntl.h
10-
// 0x8000 = FASYNC, for asynchronous I/O
11-
// 0x0002 = FWRITE, for writing
12-
sdata->memcard_fd = open(name, FASYNC|FWRITE);
9+
// This temporary FD will not be saved,
10+
// The global FD will always be wiped
11+
int fd;
12+
sdata->memcard_fd = -1;
1313

14-
if (sdata->memcard_fd == -1)
15-
return MC_RETURN_NODATA;
14+
fd = open(name, FASYNC|FWRITE);
1615

17-
close(sdata->memcard_fd);
18-
sdata->memcard_fd = -1;
19-
return MC_RETURN_IOE;
16+
if (fd != -1)
17+
{
18+
close(fd);
19+
return MC_RETURN_IOE;
20+
}
21+
22+
return MC_RETURN_NODATA;
2023
}

decompile/WorkInProgress/src/MEMCARD/MEMCARD_Load.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,7 @@ uint8_t MEMCARD_Load(int slotIdx, char *name, uint8_t *ptrMemcard, int memcardFi
1212

1313
MEMCARD_NewTask(slotIdx, name, ptrMemcard, memcardFileSize, param5); // Too many params to NewTask. param5 is always 0
1414

15-
16-
// 0x8001, in sys/fcntl.h
17-
// 0x8000 = FASYNC, for asynchronous I/O
18-
// 0x0001 = FREAD, for reading
19-
20-
sdata->memcard_fd = open(sdata->s_bu00_BASCUS_94426_slots, 0x8001);
15+
sdata->memcard_fd = open(sdata->s_bu00_BASCUS_94426_slots, FASYNC|FREAD);
2116

2217
if (sdata->memcard_fd == -1)
2318
{

decompile/WorkInProgress/src/MEMCARD/MEMCARD_Save.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,25 +49,28 @@ uint8_t MEMCARD_Save(int slotIdx, char *name,
4949

5050
MEMCARD_ChecksumSave(ptrData, fileSize);
5151

52-
// In sys/fcntl.h
53-
// 0x200 is FCREAT, create if it does not exist,
54-
// DAT_800857a3 handles read or write
52+
53+
54+
// ====== Open 1 ======
55+
56+
5557

5658
// Search for "MEMCARD_SET_SIZE_BYTE3"
57-
sdata->memcard_fd = open(sdata->s_bu00_BASCUS_94426_slots,
58-
(unsigned int)*((uint8_t *)(data.memcardIcon_PsyqHand) + 3) << 0x10 | FCREATE);
59+
int whatIsThis = (unsigned int)*((uint8_t *)(data.memcardIcon_PsyqHand) + 3) << 0x10;
60+
61+
sdata->memcard_fd = open(sdata->s_bu00_BASCUS_94426_slots, whatIsThis | FCREATE);
5962

6063
if (sdata->memcard_fd != -1)
6164
{
6265
close(sdata->memcard_fd);
6366
sdata->memcard_fd = -1;
6467
}
6568

66-
// 0x8002, in sys/fcntl.h
67-
// 0x8000 = FASYNC, for asynchronous I/O
68-
// 0x0002 = FWRITE, for writing
6969

70-
sdata->memcard_fd = open(sdata->s_bu00_BASCUS_94426_slots, 0x8002);
70+
// ====== Open 2 ======
71+
72+
73+
sdata->memcard_fd = open(sdata->s_bu00_BASCUS_94426_slots, FASYNC|FWRITE);
7174

7275
if (sdata->memcard_fd != -1)
7376
{

0 commit comments

Comments
 (0)