1 /*---------------------------------------------------------------------------*
2   Project:  CARD API create test
3   File:     create.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: create.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:40 Shiki
22     Removed CARDStat.gameVersion.
23 
24     3     01/02/22 13:00 Shiki
25     Added support for multiple sector sizes.
26 
27     2     12/08/00 7:01p Shiki
28     Fixed to call CARDCheck(), etc.
29 
30     1     11/28/00 2:13p Tian
31     Moved from card tests directories.
32 
33     3     9/08/00 6:34p Shiki
34     Fixed to check mount result code more strictly.
35 
36     2     9/06/00 8:23p Shiki
37     Revised to use EXIProbe() first.
38 
39     1     7/14/00 4:16p Shiki
40     Initial check-in.
41   $NoKeywords: $
42  *---------------------------------------------------------------------------*/
43 
44 #include <revolution.h>
45 
46 #define CARD_CHAN   1
47 
48 u8 CardWorkArea[CARD_WORKAREA_SIZE] ATTRIBUTE_ALIGN(32);
49 
main(int argc,char * argv[])50 int main(int argc, char* argv[])
51 {
52     s32          result;
53     CARDFileInfo fileInfo;
54     CARDStat     stat;
55     u32          sectorSize;
56 
57     OSInit();
58     CARDInit();
59 
60     if (argc != 2)
61     {
62         OSReport("Usage: create filename\n");
63         return 1;
64     }
65 
66     // Probe
67     OSReport("Insert card in slot %c.\n", "AB"[CARD_CHAN]);
68     while (!CARDProbe(CARD_CHAN))
69     {
70         ;
71     }
72 
73     // Mount
74     OSReport("CARDMount ");
75     result = CARDMountAsync(CARD_CHAN, CardWorkArea, 0, 0);
76     if (result < 0)
77     {
78         OSReport("failed. (%d)\n", result);
79         return 1;
80     }
81     while ((result = CARDGetResultCode(CARD_CHAN)) == CARD_RESULT_BUSY)
82     {
83         ;
84     }
85     switch (result)
86     {
87       case CARD_RESULT_READY:
88       case CARD_RESULT_BROKEN:
89         OSReport("done. (%d)\n", result);
90         OSReport("CARDCheck ");
91         result = CARDCheckAsync(CARD_CHAN, 0);
92         if (result < 0)
93         {
94             CARDUnmount(CARD_CHAN);
95             OSReport("failed. (%d)\n", result);
96             return 1;
97         }
98         while ((result = CARDGetResultCode(CARD_CHAN)) == CARD_RESULT_BUSY)
99         {
100             ;
101         }
102         break;
103     }
104     switch (result)
105     {
106       case CARD_RESULT_READY:
107         OSReport("done. (%d)\n", result);
108         break;
109       case CARD_RESULT_BROKEN:
110       case CARD_RESULT_ENCODING:
111         CARDUnmount(CARD_CHAN);
112         OSReport("failed. (%d)\n", result);
113         return 1;
114         break;
115       default:
116         OSReport("failed. (%d)\n", result);
117         return 1;
118         break;
119     }
120 
121     // Sector size
122     result = CARDGetSectorSize(CARD_CHAN, &sectorSize);
123     if (result < 0)
124     {
125         OSReport("CARDGetSectorSize() failed. (%d)\n", result);
126         return 1;
127     }
128     OSReport("Sector size %d bytes.\n", sectorSize);
129 
130     // Create
131     OSReport("CARDCreate ");
132     result = CARDCreateAsync(CARD_CHAN, argv[1], sectorSize, &fileInfo, 0);
133     if (result < 0)
134     {
135         OSReport("failed. (%d)\n", result);
136         return 1;
137     }
138     while ((result = CARDGetResultCode(CARD_CHAN)) == CARD_RESULT_BUSY)
139     {
140         ;
141     }
142     OSReport("done. (%d:%d:%d)\n", result, fileInfo.chan, fileInfo.fileNo);
143 
144     // Stat
145     OSReport("CARDGetStatus ");
146     result = CARDGetStatus(CARD_CHAN, fileInfo.fileNo, &stat);
147     if (result < 0)
148     {
149         OSReport("failed. (%d)\n", result);
150         return 1;
151     }
152     OSReport("gameName %.4s\n",  stat.gameName);
153     OSReport("company %.2s\n",   stat.company);
154     OSReport("length %d\n",      stat.length);
155     OSReport("fileName %.32s\n", stat.fileName);
156     OSReport("time %d\n",        stat.time);
157 
158     // Close
159     CARDClose(&fileInfo);
160 
161     // Unmount
162     CARDUnmount(CARD_CHAN);
163 
164     return 0;
165 }
166