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 <new>
26 #include "../NstMachine.hpp"
27 #include "NstApiMachine.hpp"
28 #include "NstApiRewinder.hpp"
29 
30 namespace Nes
31 {
32 	namespace Api
33 	{
34 		#ifdef NST_MSVC_OPTIMIZE
35 		#pragma optimize("s", on)
36 		#endif
37 
38 		Rewinder::StateCaller Rewinder::stateCallback;
39 
Enable(bool enable)40 		Result Rewinder::Enable(bool enable) throw()
41 		{
42 			try
43 			{
44 				return emulator.tracker.EnableRewinder( enable ? &emulator : NULL );
45 			}
46 			catch (Result result)
47 			{
48 				return result;
49 			}
50 			catch (const std::bad_alloc&)
51 			{
52 				return RESULT_ERR_OUT_OF_MEMORY;
53 			}
54 			catch (...)
55 			{
56 				return RESULT_ERR_GENERIC;
57 			}
58 		}
59 
IsEnabled() const60 		bool Rewinder::IsEnabled() const throw()
61 		{
62 			return emulator.tracker.IsRewinderEnabled();
63 		}
64 
IsSoundEnabled() const65 		bool Rewinder::IsSoundEnabled() const throw()
66 		{
67 			return emulator.tracker.IsRewinderSoundEnabled();
68 		}
69 
EnableSound(bool enable)70 		void Rewinder::EnableSound(bool enable) throw()
71 		{
72 			emulator.tracker.EnableRewinderSound( enable );
73 		}
74 
GetDirection() const75 		Rewinder::Direction Rewinder::GetDirection() const throw()
76 		{
77 			return emulator.tracker.IsRewinding() ? BACKWARD : FORWARD;
78 		}
79 
SetDirection(Direction dir)80 		Result Rewinder::SetDirection(Direction dir) throw()
81 		{
82 			if (emulator.Is(Machine::GAME,Machine::ON))
83 			{
84 				if (dir == BACKWARD)
85 					return emulator.tracker.StartRewinding();
86 				else
87 					return emulator.tracker.StopRewinding();
88 			}
89 
90 			return RESULT_ERR_NOT_READY;
91 		}
92 
Reset()93 		void Rewinder::Reset() throw()
94 		{
95 			if (emulator.Is(Machine::GAME,Machine::ON))
96 				emulator.tracker.ResetRewinder();
97 		}
98 
99 		#ifdef NST_MSVC_OPTIMIZE
100 		#pragma optimize("", on)
101 		#endif
102 	}
103 }
104