From 03a265e5ebabff7adbb4f97387f81e9b0428dbee Mon Sep 17 00:00:00 2001 From: notaz Date: Tue, 29 Jan 2008 23:04:26 +0000 Subject: [PATCH] win32 stuff, SIMPLE_WRITE_SOUND git-svn-id: file:///home/notaz/opt/svn/PicoDrive@341 be3aeb3a-fb24-0410-a615-afba39da0efa --- Pico/Pico.c | 6 + Pico/sound/sound.c | 2 + platform/gizmondo/port_config.h | 1 + platform/gp2x/port_config.h | 1 + platform/linux/port_config.h | 3 +- platform/psp/port_config.h | 1 + platform/win32/GenaDrive/DSound.cpp | 7 +- platform/win32/GenaDrive/Direct.cpp | 149 +++++++++++++++++-------- platform/win32/GenaDrive/Emu.cpp | 6 +- platform/win32/GenaDrive/Loop.cpp | 6 +- platform/win32/GenaDrive/Main.cpp | 20 +++- platform/win32/GenaDrive/Makefile.vc | 10 ++ platform/win32/GenaDrive/app.h | 5 + platform/win32/GenaDrive/port_config.h | 1 + 14 files changed, 161 insertions(+), 57 deletions(-) diff --git a/Pico/Pico.c b/Pico/Pico.c index 93d68764..71add131 100644 --- a/Pico/Pico.c +++ b/Pico/Pico.c @@ -255,6 +255,11 @@ static int CheckIdle(void) // to be called on 224 or line_sample scanlines only static __inline void getSamples(int y) { +#if SIMPLE_WRITE_SOUND + PsndRender(0, PsndLen); + if (PicoWriteSound) PicoWriteSound(PsndLen); + PsndClear(); +#else static int curr_pos = 0; if(y == 224) { @@ -271,6 +276,7 @@ static __inline void getSamples(int y) emustatus&=~1; curr_pos = PsndRender(0, PsndLen/2); } +#endif } diff --git a/Pico/sound/sound.c b/Pico/sound/sound.c index fbb81c89..64e172a0 100644 --- a/Pico/sound/sound.c +++ b/Pico/sound/sound.c @@ -232,6 +232,7 @@ PICO_INTERNAL int PsndRender(int offset, int length) int do_pcm = (PicoMCD&1) && (PicoOpt&0x400) && (Pico_mcd->pcm.control & 0x80) && Pico_mcd->pcm.enabled; offset <<= stereo; +#if !SIMPLE_WRITE_SOUND if (offset == 0) { // should happen once per frame // compensate for float part of PsndLen PsndLen_exc_cnt += PsndLen_exc_add; @@ -240,6 +241,7 @@ PICO_INTERNAL int PsndRender(int offset, int length) length++; } } +#endif // PSG if (PicoOpt & 2) diff --git a/platform/gizmondo/port_config.h b/platform/gizmondo/port_config.h index 13e46406..6a6f8165 100644 --- a/platform/gizmondo/port_config.h +++ b/platform/gizmondo/port_config.h @@ -6,6 +6,7 @@ #define CASE_SENSITIVE_FS 0 #define DONT_OPEN_MANY_FILES 0 #define REDUCE_IO_CALLS 0 +#define SIMPLE_WRITE_SOUND 0 // draw.c #define OVERRIDE_HIGHCOL 1 diff --git a/platform/gp2x/port_config.h b/platform/gp2x/port_config.h index 1503593f..fe0fcea3 100644 --- a/platform/gp2x/port_config.h +++ b/platform/gp2x/port_config.h @@ -6,6 +6,7 @@ #define CASE_SENSITIVE_FS 1 // CS filesystem #define DONT_OPEN_MANY_FILES 0 #define REDUCE_IO_CALLS 0 +#define SIMPLE_WRITE_SOUND 0 // draw.c #define OVERRIDE_HIGHCOL 0 diff --git a/platform/linux/port_config.h b/platform/linux/port_config.h index 0d9a5263..21e5b32d 100644 --- a/platform/linux/port_config.h +++ b/platform/linux/port_config.h @@ -12,9 +12,10 @@ // pico.c #define CAN_HANDLE_240_LINES 1 +#define SIMPLE_WRITE_SOUND 0 #define mix_32_to_16l_stereo_lvl mix_32_to_16l_stereo -#define EL_LOGMASK (EL_ANOMALY|EL_STATUS|EL_SRAMIO|EL_EEPROM|EL_UIO|EL_SVP) +#define EL_LOGMASK (EL_ANOMALY|EL_STATUS|EL_SRAMIO|EL_EEPROM|EL_UIO)//|EL_VDPDMA|EL_HVCNT|EL_ASVDP)//|EL_SVP) // EL_VDPDMA|EL_ASVDP|EL_SR) // |EL_BUSREQ|EL_Z80BNK) //#define dprintf(f,...) printf("%05i:%03i: " f "\n",Pico.m.frame_count,Pico.m.scanline,##__VA_ARGS__) diff --git a/platform/psp/port_config.h b/platform/psp/port_config.h index 93cffa74..3bd139df 100644 --- a/platform/psp/port_config.h +++ b/platform/psp/port_config.h @@ -6,6 +6,7 @@ #define CASE_SENSITIVE_FS 0 #define DONT_OPEN_MANY_FILES 1 // work around the stupid PSP ~10 open file limit #define REDUCE_IO_CALLS 1 // another workaround +#define SIMPLE_WRITE_SOUND 0 // draw.c #define USE_BGR555 1 diff --git a/platform/win32/GenaDrive/DSound.cpp b/platform/win32/GenaDrive/DSound.cpp index 5c9cc0c1..05e7f02a 100644 --- a/platform/win32/GenaDrive/DSound.cpp +++ b/platform/win32/GenaDrive/DSound.cpp @@ -45,7 +45,7 @@ int DSoundInit() wfx.nAvgBytesPerSec=wfx.nBlockAlign*wfx.nSamplesPerSec; // Make buffer for the next seg to put into the loop: - DSoundNext=(short *)malloc(PsndLen<<2); if (DSoundNext==NULL) return 1; + DSoundNext=(short *)malloc((PsndLen<<2)+64); if (DSoundNext==NULL) return 1; memset(DSoundNext,0,PsndLen<<2); // Create the DirectSound interface: @@ -89,7 +89,10 @@ static int WriteSeg() // Lock the segment at 'LoopWrite' and copy the next segment in LoopBuffer->Lock(LoopWrite<<((PicoOpt&8) ? 2 : 1),PsndLen<<((PicoOpt&8) ? 2 : 1), &mema,&sizea, &memb,&sizeb, 0); + //dprintf2("lock %p, cpy %x\n", mema, sizea); + if (mema) memcpy(mema,DSoundNext,sizea); +// if (memb) memcpy(memb,DSoundNext+sizea,sizeb); LoopBuffer->Unlock(mema,sizea, memb,0); @@ -106,6 +109,8 @@ int DSoundUpdate() LoopBuffer->GetCurrentPosition(&play,NULL); pos=play>>((PicoOpt&8) ? 2 : 1); + //dprintf2("loop %i pos %i\n", LoopWrite, pos); + // 'LoopWrite' is the next seg in the loop that we want to write // First check that the sound 'play' pointer has moved out of it: if (pos>=LoopWrite && pos -LPDIRECTDRAW7 m_pDD; -LPDIRECTDRAWSURFACE7 m_pddsFrontBuffer; -LPDIRECTDRAWSURFACE7 m_pddsBackBuffer; +LPDIRECTDRAW7 m_pDD = NULL; +LPDIRECTDRAWSURFACE7 m_pddsFrontBuffer = NULL; +LPDIRECTDRAWSURFACE7 m_pddsBackBuffer = NULL; // quick and dirty stuff.. +static void DirectExitDDraw() +{ + RELEASE(m_pddsBackBuffer); + RELEASE(m_pddsFrontBuffer); + RELEASE(m_pDD); +} + static int DirectDrawInit() { HRESULT ret; + LPDIRECTDRAWCLIPPER pcClipper = NULL; + DDSURFACEDESC2 ddsd; ret = DirectDrawCreateEx(NULL, (VOID**)&m_pDD, IID_IDirectDraw7, NULL); if (ret) { LOGFAIL(); return 1; } // Set cooperative level ret = m_pDD->SetCooperativeLevel( FrameWnd, DDSCL_NORMAL ); - if (ret) { LOGFAIL(); return 1; } + if (ret) { LOGFAIL(); goto fail; } // Create the primary surface - DDSURFACEDESC2 ddsd; ZeroMemory( &ddsd, sizeof( ddsd ) ); ddsd.dwSize = sizeof( ddsd ); ddsd.dwFlags = DDSD_CAPS; ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; ret = m_pDD->CreateSurface( &ddsd, &m_pddsFrontBuffer, NULL ); - if (ret) { LOGFAIL(); return 1; } + if (ret) { LOGFAIL(); goto fail; } // Create the backbuffer surface - ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT; + ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT; ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE; - ddsd.dwWidth = 320; - ddsd.dwHeight = 240; + ddsd.dwWidth = EmuWidth; + ddsd.dwHeight = EmuHeight; ret = m_pDD->CreateSurface( &ddsd, &m_pddsBackBuffer, NULL ); - if (ret) { LOGFAIL(); return 1; } + if (ret) { LOGFAIL(); goto fail; } // clipper - LPDIRECTDRAWCLIPPER pcClipper = NULL; ret = m_pDD->CreateClipper( 0, &pcClipper, NULL ); - if (ret) { LOGFAIL(); return 1; } + if (ret) { LOGFAIL(); goto fail; } ret = pcClipper->SetHWnd( 0, FrameWnd ); - if (ret) { LOGFAIL(); return 1; } + if (ret) { LOGFAIL(); goto fail; } ret = m_pddsFrontBuffer->SetClipper( pcClipper ); - if (ret) { LOGFAIL(); return 1; } + if (ret) { LOGFAIL(); goto fail; } RELEASE(pcClipper); + return 0; -#if 0 +fail: + RELEASE(pcClipper); + DirectExitDDraw(); + return 1; +} + +static int DirectScreenDDraw() +{ DDSURFACEDESC2 sd; + unsigned short *ps=EmuScreen; + int ret, x, y; + memset(&sd, 0, sizeof(sd)); sd.dwSize = sizeof(sd); ret = m_pddsBackBuffer->Lock(NULL, &sd, DDLOCK_SURFACEMEMORYPTR|DDLOCK_WAIT|DDLOCK_WRITEONLY, NULL); if (ret) { LOGFAIL(); return 1; } - memset(sd.lpSurface, 0xcc, 200*200); + //dprintf2("w: %i h: %i pi: %i pf: %i\n", sd.dwWidth, sd.dwHeight, sd.lPitch, sd.ddpfPixelFormat.dwRGBBitCount); + + if (sd.ddpfPixelFormat.dwRGBBitCount == 32) + { + int *dst = (int *)sd.lpSurface; + for (y = 0; y < EmuHeight; y++) + { + for (x = 0; x < EmuWidth; x++) + { + int s = *ps++; + dst[x] = ((s&0xf800)<<8) | ((s&0x07e0)<<5) | ((s&0x001f)<<3); + } + dst = (int *)((char *)dst + sd.lPitch); + } + } + else if (sd.ddpfPixelFormat.dwRGBBitCount == 16) + { + unsigned short *dst = (unsigned short *)sd.lpSurface; + for (y = 0; y < EmuHeight; y++) + { + memcpy(dst, ps, EmuWidth*2); + ps += EmuWidth; + dst = (unsigned short *)((char *)dst + sd.lPitch); + } + } + else + { + LOGFAIL(); + } ret = m_pddsBackBuffer->Unlock(NULL); if (ret) { LOGFAIL(); return 1; } -#else - DDBLTFX ddbltfx; - ZeroMemory( &ddbltfx, sizeof(ddbltfx) ); - ddbltfx.dwSize = sizeof(ddbltfx); - ddbltfx.dwFillColor = 0xff00; + return 0; +} - ret = m_pddsBackBuffer->Blt( NULL, NULL, NULL, DDBLT_COLORFILL, &ddbltfx ); -#endif +static int DirectClearDDraw(unsigned int colour) +{ + int ret; + DDBLTFX ddbltfx; + ZeroMemory( &ddbltfx, sizeof(ddbltfx) ); + ddbltfx.dwSize = sizeof(ddbltfx); + ddbltfx.dwFillColor = colour; - ret = m_pddsFrontBuffer->Blt(NULL, m_pddsBackBuffer, NULL, DDBLT_WAIT, NULL); - if (ret) { LOGFAIL(); return 1; } -Sleep(2000); -/* Sleep(500); - ret = m_pddsFrontBuffer->Blt(NULL, m_pddsBackBuffer, NULL, DDBLT_WAIT, NULL); + if (m_pddsBackBuffer != NULL) + ret = m_pddsBackBuffer->Blt( NULL, NULL, NULL, DDBLT_COLORFILL, &ddbltfx ); if (ret) { LOGFAIL(); return 1; } - Sleep(500); - ret = m_pddsFrontBuffer->Blt(NULL, m_pddsBackBuffer, NULL, DDBLT_WAIT, NULL); + return 0; +} + +static int DirectPresentDDraw() +{ + int ret = m_pddsFrontBuffer->Blt(&FrameRectMy, m_pddsBackBuffer, NULL, DDBLT_WAIT, NULL); if (ret) { LOGFAIL(); return 1; } -*/ return 0; } +/* D3D */ + int DirectInit() { - D3DPRESENT_PARAMETERS d3dpp; + D3DPRESENT_PARAMETERS d3dpp; D3DDISPLAYMODE mode; int i,u,ret=0; @@ -119,6 +168,7 @@ int DirectInit() d3dpp.BackBufferHeight=MainHeight; d3dpp.BackBufferCount =1; d3dpp.SwapEffect=D3DSWAPEFFECT_DISCARD; + d3dpp.MultiSampleType =D3DMULTISAMPLE_NONE; #ifdef _XBOX d3dpp.BackBufferFormat=D3DFMT_X8R8G8B8; @@ -127,6 +177,7 @@ int DirectInit() Direct3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT,&mode); d3dpp.BackBufferFormat=mode.Format; d3dpp.Windowed=1; + d3dpp.hDeviceWindow=FrameWnd; #endif // Try to create a device with hardware vertex processing: @@ -201,10 +252,13 @@ void DirectExit() //FontExit(); TexScreenExit(); + // d3d RELEASE(VertexBuffer) RELEASE(DirectBack) RELEASE(Device) RELEASE(Direct3D) + + DirectExitDDraw(); } @@ -251,12 +305,18 @@ static int MakeVertexList() int DirectClear(unsigned int colour) { + if (Device == NULL) + return DirectClearDDraw(colour); + Device->Clear(0,NULL,D3DCLEAR_TARGET,colour,1.0f,0); return 0; } int DirectPresent() { + if (Device == NULL) + return DirectPresentDDraw(); + Device->Present(NULL,NULL,NULL,NULL); return 0; } @@ -270,7 +330,7 @@ static int SetupMatrices() float nudgex=0.0f,nudgey=0.0f; memset(&mat,0,sizeof(mat)); - + mat.m[0][0]=mat.m[1][1]=mat.m[2][2]=mat.m[3][3]=1.0f; Device->SetTransform(D3DTS_WORLD,&mat); @@ -297,6 +357,9 @@ int DirectScreen() unsigned char *lock=NULL; int ret; + if (Device == NULL) + return DirectScreenDDraw(); + // Copy the screen to the screen texture: #ifdef _XBOX TexScreenSwizzle(); @@ -315,18 +378,12 @@ int DirectScreen() memcpy(lock,VertexList,sizeof(VertexList)); VertexBuffer->Unlock(); - ret=Device->BeginScene(); - if (ret) dprintf2("BeginScene failed\n"); - 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"); - ret=Device->EndScene(); - if (ret) dprintf2("EndScene failed\n"); + Device->BeginScene(); + Device->SetTexture(0,TexScreen); + Device->SetStreamSource(0,VertexBuffer,sizeof(CustomVertex)); + Device->SetVertexShader(D3DFVF_CUSTOMVERTEX); + Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2); + Device->EndScene(); return 0; } diff --git a/platform/win32/GenaDrive/Emu.cpp b/platform/win32/GenaDrive/Emu.cpp index 79938b2c..75f6f698 100644 --- a/platform/win32/GenaDrive/Emu.cpp +++ b/platform/win32/GenaDrive/Emu.cpp @@ -2,7 +2,7 @@ #include "app.h" unsigned short *EmuScreen=NULL; -int EmuWidth=0,EmuHeight=0; +int EmuWidth=320,EmuHeight=224; static int EmuScan(unsigned int num, void *sdata); unsigned char *PicoDraw2FB = NULL; @@ -66,7 +66,9 @@ int EmuFrame() PicoPad[0]=input; - PsndOut=(short *)DSoundNext; PicoFrame(); PsndOut=NULL; + PsndOut=(short *)DSoundNext; + PicoFrame(); + //PsndOut=NULL; return 0; } diff --git a/platform/win32/GenaDrive/Loop.cpp b/platform/win32/GenaDrive/Loop.cpp index 305c27df..b4b3eec3 100644 --- a/platform/win32/GenaDrive/Loop.cpp +++ b/platform/win32/GenaDrive/Loop.cpp @@ -13,11 +13,11 @@ int LoopInit() // bits LSb->MSb: // enable_ym2612&dac, enable_sn76496, enable_z80, stereo_sound; // alt_renderer, 6button_gamepad, accurate_timing, accurate_sprites - PicoOpt=0xbccf; + PicoOpt=0xbcc7; PsndRate=44100; // Init Direct3D: - ret=DirectInit(); if (ret) { error("Direct3D init failed"); return 1; } + ret=DirectInit(); if (ret) { error("DirectX video init failed"); return 1; } InputInit(); // Init DirectSound: @@ -108,7 +108,7 @@ static int ModeUpdate() if (LoopMode==8) { DoGame(); return 0; } - if (DSoundNext) memset(DSoundNext,0,PsndLen<<2); +// if (DSoundNext) memset(DSoundNext,0,PsndLen<<2); // if (LoopMode==2) { FileMenu.scan(); LoopMode++; return 0; } // if (LoopMode==3) { MenuUpdate(); return 0; } diff --git a/platform/win32/GenaDrive/Main.cpp b/platform/win32/GenaDrive/Main.cpp index acc8fcdc..f5f41cc3 100644 --- a/platform/win32/GenaDrive/Main.cpp +++ b/platform/win32/GenaDrive/Main.cpp @@ -5,14 +5,21 @@ char *romname; HWND FrameWnd=NULL; +RECT FrameRectMy; int MainWidth=720,MainHeight=480; // Window proc for the frame window: static LRESULT CALLBACK WndProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam) { - if (msg==WM_CLOSE) { PostQuitMessage(0); return 0; } - if (msg==WM_DESTROY) FrameWnd=NULL; // Blank handle + switch (msg) + { + case WM_CLOSE: PostQuitMessage(0); return 0; + case WM_DESTROY: FrameWnd=NULL; break; // Blank handle + case WM_SIZE: + case WM_MOVE: + case WM_SIZING: GetWindowRect(hwnd, &FrameRectMy); break; + } return DefWindowProc(hwnd,msg,wparam,lparam); } @@ -55,6 +62,10 @@ static int FrameInit() FrameWnd=CreateWindow(wc.lpszClassName,"PicoDrive " VERSION,style|WS_VISIBLE, left,top,width,height,NULL,NULL,NULL,NULL); + ShowWindow(FrameWnd, SW_NORMAL); + UpdateWindow(FrameWnd); + GetWindowRect(FrameWnd, &FrameRectMy); + return 0; } @@ -75,15 +86,16 @@ int WINAPI WinMain(HINSTANCE,HINSTANCE,LPSTR cmdline,int) unsigned char *rom_data = 0; unsigned int rom_size = 0; + static char rompath[MAX_PATH] = { 0, }; + pm_file *rom = NULL; + FrameInit(); ret=LoopInit(); if (ret) goto end0; // notaz: load rom - static char rompath[MAX_PATH]; rompath[0] = 0; strcpy(rompath, cmdline + (cmdline[0] == '\"' ? 1 : 0)); if(rompath[strlen(rompath)-1] == '\"') rompath[strlen(rompath)-1] = 0; - pm_file *rom = 0; if(strlen(rompath) > 4) rom = pm_open(rompath); if(!rom) { OPENFILENAME of; ZeroMemory(&of, sizeof(OPENFILENAME)); diff --git a/platform/win32/GenaDrive/Makefile.vc b/platform/win32/GenaDrive/Makefile.vc index 896b8b97..3a3b44fe 100644 --- a/platform/win32/GenaDrive/Makefile.vc +++ b/platform/win32/GenaDrive/Makefile.vc @@ -55,3 +55,13 @@ PicoDrive.exe : $(OBJ) clean: -del $(OBJ) PicoDrive.exe + + +test.exe : test.cpp + cl $(CFLAGS) test.cpp user32.lib d3dx8.lib d3d8.lib + +dxtut1.exe : dxtut1.cpp + cl $(CFLAGS) dxtut1.cpp user32.lib d3d8.lib + +# d3dx8.lib + diff --git a/platform/win32/GenaDrive/app.h b/platform/win32/GenaDrive/app.h index 3113a297..12a5ea99 100644 --- a/platform/win32/GenaDrive/app.h +++ b/platform/win32/GenaDrive/app.h @@ -13,6 +13,10 @@ #define RELEASE(x) if (x) x->Release(); x=NULL; +#ifndef __FUNCTION__ +#define __FUNCTION__ "" +#endif + #define LOGFAIL() dprintf2("fail: %s %s:%i\n", __FUNCTION__, __FILE__, __LINE__) @@ -56,6 +60,7 @@ extern "C" int dprintf2(char *format, ...); // Main.cpp extern char *romname; extern HWND FrameWnd; +extern RECT FrameRectMy; extern int MainWidth,MainHeight; extern void error(char *text); diff --git a/platform/win32/GenaDrive/port_config.h b/platform/win32/GenaDrive/port_config.h index 44b049a5..2a405ac0 100644 --- a/platform/win32/GenaDrive/port_config.h +++ b/platform/win32/GenaDrive/port_config.h @@ -7,6 +7,7 @@ #define START_ROW 0 // which row of tiles to start rendering at? #define END_ROW 28 // ..end +#define SIMPLE_WRITE_SOUND 1 #define mix_32_to_16l_stereo_lvl mix_32_to_16l_stereo // pico.c -- 2.39.5