From edda5c5deca9400b377bd4893806d9135ce437b0 Mon Sep 17 00:00:00 2001 From: Curt Coder Date: Fri, 30 Aug 2013 19:33:01 +0000 Subject: [PATCH] (MESS) c64: Magic Voice WIP. (nw) --- .gitattributes | 2 + src/emu/machine/40105.c | 172 +++++++++++++++++++++++++++++ src/emu/machine/40105.h | 81 ++++++++++++++ src/emu/machine/machine.mak | 10 ++ src/emu/sound/t6721a.c | 14 ++- src/emu/sound/t6721a.h | 47 +++++--- src/mess/machine/c64/magic_voice.c | 34 ++++-- src/mess/machine/c64/magic_voice.h | 4 + src/mess/mess.mak | 1 + 9 files changed, 339 insertions(+), 26 deletions(-) create mode 100644 src/emu/machine/40105.c create mode 100644 src/emu/machine/40105.h diff --git a/.gitattributes b/.gitattributes index 10ab10717b1..e08665d6f3c 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1131,6 +1131,8 @@ src/emu/luaengine.c svneol=native#text/plain src/emu/luaengine.h svneol=native#text/plain src/emu/machine.c svneol=native#text/plain src/emu/machine.h svneol=native#text/plain +src/emu/machine/40105.c svneol=native#text/plain +src/emu/machine/40105.h svneol=native#text/plain src/emu/machine/53c7xx.c svneol=native#text/plain src/emu/machine/53c7xx.h svneol=native#text/plain src/emu/machine/53c810.c svneol=native#text/plain diff --git a/src/emu/machine/40105.c b/src/emu/machine/40105.c new file mode 100644 index 00000000000..9ef59e37c5e --- /dev/null +++ b/src/emu/machine/40105.c @@ -0,0 +1,172 @@ +/********************************************************************** + + CMOS 40105 FIFO Register emulation + + Copyright MESS Team. + Visit http://mamedev.org for licensing and usage restrictions. + +**********************************************************************/ + +#include "40105.h" + + + +//************************************************************************** +// MACROS / CONSTANTS +//************************************************************************** + +#define LOG 0 + + + +//************************************************************************** +// DEVICE DEFINITIONS +//************************************************************************** + +const device_type CMOS_40105 = &device_creator; + + + +//************************************************************************** +// LIVE DEVICE +//************************************************************************** + +//------------------------------------------------- +// cmos_40105_device - constructor +//------------------------------------------------- + +cmos_40105_device::cmos_40105_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) + : device_t(mconfig, CMOS_40105, "40105", tag, owner, clock, "40105", __FILE__), + m_write_dir(*this), + m_write_dor(*this) +{ +} + + +//------------------------------------------------- +// device_start - device-specific startup +//------------------------------------------------- + +void cmos_40105_device::device_start() +{ + // resolve callbacks + m_write_dir.resolve_safe(); + m_write_dor.resolve_safe(); + + // state saving + save_item(NAME(m_d)); + save_item(NAME(m_q)); + save_item(NAME(m_dir)); + save_item(NAME(m_dor)); + save_item(NAME(m_si)); + save_item(NAME(m_so)); +} + + +//------------------------------------------------- +// device_reset - device-specific reset +//------------------------------------------------- + +void cmos_40105_device::device_reset() +{ + m_fifo = std::queue(); + + m_dir = 1; + m_dor = 0; + + m_write_dir(m_dir); + m_write_dor(m_dor); +} + + +//------------------------------------------------- +// read - read Q +//------------------------------------------------- + +UINT8 cmos_40105_device::read() +{ + return m_q; +} + + +//------------------------------------------------- +// write - write D +//------------------------------------------------- + +void cmos_40105_device::write(UINT8 data) +{ + m_d = data & 0x0f; +} + + +//------------------------------------------------- +// si_w - shift in write +//------------------------------------------------- + +WRITE_LINE_MEMBER( cmos_40105_device::si_w ) +{ + if (m_dir && !m_si && state) + { + m_fifo.push(m_d); + + if (m_fifo.size() == 16) + { + m_dir = 0; + m_write_dir(m_dir); + } + + if (!m_dor) + { + m_dor = 1; + m_write_dor(m_dor); + } + + } + + m_si = state; +} + + +//------------------------------------------------- +// so_w - shift out write +//------------------------------------------------- + +WRITE_LINE_MEMBER( cmos_40105_device::so_w ) +{ + if (m_dor && m_so && !m_so) + { + m_dor = 0; + m_write_dor(m_dor); + + m_q = m_fifo.front(); + m_fifo.pop(); + + if (m_fifo.size() > 0) + { + m_dor = 1; + m_write_dor(m_dor); + } + } + + m_so = state; +} + + +//------------------------------------------------- +// dir_r - data in ready read +//------------------------------------------------- + +READ_LINE_MEMBER( cmos_40105_device::dir_r ) +{ + return m_dir; +} + + +//------------------------------------------------- +// dor_r - data out ready read +//------------------------------------------------- + +READ_LINE_MEMBER( cmos_40105_device::dor_r ) +{ + return m_dor; +} diff --git a/src/emu/machine/40105.h b/src/emu/machine/40105.h new file mode 100644 index 00000000000..0291d75b0b6 --- /dev/null +++ b/src/emu/machine/40105.h @@ -0,0 +1,81 @@ +/********************************************************************** + + CMOS 40105 FIFO Register emulation + + Copyright MESS Team. + Visit http://mamedev.org for licensing and usage restrictions. + +**********************************************************************/ + +#pragma once + +#ifndef __CMOS_40105__ +#define __CMOS_40105__ + +#include "emu.h" +#include + + + +///************************************************************************* +// INTERFACE CONFIGURATION MACROS +///************************************************************************* + +#define MCFG_40105_ADD(_tag, _dir, _dor) \ + MCFG_DEVICE_ADD(_tag, CMOS_40105, 0) \ + downcast(device)->set_dir_callback(DEVCB2_##_dir); \ + downcast(device)->set_dor_callback(DEVCB2_##_dor); + + + +///************************************************************************* +// TYPE DEFINITIONS +///************************************************************************* + +// ======================> cmos_40105_device + +class cmos_40105_device : public device_t +{ +public: + // construction/destruction + cmos_40105_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); + + template void set_dir_callback(_dir dir) { m_write_dir.set_callback(dir); } + template void set_dor_callback(_dor dor) { m_write_dor.set_callback(dor); } + + UINT8 read(); + void write(UINT8 data); + + DECLARE_WRITE_LINE_MEMBER( si_w ); + DECLARE_WRITE_LINE_MEMBER( so_w ); + + DECLARE_READ_LINE_MEMBER( dir_r ); + DECLARE_READ_LINE_MEMBER( dor_r ); + +protected: + // device-level overrides + virtual void device_start(); + virtual void device_reset(); + +private: + devcb2_write_line m_write_dir; + devcb2_write_line m_write_dor; + + std::queue m_fifo; + + UINT8 m_d; + UINT8 m_q; + + int m_dir; + int m_dor; + int m_si; + int m_so; +}; + + +// device type definition +extern const device_type CMOS_40105; + + + +#endif diff --git a/src/emu/machine/machine.mak b/src/emu/machine/machine.mak index 8a31c486968..74181032701 100644 --- a/src/emu/machine/machine.mak +++ b/src/emu/machine/machine.mak @@ -14,6 +14,16 @@ MACHINESRC = $(EMUSRC)/machine MACHINEOBJ = $(EMUOBJ)/machine +#------------------------------------------------- +# +#@src/emu/machine/40105.h,MACHINES += CMOS40105 +#------------------------------------------------- + +ifneq ($(filter CMOS40105,$(MACHINES)),) +MACHINEOBJS += $(MACHINEOBJ)/40105.o +endif + + #------------------------------------------------- # #@src/emu/machine/53c7xx.h,MACHINES += NCR53C7XX diff --git a/src/emu/sound/t6721a.c b/src/emu/sound/t6721a.c index 4d642ef7edb..cc32a7eb5ea 100644 --- a/src/emu/sound/t6721a.c +++ b/src/emu/sound/t6721a.c @@ -39,9 +39,10 @@ const device_type T6721A = &device_creator; t6721a_device::t6721a_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) : device_t(mconfig, T6721A, "T6721A", tag, owner, clock, "t6721a", __FILE__), device_sound_interface(mconfig, *this), - m_eos_handler(*this), - m_dtrd_handler(*this), - m_apd_handler(*this), + m_write_eos(*this), + m_write_phi2(*this), + m_write_dtrd(*this), + m_write_apd(*this), m_stream(NULL) { } @@ -54,9 +55,10 @@ t6721a_device::t6721a_device(const machine_config &mconfig, const char *tag, dev void t6721a_device::device_start() { // resolve callbacks - m_eos_handler.resolve_safe(); - m_dtrd_handler.resolve_safe(); - m_apd_handler.resolve_safe(); + m_write_eos.resolve_safe(); + m_write_phi2.resolve_safe(); + m_write_dtrd.resolve_safe(); + m_write_apd.resolve_safe(); // create sound stream m_stream = machine().sound().stream_alloc(*this, 0, 1, machine().sample_rate()); diff --git a/src/emu/sound/t6721a.h b/src/emu/sound/t6721a.h index 8572063c380..6cc8c24b966 100644 --- a/src/emu/sound/t6721a.h +++ b/src/emu/sound/t6721a.h @@ -44,14 +44,17 @@ // INTERFACE CONFIGURATION MACROS //************************************************************************** -#define MCFG_T6721A_EOS_HANDLER(_devcb) \ - devcb = &t6721a_device::set_eos_handler(*device, DEVCB2_##_devcb); +#define MCFG_T6721A_EOS_HANDLER(_eos) \ + downcast(device)->set_eos_callback(DEVCB2_##_eos); -#define MCFG_T6721A_DTRD_HANDLER(_devcb) \ - devcb = &t6721a_device::set_dtrd_handler(*device, DEVCB2_##_devcb); +#define MCFG_T6721A_PHI2_HANDLER(_phi2) \ + downcast(device)->set_phi2_callback(DEVCB2_##_phi2); -#define MCFG_T6721A_APD_HANDLER(_devcb) \ - devcb = &t6721a_device::set_apd_handler(*device, DEVCB2_##_devcb); +#define MCFG_T6721A_DTRD_HANDLER(_dtrd) \ + downcast(device)->set_dtrd_callback(DEVCB2_##_dtrd); + +#define MCFG_T6721A_APD_HANDLER(_apd) \ + downcast(device)->set_apd_callback(DEVCB2_##_apd); @@ -62,15 +65,16 @@ // ======================> t6721a_device class t6721a_device : public device_t, - public device_sound_interface + public device_sound_interface { public: t6721a_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); // static configuration helpers - template static devcb2_base &set_eos_handler(device_t &device, _Object object) { return downcast(device).m_eos_handler.set_callback(object); } - template static devcb2_base &set_dtrd_handler(device_t &device, _Object object) { return downcast(device).m_dtrd_handler.set_callback(object); } - template static devcb2_base &set_apd_handler(device_t &device, _Object object) { return downcast(device).m_apd_handler.set_callback(object); } + template void set_eos_callback(_eos eos) { m_write_eos.set_callback(eos); } + template void set_phi2_callback(_phi2 phi2) { m_write_phi2.set_callback(phi2); } + template void set_dtrd_callback(_dtrd dtrd) { m_write_dtrd.set_callback(dtrd); } + template void set_apd_callback(_apd apd) { m_write_apd.set_callback(apd); } DECLARE_READ8_MEMBER( read ); DECLARE_WRITE8_MEMBER( write ); @@ -87,9 +91,26 @@ protected: virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples); private: - devcb2_write_line m_eos_handler; - devcb2_write_line m_dtrd_handler; - devcb2_write_line m_apd_handler; + enum + { + CMD_NOP = 0, + CMD_STRT, + CMD_STOP, + CMD_ADLD, + CMD_AAGN, + CMD_SPLD, + CMD_CNDT1, + CMD_CNDT2, + CMD_RRDM, + CMD_SPDN, + CMD_APDN, + CMD_SAGN + }; + + devcb2_write_line m_write_eos; + devcb2_write_line m_write_phi2; + devcb2_write_line m_write_dtrd; + devcb2_write_line m_write_apd; sound_stream *m_stream; }; diff --git a/src/mess/machine/c64/magic_voice.c b/src/mess/machine/c64/magic_voice.c index 86b4ac87b25..96942e7ec41 100644 --- a/src/mess/machine/c64/magic_voice.c +++ b/src/mess/machine/c64/magic_voice.c @@ -40,8 +40,9 @@ http://www.stefan-uhlmann.de/cbm/MVM/index.html // MACROS / CONSTANTS //************************************************************************** -#define T6721A_TAG "u5" -#define MOS6525_TAG "u2" +#define T6721A_TAG "u5" +#define MOS6525_TAG "u2" +#define CMOS40105_TAG "u1" @@ -77,7 +78,7 @@ READ8_MEMBER( c64_magic_voice_cartridge_device::tpi_pa_r ) data |= m_exp->game_r(get_offset(0xdf80), 1, 0, 1, 0) << 5; data |= m_vslsi->eos_r() << 6; - //data |= m_fifo->dir_r() << 7; + data |= m_fifo->dir_r() << 7; return data; } @@ -99,8 +100,8 @@ WRITE8_MEMBER( c64_magic_voice_cartridge_device::tpi_pa_w ) */ - //m_fifo->write(data & 0x0f); - //m_fifo->si_w(BIT(data, 4)); + m_fifo->write(data & 0x0f); + m_fifo->si_w(BIT(data, 4)); } READ8_MEMBER( c64_magic_voice_cartridge_device::tpi_pb_r ) @@ -172,7 +173,7 @@ READ8_MEMBER( c64_magic_voice_cartridge_device::tpi_pc_r ) UINT8 data = 0; data |= m_vslsi->eos_r() << 2; - //data |= m_fifo->dir_r() << 3; + data |= m_fifo->dir_r() << 3; return data; } @@ -217,14 +218,30 @@ static const tpi6525_interface tpi_intf = // t6721_interface //------------------------------------------------- +WRITE_LINE_MEMBER( c64_magic_voice_cartridge_device::phi2_w ) +{ + if (state) + { + m_vslsi->di_w(m_pd & 0x01); + + m_pd >>= 1; + } +} + WRITE_LINE_MEMBER( c64_magic_voice_cartridge_device::dtrd_w ) { + m_fifo->so_w(!state); + m_pd = m_fifo->read(); } WRITE_LINE_MEMBER( c64_magic_voice_cartridge_device::apd_w ) { - + if (state) + { + m_fifo->reset(); + m_pd = 0; + } } @@ -234,10 +251,12 @@ WRITE_LINE_MEMBER( c64_magic_voice_cartridge_device::apd_w ) static MACHINE_CONFIG_FRAGMENT( c64_magic_voice ) MCFG_TPI6525_ADD(MOS6525_TAG, tpi_intf) + MCFG_40105_ADD(CMOS40105_TAG, DEVWRITELINE(MOS6525_TAG, tpi6525_device, i3_w), NULL) MCFG_SPEAKER_STANDARD_MONO("mono") MCFG_SOUND_ADD(T6721A_TAG, T6721A, XTAL_640kHz) MCFG_T6721A_EOS_HANDLER(DEVWRITELINE(MOS6525_TAG, tpi6525_device, i2_w)) + MCFG_T6721A_PHI2_HANDLER(DEVWRITELINE(DEVICE_SELF, c64_magic_voice_cartridge_device, phi2_w)) MCFG_T6721A_DTRD_HANDLER(DEVWRITELINE(DEVICE_SELF, c64_magic_voice_cartridge_device, dtrd_w)) MCFG_T6721A_APD_HANDLER(DEVWRITELINE(DEVICE_SELF, c64_magic_voice_cartridge_device, apd_w)) MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.25) @@ -271,6 +290,7 @@ c64_magic_voice_cartridge_device::c64_magic_voice_cartridge_device(const machine device_c64_expansion_card_interface(mconfig, *this), m_vslsi(*this, T6721A_TAG), m_tpi(*this, MOS6525_TAG), + m_fifo(*this, CMOS40105_TAG), m_exp(*this, C64_EXPANSION_SLOT_TAG), m_roml2(1), m_romh2(1), diff --git a/src/mess/machine/c64/magic_voice.h b/src/mess/machine/c64/magic_voice.h index 7ace89df853..88cb5a4ee11 100644 --- a/src/mess/machine/c64/magic_voice.h +++ b/src/mess/machine/c64/magic_voice.h @@ -13,6 +13,7 @@ #define __MAGIC_VOICE__ #include "emu.h" +#include "machine/40105.h" #include "machine/6525tpi.h" #include "machine/c64/exp.h" #include "machine/cbmipt.h" @@ -43,6 +44,7 @@ public: DECLARE_READ8_MEMBER( tpi_pc_r ); DECLARE_WRITE8_MEMBER( tpi_pc_w ); + DECLARE_WRITE_LINE_MEMBER( phi2_w ); DECLARE_WRITE_LINE_MEMBER( dtrd_w ); DECLARE_WRITE_LINE_MEMBER( apd_w ); @@ -60,6 +62,7 @@ private: required_device m_vslsi; required_device m_tpi; + required_device m_fifo; required_device m_exp; int m_roml2; @@ -67,6 +70,7 @@ private: int m_eprom; int m_da_ca; UINT8 m_vslsi_data; + UINT8 m_pd; }; diff --git a/src/mess/mess.mak b/src/mess/mess.mak index 91babb5c52d..ad1a15d016e 100644 --- a/src/mess/mess.mak +++ b/src/mess/mess.mak @@ -310,6 +310,7 @@ VIDEOS += V9938 # specify available machine cores #------------------------------------------------- +MACHINES += CMOS40105 MACHINES += NCR53C7XX MACHINES += LSI53C810 MACHINES += 6522VIA