Skip to content

Commit 553ce9f

Browse files
committed
isavegame matches and iSGReadLeader bugfixes
1 parent db4ddc5 commit 553ce9f

File tree

2 files changed

+69
-26
lines changed

2 files changed

+69
-26
lines changed

include/dolphin/dolphin.h

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,35 @@ typedef int BOOL;
4242
#define NULL 0
4343
#endif
4444

45+
#define OS_CACHED_REGION_PREFIX 0x8000
46+
#define OS_UNCACHED_REGION_PREFIX 0xC000
47+
#define OS_PHYSICAL_MASK 0x3FFF
48+
49+
#define OS_BASE_CACHED (OS_CACHED_REGION_PREFIX << 16)
50+
#define OS_BASE_UNCACHED (OS_UNCACHED_REGION_PREFIX << 16)
51+
52+
#ifdef __MWERKS__
53+
u32 __OSSimulatedMemSize : (OS_BASE_CACHED | 0x00F0);
54+
u32 __OSBusClock : (OS_BASE_CACHED | 0x00F8);
55+
u32 __OSCoreClock : (OS_BASE_CACHED | 0x00FC);
56+
s32 __gUnknown800030C0[2] : (OS_BASE_CACHED | 0x30C0);
57+
u8 __gUnknown800030E3 : (OS_BASE_CACHED | 0x30E3);
58+
#else
59+
#define __OSBusClock (*(u32*)(OS_BASE_CACHED | 0x00F8))
60+
#define __OSCoreClock (*(u32*)(OS_BASE_CACHED | 0x00FC))
61+
#endif
62+
#define OS_BUS_CLOCK __OSBusClock
63+
#define OS_CORE_CLOCK __OSCoreClock
64+
#define OS_TIMER_CLOCK (OS_BUS_CLOCK / 4)
65+
66+
#define OSTicksToSeconds(ticks) ((ticks) / (OS_TIMER_CLOCK))
67+
#define OSTicksToMilliseconds(ticks) ((ticks) / (OS_TIMER_CLOCK / 1000))
68+
#define OSTicksToMicroseconds(ticks) ((ticks) * 8 / (OS_TIMER_CLOCK / 125000))
69+
#define OSSecondsToTicks(sec) ((sec) * (OS_TIMER_CLOCK))
70+
#define OSMillisecondsToTicks(msec) ((msec) * (OS_TIMER_CLOCK / 1000))
71+
#define OSNanosecondsToTicks(nsec) (((nsec) * (OS_TIMER_CLOCK / 125000)) / 8000)
72+
#define OSMicrosecondsToTicks(usec) (((usec) * (OS_TIMER_CLOCK / 125000)) / 8)
73+
4574
#ifdef __cplusplus
4675
extern "C" {
4776
#endif
@@ -365,7 +394,8 @@ s32 CARDSetStatus(s32 chan, s32 fileNo, struct CARDStat* stat);
365394
s32 CARDReadAsync(CARDFileInfo* fileInfo, void* buf, s32 length, s32 offset, CARDCallback callback);
366395
s32 CARDRead(struct CARDFileInfo* fileInfo, void* buf, s32 length, s32 offset);
367396
// CARDWrite
368-
s32 CARDWriteAsync(CARDFileInfo* fileInfo, void* buf, s32 length, s32 offset, CARDCallback callback);
397+
s32 CARDWriteAsync(CARDFileInfo* fileInfo, void* buf, s32 length, s32 offset,
398+
CARDCallback callback);
369399
// CARDOpen.h
370400
s32 CARDFastOpen(s32 chan, s32 fileNo, CARDFileInfo* fileInfo);
371401
s32 CARDOpen(s32 chan, char* fileName, CARDFileInfo* fileInfo);

src/SB/Core/gc/isavegame.cpp

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -361,23 +361,27 @@ S32 iSGTgtSetActive(st_ISGSESSION* isgdata, S32 tgtidx)
361361
static S32 iSG_get_finfo(st_ISG_MEMCARD_DATA* mcdata, const char* dpath);
362362
static S32 iSG_isSpaceForFile(st_ISG_MEMCARD_DATA* mcdata, S32 param2, const char* param3,
363363
S32* param4, S32* param5, S32* param6);
364-
// Regswaps
365364
S32 iSGTgtHaveRoom(st_ISGSESSION* isgdata, S32 tidx, S32 fsize, const char* dpath,
366365
const char* fname, S32* bytesNeeded, S32* availOnDisk, S32* needFile)
367366
{
367+
st_ISG_MEMCARD_DATA* data;
368+
S32 i;
369+
S32 count;
370+
S32 opened;
371+
S32 is_space;
368372
if (isgdata->slot < 0)
369373
{
370374
return 0;
371375
}
372-
st_ISG_MEMCARD_DATA* data = &isgdata->mcdata[isgdata->slot];
376+
data = &isgdata->mcdata[isgdata->slot];
373377
if (data->unk_0 == NULL)
374378
{
375379
return 0;
376380
}
377-
S32 count = 0;
381+
count = 0;
378382
if (fname == NULL)
379383
{
380-
for (S32 i = 0; i < ISG_NUM_FILES; ++i)
384+
for (i = 0; i < ISG_NUM_FILES; ++i)
381385
{
382386
iTRCDisk::CheckDVDAndResetState();
383387
fname = iSGMakeName(ISG_NGTYP_GAMEFILE, NULL, i);
@@ -388,7 +392,7 @@ S32 iSGTgtHaveRoom(st_ISGSESSION* isgdata, S32 tidx, S32 fsize, const char* dpat
388392
}
389393
}
390394

391-
S32 is_space = iSG_isSpaceForFile(data, fsize, fname, bytesNeeded, availOnDisk, needFile);
395+
is_space = iSG_isSpaceForFile(data, fsize, fname, bytesNeeded, availOnDisk, needFile);
392396
if (count > 0 && *bytesNeeded > *availOnDisk)
393397
{
394398
if (needFile != NULL && *bytesNeeded > *availOnDisk)
@@ -400,8 +404,8 @@ S32 iSGTgtHaveRoom(st_ISGSESSION* isgdata, S32 tidx, S32 fsize, const char* dpat
400404
}
401405

402406
CARDFileInfo fileInfo;
403-
S32 opened = 0;
404-
for (S32 i = 0; i < CARD_MAX_FILE && isgdata->slot >= 0 && isgdata->slot < ISG_NUM_SLOTS; ++i)
407+
opened = 0;
408+
for (i = 0; i < CARD_MAX_FILE && isgdata->slot >= 0 && isgdata->slot < ISG_NUM_SLOTS; ++i)
405409
{
406410
if (CARDFastOpen(isgdata->slot, i, &fileInfo) == 0)
407411
{
@@ -426,23 +430,27 @@ S32 iSGTgtHaveRoom(st_ISGSESSION* isgdata, S32 tidx, S32 fsize, const char* dpat
426430
return (*bytesNeeded > *availOnDisk) ? 0 : is_space;
427431
}
428432

429-
// Regswaps, very similar to above
430433
S32 iSGTgtHaveRoomStartup(st_ISGSESSION* isgdata, S32 tidx, S32 fsize, const char* dpath,
431434
const char* fname, S32* bytesNeeded, S32* availOnDisk, S32* needFile)
432435
{
436+
st_ISG_MEMCARD_DATA* data;
437+
S32 i;
438+
S32 count;
439+
S32 opened;
440+
S32 is_space;
433441
if (isgdata->slot < 0)
434442
{
435443
return 0;
436444
}
437-
st_ISG_MEMCARD_DATA* data = &isgdata->mcdata[isgdata->slot];
445+
data = &isgdata->mcdata[isgdata->slot];
438446
if (data->unk_0 == NULL)
439447
{
440448
return 0;
441449
}
442-
S32 count = 0;
450+
count = 0;
443451
if (fname == NULL)
444452
{
445-
for (S32 i = 0; i < ISG_NUM_FILES; ++i)
453+
for (i = 0; i < ISG_NUM_FILES; ++i)
446454
{
447455
iTRCDisk::CheckDVDAndResetState();
448456
fname = iSGMakeName(ISG_NGTYP_GAMEFILE, NULL, i);
@@ -453,7 +461,7 @@ S32 iSGTgtHaveRoomStartup(st_ISGSESSION* isgdata, S32 tidx, S32 fsize, const cha
453461
}
454462
}
455463

456-
S32 is_space = iSG_isSpaceForFile(data, fsize, fname, bytesNeeded, availOnDisk, needFile);
464+
is_space = iSG_isSpaceForFile(data, fsize, fname, bytesNeeded, availOnDisk, needFile);
457465
if (count > 0 && *bytesNeeded > *availOnDisk)
458466
{
459467
if (needFile != NULL && *bytesNeeded > *availOnDisk)
@@ -465,8 +473,8 @@ S32 iSGTgtHaveRoomStartup(st_ISGSESSION* isgdata, S32 tidx, S32 fsize, const cha
465473
}
466474

467475
CARDFileInfo fileInfo;
468-
S32 opened = 0;
469-
for (S32 i = 0; i < CARD_MAX_FILE && isgdata->slot >= 0 && isgdata->slot < ISG_NUM_SLOTS; ++i)
476+
opened = 0;
477+
for (i = 0; i < CARD_MAX_FILE && isgdata->slot >= 0 && isgdata->slot < ISG_NUM_SLOTS; ++i)
470478
{
471479
if (CARDFastOpen(isgdata->slot, i, &fileInfo) == 0)
472480
{
@@ -751,20 +759,23 @@ S32 iSGLoadFile(st_ISGSESSION* isgdata, const char* fname, char* databuf, S32 as
751759
static S32 iSG_mc_fread(st_ISG_MEMCARD_DATA* mcdata, char*, S32, S32);
752760
S32 iSGReadLeader(st_ISGSESSION* isgdata, const char* fname, char* databuf, S32 numbytes, S32 async)
753761
{
754-
void* alloc = NULL;
762+
S32 bufsize;
763+
S32 iconsize;
755764
S32 allocsize;
756765
char* readbuf;
757-
S32 bufsize;
758766

759-
en_ASYNC_OPERR operr = ISG_OPERR_NONE;
760767
S32 readret = 0;
768+
st_ISG_MEMCARD_DATA* data;
769+
void* alloc = NULL;
770+
771+
en_ASYNC_OPERR operr = ISG_OPERR_NONE;
761772
if (isgdata->slot < 0)
762773
{
763774
isgdata->unk_26c = ISG_OPSTAT_FAILURE;
764775
isgdata->unk_268 = ISG_OPERR_NOCARD;
765776
return 0;
766777
}
767-
st_ISG_MEMCARD_DATA* data = &isgdata->mcdata[isgdata->slot];
778+
data = &isgdata->mcdata[isgdata->slot];
768779

769780
if (data->unk_12c != 0)
770781
{
@@ -774,14 +785,15 @@ S32 iSGReadLeader(st_ISGSESSION* isgdata, const char* fname, char* databuf, S32
774785
}
775786

776787
iTRCDisk::CheckDVDAndResetState();
777-
S32 iconsize = iSG_cubeicon_size(data->chan, data->sectorSize);
788+
iconsize = iSG_cubeicon_size(data->chan, data->sectorSize);
778789
S32 sectorsize200 = ALIGN_THING(data->sectorSize, 0x200);
779-
if ((S32)databuf % 32 != 0 || numbytes - ((numbytes / sectorsize200) * sectorsize200) != 0)
790+
if ((S32)databuf % 32 != 0 || numbytes - (numbytes / sectorsize200) * sectorsize200 != 0)
780791
{
781-
bufsize = (iconsize + 0x1ff & ~0x1ff);
782-
S32 allocsize = bufsize + 0x1f;
792+
S32 tmpsize = (numbytes + 0x1ff & ~0x1ff);
793+
allocsize = tmpsize + 0x1f;
783794
alloc = xMemPushTemp(allocsize);
784795
memset(alloc, 0, allocsize);
796+
bufsize = tmpsize;
785797
readbuf = (char*)((U32)alloc + 0x1f & ~0x1f);
786798
}
787799
else
@@ -798,7 +810,7 @@ S32 iSGReadLeader(st_ISGSESSION* isgdata, const char* fname, char* databuf, S32
798810
iSG_mc_fclose(data);
799811
}
800812

801-
if (readret == 0 && alloc != NULL)
813+
if (readret != 0 && alloc != NULL)
802814
{
803815
memcpy(databuf, readbuf, numbytes);
804816
}
@@ -1340,8 +1352,9 @@ static S32 iSG_get_fmoddate(st_ISG_MEMCARD_DATA* mcdata, const char* fname, int*
13401352
}
13411353
else
13421354
{
1343-
// FIXME: This first param isn't right, can't decipher the 64 bit math
1344-
OSTicksToCalendarTime((u64)mcdata->unk_b0.time * (u64)(GET_BUS_FREQUENCY() / 4), &time);
1355+
OSTime t = mcdata->unk_b0.time;
1356+
t = OSSecondsToTicks(t);
1357+
OSTicksToCalendarTime(t, &time);
13451358

13461359
if (sec)
13471360
{

0 commit comments

Comments
 (0)