/*---------------------------------------------------------------------------* Project: vfdemo File: simple.c Programers: yamamoto komatu gen miyake noma Copyright (C) 2006 Nintendo. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. *---------------------------------------------------------------------------*/ #include // size_t #include // OSHalt #include // NANDInit #include // DEMO... #include #define USE_NAND static void _SampleInit(); static void _SampleMain(); static void _MakeWriteSampleData(); #define DRIVE_NUM (3) #define WORK_SIZE (DRIVE_NUM * VF_DRIVE_WORKSIZE) static char l_vfWork[WORK_SIZE] ATTRIBUTE_ALIGN(32); /*---------------------------------------------------------------------------* Name: main Arguments: none Description: The application's main loop Returns: none *---------------------------------------------------------------------------*/ void main ( void ) { GXColor Black = {0, 0, 0, 0}; OSFontHeader* FontData = NULL; // demo Init DEMOInit(NULL); // font init FontData = DEMOInitROMFont(); // Use IPL ROM font if (FontData == 0) { OSHalt("This program requires boot ROM ver 0.8 or later\n"); } GXSetCopyClear(Black, 0x00ffffff); GXCopyDisp(DEMOGetCurrentBuffer(), GX_TRUE); // make test data _MakeWriteSampleData(); // sample init _SampleInit(); // sample main _SampleMain(); while (1) { GXRenderModeObj* rmp; DEMOBeforeRender(); // none rmp = DEMOGetRenderModeObj(); DEMOInitCaption(DM_FT_XLU, (s16) rmp->fbWidth, (s16) rmp->efbHeight); DEMOSetFontType(DM_FT_XLU); DEMOSetROMFontSize(32, -1); (void)DEMORFPrintf(32, 64, 0, "VF"); DEMODoneRender(); } } /*---------------------------------------------------------------------------* Name: _MakeWriteSampleData Arguments: none Description: Creates the write data for the demo Returns: none *---------------------------------------------------------------------------*/ #define TEST_DATA_SIZE (512) static u8 l_writeData[TEST_DATA_SIZE] ATTRIBUTE_ALIGN(32); static void _MakeWriteSampleData() { int i; int add = 0; u8* buf_p = l_writeData; for ( i=0; i * VFDeleteSystemFileNANDFlash */ if (Error == VF_ERR_VFF_FILE_FORMAT) { if (VFDeleteSystemFileNANDFlash(NandVffNameA) == NAND_RESULT_OK) { Error = VF_ERR_NOT_EXIST_FILE; } else { OSReport("VFDeleteSystemFileNANDFlash Error %s Line %d\n", VFGetApiErrorString(Error), __LINE__); OSHalt("Can't delete system file."); } } /** * VF_ERR_NOT_EXIST_FILE -> * NANDCheck -> * VFCreateSystemFileNANDFlash -> * VFMountDriveNANDFlash -> * VFFormatDrive */ if (Error == VF_ERR_NOT_EXIST_FILE) { if (_NANDCheck(100*1024) == FALSE) { OSHalt("NAND no space.."); } devErr = VFCreateSystemFileNANDFlash( NandVffNameA, (100*1024) ); if (devErr != NAND_RESULT_OK) { OSReport("VFCreateSystemFileNANDFlash VFDevErr(NANDError) %d Line %d\n", devErr, __LINE__); OSHalt("Can't create sytem file."); } // mount system file OSReport("[mount drive A for NAND - VFMountDriveNANDFlash]\n"); Error = VFMountDriveNANDFlash( "A", NandVffNameA ); if (Error != VF_ERR_SUCCESS) { OSReport("VFMountDriveNANDFlash Error %s Line %d\n", VFGetApiErrorString(Error), __LINE__); OSHalt( "Can't mount nand drive."); } // format drive Error = VFFormatDrive( "A" ); if (Error != VF_ERR_SUCCESS) { OSReport("VFFormatDrive Error %s Line %d\n", VFGetApiErrorString(Error), __LINE__); OSHalt( "Can't format nand drive"); } } /** * Make Directory */ OSReport("[mount drive A for NAND - VFCreateDir]\n"); Error = VFCreateDir("A:/Sample0"); if (Error != VF_ERR_SUCCESS) { OSReport("VFCreateDir Error %s Line %d\n", VFGetApiErrorString(Error), __LINE__); } Error = VFCreateDir( "Sample0/Sample1"); if (Error != VF_ERR_SUCCESS) { OSReport("VFCreateDir Error %s Line %d\n", VFGetApiErrorString(Error), __LINE__); } /** * Change Directory */ OSReport("[mount drive A for NAND - VFChangeDir]\n"); Error = VFChangeDir("/"); if (Error != VF_ERR_SUCCESS) { OSReport("VFChangeDir Error %s Line %d\n", VFGetApiErrorString(Error), __LINE__); } /** * Write File */ // Open file OSReport("[mount drive A for NAND - VFOpenFile]\n"); fp = VFOpenFile("A:/SAMPLEA.txt", "r+", 0); if (fp == NULL){ OSReport("VFOpenFile Error %s Line %d\n", VFGetApiErrorString(VFGetLastError()), __LINE__); // create file fp = VFCreateFile("SAMPLEA.txt", 0); if (fp == NULL) { OSReport( "VFCreateFile Error %s Line %d\n", VFGetApiErrorString(VFGetLastError()), __LINE__); } } if (fp) { // write file OSReport("[mount drive A for NAND - VFWriteFile]\n"); Error = VFWriteFile(fp, l_writeData, TEST_DATA_SIZE); if (Error != VF_ERR_SUCCESS) { OSReport("VFWriteFile Error %s Line %d\n", VFGetApiErrorString(Error), __LINE__); } // sync file OSReport("[mount drive A for NAND - VFFileSync]\n"); Error = VFFileSync(fp); if (Error != VF_ERR_SUCCESS) { OSReport("VFFileSync Error %s Line %d\n", VFGetApiErrorString(Error), __LINE__); OSHalt("Can't sync file"); } // Close file OSReport("[mount drive A for NAND - VFCloseFile]\n"); Error = VFCloseFile(fp); if (Error != VF_ERR_SUCCESS) { OSReport("VFCloseFile Error %s Line %d\n", VFGetApiErrorString(Error), __LINE__); } // cut file (If file is closed, you success) OSReport("[mount drive A for NAND - VFCutFileSize]\n"); Error = VFCutFileSize("A:/SAMPLEA.txt", 23); if (Error != VF_ERR_SUCCESS) { OSReport("VFCutFileSize Error %s Line %d\n", VFGetApiErrorString(Error), __LINE__); } } /** * Delete Directory */ // make directory OSReport("[mount drive A for NAND - VFCreateDir]\n"); Error = VFCreateDir("A:/subDir0"); if (Error != VF_ERR_SUCCESS) { OSReport("VFCreateDir Error %s Line %d\n", VFGetApiErrorString(Error), __LINE__); } Error = VFCreateDir("subDir0/subDir1"); if (Error != VF_ERR_SUCCESS) { OSReport("VFCreateDir Error %s Line %d\n", VFGetApiErrorString(Error), __LINE__); } // delete directory OSReport("[mount drive A for NAND - VFCreateDir]\n"); Error = VFDeleteDir("Sample0/Sample1"); if (Error != VF_ERR_SUCCESS) { OSReport("VFDeleteDir Error %s Line %d\n", VFGetApiErrorString(Error), __LINE__); } // changed directory Error = VFChangeDir("Sample0/Sample1"); if (Error != VF_ERR_SUCCESS) { OSReport( "VFDeleteDir Error %s Line %d\n", VFGetApiErrorString(Error), __LINE__); OSReport( "VFChangeDir failed. = test success!\n"); } /** * Rename Directory */ OSReport("[mount drive A for NAND - VFRenameDir]\n"); Error = VFRenameDir("A:/subDir0", "A:/subDirXXX"); if (Error != VF_ERR_SUCCESS) { OSReport("VFRenameDir Error %s Line %d\n", VFGetApiErrorString(Error), __LINE__); } OSReport( "mount drive A Success!\n" ); //------------------------------------------------------------------ // reference drive A //------------------------------------------------------------------ { u8 readBuf[TEST_DATA_SIZE]; VFFile* fp = NULL; int i; s32 fileSize; // Open file OSReport("[reference drive A - VFOpenFile]\n"); fp = VFOpenFile("SAMPLEA.txt", "r", 0); if (fp == NULL){ OSReport("VFOpenFile Error %s Line %d\n", VFGetApiErrorString(VFGetLastError()), __LINE__); } // seek file OSReport("[reference drive A - VFSeekFile]\n"); Error = VFSeekFile(fp, 5, VF_SEEK_SET); if (Error != VF_ERR_SUCCESS) { OSReport("VFSeekFile Error %s Line %d\n", VFGetApiErrorString(Error), __LINE__); } // get file size fileSize = VFGetFileSizeByFd(fp); if (fileSize != -1) { u32 readSize = 0; // Read file OSReport("[reference drive A - VFReadFile nowSeekOffset %d]\n", VFGetOffsetByFd(fp)); Error = VFReadFile(fp, readBuf, (u32)fileSize, &readSize); if (Error != VF_ERR_SUCCESS) { OSReport("VFReadFile Error %s Line %d\n", VFGetApiErrorString(Error), __LINE__); } else { OSReport("# VFReadFile fileSize %d readSize %d\n", fileSize, readSize); } // printf OSReport("[ReadBuff]\n"); for (i=0; i", name_p); if (attribute & VF_ATTR_DIR) { OSReport(" is Directory.\n"); } else { OSReport(" is File.\n"); } while (1) { // search next Error = VFFileSearchNext(dta_p); if (Error == VF_ERR_SUCCESS) { name_p = (char*)VF_DTA_GET_LONG_FILE_NAME_P(*dta_p); attribute = VF_DTA_GET_FILE_ATTR(*dta_p); OSReport("<%s>", name_p); if (attribute & VF_ATTR_DIR) { OSReport(" is Directory.\n"); } else { OSReport(" is File.\n"); } } else { break; } } } else { OSReport("VFFileSearchFirst Error %s Line %d\n", VFGetApiErrorString(Error), __LINE__); } OSReport("\n"); OSFree(dta_p); } } //------------------------------------------------------------------ // unmount drive A //------------------------------------------------------------------ Error = VFUnmountDrive( "A" ); if (Error != VF_ERR_SUCCESS) { OSReport("VFUnmountDrive Error %s Line %d\n", VFGetApiErrorString(Error), __LINE__); OSHalt("Can't unmount nand drive."); } OSReport("unmount drive A Success!\n"); #endif //#if defined(USE_NAND) //------------------------------------------------------------------ // VF finalize //------------------------------------------------------------------ VFFinalize(); }