libsidplayfp  1.8.7
SidTuneBase.h
1 /*
2  * This file is part of libsidplayfp, a SID player engine.
3  *
4  * Copyright 2011-2013 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 "SidTuneCfg.h"
32 #include "SmartPtr.h"
33 #include "SidTuneInfoImpl.h"
34 #include "sidplayfp/SidTuneInfo.h"
35 #include "sidplayfp/siddefs.h"
36 
37 class sidmemory;
38 template <class T> class SmartPtr_sidtt;
39 
43 class loadError
44 {
45 private:
46  const char* m_msg;
47 public:
48  loadError(const char* msg) : m_msg(msg) {}
49  const char* message() const { return m_msg; }
50 };
51 
56 {
57 protected:
58  typedef std::vector<uint_least8_t> buffer_t;
59 
60 protected:
62  static const unsigned int MAX_SONGS = 256;
63 
64 private:
66  static const uint_least32_t MAX_FILELEN = 65536+2+0x7C;
67 
68  static const uint_least32_t MAX_MEMORY = 65536;
69 
70 public: // ----------------------------------------------------------------
71  virtual ~SidTuneBase() {}
72 
83  static SidTuneBase* load(const char* fileName, const char **fileNameExt, bool separatorIsSlash);
84 
89  static SidTuneBase* read(const uint_least8_t* sourceBuffer, uint_least32_t bufferLen);
90 
95  unsigned int selectSong(unsigned int songNum);
96 
100  const SidTuneInfo* getInfo() const;
101 
106  const SidTuneInfo* getInfo(unsigned int songNum);
107 
111  virtual bool placeSidTuneInC64mem(sidmemory* mem);
112 
119  virtual const char *createMD5(char *md5 SID_UNUSED) { return 0; }
120 
121  const uint_least8_t* c64Data() const { return &cache[fileOffset]; }
122 
123 protected: // -------------------------------------------------------------
124 
125  std::auto_ptr<SidTuneInfoImpl> info;
126 
127  uint_least8_t songSpeed[MAX_SONGS];
128  SidTuneInfo::clock_t clockSpeed[MAX_SONGS];
129 
131  uint_least32_t fileOffset;
132 
133  buffer_t cache;
134 
135 protected:
136  SidTuneBase();
137 
142  static void loadFile(const char* fileName,buffer_t& bufferRef);
143 
147  void convertOldStyleSpeedToTables(uint_least32_t speed,
148  SidTuneInfo::clock_t clock = SidTuneInfo::CLOCK_PAL);
149 
153  bool checkCompatibility();
154 
158  bool checkRelocInfo();
159 
163  void resolveAddrs(const uint_least8_t* c64data);
164 
181  virtual void acceptSidTune(const char* dataFileName, const char* infoFileName,
182  buffer_t& buf, bool isSlashedFileName);
183 
185  {
186  private:
187  std::string buffer;
188  public:
189  const char* convert(SmartPtr_sidtt<const uint_least8_t>& spPet);
190  };
191 
192 private: // ---------------------------------------------------------------
193 
194 #if !defined(SIDTUNE_NO_STDIN_LOADER)
195  static SidTuneBase* getFromStdIn();
196 #endif
197  static SidTuneBase* getFromFiles(const char* name, const char **fileNameExtensions, bool separatorIsSlash);
198 
202  static SidTuneBase* getFromBuffer(const uint_least8_t* const buffer, uint_least32_t bufferLen);
203 
204  static void createNewFileName(std::string& destString,
205  const char* sourceName, const char* sourceExt);
206 
207 private:
208  // prevent copying
209  SidTuneBase(const SidTuneBase&);
210  SidTuneBase& operator=(SidTuneBase&);
211 };
212 
213 #endif /* SIDTUNEBASE_H */
Definition: MUS.h:29
Definition: SidTuneBase.h:184
Definition: SidTuneInfo.h:38
virtual const char * createMD5(char *md5 SID_UNUSED)
Definition: SidTuneBase.h:119
Definition: SidTuneBase.h:55
Definition: sidmemory.h:30
uint_least32_t fileOffset
For files with header: offset to real data.
Definition: SidTuneBase.h:131
Definition: SidTuneBase.h:43