Commit 1f3cc37d authored by PoroCYon's avatar PoroCYon
Browse files

initial

parents
bin/
obj/
test1/
test2/
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.
SED ?= sed
AWK ?= awk
NASM ?= nasm
default: all
%/:
mkdir -p "$@"
obj/4klang.%: mus/4klang.% xlatsection.awk obj/
$(AWK) -f "xlatsection.awk" "$<" > "$@"
obj/4klang.h: mus/4klang.h obj/
$(SED) -E 's/extern "C"/EXTERN_C/' "$<" > "$@"
obj/4klang.o: obj/4klang.asm obj/4klang.inc
$(NASM) -g -I obj -f elf32 -o "$@" "$<"
obj/runner.o: src/runner.c obj/4klang.h
$(CC) -g -m32 -o "$@" -c "$<" -I obj
bin/runner: obj/runner.o obj/4klang.o bin/
$(CC) -g -m32 -o "$@" $(filter-out bin/,$^)
all: bin/runner
clean:
$(RM) -vr bin/ obj/
.PHONY: default all clean
# 4klang on Linux
Small template code to get 4klang running on Linux :)
Quickly hacked together by PoroCYon.
Hugs to Alkama and noby for providing test tracks!
## How to use
### Requirements
* A C compiler, make, sed, awk
* nasm or yasm
### Usage
1. Put the exported 4klang files in the `mus` folder (`4klang.asm`,
`4klang.inc` and `4klang.h`).
2. Run `make`
3. Run `bin/runner`
## License
[WTFPL](/LICENSE).
Put these three files in this directory:
4klang.asm
4klang.inc
4klang.h
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#define __stdcall /* this isn't windows. */
#ifdef __cplusplus
#define EXTERN_C extern "C" /* C++ suxx */
#else
#define EXTERN_C
#endif
#include "4klang.h"
#ifdef FLOAT_32BIT
#define APLAY_SAMPLE_FORMAT "FLOAT_LE"
#else
/*
* If you encounter this error, you should look at your 4klang.h file and check
* the line above the "#define SAMPLE_TYPE" one. This macro definition can be
* used to give the APLAY_SAMPLE_FORMAT the correct string value. Consult the
* aplay(1) manpage for the details. For example, signed 16-bit int is S16_LE.
*/
#error "This 4klang sample type isn't \"supported\" yet."
#endif
#define STRINGIFY(s) _STRINGIFIER(s)
#define _STRINGIFIER(s) #s
static SAMPLE_TYPE output_buffer[MAX_SAMPLES*2];
static char*const aplay_args[] = {
"/usr/bin/aplay",
"-c2",
"-f" APLAY_SAMPLE_FORMAT,
"-r" STRINGIFY(SAMPLE_RATE),
NULL
};
int main() {
// pipefds[0]: read end
// pipefds[1]: write end
int pipefds[2];
pipe(pipefds);
pid_t childpid = fork();
if (!childpid) {
// child process
dup2(pipefds[0], STDIN_FILENO);
execv("/usr/bin/aplay", aplay_args);
} else if (childpid > 0) {
_4klang_render(output_buffer);
ssize_t writesz = 65536 /* pipe buffer size */, readsz;
const char* outbuf = (const char*)output_buffer;
do {
readsz = write(pipefds[1], outbuf, writesz);
outbuf += writesz;
} while (readsz == writesz);
waitpid(childpid, NULL, 0);
} else {
dprintf(STDERR_FILENO, "Err: couldn't fork.\n");
}
}
#
# De-windowsify section and exported symbol names
#
{
if ($0 ~ "^section[\t ]+(\.[^\t ]*)[\t ]+([^\t ]*)[\t ]+align=(.*)$") {
basesect = $3
if (basesect == "code") {
basesect = "text"
}
extra = ""
if (basesect == "text") {
extra = " progbits alloc exec nowrite "
} else if (basesect == "data") {
extra = " progbits alloc noexec write "
} else if (basesect == "bss") {
extra = " nobits alloc noexec write "
}
print $1 " ." basesect $2 extra $4
} else if ($2 ~ "_4klang_render@4" && $1 == "export_func") {
print $1 " 4klang_render"
} else {
print $0
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment