From 54cb21bea7eedbebda5464259bbf14131cd44c56 Mon Sep 17 00:00:00 2001 From: "R. Belmont" Date: Sat, 28 Jun 2014 01:44:50 +0000 Subject: [PATCH] (MESS) Apple II: Support for the Mountain Computer Music System. [R. Belmont] --- .gitattributes | 2 + src/emu/bus/a2bus/a2bus.h | 4 + src/emu/bus/a2bus/a2mcms.c | 419 +++++++++++++++++++++++++++++++++++++ src/emu/bus/a2bus/a2mcms.h | 86 ++++++++ src/emu/bus/bus.mak | 1 + src/mess/drivers/apple2.c | 3 + 6 files changed, 515 insertions(+) create mode 100644 src/emu/bus/a2bus/a2mcms.c create mode 100644 src/emu/bus/a2bus/a2mcms.h diff --git a/.gitattributes b/.gitattributes index d1fa21ba191..ca120512846 100644 --- a/.gitattributes +++ b/.gitattributes @@ -434,6 +434,8 @@ src/emu/bus/a2bus/a2hsscsi.c svneol=native#text/plain src/emu/bus/a2bus/a2hsscsi.h svneol=native#text/plain src/emu/bus/a2bus/a2lang.c svneol=native#text/plain src/emu/bus/a2bus/a2lang.h svneol=native#text/plain +src/emu/bus/a2bus/a2mcms.c svneol=native#text/plain +src/emu/bus/a2bus/a2mcms.h svneol=native#text/plain src/emu/bus/a2bus/a2memexp.c svneol=native#text/plain src/emu/bus/a2bus/a2memexp.h svneol=native#text/plain src/emu/bus/a2bus/a2midi.c svneol=native#text/plain diff --git a/src/emu/bus/a2bus/a2bus.h b/src/emu/bus/a2bus/a2bus.h index d2dcdbe4362..87d3410383a 100644 --- a/src/emu/bus/a2bus/a2bus.h +++ b/src/emu/bus/a2bus/a2bus.h @@ -1,3 +1,5 @@ +// license:BSD-3-Clause +// copyright-holders:R. Belmont /*************************************************************************** a2bus.h - Apple II slot bus and card emulation @@ -75,6 +77,8 @@ class device_a2bus_card_interface; // ======================> a2bus_device class a2bus_device : public device_t { + // multi-card devices need to access m_device_list, so they get friend'ed here. + friend class a2bus_mcms2_device; public: // construction/destruction a2bus_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); diff --git a/src/emu/bus/a2bus/a2mcms.c b/src/emu/bus/a2bus/a2mcms.c new file mode 100644 index 00000000000..f7d43d9d496 --- /dev/null +++ b/src/emu/bus/a2bus/a2mcms.c @@ -0,0 +1,419 @@ +// license:BSD-3-Clause +// copyright-holders:R. Belmont +/********************************************************************* + + a2mcms.c + + Implementation of the Mountain Computer Music System. + This was sold standalone and also used as part of the alphaSyntauri + and SoundChaser systems. + +*********************************************************************/ + +#include "a2mcms.h" +#include "includes/apple2.h" + +// the actual sound device (a slot device can't currently also be a sound device so we keep this private here) +enum +{ + CTRL_IRQS = 0, + CTRL_DMA, + CTRL_MASTERVOL +}; + + +class mcms_device : public device_t, public device_sound_interface +{ +public: + // construction/destruction + mcms_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); + + DECLARE_WRITE8_MEMBER(voiceregs_w); + DECLARE_WRITE8_MEMBER(control_w); + UINT8 get_pen_rand(void) { m_stream->update(); return m_rand; } + + template static devcb_base &set_irq_cb(device_t &device, _Object wr) { return downcast(device).m_write_irq.set_callback(wr); } + devcb_write_line m_write_irq; + +protected: + // device-level overrides + virtual void device_start(); + virtual void device_reset(); + virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr); + + virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples); + +private: + sound_stream *m_stream; + address_space *m_6502space; + emu_timer *m_timer, *m_clrtimer; + bool m_enabled; + UINT8 m_vols[16]; + UINT8 m_table[16]; + UINT16 m_freq[16]; + UINT16 m_acc[16]; + UINT8 m_mastervol; + UINT8 m_rand; +}; + +const device_type MCMS = &device_creator; + +/*************************************************************************** + PARAMETERS +***************************************************************************/ + +//************************************************************************** +// GLOBAL VARIABLES +//************************************************************************** + +const device_type A2BUS_MCMS1 = &device_creator; +const device_type A2BUS_MCMS2 = &device_creator; + +#define ENGINE_TAG "engine" + +#define MCFG_MCMS_IRQ_CALLBACK(_cb) \ + devcb = &mcms_device::set_irq_cb(*device, DEVCB_##_cb); + +MACHINE_CONFIG_FRAGMENT( a2mcms ) + MCFG_SPEAKER_STANDARD_STEREO("mcms_l", "mcms_r") + + MCFG_DEVICE_ADD(ENGINE_TAG, MCMS, 1000000) + MCFG_MCMS_IRQ_CALLBACK(WRITELINE(a2bus_mcms1_device, irq_w)) + + MCFG_SOUND_ROUTE(0, "mcms_l", 1.0) + MCFG_SOUND_ROUTE(1, "mcms_r", 1.0) +MACHINE_CONFIG_END + +/*************************************************************************** + FUNCTION PROTOTYPES +***************************************************************************/ + +//------------------------------------------------- +// machine_config_additions - device-specific +// machine configurations +//------------------------------------------------- + +machine_config_constructor a2bus_mcms1_device::device_mconfig_additions() const +{ + return MACHINE_CONFIG_NAME( a2mcms ); +} + +//************************************************************************** +// LIVE DEVICE - Card 1 +//************************************************************************** + +a2bus_mcms1_device::a2bus_mcms1_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock, const char *shortname, const char *source) : + device_t(mconfig, type, name, tag, owner, clock, shortname, source), + device_a2bus_card_interface(mconfig, *this), + m_mcms(*this, ENGINE_TAG) +{ +} + +a2bus_mcms1_device::a2bus_mcms1_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) : + device_t(mconfig, A2BUS_MCMS1, "Mountain Computer Music System (card 1)", tag, owner, clock, "a2mcms1", __FILE__), + device_a2bus_card_interface(mconfig, *this), + m_mcms(*this, ENGINE_TAG) +{ +} + +//------------------------------------------------- +// device_start - device-specific startup +//------------------------------------------------- + +void a2bus_mcms1_device::device_start() +{ + // set_a2bus_device makes m_slot valid + set_a2bus_device(); +} + +void a2bus_mcms1_device::device_reset() +{ +} + +// read once at c0n0 to disable 125 Hz IRQs +// read once at c0n1 to enable 125 Hz IRQs +UINT8 a2bus_mcms1_device::read_c0nx(address_space &space, UINT8 offset) +{ + if (offset == 0) + { + m_mcms->control_w(space, CTRL_IRQS, 0); + } + else if (offset == 1) + { + m_mcms->control_w(space, CTRL_IRQS, 1); + } + + return 0xff; +} + +// read at Cn00: light gun in bit 7, bits 0-5 = 'random' number +UINT8 a2bus_mcms1_device::read_cnxx(address_space &space, UINT8 offset) +{ + return m_mcms->get_pen_rand(); +} + +// write 0-255 to Cn00 to set the master volume +void a2bus_mcms1_device::write_cnxx(address_space &space, UINT8 offset, UINT8 data) +{ + if (offset == 0) + { + m_mcms->control_w(space, CTRL_MASTERVOL, data); + } +} + +mcms_device *a2bus_mcms1_device::get_engine(void) +{ + return m_mcms; +} + +WRITE_LINE_MEMBER(a2bus_mcms1_device::irq_w) +{ + if (state == ASSERT_LINE) + { + raise_slot_irq(); + } + else + { + lower_slot_irq(); + } +} + +//************************************************************************** +// LIVE DEVICE - Card 2 +//************************************************************************** + +a2bus_mcms2_device::a2bus_mcms2_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock, const char *shortname, const char *source) : + device_t(mconfig, type, name, tag, owner, clock, shortname, source), + device_a2bus_card_interface(mconfig, *this) +{ +} + +a2bus_mcms2_device::a2bus_mcms2_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) : + device_t(mconfig, A2BUS_MCMS2, "Mountain Computer Music System (card 2)", tag, owner, clock, "a2mcms2", __FILE__), + device_a2bus_card_interface(mconfig, *this) +{ +} + +//------------------------------------------------- +// device_start - device-specific startup +//------------------------------------------------- + +void a2bus_mcms2_device::device_start() +{ + // set_a2bus_device makes m_slot valid + set_a2bus_device(); + + if (m_slot < 2) + { + fatalerror("MCMS: Card 2 must be in slot 2 or greater\n"); + } +} + +void a2bus_mcms2_device::device_reset() +{ + m_card1 = static_cast(m_a2bus->m_device_list[m_slot-1]); + m_engine = m_card1->get_engine(); +} + +// here to soak up false reads from indexed accesses +UINT8 a2bus_mcms2_device::read_c0nx(address_space &space, UINT8 offset) +{ + return 0xff; +} + +// write once to c0n0 to disable the card (reset also disables) +// write twice to c0n1 to enable the card (value doesn't matter) +void a2bus_mcms2_device::write_c0nx(address_space &space, UINT8 offset, UINT8 data) +{ + if (offset == 0) + { + m_engine->control_w(space, CTRL_DMA, 0); + } + else if (offset == 1) + { + m_engine->control_w(space, CTRL_DMA, 1); + } +} + +void a2bus_mcms2_device::write_cnxx(address_space &space, UINT8 offset, UINT8 data) +{ + m_engine->voiceregs_w(space, offset, data); +} + + +/* + Sound device implementation +*/ + +mcms_device::mcms_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) + : device_t(mconfig, MCMS, "Mountain Computer Music System engine", tag, owner, clock, "msmseng", __FILE__), + device_sound_interface(mconfig, *this), + m_write_irq(*this) +{ +} + +void mcms_device::device_start() +{ + m_write_irq.resolve(); + m_stream = machine().sound().stream_alloc(*this, 0, 2, 31250); + m_timer = timer_alloc(0, NULL); + m_clrtimer = timer_alloc(1, NULL); + m_enabled = false; + memset(m_vols, 0, sizeof(m_vols)); + memset(m_table, 0, sizeof(m_table)); + memset(m_freq, 0, sizeof(m_freq)); + memset(m_acc, 0, sizeof(m_acc)); + + // the card detect programs volumes and wavetable page but not freq and expects the accumulator to increment + for (int i = 0; i < 16; i++) + { + m_freq[i] = 0x0040; + } + + save_item(NAME(m_enabled)); + save_item(NAME(m_vols)); + save_item(NAME(m_table)); + save_item(NAME(m_freq)); + save_item(NAME(m_acc)); + save_item(NAME(m_mastervol)); + save_item(NAME(m_rand)); +} + +void mcms_device::device_reset() +{ + m_write_irq(CLEAR_LINE); + m_timer->adjust(attotime::never); + m_clrtimer->adjust(attotime::never); + m_enabled = false; +} + +void mcms_device::device_timer(emu_timer &timer, device_timer_id tid, int param, void *ptr) +{ + if (tid == 0) + { + m_write_irq(ASSERT_LINE); + // clear this IRQ in 10 cycles (?) + m_clrtimer->adjust(attotime::from_usec(10), 0); + } + else if (tid == 1) + { + m_write_irq(CLEAR_LINE); + } +} + +void mcms_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +{ + stream_sample_t *outL, *outR; + int i, v; + UINT16 wptr; + INT8 sample; + INT32 mixL, mixR; + + outL = outputs[1]; + outR = outputs[0]; + + if (m_enabled) + { + for (i = 0; i < samples; i++) + { + mixL = mixR = 0; + + for (v = 0; v < 16; v++) + { + m_acc[v] += m_freq[v]; + wptr = (m_table[v]<<8) | (m_acc[v]>>8); + m_rand = (m_acc[v]>>8) & 0x1f; + + sample = (m_6502space->read_byte(wptr) ^ 0x80); + if (v & 1) + { + mixL += sample * m_vols[v]; + } + else + { + mixR += sample * m_vols[v]; + } + } + + outL[i] = (mixL * m_mastervol)>>9; + outR[i] = (mixR * m_mastervol)>>9; + } + } + else + { + for (i = 0; i < samples; i++) + { + outL[i] = outR[i] = 0; + } + } +} + +WRITE8_MEMBER(mcms_device::voiceregs_w) +{ + m_stream->update(); + if (offset >= 0x20) + { + if (offset & 1) // amp + { + m_vols[(offset-0x21)/2] = data; + } + else // wavetable page + { + m_table[(offset-0x20)/2] = data; + } + } + else + { + if (offset & 1) // freq L + { + if (offset == 0x1f) + { + m_freq[0] &= 0xff00; + m_freq[0] |= data; + } + else + { + int reg = (offset/2)+1; + m_freq[reg] &= 0xff00; + m_freq[reg] |= data; + } + } + else // freq H + { + int reg = (offset/2); + m_freq[reg] &= 0x00ff; + m_freq[reg] |= (data<<8); + } + } +} + +WRITE8_MEMBER(mcms_device::control_w) +{ + // keep the space (TODO: we need to define a formal DMA mechanism from machine/apple2 out to the slots) + m_6502space = &space; + + m_stream->update(); + + switch (offset) + { + case CTRL_IRQS: + if (data == 0) + { + m_timer->adjust(attotime::never); + } + else + { + m_timer->adjust(attotime::zero, 0, attotime::from_hz(125)); + } + break; + + case CTRL_DMA: + m_enabled = (data == 0) ? false : true; + break; + + case CTRL_MASTERVOL: + m_mastervol = data; + break; + } +} + diff --git a/src/emu/bus/a2bus/a2mcms.h b/src/emu/bus/a2bus/a2mcms.h new file mode 100644 index 00000000000..9e3b7588bfb --- /dev/null +++ b/src/emu/bus/a2bus/a2mcms.h @@ -0,0 +1,86 @@ +// license:BSD-3-Clause +// copyright-holders:R. Belmont +/********************************************************************* + + a2mcms.h + + Implementation of the Mountain Computer Music System. + This was sold standalone and also used as part of the alphaSyntauri + and SoundChaser systems. + +*********************************************************************/ + +#ifndef __A2BUS_MCMS__ +#define __A2BUS_MCMS__ + +#include "emu.h" +#include "a2bus.h" + +//************************************************************************** +// TYPE DEFINITIONS +//************************************************************************** + +// forward declaration +class mcms_device; + +// card 1 +class a2bus_mcms1_device: + public device_t, + public device_a2bus_card_interface +{ +public: + // construction/destruction + a2bus_mcms1_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock, const char *shortname, const char *source); + a2bus_mcms1_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); + + // optional information overrides + virtual machine_config_constructor device_mconfig_additions() const; + + // comms from card 2 (oscillator parameter writes) + mcms_device *get_engine(void); + + DECLARE_WRITE_LINE_MEMBER(irq_w); + + required_device m_mcms; + +protected: + virtual void device_start(); + virtual void device_reset(); + + // overrides of standard a2bus slot functions + virtual UINT8 read_c0nx(address_space &space, UINT8 offset); + virtual UINT8 read_cnxx(address_space &space, UINT8 offset); + virtual void write_cnxx(address_space &space, UINT8 offset, UINT8 data); + virtual bool take_c800() { return false; } +}; + +// card 2 +class a2bus_mcms2_device: + public device_t, + public device_a2bus_card_interface +{ +public: + // construction/destruction + a2bus_mcms2_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock, const char *shortname, const char *source); + a2bus_mcms2_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); + +protected: + virtual void device_start(); + virtual void device_reset(); + + // overrides of standard a2bus slot functions + virtual UINT8 read_c0nx(address_space &space, UINT8 offset); + virtual void write_c0nx(address_space &space, UINT8 offset, UINT8 data); + virtual void write_cnxx(address_space &space, UINT8 offset, UINT8 data); + virtual bool take_c800() { return false; } + +private: + a2bus_mcms1_device *m_card1; // card 1 for passthrough + class mcms_device *m_engine; +}; + +// device type definition +extern const device_type A2BUS_MCMS1; +extern const device_type A2BUS_MCMS2; + +#endif /* __A2BUS_MCMS__ */ diff --git a/src/emu/bus/bus.mak b/src/emu/bus/bus.mak index 659899ce045..c3ff30df803 100644 --- a/src/emu/bus/bus.mak +++ b/src/emu/bus/bus.mak @@ -699,6 +699,7 @@ BUSOBJS += $(BUSOBJ)/a2bus/a2eext80col.o BUSOBJS += $(BUSOBJ)/a2bus/a2eramworks3.o BUSOBJS += $(BUSOBJ)/a2bus/a2corvus.o BUSOBJS += $(BUSOBJ)/a2bus/a2diskiing.o +BUSOBJS += $(BUSOBJ)/a2bus/a2mcms.o endif #------------------------------------------------- diff --git a/src/mess/drivers/apple2.c b/src/mess/drivers/apple2.c index 25a21e1923b..54ae77b7843 100644 --- a/src/mess/drivers/apple2.c +++ b/src/mess/drivers/apple2.c @@ -212,6 +212,7 @@ Apple 3.5 and Apple 5.25 drives - up to three devices #include "bus/a2bus/a2ultraterm.h" #include "bus/a2bus/a2pic.h" #include "bus/a2bus/a2corvus.h" +#include "bus/a2bus/a2mcms.h" #include "bus/a2bus/a2estd80col.h" #include "bus/a2bus/a2eext80col.h" #include "bus/a2bus/a2eramworks3.h" @@ -977,6 +978,8 @@ static SLOT_INTERFACE_START(apple2_cards) SLOT_INTERFACE("aevm80", A2BUS_VTC2) /* Applied Engineering ViewMaster 80 */ SLOT_INTERFACE("parallel", A2BUS_PIC) /* Apple Parallel Interface Card */ SLOT_INTERFACE("corvus", A2BUS_CORVUS) /* Corvus flat-cable HDD interface (must go in slot 6) */ + SLOT_INTERFACE("mcms1", A2BUS_MCMS1) /* Mountain Computer Music System, card 1 of 2 */ + SLOT_INTERFACE("mcms2", A2BUS_MCMS2) /* Mountain Computer Music System, card 2 of 2. must be in card 1's slot + 1! */ SLOT_INTERFACE_END static SLOT_INTERFACE_START(apple2eaux_cards)