Skip to content

Commit

Permalink
-midtunit: Added optional debug #define to emit JSON metadata about e…
Browse files Browse the repository at this point in the history
…ach DMA draw call. [Ryan Holtz]
  • Loading branch information
MooglyGuy committed Jul 6, 2019
1 parent 3fcf49a commit 6c9ab2f
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
67 changes: 67 additions & 0 deletions src/mame/video/midtunit.cpp
Expand Up @@ -14,6 +14,8 @@
#include "midtview.ipp"
#include "emuopts.h" // Used by MIDTUNIT_LOG_PNG
#include "png.h" // Used by MIDTUNIT_LOG_PNG
#include <rapidjson/prettywriter.h> // Used by MIDTUNIT_LOG_PNG_JSON
#include <rapidjson/stringbuffer.h> // Used by MIDTUNIT_LOG_PNG_JSON

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")
Expand Down Expand Up @@ -909,5 +911,70 @@ 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)
{
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();
#endif
}
#endif
1 change: 1 addition & 0 deletions src/mame/video/midtunit.h
Expand Up @@ -18,6 +18,7 @@

#define DEBUG_MIDTUNIT_BLITTER (0)
#define MIDTUNIT_LOG_PNG (0)
#define MIDTUNIT_LOG_PNG_JSON (0)

class midtunit_video_device : public device_t
{
Expand Down

12 comments on commit 6c9ab2f

@angelosa
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This stuff should go into a custom debug command, not a compile switch.
You can checkout src/mame/machine/xbox.cpp or src/mame/machine/model2.cpp for usage, should be pretty straightforward.

@MooglyGuy
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with what I assume is your concern about the code rotting over time, but I disagree with the performance implications of checking a debug flag for every single DMA-draw call that Midway T-Unit games (and therefore, also Wolf-Unit and X-Unit games) make.

@angelosa
Copy link
Member

@angelosa angelosa commented on 6c9ab2f Jul 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Compile switches are bad cause, as the name implies, you have to compile in order to enable them. Which also makes zero usefulness if for instance I want to check the behaviour in a specific MAME version.

As for the performance concern, think about the trace command: it's not always enabled but user decides when to turn on or off at will.

@MooglyGuy
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems you feel very strongly about this. By all means, feel free to improve it and hook it up to a debugger command.

@MooglyGuy
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've taken your suggestion and implemented a debugger command for logging PNGs, rather than having it stuck behind a #define.

However, when I type "help" in the debugger, it seems that driver-specific debugger commands are not listed. So how is a user supposed to know what debugger commands have been exposed by a given driver? That makes this an unacceptable solution, in my opinion.

@angelosa
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's actually an inconvenience of the custom commands: the help itself should tell the user that there actually are per-driver commands registered.

@MooglyGuy
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does now, sort of. There's now a 'helpcustom' command which will look for registered debug commands that have been flagged as having custom help, and display their help lists.

@g0d1npla1ns1ght
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I found the Available Midway Blitter command and believe I enabled midblit pngdma by performing the following: "midblit pngdma enable c:\mame\roms\nbajamte\pngs logjson"

How to I get MAME to dump the sprites?

@g0d1npla1ns1ght
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay...how do I use the feature to log PNGs? There is no instruction on how to input the path. Admittedly I'm not a coder, but like messing with MAME / ROMS in my spare time. I was smart enough to compile MAME and get to the debug feature, but I am not familiar enough with C++ to make the debug feature work. Any help would be appreciated.

@MooglyGuy
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You enable it from the debugger.

@g0d1npla1ns1ght
Copy link

@g0d1npla1ns1ght g0d1npla1ns1ght commented on 6c9ab2f Jan 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get to the point where I type midblit pngdma enable but I don't believe I am inputting the path correctly. How do I give the path?

@MooglyGuy
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the included 'help' command. Github is not intended to be a support forum.

Please sign in to comment.