libsidplayfp  2.0.1
SidTuneBase.h
1 /*
2  * This file is part of libsidplayfp, a SID player engine.
3  *
4  * Copyright 2011-2015 Leandro Nini <drfiemost@users.sourceforge.net>
5  * Copyright 2007-2010 Antti Lankila
6  * Copyright 2000 Simon White
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21  */
22 
23 #ifndef SIDTUNEBASE_H
24 #define SIDTUNEBASE_H
25 
26 #include <stdint.h>
27 #include <memory>
28 #include <vector>
29 #include <string>
30 
31 #include "sidplayfp/SidTuneInfo.h"
32 #include "sidplayfp/siddefs.h"
33 
34 #include "SmartPtr.h"
35 #include "SidTuneInfoImpl.h"
36 
37 #include "sidcxx11.h"
38 
39 namespace libsidplayfp
40 {
41 
42 class sidmemory;
43 template <class T> class SmartPtr_sidtt;
44 
48 class loadError
49 {
50 private:
51  const char* m_msg;
52 public:
53  loadError(const char* msg) : m_msg(msg) {}
54  const char* message() const { return m_msg; }
55 };
56 
61 {
62 protected:
63  typedef std::vector<uint8_t> buffer_t;
64 
65 protected:
67  static const unsigned int MAX_SONGS = 256;
68 
69  // Generic error messages
70  static const char ERR_TRUNCATED[];
71  static const char ERR_INVALID[];
72 
73 public: // ----------------------------------------------------------------
74  virtual ~SidTuneBase() {}
75 
92  static SidTuneBase* load(const char* fileName, const char **fileNameExt, bool separatorIsSlash);
93 
103  static SidTuneBase* read(const uint_least8_t* sourceBuffer, uint_least32_t bufferLen);
104 
112  unsigned int selectSong(unsigned int songNum);
113 
117  const SidTuneInfo* getInfo() const;
118 
125  const SidTuneInfo* getInfo(unsigned int songNum);
126 
132  virtual void placeSidTuneInC64mem(sidmemory& mem);
133 
141  virtual const char *createMD5(char *) { return nullptr; }
142 
150  virtual const char *createMD5New(char *) { return nullptr; }
151 
155  const uint_least8_t* c64Data() const { return &cache[fileOffset]; }
156 
157 protected: // -------------------------------------------------------------
158 
159  std::unique_ptr<SidTuneInfoImpl> info;
160 
161  uint_least8_t songSpeed[MAX_SONGS];
162  SidTuneInfo::clock_t clockSpeed[MAX_SONGS];
163 
165  uint_least32_t fileOffset;
166 
167  buffer_t cache;
168 
169 protected:
170  SidTuneBase();
171 
180  static void loadFile(const char* fileName, buffer_t& bufferRef);
181 
188  void convertOldStyleSpeedToTables(uint_least32_t speed,
189  SidTuneInfo::clock_t clock = SidTuneInfo::CLOCK_PAL);
190 
194  bool checkCompatibility();
195 
199  bool checkRelocInfo();
200 
206  void resolveAddrs(const uint_least8_t* c64data);
207 
225  virtual void acceptSidTune(const char* dataFileName, const char* infoFileName,
226  buffer_t& buf, bool isSlashedFileName);
227 
231  std::string petsciiToAscii(SmartPtr_sidtt<const uint8_t>& spPet);
232 
233 private: // ---------------------------------------------------------------
234 
235 #if !defined(SIDTUNE_NO_STDIN_LOADER)
236  static SidTuneBase* getFromStdIn();
237 #endif
238  static SidTuneBase* getFromFiles(const char* name, const char **fileNameExtensions, bool separatorIsSlash);
239 
243  static SidTuneBase* getFromBuffer(const uint_least8_t* const buffer, uint_least32_t bufferLen);
244 
252  static void createNewFileName(std::string& destString,
253  const char* sourceName, const char* sourceExt);
254 
255 private:
256  // prevent copying
257  SidTuneBase(const SidTuneBase&);
258  SidTuneBase& operator=(SidTuneBase&);
259 };
260 
261 }
262 
263 #endif /* SIDTUNEBASE_H */
Definition: exsid-emu.cpp:29
Definition: sidmemory.h:33
Definition: SidTuneBase.h:48
Definition: SidTuneInfo.h:38
virtual const char * createMD5(char *)
Definition: SidTuneBase.h:141
const uint_least8_t * c64Data() const
Definition: SidTuneBase.h:155
Definition: SidTuneBase.h:60
Definition: SidTuneBase.h:43
virtual const char * createMD5New(char *)
Definition: SidTuneBase.h:150
uint_least32_t fileOffset
For files with header: offset to real data.
Definition: SidTuneBase.h:165