-midtunit: Removed #define-based PNG/JSON logging and moved it to a debugger command. [Ryan Holtz]

This commit is contained in:
MooglyGuy 2019-07-07 05:07:36 +02:00
parent 6421e6c31c
commit c87fb4ac1c
2 changed files with 196 additions and 82 deletions

View File

@ -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")
@ -55,6 +61,106 @@ 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> &params)
{
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> &params)
{
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> &params)
{
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
@ -63,15 +169,17 @@ midxunit_video_device::midxunit_video_device(const machine_config &mconfig, cons
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)
if (m_log_png)
{
log_bitmap(command, bpp ? bpp : 8, true);
if (command & 0x80)
{
log_bitmap(command, bpp ? bpp : 8, true);
}
else
{
log_bitmap(command, bpp ? bpp : 8, false);
}
}
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();
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);
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("PaletteBank");
writer.Uint(m_dma_state.palette >> 8);
writer.Key("FGColor");
writer.Uint(m_dma_state.color);
writer.Key("YFlip");
writer.Bool(m_dma_state.yflip ? true : false);
writer.Key("PreSkipScale");
writer.Uint(m_dma_state.preskip);
writer.Key("PostSkipScale");
writer.Uint(m_dma_state.postskip);
writer.Key("RowSkipBits");
writer.Int(m_dma_state.rowbits);
writer.Key("StartPixelsToSkip");
writer.Int(m_dma_state.startskip);
writer.Key("EndPixelsToSkip");
writer.Int(m_dma_state.endskip);
writer.EndObject();
writer.EndObject();
json.puts(s.GetString());
json.close();
}
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", 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("BitsPerPixel");
writer.Uint(bpp);
writer.Key("PaletteBank");
writer.Uint(m_dma_state.palette >> 8);
writer.Key("FGColor");
writer.Uint(m_dma_state.color);
writer.Key("YFlip");
writer.Bool(m_dma_state.yflip ? true : false);
writer.Key("PreSkipScale");
writer.Uint(m_dma_state.preskip);
writer.Key("PostSkipScale");
writer.Uint(m_dma_state.postskip);
writer.Key("RowSkipBits");
writer.Int(m_dma_state.rowbits);
writer.Key("StartPixelsToSkip");
writer.Int(m_dma_state.startskip);
writer.Key("EndPixelsToSkip");
writer.Int(m_dma_state.endskip);
writer.EndObject();
writer.EndObject();
json.puts(s.GetString());
json.close();
#endif
}
#endif

View File

@ -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> &params);
void debug_help_command(int ref, const std::vector<std::string> &params);
void debug_png_dma_command(int ref, const std::vector<std::string> &params);
void log_bitmap(int command, int bpp, bool skip);
#endif
};
class midwunit_video_device : public midtunit_video_device