/// <summary> /// Support for OR-ing two LoadStatus enums /// </summary> /// <param name="support"></param> /// <param name="support2"></param> /// <returns></returns> /* * private LoadStatus orStatus(LoadStatus support, LoadStatus support2) * { * int val1 = (support == LoadStatus.LOAD_NOT_MINE) ? 0 : (support == LoadStatus.LOAD_OK) ? 1 : 2; * int val2 = (support2 == LoadStatus.LOAD_NOT_MINE) ? 0 : (support2 == LoadStatus.LOAD_OK) ? 1 : 2; * int erg = val1 | val2; * return (erg == 0) ? LoadStatus.LOAD_NOT_MINE : (erg == 1) ? LoadStatus.LOAD_OK : LoadStatus.LOAD_ERROR; * } */ /// <summary> /// Prepare cache for injected program /// </summary> /// <param name="Data"></param> /// <param name="DataStartAddress"></param> /// <returns></returns> public bool InjectProgramInMemory(byte[] Data, int DataStartAddress) { info.songs = 1; info.startSong = 1; info.dataFileLen = Data.Length; info.c64dataLen = Data.Length; // Check the size of the data. if (info.c64dataLen > SIDTUNE_MAX_MEMORY) { //info.statusstring = txt_dataTooLong; return(false); } else if (info.c64dataLen == 0) { //info.statusstring = txt_empty; return(false); } short[] weirdData = new short[Data.Length]; for (int i = 0; i < Data.Length; ++i) { weirdData[i] = Data[i]; } cache.assign(weirdData, weirdData.Length); //info.statusstring = txt_noErrors; return(true); }
/// <summary> /// Does not affect status of object, and therefore can be used to load /// files. Error string is put into info.statusstring, though /// </summary> /// <param name="fileName"></param> /// <param name="bufferRef"></param> /// <returns></returns> public bool loadFile(Stream stream, Buffer_sidtt bufferRef) { Buffer_sidtt fileBuf = new Buffer_sidtt(); int fileLen = 0; try { using (BinaryReader myIn = new BinaryReader(stream)) { fileLen = (int)stream.Length; if (!fileBuf.assign(new short[fileLen], fileLen)) { //info.statusstring = txt_notEnoughMemory; return(false); } int restFileLen = fileLen; if (restFileLen > 0) { for (int i = 0; i < fileLen; i++) { fileBuf.buf[i] = (short)myIn.ReadByte(); } } } } catch { //info.statusstring = txt_cantLoadFile; return(false); } if (fileLen == 0) { //info.statusstring = txt_empty; return(false); } if (decompressPP20(fileBuf) < 0) { return(false); } bufferRef.assign(fileBuf.xferPtr(), fileBuf.xferLen()); return(true); }
/// <summary> /// /// </summary> /// <param name="buf"></param> /// <returns>0 for no decompression (buf unchanged), 1 for decompression and -1 for error</returns> private int decompressPP20(Buffer_sidtt buf) { // Check for PowerPacker compression: load and decompress, if PP20 file. PP20 myPP = new PP20(); int fileLen; if (myPP.isCompressed(buf.buf, buf.bufLen)) { PP20.Decompressed decomp = new PP20.Decompressed(); if (0 == (fileLen = myPP.decompress(buf.buf, buf.bufLen, decomp))) { //info.statusstring = myPP.getStatusstring(); return(-1); } else { //info.statusstring = myPP.getStatusstring(); // Replace compressed buffer with uncompressed buffer. buf.assign(decomp.destBufRef, fileLen); } return(1); } return(0); }