libsidplayfp  1.1.0
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 
29 #include "sidplayfp/Buffer.h"
30 #include "sidplayfp/SmartPtr.h"
31 #include "sidplayfp/SidTuneInfo.h"
32 #include "sidplayfp/SidTune.h"
33 #include "sidplayfp/siddefs.h"
34 
36 
37 class SidTuneInfoImpl;
38 
42 class loadError
43 {
44 private:
45  const char* m_msg;
46 public:
47  loadError(const char* msg) : m_msg(msg) {}
48  const char* message() const { return m_msg; }
49 };
50 
55 {
56 protected:
58  static const unsigned int MAX_SONGS = 256;
59 
60 private:
62  static const uint_least32_t MAX_FILELEN = 65536+2+0x7C;
63 
64  static const uint_least32_t MAX_MEMORY = 65536;
65 
66 public: // ----------------------------------------------------------------
67  virtual ~SidTuneBase() {}
68 
79  static SidTuneBase* load(const char* fileName, const char **fileNameExt, bool separatorIsSlash);
80 
85  static SidTuneBase* read(const uint_least8_t* sourceBuffer, uint_least32_t bufferLen);
86 
91  unsigned int selectSong(unsigned int songNum);
92 
96  const SidTuneInfo* getInfo() const;
97 
102  const SidTuneInfo* getInfo(unsigned int songNum);
103 
107  virtual bool placeSidTuneInC64mem(sidmemory* mem);
108 
115  virtual const char *createMD5(char *md5 SID_UNUSED) { return 0; }
116 
117 protected: // -------------------------------------------------------------
118 
119  std::auto_ptr<SidTuneInfoImpl> info;
120 
121  uint_least8_t songSpeed[MAX_SONGS];
122  SidTuneInfo::clock_t clockSpeed[MAX_SONGS];
123 
125  uint_least32_t fileOffset;
126 
128 
129 protected:
130  SidTuneBase();
131 
136  static void loadFile(const char* fileName, Buffer_sidtt<const uint_least8_t>& bufferRef);
137 
139  void convertOldStyleSpeedToTables(uint_least32_t speed,
140  SidTuneInfo::clock_t clock = SidTuneInfo::CLOCK_PAL);
141 
143  bool checkCompatibility();
144 
146  bool checkRelocInfo();
147 
149  void resolveAddrs(const uint_least8_t* c64data);
150 
167  virtual void acceptSidTune(const char* dataFileName, const char* infoFileName,
168  Buffer_sidtt<const uint_least8_t>& buf, bool isSlashedFileName);
169 
171  {
172  private:
173  std::string buffer;
174  public:
175  const char* convert(SmartPtr_sidtt<const uint_least8_t>& spPet);
176  };
177 
178 private: // ---------------------------------------------------------------
179 
180 #if !defined(SIDTUNE_NO_STDIN_LOADER)
181  static SidTuneBase* getFromStdIn();
182 #endif
183  static SidTuneBase* getFromFiles(const char* name, const char **fileNameExtensions, bool separatorIsSlash);
184 
186  static SidTuneBase* getFromBuffer(const uint_least8_t* const buffer, uint_least32_t bufferLen);
187 
188  static void createNewFileName(std::string& destString,
189  const char* sourceName, const char* sourceExt);
190 
191 private: // prevent copying
192  SidTuneBase(const SidTuneBase&);
193  SidTuneBase& operator=(SidTuneBase&);
194 };
195 
196 #endif /* SIDTUNEBASE_H */
Definition: SmartPtr.h:195
Definition: SidTuneBase.h:170
Definition: SidTuneInfo.h:36
virtual const char * createMD5(char *md5 SID_UNUSED)
Definition: SidTuneBase.h:115
Definition: SidTuneBase.h:54
Definition: SidTuneInfoImpl.h:35
Definition: sidmemory.h:30
uint_least32_t fileOffset
For files with header: offset to real data.
Definition: SidTuneBase.h:125
Definition: SidTuneBase.h:42