1 #include "core/advdumper.hpp"
2 #include "core/audioapi.hpp"
3 #include "core/command.hpp"
4 #include "core/controllerframe.hpp"
5 #include "core/controller.hpp"
6 #include "core/debug.hpp"
7 #include "core/dispatch.hpp"
8 #include "core/emustatus.hpp"
9 #include "core/framebuffer.hpp"
10 #include "core/framerate.hpp"
11 #include "core/instance.hpp"
12 #include "core/inthread.hpp"
13 #include "core/jukebox.hpp"
14 #include "core/keymapper.hpp"
15 #include "core/mbranch.hpp"
16 #include "core/memorymanip.hpp"
17 #include "core/memorywatch.hpp"
18 #include "core/messages.hpp"
19 #include "core/misc.hpp"
20 #include "core/moviedata.hpp"
21 #include "core/movie.hpp"
22 #include "core/multitrack.hpp"
23 #include "core/project.hpp"
24 #include "core/queue.hpp"
25 #include "core/random.hpp"
26 #include "core/rom.hpp"
27 #include "core/runmode.hpp"
28 #include "core/settings.hpp"
29 #include "fonts/wrapper.hpp"
30 #include "library/command.hpp"
31 #include "library/framebuffer.hpp"
32 #include "library/keyboard.hpp"
33 #include "library/keyboard-mapper.hpp"
34 #include "library/lua-base.hpp"
35 #include "library/memoryspace.hpp"
36 #include "library/settingvar.hpp"
37 #include "lua/lua.hpp"
44 dtor_list::dtor_list()
49 dtor_list::~dtor_list()
54 void dtor_list::destroy()
56 dtor_list::entry
* e
= list
;
63 dtor_list::entry
* f
= e
;
71 emulator_instance::emulator_instance()
83 D
.init(iqueue
, *command
);
85 D
.init(slotcache
, *mlogic
, *command
);
89 D
.init(lua2
, *lua
, *command
, *settings
);
90 D
.init(mwatch
, *memory
, *project
, *fbuf
, *rom
);
91 D
.init(jukebox
, *settings
, *command
);
92 D
.init(setcache
, *settings
);
94 D
.init(commentary
, *settings
, *dispatch
, *audio
, *command
);
95 D
.init(subtitles
, *mlogic
, *fbuf
, *dispatch
, *command
);
96 D
.init(mbranch
, *mlogic
, *dispatch
, *supdater
);
97 D
.init(controls
, *project
, *mlogic
, *buttons
, *dispatch
, *supdater
, *command
);
99 D
.init(mapper
, *keyboard
, *command
);
101 D
.init(fbuf
, *subtitles
, *settings
, *mwatch
, *keyboard
, *dispatch
, *lua2
, *rom
, *supdater
, *command
,
103 D
.init(buttons
, *controls
, *mapper
, *keyboard
, *fbuf
, *dispatch
, *lua2
, *command
);
104 D
.init(mteditor
, *mlogic
, *controls
, *dispatch
, *supdater
, *buttons
, *command
);
108 D
.init(status
, *status_A
, *status_B
, *status_C
);
109 D
.init(abindmanager
, *mapper
, *command
);
111 D
.init(cmapper
, *memory
, *mlogic
, *rom
);
112 D
.init(project
, *commentary
, *mwatch
, *command
, *controls
, *settings
, *buttons
, *dispatch
, *iqueue
, *rom
,
114 D
.init(dbg
, *dispatch
, *rom
, *memory
, *command
);
115 D
.init(framerate
, *command
);
116 D
.init(mdumper
, *lua2
);
118 D
.init(supdater
, *project
, *mlogic
, *commentary
, *status
, *runmode
, *mdumper
, *jukebox
, *slotcache
,
119 *framerate
, *controls
, *mteditor
, *lua2
, *rom
, *mwatch
, *dispatch
);
121 status_A
->valid
= false;
122 status_B
->valid
= false;
123 status_C
->valid
= false;
124 command
->add_set(lsnes_cmds
);
125 mapper
->add_invbind_set(lsnes_invbinds
);
126 settings
->add_set(lsnes_setgrp
);
127 dispatch
->set_error_streams(&messages
.getstream());
128 random_seed_value
= 0;
131 emulator_instance::~emulator_instance()
136 emulator_instance lsnes_instance
;
138 emulator_instance
& CORE()
140 if(threads::id() != lsnes_instance
.emu_thread
) {
141 std::cerr
<< "WARNING: CORE() called in wrong thread." << std::endl
;
144 backtrace_symbols_fd(arr
, 256, 2);
147 return lsnes_instance
;
152 uint32_t digits(size_t num
)
154 if(num
< 10) return 1;
155 return 1 + digits(num
/ 10);
158 command::fnptr
<> CMD_memory_use(lsnes_cmds
, "show-memory", "Show memory usage",
159 "show-memory\nShow memory usage",
160 []() throw(std::bad_alloc
, std::runtime_error
) {
161 auto report
= memtracker::singleton().report();
162 uint32_t maxwidth_left
= 0;
163 uint32_t maxwidth_right
= 0;
164 for(auto i
: report
) {
165 maxwidth_left
= std::max(maxwidth_left
, main_font
.get_width(i
.first
));
166 maxwidth_right
= std::max(maxwidth_right
, digits(i
.second
));
168 for(auto i
: report
) {
169 uint32_t pad_spaces
= maxwidth_left
- main_font
.get_width(i
.first
) + maxwidth_right
-
170 digits(i
.second
) + 1;
171 messages
<< i
.first
<< std::string(pad_spaces
, ' ') << i
.second
<< std::endl
;