Skip to content
Open
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
2 changes: 2 additions & 0 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,8 @@ def MatchingFor(*versions):
[
Object(Matching, "JSystem/JUtility/JUTSDDrive.cpp", extra_cflags=["-O4,p", "-RTTI on", "-inline auto", "-enum int"]),
Object(Matching, "JSystem/JUtility/JUTSDFile.cpp", extra_cflags=["-O4,p", "-RTTI on", "-inline auto", "-enum int"]),
Object(NonMatching, "JSystem/JUtility/exidrv.c", mw_version="GC/1.2.5n", cflags=[*cflags_base, "-inline all"]),
Object(NonMatching, "JSystem/JUtility/carddrv.c", mw_version="GC/1.2.5n", cflags=[*cflags_base, "-inline all"]),
Object(Matching, "JSystem/JUtility/EXIBios.c", mw_version="GC/1.2.5n", cflags=[*cflags_base, "-O3,p", "-inline all"]),
],
),
Expand Down
73 changes: 73 additions & 0 deletions include/JSystem/JUtility/JUTSDCard.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#ifndef JUTSDCARD_H
#define JUTSDCARD_H

#include "types.h"

#ifdef __cplusplus
extern "C" {
#endif

#define SECTOR_SIZE 64

enum SDCommands {
// Block Read
/* 0x11 */ READ_SINGLE_BLOCK = 17,
/* 0x12 */ READ_MULTIPLE_BLOCK = 18,
/* 0x1E */ SEND_WRITE_PROT = 30,
/* 0x33 */ SEND_SCR = 51,

// Block Write
/* 0x18 */ WRITE_BLOCK = 24,
/* 0x19 */ WRITE_MULTIPLE_BLOCK = 25,
/* 0x1A */ PROGRAM_CID = 26,
/* 0x1B */ PROGRAM_CSD = 27,
/* 0x2A */ LOCK_UNLOCK = 42,

/* 0x00 */ GO_IDLE_STATE = 0,
/* 0x09 */ SEND_CSD = 9,
/* 0x0A */ SEND_CID = 10,
/* 0x0C */ STOP_TRANSMISSION = 12,
/* 0x0D */ SEND_STATUS = 13,
/* 0x10 */ SET_BLOCKLEN = 16,
/* 0x37 */ APP_CMD = 55,
/* 0x38 */ GEN_CMD = 56,
/* 0x4D */ CMD_4D = 77,
/* 0x69 */ CMD_69 = 105,
};

enum SDErrorStatus {
/* 0x400 */ LOCK_UNLOCK_FAILED = 1024,
};

typedef struct CID {
u8 data[0x10];
} CID;

typedef struct CSD {
u8 data[0x12];
} CSD;

typedef struct SDSTATUS {
u8 data[0x40];
} SDSTATUS;

typedef struct CMD {
u8 data[0x05];
} CMD;

typedef struct RES {
u8 data[0x80];
} RES;

typedef struct ARG {
union {
u8 data[0x04];
u32 data_u32;
};
} ARG;

#ifdef __cplusplus
};
#endif

#endif
94 changes: 94 additions & 0 deletions include/JSystem/JUtility/carddrv.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#ifndef CARDDRV_H
#define CARDDRV_H

#include "types.h"
#include "JSystem/JUtility/JUTSDCard.h"

#include <dolphin.h>

#ifdef __cplusplus
extern "C" {
#endif

enum CardErrorStatus {
CARD_ERROR_0000 = (0 << 0),
CARD_ERROR_0001 = (1 << 0),
CARD_ERROR_0002 = (1 << 1),
CARD_ERROR_0008 = (1 << 3),
CARD_ERROR_0010 = (1 << 4),
CARD_ERROR_0020 = (1 << 5),
CARD_ERROR_0040 = (1 << 6),
CARD_ERROR_0080 = (1 << 7),
CARD_ERROR_0100 = (1 << 8),
CARD_ERROR_0200 = (1 << 9),
CARD_ERROR_1000 = (1 << 12),
CARD_ERROR_4000 = (1 << 14),
CARD_ERROR_8000 = (1 << 15),

CARD_ERROR_0090 = (CARD_ERROR_0080 | CARD_ERROR_0010),
CARD_ERROR_00A0 = (CARD_ERROR_0080 | CARD_ERROR_0020),
CARD_ERROR_00B0 = (CARD_ERROR_0080 | CARD_ERROR_0020 | CARD_ERROR_0010),
CARD_ERROR_00C0 = (CARD_ERROR_0080 | CARD_ERROR_0040),
CARD_ERROR_00D0 = (CARD_ERROR_0080 | CARD_ERROR_0040 | CARD_ERROR_0010),
CARD_ERROR_00E0 = (CARD_ERROR_0080 | CARD_ERROR_0040 | CARD_ERROR_0020),
CARD_ERROR_00F0 = (CARD_ERROR_0080 | CARD_ERROR_0040 | CARD_ERROR_0020 | CARD_ERROR_0010),
};

typedef struct UnkARG {
ARG arg;
u8 _00;
} UnkARG;

typedef struct ReadWriteDParam5 {
u16 unk_00;
u16 unk_02;
u32 unk_04;
} ReadWriteDParam5;

extern int CARD_IF_Reset();
extern u16 CARD_InitD(int param_1, int param_2);
extern u16 CARD_SelectedNo();
extern u16 CARD_Select(u16 param_1);
extern u16 CARD_Reset();
extern int CARD_Getstatus(u16* param1);
extern int CARD_Getinfo(u8* param1);
extern u16 CARD_ReadD(SDSTATUS* param1, u32 param2, int param3, int param4, ReadWriteDParam5* param5);
extern u16 CARD_WriteD(SDSTATUS* param1, u32 param2, int param3, int param4, ReadWriteDParam5* param5);
extern u16 CARD_SD_Status();
extern u16 CARD_Command(u8 param1, int cmd);
extern u16 CARD_Response1(void);
extern u16 CARD_Response2();
extern u16 CARD_StopResponse();
extern u16 CARD_DataResponse();
extern u16 CARD_SoftReset();
extern u16 CARD_AppCommand();
extern u16 CARD_SendOpCond();
extern u16 CARD_SendCSD();
extern u16 CARD_SendCID();
extern u16 CARD_SetBlockLength(int param_1);
extern u16 CARD_Term();

extern RES SD_RES[CARD_NUM_CHANS];
extern CMD SD_CMD[CARD_NUM_CHANS];
extern CID SD_CID[CARD_NUM_CHANS];
extern SDSTATUS SD_SDSTATUS[CARD_NUM_CHANS];
extern CSD SD_CSD[CARD_NUM_CHANS];
extern OSAlarm CARD_Alarm[CARD_NUM_CHANS];
extern OSSemaphore CARD_Sem[CARD_NUM_CHANS];
extern int CARD_WP_Flag[CARD_NUM_CHANS];
extern u16 CARD_ExiChannel;
extern u16 CARD_ExiFreq[CARD_NUM_CHANS];
extern ARG SD_ARG[CARD_NUM_CHANS];
extern int CARD_SectorSize[CARD_NUM_CHANS];
extern volatile u16 CARD_ErrStatus[CARD_NUM_CHANS];
extern int CARD_Status[CARD_NUM_CHANS];
extern int CARD_UnlockFlag[CARD_NUM_CHANS];
extern int CARD_Size[CARD_NUM_CHANS];
extern int func_CARD_In[CARD_NUM_CHANS];
extern int func_CARD_Out[CARD_NUM_CHANS];

#ifdef __cplusplus
};
#endif

#endif
36 changes: 36 additions & 0 deletions include/JSystem/JUtility/exidrv.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#ifndef EXIDRV_H
#define EXIDRV_H

#include "types.h"
#include "JSystem/JUtility/JUTSDCard.h"

#include <dolphin.h>

#ifdef __cplusplus
extern "C" {
#endif

extern void EXI_Null(s32 chan /*, OSContext* context*/);
extern void EXI_Unlock(s32 chan /*, OSContext* context*/);
extern void EXI_AlarmFunc(OSAlarm* alarm, OSContext* context);
extern u16 EXI_ResRead(u8* arg0, u16 arg1);
extern u16 EXI_StopResRead(u8* arg0, u16 arg1);
extern u16 EXI_DataRes(u8* arg0);
extern u16 EXI_MultiWriteStop(void);
extern u16 EXI_DataRead(u8* arg0, u16 arg1);
extern u16 EXI_DataReadFinal(u8* arg0, u16 arg1);
extern u16 EXI_CmdWrite0(u8* arg0, u16 arg1);
extern u16 EXI_CmdWrite(u8* arg0, u16 arg1);
extern u16 EXI_MultiDataWrite(u8* arg0, u16 arg1);
extern u8 EXI_MakeCRC7(u8* arg0, u16 arg1);
extern u16 EXI_MakeCRC16(u8* arg0, u16 arg1);
extern s32 EXI_CheckTimeOut(u32 arg0, u32 arg1);

extern u8 SD_DUMMY[0x80];
extern u8 EXI_ClrData[CARD_NUM_CHANS];

#ifdef __cplusplus
};
#endif

#endif
1 change: 1 addition & 0 deletions include/dolphin/exi.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ BOOL EXIProbe(s32 channel);
s32 EXIProbeEx(s32 channel);
BOOL EXIAttach(s32 channel, EXICallback callback);
BOOL EXIDetach(s32 channel);
BOOL EXISelectSD(long chan, unsigned long dev, unsigned long freq);
u32 EXIGetState(s32 channel);
s32 EXIGetID(s32 channel, u32 device, u32* id);
void EXIProbeReset(void);
Expand Down
6 changes: 6 additions & 0 deletions include/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,10 @@

#define ASSERT(cond) ASSERTLINE(__LINE__, cond)

#ifdef __MWERKS__
#define ASM asm
#else
#define ASM
#endif

#endif // _H_MACROS_
6 changes: 3 additions & 3 deletions src/static/JSystem/JUtility/EXIBios.c
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ int EXIDetach(long chan) {
return 1;
}

int EXISelectSD(long chan, unsigned long dev, unsigned long freq) {
BOOL EXISelectSD(long chan, unsigned long dev, unsigned long freq) {
struct EXIControl* exi;
unsigned long cpr;
int enabled;
Expand Down Expand Up @@ -443,7 +443,7 @@ int EXISelectSD(long chan, unsigned long dev, unsigned long freq) {

exit:
OSRestoreInterrupts(enabled);
return 0;
return FALSE;

select:
exi->state |= 4;
Expand All @@ -462,7 +462,7 @@ int EXISelectSD(long chan, unsigned long dev, unsigned long freq) {
}
}
OSRestoreInterrupts(enabled);
return 1;
return TRUE;
}

int EXISelect(long chan, unsigned long dev, unsigned long freq) {
Expand Down
Loading