modernised YMF271 [smf]

This commit is contained in:
smf- 2013-05-10 15:06:32 +00:00
parent 2138059b16
commit 83fb87b569
5 changed files with 452 additions and 472 deletions

File diff suppressed because it is too large Load Diff

View File

@ -3,39 +3,137 @@
#ifndef __YMF271_H__
#define __YMF271_H__
#include "devlegcy.h"
#include "emu.h"
#define MCFG_YMF271_IRQ_HANDLER(_devcb) \
devcb = &ymf271_device::set_irq_handler(*device, DEVCB2_##_devcb);
struct ymf271_interface
{
devcb_read8 ext_read; /* external memory read */
devcb_write8 ext_write; /* external memory write */
devcb_write_line irq_callback; /* irq callback */
};
#define MCFG_YMF271_EXT_READ_HANDLER(_devcb) \
devcb = &ymf271_device::set_ext_read_handler(*device, DEVCB2_##_devcb);
DECLARE_READ8_DEVICE_HANDLER( ymf271_r );
DECLARE_WRITE8_DEVICE_HANDLER( ymf271_w );
#define MCFG_YMF271_EXT_WRITE_HANDLER(_devcb) \
devcb = &ymf271_device::set_ext_write_handler(*device, DEVCB2_##_devcb);
class ymf271_device : public device_t,
public device_sound_interface
{
public:
ymf271_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
~ymf271_device() { global_free(m_token); }
// access to legacy token
void *token() const { assert(m_token != NULL); return m_token; }
// static configuration helpers
template<class _Object> static devcb2_base &set_irq_handler(device_t &device, _Object object) { return downcast<ymf271_device &>(device).m_irq_handler.set_callback(object); }
template<class _Object> static devcb2_base &set_ext_read_handler(device_t &device, _Object object) { return downcast<ymf271_device &>(device).m_ext_read_handler.set_callback(object); }
template<class _Object> static devcb2_base &set_ext_write_handler(device_t &device, _Object object) { return downcast<ymf271_device &>(device).m_ext_write_handler.set_callback(object); }
DECLARE_READ8_MEMBER( read );
DECLARE_WRITE8_MEMBER( write );
protected:
// device-level overrides
virtual void device_config_complete();
virtual void device_start();
virtual void device_reset();
virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
// sound stream update overrides
virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples);
private:
struct YMF271Slot
{
INT8 extout;
UINT8 lfoFreq;
INT8 lfowave;
INT8 pms, ams;
INT8 detune;
INT8 multiple;
INT8 tl;
INT8 keyscale;
INT8 ar;
INT8 decay1rate, decay2rate;
INT8 decay1lvl;
INT8 relrate;
INT32 fns;
INT8 block;
INT8 feedback;
INT8 waveform;
INT8 accon;
INT8 algorithm;
INT8 ch0_level, ch1_level, ch2_level, ch3_level;
UINT32 startaddr;
UINT32 loopaddr;
UINT32 endaddr;
INT8 fs, srcnote, srcb;
INT64 step;
INT64 stepptr;
INT8 active;
INT8 bits;
// envelope generator
INT32 volume;
INT32 env_state;
INT32 env_attack_step; // volume increase step in attack state
INT32 env_decay1_step;
INT32 env_decay2_step;
INT32 env_release_step;
INT64 feedback_modulation0;
INT64 feedback_modulation1;
INT32 lfo_phase, lfo_step;
INT32 lfo_amplitude;
double lfo_phasemod;
};
struct YMF271Group
{
INT8 sync, pfm;
};
void init_state();
void calculate_step(YMF271Slot *slot);
void update_envelope(YMF271Slot *slot);
void init_envelope(YMF271Slot *slot);
void init_lfo(YMF271Slot *slot);
void update_lfo(YMF271Slot *slot);
int calculate_slot_volume(YMF271Slot *slot);
void update_pcm(int slotnum, INT32 *mixp, int length);
INT32 calculate_2op_fm_0(int slotnum1, int slotnum2);
INT32 calculate_2op_fm_1(int slotnum1, int slotnum2);
INT32 calculate_1op_fm_0(int slotnum, int phase_modulation);
INT32 calculate_1op_fm_1(int slotnum);
void write_register(int slotnum, int reg, int data);
void ymf271_write_fm(int grp, int adr, int data);
void ymf271_write_pcm(int data);
UINT8 ymf271_read_ext_memory(UINT32 address);
void ymf271_write_ext_memory(UINT32 address, UINT8 data);
void ymf271_write_timer(int data);
// internal state
void *m_token;
YMF271Slot m_slots[48];
YMF271Group m_groups[12];
INT32 m_timerA, m_timerB;
INT32 m_timerAVal, m_timerBVal;
INT32 m_irqstate;
INT8 m_status;
INT8 m_enable;
emu_timer *m_timA, *m_timB;
INT8 m_reg0, m_reg1, m_reg2, m_reg3, m_pcmreg, m_timerreg;
UINT32 m_ext_address;
UINT8 m_ext_read;
const UINT8 *m_rom;
devcb2_write_line m_irq_handler;
devcb2_read8 m_ext_read_handler;
devcb2_write8 m_ext_write_handler;
UINT32 m_clock;
sound_stream * m_stream;
};
extern const device_type YMF271;

View File

@ -1359,7 +1359,7 @@ WRITE8_MEMBER(ms32_state::to_main_w)
static ADDRESS_MAP_START( ms32_sound_map, AS_PROGRAM, 8, ms32_state )
AM_RANGE(0x0000, 0x3eff) AM_ROM
AM_RANGE(0x3f00, 0x3f0f) AM_DEVREADWRITE_LEGACY("ymf", ymf271_r,ymf271_w)
AM_RANGE(0x3f00, 0x3f0f) AM_DEVREADWRITE("ymf", ymf271_device, read, write)
AM_RANGE(0x3f10, 0x3f10) AM_READWRITE(latch_r,to_main_w)
AM_RANGE(0x3f20, 0x3f20) AM_READNOP /* 2nd latch ? */
AM_RANGE(0x3f20, 0x3f20) AM_WRITENOP /* to_main2_w ? */

View File

@ -1056,7 +1056,7 @@ static ADDRESS_MAP_START( spisound_map, AS_PROGRAM, 8, seibuspi_state )
AM_RANGE(0x400b, 0x400b) AM_WRITENOP /* Unknown */
AM_RANGE(0x4013, 0x4013) AM_READ(z80_coin_r)
AM_RANGE(0x401b, 0x401b) AM_WRITE(z80_bank_w) /* control register: bits 0-2 = bank @ 8000, bit 3 = watchdog? */
AM_RANGE(0x6000, 0x600f) AM_DEVREADWRITE_LEGACY("ymf", ymf271_r, ymf271_w)
AM_RANGE(0x6000, 0x600f) AM_DEVREADWRITE("ymf", ymf271_device, read, write)
AM_RANGE(0x8000, 0xffff) AM_ROMBANK("bank4")
ADDRESS_MAP_END
@ -1102,13 +1102,6 @@ WRITE32_MEMBER(seibuspi_state::sys386f2_eeprom_w)
m_eeprom->set_cs_line((data & 0x20) ? CLEAR_LINE : ASSERT_LINE);
}
static const ymf271_interface ymf271_config =
{
DEVCB_DRIVER_MEMBER(seibuspi_state,flashrom_read),
DEVCB_DRIVER_MEMBER(seibuspi_state,flashrom_write),
DEVCB_DRIVER_LINE_MEMBER(seibuspi_state,irqhandler)
};
/********************************************************************/
static ADDRESS_MAP_START( seibu386_map, AS_PROGRAM, 32, seibuspi_state )
@ -1870,7 +1863,10 @@ static MACHINE_CONFIG_START( spi, seibuspi_state )
MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker")
MCFG_SOUND_ADD("ymf", YMF271, XTAL_16_9344MHz)
MCFG_SOUND_CONFIG(ymf271_config)
MCFG_YMF271_IRQ_HANDLER(WRITELINE(seibuspi_state, irqhandler))
MCFG_YMF271_EXT_READ_HANDLER(READ8(seibuspi_state, flashrom_read))
MCFG_YMF271_EXT_WRITE_HANDLER(WRITE8(seibuspi_state,flashrom_write))
MCFG_SOUND_ROUTE(0, "lspeaker", 1.0)
MCFG_SOUND_ROUTE(1, "rspeaker", 1.0)
MACHINE_CONFIG_END
@ -1947,7 +1943,9 @@ static MACHINE_CONFIG_DERIVED( sxx2g, spi ) /* single board version using measur
MCFG_CPU_CLOCK(XTAL_4_9152MHz)
MCFG_SOUND_REPLACE("ymf", YMF271, XTAL_16_384MHz)
MCFG_SOUND_CONFIG(ymf271_config)
MCFG_YMF271_IRQ_HANDLER(WRITELINE(seibuspi_state, irqhandler))
MCFG_YMF271_EXT_READ_HANDLER(READ8(seibuspi_state, flashrom_read))
MCFG_YMF271_EXT_WRITE_HANDLER(WRITE8(seibuspi_state,flashrom_write))
MCFG_SOUND_ROUTE(0, "lspeaker", 1.0)
MCFG_SOUND_ROUTE(1, "rspeaker", 1.0)

View File

@ -1619,7 +1619,7 @@ MACHINE_RESET_MEMBER(zn_state,coh1002e)
static ADDRESS_MAP_START( psarc_snd_map, AS_PROGRAM, 16, zn_state )
AM_RANGE(0x000000, 0x07ffff) AM_ROM
AM_RANGE(0x080000, 0x0fffff) AM_RAM
AM_RANGE(0x100000, 0x10001f) AM_DEVREADWRITE8_LEGACY("ymf", ymf271_r, ymf271_w, 0x00ff )
AM_RANGE(0x100000, 0x10001f) AM_DEVREADWRITE8("ymf", ymf271_device, read, write, 0x00ff )
AM_RANGE(0x180008, 0x180009) AM_READ8(soundlatch_byte_r, 0x00ff )
AM_RANGE(0x000000, 0x07ffff) AM_WRITENOP
AM_RANGE(0x100020, 0xffffff) AM_WRITENOP