1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
#include <dolphin/card.h>
#include <dolphin/dsp.h>
#include <dolphin/dvd.h>
#include <dolphin/os.h>
#include <dolphin/CARDPriv.h>
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;
}
s32 __CARDAccess(CARDControl* card, CARDDir* ent) {
if (ent->gameName[0] == 0xFF) {
return CARD_RESULT_NOFILE;
}
if (card->diskID == &__CARDDiskNone || (memcmp(ent->gameName, card->diskID->gameName, 4) == 0 &&
memcmp(ent->company, card->diskID->company, 2) == 0)) {
return CARD_RESULT_READY;
}
return CARD_RESULT_NOPERM;
}
BOOL __CARDIsWritable(CARDDir* ent) {
if (ent->gameName[0] == 0xFF) {
return CARD_RESULT_NOFILE;
}
if ((ent->permission & CARD_ATTR_PUBLIC) != 0) {
return CARD_RESULT_READY;
}
return CARD_RESULT_NOPERM;
}
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;
}
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);
}
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);
}
BOOL __CARDIsOpened(CARDControl* card, s32 fileNo) { return FALSE; }
|