SidTuneBase.h
/*
* This file is part of libsidplayfp, a SID player engine.
*
* Copyright 2011-2013 Leandro Nini <drfiemost@users.sourceforge.net>
* Copyright 2007-2010 Antti Lankila
* Copyright 2000 Simon White
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef SIDTUNEBASE_H
#define SIDTUNEBASE_H
#include <stdint.h>
#include <memory>
#include <vector>
#include <string>
#include "SidTuneCfg.h"
#include "SmartPtr.h"
#include "SidTuneInfoImpl.h"
#include "sidplayfp/SidTuneInfo.h"
#include "sidplayfp/siddefs.h"
class sidmemory;
template <class T> class SmartPtr_sidtt;
class loadError
{
private:
const char* m_msg;
public:
loadError(const char* msg) : m_msg(msg) {}
const char* message() const { return m_msg; }
};
class SidTuneBase
{
protected:
typedef std::vector<uint_least8_t> buffer_t;
protected:
static const unsigned int MAX_SONGS = 256;
private:
static const uint_least32_t MAX_FILELEN = 65536+2+0x7C;
static const uint_least32_t MAX_MEMORY = 65536;
public: // ----------------------------------------------------------------
virtual ~SidTuneBase() {}
static SidTuneBase* load(const char* fileName, const char **fileNameExt, bool separatorIsSlash);
static SidTuneBase* read(const uint_least8_t* sourceBuffer, uint_least32_t bufferLen);
unsigned int selectSong(unsigned int songNum);
const SidTuneInfo* getInfo() const;
const SidTuneInfo* getInfo(unsigned int songNum);
virtual bool placeSidTuneInC64mem(sidmemory* mem);
virtual const char *createMD5(char *md5 SID_UNUSED) { return 0; }
protected: // -------------------------------------------------------------
std::auto_ptr<SidTuneInfoImpl> info;
uint_least8_t songSpeed[MAX_SONGS];
SidTuneInfo::clock_t clockSpeed[MAX_SONGS];
uint_least32_t fileOffset;
buffer_t cache;
protected:
SidTuneBase();
static void loadFile(const char* fileName,buffer_t& bufferRef);
void convertOldStyleSpeedToTables(uint_least32_t speed,
SidTuneInfo::clock_t clock = SidTuneInfo::CLOCK_PAL);
bool checkCompatibility();
bool checkRelocInfo();
void resolveAddrs(const uint_least8_t* c64data);
virtual void acceptSidTune(const char* dataFileName, const char* infoFileName,
buffer_t& buf, bool isSlashedFileName);
class PetsciiToAscii
{
private:
std::string buffer;
public:
const char* convert(SmartPtr_sidtt<const uint_least8_t>& spPet);
};
private: // ---------------------------------------------------------------
#if !defined(SIDTUNE_NO_STDIN_LOADER)
static SidTuneBase* getFromStdIn();
#endif
static SidTuneBase* getFromFiles(const char* name, const char **fileNameExtensions, bool separatorIsSlash);
static SidTuneBase* getFromBuffer(const uint_least8_t* const buffer, uint_least32_t bufferLen);
static void createNewFileName(std::string& destString,
const char* sourceName, const char* sourceExt);
private: // prevent copying
SidTuneBase(const SidTuneBase&);
SidTuneBase& operator=(SidTuneBase&);
};
#endif /* SIDTUNEBASE_H */
SmartPtr_sidtt
Definition: MUS.h:29
SidTuneBase::acceptSidTune
virtual void acceptSidTune(const char *dataFileName, const char *infoFileName, buffer_t &buf, bool isSlashedFileName)
Definition: SidTuneBase.cpp:274
SidTuneBase::getInfo
const SidTuneInfo * getInfo() const
Definition: SidTuneBase.cpp:103
SidTuneBase::PetsciiToAscii
Definition: SidTuneBase.h:174
SidTuneInfo
Definition: SidTuneInfo.h:36
SidTuneBase::convertOldStyleSpeedToTables
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
SidTuneBase::createMD5
virtual const char * createMD5(char *md5 SID_UNUSED)
Definition: SidTuneBase.h:119
SidTuneBase::checkCompatibility
bool checkCompatibility()
Check compatibility details are sensible.
Definition: SidTuneBase.cpp:539
SidTuneBase
Definition: SidTuneBase.h:55
SidTuneBase::loadFile
static void loadFile(const char *fileName, buffer_t &bufferRef)
Definition: SidTuneBase.cpp:177
SidTuneBase::MAX_SONGS
static const unsigned int MAX_SONGS
Also PSID file format limit.
Definition: SidTuneBase.h:62
SidTuneBase::selectSong
unsigned int selectSong(unsigned int songNum)
Definition: SidTuneBase.cpp:114
SidTuneBase::load
static SidTuneBase * load(const char *fileName, const char **fileNameExt, bool separatorIsSlash)
Definition: SidTuneBase.cpp:84
SidTuneBase::placeSidTuneInC64mem
virtual bool placeSidTuneInC64mem(sidmemory *mem)
Definition: SidTuneBase.cpp:155
SidTuneBase::resolveAddrs
void resolveAddrs(const uint_least8_t *c64data)
Common address resolution procedure.
Definition: SidTuneBase.cpp:503
SidTuneBase::checkRelocInfo
bool checkRelocInfo()
Check for valid relocation information.
Definition: SidTuneBase.cpp:456
sidmemory
Definition: sidmemory.h:30
SidTuneBase::read
static SidTuneBase * read(const uint_least8_t *sourceBuffer, uint_least32_t bufferLen)
Definition: SidTuneBase.cpp:98
SidTuneBase::fileOffset
uint_least32_t fileOffset
For files with header: offset to real data.
Definition: SidTuneBase.h:129
loadError
Definition: SidTuneBase.h:43