2020-03-15 16:24:40 +00:00
|
|
|
/*
|
|
|
|
DingusPPC - The Experimental PowerPC Macintosh emulator
|
|
|
|
Copyright (C) 2018-20 divingkatae and maximum
|
|
|
|
(theweirdo) spatium
|
|
|
|
|
|
|
|
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** AWAC sound devices family definitions.
|
|
|
|
|
|
|
|
Audio Waveform Aplifier and Converter (AWAC) is a family of custom audio
|
|
|
|
chips used in Power Macintosh.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef AWAC_H
|
|
|
|
#define AWAC_H
|
|
|
|
|
2020-03-19 14:09:24 +00:00
|
|
|
#include "dbdma.h"
|
2020-05-12 18:55:45 +00:00
|
|
|
#include "i2c.h"
|
2020-05-15 00:36:40 +00:00
|
|
|
#include "soundserver.h"
|
2020-05-12 18:55:45 +00:00
|
|
|
#include <cinttypes>
|
2020-03-23 03:15:12 +00:00
|
|
|
#include <thirdparty/SDL2/include/SDL.h>
|
2020-03-15 16:24:40 +00:00
|
|
|
|
|
|
|
/** AWAC registers offsets. */
|
|
|
|
enum {
|
|
|
|
AWAC_SOUND_CTRL_REG = 0x00,
|
|
|
|
AWAC_CODEC_CTRL_REG = 0x10,
|
|
|
|
AWAC_CODEC_STATUS_REG = 0x20,
|
|
|
|
};
|
|
|
|
|
|
|
|
/** AWAC manufacturer and revision. */
|
|
|
|
#define AWAC_MAKER_CRYSTAL 1
|
2020-05-12 18:55:45 +00:00
|
|
|
#define AWAC_REV_SCREAMER 3
|
2020-03-15 16:24:40 +00:00
|
|
|
|
|
|
|
/** Apple source calls this kValidData but doesn't explain
|
|
|
|
what it actually means. It seems like it's used to check
|
|
|
|
if the sound codec is available.
|
|
|
|
*/
|
|
|
|
#define AWAC_AVAILABLE 0x40
|
|
|
|
|
|
|
|
|
|
|
|
/** Audio processor chip (TDA7433) emulation. */
|
|
|
|
class AudioProcessor : public I2CDevice {
|
|
|
|
public:
|
|
|
|
AudioProcessor() = default;
|
|
|
|
~AudioProcessor() = default;
|
|
|
|
|
2020-05-12 18:55:45 +00:00
|
|
|
void start_transaction() {
|
|
|
|
this->pos = 0;
|
|
|
|
};
|
2020-03-15 16:24:40 +00:00
|
|
|
|
|
|
|
bool send_subaddress(uint8_t sub_addr) {
|
|
|
|
if ((sub_addr & 0xF) > 6)
|
|
|
|
return false; /* invalid subaddress -> no acknowledge */
|
|
|
|
|
|
|
|
this->sub_addr = sub_addr & 0xF;
|
|
|
|
this->auto_inc = !!(sub_addr & 0x10);
|
2020-05-12 18:55:45 +00:00
|
|
|
LOG_F(INFO, "TDA7433 subaddress = 0x%X, auto increment = %d", this->sub_addr, this->auto_inc);
|
2020-03-15 16:24:40 +00:00
|
|
|
this->pos++;
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
bool send_byte(uint8_t data) {
|
|
|
|
if (!this->pos) {
|
|
|
|
return send_subaddress(data);
|
|
|
|
} else if (this->sub_addr <= 6) {
|
|
|
|
LOG_F(INFO, "TDA7433 byte 0x%X received", data);
|
2020-05-12 18:55:45 +00:00
|
|
|
this->regs[this->sub_addr] = data;
|
2020-03-15 16:24:40 +00:00
|
|
|
if (this->auto_inc) {
|
|
|
|
this->sub_addr++;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false; /* invalid sub_addr -> no acknowledge */
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-05-12 18:55:45 +00:00
|
|
|
bool receive_byte(uint8_t* p_data) {
|
2020-03-15 16:24:40 +00:00
|
|
|
*p_data = this->regs[this->sub_addr];
|
|
|
|
LOG_F(INFO, "TDA7433 byte 0x%X sent", *p_data);
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
2020-05-12 18:55:45 +00:00
|
|
|
uint8_t regs[7]; /* control registers, see TDA7433 datasheet */
|
2020-03-15 16:24:40 +00:00
|
|
|
uint8_t sub_addr;
|
2020-05-12 18:55:45 +00:00
|
|
|
int pos;
|
|
|
|
int auto_inc;
|
2020-03-15 16:24:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2020-03-19 14:09:24 +00:00
|
|
|
class AWACDevice : public DMACallback {
|
2020-03-15 16:24:40 +00:00
|
|
|
public:
|
|
|
|
AWACDevice();
|
|
|
|
~AWACDevice();
|
|
|
|
|
2020-05-12 18:55:45 +00:00
|
|
|
void set_dma_out(DMAChannel* dma_out_ch);
|
2020-03-26 01:07:12 +00:00
|
|
|
|
2020-03-15 16:24:40 +00:00
|
|
|
uint32_t snd_ctrl_read(uint32_t offset, int size);
|
2020-05-12 18:55:45 +00:00
|
|
|
void snd_ctrl_write(uint32_t offset, uint32_t value, int size);
|
2020-03-15 16:24:40 +00:00
|
|
|
|
2020-03-19 14:09:24 +00:00
|
|
|
/* DMACallback methods */
|
|
|
|
void dma_start();
|
|
|
|
void dma_end();
|
|
|
|
|
|
|
|
protected:
|
2020-05-08 20:32:29 +00:00
|
|
|
void open_stream(int sample_rate);
|
2020-03-19 14:09:24 +00:00
|
|
|
|
2020-03-15 16:24:40 +00:00
|
|
|
private:
|
2020-05-18 00:51:56 +00:00
|
|
|
static long sound_out_callback(cubeb_stream* stream, void* user_data,
|
|
|
|
void const* input_buffer, void* output_buffer,
|
|
|
|
long req_frames);
|
|
|
|
|
2020-03-15 16:24:40 +00:00
|
|
|
uint32_t snd_ctrl_reg = {0};
|
|
|
|
uint16_t control_regs[8] = {0}; /* control registers, each 12-bits wide */
|
2020-05-12 18:55:45 +00:00
|
|
|
uint8_t is_busy = 0;
|
|
|
|
AudioProcessor* audio_proc;
|
2020-03-19 14:09:24 +00:00
|
|
|
|
2020-05-15 00:36:40 +00:00
|
|
|
SoundServer *snd_server;
|
2020-03-19 14:09:24 +00:00
|
|
|
|
2020-05-08 20:32:29 +00:00
|
|
|
bool out_stream_ready;
|
|
|
|
int out_sample_rate;
|
2020-03-26 01:07:12 +00:00
|
|
|
|
|
|
|
DMAChannel *dma_out_ch;
|
2020-03-15 16:24:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* AWAC_H */
|