diff options
author | MooglyGuy <MooglyGuy@users.noreply.github.com> | 2022-06-04 09:14:21 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-04 17:14:21 +1000 |
commit | 1bc5484698bb746c6f9f7dae58b005d2472f1215 (patch) | |
tree | 54d6a10bc728cc7ce9858d771788a595e324141c /src/devices/sound | |
parent | cd83335913a6cfe4aa2db720692fa34487b1d7a3 (diff) |
- Removed device_timer, device_timer_id, et al in favor of direct callback members. (#9788)
Primarily, this removes device_t::device_timer, device_t::timer_set,
device_t::synchronize, device_t::timer_expired, and device_timer_id.
Use of device_timer often resulted in unnecessary trampolining in
addition to switch/case overhead on a driver/device level, and
additional logic to manage delegated vs. ID-based timers on a core
level. In the worst cases, devices were performing a switch/case with
only one valid case.
device_scheduler::timer_set is marked deprecated as the only remaining
direct uses are via the Lua engine and a few drivers that need
refactoring anyway. The remaining uses occur via
device_scheduler::synchronize.
As a middle ground between the extremely short timer_alloc() and the
extremely long
machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(widget_device::contoso_tick), this)),
a helper function in device_t has been added which can be invoked with
the following syntax:
timer_alloc(FUNC(widget_device::contoso_tick), this)
- Additional changes/cleanups performed along the way:
- Converted to use logmacro:
* src/devices/bus/ieee488/hp9895.cpp
* src/devices/bus/ieee488/remote488.cpp
* src/devices/bus/isa/hdc.cpp
* src/devices/bus/isa/omti8621.cpp
* src/devices/bus/isa/sc499.cpp
* src/devices/bus/vip/vp550.cpp
* src/devices/cpu/i86/i186.cpp
* src/devices/cpu/lc8670/lc8670.cpp
* src/devices/machine/68230pit.cpp
* src/devices/machine/corvushd.cpp
* src/devices/machine/ds1994.cpp
* src/devices/machine/ticket.cpp
* src/mame/audio/pinsnd88.cpp
* src/mame/drivers/notetaker.cpp
* src/mame/machine/asic65.cpp
* src/mame/machine/rmnimbus.cpp
* src/mame/machine/victor9k_fdc.cpp
* src/mame/video/uv201.cpp
- Made usage of m_member prefix consistent:
* src/devices/bus/isa/hdc.cpp
* src/devices/bus/isa/omti8621.cpp
* src/devices/bus/vme/vme_fccpu20.cpp
* src/devices/machine/ds1386.cpp
* src/devices/machine/i7220.cpp
- Spacing consistency pass:
* src/devices/bus/isa/hdc.cpp
* src/devices/bus/isa/omti8621.cpp
* src/devices/bus/thomson/nanoresau.cpp
* src/devices/bus/ti99/internal/992board.cpp
* src/devices/bus/ti99/internal/genkbd.cpp
* src/devices/bus/ti99/internal/joyport/handset.cpp
* src/devices/bus/vme/vme_fccpu20.cpp
* src/devices/cpu/i86/i186.cpp
* src/devices/cpu/lc8670/lc8670.cpp
* src/devices/machine/68230pit.cpp
* src/devices/machine/cop452.cpp
* src/devices/machine/corvushd.cpp
* src/devices/machine/hp_dc100_tape.cpp
* src/devices/machine/hp_taco.cpp
* src/devices/machine/meters.cpp
* src/devices/machine/microtch.cpp
* src/devices/machine/phi.cpp
* src/devices/video/ef9365.cpp
* src/devices/video/v9938.cpp
* src/mame/drivers/alphaskop41xx.cpp
* src/mame/drivers/myb3k.cpp
* src/mame/drivers/notetaker.cpp
* src/mame/drivers/wpc_an.cpp
* src/mame/machine/midikbd.cpp
* src/mame/machine/rmnimbus.cpp
* src/mame/machine/wpc_lamp.cpp
* src/mame/machine/wpc_out.cpp
- Removed string-based ioport lookups:
* src/devices/bus/ti99/internal/joyport/handset.cpp
* src/devices/bus/ti99/internal/joyport/mecmouse.cpp
* src/devices/bus/vme/vme_hcpu30.cpp
* src/mame/machine/k7659kb.cpp
* src/mame/machine/ti85.cpp
- Adjustments to grammar/wording in comments
* src/devices/bus/sms_ctrl/lphaser.cpp
* src/devices/bus/sms_ctrl/sports.cpp
* src/devices/bus/snes/event.cpp
* src/devices/bus/snes/sa1.cpp
* src/devices/bus/thomson/nanoresau.cpp
* src/devices/bus/z88/z88.cpp
* src/devices/machine/ds1386.cpp
* src/devices/machine/vic_pl192.cpp
- Favored BIT() macro for single-bit checks
* src/devices/bus/ti99/internal/992board.cpp
* src/devices/bus/ti99/joyport/handset.cpp
* src/mame/drivers/notetaker.cpp
* src/mame/machine/wpc_lamp.cpp
* src/mame/machine/wpc_out.cpp
- Removed C89-style variable declarations when noticed
* src/devices/bus/isa/hdc.cpp
* src/devices/bus/sms_ctrl/lphaser.cpp
* src/devices/bus/ti99/joyport/mecmouse.cpp
* src/devices/machine/acorn_vidc.cpp
* src/devices/sound/ymz280b.cpp
* src/devices/video/vic4567.cpp
- Removed FUNCNAME to avoid compiler-specific #define checks in devices
* src/devices/bus/vme/vme_fccpu20.cpp
* src/devices/bus/vme/vme_hcpu30.cpp
* src/devices/machine/68230pit.cpp
* src/devices/machine/mc14411.cpp
* src/mame/drivers/myb3k.cpp
- Removed unecessary member prefixes/suffixes
* src/devices/video/ef9340_1.cpp
* src/mame/drivers/fuukifg2.cpp
* src/mame/drivers/fuukifg3.cpp
* src/mame/drivers/intv.cpp
* src/mame/drivers/simpsons.cpp
* src/mame/drivers/socrates.cpp
* src/mame/drivers/special_gambl.cpp
* src/mame/drivers/sprint4.cpp
* src/mame/drivers/ti990_10.cpp
* src/mame/drivers/tubep.cpp
* src/mame/drivers/vectrex.cpp
* src/mame/drivers/wpc_an.cpp
* src/mame/drivers/wpc_dot.cpp
* src/mame/drivers/wpc_flip1.cpp
* src/mame/drivers/wpc_flip2.cpp
* src/mame/machine/z80ne.cpp
* src/mame/video/rollerg.cpp
- Switched to lower-case hex constants
* src/devices/video/ef9365.cpp
* src/mame/machine/rmnimbus.cpp
- Re-ordered driver overrides and function members
* src/mame/drivers/boxer.cpp
* src/mame/drivers/eurocom2.cpp
* src/mame/drivers/exidy.cpp
* src/mame/drivers/gpworld.cpp
* src/mame/drivers/h19.cpp
* src/mame/drivers/ibmpcjr.cpp
* src/mame/drivers/mekd5.cpp
* src/mame/drivers/mgolf.cpp
* src/mame/drivers/myb3k.cpp
* src/mame/drivers/nightmare.cpp
* src/mame/drivers/notetaker.cpp
* src/mame/drivers/ptcsol.cpp
* src/mame/drivers/pwrview.cpp
* src/mame/drivers/rabbit.cpp
* src/mame/drivers/sitcom.cpp
* src/mame/drivers/socrates.cpp
* src/mame/drivers/sprint4.cpp
* src/mame/drivers/techno.cpp
* src/mame/drivers/thayers.cpp
* src/mame/drivers/ti990_10.cpp
* src/mame/drivers/ti990_4.cpp
* src/mame/drivers/tv912.cpp
* src/mame/drivers/tv990.cpp
* src/mame/drivers/uchroma68.cpp
* src/mame/drivers/vk100.cpp
* src/mame/drivers/votrhv.cpp
* src/mame/drivers/wicat.cpp
* src/mame/drivers/wpc_an.cpp
* src/mame/includes/abc80.h
* src/mame/includes/asterix.h
* src/mame/includes/fuukifg2.h
* src/mame/includes/fuukifg3.h
* src/mame/includes/gunbustr.h
* src/mame/includes/intv.h
* src/mame/includes/namcona1.h
* src/mame/includes/newbrain.h
* src/mame/includes/poly.h
* src/mame/includes/prof80.h
* src/mame/includes/rollerg.h
* src/mame/includes/s11.h
* src/mame/includes/segahang.h
* src/mame/includes/simpsons.h
* src/mame/includes/spacefb.h
* src/mame/includes/tandy2k.h
* src/mame/includes/trucocl.h
* src/mame/includes/tubebp.h
* src/mame/includes/vidbrain.h
* src/mame/includes/wolfpack.h
* src/mame/includes/wpc_dot.h
- Made capitalization consistent on class members
* src/devices/machine/meters.cpp
* src/mame/drivers/namcona1.cpp
* src/mame/drivers/notetaker.cpp
-src/devices/bus/isa/hdc.cpp:
* Removed fixed-size std::vector in favor of std::unique_ptr
-src/devices/bus/isa/s3virge.cpp:
* Moved unusually large (for a header) functions into .cpp from header
-src/devices/bus/vip/vp550.cpp
* Switched to required_device_array to simplify code paths
-src/devices/machine/arm_iomd.cpp
* Added initializers to constructor
* Favored std::size over fixed static sizes
-src/devices/machine/ds1386.cpp
* Moved register #defines into header enums
-src/devices/machine/mc68901.cpp
* Removed unnecessary parameters and emu_timer::enable calls
-src/devices/machine/mccs1850.cpp
* Removed inline overuse
-src/devices/machine/meters.cpp
* Removed unused members
-src/devices/machine/mos6526.cpp
* Removed inline overuse
-src/devices/machine/nsc810.cpp
* Converted to arrays rather than individually-numbered members
-src/devices/machine/pxa255.cpp
* Simplified DMA transfer code
-src/devices/machine/saa1043.cpp
* Removed extraneous members in favor of resolve_all_safe
-src/devices/machine/vic_pl192.cpp
* Shifted constructors, start-up, and maps to be at the top of the source file
-src/devices/machine/z8536.cpp
* Removed stray uses of device_timer_id
-src/devices/sound/cdp1869.cpp
* Removed inline overuse
-src/devices/sound/mos7360.cpp
* Converted to arrays rather than individually-numbered members
-src/emu/device.cpp
* Removed ID-based timer_alloc
* Removed timer_set
* Removed synchronize
* Removed timer_expired
* Added shorthand timer_alloc to avoid lengthy machine().scheduler().timer_alloc() calls
-src/emu/schedule.cpp
* Removed now-unused m_id and m_device members
-src/mame/audio/alesis.cpp
* Added initializers to constructor
-src/mame/drivers/alto2.cpp
* Removed custom-named driver init in favor of driver_init override
* Removed octal constant in favor of more standard hex
-src/mame/drivers/astinvad.cpp
* Fixed 'kamizake' typo
-src/mame/drivers/tm990189.cpp
* Removed unnecessary machine reset override
-src/mame/drivers/unichamp.cpp
* Removed custom-named driver init in favor of driver_init override
-src/mame/drivers/votrhv.cpp
* Fixed ROM_LOAD macros and region() usage in memory maps
-src/mame/machine/victor9k_fdc.cpp
* Made bracing style consistent across the file
-src/mame/video/gime.cpp
* Removed unnecessary void specifiers in function prototypes
Diffstat (limited to 'src/devices/sound')
63 files changed, 567 insertions, 690 deletions
diff --git a/src/devices/sound/ad1848.cpp b/src/devices/sound/ad1848.cpp index 414edc6ecb0..7c62b4912ef 100644 --- a/src/devices/sound/ad1848.cpp +++ b/src/devices/sound/ad1848.cpp @@ -32,7 +32,7 @@ void ad1848_device::device_add_mconfig(machine_config &config) void ad1848_device::device_start() { - m_timer = timer_alloc(0); + m_timer = timer_alloc(FUNC(ad1848_device::update_tick), this); m_irq_cb.resolve_safe(); m_drq_cb.resolve_safe(); save_item(NAME(m_regs.idx)); @@ -156,7 +156,7 @@ void ad1848_device::dack_w(uint8_t data) m_drq_cb(CLEAR_LINE); } -void ad1848_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(ad1848_device::update_tick) { if(!m_play) return; diff --git a/src/devices/sound/ad1848.h b/src/devices/sound/ad1848.h index ad50c964556..1fd354c3427 100644 --- a/src/devices/sound/ad1848.h +++ b/src/devices/sound/ad1848.h @@ -24,9 +24,9 @@ public: protected: virtual void device_start() override; virtual void device_reset() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; virtual void device_add_mconfig(machine_config &config) override; + TIMER_CALLBACK_MEMBER(update_tick); private: union { diff --git a/src/devices/sound/aica.cpp b/src/devices/sound/aica.cpp index 235ce7a5acc..a746f80eae0 100644 --- a/src/devices/sound/aica.cpp +++ b/src/devices/sound/aica.cpp @@ -444,9 +444,9 @@ void aica_device::Init() space().specific(m_DSP.space); space().cache(m_DSP.cache); - m_timerA = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(aica_device::timerA_cb), this)); - m_timerB = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(aica_device::timerB_cb), this)); - m_timerC = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(aica_device::timerC_cb), this)); + m_timerA = timer_alloc(FUNC(aica_device::timerA_cb), this); + m_timerB = timer_alloc(FUNC(aica_device::timerB_cb), this); + m_timerC = timer_alloc(FUNC(aica_device::timerC_cb), this); for (i = 0; i < 0x400; ++i) { diff --git a/src/devices/sound/asc.cpp b/src/devices/sound/asc.cpp index aee85be2d45..255d6043dcf 100644 --- a/src/devices/sound/asc.cpp +++ b/src/devices/sound/asc.cpp @@ -66,7 +66,7 @@ void asc_device::device_start() memset(m_regs, 0, sizeof(m_regs)); - m_timer = timer_alloc(0); + m_timer = timer_alloc(FUNC(asc_device::delayed_stream_update), this); save_item(NAME(m_fifo_a_rdptr)); save_item(NAME(m_fifo_b_rdptr)); @@ -104,10 +104,10 @@ void asc_device::device_reset() } //------------------------------------------------- -// device_timer - called when our device timer expires +// delayed_stream_update - //------------------------------------------------- -void asc_device::device_timer(emu_timer &timer, device_timer_id tid, int param) +TIMER_CALLBACK_MEMBER(asc_device::delayed_stream_update) { m_stream->update(); } diff --git a/src/devices/sound/asc.h b/src/devices/sound/asc.h index c6293366f1c..591c95d71af 100644 --- a/src/devices/sound/asc.h +++ b/src/devices/sound/asc.h @@ -76,10 +76,11 @@ protected: // 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) override; virtual void sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) override; + TIMER_CALLBACK_MEMBER(delayed_stream_update); + devcb_write_line write_irq; sound_stream *m_stream; diff --git a/src/devices/sound/bsmt2000.cpp b/src/devices/sound/bsmt2000.cpp index 5ffa2209c66..ee7e4e4ee86 100644 --- a/src/devices/sound/bsmt2000.cpp +++ b/src/devices/sound/bsmt2000.cpp @@ -126,6 +126,11 @@ void bsmt2000_device::device_start() save_item(NAME(m_left_data)); save_item(NAME(m_right_data)); save_item(NAME(m_write_pending)); + + // allocate timers + m_deferred_reset = timer_alloc(FUNC(bsmt2000_device::deferred_reset), this); + m_deferred_reg_write = timer_alloc(FUNC(bsmt2000_device::deferred_reg_write), this); + m_deferred_data_write = timer_alloc(FUNC(bsmt2000_device::deferred_data_write), this); } @@ -135,41 +140,47 @@ void bsmt2000_device::device_start() void bsmt2000_device::device_reset() { - synchronize(TIMER_ID_RESET); + m_deferred_reset->adjust(attotime::zero); +} + + + +//------------------------------------------------- +// deferred_reset - +//------------------------------------------------- + +TIMER_CALLBACK_MEMBER(bsmt2000_device::deferred_reset) +{ + m_stream->update(); + m_cpu->reset(); } //------------------------------------------------- -// device_timer - handle deferred writes and -// resets as a timer callback +// deferred_reg_write - //------------------------------------------------- -void bsmt2000_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(bsmt2000_device::deferred_reg_write) { - switch (id) - { - // deferred reset - case TIMER_ID_RESET: - m_stream->update(); - m_cpu->reset(); - break; - - // deferred register write - case TIMER_ID_REG_WRITE: - m_register_select = param & 0xffff; - break; - - // deferred data write - case TIMER_ID_DATA_WRITE: - m_write_data = param & 0xffff; - if (m_write_pending) logerror("BSMT2000: Missed data\n"); - m_write_pending = true; - break; - } + m_register_select = param & 0xffff; } + +//------------------------------------------------- +// deferred_data_write - +//------------------------------------------------- + +TIMER_CALLBACK_MEMBER(bsmt2000_device::deferred_data_write) +{ + m_write_data = param & 0xffff; + if (m_write_pending) logerror("BSMT2000: Missed data\n"); + m_write_pending = true; +} + + + //------------------------------------------------- // sound_stream_update - handle update requests // for our sound stream @@ -211,7 +222,7 @@ uint16_t bsmt2000_device::read_status() void bsmt2000_device::write_reg(uint16_t data) { - synchronize(TIMER_ID_REG_WRITE, data); + m_deferred_reg_write->adjust(attotime::zero, data); } @@ -222,7 +233,7 @@ void bsmt2000_device::write_reg(uint16_t data) void bsmt2000_device::write_data(uint16_t data) { - synchronize(TIMER_ID_DATA_WRITE, data); + m_deferred_data_write->adjust(attotime::zero, data); // boost the interleave on a write so that the caller detects the status more accurately machine().scheduler().boost_interleave(attotime::from_usec(1), attotime::from_usec(10)); diff --git a/src/devices/sound/bsmt2000.h b/src/devices/sound/bsmt2000.h index abf084d7ae1..777a06c8ac6 100644 --- a/src/devices/sound/bsmt2000.h +++ b/src/devices/sound/bsmt2000.h @@ -50,7 +50,6 @@ protected: virtual void device_add_mconfig(machine_config &config) override; virtual void device_start() override; virtual void device_reset() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; // device_sound_interface overrides virtual void sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) override; @@ -58,6 +57,10 @@ protected: // device_rom_interface overrides virtual void rom_bank_updated() override; + TIMER_CALLBACK_MEMBER(deferred_reset); + TIMER_CALLBACK_MEMBER(deferred_reg_write); + TIMER_CALLBACK_MEMBER(deferred_data_write); + public: // internal TMS I/O callbacks uint16_t tms_register_r(); @@ -72,7 +75,6 @@ private: // timers enum { - TIMER_ID_RESET, TIMER_ID_REG_WRITE, TIMER_ID_DATA_WRITE }; @@ -83,13 +85,16 @@ private: // internal state sound_stream * m_stream; required_device<tms32015_device> m_cpu; - uint16_t m_register_select; - uint16_t m_write_data; - uint16_t m_rom_address; - uint16_t m_rom_bank; - int16_t m_left_data; - int16_t m_right_data; + uint16_t m_register_select; + uint16_t m_write_data; + uint16_t m_rom_address; + uint16_t m_rom_bank; + int16_t m_left_data; + int16_t m_right_data; bool m_write_pending; + emu_timer * m_deferred_reset; + emu_timer * m_deferred_reg_write; + emu_timer * m_deferred_data_write; DECLARE_READ_LINE_MEMBER( tms_write_pending_r ); }; diff --git a/src/devices/sound/c140.cpp b/src/devices/sound/c140.cpp index b04a35a0f31..28eea0d508b 100644 --- a/src/devices/sound/c140.cpp +++ b/src/devices/sound/c140.cpp @@ -117,7 +117,7 @@ void c140_device::device_start() m_sample_rate = m_baserate = clock(); m_int1_callback.resolve_safe(); - m_int1_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(c140_device::int1_on), this)); + m_int1_timer = timer_alloc(FUNC(c140_device::int1_on), this); m_stream = stream_alloc(0, 2, m_sample_rate); diff --git a/src/devices/sound/cdp1864.cpp b/src/devices/sound/cdp1864.cpp index 87b5ea830d0..a3e8f5c037f 100644 --- a/src/devices/sound/cdp1864.cpp +++ b/src/devices/sound/cdp1864.cpp @@ -122,10 +122,9 @@ void cdp1864_device::device_start() m_stream = stream_alloc(0, 1, SAMPLE_RATE_OUTPUT_ADAPTIVE); // allocate timers - m_int_timer = timer_alloc(TIMER_INT); - m_efx_timer = timer_alloc(TIMER_EFX); - m_dma_timer = timer_alloc(TIMER_DMA); - m_hsync_timer = timer_alloc(TIMER_HSYNC); + m_int_timer = timer_alloc(FUNC(cdp1864_device::int_tick), this); + m_efx_timer = timer_alloc(FUNC(cdp1864_device::efx_tick), this); + m_dma_timer = timer_alloc(FUNC(cdp1864_device::dma_tick), this); // find devices screen().register_screen_bitmap(m_bitmap); @@ -163,91 +162,88 @@ void cdp1864_device::device_reset() //------------------------------------------------- -// device_timer - handle timer events +// timer events //------------------------------------------------- -void cdp1864_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(cdp1864_device::int_tick) { - int scanline = screen().vpos(); - - switch (id) + if (screen().vpos() == SCANLINE_INT_START) { - case TIMER_INT: - if (scanline == SCANLINE_INT_START) + if (m_disp) { - if (m_disp) - { - m_write_int(ASSERT_LINE); - } - - m_int_timer->adjust(screen().time_until_pos(SCANLINE_INT_END, 0)); + m_write_int(ASSERT_LINE); } - else - { - if (m_disp) - { - m_write_int(CLEAR_LINE); - } - m_int_timer->adjust(screen().time_until_pos(SCANLINE_INT_START, 0)); + m_int_timer->adjust(screen().time_until_pos(SCANLINE_INT_END, 0)); + } + else + { + if (m_disp) + { + m_write_int(CLEAR_LINE); } + + m_int_timer->adjust(screen().time_until_pos(SCANLINE_INT_START, 0)); + } +} + +TIMER_CALLBACK_MEMBER(cdp1864_device::efx_tick) +{ + int scanline = screen().vpos(); + switch (scanline) + { + case SCANLINE_EFX_TOP_START: + m_write_efx(ASSERT_LINE); + m_efx_timer->adjust(screen().time_until_pos(SCANLINE_EFX_TOP_END, 0)); break; - case TIMER_EFX: - switch (scanline) - { - case SCANLINE_EFX_TOP_START: - m_write_efx(ASSERT_LINE); - m_efx_timer->adjust(screen().time_until_pos(SCANLINE_EFX_TOP_END, 0)); - break; - - case SCANLINE_EFX_TOP_END: - m_write_efx(CLEAR_LINE); - m_efx_timer->adjust(screen().time_until_pos(SCANLINE_EFX_BOTTOM_START, 0)); - break; - - case SCANLINE_EFX_BOTTOM_START: - m_write_efx(ASSERT_LINE); - m_efx_timer->adjust(screen().time_until_pos(SCANLINE_EFX_BOTTOM_END, 0)); - break; - - case SCANLINE_EFX_BOTTOM_END: - m_write_efx(CLEAR_LINE); - m_efx_timer->adjust(screen().time_until_pos(SCANLINE_EFX_TOP_START, 0)); - break; - } + case SCANLINE_EFX_TOP_END: + m_write_efx(CLEAR_LINE); + m_efx_timer->adjust(screen().time_until_pos(SCANLINE_EFX_BOTTOM_START, 0)); + break; + + case SCANLINE_EFX_BOTTOM_START: + m_write_efx(ASSERT_LINE); + m_efx_timer->adjust(screen().time_until_pos(SCANLINE_EFX_BOTTOM_END, 0)); + break; + + case SCANLINE_EFX_BOTTOM_END: + m_write_efx(CLEAR_LINE); + m_efx_timer->adjust(screen().time_until_pos(SCANLINE_EFX_TOP_START, 0)); break; + } +} - case TIMER_DMA: - if (m_dmaout) +TIMER_CALLBACK_MEMBER(cdp1864_device::dma_tick) +{ + int scanline = screen().vpos(); + if (m_dmaout) + { + if (m_disp) { - if (m_disp) + if (scanline >= SCANLINE_DISPLAY_START && scanline < SCANLINE_DISPLAY_END) { - if (scanline >= SCANLINE_DISPLAY_START && scanline < SCANLINE_DISPLAY_END) - { - m_write_dma_out(CLEAR_LINE); - } + m_write_dma_out(CLEAR_LINE); } + } - m_dma_timer->adjust(clocks_to_attotime(CDP1864_CYCLES_DMA_WAIT)); + m_dma_timer->adjust(clocks_to_attotime(CDP1864_CYCLES_DMA_WAIT)); - m_dmaout = 0; - } - else + m_dmaout = 0; + } + else + { + if (m_disp) { - if (m_disp) + if (scanline >= SCANLINE_DISPLAY_START && scanline < SCANLINE_DISPLAY_END) { - if (scanline >= SCANLINE_DISPLAY_START && scanline < SCANLINE_DISPLAY_END) - { - m_write_dma_out(ASSERT_LINE); - } + m_write_dma_out(ASSERT_LINE); } + } - m_dma_timer->adjust(clocks_to_attotime(CDP1864_CYCLES_DMA_ACTIVE)); + m_dma_timer->adjust(clocks_to_attotime(CDP1864_CYCLES_DMA_ACTIVE)); - m_dmaout = 1; - } - break; + m_dmaout = 1; } } diff --git a/src/devices/sound/cdp1864.h b/src/devices/sound/cdp1864.h index db2bd156f3a..8dc1eb04e8e 100644 --- a/src/devices/sound/cdp1864.h +++ b/src/devices/sound/cdp1864.h @@ -112,20 +112,15 @@ protected: virtual void device_config_complete() override; virtual void device_start() override; virtual void device_reset() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; // internal callbacks virtual void sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) override; -private: - enum - { - TIMER_INT, - TIMER_EFX, - TIMER_DMA, - TIMER_HSYNC - }; + TIMER_CALLBACK_MEMBER(int_tick); + TIMER_CALLBACK_MEMBER(efx_tick); + TIMER_CALLBACK_MEMBER(dma_tick); +private: void initialize_palette(); static constexpr int bckgnd[4] = { 2, 0, 4, 1 }; @@ -164,7 +159,6 @@ private: emu_timer *m_int_timer; emu_timer *m_efx_timer; emu_timer *m_dma_timer; - emu_timer *m_hsync_timer; }; diff --git a/src/devices/sound/cdp1869.cpp b/src/devices/sound/cdp1869.cpp index ac7533ac316..70e4718f212 100644 --- a/src/devices/sound/cdp1869.cpp +++ b/src/devices/sound/cdp1869.cpp @@ -95,14 +95,36 @@ void cdp1869_device::cdp1869(address_map &map) //************************************************************************** -// INLINE HELPERS +// DEVICE FUNCTIONS //************************************************************************** //------------------------------------------------- +// get_rgb - get RGB value +//------------------------------------------------- + +rgb_t cdp1869_device::get_rgb(int i, int c, int l) +{ + int luma = 0; + + luma += (l & 4) ? CDP1869_WEIGHT_RED : 0; + luma += (l & 1) ? CDP1869_WEIGHT_GREEN : 0; + luma += (l & 2) ? CDP1869_WEIGHT_BLUE : 0; + + luma = (luma * 0xff) / 100; + + int const r = (c & 4) ? luma : 0; + int const g = (c & 1) ? luma : 0; + int const b = (c & 2) ? luma : 0; + + return rgb_t(r, g, b); +} + + +//------------------------------------------------- // is_ntsc - is device in NTSC mode //------------------------------------------------- -inline bool cdp1869_device::is_ntsc() +bool cdp1869_device::is_ntsc() { return m_read_pal_ntsc() ? false : true; } @@ -113,7 +135,7 @@ inline bool cdp1869_device::is_ntsc() // the given address //------------------------------------------------- -inline uint8_t cdp1869_device::read_page_ram_byte(offs_t pma) +uint8_t cdp1869_device::read_page_ram_byte(offs_t pma) { return space().read_byte(pma); } @@ -124,7 +146,7 @@ inline uint8_t cdp1869_device::read_page_ram_byte(offs_t pma) // the given address //------------------------------------------------- -inline void cdp1869_device::write_page_ram_byte(offs_t pma, uint8_t data) +void cdp1869_device::write_page_ram_byte(offs_t pma, uint8_t data) { space().write_byte(pma, data); } @@ -135,7 +157,7 @@ inline void cdp1869_device::write_page_ram_byte(offs_t pma, uint8_t data) // the given address //------------------------------------------------- -inline uint8_t cdp1869_device::read_char_ram_byte(offs_t pma, offs_t cma, uint8_t pmd) +uint8_t cdp1869_device::read_char_ram_byte(offs_t pma, offs_t cma, uint8_t pmd) { uint8_t data = 0; @@ -153,7 +175,7 @@ inline uint8_t cdp1869_device::read_char_ram_byte(offs_t pma, offs_t cma, uint8_ // the given address //------------------------------------------------- -inline void cdp1869_device::write_char_ram_byte(offs_t pma, offs_t cma, uint8_t pmd, uint8_t data) +void cdp1869_device::write_char_ram_byte(offs_t pma, offs_t cma, uint8_t pmd, uint8_t data) { if (!m_out_char_ram_func.isnull()) { @@ -166,7 +188,7 @@ inline void cdp1869_device::write_char_ram_byte(offs_t pma, offs_t cma, uint8_t // read_pcb - read page control bit //------------------------------------------------- -inline int cdp1869_device::read_pcb(offs_t pma, offs_t cma, uint8_t pmd) +int cdp1869_device::read_pcb(offs_t pma, offs_t cma, uint8_t pmd) { int pcb = 0; @@ -183,7 +205,7 @@ inline int cdp1869_device::read_pcb(offs_t pma, offs_t cma, uint8_t pmd) // update_prd_changed_timer - //------------------------------------------------- -inline void cdp1869_device::update_prd_changed_timer() +void cdp1869_device::update_prd_changed_timer() { int start = SCANLINE_PREDISPLAY_START_PAL; int end = SCANLINE_PREDISPLAY_END_PAL; @@ -224,32 +246,10 @@ inline void cdp1869_device::update_prd_changed_timer() //------------------------------------------------- -// get_rgb - get RGB value -//------------------------------------------------- - -inline rgb_t cdp1869_device::get_rgb(int i, int c, int l) -{ - int luma = 0; - - luma += (l & 4) ? CDP1869_WEIGHT_RED : 0; - luma += (l & 1) ? CDP1869_WEIGHT_GREEN : 0; - luma += (l & 2) ? CDP1869_WEIGHT_BLUE : 0; - - luma = (luma * 0xff) / 100; - - int const r = (c & 4) ? luma : 0; - int const g = (c & 1) ? luma : 0; - int const b = (c & 2) ? luma : 0; - - return rgb_t(r, g, b); -} - - -//------------------------------------------------- // get_lines - get number of character lines //------------------------------------------------- -inline int cdp1869_device::get_lines() +int cdp1869_device::get_lines() { if (m_line16 && !m_dblpage) { @@ -270,7 +270,7 @@ inline int cdp1869_device::get_lines() // get_pmemsize - get page memory size //------------------------------------------------- -inline uint16_t cdp1869_device::get_pmemsize(int cols, int rows) +uint16_t cdp1869_device::get_pmemsize(int cols, int rows) { int pmemsize = cols * rows; @@ -285,7 +285,7 @@ inline uint16_t cdp1869_device::get_pmemsize(int cols, int rows) // get_pma - get page memory address //------------------------------------------------- -inline uint16_t cdp1869_device::get_pma() +uint16_t cdp1869_device::get_pma() { if (m_dblpage) { @@ -302,7 +302,7 @@ inline uint16_t cdp1869_device::get_pma() // get_pen - get pen for color bits //------------------------------------------------- -inline int cdp1869_device::get_pen(int ccb0, int ccb1, int pcb) +int cdp1869_device::get_pen(int ccb0, int ccb1, int pcb) { int r = 0, g = 0, b = 0; @@ -392,7 +392,7 @@ void cdp1869_device::device_start() m_out_char_ram_func.resolve(); // allocate timers - m_prd_timer = timer_alloc(); + m_prd_timer = timer_alloc(FUNC(cdp1869_device::prd_update), this); m_dispoff = 0; update_prd_changed_timer(); @@ -456,10 +456,10 @@ void cdp1869_device::device_post_load() //------------------------------------------------- -// device_timer - handler timer events +// prd_update - //------------------------------------------------- -void cdp1869_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(cdp1869_device::prd_update) { m_write_prd(param); m_prd = param; diff --git a/src/devices/sound/cdp1869.h b/src/devices/sound/cdp1869.h index e40a9705333..6ce373a6931 100644 --- a/src/devices/sound/cdp1869.h +++ b/src/devices/sound/cdp1869.h @@ -210,7 +210,6 @@ protected: virtual void device_add_mconfig(machine_config &config) override; virtual void device_start() override; virtual void device_post_load() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; // device_memory_interface overrides virtual space_config_vector memory_space_config() const override; @@ -218,18 +217,21 @@ protected: // device_sound_interface callbacks virtual void sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) override; - inline bool is_ntsc(); - inline uint8_t read_page_ram_byte(offs_t address); - inline void write_page_ram_byte(offs_t address, uint8_t data); - inline uint8_t read_char_ram_byte(offs_t pma, offs_t cma, uint8_t pmd); - inline void write_char_ram_byte(offs_t pma, offs_t cma, uint8_t pmd, uint8_t data); - inline int read_pcb(offs_t pma, offs_t cma, uint8_t pmd); - inline void update_prd_changed_timer(); + TIMER_CALLBACK_MEMBER(prd_update); + static rgb_t get_rgb(int i, int c, int l); - inline int get_lines(); - inline uint16_t get_pmemsize(int cols, int rows); - inline uint16_t get_pma(); - inline int get_pen(int ccb0, int ccb1, int pcb); + + bool is_ntsc(); + uint8_t read_page_ram_byte(offs_t address); + void write_page_ram_byte(offs_t address, uint8_t data); + uint8_t read_char_ram_byte(offs_t pma, offs_t cma, uint8_t pmd); + void write_char_ram_byte(offs_t pma, offs_t cma, uint8_t pmd, uint8_t data); + int read_pcb(offs_t pma, offs_t cma, uint8_t pmd); + void update_prd_changed_timer(); + int get_lines(); + uint16_t get_pmemsize(int cols, int rows); + uint16_t get_pma(); + int get_pen(int ccb0, int ccb1, int pcb); void draw_line(bitmap_rgb32 &bitmap, const rectangle &rect, int x, int y, uint8_t data, int color); void draw_char(bitmap_rgb32 &bitmap, const rectangle &rect, int x, int y, uint16_t pma); diff --git a/src/devices/sound/dave.cpp b/src/devices/sound/dave.cpp index 8a7386e640b..44719ab4584 100644 --- a/src/devices/sound/dave.cpp +++ b/src/devices/sound/dave.cpp @@ -83,10 +83,10 @@ void dave_device::device_start() m_write_rh.resolve_safe(); // allocate timers - m_timer_1hz = timer_alloc(TIMER_1HZ); + m_timer_1hz = timer_alloc(FUNC(dave_device::update_1hz_timer), this); m_timer_1hz->adjust(attotime::from_hz(2), 0, attotime::from_hz(2)); - m_timer_50hz = timer_alloc(TIMER_50HZ); + m_timer_50hz = timer_alloc(FUNC(dave_device::update_50hz_timer), this); m_timer_50hz->adjust(attotime::from_hz(2000), 0, attotime::from_hz(2000)); // state saving @@ -146,27 +146,30 @@ void dave_device::device_reset() //------------------------------------------------- -// device_timer - handler timer events +// update_1hz_timer - //------------------------------------------------- -void dave_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(dave_device::update_1hz_timer) { - switch (id) - { - case TIMER_1HZ: - m_irq_status ^= IRQ_1HZ_DIVIDER; + m_irq_status ^= IRQ_1HZ_DIVIDER; - if (m_irq_status & IRQ_1HZ_DIVIDER) - m_irq_status |= IRQ_1HZ_LATCH; - break; + if (m_irq_status & IRQ_1HZ_DIVIDER) + m_irq_status |= IRQ_1HZ_LATCH; - case TIMER_50HZ: - m_irq_status ^= IRQ_50HZ_DIVIDER; + update_interrupt(); +} - if (m_irq_status & IRQ_50HZ_DIVIDER) - m_irq_status |= IRQ_50HZ_LATCH; - break; - } + +//------------------------------------------------- +// update_50hz_timer - +//------------------------------------------------- + +TIMER_CALLBACK_MEMBER(dave_device::update_50hz_timer) +{ + m_irq_status ^= IRQ_50HZ_DIVIDER; + + if (m_irq_status & IRQ_50HZ_DIVIDER) + m_irq_status |= IRQ_50HZ_LATCH; update_interrupt(); } diff --git a/src/devices/sound/dave.h b/src/devices/sound/dave.h index 7a6a521738f..82c024f748e 100644 --- a/src/devices/sound/dave.h +++ b/src/devices/sound/dave.h @@ -41,7 +41,6 @@ protected: // 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) override; // device_memory_interface overrides virtual space_config_vector memory_space_config() const override; @@ -49,6 +48,9 @@ protected: // sound stream update overrides virtual void sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) override; + TIMER_CALLBACK_MEMBER(update_1hz_timer); + TIMER_CALLBACK_MEMBER(update_50hz_timer); + uint8_t program_r(offs_t offset); void program_w(offs_t offset, uint8_t data); @@ -58,12 +60,6 @@ protected: private: enum { - TIMER_1HZ, - TIMER_50HZ - }; - - enum - { IRQ_50HZ_DIVIDER = 0x01, IRQ_50HZ_LATCH = 0x02, IRQ_1HZ_DIVIDER = 0x04, diff --git a/src/devices/sound/es1373.cpp b/src/devices/sound/es1373.cpp index d6baac9ad01..d254527b0bc 100644 --- a/src/devices/sound/es1373.cpp +++ b/src/devices/sound/es1373.cpp @@ -122,7 +122,7 @@ void es1373_device::device_start() // create the stream m_stream = stream_alloc(0, 2, 44100/2); - m_timer = timer_alloc(0); + m_timer = timer_alloc(FUNC(es1373_device::delayed_stream_update), this); m_timer->adjust(attotime::zero, 0, attotime::from_hz(44100/2/16)); // Save states @@ -222,9 +222,9 @@ void es1373_device::map_extra(uint64_t memory_window_start, uint64_t memory_wind } //------------------------------------------------- -// device_timer - called when our device timer expires +// delayed_stream_update - //------------------------------------------------- -void es1373_device::device_timer(emu_timer &timer, device_timer_id tid, int param) +TIMER_CALLBACK_MEMBER(es1373_device::delayed_stream_update) { m_stream->update(); } diff --git a/src/devices/sound/es1373.h b/src/devices/sound/es1373.h index ba246a05535..6d493391ae4 100644 --- a/src/devices/sound/es1373.h +++ b/src/devices/sound/es1373.h @@ -26,11 +26,12 @@ protected: virtual void device_start() override; virtual void device_stop() override; virtual void device_reset() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; virtual void device_add_mconfig(machine_config &config) override; virtual void device_post_load() override; virtual void sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) override; + TIMER_CALLBACK_MEMBER(delayed_stream_update); + // Sound stream sound_stream *m_stream; diff --git a/src/devices/sound/es5503.cpp b/src/devices/sound/es5503.cpp index 365254301b6..50bef4568d2 100644 --- a/src/devices/sound/es5503.cpp +++ b/src/devices/sound/es5503.cpp @@ -67,10 +67,10 @@ es5503_device::es5503_device(const machine_config &mconfig, const char *tag, dev //------------------------------------------------- -// device_timer - called when our device timer expires +// delayed_stream_update - //------------------------------------------------- -void es5503_device::device_timer(emu_timer &timer, device_timer_id tid, int param) +TIMER_CALLBACK_MEMBER(es5503_device::delayed_stream_update) { m_stream->update(); } @@ -235,7 +235,7 @@ void es5503_device::device_start() output_rate = (clock() / 8) / (oscsenabled + 2); m_stream = stream_alloc(0, output_channels, output_rate); - m_timer = timer_alloc(0); + m_timer = timer_alloc(FUNC(es5503_device::delayed_stream_update), this); } void es5503_device::device_clock_changed() diff --git a/src/devices/sound/es5503.h b/src/devices/sound/es5503.h index fde389ef250..153e0a79fe1 100644 --- a/src/devices/sound/es5503.h +++ b/src/devices/sound/es5503.h @@ -33,7 +33,6 @@ protected: virtual void device_start() override; virtual void device_clock_changed() override; virtual void device_reset() override; - virtual void device_timer(emu_timer &timer, device_timer_id tid, int param) override; // device_sound_interface overrides virtual void sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) override; @@ -41,6 +40,8 @@ protected: // device_rom_interface overrides virtual void rom_bank_updated() override; + TIMER_CALLBACK_MEMBER(delayed_stream_update); + sound_stream *m_stream; devcb_write_line m_irq_func; diff --git a/src/devices/sound/gb.cpp b/src/devices/sound/gb.cpp index a139b72ca3e..643ecf9ec68 100644 --- a/src/devices/sound/gb.cpp +++ b/src/devices/sound/gb.cpp @@ -143,7 +143,7 @@ cgb04_apu_device::cgb04_apu_device(const machine_config &mconfig, const char *ta void gameboy_sound_device::device_start() { m_channel = stream_alloc(0, 2, SAMPLE_RATE_OUTPUT_ADAPTIVE); - m_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(gameboy_sound_device::timer_callback),this)); + m_timer = timer_alloc(FUNC(gameboy_sound_device::timer_callback), this); m_timer->adjust(clocks_to_attotime(FRAME_CYCLES/128), 0, clocks_to_attotime(FRAME_CYCLES/128)); save_item(NAME(m_last_updated)); diff --git a/src/devices/sound/huc6230.cpp b/src/devices/sound/huc6230.cpp index ed297c36cf8..d257572f79e 100644 --- a/src/devices/sound/huc6230.cpp +++ b/src/devices/sound/huc6230.cpp @@ -181,7 +181,7 @@ void huc6230_device::device_start() m_vca_cb.resolve_safe(); m_stream = stream_alloc(2, 2, clock() / 6); - m_adpcm_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(huc6230_device::adpcm_timer),this)); + m_adpcm_timer = timer_alloc(FUNC(huc6230_device::adpcm_timer), this); for (int i = 0; i < 2; i++) { diff --git a/src/devices/sound/ics2115.cpp b/src/devices/sound/ics2115.cpp index 9eca1102f88..4b9f1ef152b 100644 --- a/src/devices/sound/ics2115.cpp +++ b/src/devices/sound/ics2115.cpp @@ -59,8 +59,8 @@ void ics2115_device::device_start() space(0).cache(m_cache); - m_timer[0].timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(ics2115_device::timer_cb_0),this)); - m_timer[1].timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(ics2115_device::timer_cb_1),this)); + m_timer[0].timer = timer_alloc(FUNC(ics2115_device::timer_cb_0), this); + m_timer[1].timer = timer_alloc(FUNC(ics2115_device::timer_cb_1), this); m_stream = stream_alloc(0, 2, clock() / (32 * 32)); m_irq_cb.resolve_safe(); diff --git a/src/devices/sound/iopspu.cpp b/src/devices/sound/iopspu.cpp index b2599eae2cd..55e6cd3b789 100644 --- a/src/devices/sound/iopspu.cpp +++ b/src/devices/sound/iopspu.cpp @@ -31,10 +31,10 @@ void iop_spu_device::device_start() m_ram = std::make_unique<uint16_t[]>(2 * 1024 * 1024); // ? if (!m_core[0].m_autodma_done_timer_hack) - m_core[0].m_autodma_done_timer_hack = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(iop_spu_device::autodma_done_timer_hack), this)); + m_core[0].m_autodma_done_timer_hack = timer_alloc(FUNC(iop_spu_device::autodma_done_timer_hack), this); if (!m_core[1].m_autodma_done_timer_hack) - m_core[1].m_autodma_done_timer_hack = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(iop_spu_device::autodma_done_timer_hack), this)); + m_core[1].m_autodma_done_timer_hack = timer_alloc(FUNC(iop_spu_device::autodma_done_timer_hack), this); save_item(NAME(m_core[0].m_status)); save_item(NAME(m_core[0].m_start_port_addr)); diff --git a/src/devices/sound/k053260.cpp b/src/devices/sound/k053260.cpp index b2e1e6cb0a0..9a85fa97811 100644 --- a/src/devices/sound/k053260.cpp +++ b/src/devices/sound/k053260.cpp @@ -126,7 +126,7 @@ void k053260_device::device_start() for (int i = 0; i < 4; i++) m_voice[i].voice_start(i); - m_timer = timer_alloc(0); + m_timer = timer_alloc(FUNC(k053260_device::update_state_outputs), this); } @@ -164,7 +164,7 @@ void k053260_device::rom_bank_updated() } -void k053260_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(k053260_device::update_state_outputs) { switch(m_timer_state) { case 0: m_sh1_cb(ASSERT_LINE); break; diff --git a/src/devices/sound/k053260.h b/src/devices/sound/k053260.h index dc8d918117e..401d3d2e34f 100644 --- a/src/devices/sound/k053260.h +++ b/src/devices/sound/k053260.h @@ -39,7 +39,6 @@ protected: virtual void device_start() override; virtual void device_clock_changed() override; virtual void device_reset() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; // sound stream update overrides virtual void sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) override; @@ -47,6 +46,8 @@ protected: // device_rom_interface overrides virtual void rom_bank_updated() override; + TIMER_CALLBACK_MEMBER(update_state_outputs); + private: // Pan multipliers static const int pan_mul[8][2]; diff --git a/src/devices/sound/k054539.cpp b/src/devices/sound/k054539.cpp index b30dbcbc724..ae0ac92e310 100644 --- a/src/devices/sound/k054539.cpp +++ b/src/devices/sound/k054539.cpp @@ -307,7 +307,7 @@ void k054539_device::sound_stream_update(sound_stream &stream, std::vector<read_ } -void k054539_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(k054539_device::call_timer_handler) { if (regs[0x22f] & 0x20) m_timer_handler(m_timer_state ^= 1); @@ -507,7 +507,7 @@ u8 k054539_device::read(offs_t offset) void k054539_device::device_start() { - m_timer = timer_alloc(0); + m_timer = timer_alloc(FUNC(k054539_device::call_timer_handler), this); // resolve / bind callbacks m_timer_handler.resolve_safe(); diff --git a/src/devices/sound/k054539.h b/src/devices/sound/k054539.h index c58f6021af3..406836af65a 100644 --- a/src/devices/sound/k054539.h +++ b/src/devices/sound/k054539.h @@ -64,7 +64,6 @@ protected: virtual void device_clock_changed() override; virtual void device_reset() override; virtual void device_post_load() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; // device_sound_interface overrides virtual void sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) override; @@ -72,6 +71,8 @@ protected: // device_rom_interface overrides virtual void rom_bank_updated() override; + TIMER_CALLBACK_MEMBER(call_timer_handler); + private: struct channel { uint32_t pos; diff --git a/src/devices/sound/ks0164.cpp b/src/devices/sound/ks0164.cpp index 99cb75ab878..f5c3c4d02e9 100644 --- a/src/devices/sound/ks0164.cpp +++ b/src/devices/sound/ks0164.cpp @@ -54,7 +54,7 @@ void ks0164_device::device_start() m_stream = stream_alloc(0, 2, clock()/3/2/2/32); space().cache(m_mem_cache); - m_timer = timer_alloc(0); + m_timer = timer_alloc(FUNC(ks0164_device::irq_timer_tick), this); m_midi_tx.resolve_safe(); @@ -98,7 +98,7 @@ void ks0164_device::device_reset() m_timer->adjust(attotime::from_msec(1), 0, attotime::from_msec(1)); } -void ks0164_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(ks0164_device::irq_timer_tick) { m_timer_interrupt = true; if(m_irqen_76 & 0x40) diff --git a/src/devices/sound/ks0164.h b/src/devices/sound/ks0164.h index 6024ae62669..208176c6e2e 100644 --- a/src/devices/sound/ks0164.h +++ b/src/devices/sound/ks0164.h @@ -30,12 +30,13 @@ protected: virtual void sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) override; virtual void device_add_mconfig(machine_config &config) override; virtual space_config_vector memory_space_config() const override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; virtual void tra_callback() override; virtual void tra_complete() override; virtual void rcv_complete() override; + TIMER_CALLBACK_MEMBER(irq_timer_tick); + private: enum { MPUS_RX_FULL = 0x01, diff --git a/src/devices/sound/mea8000.cpp b/src/devices/sound/mea8000.cpp index 3cf2ad51a6e..e557d046db4 100644 --- a/src/devices/sound/mea8000.cpp +++ b/src/devices/sound/mea8000.cpp @@ -137,7 +137,7 @@ void mea8000_device::device_start() m_stream = stream_alloc(0, 1, clock() / 60); save_item(NAME(m_output)); - m_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(mea8000_device::timer_expire),this)); + m_timer = timer_alloc(FUNC(mea8000_device::timer_expire), this); save_item(NAME(m_state)); save_item(NAME(m_buf)); diff --git a/src/devices/sound/mm5837.cpp b/src/devices/sound/mm5837.cpp index b9125b5c616..ae6687655f3 100644 --- a/src/devices/sound/mm5837.cpp +++ b/src/devices/sound/mm5837.cpp @@ -47,7 +47,7 @@ void mm5837_device::device_start() m_output_cb.resolve_safe(); // get timer - m_timer = timer_alloc(0); + m_timer = timer_alloc(FUNC(mm5837_device::update_clock_output), this); // register for save states save_item(NAME(m_source.m_shift)); @@ -70,10 +70,10 @@ void mm5837_device::device_reset() //------------------------------------------------- -// device_timer - handle timer callbacks +// update_clock_output - //------------------------------------------------- -void mm5837_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(mm5837_device::update_clock_output) { m_output_cb(m_source.clock()); } diff --git a/src/devices/sound/mm5837.h b/src/devices/sound/mm5837.h index 21d37596c45..df76f6171fd 100644 --- a/src/devices/sound/mm5837.h +++ b/src/devices/sound/mm5837.h @@ -168,7 +168,8 @@ protected: // 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) override; + + TIMER_CALLBACK_MEMBER(update_clock_output); private: // internal state diff --git a/src/devices/sound/mos6560.cpp b/src/devices/sound/mos6560.cpp index 1a007c80693..bd35429c31c 100644 --- a/src/devices/sound/mos6560.cpp +++ b/src/devices/sound/mos6560.cpp @@ -459,7 +459,7 @@ uint8_t mos6560_device::bus_r() mos6560_raster_interrupt_gen -------------------------------------------------*/ -void mos6560_device::raster_interrupt_gen() +TIMER_CALLBACK_MEMBER(mos6560_device::raster_interrupt_gen) { m_rasterline++; if (m_rasterline >= m_total_lines) @@ -760,7 +760,7 @@ void mos6560_device::device_start() } // allocate timers - m_line_timer = timer_alloc(TIMER_LINE); + m_line_timer = timer_alloc(FUNC(mos6560_device::raster_interrupt_gen), this); m_line_timer->adjust(screen().scan_period(), 0, screen().scan_period()); // initialize sound @@ -862,20 +862,6 @@ void mos6560_device::device_reset() //------------------------------------------------- -// device_timer - handler timer events -//------------------------------------------------- - -void mos6560_device::device_timer(emu_timer &timer, device_timer_id id, int param) -{ - switch (id) - { - case TIMER_LINE: - raster_interrupt_gen(); - break; - } -} - -//------------------------------------------------- // sound_stream_update - handle a stream update //------------------------------------------------- diff --git a/src/devices/sound/mos6560.h b/src/devices/sound/mos6560.h index eb902f5471e..fa950450389 100644 --- a/src/devices/sound/mos6560.h +++ b/src/devices/sound/mos6560.h @@ -121,7 +121,6 @@ protected: // 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) override; // sound stream update overrides virtual void sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) override; @@ -134,7 +133,7 @@ protected: void drawlines( int first, int last ); void soundport_w( int offset, int data ); void sound_start(); - void raster_interrupt_gen(); + TIMER_CALLBACK_MEMBER(raster_interrupt_gen); const int m_variant; diff --git a/src/devices/sound/mos7360.cpp b/src/devices/sound/mos7360.cpp index c4749b2fb9b..c76e1d8adb7 100644 --- a/src/devices/sound/mos7360.cpp +++ b/src/devices/sound/mos7360.cpp @@ -285,12 +285,12 @@ void mos7360_device::device_start() m_read_k.resolve_safe(0xff); // allocate timers - m_timer1 = timer_alloc(TIMER_ID_1); - m_timer2 = timer_alloc(TIMER_ID_2); - m_timer3 = timer_alloc(TIMER_ID_3); - m_line_timer = timer_alloc(TIMER_LINE); + m_timer[TIMER_ID_1] = timer_alloc(FUNC(mos7360_device::timer_expired), this); + m_timer[TIMER_ID_2] = timer_alloc(FUNC(mos7360_device::timer_expired), this); + m_timer[TIMER_ID_3] = timer_alloc(FUNC(mos7360_device::timer_expired), this); + m_line_timer = timer_alloc(FUNC(mos7360_device::raster_interrupt_gen), this); m_line_timer->adjust(screen().scan_period(), 0, screen().scan_period()); - m_frame_timer = timer_alloc(TIMER_FRAME); + m_frame_timer = timer_alloc(FUNC(mos7360_device::frame_interrupt_gen), this); m_frame_timer->adjust(screen().frame_period(), 0, screen().frame_period()); // allocate screen bitmap @@ -340,9 +340,7 @@ void mos7360_device::device_start() save_item(NAME(m_rom)); save_item(NAME(m_frame_count)); save_item(NAME(m_lines)); - save_item(NAME(m_timer1_active)); - save_item(NAME(m_timer2_active)); - save_item(NAME(m_timer3_active)); + save_item(NAME(m_timer_active)); save_item(NAME(m_cursor1)); save_item(NAME(m_chargenaddr)); save_item(NAME(m_bitmapaddr)); @@ -382,8 +380,10 @@ void mos7360_device::device_reset() m_rom = 1; // FIXME: at start should be RAM or ROM? old c16 code set it to ROM at init: is it correct? m_lines = TED7360_LINES; - m_chargenaddr = m_bitmapaddr = m_videoaddr = 0; - m_timer1_active = m_timer2_active = m_timer3_active = 0; + m_chargenaddr = 0; + m_bitmapaddr = 0; + m_videoaddr = 0; + std::fill(std::begin(m_timer_active), std::end(m_timer_active), false); m_cursor1 = 0; m_rasterline = 0; @@ -416,40 +416,25 @@ void mos7360_device::device_reset() //------------------------------------------------- -// device_timer - handler timer events +// timer_expired - //------------------------------------------------- -void mos7360_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(mos7360_device::timer_expired) { - switch (id) - { - case TIMER_ID_1: - // proved by digisound of several intros like eoroidpro - m_timer1->adjust(clocks_to_attotime(TIMER1), 1); - m_timer1_active = 1; - set_interrupt(0x08); - break; - - case TIMER_ID_2: - m_timer2->adjust(clocks_to_attotime(0x10000), 2); - m_timer2_active = 1; - set_interrupt(0x10); - break; - - case TIMER_ID_3: - m_timer3->adjust(clocks_to_attotime(0x10000), 3); - m_timer3_active = 1; - set_interrupt(0x40); - break; - - case TIMER_LINE: - raster_interrupt_gen(); - break; + static const uint8_t s_irq_values[3] = { 0x08, 0x10, 0x40 }; - case TIMER_FRAME: - frame_interrupt_gen(); - break; + if (param == TIMER_ID_1) + { + // proven by digital sound of several intros like eoroidpro + m_timer[param]->adjust(clocks_to_attotime(TIMER1), param); } + else + { + m_timer[param]->adjust(clocks_to_attotime(0x10000), param); + } + + m_timer_active[param] = true; + set_interrupt(s_irq_values[param]); } @@ -825,22 +810,22 @@ uint8_t mos7360_device::read(offs_t offset, int &cs0, int &cs1) switch (offset) { case 0xff00: - val = attotime_to_clocks(m_timer1->remaining()) & 0xff; + val = attotime_to_clocks(m_timer[0]->remaining()) & 0xff; break; case 0xff01: - val = attotime_to_clocks(m_timer1->remaining()) >> 8; + val = attotime_to_clocks(m_timer[0]->remaining()) >> 8; break; case 0xff02: - val = attotime_to_clocks(m_timer2->remaining()) & 0xff; + val = attotime_to_clocks(m_timer[1]->remaining()) & 0xff; break; case 0xff03: - val = attotime_to_clocks(m_timer2->remaining()) >> 8; + val = attotime_to_clocks(m_timer[1]->remaining()) >> 8; break; case 0xff04: - val = attotime_to_clocks(m_timer3->remaining()) & 0xff; + val = attotime_to_clocks(m_timer[2]->remaining()) & 0xff; break; case 0xff05: - val = attotime_to_clocks(m_timer3->remaining()) >> 8; + val = attotime_to_clocks(m_timer[2]->remaining()) >> 8; break; case 0xff07: val = (m_reg[offset & 0x1f] & ~0x40); @@ -922,45 +907,45 @@ void mos7360_device::write(offs_t offset, uint8_t data, int &cs0, int &cs1) case 0xff00: /* stop timer 1 */ m_reg[offset & 0x1f] = data; - if (m_timer1_active) + if (m_timer_active[0]) { - m_reg[1] = attotime_to_clocks(m_timer1->remaining()) >> 8; - m_timer1->reset(); - m_timer1_active = 0; + m_reg[1] = attotime_to_clocks(m_timer[0]->remaining()) >> 8; + m_timer[0]->reset(); + m_timer_active[0] = false; } break; case 0xff01: /* start timer 1 */ m_reg[offset & 0x1f] = data; - m_timer1->adjust(clocks_to_attotime(TIMER1), 1); - m_timer1_active = 1; + m_timer[0]->adjust(clocks_to_attotime(TIMER1), TIMER_ID_1); + m_timer_active[0] = true; break; case 0xff02: /* stop timer 2 */ m_reg[offset & 0x1f] = data; - if (m_timer2_active) + if (m_timer_active[1]) { - m_reg[3] = attotime_to_clocks(m_timer2->remaining()) >> 8; - m_timer2->reset(); - m_timer2_active = 0; + m_reg[3] = attotime_to_clocks(m_timer[1]->remaining()) >> 8; + m_timer[1]->reset(); + m_timer_active[1] = false; } break; case 0xff03: /* start timer 2 */ m_reg[offset & 0x1f] = data; - m_timer2->adjust(clocks_to_attotime(TIMER2), 2); - m_timer2_active = 1; + m_timer[1]->adjust(clocks_to_attotime(TIMER2), TIMER_ID_2); + m_timer_active[1] = true; break; case 0xff04: /* stop timer 3 */ m_reg[offset & 0x1f] = data; - if (m_timer3_active) + if (m_timer_active[2]) { - m_reg[5] = attotime_to_clocks(m_timer3->remaining()) >> 8; - m_timer3->reset(); - m_timer3_active = 0; + m_reg[5] = attotime_to_clocks(m_timer[2]->remaining()) >> 8; + m_timer[2]->reset(); + m_timer_active[2] = false; } break; case 0xff05: /* start timer 3 */ m_reg[offset & 0x1f] = data; - m_timer3->adjust(clocks_to_attotime(TIMER3), 3); - m_timer3_active = 1; + m_timer[2]->adjust(clocks_to_attotime(TIMER3), TIMER_ID_2); + m_timer_active[2] = true; break; case 0xff06: if (m_reg[offset & 0x1f] != data) @@ -1145,7 +1130,7 @@ uint32_t mos7360_device::screen_update(screen_device &screen, bitmap_rgb32 &bitm return 0; } -void mos7360_device::frame_interrupt_gen() +TIMER_CALLBACK_MEMBER(mos7360_device::frame_interrupt_gen) { if ((m_reg[0x1f] & 0xf) >= 0x0f) { @@ -1158,7 +1143,7 @@ void mos7360_device::frame_interrupt_gen() m_reg[0x1f]++; } -void mos7360_device::raster_interrupt_gen() +TIMER_CALLBACK_MEMBER(mos7360_device::raster_interrupt_gen) { m_rasterline++; m_rastertime = machine().time().as_double(); diff --git a/src/devices/sound/mos7360.h b/src/devices/sound/mos7360.h index c34dd2036f4..fd0a51f597b 100644 --- a/src/devices/sound/mos7360.h +++ b/src/devices/sound/mos7360.h @@ -99,15 +99,12 @@ protected: { TIMER_ID_1, TIMER_ID_2, - TIMER_ID_3, - TIMER_LINE, - TIMER_FRAME + TIMER_ID_3 }; // 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) override; // device_sound_interface callbacks virtual void sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) override; @@ -125,8 +122,9 @@ protected: void draw_cursor(int ybegin, int yend, int yoff, int xoff, int color); void drawlines(int first, int last); void soundport_w(int offset, int data); - void frame_interrupt_gen(); - void raster_interrupt_gen(); + TIMER_CALLBACK_MEMBER(timer_expired); + TIMER_CALLBACK_MEMBER(frame_interrupt_gen); + TIMER_CALLBACK_MEMBER(raster_interrupt_gen); int cs0_r(offs_t offset); int cs1_r(offs_t offset); @@ -147,16 +145,24 @@ protected: int m_frame_count; int m_lines; - int m_timer1_active, m_timer2_active, m_timer3_active; - emu_timer *m_timer1, *m_timer2, *m_timer3; + bool m_timer_active[3]; + emu_timer *m_timer[3]; int m_cursor1; - int m_chargenaddr, m_bitmapaddr, m_videoaddr; + int m_chargenaddr; + int m_bitmapaddr; + int m_videoaddr; int m_x_begin, m_x_end; int m_y_begin, m_y_end; - uint16_t m_c16_bitmap[2], m_bitmapmulti[4], m_mono[2], m_monoinversed[2], m_multi[4], m_ecmcolor[2], m_colors[5]; + uint16_t m_c16_bitmap[2]; + uint16_t m_bitmapmulti[4]; + uint16_t m_mono[2]; + uint16_t m_monoinversed[2]; + uint16_t m_multi[4]; + uint16_t m_ecmcolor[2]; + uint16_t m_colors[5]; int m_rasterline, m_lastline; double m_rastertime; diff --git a/src/devices/sound/msm5205.cpp b/src/devices/sound/msm5205.cpp index 382e69ca54e..ba196a419a3 100644 --- a/src/devices/sound/msm5205.cpp +++ b/src/devices/sound/msm5205.cpp @@ -99,8 +99,8 @@ void msm5205_device::device_start() /* stream system initialize */ m_stream = stream_alloc(0, 1, clock()); - m_vck_timer = timer_alloc(TIMER_VCK); - m_capture_timer = timer_alloc(TIMER_ADPCM_CAPTURE); + m_vck_timer = timer_alloc(FUNC(msm5205_device::toggle_vck), this); + m_capture_timer = timer_alloc(FUNC(msm5205_device::update_adpcm), this); /* register for save states */ save_item(NAME(m_data)); @@ -172,29 +172,19 @@ void msm5205_device::compute_tables() //------------------------------------------------- -// device_timer - called whenever a device timer -// fires +// toggle_vck - //------------------------------------------------- -void msm5205_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(msm5205_device::toggle_vck) { - switch (id) - { - case TIMER_VCK: - m_vck = !m_vck; - m_vck_cb(m_vck); - if (!m_vck) - m_capture_timer->adjust(attotime::from_hz(clock()/6)); // 15.6 usec at 384KHz - break; - - case TIMER_ADPCM_CAPTURE: - update_adpcm(); - break; - } + m_vck = !m_vck; + m_vck_cb(m_vck); + if (!m_vck) + m_capture_timer->adjust(attotime::from_hz(clock() / adpcm_capture_divisor())); } // timer callback at VCK low edge on MSM5205 (at rising edge on MSM6585) -void msm5205_device::update_adpcm() +TIMER_CALLBACK_MEMBER(msm5205_device::update_adpcm) { int val; int new_signal; @@ -226,7 +216,7 @@ void msm5205_device::update_adpcm() } /* update when signal changed */ - if( m_signal != new_signal) + if (m_signal != new_signal) { m_stream->update(); m_signal = new_signal; @@ -378,29 +368,6 @@ void msm5205_device::sound_stream_update(sound_stream &stream, std::vector<read_ //------------------------------------------------- -// device_timer - called whenever a device timer -// fires -//------------------------------------------------- - -void msm6585_device::device_timer(emu_timer &timer, device_timer_id id, int param) -{ - switch (id) - { - case TIMER_VCK: - m_vck = !m_vck; - m_vck_cb(m_vck); - if (m_vck) - m_capture_timer->adjust(attotime::from_hz(clock()/2)); // 3 usec at 640KHz - break; - - case TIMER_ADPCM_CAPTURE: - update_adpcm(); - break; - } -} - - -//------------------------------------------------- // sound_stream_update - handle a stream update //------------------------------------------------- diff --git a/src/devices/sound/msm5205.h b/src/devices/sound/msm5205.h index 1bbe1f56036..d38fc6e530d 100644 --- a/src/devices/sound/msm5205.h +++ b/src/devices/sound/msm5205.h @@ -60,15 +60,16 @@ protected: virtual void device_start() override; virtual void device_reset() override; virtual void device_clock_changed() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; - void update_adpcm(); + TIMER_CALLBACK_MEMBER(toggle_vck); + TIMER_CALLBACK_MEMBER(update_adpcm); // sound stream update overrides virtual void sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) override; void compute_tables(); virtual int get_prescaler() const; + virtual double adpcm_capture_divisor() const { return 6.0; } // internal state sound_stream *m_stream; // number of stream system @@ -103,9 +104,7 @@ public: protected: virtual int get_prescaler() const override; - - // device-level overrides - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; + virtual double adpcm_capture_divisor() const override { return 2.0; } // sound stream update overrides virtual void sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) override; diff --git a/src/devices/sound/pokey.cpp b/src/devices/sound/pokey.cpp index d90504499a9..d80e17f74d2 100644 --- a/src/devices/sound/pokey.cpp +++ b/src/devices/sound/pokey.cpp @@ -180,7 +180,10 @@ pokey_device::pokey_device(const machine_config &mconfig, const char *tag, devic m_serout_w_cb(*this), m_keyboard_r(*this), m_irq_f(*this), - m_output_type(LEGACY_LINEAR) + m_output_type(LEGACY_LINEAR), + m_serout_ready_timer(nullptr), + m_serout_complete_timer(nullptr), + m_serin_ready_timer(nullptr) { } @@ -258,10 +261,9 @@ void pokey_device::device_start() m_stream = stream_alloc(0, 1, clock()); - timer_alloc(SYNC_WRITE); /* timer for sync operation */ - timer_alloc(SYNC_NOOP); - timer_alloc(SYNC_POT); - timer_alloc(SYNC_SET_IRQST); + m_serout_ready_timer = timer_alloc(FUNC(pokey_device::serout_ready_irq), this); + m_serout_complete_timer = timer_alloc(FUNC(pokey_device::serout_complete_irq), this); + m_serin_ready_timer = timer_alloc(FUNC(pokey_device::serin_ready_irq), this); save_item(STRUCT_MEMBER(m_channel, m_borrow_cnt)); save_item(STRUCT_MEMBER(m_channel, m_counter)); @@ -354,63 +356,57 @@ void pokey_device::device_clock_changed() } //------------------------------------------------- -// stream_generate - handle update requests for -// our sound stream +// timer callbacks //------------------------------------------------- -void pokey_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(pokey_device::serout_ready_irq) { - switch (id) + if (m_IRQEN & IRQ_SEROR) { - case 3: - /* serout_ready_cb */ - if (m_IRQEN & IRQ_SEROR) - { - m_IRQST |= IRQ_SEROR; - if (!m_irq_f.isnull()) - m_irq_f(IRQ_SEROR); - } - break; - case 4: - /* serout_complete */ - if (m_IRQEN & IRQ_SEROC) - { - m_IRQST |= IRQ_SEROC; - if (!m_irq_f.isnull()) - m_irq_f(IRQ_SEROC); - } - break; - case 5: - /* serin_ready */ - if (m_IRQEN & IRQ_SERIN) - { - m_IRQST |= IRQ_SERIN; - if (!m_irq_f.isnull()) - m_irq_f(IRQ_SERIN); - } - break; - case SYNC_WRITE: - { - offs_t offset = (param >> 8) & 0xff; - uint8_t data = param & 0xff; - write_internal(offset, data); - } - break; - case SYNC_NOOP: - /* do nothing, caused by a forced resync */ - break; - case SYNC_POT: - //logerror("x %02x \n", (param & 0x20)); - m_ALLPOT |= (param & 0xff); - break; - case SYNC_SET_IRQST: - m_IRQST |= (param & 0xff); - break; - default: - throw emu_fatalerror("Unknown id in pokey_device::device_timer"); + m_IRQST |= IRQ_SEROR; + if (!m_irq_f.isnull()) + m_irq_f(IRQ_SEROR); + } +} + +TIMER_CALLBACK_MEMBER(pokey_device::serout_complete_irq) +{ + if (m_IRQEN & IRQ_SEROC) + { + m_IRQST |= IRQ_SEROC; + if (!m_irq_f.isnull()) + m_irq_f(IRQ_SEROC); + } +} + +TIMER_CALLBACK_MEMBER(pokey_device::serin_ready_irq) +{ + if (m_IRQEN & IRQ_SERIN) + { + m_IRQST |= IRQ_SERIN; + if (!m_irq_f.isnull()) + m_irq_f(IRQ_SERIN); } } +TIMER_CALLBACK_MEMBER(pokey_device::sync_write) +{ + offs_t offset = (param >> 8) & 0xff; + uint8_t data = param & 0xff; + write_internal(offset, data); +} + +TIMER_CALLBACK_MEMBER(pokey_device::sync_pot) +{ + //logerror("x %02x \n", (param & 0x20)); + m_ALLPOT |= (param & 0xff); +} + +TIMER_CALLBACK_MEMBER(pokey_device::sync_set_irqst) +{ + m_IRQST |= (param & 0xff); +} + void pokey_device::execute_run() { do @@ -531,7 +527,7 @@ void pokey_device::step_pot() } // some pots latched? if (upd != 0) - synchronize(SYNC_POT, upd); + machine().scheduler().synchronize(timer_expired_delegate(FUNC(pokey_device::sync_pot), this), upd); } /* @@ -755,7 +751,7 @@ uint8_t pokey_device::read(offs_t offset) { int data, pot; - synchronize(SYNC_NOOP); /* force resync */ + machine().scheduler().synchronize(); /* force resync */ switch (offset & 15) { @@ -849,7 +845,7 @@ uint8_t pokey_device::read(offs_t offset) void pokey_device::write(offs_t offset, uint8_t data) { - synchronize(SYNC_WRITE, (offset << 8) | data); + machine().scheduler().synchronize(timer_expired_delegate(FUNC(pokey_device::sync_write), this), (offset << 8) | data); } void pokey_device::write_internal(offs_t offset, uint8_t data) @@ -946,9 +942,9 @@ void pokey_device::write_internal(offs_t offset, uint8_t data) * loaders from Ballblazer and Escape from Fractalus * The real times are unknown */ - timer_set(attotime::from_usec(200), 3); + m_serout_ready_timer->adjust(attotime::from_usec(200)); /* 10 bits (assumption 1 start, 8 data and 1 stop bit) take how long? */ - timer_set(attotime::from_usec(2000), 4);// FUNC(pokey_serout_complete), 0, p); + m_serout_complete_timer->adjust(attotime::from_usec(2000)); break; case IRQEN_C: @@ -1023,7 +1019,7 @@ WRITE_LINE_MEMBER( pokey_device::sid_w ) void pokey_device::serin_ready(int after) { - timer_set(m_clock_period * after, 5, 0); + m_serin_ready_timer->adjust(m_clock_period * after, 0); } //------------------------------------------------- diff --git a/src/devices/sound/pokey.h b/src/devices/sound/pokey.h index c9d58e18eeb..1a111646df1 100644 --- a/src/devices/sound/pokey.h +++ b/src/devices/sound/pokey.h @@ -114,14 +114,6 @@ public: SKSTAT_C = 0x0F }; - enum /* sync-operations */ - { - SYNC_NOOP = 11, - SYNC_SET_IRQST = 12, - SYNC_POT = 13, - SYNC_WRITE = 14 - }; - enum output_type { LEGACY_LINEAR = 0, @@ -190,7 +182,6 @@ protected: virtual void device_reset() override; virtual void device_post_load() override; virtual void device_clock_changed() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; // device_sound_interface overrides virtual void sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) override; @@ -201,6 +192,13 @@ protected: // other internal states int m_icount; + TIMER_CALLBACK_MEMBER(serout_ready_irq); + TIMER_CALLBACK_MEMBER(serout_complete_irq); + TIMER_CALLBACK_MEMBER(serin_ready_irq); + TIMER_CALLBACK_MEMBER(sync_write); + TIMER_CALLBACK_MEMBER(sync_pot); + TIMER_CALLBACK_MEMBER(sync_set_irqst); + private: class pokey_channel @@ -228,7 +226,7 @@ private: if (m_parent->m_IRQEN & m_INTMask) { /* Exposed state has changed: This should only be updated after a resync ... */ - m_parent->synchronize(SYNC_SET_IRQST, m_INTMask); + m_parent->machine().scheduler().synchronize(timer_expired_delegate(FUNC(pokey_device::sync_set_irqst), m_parent), m_INTMask); } } } @@ -312,6 +310,10 @@ private: double m_r_pullup; double m_cap; double m_v_ref; + + emu_timer *m_serout_ready_timer; + emu_timer *m_serout_complete_timer; + emu_timer *m_serin_ready_timer; }; diff --git a/src/devices/sound/qs1000.cpp b/src/devices/sound/qs1000.cpp index 8a98b85111a..ff45ec51093 100644 --- a/src/devices/sound/qs1000.cpp +++ b/src/devices/sound/qs1000.cpp @@ -312,15 +312,6 @@ void qs1000_device::device_reset() //------------------------------------------------- -// device_timer - handle deferred writes and -// resets as a timer callback -//------------------------------------------------- -void qs1000_device::device_timer(emu_timer &timer, device_timer_id id, int param) -{ -} - - -//------------------------------------------------- // p0_r //------------------------------------------------- uint8_t qs1000_device::p0_r() diff --git a/src/devices/sound/qs1000.h b/src/devices/sound/qs1000.h index d992c6a9e7b..2624d893739 100644 --- a/src/devices/sound/qs1000.h +++ b/src/devices/sound/qs1000.h @@ -70,7 +70,6 @@ protected: virtual void device_add_mconfig(machine_config &config) override; virtual void device_start() override; virtual void device_reset() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; // device_sound_interface overrides virtual void sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) override; diff --git a/src/devices/sound/scsp.cpp b/src/devices/sound/scsp.cpp index 1b9a5a8cb8f..f58907b8611 100644 --- a/src/devices/sound/scsp.cpp +++ b/src/devices/sound/scsp.cpp @@ -579,9 +579,9 @@ void scsp_device::init() m_MidiOutR = m_MidiOutW = 0; m_DSP.space = &this->space(); - m_timerA = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(scsp_device::timerA_cb), this)); - m_timerB = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(scsp_device::timerB_cb), this)); - m_timerC = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(scsp_device::timerC_cb), this)); + m_timerA = timer_alloc(FUNC(scsp_device::timerA_cb), this); + m_timerB = timer_alloc(FUNC(scsp_device::timerB_cb), this); + m_timerC = timer_alloc(FUNC(scsp_device::timerC_cb), this); for (i = 0; i < 0x400; ++i) { diff --git a/src/devices/sound/sn76496.cpp b/src/devices/sound/sn76496.cpp index e204b0355cb..96c6a3ba789 100644 --- a/src/devices/sound/sn76496.cpp +++ b/src/devices/sound/sn76496.cpp @@ -280,7 +280,7 @@ void sn76496_base_device::device_start() m_ready_state = true; - m_ready_timer = timer_alloc(0); + m_ready_timer = timer_alloc(FUNC(sn76496_base_device::delayed_ready), this); m_ready_handler(ASSERT_LINE); register_for_save_states(); @@ -298,7 +298,7 @@ void sn76496_base_device::stereo_w(u8 data) else fatalerror("sn76496_base_device: Call to stereo write with mono chip!\n"); } -void sn76496_base_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(sn76496_base_device::delayed_ready) { m_ready_state = true; m_ready_handler(ASSERT_LINE); diff --git a/src/devices/sound/sn76496.h b/src/devices/sound/sn76496.h index d8cc4442314..f5484248715 100644 --- a/src/devices/sound/sn76496.h +++ b/src/devices/sound/sn76496.h @@ -27,26 +27,16 @@ public: DECLARE_READ_LINE_MEMBER( ready_r ) { return m_ready_state ? 1 : 0; } protected: - sn76496_base_device( - const machine_config &mconfig, - device_type type, - const char *tag, - int feedbackmask, - int noisetap1, - int noisetap2, - bool negate, - bool stereo, - int clockdivider, - bool ncr, - bool sega, - device_t *owner, - uint32_t clock); - - virtual void device_start() override; - virtual void device_clock_changed() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; + sn76496_base_device(const machine_config &mconfig, device_type type, const char *tag, + int feedbackmask, int noisetap1, int noisetap2, bool negate, bool stereo, int clockdivider, + bool ncr, bool sega, device_t *owner, uint32_t clock); + + virtual void device_start() override; + virtual void device_clock_changed() override; virtual void sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) override; + TIMER_CALLBACK_MEMBER(delayed_ready); + private: inline bool in_noise_mode(); void register_for_save_states(); diff --git a/src/devices/sound/sp0250.cpp b/src/devices/sound/sp0250.cpp index 6d9ed63ecd3..9544adb3c38 100644 --- a/src/devices/sound/sp0250.cpp +++ b/src/devices/sound/sp0250.cpp @@ -25,6 +25,7 @@ DEFINE_DEVICE_TYPE(SP0250, sp0250_device, "sp0250", "GI SP0250 LPC") sp0250_device::sp0250_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) : device_t(mconfig, SP0250, tag, owner, clock), device_sound_interface(mconfig, *this), + m_timer(nullptr), m_pwm_mode(false), m_pwm_index(PWM_CLOCKS), m_pwm_count(0), @@ -72,7 +73,8 @@ void sp0250_device::device_start() { m_drq(ASSERT_LINE); attotime period = attotime::from_hz(frame_rate); - timer_alloc()->adjust(period, 0, period); + m_timer = timer_alloc(FUNC(sp0250_device::delayed_stream_update), this); + m_timer->adjust(period, 0, period); } // PWM state @@ -108,7 +110,7 @@ void sp0250_device::device_reset() load_values(); } -void sp0250_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(sp0250_device::delayed_stream_update) { m_stream->update(); } diff --git a/src/devices/sound/sp0250.h b/src/devices/sound/sp0250.h index 260e77ad695..31c32ef4d5d 100644 --- a/src/devices/sound/sp0250.h +++ b/src/devices/sound/sp0250.h @@ -20,11 +20,12 @@ protected: // 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) override; // sound stream update overrides virtual void sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) override; + TIMER_CALLBACK_MEMBER(delayed_stream_update); + private: // internal helpers int8_t next(); @@ -47,6 +48,9 @@ private: int16_t z1, z2; }; + // timer for stream updates + emu_timer *m_timer; + // PWM state bool m_pwm_mode; uint8_t m_pwm_index; diff --git a/src/devices/sound/sp0256.cpp b/src/devices/sound/sp0256.cpp index b1219f70cd7..7f709ec90c0 100644 --- a/src/devices/sound/sp0256.cpp +++ b/src/devices/sound/sp0256.cpp @@ -106,7 +106,7 @@ void sp0256_device::device_start() // TODO: because of this, check if the bitrev functions are even used anywhere else // bitrevbuff(m_rom, 0, 0xffff); - m_lrq_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(sp0256_device::set_lrq_timer_proc),this)); + m_lrq_timer = timer_alloc(FUNC(sp0256_device::set_lrq_timer_proc), this); // save device variables save_item(NAME(m_sby_line)); diff --git a/src/devices/sound/tms5110.cpp b/src/devices/sound/tms5110.cpp index e96a9c6e736..a9d3395a4d2 100644 --- a/src/devices/sound/tms5110.cpp +++ b/src/devices/sound/tms5110.cpp @@ -1051,7 +1051,7 @@ void tms5110_device::device_start() m_stream = stream_alloc(0, 1, clock() / 80); m_state = CTL_STATE_INPUT; /* most probably not defined */ - m_romclk_hack_timer = timer_alloc(0); + m_romclk_hack_timer = timer_alloc(FUNC(tms5110_device::romclk_hack_toggle), this); register_for_save_states(); } @@ -1187,17 +1187,15 @@ uint8_t m58817_device::status_r() return (TALK_STATUS() << 0); /*CTL1 = still talking ? */ } -/****************************************************************************** - - tms5110_romclk_hack_r -- read status of romclk - -******************************************************************************/ - -void tms5110_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(tms5110_device::romclk_hack_toggle) { m_romclk_hack_state = !m_romclk_hack_state; } +//------------------------------------------------- +// romclk_hack_r - read status of romclk +//------------------------------------------------- + int tms5110_device::romclk_hack_r() { /* bring up to date first */ @@ -1322,7 +1320,7 @@ void tmsprom_device::update_prom_cnt() m_prom_cnt &= 0x0f; } -void tmsprom_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(tmsprom_device::update_romclk) { /* only 16 bytes needed ... The original dump is bad. This * is what is needed to get speech to work. The prom data has @@ -1332,10 +1330,8 @@ void tmsprom_device::device_timer(emu_timer &timer, device_timer_id id, int para * static const int prom[16] = {0x00, 0x00, 0x02, 0x00, 0x00, 0x02, 0x00, 0x00, * 0x02, 0x00, 0x40, 0x00, 0x04, 0x06, 0x04, 0x84 }; */ - uint16_t ctrl; - update_prom_cnt(); - ctrl = (m_prom[m_prom_cnt] | 0x200); + uint16_t ctrl = (m_prom[m_prom_cnt] | 0x200); //if (m_enable && m_prom_cnt < 0x10) printf("ctrl %04x, enable %d cnt %d\n", ctrl, m_enable, m_prom_cnt); m_prom_cnt = ((m_prom_cnt + 1) & 0x0f) | (m_prom_cnt & 0x10); @@ -1359,7 +1355,7 @@ void tmsprom_device::device_start() m_pdc_cb.resolve_safe(); m_ctl_cb.resolve_safe(); - m_romclk_timer = timer_alloc(0); + m_romclk_timer = timer_alloc(FUNC(tmsprom_device::update_romclk), this); m_romclk_timer->adjust(attotime::zero, 0, attotime::from_hz(clock())); m_bit = 0; diff --git a/src/devices/sound/tms5110.h b/src/devices/sound/tms5110.h index e49ea9e93cc..9d907668a70 100644 --- a/src/devices/sound/tms5110.h +++ b/src/devices/sound/tms5110.h @@ -57,7 +57,7 @@ protected: virtual void device_reset() override; virtual void device_clock_changed() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; + TIMER_CALLBACK_MEMBER(romclk_hack_toggle); // sound stream update overrides virtual void sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) override; @@ -285,7 +285,7 @@ protected: // device-level overrides virtual void device_start() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; + TIMER_CALLBACK_MEMBER(update_romclk); private: void register_for_save_states(); diff --git a/src/devices/sound/tms5220.cpp b/src/devices/sound/tms5220.cpp index 47d1ab02fc2..77622b12fef 100644 --- a/src/devices/sound/tms5220.cpp +++ b/src/devices/sound/tms5220.cpp @@ -1653,7 +1653,7 @@ void tms5220_device::device_start() /* initialize a stream */ m_stream = stream_alloc(0, 1, clock() / 80); - m_timer_io_ready = timer_alloc(0); + m_timer_io_ready = timer_alloc(FUNC(tms5220_device::set_io_ready), this); /* not during reset which is called from within a write! */ m_io_ready = true; @@ -1729,60 +1729,49 @@ void tms5220_device::device_reset() } -/********************************************************************************************** - - True timing - -***********************************************************************************************/ - -void tms5220_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(tms5220_device::set_io_ready) { - switch(id) + /* bring up to date first */ + m_stream->update(); + LOGMASKED(LOG_IO_READY, "m_timer_io_ready timer fired, param = %02x, m_rs_ws = %02x\n", param, m_rs_ws); + if (param) // low->high ready state { - case 0: // m_timer_io_ready - /* bring up to date first */ - m_stream->update(); - LOGMASKED(LOG_IO_READY, "m_timer_io_ready timer fired, param = %02x, m_rs_ws = %02x\n", param, m_rs_ws); - if (param) // low->high ready state + switch (m_rs_ws) { - switch (m_rs_ws) + case 0x02: + /* Write */ + LOGMASKED(LOG_IO_READY, "m_timer_io_ready: Attempting to service write...\n"); + if ((m_fifo_count >= FIFO_SIZE) && m_DDIS) // if FIFO is full and we're in speak external mode { - case 0x02: - /* Write */ - LOGMASKED(LOG_IO_READY, "m_timer_io_ready: Attempting to service write...\n"); - if ((m_fifo_count >= FIFO_SIZE) && m_DDIS) // if FIFO is full and we're in speak external mode - { - LOGMASKED(LOG_IO_READY, "m_timer_io_ready: in SPKEXT and FIFO was full! cannot service write now, delaying 16 cycles...\n"); - m_timer_io_ready->adjust(clocks_to_attotime(16), 1); - break; - } - else - { - LOGMASKED(LOG_IO_READY, "m_timer_io_ready: Serviced write: %02x\n", m_write_latch); - data_write(m_write_latch); - m_io_ready = param; - break; - } - case 0x01: - /* Read */ - m_read_latch = status_read(true); - LOGMASKED(LOG_IO_READY, "m_timer_io_ready: Serviced read, returning %02x\n", m_read_latch); - m_io_ready = param; - break; - case 0x03: - /* High Impedance */ - m_io_ready = param; + LOGMASKED(LOG_IO_READY, "m_timer_io_ready: in SPKEXT and FIFO was full! cannot service write now, delaying 16 cycles...\n"); + m_timer_io_ready->adjust(clocks_to_attotime(16), 1); break; - case 0x00: - /* illegal */ + } + else + { + LOGMASKED(LOG_IO_READY, "m_timer_io_ready: Serviced write: %02x\n", m_write_latch); + data_write(m_write_latch); m_io_ready = param; break; } + case 0x01: + /* Read */ + m_read_latch = status_read(true); + LOGMASKED(LOG_IO_READY, "m_timer_io_ready: Serviced read, returning %02x\n", m_read_latch); + m_io_ready = param; + break; + case 0x03: + /* High Impedance */ + m_io_ready = param; + break; + case 0x00: + /* illegal */ + m_io_ready = param; + break; } - - update_ready_state(); - break; } + + update_ready_state(); } /* diff --git a/src/devices/sound/tms5220.h b/src/devices/sound/tms5220.h index 826a78ec291..82a589c486d 100644 --- a/src/devices/sound/tms5220.h +++ b/src/devices/sound/tms5220.h @@ -72,11 +72,11 @@ protected: virtual void device_reset() override; virtual void device_clock_changed() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; - // sound stream update overrides virtual void sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) override; + TIMER_CALLBACK_MEMBER(set_io_ready); + private: static constexpr unsigned FIFO_SIZE = 16; diff --git a/src/devices/sound/upd1771.cpp b/src/devices/sound/upd1771.cpp index 2ec1d767ba0..4e865ea2c42 100644 --- a/src/devices/sound/upd1771.cpp +++ b/src/devices/sound/upd1771.cpp @@ -253,7 +253,7 @@ void upd1771c_device::device_start() /* resolve callbacks */ m_ack_handler.resolve_safe(); - m_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(upd1771c_device::ack_callback),this)); + m_timer = timer_alloc(FUNC(upd1771c_device::ack_callback), this); m_channel = stream_alloc(0, 1, clock() / 4); diff --git a/src/devices/sound/upd7759.cpp b/src/devices/sound/upd7759.cpp index 36738f029a5..2da49639c82 100644 --- a/src/devices/sound/upd7759.cpp +++ b/src/devices/sound/upd7759.cpp @@ -268,21 +268,12 @@ void upd7759_device::device_start() m_sample_offset_shift = 1; - m_timer = timer_alloc(TID_SLAVE_UPDATE); + m_timer = timer_alloc(FUNC(upd7759_device::drq_update), this); m_drqcallback.resolve_safe(); - - device_reset(); } -void upd7756_device::device_start() -{ - upd775x_device::device_start(); - - device_reset(); -} - //------------------------------------------------- // device_reset - device-specific reset //------------------------------------------------- @@ -574,54 +565,29 @@ void upd775x_device::advance_state() } } -/************************************************************ - - DRQ callback - -*************************************************************/ +TIMER_CALLBACK_MEMBER(upd775x_device::sync_port_write) +{ + m_fifo_in = param; +} -void upd7759_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(upd7759_device::drq_update) { uint8_t olddrq = m_drq; int old_state = m_state; - switch (id) - { - case TID_PORT_WRITE: - m_fifo_in = param; - break; - - case TID_RESET_WRITE: - internal_reset_w(param); - break; - - case TID_START_WRITE: - internal_start_w(param); - break; - - case TID_MD_WRITE: - internal_md_w(param); - break; - - case TID_SLAVE_UPDATE: - m_channel->update(); - - advance_state(); - - LOG_STATE("upd7759_slave_update: DRQ %d->%d\n", olddrq, m_drq); - if (olddrq != m_drq) - { - LOG_DRQ("DRQ changed %d->%d\n", olddrq, m_drq); - m_drqcallback(m_drq); - } + m_channel->update(); - if (m_state != STATE_IDLE || old_state != STATE_IDLE) - m_timer->adjust(m_clock_period * m_clocks_left); - break; + advance_state(); - default: - throw emu_fatalerror("Unknown id in upd7759_device::device_timer"); + LOG_STATE("upd7759_slave_update: DRQ %d->%d\n", olddrq, m_drq); + if (olddrq != m_drq) + { + LOG_DRQ("DRQ changed %d->%d\n", olddrq, m_drq); + m_drqcallback(m_drq); } + + if (m_state != STATE_IDLE || old_state != STATE_IDLE) + m_timer->adjust(m_clock_period * m_clocks_left); } /************************************************************ @@ -632,13 +598,13 @@ void upd7759_device::device_timer(emu_timer &timer, device_timer_id id, int para WRITE_LINE_MEMBER( upd775x_device::reset_w ) { - synchronize(TID_RESET_WRITE, state); + machine().scheduler().synchronize(timer_expired_delegate(FUNC(upd775x_device::internal_reset_w), this), state); } -void upd775x_device::internal_reset_w(int state) +TIMER_CALLBACK_MEMBER(upd775x_device::internal_reset_w) { uint8_t oldreset = m_reset; - m_reset = (state != 0); + m_reset = (param != 0); m_channel->update(); @@ -646,10 +612,10 @@ void upd775x_device::internal_reset_w(int state) device_reset(); } -void upd7759_device::internal_reset_w(int state) +TIMER_CALLBACK_MEMBER(upd7759_device::internal_reset_w) { uint8_t oldreset = m_reset; - upd775x_device::internal_reset_w(state); + upd775x_device::internal_reset_w(param); if (!oldreset && m_reset) { @@ -664,7 +630,7 @@ void upd7759_device::internal_reset_w(int state) WRITE_LINE_MEMBER( upd775x_device::start_w ) { - synchronize(TID_START_WRITE, state); + machine().scheduler().synchronize(timer_expired_delegate(FUNC(upd775x_device::internal_start_w), this), state); } void upd7759_device::internal_start_w(int state) @@ -710,14 +676,14 @@ WRITE_LINE_MEMBER(upd7759_device::md_w) m_md = state; return; } - synchronize(TID_MD_WRITE, state); + machine().scheduler().synchronize(timer_expired_delegate(FUNC(upd7759_device::internal_md_w), this), state); } -void upd7759_device::internal_md_w(int state) +TIMER_CALLBACK_MEMBER(upd7759_device::internal_md_w) { uint8_t old_md = m_md; - m_md = (state != 0); + m_md = (param != 0); LOG_STATE("upd7759_md_w: %d->%d\n", old_md, m_md); @@ -741,7 +707,7 @@ void upd7759_device::internal_md_w(int state) void upd775x_device::port_w(u8 data) { - synchronize(TID_PORT_WRITE, data); + machine().scheduler().synchronize(timer_expired_delegate(FUNC(upd775x_device::sync_port_write), this), data); } diff --git a/src/devices/sound/upd7759.h b/src/devices/sound/upd7759.h index 23f24ad1ae5..1f1d0e38dfd 100644 --- a/src/devices/sound/upd7759.h +++ b/src/devices/sound/upd7759.h @@ -27,8 +27,8 @@ public: void set_start_delay(uint32_t data) { m_start_delay = data; } protected: - virtual void internal_start_w(int state) = 0; - virtual void internal_reset_w(int state); + virtual TIMER_CALLBACK_MEMBER(internal_start_w) = 0; + virtual TIMER_CALLBACK_MEMBER(internal_reset_w); enum { @@ -78,6 +78,8 @@ protected: void update_adpcm(int data); virtual void advance_state(); + TIMER_CALLBACK_MEMBER(sync_port_write); + // internal state sound_stream *m_channel; // stream channel for playback @@ -131,14 +133,15 @@ public: DECLARE_WRITE_LINE_MEMBER( md_w ); protected: - virtual void internal_start_w(int state) override; - virtual void internal_reset_w(int state) override; - upd7759_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock); virtual void device_start() override; virtual void device_reset() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; + + virtual TIMER_CALLBACK_MEMBER(internal_start_w) override; + virtual TIMER_CALLBACK_MEMBER(internal_reset_w) override; + + TIMER_CALLBACK_MEMBER(drq_update); void internal_md_w(int state); @@ -151,14 +154,12 @@ class upd7756_device : public upd775x_device public: upd7756_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock = STANDARD_CLOCK); - virtual void device_reset() override; - protected: - virtual void internal_start_w(int state) override; - upd7756_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock); - virtual void device_start() override; + virtual void device_reset() override; + + virtual TIMER_CALLBACK_MEMBER(internal_start_w) override; }; DECLARE_DEVICE_TYPE(UPD7759, upd7759_device) diff --git a/src/devices/sound/votrax.cpp b/src/devices/sound/votrax.cpp index ee4a21a3c9f..1ec2343f72f 100644 --- a/src/devices/sound/votrax.cpp +++ b/src/devices/sound/votrax.cpp @@ -170,7 +170,7 @@ void votrax_sc01_device::device_start() m_sclock = m_mainclock / 18.0; m_cclock = m_mainclock / 36.0; m_stream = stream_alloc(0, 1, m_sclock); - m_timer = timer_alloc(); + m_timer = timer_alloc(FUNC(votrax_sc01_device::phone_tick), this); // reset outputs m_ar_cb.resolve_safe(); @@ -331,10 +331,10 @@ void votrax_sc01_device::device_clock_changed() //------------------------------------------------- -// device_timer - handle device timer +// phone_tick - process transitions //------------------------------------------------- -void votrax_sc01_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(votrax_sc01_device::phone_tick) { m_stream->update(); diff --git a/src/devices/sound/votrax.h b/src/devices/sound/votrax.h index 87c466b1875..2dcc7d087da 100644 --- a/src/devices/sound/votrax.h +++ b/src/devices/sound/votrax.h @@ -34,11 +34,12 @@ protected: virtual void device_start() override; virtual void device_reset() override; virtual void device_clock_changed() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; // device_sound_interface overrides virtual void sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) override; + TIMER_CALLBACK_MEMBER(phone_tick); + private: // Possible timer parameters enum { diff --git a/src/devices/sound/ym2154.cpp b/src/devices/sound/ym2154.cpp index 8be2888175b..287529aeeec 100644 --- a/src/devices/sound/ym2154.cpp +++ b/src/devices/sound/ym2154.cpp @@ -177,7 +177,7 @@ void ym2154_device::write(offs_t offset, u8 data) void ym2154_device::device_start() { // allocate our timer - m_timer = timer_alloc(0); + m_timer = timer_alloc(FUNC(ym2154_device::delayed_irq), this); // resolve the handlers m_update_irq.resolve(); @@ -237,10 +237,10 @@ void ym2154_device::device_clock_changed() //------------------------------------------------- -// sound_stream_update - generate sound data +// delayed_irq - //------------------------------------------------- -void ym2154_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(ym2154_device::delayed_irq) { update_irq_state(1); m_timer->adjust((2048 - m_timer_count) * attotime::from_hz(sample_rate())); diff --git a/src/devices/sound/ym2154.h b/src/devices/sound/ym2154.h index 3736b6aa367..e7f287409fa 100644 --- a/src/devices/sound/ym2154.h +++ b/src/devices/sound/ym2154.h @@ -37,7 +37,6 @@ protected: virtual void device_start() override; virtual void device_reset() override; virtual void device_clock_changed() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; // sound overrides virtual void sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) override; @@ -45,6 +44,8 @@ protected: // memory space configuration virtual space_config_vector memory_space_config() const override; + TIMER_CALLBACK_MEMBER(delayed_irq); + private: struct channel { diff --git a/src/devices/sound/ymf271.cpp b/src/devices/sound/ymf271.cpp index 6e82ee97607..b8240df9c72 100644 --- a/src/devices/sound/ymf271.cpp +++ b/src/devices/sound/ymf271.cpp @@ -1309,46 +1309,38 @@ void ymf271_device::ymf271_write_pcm(uint8_t address, uint8_t data) } } -void ymf271_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(ymf271_device::timer_a_expired) { - switch(id) - { - case 0: - m_status |= 1; - - // assert IRQ - if (m_enable & 4) - { - m_irqstate |= 1; - - if (!m_irq_handler.isnull()) - m_irq_handler(1); - } + m_status |= 1; - // reload timer - m_timA->adjust(clocks_to_attotime(384 * (1024 - m_timerA)), 0); - break; + // assert IRQ + if (m_enable & 4) + { + m_irqstate |= 1; - case 1: - m_status |= 2; + if (!m_irq_handler.isnull()) + m_irq_handler(1); + } - // assert IRQ - if (m_enable & 8) - { - m_irqstate |= 2; + // reload timer + m_timA->adjust(clocks_to_attotime(384 * (1024 - m_timerA)), 0); +} - if (!m_irq_handler.isnull()) - m_irq_handler(1); - } +TIMER_CALLBACK_MEMBER(ymf271_device::timer_b_expired) +{ + m_status |= 2; - // reload timer - m_timB->adjust(clocks_to_attotime(384 * 16 * (256 - m_timerB)), 0); - break; + // assert IRQ + if (m_enable & 8) + { + m_irqstate |= 2; - default: - throw emu_fatalerror("Unknown id in ymf271_device::device_timer"); - break; + if (!m_irq_handler.isnull()) + m_irq_handler(1); } + + // reload timer + m_timB->adjust(clocks_to_attotime(384 * 16 * (256 - m_timerB)), 0); } void ymf271_device::ymf271_write_timer(uint8_t address, uint8_t data) @@ -1732,8 +1724,8 @@ void ymf271_device::init_state() void ymf271_device::device_start() { - m_timA = timer_alloc(0); - m_timB = timer_alloc(1); + m_timA = timer_alloc(FUNC(ymf271_device::timer_a_expired), this); + m_timB = timer_alloc(FUNC(ymf271_device::timer_b_expired), this); m_irq_handler.resolve(); diff --git a/src/devices/sound/ymf271.h b/src/devices/sound/ymf271.h index 6dbf1a9408f..5c6e432649b 100644 --- a/src/devices/sound/ymf271.h +++ b/src/devices/sound/ymf271.h @@ -24,7 +24,6 @@ protected: // 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) override; virtual void device_clock_changed() override; // sound stream update overrides @@ -33,6 +32,9 @@ protected: // device_rom_interface overrides virtual void rom_bank_updated() override; + TIMER_CALLBACK_MEMBER(timer_a_expired); + TIMER_CALLBACK_MEMBER(timer_b_expired); + private: struct YMF271Slot { diff --git a/src/devices/sound/ymfm_mame.h b/src/devices/sound/ymfm_mame.h index d22fc9ad8b2..d0161426619 100644 --- a/src/devices/sound/ymfm_mame.h +++ b/src/devices/sound/ymfm_mame.h @@ -138,7 +138,7 @@ protected: { // allocate our timers for (int tnum = 0; tnum < 2; tnum++) - m_timer[tnum] = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(ym_generic_device::fm_timer_handler), this)); + m_timer[tnum] = timer_alloc(FUNC(ym_generic_device::fm_timer_handler), this); // resolve the handlers m_update_irq.resolve(); diff --git a/src/devices/sound/ymz280b.cpp b/src/devices/sound/ymz280b.cpp index f6e6a0e3935..319b03a381b 100644 --- a/src/devices/sound/ymz280b.cpp +++ b/src/devices/sound/ymz280b.cpp @@ -81,7 +81,7 @@ void ymz280b_device::update_irq_state() } -void ymz280b_device::update_step(struct YMZ280BVoice *voice) +void ymz280b_device::update_step(YMZ280BVoice *voice) { int frequency; @@ -94,7 +94,7 @@ void ymz280b_device::update_step(struct YMZ280BVoice *voice) } -void ymz280b_device::update_volumes(struct YMZ280BVoice *voice) +void ymz280b_device::update_volumes(YMZ280BVoice *voice) { if (voice->pan == 8) { @@ -118,24 +118,24 @@ void ymz280b_device::update_volumes(struct YMZ280BVoice *voice) void ymz280b_device::device_post_load() { - for (auto & elem : m_voice) + for (size_t i = 0; i < std::size(m_voice); i++) { - struct YMZ280BVoice *voice = &elem; + YMZ280BVoice *voice = &m_voice[i]; update_step(voice); if(voice->irq_schedule) - voice->timer->adjust(attotime::zero); + voice->timer->adjust(attotime::zero, i); } } -void ymz280b_device::update_irq_state_timer_common(int voicenum) +TIMER_CALLBACK_MEMBER(ymz280b_device::update_irq_state_timer_common) { - struct YMZ280BVoice *voice = &m_voice[voicenum]; + YMZ280BVoice *voice = &m_voice[param]; if(!voice->irq_schedule) return; voice->playing = 0; - m_status_register |= 1 << voicenum; + m_status_register |= 1 << param; update_irq_state(); voice->irq_schedule = 0; } @@ -164,7 +164,7 @@ static void compute_tables() ***********************************************************************************************/ -int ymz280b_device::generate_adpcm(struct YMZ280BVoice *voice, s16 *buffer, int samples) +int ymz280b_device::generate_adpcm(YMZ280BVoice *voice, s16 *buffer, int samples) { int position = voice->position; int signal = voice->signal; @@ -276,7 +276,7 @@ int ymz280b_device::generate_adpcm(struct YMZ280BVoice *voice, s16 *buffer, int ***********************************************************************************************/ -int ymz280b_device::generate_pcm8(struct YMZ280BVoice *voice, s16 *buffer, int samples) +int ymz280b_device::generate_pcm8(YMZ280BVoice *voice, s16 *buffer, int samples) { int position = voice->position; int val; @@ -346,7 +346,7 @@ int ymz280b_device::generate_pcm8(struct YMZ280BVoice *voice, s16 *buffer, int s ***********************************************************************************************/ -int ymz280b_device::generate_pcm16(struct YMZ280BVoice *voice, s16 *buffer, int samples) +int ymz280b_device::generate_pcm16(YMZ280BVoice *voice, s16 *buffer, int samples) { int position = voice->position; int val; @@ -428,7 +428,7 @@ void ymz280b_device::sound_stream_update(sound_stream &stream, std::vector<read_ /* loop over voices */ for (v = 0; v < 8; v++) { - struct YMZ280BVoice *voice = &m_voice[v]; + YMZ280BVoice *voice = &m_voice[v]; s16 prev = voice->last_sample; s16 curr = voice->curr_sample; s16 *curr_data = m_scratch.get(); @@ -501,7 +501,7 @@ void ymz280b_device::sound_stream_update(sound_stream &stream, std::vector<read_ voice->playing = 0; /* set update_irq_state_timer. IRQ is signaled on next CPU execution. */ - voice->timer->adjust(attotime::zero); + voice->timer->adjust(attotime::zero, v); voice->irq_schedule = 1; } } @@ -556,7 +556,7 @@ void ymz280b_device::device_start() for (int i = 0; i < 8; i++) { - m_voice[i].timer = timer_alloc(i); + m_voice[i].timer = timer_alloc(FUNC(ymz280b_device::update_irq_state_timer_common), this); } /* create the stream */ @@ -629,7 +629,7 @@ void ymz280b_device::device_reset() /* clear other voice parameters */ for (auto &elem : m_voice) { - struct YMZ280BVoice *voice = &elem; + YMZ280BVoice *voice = &elem; voice->curr_sample = 0; voice->last_sample = 0; @@ -639,15 +639,6 @@ void ymz280b_device::device_reset() } -void ymz280b_device::device_timer(emu_timer &timer, device_timer_id id, int param) -{ - if (id < 8) - update_irq_state_timer_common( id ); - else - throw emu_fatalerror("Unknown id in ymz280b_device::device_timer"); -} - - void ymz280b_device::device_clock_changed() { m_master_clock = (double)clock() / 384.0; @@ -669,13 +660,10 @@ void ymz280b_device::rom_bank_updated() void ymz280b_device::write_to_register(int data) { - struct YMZ280BVoice *voice; - int i; - /* lower registers follow a pattern */ if (m_current_register < 0x80) { - voice = &m_voice[(m_current_register >> 2) & 7]; + YMZ280BVoice *voice = &m_voice[(m_current_register >> 2) & 7]; switch (m_current_register & 0xe3) { @@ -687,8 +675,10 @@ void ymz280b_device::write_to_register(int data) case 0x01: /* pitch upper 1 bit, loop, key on, mode */ voice->fnum = (voice->fnum & 0xff) | ((data & 0x01) << 8); voice->looping = (data & 0x10) >> 4; - if ((data & 0x60) == 0) data &= 0x7f; /* ignore mode setting and set to same state as KON=0 */ - else voice->mode = (data & 0x60) >> 5; + if ((data & 0x60) == 0) + data &= 0x7f; /* ignore mode setting and set to same state as KON=0 */ + else + voice->mode = (data & 0x60) >> 5; if (!voice->keyon && (data & 0x80) && m_keyon_enable) { voice->playing = 1; @@ -822,7 +812,7 @@ void ymz280b_device::write_to_register(int data) if (m_keyon_enable && !(data & 0x80)) { - for (i = 0; i < 8; i++) + for (int i = 0; i < 8; i++) { m_voice[i].playing = 0; @@ -832,7 +822,7 @@ void ymz280b_device::write_to_register(int data) } else if (!m_keyon_enable && (data & 0x80)) { - for (i = 0; i < 8; i++) + for (int i = 0; i < 8; i++) { if (m_voice[i].keyon && m_voice[i].looping) m_voice[i].playing = 1; diff --git a/src/devices/sound/ymz280b.h b/src/devices/sound/ymz280b.h index c35d4be20fc..04b229de4d3 100644 --- a/src/devices/sound/ymz280b.h +++ b/src/devices/sound/ymz280b.h @@ -32,7 +32,6 @@ protected: virtual void device_start() override; virtual void device_post_load() override; virtual void device_reset() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; virtual void device_clock_changed() override; // sound stream update overrides @@ -80,17 +79,17 @@ private: }; void update_irq_state(); - void update_step(struct YMZ280BVoice *voice); - void update_volumes(struct YMZ280BVoice *voice); - void update_irq_state_timer_common(int voicenum); - int generate_adpcm(struct YMZ280BVoice *voice, s16 *buffer, int samples); - int generate_pcm8(struct YMZ280BVoice *voice, s16 *buffer, int samples); - int generate_pcm16(struct YMZ280BVoice *voice, s16 *buffer, int samples); + void update_step(YMZ280BVoice *voice); + void update_volumes(YMZ280BVoice *voice); + TIMER_CALLBACK_MEMBER(update_irq_state_timer_common); + int generate_adpcm(YMZ280BVoice *voice, s16 *buffer, int samples); + int generate_pcm8(YMZ280BVoice *voice, s16 *buffer, int samples); + int generate_pcm16(YMZ280BVoice *voice, s16 *buffer, int samples); void write_to_register(int data); int compute_status(); // internal state - struct YMZ280BVoice m_voice[8]; /* the 8 voices */ + YMZ280BVoice m_voice[8]; /* the 8 voices */ u8 m_current_register; /* currently accessible register */ u8 m_status_register; /* current status register */ u8 m_irq_state; /* current IRQ state */ |