diff options
author | therealmogminer@gmail.com <therealmogminer@gmail.com> | 2015-11-18 23:06:35 +0100 |
---|---|---|
committer | Miodrag Milanovic <mmicko@gmail.com> | 2016-01-23 17:30:14 +0100 |
commit | cccc998b20d0a25dce9f0673eca998c6a8b5efe8 (patch) | |
tree | 15c4651da7701cb50d1f7b988eef60dc8abf2241 /src/devices/sound | |
parent | 5a9fb4c34030492adbaf690627d8f612000db550 (diff) |
First round of this==NULL crash fixes
Diffstat (limited to 'src/devices/sound')
-rw-r--r-- | src/devices/sound/2610intf.cpp | 33 | ||||
-rw-r--r-- | src/devices/sound/2610intf.h | 3 | ||||
-rw-r--r-- | src/devices/sound/fm.cpp | 11 | ||||
-rw-r--r-- | src/devices/sound/upd7759.cpp | 119 | ||||
-rw-r--r-- | src/devices/sound/upd7759.h | 1 | ||||
-rw-r--r-- | src/devices/sound/ymz280b.cpp | 9 |
6 files changed, 105 insertions, 71 deletions
diff --git a/src/devices/sound/2610intf.cpp b/src/devices/sound/2610intf.cpp index 9111b03502c..4cc7f303795 100644 --- a/src/devices/sound/2610intf.cpp +++ b/src/devices/sound/2610intf.cpp @@ -16,6 +16,9 @@ #include "2610intf.h" #include "fm.h" +const char* YM2610_TAG = "ymsnd"; +const char* YM2610_DELTAT_TAG = "ymsnd.deltat"; + static void psg_set_clock(void *param, int clock) { ym2610_device *ym2610 = (ym2610_device *) param; @@ -143,9 +146,6 @@ void ym2610_device::device_start() ay8910_device::device_start(); int rate = clock()/72; - void *pcmbufa,*pcmbufb; - int pcmsizea,pcmsizeb; - std::string name(tag()); m_irq_handler.resolve(); @@ -155,16 +155,19 @@ void ym2610_device::device_start() /* stream system initialize */ m_stream = machine().sound().stream_alloc(*this,0,2,rate, stream_update_delegate(FUNC(ym2610_device::stream_generate),this)); + /* setup adpcm buffers */ - pcmbufa = region()->base(); - pcmsizea = region()->bytes(); - name.append(".deltat"); - pcmbufb = (void *)(machine().root_device().memregion(name.c_str())->base()); - pcmsizeb = machine().root_device().memregion(name.c_str())->bytes(); - if (pcmbufb == nullptr || pcmsizeb == 0) + void *pcmbufa = region()->base(); + int pcmsizea = region()->bytes(); + + std::string name = tag() + std::string(".deltat"); + memory_region *deltat_region = machine().root_device().memregion(name.c_str()); + void *pcmbufb = pcmbufa; + int pcmsizeb = pcmsizea; + if (deltat_region != nullptr && deltat_region->base() != nullptr && deltat_region->bytes() != 0) { - pcmbufb = pcmbufa; - pcmsizeb = pcmsizea; + pcmbufb = deltat_region->base(); + pcmsizeb = deltat_region->bytes(); } /**** initialize YM2610 ****/ @@ -207,14 +210,14 @@ WRITE8_MEMBER( ym2610_device::write ) const device_type YM2610 = &device_creator<ym2610_device>; ym2610_device::ym2610_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) - : ay8910_device(mconfig, YM2610, "YM2610", tag, owner, clock, PSG_TYPE_YM, 1, 0, "ym2610", __FILE__), - m_irq_handler(*this) + : ay8910_device(mconfig, YM2610, "YM2610", tag, owner, clock, PSG_TYPE_YM, 1, 0, "ym2610", __FILE__) + , m_irq_handler(*this) { } ym2610_device::ym2610_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) - : ay8910_device(mconfig, type, name, tag, owner, clock, PSG_TYPE_YM, 1, 0, shortname, source), - m_irq_handler(*this) + : ay8910_device(mconfig, type, name, tag, owner, clock, PSG_TYPE_YM, 1, 0, shortname, source) + , m_irq_handler(*this) { } diff --git a/src/devices/sound/2610intf.h b/src/devices/sound/2610intf.h index c4409e46f21..dcd0ef01787 100644 --- a/src/devices/sound/2610intf.h +++ b/src/devices/sound/2610intf.h @@ -29,6 +29,9 @@ public: void _timer_handler(int c,int count,int clock); void _ym2610_update_request(); + static const char* YM2610_TAG; + static const char* YM2610_DELTAT_TAG; + protected: // device-level overrides virtual void device_start() override; diff --git a/src/devices/sound/fm.cpp b/src/devices/sound/fm.cpp index 854fbb61004..fbc45073060 100644 --- a/src/devices/sound/fm.cpp +++ b/src/devices/sound/fm.cpp @@ -2423,7 +2423,7 @@ struct YM2610 UINT8 flagmask; /* YM2608 only */ UINT8 irqmask; /* YM2608 only */ - device_t *device; + device_t *device; }; /* here is the virtual YM2608 */ @@ -3686,14 +3686,21 @@ void ym2610_reset_chip(void *chip) F2610->pcmbuf = (const UINT8 *)dev->machine().root_device().memregion(name.c_str())->base(); F2610->pcm_size = dev->machine().root_device().memregion(name.c_str())->bytes(); name.append(".deltat"); - F2610->deltaT.memory = (UINT8 *)dev->machine().root_device().memregion(name.c_str())->base(); + memory_region *deltat_region = dev->machine().root_device().memregion(name.c_str()); + F2610->deltaT.memory = nullptr; + if (deltat_region != nullptr) + { + F2610->deltaT.memory = (UINT8 *)dev->machine().root_device().memregion(name.c_str())->base(); + } if(F2610->deltaT.memory == nullptr) { F2610->deltaT.memory = (UINT8*)F2610->pcmbuf; F2610->deltaT.memory_size = F2610->pcm_size; } else + { F2610->deltaT.memory_size = dev->machine().root_device().memregion(name.c_str())->bytes(); + } /* Reset Prescaler */ OPNSetPres( OPN, 6*24, 6*24, 4*2); /* OPN 1/6 , SSG 1/4 */ diff --git a/src/devices/sound/upd7759.cpp b/src/devices/sound/upd7759.cpp index a7e0491687f..d5727b6464d 100644 --- a/src/devices/sound/upd7759.cpp +++ b/src/devices/sound/upd7759.cpp @@ -145,52 +145,53 @@ upd775x_device::upd775x_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_sound_interface(mconfig, *this), - m_channel(nullptr), - m_sample_offset_shift(0), - m_pos(0), - m_step(0), - m_fifo_in(0), - m_reset(0), - m_start(0), - m_drq(0), - m_state(0), - m_clocks_left(0), - m_nibbles_left(0), - m_repeat_count(0), - m_post_drq_state(0), - m_post_drq_clocks(0), - m_req_sample(0), - m_last_sample(0), - m_block_header(0), - m_sample_rate(0), - m_first_valid_header(0), - m_offset(0), - m_repeat_offset(0), - m_adpcm_state(0), - m_adpcm_data(0), - m_sample(0), - m_rom(nullptr), - m_rombase(nullptr), - m_romoffset(0), - m_rommask(0), - m_drqcallback(*this) + : device_t(mconfig, type, name, tag, owner, clock, shortname, source) + , device_sound_interface(mconfig, *this) + , m_channel(nullptr) + , m_sample_offset_shift(0) + , m_pos(0) + , m_step(0) + , m_fifo_in(0) + , m_reset(0) + , m_start(0) + , m_drq(0) + , m_state(0) + , m_clocks_left(0) + , m_nibbles_left(0) + , m_repeat_count(0) + , m_post_drq_state(0) + , m_post_drq_clocks(0) + , m_req_sample(0) + , m_last_sample(0) + , m_block_header(0) + , m_sample_rate(0) + , m_first_valid_header(0) + , m_offset(0) + , m_repeat_offset(0) + , m_adpcm_state(0) + , m_adpcm_data(0) + , m_sample(0) + , m_rom_region(*this, tag) + , m_rom(nullptr) + , m_rombase(nullptr) + , m_romoffset(0) + , m_rommask(0) + , m_drqcallback(*this) { } const device_type UPD7759 = &device_creator<upd7759_device>; upd7759_device::upd7759_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) - : upd775x_device(mconfig, UPD7759, "uPD7759", tag, owner, clock, "upd7759", __FILE__), - m_timer(nullptr) + : upd775x_device(mconfig, UPD7759, "uPD7759", tag, owner, clock, "upd7759", __FILE__) + , m_timer(nullptr) { } upd7759_device::upd7759_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) : upd775x_device(mconfig, type, name, tag, owner, clock, shortname, source), - m_timer(nullptr) + , m_timer(nullptr) { } @@ -231,20 +232,27 @@ void upd7759_device::device_start() /* compute the ROM base or allocate a timer */ m_romoffset = 0; - m_rom = m_rombase = region()->base(); - if (m_rombase == nullptr) + if (m_rom_region != nullptr) { - assert(type() == UPD7759); // other chips do not support slave mode - m_timer = timer_alloc(TIMER_SLAVE_UPDATE); - m_rommask = 0; + m_rom = m_rombase = m_rom_region->base(); + + UINT32 romsize = m_rom_region->bytes(); + if (romsize >= 0x20000) + { + m_rommask = 0x1ffff; + } + else + { + m_rommask = romsize - 1; + } + + m_drqcallback.set_callback(DEVCB_NULL); } else { - UINT32 romsize = region()->bytes(); - if (romsize >= 0x20000) m_rommask = 0x1ffff; - else m_rommask = romsize - 1; - - m_drqcallback.set_callback(DEVCB_NULL); + assert(type() == UPD7759); // other chips do not support slave mode + m_timer = timer_alloc(TIMER_SLAVE_UPDATE); + m_rommask = 0; } /* assume /RESET and /START are both high */ @@ -306,19 +314,26 @@ void upd7756_device::device_start() /* compute the ROM base or allocate a timer */ m_romoffset = 0; - m_rom = m_rombase = region()->base(); - if (m_rombase == nullptr) - { - m_rommask = 0; - } - else + if (m_rom_region != nullptr) { + m_rom = m_rombase = m_rom_region->base(); + UINT32 romsize = region()->bytes(); - if (romsize >= 0x20000) m_rommask = 0x1ffff; - else m_rommask = romsize - 1; + if (romsize >= 0x20000) + { + m_rommask = 0x1ffff; + } + else + { + m_rommask = romsize - 1; + } m_drqcallback.set_callback(DEVCB_NULL); } + else + { + m_rommask = 0; + } /* assume /RESET and /START are both high */ m_reset = 1; diff --git a/src/devices/sound/upd7759.h b/src/devices/sound/upd7759.h index 637732b22fa..f42039a785a 100644 --- a/src/devices/sound/upd7759.h +++ b/src/devices/sound/upd7759.h @@ -95,6 +95,7 @@ protected: INT16 m_sample; /* current sample value */ /* ROM access */ + optional_memory_region m_rom_region; /* ROM data region which may or may not be present */ UINT8 * m_rom; /* pointer to ROM data or NULL for slave mode */ UINT8 * m_rombase; /* pointer to ROM data or NULL for slave mode */ UINT32 m_romoffset; /* ROM offset to make save/restore easier */ diff --git a/src/devices/sound/ymz280b.cpp b/src/devices/sound/ymz280b.cpp index 02c0283b4ae..fad4f1b7558 100644 --- a/src/devices/sound/ymz280b.cpp +++ b/src/devices/sound/ymz280b.cpp @@ -581,10 +581,15 @@ void ymz280b_device::device_start() /* initialize the rest of the structure */ m_master_clock = (double)clock() / 384.0; - m_mem_base = region()->base(); - m_mem_size = region()->bytes(); m_irq_handler.resolve(); + if (region() != NULL) + { + /* Some systems (e.g. Konami Firebeat) have a YMZ280B on-board that isn't hooked up to ROM, so be safe. */ + m_mem_base = region()->base(); + m_mem_size = region()->bytes(); + } + for (int i = 0; i < 8; i++) { m_voice[i].timer = timer_alloc(i); |