diff options
Diffstat (limited to 'make')
-rwxr-xr-x | make/joal-alc-CustomJavaCode.java | 6 | ||||
-rwxr-xr-x | make/joal-alc-impl-CustomCCode.c | 16 | ||||
-rwxr-xr-x | make/joal-alc-impl-CustomJavaCode.java | 42 | ||||
-rwxr-xr-x | make/joal-alc.cfg | 21 | ||||
-rwxr-xr-x | make/joal-common-CustomCCode.c | 1 |
5 files changed, 84 insertions, 2 deletions
diff --git a/make/joal-alc-CustomJavaCode.java b/make/joal-alc-CustomJavaCode.java new file mode 100755 index 0000000..8efba6e --- /dev/null +++ b/make/joal-alc-CustomJavaCode.java @@ -0,0 +1,6 @@ +/** Entry point (through function pointer) to C language function: <br> <code> const ALCchar * alcGetString(ALCdevice * device, ALCenum param); </code> */ +public java.lang.String alcGetString(ALCdevice device, int param); + +/** Fetches the names of the available ALC device specifiers. + Equivalent to the C call alcGetString(NULL, ALC_DEVICE_SPECIFIER). */ +public java.lang.String[] alcGetDeviceSpecifiers(); diff --git a/make/joal-alc-impl-CustomCCode.c b/make/joal-alc-impl-CustomCCode.c new file mode 100755 index 0000000..9207210 --- /dev/null +++ b/make/joal-alc-impl-CustomCCode.c @@ -0,0 +1,16 @@ +int strlen_alc(ALCdevice *device, int param, const char* str) { + int len = 0; + if ((device == NULL) && (param == ALC_DEVICE_SPECIFIER)) { + while (*str != 0) { + while (*str != 0) { + ++str; + ++len; + } + ++str; + ++len; + } + return len; + } else { + return strlen(str); + } +} diff --git a/make/joal-alc-impl-CustomJavaCode.java b/make/joal-alc-impl-CustomJavaCode.java new file mode 100755 index 0000000..a2f23c9 --- /dev/null +++ b/make/joal-alc-impl-CustomJavaCode.java @@ -0,0 +1,42 @@ +public java.lang.String alcGetString(ALCdevice device, int param) { + if (device == null && param == ALC_DEVICE_SPECIFIER) { + throw new ALException("Call alcGetDeviceSpecifiers to fetch all available device names"); + } + + ByteBuffer buf = alcGetStringImpl(device, param); + if (buf == null) { + return null; + } + byte[] res = new byte[buf.capacity()]; + buf.get(res); + try { + return new String(res, "US-ASCII"); + } catch (UnsupportedEncodingException e) { + throw new ALException(e); + } +} + +/** Fetches the names of the available ALC device specifiers. + Equivalent to the C call alcGetString(NULL, ALC_DEVICE_SPECIFIER). */ +public java.lang.String[] alcGetDeviceSpecifiers() { + ByteBuffer buf = alcGetStringImpl(null, ALC_DEVICE_SPECIFIER); + if (buf == null) { + return null; + } + byte[] bytes = new byte[buf.capacity()]; + buf.get(bytes); + try { + ArrayList/*<String>*/ res = new ArrayList/*<String>*/(); + int i = 0; + while (i < bytes.length) { + int startIndex = i; + while ((i < bytes.length) && (bytes[i] != 0)) + i++; + res.add(new String(bytes, startIndex, i - startIndex, "US-ASCII")); + i++; + } + return (String[]) res.toArray(new String[0]); + } catch (UnsupportedEncodingException e) { + throw new ALException(e); + } +} diff --git a/make/joal-alc.cfg b/make/joal-alc.cfg index cdc24bb..5425fec 100755 --- a/make/joal-alc.cfg +++ b/make/joal-alc.cfg @@ -12,7 +12,9 @@ ProcAddressTableClassName ALCProcAddressTable GetProcAddressTableExpr ALProcAddressLookup.getALCProcAddressTable() ProcAddressNameExpr LP $UPPERCASE({0}) +Import java.io.UnsupportedEncodingException Import java.nio.* +Import java.util.* Import net.java.games.joal.* Import net.java.games.joal.impl.* @@ -25,8 +27,18 @@ Ignore ^ALC_.+ # to use this routine to look up the ALC function pointers. Ignore alcGetProcAddress -# These routines use or return strings -ReturnsString alcGetString +# Move the body of alcGetString to a private method so we can +# implement alcGetString(NULL, ALC_DEVICE_SPECIFIER) in another method +RenameJavaMethod alcGetString alcGetStringImpl +# Specify the return length of this function with our own custom strlen +ReturnValueCapacity alcGetString strlen_alc(_ptr0, {1}, _res) + +# Note that we don't declare this as "ReturnsString" because we're +# going to wrap it in another method +IncludeAs CustomJavaCode ALC joal-alc-CustomJavaCode.java +IncludeAs CustomJavaCode ALCImpl joal-alc-impl-CustomJavaCode.java + +# These routines use strings ArgumentIsString alcIsExtensionPresent 1 ArgumentIsString alcOpenDevice 0 @@ -54,4 +66,9 @@ SkipProcAddressGen alcMakeContextCurrent JavaEpilogue alcOpenDevice ALProcAddressLookup.resetALCProcAddressTable(); JavaEpilogue alcMakeContextCurrent ALProcAddressLookup.resetALProcAddressTable(); +# To be able to use alcGetString before a context is created we need +# to instrument that routine as well +JavaPrologue alcGetString ALProcAddressLookup.resetALCProcAddressTable(); + IncludeAs CustomCCode joal-common-CustomCCode.c +IncludeAs CustomCCode joal-alc-impl-CustomCCode.c diff --git a/make/joal-common-CustomCCode.c b/make/joal-common-CustomCCode.c index f749723..a58e869 100755 --- a/make/joal-common-CustomCCode.c +++ b/make/joal-common-CustomCCode.c @@ -7,3 +7,4 @@ typedef int intptr_t; /* This header seems to be available on all other platforms */ #include <inttypes.h> #endif +#include <string.h> |