1 /*---------------------------------------------------------------------------*
2   Project:  CARD API attach test
3   File:     attach.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: format.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     2     01/02/22 13:02 Shiki
22     Added support for multiple sector sizes.
23 
24     1     11/28/00 2:13p Tian
25     Moved from card tests directories.
26 
27     2     9/06/00 8:23p Shiki
28     Revised to use EXIProbe() first.
29 
30     1     7/14/00 4:16p Shiki
31     Initial check-in.
32   $NoKeywords: $
33  *---------------------------------------------------------------------------*/
34 
35 #include <revolution.h>
36 
37 #define CARD_CHAN   1
38 
39 u8 CardWorkArea[CARD_WORKAREA_SIZE] ATTRIBUTE_ALIGN(32);
40 
main(void)41 int main(void)
42 {
43     s32 result;
44     u16 encode;
45     u16 size;
46     u32 sectorSize;
47 
48     OSInit();
49     CARDInit();
50 
51     // Probe
52     OSReport("Insert card in slot %c.\n", "AB"[CARD_CHAN]);
53     while (!CARDProbe(CARD_CHAN))
54     {
55         ;
56     }
57 
58     // Mount
59     OSReport("CARDMount ");
60     result = CARDMountAsync(CARD_CHAN, CardWorkArea, 0, 0);
61     if (result < 0)
62     {
63         OSReport("failed. (%d)\n", result);
64         return 1;
65     }
66     while ((result = CARDGetResultCode(CARD_CHAN)) == CARD_RESULT_BUSY)
67     {
68         ;
69     }
70     switch (result)
71     {
72       case CARD_RESULT_READY:
73         OSReport("done. (%d)\n", result);
74         break;
75       case CARD_RESULT_BROKEN:
76       case CARD_RESULT_ENCODING:
77         OSReport("failed. (%d)\n", result);
78         break;
79       default:
80         OSReport("failed. (%d)\n", result);
81         return 1;
82         break;
83     }
84 
85     // Format
86     OSReport("CARDFormat ");
87     result = CARDFormatAsync(CARD_CHAN, 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     if (result < 0)
98     {
99         OSReport("failed. (%d)\n", result);
100         return 1;
101     }
102     OSReport("done. (%d)\n", result);
103 
104     result = CARDGetEncoding(CARD_CHAN, &encode);
105     if (0 <= result)
106     {
107         OSReport("Character encoding: %s(%d)\n",
108                  encode == CARD_ENCODE_SJIS ? "SJIS" : "ANSI", encode);
109     }
110 
111     // Memory size
112     result = CARDGetMemSize(CARD_CHAN, &size);
113     if (result < 0)
114     {
115         OSReport("CARDGetMemSize() failed. (%d)\n", result);
116         return 1;
117     }
118     OSReport("%u Mbits memory card.\n", size);
119 
120     // Sector size
121     result = CARDGetSectorSize(CARD_CHAN, &sectorSize);
122     if (result < 0)
123     {
124         OSReport("CARDGetSectorSize() failed. (%d)\n", result);
125         return 1;
126     }
127     OSReport("Sector size %u bytes.\n", sectorSize);
128 
129     // Unmount
130     CARDUnmount(CARD_CHAN);
131 
132     return 0;
133 }
134