SidTuneBase.h
/*
* This file is part of libsidplayfp, a SID player engine.
*
* Copyright 2011-2021 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 "sidplayfp/SidTuneInfo.h"
#include "sidplayfp/siddefs.h"
#include "SmartPtr.h"
#include "SidTuneInfoImpl.h"
#include "sidcxx11.h"
namespace libsidplayfp
{
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<uint8_t> buffer_t;
protected:
static const unsigned int MAX_SONGS = 256;
// Generic error messages
static const char ERR_TRUNCATED[];
static const char ERR_INVALID[];
public: // ----------------------------------------------------------------
virtual ~SidTuneBase() {}
typedef void (*LoaderFunc)(const char* fileName, buffer_t& bufferRef);
static SidTuneBase* load(const char* fileName, const char **fileNameExt, bool separatorIsSlash);
static SidTuneBase* load(LoaderFunc loader, 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 void placeSidTuneInC64mem(sidmemory& mem);
virtual const char *createMD5(char *) { return nullptr; }
virtual const char *createMD5New(char *) { return nullptr; }
const uint_least8_t* c64Data() const { return &cache[fileOffset]; }
protected: // -------------------------------------------------------------
std::unique_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);
std::string petsciiToAscii(SmartPtr_sidtt<const uint8_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* getFromFiles(LoaderFunc loader, 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 */
SidTuneInfo
Definition SidTuneInfo.h:39
libsidplayfp::SidTuneBase
Definition SidTuneBase.h:61
libsidplayfp::SidTuneBase::MAX_SONGS
static const unsigned int MAX_SONGS
Also PSID file format limit.
Definition SidTuneBase.h:67
libsidplayfp::SidTuneBase::checkCompatibility
bool checkCompatibility()
Definition SidTuneBase.cpp:542
libsidplayfp::SidTuneBase::read
static SidTuneBase * read(const uint_least8_t *sourceBuffer, uint_least32_t bufferLen)
Definition SidTuneBase.cpp:117
libsidplayfp::SidTuneBase::acceptSidTune
virtual void acceptSidTune(const char *dataFileName, const char *infoFileName, buffer_t &buf, bool isSlashedFileName)
Definition SidTuneBase.cpp:279
libsidplayfp::SidTuneBase::getInfo
const SidTuneInfo * getInfo() const
Definition SidTuneBase.cpp:122
libsidplayfp::SidTuneBase::resolveAddrs
void resolveAddrs(const uint_least8_t *c64data)
Definition SidTuneBase.cpp:507
libsidplayfp::SidTuneBase::createMD5New
virtual const char * createMD5New(char *)
Definition SidTuneBase.h:168
libsidplayfp::SidTuneBase::petsciiToAscii
std::string petsciiToAscii(SmartPtr_sidtt< const uint8_t > &spPet)
Definition SidTuneBase.cpp:573
libsidplayfp::SidTuneBase::convertOldStyleSpeedToTables
void convertOldStyleSpeedToTables(uint_least32_t speed, SidTuneInfo::clock_t clock=SidTuneInfo::CLOCK_PAL)
Definition SidTuneBase.cpp:439
libsidplayfp::SidTuneBase::placeSidTuneInC64mem
virtual void placeSidTuneInC64mem(sidmemory &mem)
Definition SidTuneBase.cpp:168
libsidplayfp::SidTuneBase::createMD5
virtual const char * createMD5(char *)
Definition SidTuneBase.h:159
libsidplayfp::SidTuneBase::c64Data
const uint_least8_t * c64Data() const
Definition SidTuneBase.h:173
libsidplayfp::SidTuneBase::checkRelocInfo
bool checkRelocInfo()
Definition SidTuneBase.cpp:460
libsidplayfp::SidTuneBase::selectSong
unsigned int selectSong(unsigned int songNum)
Definition SidTuneBase.cpp:133
libsidplayfp::SidTuneBase::fileOffset
uint_least32_t fileOffset
For files with header: offset to real data.
Definition SidTuneBase.h:183
libsidplayfp::SidTuneBase::loadFile
static void loadFile(const char *fileName, buffer_t &bufferRef)
Definition SidTuneBase.cpp:184
libsidplayfp::SidTuneBase::load
static SidTuneBase * load(const char *fileName, const char **fileNameExt, bool separatorIsSlash)
Definition SidTuneBase.cpp:97
libsidplayfp::SmartPtr_sidtt
Definition SmartPtr.h:193
libsidplayfp::loadError
Definition SidTuneBase.h:49
libsidplayfp::sidmemory
Definition sidmemory.h:34