4 #include "platform/wxwidgets/menu_dump.hpp"
5 #include "platform/wxwidgets/menu_upload.hpp"
6 #include "platform/wxwidgets/platform.hpp"
7 #include "platform/wxwidgets/loadsave.hpp"
8 #include "platform/wxwidgets/window_mainwindow.hpp"
9 #include "platform/wxwidgets/window_messages.hpp"
10 #include "platform/wxwidgets/window_status.hpp"
11 #include "platform/wxwidgets/window-romload.hpp"
12 #include "platform/wxwidgets/settings-common.hpp"
13 #include "platform/wxwidgets/menu_tracelog.hpp"
14 #include "platform/wxwidgets/menu_branches.hpp"
15 #include "platform/wxwidgets/menu_projects.hpp"
17 #include "cmdhelp/framebuffer.hpp"
18 #include "cmdhelp/loadsave.hpp"
19 #include "cmdhelp/lua.hpp"
20 #include "cmdhelp/subtitles.hpp"
21 #include "core/audioapi.hpp"
22 #include "core/audioapi-driver.hpp"
23 #include "core/command.hpp"
24 #include "core/controller.hpp"
25 #include "core/controllerframe.hpp"
26 #include "core/dispatch.hpp"
27 #include "core/emustatus.hpp"
28 #include "core/framebuffer.hpp"
29 #include "core/framerate.hpp"
30 #include "core/instance.hpp"
31 #include "core/keymapper.hpp"
32 #include "core/ui-services.hpp"
33 #include "interface/romtype.hpp"
34 #include "core/loadlib.hpp"
35 #include "lua/lua.hpp"
36 #include "core/mainloop.hpp"
37 #include "core/memorywatch.hpp"
38 #include "core/messages.hpp"
39 #include "core/misc.hpp"
40 #include "core/moviedata.hpp"
41 #include "core/project.hpp"
42 #include "core/rom.hpp"
43 #include "core/settings.hpp"
44 #include "core/window.hpp"
45 #include "library/directory.hpp"
46 #include "library/minmax.hpp"
47 #include "library/string.hpp"
48 #include "library/zip.hpp"
49 #if defined(_WIN32) || defined(_WIN64) || defined(TEST_WIN32_CODE)
61 #define UINT64_C(val) val##ULL
63 #include <libswscale/swscale.h>
68 wxID_PAUSE
= wxID_HIGHEST
+ 1,
86 wxID_EDIT_MEMORYWATCH
,
87 wxID_SAVE_MEMORYWATCH
,
88 wxID_LOAD_MEMORYWATCH
,
92 wxID_DUMP_LAST
= wxID_DUMP_FIRST
+ 1023,
113 wxID_RELOAD_ROM_IMAGE
,
114 wxID_LOAD_ROM_IMAGE_FIRST
,
115 wxID_LOAD_ROM_IMAGE_LAST
= wxID_LOAD_ROM_IMAGE_FIRST
+ 1023,
118 wxID_DEDICATED_MEMORY_WATCH
,
120 wxID_RMOVIE_LAST
= wxID_RMOVIE_FIRST
+ 16,
122 wxID_RROM_LAST
= wxID_RROM_FIRST
+ 16,
123 wxID_CONFLICTRESOLUTION
,
131 wxID_ENTER_FULLSCREEN
,
133 wxID_ACTIONS_LAST
= wxID_ACTIONS_FIRST
+ 256,
135 wxID_SETTINGS_LAST
= wxID_SETTINGS_FIRST
+ 256,
140 wxID_RLUA_LAST
= wxID_RLUA_FIRST
+ 16,
142 wxID_UPLOAD_LAST
= wxID_UPLOAD_FIRST
+ 256,
145 wxID_TRACELOG_LAST
= wxID_TRACELOG_FIRST
+ 256,
148 wxID_BRANCH_LAST
= wxID_BRANCH_FIRST
+ 10240,
150 wxID_PROJECT_LAST
= wxID_PROJECT_FIRST
+ 17,
155 double video_scale_factor
= 1.0;
156 int scaling_flags
= SWS_POINT
;
157 bool arcorrect_enabled
= false;
158 bool hflip_enabled
= false;
159 bool vflip_enabled
= false;
160 bool rotate_enabled
= false;
164 std::string last_volume
= "0dB";
165 std::string last_volume_record
= "0dB";
166 std::string last_volume_voice
= "0dB";
167 unsigned char* screen_buffer
;
168 struct SwsContext
* sws_ctx
;
169 uint32_t* rotate_buffer
;
172 int old_flags
= SWS_POINT
;
173 bool old_hflip
= false;
174 bool old_vflip
= false;
175 bool old_rotate
= false;
176 bool main_window_dirty
;
178 bool hashing_in_progress
= false;
179 uint64_t hashing_left
= 0;
180 uint64_t hashing_total
= 0;
181 int64_t last_update
= 0;
182 threads::thread
* emulation_thread
;
183 bool status_updated
= false;
185 settingvar::variable
<settingvar::model_bool
<settingvar::yes_no
>> background_audio(*lsnes_instance
.settings
,
186 "background-audio", "GUIā£Enable background audio", true);
188 class _status_timer
: public wxTimer
198 status_updated
= false;
199 if(main_window
) main_window
->update_statusbar();
204 void cleanup_dead_download_timers();
205 class _focus_timer
: public wxTimer
210 was_focused
= (wxWindow::FindFocus() != NULL
);
211 was_enabled
= platform::is_sound_enabled();
217 bool is_focused
= (wxWindow::FindFocus() != NULL
);
218 if(is_focused
&& !was_focused
) {
220 if(!background_audio
)
221 platform::sound_enable(was_enabled
);
222 } else if(!is_focused
&& was_focused
) {
224 was_enabled
= platform::is_sound_enabled();
225 if(!background_audio
)
226 platform::sound_enable(false);
228 was_focused
= is_focused
;
229 cleanup_dead_download_timers();
236 class download_timer
;
237 std::list
<download_timer
*> download_timer_gc_queue
;
239 class download_timer
: public wxTimer
242 download_timer(wxwin_mainwindow
* main
, emulator_instance
& _inst
)
251 if(!w
->download_in_progress
) {
252 //Received a call with download finish already done. Ignore.
255 if(w
->download_in_progress
->finished
) {
256 w
->update_statusbar();
257 auto old
= w
->download_in_progress
;
258 w
->download_in_progress
= NULL
;
259 if(old
->errormsg
!= "") {
260 show_message_ok(w
, "Error downloading movie", old
->errormsg
,
263 inst
.iqueue
->queue(CLOADSAVE::ldm
.name
, "$MEMORY:wxwidgets_download_tmp");
266 try { download_timer_gc_queue
.push_back(this); } catch(...) { Stop(); }
268 w
->update_statusbar();
272 emulator_instance
& inst
;
276 void cleanup_dead_download_timers()
278 for(auto i
: download_timer_gc_queue
) {
282 download_timer_gc_queue
.clear();
285 void hash_callback(uint64_t left
, uint64_t total
)
287 wxwin_mainwindow
* mwin
= main_window
;
288 if(left
== 0xFFFFFFFFFFFFFFFFULL
) {
289 hashing_in_progress
= false;
290 runuifun([mwin
]() { if(mwin
) mwin
->notify_update_status(); });
291 last_update
= framerate_regulator::get_utime() - 2000000;
294 hashing_in_progress
= true;
296 hashing_total
= total
;
297 int64_t this_update
= framerate_regulator::get_utime();
298 if(this_update
< last_update
- 1000000 || this_update
> last_update
+ 1000000) {
299 runuifun([mwin
]() { if(mwin
) mwin
->notify_update_status(); });
300 last_update
= this_update
;
304 std::pair
<std::string
, std::string
> lsplit(std::string l
)
306 for(unsigned i
= 0; i
< l
.length() - 3; i
++)
307 if((uint8_t)l
[i
] == 0xE2 && (uint8_t)l
[i
+ 1] == 0x80 && (uint8_t)l
[i
+ 2] == 0xA3)
308 return std::make_pair(l
.substr(0, i
), l
.substr(i
+ 3));
309 return std::make_pair("", l
);
312 recentfiles::multirom
loadreq_to_multirom(const romload_request
& req
)
314 recentfiles::multirom r
;
315 r
.packfile
= req
.packfile
;
316 r
.singlefile
= req
.singlefile
;
318 r
.system
= req
.system
;
319 r
.region
= req
.region
;
320 for(unsigned i
= 0; i
< ROM_SLOT_COUNT
; i
++)
321 if(req
.files
[i
] != "") {
322 r
.files
.resize(i
+ 1);
323 r
.files
[i
] = req
.files
[i
];
328 class system_menu
: public wxMenu
331 system_menu(wxWindow
* win
, emulator_instance
& _inst
);
333 void on_select(wxCommandEvent
& e
);
334 void update(bool light
);
336 emulator_instance
& inst
;
338 void insert_pass(int id
, const std::string
& label
);
339 void insert_act(unsigned id
, const std::string
& label
, bool dots
, bool check
);
340 wxMenu
* lookup_menu(const std::string
& key
);
342 std::map
<int, unsigned> action_by_id
;
343 std::map
<unsigned, wxMenuItem
*> item_by_action
;
344 std::map
<wxMenuItem
*, wxMenu
*> menu_by_item
;
345 std::map
<std::string
, wxMenu
*> submenu_by_name
;
346 std::map
<std::string
, wxMenuItem
*> submenui_by_name
;
347 std::set
<unsigned> toggles
;
351 wxMenu
* system_menu::lookup_menu(const std::string
& key
)
356 if(submenu_by_name
.count(key
))
357 return submenu_by_name
[key
];
360 sep
= AppendSeparator();
361 auto p
= lsplit(key
);
362 wxMenu
* into
= lookup_menu(p
.first
);
363 submenu_by_name
[key
] = new wxMenu();
364 submenui_by_name
[key
] = into
->AppendSubMenu(submenu_by_name
[key
], towxstring(p
.second
));
365 menu_by_item
[submenui_by_name
[key
]] = into
;
366 return submenu_by_name
[key
];
369 void system_menu::insert_act(unsigned id
, const std::string
& label
, bool dots
, bool check
)
373 sep
= AppendSeparator();
375 auto p
= lsplit(label
);
376 wxMenu
* into
= lookup_menu(p
.first
);
378 action_by_id
[next_id
] = id
;
379 std::string use_label
= p
.second
+ (dots
? "..." : "");
381 item_by_action
[id
] = into
->AppendCheckItem(next_id
, towxstring(use_label
));
384 item_by_action
[id
] = into
->Append(next_id
, towxstring(use_label
));
385 menu_by_item
[item_by_action
[id
]] = into
;
386 pwin
->Connect(next_id
++, wxEVT_COMMAND_MENU_SELECTED
,
387 wxCommandEventHandler(system_menu::on_select
), NULL
, this);
390 void system_menu::insert_pass(int id
, const std::string
& label
)
393 pwin
->Connect(id
, wxEVT_COMMAND_MENU_SELECTED
,
394 wxCommandEventHandler(wxwin_mainwindow::handle_menu_click
), NULL
, pwin
);
395 Append(id
, towxstring(label
));
398 system_menu::system_menu(wxWindow
* win
, emulator_instance
& _inst
)
403 insert_pass(wxID_PAUSE
, "Pause/Unpause");
404 insert_pass(wxID_FRAMEADVANCE
, "Step frame");
405 insert_pass(wxID_SUBFRAMEADVANCE
, "Step subframe");
406 insert_pass(wxID_NEXTPOLL
, "Step poll");
410 system_menu::~system_menu()
414 void system_menu::on_select(wxCommandEvent
& e
)
417 if(!action_by_id
.count(e
.GetId()))
419 unsigned act_id
= action_by_id
[e
.GetId()];
420 const interface_action
* act
= NULL
;
421 for(auto i
: inst
.rom
->get_actions())
422 if(i
->id
== act_id
) {
429 auto p
= prompt_action_params(pwin
, act
->get_title(), act
->params
);
430 inst
.iqueue
->run([this, act_id
,p
]() { this->inst
.rom
->execute_action(act_id
, p
); });
431 } catch(canceled_exception
& e
) {
432 } catch(std::bad_alloc
& e
) {
437 void system_menu::update(bool light
)
441 next_id
= wxID_ACTIONS_FIRST
;
446 for(auto i
= item_by_action
.begin(); i
!= item_by_action
.end(); i
++)
447 menu_by_item
[i
->second
]->Destroy(i
->second
);
448 for(auto i
= submenui_by_name
.rbegin(); i
!= submenui_by_name
.rend(); i
++)
449 menu_by_item
[i
->second
]->Destroy(i
->second
);
450 action_by_id
.clear();
451 item_by_action
.clear();
452 menu_by_item
.clear();
453 submenu_by_name
.clear();
454 submenui_by_name
.clear();
457 for(auto i
: inst
.rom
->get_actions())
458 insert_act(i
->id
, i
->get_title(), !i
->params
.empty(), i
->is_toggle());
460 for(auto i
: item_by_action
)
461 i
.second
->Enable(inst
.rom
->action_flags(i
.first
) & 1);
462 for(auto i
: toggles
)
463 item_by_action
[i
]->Check(inst
.rom
->action_flags(i
) & 2);
466 std::string
munge_name(const std::string
& orig
)
470 if(r
= regex("(.*)\\(([0-9]+)\\)", newname
)) {
473 sequence
= parse_value
<uint64_t>(r
[2]);
474 newname
= (stringfmt() << r
[1] << "(" << sequence
+ 1 << ")").str();
476 newname
= newname
+ "(2)";
479 newname
= newname
+ "(2)";
484 void handle_watch_load(emulator_instance
& inst
, std::map
<std::string
, std::string
>& new_watches
,
485 std::set
<std::string
>& old_watches
)
487 auto proj
= inst
.project
->get();
489 for(auto i
: new_watches
) {
490 std::string name
= i
.first
;
492 if(!old_watches
.count(name
)) {
494 if(name
!= "" && i
.second
!= "")
495 inst
.mwatch
->set(name
, i
.second
);
496 } catch(std::exception
& e
) {
497 messages
<< "Can't set memory watch '" << name
<< "': "
498 << e
.what() << std::endl
;
501 } else if(inst
.mwatch
->get_string(name
) == i
.second
)
504 name
= munge_name(name
);
508 for(auto i
: new_watches
)
510 if(i
.first
!= "" && i
.second
!= "")
511 inst
.mwatch
->set(i
.first
, i
.second
);
512 } catch(std::exception
& e
) {
513 messages
<< "Can't set memory watch '" << i
.first
<< "': "
514 << e
.what() << std::endl
;
516 for(auto i
: old_watches
)
517 if(!new_watches
.count(i
))
519 inst
.mwatch
->clear(i
);
520 } catch(std::exception
& e
) {
521 messages
<< "Can't clear memory watch '" << i
<< "': "
522 << e
.what() << std::endl
;
527 std::string
get_default_screenshot_name(emulator_instance
& inst
)
529 auto p
= inst
.project
->get();
533 auto files
= directory::enumerate(p
->directory
, ".*-[0-9]+\\.png");
534 std::set
<std::string
> numbers
;
535 for(auto i
: files
) {
538 split
= i
.find_last_of("\\/");
540 split
= i
.find_last_of("/");
542 std::string name
= i
;
543 if(split
< name
.length())
544 name
= name
.substr(split
+ 1);
545 regex_results r
= regex("(.*)-([0-9]+)\\.png", name
);
546 if(r
[1] != p
->prefix
)
548 numbers
.insert(r
[2]);
550 for(uint64_t i
= 1;; i
++) {
551 std::string candidate
= (stringfmt() << i
).str();
552 if(!numbers
.count(candidate
))
553 return p
->prefix
+ "-" + candidate
+ ".png";
558 std::string
project_prefixname(emulator_instance
& inst
, const std::string ext
)
560 auto p
= inst
.project
->get();
564 return p
->prefix
+ "." + ext
;
568 void recent_rom_selected(emulator_instance
& inst
, const recentfiles::multirom
& file
)
571 req
.packfile
= file
.packfile
;
572 req
.singlefile
= file
.singlefile
;
573 req
.core
= file
.core
;
574 req
.system
= file
.system
;
575 req
.region
= file
.region
;
576 for(unsigned i
= 0; i
< file
.files
.size() && i
< ROM_SLOT_COUNT
; i
++)
577 req
.files
[i
] = file
.files
[i
];
578 inst
.iqueue
->run_async([req
]() {
579 CORE().command
->invoke("unpause-emulator");
581 }, [](std::exception
& e
) {});
584 void recent_movie_selected(emulator_instance
& inst
, const recentfiles::path
& file
)
586 inst
.iqueue
->queue(CLOADSAVE::ldsm
.name
, file
.get_path());
589 void recent_script_selected(emulator_instance
& inst
, const recentfiles::path
& file
)
591 inst
.iqueue
->queue(CLUA::run
.name
, file
.get_path());
594 wxString
getname(emulator_instance
& inst
)
596 std::string windowname
= "lsnes rr" + lsnes_version
+ " [";
597 auto p
= inst
.project
->get();
599 windowname
= windowname
+ p
->name
;
601 windowname
= windowname
+ inst
.rom
->get_core_identifier();
602 windowname
= windowname
+ "]";
603 return towxstring(windowname
);
608 emulator_instance
* inst
;
609 struct loaded_rom rom
;
610 struct moviefile
* initial
;
611 bool load_has_to_succeed
;
614 void* emulator_main(void* _args
)
616 struct emu_args
* args
= reinterpret_cast<struct emu_args
*>(_args
);
617 auto& inst
= *args
->inst
;
619 *inst
.rom
= args
->rom
;
620 messages
<< "Using core: " << inst
.rom
->get_core_identifier() << std::endl
;
621 struct moviefile
* movie
= args
->initial
;
622 bool has_to_succeed
= args
->load_has_to_succeed
;
623 platform::flush_command_queue();
624 main_loop(*inst
.rom
, *movie
, has_to_succeed
);
625 signal_program_exit();
626 } catch(std::bad_alloc
& e
) {
628 } catch(std::exception
& e
) {
629 messages
<< "FATAL: " << e
.what() << std::endl
;
630 platform::fatal_error();
636 void join_emulator_thread()
638 emulation_thread
->join();
641 bool is_readonly_mode(emulator_instance
& inst
)
644 inst
.iqueue
->run([&ret
]() {
645 ret
= *CORE().mlogic
? CORE().mlogic
->get_movie().readonly_mode() : false;
650 void set_speed(emulator_instance
& inst
, double target
)
653 inst
.framerate
->set_speed_multiplier(std::numeric_limits
<double>::infinity());
655 inst
.framerate
->set_speed_multiplier(target
/ 100);
658 void update_preferences()
660 preferred_core
.clear();
661 for(auto i
: core_type::get_core_types()) {
662 std::string val
= i
->get_hname() + " / " + i
->get_core_identifier();
663 for(auto j
: i
->get_extensions()) {
664 std::string key
= "ext:" + j
;
665 if(core_selections
.count(key
) && core_selections
[key
] == val
)
666 preferred_core
[key
] = i
;
668 std::string key2
= "type:" + i
->get_iname();
669 if(core_selections
.count(key2
) && core_selections
[key2
] == val
)
670 preferred_core
[key2
] = i
;
674 bool is_lsnes_movie(const std::string
& filename
)
676 std::istream
* s
= NULL
;
679 s
= &zip::openrel(filename
, "");
682 if(*s
&& !strcmp(buf
, "lsmv\x1A"))
690 zip::reader
r(filename
);
691 std::istream
& s
= r
["systemid"];
696 return (s2
== "lsnes-rr1");
702 class loadfile
: public wxFileDropTarget
705 loadfile(wxwin_mainwindow
* win
, emulator_instance
& _inst
) : inst(_inst
), pwin(win
) {};
706 bool OnDropFiles(wxCoord x
, wxCoord y
, const wxArrayString
& filenames
)
710 if(filenames
.Count() == 2) {
711 std::string a
= tostdstring(filenames
[0]);
712 std::string b
= tostdstring(filenames
[1]);
713 bool amov
= is_lsnes_movie(a
);
714 bool bmov
= is_lsnes_movie(b
);
717 if(amov
) std::swap(a
, b
);
718 inst
.iqueue
->run_async([a
, b
]() {
719 CORE().command
->invoke("unpause-emulator");
723 CORE().command
->invoke(CLOADSAVE::ldsm
.name
, b
);
724 }, [](std::exception
& e
) {});
727 if(filenames
.Count() == 1) {
728 std::string a
= tostdstring(filenames
[0]);
729 bool amov
= is_lsnes_movie(a
);
731 inst
.iqueue
->queue(CLOADSAVE::ldsm
.name
, a
);
732 pwin
->recent_movies
->add(a
);
737 inst
.iqueue
->run_async([req
]() {
738 CORE().command
->invoke("unpause-emulator");
740 }, [](std::exception
& e
) {});
741 pwin
->recent_roms
->add(loadreq_to_multirom(req
));
747 emulator_instance
& inst
;
748 wxwin_mainwindow
* pwin
;
752 void boot_emulator(emulator_instance
& inst
, loaded_rom
& rom
, moviefile
& movie
, bool fscreen
)
755 update_preferences();
757 struct emu_args
* a
= new emu_args
;
760 a
->load_has_to_succeed
= false;
762 modal_pause_holder hld
;
763 emulation_thread
= new threads::thread(emulator_main
, a
);
764 main_window
= new wxwin_mainwindow(inst
, fscreen
);
766 } catch(std::bad_alloc
& e
) {
771 wxwin_mainwindow::panel::panel(wxWindow
* win
, emulator_instance
& _inst
)
772 : wxPanel(win
, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
, wxWANTS_CHARS
), inst(_inst
)
775 this->Connect(wxEVT_PAINT
, wxPaintEventHandler(panel::on_paint
), NULL
, this);
776 this->Connect(wxEVT_ERASE_BACKGROUND
, wxEraseEventHandler(panel::on_erase
), NULL
, this);
777 this->Connect(wxEVT_KEY_DOWN
, wxKeyEventHandler(panel::on_keyboard_down
), NULL
, this);
778 this->Connect(wxEVT_KEY_UP
, wxKeyEventHandler(panel::on_keyboard_up
), NULL
, this);
779 this->Connect(wxEVT_LEFT_DOWN
, wxMouseEventHandler(panel::on_mouse
), NULL
, this);
780 this->Connect(wxEVT_LEFT_UP
, wxMouseEventHandler(panel::on_mouse
), NULL
, this);
781 this->Connect(wxEVT_MIDDLE_DOWN
, wxMouseEventHandler(panel::on_mouse
), NULL
, this);
782 this->Connect(wxEVT_MIDDLE_UP
, wxMouseEventHandler(panel::on_mouse
), NULL
, this);
783 this->Connect(wxEVT_RIGHT_DOWN
, wxMouseEventHandler(panel::on_mouse
), NULL
, this);
784 this->Connect(wxEVT_RIGHT_UP
, wxMouseEventHandler(panel::on_mouse
), NULL
, this);
785 this->Connect(wxEVT_MOTION
, wxMouseEventHandler(panel::on_mouse
), NULL
, this);
786 this->Connect(wxEVT_ENTER_WINDOW
, wxMouseEventHandler(panel::on_mouse
), NULL
, this);
787 this->Connect(wxEVT_LEAVE_WINDOW
, wxMouseEventHandler(panel::on_mouse
), NULL
, this);
788 SetMinSize(wxSize(512, 448));
791 void wxwin_mainwindow::menu_start(wxString name
)
794 while(!upper
.empty())
796 current_menu
= new wxMenu();
797 menubar
->Append(current_menu
, name
);
800 void wxwin_mainwindow::menu_special(wxString name
, wxMenu
* menu
)
803 while(!upper
.empty())
805 menubar
->Append(menu
, name
);
809 wxMenuItem
* wxwin_mainwindow::menu_special_sub(wxString name
, wxMenu
* menu
)
812 return current_menu
->AppendSubMenu(menu
, name
);
815 void wxwin_mainwindow::menu_entry(int id
, wxString name
)
818 current_menu
->Append(id
, name
);
819 Connect(id
, wxEVT_COMMAND_MENU_SELECTED
,
820 wxCommandEventHandler(wxwin_mainwindow::wxwin_mainwindow::handle_menu_click
), NULL
, this);
823 void wxwin_mainwindow::menu_entry_check(int id
, wxString name
)
826 checkitems
[id
] = current_menu
->AppendCheckItem(id
, name
);
827 Connect(id
, wxEVT_COMMAND_MENU_SELECTED
,
828 wxCommandEventHandler(wxwin_mainwindow::wxwin_mainwindow::handle_menu_click
), NULL
, this);
831 void wxwin_mainwindow::menu_start_sub(wxString name
)
834 wxMenu
* old
= current_menu
;
835 upper
.push(current_menu
);
836 current_menu
= new wxMenu();
837 old
->AppendSubMenu(current_menu
, name
);
840 void wxwin_mainwindow::menu_end_sub()
842 current_menu
= upper
.top();
846 bool wxwin_mainwindow::menu_ischecked(int id
)
849 if(checkitems
.count(id
))
850 return checkitems
[id
]->IsChecked();
855 void wxwin_mainwindow::menu_check(int id
, bool newstate
)
858 if(checkitems
.count(id
))
859 return checkitems
[id
]->Check(newstate
);
864 void wxwin_mainwindow::menu_enable(int id
, bool newstate
)
867 auto item
= menubar
->FindItem(id
);
870 item
->Enable(newstate
);
873 void wxwin_mainwindow::menu_separator()
876 current_menu
->AppendSeparator();
879 void wxwin_mainwindow::panel::request_paint()
885 std::pair
<double, double> calc_scale_factors(double factor
, bool ar
, double par
)
888 return std::make_pair(factor
, factor
);
890 //Too wide, make taller.
891 return std::make_pair(factor
, factor
/ par
);
893 //Too narrow, make wider.
894 return std::make_pair(factor
* par
, factor
);
898 void wxwin_mainwindow::panel::on_paint(wxPaintEvent
& e
)
901 if(wx_escape_count
>= 3 && is_fs
) {
902 //Leave fullscreen mode.
903 main_window
->enter_or_leave_fullscreen(false);
905 inst
.fbuf
->render_framebuffer();
913 bool aux
= hflip_enabled
|| vflip_enabled
|| rotate_enabled
;
914 auto sfactors
= calc_scale_factors(video_scale_factor
, arcorrect_enabled
, inst
.rom
->get_PAR());
916 tw
= inst
.fbuf
->main_screen
.get_height() * sfactors
.second
+ 0.5;
917 th
= inst
.fbuf
->main_screen
.get_width() * sfactors
.first
+ 0.5;
919 tw
= inst
.fbuf
->main_screen
.get_width() * sfactors
.first
+ 0.5;
920 th
= inst
.fbuf
->main_screen
.get_height() * sfactors
.second
+ 0.5;
923 main_window_dirty
= false;
926 //Scale this to fullscreen.
928 wxSize screen
= main_window
->GetSize();
929 double fss
= min(1.0 * screen
.GetWidth() / tw
, 1.0 * screen
.GetHeight() / th
);
934 if(!screen_buffer
|| tw
!= old_width
|| th
!= old_height
|| scaling_flags
!= old_flags
||
935 hflip_enabled
!= old_hflip
|| vflip_enabled
!= old_vflip
|| rotate_enabled
!= old_rotate
) {
937 delete[] screen_buffer
;
938 screen_buffer
= NULL
;
941 delete[] rotate_buffer
;
942 rotate_buffer
= NULL
;
946 old_flags
= scaling_flags
;
947 old_hflip
= hflip_enabled
;
948 old_vflip
= vflip_enabled
;
949 old_rotate
= rotate_enabled
;
950 uint32_t w
= inst
.fbuf
->main_screen
.get_width();
951 uint32_t h
= inst
.fbuf
->main_screen
.get_height();
953 sws_ctx
= sws_getCachedContext(sws_ctx
, rotate_enabled
? h
: w
, rotate_enabled
? w
: h
,
954 PIX_FMT_RGBA
, tw
, th
, PIX_FMT_BGR24
, scaling_flags
, NULL
, NULL
, NULL
);
955 tw
= max(tw
, static_cast<uint32_t>(128));
956 th
= max(th
, static_cast<uint32_t>(112));
957 screen_buffer
= new unsigned char[tw
* th
* 3 + 64];
959 rotate_buffer
= new uint32_t[inst
.fbuf
->main_screen
.get_width() *
960 inst
.fbuf
->main_screen
.get_height()];
961 SetMinSize(wxSize(tw
, th
));
962 signal_resize_needed();
965 //Hflip, Vflip or rotate active.
966 size_t width
= inst
.fbuf
->main_screen
.get_width();
967 size_t height
= inst
.fbuf
->main_screen
.get_height();
968 size_t width1
= width
- 1;
969 size_t height1
= height
- 1;
970 size_t stride
= inst
.fbuf
->main_screen
.rowptr(1) - inst
.fbuf
->main_screen
.rowptr(0);
971 uint32_t* pixels
= inst
.fbuf
->main_screen
.rowptr(0);
973 for(unsigned y
= 0; y
< height
; y
++) {
974 uint32_t* pixels2
= pixels
+ (vflip_enabled
? (height1
- y
) : y
) * stride
;
975 uint32_t* dpixels
= rotate_buffer
+ (height1
- y
);
977 for(unsigned x
= 0; x
< width
; x
++)
978 dpixels
[x
* height
] = pixels2
[width1
- x
];
980 for(unsigned x
= 0; x
< width
; x
++)
981 dpixels
[x
* height
] = pixels2
[x
];
984 for(unsigned y
= 0; y
< height
; y
++) {
985 uint32_t* pixels2
= pixels
+ (vflip_enabled
? (height1
- y
) : y
) * stride
;
986 uint32_t* dpixels
= rotate_buffer
+ y
* width
;
988 for(unsigned x
= 0; x
< width
; x
++)
989 dpixels
[x
] = pixels2
[width1
- x
];
991 for(unsigned x
= 0; x
< width
; x
++)
992 dpixels
[x
] = pixels2
[x
];
997 srcs
[0] = 4 * (rotate_enabled
? inst
.fbuf
->main_screen
.get_height() :
998 inst
.fbuf
->main_screen
.get_width());
1000 srcs
[0] = 4 * inst
.fbuf
->main_screen
.get_stride();
1002 srcp
[0] = reinterpret_cast<unsigned char*>(aux
? rotate_buffer
: inst
.fbuf
->main_screen
.rowptr(0));
1003 dstp
[0] = screen_buffer
;
1004 memset(screen_buffer
, 0, tw
* th
* 3);
1005 if(inst
.fbuf
->main_screen
.get_width() && inst
.fbuf
->main_screen
.get_height())
1006 sws_scale(sws_ctx
, srcp
, srcs
, 0, rotate_enabled
? inst
.fbuf
->main_screen
.get_width() :
1007 inst
.fbuf
->main_screen
.get_height(),
1009 wxBitmap
bmp(wxImage(tw
, th
, screen_buffer
, true));
1010 dc
.DrawBitmap(bmp
, 0, 0, false);
1011 main_window_dirty
= false;
1012 main_window
->update_statusbar();
1015 void wxwin_mainwindow::panel::on_erase(wxEraseEvent
& e
)
1020 void wxwin_mainwindow::panel::on_keyboard_down(wxKeyEvent
& e
)
1023 handle_wx_keyboard(inst
, e
, true);
1026 void wxwin_mainwindow::panel::on_keyboard_up(wxKeyEvent
& e
)
1029 handle_wx_keyboard(inst
, e
, false);
1032 void wxwin_mainwindow::panel::on_mouse(wxMouseEvent
& e
)
1035 handle_wx_mouse(inst
, e
);
1038 wxwin_mainwindow::wxwin_mainwindow(emulator_instance
& _inst
, bool fscreen
)
1039 : wxFrame(NULL
, wxID_ANY
, getname(_inst
), wxDefaultPosition
, wxSize(-1, -1),
1040 wxMINIMIZE_BOX
| wxSYSTEM_MENU
| wxCAPTION
| wxCLIP_CHILDREN
| wxCLOSE_BOX
), inst(_inst
)
1043 download_in_progress
= NULL
;
1046 toplevel
= new wxFlexGridSizer(1, 2, 0, 0);
1047 toplevel
->Add(gpanel
= new panel(this, inst
), 1, wxGROW
);
1048 toplevel
->Add(spanel
= new wxwin_status::panel(this, inst
, gpanel
, 20), 1, wxGROW
);
1049 spanel_shown
= true;
1050 toplevel
->SetSizeHints(this);
1054 Connect(wxEVT_CLOSE_WINDOW
, wxCloseEventHandler(wxwin_mainwindow::on_close
));
1055 SetMenuBar(menubar
= new wxMenuBar
);
1056 SetStatusBar(statusbar
= new wxStatusBar(this));
1058 menu_start(wxT("File"));
1059 menu_start_sub(wxT("New"));
1060 menu_entry(wxID_NEW_MOVIE
, wxT("Movie..."));
1061 menu_entry(wxID_NEW_PROJECT
, wxT("Project..."));
1063 menu_start_sub(wxT("Load"));
1064 menu_entry(wxID_LOAD_STATE
, wxT("State..."));
1065 menu_entry(wxID_LOAD_MOVIE
, wxT("Movie..."));
1066 menu_entry(wxID_DOWNLOAD
, wxT("Download movie..."));
1067 if(loadlib::library::name() != "") {
1069 menu_entry(wxID_LOAD_LIBRARY
, towxstring(std::string("Load ") + loadlib::library::name()));
1070 menu_entry(wxID_PLUGIN_MANAGER
, towxstring("Plugin manager"));
1073 menu_entry(wxID_RELOAD_ROM_IMAGE
, wxT("Reload ROM"));
1074 menu_entry(wxID_LOAD_ROM_IMAGE_FIRST
, wxT("ROM..."));
1075 menu_special_sub(wxT("Multifile ROM"), loadroms
= new loadrom_menu(this, wxID_LOAD_ROM_IMAGE_FIRST
+ 1,
1076 wxID_LOAD_ROM_IMAGE_LAST
, [this](core_type
* t
) { this->do_load_rom_image(t
); }));
1077 menu_special_sub(wxT("Project"), projects
= new projects_menu(this, inst
, wxID_PROJECT_FIRST
,
1078 wxID_PROJECT_LAST
, get_config_path() + "/recent-projects.txt", [this](const std::string
& id
) {
1079 this->project_selected(id
); }));
1081 menu_special_sub(wxT("Recent ROMs"), recent_roms
= new recent_menu
<recentfiles::multirom
>(this, inst
,
1082 wxID_RROM_FIRST
, wxID_RROM_LAST
, get_config_path() + "/recent-roms.txt", recent_rom_selected
));
1083 menu_special_sub(wxT("Recent Movies"), recent_movies
= new recent_menu
<recentfiles::path
>(this, inst
,
1084 wxID_RMOVIE_FIRST
, wxID_RMOVIE_LAST
, get_config_path() + "/recent-movies.txt",
1085 recent_movie_selected
));
1086 menu_special_sub(wxT("Recent Lua scripts"), recent_scripts
= new recent_menu
<recentfiles::path
>(this, inst
,
1087 wxID_RLUA_FIRST
, wxID_RLUA_LAST
, get_config_path() + "/recent-scripts.txt",
1088 recent_script_selected
));
1090 menu_entry(wxID_CONFLICTRESOLUTION
, wxT("Conflict resolution"));
1092 branches_menu
* brlist
;
1093 auto brlist_item
= menu_special_sub(wxT("Branches"), brlist
= new branches_menu(this, inst
,
1094 wxID_BRANCH_FIRST
, wxID_BRANCH_LAST
));
1095 brlist
->set_disabler([brlist_item
](bool enabled
) { brlist_item
->Enable(enabled
); });
1098 menu_start_sub(wxT("Save"));
1099 menu_entry(wxID_SAVE_STATE
, wxT("State..."));
1100 menu_entry(wxID_SAVE_MOVIE
, wxT("Movie..."));
1101 menu_entry(wxID_SAVE_SCREENSHOT
, wxT("Screenshot..."));
1102 menu_entry(wxID_SAVE_SUBTITLES
, wxT("Subtitles..."));
1103 menu_entry(wxID_CANCEL_SAVES
, wxT("Cancel pending saves"));
1105 menu_entry(wxID_CHDIR
, wxT("Change working directory..."));
1107 menu_special_sub(wxT("Upload"), new upload_menu(this, inst
, wxID_UPLOAD_FIRST
, wxID_UPLOAD_LAST
));
1109 menu_start_sub(wxT("Close"));
1110 menu_entry(wxID_CLOSE_PROJECT
, wxT("Project"));
1111 menu_entry(wxID_CLOSE_ROM
, wxT("ROM"));
1112 menu_enable(wxID_CLOSE_PROJECT
, inst
.project
->get() != NULL
);
1113 menu_enable(wxID_CLOSE_ROM
, inst
.project
->get() == NULL
);
1116 menu_entry(wxID_EXIT
, wxT("Quit"));
1118 menu_special(wxT("System"), reinterpret_cast<wxMenu
*>(sysmenu
= new system_menu(this, inst
)));
1120 menu_start(wxT("Movie"));
1121 menu_entry_check(wxID_READONLY_MODE
, wxT("Readonly mode"));
1122 menu_check(wxID_READONLY_MODE
, is_readonly_mode(inst
));
1123 menu_entry(wxID_EDIT_AUTHORS
, wxT("Edit game name && authors..."));
1124 menu_entry(wxID_EDIT_SUBTITLES
, wxT("Edit subtitles..."));
1125 menu_entry(wxID_EDIT_VSUBTITLES
, wxT("Edit commantary track..."));
1127 menu_entry(wxID_REWIND_MOVIE
, wxT("Rewind to start"));
1129 menu_start(wxT("Speed"));
1130 menu_entry(wxID_SPEED_5
, wxT("1/20x"));
1131 menu_entry(wxID_SPEED_10
, wxT("1/10x"));
1132 menu_entry(wxID_SPEED_17
, wxT("1/6x"));
1133 menu_entry(wxID_SPEED_20
, wxT("1/5x"));
1134 menu_entry(wxID_SPEED_25
, wxT("1/4x"));
1135 menu_entry(wxID_SPEED_33
, wxT("1/3x"));
1136 menu_entry(wxID_SPEED_50
, wxT("1/2x"));
1137 menu_entry(wxID_SPEED_100
, wxT("1x"));
1138 menu_entry(wxID_SPEED_150
, wxT("1.5x"));
1139 menu_entry(wxID_SPEED_200
, wxT("2x"));
1140 menu_entry(wxID_SPEED_300
, wxT("3x"));
1141 menu_entry(wxID_SPEED_500
, wxT("5x"));
1142 menu_entry(wxID_SPEED_1000
, wxT("10x"));
1143 menu_entry(wxID_SPEED_TURBO
, wxT("Turbo"));
1144 menu_entry(wxID_SET_SPEED
, wxT("Set..."));
1146 menu_start(wxT("Tools"));
1147 menu_entry(wxID_RUN_SCRIPT
, wxT("Run batch file..."));
1149 menu_entry(wxID_EVAL_LUA
, wxT("Evaluate Lua statement..."));
1150 menu_entry(wxID_RUN_LUA
, wxT("Run Lua script..."));
1152 menu_entry(wxID_RESET_LUA
, wxT("Reset Lua VM"));
1154 menu_entry(wxID_AUTOHOLD
, wxT("Autohold/Autofire..."));
1155 menu_entry(wxID_TASINPUT
, wxT("TAS input plugin..."));
1156 menu_entry(wxID_MULTITRACK
, wxT("Multitrack..."));
1157 menu_entry(wxID_EDIT_MACROS
, wxT("Edit macros..."));
1159 menu_entry(wxID_EDIT_MEMORYWATCH
, wxT("Edit memory watch..."));
1161 menu_entry(wxID_LOAD_MEMORYWATCH
, wxT("Load memory watch..."));
1162 menu_entry(wxID_SAVE_MEMORYWATCH
, wxT("Save memory watch..."));
1164 menu_entry(wxID_MEMORY_SEARCH
, wxT("Memory Search..."));
1165 menu_entry(wxID_HEXEDITOR
, wxT("Memory editor..."));
1166 tracelog_menu
* trlog
;
1167 auto trlog_item
= menu_special_sub(wxT("Trace log"), trlog
= new tracelog_menu(this, inst
,
1168 wxID_TRACELOG_FIRST
, wxID_TRACELOG_LAST
));
1169 trlog
->set_disabler([trlog_item
](bool enabled
) { trlog_item
->Enable(enabled
); });
1171 menu_entry(wxID_DISASSEMBLER
, wxT("Disassembler..."));
1173 menu_entry(wxID_MOVIE_EDIT
, wxT("Edit movie..."));
1175 menu_special_sub(wxT("Video Capture"), reinterpret_cast<dumper_menu
*>(dmenu
= new dumper_menu(this,
1176 inst
, wxID_DUMP_FIRST
, wxID_DUMP_LAST
)));
1178 menu_start(wxT("Configure"));
1179 menu_entry_check(wxID_SHOW_STATUS
, wxT("Show status panel"));
1180 menu_check(wxID_SHOW_STATUS
, true);
1181 menu_entry_check(wxID_DEDICATED_MEMORY_WATCH
, wxT("Dedicated memory watch"));
1182 menu_entry(wxID_SHOW_MESSAGES
, wxT("Show messages"));
1183 menu_special_sub(wxT("Settings"), new settings_menu(this, inst
, wxID_SETTINGS_FIRST
));
1184 if(audioapi_driver_initialized()) {
1186 menu_entry_check(wxID_AUDIO_ENABLED
, wxT("Sounds enabled"));
1187 menu_entry(wxID_VUDISPLAY
, wxT("VU display / sound controls"));
1188 menu_check(wxID_AUDIO_ENABLED
, platform::is_sound_enabled());
1191 menu_entry(wxID_ENTER_FULLSCREEN
, wxT("Enter fullscreen mode"));
1193 menu_start(wxT("Help"));
1194 menu_entry(wxID_ABOUT
, wxT("About..."));
1196 corechange
.set(inst
.dispatch
->core_change
, []() { signal_core_change(); });
1197 titlechange
.set(inst
.dispatch
->title_change
, []() { signal_core_change(); });
1198 newcore
.set(notify_new_core
, []() { update_preferences(); });
1199 unmuted
.set(inst
.dispatch
->sound_unmute
, [this](bool unmute
) {
1200 runuifun([this, unmute
]() { this->menu_check(wxID_AUDIO_ENABLED
, unmute
); });
1202 modechange
.set(inst
.dispatch
->mode_change
, [this](bool readonly
) {
1203 runuifun([this, readonly
]() { this->menu_check(wxID_READONLY_MODE
, readonly
); });
1205 gpanel
->SetDropTarget(new loadfile(this, inst
));
1206 spanel
->SetDropTarget(new loadfile(this, inst
));
1207 set_hasher_callback(hash_callback
);
1208 reinterpret_cast<system_menu
*>(sysmenu
)->update(false);
1209 menubar
->SetMenuLabel(1, towxstring(inst
.rom
->get_systemmenu_name()));
1210 focus_timer
= new _focus_timer
;
1211 status_timer
= new _status_timer
;
1213 wx_escape_count
= 0;
1214 enter_or_leave_fullscreen(true);
1218 wxwin_mainwindow::~wxwin_mainwindow()
1221 if(sws_ctx
) sws_freeContext(sws_ctx
);
1222 if(screen_buffer
) delete[] screen_buffer
;
1223 if(rotate_buffer
) delete[] rotate_buffer
;
1224 focus_timer
->Stop();
1226 status_timer
->Stop();
1227 delete status_timer
;
1230 void wxwin_mainwindow::request_paint()
1236 void wxwin_mainwindow::on_close(wxCloseEvent
& e
)
1239 //Veto it for now, latter things will delete it.
1241 inst
.iqueue
->queue("quit-emulator");
1244 void wxwin_mainwindow::notify_update() throw()
1247 if(!main_window_dirty
) {
1248 main_window_dirty
= true;
1253 void wxwin_mainwindow::notify_resized() throw()
1257 toplevel
->SetSizeHints(this);
1261 void wxwin_mainwindow::notify_update_status() throw()
1264 spanel
->request_paint();
1266 mwindow
->notify_update();
1267 status_updated
= true;
1270 void wxwin_mainwindow::notify_exit() throw()
1273 wxwidgets_exiting
= true;
1274 join_emulator_thread();
1278 std::string
read_variable_map(const std::map
<std::string
, std::u32string
>& vars
, const std::string
& key
)
1280 if(!vars
.count(key
))
1282 return utf8::to8(vars
.find(key
)->second
);
1285 void wxwin_mainwindow::update_statusbar()
1288 if(download_in_progress
) {
1289 statusbar
->SetStatusText(towxstring(download_in_progress
->statusmsg()));
1292 if(hashing_in_progress
) {
1293 //TODO: Display this as a dialog.
1294 std::ostringstream s
;
1295 s
<< "Hashing ROMs, approximately " << ((hashing_left
+ 524288) >> 20) << " of "
1296 << ((hashing_total
+ 524288) >> 20) << "MB left...";
1297 statusbar
->SetStatusText(towxstring(s
.str()));
1300 auto& vars
= inst
.status
->get_read();
1302 inst
.status
->put_read();
1306 std::ostringstream s
;
1307 bool recording
= (vars
.mode
== 'R');
1308 if(vars
.movie_valid
) {
1310 s
<< "Frame: " << vars
.curframe
;
1312 s
<< "Frame: " << vars
.curframe
<< "/" << vars
.length
;
1313 s
<< " Lag: " << vars
.lag
;
1314 if(vars
.subframe
== _lsnes_status::subframe_savepoint
)
1315 s
<< " Subframe: S";
1316 else if(vars
.subframe
== _lsnes_status::subframe_video
)
1317 s
<< " Subframe: V";
1319 s
<< " Subframe: " << vars
.subframe
;
1321 s
<< "Frame: N/A Lag: N/A Subframe: N/A";
1323 if(vars
.saveslot_valid
) {
1325 if(vars
.branch_valid
) s
<< utf8::to8(vars
.branch
) << "ā";
1327 s
<< " [" << utf8::to8(vars
.slotinfo
) << "]";
1329 s
<< " Speed: " << vars
.speed
<< "% ";
1330 if(vars
.pause
== _lsnes_status::pause_break
)
1332 else if(vars
.pause
== _lsnes_status::pause_normal
)
1336 if(vars
.mode
== 'C')
1338 else if(vars
.mode
== 'R')
1340 else if(vars
.mode
== 'P')
1342 else if(vars
.mode
== 'F')
1346 if(vars
.mbranch_valid
)
1347 s
<< " Branch: " << utf8::to8(vars
.mbranch
);
1348 std::string macros
= utf8::to8(vars
.macros
);
1350 s
<< " Macros: " << macros
;
1352 statusbar
->SetStatusText(towxstring(s
.str()));
1353 } catch(std::exception
& e
) {
1355 inst
.status
->put_read();
1358 #define NEW_KEYBINDING "A new binding..."
1359 #define NEW_ALIAS "A new alias..."
1360 #define NEW_WATCH "A new watch..."
1362 void wxwin_mainwindow::handle_menu_click(wxCommandEvent
& e
)
1366 handle_menu_click_cancelable(e
);
1367 } catch(canceled_exception
& e
) {
1369 } catch(std::bad_alloc
& e
) {
1371 } catch(std::exception
& e
) {
1372 show_message_ok(this, "Error in menu handler", e
.what(), wxICON_EXCLAMATION
);
1376 void wxwin_mainwindow::refresh_title() throw()
1379 SetTitle(getname(inst
));
1380 auto p
= inst
.project
->get();
1381 menu_enable(wxID_RELOAD_ROM_IMAGE
, !p
);
1382 for(int i
= wxID_LOAD_ROM_IMAGE_FIRST
; i
<= wxID_LOAD_ROM_IMAGE_LAST
; i
++)
1384 menu_enable(wxID_CLOSE_PROJECT
, p
!= NULL
);
1385 menu_enable(wxID_CLOSE_ROM
, p
== NULL
);
1386 reinterpret_cast<system_menu
*>(sysmenu
)->update(false);
1387 menubar
->SetMenuLabel(1, towxstring(inst
.rom
->get_systemmenu_name()));
1392 struct movie_or_savestate
1395 typedef std::pair
<std::string
,std::string
> returntype
;
1396 movie_or_savestate(emulator_instance
& _inst
, bool is_state
)
1401 filedialog_input_params
input(bool save
) const
1403 filedialog_input_params p
;
1404 std::string ext
= state
? inst
.project
->savestate_ext() : "lsmv";
1405 std::string name
= state
? "Savestates" : "Movies";
1407 p
.types
.push_back(filedialog_type_entry(name
, "*." + ext
, ext
));
1408 p
.types
.push_back(filedialog_type_entry(name
+ " (binary)", "*." + ext
, ext
));
1410 p
.types
.push_back(filedialog_type_entry(name
, "*." + ext
+ ";*." + ext
+ ".backup",
1412 if(!save
&& state
) {
1413 p
.types
.push_back(filedialog_type_entry("Savestates [playback]", "*." + ext
+
1414 ";*." + ext
+ ".backup", ext
));
1415 p
.types
.push_back(filedialog_type_entry("Savestates [recording]", "*." + ext
+
1416 ";*." + ext
+ ".backup", ext
));
1417 p
.types
.push_back(filedialog_type_entry("Savestates [preserve]", "*." + ext
+
1418 ";*." + ext
+ ".backup", ext
));
1419 p
.types
.push_back(filedialog_type_entry("Savestates [all branches]", "*." + ext
+
1420 ";*." + ext
+ ".backup", ext
));
1422 p
.default_type
= save
? (state
? save_dflt_binary(*inst
.settings
) :
1423 movie_dflt_binary(*inst
.settings
)) : 0;
1426 std::pair
<std::string
, std::string
> output(const filedialog_output_params
& p
, bool save
) const
1430 cmdmod
= p
.typechoice
? "-binary" : "-zip";
1432 switch(p
.typechoice
) {
1433 case 0: cmdmod
= ""; break;
1434 case 1: cmdmod
= "-readonly"; break;
1435 case 2: cmdmod
= "-state"; break;
1436 case 3: cmdmod
= "-preserve"; break;
1437 case 4: cmdmod
= "-allbranches"; break;
1439 return std::make_pair(cmdmod
, p
.path
);
1442 emulator_instance
& inst
;
1445 struct movie_or_savestate
filetype_movie(lsnes_instance
, false);
1446 struct movie_or_savestate
filetype_savestate(lsnes_instance
, true);
1449 void wxwin_mainwindow::project_selected(const std::string
& id
)
1451 std::string filename
, displayname
;
1452 bool load_ok
= false;
1453 inst
.iqueue
->run([id
, &filename
, &displayname
, &load_ok
]() -> void {
1455 auto& p
= CORE().project
->load(id
); //Check.
1456 filename
= p
.filename
;
1457 displayname
= p
.name
;
1460 switch_projects(id
);
1461 } catch(std::exception
& e
) {
1462 messages
<< "Failed to change project: " << e
.what() << std::endl
;
1466 recentfiles::namedobj obj
;
1468 obj
._filename
= filename
;
1469 obj
._display
= displayname
;
1474 void wxwin_mainwindow::handle_menu_click_cancelable(wxCommandEvent
& e
)
1477 std::string filename
;
1478 std::pair
<std::string
, std::string
> filename2
;
1481 case wxID_FRAMEADVANCE
:
1482 inst
.iqueue
->queue("+advance-frame");
1483 inst
.iqueue
->queue("-advance-frame");
1485 case wxID_SUBFRAMEADVANCE
:
1486 inst
.iqueue
->queue("+advance-poll");
1487 inst
.iqueue
->queue("-advance-poll");
1490 inst
.iqueue
->queue("advance-skiplag");
1493 inst
.iqueue
->queue("pause-emulator");
1496 inst
.iqueue
->queue("quit-emulator");
1498 case wxID_AUDIO_ENABLED
:
1499 platform::sound_enable(menu_ischecked(wxID_AUDIO_ENABLED
));
1501 case wxID_CANCEL_SAVES
:
1502 inst
.iqueue
->queue("cancel-saves");
1504 case wxID_LOAD_MOVIE
:
1505 filename
= choose_file_load(this, "Load Movie", UI_get_project_moviepath(inst
),
1506 filetype_movie
).second
;
1507 recent_movies
->add(filename
);
1508 inst
.iqueue
->queue(CLOADSAVE::ldm
.name
, filename
);
1510 case wxID_LOAD_STATE
:
1511 filename2
= choose_file_load(this, "Load State", UI_get_project_moviepath(inst
),
1512 filetype_savestate
);
1513 recent_movies
->add(filename2
.second
);
1514 inst
.iqueue
->queue("load" + filename2
.first
+ " " + filename2
.second
);
1516 case wxID_REWIND_MOVIE
:
1517 inst
.iqueue
->queue("rewind-movie");
1519 case wxID_SAVE_MOVIE
:
1520 filename2
= choose_file_save(this, "Save Movie", UI_get_project_moviepath(inst
), filetype_movie
,
1521 project_prefixname(inst
, "lsmv"));
1522 recent_movies
->add(filename2
.second
);
1523 inst
.iqueue
->queue("save-movie" + filename2
.first
+ " " + filename2
.second
);
1525 case wxID_SAVE_SUBTITLES
:
1526 inst
.iqueue
->queue(CSUBTITLE::save
.name
, choose_file_save(this, "Save subtitles",
1527 UI_get_project_moviepath(inst
), filetype_sub
, project_prefixname(inst
, "sub")));
1529 case wxID_SAVE_STATE
:
1530 filename2
= choose_file_save(this, "Save State", UI_get_project_moviepath(inst
),
1531 filetype_savestate
);
1532 recent_movies
->add(filename2
.second
);
1533 inst
.iqueue
->queue("save-state" + filename2
.first
+ " " + filename2
.second
);
1535 case wxID_SAVE_SCREENSHOT
:
1536 inst
.iqueue
->queue(CFRAMEBUF::ss
.name
, choose_file_save(this, "Save Screenshot",
1537 UI_get_project_moviepath(inst
), filetype_png
, get_default_screenshot_name(inst
)));
1539 case wxID_RUN_SCRIPT
:
1540 inst
.iqueue
->queue(CLUA::run
.name
, pick_file_member(this, "Select Script",
1541 UI_get_project_otherpath(inst
)));
1543 case wxID_RUN_LUA
: {
1544 std::string f
= choose_file_load(this, "Select Lua Script", UI_get_project_otherpath(inst
),
1545 filetype_lua_script
);
1546 inst
.iqueue
->queue(CLUA::run
.name
, f
);
1547 recent_scripts
->add(f
);
1550 case wxID_RESET_LUA
:
1551 inst
.iqueue
->queue(CLUA::reset
.name
);
1554 inst
.iqueue
->queue(CLUA::eval
.name
, pick_text(this, "Evaluate Lua", "Enter Lua Statement:"));
1556 case wxID_READONLY_MODE
:
1557 s
= menu_ischecked(wxID_READONLY_MODE
);
1558 inst
.iqueue
->run([s
]() {
1559 auto& core
= CORE();
1561 core
.lua2
->callback_movie_lost("readwrite");
1562 if(*core
.mlogic
) core
.mlogic
->get_movie().readonly_mode(s
);
1563 core
.dispatch
->mode_change(s
);
1565 core
.lua2
->callback_do_readwrite();
1566 core
.supdater
->update();
1567 core
.dispatch
->status_update();
1571 wxeditor_autohold_display(this, inst
);
1573 case wxID_EDIT_AUTHORS
:
1574 wxeditor_authors_display(this, inst
);
1576 case wxID_EDIT_MACROS
:
1577 wxeditor_macro_display(this, inst
);
1579 case wxID_EDIT_SUBTITLES
:
1580 wxeditor_subtitles_display(this, inst
);
1582 case wxID_EDIT_VSUBTITLES
:
1583 show_wxeditor_voicesub(this, inst
);
1585 case wxID_EDIT_MEMORYWATCH
:
1586 wxeditor_memorywatches_display(this, inst
);
1588 case wxID_SAVE_MEMORYWATCH
: {
1589 modal_pause_holder hld
;
1590 std::set
<std::string
> old_watches
;
1591 inst
.iqueue
->run([&old_watches
]() { old_watches
= CORE().mwatch
->enumerate(); });
1592 std::string filename
= choose_file_save(this, "Save watches to file",
1593 UI_get_project_otherpath(inst
), filetype_watch
);
1594 std::ofstream
out(filename
.c_str());
1595 for(auto i
: old_watches
) {
1597 inst
.iqueue
->run([i
, &val
]() {
1599 val
= CORE().mwatch
->get_string(i
);
1600 } catch(std::exception
& e
) {
1601 messages
<< "Can't get value of watch '" << i
<< "': " << e
.what()
1605 out
<< i
<< std::endl
<< val
<< std::endl
;
1610 case wxID_LOAD_MEMORYWATCH
: {
1611 modal_pause_holder hld
;
1612 std::set
<std::string
> old_watches
;
1613 inst
.iqueue
->run([&old_watches
]() { old_watches
= CORE().mwatch
->enumerate(); });
1614 std::map
<std::string
, std::string
> new_watches
;
1615 std::string filename
= choose_file_load(this, "Choose memory watch file",
1616 UI_get_project_otherpath(inst
), filetype_watch
);
1618 std::istream
& in
= zip::openrel(filename
, "");
1622 std::getline(in
, wname
);
1623 std::getline(in
, wexpr
);
1624 new_watches
[strip_CR(wname
)] = strip_CR(wexpr
);
1627 } catch(std::exception
& e
) {
1628 show_message_ok(this, "Error", std::string("Can't load memory watch: ") + e
.what(),
1629 wxICON_EXCLAMATION
);
1633 inst
.iqueue
->run([this, &new_watches
, &old_watches
]() {
1634 handle_watch_load(this->inst
, new_watches
, old_watches
);
1638 case wxID_MEMORY_SEARCH
:
1639 wxwindow_memorysearch_display(inst
);
1642 wxeditor_tasinput_display(this, inst
);
1645 std::ostringstream str
;
1646 str
<< "Version: lsnes rr" << lsnes_version
<< std::endl
;
1647 str
<< "Revision: " << lsnes_git_revision
<< std::endl
;
1648 for(auto i
: core_core::all_cores())
1650 str
<< "Core: " << i
->get_core_identifier() << std::endl
;
1651 wxMessageBox(towxstring(str
.str()), _T("About"), wxICON_INFORMATION
| wxOK
, this);
1654 case wxID_SHOW_STATUS
: {
1655 bool newstate
= menu_ischecked(wxID_SHOW_STATUS
);
1658 if(newstate
&& !spanel_shown
)
1659 toplevel
->Add(spanel
, 1, wxGROW
);
1660 else if(!newstate
&& spanel_shown
)
1661 toplevel
->Detach(spanel
);
1664 spanel_shown
= newstate
;
1666 toplevel
->SetSizeHints(this);
1670 case wxID_DEDICATED_MEMORY_WATCH
: {
1671 bool newstate
= menu_ischecked(wxID_DEDICATED_MEMORY_WATCH
);
1672 if(newstate
&& !mwindow
) {
1673 mwindow
= new wxwin_status(-1, inst
, "Memory Watch");
1674 spanel
->set_watch_flag(1);
1676 } else if(!newstate
&& mwindow
) {
1679 spanel
->set_watch_flag(0);
1683 case wxID_SET_SPEED
: {
1684 std::string value
= "infinite";
1685 double val
= inst
.framerate
->get_speed_multiplier();
1686 if(!(val
== std::numeric_limits
<double>::infinity()))
1687 value
= (stringfmt() << (100 * val
)).str();
1688 value
= pick_text(this, "Set speed", "Enter percentage speed (or \"infinite\"):", value
);
1690 if(value
== "infinite")
1691 inst
.framerate
->set_speed_multiplier(
1692 std::numeric_limits
<double>::infinity());
1694 double v
= parse_value
<double>(value
) / 100;
1697 inst
.framerate
->set_speed_multiplier(v
);
1700 wxMessageBox(wxT("Invalid speed"), _T("Error"), wxICON_EXCLAMATION
| wxOK
, this);
1708 set_speed(inst
, 10);
1711 set_speed(inst
, 16.66666666666);
1714 set_speed(inst
, 20);
1717 set_speed(inst
, 25);
1720 set_speed(inst
, 33.3333333333333);
1723 set_speed(inst
, 50);
1725 case wxID_SPEED_100
:
1726 set_speed(inst
, 100);
1728 case wxID_SPEED_150
:
1729 set_speed(inst
, 150);
1731 case wxID_SPEED_200
:
1732 set_speed(inst
, 200);
1734 case wxID_SPEED_300
:
1735 set_speed(inst
, 300);
1737 case wxID_SPEED_500
:
1738 set_speed(inst
, 500);
1740 case wxID_SPEED_1000
:
1741 set_speed(inst
, 1000);
1743 case wxID_SPEED_TURBO
:
1744 set_speed(inst
, -1);
1746 case wxID_LOAD_LIBRARY
: {
1747 std::string name
= std::string("load ") + loadlib::library::name();
1748 with_loaded_library(*new loadlib::module(loadlib::library(choose_file_load(this, name
,
1749 UI_get_project_otherpath(inst
), single_type(loadlib::library::extension(),
1750 loadlib::library::name())))));
1751 handle_post_loadlibrary();
1754 case wxID_PLUGIN_MANAGER
:
1755 wxeditor_plugin_manager_display(this);
1757 case wxID_RELOAD_ROM_IMAGE
:
1758 inst
.iqueue
->run([]() {
1759 CORE().command
->invoke("unpause-emulator");
1760 reload_current_rom();
1763 case wxID_NEW_MOVIE
:
1764 show_projectwindow(this, inst
);
1766 case wxID_SHOW_MESSAGES
:
1767 msg_window
->reshow();
1769 case wxID_CONFLICTRESOLUTION
:
1770 show_conflictwindow(this);
1772 case wxID_VUDISPLAY
:
1773 open_vumeter_window(this, inst
);
1775 case wxID_DISASSEMBLER
:
1776 wxeditor_disassembler_display(this, inst
);
1778 case wxID_MOVIE_EDIT
:
1779 wxeditor_movie_display(this, inst
);
1781 case wxID_NEW_PROJECT
:
1782 open_new_project_window(this, inst
);
1784 case wxID_CLOSE_PROJECT
:
1785 inst
.iqueue
->run([this]() -> void { this->inst
.project
->set(NULL
); });
1787 case wxID_CLOSE_ROM
:
1788 inst
.iqueue
->run([]() -> void { close_rom(); });
1790 case wxID_ENTER_FULLSCREEN
:
1791 wx_escape_count
= 0;
1792 enter_or_leave_fullscreen(true);
1794 case wxID_LOAD_ROM_IMAGE_FIRST
:
1795 do_load_rom_image(NULL
);
1797 case wxID_HEXEDITOR
:
1798 wxeditor_hexedit_display(this, inst
);
1800 case wxID_MULTITRACK
:
1801 wxeditor_multitrack_display(this, inst
);
1804 wxDirDialog
* d
= new wxDirDialog(this, wxT("Change working directory"), wxT("."),
1805 wxDD_DIR_MUST_EXIST
);
1806 if(d
->ShowModal() == wxID_CANCEL
) {
1810 std::string path
= tostdstring(d
->GetPath());
1812 chdir(path
.c_str());
1813 messages
<< "Changed working directory to '" << path
<< "'" << std::endl
;
1816 case wxID_DOWNLOAD
: {
1817 if(download_in_progress
) return;
1818 filename
= pick_text(this, "Download movie", "Enter URL to download");
1819 download_in_progress
= new file_download();
1820 download_in_progress
->url
= lsnes_uri_rewrite(filename
);
1821 download_in_progress
->target_slot
= "wxwidgets_download_tmp";
1822 download_in_progress
->do_async(*inst
.rom
);
1823 new download_timer(this, inst
);
1829 void wxwin_mainwindow::action_updated()
1831 runuifun([this]() { reinterpret_cast<system_menu
*>(sysmenu
)->update(true); });
1834 void wxwin_mainwindow::enter_or_leave_fullscreen(bool fs
)
1839 toplevel
->Detach(spanel
);
1842 ShowFullScreen(true);
1844 } else if(!fs
&& is_fs
) {
1845 ShowFullScreen(false);
1848 toplevel
->Add(spanel
, 1, wxGROW
);