Add 1.2.5e to several makefiles and matching dolphin lib stuff (#247)

* Fix select_occurence in diff.py

* Use 1.2.5e and metroid prime decomp to match dlphin lib funcs

* Fix FRANK_COMPILER WINE typo

* Double WINE use removal

* Organize dolphin compiler makefile names

* Use inline auto instead of special inline where applicable
I couldn't make CARDOpen work with the flag though
This commit is contained in:
hatal175
2023-01-20 10:51:21 -07:00
committed by GitHub
parent ccac8b31e2
commit 7825666971
105 changed files with 2068 additions and 7024 deletions
+4 -2
View File
@@ -14,6 +14,7 @@ LIBAI_A_CFLAGS := \
-fp hard \
-nodefaults \
-str reuse \
-inline auto \
-RTTI off \
-maxerrors 5 \
-enum int $(INCLUDES) \
@@ -35,10 +36,11 @@ $(BUILD_DIR)/libs/dolphin/ai/%.o: libs/dolphin/ai/%.c $(BUILD_DIR)/libs/dolphin/
@mkdir -p $(@D)
@echo building... $<
@$(ICONV) -f UTF-8 -t CP932 < $< > $(basename $@).c
@$(WINE) tools/mwcc_compiler/1.2.5/mwcceppc.exe $(LIBAI_A_CFLAGS) $(DEPFLAGS) -c -o $(dir $@) $(basename $@).c
@$(FRANK_CC) $(LIBAI_A_CFLAGS) -c -o $(@:.o=.po) $(basename $@).c
@$(DOLPHIN_LIB_CC) $(LIBAI_A_CFLAGS) $(DEPFLAGS) -c -o $(dir $@) $(basename $@).c
@if [ -z '$(DISABLE_DEPS)' ]; then tools/transform-dep.py '$(basename $@).d' '$(basename $@).d'; touch -c $@; fi
@echo Frank is fixing $@
@$(PYTHON) $(FRANK) $@ $@ $@
@$(PYTHON) $(FRANK) $@ $(@:.o=.po) $@
ifndef DISABLE_DEPS
LIBAI_A_D_FILES := $(LIBAI_A_O_FILES:.o=.d)
+35 -1
View File
@@ -211,8 +211,41 @@ static OSTime max_wait;
/* 804518B0-804518B4 000DB0 0004+00 2/2 0/0 0/0 .sbss buffer */
static OSTime buffer;
inline void AIResetStreamSampleCount(void) { __AIRegs[0] = (__AIRegs[0] & ~0x20) | 0x20; }
inline void AISetStreamTrigger(u32 trigger) { __AIRegs[3] = trigger; }
/* 80350084-803501F0 34A9C4 016C+00 0/0 1/1 0/0 .text AIInit */
// need compiler epilogue patch
// time assignments are weird
#ifdef NONMATCHING
void AIInit(u8* stack) {
if (__AI_init_flag == TRUE) {
return;
}
OSRegisterVersion(__AIVersion);
bound_32KHz = OSNanosecondsToTicks(31524);
bound_48KHz = OSNanosecondsToTicks(42024);
min_wait = OSNanosecondsToTicks(42000);
max_wait = OSNanosecondsToTicks(63000);
buffer = OSNanosecondsToTicks(3000);
AISetStreamVolRight(0);
AISetStreamVolLeft(0);
AISetStreamTrigger(0);
AIResetStreamSampleCount();
__AI_set_stream_sample_rate(1);
AISetDSPSampleRate(0);
__AIS_Callback = 0;
__AID_Callback = 0;
__CallbackStack = stack;
__OSSetInterruptHandler(5, __AIDHandler);
__OSUnmaskInterrupts(0x04000000);
__OSSetInterruptHandler(8, __AISHandler);
__OSUnmaskInterrupts(0x800000);
__AI_init_flag = TRUE;
}
#else
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
@@ -221,6 +254,7 @@ asm void AIInit(u8* stack) {
#include "asm/dolphin/ai/ai/AIInit.s"
}
#pragma pop
#endif
/* 803501F0-8035026C 34AB30 007C+00 1/1 0/0 0/0 .text __AISHandler */
void __AISHandler(s16 interrupt, OSContext* context) {
+3 -2
View File
@@ -37,10 +37,11 @@ $(BUILD_DIR)/libs/dolphin/ar/%.o: libs/dolphin/ar/%.c $(BUILD_DIR)/libs/dolphin/
@mkdir -p $(@D)
@echo building... $<
@$(ICONV) -f UTF-8 -t CP932 < $< > $(basename $@).c
@$(WINE) tools/mwcc_compiler/1.2.5/mwcceppc.exe $(LIBAR_A_CFLAGS) $(DEPFLAGS) -c -o $(dir $@) $(basename $@).c
@$(FRANK_CC) $(LIBAR_A_CFLAGS) -c -o $(@:.o=.po) $(basename $@).c
@$(DOLPHIN_LIB_CC) $(LIBAR_A_CFLAGS) $(DEPFLAGS) -c -o $(dir $@) $(basename $@).c
@if [ -z '$(DISABLE_DEPS)' ]; then tools/transform-dep.py '$(basename $@).d' '$(basename $@).d'; touch -c $@; fi
@echo Frank is fixing $@
@$(PYTHON) $(FRANK) $@ $@ $@
@$(PYTHON) $(FRANK) $@ $(@:.o=.po) $@
ifndef DISABLE_DEPS
LIBAR_A_D_FILES := $(LIBAR_A_O_FILES:.o=.d)
+223 -58
View File
@@ -12,7 +12,7 @@
void __ARHandler(s16 interrupt, OSContext* context);
void __ARClearInterrupt();
void __ARGetInterruptStatus();
u16 __ARGetInterruptStatus();
void __ARChecksize();
/* ############################################################################################## */
@@ -20,8 +20,6 @@ void __ARChecksize();
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;
@@ -31,20 +29,8 @@ ARCallback ARRegisterDMACallback(ARCallback callback) {
OSRestoreInterrupts(enabled);
return oldCb;
}
#else
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
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;
@@ -53,16 +39,6 @@ u32 ARGetDMAStatus() {
OSRestoreInterrupts(enabled);
return val;
}
#else
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
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 */
void ARStartDMA(u32 type, u32 mainmem_addr, u32 aram_addr, u32 length) {
@@ -100,8 +76,6 @@ static u32 __AR_FreeBlocks;
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;
@@ -116,16 +90,6 @@ u32 ARAlloc(u32 length) {
return tmp;
}
#else
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
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 */
@@ -139,14 +103,39 @@ SECTION_SDATA static const char* __ARVersion = lit_1;
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* stack_index_addr, u32 num_entries) {
nofralloc
#include "asm/dolphin/ar/ar/ARInit.s"
u32 ARInit(u32* stack_index_addr, u32 num_entries) {
BOOL old;
u16 refresh;
if (__AR_init_flag == TRUE) {
return 0x4000;
}
OSRegisterVersion(__ARVersion);
old = OSDisableInterrupts();
__AR_Callback = NULL;
__OSSetInterruptHandler(OS_INTR_DSP_ARAM, __ARHandler);
__OSUnmaskInterrupts(OS_INTERRUPTMASK_DSP_ARAM);
__AR_StackPointer = 0x4000;
__AR_FreeBlocks = num_entries;
__AR_BlockLength = stack_index_addr;
refresh = (u16)(__DSPRegs[13] & 0x000000ff);
__DSPRegs[13] = (u16)((__DSPRegs[13] & ~0x000000ff) | (refresh & 0x000000ff));
__ARChecksize();
__AR_init_flag = TRUE;
OSRestoreInterrupts(old);
return __AR_StackPointer;
}
#pragma pop
/* 803507F0-803507F8 -00001 0008+00 0/0 0/0 0/0 .text ARGetSize */
u32 ARGetSize(void) {
@@ -174,26 +163,201 @@ static void __ARHandler(s16 interrupt, OSContext* context) {
}
/* 80350870-80350890 34B1B0 0020+00 0/0 2/2 0/0 .text __ARClearInterrupt */
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
asm void __ARClearInterrupt() {
nofralloc
#include "asm/dolphin/ar/ar/__ARClearInterrupt.s"
void __ARClearInterrupt(void) {
u16 tmp;
tmp = __DSPRegs[5];
tmp = (u16)((tmp & ~(0x00000080 | 0x00000008)) | 0x00000020);
__DSPRegs[5] = tmp;
}
#pragma pop
/* 80350890-803508A0 34B1D0 0010+00 0/0 2/2 0/0 .text __ARGetInterruptStatus */
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
asm void __ARGetInterruptStatus() {
nofralloc
#include "asm/dolphin/ar/ar/__ARGetInterruptStatus.s"
u16 __ARGetInterruptStatus(void) {
return ((u16)(__DSPRegs[5] & 0x0020));
}
#pragma pop
#define RoundUP32(x) (((u32)(x) + 32 - 1) & ~(32 - 1))
/* 803508A0-80352094 34B1E0 17F4+00 1/1 0/0 0/0 .text __ARChecksize */
#ifdef NONMATCHING
void __ARChecksize(void) {
u8 test_data_pad[0x20 + 31];
u8 dummy_data_pad[0x20 + 31];
u8 buffer_pad[0x20 + 31];
u8 save_pad_1[0x20 + 31];
u8 save_pad_2[0x20 + 31];
u8 save_pad_3[0x20 + 31];
u8 save_pad_4[0x20 + 31];
u8 save_pad_5[0x20 + 31];
u16 dspreg9;
u32* test_data;
u32* dummy_data;
u32* buffer;
u32* save1;
u32* save2;
u32* save3;
u32* save4;
u32* save5;
u16 ARAM_mode = 0;
u32 ARAM_size = 0;
u32 i;
while (!(__DSPRegs[11] & 1))
;
ARAM_mode = 3;
__DSPRegs[9] = (u16)((__DSPRegs[9] & ~(0x00000007 | 0x00000038)) | 0x20 | 2 | 1);
ARAM_size = __AR_InternalSize = 0x1000000;
test_data = (u32*)(RoundUP32((u32)(test_data_pad)));
dummy_data = (u32*)(RoundUP32((u32)(dummy_data_pad)));
buffer = (u32*)(RoundUP32((u32)(buffer_pad)));
save1 = (u32*)(RoundUP32((u32)(save_pad_1)));
save2 = (u32*)(RoundUP32((u32)(save_pad_2)));
save3 = (u32*)(RoundUP32((u32)(save_pad_3)));
save4 = (u32*)(RoundUP32((u32)(save_pad_4)));
save5 = (u32*)(RoundUP32((u32)(save_pad_5)));
for (i = 0; i < 8; i++) {
*(test_data + i) = 0xdeadbeef;
*(dummy_data + i) = 0xbad0bad0;
}
DCFlushRange((void*)test_data, 0x20);
DCFlushRange((void*)dummy_data, 0x20);
__AR_ExpansionSize = 0;
DCInvalidateRange((void*)save1, 0x20);
__ARReadDMA((u32)save1, ARAM_size + 0, 0x20);
PPCSync();
__ARWriteDMA((u32)test_data, ARAM_size + 0x0000000, 0x20);
memset((void*)buffer, 0, 0x20);
DCFlushRange((void*)buffer, 0x20);
__ARReadDMA((u32)buffer, ARAM_size + 0x0000000, 0x20);
PPCSync();
if (buffer[0] == test_data[0]) {
DCInvalidateRange((void*)save2, 0x20);
__ARReadDMA((u32)save2, ARAM_size + 0x0200000, 0x20);
PPCSync();
DCInvalidateRange((void*)save3, 0x20);
__ARReadDMA((u32)save3, ARAM_size + 0x1000000, 0x20);
PPCSync();
DCInvalidateRange((void*)save4, 0x20);
__ARReadDMA((u32)save4, ARAM_size + 0x0000200, 0x20);
PPCSync();
DCInvalidateRange((void*)save5, 0x20);
__ARReadDMA((u32)save5, ARAM_size + 0x0400000, 0x20);
PPCSync();
__ARWriteDMA((u32)dummy_data, ARAM_size + 0x0200000, 0x20);
__ARWriteDMA((u32)test_data, ARAM_size + 0x0000000, 0x20);
memset((void*)buffer, 0, 0x20);
DCFlushRange((void*)buffer, 0x20);
__ARReadDMA((u32)buffer, ARAM_size + 0x0200000, 0x20);
PPCSync();
if (buffer[0] == test_data[0]) {
__ARWriteDMA((u32)save1, ARAM_size + 0x0000000, 0x20);
ARAM_mode |= 0 << 1;
ARAM_size += 0x0200000;
__AR_ExpansionSize = 0x0200000;
} else {
__ARWriteDMA((u32)dummy_data, ARAM_size + 0x1000000, 0x20);
__ARWriteDMA((u32)test_data, ARAM_size + 0x0000000, 0x20);
memset((void*)buffer, 0, 0x20);
DCFlushRange((void*)buffer, 0x20);
__ARReadDMA((u32)buffer, ARAM_size + 0x1000000, 0x20);
PPCSync();
if (buffer[0] == test_data[0]) {
__ARWriteDMA((u32)save1, ARAM_size + 0x0000000, 0x20);
__ARWriteDMA((u32)save2, ARAM_size + 0x0200000, 0x20);
ARAM_mode |= 4 << 1;
ARAM_size += 0x0400000;
__AR_ExpansionSize = 0x0400000;
} else {
__ARWriteDMA((u32)dummy_data, ARAM_size + 0x0000200, 0x20);
__ARWriteDMA((u32)test_data, ARAM_size + 0x0000000, 0x20);
memset((void*)buffer, 0, 0x20);
DCFlushRange((void*)buffer, 0x20);
__ARReadDMA((u32)buffer, ARAM_size + 0x0000200, 0x20);
PPCSync();
if (buffer[0] == test_data[0]) {
__ARWriteDMA((u32)save1, ARAM_size + 0x0000000, 0x20);
__ARWriteDMA((u32)save2, ARAM_size + 0x0200000, 0x20);
__ARWriteDMA((u32)save3, ARAM_size + 0x1000000, 0x20);
ARAM_mode |= 8 << 1;
ARAM_size += 0x0800000;
__AR_ExpansionSize = 0x0800000;
} else {
__ARWriteDMA((u32)dummy_data, ARAM_size + 0x0400000, 0x20);
__ARWriteDMA((u32)test_data, ARAM_size + 0x0000000, 0x20);
memset((void*)buffer, 0, 0x20);
DCFlushRange((void*)buffer, 0x20);
__ARReadDMA((u32)buffer, ARAM_size + 0x0400000, 0x20);
PPCSync();
if (buffer[0] == test_data[0]) {
__ARWriteDMA((u32)save1, ARAM_size + 0x0000000, 0x20);
__ARWriteDMA((u32)save2, ARAM_size + 0x0200000, 0x20);
__ARWriteDMA((u32)save3, ARAM_size + 0x1000000, 0x20);
__ARWriteDMA((u32)save4, ARAM_size + 0x0000200, 0x20);
ARAM_mode |= 12 << 1;
ARAM_size += 0x1000000;
__AR_ExpansionSize = 0x1000000;
} else {
__ARWriteDMA((u32)save1, ARAM_size + 0x0000000, 0x20);
__ARWriteDMA((u32)save2, ARAM_size + 0x0200000, 0x20);
__ARWriteDMA((u32)save3, ARAM_size + 0x1000000, 0x20);
__ARWriteDMA((u32)save4, ARAM_size + 0x0000200, 0x20);
__ARWriteDMA((u32)save5, ARAM_size + 0x0400000, 0x20);
ARAM_mode |= 16 << 1;
ARAM_size += 0x2000000;
__AR_ExpansionSize = 0x2000000;
}
}
}
}
__DSPRegs[9] = (u16)((__DSPRegs[9] & ~(0x07 | 0x38)) | ARAM_mode);
}
*(u32*)OSPhysicalToUncached(0x00D0) = ARAM_size;
__AR_Size = ARAM_size;
}
#else
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
@@ -202,3 +366,4 @@ asm void __ARChecksize() {
#include "asm/dolphin/ar/ar/__ARChecksize.s"
}
#pragma pop
#endif
+158 -53
View File
@@ -21,7 +21,7 @@ void ARQInit();
//
void OSRegisterVersion();
void OSDisableInterrupts();
BOOL OSDisableInterrupts();
void OSRestoreInterrupts();
void ARRegisterDMACallback();
void ARStartDMA();
@@ -32,41 +32,71 @@ void ARStartDMA();
/* ############################################################################################## */
/* 804518D8-804518DC 000DD8 0004+00 3/3 0/0 0/0 .sbss __ARQRequestQueueHi */
static u8 __ARQRequestQueueHi[4];
static ARQRequest* __ARQRequestQueueHi;
/* 804518DC-804518E0 000DDC 0004+00 1/1 0/0 0/0 .sbss __ARQRequestTailHi */
static u8 __ARQRequestTailHi[4];
static ARQRequest* __ARQRequestTailHi;
/* 804518E0-804518E4 000DE0 0004+00 3/3 0/0 0/0 .sbss __ARQRequestQueueLo */
static u8 __ARQRequestQueueLo[4];
static ARQRequest* __ARQRequestQueueLo;
/* 804518E4-804518E8 000DE4 0004+00 1/1 0/0 0/0 .sbss __ARQRequestTailLo */
static u8 __ARQRequestTailLo[4];
static ARQRequest* __ARQRequestTailLo;
/* 804518E8-804518EC 000DE8 0004+00 3/3 0/0 0/0 .sbss __ARQRequestPendingHi */
static u8 __ARQRequestPendingHi[4];
static ARQRequest* __ARQRequestPendingHi;
/* 804518EC-804518F0 000DEC 0004+00 4/4 0/0 0/0 .sbss __ARQRequestPendingLo */
static u8 __ARQRequestPendingLo[4];
static ARQRequest* __ARQRequestPendingLo;
/* 804518F0-804518F4 000DF0 0004+00 3/3 0/0 0/0 .sbss __ARQCallbackHi */
static u8 __ARQCallbackHi[4];
static ARQCallback __ARQCallbackHi;
/* 804518F4-804518F8 000DF4 0004+00 3/3 0/0 0/0 .sbss __ARQCallbackLo */
static u8 __ARQCallbackLo[4];
static ARQCallback __ARQCallbackLo;
/* 804518F8-804518FC 000DF8 0004+00 2/2 0/0 0/0 .sbss __ARQChunkSize */
static u8 __ARQChunkSize[4];
static u32 __ARQChunkSize;
/* 803D1C30-803D1C78 02ED50 0045+03 1/0 0/0 0/0 .data @1 */
const char* __ARQVersion = "<< Dolphin SDK - ARQ\trelease build: Apr 5 2004 04:15:04 (0x2301) >>";
/* 804518FC-80451900 000DFC 0004+00 1/1 0/0 0/0 .sbss __ARQ_init_flag */
static BOOL __ARQ_init_flag;
/* 80352094-80352194 34C9D4 0100+00 2/2 0/0 0/0 .text __ARQServiceQueueLo */
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
asm void __ARQServiceQueueLo() {
nofralloc
#include "asm/dolphin/ar/arq/__ARQServiceQueueLo.s"
void __ARQServiceQueueLo(void) {
if ((__ARQRequestPendingLo == NULL) && (__ARQRequestQueueLo)) {
__ARQRequestPendingLo = __ARQRequestQueueLo;
__ARQRequestQueueLo = __ARQRequestQueueLo->next;
}
if (__ARQRequestPendingLo) {
if (__ARQRequestPendingLo->length <= __ARQChunkSize) {
if (__ARQRequestPendingLo->type == ARAM_DIR_MRAM_TO_ARAM)
ARStartDMA(__ARQRequestPendingLo->type, __ARQRequestPendingLo->source,
__ARQRequestPendingLo->destination, __ARQRequestPendingLo->length);
else
ARStartDMA(__ARQRequestPendingLo->type, __ARQRequestPendingLo->destination,
__ARQRequestPendingLo->source, __ARQRequestPendingLo->length);
__ARQCallbackLo = __ARQRequestPendingLo->callback;
} else {
if (__ARQRequestPendingLo->type == ARAM_DIR_MRAM_TO_ARAM)
ARStartDMA(__ARQRequestPendingLo->type, __ARQRequestPendingLo->source,
__ARQRequestPendingLo->destination, __ARQChunkSize);
else
ARStartDMA(__ARQRequestPendingLo->type, __ARQRequestPendingLo->destination,
__ARQRequestPendingLo->source, __ARQChunkSize);
}
__ARQRequestPendingLo->length -= __ARQChunkSize;
__ARQRequestPendingLo->source += __ARQChunkSize;
__ARQRequestPendingLo->destination += __ARQChunkSize;
}
}
#pragma pop
/* 80352194-80352198 34CAD4 0004+00 1/1 0/0 0/0 .text __ARQCallbackHack */
void __ARQCallbackHack() {
@@ -74,46 +104,121 @@ void __ARQCallbackHack() {
}
/* 80352198-80352264 34CAD8 00CC+00 1/1 0/0 0/0 .text __ARQInterruptServiceRoutine */
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
asm void __ARQInterruptServiceRoutine() {
nofralloc
#include "asm/dolphin/ar/arq/__ARQInterruptServiceRoutine.s"
void __ARQInterruptServiceRoutine(void) {
if (__ARQCallbackHi) {
(*__ARQCallbackHi)((u32)__ARQRequestPendingHi);
__ARQRequestPendingHi = NULL;
__ARQCallbackHi = NULL;
}
else if (__ARQCallbackLo)
{
(*__ARQCallbackLo)((u32)__ARQRequestPendingLo);
__ARQRequestPendingLo = NULL;
__ARQCallbackLo = NULL;
}
if (__ARQRequestQueueHi) {
if (__ARQRequestQueueHi->type == 0) {
ARStartDMA(__ARQRequestQueueHi->type, __ARQRequestQueueHi->source,
__ARQRequestQueueHi->destination, __ARQRequestQueueHi->length);
} else {
ARStartDMA(__ARQRequestQueueHi->type, __ARQRequestQueueHi->destination,
__ARQRequestQueueHi->source, __ARQRequestQueueHi->length);
}
__ARQCallbackHi = __ARQRequestQueueHi->callback;
__ARQRequestPendingHi = __ARQRequestQueueHi;
__ARQRequestQueueHi = __ARQRequestQueueHi->next;
}
if (__ARQRequestPendingHi == NULL) {
__ARQServiceQueueLo();
}
}
#pragma pop
/* ############################################################################################## */
/* 803D1C30-803D1C78 02ED50 0045+03 1/0 0/0 0/0 .data @1 */
SECTION_DATA static char lit_1[] = "<< Dolphin SDK - ARQ\trelease build: Apr 5 2004 04:15:04 (0x2301) >>";
/* 80450A50-80450A58 -00001 0004+04 1/1 0/0 0/0 .sdata __ARQVersion */
SECTION_SDATA static void* __ARQVersion[1 + 1 /* padding */] = {
(void*)&lit_1,
/* padding */
NULL,
};
/* 804518FC-80451900 000DFC 0004+00 1/1 0/0 0/0 .sbss __ARQ_init_flag */
static u8 __ARQ_init_flag[4];
/* 80352264-803522D4 34CBA4 0070+00 0/0 1/1 0/0 .text ARQInit */
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
asm void ARQInit() {
nofralloc
#include "asm/dolphin/ar/arq/ARQInit.s"
void ARQInit(void) {
if (__ARQ_init_flag == TRUE) {
return;
}
OSRegisterVersion(__ARQVersion);
__ARQRequestQueueHi = __ARQRequestQueueLo = NULL;
__ARQChunkSize = ARQ_CHUNK_SIZE_DEFAULT;
ARRegisterDMACallback(&__ARQInterruptServiceRoutine);
__ARQRequestPendingHi = NULL;
__ARQRequestPendingLo = NULL;
__ARQCallbackHi = NULL;
__ARQCallbackLo = NULL;
__ARQ_init_flag = TRUE;
}
#pragma pop
/* 803522D4-80352430 34CC14 015C+00 0/0 1/1 0/0 .text ARQPostRequest */
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
asm void ARQPostRequest(ARQRequest* task, u32 owner, u32 type, u32 priority, u32 source,
u32 destination, u32 length, ARQCallback callback) {
nofralloc
#include "asm/dolphin/ar/arq/ARQPostRequest.s"
void ARQPostRequest(ARQRequest* request, u32 owner, u32 type, u32 priority, u32 source, u32 dest,
u32 length, ARQCallback callback) {
BOOL enabled;
request->next = NULL;
request->owner = owner;
request->type = type;
request->source = source;
request->destination = dest;
request->length = length;
if (callback) {
request->callback = callback;
} else {
request->callback = (ARQCallback)&__ARQCallbackHack;
}
enabled = OSDisableInterrupts();
switch (priority) {
case ARQ_PRIORITY_LOW:
if (__ARQRequestQueueLo) {
__ARQRequestTailLo->next = request;
} else {
__ARQRequestQueueLo = request;
}
__ARQRequestTailLo = request;
break;
case ARQ_PRIORITY_HIGH:
if (__ARQRequestQueueHi) {
__ARQRequestTailHi->next = request;
} else {
__ARQRequestQueueHi = request;
}
__ARQRequestTailHi = request;
break;
}
if ((__ARQRequestPendingHi == NULL) && (__ARQRequestPendingLo == NULL)) {
if (__ARQRequestQueueHi) {
if (__ARQRequestQueueHi->type == ARAM_DIR_MRAM_TO_ARAM) {
ARStartDMA(__ARQRequestQueueHi->type, __ARQRequestQueueHi->source,
__ARQRequestQueueHi->destination, __ARQRequestQueueHi->length);
} else {
ARStartDMA(__ARQRequestQueueHi->type, __ARQRequestQueueHi->destination,
__ARQRequestQueueHi->source, __ARQRequestQueueHi->length);
}
__ARQCallbackHi = __ARQRequestQueueHi->callback;
__ARQRequestPendingHi = __ARQRequestQueueHi;
__ARQRequestQueueHi = __ARQRequestQueueHi->next;
}
if (__ARQRequestPendingHi == NULL) {
__ARQServiceQueueLo();
}
}
OSRestoreInterrupts(enabled);
}
#pragma pop
+1 -1
View File
@@ -27,7 +27,7 @@ $(BUILD_DIR)/libs/dolphin/base/%.o: libs/dolphin/base/%.c $(BUILD_DIR)/libs/dolp
@mkdir -p $(@D)
@echo building... $<
@$(ICONV) -f UTF-8 -t CP932 < $< > $(basename $@).c
@$(WINE) tools/mwcc_compiler/1.2.5/mwcceppc.exe $(CFLAGS) $(LIBBASE_A_CFLAGS) $(DEPFLAGS) -c -o $(dir $@) $(basename $@).c
@$(DOLPHIN_LIB_CC) $(CFLAGS) $(LIBBASE_A_CFLAGS) $(DEPFLAGS) -c -o $(dir $@) $(basename $@).c
@if [ -z '$(DISABLE_DEPS)' ]; then tools/transform-dep.py '$(basename $@).d' '$(basename $@).d'; touch -c $@; fi
@echo Frank is fixing $@
@$(PYTHON) $(FRANK) $@ $@ $@
+228 -56
View File
@@ -186,14 +186,23 @@ s32 __CARDReadStatus(s32 chan, u8* status) {
}
/* 80352F34-80353024 34D874 00F0+00 0/0 1/1 0/0 .text __CARDReadVendorID */
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
asm void __CARDReadVendorID() {
nofralloc
#include "asm/dolphin/card/CARDBios/__CARDReadVendorID.s"
s32 __CARDReadVendorID(s32 chan, u16* vendorId) {
BOOL err;
u32 cmd;
if (!EXISelect(chan, 0, 4)) {
return CARD_RESULT_NOCARD;
}
cmd = 0x85000000;
err = FALSE;
err |= !EXIImm(chan, &cmd, 2, 1, NULL);
err |= !EXISync(chan);
err |= !EXIImm(chan, vendorId, 2, 0, NULL);
err |= !EXISync(chan);
err |= !EXIDeselect(chan);
return err ? CARD_RESULT_NOCARD : CARD_RESULT_READY;
}
#pragma pop
/* 80353024-803530D0 34D964 00AC+00 1/1 1/1 0/0 .text __CARDClearStatus */
s32 __CARDClearStatus(s32 chan) {
@@ -237,15 +246,69 @@ static void TimeoutHandler(OSAlarm* alarm, OSContext* context) {
}
}
static inline void SetupTimeoutAlarm(CARDControl* card) {
OSCancelAlarm(&card->alarm);
switch (card->cmd[0]) {
case 0xF2:
OSSetAlarm(&card->alarm, OSMillisecondsToTicks(100), TimeoutHandler);
break;
case 0xF3:
break;
case 0xF4:
if (card->pageSize > 0x80) {
OSSetAlarm(&card->alarm, OSSecondsToTicks((OSTime)2) * (card->cBlock / 0x40),
TimeoutHandler);
break;
}
case 0xF1:
OSSetAlarm(&card->alarm, OSSecondsToTicks((OSTime)2) * (card->sectorSize / 0x2000),
TimeoutHandler);
break;
default:
break;
}
}
/* 80353174-80353414 34DAB4 02A0+00 2/2 0/0 0/0 .text Retry */
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
static asm s32 Retry(s32 chan) {
nofralloc
#include "asm/dolphin/card/CARDBios/Retry.s"
static s32 Retry(s32 chan) {
CARDControl* card;
card = &__CARDBlock[chan];
if (!EXISelect(chan, 0, 4)) {
EXIUnlock(chan);
return CARD_RESULT_NOCARD;
}
SetupTimeoutAlarm(card);
if (!EXIImmEx(chan, card->cmd, card->cmdlen, 1)) {
EXIDeselect(chan);
EXIUnlock(chan);
return CARD_RESULT_NOCARD;
}
if (card->cmd[0] == 0x52 &&
!EXIImmEx(chan, (u8*)card->workArea + sizeof(CARDID), card->latency, 1)) {
EXIDeselect(chan);
EXIUnlock(chan);
return CARD_RESULT_NOCARD;
}
if (card->mode == 0xffffffff) {
EXIDeselect(chan);
EXIUnlock(chan);
return CARD_RESULT_READY;
}
if (!EXIDma(chan, card->buffer, (s32)((card->cmd[0] == 0x52) ? 512 : card->pageSize), card->mode,
__CARDTxHandler)) {
EXIDeselect(chan);
EXIUnlock(chan);
return CARD_RESULT_NOCARD;
}
return CARD_RESULT_READY;
}
#pragma pop
/* 80353414-80353524 34DD54 0110+00 1/1 0/0 0/0 .text UnlockedCallback */
static void UnlockedCallback(s32 chan, s32 result) {
@@ -287,14 +350,43 @@ static void UnlockedCallback(s32 chan, s32 result) {
}
/* 80353524-80353748 34DE64 0224+00 3/3 0/0 0/0 .text __CARDStart */
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
asm s32 __CARDStart(s32 chan, CARDCallback txCallback, CARDCallback exiCallback) {
nofralloc
#include "asm/dolphin/card/CARDBios/__CARDStart.s"
static s32 __CARDStart(s32 chan, CARDCallback txCallback, CARDCallback exiCallback) {
BOOL enabled;
CARDControl* card;
s32 result;
enabled = OSDisableInterrupts();
card = &__CARDBlock[chan];
if (!card->attached) {
result = CARD_RESULT_NOCARD;
} else {
if (txCallback) {
card->txCallback = txCallback;
}
if (exiCallback) {
card->exiCallback = exiCallback;
}
card->unlockCallback = UnlockedCallback;
if (!EXILock(chan, 0, __CARDUnlockedHandler)) {
result = CARD_RESULT_BUSY;
} else {
card->unlockCallback = 0;
if (!EXISelect(chan, 0, 4)) {
EXIUnlock(chan);
result = CARD_RESULT_NOCARD;
} else {
SetupTimeoutAlarm(card);
result = CARD_RESULT_READY;
}
}
}
OSRestoreInterrupts(enabled);
return result;
}
#pragma pop
#define AD1(x) ((u8)(((x) >> 17) & 0x7f))
#define AD1EX(x) ((u8)(AD1(x) | 0x80));
@@ -337,15 +429,19 @@ s32 __CARDReadSegment(s32 chan, CARDCallback callback) {
}
/* 8035387C-803539B8 34E1BC 013C+00 0/0 2/2 0/0 .text __CARDWritePage */
// needs compiler epilogue patch
#ifdef NONMATCH
s32 __CARDWritePage(s32 chan, CARDCallback callback) {
CARDControl* card;
s32 result;
card = &__CARDBlock[chan];
card->cmd[0] = 0xF2;
card->cmd[1] = AD1(card->addr);
if (card->pageSize > 0x80) {
card->cmd[1] = AD1(card->addr) | 0x80;
} else {
card->cmd[1] = AD1(card->addr);
}
card->cmd[2] = AD2(card->addr);
card->cmd[3] = AD3(card->addr);
card->cmd[4] = BA(card->addr);
@@ -358,7 +454,7 @@ s32 __CARDWritePage(s32 chan, CARDCallback callback) {
result = CARD_RESULT_READY;
} else if (result >= 0) {
if (!EXIImmEx(chan, card->cmd, card->cmdlen, 1) ||
!EXIDma(chan, card->buffer, 128, card->mode, __CARDTxHandler)) {
!EXIDma(chan, card->buffer, card->pageSize, card->mode, __CARDTxHandler)) {
card->exiCallback = 0;
EXIDeselect(chan);
EXIUnlock(chan);
@@ -369,26 +465,43 @@ s32 __CARDWritePage(s32 chan, CARDCallback callback) {
}
return result;
}
#else
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
asm s32 __CARDWritePage(s32 chan, CARDCallback callback) {
nofralloc
#include "asm/dolphin/card/CARDBios/__CARDWritePage.s"
}
#pragma pop
#endif
/* 803539B8-80353AC8 34E2F8 0110+00 0/0 6/6 0/0 .text __CARDEraseSector */
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
asm s32 __CARDEraseSector(s32 chan, u32 addr, CARDCallback callback) {
nofralloc
#include "asm/dolphin/card/CARDBios/__CARDEraseSector.s"
s32 __CARDEraseSector(s32 chan, u32 addr, CARDCallback callback) {
CARDControl* card;
s32 result;
card = &__CARDBlock[chan];
if (card->pageSize > 0x80) {
if (callback) {
callback(chan, 0);
}
return 0;
}
card->cmd[0] = 0xF1;
card->cmd[1] = AD1(addr);
card->cmd[2] = AD2(addr);
card->cmdlen = 3;
card->mode = -1;
card->retry = 3;
result = __CARDStart(chan, 0, callback);
if (result == CARD_RESULT_BUSY) {
result = CARD_RESULT_READY;
} else if (result >= 0) {
if (!EXIImmEx(chan, card->cmd, card->cmdlen, 1)) {
card->exiCallback = NULL;
result = CARD_RESULT_NOCARD;
} else {
result = CARD_RESULT_READY;
}
EXIDeselect(chan);
EXIUnlock(chan);
}
return result;
}
#pragma pop
/* ############################################################################################## */
/* 803D1E38-803D1E80 02EF58 0046+02 1/0 0/0 0/0 .data @1 */
@@ -478,26 +591,84 @@ s32 __CARDGetControlBlock(s32 chan, CARDControl** pcard) {
}
/* 80353C6C-80353CD0 34E5AC 0064+00 0/0 24/24 0/0 .text __CARDPutControlBlock */
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
asm s32 __CARDPutControlBlock(CARDControl* card, s32 result) {
nofralloc
#include "asm/dolphin/card/CARDBios/__CARDPutControlBlock.s"
s32 __CARDPutControlBlock(CARDControl* card, s32 result) {
BOOL enabled;
enabled = OSDisableInterrupts();
if (card->attached) {
card->result = result;
} else if (card->result == CARD_RESULT_BUSY) {
card->result = result;
}
OSRestoreInterrupts(enabled);
return result;
}
#pragma pop
/* 80353CD0-80353E20 34E610 0150+00 0/0 1/1 0/0 .text CARDFreeBlocks */
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
asm s32 CARDFreeBlocks(s32 chan, s32* byteNotUsed, s32* filesNotUsed) {
nofralloc
#include "asm/dolphin/card/CARDBios/CARDFreeBlocks.s"
s32 CARDFreeBlocks(s32 chan, s32* byteNotUsed, s32* filesNotUsed) {
CARDControl* card;
s32 result;
u16* fat;
CARDDir* dir;
CARDDir* ent;
u16 fileNo;
result = __CARDGetControlBlock(chan, &card);
if (result < 0) {
return result;
}
fat = __CARDGetFatBlock(card);
dir = __CARDGetDirBlock(card);
if (fat == 0 || dir == 0) {
return __CARDPutControlBlock(card, CARD_RESULT_BROKEN);
}
if (byteNotUsed) {
*byteNotUsed = (s32)(card->sectorSize * fat[CARD_FAT_FREEBLOCKS]);
}
if (filesNotUsed) {
*filesNotUsed = 0;
for (fileNo = 0; fileNo < CARD_MAX_FILE; fileNo++) {
ent = &dir[fileNo];
if (ent->fileName[0] == 0xff) {
++*filesNotUsed;
}
}
}
return __CARDPutControlBlock(card, CARD_RESULT_READY);
}
#pragma pop
/* 80353E20-80353EB8 34E760 0098+00 0/0 7/7 0/0 .text __CARDSync */
#ifdef NONMATCHING
s32 __CARDSync(s32 chan) {
CARDControl* card;
s32 val;
BOOL enabled;
s32 result;
card = &__CARDBlock[chan];
enabled = OSDisableInterrupts();
for (;; ) {
if (chan < 0 || chan >= 2)
result = -0x80;
else
result = card->result;
val = result;
if (val != CARD_RESULT_BUSY){
break;
} else {
OSSleepThread(&card->threadQueue);
}
}
OSRestoreInterrupts(enabled);
return val;
}
#else
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
@@ -506,6 +677,7 @@ asm s32 __CARDSync(s32 chan) {
#include "asm/dolphin/card/CARDBios/__CARDSync.s"
}
#pragma pop
#endif
/* 80353EB8-80353F08 34E7F8 0050+00 1/0 0/0 0/0 .text OnReset */
static s32 OnReset(s32 f) {
+41 -26
View File
@@ -62,18 +62,39 @@ static void WriteCallback(s32 chan, s32 result) {
}
/* 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(s32 chan, s32 result) {
nofralloc
#include "asm/dolphin/card/CARDBlock/EraseCallback.s"
static void EraseCallback(s32 chan, s32 result) {
CARDControl* card;
CARDCallback callback;
u32 temp[2]; /* this compiler sucks */
u16* fat;
u32 addr;
card = &__CARDBlock[chan];
if (result < 0) {
goto error;
}
fat = __CARDGetFatBlock(card);
addr = ((u32)fat - (u32)card->workArea) / CARD_SYSTEM_BLOCK_SIZE * card->sectorSize;
result = __CARDWrite(chan, addr, CARD_SYSTEM_BLOCK_SIZE, fat, WriteCallback);
if (result < 0) {
goto error;
}
return;
error:
if (card->apiCallback == NULL) {
__CARDPutControlBlock(card, result);
}
callback = card->eraseCallback;
if (callback) {
card->eraseCallback = NULL;
callback(chan, result);
}
}
#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;
@@ -122,23 +143,17 @@ s32 __CARDAllocBlock(s32 chan, u32 cBlock, CARDCallback callback) {
return __CARDUpdateFatBlock(chan, fat, callback);
}
#else
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
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 s32 __CARDUpdateFatBlock(s32 chan, u16* fat, CARDCallback callback) {
nofralloc
#include "asm/dolphin/card/CARDBlock/__CARDUpdateFatBlock.s"
s32 __CARDUpdateFatBlock(s32 chan, u16* fat, CARDCallback callback) {
CARDControl* card;
card = &__CARDBlock[chan];
++fat[2];
__CARDCheckSum(fat + 2, 0x1FFC, fat, fat + 1);
DCStoreRange(fat, 0x2000);
card->eraseCallback = callback;
return __CARDEraseSector(chan, (((u32)fat - (u32)card->workArea) / 8192u) * card->sectorSize,
EraseCallback);
}
#pragma pop
+130 -32
View File
@@ -53,34 +53,143 @@ void __CARDCheckSum(void* ptr, int length, u16* checksum, u16* checksumInv) {
}
/* 80355B90-80355E14 3504D0 0284+00 2/2 0/0 0/0 .text VerifyID */
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
static asm s32 VerifyID(CARDControl* card) {
nofralloc
#include "asm/dolphin/card/CARDCheck/VerifyID.s"
static s32 VerifyID(CARDControl* card) {
CARDID* id;
u16 checksum;
u16 checksumInv;
OSSramEx* sramEx;
OSTime rand;
int i;
id = card->workArea;
if (id->deviceID != 0 || id->size != card->size) {
return CARD_RESULT_BROKEN;
}
__CARDCheckSum(id, sizeof(CARDID) - sizeof(u32), &checksum, &checksumInv);
if (id->checkSum != checksum || id->checkSumInv != checksumInv) {
return CARD_RESULT_BROKEN;
}
rand = *(OSTime*)&id->serial[12];
sramEx = __OSLockSramEx();
for (i = 0; i < 12; i++) {
rand = (rand * 1103515245 + 12345) >> 16;
if (id->serial[i] != (u8)(sramEx->flashID[card - __CARDBlock][i] + rand)) {
__OSUnlockSramEx(FALSE);
return CARD_RESULT_BROKEN;
}
rand = ((rand * 1103515245 + 12345) >> 16) & 0x7FFF;
}
__OSUnlockSramEx(FALSE);
if (id->encode != __CARDGetFontEncode()) {
return CARD_RESULT_ENCODING;
}
return CARD_RESULT_READY;
}
#pragma pop
/* 80355E14-80356054 350754 0240+00 2/2 0/0 0/0 .text VerifyDir */
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
static asm s32 VerifyDir(CARDControl* card, int* outCurrent) {
nofralloc
#include "asm/dolphin/card/CARDCheck/VerifyDir.s"
static s32 VerifyDir(CARDControl* card, int* outCurrent) {
CARDDir* dir[2];
CARDDirCheck* check[2];
u16 checkSum;
u16 checkSumInv;
int i;
int errors;
int current;
current = errors = 0;
for (i = 0; i < 2; i++) {
dir[i] = (CARDDir*)((u8*)card->workArea + (1 + i) * CARD_SYSTEM_BLOCK_SIZE);
check[i] = __CARDGetDirCheck(dir[i]);
__CARDCheckSum(dir[i], CARD_SYSTEM_BLOCK_SIZE - sizeof(u32), &checkSum, &checkSumInv);
if (check[i]->checkSum != checkSum || check[i]->checkSumInv != checkSumInv) {
++errors;
current = i;
card->currentDir = 0;
}
}
if (0 == errors) {
if (card->currentDir == 0) {
if ((check[0]->checkCode - check[1]->checkCode) < 0) {
current = 0;
} else {
current = 1;
}
card->currentDir = dir[current];
memcpy(dir[current], dir[current ^ 1], CARD_SYSTEM_BLOCK_SIZE);
} else {
current = (card->currentDir == dir[0]) ? 0 : 1;
}
}
if (outCurrent) {
*outCurrent = current;
}
return errors;
}
#pragma pop
/* 80356054-803562D8 350994 0284+00 2/2 0/0 0/0 .text VerifyFAT */
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
static asm s32 VerifyFAT(CARDControl* card, int* outCurrent) {
nofralloc
#include "asm/dolphin/card/CARDCheck/VerifyFAT.s"
static s32 VerifyFAT(CARDControl* card, int* outCurrent) {
u16* fat[2];
u16* fatp;
u16 nBlock;
u16 cFree;
int i;
u16 checkSum;
u16 checkSumInv;
int errors;
int current;
current = errors = 0;
for (i = 0; i < 2; i++) {
fatp = fat[i] = (u16*)((u8*)card->workArea + (3 + i) * CARD_SYSTEM_BLOCK_SIZE);
__CARDCheckSum(&fatp[CARD_FAT_CHECKCODE], CARD_SYSTEM_BLOCK_SIZE - sizeof(u32), &checkSum,
&checkSumInv);
if (fatp[CARD_FAT_CHECKSUM] != checkSum || fatp[CARD_FAT_CHECKSUMINV] != checkSumInv) {
++errors;
current = i;
card->currentFat = 0;
continue;
}
cFree = 0;
for (nBlock = CARD_NUM_SYSTEM_BLOCK; nBlock < card->cBlock; nBlock++) {
if (fatp[nBlock] == CARD_FAT_AVAIL) {
cFree++;
}
}
if (cFree != fatp[CARD_FAT_FREEBLOCKS]) {
++errors;
current = i;
card->currentFat = 0;
continue;
}
}
if (0 == errors) {
if (card->currentFat == 0) {
if (((s16)fat[0][CARD_FAT_CHECKCODE] - (s16)fat[1][CARD_FAT_CHECKCODE]) < 0) {
current = 0;
} else {
current = 1;
}
card->currentFat = fat[current];
memcpy(fat[current], fat[current ^ 1], CARD_SYSTEM_BLOCK_SIZE);
} else {
current = (card->currentFat == fat[0]) ? 0 : 1;
}
}
if (outCurrent) {
*outCurrent = current;
}
return errors;
}
#pragma pop
/* 803562D8-80356364 350C18 008C+00 0/0 1/1 0/0 .text __CARDVerify */
s32 __CARDVerify(CARDControl* card) {
@@ -105,7 +214,6 @@ s32 __CARDVerify(CARDControl* card) {
}
/* 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];
@@ -235,16 +343,6 @@ s32 CARDCheckExAsync(s32 chan, s32* xferBytes, CARDCallback callback) {
}
return CARD_RESULT_READY;
}
#else
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
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 */
s32 CARDCheck(s32 chan) {
-23
View File
@@ -55,8 +55,6 @@ error:
}
/* 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;
@@ -88,19 +86,8 @@ error:
callback(chan, result);
}
}
#else
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
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;
@@ -123,13 +110,3 @@ s32 __CARDUpdateDir(s32 chan, CARDCallback 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 s32 __CARDUpdateDir(s32 chan, CARDCallback callback) {
nofralloc
#include "asm/dolphin/card/CARDDir/__CARDUpdateDir.s"
}
#pragma pop
#endif
+76 -7
View File
@@ -9,6 +9,7 @@
#include "dolphin/card/card.h"
#include "dolphin/dsp/dsp.h"
#include "dolphin/dvd/dvd.h"
#include "dolphin/vi/vi.h"
#include "dolphin/card/CARDPriv.h"
@@ -68,14 +69,82 @@ error:
}
/* 803575C8-80357C20 351F08 0658+00 1/1 0/0 0/0 .text __CARDFormatRegionAsync */
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
asm s32 __CARDFormatRegionAsync(s32 chan, u16 encode, CARDCallback callback) {
nofralloc
#include "asm/dolphin/card/CARDFormat/__CARDFormatRegionAsync.s"
s32 __CARDFormatRegionAsync(s32 chan, u16 encode, CARDCallback callback) {
CARDControl* card;
CARDID* id;
CARDDir* dir;
u16* fat;
s16 i;
s32 result;
OSSram* sram;
OSSramEx* sramEx;
u16 viDTVStatus;
OSTime time;
OSTime rand;
result = __CARDGetControlBlock(chan, &card);
if (result < 0) {
return result;
}
id = (CARDID*)card->workArea;
memset(id, 0xff, CARD_SYSTEM_BLOCK_SIZE);
viDTVStatus = __VIRegs[55];
id->encode = encode;
sram = __OSLockSram();
*(u32*)&id->serial[20] = sram->counterBias;
*(u32*)&id->serial[24] = sram->language;
__OSUnlockSram(FALSE);
rand = time = OSGetTime();
sramEx = __OSLockSramEx();
for (i = 0; i < 12; i++) {
rand = (rand * 1103515245 + 12345) >> 16;
id->serial[i] = (u8)(sramEx->flashID[chan][i] + rand);
rand = ((rand * 1103515245 + 12345) >> 16) & 0x7FFF;
}
__OSUnlockSramEx(FALSE);
*(u32*)&id->serial[28] = viDTVStatus;
*(OSTime*)&id->serial[12] = time;
id->deviceID = 0;
id->size = card->size;
__CARDCheckSum(id, sizeof(CARDID) - sizeof(u32), &id->checkSum, &id->checkSumInv);
for (i = 0; i < 2; i++) {
CARDDirCheck* check;
dir = (CARDDir*)((u8*)card->workArea + (1 + i) * CARD_SYSTEM_BLOCK_SIZE);
memset(dir, 0xff, CARD_SYSTEM_BLOCK_SIZE);
check = __CARDGetDirCheck(dir);
check->checkCode = i;
__CARDCheckSum(dir, CARD_SYSTEM_BLOCK_SIZE - sizeof(u32), &check->checkSum,
&check->checkSumInv);
}
for (i = 0; i < 2; i++) {
fat = (u16*)((u8*)card->workArea + (3 + i) * CARD_SYSTEM_BLOCK_SIZE);
memset(fat, 0x00, CARD_SYSTEM_BLOCK_SIZE);
fat[CARD_FAT_CHECKCODE] = (u16)i;
fat[CARD_FAT_FREEBLOCKS] = (u16)(card->cBlock - CARD_NUM_SYSTEM_BLOCK);
fat[CARD_FAT_LASTSLOT] = CARD_NUM_SYSTEM_BLOCK - 1;
__CARDCheckSum(&fat[CARD_FAT_CHECKCODE], CARD_SYSTEM_BLOCK_SIZE - sizeof(u32),
&fat[CARD_FAT_CHECKSUM], &fat[CARD_FAT_CHECKSUMINV]);
}
card->apiCallback = callback ? callback : __CARDDefaultApiCallback;
DCStoreRange(card->workArea, CARD_WORKAREA_SIZE);
card->formatStep = 0;
result = __CARDEraseSector(chan, (u32)card->sectorSize * card->formatStep, FormatCallback);
if (result < 0) {
__CARDPutControlBlock(card, result);
}
return result;
}
#pragma pop
/* 80357C20-80357C74 352560 0054+00 0/0 1/1 0/0 .text CARDFormat */
s32 CARDFormat(s32 chan) {
+137 -15
View File
@@ -146,14 +146,133 @@ static u32 LatencyTable[8] = {
};
/* 80356BC8-8035701C 351508 0454+00 2/2 0/0 0/0 .text DoMount */
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
static asm s32 DoMount(s32 chan) {
nofralloc
#include "asm/dolphin/card/CARDMount/DoMount.s"
static s32 DoMount(s32 chan) {
CARDControl* card;
u32 id;
u8 status;
s32 result;
OSSramEx* sram;
int i;
u8 checkSum;
int step;
card = &__CARDBlock[chan];
if (card->mountStep == 0) {
if (EXIGetID(chan, 0, &id) == 0) {
result = CARD_RESULT_NOCARD;
} else if (IsCard(id)) {
result = CARD_RESULT_READY;
} else {
result = CARD_RESULT_WRONGDEVICE;
}
if (result < 0) {
goto error;
}
card->cid = id;
card->size = (u16)(id & 0xFC);
card->sectorSize = SectorSizeTable[(id & 0x00003800) >> 11];
card->cBlock = (u16)((card->size * 1024 * 1024 / 8) / card->sectorSize);
card->latency = LatencyTable[(id & 0x00000700) >> 8];
result = __CARDReadVendorID(chan, &card->vendorID);
if (result < 0) {
goto error;
}
if (CARDGetFastMode() && (card->vendorID >> 8) == 0xec) {
card->pageSize = 0x200;
} else {
card->pageSize = 0x80;
}
result = __CARDClearStatus(chan);
if (result < 0) {
goto error;
}
result = __CARDReadStatus(chan, &status);
if (result < 0) {
goto error;
}
if (!EXIProbe(chan)) {
result = CARD_RESULT_NOCARD;
goto error;
}
if (!(status & 0x40)) {
result = __CARDUnlock(chan, card->id);
if (result < 0) {
goto error;
}
checkSum = 0;
sram = __OSLockSramEx();
for (i = 0; i < 12; i++) {
sram->flashID[chan][i] = card->id[i];
checkSum += card->id[i];
}
sram->flashIDCheckSum[chan] = (u8)~checkSum;
__OSUnlockSramEx(TRUE);
return result;
} else {
card->mountStep = 1;
checkSum = 0;
sram = __OSLockSramEx();
for (i = 0; i < 12; i++) {
checkSum += sram->flashID[chan][i];
}
__OSUnlockSramEx(FALSE);
if (sram->flashIDCheckSum[chan] != (u8)~checkSum) {
result = CARD_RESULT_IOERROR;
goto error;
}
}
}
if (card->mountStep == 1) {
if (card->cid == 0x80000004) {
u16 vendorID;
sram = __OSLockSramEx();
vendorID = *(u16*)sram->flashID[chan];
__OSUnlockSramEx(FALSE);
if (__CARDVendorID == 0xffff || vendorID != __CARDVendorID) {
result = CARD_RESULT_WRONGDEVICE;
goto error;
}
}
card->mountStep = 2;
result = __CARDEnableInterrupt(chan, TRUE);
if (result < 0) {
goto error;
}
EXISetExiCallback(chan, __CARDExiHandler);
EXIUnlock(chan);
DCInvalidateRange(card->workArea, CARD_WORKAREA_SIZE);
}
step = card->mountStep - 2;
result = __CARDRead(chan, (u32)card->sectorSize * step, CARD_SYSTEM_BLOCK_SIZE,
(u8*)card->workArea + (CARD_SYSTEM_BLOCK_SIZE * step), __CARDMountCallback);
if (result < 0) {
__CARDPutControlBlock(card, result);
}
return result;
error:
EXIUnlock(chan);
DoUnmount(chan, result);
return result;
}
#pragma pop
/* 8035701C-80357154 35195C 0138+00 2/2 1/1 0/0 .text __CARDMountCallback */
void __CARDMountCallback(s32 chan, s32 result) {
@@ -266,7 +385,7 @@ s32 CARDMount(s32 chan, void* workArea, CARDCallback attachCb) {
}
/* 8035733C-803573D8 351C7C 009C+00 2/2 0/0 0/0 .text DoUnmount */
static void DoUnmount(s32 chan, s32 result) {
static inline void DoUnmount(s32 chan, s32 result) {
CARDControl* card;
BOOL enabled;
@@ -284,11 +403,14 @@ static void DoUnmount(s32 chan, s32 result) {
}
/* 803573D8-80357484 351D18 00AC+00 0/0 2/2 0/0 .text CARDUnmount */
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
asm s32 CARDUnmount(s32 chan) {
nofralloc
#include "asm/dolphin/card/CARDMount/CARDUnmount.s"
s32 CARDUnmount(s32 chan) {
CARDControl* card;
s32 result;
result = __CARDGetControlBlock(chan, &card);
if (result < 0) {
return result;
}
DoUnmount(chan, CARD_RESULT_NOCARD);
return CARD_RESULT_READY;
}
#pragma pop
+2 -2
View File
@@ -12,10 +12,10 @@
#include "dolphin/card/CARDPriv.h"
/* 80450A70 0002+00 data_80450A70 __CARDVendorID */
SECTION_SDATA u16 __CARDVendorID = 0xFFFF;
u16 __CARDVendorID = 0xFFFF;
/* 80450A72 0006+00 data_80450A72 None */
SECTION_SDATA u8 data_80450A72 = 0x1C;
u8 data_80450A72 = 0x1C;
/* 80359158-8035921C 353A98 00C4+00 0/0 1/1 0/0 .text CARDGetSerialNo */
s32 CARDGetSerialNo(s32 chan, u64* serialNo) {
+105 -35
View File
@@ -41,60 +41,130 @@ BOOL __CARDCompareFileName(CARDDir* ent, const char* fileName) {
}
/* 80357CDC-80357D70 35261C 0094+00 2/2 0/0 0/0 .text __CARDAccess */
#ifdef NONMATCHING
s32 __CARDAccess(CARDControl* card, CARDDir* ent) {
const DVDDiskID* diskId = card->diskID;
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)) {
if (diskId == &__CARDDiskNone ||
(memcmp(ent->gameName, diskId->game_name, 4) == 0 &&
memcmp(ent->company, diskId->company, 2) == 0)) {
return CARD_RESULT_READY;
}
return CARD_RESULT_NOPERM;
}
#else
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
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 s32 __CARDIsWritable(CARDControl* card, CARDDir* ent) {
nofralloc
#include "asm/dolphin/card/CARDOpen/__CARDIsWritable.s"
s32 __CARDIsWritable(CARDControl* card, CARDDir* ent) {
s32 retVal;
const DVDDiskID* diskId = card->diskID;
u8 val;
if ((u8)ent->gameName[0] == 0xFFu) {
retVal = CARD_RESULT_NOFILE;
} else if (diskId == &__CARDDiskNone ||
(memcmp(ent->gameName, diskId->game_name, 4) == 0 &&
memcmp(ent->company, diskId->company, 2) == 0)) {
retVal = CARD_RESULT_READY;
} else {
retVal = CARD_RESULT_NOPERM;
}
if (retVal == CARD_RESULT_NOPERM) {
val = ent->permission & data_80450A72;
if (val & 0x20u && (memcmp(ent->gameName, __CARDDiskNone.game_name, 4) == 0 &&
memcmp(ent->company, __CARDDiskNone.company, 2) == 0)) {
return CARD_RESULT_READY;
} else if (val & 0x40 && (memcmp(ent->gameName, __CARDDiskNone.game_name, 4) == 0 &&
memcmp(ent->company, diskId->company, 2) == 0)) {
return CARD_RESULT_READY;
}
}
return retVal;
}
#pragma pop
/* 80357EA4-80357F98 3527E4 00F4+00 0/0 2/2 0/0 .text __CARDIsReadable */
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
asm s32 __CARDIsReadable(CARDControl* card, CARDDir* ent) {
nofralloc
#include "asm/dolphin/card/CARDOpen/__CARDIsReadable.s"
s32 __CARDIsReadable(CARDControl* card, CARDDir* ent) {
u8 val;
s32 retVal;
const DVDDiskID* diskId = card->diskID;
retVal = __CARDAccess(card, ent);
if (retVal == CARD_RESULT_NOPERM) {
val = ent->permission & data_80450A72;
if (val & 0x20u && (memcmp(ent->gameName, __CARDDiskNone.game_name, 4) == 0 &&
memcmp(ent->company, __CARDDiskNone.company, 2) == 0)) {
retVal = CARD_RESULT_READY;
} else if (val & 0x40 && (memcmp(ent->gameName, __CARDDiskNone.game_name, 4) == 0 &&
memcmp(ent->company, diskId->company, 2) == 0)) {
retVal = CARD_RESULT_READY;
}
}
if (retVal == CARD_RESULT_NOPERM && (ent->permission & 0x4)) {
return CARD_RESULT_READY;
}
return retVal;
}
static inline s32 __CARDGetFileNo(CARDControl* card, const char* fileName, s32* pfileNo) {
CARDDir* dir;
CARDDir* ent;
s32 fileNo;
s32 result;
if (!card->attached) {
return CARD_RESULT_NOCARD;
}
dir = __CARDGetDirBlock(card);
for (fileNo = 0; fileNo < CARD_MAX_FILE; fileNo++) {
ent = &dir[fileNo];
result = __CARDAccess(card, ent);
if (result < 0) {
continue;
}
if (__CARDCompareFileName(ent, fileName)) {
*pfileNo = fileNo;
return CARD_RESULT_READY;
}
}
return CARD_RESULT_NOFILE;
}
#pragma pop
/* 80357F98-803580B4 3528D8 011C+00 0/0 3/3 0/0 .text CARDOpen */
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
asm s32 CARDOpen(s32 chan, const char* fileName, CARDFileInfo* fileInfo) {
nofralloc
#include "asm/dolphin/card/CARDOpen/CARDOpen.s"
s32 CARDOpen(s32 chan, const char* fileName, CARDFileInfo* fileInfo) {
CARDControl* card;
CARDDir* dir;
CARDDir* ent;
s32 result;
s32 fileNo;
fileInfo->chan = -1;
result = __CARDGetControlBlock(chan, &card);
if (result < 0) {
return result;
}
result = __CARDGetFileNo(card, fileName, &fileNo);
if (0 <= result) {
dir = __CARDGetDirBlock(card);
ent = &dir[fileNo];
if (!CARDIsValidBlockNo(card, ent->startBlock)) {
result = CARD_RESULT_BROKEN;
} else {
fileInfo->chan = chan;
fileInfo->fileNo = fileNo;
fileInfo->offset = 0;
fileInfo->iBlock = ent->startBlock;
}
}
return __CARDPutControlBlock(card, result);
}
#pragma pop
/* 803580B4-80358108 3529F4 0054+00 0/0 3/3 0/0 .text CARDClose */
s32 CARDClose(CARDFileInfo* fileInfo) {
+32 -7
View File
@@ -74,14 +74,39 @@ s32 __CARDRead(s32 chan, u32 addr, s32 length, void* dst, CARDCallback callback)
}
/* 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(s32 chan, s32 result) {
nofralloc
#include "asm/dolphin/card/CARDRdwr/BlockWriteCallback.s"
static void BlockWriteCallback(s32 chan, s32 result) {
CARDCallback callback;
CARDControl* card = &__CARDBlock[chan];
if (result < 0) {
goto error;
}
card->xferred += card->pageSize;
card->addr += card->pageSize;
(u8*)card->buffer += card->pageSize;
if (--card->repeat <= 0) {
goto error;
}
result = __CARDWritePage(chan, BlockWriteCallback);
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);
}
}
#pragma pop
/* 803553AC-80355414 34FCEC 0068+00 0/0 4/4 0/0 .text __CARDWrite */
s32 __CARDWrite(s32 chan, u32 addr, s32 length, void* dst, CARDCallback callback) {
+1 -16
View File
@@ -120,7 +120,6 @@ error:
}
/* 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;
@@ -138,10 +137,7 @@ s32 CARDReadAsync(CARDFileInfo* fileInfo, void* buf, s32 length, s32 offset,
dir = __CARDGetDirBlock(card);
ent = &dir[fileInfo->fileNo];
result = __CARDAccess(card, ent);
if (result == CARD_RESULT_NOPERM) {
result = __CARDIsWritable(ent);
}
result = __CARDIsReadable(card, ent);
if (result < 0) {
return __CARDPutControlBlock(card, result);
@@ -159,17 +155,6 @@ s32 CARDReadAsync(CARDFileInfo* fileInfo, void* buf, s32 length, s32 offset,
}
return result;
}
#else
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
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 */
s32 CARDRead(CARDFileInfo* fileInfo, void* buf, s32 length, s32 offset) {
+3 -28
View File
@@ -17,7 +17,7 @@ static void UpdateIconOffsets(CARDDir* ent, CARDStat* stat);
// External References:
//
SECTION_INIT void memcpy();
void memcpy();
void __div2i();
//
@@ -84,7 +84,6 @@ static void UpdateIconOffsets(CARDDir* ent, CARDStat* stat) {
}
/* 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;
@@ -101,10 +100,7 @@ s32 CARDGetStatus(s32 chan, s32 fileNo, CARDStat* stat) {
dir = __CARDGetDirBlock(card);
ent = &dir[fileNo];
result = __CARDAccess(card, ent);
if (result == CARD_RESULT_NOPERM) {
result = __CARDIsWritable(ent);
}
result = __CARDIsReadable(card, ent);
if (result >= 0) {
memcpy(stat->gameName, ent->gameName, sizeof(stat->gameName));
@@ -123,19 +119,8 @@ s32 CARDGetStatus(s32 chan, s32 fileNo, CARDStat* stat) {
}
return __CARDPutControlBlock(card, result);
}
#else
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
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;
@@ -155,7 +140,7 @@ s32 CARDSetStatusAsync(s32 chan, s32 fileNo, CARDStat* stat, CARDCallback callba
dir = __CARDGetDirBlock(card);
ent = &dir[fileNo];
result = __CARDAccess(card, ent);
result = __CARDIsWritable(card, ent);
if (result < 0) {
return __CARDPutControlBlock(card, result);
}
@@ -178,16 +163,6 @@ s32 CARDSetStatusAsync(s32 chan, s32 fileNo, CARDStat* stat, CARDCallback callba
}
return result;
}
#else
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
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 */
s32 CARDSetStatus(s32 chan, s32 fileNo, CARDStat* stat) {
+293 -30
View File
@@ -26,7 +26,7 @@ static void DoneCallback(void* _task);
// External References:
//
SECTION_INIT void memset();
void memset();
void DSPAddTask();
void DSPSendMailToDSP();
@@ -100,15 +100,47 @@ static s32 ReadArrayUnlock(s32 chan, u32 data, void* rbuf, s32 rlen, s32 mode) {
/* 80450A68-80450A70 0004E8 0004+04 2/2 0/0 0/0 .sdata next */
static unsigned long int next = 1;
static inline int CARDRand(void) {
next = next * 1103515245 + 12345;
return (int)((unsigned int)(next / 65536) % 32768);
}
static inline void CARDSrand(unsigned int seed) { next = seed; }
/* 803541D4-80354298 34EB14 00C4+00 2/2 0/0 0/0 .text DummyLen */
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
static asm s32 DummyLen(void) {
nofralloc
#include "asm/dolphin/card/CARDUnlock/DummyLen.s"
static s32 DummyLen(void) {
u32 tick;
u32 wk;
s32 tmp;
u32 max;
wk = 1;
max = 0;
tick = OSGetTick();
CARDSrand(tick);
tmp = CARDRand();
tmp &= 0x0000001f;
tmp += 1;
while ((tmp < 4) && (max < 10)) {
tick = OSGetTick();
tmp = (s32)(tick << wk);
wk++;
if (wk > 16) {
wk = 1;
}
CARDSrand((u32)tmp);
tmp = CARDRand();
tmp &= 0x0000001f;
tmp += 1;
max++;
}
if (tmp < 4) {
tmp = 4;
}
return tmp;
}
#pragma pop
/* ############################################################################################## */
/* 803D1EA0-803D2000 02EFC0 0160+00 1/1 0/0 0/0 .data CardData */
@@ -137,32 +169,263 @@ 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,
};
typedef struct DecodeParameters {
u8* inputAddr;
u32 inputLength;
u32 aramAddr;
u8* outputAddr;
} DecodeParameters;
static inline u32 GetInitVal(void) {
u32 tmp;
u32 tick;
tick = OSGetTick();
CARDSrand(tick);
tmp = 0x7fec8000;
tmp |= CARDRand();
tmp &= 0xfffff000;
return tmp;
}
static inline u32 exnor_1st(u32 data, u32 rshift) {
u32 wk;
u32 w;
u32 i;
w = data;
for (i = 0; i < rshift; i++) {
wk = ~(w ^ (w >> 7) ^ (w >> 15) ^ (w >> 23));
w = (w >> 1) | ((wk << 30) & 0x40000000);
}
return w;
}
static inline u32 exnor(u32 data, u32 lshift) {
u32 wk;
u32 w;
u32 i;
w = data;
for (i = 0; i < lshift; i++) {
// 1bit Left Shift
wk = ~(w ^ (w << 7) ^ (w << 15) ^ (w << 23));
w = (w << 1) | ((wk >> 30) & 0x00000002);
// printf("i=%d, w=%8x\n", i, w);
}
return w;
}
/* 80354298-80354DF0 34EBD8 0B58+00 0/0 1/1 0/0 .text __CARDUnlock */
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
asm s32 __CARDUnlock(s32 chan, u8 flashID[12]) {
nofralloc
#include "asm/dolphin/card/CARDUnlock/__CARDUnlock.s"
s32 __CARDUnlock(s32 chan, u8 flashID[12]) {
u32 init_val;
u32 data;
s32 dummy;
s32 rlen;
u32 rshift;
u8 fsts;
u32 wk, wk1;
u32 Ans1 = 0;
u32 Ans2 = 0;
u32* dp;
u8 rbuf[64];
u32 para1A = 0;
u32 para1B = 0;
u32 para2A = 0;
u32 para2B = 0;
CARDControl* card;
DSPTaskInfo* task;
DecodeParameters* param;
u8* input;
u8* output;
card = &__CARDBlock[chan];
task = &card->task;
param = (DecodeParameters*)card->workArea;
input = (u8*)((u8*)param + sizeof(DecodeParameters));
input = (u8*)OSRoundUp32B(input);
output = input + 32;
fsts = 0;
init_val = GetInitVal();
dummy = DummyLen();
rlen = dummy;
if (ReadArrayUnlock(chan, init_val, rbuf, rlen, 0) < 0) {
return CARD_RESULT_NOCARD;
}
rshift = (u32)(dummy * 8 + 1);
wk = exnor_1st(init_val, rshift);
wk1 = ~(wk ^ (wk >> 7) ^ (wk >> 15) ^ (wk >> 23));
card->scramble = (wk | ((wk1 << 31) & 0x80000000));
card->scramble = bitrev(card->scramble);
dummy = DummyLen();
rlen = 20 + dummy;
data = 0;
if (ReadArrayUnlock(chan, data, rbuf, rlen, 1) < 0) {
return CARD_RESULT_NOCARD;
}
dp = (u32*)rbuf;
para1A = *dp++;
para1B = *dp++;
Ans1 = *dp++;
para2A = *dp++;
para2B = *dp++;
para1A = (para1A ^ card->scramble);
rshift = 32;
wk = exnor(card->scramble, rshift);
wk1 = ~(wk ^ (wk << 7) ^ (wk << 15) ^ (wk << 23));
card->scramble = (wk | ((wk1 >> 31) & 0x00000001));
para1B = (para1B ^ card->scramble);
rshift = 32;
wk = exnor(card->scramble, rshift);
wk1 = ~(wk ^ (wk << 7) ^ (wk << 15) ^ (wk << 23));
card->scramble = (wk | ((wk1 >> 31) & 0x00000001));
Ans1 ^= card->scramble;
rshift = 32;
wk = exnor(card->scramble, rshift);
wk1 = ~(wk ^ (wk << 7) ^ (wk << 15) ^ (wk << 23));
card->scramble = (wk | ((wk1 >> 31) & 0x00000001));
para2A = (para2A ^ card->scramble);
rshift = 32;
wk = exnor(card->scramble, rshift);
wk1 = ~(wk ^ (wk << 7) ^ (wk << 15) ^ (wk << 23));
card->scramble = (wk | ((wk1 >> 31) & 0x00000001));
para2B = (para2B ^ card->scramble);
rshift = (u32)(dummy * 8);
wk = exnor(card->scramble, rshift);
wk1 = ~(wk ^ (wk << 7) ^ (wk << 15) ^ (wk << 23));
card->scramble = (wk | ((wk1 >> 31) & 0x00000001));
rshift = 32 + 1;
wk = exnor(card->scramble, rshift);
wk1 = ~(wk ^ (wk << 7) ^ (wk << 15) ^ (wk << 23));
card->scramble = (wk | ((wk1 >> 31) & 0x00000001));
*(u32*)&input[0] = para2A;
*(u32*)&input[4] = para2B;
param->inputAddr = input;
param->inputLength = 8;
param->outputAddr = output;
param->aramAddr = 0;
DCFlushRange(input, 8);
DCInvalidateRange(output, 4);
DCFlushRange(param, sizeof(DecodeParameters));
task->priority = 255;
task->iram_mmem_addr = (u16*)OSPhysicalToCached(CardData);
task->iram_length = 0x160;
task->iram_addr = 0;
task->dsp_init_vector = 0x10;
task->init_cb = InitCallback;
task->res_cb = NULL;
task->done_cb = DoneCallback;
task->req_cb = NULL;
DSPAddTask(task);
dp = (u32*)flashID;
*dp++ = para1A;
*dp++ = para1B;
*dp = Ans1;
return CARD_RESULT_READY;
}
#pragma pop
/* 80354DF0-80354E60 34F730 0070+00 1/1 0/0 0/0 .text InitCallback */
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
static asm void InitCallback(void* _task) {
nofralloc
#include "asm/dolphin/card/CARDUnlock/InitCallback.s"
static void InitCallback(void* _task) {
s32 chan;
CARDControl* card;
DSPTaskInfo* task;
DecodeParameters* param;
task = _task;
for (chan = 0; chan < 2; ++chan) {
card = &__CARDBlock[chan];
if ((DSPTaskInfo*)&card->task == task) {
break;
}
}
param = (DecodeParameters*)card->workArea;
DSPSendMailToDSP(0xff000000);
while (DSPCheckMailToDSP())
;
DSPSendMailToDSP((u32)param);
while (DSPCheckMailToDSP())
;
}
#pragma pop
/* 80354E60-80355184 34F7A0 0324+00 1/1 0/0 0/0 .text DoneCallback */
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
static asm void DoneCallback(void* _task) {
nofralloc
#include "asm/dolphin/card/CARDUnlock/DoneCallback.s"
}
#pragma pop
static void DoneCallback(void* _task) {
u8 rbuf[64];
u32 data;
s32 dummy;
s32 rlen;
u32 rshift;
u8 unk;
u32 wk, wk1;
u32 Ans2;
s32 chan;
CARDControl* card;
s32 result;
DSPTaskInfo* task;
DecodeParameters* param;
u8* input;
u8* output;
task = _task;
for (chan = 0; chan < 2; ++chan) {
card = &__CARDBlock[chan];
if ((DSPTaskInfo*)&card->task == task) {
break;
}
}
param = (DecodeParameters*)card->workArea;
input = (u8*)((u8*)param + sizeof(DecodeParameters));
input = (u8*)OSRoundUp32B(input);
output = input + 32;
Ans2 = *(u32*)output;
dummy = DummyLen();
rlen = dummy;
data = ((Ans2 ^ card->scramble) & 0xffff0000);
if (ReadArrayUnlock(chan, data, rbuf, rlen, 1) < 0) {
EXIUnlock(chan);
__CARDMountCallback(chan, CARD_RESULT_NOCARD);
return;
}
rshift = (u32)((dummy + 4 + card->latency) * 8 + 1);
wk = exnor(card->scramble, rshift);
wk1 = ~(wk ^ (wk << 7) ^ (wk << 15) ^ (wk << 23));
card->scramble = (wk | ((wk1 >> 31) & 0x00000001));
dummy = DummyLen();
rlen = dummy;
data = (((Ans2 << 16) ^ card->scramble) & 0xffff0000);
if (ReadArrayUnlock(chan, data, rbuf, rlen, 1) < 0) {
EXIUnlock(chan);
__CARDMountCallback(chan, CARD_RESULT_NOCARD);
return;
}
result = __CARDReadStatus(chan, &unk);
if (!EXIProbe(chan)) {
EXIUnlock(chan);
__CARDMountCallback(chan, CARD_RESULT_NOCARD);
return;
}
if (result == CARD_RESULT_READY && !(unk & 0x40)) {
EXIUnlock(chan);
result = CARD_RESULT_IOERROR;
}
__CARDMountCallback(chan, result);
}
+71 -14
View File
@@ -29,24 +29,81 @@ void __div2i();
//
/* 80358914-80358A84 353254 0170+00 1/1 0/0 0/0 .text WriteCallback */
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
static asm void WriteCallback(s32 chan, s32 result) {
nofralloc
#include "asm/dolphin/card/CARDWrite/WriteCallback.s"
static void WriteCallback(s32 chan, s32 result) {
CARDControl* card;
CARDCallback callback;
u16* fat;
CARDDir* dir;
CARDDir* ent;
CARDFileInfo* fileInfo;
card = &__CARDBlock[chan];
if (result < 0) {
goto error;
}
fileInfo = card->fileInfo;
if (fileInfo->length < 0) {
result = CARD_RESULT_CANCELED;
goto error;
}
fileInfo->length -= card->sectorSize;
if (fileInfo->length <= 0) {
dir = __CARDGetDirBlock(card);
ent = &dir[fileInfo->fileNo];
ent->time = (u32)OSTicksToSeconds(OSGetTime());
callback = card->apiCallback;
card->apiCallback = 0;
result = __CARDUpdateDir(chan, callback);
} else {
fat = __CARDGetFatBlock(card);
fileInfo->offset += card->sectorSize;
fileInfo->iBlock = fat[fileInfo->iBlock];
if (!CARDIsValidBlockNo(card, fileInfo->iBlock)) {
result = CARD_RESULT_BROKEN;
goto error;
}
result = __CARDEraseSector(chan, card->sectorSize * (u32)fileInfo->iBlock, EraseCallback);
}
if (result < 0) {
goto error;
}
return;
error:
callback = card->apiCallback;
card->apiCallback = 0;
__CARDPutControlBlock(card, result);
callback(chan, result);
}
#pragma pop
/* 80358A84-80358B34 3533C4 00B0+00 2/2 0/0 0/0 .text EraseCallback */
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
static asm void EraseCallback(s32 chan, s32 result) {
nofralloc
#include "asm/dolphin/card/CARDWrite/EraseCallback.s"
static void EraseCallback(s32 chan, s32 result) {
CARDControl* card;
CARDCallback callback;
CARDFileInfo* fileInfo;
card = &__CARDBlock[chan];
if (result < 0) {
goto error;
}
fileInfo = card->fileInfo;
result = __CARDWrite(chan, card->sectorSize * (u32)fileInfo->iBlock, card->sectorSize,
card->buffer, WriteCallback);
if (result < 0) {
goto error;
}
return;
error:
callback = card->apiCallback;
card->apiCallback = 0;
__CARDPutControlBlock(card, result);
callback(chan, result);
}
#pragma pop
/* 80358B34-80358C48 353474 0114+00 1/1 0/0 0/0 .text CARDWriteAsync */
s32 CARDWriteAsync(CARDFileInfo* fileInfo, const void* buf, s32 length, s32 offset,
+7 -3
View File
@@ -34,12 +34,15 @@ LIBCARD_A_O_FILES := \
$(BUILD_DIR)/libs/dolphin/card/CARDStat.o \
$(BUILD_DIR)/libs/dolphin/card/CARDNet.o \
LIBCARD_A_CFLAGS := \
NO_INLINE_FILES = libs/dolphin/card/CARDOpen.c
LIBCARD_A_CFLAGS = \
-Cpp_exceptions off \
-proc gekko \
-fp hard \
-nodefaults \
-str reuse \
$(if $(filter $(NO_INLINE_FILES), $<),,-inline auto) \
-RTTI off \
-maxerrors 5 \
-enum int $(INCLUDES) \
@@ -61,10 +64,11 @@ $(BUILD_DIR)/libs/dolphin/card/%.o: libs/dolphin/card/%.c $(BUILD_DIR)/libs/dolp
@mkdir -p $(@D)
@echo building... $<
@$(ICONV) -f UTF-8 -t CP932 < $< > $(basename $@).c
@$(WINE) tools/mwcc_compiler/1.2.5/mwcceppc.exe $(LIBCARD_A_CFLAGS) $(DEPFLAGS) -c -o $(dir $@) $(basename $@).c
@$(FRANK_CC) $(LIBCARD_A_CFLAGS) -c -o $(@:.o=.po) $(basename $@).c
@$(DOLPHIN_LIB_CC) $(LIBCARD_A_CFLAGS) $(DEPFLAGS) -c -o $(dir $@) $(basename $@).c
@if [ -z '$(DISABLE_DEPS)' ]; then tools/transform-dep.py '$(basename $@).d' '$(basename $@).d'; touch -c $@; fi
@echo Frank is fixing $@
@$(PYTHON) $(FRANK) $@ $@ $@
@$(PYTHON) $(FRANK) $@ $(@:.o=.po) $@
ifndef DISABLE_DEPS
LIBCARD_A_D_FILES := $(LIBCARD_A_O_FILES:.o=.d)

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