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_CARTRIDGE_H 26 #define NST_CARTRIDGE_H 27 28 #include "NstRam.hpp" 29 #include "NstImage.hpp" 30 #include "NstFile.hpp" 31 #include "api/NstApiCartridge.hpp" 32 33 #ifdef NST_PRAGMA_ONCE 34 #pragma once 35 #endif 36 37 namespace Nes 38 { 39 namespace Core 40 { 41 namespace Boards 42 { 43 class Board; 44 } 45 46 class Cartridge : public Image 47 { 48 public: 49 50 explicit Cartridge(Context&); 51 52 void BeginFrame(const Api::Input&,Input::Controllers*); 53 54 typedef Api::Cartridge::Profile Profile; 55 56 static void ReadRomset(std::istream&,FavoredSystem,bool,Profile&); 57 static void ReadInes(std::istream&,FavoredSystem,Profile&); 58 static void ReadUnif(std::istream&,FavoredSystem,Profile&); 59 60 class Ines; 61 class Unif; 62 class Romset; 63 64 private: 65 66 ~Cartridge(); 67 68 struct ProfileEx 69 { 70 ProfileEx(); 71 72 enum Nmt 73 { 74 NMT_DEFAULT, 75 NMT_HORIZONTAL, 76 NMT_VERTICAL, 77 NMT_SINGLESCREEN, 78 NMT_FOURSCREEN, 79 NMT_CONTROLLED 80 }; 81 82 Nmt nmt; 83 bool battery; 84 bool wramAuto; 85 Ram trainer; 86 }; 87 88 class VsSystem; 89 90 static Result SetupBoard 91 ( 92 Ram&, 93 Ram&, 94 Boards::Board**, 95 const Context*, 96 Profile&, 97 const ProfileEx&, 98 dword*, 99 bool=false 100 ); 101 102 void Reset(bool); 103 bool PowerOff(); 104 void LoadState(State::Loader&); 105 void SaveState(State::Saver&,dword) const; 106 void Destroy(); 107 void VSync(); 108 109 uint GetDesiredController(uint) const; 110 uint GetDesiredAdapter() const; 111 void DetectControllers(uint); 112 Region GetDesiredRegion() const; 113 System GetDesiredSystem(Region,CpuModel*,PpuModel*) const; 114 115 ExternalDevice QueryExternalDevice(ExternalDeviceType); 116 117 Boards::Board* board; 118 VsSystem* vs; 119 Ram prg; 120 Ram chr; 121 Profile profile; 122 dword prgCrc; 123 File savefile; 124 const FavoredSystem favoredSystem; 125 126 public: 127 GetProfile() const128 const Profile& GetProfile() const 129 { 130 return profile; 131 } 132 GetPrgCrc() const133 dword GetPrgCrc() const 134 { 135 return prgCrc; 136 } 137 }; 138 } 139 } 140 141 #endif 142