From 845925fe992f199775302beb4ba8eb5c74acadf7 Mon Sep 17 00:00:00 2001 From: cracyc Date: Wed, 3 Oct 2018 15:55:34 -0500 Subject: plugins/portname: add softlist parent loading and import tag (nw) --- plugins/portname/init.lua | 54 ++++++++++++++++++++++++++++++++--------- src/frontend/mame/luaengine.cpp | 2 ++ 2 files changed, 45 insertions(+), 11 deletions(-) diff --git a/plugins/portname/init.lua b/plugins/portname/init.lua index e231931a347..3c04d26f72a 100644 --- a/plugins/portname/init.lua +++ b/plugins/portname/init.lua @@ -2,6 +2,7 @@ -- copyright-holders:Carl -- data files are json files named .json -- { +-- "import":"" -- "ports":{ -- "":{ -- "labels":{ @@ -39,19 +40,21 @@ function portname.startplugin() return filename end - emu.register_start(function() - local file = emu.file(ctrlrpath .. "/portname", "r") - local ret = file:open(get_filename()) - if ret then - ret = file:open(get_filename(true)) - if ret then - ret = file:open(manager:machine():system().parent .. ".json") - if ret then - return - end + local function parse_names(ctable, depth) + if depth >= 5 then + emu.print_error("portname: max import depth exceeded\n") + return + end + if ctable.import then + local file = emu.file(ctrlrpath .. "/portname", "r") + local ret = file:open(ctable.import) + if not ret then + parse_names(json.parse(file:read(file:size())), depth + 1) end end - local ctable = json.parse(file:read(file:size())) + if not ctable.ports then + return + end for pname, port in pairs(ctable.ports) do local ioport = manager:machine():ioport().ports[pname] if ioport then @@ -65,6 +68,35 @@ function portname.startplugin() end end end + end + + emu.register_start(function() + local file = emu.file(ctrlrpath .. "/portname", "r") + local ret = file:open(get_filename()) + if ret then + if emu.softname() ~= "" then + local parent + for tag, image in pairs(manager:machine().images) do + parent = image.software_parent + if parent ~= "" then + break + end + end + if parent ~= "" then + ret = file:open(emu.romname() .. "_" .. parent:match("([^:]*)$") .. ".json") + end + end + if ret then + ret = file:open(get_filename(true)) + if ret then + ret = file:open(manager:machine():system().parent .. ".json") + if ret then + return + end + end + end + end + parse_names(json.parse(file:read(file:size())), 0) end) local function menu_populate() diff --git a/src/frontend/mame/luaengine.cpp b/src/frontend/mame/luaengine.cpp index ddae8e8aeb6..44c4fc94b3a 100644 --- a/src/frontend/mame/luaengine.cpp +++ b/src/frontend/mame/luaengine.cpp @@ -24,6 +24,7 @@ #include "natkeyboard.h" #include "uiinput.h" #include "pluginopts.h" +#include "softlist.h" #ifdef __clang__ #pragma clang diagnostic ignored "-Wshift-count-overflow" @@ -1986,6 +1987,7 @@ void lua_engine::initialize() "manufacturer", &device_image_interface::manufacturer, "year", &device_image_interface::year, "software_list_name", &device_image_interface::software_list_name, + "software_parent", sol::property([](device_image_interface &di) { const software_info *si = di.software_entry(); return si ? si->parentname() : ""; }), "image_type_name", &device_image_interface::image_type_name, "load", &device_image_interface::load, "unload", &device_image_interface::unload, -- cgit v1.2.3