Use std::bind() based callbacks.

This commit is contained in:
Maxim Poliakovski 2021-10-05 00:26:43 +02:00
parent 03e58dac35
commit c313a9c8bb
4 changed files with 26 additions and 19 deletions

View File

@ -144,8 +144,8 @@ private:
int auto_inc; int auto_inc;
}; };
/** AWACs Screamer sound codec. */
class AwacsScreamer : public AwacsBase, public DMACallback { class AwacsScreamer : public AwacsBase {
public: public:
AwacsScreamer(); AwacsScreamer();
~AwacsScreamer(); ~AwacsScreamer();
@ -153,7 +153,6 @@ public:
uint32_t snd_ctrl_read(uint32_t offset, int size); uint32_t snd_ctrl_read(uint32_t offset, int size);
void snd_ctrl_write(uint32_t offset, uint32_t value, int size); void snd_ctrl_write(uint32_t offset, uint32_t value, int size);
/* DMACallback methods */
void dma_start(); void dma_start();
void dma_end(); void dma_end();

View File

@ -29,6 +29,12 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <cstring> #include <cstring>
#include <loguru.hpp> #include <loguru.hpp>
void DMAChannel::set_callbacks(DbdmaCallback start_cb, DbdmaCallback stop_cb)
{
this->start_cb = start_cb;
this->stop_cb = stop_cb;
}
void DMAChannel::get_next_cmd(uint32_t cmd_addr, DMACmd* p_cmd) { void DMAChannel::get_next_cmd(uint32_t cmd_addr, DMACmd* p_cmd) {
/* load DMACmd from physical memory */ /* load DMACmd from physical memory */
memcpy((uint8_t*)p_cmd, mmu_get_dma_mem(cmd_addr, 16), 16); memcpy((uint8_t*)p_cmd, mmu_get_dma_mem(cmd_addr, 16), 16);
@ -241,7 +247,7 @@ void DMAChannel::start()
this->queue_len = 0; this->queue_len = 0;
this->dma_cb->dma_start(); this->start_cb();
} }
void DMAChannel::resume() { void DMAChannel::resume() {
@ -259,5 +265,5 @@ void DMAChannel::abort() {
void DMAChannel::pause() { void DMAChannel::pause() {
LOG_F(INFO, "Pausing DMA channel"); LOG_F(INFO, "Pausing DMA channel");
this->dma_cb->dma_end(); this->stop_cb();
} }

View File

@ -31,6 +31,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include "dmacore.h" #include "dmacore.h"
#include <cinttypes> #include <cinttypes>
#include <functional>
/** DBDMA Channel registers offsets */ /** DBDMA Channel registers offsets */
enum DMAReg : uint32_t { enum DMAReg : uint32_t {
@ -60,21 +61,14 @@ typedef struct DMACmd {
uint16_t xfer_stat; uint16_t xfer_stat;
} DMACmd; } DMACmd;
class DMACallback { typedef std::function<void(void)> DbdmaCallback;
public:
virtual void dma_start(void) = 0;
virtual void dma_end(void) = 0;
//virtual void dma_push(uint8_t *buf, int size) = 0;
//virtual void dma_pull(uint8_t *buf, int size) = 0;
};
class DMAChannel : public DmaOutChannel { class DMAChannel : public DmaOutChannel {
public: public:
DMAChannel(DMACallback* cb) { DMAChannel() = default;
this->dma_cb = cb;
};
~DMAChannel() = default; ~DMAChannel() = default;
void set_callbacks(DbdmaCallback start_cb, DbdmaCallback stop_cb);
uint32_t reg_read(uint32_t offset, int size); uint32_t reg_read(uint32_t offset, int size);
void reg_write(uint32_t offset, uint32_t value, int size); void reg_write(uint32_t offset, uint32_t value, int size);
@ -91,7 +85,9 @@ protected:
void pause(void); void pause(void);
private: private:
DMACallback* dma_cb = 0; std::function<void(void)> start_cb; // DMA channel start callback
std::function<void(void)> stop_cb; // DMA channel stop callback
uint16_t ch_stat = 0; uint16_t ch_stat = 0;
uint32_t cmd_ptr = 0; uint32_t cmd_ptr = 0;

View File

@ -1,6 +1,6 @@
/* /*
DingusPPC - The Experimental PowerPC Macintosh emulator DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-20 divingkatae and maximum Copyright (C) 2018-21 divingkatae and maximum
(theweirdo) spatium (theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info) (Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@ -25,13 +25,14 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include "macio.h" #include "macio.h"
#include "viacuda.h" #include "viacuda.h"
#include <cinttypes> #include <cinttypes>
#include <functional>
#include <iostream> #include <iostream>
#include <loguru.hpp> #include <loguru.hpp>
#include <cpu/ppc/ppcemu.h> #include <cpu/ppc/ppcemu.h>
/** Heathrow Mac I/O device emulation. /** Heathrow Mac I/O device emulation.
Author: Max Poliakovski 2019 Author: Max Poliakovski
*/ */
using namespace std; using namespace std;
@ -42,9 +43,14 @@ HeathrowIC::HeathrowIC() : PCIDevice("mac-io/heathrow") {
this->viacuda = new ViaCuda(); this->viacuda = new ViaCuda();
gMachineObj->add_subdevice("ViaCuda", this->viacuda); gMachineObj->add_subdevice("ViaCuda", this->viacuda);
// initialize sound chip and its DMA output channel, then wire them together
this->screamer = new AwacsScreamer(); this->screamer = new AwacsScreamer();
this->snd_out_dma = new DMAChannel(this->screamer); this->snd_out_dma = new DMAChannel();
this->screamer->set_dma_out(this->snd_out_dma); this->screamer->set_dma_out(this->snd_out_dma);
this->snd_out_dma->set_callbacks(
std::bind(&AwacsScreamer::dma_start, this->screamer),
std::bind(&AwacsScreamer::dma_end, this->screamer)
);
this->mesh = new MESHController(HeathrowMESHID); this->mesh = new MESHController(HeathrowMESHID);
} }