From db00f689c89959022764dc15c9a41a3e7298681d Mon Sep 17 00:00:00 2001 From: Twinaphex Date: Tue, 10 Apr 2012 21:23:42 +0200 Subject: [PATCH] Fixed indenting in a lot of console files --- 360/fonts.cpp | 242 +++-- 360/main.c | 840 ++++++++-------- 360/menu.cpp | 826 +++++++-------- 360/xdk360_input.c | 143 ++- 360/xdk360_video.cpp | 489 ++++----- console/fileio/file_browser.c | 65 +- console/logger/logger.c | 96 +- ps3/image.c | 332 +++---- ps3/ps3_input.c | 70 +- ps3/ps3_input.h | 26 +- ps3/ps3_video_psgl.c | 1768 ++++++++++++++++----------------- ps3/salamander/main.c | 409 ++++---- 12 files changed, 2655 insertions(+), 2651 deletions(-) diff --git a/360/fonts.cpp b/360/fonts.cpp index 12ec97d373..de9765eec9 100644 --- a/360/fonts.cpp +++ b/360/fonts.cpp @@ -127,7 +127,7 @@ void xdk360_console_deinit() } // Destroy the font - xdk360_video_font_deinit(&m_Font); + xdk360_video_font_deinit(&m_Font); } void xdk360_console_add( wchar_t wch ) @@ -135,11 +135,11 @@ void xdk360_console_add( wchar_t wch ) // If this is a newline, just increment lines and move on if( wch == L'\n' ) { - video_console.m_nCurLine = ( video_console.m_nCurLine + 1 ) - % video_console.m_cScreenHeightVirtual; - video_console.m_cCurLineLength = 0; - memset(video_console.m_Lines[video_console.m_nCurLine], 0, - ( video_console.m_cScreenWidth + 1 ) * sizeof( wchar_t ) ); + video_console.m_nCurLine = ( video_console.m_nCurLine + 1 ) + % video_console.m_cScreenHeightVirtual; + video_console.m_cCurLineLength = 0; + memset(video_console.m_Lines[video_console.m_nCurLine], 0, + ( video_console.m_cScreenWidth + 1 ) * sizeof( wchar_t ) ); return; } @@ -180,85 +180,84 @@ void xdk360_console_add( wchar_t wch ) void xdk360_console_format(_In_z_ _Printf_format_string_ LPCSTR strFormat, ... ) { - video_console.m_nCurLine = 0; - video_console.m_cCurLineLength = 0; - memset( video_console.m_Buffer, 0, - video_console.m_cScreenHeightVirtual * - ( video_console.m_cScreenWidth + 1 ) * sizeof( wchar_t ) ); + video_console.m_nCurLine = 0; + video_console.m_cCurLineLength = 0; + memset( video_console.m_Buffer, 0, + video_console.m_cScreenHeightVirtual * + ( video_console.m_cScreenWidth + 1 ) * sizeof( wchar_t ) ); - va_list pArgList; - va_start( pArgList, strFormat ); - - // Count the required length of the string - unsigned long dwStrLen = _vscprintf( strFormat, pArgList ) + 1; - // +1 = null terminator - char * strMessage = ( char * )_malloca( dwStrLen ); - vsprintf_s( strMessage, dwStrLen, strFormat, pArgList ); + va_list pArgList; + va_start( pArgList, strFormat ); - // Output the string to the console - unsigned long uStringLength = strlen( strMessage ); - for( unsigned long i = 0; i < uStringLength; i++ ) - { - wchar_t wch; - int ret = MultiByteToWideChar( CP_ACP, // ANSI code page - 0, // No flags - &strMessage[i], // Character to convert - 1, // Convert one byte - &wch, // Target wide character buffer - 1 ); // One wide character - xdk360_console_add( wch ); - } + // Count the required length of the string + unsigned long dwStrLen = _vscprintf( strFormat, pArgList ) + 1; + // +1 = null terminator + char * strMessage = ( char * )_malloca( dwStrLen ); + vsprintf_s( strMessage, dwStrLen, strFormat, pArgList ); - _freea( strMessage ); + // Output the string to the console + unsigned long uStringLength = strlen( strMessage ); + for( unsigned long i = 0; i < uStringLength; i++ ) + { + wchar_t wch; + int ret = MultiByteToWideChar( CP_ACP, // ANSI code page + 0, // No flags + &strMessage[i], // Character to convert + 1, // Convert one byte + &wch, // Target wide character buffer + 1 ); // One wide character + xdk360_console_add( wch ); + } - va_end( pArgList ); + _freea( strMessage ); + + va_end( pArgList ); } void xdk360_console_format_w(_In_z_ _Printf_format_string_ LPCWSTR wstrFormat, ... ) { - video_console.m_nCurLine = 0; - video_console.m_cCurLineLength = 0; - memset( video_console.m_Buffer, 0, video_console.m_cScreenHeightVirtual - * ( video_console.m_cScreenWidth + 1 ) * sizeof( wchar_t ) ); + video_console.m_nCurLine = 0; + video_console.m_cCurLineLength = 0; + memset( video_console.m_Buffer, 0, video_console.m_cScreenHeightVirtual + * ( video_console.m_cScreenWidth + 1 ) * sizeof( wchar_t ) ); - va_list pArgList; - va_start( pArgList, wstrFormat ); + va_list pArgList; + va_start( pArgList, wstrFormat ); - // Count the required length of the string - unsigned long dwStrLen = _vscwprintf( wstrFormat, pArgList ) + 1; // +1 = null terminator - wchar_t * strMessage = ( wchar_t * )_malloca( dwStrLen * sizeof( wchar_t ) ); - vswprintf_s( strMessage, dwStrLen, wstrFormat, pArgList ); + // Count the required length of the string + unsigned long dwStrLen = _vscwprintf( wstrFormat, pArgList ) + 1; // +1 = null terminator + wchar_t * strMessage = ( wchar_t * )_malloca( dwStrLen * sizeof( wchar_t ) ); + vswprintf_s( strMessage, dwStrLen, wstrFormat, pArgList ); - // Output the string to the console - unsigned long uStringLength = wcslen( strMessage ); - for( unsigned long i = 0; i < uStringLength; i++ ) - xdk360_console_add( strMessage[i] ); + // Output the string to the console + unsigned long uStringLength = wcslen( strMessage ); + for( unsigned long i = 0; i < uStringLength; i++ ) + xdk360_console_add( strMessage[i] ); - _freea( strMessage ); + _freea( strMessage ); - va_end( pArgList ); + va_end( pArgList ); } #define CALCFONTFILEHEADERSIZE(x) ( sizeof(unsigned long) + (sizeof(float)* 4) + sizeof(unsigned short) + (sizeof(wchar_t)*(x)) ) #define FONTFILEVERSION 5 typedef struct FontFileHeaderImage_t { - unsigned long m_dwFileVersion; // Version of the font file (Must match FONTFILEVERSION) - float m_fFontHeight; // Height of the font strike in pixels - float m_fFontTopPadding; // Padding above the strike zone - float m_fFontBottomPadding; // Padding below the strike zone - float m_fFontYAdvance; // Number of pixels to move the cursor for a line feed - unsigned short m_cMaxGlyph; // Number of font characters (Should be an odd number to maintain DWORD Alignment) - wchar_t m_TranslatorTable[1]; // ASCII to Glyph lookup table, NOTE: It's m_cMaxGlyph+1 in size. - // Entry 0 maps to the "Unknown" glyph. + unsigned long m_dwFileVersion; // Version of the font file (Must match FONTFILEVERSION) + float m_fFontHeight; // Height of the font strike in pixels + float m_fFontTopPadding; // Padding above the strike zone + float m_fFontBottomPadding; // Padding below the strike zone + float m_fFontYAdvance; // Number of pixels to move the cursor for a line feed + unsigned short m_cMaxGlyph; // Number of font characters (Should be an odd number to maintain DWORD Alignment) + wchar_t m_TranslatorTable[1]; // ASCII to Glyph lookup table, NOTE: It's m_cMaxGlyph+1 in size. } FontFileHeaderImage_t; // Font strike array. Immediately follows the FontFileHeaderImage_t // structure image typedef struct FontFileStrikesImage_t { - unsigned long m_dwNumGlyphs; // Size of font strike array (First entry is the unknown glyph) - GLYPH_ATTR m_Glyphs[1]; // Array of font strike uv's etc... NOTE: It's m_dwNumGlyphs in size + unsigned long m_dwNumGlyphs; // Size of font strike array (First entry is the unknown glyph) + GLYPH_ATTR m_Glyphs[1]; // Array of font strike uv's etc... NOTE: It's m_dwNumGlyphs in size } FontFileStrikesImage_t; static PackedResource m_xprResource; @@ -334,8 +333,7 @@ static HRESULT xdk360_video_font_create_shaders (xdk360_video_font_t * font) { // Use the do {} while(0); trick for a fake goto // It simplies tear down on error conditions. - do - { + do{ // Step #1, create my vertex array with 16 bytes per entry // Floats for the position, @@ -414,83 +412,83 @@ static HRESULT xdk360_video_font_create_shaders (xdk360_video_font_t * font) void xdk360_video_font_set_size(xdk360_video_font_t * font, float x, float y) { - font->m_fXScaleFactor = x; - font->m_fYScaleFactor = y; + font->m_fXScaleFactor = x; + font->m_fYScaleFactor = y; } HRESULT xdk360_video_font_init(xdk360_video_font_t * font, const char * strFontFileName) { - font->m_pFontTexture = NULL; - font->m_dwNumGlyphs = 0L; - font->m_Glyphs = NULL; - font->m_fCursorX = 0.0f; - font->m_fCursorY = 0.0f; - font->m_fXScaleFactor = 2.0f; - font->m_fYScaleFactor = 2.0f; - font->m_cMaxGlyph = 0; - font->m_TranslatorTable = NULL; - font->m_dwNestedBeginCount = 0L; + font->m_pFontTexture = NULL; + font->m_dwNumGlyphs = 0L; + font->m_Glyphs = NULL; + font->m_fCursorX = 0.0f; + font->m_fCursorY = 0.0f; + font->m_fXScaleFactor = 2.0f; + font->m_fYScaleFactor = 2.0f; + font->m_cMaxGlyph = 0; + font->m_TranslatorTable = NULL; + font->m_dwNestedBeginCount = 0L; - // Create the font - if( FAILED( m_xprResource.Create( strFontFileName ) ) ) - return E_FAIL; + // Create the font + if( FAILED( m_xprResource.Create( strFontFileName ) ) ) + return E_FAIL; - D3DTexture * pFontTexture = m_xprResource.GetTexture( "FontTexture" ); - const void * pFontData = m_xprResource.GetData( "FontData"); + D3DTexture * pFontTexture = m_xprResource.GetTexture( "FontTexture" ); + const void * pFontData = m_xprResource.GetData( "FontData"); - // Save a copy of the texture - font->m_pFontTexture = pFontTexture; + // Save a copy of the texture + font->m_pFontTexture = pFontTexture; - // Check version of file (to make sure it matches up with the FontMaker tool) - const unsigned char * pData = static_cast(pFontData); - unsigned long dwFileVersion = reinterpret_cast(pData)->m_dwFileVersion; + // Check version of file (to make sure it matches up with the FontMaker tool) + const unsigned char * pData = static_cast(pFontData); + unsigned long dwFileVersion = reinterpret_cast(pData)->m_dwFileVersion; - if( dwFileVersion == FONTFILEVERSION ) - { - font->m_fFontHeight = reinterpret_cast(pData)->m_fFontHeight; - font->m_fFontTopPadding = reinterpret_cast(pData)->m_fFontTopPadding; - font->m_fFontBottomPadding = reinterpret_cast(pData)->m_fFontBottomPadding; - font->m_fFontYAdvance = reinterpret_cast(pData)->m_fFontYAdvance; + if( dwFileVersion == FONTFILEVERSION ) + { + font->m_fFontHeight = reinterpret_cast(pData)->m_fFontHeight; + font->m_fFontTopPadding = reinterpret_cast(pData)->m_fFontTopPadding; + font->m_fFontBottomPadding = reinterpret_cast(pData)->m_fFontBottomPadding; + font->m_fFontYAdvance = reinterpret_cast(pData)->m_fFontYAdvance; - // Point to the translator string which immediately follows the 4 floats - font->m_cMaxGlyph = reinterpret_cast(pData)->m_cMaxGlyph; - - font->m_TranslatorTable = const_cast(reinterpret_cast(pData))->m_TranslatorTable; + // Point to the translator string which immediately follows the 4 floats + font->m_cMaxGlyph = reinterpret_cast(pData)->m_cMaxGlyph; - pData += CALCFONTFILEHEADERSIZE( font->m_cMaxGlyph + 1 ); + font->m_TranslatorTable = const_cast(reinterpret_cast(pData))->m_TranslatorTable; - // Read the glyph attributes from the file - font->m_dwNumGlyphs = reinterpret_cast(pData)->m_dwNumGlyphs; - font->m_Glyphs = reinterpret_cast(pData)->m_Glyphs; // Pointer - } - else - { - SSNES_ERR( "Incorrect version number on font file.\n" ); - return E_FAIL; - } + pData += CALCFONTFILEHEADERSIZE( font->m_cMaxGlyph + 1 ); - // Create the vertex and pixel shaders for rendering the font - if( FAILED( xdk360_video_font_create_shaders(font) ) ) - { - SSNES_ERR( "Could not create font shaders.\n" ); - return E_FAIL; - } + // Read the glyph attributes from the file + font->m_dwNumGlyphs = reinterpret_cast(pData)->m_dwNumGlyphs; + font->m_Glyphs = reinterpret_cast(pData)->m_Glyphs; // Pointer + } + else + { + SSNES_ERR( "Incorrect version number on font file.\n" ); + return E_FAIL; + } - xdk360_video_t *vid = (xdk360_video_t*)g_d3d; - D3DDevice *pd3dDevice = vid->xdk360_render_device; + // Create the vertex and pixel shaders for rendering the font + if( FAILED( xdk360_video_font_create_shaders(font) ) ) + { + SSNES_ERR( "Could not create font shaders.\n" ); + return E_FAIL; + } - // Initialize the window - D3DDISPLAYMODE DisplayMode; - pd3dDevice->GetDisplayMode( 0, &DisplayMode ); - font->m_rcWindow.x1 = 0; - font->m_rcWindow.y1 = 0; - font->m_rcWindow.x2 = DisplayMode.Width; - font->m_rcWindow.y2 = DisplayMode.Height; + xdk360_video_t *vid = (xdk360_video_t*)g_d3d; + D3DDevice *pd3dDevice = vid->xdk360_render_device; - // Determine whether we should save/restore state - font->m_bSaveState = TRUE; + // Initialize the window + D3DDISPLAYMODE DisplayMode; + pd3dDevice->GetDisplayMode( 0, &DisplayMode ); + font->m_rcWindow.x1 = 0; + font->m_rcWindow.y1 = 0; + font->m_rcWindow.x2 = DisplayMode.Width; + font->m_rcWindow.y2 = DisplayMode.Height; - return S_OK; + // Determine whether we should save/restore state + font->m_bSaveState = TRUE; + + return S_OK; } void xdk360_video_font_deinit(xdk360_video_font_t * font) diff --git a/360/main.c b/360/main.c index 54a1c30f81..23df58e16e 100644 --- a/360/main.c +++ b/360/main.c @@ -45,9 +45,9 @@ #define DEVICE_CACHE 11 typedef struct _STRING { - unsigned short Length; - unsigned short MaximumLength; - char * Buffer; + unsigned short Length; + unsigned short MaximumLength; + char * Buffer; } STRING; char DEFAULT_SHADER_FILE[MAX_PATH_LENGTH]; @@ -63,532 +63,538 @@ int ssnes_main(int argc, char *argv[]); static int DriveMounted(std::string path) { - WIN32_FIND_DATA findFileData; - memset(&findFileData,0,sizeof(WIN32_FIND_DATA)); - std::string searchcmd = path + "\\*.*"; - HANDLE hFind = FindFirstFile(searchcmd.c_str(), &findFileData); + WIN32_FIND_DATA findFileData; + memset(&findFileData,0,sizeof(WIN32_FIND_DATA)); + std::string searchcmd = path + "\\*.*"; + HANDLE hFind = FindFirstFile(searchcmd.c_str(), &findFileData); - if (hFind == INVALID_HANDLE_VALUE) - return 0; + if (hFind == INVALID_HANDLE_VALUE) + return 0; - FindClose(hFind); + FindClose(hFind); - return 1; + return 1; } static int Mount( int Device, char* MountPoint ) { - char MountConv[260]; - sprintf_s( MountConv,"\\??\\%s", MountPoint ); + char MountConv[260]; + char * SysPath = NULL; - char * SysPath = NULL; - switch( Device ) - { - case DEVICE_MEMORY_UNIT0: - SysPath = "\\Device\\Mu0"; - break; - case DEVICE_MEMORY_UNIT1: - SysPath = "\\Device\\Mu1"; - break; - case DEVICE_MEMORY_ONBOARD: - SysPath = "\\Device\\BuiltInMuSfc"; - break; - case DEVICE_CDROM0: - SysPath = "\\Device\\Cdrom0"; - break; - case DEVICE_HARDISK0_PART1: - SysPath = "\\Device\\Harddisk0\\Partition1"; - break; - case DEVICE_HARDISK0_SYSPART: - SysPath = "\\Device\\Harddisk0\\SystemPartition"; - break; - case DEVICE_USB0: - SysPath = "\\Device\\Mass0"; - break; - case DEVICE_USB1: - SysPath = "\\Device\\Mass1"; - break; - case DEVICE_USB2: - SysPath = "\\Device\\Mass2"; - break; - case DEVICE_CACHE: - SysPath = "\\Device\\Harddisk0\\Cache0"; - break; + sprintf_s( MountConv,"\\??\\%s", MountPoint ); - } + switch( Device ) + { + case DEVICE_MEMORY_UNIT0: + SysPath = "\\Device\\Mu0"; + break; + case DEVICE_MEMORY_UNIT1: + SysPath = "\\Device\\Mu1"; + break; + case DEVICE_MEMORY_ONBOARD: + SysPath = "\\Device\\BuiltInMuSfc"; + break; + case DEVICE_CDROM0: + SysPath = "\\Device\\Cdrom0"; + break; + case DEVICE_HARDISK0_PART1: + SysPath = "\\Device\\Harddisk0\\Partition1"; + break; + case DEVICE_HARDISK0_SYSPART: + SysPath = "\\Device\\Harddisk0\\SystemPartition"; + break; + case DEVICE_USB0: + SysPath = "\\Device\\Mass0"; + break; + case DEVICE_USB1: + SysPath = "\\Device\\Mass1"; + break; + case DEVICE_USB2: + SysPath = "\\Device\\Mass2"; + break; + case DEVICE_CACHE: + SysPath = "\\Device\\Harddisk0\\Cache0"; + break; + } - STRING sSysPath = { (USHORT)strlen( SysPath ), (USHORT)strlen( SysPath ) + 1, SysPath }; - STRING sMountConv = { (USHORT)strlen( MountConv ), (USHORT)strlen( MountConv ) + 1, MountConv }; - int res = ObCreateSymbolicLink( &sMountConv, &sSysPath ); + STRING sSysPath = { (USHORT)strlen( SysPath ), (USHORT)strlen( SysPath ) + 1, SysPath }; + STRING sMountConv = { (USHORT)strlen( MountConv ), (USHORT)strlen( MountConv ) + 1, MountConv }; + int res = ObCreateSymbolicLink( &sMountConv, &sSysPath ); - if (res != 0) - return res; + if (res != 0) + return res; - return DriveMounted(MountPoint); + return DriveMounted(MountPoint); } static void set_default_settings (void) { - //g_settings - g_settings.rewind_enable = false; - strlcpy(g_settings.video.cg_shader_path, DEFAULT_SHADER_FILE, sizeof(g_settings.video.cg_shader_path)); - g_settings.video.vsync = true; - g_settings.video.smooth = true; - g_settings.video.aspect_ratio = -1.0f; + //g_settings + g_settings.rewind_enable = false; + strlcpy(g_settings.video.cg_shader_path, DEFAULT_SHADER_FILE, sizeof(g_settings.video.cg_shader_path)); + g_settings.video.vsync = true; + g_settings.video.smooth = true; + g_settings.video.aspect_ratio = -1.0f; - ssnes_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_B] = ssnes_platform_keybind_lut[XDK360_DEVICE_ID_JOYPAD_A]; - ssnes_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_Y] = ssnes_platform_keybind_lut[XDK360_DEVICE_ID_JOYPAD_X]; - ssnes_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_SELECT] = ssnes_platform_keybind_lut[XDK360_DEVICE_ID_JOYPAD_BACK]; - ssnes_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_START] = ssnes_platform_keybind_lut[XDK360_DEVICE_ID_JOYPAD_START]; - ssnes_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_UP] = ssnes_platform_keybind_lut[XDK360_DEVICE_ID_JOYPAD_UP]; - ssnes_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_DOWN] = ssnes_platform_keybind_lut[XDK360_DEVICE_ID_JOYPAD_DOWN]; - ssnes_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_LEFT] = ssnes_platform_keybind_lut[XDK360_DEVICE_ID_JOYPAD_LEFT]; - ssnes_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_RIGHT] = ssnes_platform_keybind_lut[XDK360_DEVICE_ID_JOYPAD_RIGHT]; - ssnes_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_A] = ssnes_platform_keybind_lut[XDK360_DEVICE_ID_JOYPAD_B]; - ssnes_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_X] = ssnes_platform_keybind_lut[XDK360_DEVICE_ID_JOYPAD_Y]; - ssnes_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_L] = ssnes_platform_keybind_lut[XDK360_DEVICE_ID_JOYPAD_LB]; - ssnes_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_R] = ssnes_platform_keybind_lut[XDK360_DEVICE_ID_JOYPAD_RB]; + ssnes_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_B] = ssnes_platform_keybind_lut[XDK360_DEVICE_ID_JOYPAD_A]; + ssnes_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_Y] = ssnes_platform_keybind_lut[XDK360_DEVICE_ID_JOYPAD_X]; + ssnes_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_SELECT] = ssnes_platform_keybind_lut[XDK360_DEVICE_ID_JOYPAD_BACK]; + ssnes_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_START] = ssnes_platform_keybind_lut[XDK360_DEVICE_ID_JOYPAD_START]; + ssnes_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_UP] = ssnes_platform_keybind_lut[XDK360_DEVICE_ID_JOYPAD_UP]; + ssnes_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_DOWN] = ssnes_platform_keybind_lut[XDK360_DEVICE_ID_JOYPAD_DOWN]; + ssnes_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_LEFT] = ssnes_platform_keybind_lut[XDK360_DEVICE_ID_JOYPAD_LEFT]; + ssnes_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_RIGHT] = ssnes_platform_keybind_lut[XDK360_DEVICE_ID_JOYPAD_RIGHT]; + ssnes_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_A] = ssnes_platform_keybind_lut[XDK360_DEVICE_ID_JOYPAD_B]; + ssnes_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_X] = ssnes_platform_keybind_lut[XDK360_DEVICE_ID_JOYPAD_Y]; + ssnes_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_L] = ssnes_platform_keybind_lut[XDK360_DEVICE_ID_JOYPAD_LB]; + ssnes_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_R] = ssnes_platform_keybind_lut[XDK360_DEVICE_ID_JOYPAD_RB]; - for(uint32_t x = 0; x < MAX_PLAYERS; x++) - { - for(uint32_t y = 0; y < SSNES_FIRST_META_KEY; y++) - { - g_settings.input.binds[x][y].id = y; - g_settings.input.binds[x][y].joykey = ssnes_default_keybind_lut[y]; - } - g_settings.input.dpad_emulation[x] = DPAD_EMULATION_LSTICK; - } + for(uint32_t x = 0; x < MAX_PLAYERS; x++) + { + for(uint32_t y = 0; y < SSNES_FIRST_META_KEY; y++) + { + g_settings.input.binds[x][y].id = y; + g_settings.input.binds[x][y].joykey = ssnes_default_keybind_lut[y]; + } + g_settings.input.dpad_emulation[x] = DPAD_EMULATION_LSTICK; + } - //g_console - g_console.block_config_read = true; - g_console.gamma_correction_enable = false; - g_console.initialize_ssnes_enable = false; - g_console.emulator_initialized = 0; - g_console.mode_switch = MODE_MENU; - g_console.screen_orientation = ORIENTATION_NORMAL; - g_console.throttle_enable = true; - g_console.aspect_ratio_index = 0; - strlcpy(g_console.aspect_ratio_name, "4:3", sizeof(g_console.aspect_ratio_name)); - strlcpy(g_console.default_rom_startup_dir, "game:", sizeof(g_console.default_rom_startup_dir)); - g_console.custom_viewport_width = 0; - g_console.custom_viewport_height = 0; - g_console.custom_viewport_x = 0; - g_console.custom_viewport_y = 0; + //g_console + g_console.block_config_read = true; + g_console.gamma_correction_enable = false; + g_console.initialize_ssnes_enable = false; + g_console.emulator_initialized = 0; + g_console.mode_switch = MODE_MENU; + g_console.screen_orientation = ORIENTATION_NORMAL; + g_console.throttle_enable = true; + g_console.aspect_ratio_index = 0; + strlcpy(g_console.aspect_ratio_name, "4:3", sizeof(g_console.aspect_ratio_name)); + strlcpy(g_console.default_rom_startup_dir, "game:", sizeof(g_console.default_rom_startup_dir)); + g_console.custom_viewport_width = 0; + g_console.custom_viewport_height = 0; + g_console.custom_viewport_x = 0; + g_console.custom_viewport_y = 0; - //g_extern - g_extern.state_slot = 0; - g_extern.audio_data.mute = 0; - g_extern.verbose = true; + //g_extern + g_extern.state_slot = 0; + g_extern.audio_data.mute = 0; + g_extern.verbose = true; } static char **dir_list_new_360(const char *dir, const char *ext) { - size_t cur_ptr = 0; - size_t cur_size = 32; - char **dir_list = NULL; + size_t cur_ptr = 0; + size_t cur_size = 32; + char **dir_list = NULL; - WIN32_FIND_DATA ffd; - HANDLE hFind = INVALID_HANDLE_VALUE; + WIN32_FIND_DATA ffd; + HANDLE hFind = INVALID_HANDLE_VALUE; - char path_buf[PATH_MAX]; + char path_buf[PATH_MAX]; - if (strlcpy(path_buf, dir, sizeof(path_buf)) >= sizeof(path_buf)) - goto error; - if (strlcat(path_buf, "*", sizeof(path_buf)) >= sizeof(path_buf)) - goto error; + if (strlcpy(path_buf, dir, sizeof(path_buf)) >= sizeof(path_buf)) + goto error; + if (strlcat(path_buf, "*", sizeof(path_buf)) >= sizeof(path_buf)) + goto error; - if (ext) - { - if (strlcat(path_buf, ext, sizeof(path_buf)) >= sizeof(path_buf)) - goto error; - } + if (ext) + { + if (strlcat(path_buf, ext, sizeof(path_buf)) >= sizeof(path_buf)) + goto error; + } - hFind = FindFirstFile(path_buf, &ffd); - if (hFind == INVALID_HANDLE_VALUE) - goto error; + hFind = FindFirstFile(path_buf, &ffd); + if (hFind == INVALID_HANDLE_VALUE) + goto error; - dir_list = (char**)calloc(cur_size, sizeof(char*)); - if (!dir_list) - goto error; + dir_list = (char**)calloc(cur_size, sizeof(char*)); + if (!dir_list) + goto error; - do - { - // Not a perfect search of course, but hopefully good enough in practice. - if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) - continue; - if (ext && !strstr(ffd.cFileName, ext)) - continue; + do + { + // Not a perfect search of course, but hopefully good enough in practice. + if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) + continue; + if (ext && !strstr(ffd.cFileName, ext)) + continue; - dir_list[cur_ptr] = (char*)malloc(PATH_MAX); - if (!dir_list[cur_ptr]) - goto error; + dir_list[cur_ptr] = (char*)malloc(PATH_MAX); + if (!dir_list[cur_ptr]) + goto error; - strlcpy(dir_list[cur_ptr], dir, PATH_MAX); - strlcat(dir_list[cur_ptr], ffd.cFileName, PATH_MAX); + strlcpy(dir_list[cur_ptr], dir, PATH_MAX); + strlcat(dir_list[cur_ptr], ffd.cFileName, PATH_MAX); - cur_ptr++; - if (cur_ptr + 1 == cur_size) // Need to reserve for NULL. - { - cur_size *= 2; - dir_list = (char**)realloc(dir_list, cur_size * sizeof(char*)); - if (!dir_list) - goto error; + cur_ptr++; + if (cur_ptr + 1 == cur_size) // Need to reserve for NULL. + { + cur_size *= 2; + dir_list = (char**)realloc(dir_list, cur_size * sizeof(char*)); + if (!dir_list) + goto error; - // Make sure it's all NULL'd out since we cannot rely on realloc to do this. - memset(dir_list + cur_ptr, 0, (cur_size - cur_ptr) * sizeof(char*)); - } - }while (FindNextFile(hFind, &ffd) != 0); + // Make sure it's all NULL'd out since we cannot rely on realloc to do this. + memset(dir_list + cur_ptr, 0, (cur_size - cur_ptr) * sizeof(char*)); + } + }while (FindNextFile(hFind, &ffd) != 0); - FindClose(hFind); - return dir_list; + FindClose(hFind); + return dir_list; - error: - SSNES_ERR("Failed to open directory: \"%s\"\n", dir); - if (hFind != INVALID_HANDLE_VALUE) - FindClose(hFind); - dir_list_free(dir_list); - return NULL; +error: + SSNES_ERR("Failed to open directory: \"%s\"\n", dir); + + if (hFind != INVALID_HANDLE_VALUE) + FindClose(hFind); + + dir_list_free(dir_list); + return NULL; } static void init_settings (bool load_libretro_path) { - char fname_tmp[MAX_PATH_LENGTH]; + char fname_tmp[MAX_PATH_LENGTH]; - if(!path_file_exists(SYS_CONFIG_FILE)) - { - SSNES_ERR("Config file \"%s\" desn't exist. Creating...\n", "game:\\ssnes.cfg"); - FILE * f; - f = fopen(SYS_CONFIG_FILE, "w"); - fclose(f); - } + if(!path_file_exists(SYS_CONFIG_FILE)) + { + FILE * f; + SSNES_ERR("Config file \"%s\" desn't exist. Creating...\n", "game:\\ssnes.cfg"); + f = fopen(SYS_CONFIG_FILE, "w"); + fclose(f); + } - config_file_t * conf = config_file_new(SYS_CONFIG_FILE); + config_file_t * conf = config_file_new(SYS_CONFIG_FILE); - if(load_libretro_path) - { - CONFIG_GET_STRING(libretro, "libretro_path"); + if(load_libretro_path) + { + CONFIG_GET_STRING(libretro, "libretro_path"); - if(!strcmp(g_settings.libretro, "")) - { - //We need to set libretro to the first entry in the cores - //directory so that it will be saved to the config file - char ** dir_list = dir_list_new_360("game:\\", ".xex"); - if (!dir_list) - { - SSNES_ERR("Couldn't read directory.\n"); - return; - } + if(!strcmp(g_settings.libretro, "")) + { + //We need to set libretro to the first entry in the cores + //directory so that it will be saved to the config file + char ** dir_list = dir_list_new_360("game:\\", ".xex"); - const char * first_xex = dir_list[0]; + if (!dir_list) + { + SSNES_ERR("Couldn't read directory.\n"); + return; + } - if(first_xex) - { - fill_pathname_base(fname_tmp, first_xex, sizeof(fname_tmp)); + const char * first_xex = dir_list[0]; - if(strcmp(fname_tmp, "SSNES-Salamander.xex") == 0) - { - SSNES_WARN("First entry is SSNES Salamander itself, increment entry by one and check if it exists.\n"); - first_xex = dir_list[1]; - fill_pathname_base(fname_tmp, first_xex, sizeof(fname_tmp)); - - if(!first_xex) - { - //This is very unlikely to happen - SSNES_WARN("There is no second entry - no choice but to set it to SSNES Salamander\n"); - first_xex = dir_list[0]; - fill_pathname_base(fname_tmp, first_xex, sizeof(fname_tmp)); - } - } - SSNES_LOG("Set first .xex entry in dir: [%s] to libretro path.\n", fname_tmp); - snprintf(g_settings.libretro, sizeof(g_settings.libretro), "game:\\%s", fname_tmp); - } - else - { - SSNES_ERR("Failed to set first .xex entry to libretro path.\n"); - } + if(first_xex) + { + fill_pathname_base(fname_tmp, first_xex, sizeof(fname_tmp)); - dir_list_free(dir_list); - } - } + if(strcmp(fname_tmp, "SSNES-Salamander.xex") == 0) + { + SSNES_WARN("First entry is SSNES Salamander itself, increment entry by one and check if it exists.\n"); + first_xex = dir_list[1]; + fill_pathname_base(fname_tmp, first_xex, sizeof(fname_tmp)); - // g_settings - CONFIG_GET_BOOL(rewind_enable, "rewind_enable"); - CONFIG_GET_BOOL(video.smooth, "video_smooth"); - CONFIG_GET_BOOL(video.vsync, "video_vsync"); - CONFIG_GET_FLOAT(video.aspect_ratio, "video_aspect_ratio"); + if(!first_xex) + { + //This is very unlikely to happen + SSNES_WARN("There is no second entry - no choice but to set it to SSNES Salamander\n"); + first_xex = dir_list[0]; + fill_pathname_base(fname_tmp, first_xex, sizeof(fname_tmp)); + } + } + SSNES_LOG("Set first .xex entry in dir: [%s] to libretro path.\n", fname_tmp); + snprintf(g_settings.libretro, sizeof(g_settings.libretro), "game:\\%s", fname_tmp); + } + else + { + SSNES_ERR("Failed to set first .xex entry to libretro path.\n"); + } - // g_console - CONFIG_GET_BOOL_CONSOLE(throttle_enable, "throttle_enable"); - CONFIG_GET_BOOL_CONSOLE(gamma_correction_enable, "gamma_correction_enable"); - CONFIG_GET_STRING_CONSOLE(default_rom_startup_dir, "default_rom_startup_dir"); - CONFIG_GET_INT_CONSOLE(aspect_ratio_index, "aspect_ratio_index"); - CONFIG_GET_INT_CONSOLE(screen_orientation, "screen_orientation"); - CONFIG_GET_STRING_CONSOLE(aspect_ratio_name, "aspect_ratio_name"); + dir_list_free(dir_list); + } + } - // g_extern - CONFIG_GET_INT_EXTERN(state_slot, "state_slot"); - CONFIG_GET_INT_EXTERN(audio_data.mute, "audio_mute"); + // g_settings + CONFIG_GET_BOOL(rewind_enable, "rewind_enable"); + CONFIG_GET_BOOL(video.smooth, "video_smooth"); + CONFIG_GET_BOOL(video.vsync, "video_vsync"); + CONFIG_GET_FLOAT(video.aspect_ratio, "video_aspect_ratio"); + + // g_console + CONFIG_GET_BOOL_CONSOLE(throttle_enable, "throttle_enable"); + CONFIG_GET_BOOL_CONSOLE(gamma_correction_enable, "gamma_correction_enable"); + CONFIG_GET_STRING_CONSOLE(default_rom_startup_dir, "default_rom_startup_dir"); + CONFIG_GET_INT_CONSOLE(aspect_ratio_index, "aspect_ratio_index"); + CONFIG_GET_INT_CONSOLE(screen_orientation, "screen_orientation"); + CONFIG_GET_STRING_CONSOLE(aspect_ratio_name, "aspect_ratio_name"); + + // g_extern + CONFIG_GET_INT_EXTERN(state_slot, "state_slot"); + CONFIG_GET_INT_EXTERN(audio_data.mute, "audio_mute"); } static void save_settings (void) { - if(!path_file_exists(SYS_CONFIG_FILE)) - { - FILE * f; - f = fopen(SYS_CONFIG_FILE, "w"); - fclose(f); - } + if(!path_file_exists(SYS_CONFIG_FILE)) + { + FILE * f; + f = fopen(SYS_CONFIG_FILE, "w"); + fclose(f); + } - config_file_t * conf = config_file_new(SYS_CONFIG_FILE); + config_file_t * conf = config_file_new(SYS_CONFIG_FILE); - if(conf == NULL) - conf = config_file_new(NULL); + if(conf == NULL) + conf = config_file_new(NULL); - // g_settings - config_set_string(conf, "libretro_path", g_settings.libretro); - config_set_bool(conf, "rewind_enable", g_settings.rewind_enable); - config_set_bool(conf, "video_smooth", g_settings.video.smooth); - config_set_bool(conf, "video_vsync", g_settings.video.vsync); + // g_settings + config_set_string(conf, "libretro_path", g_settings.libretro); + config_set_bool(conf, "rewind_enable", g_settings.rewind_enable); + config_set_bool(conf, "video_smooth", g_settings.video.smooth); + config_set_bool(conf, "video_vsync", g_settings.video.vsync); - // g_console - config_set_string(conf, "default_rom_startup_dir", g_console.default_rom_startup_dir); - config_set_bool(conf, "gamma_correction_enable", g_console.gamma_correction_enable); - config_set_bool(conf, "throttle_enable", g_console.throttle_enable); - config_set_int(conf, "aspect_ratio_index", g_console.aspect_ratio_index); - config_set_int(conf, "custom_viewport_width", g_console.custom_viewport_width); - config_set_int(conf, "custom_viewport_height", g_console.custom_viewport_height); - config_set_int(conf, "custom_viewport_x", g_console.custom_viewport_x); - config_set_int(conf, "custom_viewport_y", g_console.custom_viewport_y); - config_set_int(conf, "screen_orientation", g_console.screen_orientation); - config_set_string(conf, "aspect_ratio_name", g_console.aspect_ratio_name); + // g_console + config_set_string(conf, "default_rom_startup_dir", g_console.default_rom_startup_dir); + config_set_bool(conf, "gamma_correction_enable", g_console.gamma_correction_enable); + config_set_bool(conf, "throttle_enable", g_console.throttle_enable); + config_set_int(conf, "aspect_ratio_index", g_console.aspect_ratio_index); + config_set_int(conf, "custom_viewport_width", g_console.custom_viewport_width); + config_set_int(conf, "custom_viewport_height", g_console.custom_viewport_height); + config_set_int(conf, "custom_viewport_x", g_console.custom_viewport_x); + config_set_int(conf, "custom_viewport_y", g_console.custom_viewport_y); + config_set_int(conf, "screen_orientation", g_console.screen_orientation); + config_set_string(conf, "aspect_ratio_name", g_console.aspect_ratio_name); - // g_extern - config_set_int(conf, "state_slot", g_extern.state_slot); - config_set_int(conf, "audio_mute", g_extern.audio_data.mute); + // g_extern + config_set_int(conf, "state_slot", g_extern.state_slot); + config_set_int(conf, "audio_mute", g_extern.audio_data.mute); - if (!config_file_write(conf, SYS_CONFIG_FILE)) - SSNES_ERR("Failed to write config file to \"%s\". Check permissions.\n", SYS_CONFIG_FILE); + if (!config_file_write(conf, SYS_CONFIG_FILE)) + SSNES_ERR("Failed to write config file to \"%s\". Check permissions.\n", SYS_CONFIG_FILE); - free(conf); + free(conf); } static void get_environment_settings (void) { - DWORD ret; + DWORD ret; - //for devkits only, we will need to mount all partitions for retail - //in a different way - //DmMapDevkitDrive(); - - memset(&Mounted, 0, 20); + //for devkits only, we will need to mount all partitions for retail + //in a different way + //DmMapDevkitDrive(); - Mounted[DEVICE_USB0] = Mount(DEVICE_USB0,"Usb0:"); - Mounted[DEVICE_USB1] = Mount(DEVICE_USB1,"Usb1:"); - Mounted[DEVICE_USB2] = Mount(DEVICE_USB2,"Usb2:"); - Mounted[DEVICE_HARDISK0_PART1] = Mount(DEVICE_HARDISK0_PART1,"Hdd1:"); - Mounted[DEVICE_HARDISK0_SYSPART] = Mount(DEVICE_HARDISK0_SYSPART,"HddX:"); - Mounted[DEVICE_MEMORY_UNIT0] = Mount(DEVICE_MEMORY_UNIT0,"Memunit0:"); - Mounted[DEVICE_MEMORY_UNIT1] = Mount(DEVICE_MEMORY_UNIT1,"Memunit1:"); - Mounted[DEVICE_MEMORY_ONBOARD] = Mount(DEVICE_MEMORY_ONBOARD,"OnBoardMU:"); - Mounted[DEVICE_CDROM0] = Mount(DEVICE_CDROM0,"Dvd:"); + memset(&Mounted, 0, 20); - ret = XSetFileCacheSize(0x100000); + Mounted[DEVICE_USB0] = Mount(DEVICE_USB0,"Usb0:"); + Mounted[DEVICE_USB1] = Mount(DEVICE_USB1,"Usb1:"); + Mounted[DEVICE_USB2] = Mount(DEVICE_USB2,"Usb2:"); + Mounted[DEVICE_HARDISK0_PART1] = Mount(DEVICE_HARDISK0_PART1,"Hdd1:"); + Mounted[DEVICE_HARDISK0_SYSPART] = Mount(DEVICE_HARDISK0_SYSPART,"HddX:"); + Mounted[DEVICE_MEMORY_UNIT0] = Mount(DEVICE_MEMORY_UNIT0,"Memunit0:"); + Mounted[DEVICE_MEMORY_UNIT1] = Mount(DEVICE_MEMORY_UNIT1,"Memunit1:"); + Mounted[DEVICE_MEMORY_ONBOARD] = Mount(DEVICE_MEMORY_ONBOARD,"OnBoardMU:"); + Mounted[DEVICE_CDROM0] = Mount(DEVICE_CDROM0,"Dvd:"); - if(ret != TRUE) - { - SSNES_ERR("Couldn't change number of bytes reserved for file system cache.\n"); - } + ret = XSetFileCacheSize(0x100000); - ret = XFileCacheInit(XFILECACHE_CLEAR_ALL, 0x100000, XFILECACHE_DEFAULT_THREAD, 0, 1); + if(ret != TRUE) + { + SSNES_ERR("Couldn't change number of bytes reserved for file system cache.\n"); + } - if(ret != ERROR_SUCCESS) - { - SSNES_ERR("File cache could not be initialized.\n"); - } + ret = XFileCacheInit(XFILECACHE_CLEAR_ALL, 0x100000, XFILECACHE_DEFAULT_THREAD, 0, 1); - XFlushUtilityDrive(); - //unsigned long result = XMountUtilityDriveEx(XMOUNTUTILITYDRIVE_FORMAT0,8192, 0); + if(ret != ERROR_SUCCESS) + { + SSNES_ERR("File cache could not be initialized.\n"); + } - //if(result != ERROR_SUCCESS) - //{ - // SSNES_ERR("Couldn't mount/format utility drive.\n"); - //} + XFlushUtilityDrive(); + //unsigned long result = XMountUtilityDriveEx(XMOUNTUTILITYDRIVE_FORMAT0,8192, 0); - // detect install environment - unsigned long license_mask; + //if(result != ERROR_SUCCESS) + //{ + // SSNES_ERR("Couldn't mount/format utility drive.\n"); + //} - if (XContentGetLicenseMask(&license_mask, NULL) != ERROR_SUCCESS) - { - printf("SSNES was launched as a standalone DVD, or using DVD emulation, or from the development area of the HDD.\n"); - } - else - { - XContentQueryVolumeDeviceType("GAME",&g_console.volume_device_type, NULL); + // detect install environment + unsigned long license_mask; - switch(g_console.volume_device_type) - { - case XCONTENTDEVICETYPE_HDD: - printf("SSNES was launched from a content package on HDD.\n"); - break; - case XCONTENTDEVICETYPE_MU: - printf("SSNES was launched from a content package on USB or Memory Unit.\n"); - break; - case XCONTENTDEVICETYPE_ODD: - printf("SSNES was launched from a content package on Optical Disc Drive.\n"); - break; - default: - printf("SSNES was launched from a content package on an unknown device type.\n"); - break; + if (XContentGetLicenseMask(&license_mask, NULL) != ERROR_SUCCESS) + { + printf("SSNES was launched as a standalone DVD, or using DVD emulation, or from the development area of the HDD.\n"); + } + else + { + XContentQueryVolumeDeviceType("GAME",&g_console.volume_device_type, NULL); - } - } - - strlcpy(DEFAULT_SHADER_FILE, "game:\\media\\shaders\\stock.cg", sizeof(DEFAULT_SHADER_FILE)); - strlcpy(SYS_CONFIG_FILE, "game:\\ssnes.cfg", sizeof(SYS_CONFIG_FILE)); + switch(g_console.volume_device_type) + { + case XCONTENTDEVICETYPE_HDD: + printf("SSNES was launched from a content package on HDD.\n"); + break; + case XCONTENTDEVICETYPE_MU: + printf("SSNES was launched from a content package on USB or Memory Unit.\n"); + break; + case XCONTENTDEVICETYPE_ODD: + printf("SSNES was launched from a content package on Optical Disc Drive.\n"); + break; + default: + printf("SSNES was launched from a content package on an unknown device type.\n"); + break; + } + } + + strlcpy(DEFAULT_SHADER_FILE, "game:\\media\\shaders\\stock.cg", sizeof(DEFAULT_SHADER_FILE)); + strlcpy(SYS_CONFIG_FILE, "game:\\ssnes.cfg", sizeof(SYS_CONFIG_FILE)); } static bool manage_libretro_core(void) { - g_extern.verbose = true; - bool return_code; + g_extern.verbose = true; + bool return_code; - bool set_libretro_path = false; - char tmp_path[1024], tmp_path2[1024], tmp_pathnewfile[1024]; - snprintf(tmp_path, sizeof(tmp_path), "game:\\CORE.xex"); - SSNES_LOG("Assumed path of CORE.xex: [%s]\n", tmp_path); - if(path_file_exists(tmp_path)) - { - //if CORE.xex exists, this indicates we have just installed - //a new libretro port and that we need to change it to a more - //sane name. + bool set_libretro_path = false; + char tmp_path[1024], tmp_path2[1024], tmp_pathnewfile[1024]; + snprintf(tmp_path, sizeof(tmp_path), "game:\\CORE.xex"); + SSNES_LOG("Assumed path of CORE.xex: [%s]\n", tmp_path); - int ret; + if(path_file_exists(tmp_path)) + { + //if CORE.xex exists, this indicates we have just installed + //a new libretro port and that we need to change it to a more + //sane name. - ssnes_console_name_from_id(tmp_path2, sizeof(tmp_path2)); - strlcat(tmp_path2, ".xex", sizeof(tmp_path2)); - snprintf(tmp_pathnewfile, sizeof(tmp_pathnewfile), "game:\\%s", tmp_path2); + int ret; - if(path_file_exists(tmp_pathnewfile)) - { - SSNES_LOG("Upgrading emulator core...\n"); - //if libretro core already exists, then that means we are - //upgrading the libretro core - so delete pre-existing - //file first - ret = DeleteFile(tmp_pathnewfile); - if(ret != 0) - { - SSNES_LOG("Succeeded in removing pre-existing libretro core: [%s].\n", tmp_pathnewfile); - } - else - { - SSNES_LOG("Failed to remove pre-existing libretro core: [%s].\n", tmp_pathnewfile); - } - } + ssnes_console_name_from_id(tmp_path2, sizeof(tmp_path2)); + strlcat(tmp_path2, ".xex", sizeof(tmp_path2)); + snprintf(tmp_pathnewfile, sizeof(tmp_pathnewfile), "game:\\%s", tmp_path2); - //now attempt the renaming - ret = MoveFileExA(tmp_path, tmp_pathnewfile, NULL); - if(ret == 0) - { - SSNES_ERR("Failed to rename CORE.xex.\n"); - } - else - { - SSNES_LOG("libretro core [%s] renamed to: [%s].\n", tmp_path, tmp_pathnewfile); - set_libretro_path = true; - } - } - else - { - SSNES_LOG("CORE.xex was not found, libretro core path will be loaded from config file.\n"); - } + if(path_file_exists(tmp_pathnewfile)) + { + SSNES_LOG("Upgrading emulator core...\n"); - if(set_libretro_path) - { - //CORE.xex has been renamed, libretro path will now be set to the recently - //renamed new libretro core - strlcpy(g_settings.libretro, tmp_pathnewfile, sizeof(g_settings.libretro)); - return_code = 0; - } - else - { - //There was no CORE.xex present, or the CORE.xex file was not renamed. - //The libretro core path will still be loaded from the config file - return_code = 1; - } + //if libretro core already exists, then that means we are + //upgrading the libretro core - so delete pre-existing + //file first + + ret = DeleteFile(tmp_pathnewfile); + if(ret != 0) + { + SSNES_LOG("Succeeded in removing pre-existing libretro core: [%s].\n", tmp_pathnewfile); + } + else + { + SSNES_LOG("Failed to remove pre-existing libretro core: [%s].\n", tmp_pathnewfile); + } + } - g_extern.verbose = false; + //now attempt the renaming + ret = MoveFileExA(tmp_path, tmp_pathnewfile, NULL); + if(ret == 0) + { + SSNES_ERR("Failed to rename CORE.xex.\n"); + } + else + { + SSNES_LOG("libretro core [%s] renamed to: [%s].\n", tmp_path, tmp_pathnewfile); + set_libretro_path = true; + } + } + else + { + SSNES_LOG("CORE.xex was not found, libretro core path will be loaded from config file.\n"); + } - return return_code; + if(set_libretro_path) + { + //CORE.xex has been renamed, libretro path will now be set to the recently + //renamed new libretro core + strlcpy(g_settings.libretro, tmp_pathnewfile, sizeof(g_settings.libretro)); + return_code = 0; + } + else + { + //There was no CORE.xex present, or the CORE.xex file was not renamed. + //The libretro core path will still be loaded from the config file + return_code = 1; + } + + g_extern.verbose = false; + + return return_code; } int main(int argc, char *argv[]) { - get_environment_settings(); + get_environment_settings(); - ssnes_main_clear_state(); - config_set_defaults(); - - bool load_libretro_path = manage_libretro_core(); + ssnes_main_clear_state(); + config_set_defaults(); - set_default_settings(); - init_settings(load_libretro_path); - init_libretro_sym(); + bool load_libretro_path = manage_libretro_core(); - xdk360_video_init(); - xdk360_input_init(); + set_default_settings(); + init_settings(load_libretro_path); + init_libretro_sym(); - ssnes_input_set_default_keybind_names_for_emulator(); + xdk360_video_init(); + xdk360_input_init(); - menu_init(); + ssnes_input_set_default_keybind_names_for_emulator(); + + menu_init(); begin_loop: - if(g_console.mode_switch == MODE_EMULATION) - { - bool repeat = false; + if(g_console.mode_switch == MODE_EMULATION) + { + bool repeat = false; - input_xdk360.poll(NULL); + input_xdk360.poll(NULL); - do{ - repeat = ssnes_main_iterate(); - }while(repeat && !g_console.frame_advance_enable); - } - else if(g_console.mode_switch == MODE_MENU) - { - menu_loop(); + do{ + repeat = ssnes_main_iterate(); + }while(repeat && !g_console.frame_advance_enable); + } + else if(g_console.mode_switch == MODE_MENU) + { + menu_loop(); - if(g_console.initialize_ssnes_enable) - { - if(g_console.emulator_initialized) - ssnes_main_deinit(); + if(g_console.initialize_ssnes_enable) + { + if(g_console.emulator_initialized) + ssnes_main_deinit(); - struct ssnes_main_wrap args = {0}; + struct ssnes_main_wrap args = {0}; - args.verbose = g_extern.verbose; - args.config_path = SYS_CONFIG_FILE; - args.rom_path = g_console.rom_path; - - int init_ret = ssnes_main_init_wrap(&args); - g_console.emulator_initialized = 1; - g_console.initialize_ssnes_enable = 0; - } - } - else - goto begin_shutdown; + args.verbose = g_extern.verbose; + args.config_path = SYS_CONFIG_FILE; + args.rom_path = g_console.rom_path; - goto begin_loop; + int init_ret = ssnes_main_init_wrap(&args); + g_console.emulator_initialized = 1; + g_console.initialize_ssnes_enable = 0; + } + } + else + goto begin_shutdown; + + goto begin_loop; begin_shutdown: - if(path_file_exists(SYS_CONFIG_FILE)) - save_settings(); - xdk360_video_deinit(); + if(path_file_exists(SYS_CONFIG_FILE)) + save_settings(); - if(g_console.return_to_launcher) - { - SSNES_LOG("Attempt to load XEX: [%s].\n", g_console.launch_app_on_exit); - XLaunchNewImage(g_console.launch_app_on_exit, NULL); - } - return 0; + xdk360_video_deinit(); + + if(g_console.return_to_launcher) + { + SSNES_LOG("Attempt to load XEX: [%s].\n", g_console.launch_app_on_exit); + XLaunchNewImage(g_console.launch_app_on_exit, NULL); + } + return 0; } diff --git a/360/menu.cpp b/360/menu.cpp index 6a75c162df..77526b289a 100644 --- a/360/menu.cpp +++ b/360/menu.cpp @@ -33,533 +33,539 @@ char strbuffer[1024]; static void return_to_game (void) { - g_console.frame_advance_enable = false; - g_console.menu_enable = false; - g_console.mode_switch = MODE_EMULATION; + g_console.frame_advance_enable = false; + g_console.menu_enable = false; + g_console.mode_switch = MODE_EMULATION; } static void return_to_dashboard (void) { - g_console.menu_enable = false; - g_console.mode_switch = MODE_EXIT; - g_console.initialize_ssnes_enable = false; + g_console.menu_enable = false; + g_console.mode_switch = MODE_EXIT; + g_console.initialize_ssnes_enable = false; } /* Register custom classes */ HRESULT CSSNES::RegisterXuiClasses (void) { - CSSNESMain::Register(); - CSSNESFileBrowser::Register(); - CSSNESCoreBrowser::Register(); - CSSNESQuickMenu::Register(); - CSSNESSettings::Register(); - return S_OK; + CSSNESMain::Register(); + CSSNESFileBrowser::Register(); + CSSNESCoreBrowser::Register(); + CSSNESQuickMenu::Register(); + CSSNESSettings::Register(); + + return S_OK; } /* Unregister custom classes */ HRESULT CSSNES::UnregisterXuiClasses (void) { - CSSNESMain::Unregister(); - CSSNESCoreBrowser::Unregister(); - CSSNESFileBrowser::Unregister(); - CSSNESQuickMenu::Register(); - CSSNESSettings::Unregister(); - return S_OK; + CSSNESMain::Unregister(); + CSSNESCoreBrowser::Unregister(); + CSSNESFileBrowser::Unregister(); + CSSNESQuickMenu::Register(); + CSSNESSettings::Unregister(); + + return S_OK; } static void filebrowser_fetch_directory_entries(const char *path, filebrowser_t * browser, CXuiList * romlist, CXuiTextElement * rompath_title) { - filebrowser_push_directory(browser, path, true); + filebrowser_push_directory(browser, path, true); - unsigned long dwNum_rompath = MultiByteToWideChar(CP_ACP, 0, path, -1, NULL, 0); - wchar_t * rompath_name = new wchar_t[dwNum_rompath]; - MultiByteToWideChar(CP_ACP, 0, path, -1, rompath_name, dwNum_rompath); - rompath_title->SetText(rompath_name); + unsigned long dwNum_rompath = MultiByteToWideChar(CP_ACP, 0, path, -1, NULL, 0); + wchar_t * rompath_name = new wchar_t[dwNum_rompath]; + MultiByteToWideChar(CP_ACP, 0, path, -1, rompath_name, dwNum_rompath); + rompath_title->SetText(rompath_name); - romlist->DeleteItems(0, romlist->GetItemCount()); - romlist->InsertItems(0, browser->file_count); - for(unsigned i = 0; i < browser->file_count; i++) - { - unsigned long dwNum = MultiByteToWideChar(CP_ACP, 0, browser->cur[i].d_name, -1, NULL, 0); - wchar_t * entry_name = new wchar_t[dwNum]; - MultiByteToWideChar(CP_ACP, 0, browser->cur[i].d_name, -1, entry_name, dwNum); - romlist->SetText(i, entry_name); - delete []entry_name; - } + romlist->DeleteItems(0, romlist->GetItemCount()); + romlist->InsertItems(0, browser->file_count); + for(unsigned i = 0; i < browser->file_count; i++) + { + unsigned long dwNum = MultiByteToWideChar(CP_ACP, 0, browser->cur[i].d_name, -1, NULL, 0); + wchar_t * entry_name = new wchar_t[dwNum]; + MultiByteToWideChar(CP_ACP, 0, browser->cur[i].d_name, -1, entry_name, dwNum); + romlist->SetText(i, entry_name); + delete []entry_name; + } } HRESULT CSSNESFileBrowser::OnInit(XUIMessageInit * pInitData, BOOL& bHandled) { - GetChildById(L"XuiRomList", &m_romlist); - GetChildById(L"XuiBackButton1", &m_back); - GetChildById(L"XuiTxtRomPath", &m_rompathtitle); - GetChildById(L"XuiBtnGameDir", &m_dir_game); - GetChildById(L"XuiBtnCacheDir", &m_dir_cache); + GetChildById(L"XuiRomList", &m_romlist); + GetChildById(L"XuiBackButton1", &m_back); + GetChildById(L"XuiTxtRomPath", &m_rompathtitle); + GetChildById(L"XuiBtnGameDir", &m_dir_game); + GetChildById(L"XuiBtnCacheDir", &m_dir_cache); - filebrowser_fetch_directory_entries(g_console.default_rom_startup_dir, &browser, &m_romlist, &m_rompathtitle); + filebrowser_fetch_directory_entries(g_console.default_rom_startup_dir, &browser, &m_romlist, &m_rompathtitle); - return S_OK; + return S_OK; } HRESULT CSSNESCoreBrowser::OnInit(XUIMessageInit * pInitData, BOOL& bHandled) { - GetChildById(L"XuiRomList", &m_romlist); - GetChildById(L"XuiBackButton1", &m_back); - GetChildById(L"XuiTxtRomPath", &m_rompathtitle); - - filebrowser_new(&tmp_browser, "game:", "xex|XEX"); - filebrowser_fetch_directory_entries("game:", &tmp_browser, &m_romlist, &m_rompathtitle); + GetChildById(L"XuiRomList", &m_romlist); + GetChildById(L"XuiBackButton1", &m_back); + GetChildById(L"XuiTxtRomPath", &m_rompathtitle); - return S_OK; + filebrowser_new(&tmp_browser, "game:", "xex|XEX"); + filebrowser_fetch_directory_entries("game:", &tmp_browser, &m_romlist, &m_rompathtitle); + + return S_OK; } static const wchar_t * set_filter_element(int index) { - switch(index) - { - case FALSE: - return L"Hardware filtering: Point filtering"; - case TRUE: - return L"Hardware filtering: Linear interpolation"; - } + switch(index) + { + case FALSE: + return L"Hardware filtering: Point filtering"; + case TRUE: + return L"Hardware filtering: Linear interpolation"; + } - return L""; + return L""; } HRESULT CSSNESSettings::OnInit(XUIMessageInit * pInitData, BOOL& bHandled) { - GetChildById(L"XuiSettingsList", &m_settingslist); - GetChildById(L"XuiBackButton", &m_back); + GetChildById(L"XuiSettingsList", &m_settingslist); + GetChildById(L"XuiBackButton", &m_back); - m_settingslist.SetText(SETTING_EMU_REWIND_ENABLED, g_settings.rewind_enable ? L"Rewind: ON" : L"Rewind: OFF"); - m_settingslist.SetText(SETTING_GAMMA_CORRECTION_ENABLED, g_console.gamma_correction_enable ? L"Gamma correction: ON" : L"Gamma correction: OFF"); - m_settingslist.SetText(SETTING_HARDWARE_FILTERING, set_filter_element(g_settings.video.smooth)); - return S_OK; + m_settingslist.SetText(SETTING_EMU_REWIND_ENABLED, g_settings.rewind_enable ? L"Rewind: ON" : L"Rewind: OFF"); + m_settingslist.SetText(SETTING_GAMMA_CORRECTION_ENABLED, g_console.gamma_correction_enable ? L"Gamma correction: ON" : L"Gamma correction: OFF"); + m_settingslist.SetText(SETTING_HARDWARE_FILTERING, set_filter_element(g_settings.video.smooth)); + + return S_OK; } HRESULT CSSNESQuickMenu::OnInit(XUIMessageInit * pInitData, BOOL& bHandled) { - GetChildById(L"XuiQuickMenuList", &m_quickmenulist); - GetChildById(L"XuiBackButton", &m_back); + GetChildById(L"XuiQuickMenuList", &m_quickmenulist); + GetChildById(L"XuiBackButton", &m_back); - m_quickmenulist.SetText(MENU_ITEM_HARDWARE_FILTERING, set_filter_element(g_settings.video.smooth)); - switch(g_console.screen_orientation) - { - case ORIENTATION_NORMAL: - m_quickmenulist.SetText(MENU_ITEM_ORIENTATION, L"Orientation: Normal"); - break; - case ORIENTATION_VERTICAL: - m_quickmenulist.SetText(MENU_ITEM_ORIENTATION, L"Orientation: Vertical"); - break; - case ORIENTATION_FLIPPED: - m_quickmenulist.SetText(MENU_ITEM_ORIENTATION, L"Orientation: Flipped"); - break; - case ORIENTATION_FLIPPED_ROTATED: - m_quickmenulist.SetText(MENU_ITEM_ORIENTATION, L"Orientation: Flipped Rotated"); - break; - } - char aspectratio_label[32]; - sprintf(aspectratio_label, "Aspect Ratio: %s", g_console.aspect_ratio_name); - unsigned long dwNum = MultiByteToWideChar(CP_ACP, 0, aspectratio_label, -1, NULL, 0); - wchar_t * aspectratio_label_w = new wchar_t[dwNum]; - MultiByteToWideChar(CP_ACP, 0, aspectratio_label, -1, aspectratio_label_w, dwNum); - m_quickmenulist.SetText(MENU_ITEM_KEEP_ASPECT_RATIO, aspectratio_label_w); - delete[] aspectratio_label_w; - return S_OK; + m_quickmenulist.SetText(MENU_ITEM_HARDWARE_FILTERING, set_filter_element(g_settings.video.smooth)); + switch(g_console.screen_orientation) + { + case ORIENTATION_NORMAL: + m_quickmenulist.SetText(MENU_ITEM_ORIENTATION, L"Orientation: Normal"); + break; + case ORIENTATION_VERTICAL: + m_quickmenulist.SetText(MENU_ITEM_ORIENTATION, L"Orientation: Vertical"); + break; + case ORIENTATION_FLIPPED: + m_quickmenulist.SetText(MENU_ITEM_ORIENTATION, L"Orientation: Flipped"); + break; + case ORIENTATION_FLIPPED_ROTATED: + m_quickmenulist.SetText(MENU_ITEM_ORIENTATION, L"Orientation: Flipped Rotated"); + break; + } + char aspectratio_label[32]; + sprintf(aspectratio_label, "Aspect Ratio: %s", g_console.aspect_ratio_name); + unsigned long dwNum = MultiByteToWideChar(CP_ACP, 0, aspectratio_label, -1, NULL, 0); + wchar_t * aspectratio_label_w = new wchar_t[dwNum]; + MultiByteToWideChar(CP_ACP, 0, aspectratio_label, -1, aspectratio_label_w, dwNum); + m_quickmenulist.SetText(MENU_ITEM_KEEP_ASPECT_RATIO, aspectratio_label_w); + delete[] aspectratio_label_w; + + return S_OK; } HRESULT CSSNESQuickMenu::OnNotifyPress( HXUIOBJ hObjPressed, int & bHandled ) { - int current_index; + int current_index; - if ( hObjPressed == m_quickmenulist) - { - current_index = m_quickmenulist.GetCurSel(); + if ( hObjPressed == m_quickmenulist) + { + current_index = m_quickmenulist.GetCurSel(); - switch(current_index) - { - case MENU_ITEM_LOAD_STATE: - if (g_console.emulator_initialized) - { - ssnes_load_state(); - return_to_game(); - } - break; - case MENU_ITEM_SAVE_STATE: - if (g_console.emulator_initialized) - { - ssnes_save_state(); - return_to_game(); - } - break; - case MENU_ITEM_HARDWARE_FILTERING: - g_settings.video.smooth = !g_settings.video.smooth; - m_quickmenulist.SetText(MENU_ITEM_HARDWARE_FILTERING, set_filter_element(g_settings.video.smooth)); - break; - case MENU_ITEM_KEEP_ASPECT_RATIO: - { - if(g_console.aspect_ratio_index < LAST_ASPECT_RATIO) - g_console.aspect_ratio_index++; - else - g_console.aspect_ratio_index = 0; + switch(current_index) + { + case MENU_ITEM_LOAD_STATE: + if (g_console.emulator_initialized) + { + ssnes_load_state(); + return_to_game(); + } + break; + case MENU_ITEM_SAVE_STATE: + if (g_console.emulator_initialized) + { + ssnes_save_state(); + return_to_game(); + } + break; + case MENU_ITEM_HARDWARE_FILTERING: + g_settings.video.smooth = !g_settings.video.smooth; + m_quickmenulist.SetText(MENU_ITEM_HARDWARE_FILTERING, set_filter_element(g_settings.video.smooth)); + break; + case MENU_ITEM_KEEP_ASPECT_RATIO: + { + if(g_console.aspect_ratio_index < LAST_ASPECT_RATIO) + g_console.aspect_ratio_index++; + else + g_console.aspect_ratio_index = 0; - video_xdk360.set_aspect_ratio(NULL, g_console.aspect_ratio_index); - char aspectratio_label[32]; - sprintf(aspectratio_label, "Aspect Ratio: %s", g_console.aspect_ratio_name); - unsigned long dwNum = MultiByteToWideChar(CP_ACP, 0, aspectratio_label, -1, NULL, 0); - wchar_t * aspectratio_label_w = new wchar_t[dwNum]; - MultiByteToWideChar(CP_ACP, 0, aspectratio_label, -1, aspectratio_label_w, dwNum); - m_quickmenulist.SetText(MENU_ITEM_KEEP_ASPECT_RATIO, aspectratio_label_w); - delete[] aspectratio_label_w; - } - break; - case MENU_ITEM_OVERSCAN_AMOUNT: - break; - case MENU_ITEM_ORIENTATION: - switch(g_console.screen_orientation) - { - case ORIENTATION_NORMAL: - g_console.screen_orientation = ORIENTATION_VERTICAL; - m_quickmenulist.SetText(MENU_ITEM_ORIENTATION, L"Orientation: Vertical"); - break; - case ORIENTATION_VERTICAL: - g_console.screen_orientation = ORIENTATION_FLIPPED; - m_quickmenulist.SetText(MENU_ITEM_ORIENTATION, L"Orientation: Flipped"); - break; - case ORIENTATION_FLIPPED: - g_console.screen_orientation = ORIENTATION_FLIPPED_ROTATED; - m_quickmenulist.SetText(MENU_ITEM_ORIENTATION, L"Orientation: Flipped Rotated"); - break; - case ORIENTATION_FLIPPED_ROTATED: - g_console.screen_orientation = ORIENTATION_NORMAL; - m_quickmenulist.SetText(MENU_ITEM_ORIENTATION, L"Orientation: Normal"); - break; - } - video_xdk360.set_rotation(NULL, g_console.screen_orientation); - break; - case MENU_ITEM_RESIZE_MODE: - break; - case MENU_ITEM_FRAME_ADVANCE: - if (g_console.emulator_initialized) - { - g_console.frame_advance_enable = true; - g_console.menu_enable = false; - g_console.mode_switch = MODE_EMULATION; - } - break; - case MENU_ITEM_SCREENSHOT_MODE: - break; - case MENU_ITEM_RESET: - if (g_console.emulator_initialized) - { - return_to_game(); - ssnes_game_reset(); - } - break; - case MENU_ITEM_RETURN_TO_GAME: - if (g_console.emulator_initialized) - return_to_game(); - break; - case MENU_ITEM_RETURN_TO_DASHBOARD: - return_to_dashboard(); - break; - } - } + video_xdk360.set_aspect_ratio(NULL, g_console.aspect_ratio_index); + char aspectratio_label[32]; + sprintf(aspectratio_label, "Aspect Ratio: %s", g_console.aspect_ratio_name); + unsigned long dwNum = MultiByteToWideChar(CP_ACP, 0, aspectratio_label, -1, NULL, 0); + wchar_t * aspectratio_label_w = new wchar_t[dwNum]; + MultiByteToWideChar(CP_ACP, 0, aspectratio_label, -1, aspectratio_label_w, dwNum); + m_quickmenulist.SetText(MENU_ITEM_KEEP_ASPECT_RATIO, aspectratio_label_w); + delete[] aspectratio_label_w; + } + break; + case MENU_ITEM_OVERSCAN_AMOUNT: + break; + case MENU_ITEM_ORIENTATION: + switch(g_console.screen_orientation) + { + case ORIENTATION_NORMAL: + g_console.screen_orientation = ORIENTATION_VERTICAL; + m_quickmenulist.SetText(MENU_ITEM_ORIENTATION, L"Orientation: Vertical"); + break; + case ORIENTATION_VERTICAL: + g_console.screen_orientation = ORIENTATION_FLIPPED; + m_quickmenulist.SetText(MENU_ITEM_ORIENTATION, L"Orientation: Flipped"); + break; + case ORIENTATION_FLIPPED: + g_console.screen_orientation = ORIENTATION_FLIPPED_ROTATED; + m_quickmenulist.SetText(MENU_ITEM_ORIENTATION, L"Orientation: Flipped Rotated"); + break; + case ORIENTATION_FLIPPED_ROTATED: + g_console.screen_orientation = ORIENTATION_NORMAL; + m_quickmenulist.SetText(MENU_ITEM_ORIENTATION, L"Orientation: Normal"); + break; + } + video_xdk360.set_rotation(NULL, g_console.screen_orientation); + break; + case MENU_ITEM_RESIZE_MODE: + break; + case MENU_ITEM_FRAME_ADVANCE: + if (g_console.emulator_initialized) + { + g_console.frame_advance_enable = true; + g_console.menu_enable = false; + g_console.mode_switch = MODE_EMULATION; + } + break; + case MENU_ITEM_SCREENSHOT_MODE: + break; + case MENU_ITEM_RESET: + if (g_console.emulator_initialized) + { + return_to_game(); + ssnes_game_reset(); + } + break; + case MENU_ITEM_RETURN_TO_GAME: + if (g_console.emulator_initialized) + return_to_game(); + break; + case MENU_ITEM_RETURN_TO_DASHBOARD: + return_to_dashboard(); + break; + } + } - if ( hObjPressed == m_back ) - NavigateBack(app.hMainScene); + if ( hObjPressed == m_back ) + NavigateBack(app.hMainScene); - bHandled = TRUE; - return S_OK; + bHandled = TRUE; + + return S_OK; } HRESULT CSSNESMain::OnInit(XUIMessageInit * pInitData, BOOL& bHandled) { - struct retro_system_info info; - retro_get_system_info(&info); - const char *id = info.library_name ? info.library_name : "Unknown"; + struct retro_system_info info; + retro_get_system_info(&info); + const char *id = info.library_name ? info.library_name : "Unknown"; - GetChildById(L"XuiBtnRomBrowser", &m_filebrowser); - GetChildById(L"XuiBtnSettings", &m_settings); - GetChildById(L"XuiBtnQuickMenu", &m_quick_menu); - GetChildById(L"XuiBtnControls", &m_controls); - GetChildById(L"XuiBtnQuit", &m_quit); - GetChildById(L"XuiTxtTitle", &m_title); - GetChildById(L"XuiTxtCoreText", &m_core); - GetChildById(L"XuiBtnLibsnesCore", &m_change_libsnes_core); + GetChildById(L"XuiBtnRomBrowser", &m_filebrowser); + GetChildById(L"XuiBtnSettings", &m_settings); + GetChildById(L"XuiBtnQuickMenu", &m_quick_menu); + GetChildById(L"XuiBtnControls", &m_controls); + GetChildById(L"XuiBtnQuit", &m_quit); + GetChildById(L"XuiTxtTitle", &m_title); + GetChildById(L"XuiTxtCoreText", &m_core); + GetChildById(L"XuiBtnLibsnesCore", &m_change_libsnes_core); - char core_text[256]; - sprintf(core_text, "%s (v%s)", id, info.library_version); - char package_version[32]; - sprintf(package_version, "SSNES %s", PACKAGE_VERSION); - unsigned long dwNum = MultiByteToWideChar(CP_ACP, 0, core_text, -1, NULL, 0); - unsigned long dwNum_package = MultiByteToWideChar(CP_ACP, 0, package_version, -1, NULL, 0); - wchar_t * core_text_utf = new wchar_t[dwNum]; - wchar_t * package_version_utf = new wchar_t[dwNum_package]; - MultiByteToWideChar(CP_ACP, 0, core_text, -1, core_text_utf, dwNum); - MultiByteToWideChar(CP_ACP, 0, package_version, -1, package_version_utf, dwNum_package); - m_core.SetText(core_text_utf); - m_title.SetText(package_version_utf); - delete []core_text_utf; - delete []package_version_utf; + char core_text[256]; + sprintf(core_text, "%s (v%s)", id, info.library_version); + char package_version[32]; + sprintf(package_version, "SSNES %s", PACKAGE_VERSION); + unsigned long dwNum = MultiByteToWideChar(CP_ACP, 0, core_text, -1, NULL, 0); + unsigned long dwNum_package = MultiByteToWideChar(CP_ACP, 0, package_version, -1, NULL, 0); + wchar_t * core_text_utf = new wchar_t[dwNum]; + wchar_t * package_version_utf = new wchar_t[dwNum_package]; + MultiByteToWideChar(CP_ACP, 0, core_text, -1, core_text_utf, dwNum); + MultiByteToWideChar(CP_ACP, 0, package_version, -1, package_version_utf, dwNum_package); + m_core.SetText(core_text_utf); + m_title.SetText(package_version_utf); + delete []core_text_utf; + delete []package_version_utf; - return S_OK; + return S_OK; } HRESULT CSSNESFileBrowser::OnNotifyPress( HXUIOBJ hObjPressed, BOOL& bHandled ) { - char path[MAX_PATH_LENGTH]; + char path[MAX_PATH_LENGTH]; - if(hObjPressed == m_romlist) - { - int index = m_romlist.GetCurSel(); - if(browser.cur[index].d_type != FILE_ATTRIBUTE_DIRECTORY) - { - memset(strbuffer, 0, sizeof(strbuffer)); - wcstombs(strbuffer, (const wchar_t *)m_romlist.GetText(index), sizeof(strbuffer)); - if((strstr(strbuffer, ".zip") || strstr(strbuffer, ".ZIP")) && !g_console.block_zip_extract) - { - char path_tmp[1024]; - sprintf(path_tmp, "%s\\%s", FILEBROWSER_GET_CURRENT_DIRECTORY_NAME(browser), strbuffer); - ssnes_extract_zipfile(path_tmp); - } - else - { - memset(g_console.rom_path, 0, sizeof(g_console.rom_path)); - sprintf(g_console.rom_path, "%s\\%s", FILEBROWSER_GET_CURRENT_DIRECTORY_NAME(browser), strbuffer); - return_to_game(); - g_console.initialize_ssnes_enable = 1; - } - } - else if(browser.cur[index].d_type == FILE_ATTRIBUTE_DIRECTORY) - { - memset(strbuffer, 0, sizeof(strbuffer)); - wcstombs(strbuffer, (const wchar_t *)m_romlist.GetText(index), sizeof(strbuffer)); - snprintf(path, sizeof(path), "%s\\%s", FILEBROWSER_GET_CURRENT_DIRECTORY_NAME(browser), strbuffer); - filebrowser_fetch_directory_entries(path, &browser, &m_romlist, &m_rompathtitle); - } - } - else if (hObjPressed == m_dir_game) - { - filebrowser_new(&browser, g_console.default_rom_startup_dir, ssnes_console_get_rom_ext()); - filebrowser_fetch_directory_entries(g_console.default_rom_startup_dir, &browser, &m_romlist, &m_rompathtitle); - } - else if (hObjPressed == m_dir_cache) - { - filebrowser_new(&browser, "cache:", ssnes_console_get_rom_ext()); - filebrowser_fetch_directory_entries("cache:", &browser, &m_romlist, &m_rompathtitle); - } - else if(hObjPressed == m_back) - NavigateBack(app.hMainScene); + if(hObjPressed == m_romlist) + { + int index = m_romlist.GetCurSel(); + if(browser.cur[index].d_type != FILE_ATTRIBUTE_DIRECTORY) + { + memset(strbuffer, 0, sizeof(strbuffer)); + wcstombs(strbuffer, (const wchar_t *)m_romlist.GetText(index), sizeof(strbuffer)); + if((strstr(strbuffer, ".zip") || strstr(strbuffer, ".ZIP")) && !g_console.block_zip_extract) + { + char path_tmp[1024]; + sprintf(path_tmp, "%s\\%s", FILEBROWSER_GET_CURRENT_DIRECTORY_NAME(browser), strbuffer); + ssnes_extract_zipfile(path_tmp); + } + else + { + memset(g_console.rom_path, 0, sizeof(g_console.rom_path)); + sprintf(g_console.rom_path, "%s\\%s", FILEBROWSER_GET_CURRENT_DIRECTORY_NAME(browser), strbuffer); + return_to_game(); + g_console.initialize_ssnes_enable = 1; + } + } + else if(browser.cur[index].d_type == FILE_ATTRIBUTE_DIRECTORY) + { + memset(strbuffer, 0, sizeof(strbuffer)); + wcstombs(strbuffer, (const wchar_t *)m_romlist.GetText(index), sizeof(strbuffer)); + snprintf(path, sizeof(path), "%s\\%s", FILEBROWSER_GET_CURRENT_DIRECTORY_NAME(browser), strbuffer); + filebrowser_fetch_directory_entries(path, &browser, &m_romlist, &m_rompathtitle); + } + } + else if (hObjPressed == m_dir_game) + { + filebrowser_new(&browser, g_console.default_rom_startup_dir, ssnes_console_get_rom_ext()); + filebrowser_fetch_directory_entries(g_console.default_rom_startup_dir, &browser, &m_romlist, &m_rompathtitle); + } + else if (hObjPressed == m_dir_cache) + { + filebrowser_new(&browser, "cache:", ssnes_console_get_rom_ext()); + filebrowser_fetch_directory_entries("cache:", &browser, &m_romlist, &m_rompathtitle); + } + else if(hObjPressed == m_back) + NavigateBack(app.hMainScene); - bHandled = TRUE; - return S_OK; + bHandled = TRUE; + + return S_OK; } HRESULT CSSNESCoreBrowser::OnNotifyPress( HXUIOBJ hObjPressed, BOOL& bHandled ) { - char path[MAX_PATH_LENGTH]; + char path[MAX_PATH_LENGTH]; - if(hObjPressed == m_romlist) - { - int index = m_romlist.GetCurSel(); - if(browser.cur[index].d_type != FILE_ATTRIBUTE_DIRECTORY) - { - memset(strbuffer, 0, sizeof(strbuffer)); - wcstombs(strbuffer, (const wchar_t *)m_romlist.GetText(index), sizeof(strbuffer)); - sprintf(g_console.launch_app_on_exit, "%s\\%s", FILEBROWSER_GET_CURRENT_DIRECTORY_NAME(tmp_browser), strbuffer); - g_console.return_to_launcher = true; - g_console.menu_enable = false; - g_console.mode_switch = MODE_EXIT; - } - else if(tmp_browser.cur[index].d_type == FILE_ATTRIBUTE_DIRECTORY) - { - memset(strbuffer, 0, sizeof(strbuffer)); - wcstombs(strbuffer, (const wchar_t *)m_romlist.GetText(index), sizeof(strbuffer)); - snprintf(path, sizeof(path), "%s%s\\", FILEBROWSER_GET_CURRENT_DIRECTORY_NAME(tmp_browser), strbuffer); - filebrowser_fetch_directory_entries(path, &tmp_browser, &m_romlist, &m_rompathtitle); - } - } - else if(hObjPressed == m_back) - NavigateBack(app.hMainScene); + if(hObjPressed == m_romlist) + { + int index = m_romlist.GetCurSel(); + if(browser.cur[index].d_type != FILE_ATTRIBUTE_DIRECTORY) + { + memset(strbuffer, 0, sizeof(strbuffer)); + wcstombs(strbuffer, (const wchar_t *)m_romlist.GetText(index), sizeof(strbuffer)); + sprintf(g_console.launch_app_on_exit, "%s\\%s", FILEBROWSER_GET_CURRENT_DIRECTORY_NAME(tmp_browser), strbuffer); + g_console.return_to_launcher = true; + g_console.menu_enable = false; + g_console.mode_switch = MODE_EXIT; + } + else if(tmp_browser.cur[index].d_type == FILE_ATTRIBUTE_DIRECTORY) + { + memset(strbuffer, 0, sizeof(strbuffer)); + wcstombs(strbuffer, (const wchar_t *)m_romlist.GetText(index), sizeof(strbuffer)); + snprintf(path, sizeof(path), "%s%s\\", FILEBROWSER_GET_CURRENT_DIRECTORY_NAME(tmp_browser), strbuffer); + filebrowser_fetch_directory_entries(path, &tmp_browser, &m_romlist, &m_rompathtitle); + } + } + else if(hObjPressed == m_back) + NavigateBack(app.hMainScene); - bHandled = TRUE; - return S_OK; + bHandled = TRUE; + return S_OK; } HRESULT CSSNESSettings::OnNotifyPress( HXUIOBJ hObjPressed, int & bHandled ) { - int current_index; + int current_index; - if ( hObjPressed == m_settingslist) - { - current_index = m_settingslist.GetCurSel(); + if ( hObjPressed == m_settingslist) + { + current_index = m_settingslist.GetCurSel(); - switch(current_index) - { - case SETTING_EMU_REWIND_ENABLED: - g_settings.rewind_enable = !g_settings.rewind_enable; - m_settingslist.SetText(SETTING_EMU_REWIND_ENABLED, g_settings.rewind_enable ? L"Rewind: ON" : L"Rewind: OFF"); - break; - case SETTING_GAMMA_CORRECTION_ENABLED: - g_console.gamma_correction_enable = !g_console.gamma_correction_enable; - m_settingslist.SetText(SETTING_GAMMA_CORRECTION_ENABLED, g_console.gamma_correction_enable ? L"Gamma correction: ON" : L"Gamma correction: OFF"); - break; - case SETTING_HARDWARE_FILTERING: - g_settings.video.smooth = !g_settings.video.smooth; - m_settingslist.SetText(SETTING_HARDWARE_FILTERING, set_filter_element(g_settings.video.smooth)); - break; - } - } + switch(current_index) + { + case SETTING_EMU_REWIND_ENABLED: + g_settings.rewind_enable = !g_settings.rewind_enable; + m_settingslist.SetText(SETTING_EMU_REWIND_ENABLED, g_settings.rewind_enable ? L"Rewind: ON" : L"Rewind: OFF"); + break; + case SETTING_GAMMA_CORRECTION_ENABLED: + g_console.gamma_correction_enable = !g_console.gamma_correction_enable; + m_settingslist.SetText(SETTING_GAMMA_CORRECTION_ENABLED, g_console.gamma_correction_enable ? L"Gamma correction: ON" : L"Gamma correction: OFF"); + break; + case SETTING_HARDWARE_FILTERING: + g_settings.video.smooth = !g_settings.video.smooth; + m_settingslist.SetText(SETTING_HARDWARE_FILTERING, set_filter_element(g_settings.video.smooth)); + break; + } + } - if ( hObjPressed == m_back ) - NavigateBack(app.hMainScene); + if ( hObjPressed == m_back ) + NavigateBack(app.hMainScene); - bHandled = TRUE; - return S_OK; + bHandled = TRUE; + return S_OK; } HRESULT CSSNESMain::OnNotifyPress( HXUIOBJ hObjPressed, int & bHandled ) { - xdk360_video_t *vid = (xdk360_video_t*)g_d3d; + xdk360_video_t *vid = (xdk360_video_t*)g_d3d; - bool hdmenus_allowed = vid->video_mode.fIsHiDef && (g_console.aspect_ratio_index >= ASPECT_RATIO_16_9); + bool hdmenus_allowed = vid->video_mode.fIsHiDef && (g_console.aspect_ratio_index >= ASPECT_RATIO_16_9); - HRESULT hr; + HRESULT hr; - if ( hObjPressed == m_filebrowser ) - { - hr = XuiSceneCreate(hdmenus_allowed ? L"file://game:/media/hd/" : L"file://game:/media/sd/", L"ssnes_filebrowser.xur", NULL, &app.hFileBrowser); - - if (FAILED(hr)) - { - SSNES_ERR("Failed to load scene.\n"); - } + if ( hObjPressed == m_filebrowser ) + { + hr = XuiSceneCreate(hdmenus_allowed ? L"file://game:/media/hd/" : L"file://game:/media/sd/", L"ssnes_filebrowser.xur", NULL, &app.hFileBrowser); - NavigateForward(app.hFileBrowser); - } - else if ( hObjPressed == m_quick_menu) - { - hr = XuiSceneCreate(hdmenus_allowed ? L"file://game:/media/hd/" : L"file://game:/media/sd/", L"ssnes_quickmenu.xur", NULL, &app.hQuickMenu); - - if (FAILED(hr)) - SSNES_ERR("Failed to load scene.\n"); + if (FAILED(hr)) + { + SSNES_ERR("Failed to load scene.\n"); + } - NavigateForward(app.hQuickMenu); - } - else if ( hObjPressed == m_change_libsnes_core ) - { - hr = XuiSceneCreate(hdmenus_allowed ? L"file://game:/media/hd/" : L"file://game:/media/sd/", L"ssnes_libsnescore_browser.xur", NULL, &app.hCoreBrowser); - - if (FAILED(hr)) - { - SSNES_ERR("Failed to load scene.\n"); - } - NavigateForward(app.hCoreBrowser); - } - else if ( hObjPressed == m_settings ) - { - hr = XuiSceneCreate(hdmenus_allowed ? L"file://game:/media/hd/" : L"file://game:/media/sd/", L"ssnes_settings.xur", NULL, &app.hSSNESSettings); - - if (FAILED(hr)) - SSNES_ERR("Failed to load scene.\n"); + NavigateForward(app.hFileBrowser); + } + else if ( hObjPressed == m_quick_menu) + { + hr = XuiSceneCreate(hdmenus_allowed ? L"file://game:/media/hd/" : L"file://game:/media/sd/", L"ssnes_quickmenu.xur", NULL, &app.hQuickMenu); - NavigateForward(app.hSSNESSettings); - } - else if ( hObjPressed == m_quit ) - return_to_dashboard(); + if (FAILED(hr)) + SSNES_ERR("Failed to load scene.\n"); - bHandled = TRUE; - return S_OK; + NavigateForward(app.hQuickMenu); + } + else if ( hObjPressed == m_change_libsnes_core ) + { + hr = XuiSceneCreate(hdmenus_allowed ? L"file://game:/media/hd/" : L"file://game:/media/sd/", L"ssnes_libsnescore_browser.xur", NULL, &app.hCoreBrowser); + + if (FAILED(hr)) + { + SSNES_ERR("Failed to load scene.\n"); + } + NavigateForward(app.hCoreBrowser); + } + else if ( hObjPressed == m_settings ) + { + hr = XuiSceneCreate(hdmenus_allowed ? L"file://game:/media/hd/" : L"file://game:/media/sd/", L"ssnes_settings.xur", NULL, &app.hSSNESSettings); + + if (FAILED(hr)) + SSNES_ERR("Failed to load scene.\n"); + + NavigateForward(app.hSSNESSettings); + } + else if ( hObjPressed == m_quit ) + return_to_dashboard(); + + bHandled = TRUE; + return S_OK; } int menu_init (void) { - HRESULT hr; + HRESULT hr; - xdk360_video_t *vid = (xdk360_video_t*)g_d3d; - - hr = app.InitShared(vid->xdk360_render_device, &vid->d3dpp, XuiPNGTextureLoader); + xdk360_video_t *vid = (xdk360_video_t*)g_d3d; - if (FAILED(hr)) - { - SSNES_ERR("Failed initializing XUI application.\n"); - return 1; - } + hr = app.InitShared(vid->xdk360_render_device, &vid->d3dpp, XuiPNGTextureLoader); - /* Register font */ - hr = app.RegisterDefaultTypeface(L"Arial Unicode MS", L"file://game:/media/ssnes.ttf" ); - if (FAILED(hr)) - { - SSNES_ERR("Failed to register default typeface.\n"); - return 1; - } + if (FAILED(hr)) + { + SSNES_ERR("Failed initializing XUI application.\n"); + return 1; + } - hr = app.LoadSkin( L"file://game:/media/ssnes_scene_skin.xur"); - if (FAILED(hr)) - { - SSNES_ERR("Failed to load skin.\n"); - return 1; - } + /* Register font */ + hr = app.RegisterDefaultTypeface(L"Arial Unicode MS", L"file://game:/media/ssnes.ttf" ); + if (FAILED(hr)) + { + SSNES_ERR("Failed to register default typeface.\n"); + return 1; + } - hr = XuiSceneCreate(L"file://game:/media/sd/", L"ssnes_main.xur", NULL, &app.hMainScene); - if (FAILED(hr)) - { - SSNES_ERR("Failed to create scene 'ssnes_main.xur'.\n"); - return 1; - } + hr = app.LoadSkin( L"file://game:/media/ssnes_scene_skin.xur"); + if (FAILED(hr)) + { + SSNES_ERR("Failed to load skin.\n"); + return 1; + } - XuiSceneNavigateFirst(app.GetRootObj(), app.hMainScene, XUSER_INDEX_FOCUS); + hr = XuiSceneCreate(L"file://game:/media/sd/", L"ssnes_main.xur", NULL, &app.hMainScene); + if (FAILED(hr)) + { + SSNES_ERR("Failed to create scene 'ssnes_main.xur'.\n"); + return 1; + } - filebrowser_new(&browser, g_console.default_rom_startup_dir, ssnes_console_get_rom_ext()); + XuiSceneNavigateFirst(app.GetRootObj(), app.hMainScene, XUSER_INDEX_FOCUS); - return 0; + filebrowser_new(&browser, g_console.default_rom_startup_dir, ssnes_console_get_rom_ext()); + + return 0; } void menu_loop(void) { - g_console.menu_enable = true; + g_console.menu_enable = true; - HRESULT hr; - xdk360_video_t *vid = (xdk360_video_t*)g_d3d; + HRESULT hr; + xdk360_video_t *vid = (xdk360_video_t*)g_d3d; - if(g_console.emulator_initialized) - video_xdk360.set_swap_block_state(NULL, true); + if(g_console.emulator_initialized) + video_xdk360.set_swap_block_state(NULL, true); - do - { - g_frame_count++; - if(g_console.emulator_initialized) - { - ssnes_render_cached_frame(); - } - else - D3DDevice_Clear(vid->xdk360_render_device, 0, NULL, - D3DCLEAR_TARGET, D3DCOLOR_ARGB(255, 32, 32, 64), 1.0, 0, FALSE); + do + { + g_frame_count++; + if(g_console.emulator_initialized) + { + ssnes_render_cached_frame(); + } + else + D3DDevice_Clear(vid->xdk360_render_device, 0, NULL, + D3DCLEAR_TARGET, D3DCOLOR_ARGB(255, 32, 32, 64), 1.0, 0, FALSE); - XINPUT_STATE state; - XInputGetState(0, &state); + XINPUT_STATE state; + XInputGetState(0, &state); - g_console.menu_enable = !((state.Gamepad.wButtons & XINPUT_GAMEPAD_LEFT_THUMB) - && (state.Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_THUMB) && (g_console.emulator_initialized) - && IS_TIMER_EXPIRED()); - g_console.mode_switch = g_console.menu_enable ? MODE_MENU : MODE_EMULATION; + g_console.menu_enable = !((state.Gamepad.wButtons & XINPUT_GAMEPAD_LEFT_THUMB) + && (state.Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_THUMB) && (g_console.emulator_initialized) + && IS_TIMER_EXPIRED()); + g_console.mode_switch = g_console.menu_enable ? MODE_MENU : MODE_EMULATION; - app.RunFrame(); /* Update XUI */ - hr = app.Render(); /* Render XUI */ - hr = XuiTimersRun(); /* Update XUI timers */ + app.RunFrame(); /* Update XUI */ + hr = app.Render(); /* Render XUI */ + hr = XuiTimersRun(); /* Update XUI timers */ - if(g_console.mode_switch == MODE_EMULATION && !g_console.frame_advance_enable) - { - SET_TIMER_EXPIRATION(30); - } + if(g_console.mode_switch == MODE_EMULATION && !g_console.frame_advance_enable) + { + SET_TIMER_EXPIRATION(30); + } - video_xdk360.swap(NULL); - }while(g_console.menu_enable); - - if(g_console.emulator_initialized) - video_xdk360.set_swap_block_state(NULL, false); + video_xdk360.swap(NULL); + }while(g_console.menu_enable); - g_console.ingame_menu_enable = false; + if(g_console.emulator_initialized) + video_xdk360.set_swap_block_state(NULL, false); + + g_console.ingame_menu_enable = false; } diff --git a/360/xdk360_input.c b/360/xdk360_input.c index 8be6fab509..705ede26cd 100644 --- a/360/xdk360_input.c +++ b/360/xdk360_input.c @@ -36,20 +36,20 @@ static void xdk360_input_poll(void *data) for (unsigned i = 0; i < 4; i++) { - XINPUT_STATE state_tmp; + XINPUT_STATE state_tmp; unsigned long retval = XInputGetState(i, &state_tmp); - pads_connected += (retval == ERROR_DEVICE_NOT_CONNECTED) ? 0 : 1; - state[i] = state_tmp.Gamepad.wButtons; - state[i] |= ((state_tmp.Gamepad.sThumbLX < -DEADZONE)) << 16; - state[i] |= ((state_tmp.Gamepad.sThumbLX > DEADZONE)) << 17; - state[i] |= ((state_tmp.Gamepad.sThumbLY > DEADZONE)) << 18; - state[i] |= ((state_tmp.Gamepad.sThumbLY < -DEADZONE)) << 19; - state[i] |= ((state_tmp.Gamepad.sThumbRX < -DEADZONE)) << 20; - state[i] |= ((state_tmp.Gamepad.sThumbRX > DEADZONE)) << 21; - state[i] |= ((state_tmp.Gamepad.sThumbRY > DEADZONE)) << 22; - state[i] |= ((state_tmp.Gamepad.sThumbRY < -DEADZONE)) << 23; - state[i] |= ((state_tmp.Gamepad.bLeftTrigger > 128 ? 1 : 0)) << 24; - state[i] |= ((state_tmp.Gamepad.bRightTrigger > 128 ? 1 : 0)) << 25; + pads_connected += (retval == ERROR_DEVICE_NOT_CONNECTED) ? 0 : 1; + state[i] = state_tmp.Gamepad.wButtons; + state[i] |= ((state_tmp.Gamepad.sThumbLX < -DEADZONE)) << 16; + state[i] |= ((state_tmp.Gamepad.sThumbLX > DEADZONE)) << 17; + state[i] |= ((state_tmp.Gamepad.sThumbLY > DEADZONE)) << 18; + state[i] |= ((state_tmp.Gamepad.sThumbLY < -DEADZONE)) << 19; + state[i] |= ((state_tmp.Gamepad.sThumbRX < -DEADZONE)) << 20; + state[i] |= ((state_tmp.Gamepad.sThumbRX > DEADZONE)) << 21; + state[i] |= ((state_tmp.Gamepad.sThumbRY > DEADZONE)) << 22; + state[i] |= ((state_tmp.Gamepad.sThumbRY < -DEADZONE)) << 23; + state[i] |= ((state_tmp.Gamepad.bLeftTrigger > 128 ? 1 : 0)) << 24; + state[i] |= ((state_tmp.Gamepad.bRightTrigger > 128 ? 1 : 0)) << 25; } } @@ -77,32 +77,32 @@ static void* xdk360_input_initialize(void) void xdk360_input_init(void) { for(unsigned i = 0; i < 4; i++) - xdk360_input_map_dpad_to_stick(g_settings.input.dpad_emulation[i], i); + xdk360_input_map_dpad_to_stick(g_settings.input.dpad_emulation[i], i); } void xdk360_input_map_dpad_to_stick(uint32_t map_dpad_enum, uint32_t controller_id) { - switch(map_dpad_enum) - { - case DPAD_EMULATION_NONE: - g_settings.input.binds[controller_id][RETRO_DEVICE_ID_JOYPAD_UP].joykey = ssnes_platform_keybind_lut[XDK360_DEVICE_ID_JOYPAD_UP]; - g_settings.input.binds[controller_id][RETRO_DEVICE_ID_JOYPAD_DOWN].joykey = ssnes_platform_keybind_lut[XDK360_DEVICE_ID_JOYPAD_DOWN]; - g_settings.input.binds[controller_id][RETRO_DEVICE_ID_JOYPAD_LEFT].joykey = ssnes_platform_keybind_lut[XDK360_DEVICE_ID_JOYPAD_LEFT]; - g_settings.input.binds[controller_id][RETRO_DEVICE_ID_JOYPAD_RIGHT].joykey = ssnes_platform_keybind_lut[XDK360_DEVICE_ID_JOYPAD_RIGHT]; - break; - case DPAD_EMULATION_LSTICK: - g_settings.input.binds[controller_id][RETRO_DEVICE_ID_JOYPAD_UP].joykey = ssnes_platform_keybind_lut[XDK360_DEVICE_ID_LSTICK_UP_DPAD]; - g_settings.input.binds[controller_id][RETRO_DEVICE_ID_JOYPAD_DOWN].joykey = ssnes_platform_keybind_lut[XDK360_DEVICE_ID_LSTICK_DOWN_DPAD]; - g_settings.input.binds[controller_id][RETRO_DEVICE_ID_JOYPAD_LEFT].joykey = ssnes_platform_keybind_lut[XDK360_DEVICE_ID_LSTICK_LEFT_DPAD]; - g_settings.input.binds[controller_id][RETRO_DEVICE_ID_JOYPAD_RIGHT].joykey = ssnes_platform_keybind_lut[XDK360_DEVICE_ID_LSTICK_RIGHT_DPAD]; - break; - case DPAD_EMULATION_RSTICK: - g_settings.input.binds[controller_id][RETRO_DEVICE_ID_JOYPAD_UP].joykey = ssnes_platform_keybind_lut[XDK360_DEVICE_ID_RSTICK_UP_DPAD]; - g_settings.input.binds[controller_id][RETRO_DEVICE_ID_JOYPAD_DOWN].joykey = ssnes_platform_keybind_lut[XDK360_DEVICE_ID_RSTICK_DOWN_DPAD]; - g_settings.input.binds[controller_id][RETRO_DEVICE_ID_JOYPAD_LEFT].joykey = ssnes_platform_keybind_lut[XDK360_DEVICE_ID_RSTICK_LEFT_DPAD]; - g_settings.input.binds[controller_id][RETRO_DEVICE_ID_JOYPAD_RIGHT].joykey = ssnes_platform_keybind_lut[XDK360_DEVICE_ID_RSTICK_RIGHT_DPAD]; - break; - } + switch(map_dpad_enum) + { + case DPAD_EMULATION_NONE: + g_settings.input.binds[controller_id][RETRO_DEVICE_ID_JOYPAD_UP].joykey = ssnes_platform_keybind_lut[XDK360_DEVICE_ID_JOYPAD_UP]; + g_settings.input.binds[controller_id][RETRO_DEVICE_ID_JOYPAD_DOWN].joykey = ssnes_platform_keybind_lut[XDK360_DEVICE_ID_JOYPAD_DOWN]; + g_settings.input.binds[controller_id][RETRO_DEVICE_ID_JOYPAD_LEFT].joykey = ssnes_platform_keybind_lut[XDK360_DEVICE_ID_JOYPAD_LEFT]; + g_settings.input.binds[controller_id][RETRO_DEVICE_ID_JOYPAD_RIGHT].joykey = ssnes_platform_keybind_lut[XDK360_DEVICE_ID_JOYPAD_RIGHT]; + break; + case DPAD_EMULATION_LSTICK: + g_settings.input.binds[controller_id][RETRO_DEVICE_ID_JOYPAD_UP].joykey = ssnes_platform_keybind_lut[XDK360_DEVICE_ID_LSTICK_UP_DPAD]; + g_settings.input.binds[controller_id][RETRO_DEVICE_ID_JOYPAD_DOWN].joykey = ssnes_platform_keybind_lut[XDK360_DEVICE_ID_LSTICK_DOWN_DPAD]; + g_settings.input.binds[controller_id][RETRO_DEVICE_ID_JOYPAD_LEFT].joykey = ssnes_platform_keybind_lut[XDK360_DEVICE_ID_LSTICK_LEFT_DPAD]; + g_settings.input.binds[controller_id][RETRO_DEVICE_ID_JOYPAD_RIGHT].joykey = ssnes_platform_keybind_lut[XDK360_DEVICE_ID_LSTICK_RIGHT_DPAD]; + break; + case DPAD_EMULATION_RSTICK: + g_settings.input.binds[controller_id][RETRO_DEVICE_ID_JOYPAD_UP].joykey = ssnes_platform_keybind_lut[XDK360_DEVICE_ID_RSTICK_UP_DPAD]; + g_settings.input.binds[controller_id][RETRO_DEVICE_ID_JOYPAD_DOWN].joykey = ssnes_platform_keybind_lut[XDK360_DEVICE_ID_RSTICK_DOWN_DPAD]; + g_settings.input.binds[controller_id][RETRO_DEVICE_ID_JOYPAD_LEFT].joykey = ssnes_platform_keybind_lut[XDK360_DEVICE_ID_RSTICK_LEFT_DPAD]; + g_settings.input.binds[controller_id][RETRO_DEVICE_ID_JOYPAD_RIGHT].joykey = ssnes_platform_keybind_lut[XDK360_DEVICE_ID_RSTICK_RIGHT_DPAD]; + break; + } } static bool xdk360_key_pressed(void *data, int key) @@ -116,45 +116,44 @@ static bool xdk360_key_pressed(void *data, int key) switch(key) { - case SSNES_FAST_FORWARD_HOLD_KEY: - return ((state.Gamepad.sThumbRY < -DEADZONE) && !(state.Gamepad.bRightTrigger > 128)); - case SSNES_LOAD_STATE_KEY: - return ((state.Gamepad.sThumbRY > DEADZONE) && (state.Gamepad.bRightTrigger > 128)); - case SSNES_SAVE_STATE_KEY: - return ((state.Gamepad.sThumbRY < -DEADZONE) && (state.Gamepad.bRightTrigger > 128)); - case SSNES_STATE_SLOT_PLUS: - return ((state.Gamepad.sThumbRX > DEADZONE) && (state.Gamepad.bRightTrigger > 128)); - case SSNES_STATE_SLOT_MINUS: - return ((state.Gamepad.sThumbRX < -DEADZONE) && (state.Gamepad.bRightTrigger > 128)); - case SSNES_FRAMEADVANCE: - if(g_console.frame_advance_enable) - { - g_console.menu_enable = true; - g_console.ingame_menu_enable = true; - g_console.mode_switch = MODE_MENU; - } - return false; - case SSNES_REWIND: - return ((state.Gamepad.sThumbRY > DEADZONE) && !(state.Gamepad.bRightTrigger > 128)); - case SSNES_QUIT_KEY: - if(IS_TIMER_EXPIRED()) - { - uint32_t left_thumb_pressed = (state.Gamepad.wButtons & XINPUT_GAMEPAD_LEFT_THUMB); - uint32_t right_thumb_pressed = (state.Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_THUMB); + case SSNES_FAST_FORWARD_HOLD_KEY: + return ((state.Gamepad.sThumbRY < -DEADZONE) && !(state.Gamepad.bRightTrigger > 128)); + case SSNES_LOAD_STATE_KEY: + return ((state.Gamepad.sThumbRY > DEADZONE) && (state.Gamepad.bRightTrigger > 128)); + case SSNES_SAVE_STATE_KEY: + return ((state.Gamepad.sThumbRY < -DEADZONE) && (state.Gamepad.bRightTrigger > 128)); + case SSNES_STATE_SLOT_PLUS: + return ((state.Gamepad.sThumbRX > DEADZONE) && (state.Gamepad.bRightTrigger > 128)); + case SSNES_STATE_SLOT_MINUS: + return ((state.Gamepad.sThumbRX < -DEADZONE) && (state.Gamepad.bRightTrigger > 128)); + case SSNES_FRAMEADVANCE: + if(g_console.frame_advance_enable) + { + g_console.menu_enable = true; + g_console.ingame_menu_enable = true; + g_console.mode_switch = MODE_MENU; + } + return false; + case SSNES_REWIND: + return ((state.Gamepad.sThumbRY > DEADZONE) && !(state.Gamepad.bRightTrigger > 128)); + case SSNES_QUIT_KEY: + if(IS_TIMER_EXPIRED()) + { + uint32_t left_thumb_pressed = (state.Gamepad.wButtons & XINPUT_GAMEPAD_LEFT_THUMB); + uint32_t right_thumb_pressed = (state.Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_THUMB); - g_console.menu_enable = right_thumb_pressed && left_thumb_pressed && IS_TIMER_EXPIRED(); - g_console.ingame_menu_enable = right_thumb_pressed && !left_thumb_pressed; - - if(g_console.menu_enable || (g_console.ingame_menu_enable - && !g_console.menu_enable)) - { - g_console.mode_switch = MODE_MENU; - SET_TIMER_EXPIRATION(30); - retval = g_console.menu_enable; - } + g_console.menu_enable = right_thumb_pressed && left_thumb_pressed && IS_TIMER_EXPIRED(); + g_console.ingame_menu_enable = right_thumb_pressed && !left_thumb_pressed; - retval = g_console.ingame_menu_enable ? g_console.ingame_menu_enable : g_console.menu_enable; - } + if(g_console.menu_enable || (g_console.ingame_menu_enable && !g_console.menu_enable)) + { + g_console.mode_switch = MODE_MENU; + SET_TIMER_EXPIRATION(30); + retval = g_console.menu_enable; + } + + retval = g_console.ingame_menu_enable ? g_console.ingame_menu_enable : g_console.menu_enable; + } } return retval; diff --git a/360/xdk360_video.cpp b/360/xdk360_video.cpp index 722c07691f..1add6ea97a 100644 --- a/360/xdk360_video.cpp +++ b/360/xdk360_video.cpp @@ -35,13 +35,13 @@ void *g_d3d; struct hlsl_program_t { - D3DXHANDLE vid_size_f; - D3DXHANDLE tex_size_f; - D3DXHANDLE out_size_f; - D3DXHANDLE vid_size_v; - D3DXHANDLE tex_size_v; - D3DXHANDLE out_size_v; - XMMATRIX modelViewProj; + D3DXHANDLE vid_size_f; + D3DXHANDLE tex_size_f; + D3DXHANDLE out_size_f; + D3DXHANDLE vid_size_v; + D3DXHANDLE tex_size_v; + D3DXHANDLE out_size_v; + XMMATRIX modelViewProj; } hlsl_program; struct XPR_HEADER @@ -212,189 +212,193 @@ static void xdk360_gfx_free(void * data) static void set_viewport(bool force_full) { - xdk360_video_t *vid = (xdk360_video_t*)g_d3d; - D3DDevice_Clear(vid->xdk360_render_device, 0, NULL, D3DCLEAR_TARGET, - 0xff000000, 1.0f, 0, FALSE); + xdk360_video_t *vid = (xdk360_video_t*)g_d3d; + D3DDevice_Clear(vid->xdk360_render_device, 0, NULL, D3DCLEAR_TARGET, + 0xff000000, 1.0f, 0, FALSE); - int width = vid->video_mode.fIsHiDef ? 1280 : 640; - int height = vid->video_mode.fIsHiDef ? 720 : 480; - int m_viewport_x_temp, m_viewport_y_temp, m_viewport_width_temp, m_viewport_height_temp; - float m_zNear, m_zFar; + int width = vid->video_mode.fIsHiDef ? 1280 : 640; + int height = vid->video_mode.fIsHiDef ? 720 : 480; + int m_viewport_x_temp, m_viewport_y_temp, m_viewport_width_temp, m_viewport_height_temp; + float m_zNear, m_zFar; - m_viewport_x_temp = 0; - m_viewport_y_temp = 0; - m_viewport_width_temp = width; - m_viewport_height_temp = height; + m_viewport_x_temp = 0; + m_viewport_y_temp = 0; + m_viewport_width_temp = width; + m_viewport_height_temp = height; - m_zNear = 0.0f; - m_zFar = 1.0f; + m_zNear = 0.0f; + m_zFar = 1.0f; - if (!force_full) - { - float desired_aspect = g_settings.video.aspect_ratio; - float device_aspect = (float)width / height; - float delta; + if (!force_full) + { + float desired_aspect = g_settings.video.aspect_ratio; + float device_aspect = (float)width / height; + float delta; - // If the aspect ratios of screen and desired aspect ratio are sufficiently equal (floating point stuff), - //if(g_console.aspect_ratio_index == ASPECT_RATIO_CUSTOM) - //{ - // m_viewport_x_temp = g_console.custom_viewport_x; - // m_viewport_y_temp = g_console.custom_viewport_y; - // m_viewport_width_temp = g_console.custom_viewport_width; - // m_viewport_height_temp = g_console.custom_viewport_height; - //} - if (device_aspect > desired_aspect) - { - delta = (desired_aspect / device_aspect - 1.0) / 2.0 + 0.5; - m_viewport_x_temp = (int)(width * (0.5 - delta)); - m_viewport_width_temp = (int)(2.0 * width * delta); - width = (unsigned)(2.0 * width * delta); - } - else - { - delta = (device_aspect / desired_aspect - 1.0) / 2.0 + 0.5; - m_viewport_y_temp = (int)(height * (0.5 - delta)); - m_viewport_height_temp = (int)(2.0 * height * delta); - height = (unsigned)(2.0 * height * delta); - } - } + // If the aspect ratios of screen and desired aspect ratio are sufficiently equal (floating point stuff), + //if(g_console.aspect_ratio_index == ASPECT_RATIO_CUSTOM) + //{ + // m_viewport_x_temp = g_console.custom_viewport_x; + // m_viewport_y_temp = g_console.custom_viewport_y; + // m_viewport_width_temp = g_console.custom_viewport_width; + // m_viewport_height_temp = g_console.custom_viewport_height; + //} + if (device_aspect > desired_aspect) + { + delta = (desired_aspect / device_aspect - 1.0) / 2.0 + 0.5; + m_viewport_x_temp = (int)(width * (0.5 - delta)); + m_viewport_width_temp = (int)(2.0 * width * delta); + width = (unsigned)(2.0 * width * delta); + } + else + { + delta = (device_aspect / desired_aspect - 1.0) / 2.0 + 0.5; + m_viewport_y_temp = (int)(height * (0.5 - delta)); + m_viewport_height_temp = (int)(2.0 * height * delta); + height = (unsigned)(2.0 * height * delta); + } + } - D3DVIEWPORT9 vp = {0}; - vp.Width = m_viewport_width_temp; - vp.Height = m_viewport_height_temp; - vp.X = m_viewport_x_temp; - vp.Y = m_viewport_y_temp; - vp.MinZ = m_zNear; - vp.MaxZ = m_zFar; - D3DDevice_SetViewport(vid->xdk360_render_device, &vp); + D3DVIEWPORT9 vp = {0}; + vp.Width = m_viewport_width_temp; + vp.Height = m_viewport_height_temp; + vp.X = m_viewport_x_temp; + vp.Y = m_viewport_y_temp; + vp.MinZ = m_zNear; + vp.MaxZ = m_zFar; + D3DDevice_SetViewport(vid->xdk360_render_device, &vp); - //if(gl->overscan_enable && !force_full) - //{ - // m_left = -gl->overscan_amount/2; - // m_right = 1 + gl->overscan_amount/2; - // m_bottom = -gl->overscan_amount/2; - //} + //if(gl->overscan_enable && !force_full) + //{ + // m_left = -gl->overscan_amount/2; + // m_right = 1 + gl->overscan_amount/2; + // m_bottom = -gl->overscan_amount/2; + //} } static void xdk360_set_orientation(void * data, uint32_t orientation) { - (void)data; - xdk360_video_t *vid = (xdk360_video_t*)g_d3d; - FLOAT angle; + (void)data; + xdk360_video_t *vid = (xdk360_video_t*)g_d3d; + FLOAT angle; - switch(orientation) - { - case ORIENTATION_NORMAL: - angle = M_PI * 0 / 180; - break; - case ORIENTATION_VERTICAL: - angle = M_PI * 270 / 180; - break; - case ORIENTATION_FLIPPED: - angle = M_PI * 180 / 180; - break; - case ORIENTATION_FLIPPED_ROTATED: - angle = M_PI * 90 / 180; - break; - } - hlsl_program.modelViewProj = XMMatrixRotationZ(angle); + switch(orientation) + { + case ORIENTATION_NORMAL: + angle = M_PI * 0 / 180; + break; + case ORIENTATION_VERTICAL: + angle = M_PI * 270 / 180; + break; + case ORIENTATION_FLIPPED: + angle = M_PI * 180 / 180; + break; + case ORIENTATION_FLIPPED_ROTATED: + angle = M_PI * 90 / 180; + break; + } + + hlsl_program.modelViewProj = XMMatrixRotationZ(angle); } static void xdk360_set_aspect_ratio(void * data, uint32_t aspectratio_index) { - (void)data; - switch(aspectratio_index) - { - case ASPECT_RATIO_4_3: - g_settings.video.aspect_ratio = 1.33333333333; - strlcpy(g_console.aspect_ratio_name, "4:3", sizeof(g_console.aspect_ratio_name)); - break; - case ASPECT_RATIO_4_4: - g_settings.video.aspect_ratio = 1.0; - strlcpy(g_console.aspect_ratio_name, "4:4", sizeof(g_console.aspect_ratio_name)); - break; - case ASPECT_RATIO_4_1: - g_settings.video.aspect_ratio = 4.0; - strlcpy(g_console.aspect_ratio_name, "4:1", sizeof(g_console.aspect_ratio_name)); - break; - case ASPECT_RATIO_5_4: - g_settings.video.aspect_ratio = 1.25; - strlcpy(g_console.aspect_ratio_name, "5:4", sizeof(g_console.aspect_ratio_name)); - break; - case ASPECT_RATIO_6_5: - g_settings.video.aspect_ratio = 1.2; - strlcpy(g_console.aspect_ratio_name, "6:5", sizeof(g_console.aspect_ratio_name)); - break; - case ASPECT_RATIO_7_9: - g_settings.video.aspect_ratio = 0.77777777777; - strlcpy(g_console.aspect_ratio_name, "7:9", sizeof(g_console.aspect_ratio_name)); - break; - case ASPECT_RATIO_8_3: - g_settings.video.aspect_ratio = 2.66666666666; - strlcpy(g_console.aspect_ratio_name, "8:3", sizeof(g_console.aspect_ratio_name)); - break; - case ASPECT_RATIO_8_7: - g_settings.video.aspect_ratio = 1.14287142857; - strlcpy(g_console.aspect_ratio_name, "8:7", sizeof(g_console.aspect_ratio_name)); - break; - case ASPECT_RATIO_16_9: - g_settings.video.aspect_ratio = 1.777778; - strlcpy(g_console.aspect_ratio_name, "16:9", sizeof(g_console.aspect_ratio_name)); - break; - case ASPECT_RATIO_16_10: - g_settings.video.aspect_ratio = 1.6; - strlcpy(g_console.aspect_ratio_name, "16:10", sizeof(g_console.aspect_ratio_name)); - break; - case ASPECT_RATIO_16_15: - g_settings.video.aspect_ratio = 3.2; - strlcpy(g_console.aspect_ratio_name, "16:15", sizeof(g_console.aspect_ratio_name)); - break; - case ASPECT_RATIO_19_12: - g_settings.video.aspect_ratio = 1.58333333333; - strlcpy(g_console.aspect_ratio_name, "19:12", sizeof(g_console.aspect_ratio_name)); - break; - case ASPECT_RATIO_19_14: - g_settings.video.aspect_ratio = 1.35714285714; - strlcpy(g_console.aspect_ratio_name, "19:14", sizeof(g_console.aspect_ratio_name)); - break; - case ASPECT_RATIO_30_17: - g_settings.video.aspect_ratio = 1.76470588235; - strlcpy(g_console.aspect_ratio_name, "30:17", sizeof(g_console.aspect_ratio_name)); - break; - case ASPECT_RATIO_32_9: - g_settings.video.aspect_ratio = 3.55555555555; - strlcpy(g_console.aspect_ratio_name, "32:9", sizeof(g_console.aspect_ratio_name)); - break; - case ASPECT_RATIO_2_1: - g_settings.video.aspect_ratio = 2.0; - strlcpy(g_console.aspect_ratio_name, "2:1", sizeof(g_console.aspect_ratio_name)); - break; - case ASPECT_RATIO_3_2: - g_settings.video.aspect_ratio = 1.5; - strlcpy(g_console.aspect_ratio_name, "3:2", sizeof(g_console.aspect_ratio_name)); - break; - case ASPECT_RATIO_3_4: - g_settings.video.aspect_ratio = 0.75; - strlcpy(g_console.aspect_ratio_name, "3:4", sizeof(g_console.aspect_ratio_name)); - break; - case ASPECT_RATIO_1_1: - g_settings.video.aspect_ratio = 1.0; - strlcpy(g_console.aspect_ratio_name, "1:1", sizeof(g_console.aspect_ratio_name)); - break; - case ASPECT_RATIO_AUTO: - strlcpy(g_console.aspect_ratio_name, "(Auto)", sizeof(g_console.aspect_ratio_name)); - break; - case ASPECT_RATIO_CUSTOM: - strlcpy(g_console.aspect_ratio_name, "(Custom)", sizeof(g_console.aspect_ratio_name)); - break; - } - g_settings.video.force_aspect = false; - set_viewport(false); + (void)data; + + switch(aspectratio_index) + { + case ASPECT_RATIO_4_3: + g_settings.video.aspect_ratio = 1.33333333333; + strlcpy(g_console.aspect_ratio_name, "4:3", sizeof(g_console.aspect_ratio_name)); + break; + case ASPECT_RATIO_4_4: + g_settings.video.aspect_ratio = 1.0; + strlcpy(g_console.aspect_ratio_name, "4:4", sizeof(g_console.aspect_ratio_name)); + break; + case ASPECT_RATIO_4_1: + g_settings.video.aspect_ratio = 4.0; + strlcpy(g_console.aspect_ratio_name, "4:1", sizeof(g_console.aspect_ratio_name)); + break; + case ASPECT_RATIO_5_4: + g_settings.video.aspect_ratio = 1.25; + strlcpy(g_console.aspect_ratio_name, "5:4", sizeof(g_console.aspect_ratio_name)); + break; + case ASPECT_RATIO_6_5: + g_settings.video.aspect_ratio = 1.2; + strlcpy(g_console.aspect_ratio_name, "6:5", sizeof(g_console.aspect_ratio_name)); + break; + case ASPECT_RATIO_7_9: + g_settings.video.aspect_ratio = 0.77777777777; + strlcpy(g_console.aspect_ratio_name, "7:9", sizeof(g_console.aspect_ratio_name)); + break; + case ASPECT_RATIO_8_3: + g_settings.video.aspect_ratio = 2.66666666666; + strlcpy(g_console.aspect_ratio_name, "8:3", sizeof(g_console.aspect_ratio_name)); + break; + case ASPECT_RATIO_8_7: + g_settings.video.aspect_ratio = 1.14287142857; + strlcpy(g_console.aspect_ratio_name, "8:7", sizeof(g_console.aspect_ratio_name)); + break; + case ASPECT_RATIO_16_9: + g_settings.video.aspect_ratio = 1.777778; + strlcpy(g_console.aspect_ratio_name, "16:9", sizeof(g_console.aspect_ratio_name)); + break; + case ASPECT_RATIO_16_10: + g_settings.video.aspect_ratio = 1.6; + strlcpy(g_console.aspect_ratio_name, "16:10", sizeof(g_console.aspect_ratio_name)); + break; + case ASPECT_RATIO_16_15: + g_settings.video.aspect_ratio = 3.2; + strlcpy(g_console.aspect_ratio_name, "16:15", sizeof(g_console.aspect_ratio_name)); + break; + case ASPECT_RATIO_19_12: + g_settings.video.aspect_ratio = 1.58333333333; + strlcpy(g_console.aspect_ratio_name, "19:12", sizeof(g_console.aspect_ratio_name)); + break; + case ASPECT_RATIO_19_14: + g_settings.video.aspect_ratio = 1.35714285714; + strlcpy(g_console.aspect_ratio_name, "19:14", sizeof(g_console.aspect_ratio_name)); + break; + case ASPECT_RATIO_30_17: + g_settings.video.aspect_ratio = 1.76470588235; + strlcpy(g_console.aspect_ratio_name, "30:17", sizeof(g_console.aspect_ratio_name)); + break; + case ASPECT_RATIO_32_9: + g_settings.video.aspect_ratio = 3.55555555555; + strlcpy(g_console.aspect_ratio_name, "32:9", sizeof(g_console.aspect_ratio_name)); + break; + case ASPECT_RATIO_2_1: + g_settings.video.aspect_ratio = 2.0; + strlcpy(g_console.aspect_ratio_name, "2:1", sizeof(g_console.aspect_ratio_name)); + break; + case ASPECT_RATIO_3_2: + g_settings.video.aspect_ratio = 1.5; + strlcpy(g_console.aspect_ratio_name, "3:2", sizeof(g_console.aspect_ratio_name)); + break; + case ASPECT_RATIO_3_4: + g_settings.video.aspect_ratio = 0.75; + strlcpy(g_console.aspect_ratio_name, "3:4", sizeof(g_console.aspect_ratio_name)); + break; + case ASPECT_RATIO_1_1: + g_settings.video.aspect_ratio = 1.0; + strlcpy(g_console.aspect_ratio_name, "1:1", sizeof(g_console.aspect_ratio_name)); + break; + case ASPECT_RATIO_AUTO: + strlcpy(g_console.aspect_ratio_name, "(Auto)", sizeof(g_console.aspect_ratio_name)); + break; + case ASPECT_RATIO_CUSTOM: + strlcpy(g_console.aspect_ratio_name, "(Custom)", sizeof(g_console.aspect_ratio_name)); + break; + } + + g_settings.video.force_aspect = false; + set_viewport(false); } static void *xdk360_gfx_init(const video_info_t *video, const input_driver_t **input, void **input_data) { - HRESULT ret; + HRESULT ret; + if (g_d3d) return g_d3d; @@ -420,7 +424,7 @@ static void *xdk360_gfx_init(const video_info_t *video, const input_driver_t **i // no letterboxing in 4:3 mode (if widescreen is // unsupported if(!vid->video_mode.fIsWideScreen) - vid->d3dpp.Flags |= D3DPRESENTFLAG_NO_LETTERBOX; + vid->d3dpp.Flags |= D3DPRESENTFLAG_NO_LETTERBOX; vid->d3dpp.BackBufferWidth = vid->video_mode.fIsHiDef ? 1280 : 640; vid->d3dpp.BackBufferHeight = vid->video_mode.fIsHiDef ? 720 : 480; @@ -453,31 +457,31 @@ static void *xdk360_gfx_init(const video_info_t *video, const input_driver_t **i if (SUCCEEDED(ret)) { - SSNES_LOG("Vertex shader program from [%s] successfully compiled.\n", "game:\\media\\shaders\\stock.cg"); - ret = D3DXCompileShaderFromFile( - g_settings.video.cg_shader_path, //filepath - NULL, //macros - NULL, //includes - "main_fragment", // main function - "ps_2_0", // shader profile - 0, // flags - &pShaderCodeP, // compiled operations - &pErrorMsg, // errors - NULL); // constants + SSNES_LOG("Vertex shader program from [%s] successfully compiled.\n", "game:\\media\\shaders\\stock.cg"); + ret = D3DXCompileShaderFromFile( + g_settings.video.cg_shader_path, //filepath + NULL, //macros + NULL, //includes + "main_fragment", // main function + "ps_2_0", // shader profile + 0, // flags + &pShaderCodeP, // compiled operations + &pErrorMsg, // errors + NULL); // constants } if (FAILED(ret)) { - if(pErrorMsg) - SSNES_LOG("%s\n", (char*)pErrorMsg->GetBufferPointer()); + if(pErrorMsg) + SSNES_LOG("%s\n", (char*)pErrorMsg->GetBufferPointer()); D3DDevice_Release(vid->xdk360_render_device); - Direct3D_Release(); + Direct3D_Release(); free(vid); return NULL; } else { - SSNES_LOG("Pixel shader program from [%s] successfully compiled.\n", "game:\\media\\shaders\\stock.cg"); + SSNES_LOG("Pixel shader program from [%s] successfully compiled.\n", "game:\\media\\shaders\\stock.cg"); } vid->pVertexShader = D3DDevice_CreateVertexShader((const DWORD*)pShaderCodeV->GetBufferPointer()); @@ -486,7 +490,7 @@ static void *xdk360_gfx_init(const video_info_t *video, const input_driver_t **i pShaderCodeP->Release(); vid->lpTexture = (D3DTexture*) D3DDevice_CreateTexture(512, 512, 1, 1, 0, D3DFMT_LIN_X1R5G5B5, - 0, D3DRTYPE_TEXTURE); + 0, D3DRTYPE_TEXTURE); D3DLOCKED_RECT d3dlr; D3DTexture_LockRect(vid->lpTexture, 0, &d3dlr, NULL, D3DLOCK_NOSYSLOCK); @@ -549,23 +553,23 @@ static bool xdk360_gfx_frame(void *data, const void *frame, { D3DLOCKED_RECT d3dlr; - D3DTexture_LockRect(vid->lpTexture, 0, &d3dlr, NULL, D3DLOCK_NOSYSLOCK); - memset(d3dlr.pBits, 0, 512 * d3dlr.Pitch); - D3DTexture_UnlockRect(vid->lpTexture, 0); + D3DTexture_LockRect(vid->lpTexture, 0, &d3dlr, NULL, D3DLOCK_NOSYSLOCK); + memset(d3dlr.pBits, 0, 512 * d3dlr.Pitch); + D3DTexture_UnlockRect(vid->lpTexture, 0); float tex_w = width / 512.0f; float tex_h = height / 512.0f; - const DrawVerticeFormats verts[] = { - { -1.0f, -1.0f, 0.0f, tex_h }, - { 1.0f, -1.0f, tex_w, tex_h }, - { -1.0f, 1.0f, 0.0f, 0.0f }, - { 1.0f, 1.0f, tex_w, 0.0f }, - }; - - void *verts_ptr = (BYTE*)D3DVertexBuffer_Lock(vid->vertex_buf, 0, 0, 0); - memcpy(verts_ptr, verts, sizeof(verts)); - D3DVertexBuffer_Unlock(vid->vertex_buf); + const DrawVerticeFormats verts[] = { + { -1.0f, -1.0f, 0.0f, tex_h }, + { 1.0f, -1.0f, tex_w, tex_h }, + { -1.0f, 1.0f, 0.0f, 0.0f }, + { 1.0f, 1.0f, tex_w, 0.0f }, + }; + + void *verts_ptr = (BYTE*)D3DVertexBuffer_Lock(vid->vertex_buf, 0, 0, 0); + memcpy(verts_ptr, verts, sizeof(verts)); + D3DVertexBuffer_Unlock(vid->vertex_buf); vid->last_width = width; vid->last_height = height; @@ -579,9 +583,9 @@ static bool xdk360_gfx_frame(void *data, const void *frame, D3DTexture_LockRect(vid->lpTexture, 0, &d3dlr, NULL, D3DLOCK_NOSYSLOCK); for (unsigned y = 0; y < height; y++) { - const uint8_t *in = (const uint8_t*)frame + y * pitch; - uint8_t *out = (uint8_t*)d3dlr.pBits + y * d3dlr.Pitch; - memcpy(out, in, width * sizeof(uint16_t)); + const uint8_t *in = (const uint8_t*)frame + y * pitch; + uint8_t *out = (uint8_t*)d3dlr.pBits + y * d3dlr.Pitch; + memcpy(out, in, width * sizeof(uint16_t)); } D3DTexture_UnlockRect(vid->lpTexture, 0); @@ -601,39 +605,39 @@ static bool xdk360_gfx_frame(void *data, const void *frame, D3DDevice_DrawVertices(vid->xdk360_render_device, D3DPT_TRIANGLESTRIP, 0, D3DVERTEXCOUNT(D3DPT_TRIANGLESTRIP, 2)); if (msg) { - if(IS_TIMER_EXPIRED() || g_first_msg) - { - xdk360_console_format(msg); - g_first_msg = 0; - SET_TIMER_EXPIRATION(30); - } + if(IS_TIMER_EXPIRED() || g_first_msg) + { + xdk360_console_format(msg); + g_first_msg = 0; + SET_TIMER_EXPIRATION(30); + } - xdk360_console_draw(); + xdk360_console_draw(); } if(!vid->block_swap) - D3DDevice_Present(vid->xdk360_render_device); + D3DDevice_Present(vid->xdk360_render_device); return true; } static void xdk360_set_swap_block_swap (void * data, bool toggle) { - (void)data; - xdk360_video_t *vid = (xdk360_video_t*)g_d3d; - vid->block_swap = toggle; + (void)data; + xdk360_video_t *vid = (xdk360_video_t*)g_d3d; + vid->block_swap = toggle; - if(toggle) - SSNES_LOG("Swap is set to blocked.\n"); - else - SSNES_LOG("Swap is set to non-blocked.\n"); + if(toggle) + SSNES_LOG("Swap is set to blocked.\n"); + else + SSNES_LOG("Swap is set to non-blocked.\n"); } static void xdk360_swap (void * data) { - (void)data; - xdk360_video_t *vid = (xdk360_video_t*)g_d3d; - D3DDevice_Present(vid->xdk360_render_device); + (void)data; + xdk360_video_t *vid = (xdk360_video_t*)g_d3d; + D3DDevice_Present(vid->xdk360_render_device); } static void xdk360_gfx_set_nonblock_state(void *data, bool state) @@ -641,9 +645,9 @@ static void xdk360_gfx_set_nonblock_state(void *data, bool state) xdk360_video_t *vid = (xdk360_video_t*)data; SSNES_LOG("D3D Vsync => %s\n", state ? "off" : "on"); if(state) - D3DDevice_SetRenderState_PresentInterval(vid->xdk360_render_device, D3DPRESENT_INTERVAL_IMMEDIATE); + D3DDevice_SetRenderState_PresentInterval(vid->xdk360_render_device, D3DPRESENT_INTERVAL_IMMEDIATE); else - D3DDevice_SetRenderState_PresentInterval(vid->xdk360_render_device, D3DPRESENT_INTERVAL_ONE); + D3DDevice_SetRenderState_PresentInterval(vid->xdk360_render_device, D3DPRESENT_INTERVAL_ONE); } static bool xdk360_gfx_alive(void *data) @@ -660,7 +664,7 @@ static bool xdk360_gfx_focus(void *data) void xdk360_video_set_vsync(bool vsync) { - xdk360_gfx_set_nonblock_state(g_d3d, vsync); + xdk360_gfx_set_nonblock_state(g_d3d, vsync); } // 360 needs a working graphics stack before SSNESeven starts. @@ -670,31 +674,32 @@ void xdk360_video_set_vsync(bool vsync) // When SSNES wants to free it, it is ignored. void xdk360_video_init(void) { - video_info_t video_info = {0}; - // Might have to supply correct values here. - video_info.vsync = g_settings.video.vsync; - video_info.force_aspect = false; - video_info.smooth = g_settings.video.smooth; - video_info.input_scale = 2; + video_info_t video_info = {0}; - g_d3d = xdk360_gfx_init(&video_info, NULL, NULL); + video_info.vsync = g_settings.video.vsync; + video_info.force_aspect = false; + video_info.smooth = g_settings.video.smooth; + video_info.input_scale = 2; - g_first_msg = true; + g_d3d = xdk360_gfx_init(&video_info, NULL, NULL); - HRESULT hr = xdk360_console_init("game:\\media\\Arial_12.xpr", - 0xff000000, 0xffffffff ); - if(FAILED(hr)) - { - SSNES_ERR("Couldn't create debug console.\n"); - } + g_first_msg = true; + + HRESULT hr = xdk360_console_init("game:\\media\\Arial_12.xpr", + 0xff000000, 0xffffffff ); + + if(FAILED(hr)) + { + SSNES_ERR("Couldn't create debug console.\n"); + } } void xdk360_video_deinit(void) { - void *data = g_d3d; - g_d3d = NULL; - xdk360_console_deinit(); - xdk360_gfx_free(data); + void *data = g_d3d; + g_d3d = NULL; + xdk360_console_deinit(); + xdk360_gfx_free(data); } const video_driver_t video_xdk360 = { diff --git a/console/fileio/file_browser.c b/console/fileio/file_browser.c index be0e133d48..ba572620ee 100644 --- a/console/fileio/file_browser.c +++ b/console/fileio/file_browser.c @@ -71,57 +71,58 @@ const char * path, const char * extensions) if (strlcpy(path_buf, path, sizeof(path_buf)) >= sizeof(path_buf)) { - error = 1; + error = 1; goto error; } if (strlcat(path_buf, "\\*", sizeof(path_buf)) >= sizeof(path_buf)) { - error = 1; + error = 1; goto error; } hFind = FindFirstFile(path_buf, &ffd); if (hFind == INVALID_HANDLE_VALUE) { - error = 1; + error = 1; goto error; } do { - strcpy(filebrowser->dir[filebrowser->directory_stack_size], path); - bool found_dir = false; - if(!(ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) - { - char tmp_extensions[512]; - strncpy(tmp_extensions, extensions, sizeof(tmp_extensions)); - const char * current_extension = filebrowser_get_extension(ffd.cFileName); - bool found_rom = false; + strcpy(filebrowser->dir[filebrowser->directory_stack_size], path); + bool found_dir = false; - if(current_extension) - { - char * pch = strtok(tmp_extensions, "|"); - while (pch != NULL) - { - if(strcmp(current_extension, pch) == 0) - { - found_rom = true; - break; - } - pch = strtok(NULL, "|"); - } - } + if(!(ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) + { + char tmp_extensions[512]; + strncpy(tmp_extensions, extensions, sizeof(tmp_extensions)); + const char * current_extension = filebrowser_get_extension(ffd.cFileName); + bool found_rom = false; - if(!found_rom) - continue; - } - else if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) - found_dir = true; + if(current_extension) + { + char * pch = strtok(tmp_extensions, "|"); + while (pch != NULL) + { + if(strcmp(current_extension, pch) == 0) + { + found_rom = true; + break; + } + pch = strtok(NULL, "|"); + } + } - filebrowser->cur[filebrowser->file_count].d_type = found_dir ? FILE_ATTRIBUTE_DIRECTORY : FILE_ATTRIBUTE_NORMAL; + if(!found_rom) + continue; + } + else if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) + found_dir = true; + + filebrowser->cur[filebrowser->file_count].d_type = found_dir ? FILE_ATTRIBUTE_DIRECTORY : FILE_ATTRIBUTE_NORMAL; sprintf(filebrowser->cur[filebrowser->file_count].d_name, ffd.cFileName); - filebrowser->file_count++; + filebrowser->file_count++; }while (FindNextFile(hFind, &ffd) != 0 && (filebrowser->file_count + 1) < MAX_FILE_LIMIT); #elif defined(__CELLOS_LV2__) int fd; @@ -203,7 +204,7 @@ const char * path, const char * extensions) error: if(error) { - SSNES_ERR("Failed to open directory: \"%s\"\n", path); + SSNES_ERR("Failed to open directory: \"%s\"\n", path); } #ifdef _XBOX FindClose(hFind); diff --git a/console/logger/logger.c b/console/logger/logger.c index 70e438c3f6..7aabc32f45 100644 --- a/console/logger/logger.c +++ b/console/logger/logger.c @@ -56,83 +56,85 @@ static char sendbuf[4096]; static int inet_pton(int af, const char *src, void *dst) { - if (af != AF_INET) - return -1; - return inet_aton (src, dst); + if (af != AF_INET) + return -1; + + return inet_aton (src, dst); } #endif static int if_up_with(int index) { - (void)index; + (void)index; #ifdef __CELLOS_LV2__ - int timeout_count = 10; - int state; - int ret; + int timeout_count = 10; + int state; + int ret; - ret = cellNetCtlInit(); - if (ret < 0) - { - printf("cellNetCtlInit() failed(%x)\n", ret); - return (-1); - } + ret = cellNetCtlInit(); + if (ret < 0) + { + printf("cellNetCtlInit() failed(%x)\n", ret); + return (-1); + } - for (;;) - { - ret = cellNetCtlGetState(&state); - if (ret < 0) - { - printf("cellNetCtlGetState() failed(%x)\n", ret); - return (-1); - } - if (state == CELL_NET_CTL_STATE_IPObtained) - break; - sys_timer_usleep(500 * 1000); - timeout_count--; - if (index && timeout_count < 0) - { - printf("if_up_with(%d) timeout\n", index); - return (0); - } - } + for (;;) + { + ret = cellNetCtlGetState(&state); + if (ret < 0) + { + printf("cellNetCtlGetState() failed(%x)\n", ret); + return (-1); + } + if (state == CELL_NET_CTL_STATE_IPObtained) + break; + + sys_timer_usleep(500 * 1000); + timeout_count--; + if (index && timeout_count < 0) + { + printf("if_up_with(%d) timeout\n", index); + return (0); + } + } #endif - sock=socket(AF_INET,SOCK_DGRAM ,0); + sock=socket(AF_INET,SOCK_DGRAM ,0); - target.sin_family = AF_INET; - target.sin_port = htons(PC_DEVELOPMENT_UDP_PORT); - inet_pton(AF_INET, PC_DEVELOPMENT_IP_ADDRESS, &target.sin_addr); + target.sin_family = AF_INET; + target.sin_port = htons(PC_DEVELOPMENT_UDP_PORT); + inet_pton(AF_INET, PC_DEVELOPMENT_IP_ADDRESS, &target.sin_addr); - return (0); + return (0); } static int if_down(int sid) { - (void)sid; + (void)sid; #ifdef __CELLOS_LV2__ - cellNetCtlTerm(); + cellNetCtlTerm(); #endif - return (0); + return (0); } void logger_init (void) { - g_sid = if_up_with(1); + g_sid = if_up_with(1); } void logger_shutdown (void) { - if_down(g_sid); + if_down(g_sid); } void logger_send(const char *__format,...) { - va_list args; + va_list args; - va_start(args,__format); - vsnprintf(sendbuf,4000,__format, args); - va_end(args); + va_start(args,__format); + vsnprintf(sendbuf,4000,__format, args); + va_end(args); - int len=strlen(sendbuf); - sendto(sock,sendbuf,len,MSG_DONTWAIT,(struct sockaddr*)&target,sizeof(target)); + int len=strlen(sendbuf); + sendto(sock,sendbuf,len,MSG_DONTWAIT,(struct sockaddr*)&target,sizeof(target)); } diff --git a/ps3/image.c b/ps3/image.c index 496d46c3ec..05f53d2897 100644 --- a/ps3/image.c +++ b/ps3/image.c @@ -33,29 +33,29 @@ typedef struct CtrlMallocArg { - uint32_t mallocCallCounts; + uint32_t mallocCallCounts; } CtrlMallocArg; typedef struct CtrlFreeArg { - uint32_t freeCallCounts; + uint32_t freeCallCounts; } CtrlFreeArg; void *img_malloc(uint32_t size, void * a) { - CtrlMallocArg *arg; - arg = (CtrlMallocArg *) a; - arg->mallocCallCounts++; - return malloc(size); + CtrlMallocArg *arg; + arg = (CtrlMallocArg *) a; + arg->mallocCallCounts++; + return malloc(size); } static int img_free(void *ptr, void * a) { - CtrlFreeArg *arg; - arg = (CtrlFreeArg *) a; - arg->freeCallCounts++; - free(ptr); - return 0; + CtrlFreeArg *arg; + arg = (CtrlFreeArg *) a; + arg->freeCallCounts++; + free(ptr); + return 0; } /******************************************************************************* @@ -64,88 +64,88 @@ static int img_free(void *ptr, void * a) static bool ps3graphics_load_jpeg(const char * path, struct texture_image *out_img) { - CtrlMallocArg MallocArg; - CtrlFreeArg FreeArg; - CellJpgDecMainHandle mHandle = NULL; - CellJpgDecSubHandle sHandle = NULL; - CellJpgDecThreadInParam InParam; - CellJpgDecThreadOutParam OutParam; - CellJpgDecSrc src; - CellJpgDecOpnInfo opnInfo; - CellJpgDecInfo info; - CellJpgDecInParam inParam; - CellJpgDecOutParam outParam; - CellJpgDecDataOutInfo dOutInfo; - CellJpgDecDataCtrlParam dCtrlParam; + CtrlMallocArg MallocArg; + CtrlFreeArg FreeArg; + CellJpgDecMainHandle mHandle = NULL; + CellJpgDecSubHandle sHandle = NULL; + CellJpgDecThreadInParam InParam; + CellJpgDecThreadOutParam OutParam; + CellJpgDecSrc src; + CellJpgDecOpnInfo opnInfo; + CellJpgDecInfo info; + CellJpgDecInParam inParam; + CellJpgDecOutParam outParam; + CellJpgDecDataOutInfo dOutInfo; + CellJpgDecDataCtrlParam dCtrlParam; - MallocArg.mallocCallCounts = 0; - FreeArg.freeCallCounts = 0; - InParam.spuThreadEnable = CELL_JPGDEC_SPU_THREAD_ENABLE; - InParam.ppuThreadPriority = 1001; - InParam.spuThreadPriority = 250; - InParam.cbCtrlMallocFunc = img_malloc; - InParam.cbCtrlMallocArg = &MallocArg; - InParam.cbCtrlFreeFunc = img_free; - InParam.cbCtrlFreeArg = &FreeArg; + MallocArg.mallocCallCounts = 0; + FreeArg.freeCallCounts = 0; + InParam.spuThreadEnable = CELL_JPGDEC_SPU_THREAD_ENABLE; + InParam.ppuThreadPriority = 1001; + InParam.spuThreadPriority = 250; + InParam.cbCtrlMallocFunc = img_malloc; + InParam.cbCtrlMallocArg = &MallocArg; + InParam.cbCtrlFreeFunc = img_free; + InParam.cbCtrlFreeArg = &FreeArg; - int ret_jpeg, ret = -1; - ret_jpeg = cellJpgDecCreate(&mHandle, &InParam, &OutParam); + int ret_jpeg, ret = -1; + ret_jpeg = cellJpgDecCreate(&mHandle, &InParam, &OutParam); - if (ret_jpeg != CELL_OK) - goto error; + if (ret_jpeg != CELL_OK) + goto error; - memset(&src, 0, sizeof(CellJpgDecSrc)); - src.srcSelect = CELL_JPGDEC_FILE; - src.fileName = path; - src.fileOffset = 0; - src.fileSize = 0; - src.streamPtr = NULL; - src.streamSize = 0; + memset(&src, 0, sizeof(CellJpgDecSrc)); + src.srcSelect = CELL_JPGDEC_FILE; + src.fileName = path; + src.fileOffset = 0; + src.fileSize = 0; + src.streamPtr = NULL; + src.streamSize = 0; - src.spuThreadEnable = CELL_JPGDEC_SPU_THREAD_ENABLE; + src.spuThreadEnable = CELL_JPGDEC_SPU_THREAD_ENABLE; - ret = cellJpgDecOpen(mHandle, &sHandle, &src, &opnInfo); + ret = cellJpgDecOpen(mHandle, &sHandle, &src, &opnInfo); - if (ret != CELL_OK) - goto error; + if (ret != CELL_OK) + goto error; - ret = cellJpgDecReadHeader(mHandle, sHandle, &info); + ret = cellJpgDecReadHeader(mHandle, sHandle, &info); - if (ret != CELL_OK) - goto error; + if (ret != CELL_OK) + goto error; - inParam.commandPtr = NULL; - inParam.method = CELL_JPGDEC_FAST; - inParam.outputMode = CELL_JPGDEC_TOP_TO_BOTTOM; - inParam.outputColorSpace = CELL_JPG_ARGB; - inParam.downScale = 1; - inParam.outputColorAlpha = 0xfe; - ret = cellJpgDecSetParameter(mHandle, sHandle, &inParam, &outParam); + inParam.commandPtr = NULL; + inParam.method = CELL_JPGDEC_FAST; + inParam.outputMode = CELL_JPGDEC_TOP_TO_BOTTOM; + inParam.outputColorSpace = CELL_JPG_ARGB; + inParam.downScale = 1; + inParam.outputColorAlpha = 0xfe; + ret = cellJpgDecSetParameter(mHandle, sHandle, &inParam, &outParam); - if (ret != CELL_OK) - goto error; + if (ret != CELL_OK) + goto error; - dCtrlParam.outputBytesPerLine = outParam.outputWidth * 4; - ret = cellJpgDecDecodeData(mHandle, sHandle, (uint8_t*)out_img->pixels, &dCtrlParam, &dOutInfo); + dCtrlParam.outputBytesPerLine = outParam.outputWidth * 4; + ret = cellJpgDecDecodeData(mHandle, sHandle, (uint8_t*)out_img->pixels, &dCtrlParam, &dOutInfo); - if (ret != CELL_OK || dOutInfo.status != CELL_JPGDEC_DEC_STATUS_FINISH) - goto error; + if (ret != CELL_OK || dOutInfo.status != CELL_JPGDEC_DEC_STATUS_FINISH) + goto error; - out_img->width = outParam.outputWidth; - out_img->height = outParam.outputHeight; + out_img->width = outParam.outputWidth; + out_img->height = outParam.outputHeight; - cellJpgDecClose(mHandle, sHandle); - cellJpgDecDestroy(mHandle); + cellJpgDecClose(mHandle, sHandle); + cellJpgDecDestroy(mHandle); - return true; + return true; error: - SSNES_ERR("ps3graphics_load_jpeg(): error.\n"); - if (mHandle && sHandle) - cellJpgDecClose(mHandle, sHandle); - if (mHandle) - cellJpgDecDestroy(mHandle); - return false; + SSNES_ERR("ps3graphics_load_jpeg(): error.\n"); + if (mHandle && sHandle) + cellJpgDecClose(mHandle, sHandle); + if (mHandle) + cellJpgDecDestroy(mHandle); + return false; } /******************************************************************************* @@ -154,113 +154,113 @@ error: static bool ps3graphics_load_png(const char * path, struct texture_image *out_img) { - CtrlMallocArg MallocArg; - CtrlFreeArg FreeArg; - CellPngDecMainHandle mHandle = NULL; - CellPngDecSubHandle sHandle = NULL; - CellPngDecThreadInParam InParam; - CellPngDecThreadOutParam OutParam; - CellPngDecSrc src; - CellPngDecOpnInfo opnInfo; - CellPngDecInfo info; - CellPngDecInParam inParam; - CellPngDecOutParam outParam; - CellPngDecDataOutInfo dOutInfo; - CellPngDecDataCtrlParam dCtrlParam; + CtrlMallocArg MallocArg; + CtrlFreeArg FreeArg; + CellPngDecMainHandle mHandle = NULL; + CellPngDecSubHandle sHandle = NULL; + CellPngDecThreadInParam InParam; + CellPngDecThreadOutParam OutParam; + CellPngDecSrc src; + CellPngDecOpnInfo opnInfo; + CellPngDecInfo info; + CellPngDecInParam inParam; + CellPngDecOutParam outParam; + CellPngDecDataOutInfo dOutInfo; + CellPngDecDataCtrlParam dCtrlParam; - MallocArg.mallocCallCounts = 0; - FreeArg.freeCallCounts = 0; - InParam.spuThreadEnable = CELL_PNGDEC_SPU_THREAD_ENABLE; - InParam.ppuThreadPriority = 512; - InParam.spuThreadPriority = 200; - InParam.cbCtrlMallocFunc = img_malloc; - InParam.cbCtrlMallocArg = &MallocArg; - InParam.cbCtrlFreeFunc = img_free; - InParam.cbCtrlFreeArg = &FreeArg; + MallocArg.mallocCallCounts = 0; + FreeArg.freeCallCounts = 0; + InParam.spuThreadEnable = CELL_PNGDEC_SPU_THREAD_ENABLE; + InParam.ppuThreadPriority = 512; + InParam.spuThreadPriority = 200; + InParam.cbCtrlMallocFunc = img_malloc; + InParam.cbCtrlMallocArg = &MallocArg; + InParam.cbCtrlFreeFunc = img_free; + InParam.cbCtrlFreeArg = &FreeArg; - int ret_png, ret = -1; - ret_png = cellPngDecCreate(&mHandle, &InParam, &OutParam); + int ret_png, ret = -1; + ret_png = cellPngDecCreate(&mHandle, &InParam, &OutParam); - if (ret_png != CELL_OK) - goto error; + if (ret_png != CELL_OK) + goto error; - memset(&src, 0, sizeof(CellPngDecSrc)); - src.srcSelect = CELL_PNGDEC_FILE; - src.fileName = path; - src.fileOffset = 0; - src.fileSize = 0; - src.streamPtr = 0; - src.streamSize = 0; + memset(&src, 0, sizeof(CellPngDecSrc)); + src.srcSelect = CELL_PNGDEC_FILE; + src.fileName = path; + src.fileOffset = 0; + src.fileSize = 0; + src.streamPtr = 0; + src.streamSize = 0; - src.spuThreadEnable = CELL_PNGDEC_SPU_THREAD_ENABLE; + src.spuThreadEnable = CELL_PNGDEC_SPU_THREAD_ENABLE; - ret = cellPngDecOpen(mHandle, &sHandle, &src, &opnInfo); + ret = cellPngDecOpen(mHandle, &sHandle, &src, &opnInfo); + + if (ret != CELL_OK) + goto error; + + ret = cellPngDecReadHeader(mHandle, sHandle, &info); + + if (ret != CELL_OK) + goto error; + + inParam.commandPtr = NULL; + inParam.outputMode = CELL_PNGDEC_TOP_TO_BOTTOM; + inParam.outputColorSpace = CELL_PNGDEC_ARGB; + inParam.outputBitDepth = 8; + inParam.outputPackFlag = CELL_PNGDEC_1BYTE_PER_1PIXEL; + inParam.outputAlphaSelect = CELL_PNGDEC_STREAM_ALPHA; + ret = cellPngDecSetParameter(mHandle, sHandle, &inParam, &outParam); + + if (ret != CELL_OK) + goto error; + + dCtrlParam.outputBytesPerLine = outParam.outputWidth * 4; + ret = cellPngDecDecodeData(mHandle, sHandle, (uint8_t*)out_img->pixels, &dCtrlParam, &dOutInfo); - if (ret != CELL_OK) - goto error; + if (ret != CELL_OK || dOutInfo.status != CELL_PNGDEC_DEC_STATUS_FINISH) + goto error; - ret = cellPngDecReadHeader(mHandle, sHandle, &info); + out_img->width = outParam.outputWidth; + out_img->height = outParam.outputHeight; + cellPngDecClose(mHandle, sHandle); + cellPngDecDestroy(mHandle); - if (ret != CELL_OK) - goto error; - - inParam.commandPtr = NULL; - inParam.outputMode = CELL_PNGDEC_TOP_TO_BOTTOM; - inParam.outputColorSpace = CELL_PNGDEC_ARGB; - inParam.outputBitDepth = 8; - inParam.outputPackFlag = CELL_PNGDEC_1BYTE_PER_1PIXEL; - inParam.outputAlphaSelect = CELL_PNGDEC_STREAM_ALPHA; - ret = cellPngDecSetParameter(mHandle, sHandle, &inParam, &outParam); - - if (ret != CELL_OK) - goto error; - - dCtrlParam.outputBytesPerLine = outParam.outputWidth * 4; - ret = cellPngDecDecodeData(mHandle, sHandle, (uint8_t*)out_img->pixels, &dCtrlParam, &dOutInfo); - - - if (ret != CELL_OK || dOutInfo.status != CELL_PNGDEC_DEC_STATUS_FINISH) - goto error; - - out_img->width = outParam.outputWidth; - out_img->height = outParam.outputHeight; - - cellPngDecClose(mHandle, sHandle); - cellPngDecDestroy(mHandle); - - return true; + return true; error: - SSNES_ERR("ps3graphics_load_png(): error.\n"); - if (mHandle && sHandle) - cellPngDecClose(mHandle, sHandle); - if (mHandle) - cellPngDecDestroy(mHandle); - return false; + SSNES_ERR("ps3graphics_load_png(): error.\n"); + + if (mHandle && sHandle) + cellPngDecClose(mHandle, sHandle); + if (mHandle) + cellPngDecDestroy(mHandle); + + return false; } bool texture_image_load(const char *path, struct texture_image *out_img) { - out_img->pixels = malloc(2048 * 2048 * 4); - memset(out_img->pixels, 0, (2048 * 2048 * 4)); - if(strstr(path, ".PNG") != NULL || strstr(path, ".png") != NULL) - { - if (!ps3graphics_load_png(path, out_img)) - { - free(out_img->pixels); - return false; - } - } - else - { - if (!ps3graphics_load_jpeg(path, out_img)) - { - free(out_img->pixels); - return false; - } - } + out_img->pixels = malloc(2048 * 2048 * 4); + memset(out_img->pixels, 0, (2048 * 2048 * 4)); + if(strstr(path, ".PNG") != NULL || strstr(path, ".png") != NULL) + { + if (!ps3graphics_load_png(path, out_img)) + { + free(out_img->pixels); + return false; + } + } + else + { + if (!ps3graphics_load_jpeg(path, out_img)) + { + free(out_img->pixels); + return false; + } + } - return true; + return true; } diff --git a/ps3/ps3_input.c b/ps3/ps3_input.c index bc223c516b..5a78db09a7 100644 --- a/ps3/ps3_input.c +++ b/ps3/ps3_input.c @@ -120,7 +120,7 @@ static int16_t ps3_input_state(void *data, const struct snes_keybind **binds, ON-SCREEN KEYBOARD UTILITY ============================================================ */ -#define OSK_IN_USE (0x00000001) +#define OSK_IN_USE 1 void oskutil_init(oskutil_params *params, unsigned int containersize) { @@ -265,27 +265,27 @@ void ps3_input_init(void) void ps3_input_map_dpad_to_stick(uint32_t map_dpad_enum, uint32_t controller_id) { - switch(map_dpad_enum) - { - case DPAD_EMULATION_NONE: - g_settings.input.binds[controller_id][RETRO_DEVICE_ID_JOYPAD_UP].joykey = ssnes_platform_keybind_lut[PS3_DEVICE_ID_JOYPAD_UP]; - g_settings.input.binds[controller_id][RETRO_DEVICE_ID_JOYPAD_DOWN].joykey = ssnes_platform_keybind_lut[PS3_DEVICE_ID_JOYPAD_DOWN]; - g_settings.input.binds[controller_id][RETRO_DEVICE_ID_JOYPAD_LEFT].joykey = ssnes_platform_keybind_lut[PS3_DEVICE_ID_JOYPAD_LEFT]; - g_settings.input.binds[controller_id][RETRO_DEVICE_ID_JOYPAD_RIGHT].joykey = ssnes_platform_keybind_lut[PS3_DEVICE_ID_JOYPAD_RIGHT]; - break; - case DPAD_EMULATION_LSTICK: - g_settings.input.binds[controller_id][RETRO_DEVICE_ID_JOYPAD_UP].joykey = ssnes_platform_keybind_lut[PS3_DEVICE_ID_LSTICK_UP_DPAD]; - g_settings.input.binds[controller_id][RETRO_DEVICE_ID_JOYPAD_DOWN].joykey = ssnes_platform_keybind_lut[PS3_DEVICE_ID_LSTICK_DOWN_DPAD]; - g_settings.input.binds[controller_id][RETRO_DEVICE_ID_JOYPAD_LEFT].joykey = ssnes_platform_keybind_lut[PS3_DEVICE_ID_LSTICK_LEFT_DPAD]; - g_settings.input.binds[controller_id][RETRO_DEVICE_ID_JOYPAD_RIGHT].joykey = ssnes_platform_keybind_lut[PS3_DEVICE_ID_LSTICK_RIGHT_DPAD]; - break; - case DPAD_EMULATION_RSTICK: - g_settings.input.binds[controller_id][RETRO_DEVICE_ID_JOYPAD_UP].joykey = ssnes_platform_keybind_lut[PS3_DEVICE_ID_RSTICK_UP_DPAD]; - g_settings.input.binds[controller_id][RETRO_DEVICE_ID_JOYPAD_DOWN].joykey = ssnes_platform_keybind_lut[PS3_DEVICE_ID_RSTICK_DOWN_DPAD]; - g_settings.input.binds[controller_id][RETRO_DEVICE_ID_JOYPAD_LEFT].joykey = ssnes_platform_keybind_lut[PS3_DEVICE_ID_RSTICK_LEFT_DPAD]; - g_settings.input.binds[controller_id][RETRO_DEVICE_ID_JOYPAD_RIGHT].joykey = ssnes_platform_keybind_lut[PS3_DEVICE_ID_RSTICK_RIGHT_DPAD]; - break; - } + switch(map_dpad_enum) + { + case DPAD_EMULATION_NONE: + g_settings.input.binds[controller_id][RETRO_DEVICE_ID_JOYPAD_UP].joykey = ssnes_platform_keybind_lut[PS3_DEVICE_ID_JOYPAD_UP]; + g_settings.input.binds[controller_id][RETRO_DEVICE_ID_JOYPAD_DOWN].joykey = ssnes_platform_keybind_lut[PS3_DEVICE_ID_JOYPAD_DOWN]; + g_settings.input.binds[controller_id][RETRO_DEVICE_ID_JOYPAD_LEFT].joykey = ssnes_platform_keybind_lut[PS3_DEVICE_ID_JOYPAD_LEFT]; + g_settings.input.binds[controller_id][RETRO_DEVICE_ID_JOYPAD_RIGHT].joykey = ssnes_platform_keybind_lut[PS3_DEVICE_ID_JOYPAD_RIGHT]; + break; + case DPAD_EMULATION_LSTICK: + g_settings.input.binds[controller_id][RETRO_DEVICE_ID_JOYPAD_UP].joykey = ssnes_platform_keybind_lut[PS3_DEVICE_ID_LSTICK_UP_DPAD]; + g_settings.input.binds[controller_id][RETRO_DEVICE_ID_JOYPAD_DOWN].joykey = ssnes_platform_keybind_lut[PS3_DEVICE_ID_LSTICK_DOWN_DPAD]; + g_settings.input.binds[controller_id][RETRO_DEVICE_ID_JOYPAD_LEFT].joykey = ssnes_platform_keybind_lut[PS3_DEVICE_ID_LSTICK_LEFT_DPAD]; + g_settings.input.binds[controller_id][RETRO_DEVICE_ID_JOYPAD_RIGHT].joykey = ssnes_platform_keybind_lut[PS3_DEVICE_ID_LSTICK_RIGHT_DPAD]; + break; + case DPAD_EMULATION_RSTICK: + g_settings.input.binds[controller_id][RETRO_DEVICE_ID_JOYPAD_UP].joykey = ssnes_platform_keybind_lut[PS3_DEVICE_ID_RSTICK_UP_DPAD]; + g_settings.input.binds[controller_id][RETRO_DEVICE_ID_JOYPAD_DOWN].joykey = ssnes_platform_keybind_lut[PS3_DEVICE_ID_RSTICK_DOWN_DPAD]; + g_settings.input.binds[controller_id][RETRO_DEVICE_ID_JOYPAD_LEFT].joykey = ssnes_platform_keybind_lut[PS3_DEVICE_ID_RSTICK_LEFT_DPAD]; + g_settings.input.binds[controller_id][RETRO_DEVICE_ID_JOYPAD_RIGHT].joykey = ssnes_platform_keybind_lut[PS3_DEVICE_ID_RSTICK_RIGHT_DPAD]; + break; + } } static bool ps3_key_pressed(void *data, int key) @@ -316,21 +316,21 @@ static bool ps3_key_pressed(void *data, int key) case SSNES_QUIT_KEY: if(IS_TIMER_EXPIRED(g_console.timer_expiration_frame_count)) { - uint32_t r3_pressed = CTRL_R3(state[0]); - uint32_t l3_pressed = CTRL_L3(state[0]); - bool retval = false; - g_console.menu_enable = (r3_pressed && l3_pressed && IS_TIMER_EXPIRED(g_console.timer_expiration_frame_count)); - g_console.ingame_menu_enable = r3_pressed && !l3_pressed; + uint32_t r3_pressed = CTRL_R3(state[0]); + uint32_t l3_pressed = CTRL_L3(state[0]); + bool retval = false; + g_console.menu_enable = (r3_pressed && l3_pressed && IS_TIMER_EXPIRED(g_console.timer_expiration_frame_count)); + g_console.ingame_menu_enable = r3_pressed && !l3_pressed; - if(g_console.menu_enable || (g_console.ingame_menu_enable && !g_console.menu_enable)) - { - g_console.mode_switch = MODE_MENU; - SET_TIMER_EXPIRATION(g_console.control_timer_expiration_frame_count, 30); - retval = g_console.menu_enable; - } + if(g_console.menu_enable || (g_console.ingame_menu_enable && !g_console.menu_enable)) + { + g_console.mode_switch = MODE_MENU; + SET_TIMER_EXPIRATION(g_console.control_timer_expiration_frame_count, 30); + retval = g_console.menu_enable; + } - retval = g_console.ingame_menu_enable ? g_console.ingame_menu_enable : g_console.menu_enable; - return retval; + retval = g_console.ingame_menu_enable ? g_console.ingame_menu_enable : g_console.menu_enable; + return retval; } default: return false; diff --git a/ps3/ps3_input.h b/ps3/ps3_input.h index e61996f654..272d3c644e 100644 --- a/ps3/ps3_input.h +++ b/ps3/ps3_input.h @@ -133,19 +133,19 @@ void ps3_input_map_dpad_to_stick(uint32_t map_dpad_enum, uint32_t controller_id) typedef struct { - unsigned int osk_memorycontainer; - wchar_t init_message[CELL_OSKDIALOG_STRING_SIZE + 1]; - wchar_t message[CELL_OSKDIALOG_STRING_SIZE + 1]; - wchar_t osk_text_buffer[CELL_OSKDIALOG_STRING_SIZE + 1]; - char osk_text_buffer_char[CELL_OSKDIALOG_STRING_SIZE + 1]; - uint32_t flags; - bool is_running; - bool text_can_be_fetched; - sys_memory_container_t containerid; - CellOskDialogPoint pos; - CellOskDialogInputFieldInfo inputFieldInfo; - CellOskDialogCallbackReturnParam outputInfo; - CellOskDialogParam dialogParam; + unsigned int osk_memorycontainer; + wchar_t init_message[CELL_OSKDIALOG_STRING_SIZE + 1]; + wchar_t message[CELL_OSKDIALOG_STRING_SIZE + 1]; + wchar_t osk_text_buffer[CELL_OSKDIALOG_STRING_SIZE + 1]; + char osk_text_buffer_char[CELL_OSKDIALOG_STRING_SIZE + 1]; + uint32_t flags; + bool is_running; + bool text_can_be_fetched; + sys_memory_container_t containerid; + CellOskDialogPoint pos; + CellOskDialogInputFieldInfo inputFieldInfo; + CellOskDialogCallbackReturnParam outputInfo; + CellOskDialogParam dialogParam; } oskutil_params; void oskutil_write_message(oskutil_params *params, const wchar_t* msg); diff --git a/ps3/ps3_video_psgl.c b/ps3/ps3_video_psgl.c index 060d0c0493..e8de603513 100644 --- a/ps3/ps3_video_psgl.c +++ b/ps3/ps3_video_psgl.c @@ -108,378 +108,361 @@ void *g_gl; static bool gl_shader_init(void) { - switch (g_settings.video.shader_type) - { - case SSNES_SHADER_AUTO: - if (strlen(g_settings.video.cg_shader_path) > 0 && strlen(g_settings.video.bsnes_shader_path) > 0) - SSNES_WARN("Both Cg and bSNES XML shader are defined in config file. Cg shader will be selected by default.\n"); - // fall-through - case SSNES_SHADER_CG: - if (strlen(g_settings.video.cg_shader_path) > 0) - return gl_cg_init(g_settings.video.cg_shader_path); - break; - default: - break; - } + switch (g_settings.video.shader_type) + { + case SSNES_SHADER_AUTO: + if (strlen(g_settings.video.cg_shader_path) > 0 && strlen(g_settings.video.bsnes_shader_path) > 0) + SSNES_WARN("Both Cg and bSNES XML shader are defined in config file. Cg shader will be selected by default.\n"); + // fall-through + case SSNES_SHADER_CG: + if (strlen(g_settings.video.cg_shader_path) > 0) + return gl_cg_init(g_settings.video.cg_shader_path); + break; + default: + break; + } - return true; + return true; } static unsigned gl_shader_num(void) { - unsigned num = 0; - unsigned cg_num = gl_cg_num(); - if (cg_num > num) - num = cg_num; + unsigned num = 0; + unsigned cg_num = gl_cg_num(); - return num; + if (cg_num > num) + num = cg_num; + + return num; } static bool gl_shader_filter_type(unsigned index, bool *smooth) { - bool valid = false; - if (!valid) - valid = gl_cg_filter_type(index, smooth); + bool valid = false; + if (!valid) + valid = gl_cg_filter_type(index, smooth); - return valid; + return valid; } static void gl_shader_scale(unsigned index, struct gl_fbo_scale *scale) { - scale->valid = false; - if (!scale->valid) - gl_cg_shader_scale(index, scale); + scale->valid = false; + if (!scale->valid) + gl_cg_shader_scale(index, scale); } static void gl_create_fbo_textures(gl_t *gl) { - glGenTextures(gl->fbo_pass, gl->fbo_texture); + glGenTextures(gl->fbo_pass, gl->fbo_texture); - GLuint base_filt = g_settings.video.second_pass_smooth ? GL_LINEAR : GL_NEAREST; - for (int i = 0; i < gl->fbo_pass; i++) - { - glBindTexture(GL_TEXTURE_2D, gl->fbo_texture[i]); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); + GLuint base_filt = g_settings.video.second_pass_smooth ? GL_LINEAR : GL_NEAREST; + for (int i = 0; i < gl->fbo_pass; i++) + { + glBindTexture(GL_TEXTURE_2D, gl->fbo_texture[i]); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); - GLuint filter_type = base_filt; - bool smooth = false; - if (gl_shader_filter_type(i + 2, &smooth)) - filter_type = smooth ? GL_LINEAR : GL_NEAREST; + GLuint filter_type = base_filt; + bool smooth = false; + if (gl_shader_filter_type(i + 2, &smooth)) + filter_type = smooth ? GL_LINEAR : GL_NEAREST; - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter_type); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter_type); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter_type); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter_type); - glTexImage2D(GL_TEXTURE_2D, - 0, GL_ARGB_SCE, gl->fbo_rect[i].width, gl->fbo_rect[i].height, 0, GL_ARGB_SCE, - GL_UNSIGNED_INT_8_8_8_8, NULL); - } + glTexImage2D(GL_TEXTURE_2D, + 0, GL_ARGB_SCE, gl->fbo_rect[i].width, gl->fbo_rect[i].height, 0, GL_ARGB_SCE, + GL_UNSIGNED_INT_8_8_8_8, NULL); + } - glBindTexture(GL_TEXTURE_2D, 0); + glBindTexture(GL_TEXTURE_2D, 0); } void gl_deinit_fbo(gl_t *gl) { - if (gl->fbo_inited) - { - glDeleteTextures(gl->fbo_pass, gl->fbo_texture); - glDeleteFramebuffersOES(gl->fbo_pass, gl->fbo); - memset(gl->fbo_texture, 0, sizeof(gl->fbo_texture)); - memset(gl->fbo, 0, sizeof(gl->fbo)); - gl->fbo_inited = false; - gl->render_to_tex = false; - gl->fbo_pass = 0; - } + if (gl->fbo_inited) + { + glDeleteTextures(gl->fbo_pass, gl->fbo_texture); + glDeleteFramebuffersOES(gl->fbo_pass, gl->fbo); + memset(gl->fbo_texture, 0, sizeof(gl->fbo_texture)); + memset(gl->fbo, 0, sizeof(gl->fbo)); + gl->fbo_inited = false; + gl->render_to_tex = false; + gl->fbo_pass = 0; + } } // Horribly long and complex FBO init :D void gl_init_fbo(gl_t *gl, unsigned width, unsigned height) { - if (!g_settings.video.render_to_texture && gl_shader_num() == 0) - return; + if (!g_settings.video.render_to_texture && gl_shader_num() == 0) + return; - struct gl_fbo_scale scale, scale_last; - gl_shader_scale(1, &scale); - gl_shader_scale(gl_shader_num(), &scale_last); + struct gl_fbo_scale scale, scale_last; + gl_shader_scale(1, &scale); + gl_shader_scale(gl_shader_num(), &scale_last); - // No need to use FBOs. - if (gl_shader_num() == 1 && !scale.valid && !g_settings.video.render_to_texture) - return; + // No need to use FBOs. + if (gl_shader_num() == 1 && !scale.valid && !g_settings.video.render_to_texture) + return; - gl->fbo_pass = gl_shader_num() - 1; - if (scale_last.valid) - gl->fbo_pass++; + gl->fbo_pass = gl_shader_num() - 1; + if (scale_last.valid) + gl->fbo_pass++; - if (gl->fbo_pass <= 0) - gl->fbo_pass = 1; + if (gl->fbo_pass <= 0) + gl->fbo_pass = 1; - if (!scale.valid) - { - scale.scale_x = g_settings.video.fbo_scale_x; - scale.scale_y = g_settings.video.fbo_scale_y; - scale.type_x = scale.type_y = SSNES_SCALE_INPUT; - } + if (!scale.valid) + { + scale.scale_x = g_settings.video.fbo_scale_x; + scale.scale_y = g_settings.video.fbo_scale_y; + scale.type_x = scale.type_y = SSNES_SCALE_INPUT; + } - switch (scale.type_x) - { - case SSNES_SCALE_INPUT: - gl->fbo_rect[0].width = width * next_pow2(ceil(scale.scale_x)); - break; + switch (scale.type_x) + { + case SSNES_SCALE_INPUT: + gl->fbo_rect[0].width = width * next_pow2(ceil(scale.scale_x)); + break; + case SSNES_SCALE_ABSOLUTE: + gl->fbo_rect[0].width = next_pow2(scale.abs_x); + break; + case SSNES_SCALE_VIEWPORT: + gl->fbo_rect[0].width = next_pow2(gl->win_width); + break; + default: + break; + } - case SSNES_SCALE_ABSOLUTE: - gl->fbo_rect[0].width = next_pow2(scale.abs_x); - break; + switch (scale.type_y) + { + case SSNES_SCALE_INPUT: + gl->fbo_rect[0].height = height * next_pow2(ceil(scale.scale_y)); + break; + case SSNES_SCALE_ABSOLUTE: + gl->fbo_rect[0].height = next_pow2(scale.abs_y); + break; + case SSNES_SCALE_VIEWPORT: + gl->fbo_rect[0].height = next_pow2(gl->win_height); + break; + default: + break; + } - case SSNES_SCALE_VIEWPORT: - gl->fbo_rect[0].width = next_pow2(gl->win_width); - break; + unsigned last_width = gl->fbo_rect[0].width, last_height = gl->fbo_rect[0].height; + gl->fbo_scale[0] = scale; - default: - break; - } + SSNES_LOG("Creating FBO 0 @ %ux%u\n", gl->fbo_rect[0].width, gl->fbo_rect[0].height); - switch (scale.type_y) - { - case SSNES_SCALE_INPUT: - gl->fbo_rect[0].height = height * next_pow2(ceil(scale.scale_y)); - break; + for (int i = 1; i < gl->fbo_pass; i++) + { + gl_shader_scale(i + 1, &gl->fbo_scale[i]); + if (gl->fbo_scale[i].valid) + { + switch (gl->fbo_scale[i].type_x) + { + case SSNES_SCALE_INPUT: + gl->fbo_rect[i].width = last_width * next_pow2(ceil(gl->fbo_scale[i].scale_x)); + break; + case SSNES_SCALE_ABSOLUTE: + gl->fbo_rect[i].width = next_pow2(gl->fbo_scale[i].abs_x); + break; + case SSNES_SCALE_VIEWPORT: + gl->fbo_rect[i].width = next_pow2(gl->win_width); + break; + default: + break; + } - case SSNES_SCALE_ABSOLUTE: - gl->fbo_rect[0].height = next_pow2(scale.abs_y); - break; + switch (gl->fbo_scale[i].type_y) + { + case SSNES_SCALE_INPUT: + gl->fbo_rect[i].height = last_height * next_pow2(ceil(gl->fbo_scale[i].scale_y)); + break; + case SSNES_SCALE_ABSOLUTE: + gl->fbo_rect[i].height = next_pow2(gl->fbo_scale[i].abs_y); + break; + case SSNES_SCALE_VIEWPORT: + gl->fbo_rect[i].height = next_pow2(gl->win_height); + break; + default: + break; + } - case SSNES_SCALE_VIEWPORT: - gl->fbo_rect[0].height = next_pow2(gl->win_height); - break; + last_width = gl->fbo_rect[i].width; + last_height = gl->fbo_rect[i].height; + } + else + { + // Use previous values, essentially a 1x scale compared to last shader in chain. + gl->fbo_rect[i] = gl->fbo_rect[i - 1]; + gl->fbo_scale[i].scale_x = gl->fbo_scale[i].scale_y = 1.0; + gl->fbo_scale[i].type_x = gl->fbo_scale[i].type_y = SSNES_SCALE_INPUT; + } - default: - break; - } + SSNES_LOG("Creating FBO %d @ %ux%u\n", i, gl->fbo_rect[i].width, gl->fbo_rect[i].height); + } - unsigned last_width = gl->fbo_rect[0].width, last_height = gl->fbo_rect[0].height; - gl->fbo_scale[0] = scale; + gl_create_fbo_textures(gl); - SSNES_LOG("Creating FBO 0 @ %ux%u\n", gl->fbo_rect[0].width, gl->fbo_rect[0].height); + glGenFramebuffersOES(gl->fbo_pass, gl->fbo); + for (int i = 0; i < gl->fbo_pass; i++) + { + glBindFramebufferOES(GL_FRAMEBUFFER_OES, gl->fbo[i]); + glFramebufferTexture2DOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, gl->fbo_texture[i], 0); - for (int i = 1; i < gl->fbo_pass; i++) - { - gl_shader_scale(i + 1, &gl->fbo_scale[i]); - if (gl->fbo_scale[i].valid) - { - switch (gl->fbo_scale[i].type_x) - { - case SSNES_SCALE_INPUT: - gl->fbo_rect[i].width = last_width * next_pow2(ceil(gl->fbo_scale[i].scale_x)); - break; + GLenum status = glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES); + if (status != GL_FRAMEBUFFER_COMPLETE_OES) + goto error; + } - case SSNES_SCALE_ABSOLUTE: - gl->fbo_rect[i].width = next_pow2(gl->fbo_scale[i].abs_x); - break; - - case SSNES_SCALE_VIEWPORT: - gl->fbo_rect[i].width = next_pow2(gl->win_width); - break; - - default: - break; - } - - switch (gl->fbo_scale[i].type_y) - { - case SSNES_SCALE_INPUT: - gl->fbo_rect[i].height = last_height * next_pow2(ceil(gl->fbo_scale[i].scale_y)); - break; - - case SSNES_SCALE_ABSOLUTE: - gl->fbo_rect[i].height = next_pow2(gl->fbo_scale[i].abs_y); - break; - - case SSNES_SCALE_VIEWPORT: - gl->fbo_rect[i].height = next_pow2(gl->win_height); - break; - - default: - break; - } - - last_width = gl->fbo_rect[i].width; - last_height = gl->fbo_rect[i].height; - } - else - { - // Use previous values, essentially a 1x scale compared to last shader in chain. - gl->fbo_rect[i] = gl->fbo_rect[i - 1]; - gl->fbo_scale[i].scale_x = gl->fbo_scale[i].scale_y = 1.0; - gl->fbo_scale[i].type_x = gl->fbo_scale[i].type_y = SSNES_SCALE_INPUT; - } - - SSNES_LOG("Creating FBO %d @ %ux%u\n", i, gl->fbo_rect[i].width, gl->fbo_rect[i].height); - } - - gl_create_fbo_textures(gl); - - glGenFramebuffersOES(gl->fbo_pass, gl->fbo); - for (int i = 0; i < gl->fbo_pass; i++) - { - glBindFramebufferOES(GL_FRAMEBUFFER_OES, gl->fbo[i]); - glFramebufferTexture2DOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, gl->fbo_texture[i], 0); - - GLenum status = glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES); - if (status != GL_FRAMEBUFFER_COMPLETE_OES) - goto error; - } - - gl->fbo_inited = true; - glBindFramebufferOES(GL_FRAMEBUFFER_OES, 0); - return; + gl->fbo_inited = true; + glBindFramebufferOES(GL_FRAMEBUFFER_OES, 0); + return; error: - glDeleteTextures(gl->fbo_pass, gl->fbo_texture); - glDeleteFramebuffersOES(gl->fbo_pass, gl->fbo); - SSNES_ERR("Failed to set up frame buffer objects. Multi-pass shading will not work.\n"); + glDeleteTextures(gl->fbo_pass, gl->fbo_texture); + glDeleteFramebuffersOES(gl->fbo_pass, gl->fbo); + SSNES_ERR("Failed to set up frame buffer objects. Multi-pass shading will not work.\n"); } static inline void gl_compute_fbo_geometry(gl_t *gl, unsigned width, unsigned height, - unsigned vp_width, unsigned vp_height) +unsigned vp_width, unsigned vp_height) { - unsigned last_width = width; - unsigned last_height = height; - unsigned last_max_width = gl->tex_w; - unsigned last_max_height = gl->tex_h; - // Calculate viewports for FBOs. - for (int i = 0; i < gl->fbo_pass; i++) - { - switch (gl->fbo_scale[i].type_x) - { - case SSNES_SCALE_INPUT: - gl->fbo_rect[i].img_width = last_width * gl->fbo_scale[i].scale_x; - gl->fbo_rect[i].max_img_width = last_max_width * gl->fbo_scale[i].scale_x; - break; + unsigned last_width = width; + unsigned last_height = height; + unsigned last_max_width = gl->tex_w; + unsigned last_max_height = gl->tex_h; - case SSNES_SCALE_ABSOLUTE: - gl->fbo_rect[i].img_width = gl->fbo_rect[i].max_img_width = gl->fbo_scale[i].abs_x; - break; + // Calculate viewports for FBOs. + for (int i = 0; i < gl->fbo_pass; i++) + { + switch (gl->fbo_scale[i].type_x) + { + case SSNES_SCALE_INPUT: + gl->fbo_rect[i].img_width = last_width * gl->fbo_scale[i].scale_x; + gl->fbo_rect[i].max_img_width = last_max_width * gl->fbo_scale[i].scale_x; + break; + case SSNES_SCALE_ABSOLUTE: + gl->fbo_rect[i].img_width = gl->fbo_rect[i].max_img_width = gl->fbo_scale[i].abs_x; + break; + case SSNES_SCALE_VIEWPORT: + gl->fbo_rect[i].img_width = gl->fbo_rect[i].max_img_width = gl->fbo_scale[i].scale_x * gl->vp_out_width; + break; + default: + break; + } - case SSNES_SCALE_VIEWPORT: - gl->fbo_rect[i].img_width = gl->fbo_rect[i].max_img_width = gl->fbo_scale[i].scale_x * gl->vp_out_width; - break; + switch (gl->fbo_scale[i].type_y) + { + case SSNES_SCALE_INPUT: + gl->fbo_rect[i].img_height = last_height * gl->fbo_scale[i].scale_y; + gl->fbo_rect[i].max_img_height = last_max_height * gl->fbo_scale[i].scale_y; + break; + case SSNES_SCALE_ABSOLUTE: + gl->fbo_rect[i].img_height = gl->fbo_rect[i].max_img_height = gl->fbo_scale[i].abs_y; + break; + case SSNES_SCALE_VIEWPORT: + gl->fbo_rect[i].img_height = gl->fbo_rect[i].max_img_height = gl->fbo_scale[i].scale_y * gl->vp_out_height; + break; + default: + break; + } - default: - break; - } - - switch (gl->fbo_scale[i].type_y) - { - case SSNES_SCALE_INPUT: - gl->fbo_rect[i].img_height = last_height * gl->fbo_scale[i].scale_y; - gl->fbo_rect[i].max_img_height = last_max_height * gl->fbo_scale[i].scale_y; - break; - - case SSNES_SCALE_ABSOLUTE: - gl->fbo_rect[i].img_height = gl->fbo_rect[i].max_img_height = gl->fbo_scale[i].abs_y; - break; - - case SSNES_SCALE_VIEWPORT: - gl->fbo_rect[i].img_height = gl->fbo_rect[i].max_img_height = gl->fbo_scale[i].scale_y * gl->vp_out_height; - break; - - default: - break; - } - - last_width = gl->fbo_rect[i].img_width; - last_height = gl->fbo_rect[i].img_height; - last_max_width = gl->fbo_rect[i].max_img_width; - last_max_height = gl->fbo_rect[i].max_img_height; - } + last_width = gl->fbo_rect[i].img_width; + last_height = gl->fbo_rect[i].img_height; + last_max_width = gl->fbo_rect[i].max_img_width; + last_max_height = gl->fbo_rect[i].max_img_height; + } } static void set_viewport(gl_t *gl, unsigned width, unsigned height, bool force_full) { + uint32_t m_viewport_x_temp, m_viewport_y_temp, m_viewport_width_temp, m_viewport_height_temp; + GLfloat m_left, m_right, m_bottom, m_top, m_zNear, m_zFar; - uint32_t m_viewport_x_temp, m_viewport_y_temp, m_viewport_width_temp, m_viewport_height_temp; - GLfloat m_left, m_right, m_bottom, m_top, m_zNear, m_zFar; + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); + m_viewport_x_temp = 0; + m_viewport_y_temp = 0; + m_viewport_width_temp = width; + m_viewport_height_temp = height; - m_viewport_x_temp = 0; - m_viewport_y_temp = 0; - m_viewport_width_temp = width; - m_viewport_height_temp = height; + m_left = 0.0f; + m_right = 1.0f; + m_bottom = 0.0f; + m_top = 1.0f; + m_zNear = -1.0f; + m_zFar = 1.0f; - m_left = 0.0f; - m_right = 1.0f; - m_bottom = 0.0f; - m_top = 1.0f; - m_zNear = -1.0f; - m_zFar = 1.0f; + if (gl->keep_aspect && !force_full) + { + float desired_aspect = g_settings.video.aspect_ratio; + float device_aspect = (float)width / height; + float delta; - if (gl->keep_aspect && !force_full) - { - float desired_aspect = g_settings.video.aspect_ratio; - float device_aspect = (float)width / height; - float delta; + // If the aspect ratios of screen and desired aspect ratio are sufficiently equal (floating point stuff), + if(g_console.aspect_ratio_index == ASPECT_RATIO_CUSTOM) + { + delta = (desired_aspect / device_aspect - 1.0) / 2.0 + 0.5; + m_viewport_x_temp = g_console.custom_viewport_x; + m_viewport_y_temp = g_console.custom_viewport_y; + m_viewport_width_temp = g_console.custom_viewport_width; + m_viewport_height_temp = g_console.custom_viewport_height; + } + else if (device_aspect > desired_aspect) + { + delta = (desired_aspect / device_aspect - 1.0) / 2.0 + 0.5; + m_viewport_x_temp = (GLint)(width * (0.5 - delta)); + m_viewport_width_temp = (GLint)(2.0 * width * delta); + width = (unsigned)(2.0 * width * delta); + } + else + { + delta = (device_aspect / desired_aspect - 1.0) / 2.0 + 0.5; + m_viewport_y_temp = (GLint)(height * (0.5 - delta)); + m_viewport_height_temp = (GLint)(2.0 * height * delta); + height = (unsigned)(2.0 * height * delta); + } + } - // If the aspect ratios of screen and desired aspect ratio are sufficiently equal (floating point stuff), - if(g_console.aspect_ratio_index == ASPECT_RATIO_CUSTOM) - { - delta = (desired_aspect / device_aspect - 1.0) / 2.0 + 0.5; - m_viewport_x_temp = g_console.custom_viewport_x; - m_viewport_y_temp = g_console.custom_viewport_y; - m_viewport_width_temp = g_console.custom_viewport_width; - m_viewport_height_temp = g_console.custom_viewport_height; - } - else if (device_aspect > desired_aspect) - { - delta = (desired_aspect / device_aspect - 1.0) / 2.0 + 0.5; - m_viewport_x_temp = (GLint)(width * (0.5 - delta)); - m_viewport_width_temp = (GLint)(2.0 * width * delta); - width = (unsigned)(2.0 * width * delta); - } - else - { - delta = (device_aspect / desired_aspect - 1.0) / 2.0 + 0.5; - m_viewport_y_temp = (GLint)(height * (0.5 - delta)); - m_viewport_height_temp = (GLint)(2.0 * height * delta); - height = (unsigned)(2.0 * height * delta); - } - } + glViewport(m_viewport_x_temp, m_viewport_y_temp, m_viewport_width_temp, m_viewport_height_temp); - glViewport(m_viewport_x_temp, m_viewport_y_temp, m_viewport_width_temp, m_viewport_height_temp); + if(gl->overscan_enable && !force_full) + { + m_left = -gl->overscan_amount/2; + m_right = 1 + gl->overscan_amount/2; + m_bottom = -gl->overscan_amount/2; + } - if(gl->overscan_enable && !force_full) - { - m_left = -gl->overscan_amount/2; - m_right = 1 + gl->overscan_amount/2; - m_bottom = -gl->overscan_amount/2; - } + glOrthof(m_left, m_right, m_bottom, m_top, m_zNear, m_zFar); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); - glOrthof(m_left, m_right, m_bottom, m_top, m_zNear, m_zFar); - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); + if (prg[active_index].mvp) + cgGLSetStateMatrixParameter(prg[active_index].mvp, CG_GL_MODELVIEW_PROJECTION_MATRIX, CG_GL_MATRIX_IDENTITY); - if (prg[active_index].mvp) - cgGLSetStateMatrixParameter(prg[active_index].mvp, CG_GL_MODELVIEW_PROJECTION_MATRIX, CG_GL_MATRIX_IDENTITY); + gl->vp_width = width; + gl->vp_height = height; - gl->vp_width = width; - gl->vp_height = height; - - // Set last backbuffer viewport. - if (!force_full) - { - gl->vp_out_width = width; - gl->vp_out_height = height; - } + // Set last backbuffer viewport. + if (!force_full) + { + gl->vp_out_width = width; + gl->vp_out_height = height; + } } static void set_lut_texture_coords(const GLfloat *coords) { - // For texture images. - pglClientActiveTexture(GL_TEXTURE1); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - glTexCoordPointer(2, GL_FLOAT, 0, coords); - pglClientActiveTexture(GL_TEXTURE0); + // For texture images. + pglClientActiveTexture(GL_TEXTURE1); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + glTexCoordPointer(2, GL_FLOAT, 0, coords); + pglClientActiveTexture(GL_TEXTURE0); } #define set_texture_coords(coords, xamt, yamt) \ @@ -490,799 +473,798 @@ static void set_lut_texture_coords(const GLfloat *coords) void gl_frame_menu (void) { - gl_t *gl = g_gl; + gl_t *gl = g_gl; - g_frame_count++; + g_frame_count++; - if(!gl) - return; + if(!gl) + return; + gl_cg_use(SSNES_CG_MENU_SHADER_INDEX); - gl_cg_use(SSNES_CG_MENU_SHADER_INDEX); + gl_cg_set_params(gl->win_width, gl->win_height, gl->win_width, + gl->win_height, gl->win_width, gl->win_height, g_frame_count, + NULL, NULL, NULL, 0); - gl_cg_set_params(gl->win_width, gl->win_height, gl->win_width, - gl->win_height, gl->win_width, gl->win_height, g_frame_count, - NULL, NULL, NULL, 0); + set_viewport(gl, gl->win_width, gl->win_height, true); - set_viewport(gl, gl->win_width, gl->win_height, true); + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, gl->menu_texture_id); - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, gl->menu_texture_id); + glDrawArrays(GL_QUADS, 0, 4); - glDrawArrays(GL_QUADS, 0, 4); - - glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]); + glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]); } static void ps3graphics_set_orientation(void * data, uint32_t orientation) { - (void)data; - switch (orientation) - { - case ORIENTATION_NORMAL: - vertex_ptr = vertexes_flipped; - break; + (void)data; + switch (orientation) + { + case ORIENTATION_NORMAL: + vertex_ptr = vertexes_flipped; + break; + case ORIENTATION_VERTICAL: + vertex_ptr = vertexes_90; + break; + case ORIENTATION_FLIPPED: + vertex_ptr = vertexes_180; + break; + case ORIENTATION_FLIPPED_ROTATED: + vertex_ptr = vertexes_270; + break; + } - case ORIENTATION_VERTICAL: - vertex_ptr = vertexes_90; - break; - - case ORIENTATION_FLIPPED: - vertex_ptr = vertexes_180; - break; - - case ORIENTATION_FLIPPED_ROTATED: - vertex_ptr = vertexes_270; - break; - } - - glVertexPointer(2, GL_FLOAT, 0, vertex_ptr); + glVertexPointer(2, GL_FLOAT, 0, vertex_ptr); } static bool gl_frame(void *data, const void *frame, unsigned width, unsigned height, unsigned pitch, const char *msg) { - gl_t *gl = data; + gl_t *gl = data; - gl_cg_use(1); - g_frame_count++; + gl_cg_use(1); + g_frame_count++; - glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]); + glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]); - // Render to texture in first pass. - if (gl->fbo_inited) - { - gl_compute_fbo_geometry(gl, width, height, gl->vp_out_width, gl->vp_out_height); - glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]); - glBindFramebufferOES(GL_FRAMEBUFFER_OES, gl->fbo[0]); - gl->render_to_tex = true; - set_viewport(gl, gl->fbo_rect[0].img_width, gl->fbo_rect[0].img_height, true); - } + // Render to texture in first pass. + if (gl->fbo_inited) + { + gl_compute_fbo_geometry(gl, width, height, gl->vp_out_width, gl->vp_out_height); + glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]); + glBindFramebufferOES(GL_FRAMEBUFFER_OES, gl->fbo[0]); + gl->render_to_tex = true; + set_viewport(gl, gl->fbo_rect[0].img_width, gl->fbo_rect[0].img_height, true); + } - if ((width != gl->last_width[gl->tex_index] || height != gl->last_height[gl->tex_index]) && gl->empty_buf) // Res change. need to clear out texture. - { - gl->last_width[gl->tex_index] = width; - gl->last_height[gl->tex_index] = height; + if ((width != gl->last_width[gl->tex_index] || height != gl->last_height[gl->tex_index]) && gl->empty_buf) // Res change. need to clear out texture. + { + gl->last_width[gl->tex_index] = width; + gl->last_height[gl->tex_index] = height; - glBufferSubData(GL_TEXTURE_REFERENCE_BUFFER_SCE, - gl->tex_w * gl->tex_h * gl->tex_index * gl->base_size, - gl->tex_w * gl->tex_h * gl->base_size, - gl->empty_buf); + glBufferSubData(GL_TEXTURE_REFERENCE_BUFFER_SCE, + gl->tex_w * gl->tex_h * gl->tex_index * gl->base_size, + gl->tex_w * gl->tex_h * gl->base_size, + gl->empty_buf); - GLfloat xamt = (GLfloat)width / gl->tex_w; - GLfloat yamt = (GLfloat)height / gl->tex_h; + GLfloat xamt = (GLfloat)width / gl->tex_w; + GLfloat yamt = (GLfloat)height / gl->tex_h; - set_texture_coords(gl->tex_coords, xamt, yamt); - } - // We might have used different texture coordinates last frame. Edge case if resolution changes very rapidly. - else if (width != gl->last_width[(gl->tex_index - 1) & TEXTURES_MASK] || height != gl->last_height[(gl->tex_index - 1) & TEXTURES_MASK]) - { - GLfloat xamt = (GLfloat)width / gl->tex_w; - GLfloat yamt = (GLfloat)height / gl->tex_h; - set_texture_coords(gl->tex_coords, xamt, yamt); - } + set_texture_coords(gl->tex_coords, xamt, yamt); + } + else if (width != gl->last_width[(gl->tex_index - 1) & TEXTURES_MASK] || height != gl->last_height[(gl->tex_index - 1) & TEXTURES_MASK]) + { + // We might have used different texture coordinates last frame. Edge case if resolution changes very rapidly. + GLfloat xamt = (GLfloat)width / gl->tex_w; + GLfloat yamt = (GLfloat)height / gl->tex_h; + set_texture_coords(gl->tex_coords, xamt, yamt); + } - // Need to preserve the "flipped" state when in FBO as well to have - // consistent texture coordinates. - if (gl->render_to_tex) - glVertexPointer(2, GL_FLOAT, 0, vertexes); + // Need to preserve the "flipped" state when in FBO as well to have + // consistent texture coordinates. + if (gl->render_to_tex) + glVertexPointer(2, GL_FLOAT, 0, vertexes); - { - size_t buffer_addr = gl->tex_w * gl->tex_h * gl->tex_index * gl->base_size; - size_t buffer_stride = gl->tex_w * gl->base_size; - const uint8_t *frame_copy = frame; - size_t frame_copy_size = width * gl->base_size; - for (unsigned h = 0; h < height; h++) - { - glBufferSubData(GL_TEXTURE_REFERENCE_BUFFER_SCE, - buffer_addr, - frame_copy_size, - frame_copy); + size_t buffer_addr = gl->tex_w * gl->tex_h * gl->tex_index * gl->base_size; + size_t buffer_stride = gl->tex_w * gl->base_size; + const uint8_t *frame_copy = frame; + size_t frame_copy_size = width * gl->base_size; + for (unsigned h = 0; h < height; h++) + { + glBufferSubData(GL_TEXTURE_REFERENCE_BUFFER_SCE, + buffer_addr, + frame_copy_size, + frame_copy); - frame_copy += pitch; - buffer_addr += buffer_stride; - } - } + frame_copy += pitch; + buffer_addr += buffer_stride; + } - struct gl_tex_info tex_info = { - .tex = gl->texture[gl->tex_index], - .input_size = {width, height}, - .tex_size = {gl->tex_w, gl->tex_h} - }; - struct gl_tex_info fbo_tex_info[MAX_SHADERS]; - unsigned fbo_tex_info_cnt = 0; - memcpy(tex_info.coord, gl->tex_coords, sizeof(gl->tex_coords)); + struct gl_tex_info tex_info = { + .tex = gl->texture[gl->tex_index], + .input_size = {width, height}, + .tex_size = {gl->tex_w, gl->tex_h} + }; - glClear(GL_COLOR_BUFFER_BIT); - gl_cg_set_params(width, height, - gl->tex_w, gl->tex_h, - gl->vp_width, gl->vp_height, - g_frame_count, &tex_info, gl->prev_info, fbo_tex_info, fbo_tex_info_cnt); + struct gl_tex_info fbo_tex_info[MAX_SHADERS]; + unsigned fbo_tex_info_cnt = 0; + memcpy(tex_info.coord, gl->tex_coords, sizeof(gl->tex_coords)); - glDrawArrays(GL_QUADS, 0, 4); + glClear(GL_COLOR_BUFFER_BIT); + gl_cg_set_params(width, height, + gl->tex_w, gl->tex_h, + gl->vp_width, gl->vp_height, + g_frame_count, &tex_info, gl->prev_info, fbo_tex_info, fbo_tex_info_cnt); - if (gl->fbo_inited) - { - // Render the rest of our passes. - glTexCoordPointer(2, GL_FLOAT, 0, gl->fbo_tex_coords); + glDrawArrays(GL_QUADS, 0, 4); - // It's kinda handy ... :) - const struct gl_fbo_rect *prev_rect; - const struct gl_fbo_rect *rect; - struct gl_tex_info *fbo_info; + if (gl->fbo_inited) + { + // Render the rest of our passes. + glTexCoordPointer(2, GL_FLOAT, 0, gl->fbo_tex_coords); - // Calculate viewports, texture coordinates etc, and render all passes from FBOs, to another FBO. - for (int i = 1; i < gl->fbo_pass; i++) - { - prev_rect = &gl->fbo_rect[i - 1]; - rect = &gl->fbo_rect[i]; - fbo_info = &fbo_tex_info[i - 1]; + // It's kinda handy ... :) + const struct gl_fbo_rect *prev_rect; + const struct gl_fbo_rect *rect; + struct gl_tex_info *fbo_info; - GLfloat xamt = (GLfloat)prev_rect->img_width / prev_rect->width; - GLfloat yamt = (GLfloat)prev_rect->img_height / prev_rect->height; + // Calculate viewports, texture coordinates etc, and render all passes from FBOs, to another FBO. + for (int i = 1; i < gl->fbo_pass; i++) + { + prev_rect = &gl->fbo_rect[i - 1]; + rect = &gl->fbo_rect[i]; + fbo_info = &fbo_tex_info[i - 1]; - set_texture_coords(gl->fbo_tex_coords, xamt, yamt); + GLfloat xamt = (GLfloat)prev_rect->img_width / prev_rect->width; + GLfloat yamt = (GLfloat)prev_rect->img_height / prev_rect->height; - fbo_info->tex = gl->fbo_texture[i - 1]; - fbo_info->input_size[0] = prev_rect->img_width; - fbo_info->input_size[1] = prev_rect->img_height; - fbo_info->tex_size[0] = prev_rect->width; - fbo_info->tex_size[1] = prev_rect->height; - memcpy(fbo_info->coord, gl->fbo_tex_coords, sizeof(gl->fbo_tex_coords)); + set_texture_coords(gl->fbo_tex_coords, xamt, yamt); - glBindFramebufferOES(GL_FRAMEBUFFER_OES, gl->fbo[i]); - gl_cg_use(i + 1); - glBindTexture(GL_TEXTURE_2D, gl->fbo_texture[i - 1]); + fbo_info->tex = gl->fbo_texture[i - 1]; + fbo_info->input_size[0] = prev_rect->img_width; + fbo_info->input_size[1] = prev_rect->img_height; + fbo_info->tex_size[0] = prev_rect->width; + fbo_info->tex_size[1] = prev_rect->height; + memcpy(fbo_info->coord, gl->fbo_tex_coords, sizeof(gl->fbo_tex_coords)); - glClear(GL_COLOR_BUFFER_BIT); + glBindFramebufferOES(GL_FRAMEBUFFER_OES, gl->fbo[i]); + gl_cg_use(i + 1); + glBindTexture(GL_TEXTURE_2D, gl->fbo_texture[i - 1]); - // Render to FBO with certain size. - set_viewport(gl, rect->img_width, rect->img_height, true); - gl_cg_set_params(prev_rect->img_width, prev_rect->img_height, - prev_rect->width, prev_rect->height, - gl->vp_width, gl->vp_height, g_frame_count, - &tex_info, gl->prev_info, fbo_tex_info, fbo_tex_info_cnt); + glClear(GL_COLOR_BUFFER_BIT); - glDrawArrays(GL_QUADS, 0, 4); + // Render to FBO with certain size. + set_viewport(gl, rect->img_width, rect->img_height, true); + gl_cg_set_params(prev_rect->img_width, prev_rect->img_height, + prev_rect->width, prev_rect->height, + gl->vp_width, gl->vp_height, g_frame_count, + &tex_info, gl->prev_info, fbo_tex_info, fbo_tex_info_cnt); - fbo_tex_info_cnt++; - } + glDrawArrays(GL_QUADS, 0, 4); - // Render our last FBO texture directly to screen. - prev_rect = &gl->fbo_rect[gl->fbo_pass - 1]; - GLfloat xamt = (GLfloat)prev_rect->img_width / prev_rect->width; - GLfloat yamt = (GLfloat)prev_rect->img_height / prev_rect->height; + fbo_tex_info_cnt++; + } - set_texture_coords(gl->fbo_tex_coords, xamt, yamt); + // Render our last FBO texture directly to screen. + prev_rect = &gl->fbo_rect[gl->fbo_pass - 1]; + GLfloat xamt = (GLfloat)prev_rect->img_width / prev_rect->width; + GLfloat yamt = (GLfloat)prev_rect->img_height / prev_rect->height; - // Render our FBO texture to back buffer. - glBindFramebufferOES(GL_FRAMEBUFFER_OES, 0); - gl_cg_use(gl->fbo_pass + 1); + set_texture_coords(gl->fbo_tex_coords, xamt, yamt); - glBindTexture(GL_TEXTURE_2D, gl->fbo_texture[gl->fbo_pass - 1]); + // Render our FBO texture to back buffer. + glBindFramebufferOES(GL_FRAMEBUFFER_OES, 0); + gl_cg_use(gl->fbo_pass + 1); - glClear(GL_COLOR_BUFFER_BIT); - gl->render_to_tex = false; - set_viewport(gl, gl->win_width, gl->win_height, false); - gl_cg_set_params(prev_rect->img_width, prev_rect->img_height, - prev_rect->width, prev_rect->height, - gl->vp_width, gl->vp_height, g_frame_count, - &tex_info, gl->prev_info, fbo_tex_info, fbo_tex_info_cnt); + glBindTexture(GL_TEXTURE_2D, gl->fbo_texture[gl->fbo_pass - 1]); - glVertexPointer(2, GL_FLOAT, 0, vertex_ptr); - glDrawArrays(GL_QUADS, 0, 4); + glClear(GL_COLOR_BUFFER_BIT); + gl->render_to_tex = false; + set_viewport(gl, gl->win_width, gl->win_height, false); + gl_cg_set_params(prev_rect->img_width, prev_rect->img_height, + prev_rect->width, prev_rect->height, + gl->vp_width, gl->vp_height, g_frame_count, + &tex_info, gl->prev_info, fbo_tex_info, fbo_tex_info_cnt); - glTexCoordPointer(2, GL_FLOAT, 0, gl->tex_coords); - } + glVertexPointer(2, GL_FLOAT, 0, vertex_ptr); + glDrawArrays(GL_QUADS, 0, 4); - memmove(gl->prev_info + 1, gl->prev_info, sizeof(tex_info) * (TEXTURES - 1)); - memcpy(&gl->prev_info[0], &tex_info, sizeof(tex_info)); - gl->tex_index = (gl->tex_index + 1) & TEXTURES_MASK; + glTexCoordPointer(2, GL_FLOAT, 0, gl->tex_coords); + } - if (msg) - { - cellDbgFontPrintf(g_settings.video.msg_pos_x, g_settings.video.msg_pos_y, 1.11f, BLUE, msg); - cellDbgFontPrintf(g_settings.video.msg_pos_x, g_settings.video.msg_pos_y, 1.10f, WHITE, msg); - cellDbgFontDraw(); - } + memmove(gl->prev_info + 1, gl->prev_info, sizeof(tex_info) * (TEXTURES - 1)); + memcpy(&gl->prev_info[0], &tex_info, sizeof(tex_info)); + gl->tex_index = (gl->tex_index + 1) & TEXTURES_MASK; - if(!gl->block_swap) - psglSwap(); - return true; + if (msg) + { + cellDbgFontPrintf(g_settings.video.msg_pos_x, g_settings.video.msg_pos_y, 1.11f, BLUE, msg); + cellDbgFontPrintf(g_settings.video.msg_pos_x, g_settings.video.msg_pos_y, 1.10f, WHITE, msg); + cellDbgFontDraw(); + } + + if(!gl->block_swap) + psglSwap(); + + return true; } static void psgl_deinit(gl_t *gl) { - glFinish(); - cellDbgFontExit(); + glFinish(); + cellDbgFontExit(); - psglDestroyContext(gl->gl_context); - psglDestroyDevice(gl->gl_device); + psglDestroyContext(gl->gl_context); + psglDestroyDevice(gl->gl_device); - psglExit(); + psglExit(); } static void gl_free(void *data) { - if (g_gl) - return; + if (g_gl) + return; - gl_t *gl = data; + gl_t *gl = data; - gl_cg_deinit(); + gl_cg_deinit(); - glDisableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_TEXTURE_COORD_ARRAY); - glDisableClientState(GL_COLOR_ARRAY); - glDeleteTextures(TEXTURES, gl->texture); - glBindBuffer(GL_TEXTURE_REFERENCE_BUFFER_SCE, 0); - glDeleteBuffers(1, &gl->pbo); + glDisableClientState(GL_VERTEX_ARRAY); + glDisableClientState(GL_TEXTURE_COORD_ARRAY); + glDisableClientState(GL_COLOR_ARRAY); + glDeleteTextures(TEXTURES, gl->texture); + glBindBuffer(GL_TEXTURE_REFERENCE_BUFFER_SCE, 0); + glDeleteBuffers(1, &gl->pbo); - gl_deinit_fbo(gl); - psgl_deinit(gl); + gl_deinit_fbo(gl); + psgl_deinit(gl); - if (gl->empty_buf) - free(gl->empty_buf); + if (gl->empty_buf) + free(gl->empty_buf); - free(gl); + free(gl); } static void gl_set_nonblock_state(void *data, bool state) { - gl_t *gl = data; - if (gl->vsync) - { - SSNES_LOG("GL VSync => %s\n", state ? "off" : "on"); - if(state) - glDisable(GL_VSYNC_SCE); - else - glEnable(GL_VSYNC_SCE); - } + gl_t *gl = data; + if (gl->vsync) + { + SSNES_LOG("GL VSync => %s\n", state ? "off" : "on"); + if(state) + glDisable(GL_VSYNC_SCE); + else + glEnable(GL_VSYNC_SCE); + } } static bool psgl_init_device(gl_t *gl, const video_info_t *video, uint32_t resolution_id) { - PSGLinitOptions options = { - .enable = PSGL_INIT_MAX_SPUS | PSGL_INIT_INITIALIZE_SPUS, - .maxSPUs = 1, - .initializeSPUs = GL_FALSE, - }; + PSGLinitOptions options = + { + .enable = PSGL_INIT_MAX_SPUS | PSGL_INIT_INITIALIZE_SPUS, + .maxSPUs = 1, + .initializeSPUs = GL_FALSE, + }; #if CELL_SDK_VERSION < 0x340000 - options.enable |= PSGL_INIT_HOST_MEMORY_SIZE; + options.enable |= PSGL_INIT_HOST_MEMORY_SIZE; #endif - // Initialize 6 SPUs but reserve 1 SPU as a raw SPU for PSGL - sys_spu_initialize(6, 1); - psglInit(&options); + // Initialize 6 SPUs but reserve 1 SPU as a raw SPU for PSGL + sys_spu_initialize(6, 1); + psglInit(&options); - PSGLdeviceParameters params; + PSGLdeviceParameters params; - params.enable = PSGL_DEVICE_PARAMETERS_COLOR_FORMAT | \ - PSGL_DEVICE_PARAMETERS_DEPTH_FORMAT | \ - PSGL_DEVICE_PARAMETERS_MULTISAMPLING_MODE; - params.colorFormat = GL_ARGB_SCE; - params.depthFormat = GL_NONE; - params.multisamplingMode = GL_MULTISAMPLING_NONE_SCE; + params.enable = PSGL_DEVICE_PARAMETERS_COLOR_FORMAT | \ + PSGL_DEVICE_PARAMETERS_DEPTH_FORMAT | \ + PSGL_DEVICE_PARAMETERS_MULTISAMPLING_MODE; + params.colorFormat = GL_ARGB_SCE; + params.depthFormat = GL_NONE; + params.multisamplingMode = GL_MULTISAMPLING_NONE_SCE; - if(g_console.triple_buffering_enable) - { - params.enable |= PSGL_DEVICE_PARAMETERS_BUFFERING_MODE; - params.bufferingMode = PSGL_BUFFERING_MODE_TRIPLE; - } + if(g_console.triple_buffering_enable) + { + params.enable |= PSGL_DEVICE_PARAMETERS_BUFFERING_MODE; + params.bufferingMode = PSGL_BUFFERING_MODE_TRIPLE; + } - if(resolution_id) - { - CellVideoOutResolution resolution; - cellVideoOutGetResolution(resolution_id, &resolution); + if(resolution_id) + { + CellVideoOutResolution resolution; + cellVideoOutGetResolution(resolution_id, &resolution); - params.enable |= PSGL_DEVICE_PARAMETERS_WIDTH_HEIGHT; - params.width = resolution.width; - params.height = resolution.height; - } + params.enable |= PSGL_DEVICE_PARAMETERS_WIDTH_HEIGHT; + params.width = resolution.width; + params.height = resolution.height; + } - gl->gl_device = psglCreateDeviceExtended(¶ms); - psglGetDeviceDimensions(gl->gl_device, &gl->win_width, &gl->win_height); + gl->gl_device = psglCreateDeviceExtended(¶ms); + psglGetDeviceDimensions(gl->gl_device, &gl->win_width, &gl->win_height); - if(g_console.custom_viewport_width == 0) - g_console.custom_viewport_width = gl->win_width; - if(g_console.custom_viewport_height == 0) - g_console.custom_viewport_height = gl->win_height; + if(g_console.custom_viewport_width == 0) + g_console.custom_viewport_width = gl->win_width; - gl->gl_context = psglCreateContext(); - psglMakeCurrent(gl->gl_context, gl->gl_device); - psglResetCurrentContext(); + if(g_console.custom_viewport_height == 0) + g_console.custom_viewport_height = gl->win_height; - return true; + gl->gl_context = psglCreateContext(); + psglMakeCurrent(gl->gl_context, gl->gl_device); + psglResetCurrentContext(); + + return true; } static void psgl_init_dbgfont(gl_t *gl) { - CellDbgFontConfig cfg; - memset(&cfg, 0, sizeof(cfg)); - cfg.bufSize = 512; - cfg.screenWidth = gl->win_width; - cfg.screenHeight = gl->win_height; - cellDbgFontInit(&cfg); + CellDbgFontConfig cfg; + memset(&cfg, 0, sizeof(cfg)); + cfg.bufSize = 512; + cfg.screenWidth = gl->win_width; + cfg.screenHeight = gl->win_height; + cellDbgFontInit(&cfg); } static void *gl_init(const video_info_t *video, const input_driver_t **input, void **input_data) { - if (g_gl) - return g_gl; + if (g_gl) + return g_gl; - gl_t *gl = calloc(1, sizeof(gl_t)); - if (!gl) - return NULL; + gl_t *gl = calloc(1, sizeof(gl_t)); + if (!gl) + return NULL; - if (!psgl_init_device(gl, video, g_console.current_resolution_id)) - return NULL; + if (!psgl_init_device(gl, video, g_console.current_resolution_id)) + return NULL; - SSNES_LOG("Detecting resolution %ux%u.\n", gl->win_width, gl->win_height); + SSNES_LOG("Detecting resolution %ux%u.\n", gl->win_width, gl->win_height); - video->vsync ? glEnable(GL_VSYNC_SCE) : glDisable(GL_VSYNC_SCE); + video->vsync ? glEnable(GL_VSYNC_SCE) : glDisable(GL_VSYNC_SCE); - gl->vsync = video->vsync; + gl->vsync = video->vsync; - SSNES_LOG("GL: Using resolution %ux%u.\n", gl->win_width, gl->win_height); + SSNES_LOG("GL: Using resolution %ux%u.\n", gl->win_width, gl->win_height); - SSNES_LOG("GL: Initializing debug fonts...\n"); - psgl_init_dbgfont(gl); + SSNES_LOG("GL: Initializing debug fonts...\n"); + psgl_init_dbgfont(gl); - SSNES_LOG("Initializing menu shader...\n"); - gl_cg_set_menu_shader(DEFAULT_MENU_SHADER_FILE); + SSNES_LOG("Initializing menu shader...\n"); + gl_cg_set_menu_shader(DEFAULT_MENU_SHADER_FILE); - if (!gl_shader_init()) - { - SSNES_ERR("Menu shader initialization failed.\n"); - psgl_deinit(gl); - free(gl); - return NULL; - } + if (!gl_shader_init()) + { + SSNES_ERR("Menu shader initialization failed.\n"); + psgl_deinit(gl); + free(gl); + return NULL; + } - SSNES_LOG("GL: Loaded %u program(s).\n", gl_shader_num()); + SSNES_LOG("GL: Loaded %u program(s).\n", gl_shader_num()); - // Set up render to texture. - gl_init_fbo(gl, SSNES_SCALE_BASE * video->input_scale, - SSNES_SCALE_BASE * video->input_scale); + // Set up render to texture. + gl_init_fbo(gl, SSNES_SCALE_BASE * video->input_scale, + SSNES_SCALE_BASE * video->input_scale); - gl->keep_aspect = video->force_aspect; + gl->keep_aspect = video->force_aspect; - // Apparently need to set viewport for passes when we aren't using FBOs. - gl_cg_use(0); - set_viewport(gl, gl->win_width, gl->win_height, false); - gl_cg_use(1); - set_viewport(gl, gl->win_width, gl->win_height, false); + // Apparently need to set viewport for passes when we aren't using FBOs. + gl_cg_use(0); + set_viewport(gl, gl->win_width, gl->win_height, false); + gl_cg_use(1); + set_viewport(gl, gl->win_width, gl->win_height, false); - bool force_smooth = false; - if (gl_shader_filter_type(1, &force_smooth)) - gl->tex_filter = force_smooth ? GL_LINEAR : GL_NEAREST; - else - gl->tex_filter = video->smooth ? GL_LINEAR : GL_NEAREST; + bool force_smooth = false; + if (gl_shader_filter_type(1, &force_smooth)) + gl->tex_filter = force_smooth ? GL_LINEAR : GL_NEAREST; + else + gl->tex_filter = video->smooth ? GL_LINEAR : GL_NEAREST; - gl->texture_type = GL_BGRA; - gl->texture_fmt = video->rgb32 ? GL_ARGB_SCE : GL_RGB5_A1; - gl->base_size = video->rgb32 ? sizeof(uint32_t) : sizeof(uint16_t); + gl->texture_type = GL_BGRA; + gl->texture_fmt = video->rgb32 ? GL_ARGB_SCE : GL_RGB5_A1; + gl->base_size = video->rgb32 ? sizeof(uint32_t) : sizeof(uint16_t); - glEnable(GL_TEXTURE_2D); - glClearColor(0, 0, 0, 1); + glEnable(GL_TEXTURE_2D); + glClearColor(0, 0, 0, 1); - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); - gl->tex_w = SSNES_SCALE_BASE * video->input_scale; - gl->tex_h = SSNES_SCALE_BASE * video->input_scale; - glGenBuffers(1, &gl->pbo); - glBindBuffer(GL_TEXTURE_REFERENCE_BUFFER_SCE, gl->pbo); - glBufferData(GL_TEXTURE_REFERENCE_BUFFER_SCE, gl->tex_w * gl->tex_h * gl->base_size * TEXTURES, NULL, GL_STREAM_DRAW); + gl->tex_w = SSNES_SCALE_BASE * video->input_scale; + gl->tex_h = SSNES_SCALE_BASE * video->input_scale; + glGenBuffers(1, &gl->pbo); + glBindBuffer(GL_TEXTURE_REFERENCE_BUFFER_SCE, gl->pbo); + glBufferData(GL_TEXTURE_REFERENCE_BUFFER_SCE, gl->tex_w * gl->tex_h * gl->base_size * TEXTURES, NULL, GL_STREAM_DRAW); - glGenTextures(TEXTURES, gl->texture); + glGenTextures(TEXTURES, gl->texture); - for (unsigned i = 0; i < TEXTURES; i++) - { - glBindTexture(GL_TEXTURE_2D, gl->texture[i]); + for (unsigned i = 0; i < TEXTURES; i++) + { + glBindTexture(GL_TEXTURE_2D, gl->texture[i]); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gl->tex_filter); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gl->tex_filter); - } + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gl->tex_filter); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gl->tex_filter); + } - glEnableClientState(GL_VERTEX_ARRAY); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - glEnableClientState(GL_COLOR_ARRAY); - glVertexPointer(2, GL_FLOAT, 0, vertex_ptr); + glEnableClientState(GL_VERTEX_ARRAY); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + glEnableClientState(GL_COLOR_ARRAY); + glVertexPointer(2, GL_FLOAT, 0, vertex_ptr); - memcpy(gl->tex_coords, tex_coords, sizeof(tex_coords)); - glTexCoordPointer(2, GL_FLOAT, 0, gl->tex_coords); + memcpy(gl->tex_coords, tex_coords, sizeof(tex_coords)); + glTexCoordPointer(2, GL_FLOAT, 0, gl->tex_coords); - glColorPointer(4, GL_FLOAT, 0, white_color); + glColorPointer(4, GL_FLOAT, 0, white_color); - set_lut_texture_coords(tex_coords); + set_lut_texture_coords(tex_coords); - // Empty buffer that we use to clear out the texture with on res change. - gl->empty_buf = calloc(gl->tex_w * gl->tex_h, gl->base_size); + // Empty buffer that we use to clear out the texture with on res change. + gl->empty_buf = calloc(gl->tex_w * gl->tex_h, gl->base_size); - for (unsigned i = 0; i < TEXTURES; i++) - { - glBindTexture(GL_TEXTURE_2D, gl->texture[i]); - glTextureReferenceSCE(GL_TEXTURE_2D, 1, - gl->tex_w, gl->tex_h, 0, - gl->texture_fmt, - gl->tex_w * gl->base_size, - gl->tex_w * gl->tex_h * i * gl->base_size); - } - glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]); + for (unsigned i = 0; i < TEXTURES; i++) + { + glBindTexture(GL_TEXTURE_2D, gl->texture[i]); + glTextureReferenceSCE(GL_TEXTURE_2D, 1, + gl->tex_w, gl->tex_h, 0, + gl->texture_fmt, + gl->tex_w * gl->base_size, + gl->tex_w * gl->tex_h * i * gl->base_size); + } + glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]); - for (unsigned i = 0; i < TEXTURES; i++) - { - gl->last_width[i] = gl->tex_w; - gl->last_height[i] = gl->tex_h; - } + for (unsigned i = 0; i < TEXTURES; i++) + { + gl->last_width[i] = gl->tex_w; + gl->last_height[i] = gl->tex_h; + } - for (unsigned i = 0; i < TEXTURES; i++) - { - gl->prev_info[i].tex = gl->texture[(gl->tex_index - (i + 1)) & TEXTURES_MASK]; - gl->prev_info[i].input_size[0] = gl->tex_w; - gl->prev_info[i].tex_size[0] = gl->tex_w; - gl->prev_info[i].input_size[1] = gl->tex_h; - gl->prev_info[i].tex_size[1] = gl->tex_h; - memcpy(gl->prev_info[i].coord, tex_coords, sizeof(tex_coords)); - } + for (unsigned i = 0; i < TEXTURES; i++) + { + gl->prev_info[i].tex = gl->texture[(gl->tex_index - (i + 1)) & TEXTURES_MASK]; + gl->prev_info[i].input_size[0] = gl->tex_w; + gl->prev_info[i].tex_size[0] = gl->tex_w; + gl->prev_info[i].input_size[1] = gl->tex_h; + gl->prev_info[i].tex_size[1] = gl->tex_h; + memcpy(gl->prev_info[i].coord, tex_coords, sizeof(tex_coords)); + } - if (!gl_check_error()) - { - psgl_deinit(gl); - free(gl); - return NULL; - } + if (!gl_check_error()) + { + psgl_deinit(gl); + free(gl); + return NULL; + } - if (input) - *input = NULL; - if (input_data) - *input_data = NULL; + if (input) + *input = NULL; + if (input_data) + *input_data = NULL; - return gl; + return gl; } static bool gl_alive(void *data) { - (void)data; - cellSysutilCheckCallback(); - return !g_quitting; + (void)data; + cellSysutilCheckCallback(); + return !g_quitting; } static bool gl_focus(void *data) { - (void)data; - return true; + (void)data; + return true; } static void ps3graphics_set_swap_block_swap(void * data, bool toggle) { - (void)data; - gl_t *gl = g_gl; - gl->block_swap = toggle; + (void)data; + gl_t *gl = g_gl; + gl->block_swap = toggle; } static void ps3graphics_swap(void * data) { - (void)data; - psglSwap(); - cellSysutilCheckCallback(); + (void)data; + psglSwap(); + cellSysutilCheckCallback(); } static void ps3graphics_set_aspect_ratio(void * data, uint32_t aspectratio_index) { - (void)data; - gl_t * gl = g_gl; + (void)data; + gl_t * gl = g_gl; - switch(aspectratio_index) - { - case ASPECT_RATIO_4_3: - g_settings.video.aspect_ratio = 1.33333333333; - strlcpy(g_console.aspect_ratio_name, "4:3", sizeof(g_console.aspect_ratio_name)); - break; - case ASPECT_RATIO_4_4: - g_settings.video.aspect_ratio = 1.0; - strlcpy(g_console.aspect_ratio_name, "4:4", sizeof(g_console.aspect_ratio_name)); - break; - case ASPECT_RATIO_4_1: - g_settings.video.aspect_ratio = 4.0; - strlcpy(g_console.aspect_ratio_name, "4:1", sizeof(g_console.aspect_ratio_name)); - break; - case ASPECT_RATIO_5_4: - g_settings.video.aspect_ratio = 1.25; - strlcpy(g_console.aspect_ratio_name, "5:4", sizeof(g_console.aspect_ratio_name)); - break; - case ASPECT_RATIO_6_5: - g_settings.video.aspect_ratio = 1.2; - strlcpy(g_console.aspect_ratio_name, "6:5", sizeof(g_console.aspect_ratio_name)); - break; - case ASPECT_RATIO_7_9: - g_settings.video.aspect_ratio = 0.77777777777; - strlcpy(g_console.aspect_ratio_name, "7:9", sizeof(g_console.aspect_ratio_name)); - break; - case ASPECT_RATIO_8_3: - g_settings.video.aspect_ratio = 2.66666666666; - strlcpy(g_console.aspect_ratio_name, "8:3", sizeof(g_console.aspect_ratio_name)); - break; - case ASPECT_RATIO_8_7: - g_settings.video.aspect_ratio = 1.14287142857; - strlcpy(g_console.aspect_ratio_name, "8:7", sizeof(g_console.aspect_ratio_name)); - break; - case ASPECT_RATIO_16_9: - g_settings.video.aspect_ratio = 1.777778; - strlcpy(g_console.aspect_ratio_name, "16:9", sizeof(g_console.aspect_ratio_name)); - break; - case ASPECT_RATIO_16_10: - g_settings.video.aspect_ratio = 1.6; - strlcpy(g_console.aspect_ratio_name, "16:10", sizeof(g_console.aspect_ratio_name)); - break; - case ASPECT_RATIO_16_15: - g_settings.video.aspect_ratio = 3.2; - strlcpy(g_console.aspect_ratio_name, "16:15", sizeof(g_console.aspect_ratio_name)); - break; - case ASPECT_RATIO_19_12: - g_settings.video.aspect_ratio = 1.58333333333; - strlcpy(g_console.aspect_ratio_name, "19:12", sizeof(g_console.aspect_ratio_name)); - break; - case ASPECT_RATIO_19_14: - g_settings.video.aspect_ratio = 1.35714285714; - strlcpy(g_console.aspect_ratio_name, "19:14", sizeof(g_console.aspect_ratio_name)); - break; - case ASPECT_RATIO_30_17: - g_settings.video.aspect_ratio = 1.76470588235; - strlcpy(g_console.aspect_ratio_name, "30:17", sizeof(g_console.aspect_ratio_name)); - break; - case ASPECT_RATIO_32_9: - g_settings.video.aspect_ratio = 3.55555555555; - strlcpy(g_console.aspect_ratio_name, "32:9", sizeof(g_console.aspect_ratio_name)); - break; - case ASPECT_RATIO_2_1: - g_settings.video.aspect_ratio = 2.0; - strlcpy(g_console.aspect_ratio_name, "2:1", sizeof(g_console.aspect_ratio_name)); - break; - case ASPECT_RATIO_3_2: - g_settings.video.aspect_ratio = 1.5; - strlcpy(g_console.aspect_ratio_name, "3:2", sizeof(g_console.aspect_ratio_name)); - break; - case ASPECT_RATIO_3_4: - g_settings.video.aspect_ratio = 0.75; - strlcpy(g_console.aspect_ratio_name, "3:4", sizeof(g_console.aspect_ratio_name)); - break; - case ASPECT_RATIO_1_1: - g_settings.video.aspect_ratio = 1.0; - strlcpy(g_console.aspect_ratio_name, "1:1", sizeof(g_console.aspect_ratio_name)); - break; - case ASPECT_RATIO_AUTO: - strlcpy(g_console.aspect_ratio_name, "(Auto)", sizeof(g_console.aspect_ratio_name)); - break; - case ASPECT_RATIO_CUSTOM: - strlcpy(g_console.aspect_ratio_name, "(Custom)", sizeof(g_console.aspect_ratio_name)); - break; - } - g_settings.video.force_aspect = false; - gl->keep_aspect = true; - set_viewport(gl, gl->win_width, gl->win_height, false); + switch(aspectratio_index) + { + case ASPECT_RATIO_4_3: + g_settings.video.aspect_ratio = 1.33333333333; + strlcpy(g_console.aspect_ratio_name, "4:3", sizeof(g_console.aspect_ratio_name)); + break; + case ASPECT_RATIO_4_4: + g_settings.video.aspect_ratio = 1.0; + strlcpy(g_console.aspect_ratio_name, "4:4", sizeof(g_console.aspect_ratio_name)); + break; + case ASPECT_RATIO_4_1: + g_settings.video.aspect_ratio = 4.0; + strlcpy(g_console.aspect_ratio_name, "4:1", sizeof(g_console.aspect_ratio_name)); + break; + case ASPECT_RATIO_5_4: + g_settings.video.aspect_ratio = 1.25; + strlcpy(g_console.aspect_ratio_name, "5:4", sizeof(g_console.aspect_ratio_name)); + break; + case ASPECT_RATIO_6_5: + g_settings.video.aspect_ratio = 1.2; + strlcpy(g_console.aspect_ratio_name, "6:5", sizeof(g_console.aspect_ratio_name)); + break; + case ASPECT_RATIO_7_9: + g_settings.video.aspect_ratio = 0.77777777777; + strlcpy(g_console.aspect_ratio_name, "7:9", sizeof(g_console.aspect_ratio_name)); + break; + case ASPECT_RATIO_8_3: + g_settings.video.aspect_ratio = 2.66666666666; + strlcpy(g_console.aspect_ratio_name, "8:3", sizeof(g_console.aspect_ratio_name)); + break; + case ASPECT_RATIO_8_7: + g_settings.video.aspect_ratio = 1.14287142857; + strlcpy(g_console.aspect_ratio_name, "8:7", sizeof(g_console.aspect_ratio_name)); + break; + case ASPECT_RATIO_16_9: + g_settings.video.aspect_ratio = 1.777778; + strlcpy(g_console.aspect_ratio_name, "16:9", sizeof(g_console.aspect_ratio_name)); + break; + case ASPECT_RATIO_16_10: + g_settings.video.aspect_ratio = 1.6; + strlcpy(g_console.aspect_ratio_name, "16:10", sizeof(g_console.aspect_ratio_name)); + break; + case ASPECT_RATIO_16_15: + g_settings.video.aspect_ratio = 3.2; + strlcpy(g_console.aspect_ratio_name, "16:15", sizeof(g_console.aspect_ratio_name)); + break; + case ASPECT_RATIO_19_12: + g_settings.video.aspect_ratio = 1.58333333333; + strlcpy(g_console.aspect_ratio_name, "19:12", sizeof(g_console.aspect_ratio_name)); + break; + case ASPECT_RATIO_19_14: + g_settings.video.aspect_ratio = 1.35714285714; + strlcpy(g_console.aspect_ratio_name, "19:14", sizeof(g_console.aspect_ratio_name)); + break; + case ASPECT_RATIO_30_17: + g_settings.video.aspect_ratio = 1.76470588235; + strlcpy(g_console.aspect_ratio_name, "30:17", sizeof(g_console.aspect_ratio_name)); + break; + case ASPECT_RATIO_32_9: + g_settings.video.aspect_ratio = 3.55555555555; + strlcpy(g_console.aspect_ratio_name, "32:9", sizeof(g_console.aspect_ratio_name)); + break; + case ASPECT_RATIO_2_1: + g_settings.video.aspect_ratio = 2.0; + strlcpy(g_console.aspect_ratio_name, "2:1", sizeof(g_console.aspect_ratio_name)); + break; + case ASPECT_RATIO_3_2: + g_settings.video.aspect_ratio = 1.5; + strlcpy(g_console.aspect_ratio_name, "3:2", sizeof(g_console.aspect_ratio_name)); + break; + case ASPECT_RATIO_3_4: + g_settings.video.aspect_ratio = 0.75; + strlcpy(g_console.aspect_ratio_name, "3:4", sizeof(g_console.aspect_ratio_name)); + break; + case ASPECT_RATIO_1_1: + g_settings.video.aspect_ratio = 1.0; + strlcpy(g_console.aspect_ratio_name, "1:1", sizeof(g_console.aspect_ratio_name)); + break; + case ASPECT_RATIO_AUTO: + strlcpy(g_console.aspect_ratio_name, "(Auto)", sizeof(g_console.aspect_ratio_name)); + break; + case ASPECT_RATIO_CUSTOM: + strlcpy(g_console.aspect_ratio_name, "(Custom)", sizeof(g_console.aspect_ratio_name)); + break; + } + + g_settings.video.force_aspect = false; + gl->keep_aspect = true; + set_viewport(gl, gl->win_width, gl->win_height, false); } const video_driver_t video_gl = { - .init = gl_init, - .frame = gl_frame, - .alive = gl_alive, - .set_nonblock_state = gl_set_nonblock_state, - .focus = gl_focus, - .free = gl_free, - .ident = "gl", - .set_swap_block_state = ps3graphics_set_swap_block_swap, - .set_rotation = ps3graphics_set_orientation, - .set_aspect_ratio = ps3graphics_set_aspect_ratio, - .swap = ps3graphics_swap + .init = gl_init, + .frame = gl_frame, + .alive = gl_alive, + .set_nonblock_state = gl_set_nonblock_state, + .focus = gl_focus, + .free = gl_free, + .ident = "gl", + .set_swap_block_state = ps3graphics_set_swap_block_swap, + .set_rotation = ps3graphics_set_orientation, + .set_aspect_ratio = ps3graphics_set_aspect_ratio, + .swap = ps3graphics_swap }; static void get_all_available_resolutions (void) { - bool defaultresolution; - uint32_t i, resolution_count; - uint16_t num_videomodes; + bool defaultresolution; + uint32_t i, resolution_count; + uint16_t num_videomodes; - defaultresolution = true; + defaultresolution = true; - uint32_t videomode[] = { - CELL_VIDEO_OUT_RESOLUTION_480, CELL_VIDEO_OUT_RESOLUTION_576, - CELL_VIDEO_OUT_RESOLUTION_960x1080, CELL_VIDEO_OUT_RESOLUTION_720, - CELL_VIDEO_OUT_RESOLUTION_1280x1080, CELL_VIDEO_OUT_RESOLUTION_1440x1080, - CELL_VIDEO_OUT_RESOLUTION_1600x1080, CELL_VIDEO_OUT_RESOLUTION_1080}; + uint32_t videomode[] = { + CELL_VIDEO_OUT_RESOLUTION_480, CELL_VIDEO_OUT_RESOLUTION_576, + CELL_VIDEO_OUT_RESOLUTION_960x1080, CELL_VIDEO_OUT_RESOLUTION_720, + CELL_VIDEO_OUT_RESOLUTION_1280x1080, CELL_VIDEO_OUT_RESOLUTION_1440x1080, + CELL_VIDEO_OUT_RESOLUTION_1600x1080, CELL_VIDEO_OUT_RESOLUTION_1080}; - num_videomodes = sizeof(videomode)/sizeof(uint32_t); + num_videomodes = sizeof(videomode)/sizeof(uint32_t); - resolution_count = 0; - for (i = 0; i < num_videomodes; i++) - if (cellVideoOutGetResolutionAvailability(CELL_VIDEO_OUT_PRIMARY, videomode[i], CELL_VIDEO_OUT_ASPECT_AUTO,0)) + resolution_count = 0; + for (i = 0; i < num_videomodes; i++) + if (cellVideoOutGetResolutionAvailability(CELL_VIDEO_OUT_PRIMARY, videomode[i], CELL_VIDEO_OUT_ASPECT_AUTO,0)) resolution_count++; - g_console.supported_resolutions = (uint32_t*)malloc(resolution_count * sizeof(uint32_t)); + g_console.supported_resolutions = (uint32_t*)malloc(resolution_count * sizeof(uint32_t)); - g_console.supported_resolutions_count = 0; - for (i = 0; i < num_videomodes; i++) - { - if (cellVideoOutGetResolutionAvailability(CELL_VIDEO_OUT_PRIMARY, videomode[i], CELL_VIDEO_OUT_ASPECT_AUTO,0)) - { - g_console.supported_resolutions[g_console.supported_resolutions_count++] = videomode[i]; - g_console.initial_resolution_id = videomode[i]; + g_console.supported_resolutions_count = 0; - if (g_console.current_resolution_id == videomode[i]) - { - defaultresolution = false; - g_console.current_resolution_index = g_console.supported_resolutions_count-1; - } - } - } + for (i = 0; i < num_videomodes; i++) + { + if (cellVideoOutGetResolutionAvailability(CELL_VIDEO_OUT_PRIMARY, videomode[i], CELL_VIDEO_OUT_ASPECT_AUTO,0)) + { + g_console.supported_resolutions[g_console.supported_resolutions_count++] = videomode[i]; + g_console.initial_resolution_id = videomode[i]; - /* In case we didn't specify a resolution - make the last resolution - that was added to the list (the highest resolution) the default resolution*/ - if (g_console.current_resolution_id > num_videomodes || defaultresolution) - g_console.current_resolution_index = g_console.supported_resolutions_count-1; + if (g_console.current_resolution_id == videomode[i]) + { + defaultresolution = false; + g_console.current_resolution_index = g_console.supported_resolutions_count-1; + } + } + } + + /* In case we didn't specify a resolution - make the last resolution + that was added to the list (the highest resolution) the default resolution*/ + if (g_console.current_resolution_id > num_videomodes || defaultresolution) + g_console.current_resolution_index = g_console.supported_resolutions_count-1; } void ps3_set_resolution (void) { - gl_t *gl = g_gl; - cellVideoOutGetState(CELL_VIDEO_OUT_PRIMARY, 0, &gl->g_video_state); + gl_t *gl = g_gl; + cellVideoOutGetState(CELL_VIDEO_OUT_PRIMARY, 0, &gl->g_video_state); } void ps3_next_resolution (void) { - if(g_console.current_resolution_index+1 < g_console.supported_resolutions_count) - { - g_console.current_resolution_index++; - g_console.current_resolution_id = g_console.supported_resolutions[g_console.current_resolution_index]; - } + if(g_console.current_resolution_index+1 < g_console.supported_resolutions_count) + { + g_console.current_resolution_index++; + g_console.current_resolution_id = g_console.supported_resolutions[g_console.current_resolution_index]; + } } void ps3_previous_resolution (void) { - if(g_console.current_resolution_index) - { - g_console.current_resolution_index--; - g_console.current_resolution_id = g_console.supported_resolutions[g_console.current_resolution_index]; - } + if(g_console.current_resolution_index) + { + g_console.current_resolution_index--; + g_console.current_resolution_id = g_console.supported_resolutions[g_console.current_resolution_index]; + } } int ps3_check_resolution(uint32_t resolution_id) { - return cellVideoOutGetResolutionAvailability(CELL_VIDEO_OUT_PRIMARY, resolution_id, \ - CELL_VIDEO_OUT_ASPECT_AUTO,0); + return cellVideoOutGetResolutionAvailability(CELL_VIDEO_OUT_PRIMARY, resolution_id, CELL_VIDEO_OUT_ASPECT_AUTO,0); } const char * ps3_get_resolution_label(uint32_t resolution) { - switch(resolution) - { - case CELL_VIDEO_OUT_RESOLUTION_480: - return "720x480 (480p)"; - case CELL_VIDEO_OUT_RESOLUTION_576: - return "720x576 (576p)"; - case CELL_VIDEO_OUT_RESOLUTION_720: - return "1280x720 (720p)"; - case CELL_VIDEO_OUT_RESOLUTION_960x1080: - return "960x1080"; - case CELL_VIDEO_OUT_RESOLUTION_1280x1080: - return "1280x1080"; - case CELL_VIDEO_OUT_RESOLUTION_1440x1080: - return "1440x1080"; - case CELL_VIDEO_OUT_RESOLUTION_1600x1080: - return "1600x1080"; - case CELL_VIDEO_OUT_RESOLUTION_1080: - return "1920x1080 (1080p)"; - default: - return "Unknown"; - } + switch(resolution) + { + case CELL_VIDEO_OUT_RESOLUTION_480: + return "720x480 (480p)"; + case CELL_VIDEO_OUT_RESOLUTION_576: + return "720x576 (576p)"; + case CELL_VIDEO_OUT_RESOLUTION_720: + return "1280x720 (720p)"; + case CELL_VIDEO_OUT_RESOLUTION_960x1080: + return "960x1080"; + case CELL_VIDEO_OUT_RESOLUTION_1280x1080: + return "1280x1080"; + case CELL_VIDEO_OUT_RESOLUTION_1440x1080: + return "1440x1080"; + case CELL_VIDEO_OUT_RESOLUTION_1600x1080: + return "1600x1080"; + case CELL_VIDEO_OUT_RESOLUTION_1080: + return "1920x1080 (1080p)"; + default: + return "Unknown"; + } } void ps3graphics_set_vsync(uint32_t vsync) { - if(vsync) - glEnable(GL_VSYNC_SCE); - else - glDisable(GL_VSYNC_SCE); + if(vsync) + glEnable(GL_VSYNC_SCE); + else + glDisable(GL_VSYNC_SCE); } bool ps3_setup_texture(void) { - gl_t *gl = g_gl; + gl_t *gl = g_gl; - if (!gl) - return false; + if (!gl) + return false; - glGenTextures(1, &gl->menu_texture_id); + glGenTextures(1, &gl->menu_texture_id); - SSNES_LOG("Loading texture image for menu...\n"); - if(!texture_image_load(DEFAULT_MENU_BORDER_FILE, &gl->menu_texture)) - { - SSNES_ERR("Failed to load texture image for menu.\n"); - return false; - } + SSNES_LOG("Loading texture image for menu...\n"); + if(!texture_image_load(DEFAULT_MENU_BORDER_FILE, &gl->menu_texture)) + { + SSNES_ERR("Failed to load texture image for menu.\n"); + return false; + } - glBindTexture(GL_TEXTURE_2D, gl->menu_texture_id); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glBindTexture(GL_TEXTURE_2D, gl->menu_texture_id); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexImage2D(GL_TEXTURE_2D, 0, GL_ARGB_SCE, gl->menu_texture.width, gl->menu_texture.height, 0, - GL_ARGB_SCE, GL_UNSIGNED_INT_8_8_8_8, gl->menu_texture.pixels); + glTexImage2D(GL_TEXTURE_2D, 0, GL_ARGB_SCE, gl->menu_texture.width, gl->menu_texture.height, 0, + GL_ARGB_SCE, GL_UNSIGNED_INT_8_8_8_8, gl->menu_texture.pixels); - glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]); + glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]); - free(gl->menu_texture.pixels); + free(gl->menu_texture.pixels); - return true; + return true; } void ps3_set_filtering(unsigned index, bool set_smooth) { - gl_t *gl = g_gl; + gl_t *gl = g_gl; - if (!gl) - return; + if (!gl) + return; - if (index == 1) - { - // Apply to all PREV textures. - for (unsigned i = 0; i < TEXTURES; i++) - { - glBindTexture(GL_TEXTURE_2D, gl->texture[i]); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, set_smooth ? GL_LINEAR : GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, set_smooth ? GL_LINEAR : GL_NEAREST); - } - } - else if (index >= 2 && gl->fbo_inited) - { - glBindTexture(GL_TEXTURE_2D, gl->fbo_texture[index - 2]); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, set_smooth ? GL_LINEAR : GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, set_smooth ? GL_LINEAR : GL_NEAREST); - } + if (index == 1) + { + // Apply to all PREV textures. + for (unsigned i = 0; i < TEXTURES; i++) + { + glBindTexture(GL_TEXTURE_2D, gl->texture[i]); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, set_smooth ? GL_LINEAR : GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, set_smooth ? GL_LINEAR : GL_NEAREST); + } + } + else if (index >= 2 && gl->fbo_inited) + { + glBindTexture(GL_TEXTURE_2D, gl->fbo_texture[index - 2]); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, set_smooth ? GL_LINEAR : GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, set_smooth ? GL_LINEAR : GL_NEAREST); + } - glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]); + glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]); } void ps3graphics_set_overscan(bool overscan_enable, float amount, bool recalculate_viewport) { - gl_t * gl = g_gl; - if(!gl) - return; + gl_t * gl = g_gl; + if(!gl) + return; - gl->overscan_enable = overscan_enable; - gl->overscan_amount = amount; + gl->overscan_enable = overscan_enable; + gl->overscan_amount = amount; - if(recalculate_viewport) - set_viewport(gl, gl->win_width, gl->win_height, false); + if(recalculate_viewport) + set_viewport(gl, gl->win_width, gl->win_height, false); } @@ -1296,42 +1278,44 @@ void ps3graphics_set_overscan(bool overscan_enable, float amount, bool recalcula void ps3graphics_video_init(bool get_all_resolutions) { - video_info_t video_info = {0}; - // Might have to supply correct values here. - video_info.vsync = g_settings.video.vsync; - video_info.force_aspect = false; - video_info.smooth = g_settings.video.smooth; - video_info.input_scale = 2; - g_gl = gl_init(&video_info, NULL, NULL); + video_info_t video_info = {0}; - gl_t * gl = g_gl; + // Might have to supply correct values here. + video_info.vsync = g_settings.video.vsync; + video_info.force_aspect = false; + video_info.smooth = g_settings.video.smooth; + video_info.input_scale = 2; + g_gl = gl_init(&video_info, NULL, NULL); - gl->overscan_enable = g_console.overscan_enable; - gl->overscan_amount = g_console.overscan_amount; + gl_t * gl = g_gl; - if(get_all_resolutions) - get_all_available_resolutions(); - ps3_set_resolution(); - ps3_setup_texture(); - ps3graphics_set_overscan(gl->overscan_enable, gl->overscan_amount, 0); + gl->overscan_enable = g_console.overscan_enable; + gl->overscan_amount = g_console.overscan_amount; + + if(get_all_resolutions) + get_all_available_resolutions(); + + ps3_set_resolution(); + ps3_setup_texture(); + ps3graphics_set_overscan(gl->overscan_enable, gl->overscan_amount, 0); } void ps3graphics_video_reinit(void) { - gl_t * gl = g_gl; + gl_t * gl = g_gl; - if(!gl) - return; + if(!gl) + return; - ps3_video_deinit(); - gl_cg_invalidate_context(); - ps3graphics_video_init(false); + ps3_video_deinit(); + gl_cg_invalidate_context(); + ps3graphics_video_init(false); } void ps3_video_deinit(void) { - void *data = g_gl; - g_gl = NULL; - gl_free(data); + void *data = g_gl; + g_gl = NULL; + gl_free(data); } diff --git a/ps3/salamander/main.c b/ps3/salamander/main.c index 7002e7a16a..8e05a225a4 100644 --- a/ps3/salamander/main.c +++ b/ps3/salamander/main.c @@ -67,281 +67,284 @@ SYS_PROCESS_PARAM(1001, 0x100000) static bool path_file_exists(const char *path) { - FILE *dummy = fopen(path, "rb"); - if (dummy) - { - fclose(dummy); - return true; - } - return false; + FILE *dummy = fopen(path, "rb"); + if (dummy) + { + fclose(dummy); + return true; + } + return false; } static void dir_list_free(char **dir_list) { - if (!dir_list) - return; + if (!dir_list) + return; - char **orig = dir_list; - while (*dir_list) - free(*dir_list++); - free(orig); + char **orig = dir_list; + while (*dir_list) + free(*dir_list++); + free(orig); } static char **dir_list_new(const char *dir, const char *ext) { - size_t cur_ptr = 0; - size_t cur_size = 32; - char **dir_list = NULL; + size_t cur_ptr = 0; + size_t cur_size = 32; + char **dir_list = NULL; - DIR *directory = NULL; - const struct dirent *entry = NULL; + DIR *directory = NULL; + const struct dirent *entry = NULL; - directory = opendir(dir); - if (!directory) - goto error; + directory = opendir(dir); + if (!directory) + goto error; - dir_list = (char**)calloc(cur_size, sizeof(char*)); - if (!dir_list) - goto error; + dir_list = (char**)calloc(cur_size, sizeof(char*)); + if (!dir_list) + goto error; - while ((entry = readdir(directory))) - { - // Not a perfect search of course, but hopefully good enough in practice. - if (ext && !strstr(entry->d_name, ext)) - continue; + while ((entry = readdir(directory))) + { + // Not a perfect search of course, but hopefully good enough in practice. + if (ext && !strstr(entry->d_name, ext)) + continue; - dir_list[cur_ptr] = (char*)malloc(PATH_MAX); - if (!dir_list[cur_ptr]) - goto error; + dir_list[cur_ptr] = (char*)malloc(PATH_MAX); + if (!dir_list[cur_ptr]) + goto error; - strlcpy(dir_list[cur_ptr], dir, PATH_MAX); - strlcat(dir_list[cur_ptr], "/", PATH_MAX); - strlcat(dir_list[cur_ptr], entry->d_name, PATH_MAX); + strlcpy(dir_list[cur_ptr], dir, PATH_MAX); + strlcat(dir_list[cur_ptr], "/", PATH_MAX); + strlcat(dir_list[cur_ptr], entry->d_name, PATH_MAX); - cur_ptr++; - if (cur_ptr + 1 == cur_size) // Need to reserve for NULL. - { - cur_size *= 2; - dir_list = (char**)realloc(dir_list, cur_size * sizeof(char*)); - if (!dir_list) - goto error; + cur_ptr++; + if (cur_ptr + 1 == cur_size) // Need to reserve for NULL. + { + cur_size *= 2; + dir_list = (char**)realloc(dir_list, cur_size * sizeof(char*)); + if (!dir_list) + goto error; - // Make sure it's all NULL'd out since we cannot rely on realloc to do this. - memset(dir_list + cur_ptr, 0, (cur_size - cur_ptr) * sizeof(char*)); - } - } + // Make sure it's all NULL'd out since we cannot rely on realloc to do this. + memset(dir_list + cur_ptr, 0, (cur_size - cur_ptr) * sizeof(char*)); + } + } - closedir(directory); - return dir_list; + closedir(directory); + return dir_list; error: - SSNES_ERR("Failed to open directory: \"%s\"\n", dir); - if (directory) - closedir(directory); - dir_list_free(dir_list); - return NULL; + SSNES_ERR("Failed to open directory: \"%s\"\n", dir); + + if (directory) + closedir(directory); + + dir_list_free(dir_list); + return NULL; } static void find_and_set_first_file(void) { - //Last fallback - we'll need to start the first .SELF file - // we can find in the SSNES cores directory - char ** dir_list = dir_list_new(LIBSNES_DIR_PATH, ".SELF"); - if (!dir_list) - { - SSNES_ERR("Failed last fallback - SSNES Salamander will exit.\n"); - return; - } + //Last fallback - we'll need to start the first .SELF file + // we can find in the SSNES cores directory - const char * first_self = dir_list[0]; + char ** dir_list = dir_list_new(LIBSNES_DIR_PATH, ".SELF"); + if (!dir_list) + { + SSNES_ERR("Failed last fallback - SSNES Salamander will exit.\n"); + return; + } - if(first_self) - { - SSNES_LOG("Start first entry in libretro cores dir: [%s].\n", first_self); - strlcpy(libretro_path, first_self, sizeof(libretro_path)); - } - else - { - SSNES_ERR("Failed last fallback - SSNES Salamander will exit.\n"); - } + const char * first_self = dir_list[0]; - dir_list_free(dir_list); + if(first_self) + { + SSNES_LOG("Start first entry in libretro cores dir: [%s].\n", first_self); + strlcpy(libretro_path, first_self, sizeof(libretro_path)); + } + else + { + SSNES_ERR("Failed last fallback - SSNES Salamander will exit.\n"); + } + + dir_list_free(dir_list); } static void init_settings(void) { - char tmp_str[MAX_PATH_LENGTH]; - bool config_file_exists; + char tmp_str[MAX_PATH_LENGTH]; + bool config_file_exists; - - if(!path_file_exists(SYS_CONFIG_FILE)) - { - config_file_exists = false; - SSNES_ERR("Config file \"%s\" doesn't exist. Creating...\n", SYS_CONFIG_FILE); - FILE * f; - f = fopen(SYS_CONFIG_FILE, "w"); - fclose(f); - } - else - config_file_exists = true; + if(!path_file_exists(SYS_CONFIG_FILE)) + { + FILE * f; + config_file_exists = false; + SSNES_ERR("Config file \"%s\" doesn't exist. Creating...\n", SYS_CONFIG_FILE); + f = fopen(SYS_CONFIG_FILE, "w"); + fclose(f); + } + else + config_file_exists = true; - //try to find CORE.SELF - char core_self[1024]; - snprintf(core_self, sizeof(core_self), "%s/CORE.SELF", LIBSNES_DIR_PATH); + //try to find CORE.SELF + char core_self[1024]; + snprintf(core_self, sizeof(core_self), "%s/CORE.SELF", LIBSNES_DIR_PATH); - if(path_file_exists(core_self)) - { - //Start CORE.SELF - snprintf(libretro_path, sizeof(libretro_path), core_self); - SSNES_LOG("Start [%s].\n", libretro_path); - } - else - { - if(config_file_exists) - { - config_file_t * conf = config_file_new(SYS_CONFIG_FILE); - config_get_array(conf, "libretro_path", tmp_str, sizeof(tmp_str)); - snprintf(libretro_path, sizeof(libretro_path), tmp_str); - } + if(path_file_exists(core_self)) + { + //Start CORE.SELF + snprintf(libretro_path, sizeof(libretro_path), core_self); + SSNES_LOG("Start [%s].\n", libretro_path); + } + else + { + if(config_file_exists) + { + config_file_t * conf = config_file_new(SYS_CONFIG_FILE); + config_get_array(conf, "libretro_path", tmp_str, sizeof(tmp_str)); + snprintf(libretro_path, sizeof(libretro_path), tmp_str); + } - if(!config_file_exists || !strcmp(libretro_path, "")) - find_and_set_first_file(); - else - { - SSNES_LOG("Start [%s] found in ssnes.cfg.\n", libretro_path); - } - } + if(!config_file_exists || !strcmp(libretro_path, "")) + find_and_set_first_file(); + else + { + SSNES_LOG("Start [%s] found in ssnes.cfg.\n", libretro_path); + } + } } static void get_environment_settings (void) { - unsigned int get_type; - unsigned int get_attributes; - CellGameContentSize size; - char dirName[CELL_GAME_DIRNAME_SIZE]; + unsigned int get_type; + unsigned int get_attributes; + CellGameContentSize size; + char dirName[CELL_GAME_DIRNAME_SIZE]; - memset(&size, 0x00, sizeof(CellGameContentSize)); + memset(&size, 0x00, sizeof(CellGameContentSize)); - int ret = cellGameBootCheck(&get_type, &get_attributes, &size, dirName); - if(ret < 0) - { - SSNES_ERR("cellGameBootCheck() Error: 0x%x.\n", ret); - } - else - { - SSNES_LOG("cellGameBootCheck() OK.\n"); - SSNES_LOG("Directory name: [%s].\n", dirName); - SSNES_LOG(" HDD Free Size (in KB) = [%d] Size (in KB) = [%d] System Size (in KB) = [%d].\n", size.hddFreeSizeKB, size.sizeKB, size.sysSizeKB); + int ret = cellGameBootCheck(&get_type, &get_attributes, &size, dirName); + if(ret < 0) + { + SSNES_ERR("cellGameBootCheck() Error: 0x%x.\n", ret); + } + else + { + SSNES_LOG("cellGameBootCheck() OK.\n"); + SSNES_LOG("Directory name: [%s].\n", dirName); + SSNES_LOG(" HDD Free Size (in KB) = [%d] Size (in KB) = [%d] System Size (in KB) = [%d].\n", size.hddFreeSizeKB, size.sizeKB, size.sysSizeKB); - switch(get_type) - { - case CELL_GAME_GAMETYPE_DISC: - SSNES_LOG("SSNES was launched on Optical Disc Drive.\n"); - break; - case CELL_GAME_GAMETYPE_HDD: - SSNES_LOG("SSNES was launched on HDD.\n"); - break; - } + switch(get_type) + { + case CELL_GAME_GAMETYPE_DISC: + SSNES_LOG("SSNES was launched on Optical Disc Drive.\n"); + break; + case CELL_GAME_GAMETYPE_HDD: + SSNES_LOG("SSNES was launched on HDD.\n"); + break; + } - if((get_attributes & CELL_GAME_ATTRIBUTE_APP_HOME) == CELL_GAME_ATTRIBUTE_APP_HOME) - SSNES_LOG("SSNES was launched from host machine (APP_HOME).\n"); + if((get_attributes & CELL_GAME_ATTRIBUTE_APP_HOME) == CELL_GAME_ATTRIBUTE_APP_HOME) + SSNES_LOG("SSNES was launched from host machine (APP_HOME).\n"); - ret = cellGameContentPermit(contentInfoPath, usrDirPath); + ret = cellGameContentPermit(contentInfoPath, usrDirPath); - if(ret < 0) - { - SSNES_ERR("cellGameContentPermit() Error: 0x%x\n", ret); - } - else - { - SSNES_LOG("cellGameContentPermit() OK.\n"); - SSNES_LOG("contentInfoPath : [%s].\n", contentInfoPath); - SSNES_LOG("usrDirPath : [%s].\n", usrDirPath); - } + if(ret < 0) + { + SSNES_ERR("cellGameContentPermit() Error: 0x%x\n", ret); + } + else + { + SSNES_LOG("cellGameContentPermit() OK.\n"); + SSNES_LOG("contentInfoPath : [%s].\n", contentInfoPath); + SSNES_LOG("usrDirPath : [%s].\n", usrDirPath); + } - /* now we fill in all the variables */ - snprintf(SYS_CONFIG_FILE, sizeof(SYS_CONFIG_FILE), "%s/ssnes.cfg", usrDirPath); - snprintf(LIBSNES_DIR_PATH, sizeof(LIBSNES_DIR_PATH), "%s/cores", usrDirPath); - } + /* now we fill in all the variables */ + snprintf(SYS_CONFIG_FILE, sizeof(SYS_CONFIG_FILE), "%s/ssnes.cfg", usrDirPath); + snprintf(LIBSNES_DIR_PATH, sizeof(LIBSNES_DIR_PATH), "%s/cores", usrDirPath); + } } int main(int argc, char *argv[]) { - CellPadData pad_data; - char spawn_data[256], spawn_data_size[16]; - SceNpDrmKey * k_licensee = NULL; - int ret; + CellPadData pad_data; + char spawn_data[256], spawn_data_size[16]; + SceNpDrmKey * k_licensee = NULL; + int ret; - cellSysmoduleLoadModule(CELL_SYSMODULE_IO); - cellSysmoduleLoadModule(CELL_SYSMODULE_FS); - cellSysmoduleLoadModule(CELL_SYSMODULE_SYSUTIL_GAME); - cellSysmoduleLoadModule(CELL_SYSMODULE_NET); + cellSysmoduleLoadModule(CELL_SYSMODULE_IO); + cellSysmoduleLoadModule(CELL_SYSMODULE_FS); + cellSysmoduleLoadModule(CELL_SYSMODULE_SYSUTIL_GAME); + cellSysmoduleLoadModule(CELL_SYSMODULE_NET); - cellSysmoduleLoadModule(CELL_SYSMODULE_SYSUTIL_NP); + cellSysmoduleLoadModule(CELL_SYSMODULE_SYSUTIL_NP); - sys_net_initialize_network(); + sys_net_initialize_network(); #ifdef HAVE_LOGGER - logger_init(); + logger_init(); #endif - sceNpInit(NP_POOL_SIZE, np_pool); + sceNpInit(NP_POOL_SIZE, np_pool); - get_environment_settings(); - - cellPadInit(7); + get_environment_settings(); - cellPadGetData(0, &pad_data); + cellPadInit(7); - if(pad_data.button[CELL_PAD_BTN_OFFSET_DIGITAL2] & CELL_PAD_CTRL_TRIANGLE) - { - //override path, boot first SELF in cores directory - SSNES_LOG("Fallback - Will boot first SELF in SSNES cores/ directory.\n"); - find_and_set_first_file(); - } - else - { - //normal SELF loading path - init_settings(); - } + cellPadGetData(0, &pad_data); - cellPadEnd(); + if(pad_data.button[CELL_PAD_BTN_OFFSET_DIGITAL2] & CELL_PAD_CTRL_TRIANGLE) + { + //override path, boot first SELF in cores directory + SSNES_LOG("Fallback - Will boot first SELF in SSNES cores/ directory.\n"); + find_and_set_first_file(); + } + else + { + //normal SELF loading path + init_settings(); + } + + cellPadEnd(); #ifdef HAVE_LOGGER - logger_shutdown(); + logger_shutdown(); #endif - for(unsigned int i = 0; i < sizeof(spawn_data); ++i) - spawn_data[i] = i & 0xff; + for(unsigned int i = 0; i < sizeof(spawn_data); ++i) + spawn_data[i] = i & 0xff; - sprintf(spawn_data_size, "%d", 256); + sprintf(spawn_data_size, "%d", 256); - const char * const spawn_argv[] = { - spawn_data_size, - "test argv for", - "sceNpDrmProcessExitSpawn2()", - NULL - }; + const char * const spawn_argv[] = { + spawn_data_size, + "test argv for", + "sceNpDrmProcessExitSpawn2()", + NULL + }; - ret = sceNpDrmProcessExitSpawn2(k_licensee, libretro_path, (const char** const)spawn_argv, NULL, (sys_addr_t)spawn_data, 256, 1000, SYS_PROCESS_PRIMARY_STACK_SIZE_1M); - SSNES_LOG("Launch libretro core: [%s] (return code: %x]).\n", libretro_path, ret); - if(ret < 0) - { - SSNES_LOG("SELF file is not of NPDRM type, trying another approach to boot it...\n"); - sys_game_process_exitspawn2(libretro_path, NULL, NULL, NULL, 0, 1000, SYS_PROCESS_PRIMARY_STACK_SIZE_1M); + ret = sceNpDrmProcessExitSpawn2(k_licensee, libretro_path, (const char** const)spawn_argv, NULL, (sys_addr_t)spawn_data, 256, 1000, SYS_PROCESS_PRIMARY_STACK_SIZE_1M); + SSNES_LOG("Launch libretro core: [%s] (return code: %x]).\n", libretro_path, ret); - } - sceNpTerm(); + if(ret < 0) + { + SSNES_LOG("SELF file is not of NPDRM type, trying another approach to boot it...\n"); + sys_game_process_exitspawn2(libretro_path, NULL, NULL, NULL, 0, 1000, SYS_PROCESS_PRIMARY_STACK_SIZE_1M); + } - sys_net_finalize_network(); + sceNpTerm(); - cellSysmoduleUnloadModule(CELL_SYSMODULE_SYSUTIL_NP); + sys_net_finalize_network(); - cellSysmoduleUnloadModule(CELL_SYSMODULE_NET); - cellSysmoduleUnloadModule(CELL_SYSMODULE_SYSUTIL_GAME); - cellSysmoduleLoadModule(CELL_SYSMODULE_FS); - cellSysmoduleLoadModule(CELL_SYSMODULE_IO); + cellSysmoduleUnloadModule(CELL_SYSMODULE_SYSUTIL_NP); - return 1; + cellSysmoduleUnloadModule(CELL_SYSMODULE_NET); + cellSysmoduleUnloadModule(CELL_SYSMODULE_SYSUTIL_GAME); + cellSysmoduleLoadModule(CELL_SYSMODULE_FS); + cellSysmoduleLoadModule(CELL_SYSMODULE_IO); + + return 1; }