1 /*---------------------------------------------------------------------------* 2 Project: Horizon 3 File: gr_LookUpTable.cpp 4 5 Copyright (C)2009-2012 Nintendo Co., Ltd. All rights reserved. 6 7 These coded instructions, statements, and computer programs contain 8 proprietary information of Nintendo of America Inc. and/or Nintendo 9 Company Ltd., and are protected by Federal copyright law. They may 10 not be disclosed to third parties or copied or duplicated in any form, 11 in whole or in part, without the prior written consent of Nintendo. 12 13 $Rev: 46347 $ 14 *---------------------------------------------------------------------------*/ 15 16 #include <nn/gr/CTR/gr_LookUpTable.h> 17 18 namespace nn 19 { 20 namespace gr 21 { 22 namespace CTR 23 { 24 SetTable(const f32 table[LOOKUP_TABLE_ELEMENT_NUM],const f32 lastDiffValue,const bool isInputAbs)25 void LookUpTable::SetTable( const f32 table[ LOOKUP_TABLE_ELEMENT_NUM ], 26 const f32 lastDiffValue, 27 const bool isInputAbs ) 28 { 29 // When the input value is [0.0, 1.0] 30 if ( isInputAbs ) 31 { 32 SetAbsTable( table, lastDiffValue ); 33 } 34 // When the input value is [-1.0, 1.0] 35 else 36 { 37 SetNotAbsTable( table, lastDiffValue ); 38 } 39 } 40 SetAbsTable(const f32 table[LOOKUP_TABLE_ELEMENT_NUM],const f32 lastDiffValue)41 void LookUpTable::SetAbsTable( const f32 table[ LOOKUP_TABLE_ELEMENT_NUM ], 42 const f32 lastDiffValue ) 43 { 44 bit32* command = m_TableCommand; 45 46 // When the input value is [0.0, 1.0] 47 48 int i = 0; 49 *command++ = Float32ToUnsignedFix12( table[ i ] ) | 50 Float32ToFix12( table[ i + 1 ] - table[ i ] ) << 12; 51 *command++ = PICA_CMD_HEADER_BURST( PICA_REG_FRAG_LIGHT_LUT_DATA0, 256 ); 52 53 for ( ++i; i < 0xff; ++i ) 54 { 55 *command++ = Float32ToUnsignedFix12( table[ i ] ) | 56 Float32ToFix12( table[ i + 1 ] - table[ i ] ) << 12; 57 } 58 59 // Final difference value 60 *command++ = Float32ToUnsignedFix12( table[ i ] ) | 61 Float32ToFix12( lastDiffValue ) << 12; 62 *command++ = 0; 63 } 64 SetNotAbsTable(const f32 table[LOOKUP_TABLE_ELEMENT_NUM],const f32 lastDiffValue)65 void LookUpTable::SetNotAbsTable( const f32 table[ LOOKUP_TABLE_ELEMENT_NUM ], 66 const f32 lastDiffValue ) 67 { 68 bit32* command = m_TableCommand; 69 70 // When the input value is [0.0, 1.0] 71 72 const u32 LOOKUP_TABLE_HALF_ELEMENT_NUM = LOOKUP_TABLE_ELEMENT_NUM / 2; 73 74 u32 i = LOOKUP_TABLE_HALF_ELEMENT_NUM; 75 76 *command++ = Float32ToUnsignedFix12( table[ i ] ) | 77 Float32ToFix12( table[ i + 1 ] - table[ i ] ) << 12; 78 *command++ = PICA_CMD_HEADER_BURST( PICA_REG_FRAG_LIGHT_LUT_DATA0, 256 ); 79 80 for ( ++i; i < 0xff; ++i ) 81 { 82 *command++ = Float32ToUnsignedFix12( table[ i ] ) | 83 Float32ToFix12( table[ i + 1 ] - table[ i ] ) << 12; 84 } 85 86 // Final difference value 87 *command++ = Float32ToUnsignedFix12( table[ i ] ) | 88 Float32ToFix12( lastDiffValue ) << 12; 89 90 // When the input value is [-1.0, 0.0] 91 92 i = 0; 93 94 *command++ = Float32ToUnsignedFix12( table[ i ] ) | 95 Float32ToFix12( table[ i + 1 ] - table[ i ] ) << 12; 96 97 for ( ++i; i < 0x80; ++i ) 98 { 99 *command++ = Float32ToUnsignedFix12( table[ i ] ) | 100 Float32ToFix12( table[ i + 1 ] - table[ i ] ) << 12; 101 } 102 *command++ = 0; 103 } 104 105 } // namespace CTR 106 } // namespace gr 107 } // namespace nn 108