Fix SA1 open bus
[lsnes.git] / src / core / movie.cpp
blobcb1f689fd901b542d9bbe3c4ccd156f13e47c4bb
1 #include "lsnes.hpp"
3 #include "core/misc.hpp"
4 #include "core/movie.hpp"
5 #include "core/rom.hpp"
6 #include "interface/romtype.hpp"
8 #include <stdexcept>
9 #include <cassert>
10 #include <cstring>
11 #include <fstream>
13 struct moviefile cur_mf;
14 movie_logic movb;
16 movie_logic::movie_logic() throw()
18 mf = NULL;
19 mov = NULL;
20 rrd = NULL;
23 void movie_logic::set_movie(movie& _mov, bool free_old) throw()
25 auto tmp = mov;
26 mov = &_mov;
27 if(free_old) delete tmp;
30 movie& movie_logic::get_movie() throw(std::runtime_error)
32 if(!mov)
33 throw std::runtime_error("No movie");
34 return *mov;
37 void movie_logic::set_mfile(moviefile& _mf, bool free_old) throw()
39 auto tmp = mf;
40 mf = &_mf;
41 if(free_old) delete tmp;
44 moviefile& movie_logic::get_mfile() throw(std::runtime_error)
46 if(!mf)
47 throw std::runtime_error("No movie");
48 return *mf;
51 void movie_logic::set_rrdata(rrdata_set& _rrd, bool free_old) throw()
53 auto tmp = rrd;
54 rrd = &_rrd;
55 if(free_old) delete tmp;
58 rrdata_set& movie_logic::get_rrdata() throw(std::runtime_error)
60 if(!rrd)
61 throw std::runtime_error("No movie");
62 return *rrd;
65 void movie_logic::new_frame_starting(bool dont_poll) throw(std::bad_alloc, std::runtime_error)
67 mov->next_frame();
68 controller_frame c = update_controls(false);
69 if(!mov->readonly_mode()) {
70 mov->set_controls(c);
71 if(!dont_poll)
72 mov->set_all_DRDY();
73 } else if(!dont_poll)
74 mov->set_all_DRDY();
77 short movie_logic::input_poll(unsigned port, unsigned dev, unsigned id) throw(std::bad_alloc, std::runtime_error)
79 if(!mov)
80 return 0;
81 if(!mov->get_DRDY(port, dev, id)) {
82 mov->set_controls(update_controls(true));
83 mov->set_all_DRDY();
85 int16_t in = mov->next_input(port, dev, id);
86 //std::cerr << "BSNES asking for (" << port << "," << dev << "," << id << ") (frame "
87 // << mov->get_current_frame() << ") giving " << in << std::endl;
88 return in;
91 void movie_logic::release_memory()
93 delete rrd;
94 rrd = NULL;
95 delete mov;
96 mov = NULL;
97 delete mf;
98 mf = NULL;