1 /* 2 * This file is part of libsidplayfp, a SID player engine. 3 * 4 * Copyright 2011-2019 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 SIDPLAYFP_H 24 #define SIDPLAYFP_H 25 26 #include <stdint.h> 27 #include <stdio.h> 28 #include <vector> 29 30 #include "sidplayfp/siddefs.h" 31 #include "sidplayfp/sidversion.h" 32 33 class SidConfig; 34 class SidTune; 35 class SidInfo; 36 class EventContext; 37 38 // Private Sidplayer 39 namespace libsidplayfp 40 { 41 class Player; 42 } 43 44 /** 45 * sidplayfp 46 */ 47 class SID_EXTERN sidplayfp 48 { 49 private: 50 libsidplayfp::Player &sidplayer; 51 52 public: 53 sidplayfp(); 54 ~sidplayfp(); 55 56 /** 57 * Get the current engine configuration. 58 * 59 * @return a const reference to the current configuration. 60 */ 61 const SidConfig &config() const; 62 63 /** 64 * Get the current player informations. 65 * 66 * @return a const reference to the current info. 67 */ 68 const SidInfo &info() const; 69 70 /** 71 * Configure the engine. 72 * Check #error for detailed message if something goes wrong. 73 * 74 * @param cfg the new configuration 75 * @return true on success, false otherwise. 76 */ 77 bool config(const SidConfig &cfg); 78 79 /** 80 * Error message. 81 * 82 * @return string error message. 83 */ 84 const char *error() const; 85 86 /** 87 * Set the fast-forward factor. 88 * 89 * @param percent 90 */ 91 bool fastForward(unsigned int percent); 92 93 /** 94 * Load a tune. 95 * Check #error for detailed message if something goes wrong. 96 * 97 * @param tune the SidTune to load, 0 unloads current tune. 98 * @return true on sucess, false otherwise. 99 */ 100 bool load(SidTune *tune); 101 102 /** 103 * Run the emulation and produce samples to play if a buffer is given. 104 * 105 * @param buffer pointer to the buffer to fill with samples. 106 * @param count the size of the buffer measured in 16 bit samples 107 * or 0 if no output is needed (e.g. Hardsid) 108 * @return the number of produced samples. If less than requested 109 * and #isPlaying() is true an error occurred, use #error() to get 110 * a detailed message. 111 */ 112 uint_least32_t play(int16_t *buffer, uint_least32_t count, std::vector<int16_t *> *rawSamples = nullptr); 113 114 /** 115 * Check if the engine is playing or stopped. 116 * 117 * @return true if playing, false otherwise. 118 */ 119 bool isPlaying() const; 120 121 /** 122 * Stop the engine. 123 */ 124 void stop(); 125 126 /** 127 * Control debugging. 128 * Only has effect if library have been compiled 129 * with the --enable-debug option. 130 * 131 * @param enable enable/disable debugging. 132 * @param out the file where to redirect the debug info. 133 */ 134 void debug(bool enable, FILE *out); 135 136 /** 137 * Mute/unmute a SID channel. 138 * 139 * @param sidNum the SID chip, 0 for the first one, 1 for the second. 140 * @param voice the channel to mute/unmute. 141 * @param enable true unmutes the channel, false mutes it. 142 */ 143 void mute(unsigned int sidNum, unsigned int voice, bool enable); 144 145 /** 146 * Get the status of the given SID chip. 147 * 148 * @param sidNum the SID chip, 0 for the first one, 1 for the second. 149 * @param gatestoggle, returns GATE changes since last time this function 150 * was called. Bit 0, if voice 1 has been enabled. Bit 1 if 151 * voice 1 has been disabled. Bit 2 and 3 for voice 2, bit 152 * 4 and 5 for voice 3. 153 * @param syncstoggle, returns SYNC changes since last time this function 154 * was called. Bit 0, if voice 1 has been enabled. Bit 1 if 155 * voice 1 has been disabled. Bit 2 and 3 for voice 2, bit 156 * 4 and 5 for voice 3. 157 * @param teststoggle, returns TEST changes since last time this function 158 * was called. Bit 0, if voice 1 has been enabled. Bit 1 if 159 * voice 1 has been disabled. Bit 2 and 3 for voice 2, bit 160 * 4 and 5 for voice 3. 161 * @param registers returns a pointer to an array 32 (only first 25 are 162 * needed) entries long that gives the last known write-status 163 * of the SID chip. 164 * @return true on sucess, false otherwise (invalid sidNum). 165 */ 166 bool getSidStatus(unsigned int sidNum, uint8_t& gatestoggle, uint8_t& syncstoggle, uint8_t& teststoggle, uint8_t **registers); 167 168 /** 169 * Get the current playing time. 170 * 171 * @return the current playing time measured in seconds. 172 */ 173 uint_least32_t time() const; 174 175 uint_least32_t timeMs() const; 176 177 /** 178 * Set ROM images. 179 * 180 * @param kernal pointer to Kernal ROM. 181 * @param basic pointer to Basic ROM, generally needed only for BASIC tunes. 182 * @param character pointer to character generator ROM. 183 */ 184 void setRoms(const uint8_t* kernal, const uint8_t* basic=0, const uint8_t* character=0); 185 186 /** 187 * Get the CIA 1 Timer A programmed value. 188 */ 189 uint_least16_t getCia1TimerA() const; 190 }; 191 192 #endif // SIDPLAYFP_H 193