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