libsidplayfp  0.3.5
SidTune.h
1 /*
2  * /home/ms/files/source/libsidtune/RCS/SidTune.h,v
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */
18 
19 #ifndef SIDTUNE_H
20 #define SIDTUNE_H
21 
22 
23 #include "sidtypes.h"
24 #include "Buffer.h"
25 #include "SmartPtr.h"
26 
27 #include <fstream>
28 
30 const uint_least16_t SIDTUNE_MAX_SONGS = 256;
31 
32 const uint_least16_t SIDTUNE_MAX_CREDIT_STRINGS = 10;
33 
35 const uint_least16_t SIDTUNE_MAX_CREDIT_STRLEN = 80+1;
36 
37 const uint_least32_t SIDTUNE_MAX_MEMORY = 65536;
38 
40 const uint_least32_t SIDTUNE_MAX_FILELEN = 65536+2+0x7C;
41 
43 const int SIDTUNE_SPEED_VBI = 0;
44 
46 const int SIDTUNE_SPEED_CIA_1A = 60;
47 
48 const int SIDTUNE_CLOCK_UNKNOWN = 0x00;
49 const int SIDTUNE_CLOCK_PAL = 0x01; // These are also used in the
50 const int SIDTUNE_CLOCK_NTSC = 0x02; // emulator engine!
51 const int SIDTUNE_CLOCK_ANY = (SIDTUNE_CLOCK_PAL | SIDTUNE_CLOCK_NTSC);
52 
53 const int SIDTUNE_SIDMODEL_UNKNOWN = 0x00;
54 const int SIDTUNE_SIDMODEL_6581 = 0x01; // These are also used in the
55 const int SIDTUNE_SIDMODEL_8580 = 0x02; // emulator engine!
56 const int SIDTUNE_SIDMODEL_ANY = (SIDTUNE_SIDMODEL_6581 | SIDTUNE_SIDMODEL_8580);
57 
58 const int SIDTUNE_COMPATIBILITY_C64 = 0x00;
59 const int SIDTUNE_COMPATIBILITY_PSID = 0x01;
60 const int SIDTUNE_COMPATIBILITY_R64 = 0x02;
61 const int SIDTUNE_COMPATIBILITY_BASIC = 0x03;
62 
63 template class SID_EXTERN Buffer_sidtt<const uint_least8_t>;
64 
81 {
83  const char* formatString;
84 
86  const char* statusString;
87 
89  const char* speedString;
90 
91  uint_least16_t loadAddr;
92  uint_least16_t initAddr;
93  uint_least16_t playAddr;
94 
95  uint_least16_t songs;
96  uint_least16_t startSong;
97 
103  uint_least16_t sidChipBase1;
104  uint_least16_t sidChipBase2;
105 
106 
109  uint_least16_t currentSong;
110 
112  uint_least8_t songSpeed;
113 
115  uint_least8_t clockSpeed;
116 
118  uint_least8_t relocStartPage;
119 
121  uint_least8_t relocPages;
122 
124  bool musPlayer;
125 
128 
131 
134 
136  bool fixLoad;
137 
139  uint_least16_t songLength;
140 
145  uint_least8_t numberOfInfoStrings;
146 
148  char* infoString[SIDTUNE_MAX_CREDIT_STRINGS];
149 
151  uint_least16_t numberOfCommentStrings;
152 
154  char ** commentString;
155 
157  uint_least32_t dataFileLen;
158 
160  uint_least32_t c64dataLen;
161 
163  char* path;
164 
167 
170 };
171 
175 class SID_EXTERN SidTune
176 {
177  private:
178  typedef enum
179  {
180  LOAD_NOT_MINE = 0,
181  LOAD_OK,
182  LOAD_ERROR
183  } LoadStatus;
184 
185  public: // ----------------------------------------------------------------
186 
199  SidTune(const char* fileName, const char **fileNameExt = 0,
200  const bool separatorIsSlash = false);
201 
206  SidTune(const uint_least8_t* oneFileFormatSidtune, const uint_least32_t sidtuneLength);
207 
208  virtual ~SidTune();
209 
217  void setFileNameExtensions(const char **fileNameExt);
218 
223  bool load(const char* fileName, const bool separatorIsSlash = false);
224 
228  bool read(const uint_least8_t* sourceBuffer, const uint_least32_t bufferLen);
229 
234  const SidTuneInfo& operator[](const uint_least16_t songNum);
235 
240  uint_least16_t selectSong(const uint_least16_t songNum);
241 
246  const SidTuneInfo& getInfo();
247 
252  void getInfo(SidTuneInfo&);
253 
259  operator bool() { return status; }
260  bool getStatus() { return status; }
261 
265  bool isStereo()
266  {
267  return (info.sidChipBase1!=0 && info.sidChipBase2!=0);
268  }
269 
273  bool placeSidTuneInC64mem(uint_least8_t* c64buf);
274 
275  // --- file save & format conversion ---
276 
286  bool saveC64dataFile( const char* destFileName, const bool overWriteFlag = false );
287  bool saveSIDfile( const char* destFileName, const bool overWriteFlag = false );
288  bool savePSIDfile( const char* destFileName, const bool overWriteFlag = false );
289 
304  void fixLoadAddress(const bool force = false, uint_least16_t initAddr = 0,
305  uint_least16_t playAddr = 0);
306 
311  bool loadFile(const char* fileName, Buffer_sidtt<const uint_least8_t>& bufferRef);
312 
313  bool saveToOpenFile( std::ofstream& toFile, const uint_least8_t* buffer, uint_least32_t bufLen );
314 
315  protected: // -------------------------------------------------------------
316 
317  SidTuneInfo info;
318  bool status;
319 
320  uint_least8_t songSpeed[SIDTUNE_MAX_SONGS];
321  uint_least8_t clockSpeed[SIDTUNE_MAX_SONGS];
322  uint_least16_t songLength[SIDTUNE_MAX_SONGS];
323 
325  char infoString[SIDTUNE_MAX_CREDIT_STRINGS][SIDTUNE_MAX_CREDIT_STRLEN];
326 
338 
340  uint_least32_t fileOffset;
341 
343  uint_least16_t musDataLen;
344 
346 
348  static const char** fileNameExtensions;
349 
350  // --- protected member functions ---
351 
353  void convertOldStyleSpeedToTables(uint_least32_t speed,
354  int clock = SIDTUNE_CLOCK_PAL);
355 
356  virtual int convertPetsciiToAscii (SmartPtr_sidtt<const uint_least8_t>&, char*);
357 
359  bool checkCompatibility(void);
361  bool checkRelocInfo(void);
363  bool resolveAddrs(const uint_least8_t* c64data);
364 
365  // Support for various file formats.
366 
367  virtual LoadStatus PSID_fileSupport (Buffer_sidtt<const uint_least8_t>& dataBuf);
368  virtual bool PSID_fileSupportSave(std::ofstream& toFile, const uint_least8_t* dataBuffer);
369 
370  virtual LoadStatus SID_fileSupport (Buffer_sidtt<const uint_least8_t>& dataBuf,
372  virtual bool SID_fileSupportSave (std::ofstream& toFile);
373 
374  virtual LoadStatus MUS_fileSupport (Buffer_sidtt<const uint_least8_t>& musBuf,
376  LoadStatus MUS_load (Buffer_sidtt<const uint_least8_t>& musBuf,
377  bool init = false);
378  LoadStatus MUS_load (Buffer_sidtt<const uint_least8_t>& musBuf,
380  bool init = false);
381  virtual bool MUS_detect (const void* buffer, const uint_least32_t bufLen,
382  uint_least32_t& voice3Index);
383  virtual bool MUS_mergeParts (Buffer_sidtt<const uint_least8_t>& musBuf,
385  virtual void MUS_setPlayerAddress();
386  virtual void MUS_installPlayer (uint_least8_t *c64buf);
387 
388  virtual LoadStatus INFO_fileSupport (Buffer_sidtt<const uint_least8_t>& dataBuf,
390  virtual LoadStatus PRG_fileSupport (const char* fileName,
392  virtual LoadStatus X00_fileSupport (const char* fileName,
394 
396 
397  static const char* txt_songNumberExceed;
398  static const char* txt_empty;
399  static const char* txt_unrecognizedFormat;
400  static const char* txt_noDataFile;
401  static const char* txt_notEnoughMemory;
402  static const char* txt_cantLoadFile;
403  static const char* txt_cantOpenFile;
404  static const char* txt_fileTooLong;
405  static const char* txt_dataTooLong;
406  static const char* txt_cantCreateFile;
407  static const char* txt_fileIoError;
408  static const char* txt_VBI;
409  static const char* txt_CIA;
410  static const char* txt_noErrors;
411  static const char* txt_na;
412  static const char* txt_badAddr;
413  static const char* txt_badReloc;
414  static const char* txt_corrupt;
416 
417  private: // ---------------------------------------------------------------
418 
419  void init();
420  void cleanup();
421 #if !defined(SIDTUNE_NO_STDIN_LOADER)
422  void getFromStdIn();
423 #endif
424  void getFromFiles(const char* name);
425 
426  void deleteFileNameCopies();
427 
429  void getFromBuffer(const uint_least8_t* const buffer, const uint_least32_t bufferLen);
430 
435  bool acceptSidTune(const char* dataFileName, const char* infoFileName,
437 
438  bool createNewFileName(Buffer_sidtt<char>& destString,
439  const char* sourceName, const char* sourceExt);
440 
441  int decompressPP20(Buffer_sidtt<const uint_least8_t>& buf);
442 
443  private: // prevent copying
444  SidTune(const SidTune&);
445  SidTune& operator=(SidTune&);
446 };
447 
448 #endif /* SIDTUNE_H */