Play audio in emulator class, update class references from the SNES

This commit is contained in:
scawful
2024-04-24 10:08:05 -04:00
parent f3cf9ac555
commit bd6fc2e8f1
4 changed files with 34 additions and 64 deletions

View File

@@ -59,8 +59,8 @@ void Emulator::Run() {
return;
}
snes_.Init(*rom());
wanted_frames_ = 1.0 / (snes_.Memory()->pal_timing() ? 50.0 : 60.0);
wanted_samples_ = 48000 / (snes_.Memory()->pal_timing() ? 50 : 60);
wanted_frames_ = 1.0 / (snes_.Memory().pal_timing() ? 50.0 : 60.0);
wanted_samples_ = 48000 / (snes_.Memory().pal_timing() ? 50 : 60);
loaded = true;
countFreq = SDL_GetPerformanceFrequency();
@@ -84,6 +84,12 @@ void Emulator::Run() {
if (loaded) {
snes_.RunFrame();
snes_.SetSamples(audio_buffer_, wanted_samples_);
if (SDL_GetQueuedAudioSize(audio_device_) <= wanted_samples_ * 4 * 6) {
SDL_QueueAudio(audio_device_, audio_buffer_, wanted_samples_ * 4);
}
void* ppu_pixels_;
int ppu_pitch_;
if (SDL_LockTexture(ppu_texture_, NULL, &ppu_pixels_, &ppu_pitch_) !=
@@ -153,7 +159,7 @@ void Emulator::RenderNavBar() {
if (ImGui::Button(ICON_MD_SKIP_NEXT)) {
// Step through Code logic
snes_.cpu()->RunOpcode();
snes_.cpu().RunOpcode();
}
if (ImGui::IsItemHovered()) {
ImGui::SetTooltip("Step Through Code");
@@ -210,7 +216,7 @@ void Emulator::RenderNavBar() {
}
SameLine();
ImGui::Checkbox("Logging", snes_.cpu()->mutable_log_instructions());
ImGui::Checkbox("Logging", snes_.cpu().mutable_log_instructions());
static bool show_memory_viewer = false;
@@ -257,28 +263,28 @@ void Emulator::RenderBreakpointList() {
if (ImGui::InputText("##BreakpointInput", breakpoint_input, 10,
ImGuiInputTextFlags_EnterReturnsTrue)) {
int breakpoint = std::stoi(breakpoint_input, nullptr, 16);
snes_.cpu()->SetBreakpoint(breakpoint);
snes_.cpu().SetBreakpoint(breakpoint);
memset(breakpoint_input, 0, sizeof(breakpoint_input));
}
SameLine();
if (ImGui::Button("Add")) {
int breakpoint = std::stoi(breakpoint_input, nullptr, 16);
snes_.cpu()->SetBreakpoint(breakpoint);
snes_.cpu().SetBreakpoint(breakpoint);
memset(breakpoint_input, 0, sizeof(breakpoint_input));
}
SameLine();
if (ImGui::Button("Clear")) {
snes_.cpu()->ClearBreakpoints();
snes_.cpu().ClearBreakpoints();
}
Separator();
auto breakpoints = snes_.cpu()->GetBreakpoints();
auto breakpoints = snes_.cpu().GetBreakpoints();
if (!breakpoints.empty()) {
Text("Breakpoints:");
ImGui::BeginChild("BreakpointsList", ImVec2(0, 100), true);
for (auto breakpoint : breakpoints) {
if (ImGui::Selectable(absl::StrFormat("0x%04X", breakpoint).c_str())) {
// Jump to breakpoint
// snes_.cpu()->JumpToBreakpoint(breakpoint);
// snes_.cpu().JumpToBreakpoint(breakpoint);
}
}
ImGui::EndChild();
@@ -287,8 +293,8 @@ void Emulator::RenderBreakpointList() {
gui::InputHexByte("PB", &manual_pb_, 50.f);
gui::InputHexWord("PC", &manual_pc_, 75.f);
if (ImGui::Button("Set Current Address")) {
snes_.cpu()->PC = manual_pc_;
snes_.cpu()->PB = manual_pb_;
snes_.cpu().PC = manual_pc_;
snes_.cpu().PB = manual_pb_;
}
}
@@ -342,8 +348,8 @@ void Emulator::RenderMemoryViewer() {
}
TableNextColumn();
mem_edit.DrawContents((void*)snes_.Memory()->rom_.data(),
snes_.Memory()->rom_.size());
mem_edit.DrawContents((void*)snes_.Memory().rom_.data(),
snes_.Memory().rom_.size());
ImGui::EndTable();
}