/*========== Loader code */ bool LoadModuleHeader(M15ModuleHeader mh) { int t, u; mh.songname = m_Reader.Read_String(20); /* sanity check : title should contain printable characters and a bunch * of null chars */ for (t = 0; t < mh.songname.Length; t++) { if ((mh.songname[t] != 0) && (mh.songname[t] < 32)) { return(false); } } for (t = 0; (t < mh.songname.Length) && (mh.songname[t] != 0); t++) { ; } if (t < 20) { for (; t < mh.songname.Length; t++) { if (mh.songname[t] != 0) { return(false); } } } for (t = 0; t < 15; t++) { M15SampleInfo s = mh.samples[t]; s.samplename = m_Reader.Read_String(22); s.length = m_Reader.Read_Motorola_ushort(); s.finetune = m_Reader.Read_byte(); s.volume = m_Reader.Read_byte(); s.reppos = m_Reader.Read_Motorola_ushort(); s.replen = m_Reader.Read_Motorola_ushort(); /* sanity check : sample title should contain printable characters and * a bunch of null chars */ for (u = 0; u < s.samplename.Length; u++) { if ((s.samplename[u] != 0) && (s.samplename[u] < /*32*/ 14)) { return(false); } } for (u = 0; (u < s.samplename.Length) && (s.samplename[u] != 0); u++) { ; } if (u < 20) { for (; u < s.samplename.Length; u++) { if (s.samplename[u] != 0) { return(false); } } } /* sanity check : finetune values */ if ((s.finetune >> 4) != 0) { return(false); } } mh.songlength = m_Reader.Read_byte(); mh.magic1 = m_Reader.Read_byte(); /* should be 127 */ /* sanity check : no more than 128 positions, restart position in range */ if ((mh.songlength == 0) || (mh.songlength > 128)) { return(false); } /* values encountered so far are 0x6a and 0x78 */ if (((mh.magic1 & 0xf8) != 0x78) && (mh.magic1 != 0x6a) && (mh.magic1 > mh.songlength)) { return(false); } m_Reader.Read_bytes(mh.positions, 128); /* sanity check : pattern range is 0..63 */ for (t = 0; t < 128; t++) { if (mh.positions[t] > 63) { return(false); } } return(!m_Reader.isEOF()); }
public override bool Test() { int t, numpat; mh = new M15ModuleHeader(); ust_loader = false; if (!LoadModuleHeader(mh)) { return(false); } /* reject other file types */ for (t = 0; t < REJECT; t++) { if (mh.songname == signatures[t]) { mh = null; return(false); } } if (mh.magic1 > 127) { return(false); } if ((mh.songlength == 0) || (mh.songlength > mh.magic1)) { return(false); } for (t = 0; t < 15; t++) { /* all finetunes should be zero */ if (mh.samples[t].finetune != 0) { return(false); } /* all volumes should be <= 64 */ if (mh.samples[t].volume > 64) { return(false); } /* all instrument names should begin with s, st-, or a number */ if (mh.samples[t].samplename.Length > 0 && (mh.samples[t].samplename[0] == 's' || mh.samples[t].samplename[0] == 'S')) { if (!String.IsNullOrEmpty(mh.samples[t].samplename) && !mh.samples[t].samplename.StartsWith("st-") && !mh.samples[t].samplename.StartsWith("ST-")) { ust_loader = true; } } else { if (mh.samples[t].samplename.Length == 0 || (mh.samples[t].samplename.Length > 0 && !char.IsDigit(mh.samples[t].samplename[0]))) { ust_loader = true; } } if (mh.samples[t].length > 4999 || mh.samples[t].reppos > 9999) { ust_loader = false; if (mh.samples[t].length > 32768) { return(false); } } /* if loop information is incorrect as words, but correct as bytes, * this is likely to be an ust-style module */ if ((mh.samples[t].reppos + mh.samples[t].replen > mh.samples[t].length) && (mh.samples[t].reppos + mh.samples[t].replen < (mh.samples[t].length << 1))) { ust_loader = true; return(true); } if (!ust_loader) { return(true); } } for (numpat = 0, t = 0; t < mh.songlength; t++) { if (mh.positions[t] > numpat) { numpat = mh.positions[t]; } } numpat++; switch (CheckPatternType(numpat)) { case 0: /* indecisive, so check more clues... */ break; case 1: ust_loader = true; break; case 2: ust_loader = false; break; } return(true); }
public override void Cleanup() { patbuf = null; mh = null; }
public override bool Init() { mh = new M15ModuleHeader(); return(true); }