int ftm_load(xmp_file f) { int i, j, k; struct xmp_event *event; struct ftm_header fh; struct ftm_instrument si; uint8 b1, b2, b3; LOAD_INIT(); xmp_fread(&fh.id, 4, 1, f); if (memcmp(fh.id, "FTMN", 4)) return -1; fh.ver = read8(f); fh.nos = read8(f); read16b(f); read32b(f); read32b(f); xmp_fread(&fh.title, 32, 1, f); xmp_fread(&fh.author, 32, 1, f); read16b(f); //mod->len = fh.len; //mod->pat = fh.pat; mod->ins = fh.nos; mod->smp = mod->ins; mod->trk = mod->pat * mod->chn; for (i = 0; i < mod->len; i++) mod->xxo[i] = fh.order[i]; set_type(m, "Face The Music"); MODULE_INFO(); PATTERN_INIT(); /* Load and convert patterns */ if (V(0)) report("Stored patterns: %d ", mod->pat); for (i = 0; i < mod->pat; i++) { PATTERN_ALLOC(i); mod->xxp[i]->rows = 64; TRACK_ALLOC(i); for (j = 0; j < 4; j++) { } reportv(ctx, 0, "."); } INSTRUMENT_INIT(); reportv(ctx, 0, "\nStored samples : %d ", mod->smp); for (i = 0; i < mod->smp; i++) { reportv(ctx, 0, "."); } reportv(ctx, 0, "\n"); mod->flg |= XXM_FLG_MODRNG; return 0; }
static void get_venv(struct module_data *m, int size, FILE *f, void *parm) { struct xmp_module *mod = &m->mod; int i, j, nenv, ins; nenv = read16b(f); D_(D_INFO "Vol envelopes : %d ", nenv); for (i = 0; i < nenv; i++) { ins = read16b(f) - 1; mod->xxi[ins].aei.flg = read8(f) & 0x07; mod->xxi[ins].aei.npt = read8(f); mod->xxi[ins].aei.sus = read8(f); mod->xxi[ins].aei.lps = read8(f); mod->xxi[ins].aei.lpe = read8(f); read8(f); /* 2nd sustain */ //read8(f); /* reserved */ for (j = 0; j < 32; j++) { mod->xxi[ins].aei.data[j * 2 + 0] = read16b(f); mod->xxi[ins].aei.data[j * 2 + 1] = read16b(f); } } }
static void get_venv(struct xmp_context *ctx, int size, FILE *f) { struct xmp_player_context *p = &ctx->p; struct xmp_mod_context *m = &p->m; int i, j, nenv, ins; nenv = read16b(f); reportv(ctx, 1, "Vol envelopes : %d ", nenv); for (i = 0; i < m->xxh->ins; i++) { m->xxae[i] = calloc(4, 32); } for (i = 0; i < nenv; i++) { ins = read16b(f) - 1; m->xxih[ins].aei.flg = read8(f) & 0x07; m->xxih[ins].aei.npt = read8(f); m->xxih[ins].aei.sus = read8(f); m->xxih[ins].aei.lps = read8(f); m->xxih[ins].aei.lpe = read8(f); read8(f); /* 2nd sustain */ //read8(f); /* reserved */ for (j = 0; j < 32; j++) { m->xxae[ins][j * 2 + 0] = read16b(f); m->xxae[ins][j * 2 + 1] = read16b(f); } reportv(ctx, 1, "."); } reportv(ctx, 1, "\n"); }
static int depack_fcm(xmp_file in, xmp_file out) { uint8 c1; uint8 ptable[128]; uint8 pat_pos; uint8 pat_max; int i; int size, ssize = 0; memset(ptable, 0, 128); read32b(in); /* bypass "FC-M" ID */ read16b(in); /* version number? */ read32b(in); /* bypass "NAME" chunk */ pw_move_data(out, in, 20); /* read and write title */ read32b(in); /* bypass "INST" chunk */ /* read and write sample descriptions */ for (i = 0; i < 31; i++) { pw_write_zero(out, 22); /*sample name */ write16b(out, size = read16b(in)); /* size */ ssize += size * 2; write8(out, read8(in)); /* finetune */ write8(out, read8(in)); /* volume */ write16b(out, read16b(in)); /* loop start */ size = read16b(in); /* loop size */ if (size == 0) size = 1; write16b(out, size); } read32b(in); /* bypass "LONG" chunk */ write8(out, pat_pos = read8(in)); /* pattern table lenght */ write8(out, read8(in)); /* NoiseTracker byte */ read32b(in); /* bypass "PATT" chunk */ /* read and write pattern list and get highest patt number */ for (pat_max = i = 0; i < pat_pos; i++) { write8(out, c1 = read8(in)); if (c1 > pat_max) pat_max = c1; } for (; i < 128; i++) write8(out, 0); write32b(out, PW_MOD_MAGIC); /* write ptk ID */ read32b(in); /* bypass "SONG" chunk */ for (i = 0; i <= pat_max; i++) /* pattern data */ pw_move_data(out, in, 1024); read32b(in); /* bypass "SAMP" chunk */ pw_move_data(out, in, ssize); /* sample data */ return 0; }
static int mfp_load(struct xmp_context *ctx, FILE *f, const int start) { struct xmp_player_context *p = &ctx->p; struct xmp_mod_context *m = &p->m; int i, j, k, x, y; struct xxm_event *event; struct stat st; char smp_filename[PATH_MAX]; FILE *s; int size1, size2; int pat_addr, pat_table[128][4]; uint8 buf[1024], mod_event[4]; int row; LOAD_INIT(); sprintf(m->type, "Magnetic Fields Packer"); MODULE_INFO(); m->xxh->chn = 4; m->xxh->ins = m->xxh->smp = 31; INSTRUMENT_INIT(); reportv(ctx, 1, " Len LBeg LEnd L Vol Fin\n"); for (i = 0; i < 31; i++) { int loop_size; m->xxi[i] = calloc(sizeof(struct xxm_instrument), 1); m->xxs[i].len = 2 * read16b(f); m->xxi[i][0].fin = (int8)(read8(f) << 4); m->xxi[i][0].vol = read8(f); m->xxs[i].lps = 2 * read16b(f); loop_size = read16b(f); m->xxs[i].lpe = m->xxs[i].lps + 2 * loop_size; m->xxs[i].flg = loop_size > 1 ? WAVE_LOOPING : 0; m->xxi[i][0].pan = 0x80; m->xxi[i][0].sid = i; m->xxih[i].nsm = !!(m->xxs[i].len); m->xxih[i].rls = 0xfff; if (V(1) && m->xxs[i].len > 2) { report("[%2X] %04x %04x %04x %c V%02x %+d %c\n", i, m->xxs[i].len, m->xxs[i].lps, m->xxs[i].lpe, loop_size > 1 ? 'L' : ' ', m->xxi[i][0].vol, m->xxi[i][0].fin >> 4, m->xxs[i].flg & WAVE_PTKLOOP ? '!' : ' '); } }
static void get_info(struct module_data *m, int size, FILE *f, void *parm) { struct xmp_module *mod = &m->mod; mod->ins = read16b(f); mod->smp = read16b(f); read16b(f); /* Songs */ mod->pat = read16b(f); mod->chn = read16b(f); mod->trk = mod->pat * mod->chn; INSTRUMENT_INIT(); }
static void get_info(struct xmp_context *ctx, int size, FILE *f) { struct xmp_player_context *p = &ctx->p; struct xmp_mod_context *m = &p->m; m->xxh->ins = read16b(f); m->xxh->smp = read16b(f); read16b(f); /* Songs */ m->xxh->pat = read16b(f); m->xxh->chn = read16b(f); m->xxh->trk = m->xxh->pat * m->xxh->chn; INSTRUMENT_INIT(); }
static void get_plen(struct module_data *m, int size, xmp_file f, void *parm) { struct xmp_module *mod = &m->mod; mod->len = read16b(f); D_(D_INFO "Module length: %d", mod->len); }
static void get_slen(struct module_data *m, int size, xmp_file f, void *parm) { struct xmp_module *mod = &m->mod; mod->pat = read16b(f); mod->trk = mod->pat * mod->chn; }
static void get_spee(struct module_data *m, int size, xmp_file f, void *parm) { struct xmp_module *mod = &m->mod; mod->spd = read16b(f); mod->bpm = 125; }
static void get_emic(struct xmp_context *ctx, int size, FILE *f) { struct xmp_player_context *p = &ctx->p; struct xmp_mod_context *m = &p->m; int i, ver; ver = read16b(f); fread(m->name, 1, 20, f); fread(m->author, 1, 20, f); m->xxh->bpm = read8(f); m->xxh->ins = read8(f); m->xxh->smp = m->xxh->ins; m->xxh->flg |= XXM_FLG_MODRNG; snprintf(m->type, XMP_NAMESIZE, "EMOD v%d (Quadra Composer)", ver); MODULE_INFO(); INSTRUMENT_INIT(); reportv(ctx, 1, " Instrument name Len LBeg LEnd L Vol Fin\n"); for (i = 0; i < m->xxh->ins; i++) { m->xxi[i] = calloc(sizeof (struct xxm_instrument), 1); read8(f); /* num */ m->xxi[i][0].vol = read8(f); m->xxs[i].len = 2 * read16b(f); fread(m->xxih[i].name, 1, 20, f); m->xxs[i].flg = read8(f) & 1 ? WAVE_LOOPING : 0; m->xxi[i][0].fin = read8(f); m->xxs[i].lps = 2 * read16b(f); m->xxs[i].lpe = m->xxs[i].lps + 2 * read16b(f); read32b(f); /* ptr */ m->xxih[i].nsm = 1; m->xxi[i][0].pan = 0x80; m->xxi[i][0].sid = i; if (V(1) && (strlen((char *)m->xxih[i].name) || (m->xxs[i].len > 2))) { report ("[%2X] %-20.20s %05x %05x %05x %c V%02x %+d\n", i, m->xxih[i].name, m->xxs[i].len, m->xxs[i].lps, m->xxs[i].lpe, m->xxs[i].flg & WAVE_LOOPING ? 'L' : ' ', m->xxi[i][0].vol, m->xxi[i][0].fin >> 4); } }
static void get_plen(struct xmp_context *ctx, int size, FILE *f) { struct xmp_player_context *p = &ctx->p; struct xmp_mod_context *m = &p->m; m->xxh->len = read16b(f); reportv(ctx, 0, "Module length : %d patterns\n", m->xxh->len); }
static void get_slen(struct xmp_context *ctx, int size, FILE *f) { struct xmp_player_context *p = &ctx->p; struct xmp_mod_context *m = &p->m; m->xxh->pat = read16b(f); m->xxh->trk = m->xxh->pat * m->xxh->chn; }
static void get_spee(struct xmp_context *ctx, int size, FILE *f) { struct xmp_player_context *p = &ctx->p; struct xmp_mod_context *m = &p->m; m->xxh->tpo = read16b(f); m->xxh->bpm = 125; }
static int depack_mp(FILE *in, FILE *out) { uint8 c1; uint8 ptable[128]; uint8 max; int i; int size, ssize = 0; memset(ptable, 0, 128); pw_write_zero(out, 20); /* title */ if (read32b(in) != MAGIC_TRK1) /* TRK1 */ fseek(in, -4, SEEK_CUR); for (i = 0; i < 31; i++) { pw_write_zero(out, 22); /* sample name */ write16b(out, size = read16b(in)); /* size */ ssize += size * 2; write8(out, read8(in)); /* finetune */ write8(out, read8(in)); /* volume */ write16b(out, read16b(in)); /* loop start */ write16b(out, read16b(in)); /* loop size */ } write8(out, read8(in)); /* pattern table length */ write8(out, read8(in)); /* NoiseTracker restart byte */ for (max = i = 0; i < 128; i++) { write8(out, c1 = read8(in)); if (c1 > max) max = c1; } max++; write32b(out, PW_MOD_MAGIC); /* M.K. */ if (read32b(in) != 0) /* bypass unknown empty bytes */ fseek (in, -4, SEEK_CUR); pw_move_data(out, in, 1024 * max); /* pattern data */ pw_move_data(out, in, ssize); /* sample data */ return 0; }
static void get_inst(struct xmp_context *ctx, int size, FILE *f) { struct xmp_player_context *p = &ctx->p; struct xmp_mod_context *m = &p->m; int i; int c2spd, flags, snum; uint8 buffer[50]; reportv(ctx, 0, "Instruments : %d ", m->xxh->ins); reportv(ctx, 1, "\n Instrument name Smp Vol Pan C2Spd"); for (i = 0; i < m->xxh->ins; i++) { m->xxi[i] = calloc(sizeof(struct xxm_instrument), 1); m->xxih[i].nsm = 1; fread(buffer, 30, 1, f); copy_adjust(m->xxih[i].name, buffer, 30); snum = read16b(f); if (snum == 0 || snum > m->xxh->smp) continue; m->xxi[i][0].sid = --snum; m->xxi[i][0].vol = read16b(f); c2spd = read32b(f); m->xxs[snum].lps = read32b(f); m->xxs[snum].lpe = m->xxs[i].lps + read32b(f); m->xxi[i][0].pan = 0x80 + (int16)read16b(f); if (m->xxi[i][0].pan > 0xff) m->xxi[i][0].pan = 0xff; flags = read16b(f); m->xxs[snum].flg = flags & 0x03 ? WAVE_LOOPING : 0; m->xxs[snum].flg |= flags & 0x02 ? WAVE_BIDIR_LOOP : 0; c2spd_to_note(c2spd, &m->xxi[i][0].xpo, &m->xxi[i][0].fin); reportv(ctx, 1, "\n[%2X] %-30.30s #%02X V%02x P%02x %5d ", i, m->xxih[i].name, snum, m->xxi[i][0].vol, m->xxi[i][0].pan, c2spd); reportv(ctx, 0, "."); } reportv(ctx, 0, "\n"); }
static void get_samp(struct xmp_context *ctx, int size, FILE *f) { struct xmp_player_context *p = &ctx->p; struct xmp_mod_context *m = &p->m; int i, j; int looplen; /* Should be always 36 */ m->xxh->ins = size / 32; /* sizeof(struct okt_instrument_header); */ m->xxh->smp = m->xxh->ins; INSTRUMENT_INIT(); reportv(ctx, 1, " Instrument name Len Lbeg Lend L Vol Mod\n"); for (j = i = 0; i < m->xxh->ins; i++) { m->xxi[i] = calloc(sizeof (struct xxm_instrument), 1); fread(m->xxih[i].name, 1, 20, f); str_adj((char *)m->xxih[i].name); /* Sample size is always rounded down */ m->xxs[i].len = read32b(f) & ~1; m->xxs[i].lps = read16b(f); looplen = read16b(f); m->xxs[i].lpe = m->xxs[i].lps + looplen; m->xxi[i][0].vol = read16b(f); mode[i] = read16b(f); m->xxih[i].nsm = !!(m->xxs[i].len); m->xxs[i].flg = looplen > 2 ? WAVE_LOOPING : 0; m->xxi[i][0].pan = 0x80; m->xxi[i][0].sid = j; idx[j] = i; if ((V(1)) && (strlen((char *)m->xxih[i].name) || (m->xxs[i].len > 1))) report ("[%2X] %-20.20s %05x %05x %05x %c V%02x M%02x\n", i, m->xxih[i].name, m->xxs[i].len, m->xxs[i].lps, m->xxs[i].lpe, m->xxs[i].flg & WAVE_LOOPING ? 'L' : ' ', m->xxi[i][0].vol, mode[i]); if (m->xxih[i].nsm) j++; } }
static void get_samp(struct module_data *m, int size, xmp_file f, void *parm) { struct xmp_module *mod = &m->mod; struct local_data *data = (struct local_data *)parm; int i, j; int looplen; /* Should be always 36 */ mod->ins = size / 32; /* sizeof(struct okt_instrument_header); */ mod->smp = mod->ins; INSTRUMENT_INIT(); for (j = i = 0; i < mod->ins; i++) { mod->xxi[i].sub = calloc(sizeof (struct xmp_subinstrument), 1); xmp_fread(mod->xxi[i].name, 1, 20, f); str_adj((char *)mod->xxi[i].name); /* Sample size is always rounded down */ mod->xxs[i].len = read32b(f) & ~1; mod->xxs[i].lps = read16b(f); looplen = read16b(f); mod->xxs[i].lpe = mod->xxs[i].lps + looplen; mod->xxi[i].sub[0].vol = read16b(f); data->mode[i] = read16b(f); mod->xxi[i].nsm = !!(mod->xxs[i].len); mod->xxs[i].flg = looplen > 2 ? XMP_SAMPLE_LOOP : 0; mod->xxi[i].sub[0].pan = 0x80; mod->xxi[i].sub[0].sid = j; data->idx[j] = i; D_(D_INFO "[%2X] %-20.20s %05x %05x %05x %c V%02x M%02x\n", i, mod->xxi[i].name, mod->xxs[i].len, mod->xxs[i].lps, mod->xxs[i].lpe, mod->xxs[i].flg & XMP_SAMPLE_LOOP ? 'L' : ' ', mod->xxi[i].sub[0].vol, data->mode[i]); if (mod->xxi[i].nsm) j++; } }
uint16 hio_read16b(HIO_HANDLE *h) { switch (HIO_HANDLE_TYPE(h)) { case HIO_HANDLE_TYPE_FILE: return read16b(h->handle.file); case HIO_HANDLE_TYPE_MEMORY: return mread16b(h->handle.mem); default: return 0; } }
static void get_song(struct module_data *m, int size, FILE *f, void *parm) { struct xmp_module *mod = &m->mod; struct local_data *data = (struct local_data *)parm; int i; char buffer[50]; if (data->have_song) return; data->have_song = 1; fread(buffer, 44, 1, f); D_(D_INFO "Song name: %s", buffer); mod->len = read16b(f); D_(D_INFO "Song length: %d patterns", mod->len); for (i = 0; i < mod->len; i++) mod->xxo[i] = read16b(f); }
static void get_song(struct xmp_context *ctx, int size, FILE *f) { struct xmp_player_context *p = &ctx->p; struct xmp_mod_context *m = &p->m; int i; char buffer[50]; if (have_song) return; have_song = 1; fread(buffer, 44, 1, f); if (V(0) && *buffer) report("Song name : %s\n", buffer); m->xxh->len = read16b(f); reportv(ctx, 0, "Song length : %d patterns\n", m->xxh->len); for (i = 0; i < m->xxh->len; i++) m->xxo[i] = read16b(f); }
static void get_cmod(struct module_data *m, int size, xmp_file f, void *parm) { struct xmp_module *mod = &m->mod; int i, j, k; mod->chn = 0; for (i = 0; i < 4; i++) { j = read16b(f); for (k = !!j; k >= 0; k--) { mod->xxc[mod->chn].pan = (((i + 1) / 2) % 2) * 0xff; mod->chn++; } } }
static void get_inst(struct module_data *m, int size, FILE *f, void *parm) { struct xmp_module *mod = &m->mod; int i; int c2spd, flags, snum; uint8 buffer[50]; D_(D_INFO "Instruments: %d", mod->ins); for (i = 0; i < mod->ins; i++) { mod->xxi[i].sub = calloc(sizeof (struct xmp_subinstrument), 1); mod->xxi[i].nsm = 1; fread(buffer, 30, 1, f); copy_adjust(mod->xxi[i].name, buffer, 30); snum = read16b(f); if (snum == 0 || snum > mod->smp) continue; mod->xxi[i].sub[0].sid = --snum; mod->xxi[i].sub[0].vol = read16b(f); c2spd = read32b(f); mod->xxs[snum].lps = read32b(f); mod->xxs[snum].lpe = mod->xxs[i].lps + read32b(f); mod->xxi[i].sub[0].pan = 0x80 + (int16)read16b(f); if (mod->xxi[i].sub[0].pan > 0xff) mod->xxi[i].sub[0].pan = 0xff; flags = read16b(f); mod->xxs[snum].flg = flags & 0x03 ? XMP_SAMPLE_LOOP : 0; mod->xxs[snum].flg |= flags & 0x02 ? XMP_SAMPLE_LOOP_BIDIR : 0; c2spd_to_note(c2spd, &mod->xxi[i].sub[0].xpo, &mod->xxi[i].sub[0].fin); D_(D_INFO "[%2X] %-30.30s #%02X V%02x P%02x %5d", i, mod->xxi[i].name, snum, mod->xxi[i].sub[0].vol, mod->xxi[i].sub[0].pan, c2spd); } }
static void get_cmod(struct xmp_context *ctx, int size, FILE *f) { struct xmp_player_context *p = &ctx->p; struct xmp_mod_context *m = &p->m; int i, j, k; m->xxh->chn = 0; for (i = 0; i < 4; i++) { j = read16b(f); for (k = !!j; k >= 0; k--) { m->xxc[m->xxh->chn].pan = (((i + 1) / 2) % 2) * 0xff; m->xxh->chn++; } } }
static int dbm_load(struct module_data *m, FILE *f, const int start) { struct xmp_module *mod = &m->mod; iff_handle handle; char name[44]; uint16 version; int i; struct local_data data; LOAD_INIT(); read32b(f); /* DBM0 */ data.have_song = 0; version = read16b(f); fseek(f, 10, SEEK_CUR); fread(name, 1, 44, f); handle = iff_new(); if (handle == NULL) return -1; /* IFF chunk IDs */ iff_register(handle, "INFO", get_info); iff_register(handle, "SONG", get_song); iff_register(handle, "INST", get_inst); iff_register(handle, "PATT", get_patt); iff_register(handle, "SMPL", get_smpl); iff_register(handle, "VENV", get_venv); strncpy(mod->name, name, XMP_NAME_SIZE); snprintf(mod->type, XMP_NAME_SIZE, "DigiBooster Pro %d.%02x DBM0", version >> 8, version & 0xff); MODULE_INFO(); /* Load IFF chunks */ while (!feof(f)) { iff_chunk(handle, m, f, &data); } iff_release(handle); for (i = 0; i < mod->chn; i++) mod->xxc[i].pan = 0x80; return 0; }
uint16 hio_read16b(HIO_HANDLE *h) { if (HIO_HANDLE_TYPE(h) == HIO_HANDLE_TYPE_FILE) { return read16b(h->f); } else { ptrdiff_t can_read = CAN_READ(h); if (can_read >= 2) { uint16 n = readmem16b(h->start + h->pos); h->pos += 2; return n; } else { h->pos += can_read; return EOF; } } }
static int ssn_test(FILE *f, char *t, const int start) { uint16 id; id = read16b(f); if (id != 0x6966 && id != 0x4a4e) return -1; fseek(f, 238, SEEK_CUR); if (read8(f) != 0xff) return -1; fseek(f, 2, SEEK_CUR); read_title(f, t, 36); return 0; }
static int mdl_test(FILE *f, char *t, const int start) { uint16 id; if (read32b(f) != MAGIC_DMDL) return -1; read8(f); /* version */ id = read16b(f); if (id == 0x494e) { /* IN */ read32b(f); read_title(f, t, 32); } else { read_title(f, t, 0); } return 0; }
static int dbm_load(struct xmp_context *ctx, FILE *f, const int start) { struct xmp_player_context *p = &ctx->p; struct xmp_mod_context *m = &p->m; char name[44]; uint16 version; int i; LOAD_INIT(); read32b(f); /* DBM0 */ have_song = 0; version = read16b(f); fseek(f, 10, SEEK_CUR); fread(name, 1, 44, f); /* IFF chunk IDs */ iff_register("INFO", get_info); iff_register("SONG", get_song); iff_register("INST", get_inst); iff_register("PATT", get_patt); iff_register("SMPL", get_smpl); iff_register("VENV", get_venv); strncpy(m->name, name, XMP_NAMESIZE); snprintf(m->type, XMP_NAMESIZE, "DBM0 (DigiBooster Pro " "%d.%02x)", version >> 8, version & 0xff); MODULE_INFO(); /* Load IFF chunks */ while (!feof(f)) iff_chunk(ctx, f); iff_release(); for (i = 0; i < m->xxh->chn; i++) m->xxc[i].pan = 0x80; return 0; }
static int emod_test(xmp_file f, char *t, const int start) { if (read32b(f) != MAGIC_FORM) return -1; read32b(f); if (read32b(f) != MAGIC_EMOD) return -1; if (read32b(f) == MAGIC_EMIC) { read32b(f); /* skip size */ read16b(f); /* skip version */ read_title(f, t, 20); } else { read_title(f, t, 0); } return 0; }