Skip to content

Commit

Permalink
isavegame progress (#363)
Browse files Browse the repository at this point in the history
* Add some memcard stuff to dolphin header

* isavegame progress
  • Loading branch information
SquareMan authored Sep 4, 2024
1 parent 9fdea7d commit 03c0066
Show file tree
Hide file tree
Showing 3 changed files with 243 additions and 70 deletions.
23 changes: 22 additions & 1 deletion include/dolphin/dolphin.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,30 @@ void PADReset(u32 mask);
void AXQuit();
void AXFreeVoice(_AXVPB*);
void OSSetSoundMode(u32 mode);
s32 CARDProbeEx(s32, s32*, s32*);
void VIWaitForRetrace();

#define CARD_RESULT_UNLOCKED 1
#define CARD_RESULT_READY 0
#define CARD_RESULT_BUSY -1
#define CARD_RESULT_WRONGDEVICE -2
#define CARD_RESULT_NOCARD -3
#define CARD_RESULT_NOFILE -4
#define CARD_RESULT_IOERROR -5
#define CARD_RESULT_BROKEN -6
#define CARD_RESULT_EXIST -7
#define CARD_RESULT_NOENT -8
#define CARD_RESULT_INSSPACE -9
#define CARD_RESULT_NOPERM -10
#define CARD_RESULT_LIMIT -11
#define CARD_RESULT_NAMETOOLONG -12
#define CARD_RESULT_ENCODING -13
#define CARD_RESULT_CANCELED -14
#define CARD_RESULT_FATAL_ERROR -128

void CARDInit(void);
s32 CARDUnmount(s32 chan);
s32 CARDProbeEx(s32 chan, s32* memSize, s32* sectorSize);

#ifdef __cplusplus
}
#endif
Expand Down
208 changes: 174 additions & 34 deletions src/SB/Core/gc/isavegame.cpp
Original file line number Diff line number Diff line change
@@ -1,51 +1,66 @@
#include "isavegame.h"

#include <types.h>
#include <stdio.h>
#include <string.h>

#include "iFile.h"
#include "iTRC.h"

extern char isavegame_strings[];
#include <dolphin.h>
#include <stdio.h>
#include <string.h>
#include <types.h>

extern st_ISGSESSION g_isgdata_MAIN;
// WIP
struct st_ISG_TPL_TEXPALETTE
{
};

// .sbss
static volatile S32 g_isginit;
static st_ISG_TPL_TEXPALETTE* g_rawicon;
static st_ISG_TPL_TEXPALETTE* g_rawbanr;
static S32 g_iconsize;
static S32 g_banrsize;
static S8 isMounted;

// .data
static st_ISGSESSION g_isgdata_MAIN = { 0 };
static struct
{
S32 unk_0;
S32 unk_4;
S32 unk_8;
} g_legalSectSize = { 0x2000, 0, -1 };

extern S32 g_isginit;
static S32 iSG_start_your_engines();
static S32 iSG_chk_icondata();
static S32 iSG_load_icondata();
static void iSG_discard_icondata();
static S32 iSG_mc_unmount(S32 slot);

#if 0
S32 iSGStartup()
{
S32 i = g_isginit;

if (g_isginit != 0)
if (g_isginit++ != 0)
{
g_isginit = i;

return i;
return g_isginit;
}
g_isginit = i;

iSG_start_your_engines();
iSG_load_icondata();
return i;
return g_isginit;
}
#endif

S32 iSGShutdown()
{
iSG_discard_icondata();
return 1;
}

// WIP
char* iSGMakeName(en_NAMEGEN_TYPE type, const char* base, S32 idx)
{
static S32 rotate = 0;
static char rotatebuf[32][8];
static volatile S32 rotate = 0; // fakematch??
static char rotatebuf[8][32] = { 0 };

char* use_buf = rotatebuf[rotate];
char* fmt_sd = isavegame_strings;
rotate++;
const char* fmt_sd = "%s%02d";
char* use_buf = rotatebuf[rotate++];
if (rotate == 8)
{
rotate = 0;
Expand All @@ -62,7 +77,7 @@ char* iSGMakeName(en_NAMEGEN_TYPE type, const char* base, S32 idx)
}
else
{
sprintf(use_buf, fmt_sd, isavegame_strings + 7, idx);
sprintf(use_buf, fmt_sd, "SpongeBob", idx);
}
break;
case ISG_NGTYP_GAMEDIR:
Expand All @@ -74,39 +89,164 @@ char* iSGMakeName(en_NAMEGEN_TYPE type, const char* base, S32 idx)
return use_buf;
}

#if 0
// Struct definition is screwed up.
st_ISGSESSION* iSGSessionBegin(void* cltdata, void (*chgfunc)(void*, en_CHGCODE), S32 monitor)
{
iTRCDisk::CheckDVDAndResetState();
memset(&g_isgdata_MAIN, 0, sizeof(st_ISGSESSION));

g_isgdata_MAIN.unk_260 = -1;
g_isgdata_MAIN.chgfunc = chgfunc;
g_isgdata_MAIN.cltdata = cltdata;

iSG_chk_icondata();
return &g_isgdata_MAIN;
}
#endif

#if 0
// Structs make no sense
void iSGSessionEnd(st_ISGSESSION* isgdata)
{
iTRCDisk::CheckDVDAndResetState();
for (S32 i = 0; i < 2; i++)
for (S32 i = 0; i < ISG_NUM_SLOTS; i++)
{
if (isgdata->mcdata[i].mcport != 0)
if (isgdata->mcdata[i].unk_0)
{
iSG_mc_unmount(i);
isgdata->mcdata[i].mcport = 0;
isgdata->mcdata[i].unk_0 = 0;
}
}

memset(isgdata, 0, sizeof(st_ISGSESSION));
}
#endif

void iSG_cb_asyndone(long, long)
static S32 iSG_start_your_engines()
{
CARDInit();
return 1;
}

// Looks equivalent. Can't get variable initializtions to match.
S32 iSG_mcidx2slot(S32 param1, S32* param2, S32* param3)
{
s32 cardReady[ISG_NUM_SLOTS] = {};
S32 ret = 0;
S32 idk = 0;
s32 memSize = 0;
s32 sectorSize = 0;
*param2 = -1;

for (S32 i = 0; i < ISG_NUM_SLOTS; i++)
{
s32 result;
do
{
result = CARDProbeEx(i, &memSize, &sectorSize);
} while (result == CARD_RESULT_BUSY);

if (result == CARD_RESULT_READY)
{
cardReady[i] = TRUE;
}
}

for (S32 i = 0; i < ISG_NUM_SLOTS; i++)
{
if (cardReady[i])
{
if (idk == param1)
{
*param2 = i;
ret = 1;
break;
}
idk++;
}
}

if (param3)
{
for (S32 i = 0; i < ISG_NUM_SLOTS; i++)
{
param3[i] = cardReady[i];
}
}

return ret;
}

static S32 iSG_mc_exists(S32 slot)
{
S32 ret = 0;
s32 memSize = 0;
s32 sectorSize = 0;

if (slot < -1)
{
return 0;
}

S32 result;
do
{
result = CARDProbeEx(slot, &memSize, &sectorSize);
} while (result == CARD_RESULT_BUSY);

if (result == CARD_RESULT_READY)
{
ret = 1;
}

return ret;
}

static S32 iSG_chk_icondata()
{
return 1;
}

void iSG_tpl_unpack(st_ISG_TPL_TEXPALETTE*);
static S32 iSG_load_icondata()
{
g_rawicon = (st_ISG_TPL_TEXPALETTE*)iFileLoad("/SBGCIcon.tpl", NULL, (U32*)g_iconsize);
g_rawbanr = (st_ISG_TPL_TEXPALETTE*)iFileLoad("/SBGCBanner.tpl", NULL, (U32*)g_banrsize);
iSG_tpl_unpack(g_rawicon);
iSG_tpl_unpack(g_rawbanr);

return g_rawicon && g_iconsize && g_rawbanr && g_banrsize ? 1 : 0;
}

static void iSG_discard_icondata()
{
OSFreeToHeap(__OSCurrHeap, g_rawicon);
OSFreeToHeap(__OSCurrHeap, g_rawbanr);
g_rawicon = NULL;
g_iconsize = 0;
g_rawbanr = NULL;
g_banrsize = 0;
}

static S32 iSG_mc_unmount(S32 slot)
{
S32 ret = 0;
s32 chan = slot;
S32 result;

do
{
result = CARDUnmount(chan);
} while (result == CARD_RESULT_BUSY);

if (result == CARD_RESULT_READY)
{
ret = 1;
}
else if (result == CARD_RESULT_NOCARD)
{
ret = 1;
}

return ret;
}

static void iSG_cb_asyndone(long, long)
{
}

Expand Down
Loading

0 comments on commit 03c0066

Please sign in to comment.