Skip to content

Commit

Permalink
added interrupt I_STAT and I_MASK plots
Browse files Browse the repository at this point in the history
  • Loading branch information
timlump committed Jun 7, 2020
1 parent af8db0a commit 84bfcbd
Show file tree
Hide file tree
Showing 7 changed files with 3,888 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ set(imgui_files
imgui/imstb_rectpack.h
imgui/imstb_textedit.h
imgui/imstb_truetype.h
imgui/implot.h
imgui/implot.cpp
)

set(glad_files
Expand All @@ -52,6 +54,8 @@ set(debug_files
GpuMenu.cpp
CdromMenu.hpp
CdromMenu.cpp
InterruptMenu.hpp
InterruptMenu.cpp
)


Expand Down
7 changes: 7 additions & 0 deletions DebugMenuManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "CpuMenu.hpp"
#include "GpuMenu.hpp"
#include "CdromMenu.hpp"
#include "InterruptMenu.hpp"

#include <iostream>
#include <sstream>
Expand All @@ -31,6 +32,7 @@ void DebugMenuManager::init(GLFWwindow* window, std::shared_ptr<Psx> _psx)
menus.push_back(std::make_shared<CpuMenu>(psx));
menus.push_back(std::make_shared<GpuMenu>(psx));
menus.push_back(std::make_shared<CdromMenu>(psx));
menus.push_back(std::make_shared<InterruptMenu>(psx));
}

void DebugMenuManager::uninit()
Expand Down Expand Up @@ -78,6 +80,11 @@ void DebugMenuManager::tick()
psx->save_state(*state);
backward_states.push_back(state);
}

for (auto& iter : menus)
{
iter->tick();
}
}

void DebugMenuManager::draw_main_menu()
Expand Down
100 changes: 100 additions & 0 deletions InterruptMenu.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#include "InterruptMenu.hpp"
#include "imgui.h"
#include "imgui_impl_glfw.h"
#include "imgui_impl_opengl3.h"
#include "implot.h"
#include "SystemControlCoprocessor.hpp"
#include "Psx.hpp"
#include "Cpu.hpp"

InterruptMenu::InterruptMenu(std::shared_ptr<Psx> _psx) : DebugMenu(_psx)
{

}

void InterruptMenu::draw_in_category(menubar_category category)
{
if (category == menubar_category::VIEW)
{
ImGui::Checkbox("Show Interrupts", &is_visible);
}
}

void InterruptMenu::draw_menu()
{
if (is_visible == false)
{
return;
}

ImGui::Begin("Interrupt");
ImGui::Text("I_STAT");
for (int idx = 0; idx < NUM_IRQS; idx++)
{
ImGui::PlotLines(std::to_string(idx).c_str(),
[](void *data, int idx) {
std::deque<float> * values = static_cast<std::deque<float>*>(data);
if (static_cast<unsigned int>(idx) < values->size())
{
return (*values)[idx];
}
else
{
return 0.f;
}
},
reinterpret_cast<void*>(&i_stat_irqs[idx]), MAX_VALUE_COUNT, 0, 0, 0.f, 1.f);
}

ImGui::Text("I_MASK");
for (int idx = 0; idx < NUM_IRQS; idx++)
{
ImGui::PlotLines(std::to_string(idx).c_str(),
[](void *data, int idx) {
std::deque<float> * values = static_cast<std::deque<float>*>(data);
if (static_cast<unsigned int>(idx) < values->size())
{
return (*values)[idx];
}
else
{
return 0.f;
}
},
reinterpret_cast<void*>(&i_mask_irqs[idx]), MAX_VALUE_COUNT, 0, 0, 0.f, 1.f);
}
ImGui::End();
}

void InterruptMenu::tick()
{
if (is_visible == false)
{
return;
}

system_control::interrupt_register i_stat = psx->cpu->cop0->interrupt_status_register;
system_control::interrupt_register i_mask = psx->cpu->cop0->interrupt_mask_register;

unsigned int i_stat_bits = i_stat.IRQ_BITS;
unsigned int i_mask_bits = i_mask.IRQ_BITS;
for (int idx = 0; idx < NUM_IRQS; idx++)
{
bool i_stat_for_idx = i_stat_bits & 0x1;
bool i_mask_for_idx = i_mask_bits & 0x1;

i_stat_irqs[idx].push_back(i_stat_for_idx ? 1.f : 0.f);
i_mask_irqs[idx].push_back(i_mask_for_idx ? 1.f : 0.f);

if (i_stat_irqs[idx].size() > MAX_VALUE_COUNT)
{
// can pop both as they will have the exact same size
i_stat_irqs[idx].pop_front();
i_mask_irqs[idx].pop_front();
}

// shift to next irq bit to check
i_stat_bits >>= 1;
i_mask_bits >>= 1;
}
}
23 changes: 23 additions & 0 deletions InterruptMenu.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#pragma once
#include "DebugMenuManager.hpp"
#include <deque>

class InterruptMenu : public DebugMenu
{
public:
InterruptMenu(std::shared_ptr<Psx> _psx);

virtual void draw_in_category(menubar_category category) final;
virtual void draw_menu() final;
virtual void tick() final;

private:
bool is_visible = false;

static const int MAX_VALUE_COUNT = 1000;
static const int NUM_IRQS = 11;

std::deque<float> i_stat_irqs[NUM_IRQS];
std::deque<float> i_mask_irqs[NUM_IRQS];

};
Loading

0 comments on commit 84bfcbd

Please sign in to comment.