From 2fd7c1bb9f273fae0cfb91c57b861c342a0dca3a Mon Sep 17 00:00:00 2001 From: TwinAphex51224 Date: Sun, 22 Jan 2012 01:43:54 +0100 Subject: [PATCH] (360) Add preliminary WIP XUI menu code - far from complete --- 360/main.c | 33 ++++++- 360/menu.cpp | 92 ++++++++++++++++++++ 360/menu.h | 24 +++++ 360/xdk360_video.cpp | 42 ++++----- 360/xdk360_video.h | 13 +++ msvc-360/SSNES-360/SSNES-360.vcxproj | 1 + msvc-360/SSNES-360/SSNES-360.vcxproj.filters | 3 + 7 files changed, 177 insertions(+), 31 deletions(-) create mode 100644 360/menu.cpp create mode 100644 360/menu.h diff --git a/360/main.c b/360/main.c index 54c0936996..499d888b7b 100644 --- a/360/main.c +++ b/360/main.c @@ -17,16 +17,41 @@ */ #include -#include -#include #include #include +#include "menu.h" #include "xdk360_video.h" +CSSNES app; + int ssnes_main(int argc, char *argv[]); #undef main -// Temporary, a more sane implementation should go here. + +int xui_init (void) +{ + HRESULT hr; + + xdk360_video_t *vid = (xdk360_video_t*)g_d3d; + + hr = app.InitShared(vid->xdk360_render_device, &vid->d3dpp, XuiTextureLoader); + + if (FAILED(hr)) + { + OutputDebugString("Failed initializing XUI application.\n"); + return 1; + } + + /* Register font */ + hr = app.RegisterDefaultTypeface(L"Arial Unicode MS", L"file://game:/media/ssnes.ttf" ); + if (FAILED(hr)) + { + OutputDebugString("Failed to register default typeface.\n"); + return 1; + } + + return 0; +} int main(int argc, char *argv[]) { @@ -44,6 +69,6 @@ int main(int argc, char *argv[]) char *argv_[] = { arg1, arg2, arg3, arg4, arg5, NULL }; return ssnes_main(sizeof(argv_) / sizeof(argv_[0]) - 1, argv_); - xdk360_video_deinit(); + xdk360_video_deinit(); } diff --git a/360/menu.cpp b/360/menu.cpp new file mode 100644 index 0000000000..1601887071 --- /dev/null +++ b/360/menu.cpp @@ -0,0 +1,92 @@ +/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes. + * Copyright (C) 2010-2012 - Hans-Kristian Arntzen + * Copyright (C) 2011-2012 - Daniel De Matteis + * + * Some code herein may be based on code found in BSNES. + * + * SSNES 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. + * + * SSNES 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 SSNES. + * If not, see . + */ + +#include +#include "xdkxui.h" + +/* Register custom classes */ +HRESULT CSSNES::RegisterXuiClasses (void) +{ + return CSSNESMain::Register(); +} + +/* Unregister custom classes */ +HRESULT CSSNES::UnregisterXuiClasses (void) +{ + return CSSNESMain::Unregister(); + return S_OK; +} + +HRESULT APIENTRY XuiTextureLoader(IXuiDevice *pDevice, LPCWSTR szFileName, XUIImageInfo *pImageInfo, IDirect3DTexture9 **ppTex) +{ + CONST BYTE *pbTextureData = 0; + UINT cbTextureData = 0; + HXUIRESOURCE hResource = 0; + BOOL bIsMemoryResource = FALSE; + HRESULT hr; + + + hr = XuiResourceOpen(szFileName, &hResource, &bIsMemoryResource); + if (FAILED(hr)) + return hr; + + if (bIsMemoryResource) + { + hr = XuiResourceGetBuffer(hResource, &pbTextureData); + if (FAILED(hr)) + goto cleanup; + cbTextureData = XuiResourceGetTotalSize(hResource); + } + else + { + hr = XuiResourceRead(hResource, NULL, 0, &cbTextureData); + if (FAILED(hr)) + goto cleanup; + + pbTextureData = (BYTE *)XuiAlloc(cbTextureData); + if (pbTextureData == 0) + { + hr = E_OUTOFMEMORY; + goto cleanup; + } + + hr = XuiResourceRead(hResource, (BYTE*)pbTextureData, cbTextureData, &cbTextureData); + if (FAILED(hr)) + goto cleanup; + + XuiResourceClose(hResource); + hResource = 0; + + } + + //Format specific code should be added here to initialize pImageInfo + // and to create an IDirect3DTexture9 interface. + + +cleanup: + + if (bIsMemoryResource && hResource != 0) + XuiResourceReleaseBuffer(hResource, pbTextureData); + else + XuiFree((LPVOID)pbTextureData); + + if (hResource != 0) + XuiResourceClose(hResource); + + return hr; +} \ No newline at end of file diff --git a/360/menu.h b/360/menu.h new file mode 100644 index 0000000000..c7d4d46bff --- /dev/null +++ b/360/menu.h @@ -0,0 +1,24 @@ +#ifndef _MENU_XUI_H_ +#define _MENU_XUI_H_ + +#include +#include + +class CSSNES : public CXuiModule +{ +protected: + /* Override so that Cssnes can register classes */ + virtual HRESULT RegisterXuiClasses(); + /* Override so that Cssnes can unregister classes */ + virtual HRESULT UnregisterXuiClasses(); +}; + +class CSSNESMain: public CXuiSceneImpl +{ +public: + XUI_IMPLEMENT_CLASS(CSSNESMain, L"CSSNESMain", XUI_CLASS_SCENE) +}; + +HRESULT APIENTRY XuiTextureLoader(IXuiDevice *pDevice, LPCWSTR szFileName, XUIImageInfo *pImageInfo, IDirect3DTexture9 **ppTex); + +#endif diff --git a/360/xdk360_video.cpp b/360/xdk360_video.cpp index c1f115932e..e2c9cfadf3 100644 --- a/360/xdk360_video.cpp +++ b/360/xdk360_video.cpp @@ -1,5 +1,6 @@ /* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes. - * Copyright (C) 2010-2011 - Hans-Kristian Arntzen + * Copyright (C) 2010-2012 - Hans-Kristian Arntzen + * Copyright (C) 2011-2012 - Daniel De Matteis * * Some code herein may be based on code found in BSNES. * @@ -70,18 +71,6 @@ static bool g_quitting; unsigned g_frame_count; void *g_d3d; -typedef struct xdk360_video -{ - IDirect3D9* xdk360_device; - IDirect3DDevice9* xdk360_render_device; - IDirect3DVertexShader9 *pVertexShader; - IDirect3DPixelShader9* pPixelShader; - IDirect3DVertexDeclaration9* pVertexDecl; - IDirect3DVertexBuffer9* vertex_buf; - IDirect3DTexture9* lpTexture; - unsigned last_width, last_height; -} xdk360_video_t; - static void xdk360_gfx_free(void * data) { if (g_d3d) @@ -118,22 +107,21 @@ static void *xdk360_gfx_init(const video_info_t *video, const input_driver_t **i return NULL; } - D3DPRESENT_PARAMETERS d3dpp; - ZeroMemory(&d3dpp, sizeof(d3dpp)); + ZeroMemory(&vid->d3dpp, sizeof(vid->d3dpp)); - d3dpp.BackBufferWidth = 1280; - d3dpp.BackBufferHeight = 720; - d3dpp.BackBufferFormat = (D3DFORMAT)MAKESRGBFMT(D3DFMT_A8R8G8B8); - d3dpp.FrontBufferFormat = (D3DFORMAT)MAKESRGBFMT(D3DFMT_LE_X8R8G8B8); - d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE; - d3dpp.MultiSampleQuality = 0; - d3dpp.BackBufferCount = 2; - d3dpp.EnableAutoDepthStencil = TRUE; - d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8; - d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; - d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_ONE; + vid->d3dpp.BackBufferWidth = 1280; + vid->d3dpp.BackBufferHeight = 720; + vid->d3dpp.BackBufferFormat = (D3DFORMAT)MAKESRGBFMT(D3DFMT_A8R8G8B8); + vid->d3dpp.FrontBufferFormat = (D3DFORMAT)MAKESRGBFMT(D3DFMT_LE_X8R8G8B8); + vid->d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE; + vid->d3dpp.MultiSampleQuality = 0; + vid->d3dpp.BackBufferCount = 2; + vid->d3dpp.EnableAutoDepthStencil = TRUE; + vid->d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8; + vid->d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; + vid->d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_ONE; - vid->xdk360_device->CreateDevice(0, D3DDEVTYPE_HAL, NULL, D3DCREATE_HARDWARE_VERTEXPROCESSING, &d3dpp, + vid->xdk360_device->CreateDevice(0, D3DDEVTYPE_HAL, NULL, D3DCREATE_HARDWARE_VERTEXPROCESSING, &vid->d3dpp, &vid->xdk360_render_device); ID3DXBuffer* pShaderCodeV = NULL; diff --git a/360/xdk360_video.h b/360/xdk360_video.h index ee1fbd302d..c81576b904 100644 --- a/360/xdk360_video.h +++ b/360/xdk360_video.h @@ -19,6 +19,19 @@ #ifndef _XDK360_VIDEO_H #define _XDK360_VIDEO_H +typedef struct xdk360_video +{ + IDirect3D9* xdk360_device; + IDirect3DDevice9* xdk360_render_device; + IDirect3DVertexShader9 *pVertexShader; + IDirect3DPixelShader9* pPixelShader; + IDirect3DVertexDeclaration9* pVertexDecl; + IDirect3DVertexBuffer9* vertex_buf; + IDirect3DTexture9* lpTexture; + unsigned last_width, last_height; + D3DPRESENT_PARAMETERS d3dpp; +} xdk360_video_t; + void xdk360_video_init(void); void xdk360_video_deinit(void); diff --git a/msvc-360/SSNES-360/SSNES-360.vcxproj b/msvc-360/SSNES-360/SSNES-360.vcxproj index 3bfee135ee..9717ab7d80 100644 --- a/msvc-360/SSNES-360/SSNES-360.vcxproj +++ b/msvc-360/SSNES-360/SSNES-360.vcxproj @@ -241,6 +241,7 @@ + diff --git a/msvc-360/SSNES-360/SSNES-360.vcxproj.filters b/msvc-360/SSNES-360/SSNES-360.vcxproj.filters index ea36fd3e71..4123f615fd 100644 --- a/msvc-360/SSNES-360/SSNES-360.vcxproj.filters +++ b/msvc-360/SSNES-360/SSNES-360.vcxproj.filters @@ -110,6 +110,9 @@ Source Files\conf + + Source Files\360 +