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_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 int gtk_load(struct module_data *m, HIO_HANDLE *f, const int start) { struct xmp_module *mod = &m->mod; struct xmp_event *event; int i, j, k; uint8 buffer[40]; int rows, bits, c2spd, size; int ver, patmax; LOAD_INIT(); hio_read(buffer, 4, 1, f); ver = buffer[3]; hio_read(mod->name, 32, 1, f); set_type(m, "Graoumf Tracker GTK v%d", ver); hio_seek(f, 160, SEEK_CUR); /* skip comments */ mod->ins = hio_read16b(f); mod->smp = mod->ins; rows = hio_read16b(f); mod->chn = hio_read16b(f); mod->len = hio_read16b(f); mod->rst = hio_read16b(f); m->volbase = 0x100; MODULE_INFO(); D_(D_INFO "Instruments : %d ", mod->ins); if (instrument_init(mod) < 0) return -1; for (i = 0; i < mod->ins; i++) { if (subinstrument_alloc(mod, i, 1) < 0) return -1; hio_read(buffer, 28, 1, f); instrument_name(mod, i, buffer, 28); if (ver == 1) { hio_read32b(f); mod->xxs[i].len = hio_read32b(f); mod->xxs[i].lps = hio_read32b(f); size = hio_read32b(f); mod->xxs[i].lpe = mod->xxs[i].lps + size - 1; hio_read16b(f); hio_read16b(f); mod->xxi[i].sub[0].vol = 0xff; mod->xxi[i].sub[0].pan = 0x80; bits = 1; c2spd = 8363; } else { hio_seek(f, 14, SEEK_CUR); hio_read16b(f); /* autobal */ bits = hio_read16b(f); /* 1 = 8 bits, 2 = 16 bits */ c2spd = hio_read16b(f); c2spd_to_note(c2spd, &mod->xxi[i].sub[0].xpo, &mod->xxi[i].sub[0].fin); mod->xxs[i].len = hio_read32b(f); mod->xxs[i].lps = hio_read32b(f); size = hio_read32b(f); mod->xxs[i].lpe = mod->xxs[i].lps + size - 1; mod->xxi[i].sub[0].vol = hio_read16b(f); hio_read8(f); mod->xxi[i].sub[0].fin = hio_read8s(f); } if (mod->xxs[i].len > 0) mod->xxi[i].nsm = 1; mod->xxi[i].sub[0].sid = i; mod->xxs[i].flg = size > 2 ? XMP_SAMPLE_LOOP : 0; if (bits > 1) { mod->xxs[i].flg |= XMP_SAMPLE_16BIT; mod->xxs[i].len >>= 1; mod->xxs[i].lps >>= 1; mod->xxs[i].lpe >>= 1; } D_(D_INFO "[%2X] %-28.28s %05x%c%05x %05x %c " "V%02x F%+03d %5d", i, mod->xxi[i].name, mod->xxs[i].len, bits > 1 ? '+' : ' ', mod->xxs[i].lps, size, mod->xxs[i].flg & XMP_SAMPLE_LOOP ? 'L' : ' ', mod->xxi[i].sub[0].vol, mod->xxi[i].sub[0].fin, c2spd); }
static int get_inst(struct module_data *m, int size, HIO_HANDLE *f, void *parm) { struct xmp_module *mod = &m->mod; int i, c2spd; uint8 name[30]; mod->ins = mod->smp = hio_read16b(f); D_(D_INFO "Instruments : %d ", mod->ins); if (instrument_init(mod) < 0) return -1; for (i = 0; i < mod->ins; i++) { int fine, replen, flag; if (subinstrument_alloc(mod, i, 1) < 0) return -1; hio_read32b(f); /* reserved */ mod->xxs[i].len = hio_read32b(f); mod->xxi[i].nsm = !!mod->xxs[i].len; fine = hio_read8s(f); /* finetune */ mod->xxi[i].sub[0].vol = hio_read8(f); mod->xxi[i].sub[0].pan = 0x80; mod->xxs[i].lps = hio_read32b(f); replen = hio_read32b(f); mod->xxs[i].lpe = mod->xxs[i].lps + replen - 1; mod->xxs[i].flg = replen > 2 ? XMP_SAMPLE_LOOP : 0; hio_read(name, 22, 1, f); instrument_name(mod, i, name, 22); flag = hio_read16b(f); /* bit 0-7:resol 8:stereo */ if ((flag & 0xff) > 8) { mod->xxs[i].flg |= XMP_SAMPLE_16BIT; mod->xxs[i].len >>= 1; mod->xxs[i].lps >>= 1; mod->xxs[i].lpe >>= 1; } hio_read32b(f); /* midi note (0x00300000) */ c2spd = hio_read32b(f); /* frequency */ c2spd_to_note(c2spd, &mod->xxi[i].sub[0].xpo, &mod->xxi[i].sub[0].fin); /* It's strange that we have both c2spd and finetune */ mod->xxi[i].sub[0].fin += fine; mod->xxi[i].sub[0].sid = i; D_(D_INFO "[%2X] %-22.22s %05x%c%05x %05x %c%c %2db V%02x F%+03d %5d", i, mod->xxi[i].name, mod->xxs[i].len, mod->xxs[i].flg & XMP_SAMPLE_16BIT ? '+' : ' ', mod->xxs[i].lps, replen, mod->xxs[i].flg & XMP_SAMPLE_LOOP ? 'L' : ' ', flag & 0x100 ? 'S' : ' ', flag & 0xff, mod->xxi[i].sub[0].vol, fine, c2spd); }
static int no_load(struct module_data *m, HIO_HANDLE *f, const int start) { struct xmp_module *mod = &m->mod; struct xmp_event *event; int i, j, k; int nsize; LOAD_INIT(); hio_read32b(f); /* NO 0x00 0x00 */ set_type(m, "Liquid Tracker"); nsize = hio_read8(f); for (i = 0; i < nsize; i++) { uint8 x = hio_read8(f); if (i < XMP_NAME_SIZE) mod->name[i] = x; } hio_read16l(f); hio_read16l(f); hio_read16l(f); hio_read16l(f); hio_read8(f); mod->pat = hio_read8(f); hio_read8(f); mod->chn = hio_read8(f); mod->trk = mod->pat * mod->chn; hio_read8(f); hio_read16l(f); hio_read16l(f); hio_read8(f); mod->ins = mod->smp = 63; for (i = 0; i < 256; i++) { uint8 x = hio_read8(f); if (x == 0xff) break; mod->xxo[i] = x; } hio_seek(f, 255 - i, SEEK_CUR); mod->len = i; MODULE_INFO(); if (instrument_init(mod) < 0) return -1; /* Read instrument names */ for (i = 0; i < mod->ins; i++) { int hasname, c2spd; if (subinstrument_alloc(mod, i, 1) < 0) return -1; nsize = hio_read8(f); hasname = 0; for (j = 0; j < nsize; j++) { uint8 x = hio_read8(f); if (x != 0x20) hasname = 1; if (j < 32) mod->xxi[i].name[j] = x; } if (!hasname) mod->xxi[i].name[0] = 0; hio_read32l(f); hio_read32l(f); mod->xxi[i].sub[0].vol = hio_read8(f); c2spd = hio_read16l(f); mod->xxs[i].len = hio_read16l(f); mod->xxs[i].lps = hio_read16l(f); mod->xxs[i].lpe = hio_read16l(f); hio_read32l(f); hio_read16l(f); if (mod->xxs[i].len > 0) mod->xxi[i].nsm = 1; /* mod->xxs[i].lps = 0; mod->xxs[i].lpe = 0; */ mod->xxs[i].flg = mod->xxs[i].lpe > 0 ? XMP_SAMPLE_LOOP : 0; mod->xxi[i].sub[0].fin = 0; mod->xxi[i].sub[0].pan = 0x80; mod->xxi[i].sub[0].sid = i; D_(D_INFO "[%2X] %-22.22s %04x %04x %04x %c V%02x %5d", 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, c2spd); c2spd = 8363 * c2spd / 8448; c2spd_to_note(c2spd, &mod->xxi[i].sub[0].xpo, &mod->xxi[i].sub[0].fin); } if (pattern_init(mod) < 0) return -1; /* Read and convert patterns */ D_(D_INFO "Stored patterns: %d ", mod->pat); for (i = 0; i < mod->pat; i++) { if (pattern_tracks_alloc(mod, i, 64) < 0) return -1; for (j = 0; j < mod->xxp[i]->rows; j++) { for (k = 0; k < mod->chn; k++) { uint32 x, note, ins, vol, fxt, fxp; event = &EVENT (i, k, j); x = hio_read32l(f); note = x & 0x0000003f; ins = (x & 0x00001fc0) >> 6; vol = (x & 0x000fe000) >> 13; fxt = (x & 0x00f00000) >> 20; fxp = (x & 0xff000000) >> 24; if (note != 0x3f) event->note = 36 + note; if (ins != 0x7f) event->ins = 1 + ins; if (vol != 0x7f) event->vol = vol; if (fxt != 0x0f) { event->fxt = fx[fxt]; event->fxp = fxp; } } } } /* Read samples */ D_(D_INFO "Stored samples: %d", mod->smp); for (i = 0; i < mod->ins; i++) { if (mod->xxs[i].len == 0) continue; if (load_sample(m, f, SAMPLE_FLAG_UNS, &mod->xxs[i], NULL) < 0) return -1; } m->quirk |= QUIRKS_ST3; m->read_event_type = READ_EVENT_ST3; return 0; }
static int get_inst(struct module_data *m, int size, HIO_HANDLE *f, void *parm) { struct xmp_module *mod = &m->mod; struct local_data *data = (struct local_data *)parm; int i, j; int srate, finetune, flags; int val, vwf, vra, vde, vsw, fade; uint8 buf[30]; hio_read8(f); /* 00 */ i = hio_read8(f); /* instrument number */ hio_read(&mod->xxi[i].name, 1, 28, f); adjust_string((char *)mod->xxi[i].name); mod->xxi[i].nsm = hio_read8(f); for (j = 0; j < 108; j++) { mod->xxi[i].map[j].ins = hio_read8(f); } hio_seek(f, 11, SEEK_CUR); /* unknown */ vwf = hio_read8(f); /* vibrato waveform */ vsw = hio_read8(f); /* vibrato sweep */ hio_read8(f); /* unknown */ hio_read8(f); /* unknown */ vde = hio_read8(f); /* vibrato depth */ vra = hio_read16l(f) / 16; /* vibrato speed */ hio_read8(f); /* unknown */ val = hio_read8(f); /* PV envelopes flags */ if (LSN(val) & 0x01) mod->xxi[i].aei.flg |= XMP_ENVELOPE_ON; if (LSN(val) & 0x02) mod->xxi[i].aei.flg |= XMP_ENVELOPE_SUS; if (LSN(val) & 0x04) mod->xxi[i].aei.flg |= XMP_ENVELOPE_LOOP; if (MSN(val) & 0x01) mod->xxi[i].pei.flg |= XMP_ENVELOPE_ON; if (MSN(val) & 0x02) mod->xxi[i].pei.flg |= XMP_ENVELOPE_SUS; if (MSN(val) & 0x04) mod->xxi[i].pei.flg |= XMP_ENVELOPE_LOOP; val = hio_read8(f); /* PV envelopes points */ mod->xxi[i].aei.npt = LSN(val) + 1; mod->xxi[i].pei.npt = MSN(val) + 1; val = hio_read8(f); /* PV envelopes sustain point */ mod->xxi[i].aei.sus = LSN(val); mod->xxi[i].pei.sus = MSN(val); val = hio_read8(f); /* PV envelopes loop start */ mod->xxi[i].aei.lps = LSN(val); mod->xxi[i].pei.lps = MSN(val); hio_read8(f); /* PV envelopes loop end */ mod->xxi[i].aei.lpe = LSN(val); mod->xxi[i].pei.lpe = MSN(val); if (mod->xxi[i].aei.npt <= 0 || mod->xxi[i].aei.npt >= XMP_MAX_ENV_POINTS) mod->xxi[i].aei.flg &= ~XMP_ENVELOPE_ON; if (mod->xxi[i].pei.npt <= 0 || mod->xxi[i].pei.npt >= XMP_MAX_ENV_POINTS) mod->xxi[i].pei.flg &= ~XMP_ENVELOPE_ON; hio_read(buf, 1, 30, f); /* volume envelope points */; for (j = 0; j < mod->xxi[i].aei.npt; j++) { mod->xxi[i].aei.data[j * 2] = readmem16l(buf + j * 3) / 16; mod->xxi[i].aei.data[j * 2 + 1] = buf[j * 3 + 2]; } hio_read(buf, 1, 30, f); /* pan envelope points */; for (j = 0; j < mod->xxi[i].pei.npt; j++) { mod->xxi[i].pei.data[j * 2] = readmem16l(buf + j * 3) / 16; mod->xxi[i].pei.data[j * 2 + 1] = buf[j * 3 + 2]; } fade = hio_read8(f); /* fadeout - 0x80->0x02 0x310->0x0c */ hio_read8(f); /* unknown */ D_(D_INFO "[%2X] %-28.28s %2d ", i, mod->xxi[i].name, mod->xxi[i].nsm); if (mod->xxi[i].nsm == 0) return 0; if (subinstrument_alloc(mod, i, mod->xxi[i].nsm) < 0) return -1; for (j = 0; j < mod->xxi[i].nsm; j++, data->snum++) { hio_read32b(f); /* SAMP */ hio_read32b(f); /* size */ hio_read(&mod->xxs[data->snum].name, 1, 28, f); adjust_string((char *)mod->xxs[data->snum].name); mod->xxi[i].sub[j].pan = hio_read8(f) * 4; if (mod->xxi[i].sub[j].pan == 0) /* not sure about this */ mod->xxi[i].sub[j].pan = 0x80; mod->xxi[i].sub[j].vol = hio_read8(f); flags = hio_read8(f); hio_read8(f); /* unknown - 0x80 */ mod->xxi[i].sub[j].vwf = vwf; mod->xxi[i].sub[j].vde = vde; mod->xxi[i].sub[j].vra = vra; mod->xxi[i].sub[j].vsw = vsw; mod->xxi[i].sub[j].sid = data->snum; mod->xxs[data->snum].len = hio_read32l(f); mod->xxs[data->snum].lps = hio_read32l(f); mod->xxs[data->snum].lpe = hio_read32l(f); mod->xxs[data->snum].flg = 0; if (flags & 0x04) mod->xxs[data->snum].flg |= XMP_SAMPLE_16BIT; if (flags & 0x08) mod->xxs[data->snum].flg |= XMP_SAMPLE_LOOP; if (flags & 0x10) mod->xxs[data->snum].flg |= XMP_SAMPLE_LOOP_BIDIR; /* if (flags & 0x80) mod->xxs[data->snum].flg |= ? */ srate = hio_read32l(f); finetune = 0; c2spd_to_note(srate, &mod->xxi[i].sub[j].xpo, &mod->xxi[i].sub[j].fin); mod->xxi[i].sub[j].fin += finetune; hio_read32l(f); /* 0x00000000 */ hio_read32l(f); /* unknown */ D_(D_INFO " %X: %05x%c%05x %05x %c V%02x P%02x %5d", j, mod->xxs[data->snum].len, mod->xxs[data->snum].flg & XMP_SAMPLE_16BIT ? '+' : ' ', mod->xxs[data->snum].lps, mod->xxs[data->snum].lpe, mod->xxs[data->snum].flg & XMP_SAMPLE_LOOP_BIDIR ? 'B' : mod->xxs[data->snum].flg & XMP_SAMPLE_LOOP ? 'L' : ' ', mod->xxi[i].sub[j].vol, mod->xxi[i].sub[j].pan, srate); if (mod->xxs[data->snum].len > 1) { int snum = data->snum; if (load_sample(m, f, 0, &mod->xxs[snum], NULL) < 0) return -1; } } return 0; }
static int mgt_load(struct module_data *m, HIO_HANDLE *f, const int start) { struct xmp_module *mod = &m->mod; struct xmp_event *event; int i, j; int ver; int sng_ptr, seq_ptr, ins_ptr, pat_ptr, trk_ptr, smp_ptr; int sdata[64]; LOAD_INIT(); hio_read24b(f); /* MGT */ ver = hio_read8(f); hio_read32b(f); /* MCS */ set_type(m, "Megatracker MGT v%d.%d", MSN(ver), LSN(ver)); mod->chn = hio_read16b(f); hio_read16b(f); /* number of songs */ mod->len = hio_read16b(f); mod->pat = hio_read16b(f); mod->trk = hio_read16b(f); mod->ins = mod->smp = hio_read16b(f); hio_read16b(f); /* reserved */ hio_read32b(f); /* reserved */ sng_ptr = hio_read32b(f); seq_ptr = hio_read32b(f); ins_ptr = hio_read32b(f); pat_ptr = hio_read32b(f); trk_ptr = hio_read32b(f); smp_ptr = hio_read32b(f); hio_read32b(f); /* total smp len */ hio_read32b(f); /* unpacked trk size */ hio_seek(f, start + sng_ptr, SEEK_SET); hio_read(mod->name, 1, 32, f); seq_ptr = hio_read32b(f); mod->len = hio_read16b(f); mod->rst = hio_read16b(f); mod->bpm = hio_read8(f); mod->spd = hio_read8(f); hio_read16b(f); /* global volume */ hio_read8(f); /* master L */ hio_read8(f); /* master R */ for (i = 0; i < mod->chn; i++) { hio_read16b(f); /* pan */ } MODULE_INFO(); /* Sequence */ hio_seek(f, start + seq_ptr, SEEK_SET); for (i = 0; i < mod->len; i++) mod->xxo[i] = hio_read16b(f); /* Instruments */ if (instrument_init(mod) < 0) return -1; hio_seek(f, start + ins_ptr, SEEK_SET); for (i = 0; i < mod->ins; i++) { int c2spd, flags; if (subinstrument_alloc(mod, i , 1) < 0) return -1; hio_read(mod->xxi[i].name, 1, 32, f); sdata[i] = hio_read32b(f); mod->xxs[i].len = hio_read32b(f); mod->xxs[i].lps = hio_read32b(f); mod->xxs[i].lpe = mod->xxs[i].lps + hio_read32b(f); hio_read32b(f); hio_read32b(f); c2spd = hio_read32b(f); c2spd_to_note(c2spd, &mod->xxi[i].sub[0].xpo, &mod->xxi[i].sub[0].fin); mod->xxi[i].sub[0].vol = hio_read16b(f) >> 4; hio_read8(f); /* vol L */ hio_read8(f); /* vol R */ mod->xxi[i].sub[0].pan = 0x80; flags = hio_read8(f); mod->xxs[i].flg = flags & 0x03 ? XMP_SAMPLE_LOOP : 0; mod->xxs[i].flg |= flags & 0x02 ? XMP_SAMPLE_LOOP_BIDIR : 0; mod->xxi[i].sub[0].fin += 0 * hio_read8(f); // FIXME hio_read8(f); /* unused */ hio_read8(f); hio_read8(f); hio_read8(f); hio_read16b(f); hio_read32b(f); hio_read32b(f); mod->xxi[i].nsm = !!mod->xxs[i].len; mod->xxi[i].sub[0].sid = i; D_(D_INFO "[%2X] %-32.32s %04x %04x %04x %c V%02x %5d\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_BIDIR ? 'B' : mod->xxs[i].flg & XMP_SAMPLE_LOOP ? 'L' : ' ', mod->xxi[i].sub[0].vol, c2spd); } /* PATTERN_INIT - alloc extra track*/ if (pattern_init(mod) < 0) return -1; D_(D_INFO "Stored tracks: %d", mod->trk); /* Tracks */ for (i = 1; i < mod->trk; i++) { int offset, rows; uint8 b; hio_seek(f, start + trk_ptr + i * 4, SEEK_SET); offset = hio_read32b(f); hio_seek(f, start + offset, SEEK_SET); rows = hio_read16b(f); if (track_alloc(mod, i, rows) < 0) return -1; //printf("\n=== Track %d ===\n\n", i); for (j = 0; j < rows; j++) { uint8 note, f2p; b = hio_read8(f); j += b & 0x03; note = 0; event = &mod->xxt[i]->event[j]; if (b & 0x04) note = hio_read8(f); if (b & 0x08) event->ins = hio_read8(f); if (b & 0x10) event->vol = hio_read8(f); if (b & 0x20) event->fxt = hio_read8(f); if (b & 0x40) event->fxp = hio_read8(f); if (b & 0x80) f2p = hio_read8(f); if (note == 1) event->note = XMP_KEY_OFF; else if (note > 11) /* adjusted to play codeine.mgt */ event->note = note + 1; /* effects */ if (event->fxt < 0x10) /* like amiga */ ; else switch (event->fxt) { case 0x13: case 0x14: case 0x15: case 0x17: case 0x1c: case 0x1d: case 0x1e: event->fxt = FX_EXTENDED; event->fxp = ((event->fxt & 0x0f) << 4) | (event->fxp & 0x0f); break; default: event->fxt = event->fxp = 0; } /* volume and volume column effects */ if ((event->vol >= 0x10) && (event->vol <= 0x50)) { event->vol -= 0x0f; continue; } switch (event->vol >> 4) { case 0x06: /* Volume slide down */ event->f2t = FX_VOLSLIDE_2; event->f2p = event->vol - 0x60; break; case 0x07: /* Volume slide up */ event->f2t = FX_VOLSLIDE_2; event->f2p = (event->vol - 0x70) << 4; break; case 0x08: /* Fine volume slide down */ event->f2t = FX_EXTENDED; event->f2p = (EX_F_VSLIDE_DN << 4) | (event->vol - 0x80); break; case 0x09: /* Fine volume slide up */ event->f2t = FX_EXTENDED; event->f2p = (EX_F_VSLIDE_UP << 4) | (event->vol - 0x90); break; case 0x0a: /* Set vibrato speed */ event->f2t = FX_VIBRATO; event->f2p = (event->vol - 0xa0) << 4; break; case 0x0b: /* Vibrato */ event->f2t = FX_VIBRATO; event->f2p = event->vol - 0xb0; break; case 0x0c: /* Set panning */ event->f2t = FX_SETPAN; event->f2p = ((event->vol - 0xc0) << 4) + 8; break; case 0x0d: /* Pan slide left */ event->f2t = FX_PANSLIDE; event->f2p = (event->vol - 0xd0) << 4; break; case 0x0e: /* Pan slide right */ event->f2t = FX_PANSLIDE; event->f2p = event->vol - 0xe0; break; case 0x0f: /* Tone portamento */ event->f2t = FX_TONEPORTA; event->f2p = (event->vol - 0xf0) << 4; break; } event->vol = 0; /*printf("%02x %02x %02x %02x %02x %02x\n", j, event->note, event->ins, event->vol, event->fxt, event->fxp);*/ } } /* Extra track */ mod->xxt[0] = calloc(sizeof(struct xmp_track) + sizeof(struct xmp_event) * 64 - 1, 1); mod->xxt[0]->rows = 64; /* Read and convert patterns */ D_(D_INFO "Stored patterns: %d", mod->pat); hio_seek(f, start + pat_ptr, SEEK_SET); for (i = 0; i < mod->pat; i++) { if (pattern_alloc(mod, i) < 0) return -1; mod->xxp[i]->rows = hio_read16b(f); for (j = 0; j < mod->chn; j++) { mod->xxp[i]->index[j] = hio_read16b(f) - 1; } } /* Read samples */ D_(D_INFO "Stored samples: %d", mod->smp); for (i = 0; i < mod->ins; i++) { if (mod->xxi[i].nsm == 0) continue; hio_seek(f, start + sdata[i], SEEK_SET); if (load_sample(m, f, 0, &mod->xxs[i], NULL) < 0) return -1; } return 0; }
static int ptm_load(struct module_data *m, HIO_HANDLE *f, const int start) { struct xmp_module *mod = &m->mod; int c, r, i, smp_ofs[256]; struct xmp_event *event; struct ptm_file_header pfh; struct ptm_instrument_header pih; uint8 n, b; LOAD_INIT(); /* Load and convert header */ hio_read(&pfh.name, 28, 1, f); /* Song name */ pfh.doseof = hio_read8(f); /* 0x1a */ pfh.vermin = hio_read8(f); /* Minor version */ pfh.vermaj = hio_read8(f); /* Major type */ pfh.rsvd1 = hio_read8(f); /* Reserved */ pfh.ordnum = hio_read16l(f); /* Number of orders (must be even) */ pfh.insnum = hio_read16l(f); /* Number of instruments */ pfh.patnum = hio_read16l(f); /* Number of patterns */ pfh.chnnum = hio_read16l(f); /* Number of channels */ pfh.flags = hio_read16l(f); /* Flags (set to 0) */ pfh.rsvd2 = hio_read16l(f); /* Reserved */ pfh.magic = hio_read32b(f); /* 'PTMF' */ if (pfh.magic != MAGIC_PTMF) return -1; /* Sanity check */ if (pfh.ordnum > 256 || pfh.insnum > 255 || pfh.patnum > 128 || pfh.chnnum > 32) { return -1; } hio_read(&pfh.rsvd3, 16, 1, f); /* Reserved */ hio_read(&pfh.chset, 32, 1, f); /* Channel settings */ hio_read(&pfh.order, 256, 1, f); /* Orders */ for (i = 0; i < 128; i++) pfh.patseg[i] = hio_read16l(f); mod->len = pfh.ordnum; mod->ins = pfh.insnum; mod->pat = pfh.patnum; mod->chn = pfh.chnnum; mod->trk = mod->pat * mod->chn; mod->smp = mod->ins; mod->spd = 6; mod->bpm = 125; memcpy (mod->xxo, pfh.order, 256); m->c4rate = C4_NTSC_RATE; copy_adjust(mod->name, pfh.name, 28); set_type(m, "Poly Tracker PTM %d.%02x", pfh.vermaj, pfh.vermin); MODULE_INFO(); if (instrument_init(mod) < 0) return -1; /* Read and convert instruments and samples */ for (i = 0; i < mod->ins; i++) { struct xmp_instrument *xxi = &mod->xxi[i]; struct xmp_sample *xxs = &mod->xxs[i]; struct xmp_subinstrument *sub; pih.type = hio_read8(f); /* Sample type */ hio_read(&pih.dosname, 12, 1, f); /* DOS file name */ pih.vol = hio_read8(f); /* Volume */ pih.c4spd = hio_read16l(f); /* C4 speed */ pih.smpseg = hio_read16l(f); /* Sample segment (not used) */ pih.smpofs = hio_read32l(f); /* Sample offset */ pih.length = hio_read32l(f); /* Length */ pih.loopbeg = hio_read32l(f); /* Loop begin */ pih.loopend = hio_read32l(f); /* Loop end */ pih.gusbeg = hio_read32l(f); /* GUS begin address */ pih.guslps = hio_read32l(f); /* GUS loop start address */ pih.guslpe = hio_read32l(f); /* GUS loop end address */ pih.gusflg = hio_read8(f); /* GUS loop flags */ pih.rsvd1 = hio_read8(f); /* Reserved */ hio_read(&pih.name, 28, 1, f); /* Instrument name */ pih.magic = hio_read32b(f); /* 'PTMS' */ if ((pih.type & 3) != 1) continue; if (subinstrument_alloc(mod, i, 1) < 0) return -1; sub = &xxi->sub[0]; smp_ofs[i] = pih.smpofs; xxs->len = pih.length; xxs->lps = pih.loopbeg; xxs->lpe = pih.loopend; if (mod->xxs[i].len > 0) mod->xxi[i].nsm = 1; xxs->flg = 0; if (pih.type & 0x04) { xxs->flg |= XMP_SAMPLE_LOOP; } if (pih.type & 0x08) { xxs->flg |= XMP_SAMPLE_LOOP | XMP_SAMPLE_LOOP_BIDIR; } if (pih.type & 0x10) { xxs->flg |= XMP_SAMPLE_16BIT; xxs->len >>= 1; xxs->lps >>= 1; xxs->lpe >>= 1; } sub->vol = pih.vol; sub->pan = 0x80; sub->sid = i; pih.magic = 0; instrument_name(mod, i, pih.name, 28); D_(D_INFO "[%2X] %-28.28s %05x%c%05x %05x %c V%02x %5d", i, mod->xxi[i].name, mod->xxs[i].len, pih.type & 0x10 ? '+' : ' ', xxs->lps, xxs->lpe, xxs->flg & XMP_SAMPLE_LOOP ? 'L' : ' ', sub->vol, pih.c4spd); /* Convert C4SPD to relnote/finetune */ c2spd_to_note(pih.c4spd, &sub->xpo, &sub->fin); }
static int ptm_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 c, r, i, smp_ofs[256]; struct xxm_event *event; struct ptm_file_header pfh; struct ptm_instrument_header pih; uint8 n, b; LOAD_INIT(); /* Load and convert header */ fread(&pfh.name, 28, 1, f); /* Song name */ pfh.doseof = read8(f); /* 0x1a */ pfh.vermin = read8(f); /* Minor version */ pfh.vermaj = read8(f); /* Major type */ pfh.rsvd1 = read8(f); /* Reserved */ pfh.ordnum = read16l(f); /* Number of orders (must be even) */ pfh.insnum = read16l(f); /* Number of instruments */ pfh.patnum = read16l(f); /* Number of patterns */ pfh.chnnum = read16l(f); /* Number of channels */ pfh.flags = read16l(f); /* Flags (set to 0) */ pfh.rsvd2 = read16l(f); /* Reserved */ pfh.magic = read32b(f); /* 'PTMF' */ #if 0 if (pfh.magic != MAGIC_PTMF) return -1; #endif fread(&pfh.rsvd3, 16, 1, f); /* Reserved */ fread(&pfh.chset, 32, 1, f); /* Channel settings */ fread(&pfh.order, 256, 1, f); /* Orders */ for (i = 0; i < 128; i++) pfh.patseg[i] = read16l(f); m->xxh->len = pfh.ordnum; m->xxh->ins = pfh.insnum; m->xxh->pat = pfh.patnum; m->xxh->chn = pfh.chnnum; m->xxh->trk = m->xxh->pat * m->xxh->chn; m->xxh->smp = m->xxh->ins; m->xxh->tpo = 6; m->xxh->bpm = 125; memcpy (m->xxo, pfh.order, 256); m->c4rate = C4_NTSC_RATE; copy_adjust((uint8 *)m->name, pfh.name, 28); sprintf(m->type, "PTMF %d.%02x (Poly Tracker)", pfh.vermaj, pfh.vermin); MODULE_INFO(); INSTRUMENT_INIT(); /* Read and convert instruments and samples */ reportv(ctx, 1, " Instrument name Len LBeg LEnd L Vol C4Spd\n"); for (i = 0; i < m->xxh->ins; i++) { m->xxi[i] = calloc (sizeof (struct xxm_instrument), 1); pih.type = read8(f); /* Sample type */ fread(&pih.dosname, 12, 1, f); /* DOS file name */ pih.vol = read8(f); /* Volume */ pih.c4spd = read16l(f); /* C4 speed */ pih.smpseg = read16l(f); /* Sample segment (not used) */ pih.smpofs = read32l(f); /* Sample offset */ pih.length = read32l(f); /* Length */ pih.loopbeg = read32l(f); /* Loop begin */ pih.loopend = read32l(f); /* Loop end */ pih.gusbeg = read32l(f); /* GUS begin address */ pih.guslps = read32l(f); /* GUS loop start address */ pih.guslpe = read32l(f); /* GUS loop end address */ pih.gusflg = read8(f); /* GUS loop flags */ pih.rsvd1 = read8(f); /* Reserved */ fread(&pih.name, 28, 1, f); /* Instrument name */ pih.magic = read32b(f); /* 'PTMS' */ if ((pih.type & 3) != 1) continue; smp_ofs[i] = pih.smpofs; m->xxih[i].nsm = !!(m->xxs[i].len = pih.length); m->xxs[i].lps = pih.loopbeg; m->xxs[i].lpe = pih.loopend; if (m->xxs[i].lpe) m->xxs[i].lpe--; m->xxs[i].flg = pih.type & 0x04 ? WAVE_LOOPING : 0; m->xxs[i].flg |= pih.type & 0x08 ? WAVE_LOOPING | WAVE_BIDIR_LOOP : 0; m->xxs[i].flg |= pih.type & 0x10 ? WAVE_16_BITS : 0; m->xxi[i][0].vol = pih.vol; m->xxi[i][0].pan = 0x80; m->xxi[i][0].sid = i; pih.magic = 0; copy_adjust(m->xxih[i].name, pih.name, 28); if ((V(1)) && (strlen((char *)m->xxih[i].name) || m->xxs[i].len)) report ("[%2X] %-28.28s %05x%c%05x %05x %c V%02x %5d\n", i, m->xxih[i].name, m->xxs[i].len, pih.type & 0x10 ? '+' : ' ', m->xxs[i].lps, m->xxs[i].lpe, m->xxs[i].flg & WAVE_LOOPING ? 'L' : ' ', m->xxi[i][0].vol, pih.c4spd); /* Convert C4SPD to relnote/finetune */ c2spd_to_note (pih.c4spd, &m->xxi[i][0].xpo, &m->xxi[i][0].fin); } PATTERN_INIT(); /* Read patterns */ reportv(ctx, 0, "Stored patterns: %d ", m->xxh->pat); for (i = 0; i < m->xxh->pat; i++) { if (!pfh.patseg[i]) continue; PATTERN_ALLOC (i); m->xxp[i]->rows = 64; TRACK_ALLOC (i); fseek(f, start + 16L * pfh.patseg[i], SEEK_SET); r = 0; while (r < 64) { fread (&b, 1, 1, f); if (!b) { r++; continue; } c = b & PTM_CH_MASK; if (c >= m->xxh->chn) continue; event = &EVENT (i, c, r); if (b & PTM_NI_FOLLOW) { fread (&n, 1, 1, f); switch (n) { case 255: n = 0; break; /* Empty note */ case 254: n = XMP_KEY_OFF; break; /* Key off */ } event->note = n; fread (&n, 1, 1, f); event->ins = n; } if (b & PTM_FX_FOLLOWS) { event->fxt = read8(f); event->fxp = read8(f); if (event->fxt > 0x17) event->fxt = event->fxp = 0; switch (event->fxt) { case 0x0e: /* Extended effect */ if (MSN(event->fxp) == 0x8) { /* Pan set */ event->fxt = FX_SETPAN; event->fxp = LSN (event->fxp) << 4; } break; case 0x10: /* Set global volume */ event->fxt = FX_GLOBALVOL; break; case 0x11: /* Multi retrig */ event->fxt = FX_MULTI_RETRIG; break; case 0x12: /* Fine vibrato */ event->fxt = FX_FINE4_VIBRA; break; case 0x13: /* Note slide down */ event->fxt = FX_NSLIDE_DN; break; case 0x14: /* Note slide up */ event->fxt = FX_NSLIDE_UP; break; case 0x15: /* Note slide down + retrig */ event->fxt = FX_NSLIDE_R_DN; break; case 0x16: /* Note slide up + retrig */ event->fxt = FX_NSLIDE_R_UP; break; case 0x17: /* Reverse sample */ event->fxt = event->fxp = 0; break; } } if (b & PTM_VOL_FOLLOWS) { event->vol = read8(f) + 1; } } reportv(ctx, 0, "."); } reportv(ctx, 0, "\nStored samples : %d ", m->xxh->smp); for (i = 0; i < m->xxh->smp; i++) { if (!m->xxs[i].len) continue; fseek(f, start + smp_ofs[m->xxi[i][0].sid], SEEK_SET); xmp_drv_loadpatch(ctx, f, m->xxi[i][0].sid, m->c4rate, XMP_SMP_8BDIFF, &m->xxs[m->xxi[i][0].sid], NULL); reportv(ctx, 0, "."); } reportv(ctx, 0, "\n"); m->vol_xlat = ptm_vol; for (i = 0; i < m->xxh->chn; i++) m->xxc[i].pan = pfh.chset[i] << 4; return 0; }
static int gdm_load(struct module_data *m, xmp_file f, const int start) { struct xmp_module *mod = &m->mod; struct xmp_event *event; int vermaj, vermin, tvmaj, tvmin, tracker; int origfmt, ord_ofs, pat_ofs, ins_ofs, smp_ofs; uint8 buffer[32], panmap[32]; int i; LOAD_INIT(); read32b(f); /* skip magic */ xmp_fread(mod->name, 1, 32, f); xmp_fseek(f, 32, SEEK_CUR); /* skip author */ xmp_fseek(f, 7, SEEK_CUR); vermaj = read8(f); vermin = read8(f); tracker = read16l(f); tvmaj = read8(f); tvmin = read8(f); if (tracker == 0) { set_type(m, "GDM %d.%02d (2GDM %d.%02d)", vermaj, vermin, tvmaj, tvmin); } else { set_type(m, "GDM %d.%02d (unknown tracker %d.%02d)", vermaj, vermin, tvmaj, tvmin); } xmp_fread(panmap, 32, 1, f); for (i = 0; i < 32; i++) { if (panmap[i] != 0xff) mod->chn = i + 1; if (panmap[i] == 16) panmap[i] = 8; mod->xxc[i].pan = 0x80 + (panmap[i] - 8) * 16; } mod->gvl = read8(f); mod->spd = read8(f); mod->bpm = read8(f); origfmt = read16l(f); ord_ofs = read32l(f); mod->len = read8(f) + 1; pat_ofs = read32l(f); mod->pat = read8(f) + 1; ins_ofs = read32l(f); smp_ofs = read32l(f); mod->ins = mod->smp = read8(f) + 1; mod->trk = mod->pat * mod->chn; MODULE_INFO(); xmp_fseek(f, start + ord_ofs, SEEK_SET); for (i = 0; i < mod->len; i++) mod->xxo[i] = read8(f); /* Read instrument data */ xmp_fseek(f, start + ins_ofs, SEEK_SET); INSTRUMENT_INIT(); for (i = 0; i < mod->ins; i++) { int flg, c4spd, vol, pan; mod->xxi[i].sub = calloc(sizeof (struct xmp_subinstrument), 1); xmp_fread(buffer, 32, 1, f); copy_adjust(mod->xxi[i].name, buffer, 32); xmp_fseek(f, 12, SEEK_CUR); /* skip filename */ read8(f); /* skip EMS handle */ mod->xxs[i].len = read32l(f); mod->xxs[i].lps = read32l(f); mod->xxs[i].lpe = read32l(f); flg = read8(f); c4spd = read16l(f); vol = read8(f); pan = read8(f); mod->xxi[i].sub[0].vol = vol > 0x40 ? 0x40 : vol; mod->xxi[i].sub[0].pan = pan > 15 ? 0x80 : 0x80 + (pan - 8) * 16; c2spd_to_note(c4spd, &mod->xxi[i].sub[0].xpo, &mod->xxi[i].sub[0].fin); mod->xxi[i].nsm = !!(mod->xxs[i].len); mod->xxi[i].sub[0].sid = i; mod->xxs[i].flg = 0; if (flg & 0x01) { mod->xxs[i].flg |= XMP_SAMPLE_LOOP; } if (flg & 0x02) { mod->xxs[i].flg |= XMP_SAMPLE_16BIT; mod->xxs[i].len >>= 1; mod->xxs[i].lps >>= 1; mod->xxs[i].lpe >>= 1; } D_(D_INFO "[%2X] %-32.32s %05x%c%05x %05x %c V%02x P%02x %5d", i, mod->xxi[i].name, mod->xxs[i].len, mod->xxs[i].flg & XMP_SAMPLE_16BIT ? '+' : ' ', mod->xxs[i].lps, mod->xxs[i].lpe, mod->xxs[i].flg & XMP_SAMPLE_LOOP ? 'L' : ' ', mod->xxi[i].sub[0].vol, mod->xxi[i].sub[0].pan, c4spd); }
static int s3m_load(struct module_data *m, FILE *f, const int start) { struct xmp_module *mod = &m->mod; int c, r, i; struct s3m_adlib_header sah; struct xmp_event *event = 0, dummy; struct s3m_file_header sfh; struct s3m_instrument_header sih; int pat_len; uint8 n, b, x8; char tracker_name[40]; int quirk87 = 0; uint16 *pp_ins; /* Parapointers to instruments */ uint16 *pp_pat; /* Parapointers to patterns */ uint8 arpeggio_val[32]; LOAD_INIT(); fread(&sfh.name, 28, 1, f); /* Song name */ read8(f); /* 0x1a */ sfh.type = read8(f); /* File type */ read16l(f); /* Reserved */ sfh.ordnum = read16l(f); /* Number of orders (must be even) */ sfh.insnum = read16l(f); /* Number of instruments */ sfh.patnum = read16l(f); /* Number of patterns */ sfh.flags = read16l(f); /* Flags */ sfh.version = read16l(f); /* Tracker ID and version */ sfh.ffi = read16l(f); /* File format information */ sfh.magic = read32b(f); /* 'SCRM' */ sfh.gv = read8(f); /* Global volume */ sfh.is = read8(f); /* Initial speed */ sfh.it = read8(f); /* Initial tempo */ sfh.mv = read8(f); /* Master volume */ sfh.uc = read8(f); /* Ultra click removal */ sfh.dp = read8(f); /* Default pan positions if 0xfc */ read32l(f); /* Reserved */ read32l(f); /* Reserved */ sfh.special = read16l(f); /* Ptr to special custom data */ fread(sfh.chset, 32, 1, f); /* Channel settings */ #if 0 if (sfh.magic != MAGIC_SCRM) return -1; #endif /* S3M anomaly in return_of_litmus.s3m */ if (sfh.version == 0x1301 && sfh.name[27] == 0x87) quirk87 = 1; if (quirk87) { fix87(sfh.name); fix87(sfh.patnum); fix87(sfh.flags); } copy_adjust(mod->name, sfh.name, 28); /* Load and convert header */ mod->len = sfh.ordnum; mod->ins = sfh.insnum; mod->smp = mod->ins; mod->pat = sfh.patnum; pp_ins = calloc (2, mod->ins); pp_pat = calloc (2, mod->pat); if (sfh.flags & S3M_AMIGA_RANGE) m->quirk |= QUIRK_MODRNG; if (sfh.flags & S3M_ST300_VOLS) m->quirk |= QUIRK_VSALL; /* m->volbase = 4096 / sfh.gv; */ mod->spd = sfh.is; mod->bpm = sfh.it; for (i = 0; i < 32; i++) { if (sfh.chset[i] == S3M_CH_OFF) continue; mod->chn = i + 1; if (sfh.mv & 0x80) { /* stereo */ int x = sfh.chset[i] & S3M_CH_PAN; mod->xxc[i].pan = (x & 0x0f) < 8 ? 0x00 : 0xff; } else { mod->xxc[i].pan = 0x80; } } mod->trk = mod->pat * mod->chn; fread(mod->xxo, 1, mod->len, f); for (i = 0; i < mod->ins; i++) pp_ins[i] = read16l(f); for (i = 0; i < mod->pat; i++) pp_pat[i] = read16l(f); /* Default pan positions */ for (i = 0, sfh.dp -= 0xfc; !sfh.dp /* && n */ && (i < 32); i++) { uint8 x = read8(f); if (x & S3M_PAN_SET) mod->xxc[i].pan = (x << 4) & 0xff; else mod->xxc[i].pan = sfh.mv % 0x80 ? 0x30 + 0xa0 * (i & 1) : 0x80; } m->c4rate = C4_NTSC_RATE; if (sfh.version == 0x1300) m->quirk |= QUIRK_VSALL; switch (sfh.version >> 12) { case 1: snprintf(tracker_name, 40, "Scream Tracker %d.%02x", (sfh.version & 0x0f00) >> 8, sfh.version & 0xff); m->quirk |= QUIRK_ST3GVOL; break; case 2: snprintf(tracker_name, 40, "Imago Orpheus %d.%02x", (sfh.version & 0x0f00) >> 8, sfh.version & 0xff); break; case 3: if (sfh.version == 0x3216) { strcpy(tracker_name, "Impulse Tracker 2.14v3"); } else if (sfh.version == 0x3217) { strcpy(tracker_name, "Impulse Tracker 2.14v5"); } else { snprintf(tracker_name, 40, "Impulse Tracker %d.%02x", (sfh.version & 0x0f00) >> 8, sfh.version & 0xff); } break; case 4: snprintf(tracker_name, 40, "Schism Tracker %d.%02x", (sfh.version & 0x0f00) >> 8, sfh.version & 0xff); break; case 5: snprintf(tracker_name, 40, "OpenMPT %d.%02x", (sfh.version & 0x0f00) >> 8, sfh.version & 0xff); break; default: snprintf(tracker_name, 40, "unknown (%04x)", sfh.version); } snprintf(mod->type, XMP_NAME_SIZE, "%s S3M", tracker_name); MODULE_INFO(); PATTERN_INIT(); /* Read patterns */ D_(D_INFO "Stored patterns: %d", mod->pat); memset (arpeggio_val, 0, 32); for (i = 0; i < mod->pat; i++) { PATTERN_ALLOC (i); mod->xxp[i]->rows = 64; TRACK_ALLOC (i); if (!pp_pat[i]) continue; fseek(f, start + pp_pat[i] * 16, SEEK_SET); r = 0; pat_len = read16l(f) - 2; /* Used to be (--pat_len >= 0). Replaced by Rudolf Cejka * <*****@*****.**>, fixes hunt.s3m * ftp://us.aminet.net/pub/aminet/mods/8voic/s3m_hunt.lha */ while (r < mod->xxp[i]->rows) { b = read8(f); if (b == S3M_EOR) { r++; continue; } c = b & S3M_CH_MASK; event = c >= mod->chn ? &dummy : &EVENT (i, c, r); if (b & S3M_NI_FOLLOW) { switch(n = read8(f)) { case 255: n = 0; break; /* Empty note */ case 254: n = XMP_KEY_OFF; break; /* Key off */ default: n = 13 + 12 * MSN (n) + LSN (n); } event->note = n; event->ins = read8(f); pat_len -= 2; } if (b & S3M_VOL_FOLLOWS) { event->vol = read8(f) + 1; pat_len--; } if (b & S3M_FX_FOLLOWS) { event->fxt = read8(f); event->fxp = read8(f); xlat_fx(c, event, arpeggio_val); pat_len -= 2; } } } D_(D_INFO "Stereo enabled: %s", sfh.mv & 0x80 ? "yes" : "no"); D_(D_INFO "Pan settings: %s", sfh.dp ? "no" : "yes"); INSTRUMENT_INIT(); /* Read and convert instruments and samples */ D_(D_INFO "Instruments: %d", mod->ins); for (i = 0; i < mod->ins; i++) { mod->xxi[i].sub = calloc(sizeof (struct xmp_subinstrument), 1); fseek(f, start + pp_ins[i] * 16, SEEK_SET); x8 = read8(f); mod->xxi[i].sub[0].pan = 0x80; mod->xxi[i].sub[0].sid = i; if (x8 >= 2) { /* OPL2 FM instrument */ fread(&sah.dosname, 12, 1, f); /* DOS file name */ fread(&sah.rsvd1, 3, 1, f); /* 0x00 0x00 0x00 */ fread(&sah.reg, 12, 1, f); /* Adlib registers */ sah.vol = read8(f); sah.dsk = read8(f); read16l(f); sah.c2spd = read16l(f); /* C 4 speed */ read16l(f); fread(&sah.rsvd4, 12, 1, f); /* Reserved */ fread(&sah.name, 28, 1, f); /* Instrument name */ sah.magic = read32b(f); /* 'SCRI' */ if (sah.magic != MAGIC_SCRI) { D_(D_CRIT "error: FM instrument magic"); return -2; } sah.magic = 0; copy_adjust(mod->xxi[i].name, sah.name, 28); mod->xxi[i].nsm = 1; mod->xxi[i].sub[0].vol = sah.vol; c2spd_to_note(sah.c2spd, &mod->xxi[i].sub[0].xpo, &mod->xxi[i].sub[0].fin); mod->xxi[i].sub[0].xpo += 12; load_sample(f, SAMPLE_FLAG_ADLIB, &mod->xxs[i], (char *)&sah.reg); D_(D_INFO "[%2X] %-28.28s", i, mod->xxi[i].name); continue; } fread(&sih.dosname, 13, 1, f); /* DOS file name */ sih.memseg = read16l(f); /* Pointer to sample data */ sih.length = read32l(f); /* Length */ sih.loopbeg = read32l(f); /* Loop begin */ sih.loopend = read32l(f); /* Loop end */ sih.vol = read8(f); /* Volume */ sih.rsvd1 = read8(f); /* Reserved */ sih.pack = read8(f); /* Packing type (not used) */ sih.flags = read8(f); /* Loop/stereo/16bit samples flags */ sih.c2spd = read16l(f); /* C 4 speed */ sih.rsvd2 = read16l(f); /* Reserved */ fread(&sih.rsvd3, 4, 1, f); /* Reserved */ sih.int_gp = read16l(f); /* Internal - GUS pointer */ sih.int_512 = read16l(f); /* Internal - SB pointer */ sih.int_last = read32l(f); /* Internal - SB index */ fread(&sih.name, 28, 1, f); /* Instrument name */ sih.magic = read32b(f); /* 'SCRS' */ if (x8 == 1 && sih.magic != MAGIC_SCRS) { D_(D_CRIT "error: instrument magic"); return -2; } if (quirk87) { fix87(sih.length); fix87(sih.loopbeg); fix87(sih.loopend); fix87(sih.flags); } mod->xxs[i].len = sih.length; mod->xxi[i].nsm = sih.length > 0 ? 1 : 0; mod->xxs[i].lps = sih.loopbeg; mod->xxs[i].lpe = sih.loopend; mod->xxs[i].flg = sih.flags & 1 ? XMP_SAMPLE_LOOP : 0; if (sih.flags & 4) { mod->xxs[i].flg |= XMP_SAMPLE_16BIT; mod->xxs[i].len >>= 1; mod->xxs[i].lps >>= 1; mod->xxs[i].lpe >>= 1; } mod->xxi[i].sub[0].vol = sih.vol; sih.magic = 0; copy_adjust(mod->xxi[i].name, sih.name, 28); D_(D_INFO "[%2X] %-28.28s %04x%c%04x %04x %c V%02x %5d", i, mod->xxi[i].name, mod->xxs[i].len, mod->xxs[i].flg & XMP_SAMPLE_16BIT ?'+' : ' ', mod->xxs[i].lps, mod->xxs[i].lpe, mod->xxs[i].flg & XMP_SAMPLE_LOOP ? 'L' : ' ', mod->xxi[i].sub[0].vol, sih.c2spd); c2spd_to_note(sih.c2spd, &mod->xxi[i].sub[0].xpo, &mod->xxi[i].sub[0].fin); fseek(f, start + 16L * sih.memseg, SEEK_SET); load_sample(f, (sfh.ffi - 1) * SAMPLE_FLAG_UNS, &mod->xxs[i], NULL); }
static int get_inst(struct module_data *m, int size, HIO_HANDLE *f, void *parm) { struct xmp_module *mod = &m->mod; int i, srate, finetune, flags; int has_unsigned_sample; hio_read32b(f); /* 42 01 00 00 */ hio_read8(f); /* 00 */ i = hio_read8(f); /* instrument number */ hio_read(&mod->xxi[i].name, 1, 28, f); adjust_string((char *)mod->xxi[i].name); hio_seek(f, 290, SEEK_CUR); /* Sample/note map, envelopes */ mod->xxi[i].nsm = hio_read16l(f); D_(D_INFO "[%2X] %-28.28s %2d ", i, mod->xxi[i].name, mod->xxi[i].nsm); if (mod->xxi[i].nsm == 0) return 0; if (subinstrument_alloc(mod, i, mod->xxi[i].nsm) < 0) return -1; /* FIXME: Currently reading only the first sample */ hio_read32b(f); /* RIFF */ hio_read32b(f); /* size */ hio_read32b(f); /* AS */ hio_read32b(f); /* SAMP */ hio_read32b(f); /* size */ hio_read32b(f); /* unknown - usually 0x40000000 */ hio_read(&mod->xxs[i].name, 1, 28, f); adjust_string((char *)mod->xxs[i].name); hio_read32b(f); /* unknown - 0x0000 */ hio_read8(f); /* unknown - 0x00 */ mod->xxi[i].sub[0].sid = i; mod->xxi[i].vol = hio_read8(f); mod->xxi[i].sub[0].pan = 0x80; mod->xxi[i].sub[0].vol = (hio_read16l(f) + 1) / 512; flags = hio_read16l(f); hio_read16l(f); /* unknown - 0x0080 */ mod->xxs[i].len = hio_read32l(f); mod->xxs[i].lps = hio_read32l(f); mod->xxs[i].lpe = hio_read32l(f); mod->xxs[i].flg = 0; has_unsigned_sample = 0; if (flags & 0x04) mod->xxs[i].flg |= XMP_SAMPLE_16BIT; if (flags & 0x08) mod->xxs[i].flg |= XMP_SAMPLE_LOOP; if (flags & 0x10) mod->xxs[i].flg |= XMP_SAMPLE_LOOP | XMP_SAMPLE_LOOP_BIDIR; if (~flags & 0x80) has_unsigned_sample = 1; srate = hio_read32l(f); finetune = 0; c2spd_to_note(srate, &mod->xxi[i].sub[0].xpo, &mod->xxi[i].sub[0].fin); mod->xxi[i].sub[0].fin += finetune; hio_read32l(f); /* 0x00000000 */ hio_read32l(f); /* unknown */ D_(D_INFO " %x: %05x%c%05x %05x %c V%02x %04x %5d", 0, mod->xxs[i].len, mod->xxs[i].flg & XMP_SAMPLE_16BIT ? '+' : ' ', mod->xxs[i].lps, mod->xxs[i].lpe, mod->xxs[i].flg & XMP_SAMPLE_LOOP_BIDIR ? 'B' : mod->xxs[i].flg & XMP_SAMPLE_LOOP ? 'L' : ' ', mod->xxi[i].sub[0].vol, flags, srate); if (mod->xxs[i].len > 1) { if (load_sample(m, f, has_unsigned_sample ? SAMPLE_FLAG_UNS : 0, &mod->xxs[i], NULL) < 0) return -1; } return 0; }
static int gdm_load(struct module_data *m, HIO_HANDLE *f, const int start) { struct xmp_module *mod = &m->mod; struct xmp_event *event; int vermaj, vermin, tvmaj, tvmin, tracker; int /*origfmt,*/ ord_ofs, pat_ofs, ins_ofs, smp_ofs; uint8 buffer[32], panmap[32]; int i; LOAD_INIT(); hio_read32b(f); /* skip magic */ hio_read(mod->name, 1, 32, f); hio_seek(f, 32, SEEK_CUR); /* skip author */ hio_seek(f, 7, SEEK_CUR); vermaj = hio_read8(f); vermin = hio_read8(f); tracker = hio_read16l(f); tvmaj = hio_read8(f); tvmin = hio_read8(f); if (tracker == 0) { set_type(m, "GDM %d.%02d (2GDM %d.%02d)", vermaj, vermin, tvmaj, tvmin); } else { set_type(m, "GDM %d.%02d (unknown tracker %d.%02d)", vermaj, vermin, tvmaj, tvmin); } hio_read(panmap, 32, 1, f); for (i = 0; i < 32; i++) { if (panmap[i] == 255) { panmap[i] = 8; mod->xxc[i].vol = 0; mod->xxc[i].flg |= XMP_CHANNEL_MUTE; } else if (panmap[i] == 16) { panmap[i] = 8; } mod->xxc[i].pan = 0x80 + (panmap[i] - 8) * 16; } mod->gvl = hio_read8(f); mod->spd = hio_read8(f); mod->bpm = hio_read8(f); /*origfmt =*/ hio_read16l(f); ord_ofs = hio_read32l(f); mod->len = hio_read8(f) + 1; pat_ofs = hio_read32l(f); mod->pat = hio_read8(f) + 1; ins_ofs = hio_read32l(f); smp_ofs = hio_read32l(f); mod->ins = mod->smp = hio_read8(f) + 1; MODULE_INFO(); hio_seek(f, start + ord_ofs, SEEK_SET); for (i = 0; i < mod->len; i++) mod->xxo[i] = hio_read8(f); /* Read instrument data */ hio_seek(f, start + ins_ofs, SEEK_SET); if (instrument_init(mod) < 0) return -1; for (i = 0; i < mod->ins; i++) { int flg, c4spd, vol, pan; if (subinstrument_alloc(mod, i, 1) < 0) return -1; hio_read(buffer, 32, 1, f); instrument_name(mod, i, buffer, 32); hio_seek(f, 12, SEEK_CUR); /* skip filename */ hio_read8(f); /* skip EMS handle */ mod->xxs[i].len = hio_read32l(f); mod->xxs[i].lps = hio_read32l(f); mod->xxs[i].lpe = hio_read32l(f); flg = hio_read8(f); c4spd = hio_read16l(f); vol = hio_read8(f); pan = hio_read8(f); mod->xxi[i].sub[0].vol = vol > 0x40 ? 0x40 : vol; mod->xxi[i].sub[0].pan = pan > 15 ? 0x80 : 0x80 + (pan - 8) * 16; c2spd_to_note(c4spd, &mod->xxi[i].sub[0].xpo, &mod->xxi[i].sub[0].fin); mod->xxi[i].sub[0].sid = i; mod->xxs[i].flg = 0; if (mod->xxs[i].len > 0) mod->xxi[i].nsm = 1; if (flg & 0x01) { mod->xxs[i].flg |= XMP_SAMPLE_LOOP; } if (flg & 0x02) { mod->xxs[i].flg |= XMP_SAMPLE_16BIT; mod->xxs[i].len >>= 1; mod->xxs[i].lps >>= 1; mod->xxs[i].lpe >>= 1; } D_(D_INFO "[%2X] %-32.32s %05x%c%05x %05x %c V%02x P%02x %5d", i, mod->xxi[i].name, mod->xxs[i].len, mod->xxs[i].flg & XMP_SAMPLE_16BIT ? '+' : ' ', mod->xxs[i].lps, mod->xxs[i].lpe, mod->xxs[i].flg & XMP_SAMPLE_LOOP ? 'L' : ' ', mod->xxi[i].sub[0].vol, mod->xxi[i].sub[0].pan, c4spd); }
int xmp_smix_load_sample(xmp_context opaque, int num, char *path) { struct context_data *ctx = (struct context_data *)opaque; struct smix_data *smix = &ctx->smix; struct module_data *m = &ctx->m; struct xmp_instrument *xxi; struct xmp_sample *xxs; HIO_HANDLE *h; uint32 magic; int chn, rate, bits, size; int retval = -XMP_ERROR_INTERNAL; if (num >= smix->ins) { retval = -XMP_ERROR_INVALID; goto err; } xxi = &smix->xxi[num]; xxs = &smix->xxs[num]; h = hio_open_file(path, "rb"); if (h == NULL) { retval = -XMP_ERROR_SYSTEM; goto err; } /* Init instrument */ xxi->sub = calloc(sizeof(struct xmp_subinstrument), 1); if (xxi->sub == NULL) { retval = -XMP_ERROR_SYSTEM; goto err1; } xxi->vol = m->volbase; xxi->nsm = 1; xxi->sub[0].sid = num; xxi->sub[0].vol = xxi->vol; xxi->sub[0].pan = 0x80; /* Load sample */ magic = hio_read32b(h); if (magic != 0x52494646) { /* RIFF */ retval = -XMP_ERROR_FORMAT; goto err2; } hio_seek(h, 22, SEEK_SET); chn = hio_read16l(h); if (chn != 1) { retval = -XMP_ERROR_FORMAT; goto err2; } rate = hio_read32l(h); hio_seek(h, 34, SEEK_SET); bits = hio_read16l(h); hio_seek(h, 40, SEEK_SET); size = hio_read32l(h) / (bits / 8); c2spd_to_note(rate, &xxi->sub[0].xpo, &xxi->sub[0].fin); xxs->len = 8 * size / bits; xxs->lps = 0; xxs->lpe = 0; xxs->flg = bits == 16 ? XMP_SAMPLE_16BIT : 0; xxs->data = malloc(size); if (xxs->data == NULL) { retval = -XMP_ERROR_SYSTEM; goto err2; } hio_seek(h, 44, SEEK_SET); hio_read(xxs->data, 1, size, h); hio_close(h); return 0; err2: free(xxi->sub); xxi->sub = NULL; err1: hio_close(h); err: return retval; }
static int mgt_load(struct xmp_context *ctx, FILE *f, const int start) { struct xmp_player_context *p = &ctx->p; struct xmp_mod_context *m = &p->m; struct xxm_event *event; int i, j; int ver; int sng_ptr, seq_ptr, ins_ptr, pat_ptr, trk_ptr, smp_ptr; int sdata[64]; LOAD_INIT(); read24b(f); /* MGT */ ver = read8(f); read32b(f); /* MCS */ sprintf(m->type, "MGT v%d.%d (Megatracker)", MSN(ver), LSN(ver)); m->xxh->chn = read16b(f); read16b(f); /* number of songs */ m->xxh->len = read16b(f); m->xxh->pat = read16b(f); m->xxh->trk = read16b(f); m->xxh->ins = m->xxh->smp = read16b(f); read16b(f); /* reserved */ read32b(f); /* reserved */ sng_ptr = read32b(f); seq_ptr = read32b(f); ins_ptr = read32b(f); pat_ptr = read32b(f); trk_ptr = read32b(f); smp_ptr = read32b(f); read32b(f); /* total smp len */ read32b(f); /* unpacked trk size */ fseek(f, start + sng_ptr, SEEK_SET); fread(m->name, 1, 32, f); seq_ptr = read32b(f); m->xxh->len = read16b(f); m->xxh->rst = read16b(f); m->xxh->bpm = read8(f); m->xxh->tpo = read8(f); read16b(f); /* global volume */ read8(f); /* master L */ read8(f); /* master R */ for (i = 0; i < m->xxh->chn; i++) { read16b(f); /* pan */ } MODULE_INFO(); /* Sequence */ fseek(f, start + seq_ptr, SEEK_SET); for (i = 0; i < m->xxh->len; i++) m->xxo[i] = read16b(f); /* Instruments */ INSTRUMENT_INIT(); fseek(f, start + ins_ptr, SEEK_SET); reportv(ctx, 1, " Name Len LBeg LEnd L Vol C2Spd\n"); for (i = 0; i < m->xxh->ins; i++) { int c2spd, flags; m->xxi[i] = calloc(sizeof(struct xxm_instrument), 1); fread(m->xxih[i].name, 1, 32, f); sdata[i] = read32b(f); m->xxs[i].len = read32b(f); m->xxs[i].lps = read32b(f); m->xxs[i].lpe = m->xxs[i].lps + read32b(f); read32b(f); read32b(f); c2spd = read32b(f); c2spd_to_note(c2spd, &m->xxi[i][0].xpo, &m->xxi[i][0].fin); m->xxi[i][0].vol = read16b(f) >> 4; read8(f); /* vol L */ read8(f); /* vol R */ m->xxi[i][0].pan = 0x80; flags = read8(f); m->xxs[i].flg = flags & 0x03 ? WAVE_LOOPING : 0; m->xxs[i].flg |= flags & 0x02 ? WAVE_BIDIR_LOOP : 0; m->xxi[i][0].fin += 0 * read8(f); // FIXME read8(f); /* unused */ read8(f); read8(f); read8(f); read16b(f); read32b(f); read32b(f); m->xxih[i].nsm = !!m->xxs[i].len; m->xxi[i][0].sid = i; if (V(1) && (strlen((char*)m->xxih[i].name) || (m->xxs[i].len > 1))) { report("[%2X] %-32.32s %04x %04x %04x %c V%02x %5d\n", i, m->xxih[i].name, m->xxs[i].len, m->xxs[i].lps, m->xxs[i].lpe, m->xxs[i].flg & WAVE_BIDIR_LOOP ? 'B' : m->xxs[i].flg & WAVE_LOOPING ? 'L' : ' ', m->xxi[i][0].vol, c2spd); } } /* PATTERN_INIT - alloc extra track*/ PATTERN_INIT(); reportv(ctx, 0, "Stored tracks : %d ", m->xxh->trk); /* Tracks */ for (i = 1; i < m->xxh->trk; i++) { int offset, rows; uint8 b; fseek(f, start + trk_ptr + i * 4, SEEK_SET); offset = read32b(f); fseek(f, start + offset, SEEK_SET); rows = read16b(f); m->xxt[i] = calloc(sizeof(struct xxm_track) + sizeof(struct xxm_event) * rows, 1); m->xxt[i]->rows = rows; //printf("\n=== Track %d ===\n\n", i); for (j = 0; j < rows; j++) { uint8 note, f2p; b = read8(f); j += b & 0x03; note = 0; event = &m->xxt[i]->event[j]; if (b & 0x04) note = read8(f); if (b & 0x08) event->ins = read8(f); if (b & 0x10) event->vol = read8(f); if (b & 0x20) event->fxt = read8(f); if (b & 0x40) event->fxp = read8(f); if (b & 0x80) f2p = read8(f); if (note == 1) event->note = XMP_KEY_OFF; else if (note > 11) /* adjusted to play codeine.mgt */ event->note = note - 11; /* effects */ if (event->fxt < 0x10) /* like amiga */ ; else switch (event->fxt) { case 0x13: case 0x14: case 0x15: case 0x17: case 0x1c: case 0x1d: case 0x1e: event->fxt = FX_EXTENDED; event->fxp = ((event->fxt & 0x0f) << 4) | (event->fxp & 0x0f); break; default: event->fxt = event->fxp = 0; } /* volume and volume column effects */ if ((event->vol >= 0x10) && (event->vol <= 0x50)) { event->vol -= 0x0f; continue; } switch (event->vol >> 4) { case 0x06: /* Volume slide down */ event->f2t = FX_VOLSLIDE_2; event->f2p = event->vol - 0x60; break; case 0x07: /* Volume slide up */ event->f2t = FX_VOLSLIDE_2; event->f2p = (event->vol - 0x70) << 4; break; case 0x08: /* Fine volume slide down */ event->f2t = FX_EXTENDED; event->f2p = (EX_F_VSLIDE_DN << 4) | (event->vol - 0x80); break; case 0x09: /* Fine volume slide up */ event->f2t = FX_EXTENDED; event->f2p = (EX_F_VSLIDE_UP << 4) | (event->vol - 0x90); break; case 0x0a: /* Set vibrato speed */ event->f2t = FX_VIBRATO; event->f2p = (event->vol - 0xa0) << 4; break; case 0x0b: /* Vibrato */ event->f2t = FX_VIBRATO; event->f2p = event->vol - 0xb0; break; case 0x0c: /* Set panning */ event->f2t = FX_SETPAN; event->f2p = ((event->vol - 0xc0) << 4) + 8; break; case 0x0d: /* Pan slide left */ event->f2t = FX_PANSLIDE; event->f2p = (event->vol - 0xd0) << 4; break; case 0x0e: /* Pan slide right */ event->f2t = FX_PANSLIDE; event->f2p = event->vol - 0xe0; break; case 0x0f: /* Tone portamento */ event->f2t = FX_TONEPORTA; event->f2p = (event->vol - 0xf0) << 4; break; } event->vol = 0; /*printf("%02x %02x %02x %02x %02x %02x\n", j, event->note, event->ins, event->vol, event->fxt, event->fxp);*/ } if (V(0) && i % m->xxh->chn == 0) report("."); } reportv(ctx, 0, "\n"); /* Extra track */ m->xxt[0] = calloc(sizeof(struct xxm_track) + sizeof(struct xxm_event) * 64 - 1, 1); m->xxt[0]->rows = 64; /* Read and convert patterns */ reportv(ctx, 0, "Stored patterns: %d ", m->xxh->pat); fseek(f, start + pat_ptr, SEEK_SET); for (i = 0; i < m->xxh->pat; i++) { PATTERN_ALLOC(i); m->xxp[i]->rows = read16b(f); for (j = 0; j < m->xxh->chn; j++) { m->xxp[i]->info[j].index = read16b(f) - 1; //printf("%3d ", m->xxp[i]->info[j].index); } reportv(ctx, 0, "."); //printf("\n"); } reportv(ctx, 0, "\n"); /* Read samples */ reportv(ctx, 0, "Stored samples : %d ", m->xxh->smp); for (i = 0; i < m->xxh->ins; i++) { if (m->xxih[i].nsm == 0) continue; fseek(f, start + sdata[i], SEEK_SET); xmp_drv_loadpatch(ctx, f, m->xxi[i][0].sid, m->c4rate, 0, &m->xxs[m->xxi[i][0].sid], NULL); reportv(ctx, 0, "."); } reportv(ctx, 0, "\n"); return 0; }
static int amf_load(struct module_data *m, HIO_HANDLE *f, const int start) { struct xmp_module *mod = &m->mod; int i, j; struct xmp_event *event; uint8 buf[1024]; int *trkmap, newtrk; int ver; LOAD_INIT(); hio_read(buf, 1, 3, f); ver = hio_read8(f); hio_read(buf, 1, 32, f); strncpy(mod->name, (char *)buf, 32); set_type(m, "DSMI %d.%d AMF", ver / 10, ver % 10); mod->ins = hio_read8(f); mod->len = hio_read8(f); mod->trk = hio_read16l(f); mod->chn = hio_read8(f); mod->smp = mod->ins; mod->pat = mod->len; if (ver == 0x0a) hio_read(buf, 1, 16, f); /* channel remap table */ if (ver >= 0x0d) { hio_read(buf, 1, 32, f); /* panning table */ for (i = 0; i < 32; i++) { mod->xxc->pan = 0x80 + 2 * (int8)buf[i]; } mod->bpm = hio_read8(f); mod->spd = hio_read8(f); } else if (ver >= 0x0b) { hio_read(buf, 1, 16, f); } MODULE_INFO(); /* Orders */ /* * Andre Timmermans <*****@*****.**> says: * * Order table: track numbers in this table are not explained, * but as you noticed you have to perform -1 to obtain the index * in the track table. For value 0, found in some files, I think * it means an empty track. */ for (i = 0; i < mod->len; i++) mod->xxo[i] = i; D_(D_INFO "Stored patterns: %d", mod->pat); mod->xxp = calloc(sizeof(struct xmp_pattern *), mod->pat + 1); if (mod->xxp == NULL) return -1; for (i = 0; i < mod->pat; i++) { if (pattern_alloc(mod, i) < 0) return -1; mod->xxp[i]->rows = ver >= 0x0e ? hio_read16l(f) : 64; for (j = 0; j < mod->chn; j++) { uint16 t = hio_read16l(f); mod->xxp[i]->index[j] = t; } } /* Instruments */ if (instrument_init(mod) < 0) return -1; /* Probe for 2-byte loop start 1.0 format * in facing_n.amf and sweetdrm.amf have only the sample * loop start specified in 2 bytes */ if (ver <= 0x0a) { uint8 b; uint32 len, start, end; long pos = hio_tell(f); for (i = 0; i < mod->ins; i++) { b = hio_read8(f); if (b != 0 && b != 1) { ver = 0x09; break; } hio_seek(f, 32 + 13, SEEK_CUR); if (hio_read32l(f) > 0x100000) { /* check index */ ver = 0x09; break; } len = hio_read32l(f); if (len > 0x100000) { /* check len */ ver = 0x09; break; } if (hio_read16l(f) == 0x0000) { /* check c2spd */ ver = 0x09; break; } if (hio_read8(f) > 0x40) { /* check volume */ ver = 0x09; break; } start = hio_read32l(f); if (start > len) { /* check loop start */ ver = 0x09; break; } end = hio_read32l(f); if (end > len) { /* check loop end */ ver = 0x09; break; } } hio_seek(f, pos, SEEK_SET); } for (i = 0; i < mod->ins; i++) { /*uint8 b;*/ int c2spd; if (subinstrument_alloc(mod, i, 1) < 0) return -1; /*b =*/ hio_read8(f); hio_read(buf, 1, 32, f); instrument_name(mod, i, buf, 32); hio_read(buf, 1, 13, f); /* sample name */ hio_read32l(f); /* sample index */ mod->xxi[i].nsm = 1; mod->xxi[i].sub[0].sid = i; mod->xxi[i].sub[0].pan = 0x80; mod->xxs[i].len = hio_read32l(f); c2spd = hio_read16l(f); c2spd_to_note(c2spd, &mod->xxi[i].sub[0].xpo, &mod->xxi[i].sub[0].fin); mod->xxi[i].sub[0].vol = hio_read8(f); /* * Andre Timmermans <*****@*****.**> says: * * [Miodrag Vallat's] doc tells that in version 1.0 only * sample loop start is present (2 bytes) but the files I * have tells both start and end are present (2*4 bytes). * Maybe it should be read as version < 1.0. * * CM: confirmed with Maelcum's "The tribal zone" */ if (ver < 0x0a) { mod->xxs[i].lps = hio_read16l(f); mod->xxs[i].lpe = mod->xxs[i].len; } else { mod->xxs[i].lps = hio_read32l(f); mod->xxs[i].lpe = hio_read32l(f); } if (ver < 0x0a) { mod->xxs[i].flg = mod->xxs[i].lps > 0 ? XMP_SAMPLE_LOOP : 0; } else { mod->xxs[i].flg = mod->xxs[i].lpe > mod->xxs[i].lps ? XMP_SAMPLE_LOOP : 0; } D_(D_INFO "[%2X] %-32.32s %05x %05x %05x %c V%02x %5d", 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, c2spd); } /* Tracks */ trkmap = calloc(sizeof(int), mod->trk); if (trkmap == NULL) return -1; newtrk = 0; for (i = 0; i < mod->trk; i++) { /* read track table */ uint16 t; t = hio_read16l(f); trkmap[i] = t; if (t > newtrk) newtrk = t; /*printf("%d -> %d\n", i, t);*/ } for (i = 0; i < mod->pat; i++) { /* read track table */ for (j = 0; j < mod->chn; j++) { int k = mod->xxp[i]->index[j] - 1; /* Use empty track if an invalid track is requested * (such as in Lasse Makkonen "faster and louder") */ if (k < 0 || k >= mod->trk) k = 0; mod->xxp[i]->index[j] = trkmap[k]; /*printf("mod->xxp[%d]->info[%d].index = %d (k = %d)\n", i, j, trkmap[k], k);*/ } } mod->trk = newtrk; /* + empty track */ free(trkmap); D_(D_INFO "Stored tracks: %d", mod->trk); mod->trk++; mod->xxt = calloc (sizeof (struct xmp_track *), mod->trk); if (mod->xxt == NULL) return -1; /* Alloc track 0 as empty track */ if (track_alloc(mod, 0, 64) < 0) return -1; /* Alloc rest of the tracks */ for (i = 1; i < mod->trk; i++) { uint8 t1, t2, t3; int size; if (track_alloc(mod, i, 64) < 0) return -1; size = hio_read24l(f); /*printf("TRACK %d SIZE %d\n", i, size);*/ for (j = 0; j < size; j++) { t1 = hio_read8(f); /* row */ t2 = hio_read8(f); /* type */ t3 = hio_read8(f); /* parameter */ /*printf("track %d row %d: %02x %02x %02x\n", i, t1, t1, t2, t3);*/ if (t1 == 0xff && t2 == 0xff && t3 == 0xff) break; event = &mod->xxt[i]->event[t1]; if (t2 < 0x7f) { /* note */ if (t2 > 0) event->note = t2 + 1; event->vol = t3; } else if (t2 == 0x7f) { /* copy previous */ memcpy(event, &mod->xxt[i]->event[t1 - 1], sizeof(struct xmp_event)); } else if (t2 == 0x80) { /* instrument */ event->ins = t3 + 1; } else { /* effects */ uint8 fxp, fxt; fxp = fxt = 0; switch (t2) { case 0x81: fxt = FX_SPEED; fxp = t3; break; case 0x82: if ((int8)t3 > 0) { fxt = FX_VOLSLIDE; fxp = t3 << 4; } else { fxt = FX_VOLSLIDE; fxp = -(int8)t3 & 0x0f; } break; case 0x83: event->vol = t3; break; case 0x84: /* AT: Not explained for 0x84, pitch * slide, value 0x00 corresponds to * S3M E00 and 0x80 stands for S3M F00 * (I checked with M2AMF) */ if ((int8)t3 >= 0) { fxt = FX_PORTA_DN; fxp = t3; } else if (t3 == 0x80) { fxt = FX_PORTA_UP; fxp = 0; } else { fxt = FX_PORTA_UP; fxp = -(int8)t3; } break; case 0x85: /* porta abs -- unknown */ break; case 0x86: fxt = FX_TONEPORTA; fxp = t3; break; /* AT: M2AMF maps both tremolo and tremor to * 0x87. Since tremor is only found in certain * formats, maybe it would be better to * consider it is a tremolo. */ case 0x87: fxt = FX_TREMOLO; fxp = t3; break; case 0x88: fxt = FX_ARPEGGIO; fxp = t3; break; case 0x89: fxt = FX_VIBRATO; fxp = t3; break; case 0x8a: if ((int8)t3 > 0) { fxt = FX_TONE_VSLIDE; fxp = t3 << 4; } else { fxt = FX_TONE_VSLIDE; fxp = -(int8)t3 & 0x0f; } break; case 0x8b: if ((int8)t3 > 0) { fxt = FX_VIBRA_VSLIDE; fxp = t3 << 4; } else { fxt = FX_VIBRA_VSLIDE; fxp = -(int8)t3 & 0x0f; } break; case 0x8c: fxt = FX_BREAK; fxp = t3; break; case 0x8d: fxt = FX_JUMP; fxp = t3; break; case 0x8e: /* sync -- unknown */ break; case 0x8f: fxt = FX_EXTENDED; fxp = (EX_RETRIG << 4) | (t3 & 0x0f); break; case 0x90: fxt = FX_OFFSET; fxp = t3; break; case 0x91: if ((int8)t3 > 0) { fxt = FX_EXTENDED; fxp = (EX_F_VSLIDE_UP << 4) | (t3 & 0x0f); } else { fxt = FX_EXTENDED; fxp = (EX_F_VSLIDE_DN << 4) | (t3 & 0x0f); } break; case 0x92: if ((int8)t3 > 0) { fxt = FX_PORTA_DN; fxp = 0xf0 | (fxp & 0x0f); } else { fxt = FX_PORTA_UP; fxp = 0xf0 | (fxp & 0x0f); } break; case 0x93: fxt = FX_EXTENDED; fxp = (EX_DELAY << 4) | (t3 & 0x0f); break; case 0x94: fxt = FX_EXTENDED; fxp = (EX_CUT << 4) | (t3 & 0x0f); break; case 0x95: fxt = FX_SPEED; if (t3 < 0x21) t3 = 0x21; fxp = t3; break; case 0x96: if ((int8)t3 > 0) { fxt = FX_PORTA_DN; fxp = 0xe0 | (fxp & 0x0f); } else { fxt = FX_PORTA_UP; fxp = 0xe0 | (fxp & 0x0f); } break; case 0x97: fxt = FX_SETPAN; fxp = 0x80 + 2 * (int8)t3; break; } event->fxt = fxt; event->fxp = fxp; } } } /* Samples */ D_(D_INFO "Stored samples: %d", mod->smp); for (i = 0; i < mod->ins; i++) { if (load_sample(m, f, SAMPLE_FLAG_UNS, &mod->xxs[i], NULL) < 0) return -1; } m->quirk |= QUIRK_FINEFX; return 0; }
static int stx_load(struct module_data *m, xmp_file f, const int start) { struct xmp_module *mod = &m->mod; int c, r, i, broken = 0; struct xmp_event *event = 0, dummy; struct stx_file_header sfh; struct stx_instrument_header sih; uint8 n, b; uint16 x16; int bmod2stm = 0; uint16 *pp_ins; /* Parapointers to instruments */ uint16 *pp_pat; /* Parapointers to patterns */ LOAD_INIT(); xmp_fread(&sfh.name, 20, 1, f); xmp_fread(&sfh.magic, 8, 1, f); sfh.psize = read16l(f); sfh.unknown1 = read16l(f); sfh.pp_pat = read16l(f); sfh.pp_ins = read16l(f); sfh.pp_chn = read16l(f); sfh.unknown2 = read16l(f); sfh.unknown3 = read16l(f); sfh.gvol = read8(f); sfh.tempo = read8(f); sfh.unknown4 = read16l(f); sfh.unknown5 = read16l(f); sfh.patnum = read16l(f); sfh.insnum = read16l(f); sfh.ordnum = read16l(f); sfh.unknown6 = read16l(f); sfh.unknown7 = read16l(f); sfh.unknown8 = read16l(f); xmp_fread(&sfh.magic2, 4, 1, f); /* BMOD2STM does not convert pitch */ if (!strncmp ((char *) sfh.magic, "BMOD2STM", 8)) bmod2stm = 1; #if 0 if ((strncmp ((char *) sfh.magic, "!Scream!", 8) && !bmod2stm) || strncmp ((char *) sfh.magic2, "SCRM", 4)) return -1; #endif mod->ins = sfh.insnum; mod->pat = sfh.patnum; mod->trk = mod->pat * mod->chn; mod->len = sfh.ordnum; mod->spd = MSN (sfh.tempo); mod->smp = mod->ins; m->c4rate = C4_NTSC_RATE; /* STM2STX 1.0 released with STMIK 0.2 converts STMs with the pattern * length encoded in the first two bytes of the pattern (like S3M). */ xmp_fseek(f, start + (sfh.pp_pat << 4), SEEK_SET); x16 = read16l(f); xmp_fseek(f, start + (x16 << 4), SEEK_SET); x16 = read16l(f); if (x16 == sfh.psize) broken = 1; strncpy(mod->name, (char *)sfh.name, 20); if (bmod2stm) set_type(m, "BMOD2STM STX"); else snprintf(mod->type, XMP_NAME_SIZE, "STM2STX 1.%d", broken ? 0 : 1); MODULE_INFO(); pp_pat = calloc (2, mod->pat); pp_ins = calloc (2, mod->ins); /* Read pattern pointers */ xmp_fseek(f, start + (sfh.pp_pat << 4), SEEK_SET); for (i = 0; i < mod->pat; i++) pp_pat[i] = read16l(f); /* Read instrument pointers */ xmp_fseek(f, start + (sfh.pp_ins << 4), SEEK_SET); for (i = 0; i < mod->ins; i++) pp_ins[i] = read16l(f); /* Skip channel table (?) */ xmp_fseek(f, start + (sfh.pp_chn << 4) + 32, SEEK_SET); /* Read orders */ for (i = 0; i < mod->len; i++) { mod->xxo[i] = read8(f); xmp_fseek(f, 4, SEEK_CUR); } INSTRUMENT_INIT(); /* Read and convert instruments and samples */ for (i = 0; i < mod->ins; i++) { mod->xxi[i].sub = calloc(sizeof (struct xmp_subinstrument), 1); xmp_fseek(f, start + (pp_ins[i] << 4), SEEK_SET); sih.type = read8(f); xmp_fread(&sih.dosname, 13, 1, f); sih.memseg = read16l(f); sih.length = read32l(f); sih.loopbeg = read32l(f); sih.loopend = read32l(f); sih.vol = read8(f); sih.rsvd1 = read8(f); sih.pack = read8(f); sih.flags = read8(f); sih.c2spd = read16l(f); sih.rsvd2 = read16l(f); xmp_fread(&sih.rsvd3, 4, 1, f); sih.int_gp = read16l(f); sih.int_512 = read16l(f); sih.int_last = read32l(f); xmp_fread(&sih.name, 28, 1, f); xmp_fread(&sih.magic, 4, 1, f); mod->xxi[i].nsm = !!(mod->xxs[i].len = sih.length); mod->xxs[i].lps = sih.loopbeg; mod->xxs[i].lpe = sih.loopend; if (mod->xxs[i].lpe == 0xffff) mod->xxs[i].lpe = 0; mod->xxs[i].flg = mod->xxs[i].lpe > 0 ? XMP_SAMPLE_LOOP : 0; mod->xxi[i].sub[0].vol = sih.vol; mod->xxi[i].sub[0].pan = 0x80; mod->xxi[i].sub[0].sid = i; copy_adjust(mod->xxi[i].name, sih.name, 12); D_(D_INFO "[%2X] %-14.14s %04x %04x %04x %c V%02x %5d\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, sih.c2spd); sih.c2spd = 8363 * sih.c2spd / 8448; c2spd_to_note(sih.c2spd, &mod->xxi[i].sub[0].xpo, &mod->xxi[i].sub[0].fin); } PATTERN_INIT(); /* Read and convert patterns */ D_(D_INFO "Stored patterns: %d", mod->pat); for (i = 0; i < mod->pat; i++) { PATTERN_ALLOC (i); mod->xxp[i]->rows = 64; TRACK_ALLOC (i); if (!pp_pat[i]) continue; xmp_fseek(f, start + (pp_pat[i] << 4), SEEK_SET); if (broken) xmp_fseek(f, 2, SEEK_CUR); for (r = 0; r < 64; ) { b = read8(f); if (b == S3M_EOR) { r++; continue; } c = b & S3M_CH_MASK; event = c >= mod->chn ? &dummy : &EVENT (i, c, r); if (b & S3M_NI_FOLLOW) { n = read8(f); switch (n) { case 255: n = 0; break; /* Empty note */ case 254: n = XMP_KEY_OFF; break; /* Key off */ default: n = 37 + 12 * MSN (n) + LSN (n); } event->note = n; event->ins = read8(f);; } if (b & S3M_VOL_FOLLOWS) { event->vol = read8(f) + 1; } if (b & S3M_FX_FOLLOWS) { event->fxt = fx[read8(f)]; event->fxp = read8(f); switch (event->fxt) { case FX_SPEED: event->fxp = MSN (event->fxp); break; case FX_NONE: event->fxp = event->fxt = 0; break; } } } } free (pp_pat); free (pp_ins); /* Read samples */ D_(D_INFO "Stored samples: %d", mod->smp); for (i = 0; i < mod->ins; i++) { load_sample(m, f, 0, &mod->xxs[mod->xxi[i].sub[0].sid], NULL); } m->quirk |= QUIRK_VSALL | QUIRKS_ST3; m->read_event_type = READ_EVENT_ST3; return 0; }
static int stm_load(struct module_data *m, HIO_HANDLE *f, const int start) { struct xmp_module *mod = &m->mod; int i, j; struct xmp_event *event; struct stm_file_header sfh; uint8 b; int bmod2stm = 0; LOAD_INIT(); hio_read(&sfh.name, 20, 1, f); /* ASCIIZ song name */ hio_read(&sfh.magic, 8, 1, f); /* '!Scream!' */ sfh.rsvd1 = hio_read8(f); /* '\x1a' */ sfh.type = hio_read8(f); /* 1=song, 2=module */ sfh.vermaj = hio_read8(f); /* Major version number */ sfh.vermin = hio_read8(f); /* Minor version number */ sfh.tempo = hio_read8(f); /* Playback tempo */ sfh.patterns = hio_read8(f); /* Number of patterns */ sfh.gvol = hio_read8(f); /* Global volume */ hio_read(&sfh.rsvd2, 13, 1, f); /* Reserved */ for (i = 0; i < 31; i++) { hio_read(&sfh.ins[i].name, 12, 1, f); /* ASCIIZ instrument name */ sfh.ins[i].id = hio_read8(f); /* Id=0 */ sfh.ins[i].idisk = hio_read8(f); /* Instrument disk */ sfh.ins[i].rsvd1 = hio_read16l(f); /* Reserved */ sfh.ins[i].length = hio_read16l(f); /* Sample length */ sfh.ins[i].loopbeg = hio_read16l(f); /* Loop begin */ sfh.ins[i].loopend = hio_read16l(f); /* Loop end */ sfh.ins[i].volume = hio_read8(f); /* Playback volume */ sfh.ins[i].rsvd2 = hio_read8(f); /* Reserved */ sfh.ins[i].c2spd = hio_read16l(f); /* C4 speed */ sfh.ins[i].rsvd3 = hio_read32l(f); /* Reserved */ sfh.ins[i].paralen = hio_read16l(f); /* Length in paragraphs */ } if (!strncmp ((char *)sfh.magic, "BMOD2STM", 8)) bmod2stm = 1; mod->pat = sfh.patterns; mod->trk = mod->pat * mod->chn; mod->spd = MSN (sfh.tempo); mod->ins = 31; mod->smp = mod->ins; m->c4rate = C4_NTSC_RATE; copy_adjust(mod->name, sfh.name, 20); if (bmod2stm) { snprintf(mod->type, XMP_NAME_SIZE, "BMOD2STM STM"); } else { snprintf(mod->type, XMP_NAME_SIZE, "Scream Tracker %d.%02d STM", sfh.vermaj, sfh.vermin); } MODULE_INFO(); if (instrument_init(mod) < 0) return -1; /* Read and convert instruments and samples */ for (i = 0; i < mod->ins; i++) { if (subinstrument_alloc(mod, i, 1) < 0) return -1; mod->xxs[i].len = sfh.ins[i].length; mod->xxs[i].lps = sfh.ins[i].loopbeg; mod->xxs[i].lpe = sfh.ins[i].loopend; if (mod->xxs[i].lpe == 0xffff) mod->xxs[i].lpe = 0; mod->xxs[i].flg = mod->xxs[i].lpe > 0 ? XMP_SAMPLE_LOOP : 0; mod->xxi[i].sub[0].vol = sfh.ins[i].volume; mod->xxi[i].sub[0].pan = 0x80; mod->xxi[i].sub[0].sid = i; if (mod->xxs[i].len > 0) mod->xxi[i].nsm = 1; instrument_name(mod, i, sfh.ins[i].name, 12); D_(D_INFO "[%2X] %-14.14s %04x %04x %04x %c V%02x %5d", 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, sfh.ins[i].c2spd); sfh.ins[i].c2spd = 8363 * sfh.ins[i].c2spd / 8448; c2spd_to_note (sfh.ins[i].c2spd, &mod->xxi[i].sub[0].xpo, &mod->xxi[i].sub[0].fin); } hio_read(mod->xxo, 1, 128, f); for (i = 0; i < 128; i++) if (mod->xxo[i] >= mod->pat) break; mod->len = i; D_(D_INFO "Module length: %d", mod->len); if (pattern_init(mod) < 0) return -1; /* Read and convert patterns */ D_(D_INFO "Stored patterns: %d", mod->pat); for (i = 0; i < mod->pat; i++) { if (pattern_tracks_alloc(mod, i, 64) < 0) return -1; for (j = 0; j < 64 * mod->chn; j++) { event = &EVENT (i, j % mod->chn, j / mod->chn); b = hio_read8(f); memset (event, 0, sizeof (struct xmp_event)); switch (b) { case 251: case 252: case 253: break; case 255: b = 0; default: event->note = b ? 13 + LSN(b) + 12 * (2 + MSN(b)) : 0; b = hio_read8(f); event->vol = b & 0x07; event->ins = (b & 0xf8) >> 3; b = hio_read8(f); event->vol += (b & 0xf0) >> 1; if (event->vol > 0x40) event->vol = 0; else event->vol++; event->fxt = fx[LSN(b)]; event->fxp = hio_read8(f); switch (event->fxt) { case FX_SPEED: event->fxp = MSN (event->fxp); break; case FX_NONE: event->fxp = event->fxt = 0; break; } } } } /* Read samples */ D_(D_INFO "Stored samples: %d", mod->smp); for (i = 0; i < mod->ins; i++) { if (mod->xxs[i].len > 1) { if (load_sample(m, f, 0, &mod->xxs[i], NULL) < 0) return -1; } else { mod->xxi[i].nsm = 0; } } m->quirk |= QUIRK_VSALL | QUIRKS_ST3; m->read_event_type = READ_EVENT_ST3; return 0; }
static int gtk_load(struct module_data *m, FILE *f, const int start) { struct xmp_module *mod = &m->mod; struct xmp_event *event; int i, j, k; uint8 buffer[40]; int rows, bits, c2spd, size; int ver, patmax; LOAD_INIT(); fread(buffer, 4, 1, f); ver = buffer[3]; fread(mod->name, 32, 1, f); set_type(m, "Graoumf Tracker GTK v%d", ver); fseek(f, 160, SEEK_CUR); /* skip comments */ mod->ins = read16b(f); mod->smp = mod->ins; rows = read16b(f); mod->chn = read16b(f); mod->len = read16b(f); mod->rst = read16b(f); MODULE_INFO(); D_(D_INFO "Instruments : %d ", mod->ins); INSTRUMENT_INIT(); for (i = 0; i < mod->ins; i++) { mod->xxi[i].sub = calloc(sizeof (struct xmp_subinstrument), 1); fread(buffer, 28, 1, f); copy_adjust(mod->xxi[i].name, buffer, 28); if (ver == 1) { read32b(f); mod->xxs[i].len = read32b(f); mod->xxs[i].lps = read32b(f); size = read32b(f); mod->xxs[i].lpe = mod->xxs[i].lps + size - 1; read16b(f); read16b(f); mod->xxi[i].sub[0].vol = 0x40; mod->xxi[i].sub[0].pan = 0x80; bits = 1; c2spd = 8363; } else { fseek(f, 14, SEEK_CUR); read16b(f); /* autobal */ bits = read16b(f); /* 1 = 8 bits, 2 = 16 bits */ c2spd = read16b(f); c2spd_to_note(c2spd, &mod->xxi[i].sub[0].xpo, &mod->xxi[i].sub[0].fin); mod->xxs[i].len = read32b(f); mod->xxs[i].lps = read32b(f); size = read32b(f); mod->xxs[i].lpe = mod->xxs[i].lps + size - 1; mod->xxi[i].sub[0].vol = read16b(f) / 4; read8(f); mod->xxi[i].sub[0].fin = read8s(f); } mod->xxi[i].nsm = !!mod->xxs[i].len; mod->xxi[i].sub[0].sid = i; mod->xxs[i].flg = size > 2 ? XMP_SAMPLE_LOOP : 0; if (bits > 1) { mod->xxs[i].flg |= XMP_SAMPLE_16BIT; mod->xxs[i].len >>= 1; mod->xxs[i].lps >>= 1; mod->xxs[i].lpe >>= 1; } D_(D_INFO "[%2X] %-28.28s %05x%c%05x %05x %c " "V%02x F%+03d %5d", i, mod->xxi[i].name, mod->xxs[i].len, bits > 1 ? '+' : ' ', mod->xxs[i].lps, size, mod->xxs[i].flg & XMP_SAMPLE_LOOP ? 'L' : ' ', mod->xxi[i].sub[0].vol, mod->xxi[i].sub[0].fin, c2spd); }
static int gdm_load(struct xmp_context *ctx, FILE *f, const int start) { struct xmp_player_context *p = &ctx->p; struct xmp_mod_context *m = &p->m; struct xxm_event *event; int vermaj, vermin, tvmaj, tvmin, tracker; int origfmt, ord_ofs, pat_ofs, ins_ofs, smp_ofs; uint8 buffer[32], panmap[32]; int i; LOAD_INIT(); read32b(f); /* skip magic */ fread(m->name, 1, 32, f); fread(m->author, 1, 32, f); fseek(f, 7, SEEK_CUR); vermaj = read8(f); vermin = read8(f); tracker = read16l(f); tvmaj = read8(f); tvmin = read8(f); if (tracker == 0) { sprintf(m->type, "GDM %d.%02d, (2GDM %d.%02d)", vermaj, vermin, tvmaj, tvmin); } else { sprintf(m->type, "GDM %d.%02d (unknown tracker %d.%02d)", vermaj, vermin, tvmaj, tvmin); } fread(panmap, 32, 1, f); for (i = 0; i < 32; i++) { if (panmap[i] != 0xff) m->xxh->chn = i + 1; if (panmap[i] == 16) panmap[i] = 8; m->xxc[i].pan = 0x80 + (panmap[i] - 8) * 16; } m->xxh->gvl = read8(f); m->xxh->tpo = read8(f); m->xxh->bpm = read8(f); origfmt = read16l(f); ord_ofs = read32l(f); m->xxh->len = read8(f); pat_ofs = read32l(f); m->xxh->pat = read8(f); ins_ofs = read32l(f); smp_ofs = read32l(f); m->xxh->ins = m->xxh->smp = read8(f); m->xxh->trk = m->xxh->pat * m->xxh->chn; MODULE_INFO(); if (origfmt > 9) origfmt = 9; reportv(ctx, 0, "Orig format : %s\n", fmt[origfmt]); fseek(f, start + ord_ofs, SEEK_SET); for (i = 0; i < m->xxh->len; i++) m->xxo[i] = read8(f); /* Read instrument data */ fseek(f, start + ins_ofs, SEEK_SET); INSTRUMENT_INIT(); reportv(ctx, 1, " Name Len LBeg LEnd L Vol Pan C4Spd\n"); for (i = 0; i < m->xxh->ins; i++) { int flg, c4spd, vol, pan; m->xxi[i] = calloc(sizeof(struct xxm_instrument), 1); fread(buffer, 32, 1, f); copy_adjust(m->xxih[i].name, buffer, 32); fseek(f, 12, SEEK_CUR); /* skip filename */ read8(f); /* skip EMS handle */ m->xxs[i].len = read32l(f); m->xxs[i].lps = read32l(f); m->xxs[i].lpe = read32l(f); flg = read8(f); c4spd = read16l(f); vol = read8(f); pan = read8(f); m->xxi[i][0].vol = vol > 0x40 ? 0x40 : vol; m->xxi[i][0].pan = pan > 15 ? 0x80 : 0x80 + (pan - 8) * 16; c2spd_to_note(c4spd, &m->xxi[i][0].xpo, &m->xxi[i][0].fin); m->xxih[i].nsm = !!(m->xxs[i].len); m->xxi[i][0].sid = i; m->xxs[i].flg = 0; if (flg & 0x01) m->xxs[i].flg |= WAVE_LOOPING; if (flg & 0x02) m->xxs[i].flg |= WAVE_16_BITS; if (V(1) && (strlen((char*)m->xxih[i].name) || (m->xxs[i].len > 1))) { report("[%2X] %-32.32s %05x%c%05x %05x %c V%02x P%02x %5d\n", i, m->xxih[i].name, m->xxs[i].len, m->xxs[i].flg & WAVE_16_BITS ? '+' : ' ', m->xxs[i].lps, m->xxs[i].lpe, m->xxs[i].flg & WAVE_LOOPING ? 'L' : ' ', m->xxi[i][0].vol, m->xxi[i][0].pan, c4spd); } } /* Read and convert patterns */ fseek(f, start + pat_ofs, SEEK_SET); PATTERN_INIT(); reportv(ctx, 0, "Stored patterns: %d ", m->xxh->pat); for (i = 0; i < m->xxh->pat; i++) { int len, c, r, k; PATTERN_ALLOC(i); m->xxp[i]->rows = 64; TRACK_ALLOC(i); len = read16l(f); len -= 2; for (r = 0; len > 0; ) { c = read8(f); len--; if (c == 0) { r++; continue; } assert((c & 0x1f) < m->xxh->chn); event = &EVENT (i, c & 0x1f, r); if (c & 0x20) { /* note and sample follows */ k = read8(f); event->note = 12 * MSN(k & 0x7f) + LSN(k); event->ins = read8(f); len -= 2; } if (c & 0x40) { /* effect(s) follow */ do { k = read8(f); len--; switch ((k & 0xc0) >> 6) { case 0: event->fxt = k & 0x1f; event->fxp = read8(f); len--; fix_effect(&event->fxt, &event->fxp); break; case 1: event->f2t = k & 0x1f; event->f2p = read8(f); len--; fix_effect(&event->f2t, &event->f2p); break; case 2: read8(f); len--; } } while (k & 0x20); } } reportv(ctx, 0, "."); } reportv(ctx, 0, "\n"); /* Read samples */ fseek(f, start + smp_ofs, SEEK_SET); reportv(ctx, 0, "Stored samples : %d ", m->xxh->smp); for (i = 0; i < m->xxh->ins; i++) { xmp_drv_loadpatch(ctx, f, m->xxi[i][0].sid, m->c4rate, XMP_SMP_UNS, &m->xxs[m->xxi[i][0].sid], NULL); reportv(ctx, 0, "."); } reportv(ctx, 0, "\n"); return 0; }