libsidplayfp  1.2.2
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 protected: // -------------------------------------------------------------
122 
123  std::auto_ptr<SidTuneInfoImpl> info;
124 
125  uint_least8_t songSpeed[MAX_SONGS];
126  SidTuneInfo::clock_t clockSpeed[MAX_SONGS];
127 
129  uint_least32_t fileOffset;
130 
131  buffer_t cache;
132 
133 protected:
134  SidTuneBase();
135 
140  static void loadFile(const char* fileName,buffer_t& bufferRef);
141 
143  void convertOldStyleSpeedToTables(uint_least32_t speed,
144  SidTuneInfo::clock_t clock = SidTuneInfo::CLOCK_PAL);
145 
147  bool checkCompatibility();
148 
150  bool checkRelocInfo();
151 
153  void resolveAddrs(const uint_least8_t* c64data);
154 
171  virtual void acceptSidTune(const char* dataFileName, const char* infoFileName,
172  buffer_t& buf, bool isSlashedFileName);
173 
175  {
176  private:
177  std::string buffer;
178  public:
179  const char* convert(SmartPtr_sidtt<const uint_least8_t>& spPet);
180  };
181 
182 private: // ---------------------------------------------------------------
183 
184 #if !defined(SIDTUNE_NO_STDIN_LOADER)
185  static SidTuneBase* getFromStdIn();
186 #endif
187  static SidTuneBase* getFromFiles(const char* name, const char **fileNameExtensions, bool separatorIsSlash);
188 
190  static SidTuneBase* getFromBuffer(const uint_least8_t* const buffer, uint_least32_t bufferLen);
191 
192  static void createNewFileName(std::string& destString,
193  const char* sourceName, const char* sourceExt);
194 
195 private: // prevent copying
196  SidTuneBase(const SidTuneBase&);
197  SidTuneBase& operator=(SidTuneBase&);
198 };
199 
200 #endif /* SIDTUNEBASE_H */
Definition: MUS.h:29
virtual void acceptSidTune(const char *dataFileName, const char *infoFileName, buffer_t &buf, bool isSlashedFileName)
Definition: SidTuneBase.cpp:274
const SidTuneInfo * getInfo() const
Definition: SidTuneBase.cpp:103
Definition: SidTuneBase.h:174
Definition: SidTuneInfo.h:36
void convertOldStyleSpeedToTables(uint_least32_t speed, SidTuneInfo::clock_t clock=SidTuneInfo::CLOCK_PAL)
Convert 32-bit PSID-style speed word to internal tables.
Definition: SidTuneBase.cpp:437
virtual const char * createMD5(char *md5 SID_UNUSED)
Definition: SidTuneBase.h:119
bool checkCompatibility()
Check compatibility details are sensible.
Definition: SidTuneBase.cpp:539
Definition: SidTuneBase.h:55
static void loadFile(const char *fileName, buffer_t &bufferRef)
Definition: SidTuneBase.cpp:177
static const unsigned int MAX_SONGS
Also PSID file format limit.
Definition: SidTuneBase.h:62
unsigned int selectSong(unsigned int songNum)
Definition: SidTuneBase.cpp:114
static SidTuneBase * load(const char *fileName, const char **fileNameExt, bool separatorIsSlash)
Definition: SidTuneBase.cpp:84
virtual bool placeSidTuneInC64mem(sidmemory *mem)
Definition: SidTuneBase.cpp:155
void resolveAddrs(const uint_least8_t *c64data)
Common address resolution procedure.
Definition: SidTuneBase.cpp:503
bool checkRelocInfo()
Check for valid relocation information.
Definition: SidTuneBase.cpp:456
Definition: sidmemory.h:30
static SidTuneBase * read(const uint_least8_t *sourceBuffer, uint_least32_t bufferLen)
Definition: SidTuneBase.cpp:98
uint_least32_t fileOffset
For files with header: offset to real data.
Definition: SidTuneBase.h:129
Definition: SidTuneBase.h:43