libsidplayfp  1.0.1
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 <fstream>
28 #include <memory>
29 
30 #include "sidplayfp/Buffer.h"
31 #include "sidplayfp/SmartPtr.h"
32 #include "sidplayfp/SidTuneInfo.h"
33 #include "sidplayfp/SidTune.h"
34 #include "sidplayfp/siddefs.h"
35 
37 
38 class SidTuneInfoImpl;
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:
59  static const unsigned int MAX_SONGS = 256;
60 
61 private:
63  static const uint_least32_t MAX_FILELEN = 65536+2+0x7C;
64 
65  static const uint_least32_t MAX_MEMORY = 65536;
66 
67 public: // ----------------------------------------------------------------
68  virtual ~SidTuneBase() {}
69 
80  static SidTuneBase* load(const char* fileName, const char **fileNameExt, bool separatorIsSlash);
81 
86  static SidTuneBase* read(const uint_least8_t* sourceBuffer, uint_least32_t bufferLen);
87 
92  unsigned int selectSong(unsigned int songNum);
93 
97  const SidTuneInfo* getInfo() const;
98 
103  const SidTuneInfo* getInfo(unsigned int songNum);
104 
108  virtual bool placeSidTuneInC64mem(sidmemory* mem);
109 
116  virtual const char *createMD5(char *md5 SID_UNUSED) { return 0; }
117 
118 protected: // -------------------------------------------------------------
119 
120  std::auto_ptr<SidTuneInfoImpl> info;
121 
122  uint_least8_t songSpeed[MAX_SONGS];
123  SidTuneInfo::clock_t clockSpeed[MAX_SONGS];
124 
126  uint_least32_t fileOffset;
127 
129 
130 protected:
131  SidTuneBase();
132 
137  static void loadFile(const char* fileName, Buffer_sidtt<const uint_least8_t>& bufferRef);
138 
140  void convertOldStyleSpeedToTables(uint_least32_t speed,
141  SidTuneInfo::clock_t clock = SidTuneInfo::CLOCK_PAL);
142 
144  bool checkCompatibility();
145 
147  bool checkRelocInfo();
148 
150  void resolveAddrs(const uint_least8_t* c64data);
151 
168  virtual void acceptSidTune(const char* dataFileName, const char* infoFileName,
169  Buffer_sidtt<const uint_least8_t>& buf, bool isSlashedFileName);
170 
172  {
173  private:
174  std::string buffer;
175  public:
176  const char* convert(SmartPtr_sidtt<const uint_least8_t>& spPet);
177  };
178 
179 private: // ---------------------------------------------------------------
180 
181 #if !defined(SIDTUNE_NO_STDIN_LOADER)
182  static SidTuneBase* getFromStdIn();
183 #endif
184  static SidTuneBase* getFromFiles(const char* name, const char **fileNameExtensions, bool separatorIsSlash);
185 
187  static SidTuneBase* getFromBuffer(const uint_least8_t* const buffer, uint_least32_t bufferLen);
188 
189  static void createNewFileName(std::string& destString,
190  const char* sourceName, const char* sourceExt);
191 
192 private: // prevent copying
193  SidTuneBase(const SidTuneBase&);
194  SidTuneBase& operator=(SidTuneBase&);
195 };
196 
197 #endif /* SIDTUNEBASE_H */