Use std::bind() based callbacks.
This commit is contained in:
parent
03e58dac35
commit
c313a9c8bb
|
@ -144,8 +144,8 @@ private:
|
|||
int auto_inc;
|
||||
};
|
||||
|
||||
|
||||
class AwacsScreamer : public AwacsBase, public DMACallback {
|
||||
/** AWACs Screamer sound codec. */
|
||||
class AwacsScreamer : public AwacsBase {
|
||||
public:
|
||||
AwacsScreamer();
|
||||
~AwacsScreamer();
|
||||
|
@ -153,7 +153,6 @@ public:
|
|||
uint32_t snd_ctrl_read(uint32_t offset, int size);
|
||||
void snd_ctrl_write(uint32_t offset, uint32_t value, int size);
|
||||
|
||||
/* DMACallback methods */
|
||||
void dma_start();
|
||||
void dma_end();
|
||||
|
||||
|
|
|
@ -29,6 +29,12 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|||
#include <cstring>
|
||||
#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) {
|
||||
/* load DMACmd from physical memory */
|
||||
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->dma_cb->dma_start();
|
||||
this->start_cb();
|
||||
}
|
||||
|
||||
void DMAChannel::resume() {
|
||||
|
@ -259,5 +265,5 @@ void DMAChannel::abort() {
|
|||
|
||||
void DMAChannel::pause() {
|
||||
LOG_F(INFO, "Pausing DMA channel");
|
||||
this->dma_cb->dma_end();
|
||||
this->stop_cb();
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|||
|
||||
#include "dmacore.h"
|
||||
#include <cinttypes>
|
||||
#include <functional>
|
||||
|
||||
/** DBDMA Channel registers offsets */
|
||||
enum DMAReg : uint32_t {
|
||||
|
@ -60,21 +61,14 @@ typedef struct DMACmd {
|
|||
uint16_t xfer_stat;
|
||||
} DMACmd;
|
||||
|
||||
class DMACallback {
|
||||
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;
|
||||
};
|
||||
typedef std::function<void(void)> DbdmaCallback;
|
||||
|
||||
class DMAChannel : public DmaOutChannel {
|
||||
public:
|
||||
DMAChannel(DMACallback* cb) {
|
||||
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);
|
||||
void reg_write(uint32_t offset, uint32_t value, int size);
|
||||
|
||||
|
@ -91,7 +85,9 @@ protected:
|
|||
void pause(void);
|
||||
|
||||
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;
|
||||
uint32_t cmd_ptr = 0;
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(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 "viacuda.h"
|
||||
#include <cinttypes>
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
#include <loguru.hpp>
|
||||
#include <cpu/ppc/ppcemu.h>
|
||||
|
||||
/** Heathrow Mac I/O device emulation.
|
||||
|
||||
Author: Max Poliakovski 2019
|
||||
Author: Max Poliakovski
|
||||
*/
|
||||
|
||||
using namespace std;
|
||||
|
@ -42,9 +43,14 @@ HeathrowIC::HeathrowIC() : PCIDevice("mac-io/heathrow") {
|
|||
this->viacuda = new ViaCuda();
|
||||
gMachineObj->add_subdevice("ViaCuda", this->viacuda);
|
||||
|
||||
// initialize sound chip and its DMA output channel, then wire them together
|
||||
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->snd_out_dma->set_callbacks(
|
||||
std::bind(&AwacsScreamer::dma_start, this->screamer),
|
||||
std::bind(&AwacsScreamer::dma_end, this->screamer)
|
||||
);
|
||||
|
||||
this->mesh = new MESHController(HeathrowMESHID);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue