Skip to content

Commit

Permalink
[debugger] Option to select reset values. #4
Browse files Browse the repository at this point in the history
  • Loading branch information
drhelius committed Jan 31, 2025
1 parent 2562b8f commit 1848373
Show file tree
Hide file tree
Showing 9 changed files with 146 additions and 10 deletions.
8 changes: 8 additions & 0 deletions platforms/shared/desktop/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ void config_read(void)
config_debug.dis_replace_labels = read_bool("Debug", "DisReplaceLabels", true);
config_debug.font_size = read_int("Debug", "FontSize", 0);
config_debug.multi_viewport = read_bool("Debug", "MultiViewport", false);
config_debug.reset_ram = read_int("Debug", "InitRam", 0);
config_debug.reset_registers = read_int("Debug", "InitRegisters", 0);
config_debug.reset_color_table = read_int("Debug", "InitColorTable", 0);
config_debug.reset_mpr = read_int("Debug", "InitMPR", 0);

config_emulator.maximized = read_bool("Emulator", "Maximized", false);
config_emulator.fullscreen = read_bool("Emulator", "FullScreen", false);
Expand Down Expand Up @@ -267,6 +271,10 @@ void config_write(void)
write_bool("Debug", "DisReplaceLabels", config_debug.dis_replace_labels);
write_int("Debug", "FontSize", config_debug.font_size);
write_bool("Debug", "MultiViewport", config_debug.multi_viewport);
write_int("Debug", "InitRam", config_debug.reset_ram);
write_int("Debug", "InitRegisters", config_debug.reset_registers);
write_int("Debug", "InitColorTable", config_debug.reset_color_table);
write_int("Debug", "InitMPR", config_debug.reset_mpr);

write_bool("Emulator", "Maximized", config_emulator.maximized);
write_bool("Emulator", "FullScreen", config_emulator.fullscreen);
Expand Down
4 changes: 4 additions & 0 deletions platforms/shared/desktop/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ struct config_Debug
bool dis_replace_labels = true;
int font_size = 0;
bool multi_viewport = false;
int reset_ram = 0;
int reset_registers = 0;
int reset_color_table = 0;
int reset_mpr = 0;
};

EXTERN mINI::INIFile* config_ini_file;
Expand Down
71 changes: 71 additions & 0 deletions platforms/shared/desktop/gui_menus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,18 @@ static void file_dialogs(void);
static void keyboard_configuration_item(const char* text, SDL_Scancode* key, int player);
static void gamepad_configuration_item(const char* text, int* button, int player);
static void draw_savestate_slot_info(int slot);
static int get_reset_value(int option);

void gui_init_menus(void)
{
strcpy(gui_savefiles_path, config_emulator.savefiles_path.c_str());
strcpy(gui_savestates_path, config_emulator.savestates_path.c_str());
strcpy(gui_screenshots_path, config_emulator.screenshots_path.c_str());
gui_shortcut_open_rom = false;

emu_get_core()->GetMemory()->SetResetValues(get_reset_value(config_debug.reset_mpr), get_reset_value(config_debug.reset_ram));
emu_get_core()->GetHuC6260()->SetResetValue(get_reset_value(config_debug.reset_color_table));
emu_get_core()->GetHuC6280()->SetResetValue(get_reset_value(config_debug.reset_registers));
}

void gui_main_menu(void)
Expand Down Expand Up @@ -586,6 +591,57 @@ static void menu_debug(void)

ImGui::Separator();

if (ImGui::BeginMenu("Reset Values"))
{
if (ImGui::BeginMenu("RAM"))
{
ImGui::PushItemWidth(100.0f);
if (ImGui::Combo("##init_ram", &config_debug.reset_ram, "Random\0 0x00\0 0xFF\0\0"))
{
emu_get_core()->GetMemory()->SetResetValues(get_reset_value(config_debug.reset_mpr), get_reset_value(config_debug.reset_ram));
}
ImGui::PopItemWidth();
ImGui::EndMenu();
}

if (ImGui::BeginMenu("Registers"))
{
ImGui::PushItemWidth(100.0f);
if (ImGui::Combo("##init_registers", &config_debug.reset_registers, "Random\0 0x00\0 0xFF\0\0"))
{
emu_get_core()->GetHuC6280()->SetResetValue(get_reset_value(config_debug.reset_registers));
}
ImGui::PopItemWidth();
ImGui::EndMenu();
}

if (ImGui::BeginMenu("Palettes"))
{
ImGui::PushItemWidth(100.0f);
if (ImGui::Combo("##init_color_table", &config_debug.reset_color_table, "Random\0 0x0000\0 0x01FF\0\0"))
{
emu_get_core()->GetHuC6260()->SetResetValue(get_reset_value(config_debug.reset_color_table));
}
ImGui::PopItemWidth();
ImGui::EndMenu();
}

if (ImGui::BeginMenu("MPRs"))
{
ImGui::PushItemWidth(100.0f);
if (ImGui::Combo("##init_mpr", &config_debug.reset_mpr, "Random\0 0x00\0 0xFF\0\0"))
{
emu_get_core()->GetMemory()->SetResetValues(get_reset_value(config_debug.reset_mpr), get_reset_value(config_debug.reset_ram));
}
ImGui::PopItemWidth();
ImGui::EndMenu();
}

ImGui::EndMenu();
}

ImGui::Separator();

ImGui::MenuItem("Show Output Screen", "", &config_debug.show_screen, config_debug.debug);
ImGui::MenuItem("Show Disassembler", "", &config_debug.show_disassembler, config_debug.debug);
ImGui::MenuItem("Show HuC6280 Status", "", &config_debug.show_processor, config_debug.debug);
Expand Down Expand Up @@ -740,3 +796,18 @@ static void draw_savestate_slot_info(int slot)
ImGui::TextColored(ImVec4(0.50f, 0.50f, 0.50f, 1.0f), "Slot %d is empty", slot + 1);
}
}

static int get_reset_value(int option)
{
switch (option)
{
case 0:
return -1;
case 1:
return 0x0000;
case 2:
return 0xFFFF;
default:
return -1;
}
}
11 changes: 10 additions & 1 deletion src/huc6260.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ HuC6260::HuC6260(HuC6270* huc6270, HuC6280* huc6280)
m_overscan = 0;
m_scanline_start = 0;
m_scanline_end = 239;
m_reset_value = -1;
}

HuC6260::~HuC6260()
Expand Down Expand Up @@ -101,7 +102,10 @@ void HuC6260::Reset()

for (int i = 0; i < 512; i++)
{
m_color_table[i] = rand() & 0x1FF;
if (m_reset_value < 0)
m_color_table[i] = rand() & 0x1FF;
else
m_color_table[i] = m_reset_value & 0x1FF;
}
}

Expand Down Expand Up @@ -247,6 +251,11 @@ GG_Pixel_Format HuC6260::GetPixelFormat()
return m_pixel_format;
}

void HuC6260::SetResetValue(int value)
{
m_reset_value = value;
}

void HuC6260::WritePixel(u16 pixel)
{
assert(pixel < 512);
Expand Down
2 changes: 2 additions & 0 deletions src/huc6260.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class HuC6260
void SetScanlineEnd(int scanline_end);
void SetOverscan(bool overscan);
GG_Pixel_Format GetPixelFormat();
void SetResetValue(int value);
void SaveState(std::ostream& stream);
void LoadState(std::istream& stream);

Expand Down Expand Up @@ -112,6 +113,7 @@ class HuC6260
u16 m_bgr565_palette[512];
u16 m_rgb555_palette[512];
u16 m_bgr555_palette[512];
int m_reset_value;
};

static const HuC6260::HuC6260_Speed k_huc6260_speed[4] = {
Expand Down
29 changes: 24 additions & 5 deletions src/huc6280.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ HuC6280::HuC6280()
InitOPCodeFunctors();
m_breakpoints_enabled = false;
m_breakpoints_irq_enabled = false;
m_reset_value = -1;
m_processor_state.A = &m_A;
m_processor_state.X = &m_X;
m_processor_state.Y = &m_Y;
Expand Down Expand Up @@ -64,11 +65,24 @@ void HuC6280::Reset()
m_PC.SetHigh(m_memory->Read(0xFFFF));
m_debug_next_irq = 1;
DisassembleNextOPCode();
m_A.SetValue(rand() & 0xFF);
m_X.SetValue(rand() & 0xFF);
m_Y.SetValue(rand() & 0xFF);
m_S.SetValue(rand() & 0xFF);
m_P.SetValue(rand() & 0xFF);

if (m_reset_value < 0)
{
m_A.SetValue(rand() & 0xFF);
m_X.SetValue(rand() & 0xFF);
m_Y.SetValue(rand() & 0xFF);
m_S.SetValue(rand() & 0xFF);
m_P.SetValue(rand() & 0xFF);
}
else
{
m_A.SetValue(m_reset_value & 0xFF);
m_X.SetValue(m_reset_value & 0xFF);
m_Y.SetValue(m_reset_value & 0xFF);
m_S.SetValue(m_reset_value & 0xFF);
m_P.SetValue(m_reset_value & 0xFF);
}

ClearFlag(FLAG_TRANSFER);
ClearFlag(FLAG_DECIMAL);
SetFlag(FLAG_INTERRUPT);
Expand Down Expand Up @@ -263,6 +277,11 @@ void HuC6280::DisassembleNextOPCode()
#endif
}

void HuC6280::SetResetValue(int value)
{
m_reset_value = value;
}

void HuC6280::EnableBreakpoints(bool enable, bool irqs)
{
m_breakpoints_enabled = enable;
Expand Down
2 changes: 2 additions & 0 deletions src/huc6280.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ class HuC6280
void WriteTimerRegister(u16 address, u8 value);
HuC6280_State* GetState();
void DisassembleNextOPCode();
void SetResetValue(int value);
void EnableBreakpoints(bool enable, bool irqs);
bool BreakpointHit();
bool RunToBreakpointHit();
Expand Down Expand Up @@ -164,6 +165,7 @@ class HuC6280
GG_Breakpoint m_run_to_breakpoint;
bool m_run_to_breakpoint_requested;
std::stack<GG_CallStackEntry> m_disassembler_call_stack;
int m_reset_value;

private:
u32 TickOPCode();
Expand Down
26 changes: 22 additions & 4 deletions src/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ Memory::Memory(HuC6260* huc6260, HuC6270* huc6270, HuC6280* huc6280, Cartridge*
InitPointer(m_test_memory);
InitPointer(m_current_mapper);
InitPointer(m_sf2_mapper);
m_mpr_reset_value = -1;
m_wram_reset_value = -1;
}

Memory::~Memory()
Expand Down Expand Up @@ -87,15 +89,25 @@ void Memory::Reset()

for (int i = 0; i < 7; i++)
{
do
if (m_mpr_reset_value < 0)
{
m_mpr[i] = rand() & 0xFF;
do
{
m_mpr[i] = rand() & 0xFF;
}
while (m_mpr[i] == 0x00);
}
while (m_mpr[i] == 0x00);
else
m_mpr[i] = m_mpr_reset_value & 0xFF;
}

for (int i = 0; i < 0x2000; i++)
m_wram[i] = rand() & 0xFF;
{
if (m_wram_reset_value < 0)
m_wram[i] = rand() & 0xFF;
else
m_wram[i] = m_wram_reset_value & 0xFF;
}

#if defined(GG_TESTING)
for (int i = 0; i < 0x10000; i++)
Expand All @@ -111,6 +123,12 @@ void Memory::Reset()
m_current_mapper = NULL;
}

void Memory::SetResetValues(int mpr, int wram)
{
m_mpr_reset_value = mpr;
m_wram_reset_value = wram;
}

Memory::GG_Disassembler_Record* Memory::GetDisassemblerRecord(u16 address)
{
return m_disassembler[GetPhysicalAddress(address)];
Expand Down
3 changes: 3 additions & 0 deletions src/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class Memory
u8 GetMprTMA(u8 bits);
u32 GetPhysicalAddress(u16 address);
u8 GetBank(u16 address);
void SetResetValues(int mpr, int wram);
GG_Disassembler_Record* GetDisassemblerRecord(u16 address);
GG_Disassembler_Record* GetOrCreateDisassemblerRecord(u16 address);
void ResetDisassemblerRecords();
Expand All @@ -88,6 +89,8 @@ class Memory
u8 m_mpr_buffer;
u8* m_test_memory;
Mapper* m_current_mapper;
int m_mpr_reset_value;
int m_wram_reset_value;
};

#include "memory_inline.h"
Expand Down

0 comments on commit 1848373

Please sign in to comment.