dolphin lib work (#237)

* getLayerNo_common_common finally matched

* dolphin ai / ar / card work from prime decomp

* work on dolphin dvd / dsp / db

* more dolphin os work

* si work

* remove asm

* build fix
This commit is contained in:
TakaRikka
2023-01-02 12:20:10 -07:00
committed by GitHub
parent 6cc376bb2b
commit f070ee948f
257 changed files with 9623 additions and 10848 deletions
+2 -2
View File
@@ -573,7 +573,7 @@ void JFWDisplay::threadSleep(s64 time) {
s32 status = OSDisableInterrupts();
alarm.appendLink();
OSSetAlarm(&alarm, time, (OSAlarmHandler*)JFWThreadAlarmHandler);
OSSetAlarm(&alarm, time, JFWThreadAlarmHandler);
OSSuspendThread(alarm.getThread());
OSRestoreInterrupts(status);
}
@@ -694,7 +694,7 @@ static void JFWDrawDoneAlarm() {
s32 status = OSDisableInterrupts();
alarm.createAlarm();
alarm.appendLink();
OSSetAlarm(&alarm, 0.5 * (*(u32*)0x800000F8 / 4), (OSAlarmHandler*)JFWGXAbortAlarmHandler);
OSSetAlarm(&alarm, 0.5 * (*(u32*)0x800000F8 / 4), JFWGXAbortAlarmHandler);
GXDrawDone();
alarm.cancelAlarm();
alarm.removeLink();
+9 -1
View File
@@ -9,6 +9,14 @@ LIBAI_A_O_FILES := \
$(BUILD_DIR)/libs/dolphin/ai/ai.o \
LIBAI_A_CFLAGS := \
-Cpp_exceptions off \
-proc gekko \
-fp hard \
-nodefaults \
-str reuse \
-RTTI off \
-maxerrors 5 \
-enum int $(INCLUDES) \
-O4,p \
-lang=c \
@@ -27,4 +35,4 @@ $(BUILD_DIR)/libs/dolphin/ai/%.o: libs/dolphin/ai/%.c
@mkdir -p $(@D)
@echo building... $<
@$(ICONV) -f UTF-8 -t CP932 < $< > $(basename $@).c
@$(WINE) tools/mwcc_compiler/1.2.5/mwcceppc.exe $(CFLAGS) $(LIBAI_A_CFLAGS) -c -o $@ $(basename $@).c
@$(WINE) tools/mwcc_compiler/1.2.5/mwcceppc.exe $(LIBAI_A_CFLAGS) -c -o $@ $(basename $@).c
+282 -164
View File
File diff suppressed because it is too large Load Diff
+9 -1
View File
@@ -11,6 +11,14 @@ LIBAR_A_O_FILES := \
$(BUILD_DIR)/libs/dolphin/ar/arq.o \
LIBAR_A_CFLAGS := \
-Cpp_exceptions off \
-proc gekko \
-fp hard \
-nodefaults \
-str reuse \
-RTTI off \
-maxerrors 5 \
-enum int $(INCLUDES) \
-O4,p \
-lang=c \
@@ -29,5 +37,5 @@ $(BUILD_DIR)/libs/dolphin/ar/%.o: libs/dolphin/ar/%.c
@mkdir -p $(@D)
@echo building... $<
@$(ICONV) -f UTF-8 -t CP932 < $< > $(basename $@).c
@$(WINE) tools/mwcc_compiler/1.2.5/mwcceppc.exe $(CFLAGS) $(LIBAR_A_CFLAGS) -c -o $@ $(basename $@).c
@$(WINE) tools/mwcc_compiler/1.2.5/mwcceppc.exe $(LIBAR_A_CFLAGS) -c -o $@ $(basename $@).c
+101 -57
View File
@@ -4,142 +4,186 @@
//
#include "dolphin/ar/ar.h"
#include "MSL_C/MSL_Common/Src/string.h"
#include "dol2asm.h"
#include "dolphin/types.h"
#include "dolphin/base/PPCArch.h"
#include "dolphin/dsp/dsp.h"
#include "dolphin/os/OS.h"
//
// Forward References:
//
void ARRegisterDMACallback();
void ARGetDMAStatus();
void ARStartDMA();
void __ARHandler();
void __ARHandler(s16 interrupt, OSContext* context);
void __ARClearInterrupt();
void __ARGetInterruptStatus();
void __ARChecksize();
//
// External References:
//
SECTION_INIT void memset();
void PPCSync();
void OSRegisterVersion();
void DCInvalidateRange();
void DCFlushRange();
void OSSetCurrentContext();
void OSClearContext();
void OSDisableInterrupts();
void OSRestoreInterrupts();
void __OSSetInterruptHandler();
void __OSUnmaskInterrupts();
//
// Declarations:
//
/* ############################################################################################## */
/* 804518B8-804518BC 000DB8 0004+00 3/3 0/0 0/0 .sbss __AR_Callback */
static u8 __AR_Callback[4];
static ARCallback __AR_Callback;
/* 80350554-80350598 34AE94 0044+00 0/0 1/1 0/0 .text ARRegisterDMACallback */
// needs compiler epilogue patch
#ifdef NONMATCHING
ARCallback ARRegisterDMACallback(ARCallback callback) {
ARCallback oldCb;
BOOL enabled;
oldCb = __AR_Callback;
enabled = OSDisableInterrupts();
__AR_Callback = callback;
OSRestoreInterrupts(enabled);
return oldCb;
}
#else
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
asm void ARRegisterDMACallback() {
asm ARCallback ARRegisterDMACallback(ARCallback callback) {
nofralloc
#include "asm/dolphin/ar/ar/ARRegisterDMACallback.s"
}
#pragma pop
#endif
/* 80350598-803505D4 34AED8 003C+00 0/0 2/2 0/0 .text ARGetDMAStatus */
// needs compiler epilogue patch
#ifdef NONMATCHING
u32 ARGetDMAStatus() {
BOOL enabled;
u32 val;
enabled = OSDisableInterrupts();
val = __DSPRegs[5] & 0x0200;
OSRestoreInterrupts(enabled);
return val;
}
#else
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
asm void ARGetDMAStatus() {
asm u32 ARGetDMAStatus(void) {
nofralloc
#include "asm/dolphin/ar/ar/ARGetDMAStatus.s"
}
#pragma pop
#endif
/* 803505D4-803506C4 34AF14 00F0+00 0/0 5/5 0/0 .text ARStartDMA */
// needs compiler epilogue patch
#ifdef NONMATCHING
void ARStartDMA(u32 type, u32 mainmem_addr, u32 aram_addr, u32 length) {
BOOL enabled;
enabled = OSDisableInterrupts();
__DSPRegs[16] = (u16)(__DSPRegs[16] & ~0x3ff) | (u16)(mainmem_addr >> 16);
__DSPRegs[17] = (u16)(__DSPRegs[17] & ~0xffe0) | (u16)(mainmem_addr & 0xffff);
__DSPRegs[18] = (u16)(__DSPRegs[18] & ~0x3ff) | (u16)(aram_addr >> 16);
__DSPRegs[19] = (u16)(__DSPRegs[19] & ~0xffe0) | (u16)(aram_addr & 0xffff);
__DSPRegs[20] = (u16)((__DSPRegs[20] & ~0x8000) | (type << 15));
__DSPRegs[20] = (u16)(__DSPRegs[20] & ~0x3ff) | (u16)(length >> 16);
__DSPRegs[21] = (u16)(__DSPRegs[21] & ~0xffe0) | (u16)(length & 0xffff);
OSRestoreInterrupts(enabled);
}
#else
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
asm void ARStartDMA() {
asm void ARStartDMA(u32 type, u32 mainmem_addr, u32 aram_addr, u32 length) {
nofralloc
#include "asm/dolphin/ar/ar/ARStartDMA.s"
}
#pragma pop
#endif
/* ############################################################################################## */
/* 804518BC-804518C0 000DBC 0004+00 2/1 0/0 0/0 .sbss __AR_Size */
static u8 __AR_Size[4];
static u32 __AR_Size;
/* 804518C0-804518C4 000DC0 0004+00 1/1 0/0 0/0 .sbss __AR_InternalSize */
static u8 __AR_InternalSize[4];
static u32 __AR_InternalSize;
/* 804518C4-804518C8 000DC4 0004+00 1/1 0/0 0/0 .sbss __AR_ExpansionSize */
static u8 __AR_ExpansionSize[4];
static u32 __AR_ExpansionSize;
/* 804518C8-804518CC 000DC8 0004+00 2/2 0/0 0/0 .sbss __AR_StackPointer */
static u8 __AR_StackPointer[4];
static u32 __AR_StackPointer;
/* 804518CC-804518D0 000DCC 0004+00 2/2 0/0 0/0 .sbss __AR_FreeBlocks */
static u8 __AR_FreeBlocks[4];
static u32 __AR_FreeBlocks;
/* 804518D0-804518D4 000DD0 0004+00 2/2 0/0 0/0 .sbss __AR_BlockLength */
static u8 __AR_BlockLength[4];
static u32* __AR_BlockLength;
/* 803506C4-8035072C 34B004 0068+00 0/0 1/1 0/0 .text ARAlloc */
// needs compiler epilogue patch
#ifdef NONMATCHING
u32 ARAlloc(u32 length) {
u32 tmp;
BOOL enabled;
enabled = OSDisableInterrupts();
tmp = __AR_StackPointer;
__AR_StackPointer += length;
*__AR_BlockLength = length;
__AR_BlockLength++;
__AR_FreeBlocks--;
OSRestoreInterrupts(enabled);
return tmp;
}
#else
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
asm u32 ARAlloc(u32) {
asm u32 ARAlloc(u32 length) {
nofralloc
#include "asm/dolphin/ar/ar/ARAlloc.s"
}
#pragma pop
#endif
/* ############################################################################################## */
/* 803D1BE8-803D1C30 02ED08 0044+04 1/0 0/0 0/0 .data @1 */
SECTION_DATA static char lit_1[] = "<< Dolphin SDK - AR\trelease build: Apr 5 2004 04:15:03 (0x2301) >>";
SECTION_DATA static char lit_1[] =
"<< Dolphin SDK - AR\trelease build: Apr 5 2004 04:15:03 (0x2301) >>";
/* 80450A48-80450A50 -00001 0004+04 1/1 0/0 0/0 .sdata __ARVersion */
SECTION_SDATA static void* __ARVersion[1 + 1 /* padding */] = {
(void*)&lit_1,
/* padding */
NULL,
};
SECTION_SDATA static const char* __ARVersion = lit_1;
/* 804518D4-804518D8 000DD4 0004+00 1/1 0/0 0/0 .sbss __AR_init_flag */
static u8 __AR_init_flag[4];
static volatile BOOL __AR_init_flag;
/* 8035072C-803507F0 34B06C 00C4+00 0/0 1/1 0/0 .text ARInit */
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
asm u32 ARInit(u32*, u32) {
asm u32 ARInit(u32* stack_index_addr, u32 num_entries) {
nofralloc
#include "asm/dolphin/ar/ar/ARInit.s"
}
#pragma pop
/* 803507F0-803507F8 -00001 0008+00 0/0 0/0 0/0 .text ARGetSize */
u32 ARGetSize() {
return *(u32*)(&__AR_Size);
u32 ARGetSize(void) {
return __AR_Size;
}
/* 803507F8-80350870 34B138 0078+00 1/1 0/0 0/0 .text __ARHandler */
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
asm void __ARHandler() {
nofralloc
#include "asm/dolphin/ar/ar/__ARHandler.s"
static void __ARHandler(s16 interrupt, OSContext* context) {
OSContext exceptionContext;
u16 tmp;
tmp = __DSPRegs[5];
tmp = (u16)((tmp & ~0x00000088) | 0x20);
__DSPRegs[5] = tmp;
OSClearContext(&exceptionContext);
OSSetCurrentContext(&exceptionContext);
if (__AR_Callback) {
(*__AR_Callback)();
}
OSClearContext(&exceptionContext);
OSSetCurrentContext(context);
}
#pragma pop
/* 80350870-80350890 34B1B0 0020+00 0/0 2/2 0/0 .text __ARClearInterrupt */
#pragma push
+1 -3
View File
@@ -18,8 +18,6 @@ LIBBASE_A_LDFLAGS := \
-proc gekko \
-linkmode moreram \
$(BUILD_DIR)/libs/dolphin/base/PPCArch.o: MWCC_VERSION := 1.2.5
$(BUILD_DIR)/libbase.a: $(LIBBASE_A_O_FILES)
@echo linking... $(BUILD_DIR)/libbase.a
@echo $(LIBBASE_A_O_FILES) > build/LIBBASE_A_ofiles
@@ -29,5 +27,5 @@ $(BUILD_DIR)/libs/dolphin/base/%.o: libs/dolphin/base/%.c
@mkdir -p $(@D)
@echo building... $<
@$(ICONV) -f UTF-8 -t CP932 < $< > $(basename $@).c
@$(CC) $(CFLAGS) $(LIBBASE_A_CFLAGS) -c -o $@ $(basename $@).c
@$(WINE) tools/mwcc_compiler/1.2.5/mwcceppc.exe $(CFLAGS) $(LIBBASE_A_CFLAGS) -c -o $@ $(basename $@).c
+57 -134
View File
@@ -1,248 +1,171 @@
//
// Generated By: dol2asm
// Translation Unit: PPCArch
//
#include "dolphin/base/PPCArch.h"
#include "dol2asm.h"
#include "dolphin/types.h"
//
// Forward References:
//
extern void PPCMfmsr();
extern void PPCMtmsr();
extern void PPCMfhid0();
extern void PPCMthid0();
extern void PPCMfl2cr();
extern void PPCMtl2cr();
extern void PPCMtdec();
extern void PPCSync();
extern void PPCHalt();
extern void PPCMtmmcr0();
extern void PPCMtmmcr1();
extern void PPCMtpmc1();
extern void PPCMtpmc2();
extern void PPCMtpmc3();
extern void PPCMtpmc4();
extern u32 PPCMffpscr();
extern void PPCMtfpscr();
extern void PPCMfhid2();
extern void PPCMthid2();
extern void PPCMtwpar();
extern void PPCDisableSpeculation();
extern void PPCSetFpNonIEEEMode();
//
// External References:
//
//
// Declarations:
//
// clang-format off
/* 80339CC0-80339CC8 -00001 0008+00 0/0 0/0 0/0 .text PPCMfmsr */
asm void PPCMfmsr() {
// clang-format off
asm u32 PPCMfmsr(void) {
nofralloc
mfmsr r3
blr
// clang-format on
}
/* 80339CC8-80339CD0 -00001 0008+00 0/0 0/0 0/0 .text PPCMtmsr */
asm void PPCMtmsr() {
// clang-format off
asm void PPCMtmsr(register u32 newMSR) {
nofralloc
mtmsr r3
mtmsr newMSR
blr
// clang-format on
}
/* 80339CD0-80339CD8 -00001 0008+00 0/0 0/0 0/0 .text PPCMfhid0 */
asm void PPCMfhid0() {
// clang-format off
asm u32 PPCMfhid0(void) {
nofralloc
mfspr r3, 0x3f0
mfspr r3, HID0
blr
// clang-format on
}
/* 80339CD8-80339CE0 -00001 0008+00 0/0 0/0 0/0 .text PPCMthid0 */
asm void PPCMthid0() {
// clang-format off
asm void PPCMthid0(register u32 newHID0) {
nofralloc
mtspr 0x3f0, r3
mtspr HID0, newHID0
blr
// clang-format on
}
/* 80339CE0-80339CE8 -00001 0008+00 0/0 0/0 0/0 .text PPCMfl2cr */
asm void PPCMfl2cr() {
// clang-format off
asm u32 PPCMfl2cr(void) {
nofralloc
mfspr r3, 0x3f9
mfspr r3, L2CR
blr
// clang-format on
}
/* 80339CE8-80339CF0 -00001 0008+00 0/0 0/0 0/0 .text PPCMtl2cr */
asm void PPCMtl2cr() {
// clang-format off
asm void PPCMtl2cr(register u32 newL2cr) {
nofralloc
mtspr 0x3f9, r3
mtspr L2CR, newL2cr
blr
// clang-format on
}
/* 80339CF0-80339CF8 -00001 0008+00 0/0 0/0 0/0 .text PPCMtdec */
asm void PPCMtdec() {
// clang-format off
asm void PPCMtdec(register u32 newDec) {
nofralloc
mtspr 0x16, r3
mtdec newDec
blr
// clang-format on
}
/* 80339CF8-80339D00 -00001 0008+00 0/0 0/0 0/0 .text PPCSync */
asm void PPCSync() {
// clang-format off
asm void PPCSync(void) {
nofralloc
sc
blr
// clang-format on
}
/* 80339D00-80339D14 334640 0014+00 0/0 7/7 0/0 .text PPCHalt */
asm void PPCHalt(void) {
// clang-format off
nofralloc
sync
_spin:
nop
li r3, 0
nop
b _spin
// clang-format on
}
/* 80339D14-80339D1C -00001 0008+00 0/0 0/0 0/0 .text PPCMtmmcr0 */
asm void PPCMtmmcr0() {
// clang-format off
asm void PPCMtmmcr0(register u32 newMmcr0) {
nofralloc
mtspr 0x3b8, r3
mtspr MMCR0, newMmcr0
blr
// clang-format on
}
/* 80339D1C-80339D24 -00001 0008+00 0/0 0/0 0/0 .text PPCMtmmcr1 */
asm void PPCMtmmcr1() {
// clang-format off
asm void PPCMtmmcr1(register u32 newMmcr1) {
nofralloc
mtspr 0x3bc, r3
mtspr MMCR1, newMmcr1
blr
// clang-format on
}
/* 80339D24-80339D2C -00001 0008+00 0/0 0/0 0/0 .text PPCMtpmc1 */
asm void PPCMtpmc1() {
// clang-format off
asm void PPCMtpmc1(register u32 newPmc1) {
nofralloc
mtspr 0x3b9, r3
mtspr PMC1, newPmc1
blr
// clang-format on
}
/* 80339D2C-80339D34 -00001 0008+00 0/0 0/0 0/0 .text PPCMtpmc2 */
asm void PPCMtpmc2() {
// clang-format off
asm void PPCMtpmc2(register u32 newPmc2) {
nofralloc
mtspr 0x3ba, r3
mtspr PMC2, newPmc2
blr
// clang-format on
}
/* 80339D34-80339D3C -00001 0008+00 0/0 0/0 0/0 .text PPCMtpmc3 */
asm void PPCMtpmc3() {
// clang-format off
asm void PPCMtpmc3(register u32 newPmc3) {
nofralloc
mtspr 0x3bd, r3
mtspr PMC3, newPmc3
blr
// clang-format on
}
/* 80339D3C-80339D44 -00001 0008+00 0/0 0/0 0/0 .text PPCMtpmc4 */
asm void PPCMtpmc4() {
// clang-format off
asm void PPCMtpmc4(register u32 newPmc4) {
nofralloc
mtspr 0x3be, r3
mtspr PMC4, newPmc4
blr
// clang-format on
}
/* 80339D44-80339D64 334684 0020+00 0/0 2/2 0/0 .text PPCMffpscr */
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
asm u32 PPCMffpscr() {
nofralloc
#include "asm/dolphin/base/PPCArch/PPCMffpscr.s"
u32 PPCMffpscr(void) {
union FpscrUnion m;
asm {
mffs fp31
stfd fp31, m.f;
}
return m.u.fpscr;
}
#pragma pop
/* 80339D64-80339D8C 3346A4 0028+00 0/0 2/2 0/0 .text PPCMtfpscr */
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
asm void PPCMtfpscr() {
nofralloc
#include "asm/dolphin/base/PPCArch/PPCMtfpscr.s"
void PPCMtfpscr(register u32 newFPSCR) {
union FpscrUnion m;
asm {
li r4, 0
stw r4, m.u.fpscr_pad;
stw newFPSCR, m.u.fpscr
lfd fp31, m.f
mtfsf 0xff, fp31
}
}
#pragma pop
/* 80339D8C-80339D94 -00001 0008+00 0/0 0/0 0/0 .text PPCMfhid2 */
asm void PPCMfhid2() {
// clang-format off
asm u32 PPCMfhid2(void) {
nofralloc
mfspr r3, 0x398
mfspr r3, HID2
blr
// clang-format on
}
/* 80339D94-80339D9C -00001 0008+00 0/0 0/0 0/0 .text PPCMthid2 */
asm void PPCMthid2() {
// clang-format off
asm void PPCMthid2(register u32 newhid2) {
nofralloc
mtspr 0x398, r3
mtspr HID2, newhid2
blr
// clang-format on
}
/* 80339D9C-80339DA4 -00001 0008+00 0/0 0/0 0/0 .text PPCMtwpar */
asm void PPCMtwpar() {
// clang-format off
asm void PPCMtwpar(register u32 newwpar) {
nofralloc
mtspr 0x399, r3
mtspr WPAR, newwpar
blr
// clang-format on
}
/* 80339DA4-80339DCC 3346E4 0028+00 0/0 1/1 0/0 .text PPCDisableSpeculation */
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
asm void PPCDisableSpeculation() {
nofralloc
#include "asm/dolphin/base/PPCArch/PPCDisableSpeculation.s"
void PPCDisableSpeculation(void) {
PPCMthid0(PPCMfhid0() | HID0_SPD);
}
#pragma pop
/* 80339DCC-80339DD4 -00001 0008+00 0/0 0/0 0/0 .text PPCSetFpNonIEEEMode */
asm void PPCSetFpNonIEEEMode() {
// clang-format off
nofralloc
mtfsb1 0x1d
mtfsb1 4*7+1
blr
// clang-format on
}
// clang-format on
File diff suppressed because it is too large Load Diff
+101 -29
View File
@@ -4,80 +4,152 @@
//
#include "dolphin/card/CARDBlock.h"
#include "MSL_C/MSL_Common/Src/string.h"
#include "dol2asm.h"
#include "dolphin/types.h"
#include "dolphin/card/card.h"
#include "dolphin/dsp/dsp.h"
#include "dolphin/dvd/dvd.h"
#include "dolphin/card/CARDPriv.h"
//
// Forward References:
//
void __CARDGetFatBlock();
static void WriteCallback();
static void EraseCallback();
void __CARDAllocBlock();
void __CARDUpdateFatBlock();
//
// External References:
//
SECTION_INIT void memcpy();
void DCStoreRange();
void __CARDEraseSector();
void __CARDPutControlBlock();
void __CARDWrite();
void __CARDCheckSum();
extern u8 __CARDBlock[544];
static void WriteCallback(s32 chan, s32 result);
static void EraseCallback(s32 chan, s32 result);
//
// Declarations:
//
/* 80355414-8035541C 34FD54 0008+00 0/0 5/5 0/0 .text __CARDGetFatBlock */
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
asm void __CARDGetFatBlock() {
nofralloc
#include "asm/dolphin/card/CARDBlock/__CARDGetFatBlock.s"
u16* __CARDGetFatBlock(CARDControl* card) {
return card->currentFat;
}
#pragma pop
/* 8035541C-803554F0 34FD5C 00D4+00 1/1 0/0 0/0 .text WriteCallback */
// needs compiler epilogue patch
#ifdef NONMATCHING
static void WriteCallback(s32 chan, s32 result) {
CARDControl* card;
CARDCallback callback;
u16* fat;
u16* fatBack;
card = &__CARDBlock[chan];
if (result >= 0) {
fat = (u16*)((u8*)card->workArea + 0x6000);
fatBack = (u16*)((u8*)card->workArea + 0x8000);
if (card->currentFat == fat) {
card->currentFat = fatBack;
memcpy(fatBack, fat, 0x2000);
} else {
card->currentFat = fat;
memcpy(fat, fatBack, 0x2000);
}
}
if (card->apiCallback == NULL) {
__CARDPutControlBlock(card, result);
}
callback = card->eraseCallback;
if (callback) {
card->eraseCallback = NULL;
callback(chan, result);
}
}
#else
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
static asm void WriteCallback() {
static asm void WriteCallback(s32 chan, s32 result) {
nofralloc
#include "asm/dolphin/card/CARDBlock/WriteCallback.s"
}
#pragma pop
#endif
/* 803554F0-803555B8 34FE30 00C8+00 1/1 0/0 0/0 .text EraseCallback */
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
static asm void EraseCallback() {
static asm void EraseCallback(s32 chan, s32 result) {
nofralloc
#include "asm/dolphin/card/CARDBlock/EraseCallback.s"
}
#pragma pop
/* 803555B8-803556D0 34FEF8 0118+00 0/0 1/1 0/0 .text __CARDAllocBlock */
// needs compiler epilogue patch
#ifdef NONMATCHING
s32 __CARDAllocBlock(s32 chan, u32 cBlock, CARDCallback callback) {
CARDControl* card;
u16* fat;
u16 iBlock;
u16 startBlock;
u16 prevBlock;
u16 count;
card = &__CARDBlock[chan];
if (!card->attached) {
return CARD_RESULT_NOCARD;
}
fat = __CARDGetFatBlock(card);
if (fat[3] < cBlock) {
return CARD_RESULT_INSSPACE;
}
fat[3] -= cBlock;
startBlock = 0xFFFF;
iBlock = fat[4];
count = 0;
while (0 < cBlock) {
if (card->cBlock - 5 < ++count) {
return CARD_RESULT_BROKEN;
}
iBlock++;
if (!CARDIsValidBlockNo(card, iBlock)) {
iBlock = 5;
}
if (fat[iBlock] == 0x0000u) {
if (startBlock == 0xFFFF) {
startBlock = iBlock;
} else {
fat[prevBlock] = iBlock;
}
prevBlock = iBlock;
fat[iBlock] = 0xFFFF;
--cBlock;
}
}
fat[4] = iBlock;
card->startBlock = startBlock;
return __CARDUpdateFatBlock(chan, fat, callback);
}
#else
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
asm void __CARDAllocBlock() {
asm s32 __CARDAllocBlock(s32 chan, u32 cBlock, CARDCallback callback) {
nofralloc
#include "asm/dolphin/card/CARDBlock/__CARDAllocBlock.s"
}
#pragma pop
#endif
/* 803556D0-8035577C 350010 00AC+00 1/1 1/1 0/0 .text __CARDUpdateFatBlock */
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
asm void __CARDUpdateFatBlock() {
asm s32 __CARDUpdateFatBlock(s32 chan, u16* fat, CARDCallback callback) {
nofralloc
#include "asm/dolphin/card/CARDBlock/__CARDUpdateFatBlock.s"
}
+202 -41
View File
@@ -4,60 +4,59 @@
//
#include "dolphin/card/CARDCheck.h"
#include "MSL_C/MSL_Common/Src/string.h"
#include "dol2asm.h"
#include "dolphin/types.h"
#include "dolphin/card/card.h"
#include "dolphin/dsp/dsp.h"
#include "dolphin/dvd/dvd.h"
#include "dolphin/card/CARDPriv.h"
//
// Forward References:
//
void __CARDCheckSum();
static void VerifyID();
static void VerifyDir();
static void VerifyFAT();
void __CARDVerify();
static void CARDCheckExAsync();
void CARDCheck();
static s32 VerifyID(CARDControl* card);
static s32 VerifyDir(CARDControl* card, int* outCurrent);
static s32 VerifyFAT(CARDControl* card, int* outCurrent);
//
// External References:
//
SECTION_INIT void memset();
SECTION_INIT void memcpy();
void OSDisableInterrupts();
void OSRestoreInterrupts();
void __OSLockSramEx();
void __OSUnlockSramEx();
void __CARDSyncCallback();
void __CARDGetFontEncode();
void __CARDGetControlBlock();
void __CARDPutControlBlock();
void __CARDSync();
void __CARDUpdateFatBlock();
void __CARDUpdateDir();
void __shr2i();
extern u8 __CARDBlock[544];
//
// Declarations:
//
/* 803559E0-80355B90 350320 01B0+00 0/0 3/3 0/0 .text __CARDCheckSum */
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
asm void __CARDCheckSum() {
nofralloc
#include "asm/dolphin/card/CARDCheck/__CARDCheckSum.s"
void __CARDCheckSum(void* ptr, int length, u16* checksum, u16* checksumInv) {
u16* p;
int i;
length /= sizeof(u16);
*checksum = *checksumInv = 0;
for (i = 0, p = ptr; i < length; i++, p++) {
*checksum += *p;
*checksumInv += ~*p;
}
if (*checksum == 0xFFFF) {
*checksum = 0;
}
if (*checksumInv == 0xFFFF) {
*checksumInv = 0;
}
}
#pragma pop
/* 80355B90-80355E14 3504D0 0284+00 2/2 0/0 0/0 .text VerifyID */
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
static asm void VerifyID() {
static asm s32 VerifyID(CARDControl* card) {
nofralloc
#include "asm/dolphin/card/CARDCheck/VerifyID.s"
}
@@ -67,7 +66,7 @@ static asm void VerifyID() {
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
static asm void VerifyDir() {
static asm s32 VerifyDir(CARDControl* card, int* outCurrent) {
nofralloc
#include "asm/dolphin/card/CARDCheck/VerifyDir.s"
}
@@ -77,38 +76,200 @@ static asm void VerifyDir() {
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
static asm void VerifyFAT() {
static asm s32 VerifyFAT(CARDControl* card, int* outCurrent) {
nofralloc
#include "asm/dolphin/card/CARDCheck/VerifyFAT.s"
}
#pragma pop
/* 803562D8-80356364 350C18 008C+00 0/0 1/1 0/0 .text __CARDVerify */
// needs compiler epilogue patch
#ifdef NONMATCHING
s32 __CARDVerify(CARDControl* card) {
s32 result;
int errors;
result = VerifyID(card);
if (result < 0) {
return result;
}
errors = VerifyDir(card, NULL);
errors += VerifyFAT(card, NULL);
switch (errors) {
case 0:
return CARD_RESULT_READY;
case 1:
return CARD_RESULT_BROKEN;
default:
return CARD_RESULT_BROKEN;
}
}
#else
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
asm void __CARDVerify() {
asm s32 __CARDVerify(CARDControl* card) {
nofralloc
#include "asm/dolphin/card/CARDCheck/__CARDVerify.s"
}
#pragma pop
#endif
/* 80356364-803568F4 350CA4 0590+00 1/1 0/0 0/0 .text CARDCheckExAsync */
#ifdef NONMATCHING
s32 CARDCheckExAsync(s32 chan, s32* xferBytes, CARDCallback callback) {
CARDControl* card;
CARDDir* dir[2];
u16* fat[2];
u16* map;
s32 result;
int errors;
int currentFat;
int currentDir;
s32 fileNo;
u16 iBlock;
u16 cBlock;
u16 cFree;
BOOL updateFat = FALSE;
BOOL updateDir = FALSE;
BOOL updateOrphan = FALSE;
if (xferBytes) {
*xferBytes = 0;
}
result = __CARDGetControlBlock(chan, &card);
if (result < 0) {
return result;
}
result = VerifyID(card);
if (result < 0) {
return __CARDPutControlBlock(card, result);
}
errors = VerifyDir(card, &currentDir);
errors += VerifyFAT(card, &currentFat);
if (1 < errors) {
return __CARDPutControlBlock(card, CARD_RESULT_BROKEN);
}
dir[0] = (CARDDir*)((u8*)card->workArea + (1 + 0) * CARD_SYSTEM_BLOCK_SIZE);
dir[1] = (CARDDir*)((u8*)card->workArea + (1 + 1) * CARD_SYSTEM_BLOCK_SIZE);
fat[0] = (u16*)((u8*)card->workArea + (3 + 0) * CARD_SYSTEM_BLOCK_SIZE);
fat[1] = (u16*)((u8*)card->workArea + (3 + 1) * CARD_SYSTEM_BLOCK_SIZE);
switch (errors) {
case 0:
break;
case 1:
if (!card->currentDir) {
card->currentDir = dir[currentDir];
memcpy(dir[currentDir], dir[currentDir ^ 1], CARD_SYSTEM_BLOCK_SIZE);
updateDir = TRUE;
} else {
card->currentFat = fat[currentFat];
memcpy(fat[currentFat], fat[currentFat ^ 1], CARD_SYSTEM_BLOCK_SIZE);
updateFat = TRUE;
}
break;
}
map = fat[currentFat ^ 1];
memset(map, 0, CARD_SYSTEM_BLOCK_SIZE);
for (fileNo = 0; fileNo < CARD_MAX_FILE; fileNo++) {
CARDDir* ent;
ent = &card->currentDir[fileNo];
if (ent->gameName[0] == 0xff) {
continue;
}
for (iBlock = ent->startBlock, cBlock = 0; iBlock != 0xFFFF && cBlock < ent->length;
iBlock = card->currentFat[iBlock], ++cBlock) {
if (!CARDIsValidBlockNo(card, iBlock) || 1 < ++map[iBlock]) {
return __CARDPutControlBlock(card, CARD_RESULT_BROKEN);
}
}
if (cBlock != ent->length || iBlock != 0xFFFF) {
return __CARDPutControlBlock(card, CARD_RESULT_BROKEN);
}
}
cFree = 0;
for (iBlock = CARD_NUM_SYSTEM_BLOCK; iBlock < card->cBlock; iBlock++) {
u16 nextBlock;
nextBlock = card->currentFat[iBlock];
if (map[iBlock] == 0) {
if (nextBlock != CARD_FAT_AVAIL) {
card->currentFat[iBlock] = CARD_FAT_AVAIL;
updateOrphan = TRUE;
}
cFree++;
} else if (!CARDIsValidBlockNo(card, nextBlock) && nextBlock != 0xFFFF) {
return __CARDPutControlBlock(card, CARD_RESULT_BROKEN);
}
}
if (cFree != card->currentFat[CARD_FAT_FREEBLOCKS]) {
card->currentFat[CARD_FAT_FREEBLOCKS] = cFree;
updateOrphan = TRUE;
}
if (updateOrphan) {
__CARDCheckSum(&card->currentFat[CARD_FAT_CHECKCODE], CARD_SYSTEM_BLOCK_SIZE - sizeof(u32),
&card->currentFat[CARD_FAT_CHECKSUM],
&card->currentFat[CARD_FAT_CHECKSUMINV]);
}
memcpy(fat[currentFat ^ 1], fat[currentFat], CARD_SYSTEM_BLOCK_SIZE);
if (updateDir) {
if (xferBytes) {
*xferBytes = CARD_SYSTEM_BLOCK_SIZE;
}
return __CARDUpdateDir(chan, callback);
}
if (updateFat | updateOrphan) {
if (xferBytes) {
*xferBytes = CARD_SYSTEM_BLOCK_SIZE;
}
return __CARDUpdateFatBlock(chan, card->currentFat, callback);
}
__CARDPutControlBlock(card, CARD_RESULT_READY);
if (callback) {
BOOL enabled = OSDisableInterrupts();
callback(chan, CARD_RESULT_READY);
OSRestoreInterrupts(enabled);
}
return CARD_RESULT_READY;
}
#else
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
static asm void CARDCheckExAsync() {
static asm s32 CARDCheckExAsync(s32 chan, s32* xferBytes, CARDCallback callback) {
nofralloc
#include "asm/dolphin/card/CARDCheck/CARDCheckExAsync.s"
}
#pragma pop
#endif
/* 803568F4-80356948 351234 0054+00 0/0 2/2 0/0 .text CARDCheck */
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
asm void CARDCheck() {
nofralloc
#include "asm/dolphin/card/CARDCheck/CARDCheck.s"
s32 CARDCheck(s32 chan) {
s32 xferBytes;
s32 result = CARDCheckExAsync(chan, &xferBytes, __CARDSyncCallback);
if (result >= 0) {
if (&xferBytes == NULL) {
return result;
}
return __CARDSync(chan);
}
return result;
}
#pragma pop
+120 -54
View File
@@ -4,69 +4,135 @@
//
#include "dolphin/card/CARDCreate.h"
#include "MSL_C/MSL_Common/Src/mem.h"
#include "MSL_C/MSL_Common/Src/string.h"
#include "dol2asm.h"
#include "dolphin/types.h"
#include "dolphin/card/card.h"
#include "dolphin/dsp/dsp.h"
#include "dolphin/dvd/dvd.h"
//
// Forward References:
//
#include "dolphin/card/CARDPriv.h"
static void CreateCallbackFat();
static void CARDCreateAsync();
void CARDCreate();
//
// External References:
//
SECTION_INIT void memcpy();
void OSGetTime();
void __CARDDefaultApiCallback();
void __CARDSyncCallback();
void __CARDGetControlBlock();
void __CARDPutControlBlock();
void __CARDSync();
void __CARDGetFatBlock();
void __CARDAllocBlock();
void __CARDGetDirBlock();
void __CARDUpdateDir();
void __CARDCompareFileName();
void __div2i();
void memcmp();
void strncpy();
void strlen();
extern u8 __CARDBlock[544];
//
// Declarations:
//
static void CreateCallbackFat(s32 chan, s32 result);
/* 80358108-80358238 352A48 0130+00 1/1 0/0 0/0 .text CreateCallbackFat */
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
static asm void CreateCallbackFat() {
nofralloc
#include "asm/dolphin/card/CARDCreate/CreateCallbackFat.s"
static void CreateCallbackFat(s32 chan, s32 result) {
CARDControl* card;
CARDDir* dir;
CARDDir* ent;
CARDCallback callback;
card = &__CARDBlock[chan];
callback = card->apiCallback;
card->apiCallback = 0;
if (result < 0) {
goto error;
}
dir = __CARDGetDirBlock(card);
ent = &dir[card->freeNo];
memcpy(ent->gameName, card->diskID->game_name, sizeof(ent->gameName));
memcpy(ent->company, card->diskID->company, sizeof(ent->company));
ent->permission = CARD_ATTR_PUBLIC;
ent->copyTimes = 0;
ent->startBlock = card->startBlock;
ent->bannerFormat = 0;
ent->iconAddr = 0xFFFFFFFF;
ent->iconFormat = 0;
ent->iconSpeed = 0;
ent->commentAddr = 0xFFFFFFFF;
CARDSetIconSpeed(ent, 0, CARD_STAT_SPEED_FAST);
card->fileInfo->offset = 0;
card->fileInfo->iBlock = ent->startBlock;
ent->time = (u32)OSTicksToSeconds(OSGetTime());
result = __CARDUpdateDir(chan, callback);
if (result < 0) {
goto error;
}
return;
error:
__CARDPutControlBlock(card, result);
if (callback) {
callback(chan, result);
}
}
#pragma pop
/* 80358238-80358458 352B78 0220+00 1/1 0/0 0/0 .text CARDCreateAsync */
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
static asm void CARDCreateAsync() {
nofralloc
#include "asm/dolphin/card/CARDCreate/CARDCreateAsync.s"
s32 CARDCreateAsync(s32 chan, const char* fileName, u32 size, CARDFileInfo* fileInfo,
CARDCallback callback) {
CARDControl* card;
CARDDir* dir;
CARDDir* ent;
s32 result;
u16 fileNo;
u16 freeNo;
u16* fat;
if (strlen(fileName) > (u32)CARD_FILENAME_MAX) {
return CARD_RESULT_NAMETOOLONG;
}
result = __CARDGetControlBlock(chan, &card);
if (result < 0) {
return result;
}
if (size <= 0 || (size % card->sectorSize) != 0) {
return CARD_RESULT_FATAL_ERROR;
}
freeNo = (u16)-1;
dir = __CARDGetDirBlock(card);
for (fileNo = 0; fileNo < CARD_MAX_FILE; fileNo++) {
ent = &dir[fileNo];
if (ent->gameName[0] == 0xff) {
if (freeNo == (u16)-1) {
freeNo = fileNo;
}
} else if (memcmp(ent->gameName, card->diskID->game_name, sizeof(ent->gameName)) == 0 &&
memcmp(ent->company, card->diskID->company, sizeof(ent->company)) == 0 &&
__CARDCompareFileName(ent, fileName)) {
return __CARDPutControlBlock(card, CARD_RESULT_EXIST);
}
}
if (freeNo == (u16)-1) {
return __CARDPutControlBlock(card, CARD_RESULT_NOENT);
}
fat = __CARDGetFatBlock(card);
if (card->sectorSize * fat[CARD_FAT_FREEBLOCKS] < size) {
return __CARDPutControlBlock(card, CARD_RESULT_INSSPACE);
}
card->apiCallback = callback ? callback : __CARDDefaultApiCallback;
card->freeNo = freeNo;
ent = &dir[freeNo];
ent->length = (u16)(size / card->sectorSize);
strncpy((char*)ent->fileName, fileName, CARD_FILENAME_MAX);
card->fileInfo = fileInfo;
fileInfo->chan = chan;
fileInfo->fileNo = freeNo;
result = __CARDAllocBlock(chan, size / card->sectorSize, CreateCallbackFat);
if (result < 0) {
return __CARDPutControlBlock(card, result);
}
return result;
}
#pragma pop
/* 80358458-803584A0 352D98 0048+00 0/0 1/1 0/0 .text CARDCreate */
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
asm void CARDCreate() {
nofralloc
#include "asm/dolphin/card/CARDCreate/CARDCreate.s"
s32 CARDCreate(s32 chan, const char* fileName, u32 size, CARDFileInfo* fileInfo) {
s32 result = CARDCreateAsync(chan, fileName, size, fileInfo, __CARDSyncCallback);
if (result < 0) {
return result;
}
return __CARDSync(chan);
}
#pragma pop
+104 -30
View File
@@ -4,70 +4,144 @@
//
#include "dolphin/card/CARDDir.h"
#include "MSL_C/MSL_Common/Src/string.h"
#include "dol2asm.h"
#include "dolphin/types.h"
#include "dolphin/card/card.h"
#include "dolphin/dsp/dsp.h"
#include "dolphin/dvd/dvd.h"
//
// Forward References:
//
#include "dolphin/card/CARDPriv.h"
void __CARDGetDirBlock();
static void WriteCallback();
static void EraseCallback();
void __CARDUpdateDir();
//
// External References:
//
SECTION_INIT void memcpy();
void DCStoreRange();
void __CARDEraseSector();
void __CARDPutControlBlock();
void __CARDWrite();
void __CARDCheckSum();
extern u8 __CARDBlock[544];
static void WriteCallback(s32 chan, s32 result);
static void EraseCallback(s32 chan, s32 result);
//
// Declarations:
//
/* 8035577C-80355784 3500BC 0008+00 0/0 10/10 0/0 .text __CARDGetDirBlock */
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
asm void __CARDGetDirBlock() {
nofralloc
#include "asm/dolphin/card/CARDDir/__CARDGetDirBlock.s"
CARDDir* __CARDGetDirBlock(CARDControl* card) {
return card->currentDir;
}
#pragma pop
/* 80355784-80355854 3500C4 00D0+00 1/1 0/0 0/0 .text WriteCallback */
// needs compiler epilogue patch
#ifdef NONMATCHING
static void WriteCallback(s32 chan, s32 result) {
CARDControl* card;
CARDCallback callback;
card = &__CARDBlock[chan];
if (0 <= result) {
CARDDir* dir0 = (CARDDir*)((u8*)card->workArea + 0x2000);
CARDDir* dir1 = (CARDDir*)((u8*)card->workArea + 0x4000);
if (card->currentDir == dir0) {
card->currentDir = dir1;
memcpy(dir1, dir0, 0x2000);
} else {
card->currentDir = dir0;
memcpy(dir0, dir1, 0x2000);
}
}
error:
if (card->apiCallback == 0) {
__CARDPutControlBlock(card, result);
}
callback = card->eraseCallback;
if (callback) {
card->eraseCallback = 0;
callback(chan, result);
}
}
#else
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
static asm void WriteCallback() {
static asm void WriteCallback(s32 chan, s32 result) {
nofralloc
#include "asm/dolphin/card/CARDDir/WriteCallback.s"
}
#pragma pop
#endif
/* 80355854-8035591C 350194 00C8+00 1/1 0/0 0/0 .text EraseCallback */
// needs compiler epilogue patch
#ifdef NONMATCHING
static void EraseCallback(s32 chan, s32 result) {
CARDControl* card;
CARDCallback callback;
CARDDir* dir;
u32 tmp[2];
u32 addr;
card = &__CARDBlock[chan];
if (result < 0) {
goto error;
}
dir = __CARDGetDirBlock(card);
addr = ((u32)dir - (u32)card->workArea) / 0x2000 * card->sectorSize;
result = __CARDWrite(chan, addr, 0x2000, dir, WriteCallback);
if (result < 0) {
goto error;
}
return;
error:
if (card->apiCallback == 0) {
__CARDPutControlBlock(card, result);
}
callback = card->eraseCallback;
if (callback) {
card->eraseCallback = 0;
callback(chan, result);
}
}
#else
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
static asm void EraseCallback() {
static asm void EraseCallback(s32 chan, s32 result) {
nofralloc
#include "asm/dolphin/card/CARDDir/EraseCallback.s"
}
#pragma pop
#endif
/* 8035591C-803559E0 35025C 00C4+00 0/0 4/4 0/0 .text __CARDUpdateDir */
#ifdef NONMATCHING
s32 __CARDUpdateDir(s32 chan, CARDCallback callback) {
CARDControl* card;
CARDDirCheck* check;
u32 tmp[2];
u32 addr;
CARDDir* dir;
card = &__CARDBlock[chan];
if (!card->attached) {
return CARD_RESULT_NOCARD;
}
dir = __CARDGetDirBlock(card);
check = __CARDGetDirCheck(dir);
++check->checkCode;
__CARDCheckSum(dir, 0x2000 - sizeof(u32), &check->checkSum, &check->checkSumInv);
DCStoreRange(dir, 0x2000);
card->eraseCallback = callback;
addr = ((u32)dir - (u32)card->workArea) / 0x2000 * card->sectorSize;
return __CARDEraseSector(chan, addr, EraseCallback);
}
#else
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
asm void __CARDUpdateDir() {
asm s32 __CARDUpdateDir(s32 chan, CARDCallback callback) {
nofralloc
#include "asm/dolphin/card/CARDDir/__CARDUpdateDir.s"
}
#pragma pop
#endif
+57 -31
View File
@@ -4,71 +4,97 @@
//
#include "dolphin/card/CARDFormat.h"
#include "MSL_C/MSL_Common/Src/string.h"
#include "dol2asm.h"
#include "dolphin/types.h"
#include "dolphin/card/card.h"
#include "dolphin/dsp/dsp.h"
#include "dolphin/dvd/dvd.h"
#include "dolphin/card/CARDPriv.h"
//
// Forward References:
//
static void FormatCallback();
void __CARDFormatRegionAsync();
void CARDFormat();
static void FormatCallback(s32 chan, s32 result);
//
// External References:
//
SECTION_INIT void memset();
SECTION_INIT void memcpy();
void DCStoreRange();
void __OSLockSram();
void __OSLockSramEx();
void __OSUnlockSram();
void __OSUnlockSramEx();
void OSGetTime();
void __CARDDefaultApiCallback();
void __CARDSyncCallback();
void __CARDEraseSector();
void __CARDGetFontEncode();
void __CARDGetControlBlock();
void __CARDPutControlBlock();
void __CARDSync();
void __CARDWrite();
void __CARDCheckSum();
void __shr2i();
extern u8 __CARDBlock[544];
//
// Declarations:
//
/* 80357484-803575C8 351DC4 0144+00 1/1 0/0 0/0 .text FormatCallback */
// needs compiler epilogue patch
#ifdef NONMATCHING
static void FormatCallback(s32 chan, s32 result) {
CARDControl* card;
CARDCallback callback;
card = &__CARDBlock[chan];
if (result < 0) {
goto error;
}
++card->formatStep;
if (card->formatStep < CARD_NUM_SYSTEM_BLOCK) {
result = __CARDEraseSector(chan, (u32)card->sectorSize * card->formatStep, FormatCallback);
if (0 <= result) {
return;
}
} else if (card->formatStep < 2 * CARD_NUM_SYSTEM_BLOCK) {
int step = card->formatStep - CARD_NUM_SYSTEM_BLOCK;
result = __CARDWrite(chan, (u32)card->sectorSize * step, CARD_SYSTEM_BLOCK_SIZE,
(u8*)card->workArea + (CARD_SYSTEM_BLOCK_SIZE * step), FormatCallback);
if (result >= 0) {
return;
}
} else {
card->currentDir = (CARDDir*)((u8*)card->workArea + (1 + 0) * CARD_SYSTEM_BLOCK_SIZE);
memcpy(card->currentDir, (u8*)card->workArea + (1 + 1) * CARD_SYSTEM_BLOCK_SIZE,
CARD_SYSTEM_BLOCK_SIZE);
card->currentFat = (u16*)((u8*)card->workArea + (3 + 0) * CARD_SYSTEM_BLOCK_SIZE);
memcpy(card->currentFat, (u8*)card->workArea + (3 + 1) * CARD_SYSTEM_BLOCK_SIZE,
CARD_SYSTEM_BLOCK_SIZE);
}
error:
callback = card->apiCallback;
card->apiCallback = 0;
__CARDPutControlBlock(card, result);
callback(chan, result);
}
#else
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
static asm void FormatCallback() {
static asm void FormatCallback(s32 chan, s32 result) {
nofralloc
#include "asm/dolphin/card/CARDFormat/FormatCallback.s"
}
#pragma pop
#endif
/* 803575C8-80357C20 351F08 0658+00 1/1 0/0 0/0 .text __CARDFormatRegionAsync */
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
asm void __CARDFormatRegionAsync() {
asm s32 __CARDFormatRegionAsync(s32 chan, u16 encode, CARDCallback callback) {
nofralloc
#include "asm/dolphin/card/CARDFormat/__CARDFormatRegionAsync.s"
}
#pragma pop
/* 80357C20-80357C74 352560 0054+00 0/0 1/1 0/0 .text CARDFormat */
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
asm void CARDFormat() {
nofralloc
#include "asm/dolphin/card/CARDFormat/CARDFormat.s"
s32 CARDFormat(s32 chan) {
s32 result = __CARDFormatRegionAsync(chan, __CARDGetFontEncode(), __CARDSyncCallback);
if (result < 0) {
return result;
}
return __CARDSync(chan);
}
#pragma pop
+243 -93
View File
@@ -5,59 +5,22 @@
#include "dolphin/card/CARDMount.h"
#include "dol2asm.h"
#include "dolphin/types.h"
#include "dolphin/card/card.h"
#include "dolphin/dsp/dsp.h"
#include "dolphin/dvd/dvd.h"
#include "dolphin/exi/EXIBios.h"
#include "dolphin/card/CARDPriv.h"
u8 GameChoice : 0x800030E3;
//
// Forward References:
//
static void IsCard();
void CARDProbe();
void CARDProbeEx();
static void DoMount();
void __CARDMountCallback();
static void CARDMountAsync();
void CARDMount();
static void DoUnmount();
void CARDUnmount();
//
// External References:
//
void OSCancelAlarm();
void DCInvalidateRange();
void OSDisableInterrupts();
void OSRestoreInterrupts();
void __OSLockSramEx();
void __OSUnlockSramEx();
void EXISetExiCallback();
void EXIProbe();
void EXIProbeEx();
void EXIAttach();
void EXIDetach();
void EXILock();
void EXIUnlock();
void EXIGetState();
void EXIGetID();
void __CARDDefaultApiCallback();
void __CARDSyncCallback();
void __CARDExtHandler();
void __CARDExiHandler();
void __CARDUnlockedHandler();
void __CARDEnableInterrupt();
void __CARDReadStatus();
void __CARDReadVendorID();
void __CARDClearStatus();
void __CARDGetControlBlock();
void __CARDPutControlBlock();
void __CARDSync();
void CARDGetFastMode();
void __CARDUnlock();
void __CARDRead();
void __CARDVerify();
extern u8 __CARDBlock[544];
extern u8 struct_80450A70[8];
static BOOL IsCard(u32 id);
static s32 DoMount(s32 chan);
static void DoUnmount(s32 chan, s32 result);
//
// Declarations:
@@ -65,103 +28,290 @@ extern u8 struct_80450A70[8];
/* ############################################################################################## */
/* 803D2000-803D2020 02F120 0020+00 3/3 0/0 0/0 .data SectorSizeTable */
SECTION_DATA static u8 SectorSizeTable[32] = {
0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x01, 0x00, 0x00,
0x00, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
static u32 SectorSizeTable[8] = {
8 * 1024, 16 * 1024, 32 * 1024, 64 * 1024, 128 * 1024, 256 * 1024, 0, 0,
};
/* 80356948-80356A14 351288 00CC+00 2/2 0/0 0/0 .text IsCard */
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
static asm void IsCard() {
nofralloc
#include "asm/dolphin/card/CARDMount/IsCard.s"
static BOOL IsCard(u32 id) {
u32 size;
s32 sectorSize;
if (id & (0xFFFF0000) && (id != 0x80000004 || __CARDVendorID == 0xFFFF)) {
return FALSE;
}
if ((id & 3) != 0) {
return FALSE;
}
size = id & 0xfc;
switch (size) {
case 4:
case 8:
case 16:
case 32:
case 64:
case 128:
break;
default:
return FALSE;
break;
}
sectorSize = SectorSizeTable[(id & 0x00003800) >> 11];
if (sectorSize == 0) {
return FALSE;
}
if ((size * 1024 * 1024 / 8) / sectorSize < 8) {
return FALSE;
}
return TRUE;
}
#pragma pop
/* 80356A14-80356A4C 351354 0038+00 0/0 1/1 0/0 .text CARDProbe */
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
asm void CARDProbe() {
nofralloc
#include "asm/dolphin/card/CARDMount/CARDProbe.s"
s32 CARDProbe(s32 chan) {
s32 result;
if (GameChoice & 0x80) {
result = 0;
} else {
result = EXIProbe(chan);
}
return result;
}
#pragma pop
/* 80356A4C-80356BC8 35138C 017C+00 0/0 1/1 0/0 .text CARDProbeEx */
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
asm void CARDProbeEx() {
nofralloc
#include "asm/dolphin/card/CARDMount/CARDProbeEx.s"
s32 CARDProbeEx(s32 chan, s32* memSize, s32* sectorSize) {
u32 id;
CARDControl* card;
BOOL enabled;
s32 result;
int probe;
if (chan < 0 || 2 <= chan) {
return CARD_RESULT_FATAL_ERROR;
}
if (GameChoice & 0x80) {
return CARD_RESULT_NOCARD;
}
card = &__CARDBlock[chan];
enabled = OSDisableInterrupts();
probe = EXIProbeEx(chan);
if (probe == -1) {
result = CARD_RESULT_NOCARD;
} else if (probe == 0) {
result = CARD_RESULT_BUSY;
} else if (card->attached) {
if (card->mountStep < 1) {
result = CARD_RESULT_BUSY;
} else {
if (memSize) {
*memSize = card->size;
}
if (sectorSize) {
*sectorSize = card->sectorSize;
}
result = CARD_RESULT_READY;
}
} else if ((EXIGetState(chan) & 8)) {
result = CARD_RESULT_WRONGDEVICE;
} else if (!EXIGetID(chan, 0, &id)) {
result = CARD_RESULT_BUSY;
} else if (IsCard(id)) {
if (memSize) {
*memSize = (s32)(id & 0xfc);
}
if (sectorSize) {
*sectorSize = SectorSizeTable[(id & 0x00003800) >> 11];
}
result = CARD_RESULT_READY;
} else {
result = CARD_RESULT_WRONGDEVICE;
}
OSRestoreInterrupts(enabled);
return result;
}
#pragma pop
/* ############################################################################################## */
/* 803D2020-803D2040 02F140 0020+00 1/1 0/0 0/0 .data LatencyTable */
SECTION_DATA static u8 LatencyTable[32] = {
0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x20,
0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00,
static u32 LatencyTable[8] = {
4, 8, 16, 32, 64, 128, 256, 512,
};
/* 80356BC8-8035701C 351508 0454+00 2/2 0/0 0/0 .text DoMount */
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
static asm void DoMount() {
static asm s32 DoMount(s32 chan) {
nofralloc
#include "asm/dolphin/card/CARDMount/DoMount.s"
}
#pragma pop
/* 8035701C-80357154 35195C 0138+00 2/2 1/1 0/0 .text __CARDMountCallback */
// needs compiler epilogue patch
#ifdef NONMATCHING
void __CARDMountCallback(s32 chan, s32 result) {
CARDControl* card;
CARDCallback callback;
card = &__CARDBlock[chan];
switch (result) {
case CARD_RESULT_READY:
if (++card->mountStep < CARD_MAX_MOUNT_STEP) {
result = DoMount(chan);
if (0 <= result) {
return;
}
} else {
result = __CARDVerify(card);
}
break;
case CARD_RESULT_UNLOCKED:
card->unlockCallback = __CARDMountCallback;
if (!EXILock(chan, 0, __CARDUnlockedHandler)) {
return;
}
card->unlockCallback = 0;
result = DoMount(chan);
if (0 <= result) {
return;
}
break;
case CARD_RESULT_IOERROR:
case CARD_RESULT_NOCARD:
DoUnmount(chan, result);
break;
}
callback = card->apiCallback;
card->apiCallback = 0;
__CARDPutControlBlock(card, result);
callback(chan, result);
}
#else
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
asm void __CARDMountCallback() {
asm void __CARDMountCallback(s32 chan, s32 result) {
nofralloc
#include "asm/dolphin/card/CARDMount/__CARDMountCallback.s"
}
#pragma pop
#endif
/* 80357154-803572F4 351A94 01A0+00 1/1 0/0 0/0 .text CARDMountAsync */
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
static asm void CARDMountAsync() {
nofralloc
#include "asm/dolphin/card/CARDMount/CARDMountAsync.s"
s32 CARDMountAsync(s32 chan, void* workArea, CARDCallback detachCallback,
CARDCallback attachCallback) {
CARDControl* card;
BOOL enabled;
if (chan < 0 || 2 <= chan) {
return CARD_RESULT_FATAL_ERROR;
}
if (GameChoice & 0x80) {
return CARD_RESULT_NOCARD;
}
card = &__CARDBlock[chan];
enabled = OSDisableInterrupts();
if (card->result == CARD_RESULT_BUSY) {
OSRestoreInterrupts(enabled);
return CARD_RESULT_BUSY;
}
if (!card->attached && (EXIGetState(chan) & 0x08)) {
OSRestoreInterrupts(enabled);
return CARD_RESULT_WRONGDEVICE;
}
card->result = CARD_RESULT_BUSY;
card->workArea = workArea;
card->extCallback = detachCallback;
card->apiCallback = attachCallback ? attachCallback : __CARDDefaultApiCallback;
card->exiCallback = 0;
if (!card->attached && !EXIAttach(chan, __CARDExtHandler)) {
card->result = CARD_RESULT_NOCARD;
OSRestoreInterrupts(enabled);
return CARD_RESULT_NOCARD;
}
card->mountStep = 0;
card->attached = TRUE;
EXISetExiCallback(chan, 0);
OSCancelAlarm(&card->alarm);
card->currentDir = 0;
card->currentFat = 0;
OSRestoreInterrupts(enabled);
card->unlockCallback = __CARDMountCallback;
if (!EXILock(chan, 0, __CARDUnlockedHandler)) {
return CARD_RESULT_READY;
}
card->unlockCallback = 0;
return DoMount(chan);
}
#pragma pop
/* 803572F4-8035733C 351C34 0048+00 0/0 1/1 0/0 .text CARDMount */
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
asm void CARDMount() {
nofralloc
#include "asm/dolphin/card/CARDMount/CARDMount.s"
s32 CARDMount(s32 chan, void* workArea, CARDCallback attachCb) {
s32 result = CARDMountAsync(chan, workArea, attachCb, __CARDSyncCallback);
if (result < 0) {
return result;
}
return __CARDSync(chan);
}
#pragma pop
/* 8035733C-803573D8 351C7C 009C+00 2/2 0/0 0/0 .text DoUnmount */
// needs compiler epilogue patch
#ifdef NONMATCHING
static void DoUnmount(s32 chan, s32 result) {
CARDControl* card;
BOOL enabled;
card = &__CARDBlock[chan];
enabled = OSDisableInterrupts();
if (card->attached) {
EXISetExiCallback(chan, 0);
EXIDetach(chan);
OSCancelAlarm(&card->alarm);
card->attached = FALSE;
card->result = result;
card->mountStep = 0;
}
OSRestoreInterrupts(enabled);
}
#else
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
static asm void DoUnmount() {
static asm void DoUnmount(s32 chan, s32 result) {
nofralloc
#include "asm/dolphin/card/CARDMount/DoUnmount.s"
}
#pragma pop
#endif
/* 803573D8-80357484 351D18 00AC+00 0/0 2/2 0/0 .text CARDUnmount */
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
asm void CARDUnmount() {
asm s32 CARDUnmount(s32 chan) {
nofralloc
#include "asm/dolphin/card/CARDMount/CARDUnmount.s"
}
+31 -39
View File
@@ -5,48 +5,40 @@
#include "dolphin/card/CARDNet.h"
#include "dol2asm.h"
#include "dolphin/types.h"
#include "dolphin/card/card.h"
#include "dolphin/dsp/dsp.h"
#include "dolphin/dvd/dvd.h"
//
// Forward References:
//
#include "dolphin/card/CARDPriv.h"
void CARDGetSerialNo();
extern u8 struct_80450A70[8];
/* 80450A70 0002+00 data_80450A70 __CARDVendorID */
SECTION_SDATA u16 __CARDVendorID = 0xFFFF;
//
// External References:
//
void __CARDGetControlBlock();
void __CARDPutControlBlock();
//
// Declarations:
//
/* 80450A72 0006+00 data_80450A72 None */
SECTION_SDATA u8 data_80450A72 = 0x1C;
/* 80359158-8035921C 353A98 00C4+00 0/0 1/1 0/0 .text CARDGetSerialNo */
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
asm void CARDGetSerialNo() {
nofralloc
#include "asm/dolphin/card/CARDNet/CARDGetSerialNo.s"
}
#pragma pop
s32 CARDGetSerialNo(s32 chan, u64* serialNo) {
CARDControl* card;
CARDID* id;
int i;
u64 code;
s32 result;
/* ############################################################################################## */
/* 80450A70-80450A78 -00001 0008+00 0/0 4/4 0/0 .sdata None */
SECTION_SDATA extern u8 struct_80450A70[8];
SECTION_SDATA u8 struct_80450A70[8] = {
/* 80450A70 0002+00 data_80450A70 __CARDVendorID */
0xFF,
0xFF,
/* 80450A72 0006+00 data_80450A72 None */
0x1C,
0x00,
0x00,
0x00,
0x00,
0x00,
};
if (!(0 <= chan && chan < 2)) {
return CARD_RESULT_FATAL_ERROR;
}
result = __CARDGetControlBlock(chan, &card);
if (result < 0) {
return result;
}
id = (CARDID*)card->workArea;
for (code = 0, i = 0; i < sizeof(id->serial) / sizeof(u64); ++i) {
code ^= *(u64*)&id->serial[sizeof(u64) * i];
}
*serialNo = code;
return __CARDPutControlBlock(card, CARD_RESULT_READY);
}
+57 -40
View File
@@ -4,60 +4,73 @@
//
#include "dolphin/card/CARDOpen.h"
#include "MSL_C/MSL_Common/Src/mem.h"
#include "dol2asm.h"
#include "dolphin/types.h"
#include "dolphin/card/card.h"
#include "dolphin/dsp/dsp.h"
#include "dolphin/dvd/dvd.h"
//
// Forward References:
//
void __CARDCompareFileName();
void __CARDAccess();
void __CARDIsWritable();
void __CARDIsReadable();
void CARDOpen();
void CARDClose();
//
// External References:
//
void __CARDGetControlBlock();
void __CARDPutControlBlock();
void __CARDGetDirBlock();
void memcmp();
extern u8 __CARDDiskNone[32];
extern u8 struct_80450A70[8];
#include "dolphin/card/CARDPriv.h"
//
// Declarations:
//
/* 80357C74-80357CDC 3525B4 0068+00 1/1 1/1 0/0 .text __CARDCompareFileName */
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
asm void __CARDCompareFileName() {
nofralloc
#include "asm/dolphin/card/CARDOpen/__CARDCompareFileName.s"
BOOL __CARDCompareFileName(CARDDir* ent, const char* fileName) {
char* entName;
char c1;
char c2;
int n;
entName = (char*)ent->fileName;
n = CARD_FILENAME_MAX;
while (0 <= --n) {
if ((c1 = *entName++) != (c2 = *fileName++)) {
return FALSE;
} else if (c2 == '\0') {
return TRUE;
}
}
if (*fileName == '\0') {
return TRUE;
}
return FALSE;
}
#pragma pop
/* 80357CDC-80357D70 35261C 0094+00 2/2 0/0 0/0 .text __CARDAccess */
#ifdef NONMATCHING
s32 __CARDAccess(CARDControl* card, CARDDir* ent) {
if (ent->gameName[0] == 0xFF) {
return CARD_RESULT_NOFILE;
}
if (card->diskID == &__CARDDiskNone ||
(memcmp(ent->gameName, card->diskID->game_name, 4) == 0 &&
memcmp(ent->company, card->diskID->company, 2) == 0)) {
return CARD_RESULT_READY;
}
return CARD_RESULT_NOPERM;
}
#else
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
asm void __CARDAccess() {
asm s32 __CARDAccess(CARDControl* card, CARDDir* ent) {
nofralloc
#include "asm/dolphin/card/CARDOpen/__CARDAccess.s"
}
#pragma pop
#endif
/* 80357D70-80357EA4 3526B0 0134+00 0/0 2/2 0/0 .text __CARDIsWritable */
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
asm void __CARDIsWritable() {
asm s32 __CARDIsWritable(CARDControl* card, CARDDir* ent) {
nofralloc
#include "asm/dolphin/card/CARDOpen/__CARDIsWritable.s"
}
@@ -67,7 +80,7 @@ asm void __CARDIsWritable() {
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
asm void __CARDIsReadable() {
asm s32 __CARDIsReadable(CARDControl* card, CARDDir* ent) {
nofralloc
#include "asm/dolphin/card/CARDOpen/__CARDIsReadable.s"
}
@@ -77,18 +90,22 @@ asm void __CARDIsReadable() {
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
asm void CARDOpen() {
asm s32 CARDOpen(s32 chan, const char* fileName, CARDFileInfo* fileInfo) {
nofralloc
#include "asm/dolphin/card/CARDOpen/CARDOpen.s"
}
#pragma pop
/* 803580B4-80358108 3529F4 0054+00 0/0 3/3 0/0 .text CARDClose */
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
asm void CARDClose() {
nofralloc
#include "asm/dolphin/card/CARDOpen/CARDClose.s"
s32 CARDClose(CARDFileInfo* fileInfo) {
CARDControl* card;
s32 result;
result = __CARDGetControlBlock(fileInfo->chan, &card);
if (result < 0) {
return result;
}
fileInfo->chan = -1;
return __CARDPutControlBlock(card, CARD_RESULT_READY);
}
#pragma pop
+72 -30
View File
@@ -5,66 +5,108 @@
#include "dolphin/card/CARDRdwr.h"
#include "dol2asm.h"
#include "dolphin/types.h"
#include "dolphin/card/card.h"
#include "dolphin/dsp/dsp.h"
#include "dolphin/dvd/dvd.h"
#include "dolphin/card/CARDPriv.h"
//
// Forward References:
//
static void BlockReadCallback();
void __CARDRead();
static void BlockWriteCallback();
void __CARDWrite();
//
// External References:
//
void __CARDReadSegment();
void __CARDWritePage();
void __CARDPutControlBlock();
extern u8 __CARDBlock[544];
static void BlockReadCallback(s32 chan, s32 result);
static void BlockWriteCallback(s32 chan, s32 result);
//
// Declarations:
//
/* 80355184-80355260 34FAC4 00DC+00 1/1 0/0 0/0 .text BlockReadCallback */
// needs compiler epilogue patch
#ifdef NONMATCHING
static void BlockReadCallback(s32 chan, s32 result) {
CARDControl* card;
CARDCallback callback;
card = &__CARDBlock[chan];
if (result < 0) {
goto error;
}
card->xferred += CARD_SEG_SIZE;
card->addr += CARD_SEG_SIZE;
(u8*)card->buffer += CARD_SEG_SIZE;
if (--card->repeat <= 0) {
goto error;
}
result = __CARDReadSegment(chan, BlockReadCallback);
if (result < 0) {
goto error;
}
return;
error:
if (card->apiCallback == 0) {
__CARDPutControlBlock(card, result);
}
callback = card->xferCallback;
if (callback) {
card->xferCallback = 0;
callback(chan, result);
}
}
#else
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
static asm void BlockReadCallback() {
static asm void BlockReadCallback(s32 chan, s32 result) {
nofralloc
#include "asm/dolphin/card/CARDRdwr/BlockReadCallback.s"
}
#pragma pop
#endif
/* 80355260-803552C4 34FBA0 0064+00 0/0 3/3 0/0 .text __CARDRead */
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
asm void __CARDRead() {
nofralloc
#include "asm/dolphin/card/CARDRdwr/__CARDRead.s"
s32 __CARDRead(s32 chan, u32 addr, s32 length, void* dst, CARDCallback callback) {
CARDControl* card;
card = &__CARDBlock[chan];
if (!card->attached) {
return CARD_RESULT_NOCARD;
}
card->xferCallback = callback;
card->repeat = (int)(length / CARD_SEG_SIZE);
card->addr = addr;
card->buffer = dst;
return __CARDReadSegment(chan, BlockReadCallback);
}
#pragma pop
/* 803552C4-803553AC 34FC04 00E8+00 1/1 0/0 0/0 .text BlockWriteCallback */
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
static asm void BlockWriteCallback() {
static asm void BlockWriteCallback(s32 chan, s32 result) {
nofralloc
#include "asm/dolphin/card/CARDRdwr/BlockWriteCallback.s"
}
#pragma pop
/* 803553AC-80355414 34FCEC 0068+00 0/0 4/4 0/0 .text __CARDWrite */
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
asm void __CARDWrite() {
nofralloc
#include "asm/dolphin/card/CARDRdwr/__CARDWrite.s"
s32 __CARDWrite(s32 chan, u32 addr, s32 length, void* dst, CARDCallback callback) {
CARDControl* card;
card = &__CARDBlock[chan];
if (!card->attached) {
return CARD_RESULT_NOCARD;
}
card->xferCallback = callback;
card->repeat = (int)(length / card->pageSize);
card->addr = addr;
card->buffer = dst;
return __CARDWritePage(chan, BlockWriteCallback);
}
#pragma pop
+154 -37
View File
@@ -5,73 +5,190 @@
#include "dolphin/card/CARDRead.h"
#include "dol2asm.h"
#include "dolphin/types.h"
#include "dolphin/card/card.h"
#include "dolphin/dsp/dsp.h"
#include "dolphin/dvd/dvd.h"
#include "dolphin/card/CARDPriv.h"
//
// Forward References:
//
void __CARDSeek();
static void ReadCallback();
static void CARDReadAsync();
void CARDRead();
//
// External References:
//
void DCInvalidateRange();
void __CARDDefaultApiCallback();
void __CARDSyncCallback();
void __CARDGetControlBlock();
void __CARDPutControlBlock();
void __CARDSync();
void __CARDRead();
void __CARDGetFatBlock();
void __CARDGetDirBlock();
void __CARDIsReadable();
extern u8 __CARDBlock[544];
static void ReadCallback(s32 chan, s32 result);
//
// Declarations:
//
/* 803584A0-80358658 352DE0 01B8+00 1/1 1/1 0/0 .text __CARDSeek */
// needs compiler epilogue patch
#ifdef NONMATCHING
s32 __CARDSeek(CARDFileInfo* fileInfo, s32 length, s32 offset, CARDControl** pcard) {
CARDControl* card;
CARDDir* dir;
CARDDir* ent;
s32 result;
u16* fat;
result = __CARDGetControlBlock(fileInfo->chan, &card);
if (result < 0) {
return result;
}
if (!CARDIsValidBlockNo(card, fileInfo->iBlock) ||
card->cBlock * card->sectorSize <= fileInfo->offset) {
return __CARDPutControlBlock(card, CARD_RESULT_FATAL_ERROR);
}
dir = __CARDGetDirBlock(card);
ent = &dir[fileInfo->fileNo];
if (ent->length * card->sectorSize <= offset ||
ent->length * card->sectorSize < offset + length) {
return __CARDPutControlBlock(card, CARD_RESULT_LIMIT);
}
card->fileInfo = fileInfo;
fileInfo->length = length;
if (offset < fileInfo->offset) {
fileInfo->offset = 0;
fileInfo->iBlock = ent->startBlock;
if (!CARDIsValidBlockNo(card, fileInfo->iBlock)) {
return __CARDPutControlBlock(card, CARD_RESULT_BROKEN);
}
}
fat = __CARDGetFatBlock(card);
while (fileInfo->offset < TRUNC(offset, card->sectorSize)) {
fileInfo->offset += card->sectorSize;
fileInfo->iBlock = fat[fileInfo->iBlock];
if (!CARDIsValidBlockNo(card, fileInfo->iBlock)) {
return __CARDPutControlBlock(card, CARD_RESULT_BROKEN);
}
}
fileInfo->offset = offset;
*pcard = card;
return CARD_RESULT_READY;
}
#else
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
asm void __CARDSeek() {
asm s32 __CARDSeek(CARDFileInfo* fileInfo, s32 length, s32 offset, CARDControl** pcard) {
nofralloc
#include "asm/dolphin/card/CARDRead/__CARDSeek.s"
}
#pragma pop
#endif
/* 80358658-80358788 352F98 0130+00 1/1 0/0 0/0 .text ReadCallback */
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
static asm void ReadCallback() {
nofralloc
#include "asm/dolphin/card/CARDRead/ReadCallback.s"
static void ReadCallback(s32 chan, s32 result) {
CARDControl* card;
CARDCallback callback;
u16* fat;
CARDFileInfo* fileInfo;
s32 length;
card = &__CARDBlock[chan];
if (result < 0) {
goto error;
}
fileInfo = card->fileInfo;
if (fileInfo->length < 0) {
result = CARD_RESULT_CANCELED;
goto error;
}
length = (s32)TRUNC(fileInfo->offset + card->sectorSize, card->sectorSize) - fileInfo->offset;
fileInfo->length -= length;
if (fileInfo->length <= 0) {
goto error;
}
fat = __CARDGetFatBlock(card);
fileInfo->offset += length;
fileInfo->iBlock = fat[fileInfo->iBlock];
if (!CARDIsValidBlockNo(card, fileInfo->iBlock)) {
result = CARD_RESULT_BROKEN;
goto error;
}
result = __CARDRead(chan, card->sectorSize * (u32)fileInfo->iBlock,
(fileInfo->length < card->sectorSize) ? fileInfo->length : card->sectorSize,
card->buffer, ReadCallback);
if (result < 0) {
goto error;
}
return;
error:
callback = card->apiCallback;
card->apiCallback = 0;
__CARDPutControlBlock(card, result);
callback(chan, result);
}
#pragma pop
/* 80358788-803588CC 3530C8 0144+00 1/1 0/0 0/0 .text CARDReadAsync */
#ifdef NONMATCHING
s32 CARDReadAsync(CARDFileInfo* fileInfo, void* buf, s32 length, s32 offset,
CARDCallback callback) {
CARDControl* card;
s32 result;
CARDDir* dir;
CARDDir* ent;
if (OFFSET(offset, CARD_SEG_SIZE) != 0 || OFFSET(length, CARD_SEG_SIZE) != 0) {
return CARD_RESULT_FATAL_ERROR;
}
result = __CARDSeek(fileInfo, length, offset, &card);
if (result < 0) {
return result;
}
dir = __CARDGetDirBlock(card);
ent = &dir[fileInfo->fileNo];
result = __CARDAccess(card, ent);
if (result == CARD_RESULT_NOPERM) {
result = __CARDIsWritable(ent);
}
if (result < 0) {
return __CARDPutControlBlock(card, result);
}
DCInvalidateRange(buf, (u32)length);
card->apiCallback = callback ? callback : __CARDDefaultApiCallback;
offset = (s32)OFFSET(fileInfo->offset, card->sectorSize);
length = (length < card->sectorSize - offset) ? length : card->sectorSize - offset;
result = __CARDRead(fileInfo->chan, card->sectorSize * (u32)fileInfo->iBlock + offset, length,
buf, ReadCallback);
if (result < 0) {
__CARDPutControlBlock(card, result);
}
return result;
}
#else
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
static asm void CARDReadAsync() {
static asm s32 CARDReadAsync(CARDFileInfo* fileInfo, void* buf, s32 length, s32 offset,
CARDCallback callback) {
nofralloc
#include "asm/dolphin/card/CARDRead/CARDReadAsync.s"
}
#pragma pop
#endif
/* 803588CC-80358914 35320C 0048+00 0/0 2/2 0/0 .text CARDRead */
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
asm void CARDRead() {
nofralloc
#include "asm/dolphin/card/CARDRead/CARDRead.s"
s32 CARDRead(CARDFileInfo* fileInfo, void* buf, s32 length, s32 offset) {
s32 result = CARDReadAsync(fileInfo, buf, length, offset, __CARDSyncCallback);
if (result < 0) {
return result;
}
return __CARDSync(fileInfo->chan);
}
#pragma pop
+156 -33
View File
@@ -5,31 +5,19 @@
#include "dolphin/card/CARDStat.h"
#include "dol2asm.h"
#include "dolphin/types.h"
#include "dolphin/card/card.h"
#include "dolphin/dsp/dsp.h"
#include "dolphin/dvd/dvd.h"
//
// Forward References:
//
#include "dolphin/card/CARDPriv.h"
static void UpdateIconOffsets();
void CARDGetStatus();
static void CARDSetStatusAsync();
void CARDSetStatus();
static void UpdateIconOffsets(CARDDir* ent, CARDStat* stat);
//
// External References:
//
SECTION_INIT void memcpy();
void OSGetTime();
void __CARDSyncCallback();
void __CARDGetControlBlock();
void __CARDPutControlBlock();
void __CARDSync();
void __CARDGetDirBlock();
void __CARDUpdateDir();
void __CARDIsWritable();
void __CARDIsReadable();
void __div2i();
//
@@ -37,41 +25,176 @@ void __div2i();
//
/* 80358C90-80358E88 3535D0 01F8+00 2/2 0/0 0/0 .text UpdateIconOffsets */
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
static asm void UpdateIconOffsets() {
nofralloc
#include "asm/dolphin/card/CARDStat/UpdateIconOffsets.s"
static void UpdateIconOffsets(CARDDir* ent, CARDStat* stat) {
u32 offset;
BOOL iconTlut;
int i;
offset = ent->iconAddr;
if (offset == 0xFFFFFFFF) {
stat->bannerFormat = 0;
stat->iconFormat = 0;
stat->iconSpeed = 0;
offset = 0;
}
iconTlut = FALSE;
switch (CARDGetBannerFormat(ent)) {
case CARD_STAT_BANNER_C8:
stat->offsetBanner = offset;
offset += CARD_BANNER_WIDTH * CARD_BANNER_HEIGHT;
stat->offsetBannerTlut = offset;
offset += 2 * 256;
break;
case CARD_STAT_BANNER_RGB5A3:
stat->offsetBanner = offset;
offset += 2 * CARD_BANNER_WIDTH * CARD_BANNER_HEIGHT;
stat->offsetBannerTlut = 0xFFFFFFFF;
break;
default:
stat->offsetBanner = 0xFFFFFFFF;
stat->offsetBannerTlut = 0xFFFFFFFF;
break;
}
for (i = 0; i < CARD_ICON_MAX; ++i) {
switch (CARDGetIconFormat(ent, i)) {
case CARD_STAT_ICON_C8:
stat->offsetIcon[i] = offset;
offset += CARD_ICON_WIDTH * CARD_ICON_HEIGHT;
iconTlut = TRUE;
break;
case CARD_STAT_ICON_RGB5A3:
stat->offsetIcon[i] = offset;
offset += 2 * CARD_ICON_WIDTH * CARD_ICON_HEIGHT;
break;
default:
stat->offsetIcon[i] = 0xFFFFFFFF;
break;
}
}
if (iconTlut) {
stat->offsetIconTlut = offset;
offset += 2 * 256;
} else {
stat->offsetIconTlut = 0xFFFFFFFF;
}
stat->offsetData = offset;
}
#pragma pop
/* 80358E88-80358F9C 3537C8 0114+00 0/0 2/2 0/0 .text CARDGetStatus */
#ifdef NONMATCHING
s32 CARDGetStatus(s32 chan, s32 fileNo, CARDStat* stat) {
CARDControl* card;
CARDDir* dir;
CARDDir* ent;
s32 result;
if (fileNo < 0 || CARD_MAX_FILE <= fileNo) {
return CARD_RESULT_FATAL_ERROR;
}
result = __CARDGetControlBlock(chan, &card);
if (result < 0) {
return result;
}
dir = __CARDGetDirBlock(card);
ent = &dir[fileNo];
result = __CARDAccess(card, ent);
if (result == CARD_RESULT_NOPERM) {
result = __CARDIsWritable(ent);
}
if (result >= 0) {
memcpy(stat->gameName, ent->gameName, sizeof(stat->gameName));
memcpy(stat->company, ent->company, sizeof(stat->company));
stat->length = (u32)ent->length * card->sectorSize;
memcpy(stat->fileName, ent->fileName, CARD_FILENAME_MAX);
stat->time = ent->time;
stat->bannerFormat = ent->bannerFormat;
stat->iconAddr = ent->iconAddr;
stat->iconFormat = ent->iconFormat;
stat->iconSpeed = ent->iconSpeed;
stat->commentAddr = ent->commentAddr;
UpdateIconOffsets(ent, stat);
}
return __CARDPutControlBlock(card, result);
}
#else
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
asm void CARDGetStatus() {
asm s32 CARDGetStatus(s32 chan, s32 fileNo, CARDStat* stat) {
nofralloc
#include "asm/dolphin/card/CARDStat/CARDGetStatus.s"
}
#pragma pop
#endif
/* 80358F9C-80359110 3538DC 0174+00 1/1 0/0 0/0 .text CARDSetStatusAsync */
#ifdef NONMATCHING
s32 CARDSetStatusAsync(s32 chan, s32 fileNo, CARDStat* stat, CARDCallback callback) {
CARDControl* card;
CARDDir* dir;
CARDDir* ent;
s32 result;
if (fileNo < 0 || CARD_MAX_FILE <= fileNo ||
(stat->iconAddr != 0xffffffff && CARD_READ_SIZE <= stat->iconAddr) ||
(stat->commentAddr != 0xffffffff &&
CARD_SYSTEM_BLOCK_SIZE - CARD_COMMENT_SIZE < stat->commentAddr % CARD_SYSTEM_BLOCK_SIZE)) {
return CARD_RESULT_FATAL_ERROR;
}
result = __CARDGetControlBlock(chan, &card);
if (result < 0) {
return result;
}
dir = __CARDGetDirBlock(card);
ent = &dir[fileNo];
result = __CARDAccess(card, ent);
if (result < 0) {
return __CARDPutControlBlock(card, result);
}
ent->bannerFormat = stat->bannerFormat;
ent->iconAddr = stat->iconAddr;
ent->iconFormat = stat->iconFormat;
ent->iconSpeed = stat->iconSpeed;
ent->commentAddr = stat->commentAddr;
UpdateIconOffsets(ent, stat);
if (ent->iconAddr == 0xffffffff) {
CARDSetIconSpeed(ent, 0, CARD_STAT_SPEED_FAST);
}
ent->time = (u32)OSTicksToSeconds(OSGetTime());
result = __CARDUpdateDir(chan, callback);
if (result < 0) {
__CARDPutControlBlock(card, result);
}
return result;
}
#else
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
static asm void CARDSetStatusAsync() {
static asm s32 CARDSetStatusAsync(s32 chan, s32 fileNo, CARDStat* stat, CARDCallback callback) {
nofralloc
#include "asm/dolphin/card/CARDStat/CARDSetStatusAsync.s"
}
#pragma pop
#endif
/* 80359110-80359158 353A50 0048+00 0/0 1/1 0/0 .text CARDSetStatus */
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
asm void CARDSetStatus() {
nofralloc
#include "asm/dolphin/card/CARDStat/CARDSetStatus.s"
s32 CARDSetStatus(s32 chan, s32 fileNo, CARDStat* stat) {
s32 result = CARDSetStatusAsync(chan, fileNo, stat, __CARDSyncCallback);
if (result < 0) {
return result;
}
return __CARDSync(chan);
}
#pragma pop
+73 -43
View File
@@ -5,18 +5,22 @@
#include "dolphin/card/CARDUnlock.h"
#include "dol2asm.h"
#include "dolphin/types.h"
#include "dolphin/card/card.h"
#include "dolphin/dsp/dsp.h"
#include "dolphin/dvd/dvd.h"
#include "dolphin/exi/EXIBios.h"
#include "dolphin/card/CARDPriv.h"
//
// Forward References:
//
static void bitrev();
static void ReadArrayUnlock();
static void DummyLen();
void __CARDUnlock();
static void InitCallback();
static void DoneCallback();
static u32 bitrev(u32 data);
static s32 ReadArrayUnlock(s32 chan, u32 data, void* rbuf, s32 rlen, s32 mode);
static s32 DummyLen(void);
static void InitCallback(void* _task);
static void DoneCallback(void* _task);
//
// External References:
@@ -24,57 +28,83 @@ static void DoneCallback();
SECTION_INIT void memset();
void DSPAddTask();
void DCInvalidateRange();
void DCFlushRange();
void OSGetTick();
void EXIImmEx();
void EXIProbe();
void EXISelect();
void EXIDeselect();
void EXIUnlock();
void DSPCheckMailToDSP();
void DSPSendMailToDSP();
void __CARDReadStatus();
void __CARDMountCallback();
extern u8 __CARDBlock[544];
//
// Declarations:
//
/* 80353F24-80354090 34E864 016C+00 1/1 0/0 0/0 .text bitrev */
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
static asm void bitrev() {
nofralloc
#include "asm/dolphin/card/CARDUnlock/bitrev.s"
static u32 bitrev(u32 data) {
u32 wk;
u32 i;
u32 k = 0;
u32 j = 1;
wk = 0;
for (i = 0; i < 32; i++) {
if (i > 15) {
if (i == 31) {
wk |= (((data & (0x01 << 31)) >> 31) & 0x01);
} else {
wk |= ((data & (0x01 << i)) >> j);
j += 2;
}
} else {
wk |= ((data & (0x01 << i)) << (31 - i - k));
k++;
}
}
return wk;
}
#pragma pop
#define SEC_AD1(x) ((u8)(((x) >> 29) & 0x03))
#define SEC_AD2(x) ((u8)(((x) >> 21) & 0xff))
#define SEC_AD3(x) ((u8)(((x) >> 19) & 0x03))
#define SEC_BA(x) ((u8)(((x) >> 12) & 0x7f))
/* 80354090-803541D4 34E9D0 0144+00 2/2 0/0 0/0 .text ReadArrayUnlock */
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
static asm void ReadArrayUnlock() {
nofralloc
#include "asm/dolphin/card/CARDUnlock/ReadArrayUnlock.s"
static s32 ReadArrayUnlock(s32 chan, u32 data, void* rbuf, s32 rlen, s32 mode) {
CARDControl* card;
BOOL err;
u8 cmd[5];
card = &__CARDBlock[chan];
if (!EXISelect(chan, 0, 4)) {
return CARD_RESULT_NOCARD;
}
data &= 0xfffff000;
memset(cmd, 0, 5);
cmd[0] = 0x52;
if (mode == 0) {
cmd[1] = SEC_AD1(data);
cmd[2] = SEC_AD2(data);
cmd[3] = SEC_AD3(data);
cmd[4] = SEC_BA(data);
} else {
cmd[1] = (u8)((data & 0xff000000) >> 24);
cmd[2] = (u8)((data & 0x00ff0000) >> 16);
}
err = FALSE;
err |= !EXIImmEx(chan, cmd, 5, 1);
err |= !EXIImmEx(chan, (u8*)card->workArea + (u32)sizeof(CARDID), card->latency, 1);
err |= !EXIImmEx(chan, rbuf, rlen, 0);
err |= !EXIDeselect(chan);
return err ? CARD_RESULT_NOCARD : CARD_RESULT_READY;
}
#pragma pop
/* ############################################################################################## */
/* 80450A68-80450A70 0004E8 0004+04 2/2 0/0 0/0 .sdata next */
SECTION_SDATA static u32 next[1 + 1 /* padding */] = {
0x00000001,
/* padding */
0x00000000,
};
static unsigned long int next = 1;
/* 803541D4-80354298 34EB14 00C4+00 2/2 0/0 0/0 .text DummyLen */
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
static asm void DummyLen() {
static asm s32 DummyLen(void) {
nofralloc
#include "asm/dolphin/card/CARDUnlock/DummyLen.s"
}
@@ -82,7 +112,7 @@ static asm void DummyLen() {
/* ############################################################################################## */
/* 803D1EA0-803D2000 02EFC0 0160+00 1/1 0/0 0/0 .data CardData */
SECTION_DATA static u8 CardData[352] = {
SECTION_DATA static u8 CardData[352] ALIGN_DECL(32) = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x02, 0xFF, 0x00, 0x21,
0x13, 0x06, 0x12, 0x03, 0x12, 0x04, 0x13, 0x05, 0x00, 0x92, 0x00, 0xFF, 0x00, 0x88, 0xFF, 0xFF,
@@ -111,7 +141,7 @@ SECTION_DATA static u8 CardData[352] = {
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
asm void __CARDUnlock() {
asm s32 __CARDUnlock(s32 chan, u8 flashID[12]) {
nofralloc
#include "asm/dolphin/card/CARDUnlock/__CARDUnlock.s"
}
@@ -121,7 +151,7 @@ asm void __CARDUnlock() {
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
static asm void InitCallback() {
static asm void InitCallback(void* _task) {
nofralloc
#include "asm/dolphin/card/CARDUnlock/InitCallback.s"
}
@@ -131,7 +161,7 @@ static asm void InitCallback() {
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
static asm void DoneCallback() {
static asm void DoneCallback(void* _task) {
nofralloc
#include "asm/dolphin/card/CARDUnlock/DoneCallback.s"
}

Some files were not shown because too many files have changed in this diff Show More