Fix SA1 open bus
[lsnes.git] / src / core / advdumper.cpp
blob6f8dc9827a492caf74c7456f3be9ac4a063fb0d1
1 #include "core/advdumper.hpp"
2 #include "core/command.hpp"
3 #include "core/dispatch.hpp"
4 #include "library/globalwrap.hpp"
5 #include "lua/lua.hpp"
6 #include "library/string.hpp"
8 #include <map>
9 #include <string>
11 namespace
13 globalwrap<std::map<std::string, adv_dumper*>> dumpers;
16 const std::string& adv_dumper::id() throw()
18 return d_id;
21 adv_dumper::~adv_dumper()
23 dumpers().erase(d_id);
24 information_dispatch::do_dumper_update();
27 std::set<adv_dumper*> adv_dumper::get_dumper_set() throw(std::bad_alloc)
29 std::set<adv_dumper*> d;
30 for(auto i : dumpers())
31 d.insert(i.second);
32 return d;
35 adv_dumper::adv_dumper(const std::string& id) throw(std::bad_alloc)
37 d_id = id;
38 dumpers()[d_id] = this;
41 unsigned adv_dumper::target_type_mask = 3;
42 unsigned adv_dumper::target_type_file = 0;
43 unsigned adv_dumper::target_type_prefix = 1;
44 unsigned adv_dumper::target_type_special = 2;
46 template<bool X> bool render_video_hud(struct framebuffer::fb<X>& target, struct framebuffer::raw& source, uint32_t hscl,
47 uint32_t vscl, uint32_t lgap, uint32_t tgap, uint32_t rgap, uint32_t bgap, void(*fn)())
49 bool lua_kill_video = false;
50 struct lua_render_context lrc;
51 framebuffer::queue rq;
52 lrc.left_gap = lgap;
53 lrc.right_gap = rgap;
54 lrc.bottom_gap = bgap;
55 lrc.top_gap = tgap;
56 lrc.queue = &rq;
57 lrc.width = source.get_width();
58 lrc.height = source.get_height();
59 lua_callback_do_video(&lrc, lua_kill_video, hscl, vscl);
60 if(fn)
61 fn();
62 target.reallocate(lrc.left_gap + source.get_width() * hscl + lrc.right_gap, lrc.top_gap +
63 source.get_height() * vscl + lrc.bottom_gap, false);
64 target.set_origin(lrc.left_gap, lrc.top_gap);
65 target.copy_from(source, hscl, vscl);
66 rq.run(target);
67 return !lua_kill_video;
70 uint64_t killed_audio_length(uint32_t fps_n, uint32_t fps_d, double& fraction)
72 auto g = information_dispatch::get_sound_rate();
73 double x = 1.0 * fps_d * g.first / (fps_n * g.second) + fraction;
74 uint64_t y = x;
75 fraction = x - y;
76 return y;
79 template bool render_video_hud(struct framebuffer::fb<false>& target, struct framebuffer::raw& source, uint32_t hscl,
80 uint32_t vscl, uint32_t lgap, uint32_t tgap, uint32_t rgap, uint32_t bgap, void(*fn)());
81 template bool render_video_hud(struct framebuffer::fb<true>& target, struct framebuffer::raw& source, uint32_t hscl,
82 uint32_t vscl, uint32_t lgap, uint32_t tgap, uint32_t rgap, uint32_t bgap, void(*fn)());