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 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405
|
////////////////////////////////////////////////////////////////////////////////////////
//
// 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_CARTRIDGE_H
#define NST_API_CARTRIDGE_H
#include <iosfwd>
#include <string>
#include <vector>
#include "NstApiInput.hpp"
#include "NstApiMachine.hpp"
#ifdef NST_PRAGMA_ONCE
#pragma once
#endif
#if NST_MSVC >= 1200
#pragma warning( push )
#pragma warning( disable : 4512 )
#endif
namespace Nes
{
namespace Api
{
/**
* Cartridge interface.
*/
class Cartridge : public Base
{
struct ChooseProfileCaller;
public:
/**
* Interface constructor.
*
* @param instance emulator instance
*/
template<typename T>
Cartridge(T& instance)
: Base(instance) {}
/**
* Cartridge profile context.
**/
struct Profile
{
Profile() throw();
~Profile() throw();
/**
* Hash checksum.
*
* Stores SHA-1 and CRC-32 combined or just one of the two.
*/
class Hash : public Core::ImplicitBool<Hash>
{
public:
enum
{
SHA1_LENGTH = 40,
SHA1_WORD_LENGTH = SHA1_LENGTH / 8,
CRC32_LENGTH = 8,
CRC32_WORD_LENGTH = CRC32_LENGTH / 8
};
/**
* Default constructor.
*/
Hash() throw();
/**
* Constructs new checksum from null-terminated strings.
*
* @param sha SHA-1 string, set to NULL if values shouldn't be used
* @param crc CRC-32 string, set to NULL if value shouldn't be used
*/
Hash(const char* sha,const char* crc) throw();
/**
* Constructs new checksum from null-terminated wide-strings.
*
* @param sha SHA-1 string, set to NULL if values shouldn't be used
* @param crc CRC-32 string, set to NULL if value shouldn't be used
*/
Hash(const wchar_t* sha,const wchar_t* crc) throw();
/**
* Constructs new checksum from input values.
*
* @param sha SHA-1 value, set to NULL if values shouldn't be used
* @param crc CRC-32 value, set to 0 if value shouldn't be used
*/
Hash(const dword* sha,dword crc) throw();
/**
* Tests for less-than.
*
* @param hash hash to compare with
* @return true if input hash is less than this
*/
bool operator < (const Hash& hash) const throw();
/**
* Tests for equality.
*
* @param hash hash to compare with
* @return true if hashes are equal
*/
bool operator == (const Hash& hash) const throw();
/**
* Checks if checksum is cleared.
*
* @return true if cleared
*/
bool operator ! () const throw();
/**
* Computes and updates checksum from input.
*
* @param mem pointer to memory
* @param length length of memory in bytes
*/
void Compute(const void* mem,ulong length) throw();
/**
* Assigns new checksum from null-terminated strings.
*
* @param sha SHA-1 string, set to NULL if values shouldn't be used
* @param crc CRC-32 string, set to NULL if value shouldn't be used
*/
void Assign(const char* sha,const char* crc) throw();
/**
* Assigns new checksum from null-terminated wide-strings.
*
* @param sha SHA-1 string, set to NULL if values shouldn't be used
* @param crc CRC-32 string, set to NULL if value shouldn't be used
*/
void Assign(const wchar_t* sha,const wchar_t* crc) throw();
/**
* Assigns new checksum from input values.
*
* @param sha SHA-1 value, set to NULL if values shouldn't be used
* @param crc CRC-32 value, set to 0 if value shouldn't be used
*/
void Assign(const dword* sha,dword crc) throw();
/**
* Returns the current checksum.
*
* @param sha SHA-1 string to be filled, set to to NULL if not needed
* @param crc CRC-32 string to be filled, set to NULL if not needed
*/
void Get(char* sha,char* crc) const throw();
/**
* Clears the current checksum.
*/
void Clear() throw();
/**
* Returns the current SHA-1 values.
*
* @return SHA-1 values, zero-filled if unused
*/
const dword* GetSha1() const throw();
/**
* Returns the current CRC-32 value.
*
* @return CRC-32 value, 0 if unused
*/
dword GetCrc32() const throw();
private:
template<typename T>
void Import(const T*,const T*);
template<typename T>
static bool Set(dword&,const T* NST_RESTRICT);
dword data[CRC32_WORD_LENGTH+SHA1_WORD_LENGTH];
};
/**
* Game context.
*/
struct Game
{
Game() throw();
/**
* Game title.
*/
std::wstring title;
/**
* Alternative game title.
*/
std::wstring altTitle;
/**
* Class.
*/
std::wstring clss;
/**
* Sub-class.
*/
std::wstring subClss;
/**
* Catalog.
*/
std::wstring catalog;
/**
* Publisher.
*/
std::wstring publisher;
/**
* Developer.
*/
std::wstring developer;
/**
* Port Developer.
*/
std::wstring portDeveloper;
/**
* Region.
*/
std::wstring region;
/**
* Revision.
*/
std::wstring revision;
/**
* Utilized controller adapter.
*/
Input::Adapter adapter;
/**
* Utilized controllers.
*/
Input::Type controllers[5];
/**
* Number of players.
*/
uint players;
};
/**
* Dump context.
*/
struct Dump
{
Dump() throw();
/**
* Dump state type.
*/
enum State
{
/**
* Good dump.
*/
OK,
/**
* Bad dump.
*/
BAD,
/**
* Unknown dump.
*/
UNKNOWN
};
/**
* Dumped by.
*/
std::wstring by;
/**
* Dump date.
*/
std::wstring date;
/**
* Dump state.
*/
State state;
};
/**
* System context.
*/
struct System
{
System() throw();
/**
* System Type.
*/
enum Type
{
/**
* NES NTSC console.
*/
NES_NTSC = Core::SYSTEM_NES_NTSC,
/**
* NES PAL console.
*/
NES_PAL = Core::SYSTEM_NES_PAL,
/**
* NES PAL-A console.
*/
NES_PAL_A = Core::SYSTEM_NES_PAL_A,
/**
* NES PAL-B console.
*/
NES_PAL_B = Core::SYSTEM_NES_PAL_B,
/**
* Famicom console.
*/
FAMICOM = Core::SYSTEM_FAMICOM,
/**
* Dendy console (clone).
*/
DENDY = Core::SYSTEM_DENDY,
/**
* Vs UniSystem arcade.
*/
VS_UNISYSTEM = Core::SYSTEM_VS_UNISYSTEM,
/**
* Vs DualSystem arcade.
*/
VS_DUALSYSTEM = Core::SYSTEM_VS_DUALSYSTEM,
/**
* PlayChoice-10 arcade.
*/
PLAYCHOICE_10 = Core::SYSTEM_PLAYCHOICE_10
};
/**
* CPU type.
*/
enum Cpu
{
/**
* RP2A03 NTSC CPU.
*/
CPU_RP2A03 = Core::CPU_RP2A03,
/**
* RP2A07 PAL CPU.
*/
CPU_RP2A07 = Core::CPU_RP2A07,
/**
* Dendy CPU (clone).
*/
CPU_DENDY = Core::CPU_DENDY
};
/**
* PPU type.
*/
enum Ppu
{
/**
* RP2C02 NTSC PPU.
*/
PPU_RP2C02 = Core::PPU_RP2C02,
/**
* RP2C03B RGB PPU.
*/
PPU_RP2C03B = Core::PPU_RP2C03B,
/**
* RP2C03G RGB PPU.
*/
PPU_RP2C03G = Core::PPU_RP2C03G,
/**
* RP2C04-0001 RGB PPU.
*/
PPU_RP2C04_0001 = Core::PPU_RP2C04_0001,
/**
* RP2C04-0002 RGB PPU.
*/
PPU_RP2C04_0002 = Core::PPU_RP2C04_0002,
/**
* RP2C04-0003 RGB PPU.
*/
PPU_RP2C04_0003 = Core::PPU_RP2C04_0003,
/**
* RP2C04-0004 RGB PPU.
*/
PPU_RP2C04_0004 = Core::PPU_RP2C04_0004,
/**
* RC2C03B RGB PPU.
*/
PPU_RC2C03B = Core::PPU_RC2C03B,
/**
* RC2C03C RGB PPU.
*/
PPU_RC2C03C = Core::PPU_RC2C03C,
/**
* RC2C05-01 RGB PPU.
*/
PPU_RC2C05_01 = Core::PPU_RC2C05_01,
/**
* RC2C05-02 RGB PPU.
*/
PPU_RC2C05_02 = Core::PPU_RC2C05_02,
/**
* RC2C05-03 RGB PPU.
*/
PPU_RC2C05_03 = Core::PPU_RC2C05_03,
/**
* RC2C05-04 RGB PPU.
*/
PPU_RC2C05_04 = Core::PPU_RC2C05_04,
/**
* RC2C05-05 RGB PPU.
*/
PPU_RC2C05_05 = Core::PPU_RC2C05_05,
/**
* RP2C07 PAL PPU.
*/
PPU_RP2C07 = Core::PPU_RP2C07,
/**
* Dendy PPU (clone).
*/
PPU_DENDY = Core::PPU_DENDY
};
/**
* System type.
*/
Type type;
/**
* CPU type.
*/
Cpu cpu;
/**
* PPU type.
*/
Ppu ppu;
};
/**
* Cartridge property.
*/
struct Property
{
/**
* Name.
*/
std::wstring name;
/**
* Value.
*/
std::wstring value;
};
/**
* Cartridge properties.
*/
typedef std::vector<Property> Properties;
/**
* Board context.
*/
class Board
{
template<typename T>
dword GetComponentSize(const T&) const;
template<typename T>
bool HasComponentBattery(const T&) const;
public:
Board() throw();
~Board() throw();
/**
* Returns total size of PRG-ROM.
*
* @return size
*/
dword GetPrg() const throw();
/**
* Returns total size of CHR-ROM.
*
* @return size
*/
dword GetChr() const throw();
/**
* Returns total size of W-RAM.
*
* @return size
*/
dword GetWram() const throw();
/**
* Returns total size of V-RAM.
*
* @return size
*/
dword GetVram() const throw();
/**
* Returns battery status.
*
* @return true if a battery is present
*/
bool HasBattery() const throw();
/**
* Returns W-RAM battery status.
*
* @return true if a battery is present and connected to W-RAM
*/
bool HasWramBattery() const throw();
/**
* Returns custom chip battery status.
*
* @return true if a battery is present and connected to a custom chip
*/
bool HasMmcBattery() const throw();
enum
{
SOLDERPAD_H = 0x1,
SOLDERPAD_V = 0x2,
NO_MAPPER = 0xFFFF
};
/**
* Pin context.
*/
struct Pin
{
Pin() throw();
/**
* Pin number.
*/
uint number;
/**
* Pin function.
*/
std::wstring function;
};
/**
* Pins.
*/
typedef std::vector<Pin> Pins;
/**
* Analogue sound sample context.
*/
struct Sample
{
Sample() throw();
/**
* Sound sample id.
*/
uint id;
/**
* Sound sample file.
*/
std::wstring file;
};
/**
* Analogue sound samples.
*/
typedef std::vector<Sample> Samples;
/**
* ROM chip.
*/
struct Rom
{
Rom() throw();
/**
* ROM chip ID.
*/
dword id;
/**
* ROM chip size.
*/
dword size;
/**
* ROM chip name.
*/
std::wstring name;
/**
* File pointing to ROM chip.
*/
std::wstring file;
/**
* ROM chip package method.
*/
std::wstring package;
/**
* ROM chip pins.
*/
Pins pins;
/**
* ROM chip checksum.
*/
Hash hash;
};
/**
* RAM chip.
*/
struct Ram
{
Ram() throw();
/**
* RAM chip ID.
*/
dword id;
/**
* RAM chip size.
*/
dword size;
/**
* File pointing to RAM chip.
*/
std::wstring file;
/**
* RAM chip package method.
*/
std::wstring package;
/**
* RAM chip pins.
*/
Pins pins;
/**
* Battery connected to RAM chip.
*/
bool battery;
};
/**
* Custom chip.
*/
struct Chip
{
Chip() throw();
/**
* Custom chip type.
*/
std::wstring type;
/**
* File pointing to custom chip.
*/
std::wstring file;
/**
* Custom chip package type.
*/
std::wstring package;
/**
* Custom chip pins.
*/
Pins pins;
/**
* Analogue sound samples for custom chip.
*/
Samples samples;
/**
* battery connected to custom chip.
*/
bool battery;
};
/**
* ROM chips.
*/
typedef std::vector<Rom> Roms;
/**
* RAM chips.
*/
typedef std::vector<Ram> Rams;
/**
* Custom chips.
*/
typedef std::vector<Chip> Chips;
/**
* PRG-ROM chips.
*/
typedef Roms Prg;
/**
* CHR-ROM chips.
*/
typedef Roms Chr;
/**
* W-RAM chips.
*/
typedef Rams Wram;
/**
* V-RAM chips.
*/
typedef Rams Vram;
/**
* Board type.
*/
std::wstring type;
/**
* CIC type.
*/
std::wstring cic;
/**
* Board PCB name.
*/
std::wstring pcb;
/**
* PRG-ROM.
*/
Prg prg;
/**
* CHR-ROM.
*/
Chr chr;
/**
* W-RAM.
*/
Wram wram;
/**
* V-RAM.
*/
Vram vram;
/**
* Custom chips.
*/
Chips chips;
/**
* Solder pads.
*/
uint solderPads;
/**
* Mapper ID.
*/
uint mapper;
/**
* Submapper ID.
*/
uint subMapper;
/**
* CHR RAM Size.
*/
uint chrRam;
};
/**
* Hash of ROM chips combined.
*/
Hash hash;
/**
* Dump context.
*/
Dump dump;
/**
* Game context.
*/
Game game;
/**
* System context.
*/
System system;
/**
* Board context.
*/
Board board;
/**
* Properties.
*/
Properties properties;
/**
* Multi-region game.
*/
bool multiRegion;
/**
* Soft-patching state.
*/
bool patched;
};
/**
* Database interface
*/
class Database
{
Core::Machine& emulator;
bool Create();
public:
/**
* Interface constructor.
*
* @param instance emulator instance
*/
Database(Core::Machine& instance)
: emulator(instance) {}
/**
* Database entry.
*/
class Entry : public Core::ImplicitBool<Entry>
{
public:
/**
* Returns the profile of this entry.
*
* @param profile object to be filled
* @return result code
*/
Result GetProfile(Profile& profile) const throw();
/**
* Returns the game title.
*
* @return game title or empty string on invalid entry
*/
const wchar_t* GetTitle() const throw();
/**
* Returns the target region.
*
* @return target region or empty string on invalid entry
*/
const wchar_t* GetRegion() const throw();
/**
* Returns the target system.
*
* @return target system
*/
Profile::System::Type GetSystem() const throw();
/**
* Checks if the game targets multiple regions.
*
* @return true if targeting multiple regions
*/
bool IsMultiRegion () const throw();
/**
* Returns hash code of ROM chips combined.
*
* @return hash code or NULL on invalid entry
*/
const Profile::Hash* GetHash() const throw();
/**
* Returns total size of PRG-ROM.
*
* @return size or 0 on invalid entry
*/
dword GetPrgRom() const throw();
/**
* Returns total size of CHR-ROM.
*
* @return size or 0 on invalid entry
*/
dword GetChrRom() const throw();
/**
* Returns total size of W-RAM.
*
* @return size or 0 on invalid entry
*/
uint GetWram() const throw();
/**
* Returns total size of V-RAM.
*
* @return size or 0 on invalid entry
*/
uint GetVram() const throw();
/**
* Returns mapper ID.
*
* @return mapper ID or 0 on invalid entry
*/
uint GetMapper() const throw();
/**
* Returns battery status.
*
* @return true if a battery is present
*/
bool HasBattery() const throw();
/**
* Returns the dump state.
*
* @return dump state
*/
Profile::Dump::State GetDumpState() const throw();
private:
friend class Database;
const void* ref;
Entry(const void* r)
: ref(r) {}
public:
/**
* Default constructor.
*/
Entry()
: ref(NULL) {}
/**
* Checks if entry is invalid.
*
* @return true if invalid
*/
bool operator ! () const
{
return !ref;
}
};
/**
* Resets and loads internal XML database.
*
* @param stream input stream
* @return result code
*/
Result Load(std::istream& stream) throw();
/**
* Resets and loads internal <b>and</b> external XML databases.
*
* @param streamInternal input stream to internal XML database
* @param streamExternal input stream to external XML database
* @return result code
*/
Result Load(std::istream& streamInternal,std::istream& streamExternal) throw();
/**
* Removes all databases from the system.
*/
void Unload() throw();
/**
* Enables image corrections.
*
* @param state true to enable, default is true
* @return result code
*/
Result Enable(bool state=true) throw();
/**
* Checks if image corrections are enabled.
*
* @return true if enabled
*/
bool IsEnabled() const throw();
/**
* Checks if any database has been loaded into the system.
*
* @return true if loaded
*/
bool IsLoaded() const throw();
/**
* Attempts to locate and return an entry from one of the databases.
*
* @param hash hash code of combined ROMs
* @param system preferred system in case of multiple profiles
* @return entry found
*/
Entry FindEntry(const Profile::Hash& hash,Machine::FavoredSystem system) const throw();
/**
* Attempts to locate and return an entry from one of the databases.
*
* @param mem pointer to memory of combined ROMs
* @param size size of memory
* @param system preferred system in case of multiple profiles
* @return entry found
*/
Entry FindEntry(const void* mem,ulong size,Machine::FavoredSystem system) const throw();
};
/**
* iNES header format context.
*/
struct NesHeader
{
NesHeader() throw();
/**
* Clears settings.
*/
void Clear() throw();
/**
* Imports settings from iNES file header in memory.
*
* @param pointer to iNES header at least 16 byte in size
* @param size size of memory
* @return result code
*/
Result Import(const void* mem,ulong size) throw();
/**
* Exports settings to iNES file header in memory.
*
* @param pointer to iNES header at least 16 byte in size
* @param size size of memory
* @return result code
*/
Result Export(void* mem,ulong size) const throw();
enum
{
MAX_PRG_ROM = 0x4000 * 0xFFFUL,
MAX_CHR_ROM = 0x2000 * 0xFFFUL
};
/**
* Region type.
*/
enum Region
{
/**
* NTSC only.
*/
REGION_NTSC = 1,
/**
* PAL only.
*/
REGION_PAL,
/**
* Both PAL and NTSC.
*/
REGION_BOTH
};
/**
* System type.
*/
enum System
{
/**
* Console.
*/
SYSTEM_CONSOLE,
/**
* Vs System
*/
SYSTEM_VS,
/**
* PlayChoice-10
*/
SYSTEM_PC10
};
/**
* PPU type.
*/
enum Ppu
{
/**
* RP2C02 NTSC PPU.
*/
PPU_RP2C02 = Core::PPU_RP2C02,
/**
* RP2C03B RGB PPU.
*/
PPU_RP2C03B = Core::PPU_RP2C03B,
/**
* RP2C03G RGB PPU.
*/
PPU_RP2C03G = Core::PPU_RP2C03G,
/**
* RP2C04-0001 RGB PPU.
*/
PPU_RP2C04_0001 = Core::PPU_RP2C04_0001,
/**
* RP2C04-0002 RGB PPU.
*/
PPU_RP2C04_0002 = Core::PPU_RP2C04_0002,
/**
* RP2C04-0003 RGB PPU.
*/
PPU_RP2C04_0003 = Core::PPU_RP2C04_0003,
/**
* RP2C04-0004 RGB PPU.
*/
PPU_RP2C04_0004 = Core::PPU_RP2C04_0004,
/**
* RC2C03B RGB PPU.
*/
PPU_RC2C03B = Core::PPU_RC2C03B,
/**
* RC2C03C RGB PPU.
*/
PPU_RC2C03C = Core::PPU_RC2C03C,
/**
* RC2C05-01 RGB PPU.
*/
PPU_RC2C05_01 = Core::PPU_RC2C05_01,
/**
* RC2C05-02 RGB PPU.
*/
PPU_RC2C05_02 = Core::PPU_RC2C05_02,
/**
* RC2C05-03 RGB PPU.
*/
PPU_RC2C05_03 = Core::PPU_RC2C05_03,
/**
* RC2C05-04 RGB PPU.
*/
PPU_RC2C05_04 = Core::PPU_RC2C05_04,
/**
* RC2C05-05 RGB PPU.
*/
PPU_RC2C05_05 = Core::PPU_RC2C05_05,
/**
* RP2C07 PAL PPU.
*/
PPU_RP2C07 = Core::PPU_RP2C07
};
/**
* Name-table mirroring type.
*/
enum Mirroring
{
/**
* Horizontal mirroring.
*/
MIRRORING_HORIZONTAL,
/**
* Vertical mirroring.
*/
MIRRORING_VERTICAL,
/**
* Four-screen mirroring.
*/
MIRRORING_FOURSCREEN,
/**
* Single-screen mirroring.
*/
MIRRORING_SINGLESCREEN,
/**
* Software-controlled mirroring.
*/
MIRRORING_CONTROLLED
};
/**
* System.
*/
System system;
/**
* Region.
*/
Region region;
/**
* PRG-ROM size.
*/
dword prgRom;
/**
* volatile PRG-RAM (aka W-RAM) size.
*/
dword prgRam;
/**
* Non-volatile PRG-RAM (aka W-RAM) size.
*/
dword prgNvRam;
/**
* CHR-ROM size.
*/
dword chrRom;
/**
* volatile CHR-RAM (aka V-RAM) size.
*/
dword chrRam;
/**
* Non-volatile CHR-RAM (aka V-RAM) size.
*/
dword chrNvRam;
/**
* PPU.
*/
Ppu ppu;
/**
* Name-table mirroring.
*/
Mirroring mirroring;
/**
* Mapper ID.
*/
ushort mapper;
/**
* Sub-mapper ID.
*/
uchar subMapper;
/**
* iNES version number.
*/
uchar version;
/**
* Vs System security bits.
*/
uchar security;
/**
* Trainer.
*/
bool trainer;
};
/**
* Returns the current cartridge profile.
*
* @return pointer to current profile, NULL if no cartridge has been loaded into the system
*/
const Profile* GetProfile() const throw();
/**
* Creates a profile of an XML ROM set file.
*
* @param stream input stream to XML file
* @param system preferred system in case of multiple profiles
* @param askProfile allow callback triggering for choosing between multiple profiles
* @param profile object to be filled
* @return result code
*/
static Result ReadRomset(std::istream& stream,Machine::FavoredSystem system,bool askProfile,Profile& profile) throw();
/**
* Creates a profile of an iNES file.
*
* @param stream input stream to iNES file
* @param system preferred system in case of multiple profiles
* @param profile object to be filled
* @return result code
*/
static Result ReadInes(std::istream& stream,Machine::FavoredSystem system,Profile& profile) throw();
/**
* Creates a profile of a UNIF file.
*
* @param stream input stream to UNIF file
* @param system preferred system in case of multiple profiles
* @param profile object to be filled
* @return result code
*/
static Result ReadUnif(std::istream& stream,Machine::FavoredSystem system,Profile& profile) throw();
/**
* Returns the database interface.
*
* @return database interface
*/
Database GetDatabase() throw()
{
return emulator;
}
enum
{
CHOOSE_DEFAULT_PROFILE = INT_MAX
};
/**
* Cartridge profile chooser callback prototype.
*
* @param userData optional user data
* @param profiles pointer to an array of profiles
* @param profileNames pointer to a wide-string array of profile names
* @param numProfiles number of profiles to choose between
* @return array index of chosen profile
*/
typedef uint (NST_CALLBACK *ChooseProfileCallback) (UserData userData,const Profile* profiles,const std::wstring* profileNames,uint numProfiles);
/**
* Cartridge profile chooser callback manager.
*
* Static object used for adding the user defined callback.
*/
static ChooseProfileCaller chooseProfileCallback;
};
/**
* Cartridge profile chooser callback invoker.
*
* Used internally by the core.
*/
struct Cartridge::ChooseProfileCaller : Core::UserCallback<Cartridge::ChooseProfileCallback>
{
uint operator () (const Profile* profiles,const std::wstring* names,uint count) const
{
return function ? function( userdata, profiles, names, count ) : CHOOSE_DEFAULT_PROFILE;
}
};
}
}
#if NST_MSVC >= 1200
#pragma warning( pop )
#endif
#endif
|