summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/machine.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/emu/machine.cpp')
-rw-r--r--src/emu/machine.cpp84
1 files changed, 56 insertions, 28 deletions
diff --git a/src/emu/machine.cpp b/src/emu/machine.cpp
index 7f8f532ddf7..6f7496e49d2 100644
--- a/src/emu/machine.cpp
+++ b/src/emu/machine.cpp
@@ -89,8 +89,6 @@
#if defined(EMSCRIPTEN)
#include <emscripten.h>
-
-void js_set_main_loop(running_machine * machine);
#endif
@@ -342,17 +340,18 @@ int running_machine::run(bool quiet)
export_http_api();
- // run the CPUs until a reset or exit
m_hard_reset_pending = false;
- while ((!m_hard_reset_pending && !m_exit_pending) || m_saveload_schedule != saveload_schedule::NONE)
- {
- g_profiler.start(PROFILER_EXTRA);
#if defined(EMSCRIPTEN)
- // break out to our async javascript loop and halt
- js_set_main_loop(this);
+ // break out to our async javascript loop and halt
+ emscripten_set_running_machine(this);
#endif
+ // run the CPUs until a reset or exit
+ while ((!m_hard_reset_pending && !m_exit_pending) || m_saveload_schedule != saveload_schedule::NONE)
+ {
+ g_profiler.start(PROFILER_EXTRA);
+
// execute CPUs if not paused
if (!m_paused)
m_scheduler.timeslice();
@@ -422,7 +421,6 @@ int running_machine::run(bool quiet)
return error;
}
-
//-------------------------------------------------
// schedule_exit - schedule a clean exit
//-------------------------------------------------
@@ -1316,41 +1314,71 @@ device_memory_interface::space_config_vector dummy_space_device::memory_space_co
#if defined(EMSCRIPTEN)
-static running_machine * jsmess_machine;
+running_machine * running_machine::emscripten_running_machine;
-void js_main_loop()
+void running_machine::emscripten_main_loop()
{
- if (jsmess_machine->paused()) {
- jsmess_machine->video().frame_update();
- return;
+ running_machine *machine = emscripten_running_machine;
+
+ g_profiler.start(PROFILER_EXTRA);
+
+ // execute CPUs if not paused
+ if (!machine->m_paused)
+ {
+ device_scheduler * scheduler;
+ scheduler = &(machine->scheduler());
+
+ // Emscripten will call this function at 60Hz, so step the simulation
+ // forward for the amount of time that has passed since the last frame
+ const attotime frametime(0,HZ_TO_ATTOSECONDS(60));
+ const attotime stoptime(scheduler->time() + frametime);
+
+ while (!machine->m_paused && !machine->scheduled_event_pending() && scheduler->time() < stoptime)
+ {
+ scheduler->timeslice();
+ // handle save/load
+ if (machine->m_saveload_schedule != saveload_schedule::NONE)
+ {
+ machine->handle_saveload();
+ break;
+ }
+ }
}
+ // otherwise, just pump video updates through
+ else
+ machine->m_video->frame_update();
- device_scheduler * scheduler;
- scheduler = &(jsmess_machine->scheduler());
- attotime stoptime(scheduler->time() + attotime(0,HZ_TO_ATTOSECONDS(60)));
- while (scheduler->time() < stoptime) {
- scheduler->timeslice();
+ // cancel the emscripten loop if the system has been told to exit
+ if (machine->exit_pending())
+ {
+ emscripten_cancel_main_loop();
}
+
+ g_profiler.stop();
}
-void js_set_main_loop(running_machine * machine) {
- jsmess_machine = machine;
+void running_machine::emscripten_set_running_machine(running_machine *machine)
+{
+ emscripten_running_machine = machine;
EM_ASM (
JSMESS.running = true;
);
- emscripten_set_main_loop(&js_main_loop, 0, 1);
+ emscripten_set_main_loop(&(emscripten_main_loop), 0, 1);
}
-running_machine * js_get_machine() {
- return jsmess_machine;
+running_machine * running_machine::emscripten_get_running_machine()
+{
+ return emscripten_running_machine;
}
-ui_manager * js_get_ui() {
- return &(jsmess_machine->ui());
+ui_manager * running_machine::emscripten_get_ui()
+{
+ return &(emscripten_running_machine->ui());
}
-sound_manager * js_get_sound() {
- return &(jsmess_machine->sound());
+sound_manager * running_machine::emscripten_get_sound()
+{
+ return &(emscripten_running_machine->sound());
}
#endif /* defined(EMSCRIPTEN) */