Actually call on_reset callback
[lsnes.git] / src / core / movie.cpp
blob40d67d69169f2ccd2c68a466e0ab3f9afd49ada9
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 frob_with_value = [](unsigned a, unsigned b, unsigned c, unsigned d) {};
13 mf = NULL;
14 mov = NULL;
15 rrd = NULL;
18 void movie_logic::set_movie(movie& _mov, bool free_old) throw()
20 auto tmp = mov;
21 mov = &_mov;
22 mov->set_frob_with_value(frob_with_value);
23 if(free_old) delete tmp;
26 movie& movie_logic::get_movie()
28 if(!mov)
29 throw std::runtime_error("No movie");
30 return *mov;
33 void movie_logic::set_mfile(moviefile& _mf, bool free_old) throw()
35 auto tmp = mf;
36 mf = &_mf;
37 if(free_old) delete tmp;
40 moviefile& movie_logic::get_mfile()
42 if(!mf)
43 throw std::runtime_error("No movie");
44 return *mf;
47 void movie_logic::set_rrdata(rrdata_set& _rrd, bool free_old) throw()
49 auto tmp = rrd;
50 rrd = &_rrd;
51 if(free_old) delete tmp;
54 rrdata_set& movie_logic::get_rrdata()
56 if(!rrd)
57 throw std::runtime_error("No movie");
58 return *rrd;
61 void movie_logic::new_frame_starting(bool dont_poll)
63 mov->next_frame();
64 portctrl::frame c = update_controls(false);
65 if(!mov->readonly_mode()) {
66 mov->set_controls(c);
67 if(!dont_poll)
68 mov->set_all_DRDY();
69 } else if(!dont_poll)
70 mov->set_all_DRDY();
73 short movie_logic::input_poll(unsigned port, unsigned dev, unsigned id)
75 if(!mov)
76 return 0;
77 //If this is for something else than 0-0-x, drop out of poll advance if any.
78 bool force = false;
79 if(port || dev) force = notify_user_poll();
80 if(!mov->get_DRDY(port, dev, id) || force) {
81 mov->set_controls(update_controls(true, force));
82 mov->set_all_DRDY();
84 return mov->next_input(port, dev, id);
87 void movie_logic::release_memory()
89 delete rrd;
90 rrd = NULL;
91 delete mov;
92 mov = NULL;
93 delete mf;
94 mf = NULL;
97 void movie_logic::set_frob_with_value(std::function<void(unsigned,unsigned,unsigned,short&)> func)
99 frob_with_value = func;
100 if(mov) mov->set_frob_with_value(func);