| 142 | }; |
| 143 | |
| 144 | u32 GBIMicrocode_DetectVersion( u32 code_base, u32 code_size, u32 data_base, u32 data_size, CustomMicrocodeCallback custom_callback ) |
| 145 | { |
| 146 | // I think only checking code_base should be enough.. |
| 147 | u32 idx {code_base + data_base}; |
| 148 | |
| 149 | // Cheap way to cache ucodes, don't check for strings (too slow!) but check last used ucode entries which is alot faster than string comparison. |
| 150 | // This only needed for GBI1/2/SDEX ucodes that use LoadUcode, else we only check when code_base changes, which usually never happens |
| 151 | // |
| 152 | u32 i ; |
| 153 | for( i = 0; i < MAX_UCODE_CACHE_ENTRIES; i++ ) |
| 154 | { |
| 155 | const UcodeInfo &used( gUcodeInfo[ i ] ); |
| 156 | |
| 157 | // If this returns false, it means this entry is free to use |
| 158 | if( used.set == false ) |
| 159 | break; |
| 160 | |
| 161 | if( used.index == idx ) |
| 162 | return used.ucode; |
| 163 | } |
| 164 | |
| 165 | // |
| 166 | // Try to find the version string in the microcode data. This is faster than calculating a crc of the code |
| 167 | // |
| 168 | char str[256] = ""; |
| 169 | GBIMicrocode_DetectVersionString( data_base, data_size, str, 256 ); |
| 170 | |
| 171 | // It wasn't the same as the last time around, we'll hash it and check if is a custom ucode. |
| 172 | // |
| 173 | u32 code_hash = GBIMicrocode_MicrocodeHash( code_base, code_size ); |
| 174 | u32 ucode_version = GBI_0; |
| 175 | u32 ucode_offset = ~0; |
| 176 | |
| 177 | for ( u32 i = 0; i < ARRAYSIZE(gMicrocodeData); i++ ) |
| 178 | { |
| 179 | if ( code_hash == gMicrocodeData[i].hash ) |
| 180 | { |
| 181 | //DBGConsole_Msg(0, "Ucode has been Detected in Array :[M\"%s\", Ucode %d]", str, gMicrocodeData[ i ].ucode); |
| 182 | ucode_version = gMicrocodeData[ i ].ucode; |
| 183 | ucode_offset = gMicrocodeData[ i ].offset; |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | if( ucode_version != GBI_0 ) |
| 188 | { |
| 189 | // If this a custom ucode, let's build an array based from ucode_offset |
| 190 | custom_callback( ucode_version, ucode_offset ); |
| 191 | } |
| 192 | else |
| 193 | { |
| 194 | // |
| 195 | // If it wasn't a custom ucode |
| 196 | // See if we can identify it by string, if no match was found set default for Fast3D ucode |
| 197 | // |
| 198 | const char *ucodes[] { "F3", "L3", "S2DEX" }; |
| 199 | char *match {}; |
| 200 | |
| 201 | for(u32 j {}; j<3;j++) |
no test coverage detected