Tie up a few loose ends:

debugger: Octal cheats for octal address spaces.

frontend: Pass events for automatically generated menu items to the
plugin - they will have index zero.

frontend: Don't try calling the data plugin from the main menu if the
system isn't starting yet - doing so will prevent the data plugin from
loading at all.
This commit is contained in:
Vas Crabb 2021-10-20 02:03:43 +11:00
parent 9e7779bdd5
commit 0a9ea09a9a
11 changed files with 141 additions and 115 deletions

View File

@ -30,7 +30,6 @@ infinite lives cheat for Raiden (``raiden``):
:ref:`cheatinit command <debugger-command-cheatinit>`::
>cheatinit ub
MAME debugger version 0.237 (mame0237)
36928 cheat locations initialized for NEC V30 ':maincpu' program space
* Allow the game to run, lose a life and break into the debugger.
* Use the :ref:`cheatnext command <debugger-command-cheatnext>` to
@ -55,7 +54,7 @@ infinite lives cheat for Raiden (``raiden``):
<cheat desc="Possibility 1: 00B85 (01)">
<script state="run">
<action>:maincpu.ppb@00B85=03</action>
<action>:maincpu.pb@0x00B85=0x03</action>
</script>
</cheat>

View File

@ -1,11 +1,11 @@
-- license:BSD-3-Clause
-- copyright-holders:Jack Li
local exports = {}
exports.name = 'autofire'
exports.version = '0.0.3'
exports.description = 'Autofire plugin'
exports.license = 'The BSD 3-Clause License'
exports.author = { name = 'Jack Li' }
local exports = {
name = 'autofire',
version = '0.0.3',
description = 'Autofire plugin',
license = 'The BSD 3-Clause License',
author = { name = 'Jack Li' } }
local autofire = exports

View File

@ -1,10 +1,10 @@
{
"plugin": {
"name": "autofire",
"description": "Autofire plugin",
"version": "0.0.3",
"author": "Jack Li",
"type": "plugin",
"start": "false"
}
"plugin": {
"name": "autofire",
"description": "Autofire plugin",
"version": "0.0.3",
"author": "Jack Li",
"type": "plugin",
"start": "false"
}
}

View File

@ -91,16 +91,13 @@ function timer.startplugin()
local function menu_populate()
local time = os.time() - start_time
return {{ _("Current time"), "", "off" },
{ sectohms(time), "", "off" },
{ _("Total time"), "", "off" },
{ sectohms(total_time + time), "", "off" },
{ _("Play Count"), "", "off" },
{ play_count, "", "off" }}
return {{ _("Current time"), sectohms(time), "off" },
{ _("Total time"), sectohms(total_time + time), "off" },
{ _("Play Count"), play_count, "off" }}
end
local function menu_callback(index, event)
return true
return false
end
emu.register_menu(menu_callback, menu_populate, _("Timer"))

View File

@ -88,11 +88,11 @@ bool debugger_commands::cheat_address_is_valid(address_space &space, offs_t addr
the current cheat width, if signed
-------------------------------------------------*/
u64 debugger_commands::cheat_sign_extend(const cheat_system *cheatsys, u64 value)
inline u64 debugger_commands::cheat_system::sign_extend(u64 value) const
{
if (cheatsys->signed_cheat)
if (signed_cheat)
{
switch (cheatsys->width)
switch (width)
{
case 1: value = s8(value); break;
case 2: value = s16(value); break;
@ -106,11 +106,11 @@ u64 debugger_commands::cheat_sign_extend(const cheat_system *cheatsys, u64 value
cheat_byte_swap - swap a value
-------------------------------------------------*/
u64 debugger_commands::cheat_byte_swap(const cheat_system *cheatsys, u64 value)
inline u64 debugger_commands::cheat_system::byte_swap(u64 value) const
{
if (cheatsys->swapped_cheat)
if (swapped_cheat)
{
switch (cheatsys->width)
switch (width)
{
case 2: value = swapendian_int16(value); break;
case 4: value = swapendian_int32(value); break;
@ -126,21 +126,21 @@ u64 debugger_commands::cheat_byte_swap(const cheat_system *cheatsys, u64 value)
and swapping if necessary
-------------------------------------------------*/
u64 debugger_commands::cheat_read_extended(const cheat_system *cheatsys, address_space &space, offs_t address)
u64 debugger_commands::cheat_system::read_extended(offs_t address) const
{
address &= space.logaddrmask();
u64 value = space.unmap();
if (space.device().memory().translate(space.spacenum(), TRANSLATE_READ_DEBUG, address))
address &= space->logaddrmask();
u64 value = space->unmap();
if (space->device().memory().translate(space->spacenum(), TRANSLATE_READ_DEBUG, address))
{
switch (cheatsys->width)
switch (width)
{
case 1: value = space.read_byte(address); break;
case 2: value = space.read_word_unaligned(address); break;
case 4: value = space.read_dword_unaligned(address); break;
case 8: value = space.read_qword_unaligned(address); break;
case 1: value = space->read_byte(address); break;
case 2: value = space->read_word_unaligned(address); break;
case 4: value = space->read_dword_unaligned(address); break;
case 8: value = space->read_qword_unaligned(address); break;
}
}
return cheat_sign_extend(cheatsys, cheat_byte_swap(cheatsys, value));
return sign_extend(byte_swap(value));
}
debugger_commands::debugger_commands(running_machine& machine, debugger_cpu& cpu, debugger_console& console)
@ -3004,7 +3004,7 @@ void debugger_commands::execute_cheatrange(bool init, const std::vector<std::str
for (u64 curaddr = cheat_region[i].offset; curaddr <= cheat_region[i].endoffset; curaddr += width)
if (cheat_address_is_valid(*space, curaddr))
{
m_cheat.cheatmap[active_cheat].previous_value = cheat_read_extended(&m_cheat, *space, curaddr);
m_cheat.cheatmap[active_cheat].previous_value = m_cheat.read_extended(curaddr);
m_cheat.cheatmap[active_cheat].first_value = m_cheat.cheatmap[active_cheat].previous_value;
m_cheat.cheatmap[active_cheat].offset = curaddr;
m_cheat.cheatmap[active_cheat].state = 1;
@ -3056,7 +3056,7 @@ void debugger_commands::execute_cheatnext(bool initial, const std::vector<std::s
u64 comp_value = 0;
if (params.size() > 1 && !validate_number_parameter(params[1], comp_value))
return;
comp_value = cheat_sign_extend(&m_cheat, comp_value);
comp_value = m_cheat.sign_extend(comp_value);
// decode condition
u8 condition;
@ -3093,8 +3093,10 @@ void debugger_commands::execute_cheatnext(bool initial, const std::vector<std::s
for (u64 cheatindex = 0; cheatindex < m_cheat.cheatmap.size(); cheatindex += 1)
if (m_cheat.cheatmap[cheatindex].state == 1)
{
u64 cheat_value = cheat_read_extended(&m_cheat, *space, m_cheat.cheatmap[cheatindex].offset);
u64 comp_byte = !initial ? m_cheat.cheatmap[cheatindex].previous_value : m_cheat.cheatmap[cheatindex].first_value;
u64 cheat_value = m_cheat.read_extended(m_cheat.cheatmap[cheatindex].offset);
u64 comp_byte = initial
? m_cheat.cheatmap[cheatindex].first_value
: m_cheat.cheatmap[cheatindex].previous_value;
u8 disable_byte = false;
switch (condition)
@ -3218,29 +3220,46 @@ void debugger_commands::execute_cheatlist(const std::vector<std::string> &params
}
}
// get device/space syntax for memory access
std::string tag(space->device().tag());
char spaceletter;
std::string spaceletter;
switch (space->spacenum())
{
case AS_PROGRAM: spaceletter = 'p'; break;
case AS_DATA: spaceletter = 'd'; break;
case AS_IO: spaceletter = 'i'; break;
case AS_OPCODES: spaceletter = '3'; break;
default:
tag.append(1, ':');
tag.append(space->name());
spaceletter = 'p';
default:
tag.append(1, ':');
tag.append(space->name());
break;
case AS_PROGRAM:
spaceletter = "p";
break;
case AS_DATA:
spaceletter = "d";
break;
case AS_IO:
spaceletter = "i";
break;
case AS_OPCODES:
spaceletter = "3";
break;
}
// get size syntax for memory access and formatting values
bool const octal = space->is_octal();
int const addrchars = octal
? ((2 + space->logaddr_width()) / 3)
: ((3 + space->logaddr_width()) / 4);
int const datachars = octal
? ((2 + (m_cheat.width * 8)) / 3)
: ((3 + (m_cheat.width * 8)) / 4);
u64 const sizemask = util::make_bitmask<u64>(m_cheat.width * 8);
char sizeletter;
u64 sizemask;
switch (m_cheat.width)
{
default:
case 1: sizeletter = 'b'; sizemask = 0xffU; break;
case 2: sizeletter = 'w'; sizemask = 0xffffU; break;
case 4: sizeletter = 'd'; sizemask = 0xffffffffU; break;
case 8: sizeletter = 'q'; sizemask = 0xffffffffffffffffU; break;
default:
case 1: sizeletter = 'b'; break;
case 2: sizeletter = 'w'; break;
case 4: sizeletter = 'd'; break;
case 8: sizeletter = 'q'; break;
}
// write the cheat list
@ -3250,7 +3269,8 @@ void debugger_commands::execute_cheatlist(const std::vector<std::string> &params
{
if (m_cheat.cheatmap[cheatindex].state == 1)
{
u64 const value = cheat_byte_swap(&m_cheat, cheat_read_extended(&m_cheat, *space, m_cheat.cheatmap[cheatindex].offset)) & sizemask;
u64 const value = m_cheat.byte_swap(m_cheat.read_extended(m_cheat.cheatmap[cheatindex].offset)) & sizemask;
u64 const first_value = m_cheat.byte_swap(m_cheat.cheatmap[cheatindex].first_value) & sizemask;
offs_t const address = space->byte_to_address(m_cheat.cheatmap[cheatindex].offset);
if (!params.empty())
@ -3260,23 +3280,31 @@ void debugger_commands::execute_cheatlist(const std::vector<std::string> &params
output.rdbuf()->clear();
stream_format(
output,
" <cheat desc=\"Possibility %d: %0*X (%0*X)\">\n"
" <script state=\"run\">\n"
" <action>%s.p%c%c@%0*X=%0*X</action>\n"
" </script>\n"
" </cheat>\n\n",
active_cheat, space->logaddrchars(), address, m_cheat.width * 2, value,
tag, spaceletter, sizeletter, space->logaddrchars(), address, m_cheat.width * 2, cheat_byte_swap(&m_cheat, m_cheat.cheatmap[cheatindex].first_value) & sizemask);
octal ?
" <cheat desc=\"Possibility %d: 0%0*o (0%0*o)\">\n"
" <script state=\"run\">\n"
" <action>%s.%s%c@0o%0*o=0o%0*o</action>\n"
" </script>\n"
" </cheat>\n\n" :
" <cheat desc=\"Possibility %d: %0*X (%0*X)\">\n"
" <script state=\"run\">\n"
" <action>%s.%s%c@0x%0*X=0x%0*X</action>\n"
" </script>\n"
" </cheat>\n\n",
active_cheat, addrchars, address, datachars, value,
tag, spaceletter, sizeletter, addrchars, address, datachars, first_value);
auto const &text(output.vec());
fprintf(f, "%.*s", int(unsigned(text.size())), &text[0]);
}
else
{
m_console.printf(
"Address=%0*X Start=%0*X Current=%0*X\n",
space->logaddrchars(), address,
m_cheat.width * 2, cheat_byte_swap(&m_cheat, m_cheat.cheatmap[cheatindex].first_value) & sizemask,
m_cheat.width * 2, value);
octal
? "Address=0%0*o Start=0%0*o Current=0%0*o\n"
: "Address=%0*X Start=%0*X Current=%0*X\n",
addrchars, address,
datachars, first_value,
datachars, value);
}
}
}

View File

@ -73,6 +73,10 @@ private:
u8 swapped_cheat;
std::vector<cheat_map> cheatmap;
u8 undo;
u64 sign_extend(u64 value) const;
u64 byte_swap(u64 value) const;
u64 read_extended(offs_t address) const;
};
struct cheat_region_map
@ -89,9 +93,6 @@ private:
bool debug_command_parameter_command(const char *param);
bool cheat_address_is_valid(address_space &space, offs_t address);
u64 cheat_sign_extend(const cheat_system *cheatsys, u64 value);
u64 cheat_byte_swap(const cheat_system *cheatsys, u64 value);
u64 cheat_read_extended(const cheat_system *cheatsys, address_space &space, offs_t address);
u64 get_cpunum();

View File

@ -70,20 +70,20 @@ menu_dats_view::menu_dats_view(mame_ui_manager &mui, render_container &container
// ctor
//-------------------------------------------------
menu_dats_view::menu_dats_view(mame_ui_manager &mui, render_container &container, const ui_software_info *swinfo, const ui_system_info *system)
menu_dats_view::menu_dats_view(mame_ui_manager &mui, render_container &container, const ui_software_info &swinfo)
: menu(mui, container)
, m_system(!system ? &system_list::instance().systems()[driver_list::find(mui.machine().system().name)] : system)
, m_swinfo(swinfo)
, m_system(nullptr)
, m_swinfo(&swinfo)
, m_issoft(true)
, m_layout()
, m_actual(0)
, m_list(swinfo->listname)
, m_short(swinfo->shortname)
, m_long(swinfo->longname)
, m_parent(swinfo->parentname)
, m_list(swinfo.listname)
, m_short(swinfo.shortname)
, m_long(swinfo.longname)
, m_parent(swinfo.parentname)
{
if (!swinfo->infotext.empty())
if (!swinfo.infotext.empty())
m_items_list.emplace_back(_("Software List Info"), 0, "");
std::vector<std::string> lua_list;
if (mame_machine_manager::instance()->lua()->call_plugin("data_list", std::string(m_short).append(1, ',').append(m_list).c_str(), lua_list))

View File

@ -36,7 +36,7 @@ namespace ui {
class menu_dats_view : public menu
{
public:
menu_dats_view(mame_ui_manager &mui, render_container &container, const ui_software_info *swinfo, const ui_system_info *system = nullptr);
menu_dats_view(mame_ui_manager &mui, render_container &container, const ui_software_info &swinfo);
menu_dats_view(mame_ui_manager &mui, render_container &container, const ui_system_info *system = nullptr);
virtual ~menu_dats_view() override;

View File

@ -159,8 +159,9 @@ void menu_main::populate(float &customtop, float &custombottom)
if (machine().options().plugins() && !mame_machine_manager::instance()->lua()->get_menu().empty())
item_append(_("Plugin Options"), 0, (void *)PLUGINS);
if (mame_machine_manager::instance()->lua()->call_plugin_check<const char *>("data_list", "", true))
item_append(_("External DAT View"), 0, (void *)EXTERNAL_DATS);
if (machine().phase() >= machine_phase::RESET)
if (mame_machine_manager::instance()->lua()->call_plugin_check<const char *>("data_list", "", true))
item_append(_("External DAT View"), 0, (void *)EXTERNAL_DATS);
item_append(menu_item_type::SEPARATOR);

View File

@ -72,40 +72,40 @@ void menu_plugin_opt::handle()
{
const event *menu_event = process(0);
if (menu_event && uintptr_t(menu_event->itemref))
if (menu_event)
{
std::string key;
switch (menu_event->iptkey)
{
case IPT_UI_UP:
key = "up";
break;
case IPT_UI_DOWN:
key = "down";
break;
case IPT_UI_LEFT:
key = "left";
break;
case IPT_UI_RIGHT:
key = "right";
break;
case IPT_UI_SELECT:
key = "select";
break;
case IPT_UI_DISPLAY_COMMENT:
key = "comment";
break;
case IPT_UI_CLEAR:
key = "clear";
break;
case IPT_UI_CANCEL:
key = "cancel";
break;
case IPT_SPECIAL:
key = std::to_string((u32)menu_event->unichar);
break;
default:
return;
case IPT_UI_UP:
key = "up";
break;
case IPT_UI_DOWN:
key = "down";
break;
case IPT_UI_LEFT:
key = "left";
break;
case IPT_UI_RIGHT:
key = "right";
break;
case IPT_UI_SELECT:
key = "select";
break;
case IPT_UI_DISPLAY_COMMENT:
key = "comment";
break;
case IPT_UI_CLEAR:
key = "clear";
break;
case IPT_UI_CANCEL:
key = "cancel";
break;
case IPT_SPECIAL:
key = std::to_string((u32)menu_event->unichar);
break;
default:
return;
}
if (mame_machine_manager::instance()->lua()->menu_callback(m_menu, uintptr_t(menu_event->itemref), key))
reset(reset_options::REMEMBER_REF);

View File

@ -856,7 +856,7 @@ void menu_select_launch::inkey_dats()
ui_system_info const *system;
get_selection(software, system);
if (software && !software->startempty)
menu::stack_push<menu_dats_view>(ui(), container(), software);
menu::stack_push<menu_dats_view>(ui(), container(), *software);
else if (system)
menu::stack_push<menu_dats_view>(ui(), container(), system);
}