awacs: Rewrite

This commit is contained in:
Olivier Galibert 2021-03-21 14:06:07 +01:00
parent f2fa9bd3b1
commit 38bfe838e2
3 changed files with 315 additions and 87 deletions

View File

@ -16,6 +16,8 @@
// device type definition
DEFINE_DEVICE_TYPE(AWACS, awacs_device, "awacs", "AWACS")
const u8 awacs_device::divider[4] = { 16, 12, 8, 16 };
//**************************************************************************
// LIVE DEVICE
@ -28,10 +30,13 @@ DEFINE_DEVICE_TYPE(AWACS, awacs_device, "awacs", "AWACS")
awacs_device::awacs_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
: device_t(mconfig, AWACS, tag, owner, clock)
, device_sound_interface(mconfig, *this)
, m_irq_out_cb(*this)
, m_irq_in_cb(*this)
, m_output_cb(*this)
, m_input_cb(*this)
, m_input_port_cb(*this)
, m_output_port_cb(*this)
, m_stream(nullptr)
, m_play_ptr(0), m_buffer_size(0), m_buffer_num(0), m_playback_enable(false)
, m_dma_space(nullptr), m_dma_offset_0(0), m_dma_offset_1(0)
, m_timer(nullptr)
{
}
@ -42,15 +47,32 @@ awacs_device::awacs_device(const machine_config &mconfig, const char *tag, devic
void awacs_device::device_start()
{
// create the stream
m_stream = stream_alloc(0, 2, 22050);
m_stream = stream_alloc(0, 2, clock()/64/divider[0], STREAM_SYNCHRONOUS);
memset(m_regs, 0, sizeof(m_regs));
m_last_sample = attotime::zero;
m_timer = timer_alloc(0, nullptr);
m_irq_out_cb.resolve_safe();
m_irq_in_cb.resolve_safe();
save_item(NAME(m_play_ptr));
save_item(NAME(m_buffer_size));
save_item(NAME(m_playback_enable));
m_output_cb.resolve_safe(0);
m_input_cb.resolve_safe();
m_input_port_cb.resolve_safe(0);
m_output_port_cb.resolve_safe();
save_item(NAME(m_extend));
save_item(NAME(m_ext_command));
save_item(NAME(m_ext_address));
save_item(NAME(m_ext_data));
save_item(NAME(m_codec0));
save_item(NAME(m_codec1));
save_item(NAME(m_codec2));
save_item(NAME(m_ctrl0));
save_item(NAME(m_ctrl1));
save_item(NAME(m_out_irq));
save_item(NAME(m_in_irq));
save_item(NAME(m_output_buffer));
save_item(NAME(m_input_buffer));
}
@ -60,26 +82,26 @@ void awacs_device::device_start()
void awacs_device::device_reset()
{
m_stream->update();
m_extend = false;
m_ext_command = false;
m_ext_address = 0;
m_ext_data = 0;
m_codec0 = 0;
m_codec1 = 0;
m_codec2 = 0;
m_ctrl0 = 0;
m_ctrl1 = 0;
m_out_irq = 0;
m_in_irq = 0;
m_output_buffer = false;
m_input_buffer = false;
memset(m_regs, 0, sizeof(m_regs));
m_irq_out_cb(false);
m_irq_in_cb(false);
m_play_ptr = 0;
m_buffer_size = 0;
m_playback_enable = false;
m_dma_space = nullptr;
m_dma_offset_0 = m_dma_offset_1 = 0;
m_buffer_num = 0;
m_stream->set_sample_rate(clock()/64/divider[(m_ctrl0 >> 1) & 3]);
}
//-------------------------------------------------
// device_timer - called when our device timer expires
//-------------------------------------------------
void awacs_device::device_timer(emu_timer &timer, device_timer_id tid, int param, void *ptr)
{
m_stream->update();
}
//-------------------------------------------------
// sound_stream_update - handle update requests for
@ -88,49 +110,127 @@ void awacs_device::device_timer(emu_timer &timer, device_timer_id tid, int param
void awacs_device::sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs)
{
// int offset = (m_buffer_num == 0) ? m_dma_offset_0 : m_dma_offset_1;
m_last_sample = machine().time();
auto &outL = outputs[0];
auto &outR = outputs[1];
if (m_playback_enable)
{
for (int i = 0; i < outL.samples(); i++)
{
#if 0
outL.put_int(i, s16(m_dma_space->read_word(offset + m_play_ptr)), 32768);
outR.put_int(i, s16(m_dma_space->read_word(offset + m_play_ptr + 2)), 32768);
#else
outL.put_int(i, 0, 32768);
outR.put_int(i, 0, 32768);
#endif
m_play_ptr += 4;
}
// out of buffer?
if (m_play_ptr >= m_buffer_size)
{
uint8_t bufflag[2] = { 0x40, 0x80 };
m_regs[0x18] |= bufflag[m_buffer_num];
m_buffer_num ^= 1;
m_play_ptr = 0;
}
if(m_phase == 0) {
m_active = 0;
if(m_ctrl0 & 1)
m_active |= ACTIVE_OUT;
if(m_ctrl1 & 0x80)
m_active |= ACTIVE_IN;
}
if(m_active & ACTIVE_OUT) {
u32 data = m_output_cb(m_phase | (m_output_buffer ? 0x10000 : 0));
s16 left = data >> 16;
s16 right = data;
outputs[0].put_int(0, left, 32768);
outputs[1].put_int(0, right, 32768);
} else {
m_output_buffer = false;
outputs[0].put_int(0, 0, 32768);
outputs[1].put_int(0, 0, 32768);
}
if(m_active & ACTIVE_IN)
m_input_cb(m_phase | (m_input_buffer ? 0x10000 : 0), 0);
else
{
outL.fill(0);
outR.fill(0);
m_input_buffer = false;
m_phase = (m_phase + 1) & 0xfff;
if(m_phase >= m_buffer_size) {
m_phase = 0;
if(m_active & ACTIVE_OUT) {
if(m_output_buffer) {
m_output_buffer = false;
if(m_out_irq & 0x40)
m_out_irq |= 0x20;
else
m_out_irq |= 0x40;
} else {
m_output_buffer = true;
if(m_out_irq & 0x80)
m_out_irq |= 0x20;
else
m_out_irq |= 0x80;
}
}
if(m_active & ACTIVE_IN) {
if(m_input_buffer) {
m_input_buffer = false;
if(m_in_irq & 0x40)
m_in_irq |= 0x20;
else
m_in_irq |= 0x40;
} else {
m_input_buffer = true;
if(m_in_irq & 0x80)
m_in_irq |= 0x20;
else
m_in_irq |= 0x80;
}
}
update_irq();
}
}
void awacs_device::update_irq()
{
m_irq_out_cb(((m_out_irq >> 4) & m_out_irq) != 0);
m_irq_in_cb(((m_in_irq >> 4) & m_in_irq) != 0);
}
//-------------------------------------------------
// read - read from the chip's registers and internal RAM
// read - read from the chip's registers
//-------------------------------------------------
uint8_t awacs_device::read(offs_t offset)
{
return m_regs[offset];
switch(offset) {
case 0x00:
if(m_extend)
return 0x80 | (m_ext_command ? 0x40 : 0x00) | (m_ext_address >> 4);
else
return m_codec0;
case 0x01:
if(m_extend)
return ((m_ext_address & 0xf) << 4) | ((m_ext_data & 0xf00) >> 8);
else
return m_codec1;
case 0x02:
if(m_extend)
return m_ext_data & 0x0ff;
else
return m_codec2;
case 0x06: return m_input_port_cb() & 0xf;
case 0x0c: {
u64 cycles = (machine().time() - m_last_sample).as_ticks(clock())/divider[(m_ctrl0 >> 1) & 3];
if(cycles > 63)
cycles = 63;
return cycles | ((m_phase & 3) << 6);
}
case 0x0d: return m_phase >> 2;
case 0x0e: return m_phase >> 10;
case 0x10: return m_ctrl0;
case 0x11: return m_ctrl1;
case 0x14: return m_in_irq;
case 0x18: return m_out_irq;
default:
logerror("reg_r %02x\n", offset);
return 0;
}
}
//-------------------------------------------------
@ -139,8 +239,107 @@ uint8_t awacs_device::read(offs_t offset)
void awacs_device::write(offs_t offset, uint8_t data)
{
switch (offset)
{
switch (offset) {
case 0x00:
m_extend = data & 0x80;
if(m_extend) {
m_ext_command = data & 0x40;
m_ext_address = (m_ext_address & 0xf) | ((data & 0x1f) << 4);
logerror("extended command=%d adr=%03x data=%03x\n", m_ext_command, m_ext_address, m_ext_data);
} else {
m_codec0 = data & 0x7f;
logerror("codec mute=%s iml=%x imr=%x gain_l=%x\n",
m_codec0 & 0x40 ? "on" : "off",
m_codec0 & 0x20 ? "on" : "off",
m_codec0 & 0x10 ? "on" : "off",
m_codec0 & 0xf);
}
break;
case 0x01:
if(m_extend) {
m_ext_address = (m_ext_address & 0x3f0) | ((data & 0xf0) >> 4);
m_ext_data = (m_ext_data & 0x0ff) | ((data & 0xf) << 8);
logerror("extended command=%d adr=%03x data=%03x\n", m_ext_command, m_ext_address, m_ext_data);
} else {
m_codec1 = data;
logerror("codec gain_r=%x att_l=%x\n",
(m_codec1 & 0xf0) >> 4,
m_codec1 & 0xf);
}
break;
case 0x02:
if(m_extend) {
m_ext_data = (m_ext_data & 0xf00) | data;
logerror("extended command=%d adr=%03x data=%03x\n", m_ext_command, m_ext_address, m_ext_data);
} else {
m_codec2 = data;
m_output_port_cb(data & 0xf);
logerror("codec att_r=%x output_port=%x\n",
(m_codec2 & 0xf0) >> 4,
m_codec2 & 0xf);
}
break;
case 0x08:
m_buffer_size = (m_buffer_size & 0xfc) | ((data & 7) << 8);
logerror("buffer size %03x\n", m_buffer_size);
break;
case 0x09:
m_buffer_size = (m_buffer_size & 0x700) | (data & 0xfc);
logerror("buffer size %03x\n", m_buffer_size);
break;
case 0x10:
m_ctrl0 = data;
m_stream->set_sample_rate(clock()/64/divider[(m_ctrl0 >> 1) & 3]);
logerror("ctr0_w %02x - play=%s rate=%d\n", m_ctrl0, m_ctrl0 & 1 ? "on" : "off", clock()/64/divider[(m_ctrl0 >> 1) & 3]);
break;
case 0x11:
m_ctrl1 = data;
logerror("ctr1_w %02x - record=%s frame_irq=%s sf_out=%x sf_in=%x\n", m_ctrl1,
m_ctrl1 & 0x80 ? "on" : "off",
m_ctrl1 & 0x40 ? "on" : "off",
(m_ctrl1 >> 2) & 0xf,
m_ctrl1 & 3);
break;
case 0x14:
m_in_irq = ((m_in_irq & 0xf0) & (~data)) | (data & 0x0f);
logerror("input irq if1=%d if0=%d cerr=%d ovr=%d ie1=%d ie0=%d oe=%d, ce=%d\n",
BIT(m_in_irq, 7),
BIT(m_in_irq, 6),
BIT(m_in_irq, 5),
BIT(m_in_irq, 4),
BIT(m_in_irq, 3),
BIT(m_in_irq, 2),
BIT(m_in_irq, 1),
BIT(m_in_irq, 0));
update_irq();
break;
case 0x18:
m_out_irq = ((m_out_irq & 0xe0) & (~data)) | (data & 0x0e);
logerror("output irq if1=%d if0=%d und=%d ie1=%d ie0=%d ue=%d\n",
BIT(m_out_irq, 7),
BIT(m_out_irq, 6),
BIT(m_out_irq, 5),
BIT(m_out_irq, 3),
BIT(m_out_irq, 2),
BIT(m_out_irq, 1));
update_irq();
break;
default:
logerror("reg_w %02x, %02x\n", offset, data);
break;
#if 0
case 0x8:
case 0x9:
m_regs[offset] = data;
@ -169,14 +368,6 @@ void awacs_device::write(offs_t offset, uint8_t data)
m_regs[offset] |= (data & 0x0f);
m_regs[offset] &= ~(data & 0xf0);
return;
#endif
}
m_regs[offset] = data;
}
void awacs_device::set_dma_base(address_space &space, int offset0, int offset1)
{
m_dma_space = &space;
m_dma_offset_0 = offset0;
m_dma_offset_1 = offset1;
}

View File

@ -25,31 +25,46 @@ public:
// construction/destruction
awacs_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
auto irq_out_cb() { return m_irq_out_cb.bind(); }
auto irq_in_cb() { return m_irq_in_cb.bind(); }
auto dma_output() { return m_output_cb.bind(); }
auto dma_input() { return m_input_cb.bind(); }
auto port_input() { return m_input_port_cb.bind(); }
auto port_output() { return m_output_port_cb.bind(); }
uint8_t read(offs_t offset);
void write(offs_t offset, uint8_t data);
void set_dma_base(address_space &space, int offset0, int offset1);
protected:
enum {
ACTIVE_OUT = 0x01,
ACTIVE_IN = 0x02
};
static const u8 divider[4];
// device-level overrides
virtual void device_start() override;
virtual void device_reset() override;
virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) override;
virtual void sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) override;
devcb_write_line m_irq_out_cb, m_irq_in_cb;
devcb_read32 m_output_cb;
devcb_write32 m_input_cb;
devcb_read8 m_input_port_cb;
devcb_write8 m_output_port_cb;
sound_stream *m_stream;
// inline data
uint8_t m_regs[0x100];
attotime m_last_sample;
u8 m_ctrl0, m_ctrl1, m_codec0, m_codec1, m_codec2, m_out_irq, m_in_irq, m_active;
u16 m_ext_address, m_ext_data, m_buffer_size, m_phase;
bool m_extend, m_ext_command, m_input_buffer, m_output_buffer;
int m_play_ptr, m_buffer_size, m_buffer_num;
bool m_playback_enable;
address_space *m_dma_space;
int m_dma_offset_0, m_dma_offset_1;
emu_timer *m_timer;
void update_irq();
};

View File

@ -21,6 +21,7 @@
constexpr auto IO_CLOCK = 31.3344_MHz_XTAL;
constexpr auto ENET_CLOCK = 20_MHz_XTAL;
constexpr auto SOUND_CLOCK = 45.1584_MHz_XTAL;
class macpdm_state : public driver_device
{
@ -199,6 +200,9 @@ private:
uint8_t dma_enet_tx_ctrl_r();
void dma_enet_tx_ctrl_w(uint8_t data);
uint32_t sound_dma_output(offs_t offset);
void sound_dma_input(offs_t offset, uint32_t value);
uint32_t screen_update(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect);
};
@ -228,8 +232,6 @@ void macpdm_state::driver_init()
// 7100 = a55a3012
// 8100 = a55a3013
m_awacs->set_dma_base(m_maincpu->space(AS_PROGRAM), 0x10000, 0x12000);
save_item(NAME(m_hmc_reg));
save_item(NAME(m_hmc_buffer));
save_item(NAME(m_hmc_bit));
@ -654,9 +656,14 @@ WRITE_LINE_MEMBER(macpdm_state::slot1_irq)
via2_irq_slot_set(0x10, state);
}
WRITE_LINE_MEMBER(macpdm_state::slot0_irq)
WRITE_LINE_MEMBER(macpdm_state::sndo_dma_irq)
{
via2_irq_slot_set(0x08, state);
// TODO
}
WRITE_LINE_MEMBER(macpdm_state::sndi_dma_irq)
{
// TODO
}
uint32_t macpdm_state::dma_badr_r()
@ -918,6 +925,17 @@ void macpdm_state::dma_enet_tx_ctrl_w(uint8_t data)
logerror("dma_enet_tx_ctrl_w %02x\n", m_dma_enet_tx_ctrl);
}
uint32_t macpdm_state::sound_dma_output(offs_t offset)
{
offs_t adr = m_dma_badr + (offset & 0x10000 ? 0x12000 : 0x10000) + 4*(offset & 0x7ff);
return m_maincpu->space().read_dword(adr);
}
void macpdm_state::sound_dma_input(offs_t offset, uint32_t value)
{
offs_t adr = m_dma_badr + (offset & 0x10000 ? 0x0e000 : 0x0c000) + 4*(offset & 0x7ff);
m_maincpu->space().write_dword(adr, value);
}
void macpdm_state::pdm_map(address_map &map)
@ -930,8 +948,6 @@ void macpdm_state::pdm_map(address_map &map)
// 50f0a000 = MACE ethernet controller
map(0x50f10000, 0x50f10000).rw(FUNC(macpdm_state::scsi_r), FUNC(macpdm_state::scsi_w)).select(0xf0);
map(0x50f10100, 0x50f10101).r(m_ncr53c94, FUNC(ncr53c94_device::dma16_r));
// 50f14000 = sound registers (AWACS)
map(0x50f14000, 0x50f1401f).rw(m_awacs, FUNC(awacs_device::read), FUNC(awacs_device::write));
map(0x50f16000, 0x50f16000).rw(FUNC(macpdm_state::fdc_r), FUNC(macpdm_state::fdc_w)).select(0x1e00);
@ -986,7 +1002,13 @@ void macpdm_state::macpdm(machine_config &config)
SPEAKER(config, "lspeaker").front_left();
SPEAKER(config, "rspeaker").front_right();
AWACS(config, m_awacs, 44100);
AWACS(config, m_awacs, SOUND_CLOCK/2);
m_awacs->irq_out_cb().set(FUNC(macpdm_state::sndo_dma_irq));
m_awacs->irq_in_cb().set(FUNC(macpdm_state::sndi_dma_irq));
m_awacs->dma_output().set(FUNC(macpdm_state::sound_dma_output));
m_awacs->dma_input().set(FUNC(macpdm_state::sound_dma_input));
m_awacs->add_route(0, "lspeaker", 1.0);
m_awacs->add_route(1, "rspeaker", 1.0);