/*---------------------------------------------------------------------------* Copyright (C) 2010-2011 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. *---------------------------------------------------------------------------*/ #pragma once #ifndef __GFDFILEIO_H__ #define __GFDFILEIO_H__ #ifdef __cplusplus extern "C" { #endif // __cplusplus /// @addtogroup GFDFileIOGroup /// @{ /// \brief Round up value to power-of-2 size #define GFD_ROUND_UP(value, size) (((value) + ((size) - 1)) & ~((size) - 1)) // // Write Functions // /// \brief Writes a GFD header to the file. /// /// \param fp Dest Output file pointer. /// \param gpuVer Gpu version. /// \param alignMode Align mode. /// \return true or false /// /// \donotcall \notthreadsafe \hostonly \enddonotcall /// GFD_DECLSPEC bool GFD_API GFDWriteFileHeader(FILE *fp, GFDGPUVersion gpuVer, GFDAlignMode alignMode); /// \brief Writes a block header to the file. /// /// \param fp Dest Output file pointer. /// \param type Type of Block /// \param dataSize Data size in bytes following this header. /// \return true or false /// /// \donotcall \notthreadsafe \hostonly \enddonotcall /// GFD_DECLSPEC bool GFD_API GFDWriteFileBlockHeader(FILE *fp, GFDBlockType type, u32 dataSize); /// \brief Writes a GPU data to the file. /// /// \param fp Dest Output file pointer. /// \param numElements Number of input elements /// \param elemSize Element size /// \param swapMode Endian Swap mode for data writing /// \param pData Input Data pointer. /// \return true or false /// /// \donotcall \notthreadsafe \hostonly \enddonotcall /// GFD_DECLSPEC bool GFD_API GFDWriteFileGPUData(FILE *fp, u32 numElements, GFDElementSize elemSize, GFDEndianSwapMode swapMode, void *pData); /// \brief Writes a PPC data to the file. /// /// \param fp Dest Output file pointer /// \param numElements Number of input elements /// \param elemSize Element size /// \param pData Input Data pointer. /// \return true or false /// /// \donotcall \notthreadsafe \hostonly \enddonotcall /// GFD_DECLSPEC inline bool GFD_API GFDWriteFilePPCData(FILE *fp, u32 numElements, GFDElementSize elemSize, void *pData) { return GFDWriteFileGPUData(fp, numElements, elemSize, GFD_ENDIAN_SWAP_MODE_BIG, pData); } /// \brief Writes a padding block header and padding data block with 0 to the file. /// /// \param fp Dest Output file pointer. /// \param padSize Padding size in bytes for data block /// \return true or false /// /// \donotcall \notthreadsafe \hostonly \enddonotcall /// GFD_DECLSPEC bool GFD_API GFDWriteFilePadBlock(FILE *fp, u32 padSize); /// \brief Open gfd file. Need to call GFDCloseFile to close. /// /// \param fp A pointer to the file pointer that will receive the pointer to the opened file. /// \param fileName Name of the input gtx file. /// \param mode string containing a file access mode for fopen_s. /// \return 0 on successful to open. Return fopen_s error code on failure. /// /// \donotcall \notthreadsafe \hostonly \enddonotcall /// GFD_DECLSPEC errno_t GFD_API GFDOpenFile(FILE **fp, const char* fileName, const char *mode); /// \brief Close gfd file. /// /// \param fp Pointer to FILE structure. /// \return 0 on the stream is successfully closed. /// /// \donotcall \notthreadsafe \hostonly \enddonotcall /// GFD_DECLSPEC int GFD_API GFDCloseFile(FILE *fp); // // Read Functions // /// \brief Reads a GPU data from the file. Need to use GFDOpenFile for the file pointer. /// /// \param pData Output buffer pointer. /// \param numElements Number of output elements /// \param elemSize Element size /// \param swapMode Endian Swap mode for data reading /// \param fp Input file pointer. /// \return true or false /// /// \donotcall \notthreadsafe \hostonly \enddonotcall /// GFD_DECLSPEC bool GFD_API GFDReadFileGPUData(void *pData, u32 numElements, GFDElementSize elemSize, GFDEndianSwapMode swapMode, FILE *fp); /// \brief Reads a CPU data from the file. /// /// \param pData Output buffer pointer. /// \param numElements Number of output elements /// \param elemSize Element size /// \param fp Input file pointer. /// \return true or false /// /// \donotcall \notthreadsafe \hostonly \enddonotcall /// GFD_DECLSPEC inline bool GFD_API GFDReadFilePPCData(void *pData, u32 numElements, GFDElementSize elemSize, FILE *fp) { return GFDReadFileGPUData(pData, numElements, elemSize, GFD_ENDIAN_SWAP_MODE_BIG, fp); } /// \brief Checks File Header magic and version values. /// /// \param pHeader Header pointer to check /// \return true or false /// /// \donotcall \notthreadsafe \hostonly \enddonotcall /// GFD_DECLSPEC inline bool GFD_API GFDCheckHeaderMagicVersions(const GFDHeader *pHeader) { u32 magic = pHeader->magic; if (!(GFD_HEADER_MAGIC == GFD_SWAP_8_IN_32(magic))) { ASSERT(!"Unknown GFD format."); return false; } if (!(GFD_HEADER_MAJOR == pHeader->majorVersion)) { ASSERT(!"Unsupported GFD version."); return false; } return true; } /// \brief Checks Block Header magic and version values. /// /// \param pBlockHeader Header pointer to check /// \return true or false /// /// \donotcall \notthreadsafe \hostonly \enddonotcall /// GFD_DECLSPEC inline bool GFD_API GFDCheckBlockHeaderMagicVersions(const GFDBlockHeader *pBlockHeader) { u32 magic = pBlockHeader->magic; if (!(GFD_BLOCK_HEADER_MAGIC == GFD_SWAP_8_IN_32(magic))) { ASSERT(!"Unknown GFD block format."); return false; } if (!(GFD_BLOCK_HEADER_MAJOR == pBlockHeader->majorVersion)) { ASSERT(!"Unsupported GFD block version."); return false; } return true; } /// @} #ifdef __cplusplus } #endif // __cplusplus #endif // __GFDFILEIO_H__