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 #include "NstManager.hpp" 26 #include "NstDialogDipSwitches.hpp" 27 #include "NstManagerDipSwitches.hpp" 28 29 namespace Nestopia 30 { 31 namespace Managers 32 { DipSwitches(Emulator & e,const Configuration & cfg,Window::Menu & m)33 DipSwitches::DipSwitches(Emulator& e,const Configuration& cfg,Window::Menu& m) 34 : Manager(e,m,this,&DipSwitches::OnEmuEvent) 35 { 36 static const Window::Menu::CmdHandler::Entry<DipSwitches> commands[] = 37 { 38 { IDM_MACHINE_EXT_DIPSWITCHES, &DipSwitches::OnCmdDipSwitches }, 39 { IDM_MACHINE_OPTIONS_DIPSWITCHESONLOAD, &DipSwitches::OnCmdDipSwitchesOnLoad } 40 }; 41 42 menu.Commands().Add( this, commands ); 43 44 static const Window::Menu::PopupHandler::Entry<DipSwitches> popups[] = 45 { 46 { Window::Menu::PopupHandler::Pos<IDM_POS_MACHINE,IDM_POS_MACHINE_EXT>::ID, &DipSwitches::OnMenuExt } 47 }; 48 49 menu.Popups().Add( this, popups ); 50 51 menu[IDM_MACHINE_OPTIONS_DIPSWITCHESONLOAD].Check( !cfg["machine"]["dip-switches-on-load"].No() ); 52 } 53 Save(Configuration & cfg) const54 void DipSwitches::Save(Configuration& cfg) const 55 { 56 cfg["machine"]["dip-switches-on-load"].YesNo() = menu[IDM_MACHINE_OPTIONS_DIPSWITCHESONLOAD].Checked(); 57 } 58 Available() const59 bool DipSwitches::Available() const 60 { 61 return 62 ( 63 Nes::DipSwitches(emulator).NumDips() && 64 !emulator.NetPlayers() && 65 !emulator.IsLocked() 66 ); 67 } 68 OpenDialog(bool userOpen) const69 bool DipSwitches::OpenDialog(bool userOpen) const 70 { 71 return Available() ? Window::DipSwitches( emulator, userOpen ).Open() : false; 72 } 73 OnMenuExt(const Window::Menu::PopupHandler::Param & param)74 void DipSwitches::OnMenuExt(const Window::Menu::PopupHandler::Param& param) 75 { 76 param.menu[IDM_MACHINE_EXT_DIPSWITCHES].Enable( !param.show || Available() ); 77 } 78 OnCmdDipSwitches(uint)79 void DipSwitches::OnCmdDipSwitches(uint) 80 { 81 OpenDialog( true ); 82 } 83 OnCmdDipSwitchesOnLoad(uint)84 void DipSwitches::OnCmdDipSwitchesOnLoad(uint) 85 { 86 menu[IDM_MACHINE_OPTIONS_DIPSWITCHESONLOAD].ToggleCheck(); 87 } 88 OnEmuEvent(const Emulator::Event event,const Emulator::Data data)89 void DipSwitches::OnEmuEvent(const Emulator::Event event,const Emulator::Data data) 90 { 91 switch (event) 92 { 93 case Emulator::EVENT_LOAD: 94 95 if (menu[IDM_MACHINE_OPTIONS_DIPSWITCHESONLOAD].Checked()) 96 { 97 if (OpenDialog( false )) 98 menu[IDM_MACHINE_OPTIONS_DIPSWITCHESONLOAD].Uncheck(); 99 } 100 101 break; 102 103 case Emulator::EVENT_NETPLAY_MODE: 104 105 menu[IDM_MACHINE_OPTIONS_DIPSWITCHESONLOAD].Enable( !data ); 106 break; 107 } 108 } 109 } 110 } 111