diff options
author | MooglyGuy <therealmogminer@gmail.com> | 2019-07-07 05:07:36 +0200 |
---|---|---|
committer | MooglyGuy <therealmogminer@gmail.com> | 2019-07-07 05:07:36 +0200 |
commit | c87fb4ac1c63699a58160f503c550e44d36f9643 (patch) | |
tree | 35752596df412f05565e68c67cf0a852ef9e0504 | |
parent | 6421e6c31cd597f49bb51703f9b506ff9c5f3f45 (diff) |
-midtunit: Removed #define-based PNG/JSON logging and moved it to a debugger command. [Ryan Holtz]
-rw-r--r-- | src/mame/video/midtunit.cpp | 240 | ||||
-rw-r--r-- | src/mame/video/midtunit.h | 10 |
2 files changed, 182 insertions, 68 deletions
diff --git a/src/mame/video/midtunit.cpp b/src/mame/video/midtunit.cpp index 6643fa7ac0f..791821f1f25 100644 --- a/src/mame/video/midtunit.cpp +++ b/src/mame/video/midtunit.cpp @@ -12,10 +12,16 @@ #include "midtunit.ipp" #include "screen.h" #include "midtview.ipp" -#include "emuopts.h" // Used by MIDTUNIT_LOG_PNG -#include "png.h" // Used by MIDTUNIT_LOG_PNG -#include "rapidjson/include/rapidjson/prettywriter.h" // Used by MIDTUNIT_LOG_PNG_JSON -#include "rapidjson/include/rapidjson/stringbuffer.h" // Used by MIDTUNIT_LOG_PNG_JSON + +#include "debug/debugcon.h" +#include "debug/debugcmd.h" +#include "debugger.h" + +#include "emuopts.h" // Used by PNG logging +#include "png.h" // Used by PNG logging + +#include "rapidjson/include/rapidjson/prettywriter.h" // Used by JSON logging +#include "rapidjson/include/rapidjson/stringbuffer.h" // Used by JSON logging DEFINE_DEVICE_TYPE(MIDTUNIT_VIDEO, midtunit_video_device, "tunitvid", "Midway T-Unit Video") DEFINE_DEVICE_TYPE(MIDWUNIT_VIDEO, midwunit_video_device, "wunitvid", "Midway W-Unit Video") @@ -57,21 +63,123 @@ midxunit_video_device::midxunit_video_device(const machine_config &mconfig, cons /************************************* * + * Debugger commands + * + *************************************/ + +void midtunit_video_device::debug_init() +{ + if (machine().debug_flags & DEBUG_FLAG_ENABLED) + { + using namespace std::placeholders; + machine().debugger().console().register_command("midblit", CMDFLAG_CUSTOM_HELP, 0, 1, 4, std::bind(&midtunit_video_device::debug_commands, this, _1, _2)); + } +} + +void midtunit_video_device::debug_commands(int ref, const std::vector<std::string> ¶ms) +{ + if (params.size() < 1) + return; + + if (params[0] == "pngdma") + debug_png_dma_command(ref, params); + else + debug_help_command(ref, params); +} + +void midtunit_video_device::debug_help_command(int ref, const std::vector<std::string> ¶ms) +{ + debugger_console &con = machine().debugger().console(); + + con.printf("Available Midway Blitter commands:\n"); + con.printf(" midblit pngdma,<enable>[,<path>][,<logjson>] -- Enable or disable dumping of DMA-drawn sprite PNGs to <path>, with or without JSON metadata\n"); + con.printf(" midblit help -- this list\n"); +} + +void midtunit_video_device::debug_png_dma_command(int ref, const std::vector<std::string> ¶ms) +{ + debugger_console &con = machine().debugger().console(); + + if (params.size() < 2) + { + con.printf("Error: not enough parameters for midblit pngdma command\n"); + return; + } + + if (params.size() > 4) + { + con.printf("Error: too many parameters for midblit pngdma command\n"); + return; + } + + bool old_state = m_log_png; + bool new_state = false; + if (!machine().debugger().commands().validate_boolean_parameter(params[1], new_state)) + return; + + if (!new_state) + { + if (params.size() > 2) + { + con.printf("Error: too many parameters for midblit pngdma command\n"); + return; + } + m_log_png = false; + return; + } + + if (params.size() < 3) + { + con.printf("Error: not enough parameters for midblit pngdma command\n"); + return; + } + + if (params[2].empty() || params[2].length() > 2047) + { + con.printf("Error: invalid path parameter for midblit pngdma command\n"); + return; + } + + strncpy(m_log_path, params[2].c_str(), 2047); + + if (params.size() == 4) + { + if (!machine().debugger().commands().validate_boolean_parameter(params[3], m_log_json)) + return; + } + + m_log_png = new_state; + + if (!old_state && new_state) + { + m_logged_rom = make_unique_clear<uint64_t[]>(0x4000000); + } + else if (old_state && !new_state) + { + m_logged_rom.reset(); + } +} + + +/************************************* + * * Video startup * *************************************/ void midtunit_video_device::device_start() { + debug_init(); + /* allocate memory */ m_local_videoram = std::make_unique<uint16_t[]>(0x100000/2); #if DEBUG_MIDTUNIT_BLITTER m_debug_videoram = std::make_unique<uint16_t[]>(0x100000/2); #endif -#if MIDTUNIT_LOG_PNG - m_logged_rom = std::make_unique<uint64_t[]>(0x4000000); -#endif + + m_logged_rom.reset(); + m_log_png = false; m_dma_timer = timer_alloc(TIMER_DMA); @@ -689,16 +797,17 @@ WRITE16_MEMBER(midtunit_video_device::midtunit_dma_w) m_dma_state.endskip = m_dma_register[DMA_LRSKIP]; } -#if MIDTUNIT_LOG_PNG - if (command & 0x80) - { - log_bitmap(command, bpp ? bpp : 8, true); - } - else + if (m_log_png) { - log_bitmap(command, bpp ? bpp : 8, false); + if (command & 0x80) + { + log_bitmap(command, bpp ? bpp : 8, true); + } + else + { + log_bitmap(command, bpp ? bpp : 8, false); + } } -#endif /* then draw */ if (m_dma_state.xstep == 0x100 && m_dma_state.ystep == 0x100) @@ -760,7 +869,6 @@ TMS340X0_SCANLINE_IND16_CB_MEMBER(midxunit_video_device::scanline_update) dest[x] = src[fulladdr++ & 0x1ff] & 0x7fff; } -#if MIDTUNIT_LOG_PNG void midtunit_video_device::log_bitmap(int command, int bpp, bool Skip) { const uint32_t raw_offset = m_dma_register[DMA_OFFSETLO] | (m_dma_register[DMA_OFFSETHI] << 16); @@ -789,7 +897,7 @@ void midtunit_video_device::log_bitmap(int command, int bpp, bool Skip) default: return; } - emu_file file(machine().options().snapshot_directory(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS); + emu_file file(m_log_path, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS); char name_buf[256]; snprintf(name_buf, 255, "0x%08x.png", raw_offset); @@ -912,69 +1020,69 @@ void midtunit_video_device::log_bitmap(int command, int bpp, bool Skip) png_write_bitmap(file, nullptr, m_log_bitmap, 0, nullptr); -#if MIDTUNIT_LOG_PNG_JSON - char hex_buf[11]; - rapidjson::StringBuffer s; - rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(s); - emu_file json(machine().options().snapshot_directory(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS); - - snprintf(name_buf, 255, "0x%08x.json", raw_offset); - auto const jsonerr = json.open(name_buf); - if (jsonerr != osd_file::error::NONE) + if (m_log_json) { - return; - } + char hex_buf[11]; + rapidjson::StringBuffer s; + rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(s); + emu_file json(m_log_path, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS); + + snprintf(name_buf, 255, "0x%08x.json", raw_offset); + auto const jsonerr = json.open(name_buf); + if (jsonerr != osd_file::error::NONE) + { + return; + } - writer.StartObject(); - writer.Key("DMAState"); - writer.StartObject(); + writer.StartObject(); + writer.Key("DMAState"); + writer.StartObject(); - sprintf(hex_buf, "0x%08x", raw_offset); - writer.Key("MemoryAddress"); - writer.String(hex_buf); + sprintf(hex_buf, "0x%08x", raw_offset); + writer.Key("MemoryAddress"); + writer.String(hex_buf); - sprintf(hex_buf, "0x%08x", m_dma_state.offset); - writer.Key("ROMSourceOffset"); - writer.String(hex_buf); + sprintf(hex_buf, "0x%08x", m_dma_state.offset); + writer.Key("ROMSourceOffset"); + writer.String(hex_buf); - writer.Key("Size"); - writer.StartArray(); - writer.Int(m_dma_state.width); - writer.Int(m_dma_state.height); - writer.EndArray(); + writer.Key("Size"); + writer.StartArray(); + writer.Int(m_dma_state.width); + writer.Int(m_dma_state.height); + writer.EndArray(); - writer.Key("BitsPerPixel"); - writer.Uint(bpp); + writer.Key("BitsPerPixel"); + writer.Uint(bpp); - writer.Key("PaletteBank"); - writer.Uint(m_dma_state.palette >> 8); + writer.Key("PaletteBank"); + writer.Uint(m_dma_state.palette >> 8); - writer.Key("FGColor"); - writer.Uint(m_dma_state.color); + writer.Key("FGColor"); + writer.Uint(m_dma_state.color); - writer.Key("YFlip"); - writer.Bool(m_dma_state.yflip ? true : false); + writer.Key("YFlip"); + writer.Bool(m_dma_state.yflip ? true : false); - writer.Key("PreSkipScale"); - writer.Uint(m_dma_state.preskip); + writer.Key("PreSkipScale"); + writer.Uint(m_dma_state.preskip); - writer.Key("PostSkipScale"); - writer.Uint(m_dma_state.postskip); + writer.Key("PostSkipScale"); + writer.Uint(m_dma_state.postskip); - writer.Key("RowSkipBits"); - writer.Int(m_dma_state.rowbits); + writer.Key("RowSkipBits"); + writer.Int(m_dma_state.rowbits); - writer.Key("StartPixelsToSkip"); - writer.Int(m_dma_state.startskip); + writer.Key("StartPixelsToSkip"); + writer.Int(m_dma_state.startskip); - writer.Key("EndPixelsToSkip"); - writer.Int(m_dma_state.endskip); + writer.Key("EndPixelsToSkip"); + writer.Int(m_dma_state.endskip); - writer.EndObject(); - writer.EndObject(); + writer.EndObject(); + writer.EndObject(); - json.puts(s.GetString()); - json.close(); -#endif + json.puts(s.GetString()); + json.close(); + } } -#endif
\ No newline at end of file diff --git a/src/mame/video/midtunit.h b/src/mame/video/midtunit.h index c020623b5f9..f190c561b56 100644 --- a/src/mame/video/midtunit.h +++ b/src/mame/video/midtunit.h @@ -167,12 +167,18 @@ protected: int32_t m_debug_dma_mode; int32_t m_debug_dma_command; #endif -#if MIDTUNIT_LOG_PNG + + char m_log_path[2048]; + bool m_log_png; + bool m_log_json; std::unique_ptr<uint64_t[]> m_logged_rom; bitmap_argb32 m_log_bitmap; + void debug_init(); + void debug_commands(int ref, const std::vector<std::string> ¶ms); + void debug_help_command(int ref, const std::vector<std::string> ¶ms); + void debug_png_dma_command(int ref, const std::vector<std::string> ¶ms); void log_bitmap(int command, int bpp, bool skip); -#endif }; class midwunit_video_device : public midtunit_video_device |