Skip to content

Commit

Permalink
Added option for toggling sound
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtranhq committed Aug 6, 2020
1 parent aa839bf commit e2f0109
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/apu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class Apu
void write_reg(uint8_t b, uint16_t adr);
void set_speaker(Speaker *s);
void reset();
void toggle_sound(bool b);

private:
// clockfreq/samplingrate
Expand Down
1 change: 1 addition & 0 deletions include/system.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class System
bool is_running();
void set_throttle(double factor);
void set_debug(bool b);
void toggle_sound(bool b);

// system setup
bool load_cartridge(const std::string &path);
Expand Down
1 change: 1 addition & 0 deletions platforms/qt/include/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ private slots:
void toggleAntiAlias(bool);
void toggleForceDmg(bool);
void openCustomPaletteWindow();
void toggleSound(bool);

void update_display();

Expand Down
11 changes: 11 additions & 0 deletions platforms/qt/src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ void MainWindow::openCustomPaletteWindow()

}

void MainWindow::toggleSound(bool b)
{
system_.toggle_sound(b);
}

void MainWindow::update_display()
{
QImage img {renderer_->image()};
Expand Down Expand Up @@ -156,6 +161,12 @@ void MainWindow::createActions()
connect(forceDmgAct, SIGNAL(toggled(bool)), this, SLOT(toggleForceDmg(bool)));
optionsMenu->addAction(forceDmgAct);

QAction *enableSoundAct = new QAction(tr("Enable Sound"), this);
enableSoundAct->setCheckable(true);
enableSoundAct->setChecked(true);
connect(enableSoundAct, SIGNAL(toggled(bool)), this, SLOT(toggleSound(bool)));
optionsMenu->addAction(enableSoundAct);


QMenu *toolsMenu = menuBar()->addMenu(tr("&Tools"));
toolsMenu->addAction(tr("Disassemble"), this, &MainWindow::showDisassembler);
Expand Down
5 changes: 5 additions & 0 deletions src/apu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,8 @@ void Apu::set_speaker(Speaker *s)
speaker_ = s;
}

void Apu::toggle_sound(bool b)
{
speaker_->toggle(b);
}

5 changes: 5 additions & 0 deletions src/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,11 @@ void System::set_debug_callback(std::function<void()> fn)
debug_callback_ = std::move(fn);
}

void System::toggle_sound(bool b)
{
apu_.toggle_sound(b);
}

std::unordered_map<std::string, Memory_range> System::dump_memory() const
{
return memory_.dump();
Expand Down

0 comments on commit e2f0109

Please sign in to comment.