/// <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> /// 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> /// Cache the data of a single-file or two-file sidtune and its corresponding file names /// </summary> /// <param name="buf"></param> /// <returns></returns> private bool acceptSidTune(Buffer_sidtt buf) { // @FIXME@ - MUS if (info.numberOfInfostrings == 3) { // Add <?> (HVSC standard) to // missing title, author, // release fields for (int i = 0; i < 3; i++) { if (infostring[i].Length == 0) { infostring[i] = "<?>"; info.infostring[i] = infostring[i]; } } } // Fix bad sidtune set up. if (info.songs > SIDTUNE_MAX_SONGS) { info.songs = SIDTUNE_MAX_SONGS; } else if (info.songs == 0) { info.songs++; } if (info.startSong > info.songs) { info.startSong = 1; } else if (info.startSong == 0) { info.startSong++; } info.dataFileLen = buf.bufLen; info.c64dataLen = buf.bufLen - fileOffset; // Calculate any remaining addresses and then // confirm all the file details are correct if (resolveAddrs(buf.buf, fileOffset) == false) { return(false); } if (!checkRelocInfo()) { return(false); } if (!checkCompatibility()) { return(false); } if (info.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.fixLoad = (SIDEndian.endian_little16(buf.buf, fileOffset) == (info.loadAddr + 2)); } // 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); } cache.assign(buf.xferPtr(), buf.xferLen()); //info.statusstring = txt_noErrors; return(true); }