Ejemplo n.º 1
0
            public M15ModuleHeader()
            {
                samples = new M15SampleInfo[15];

                for (int i = 0; i < samples.Length; i++)
                {
                    samples[i] = new M15SampleInfo();
                }

                positions = new byte[128];
            }
Ejemplo n.º 2
0
        /*========== 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());
        }