Skip to content

Commit

Permalink
Replicated incpack tool and re-dumped Wave100 to make sure it's okay.
Browse files Browse the repository at this point in the history
  • Loading branch information
Yukitty committed Sep 6, 2016
1 parent b5f88d9 commit fe47b07
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions src/Wave100.inc
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
62 changes: 62 additions & 0 deletions src/incpack.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// incpack utility
// Takes a file
// Dumps an equivalent C array to a .inc file.

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#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;
}

0 comments on commit fe47b07

Please sign in to comment.