-\r
#include "app.h"\r
\r
// d3d\r
// ddraw\r
#include <ddraw.h>\r
\r
-LPDIRECTDRAW7 m_pDD;\r
-LPDIRECTDRAWSURFACE7 m_pddsFrontBuffer;\r
-LPDIRECTDRAWSURFACE7 m_pddsBackBuffer;\r
+LPDIRECTDRAW7 m_pDD = NULL;\r
+LPDIRECTDRAWSURFACE7 m_pddsFrontBuffer = NULL;\r
+LPDIRECTDRAWSURFACE7 m_pddsBackBuffer = NULL;\r
\r
// quick and dirty stuff..\r
+static void DirectExitDDraw()\r
+{\r
+ RELEASE(m_pddsBackBuffer);\r
+ RELEASE(m_pddsFrontBuffer);\r
+ RELEASE(m_pDD);\r
+}\r
+\r
static int DirectDrawInit()\r
{\r
HRESULT ret;\r
+ LPDIRECTDRAWCLIPPER pcClipper = NULL;\r
+ DDSURFACEDESC2 ddsd;\r
\r
ret = DirectDrawCreateEx(NULL, (VOID**)&m_pDD, IID_IDirectDraw7, NULL);\r
if (ret) { LOGFAIL(); return 1; }\r
\r
// Set cooperative level\r
ret = m_pDD->SetCooperativeLevel( FrameWnd, DDSCL_NORMAL );\r
- if (ret) { LOGFAIL(); return 1; }\r
+ if (ret) { LOGFAIL(); goto fail; }\r
\r
// Create the primary surface\r
- DDSURFACEDESC2 ddsd;\r
ZeroMemory( &ddsd, sizeof( ddsd ) );\r
ddsd.dwSize = sizeof( ddsd );\r
ddsd.dwFlags = DDSD_CAPS;\r
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;\r
\r
ret = m_pDD->CreateSurface( &ddsd, &m_pddsFrontBuffer, NULL );\r
- if (ret) { LOGFAIL(); return 1; }\r
+ if (ret) { LOGFAIL(); goto fail; }\r
\r
// Create the backbuffer surface\r
- ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT; \r
+ ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;\r
ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;\r
- ddsd.dwWidth = 320;\r
- ddsd.dwHeight = 240;\r
+ ddsd.dwWidth = EmuWidth;\r
+ ddsd.dwHeight = EmuHeight;\r
\r
ret = m_pDD->CreateSurface( &ddsd, &m_pddsBackBuffer, NULL );\r
- if (ret) { LOGFAIL(); return 1; }\r
+ if (ret) { LOGFAIL(); goto fail; }\r
\r
// clipper\r
- LPDIRECTDRAWCLIPPER pcClipper = NULL;\r
ret = m_pDD->CreateClipper( 0, &pcClipper, NULL );\r
- if (ret) { LOGFAIL(); return 1; }\r
+ if (ret) { LOGFAIL(); goto fail; }\r
\r
ret = pcClipper->SetHWnd( 0, FrameWnd );\r
- if (ret) { LOGFAIL(); return 1; }\r
+ if (ret) { LOGFAIL(); goto fail; }\r
\r
ret = m_pddsFrontBuffer->SetClipper( pcClipper );\r
- if (ret) { LOGFAIL(); return 1; }\r
+ if (ret) { LOGFAIL(); goto fail; }\r
\r
RELEASE(pcClipper);\r
+ return 0;\r
\r
-#if 0\r
+fail:\r
+ RELEASE(pcClipper);\r
+ DirectExitDDraw();\r
+ return 1;\r
+}\r
+\r
+static int DirectScreenDDraw()\r
+{\r
DDSURFACEDESC2 sd;\r
+ unsigned short *ps=EmuScreen;\r
+ int ret, x, y;\r
+\r
memset(&sd, 0, sizeof(sd));\r
sd.dwSize = sizeof(sd);\r
ret = m_pddsBackBuffer->Lock(NULL, &sd, DDLOCK_SURFACEMEMORYPTR|DDLOCK_WAIT|DDLOCK_WRITEONLY, NULL);\r
if (ret) { LOGFAIL(); return 1; }\r
\r
- memset(sd.lpSurface, 0xcc, 200*200);\r
+ //dprintf2("w: %i h: %i pi: %i pf: %i\n", sd.dwWidth, sd.dwHeight, sd.lPitch, sd.ddpfPixelFormat.dwRGBBitCount);\r
+\r
+ if (sd.ddpfPixelFormat.dwRGBBitCount == 32)\r
+ {\r
+ int *dst = (int *)sd.lpSurface;\r
+ for (y = 0; y < EmuHeight; y++)\r
+ {\r
+ for (x = 0; x < EmuWidth; x++)\r
+ {\r
+ int s = *ps++;\r
+ dst[x] = ((s&0xf800)<<8) | ((s&0x07e0)<<5) | ((s&0x001f)<<3);\r
+ }\r
+ dst = (int *)((char *)dst + sd.lPitch);\r
+ }\r
+ }\r
+ else if (sd.ddpfPixelFormat.dwRGBBitCount == 16)\r
+ {\r
+ unsigned short *dst = (unsigned short *)sd.lpSurface;\r
+ for (y = 0; y < EmuHeight; y++)\r
+ {\r
+ memcpy(dst, ps, EmuWidth*2);\r
+ ps += EmuWidth;\r
+ dst = (unsigned short *)((char *)dst + sd.lPitch);\r
+ }\r
+ }\r
+ else\r
+ {\r
+ LOGFAIL();\r
+ }\r
\r
ret = m_pddsBackBuffer->Unlock(NULL);\r
if (ret) { LOGFAIL(); return 1; }\r
-#else\r
- DDBLTFX ddbltfx;\r
- ZeroMemory( &ddbltfx, sizeof(ddbltfx) );\r
- ddbltfx.dwSize = sizeof(ddbltfx);\r
- ddbltfx.dwFillColor = 0xff00;\r
+ return 0;\r
+}\r
\r
- ret = m_pddsBackBuffer->Blt( NULL, NULL, NULL, DDBLT_COLORFILL, &ddbltfx );\r
-#endif\r
+static int DirectClearDDraw(unsigned int colour)\r
+{\r
+ int ret;\r
+ DDBLTFX ddbltfx;\r
+ ZeroMemory( &ddbltfx, sizeof(ddbltfx) );\r
+ ddbltfx.dwSize = sizeof(ddbltfx);\r
+ ddbltfx.dwFillColor = colour;\r
\r
- ret = m_pddsFrontBuffer->Blt(NULL, m_pddsBackBuffer, NULL, DDBLT_WAIT, NULL);\r
- if (ret) { LOGFAIL(); return 1; }\r
-Sleep(2000);\r
-/* Sleep(500);\r
- ret = m_pddsFrontBuffer->Blt(NULL, m_pddsBackBuffer, NULL, DDBLT_WAIT, NULL);\r
+ if (m_pddsBackBuffer != NULL)\r
+ ret = m_pddsBackBuffer->Blt( NULL, NULL, NULL, DDBLT_COLORFILL, &ddbltfx );\r
if (ret) { LOGFAIL(); return 1; }\r
- Sleep(500);\r
- ret = m_pddsFrontBuffer->Blt(NULL, m_pddsBackBuffer, NULL, DDBLT_WAIT, NULL);\r
+ return 0;\r
+}\r
+\r
+static int DirectPresentDDraw()\r
+{\r
+ int ret = m_pddsFrontBuffer->Blt(&FrameRectMy, m_pddsBackBuffer, NULL, DDBLT_WAIT, NULL);\r
if (ret) { LOGFAIL(); return 1; }\r
-*/\r
return 0;\r
}\r
\r
\r
+/* D3D */\r
+\r
int DirectInit()\r
{\r
- D3DPRESENT_PARAMETERS d3dpp; \r
+ D3DPRESENT_PARAMETERS d3dpp;\r
D3DDISPLAYMODE mode;\r
int i,u,ret=0;\r
\r
d3dpp.BackBufferHeight=MainHeight;\r
d3dpp.BackBufferCount =1;\r
d3dpp.SwapEffect=D3DSWAPEFFECT_DISCARD;\r
+ d3dpp.MultiSampleType =D3DMULTISAMPLE_NONE;\r
\r
#ifdef _XBOX\r
d3dpp.BackBufferFormat=D3DFMT_X8R8G8B8;\r
Direct3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT,&mode);\r
d3dpp.BackBufferFormat=mode.Format;\r
d3dpp.Windowed=1;\r
+ d3dpp.hDeviceWindow=FrameWnd;\r
#endif\r
\r
// Try to create a device with hardware vertex processing:\r
//FontExit();\r
TexScreenExit();\r
\r
+ // d3d\r
RELEASE(VertexBuffer)\r
RELEASE(DirectBack)\r
RELEASE(Device)\r
RELEASE(Direct3D)\r
+\r
+ DirectExitDDraw();\r
}\r
\r
\r
\r
int DirectClear(unsigned int colour)\r
{\r
+ if (Device == NULL)\r
+ return DirectClearDDraw(colour);\r
+\r
Device->Clear(0,NULL,D3DCLEAR_TARGET,colour,1.0f,0);\r
return 0;\r
}\r
\r
int DirectPresent()\r
{\r
+ if (Device == NULL)\r
+ return DirectPresentDDraw();\r
+\r
Device->Present(NULL,NULL,NULL,NULL);\r
return 0;\r
}\r
float nudgex=0.0f,nudgey=0.0f;\r
\r
memset(&mat,0,sizeof(mat));\r
- \r
+\r
mat.m[0][0]=mat.m[1][1]=mat.m[2][2]=mat.m[3][3]=1.0f;\r
Device->SetTransform(D3DTS_WORLD,&mat);\r
\r
unsigned char *lock=NULL;\r
int ret;\r
\r
+ if (Device == NULL)\r
+ return DirectScreenDDraw();\r
+\r
// Copy the screen to the screen texture:\r
#ifdef _XBOX\r
TexScreenSwizzle();\r
memcpy(lock,VertexList,sizeof(VertexList));\r
VertexBuffer->Unlock();\r
\r
- ret=Device->BeginScene();\r
- if (ret) dprintf2("BeginScene failed\n");\r
- ret=Device->SetTexture(0,TexScreen);\r
- if (ret) dprintf2("SetTexture failed\n");\r
- ret=Device->SetStreamSource(0,VertexBuffer,sizeof(CustomVertex));\r
- if (ret) dprintf2("SetStreamSource failed\n");\r
- ret=Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);\r
- if (ret) dprintf2("SetVertexShader failed\n");\r
- ret=Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);\r
- if (ret) dprintf2("DrawPrimitive failed\n");\r
- ret=Device->EndScene();\r
- if (ret) dprintf2("EndScene failed\n");\r
+ Device->BeginScene();\r
+ Device->SetTexture(0,TexScreen);\r
+ Device->SetStreamSource(0,VertexBuffer,sizeof(CustomVertex));\r
+ Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);\r
+ Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);\r
+ Device->EndScene();\r
\r
return 0;\r
}\r
\r
char *romname;\r
HWND FrameWnd=NULL;\r
+RECT FrameRectMy;\r
\r
int MainWidth=720,MainHeight=480;\r
\r
// Window proc for the frame window:\r
static LRESULT CALLBACK WndProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam)\r
{\r
- if (msg==WM_CLOSE) { PostQuitMessage(0); return 0; }\r
- if (msg==WM_DESTROY) FrameWnd=NULL; // Blank handle\r
+ switch (msg)\r
+ {\r
+ case WM_CLOSE: PostQuitMessage(0); return 0;\r
+ case WM_DESTROY: FrameWnd=NULL; break; // Blank handle\r
+ case WM_SIZE:\r
+ case WM_MOVE:\r
+ case WM_SIZING: GetWindowRect(hwnd, &FrameRectMy); break;\r
+ }\r
\r
return DefWindowProc(hwnd,msg,wparam,lparam);\r
}\r
FrameWnd=CreateWindow(wc.lpszClassName,"PicoDrive " VERSION,style|WS_VISIBLE,\r
left,top,width,height,NULL,NULL,NULL,NULL);\r
\r
+ ShowWindow(FrameWnd, SW_NORMAL);\r
+ UpdateWindow(FrameWnd);\r
+ GetWindowRect(FrameWnd, &FrameRectMy);\r
+\r
return 0;\r
}\r
\r
unsigned char *rom_data = 0;\r
unsigned int rom_size = 0;\r
\r
+ static char rompath[MAX_PATH] = { 0, };\r
+ pm_file *rom = NULL;\r
+\r
FrameInit();\r
ret=LoopInit(); if (ret) goto end0;\r
\r
// notaz: load rom\r
- static char rompath[MAX_PATH]; rompath[0] = 0;\r
strcpy(rompath, cmdline + (cmdline[0] == '\"' ? 1 : 0));\r
if(rompath[strlen(rompath)-1] == '\"') rompath[strlen(rompath)-1] = 0;\r
\r
- pm_file *rom = 0;\r
if(strlen(rompath) > 4) rom = pm_open(rompath);\r
if(!rom) {\r
OPENFILENAME of; ZeroMemory(&of, sizeof(OPENFILENAME));\r