1 /*---------------------------------------------------------------------------* 2 3 Copyright (C) Nintendo. All rights reserved. 4 5 These coded instructions, statements, and computer programs contain 6 proprietary information of Nintendo of America Inc. and/or Nintendo 7 Company Ltd., and are protected by Federal copyright law. They may 8 not be disclosed to third parties or copied or duplicated in any form, 9 in whole or in part, without the prior written consent of Nintendo. 10 11 *---------------------------------------------------------------------------*/ 12 // ----------------------------------------------------------------------------- 13 // demoFWB.h 14 // 15 // ----------------------------------------------------------------------------- 16 17 #ifndef __DEMO_FWB_H__ 18 #define __DEMO_FWB_H__ 19 20 #include <cafe/demo.h> 21 22 #ifdef __cplusplus 23 extern "C" { 24 #endif 25 26 /// @addtogroup demoFileWriteBuffer 27 /// @{ 28 29 /// \brief Data container for Demo file-write-buffer (FWB) object. 30 typedef struct _DEMOFWBFileInfo 31 { 32 /// The DEMOFSFileInfo data. 33 DEMOFSFileInfo fileInfo; 34 35 /// \brief A pointer to the large write buffer that holds all of the writes until they are flushed to the file. 36 /// MUST be \c PPC_IO_BUFFER_ALIGN byte aligned. 37 void* writeBuffer; 38 39 /// The size of the writeBuffer buffer in bytes. 40 u32 writeBufferSize; 41 42 /// Current write location within the writeBuffer. This is the next empty index/location to write data. 43 u32 writeBufferWriteLocation; 44 45 } DEMOFWBFileInfo; 46 47 48 /// \brief Open a file and initialize the file-write-buffer (FWB) object. 49 /// 50 /// Opens a file for writing. 51 /// 52 /// If the path name begins with '/', it is used as an absolute path name. 53 /// If it does not, then "/vol/content/" is prepended to the path name. 54 /// 55 /// \note If /vol/content has been remapped to use DVDFS, then you may not 56 /// open files there in "w" (write) mode. Use /vol/save instead. 57 /// 58 /// \param path Pointer to filename to open 59 /// \param fwbFileInfo Pointer to a DEMOFWBFileInfo structure that will be filled in if the function succeeds 60 /// \param mode Pointer to file mode to use. i.e. "w" for write. 61 /// \param writeBufferSize The size of the buffer, that will be internally allocated and used to buffer up prints 62 /// before writing them to the file. A larger buffer size will result in greater buffering and higher performance. 63 /// 64 /// \retval DEMO_FS_RESULT_OK if it is ok. 65 /// \retval DEMO_FS_RESULT_PERMISSION if it is not permitted to open current file. 66 /// \retval DEMO_FS_RESULT_CORRUPTION if a file is corrupted. 67 /// \retval DEMO_FS_FATAL_ERROR if a fatal error occurs during a read, the function returns. 68 s32 DEMOFWBOpenFile(const char* path, DEMOFWBFileInfo* fwbFileInfo, const char* mode, u32 writeBufferSize); 69 70 71 /// \brief Closes the file. 72 /// 73 /// Closes the file tied to the file-write-buffer (FWB) object. This will ensure all writes are flushed to the file. 74 /// 75 /// \param fwbFileInfo File information for the file to close. 76 /// 77 /// \retval DEMO_FS_RESULT_OK if it is ok. 78 /// \retval DEMO_FS_RESULT_CORRUPTION if a file is corrupted. 79 /// \retval DEMO_FS_FATAL_ERROR if a fatal error occurs. 80 s32 DEMOFWBCloseFile(DEMOFWBFileInfo* fwbFileInfo); 81 82 /// \brief Flushes previous writes to the file-write-buffer (FWB) object to the file. 83 /// It is not required to ever call this function. DEMOFWBCloseFile() will automatically 84 /// call this function and ensure all writes are flushed. 85 s32 DEMOFWBFlush(DEMOFWBFileInfo* fwbFileInfo); 86 87 88 /// \brief Writes data to the file-write-buffer (FWB) object. 89 /// 90 /// \param fwbFileInfo Pointer to a DEMOFWBFileInfo structure. 91 /// \param bufferAddress Buffer address. 92 /// \param length Number of bytes to write. 93 /// 94 /// \retval DEMO_FS_RESULT_OK if it is ok. 95 /// \retval DEMO_FS_RESULT_FATAL_ERROR if there is an error. 96 s32 DEMOFWBWrite(DEMOFWBFileInfo* fwbFileInfo, void* bufferAddress, s32 length); 97 98 99 /// \brief Prints characters to the file-write-buffer (FWB) object. 100 /// No single write should be larger than writeBufferSize specified in DEMOFWBInit(). 101 /// If a single write is too large, DEMO_FS_RESULT_AREA_FULL will be returned. 102 /// 103 /// \retval DEMO_FS_RESULT_OK if it is ok. 104 /// \retval DEMO_FS_RESULT_FATAL_ERROR if there is an error. 105 /// \retval DEMO_FS_RESULT_AREA_FULL if the single write is larger than writeBufferSize specified in DEMOFWBInit() 106 s32 DEMOFWBfprintf(DEMOFWBFileInfo* fwbFileInfo, const char * format, ...); 107 108 /// @} 109 110 #ifdef __cplusplus 111 } 112 #endif 113 114 #endif /// __DEMO_FWB_H__ 115