Skip to content

Commit 7fa7c12

Browse files
committed
allow kenbuild to compile with Xaudio2 using MinGW-W64
Using mingw-w64 13.0.0 on macOS cross-compiling to x86-64, the resulting executables can be successfully run under Wine. DLL dependencies are: libgcc_s_seh-1.dll libstdc++-6.dll libwinpthread-1.dll fixes #24
1 parent 37a7331 commit 7fa7c12

File tree

5 files changed

+24
-10
lines changed

5 files changed

+24
-10
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,13 @@ _SDL2.framework_ found in the _.dmg_ file to _xcode/frameworks_.
6969
game with: `nmake /f Makefile.msvc`
7070
4. Assuming that was successful, run the test game with: `data\game`
7171

72+
### With MinGW-W64 cross-compiling for Windows
73+
74+
1. (For example, on macOS with Homebrew) Install _mingw-w64_ with: `brew install mingw-w64`
75+
2. Change into the _kenbuild_ subdirectory of this cloned repository, then compile
76+
the test game with: `make HOST{CC=cc,CXX=c++} $(set CC=gcc CXX=g++ RC=windres
77+
RANLIB=ranlib AR=ar; echo ${@/=/=x86_64-w64-mingw32-})`
78+
7279
Compilation options
7380
-------------------
7481

kenbuild/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,9 @@ ifeq ($(RENDERTYPE),SDL)
8787
endif
8888
endif
8989
ifeq ($(RENDERTYPE),WIN)
90-
GAMEEXEOBJS+= $(SRC)/kdmsound_stub.$o $(SRC)/gameres.$(res) $(SRC)/startwin_game.$o
90+
GAMEEXEOBJS+= $(SRC)/kdmsound_xaudio2.$o $(SRC)/gameres.$(res) $(SRC)/startwin_game.$o
9191
EDITOREXEOBJS+= $(SRC)/buildres.$(res)
92+
GAMELDFLAGS+= -lxaudio2_9 -lole32
9293
endif
9394

9495
.PHONY: clean veryclean all

kenbuild/src/kdmsound.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ void setears(int daposx, int daposy, int daxvect, int dayvect)
176176
unlockkdm();
177177
}
178178

179-
void wsayfollow(char *dafilename, int dafreq, int davol, int *daxplc, int *dayplc, char followstat)
179+
void wsayfollow(const char *dafilename, int dafreq, int davol, int *daxplc, int *dayplc, char followstat)
180180
{
181181
char ch1, ch2, bad;
182182
int i, wavnum, chanum;
@@ -234,7 +234,7 @@ void wsayfollow(char *dafilename, int dafreq, int davol, int *daxplc, int *daypl
234234
}
235235
}
236236

237-
void wsay(char *dafilename, int dafreq, int volume1, int volume2)
237+
void wsay(const char *dafilename, int dafreq, int volume1, int volume2)
238238
{
239239
char ch1, ch2;
240240
int i, j, bad;
@@ -266,7 +266,7 @@ void wsay(char *dafilename, int dafreq, int volume1, int volume2)
266266
} while (i >= 0);
267267
}
268268

269-
void loadwaves(char *wavename)
269+
void loadwaves(const char *wavename)
270270
{
271271
int fil, i, j, dawaversionum, totsndbytes;
272272

@@ -321,7 +321,7 @@ void loadwaves(char *wavename)
321321
snd[totsndbytes] = snd[totsndbytes+1] = 128;
322322
}
323323

324-
int loadsong(char *filename)
324+
int loadsong(const char *filename)
325325
{
326326
int i, fil;
327327
int kdmversionum;

kenbuild/src/kdmsound.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ void uninitsb(void);
2323
void refreshaudio(void);
2424

2525
void setears(int daposx, int daposy, int daxvect, int dayvect);
26-
void wsayfollow(char *dafilename, int dafreq, int davol, int *daxplc, int *dayplc, char followstat);
27-
void wsay(char *dafilename, int dafreq, int volume1, int volume2);
28-
void loadwaves(char *wavename);
29-
int loadsong(char *songname);
26+
void wsayfollow(const char *dafilename, int dafreq, int davol, int *daxplc, int *dayplc, char followstat);
27+
void wsay(const char *dafilename, int dafreq, int volume1, int volume2);
28+
void loadwaves(const char *wavename);
29+
int loadsong(const char *songname);
3030
void musicon(void);
3131
void musicoff(void);
3232

kenbuild/src/kdmsound_xaudio2.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111
#include "windows.h"
1212
#include "xaudio2.h"
1313

14+
#if defined(__MINGW32__) && !defined(XAUDIO2_USE_DEFAULT_PROCESSOR)
15+
#define XAUDIO2_USE_DEFAULT_PROCESSOR XAUDIO2_ANY_PROCESSOR
16+
#endif
17+
#define kmin(a,b) ((a)<(b)?(a):(b))
18+
#define kmax(a,b) ((a)>(b)?(a):(b))
19+
1420
extern "C" {
1521
#define KDMSOUND_INTERNAL
1622
#include "kdmsound.h"
@@ -73,7 +79,7 @@ void initsb(char dadigistat, char damusistat, int dasamplerate, char danumspeake
7379

7480
WAVEFORMATEX sourcefmt = {0};
7581
sourcefmt.wFormatTag = WAVE_FORMAT_PCM;
76-
sourcefmt.nChannels = max(1, min(2, danumspeakers));
82+
sourcefmt.nChannels = kmax(1, kmin(2, danumspeakers));
7783
sourcefmt.nSamplesPerSec = dasamplerate;
7884
sourcefmt.wBitsPerSample = dabytespersample * 8;
7985
sourcefmt.nBlockAlign = sourcefmt.nChannels * dabytespersample;

0 commit comments

Comments
 (0)