luaengine.cpp: Exposed cassette image devices.

This commit is contained in:
cracyc 2020-12-02 01:58:27 -06:00 committed by GitHub
parent 3973a65bf6
commit 4103b2acc2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -16,6 +16,8 @@
#include "ui/pluginopt.h"
#include "ui/ui.h"
#include "imagedev/cassette.h"
#include "debugger.h"
#include "drivenum.h"
#include "emuopts.h"
@ -529,6 +531,13 @@ void lua_engine::initialize()
};
static const enum_parser<int, 3> s_seek_parser =
{
{ "set", SEEK_SET },
{ "cur", SEEK_CUR },
{ "end", SEEK_END }
};
/* emu library
*
* emu.app_name() - return application name
@ -744,16 +753,7 @@ void lua_engine::initialize()
return sol::make_object(sol(), file.tell());
},
[this](emu_file &file, const char* whence) -> sol::object {
int wval = -1;
const char *seekdirs[] = {"set", "cur", "end"};
for(int i = 0; i < 3; i++)
{
if(!strncmp(whence, seekdirs[i], 3))
{
wval = i;
break;
}
}
int wval = s_seek_parser(whence);
if(wval < 0 || wval >= 3)
return sol::make_object(sol(), sol::lua_nil);
if(file.seek(0, wval))
@ -761,16 +761,7 @@ void lua_engine::initialize()
return sol::make_object(sol(), file.tell());
},
[this](emu_file &file, const char* whence, s64 offset) -> sol::object {
int wval = -1;
const char *seekdirs[] = {"set", "cur", "end"};
for(int i = 0; i < 3; i++)
{
if(!strncmp(whence, seekdirs[i], 3))
{
wval = i;
break;
}
}
int wval = s_seek_parser(whence);
if(wval < 0 || wval >= 3)
return sol::make_object(sol(), sol::lua_nil);
if(file.seek(offset, wval))
@ -1145,6 +1136,7 @@ void lua_engine::initialize()
machine_type["hard_reset_pending"] = sol::property(&running_machine::hard_reset_pending);
machine_type["devices"] = sol::property([] (running_machine &m) { return devenum<device_enumerator>(m.root_device()); });
machine_type["screens"] = sol::property([] (running_machine &m) { return devenum<screen_device_enumerator>(m.root_device()); });
machine_type["cassettes"] = sol::property([] (running_machine &m) { return devenum<cassette_device_enumerator>(m.root_device()); });
machine_type["images"] = sol::property([] (running_machine &m) { return devenum<image_interface_enumerator>(m.root_device()); });
machine_type["popmessage"] = sol::overload(
[](running_machine &m, const char *str) { m.popmessage("%s", str); },
@ -1787,6 +1779,44 @@ void lua_engine::initialize()
image_type.set("must_be_loaded", sol::property(&device_image_interface::must_be_loaded));
/* cassette_image_device
*
* device.cassette
*
* cass:play()
* cass:stop()
* cass:record()
* cass:forward() - forward play direction
* cass:reverse() - reverse play direction
* cass:seek(time, origin) - seek time sec from origin: "set", "cur", "end"
*
* cass.is_stopped
* cass.is_playing
* cass.is_recording
* cass.motor_state
* cass.speaker_state
* cass.position
* cass.length
* cass.image - get the device_image_interface for this cassette device
*/
auto cass_type = sol().registry().new_usertype<cassette_image_device>("cassette", sol::no_constructor);
cass_type["stop"] = [] (cassette_image_device &c) { c.change_state(CASSETTE_STOPPED, CASSETTE_MASK_UISTATE); };
cass_type["play"] = [] (cassette_image_device &c) { c.change_state(CASSETTE_PLAY, CASSETTE_MASK_UISTATE); };
cass_type["record"] = [] (cassette_image_device &c) { c.change_state(CASSETTE_RECORD, CASSETTE_MASK_UISTATE); };
cass_type["is_stopped"] = sol::property(&cassette_image_device::is_stopped);
cass_type["is_playing"] = sol::property(&cassette_image_device::is_playing);
cass_type["is_recording"] = sol::property(&cassette_image_device::is_recording);
cass_type["motor_state"] = sol::property(&cassette_image_device::motor_on, &cassette_image_device::set_motor);
cass_type["speaker_state"] = sol::property(&cassette_image_device::speaker_on, &cassette_image_device::set_speaker);
cass_type["position"] = sol::property(&cassette_image_device::get_position);
cass_type["length"] = sol::property([] (cassette_image_device &c) { if (c.exists()) return c.get_length(); return 0.0; });
cass_type["forward"] = &cassette_image_device::go_forward;
cass_type["reverse"] = &cassette_image_device::go_reverse;
cass_type["seek"] = [] (cassette_image_device &c, double time, const char* origin) { if (c.exists()) c.seek(time, s_seek_parser(origin)); };
cass_type["image"] = sol::property([] (cassette_image_device &c) { return dynamic_cast<device_image_interface *>(&c); });
/* mame_machine_manager library
*
* manager