Commit 548599c2 authored by Erik Faye-Lund's avatar Erik Faye-Lund
Browse files

pimpconv: port to C

While we're at it, port load_xm.c and load_mod.c, as well as the
tests.
parent 3b6d55eb
......@@ -33,7 +33,6 @@ endif
define setup-gcc
$(1)CC = $(2)gcc
$(1)CXX = $(2)g++
$(1)STRIP = $(2)strip
$(1)LD = $(2)ld
$(1)AS = $(2)as
......@@ -42,7 +41,6 @@ endef
define setup-armcc
$(1)CC = armcc
$(1)CXX = armcpp
$(1)STRIP = strip
$(1)LD = armlink
$(1)AS = armasm
......@@ -59,7 +57,6 @@ $(eval $(call setup-gcc,,))
ifneq ($(findstring $(MAKEFLAGS),s),s)
QUIET_CC = @echo ' ' CC $@;
QUIET_CXX = @echo ' ' CXX $@;
QUIET_AS = @echo ' ' AS $@;
QUIET_AR = @echo ' ' AR $@;
QUIET_LINK = @echo ' ' LINK $@;
......@@ -71,14 +68,12 @@ ifeq ($(TARGET), arm-gba)
TARGET_CPPFLAGS = -I$(DEVKITARM)/include -DTARGET_GBA
TARGET_COMMON = -mcpu=arm7tdmi -mtune=arm7tdmi -mthumb-interwork
TARGET_CFLAGS = $(TARGET_COMMON) -mlong-calls
TARGET_CXXFLAGS = $(TARGET_COMMON) -mlong-calls
TARGET_LDFLAGS = $(TARGET_COMMON) -Wl,--gc-section
TARGET_ASFLAGS = $(TARGET_COMMON)
endif
CPPFLAGS =
CFLAGS = -pedantic -Wall -Wno-long-long
CXXFLAGS = -fconserve-space -fno-rtti -fno-exceptions
LDFLAGS =
ASFLAGS =
ARFLAGS = rcs
......@@ -103,7 +98,7 @@ ARM_SOURCES = \
PIMPCONV_SOURCES = \
converter/pimpconv.c \
converter/serializer.cpp \
converter/serializer.c \
converter/serialize_module.c \
converter/serialize_instrument.c \
src/convert_sample.c \
......@@ -113,13 +108,11 @@ PIMPCONV_SOURCES = \
ifeq ($(CONFIG), debug)
CPPFLAGS += -DDEBUG
CXXFLAGS += -g -ggdb
CFLAGS += -g -ggdb
SOURCES += src/pimp_mixer_portable.c
SOURCES += src/pimp_debug.c
else
CPPFLAGS += -DRELEASE -DNDEBUG
CXXFLAGS += -O3 -fomit-frame-pointer
CFLAGS += -O3 -fomit-frame-pointer
SOURCES += src/pimp_mixer_arm.S
SOURCES += src/pimp_mixer_clip_arm.S
......@@ -127,7 +120,6 @@ endif
ifeq ($(PROFILING), 1)
CFLAGS += -finstrument-functions
CXXFLAGS += -finstrument-functions
SOURCES += profiling/cyg-profile.c
endif
......@@ -137,8 +129,6 @@ HOST_BUILD_DIR = $(BUILD_DIR)/$(HOST)/$(CONFIG)
source-to-object = \
$(subst .c,.o, $(filter-out $(ARM_SOURCES), $(filter %.c,$1))) \
$(subst .c,.iwram.o, $(filter $(ARM_SOURCES), $(filter %.c,$1))) \
$(subst .cpp,.o, $(filter-out $(ARM_SOURCES), $(filter %.cpp,$1))) \
$(subst .cpp,.iwram.o,$(filter $(ARM_SOURCES), $(filter %.cpp,$1))) \
$(subst .S,.o, $(filter-out $(ARM_SOURCES), $(filter %.S,$1))) \
$(subst .S,.iwram.o, $(filter $(ARM_SOURCES), $(filter %.S,$1)))
......@@ -179,7 +169,6 @@ TAGS:
$(call make-target-objs, $(filter-out $(ARM_SOURCES), $(SOURCES))): TARGET_CFLAGS += -mthumb
$(call make-target-objs, $(filter $(ARM_SOURCES), $(SOURCES))): TARGET_CFLAGS += -marm
bin/pimpconv$(EXE_EXT): CC = $(HOST_CXX) # make sure we use the c++ compiler for this
bin/pimpconv$(EXE_EXT): $(call make-host-objs, $(PIMPCONV_SOURCES))
$(QUIET_LINK)$(LINK.o) $^ $(LOADLIBES) $(LDLIBS) $(OUTPUT_OPTION)
......@@ -193,10 +182,7 @@ $(TARGET_BUILD_DIR)/%.o: CFLAGS += $(TARGET_CFLAGS)
$(TARGET_BUILD_DIR)/%.o: ASFLAGS += $(TARGET_ASFLAGS)
# Override CC for host-builds
$(HOST_BUILD_DIR)/%.o: CFLAGS += $(HOST_CFLAGS)
$(HOST_BUILD_DIR)/%.o: CXXFLAGS += $(HOST_CXXFLAGS)
bin/pimpconv$(EXE_EXT): CC = $(CXX)
bin/pimpconv$(EXE_EXT): LDFLAGS += $(HOST_LDFLAGS) -lstdc++
bin/pimpconv$(EXE_EXT): LOADLIBES += -lm
### C
......@@ -212,12 +198,6 @@ $(HOST_BUILD_DIR)/%.o: %.c
@$(MKDIR) $(dir $@)
$(QUIET_CC)$(COMPILE.c) $(OUTPUT_OPTION) $< -MMD -MP -MF $(@:.o=.d)
### C++
$(HOST_BUILD_DIR)/%.o: %.cpp
@$(MKDIR) $(dir $@)
$(QUIET_CXX)$(COMPILE.cpp) $(OUTPUT_OPTION) $< -MMD -MP -MF $(@:.o=.d)
### ASM
$(TARGET_BUILD_DIR)/%.o: %.S
......
......@@ -91,12 +91,12 @@ static void merge_samples(struct pimp_sample_bank *dst, const struct pimp_sample
for (i = 0; i < mod->instrument_count; ++i)
{
int j;
pimp_instrument *instr = pimp_module_get_instrument(mod, i);
struct pimp_instrument *instr = pimp_module_get_instrument(mod, i);
for (j = 0; j < instr->sample_count; ++j)
{
int pos;
void *data = NULL;
pimp_sample *samp = pimp_instrument_get_sample(instr, j);
struct pimp_sample *samp = pimp_instrument_get_sample(instr, j);
ASSERT(NULL != samp);
data = pimp_sample_bank_get_sample_data(src, samp->data_ptr);
......
......@@ -15,7 +15,7 @@
#define TRACE()
#endif
int serialize_sample(struct serializer *s, const pimp_sample *samp)
int serialize_sample(struct serializer *s, const struct pimp_sample *samp)
{
int pos;
......@@ -46,7 +46,7 @@ int serialize_sample(struct serializer *s, const pimp_sample *samp)
return pos;
}
int serialize_envelope(struct serializer *s, const pimp_envelope *env)
int serialize_envelope(struct serializer *s, const struct pimp_envelope *env)
{
int pos, i;
......@@ -85,10 +85,10 @@ int serialize_envelope(struct serializer *s, const pimp_envelope *env)
}
/* dumps all samples in an instrument, returns position of first sample */
void serialize_instrument_data(struct serializer *s, const pimp_instrument *instr)
void serialize_instrument_data(struct serializer *s, const struct pimp_instrument *instr)
{
struct pimp_envelope *vol_env, *pan_env;
int i;
pimp_envelope *vol_env, *pan_env;
ASSERT(NULL != instr);
ASSERT(NULL != s);
......@@ -110,7 +110,7 @@ void serialize_instrument_data(struct serializer *s, const pimp_instrument *inst
}
/* dump instrument structure, return position */
void serialize_instrument(struct serializer *s, const pimp_instrument *instr)
void serialize_instrument(struct serializer *s, const struct pimp_instrument *instr)
{
int i;
......
......@@ -9,12 +9,12 @@
struct serializer;
/* serialize a sample */
int serialize_sample(struct serializer *s, const pimp_sample *samp);
int serialize_sample(struct serializer *s, const struct pimp_sample *samp);
/* serialize all samples in an instrument */
void serialize_instrument_data(struct serializer *s, const pimp_instrument *instr);
void serialize_instrument_data(struct serializer *s, const struct pimp_instrument *instr);
/* serialize instrument structure */
void serialize_instrument(struct serializer *s, const pimp_instrument *instr);
void serialize_instrument(struct serializer *s, const struct pimp_instrument *instr);
#endif /* DUMP_INSTRUMENT_H */
......@@ -51,7 +51,7 @@ void serialize_module_struct(struct serializer *s, const pimp_module *mod)
serialize_byte(s, mod->channel_count);
}
void serialize_channels(struct serializer *s, const pimp_module *mod)
void serialize_channels(struct serializer *s, const struct pimp_module *mod)
{
int i;
......@@ -64,14 +64,14 @@ void serialize_channels(struct serializer *s, const pimp_module *mod)
serializer_set_pointer(s, pimp_get_ptr(&mod->channel_ptr), s->pos);
for (i = 0; i < mod->channel_count; ++i)
{
const pimp_channel *chan = pimp_module_get_channel(mod, i);
const struct pimp_channel *chan = pimp_module_get_channel(mod, i);
serialize_byte(s, chan->pan);
serialize_byte(s, chan->volume);
serialize_byte(s, chan->mute);
}
}
void serialize_instruments(struct serializer *s, const pimp_module *mod)
void serialize_instruments(struct serializer *s, const struct pimp_module *mod)
{
int i;
......@@ -84,19 +84,19 @@ void serialize_instruments(struct serializer *s, const pimp_module *mod)
serializer_set_pointer(s, pimp_get_ptr(&mod->instrument_ptr), s->pos);
for (i = 0; i < mod->instrument_count; ++i)
{
const pimp_instrument *instr = pimp_module_get_instrument(mod, i);
const struct pimp_instrument *instr = pimp_module_get_instrument(mod, i);
serialize_instrument(s, instr);
}
/* dump instrument data (samples, envelopes etc) */
for (i = 0; i < mod->instrument_count; ++i)
{
const pimp_instrument *instr = pimp_module_get_instrument(mod, i);
const struct pimp_instrument *instr = pimp_module_get_instrument(mod, i);
serialize_instrument_data(s, instr);
}
}
void serialize_orders(struct serializer *s, const pimp_module *mod)
void serialize_orders(struct serializer *s, const struct pimp_module *mod)
{
int i;
......@@ -112,7 +112,7 @@ void serialize_orders(struct serializer *s, const pimp_module *mod)
}
}
void serialize_patterns(struct serializer *s, const pimp_module *mod)
void serialize_patterns(struct serializer *s, const struct pimp_module *mod)
{
int i;
......@@ -125,7 +125,7 @@ void serialize_patterns(struct serializer *s, const pimp_module *mod)
serializer_set_pointer(s, pimp_get_ptr(&mod->pattern_ptr), s->pos);
for (i = 0; i < mod->pattern_count; ++i)
{
const pimp_pattern *pattern = pimp_module_get_pattern(mod, i);
const struct pimp_pattern *pattern = pimp_module_get_pattern(mod, i);
serializer_align(s, 4);
serialize_pointer(s, pimp_get_ptr(&pattern->data_ptr)); /* data_ptr */
......@@ -136,9 +136,9 @@ void serialize_patterns(struct serializer *s, const pimp_module *mod)
for (i = 0; i < mod->pattern_count; ++i)
{
int j;
const pimp_pattern_entry *pattern_data = NULL;
const struct pimp_pattern_entry *pattern_data = NULL;
const pimp_pattern *pattern = pimp_module_get_pattern(mod, i);
const struct pimp_pattern *pattern = pimp_module_get_pattern(mod, i);
if (NULL == pattern) continue;
pattern_data = pimp_pattern_get_data(pattern);
......@@ -149,7 +149,7 @@ void serialize_patterns(struct serializer *s, const pimp_module *mod)
/* write the actual pattern data data */
for (j = 0; j < pattern->row_count * mod->channel_count; ++j)
{
const pimp_pattern_entry *pe = &pattern_data[j];
const struct pimp_pattern_entry *pe = &pattern_data[j];
serialize_byte(s, pe->note);
serialize_byte(s, pe->instrument);
serialize_byte(s, pe->volume_command);
......@@ -159,7 +159,7 @@ void serialize_patterns(struct serializer *s, const pimp_module *mod)
}
}
void serialize_module(struct serializer *s, const pimp_module *mod)
void serialize_module(struct serializer *s, const struct pimp_module *mod)
{
ASSERT(NULL != s);
ASSERT(NULL != mod);
......
/* serializer.cpp -- low-level serializer for pimpconv
/* serializer.c -- low-level serializer for pimpconv
* Copyright (C) 2005-2006 Jrn Nystad and Erik Faye-Lund
* For conditions of distribution and use, see copyright notice in LICENSE.TXT
*/
......@@ -57,7 +57,7 @@ void serializer_check_size(struct serializer *s, size_t needed_size)
TRACE();
s->buffer_size = MAX(s->buffer_size * 2, s->buffer_size + needed_size);
s->data = (unsigned char*)realloc(s->data, s->buffer_size);
s->data = realloc(s->data, s->buffer_size);
if (NULL == s->data)
{
......@@ -162,7 +162,7 @@ void serialize_pointer(struct serializer *s, void *ptr)
return;
}
s->relocs = (struct reloc *)realloc(s->relocs, sizeof(struct reloc) * (s->num_relocs + 1));
s->relocs = realloc(s->relocs, sizeof(struct reloc) * (s->num_relocs + 1));
if (!s->relocs) {
fputs("out of memory\n", stderr);
abort();
......
......@@ -47,7 +47,7 @@ static BOOL load_instrument(FILE *fp, struct pimp_instrument *instr, struct pimp
fread(buf, 1, 22, fp);
buf[22] = '\0';
sample = (struct pimp_sample *)malloc(sizeof(struct pimp_sample));
sample = malloc(sizeof(struct pimp_sample));
if (NULL == sample) return FALSE;
/* only one sample per instrument in MOD */
......@@ -168,7 +168,7 @@ pimp_module *load_module_mod(FILE *fp, struct pimp_sample_bank *sample_bank)
channel_count = get_channel_count(sig);
if (channel_count <= 0) return NULL;
mod = (pimp_module *)malloc(sizeof(pimp_module));
mod = malloc(sizeof(pimp_module));
if (NULL == mod) return NULL;
memset(mod, 0, sizeof(pimp_module));
......@@ -202,7 +202,7 @@ pimp_module *load_module_mod(FILE *fp, struct pimp_sample_bank *sample_bank)
mod->channel_count = channel_count;
/* allocate channel array */
channels = (struct pimp_channel *)malloc(sizeof(struct pimp_channel) * mod->channel_count);
channels = malloc(sizeof(struct pimp_channel) * mod->channel_count);
if (NULL == channels) return NULL;
memset(channels, 0, sizeof(struct pimp_channel) * mod->channel_count);
......@@ -222,7 +222,7 @@ pimp_module *load_module_mod(FILE *fp, struct pimp_sample_bank *sample_bank)
{
struct pimp_instrument *instruments;
mod->instrument_count = 31;
instruments = (struct pimp_instrument *)malloc(sizeof(struct pimp_instrument) * mod->instrument_count);
instruments = malloc(sizeof(struct pimp_instrument) * mod->instrument_count);
if (NULL == instruments) return NULL;
memset(instruments, 0, sizeof(struct pimp_instrument) * mod->instrument_count);
......@@ -257,7 +257,7 @@ pimp_module *load_module_mod(FILE *fp, struct pimp_sample_bank *sample_bank)
{
/* allocate memory */
unsigned char *orders = (unsigned char *)malloc(mod->order_count);
unsigned char *orders = malloc(mod->order_count);
if (NULL == orders) return NULL;
memset(orders, 0, mod->order_count);
......@@ -296,7 +296,7 @@ pimp_module *load_module_mod(FILE *fp, struct pimp_sample_bank *sample_bank)
struct pimp_pattern *patterns;
mod->pattern_count = max_pattern + 1;
patterns = (struct pimp_pattern *)malloc(sizeof(struct pimp_pattern) * mod->pattern_count);
patterns = malloc(sizeof(struct pimp_pattern) * mod->pattern_count);
if (NULL == patterns) return NULL;
memset(patterns, 0, sizeof(struct pimp_pattern) * mod->pattern_count);
......@@ -310,7 +310,7 @@ pimp_module *load_module_mod(FILE *fp, struct pimp_sample_bank *sample_bank)
struct pimp_pattern *pat = &patterns[p];
pat->row_count = 64;
pattern_data = (struct pimp_pattern_entry *)malloc(sizeof(struct pimp_pattern_entry) * mod->channel_count * pat->row_count);
pattern_data = malloc(sizeof(struct pimp_pattern_entry) * mod->channel_count * pat->row_count);
if (NULL == pattern_data) return NULL;
pimp_set_ptr(&pat->data_ptr, pattern_data);
......
......@@ -129,7 +129,7 @@ static BOOL load_instrument(FILE *fp, struct pimp_instrument *instr, struct pimp
pimp_set_ptr(&instr->vol_env_ptr, NULL);
if ((ih.vol_type & 1) == 1)
{
struct pimp_envelope *env = (struct pimp_envelope*)malloc(sizeof(struct pimp_envelope));
struct pimp_envelope *env = malloc(sizeof(struct pimp_envelope));
if (NULL == env) return FALSE;
memset(env, 0, sizeof(struct pimp_envelope));
......@@ -168,7 +168,7 @@ static BOOL load_instrument(FILE *fp, struct pimp_instrument *instr, struct pimp
if ((ih.pan_type & 1) == 1)
{
/* panning envelope */
struct pimp_envelope *env = (struct pimp_envelope*)malloc(sizeof(struct pimp_envelope));
struct pimp_envelope *env = malloc(sizeof(struct pimp_envelope));
if (NULL == env) return FALSE;
memset(env, 0, sizeof(struct pimp_envelope));
......@@ -217,7 +217,7 @@ static BOOL load_instrument(FILE *fp, struct pimp_instrument *instr, struct pimp
struct pimp_sample *samples = NULL;
if (instr->sample_count > 0)
{
samples = (struct pimp_sample *)malloc(sizeof(struct pimp_sample) * instr->sample_count);
samples = malloc(sizeof(struct pimp_sample) * instr->sample_count);
if (NULL == samples) return FALSE;
}
pimp_set_ptr(&instr->sample_ptr, samples);
......@@ -226,7 +226,7 @@ static BOOL load_instrument(FILE *fp, struct pimp_instrument *instr, struct pimp
fseek(fp, ih.header_size - (ftell(fp) - last_pos), SEEK_CUR);
/* sample headers allocated dynamically because data needs to be remembered. we're doing two passes here - one for sample headers, and one for sample data. */
sample_headers = (xm_sample_header *)malloc(sizeof(xm_sample_header) * ih.samples);
sample_headers = malloc(sizeof(xm_sample_header) * ih.samples);
if (NULL == sample_headers) return FALSE;
memset(sample_headers, 0, sizeof(xm_sample_header) * ih.samples);
......@@ -459,7 +459,7 @@ pimp_module *load_module_xm(FILE *fp, struct pimp_sample_bank *sample_bank)
}
}
mod = (pimp_module *)malloc(sizeof(pimp_module));
mod = malloc(sizeof(pimp_module));
if (NULL == mod) return NULL;
memset(mod, 0, sizeof(pimp_module));
......@@ -542,7 +542,7 @@ pimp_module *load_module_xm(FILE *fp, struct pimp_sample_bank *sample_bank)
{
struct pimp_channel *channels;
mod->channel_count = xm_header.channels;
channels = (struct pimp_channel *)malloc(sizeof(struct pimp_channel) * mod->channel_count);
channels = malloc(sizeof(struct pimp_channel) * mod->channel_count);
if (NULL == channels) return NULL;
pimp_set_ptr(&mod->channel_ptr, channels);
......@@ -565,7 +565,7 @@ pimp_module *load_module_xm(FILE *fp, struct pimp_sample_bank *sample_bank)
mod->pattern_count = xm_header.patterns;
/* allocate memory for patterns */
patterns = (struct pimp_pattern *)malloc(sizeof(struct pimp_pattern) * mod->pattern_count);
patterns = malloc(sizeof(struct pimp_pattern) * mod->pattern_count);
if (NULL == patterns) return NULL;
pimp_set_ptr(&mod->pattern_ptr, patterns);
......@@ -593,7 +593,7 @@ pimp_module *load_module_xm(FILE *fp, struct pimp_sample_bank *sample_bank)
pat->row_count = pattern_header.rows;
/* allocate memory for pattern data */
pattern_data = (struct pimp_pattern_entry *)malloc(sizeof(struct pimp_pattern_entry) * mod->channel_count * pat->row_count);
pattern_data = malloc(sizeof(struct pimp_pattern_entry) * mod->channel_count * pat->row_count);
if (NULL == pattern_data)
{
return NULL;
......@@ -696,7 +696,7 @@ pimp_module *load_module_xm(FILE *fp, struct pimp_sample_bank *sample_bank)
mod->instrument_count = xm_header.instruments;
/* allocate instruments */
instruments = (struct pimp_instrument *)malloc(sizeof(struct pimp_instrument) * mod->instrument_count);
instruments = malloc(sizeof(struct pimp_instrument) * mod->instrument_count);
if (NULL == instruments) return NULL;
pimp_set_ptr(&mod->instrument_ptr, instruments);
......
......@@ -2,10 +2,9 @@
# Copyright (C) 2005-2007 Jrn Nystad and Erik Faye-Lund
# For conditions of distribution and use, see copyright notice in LICENSE.TXT
CC = g++
CC = gcc
CPPFLAGS = -I.. -DUNIT_TESTING -DDEBUG
CFLAGS = -g
CXXFLAGS = -g
ifdef COMSPEC
EXE_EXT=.exe
......@@ -43,8 +42,8 @@ clean:
run: unit_test$(EXE_EXT)
./unit_test$(EXE_EXT)
unit_test$(EXE_EXT): $(TEST_SOURCES) $(TEST_DEPS_SOURCES) $(FRAMEWORK_SOURCES) ../converter/serializer.cpp
$(LINK.cpp) $^$(LOADLIBES) $(LDLIBS) -o $@
unit_test$(EXE_EXT): $(TEST_SOURCES) $(TEST_DEPS_SOURCES) $(FRAMEWORK_SOURCES) ../converter/serializer.c
$(LINK.c) $^$(LOADLIBES) $(LDLIBS) -o $@
dump_render$(EXE_EXT): toplevel/dump_render.c $(TEST_DEPS_SOURCES)
$(LINK.c) $^$(LOADLIBES) $(LDLIBS) -o $@
......
......@@ -37,7 +37,7 @@ char *test_printf(struct test_suite *suite, const char* fmt, ...)
len = vsnprintf(temp, MAX_TEST_PRINTF_STRING_LEN, fmt, arglist);
va_end(arglist);
string = (char*)malloc(len + 1);
string = malloc(len + 1);
if (NULL != string)
{
va_start(arglist, fmt);
......
......@@ -43,7 +43,7 @@ static void test_mixer_basic(struct test_suite *suite)
*/
int target_size;
pimp_mixer mixer;
struct pimp_mixer mixer;
pimp_mixer_reset(&mixer);
mixer.mix_buffer = mix_buffer + 1;
......@@ -99,7 +99,7 @@ static void test_looping(struct test_suite *suite)
- that a loop happens at the correct sub-sample
*/
pimp_mixer_channel_state chan;
struct pimp_mixer_channel_state chan;
const u8 sample_data[] = { 0x00, 0x01, 0x02, 0x03, 0x04 };
......
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