Exemple #1
0
        public static SidTuneBase load(string fileName, byte[] dataBuf)
        {
            string ext = SidTuneTools.fileExtOfPath(fileName);

            if ((ext != ".prg") &&
                (ext != ".c64"))
            {
                return(null);
            }

            if (dataBuf.Length < 2)
            {
                throw new loadError(ERR_TRUNCATED);
            }

            prg tune = new prg();

            tune.load();

            return(tune);
        }
Exemple #2
0
        public static SidTuneBase load(string fileName, byte[] dataBuf)
        {
            string ext = SidTuneTools.fileExtOfPath(fileName);

            // Combined extension & magic field identification
            if (ext.Length != 4)
            {
                return(null);
            }

            //if (!isdigit(ext[2]) || !isdigit(ext[3]))
            //return null;
            if ("0123456789".IndexOf(ext[2]) < 0 || "0123456789".IndexOf(ext[3]) < 0)
            {
                return(null);
            }

            string    format = null;
            X00Format type;

            switch (ext[1].ToString().ToUpper()[0])
            {
            case 'D':
                type   = X00Format.X00_DEL;
                format = TXT_FORMAT_DEL;
                break;

            case 'S':
                type   = X00Format.X00_SEQ;
                format = TXT_FORMAT_SEQ;
                break;

            case 'P':
                type   = X00Format.X00_PRG;
                format = TXT_FORMAT_PRG;
                break;

            case 'U':
                type   = X00Format.X00_USR;
                format = TXT_FORMAT_USR;
                break;

            case 'R':
                type   = X00Format.X00_REL;
                format = TXT_FORMAT_REL;
                break;

            default:
                return(null);
            }

            // Verify the file is what we think it is
            Int32 bufLen = dataBuf.Length;

            if (bufLen < X00_ID_LEN)
            {
                return(null);
            }

            X00Header pHeader = new X00Header();

            mem.memcpy(ref pHeader.id, dataBuf, X00_ID_LEN);
            Ptr <byte> p = new Ptr <byte>(pHeader.name, 0);

            mem.memcpy(ref p, new Ptr <byte>(dataBuf, X00_ID_LEN), X00_NAME_LEN);
            pHeader.length = dataBuf[X00_ID_LEN + X00_NAME_LEN];

            if (Encoding.ASCII.GetString(pHeader.id) == P00_ID)
            {
                return(null);
            }

            // File types current supported
            if (type != X00Format.X00_PRG)
            {
                throw new loadError("Not a PRG inside X00");
            }

            if (bufLen < 26 + 2)//sizeof(X00Header) + 2)
            {
                throw new loadError(ERR_TRUNCATED);
            }

            p00 tune = new p00();

            tune.load(Encoding.ASCII.GetBytes(format), pHeader);

            return(tune);
        }
        protected virtual void acceptSidTune(string dataFileName, string infoFileName, ref List <byte> buf, bool isSlashedFileName)
        {
            // Make a copy of the data file name and path, if available.
            if (dataFileName != null)
            {
                Int32 fileNamePos = (Int32)(isSlashedFileName ?
                                            SidTuneTools.slashedFileNameWithoutPath(dataFileName) :
                                            SidTuneTools.fileNameWithoutPath(dataFileName));
                info.m_path         = dataFileName.Substring(0, fileNamePos);
                info.m_dataFileName = dataFileName.Substring(fileNamePos);
            }

            // Make a copy of the info file name, if available.
            if (infoFileName != null)
            {
                Int32 fileNamePos = (Int32)(isSlashedFileName ?
                                            SidTuneTools.slashedFileNameWithoutPath(infoFileName) :
                                            SidTuneTools.fileNameWithoutPath(infoFileName));
                info.m_infoFileName = infoFileName.Substring(fileNamePos);
            }

            // Fix bad sidtune set up.
            if (info.m_songs > MAX_SONGS)
            {
                info.m_songs = MAX_SONGS;
            }
            else if (info.m_songs == 0)
            {
                info.m_songs = 1;
            }

            if (info.m_startSong == 0 ||
                info.m_startSong > info.m_songs)
            {
                info.m_startSong = 1;
            }

            info.m_dataFileLen = (UInt32)buf.Count;
            info.m_c64dataLen  = (UInt32)(buf.Count - fileOffset);

            // Calculate any remaining addresses and then
            // confirm all the file details are correct
            resolveAddrs(buf, (Int32)fileOffset);

            if (checkRelocInfo() == false)
            {
                throw new loadError(ERR_BAD_RELOC);
            }
            if (checkCompatibility() == false)
            {
                throw new loadError(ERR_BAD_ADDR);
            }

            if (info.m_dataFileLen >= 2)
            {
                // We only detect an offset of two. Some position independent
                // sidtunes contain a load address of 0xE000, but are loaded
                // to 0x0FFE and call player at 0x1000.
                info.m_fixLoad = (sidendian.endian_little16(new Ptr <byte>(buf.ToArray(), (Int32)fileOffset)) == (info.m_loadAddr + 2));
            }

            // Check the size of the data.
            if (info.m_c64dataLen > MAX_MEMORY)
            {
                throw new loadError(ERR_DATA_TOO_LONG);
            }
            else if (info.m_c64dataLen == 0)
            {
                throw new loadError(ERR_EMPTY);
            }

            cache = new List <byte>(buf);
        }