libsidplayfp
1.0.3
|
00001 /* 00002 * This file is part of libsidplayfp, a SID player engine. 00003 * 00004 * Copyright 2011-2013 Leandro Nini <drfiemost@users.sourceforge.net> 00005 * Copyright 2007-2010 Antti Lankila 00006 * Copyright 2001-2002 by Jarno Paananen 00007 * Copyright 2000-2002 Simon White 00008 * 00009 * This program is free software; you can redistribute it and/or modify 00010 * it under the terms of the GNU General Public License as published by 00011 * the Free Software Foundation; either version 2 of the License, or 00012 * (at your option) any later version. 00013 * 00014 * This program is distributed in the hope that it will be useful, 00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 * GNU General Public License for more details. 00018 * 00019 * You should have received a copy of the GNU General Public License 00020 * along with this program; if not, write to the Free Software 00021 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00022 */ 00023 00024 #ifndef HARDSID_EMU_H 00025 #define HARDSID_EMU_H 00026 00027 #include <string> 00028 00029 #include "sidplayfp/event.h" 00030 #include "sidplayfp/sidemu.h" 00031 #include "sidplayfp/EventScheduler.h" 00032 #include "sidplayfp/siddefs.h" 00033 00034 #ifdef HAVE_CONFIG_H 00035 # include "config.h" 00036 #endif 00037 00038 #ifdef _WIN32 00039 00040 #include <windows.h> 00041 00042 #define HSID_VERSION_MIN (WORD) 0x0200 00043 #define HSID_VERSION_204 (WORD) 0x0204 00044 #define HSID_VERSION_207 (WORD) 0x0207 00045 00046 //************************************************************************** 00047 // Version 2 Interface 00048 typedef void (CALLBACK* HsidDLL2_Delay_t) (BYTE deviceID, WORD cycles); 00049 typedef BYTE (CALLBACK* HsidDLL2_Devices_t) (); 00050 typedef void (CALLBACK* HsidDLL2_Filter_t) (BYTE deviceID, BOOL filter); 00051 typedef void (CALLBACK* HsidDLL2_Flush_t) (BYTE deviceID); 00052 typedef void (CALLBACK* HsidDLL2_Mute_t) (BYTE deviceID, BYTE channel, BOOL mute); 00053 typedef void (CALLBACK* HsidDLL2_MuteAll_t) (BYTE deviceID, BOOL mute); 00054 typedef void (CALLBACK* HsidDLL2_Reset_t) (BYTE deviceID); 00055 typedef BYTE (CALLBACK* HsidDLL2_Read_t) (BYTE deviceID, WORD cycles, BYTE SID_reg); 00056 typedef void (CALLBACK* HsidDLL2_Sync_t) (BYTE deviceID); 00057 typedef void (CALLBACK* HsidDLL2_Write_t) (BYTE deviceID, WORD cycles, BYTE SID_reg, BYTE data); 00058 typedef WORD (CALLBACK* HsidDLL2_Version_t) (); 00059 00060 // Version 2.04 Extensions 00061 typedef BOOL (CALLBACK* HsidDLL2_Lock_t) (BYTE deviceID); 00062 typedef void (CALLBACK* HsidDLL2_Unlock_t) (BYTE deviceID); 00063 typedef void (CALLBACK* HsidDLL2_Reset2_t) (BYTE deviceID, BYTE volume); 00064 00065 // Version 2.07 Extensions 00066 typedef void (CALLBACK* HsidDLL2_Mute2_t) (BYTE deviceID, BYTE channel, BOOL mute, BOOL manual); 00067 00068 struct HsidDLL2 00069 { 00070 HINSTANCE Instance; 00071 HsidDLL2_Delay_t Delay; 00072 HsidDLL2_Devices_t Devices; 00073 HsidDLL2_Filter_t Filter; 00074 HsidDLL2_Flush_t Flush; 00075 HsidDLL2_Lock_t Lock; 00076 HsidDLL2_Unlock_t Unlock; 00077 HsidDLL2_Mute_t Mute; 00078 HsidDLL2_Mute2_t Mute2; 00079 HsidDLL2_MuteAll_t MuteAll; 00080 HsidDLL2_Reset_t Reset; 00081 HsidDLL2_Reset2_t Reset2; 00082 HsidDLL2_Read_t Read; 00083 HsidDLL2_Sync_t Sync; 00084 HsidDLL2_Write_t Write; 00085 WORD Version; 00086 }; 00087 00088 #endif // _WIN32 00089 00090 #define HARDSID_VOICES 3 00091 // Approx 60ms 00092 #define HARDSID_DELAY_CYCLES 60000 00093 00094 /*************************************************************************** 00095 * HardSID SID Specialisation 00096 ***************************************************************************/ 00097 class HardSID : public sidemu, private Event 00098 { 00099 private: 00100 friend class HardSIDBuilder; 00101 00102 // HardSID specific data 00103 #ifndef _WIN32 00104 static bool m_sidFree[16]; 00105 int m_handle; 00106 #endif 00107 00108 static const unsigned int voices; 00109 static unsigned int sid; 00110 00111 static std::string m_credit; 00112 00113 00114 // Generic variables 00115 EventContext *m_eventContext; 00116 event_clock_t m_accessClk; 00117 std::string m_errorBuffer; 00118 00119 // Must stay in this order 00120 bool muted[HARDSID_VOICES]; 00121 unsigned int m_instance; 00122 bool m_status; 00123 bool m_locked; 00124 00125 public: 00126 static const char* getCredits(); 00127 00128 public: 00129 HardSID(sidbuilder *builder); 00130 ~HardSID(); 00131 00132 // Standard component functions 00133 const char *credits () const { return getCredits(); } 00134 00135 void reset() { sidemu::reset (); } 00136 void reset(uint8_t volume); 00137 00138 uint8_t read(uint_least8_t addr); 00139 void write(uint_least8_t addr, uint8_t data); 00140 00141 void clock(); 00142 const char *error() const { return m_errorBuffer.c_str(); } 00143 bool getStatus() const { return m_status; } 00144 00145 // Standard SID functions 00146 void filter(bool enable); 00147 void model(SidConfig::sid_model_t model SID_UNUSED) {;} 00148 void voice(unsigned int num, bool mute); 00149 // HardSID specific 00150 void flush(); 00151 00152 // Must lock the SID before using the standard functions. 00153 bool lock(EventContext *env); 00154 void unlock(); 00155 00156 private: 00157 // Fixed interval timer delay to prevent sidplay2 00158 // shoot to 100% CPU usage when song nolonger 00159 // writes to SID. 00160 void event(); 00161 }; 00162 00163 #endif // HARDSID_EMU_H