diff options
Diffstat (limited to 'src/frontend/mame/cheat.cpp')
-rw-r--r-- | src/frontend/mame/cheat.cpp | 68 |
1 files changed, 41 insertions, 27 deletions
diff --git a/src/frontend/mame/cheat.cpp b/src/frontend/mame/cheat.cpp index 61cda1cf475..e0d890ebda6 100644 --- a/src/frontend/mame/cheat.cpp +++ b/src/frontend/mame/cheat.cpp @@ -81,6 +81,7 @@ #include "corestr.h" #include "emuopts.h" +#include "fileio.h" #include <cstring> #include <iterator> @@ -204,7 +205,7 @@ const char *cheat_parameter::text() // save - save a single cheat parameter //------------------------------------------------- -void cheat_parameter::save(emu_file &cheatfile) const +void cheat_parameter::save(util::core_file &cheatfile) const { // output the parameter tag cheatfile.printf("\t\t<parameter"); @@ -367,7 +368,7 @@ void cheat_script::execute(cheat_manager &manager, uint64_t &argindex) // save - save a single cheat script //------------------------------------------------- -void cheat_script::save(emu_file &cheatfile) const +void cheat_script::save(util::core_file &cheatfile) const { // output the script tag cheatfile.printf("\t\t<script"); @@ -418,6 +419,10 @@ cheat_script::script_entry::script_entry( if (!expression || !expression[0]) throw emu_fatalerror("%s.xml(%d): missing expression in action tag\n", filename, entrynode.line); m_expression.parse(expression); + + // initialise these to defautlt values + m_line = 0; + m_justify = ui::text_layout::text_justify::LEFT; } else { @@ -431,12 +436,12 @@ cheat_script::script_entry::script_entry( // extract other attributes m_line = entrynode.get_attribute_int("line", 0); - m_justify = ui::text_layout::LEFT; + m_justify = ui::text_layout::text_justify::LEFT; char const *const align(entrynode.get_attribute_string("align", "left")); if (!std::strcmp(align, "center")) - m_justify = ui::text_layout::CENTER; + m_justify = ui::text_layout::text_justify::CENTER; else if (!std::strcmp(align, "right")) - m_justify = ui::text_layout::RIGHT; + m_justify = ui::text_layout::text_justify::RIGHT; else if (std::strcmp(align, "left")) throw emu_fatalerror("%s.xml(%d): invalid alignment '%s' specified\n", filename, entrynode.line, align); @@ -527,7 +532,7 @@ void cheat_script::script_entry::execute(cheat_manager &manager, uint64_t &argin // save - save a single action or output //------------------------------------------------- -void cheat_script::script_entry::save(emu_file &cheatfile) const +void cheat_script::script_entry::save(util::core_file &cheatfile) const { if (m_format.empty()) { @@ -540,16 +545,16 @@ void cheat_script::script_entry::save(emu_file &cheatfile) const else { // output an output - cheatfile.printf("\t\t\t<output format=\"%s\"", m_format.c_str()); + cheatfile.printf("\t\t\t<output format=\"%s\"", m_format); if (!m_condition.is_empty()) cheatfile.printf(" condition=\"%s\"", cheat_manager::quote_expression(m_condition)); if (m_line != 0) cheatfile.printf(" line=\"%d\"", m_line); - if (m_justify == ui::text_layout::CENTER) + if (m_justify == ui::text_layout::text_justify::CENTER) cheatfile.printf(" align=\"center\""); - else if (m_justify == ui::text_layout::RIGHT) + else if (m_justify == ui::text_layout::text_justify::RIGHT) cheatfile.printf(" align=\"right\""); if (m_arglist.size() == 0) @@ -658,7 +663,7 @@ int cheat_script::script_entry::output_argument::values(uint64_t &argindex, uint // save - save a single output argument //------------------------------------------------- -void cheat_script::script_entry::output_argument::save(emu_file &cheatfile) const +void cheat_script::script_entry::output_argument::save(util::core_file &cheatfile) const { cheatfile.printf("\t\t\t\t<argument"); if (m_count != 1) @@ -758,7 +763,7 @@ cheat_entry::~cheat_entry() // save - save a single cheat entry //------------------------------------------------- -void cheat_entry::save(emu_file &cheatfile) const +void cheat_entry::save(util::core_file &cheatfile) const { // determine if we have scripts bool const has_scripts(m_off_script || m_on_script || m_run_script || m_change_script); @@ -1056,6 +1061,9 @@ constexpr int cheat_manager::CHEAT_VERSION; cheat_manager::cheat_manager(running_machine &machine) : m_machine(machine) + , m_framecount(0) + , m_numlines(0) + , m_lastline(0) , m_disabled(true) , m_symtable(machine) { @@ -1090,7 +1098,7 @@ cheat_manager::cheat_manager(running_machine &machine) // cheat engine //------------------------------------------------- -void cheat_manager::set_enable(bool enable) +void cheat_manager::set_enable(bool enable, bool show) { // if the cheat engine is disabled, we're done if (!machine().options().cheat()) @@ -1106,7 +1114,8 @@ void cheat_manager::set_enable(bool enable) if (cheat->state() == SCRIPT_STATE_RUN) cheat->execute_off_script(); } - machine().popmessage("Cheats Disabled"); + if (show) + machine().popmessage("Cheats Disabled"); m_disabled = true; } else if (m_disabled && enable) @@ -1120,7 +1129,8 @@ void cheat_manager::set_enable(bool enable) if (cheat->state() == SCRIPT_STATE_RUN) cheat->execute_on_script(); } - machine().popmessage("Cheats Enabled"); + if (show) + machine().popmessage("Cheats Enabled"); } } @@ -1191,10 +1201,10 @@ bool cheat_manager::save_all(std::string const &filename) { // open the file with the proper name emu_file cheatfile(machine().options().cheat_path(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS); - osd_file::error const filerr(cheatfile.open(filename + ".xml")); + std::error_condition const filerr(cheatfile.open(filename + ".xml")); // if that failed, return nothing - if (filerr != osd_file::error::NONE) + if (filerr) return false; // wrap the rest of catch errors @@ -1236,10 +1246,13 @@ void cheat_manager::render_text(mame_ui_manager &mui, render_container &containe if (!m_output[linenum].empty()) { // output the text - mui.draw_text_full(container, m_output[linenum], + mui.draw_text_full( + container, + m_output[linenum], 0.0f, float(linenum) * mui.get_line_height(), 1.0f, - m_justify[linenum], ui::text_layout::NEVER, mame_ui_manager::OPAQUE_, - rgb_t::white(), rgb_t::black(), nullptr, nullptr); + m_justify[linenum], ui::text_layout::word_wrapping::NEVER, + mame_ui_manager::OPAQUE_, rgb_t::white(), rgb_t::black(), + nullptr, nullptr); } } } @@ -1264,7 +1277,8 @@ std::string &cheat_manager::get_output_string(int row, ui::text_layout::text_jus row = (row < 0) ? (m_numlines + row) : (row - 1); // clamp within range - row = std::min(std::max(row, 0), m_numlines - 1); + assert(m_numlines > 0); + row = std::clamp(row, 0, m_numlines - 1); // return the appropriate string m_justify[row] = justify; @@ -1292,6 +1306,11 @@ std::string cheat_manager::quote_expression(const parsed_expression &expression) strreplace(str, "& ", " band "); strreplace(str, "&", " band "); + strreplace(str, " << ", " lshift "); + strreplace(str, " <<", " lshift "); + strreplace(str, "<< ", " lshift "); + strreplace(str, "<<", " lshift "); + strreplace(str, " <= ", " le "); strreplace(str, " <=", " le "); strreplace(str, "<= ", " le "); @@ -1302,11 +1321,6 @@ std::string cheat_manager::quote_expression(const parsed_expression &expression) strreplace(str, "< ", " lt "); strreplace(str, "<", " lt "); - strreplace(str, " << ", " lshift "); - strreplace(str, " <<", " lshift "); - strreplace(str, "<< ", " lshift "); - strreplace(str, "<<", " lshift "); - return str; } @@ -1389,8 +1403,8 @@ void cheat_manager::load_cheats(std::string const &filename) emu_file cheatfile(std::move(searchstr), OPEN_FLAG_READ); try { - // loop over all instrances of the files found in our search paths - for (osd_file::error filerr = cheatfile.open(filename + ".xml"); filerr == osd_file::error::NONE; filerr = cheatfile.open_next()) + // loop over all instances of the files found in our search paths + for (std::error_condition filerr = cheatfile.open(filename + ".xml"); !filerr; filerr = cheatfile.open_next()) { osd_printf_verbose("Loading cheats file from %s\n", cheatfile.fullpath()); |