1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481
|
////////////////////////////////////////////////////////////////////////////////////////
//
// Nestopia - NES/Famicom emulator written in C++
//
// Copyright (C) 2003-2008 Martin Freij
//
// This file is part of Nestopia.
//
// Nestopia 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.
//
// Nestopia 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 Nestopia; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
////////////////////////////////////////////////////////////////////////////////////////
#ifndef NST_API_USER_H
#define NST_API_USER_H
#include <iosfwd>
#include "NstApi.hpp"
#ifdef NST_PRAGMA_ONCE
#pragma once
#endif
#if NST_ICC >= 810
#pragma warning( push )
#pragma warning( disable : 304 444 )
#elif NST_MSVC >= 1200
#pragma warning( push )
#pragma warning( disable : 4512 )
#endif
namespace Nes
{
namespace Api
{
/**
* User IO interfaces.
*/
class User : public Base
{
struct LogCaller;
struct EventCaller;
struct QuestionCaller;
struct FileIoCaller;
public:
/**
* Interface constructor.
*
* @param instance emulator instance
*/
template<typename T>
User(T& instance)
: Base(instance) {}
/**
* User questions.
*/
enum Question
{
/**
* Whether to proceed or abort if CRC validation fails when loading a save state.
*/
QUESTION_NST_PRG_CRC_FAIL_CONTINUE = 1,
/**
* Whether to proceed or abort if CRC validation fails when playing a move.
*/
QUESTION_NSV_PRG_CRC_FAIL_CONTINUE
};
/**
* User answer.
*/
enum Answer
{
/**
* No.
*/
ANSWER_NO,
/**
* Yes.
*/
ANSWER_YES,
/**
* Default answer (default).
*/
ANSWER_DEFAULT
};
/**
* User events.
*/
enum Event
{
/**
* CPU jam.
*/
EVENT_CPU_JAM = 1,
/**
* Can display an in-game timer.
*/
EVENT_DISPLAY_TIMER,
/**
* An unofficial CPU opcode was executed.
*/
EVENT_CPU_UNOFFICIAL_OPCODE
};
/**
* File IO interface.
*/
struct File
{
/**
* Action event.
*/
enum Action
{
/**
* For loading battery-backed RAM into a cartridge.
*/
LOAD_BATTERY = 1,
/**
* For saving the battery-backed RAM in a cartridge.
*/
SAVE_BATTERY,
/**
* For patching a Famicom Disk System image.
*/
LOAD_FDS,
/**
* For saving a modified Famicom Disk System image to patch or directly to image.
*/
SAVE_FDS,
/**
* For loading EEPROM into a cartridge.
*/
LOAD_EEPROM,
/**
* For saving the EEPROM in a cartridge.
*/
SAVE_EEPROM,
/**
* For loading cassette tape recording.
*/
LOAD_TAPE,
/**
* For saving the cassette tape recording.
*/
SAVE_TAPE,
/**
* For loading Turbo File device data.
*/
LOAD_TURBOFILE,
/**
* For saving Turbo File device data.
*/
SAVE_TURBOFILE,
/**
* For loading ROM into a cartridge.
*/
LOAD_ROM,
/**
* For loading raw PCM audio samples.
*/
LOAD_SAMPLE,
/**
* For loading raw PCM audio samples used in Moero Pro Yakyuu.
*/
LOAD_SAMPLE_MOERO_PRO_YAKYUU,
/**
* For loading raw PCM audio samples used in Moero Pro Yakyuu 88.
*/
LOAD_SAMPLE_MOERO_PRO_YAKYUU_88,
/**
* For loading raw PCM audio samples used in Moero Pro Tennis.
*/
LOAD_SAMPLE_MOERO_PRO_TENNIS,
/**
* For loading raw PCM audio samples used in Terao No Dosukoi Oozumou.
*/
LOAD_SAMPLE_TERAO_NO_DOSUKOI_OOZUMOU,
/**
* For loading raw PCM audio samples used in Aerobics Studio.
*/
LOAD_SAMPLE_AEROBICS_STUDIO
};
/**
* Supported patch formats.
*/
enum Patch
{
/**
* UPS.
*/
PATCH_UPS,
/**
* IPS.
*/
PATCH_IPS
};
/**
* Returns type of action.
*
* @return action
*/
virtual Action GetAction() const throw() = 0;
/**
* Returns the name of the file to load.
*
* Used only with the LOAD_ROM and LOAD_SAMPLE action callbacks.
*
* @return filename
*/
virtual const wchar_t* GetName() const throw();
/**
* Returns the sound file ID to load.
*
* Used only with the LOAD_SAMPLE_xx action callbacks.
*
* @return sample id
*/
virtual uint GetId() const throw();
/**
* Returns the maximum allowed size for the content to load.
*
* Used only with the LOAD_xx action callbacks.
*
* @return max size
*/
virtual ulong GetMaxSize() const throw();
/**
* Saves the content into an output stream.
*
* Used only with the SAVE_xx action callbacks.
*
* @param stream output stream
* @param result code
*/
virtual Result GetContent(std::ostream& stream) const throw();
/**
* Returns a pointer to the content to be saved and its size.
*
* Used only with the SAVE_xx action callbacks.
*
* @param mem pointer to content
* @param size size of content
* @param result code
*/
virtual Result GetContent(const void*& mem,ulong& size) const throw();
/**
* Saves the patch content into an output stream.
*
* Used only with the FDS_SAVE action callback.
*
* @param patch patch format to use
* @param stream output stream
*/
virtual Result GetPatchContent(Patch patch,std::ostream& stream) const throw();
/**
* Loads content into the core through stream.
*
* Used only with the LOAD_xx action callbacks.
* This method can't be used for audio or patch content. Instead, use LoadSampleContent(..)
* and SetPatchContent(..) for those.
*
* @param stream input stream
* @return result code
*/
virtual Result SetContent(std::istream& stream) throw();
/**
* Loads content into the core.
*
* Used only with the LOAD_xx action callbacks.
* This method can't be used for audio or patch content. Instead, use LoadSampleContent(..)
* and SetPatchContent(..) for those.
*
* @param mem content
* @param size size of content
* @return result code
*/
virtual Result SetContent(const void* mem,ulong size) throw();
/**
* Loads patch content into the core.
*
* Used only with LOAD_FDS action callback.
*
* @param stream input stream to patch
* @return result code
*/
virtual Result SetPatchContent(std::istream& stream) throw();
/**
* Loads audio content into the core.
*
* Used only with the LOAD_SAMPLE and LOAD_SAMPLE_xx action callbacks.
*
* @param mem sample content
* @param length number of samples
* @param stereo dual channel if true
* @param bits bits per sample
* @param rate sample rate
* @return result code
*/
virtual Result SetSampleContent(const void* mem,ulong length,bool stereo,uint bits,ulong rate) throw();
/**
* Gets raw backed data of file.
*
* Used with LOAD_BATTERY to get a raw, persistent pointer to backed data,
* which can be freely written or read from.
* Returns non-NULL pointer in data if backed data is not contigous.
*
* @param data pointer to raw storage
* @param size size of raw storage
*/
virtual void GetRawStorage(void*& data, ulong& size) const throw();
};
enum
{
NUM_QUESTION_CALLBACKS = 2,
NUM_EVENT_CALLBACKS = 3,
NUM_FILE_CALLBACKS = 17
};
/**
* Logfile callback prototype.
*
* @param userData optional user data
* @param string string content
* @param length string length
*/
typedef void (NST_CALLBACK *LogCallback) (UserData userData,const char* string,ulong length);
/**
* Logfile callback prototype.
*
* @param userData optional user data
* @param event type of event
* @param context context depending on event
*/
typedef void (NST_CALLBACK *EventCallback) (UserData userData,Event event,const void* context);
/**
* User question callback prototype.
*
* @param userData optional user data
* @param question type of question
* @return user answer
*/
typedef Answer (NST_CALLBACK *QuestionCallback) (UserData userData,Question question);
/**
* File IO callback prototype.
*
* @param userData optional user data
* @param file File IO interface
*/
typedef void (NST_CALLBACK *FileIoCallback) (UserData userData,File& file);
/**
* Logfile callback manager.
*
* Static object used for adding the user defined callback.
*/
static LogCaller logCallback;
/**
* User event callback manager.
*
* Static object used for adding the user defined callback.
*/
static EventCaller eventCallback;
/**
* User question callback manager.
*
* Static object used for adding the user defined callback.
*/
static QuestionCaller questionCallback;
/**
* File IO callback manager.
*
* Static object used for adding the user defined callback.
*/
static FileIoCaller fileIoCallback;
};
/**
* Logfile callback invoker.
*
* Used internally by the core.
*/
struct User::LogCaller : Core::UserCallback<User::LogCallback>
{
void operator () (const char* text,ulong length) const
{
if (function)
function( userdata, text, length );
}
template<ulong N>
void operator () (const char (&c)[N]) const
{
(*this)( c, N-1 );
}
};
/**
* User event callback invoker.
*
* Used internally by the core.
*/
struct User::EventCaller : Core::UserCallback<User::EventCallback>
{
void operator () (Event event,const void* data=0) const
{
if (function)
function( userdata, event, data );
}
};
/**
* User question callback invoker.
*
* Used internally by the core.
*/
struct User::QuestionCaller : Core::UserCallback<User::QuestionCallback>
{
Answer operator () (Question question) const
{
return function ? function( userdata, question ) : ANSWER_DEFAULT;
}
};
/**
* File IO callback invoker.
*
* Used internally by the core.
*/
struct User::FileIoCaller : Core::UserCallback<User::FileIoCallback>
{
void operator () (File& file) const
{
if (function)
function( userdata, file );
}
};
}
}
#if NST_MSVC >= 1200 || NST_ICC >= 810
#pragma warning( pop )
#endif
#endif
|