From 12a97e675a092fbabb3bf46009c11e2e21ed1835 Mon Sep 17 00:00:00 2001 From: Twinaphex Date: Sat, 7 Jul 2012 14:06:21 +0200 Subject: [PATCH] (360/Xbox 1) Make more 360-only code generic (for Xbox 1 reuse) --- 360/xdk360_video.cpp | 151 +----------------------------- 360/xdk360_video.h | 3 + 360/xdk360_video_resources.cpp | 162 +++++++++++++++++++++++++++++++++ 360/xdk360_video_resources.h | 12 +-- console/griffin/griffin.c | 6 +- 5 files changed, 176 insertions(+), 158 deletions(-) create mode 100644 360/xdk360_video_resources.cpp diff --git a/360/xdk360_video.cpp b/360/xdk360_video.cpp index bb888eb841..28076ce421 100644 --- a/360/xdk360_video.cpp +++ b/360/xdk360_video.cpp @@ -21,7 +21,6 @@ #include "../driver.h" #include "xdk360_video.h" -#include "xdk360_video_resources.h" #ifdef HAVE_HLSL #include "../gfx/shader_hlsl.h" @@ -36,7 +35,9 @@ #include "config.h" #endif +#ifdef _XBOX360 /* Xbox 360 specific code */ +#include "xdk360_video_resources.h" const DWORD g_MapLinearToSrgbGpuFormat[] = { @@ -106,151 +107,7 @@ const DWORD g_MapLinearToSrgbGpuFormat[] = GPUTEXTUREFORMAT_2_10_10_10_FLOAT_EDRAM, }; -struct XPR_HEADER -{ - unsigned long dwMagic; - unsigned long dwHeaderSize; - unsigned long dwDataSize; -}; - -#define XPR2_MAGIC_VALUE (0x58505232) - -PackedResource::PackedResource() -{ - m_pSysMemData = NULL; - m_dwSysMemDataSize = 0L; - m_pVidMemData = NULL; - m_dwVidMemDataSize = 0L; - m_pResourceTags = NULL; - m_dwNumResourceTags = 0L; - m_bInitialized = FALSE; -} - -PackedResource::~PackedResource() -{ - Destroy(); -} - -void * PackedResource::GetData( const char * strName ) const -{ - if( m_pResourceTags == NULL || strName == NULL ) - return NULL; - - for( unsigned long i = 0; i < m_dwNumResourceTags; i++ ) - { - if( !_stricmp( strName, m_pResourceTags[i].strName ) ) - return &m_pSysMemData[m_pResourceTags[i].dwOffset]; - } - - return NULL; -} - -HRESULT PackedResource::Create( const char * strFilename ) -{ - unsigned long dwNumBytesRead; - void * hFile = CreateFile( strFilename, GENERIC_READ, FILE_SHARE_READ, NULL, - OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, NULL ); - - if( hFile == INVALID_HANDLE_VALUE ) - { - RARCH_ERR( "File <%s> not found.\n", strFilename ); - return E_FAIL; - } - - // Read in and verify the XPR magic header - XPR_HEADER xprh; - if( !ReadFile( hFile, &xprh, sizeof( XPR_HEADER ), &dwNumBytesRead, NULL ) ) - { - RARCH_ERR( "Error reading XPR header in file <%s>.\n", strFilename ); - CloseHandle( hFile ); - return E_FAIL; - } - - if( xprh.dwMagic != XPR2_MAGIC_VALUE ) - { - RARCH_ERR( "Invalid Xbox Packed Resource (.xpr) file: Magic = 0x%08lx.\n", xprh.dwMagic ); - CloseHandle( hFile ); - return E_FAIL; - } - - // Compute memory requirements - m_dwSysMemDataSize = xprh.dwHeaderSize; - m_dwVidMemDataSize = xprh.dwDataSize; - - // Allocate memory - m_pSysMemData = (unsigned char*)malloc(m_dwSysMemDataSize); - if( m_pSysMemData == NULL ) - { - RARCH_ERR( "Could not allocate system memory.\n" ); - m_dwSysMemDataSize = 0; - return E_FAIL; - } - m_pVidMemData = ( unsigned char* )XMemAlloc( m_dwVidMemDataSize, MAKE_XALLOC_ATTRIBUTES( 0, 0, 0, 0, eXALLOCAllocatorId_GameMax, - XALLOC_PHYSICAL_ALIGNMENT_4K, XALLOC_MEMPROTECT_WRITECOMBINE, 0, XALLOC_MEMTYPE_PHYSICAL ) ); - - if( m_pVidMemData == NULL ) - { - RARCH_ERR( "Could not allocate physical memory.\n" ); - m_dwSysMemDataSize = 0; - m_dwVidMemDataSize = 0; - free(m_pSysMemData); - m_pSysMemData = NULL; - return E_FAIL; - } - - // Read in the data from the file - if( !ReadFile( hFile, m_pSysMemData, m_dwSysMemDataSize, &dwNumBytesRead, NULL ) || - !ReadFile( hFile, m_pVidMemData, m_dwVidMemDataSize, &dwNumBytesRead, NULL ) ) - { - RARCH_ERR( "Unable to read Xbox Packed Resource (.xpr) file.\n" ); - CloseHandle( hFile ); - return E_FAIL; - } - - // Done with the file - CloseHandle( hFile ); - - // Extract resource table from the header data - m_dwNumResourceTags = *( unsigned long * )( m_pSysMemData + 0 ); - m_pResourceTags = ( RESOURCE* )( m_pSysMemData + 4 ); - - // Patch up the resources - for( unsigned long i = 0; i < m_dwNumResourceTags; i++ ) - { - m_pResourceTags[i].strName = ( char * )( m_pSysMemData + ( unsigned long )m_pResourceTags[i].strName ); - - // Fixup the texture memory - if( ( m_pResourceTags[i].dwType & 0xffff0000 ) == ( RESOURCETYPE_TEXTURE & 0xffff0000 ) ) - { - D3DTexture* pTexture = ( D3DTexture* )&m_pSysMemData[m_pResourceTags[i].dwOffset]; - // Adjust Base address according to where memory was allocated - XGOffsetBaseTextureAddress( pTexture, m_pVidMemData, m_pVidMemData ); - } - } - - m_bInitialized = TRUE; - - return 0; -} - -void PackedResource::Destroy() -{ - free(m_pSysMemData); - m_pSysMemData = NULL; - m_dwSysMemDataSize = 0L; - - if( m_pVidMemData != NULL ) - XMemFree( m_pVidMemData, MAKE_XALLOC_ATTRIBUTES( 0, 0, 0, 0, eXALLOCAllocatorId_GameMax, - 0, 0, 0, XALLOC_MEMTYPE_PHYSICAL ) ); - - m_pVidMemData = NULL; - m_dwVidMemDataSize = 0L; - - m_pResourceTags = NULL; - m_dwNumResourceTags = 0L; - - m_bInitialized = FALSE; -} +#endif /* end of Xbox 360 specific code */ @@ -940,7 +797,7 @@ const video_driver_t video_xdk360 = { xdk360_focus, NULL, xdk360_free, - "xdk360", + "xdk_gfx", xdk360_start, xdk360_stop, xdk360_restart, diff --git a/360/xdk360_video.h b/360/xdk360_video.h index 504a459b1e..c1cf4caeeb 100644 --- a/360/xdk360_video.h +++ b/360/xdk360_video.h @@ -18,7 +18,10 @@ #define _XDK360_VIDEO_H #include + +#ifdef _XBOX360 #include "../gfx/fonts/xdk360_fonts.h" +#endif #define DFONT_MAX 4096 #define PRIM_FVF (D3DFVF_XYZRHW | D3DFVF_TEX1) diff --git a/360/xdk360_video_resources.cpp b/360/xdk360_video_resources.cpp new file mode 100644 index 0000000000..d4a79b5139 --- /dev/null +++ b/360/xdk360_video_resources.cpp @@ -0,0 +1,162 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2010-2012 - Hans-Kristian Arntzen + * Copyright (C) 2011-2012 - Daniel De Matteis + * + * RetroArch is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with RetroArch. + * If not, see . + */ + +#include "xdk360_video_resources.h" + +struct XPR_HEADER +{ + unsigned long dwMagic; + unsigned long dwHeaderSize; + unsigned long dwDataSize; +}; + +#define XPR2_MAGIC_VALUE (0x58505232) + +PackedResource::PackedResource() +{ + m_pSysMemData = NULL; + m_dwSysMemDataSize = 0L; + m_pVidMemData = NULL; + m_dwVidMemDataSize = 0L; + m_pResourceTags = NULL; + m_dwNumResourceTags = 0L; + m_bInitialized = FALSE; +} + +PackedResource::~PackedResource() +{ + Destroy(); +} + +void * PackedResource::GetData( const char * strName ) const +{ + if( m_pResourceTags == NULL || strName == NULL ) + return NULL; + + for( unsigned long i = 0; i < m_dwNumResourceTags; i++ ) + { if( !_stricmp( strName, m_pResourceTags[i].strName ) ) + return &m_pSysMemData[m_pResourceTags[i].dwOffset]; + } + + return NULL; +} + +HRESULT PackedResource::Create( const char * strFilename ) +{ + unsigned long dwNumBytesRead; + void * hFile = CreateFile( strFilename, GENERIC_READ, FILE_SHARE_READ, NULL, + OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, NULL ); + + if( hFile == INVALID_HANDLE_VALUE ) + { + RARCH_ERR( "File <%s> not found.\n", strFilename ); + return E_FAIL; + } + + // Read in and verify the XPR magic header + XPR_HEADER xprh; + if( !ReadFile( hFile, &xprh, sizeof( XPR_HEADER ), &dwNumBytesRead, NULL ) ) + { + RARCH_ERR( "Error reading XPR header in file <%s>.\n", strFilename ); + CloseHandle( hFile ); + return E_FAIL; + } + + if( xprh.dwMagic != XPR2_MAGIC_VALUE ) + { + RARCH_ERR( "Invalid Xbox Packed Resource (.xpr) file: Magic = 0x%08lx.\n", xprh.dwMagic ); + CloseHandle( hFile ); + return E_FAIL; + } + + // Compute memory requirements + m_dwSysMemDataSize = xprh.dwHeaderSize; + m_dwVidMemDataSize = xprh.dwDataSize; + + // Allocate memory + m_pSysMemData = (unsigned char*)malloc(m_dwSysMemDataSize); + if( m_pSysMemData == NULL ) + { + RARCH_ERR( "Could not allocate system memory.\n" ); + m_dwSysMemDataSize = 0; + return E_FAIL; + } + m_pVidMemData = ( unsigned char* )XMemAlloc( m_dwVidMemDataSize, MAKE_XALLOC_ATTRIBUTES( 0, 0, 0, 0, eXALLOCAllocatorId_GameMax, + XALLOC_PHYSICAL_ALIGNMENT_4K, XALLOC_MEMPROTECT_WRITECOMBINE, 0, XALLOC_MEMTYPE_PHYSICAL ) ); + + if( m_pVidMemData == NULL ) + { + RARCH_ERR( "Could not allocate physical memory.\n" ); + m_dwSysMemDataSize = 0; + m_dwVidMemDataSize = 0; + free(m_pSysMemData); + m_pSysMemData = NULL; + return E_FAIL; + } + + // Read in the data from the file + if( !ReadFile( hFile, m_pSysMemData, m_dwSysMemDataSize, &dwNumBytesRead, NULL ) || + !ReadFile( hFile, m_pVidMemData, m_dwVidMemDataSize, &dwNumBytesRead, NULL ) ) + { + RARCH_ERR( "Unable to read Xbox Packed Resource (.xpr) file.\n" ); + CloseHandle( hFile ); + return E_FAIL; + } + + // Done with the file + CloseHandle( hFile ); + + // Extract resource table from the header data + m_dwNumResourceTags = *( unsigned long * )( m_pSysMemData + 0 ); + m_pResourceTags = ( RESOURCE* )( m_pSysMemData + 4 ); + + // Patch up the resources + for( unsigned long i = 0; i < m_dwNumResourceTags; i++ ) + { + m_pResourceTags[i].strName = ( char * )( m_pSysMemData + ( unsigned long )m_pResourceTags[i].strName ); + + // Fixup the texture memory + if( ( m_pResourceTags[i].dwType & 0xffff0000 ) == ( RESOURCETYPE_TEXTURE & 0xffff0000 ) ) + { + D3DTexture* pTexture = ( D3DTexture* )&m_pSysMemData[m_pResourceTags[i].dwOffset]; + // Adjust Base address according to where memory was allocated + XGOffsetBaseTextureAddress( pTexture, m_pVidMemData, m_pVidMemData ); + } + } + + m_bInitialized = TRUE; + + return 0; +} + +void PackedResource::Destroy() +{ + free(m_pSysMemData); + m_pSysMemData = NULL; + m_dwSysMemDataSize = 0L; + + if( m_pVidMemData != NULL ) + XMemFree( m_pVidMemData, MAKE_XALLOC_ATTRIBUTES( 0, 0, 0, 0, eXALLOCAllocatorId_GameMax, + 0, 0, 0, XALLOC_MEMTYPE_PHYSICAL ) ); + + m_pVidMemData = NULL; + m_dwVidMemDataSize = 0L; + + m_pResourceTags = NULL; + m_dwNumResourceTags = 0L; + + m_bInitialized = FALSE; +} diff --git a/360/xdk360_video_resources.h b/360/xdk360_video_resources.h index d8de8b76d3..9bcd7e28f7 100644 --- a/360/xdk360_video_resources.h +++ b/360/xdk360_video_resources.h @@ -14,8 +14,6 @@ * If not, see . */ -#pragma once - #ifndef RARCH_360_RESOURCES_H #define RARCH_360_RESOURCES_H @@ -39,21 +37,15 @@ enum RESOURCETYPE_EOF = 0xffffffff }; - -//-------------------------------------------------------------------------------------- -// Name: PackedResource -//-------------------------------------------------------------------------------------- class PackedResource { protected: unsigned char * m_pSysMemData; // Alloc'ed memory for resource headers etc. - unsigned long m_dwSysMemDataSize; - unsigned char * m_pVidMemData; // Alloc'ed memory for resource data, etc. + unsigned long m_dwSysMemDataSize; unsigned long m_dwVidMemDataSize; - - RESOURCE* m_pResourceTags; // Tags to associate names with the resources unsigned long m_dwNumResourceTags; // Number of resource tags + RESOURCE* m_pResourceTags; // Tags to associate names with the resources public: int m_bInitialized; // Resource is fully initialized HRESULT Create( const char * strFilename ); diff --git a/console/griffin/griffin.c b/console/griffin/griffin.c index c56b0017eb..eab6bbea2c 100644 --- a/console/griffin/griffin.c +++ b/console/griffin/griffin.c @@ -93,11 +93,15 @@ VIDEO DRIVER #elif defined(HAVE_OPENGLES20) #include "../../gfx/gles.c" #elif defined(_XBOX360) -#include "../../360/xdk360_video.cpp" +#include "../../360/xdk360_video_resources.cpp" #elif defined(GEKKO) #include "../../wii/video.c" #endif +#ifdef _XBOX +#include "../../360/xdk360_video.cpp" +#endif + #include "../../gfx/null.c" /*============================================================