Skip to content

Commit

Permalink
added register change breakpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
timlump committed Jun 1, 2020
1 parent b150cc0 commit 80ef2f7
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 9 deletions.
4 changes: 3 additions & 1 deletion CpuMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,10 @@ void CpuMenu::draw_menu()
ImGui::Text("Pointers");
}

// register contents
std::string reg_name = MipsToString::register_to_string(idx);
ImGui::Checkbox(std::string("##" + reg_name).c_str(), &psx->cpu->register_file.break_on_change[idx]);
ImGui::SameLine();
// register contents
int * reg_ref = reinterpret_cast<int*>(psx->cpu->register_file.get_register_ref(idx));
ImGui::InputInt(reg_name.c_str(), reg_ref, 1, 100, ImGuiInputTextFlags_CharsHexadecimal);
}
Expand Down
1 change: 1 addition & 0 deletions CpuMenu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class CpuMenu : public DebugMenu
virtual void draw_menu() final;

virtual void tick() final;

private:
bool is_visible = false;
};
15 changes: 9 additions & 6 deletions DebugMenuManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "GpuMenu.hpp"
#include "CdromMenu.hpp"

#include <iostream>
#include <sstream>

void DebugMenuManager::init(GLFWwindow* window, std::shared_ptr<Psx> _psx)
Expand Down Expand Up @@ -67,12 +68,6 @@ void DebugMenuManager::tick()
{
if (recording_states)
{
if (backward_states.size() > MAX_BACKWARDS_STATES_SAVED)
{
delete backward_states.front();
backward_states.pop_front();
}

std::stringstream * state = new std::stringstream();
psx->save_state(*state);
backward_states.push_back(state);
Expand Down Expand Up @@ -108,11 +103,19 @@ void DebugMenuManager::draw_main_menu()

if (ImGui::BeginMenu("Options"))
{
ImGui::InputInt("Number of backward steps to record", &max_saved_states);

if (max_saved_states < 0)
{
max_saved_states = 0;
}

ImGui::Checkbox("Pause on enter/exit interrupt", &pause_on_enter_exit_exception);
ImGui::Checkbox("Pause on access peripheral", &pause_on_access_perhipheral);
ImGui::Checkbox("Ignore GPU Access", &ignore_pause_on_access_gpu);
ImGui::Checkbox("Ignore SPU Access", &ignore_pause_on_access_spu);
ImGui::Checkbox("Ignore CDROM Access", &ignore_pause_on_access_cdrom);
ImGui::Checkbox("Ignore Interrupt Control Access", &ignore_pause_on_interrupt_control);

for (auto& iter : menus)
{
Expand Down
3 changes: 2 additions & 1 deletion DebugMenuManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ class DebugMenuManager
bool ignore_pause_on_access_gpu = true;
bool ignore_pause_on_access_spu = true;
bool ignore_pause_on_access_cdrom = true;
bool ignore_pause_on_interrupt_control = true;

static const int MAX_BACKWARDS_STATES_SAVED = 100;
int max_saved_states = 100;

private:
std::vector <std::shared_ptr<DebugMenu>> menus;
Expand Down
4 changes: 4 additions & 0 deletions RegisterFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ unsigned int RegisterFile::get_register(unsigned int index, bool ignore_load_del

void RegisterFile::set_register(unsigned int index, unsigned int value, bool load_delay)
{
// debug use
register_just_changed = true;
index_of_register_changed = index;

if (index != 0)
{
if (load_delay)
Expand Down
3 changes: 3 additions & 0 deletions RegisterFile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ class RegisterFile
{
return &stage_3_registers[index];
}
bool register_just_changed = false;
int index_of_register_changed = 0;
bool break_on_change[32] = { false };

private:
unsigned int stage_1_registers[32] = { 0 };
Expand Down
2 changes: 2 additions & 0 deletions SystemControlCoprocessor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class SystemControlCoprocessor : public Cop, public Bus::BusDevice {
virtual bool trigger_pending_interrupts(SystemControlCoprocessor* system_control_processor, unsigned int & excode) = 0;
};

virtual bool is_peripheral() final { return true; }

virtual bus_device_type get_bus_device_type() final { return bus_device_type::INTERRUPT_CONTROL; }

virtual bool is_address_for_device(unsigned int address) final;
Expand Down
21 changes: 20 additions & 1 deletion main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,17 @@ int main(int num_args, char ** args )
// allow debug menu to pause on address access
bool exception_pause_request = (debug_menu->pause_on_enter_exit_exception && psx->cpu->currently_entering_exiting_exeception);
bool device_pause_request = (debug_menu->pause_on_access_perhipheral && psx->bus->currently_accessing_peripheral);

bool register_pause_request = false;
if (psx->cpu->register_file.register_just_changed)
{
int idx = psx->cpu->register_file.index_of_register_changed;
if (psx->cpu->register_file.break_on_change[idx])
{
register_pause_request = true;
psx->cpu->register_file.register_just_changed = false;
}
}

// cancel pause request if the device is being ignored,
// we don't want it stopping on every device access, it would take forever to get anywhere
Expand Down Expand Up @@ -212,6 +223,14 @@ int main(int num_args, char ** args )
}
} break;

case Bus::BusDevice::bus_device_type::INTERRUPT_CONTROL:
{
if (debug_menu->ignore_pause_on_interrupt_control)
{
device_pause_request = false;
}
} break;

default:
{
// do nothing
Expand All @@ -220,7 +239,7 @@ int main(int num_args, char ** args )
}

psx->bus->currently_accessing_peripheral = false;
if (psx->bus->request_pause || exception_pause_request || device_pause_request)
if (psx->bus->request_pause || exception_pause_request || device_pause_request || register_pause_request)
{
debug_menu->paused_requested = true;
psx->bus->request_pause = false;
Expand Down

0 comments on commit 80ef2f7

Please sign in to comment.