From: notaz Date: Mon, 28 Jan 2008 19:28:53 +0000 (+0000) Subject: tweaking win32 port X-Git-Tag: v1.85~588 X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8831ef19a03770189816740eb2304ad2cb9a07a7;p=picodrive.git tweaking win32 port git-svn-id: file:///home/notaz/opt/svn/PicoDrive@339 be3aeb3a-fb24-0410-a615-afba39da0efa --- diff --git a/platform/win32/GenaDrive/DSound.cpp b/platform/win32/GenaDrive/DSound.cpp index 9884972a..5c9cc0c1 100644 --- a/platform/win32/GenaDrive/DSound.cpp +++ b/platform/win32/GenaDrive/DSound.cpp @@ -12,7 +12,6 @@ static IDirectSoundBuffer *LoopBuffer=NULL; static int LoopLen=0,LoopWrite=0; // Next position in loop to write short *DSoundNext=NULL; // Buffer for next sound data to put in loop -//int DSoundSeg=0; // Seg length in samples static int LoopBlank() { @@ -102,7 +101,7 @@ int DSoundUpdate() DWORD play=0; int pos=0; - if (LoopBuffer==NULL) return 1; + if (LoopBuffer==NULL) return -1; LoopBuffer->GetCurrentPosition(&play,NULL); pos=play>>((PicoOpt&8) ? 2 : 1); @@ -121,10 +120,12 @@ int DSoundUpdate() void DSoundMute() { + if (LoopBuffer==NULL) return; LoopBuffer->Stop(); } void DSoundUnMute() { + if (LoopBuffer==NULL) return; LoopBuffer->Play(0,0,DSBPLAY_LOOPING); } diff --git a/platform/win32/GenaDrive/Direct.cpp b/platform/win32/GenaDrive/Direct.cpp index b6f4285b..8277bce9 100644 --- a/platform/win32/GenaDrive/Direct.cpp +++ b/platform/win32/GenaDrive/Direct.cpp @@ -21,7 +21,8 @@ int DirectInit() { D3DPRESENT_PARAMETERS d3dpp; D3DDISPLAYMODE mode; - int i=0,ret=0; + D3DDEVTYPE dt = D3DDEVTYPE_HAL; + int i,u,ret=0; memset(&d3dpp,0,sizeof(d3dpp)); memset(&mode,0,sizeof(mode)); @@ -44,25 +45,21 @@ int DirectInit() #endif // Try to create a device with hardware vertex processing: - for (i=0;i<4;i++) + for (u=0;u<2;u++) { - int behave=D3DCREATE_HARDWARE_VERTEXPROCESSING; - -#ifdef _XBOX - if (i==1) + for (i=0;i<4;i++) { - // If 60Hz didn't work, try PAL 50Hz instead: - d3dpp.FullScreen_RefreshRateInHz=0; - d3dpp.BackBufferHeight=MainHeight=576; - } -#endif + int behave=D3DCREATE_HARDWARE_VERTEXPROCESSING; - // Try software vertex processing: - if (i==2) behave=D3DCREATE_MIXED_VERTEXPROCESSING; - if (i==3) behave=D3DCREATE_SOFTWARE_VERTEXPROCESSING; + // Try software vertex processing: + if (i==1) behave=D3DCREATE_MIXED_VERTEXPROCESSING; + if (i==2) behave=D3DCREATE_SOFTWARE_VERTEXPROCESSING; - Direct3D->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,FrameWnd,behave,&d3dpp,&Device); + Direct3D->CreateDevice(D3DADAPTER_DEFAULT,dt,FrameWnd,behave,&d3dpp,&Device); + if (Device) break; + } if (Device) break; + dt = D3DDEVTYPE_REF; } if (Device==NULL) return 1; @@ -184,12 +181,14 @@ static int SetupMatrices() int DirectScreen() { unsigned char *lock=NULL; + int ret; // Copy the screen to the screen texture: #ifdef _XBOX TexScreenSwizzle(); #else - TexScreenLinear(); + ret=TexScreenLinear(); + if (ret) dprintf2("TexScreenLinear failed\n"); #endif SetupMatrices(); @@ -197,14 +196,19 @@ int DirectScreen() MakeVertexList(); // Copy vertices in: - VertexBuffer->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1; + VertexBuffer->Lock(0,sizeof(VertexList),&lock,0); + if (lock==NULL) { dprintf2("VertexBuffer->Lock failed\n"); return 1; } memcpy(lock,VertexList,sizeof(VertexList)); VertexBuffer->Unlock(); - Device->SetTexture(0,TexScreen); - Device->SetStreamSource(0,VertexBuffer,sizeof(CustomVertex)); - Device->SetVertexShader(D3DFVF_CUSTOMVERTEX); - Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2); - + ret=Device->SetTexture(0,TexScreen); + if (ret) dprintf2("SetTexture failed\n"); + ret=Device->SetStreamSource(0,VertexBuffer,sizeof(CustomVertex)); + if (ret) dprintf2("SetStreamSource failed\n"); + ret=Device->SetVertexShader(D3DFVF_CUSTOMVERTEX); + if (ret) dprintf2("SetVertexShader failed\n"); + ret=Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2); + if (ret) dprintf2("DrawPrimitive failed\n"); + return 0; } diff --git a/platform/win32/GenaDrive/Emu.cpp b/platform/win32/GenaDrive/Emu.cpp index 4e5bc950..d93abafc 100644 --- a/platform/win32/GenaDrive/Emu.cpp +++ b/platform/win32/GenaDrive/Emu.cpp @@ -2,9 +2,7 @@ #include "app.h" unsigned short *EmuScreen=NULL; -extern "C" unsigned short *framebuff=NULL; int EmuWidth=0,EmuHeight=0; -static int frame=0; static int EmuScan(unsigned int num, void *sdata); unsigned char *PicoDraw2FB = NULL; @@ -18,10 +16,9 @@ int EmuInit() EmuWidth=320; EmuHeight=224; len=EmuWidth*EmuHeight; len<<=1; EmuScreen=(unsigned short *)malloc(len); if (EmuScreen==NULL) return 1; - framebuff=(unsigned short *)malloc((8+320)*(8+224+8)*2); + PicoDraw2FB=(unsigned char *)malloc((8+320)*(8+224+8)*2); memset(EmuScreen,0,len); - PicoDraw2FB = (unsigned char *)framebuff; PicoDrawSetColorFormat(1); PicoScan=EmuScan; @@ -32,7 +29,7 @@ void EmuExit() { //RomFree(); free(EmuScreen); EmuScreen=NULL; // Deallocate screen - free(framebuff); + free(PicoDraw2FB); EmuWidth=EmuHeight=0; PicoExit(); @@ -50,7 +47,7 @@ static int EmuScan(unsigned int num, void *sdata) pd=EmuScreen+(num<<8)+(num<<6); end=pd+320; ps=(unsigned short *)sdata; - do { *pd++=*ps++; } while (pd -extern char *romname; -extern unsigned char *rom_data; -extern unsigned int rom_size; -extern int fastForward; -extern int frameStep; -extern int emu_frame; - struct Input Inp; // --------------------- XBox Input ----------------------------- @@ -123,25 +116,27 @@ static int DeviceRead() else if(!sblobked && GetAsyncKeyState(VK_TAB)) { PicoReset(0); sblobked = 1; - emu_frame = 0; } - else if(!sblobked && GetAsyncKeyState(VK_ESCAPE)) { - DSoundMute(); + else if(!sblobked && GetAsyncKeyState(VK_ESCAPE)) + { + unsigned char *rom_data; + unsigned int rom_size; + DSoundMute(); pm_file *rom = 0; OPENFILENAME of; ZeroMemory(&of, sizeof(OPENFILENAME)); - of.lStructSize = sizeof(OPENFILENAME); - of.lpstrFilter = "ROMs\0*.smd;*.bin;*.gen\0"; - of.lpstrFile = romname; romname[0] = 0; - of.nMaxFile = MAX_PATH; - of.Flags = OFN_FILEMUSTEXIST|OFN_HIDEREADONLY; - GetOpenFileName(&of); - rom = pm_open(romname); - DSoundUnMute(); - if(!rom) return 1; + of.lStructSize = sizeof(OPENFILENAME); + of.lpstrFilter = "ROMs\0*.smd;*.bin;*.gen\0"; + of.lpstrFile = romname; romname[0] = 0; + of.nMaxFile = MAX_PATH; + of.Flags = OFN_FILEMUSTEXIST|OFN_HIDEREADONLY; + GetOpenFileName(&of); + rom = pm_open(romname); + DSoundUnMute(); + if(!rom) return 1; PicoCartLoad(rom, &rom_data, &rom_size); PicoCartInsert(rom_data, rom_size); - pm_close(rom); - sblobked = 1; + pm_close(rom); + sblobked = 1; } else sblobked = GetAsyncKeyState(VK_F6) | GetAsyncKeyState(VK_F9) | diff --git a/platform/win32/GenaDrive/Loop.cpp b/platform/win32/GenaDrive/Loop.cpp index 2781a913..305c27df 100644 --- a/platform/win32/GenaDrive/Loop.cpp +++ b/platform/win32/GenaDrive/Loop.cpp @@ -1,10 +1,6 @@ #include "app.h" //#include "FileMenu.h" -extern char *romname; -int fastForward=0; -int frameStep=0; - char LoopQuit=0; static FILE *DebugFile=NULL; int LoopMode=0; @@ -17,9 +13,8 @@ int LoopInit() // bits LSb->MSb: // enable_ym2612&dac, enable_sn76496, enable_z80, stereo_sound; // alt_renderer, 6button_gamepad, accurate_timing, accurate_sprites - PicoOpt=0x1f; + PicoOpt=0xbccf; PsndRate=44100; - //PsndLen=PsndRate/60; // calculated later by pico itself // Init Direct3D: ret=DirectInit(); if (ret) { error("Direct3D init failed"); return 1; } @@ -55,18 +50,9 @@ void LoopExit() // ---------------------------------------------------------------- -int emu_frame = 0; - static int DoGame() { - if(fastForward) { PicoSkipFrame+=1; PicoSkipFrame&=7; } - else PicoSkipFrame=0; - - if(frameStep==1) return 0; - else if(frameStep==3) frameStep=1; - EmuFrame(); - emu_frame++; if (Inp.held[7]==1) LoopMode=2; // Right thumb = Toggle Menu @@ -144,9 +130,8 @@ static int ModeRender() static void UpdateSound(int len) { - if(fastForward) return; - while (DSoundUpdate()) { Sleep(1); } - while (DSoundUpdate()==0) { } + while (DSoundUpdate() > 0) { Sleep(1); } + while (DSoundUpdate()== 0) { } } int LoopCode() diff --git a/platform/win32/GenaDrive/Main.cpp b/platform/win32/GenaDrive/Main.cpp index a8e3362e..acc8fcdc 100644 --- a/platform/win32/GenaDrive/Main.cpp +++ b/platform/win32/GenaDrive/Main.cpp @@ -1,5 +1,5 @@ - #include "app.h" +#include "version.h" #include #include @@ -8,42 +8,6 @@ HWND FrameWnd=NULL; int MainWidth=720,MainHeight=480; -char AppName[]="GenaDrive"; - -#ifdef STARSCREAM - extern "C" int SekReset(); -#endif - -// ------------------------------------ XBox Main ------------------------------------------ -#ifdef _XBOX - -static int MainCode() -{ - int ret=0; - - ret=LoopInit(); if (ret) { LoopExit(); return 1; } - - LoopQuit=0; LoopCode(); - LoopExit(); - - return 0; -} - -int __cdecl main() -{ - LD_LAUNCH_DASHBOARD launch; - - MainCode(); - - // Go back to dashboard: - memset(&launch,0,sizeof(launch)); - launch.dwReason=XLD_LAUNCH_DASHBOARD_MAIN_MENU; - XLaunchNewImage(NULL,(LAUNCH_DATA *)&launch); -} -#endif - -// ----------------------------------- Windows Main ---------------------------------------- -#ifndef _XBOX // Window proc for the frame window: static LRESULT CALLBACK WndProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam) { @@ -88,7 +52,7 @@ static int FrameInit() top-=height; top>>=1; // Create the window: - FrameWnd=CreateWindow(wc.lpszClassName,AppName,style|WS_VISIBLE, + FrameWnd=CreateWindow(wc.lpszClassName,"PicoDrive " VERSION,style|WS_VISIBLE, left,top,width,height,NULL,NULL,NULL,NULL); return 0; @@ -102,19 +66,17 @@ static DWORD WINAPI ThreadCode(void *) return 0; } -// starscream needs this -unsigned char *rom_data = 0; -unsigned int rom_size = 0; - int WINAPI WinMain(HINSTANCE,HINSTANCE,LPSTR cmdline,int) { MSG msg; int ret=0; DWORD tid=0; HANDLE thread=NULL; + unsigned char *rom_data = 0; + unsigned int rom_size = 0; FrameInit(); - ret=LoopInit(); if (ret) { LoopExit(); return 1; } + ret=LoopInit(); if (ret) goto end0; // notaz: load rom static char rompath[MAX_PATH]; rompath[0] = 0; @@ -125,27 +87,29 @@ int WINAPI WinMain(HINSTANCE,HINSTANCE,LPSTR cmdline,int) if(strlen(rompath) > 4) rom = pm_open(rompath); if(!rom) { OPENFILENAME of; ZeroMemory(&of, sizeof(OPENFILENAME)); - of.lStructSize = sizeof(OPENFILENAME); - of.lpstrFilter = "ROMs\0*.smd;*.bin;*.gen\0"; - of.lpstrFile = rompath; rompath[0] = 0; - of.nMaxFile = MAX_PATH; - of.Flags = OFN_FILEMUSTEXIST|OFN_HIDEREADONLY; - if(!GetOpenFileName(&of)) return 1; - rom = pm_open(rompath); - if(!rom) return 1; + of.lStructSize = sizeof(OPENFILENAME); + of.lpstrFilter = "ROMs\0*.smd;*.bin;*.gen;*.zip\0"; + of.lpstrFile = rompath; rompath[0] = 0; + of.nMaxFile = MAX_PATH; + of.Flags = OFN_FILEMUSTEXIST|OFN_HIDEREADONLY; + if(!GetOpenFileName(&of)) goto end0; + rom = pm_open(rompath); + if(!rom) goto end0; } romname = rompath; - if(PicoCartLoad(rom, &rom_data, &rom_size)) { - //RDebug::Print(_L("PicoCartLoad() failed.")); - //goto cleanup; - } + ret=PicoCartLoad(rom, &rom_data, &rom_size); pm_close(rom); + if (ret) { + error("failed to load ROM"); + goto end0; + } PicoCartInsert(rom_data, rom_size); // only now we got the mode (pal/ntsc), so init sound now - DSoundInit(); + ret=DSoundInit(); + if (ret) error("Failed to init DirectSound"); // warning // Make another thread to run LoopCode(): LoopQuit=0; @@ -165,6 +129,7 @@ int WINAPI WinMain(HINSTANCE,HINSTANCE,LPSTR cmdline,int) LoopQuit=1; WaitForSingleObject(thread,5000); CloseHandle(thread); thread=NULL; +end0: LoopExit(); DestroyWindow(FrameWnd); @@ -178,5 +143,4 @@ extern void error(char *text) { MessageBox(FrameWnd, text, "Error", 0); } -#endif diff --git a/platform/win32/GenaDrive/TexScreen.cpp b/platform/win32/GenaDrive/TexScreen.cpp index 45eeab73..d656a877 100644 --- a/platform/win32/GenaDrive/TexScreen.cpp +++ b/platform/win32/GenaDrive/TexScreen.cpp @@ -86,7 +86,8 @@ int TexScreenLinear() int y=0,line=0; unsigned short *ps=NULL; - TexScreen->LockRect(0,&lock,NULL,0); if (lock.pBits==NULL) return 1; + TexScreen->LockRect(0,&lock,NULL,0); + if (lock.pBits==NULL) return 1; dest=(unsigned char *)lock.pBits; ps=EmuScreen; @@ -98,7 +99,7 @@ int TexScreenLinear() for (x=0; x -#ifdef _XBOX -#include -#endif - -#ifndef _XBOX #define WIN32_LEAN_AND_MEAN #include #include -#endif #include @@ -19,11 +13,6 @@ #define RELEASE(x) if (x) x->Release(); x=NULL; -#ifdef _XBOX -#define HOME "d:\\" -#else -#define HOME ".\\" -#endif // Emu.cpp extern unsigned short *EmuScreen; @@ -63,9 +52,9 @@ int LoopCode(); extern "C" int dprintf2(char *format, ...); // Main.cpp +extern char *romname; extern HWND FrameWnd; extern int MainWidth,MainHeight; -extern char AppName[]; extern void error(char *text); // Rom.cpp diff --git a/platform/win32/GenaDrive/version.h b/platform/win32/GenaDrive/version.h new file mode 100644 index 00000000..95717b1c --- /dev/null +++ b/platform/win32/GenaDrive/version.h @@ -0,0 +1,2 @@ +#define VERSION "1.40" +