Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SD2SP2 support #67

Merged
merged 3 commits into from
Oct 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions gc/ogc/disc_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#define FEATURE_GAMECUBE_SLOTA 0x00000010
#define FEATURE_GAMECUBE_SLOTB 0x00000020
#define FEATURE_GAMECUBE_DVD 0x00000040
#define FEATURE_GAMECUBE_PORT2 0x00000080
#define FEATURE_WII_SD 0x00000100
#define FEATURE_WII_USB 0x00000200
#define FEATURE_WII_DVD 0x00000400
Expand Down
2 changes: 1 addition & 1 deletion gc/sdcard/card_cmn.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#define CARDIO_ERROR_INVALIDPARAM -127
#define CARDIO_ERROR_FATALERROR -128

#define MAX_DRIVE 2
#define MAX_DRIVE 3
#define SECTOR_SIZE 512

#define NOT_INITIALIZED 0
Expand Down
1 change: 1 addition & 0 deletions gc/sdcard/gcsd.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@

extern const DISC_INTERFACE __io_gcsda;
extern const DISC_INTERFACE __io_gcsdb;
extern const DISC_INTERFACE __io_gcsd2;

#endif
42 changes: 42 additions & 0 deletions libogc/gcsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,38 @@ static bool __gcsdb_shutdown(void)
return __gcsd_shutdown(1);
}



static bool __gcsd2_startup(void)
{
return __gcsd_startup(2);
}

static bool __gcsd2_isInserted(void)
{
return __gcsd_isInserted(2);
}

static bool __gcsd2_readSectors(sec_t sector, sec_t numSectors, void *buffer)
{
return __gcsd_readSectors(2, sector, numSectors, buffer);
}

static bool __gcsd2_writeSectors(sec_t sector, sec_t numSectors, const void *buffer)
{
return __gcsd_writeSectors(2, sector, numSectors, buffer);
}

static bool __gcsd2_clearStatus(void)
{
return __gcsd_clearStatus(2);
}

static bool __gcsd2_shutdown(void)
{
return __gcsd_shutdown(2);
}

const DISC_INTERFACE __io_gcsda = {
DEVICE_TYPE_GC_SD,
FEATURE_MEDIUM_CANREAD | FEATURE_MEDIUM_CANWRITE | FEATURE_GAMECUBE_SLOTA,
Expand All @@ -172,3 +204,13 @@ const DISC_INTERFACE __io_gcsdb = {
__gcsdb_clearStatus,
__gcsdb_shutdown
};
const DISC_INTERFACE __io_gcsd2 = {
DEVICE_TYPE_GC_SD,
FEATURE_MEDIUM_CANREAD | FEATURE_MEDIUM_CANWRITE | FEATURE_GAMECUBE_PORT2,
__gcsd2_startup,
__gcsd2_isInserted,
__gcsd2_readSectors,
__gcsd2_writeSectors,
__gcsd2_clearStatus,
__gcsd2_shutdown
} ;
62 changes: 14 additions & 48 deletions libogc/sdgecko_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,8 @@ static void __exi_wait(s32 drv_no)
static s32 __card_exthandler(s32 chn,s32 dev)
{
_ioCardInserted[chn] = FALSE;
sdgecko_doUnmount(chn);
_ioFlag[chn] = NOT_INITIALIZED;
sdgecko_ejectedCB(chn);
EXI_Unlock(chn);
return 1;
}

Expand Down Expand Up @@ -406,32 +405,21 @@ static s32 __card_writecmd(s32 drv_no,void *buf,s32 len)
static s32 __card_readresponse(s32 drv_no,void *buf,s32 len)
{
u8 *ptr;
s32 startT,ret;
u32 cnt;
s32 ret;

if(drv_no<0 || drv_no>=MAX_DRIVE) return CARDIO_ERROR_NOCARD;

ret = CARDIO_ERROR_READY;
ptr = buf;
*ptr = _ioClrFlag;

__exi_wait(drv_no);

if(EXI_Select(drv_no,EXI_DEVICE_0,_ioCardFreq)==0) {
EXI_Unlock(drv_no);
return CARDIO_ERROR_NOCARD;
}

if(EXI_ImmEx(drv_no,ptr,1,EXI_READWRITE)==0) {
EXI_Deselect(drv_no);
EXI_Unlock(drv_no);
return CARDIO_ERROR_IOERROR;
}
#ifdef _CARDIO_DEBUG
printf("sd response: %02x\n",((u8*)buf)[0]);
#endif

startT = gettick();
while(*ptr&0x80) {
ret = CARDIO_ERROR_READY;
ptr = buf;
for(cnt=0;cnt<16;cnt++) {
*ptr = _ioClrFlag;
if(EXI_ImmEx(drv_no,ptr,1,EXI_READWRITE)==0) {
EXI_Deselect(drv_no);
Expand All @@ -442,20 +430,8 @@ static s32 __card_readresponse(s32 drv_no,void *buf,s32 len)
printf("sd response: %02x\n",((u8*)buf)[0]);
#endif
if(!(*ptr&0x80)) break;
if(__card_checktimeout(drv_no,startT,500)!=0) {
*ptr = _ioClrFlag;
if(EXI_ImmEx(drv_no,ptr,1,EXI_READWRITE)==0) {
EXI_Deselect(drv_no);
EXI_Unlock(drv_no);
return CARDIO_ERROR_IOERROR;
}
#ifdef _CARDIO_DEBUG
printf("sd response: %02x\n",((u8*)buf)[0]);
#endif
if(*ptr&0x80) ret = CARDIO_ERROR_IOTIMEOUT;
break;
}
}
if(cnt>=16) ret = CARDIO_ERROR_IOTIMEOUT;
if(len>1 && ret==CARDIO_ERROR_READY) {
*(++ptr) = _ioClrFlag;
if(EXI_ImmEx(drv_no,ptr,len-1,EXI_READWRITE)==0) ret = CARDIO_ERROR_IOERROR;
Expand Down Expand Up @@ -1173,6 +1149,7 @@ static bool __card_check(s32 drv_no)
#ifdef _CARDIO_DEBUG
printf("__card_check(%d)\n",drv_no);
#endif
if(drv_no==2) return TRUE;
while((ret=EXI_ProbeEx(drv_no))==0);
if(ret!=1) return FALSE;

Expand Down Expand Up @@ -1311,7 +1288,7 @@ s32 sdgecko_readCID(s32 drv_no)
{
s32 ret;

if(drv_no<EXI_CHANNEL_0 || drv_no>=EXI_CHANNEL_2) return CARDIO_ERROR_NOCARD;
if(drv_no<0 || drv_no>=MAX_DRIVE) return CARDIO_ERROR_NOCARD;
#ifdef _CARDIO_DEBUG
printf("sdgecko_readCID(%d)\n",drv_no);
#endif
Expand Down Expand Up @@ -1341,7 +1318,7 @@ s32 sdgecko_readStatus(s32 drv_no)

if(drv_no<0 || drv_no>=MAX_DRIVE) return CARDIO_ERROR_NOCARD;
#ifdef _CARDIO_DEBUG
printf("sdgecko_readCSD(%d)\n",drv_no);
printf("sdgecko_readStatus(%d)\n",drv_no);
#endif
ret = sdgecko_preIO(drv_no);
if(ret!=0) return ret;
Expand Down Expand Up @@ -1443,26 +1420,15 @@ s32 sdgecko_writeSectors(s32 drv_no,u32 sector_no,u32 num_sectors,const void *bu

s32 sdgecko_doUnmount(s32 drv_no)
{
s32 ret;

if(drv_no<0 || drv_no>=MAX_DRIVE) return CARDIO_ERROR_NOCARD;

if(__card_check(drv_no)==TRUE && _ioFlag[drv_no]!=NOT_INITIALIZED) {
if((ret=__card_sendappcmd(drv_no))!=0) goto exit;
if((ret=__card_sendcmd(drv_no,0x2a,NULL))!=0) goto exit;
ret = __card_response1(drv_no);
#ifdef _CARDIO_DEBUG
printf("sdgecko_doUnmount(%d) disconnected 50KOhm pull-up(%d)\n",drv_no,ret);
#endif
}
_ioFlag[drv_no] = NOT_INITIALIZED;

exit:
if(_ioCardInserted[drv_no]==TRUE) {
_ioCardInserted[drv_no] = FALSE;
EXI_Detach(drv_no);
_ioFlag[drv_no] = NOT_INITIALIZED;
if(drv_no!=2) EXI_Detach(drv_no);
sdgecko_ejectedCB(drv_no);
}
if(_ioRetryCB)
if(_ioRetryCB)
return _ioRetryCB(drv_no);

return CARDIO_ERROR_READY;
Expand Down
4 changes: 2 additions & 2 deletions libogc/usbgecko.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@


static u32 usbgecko_inited = 0;
static lwpq_t wait_exi_queue[2];
static lwpq_t wait_exi_queue[3];

static s32 __usbgecko_exi_unlock(s32 chan,s32 dev)
{
Expand All @@ -28,7 +28,7 @@ static void __usbgecko_init(void)
{
u32 i;

for(i=0;i<EXI_CHANNEL_2;i++) {
for(i=0;i<EXI_CHANNEL_MAX;i++) {
LWP_InitQueue(&wait_exi_queue[i]);
}
usbgecko_inited = 1;
Expand Down