lsnes rr2-β24
[lsnes.git] / src / core / movie.cpp
blob6f9b8c18557ce175997dafed949a4fffb08b59dc
1 #include "lsnes.hpp"
3 #include "core/movie.hpp"
5 #include <stdexcept>
6 #include <cassert>
7 #include <cstring>
8 #include <fstream>
10 movie_logic::movie_logic() throw()
12 mf = NULL;
13 mov = NULL;
14 rrd = NULL;
17 void movie_logic::set_movie(movie& _mov, bool free_old) throw()
19 auto tmp = mov;
20 mov = &_mov;
21 if(free_old) delete tmp;
24 movie& movie_logic::get_movie() throw(std::runtime_error)
26 if(!mov)
27 throw std::runtime_error("No movie");
28 return *mov;
31 void movie_logic::set_mfile(moviefile& _mf, bool free_old) throw()
33 auto tmp = mf;
34 mf = &_mf;
35 if(free_old) delete tmp;
38 moviefile& movie_logic::get_mfile() throw(std::runtime_error)
40 if(!mf)
41 throw std::runtime_error("No movie");
42 return *mf;
45 void movie_logic::set_rrdata(rrdata_set& _rrd, bool free_old) throw()
47 auto tmp = rrd;
48 rrd = &_rrd;
49 if(free_old) delete tmp;
52 rrdata_set& movie_logic::get_rrdata() throw(std::runtime_error)
54 if(!rrd)
55 throw std::runtime_error("No movie");
56 return *rrd;
59 void movie_logic::new_frame_starting(bool dont_poll) throw(std::bad_alloc, std::runtime_error)
61 mov->next_frame();
62 portctrl::frame c = update_controls(false);
63 if(!mov->readonly_mode()) {
64 mov->set_controls(c);
65 if(!dont_poll)
66 mov->set_all_DRDY();
67 } else if(!dont_poll)
68 mov->set_all_DRDY();
71 short movie_logic::input_poll(unsigned port, unsigned dev, unsigned id) throw(std::bad_alloc, std::runtime_error)
73 if(!mov)
74 return 0;
75 //If this is for something else than 0-0-x, drop out of poll advance if any.
76 bool force = false;
77 if(port || dev) force = notify_user_poll();
78 if(!mov->get_DRDY(port, dev, id) || force) {
79 mov->set_controls(update_controls(true, force));
80 mov->set_all_DRDY();
82 return mov->next_input(port, dev, id);
85 void movie_logic::release_memory()
87 delete rrd;
88 rrd = NULL;
89 delete mov;
90 mov = NULL;
91 delete mf;
92 mf = NULL;