1 //////////////////////////////////////////////////////////////////////////////////////// 2 // 3 // Nestopia - NES/Famicom emulator written in C++ 4 // 5 // Copyright (C) 2003-2008 Martin Freij 6 // 7 // This file is part of Nestopia. 8 // 9 // Nestopia is free software; you can redistribute it and/or modify 10 // it under the terms of the GNU General Public License as published by 11 // the Free Software Foundation; either version 2 of the License, or 12 // (at your option) any later version. 13 // 14 // Nestopia is distributed in the hope that it will be useful, 15 // but WITHOUT ANY WARRANTY; without even the implied warranty of 16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 // GNU General Public License for more details. 18 // 19 // You should have received a copy of the GNU General Public License 20 // along with Nestopia; if not, write to the Free Software 21 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 // 23 //////////////////////////////////////////////////////////////////////////////////////// 24 25 #ifndef NST_API_NSF_H 26 #define NST_API_NSF_H 27 28 #include "NstApi.hpp" 29 30 #ifdef NST_PRAGMA_ONCE 31 #pragma once 32 #endif 33 34 #if NST_ICC >= 810 35 #pragma warning( push ) 36 #pragma warning( disable : 444 ) 37 #elif NST_MSVC >= 1200 38 #pragma warning( push ) 39 #pragma warning( disable : 4512 ) 40 #endif 41 42 namespace Nes 43 { 44 namespace Api 45 { 46 /** 47 * NES Sound Files interface. 48 */ 49 class Nsf : public Base 50 { 51 struct EventCaller; 52 53 public: 54 55 /** 56 * Interface constructor. 57 * 58 * @param instance emulator instance 59 */ 60 template<typename T> Nsf(T & instance)61 Nsf(T& instance) 62 : Base(instance) {} 63 64 enum 65 { 66 NO_SONG = -1 67 }; 68 69 /** 70 * Tune mode. 71 */ 72 enum TuneMode 73 { 74 /** 75 * NTSC only. 76 */ 77 TUNE_MODE_NTSC, 78 /** 79 * PAL only. 80 */ 81 TUNE_MODE_PAL, 82 /** 83 * Both NTSC and PAL. 84 */ 85 TUNE_MODE_BOTH 86 }; 87 88 enum 89 { 90 CHIP_VRC6 = 0x01, 91 CHIP_VRC7 = 0x02, 92 CHIP_FDS = 0x04, 93 CHIP_MMC5 = 0x08, 94 CHIP_N163 = 0x10, 95 CHIP_S5B = 0x20, 96 CHIP_ALL = 0x3F 97 }; 98 99 /** 100 * Returns the name of the NSF. 101 * 102 * @return name or empty string if NSF hasn't been loaded 103 */ 104 const char* GetName() const throw(); 105 106 /** 107 * Returns the name of the artists. 108 * 109 * @return artist names or empty string if NSF hasn't been loaded 110 */ 111 const char* GetArtist() const throw(); 112 113 /** 114 * Returns the copyright string. 115 * 116 * @return copyright or empty string if NSF hasn't been loaded 117 */ 118 const char* GetCopyright() const throw(); 119 120 /** 121 * Return the tune mode. 122 * 123 * @return tune mode 124 */ 125 TuneMode GetMode() const throw(); 126 127 /** 128 * Returns the init-address. 129 * 130 * @return address 131 */ 132 uint GetInitAddress() const throw(); 133 134 /** 135 * Returns the load-address. 136 * 137 * @return address 138 */ 139 uint GetLoadAddress() const throw(); 140 141 /** 142 * Returns the play-address. 143 * 144 * @return address 145 */ 146 uint GetPlayAddress() const throw(); 147 148 /** 149 * Returns the total number of songs. 150 * 151 * @return number 152 */ 153 uint GetNumSongs() const throw(); 154 155 /** 156 * Returns the current song index. 157 * 158 * @return song index or NO_SONG if NSF hasn't been loaded 159 */ 160 int GetCurrentSong() const throw(); 161 162 /** 163 * Returns the starting song index. 164 * 165 * @return song index or NO_SONG if NSF hasn't been loaded 166 */ 167 int GetStartingSong() const throw(); 168 169 /** 170 * Returns the OR:ed chips in use. 171 * 172 * @return OR:ed chips used 173 */ 174 uint GetChips() const throw(); 175 176 /** 177 * Checks if a song is currently being played. 178 * 179 * @return true if playing 180 */ 181 bool IsPlaying() const throw(); 182 183 /** 184 * Checks if the NSF uses bank-switching. 185 * 186 * @return true if NSF uses bank-switching 187 */ 188 bool UsesBankSwitching() const throw(); 189 190 /** 191 * Selects a song. 192 * 193 * @param song index 194 * @return result code 195 */ 196 Result SelectSong(uint song) throw(); 197 198 /** 199 * Selects the next song. 200 * 201 * @return result code 202 */ 203 Result SelectNextSong() throw(); 204 205 /** 206 * Selects the previous song. 207 * 208 * @return result code 209 */ 210 Result SelectPrevSong() throw(); 211 212 /** 213 * Plays current selected song. 214 * 215 * @return result code 216 */ 217 Result PlaySong() throw(); 218 219 /** 220 * Stops current selected song. 221 * 222 * @return result code 223 */ 224 Result StopSong() throw(); 225 226 /** 227 * Event. 228 */ 229 enum Event 230 { 231 /** 232 * A new song has been selected. 233 */ 234 EVENT_SELECT_SONG, 235 /* 236 * Song has started playing. 237 */ 238 EVENT_PLAY_SONG, 239 /** 240 * Song has stopped playing. 241 */ 242 EVENT_STOP_SONG 243 }; 244 245 enum 246 { 247 NUM_EVENT_CALLBACKS = 3 248 }; 249 250 /** 251 * Event callback prototype. 252 * 253 * @param userData optional user data 254 * @param event type of event 255 */ 256 typedef void (NST_CALLBACK *EventCallback) (UserData userData,Event event); 257 258 /** 259 * Event callback manager. 260 * 261 * Static object used for adding the user defined callback. 262 */ 263 static EventCaller eventCallback; 264 }; 265 266 /** 267 * Song event callback invoker. 268 * 269 * Used internally by the core. 270 */ 271 struct Nsf::EventCaller : Core::UserCallback<Nsf::EventCallback> 272 { operator ()Nes::Api::Nsf::EventCaller273 void operator () (Event event) const 274 { 275 if (function) 276 function( userdata, event ); 277 } 278 }; 279 } 280 } 281 282 #if NST_MSVC >= 1200 || NST_ICC >= 810 283 #pragma warning( pop ) 284 #endif 285 286 #endif 287