mirror of https://github.com/PrimeDecomp/prime.git
Link CARDRdwr.c
This commit is contained in:
parent
58d5c4a816
commit
b0405b7673
|
@ -11,6 +11,8 @@ extern "C" {
|
|||
#define CARD_FAT_FREEBLOCKS 0x0003u
|
||||
#define CARD_FAT_LASTSLOT 0x0004u
|
||||
|
||||
#define CARD_SEG_SIZE 512u
|
||||
|
||||
#define CARD_NUM_SYSTEM_BLOCK 5
|
||||
#define CARD_SYSTEM_BLOCK_SIZE (8 * 1024u)
|
||||
|
||||
|
|
|
@ -817,7 +817,7 @@ DTK_FILES :=\
|
|||
CARD_FILES :=\
|
||||
$(BUILD_DIR)/asm/Dolphin/card/CARDBios.o\
|
||||
$(BUILD_DIR)/src/Dolphin/card/CARDUnlock.ep.o\
|
||||
$(BUILD_DIR)/asm/Dolphin/card/CARDRdwr.o\
|
||||
$(BUILD_DIR)/src/Dolphin/card/CARDRdwr.ep.o\
|
||||
$(BUILD_DIR)/asm/Dolphin/card/CARDBlock.o\
|
||||
$(BUILD_DIR)/asm/Dolphin/card/CARDDir.o\
|
||||
$(BUILD_DIR)/asm/Dolphin/card/CARDCheck.o\
|
||||
|
|
|
@ -0,0 +1,104 @@
|
|||
#include <dolphin/card.h>
|
||||
#include <dolphin/dsp.h>
|
||||
#include <dolphin/dvd.h>
|
||||
#include <dolphin/os.h>
|
||||
|
||||
#include <dolphin/CARDPriv.h>
|
||||
|
||||
static void BlockReadCallback(s32 chan, s32 result) {
|
||||
CARDControl* card;
|
||||
CARDCallback callback;
|
||||
|
||||
card = &__CARDBlock[chan];
|
||||
if (result < 0) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
card->xferred += 0x200;
|
||||
|
||||
card->addr += 0x200;
|
||||
(u8*)card->buffer += 0x200;
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
static void BlockWriteCallback(s32 chan, s32 result) {
|
||||
CARDControl* card;
|
||||
CARDCallback callback;
|
||||
|
||||
card = &__CARDBlock[chan];
|
||||
if (result < 0) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
card->xferred += 128;
|
||||
|
||||
card->addr += 128;
|
||||
(u8*)card->buffer += 128;
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
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 / 128u);
|
||||
card->addr = addr;
|
||||
card->buffer = dst;
|
||||
|
||||
return __CARDWritePage(chan, BlockWriteCallback);
|
||||
}
|
Loading…
Reference in New Issue