#pragma once
///
/// Types of debugging information to get the internal state of the emulated system.
///
enum DebugInfoType
{
DebugInfoType_Unknown = 0,
DebugInfoType_Test,
DebugInfoType_Core,
DebugInfoType_CoreRegs,
DebugInfoType_APU,
DebugInfoType_APURegs,
DebugInfoType_PPU,
DebugInfoType_PPURegs,
DebugInfoType_Board,
DebugInfoType_Cart,
};
#pragma pack(push, 1)
///
/// One entry of debugging information. On the managed application side, a PropertyGrid is created based on the debug entries.
///
struct DebugInfoEntry
{
char category[32];
char name[32];
uint8_t bits; // The number of significant bits in the value
uint32_t value;
};
#pragma pack(pop)
#pragma pack(push, 1)
///
/// Memory block descriptor
///
struct MemDesciptor
{
char name[32];
int32_t size;
};
#pragma pack(pop)
struct DebugInfoProvider
{
DebugInfoEntry* entry;
uint32_t(*GetValue)(void* opaque, DebugInfoEntry* entry);
void (*SetValue)(void* opaque, DebugInfoEntry* entry, uint32_t value);
void* opaque;
};
struct MemProvider
{
MemDesciptor* descr;
uint8_t(*ReadByte)(void* opaque, size_t addr);
void(*WriteByte)(void* opaque, size_t addr, uint8_t data);
void* opaque;
bool cartRelated;
};
class DebugHub
{
public:
std::list testInfo;
std::list coreInfo;
std::list coreRegsInfo;
std::list apuInfo;
std::list apuRegsInfo;
std::list ppuInfo;
std::list ppuRegsInfo;
std::list boardInfo;
std::list cartInfo;
std::list memMap;
DebugHub();
~DebugHub();
///
/// Add a handler for getting debugging information
///
/// Type of debugging information (corresponds to single PropertyGrid)
/// One entry of debugging information. Corresponds to a single signal/register/whatever. (auto-delete)
/// Delegate to get the value
/// Delegate to set the value
/// Transparent pointer to pass to the delegate (usually `this`)
void AddDebugInfo(DebugInfoType type, DebugInfoEntry* entry,
uint32_t(*GetValue)(void* opaque, DebugInfoEntry* entry),
void (*SetValue)(void* opaque, DebugInfoEntry* entry, uint32_t value),
void* opaque);
///
/// Delete all debugging information handlers
///
void DisposeDebugInfo();
///
/// Clear the registered handlers for "Cart" type only.
///
void DisposeCartDebugInfo();
///
/// Add a memory region access handler.
///
/// Memory descriptor (auto-delete)
/// Delegate to read one byte
/// Delegate to write one byte
/// Transparent pointer to pass to the delegate (usually `this`)
/// true: The memory region refers to the external cartridge.
void AddMemRegion(MemDesciptor* descr, uint8_t (*ReadByte)(void* opaque, size_t addr), void(*WriteByte)(void* opaque, size_t addr, uint8_t data), void* opaque, bool cartRelated);
///
/// Clear MemLayout.
///
void DisposeMemMap();
///
/// Clear cartRelated MemLayout only.
///
void DisposeCartMemMap();
};
extern DebugHub* dbg_hub;
void CreateDebugHub();
void DisposeDebugHub();