mirror of
https://github.com/RaySollium99/picodrive.git
synced 2025-09-05 15:27:46 -04:00
win32 stuff, SIMPLE_WRITE_SOUND
git-svn-id: file:///home/notaz/opt/svn/PicoDrive@341 be3aeb3a-fb24-0410-a615-afba39da0efa
This commit is contained in:
parent
7c9e6899a2
commit
03a265e5eb
14 changed files with 161 additions and 57 deletions
|
@ -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<LoopWrite+PsndLen) return 1; // No, it hasn't
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
#include "app.h"
|
||||
|
||||
// d3d
|
||||
|
@ -21,91 +20,141 @@ static CustomVertex VertexList[4];
|
|||
// ddraw
|
||||
#include <ddraw.h>
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
static int DirectClearDDraw(unsigned int colour)
|
||||
{
|
||||
int ret;
|
||||
DDBLTFX ddbltfx;
|
||||
ZeroMemory( &ddbltfx, sizeof(ddbltfx) );
|
||||
ddbltfx.dwSize = sizeof(ddbltfx);
|
||||
ddbltfx.dwFillColor = colour;
|
||||
|
||||
if (m_pddsBackBuffer != NULL)
|
||||
ret = m_pddsBackBuffer->Blt( NULL, NULL, NULL, DDBLT_COLORFILL, &ddbltfx );
|
||||
#endif
|
||||
if (ret) { LOGFAIL(); return 1; }
|
||||
return 0;
|
||||
}
|
||||
|
||||
ret = m_pddsFrontBuffer->Blt(NULL, m_pddsBackBuffer, NULL, DDBLT_WAIT, NULL);
|
||||
static int DirectPresentDDraw()
|
||||
{
|
||||
int ret = m_pddsFrontBuffer->Blt(&FrameRectMy, 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 (ret) { LOGFAIL(); return 1; }
|
||||
Sleep(500);
|
||||
ret = m_pddsFrontBuffer->Blt(NULL, 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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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; }
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue