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 alm_load(struct module_data *m, HIO_HANDLE *f, const int start) { struct xmp_module *mod = &m->mod; int i, j; struct alm_file_header afh; struct xmp_event *event; struct stat stat; uint8 b; char *basename; char filename[NAME_SIZE]; char modulename[NAME_SIZE]; LOAD_INIT(); hio_read(&afh.id, 7, 1, f); if (!strncmp((char *)afh.id, "ALEYMOD", 7)) /* Version 1.0 */ mod->spd = afh.speed / 2; strncpy(modulename, m->filename, NAME_SIZE); basename = strtok (modulename, "."); afh.speed = hio_read8(f); afh.length = hio_read8(f); afh.restart = hio_read8(f); hio_read(&afh.order, 128, 1, f); mod->len = afh.length; mod->rst = afh.restart; memcpy (mod->xxo, afh.order, mod->len); for (mod->pat = i = 0; i < mod->len; i++) if (mod->pat < afh.order[i]) mod->pat = afh.order[i]; mod->pat++; mod->ins = 31; mod->trk = mod->pat * mod->chn; mod->smp = mod->ins; m->c4rate = C4_NTSC_RATE; set_type(m, "Aley's Module"); MODULE_INFO(); 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); if (b) event->note = (b == 37) ? 0x61 : b + 48; event->ins = hio_read8(f); } } if (instrument_init(mod) < 0) return -1; /* Read and convert instruments and samples */ D_(D_INFO "Loading samples: %d", mod->ins); for (i = 0; i < mod->ins; i++) { HIO_HANDLE *s; if (subinstrument_alloc(mod, i, 1) < 0) return -1; mod->xxi[i].sub = calloc(sizeof (struct xmp_subinstrument), 1); snprintf(filename, NAME_SIZE, "%s.%d", basename, i + 1); s = hio_open(filename, "rb"); if (s == NULL) continue; mod->xxi[i].nsm = 1; hio_stat(s, &stat); b = hio_read8(s); /* Get first octet */ mod->xxs[i].len = stat.st_size - 5 * !b; if (!b) { /* Instrument with header */ mod->xxs[i].lps = hio_read16l(f); mod->xxs[i].lpe = hio_read16l(f); mod->xxs[i].flg = mod->xxs[i].lpe > mod->xxs[i].lps ? XMP_SAMPLE_LOOP : 0; } else { hio_seek(s, 0, SEEK_SET); } mod->xxi[i].sub[0].pan = 0x80; mod->xxi[i].sub[0].vol = 0x40; mod->xxi[i].sub[0].sid = i; D_(D_INFO "[%2X] %-14.14s %04x %04x %04x %c V%02x", i, filename, 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); if (load_sample(m, s, SAMPLE_FLAG_UNS, &mod->xxs[i], NULL) < 0) return -1; hio_close(s); } /* ALM is LRLR, not LRRL */ for (i = 0; i < mod->chn; i++) mod->xxc[i].pan = DEFPAN((i % 2) * 0xff); return 0; }