From 18483731855a0828bb6771e919e2618e7a2f27f1 Mon Sep 17 00:00:00 2001 From: Ignacio Sanchez Gines <863613+drhelius@users.noreply.github.com> Date: Fri, 31 Jan 2025 13:04:08 +0100 Subject: [PATCH] [debugger] Option to select reset values. #4 --- platforms/shared/desktop/config.cpp | 8 +++ platforms/shared/desktop/config.h | 4 ++ platforms/shared/desktop/gui_menus.cpp | 71 ++++++++++++++++++++++++++ src/huc6260.cpp | 11 +++- src/huc6260.h | 2 + src/huc6280.cpp | 29 +++++++++-- src/huc6280.h | 2 + src/memory.cpp | 26 ++++++++-- src/memory.h | 3 ++ 9 files changed, 146 insertions(+), 10 deletions(-) diff --git a/platforms/shared/desktop/config.cpp b/platforms/shared/desktop/config.cpp index 7cb11f3..e847bbf 100644 --- a/platforms/shared/desktop/config.cpp +++ b/platforms/shared/desktop/config.cpp @@ -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); @@ -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); diff --git a/platforms/shared/desktop/config.h b/platforms/shared/desktop/config.h index b7caa36..c317f51 100644 --- a/platforms/shared/desktop/config.h +++ b/platforms/shared/desktop/config.h @@ -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; diff --git a/platforms/shared/desktop/gui_menus.cpp b/platforms/shared/desktop/gui_menus.cpp index c97ef39..fe9d5f5 100644 --- a/platforms/shared/desktop/gui_menus.cpp +++ b/platforms/shared/desktop/gui_menus.cpp @@ -51,6 +51,7 @@ 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) { @@ -58,6 +59,10 @@ void gui_init_menus(void) 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) @@ -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); @@ -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; + } +} diff --git a/src/huc6260.cpp b/src/huc6260.cpp index 15ff6a3..9c22f8b 100644 --- a/src/huc6260.cpp +++ b/src/huc6260.cpp @@ -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() @@ -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; } } @@ -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); diff --git a/src/huc6260.h b/src/huc6260.h index fb2ebee..a5bb566 100644 --- a/src/huc6260.h +++ b/src/huc6260.h @@ -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); @@ -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] = { diff --git a/src/huc6280.cpp b/src/huc6280.cpp index 1104bfc..2f71dd5 100644 --- a/src/huc6280.cpp +++ b/src/huc6280.cpp @@ -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; @@ -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); @@ -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; diff --git a/src/huc6280.h b/src/huc6280.h index b89258f..c62ebae 100644 --- a/src/huc6280.h +++ b/src/huc6280.h @@ -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(); @@ -164,6 +165,7 @@ class HuC6280 GG_Breakpoint m_run_to_breakpoint; bool m_run_to_breakpoint_requested; std::stack m_disassembler_call_stack; + int m_reset_value; private: u32 TickOPCode(); diff --git a/src/memory.cpp b/src/memory.cpp index 33ea5b4..42bb112 100644 --- a/src/memory.cpp +++ b/src/memory.cpp @@ -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() @@ -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++) @@ -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)]; diff --git a/src/memory.h b/src/memory.h index 3b4a4f3..ef21201 100644 --- a/src/memory.h +++ b/src/memory.h @@ -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(); @@ -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"