diff --git a/GNUmakefile b/GNUmakefile index 3c4827f67..2fa91b43e 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -59,6 +59,7 @@ libxmplite_objs := \ itsex.c \ it_load.c \ mod_load.c \ + mtm_load.c \ s3m_load.c \ sample.c \ xm_load.c \ diff --git a/platform/Windows/msvc.mak b/platform/Windows/msvc.mak index 3947b8a25..6c2504bb5 100644 --- a/platform/Windows/msvc.mak +++ b/platform/Windows/msvc.mak @@ -216,10 +216,10 @@ LIBXMPLITE_OBJS=$(LIBXMPLITE_OBJ)\control.$o \ $(LIBXMPLITE_OBJ)\itsex.$o \ $(LIBXMPLITE_OBJ)\it_load.$o \ $(LIBXMPLITE_OBJ)\mod_load.$o \ + $(LIBXMPLITE_OBJ)\mtm_load.$o \ $(LIBXMPLITE_OBJ)\s3m_load.$o \ $(LIBXMPLITE_OBJ)\sample.$o \ - $(LIBXMPLITE_OBJ)\xm_load.$o - + $(LIBXMPLITE_OBJ)\xm_load.$o \ AUDIOLIB_OBJS=$(AUDIOLIB_OBJ)\drivers.$o \ $(AUDIOLIB_OBJ)\fx_man.$o \ diff --git a/source/audiolib/src/xmp.cpp b/source/audiolib/src/xmp.cpp index 11a613bae..f1210366e 100644 --- a/source/audiolib/src/xmp.cpp +++ b/source/audiolib/src/xmp.cpp @@ -249,7 +249,7 @@ int32_t MV_PlayXMP3D(char *ptr, uint32_t ptrlength, int32_t loophow, int32_t pit #endif -// KEEPINSYNC libxmp-lite/src/loaders/*_load.c +// KEEPINSYNC libxmp-lite/src/*_load.c static int it_test_memory(char const *ptr, uint32_t ptrlength) { @@ -312,10 +312,33 @@ static int xm_test_memory(char const *ptr, uint32_t ptrlength) return 0; } +static int mtm_test_memory(char const *ptr, uint32_t ptrlength) +{ + static char const mtm_magic[] = "MTM\x10"; + + if (ptrlength < sizeof(mtm_magic)-1 || + memcmp(ptr, mtm_magic, sizeof(mtm_magic)-1)) + return -1; + + return 0; +} + int MV_IdentifyXMP(char const *ptr, uint32_t ptrlength) { - return it_test_memory(ptr, ptrlength) == 0 || - mod_test_memory(ptr, ptrlength) == 0 || - s3m_test_memory(ptr, ptrlength) == 0 || - xm_test_memory(ptr, ptrlength) == 0; + static decltype(mod_test_memory) * const module_test_functions[] = + { + it_test_memory, + mod_test_memory, + s3m_test_memory, + xm_test_memory, + mtm_test_memory, + }; + + for (auto const test_module : module_test_functions) + { + if (test_module(ptr, ptrlength) == 0) + return 1; + } + + return 0; } diff --git a/source/libxmp-lite/src/format.c b/source/libxmp-lite/src/format.c index def12d5b5..8297d386d 100644 --- a/source/libxmp-lite/src/format.c +++ b/source/libxmp-lite/src/format.c @@ -31,21 +31,23 @@ extern const struct format_loader libxmp_loader_xm; extern const struct format_loader libxmp_loader_mod; extern const struct format_loader libxmp_loader_it; extern const struct format_loader libxmp_loader_s3m; +extern const struct format_loader libxmp_loader_mtm; extern const struct pw_format *const pw_format[]; extern const struct format_loader *const format_loader[]; -const struct format_loader *const format_loader[5] = { +const struct format_loader *const format_loader[] = { &libxmp_loader_xm, &libxmp_loader_mod, #ifndef LIBXMP_CORE_DISABLE_IT &libxmp_loader_it, #endif &libxmp_loader_s3m, + &libxmp_loader_mtm, NULL }; -static const char *_farray[5] = { NULL }; +static const char *_farray[sizeof(format_loader)/sizeof(struct format_loader *)] = { NULL }; const char **format_list() { diff --git a/source/libxmp-lite/src/mtm_load.c b/source/libxmp-lite/src/mtm_load.c index 1b482e716..d48401973 100644 --- a/source/libxmp-lite/src/mtm_load.c +++ b/source/libxmp-lite/src/mtm_load.c @@ -50,6 +50,7 @@ struct mtm_instrument_header { static int mtm_test(HIO_HANDLE *, char *, const int); static int mtm_load(struct module_data *, HIO_HANDLE *, const int); +extern const struct format_loader libxmp_loader_mtm; const struct format_loader libxmp_loader_mtm = { "Multitracker", mtm_test,