Path: blob/master/libmupen64plus/mupen64plus-video-rice/src/Config.cpp
2 views
/*1Copyright (C) 2003 Rice196423This program is free software; you can redistribute it and/or4modify it under the terms of the GNU General Public License5as published by the Free Software Foundation; either version 26of the License, or (at your option) any later version.78This program is distributed in the hope that it will be useful,9but WITHOUT ANY WARRANTY; without even the implied warranty of10MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the11GNU General Public License for more details.1213You should have received a copy of the GNU General Public License14along with this program; if not, write to the Free Software15Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.1617*/1819#include <vector>20#include <fstream>2122#include <stdlib.h>2324#define M64P_PLUGIN_PROTOTYPES 125#include "osal_preproc.h"26#include "m64p_types.h"27#include "m64p_plugin.h"28#include "m64p_config.h"2930#include "Config.h"31#include "Debugger.h"32#include "DeviceBuilder.h"33#include "RenderBase.h"34#include "TextureManager.h"35#include "Video.h"3637#define INI_FILE "RiceVideoLinux.ini"3839static m64p_handle l_ConfigVideoRice = NULL;40static m64p_handle l_ConfigVideoGeneral = NULL;4142static int FindIniEntry(uint32 dwCRC1, uint32 dwCRC2, uint8 nCountryID, char* szName, int PrintInfo);4344const char *frameBufferSettings[] =45{46"None (default)",47"Hide Framebuffer Effects",48"Basic Framebuffer",49"Basic & Write Back",50"Write Back & Reload",51"Write Back Every Frame",52"With Emulator",53"Basic Framebuffer & With Emulator",54"With Emulator Read Only",55"With Emulator Write Only",56};5758const int resolutions[][2] =59{60{320, 240},61{400, 300},62{480, 360},63{512, 384},64{640, 480},65{800, 600},66{1024, 768},67{1152, 864},68{1280, 960},69{1400, 1050},70{1600, 1200},71{1920, 1440},72{2048, 1536},73};74const int numberOfResolutions = sizeof(resolutions)/sizeof(int)/2;7576const char* resolutionsS[] =77{78"320 x 240",79"400 x 300",80"480 x 360",81"512 x 384",82"640 x 480",83"800 x 600",84"1024 x 768",85"1152 x 864",86"1280 x 960",87"1400 x 1050",88"1600 x 1200",89"1920 x 1440",90"2048 x 1536"91};9293const char *frameBufferWriteBackControlSettings[] =94{95"Every Frame (default)",96"Every 2 Frames",97"Every 3 Frames",98"Every 4 Frames",99"Every 5 Frames",100"Every 6 Frames",101"Every 7 Frames",102"Every 8 Frames",103};104105const char *renderToTextureSettings[] =106{107"None (default)",108"Hide Render-to-texture Effects",109"Basic Render-to-texture",110"Basic & Write Back",111"Write Back & Reload",112};113114const char *screenUpdateSettings[] =115{116"At VI origin update",117"At VI origin change",118"At CI change",119"At the 1st CI change",120"At the 1st drawing",121"Before clear the screen",122"At VI origin update after screen is drawn (default)",123};124125WindowSettingStruct windowSetting;126GlobalOptions options;127RomOptions defaultRomOptions;128RomOptions currentRomOptions;129FrameBufferOptions frameBufferOptions;130std::vector<IniSection> IniSections;131bool bIniIsChanged = false;132char szIniFileName[300];133134SettingInfo TextureQualitySettings[] =135{136{"Default", FORCE_DEFAULT_FILTER},137{"32-bit Texture", FORCE_POINT_FILTER},138{"16-bit Texture", FORCE_LINEAR_FILTER},139};140141SettingInfo ForceTextureFilterSettings[] =142{143{"N64 Default Texture Filter", FORCE_DEFAULT_FILTER},144{"Force Nearest Filter (faster, low quality)", FORCE_POINT_FILTER},145{"Force Linear Filter (slower, better quality)", FORCE_LINEAR_FILTER},146};147148SettingInfo TextureEnhancementSettings[] =149{150{"N64 original texture (No enhancement)", TEXTURE_NO_ENHANCEMENT},151{"2x (Double the texture size)", TEXTURE_2X_ENHANCEMENT},152{"2xSaI", TEXTURE_2XSAI_ENHANCEMENT},153{"hq2x", TEXTURE_HQ2X_ENHANCEMENT},154{"lq2x", TEXTURE_LQ2X_ENHANCEMENT},155{"hq4x", TEXTURE_HQ4X_ENHANCEMENT},156{"Sharpen", TEXTURE_SHARPEN_ENHANCEMENT},157{"Sharpen More", TEXTURE_SHARPEN_MORE_ENHANCEMENT},158};159160SettingInfo TextureEnhancementControlSettings[] =161{162{"Normal", TEXTURE_ENHANCEMENT_NORMAL},163{"Smooth", TEXTURE_ENHANCEMENT_WITH_SMOOTH_FILTER_1},164{"Less smooth", TEXTURE_ENHANCEMENT_WITH_SMOOTH_FILTER_2},165{"2xSaI smooth", TEXTURE_ENHANCEMENT_WITH_SMOOTH_FILTER_3},166{"Less 2xSaI smooth", TEXTURE_ENHANCEMENT_WITH_SMOOTH_FILTER_4},167};168169SettingInfo colorQualitySettings[] =170{171{"16-bit", TEXTURE_FMT_A4R4G4B4},172{"32-bit (def)", TEXTURE_FMT_A8R8G8B8},173};174175const char* strDXDeviceDescs[] = { "HAL", "REF" };176177SettingInfo openGLDepthBufferSettings[] =178{179{"16-bit (def)", 16},180{"32-bit", 32},181};182183RenderEngineSetting OpenGLRenderSettings[] =184{185{"To Fit Your Video Card", OGL_DEVICE},186{"OpenGL 1.1 (Lowest)", OGL_1_1_DEVICE},187{"OpenGL 1.2/1.3", OGL_1_2_DEVICE},188{"OpenGL 1.4", OGL_1_4_DEVICE},189//{"OpenGL 1.4, the 2nd combiner", OGL_1_4_V2_DEVICE},190{"OpenGL for Nvidia TNT or better", OGL_TNT2_DEVICE},191{"OpenGL for Nvidia GeForce or better ", NVIDIA_OGL_DEVICE},192{"OpenGL Fragment Program Extension", OGL_FRAGMENT_PROGRAM},193};194195SettingInfo OnScreenDisplaySettings[] =196{197{"Display Nothing", ONSCREEN_DISPLAY_NOTHING},198{"Display DList Per Second", ONSCREEN_DISPLAY_DLIST_PER_SECOND},199{"Display Frame Per Second", ONSCREEN_DISPLAY_FRAME_PER_SECOND},200{"Display Debug Information Only", ONSCREEN_DISPLAY_DEBUG_INFORMATION_ONLY},201{"Display Messages From CPU Core Only", ONSCREEN_DISPLAY_TEXT_FROM_CORE_ONLY},202{"Display DList Per Second With Core Msgs", ONSCREEN_DISPLAY_DLIST_PER_SECOND_WITH_CORE_MSG},203{"Display Frame Per Second With Core Msgs", ONSCREEN_DISPLAY_FRAME_PER_SECOND_WITH_CORE_MSG},204{"Display Debug Information With Core Msgs", ONSCREEN_DISPLAY_DEBUG_INFORMATION_WITH_CORE_MSG},205};206207const int numberOfOpenGLRenderEngineSettings = sizeof(OpenGLRenderSettings)/sizeof(RenderEngineSetting);208209void GenerateFrameBufferOptions(void)210{211if( CDeviceBuilder::GetGeneralDeviceType() == OGL_DEVICE )212{213// OpenGL does not support much yet214if( currentRomOptions.N64FrameBufferEmuType != FRM_BUF_NONE )215currentRomOptions.N64FrameBufferEmuType = FRM_BUF_IGNORE;216if( currentRomOptions.N64RenderToTextureEmuType != TXT_BUF_NONE )217currentRomOptions.N64RenderToTextureEmuType = TXT_BUF_IGNORE;218}219220frameBufferOptions.bUpdateCIInfo = false;221222frameBufferOptions.bCheckBackBufs = false;223frameBufferOptions.bWriteBackBufToRDRAM = false;224frameBufferOptions.bLoadBackBufFromRDRAM = false;225226frameBufferOptions.bIgnore = true;227228frameBufferOptions.bSupportRenderTextures = false;229frameBufferOptions.bCheckRenderTextures = false;230frameBufferOptions.bRenderTextureWriteBack = false;231frameBufferOptions.bLoadRDRAMIntoRenderTexture = false;232233frameBufferOptions.bProcessCPUWrite = false;234frameBufferOptions.bProcessCPURead = false;235frameBufferOptions.bAtEachFrameUpdate = false;236frameBufferOptions.bIgnoreRenderTextureIfHeightUnknown = false;237238switch( currentRomOptions.N64FrameBufferEmuType )239{240case FRM_BUF_NONE:241break;242case FRM_BUF_COMPLETE:243frameBufferOptions.bAtEachFrameUpdate = true;244frameBufferOptions.bProcessCPUWrite = true;245frameBufferOptions.bProcessCPURead = true;246frameBufferOptions.bUpdateCIInfo = true;247break;248case FRM_BUF_WRITEBACK_AND_RELOAD:249frameBufferOptions.bLoadBackBufFromRDRAM = true;250case FRM_BUF_BASIC_AND_WRITEBACK:251frameBufferOptions.bWriteBackBufToRDRAM = true;252case FRM_BUF_BASIC:253frameBufferOptions.bCheckBackBufs = true;254case FRM_BUF_IGNORE:255frameBufferOptions.bUpdateCIInfo = true;256break;257case FRM_BUF_BASIC_AND_WITH_EMULATOR:258// Banjo Kazooie259frameBufferOptions.bCheckBackBufs = true;260case FRM_BUF_WITH_EMULATOR:261frameBufferOptions.bUpdateCIInfo = true;262frameBufferOptions.bProcessCPUWrite = true;263frameBufferOptions.bProcessCPURead = true;264break;265case FRM_BUF_WITH_EMULATOR_READ_ONLY:266frameBufferOptions.bUpdateCIInfo = true;267frameBufferOptions.bProcessCPURead = true;268break;269case FRM_BUF_WITH_EMULATOR_WRITE_ONLY:270frameBufferOptions.bUpdateCIInfo = true;271frameBufferOptions.bProcessCPUWrite = true;272break;273}274275switch( currentRomOptions.N64RenderToTextureEmuType )276{277case TXT_BUF_NONE:278frameBufferOptions.bSupportRenderTextures = false;279break;280case TXT_BUF_WRITE_BACK_AND_RELOAD:281frameBufferOptions.bLoadRDRAMIntoRenderTexture = true;282case TXT_BUF_WRITE_BACK:283frameBufferOptions.bRenderTextureWriteBack = true;284case TXT_BUF_NORMAL:285frameBufferOptions.bCheckRenderTextures = true;286frameBufferOptions.bIgnore = false;287case TXT_BUF_IGNORE:288frameBufferOptions.bUpdateCIInfo = true;289frameBufferOptions.bSupportRenderTextures = true;290break;291}292293if( currentRomOptions.screenUpdateSetting >= SCREEN_UPDATE_AT_CI_CHANGE )294{295frameBufferOptions.bUpdateCIInfo = true;296}297}298299BOOL InitConfiguration(void)300{301if (ConfigOpenSection("Video-General", &l_ConfigVideoGeneral) != M64ERR_SUCCESS)302{303DebugMessage(M64MSG_ERROR, "Unable to open Video-General configuration section");304return FALSE;305}306if (ConfigOpenSection("Video-Rice", &l_ConfigVideoRice) != M64ERR_SUCCESS)307{308DebugMessage(M64MSG_ERROR, "Unable to open Video-Rice configuration section");309return FALSE;310}311312ConfigSetDefaultBool(l_ConfigVideoGeneral, "Fullscreen", 0, "Use fullscreen mode if True, or windowed mode if False ");313ConfigSetDefaultInt(l_ConfigVideoGeneral, "ScreenWidth", 640, "Width of output window or fullscreen width");314ConfigSetDefaultInt(l_ConfigVideoGeneral, "ScreenHeight", 480, "Height of output window or fullscreen height");315ConfigSetDefaultBool(l_ConfigVideoGeneral, "VerticalSync", 0, "If true, activate the SDL_GL_SWAP_CONTROL attribute");316317ConfigSetDefaultInt(l_ConfigVideoRice, "FrameBufferSetting", FRM_BUF_NONE, "Frame Buffer Emulation (0=ROM default, 1=disable)");318ConfigSetDefaultInt(l_ConfigVideoRice, "FrameBufferWriteBackControl", FRM_BUF_WRITEBACK_NORMAL, "Frequency to write back the frame buffer (0=every frame, 1=every other frame, etc)");319ConfigSetDefaultInt(l_ConfigVideoRice, "RenderToTexture", TXT_BUF_NONE, "Render-to-texture emulation (0=none, 1=ignore, 2=normal, 3=write back, 4=write back and reload)");320#if defined(WIN32)321ConfigSetDefaultInt(l_ConfigVideoRice, "ScreenUpdateSetting", SCREEN_UPDATE_AT_1ST_CI_CHANGE, "Control when the screen will be updated (0=ROM default, 1=VI origin update, 2=VI origin change, 3=CI change, 4=first CI change, 5=first primitive draw, 6=before screen clear, 7=after screen drawn)"); // SCREEN_UPDATE_AT_VI_UPDATE_AND_DRAWN322#else323ConfigSetDefaultInt(l_ConfigVideoRice, "ScreenUpdateSetting", SCREEN_UPDATE_AT_VI_UPDATE, "Control when the screen will be updated (0=ROM default, 1=VI origin update, 2=VI origin change, 3=CI change, 4=first CI change, 5=first primitive draw, 6=before screen clear, 7=after screen drawn)"); // SCREEN_UPDATE_AT_VI_UPDATE_AND_DRAWN324#endif325ConfigSetDefaultBool(l_ConfigVideoRice, "NormalAlphaBlender", FALSE, "Force to use normal alpha blender");326ConfigSetDefaultBool(l_ConfigVideoRice, "FastTextureLoading", FALSE, "Use a faster algorithm to speed up texture loading and CRC computation");327ConfigSetDefaultBool(l_ConfigVideoRice, "AccurateTextureMapping", TRUE, "Use different texture coordinate clamping code");328ConfigSetDefaultBool(l_ConfigVideoRice, "InN64Resolution", FALSE, "Force emulated frame buffers to be in N64 native resolution");329ConfigSetDefaultBool(l_ConfigVideoRice, "SaveVRAM", FALSE, "Try to reduce Video RAM usage (should never be used)");330ConfigSetDefaultBool(l_ConfigVideoRice, "DoubleSizeForSmallTxtrBuf", FALSE, "Enable this option to have better render-to-texture quality");331ConfigSetDefaultBool(l_ConfigVideoRice, "DefaultCombinerDisable", FALSE, "Force to use normal color combiner");332333ConfigSetDefaultBool(l_ConfigVideoRice, "EnableHacks", TRUE, "Enable game-specific settings from INI file");334ConfigSetDefaultBool(l_ConfigVideoRice, "WinFrameMode", FALSE, "If enabled, graphics will be drawn in WinFrame mode instead of solid and texture mode");335ConfigSetDefaultBool(l_ConfigVideoRice, "FullTMEMEmulation", FALSE, "N64 Texture Memory Full Emulation (may fix some games, may break others)");336ConfigSetDefaultBool(l_ConfigVideoRice, "OpenGLVertexClipper", FALSE, "Enable vertex clipper for fog operations");337ConfigSetDefaultBool(l_ConfigVideoRice, "EnableSSE", TRUE, "Enable/Disable SSE optimizations for capable CPUs");338ConfigSetDefaultBool(l_ConfigVideoRice, "EnableVertexShader", FALSE, "Use GPU vertex shader");339ConfigSetDefaultBool(l_ConfigVideoRice, "SkipFrame", FALSE, "If this option is enabled, the plugin will skip every other frame");340ConfigSetDefaultBool(l_ConfigVideoRice, "TexRectOnly", FALSE, "If enabled, texture enhancement will be done only for TxtRect ucode");341ConfigSetDefaultBool(l_ConfigVideoRice, "SmallTextureOnly", FALSE, "If enabled, texture enhancement will be done only for textures width+height<=128");342ConfigSetDefaultBool(l_ConfigVideoRice, "LoadHiResCRCOnly", TRUE, "Select hi-resolution textures based only on the CRC and ignore format+size information (Glide64 compatibility)");343ConfigSetDefaultBool(l_ConfigVideoRice, "LoadHiResTextures", FALSE, "Enable hi-resolution texture file loading");344ConfigSetDefaultBool(l_ConfigVideoRice, "DumpTexturesToFiles", FALSE, "Enable texture dumping");345ConfigSetDefaultBool(l_ConfigVideoRice, "ShowFPS", FALSE, "Display On-screen FPS");346347ConfigSetDefaultInt(l_ConfigVideoRice, "Mipmapping", 2, "Use Mipmapping? 0=no, 1=nearest, 2=bilinear, 3=trilinear");348ConfigSetDefaultInt(l_ConfigVideoRice, "FogMethod", 0, "Enable, Disable or Force fog generation (0=Disable, 1=Enable n64 choose, 2=Force Fog)");349ConfigSetDefaultInt(l_ConfigVideoRice, "ForceTextureFilter", 0, "Force to use texture filtering or not (0=auto: n64 choose, 1=force no filtering, 2=force filtering)");350ConfigSetDefaultInt(l_ConfigVideoRice, "TextureEnhancement", 0, "Primary texture enhancement filter (0=None, 1=2X, 2=2XSAI, 3=HQ2X, 4=LQ2X, 5=HQ4X, 6=Sharpen, 7=Sharpen More, 8=External, 9=Mirrored)");351ConfigSetDefaultInt(l_ConfigVideoRice, "TextureEnhancementControl", 0, "Secondary texture enhancement filter (0 = none, 1-4 = filtered)");352ConfigSetDefaultInt(l_ConfigVideoRice, "TextureQuality", TXT_QUALITY_DEFAULT, "Color bit depth to use for textures (0=default, 1=32 bits, 2=16 bits)");353ConfigSetDefaultInt(l_ConfigVideoRice, "OpenGLDepthBufferSetting", 16, "Z-buffer depth (only 16 or 32)");354ConfigSetDefaultInt(l_ConfigVideoRice, "MultiSampling", 0, "Enable/Disable MultiSampling (0=off, 2,4,8,16=quality)");355ConfigSetDefaultInt(l_ConfigVideoRice, "ColorQuality", TEXTURE_FMT_A8R8G8B8, "Color bit depth for rendering window (0=32 bits, 1=16 bits)");356ConfigSetDefaultInt(l_ConfigVideoRice, "OpenGLRenderSetting", OGL_DEVICE, "OpenGL level to support (0=auto, 1=OGL_1.1, 2=OGL_1.2, 3=OGL_1.3, 4=OGL_1.4, 5=OGL_1.4_V2, 6=OGL_TNT2, 7=NVIDIA_OGL, 8=OGL_FRAGMENT_PROGRAM)");357ConfigSetDefaultInt(l_ConfigVideoRice, "AnisotropicFiltering", 0, "Enable/Disable Anisotropic Filtering for Mipmapping (0=no filtering, 2-16=quality). This is uneffective if Mipmapping is 0. If the given value is to high to be supported by your graphic card, the value will be the highest value your graphic card can support. Better result with Trilinear filtering");358359// Per-game hacks360ConfigSetDefaultBool(l_ConfigVideoRice, "DisableTextureCRC", FALSE, "...?");361ConfigSetDefaultBool(l_ConfigVideoRice, "DisableCulling", FALSE, "...?");362ConfigSetDefaultBool(l_ConfigVideoRice, "IncTexRectEdge", FALSE, "...?");363ConfigSetDefaultBool(l_ConfigVideoRice, "ZHack", FALSE, "...?");364ConfigSetDefaultBool(l_ConfigVideoRice, "TextureScaleHack", FALSE, "...?");365ConfigSetDefaultBool(l_ConfigVideoRice, "PrimaryDepthHack", FALSE, "...?");366ConfigSetDefaultBool(l_ConfigVideoRice, "Texture1Hack", FALSE, "...?");367ConfigSetDefaultBool(l_ConfigVideoRice, "FastLoadTile", FALSE, "...?");368ConfigSetDefaultBool(l_ConfigVideoRice, "UseSmallerTexture", FALSE, "...?");369370ConfigSetDefaultInt(l_ConfigVideoRice, "VIWidth", -1, "...?");371ConfigSetDefaultInt(l_ConfigVideoRice, "VIHeight", -1, "...?");372ConfigSetDefaultInt(l_ConfigVideoRice, "UseCIWidthAndRatio", NOT_USE_CI_WIDTH_AND_RATIO, "...?");373ConfigSetDefaultInt(l_ConfigVideoRice, "FullTMEM", 0, "...?");374375ConfigSetDefaultBool(l_ConfigVideoRice, "TxtSizeMethod2", FALSE, "...?");376ConfigSetDefaultBool(l_ConfigVideoRice, "EnableTxtLOD", FALSE, "...?");377378ConfigSetDefaultInt(l_ConfigVideoRice, "FastTextureCRC", 0, "...?");379380ConfigSetDefaultBool(l_ConfigVideoRice, "EmulateClear", FALSE, "...?");381ConfigSetDefaultBool(l_ConfigVideoRice, "ForceScreenClear", FALSE, "...?");382383ConfigSetDefaultInt(l_ConfigVideoRice, "AccurateTextureMappingHack", 0, "...?");384ConfigSetDefaultInt(l_ConfigVideoRice, "NormalBlender", 0, "...?");385386ConfigSetDefaultBool(l_ConfigVideoRice, "DisableBlender", FALSE, "...?");387388ConfigSetDefaultInt(l_ConfigVideoRice, "NormalCombiner", 0, "...?");389390ConfigSetDefaultBool(l_ConfigVideoRice, "ForceDepthBuffer", FALSE, "...?");391ConfigSetDefaultBool(l_ConfigVideoRice, "DisableObjBG", FALSE, "...?");392393ConfigSetDefaultInt(l_ConfigVideoRice, "FrameBufferOption", 0, "...?");394ConfigSetDefaultInt(l_ConfigVideoRice, "RenderToTextureOption", 0, "...?");395ConfigSetDefaultInt(l_ConfigVideoRice, "ScreenUpdateSettingHack", 0, "...?");396397ConfigSetDefaultInt(l_ConfigVideoRice, "EnableHacksForGame", NO_HACK_FOR_GAME, "...?");398399return TRUE;400}401402bool isMMXSupported()403{404int IsMMXSupported = 0;405406#if !defined(__GNUC__) && !defined(NO_ASM)407__asm408{409mov eax,1 // CPUID level 1410cpuid // EDX = feature flag411and edx,0x800000 // test bit 23 of feature flag412mov IsMMXSupported,edx // != 0 if MMX is supported413}414#elif defined(__GNUC__) && defined(__x86_64__) && !defined(NO_ASM)415return true;416#elif !defined(NO_ASM) // GCC assumed417asm volatile (418"push %%ebx \n"419"mov $1, %%eax \n" // CPUID level 1420"cpuid \n" // EDX = feature flag421"and $0x800000, %%edx \n" // test bit 23 of feature flag422"pop %%ebx \n"423: "=d"(IsMMXSupported)424:425: "memory", "cc", "eax", "ecx"426);427#endif428if (IsMMXSupported != 0)429return true;430else431return false;432}433434bool isSSESupported()435{436int SSESupport = 0;437438// And finally, check the CPUID for Streaming SIMD Extensions support.439#if !defined(__GNUC__) && !defined(NO_ASM)440_asm441{442mov eax, 1 // Put a "1" in eax to tell CPUID to get the feature bits443cpuid // Perform CPUID (puts processor feature info into EDX)444and edx, 02000000h // Test bit 25, for Streaming SIMD Extensions existence.445mov SSESupport, edx // SIMD Extensions). Set return value to 1 to indicate,446}447#elif defined(__GNUC__) && defined(__x86_64__) && !defined(NO_ASM)448return true;449#elif !defined(NO_ASM) // GCC assumed450asm volatile (451"push %%ebx \n"452"mov $1, %%eax \n" // Put a "1" in eax to tell CPUID to get the feature bits453"cpuid \n" // Perform CPUID (puts processor feature info into EDX)454"and $0x02000000, %%edx \n" // Test bit 25, for Streaming SIMD Extensions existence.455"pop %%ebx \n"456: "=d"(SSESupport)457:458: "memory", "cc", "eax", "ecx"459);460# endif461462if (SSESupport != 0)463return true;464else465return false;466}467468static void ReadConfiguration(void)469{470windowSetting.bDisplayFullscreen = ConfigGetParamBool(l_ConfigVideoGeneral, "Fullscreen");471windowSetting.uDisplayWidth = ConfigGetParamInt(l_ConfigVideoGeneral, "ScreenWidth");472windowSetting.uDisplayHeight = ConfigGetParamInt(l_ConfigVideoGeneral, "ScreenHeight");473windowSetting.bVerticalSync = ConfigGetParamBool(l_ConfigVideoGeneral, "VerticalSync");474475defaultRomOptions.N64FrameBufferEmuType = ConfigGetParamInt(l_ConfigVideoRice, "FrameBufferSetting");476defaultRomOptions.N64FrameBufferWriteBackControl = ConfigGetParamInt(l_ConfigVideoRice, "FrameBufferWriteBackControl");477defaultRomOptions.N64RenderToTextureEmuType = ConfigGetParamInt(l_ConfigVideoRice, "RenderToTexture");478defaultRomOptions.screenUpdateSetting = ConfigGetParamInt(l_ConfigVideoRice, "screenUpdateSetting");479480defaultRomOptions.bNormalBlender = ConfigGetParamBool(l_ConfigVideoRice, "NormalAlphaBlender");481defaultRomOptions.bFastTexCRC = ConfigGetParamBool(l_ConfigVideoRice, "FastTextureLoading");482defaultRomOptions.bAccurateTextureMapping = ConfigGetParamBool(l_ConfigVideoRice, "AccurateTextureMapping");483defaultRomOptions.bInN64Resolution = ConfigGetParamBool(l_ConfigVideoRice, "InN64Resolution");484defaultRomOptions.bSaveVRAM = ConfigGetParamBool(l_ConfigVideoRice, "SaveVRAM");485defaultRomOptions.bDoubleSizeForSmallTxtrBuf = ConfigGetParamBool(l_ConfigVideoRice, "DoubleSizeForSmallTxtrBuf");486defaultRomOptions.bNormalCombiner = ConfigGetParamBool(l_ConfigVideoRice, "DefaultCombinerDisable");487488options.bEnableHacks = ConfigGetParamBool(l_ConfigVideoRice, "EnableHacks");489options.bWinFrameMode = ConfigGetParamBool(l_ConfigVideoRice, "WinFrameMode");490options.bFullTMEM = ConfigGetParamBool(l_ConfigVideoRice, "FullTMEMEmulation");491options.bOGLVertexClipper = ConfigGetParamBool(l_ConfigVideoRice, "OpenGLVertexClipper");492options.bEnableSSE = ConfigGetParamBool(l_ConfigVideoRice, "EnableSSE");493options.bEnableVertexShader = ConfigGetParamBool(l_ConfigVideoRice, "EnableVertexShader");494options.bSkipFrame = ConfigGetParamBool(l_ConfigVideoRice, "SkipFrame");495options.bTexRectOnly = ConfigGetParamBool(l_ConfigVideoRice, "TexRectOnly");496options.bSmallTextureOnly = ConfigGetParamBool(l_ConfigVideoRice, "SmallTextureOnly");497options.bLoadHiResTextures = ConfigGetParamBool(l_ConfigVideoRice, "LoadHiResTextures");498options.bLoadHiResCRCOnly = ConfigGetParamBool(l_ConfigVideoRice, "LoadHiResCRCOnly");499options.bDumpTexturesToFiles = ConfigGetParamBool(l_ConfigVideoRice, "DumpTexturesToFiles");500options.bShowFPS = ConfigGetParamBool(l_ConfigVideoRice, "ShowFPS");501502options.mipmapping = ConfigGetParamInt(l_ConfigVideoRice, "Mipmapping");503options.fogMethod = ConfigGetParamInt(l_ConfigVideoRice, "FogMethod");504options.forceTextureFilter = ConfigGetParamInt(l_ConfigVideoRice, "ForceTextureFilter");505options.textureEnhancement = ConfigGetParamInt(l_ConfigVideoRice, "TextureEnhancement");506options.textureEnhancementControl = ConfigGetParamInt(l_ConfigVideoRice, "TextureEnhancementControl");507options.textureQuality = ConfigGetParamInt(l_ConfigVideoRice, "TextureQuality");508options.OpenglDepthBufferSetting = ConfigGetParamInt(l_ConfigVideoRice, "OpenGLDepthBufferSetting");509options.multiSampling = ConfigGetParamInt(l_ConfigVideoRice, "MultiSampling");510options.colorQuality = ConfigGetParamInt(l_ConfigVideoRice, "ColorQuality");511options.OpenglRenderSetting = ConfigGetParamInt(l_ConfigVideoRice, "OpenGLRenderSetting");512options.anisotropicFiltering = ConfigGetParamInt(l_ConfigVideoRice, "AnisotropicFiltering");513514CDeviceBuilder::SelectDeviceType((SupportedDeviceType)options.OpenglRenderSetting);515516status.isMMXSupported = isMMXSupported();517status.isSSESupported = isSSESupported();518status.isVertexShaderSupported = false;519520status.isSSEEnabled = status.isSSESupported && options.bEnableSSE;521#if !defined(NO_ASM)522if( status.isSSEEnabled )523{524ProcessVertexData = ProcessVertexDataSSE;525DebugMessage(M64MSG_INFO, "SSE processing enabled.");526}527else528#endif529{530ProcessVertexData = ProcessVertexDataNoSSE;531DebugMessage(M64MSG_INFO, "Disabled SSE processing.");532}533534status.isVertexShaderEnabled = status.isVertexShaderSupported && options.bEnableVertexShader;535status.bUseHW_T_L = false;536}537538BOOL LoadConfiguration(void)539{540IniSections.clear();541bIniIsChanged = false;542/*543strcpy(szIniFileName, INI_FILE);544545if (!ReadIniFile())546{547DebugMessage(M64MSG_ERROR, "Unable to read ini file from disk");548return FALSE;549}550*/551552if (l_ConfigVideoGeneral == NULL || l_ConfigVideoRice == NULL)553{554DebugMessage(M64MSG_ERROR, "Rice Video configuration sections are not open!");555return FALSE;556}557558// Read config parameters from core config API and set up internal variables559ReadConfiguration();560561return TRUE;562}563564void GenerateCurrentRomOptions()565{566currentRomOptions.N64FrameBufferEmuType =g_curRomInfo.dwFrameBufferOption;567currentRomOptions.N64FrameBufferWriteBackControl =defaultRomOptions.N64FrameBufferWriteBackControl;568currentRomOptions.N64RenderToTextureEmuType =g_curRomInfo.dwRenderToTextureOption;569currentRomOptions.screenUpdateSetting =g_curRomInfo.dwScreenUpdateSetting;570currentRomOptions.bNormalCombiner =g_curRomInfo.dwNormalCombiner;571currentRomOptions.bNormalBlender =g_curRomInfo.dwNormalBlender;572currentRomOptions.bFastTexCRC =g_curRomInfo.dwFastTextureCRC;573currentRomOptions.bAccurateTextureMapping =g_curRomInfo.dwAccurateTextureMapping;574575options.enableHackForGames = NO_HACK_FOR_GAME;576if ((strncmp((char*)g_curRomInfo.szGameName, "BANJO TOOIE", 11) == 0))577{578options.enableHackForGames = HACK_FOR_BANJO_TOOIE;579}580else if ((strncmp((char*)g_curRomInfo.szGameName, "DR.MARIO", 8) == 0))581{582options.enableHackForGames = HACK_FOR_DR_MARIO;583}584else if ((strncasecmp((char*)g_curRomInfo.szGameName, "Pilot", 5) == 0))585{586options.enableHackForGames = HACK_FOR_PILOT_WINGS;587}588else if ((strncasecmp((char*)g_curRomInfo.szGameName, "YOSHI", 5) == 0))589{590options.enableHackForGames = HACK_FOR_YOSHI;591}592else if ((strncasecmp((char*)g_curRomInfo.szGameName, "NITRO", 5) == 0))593{594options.enableHackForGames = HACK_FOR_NITRO;595}596else if ((strncasecmp((char*)g_curRomInfo.szGameName, "TONY HAWK", 9) == 0))597{598options.enableHackForGames = HACK_FOR_TONYHAWK;599}600else if ((strncasecmp((char*)g_curRomInfo.szGameName, "THPS", 4) == 0))601{602options.enableHackForGames = HACK_FOR_TONYHAWK;603}604else if ((strncasecmp((char*)g_curRomInfo.szGameName, "SPIDERMAN", 9) == 0))605{606options.enableHackForGames = HACK_FOR_TONYHAWK;607}608else if ((strncasecmp((char*)g_curRomInfo.szGameName, "NASCAR", 6) == 0))609{610options.enableHackForGames = HACK_FOR_NASCAR;611}612else if ((strstr((char*)g_curRomInfo.szGameName, "ZELDA") != 0) && (strstr((char*)g_curRomInfo.szGameName, "MASK") != 0))613{614options.enableHackForGames = HACK_FOR_ZELDA_MM;615}616else if ((strstr((char*)g_curRomInfo.szGameName, "ZELDA") != 0))617{618options.enableHackForGames = HACK_FOR_ZELDA;619}620else if ((strstr((char*)g_curRomInfo.szGameName, "Ogre") != 0))621{622options.enableHackForGames = HACK_FOR_OGRE_BATTLE;623}624else if ((strstr((char*)g_curRomInfo.szGameName, "TWINE") != 0))625{626options.enableHackForGames = HACK_FOR_TWINE;627}628else if ((strstr((char*)g_curRomInfo.szGameName, "Squadron") != 0))629{630options.enableHackForGames = HACK_FOR_ROGUE_SQUADRON;631}632else if ((strstr((char*)g_curRomInfo.szGameName, "Baseball") != 0) && (strstr((char*)g_curRomInfo.szGameName, "Star") != 0))633{634options.enableHackForGames = HACK_FOR_ALL_STAR_BASEBALL;635}636else if ((strstr((char*)g_curRomInfo.szGameName, "Tigger") != 0) && (strstr((char*)g_curRomInfo.szGameName, "Honey") != 0))637{638options.enableHackForGames = HACK_FOR_TIGER_HONEY_HUNT;639}640else if ((strstr((char*)g_curRomInfo.szGameName, "Bust") != 0) && (strstr((char*)g_curRomInfo.szGameName, "Move") != 0))641{642options.enableHackForGames = HACK_FOR_BUST_A_MOVE;643}644else if ((strncasecmp((char*)g_curRomInfo.szGameName, "MarioTennis",11) == 0))645{646options.enableHackForGames = HACK_FOR_MARIO_TENNIS;647}648else if ((strncasecmp((char*)g_curRomInfo.szGameName, "SUPER BOWLING",13) == 0))649{650options.enableHackForGames = HACK_FOR_SUPER_BOWLING;651}652else if ((strncasecmp((char*)g_curRomInfo.szGameName, "CONKER",6) == 0))653{654options.enableHackForGames = HACK_FOR_CONKER;655}656else if ((strncasecmp((char*)g_curRomInfo.szGameName, "MK_MYTHOLOGIES",14) == 0))657{658options.enableHackForGames = HACK_REVERSE_Y_COOR;659}660else if ((strncasecmp((char*)g_curRomInfo.szGameName, "Fighting Force",14) == 0))661{662options.enableHackForGames = HACK_REVERSE_XY_COOR;663}664else if ((strncasecmp((char*)g_curRomInfo.szGameName, "GOLDENEYE",9) == 0))665{666options.enableHackForGames = HACK_FOR_GOLDEN_EYE;667}668else if ((strncasecmp((char*)g_curRomInfo.szGameName, "F-ZERO",6) == 0))669{670options.enableHackForGames = HACK_FOR_FZERO;671}672else if ((strncasecmp((char*)g_curRomInfo.szGameName, "Command&Conquer",15) == 0))673{674options.enableHackForGames = HACK_FOR_COMMANDCONQUER;675}676else if ((strncasecmp((char*)g_curRomInfo.szGameName, "READY 2 RUMBLE",14) == 0))677{678options.enableHackForGames = HACK_FOR_RUMBLE;679}680else if ((strncasecmp((char*)g_curRomInfo.szGameName, "READY to RUMBLE",15) == 0))681{682options.enableHackForGames = HACK_FOR_RUMBLE;683}684else if ((strncasecmp((char*)g_curRomInfo.szGameName, "South Park Rally",16) == 0))685{686options.enableHackForGames = HACK_FOR_SOUTH_PARK_RALLY;687}688else if ((strncasecmp((char*)g_curRomInfo.szGameName, "Extreme G 2",11) == 0))689{690options.enableHackForGames = HACK_FOR_EXTREME_G2;691}692else if ((strncasecmp((char*)g_curRomInfo.szGameName, "MarioGolf64",11) == 0))693{694options.enableHackForGames = HACK_FOR_MARIO_GOLF;695}696else if ((strncasecmp((char*)g_curRomInfo.szGameName, "MLB FEATURING",13) == 0))697{698options.enableHackForGames = HACK_FOR_MLB;699}700else if ((strncasecmp((char*)g_curRomInfo.szGameName, "POLARISSNOCROSS",15) == 0))701{702options.enableHackForGames = HACK_FOR_POLARISSNOCROSS;703}704else if ((strncasecmp((char*)g_curRomInfo.szGameName, "TOP GEAR RALLY",14) == 0))705{706options.enableHackForGames = HACK_FOR_TOPGEARRALLY;707}708else if ((strncasecmp((char*)g_curRomInfo.szGameName, "DUKE NUKEM",10) == 0))709{710options.enableHackForGames = HACK_FOR_DUKE_NUKEM;711}712else if ((strncasecmp((char*)g_curRomInfo.szGameName, "MARIOKART64",11) == 0))713{714options.enableHackForGames = HACK_FOR_MARIO_KART;715}716717options.enableHackForGames = (HACK_FOR_GAMES)ConfigGetParamInt(l_ConfigVideoRice, "EnableHacksForGame");718719if (options.enableHackForGames != NO_HACK_FOR_GAME)720DebugMessage(M64MSG_INFO, "Enabled hacks for game: '%s'", g_curRomInfo.szGameName);721722if( currentRomOptions.N64FrameBufferEmuType == 0 ) currentRomOptions.N64FrameBufferEmuType = defaultRomOptions.N64FrameBufferEmuType;723else currentRomOptions.N64FrameBufferEmuType--;724if( currentRomOptions.N64RenderToTextureEmuType == 0 ) currentRomOptions.N64RenderToTextureEmuType = defaultRomOptions.N64RenderToTextureEmuType;725else currentRomOptions.N64RenderToTextureEmuType--;726if( currentRomOptions.screenUpdateSetting == 0 ) currentRomOptions.screenUpdateSetting = defaultRomOptions.screenUpdateSetting;727if( currentRomOptions.bNormalCombiner == 0 ) currentRomOptions.bNormalCombiner = defaultRomOptions.bNormalCombiner;728else currentRomOptions.bNormalCombiner--;729if( currentRomOptions.bNormalBlender == 0 ) currentRomOptions.bNormalBlender = defaultRomOptions.bNormalBlender;730else currentRomOptions.bNormalBlender--;731if( currentRomOptions.bFastTexCRC == 0 ) currentRomOptions.bFastTexCRC = defaultRomOptions.bFastTexCRC;732else currentRomOptions.bFastTexCRC--;733if( currentRomOptions.bAccurateTextureMapping == 0 ) currentRomOptions.bAccurateTextureMapping = defaultRomOptions.bAccurateTextureMapping;734else currentRomOptions.bAccurateTextureMapping--;735736options.bUseFullTMEM = ((options.bFullTMEM && (g_curRomInfo.dwFullTMEM == 0)) || g_curRomInfo.dwFullTMEM == 2);737738GenerateFrameBufferOptions();739740if( options.enableHackForGames == HACK_FOR_MARIO_GOLF || options.enableHackForGames == HACK_FOR_MARIO_TENNIS )741{742frameBufferOptions.bIgnoreRenderTextureIfHeightUnknown = true;743}744}745746void Ini_GetRomOptions(LPGAMESETTING pGameSetting)747{748/*749int i;750751i = FindIniEntry(pGameSetting->romheader.dwCRC1,752pGameSetting->romheader.dwCRC2,753pGameSetting->romheader.nCountryID,754(char*)pGameSetting->szGameName, 1);755*/756757pGameSetting->bDisableTextureCRC = ConfigGetParamBool(l_ConfigVideoRice, "DisableTextureCRC");758pGameSetting->bDisableCulling = ConfigGetParamBool(l_ConfigVideoRice, "DisableCulling");759pGameSetting->bIncTexRectEdge = ConfigGetParamBool(l_ConfigVideoRice, "IncTexRectEdge");760pGameSetting->bZHack = ConfigGetParamBool(l_ConfigVideoRice, "ZHack");761pGameSetting->bTextureScaleHack = ConfigGetParamBool(l_ConfigVideoRice, "TextureScaleHack");762pGameSetting->bPrimaryDepthHack = ConfigGetParamBool(l_ConfigVideoRice, "PrimaryDepthHack");763pGameSetting->bTexture1Hack = ConfigGetParamBool(l_ConfigVideoRice, "Texture1Hack");764pGameSetting->bFastLoadTile = ConfigGetParamBool(l_ConfigVideoRice, "FastLoadTile");765pGameSetting->bUseSmallerTexture = ConfigGetParamBool(l_ConfigVideoRice, "UseSmallerTexture");766767pGameSetting->VIWidth = ConfigGetParamInt(l_ConfigVideoRice, "VIWidth");768pGameSetting->VIHeight = ConfigGetParamInt(l_ConfigVideoRice, "VIHeight");769pGameSetting->UseCIWidthAndRatio = ConfigGetParamInt(l_ConfigVideoRice, "UseCIWidthAndRatio");770pGameSetting->dwFullTMEM = ConfigGetParamInt(l_ConfigVideoRice, "FullTMEM");771pGameSetting->bTxtSizeMethod2 = ConfigGetParamBool(l_ConfigVideoRice, "TxtSizeMethod2");772pGameSetting->bEnableTxtLOD = ConfigGetParamBool(l_ConfigVideoRice, "EnableTxtLOD");773774pGameSetting->dwFastTextureCRC = ConfigGetParamInt(l_ConfigVideoRice, "FastTextureCRC");775pGameSetting->bEmulateClear = ConfigGetParamBool(l_ConfigVideoRice, "EmulateClear");776pGameSetting->bForceScreenClear = ConfigGetParamBool(l_ConfigVideoRice, "ForceScreenClear");777pGameSetting->dwAccurateTextureMapping = ConfigGetParamInt(l_ConfigVideoRice, "AccurateTextureMappingHack");778pGameSetting->dwNormalBlender = ConfigGetParamInt(l_ConfigVideoRice, "NormalBlender");779pGameSetting->bDisableBlender = ConfigGetParamBool(l_ConfigVideoRice, "DisableBlender");780pGameSetting->dwNormalCombiner = ConfigGetParamInt(l_ConfigVideoRice, "NormalCombiner");781pGameSetting->bForceDepthBuffer = ConfigGetParamBool(l_ConfigVideoRice, "ForceDepthBuffer");782pGameSetting->bDisableObjBG = ConfigGetParamBool(l_ConfigVideoRice, "DisableObjBG");783pGameSetting->dwFrameBufferOption = ConfigGetParamInt(l_ConfigVideoRice, "FrameBufferOption");784pGameSetting->dwRenderToTextureOption = ConfigGetParamInt(l_ConfigVideoRice, "RenderToTextureOption");785pGameSetting->dwScreenUpdateSetting = ConfigGetParamInt(l_ConfigVideoRice, "ScreenUpdateSettingHack");786}787788void Ini_StoreRomOptions(LPGAMESETTING pGameSetting)789{790int i;791792i = FindIniEntry(pGameSetting->romheader.dwCRC1,793pGameSetting->romheader.dwCRC2,794pGameSetting->romheader.nCountryID,795(char*)pGameSetting->szGameName, 0);796797if( IniSections[i].bDisableTextureCRC !=pGameSetting->bDisableTextureCRC )798{799IniSections[i].bDisableTextureCRC =pGameSetting->bDisableTextureCRC ;800bIniIsChanged=true;801}802803if( IniSections[i].bDisableCulling !=pGameSetting->bDisableCulling )804{805IniSections[i].bDisableCulling =pGameSetting->bDisableCulling ;806bIniIsChanged=true;807}808809if( IniSections[i].dwFastTextureCRC !=pGameSetting->dwFastTextureCRC )810{811IniSections[i].dwFastTextureCRC =pGameSetting->dwFastTextureCRC ;812bIniIsChanged=true;813}814815if( IniSections[i].bEmulateClear !=pGameSetting->bEmulateClear )816{817IniSections[i].bEmulateClear =pGameSetting->bEmulateClear ;818bIniIsChanged=true;819}820821if( IniSections[i].dwNormalBlender !=pGameSetting->dwNormalBlender )822{823IniSections[i].dwNormalBlender =pGameSetting->dwNormalBlender ;824bIniIsChanged=true;825}826827if( IniSections[i].bDisableBlender !=pGameSetting->bDisableBlender )828{829IniSections[i].bDisableBlender =pGameSetting->bDisableBlender ;830bIniIsChanged=true;831}832833if( IniSections[i].bForceScreenClear !=pGameSetting->bForceScreenClear )834{835IniSections[i].bForceScreenClear =pGameSetting->bForceScreenClear ;836bIniIsChanged=true;837}838if( IniSections[i].dwAccurateTextureMapping !=pGameSetting->dwAccurateTextureMapping )839{840IniSections[i].dwAccurateTextureMapping =pGameSetting->dwAccurateTextureMapping ;841bIniIsChanged=true;842}843if( IniSections[i].dwNormalCombiner !=pGameSetting->dwNormalCombiner )844{845IniSections[i].dwNormalCombiner =pGameSetting->dwNormalCombiner ;846bIniIsChanged=true;847}848if( IniSections[i].bForceDepthBuffer !=pGameSetting->bForceDepthBuffer )849{850IniSections[i].bForceDepthBuffer =pGameSetting->bForceDepthBuffer ;851bIniIsChanged=true;852}853if( IniSections[i].bDisableObjBG !=pGameSetting->bDisableObjBG )854{855IniSections[i].bDisableObjBG =pGameSetting->bDisableObjBG ;856bIniIsChanged=true;857}858if( IniSections[i].dwFrameBufferOption !=pGameSetting->dwFrameBufferOption )859{860IniSections[i].dwFrameBufferOption =pGameSetting->dwFrameBufferOption ;861bIniIsChanged=true;862}863if( IniSections[i].dwRenderToTextureOption !=pGameSetting->dwRenderToTextureOption )864{865IniSections[i].dwRenderToTextureOption =pGameSetting->dwRenderToTextureOption ;866bIniIsChanged=true;867}868if( IniSections[i].dwScreenUpdateSetting !=pGameSetting->dwScreenUpdateSetting )869{870IniSections[i].dwScreenUpdateSetting =pGameSetting->dwScreenUpdateSetting ;871bIniIsChanged=true;872}873if( IniSections[i].bIncTexRectEdge != pGameSetting->bIncTexRectEdge )874{875IniSections[i].bIncTexRectEdge =pGameSetting->bIncTexRectEdge;876bIniIsChanged=true;877}878if( IniSections[i].bZHack != pGameSetting->bZHack )879{880IniSections[i].bZHack =pGameSetting->bZHack;881bIniIsChanged=true;882}883if( IniSections[i].bTextureScaleHack != pGameSetting->bTextureScaleHack )884{885IniSections[i].bTextureScaleHack =pGameSetting->bTextureScaleHack;886bIniIsChanged=true;887}888if( IniSections[i].bPrimaryDepthHack != pGameSetting->bPrimaryDepthHack )889{890IniSections[i].bPrimaryDepthHack =pGameSetting->bPrimaryDepthHack;891bIniIsChanged=true;892}893if( IniSections[i].bTexture1Hack != pGameSetting->bTexture1Hack )894{895IniSections[i].bTexture1Hack =pGameSetting->bTexture1Hack;896bIniIsChanged=true;897}898if( IniSections[i].bFastLoadTile != pGameSetting->bFastLoadTile )899{900IniSections[i].bFastLoadTile =pGameSetting->bFastLoadTile;901bIniIsChanged=true;902}903if( IniSections[i].bUseSmallerTexture != pGameSetting->bUseSmallerTexture )904{905IniSections[i].bUseSmallerTexture =pGameSetting->bUseSmallerTexture;906bIniIsChanged=true;907}908if( IniSections[i].VIWidth != pGameSetting->VIWidth )909{910IniSections[i].VIWidth =pGameSetting->VIWidth;911bIniIsChanged=true;912}913if( IniSections[i].VIHeight != pGameSetting->VIHeight )914{915IniSections[i].VIHeight =pGameSetting->VIHeight;916bIniIsChanged=true;917}918if( IniSections[i].UseCIWidthAndRatio != pGameSetting->UseCIWidthAndRatio )919{920IniSections[i].UseCIWidthAndRatio =pGameSetting->UseCIWidthAndRatio;921bIniIsChanged=true;922}923if( IniSections[i].dwFullTMEM != pGameSetting->dwFullTMEM )924{925IniSections[i].dwFullTMEM =pGameSetting->dwFullTMEM;926bIniIsChanged=true;927}928if( IniSections[i].bTxtSizeMethod2 != pGameSetting->bTxtSizeMethod2 )929{930IniSections[i].bTxtSizeMethod2 =pGameSetting->bTxtSizeMethod2;931bIniIsChanged=true;932}933if( IniSections[i].bEnableTxtLOD != pGameSetting->bEnableTxtLOD )934{935IniSections[i].bEnableTxtLOD =pGameSetting->bEnableTxtLOD;936bIniIsChanged=true;937}938939if( bIniIsChanged )940{941WriteIniFile();942TRACE0("Rom option is changed and saved");943}944}945946std::ifstream& getline( std::ifstream &is, char *str );947948char * left(const char * src, int nchars)949{950static char dst[300];951strncpy(dst,src,nchars);952dst[nchars]=0;953return dst;954}955956char * right(const char *src, int nchars)957{958static char dst[300];959int srclen = strlen(src);960if (nchars >= srclen)961{962strcpy(dst, src);963}964else965{966strncpy(dst, src + srclen - nchars, nchars);967dst[nchars]=0;968}969return dst;970}971972char * tidy(char * s)973{974char * p = s + strlen(s);975976p--;977while (p >= s && (*p == ' ' || *p == 0xa || *p == '\n') )978{979*p = 0;980p--;981}982return s;983984}985986BOOL ReadIniFile()987{988std::ifstream inifile;989char readinfo[100];990//const char *ini_filepath = ConfigGetSharedDataFilepath(szIniFileName);991const char *ini_filepath = ".\\RiceVideoLinux.ini";992993DebugMessage(M64MSG_VERBOSE, "Reading .ini file: %s", ini_filepath);994inifile.open(ini_filepath);995996if (inifile.fail())997{998return FALSE;999}10001001while (getline(inifile,readinfo)/*&§ionno<999*/)1002{1003tidy(readinfo);10041005if (readinfo[0] == '/')1006continue;10071008if (!strcasecmp(readinfo,"")==0)1009{1010if (readinfo[0] == '{') //if a section heading1011{1012section newsection;10131014readinfo[strlen(readinfo)-1]='\0';1015strcpy(newsection.crccheck, readinfo+1);10161017newsection.bDisableTextureCRC = FALSE;1018newsection.bDisableCulling = FALSE;1019newsection.bIncTexRectEdge = FALSE;1020newsection.bZHack = FALSE;1021newsection.bTextureScaleHack = FALSE;1022newsection.bFastLoadTile = FALSE;1023newsection.bUseSmallerTexture = FALSE;1024newsection.bPrimaryDepthHack = FALSE;1025newsection.bTexture1Hack = FALSE;1026newsection.bDisableObjBG = FALSE;1027newsection.VIWidth = -1;1028newsection.VIHeight = -1;1029newsection.UseCIWidthAndRatio = NOT_USE_CI_WIDTH_AND_RATIO;1030newsection.dwFullTMEM = 0;1031newsection.bTxtSizeMethod2 = FALSE;1032newsection.bEnableTxtLOD = FALSE;10331034newsection.bEmulateClear = FALSE;1035newsection.bForceScreenClear = FALSE;1036newsection.bDisableBlender = FALSE;1037newsection.bForceDepthBuffer = FALSE;1038newsection.dwFastTextureCRC = 0;1039newsection.dwAccurateTextureMapping = 0;1040newsection.dwNormalBlender = 0;1041newsection.dwNormalCombiner = 0;1042newsection.dwFrameBufferOption = 0;1043newsection.dwRenderToTextureOption = 0;1044newsection.dwScreenUpdateSetting = 0;10451046IniSections.push_back(newsection);10471048}1049else1050{1051int sectionno = IniSections.size() - 1;10521053if (strcasecmp(left(readinfo,4), "Name")==0)1054strcpy(IniSections[sectionno].name,right(readinfo,strlen(readinfo)-5));10551056if (strcasecmp(left(readinfo,17), "DisableTextureCRC")==0)1057IniSections[sectionno].bDisableTextureCRC=true;10581059if (strcasecmp(left(readinfo,14), "DisableCulling")==0)1060IniSections[sectionno].bDisableCulling=true;10611062if (strcasecmp(left(readinfo,16), "PrimaryDepthHack")==0)1063IniSections[sectionno].bPrimaryDepthHack=true;10641065if (strcasecmp(left(readinfo,12), "Texture1Hack")==0)1066IniSections[sectionno].bTexture1Hack=true;10671068if (strcasecmp(left(readinfo,12), "FastLoadTile")==0)1069IniSections[sectionno].bFastLoadTile=true;10701071if (strcasecmp(left(readinfo,17), "UseSmallerTexture")==0)1072IniSections[sectionno].bUseSmallerTexture=true;10731074if (strcasecmp(left(readinfo,14), "IncTexRectEdge")==0)1075IniSections[sectionno].bIncTexRectEdge=true;10761077if (strcasecmp(left(readinfo,5), "ZHack")==0)1078IniSections[sectionno].bZHack=true;10791080if (strcasecmp(left(readinfo,16), "TexRectScaleHack")==0)1081IniSections[sectionno].bTextureScaleHack=true;10821083if (strcasecmp(left(readinfo,7), "VIWidth")==0)1084IniSections[sectionno].VIWidth = strtol(right(readinfo,3),NULL,10);10851086if (strcasecmp(left(readinfo,8), "VIHeight")==0)1087IniSections[sectionno].VIHeight = strtol(right(readinfo,3),NULL,10);10881089if (strcasecmp(left(readinfo,18), "UseCIWidthAndRatio")==0)1090IniSections[sectionno].UseCIWidthAndRatio = strtol(right(readinfo,1),NULL,10);10911092if (strcasecmp(left(readinfo,8), "FullTMEM")==0)1093IniSections[sectionno].dwFullTMEM = strtol(right(readinfo,1),NULL,10);10941095if (strcasecmp(left(readinfo,24), "AlternativeTxtSizeMethod")==0)1096IniSections[sectionno].bTxtSizeMethod2 = strtol(right(readinfo,1),NULL,10);10971098if (strcasecmp(left(readinfo,12), "EnableTxtLOD")==0)1099IniSections[sectionno].bEnableTxtLOD = strtol(right(readinfo,1),NULL,10);11001101if (strcasecmp(left(readinfo,12), "DisableObjBG")==0)1102IniSections[sectionno].bDisableObjBG = strtol(right(readinfo,1),NULL,10);11031104if (strcasecmp(left(readinfo,16), "ForceScreenClear")==0)1105IniSections[sectionno].bForceScreenClear = strtol(right(readinfo,1),NULL,10);11061107if (strcasecmp(left(readinfo,22), "AccurateTextureMapping")==0)1108IniSections[sectionno].dwAccurateTextureMapping = strtol(right(readinfo,1),NULL,10);11091110if (strcasecmp(left(readinfo,14), "FastTextureCRC")==0)1111IniSections[sectionno].dwFastTextureCRC = strtol(right(readinfo,1),NULL,10);11121113if (strcasecmp(left(readinfo,12), "EmulateClear")==0)1114IniSections[sectionno].bEmulateClear = strtol(right(readinfo,1),NULL,10);11151116if (strcasecmp(left(readinfo,18), "NormalAlphaBlender")==0)1117IniSections[sectionno].dwNormalBlender = strtol(right(readinfo,1),NULL,10);11181119if (strcasecmp(left(readinfo,19), "DisableAlphaBlender")==0)1120IniSections[sectionno].bDisableBlender = strtol(right(readinfo,1),NULL,10);11211122if (strcasecmp(left(readinfo,19), "NormalColorCombiner")==0)1123IniSections[sectionno].dwNormalCombiner = strtol(right(readinfo,1),NULL,10);11241125if (strcasecmp(left(readinfo,16), "ForceDepthBuffer")==0)1126IniSections[sectionno].bForceDepthBuffer = strtol(right(readinfo,1),NULL,10);11271128if (strcasecmp(left(readinfo,20), "FrameBufferEmulation")==0)1129IniSections[sectionno].dwFrameBufferOption = strtol(readinfo+21,NULL,10);11301131if (strcasecmp(left(readinfo,15), "RenderToTexture")==0)1132IniSections[sectionno].dwRenderToTextureOption = strtol(right(readinfo,1),NULL,10);11331134if (strcasecmp(left(readinfo,19), "ScreenUpdateSetting")==0)1135IniSections[sectionno].dwScreenUpdateSetting = strtol(right(readinfo,1),NULL,10);1136}1137}1138}1139inifile.close();11401141return TRUE;1142}11431144//read a line from the ini file1145std::ifstream & getline(std::ifstream & is, char *str)1146{1147char buf[100];11481149is.getline(buf,100);1150strcpy( str,buf);1151return is;1152}11531154void WriteIniFile()1155{1156uint32 i;1157FILE * fhIn;1158FILE * fhOut;11591160/* get path to game-hack INI file and read it */1161const char *ini_filepath = ConfigGetSharedDataFilepath(szIniFileName);1162if (ini_filepath == NULL)1163return;1164fhIn = fopen(ini_filepath, "r");1165if (fhIn == NULL)1166return;1167fseek(fhIn, 0L, SEEK_END);1168long filelen = ftell(fhIn);1169fseek(fhIn, 0L, SEEK_SET);1170char *chIniData = (char *) malloc(filelen + 1);1171if (chIniData == NULL)1172{1173fclose(fhIn);1174return;1175}1176long bytesread = fread(chIniData, 1, filelen, fhIn);1177fclose(fhIn);1178if (bytesread != filelen)1179{1180free(chIniData);1181return;1182}1183chIniData[filelen] = 0;11841185/* now try to open the file for writing */1186fhOut = fopen(ini_filepath, "w");1187if (fhOut == NULL)1188{1189free(chIniData);1190return;1191}11921193// Mark all sections and needing to be written1194for (i = 0; i < IniSections.size(); i++)1195{1196IniSections[i].bOutput = false;1197}11981199char *thisline = chIniData;1200while ((thisline - chIniData) < filelen)1201{1202char *nextline = strchr(thisline, '\n');1203if (nextline == NULL)1204nextline = thisline + strlen(thisline) + 1;1205else1206nextline++;1207if (thisline[0] == '{')1208{1209BOOL bFound = FALSE;1210// Start of section1211tidy((char*) thisline);1212thisline[strlen(thisline) - 1] = '\0';1213for (i = 0; i < IniSections.size(); i++)1214{1215if (IniSections[i].bOutput)1216continue;1217if (strcasecmp((char*) thisline + 1, IniSections[i].crccheck) == 0)1218{1219// Output this CRC1220OutputSectionDetails(i, fhOut);1221IniSections[i].bOutput = true;1222bFound = TRUE;1223break;1224}1225}1226if (!bFound)1227{1228// Do what? This should never happen, unless the user1229// replaces the inifile while game is running!1230}1231}1232else if (thisline[0] == '/')1233{1234// Comment1235fputs((char*) thisline, fhOut);1236}1237thisline = nextline;1238}12391240// Input buffer done- process any new entries!1241for (i = 0; i < IniSections.size(); i++)1242{1243// Skip any that have not been done.1244if (IniSections[i].bOutput)1245continue;1246// Output this CRC1247OutputSectionDetails(i, fhOut);1248IniSections[i].bOutput = true;1249}12501251fclose(fhOut);1252free(chIniData);12531254bIniIsChanged = false;1255}12561257void OutputSectionDetails(uint32 i, FILE * fh)1258{1259fprintf(fh, "{%s}\n", IniSections[i].crccheck);12601261fprintf(fh, "Name=%s\n", IniSections[i].name);1262//fprintf(fh, "UCode=%d\n", IniSections[i].ucode);12631264// Tri-state variables1265if (IniSections[i].dwAccurateTextureMapping != 0)1266fprintf(fh, "AccurateTextureMapping=%d\n", IniSections[i].dwAccurateTextureMapping);12671268if (IniSections[i].dwFastTextureCRC != 0)1269fprintf(fh, "FastTextureCRC=%d\n", IniSections[i].dwFastTextureCRC);12701271if (IniSections[i].dwNormalBlender != 0)1272fprintf(fh, "NormalAlphaBlender=%d\n", IniSections[i].dwNormalBlender);12731274if (IniSections[i].dwNormalCombiner != 0)1275fprintf(fh, "NormalColorCombiner=%d\n", IniSections[i].dwNormalCombiner);127612771278// Normal bi-state variables1279if (IniSections[i].bDisableTextureCRC)1280fprintf(fh, "DisableTextureCRC\n");12811282if (IniSections[i].bDisableCulling)1283fprintf(fh, "DisableCulling\n");12841285if (IniSections[i].bPrimaryDepthHack)1286fprintf(fh, "PrimaryDepthHack\n");12871288if (IniSections[i].bTexture1Hack)1289fprintf(fh, "Texture1Hack\n");12901291if (IniSections[i].bFastLoadTile)1292fprintf(fh, "FastLoadTile\n");12931294if (IniSections[i].bUseSmallerTexture)1295fprintf(fh, "UseSmallerTexture\n");12961297if (IniSections[i].bIncTexRectEdge)1298fprintf(fh, "IncTexRectEdge\n");12991300if (IniSections[i].bZHack)1301fprintf(fh, "ZHack\n");13021303if (IniSections[i].bTextureScaleHack)1304fprintf(fh, "TexRectScaleHack\n");13051306if (IniSections[i].VIWidth > 0)1307fprintf(fh, "VIWidth=%d\n", IniSections[i].VIWidth);13081309if (IniSections[i].VIHeight > 0)1310fprintf(fh, "VIHeight=%d\n", IniSections[i].VIHeight);13111312if (IniSections[i].UseCIWidthAndRatio > 0)1313fprintf(fh, "UseCIWidthAndRatio=%d\n", IniSections[i].UseCIWidthAndRatio);13141315if (IniSections[i].dwFullTMEM > 0)1316fprintf(fh, "FullTMEM=%d\n", IniSections[i].dwFullTMEM);13171318if (IniSections[i].bTxtSizeMethod2 != FALSE )1319fprintf(fh, "AlternativeTxtSizeMethod=%d\n", IniSections[i].bTxtSizeMethod2);13201321if (IniSections[i].bEnableTxtLOD != FALSE )1322fprintf(fh, "EnableTxtLOD=%d\n", IniSections[i].bEnableTxtLOD);13231324if (IniSections[i].bDisableObjBG != 0 )1325fprintf(fh, "DisableObjBG=%d\n", IniSections[i].bDisableObjBG);13261327if (IniSections[i].bForceScreenClear != 0)1328fprintf(fh, "ForceScreenClear=%d\n", IniSections[i].bForceScreenClear);13291330if (IniSections[i].bEmulateClear != 0)1331fprintf(fh, "EmulateClear=%d\n", IniSections[i].bEmulateClear);13321333if (IniSections[i].bDisableBlender != 0)1334fprintf(fh, "DisableAlphaBlender=%d\n", IniSections[i].bDisableBlender);13351336if (IniSections[i].bForceDepthBuffer != 0)1337fprintf(fh, "ForceDepthBuffer=%d\n", IniSections[i].bForceDepthBuffer);13381339if (IniSections[i].dwFrameBufferOption != 0)1340fprintf(fh, "FrameBufferEmulation=%d\n", IniSections[i].dwFrameBufferOption);13411342if (IniSections[i].dwRenderToTextureOption != 0)1343fprintf(fh, "RenderToTexture=%d\n", IniSections[i].dwRenderToTextureOption);13441345if (IniSections[i].dwScreenUpdateSetting != 0)1346fprintf(fh, "ScreenUpdateSetting=%d\n", IniSections[i].dwScreenUpdateSetting);13471348fprintf(fh, "\n"); // Spacer1349}13501351// Find the entry corresponding to the specified rom.1352// If the rom is not found, a new entry is created1353// The resulting value is returned1354void __cdecl DebuggerAppendMsg (const char * Message, ...);13551356static int FindIniEntry(uint32 dwCRC1, uint32 dwCRC2, uint8 nCountryID, char* szName, int PrintInfo)1357{1358uint32 i;1359unsigned char szCRC[50+1];13601361// Generate the CRC-ID for this rom:1362sprintf((char*)szCRC, "%08x%08x-%02x", (unsigned int)dwCRC1, (unsigned int)dwCRC2, nCountryID);13631364for (i = 0; i < IniSections.size(); i++)1365{1366if (strcasecmp((char*)szCRC, IniSections[i].crccheck) == 0)1367{1368if (PrintInfo)1369DebugMessage(M64MSG_INFO, "Found ROM '%s', CRC %s", IniSections[i].name, szCRC);1370return i;1371}1372}13731374// Add new entry!!!1375section newsection;13761377if (PrintInfo)1378DebugMessage(M64MSG_INFO, "ROM (CRC %s) not found in INI file", szCRC);13791380strcpy(newsection.crccheck, (char*)szCRC);13811382strncpy(newsection.name, szName, 50);1383newsection.bDisableTextureCRC = FALSE;1384newsection.bDisableCulling = FALSE;1385newsection.bIncTexRectEdge = FALSE;1386newsection.bZHack = FALSE;1387newsection.bTextureScaleHack = FALSE;1388newsection.bFastLoadTile = FALSE;1389newsection.bUseSmallerTexture = FALSE;1390newsection.bPrimaryDepthHack = FALSE;1391newsection.bTexture1Hack = FALSE;1392newsection.bDisableObjBG = FALSE;1393newsection.VIWidth = -1;1394newsection.VIHeight = -1;1395newsection.UseCIWidthAndRatio = NOT_USE_CI_WIDTH_AND_RATIO;1396newsection.dwFullTMEM = 0;1397newsection.bTxtSizeMethod2 = FALSE;1398newsection.bEnableTxtLOD = FALSE;13991400newsection.bEmulateClear = FALSE;1401newsection.bForceScreenClear = FALSE;1402newsection.bDisableBlender = FALSE;1403newsection.bForceDepthBuffer = FALSE;1404newsection.dwFastTextureCRC = 0;1405newsection.dwAccurateTextureMapping = 0;1406newsection.dwNormalBlender = 0;1407newsection.dwNormalCombiner = 0;1408newsection.dwFrameBufferOption = 0;1409newsection.dwRenderToTextureOption = 0;1410newsection.dwScreenUpdateSetting = 0;14111412IniSections.push_back(newsection);14131414bIniIsChanged = true; // Flag to indicate we should be updated1415return IniSections.size()-1; // -1 takes into account increment1416}14171418GameSetting g_curRomInfo;14191420void ROM_GetRomNameFromHeader(unsigned char * szName, ROMHeader * pHdr)1421{1422unsigned char * p;14231424memcpy(szName, pHdr->szName, 20);1425szName[20] = '\0';14261427p = szName + (strlen((char*)szName) -1); // -1 to skip null1428while (p >= szName && *p == ' ')1429{1430*p = 0;1431p--;1432}1433}14341435uint32 CountryCodeToTVSystem(uint32 countryCode)1436{1437uint32 system;1438switch(countryCode)1439{1440/* Demo */1441case 0:1442system = TV_SYSTEM_NTSC;1443break;14441445case '7':1446system = TV_SYSTEM_NTSC;1447break;14481449case 0x41:1450system = TV_SYSTEM_NTSC;1451break;14521453/* Germany */1454case 0x44:1455system = TV_SYSTEM_PAL;1456break;14571458/* USA */1459case 0x45:1460system = TV_SYSTEM_NTSC;1461break;14621463/* France */1464case 0x46:1465system = TV_SYSTEM_PAL;1466break;14671468/* Italy */1469case 'I':1470system = TV_SYSTEM_PAL;1471break;14721473/* Japan */1474case 0x4A:1475system = TV_SYSTEM_NTSC;1476break;14771478/* Europe - PAL */1479case 0x50:1480system = TV_SYSTEM_PAL;1481break;14821483case 'S': /* Spain */1484system = TV_SYSTEM_PAL;1485break;14861487/* Australia */1488case 0x55:1489system = TV_SYSTEM_PAL;1490break;14911492case 0x58:1493system = TV_SYSTEM_PAL;1494break;14951496/* Australia */1497case 0x59:1498system = TV_SYSTEM_PAL;1499break;15001501case 0x20:1502case 0x21:1503case 0x38:1504case 0x70:1505system = TV_SYSTEM_PAL;1506break;15071508/* ??? */1509default:1510system = TV_SYSTEM_PAL;1511break;1512}15131514return system;1515}15161517151815191520