/*---------------------------------------------------------------------------* Project: Sample demo program for NAND library File: basic.c Programmer: HIRATSU Daisuke 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. $Log: basic.c,v $ Revision 1.11 06/05/2006 13:09:05 hiratsu Removed NANDFinalize(). Used home directory to store file. Revision 1.10 05/03/2006 09:07:25 hiratsu Fixed a little bit because NAND APIs are changed. Revision 1.9 2006/04/27 17:57:35 orest Added NANDFinalize() api. Revision 1.8 03/17/2006 02:41:09 hiratsu Now this sample demo program uses buffer from MEM2 with 32byte alignment. Revision 1.7 03/11/2006 10:43:20 hiratsu Now, we can link real ISFS module. Revision 1.6 03/06/2006 12:05:34 hiratsu Removed finalize function. Revision 1.5 2006/03/06 09:59:08 kawaset Eliminated warnings. Revision 1.4 02/16/2006 13:00:53 hiratsu Changed order of arguments for NANDOpen(). Revision 1.3 02/06/2006 08:07:51 hiratsu Added seek code. Now this demo prints write buffer and read buffer. Revision 1.2 01/30/2006 10:32:34 hiratsu Modified code because specification of NANDInit() has been changed. Added static function for initialize and finalize to make code simple. (I wanted to avoid too many #ifdef) Revision 1.1 01/24/2006 12:34:39 hiratsu NAND library demo program. This tells basic operation of NAND library ( Init -> Create -> Open -> Write -> Read -> Close -> Delete ). *---------------------------------------------------------------------------*/ #include #include #include #include #include "util.h" #define FILENAME "nanddemo.dat" #define PERM (NAND_PERM_OWNER_READ | NAND_PERM_OWNER_WRITE) // Owner can read/write #define ATTR 0x00 // No attributes. #define SIZE 256 int main(void) { s32 ret = NAND_RESULT_FATAL_ERROR; NANDFileInfo info; char *data=0; char *buf=0; char path[NAND_MAX_PATH]=""; initializeHeap(); data = (char*)alloc32(SIZE); buf = (char*)alloc32(SIZE); strcpy(data, "Sample demo program for NAND library."); ret = NANDInit(); if(ret != NAND_RESULT_OK) { printErrMsg(ret); OSReport("NANDInit() failed.\n"); return EXIT_FAILURE; } ret = NANDGetCurrentDir(path); if(ret != NAND_RESULT_OK) { printErrMsg(ret); OSReport("NANDGetCurrentDir() failed.\n"); return EXIT_FAILURE; } OSReport("Current directory: %s\n", path); ret = NANDCreate(FILENAME, PERM, ATTR); if(ret == NAND_RESULT_OK) { // Do nothing. } else if(ret == NAND_RESULT_EXISTS) { OSReport("File already exists.\n"); } else { printErrMsg(ret); OSReport("NANDCreate() failed.\n"); return EXIT_FAILURE; } ret = NANDOpen(FILENAME, &info, NAND_ACCESS_WRITE | NAND_ACCESS_READ); if(ret != NAND_RESULT_OK) { printErrMsg(ret); OSReport("NANDOpen() failed. Result code: %d\n", ret); return EXIT_FAILURE; } ret = NANDWrite(&info, data, SIZE); if(ret != SIZE) { printErrMsg(ret); OSReport("NANDWrite() failed.\n"); NANDClose(&info); return EXIT_FAILURE; } ret = NANDSeek(&info, 0, NAND_SEEK_SET); if(ret != 0) { printErrMsg(ret); OSReport("NANDSeek() failed.\n"); NANDClose(&info); return EXIT_FAILURE; } ret = NANDRead(&info, buf, SIZE); if(ret != SIZE) { printErrMsg(ret); OSReport("NANDRead() failed.\n"); NANDClose(&info); return EXIT_FAILURE; } OSReport("Write data: %s\n", data); OSReport("Read data: %s\n", buf); ret = NANDClose(&info); if(ret != NAND_RESULT_OK) { printErrMsg(ret); OSReport("NANDClose() failed.\n"); return EXIT_FAILURE; } ret = NANDDelete(FILENAME); if(ret != NAND_RESULT_OK) { printErrMsg(ret); OSReport("NANDDelete() failed.\n"); return EXIT_FAILURE; } free32(buf); free32(data); finalizeHeap(); OSHalt("Finished with success"); return EXIT_SUCCESS; // Never reach here. }