diff --git a/src/Makefile b/src/Makefile index 221bd28..4503445 100644 --- a/src/Makefile +++ b/src/Makefile @@ -7,6 +7,9 @@ OBJECTS= in_org.o in_org-res.o in_org.dll: $(OBJECTS) $(CC) $(LFLAGS) -o $@ $(OBJECTS) +incpack.exe: incpack.c + $(CC) -o $@ $< -Wall -Wextra -O2 -s -std=gnu99 + %.o: %.c $(wildcard *.inc) $(CC) -c -o $@ $< $(CFLAGS) diff --git a/src/Wave100.inc b/src/Wave100.inc index 4d8653a..69c2d93 100644 --- a/src/Wave100.inc +++ b/src/Wave100.inc @@ -1,6 +1,6 @@ -// Official ORG instrument from Studio Pixel +// Official ORG instrument by Studio Pixel #define WAVELENGTH 256 -const unsigned char Wave100[WAVELENGTH*100] = { +static const unsigned char Wave100[WAVELENGTH*100] = { 0x00,0xFE,0xFC,0xFB,0xF9,0xF8,0xF5,0xF3,0xF0,0xED,0xEB,0xE9,0xE8,0xE6,0xE4,0xE3, 0xE1,0xE0,0xDE,0xDC,0xDC,0xDB,0xDA,0xD9,0xD8,0xD8,0xD6,0xD6,0xD5,0xD4,0xD3,0xD3, 0xD2,0xD1,0xD0,0xD0,0xD0,0xCF,0xCE,0xCE,0xCD,0xCC,0xCC,0xCC,0xCB,0xCB,0xCA,0xCA, diff --git a/src/incpack.c b/src/incpack.c new file mode 100644 index 0000000..327ccf3 --- /dev/null +++ b/src/incpack.c @@ -0,0 +1,62 @@ +// incpack utility +// Takes a file +// Dumps an equivalent C array to a .inc file. + +#include +#include +#include + +#define CHUNK 1024 + +int main(int argc, char *argv[]) +{ + unsigned char in[CHUNK]; + + puts("incdump"); + + const char *file = "Wave100.dat"; + if (argc > 1) + file = argv[1]; + + FILE *source = fopen(file, "rb"); + if (!source) + { + printf("File '%s' not found.", file); + return EXIT_FAILURE; + } + + char asset_name[64]; + { + const char *fp = file + strlen(file); + while (--fp > file && *fp != '/' && *fp != '\\'); + if (*fp == '/' || *fp == '\\') ++fp; + strncpy(asset_name, fp, 63); + asset_name[63] = '\0'; + char *ap = asset_name; + while (*ap++) { if (*ap == '.') *ap = '\0'; } + strcpy(&asset_name[strlen(asset_name)], ".inc"); + } + + printf("Compressing '%s' to '%s'\n", file, asset_name); + + FILE *dest = fopen(asset_name, "w"); + asset_name[strlen(asset_name)-4]='\0'; + fprintf(dest, "static const unsigned char %s[] = {", asset_name); + + unsigned len = 0; + do { + len = fread(in, 1, CHUNK, source); + for (unsigned i = 0; i < len; i++) + { + if (i%16 == 0) + fprintf(dest,"\n\t"); + fprintf(dest,"0x%02X,",in[i]); + } + } while (len > 0); + fclose(source); + fputs("};", dest); + fclose(dest); + + puts("Done!"); + return EXIT_SUCCESS; +}