1 /*---------------------------------------------------------------------------*
2 Project: DARCH Test
3 File: darchtest.c
4
5 Copyright (C) 2007 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: darchdemo.c,v $
14 Revision 1.1.2.1 2009/01/15 07:32:15 nakano_yoshinobu
15 Fixed darchD.exe to darch.exe.
16
17 Revision 1.1 2008/05/12 07:42:27 nakano_yoshinobu
18 Moved from tests.
19
20 Revision 1.6 2007/10/12 00:47:58 nakano_yoshinobu
21 (none)
22
23 Revision 1.3.4.1 2007/10/10 02:58:28 nakano_yoshinobu
24 Added comments.
25
26 Revision 1.5 2007/10/03 05:14:38 nakano_yoshinobu
27 Fixed DARCHTEST_ARC_FILE_NAME and fileInfo.
28
29 Revision 1.4 2007/08/29 12:12:35 nakano_yoshinobu
30 Added GetFileInfo() and CompTest().
31
32 Revision 1.3 2007/06/04 00:56:15 ooizumi
33 Added comments.
34
35 Revision 1.2 2007/05/31 11:11:42 ooizumi
36 Fixed.
37
38 $NoKeywords: $
39 *---------------------------------------------------------------------------*/
40
41 #include <string.h>
42
43 #include <revolution.h>
44
45 #include <revolution/darch.h>
46
47 // for DARCH TEST
48 #define DARCH_COMP_TEST
49 #define DARCHTEST_ARC_FILE_NAME "darchdemo/darchdemo.arc"
50
51
52 /*---------------------------------------------------------------------------*
53 Name: fileInfo
54
55 Description: file information list to archive
56
57 *---------------------------------------------------------------------------*/
58
59 DARCHFileInfo fileInfo[] =
60 {
61 { "darchdemo/test1/wii.tpl", NULL, 0 },
62 { "darchdemo/test1/yoshi.tpl", NULL, 0 },
63 { "darchdemo/test2/clrbars7.BMP", NULL, 0 },
64 { "darchdemo/test2/dump.bmp", NULL, 0 },
65 { "darchdemo/test2/gray256b.BMP", NULL, 0 },
66 { "darchdemo/test2/gray3.BMP", NULL, 0 },
67 { "darchdemo/test2/marina2.BMP", NULL, 0 },
68 { "darchdemo/test2/rainbow.BMP", NULL, 0 },
69 { "darchdemo/test2/venice3.BMP", NULL, 0 },
70 { NULL, NULL, 0 },
71 };
72
73 /*---------------------------------------------------------------------------*
74 Name: GetFileInfo
75
76 Description: Get file infomation to archive
77
78 Arguments: fileInfo : file information list to archive
79
80 Returns: fileInfoNum : file number to archive
81 *---------------------------------------------------------------------------*/
GetFileInfo(u32 * fileInfoNum,DARCHFileInfo * fileInfo)82 static void GetFileInfo(u32* fileInfoNum, DARCHFileInfo *fileInfo)
83 {
84 DVDFileInfo dvdFileInfo;
85 DARCHFileInfo *darchFileInfo;
86 u32 darchFileInfoNum ;
87
88 // Load files to archive and set informations
89 darchFileInfo = fileInfo;
90 darchFileInfoNum = 0;
91
92 while(darchFileInfo->pathName)
93 {
94 if(!DVDOpen(darchFileInfo->pathName, &dvdFileInfo))
95 {
96 OSReport("Failed to open %s\n", darchFileInfo->pathName);
97 OSHalt("error!");
98 }
99
100 darchFileInfo->length = DVDGetLength(&dvdFileInfo);
101 darchFileInfo->fileStart = OSAllocFromMEM2ArenaLo(OSRoundUp32B(DVDGetLength(&dvdFileInfo)), 32);
102
103
104 if(!DVDRead(&dvdFileInfo, darchFileInfo->fileStart, (s32)OSRoundUp32B(darchFileInfo->length), 0))
105 {
106 OSReport("Failed to read %s\n", darchFileInfo->pathName);
107 OSHalt("error!");
108 }
109 darchFileInfo++;
110 darchFileInfoNum++;
111 }
112 OSReport(" Arc File Number : %d\n", darchFileInfoNum);
113
114 *fileInfoNum = darchFileInfoNum;
115 }
116
117 /*---------------------------------------------------------------------------*
118 Name: CompTest
119
120 Description: Compare Test for darch lib.
121 This test compares ARC file by darch.exe to ARC file image by darch lib.
122
123 Arguments: size : size of ARC file image
124 dstBuffer : address to store data
125
126 Returns: BOOL
127 *---------------------------------------------------------------------------*/
CompTest(u32 size,void * dstBuffer)128 static BOOL CompTest(u32 size, void* dstBuffer)
129 {
130 DVDFileInfo dvdFileInfo;
131 void* cmpBuffer;
132 u32 cmpSize;
133 u32 i = 1;
134
135 // Load ARC file image creaated by darch.exe
136 if(!DVDOpen(DARCHTEST_ARC_FILE_NAME, &dvdFileInfo))
137 {
138 OSReport(" Failed to open %s\n", DARCHTEST_ARC_FILE_NAME);
139 OSHalt(" error! ");
140 return FALSE;
141 }
142 cmpSize = DVDGetLength(&dvdFileInfo);
143 cmpBuffer = OSAllocFromMEM2ArenaLo(OSRoundUp32B(cmpSize), 32);
144
145 if(!DVDRead(&dvdFileInfo, cmpBuffer, (s32)OSRoundUp32B(cmpSize), 0))
146 {
147 OSReport(" Failed to read %s\n", DARCHTEST_ARC_FILE_NAME);
148 OSHalt(" error! ");
149 return FALSE;
150 }
151
152 // Compare sizes
153 if(size != cmpSize)
154 {
155 OSReport(" Failed to compare image size\n");
156 OSReport("cmp Buffer Size : %d Bytes\n", cmpSize);
157 OSHalt(" error! ");
158 return FALSE;
159 }
160
161 // Compare data
162 while(i <= size)
163 {
164 if(*((u8*)dstBuffer + i - 1) != *((u8*)cmpBuffer + i - 1))
165 {
166 OSReport(" Failed to compare %dth data %x %02X!=%02X\n",
167 i - 1, ((u8*)dstBuffer+ i - 1), *((u8*)dstBuffer + i - 1), *((u8*)cmpBuffer + i - 1));
168 return FALSE;
169 break;
170 }
171 else
172 {
173 // OSReport(" Compare %dth data %x %02X==%02X\n",
174 // i - 1, ((u8*)dstBuffer+ i - 1), *((u8*)dstBuffer + i - 1), *((u8*)cmpBuffer + i - 1));
175
176 }
177 i++;
178 }
179
180 return TRUE;
181 }
182
183 /*---------------------------------------------------------------------------*
184 Name: main
185
186 Description: Demo for darch lib
187
188 *---------------------------------------------------------------------------*/
main(void)189 void main( void )
190 {
191 u32 fileInfoNum;
192 u32 size;
193 void* dstBuffer;
194 OSTime start, end;
195
196 // Get file infomation
197 GetFileInfo(&fileInfoNum, fileInfo);
198
199 start = OSGetTime();
200
201 // Get dst Buffer Size
202 size = DARCHGetArcSize(fileInfo, fileInfoNum);
203 OSReport(" dstBuffer Size : %d Bytes\n", size);
204
205 // Get dst Buffer Address
206 dstBuffer = OSAllocFromMEM2ArenaLo(size,32);
207 OSReport(" dstBuffer Address : 0x%08X - 0x%08X\n", dstBuffer, (void*)((u32)dstBuffer + size));
208
209 // Create ARC File
210 if(!DARCHCreate(dstBuffer, size, fileInfo, fileInfoNum))
211 {
212 OSReport("failed to create\n");
213 OSHalt("\nDARCHCreate() >> error!\n");
214 }
215 end = OSGetTime();
216
217 // Time of creation
218 OSReport(" DARCHCreate()Time : %d us\n", OSTicksToMicroseconds(end - start));
219
220
221 #ifdef DARCH_COMP_TEST
222 OSReport(" \n# Compare Test >> \n" );
223
224 if(CompTest(size, dstBuffer))
225 OSReport(" clear! \n");
226 else
227 OSHalt(" error! ");
228 #endif
229
230 OSReport("End of Demo\n");
231 }
232
233