Browse Source

Clean up sound code

pull/281/head
Anders Jenbo 7 years ago
parent
commit
1d03064fee
  1. 60
      3rdParty/Storm/Source/storm.h
  2. 321
      Source/appfat.cpp
  3. 8
      Source/diablo.cpp
  4. 5
      Source/dx.h
  5. 29
      Source/effects.cpp
  6. 11
      Source/scrollrt.cpp
  7. 1
      Source/sound.h
  8. 139
      Source/wave.cpp
  9. 9
      Source/wave.h
  10. 6
      SourceS/miniwin.h
  11. 44
      SourceS/miniwin/com.h
  12. 123
      SourceS/miniwin/com/ddraw_macro.inc
  13. 88
      SourceS/miniwin/com/dsound.inc
  14. 28
      SourceS/miniwin/com/dsound_macro.inc
  15. 18
      SourceS/miniwin/com_macro.h
  16. 12
      SourceS/miniwin/misc.h
  17. 20
      SourceS/miniwin/misc_macro.h
  18. 12
      SourceX/dx.cpp
  19. 78
      SourceX/miniwin/dsound.cpp
  20. 16
      SourceX/miniwin/dsound.h
  21. 2
      SourceX/miniwin/misc.cpp
  22. 211
      SourceX/sound.cpp
  23. 2
      SourceX/storm/storm.cpp
  24. 7
      structs.h

60
3rdParty/Storm/Source/storm.h vendored

@ -691,34 +691,6 @@ STORMAPI
SDrawGetFrameWindow(
HWND *sdraw_framewindow);
/* SDrawGetObjects @ 347
*
* Retrieves the object information that was initialized using
* SDrawManualInitialize or SDrawAutoInitialize.
*
* ddInterface: The DirectDraw interface.
* primarySurface: The primary DirectDraw surface.
* surface2: A second unknown surface.
* surface3: A third unknown surface.
* backSurface: The back DirectDraw surface.
* ddPalette: The DirectDraw palette.
* hPalette: The palette handle.
*
* Returns FALSE if the direct draw interface has not been initialized.
*/
BOOL
STORMAPI
SDrawGetObjects(
LPDIRECTDRAW *ddInterface ,
LPDIRECTDRAWSURFACE *primarySurface,
LPDIRECTDRAWSURFACE *surface2,
LPDIRECTDRAWSURFACE *surface3,
LPDIRECTDRAWSURFACE *backSurface ,
LPDIRECTDRAWPALETTE *ddPalette,
HPALETTE *hPalette);
/* SDrawGetScreenSize @ 348
*
* Obtains information for the current screen resolution.
@ -740,38 +712,6 @@ SDrawGetScreenSize(
// undefined
BOOL STORMAPI SDrawLockSurface(int surfacenumber, RECT *lpDestRect, void **lplpSurface, int *lpPitch, int arg_unused);
/* SDrawManualInitialize @ 351
*
* Sets the DirectDraw variables to be referenced in Storm.
*
* hWnd: The handle of the DirectDraw window.
* ddInterface: The DirectDraw interface.
* primarySurface: The first and primary surface.
* surface2: A second surface. Behaviour not completely known.
* surface3: A third surface. Behaviour not completely known.
* backSurface: The fourth and final surface. The back surface.
* ddPalette: The DirectDraw palette if the application requires it.
* hPalette: The palette handle that belongs to the window.
* If this is NULL and ddPalette is specified, then it
* will be created automatically. A palette can be created
* using the CreatePalette WinAPI function.
*
* Returns FALSE if no variables were specified.
*/
BOOL
STORMAPI
SDrawManualInitialize(
HWND hWnd,
LPDIRECTDRAW ddInterface,
LPDIRECTDRAWSURFACE primarySurface,
LPDIRECTDRAWSURFACE surface2,
LPDIRECTDRAWSURFACE surface3,
LPDIRECTDRAWSURFACE backSurface,
LPDIRECTDRAWPALETTE ddPalette,
HPALETTE hPalette);
/* SDrawPostClose @ 353
*
* Posts a WM_QUIT message to the active drawing window specified

321
Source/appfat.cpp

@ -70,300 +70,15 @@ void TraceErrorDD(HRESULT hError, char *pszBuffer, DWORD dwMaxChars)
const char *szError;
switch (hError) {
case DDERR_CANTPAGEUNLOCK:
szError = "DDERR_CANTPAGEUNLOCK";
break;
case DDERR_NOTPAGELOCKED:
szError = "DDERR_NOTPAGELOCKED";
break;
case DD_OK:
szError = "DD_OK";
break;
case DDERR_CANTPAGELOCK:
szError = "DDERR_CANTPAGELOCK";
break;
case DDERR_BLTFASTCANTCLIP:
szError = "DDERR_BLTFASTCANTCLIP";
break;
case DDERR_NOBLTHW:
szError = "DDERR_NOBLTHW";
break;
case DDERR_NODDROPSHW:
szError = "DDERR_NODDROPSHW";
break;
case DDERR_OVERLAYNOTVISIBLE:
szError = "DDERR_OVERLAYNOTVISIBLE";
break;
case DDERR_NOOVERLAYDEST:
szError = "DDERR_NOOVERLAYDEST";
break;
case DDERR_INVALIDPOSITION:
szError = "DDERR_INVALIDPOSITION";
break;
case DDERR_NOTAOVERLAYSURFACE:
szError = "DDERR_NOTAOVERLAYSURFACE";
break;
case DDERR_EXCLUSIVEMODEALREADYSET:
szError = "DDERR_EXCLUSIVEMODEALREADYSET";
break;
case DDERR_NOTFLIPPABLE:
szError = "DDERR_NOTFLIPPABLE";
break;
case DDERR_CANTDUPLICATE:
szError = "DDERR_CANTDUPLICATE";
break;
case DDERR_NOTLOCKED:
szError = "DDERR_NOTLOCKED";
break;
case DDERR_CANTCREATEDC:
szError = "DDERR_CANTCREATEDC";
break;
case DDERR_NODC:
szError = "DDERR_NODC";
break;
case DDERR_WRONGMODE:
szError = "DDERR_WRONGMODE";
break;
case DDERR_IMPLICITLYCREATED:
szError = "DDERR_IMPLICITLYCREATED";
break;
case DDERR_NOTPALETTIZED:
szError = "DDERR_NOTPALETTIZED";
break;
case DDERR_NOMIPMAPHW:
szError = "DDERR_NOMIPMAPHW";
break;
case DDERR_INVALIDSURFACETYPE:
szError = "DDERR_INVALIDSURFACETYPE";
break;
case DDERR_DCALREADYCREATED:
szError = "DDERR_DCALREADYCREATED";
break;
case DDERR_NOPALETTEHW:
szError = "DDERR_NOPALETTEHW";
break;
case DDERR_DIRECTDRAWALREADYCREATED:
szError = "DDERR_DIRECTDRAWALREADYCREATED";
break;
case DDERR_NODIRECTDRAWHW:
szError = "DDERR_NODIRECTDRAWHW";
break;
case DDERR_PRIMARYSURFACEALREADYEXISTS:
szError = "DDERR_PRIMARYSURFACEALREADYEXISTS";
break;
case DDERR_NOEMULATION:
szError = "DDERR_NOEMULATION";
break;
case DDERR_REGIONTOOSMALL:
szError = "DDERR_REGIONTOOSMALL";
break;
case DDERR_CLIPPERISUSINGHWND:
szError = "DDERR_CLIPPERISUSINGHWND";
break;
case DDERR_NOCLIPPERATTACHED:
szError = "DDERR_NOCLIPPERATTACHED";
break;
case DDERR_NOHWND:
szError = "DDERR_NOHWND";
break;
case DDERR_HWNDSUBCLASSED:
szError = "DDERR_HWNDSUBCLASSED";
break;
case DDERR_HWNDALREADYSET:
szError = "DDERR_HWNDALREADYSET";
break;
case DDERR_NOPALETTEATTACHED:
szError = "DDERR_NOPALETTEATTACHED";
break;
case DDERR_INVALIDDIRECTDRAWGUID:
szError = "DDERR_INVALIDDIRECTDRAWGUID";
break;
case DDERR_UNSUPPORTEDFORMAT:
szError = "DDERR_UNSUPPORTEDFORMAT";
break;
case DDERR_UNSUPPORTEDMASK:
szError = "DDERR_UNSUPPORTEDMASK";
break;
case DDERR_VERTICALBLANKINPROGRESS:
szError = "DDERR_VERTICALBLANKINPROGRESS";
break;
case DDERR_WASSTILLDRAWING:
szError = "DDERR_WASSTILLDRAWING";
break;
case DDERR_XALIGN:
szError = "DDERR_XALIGN";
break;
case DDERR_TOOBIGWIDTH:
szError = "DDERR_TOOBIGWIDTH";
break;
case DDERR_CANTLOCKSURFACE:
szError = "DDERR_CANTLOCKSURFACE";
break;
case DDERR_SURFACEISOBSCURED:
szError = "DDERR_SURFACEISOBSCURED";
break;
case DDERR_SURFACELOST:
szError = "DDERR_SURFACELOST";
break;
case DDERR_SURFACENOTATTACHED:
szError = "DDERR_SURFACENOTATTACHED";
break;
case DDERR_TOOBIGHEIGHT:
szError = "DDERR_TOOBIGHEIGHT";
break;
case DDERR_TOOBIGSIZE:
szError = "DDERR_TOOBIGSIZE";
break;
case DDERR_SURFACEBUSY:
szError = "DDERR_SURFACEBUSY";
break;
case DDERR_OVERLAYCOLORKEYONLYONEACTIVE:
szError = "DDERR_OVERLAYCOLORKEYONLYONEACTIVE";
break;
case DDERR_PALETTEBUSY:
szError = "DDERR_PALETTEBUSY";
break;
case DDERR_COLORKEYNOTSET:
szError = "DDERR_COLORKEYNOTSET";
break;
case DDERR_SURFACEALREADYATTACHED:
szError = "DDERR_SURFACEALREADYATTACHED";
break;
case DDERR_SURFACEALREADYDEPENDENT:
szError = "DDERR_SURFACEALREADYDEPENDENT";
break;
case DDERR_OVERLAYCANTCLIP:
szError = "DDERR_OVERLAYCANTCLIP";
break;
case DDERR_NOVSYNCHW:
szError = "DDERR_NOVSYNCHW";
break;
case DDERR_NOZBUFFERHW:
szError = "DDERR_NOZBUFFERHW";
break;
case DDERR_NOZOVERLAYHW:
szError = "DDERR_NOZOVERLAYHW";
break;
case DDERR_OUTOFCAPS:
szError = "DDERR_OUTOFCAPS";
break;
case DDERR_OUTOFVIDEOMEMORY:
szError = "DDERR_OUTOFVIDEOMEMORY";
break;
case DDERR_NOTEXTUREHW:
szError = "DDERR_NOTEXTUREHW";
break;
case DDERR_NOROTATIONHW:
szError = "DDERR_NOROTATIONHW";
break;
case DDERR_NOSTRETCHHW:
szError = "DDERR_NOSTRETCHHW";
break;
case DDERR_NOT4BITCOLOR:
szError = "DDERR_NOT4BITCOLOR";
break;
case DDERR_NOT4BITCOLORINDEX:
szError = "DDERR_NOT4BITCOLORINDEX";
break;
case DDERR_NOT8BITCOLOR:
szError = "DDERR_NOT8BITCOLOR";
break;
case DDERR_NORASTEROPHW:
szError = "DDERR_NORASTEROPHW";
break;
case DDERR_NOEXCLUSIVEMODE:
szError = "DDERR_NOEXCLUSIVEMODE";
break;
case DDERR_NOFLIPHW:
szError = "DDERR_NOFLIPHW";
break;
case DDERR_NOGDI:
szError = "DDERR_NOGDI";
break;
case DDERR_NOMIRRORHW:
szError = "DDERR_NOMIRRORHW";
break;
case DDERR_NOTFOUND:
szError = "DDERR_NOTFOUND";
break;
case DDERR_NOOVERLAYHW:
szError = "DDERR_NOOVERLAYHW";
break;
case DDERR_NOCOLORKEYHW:
szError = "DDERR_NOCOLORKEYHW";
break;
case DDERR_NOALPHAHW:
szError = "DDERR_NOALPHAHW";
break;
case DDERR_NOCLIPLIST:
szError = "DDERR_NOCLIPLIST";
break;
case DDERR_NOCOLORCONVHW:
szError = "DDERR_NOCOLORCONVHW";
break;
case DDERR_NOCOOPERATIVELEVELSET:
szError = "DDERR_NOCOOPERATIVELEVELSET";
break;
case DDERR_NOCOLORKEY:
szError = "DDERR_NOCOLORKEY";
break;
case DDERR_NO3D:
szError = "DDERR_NO3D";
break;
case DDERR_INVALIDMODE:
szError = "DDERR_INVALIDMODE";
break;
case DDERR_INVALIDOBJECT:
szError = "DDERR_INVALIDOBJECT";
break;
case DDERR_INVALIDPIXELFORMAT:
szError = "DDERR_INVALIDPIXELFORMAT";
break;
case DDERR_INVALIDRECT:
szError = "DDERR_INVALIDRECT";
break;
case DDERR_LOCKEDSURFACES:
szError = "DDERR_LOCKEDSURFACES";
break;
case DDERR_INVALIDCLIPLIST:
szError = "DDERR_INVALIDCLIPLIST";
break;
case DDERR_CURRENTLYNOTAVAIL:
szError = "DDERR_CURRENTLYNOTAVAIL";
break;
case DDERR_EXCEPTION:
szError = "DDERR_EXCEPTION";
break;
case DDERR_HEIGHTALIGN:
szError = "DDERR_HEIGHTALIGN";
break;
case DDERR_INCOMPATIBLEPRIMARY:
szError = "DDERR_INCOMPATIBLEPRIMARY";
break;
case DDERR_INVALIDCAPS:
szError = "DDERR_INVALIDCAPS";
break;
case DDERR_CANNOTDETACHSURFACE:
szError = "DDERR_CANNOTDETACHSURFACE";
break;
case DDERR_UNSUPPORTED:
szError = "DDERR_UNSUPPORTED";
break;
case DDERR_GENERIC:
szError = "DDERR_GENERIC";
break;
case DDERR_OUTOFMEMORY:
szError = "DDERR_OUTOFMEMORY";
break;
case DDERR_INVALIDPARAMS:
szError = "DDERR_INVALIDPARAMS";
break;
case DDERR_ALREADYINITIALIZED:
szError = "DDERR_ALREADYINITIALIZED";
break;
case DDERR_CANNOTATTACHSURFACE:
szError = "DDERR_CANNOTATTACHSURFACE";
break;
default: {
const char szUnknown[] = "DDERR unknown 0x%x";
/// ASSERT: assert(dwMaxChars >= sizeof(szUnknown) + 10);
@ -380,45 +95,9 @@ void TraceErrorDS(HRESULT hError, char *pszBuffer, DWORD dwMaxChars)
const char *szError;
switch (hError) {
case DSERR_PRIOLEVELNEEDED:
szError = "DSERR_PRIOLEVELNEEDED";
break;
case DSERR_BADFORMAT:
szError = "DSERR_BADFORMAT";
break;
case DSERR_NODRIVER:
szError = "DSERR_NODRIVER";
break;
case DSERR_ALREADYINITIALIZED:
szError = "DSERR_ALREADYINITIALIZED";
break;
case DSERR_BUFFERLOST:
szError = "DSERR_BUFFERLOST";
break;
case DS_OK:
szError = "DS_OK";
break;
case DSERR_INVALIDCALL:
szError = "DSERR_INVALIDCALL";
break;
case E_NOINTERFACE:
szError = "E_NOINTERFACE";
break;
case DSERR_NOAGGREGATION:
szError = "DSERR_NOAGGREGATION";
break;
case DSERR_OUTOFMEMORY:
szError = "DSERR_OUTOFMEMORY";
break;
case DSERR_INVALIDPARAM:
szError = "DSERR_INVALIDPARAM";
break;
case DSERR_ALLOCATED:
szError = "DSERR_ALLOCATED";
break;
case DSERR_CONTROLUNAVAIL:
szError = "DSERR_CONTROLUNAVAIL";
break;
default: {
const char szUnknown[] = "DSERR unknown 0x%x";
/// ASSERT: assert(dwMaxChars >= sizeof(szUnknown) + 10);

8
Source/diablo.cpp

@ -310,13 +310,7 @@ void diablo_parse_flags(char *args)
while (isspace(*args)) {
args++;
}
if (_strnicmp("dd_emulate", args, strlen("dd_emulate")) == 0) {
gbEmulate = 1;
args += strlen("dd_emulate");
} else if (_strnicmp("ds_noduplicates", args, strlen("ds_noduplicates")) == 0) {
gbDupSounds = FALSE;
args += strlen("ds_noduplicates");
} else {
{
c = tolower(*args);
args++;
#ifdef _DEBUG

5
Source/dx.h

@ -2,11 +2,7 @@
#ifndef __DX_H__
#define __DX_H__
extern IDirectDraw *lpDDInterface;
extern IDirectDrawPalette *lpDDPalette;
extern BYTE *gpBuffer;
extern IDirectDrawSurface *lpDDSBackBuf;
extern IDirectDrawSurface *lpDDSPrimary;
extern char gbBackBuf;
extern char gbEmulate;
extern HMODULE ghDiabMod;
@ -14,7 +10,6 @@ extern HMODULE ghDiabMod;
void dx_init(HWND hWnd);
void dx_create_back_buffer();
void dx_create_primary_surface();
HRESULT dx_DirectDrawCreate(LPGUID guid, LPDIRECTDRAW *lplpDD, LPUNKNOWN pUnkOuter);
void lock_buf(BYTE idx);
void lock_buf_priv();
void unlock_buf(BYTE idx);

29
Source/effects.cpp

@ -1,5 +1,6 @@
#include "diablo.h"
#include "../3rdParty/Storm/Source/storm.h"
#include <SDL_mixer.h>
DEVILUTION_BEGIN_NAMESPACE
@ -1147,32 +1148,7 @@ void PlaySfxLoc(int psfx, int x, int y)
void FreeMonsterSnd()
{
int i, j, k;
snd_update(TRUE);
sfx_stop();
sound_stop();
for (i = 0; i < nummtypes; i++) {
for (j = 0; j < 4; j++) {
for (k = 0; k < 2; k++) {
snd_stop_snd(Monsters[i].Snds[j][k]);
}
}
}
}
void sound_stop()
{
int i;
TSFX *snd;
snd = &sgSFX[0];
for (i = 0; i < sizeof(sgSFX) / sizeof(TSFX); i++) {
if (snd->pSnd)
snd_stop_snd(snd->pSnd);
snd++;
}
Mix_HaltChannel(-1);
}
void sound_update()
@ -1181,7 +1157,6 @@ void sound_update()
return;
}
snd_update(FALSE);
effects_update();
}

11
Source/scrollrt.cpp

@ -2388,17 +2388,8 @@ void DoBlitScreen(DWORD dwX, DWORD dwY, DWORD dwWdt, DWORD dwHgt)
break;
}
Sleep(1);
if (hDDVal == DDERR_SURFACELOST) {
return;
}
if (hDDVal != DDERR_WASSTILLDRAWING && hDDVal != DDERR_SURFACEBUSY) {
break;
}
}
if (hDDVal != DDERR_SURFACELOST
&& hDDVal != DDERR_WASSTILLDRAWING
&& hDDVal != DDERR_SURFACEBUSY
&& hDDVal != DD_OK) {
if (hDDVal != DD_OK) {
DD_ERR_MSG(hDDVal);
}
}

1
Source/sound.h

@ -18,7 +18,6 @@ void sound_file_cleanup(TSnd *sound_file);
void snd_init(HWND hWnd);
void sound_load_volume(char *value_name, int *value);
void sound_create_primary_buffer(HANDLE music_track);
HRESULT sound_DirectSoundCreate(LPGUID lpGuid, LPDIRECTSOUND *ppDS, LPUNKNOWN pUnkOuter);
void sound_cleanup();
void sound_store_volume(char *key, int value);
void music_stop();

139
Source/wave.cpp

@ -73,144 +73,5 @@ int WSetFilePointer(HANDLE file1, int offset, HANDLE file2, int whence)
return result;
}
BOOL LoadWaveFormat(HANDLE hsFile, WAVEFORMATEX *pwfx)
{
BOOL ret;
MEMFILE wave_file;
AllocateMemFile(hsFile, &wave_file, 0);
ret = ReadWaveFile(&wave_file, pwfx, NULL);
FreeMemFile(&wave_file);
return ret;
}
void *AllocateMemFile(HANDLE hsFile, MEMFILE *pMemFile, DWORD dwPos)
{
DWORD length;
memset(pMemFile, 0, sizeof(*pMemFile));
pMemFile->end = WGetFileSize(hsFile, NULL);
length = 4096;
if (dwPos > length)
length = dwPos;
pMemFile->buf_len = length;
if (length >= pMemFile->end)
length = pMemFile->end;
pMemFile->buf_len = length;
pMemFile->buf = DiabloAllocPtr(length);
pMemFile->file = hsFile;
return pMemFile->buf;
}
void FreeMemFile(MEMFILE *pMemFile)
{
MemFreeDbg(pMemFile->buf);
}
BOOL ReadWaveFile(MEMFILE *pMemFile, WAVEFORMATEX *pwfx, CKINFO *chunk)
{
MMCKINFO hdr;
CKINFO fmt;
PCMWAVEFORMAT wf;
if (!ReadMemFile(pMemFile, &hdr, 12))
return FALSE;
if (hdr.ckid != FOURCC_RIFF || hdr.fccType != MAKEFOURCC('W', 'A', 'V', 'E'))
return FALSE;
if (!ReadWaveSection(pMemFile, MAKEFOURCC('f', 'm', 't', ' '), &fmt))
return FALSE;
if (fmt.dwSize < sizeof(PCMWAVEFORMAT))
return FALSE;
if (!ReadMemFile(pMemFile, &wf, sizeof(wf)))
return FALSE;
if (SeekMemFile(pMemFile, fmt.dwSize - sizeof(wf), FILE_CURRENT) == -1)
return FALSE;
pwfx->cbSize = 0;
pwfx->wFormatTag = wf.wf.wFormatTag;
pwfx->nChannels = wf.wf.nChannels;
pwfx->nSamplesPerSec = wf.wf.nSamplesPerSec;
pwfx->nAvgBytesPerSec = wf.wf.nAvgBytesPerSec;
pwfx->nBlockAlign = wf.wf.nBlockAlign;
pwfx->wBitsPerSample = wf.wBitsPerSample;
if (chunk == NULL)
return TRUE;
return ReadWaveSection(pMemFile, MAKEFOURCC('d', 'a', 't', 'a'), chunk);
}
BOOL ReadMemFile(MEMFILE *pMemFile, void *lpBuf, size_t length)
{
while (length) {
size_t to_copy;
if (!pMemFile->bytes_to_read)
FillMemFile(pMemFile);
to_copy = pMemFile->bytes_to_read;
if (length < to_copy)
to_copy = length;
if (!to_copy)
return FALSE;
memcpy(lpBuf, &pMemFile->buf[pMemFile->dist], to_copy);
pMemFile->offset += to_copy;
pMemFile->dist += to_copy;
pMemFile->bytes_to_read -= to_copy;
// BUGFIX: lpBuf is not incremented, next read will overwrite data
length -= to_copy;
}
return TRUE;
}
void FillMemFile(MEMFILE *pMemFile)
{
DWORD to_read;
WSetFilePointer(pMemFile->file, pMemFile->offset, NULL, FILE_BEGIN);
to_read = pMemFile->end - pMemFile->offset;
if (pMemFile->buf_len < to_read)
to_read = pMemFile->buf_len;
if (to_read)
WReadFile(pMemFile->file, pMemFile->buf, to_read);
pMemFile->dist = 0;
pMemFile->bytes_to_read = to_read;
}
int SeekMemFile(MEMFILE *pMemFile, ULONG lDist, DWORD dwMethod)
{
if (lDist < pMemFile->bytes_to_read) {
pMemFile->bytes_to_read -= lDist;
pMemFile->dist += lDist;
} else
pMemFile->bytes_to_read = 0;
pMemFile->offset += lDist;
return pMemFile->offset;
}
BOOL ReadWaveSection(MEMFILE *pMemFile, DWORD id, CKINFO *chunk)
{
DWORD hdr[2];
while (1) {
if (!ReadMemFile(pMemFile, hdr, sizeof(hdr)))
return FALSE;
if (hdr[0] == id)
break;
if (SeekMemFile(pMemFile, hdr[1], FILE_CURRENT) == -1)
return FALSE;
}
chunk->dwSize = hdr[1];
chunk->dwOffset = SeekMemFile(pMemFile, 0, FILE_CURRENT);
return chunk->dwOffset != (DWORD)-1;
}
BYTE *LoadWaveFile(HANDLE hsFile, WAVEFORMATEX *pwfx, CKINFO *chunk)
{
MEMFILE wave_file;
AllocateMemFile(hsFile, &wave_file, (DWORD)-1);
if (!ReadWaveFile(&wave_file, pwfx, chunk)) {
FreeMemFile(&wave_file);
return NULL;
}
return wave_file.buf;
}
DEVILUTION_END_NAMESPACE

9
Source/wave.h

@ -8,14 +8,5 @@ void WGetFileArchive(HANDLE hsFile, DWORD *retry, const char *FileName);
BOOL WOpenFile(const char *FileName, HANDLE *phsFile, BOOL mayNotExist);
void WReadFile(HANDLE hsFile, LPVOID buf, DWORD to_read);
int WSetFilePointer(HANDLE file1, int offset, HANDLE file2, int whence);
BOOL LoadWaveFormat(HANDLE hsFile, WAVEFORMATEX *pwfx);
void *AllocateMemFile(HANDLE hsFile, MEMFILE *pMemFile, DWORD dwPos);
void FreeMemFile(MEMFILE *pMemFile);
BOOL ReadWaveFile(MEMFILE *pMemFile, WAVEFORMATEX *pwfx, CKINFO *chunk);
BOOL ReadMemFile(MEMFILE *pMemFile, void *lpBuf, size_t length);
void FillMemFile(MEMFILE *pMemFile);
int SeekMemFile(MEMFILE *pMemFile, ULONG lDist, DWORD dwMethod);
BOOL ReadWaveSection(MEMFILE *pMemFile, DWORD id, CKINFO *chunk);
BYTE *LoadWaveFile(HANDLE hsFile, WAVEFORMATEX *pwfx, CKINFO *chunk);
#endif /* __WAVE_H__ */

6
SourceS/miniwin.h

@ -28,6 +28,10 @@
#include "miniwin/rand.h"
#include "storm_full.h"
#define MAX_PATH DVL_MAX_PATH
#ifndef MAX_PATH
#define MAX_PATH DVL_MAX_PATH
#endif
#ifdef DEVILUTION_ENGINE
#include "miniwin/misc_macro.h"
#include "miniwin/com_macro.h"
#endif

44
SourceS/miniwin/com.h

@ -2,40 +2,26 @@
namespace dvl {
//
// COM
//
#define DECLARE_INTERFACE_(name, base) struct name : public base
#define THIS_
#define THIS
#define PURE = 0
#define STDMETHOD(name) STDMETHOD_(HRESULT, name)
#define STDMETHOD_(type, name) virtual WINAPI type name
struct IUnknown {
// clang-format off
STDMETHOD_(ULONG, Release)(THIS) PURE;
// clang-format on
struct IDirectSoundBuffer {
virtual WINAPI void Release() = 0;
virtual WINAPI void GetStatus(LPDWORD pdwStatus) = 0;
virtual WINAPI void Play(int lVolume, int lPan) = 0;
virtual WINAPI void Stop() = 0;
virtual WINAPI const char *SetChunk(BYTE *fileData, DWORD dwBytes) = 0;
};
template<class T, class U, class V> constexpr HRESULT DVL_MAKE_HRESULT(T&& sev, U&& fac, V&& code)
{
return (((uint32_t)(sev) << 31) | ((uint32_t)(fac) << 16) | ((uint32_t)(code)));
}
typedef struct IDirectDrawPalette *LPDIRECTDRAWPALETTE;
typedef struct IDirectDrawSurface *LPDIRECTDRAWSURFACE;
typedef struct IDirectDraw *LPDIRECTDRAW;
typedef IDirectSoundBuffer *LPDIRECTSOUNDBUFFER;
#include "miniwin/com/dsound.inc"
const auto DVL_DS_OK = 0;
const auto DVL_ERROR_SUCCESS = 0L;
const auto DVL_DSBSTATUS_PLAYING = 0x00000001;
constexpr HRESULT DVL_E_FAIL = 0x80004005L;
constexpr HRESULT DVL_S_OK = 0;
constexpr HRESULT DVL_S_OK = 0;
constexpr auto DVL_SW_HIDE = 0;
constexpr auto DVL_SW_HIDE = 0;
constexpr auto DVL_SW_SHOWNORMAL = 1;
constexpr auto DVL_SM_CXSCREEN = 0;
constexpr auto DVL_SM_CYSCREEN = 1;
constexpr auto DVL_SM_CXSCREEN = 0;
constexpr auto DVL_SM_CYSCREEN = 1;
} // namespace dvl
} // namespace dvl

123
SourceS/miniwin/com/ddraw_macro.inc

@ -1,123 +0,0 @@
#define _FACDD 0x876
#define MAKE_DDHRESULT(code) MAKE_HRESULT(1, _FACDD, code)
#define DDERR_SURFACELOST MAKE_DDHRESULT(450)
#define DDERR_WASSTILLDRAWING MAKE_DDHRESULT(540)
#define DDERR_SURFACEBUSY MAKE_DDHRESULT(430)
/*
* returned when the position of the overlay on the destionation is no longer
* legal for that destionation.
*/
#define DDERR_INVALIDPOSITION MAKE_DDHRESULT(579)
#define DDERR_ALREADYINITIALIZED MAKE_DDHRESULT(5)
#define DDERR_BLTFASTCANTCLIP MAKE_DDHRESULT(574)
#define DDERR_CANNOTATTACHSURFACE MAKE_DDHRESULT(10)
#define DDERR_CANNOTDETACHSURFACE MAKE_DDHRESULT(20)
#define DDERR_CANTCREATEDC MAKE_DDHRESULT(585)
#define DDERR_CANTDUPLICATE MAKE_DDHRESULT(583)
#define DDERR_CANTLOCKSURFACE MAKE_DDHRESULT(435)
#define DDERR_CANTPAGELOCK MAKE_DDHRESULT(640)
#define DDERR_CANTPAGEUNLOCK MAKE_DDHRESULT(660)
#define DDERR_CLIPPERISUSINGHWND MAKE_DDHRESULT(567)
#define DDERR_COLORKEYNOTSET MAKE_DDHRESULT(400)
#define DDERR_CURRENTLYNOTAVAIL MAKE_DDHRESULT(40)
#define DDERR_DCALREADYCREATED MAKE_DDHRESULT(620)
#define DDERR_DIRECTDRAWALREADYCREATED MAKE_DDHRESULT(562)
#define DDERR_EXCEPTION MAKE_DDHRESULT(55)
#define DDERR_EXCLUSIVEMODEALREADYSET MAKE_DDHRESULT(581)
#define DDERR_GENERIC E_FAIL
#define DDERR_HEIGHTALIGN MAKE_DDHRESULT(90)
#define DDERR_HWNDALREADYSET MAKE_DDHRESULT(571)
#define DDERR_HWNDSUBCLASSED MAKE_DDHRESULT(570)
#define DDERR_IMPLICITLYCREATED MAKE_DDHRESULT(588)
#define DDERR_INCOMPATIBLEPRIMARY MAKE_DDHRESULT(95)
#define DDERR_INVALIDCAPS MAKE_DDHRESULT(100)
#define DDERR_INVALIDCLIPLIST MAKE_DDHRESULT(110)
#define DDERR_INVALIDDIRECTDRAWGUID MAKE_DDHRESULT(561)
#define DDERR_INVALIDMODE MAKE_DDHRESULT(120)
#define DDERR_INVALIDOBJECT MAKE_DDHRESULT(130)
#define DDERR_INVALIDPARAMS 0x80070057
#define DDERR_INVALIDPIXELFORMAT MAKE_DDHRESULT(145)
#define DDERR_INVALIDPOSITION MAKE_DDHRESULT(579)
#define DDERR_INVALIDRECT MAKE_DDHRESULT(150)
#define DDERR_INVALIDSURFACETYPE MAKE_DDHRESULT(592)
#define DDERR_LOCKEDSURFACES MAKE_DDHRESULT(160)
#define DDERR_NO3D MAKE_DDHRESULT(170)
#define DDERR_NOALPHAHW MAKE_DDHRESULT(180)
#define DDERR_NOBLTHW MAKE_DDHRESULT(575)
#define DDERR_NOCLIPLIST MAKE_DDHRESULT(205)
#define DDERR_NOCLIPPERATTACHED MAKE_DDHRESULT(568)
#define DDERR_NOCOLORCONVHW MAKE_DDHRESULT(210)
#define DDERR_NOCOLORKEYHW MAKE_DDHRESULT(220)
#define DDERR_NOCOLORKEY MAKE_DDHRESULT(215)
#define DDERR_NOCOOPERATIVELEVELSET MAKE_DDHRESULT(212)
#define DDERR_NODC MAKE_DDHRESULT(586)
#define DDERR_NODDROPSHW MAKE_DDHRESULT(576)
#define DDERR_NODIRECTDRAWHW MAKE_DDHRESULT(563)
#define DDERR_NOEMULATION MAKE_DDHRESULT(565)
#define DDERR_NOEXCLUSIVEMODE MAKE_DDHRESULT(225)
#define DDERR_NOFLIPHW MAKE_DDHRESULT(230)
#define DDERR_NOGDI MAKE_DDHRESULT(240)
#define DDERR_NOHWND MAKE_DDHRESULT(569)
#define DDERR_NOMIPMAPHW MAKE_DDHRESULT(591)
#define DDERR_NOMIRRORHW MAKE_DDHRESULT(250)
#define DDERR_NOOVERLAYDEST MAKE_DDHRESULT(578)
#define DDERR_NOOVERLAYHW MAKE_DDHRESULT(260)
#define DDERR_NOPALETTEATTACHED MAKE_DDHRESULT(572)
#define DDERR_NOPALETTEHW MAKE_DDHRESULT(573)
#define DDERR_NORASTEROPHW MAKE_DDHRESULT(280)
#define DDERR_NOROTATIONHW MAKE_DDHRESULT(290)
#define DDERR_NOSTRETCHHW MAKE_DDHRESULT(310)
#define DDERR_NOT4BITCOLORINDEX MAKE_DDHRESULT(317)
#define DDERR_NOT4BITCOLOR MAKE_DDHRESULT(316)
#define DDERR_NOT8BITCOLOR MAKE_DDHRESULT(320)
#define DDERR_NOTAOVERLAYSURFACE MAKE_DDHRESULT(580)
#define DDERR_NOTEXTUREHW MAKE_DDHRESULT(330)
#define DDERR_NOTFLIPPABLE MAKE_DDHRESULT(582)
#define DDERR_NOTFOUND MAKE_DDHRESULT(255)
#define DDERR_NOTLOCKED MAKE_DDHRESULT(584)
#define DDERR_NOTPAGELOCKED MAKE_DDHRESULT(680)
#define DDERR_NOTPALETTIZED MAKE_DDHRESULT(589)
#define DDERR_NOVSYNCHW MAKE_DDHRESULT(335)
#define DDERR_NOZBUFFERHW MAKE_DDHRESULT(340)
#define DDERR_NOZOVERLAYHW MAKE_DDHRESULT(350)
#define DDERR_OUTOFCAPS MAKE_DDHRESULT(360)
#define DDERR_OUTOFMEMORY 0x8007000E
#define DDERR_OUTOFVIDEOMEMORY MAKE_DDHRESULT(380)
#define DDERR_OVERLAYCANTCLIP MAKE_DDHRESULT(382)
#define DDERR_OVERLAYCOLORKEYONLYONEACTIVE MAKE_DDHRESULT(384)
#define DDERR_OVERLAYNOTVISIBLE MAKE_DDHRESULT(577)
#define DDERR_PALETTEBUSY MAKE_DDHRESULT(387)
#define DDERR_PRIMARYSURFACEALREADYEXISTS MAKE_DDHRESULT(564)
#define DDERR_REGIONTOOSMALL MAKE_DDHRESULT(566)
#define DDERR_SURFACEALREADYATTACHED MAKE_DDHRESULT(410)
#define DDERR_SURFACEALREADYDEPENDENT MAKE_DDHRESULT(420)
#define DDERR_SURFACEBUSY MAKE_DDHRESULT(430)
#define DDERR_SURFACEISOBSCURED MAKE_DDHRESULT(440)
#define DDERR_SURFACELOST MAKE_DDHRESULT(450)
#define DDERR_SURFACENOTATTACHED MAKE_DDHRESULT(460)
#define DDERR_TOOBIGHEIGHT MAKE_DDHRESULT(470)
#define DDERR_TOOBIGSIZE MAKE_DDHRESULT(480)
#define DDERR_TOOBIGWIDTH MAKE_DDHRESULT(490)
#define DDERR_UNSUPPORTED 0x80004001
#define DDERR_UNSUPPORTEDFORMAT MAKE_DDHRESULT(510)
#define DDERR_UNSUPPORTEDMASK MAKE_DDHRESULT(520)
#define DDERR_VERTICALBLANKINPROGRESS MAKE_DDHRESULT(537)
#define DDERR_WASSTILLDRAWING MAKE_DDHRESULT(540)
#define DDERR_WRONGMODE MAKE_DDHRESULT(587)
#define DDERR_XALIGN MAKE_DDHRESULT(560)
#define DD_OK S_OK
#define DDBLTFAST_WAIT 0x00000010
#define DDLOCK_WRITEONLY 0x00000020L
#define DDLOCK_WAIT 0x00000001L
#define DDPCAPS_ALLOW256 0x00000040l
#define DDPCAPS_8BIT 0x00000004l
#define PC_RESERVED 0x01
#define PC_NOCOLLAPSE 0x04
#define DDWAITVB_BLOCKBEGIN 0x00000001l

88
SourceS/miniwin/com/dsound.inc

@ -1,88 +0,0 @@
struct IDirectSound;
typedef IDirectSound *LPDIRECTSOUND;
typedef struct _DSBUFFERDESC {
DWORD dwSize;
DWORD dwFlags;
DWORD dwBufferBytes;
DWORD dwReserved;
LPWAVEFORMATEX lpwfxFormat;
} DSBUFFERDESC, *LPDSBUFFERDESC;
typedef DSBUFFERDESC *LPDSBCAPS, *LPCDSBUFFERDESC;
DECLARE_INTERFACE_(IDirectSoundBuffer, IUnknown)
{
// clang-format off
STDMETHOD(GetStatus)(THIS_ LPDWORD pdwStatus) PURE;
STDMETHOD(Lock)(THIS_ DWORD dwOffset, DWORD dwBytes, LPVOID *ppvAudioPtr1, LPDWORD pdwAudioBytes1,
LPVOID *ppvAudioPtr2, LPDWORD pdwAudioBytes2, DWORD dwFlags) PURE;
STDMETHOD(Play)(THIS_ DWORD dwReserved1, DWORD dwPriority, DWORD dwFlags) PURE;
STDMETHOD(SetVolume)(THIS_ LONG lVolume) PURE;
STDMETHOD(SetPan)(THIS_ LONG lPan) PURE;
STDMETHOD(Stop)(THIS) PURE;
STDMETHOD(Unlock)(THIS_ LPVOID pvAudioPtr1, DWORD dwAudioBytes1, LPVOID pvAudioPtr2, DWORD dwAudioBytes2) PURE;
// clang-format on
};
typedef IDirectSoundBuffer *LPDIRECTSOUNDBUFFER;
typedef void *LPUNKNOWN, *LPCGUID;
typedef struct _DSCAPS {
DWORD dwSize;
DWORD dwFlags;
DWORD dwMinSecondarySampleRate;
DWORD dwMaxSecondarySampleRate;
DWORD dwPrimaryBuffers;
DWORD dwMaxHwMixingAllBuffers;
DWORD dwMaxHwMixingStaticBuffers;
DWORD dwMaxHwMixingStreamingBuffers;
DWORD dwFreeHwMixingAllBuffers;
DWORD dwFreeHwMixingStaticBuffers;
DWORD dwFreeHwMixingStreamingBuffers;
DWORD dwMaxHw3DAllBuffers;
DWORD dwMaxHw3DStaticBuffers;
DWORD dwMaxHw3DStreamingBuffers;
DWORD dwFreeHw3DAllBuffers;
DWORD dwFreeHw3DStaticBuffers;
DWORD dwFreeHw3DStreamingBuffers;
DWORD dwTotalHwMemBytes;
DWORD dwFreeHwMemBytes;
DWORD dwMaxContigFreeHwMemBytes;
DWORD dwUnlockTransferRateHwBuffers;
DWORD dwPlayCpuOverheadSwBuffers;
DWORD dwReserved1;
DWORD dwReserved2;
} DSCAPS, *LPDSCAPS;
DECLARE_INTERFACE_(IDirectSound, IUnknown)
{
// clang-format off
STDMETHOD(CreateSoundBuffer)(THIS_ LPCDSBUFFERDESC pcDSBufferDesc, LPDIRECTSOUNDBUFFER *ppDSBuffer, LPUNKNOWN pUnkOuter) PURE;
// clang-format on
};
class DirectSound : public IDirectSound {
public:
virtual ULONG Release();
virtual HRESULT CreateSoundBuffer(LPCDSBUFFERDESC pcDSBufferDesc, LPDIRECTSOUNDBUFFER *ppDSBuffer, LPUNKNOWN pUnkOute);
};
const auto DVL__FACDS = 0x878;
template<class T> constexpr HRESULT DVL_MAKE_DSHRESULT(T&& code)
{
return DVL_MAKE_HRESULT(1, DVL__FACDS, code);
}
const auto DVL_DSBCAPS_PRIMARYBUFFER = 0x00000001;
const auto DVL_DSBCAPS_STATIC = 0x00000002;
const auto DVL_DSBCAPS_CTRLPAN = 0x00000040;
const auto DVL_DSBCAPS_CTRLVOLUME = 0x00000080;
const auto DVL_WAVE_FORMAT_PCM = 1;
const auto DVL_DS_OK = 0;
const auto DVL_DSERR_INVALIDPARAM = 0x80070057;
const auto DVL_ERROR_SUCCESS = 0L;
const auto DVL_DSSCL_EXCLUSIVE = 0x00000003;
const auto DVL_DSBSTATUS_PLAYING = 0x00000001;
const auto DVL_DSERR_BUFFERLOST = DVL_MAKE_DSHRESULT(150);

28
SourceS/miniwin/com/dsound_macro.inc

@ -1,28 +0,0 @@
#define DSBCAPS_PRIMARYBUFFER DVL_DSBCAPS_PRIMARYBUFFER
#define DSBCAPS_STATIC DVL_DSBCAPS_STATIC
#define DSBCAPS_CTRLPAN DVL_DSBCAPS_CTRLPAN
#define DSBCAPS_CTRLVOLUME DVL_DSBCAPS_CTRLVOLUME
#define WAVE_FORMAT_PCM DVL_WAVE_FORMAT_PCM
#define ERROR_SUCCESS DVL_ERROR_SUCCESS
#define _FACDS DVL__FACDS
#define MAKE_DSHRESULT DVL_MAKE_DSHRESULT
#define E_NOINTERFACE 0x80004002
#define DSERR_PRIOLEVELNEEDED MAKE_DSHRESULT(70)
#define DSERR_BADFORMAT MAKE_DSHRESULT(100)
#define DSERR_NODRIVER MAKE_DSHRESULT(120)
#define DSERR_ALREADYINITIALIZED MAKE_DSHRESULT(130)
#define DSERR_BUFFERLOST DVL_DSERR_BUFFERLOST
#define DS_OK DVL_DS_OK
#define DSERR_INVALIDCALL MAKE_DSHRESULT(50)
#define DSERR_NOAGGREGATION 0x80040110
#define DSERR_OUTOFMEMORY 0x8007000E
#define DSERR_INVALIDPARAM DVL_DSERR_INVALIDPARAM
#define DSERR_ALLOCATED MAKE_DSHRESULT(10)
#define DSERR_CONTROLUNAVAIL MAKE_DSHRESULT(30)
#define DSSCL_EXCLUSIVE DVL_DSSCL_EXCLUSIVE
#define DVL_DSBSTATUS_PLAYING 0x00000001

18
SourceS/miniwin/com_macro.h

@ -3,17 +3,21 @@
#define SW_HIDE DVL_SW_HIDE
#define SW_SHOWNORMAL DVL_SW_SHOWNORMAL
#define LR_DEFAULTCOLOR 0x0000
#define SM_CXSCREEN DVL_SM_CXSCREEN
#define SM_CYSCREEN DVL_SM_CYSCREEN
#define GW_HWNDNEXT 2
#define E_FAIL DVL_E_FAIL
#define S_OK DVL_S_OK
#define MAKE_HRESULT DVL_MAKE_HRESULT
#define DDERR_INVALIDOBJECT 0x88760082
#define DDERR_OUTOFMEMORY 0x8876000E
#define DD_OK S_OK
#define DDBLTFAST_WAIT 0x00000010
#define PC_RESERVED 0x01
#define PC_NOCOLLAPSE 0x04
#define ERROR_SUCCESS DVL_ERROR_SUCCESS
#define DS_OK DVL_DS_OK
#include "miniwin/com/ddraw_macro.inc"
#include "miniwin/com/dsound_macro.inc"

12
SourceS/miniwin/misc.h

@ -88,16 +88,6 @@ typedef struct pcmwaveformat_tag {
WAVEFORMAT wf;
WORD wBitsPerSample;
} PCMWAVEFORMAT, *PPCMWAVEFORMAT, *LPPCMWAVEFORMAT;
typedef struct tWAVEFORMATEX {
WORD wFormatTag;
WORD nChannels;
DWORD nSamplesPerSec;
DWORD nAvgBytesPerSec;
WORD nBlockAlign;
WORD wBitsPerSample;
WORD cbSize;
} WAVEFORMATEX, *LPWAVEFORMATEX, *LPCWAVEFORMATEX;
#pragma pack(pop)
typedef struct _FILETIME {
@ -557,7 +547,7 @@ typedef struct _MEMORY_BASIC_INFORMATION {
// Total fakes
//
typedef struct {
} SOCKADDR, GUID, *LPGUID;
} SOCKADDR;
BOOL IsBadReadPtr(const void *lp, UINT_PTR ucb);
BOOL IsBadWritePtr(LPVOID lp, UINT_PTR ucb);

20
SourceS/miniwin/misc_macro.h

@ -10,29 +10,9 @@
//
// Intrinsics
//
#define LOBYTE(w) ((BYTE)(((DWORD_PTR)(w)) & 0xff))
#define HIBYTE(w) ((BYTE)((((DWORD_PTR)(w)) >> 8) & 0xff))
#define LOWORD(l) ((WORD)(((DWORD_PTR)(l)) & 0xffff))
#define HIWORD(l) ((WORD)((((DWORD_PTR)(l)) >> 16) & 0xffff))
#define INFINITE DVL_INFINITE
#ifndef __BIG_ENDIAN__
#define MAKEFOURCC(x, y, z, w) \
(((uint32_t)((uint8_t)x)) \
| (((uint32_t)((uint8_t)y)) << 8) \
| (((uint32_t)((uint8_t)z)) << 16) \
| (((uint32_t)((uint8_t)w)) << 24))
#else
#define MAKEFOURCC(w, z, y, x) \
(((uint32_t)((uint8_t)x)) \
| (((uint32_t)((uint8_t)y)) << 8) \
| (((uint32_t)((uint8_t)z)) << 16) \
| (((uint32_t)((uint8_t)w)) << 24))
#endif
#define FOURCC_RIFF MAKEFOURCC('R', 'I', 'F', 'F')
#define CreateEvent CreateEventA
#define PM_NOREMOVE DVL_PM_NOREMOVE

12
SourceX/dx.cpp

@ -1,6 +1,7 @@
#include "diablo.h"
#include "../3rdParty/Storm/Source/storm.h"
#include "miniwin/ddraw.h"
#include "miniwin/com_macro.h"
#include <SDL.h>
namespace dvl {
@ -11,7 +12,6 @@ BYTE *gpBuffer;
int locktbl[256];
#endif
static CCritSect sgMemCrit;
char gbEmulate;
HMODULE ghDiabMod;
SDL_Window *window;
@ -47,8 +47,7 @@ void dx_create_back_buffer()
pal_surface = SDL_CreateRGBSurfaceWithFormat(0, BUFFER_WIDTH, BUFFER_HEIGHT, 8, SDL_PIXELFORMAT_INDEX8);
if (pal_surface == NULL) {
SDL_Log(SDL_GetError());
ERR_DLG(IDD_DIALOG1, 0x80000002L); //DDERR_OUTOFMEMORY
return;
ERR_DLG(IDD_DIALOG1, DDERR_OUTOFMEMORY);
}
gpBuffer = (BYTE *)pal_surface->pixels;
@ -59,7 +58,7 @@ void dx_create_back_buffer()
if (SDL_SetSurfacePalette(pal_surface, palette) <= -1) {
#endif
SDL_Log(SDL_GetError());
ERR_DLG(IDD_DIALOG1, 1); //MAKE_HRESULT(130);//DVL_MAKE_HRESULT(130);
ERR_DLG(IDD_DIALOG1, DDERR_INVALIDOBJECT);
}
pal_surface_palette_version = 1;
@ -83,8 +82,7 @@ void dx_create_primary_surface()
#endif
if (surface == NULL) {
SDL_Log(SDL_GetError());
ERR_DLG(IDD_DIALOG1, (HRESULT)0x80000002L); //DDERR_OUTOFMEMORY
return;
ERR_DLG(IDD_DIALOG1, DDERR_OUTOFMEMORY);
}
}
@ -186,7 +184,7 @@ HRESULT CreatePalette()
palette = SDL_AllocPalette(256);
if (palette == NULL) {
SDL_Log(SDL_GetError());
return (HRESULT)0x80000002L; //DDERR_OUTOFMEMORY
return DDERR_OUTOFMEMORY;
}
return DVL_DS_OK;

78
SourceX/miniwin/dsound.cpp

@ -5,34 +5,14 @@
namespace dvl {
ULONG DirectSound::Release()
{
Mix_CloseAudio();
return 0;
};
HRESULT DirectSound::CreateSoundBuffer(LPCDSBUFFERDESC pcDSBufferDesc, LPDIRECTSOUNDBUFFER *ppDSBuffer, LPUNKNOWN pUnkOute)
{
if (pcDSBufferDesc->dwFlags != DVL_DSBCAPS_PRIMARYBUFFER) { // Creating primery buffer isn't needed and breaks Music
*ppDSBuffer = new DirectSoundBuffer();
}
return DVL_DS_OK;
};
///// DirectSoundBuffer /////
ULONG DirectSoundBuffer::Release()
void DirectSoundBuffer::Release()
{
Mix_FreeChunk(chunk);
return 0;
};
/**
* @brief Only used for handeling duplicates
*/
HRESULT DirectSoundBuffer::GetStatus(LPDWORD pdwStatus)
void DirectSoundBuffer::GetStatus(LPDWORD pdwStatus)
{
for (int i = 1; i < Mix_AllocateChannels(-1); i++) {
if (Mix_GetChunk(i) == chunk && Mix_Playing(i)) {
@ -40,48 +20,22 @@ HRESULT DirectSoundBuffer::GetStatus(LPDWORD pdwStatus)
break;
}
}
return DVL_DS_OK;
};
HRESULT DirectSoundBuffer::Lock(DWORD dwOffset, DWORD dwBytes, LPVOID *ppvAudioPtr1, LPDWORD pdwAudioBytes1,
LPVOID *ppvAudioPtr2, LPDWORD pdwAudioBytes2, DWORD dwFlags)
{
*pdwAudioBytes1 = dwBytes;
*ppvAudioPtr1 = malloc(dwBytes);
return DVL_DS_OK;
};
HRESULT DirectSoundBuffer::Play(DWORD dwReserved1, DWORD dwPriority, DWORD dwFlags)
void DirectSoundBuffer::Play(int lVolume, int lPan)
{
int channel = Mix_PlayChannel(-1, chunk, 0);
if (channel == -1) {
SDL_Log("Too few channels, skipping sound\n");
return DVL_DS_OK;
return;
}
Mix_Volume(channel, volume);
Mix_Volume(channel, pow(10, lVolume / 2000.0) * MIX_MAX_VOLUME);
int pan = copysign(pow(10, -abs(lPan) / 2000.0) * 255, lPan);
Mix_SetPanning(channel, pan > 0 ? pan : 255, pan < 0 ? abs(pan) : 255);
return DVL_DS_OK;
};
HRESULT DirectSoundBuffer::SetVolume(LONG lVolume)
{
volume = pow(10, lVolume / 2000.0) * MIX_MAX_VOLUME;
return DVL_DS_OK;
};
HRESULT DirectSoundBuffer::SetPan(LONG lPan)
{
pan = copysign(pow(10, -abs(lPan) / 2000.0) * 255, lPan);
return DVL_DS_OK;
};
HRESULT DirectSoundBuffer::Stop()
void DirectSoundBuffer::Stop()
{
for (int i = 1; i < Mix_AllocateChannels(-1); i++) {
if (Mix_GetChunk(i) != chunk) {
@ -90,21 +44,21 @@ HRESULT DirectSoundBuffer::Stop()
Mix_HaltChannel(i);
}
return DVL_DS_OK;
};
HRESULT DirectSoundBuffer::Unlock(LPVOID pvAudioPtr1, DWORD dwAudioBytes1, LPVOID pvAudioPtr2, DWORD dwAudioBytes2)
const char *DirectSoundBuffer::SetChunk(BYTE *fileData, DWORD dwBytes)
{
SDL_RWops *rw = SDL_RWFromConstMem(pvAudioPtr1, dwAudioBytes1);
if (rw == NULL) {
SDL_Log(SDL_GetError());
SDL_RWops *buf1 = SDL_RWFromConstMem(fileData, dwBytes);
if (buf1 == NULL) {
return SDL_GetError();
}
chunk = Mix_LoadWAV_RW(rw, 1);
free(pvAudioPtr1);
chunk = Mix_LoadWAV_RW(buf1, 1);
if (chunk == NULL) {
return SDL_GetError();
}
return DVL_DS_OK;
return NULL;
};
} // namespace dvl

16
SourceX/miniwin/dsound.h

@ -6,18 +6,12 @@ namespace dvl {
struct DirectSoundBuffer : public IDirectSoundBuffer {
public:
virtual ULONG Release();
BOOL GetStatus(LPDWORD pdwStatus);
HRESULT Lock(DWORD dwOffset, DWORD dwBytes, LPVOID *ppvAudioPtr1, LPDWORD pdwAudioBytes1,
LPVOID *ppvAudioPtr2, LPDWORD pdwAudioBytes2, DWORD dwFlags);
HRESULT Play(DWORD dwReserved1, DWORD dwPriority, DWORD dwFlags);
HRESULT SetVolume(LONG lVolume);
HRESULT SetPan(LONG lPan);
HRESULT Stop();
HRESULT Unlock(LPVOID pvAudioPtr1, DWORD dwAudioBytes1, LPVOID pvAudioPtr2, DWORD dwAudioBytes2);
virtual void Release();
void GetStatus(LPDWORD pdwStatus);
void Play(int lVolume, int lPan);
void Stop();
const char *SetChunk(BYTE *fileData, DWORD dwBytes);
private:
int volume = 0;
int pan = 0;
Mix_Chunk *chunk;
};

2
SourceX/miniwin/misc.cpp

@ -279,7 +279,7 @@ HWND CreateWindowExA(
int upscale = 1;
DvlIntSetting("upscale", &upscale);
DvlIntSetting("fullscreen", &fullscreen);
DvlIntSetting("fullscreen", (int *)&fullscreen);
int grabInput = 1;
DvlIntSetting("grab input", &grabInput);

211
SourceX/sound.cpp

@ -1,18 +1,15 @@
#include "devilution.h"
#include "miniwin/dsound.h"
#include "stubs.h"
#include <SDL.h>
#include <SDL_mixer.h>
namespace dvl {
LPDIRECTSOUNDBUFFER DSBs[8];
LPDIRECTSOUND sglpDS;
BOOLEAN gbSndInited;
int sglMusicVolume;
int sglSoundVolume;
HMODULE hDsound_dll;
HANDLE sgpMusicTrack;
LPDIRECTSOUNDBUFFER sglpDSB;
Mix_Music *music;
SDL_RWops *musicRw;
@ -20,9 +17,8 @@ char *musicBuffer;
/* data */
BYTE gbMusicOn = true;
BYTE gbSoundOn = true;
BYTE gbDupSounds = true;
BOOLEAN gbMusicOn = true;
BOOLEAN gbSoundOn = true;
int sgnMusicTrack = 6;
char *sgszMusicTracks[NUM_MUSIC] = {
"Music\\DTowne.wav",
@ -32,30 +28,6 @@ char *sgszMusicTracks[NUM_MUSIC] = {
"Music\\DLvlD.wav",
"Music\\Dintro.wav"
};
char unk_volume[4][2] = {
{ 15, -16 },
{ 15, -16 },
{ 30, -31 },
{ 30, -31 }
};
void snd_update(BOOL bStopAll)
{
DWORD dwStatus, i;
for (i = 0; i < 8; i++) {
if (!DSBs[i])
continue;
if (!bStopAll && DSBs[i]->GetStatus(&dwStatus) == DVL_DS_OK && dwStatus == DVL_DSBSTATUS_PLAYING)
continue;
DSBs[i]->Stop();
DSBs[i]->Release();
DSBs[i] = NULL;
}
}
void snd_stop_snd(TSnd *pSnd)
{
@ -73,8 +45,7 @@ BOOL snd_playing(TSnd *pSnd)
if (pSnd->DSB == NULL)
return false;
if (pSnd->DSB->GetStatus(&dwStatus) != DVL_DS_OK)
return false;
pSnd->DSB->GetStatus(&dwStatus);
return dwStatus == DVL_DSBSTATUS_PLAYING;
}
@ -83,7 +54,6 @@ void snd_play_snd(TSnd *pSnd, int lVolume, int lPan)
{
LPDIRECTSOUNDBUFFER DSB;
DWORD tc;
HRESULT error_code;
if (!pSnd || !gbSoundOn) {
return;
@ -105,56 +75,17 @@ void snd_play_snd(TSnd *pSnd, int lVolume, int lPan)
} else if (lVolume > VOLUME_MAX) {
lVolume = VOLUME_MAX;
}
DSB->SetVolume(lVolume);
DSB->SetPan(lPan);
error_code = DSB->Play(0, 0, 0);
if (error_code != DVL_DSERR_BUFFERLOST) {
if (error_code != DVL_DS_OK) {
DSErrMsg(error_code, __LINE__, __FILE__);
}
} else if (sound_file_reload(pSnd, DSB)) {
DSB->Play(0, 0, 0);
}
DSB->Play(lVolume, lPan);
pSnd->start_tc = tc;
}
BOOL sound_file_reload(TSnd *sound_file, LPDIRECTSOUNDBUFFER DSB)
{
HANDLE file;
LPVOID buf1, buf2;
DWORD size1, size2;
BOOL rv;
rv = false;
WOpenFile(sound_file->sound_path, &file, false);
WSetFilePointer(file, sound_file->chunk.dwOffset, NULL, 0);
if (DSB->Lock(0, sound_file->chunk.dwSize, &buf1, &size1, &buf2, &size2, 0) == DVL_DS_OK) {
WReadFile(file, buf1, size1);
if (DSB->Unlock(buf1, size1, buf2, size2) == DVL_DS_OK)
rv = true;
}
WCloseFile(file);
return rv;
}
TSnd *sound_file_load(char *path)
{
HANDLE file;
BYTE *wave_file;
TSnd *pSnd;
LPVOID buf1, buf2;
DWORD size1, size2;
HRESULT error_code;
if (!sglpDS)
return NULL;
DWORD dwBytes;
const char *error;
WOpenFile(path, &file, false);
pSnd = (TSnd *)DiabloAllocPtr(sizeof(TSnd));
@ -162,48 +93,20 @@ TSnd *sound_file_load(char *path)
pSnd->sound_path = path;
pSnd->start_tc = GetTickCount() - 81;
wave_file = LoadWaveFile(file, &pSnd->fmt, &pSnd->chunk);
if (!wave_file)
app_fatal("Invalid sound format on file %s", pSnd->sound_path);
sound_CreateSoundBuffer(pSnd);
error_code = pSnd->DSB->Lock(0, pSnd->chunk.dwSize, &buf1, &size1, &buf2, &size2, 0);
if (error_code != DVL_DS_OK)
DSErrMsg(error_code, __LINE__, __FILE__);
memcpy(buf1, wave_file + pSnd->chunk.dwOffset, size1);
dwBytes = SFileGetFileSize(file, NULL);
wave_file = DiabloAllocPtr(dwBytes);
SFileReadFile(file, wave_file, dwBytes, NULL, NULL);
error_code = pSnd->DSB->Unlock(buf1, size1, buf2, size2);
if (error_code != DVL_DS_OK)
DSErrMsg(error_code, __LINE__, __FILE__);
mem_free_dbg((void *)wave_file);
pSnd->DSB = new DirectSoundBuffer();
error = pSnd->DSB->SetChunk(wave_file, dwBytes);
WCloseFile(file);
mem_free_dbg(wave_file);
if (error != NULL) {
app_fatal("%s: %s", pSnd->sound_path, error);
}
return pSnd;
}
// 456F07: could not find valid save-restore pair for esi
void sound_CreateSoundBuffer(TSnd *sound_file)
{
DUMMY_ONCE();
DSBUFFERDESC DSB;
HRESULT error_code;
memset(&DSB, 0, sizeof(DSBUFFERDESC));
DSB.dwBufferBytes = sound_file->chunk.dwSize;
DSB.lpwfxFormat = &sound_file->fmt;
DSB.dwSize = sizeof(DSBUFFERDESC);
DSB.dwFlags = DVL_DSBCAPS_CTRLVOLUME | DVL_DSBCAPS_CTRLPAN | DVL_DSBCAPS_STATIC;
sound_file->chunk.dwSize += sound_file->chunk.dwOffset;
sound_file->chunk.dwOffset = 0;
error_code = sglpDS->CreateSoundBuffer(&DSB, &sound_file->DSB, NULL);
if (error_code != DVL_ERROR_SUCCESS)
DSErrMsg(error_code, __LINE__, __FILE__);
}
void sound_file_cleanup(TSnd *sound_file)
{
@ -226,13 +129,14 @@ void snd_init(HWND hWnd)
sound_load_volume("Music Volume", &sglMusicVolume);
gbMusicOn = sglMusicVolume > VOLUME_MIN;
if (sound_DirectSoundCreate(NULL, &sglpDS, NULL) != DVL_DS_OK)
sglpDS = NULL;
if (sglpDS)
sound_create_primary_buffer(NULL);
int result = Mix_OpenAudio(22050, AUDIO_S16LSB, 2, 1024);
if (result < 0) {
SDL_Log(Mix_GetError());
}
Mix_AllocateChannels(25);
Mix_ReserveChannels(1); // reserve one channel for naration (SFileDda*)
gbSndInited = sglpDS != NULL;
gbSndInited = true;
}
void sound_load_volume(char *value_name, int *value)
@ -251,76 +155,10 @@ void sound_load_volume(char *value_name, int *value)
*value -= *value % 100;
}
void sound_create_primary_buffer(HANDLE music_track)
{
HRESULT error_code;
DSBUFFERDESC dsbuf;
WAVEFORMATEX format;
if (!music_track) {
memset(&dsbuf, 0, sizeof(DSBUFFERDESC));
dsbuf.dwSize = sizeof(DSBUFFERDESC);
dsbuf.dwFlags = DVL_DSBCAPS_PRIMARYBUFFER;
error_code = sglpDS->CreateSoundBuffer(&dsbuf, &sglpDSB, NULL);
if (error_code != DVL_DS_OK)
DSErrMsg(error_code, __LINE__, __FILE__);
}
if (sglpDSB) {
DSCAPS dsbcaps;
dsbcaps.dwSize = sizeof(DSCAPS);
if (!music_track || !LoadWaveFormat(music_track, &format)) {
memset(&format, 0, sizeof(WAVEFORMATEX));
format.wFormatTag = DVL_WAVE_FORMAT_PCM;
format.nSamplesPerSec = 22050;
format.wBitsPerSample = 16;
format.cbSize = 0;
}
format.nChannels = 2;
format.nBlockAlign = format.nChannels * format.wBitsPerSample / 8;
format.nAvgBytesPerSec = format.nSamplesPerSec * format.nBlockAlign;
}
}
// 69F100: using guessed type int sglpDSB;
HRESULT sound_DirectSoundCreate(LPGUID lpGuid, LPDIRECTSOUND *ppDS, LPUNKNOWN pUnkOuter)
{
DUMMY();
HRESULT(*DirectSoundCreate)
(LPGUID lpGuid, LPDIRECTSOUND * ppDS, LPUNKNOWN pUnkOuter);
if (hDsound_dll == NULL) {
if (hDsound_dll == NULL) {
}
}
DirectSoundCreate = NULL;
if (DirectSoundCreate == NULL) {
}
*ppDS = new DirectSound();
int result = Mix_OpenAudio(22050, AUDIO_S16LSB, 2, 1024);
if (result < 0) {
SDL_Log(Mix_GetError());
}
Mix_AllocateChannels(25);
Mix_ReserveChannels(1); // reserve one channel for naration (SFileDda*)
return result;
}
void sound_cleanup()
{
snd_update(true);
SFileDdaDestroy();
if (sglpDS) {
sglpDS->Release();
delete sglpDS;
sglpDS = NULL;
}
if (gbSndInited) {
gbSndInited = false;
sound_store_volume("Sound Volume", sglSoundVolume);
@ -353,7 +191,7 @@ void music_start(int nTrack)
/// ASSERT: assert((DWORD) nTrack < NUM_MUSIC);
music_stop();
if (sglpDS && gbMusicOn) {
if (gbMusicOn) {
#ifdef _DEBUG
SFileEnableDirectAccess(false);
#endif
@ -361,7 +199,6 @@ void music_start(int nTrack)
#ifdef _DEBUG
SFileEnableDirectAccess(true);
#endif
sound_create_primary_buffer(sgpMusicTrack);
if (!success) {
sgpMusicTrack = NULL;
} else {

2
SourceX/storm/storm.cpp

@ -58,7 +58,7 @@ BOOL SFileDdaBeginEx(HANDLE hFile, DWORD flags, DWORD mask, unsigned __int32 lDi
{
DWORD bytestoread = SFileGetFileSize(hFile, 0);
char *SFXbuffer = (char *)malloc(bytestoread);
SFileReadFile(hFile, SFXbuffer, bytestoread, NULL, 0);
SFileReadFile(hFile, SFXbuffer, bytestoread, NULL, NULL);
SDL_RWops *rw = SDL_RWFromConstMem(SFXbuffer, bytestoread);
if (rw == NULL) {

7
structs.h

@ -449,14 +449,7 @@ typedef struct MissileStruct {
// effects/sound
//////////////////////////////////////////////////
typedef struct CKINFO {
DWORD dwSize;
DWORD dwOffset;
} CKINFO;
typedef struct TSnd {
WAVEFORMATEX fmt;
CKINFO chunk;
char *sound_path;
LPDIRECTSOUNDBUFFER DSB;
int start_tc;

Loading…
Cancel
Save