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