Skip to content

Commit

Permalink
Now showing total number of CPU cycles executed
Browse files Browse the repository at this point in the history
  • Loading branch information
sunipkm committed Feb 18, 2021
1 parent e7fca31 commit bbf1036
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ cpu_6502 *cpu; // our cpu!
volatile bool cpu_running = false;
volatile bool cpu_stepping = true;
volatile unsigned long long cpu_time = 17000; // 17000 us
uint64_t total_cycles = 0;

volatile int done = 0;

Expand Down Expand Up @@ -262,7 +263,7 @@ void CPURun()
static float usr_font_scale = 1.0f;
ImGui::SetWindowFontScale(font_scale * usr_font_scale);
float win_sz_x = (5 + 8 * 2) * font_scale * usr_font_scale * FONT_SZ;
float win_sz_y = 21 * font_scale * usr_font_scale * (FONT_SZ + 6 / font_scale / usr_font_scale);
float win_sz_y = 22 * font_scale * usr_font_scale * (FONT_SZ + 6 / font_scale / usr_font_scale);
ImGui::SetWindowSize(ImVec2(win_sz_x, win_sz_y));
float __usr_font_scale = usr_font_scale;
// ImGui::PushItemWidth(15 * font_scale * usr_font_scale * FONT_SZ);
Expand Down Expand Up @@ -290,6 +291,7 @@ void CPURun()
cpu_time = num * 1000;
}
ImGui::PopStyleColor();
ImGui::Text("Total Cycles: %llu", total_cycles);
ImGui::PushStyleColor(0, IMYLW);
ImGui::Separator();
ImGui::PopStyleColor();
Expand All @@ -298,6 +300,7 @@ void CPURun()
{
cpu_running = false;
cpu_stepping = true;
total_cycles = 0;
cpu_reset(cpu);
}
ImGui::SameLine();
Expand Down Expand Up @@ -429,6 +432,7 @@ void *CPUThread(void *id)
cpu_exec(cpu);
if (cpu_stepping)
cpu_running = false;
total_cycles++;
}
usleep(cpu_time); // 60 Hz
}
Expand All @@ -446,7 +450,7 @@ void CPURegisters(float font_scale)
ImGui::SameLine();
ImGui::Text("\t");
ImGui::SameLine();

ImGui::Text("Cycle: ");
ImGui::SameLine();
ImGui::PushFont(HexWinFont);
Expand Down
2 changes: 1 addition & 1 deletion mos6502

0 comments on commit bbf1036

Please sign in to comment.