1 /*---------------------------------------------------------------------------*
2 Project: CARD API stat test
3 File: list.c
4
5 Copyright 2000 Nintendo. All rights reserved.
6
7 These coded instructions, statements, and computer programs contain
8 proprietary information of Nintendo of America Inc. and/or Nintendo
9 Company Ltd., and are protected by Federal copyright law. They may
10 not be disclosed to third parties or copied or duplicated in any form,
11 in whole or in part, without the prior written consent of Nintendo.
12
13 $Log: list.c,v $
14 Revision 1.2 02/20/2006 04:13:08 mitu
15 changed include path from dolphin/ to revolution/.
16
17 Revision 1.1 01/31/2006 10:48:30 mitu
18 (none)
19
20
21 4 01/04/23 14:56 Shiki
22 Fixed OSReport().
23
24 3 01/04/23 14:40 Shiki
25 Removed CARDStat.gameVersion.
26
27 2 01/02/22 13:01 Shiki
28 Added support for multiple sector sizes.
29
30 1 11/28/00 2:13p Tian
31 Moved from card tests directories.
32
33 7 10/31/00 4:49p Shiki
34 Modified to call CARDCheck().
35
36 6 9/14/00 8:17p Shiki
37 Revised to use localtime().
38
39 5 9/08/00 6:30p Shiki
40 Fixed to check mount result code more strictly.
41
42 4 9/06/00 8:23p Shiki
43 Revised to use EXIProbe() first.
44
45 3 8/10/00 4:39p Shiki
46 Modified CARDStat.length from u8 to u32.
47
48 2 8/08/00 5:23p Shiki
49 Improved the output format.
50
51 1 7/14/00 4:16p Shiki
52 Initial check-in.
53 $NoKeywords: $
54 *---------------------------------------------------------------------------*/
55
56 #include <revolution.h>
57
58 #define CARD_CHAN 1
59
60 u8 CardWorkArea[CARD_WORKAREA_SIZE] ATTRIBUTE_ALIGN(32);
61
main(void)62 int main(void)
63 {
64 s32 result;
65 CARDStat stat;
66 u16 fileNo;
67 s32 byteNotUsed;
68 s32 filesNotUsed;
69 u32 sectorSize;
70 OSCalendarTime ct;
71
72 OSInit();
73 CARDInit();
74
75 // Probe
76 OSReport("Insert card in slot %c.\n", "AB"[CARD_CHAN]);
77 while (!CARDProbe(CARD_CHAN))
78 {
79 ;
80 }
81
82 // Mount
83 OSReport("CARDMount ");
84 result = CARDMountAsync(CARD_CHAN, CardWorkArea, 0, 0);
85 if (result < 0)
86 {
87 OSReport("failed. (%d)\n", result);
88 return 1;
89 }
90 while ((result = CARDGetResultCode(CARD_CHAN)) == CARD_RESULT_BUSY)
91 {
92 ;
93 }
94 switch (result)
95 {
96 case CARD_RESULT_READY:
97 case CARD_RESULT_BROKEN:
98 OSReport("done. (%d)\n", result);
99 OSReport("CARDCheck ");
100 result = CARDCheckAsync(CARD_CHAN, 0);
101 if (result < 0)
102 {
103 CARDUnmount(CARD_CHAN);
104 OSReport("failed. (%d)\n", result);
105 return 1;
106 }
107 while ((result = CARDGetResultCode(CARD_CHAN)) == CARD_RESULT_BUSY)
108 {
109 ;
110 }
111 break;
112 }
113 switch (result)
114 {
115 case CARD_RESULT_READY:
116 OSReport("done. (%d)\n", result);
117 break;
118 case CARD_RESULT_BROKEN:
119 case CARD_RESULT_ENCODING:
120 CARDUnmount(CARD_CHAN);
121 OSReport("failed. (%d)\n", result);
122 return 1;
123 break;
124 default:
125 OSReport("failed. (%d)\n", result);
126 return 1;
127 break;
128 }
129
130 // List
131 OSReport("no. game com. length fileName date time\n");
132 for (fileNo = 0; fileNo < CARD_MAX_FILE; fileNo++)
133 {
134 result = CARDGetStatus(CARD_CHAN, fileNo, &stat);
135 if (result < 0)
136 {
137 continue;
138 }
139 OSReport("%3d ", fileNo);
140 OSReport("%-4.4s ", stat.gameName);
141 OSReport("%-2.2s ", stat.company);
142 OSReport("%-8d ", stat.length);
143 OSReport("%-32.32s ", stat.fileName);
144
145 OSTicksToCalendarTime(OSSecondsToTicks((OSTime) stat.time), &ct);
146 OSReport("%02.2d/%02.2d/%02.2d %02.2d:%02.2d:%02.2d\n",
147 ct.mon + 1, ct.mday, ct.year % 100,
148 ct.hour, ct.min, ct.sec);
149 }
150
151 // Sector size
152 result = CARDGetSectorSize(CARD_CHAN, §orSize);
153 if (result < 0)
154 {
155 OSReport("CARDGetSectorSize() failed. (%d)\n", result);
156 CARDUnmount(CARD_CHAN);
157 return 1;
158 }
159 OSReport("Sector size %u bytes.\n", sectorSize);
160
161 // FreeBlocks
162 OSReport("CARDFreeBlocks ");
163 result = CARDFreeBlocks(CARD_CHAN, &byteNotUsed, &filesNotUsed);
164 if (result < 0)
165 {
166 OSReport("failed. (%d)\n", result);
167 CARDUnmount(CARD_CHAN);
168 return 1;
169 }
170 OSReport("done. (%d)\n", result);
171 OSReport("%d bytes (%d blocks) free.\n%d files free.\n", byteNotUsed, byteNotUsed / sectorSize, filesNotUsed);
172
173 // Unmount
174 CARDUnmount(CARD_CHAN);
175
176 return 0;
177 }
178