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