static int coco_load(struct module_data *m, FILE *f, const int start) { struct xmp_module *mod = &m->mod; struct xmp_event *event; int i, j; int seq_ptr, pat_ptr, smp_ptr[100]; LOAD_INIT(); mod->chn = read8(f) & 0x3f; read_title(f, mod->name, 20); for (i = 0; i < 20; i++) { if (mod->name[i] == 0x0d) mod->name[i] = 0; } set_type(m, "Coconizer"); mod->ins = mod->smp = read8(f); mod->len = read8(f); mod->pat = read8(f); mod->trk = mod->pat * mod->chn; seq_ptr = read32l(f); pat_ptr = read32l(f); MODULE_INFO(); INSTRUMENT_INIT(); m->vol_table = (int *)arch_vol_table; m->volbase = 0xff; for (i = 0; i < mod->ins; i++) { mod->xxi[i].sub = calloc(sizeof (struct xmp_subinstrument), 1); smp_ptr[i] = read32l(f); mod->xxs[i].len = read32l(f); mod->xxi[i].sub[0].vol = 0xff - read32l(f); mod->xxi[i].sub[0].pan = 0x80; mod->xxs[i].lps = read32l(f); mod->xxs[i].lpe = mod->xxs[i].lps + read32l(f); if (mod->xxs[i].lpe) mod->xxs[i].lpe -= 1; mod->xxs[i].flg = mod->xxs[i].lps > 0 ? XMP_SAMPLE_LOOP : 0; fread(mod->xxi[i].name, 1, 11, f); for (j = 0; j < 11; j++) { if (mod->xxi[i].name[j] == 0x0d) mod->xxi[i].name[j] = 0; } read8(f); /* unused */ mod->xxi[i].nsm = !!mod->xxs[i].len; mod->xxi[i].sub[0].sid = i; D_(D_INFO "[%2X] %-10.10s %05x %05x %05x %c V%02x", 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); } /* Sequence */ fseek(f, start + seq_ptr, SEEK_SET); for (i = 0; ; i++) { uint8 x = read8(f); if (x == 0xff) break; mod->xxo[i] = x; } for (i++; i % 4; i++) /* for alignment */ read8(f); /* Patterns */ PATTERN_INIT(); 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); for (j = 0; j < (64 * mod->chn); j++) { event = &EVENT (i, j % mod->chn, j / mod->chn); event->fxp = read8(f); event->fxt = read8(f); event->ins = read8(f); event->note = read8(f); if (event->note) event->note += 12; fix_effect(event); } } /* Read samples */ D_(D_INFO "Stored samples : %d", mod->smp); for (i = 0; i < mod->ins; i++) { if (mod->xxi[i].nsm == 0) continue; fseek(f, start + smp_ptr[i], SEEK_SET); load_sample(f, SAMPLE_FLAG_VIDC, &mod->xxs[mod->xxi[i].sub[0].sid], NULL); } for (i = 0; i < mod->chn; i++) mod->xxc[i].pan = (((i + 3) / 2) % 2) * 0xff; return 0; }
static int coco_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 seq_ptr, pat_ptr, smp_ptr[100]; LOAD_INIT(); mod->chn = hio_read8(f) & 0x3f; libxmp_read_title(f, mod->name, 20); for (i = 0; i < 20; i++) { if (mod->name[i] == 0x0d) mod->name[i] = 0; } libxmp_set_type(m, "Coconizer"); mod->ins = mod->smp = hio_read8(f); mod->len = hio_read8(f); mod->pat = hio_read8(f); mod->trk = mod->pat * mod->chn; seq_ptr = hio_read32l(f); pat_ptr = hio_read32l(f); MODULE_INFO(); if (libxmp_init_instrument(m) < 0) return -1; m->vol_table = (int *)arch_vol_table; m->volbase = 0xff; for (i = 0; i < mod->ins; i++) { if (libxmp_alloc_subinstrument(mod, i, 1) < 0) return -1; smp_ptr[i] = hio_read32l(f); mod->xxs[i].len = hio_read32l(f); mod->xxi[i].sub[0].vol = 0xff - hio_read32l(f); mod->xxi[i].sub[0].pan = 0x80; mod->xxs[i].lps = hio_read32l(f); mod->xxs[i].lpe = mod->xxs[i].lps + hio_read32l(f); if (mod->xxs[i].lpe) mod->xxs[i].lpe -= 1; mod->xxs[i].flg = mod->xxs[i].lps > 0 ? XMP_SAMPLE_LOOP : 0; hio_read(mod->xxi[i].name, 1, 11, f); for (j = 0; j < 11; j++) { if (mod->xxi[i].name[j] == 0x0d) mod->xxi[i].name[j] = 0; } hio_read8(f); /* unused */ mod->xxi[i].sub[0].sid = i; if (mod->xxs[i].len > 0) mod->xxi[i].nsm = 1; D_(D_INFO "[%2X] %-10.10s %05x %05x %05x %c V%02x", 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); } /* Sequence */ hio_seek(f, start + seq_ptr, SEEK_SET); for (i = 0; ; i++) { uint8 x = hio_read8(f); if (x == 0xff) break; mod->xxo[i] = x; } for (i++; i % 4; i++) /* for alignment */ hio_read8(f); /* Patterns */ if (libxmp_init_pattern(mod) < 0) return -1; D_(D_INFO "Stored patterns: %d", mod->pat); for (i = 0; i < mod->pat; i++) { if (libxmp_alloc_pattern_tracks(mod, i, 64) < 0) return -1; for (j = 0; j < (64 * mod->chn); j++) { event = &EVENT (i, j % mod->chn, j / mod->chn); event->fxp = hio_read8(f); event->fxt = hio_read8(f); event->ins = hio_read8(f); event->note = hio_read8(f); if (event->note) event->note += 12; fix_effect(event); } } /* 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 + smp_ptr[i], SEEK_SET); if (libxmp_load_sample(m, f, SAMPLE_FLAG_VIDC, &mod->xxs[i], NULL) < 0) return -1; } for (i = 0; i < mod->chn; i++) { mod->xxc[i].pan = DEFPAN((((i + 3) / 2) % 2) * 0xff); } return 0; }
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; }