/*---------------------------------------------------------------------------* Project: Horizon File: font_BinaryFileFormat.h Copyright (C)2009-2010 Nintendo Co., Ltd./HAL Laboratory, Inc. 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. $Revision: 24675 $ *---------------------------------------------------------------------------*/ #ifndef NN_FONT_DETAIL_FONT_BINARY_FILE_FORMAT_H_ #define NN_FONT_DETAIL_FONT_BINARY_FILE_FORMAT_H_ #include #if ( NN_ENDIAN == NN_ENDIAN_VALUE_LITTLE ) //---- little endian #define NN_FONT_MAKE_SIGWORD(a, b, c, d) \ static_cast( \ (static_cast(a) << 0) | (static_cast(b) << 8) \ | (static_cast(c) << 16) | (static_cast(d) << 24) \ ) #else //---- big endian #define NN_FONT_MAKE_SIGWORD(a, b, c, d) \ static_cast( \ (static_cast(a) << 24) | (static_cast(b) << 16) \ | (static_cast(c) << 8) | (static_cast(d) << 0) \ ) #endif #define NN_FONT_MAKE_VERSION(major, minor, micro, binaryBugFix) \ static_cast( \ (static_cast(major) << 24) | (static_cast(minor) << 16) \ | (static_cast(micro) << 8) | (static_cast(binaryBugFix)) \ ) #define NN_FONT_VERSION_MAJOR(version) (((version) >> 24) & 0xff) #define NN_FONT_VERSION_MINOR(version) (((version) >> 16) & 0xff) #define NN_FONT_VERSION_MICRO(version) (((version) >> 8) & 0xff) #define NN_FONT_VERSION_BINARYBUGFIX(version) (((version) >> 0) & 0xff) namespace nn { namespace font { namespace detail { // #define NN_SWAP_ENDIAN #if !defined( NN_SWAP_ENDIAN ) typedef u8 ResU8; //!< @details :private typedef s8 ResS8; //!< @details :private typedef u16 ResU16; //!< @details :private typedef s16 ResS16; //!< @details :private typedef u32 ResU32; //!< @details :private typedef s32 ResS32; //!< @details :private typedef f32 ResF32; //!< @details :private typedef u32 ResU64; //!< @details :private typedef s32 ResS64; //!< @details :private typedef f32 ResF64; //!< @details :private #else // if defined( NN_SWAP_ENDIAN ) namespace Endian { typedef union { u64 UInt64; s64 SInt64; #if defined( NN_ENABLE_FLOAT64 ) f64 Float64; #endif } Type64; typedef union { u32 UInt32; s32 SInt32; f32 Float32; } Type32; typedef union { u16 UInt16; s16 SInt16; } Type16; static u64 BSwap( u64 val ) { const u64 MASK = 0xFF00FF00FF00FF00ULL; const u64 MASK2 = 0xFFFF0000FFFF0000ULL; val = ( (val & MASK) >> 8 ) | ( (val << 8) & MASK ); val = ( (val & MASK2) >> 16 ) | ( (val << 16) & MASK2 ); return (val >> 32) | (val << 32); } static s64 BSwap( s64 val ) { Type64 data; data.SInt64 = val; data.UInt64 = BSwap( data.UInt64 ); return data.SInt64; } #if defined( NN_ENABLE_FLOAT64 ) static f64 BSwap( f64 val ) { Type64 data; data.Float64 = val; data.UInt64 = BSwap( data.UInt64 ); return data.Float64; } #endif static u32 BSwap( u32 val ) { const u32 MASK = 0xFF00FF00; val = ( (val & MASK) >> 8 ) | ( (val << 8) & MASK ); return (val >> 16) | (val << 16); } static s32 BSwap( s32 val ) { Type32 data; data.SInt32 = val; data.UInt32 = BSwap( data.UInt32 ); return data.SInt32; } static f32 BSwap( f32 val ) { Type32 data; data.Float32 = val; data.UInt32 = BSwap( data.UInt32 ); return data.Float32; } static u16 BSwap( u16 val ) { return (u16)( (val >> 8) | (val << 8) ); } static s16 BSwap( s16 val ) { return (s16)( ((u16)val >> 8) | ((u16)val << 8) ); } } /* namespace Endian */ template class ResNum { public: /* ctor */ ResNum() {} /* ctor */ ResNum(const ResNum& other) : bits(other.bits) {} /* ctor */ ResNum(const T val ) : bits( Endian::BSwap( val ) ) {} void operator = (const ResNum& other) { bits = other.bits; } /* T */ operator T () const { return Endian::BSwap( bits ); } void operator = (T val) { bits = Endian::BSwap( val ); } private: T bits; }; typedef u8 ResU8; //!< @details :private typedef s8 ResS8; //!< @details :private typedef ResNum ResU16; //!< @details :private typedef ResNum ResS16; //!< @details :private typedef ResNum ResU32; //!< @details :private typedef ResNum ResS32; //!< @details :private typedef ResNum ResF32; //!< @details :private typedef ResNum ResU64; //!< @details :private typedef ResNum ResS64; //!< @details :private typedef ResNum ResF64; //!< @details :private #endif // define( NN_SWAP_ENDIAN ) //---- シグネチャ型 typedef u32 SigWord; namespace { const u16 BYTE_ORDER_MARK = 0xFEFF; } /*!--------------------------------------------------------------------------* @brief NintendoWare 標準バイナリファイルヘッダ @details :private *---------------------------------------------------------------------------*/ struct BinaryFileHeader { SigWord signature; // ファイルシグネチャ : 4 Byte u16 byteOrder; // バイトオーダーマーク : 2 Byte ResU16 headerSize; // ヘッダサイズ : 2 Byte ResU32 version; // ファイルバージョン : 4 Byte ResU32 fileSize; // ファイルサイズ : 4 Byte ResU16 dataBlocks; // ブロック数 : 2 Byte u16 reserved; // 予約 : 2 Byte }; /*!--------------------------------------------------------------------------* @brief NintendoWare 標準バイナリブロックヘッダ @details :private *---------------------------------------------------------------------------*/ struct BinaryBlockHeader { SigWord kind; // ブロック種別名 u32 size; // ブロック全体サイズ }; bool IsValidBinaryFile( const BinaryFileHeader* /*pHeader*/, u32 /*signature*/, u32 /*version*/, u16 /*minBlocks = 1*/ ); }}} // namespace nn::font::detail #endif // NN_FONT_DETAIL_FONT_BINARY_FILE_FORMAT_H_