Main Page | Class Hierarchy | Compound List | File List | Compound Members | File Members | Related Pages

sidtune.h

Go to the documentation of this file.
00001 //
00002 // 1997/09/27 21:33:14
00003 //
00004 
00005 #ifndef __SIDTUNE_H
00006 #define __SIDTUNE_H
00007 
00008 #include "epocglue.h"
00009 
00010 #if !defined (__EPOC32__) && !defined (__SYMBIAN32__)
00011 #include <fstream.h> //ALFRED
00012 #endif
00013 
00014 #include "mytypes.h"
00015 
00016 static const int classMaxSongs = 256;
00017 static const int infoStringNum = 5;     // maximum
00018 static const int infoStringLen = 80+1;  // 80 characters plus terminating zero
00019 
00020 static const int SIDTUNE_SPEED_CIA_1A = 0;     // CIA 1 Timer A
00021 static const int SIDTUNE_SPEED_VBI_PAL = 50;   // Hz
00022 static const int SIDTUNE_SPEED_VBI_NTSC = 60;  // Hz
00023 
00024 static const int SIDTUNE_CLOCK_PAL = 0;   // These are also used in the
00025 static const int SIDTUNE_CLOCK_NTSC = 1;  // emulator engine !
00026 
00027 // An instance of this structure is used to transport values to
00028 // and from the ``sidTune-class'';
00029 struct sidTuneInfo
00030 {
00031         // Consider the following fields as read-only !
00032         //
00033         // Currently, the only way to get the class to accept values which
00034         // were written to these fields is creating a derived class.
00035         //
00036         const char* formatString;   // the name of the identified file format
00037         const char* speedString;    // describing the speed a song is running at
00038         uword loadAddr;
00039         uword initAddr;
00040         uword playAddr;
00041         uword startSong;
00042         uword songs;
00043         //
00044         // Available after song initialization.
00045         //
00046         uword irqAddr;              // if (playAddr == 0), interrupt handler was
00047                                     // installed and starts calling the C64 player
00048                                     // at this address
00049         uword currentSong;          // the one that has been initialized
00050         ubyte songSpeed;            // intended speed, see top
00051         ubyte clockSpeed;           // -"-
00052         bool musPlayer;             // true = install sidplayer routine
00053         uword lengthInSeconds;      // --- not yet supported ---
00054         //
00055         // Song title, credits, ...
00056         //
00057         ubyte numberOfInfoStrings;  // the number of available text info lines
00058         char* infoString[infoStringNum];
00059         char* nameString;           // name, author and copyright strings
00060         char* authorString;         // are duplicates of infoString[?]
00061         char* copyrightString;
00062         //
00063         uword numberOfCommentStrings;  // --- not yet supported ---
00064         char ** commentString;         // -"-
00065         //
00066         udword dataFileLen;         // length of single-file sidtune or raw data
00067         udword c64dataLen;          // length of raw C64 data
00068         char* dataFileName;         // a first file: e.g. ``*.DAT''
00069         char* infoFileName;         // a second file: e.g. ``*.SID''
00070         //
00071         const char* statusString;   // error/status message of last operation
00072 };
00073 
00074 
00075 class emuEngine;
00076 
00077 
00078 class sidTune
00079 {
00080 
00081  public:  // ----------------------------------------------------------------
00082 
00083         // --- constructors ---
00084 
00085         // Load a sidtune from a file.
00086         // To retrieve data from standard input pass in filename "-".
00087         IMPORT_C sidTune(const char* sidTuneFileName);
00088 
00089         // If you want to override the default filename extensions use this
00090         // contructor. Please note, that if the specified ``sidTuneFileName''
00091         // does exist and the loader is able to determine its file format,
00092         // this function does not try to append any file name extension.
00093         // See ``sidtune.cpp'' for the default list of file name extensions.
00094         // You can specific ``sidTuneFileName = 0'', if you do not want to
00095         // load a sidtune. You can later load one with open().
00096         sidTune(const char* sidTuneFileName, const char **fileNameExt);
00097 
00098         // Load a single-file sidtune from a memory buffer.
00099         // Currently supported: PSID format
00100         sidTune(ubyte* oneFileFormatSidtune, udword sidtuneLength);
00101 
00102     virtual ~sidTune();  // destructor
00103 
00104         // --- member functions ---
00105 
00106         // Load a sidtune from a file into an existing object.
00107         bool open(const char* sidTuneFileName);
00108     bool load(ubyte* oneFileFormatSidtune, udword sidtuneLength);
00109 
00110         IMPORT_C void getInfo( struct sidTuneInfo& );
00111 //      bool returnInfo( struct sidTuneInfo& outSidTuneInfo )  { return getInfo(outSidTuneInfo); }
00112     virtual bool setInfo( struct sidTuneInfo& );  // dummy
00113 
00114     ubyte getSongSpeed()  { return info.songSpeed; }
00115     ubyte returnSongSpeed()  { return getSongSpeed(); }
00116 
00117         uword getPlayAddr()     { return info.playAddr; }
00118         uword returnPlayAddr()  { return getPlayAddr(); }
00119 
00120     // This function initializes the SID emulator engine to play the given
00121     // sidtune song.
00122 //      friend bool sidEmuInitializeSong(emuEngine &, sidTune &, uword songNum);
00123 
00124     // This is an old non-obsolete sub-function, that does not scan the sidtune
00125     // for digis. If (emuConfig.digiPlayerScan == 0), this functions does the
00126         // same as the one above.
00127         friend bool sidEmuInitializeSongOld(emuEngine &, sidTune &,     uword songNum);
00128 
00129         // Determine current state of object (true = okay, false = error).
00130         // Upon error condition use ``getInfo'' to get a descriptive
00131         // text string in ``sidTuneInfo.statusString''.
00132     operator bool()  { return status; }
00133         bool getStatus()  { return status; }
00134         bool returnStatus()  { return getStatus(); }
00135 
00136         // --- format conversion ---
00137 
00138         // These functions work for any successfully created object.
00139         // overWriteFlag: true  = Overwrite existing file.
00140         //                false = Default, return error when file already
00141         //                        exists.
00142         // One could imagine an "Are you sure ?"-checkbox before overwriting
00143         // any file.
00144         // returns: true = Successful, false = Error condition.
00145     bool saveC64dataFile( const char* destFileName, bool overWriteFlag = false );
00146         bool saveSIDfile( const char* destFileName, bool overWriteFlag = false );
00147         bool savePSIDfile( const char* destFileName, bool overWriteFlag = false );
00148         bool saveSID2file( const char* destFileName, bool overWriteFlag = false );
00149 
00150 
00151  public:  // TODO -------------------------------------------------------------
00152 
00153         bool status;
00154         sidTuneInfo info;
00155 
00156  protected:  // -------------------------------------------------------------
00157 
00158         ubyte songSpeed[classMaxSongs];
00159         uword songLength[classMaxSongs];   // song lengths in seconds
00160 
00161         // holds text info from the format headers etc.
00162         char infoString[infoStringNum][infoStringLen];
00163 
00164         ubyte fillUpWidth;  // fill up saved text strings up to this width
00165 
00166         bool isCached;
00167         ubyte* cachePtr;
00168         udword cacheLen;
00169 
00170         // Using external buffers for loading files instead of the interpreter
00171         // memory. This separates the sidtune objects from the interpreter.
00172         ubyte* fileBuf;
00173         ubyte* fileBuf2;
00174 
00175         udword fileOffset;  // for files with header: offset to real data
00176 
00177         // Filename extensions to append for various file types.
00178         const char * const * fileNameExtensions;
00179 
00180         // --- protected member functions ---
00181 
00182         // Convert 32-bit PSID-style speed word to internal variables.
00183         void convertOldStyleSpeedToTables(udword oldStyleSpeed);
00184 
00185         // Copy C64 data from internal cache to C64 memory.
00186         bool placeSidTuneInC64mem( ubyte* c64buf );
00187 
00188         udword loadFile(const char* fileName, ubyte** bufferRef);
00189 //      bool saveToOpenFile( ofstream& toFile, ubyte* buffer, udword bufLen ); //ALFRED - TODO
00190 
00191         // Data caching.
00192         bool cacheRawData( void* sourceBuffer, udword sourceBufLen );
00193         bool getCachedRawData( void* destBuffer, udword destBufLen );
00194 
00195         // Support for various file formats.
00196 
00197         virtual bool PSID_fileSupport(void* buffer, udword bufLen);
00198 //      virtual bool PSID_fileSupportSave(ofstream& toFile, ubyte* dataBuffer); //ALFRED - TODO
00199 
00200         virtual bool MUS_fileSupport(void* buffer, udword bufLen);
00201         virtual void MUS_installPlayer(ubyte *c64buf);
00202 
00203         virtual bool INFO_fileSupport(void* dataBuffer, udword dataBufLen,
00204                                                                   void* infoBuffer, udword infoBufLen);
00205 
00206         virtual bool SID_fileSupport(void* dataBuffer, udword dataBufLen,
00207                                                                  void* sidBuffer, udword sidBufLen);
00208 //      virtual bool SID_fileSupportSave(ofstream& toFile);  //ALFRED - TODO
00209         
00210 //      virtual bool SID2_fileSupport(void* dataBuffer, udword dataBufLen);
00211 //      virtual bool SID2_fileSupportSave(ofstream& toFile, ubyte* dataBuffer);
00212 
00213         
00214  private:  // ---------------------------------------------------------------
00215         
00216         // --- private member functions ---
00217 
00218         void safeConstructor();
00219         void safeDestructor();
00220 #if !defined(__POWERPC__)
00221         void stdinConstructor();
00222 #endif
00223         void filesConstructor( const char* );   
00224         
00225         uword selectSong(uword selectedSong);
00226         void setIRQaddress(uword address);
00227         
00228         void deleteFileBuffers();
00229         // Try to retrieve single-file sidtune from specified buffer.
00230         bool getSidtuneFromFileBuffer(ubyte* buffer, udword bufferLen);
00231         // Cache the data of a single-file or two-file sidtune and its
00232         // corresponding file names.
00233         void acceptSidTune(const char* dataFileName, const char* infoFileName,
00234                                            ubyte* dataFileBuf, udword dataLen );
00235         bool createNewFileName( char** destStringPtr,
00236                                                    const char* sourceName, const char* sourceExt);
00237 };
00238         
00239 
00240 #endif // __SIDTUNE_H

Generated on Tue Feb 8 04:14:15 2005 for Esidplay by doxygen 1.3.3