diff options
Diffstat (limited to 'plugins/adplug/adplug/s3m.cpp')
-rw-r--r-- | plugins/adplug/adplug/s3m.cpp | 192 |
1 files changed, 103 insertions, 89 deletions
diff --git a/plugins/adplug/adplug/s3m.cpp b/plugins/adplug/adplug/s3m.cpp index ff0baa35..173a7563 100644 --- a/plugins/adplug/adplug/s3m.cpp +++ b/plugins/adplug/adplug/s3m.cpp @@ -22,7 +22,8 @@ * Extra Fine Slides (EEx, FEx) & Fine Vibrato (Uxy) are inaccurate */ -#include <cstring> +#include <stdio.h> +#include <string.h> #include "s3m.h" const char Cs3mPlayer::chnresolv[] = // S3M -> adlib channel conversion @@ -56,97 +57,109 @@ Cs3mPlayer::Cs3mPlayer(Copl *newopl): CPlayer(newopl) } } -bool Cs3mPlayer::load(const std::string &filename, const CFileProvider &fp) +bool Cs3mPlayer::load(const char *filename, const CFileProvider &fp) { - binistream *f = fp.open(filename); if(!f) return false; - unsigned short insptr[99],pattptr[99]; - int i,row; - unsigned char bufval,bufval2; - unsigned short ppatlen; - s3mheader *checkhead; - bool adlibins=false; - - // file validation section - checkhead = new s3mheader; - load_header(f, checkhead); - if(checkhead->kennung != 0x1a || checkhead->typ != 16 - || checkhead->insnum > 99) { - delete checkhead; fp.close(f); return false; - } else - if(strncmp(checkhead->scrm,"SCRM",4)) { - delete checkhead; fp.close(f); return false; - } else { // is an adlib module? - f->seek(checkhead->ordnum, binio::Add); - for(i = 0; i < checkhead->insnum; i++) - insptr[i] = f->readInt(2); - for(i=0;i<checkhead->insnum;i++) { - f->seek(insptr[i]*16); - if(f->readInt(1) >= 2) { - adlibins = true; - break; - } - } - delete checkhead; - if(!adlibins) { fp.close(f); return false; } + binistream *f = fp.open(filename); + if(!f) { + return false; + } + unsigned short insptr[99],pattptr[99]; + int i,row; + unsigned char bufval,bufval2; + unsigned short ppatlen; + s3mheader *checkhead; + bool adlibins=false; + + // file validation section + checkhead = new s3mheader; + load_header(f, checkhead); + if(checkhead->kennung != 0x1a || checkhead->typ != 16 + || checkhead->insnum > 99) { + delete checkhead; + fp.close(f); + return false; + } else + if(strncmp(checkhead->scrm,"SCRM",4)) { + delete checkhead; + fp.close(f); + return false; + } else { // is an adlib module? + f->seek(checkhead->ordnum, binio::Add); + for(i = 0; i < checkhead->insnum; i++) { + insptr[i] = f->readInt(2); + } + for(i=0;i<checkhead->insnum;i++) { + f->seek(insptr[i]*16); + int n = f->readInt(1); + if(n >= 2) { + adlibins = true; + break; + } + } + delete checkhead; + if(!adlibins) { + fp.close(f); + return false; + } + } + + // load section + f->seek(0); // rewind for load + load_header(f, &header); // read header + + // security check + if(header.ordnum > 256 || header.insnum > 99 || header.patnum > 99) { + fp.close(f); + return false; } - // load section - f->seek(0); // rewind for load - load_header(f, &header); // read header - - // security check - if(header.ordnum > 256 || header.insnum > 99 || header.patnum > 99) { - fp.close(f); - return false; - } - - for(i = 0; i < header.ordnum; i++) orders[i] = f->readInt(1); // read orders - for(i = 0; i < header.insnum; i++) insptr[i] = f->readInt(2); // instrument parapointers - for(i = 0; i < header.patnum; i++) pattptr[i] = f->readInt(2); // pattern parapointers - - for(i=0;i<header.insnum;i++) { // load instruments - f->seek(insptr[i]*16); - inst[i].type = f->readInt(1); - f->readString(inst[i].filename, 15); - inst[i].d00 = f->readInt(1); inst[i].d01 = f->readInt(1); - inst[i].d02 = f->readInt(1); inst[i].d03 = f->readInt(1); - inst[i].d04 = f->readInt(1); inst[i].d05 = f->readInt(1); - inst[i].d06 = f->readInt(1); inst[i].d07 = f->readInt(1); - inst[i].d08 = f->readInt(1); inst[i].d09 = f->readInt(1); - inst[i].d0a = f->readInt(1); inst[i].d0b = f->readInt(1); - inst[i].volume = f->readInt(1); inst[i].dsk = f->readInt(1); - f->ignore(2); - inst[i].c2spd = f->readInt(4); - f->ignore(12); - f->readString(inst[i].name, 28); - f->readString(inst[i].scri, 4); - } + for(i = 0; i < header.ordnum; i++) orders[i] = f->readInt(1); // read orders + for(i = 0; i < header.insnum; i++) insptr[i] = f->readInt(2); // instrument parapointers + for(i = 0; i < header.patnum; i++) pattptr[i] = f->readInt(2); // pattern parapointers + + for(i=0;i<header.insnum;i++) { // load instruments + f->seek(insptr[i]*16); + inst[i].type = f->readInt(1); + f->readString(inst[i].filename, 15); + inst[i].d00 = f->readInt(1); inst[i].d01 = f->readInt(1); + inst[i].d02 = f->readInt(1); inst[i].d03 = f->readInt(1); + inst[i].d04 = f->readInt(1); inst[i].d05 = f->readInt(1); + inst[i].d06 = f->readInt(1); inst[i].d07 = f->readInt(1); + inst[i].d08 = f->readInt(1); inst[i].d09 = f->readInt(1); + inst[i].d0a = f->readInt(1); inst[i].d0b = f->readInt(1); + inst[i].volume = f->readInt(1); inst[i].dsk = f->readInt(1); + f->ignore(2); + inst[i].c2spd = f->readInt(4); + f->ignore(12); + f->readString(inst[i].name, 28); + f->readString(inst[i].scri, 4); + } - for(i=0;i<header.patnum;i++) { // depack patterns - f->seek(pattptr[i]*16); - ppatlen = f->readInt(2); - unsigned long pattpos = f->pos(); - for(row=0;(row<64) && (pattpos-pattptr[i]*16<=ppatlen);row++) - do { - bufval = f->readInt(1); - if(bufval & 32) { - bufval2 = f->readInt(1); - pattern[i][row][bufval & 31].note = bufval2 & 15; - pattern[i][row][bufval & 31].oct = (bufval2 & 240) >> 4; - pattern[i][row][bufval & 31].instrument = f->readInt(1); - } - if(bufval & 64) - pattern[i][row][bufval & 31].volume = f->readInt(1); - if(bufval & 128) { - pattern[i][row][bufval & 31].command = f->readInt(1); - pattern[i][row][bufval & 31].info = f->readInt(1); - } - } while(bufval); - } + for(i=0;i<header.patnum;i++) { // depack patterns + f->seek(pattptr[i]*16); + ppatlen = f->readInt(2); + unsigned long pattpos = f->pos(); + for(row=0;(row<64) && (pattpos-pattptr[i]*16<=ppatlen);row++) + do { + bufval = f->readInt(1); + if(bufval & 32) { + bufval2 = f->readInt(1); + pattern[i][row][bufval & 31].note = bufval2 & 15; + pattern[i][row][bufval & 31].oct = (bufval2 & 240) >> 4; + pattern[i][row][bufval & 31].instrument = f->readInt(1); + } + if(bufval & 64) + pattern[i][row][bufval & 31].volume = f->readInt(1); + if(bufval & 128) { + pattern[i][row][bufval & 31].command = f->readInt(1); + pattern[i][row][bufval & 31].info = f->readInt(1); + } + } while(bufval); + } - fp.close(f); - rewind(0); - return true; // done + fp.close(f); + rewind(0); + return true; // done } bool Cs3mPlayer::update() @@ -404,7 +417,7 @@ void Cs3mPlayer::rewind(int subsong) opl->write(1,32); // Go to ym3812 mode } -std::string Cs3mPlayer::gettype() +const char * Cs3mPlayer::gettype() { char filever[5]; @@ -416,7 +429,8 @@ std::string Cs3mPlayer::gettype() default: strcpy(filever,"3.??"); } - return (std::string("Scream Tracker ") + filever); + snprintf (filetype, sizeof (filetype), "Scream Tracker %s", filever); + return filetype; } float Cs3mPlayer::getrefresh() |