libsidplayfp
1.0.3
|
00001 /* 00002 * This file is part of libsidplayfp, a SID player engine. 00003 * 00004 * Copyright 2011-2013 Leandro Nini <drfiemost@users.sourceforge.net> 00005 * Copyright 2007-2010 Antti Lankila 00006 * Copyright 2000 Simon White 00007 * 00008 * This program is free software; you can redistribute it and/or modify 00009 * it under the terms of the GNU General Public License as published by 00010 * the Free Software Foundation; either version 2 of the License, or 00011 * (at your option) any later version. 00012 * 00013 * This program is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU General Public License 00019 * along with this program; if not, write to the Free Software 00020 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00021 */ 00022 00023 #ifndef SIDTUNEBASE_H 00024 #define SIDTUNEBASE_H 00025 00026 #include <stdint.h> 00027 #include <fstream> 00028 #include <memory> 00029 00030 #include "sidplayfp/Buffer.h" 00031 #include "sidplayfp/SmartPtr.h" 00032 #include "sidplayfp/SidTuneInfo.h" 00033 #include "sidplayfp/SidTune.h" 00034 #include "sidplayfp/siddefs.h" 00035 00036 template class Buffer_sidtt<const uint_least8_t>; 00037 00038 class SidTuneInfoImpl; 00039 00043 class loadError 00044 { 00045 private: 00046 const char* m_msg; 00047 public: 00048 loadError(const char* msg) : m_msg(msg) {} 00049 const char* message() const { return m_msg; } 00050 }; 00051 00055 class SidTuneBase 00056 { 00057 protected: 00059 static const unsigned int MAX_SONGS = 256; 00060 00061 private: 00063 static const uint_least32_t MAX_FILELEN = 65536+2+0x7C; 00064 00065 static const uint_least32_t MAX_MEMORY = 65536; 00066 00067 public: // ---------------------------------------------------------------- 00068 virtual ~SidTuneBase() {} 00069 00080 static SidTuneBase* load(const char* fileName, const char **fileNameExt, bool separatorIsSlash); 00081 00086 static SidTuneBase* read(const uint_least8_t* sourceBuffer, uint_least32_t bufferLen); 00087 00092 unsigned int selectSong(unsigned int songNum); 00093 00097 const SidTuneInfo* getInfo() const; 00098 00103 const SidTuneInfo* getInfo(unsigned int songNum); 00104 00108 virtual bool placeSidTuneInC64mem(sidmemory* mem); 00109 00116 virtual const char *createMD5(char *md5 SID_UNUSED) { return 0; } 00117 00118 protected: // ------------------------------------------------------------- 00119 00120 std::auto_ptr<SidTuneInfoImpl> info; 00121 00122 uint_least8_t songSpeed[MAX_SONGS]; 00123 SidTuneInfo::clock_t clockSpeed[MAX_SONGS]; 00124 00126 uint_least32_t fileOffset; 00127 00128 Buffer_sidtt<const uint_least8_t> cache; 00129 00130 protected: 00131 SidTuneBase(); 00132 00137 static void loadFile(const char* fileName, Buffer_sidtt<const uint_least8_t>& bufferRef); 00138 00140 void convertOldStyleSpeedToTables(uint_least32_t speed, 00141 SidTuneInfo::clock_t clock = SidTuneInfo::CLOCK_PAL); 00142 00144 bool checkCompatibility(); 00145 00147 bool checkRelocInfo(); 00148 00150 void resolveAddrs(const uint_least8_t* c64data); 00151 00168 virtual void acceptSidTune(const char* dataFileName, const char* infoFileName, 00169 Buffer_sidtt<const uint_least8_t>& buf, bool isSlashedFileName); 00170 00171 class PetsciiToAscii 00172 { 00173 private: 00174 std::string buffer; 00175 public: 00176 const char* convert(SmartPtr_sidtt<const uint_least8_t>& spPet); 00177 }; 00178 00179 private: // --------------------------------------------------------------- 00180 00181 #if !defined(SIDTUNE_NO_STDIN_LOADER) 00182 static SidTuneBase* getFromStdIn(); 00183 #endif 00184 static SidTuneBase* getFromFiles(const char* name, const char **fileNameExtensions, bool separatorIsSlash); 00185 00187 static SidTuneBase* getFromBuffer(const uint_least8_t* const buffer, uint_least32_t bufferLen); 00188 00189 static void createNewFileName(std::string& destString, 00190 const char* sourceName, const char* sourceExt); 00191 00192 private: // prevent copying 00193 SidTuneBase(const SidTuneBase&); 00194 SidTuneBase& operator=(SidTuneBase&); 00195 }; 00196 00197 #endif /* SIDTUNEBASE_H */