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/mame/machine | |
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/mame/machine')
209 files changed, 2011 insertions, 2453 deletions
diff --git a/src/mame/machine/3dom2.cpp b/src/mame/machine/3dom2.cpp index bbe7638ad46..a93fdf1acab 100644 --- a/src/mame/machine/3dom2.cpp +++ b/src/mame/machine/3dom2.cpp @@ -252,7 +252,7 @@ void m2_bda_device::device_start() save_pointer(NAME(m_ram), ram_size / sizeof(uint32_t)); // Set a timer to pull data from the DSPP FIFO into the DACs - m_dac_timer = timer_alloc(0); + m_dac_timer = timer_alloc(FUNC(m2_bda_device::dac_update), this); m_dac_timer->adjust(attotime::from_hz(16.9345)); } @@ -311,21 +311,14 @@ void m2_bda_device::device_add_mconfig(machine_config &config) //------------------------------------------------- -// device_timer - device-specific timers +// dac_update - pull DAC data from the DSPP //------------------------------------------------- -void m2_bda_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(m2_bda_device::dac_update) { - switch (id) - { - case 0: - { - m_dac_l(m_dspp->read_output_fifo()); - m_dac_r(m_dspp->read_output_fifo()); - m_dac_timer->adjust(attotime::from_hz(44100)); - break; - } - } + m_dac_l(m_dspp->read_output_fifo()); + m_dac_r(m_dspp->read_output_fifo()); + m_dac_timer->adjust(attotime::from_hz(44100)); } @@ -813,8 +806,8 @@ void m2_vdu_device::device_start() m_vint1_int_handler.resolve_safe(); // Initialize line interrupt timers - m_vint0_timer = timer_alloc(TIMER_ID_VINT0); - m_vint1_timer = timer_alloc(TIMER_ID_VINT1); + m_vint0_timer = timer_alloc(FUNC(m2_vdu_device::vint0_set), this); + m_vint1_timer = timer_alloc(FUNC(m2_vdu_device::vint1_set), this); // Calculate H/V count bias values (1 = start of blanking) const rectangle visarea = m_screen->visible_area(); @@ -861,28 +854,21 @@ void m2_vdu_device::device_reset() //------------------------------------------------- -// device_timer - device-specific timers +// vertical interrupt timer callbacks //------------------------------------------------- -void m2_vdu_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(m2_vdu_device::vint0_set) { - switch (id) - { - case TIMER_ID_VINT0: - { - m_vint |= VDU_VINT_VINT0; - m_vint0_int_handler(ASSERT_LINE); - set_vint_timer(0); - break; - } - case TIMER_ID_VINT1: - { - m_vint |= VDU_VINT_VINT1; - m_vint1_int_handler(ASSERT_LINE); - set_vint_timer(1); - break; - } - } + m_vint |= VDU_VINT_VINT0; + m_vint0_int_handler(ASSERT_LINE); + set_vint_timer(0); +} + +TIMER_CALLBACK_MEMBER(m2_vdu_device::vint1_set) +{ + m_vint |= VDU_VINT_VINT1; + m_vint1_int_handler(ASSERT_LINE); + set_vint_timer(1); } @@ -1493,7 +1479,8 @@ m2_cde_device::m2_cde_device(const machine_config &mconfig, const char *tag, dev m_cpu1(*this, finder_base::DUMMY_TAG), m_bda(*this, finder_base::DUMMY_TAG), m_int_handler(*this), - m_sdbg_out_handler(*this) + m_sdbg_out_handler(*this), + m_cd_ready_timer(nullptr) { } @@ -1509,8 +1496,8 @@ void m2_cde_device::device_start() m_sdbg_out_handler.resolve_safe(); // Init DMA - m_dma[0].m_timer = timer_alloc(TIMER_ID_DMA1); - m_dma[1].m_timer = timer_alloc(TIMER_ID_DMA2); + m_dma[0].m_timer = timer_alloc(FUNC(m2_cde_device::next_dma), this); + m_dma[1].m_timer = timer_alloc(FUNC(m2_cde_device::next_dma), this); // Register state for saving save_item(NAME(m_sdbg_cntl)); @@ -1534,8 +1521,10 @@ void m2_cde_device::device_start() save_item(NAME(m_dma[i].m_nbad), i); save_item(NAME(m_dma[i].m_npad), i); save_item(NAME(m_dma[i].m_ncnt), i); - // timer } + + // Allocate other timers + m_cd_ready_timer = timer_alloc(FUNC(m2_cde_device::trigger_ready_int), this); } //------------------------------------------------- @@ -1568,29 +1557,13 @@ void m2_cde_device::device_post_load() //------------------------------------------------- -// device_timer - a timer +// trigger_ready_int - flag CD ready //------------------------------------------------- -void m2_cde_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(m2_cde_device::trigger_ready_int) { - switch (id) - { - case TIMER_ID_READY: - // TODO ? - set_interrupt(CDE_ID_READY); - break; - - case TIMER_ID_DMA1: - next_dma(0); - break; - - case TIMER_ID_DMA2: - next_dma(1); - break; - - default: - throw emu_fatalerror("m2_cde_device::device_timer: Unknown CDE timer ID"); - } + // TODO: Do we need to do more things here? + set_interrupt(CDE_ID_READY); } @@ -1743,31 +1716,22 @@ void m2_cde_device::write(address_space &space, offs_t offset, uint32_t data, ui switch (byte_offs) { case CDE_SDBG_CNTL: - { // ........ ........ xxxxxxxx xxxx.... Clock scaler (written with 33MHz/38400 = 868) write_m2_reg(m_sdbg_cntl, data, wm_cw); break; - } case CDE_SDBG_WRT: - { m_sdbg_out_handler(data); set_interrupt(CDE_SDBG_WRT_DONE); break; - } case CDE_INT_STS: - { write_m2_reg(m_int_status, data, wm_cw); update_interrupts(); break; - } case CDE_INT_ENABLE: - { write_m2_reg(m_int_enable, data, wm_cs); update_interrupts(); break; - } case CDE_RESET_CNTL: - { if (data & 1) { // TODO: Should we reset both CPUs? @@ -1782,23 +1746,16 @@ void m2_cde_device::write(address_space &space, offs_t offset, uint32_t data, ui } break; - } case CDE_CD_CMD_WRT: - { //set_interrupt(CDE_CD_CMD_WRT_DONE); // ? //set_interrupt(CDE_CD_STS_FL_DONE); // ? break; - }; case CDE_UNIQ_ID_CMD: - { // TODO: What is this? - timer_set(attotime::from_usec(250), TIMER_ID_READY); + m_cd_ready_timer->adjust(attotime::from_usec(250)); break; - } case CDE_BBLOCK: - { break; - } case CDE_DEV0_SETUP: case CDE_DEV1_SETUP: @@ -1830,18 +1787,14 @@ void m2_cde_device::write(address_space &space, offs_t offset, uint32_t data, ui // case CDE_SYSTEM_CONF: case CDE_VISA_DIS: - { write_m2_reg(m_visa_dis, data, wm_cw); break; - } case CDE_MICRO_RWS: case CDE_MICRO_WI: case CDE_MICRO_WOB: case CDE_MICRO_WO: case CDE_MICRO_STATUS: - { break; - } case CDE_DMA1_CNTL: case CDE_DMA2_CNTL: @@ -1861,26 +1814,19 @@ void m2_cde_device::write(address_space &space, offs_t offset, uint32_t data, ui } case CDE_DMA1_CBAD: case CDE_DMA2_CBAD: - { write_m2_reg(m_dma[dmach].m_cbad, data, wm_cw); break; - } case CDE_DMA1_CPAD: case CDE_DMA2_CPAD: - { write_m2_reg(m_dma[dmach].m_cpad, data, wm_cw); break; - } case CDE_DMA1_CCNT: case CDE_DMA2_CCNT: - { write_m2_reg(m_dma[dmach].m_ccnt, data, wm_cw); break; - } default: - { //logerror("%s: CDE_W UNHANDLED: 0x%.8x 0x%.8x 0x%.8x\n", machine().describe_context(), byte_offs, data, mem_mask); - } + break; } } @@ -1926,7 +1872,7 @@ void m2_cde_device::start_dma(uint32_t ch) attotime delay = attotime::from_nsec(10);// * dma_ch.m_ccnt; // attotime delay = clocks_to_attotime(4 * dma_ch.m_ccnt); - dma_ch.m_timer->adjust(delay); + dma_ch.m_timer->adjust(delay, (int)ch); if (dma_ch.m_cntl & CDE_DMA_DIRECTION) { @@ -1989,8 +1935,9 @@ void m2_cde_device::start_dma(uint32_t ch) // next_dma - Start the next DMA if set //------------------------------------------------- -void m2_cde_device::next_dma(uint32_t ch) +TIMER_CALLBACK_MEMBER(m2_cde_device::next_dma) { + const uint32_t ch = (uint32_t)param; dma_channel &dma_ch = m_dma[ch]; // TODO: HACK! diff --git a/src/mame/machine/3dom2.h b/src/mame/machine/3dom2.h index 25df60b11bc..5c3ba784e2c 100644 --- a/src/mame/machine/3dom2.h +++ b/src/mame/machine/3dom2.h @@ -164,7 +164,8 @@ protected: virtual void device_reset() override; virtual void device_post_load() override; virtual void device_add_mconfig(machine_config &config) override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; + + TIMER_CALLBACK_MEMBER(dac_update); private: enum base_addr @@ -400,16 +401,11 @@ 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; -private: - enum timer_id - { - TIMER_ID_VBLANK, - TIMER_ID_VINT0, - TIMER_ID_VINT1, - }; + TIMER_CALLBACK_MEMBER(vint0_set); + TIMER_CALLBACK_MEMBER(vint1_set); +private: void set_vint_timer(uint32_t id); void parse_dc_word(uint32_t data); void parse_av_word(uint32_t data); @@ -525,19 +521,8 @@ protected: virtual void device_start() 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; private: - - enum timer_id - { - TIMER_ID_READY, - TIMER_ID_CD_DMA1, - TIMER_ID_CD_DMA2, - TIMER_ID_DMA1, - TIMER_ID_DMA2, - }; - enum reg_offs { // Miscellaneous @@ -684,7 +669,8 @@ private: void reset_dma(uint32_t ch); void start_dma(uint32_t ch); - void next_dma(uint32_t ch); + TIMER_CALLBACK_MEMBER(next_dma); + TIMER_CALLBACK_MEMBER(trigger_ready_int); static uint32_t address_to_biobus_slot(uint32_t addr) { @@ -699,6 +685,8 @@ private: devcb_write_line m_int_handler; devcb_write32 m_sdbg_out_handler; + // Timers + emu_timer *m_cd_ready_timer; // Registers uint32_t m_sdbg_in; diff --git a/src/mame/machine/aim65.cpp b/src/mame/machine/aim65.cpp index cf7b14ba9e1..031d5272c06 100644 --- a/src/mame/machine/aim65.cpp +++ b/src/mame/machine/aim65.cpp @@ -142,7 +142,7 @@ void aim65_state::machine_start() save_item(NAME(m_printer_y)); save_item(NAME(m_printer_flag)); save_item(NAME(m_printer_level)); - m_print_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(aim65_state::printer_timer),this)); + m_print_timer = timer_alloc(FUNC(aim65_state::printer_timer), this); m_printerRAM = make_unique_clear<uint16_t[]>(64*100); save_pointer(NAME(m_printerRAM), 64*100); } diff --git a/src/mame/machine/amiga.cpp b/src/mame/machine/amiga.cpp index e1a21ae7fc9..bf729fe3d58 100644 --- a/src/mame/machine/amiga.cpp +++ b/src/mame/machine/amiga.cpp @@ -163,10 +163,10 @@ void amiga_state::machine_start() m_chip_ram_mask = (m_chip_ram.bytes() - 1) & ~1; // set up the timers - m_irq_timer = timer_alloc(TIMER_AMIGA_IRQ); - m_blitter_timer = timer_alloc(TIMER_AMIGA_BLITTER); - m_serial_timer = timer_alloc(TIMER_SERIAL); - m_scanline_timer = timer_alloc(TIMER_SCANLINE); + m_irq_timer = timer_alloc(FUNC(amiga_state::amiga_irq_proc), this); + m_blitter_timer = timer_alloc(FUNC(amiga_state::amiga_blitter_proc), this); + m_serial_timer = timer_alloc(FUNC(amiga_state::serial_shift), this); + m_scanline_timer = timer_alloc(FUNC(amiga_state::scanline_callback), this); // start the scanline timer m_scanline_timer->adjust(m_screen->time_until_pos(0)); @@ -226,27 +226,6 @@ uint32_t amiga_state::rom_mirror32_r(offs_t offset, uint32_t mem_mask) return m_maincpu->space(AS_PROGRAM).read_dword(offset + 0xf80000, mem_mask); } -void amiga_state::device_timer(emu_timer &timer, device_timer_id id, int param) -{ - switch (id) - { - case TIMER_SCANLINE: - scanline_callback(param); - break; - case TIMER_AMIGA_IRQ: - amiga_irq_proc(param); - break; - case TIMER_AMIGA_BLITTER: - amiga_blitter_proc(param); - break; - case TIMER_SERIAL: - serial_shift(); - break; - default: - fatalerror("Invalid timer: %d\n", id); - } -} - /************************************* * @@ -1725,7 +1704,7 @@ void amiga_state::serial_adjust() m_serial_timer->adjust(attotime::from_hz(baud) / 2, 0, attotime::from_hz(baud)); } -void amiga_state::serial_shift() +TIMER_CALLBACK_MEMBER(amiga_state::serial_shift) { if (CUSTOM_REG(REG_ADKCON) & ADKCON_UARTBRK) { diff --git a/src/mame/machine/amstrad.cpp b/src/mame/machine/amstrad.cpp index 07c3eb31352..0910624225e 100644 --- a/src/mame/machine/amstrad.cpp +++ b/src/mame/machine/amstrad.cpp @@ -221,25 +221,6 @@ TIMER_CALLBACK_MEMBER(amstrad_state::amstrad_pc2_low) } -void amstrad_state::device_timer(emu_timer &timer, device_timer_id id, int param) -{ - switch (id) - { - case TIMER_PC2_LOW: - amstrad_pc2_low(param); - break; - case TIMER_VIDEO_UPDATE: - amstrad_video_update_timer(param); - break; - case TIMER_SET_RESOLUTION: - cb_set_resolution(param); - break; - default: - throw emu_fatalerror("Unknown id in amstrad_state::device_timer"); - } -} - - /*************************************************************************/ /* KC Compact @@ -589,7 +570,7 @@ void amstrad_state::amstrad_vh_update_colour(int PenIndex, uint16_t hw_colour_in { int val; - timer_set(attotime::from_usec(0), TIMER_VIDEO_UPDATE, 1); + m_video_update_timer->adjust(attotime::from_usec(0), 1); /* CPC+/GX4000 - normal palette changes through the Gate Array also makes the corresponding change in the ASIC palette */ val = (amstrad_palette[hw_colour_index] & 0xf00000) >> 16; /* red */ @@ -600,7 +581,7 @@ void amstrad_state::amstrad_vh_update_colour(int PenIndex, uint16_t hw_colour_in } else { - timer_set(attotime::from_usec(0), TIMER_VIDEO_UPDATE, 0); + m_video_update_timer->adjust(attotime::from_usec(0), 0); } m_GateArray_render_colours[PenIndex] = hw_colour_index; } @@ -608,7 +589,7 @@ void amstrad_state::amstrad_vh_update_colour(int PenIndex, uint16_t hw_colour_in void amstrad_state::aleste_vh_update_colour(int PenIndex, uint16_t hw_colour_index) { - timer_set(attotime::from_usec(0), TIMER_VIDEO_UPDATE, 0); + m_video_update_timer->adjust(attotime::from_usec(0), 0); m_GateArray_render_colours[PenIndex] = hw_colour_index+32; } @@ -975,7 +956,7 @@ WRITE_LINE_MEMBER(amstrad_state::amstrad_vsync_changed) m_gate_array.vsync = state ? 1 : 0; /* Schedule a write to PC2 */ - timer_set(attotime::zero, TIMER_PC2_LOW); + m_pc2_low_timer->adjust(attotime::zero); } @@ -996,7 +977,7 @@ WRITE_LINE_MEMBER(amstrad_state::amstrad_plus_vsync_changed) m_gate_array.vsync = state ? 1 : 0; /* Schedule a write to PC2 */ - timer_set(attotime::zero, TIMER_PC2_LOW); + m_pc2_low_timer->adjust(attotime::zero); } @@ -1075,6 +1056,8 @@ void amstrad_state::video_start() m_gate_array.bitmap = std::make_unique<bitmap_ind16>(m_screen->width(), m_screen->height() ); m_gate_array.hsync_after_vsync_counter = 3; std::fill(std::begin(m_GateArray_render_colours), std::end(m_GateArray_render_colours), 0); + + m_video_update_timer = timer_alloc(FUNC(amstrad_state::amstrad_video_update_timer), this); } @@ -2056,9 +2039,9 @@ void amstrad_state::amstrad_cpc_io_w(offs_t offset, uint8_t data) break; case 0x01: /* Write to selected internal 6845 register Write Only */ if ( m_system_type == SYSTEM_PLUS || m_system_type == SYSTEM_GX4000 ) - timer_set(attotime::from_usec(0), TIMER_VIDEO_UPDATE, 1); + m_video_update_timer->adjust(attotime::from_usec(0), 1); else - timer_set(attotime::from_usec(0), TIMER_VIDEO_UPDATE, 0); + m_video_update_timer->adjust(attotime::from_usec(0), 0); m_crtc->register_w(data); /* printer port bit 8 */ @@ -2609,7 +2592,7 @@ uint8_t amstrad_state::amstrad_ppi_portb_r() //logerror("amstrad_ppi_portb_r\n"); /* Schedule a write to PC2 */ - timer_set(attotime::zero, TIMER_PC2_LOW); + m_pc2_low_timer->adjust(attotime::zero); return data; } @@ -3099,9 +3082,15 @@ TIMER_CALLBACK_MEMBER(amstrad_state::cb_set_resolution) m_screen->configure( 1024, height, visarea, refresh ); } +void amstrad_state::alloc_timers() +{ + m_pc2_low_timer = timer_alloc(FUNC(amstrad_state::amstrad_pc2_low), this); + m_set_resolution_timer = timer_alloc(FUNC(amstrad_state::cb_set_resolution), this); +} MACHINE_START_MEMBER(amstrad_state,amstrad) { + alloc_timers(); m_system_type = SYSTEM_CPC; m_centronics->write_data7(0); } @@ -3118,12 +3107,13 @@ MACHINE_RESET_MEMBER(amstrad_state,amstrad) m_gate_array.hsync = 0; m_gate_array.vsync = 0; - timer_set(attotime::zero, TIMER_SET_RESOLUTION); + m_set_resolution_timer->adjust(attotime::zero); } MACHINE_START_MEMBER(amstrad_state,plus) { + alloc_timers(); m_asic.ram = m_region_user1->base(); // 16kB RAM for ASIC, memory-mapped registers. m_system_type = SYSTEM_PLUS; m_centronics->write_data7(0); @@ -3166,11 +3156,12 @@ MACHINE_RESET_MEMBER(amstrad_state,plus) space.install_write_handler(0x6000, 0x7fff, write8sm_delegate(*this, FUNC(amstrad_state::amstrad_plus_asic_6000_w))); // multiface_init(); - timer_set(attotime::zero, TIMER_SET_RESOLUTION); + m_set_resolution_timer->adjust(attotime::zero); } MACHINE_START_MEMBER(amstrad_state,gx4000) { + alloc_timers(); m_asic.ram = m_region_user1->base(); // 16kB RAM for ASIC, memory-mapped registers. m_system_type = SYSTEM_GX4000; @@ -3208,11 +3199,12 @@ MACHINE_RESET_MEMBER(amstrad_state,gx4000) space.install_write_handler(0x4000, 0x5fff, write8sm_delegate(*this, FUNC(amstrad_state::amstrad_plus_asic_4000_w))); space.install_write_handler(0x6000, 0x7fff, write8sm_delegate(*this, FUNC(amstrad_state::amstrad_plus_asic_6000_w))); - timer_set(attotime::zero, TIMER_SET_RESOLUTION); + m_set_resolution_timer->adjust(attotime::zero); } MACHINE_START_MEMBER(amstrad_state,kccomp) { + alloc_timers(); m_system_type = SYSTEM_CPC; m_centronics->write_data7(0); @@ -3221,7 +3213,7 @@ MACHINE_START_MEMBER(amstrad_state,kccomp) m_gate_array.hsync = 0; m_gate_array.vsync = 0; - timer_set(attotime::zero, TIMER_SET_RESOLUTION); + m_set_resolution_timer->adjust(attotime::zero); } @@ -3242,6 +3234,7 @@ MACHINE_RESET_MEMBER(amstrad_state,kccomp) MACHINE_START_MEMBER(amstrad_state,aleste) { + alloc_timers(); m_system_type = SYSTEM_ALESTE; m_centronics->write_data7(0); } @@ -3251,7 +3244,7 @@ MACHINE_RESET_MEMBER(amstrad_state,aleste) amstrad_common_init(); amstrad_reset_machine(); - timer_set(attotime::zero, TIMER_SET_RESOLUTION); + m_set_resolution_timer->adjust(attotime::zero); } diff --git a/src/mame/machine/apollo.cpp b/src/mame/machine/apollo.cpp index 1b4f63013f1..9c6adb99b53 100644 --- a/src/mame/machine/apollo.cpp +++ b/src/mame/machine/apollo.cpp @@ -1276,8 +1276,7 @@ void apollo_stdio_device::device_start() m_tx_w.resolve_safe(); - m_poll_timer = machine().scheduler().timer_alloc(timer_expired_delegate( - FUNC(apollo_stdio_device::poll_timer), this)); + m_poll_timer = timer_alloc(FUNC(apollo_stdio_device::poll_timer), this); } //------------------------------------------------- @@ -1306,13 +1305,6 @@ void apollo_stdio_device::device_reset() m_poll_timer->adjust(attotime::zero, 0, attotime::from_msec(1)); // every 1ms } -void apollo_stdio_device::device_timer(emu_timer &timer, device_timer_id id, - int param) -{ -// FIXME? -// device_serial_interface::device_timer(timer, id, param); -} - void apollo_stdio_device::rcv_complete() // Rx completed receiving byte { receive_register_extract(); diff --git a/src/mame/machine/apollo_kbd.cpp b/src/mame/machine/apollo_kbd.cpp index 54302827fea..5e7e577325a 100644 --- a/src/mame/machine/apollo_kbd.cpp +++ b/src/mame/machine/apollo_kbd.cpp @@ -240,7 +240,7 @@ void apollo_kbd_device::device_start() m_beeper.start(this); m_mouse.start(this); - m_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(apollo_kbd_device::kbd_scan_timer), this)); + m_timer = timer_alloc(FUNC(apollo_kbd_device::kbd_scan_timer), this); } //------------------------------------------------- @@ -315,7 +315,7 @@ void apollo_kbd_device::beeper::start(apollo_kbd_device *device) m_device = device; LOG2(("start apollo_kbd::beeper")); m_beeper = m_device->m_beep.target(); - m_timer = m_device->machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(apollo_kbd_device::beeper::beeper_callback), this)); + m_timer = m_device->timer_alloc(FUNC(apollo_kbd_device::beeper::beeper_callback), this); } void apollo_kbd_device::beeper::reset() diff --git a/src/mame/machine/apple3.cpp b/src/mame/machine/apple3.cpp index d3467664e76..3d6045d8d12 100644 --- a/src/mame/machine/apple3.cpp +++ b/src/mame/machine/apple3.cpp @@ -729,8 +729,8 @@ void apple3_state::init_apple3() m_via[1]->write_pb6(1); m_via[1]->write_pb7(1); - m_scanstart = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(apple3_state::scanstart_cb),this)); - m_scanend = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(apple3_state::scanend_cb),this)); + m_scanstart = timer_alloc(FUNC(apple3_state::scanstart_cb), this); + m_scanend = timer_alloc(FUNC(apple3_state::scanend_cb), this); apple3_update_memory(); diff --git a/src/mame/machine/archimedes_keyb.cpp b/src/mame/machine/archimedes_keyb.cpp index 6b1a2e55f6a..a6aa8278969 100644 --- a/src/mame/machine/archimedes_keyb.cpp +++ b/src/mame/machine/archimedes_keyb.cpp @@ -254,7 +254,7 @@ void archimedes_keyboard_device::device_start() set_data_frame(1, 8, PARITY_NONE, STOP_BITS_2); set_rate(31250); - m_mouse_timer = timer_alloc(); + m_mouse_timer = timer_alloc(FUNC(archimedes_keyboard_device::update_mouse), this); save_item(NAME(m_mouse_x)); save_item(NAME(m_mouse_y)); @@ -337,7 +337,7 @@ void archimedes_keyboard_device::tra_callback() m_kout(transmit_register_get_data_bit()); } -void archimedes_keyboard_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(archimedes_keyboard_device::update_mouse) { // Mouse quadrature signals // Increase Decrease diff --git a/src/mame/machine/archimedes_keyb.h b/src/mame/machine/archimedes_keyb.h index 821d929bd07..7acf6ae8d59 100644 --- a/src/mame/machine/archimedes_keyb.h +++ b/src/mame/machine/archimedes_keyb.h @@ -36,7 +36,6 @@ protected: virtual void device_resolve_objects() 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; // optional information overrides virtual const tiny_rom_entry *device_rom_region() const override; @@ -48,6 +47,8 @@ protected: virtual void tra_complete() override; virtual void rcv_complete() override; + TIMER_CALLBACK_MEMBER(update_mouse); + private: void tx_w(uint8_t data); uint8_t mouse_r(); diff --git a/src/mame/machine/asic65.cpp b/src/mame/machine/asic65.cpp index 52c080ed0a9..32de7641d53 100644 --- a/src/mame/machine/asic65.cpp +++ b/src/mame/machine/asic65.cpp @@ -11,8 +11,10 @@ #include <algorithm> -#define LOG_ASIC 0 +#define LOG_ASIC (1U << 1) +#define VERBOSE (0) +#include "logmacro.h" #define PARAM_WRITE 0 #define COMMAND_WRITE 1 @@ -87,6 +89,7 @@ DEFINE_DEVICE_TYPE(ASIC65, asic65_device, "asic65", "Atari ASIC65") asic65_device::asic65_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock) : device_t(mconfig, ASIC65, tag, owner, clock) + , m_synced_write_timer(nullptr) , m_asic65_type(0) , m_command(0) , m_yorigin(0x1800) @@ -101,7 +104,6 @@ asic65_device::asic65_device(const machine_config &mconfig, const char *tag, dev , m_xflg(0) , m_68data(0) , m_tdata(0) - , m_log(nullptr) { std::fill(std::begin(m_param), std::end(m_param), 0); } @@ -126,6 +128,8 @@ void asic65_device::device_start() save_item(NAME(m_68data)); save_item(NAME(m_tdata)); save_item(NAME(m_param)); + + m_synced_write_timer = timer_alloc(FUNC(asic65_device::synced_write), this); } //------------------------------------------------- @@ -169,32 +173,22 @@ void asic65_device::reset_line(int state) * *************************************/ -void asic65_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(asic65_device::synced_write) { - switch (id) - { - case TIMER_M68K_ASIC65_DEFERRED_W: - m_tfull = 1; - m_cmd = param >> 16; - m_tdata = param; - if (m_asic65_type == ASIC65_ROMBASED) - m_ourcpu->set_input_line(0, ASSERT_LINE); - break; - default: - throw emu_fatalerror("Unknown id in asic65_device::device_timer"); - } + m_tfull = 1; + m_cmd = param >> 16; + m_tdata = param; + if (m_asic65_type == ASIC65_ROMBASED) + m_ourcpu->set_input_line(0, ASSERT_LINE); } void asic65_device::data_w(offs_t offset, u16 data) { - /* logging */ - if (LOG_ASIC && !m_log) m_log = fopen("m_log", "w"); - /* rom-based use a deferred write mechanism */ if (m_asic65_type == ASIC65_ROMBASED) { - synchronize(TIMER_M68K_ASIC65_DEFERRED_W, data | (offset << 16)); + m_synced_write_timer->adjust(attotime::zero, data | (offset << 16)); machine().scheduler().boost_interleave(attotime::zero, attotime::from_usec(20)); return; } @@ -202,7 +196,7 @@ void asic65_device::data_w(offs_t offset, u16 data) /* parameters go to offset 0 */ if (!(offset & 1)) { - if (m_log) fprintf(m_log, " W=%04X", data); + LOGMASKED(LOG_ASIC, "%s: Write %04X", machine().describe_context(), data); /* add to the parameter list, but don't overflow */ m_param[m_param_index++] = data; @@ -214,7 +208,7 @@ void asic65_device::data_w(offs_t offset, u16 data) else { int command = (data < MAX_COMMANDS) ? command_map[m_asic65_type][data] : OP_UNKNOWN; - if (m_log) fprintf(m_log, "\n%s %c%04X:", machine().describe_context().c_str(), (command == OP_UNKNOWN) ? '*' : ' ', data); + LOGMASKED(LOG_ASIC, "%s: Command %c %04X", machine().describe_context(), (command == OP_UNKNOWN) ? '*' : ' ', data); /* set the command number and reset the parameter/result indices */ m_command = data; @@ -452,8 +446,7 @@ u16 asic65_device::read() } } - if (LOG_ASIC && !m_log) m_log = fopen("m_log", "w"); - if (m_log) fprintf(m_log, " (R=%04X)", result); + LOGMASKED(LOG_ASIC, "%s: Read %04X", machine().describe_context(), result); return result; } diff --git a/src/mame/machine/asic65.h b/src/mame/machine/asic65.h index 3c333e8497b..8599620235f 100644 --- a/src/mame/machine/asic65.h +++ b/src/mame/machine/asic65.h @@ -55,9 +55,11 @@ protected: virtual void device_start() override; virtual void device_reset() override; virtual void device_add_mconfig(machine_config &config) override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; + + TIMER_CALLBACK_MEMBER(synced_write); private: + emu_timer *m_synced_write_timer; u8 m_asic65_type; int m_command; u16 m_param[32]; @@ -76,8 +78,6 @@ private: u16 m_68data; u16 m_tdata; - FILE * m_log; - DECLARE_READ_LINE_MEMBER( get_bio ); }; diff --git a/src/mame/machine/atarigen.cpp b/src/mame/machine/atarigen.cpp index 604c7c240c6..89b95d021bc 100644 --- a/src/mame/machine/atarigen.cpp +++ b/src/mame/machine/atarigen.cpp @@ -22,11 +22,13 @@ atarigen_state::atarigen_state(const machine_config &mconfig, device_type type, , m_maincpu(*this, "maincpu") , m_gfxdecode(*this, "gfxdecode") , m_screen(*this, "screen") + , m_unhalt_cpu_timer(nullptr) { } void atarigen_state::machine_start() { + m_unhalt_cpu_timer = timer_alloc(FUNC(atarigen_state::unhalt_cpu), this); } @@ -35,15 +37,9 @@ void atarigen_state::machine_reset() } -void atarigen_state::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(atarigen_state::unhalt_cpu) { - switch (id) - { - // unhalt the CPU - case TID_UNHALT_CPU: - m_maincpu->set_input_line(INPUT_LINE_HALT, CLEAR_LINE); - break; - } + m_maincpu->set_input_line(INPUT_LINE_HALT, CLEAR_LINE); } @@ -70,7 +66,7 @@ void atarigen_state::halt_until_hblank_0(device_t &device, screen_device &screen // halt and set a timer to wake up m_maincpu->set_input_line(INPUT_LINE_HALT, ASSERT_LINE); - timer_set(screen.scan_period() * (hblank - hpos) / width, TID_UNHALT_CPU); + m_unhalt_cpu_timer->adjust(screen.scan_period() * (hblank - hpos) / width); } diff --git a/src/mame/machine/atarigen.h b/src/mame/machine/atarigen.h index e03c3e43136..32aafb7b9f6 100644 --- a/src/mame/machine/atarigen.h +++ b/src/mame/machine/atarigen.h @@ -28,20 +28,13 @@ protected: // users must call through to these virtual void machine_start() override; virtual void machine_reset() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; // video helpers void halt_until_hblank_0(device_t &device, screen_device &screen); // misc helpers void blend_gfx(int gfx0, int gfx1, int mask0, int mask1); - - // timer IDs - enum - { - TID_UNHALT_CPU, - TID_ATARIGEN_LAST - }; + TIMER_CALLBACK_MEMBER(unhalt_cpu); required_device<cpu_device> m_maincpu; @@ -49,6 +42,8 @@ protected: optional_device<screen_device> m_screen; std::unique_ptr<u8[]> m_blended_data; + + emu_timer *m_unhalt_cpu_timer; }; diff --git a/src/mame/machine/atariscom.cpp b/src/mame/machine/atariscom.cpp index 4c55b43a1ee..6f282192725 100644 --- a/src/mame/machine/atariscom.cpp +++ b/src/mame/machine/atariscom.cpp @@ -60,6 +60,11 @@ void atari_sound_comm_device::device_start() save_item(NAME(m_sound_to_main_ready)); save_item(NAME(m_main_to_sound_data)); save_item(NAME(m_sound_to_main_data)); + + // allocate timers + m_sound_reset_timer = timer_alloc(FUNC(atari_sound_comm_device::delayed_sound_reset), this); + m_sound_write_timer = timer_alloc(FUNC(atari_sound_comm_device::delayed_sound_write), this); + m_6502_write_timer = timer_alloc(FUNC(atari_sound_comm_device::delayed_6502_write), this); } @@ -77,37 +82,13 @@ void atari_sound_comm_device::device_reset() //------------------------------------------------- -// device_timer: Handle device-specific timer -// calbacks -//------------------------------------------------- - -void atari_sound_comm_device::device_timer(emu_timer &timer, device_timer_id id, int param) -{ - switch (id) - { - case TID_SOUND_RESET: - delayed_sound_reset(param); - break; - - case TID_SOUND_WRITE: - delayed_sound_write(param); - break; - - case TID_6502_WRITE: - delayed_6502_write(param); - break; - } -} - - -//------------------------------------------------- // sound_reset_w: Write handler which resets the // sound CPU in response. //------------------------------------------------- void atari_sound_comm_device::sound_reset_w(u16 data) { - synchronize(TID_SOUND_RESET); + m_sound_reset_timer->adjust(attotime::zero); } @@ -120,7 +101,7 @@ void atari_sound_comm_device::sound_reset_w(u16 data) void atari_sound_comm_device::main_command_w(u8 data) { - synchronize(TID_SOUND_WRITE, data); + m_sound_write_timer->adjust(attotime::zero, data); } @@ -149,7 +130,7 @@ u8 atari_sound_comm_device::main_response_r() void atari_sound_comm_device::sound_response_w(u8 data) { - synchronize(TID_6502_WRITE, data); + m_6502_write_timer->adjust(attotime::zero, data); } @@ -175,7 +156,7 @@ u8 atari_sound_comm_device::sound_command_r() // reset command between the two CPUs. //------------------------------------------------- -void atari_sound_comm_device::delayed_sound_reset(int param) +TIMER_CALLBACK_MEMBER(atari_sound_comm_device::delayed_sound_reset) { // unhalt and reset the sound CPU if (param == 0) @@ -199,14 +180,14 @@ void atari_sound_comm_device::delayed_sound_reset(int param) // from the main CPU to the sound CPU. //------------------------------------------------- -void atari_sound_comm_device::delayed_sound_write(int data) +TIMER_CALLBACK_MEMBER(atari_sound_comm_device::delayed_sound_write) { // warn if we missed something if (m_main_to_sound_ready) logerror("Missed command from 680x0\n"); // set up the states and signal an NMI to the sound CPU - m_main_to_sound_data = data; + m_main_to_sound_data = param; m_main_to_sound_ready = true; m_sound_cpu->set_input_line(INPUT_LINE_NMI, ASSERT_LINE); @@ -221,14 +202,14 @@ void atari_sound_comm_device::delayed_sound_write(int data) // from the sound CPU to the main CPU. //------------------------------------------------- -void atari_sound_comm_device::delayed_6502_write(int data) +TIMER_CALLBACK_MEMBER(atari_sound_comm_device::delayed_6502_write) { // warn if we missed something if (m_sound_to_main_ready) logerror("Missed result from 6502\n"); // set up the states and signal the sound interrupt to the main CPU - m_sound_to_main_data = data; + m_sound_to_main_data = param; m_sound_to_main_ready = true; m_main_int_cb(ASSERT_LINE); } diff --git a/src/mame/machine/atariscom.h b/src/mame/machine/atariscom.h index abc0f8931e8..39633550b75 100644 --- a/src/mame/machine/atariscom.h +++ b/src/mame/machine/atariscom.h @@ -56,35 +56,29 @@ public: void sound_reset_w(u16 data = 0); // sound cpu accessors - void sound_cpu_reset() { synchronize(TID_SOUND_RESET, 1); } + void sound_cpu_reset() { m_sound_reset_timer->adjust(attotime::zero, 1); } void sound_response_w(u8 data); u8 sound_command_r(); protected: // sound I/O helpers - void delayed_sound_reset(int param); - void delayed_sound_write(int data); - void delayed_6502_write(int data); + TIMER_CALLBACK_MEMBER(delayed_sound_reset); + TIMER_CALLBACK_MEMBER(delayed_sound_write); + TIMER_CALLBACK_MEMBER(delayed_6502_write); // 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; private: - // timer IDs - enum - { - TID_SOUND_RESET, - TID_SOUND_WRITE, - TID_6502_WRITE - }; - // configuration state devcb_write_line m_main_int_cb; // internal state required_device<cpu_device> m_sound_cpu; + emu_timer *m_sound_reset_timer; + emu_timer *m_sound_write_timer; + emu_timer *m_6502_write_timer; bool m_main_to_sound_ready; bool m_sound_to_main_ready; u8 m_main_to_sound_data; diff --git a/src/mame/machine/ataristb.cpp b/src/mame/machine/ataristb.cpp index 483a11f0410..e1daa535a5d 100644 --- a/src/mame/machine/ataristb.cpp +++ b/src/mame/machine/ataristb.cpp @@ -526,7 +526,7 @@ void st_blitter_device::device_resolve_objects() void st_blitter_device::device_start() { - m_blitter_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(st_blitter_device::blitter_tick), this)); + m_blitter_timer = timer_alloc(FUNC(st_blitter_device::blitter_tick), this); // register for state saving save_item(NAME(m_halftone)); diff --git a/src/mame/machine/balsente.cpp b/src/mame/machine/balsente.cpp index 4724cbec2fa..6889918cd42 100644 --- a/src/mame/machine/balsente.cpp +++ b/src/mame/machine/balsente.cpp @@ -37,7 +37,7 @@ TIMER_DEVICE_CALLBACK_MEMBER(balsente_state::interrupt_timer) m_maincpu->set_input_line(M6809_IRQ_LINE, ASSERT_LINE); /* it will turn off on the next HBLANK */ - machine().scheduler().timer_set(m_screen->time_until_pos(param, BALSENTE_HBSTART), timer_expired_delegate(FUNC(balsente_state::irq_off),this)); + m_irq_off_timer->adjust(m_screen->time_until_pos(param, BALSENTE_HBSTART)); /* if this is Grudge Match, update the steering */ if (m_grudge_steering_result & 0x80) @@ -78,6 +78,9 @@ void balsente_state::machine_start() save_item(NAME(m_spiker_expand_bits)); save_item(NAME(m_grudge_steering_result)); save_item(NAME(m_grudge_last_steering)); + + m_irq_off_timer = timer_alloc(FUNC(balsente_state::irq_off), this); + m_adc_timer = timer_alloc(FUNC(balsente_state::adc_finished), this); } @@ -100,6 +103,9 @@ void balsente_state::machine_reset() /* start a timer to generate interrupts */ m_scanline_timer->adjust(m_screen->time_until_pos(0)); + + m_irq_off_timer->adjust(attotime::never); + m_adc_timer->adjust(attotime::never); } @@ -318,7 +324,7 @@ void balsente_state::adc_select_w(offs_t offset, uint8_t data) /* set a timer to go off and read the value after 50us */ /* it's important that we do this for Mini Golf */ logerror("adc_select %d\n", offset & 7); - machine().scheduler().timer_set(attotime::from_usec(50), timer_expired_delegate(FUNC(balsente_state::adc_finished),this), offset & 7); + m_adc_timer->adjust(attotime::from_usec(50), offset & 7); } uint8_t balsente_state::teamht_extra_r() diff --git a/src/mame/machine/bbc.cpp b/src/mame/machine/bbc.cpp index 3cd5f5f24c1..3bc221a57c1 100644 --- a/src/mame/machine/bbc.cpp +++ b/src/mame/machine/bbc.cpp @@ -1374,8 +1374,8 @@ void bbc_state::init_bbc() m_nr_high_tones = 0; m_serproc_data = 0; m_cass_out_enabled = 0; - m_tape_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(bbc_state::tape_timer_cb), this)); - m_reset_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(bbc_state::reset_timer_cb), this)); + m_tape_timer = timer_alloc(FUNC(bbc_state::tape_timer_cb), this); + m_reset_timer = timer_alloc(FUNC(bbc_state::reset_timer_cb), this); /* vertical sync pulse from video circuit */ m_via6522_0->write_ca1(1); diff --git a/src/mame/machine/bebox.cpp b/src/mame/machine/bebox.cpp index 97998b73473..dda04ddb2b0 100644 --- a/src/mame/machine/bebox.cpp +++ b/src/mame/machine/bebox.cpp @@ -726,18 +726,6 @@ void bebox_state::scsi53c810_pci_write(int function, int offset, uint32_t data, } -void bebox_state::device_timer(emu_timer &timer, device_timer_id id, int param) -{ - switch (id) - { - case TIMER_GET_DEVICES: - break; - default: - throw emu_fatalerror("Unknown id in bebox_state::device_timer"); - } -} - - /************************************* * * Driver main @@ -746,8 +734,6 @@ void bebox_state::device_timer(emu_timer &timer, device_timer_id id, int param) void bebox_state::machine_reset() { - timer_set(attotime::zero, TIMER_GET_DEVICES); - m_ppc[0]->set_input_line(INPUT_LINE_RESET, CLEAR_LINE); m_ppc[1]->set_input_line(INPUT_LINE_RESET, ASSERT_LINE); diff --git a/src/mame/machine/bk.cpp b/src/mame/machine/bk.cpp index d9c5a7c6907..9a5ab095316 100644 --- a/src/mame/machine/bk.cpp +++ b/src/mame/machine/bk.cpp @@ -63,7 +63,7 @@ void bk_state::machine_start() m_maincpu->set_input_line(t11_device::VEC_LINE, ASSERT_LINE); - m_kbd_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(bk_state::keyboard_callback), this)); + m_kbd_timer = timer_alloc(FUNC(bk_state::keyboard_callback), this); m_kbd_timer->adjust(attotime::from_hz(2400), 0, attotime::from_hz(2400)); } diff --git a/src/mame/machine/bublbobl.cpp b/src/mame/machine/bublbobl.cpp index 59784418ca3..659bcda1027 100644 --- a/src/mame/machine/bublbobl.cpp +++ b/src/mame/machine/bublbobl.cpp @@ -127,16 +127,9 @@ uint8_t bublbobl_state::tokiob_mcu_r() } -void bublbobl_state::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(bublbobl_state::irq_ack) { - switch (id) - { - case TIMER_M68705_IRQ_ACK: - m_mcu->set_input_line(0, CLEAR_LINE); - break; - default: - throw emu_fatalerror("Unknown id in bublbobl_state::device_timer"); - } + m_mcu->set_input_line(0, CLEAR_LINE); } void bublbobl_state::bublbobl_soundcpu_reset_w(uint8_t data) @@ -331,7 +324,7 @@ uint8_t bublbobl_state::boblbobl_ic43_b_r(offs_t offset) INTERRUPT_GEN_MEMBER(bub68705_state::bublbobl_m68705_interrupt) { device.execute().set_input_line(M68705_IRQ_LINE, ASSERT_LINE); - timer_set(attotime::from_msec(1000/60), TIMER_M68705_IRQ_ACK); /* TODO: understand how this is ack'ed */ + m_irq_ack_timer->adjust(attotime::from_msec(1000/60)); /* TODO: understand how this is ack'ed */ } diff --git a/src/mame/machine/cdicdic.cpp b/src/mame/machine/cdicdic.cpp index 6786f3c69b4..95b181e1475 100644 --- a/src/mame/machine/cdicdic.cpp +++ b/src/mame/machine/cdicdic.cpp @@ -1527,10 +1527,10 @@ void cdicdic_device::device_start() save_item(NAME(m_xa_last)); - m_audio_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(cdicdic_device::audio_tick), this)); + m_audio_timer = timer_alloc(FUNC(cdicdic_device::audio_tick), this); m_audio_timer->adjust(attotime::never); - m_sector_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(cdicdic_device::sector_tick), this)); + m_sector_timer = timer_alloc(FUNC(cdicdic_device::sector_tick), this); m_sector_timer->adjust(attotime::never); } diff --git a/src/mame/machine/cdislavehle.cpp b/src/mame/machine/cdislavehle.cpp index 4c103f24a37..21812cc85f5 100644 --- a/src/mame/machine/cdislavehle.cpp +++ b/src/mame/machine/cdislavehle.cpp @@ -471,7 +471,7 @@ void cdislave_hle_device::device_start() save_item(NAME(m_device_mouse_x)); save_item(NAME(m_device_mouse_y)); - m_interrupt_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(cdislave_hle_device::trigger_readback_int), this)); + m_interrupt_timer = timer_alloc(FUNC(cdislave_hle_device::trigger_readback_int), this); m_interrupt_timer->adjust(attotime::never); } diff --git a/src/mame/machine/cedar_magnet_board.cpp b/src/mame/machine/cedar_magnet_board.cpp index 2cffb11abb3..f4dc1c723af 100644 --- a/src/mame/machine/cedar_magnet_board.cpp +++ b/src/mame/machine/cedar_magnet_board.cpp @@ -82,8 +82,8 @@ void cedar_magnet_board_interface::interface_pre_reset() void cedar_magnet_board_interface::interface_pre_start() { - m_halt_assert_timer = device().machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(cedar_magnet_board_interface::halt_assert_callback), this)); - m_halt_clear_timer = device().machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(cedar_magnet_board_interface::halt_clear_callback), this)); - m_reset_assert_timer = device().machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(cedar_magnet_board_interface::reset_assert_callback), this)); - m_reset_clear_timer = device().machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(cedar_magnet_board_interface::reset_clear_callback), this)); + m_halt_assert_timer = device().timer_alloc(FUNC(cedar_magnet_board_interface::halt_assert_callback), this); + m_halt_clear_timer = device().timer_alloc(FUNC(cedar_magnet_board_interface::halt_clear_callback), this); + m_reset_assert_timer = device().timer_alloc(FUNC(cedar_magnet_board_interface::reset_assert_callback), this); + m_reset_clear_timer = device().timer_alloc(FUNC(cedar_magnet_board_interface::reset_clear_callback), this); } diff --git a/src/mame/machine/cmi_mkbd.cpp b/src/mame/machine/cmi_mkbd.cpp index 126b8da9e93..f4b3a2a987a 100644 --- a/src/mame/machine/cmi_mkbd.cpp +++ b/src/mame/machine/cmi_mkbd.cpp @@ -73,22 +73,17 @@ void cmi_music_keyboard_device::device_resolve_objects() void cmi_music_keyboard_device::device_start() { - m_cmi10_scnd_timer = timer_alloc(TIMER_CMI10_SCND); - + m_cmi10_scnd_timer = timer_alloc(FUNC(cmi_music_keyboard_device::scnd_update), this); m_cmi10_scnd_timer->adjust(attotime::from_hz(4000000 / 4 / 2048 / 2), 0, attotime::from_hz(4000000 / 4 / 2048 / 2)); + m_scnd = 0; } -void cmi_music_keyboard_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(cmi_music_keyboard_device::scnd_update) { - switch (id) - { - case TIMER_CMI10_SCND: - m_cmi10_pia_u20->ca1_w(m_scnd); - m_scnd ^= 1; - m_cmi10_pia_u21->ca1_w(m_scnd); - break; - } + m_cmi10_pia_u20->ca1_w(m_scnd); + m_scnd ^= 1; + m_cmi10_pia_u21->ca1_w(m_scnd); } /* diff --git a/src/mame/machine/cmi_mkbd.h b/src/mame/machine/cmi_mkbd.h index e1ab74bd6ac..8891f0cd090 100644 --- a/src/mame/machine/cmi_mkbd.h +++ b/src/mame/machine/cmi_mkbd.h @@ -17,8 +17,6 @@ class cmi_music_keyboard_device : public device_t { - static const device_timer_id TIMER_CMI10_SCND = 0; - public: cmi_music_keyboard_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock = 0); @@ -38,7 +36,8 @@ protected: virtual ioport_constructor device_input_ports() const override; virtual void device_resolve_objects() override; virtual void device_start() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; + + TIMER_CALLBACK_MEMBER(scnd_update); private: void cmi10_u20_a_w(u8 data); diff --git a/src/mame/machine/coco.cpp b/src/mame/machine/coco.cpp index ee2d19a1b62..c2de273d41e 100644 --- a/src/mame/machine/coco.cpp +++ b/src/mame/machine/coco.cpp @@ -137,9 +137,9 @@ void coco_state::device_start() DIECOM_LIGHTGUN_LX_TAG, DIECOM_LIGHTGUN_LY_TAG, DIECOM_LIGHTGUN_BUTTONS_TAG); // timers - m_hiresjoy_transition_timer[0] = timer_alloc(TIMER_HIRES_JOYSTICK_X); - m_hiresjoy_transition_timer[1] = timer_alloc(TIMER_HIRES_JOYSTICK_Y); - m_diecom_lightgun_timer = timer_alloc(TIMER_DIECOM_LIGHTGUN); + m_hiresjoy_transition_timer[0] = timer_alloc(FUNC(coco_state::joystick_update), this); + m_hiresjoy_transition_timer[1] = timer_alloc(FUNC(coco_state::joystick_update), this); + m_diecom_lightgun_timer = timer_alloc(FUNC(coco_state::diecom_lightgun_hit), this); // cart slot m_cococart->set_cart_base_update(cococart_base_update_delegate(&coco_state::update_cart_base, this)); @@ -187,21 +187,18 @@ void coco_state::device_reset() //------------------------------------------------- -// device_timer +// timer callbacks //------------------------------------------------- -void coco_state::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(coco_state::diecom_lightgun_hit) { - switch(id) - { - case TIMER_DIECOM_LIGHTGUN: - m_dclg_output_h |= 0x02; - [[fallthrough]]; - case TIMER_HIRES_JOYSTICK_X: - case TIMER_HIRES_JOYSTICK_Y: - poll_keyboard(); - break; - } + m_dclg_output_h |= 0x02; + poll_keyboard(); +} + +TIMER_CALLBACK_MEMBER(coco_state::joystick_update) +{ + poll_keyboard(); } diff --git a/src/mame/machine/cuda.cpp b/src/mame/machine/cuda.cpp index 39cad3032c0..d91112fe5fb 100644 --- a/src/mame/machine/cuda.cpp +++ b/src/mame/machine/cuda.cpp @@ -395,8 +395,8 @@ void cuda_device::device_start() write_via_clock.resolve_safe(); write_via_data.resolve_safe(); - m_timer = timer_alloc(0); - m_prog_timer = timer_alloc(1); + m_timer = timer_alloc(FUNC(cuda_device::seconds_tick), this); + m_prog_timer = timer_alloc(FUNC(cuda_device::timer_tick), this); save_item(NAME(ddrs[0])); save_item(NAME(ddrs[1])); save_item(NAME(ddrs[2])); @@ -457,37 +457,35 @@ void cuda_device::device_reset() last_adb = 0; } -void cuda_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(cuda_device::seconds_tick) { - if (id == 0) + onesec |= 0x40; + + if (onesec & 0x10) { - onesec |= 0x40; + m_maincpu->set_input_line(M68HC05EG_INT_CPI, ASSERT_LINE); + } +} - if (onesec & 0x10) - { - m_maincpu->set_input_line(M68HC05EG_INT_CPI, ASSERT_LINE); - } +TIMER_CALLBACK_MEMBER(cuda_device::timer_tick) +{ + timer_ctrl |= 0x80; + + if (timer_ctrl & 0x20) + { + m_maincpu->set_input_line(M68HC05EG_INT_TIMER, ASSERT_LINE); } - else + + ripple_counter--; + if (ripple_counter <= 0) { - timer_ctrl |= 0x80; + timer_ctrl |= 0x40; - if (timer_ctrl & 0x20) - { - m_maincpu->set_input_line(M68HC05EG_INT_TIMER, ASSERT_LINE); - } + ripple_counter = timer_counter; - ripple_counter--; - if (ripple_counter <= 0) + if (timer_ctrl & 0x10) { - timer_ctrl |= 0x40; - - ripple_counter = timer_counter; - - if (timer_ctrl & 0x10) - { - m_maincpu->set_input_line(M68HC05EG_INT_TIMER, ASSERT_LINE); - } + m_maincpu->set_input_line(M68HC05EG_INT_TIMER, ASSERT_LINE); } } } diff --git a/src/mame/machine/cuda.h b/src/mame/machine/cuda.h index db22197f20b..b6ccf42a755 100644 --- a/src/mame/machine/cuda.h +++ b/src/mame/machine/cuda.h @@ -85,9 +85,10 @@ protected: virtual void device_add_mconfig(machine_config &config) override; virtual const tiny_rom_entry *device_rom_region() const override; - required_device<cpu_device> m_maincpu; + TIMER_CALLBACK_MEMBER(seconds_tick); + TIMER_CALLBACK_MEMBER(timer_tick); - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; + required_device<cpu_device> m_maincpu; private: uint8_t ddrs[3]{}; diff --git a/src/mame/machine/dc.cpp b/src/mame/machine/dc.cpp index 0698f187d3b..c0faebb7673 100644 --- a/src/mame/machine/dc.cpp +++ b/src/mame/machine/dc.cpp @@ -407,7 +407,7 @@ void dc_state::dc_sysctrl_w(offs_t offset, uint64_t data, uint64_t mem_mask) dc_sysctrl_regs[SB_C2DSTAT]=address+ddtdata.length; /* TODO: timing is a guess */ - machine().scheduler().timer_set(m_maincpu->cycles_to_attotime(ddtdata.length/4), timer_expired_delegate(FUNC(dc_state::ch2_dma_irq),this)); + m_ch2_dma_irq_timer->adjust(m_maincpu->cycles_to_attotime(ddtdata.length/4)); } break; @@ -548,6 +548,8 @@ void dc_state::machine_start() // save states save_pointer(NAME(dc_sysctrl_regs), 0x200/4); + + m_ch2_dma_irq_timer = timer_alloc(FUNC(dc_state::ch2_dma_irq), this); } void dc_state::machine_reset() @@ -559,6 +561,8 @@ void dc_state::machine_reset() memset(dc_sysctrl_regs, 0, sizeof(dc_sysctrl_regs)); dc_sysctrl_regs[SB_SBREV] = 0x0b; + + m_ch2_dma_irq_timer->adjust(attotime::never); } uint32_t dc_state::dc_aica_reg_r(offs_t offset, uint32_t mem_mask) diff --git a/src/mame/machine/dc_g2if.cpp b/src/mame/machine/dc_g2if.cpp index a75bf4b0f37..9929a2844fc 100644 --- a/src/mame/machine/dc_g2if.cpp +++ b/src/mame/machine/dc_g2if.cpp @@ -74,7 +74,7 @@ void dc_g2if_device::device_start() { for (int i = 0; i < 4; i++) { - m_dma[i].end_timer = timer_alloc(i); + m_dma[i].end_timer = timer_alloc(FUNC(dc_g2if_device::dma_end_tick), this); } m_int_w.resolve(); @@ -121,13 +121,13 @@ void dc_g2if_device::device_reset() } } -void dc_g2if_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(dc_g2if_device::dma_end_tick) { - u8 channel = (u8)id; - bool dma_result = (param == 1); + u8 channel = (u8)(param >> 1); + bool dma_result = (param & 1); m_dma[channel].in_progress = false; m_dma[channel].start = false; - LOGDMAEND("DMA%d %s\n", id, dma_result ? "normal end" : "overflow error"); + LOGDMAEND("DMA%d %s\n", channel, dma_result ? "normal end" : "overflow error"); if (dma_result) m_int_w(channel, 1); @@ -510,7 +510,7 @@ void dc_g2if_device::dma_execute(u8 channel) if (m_dma[channel].mode == true) m_dma[channel].enable = false; - m_dma[channel].end_timer->adjust(dma_time, dma_result); + m_dma[channel].end_timer->adjust(dma_time, (channel << 1) | (dma_result ? 1 : 0)); } /* diff --git a/src/mame/machine/dc_g2if.h b/src/mame/machine/dc_g2if.h index 5cf0888b563..c598307b441 100644 --- a/src/mame/machine/dc_g2if.h +++ b/src/mame/machine/dc_g2if.h @@ -35,7 +35,8 @@ 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; + + TIMER_CALLBACK_MEMBER(dma_end_tick); private: required_address_space m_host_space; diff --git a/src/mame/machine/dccons.cpp b/src/mame/machine/dccons.cpp index ba8ed4ba1c2..07c1a95afde 100644 --- a/src/mame/machine/dccons.cpp +++ b/src/mame/machine/dccons.cpp @@ -104,9 +104,7 @@ TIMER_CALLBACK_MEMBER(dc_cons_state::atapi_xfer_end ) void dc_cons_state::dreamcast_atapi_init() { - atapi_timer = machine().scheduler().timer_alloc( - timer_expired_delegate(FUNC(dc_cons_state::atapi_xfer_end), this) - ); + atapi_timer = timer_alloc(FUNC(dc_cons_state::atapi_xfer_end), this); atapi_timer->adjust(attotime::never); save_item(NAME(atapi_xferlen)); save_item(NAME(atapi_xferbase)); diff --git a/src/mame/machine/dec_lk201.cpp b/src/mame/machine/dec_lk201.cpp index 4bf0ad985bc..1e1a87a3011 100644 --- a/src/mame/machine/dec_lk201.cpp +++ b/src/mame/machine/dec_lk201.cpp @@ -523,10 +523,10 @@ lk201_device::lk201_device(const machine_config &mconfig, const char *tag, devic void lk201_device::device_start() { - m_count = timer_alloc(1); + m_count = timer_alloc(FUNC(lk201_device::timer_irq), this); m_tx_handler.resolve_safe(); - m_beeper = timer_alloc(2); + m_beeper = timer_alloc(FUNC(lk201_device::beeper_off), this); m_led_wait.resolve(); m_led_compose.resolve(); @@ -572,27 +572,19 @@ void lk201_device::device_reset() m_led_hold = 0; // led11 } -void lk201_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(lk201_device::timer_irq) { - switch (id) - { - case 1: - m_timer.tsr |= TSR_OCFL; - - if ((m_timer.tcr & TCR_OCIE) && (m_timer.tsr & TSR_OCFL)) - m_maincpu->set_input_line(M68HC05EG_INT_TIMER, ASSERT_LINE); - break; + m_timer.tsr |= TSR_OCFL; - case 2: - m_speaker->set_output_gain(0, 0); - m_speaker->set_state(0); - break; - - default: - break; - } + if ((m_timer.tcr & TCR_OCIE) && (m_timer.tsr & TSR_OCFL)) + m_maincpu->set_input_line(M68HC05EG_INT_TIMER, ASSERT_LINE); } +TIMER_CALLBACK_MEMBER(lk201_device::beeper_off) +{ + m_speaker->set_output_gain(0, 0); + m_speaker->set_state(0); +} void lk201_device::rcv_complete() { diff --git a/src/mame/machine/dec_lk201.h b/src/mame/machine/dec_lk201.h index 59881d309a4..9ed6d7c5368 100644 --- a/src/mame/machine/dec_lk201.h +++ b/src/mame/machine/dec_lk201.h @@ -67,13 +67,15 @@ protected: virtual ioport_constructor device_input_ports() const 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_serial overrides virtual void rcv_complete() override; // Rx completed receiving byte virtual void tra_complete() override; // Tx completed sending byte virtual void tra_callback() override; // Tx send bit + TIMER_CALLBACK_MEMBER(timer_irq); + TIMER_CALLBACK_MEMBER(beeper_off); + private: uint8_t ddrs[3]; uint8_t ports[3]; diff --git a/src/mame/machine/deco_irq.cpp b/src/mame/machine/deco_irq.cpp index ce4bac5c0a2..f164e481444 100644 --- a/src/mame/machine/deco_irq.cpp +++ b/src/mame/machine/deco_irq.cpp @@ -74,7 +74,7 @@ void deco_irq_device::device_start() m_vblank_irq_cb.resolve_safe(); // allocate scanline timer and start it - m_scanline_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(deco_irq_device::scanline_callback), this)); + m_scanline_timer = timer_alloc(FUNC(deco_irq_device::scanline_callback), this); m_scanline_timer->adjust(m_screen->time_until_pos(0)); // register for save states diff --git a/src/mame/machine/decocass_tape.cpp b/src/mame/machine/decocass_tape.cpp index a42c44639e6..1dc296ae3f4 100644 --- a/src/mame/machine/decocass_tape.cpp +++ b/src/mame/machine/decocass_tape.cpp @@ -84,7 +84,7 @@ void decocass_tape_device::device_start() int curblock, offs, numblocks; /* fetch the data pointer */ - m_tape_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(decocass_tape_device::tape_clock_callback), this)); + m_tape_timer = timer_alloc(FUNC(decocass_tape_device::tape_clock_callback), this); if (!m_tape_data.found()) return; diff --git a/src/mame/machine/decopincpu.cpp b/src/mame/machine/decopincpu.cpp index 138c8b683c5..ee86912bc33 100644 --- a/src/mame/machine/decopincpu.cpp +++ b/src/mame/machine/decopincpu.cpp @@ -56,28 +56,23 @@ static INPUT_PORTS_START( decocpu1 ) PORT_CONFSETTING( 0x10, "English" ) INPUT_PORTS_END -void decocpu_type1_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(decocpu_type1_device::irq_trigger) { - switch(id) + if (param == 1) { - case TIMER_IRQ: - if(param == 1) - { - m_cpu->set_input_line(M6808_IRQ_LINE, ASSERT_LINE); - m_irq_timer->adjust(attotime::from_ticks(32,E_CLOCK),0); - m_irq_active = true; - m_pia28->ca1_w(BIT(ioport("DIAGS")->read(), 2)); - m_pia28->cb1_w(BIT(ioport("DIAGS")->read(), 3)); - } - else - { - m_cpu->set_input_line(M6808_IRQ_LINE, CLEAR_LINE); - m_irq_timer->adjust(attotime::from_ticks(S11_IRQ_CYCLES,E_CLOCK),1); - m_irq_active = false; - m_pia28->ca1_w(1); - m_pia28->cb1_w(1); - } - break; + m_cpu->set_input_line(M6808_IRQ_LINE, ASSERT_LINE); + m_irq_timer->adjust(attotime::from_ticks(32, E_CLOCK), 0); + m_irq_active = true; + m_pia28->ca1_w(BIT(m_diags->read(), 2)); + m_pia28->cb1_w(BIT(m_diags->read(), 3)); + } + else + { + m_cpu->set_input_line(M6808_IRQ_LINE, CLEAR_LINE); + m_irq_timer->adjust(attotime::from_ticks(S11_IRQ_CYCLES, E_CLOCK), 1); + m_irq_active = false; + m_pia28->ca1_w(1); + m_pia28->cb1_w(1); } } @@ -90,10 +85,10 @@ INPUT_CHANGED_MEMBER( decocpu_type1_device::main_nmi ) WRITE_LINE_MEMBER(decocpu_type1_device::cpu_pia_irq) { - if(state == CLEAR_LINE) + if (state == CLEAR_LINE) { // restart IRQ timer - m_irq_timer->adjust(attotime::from_ticks(S11_IRQ_CYCLES,E_CLOCK),1); + m_irq_timer->adjust(attotime::from_ticks(S11_IRQ_CYCLES, E_CLOCK), 1); m_irq_active = false; } else @@ -105,93 +100,93 @@ WRITE_LINE_MEMBER(decocpu_type1_device::cpu_pia_irq) } } -void decocpu_type1_device::lamp0_w(uint8_t data) +void decocpu_type1_device::lamp0_w(u8 data) { m_cpu->set_input_line(M6808_IRQ_LINE, CLEAR_LINE); m_lamp_data = data ^ 0xff; - m_write_lamp(0,data,0xff); + m_write_lamp(0, data, 0xff); } -void decocpu_type1_device::lamp1_w(uint8_t data) +void decocpu_type1_device::lamp1_w(u8 data) { for (u8 i = 0; i < 8; i++) if (BIT(data, i)) for (u8 j = 0; j < 8; j++) - m_io_outputs[22U+i*8U+j] = BIT(m_lamp_data, j); + m_io_outputs[22 + i * 8 + j] = BIT(m_lamp_data, j); - m_write_lamp(1,data,0xff); + m_write_lamp(1, data, 0xff); } -uint8_t decocpu_type1_device::display_strobe_r() +u8 decocpu_type1_device::display_strobe_r() { - uint8_t ret = 0x80; + u8 ret = 0x80; - if(BIT(ioport("DIAGS")->read(), 4)) // W7 Jumper + if (BIT(m_diags->read(), 4)) // W7 Jumper ret &= ~0x80; return ret | (m_read_display(0) & 0x7f); } -void decocpu_type1_device::display_strobe_w(uint8_t data) +void decocpu_type1_device::display_strobe_w(u8 data) { - m_write_display(0,data,0xff); + m_write_display(0, data, 0xff); } -void decocpu_type1_device::display_out1_w(uint8_t data) +void decocpu_type1_device::display_out1_w(u8 data) { - m_write_display(1,data,0xff); + m_write_display(1, data, 0xff); } -void decocpu_type1_device::display_out2_w(uint8_t data) +void decocpu_type1_device::display_out2_w(u8 data) { - m_write_display(2,data,0xff); + m_write_display(2, data, 0xff); } -void decocpu_type1_device::display_out3_w(uint8_t data) +void decocpu_type1_device::display_out3_w(u8 data) { - m_write_display(3,data,0xff); + m_write_display(3, data, 0xff); } -uint8_t decocpu_type1_device::display_in3_r() +u8 decocpu_type1_device::display_in3_r() { return m_read_display(3); } -void decocpu_type1_device::switch_w(uint8_t data) +void decocpu_type1_device::switch_w(u8 data) { - m_write_switch(0,data,0xff); + m_write_switch(0, data, 0xff); } -uint8_t decocpu_type1_device::switch_r() +u8 decocpu_type1_device::switch_r() { return m_read_switch(0); } -uint8_t decocpu_type1_device::dmdstatus_r() +u8 decocpu_type1_device::dmdstatus_r() { return m_read_dmdstatus(0); } -void decocpu_type1_device::display_out4_w(uint8_t data) +void decocpu_type1_device::display_out4_w(u8 data) { - m_write_display(4,data,0xff); + m_write_display(4, data, 0xff); } -void decocpu_type1_device::sound_w(uint8_t data) +void decocpu_type1_device::sound_w(u8 data) { - m_write_soundlatch(0,data,0xff); + m_write_soundlatch(0, data, 0xff); } -void decocpu_type1_device::solenoid1_w(uint8_t data) +void decocpu_type1_device::solenoid1_w(u8 data) { - m_write_solenoid(1,data,0xff); + m_write_solenoid(1, data, 0xff); for (u8 i = 0; i < 8; i++) - m_io_outputs[i+8] = BIT(data, i); + m_io_outputs[i + 8] = BIT(data, i); } -void decocpu_type1_device::solenoid0_w(uint8_t data) +void decocpu_type1_device::solenoid0_w(u8 data) { - m_write_solenoid(0,data,0xff); + m_write_solenoid(0, data, 0xff); for (u8 i = 0; i < 8; i++) m_io_outputs[i] = BIT(data, i); } @@ -257,11 +252,12 @@ ioport_constructor decocpu_type1_device::device_input_ports() const return INPUT_PORTS_NAME( decocpu1 ); } -decocpu_type1_device::decocpu_type1_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) +decocpu_type1_device::decocpu_type1_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock) : decocpu_type1_device(mconfig, DECOCPU1, tag, owner, clock) -{} +{ +} -decocpu_type1_device::decocpu_type1_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock) +decocpu_type1_device::decocpu_type1_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, u32 clock) : device_t(mconfig, type, tag, owner, clock) , m_cpu(*this,"maincpu") , m_pia21(*this, "pia21") @@ -271,6 +267,7 @@ decocpu_type1_device::decocpu_type1_device(const machine_config &mconfig, device , m_pia30(*this, "pia30") , m_pia34(*this, "pia34") , m_rom(*this, finder_base::DUMMY_TAG) + , m_diags(*this, "DIAGS") , m_read_display(*this) , m_write_display(*this) , m_read_dmdstatus(*this) @@ -280,7 +277,8 @@ decocpu_type1_device::decocpu_type1_device(const machine_config &mconfig, device , m_write_lamp(*this) , m_write_solenoid(*this) , m_io_outputs(*this, "out%d", 0U) -{} +{ +} void decocpu_type1_device::device_start() { @@ -294,23 +292,25 @@ void decocpu_type1_device::device_start() m_write_lamp.resolve_safe(); m_write_solenoid.resolve_safe(); - m_irq_timer = timer_alloc(TIMER_IRQ); - m_irq_timer->adjust(attotime::from_ticks(S11_IRQ_CYCLES,E_CLOCK),1); + m_irq_timer = timer_alloc(FUNC(decocpu_type1_device::irq_trigger), this); + m_irq_timer->adjust(attotime::from_ticks(S11_IRQ_CYCLES, E_CLOCK), 1); m_irq_active = false; - m_cpu->space(AS_PROGRAM).install_rom(0x4000,0xffff,&m_rom[0x4000]); + m_cpu->space(AS_PROGRAM).install_rom(0x4000, 0xffff, &m_rom[0x4000]); m_io_outputs.resolve(); save_item(NAME(m_lamp_data)); } -decocpu_type2_device::decocpu_type2_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) +decocpu_type2_device::decocpu_type2_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock) : decocpu_type2_device(mconfig, DECOCPU2, tag, owner, clock) -{} +{ +} -decocpu_type2_device::decocpu_type2_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock) +decocpu_type2_device::decocpu_type2_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, u32 clock) : decocpu_type1_device(mconfig, type, tag, owner, clock) -{} +{ +} void decocpu_type2_device::device_add_mconfig(machine_config &config) { @@ -325,22 +325,25 @@ void decocpu_type2_device::device_start() decocpu_type1_device::device_start(); } -decocpu_type3_device::decocpu_type3_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) +decocpu_type3_device::decocpu_type3_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock) : decocpu_type3_device(mconfig, DECOCPU3, tag, owner, clock) -{} +{ +} -decocpu_type3_device::decocpu_type3_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock) +decocpu_type3_device::decocpu_type3_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, u32 clock) : decocpu_type2_device(mconfig, type, tag, owner, clock) -{} +{ +} void decocpu_type3_device::device_start() { decocpu_type1_device::device_start(); } -decocpu_type3b_device::decocpu_type3b_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) +decocpu_type3b_device::decocpu_type3b_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock) : decocpu_type3_device(mconfig, DECOCPU3B, tag, owner, clock) -{} +{ +} void decocpu_type3b_device::device_start() { diff --git a/src/mame/machine/decopincpu.h b/src/mame/machine/decopincpu.h index 754919195a2..e74a0fe06a2 100644 --- a/src/mame/machine/decopincpu.h +++ b/src/mame/machine/decopincpu.h @@ -29,13 +29,13 @@ class decocpu_type1_device : public device_t { public: template <typename T> - decocpu_type1_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock, T &&cpuregion_tag) + decocpu_type1_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock, T &&cpuregion_tag) : decocpu_type1_device(mconfig, tag, owner, clock) { set_cpuregion(std::forward<T>(cpuregion_tag)); } - decocpu_type1_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock); + decocpu_type1_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock); // callbacks auto display_read_callback() { return m_read_display.bind(); } @@ -52,16 +52,16 @@ public: template <typename T> void set_cpuregion(T &&tag) { m_rom.set_tag(std::forward<T>(tag)); } // region for cpu board code and data protected: - static constexpr device_timer_id TIMER_IRQ = 0; - void solenoid0_w(uint8_t data); + void solenoid0_w(u8 data); - decocpu_type1_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock); + decocpu_type1_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, u32 clock); // overrides virtual void device_add_mconfig(machine_config &config) override; virtual void device_start() override; virtual ioport_constructor device_input_ports() const override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; + + TIMER_CALLBACK_MEMBER(irq_trigger); void decocpu1_map(address_map &map); @@ -72,7 +72,8 @@ protected: required_device<pia6821_device> m_pia2c; required_device<pia6821_device> m_pia30; required_device<pia6821_device> m_pia34; - required_region_ptr<uint8_t> m_rom; + required_region_ptr<u8> m_rom; + required_ioport m_diags; private: emu_timer* m_irq_timer = 0; @@ -98,37 +99,37 @@ private: DECLARE_WRITE_LINE_MEMBER(pia2c_cb2_w) { m_io_outputs[17] = state; } DECLARE_WRITE_LINE_MEMBER(pia30_ca2_w) { m_io_outputs[19] = state; } DECLARE_WRITE_LINE_MEMBER(pia30_cb2_w) { m_io_outputs[16] = state; } - void lamp0_w(uint8_t data); - void lamp1_w(uint8_t data); - uint8_t display_strobe_r(); - void display_strobe_w(uint8_t data); - void display_out1_w(uint8_t data); - void display_out2_w(uint8_t data); - void display_out3_w(uint8_t data); - void display_out4_w(uint8_t data); - uint8_t display_in3_r(); - void switch_w(uint8_t data); - uint8_t switch_r(); - uint8_t dmdstatus_r(); - void sound_w(uint8_t data); - void solenoid1_w(uint8_t data); + void lamp0_w(u8 data); + void lamp1_w(u8 data); + u8 display_strobe_r(); + void display_strobe_w(u8 data); + void display_out1_w(u8 data); + void display_out2_w(u8 data); + void display_out3_w(u8 data); + void display_out4_w(u8 data); + u8 display_in3_r(); + void switch_w(u8 data); + u8 switch_r(); + u8 dmdstatus_r(); + void sound_w(u8 data); + void solenoid1_w(u8 data); }; class decocpu_type2_device : public decocpu_type1_device { public: template <typename T> - decocpu_type2_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock, T &&cpuregion_tag) + decocpu_type2_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock, T &&cpuregion_tag) : decocpu_type2_device(mconfig, tag, owner, clock) { set_cpuregion(std::forward<T>(cpuregion_tag)); } - decocpu_type2_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock); + decocpu_type2_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock); void decocpu2_map(address_map &map); protected: - decocpu_type2_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock); + decocpu_type2_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, u32 clock); // overrides virtual void device_add_mconfig(machine_config &config) override; @@ -139,16 +140,16 @@ class decocpu_type3_device : public decocpu_type2_device { public: template <typename T> - decocpu_type3_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock, T &&cpuregion_tag) + decocpu_type3_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock, T &&cpuregion_tag) : decocpu_type3_device(mconfig, tag, owner, clock) { set_cpuregion(std::forward<T>(cpuregion_tag)); } - decocpu_type3_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock); + decocpu_type3_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock); protected: - decocpu_type3_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock); + decocpu_type3_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, u32 clock); // overrides virtual void device_start() override; @@ -158,13 +159,13 @@ class decocpu_type3b_device : public decocpu_type3_device { public: template <typename T> - decocpu_type3b_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock, T &&cpuregion_tag) + decocpu_type3b_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock, T &&cpuregion_tag) : decocpu_type3b_device(mconfig, tag, owner, clock) { set_cpuregion(std::forward<T>(cpuregion_tag)); } - decocpu_type3b_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock); + decocpu_type3b_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock); protected: // overrides diff --git a/src/mame/machine/dmac_0266.cpp b/src/mame/machine/dmac_0266.cpp index 8b873924cfa..22f1402ad0a 100644 --- a/src/mame/machine/dmac_0266.cpp +++ b/src/mame/machine/dmac_0266.cpp @@ -58,7 +58,7 @@ void dmac_0266_device::device_start() save_item(NAME(m_req_state)); - m_dma_check = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(dmac_0266_device::dma_check), this)); + m_dma_check = timer_alloc(FUNC(dmac_0266_device::dma_check), this); m_req_state = false; } diff --git a/src/mame/machine/dmac_0448.cpp b/src/mame/machine/dmac_0448.cpp index 95c64e9f530..365df3e9582 100644 --- a/src/mame/machine/dmac_0448.cpp +++ b/src/mame/machine/dmac_0448.cpp @@ -54,8 +54,8 @@ void dmac_0448_device::device_start() m_dma_r.resolve_all_safe(0); m_dma_w.resolve_all_safe(); - m_irq_check = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(dmac_0448_device::irq_check), this)); - m_dma_check = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(dmac_0448_device::dma_check), this)); + m_irq_check = timer_alloc(FUNC(dmac_0448_device::irq_check), this); + m_dma_check = timer_alloc(FUNC(dmac_0448_device::dma_check), this); m_out_int_state = false; m_gsel = 0; diff --git a/src/mame/machine/egret.cpp b/src/mame/machine/egret.cpp index 9af4be4d36e..3abaa99260f 100644 --- a/src/mame/machine/egret.cpp +++ b/src/mame/machine/egret.cpp @@ -399,7 +399,7 @@ void egret_device::device_start() } #endif - m_timer = timer_alloc(0); + m_timer = timer_alloc(FUNC(egret_device::seconds_tick), this); save_item(NAME(ddrs[0])); save_item(NAME(ddrs[1])); save_item(NAME(ddrs[2])); @@ -468,7 +468,7 @@ void egret_device::device_reset() last_adb = 0; } -void egret_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(egret_device::seconds_tick) { onesec |= 0x40; diff --git a/src/mame/machine/egret.h b/src/mame/machine/egret.h index 91fc4fd0683..f82c4a2e203 100644 --- a/src/mame/machine/egret.h +++ b/src/mame/machine/egret.h @@ -96,9 +96,9 @@ protected: virtual void device_add_mconfig(machine_config &config) override; virtual const tiny_rom_entry *device_rom_region() const override; - required_device<cpu_device> m_maincpu; + TIMER_CALLBACK_MEMBER(seconds_tick); - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; + required_device<cpu_device> m_maincpu; private: uint8_t ddrs[3]{}; @@ -107,14 +107,20 @@ private: uint8_t timer_ctrl = 0; uint8_t timer_counter = 0; uint8_t onesec = 0; - uint8_t xcvr_session = 0, via_full = 0, sys_session = 0, via_data = 0, via_clock = 0, last_adb = 0; + uint8_t xcvr_session = 0; + uint8_t via_full = 0; + uint8_t sys_session = 0; + uint8_t via_data = 0; + uint8_t via_clock = 0; + uint8_t last_adb = 0; uint64_t last_adb_time = 0; bool egret_controls_power = false; bool adb_in = false; int reset_line = 0; int m_adb_dtime = 0; emu_timer *m_timer = nullptr; - uint8_t pram[0x100]{}, disk_pram[0x100]{}; + uint8_t pram[0x100]{}; + uint8_t disk_pram[0x100]{}; bool pram_loaded = false; #if USE_BUS_ADB diff --git a/src/mame/machine/elan_eu3a05commonsys.cpp b/src/mame/machine/elan_eu3a05commonsys.cpp index 638bbe6e459..f785ad2fe75 100644 --- a/src/mame/machine/elan_eu3a05commonsys.cpp +++ b/src/mame/machine/elan_eu3a05commonsys.cpp @@ -228,19 +228,12 @@ void elan_eu3a05commonsys_device::map(address_map &map) } -void elan_eu3a05commonsys_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(elan_eu3a05commonsys_device::unknown_timer_tick) { - switch (id) - { - case TIMER_UNK: - { - // rad_bb3 unmasks the interrupt, but the jumps use pointers in RAM, which haven't been set up at the time - // of unmasking, so we need to find some kind of global enable / disable, or timer enable. - if (m_allow_timer_irq) - generate_custom_interrupt(m_whichtimer); - break; - } - } + // rad_bb3 unmasks the interrupt, but the jumps use pointers in RAM, which haven't been set up at the time + // of unmasking, so we need to find some kind of global enable / disable, or timer enable. + if (m_allow_timer_irq) + generate_custom_interrupt(m_whichtimer); } @@ -254,7 +247,7 @@ void elan_eu3a05commonsys_device::device_start() save_item(NAME(m_custom_irq_vector)); save_item(NAME(m_custom_nmi_vector)); - m_unk_timer = timer_alloc(TIMER_UNK); + m_unk_timer = timer_alloc(FUNC(elan_eu3a05commonsys_device::unknown_timer_tick), this); m_unk_timer->adjust(attotime::never); } diff --git a/src/mame/machine/elan_eu3a05commonsys.h b/src/mame/machine/elan_eu3a05commonsys.h index 3e62c48d556..77c185b72ee 100644 --- a/src/mame/machine/elan_eu3a05commonsys.h +++ b/src/mame/machine/elan_eu3a05commonsys.h @@ -31,7 +31,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(unknown_timer_tick); required_device<m6502_device> m_cpu; required_device<address_map_bank_device> m_bank; @@ -63,7 +64,6 @@ private: uint8_t radica_5009_unk_r() { return machine().rand(); } emu_timer *m_unk_timer = nullptr; - static const device_timer_id TIMER_UNK = 0; int m_whichtimer; }; diff --git a/src/mame/machine/electron.cpp b/src/mame/machine/electron.cpp index 2bd23ed3a57..32d92743410 100644 --- a/src/mame/machine/electron.cpp +++ b/src/mame/machine/electron.cpp @@ -24,26 +24,12 @@ void electron_state::waitforramsync() m_maincpu->adjust_icount(-cycles); } - -void electron_state::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(electron_state::setup_beep) { - switch (id) - { - case TIMER_TAPE_HANDLER: - electron_tape_timer_handler(param); - break; - case TIMER_SETUP_BEEP: - setup_beep(param); - break; - case TIMER_SCANLINE_INTERRUPT: - electron_scanline_interrupt(param); - break; - default: - throw emu_fatalerror("Unknown id in electron_state::device_timer"); - } + m_beeper->set_state( 0 ); + m_beeper->set_clock( 300 ); } - void electron_state::electron_tape_start() { if (m_ula.tape_running ) @@ -583,20 +569,14 @@ void electron_state::electron_interrupt_handler(int mode, int interrupt) Machine Initialisation functions ***************************************/ -TIMER_CALLBACK_MEMBER(electron_state::setup_beep) -{ - m_beeper->set_state( 0 ); - m_beeper->set_clock( 300 ); -} - void electron_state::machine_start() { m_capslock_led.resolve(); m_ula.interrupt_status = 0x82; m_ula.interrupt_control = 0x00; - timer_set(attotime::zero, TIMER_SETUP_BEEP); - m_tape_timer = timer_alloc(TIMER_TAPE_HANDLER); + m_tape_timer = timer_alloc(FUNC(electron_state::electron_tape_timer_handler), this); + m_beep_timer = timer_alloc(FUNC(electron_state::setup_beep), this); /* register save states */ save_item(STRUCT_MEMBER(m_ula, interrupt_status)); @@ -630,6 +610,9 @@ void electron_state::machine_reset() m_mrb_mapped = true; m_vdu_drivers = false; + + m_tape_timer->adjust(attotime::never); + m_beep_timer->adjust(attotime::never); } void electronsp_state::machine_start() diff --git a/src/mame/machine/esqpanel.cpp b/src/mame/machine/esqpanel.cpp index 338c7be5712..ba33ee64e2f 100644 --- a/src/mame/machine/esqpanel.cpp +++ b/src/mame/machine/esqpanel.cpp @@ -7,8 +7,6 @@ #include "http.h" #include "esqpanel.h" -#define ESQPANEL_EXTERNAL_TIMER_ID 47000 - //************************************************************************** // External panel support //************************************************************************** @@ -441,7 +439,7 @@ void esqpanel_device::device_start() return write_contents(o); }); - m_external_timer = timer_alloc(ESQPANEL_EXTERNAL_TIMER_ID); + m_external_timer = timer_alloc(FUNC(esqpanel_device::check_external_panel_server), this); m_external_timer->enable(false); } } @@ -484,14 +482,6 @@ void esqpanel_device::device_stop() m_external_panel_server = nullptr; } -void esqpanel_device::device_timer(emu_timer &timer, device_timer_id id, int param) -{ - if (ESQPANEL_EXTERNAL_TIMER_ID == id) - { - check_external_panel_server(); - } -} - void esqpanel_device::rcv_complete() // Rx completed receiving byte { receive_register_extract(); @@ -618,7 +608,7 @@ void esqpanel_device::xmit_char(uint8_t data) } } -void esqpanel_device::check_external_panel_server() { +TIMER_CALLBACK_MEMBER(esqpanel_device::check_external_panel_server) { while (m_external_panel_server->has_commands()) { std::string command = m_external_panel_server->get_next_command(); diff --git a/src/mame/machine/esqpanel.h b/src/mame/machine/esqpanel.h index f902266afee..52481a12d10 100644 --- a/src/mame/machine/esqpanel.h +++ b/src/mame/machine/esqpanel.h @@ -40,7 +40,6 @@ protected: virtual void device_start() override; virtual void device_reset() override; virtual void device_stop() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; // serial overrides virtual void rcv_complete() override; // Rx completed receiving byte @@ -49,7 +48,7 @@ protected: virtual void send_to_display(uint8_t data) = 0; - void check_external_panel_server(); + TIMER_CALLBACK_MEMBER(check_external_panel_server); virtual const std::string get_front_panel_html_file() const { return ""; } virtual const std::string get_front_panel_js_file() const { return ""; } diff --git a/src/mame/machine/esqvfd.cpp b/src/mame/machine/esqvfd.cpp index 5e2797cbd6e..68b913f9c22 100644 --- a/src/mame/machine/esqvfd.cpp +++ b/src/mame/machine/esqvfd.cpp @@ -140,10 +140,6 @@ void esqvfd_device::device_reset() memset(m_dirty, 1, sizeof(m_attrs)); } -void esqvfd_device::device_timer(emu_timer &timer, device_timer_id id, int param) -{ -} - // generic display update; can override from child classes if not good enough void esqvfd_device::update_display() { diff --git a/src/mame/machine/esqvfd.h b/src/mame/machine/esqvfd.h index 5b827b335b2..ec6c7772173 100644 --- a/src/mame/machine/esqvfd.h +++ b/src/mame/machine/esqvfd.h @@ -48,7 +48,6 @@ 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; output_helper::ptr m_vfds; int m_cursx = 0, m_cursy = 0; diff --git a/src/mame/machine/f5220_kbd.cpp b/src/mame/machine/f5220_kbd.cpp index 91c590e402d..df6f81ea62b 100644 --- a/src/mame/machine/f5220_kbd.cpp +++ b/src/mame/machine/f5220_kbd.cpp @@ -203,7 +203,7 @@ void f5220_kbd_device::device_start() m_int_handler.resolve_safe(); // timer for initial keyboard data - m_reset_timer = timer_alloc(0); + m_reset_timer = timer_alloc(FUNC(f5220_kbd_device::reset_done), this); m_reset_timer->adjust(attotime::from_msec(1000)); // register for state saving @@ -224,12 +224,13 @@ void f5220_kbd_device::device_reset() } //------------------------------------------------- -// device_timer - device-specific timer +// reset_done - flag an interrupt to indicate +// the device has come out of reset //------------------------------------------------- -void f5220_kbd_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(f5220_kbd_device::reset_done) { - logerror("Reset\n"); + logerror("Reset Done\n"); m_int_handler(1); m_int_handler(0); diff --git a/src/mame/machine/f5220_kbd.h b/src/mame/machine/f5220_kbd.h index 2d3d22d1ef2..3cf1c050cbc 100644 --- a/src/mame/machine/f5220_kbd.h +++ b/src/mame/machine/f5220_kbd.h @@ -36,13 +36,14 @@ protected: virtual ioport_constructor device_input_ports() const 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_matrix_keyboard_interface overrides virtual void key_make(uint8_t row, uint8_t column) override; virtual void key_break(uint8_t row, uint8_t column) override; virtual void key_repeat(uint8_t row, uint8_t column) override; + TIMER_CALLBACK_MEMBER(reset_done); + private: devcb_write_line m_int_handler; diff --git a/src/mame/machine/fm_scsi.cpp b/src/mame/machine/fm_scsi.cpp index c370c232964..d2b8fcd266f 100644 --- a/src/mame/machine/fm_scsi.cpp +++ b/src/mame/machine/fm_scsi.cpp @@ -79,8 +79,8 @@ void fmscsi_device::device_start() m_drq_handler.resolve_safe(); // allocate read timer - m_transfer_timer = timer_alloc(TIMER_TRANSFER); - m_phase_timer = timer_alloc(TIMER_PHASE); + m_transfer_timer = timer_alloc(FUNC(fmscsi_device::update_transfer), this); + m_phase_timer = timer_alloc(FUNC(fmscsi_device::set_phase), this); } void fmscsi_device::device_reset() @@ -117,21 +117,13 @@ int fmscsi_device::get_scsi_cmd_len(uint8_t cbyte) //return 6; } -void fmscsi_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(fmscsi_device::update_transfer) { - switch(id) + set_input_line(FMSCSI_LINE_REQ,1); + //logerror("FMSCSI: timer triggered: %i/%i\n",m_result_index,m_result_length); + if(m_output_lines & FMSCSI_LINE_DMAE) { - case TIMER_TRANSFER: - set_input_line(FMSCSI_LINE_REQ,1); - //logerror("FMSCSI: timer triggered: %i/%i\n",m_result_index,m_result_length); - if(m_output_lines & FMSCSI_LINE_DMAE) - { - m_drq_handler(1); - } - break; - case TIMER_PHASE: - set_phase(param); - break; + m_drq_handler(1); } } @@ -256,12 +248,12 @@ void fmscsi_device::fmscsi_data_w(uint8_t data) } } -void fmscsi_device::set_phase(int phase) +TIMER_CALLBACK_MEMBER(fmscsi_device::set_phase) { - m_phase = phase; + m_phase = param; logerror("FMSCSI: phase set to %i\n",m_phase); // set input lines accordingly - switch(phase) + switch(param) { case SCSI_PHASE_BUS_FREE: set_input_line(FMSCSI_LINE_BSY,0); diff --git a/src/mame/machine/fm_scsi.h b/src/mame/machine/fm_scsi.h index 5b3b06866f0..9a3df8c0ba6 100644 --- a/src/mame/machine/fm_scsi.h +++ b/src/mame/machine/fm_scsi.h @@ -31,7 +31,7 @@ public: uint8_t fmscsi_r(offs_t offset); void fmscsi_w(offs_t offset, uint8_t data); - void set_phase(int phase); + TIMER_CALLBACK_MEMBER(set_phase); int get_phase(void); void set_input_line(uint8_t line, uint8_t state); uint8_t get_input_line(uint8_t line); @@ -42,13 +42,10 @@ protected: // device-level overrides (none are required, but these are common) virtual void device_start() override; virtual void device_reset() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; -private: - // internal device state goes here - static const device_timer_id TIMER_TRANSFER = 0; - static const device_timer_id TIMER_PHASE = 1; + TIMER_CALLBACK_MEMBER(update_transfer); +private: int get_scsi_cmd_len(uint8_t cbyte); void stop_transfer(); diff --git a/src/mame/machine/gaelco3d.cpp b/src/mame/machine/gaelco3d.cpp index 9e3c106fca4..a2d195782c1 100644 --- a/src/mame/machine/gaelco3d.cpp +++ b/src/mame/machine/gaelco3d.cpp @@ -189,6 +189,7 @@ gaelco_serial_device::gaelco_serial_device(const machine_config &mconfig, const m_last_in_msg_cnt(0), m_slack_cnt(0), m_sync_timer(nullptr), + m_status_set_timer(nullptr), m_in_ptr(nullptr), m_out_ptr(nullptr), m_os_shmem(nullptr), @@ -206,7 +207,8 @@ void gaelco_serial_device::device_start() assert(strlen(tag()) < 20); m_irq_handler.resolve_safe(); - m_sync_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(gaelco_serial_device::link_cb), this)); + m_sync_timer = timer_alloc(FUNC(gaelco_serial_device::link_cb), this); + m_status_set_timer = timer_alloc(FUNC(gaelco_serial_device::set_status_cb), this); /* register for save states */ //save_item(NAME(earom->offset)); @@ -239,7 +241,9 @@ void gaelco_serial_device::device_start() void gaelco_serial_device::device_reset() { - m_status = GAELCOSER_STATUS_READY |GAELCOSER_STATUS_IRQ_ENABLE ; + m_status_set_timer->adjust(attotime::never); + + m_status = GAELCOSER_STATUS_READY | GAELCOSER_STATUS_IRQ_ENABLE; m_last_in_msg_cnt = -1; m_slack_cnt = LINK_SLACK_B; @@ -274,7 +278,7 @@ TIMER_CALLBACK_MEMBER( gaelco_serial_device::set_status_cb ) void gaelco_serial_device::set_status(uint8_t mask, uint8_t set, int wait) { - machine().scheduler().timer_set(attotime::from_hz(wait), timer_expired_delegate(FUNC(gaelco_serial_device::set_status_cb), this), (mask << 8)|set); + m_status_set_timer->adjust(attotime::from_hz(wait), (mask << 8) | set); } void gaelco_serial_device::process_in() diff --git a/src/mame/machine/gaelco3d.h b/src/mame/machine/gaelco3d.h index 05a09a8ee0a..b30856e6bf9 100644 --- a/src/mame/machine/gaelco3d.h +++ b/src/mame/machine/gaelco3d.h @@ -88,6 +88,7 @@ private: int m_slack_cnt; emu_timer *m_sync_timer; + emu_timer *m_status_set_timer; buf_t *m_in_ptr; buf_t *m_out_ptr; diff --git a/src/mame/machine/gamecom.cpp b/src/mame/machine/gamecom.cpp index 727f4f8e8ab..6ff53ee45f2 100644 --- a/src/mame/machine/gamecom.cpp +++ b/src/mame/machine/gamecom.cpp @@ -611,9 +611,9 @@ void gamecom_state::gamecom_update_timers(uint8_t data) void gamecom_state::init_gamecom() { - m_clock_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(gamecom_state::gamecom_clock_timer_callback),this)); - m_sound0_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(gamecom_state::gamecom_sound0_timer_callback),this)); - m_sound1_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(gamecom_state::gamecom_sound1_timer_callback),this)); + m_clock_timer = timer_alloc(FUNC(gamecom_state::gamecom_clock_timer_callback), this); + m_sound0_timer = timer_alloc(FUNC(gamecom_state::gamecom_sound0_timer_callback), this); + m_sound1_timer = timer_alloc(FUNC(gamecom_state::gamecom_sound1_timer_callback), this); m_sound0_timer->adjust(attotime::from_seconds(1), 0, attotime::from_seconds(1)); m_sound1_timer->adjust(attotime::from_seconds(1), 0, attotime::from_seconds(1)); m_p_ram = m_share_maincpu; // required here because pio_w gets called before machine_reset diff --git a/src/mame/machine/harddriv.cpp b/src/mame/machine/harddriv.cpp index 7745c5a8d9f..57abbcd7a0a 100644 --- a/src/mame/machine/harddriv.cpp +++ b/src/mame/machine/harddriv.cpp @@ -45,6 +45,7 @@ void harddriv_state::device_start() init_video(); + m_xdsp_serial_irq_off_timer = timer_alloc(FUNC(harddriv_state::xdsp_sport1_irq_off_callback), this); } @@ -79,6 +80,8 @@ void harddriv_state::device_reset() m_ds3xdsp_timer_en = 0; m_ds3xdsp_internal_timer->adjust(attotime::never); } + + m_xdsp_serial_irq_off_timer->adjust(attotime::never); } @@ -1322,7 +1325,7 @@ WRITE_LINE_MEMBER(harddriv_state::hdds3xdsp_timer_enable_callback) /* TODO: The following does not work correctly */ -TIMER_CALLBACK_MEMBER(harddriv_state::xsdp_sport1_irq_off_callback) +TIMER_CALLBACK_MEMBER(harddriv_state::xdsp_sport1_irq_off_callback) { m_ds3xdsp->set_input_line(ADSP2105_SPORT1_RX, CLEAR_LINE); } @@ -1336,7 +1339,7 @@ void harddriv_state::hdds3sdsp_serial_tx_callback(uint32_t data) m_ds3sdsp_sdata = data; m_ds3xdsp->set_input_line(ADSP2105_SPORT1_RX, ASSERT_LINE); - machine().scheduler().timer_set(attotime::from_nsec(200), timer_expired_delegate(FUNC(harddriv_state::xsdp_sport1_irq_off_callback), this)); + m_xdsp_serial_irq_off_timer->adjust(attotime::from_nsec(200)); } diff --git a/src/mame/machine/hec2hrp.cpp b/src/mame/machine/hec2hrp.cpp index c2fb3794580..064de7de28d 100644 --- a/src/mame/machine/hec2hrp.cpp +++ b/src/mame/machine/hec2hrp.cpp @@ -812,7 +812,7 @@ void hec2hrp_state::hector_init() m_pot0 = m_pot1 = 0x40; /* for cassette sync */ - m_cassette_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(hec2hrp_state::cassette_clock),this)); + m_cassette_timer = timer_alloc(FUNC(hec2hrp_state::cassette_clock), this); m_cassette_timer->adjust(attotime::from_msec(100), 0, attotime::from_usec(64));/* => real sync scan speed for 15,624Khz*/ init_sn76477(); /* init R/C values */ diff --git a/src/mame/machine/hp2640_tape.cpp b/src/mame/machine/hp2640_tape.cpp index 45fcc5caff7..a9a7630c4fe 100644 --- a/src/mame/machine/hp2640_tape.cpp +++ b/src/mame/machine/hp2640_tape.cpp @@ -45,11 +45,12 @@ #include "hp2640_tape.h" // Debugging -#include "logmacro.h" -#undef VERBOSE -#define VERBOSE 0 + //#define VERBOSE (LOG_GENERAL) +#define VERBOSE (0) +#include "logmacro.h" + // Bit manipulation namespace { template<typename T> constexpr T BIT_MASK(unsigned n) @@ -68,12 +69,6 @@ namespace { } } -// Timers -enum { - GAP_TMR_ID, - CELL_TMR_ID -}; - // Constants constexpr double FAST_SPEED = 60.0; // Fast speed: 60 ips constexpr double SLOW_SPEED = 10.0; // Slow speed: 10 ips @@ -258,8 +253,8 @@ void hp2640_tape_device::device_start() m_led0_handler.resolve_safe(); m_led1_handler.resolve_safe(); - m_gap_timer = timer_alloc(GAP_TMR_ID); - m_cell_timer = timer_alloc(CELL_TMR_ID); + m_gap_timer = timer_alloc(FUNC(hp2640_tape_device::gap_timer_tick), this); + m_cell_timer = timer_alloc(FUNC(hp2640_tape_device::cell_timer_tick), this); save_item(NAME(m_selected_drive)); save_item(NAME(m_cmd_reg)); @@ -311,37 +306,33 @@ void hp2640_tape_device::device_reset() m_cell_timer->reset(); } -void hp2640_tape_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(hp2640_tape_device::gap_timer_tick) { - LOG("TMR %d @%s\n" , id , machine().time().to_string()); + LOG("TMR 0 @%s\n", machine().time().to_string()); - switch (id) { - case GAP_TMR_ID: - m_gap = !m_gap; - if (m_gap) { - set_gap(); - } else { - LOG("GAP ENDS\n"); - load_gap_timer(); - if (m_isf) { - load_modulus(); - } + m_gap = !m_gap; + if (m_gap) { + set_gap(); + } else { + LOG("GAP ENDS\n"); + load_gap_timer(); + if (m_isf) { + load_modulus(); } - break; + } +} - case CELL_TMR_ID: - if (m_current_op == hp_dc100_tape_device::OP_READ) { - m_cell_cnt++; - if (m_cell_cnt == 15) { - restart_cell_cnt(); - } else { - load_modulus(); - } - } - break; +TIMER_CALLBACK_MEMBER(hp2640_tape_device::cell_timer_tick) +{ + LOG("TMR 1 @%s\n", machine().time().to_string()); - default: - break; + if (m_current_op == hp_dc100_tape_device::OP_READ) { + m_cell_cnt++; + if (m_cell_cnt == 15) { + restart_cell_cnt(); + } else { + load_modulus(); + } } } diff --git a/src/mame/machine/hp2640_tape.h b/src/mame/machine/hp2640_tape.h index 9c6ff7e382a..30c511c4a8f 100644 --- a/src/mame/machine/hp2640_tape.h +++ b/src/mame/machine/hp2640_tape.h @@ -38,7 +38,9 @@ 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; + + TIMER_CALLBACK_MEMBER(gap_timer_tick); + TIMER_CALLBACK_MEMBER(cell_timer_tick); private: devcb_write_line m_irq_handler; diff --git a/src/mame/machine/hp48.cpp b/src/mame/machine/hp48.cpp index 41b44ba5727..4c0a561a78f 100644 --- a/src/mame/machine/hp48.cpp +++ b/src/mame/machine/hp48.cpp @@ -108,7 +108,7 @@ void hp48_state::rs232_start_recv_byte(uint8_t data) } /* schedule end of reception */ - machine().scheduler().timer_set(RS232_DELAY, timer_expired_delegate(FUNC(hp48_state::rs232_byte_recv_cb),this), data); + m_recv_done_timer->adjust(RS232_DELAY, data); } @@ -137,7 +137,7 @@ void hp48_state::rs232_send_byte() m_io[0x12] |= 3; /* schedule transmission */ - machine().scheduler().timer_set(RS232_DELAY, timer_expired_delegate(FUNC(hp48_state::rs232_byte_sent_cb),this), data); + m_send_done_timer->adjust(RS232_DELAY, data); } @@ -976,16 +976,24 @@ void hp48_state::base_machine_start(hp48_models model) } /* timers */ - m_1st_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(hp48_state::timer1_cb), this)); + m_1st_timer = timer_alloc(FUNC(hp48_state::timer1_cb), this); m_1st_timer->adjust(attotime::from_hz(16), 0, attotime::from_hz(16)); - m_2nd_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(hp48_state::timer2_cb), this)); + m_2nd_timer = timer_alloc(FUNC(hp48_state::timer2_cb), this); m_2nd_timer->adjust(attotime::from_hz(8192), 0, attotime::from_hz(8192)); /* 1ms keyboard polling */ - m_kbd_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(hp48_state::kbd_cb), this)); + m_kbd_timer = timer_alloc(FUNC(hp48_state::kbd_cb), this); m_kbd_timer->adjust(attotime::from_msec(1), 0, attotime::from_msec(1)); + /* serial receive done */ + m_recv_done_timer = timer_alloc(FUNC(hp48_state::rs232_byte_recv_cb), this); + m_recv_done_timer->adjust(attotime::never); + + /* serial send done */ + m_send_done_timer = timer_alloc(FUNC(hp48_state::rs232_byte_sent_cb), this); + m_send_done_timer->adjust(attotime::never); + m_lshift0.resolve(); m_rshift0.resolve(); m_alpha0.resolve(); diff --git a/src/mame/machine/hp9845_printer.cpp b/src/mame/machine/hp9845_printer.cpp index c3b17acfaec..27cafb9df07 100644 --- a/src/mame/machine/hp9845_printer.cpp +++ b/src/mame/machine/hp9845_printer.cpp @@ -172,7 +172,7 @@ void hp9845_printer_device::device_start() save_item(NAME(m_fsm_state)); save_item(NAME(m_cur_line)); - m_timer = timer_alloc(0); + m_timer = timer_alloc(FUNC(hp9845_printer_device::clear_busy_flag), this); } void hp9845_printer_device::device_reset() @@ -186,7 +186,7 @@ void hp9845_printer_device::device_reset() m_sts_handler(true); } -void hp9845_printer_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(hp9845_printer_device::clear_busy_flag) { m_busy = false; update_fsm(); diff --git a/src/mame/machine/hp9845_printer.h b/src/mame/machine/hp9845_printer.h index ce8fce69084..b3da40da833 100644 --- a/src/mame/machine/hp9845_printer.h +++ b/src/mame/machine/hp9845_printer.h @@ -31,7 +31,8 @@ public: 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; + + TIMER_CALLBACK_MEMBER(clear_busy_flag); // PPU access uint16_t printer_r(offs_t offset); diff --git a/src/mame/machine/hpc3.cpp b/src/mame/machine/hpc3.cpp index dcab7432baa..89e736c698c 100644 --- a/src/mame/machine/hpc3.cpp +++ b/src/mame/machine/hpc3.cpp @@ -150,7 +150,7 @@ void hpc3_device::device_start() save_item(NAME(m_pbus_dma[i].m_config), i); save_item(NAME(m_pbus_dma[i].m_control), i); - m_pbus_dma[i].m_timer = timer_alloc(TIMER_PBUS_DMA + i); + m_pbus_dma[i].m_timer = timer_alloc(FUNC(hpc3_device::do_pbus_dma), this); m_pbus_dma[i].m_timer->adjust(attotime::never); } @@ -166,7 +166,7 @@ void hpc3_device::device_start() save_pointer(NAME(m_enet_fifo[ENET_RECV]), 32); save_pointer(NAME(m_enet_fifo[ENET_XMIT]), 40); - m_enet_tx_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(hpc3_device::enet_transmit), this)); + m_enet_tx_timer = timer_alloc(FUNC(hpc3_device::enet_transmit), this); } void hpc3_device::device_reset() @@ -218,29 +218,9 @@ void hpc3_device::map(address_map &map) map(0x00060000, 0x0007ffff).rw(FUNC(hpc3_device::bbram_r), FUNC(hpc3_device::bbram_w)); } -void hpc3_device::device_timer(emu_timer &timer, device_timer_id id, int param) -{ - switch (id) - { - case TIMER_PBUS_DMA+0: - case TIMER_PBUS_DMA+1: - case TIMER_PBUS_DMA+2: - case TIMER_PBUS_DMA+3: - do_pbus_dma(id - TIMER_PBUS_DMA); - break; - case TIMER_PBUS_DMA+4: - case TIMER_PBUS_DMA+5: - case TIMER_PBUS_DMA+6: - case TIMER_PBUS_DMA+7: - LOGMASKED(LOG_UNKNOWN, "HPC3: Ignoring active PBUS DMA on channel %d\n", id - TIMER_PBUS_DMA); - break; - default: - throw emu_fatalerror("Unknown id in hpc3_device::device_timer"); - } -} - -void hpc3_device::do_pbus_dma(uint32_t channel) +TIMER_CALLBACK_MEMBER(hpc3_device::do_pbus_dma) { + uint32_t channel = (uint32_t)param; pbus_dma_t &dma = m_pbus_dma[channel]; if (dma.m_active && channel < 4) @@ -280,7 +260,7 @@ void hpc3_device::do_pbus_dma(uint32_t channel) return; } } - dma.m_timer->adjust(m_hal2->get_rate(channel)); + dma.m_timer->adjust(m_hal2->get_rate(channel), (int)channel); } else { @@ -881,7 +861,7 @@ void hpc3_device::pbusdma_w(address_space &space, offs_t offset, uint32_t data, attotime rate = m_hal2->get_rate(channel); if (rate != attotime::zero) { - dma.m_timer->adjust(rate); + dma.m_timer->adjust(rate, (int)channel); dma.m_active = true; } } diff --git a/src/mame/machine/hpc3.h b/src/mame/machine/hpc3.h index c0d53ca5ac6..7a37648fbbc 100644 --- a/src/mame/machine/hpc3.h +++ b/src/mame/machine/hpc3.h @@ -71,7 +71,6 @@ protected: virtual void device_resolve_objects() 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; virtual space_config_vector memory_space_config() const override; @@ -109,7 +108,7 @@ protected: uint32_t bbram_r(offs_t offset); void bbram_w(offs_t offset, uint32_t data); - void do_pbus_dma(uint32_t channel); + TIMER_CALLBACK_MEMBER(do_pbus_dma); void do_scsi_dma(int channel); void dump_chain(uint32_t base); @@ -123,8 +122,6 @@ protected: void enet_misc_w(u32 data); bool enet_rx_bc_dec(unsigned const count = 1); - static const device_timer_id TIMER_PBUS_DMA = 0; - struct pbus_dma_t { bool m_active = false; diff --git a/src/mame/machine/ibm6580_fdc.cpp b/src/mame/machine/ibm6580_fdc.cpp index 5abc6573705..0cc35e56532 100644 --- a/src/mame/machine/ibm6580_fdc.cpp +++ b/src/mame/machine/ibm6580_fdc.cpp @@ -61,7 +61,7 @@ void dw_fdc_device::device_start() m_out_data.resolve_safe(); m_out_clock.resolve_safe(); m_out_strobe.resolve_safe(); - m_reset_timer = timer_alloc(); + m_reset_timer = timer_alloc(FUNC(dw_fdc_device::assert_reset_line), this); } void dw_fdc_device::device_reset() @@ -69,7 +69,7 @@ void dw_fdc_device::device_reset() m_p1 = m_p2 = m_t0 = m_t1 = 0; } -void dw_fdc_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(dw_fdc_device::assert_reset_line) { m_mcu->set_input_line(INPUT_LINE_RESET, ASSERT_LINE); } diff --git a/src/mame/machine/ibm6580_fdc.h b/src/mame/machine/ibm6580_fdc.h index b5c9fa8b6fc..64dcb85ffa7 100644 --- a/src/mame/machine/ibm6580_fdc.h +++ b/src/mame/machine/ibm6580_fdc.h @@ -28,7 +28,8 @@ 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; + + TIMER_CALLBACK_MEMBER(assert_reset_line); private: uint8_t m_bus, m_t0, m_t1, m_p1, m_p2; diff --git a/src/mame/machine/imm6_76.cpp b/src/mame/machine/imm6_76.cpp index db4cdcbd236..19a8d4ad5c8 100644 --- a/src/mame/machine/imm6_76.cpp +++ b/src/mame/machine/imm6_76.cpp @@ -29,9 +29,9 @@ intel_imm6_76_device::intel_imm6_76_device( void intel_imm6_76_device::device_start() { - m_cycle_tmr = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(intel_imm6_76_device::cycle_expired), this)); - m_cycle_a_tmr = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(intel_imm6_76_device::cycle_a_expired), this)); - m_prg_tmr = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(intel_imm6_76_device::prg_expired), this)); + m_cycle_tmr = timer_alloc(FUNC(intel_imm6_76_device::cycle_expired), this); + m_cycle_a_tmr = timer_alloc(FUNC(intel_imm6_76_device::cycle_a_expired), this); + m_prg_tmr = timer_alloc(FUNC(intel_imm6_76_device::prg_expired), this); save_item(NAME(m_data)); save_item(NAME(m_di)); diff --git a/src/mame/machine/interpro_ioga.cpp b/src/mame/machine/interpro_ioga.cpp index 0ab14ca6997..22e493c4f93 100644 --- a/src/mame/machine/interpro_ioga.cpp +++ b/src/mame/machine/interpro_ioga.cpp @@ -194,24 +194,24 @@ void interpro_ioga_device::device_start() } // allocate timers - m_interrupt_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(interpro_ioga_device::interrupt_check), this)); - m_dma_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(interpro_ioga_device::dma), this)); - m_serial_dma_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(interpro_ioga_device::serial_dma), this)); + m_interrupt_timer = timer_alloc(FUNC(interpro_ioga_device::interrupt_check), this); + m_dma_timer = timer_alloc(FUNC(interpro_ioga_device::dma), this); + m_serial_dma_timer = timer_alloc(FUNC(interpro_ioga_device::serial_dma), this); - m_timer0 = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(interpro_ioga_device::timer0), this)); - m_timer1 = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(interpro_ioga_device::timer1), this)); + m_timer0 = timer_alloc(FUNC(interpro_ioga_device::timer0), this); + m_timer1 = timer_alloc(FUNC(interpro_ioga_device::timer1), this); - m_timer_60hz = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(interpro_ioga_device::timer_60hz), this)); + m_timer_60hz = timer_alloc(FUNC(interpro_ioga_device::timer_60hz), this); - m_eth_reset_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(interpro_ioga_device::eth_reset), this)); + m_eth_reset_timer = timer_alloc(FUNC(interpro_ioga_device::eth_reset), this); } void sapphire_ioga_device::device_start() { interpro_ioga_device::device_start(); - m_timer2 = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(sapphire_ioga_device::timer2), this)); - m_timer3 = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(sapphire_ioga_device::timer3), this)); + m_timer2 = timer_alloc(FUNC(sapphire_ioga_device::timer2), this); + m_timer3 = timer_alloc(FUNC(sapphire_ioga_device::timer3), this); } void interpro_ioga_device::device_reset() diff --git a/src/mame/machine/intv.cpp b/src/mame/machine/intv.cpp index c580b93dc37..a73293b29f4 100644 --- a/src/mame/machine/intv.cpp +++ b/src/mame/machine/intv.cpp @@ -481,7 +481,7 @@ void intv_state::intvkbd_periph_w(offs_t offset, uint8_t data) } } -uint16_t intv_state::intv_stic_r(offs_t offset) +uint16_t intv_state::stic_r(offs_t offset) { if (m_bus_copy_mode || !m_stic->read_stic_handshake()) return m_stic->read(offset); @@ -489,14 +489,14 @@ uint16_t intv_state::intv_stic_r(offs_t offset) return offset; } -void intv_state::intv_stic_w(offs_t offset, uint16_t data) +void intv_state::stic_w(offs_t offset, uint16_t data) { if (m_bus_copy_mode || !m_stic->read_stic_handshake()) m_stic->write(offset, data); } -uint16_t intv_state::intv_gram_r(offs_t offset) +uint16_t intv_state::gram_r(offs_t offset) { //logerror("read: %d = GRAM(%d)\n",state->m_gram[offset],offset); if (m_bus_copy_mode || !m_stic->read_stic_handshake()) @@ -505,31 +505,31 @@ uint16_t intv_state::intv_gram_r(offs_t offset) return offset; } -void intv_state::intv_gram_w(offs_t offset, uint16_t data) +void intv_state::gram_w(offs_t offset, uint16_t data) { if (m_bus_copy_mode || !m_stic->read_stic_handshake()) m_stic->gram_write(offset, data); } -uint16_t intv_state::intv_ram8_r(offs_t offset) +uint16_t intv_state::ram8_r(offs_t offset) { //logerror("%x = ram8_r(%x)\n",state->m_ram8[offset],offset); return (int)m_ram8[offset]; } -void intv_state::intv_ram8_w(offs_t offset, uint16_t data) +void intv_state::ram8_w(offs_t offset, uint16_t data) { //logerror("ram8_w(%x) = %x\n",offset,data); m_ram8[offset] = data&0xff; } -uint16_t intv_state::intv_ram16_r(offs_t offset) +uint16_t intv_state::ram16_r(offs_t offset) { //logerror("%x = ram16_r(%x)\n",state->m_ram16[offset],offset); return (int)m_ram16[offset]; } -void intv_state::intv_ram16_w(offs_t offset, uint16_t data) +void intv_state::ram16_w(offs_t offset, uint16_t data) { //logerror("%g: WRITING TO GRAM offset = %d\n",machine.time(),offset); //logerror("ram16_w(%x) = %x\n",offset,data); @@ -639,16 +639,21 @@ void intv_state::machine_start() m_cart->save_ram(); } + + m_int2_complete_timer = timer_alloc(FUNC(intv_state::interrupt2_complete), this); + m_int_complete_timer = timer_alloc(FUNC(intv_state::interrupt_complete), this); + for (int row = 0; row < stic_device::BACKTAB_HEIGHT; row++) + m_btb_fill_timers[row] = timer_alloc(FUNC(intv_state::btb_fill), this); } -TIMER_CALLBACK_MEMBER(intv_state::intv_interrupt_complete) +TIMER_CALLBACK_MEMBER(intv_state::interrupt_complete) { m_maincpu->set_input_line(CP1610_INT_INTRM, CLEAR_LINE); m_bus_copy_mode = 0; } -TIMER_CALLBACK_MEMBER(intv_state::intv_btb_fill) +TIMER_CALLBACK_MEMBER(intv_state::btb_fill) { uint8_t row = m_backtab_row; //m_maincpu->adjust_icount(-STIC_ROW_FETCH); @@ -659,7 +664,7 @@ TIMER_CALLBACK_MEMBER(intv_state::intv_btb_fill) m_backtab_row += 1; } -INTERRUPT_GEN_MEMBER(intv_state::intv_interrupt) +INTERRUPT_GEN_MEMBER(intv_state::interrupt) { int delay = m_stic->read_row_delay(); m_maincpu->set_input_line(CP1610_INT_INTRM, ASSERT_LINE); @@ -668,10 +673,13 @@ INTERRUPT_GEN_MEMBER(intv_state::intv_interrupt) m_backtab_row = 0; m_maincpu->adjust_icount(-(12*stic_device::ROW_BUSRQ+stic_device::FRAME_BUSRQ)); // Account for stic cycle stealing - timer_set(m_maincpu->cycles_to_attotime(stic_device::VBLANK_END), TIMER_INTV_INTERRUPT_COMPLETE); + m_int_complete_timer->adjust(m_maincpu->cycles_to_attotime(stic_device::VBLANK_END)); for (int row = 0; row < stic_device::BACKTAB_HEIGHT; row++) { - timer_set(m_maincpu->cycles_to_attotime(stic_device::FIRST_FETCH-stic_device::FRAME_BUSRQ+stic_device::CYCLES_PER_SCANLINE*stic_device::Y_SCALE*delay + (stic_device::CYCLES_PER_SCANLINE*stic_device::Y_SCALE*stic_device::CARD_HEIGHT - stic_device::ROW_BUSRQ)*row), TIMER_INTV_BTB_FILL); + const uint32_t row_cycles = (stic_device::CYCLES_PER_SCANLINE * stic_device::Y_SCALE * stic_device::CARD_HEIGHT - stic_device::ROW_BUSRQ) * row; + const uint32_t total_cycles = stic_device::FIRST_FETCH - stic_device::FRAME_BUSRQ + stic_device::CYCLES_PER_SCANLINE * stic_device::Y_SCALE * delay + row_cycles; + attotime duration = m_maincpu->cycles_to_attotime(total_cycles); + m_btb_fill_timers[row]->adjust(duration); } if (delay == 0) diff --git a/src/mame/machine/irobot.cpp b/src/mame/machine/irobot.cpp index 0f041f37e5a..ba136b8b43e 100644 --- a/src/mame/machine/irobot.cpp +++ b/src/mame/machine/irobot.cpp @@ -170,7 +170,7 @@ void irobot_state::machine_start() m_statwr = 0; /* set an initial timer to go off on scanline 0 */ - m_scanline_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(irobot_state::scanline_callback), this)); + m_scanline_timer = timer_alloc(FUNC(irobot_state::scanline_callback), this); m_scanline_timer->adjust(m_screen->time_until_pos(0)); } diff --git a/src/mame/machine/iteagle_fpga.cpp b/src/mame/machine/iteagle_fpga.cpp index 9626de12edd..6b914ea1dd3 100644 --- a/src/mame/machine/iteagle_fpga.cpp +++ b/src/mame/machine/iteagle_fpga.cpp @@ -113,7 +113,7 @@ void iteagle_fpga_device::device_start() // RAM defaults to base address 0x000e0000 bank_infos[2].adr = 0x000e0000 & (~(bank_infos[2].size - 1)); - m_timer = timer_alloc(0); + m_timer = timer_alloc(FUNC(iteagle_fpga_device::assert_vblank_irq), this); // Switch IO m_in_cb.resolve_all_safe(0xffff); @@ -215,9 +215,10 @@ void iteagle_fpga_device::update_sequence_eg1(uint32_t data) } //------------------------------------------------- -// device_timer - called when our device timer expires +// assert_vblank_irq - //------------------------------------------------- -void iteagle_fpga_device::device_timer(emu_timer &timer, device_timer_id tid, int param) + +TIMER_CALLBACK_MEMBER(iteagle_fpga_device::assert_vblank_irq) { //int beamy = m_screen->vpos(); //const rectangle &visarea = m_screen->visible_area(); @@ -229,7 +230,7 @@ void iteagle_fpga_device::device_timer(emu_timer &timer, device_timer_id tid, in m_fpga_regs[0x04 / 4] |= 0x00080000; m_cpu->set_input_line(m_irq_num, ASSERT_LINE); if (LOG_FPGA) - logerror("%s:fpga device_timer Setting interrupt(%i)\n", machine().describe_context(), m_irq_num); + logerror("%s:fpga assert_vblank_irq Setting interrupt(%i)\n", machine().describe_context(), m_irq_num); } WRITE_LINE_MEMBER(iteagle_fpga_device::vblank_update) diff --git a/src/mame/machine/iteagle_fpga.h b/src/mame/machine/iteagle_fpga.h index 391934e7898..e7d4ead2a82 100644 --- a/src/mame/machine/iteagle_fpga.h +++ b/src/mame/machine/iteagle_fpga.h @@ -64,9 +64,10 @@ 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(assert_vblank_irq); + private: required_device<nvram_device> m_rtc; optional_device<nvram_device> m_e1_nvram; diff --git a/src/mame/machine/itech8.cpp b/src/mame/machine/itech8.cpp index 4a3e2e5dcef..22b9685dfde 100644 --- a/src/mame/machine/itech8.cpp +++ b/src/mame/machine/itech8.cpp @@ -482,7 +482,7 @@ uint8_t itech8_state::slikshot_z80_control_r() * *************************************/ -TIMER_CALLBACK_MEMBER( itech8_state::delayed_z80_control_w ) +TIMER_CALLBACK_MEMBER(itech8_state::delayed_z80_control_w) { int data = param; @@ -509,7 +509,7 @@ TIMER_CALLBACK_MEMBER( itech8_state::delayed_z80_control_w ) void itech8_state::slikshot_z80_control_w(uint8_t data) { - synchronize(TIMER_DELAYED_Z80_CONTROL, data); + machine().scheduler().synchronize(timer_expired_delegate(FUNC(itech8_state::delayed_z80_control_w), this), data); } diff --git a/src/mame/machine/jaleco_ms32_sysctrl.cpp b/src/mame/machine/jaleco_ms32_sysctrl.cpp index 17884d9efec..1ef2c744750 100644 --- a/src/mame/machine/jaleco_ms32_sysctrl.cpp +++ b/src/mame/machine/jaleco_ms32_sysctrl.cpp @@ -130,8 +130,8 @@ void jaleco_ms32_sysctrl_device::device_start() save_item(NAME(m_timer.irq_enable)); save_item(NAME(m_timer.interval)); - m_timer.prg_irq = timer_alloc(PRG_TIMER); - m_timer_scanline = timer_alloc(SCANLINE_TIMER); + m_timer.prg_irq = timer_alloc(FUNC(jaleco_ms32_sysctrl_device::prg_timer_tick), this); + m_timer_scanline = timer_alloc(FUNC(jaleco_ms32_sysctrl_device::flush_scanline_timer), this); } @@ -177,8 +177,10 @@ void jaleco_ms32_sysctrl_device::flush_prg_timer() m_timer.prg_irq->adjust(step); } -void jaleco_ms32_sysctrl_device::flush_scanline_timer(int current_scanline) +TIMER_CALLBACK_MEMBER(jaleco_ms32_sysctrl_device::flush_scanline_timer) { + int current_scanline = param; + // in typical Jaleco fashion (cfr. mega system 1), both irqs are somehow configurable (a pin?). // Examples are tp2ms32 and wpksocv2, wanting vblank as vector 9 and field as 10 otherwise they runs // at half speed, but then their config can't possibly work with p47aces (i.e. wants 10 and 9 respectively), @@ -197,18 +199,10 @@ void jaleco_ms32_sysctrl_device::flush_scanline_timer(int current_scanline) m_timer_scanline->adjust(m_screen->time_until_pos(next_scanline), next_scanline); } -void jaleco_ms32_sysctrl_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(jaleco_ms32_sysctrl_device::prg_timer_tick) { - switch (id) - { - case SCANLINE_TIMER: - flush_scanline_timer(param); - break; - case PRG_TIMER: - m_prg_timer_cb(1); - flush_prg_timer(); - break; - } + m_prg_timer_cb(1); + flush_prg_timer(); } //***************************************************************************** diff --git a/src/mame/machine/jaleco_ms32_sysctrl.h b/src/mame/machine/jaleco_ms32_sysctrl.h index 8f10db9a887..8a303747ffe 100644 --- a/src/mame/machine/jaleco_ms32_sysctrl.h +++ b/src/mame/machine/jaleco_ms32_sysctrl.h @@ -51,7 +51,8 @@ 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; + + TIMER_CALLBACK_MEMBER(prg_timer_tick); private: required_device<screen_device> m_screen; @@ -94,14 +95,9 @@ private: }m_timer; emu_timer *m_timer_scanline; - enum timer_id - { - SCANLINE_TIMER = 1, - PRG_TIMER - }; - inline void flush_prg_timer(); - inline void flush_scanline_timer(int current_scanline); + void flush_prg_timer(); + TIMER_CALLBACK_MEMBER(flush_scanline_timer); bool m_invert_vblank_lines; }; diff --git a/src/mame/machine/k573fpga.cpp b/src/mame/machine/k573fpga.cpp index f11b80eebd6..4e85563af1f 100644 --- a/src/mame/machine/k573fpga.cpp +++ b/src/mame/machine/k573fpga.cpp @@ -50,7 +50,7 @@ void k573fpga_device::device_start() save_item(NAME(counter_base)); save_item(NAME(is_mpeg_frame_synced)); - m_stream_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(k573fpga_device::update_stream), this)); + m_stream_timer = timer_alloc(FUNC(k573fpga_device::update_stream), this); m_stream_timer->adjust(attotime::never); } diff --git a/src/mame/machine/k573kara.cpp b/src/mame/machine/k573kara.cpp index 3f38fa3ac66..6421c85b58b 100644 --- a/src/mame/machine/k573kara.cpp +++ b/src/mame/machine/k573kara.cpp @@ -112,10 +112,6 @@ void k573kara_device::device_add_mconfig(machine_config &config) duart_chan0.out_rts_callback().set("rs232_chan0", FUNC(rs232_port_device::write_rts)); } -void k573kara_device::device_timer(emu_timer &timer, device_timer_id id, int param) -{ -} - uint16_t k573kara_device::io_r() { // Stage platforms can be connected through the RJ45 ports and the data returned through here. diff --git a/src/mame/machine/k573kara.h b/src/mame/machine/k573kara.h index c551b5b088a..fb8d3e64865 100644 --- a/src/mame/machine/k573kara.h +++ b/src/mame/machine/k573kara.h @@ -20,7 +20,6 @@ protected: virtual void device_reset() override; virtual const tiny_rom_entry *device_rom_region() const override; virtual void device_add_mconfig(machine_config &config) override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; private: uint16_t uart_r(offs_t offset); diff --git a/src/mame/machine/k7659kb.cpp b/src/mame/machine/k7659kb.cpp index f5aaadde9a9..9ff45834d8b 100644 --- a/src/mame/machine/k7659kb.cpp +++ b/src/mame/machine/k7659kb.cpp @@ -197,6 +197,7 @@ ioport_constructor k7659_keyboard_device::device_input_ports() const k7659_keyboard_device::k7659_keyboard_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) : device_t(mconfig, K7659_KEYBOARD, tag, owner, clock) + , m_keys(*this, "A%u", 1U) {} @@ -206,7 +207,7 @@ k7659_keyboard_device::k7659_keyboard_device(const machine_config &mconfig, cons void k7659_keyboard_device::device_start() { - m_timer = timer_alloc(); + m_timer = timer_alloc(FUNC(k7659_keyboard_device::scan_keyboard), this); // state saving save_item(NAME(m_lookup)); save_item(NAME(m_key)); @@ -224,21 +225,21 @@ void k7659_keyboard_device::device_reset() m_timer->adjust(attotime::from_hz(200), 0, attotime::from_hz(200)); } -void k7659_keyboard_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(k7659_keyboard_device::scan_keyboard) { uint8_t retVal = 0;//m_lookup; - uint8_t a1 = ioport("A1")->read(); - uint8_t a2 = ioport("A2")->read(); - uint8_t a3 = ioport("A3")->read(); - uint8_t a4 = ioport("A4")->read(); - uint8_t a5 = ioport("A5")->read(); - uint8_t a6 = ioport("A6")->read(); - uint8_t a7 = ioport("A7")->read(); - uint8_t a8 = ioport("A8")->read(); - uint8_t a9 = ioport("A9")->read(); - uint8_t a10 = ioport("A10")->read(); - uint8_t a11 = ioport("A11")->read(); - uint8_t a12 = ioport("A12")->read(); + uint8_t a1 = m_keys[0]->read(); + uint8_t a2 = m_keys[1]->read(); + uint8_t a3 = m_keys[2]->read(); + uint8_t a4 = m_keys[3]->read(); + uint8_t a5 = m_keys[4]->read(); + uint8_t a6 = m_keys[5]->read(); + uint8_t a7 = m_keys[6]->read(); + uint8_t a8 = m_keys[7]->read(); + uint8_t a9 = m_keys[8]->read(); + uint8_t a10 = m_keys[9]->read(); + uint8_t a11 = m_keys[10]->read(); + uint8_t a12 = m_keys[11]->read(); uint16_t code = 0; if (a1) code = 0x10 + key_pos(a1); diff --git a/src/mame/machine/k7659kb.h b/src/mame/machine/k7659kb.h index 24e5bed5cb8..e01ba695418 100644 --- a/src/mame/machine/k7659kb.h +++ b/src/mame/machine/k7659kb.h @@ -39,16 +39,18 @@ 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; // optional information overrides virtual const tiny_rom_entry *device_rom_region() const override; virtual void device_add_mconfig(machine_config &config) override; virtual ioport_constructor device_input_ports() const override; + TIMER_CALLBACK_MEMBER(scan_keyboard); + emu_timer *m_timer = nullptr; private: + required_ioport_array<12> m_keys; uint8_t key_pos(uint8_t val); uint8_t m_lookup = 0; uint8_t m_key = 0; diff --git a/src/mame/machine/kaneko_calc3.cpp b/src/mame/machine/kaneko_calc3.cpp index 5daf0485142..306e81b190b 100644 --- a/src/mame/machine/kaneko_calc3.cpp +++ b/src/mame/machine/kaneko_calc3.cpp @@ -62,7 +62,7 @@ kaneko_calc3_device::kaneko_calc3_device(const machine_config &mconfig, const ch void kaneko_calc3_device::device_start() { initial_scan_tables(); - m_runtimer = timer_alloc(MCU_RUN_TIMER); + m_runtimer = timer_alloc(FUNC(kaneko_calc3_device::mcu_run_trigger), this); save_item(NAME(m_mcu_status)); save_item(NAME(m_mcu_command_offset)); @@ -95,17 +95,10 @@ void kaneko_calc3_device::reset_run_timer() m_runtimer->adjust(attotime::from_hz(59.1854)); } -void kaneko_calc3_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(kaneko_calc3_device::mcu_run_trigger) { - switch(id) - { - case MCU_RUN_TIMER: - mcu_run(); - reset_run_timer(); - break; - default: - throw emu_fatalerror("Unknown id in kaneko_calc3_device::device_timer"); - } + mcu_run(); + reset_run_timer(); } /* diff --git a/src/mame/machine/kaneko_calc3.h b/src/mame/machine/kaneko_calc3.h index ca9fc97f8ef..49b317504f4 100644 --- a/src/mame/machine/kaneko_calc3.h +++ b/src/mame/machine/kaneko_calc3.h @@ -33,7 +33,8 @@ 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; + + TIMER_CALLBACK_MEMBER(mcu_run_trigger); private: required_device<cpu_device> m_maincpu; @@ -60,11 +61,6 @@ private: uint16_t m_checksumaddress; emu_timer* m_runtimer; - enum - { - MCU_RUN_TIMER - }; - void mcu_init(); void initial_scan_tables(); void mcu_com_w(offs_t offset, uint16_t data, uint16_t mem_mask, int _n_); diff --git a/src/mame/machine/kc.cpp b/src/mame/machine/kc.cpp index 4d1ebef7004..febbb1b5d14 100644 --- a/src/mame/machine/kc.cpp +++ b/src/mame/machine/kc.cpp @@ -732,8 +732,8 @@ WRITE_LINE_MEMBER( kc_state::keyboard_cb ) void kc_state::machine_start() { - m_cassette_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(kc_state::kc_cassette_timer_callback),this)); - m_cassette_oneshot_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(kc_state::kc_cassette_oneshot_timer),this)); + m_cassette_timer = timer_alloc(FUNC(kc_state::kc_cassette_timer_callback), this); + m_cassette_oneshot_timer = timer_alloc(FUNC(kc_state::kc_cassette_oneshot_timer), this); m_ram_base = m_ram->pointer(); } diff --git a/src/mame/machine/kc_keyb.cpp b/src/mame/machine/kc_keyb.cpp index e2de504f367..2c8190e7d4e 100644 --- a/src/mame/machine/kc_keyb.cpp +++ b/src/mame/machine/kc_keyb.cpp @@ -458,8 +458,7 @@ void kc_keyboard_device::device_start() // resolve callbacks m_write_out.resolve_safe(); - m_timer_transmit_pulse = timer_alloc(TIMER_TRANSMIT_PULSE); - + m_timer_transmit_pulse = timer_alloc(FUNC(kc_keyboard_device::transmit_pulse), this); m_timer_transmit_pulse->adjust(attotime::from_usec(1024), 0, attotime::from_usec(1024)); } @@ -488,61 +487,56 @@ ioport_constructor kc_keyboard_device::device_input_ports() const } //------------------------------------------------- -// device_timer - handler timer events +// transmit_pulse - update transmit state //------------------------------------------------- -void kc_keyboard_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(kc_keyboard_device::transmit_pulse) { - switch(id) + if (m_transmit_buffer.pulse_sent < m_transmit_buffer.pulse_count) { - case TIMER_TRANSMIT_PULSE: - if (m_transmit_buffer.pulse_sent < m_transmit_buffer.pulse_count) - { - // byte containing pulse state - int pulse_byte_count = m_transmit_buffer.pulse_sent>>3; - // bit within byte containing pulse state - int pulse_bit_count = 7 - (m_transmit_buffer.pulse_sent & 0x07); + // byte containing pulse state + int pulse_byte_count = m_transmit_buffer.pulse_sent>>3; + // bit within byte containing pulse state + int pulse_bit_count = 7 - (m_transmit_buffer.pulse_sent & 0x07); - // get current pulse state - int pulse_state = (m_transmit_buffer.data[pulse_byte_count]>>pulse_bit_count) & 0x01; + // get current pulse state + int pulse_state = (m_transmit_buffer.data[pulse_byte_count]>>pulse_bit_count) & 0x01; - LOG("KC keyboard sending pulse: %02x\n", pulse_state); + LOG("KC keyboard sending pulse: %02x\n", pulse_state); - // send pulse - m_write_out(pulse_state ? ASSERT_LINE : CLEAR_LINE); + // send pulse + m_write_out(pulse_state ? ASSERT_LINE : CLEAR_LINE); - // update counts - m_transmit_buffer.pulse_sent++; - } - else - { - // if there is nothing to send, rescan the keyboard - static const char *const keynames[] = { "KEY0", "KEY1", "KEY2", "KEY3", "KEY4", "KEY5", "KEY6", "KEY7" }; + // update counts + m_transmit_buffer.pulse_sent++; + } + else + { + // if there is nothing to send, rescan the keyboard + static const char *const keynames[] = { "KEY0", "KEY1", "KEY2", "KEY3", "KEY4", "KEY5", "KEY6", "KEY7" }; - m_transmit_buffer.pulse_sent = 0; - m_transmit_buffer.pulse_count = 0; + m_transmit_buffer.pulse_sent = 0; + m_transmit_buffer.pulse_count = 0; - // scan all lines (excluding shift) - for (int i=0; i<8; i++) - { - uint8_t keyboard_line_data = ioport(keynames[i])->read(); + // scan all lines (excluding shift) + for (int i=0; i<8; i++) + { + uint8_t keyboard_line_data = ioport(keynames[i])->read(); - // scan through each bit - for (int b=0; b<8; b++) + // scan through each bit + for (int b=0; b<8; b++) + { + // is pressed? + if ((keyboard_line_data & (1<<b)) != 0) { - // is pressed? - if ((keyboard_line_data & (1<<b)) != 0) - { - // generate fake code - uint8_t code = (i<<3) | b; - LOG("Code: %02x\n",code); - - transmit_scancode(code); - } + // generate fake code + uint8_t code = (i<<3) | b; + LOG("Code: %02x\n",code); + + transmit_scancode(code); } } } - break; } } diff --git a/src/mame/machine/kc_keyb.h b/src/mame/machine/kc_keyb.h index 13ebee7f9e1..c05cb8c1e5e 100644 --- a/src/mame/machine/kc_keyb.h +++ b/src/mame/machine/kc_keyb.h @@ -37,15 +37,14 @@ 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(transmit_pulse); void add_pulse_to_transmit_buffer(int pulse_state, int pulse_number = 1); void add_bit(int bit); void transmit_scancode(uint8_t scan_code); private: - static constexpr device_timer_id TIMER_TRANSMIT_PULSE = 1; - // internal state emu_timer * m_timer_transmit_pulse; devcb_write_line m_write_out; diff --git a/src/mame/machine/leland.cpp b/src/mame/machine/leland.cpp index 894e9771252..29bdba56f70 100644 --- a/src/mame/machine/leland.cpp +++ b/src/mame/machine/leland.cpp @@ -306,7 +306,7 @@ void ataxx_state::indyheat_analog_w(offs_t offset, u8 data) void leland_state::machine_start() { /* start scanline interrupts going */ - m_master_int_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(leland_state::leland_interrupt_callback),this)); + m_master_int_timer = timer_alloc(FUNC(leland_state::leland_interrupt_callback), this); save_item(NAME(m_dac_control)); save_item(NAME(m_wcol_enable)); @@ -365,7 +365,7 @@ void ataxx_state::machine_start() m_extra_tram = std::make_unique<u8[]>(ATAXX_EXTRA_TRAM_SIZE); /* start scanline interrupts going */ - m_master_int_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(leland_state::ataxx_interrupt_callback),this)); + m_master_int_timer = timer_alloc(FUNC(leland_state::ataxx_interrupt_callback), this); save_item(NAME(m_wcol_enable)); save_item(NAME(m_dial_last_input)); diff --git a/src/mame/machine/lisa.cpp b/src/mame/machine/lisa.cpp index 86f472ee854..4fbce2e6555 100644 --- a/src/mame/machine/lisa.cpp +++ b/src/mame/machine/lisa.cpp @@ -43,60 +43,30 @@ #include "screen.h" -/* - pointers with RAM & ROM location -*/ - /* up to 2MB of 68k RAM (normally 1MB or 512kb), generally 16kb of ROM */ /* offsets in "maincpu" */ #define RAM_OFFSET 0x004000 #define ROM_OFFSET 0x000000 -/* 1kb of RAM for 6504 floppy disk controller (shared with 68000), and 4kb of -ROM (8kb on some boards, but then only one 4kb bank is selected, according to -the drive type (TWIGGY or 3.5'')) */ - -/* special ROM (includes S/N) */ - - /* - MMU regs -*/ - - - + 1kb of RAM for 6504 floppy disk controller (shared with 68000), and 4kb of + ROM (8kb on some boards, but then only one 4kb bank is selected, according to + the drive type (TWIGGY or 3.5'')) + special ROM (includes S/N) -/* parity logic - only hard errors are emulated for now, since a) the ROMs power-up test only tests hard errors b) most memory boards do not use soft errors (i.e. they only generate 1 parity bit to detect errors, instead of generating several ECC bits to fix errors) -*/ - - - -/* - video -*/ - - -/* 2 vias : one is used for communication with COPS ; the other may be used to interface a hard disk */ /* - floppy disk interface -*/ - - - - -/* lisa model identification */ enum lisa_model_t @@ -110,14 +80,6 @@ enum lisa_model_t /* - protos -*/ - - - - - -/* Interrupt handling */ @@ -558,7 +520,7 @@ TIMER_CALLBACK_MEMBER(lisa_state::set_COPS_ready) m_via0->write_pb6(m_COPS_Ready); /* impulsion width : +/- 20us */ - machine().scheduler().timer_set(attotime::from_usec(20), timer_expired_delegate(FUNC(lisa_state::read_COPS_command),this)); + m_cops_cmd_timer->adjust(attotime::from_usec(20)); } void lisa_state::reset_COPS() @@ -934,12 +896,15 @@ void lisa_state::init_mac_xl() void lisa_state::machine_start() { - m_mouse_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(lisa_state::handle_mouse),this)); + m_mouse_timer = timer_alloc(FUNC(lisa_state::handle_mouse), this); /* read command every ms (don't know the real value) */ - m_cops_ready_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(lisa_state::set_COPS_ready), this)); + m_cops_ready_timer = timer_alloc(FUNC(lisa_state::set_COPS_ready), this); m_cops_ready_timer->adjust(attotime::from_msec(1), 0, attotime::from_msec(1)); + m_cops_cmd_timer = timer_alloc(FUNC(lisa_state::read_COPS_command), this); + m_cops_cmd_timer->adjust(attotime::never); + m_nvram->set_base(m_fdc_ram, 1024); m_fifo_tail = 0; @@ -989,17 +954,14 @@ void lisa_state::machine_reset() /* reset COPS keyboard/mouse controller */ init_COPS(); + m_cops_cmd_timer->adjust(attotime::never); - { - COPS_via_out_ca2(0); /* VIA core forgets to do so */ - } + COPS_via_out_ca2(0); /* VIA core forgets to do so */ /* initialize floppy */ + if (m_features.floppy_hardware == sony_lisa2) { - if (m_features.floppy_hardware == sony_lisa2) - { - sony_set_enable_lines(m_fdc, 1); /* on lisa2, drive unit 1 is always selected (?) */ - } + sony_set_enable_lines(m_fdc, 1); /* on lisa2, drive unit 1 is always selected (?) */ } } diff --git a/src/mame/machine/lynx.cpp b/src/mame/machine/lynx.cpp index c00a1accdac..efec05ee408 100644 --- a/src/mame/machine/lynx.cpp +++ b/src/mame/machine/lynx.cpp @@ -533,27 +533,6 @@ void lynx_state::blit_lines() } } -void lynx_state::device_timer(emu_timer &timer, device_timer_id id, int param) -{ - switch (id) - { - case TIMER_BLITTER: - blitter_timer(param); - break; - case TIMER_SHOT: - timer_shot(param); - break; - case TIMER_UART_LOOPBACK: - uart_loopback_timer(param); - break; - case TIMER_UART: - uart_timer(param); - break; - default: - throw emu_fatalerror("Unknown id in lynx_state::device_timer"); - } -} - TIMER_CALLBACK_MEMBER(lynx_state::blitter_timer) { m_blitter.busy = false; // blitter finished @@ -730,7 +709,7 @@ void lynx_state::blitter() } } - timer_set(m_maincpu->cycles_to_attotime(m_blitter.memory_accesses), TIMER_BLITTER); + m_blitter_timer->adjust(m_maincpu->cycles_to_attotime(m_blitter.memory_accesses)); } @@ -1342,7 +1321,7 @@ TIM_BORROWOUT EQU %00000001 void lynx_state::timer_init(int which) { memset(&m_timer[which], 0, sizeof(LYNX_TIMER)); - m_timer[which].timer = timer_alloc(TIMER_SHOT); + m_timer[which].timer = timer_alloc(FUNC(lynx_state::timer_shot), this); save_item(NAME(m_timer[which].bakup), which); save_item(NAME(m_timer[which].cntrl1), which); @@ -1592,14 +1571,14 @@ TIMER_CALLBACK_MEMBER(lynx_state::uart_timer) { m_uart.data_to_send = m_uart.buffer; m_uart.buffer_loaded = false; - timer_set(attotime::from_usec(11*16), TIMER_UART); + m_uart_timer->adjust(attotime::from_usec(11*16)); } else { m_uart.sending = false; m_uart.received = true; m_uart.data_received = m_uart.data_to_send; - timer_set(attotime::from_usec(11*16), TIMER_UART_LOOPBACK); + m_loopback_timer->adjust(attotime::from_usec(11*16)); if (m_uart.RXINTEN()) { interrupt_set(4); @@ -1659,7 +1638,7 @@ void lynx_state::uart_w(offs_t offset, u8 data) m_uart.sending = true; m_uart.data_to_send = data; // timing not accurate, baude rate should be calculated from timer 4 backup value and clock rate - timer_set(attotime::from_usec(11*16), TIMER_UART); + m_uart_timer->adjust(attotime::from_usec(11*16)); } break; } @@ -2009,6 +1988,10 @@ void lynx_state::machine_start() for (int i = 0; i < NR_LYNX_TIMERS; i++) timer_init(i); + + m_blitter_timer = timer_alloc(FUNC(lynx_state::blitter_timer), this); + m_loopback_timer = timer_alloc(FUNC(lynx_state::uart_loopback_timer), this); + m_uart_timer = timer_alloc(FUNC(lynx_state::uart_timer), this); } diff --git a/src/mame/machine/m24_kbd.cpp b/src/mame/machine/m24_kbd.cpp index bc19f619453..dc45fec3c3c 100644 --- a/src/mame/machine/m24_kbd.cpp +++ b/src/mame/machine/m24_kbd.cpp @@ -217,7 +217,7 @@ void m24_keyboard_device::device_start() { m_out_data.resolve_safe(); m_out_data(1); - m_reset_timer = timer_alloc(); + m_reset_timer = timer_alloc(FUNC(m24_keyboard_device::reset_mcu), this); } void m24_keyboard_device::device_reset() @@ -225,7 +225,7 @@ void m24_keyboard_device::device_reset() m_kbcdata = true; } -void m24_keyboard_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(m24_keyboard_device::reset_mcu) { m_mcu->set_input_line(INPUT_LINE_RESET, ASSERT_LINE); m_out_data(1); diff --git a/src/mame/machine/m24_kbd.h b/src/mame/machine/m24_kbd.h index 69083734950..3e6d44dd540 100644 --- a/src/mame/machine/m24_kbd.h +++ b/src/mame/machine/m24_kbd.h @@ -21,11 +21,12 @@ 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 const tiny_rom_entry *device_rom_region() const override; virtual void device_add_mconfig(machine_config &config) override; virtual ioport_constructor device_input_ports() const override; + TIMER_CALLBACK_MEMBER(reset_mcu); + private: required_ioport_array<16> m_rows; required_ioport m_mousebtn; diff --git a/src/mame/machine/m3comm.cpp b/src/mame/machine/m3comm.cpp index ccd7a84ff74..8b9eeaa40a3 100644 --- a/src/mame/machine/m3comm.cpp +++ b/src/mame/machine/m3comm.cpp @@ -138,7 +138,7 @@ m3comm_device::m3comm_device(const machine_config &mconfig, const char *tag, dev device_t(mconfig, M3COMM, tag, owner, clock), m_line_rx(OPEN_FLAG_WRITE | OPEN_FLAG_CREATE ), m_line_tx(OPEN_FLAG_READ), - m68k_ram(*this, "m68k_ram"), + m_68k_ram(*this, "m68k_ram"), m_commcpu(*this, M68K_TAG), m_ram(*this, RAM_TAG) { @@ -163,8 +163,8 @@ m3comm_device::m3comm_device(const machine_config &mconfig, const char *tag, dev void m3comm_device::device_start() { - timer = timer_alloc(TIMER_IRQ5); - timer->adjust(attotime::from_usec(10000)); + m_timer = timer_alloc(FUNC(m3comm_device::trigger_irq5), this); + m_timer->adjust(attotime::from_usec(10000)); } //------------------------------------------------- @@ -173,8 +173,8 @@ void m3comm_device::device_start() void m3comm_device::device_reset() { - naomi_control = 0xC000; - naomi_offset = 0; + m_naomi_control = 0xC000; + m_naomi_offset = 0; m_status0 = 0; m_status1 = 0; m_commbank = 0; @@ -194,13 +194,10 @@ uint16_t swapb16(uint16_t data) } -void m3comm_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(m3comm_device::trigger_irq5) { - if(id != TIMER_IRQ5) - return; - m_commcpu->set_input_line(M68K_IRQ_5, ASSERT_LINE); - timer.adjust(attotime::from_usec(10000)); // there is it from actually ?????? + m_timer->adjust(attotime::from_usec(10000)); // Where is this timing from, actually? } ///////////// Internal MMIO @@ -267,7 +264,7 @@ void m3comm_device::ioregs_w(offs_t offset, uint16_t data, uint16_t mem_mask) break; // it seems one of these ^v is IRQ6 ON/ACK, another is data transfer enable case 0x16 / 2: // written 8C at data receive enable, 0 at IRQ6 handler if ((data & 0xFF) == 0x8C) { - LOG("M3COMM Receive offs %04x size %04x\n", recv_offset, recv_size); + LOG("M3COMM Receive offs %04x size %04x\n", m_recv_offset, m_recv_size); /* if (!m_line_rx.is_open()) { @@ -277,7 +274,7 @@ void m3comm_device::ioregs_w(offs_t offset, uint16_t data, uint16_t mem_mask) if (m_line_rx.is_open()) { uint8_t *commram = (uint8_t*)membank("comm_ram")->base(); - m_line_rx.read(&commram[recv_offset], recv_size); + m_line_rx.read(&commram[m_recv_offset], m_recv_size); } */ m_commcpu->set_input_line(M68K_IRQ_6, ASSERT_LINE); // debug hack @@ -287,7 +284,7 @@ void m3comm_device::ioregs_w(offs_t offset, uint16_t data, uint16_t mem_mask) break; // it seems one of these ^v is IRQ4 ON/ACK, another is data transfer enable case 0x1C / 2: // written 8C at data transmit enable, 0 at IRQ4 handler if ((data & 0xFF) == 0x8C) { - LOG("M3COMM Send offs %04x size %04x\n", send_offset, send_size); + LOG("M3COMM Send offs %04x size %04x\n", m_send_offset, m_send_size); /* if (!m_line_tx.is_open()) { @@ -297,23 +294,23 @@ void m3comm_device::ioregs_w(offs_t offset, uint16_t data, uint16_t mem_mask) if (m_line_tx.is_open()) { uint8_t *commram = (uint8_t*)membank("comm_ram")->base(); - m_line_tx.write(&commram[send_offset], send_size); + m_line_tx.write(&commram[m_send_offset], m_send_size); } */ } m_commcpu->set_input_line(M68K_IRQ_4, ((data & 0xFF) == 0x8C) ? ASSERT_LINE : CLEAR_LINE); // debug hack break; case 0x40 / 2: - recv_offset = (recv_offset >> 8) | (data << 8); + m_recv_offset = (m_recv_offset >> 8) | (data << 8); break; case 0x42 / 2: - recv_size = (recv_size >> 8) | (data << 8); + m_recv_size = (m_recv_size >> 8) | (data << 8); break; case 0x44 / 2: - send_offset = (send_offset >> 8) | (data << 8); + m_send_offset = (m_send_offset >> 8) | (data << 8); break; case 0x46 / 2: - send_size = (send_size >> 8) | (data << 8); + m_send_size = (m_send_size >> 8) | (data << 8); break; case 0x88 / 2: COMBINE_DATA(&m_status0); @@ -334,12 +331,12 @@ void m3comm_device::ioregs_w(offs_t offset, uint16_t data, uint16_t mem_mask) uint16_t m3comm_device::m3_m68k_ram_r(offs_t offset) { - uint16_t value = m68k_ram[offset]; // FIXME endian + uint16_t value = m_68k_ram[offset]; // FIXME endian return swapb16(value); } void m3comm_device::m3_m68k_ram_w(offs_t offset, uint16_t data) { - m68k_ram[offset] = swapb16(data); // FIXME endian + m_68k_ram[offset] = swapb16(data); // FIXME endian } uint8_t m3comm_device::m3_comm_ram_r(offs_t offset) { @@ -373,21 +370,21 @@ uint16_t m3comm_device::naomi_r(offs_t offset) switch (offset) { case 0: // 5F7018 - return naomi_control; + return m_naomi_control; case 1: // 5F701C - return naomi_offset; + return m_naomi_offset; case 2: // 5F7020 { -// LOG("M3COMM read @ %08x\n", (naomi_control << 16) | naomi_offset); +// LOG("M3COMM read @ %08x\n", (m_naomi_control << 16) | m_naomi_offset); uint16_t value; - if (naomi_control & 1) - value = m68k_ram[naomi_offset / 2]; // FIXME endian + if (m_naomi_control & 1) + value = m_68k_ram[m_naomi_offset / 2]; // FIXME endian else { uint16_t *commram = (uint16_t*)membank("comm_ram")->base(); - value = commram[naomi_offset / 2]; // FIXME endian + value = commram[m_naomi_offset / 2]; // FIXME endian } - naomi_offset += 2; + m_naomi_offset += 2; return value; } case 3: // 5F7024 @@ -411,21 +408,21 @@ void m3comm_device::naomi_w(offs_t offset, uint16_t data) // bit 14: G1 DMA bus master 0 - active / 1 - disabled // bit 15: 0 - enable / 1 - disable this device ??? // LOG("M3COMM control write %04x\n", data); - naomi_control = data; - m_commcpu->set_input_line(INPUT_LINE_RESET, (naomi_control & 0x20) ? CLEAR_LINE : ASSERT_LINE); + m_naomi_control = data; + m_commcpu->set_input_line(INPUT_LINE_RESET, (m_naomi_control & 0x20) ? CLEAR_LINE : ASSERT_LINE); break; case 1: // 5F701C - naomi_offset = data; + m_naomi_offset = data; break; case 2: // 5F7020 -// LOG("M3COMM write @ %08x %04x\n", (naomi_control << 16) | naomi_offset, data); - if (naomi_control & 1) - m68k_ram[naomi_offset / 2] = data; // FIXME endian +// LOG("M3COMM write @ %08x %04x\n", (m_naomi_control << 16) | m_naomi_offset, data); + if (m_naomi_control & 1) + m_68k_ram[m_naomi_offset / 2] = data; // FIXME endian else { uint16_t *commram = (uint16_t*)membank("comm_ram")->base(); - commram[naomi_offset / 2] = data; // FIXME endian + commram[m_naomi_offset / 2] = data; // FIXME endian } - naomi_offset += 2; + m_naomi_offset += 2; break; case 3: // 5F7024 m_status0 = data; diff --git a/src/mame/machine/m3comm.h b/src/mame/machine/m3comm.h index 7f63d698424..db1684bdcae 100644 --- a/src/mame/machine/m3comm.h +++ b/src/mame/machine/m3comm.h @@ -41,26 +41,25 @@ public: void m3comm_mem(address_map &map); protected: - enum { TIMER_IRQ5 = 1 }; - // device-level overrides virtual void device_start() override; virtual void device_reset() override; virtual void device_reset_after_children() 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(trigger_irq5); + private: - uint16_t naomi_control = 0; - uint16_t naomi_offset = 0; + uint16_t m_naomi_control = 0; + uint16_t m_naomi_offset = 0; uint16_t m_status0 = 0; uint16_t m_status1 = 0; uint16_t m_commbank = 0; - uint16_t recv_offset = 0; - uint16_t recv_size = 0; - uint16_t send_offset = 0; - uint16_t send_size = 0; + uint16_t m_recv_offset = 0; + uint16_t m_recv_size = 0; + uint16_t m_send_offset = 0; + uint16_t m_send_size = 0; emu_file m_line_rx; // rx line - can be either differential, simple serial or toslink @@ -68,9 +67,9 @@ private: char m_localhost[256]{}; char m_remotehost[256]{}; - emu_timer *timer = nullptr; + emu_timer *m_timer = nullptr; - required_shared_ptr<uint16_t> m68k_ram; + required_shared_ptr<uint16_t> m_68k_ram; required_device<m68000_device> m_commcpu; required_device<ram_device> m_ram; }; diff --git a/src/mame/machine/mac.cpp b/src/mame/machine/mac.cpp index 24d129f8ce3..32206173d16 100644 --- a/src/mame/machine/mac.cpp +++ b/src/mame/machine/mac.cpp @@ -1020,19 +1020,19 @@ void mac_state::machine_start() { if (m_screen) { - this->m_scanline_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(mac_state::mac_scanline_tick),this)); + this->m_scanline_timer = timer_alloc(FUNC(mac_state::mac_scanline_tick), this); this->m_scanline_timer->adjust(m_screen->time_until_pos(0, 0)); } else { - m_adbupdate_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(mac_state::mac_adbrefresh_tick),this)); + m_adbupdate_timer = timer_alloc(FUNC(mac_state::mac_adbrefresh_tick), this); m_adbupdate_timer->adjust(attotime::from_hz(70)); } if (m_model != MODEL_MAC_IIFX) - m_6015_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(mac_state::mac_6015_tick),this)); + m_6015_timer = timer_alloc(FUNC(mac_state::mac_6015_tick), this); else - m_6015_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(mac_state::oss_6015_tick),this)); + m_6015_timer = timer_alloc(FUNC(mac_state::oss_6015_tick), this); m_6015_timer->adjust(attotime::never); } @@ -1210,7 +1210,7 @@ void mac_state::mac_driver_init(model_t model) if ((model == MODEL_MAC_CLASSIC_II) || (model == MODEL_MAC_LC) || (model == MODEL_MAC_COLOR_CLASSIC) || (model >= MODEL_MAC_LC_475 && model <= MODEL_MAC_LC_580) || (model == MODEL_MAC_LC_II) || (model == MODEL_MAC_LC_III) || (model == MODEL_MAC_LC_III_PLUS) || ((m_model >= MODEL_MAC_II) && (m_model <= MODEL_MAC_SE30))) { - m_overlay_timeout = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(mac_state::overlay_timeout_func),this)); + m_overlay_timeout = timer_alloc(FUNC(mac_state::overlay_timeout_func), this); } else { diff --git a/src/mame/machine/macadb.cpp b/src/mame/machine/macadb.cpp index 28debf54c4b..0c7ff21b46b 100644 --- a/src/mame/machine/macadb.cpp +++ b/src/mame/machine/macadb.cpp @@ -222,7 +222,7 @@ void macadb_device::device_start() write_adb_data.resolve_safe(); write_adb_irq.resolve_safe(); - this->m_adb_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(macadb_device::mac_adb_tick),this)); + this->m_adb_timer = timer_alloc(FUNC(macadb_device::mac_adb_tick), this); this->m_adb_timer->adjust(attotime::never); std::fill(std::begin(m_adb_buffer), std::end(m_adb_buffer), 0); diff --git a/src/mame/machine/mace.cpp b/src/mame/machine/mace.cpp index d2a1f8c12c3..86d5ffebd10 100644 --- a/src/mame/machine/mace.cpp +++ b/src/mame/machine/mace.cpp @@ -86,8 +86,8 @@ void mace_device::device_start() save_item(NAME(m_ust_msc.m_vin2_msc_ust)); save_item(NAME(m_ust_msc.m_vout_msc_ust)); - m_timer_ust = timer_alloc(TIMER_UST); - m_timer_msc = timer_alloc(TIMER_MSC); + m_timer_ust = timer_alloc(FUNC(mace_device::ust_tick), this); + m_timer_msc = timer_alloc(FUNC(mace_device::msc_tick), this); m_timer_ust->adjust(attotime::never); m_timer_msc->adjust(attotime::never); } @@ -440,20 +440,19 @@ void mace_device::rtc_w(offs_t offset, uint64_t data, uint64_t mem_mask) // TIMERS //************************************************************************** -void mace_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(mace_device::ust_tick) { - if (id == TIMER_UST) - { - m_ust_msc.m_ust++; - m_ust_msc.m_ust_msc &= 0x00000000ffffffffULL; - m_ust_msc.m_ust_msc |= (uint64_t)m_ust_msc.m_ust << 32; - } - else if (id == TIMER_MSC) - { - m_ust_msc.m_msc++; - m_ust_msc.m_ust_msc &= 0xffffffff00000000ULL; - m_ust_msc.m_ust_msc |= m_ust_msc.m_msc; - } + m_ust_msc.m_ust++; + m_ust_msc.m_ust_msc &= 0x00000000ffffffffULL; + m_ust_msc.m_ust_msc |= (uint64_t)m_ust_msc.m_ust << 32; + check_ust_msc_compare(); +} + +TIMER_CALLBACK_MEMBER(mace_device::msc_tick) +{ + m_ust_msc.m_msc++; + m_ust_msc.m_ust_msc &= 0xffffffff00000000ULL; + m_ust_msc.m_ust_msc |= m_ust_msc.m_msc; check_ust_msc_compare(); } diff --git a/src/mame/machine/mace.h b/src/mame/machine/mace.h index 74ed78030c8..f2a29d94726 100644 --- a/src/mame/machine/mace.h +++ b/src/mame/machine/mace.h @@ -35,10 +35,9 @@ protected: virtual void device_start() override; virtual void device_reset() override; virtual void device_add_mconfig(machine_config &config) override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; - static const device_timer_id TIMER_MSC = 0; - static const device_timer_id TIMER_UST = 1; + TIMER_CALLBACK_MEMBER(ust_tick); + TIMER_CALLBACK_MEMBER(msc_tick); // UST/MSC Timer void check_ust_msc_compare(); diff --git a/src/mame/machine/macpci.cpp b/src/mame/machine/macpci.cpp index 570ca958039..034828222d6 100644 --- a/src/mame/machine/macpci.cpp +++ b/src/mame/machine/macpci.cpp @@ -107,7 +107,7 @@ WRITE_LINE_MEMBER(macpci_state::mac_adb_via_out_cb2) void macpci_state::machine_start() { - m_6015_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(macpci_state::mac_6015_tick),this)); + m_6015_timer = timer_alloc(FUNC(macpci_state::mac_6015_tick), this); m_6015_timer->adjust(attotime::never); } diff --git a/src/mame/machine/macrtc.cpp b/src/mame/machine/macrtc.cpp index 0d31c3585fd..c286aaf438f 100644 --- a/src/mame/machine/macrtc.cpp +++ b/src/mame/machine/macrtc.cpp @@ -54,7 +54,7 @@ rtc3430042_device::rtc3430042_device(const machine_config &mconfig, const char * void rtc3430042_device::device_start() { // allocate timers - m_clock_timer = timer_alloc(); + m_clock_timer = timer_alloc(FUNC(rtc3430042_device::seconds_tick), this); m_clock_timer->adjust(attotime::from_hz(clock() / 32768), 0, attotime::from_hz(clock() / 32768)); // state saving @@ -76,10 +76,10 @@ void rtc3430042_device::device_reset() } //------------------------------------------------- -// device_timer - handler timer events +// seconds_tick - //------------------------------------------------- -void rtc3430042_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(rtc3430042_device::seconds_tick) { advance_seconds(); } diff --git a/src/mame/machine/macrtc.h b/src/mame/machine/macrtc.h index f921e7b76b6..66476e63c4c 100644 --- a/src/mame/machine/macrtc.h +++ b/src/mame/machine/macrtc.h @@ -38,7 +38,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_rtc_interface overrides virtual void rtc_clock_updated(int year, int month, int day, int day_of_week, int hour, int minute, int second) override; @@ -49,6 +48,8 @@ protected: virtual bool nvram_read(util::read_stream &file) override; virtual bool nvram_write(util::write_stream &file) override; + TIMER_CALLBACK_MEMBER(seconds_tick); + private: /* state of rTCEnb and rTCClk lines */ uint8_t m_rtc_rTCEnb = 0; diff --git a/src/mame/machine/macscsi.cpp b/src/mame/machine/macscsi.cpp index 7a06b246ad2..3bc17a15fad 100644 --- a/src/mame/machine/macscsi.cpp +++ b/src/mame/machine/macscsi.cpp @@ -96,7 +96,7 @@ void mac_scsi_helper_device::device_resolve_objects() void mac_scsi_helper_device::device_start() { - m_pseudo_dma_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(mac_scsi_helper_device::timer_callback), this)); + m_pseudo_dma_timer = timer_alloc(FUNC(mac_scsi_helper_device::timer_callback), this); save_item(NAME(m_mode)); save_item(NAME(m_read_fifo_bytes)); diff --git a/src/mame/machine/maple-dc.cpp b/src/mame/machine/maple-dc.cpp index 60f7008d243..47e44386efd 100644 --- a/src/mame/machine/maple-dc.cpp +++ b/src/mame/machine/maple-dc.cpp @@ -38,7 +38,7 @@ void maple_dc_device::register_port(int port, maple_device *device) void maple_dc_device::device_start() { logerror("maple_dc_device started\n"); - timer = timer_alloc(0); + timer = timer_alloc(FUNC(maple_dc_device::dma_timer_tick), this); irq_cb.resolve_safe(); mdstar = 0; @@ -68,10 +68,8 @@ void maple_dc_device::device_reset() dma_endflag = false; } -void maple_dc_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(maple_dc_device::dma_timer_tick) { - timer.adjust(attotime::never); - switch(dma_state) { case DMA_WAIT_REPLY: dma_state = DMA_TIMEOUT; diff --git a/src/mame/machine/maple-dc.h b/src/mame/machine/maple-dc.h index deb405b58d3..45d2efbbec1 100644 --- a/src/mame/machine/maple-dc.h +++ b/src/mame/machine/maple-dc.h @@ -49,7 +49,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(dma_timer_tick); private: enum { diff --git a/src/mame/machine/mapledev.cpp b/src/mame/machine/mapledev.cpp index b2a6d11135d..ee4340ee56f 100644 --- a/src/mame/machine/mapledev.cpp +++ b/src/mame/machine/mapledev.cpp @@ -14,7 +14,7 @@ void maple_device::device_start() { host->register_port(host_port, this); - timer = timer_alloc(TIMER_ID); + timer = timer_alloc(FUNC(maple_device::reply_ready), this); save_item(NAME(reply_buffer)); save_item(NAME(reply_size)); @@ -26,15 +26,6 @@ void maple_device::maple_reset() device_reset(); } -void maple_device::device_timer(emu_timer &timer, device_timer_id id, int param) -{ - if(id != TIMER_ID) - return; - - timer.adjust(attotime::never); - reply_ready(); -} - void maple_device::reply_ready_with_delay() { // Arbitrary delay to avoid instant replies @@ -43,7 +34,7 @@ void maple_device::reply_ready_with_delay() timer->adjust(attotime::from_usec(100)); } -void maple_device::reply_ready() +TIMER_CALLBACK_MEMBER(maple_device::reply_ready) { host->end_of_reply(); } diff --git a/src/mame/machine/mapledev.h b/src/mame/machine/mapledev.h index c7bab8597df..2bc3f6d4676 100644 --- a/src/mame/machine/mapledev.h +++ b/src/mame/machine/mapledev.h @@ -16,8 +16,6 @@ public: virtual void maple_reset(); protected: - enum { TIMER_ID = 1000 }; - maple_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock); uint32_t reply_size = 0; @@ -26,9 +24,8 @@ protected: // device-level overrides virtual void device_start() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; - void reply_ready(); + TIMER_CALLBACK_MEMBER(reply_ready); void reply_ready_with_delay(); // Copy a string and complete it with spaces up to size len diff --git a/src/mame/machine/mcr.cpp b/src/mame/machine/mcr.cpp index 3b4323d94fe..61e99cbe5d3 100644 --- a/src/mame/machine/mcr.cpp +++ b/src/mame/machine/mcr.cpp @@ -86,7 +86,7 @@ void mcr_state::machine_start() void mcr_nflfoot_state::machine_start() { /* allocate a timer for the IPU watchdog */ - m_ipu_watchdog_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(mcr_nflfoot_state::ipu_watchdog_reset), this)); + m_ipu_watchdog_timer = timer_alloc(FUNC(mcr_nflfoot_state::ipu_watchdog_reset), this); } diff --git a/src/mame/machine/mcr68.cpp b/src/mame/machine/mcr68.cpp index 9523ebe169f..c8578c5a1ba 100644 --- a/src/mame/machine/mcr68.cpp +++ b/src/mame/machine/mcr68.cpp @@ -20,9 +20,16 @@ * *************************************/ +void mcr68_state::machine_start() +{ + m_493_on_timer = timer_alloc(FUNC(mcr68_state::mcr68_493_callback), this); + m_493_off_timer = timer_alloc(FUNC(mcr68_state::mcr68_493_off_callback), this); +} + void mcr68_state::machine_reset() -{ /* for the most part all MCR/68k games are the same */ - m_v493_callback = timer_expired_delegate(FUNC(mcr68_state::mcr68_493_callback),this); +{ + m_493_on_timer->adjust(attotime::never); + m_493_off_timer->adjust(attotime::never); } @@ -47,7 +54,7 @@ TIMER_DEVICE_CALLBACK_MEMBER( mcr68_state::scanline_cb ) /* also set a timer to generate the 493 signal at a specific time before the next VBLANK */ /* the timing of this is crucial for Blasted and Tri-Sports, which check the timing of */ /* VBLANK and 493 using counter 2 */ - machine().scheduler().timer_set(attotime::from_hz(30) - m_timing_factor, m_v493_callback); + m_493_on_timer->adjust(attotime::from_hz(30) - m_timing_factor); } // HSYNC @@ -72,7 +79,7 @@ TIMER_CALLBACK_MEMBER(mcr68_state::mcr68_493_off_callback) TIMER_CALLBACK_MEMBER(mcr68_state::mcr68_493_callback) { m_maincpu->set_input_line(1, ASSERT_LINE); - machine().scheduler().timer_set(m_screen->scan_period(), timer_expired_delegate(FUNC(mcr68_state::mcr68_493_off_callback),this)); + m_493_off_timer->adjust(m_screen->scan_period()); if (VERBOSE) logerror("--- (INT1) ---\n"); diff --git a/src/mame/machine/mct_adr.cpp b/src/mame/machine/mct_adr.cpp index 81dc3db6907..943f512931c 100644 --- a/src/mame/machine/mct_adr.cpp +++ b/src/mame/machine/mct_adr.cpp @@ -152,9 +152,9 @@ void mct_adr_device::device_start() m_ioc_physical_tag = 0; m_ioc_logical_tag = 0; - m_irq_check = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(mct_adr_device::irq_check), this)); - m_dma_check = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(mct_adr_device::dma_check), this)); - m_interval_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(mct_adr_device::interval_timer), this)); + m_irq_check = timer_alloc(FUNC(mct_adr_device::irq_check), this); + m_dma_check = timer_alloc(FUNC(mct_adr_device::dma_check), this); + m_interval_timer = timer_alloc(FUNC(mct_adr_device::interval_timer), this); m_out_int_timer_asserted = false; m_out_int_device_asserted = false; diff --git a/src/mame/machine/mega32x.cpp b/src/mame/machine/mega32x.cpp index 75cd4728eb5..bf741a87502 100644 --- a/src/mame/machine/mega32x.cpp +++ b/src/mame/machine/mega32x.cpp @@ -1734,7 +1734,7 @@ void sega_32x_device::device_start() } m_stream = stream_alloc(2, 2, 48000 * 4); - m_32x_pwm_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(sega_32x_device::handle_pwm_callback), this)); + m_32x_pwm_timer = timer_alloc(FUNC(sega_32x_device::handle_pwm_callback), this); m_32x_dram0 = std::make_unique<uint16_t[]>(0x40000/2); m_32x_dram1 = std::make_unique<uint16_t[]>(0x40000/2); diff --git a/src/mame/machine/megadriv.cpp b/src/mame/machine/megadriv.cpp index 3f4d649db2c..f7513e21b51 100644 --- a/src/mame/machine/megadriv.cpp +++ b/src/mame/machine/megadriv.cpp @@ -649,7 +649,7 @@ void md_base_state::megadriv_68k_req_z80_bus(offs_t offset, uint16_t data, uint1 /* If the z80 is running, sync the z80 execution state */ if (!m_genz80.z80_is_reset) - machine().scheduler().timer_set(attotime::zero, timer_expired_delegate(FUNC(md_base_state::megadriv_z80_run_state),this)); + m_genz80.z80_run_timer->adjust(attotime::zero); } void md_base_state::megadriv_68k_req_z80_reset(offs_t offset, uint16_t data, uint16_t mem_mask) @@ -693,7 +693,7 @@ void md_base_state::megadriv_68k_req_z80_reset(offs_t offset, uint16_t data, uin m_genz80.z80_is_reset = 1; } } - machine().scheduler().timer_set(attotime::zero, timer_expired_delegate(FUNC(md_base_state::megadriv_z80_run_state),this)); + m_genz80.z80_run_timer->adjust(attotime::zero); } @@ -824,6 +824,9 @@ void md_base_state::machine_start() save_item(NAME(m_megadrive_io_data_regs)); save_item(NAME(m_megadrive_io_ctrl_regs)); save_item(NAME(m_megadrive_io_tx_regs)); + + if (m_z80snd) + m_genz80.z80_run_timer = timer_alloc(FUNC(md_base_state::megadriv_z80_run_state), this); } void md_base_state::machine_reset() @@ -837,7 +840,7 @@ void md_base_state::machine_reset() m_genz80.z80_has_bus = 1; m_genz80.z80_bank_addr = 0; m_vdp->set_scanline_counter(-1); - machine().scheduler().timer_set(attotime::zero, timer_expired_delegate(FUNC(md_base_state::megadriv_z80_run_state),this)); + m_genz80.z80_run_timer->adjust(attotime::zero); } megadrive_reset_io(); diff --git a/src/mame/machine/mhavoc.cpp b/src/mame/machine/mhavoc.cpp index 60bdc933683..49419f2bd3c 100644 --- a/src/mame/machine/mhavoc.cpp +++ b/src/mame/machine/mhavoc.cpp @@ -79,6 +79,8 @@ void mhavoc_state::machine_start() save_item(NAME(m_gamma_irq_clock)); save_item(NAME(m_speech_write_buffer)); + + m_gamma_sync_timer = machine().scheduler().timer_alloc(timer_expired_delegate()); } diff --git a/src/mame/machine/micro3d.cpp b/src/mame/machine/micro3d.cpp index 5b4758b8767..a5103f2135b 100644 --- a/src/mame/machine/micro3d.cpp +++ b/src/mame/machine/micro3d.cpp @@ -125,18 +125,6 @@ static inline int64_t normalised_multiply(int32_t a, int32_t b) return result >> 14; } -void micro3d_state::device_timer(emu_timer &timer, device_timer_id id, int param) -{ - switch (id) - { - case TIMER_MAC_DONE: - mac_done_callback(param); - break; - default: - throw emu_fatalerror("Unknown id in micro3d_state::device_timer"); - } -} - TIMER_CALLBACK_MEMBER(micro3d_state::mac_done_callback) { m_drmath->set_input_line(AM29000_INTR0, ASSERT_LINE); @@ -334,7 +322,7 @@ void micro3d_state::micro3d_mac2_w(uint32_t data) /* TODO: Calculate a better estimate for timing */ if (m_mac_stat) - timer_set(attotime::from_hz(MAC_CLK) * mac_cycles, TIMER_MAC_DONE); + m_mac_done_timer->adjust(attotime::from_hz(MAC_CLK) * mac_cycles); m_mrab11 = mrab11; m_vtx_addr = vtx_addr; @@ -530,9 +518,15 @@ void micro3d_state::init_botss() init_micro3d(); } +void micro3d_state::machine_start() +{ + m_mac_done_timer = timer_alloc(FUNC(micro3d_state::mac_done_callback), this); +} + void micro3d_state::machine_reset() { m_vgb->set_input_line(INPUT_LINE_RESET, ASSERT_LINE); m_drmath->set_input_line(INPUT_LINE_RESET, ASSERT_LINE); m_audiocpu->set_input_line(INPUT_LINE_RESET, ASSERT_LINE); + m_mac_done_timer->adjust(attotime::never); } diff --git a/src/mame/machine/microtan.cpp b/src/mame/machine/microtan.cpp index 2c9504c5ff4..0a3c2f07feb 100644 --- a/src/mame/machine/microtan.cpp +++ b/src/mame/machine/microtan.cpp @@ -365,7 +365,7 @@ void microtan_state::init_microtan() { init_gfx2(); - m_pulse_nmi_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(microtan_state::pulse_nmi), this)); + m_pulse_nmi_timer = timer_alloc(FUNC(microtan_state::pulse_nmi), this); } void microtan_state::machine_start() diff --git a/src/mame/machine/midikbd.cpp b/src/mame/machine/midikbd.cpp index 5fd3cbdb85c..3ec87ae9613 100644 --- a/src/mame/machine/midikbd.cpp +++ b/src/mame/machine/midikbd.cpp @@ -13,71 +13,66 @@ midi_keyboard_device::midi_keyboard_device(const machine_config &mconfig, const { } -void midi_keyboard_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(midi_keyboard_device::scan_keyboard) { - if(!id) + const int keyboard_notes[24] = { - const int keyboard_notes[24] = - { - 0x3c, // C1 - 0x3d, // C1# - 0x3e, // D1 - 0x3f, // D1# - 0x40, // E1 - 0x41, // F1 - 0x42, // F1# - 0x43, // G1 - 0x44, // G1# - 0x45, // A1 - 0x46, // A1# - 0x47, // B1 - 0x48, // C2 - 0x49, // C2# - 0x4a, // D2 - 0x4b, // D2# - 0x4c, // E2 - 0x4d, // F2 - 0x4e, // F2# - 0x4f, // G2 - 0x50, // G2# - 0x51, // A2 - 0x52, // A2# - 0x53, // B2 - }; - - int i; + 0x3c, // C1 + 0x3d, // C1# + 0x3e, // D1 + 0x3f, // D1# + 0x40, // E1 + 0x41, // F1 + 0x42, // F1# + 0x43, // G1 + 0x44, // G1# + 0x45, // A1 + 0x46, // A1# + 0x47, // B1 + 0x48, // C2 + 0x49, // C2# + 0x4a, // D2 + 0x4b, // D2# + 0x4c, // E2 + 0x4d, // F2 + 0x4e, // F2# + 0x4f, // G2 + 0x50, // G2# + 0x51, // A2 + 0x52, // A2# + 0x53, // B2 + }; - uint32_t kbstate = m_keyboard->read(); - if(kbstate != m_keyboard_state) + uint32_t kbstate = m_keyboard->read(); + if (kbstate != m_keyboard_state) + { + for (int i = 0; i < 24; i++) { - for (i=0; i < 24; i++) - { - int kbnote = keyboard_notes[i]; + int kbnote = keyboard_notes[i]; - if ((m_keyboard_state & (1 << i)) != 0 && (kbstate & (1 << i)) == 0) - { - // key was on, now off -> send Note Off message - push_tx(0x80); - push_tx(kbnote); - push_tx(0x7f); - } - else if ((m_keyboard_state & (1 << i)) == 0 && (kbstate & (1 << i)) != 0) - { - // key was off, now on -> send Note On message - push_tx(0x90); - push_tx(kbnote); - push_tx(0x7f); - } + if ((m_keyboard_state & (1 << i)) != 0 && (kbstate & (1 << i)) == 0) + { + // key was on, now off -> send Note Off message + push_tx(0x80); + push_tx(kbnote); + push_tx(0x7f); + } + else if ((m_keyboard_state & (1 << i)) == 0 && (kbstate & (1 << i)) != 0) + { + // key was off, now on -> send Note On message + push_tx(0x90); + push_tx(kbnote); + push_tx(0x7f); } } - else - // no messages, send Active Sense message instead - push_tx(0xfe); - - m_keyboard_state = kbstate; - if(is_transmit_register_empty()) - tra_complete(); } + else + // no messages, send Active Sense message instead + push_tx(0xfe); + + m_keyboard_state = kbstate; + if (is_transmit_register_empty()) + tra_complete(); } void midi_keyboard_device::device_start() @@ -86,7 +81,7 @@ void midi_keyboard_device::device_start() set_tra_rate(clock()); m_out_tx_func.resolve_safe(); m_head = m_tail = 0; - m_keyboard_timer = timer_alloc(); + m_keyboard_timer = timer_alloc(FUNC(midi_keyboard_device::scan_keyboard), this); m_keyboard_timer->adjust(attotime::from_msec(10), 0, attotime::from_msec(10)); } @@ -97,7 +92,7 @@ void midi_keyboard_device::tra_callback() void midi_keyboard_device::tra_complete() { - if(m_head != m_tail) + if (m_head != m_tail) { transmit_register_setup(m_buffer[m_tail]); ++m_tail %= 16; diff --git a/src/mame/machine/midikbd.h b/src/mame/machine/midikbd.h index f9cdc05fed3..9048153f530 100644 --- a/src/mame/machine/midikbd.h +++ b/src/mame/machine/midikbd.h @@ -17,10 +17,11 @@ public: auto tx_callback() { return m_out_tx_func.bind(); } protected: - void device_start() override; - void tra_callback() override; - void tra_complete() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; + virtual void device_start() override; + virtual void tra_callback() override; + virtual void tra_complete() override; + + TIMER_CALLBACK_MEMBER(scan_keyboard); private: void push_tx(uint8_t data) { ++m_head %= 16; m_buffer[m_head] = data; } diff --git a/src/mame/machine/midwayic.cpp b/src/mame/machine/midwayic.cpp index 5ea2fe4d74d..eae2ab7d165 100644 --- a/src/mame/machine/midwayic.cpp +++ b/src/mame/machine/midwayic.cpp @@ -375,7 +375,7 @@ void midway_serial_pic2_device::device_start() //m_yearoffs = yearoffs; m_time_just_written = 0; - m_time_write_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(midway_serial_pic2_device::reset_timer),this)); + m_time_write_timer = timer_alloc(FUNC(midway_serial_pic2_device::reset_timer), this); memset(m_default_nvram, 0xff, sizeof(m_default_nvram)); } diff --git a/src/mame/machine/mie.cpp b/src/mame/machine/mie.cpp index 9ea80066912..77639bd5ea8 100644 --- a/src/mame/machine/mie.cpp +++ b/src/mame/machine/mie.cpp @@ -89,7 +89,7 @@ mie_device::mie_device(const machine_config &mconfig, const char *tag, device_t void mie_device::device_start() { maple_device::device_start(); - timer = timer_alloc(0); + timer = timer_alloc(FUNC(mie_device::update_irq_reply), this); save_item(NAME(gpiodir)); save_item(NAME(gpio_val)); @@ -143,16 +143,15 @@ void mie_device::control_w(offs_t offset, uint8_t data) } } -void mie_device::device_timer(emu_timer &_timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(mie_device::update_irq_reply) { - timer->adjust(attotime::never); if(control & CTRL_RXB) { control &= ~CTRL_RXB; control |= CTRL_RFB; raise_irq(maple_irqlevel); } if(control & (CTRL_TXB|CTRL_CTXB)) { - reply_ready(); + reply_ready(0); lreg -= reply_size; if(reply_partial) { control &= ~CTRL_CTXB; @@ -312,7 +311,7 @@ void mie_device::lreg_w(uint8_t data) uint8_t mie_device::jvs_r() { - if (jvs_lcr & 0x80) + if(jvs_lcr & 0x80) return 0; const uint8_t *buf; @@ -325,7 +324,7 @@ uint8_t mie_device::jvs_r() void mie_device::jvs_w(uint8_t data) { - if (jvs_lcr & 0x80) + if(jvs_lcr & 0x80) return; jvs->push(data); diff --git a/src/mame/machine/mie.h b/src/mame/machine/mie.h index 1f72056cf9a..17dc7ddad8d 100644 --- a/src/mame/machine/mie.h +++ b/src/mame/machine/mie.h @@ -83,12 +83,13 @@ 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; // optional information overrides virtual const tiny_rom_entry *device_rom_region() const override; virtual void device_add_mconfig(machine_config &config) override; + TIMER_CALLBACK_MEMBER(update_irq_reply); + private: enum { TBUF_SIZE = 8 }; diff --git a/src/mame/machine/mips_rambo.cpp b/src/mame/machine/mips_rambo.cpp index 017d24fef77..892575ced58 100644 --- a/src/mame/machine/mips_rambo.cpp +++ b/src/mame/machine/mips_rambo.cpp @@ -73,9 +73,9 @@ void mips_rambo_device::device_start() ch.write_cb.resolve_safe(); } - m_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(mips_rambo_device::timer), this)); - m_dma = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(mips_rambo_device::dma), this)); - m_buzzer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(mips_rambo_device::buzzer), this)); + m_timer = timer_alloc(FUNC(mips_rambo_device::timer), this); + m_dma = timer_alloc(FUNC(mips_rambo_device::dma), this); + m_buzzer = timer_alloc(FUNC(mips_rambo_device::buzzer), this); } void mips_rambo_device::device_reset() diff --git a/src/mame/machine/mm1kb.cpp b/src/mame/machine/mm1kb.cpp index 800b73c5b30..9b7c2080223 100644 --- a/src/mame/machine/mm1kb.cpp +++ b/src/mame/machine/mm1kb.cpp @@ -211,11 +211,6 @@ mm1_keyboard_device::mm1_keyboard_device(const machine_config &mconfig, const ch { } -enum -{ - SCAN_TIMER, -}; - //------------------------------------------------- // device_start - device-specific startup //------------------------------------------------- @@ -226,7 +221,7 @@ void mm1_keyboard_device::device_start() m_write_kbst.resolve_safe(); // allocate timers - m_scan_timer = timer_alloc(SCAN_TIMER); + m_scan_timer = timer_alloc(FUNC(mm1_keyboard_device::scan_keyboard), this); m_scan_timer->adjust(attotime::from_hz(clock()), 0, attotime::from_hz(clock())); // add notification request for system shut down (to play back the power switch sound once more) @@ -244,10 +239,10 @@ void mm1_keyboard_device::shut_down_mm1() } //------------------------------------------------- -// device_timer - handler timer events +// scan_keyboard //------------------------------------------------- -void mm1_keyboard_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(mm1_keyboard_device::scan_keyboard) { // handle scan timer uint8_t data = 0xff; diff --git a/src/mame/machine/mm1kb.h b/src/mame/machine/mm1kb.h index 5d019c3daa4..3a38b086a0a 100644 --- a/src/mame/machine/mm1kb.h +++ b/src/mame/machine/mm1kb.h @@ -48,13 +48,14 @@ public: protected: // device-level overrides virtual void device_start() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; // optional information overrides virtual const tiny_rom_entry *device_rom_region() const override; virtual void device_add_mconfig(machine_config &config) override; virtual ioport_constructor device_input_ports() const override; + TIMER_CALLBACK_MEMBER(scan_keyboard); + private: devcb_write_line m_write_kbst; diff --git a/src/mame/machine/mpu4.cpp b/src/mame/machine/mpu4.cpp index 00e59359ef8..9d2ccbdc2e6 100644 --- a/src/mame/machine/mpu4.cpp +++ b/src/mame/machine/mpu4.cpp @@ -693,15 +693,10 @@ void mpu4_state::ic24_setup() } -void mpu4_state::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(mpu4_state::update_ic24) { - switch(id) - { - case TIMER_IC24: - m_ic23_active=0; - ic24_output(1); - break; - } + m_ic23_active=0; + ic24_output(1); } @@ -1256,10 +1251,10 @@ all eight meters are driven from this port, giving the 8 line driver chip //This may be overkill, but the meter sensing is VERY picky - int combined_meter = m_meters->GetActivity(0) | m_meters->GetActivity(1) | - m_meters->GetActivity(2) | m_meters->GetActivity(3) | - m_meters->GetActivity(4) | m_meters->GetActivity(5) | - m_meters->GetActivity(6) | m_meters->GetActivity(7); + int combined_meter = m_meters->get_activity(0) | m_meters->get_activity(1) | + m_meters->get_activity(2) | m_meters->get_activity(3) | + m_meters->get_activity(4) | m_meters->get_activity(5) | + m_meters->get_activity(6) | m_meters->get_activity(7); if(combined_meter) { @@ -2167,7 +2162,7 @@ void mpu4_state::mpu4_config_common() m_digits.resolve(); m_triacs.resolve(); - m_ic24_timer = timer_alloc(TIMER_IC24); + m_ic24_timer = timer_alloc(FUNC(mpu4_state::update_ic24), this); m_lamp_strobe_ext_persistence = 0; } diff --git a/src/mame/machine/mw8080bw.cpp b/src/mame/machine/mw8080bw.cpp index cbdd0f70a65..482b7f1bb9a 100644 --- a/src/mame/machine/mw8080bw.cpp +++ b/src/mame/machine/mw8080bw.cpp @@ -99,7 +99,7 @@ IRQ_CALLBACK_MEMBER(mw8080bw_state::interrupt_vector) void mw8080bw_state::mw8080bw_create_interrupt_timer( ) { - m_interrupt_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(mw8080bw_state::interrupt_trigger),this)); + m_interrupt_timer = timer_alloc(FUNC(mw8080bw_state::interrupt_trigger), this); } diff --git a/src/mame/machine/n64.cpp b/src/mame/machine/n64.cpp index e29569aa1b0..ea066f44335 100644 --- a/src/mame/machine/n64.cpp +++ b/src/mame/machine/n64.cpp @@ -116,12 +116,12 @@ void n64_periphs::poll_reset_button(bool button) void n64_periphs::device_start() { - ai_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(n64_periphs::ai_timer_callback),this)); - pi_dma_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(n64_periphs::pi_dma_callback),this)); - si_dma_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(n64_periphs::si_dma_callback),this)); - vi_scanline_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(n64_periphs::vi_scanline_callback),this)); - dp_delay_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(n64_periphs::dp_delay_callback),this)); - reset_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(n64_periphs::reset_timer_callback),this)); + ai_timer = timer_alloc(FUNC(n64_periphs::ai_timer_callback), this); + pi_dma_timer = timer_alloc(FUNC(n64_periphs::pi_dma_callback), this); + si_dma_timer = timer_alloc(FUNC(n64_periphs::si_dma_callback), this); + vi_scanline_timer = timer_alloc(FUNC(n64_periphs::vi_scanline_callback), this); + dp_delay_timer = timer_alloc(FUNC(n64_periphs::dp_delay_callback), this); + reset_timer = timer_alloc(FUNC(n64_periphs::reset_timer_callback), this); m_n64 = machine().driver_data<n64_state>(); } diff --git a/src/mame/machine/namco06.cpp b/src/mame/machine/namco06.cpp index df37c79d1c6..a64e5c45e7d 100644 --- a/src/mame/machine/namco06.cpp +++ b/src/mame/machine/namco06.cpp @@ -268,7 +268,7 @@ void namco_06xx_device::device_start() m_write.resolve_all_safe(); /* allocate a timer */ - m_nmi_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(namco_06xx_device::nmi_generate),this)); + m_nmi_timer = timer_alloc(FUNC(namco_06xx_device::nmi_generate), this); save_item(NAME(m_control)); save_item(NAME(m_next_timer_state)); diff --git a/src/mame/machine/namcos21_dsp.cpp b/src/mame/machine/namcos21_dsp.cpp index 14810b43f07..49ee6e38777 100644 --- a/src/mame/machine/namcos21_dsp.cpp +++ b/src/mame/machine/namcos21_dsp.cpp @@ -29,7 +29,7 @@ namcos21_dsp_device::namcos21_dsp_device(const machine_config &mconfig, const ch void namcos21_dsp_device::device_start() { m_winrun_dspcomram = std::make_unique<uint16_t[]>(0x1000*2); - m_suspend_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(namcos21_dsp_device::suspend_callback),this)); + m_suspend_timer = timer_alloc(FUNC(namcos21_dsp_device::suspend_callback), this); m_pointram = std::make_unique<uint8_t[]>(PTRAM_SIZE); m_pointram_idx = 0; diff --git a/src/mame/machine/naomig1.cpp b/src/mame/machine/naomig1.cpp index 716714e1da2..2b8ccab0845 100644 --- a/src/mame/machine/naomig1.cpp +++ b/src/mame/machine/naomig1.cpp @@ -36,7 +36,7 @@ naomi_g1_device::naomi_g1_device(const machine_config &mconfig, device_type type void naomi_g1_device::device_start() { - timer = timer_alloc(G1_TIMER_ID); + timer = timer_alloc(FUNC(naomi_g1_device::trigger_gdrom_irq), this); irq_cb.resolve_safe(); ext_irq_cb.resolve_safe(); reset_out_cb.resolve_safe(); @@ -58,9 +58,8 @@ void naomi_g1_device::device_reset() set_ext_irq(CLEAR_LINE); } -void naomi_g1_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(naomi_g1_device::trigger_gdrom_irq) { - timer.adjust(attotime::never); if(!gdst) return; gdst = 0; diff --git a/src/mame/machine/naomig1.h b/src/mame/machine/naomig1.h index 32560d4eab9..924c3712aa5 100644 --- a/src/mame/machine/naomig1.h +++ b/src/mame/machine/naomig1.h @@ -51,13 +51,10 @@ public: uint32_t sb_gdlend_r(offs_t offset, uint32_t mem_mask = ~0); // 5f74f8 protected: - enum { G1_TIMER_ID = 0x42 }; - naomi_g1_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 void dma_get_position(uint8_t *&base, uint32_t &limit, bool to_maincpu) = 0; virtual void dma_advance(uint32_t size) = 0; @@ -65,6 +62,8 @@ protected: void set_ext_irq(int state) { ext_irq_cb(state); } void set_reset_out() { reset_out_cb(ASSERT_LINE); } + TIMER_CALLBACK_MEMBER(trigger_gdrom_irq); + private: uint32_t gdstar, gdlen, gddir, gden, gdst; diff --git a/src/mame/machine/nb1412m2.cpp b/src/mame/machine/nb1412m2.cpp index 9e4ea2761d3..dd1a134df68 100644 --- a/src/mame/machine/nb1412m2.cpp +++ b/src/mame/machine/nb1412m2.cpp @@ -158,9 +158,9 @@ void nb1412m2_device::device_start() save_item(NAME(m_const90)); save_item(NAME(m_timer_rate)); - m_timer = timer_alloc(TIMER_MAIN); + m_timer = timer_alloc(FUNC(nb1412m2_device::main_timer_tick), this); m_timer->adjust(attotime::never); - m_dac_timer = timer_alloc(TIMER_DAC); + m_dac_timer = timer_alloc(FUNC(nb1412m2_device::update_dac), this); m_dac_cb.resolve_safe(); } @@ -184,29 +184,24 @@ void nb1412m2_device::device_reset() m_dac_timer->adjust(attotime::never); } -void nb1412m2_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(nb1412m2_device::main_timer_tick) { - switch (id) + m_timer_reg = true; +} + +TIMER_CALLBACK_MEMBER(nb1412m2_device::update_dac) +{ + if(m_dac_playback == true) { - case TIMER_MAIN: - m_timer_reg = true; - m_timer->adjust(attotime::never); - break; - case TIMER_DAC: - if(m_dac_playback == true) - { - uint8_t dac_value; - dac_value = m_data[m_dac_current_address]; - m_dac_cb(dac_value); - m_dac_current_address++; - m_dac_current_address &= m_data.length() - 1; - if(dac_value == 0x80) - m_dac_playback = false; - } - - break; - default: - throw emu_fatalerror("Unknown id in nb1412m2_device::device_timer"); + uint8_t dac_value; + dac_value = m_data[m_dac_current_address]; + m_dac_cb(dac_value); + m_dac_current_address++; + m_dac_current_address &= m_data.length() - 1; + if(dac_value == 0x80) + { + m_dac_playback = false; + } } } diff --git a/src/mame/machine/nb1412m2.h b/src/mame/machine/nb1412m2.h index ca6074c3ccb..f91b3110767 100644 --- a/src/mame/machine/nb1412m2.h +++ b/src/mame/machine/nb1412m2.h @@ -39,9 +39,11 @@ 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; virtual space_config_vector memory_space_config() const override; + TIMER_CALLBACK_MEMBER(main_timer_tick); + TIMER_CALLBACK_MEMBER(update_dac); + private: uint8_t m_command; uint16_t m_rom_address; @@ -60,9 +62,6 @@ private: required_region_ptr<uint8_t> m_data; devcb_write8 m_dac_cb; - static const device_timer_id TIMER_MAIN = 1; - static const device_timer_id TIMER_DAC = 2; - void rom_address_w(offs_t offset, uint8_t data); uint8_t rom_decrypt_r(); void rom_op_w(uint8_t data); diff --git a/src/mame/machine/nb1413m3.cpp b/src/mame/machine/nb1413m3.cpp index cf7a26baa54..03400207522 100644 --- a/src/mame/machine/nb1413m3.cpp +++ b/src/mame/machine/nb1413m3.cpp @@ -55,7 +55,7 @@ nb1413m3_device::nb1413m3_device(const machine_config &mconfig, const char *tag, void nb1413m3_device::device_start() { m_led.resolve(); - m_timer_cb = timer_alloc(TIMER_CB); + m_timer_cb = timer_alloc(FUNC(nb1413m3_device::timer_callback), this); m_timer_cb->adjust(attotime::zero); save_item(NAME(m_nb1413m3_type)); @@ -103,18 +103,6 @@ void nb1413m3_device::device_reset() DEVICE HANDLERS *****************************************************************************/ -void nb1413m3_device::device_timer(emu_timer &timer, device_timer_id id, int param) -{ - switch (id) - { - case TIMER_CB: - timer_callback(param); - break; - default: - throw emu_fatalerror("Unknown id in nb1413m3_device::device_timer"); - } -} - /* TODO: is all of this actually programmable? */ TIMER_CALLBACK_MEMBER( nb1413m3_device::timer_callback ) { diff --git a/src/mame/machine/nb1413m3.h b/src/mame/machine/nb1413m3.h index b33033d3c0c..baa1d51b660 100644 --- a/src/mame/machine/nb1413m3.h +++ b/src/mame/machine/nb1413m3.h @@ -139,11 +139,6 @@ public: // configuration helpers void set_type(int type) { m_nb1413m3_type = type; } - enum - { - TIMER_CB - }; - void nmi_clock_w(uint8_t data); uint8_t sndrom_r(address_space &space, offs_t offset); void sndrombank1_w(uint8_t data); @@ -180,7 +175,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; private: diff --git a/src/mame/machine/nes_vt_soc.cpp b/src/mame/machine/nes_vt_soc.cpp index a3b87525f5b..4f86276c97d 100644 --- a/src/mame/machine/nes_vt_soc.cpp +++ b/src/mame/machine/nes_vt_soc.cpp @@ -427,17 +427,17 @@ void nes_vt02_vt03_soc_device::chr_w(offs_t offset, uint8_t data) -void nes_vt02_vt03_soc_device::scanline_irq(int scanline, int vblank, int blanked) +void nes_vt02_vt03_soc_device::scanline_irq(int scanline, bool vblank, bool blanked) { video_irq(false, scanline, vblank, blanked); } -void nes_vt02_vt03_soc_device::hblank_irq(int scanline, int vblank, int blanked) +void nes_vt02_vt03_soc_device::hblank_irq(int scanline, bool vblank, bool blanked) { video_irq(true, scanline, vblank, blanked); } -void nes_vt02_vt03_soc_device::video_irq(bool hblank, int scanline, int vblank, int blanked) +void nes_vt02_vt03_soc_device::video_irq(bool hblank, int scanline, bool vblank, bool blanked) { //TSYNEN if (((m_410x[0xb] >> 7) & 0x01) == hblank) diff --git a/src/mame/machine/nes_vt_soc.h b/src/mame/machine/nes_vt_soc.h index 8fd5e21acf6..9a1cb3f6caf 100644 --- a/src/mame/machine/nes_vt_soc.h +++ b/src/mame/machine/nes_vt_soc.h @@ -80,9 +80,9 @@ protected: uint8_t spr_r(offs_t offset); uint8_t chr_r(offs_t offset); void chr_w(offs_t offset, uint8_t data); - void scanline_irq(int scanline, int vblank, int blanked); - void hblank_irq(int scanline, int vblank, int blanked); - void video_irq(bool hblank, int scanline, int vblank, int blanked); + void scanline_irq(int scanline, bool vblank, bool blanked); + void hblank_irq(int scanline, bool vblank, bool blanked); + void video_irq(bool hblank, int scanline, bool vblank, bool blanked); uint8_t nt_r(offs_t offset); void nt_w(offs_t offset, uint8_t data); int calculate_real_video_address(int addr, int extended, int readtype); diff --git a/src/mame/machine/nextkbd.cpp b/src/mame/machine/nextkbd.cpp index eadc0606563..deb6036f76c 100644 --- a/src/mame/machine/nextkbd.cpp +++ b/src/mame/machine/nextkbd.cpp @@ -33,7 +33,7 @@ void nextkbd_device::device_start() int_power_cb.resolve_safe(); int_nmi_cb.resolve_safe(); - poll_timer = timer_alloc(0); + poll_timer = timer_alloc(FUNC(nextkbd_device::update_tick), this); save_item(NAME(ctrl_snd)); save_item(NAME(ctrl_kms)); @@ -124,7 +124,7 @@ void nextkbd_device::update_mouse(bool force_update) send(); } -void nextkbd_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(nextkbd_device::update_tick) { if(!fifo_empty()) send(); diff --git a/src/mame/machine/nextkbd.h b/src/mame/machine/nextkbd.h index 60e6d84735e..f07afaf405a 100644 --- a/src/mame/machine/nextkbd.h +++ b/src/mame/machine/nextkbd.h @@ -35,9 +35,10 @@ 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 ioport_constructor device_input_ports() const override; + TIMER_CALLBACK_MEMBER(update_tick); + private: // Big thanks to the previous emulator for that information enum { diff --git a/src/mame/machine/osborne1.cpp b/src/mame/machine/osborne1.cpp index 0b18cfe1193..840ff50d22f 100644 --- a/src/mame/machine/osborne1.cpp +++ b/src/mame/machine/osborne1.cpp @@ -279,13 +279,13 @@ void osborne1_state::machine_start() m_bank_fxxx->configure_entries(0, 1, m_ram->pointer() + 0xF000, 0); m_bank_fxxx->configure_entries(1, 1, m_ram->pointer() + 0x10000, 0); - m_video_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(osborne1_state::video_callback), this)); + m_video_timer = timer_alloc(FUNC(osborne1_state::video_callback), this); m_tilemap = &machine().tilemap().create( *m_gfxdecode, tilemap_get_info_delegate(*this, FUNC(osborne1_state::get_tile_info)), TILEMAP_SCAN_ROWS, 8, 10, 128, 32); - m_acia_rxc_txc_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(osborne1_state::acia_rxc_txc_callback), this)); + m_acia_rxc_txc_timer = timer_alloc(FUNC(osborne1_state::acia_rxc_txc_callback), this); m_maincpu->space(AS_PROGRAM).cache(m_mem_cache); diff --git a/src/mame/machine/p2000t_mdcr.cpp b/src/mame/machine/p2000t_mdcr.cpp index 8e6fa4d2a83..c9559ab50ed 100644 --- a/src/mame/machine/p2000t_mdcr.cpp +++ b/src/mame/machine/p2000t_mdcr.cpp @@ -101,7 +101,7 @@ mdcr_device::mdcr_device(machine_config const &mconfig, char const *tag, device_ void mdcr_device::device_start() { - m_read_timer = timer_alloc(); + m_read_timer = timer_alloc(FUNC(mdcr_device::read_timer_tick), this); m_read_timer->adjust(attotime::from_hz(44100), 0, attotime::from_hz(44100)); save_item(NAME(m_fwd)); @@ -132,7 +132,7 @@ void mdcr_device::device_post_load() m_cassette->seek(m_save_tape_time, SEEK_SET); } -void mdcr_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(mdcr_device::read_timer_tick) { if (!m_recording && m_cassette->motor_on()) { diff --git a/src/mame/machine/p2000t_mdcr.h b/src/mame/machine/p2000t_mdcr.h index d114414e257..4c5ebce9d39 100644 --- a/src/mame/machine/p2000t_mdcr.h +++ b/src/mame/machine/p2000t_mdcr.h @@ -75,10 +75,10 @@ protected: virtual void device_start() override; virtual void device_pre_save() override; virtual void device_post_load() 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(read_timer_tick); + private: /// \brief A Phase Decoder used in a Philips MDCR220 Mini Cassette Recorder /// diff --git a/src/mame/machine/pc1512kb.cpp b/src/mame/machine/pc1512kb.cpp index 288bdb476ac..91dc17bea62 100644 --- a/src/mame/machine/pc1512kb.cpp +++ b/src/mame/machine/pc1512kb.cpp @@ -226,7 +226,7 @@ void pc1512_keyboard_device::device_start() { m_leds.resolve(); // allocate timers - m_reset_timer = timer_alloc(); + m_reset_timer = timer_alloc(FUNC(pc1512_keyboard_device::reset_timer_tick), this); // resolve callbacks m_write_clock.resolve_safe(); @@ -253,10 +253,10 @@ void pc1512_keyboard_device::device_reset() //------------------------------------------------- -// device_timer - handler timer events +// reset_timer_tick - reset the keyboard //------------------------------------------------- -void pc1512_keyboard_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(pc1512_keyboard_device::reset_timer_tick) { if (!m_clock_in) { diff --git a/src/mame/machine/pc1512kb.h b/src/mame/machine/pc1512kb.h index 538f8c51998..d6a69f29061 100644 --- a/src/mame/machine/pc1512kb.h +++ b/src/mame/machine/pc1512kb.h @@ -48,13 +48,14 @@ 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; // optional information overrides virtual const tiny_rom_entry *device_rom_region() const override; virtual void device_add_mconfig(machine_config &config) override; virtual ioport_constructor device_input_ports() const override; + TIMER_CALLBACK_MEMBER(reset_timer_tick); + private: enum { diff --git a/src/mame/machine/pc80s31k.cpp b/src/mame/machine/pc80s31k.cpp index bb3004c8204..1b85cff8daa 100644 --- a/src/mame/machine/pc80s31k.cpp +++ b/src/mame/machine/pc80s31k.cpp @@ -295,13 +295,11 @@ void pc80s31_device::device_add_mconfig(machine_config &config) } //------------------------------------------------- -// device_timer - device-specific timers +// tc_zero_tick //------------------------------------------------- -void pc80s31_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(pc80s31_device::tc_zero_tick) { - assert(id == 0); - m_fdc->tc_w(false); // several games tries to scan invalid IDs from their structures, if this hits then @@ -326,7 +324,7 @@ void pc80s31_device::device_timer(emu_timer &timer, device_timer_id id, int para void pc80s31_device::device_start() { - m_tc_zero_timer = timer_alloc(0); + m_tc_zero_timer = timer_alloc(FUNC(pc80s31_device::tc_zero_tick), this); save_item(NAME(m_irq_vector)); } diff --git a/src/mame/machine/pc80s31k.h b/src/mame/machine/pc80s31k.h index 4d08610455b..f54d0d511bb 100644 --- a/src/mame/machine/pc80s31k.h +++ b/src/mame/machine/pc80s31k.h @@ -38,10 +38,11 @@ protected: virtual void device_start() override; virtual void device_reset() override; virtual const tiny_rom_entry *device_rom_region() const override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; virtual void fdc_io(address_map &map); + TIMER_CALLBACK_MEMBER(tc_zero_tick); + required_device<upd765a_device> m_fdc; required_device_array<floppy_connector, 2> m_floppy; u8 m_irq_vector = 0; diff --git a/src/mame/machine/pc9801_kbd.cpp b/src/mame/machine/pc9801_kbd.cpp index 12dc4eaa2e9..26ce6a92409 100644 --- a/src/mame/machine/pc9801_kbd.cpp +++ b/src/mame/machine/pc9801_kbd.cpp @@ -47,11 +47,11 @@ pc9801_kbd_device::pc9801_kbd_device(const machine_config &mconfig, const char * INPUT_CHANGED_MEMBER(pc9801_kbd_device::key_stroke) { - if(newval && !oldval) - m_rx_buf[uint8_t(param) & 0x7f] = 1; + if (newval && !oldval) + m_rx_buf[param & 0x7f] = 1; - if(oldval && !newval) - m_rx_buf[uint8_t(param) & 0x7f] = 2; + if (oldval && !newval) + m_rx_buf[param & 0x7f] = 2; } static INPUT_PORTS_START( pc9801_kbd ) @@ -240,7 +240,7 @@ void pc9801_kbd_device::device_start() { m_write_irq.resolve_safe(); - m_rxtimer = timer_alloc(RX_TIMER); + m_rxtimer = timer_alloc(FUNC(pc9801_kbd_device::rx_timer_tick), this); m_rxtimer->adjust(attotime::from_hz(clock()), 0, attotime::from_hz(clock())); } @@ -251,9 +251,7 @@ void pc9801_kbd_device::device_start() void pc9801_kbd_device::device_reset() { - int i; - - for(i=0;i<0x80;i++) + for (int i = 0; i < 0x80; i++) m_rx_buf[i] = 0; m_keyb_tx = 0xff; @@ -262,39 +260,34 @@ void pc9801_kbd_device::device_reset() } //------------------------------------------------- -// device_timer - handler timer events +// rx_timer_tick //------------------------------------------------- -void pc9801_kbd_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(pc9801_kbd_device::rx_timer_tick) { - if(id == RX_TIMER) + /* key up */ + for (int i = 0; i < 0x80; i++) { - int i; - - /* key up */ - for(i=0;i<0x80;i++) + if (m_rx_buf[i] == 2) { - if(m_rx_buf[i] == 2) - { - m_keyb_tx = i | 0x80; - m_write_irq(ASSERT_LINE); - m_key_avail = true; - m_rx_buf[i] = 0; - return; - } + m_keyb_tx = i | 0x80; + m_write_irq(ASSERT_LINE); + m_key_avail = true; + m_rx_buf[i] = 0; + return; } + } - /* key down */ - for(i=0x7f;i>=0;i--) + /* key down */ + for (int i = 0x7f; i >= 0; i--) + { + if (m_rx_buf[i] == 1) { - if(m_rx_buf[i] == 1) - { - m_keyb_tx = i; - m_write_irq(ASSERT_LINE); - m_key_avail = true; - m_rx_buf[i] = 0; - return; - } + m_keyb_tx = i; + m_write_irq(ASSERT_LINE); + m_key_avail = true; + m_rx_buf[i] = 0; + return; } } } @@ -306,7 +299,7 @@ void pc9801_kbd_device::device_timer(emu_timer &timer, device_timer_id id, int p uint8_t pc9801_kbd_device::rx_r(offs_t offset) { m_write_irq(CLEAR_LINE); - if(!offset) + if (!offset) { m_key_avail = false; return m_keyb_tx; diff --git a/src/mame/machine/pc9801_kbd.h b/src/mame/machine/pc9801_kbd.h index 80c8aaa81d2..b9c0aaa9523 100644 --- a/src/mame/machine/pc9801_kbd.h +++ b/src/mame/machine/pc9801_kbd.h @@ -37,15 +37,15 @@ protected: virtual void device_validity_check(validity_checker &valid) const 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; - devcb_write_line m_write_irq; + TIMER_CALLBACK_MEMBER(rx_timer_tick); + + devcb_write_line m_write_irq; - static const device_timer_id RX_TIMER = 1; emu_timer * m_rxtimer; - uint8_t m_rx_buf[0x80]; - uint8_t m_keyb_tx; - uint8_t m_keyb_rx; + uint8_t m_rx_buf[0x80]; + uint8_t m_keyb_tx; + uint8_t m_keyb_rx; bool m_key_avail; }; diff --git a/src/mame/machine/pce220_ser.cpp b/src/mame/machine/pce220_ser.cpp index 7854fdc8c09..b88088fcafd 100644 --- a/src/mame/machine/pce220_ser.cpp +++ b/src/mame/machine/pce220_ser.cpp @@ -64,8 +64,8 @@ pce220_serial_device::~pce220_serial_device() void pce220_serial_device::device_start() { - m_send_timer = timer_alloc(TIMER_SEND); - m_receive_timer = timer_alloc(TIMER_RECEIVE); + m_send_timer = timer_alloc(FUNC(pce220_serial_device::send_tick), this); + m_receive_timer = timer_alloc(FUNC(pce220_serial_device::receive_tick), this); m_send_timer->reset(); m_receive_timer->reset(); } @@ -85,85 +85,31 @@ void pce220_serial_device::device_reset() //------------------------------------------------- -// device_timer - handler timer events +// timer events //------------------------------------------------- -void pce220_serial_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(pce220_serial_device::send_tick) { - if (id == TIMER_SEND && m_enabled) + if (!m_enabled) { - //send data - if (m_bytes_count <= length()) - { - switch(m_state) - { - case SIO_WAIT: - m_ack = 1; //data send request - //waits until is ready to receive - if(!m_busy) - return; - break; - case SIO_SEND_START: - //send start bit - m_xin = 1; - break; - case SIO_SEND_BIT0: - case SIO_SEND_BIT1: - case SIO_SEND_BIT2: - case SIO_SEND_BIT3: - case SIO_SEND_BIT4: - case SIO_SEND_BIT5: - case SIO_SEND_BIT6: - case SIO_SEND_BIT7: - m_xin = BIT(~m_current_byte, m_state - SIO_SEND_BIT0); - break; - case SIO_SEND_PARITY: - m_xin = calc_parity(m_current_byte); - break; - case SIO_SEND_STOP1: - case SIO_SEND_STOP2: - //stop bit - m_xin = m_ack = 0; - break; - } - - if (m_state == (SIO_SEND_PARITY + SIO_STOP_BIT)) - { - //next byte - m_bytes_count++; - popmessage("Send %d/%d bytes\n", m_bytes_count , (uint32_t)length()); - m_state = SIO_WAIT; - if (m_bytes_count < length()) - fread(&m_current_byte, 1); - else - m_current_byte = SIO_EOT_BYTE; - } - else - { - m_state = get_next_state(); - } - - } - else - { - m_din = m_xin = m_ack = 0; - } + m_din = m_xin = m_ack = 0; + return; } - else if (id == TIMER_RECEIVE && m_enabled) + + //send data + if (m_bytes_count <= length()) { - //receive data switch(m_state) { case SIO_WAIT: - //wait send request - if(m_busy) + m_ack = 1; //data send request + //waits until is ready to receive + if(!m_busy) return; - m_ack = 1; //acknowledge break; case SIO_SEND_START: - //wait for the start bit - if (!m_xout) - return; + //send start bit + m_xin = 1; break; case SIO_SEND_BIT0: case SIO_SEND_BIT1: @@ -173,16 +119,15 @@ void pce220_serial_device::device_timer(emu_timer &timer, device_timer_id id, in case SIO_SEND_BIT5: case SIO_SEND_BIT6: case SIO_SEND_BIT7: - m_current_byte |= ((~m_xout)&1) << (m_state - SIO_SEND_BIT0); + m_xin = BIT(~m_current_byte, m_state - SIO_SEND_BIT0); break; case SIO_SEND_PARITY: - if (m_xout != calc_parity(m_current_byte)) - logerror("SIO %s: byte %d has wrong parity!\n", tag(), m_bytes_count); + m_xin = calc_parity(m_current_byte); break; case SIO_SEND_STOP1: case SIO_SEND_STOP2: - //receive stop bit - m_ack = 0; + //stop bit + m_xin = m_ack = 0; break; } @@ -190,16 +135,18 @@ void pce220_serial_device::device_timer(emu_timer &timer, device_timer_id id, in { //next byte m_bytes_count++; - popmessage("Received %d bytes\n", m_bytes_count); + popmessage("Send %d/%d bytes\n", m_bytes_count , (uint32_t)length()); m_state = SIO_WAIT; - if (m_current_byte != SIO_EOT_BYTE) - fwrite(&m_current_byte, 1); - m_current_byte = 0; + if (m_bytes_count < length()) + fread(&m_current_byte, 1); + else + m_current_byte = SIO_EOT_BYTE; } else { m_state = get_next_state(); } + } else { @@ -207,6 +154,65 @@ void pce220_serial_device::device_timer(emu_timer &timer, device_timer_id id, in } } +TIMER_CALLBACK_MEMBER(pce220_serial_device::receive_tick) +{ + if (!m_enabled) + { + m_din = m_xin = m_ack = 0; + return; + } + + //receive data + switch(m_state) + { + case SIO_WAIT: + //wait send request + if(m_busy) + return; + m_ack = 1; //acknowledge + break; + case SIO_SEND_START: + //wait for the start bit + if (!m_xout) + return; + break; + case SIO_SEND_BIT0: + case SIO_SEND_BIT1: + case SIO_SEND_BIT2: + case SIO_SEND_BIT3: + case SIO_SEND_BIT4: + case SIO_SEND_BIT5: + case SIO_SEND_BIT6: + case SIO_SEND_BIT7: + m_current_byte |= ((~m_xout)&1) << (m_state - SIO_SEND_BIT0); + break; + case SIO_SEND_PARITY: + if (m_xout != calc_parity(m_current_byte)) + logerror("SIO %s: byte %d has wrong parity!\n", tag(), m_bytes_count); + break; + case SIO_SEND_STOP1: + case SIO_SEND_STOP2: + //receive stop bit + m_ack = 0; + break; + } + + if (m_state == (SIO_SEND_PARITY + SIO_STOP_BIT)) + { + //next byte + m_bytes_count++; + popmessage("Received %d bytes\n", m_bytes_count); + m_state = SIO_WAIT; + if (m_current_byte != SIO_EOT_BYTE) + fwrite(&m_current_byte, 1); + m_current_byte = 0; + } + else + { + m_state = get_next_state(); + } +} + /*------------------------------------------------- DEVICE_IMAGE_LOAD( pce220_serial ) -------------------------------------------------*/ diff --git a/src/mame/machine/pce220_ser.h b/src/mame/machine/pce220_ser.h index f9e5e3c927c..9ba165cd0af 100644 --- a/src/mame/machine/pce220_ser.h +++ b/src/mame/machine/pce220_ser.h @@ -59,26 +59,25 @@ 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(send_tick); + TIMER_CALLBACK_MEMBER(receive_tick); private: // internal device state - static const device_timer_id TIMER_SEND = 0; - static const device_timer_id TIMER_RECEIVE = 1; - emu_timer* m_send_timer = nullptr; // timer for send data emu_timer* m_receive_timer = nullptr; // timer for receive data - uint8_t m_state = 0; // transfer status - uint32_t m_bytes_count = 0; // number of bytes transferred - uint8_t m_current_byte = 0; // byte in transfer - uint8_t m_enabled = 0; // enable/disable - - uint8_t m_busy = 0; // CTS - uint8_t m_dout = 0; // DTR - uint8_t m_xout = 0; // TXD - uint8_t m_xin = 0; // RXD - uint8_t m_din = 0; // DSR - uint8_t m_ack = 0; // RTS + uint8_t m_state = 0; // transfer status + uint32_t m_bytes_count = 0; // number of bytes transferred + uint8_t m_current_byte = 0; // byte in transfer + uint8_t m_enabled = 0; // enable/disable + + uint8_t m_busy = 0; // CTS + uint8_t m_dout = 0; // DTR + uint8_t m_xout = 0; // TXD + uint8_t m_xin = 0; // RXD + uint8_t m_din = 0; // DSR + uint8_t m_ack = 0; // RTS }; // device type definition diff --git a/src/mame/machine/pce_cd.cpp b/src/mame/machine/pce_cd.cpp index 8667f48fc53..5b82e4fc944 100644 --- a/src/mame/machine/pce_cd.cpp +++ b/src/mame/machine/pce_cd.cpp @@ -145,21 +145,24 @@ void pce_cd_device::device_start() m_subcode_buffer = std::make_unique<uint8_t[]>(96); - m_data_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(pce_cd_device::data_timer_callback),this)); + m_data_timer = timer_alloc(FUNC(pce_cd_device::data_timer_callback), this); m_data_timer->adjust(attotime::never); - m_adpcm_dma_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(pce_cd_device::adpcm_dma_timer_callback),this)); + m_adpcm_dma_timer = timer_alloc(FUNC(pce_cd_device::adpcm_dma_timer_callback), this); m_adpcm_dma_timer->adjust(attotime::never); - m_cdda_fadeout_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(pce_cd_device::cdda_fadeout_callback),this)); + m_cdda_fadeout_timer = timer_alloc(FUNC(pce_cd_device::cdda_fadeout_callback), this); m_cdda_fadeout_timer->adjust(attotime::never); - m_cdda_fadein_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(pce_cd_device::cdda_fadein_callback),this)); + m_cdda_fadein_timer = timer_alloc(FUNC(pce_cd_device::cdda_fadein_callback), this); m_cdda_fadein_timer->adjust(attotime::never); - m_adpcm_fadeout_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(pce_cd_device::adpcm_fadeout_callback),this)); + m_adpcm_fadeout_timer = timer_alloc(FUNC(pce_cd_device::adpcm_fadeout_callback), this); m_adpcm_fadeout_timer->adjust(attotime::never); - m_adpcm_fadein_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(pce_cd_device::adpcm_fadein_callback),this)); + m_adpcm_fadein_timer = timer_alloc(FUNC(pce_cd_device::adpcm_fadein_callback), this); m_adpcm_fadein_timer->adjust(attotime::never); + m_ack_clear_timer = timer_alloc(FUNC(pce_cd_device::clear_ack), this); + m_ack_clear_timer->adjust(attotime::never); + // m_cd_file pointer is setup at a later stage because it is still empty when this function is called // TODO: add proper restore for the cd data... @@ -1446,7 +1449,7 @@ uint8_t pce_cd_device::get_cd_data_byte() if (m_scsi_IO) { m_scsi_ACK = 1; - machine().scheduler().timer_set(m_maincpu->cycles_to_attotime(15), timer_expired_delegate(FUNC(pce_cd_device::clear_ack),this)); + m_ack_clear_timer->adjust(m_maincpu->cycles_to_attotime(15)); } } return data; diff --git a/src/mame/machine/pce_cd.h b/src/mame/machine/pce_cd.h index e9d9595349c..30882f1d099 100644 --- a/src/mame/machine/pce_cd.h +++ b/src/mame/machine/pce_cd.h @@ -205,10 +205,12 @@ private: emu_timer *m_cdda_fadeout_timer = nullptr; emu_timer *m_cdda_fadein_timer = nullptr; - double m_cdda_volume = 0; + double m_cdda_volume = 0; emu_timer *m_adpcm_fadeout_timer = nullptr; emu_timer *m_adpcm_fadein_timer = nullptr; - double m_adpcm_volume = 0; + double m_adpcm_volume = 0; + + emu_timer *m_ack_clear_timer = nullptr; DECLARE_WRITE_LINE_MEMBER(msm5205_int); void nvram_init(nvram_device &nvram, void *data, size_t size); diff --git a/src/mame/machine/playch10.cpp b/src/mame/machine/playch10.cpp index 7e625b4df08..5f26d5f1b0f 100644 --- a/src/mame/machine/playch10.cpp +++ b/src/mame/machine/playch10.cpp @@ -272,7 +272,7 @@ void playch10_state::pc10_set_mirroring(int mirroring) * 64 1 * \*****************/ -void playch10_state::pc10_set_videorom_bank( int first, int count, int bank, int size ) +void playch10_state::pc10_set_videorom_bank(int first, int count, int bank, int size) { int i, len; /* first = first bank to map */ @@ -301,7 +301,7 @@ void playch10_state::pc10_set_videorom_bank( int first, int count, int bank, int } } -void playch10_state::set_videoram_bank( int first, int count, int bank, int size ) +void playch10_state::set_videoram_bank(int first, int count, int bank, int size) { int i; /* first = first bank to map */ @@ -650,7 +650,7 @@ void playch10_state::init_pcfboard() //********************************************************************************** // G Board (MMC3) games (Super Mario Bros. 3, etc) -void playch10_state::gboard_scanline_cb( int scanline, int vblank, int blanked ) +void playch10_state::gboard_scanline_cb(int scanline, bool vblank, bool blanked) { if (scanline < ppu2c0x_device::BOTTOM_VISIBLE_SCANLINE) { diff --git a/src/mame/machine/pmd85.cpp b/src/mame/machine/pmd85.cpp index 8e3829a64c5..1d8157bda59 100644 --- a/src/mame/machine/pmd85.cpp +++ b/src/mame/machine/pmd85.cpp @@ -624,18 +624,6 @@ void pmd85_state::mato_io_w(offs_t offset, uint8_t data) } } -void pmd85_state::device_timer(emu_timer &timer, device_timer_id id, int param) -{ - switch (id) - { - case TIMER_CASSETTE: - cassette_timer_callback(param); - break; - default: - throw emu_fatalerror("Unknown id in pmd85_state::device_timer"); - } -} - TIMER_CALLBACK_MEMBER(pmd85_state::cassette_timer_callback) { bool data; @@ -708,7 +696,7 @@ void pmd85_state::common_driver_init() { m_previous_level = 0; m_clk_level = m_clk_level_tape = 1; - m_cassette_timer = timer_alloc(TIMER_CASSETTE); + m_cassette_timer = timer_alloc(FUNC(pmd85_state::cassette_timer_callback), this); m_cassette_timer->adjust(attotime::zero, 0, attotime::from_hz(2400)); } diff --git a/src/mame/machine/pocketc.cpp b/src/mame/machine/pocketc.cpp index 3530366960d..e16ee649c90 100644 --- a/src/mame/machine/pocketc.cpp +++ b/src/mame/machine/pocketc.cpp @@ -14,22 +14,15 @@ READ_LINE_MEMBER(pocketc_state::brk_r) return BIT(m_extra->read(), 0); } -void pocketc_state::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(pocketc_state::power_up_done) { - switch (id) - { - case TIMER_POWER_UP: - m_power = 0; - break; - default: - throw emu_fatalerror("Unknown id in pocketc_state::device_timer"); - } + m_power = 0; } void pocketc_state::machine_start() { m_cpu_nvram->set_base(m_maincpu->internal_ram(), 96); - m_power_timer = timer_alloc(TIMER_POWER_UP); + m_power_timer = timer_alloc(FUNC(pocketc_state::power_up_done), this); } void pocketc_state::machine_reset() diff --git a/src/mame/machine/poly.cpp b/src/mame/machine/poly.cpp index cb1bbc5379c..babd159b9ec 100644 --- a/src/mame/machine/poly.cpp +++ b/src/mame/machine/poly.cpp @@ -44,7 +44,7 @@ TIMER_CALLBACK_MEMBER(poly_state::set_protect) void poly_state::set_protect_w(uint8_t data) { /* set protect after 1 E cycle */ - machine().scheduler().timer_set(m_maincpu->cycles_to_attotime(2), timer_expired_delegate(FUNC(poly_state::set_protect), this)); + m_protect_timer->adjust(m_maincpu->cycles_to_attotime(2)); } diff --git a/src/mame/machine/psxcd.cpp b/src/mame/machine/psxcd.cpp index 503df61339c..43a4a732184 100644 --- a/src/mame/machine/psxcd.cpp +++ b/src/mame/machine/psxcd.cpp @@ -8,7 +8,7 @@ static inline void ATTR_PRINTF(3,4) verboselog( device_t& device, int n_level, const char *s_fmt, ... ) { - if( VERBOSE_LEVEL >= n_level ) + if (VERBOSE_LEVEL >= n_level) { va_list v; char buf[ 32768 ]; @@ -21,62 +21,65 @@ static inline void ATTR_PRINTF(3,4) verboselog( device_t& device, int n_level, c enum cdrom_events { - event_cmd_complete=0, - event_read_sector, - event_play_sector, - event_change_disk + EVENT_CMD_COMPLETE, + EVENT_READ_SECTOR, + EVENT_PLAY_SECTOR, + EVENT_CHANGE_DISK }; enum intr_status { - intr_nointr=0, - intr_dataready, - intr_acknowledge, - intr_complete, - intr_dataend, - intr_diskerror + INTR_NOINTR, + INTR_DATAREADY, + INTR_ACKNOWLEDGE, + INTR_COMPLETE, + INTR_DATAEND, + INTR_DISKERROR }; enum mode_flags { - mode_double_speed=0x80, - mode_adpcm=0x40, - mode_size=0x20, - mode_size2=0x10, - mode_size_mask=0x30, - mode_channel=0x08, - mode_report=0x04, - mode_autopause=0x02, - mode_cdda=0x01 + MODE_DOUBLE_SPEED = 0x80, + MODE_ADPCM = 0x40, + MODE_SIZE = 0x20, + MODE_SIZE2 = 0x10, + MODE_SIZE_MASK = 0x30, + MODE_CHANNEL = 0x08, + MODE_REPORT = 0x04, + MODE_AUTOPAUSE = 0x02, + MODE_CDDA = 0x01 }; enum status_f { - status_playing=0x80, - status_seeking=0x40, - status_reading=0x20, - status_shellopen=0x10, - status_invalid=0x08, - status_seekerror=0x04, - status_standby=0x02, - status_error=0x01 + STATUS_PLAYING = 0x80, + STATUS_SEEKING = 0x40, + STATUS_READING = 0x20, + STATUS_SHELLOPEN = 0x10, + STATUS_INVALID = 0x08, + STATUS_SEEKERROR = 0x04, + STATUS_STANDBY = 0x02, + STATUS_ERROR = 0x01 }; struct subheader { - uint8_t file, channel, submode, coding; + uint8_t file; + uint8_t channel; + uint8_t submode; + uint8_t coding; }; enum submode_flags { - submode_eof=0x80, - submode_realtime=0x40, - submode_form=0x20, - submode_trigger=0x10, - submode_data=0x08, - submode_audio=0x04, - submode_video=0x02, - submode_eor=0x01 + SUBMODE_EOF = 0x80, + SUBMODE_REALTIME = 0x40, + SUBMODE_FORM = 0x20, + SUBMODE_TRIGGER = 0x10, + SUBMODE_DATA = 0x08, + SUBMODE_AUDIO = 0x04, + SUBMODE_VIDEO = 0x02, + SUBMODE_EOR = 0x01 }; //************************************************************************** @@ -100,21 +103,21 @@ void psxcd_device::device_start() cdrom_image_device::device_start(); m_irq_handler.resolve_safe(); - unsigned int sysclk=m_maincpu->clock()/2; - start_read_delay=(sysclk/60); - read_sector_cycles=(sysclk/75); - preread_delay=(read_sector_cycles>>2)-500; + uint32_t sysclk = m_maincpu->clock() / 2; + start_read_delay = (sysclk / 60); + read_sector_cycles = (sysclk / 75); + preread_delay = (read_sector_cycles >> 2) - 500; m_sysclock = sysclk; res_queue = nullptr; rdp = 0; - status=status_shellopen; - mode=0; + status = STATUS_SHELLOPEN; + mode = 0; for (int i = 0; i < MAX_PSXCD_TIMERS; i++) { - m_timers[i] = timer_alloc(i); + m_timers[i] = timer_alloc(FUNC(psxcd_device::handle_event), this); m_timerinuse[i] = false; m_results[i] = nullptr; } @@ -146,10 +149,10 @@ void psxcd_device::device_stop() { for (int i = 0; i < MAX_PSXCD_TIMERS; i++) { - if(m_timerinuse[i] && m_results[i]) + if (m_timerinuse[i] && m_results[i]) delete m_results[i]; } - while(res_queue) + while (res_queue) { command_result *res = res_queue->next; delete res_queue; @@ -164,16 +167,16 @@ void psxcd_device::device_reset() for (int i = 0; i < MAX_PSXCD_TIMERS; i++) { - if(m_timerinuse[i] && m_results[i]) + if (m_timerinuse[i] && m_results[i]) delete m_results[i]; - m_timers[i]->adjust(attotime::never, 0, attotime::never); + m_timers[i]->adjust(attotime::never); m_timerinuse[i] = false; } open = true; - if(m_cdrom_handle) - add_system_event(event_change_disk, m_sysclock, nullptr); + if (m_cdrom_handle) + add_system_event(EVENT_CHANGE_DISK, m_sysclock, nullptr); - while(res_queue) + while (res_queue) { command_result *res = res_queue->next; delete res_queue; @@ -196,8 +199,8 @@ image_init_result psxcd_device::call_load() { image_init_result ret = cdrom_image_device::call_load(); open = true; - if(ret == image_init_result::PASS) - add_system_event(event_change_disk, m_sysclock, nullptr); // 1 sec to spin up the disk + if (ret == image_init_result::PASS) + add_system_event(EVENT_CHANGE_DISK, m_sysclock, nullptr); // 1 sec to spin up the disk return ret; } @@ -206,8 +209,8 @@ void psxcd_device::call_unload() stop_read(); cdrom_image_device::call_unload(); open = true; - status = status_shellopen; - send_result(intr_diskerror); + status = STATUS_SHELLOPEN; + send_result(INTR_DISKERROR); } uint8_t psxcd_device::read(offs_t offset) @@ -231,7 +234,7 @@ uint8_t psxcd_device::read(offs_t offset) if ((res_queue) && (rdp < res_queue->sz)) { ret = res_queue->data[rdp++]; - if(rdp == res_queue->sz) + if (rdp == res_queue->sz) m_regs.sr &= ~0x20; else m_regs.sr |= 0x20; @@ -241,12 +244,12 @@ uint8_t psxcd_device::read(offs_t offset) break; case 2: - if(!m_dmaload) + if (!m_dmaload) ret = 0; else { ret = m_transbuf[m_transcurr++]; - if(m_transcurr >= raw_sector_size) + if (m_transcurr >= raw_sector_size) { m_dmaload = false; m_regs.sr &= ~0x40; @@ -255,7 +258,7 @@ uint8_t psxcd_device::read(offs_t offset) break; case 3: - if(m_regs.sr & 1) + if (m_regs.sr & 1) ret = m_regs.ir | 0xe0; else ret = m_regs.imr | 0xe0; @@ -316,7 +319,7 @@ void psxcd_device::write(offs_t offset, uint8_t data) ---- -xxx Response received */ case 0x03: - if((data & 0x80) && !m_dmaload) + if ((data & 0x80) && !m_dmaload) { m_dmaload = true; memcpy(m_transbuf, secbuf[m_cursec], raw_sector_size); @@ -325,7 +328,7 @@ void psxcd_device::write(offs_t offset, uint8_t data) m_cursec++; m_cursec %= sector_buffer_size; - switch(mode & mode_size_mask) + switch (mode & MODE_SIZE_MASK) { case 0x00: default: @@ -345,7 +348,7 @@ void psxcd_device::write(offs_t offset, uint8_t data) verboselog(*this, 1, "psxcd: request data=%s\n",str); #endif } - else if(!(data & 0x80)) + else if (!(data & 0x80)) { m_dmaload = false; m_regs.sr &= ~0x40; @@ -353,21 +356,21 @@ void psxcd_device::write(offs_t offset, uint8_t data) break; case 0x13: - if(data & 0x1f) + if (data & 0x1f) { m_regs.ir &= ~(data & 0x1f); - if(res_queue && !m_regs.ir) + if (res_queue && !m_regs.ir) { command_result *res = res_queue; - if(res == m_int1) + if (res == m_int1) m_int1 = nullptr; res_queue = res->next; delete res; m_regs.sr &= ~0x20; rdp = 0; - if(res_queue) + if (res_queue) { m_regs.sr |= 0x20; m_regs.ir = res_queue->res; @@ -375,7 +378,7 @@ void psxcd_device::write(offs_t offset, uint8_t data) verboselog(*this, 1, "psxcd: nextres\n"); } } - if(data & 0x40) + if (data & 0x40) m_param_count = 0; break; @@ -425,7 +428,7 @@ const psxcd_device::cdcmd psxcd_device::cmd_table[]= void psxcd_device::write_command(uint8_t byte) { - if(byte > 30) // coverity 140157 + if (byte > 30) // coverity 140157 illegalcmd(byte); else (this->*cmd_table[byte])(); @@ -437,7 +440,7 @@ void psxcd_device::cdcmd_sync() verboselog(*this, 1, "psxcd: sync\n"); stop_read(); - send_result(intr_acknowledge); + send_result(INTR_ACKNOWLEDGE); } void psxcd_device::cdcmd_nop() @@ -445,9 +448,9 @@ void psxcd_device::cdcmd_nop() verboselog(*this, 1, "psxcd: nop\n"); if (!open) - status &= ~status_shellopen; + status &= ~STATUS_SHELLOPEN; - send_result(intr_complete); + send_result(INTR_COMPLETE); } void psxcd_device::cdcmd_setloc() @@ -467,12 +470,12 @@ void psxcd_device::cdcmd_setloc() else verboselog(*this, 0, "psxcd: setloc out of range: %02d:%02d:%02d\n",l.b[M],l.b[S],l.b[F]); - send_result(intr_complete); + send_result(INTR_COMPLETE); } void psxcd_device::cdcmd_play() { - if(cmdbuf[0] && m_param_count) + if (cmdbuf[0] && m_param_count) loc.w = lba_to_msf_ps(m_cdrom_handle->get_track_start(bcd_to_decimal(cmdbuf[0]) - 1)); curpos.w = loc.w; @@ -483,7 +486,7 @@ void psxcd_device::cdcmd_play() stop_read(); start_play(); - send_result(intr_complete); + send_result(INTR_COMPLETE); } void psxcd_device::cdcmd_forward() @@ -498,7 +501,7 @@ void psxcd_device::cdcmd_backward() void psxcd_device::cdcmd_readn() { - if(!open) + if (!open) { verboselog(*this, 1, "psxcd: readn\n"); @@ -506,9 +509,10 @@ void psxcd_device::cdcmd_readn() stop_read(); start_read(); - } else + } + else { - send_result(intr_diskerror, nullptr, 0, 0x80); + send_result(INTR_DISKERROR, nullptr, 0, 0x80); } } @@ -517,7 +521,7 @@ void psxcd_device::cdcmd_standby() verboselog(*this, 1, "psxcd: standby\n"); stop_read(); - send_result(intr_acknowledge); + send_result(INTR_ACKNOWLEDGE); } void psxcd_device::cdcmd_stop() @@ -525,7 +529,7 @@ void psxcd_device::cdcmd_stop() verboselog(*this, 1, "psxcd: stop\n"); stop_read(); - send_result(intr_acknowledge); + send_result(INTR_ACKNOWLEDGE); } void psxcd_device::cdcmd_pause() @@ -534,7 +538,7 @@ void psxcd_device::cdcmd_pause() stop_read(); - send_result(intr_acknowledge); + send_result(INTR_ACKNOWLEDGE); } void psxcd_device::cdcmd_init() @@ -545,7 +549,7 @@ void psxcd_device::cdcmd_init() mode=0; m_regs.sr |= 0x10; - send_result(intr_acknowledge); + send_result(INTR_ACKNOWLEDGE); } void psxcd_device::cdcmd_mute() @@ -553,7 +557,7 @@ void psxcd_device::cdcmd_mute() verboselog(*this, 1, "psxcd: mute\n"); m_mute = true; - send_result(intr_complete); + send_result(INTR_COMPLETE); } void psxcd_device::cdcmd_demute() @@ -561,7 +565,7 @@ void psxcd_device::cdcmd_demute() verboselog(*this, 1, "psxcd: demute\n"); m_mute = false; - send_result(intr_complete); + send_result(INTR_COMPLETE); } void psxcd_device::cdcmd_setfilter() @@ -571,7 +575,7 @@ void psxcd_device::cdcmd_setfilter() filter_file=cmdbuf[0]; filter_channel=cmdbuf[1]; - send_result(intr_acknowledge); + send_result(INTR_ACKNOWLEDGE); } void psxcd_device::cdcmd_setmode() @@ -579,7 +583,7 @@ void psxcd_device::cdcmd_setmode() verboselog(*this, 1, "psxcd: setmode %08x\n",cmdbuf[0]); mode=cmdbuf[0]; - send_result(intr_complete); + send_result(INTR_COMPLETE); } void psxcd_device::cdcmd_getparam() @@ -597,7 +601,7 @@ void psxcd_device::cdcmd_getparam() verboselog(*this, 1, "psxcd: getparam [%02x %02x %02x %02x %02x %02x]\n", data[0], data[1], data[2], data[3], data[4], data[5]); - send_result(intr_complete,data,6); + send_result(INTR_COMPLETE, data, 6); } uint32_t psxcd_device::sub_loc(CDPOS src1, CDPOS src2) @@ -625,7 +629,7 @@ void psxcd_device::cdcmd_getlocl() lastsechdr[0], lastsechdr[1], lastsechdr[2], lastsechdr[3], lastsechdr[4], lastsechdr[5], lastsechdr[6], lastsechdr[7]); - send_result(intr_complete,lastsechdr,8); + send_result(INTR_COMPLETE, lastsechdr, 8); } void psxcd_device::cdcmd_getlocp() @@ -635,7 +639,7 @@ void psxcd_device::cdcmd_getlocp() start.w = (track == 1) ? 0x000200 : lba_to_msf_ps(m_cdrom_handle->get_track_start(track - 1)); tloc.w = sub_loc(loc, start); - unsigned char data[8]= + unsigned char data[8] = { decimal_to_bcd(track), // track 0x01, // index @@ -650,7 +654,7 @@ void psxcd_device::cdcmd_getlocp() verboselog(*this, 1, "psxcd: getlocp [%02x %02x %02x %02x %02x %02x %02x %02x]\n", data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7]); - send_result(intr_complete,data,8); + send_result(INTR_COMPLETE, data, 8); } void psxcd_device::cdcmd_gettn() @@ -658,20 +662,20 @@ void psxcd_device::cdcmd_gettn() verboselog(*this, 1, "psxcd: gettn\n"); - if(!open) + if (!open) { - unsigned char data[3]= + unsigned char data[3] = { status, decimal_to_bcd(1), decimal_to_bcd(m_cdrom_handle->get_last_track()) }; - send_result(intr_complete,data,3); + send_result(INTR_COMPLETE, data, 3); } else { - send_result(intr_diskerror, nullptr, 0, 0x80); + send_result(INTR_DISKERROR, nullptr, 0, 0x80); } } @@ -679,15 +683,15 @@ void psxcd_device::cdcmd_gettd() { uint8_t track = bcd_to_decimal(cmdbuf[0]); uint8_t last = m_cdrom_handle->get_last_track(); - if(track <= last) + if (track <= last) { CDPOS trkstart; - if(!track) // length of disk + if (!track) // length of disk trkstart.w = lba_to_msf_ps(m_cdrom_handle->get_track_start(0xaa)); else trkstart.w = lba_to_msf_ps(m_cdrom_handle->get_track_start(track - 1)); - unsigned char data[3]= + unsigned char data[3] = { status, decimal_to_bcd(trkstart.b[M]), @@ -696,11 +700,11 @@ void psxcd_device::cdcmd_gettd() verboselog(*this, 1, "psxcd: gettd %02x [%02x %02x %02x]\n", cmdbuf[0], data[0], data[1], data[2]); - send_result(intr_acknowledge,data,3); + send_result(INTR_ACKNOWLEDGE, data, 3); } else { - send_result(intr_diskerror, nullptr, 0, 0x80); + send_result(INTR_DISKERROR, nullptr, 0, 0x80); } } @@ -708,29 +712,29 @@ void psxcd_device::cdcmd_seekl() { verboselog(*this, 1, "psxcd: seekl [%02d:%02d:%02d]\n", loc.b[M], loc.b[S], loc.b[F]); - curpos.w=loc.w; + curpos.w = loc.w; - send_result(intr_acknowledge); + send_result(INTR_ACKNOWLEDGE); } void psxcd_device::cdcmd_seekp() { verboselog(*this, 1, "psxcd: seekp\n"); - curpos.w=loc.w; + curpos.w = loc.w; - send_result(intr_acknowledge); + send_result(INTR_ACKNOWLEDGE); } void psxcd_device::cdcmd_test() { verboselog(*this, 1, "psxcd: test %02x\n", cmdbuf[0]); - switch(cmdbuf[0]) + switch (cmdbuf[0]) { case 0x20: { - static uint8_t data[4]= + static uint8_t data[4] = { 0x95, 0x07, @@ -738,13 +742,13 @@ void psxcd_device::cdcmd_test() 0xff }; - send_result(intr_complete,data,4); + send_result(INTR_COMPLETE, data, 4); break; } default: verboselog(*this, 0, "psxcd: unimplemented test cmd %02x\n", cmdbuf[0]); - cmd_complete(prepare_result(intr_diskerror, nullptr, 0, 0x10)); + cmd_complete(prepare_result(INTR_DISKERROR, nullptr, 0, 0x10)); break; } } @@ -759,33 +763,33 @@ void psxcd_device::cdcmd_id() int irq; memset(cdid, '\0', 8); - send_result(intr_complete); - if(m_cdrom_handle->get_track_type(0) == cdrom_file::CD_TRACK_AUDIO) + send_result(INTR_COMPLETE); + if (m_cdrom_handle->get_track_type(0) == cdrom_file::CD_TRACK_AUDIO) { - irq = intr_diskerror; - cdid[0] = status | status_invalid; + irq = INTR_DISKERROR; + cdid[0] = status | STATUS_INVALID; cdid[1] = 0x90; } else { - irq = intr_acknowledge; + irq = INTR_ACKNOWLEDGE; cdid[0] = status; cdid[4] = 'S'; cdid[5] = 'C'; cdid[6] = 'E'; cdid[7] = 'A'; } - send_result(irq,cdid,8,default_irq_delay*3); + send_result(irq, cdid, 8, default_irq_delay * 3); } else { - send_result(intr_diskerror, nullptr, 0, 0x80); + send_result(INTR_DISKERROR, nullptr, 0, 0x80); } } void psxcd_device::cdcmd_reads() { - if(!open) + if (!open) { verboselog(*this, 1, "psxcd: reads\n"); @@ -793,9 +797,10 @@ void psxcd_device::cdcmd_reads() stop_read(); start_read(); - } else + } + else { - send_result(intr_diskerror, nullptr, 0, 0x80); + send_result(INTR_DISKERROR, nullptr, 0, 0x80); } } @@ -808,18 +813,18 @@ void psxcd_device::cdcmd_readtoc() { verboselog(*this, 1, "psxcd: readtoc\n"); - send_result(intr_complete); - send_result(intr_acknowledge, nullptr, 0, default_irq_delay*3); // ? + send_result(INTR_COMPLETE); + send_result(INTR_ACKNOWLEDGE, nullptr, 0, default_irq_delay * 3); // ? } void psxcd_device::cdcmd_unknown12() { verboselog(*this, 1, "psxcd: unknown 12\n"); // set session? readt? - if(cmdbuf[0] == 1) - send_result(intr_complete); + if (cmdbuf[0] == 1) + send_result(INTR_COMPLETE); else - send_result(intr_diskerror, nullptr, 0, 0x40); + send_result(INTR_DISKERROR, nullptr, 0, 0x40); } void psxcd_device::cdcmd_illegal17() @@ -841,7 +846,7 @@ void psxcd_device::illegalcmd(uint8_t cmd) { verboselog(*this, 0, "psxcd: unimplemented cd command %02x\n", cmd); - send_result(intr_diskerror, nullptr, 0, 0x40); + send_result(INTR_DISKERROR, nullptr, 0, 0x40); } void psxcd_device::cmd_complete(command_result *res) @@ -859,7 +864,7 @@ void psxcd_device::cmd_complete(command_result *res) { res_queue = res; m_regs.ir = res_queue->res; - if(m_regs.ir & m_regs.imr) + if (m_regs.ir & m_regs.imr) m_irq_handler(1); m_regs.sr |= 0x20; } @@ -868,19 +873,20 @@ void psxcd_device::cmd_complete(command_result *res) psxcd_device::command_result *psxcd_device::prepare_result(uint8_t res, uint8_t *data, int sz, uint8_t errcode) { - auto cr=new command_result; + auto cr = new command_result; - cr->res=res; + cr->res = res; if (sz) { assert(sz<sizeof(cr->data)); - memcpy(cr->data,data,sz); - cr->sz=sz; - } else + memcpy(cr->data, data, sz); + cr->sz = sz; + } + else { - if((res == intr_diskerror) && errcode) + if ((res == INTR_DISKERROR) && errcode) { - cr->data[0] = status | status_error; + cr->data[0] = status | STATUS_ERROR; cr->data[1] = errcode; cr->sz = 2; } @@ -890,7 +896,7 @@ psxcd_device::command_result *psxcd_device::prepare_result(uint8_t res, uint8_t cr->sz=1; } } - status &= ~status_error; + status &= ~STATUS_ERROR; return cr; } @@ -901,13 +907,20 @@ void psxcd_device::send_result(uint8_t res, uint8_t *data, int sz, int delay, ui // delay the sector read slightly if necessary uint64_t systime = m_maincpu->total_cycles(); - if ((next_read_event != -1) && ((systime+delay)>(next_sector_t))) + if ((next_read_event != -1) && ((systime + delay)>(next_sector_t))) { uint32_t hz = m_sysclock / (delay + 2000); - m_timers[next_read_event]->adjust(attotime::from_hz(hz), 0, attotime::never); + if (status & STATUS_PLAYING) + { + m_timers[next_read_event]->adjust(attotime::from_hz(hz), (next_read_event << 2) | EVENT_PLAY_SECTOR); + } + else if (status & STATUS_READING) + { + m_timers[next_read_event]->adjust(attotime::from_hz(hz), (next_read_event << 2) | EVENT_READ_SECTOR); + } } - add_system_event(event_cmd_complete, delay, prepare_result(res, data, sz, errcode)); + add_system_event(EVENT_CMD_COMPLETE, delay, prepare_result(res, data, sz, errcode)); } void psxcd_device::start_dma(uint8_t *mainram, uint32_t size) @@ -915,10 +928,10 @@ void psxcd_device::start_dma(uint8_t *mainram, uint32_t size) uint32_t sector_size; verboselog(*this, 1, "psxcd: start dma %d bytes at %d\n", size, m_transcurr); - if(!m_dmaload) + if (!m_dmaload) return; - switch(mode & mode_size_mask) + switch (mode & MODE_SIZE_MASK) { case 0x00: default: @@ -932,13 +945,13 @@ void psxcd_device::start_dma(uint8_t *mainram, uint32_t size) break; } - if(size > (sector_size - m_transcurr)) + if (size > (sector_size - m_transcurr)) size = (sector_size - m_transcurr); memcpy(mainram, &m_transbuf[m_transcurr], size); m_transcurr += size; - if(sector_size <= m_transcurr) + if (sector_size <= m_transcurr) { m_dmaload = false; m_regs.sr &= ~0x40; @@ -949,49 +962,48 @@ void psxcd_device::read_sector() { next_read_event=-1; - if (status & status_reading) + if (status & STATUS_READING) { bool isend = false; uint32_t sector = msf_to_lba_ps(curpos.w); uint8_t *buf = secbuf[sectail]; if (m_cdrom_handle->read_data(sector, buf, cdrom_file::CD_TRACK_RAW_DONTCARE)) { - subheader *sub=(subheader *)(buf+16); - memcpy(lastsechdr, buf+12, 8); + subheader *sub = (subheader *)(buf + 16); + memcpy(lastsechdr, buf + 12, 8); verboselog(*this, 2, "psxcd: subheader file=%02x chan=%02x submode=%02x coding=%02x [%02x%02x%02x%02x]\n", sub->file, sub->channel, sub->submode, sub->coding, buf[0xc], buf[0xd], buf[0xe], buf[0xf]); - if ((mode & mode_adpcm) && (sub->submode & submode_audio)) + if ((mode & MODE_ADPCM) && (sub->submode & SUBMODE_AUDIO)) { - if ((sub->submode & submode_eof) && (mode & mode_autopause)) + if ((sub->submode & SUBMODE_EOF) && (mode & MODE_AUTOPAUSE)) { isend=true; //printf("end of file\n"); } - if((!(mode & mode_channel) || - ((sub->file == filter_file) && (sub->channel == filter_channel))) && !m_mute) - m_spu->play_xa(0,buf+16); + if ((!(mode & MODE_CHANNEL) || ((sub->file == filter_file) && (sub->channel == filter_channel))) && !m_mute) + m_spu->play_xa(0, buf + 16); } else { - if(!m_int1) + if (!m_int1) m_cursec = sectail; - m_int1 = prepare_result(intr_dataready); + m_int1 = prepare_result(INTR_DATAREADY); cmd_complete(m_int1); sectail++; sectail %= sector_buffer_size; } curpos.b[F]++; - if (curpos.b[F]==75) + if (curpos.b[F] == 75) { - curpos.b[F]=0; + curpos.b[F] = 0; curpos.b[S]++; - if (curpos.b[S]==60) + if (curpos.b[S] == 60) { - curpos.b[S]=0; + curpos.b[S] = 0; curpos.b[M]++; } } @@ -1001,19 +1013,21 @@ void psxcd_device::read_sector() else isend = true; - if (! isend) + if (!isend) { - unsigned int cyc=read_sector_cycles; - if (mode&mode_double_speed) cyc>>=1; + uint32_t cyc = read_sector_cycles; + if (mode & MODE_DOUBLE_SPEED) + cyc >>= 1; - next_sector_t+=cyc; + next_sector_t += cyc; - next_read_event = add_system_event(event_read_sector, cyc, nullptr); - } else + next_read_event = add_system_event(EVENT_READ_SECTOR, cyc, nullptr); + } + else { verboselog(*this, 1, "psxcd: autopause xa\n"); - cmd_complete(prepare_result(intr_dataend)); + cmd_complete(prepare_result(INTR_DATAEND)); stop_read(); } } @@ -1021,23 +1035,23 @@ void psxcd_device::read_sector() void psxcd_device::play_sector() { - next_read_event=-1; + next_read_event = -1; - if (status&status_playing) + if (status & STATUS_PLAYING) { uint32_t sector = msf_to_lba_ps(curpos.w); - if(m_cdrom_handle->read_data(sector, secbuf[sectail], cdrom_file::CD_TRACK_AUDIO)) + if (m_cdrom_handle->read_data(sector, secbuf[sectail], cdrom_file::CD_TRACK_AUDIO)) { - if(!m_mute) + if (!m_mute) m_spu->play_cdda(0, secbuf[sectail]); } else { - if(!m_cdrom_handle->read_data(sector, secbuf[sectail], cdrom_file::CD_TRACK_RAW_DONTCARE)) + if (!m_cdrom_handle->read_data(sector, secbuf[sectail], cdrom_file::CD_TRACK_RAW_DONTCARE)) { stop_read(); // assume we've reached the end - cmd_complete(prepare_result(intr_dataend)); + cmd_complete(prepare_result(INTR_DATAEND)); return; } } @@ -1054,33 +1068,33 @@ void psxcd_device::play_sector() } } - loc.w=curpos.w; + loc.w = curpos.w; sector++; sectail++; sectail %= sector_buffer_size; - if (mode&mode_autopause) + if (mode & MODE_AUTOPAUSE) { - if (sector>=autopause_sector) + if (sector >= autopause_sector) { verboselog(*this, 1, "psxcd: autopause cdda\n"); stop_read(); - cmd_complete(prepare_result(intr_dataend)); + cmd_complete(prepare_result(INTR_DATAEND)); return; } } - if ((mode&mode_report) && !(sector & 15)) // slow the int rate + if ((mode & MODE_REPORT) && !(sector & 15)) // slow the int rate { - auto res=new command_result; + auto res = new command_result; uint8_t track = m_cdrom_handle->get_track(sector) + 1; - res->res=intr_dataready; + res->res = INTR_DATAREADY; res->data[0]=status; res->data[1]=decimal_to_bcd(track); res->data[2]=1; - if(sector & 0x10) + if (sector & 0x10) { CDPOS tloc, start; start.w = (track == 1) ? 0x000200 : lba_to_msf_ps(m_cdrom_handle->get_track_start(track - 1)); @@ -1101,11 +1115,11 @@ void psxcd_device::play_sector() cmd_complete(res); } - unsigned int cyc=read_sector_cycles; + uint32_t cyc = read_sector_cycles; - next_sector_t+=cyc>>1; + next_sector_t += cyc >> 1; - next_read_event = add_system_event(event_play_sector, next_sector_t - m_maincpu->total_cycles(), nullptr); + next_read_event = add_system_event(EVENT_PLAY_SECTOR, next_sector_t - m_maincpu->total_cycles(), nullptr); } } @@ -1113,78 +1127,80 @@ void psxcd_device::start_read() { uint32_t sector = msf_to_lba_ps(curpos.w); - assert((status&(status_reading|status_playing))==0); + assert((status & (STATUS_READING | STATUS_PLAYING)) == 0); - if(!(mode & mode_cdda) && (m_cdrom_handle->get_track_type(m_cdrom_handle->get_track(sector + 150)) == cdrom_file::CD_TRACK_AUDIO)) + if (!(mode & MODE_CDDA) && (m_cdrom_handle->get_track_type(m_cdrom_handle->get_track(sector + 150)) == cdrom_file::CD_TRACK_AUDIO)) { stop_read(); - cmd_complete(prepare_result(intr_diskerror, nullptr, 0, 0x40)); + cmd_complete(prepare_result(INTR_DISKERROR, nullptr, 0, 0x40)); return; } - send_result(intr_complete); - status |= status_reading; + send_result(INTR_COMPLETE); + status |= STATUS_READING; m_cursec=sectail=0; - unsigned int cyc=read_sector_cycles; - if (mode&mode_double_speed) cyc>>=1; + uint32_t cyc = read_sector_cycles; + if (mode & MODE_DOUBLE_SPEED) + cyc >>= 1; - int64_t systime=m_maincpu->total_cycles(); + int64_t systime = m_maincpu->total_cycles(); - systime+=start_read_delay; + systime += start_read_delay; - next_sector_t=systime+cyc; - next_read_event = add_system_event(event_read_sector, start_read_delay+preread_delay, nullptr); + next_sector_t = systime + cyc; + next_read_event = add_system_event(EVENT_READ_SECTOR, start_read_delay + preread_delay, nullptr); } void psxcd_device::start_play() { uint8_t track = m_cdrom_handle->get_track(msf_to_lba_ps(curpos.w) + 150); - if(m_cdrom_handle->get_track_type(track) != cdrom_file::CD_TRACK_AUDIO) + if (m_cdrom_handle->get_track_type(track) != cdrom_file::CD_TRACK_AUDIO) verboselog(*this, 0, "psxcd: playing data track\n"); - status|=status_playing; + status |= STATUS_PLAYING; - m_cursec=sectail=0; + m_cursec = sectail = 0; - if (mode&mode_autopause) + if (mode & MODE_AUTOPAUSE) { const auto &toc = m_cdrom_handle->get_toc(); autopause_sector = m_cdrom_handle->get_track_start(track) + toc.tracks[track].logframes; // printf("pos=%d auto=%d\n",pos,autopause_sector); } - unsigned int cyc=read_sector_cycles; + uint32_t cyc = read_sector_cycles; - next_sector_t=m_maincpu->total_cycles()+cyc; + next_sector_t = m_maincpu->total_cycles() + cyc; - next_sector_t+=cyc>>1; + next_sector_t += cyc >> 1; - next_read_event = add_system_event(event_play_sector, next_sector_t - m_maincpu->total_cycles(), nullptr); + next_read_event = add_system_event(EVENT_PLAY_SECTOR, next_sector_t - m_maincpu->total_cycles(), nullptr); } void psxcd_device::stop_read() { - if (status & (status_reading|status_playing)) + if (status & (STATUS_READING | STATUS_PLAYING)) verboselog(*this, 1, "psxcd: stop read\n"); - status&=~(status_reading|status_playing); + status &= ~(STATUS_READING | STATUS_PLAYING); if (next_read_event != -1) { - m_timers[next_read_event]->adjust(attotime::never, 0, attotime::never); + m_timers[next_read_event]->adjust(attotime::never); m_timerinuse[next_read_event] = false; next_read_event = -1; } - uint32_t sector=msf_to_lba_ps(curpos.w); + uint32_t sector = msf_to_lba_ps(curpos.w); m_spu->flush_xa(sector); m_spu->flush_cdda(sector); } -void psxcd_device::device_timer(emu_timer &timer, device_timer_id tid, int param) +TIMER_CALLBACK_MEMBER(psxcd_device::handle_event) { + int tid = param >> 2; if (!m_timerinuse[tid]) { verboselog(*this, 0, "psxcd: timer fired for free event\n"); @@ -1192,27 +1208,24 @@ void psxcd_device::device_timer(emu_timer &timer, device_timer_id tid, int param } m_timerinuse[tid] = false; - switch (param) + switch (param & 3) { - case event_cmd_complete: - { + case EVENT_CMD_COMPLETE: verboselog(*this, 1, "psxcd: event cmd complete\n"); - cmd_complete(m_results[tid]); break; - } - case event_read_sector: + case EVENT_READ_SECTOR: read_sector(); break; - case event_play_sector: + case EVENT_PLAY_SECTOR: play_sector(); break; - case event_change_disk: + case EVENT_CHANGE_DISK: open = false; - status |= status_standby; + status |= STATUS_STANDBY; break; } } @@ -1221,11 +1234,11 @@ int psxcd_device::add_system_event(int type, uint64_t t, command_result *ptr) { // t is in maincpu clock cycles uint32_t hz = m_sysclock / t; - for(int i = 0; i < MAX_PSXCD_TIMERS; i++) + for (int i = 0; i < MAX_PSXCD_TIMERS; i++) { - if(!m_timerinuse[i]) + if (!m_timerinuse[i]) { - m_timers[i]->adjust(attotime::from_hz(hz), type, attotime::never); + m_timers[i]->adjust(attotime::from_hz(hz), (i << 2) | type, attotime::never); m_results[i] = ptr; m_timerinuse[i] = true; return i; diff --git a/src/mame/machine/psxcd.h b/src/mame/machine/psxcd.h index 79b9e493efe..9bfd55f3489 100644 --- a/src/mame/machine/psxcd.h +++ b/src/mame/machine/psxcd.h @@ -35,9 +35,10 @@ 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 const tiny_rom_entry *device_rom_region() const override; + TIMER_CALLBACK_MEMBER(handle_event); + private: static constexpr unsigned MAX_PSXCD_TIMERS = 4; @@ -106,25 +107,38 @@ private: uint32_t msf_to_lba_ps(uint32_t msf) { msf = cdrom_file::msf_to_lba(msf); return (msf>150)?(msf-150):msf; } uint32_t lba_to_msf_ps(uint32_t lba) { return cdrom_file::lba_to_msf_alt(lba+150); } - static const unsigned int sector_buffer_size=16, default_irq_delay=16000; //480; //8000; //2000<<2; - static const unsigned int raw_sector_size=2352; - - uint8_t cmdbuf[64]{}, mode = 0, secbuf[sector_buffer_size][raw_sector_size]{}; - uint8_t filter_file = 0, filter_channel = 0, lastsechdr[8]{}, status = 0; + static const uint32_t sector_buffer_size = 16; + static const uint32_t default_irq_delay = 16000; + static const uint32_t raw_sector_size = 2352; + + uint8_t cmdbuf[64]{}; + uint8_t mode = 0; + uint8_t secbuf[sector_buffer_size][raw_sector_size]{}; + uint8_t filter_file = 0; + uint8_t filter_channel = 0; + uint8_t lastsechdr[8]{}; + uint8_t status = 0; int rdp = 0; uint8_t m_cursec = 0, sectail = 0; uint16_t m_transcurr = 0; uint8_t m_transbuf[raw_sector_size]{}; - command_result *res_queue = nullptr, *m_int1 = nullptr; + command_result *res_queue = nullptr; + command_result *m_int1 = nullptr; struct { - uint8_t sr = 0, ir = 0, imr = 0; + uint8_t sr = 0; + uint8_t ir = 0; + uint8_t imr = 0; struct { - uint8_t ll = 0, lr = 0, rl = 0, rr = 0; + uint8_t ll = 0; + uint8_t lr = 0; + uint8_t rl = 0; + uint8_t rr = 0; } vol; } m_regs; - CDPOS loc, curpos; + CDPOS loc; + CDPOS curpos; #ifdef LSB_FIRST enum { @@ -140,10 +154,15 @@ private: }; #endif - bool open = false, m_mute = false, m_dmaload = false; - device_timer_id next_read_event{}; + bool open = false; + bool m_mute = false; + bool m_dmaload = false; + int next_read_event{}; int64_t next_sector_t = 0; - unsigned int autopause_sector = 0, start_read_delay = 0, read_sector_cycles = 0, preread_delay = 0; + uint32_t autopause_sector = 0; + uint32_t start_read_delay = 0; + uint32_t read_sector_cycles = 0; + uint32_t preread_delay = 0; uint32_t m_param_count = 0; uint32_t m_sysclock = 0; diff --git a/src/mame/machine/qx10kbd.cpp b/src/mame/machine/qx10kbd.cpp index a3ffff7c637..64105686b9e 100644 --- a/src/mame/machine/qx10kbd.cpp +++ b/src/mame/machine/qx10kbd.cpp @@ -27,7 +27,7 @@ tiny_rom_entry const *qx10_keyboard_device::device_rom_region() const void qx10_keyboard_device::device_start() { - m_bit_timer = timer_alloc(); + m_bit_timer = timer_alloc(FUNC(qx10_keyboard_device::toggle_clk), this); m_bit_timer->adjust(attotime::from_hz(2400), 0, attotime::from_hz(2400)); m_clk_state = 0; } @@ -37,7 +37,7 @@ WRITE_LINE_MEMBER(qx10_keyboard_device::input_txd) m_rxd = state; } -void qx10_keyboard_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(qx10_keyboard_device::toggle_clk) { m_clk_state = !m_clk_state; } diff --git a/src/mame/machine/qx10kbd.h b/src/mame/machine/qx10kbd.h index 846829fd5a3..6e7d15a701a 100644 --- a/src/mame/machine/qx10kbd.h +++ b/src/mame/machine/qx10kbd.h @@ -22,15 +22,17 @@ public: protected: virtual const tiny_rom_entry *device_rom_region() const override; virtual void device_add_mconfig(machine_config &config) override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; virtual void device_start() override; + TIMER_CALLBACK_MEMBER(toggle_clk); + private: required_ioport_array<16> m_rows; required_device<cpu_device> m_mcu; emu_timer *m_bit_timer = nullptr; u8 m_rxd = 0; - int m_row = 0, m_clk_state = 0; + int m_row = 0; + int m_clk_state = 0; }; DECLARE_DEVICE_TYPE(QX10_KEYBOARD, qx10_keyboard_device) diff --git a/src/mame/machine/rm380z.cpp b/src/mame/machine/rm380z.cpp index 4d8d57a1405..76651b1547d 100644 --- a/src/mame/machine/rm380z.cpp +++ b/src/mame/machine/rm380z.cpp @@ -226,7 +226,7 @@ void rm380z_state::disk_0_control(uint8_t data) void rm380z_state::machine_start() { - m_static_vblank_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(rm380z_state::static_vblank_timer), this)); + m_static_vblank_timer = timer_alloc(FUNC(rm380z_state::static_vblank_timer), this); m_static_vblank_timer->adjust(attotime::from_hz(TIMER_SPEED), 0, attotime::from_hz(TIMER_SPEED)); } diff --git a/src/mame/machine/rmnimbus.cpp b/src/mame/machine/rmnimbus.cpp index 9805cb0a4ef..557422c38ff 100644 --- a/src/mame/machine/rmnimbus.cpp +++ b/src/mame/machine/rmnimbus.cpp @@ -215,7 +215,7 @@ void rmnimbus_state::machine_reset() void rmnimbus_state::machine_start() { - m_nimbus_mouse.m_mouse_timer=timer_alloc(TIMER_MOUSE); + m_nimbus_mouse.m_mouse_timer = timer_alloc(FUNC(rmnimbus_state::do_mouse), this); /* setup debug commands */ if (machine().debug_flags & DEBUG_FLAG_ENABLED) @@ -1669,18 +1669,10 @@ WRITE_LINE_MEMBER(rmnimbus_state::nimbus_msm5205_vck) external_int(EXTERNAL_INT_MSM5205,state); } -void rmnimbus_state::device_timer(emu_timer &timer, device_timer_id id, int param) -{ - switch(id) - { - case TIMER_MOUSE : do_mouse(); break; - } -} - static const int MOUSE_XYA[4] = { 1, 1, 0, 0 }; static const int MOUSE_XYB[4] = { 0, 1, 1, 0 }; -void rmnimbus_state::do_mouse() +TIMER_CALLBACK_MEMBER(rmnimbus_state::do_mouse) { uint8_t mouse_x; // Current mouse X and Y uint8_t mouse_y; diff --git a/src/mame/machine/rx01.cpp b/src/mame/machine/rx01.cpp index 48497995804..d791bd0fb80 100644 --- a/src/mame/machine/rx01.cpp +++ b/src/mame/machine/rx01.cpp @@ -81,6 +81,7 @@ void rx01_device::device_add_mconfig(machine_config &config) void rx01_device::device_start() { + m_command_timer = timer_alloc(FUNC(rx01_device::service_command), this); } @@ -90,7 +91,9 @@ void rx01_device::device_start() void rx01_device::device_reset() { - for(auto & elem : m_image) + m_command_timer->adjust(attotime::never); + + for (auto & elem : m_image) { elem->floppy_mon_w(0); // turn it on elem->floppy_drive_set_controller(this); @@ -107,7 +110,8 @@ void rx01_device::device_reset() uint16_t rx01_device::read(offs_t offset) { - switch(offset & 1) { + switch (offset & 1) + { case 0: return status_read(); default: return data_read(); } @@ -121,7 +125,8 @@ uint16_t rx01_device::read(offs_t offset) void rx01_device::write(offs_t offset, uint16_t data) { - switch(offset & 1) { + switch (offset & 1) + { case 0: command_write(data); break; case 1: data_write(data); break; } @@ -130,50 +135,51 @@ void rx01_device::write(offs_t offset, uint16_t data) void rx01_device::command_write(uint16_t data) { printf("command_write %04x\n",data); - m_unit = BIT(data,4); - m_interrupt = BIT(data,6); + m_unit = BIT(data, 4); + m_interrupt = BIT(data, 6); - m_image[m_unit]->floppy_drive_set_ready_state(1,0); + m_image[m_unit]->floppy_drive_set_ready_state(1, 0); - if (BIT(data,14)) // Initialize + if (BIT(data, 14)) // Initialize { printf("initialize\n"); m_state = RX01_INIT; } else if (BIT(data,1)) // If GO bit is selected { - m_rxcs &= ~(1<<5); // Clear done bit + m_rxcs &= ~(1 << 5); // Clear done bit m_buf_pos = 0; // Point to start of buffer - switch((data >> 1) & 7) { + switch ((data >> 1) & 7) + { case 0: // Fill Buffer - m_rxcs |= (1<<7); // Set TR Bit - m_state = RX01_FILL; - break; + m_rxcs |= (1 << 7); // Set TR Bit + m_state = RX01_FILL; + break; case 1: // Empty Buffer - m_state = RX01_EMPTY; - break; + m_state = RX01_EMPTY; + break; case 2: // Write Sector case 3: // Read Sector case 6: // Write Deleted Data Sector - m_rxes &= ~(1<<6 | 1<<1 | 1<<0);// Reset bits 0, 1 and 6 - m_state = RX01_SET_SECTOR; - break; + m_rxes &= ~(1 << 6 | 1 << 1 | 1 << 0);// Reset bits 0, 1 and 6 + m_state = RX01_SET_SECTOR; + break; case 4: // Not Used - m_state = RX01_COMPLETE; - break; + m_state = RX01_COMPLETE; + break; case 5: // Read Status - m_state = RX01_COMPLETE; - m_rxdb = m_rxes; - break; + m_state = RX01_COMPLETE; + m_rxdb = m_rxes; + break; case 7: // Read Error Register - m_state = RX01_COMPLETE; - // set ready signal according to current drive status - m_rxes |= m_image[m_unit]->floppy_drive_get_flag_state(FLOPPY_DRIVE_READY) << 7; - break; + m_state = RX01_COMPLETE; + // set ready signal according to current drive status + m_rxes |= m_image[m_unit]->floppy_drive_get_flag_state(FLOPPY_DRIVE_READY) << 7; + break; } } - machine().scheduler().timer_set(attotime::from_msec(100), timer_expired_delegate(FUNC(rx01_device::service_command),this)); + m_command_timer->adjust(attotime::from_msec(100)); } uint16_t rx01_device::status_read() @@ -186,13 +192,15 @@ void rx01_device::data_write(uint16_t data) { // printf("data_write %04x\n",data); // data can be written only if TR is set - if (BIT(m_rxcs,7)) m_rxdb = data; - machine().scheduler().timer_set(attotime::from_msec(100), timer_expired_delegate(FUNC(rx01_device::service_command),this)); + if (BIT(m_rxcs,7)) + m_rxdb = data; + machine().scheduler().timer_set(attotime::from_msec(100), timer_expired_delegate(FUNC(rx01_device::service_command), this)); } uint16_t rx01_device::data_read() { - if (m_state==RX01_EMPTY && BIT(m_rxcs,7)) m_rxcs &= (1<<7); // clear TR bit; + if (m_state == RX01_EMPTY && BIT(m_rxcs, 7)) + m_rxcs &= (1 << 7); // clear TR bit; // printf("data_read %04x\n",m_rxdb); return m_rxdb; } @@ -201,46 +209,51 @@ TIMER_CALLBACK_MEMBER(rx01_device::service_command) { printf("service_command %d\n",m_state); m_rxes |= m_image[m_unit]->floppy_drive_get_flag_state(FLOPPY_DRIVE_READY) << 7; - switch(m_state) { - case RX01_FILL : - m_buffer[m_buf_pos] = m_rxdb & 0xff; - m_buf_pos++; - if (m_buf_pos<128) - { - m_rxcs |= (1<<7); // Set TR Bit - } else { - //finished - } - break; - case RX01_EMPTY : - if (m_buf_pos>=128) - { - //finished - } else { - m_buffer[m_buf_pos] = m_rxdb & 0xff; - m_buf_pos++; - m_rxcs |= (1<<7); // Set TR Bit - } - break; + switch (m_state) + { + case RX01_FILL: + m_buffer[m_buf_pos] = m_rxdb & 0xff; + m_buf_pos++; + if (m_buf_pos < 128) + { + m_rxcs |= (1 << 7); // Set TR Bit + } + else + { + //finished + } + break; + case RX01_EMPTY: + if (m_buf_pos >= 128) + { + //finished + } + else + { + m_buffer[m_buf_pos] = m_rxdb & 0xff; + m_buf_pos++; + m_rxcs |= (1 << 7); // Set TR Bit + } + break; case RX01_SET_SECTOR: - m_rxsa = m_rxdb & 0x1f; - m_rxcs |= (1<<7); // Set TR Bit - m_state = RX01_SET_TRACK; - break; + m_rxsa = m_rxdb & 0x1f; + m_rxcs |= (1 << 7); // Set TR Bit + m_state = RX01_SET_TRACK; + break; case RX01_SET_TRACK: - m_rxta = m_rxdb & 0x7f; - m_rxcs |= (1<<7); // Set TR Bit - m_state = RX01_TRANSFER; - position_head(); - break; + m_rxta = m_rxdb & 0x7f; + m_rxcs |= (1 << 7); // Set TR Bit + m_state = RX01_TRANSFER; + position_head(); + break; case RX01_TRANSFER: - break; + break; case RX01_COMPLETE: - break; + break; case RX01_INIT: - m_rxes |= (1<<2); // Set init done flag - m_rxcs |= (1<<5); // Set operation done - break; + m_rxes |= (1 << 2); // Set init done flag + m_rxcs |= (1 << 5); // Set operation done + break; } } diff --git a/src/mame/machine/rx01.h b/src/mame/machine/rx01.h index e4fc2fe59a6..a6c128f71e8 100644 --- a/src/mame/machine/rx01.h +++ b/src/mame/machine/rx01.h @@ -67,6 +67,7 @@ private: uint8_t m_buffer[128]{}; int m_buf_pos = 0; + emu_timer *m_command_timer = nullptr; uint16_t m_rxcs = 0; // Command and Status Register uint16_t m_rxdb = 0; // Data Buffer Register uint16_t m_rxta = 0; // RX Track Address diff --git a/src/mame/machine/saa7191.cpp b/src/mame/machine/saa7191.cpp index 96a2e72315b..a879506e84b 100644 --- a/src/mame/machine/saa7191.cpp +++ b/src/mame/machine/saa7191.cpp @@ -53,9 +53,6 @@ void saa7191_device::device_start() m_uv_out.resolve_safe(); m_hs_out.resolve_safe(); m_vs_out.resolve_safe(); - - m_input_clock = timer_alloc(TIMER_INPUT_CLOCK); - m_input_clock->adjust(attotime::never); } void saa7191_device::device_reset() @@ -67,12 +64,6 @@ void saa7191_device::device_reset() m_i2c_read_addr = 0x8b; m_i2c_subaddr = 0x00; m_i2c_state = I2C_STATE_IDLE; - - m_input_clock->adjust(attotime::never); -} - -void saa7191_device::device_timer(emu_timer &timer, device_timer_id id, int param) -{ } void saa7191_device::i2c_data_w(uint8_t data) diff --git a/src/mame/machine/saa7191.h b/src/mame/machine/saa7191.h index 51a16b43a3b..907edfdc3b0 100644 --- a/src/mame/machine/saa7191.h +++ b/src/mame/machine/saa7191.h @@ -39,7 +39,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; private: void reg_w(uint8_t data); @@ -151,10 +150,6 @@ private: I2C_STATE_DATA_WRITE }; - static constexpr device_timer_id TIMER_INPUT_CLOCK = 0; - - emu_timer *m_input_clock; - uint8_t m_status; uint8_t m_regs[REG_COUNT]; diff --git a/src/mame/machine/sgi.cpp b/src/mame/machine/sgi.cpp index 21eb109832d..0b943ae4d90 100644 --- a/src/mame/machine/sgi.cpp +++ b/src/mame/machine/sgi.cpp @@ -86,10 +86,10 @@ void sgi_mc_device::device_start() m_sys_id = 0x03; // rev. C MC m_sys_id |= m_eisa_present() << 4; - m_rpss_timer = timer_alloc(TIMER_RPSS); + m_rpss_timer = timer_alloc(FUNC(sgi_mc_device::rpss_tick), this); m_rpss_timer->adjust(attotime::never); - m_dma_timer = timer_alloc(TIMER_DMA); + m_dma_timer = timer_alloc(FUNC(sgi_mc_device::perform_dma), this); m_dma_timer->adjust(attotime::never); save_item(NAME(m_cpu_control)); @@ -211,7 +211,7 @@ uint32_t sgi_mc_device::dma_translate(uint32_t address) return 0; } -void sgi_mc_device::dma_immediate() +TIMER_CALLBACK_MEMBER(sgi_mc_device::perform_dma) { uint32_t memory_addr = m_dma_mem_addr; uint32_t linecount = get_line_count(); @@ -721,19 +721,12 @@ void sgi_mc_device::write(offs_t offset, uint32_t data, uint32_t mem_mask) } } -void sgi_mc_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(sgi_mc_device::rpss_tick) { - if (id == TIMER_RPSS) + m_rpss_divide_counter--; + if (m_rpss_divide_counter < 0) { - m_rpss_divide_counter--; - if (m_rpss_divide_counter < 0) - { - m_rpss_divide_counter = m_rpss_divide_count; - m_rpss_counter += m_rpss_increment; - } - } - else if (id == TIMER_DMA) - { - dma_immediate(); + m_rpss_divide_counter = m_rpss_divide_count; + m_rpss_counter += m_rpss_increment; } } diff --git a/src/mame/machine/sgi.h b/src/mame/machine/sgi.h index 0f5fd99e670..c634e353108 100644 --- a/src/mame/machine/sgi.h +++ b/src/mame/machine/sgi.h @@ -41,10 +41,6 @@ protected: virtual void device_resolve_objects() 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; - - static const device_timer_id TIMER_RPSS = 0; - static const device_timer_id TIMER_DMA = 1; private: enum @@ -57,7 +53,8 @@ private: }; uint32_t dma_translate(uint32_t address); - void dma_immediate(); + TIMER_CALLBACK_MEMBER(perform_dma); + TIMER_CALLBACK_MEMBER(rpss_tick); uint32_t get_line_count() { return m_dma_size >> 16; } uint32_t get_line_width() { return (uint16_t)m_dma_size; } diff --git a/src/mame/machine/simpsons.cpp b/src/mame/machine/simpsons.cpp index 9d6610a0b6d..995363e6fb6 100644 --- a/src/mame/machine/simpsons.cpp +++ b/src/mame/machine/simpsons.cpp @@ -12,14 +12,14 @@ ***************************************************************************/ -void simpsons_state::simpsons_eeprom_w(uint8_t data) +void simpsons_state::eeprom_w(uint8_t data) { if (data == 0xff) return; ioport("EEPROMOUT")->write(data, 0xff); - simpsons_video_banking(data & 0x03); + video_bank_select(data & 0x03); m_firq_enabled = data & 0x04; if (!m_firq_enabled) @@ -32,7 +32,7 @@ void simpsons_state::simpsons_eeprom_w(uint8_t data) ***************************************************************************/ -void simpsons_state::simpsons_coin_counter_w(uint8_t data) +void simpsons_state::coin_counter_w(uint8_t data) { /* bit 0,1 coin counters */ machine().bookkeeping().coin_counter_w(0, data & 0x01); @@ -45,7 +45,7 @@ void simpsons_state::simpsons_coin_counter_w(uint8_t data) m_k053246->k053246_set_objcha_line((~data & 0x20) ? ASSERT_LINE : CLEAR_LINE); } -uint8_t simpsons_state::simpsons_sound_interrupt_r() +uint8_t simpsons_state::sound_interrupt_r() { m_audiocpu->set_input_line_and_vector(0, HOLD_LINE, 0xff ); // Z80 return 0x00; @@ -78,6 +78,9 @@ void simpsons_state::machine_start() save_item(NAME(m_layer_colorbase)); save_item(NAME(m_layerpri)); save_pointer(NAME(m_spriteram), 0x1000 / 2); + + m_dma_start_timer = timer_alloc(FUNC(simpsons_state::dma_start), this); + m_dma_end_timer = timer_alloc(FUNC(simpsons_state::dma_end), this); } void simpsons_state::machine_reset() @@ -95,5 +98,8 @@ void simpsons_state::machine_reset() /* init the default banks */ membank("bank1")->set_entry(0); membank("bank2")->set_entry(0); - simpsons_video_banking(0); + video_bank_select(0); + + m_dma_start_timer->adjust(attotime::never); + m_dma_end_timer->adjust(attotime::never); } diff --git a/src/mame/machine/sms.cpp b/src/mame/machine/sms.cpp index 1a2a2a3a94b..465147d6eb2 100644 --- a/src/mame/machine/sms.cpp +++ b/src/mame/machine/sms.cpp @@ -1041,7 +1041,7 @@ void sms_state::machine_start() } } - m_lphaser_th_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(sms_state::lphaser_th_generate),this)); + m_lphaser_th_timer = timer_alloc(FUNC(sms_state::lphaser_th_generate), this); save_item(NAME(m_mapper)); save_item(NAME(m_port_dc_reg)); diff --git a/src/mame/machine/snes.cpp b/src/mame/machine/snes.cpp index d8bdd2bf16c..fe2a810c5ee 100644 --- a/src/mame/machine/snes.cpp +++ b/src/mame/machine/snes.cpp @@ -52,44 +52,10 @@ void snes_state::scpu_irq_refresh() } -void snes_state::device_timer(emu_timer &timer, device_timer_id id, int param) -{ - switch (id) - { - case TIMER_NMI_TICK: - snes_nmi_tick(param); - break; - case TIMER_HIRQ_TICK: - snes_hirq_tick_callback(param); - break; - case TIMER_RESET_OAM_ADDRESS: - snes_reset_oam_address(param); - break; - case TIMER_RESET_HDMA: - snes_reset_hdma(param); - break; - case TIMER_UPDATE_IO: - snes_update_io(param); - break; - case TIMER_SCANLINE_TICK: - snes_scanline_tick(param); - break; - case TIMER_HBLANK_TICK: - snes_hblank_tick(param); - break; - default: - throw emu_fatalerror("Unknown id in snes_state::device_timer"); - } -} - - TIMER_CALLBACK_MEMBER(snes_state::snes_nmi_tick) { // pull NMI m_maincpu->set_input_line(G65816_LINE_NMI, ASSERT_LINE); - - // don't happen again - m_nmi_timer->adjust(attotime::never); } void snes_state::hirq_tick() @@ -99,9 +65,6 @@ void snes_state::hirq_tick() m_ppu->set_latch_hv(m_ppu->current_x(), m_ppu->current_y()); SNES_CPU_REG(TIMEUP) = 0x80; /* Indicate that irq occurred */ scpu_irq_refresh(); - - // don't happen again - m_hirq_timer->adjust(attotime::never); } TIMER_CALLBACK_MEMBER(snes_state::snes_hirq_tick_callback) @@ -125,8 +88,6 @@ TIMER_CALLBACK_MEMBER(snes_state::snes_update_io) { io_read(); SNES_CPU_REG(HVBJOY) &= 0xfe; /* Clear busy bit */ - - m_io_timer->adjust(attotime::never); } TIMER_CALLBACK_MEMBER(snes_state::snes_scanline_tick) @@ -180,7 +141,7 @@ TIMER_CALLBACK_MEMBER(snes_state::snes_scanline_tick) /* Start of VBlank */ if (m_ppu->current_vert() == m_ppu->last_visible_line()) { - timer_set(m_screen->time_until_pos(m_ppu->current_vert(), 10), TIMER_RESET_OAM_ADDRESS); + m_oam_reset_addr_timer->adjust(m_screen->time_until_pos(m_ppu->current_vert(), 10)); SNES_CPU_REG(HVBJOY) |= 0x81; /* Set vblank bit to on & indicate controllers being read */ SNES_CPU_REG(RDNMI) |= 0x80; /* Set NMI occurred bit */ @@ -212,7 +173,6 @@ TIMER_CALLBACK_MEMBER(snes_state::snes_scanline_tick) m_maincpu->set_input_line(G65816_LINE_NMI, CLEAR_LINE ); } - m_scanline_timer->adjust(attotime::never); m_hblank_timer->adjust(m_screen->time_until_pos(m_ppu->current_vert(), m_hblank_offset * m_ppu->htmult())); // printf("%02x %d\n",SNES_CPU_REG(HVBJOY),m_ppu->current_vert()); @@ -226,9 +186,6 @@ TIMER_CALLBACK_MEMBER(snes_state::snes_hblank_tick) m_ppu->set_current_vert(m_screen->vpos()); - /* make sure we halt */ - m_hblank_timer->adjust(attotime::never); - /* draw a scanline */ if (m_ppu->current_vert() <= m_ppu->last_visible_line()) { @@ -559,7 +516,7 @@ void snes_state::snes_w_io(address_space &space, offs_t offset, uint8_t data) return; case HDMAEN: /* HDMA channel designation */ if (data != SNES_CPU_REG(HDMAEN)) //if a HDMA is enabled, data is inited at the next scanline - timer_set(m_screen->time_until_pos(m_ppu->current_vert() + 1), TIMER_RESET_HDMA); + m_hdma_reset_timer->adjust(m_screen->time_until_pos(m_ppu->current_vert() + 1)); SNES_CPU_REG(HDMAEN) = data; return; case TIMEUP: // IRQ Flag is cleared on both read and write @@ -1018,20 +975,24 @@ uint8_t snes_state::oldjoy2_read(int latched) void snes_state::snes_init_timers() { /* init timers and stop them */ - m_scanline_timer = timer_alloc(TIMER_SCANLINE_TICK); + m_scanline_timer = timer_alloc(FUNC(snes_state::snes_scanline_tick), this); m_scanline_timer->adjust(attotime::never); - m_hblank_timer = timer_alloc(TIMER_HBLANK_TICK); + m_hblank_timer = timer_alloc(FUNC(snes_state::snes_hblank_tick), this); m_hblank_timer->adjust(attotime::never); - m_nmi_timer = timer_alloc(TIMER_NMI_TICK); + m_nmi_timer = timer_alloc(FUNC(snes_state::snes_nmi_tick), this); m_nmi_timer->adjust(attotime::never); - m_hirq_timer = timer_alloc(TIMER_HIRQ_TICK); + m_hirq_timer = timer_alloc(FUNC(snes_state::snes_hirq_tick_callback), this); m_hirq_timer->adjust(attotime::never); //m_div_timer = timer_alloc(TIMER_DIV); //m_div_timer->adjust(attotime::never); //m_mult_timer = timer_alloc(TIMER_MULT); //m_mult_timer->adjust(attotime::never); - m_io_timer = timer_alloc(TIMER_UPDATE_IO); + m_io_timer = timer_alloc(FUNC(snes_state::snes_update_io), this); m_io_timer->adjust(attotime::never); + m_oam_reset_addr_timer = timer_alloc(FUNC(snes_state::snes_reset_oam_address), this); + m_oam_reset_addr_timer->adjust(attotime::never); + m_hdma_reset_timer = timer_alloc(FUNC(snes_state::snes_reset_hdma), this); + m_hdma_reset_timer->adjust(attotime::never); // SNES hcounter has a 0-339 range. hblank starts at counter 260. // clayfighter sets an HIRQ at 260, apparently it wants it to be before hdma kicks off, so we'll delay 2 pixels. diff --git a/src/mame/machine/sorcerer.cpp b/src/mame/machine/sorcerer.cpp index 85729ba7041..fdd3273b58d 100644 --- a/src/mame/machine/sorcerer.cpp +++ b/src/mame/machine/sorcerer.cpp @@ -28,22 +28,6 @@ TIMER_CALLBACK_MEMBER(sorcerer_state::serial_tc) } -void sorcerer_state::device_timer(emu_timer &timer, device_timer_id id, int param) -{ - switch (id) - { - case TIMER_SERIAL: - serial_tc(param); - break; - case TIMER_CASSETTE: - cassette_tc(param); - break; - default: - throw emu_fatalerror("Unknown id in sorcerer_state::device_timer"); - } -} - - /* timer to read cassette waveforms */ TIMER_CALLBACK_MEMBER(sorcerer_state::cassette_tc) @@ -437,8 +421,8 @@ u8 sorcerer_state::portfe_r() // ************ MACHINE ************** void sorcerer_state::machine_start_common(offs_t endmem) { - m_cassette_timer = timer_alloc(TIMER_CASSETTE); - m_serial_timer = timer_alloc(TIMER_SERIAL); + m_cassette_timer = timer_alloc(FUNC(sorcerer_state::cassette_tc), this); + m_serial_timer = timer_alloc(FUNC(sorcerer_state::serial_tc), this); m_halt = false; diff --git a/src/mame/machine/starwars.cpp b/src/mame/machine/starwars.cpp index dcaf2205f3a..93836c10d2e 100644 --- a/src/mame/machine/starwars.cpp +++ b/src/mame/machine/starwars.cpp @@ -115,7 +115,7 @@ void starwars_state::starwars_mproc_init() m_PROM_AM[cnt] = (val >> 7) & 0x0001; } - m_math_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(starwars_state::math_run_clear),this)); + m_math_timer = timer_alloc(FUNC(starwars_state::math_run_clear), this); } diff --git a/src/mame/machine/stfight.cpp b/src/mame/machine/stfight.cpp index c20c656e0d5..1267445e71f 100644 --- a/src/mame/machine/stfight.cpp +++ b/src/mame/machine/stfight.cpp @@ -72,7 +72,7 @@ void stfight_state::machine_start() m_main_bank->configure_entries(0, 4, memregion("maincpu")->base() + 0x10000, 0x4000); m_main_bank->set_entry(0); - m_int1_timer = timer_alloc(TIMER_STFIGHT_INTERRUPT_1); + m_int1_timer = timer_alloc(FUNC(stfight_state::rst08_tick), this); save_item(NAME(m_coin_state)); save_item(NAME(m_fm_data)); @@ -109,17 +109,9 @@ void stfight_state::stfight_bank_w(uint8_t data) * CPU 1 timed interrupt - 60Hz??? */ -void stfight_state::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(stfight_state::rst08_tick) { - switch (id) - { - case TIMER_STFIGHT_INTERRUPT_1: - // Do a RST08 - m_maincpu->set_input_line_and_vector(0, HOLD_LINE, 0xd7); // Z80 - break; - default: - throw emu_fatalerror("Unknown id in stfight_state::device_timer"); - } + m_maincpu->set_input_line_and_vector(0, HOLD_LINE, 0xd7); // Z80 } INTERRUPT_GEN_MEMBER(stfight_state::stfight_vb_interrupt) diff --git a/src/mame/machine/swtpc09.cpp b/src/mame/machine/swtpc09.cpp index 2741a6f5e3c..fe7b02b9d80 100644 --- a/src/mame/machine/swtpc09.cpp +++ b/src/mame/machine/swtpc09.cpp @@ -1010,7 +1010,7 @@ void swtpc09_state::machine_start() m_dmaf_high_address[2] = 0; m_dmaf_high_address[3] = 0; - m_floppy_motor_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(swtpc09_state::floppy_motor_callback),this)); + m_floppy_motor_timer = timer_alloc(FUNC(swtpc09_state::floppy_motor_callback), this); m_floppy_motor_on = 0; // reset the 6844 diff --git a/src/mame/machine/thomson.cpp b/src/mame/machine/thomson.cpp index 378bf038f1a..78dc3f877e6 100644 --- a/src/mame/machine/thomson.cpp +++ b/src/mame/machine/thomson.cpp @@ -867,7 +867,7 @@ TIMER_CALLBACK_MEMBER(thomson_state::to7_game_update_cb) void thomson_state::to7_game_init() { LOG (( "to7_game_init called\n" )); - m_to7_game_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(thomson_state::to7_game_update_cb),this)); + m_to7_game_timer = timer_alloc(FUNC(thomson_state::to7_game_update_cb), this); m_to7_game_timer->adjust(TO7_GAME_POLL_PERIOD, 0, TO7_GAME_POLL_PERIOD); save_item(NAME(m_to7_game_sound)); save_item(NAME(m_to7_game_mute)); @@ -1597,7 +1597,7 @@ MACHINE_START_MEMBER( mo5_state, mo5 ) to7_game_init(); to7_modem_init(); to7_midi_init(); - m_mo5_periodic_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(mo5_state::mo5_periodic_cb),this)); + m_mo5_periodic_timer = timer_alloc(FUNC(mo5_state::mo5_periodic_cb), this); m_extension->rom_map(m_maincpu->space(AS_PROGRAM), 0xa000, 0xa7bf); m_extension->io_map (m_maincpu->space(AS_PROGRAM), 0xa7d0, 0xa7df); @@ -2423,7 +2423,7 @@ void to9_state::to9_kbd_reset() void to9_state::to9_kbd_init() { LOG(( "to9_kbd_init called\n" )); - m_to9_kbd_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(to9_state::to9_kbd_timer_cb),this)); + m_to9_kbd_timer = timer_alloc(FUNC(to9_state::to9_kbd_timer_cb), this); save_item(NAME(m_to9_kbd_parity)); save_item(NAME(m_to9_kbd_intr)); save_item(NAME(m_to9_kbd_in)); @@ -2877,7 +2877,7 @@ void to9_state::to8_kbd_reset() void to9_state::to8_kbd_init() { - m_to8_kbd_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(to9_state::to8_kbd_timer_cb),this)); + m_to8_kbd_timer = timer_alloc(FUNC(to9_state::to8_kbd_timer_cb), this); m_to8_kbd_signal = machine().scheduler().timer_alloc(timer_expired_delegate()); save_item(NAME(m_to8_kbd_ack)); save_item(NAME(m_to8_kbd_data)); @@ -4001,7 +4001,7 @@ TIMER_CALLBACK_MEMBER(mo6_state::mo6_game_update_cb) void mo6_state::mo6_game_init() { LOG (( "mo6_game_init called\n" )); - m_to7_game_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(mo6_state::mo6_game_update_cb),this)); + m_to7_game_timer = timer_alloc(FUNC(mo6_state::mo6_game_update_cb), this); m_to7_game_timer->adjust(TO7_GAME_POLL_PERIOD, 0, TO7_GAME_POLL_PERIOD); save_item(NAME(m_to7_game_sound)); save_item(NAME(m_to7_game_mute)); @@ -4303,7 +4303,7 @@ MACHINE_START_MEMBER( mo6_state, mo6 ) to9_palette_init(); to7_modem_init(); to7_midi_init(); - m_mo5_periodic_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(mo6_state::mo5_periodic_cb),this)); + m_mo5_periodic_timer = timer_alloc(FUNC(mo6_state::mo5_periodic_cb), this); m_extension->rom_map(m_maincpu->space(AS_PROGRAM), 0xa000, 0xa7bf); m_extension->io_map (m_maincpu->space(AS_PROGRAM), 0xa7d0, 0xa7df); @@ -4423,7 +4423,7 @@ void mo5nr_state::mo5nr_sys_porta_out(uint8_t data) void mo5nr_state::mo5nr_game_init() { LOG (( "mo5nr_game_init called\n" )); - m_to7_game_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(mo5nr_state::mo6_game_update_cb),this)); + m_to7_game_timer = timer_alloc(FUNC(mo5nr_state::mo6_game_update_cb), this); m_to7_game_timer->adjust( TO7_GAME_POLL_PERIOD, 0, TO7_GAME_POLL_PERIOD ); save_item(NAME(m_to7_game_sound)); save_item(NAME(m_to7_game_mute)); @@ -4505,7 +4505,7 @@ MACHINE_START_MEMBER( mo5nr_state, mo5nr ) to9_palette_init(); to7_modem_init(); to7_midi_init(); - m_mo5_periodic_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(mo5nr_state::mo5_periodic_cb),this)); + m_mo5_periodic_timer = timer_alloc(FUNC(mo5nr_state::mo5_periodic_cb), this); m_extension->rom_map(m_extension_view[0], 0xa000, 0xa7bf); m_extension->io_map (m_extension_view[0], 0xa7d0, 0xa7df); diff --git a/src/mame/machine/ti85.cpp b/src/mame/machine/ti85.cpp index a9c473ba3c5..3906581466b 100644 --- a/src/mame/machine/ti85.cpp +++ b/src/mame/machine/ti85.cpp @@ -71,66 +71,34 @@ TIMER_CALLBACK_MEMBER(ti85_state::ti83_timer2_callback) } } -void ti85_state::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(ti85_state::crystal_timer_tick) { - switch (id) + int id = param; + + if (m_ctimer[id].count) { - case CRYSTAL_TIMER3: - case CRYSTAL_TIMER2: - case CRYSTAL_TIMER1: - if (m_ctimer[id].count) + m_ctimer[id].count--; + if (!m_ctimer[id].count) { - m_ctimer[id].count--; - if (!m_ctimer[id].count) + if (!(m_ctimer[id].loop & 4)) { - if (!(m_ctimer[id].loop & 4)) + if (!(m_ctimer[id].loop & 1)) { - if (!(m_ctimer[id].loop & 1)) - { - m_ctimer[id].setup = 0; - } - else - { - ti83pse_count(id, m_ctimer[id].max); - } - if (!(m_ctimer[id].loop & 2)) - { - //generate interrupt - m_ctimer_interrupt_status |= (0x20 << id); - m_maincpu->set_input_line(0, HOLD_LINE); - } - m_ctimer[id].loop &= 2; + m_ctimer[id].setup = 0; } + else + { + ti83pse_count(id, m_ctimer[id].max); + } + if (!(m_ctimer[id].loop & 2)) + { + //generate interrupt + m_ctimer_interrupt_status |= (0x20 << id); + m_maincpu->set_input_line(0, HOLD_LINE); + } + m_ctimer[id].loop &= 2; } } - break; - case HW_TIMER1: - if (ioport("ON")->read() & 0x01) - { - if (m_ON_interrupt_mask && !m_ON_pressed) - { - m_maincpu->set_input_line(0, HOLD_LINE); - m_ON_interrupt_status = 1; - } - m_ON_pressed = 1; - return; - } - else - { - m_ON_pressed = 0; - } - if (m_timer_interrupt_mask & 2) - { - m_maincpu->set_input_line(0, HOLD_LINE); - m_timer_interrupt_status = m_timer_interrupt_status | 2; - } - break; - case HW_TIMER2: - if (m_timer_interrupt_mask & 4) - { - m_maincpu->set_input_line(0, HOLD_LINE); - m_timer_interrupt_status = m_timer_interrupt_status | 4; - } } } @@ -255,7 +223,7 @@ void ti85_state::machine_start() m_port4_bit0 = 0; m_ti81_port_7_data = 0; - m_ti85_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(ti85_state::ti85_timer_callback), this)); + m_ti85_timer = timer_alloc(FUNC(ti85_state::ti85_timer_callback), this); m_ti85_timer->adjust(attotime::from_hz(256), 0, attotime::from_hz(256)); space.unmap_write(0x0000, 0x3fff); @@ -360,9 +328,9 @@ MACHINE_START_MEMBER(ti85_state,ti83p) ti85_state::update_ti83p_memory(); - m_ti83_1st_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(ti85_state::ti83_timer1_callback), this)); + m_ti83_1st_timer = timer_alloc(FUNC(ti85_state::ti83_timer1_callback), this); m_ti83_1st_timer->adjust(attotime::from_hz(256), 0, attotime::from_hz(256)); - m_ti83_2nd_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(ti85_state::ti83_timer2_callback), this)); + m_ti83_2nd_timer = timer_alloc(FUNC(ti85_state::ti83_timer2_callback), this); m_ti83_2nd_timer->adjust(attotime::from_hz(512), 0, attotime::from_hz(512)); /* save states and debugging */ @@ -400,14 +368,14 @@ void ti85_state::ti8xpse_init_common() ti85_state::update_ti83pse_memory(); - m_ti83_1st_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(ti85_state::ti83_timer1_callback), this)); + m_ti83_1st_timer = timer_alloc(FUNC(ti85_state::ti83_timer1_callback), this); m_ti83_1st_timer->adjust(attotime::from_hz(256), 0, attotime::from_hz(256)); - m_ti83_2nd_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(ti85_state::ti83_timer2_callback), this)); + m_ti83_2nd_timer = timer_alloc(FUNC(ti85_state::ti83_timer2_callback), this); m_ti83_2nd_timer->adjust(attotime::from_hz(512), 0, attotime::from_hz(512)); - m_crystal_timer1 = timer_alloc(CRYSTAL_TIMER1); - m_crystal_timer2 = timer_alloc(CRYSTAL_TIMER2); - m_crystal_timer3 = timer_alloc(CRYSTAL_TIMER3); + m_crystal_timer1 = timer_alloc(FUNC(ti85_state::crystal_timer_tick), this); + m_crystal_timer2 = timer_alloc(FUNC(ti85_state::crystal_timer_tick), this); + m_crystal_timer3 = timer_alloc(FUNC(ti85_state::crystal_timer_tick), this); /* save states and debugging */ save_item(NAME(m_ctimer_interrupt_status)); @@ -472,7 +440,7 @@ MACHINE_START_MEMBER(ti85_state,ti86) membank("bank4")->set_base(m_ti8x_ram.get()); subdevice<nvram_device>("nvram")->set_base(m_ti8x_ram.get(), sizeof(uint8_t)*128*1024); - m_ti85_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(ti85_state::ti85_timer_callback), this)); + m_ti85_timer = timer_alloc(FUNC(ti85_state::ti85_timer_callback), this); m_ti85_timer->adjust(attotime::from_hz(256), 0, attotime::from_hz(256)); } @@ -486,34 +454,31 @@ uint8_t ti85_state::ti85_port_0000_r() uint8_t ti85_state::ti8x_keypad_r() { - int data = 0xff; - int port; - int bit; - static const char *const bitnames[] = { "BIT0", "BIT1", "BIT2", "BIT3", "BIT4", "BIT5", "BIT6", "BIT7" }; + uint8_t data = 0xff; if (m_keypad_mask == 0x7f) return data; - for (bit = 0; bit < 7; bit++) + for (int bit = 0; bit < 7; bit++) { - if (~m_keypad_mask&(0x01<<bit)) + if (BIT(~m_keypad_mask, bit)) { - for (port = 0; port < 8; port++) + for (int port = 0; port < 8; port++) { - data ^= ioport(bitnames[port])->read() & (0x01<<bit) ? 0x01<<port : 0x00; + data ^= BIT(m_keys[port]->read(), bit) ? (1 << port) : 0x00; } } } return data; } - uint8_t ti85_state::ti85_port_0002_r() +uint8_t ti85_state::ti85_port_0002_r() { return 0xff; } - uint8_t ti85_state::ti85_port_0003_r() +uint8_t ti85_state::ti85_port_0003_r() { - int data = 0; + uint8_t data = 0; if (m_LCD_status) data |= m_LCD_mask; @@ -528,12 +493,12 @@ uint8_t ti85_state::ti8x_keypad_r() return data; } - uint8_t ti85_state::ti85_port_0004_r() +uint8_t ti85_state::ti85_port_0004_r() { return 0xff; } - uint8_t ti85_state::ti85_port_0005_r() +uint8_t ti85_state::ti85_port_0005_r() { return m_ti8x_memory_page_1; } @@ -592,7 +557,7 @@ uint8_t ti85_state::ti83_port_0002_r() uint8_t ti85_state::ti83_port_0003_r() { - int data = 0; + uint8_t data = 0; if (m_ON_interrupt_status) data |= 0x01; @@ -623,12 +588,12 @@ uint8_t ti85_state::ti8x_plus_serial_r() uint8_t ti85_state::ti83p_port_0002_r() { - return m_ti8x_port2|3; + return m_ti8x_port2 | 3; } uint8_t ti85_state::ti83p_port_0004_r() { - int data = 0; + uint8_t data = 0; //data |= m_LCD_mask; @@ -656,7 +621,7 @@ uint8_t ti85_state::ti83p_port_0004_r() uint8_t ti85_state::ti83pse_port_0002_r() { - return 0xC3 | (m_flash_unlocked << 2); + return 0xc3 | (m_flash_unlocked << 2); } uint8_t ti85_state::ti83pse_port_0009_r() @@ -682,28 +647,29 @@ void ti85_state::ti85_port_0000_w(uint8_t data) void ti85_state::ti8x_keypad_w(uint8_t data) { - m_keypad_mask = data&0x7f; + m_keypad_mask = data & 0x7f; } void ti85_state::ti85_port_0002_w(uint8_t data) { - m_LCD_contrast = data&0x1f; + m_LCD_contrast = data & 0x1f; } void ti85_state::ti85_port_0003_w(uint8_t data) { - if (m_LCD_status && !(data&0x08)) m_timer_interrupt_mask = 0; - m_ON_interrupt_mask = data&0x01; -// m_timer_interrupt_mask = data&0x04; - m_LCD_mask = data&0x02; - m_LCD_status = data&0x08; + if (m_LCD_status && !(data & 0x08)) + m_timer_interrupt_mask = 0; + m_ON_interrupt_mask = data & 0x01; +// m_timer_interrupt_mask = data & 0x04; + m_LCD_mask = data & 0x02; + m_LCD_status = data & 0x08; } void ti85_state::ti85_port_0004_w(uint8_t data) { - m_video_buffer_width = (data>>3)&0x03; - m_interrupt_speed = (data>>1)&0x03; - m_port4_bit0 = data&0x01; + m_video_buffer_width = (data >> 3) & 0x03; + m_interrupt_speed = (data >> 1) & 0x03; + m_port4_bit0 = data & 0x01; } void ti85_state::ti85_port_0005_w(uint8_t data) @@ -740,19 +706,19 @@ void ti85_state::ti8x_serial_w(uint8_t data) void ti85_state::ti86_port_0005_w(uint8_t data) { - m_ti8x_memory_page_1 = data&((data&0x40)?0x47:0x4f); + m_ti8x_memory_page_1 = data & ((data & 0x40) ? 0x47 : 0x4f); update_ti86_memory(); } void ti85_state::ti86_port_0006_w(uint8_t data) { - m_ti8x_memory_page_2 = data&((data&0x40)?0x47:0x4f); + m_ti8x_memory_page_2 = data & ((data & 0x40) ? 0x47 : 0x4f); update_ti86_memory(); } void ti85_state::ti82_port_0002_w(uint8_t data) { - m_ti8x_memory_page_1 = (data & 0x07); + m_ti8x_memory_page_1 = data & 0x07; update_ti85_memory(); m_ti8x_port2 = data; } @@ -772,11 +738,12 @@ void ti85_state::ti83_port_0002_w(uint8_t data) void ti85_state::ti83_port_0003_w(uint8_t data) { - if (m_LCD_status && !(data&0x08)) m_timer_interrupt_mask = 0; - m_ON_interrupt_mask = data&0x01; - //m_timer_interrupt_mask = data&0x04; - m_LCD_mask = data&0x02; - m_LCD_status = data&0x08; + if (m_LCD_status && !(data & 0x08)) + m_timer_interrupt_mask = 0; + m_ON_interrupt_mask = data & 0x01; + //m_timer_interrupt_mask = data & 0x04; + m_LCD_mask = data & 0x02; + m_LCD_status = data & 0x08; } void ti85_state::ti8x_plus_serial_w(uint8_t data) @@ -801,14 +768,14 @@ void ti85_state::ti8x_plus_serial_w(uint8_t data) void ti85_state::ti83pse_int_ack_w(uint8_t data) { - //Lets ignore this for now, I think it'll be fine. + //Lets ignore this for now, it should be fine. m_ON_interrupt_status = data & 1; m_timer_interrupt_status = data & 0x06; } void ti85_state::ti83p_int_mask_w(uint8_t data) { - //m_LCD_mask = (data&0x08) >> 2; + //m_LCD_mask = (data & 0x08) >> 2; m_ON_interrupt_mask = data & 0x01; m_ON_interrupt_status &= m_ON_interrupt_mask; @@ -825,13 +792,13 @@ void ti85_state::ti83p_port_0004_w(uint8_t data) void ti85_state::ti83p_port_0006_w(uint8_t data) { - m_ti8x_memory_page_1 = data & ((data&0x40) ? 0x41 : 0x5f); + m_ti8x_memory_page_1 = data & ((data & 0x40) ? 0x41 : 0x5f); update_ti83p_memory(); } void ti85_state::ti83p_port_0007_w(uint8_t data) { - m_ti8x_memory_page_2 = data & ((data&0x40) ? 0x41 : 0x5f); + m_ti8x_memory_page_2 = data & ((data & 0x40) ? 0x41 : 0x5f); update_ti83p_memory(); } @@ -849,7 +816,7 @@ void ti85_state::ti83pse_port_0005_w(uint8_t data) void ti85_state::ti83pse_port_0006_w(uint8_t data) { - if ((m_model == TI84P) && (data < 0x80)) + if (m_model == TI84P && data < 0x80) { m_ti8x_memory_page_1 = data & 0x3f; } @@ -862,7 +829,7 @@ void ti85_state::ti83pse_port_0006_w(uint8_t data) void ti85_state::ti83pse_port_0007_w(uint8_t data) { - if ((m_model == TI84P) && (data < 0x80)) + if (m_model == TI84P && data < 0x80) { m_ti8x_memory_page_2 = data & 0x3f; } @@ -882,7 +849,7 @@ void ti85_state::ti83p_port_0014_w(uint8_t data) void ti85_state::ti83pse_port_0020_w(uint8_t data) { m_cpu_speed = data; - if(data) + if (data) { m_maincpu->set_unscaled_clock(15000000); } @@ -955,15 +922,15 @@ void ti85_state::ti83pse_count( uint8_t timer, uint8_t data) switch (timer) { case CRYSTAL_TIMER1: - m_crystal_timer1->adjust(attotime::zero, 0, attotime::from_hz( 32768.0f/m_ctimer[timer].divsor)); + m_crystal_timer1->adjust(attotime::zero, CRYSTAL_TIMER1, attotime::from_hz(32768.0f / m_ctimer[timer].divsor)); m_crystal_timer1->enable(true); break; case CRYSTAL_TIMER2: - m_crystal_timer2->adjust(attotime::zero, 0, attotime::from_hz( 32768.0f/m_ctimer[timer].divsor)); + m_crystal_timer2->adjust(attotime::zero, CRYSTAL_TIMER2, attotime::from_hz(32768.0f / m_ctimer[timer].divsor)); m_crystal_timer2->enable(true); break; case CRYSTAL_TIMER3: - m_crystal_timer3->adjust(attotime::zero, 0, attotime::from_hz( 32768.0f/m_ctimer[timer].divsor)); + m_crystal_timer3->adjust(attotime::zero, CRYSTAL_TIMER3, attotime::from_hz(32768.0f / m_ctimer[timer].divsor)); m_crystal_timer3->enable(true); break; @@ -1081,14 +1048,13 @@ void ti85_state::ti83pse_ctimer3_count_w(uint8_t data) TI calculators snapshot files (SAV) ***************************************************************************/ -void ti85_state::ti8x_snapshot_setup_registers (uint8_t * data) +void ti85_state::ti8x_snapshot_setup_registers(uint8_t *data) { - unsigned char lo,hi; - unsigned char * reg = data + 0x40; + uint8_t *reg = data + 0x40; /* Set registers */ - lo = reg[0x00] & 0x0ff; - hi = reg[0x01] & 0x0ff; + uint8_t lo = reg[0x00] & 0x0ff; + uint8_t hi = reg[0x01] & 0x0ff; m_maincpu->set_state_int(Z80_AF, (hi << 8) | lo); lo = reg[0x04] & 0x0ff; hi = reg[0x05] & 0x0ff; @@ -1123,47 +1089,46 @@ void ti85_state::ti8x_snapshot_setup_registers (uint8_t * data) lo = reg[0x2c] & 0x0ff; hi = reg[0x2d] & 0x0ff; m_maincpu->set_state_int(Z80_HL2, (hi << 8) | lo); - m_maincpu->set_state_int(Z80_IFF1, reg[0x30]&0x0ff); - m_maincpu->set_state_int(Z80_IFF2, reg[0x34]&0x0ff); - m_maincpu->set_state_int(Z80_HALT, reg[0x38]&0x0ff); - m_maincpu->set_state_int(Z80_IM, reg[0x3c]&0x0ff); - m_maincpu->set_state_int(Z80_I, reg[0x40]&0x0ff); + m_maincpu->set_state_int(Z80_IFF1, reg[0x30] & 0x0ff); + m_maincpu->set_state_int(Z80_IFF2, reg[0x34] & 0x0ff); + m_maincpu->set_state_int(Z80_HALT, reg[0x38] & 0x0ff); + m_maincpu->set_state_int(Z80_IM, reg[0x3c] & 0x0ff); + m_maincpu->set_state_int(Z80_I, reg[0x40] & 0x0ff); - m_maincpu->set_state_int(Z80_R, (reg[0x44]&0x7f) | (reg[0x48]&0x80)); + m_maincpu->set_state_int(Z80_R, (reg[0x44] & 0x7f) | (reg[0x48] & 0x80)); m_maincpu->set_input_line(0, 0); m_maincpu->set_input_line(INPUT_LINE_NMI, 0); m_maincpu->set_input_line(INPUT_LINE_HALT, 0); } -void ti85_state::ti85_setup_snapshot (uint8_t * data) +void ti85_state::ti85_setup_snapshot(uint8_t *data) { address_space &space = m_maincpu->space(AS_PROGRAM); - int i; - unsigned char lo,hi; - unsigned char * hdw = data + 0x8000 + 0x94; + uint8_t *hdw = data + 0x8000 + 0x94; - ti8x_snapshot_setup_registers (data); + ti8x_snapshot_setup_registers(data); /* Memory dump */ - for (i = 0; i < 0x8000; i++) - space.write_byte(i + 0x8000, data[i+0x94]); + for (int i = 0; i < 0x8000; i++) + space.write_byte(i + 0x8000, data[i + 0x94]); - m_keypad_mask = hdw[0x00]&0x7f; + m_keypad_mask = hdw[0x00] & 0x7f; - m_ti8x_memory_page_1 = hdw[0x08]&0xff; + m_ti8x_memory_page_1 = hdw[0x08] & 0xff; update_ti85_memory(); - m_power_mode = hdw[0x14]&0xff; + m_power_mode = hdw[0x14] & 0xff; - lo = hdw[0x28] & 0x0ff; - hi = hdw[0x29] & 0x0ff; - m_LCD_memory_base = (((hi << 8) | lo)-0xc000)>>8; + uint8_t lo = hdw[0x28] & 0x0ff; + uint8_t hi = hdw[0x29] & 0x0ff; + m_LCD_memory_base = (((hi << 8) | lo) - 0xc000) >> 8; - m_LCD_status = hdw[0x2c]&0xff ? 0 : 0x08; - if (m_LCD_status) m_LCD_mask = 0x02; + m_LCD_status = hdw[0x2c] & 0xff ? 0 : 0x08; + if (m_LCD_status) + m_LCD_mask = 0x02; - m_LCD_contrast = hdw[0x30]&0xff; + m_LCD_contrast = hdw[0x30] & 0xff; m_timer_interrupt_mask = !hdw[0x38]; m_timer_interrupt_status = 0; @@ -1176,10 +1141,9 @@ void ti85_state::ti85_setup_snapshot (uint8_t * data) m_interrupt_speed = 0x03; } -void ti85_state::ti86_setup_snapshot (uint8_t * data) +void ti85_state::ti86_setup_snapshot(uint8_t *data) { - unsigned char lo,hi; - unsigned char * hdw = data + 0x20000 + 0x94; + uint8_t *hdw = data + 0x20000 + 0x94; ti8x_snapshot_setup_registers ( data); @@ -1188,22 +1152,23 @@ void ti85_state::ti86_setup_snapshot (uint8_t * data) m_keypad_mask = hdw[0x00]&0x7f; - m_ti8x_memory_page_1 = hdw[0x04]&0xff ? 0x40 : 0x00; - m_ti8x_memory_page_1 |= hdw[0x08]&0x0f; + m_ti8x_memory_page_1 = hdw[0x04] & 0xff ? 0x40 : 0x00; + m_ti8x_memory_page_1 |= hdw[0x08] & 0x0f; - m_ti8x_memory_page_2 = hdw[0x0c]&0xff ? 0x40 : 0x00; - m_ti8x_memory_page_2 |= hdw[0x10]&0x0f; + m_ti8x_memory_page_2 = hdw[0x0c] & 0xff ? 0x40 : 0x00; + m_ti8x_memory_page_2 |= hdw[0x10] & 0x0f; update_ti86_memory(); - lo = hdw[0x2c] & 0x0ff; - hi = hdw[0x2d] & 0x0ff; - m_LCD_memory_base = (((hi << 8) | lo)-0xc000)>>8; + uint8_t lo = hdw[0x2c] & 0x0ff; + uint8_t hi = hdw[0x2d] & 0x0ff; + m_LCD_memory_base = (((hi << 8) | lo) - 0xc000) >> 8; - m_LCD_status = hdw[0x30]&0xff ? 0 : 0x08; - if (m_LCD_status) m_LCD_mask = 0x02; + m_LCD_status = hdw[0x30] & 0xff ? 0 : 0x08; + if (m_LCD_status) + m_LCD_mask = 0x02; - m_LCD_contrast = hdw[0x34]&0xff; + m_LCD_contrast = hdw[0x34] & 0xff; m_timer_interrupt_mask = !hdw[0x3c]; m_timer_interrupt_status = 0; @@ -1229,12 +1194,12 @@ SNAPSHOT_LOAD_MEMBER(ti85_state::snapshot_cb) if (image.length() != expected_snapshot_size) { - logerror ("Incomplete snapshot file\n"); + logerror("Incomplete snapshot file\n"); return image_init_result::FAIL; } std::vector<uint8_t> ti8x_snapshot_data(image.length()); - image.fread( &ti8x_snapshot_data[0], image.length()); + image.fread(&ti8x_snapshot_data[0], image.length()); if (!strncmp(machine().system().name, "ti85", 4)) ti85_setup_snapshot(&ti8x_snapshot_data[0]); diff --git a/src/mame/machine/trs80.cpp b/src/mame/machine/trs80.cpp index 1f6e17979f4..21723f95ddd 100644 --- a/src/mame/machine/trs80.cpp +++ b/src/mame/machine/trs80.cpp @@ -332,7 +332,7 @@ void trs80_state::machine_start() m_tape_unit = 1; m_reg_load = 1; - m_cassette_data_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(trs80_state::cassette_data_callback),this)); + m_cassette_data_timer = timer_alloc(FUNC(trs80_state::cassette_data_callback), this); m_cassette_data_timer->adjust( attotime::zero, 0, attotime::from_hz(11025) ); } diff --git a/src/mame/machine/trs80m3.cpp b/src/mame/machine/trs80m3.cpp index 842f210bb17..fed0e9d0ff3 100644 --- a/src/mame/machine/trs80m3.cpp +++ b/src/mame/machine/trs80m3.cpp @@ -578,7 +578,7 @@ void trs80m3_state::machine_start() if (!BIT(m_model4, 2)) // Model 4P has no cassette hardware { - m_cassette_data_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(trs80m3_state::cassette_data_callback),this)); + m_cassette_data_timer = timer_alloc(FUNC(trs80m3_state::cassette_data_callback), this); m_cassette_data_timer->adjust( attotime::zero, 0, attotime::from_hz(11025) ); } diff --git a/src/mame/machine/tsconf.cpp b/src/mame/machine/tsconf.cpp index 3540708fbf8..1204fa16140 100644 --- a/src/mame/machine/tsconf.cpp +++ b/src/mame/machine/tsconf.cpp @@ -767,56 +767,47 @@ void tsconf_state::dma_ready(int line) } } -void tsconf_state::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(tsconf_state::irq_frame) { - switch (id) + if (BIT(m_regs[INT_MASK], 0)) { - case TIMER_IRQ_FRAME: + m_maincpu->set_input_line_and_vector(0, ASSERT_LINE, 0xff); + m_irq_off_timer->adjust(m_maincpu->clocks_to_attotime(32 * (1 << (m_regs[SYS_CONFIG] & 0x03)))); + } +} + +TIMER_CALLBACK_MEMBER(tsconf_state::irq_scanline) +{ + u16 screen_vpos = m_screen->vpos(); + m_line_irq_timer->adjust(m_screen->time_until_pos(screen_vpos + 1)); + if (BIT(m_regs[INT_MASK], 1)) { - if (BIT(m_regs[INT_MASK], 0)) - { - m_maincpu->set_input_line_and_vector(0, ASSERT_LINE, 0xff); - m_irq_off_timer->adjust(m_maincpu->clocks_to_attotime(32 * (1 << (m_regs[SYS_CONFIG] & 0x03)))); - } - break; + m_maincpu->set_input_line_and_vector(0, ASSERT_LINE, 0xfd); + // Not quite precise. Scanline can't be skipped. + m_irq_off_timer->adjust(m_maincpu->clocks_to_attotime(32 * (1 << (m_regs[SYS_CONFIG] & 0x03)))); } - case TIMER_IRQ_SCANLINE: + if (BIT(m_regs[INT_MASK], 0) && OFFS_512(VS_INT_L) == screen_vpos && m_regs[HS_INT] == 0) { - u16 screen_vpos = m_screen->vpos(); - m_line_irq_timer->adjust(m_screen->time_until_pos(screen_vpos + 1)); - if (BIT(m_regs[INT_MASK], 1)) - { - m_maincpu->set_input_line_and_vector(0, ASSERT_LINE, 0xfd); - // Not quite precise. Scanline can't be skipped. - m_irq_off_timer->adjust(m_maincpu->clocks_to_attotime(32 * (1 << (m_regs[SYS_CONFIG] & 0x03)))); - } - if (BIT(m_regs[INT_MASK], 0) && OFFS_512(VS_INT_L) == screen_vpos && m_regs[HS_INT] == 0) - { - m_maincpu->set_input_line_and_vector(0, ASSERT_LINE, 0xff); - m_irq_off_timer->adjust(m_maincpu->clocks_to_attotime(32 * (1 << (m_regs[SYS_CONFIG] & 0x03)))); - } + m_maincpu->set_input_line_and_vector(0, ASSERT_LINE, 0xff); + m_irq_off_timer->adjust(m_maincpu->clocks_to_attotime(32 * (1 << (m_regs[SYS_CONFIG] & 0x03)))); + } - m_screen->update_now(); - for (const auto &[reg, val] : m_scanline_delayed_regs_update) + m_screen->update_now(); + for (const auto &[reg, val] : m_scanline_delayed_regs_update) + { + m_regs[reg] = val; + switch (reg) { - m_regs[reg] = val; - switch (reg) - { - case G_Y_OFFS_L: - case G_Y_OFFS_H: - m_gfx_y_frame_offset = get_screen_area().top() - m_screen->vpos(); - break; + case G_Y_OFFS_L: + case G_Y_OFFS_H: + m_gfx_y_frame_offset = get_screen_area().top() - m_screen->vpos(); + break; - default: - break; - } + default: + break; } - m_scanline_delayed_regs_update.clear(); - break; - } - default: - spectrum_state::device_timer(timer, id, param); } + m_scanline_delayed_regs_update.clear(); } u8 tsconf_state::beta_neutral_r(offs_t offset) diff --git a/src/mame/machine/tv955kb.cpp b/src/mame/machine/tv955kb.cpp index 4ad8e08431e..aaaf968bebe 100644 --- a/src/mame/machine/tv955kb.cpp +++ b/src/mame/machine/tv955kb.cpp @@ -40,7 +40,7 @@ void tv955kb_device::device_resolve_objects() void tv955kb_device::device_start() { - m_bell_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(tv955kb_device::bell_q8), this)); + m_bell_timer = timer_alloc(FUNC(tv955kb_device::bell_q8), this); save_item(NAME(m_bell_on)); diff --git a/src/mame/machine/upd65031.cpp b/src/mame/machine/upd65031.cpp index cc4b33e90d2..9811769901d 100644 --- a/src/mame/machine/upd65031.cpp +++ b/src/mame/machine/upd65031.cpp @@ -305,9 +305,9 @@ void upd65031_device::device_start() m_out_mem_cb.resolve(); // allocate timers - m_rtc_timer = timer_alloc(TIMER_RTC); - m_flash_timer = timer_alloc(TIMER_FLASH); - m_speaker_timer = timer_alloc(TIMER_SPEAKER); + m_rtc_timer = timer_alloc(FUNC(upd65031_device::rtc_tick), this); + m_flash_timer = timer_alloc(FUNC(upd65031_device::flash_tick), this); + m_speaker_timer = timer_alloc(FUNC(upd65031_device::speaker_tick), this); m_rtc_timer->adjust(attotime::from_msec(5), 0, attotime::from_msec(5)); m_flash_timer->adjust(attotime::from_hz(2), 0, attotime::from_hz(2)); m_speaker_timer->reset(); @@ -380,116 +380,104 @@ void upd65031_device::device_reset() //------------------------------------------------- -// device_timer - handler timer events +// timer events //------------------------------------------------- -void upd65031_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(upd65031_device::rtc_tick) { - switch (id) + // if a key is pressed sets the interrupt + if ((m_int & INT_GINT) && (m_int & INT_KEY) && m_read_kb(0) != 0xff) { - case TIMER_RTC: + LOG("%s: Keyboard interrupt!\n", machine().describe_context()); - // if a key is pressed sets the interrupt - if ((m_int & INT_GINT) && (m_int & INT_KEY) && m_read_kb(0) != 0xff) - { - LOG("%s: Keyboard interrupt!\n", machine().describe_context()); - - // awakes CPU from snooze on key down - if (m_mode == STATE_SNOOZE) - set_mode(STATE_AWAKE); + // awakes CPU from snooze on key down + if (m_mode == STATE_SNOOZE) + set_mode(STATE_AWAKE); - m_sta |= STA_KEY; - } - else - { - m_sta &= ~STA_KEY; - } + m_sta |= STA_KEY; + } + else + { + m_sta &= ~STA_KEY; + } - // hold clock at reset? - in this mode it doesn't update - if (!(m_com & COM_RESTIM)) - { - bool irq_change = false; + // hold clock at reset? - in this mode it doesn't update + if (!(m_com & COM_RESTIM)) + { + bool irq_change = false; - // update 5 millisecond counter - m_tim[0]++; + // update 5 millisecond counter + m_tim[0]++; - // tick - if (m_tim[0] & 1) + // tick + if (m_tim[0] & 1) + { + // set tick int has occurred + if (m_tmk & TSTA_TICK) { - // set tick int has occurred - if (m_tmk & TSTA_TICK) - { - m_tsta |= TSTA_TICK; - irq_change = true; - } + m_tsta |= TSTA_TICK; + irq_change = true; } + } + + if (m_tim[0] == 200) + { + m_tim[0] = 0; + m_tim[1]++; - if (m_tim[0] == 128) // on the rising edge of TIM0 bit 7 + if (m_tim[1] == 32) // on the rising edge of TIM1 bit 5 { - // set seconds int has occurred - if (m_tmk & TSTA_SEC) + // set minutes int has occurred + if (m_tmk & TSTA_MIN) { - m_tsta |= TSTA_SEC; + m_tsta |= TSTA_MIN; irq_change = true; } } - if (m_tim[0] == 200) + if (m_tim[1] == 60) { - m_tim[0] = 0; - m_tim[1]++; + m_tim[1] = 0; + m_tim[2]++; - if (m_tim[1] == 32) // on the rising edge of TIM1 bit 5 + if (m_tim[2] == 0) // overflowed from 255 { - // set minutes int has occurred - if (m_tmk & TSTA_MIN) - { - m_tsta |= TSTA_MIN; - irq_change = true; - } - } - - if (m_tim[1] == 60) - { - m_tim[1] = 0; - m_tim[2]++; + m_tim[3]++; - if (m_tim[2] == 0) // overflowed from 255 + if (m_tim[3] == 0) // overflowed from 255 { - m_tim[3]++; + m_tim[4]++; - if (m_tim[3] == 0) // overflowed from 255 - { - m_tim[4]++; - - if (m_tim[4] == 32) - m_tim[4] = 0; - } + if (m_tim[4] == 32) + m_tim[4] = 0; } } } + } - if ((m_int & INT_GINT) && (m_int & INT_TIME) && irq_change && !(m_sta & STA_FLAPOPEN)) - { - set_mode(STATE_AWAKE); - - update_rtc_interrupt(); - } + if ((m_int & INT_GINT) && (m_int & INT_TIME) && irq_change && !(m_sta & STA_FLAPOPEN)) + { + set_mode(STATE_AWAKE); - // refresh interrupt - interrupt_refresh(); + update_rtc_interrupt(); } - break; - case TIMER_FLASH: - m_flash = !m_flash; - break; - case TIMER_SPEAKER: - m_speaker_state = !m_speaker_state; - m_write_spkr(m_speaker_state ? 1 : 0); - break; + + // refresh interrupt + interrupt_refresh(); } } +TIMER_CALLBACK_MEMBER(upd65031_device::flash_tick) +{ + m_flash = !m_flash; +} + +TIMER_CALLBACK_MEMBER(upd65031_device::speaker_tick) +{ + m_speaker_state = !m_speaker_state; + m_write_spkr(m_speaker_state ? 1 : 0); +} + //------------------------------------------------- // screen_update diff --git a/src/mame/machine/upd65031.h b/src/mame/machine/upd65031.h index 70436c53366..427ba877408 100644 --- a/src/mame/machine/upd65031.h +++ b/src/mame/machine/upd65031.h @@ -58,7 +58,10 @@ 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(rtc_tick); + TIMER_CALLBACK_MEMBER(flash_tick); + TIMER_CALLBACK_MEMBER(speaker_tick); virtual void tra_callback() override; virtual void tra_complete() override; @@ -70,9 +73,6 @@ private: inline void update_uart_interrupt(); inline void update_tx(int state); inline void set_mode(int mode); - static const device_timer_id TIMER_RTC = 0; - static const device_timer_id TIMER_FLASH = 1; - static const device_timer_id TIMER_SPEAKER = 2; devcb_read8 m_read_kb; devcb_write_line m_write_int; diff --git a/src/mame/machine/vectrex.cpp b/src/mame/machine/vectrex.cpp index b73eed6e20c..e37b90339a4 100644 --- a/src/mame/machine/vectrex.cpp +++ b/src/mame/machine/vectrex.cpp @@ -46,48 +46,27 @@ static const double crazy_coaster_angles[3] = {0, 0.1631, 0.3305}; static const double unknown_game_angles[3] = {0,0.16666666, 0.33333333}; +TIMER_CALLBACK_MEMBER(vectrex_base_state::update_analog) +{ + update_vector(); + m_analog[param] = m_via_out[PORTA]; +} +TIMER_CALLBACK_MEMBER(vectrex_base_state::update_blank) +{ + update_vector(); + m_blank = param; +} -void vectrex_base_state::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(vectrex_base_state::update_mux_enable) { - switch (id) - { - case TIMER_VECTREX_IMAGER_CHANGE_COLOR: - vectrex_imager_change_color(param); - break; - case TIMER_UPDATE_LEVEL: - update_level(param); - break; - case TIMER_VECTREX_IMAGER_EYE: - vectrex_imager_eye(param); - break; - case TIMER_LIGHTPEN_TRIGGER: - lightpen_trigger(param); - break; - case TIMER_VECTREX_REFRESH: - vectrex_refresh(param); - break; - case TIMER_VECTREX_ZERO_INTEGRATORS: - vectrex_zero_integrators(param); - break; - case TIMER_UPDATE_ANALOG: - update_vector(); - m_analog[param] = m_via_out[PORTA]; - break; - case TIMER_UPDATE_BLANK: - update_vector(); - m_blank = param; - break; - case TIMER_UPDATE_MUX_ENABLE: - update_vector(); - break; - case TIMER_UPDATE_RAMP: - update_vector(); - m_ramp = param; - break; - default: - fatalerror("Unknown id in vectrex_base_state::device_timer"); - } + update_vector(); +} + +TIMER_CALLBACK_MEMBER(vectrex_base_state::update_ramp) +{ + update_vector(); + m_ramp = param; } @@ -104,7 +83,7 @@ void vectrex_base_state::configure_imager(bool reset_refresh, const double *imag m_imager_angles = imager_angles; } -void vectrex_base_state::vectrex_configuration() +void vectrex_base_state::screen_configuration() { unsigned char cport = m_io_3dconf->read(); @@ -116,7 +95,7 @@ void vectrex_base_state::vectrex_configuration() if (m_imager_status == 0) m_imager_status = cport & 0x01; - vector_add_point_function = cport & 0x02 ? &vectrex_base_state::vectrex_add_point_stereo: &vectrex_base_state::vectrex_add_point; + vector_add_point_function = cport & 0x02 ? &vectrex_base_state::add_point_stereo: &vectrex_base_state::add_point; switch ((cport >> 2) & 0x07) { @@ -179,7 +158,7 @@ void vectrex_base_state::vectrex_configuration() } else { - vector_add_point_function = &vectrex_base_state::vectrex_add_point; + vector_add_point_function = &vectrex_base_state::add_point; m_beam_color = rgb_t::white(); m_imager_colors[0] = m_imager_colors[1] = m_imager_colors[2] = m_imager_colors[3] = m_imager_colors[4] = m_imager_colors[5] = rgb_t::white(); } @@ -193,13 +172,13 @@ void vectrex_base_state::vectrex_configuration() *********************************************************************/ -WRITE_LINE_MEMBER(vectrex_base_state::vectrex_via_irq) +WRITE_LINE_MEMBER(vectrex_base_state::via_irq) { m_maincpu->set_input_line(M6809_IRQ_LINE, state); } -uint8_t vectrex_base_state::vectrex_via_pb_r() +uint8_t vectrex_base_state::via_pb_r() { int pot = m_io_contr[(m_via_out[PORTB] & 0x6) >> 1]->read() - 0x80; @@ -212,7 +191,7 @@ uint8_t vectrex_base_state::vectrex_via_pb_r() } -uint8_t vectrex_base_state::vectrex_via_pa_r() +uint8_t vectrex_base_state::via_pa_r() { if ((!(m_via_out[PORTB] & 0x10)) && (m_via_out[PORTB] & 0x08)) /* BDIR inactive, we can read the PSG. BC1 has to be active. */ @@ -224,7 +203,7 @@ uint8_t vectrex_base_state::vectrex_via_pa_r() } -uint8_t raaspec_state::vectrex_s1_via_pb_r() +uint8_t raaspec_state::s1_via_pb_r() { return (m_via_out[PORTB] & ~0x40) | (m_io_coin->read() & 0x40); } @@ -236,7 +215,7 @@ uint8_t raaspec_state::vectrex_s1_via_pb_r() *********************************************************************/ -TIMER_CALLBACK_MEMBER(vectrex_base_state::vectrex_imager_change_color) +TIMER_CALLBACK_MEMBER(vectrex_base_state::imager_change_color) { m_beam_color = param; } @@ -247,46 +226,47 @@ TIMER_CALLBACK_MEMBER(vectrex_base_state::update_level) m_imager_pinlevel = param; } +TIMER_CALLBACK_MEMBER(vectrex_base_state::imager_eye) +{ + if (m_imager_status > 0) + { + const int coffset = param > 1 ? 3: 0; + const double rtime = (1.0 / m_imager_freq); + + m_imager_status = param; + m_imager_color_timers[0]->adjust(attotime::from_double(rtime * m_imager_angles[0]), m_imager_colors[coffset+2]); + m_imager_color_timers[1]->adjust(attotime::from_double(rtime * m_imager_angles[1]), m_imager_colors[coffset+1]); + m_imager_color_timers[2]->adjust(attotime::from_double(rtime * m_imager_angles[2]), m_imager_colors[coffset]); + } +} -TIMER_CALLBACK_MEMBER(vectrex_base_state::vectrex_imager_eye) +TIMER_CALLBACK_MEMBER(vectrex_base_state::imager_index) { - int coffset; - double rtime = (1.0 / m_imager_freq); + imager_eye(param); if (m_imager_status > 0) { - m_imager_status = param; - coffset = param > 1? 3: 0; - timer_set(attotime::from_double(rtime * m_imager_angles[0]), TIMER_VECTREX_IMAGER_CHANGE_COLOR, m_imager_colors[coffset+2]); - timer_set(attotime::from_double(rtime * m_imager_angles[1]), TIMER_VECTREX_IMAGER_CHANGE_COLOR, m_imager_colors[coffset+1]); - timer_set(attotime::from_double(rtime * m_imager_angles[2]), TIMER_VECTREX_IMAGER_CHANGE_COLOR, m_imager_colors[coffset]); + const double rtime = (1.0 / m_imager_freq); - if (param == 2) - { - timer_set(attotime::from_double(rtime * 0.50), TIMER_VECTREX_IMAGER_EYE, 1); + m_imager_eye_timer->adjust(attotime::from_double(rtime * 0.50), 1); - /* Index hole sensor is connected to IO7 which triggers also CA1 of VIA */ - m_via6522_0->write_ca1(1); - m_via6522_0->write_ca1(0); - m_imager_pinlevel |= 0x80; - timer_set(attotime::from_double(rtime / 360.0), TIMER_UPDATE_LEVEL, 0); - } + /* Index hole sensor is connected to IO7 which triggers also CA1 of VIA */ + m_via6522_0->write_ca1(1); + m_via6522_0->write_ca1(0); + m_imager_pinlevel |= 0x80; + m_imager_level_timer->adjust(attotime::from_double(rtime / 360.0)); } } - -void vectrex_base_state::vectrex_psg_port_w(uint8_t data) +void vectrex_base_state::psg_port_w(uint8_t data) { - double wavel, ang_acc, tmp; - int mcontrol; - - mcontrol = data & 0x40; /* IO6 controls the imager motor */ + uint8_t mcontrol = data & 0x40; /* IO6 controls the imager motor */ if (!mcontrol && mcontrol ^ m_old_mcontrol) { m_old_mcontrol = mcontrol; - tmp = machine().time().as_double(); - wavel = tmp - m_sl; + double tmp = machine().time().as_double(); + double wavel = tmp - m_sl; m_sl = tmp; if (wavel < 1) @@ -297,15 +277,14 @@ void vectrex_base_state::vectrex_psg_port_w(uint8_t data) of the whole thing and some constants of the motor's torque/speed curve. pwl is the negative pulse width and wavel is the whole wavelength. */ - ang_acc = (50.0 - 1.55 * m_imager_freq) / MMI; + double ang_acc = (50.0 - 1.55 * m_imager_freq) / MMI; m_imager_freq += ang_acc * m_pwl + DAMPC * m_imager_freq / MMI * wavel; if (m_imager_freq > 1) { - m_imager_timer->adjust( - attotime::from_double(std::min(1.0 / m_imager_freq, m_imager_timer->remaining().as_double())), - 2, - attotime::from_double(1.0 / m_imager_freq)); + attotime eye_time = attotime::from_double(std::min(1.0 / m_imager_freq, m_imager_eye_timer->remaining().as_double())); + attotime eye_period = attotime::from_double(1.0 / m_imager_freq); + m_imager_eye_timer->adjust(eye_time, 2, eye_period); } } } diff --git a/src/mame/machine/victor9k_fdc.cpp b/src/mame/machine/victor9k_fdc.cpp index 413fe8373a0..a2c305e2989 100644 --- a/src/mame/machine/victor9k_fdc.cpp +++ b/src/mame/machine/victor9k_fdc.cpp @@ -49,14 +49,16 @@ // MACROS / CONSTANTS //************************************************************************** -#define LOG 0 -#define LOG_VIA 0 +#define LOG_VIA (1U << 1) +#define LOG_SCP (1U << 2) +#define LOG_BITS (1U << 3) + #ifdef USE_SCP -#define LOG_SCP 1 +#define VERBOSE (LOG_SCP) #else -#define LOG_SCP 0 +#define VERBOSE (0) #endif -#define LOG_BITS 0 +#include "logmacro.h" #define I8048_TAG "5d" #define M6522_4_TAG "1f" @@ -269,9 +271,9 @@ void victor_9000_fdc_device::device_start() m_lbrdy_cb.resolve_safe(); // allocate timer - t_gen = timer_alloc(TM_GEN); - t_tach0 = timer_alloc(TM_TACH0); - t_tach1 = timer_alloc(TM_TACH1); + t_gen = timer_alloc(FUNC(victor_9000_fdc_device::gen_tick), this); + t_tach0 = timer_alloc(FUNC(victor_9000_fdc_device::tach0_tick), this); + t_tach1 = timer_alloc(FUNC(victor_9000_fdc_device::tach1_tick), this); // state saving save_item(NAME(m_da)); @@ -338,28 +340,25 @@ void victor_9000_fdc_device::device_reset() //------------------------------------------------- -// device_timer - handler timer events +// timer events //------------------------------------------------- -void victor_9000_fdc_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(victor_9000_fdc_device::gen_tick) { - switch (id) - { - case TM_GEN: - live_sync(); - live_run(); - break; + live_sync(); + live_run(); +} - case TM_TACH0: - m_tach0 = !m_tach0; - if (LOG_SCP) logerror("%s TACH0 %u\n", machine().time().as_string(), m_tach0); - break; +TIMER_CALLBACK_MEMBER(victor_9000_fdc_device::tach0_tick) +{ + m_tach0 = !m_tach0; + LOGMASKED(LOG_SCP, "%s TACH0 %u\n", machine().time().as_string(), m_tach0); +} - case TM_TACH1: - m_tach1 = !m_tach1; - if (LOG_SCP) logerror("%s TACH1 %u\n", machine().time().as_string(), m_tach1); - break; - } +TIMER_CALLBACK_MEMBER(victor_9000_fdc_device::tach1_tick) +{ + m_tach1 = !m_tach1; + LOGMASKED(LOG_SCP, "%s TACH1 %u\n", machine().time().as_string(), m_tach1); } @@ -491,7 +490,7 @@ void victor_9000_fdc_device::floppy_p2_w(uint8_t data) m_scp_rdy1 = BIT(data, 7); update_rdy(); - if (LOG_SCP) logerror("%s %s START0/STOP0/SEL0/RDY0 %u/%u/%u/%u START1/STOP1/SEL1/RDY1 %u/%u/%u/%u\n", machine().time().as_string(), machine().describe_context(), start0, stop0, sel0, m_rdy0, start1, stop1, sel1, m_rdy1); + LOGMASKED(LOG_SCP, "%s %s START0/STOP0/SEL0/RDY0 %u/%u/%u/%u START1/STOP1/SEL1/RDY1 %u/%u/%u/%u\n", machine().time().as_string(), machine().describe_context(), start0, stop0, sel0, m_rdy0, start1, stop1, sel1, m_rdy1); if (sync) { @@ -511,11 +510,15 @@ void victor_9000_fdc_device::floppy_p2_w(uint8_t data) checkpoint(); - if ((m_floppy0->get_device() && !m_floppy0->get_device()->mon_r()) || (m_floppy1->get_device() && !m_floppy1->get_device()->mon_r())) { - if(cur_live.state == IDLE) { + if ((m_floppy0->get_device() && !m_floppy0->get_device()->mon_r()) || (m_floppy1->get_device() && !m_floppy1->get_device()->mon_r())) + { + if(cur_live.state == IDLE) + { live_start(); } - } else { + } + else + { live_abort(); } @@ -530,7 +533,7 @@ void victor_9000_fdc_device::floppy_p2_w(uint8_t data) READ_LINE_MEMBER(victor_9000_fdc_device::tach0_r) { - if (LOG_SCP) logerror("%s %s Read TACH0 %u\n", machine().time().as_string(), machine().describe_context(), m_tach0); + LOGMASKED(LOG_SCP, "%s %s Read TACH0 %u\n", machine().time().as_string(), machine().describe_context(), m_tach0); return m_tach0; } @@ -541,7 +544,7 @@ READ_LINE_MEMBER(victor_9000_fdc_device::tach0_r) READ_LINE_MEMBER(victor_9000_fdc_device::tach1_r) { - if (LOG_SCP) logerror("%s %s Read TACH1 %u\n", machine().time().as_string(), machine().describe_context(), m_tach1); + LOGMASKED(LOG_SCP, "%s %s Read TACH1 %u\n", machine().time().as_string(), machine().describe_context(), m_tach1); return m_tach1; } @@ -579,12 +582,15 @@ void victor_9000_fdc_device::update_stepper_motor(floppy_image_device *floppy, i void victor_9000_fdc_device::update_spindle_motor(floppy_image_device *floppy, emu_timer *t_tach, bool start, bool stop, bool sel, uint8_t &da) { #ifdef USE_SCP - if (start && !stop && floppy->mon_r()) { - if (LOG_SCP) logerror("%s: motor start\n", floppy->tag()); + if (start && !stop && floppy->mon_r()) + { + LOGMASKED(LOG_SCP, "%s: motor start\n", floppy->tag()); floppy->mon_w(0); t_tach->enable(true); - } else if (stop && !floppy->mon_r()) { - if (LOG_SCP) logerror("%s: motor stop\n", floppy->tag()); + } + else if (stop && !floppy->mon_r()) + { + LOGMASKED(LOG_SCP, "%s: motor stop\n", floppy->tag()); floppy->mon_w(1); t_tach->enable(false); } @@ -594,12 +600,13 @@ void victor_9000_fdc_device::update_spindle_motor(floppy_image_device *floppy, e void victor_9000_fdc_device::update_rpm(floppy_image_device *floppy, emu_timer *t_tach, bool sel, uint8_t &da) { #ifdef USE_SCP - if (sel) { + if (sel) + { da = m_da; float tach = rpm[da] / 60.0 * SPINDLE_RATIO * MOTOR_POLES; - if (LOG_SCP) logerror("%s: motor speed %u rpm / tach %0.1f hz %0.9f s (DA %02x)\n", floppy->tag(), rpm[da], (double) tach, 1.0/(double)tach, da); + LOGMASKED(LOG_SCP, "%s: motor speed %u rpm / tach %0.1f hz %0.9f s (DA %02x)\n", floppy->tag(), rpm[da], (double) tach, 1.0/(double)tach, da); floppy->set_rpm(rpm[da]); @@ -623,7 +630,7 @@ void victor_9000_fdc_device::update_rdy() void victor_9000_fdc_device::da_w(uint8_t data) { - if (LOG_SCP) logerror("%s %s DA %02x SEL0 %u SEL1 %u\n", machine().time().as_string(), machine().describe_context(), data, m_sel0, m_sel1); + LOGMASKED(LOG_SCP, "%s %s DA %02x SEL0 %u SEL1 %u\n", machine().time().as_string(), machine().describe_context(), data, m_sel0, m_sel1); live_sync(); m_da = data; @@ -673,20 +680,19 @@ void victor_9000_fdc_device::via4_pa_w(uint8_t data) m_via_l0ms = data & 0x0f; #ifndef USE_SCP - { // HACK to bypass SCP - if (m_floppy0->get_device()) - { - m_floppy0->get_device()->mon_w((m_via_l0ms == 0xf) ? 1 : 0); - m_floppy0->get_device()->set_rpm(victor9k_format::get_rpm(m_side, m_floppy0->get_device()->get_cyl())); - } - m_rdy0 = (m_via_l0ms == 0xf) ? 0 : 1; - update_rdy(); + // HACK to bypass SCP + if (m_floppy0->get_device()) + { + m_floppy0->get_device()->mon_w((m_via_l0ms == 0xf) ? 1 : 0); + m_floppy0->get_device()->set_rpm(victor9k_format::get_rpm(m_side, m_floppy0->get_device()->get_cyl())); } + m_rdy0 = (m_via_l0ms == 0xf) ? 0 : 1; + update_rdy(); #endif uint8_t st0 = data >> 4; - if (LOG_VIA) logerror("%s %s L0MS %01x ST0 %01x\n", machine().time().as_string(), machine().describe_context(), m_via_l0ms, st0); + LOGMASKED(LOG_VIA, "%s %s L0MS %01x ST0 %01x\n", machine().time().as_string(), machine().describe_context(), m_via_l0ms, st0); if (m_st0 != st0) { @@ -738,20 +744,19 @@ void victor_9000_fdc_device::via4_pb_w(uint8_t data) m_via_l1ms = data & 0x0f; #ifndef USE_SCP - { // HACK to bypass SCP - if (m_floppy1->get_device()) - { - m_floppy1->get_device()->mon_w((m_via_l1ms == 0xf) ? 1 : 0); - m_floppy1->get_device()->set_rpm(victor9k_format::get_rpm(m_side, m_floppy1->get_device()->get_cyl())); - } - m_rdy1 = (m_via_l1ms == 0xf) ? 0 : 1; - update_rdy(); + // HACK to bypass SCP + if (m_floppy1->get_device()) + { + m_floppy1->get_device()->mon_w((m_via_l1ms == 0xf) ? 1 : 0); + m_floppy1->get_device()->set_rpm(victor9k_format::get_rpm(m_side, m_floppy1->get_device()->get_cyl())); } + m_rdy1 = (m_via_l1ms == 0xf) ? 0 : 1; + update_rdy(); #endif uint8_t st1 = data >> 4; - if (LOG_VIA) logerror("%s %s L1MS %01x ST1 %01x\n", machine().time().as_string(), machine().describe_context(), m_via_l1ms, st1); + LOGMASKED(LOG_VIA, "%s %s L1MS %01x ST1 %01x\n", machine().time().as_string(), machine().describe_context(), m_via_l1ms, st1); if (m_st1 != st1) { @@ -771,7 +776,7 @@ WRITE_LINE_MEMBER( victor_9000_fdc_device::wrsync_w ) m_wrsync = state; cur_live.wrsync = state; checkpoint(); - if (LOG_VIA) logerror("%s %s WRSYNC %u\n", machine().time().as_string(), machine().describe_context(), state); + LOGMASKED(LOG_VIA, "%s %s WRSYNC %u\n", machine().time().as_string(), machine().describe_context(), state); live_run(); } } @@ -820,7 +825,7 @@ void victor_9000_fdc_device::via5_pb_w(uint8_t data) */ - if (LOG_VIA) logerror("%s %s WD %02x\n", machine().time().as_string(), machine().describe_context(), data); + LOGMASKED(LOG_VIA, "%s %s WD %02x\n", machine().time().as_string(), machine().describe_context(), data); m_via5->write_cb1(BIT(data, 7)); @@ -858,7 +863,7 @@ uint8_t victor_9000_fdc_device::via6_pa_r() */ - if (LOG_VIA) logerror("%s %s TRK0D0 %u TRK0D1 %u SYNC %u\n", machine().time().as_string(), machine().describe_context(), m_floppy0->get_device() ? m_floppy0->get_device()->trk00_r() : 0, m_floppy1->get_device() ? m_floppy1->get_device()->trk00_r() : 0, checkpoint_live.sync); + LOGMASKED(LOG_VIA, "%s %s TRK0D0 %u TRK0D1 %u SYNC %u\n", machine().time().as_string(), machine().describe_context(), m_floppy0->get_device() ? m_floppy0->get_device()->trk00_r() : 0, m_floppy1->get_device() ? m_floppy1->get_device()->trk00_r() : 0, checkpoint_live.sync); uint8_t data = 0; @@ -904,11 +909,13 @@ void victor_9000_fdc_device::via6_pa_w(uint8_t data) // dual side select int side = BIT(data, 4); - if (m_side != side) sync = true; + if (m_side != side) + sync = true; // select drive A/B int drive = BIT(data, 5); - if (m_drive != drive) sync = true; + if (m_drive != drive) + sync = true; if (sync) { @@ -916,13 +923,15 @@ void victor_9000_fdc_device::via6_pa_w(uint8_t data) m_side = side; cur_live.side = side; - if (m_floppy0->get_device()) m_floppy0->get_device()->ss_w(side); - if (m_floppy1->get_device()) m_floppy1->get_device()->ss_w(side); + if (m_floppy0->get_device()) + m_floppy0->get_device()->ss_w(side); + if (m_floppy1->get_device()) + m_floppy1->get_device()->ss_w(side); m_drive = drive; cur_live.drive = drive; - if (LOG_VIA) logerror("%s %s SIDE %u DRIVE %u\n", machine().time().as_string(), machine().describe_context(), side, drive); + LOGMASKED(LOG_VIA, "%s %s SIDE %u DRIVE %u\n", machine().time().as_string(), machine().describe_context(), side, drive); checkpoint(); live_run(); @@ -995,11 +1004,13 @@ void victor_9000_fdc_device::via6_pb_w(uint8_t data) // stepper enable A int stp0 = BIT(data, 6); - if (m_stp0 != stp0) sync = true; + if (m_stp0 != stp0) + sync = true; // stepper enable B int stp1 = BIT(data, 7); - if (m_stp1 != stp1) sync = true; + if (m_stp1 != stp1) + sync = true; m_via6->write_cb1(stp1); if (sync) @@ -1007,12 +1018,14 @@ void victor_9000_fdc_device::via6_pb_w(uint8_t data) live_sync(); m_stp0 = stp0; - if (m_floppy0->get_device()) update_stepper_motor(m_floppy0->get_device(), m_stp0, m_st0, m_st0); + if (m_floppy0->get_device()) + update_stepper_motor(m_floppy0->get_device(), m_stp0, m_st0, m_st0); m_stp1 = stp1; - if (m_floppy1->get_device()) update_stepper_motor(m_floppy1->get_device(), m_stp1, m_st1, m_st1); + if (m_floppy1->get_device()) + update_stepper_motor(m_floppy1->get_device(), m_stp1, m_st1, m_st1); - if (LOG_VIA) logerror("%s %s STP0 %u STP1 %u\n", machine().time().as_string(), machine().describe_context(), stp0, stp1); + LOGMASKED(LOG_VIA, "%s %s STP0 %u STP1 %u\n", machine().time().as_string(), machine().describe_context(), stp0, stp1); checkpoint(); live_run(); @@ -1026,10 +1039,13 @@ WRITE_LINE_MEMBER( victor_9000_fdc_device::drw_w ) live_sync(); m_drw = cur_live.drw = state; checkpoint(); - if (LOG_VIA) logerror("%s %s DRW %u\n", machine().time().as_string(), machine().describe_context(), state); - if (state) { + LOGMASKED(LOG_VIA, "%s %s DRW %u\n", machine().time().as_string(), machine().describe_context(), state); + if (state) + { pll_stop_writing(get_floppy(), machine().time()); - } else { + } + else + { pll_start_writing(machine().time()); } live_run(); @@ -1043,7 +1059,7 @@ WRITE_LINE_MEMBER( victor_9000_fdc_device::erase_w ) live_sync(); m_erase = cur_live.erase = state; checkpoint(); - if (LOG_VIA) logerror("%s %s ERASE %u\n", machine().time().as_string(), machine().describe_context(), state); + LOGMASKED(LOG_VIA, "%s %s ERASE %u\n", machine().time().as_string(), machine().describe_context(), state); live_run(); } } @@ -1059,7 +1075,7 @@ uint8_t victor_9000_fdc_device::cs7_r(offs_t offset) { m_lbrdy_cb(1); - if (LOG_VIA) logerror("%s %s LBRDY 1 : %02x\n", machine().time().as_string(), machine().describe_context(), m_via5->read(offset)); + LOGMASKED(LOG_VIA, "%s %s LBRDY 1 : %02x\n", machine().time().as_string(), machine().describe_context(), m_via5->read(offset)); return m_via5->read(offset); } @@ -1068,7 +1084,7 @@ void victor_9000_fdc_device::cs7_w(offs_t offset, uint8_t data) { m_lbrdy_cb(1); - if (LOG_VIA) logerror("%s %s LBRDY 1\n", machine().time().as_string(), machine().describe_context()); + LOGMASKED(LOG_VIA, "%s %s LBRDY 1\n", machine().time().as_string(), machine().describe_context()); m_via5->write(offset, data); } @@ -1171,18 +1187,24 @@ void victor_9000_fdc_device::live_delay(int state) void victor_9000_fdc_device::live_sync() { - if(!cur_live.tm.is_never()) { - if(cur_live.tm > machine().time()) { + if(!cur_live.tm.is_never()) + { + if(cur_live.tm > machine().time()) + { rollback(); live_run(machine().time()); pll_commit(get_floppy(), cur_live.tm); - } else { + } + else + { pll_commit(get_floppy(), cur_live.tm); - if(cur_live.next_state != -1) { + if(cur_live.next_state != -1) + { cur_live.state = cur_live.next_state; cur_live.next_state = -1; } - if(cur_live.state == IDLE) { + if(cur_live.state == IDLE) + { pll_stop_writing(get_floppy(), cur_live.tm); cur_live.tm = attotime::never; } @@ -1194,7 +1216,8 @@ void victor_9000_fdc_device::live_sync() void victor_9000_fdc_device::live_abort() { - if(!cur_live.tm.is_never() && cur_live.tm > machine().time()) { + if(!cur_live.tm.is_never() && cur_live.tm > machine().time()) + { rollback(); live_run(machine().time()); } @@ -1218,9 +1241,12 @@ void victor_9000_fdc_device::live_run(const attotime &limit) if(cur_live.state == IDLE || cur_live.next_state != -1) return; - for(;;) { - switch(cur_live.state) { - case RUNNING: { + for(;;) + { + switch(cur_live.state) + { + case RUNNING: + { bool syncpoint = false; if (cur_live.tm > limit) @@ -1228,7 +1254,8 @@ void victor_9000_fdc_device::live_run(const attotime &limit) // read bit int bit = 0; - if (cur_live.drw) { + if (cur_live.drw) + { bit = pll_get_next_bit(cur_live.tm, get_floppy(), limit); if(bit < 0) return; @@ -1236,7 +1263,8 @@ void victor_9000_fdc_device::live_run(const attotime &limit) // write bit int write_bit = 0; - if (!cur_live.drw) { // TODO WPS + if (!cur_live.drw) // TODO WPS + { write_bit = BIT(cur_live.shift_reg_write, 9); if (pll_write_next_bit(write_bit, cur_live.tm, get_floppy(), limit)) return; @@ -1251,32 +1279,45 @@ void victor_9000_fdc_device::live_run(const attotime &limit) int sync = !(cur_live.shift_reg == 0x3ff); // bit counter - if (cur_live.drw) { - if (!sync) { + if (cur_live.drw) + { + if (!sync) + { cur_live.bit_counter = 0; - } else if (cur_live.sync) { + } + else if (cur_live.sync) + { cur_live.bit_counter++; - if (cur_live.bit_counter == 10) { + if (cur_live.bit_counter == 10) + { cur_live.bit_counter = 0; } } - } else { + } + else + { cur_live.bit_counter++; - if (cur_live.bit_counter == 10) { + if (cur_live.bit_counter == 10) + { cur_live.bit_counter = 0; } } // sync counter - if (sync) { + if (sync) + { cur_live.sync_bit_counter = 0; cur_live.sync_byte_counter = 10; // TODO 9 in schematics - } else if (!cur_live.sync) { + } + else if (!cur_live.sync) + { cur_live.sync_bit_counter++; - if (cur_live.sync_bit_counter == 10) { + if (cur_live.sync_bit_counter == 10) + { cur_live.sync_bit_counter = 0; cur_live.sync_byte_counter++; - if (cur_live.sync_byte_counter == 16) { + if (cur_live.sync_byte_counter == 16) + { cur_live.sync_byte_counter = 0; } } @@ -1286,16 +1327,19 @@ void victor_9000_fdc_device::live_run(const attotime &limit) int syn = !(cur_live.sync_byte_counter == 15); // GCR decoder - if (cur_live.drw) { + if (cur_live.drw) + { cur_live.i = cur_live.drw << 10 | cur_live.shift_reg; - } else { + } + else + { cur_live.i = cur_live.drw << 10 | 0x200 | ((cur_live.wd & 0xf0) << 1) | cur_live.wrsync << 4 | (cur_live.wd & 0x0f); } cur_live.e = m_gcr_rom->base()[cur_live.i]; attotime next = cur_live.tm + m_period; - if (LOG) logerror("%s:%s cyl %u bit %u sync %u bc %u sr %03x sbc %u sBC %u syn %u i %03x e %02x\n",cur_live.tm.as_string(),next.as_string(),get_floppy()->get_cyl(),bit,sync,cur_live.bit_counter,cur_live.shift_reg,cur_live.sync_bit_counter,cur_live.sync_byte_counter,syn,cur_live.i,cur_live.e); + LOGMASKED(LOG_GENERAL, "%s:%s cyl %u bit %u sync %u bc %u sr %03x sbc %u sBC %u syn %u i %03x e %02x\n",cur_live.tm.as_string(),next.as_string(),get_floppy()->get_cyl(),bit,sync,cur_live.bit_counter,cur_live.shift_reg,cur_live.sync_bit_counter,cur_live.sync_byte_counter,syn,cur_live.i,cur_live.e); // byte ready int brdy = !(cur_live.bit_counter == 9); @@ -1303,69 +1347,77 @@ void victor_9000_fdc_device::live_run(const attotime &limit) // GCR error int gcr_err = !(brdy || BIT(cur_live.e, 3)); - if (LOG_BITS) { - if (cur_live.drw) { - logerror("%s cyl %u bit %u sync %u bc %u sr %03x i %03x e %02x\n",cur_live.tm.as_string(),get_floppy()->get_cyl(),bit,sync,cur_live.bit_counter,cur_live.shift_reg,cur_live.i,cur_live.e); - } else { - logerror("%s cyl %u writing bit %u bc %u sr %03x i %03x e %02x\n",cur_live.tm.as_string(),get_floppy()->get_cyl(),write_bit,cur_live.bit_counter,cur_live.shift_reg_write,cur_live.i,cur_live.e); - } - } + if (cur_live.drw) + LOGMASKED(LOG_BITS, "%s cyl %u bit %u sync %u bc %u sr %03x i %03x e %02x\n",cur_live.tm.as_string(),get_floppy()->get_cyl(),bit,sync,cur_live.bit_counter,cur_live.shift_reg,cur_live.i,cur_live.e); + else + LOGMASKED(LOG_BITS, "%s cyl %u writing bit %u bc %u sr %03x i %03x e %02x\n",cur_live.tm.as_string(),get_floppy()->get_cyl(),write_bit,cur_live.bit_counter,cur_live.shift_reg_write,cur_live.i,cur_live.e); - if (!brdy) { + if (!brdy) + { // load write shift register cur_live.shift_reg_write = GCR_ENCODE(cur_live.e, cur_live.i); - if (LOG) logerror("%s load write shift register %03x\n",cur_live.tm.as_string(),cur_live.shift_reg_write); - } else { + LOGMASKED(LOG_GENERAL, "%s load write shift register %03x\n",cur_live.tm.as_string(),cur_live.shift_reg_write); + } + else + { // clock write shift register cur_live.shift_reg_write <<= 1; cur_live.shift_reg_write &= 0x3ff; } - if (brdy != cur_live.brdy) { - if (LOG) logerror("%s BRDY %u\n", cur_live.tm.as_string(),brdy); + if (brdy != cur_live.brdy) + { + LOGMASKED(LOG_GENERAL, "%s BRDY %u\n", cur_live.tm.as_string(),brdy); if (!brdy) { cur_live.lbrdy_changed = true; - if (LOG_VIA) logerror("%s LBRDY 0 : %02x\n", cur_live.tm.as_string(), GCR_DECODE(cur_live.e, cur_live.i)); + LOGMASKED(LOG_VIA, "%s LBRDY 0 : %02x\n", cur_live.tm.as_string(), GCR_DECODE(cur_live.e, cur_live.i)); } cur_live.brdy = brdy; syncpoint = true; } - if (sync != cur_live.sync) { - if (LOG) logerror("%s SYNC %u\n", cur_live.tm.as_string(),sync); + if (sync != cur_live.sync) + { + LOGMASKED(LOG_GENERAL, "%s SYNC %u\n", cur_live.tm.as_string(),sync); cur_live.sync = sync; syncpoint = true; } - if (syn != cur_live.syn) { - if (LOG) logerror("%s SYN %u\n", cur_live.tm.as_string(),syn); + if (syn != cur_live.syn) + { + LOGMASKED(LOG_GENERAL, "%s SYN %u\n", cur_live.tm.as_string(),syn); cur_live.syn = syn; cur_live.syn_changed = true; syncpoint = true; } - if (gcr_err != cur_live.gcr_err) { - if (LOG) logerror("%s GCR ERR %u\n", cur_live.tm.as_string(),gcr_err); + if (gcr_err != cur_live.gcr_err) + { + LOGMASKED(LOG_GENERAL, "%s GCR ERR %u\n", cur_live.tm.as_string(),gcr_err); cur_live.gcr_err = gcr_err; syncpoint = true; } - if (syncpoint) { + if (syncpoint) + { live_delay(RUNNING_SYNCPOINT); return; } break; } - case RUNNING_SYNCPOINT: { - if (cur_live.lbrdy_changed) { + case RUNNING_SYNCPOINT: + { + if (cur_live.lbrdy_changed) + { m_lbrdy_cb(0); cur_live.lbrdy_changed = false; } - if (cur_live.syn_changed) { + if (cur_live.syn_changed) + { m_syn_cb(cur_live.syn); cur_live.syn_changed = false; } diff --git a/src/mame/machine/victor9k_fdc.h b/src/mame/machine/victor9k_fdc.h index 67105ba4318..6f91f426d48 100644 --- a/src/mame/machine/victor9k_fdc.h +++ b/src/mame/machine/victor9k_fdc.h @@ -46,12 +46,15 @@ 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; // optional information overrides virtual const tiny_rom_entry *device_rom_region() const override; virtual void device_add_mconfig(machine_config &config) override; + TIMER_CALLBACK_MEMBER(gen_tick); + TIMER_CALLBACK_MEMBER(tach0_tick); + TIMER_CALLBACK_MEMBER(tach1_tick); + private: static const int rpm[0x100]; @@ -59,13 +62,6 @@ private: enum { - TM_GEN, - TM_TACH0, - TM_TACH1 - }; - - enum - { LED_A = 0, LED_B }; diff --git a/src/mame/machine/vino.cpp b/src/mame/machine/vino.cpp index ef9d72acc68..5de93c7fb78 100644 --- a/src/mame/machine/vino.cpp +++ b/src/mame/machine/vino.cpp @@ -49,8 +49,8 @@ vino_device::vino_device(const machine_config &mconfig, const char *tag, device_ void vino_device::device_start() { - m_channels[0].m_fetch_timer = timer_alloc(TIMER_FETCH_CHA); - m_channels[1].m_fetch_timer = timer_alloc(TIMER_FETCH_CHB); + m_channels[0].m_fetch_timer = timer_alloc(FUNC(vino_device::fetch_pixel<0>), this); + m_channels[1].m_fetch_timer = timer_alloc(FUNC(vino_device::fetch_pixel<1>), this); save_item(NAME(m_rev_id)); save_item(NAME(m_control)); @@ -146,12 +146,6 @@ void vino_device::device_add_mconfig(machine_config &config) IMAGE_AVIVIDEO(config, m_avivideo); } -void vino_device::device_timer(emu_timer &timer, device_timer_id id, int param) -{ - if (id == TIMER_FETCH_CHA || id == TIMER_FETCH_CHB) - fetch_pixel((int)id); -} - uint32_t vino_device::read(offs_t offset, uint32_t mem_mask) { switch (offset & ~1) @@ -800,26 +794,27 @@ void vino_device::input_pixel(int channel, int32_t &y, int32_t &u, int32_t &v) } } -void vino_device::fetch_pixel(int channel) +template <int Channel> +TIMER_CALLBACK_MEMBER(vino_device::fetch_pixel) { - channel_t &chan = m_channels[channel]; + channel_t &chan = m_channels[Channel]; if (chan.m_decimation > 1 && (chan.m_field_x % chan.m_decimation) != 0) { - count_pixel(channel); + count_pixel(Channel); return; } if (BIT(chan.m_frame_mask_shifter, 0)) { int32_t y = 0, u = 0, v = 0; - input_pixel(channel, y, u, v); - process_pixel(channel, y, u, v); + input_pixel(Channel, y, u, v); + process_pixel(Channel, y, u, v); } else { - count_pixel(channel); + count_pixel(Channel); if (chan.m_end_of_field) { - end_of_field(channel); + end_of_field(Channel); chan.m_end_of_field = false; } } diff --git a/src/mame/machine/vino.h b/src/mame/machine/vino.h index f88e406bc38..bec1474421d 100644 --- a/src/mame/machine/vino.h +++ b/src/mame/machine/vino.h @@ -37,12 +37,8 @@ protected: virtual void device_start() override; virtual void device_reset() override; virtual void device_add_mconfig(machine_config &config) override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; private: - static constexpr device_timer_id TIMER_FETCH_CHA = 0; - static constexpr device_timer_id TIMER_FETCH_CHB = 1; - enum channel_num_t : uint32_t { CHAN_A, @@ -218,7 +214,7 @@ private: uint32_t linear_rgb(uint32_t a, uint32_t b, float f); uint32_t bilinear_pixel(float s, float t); void input_pixel(int channel, int32_t &y, int32_t &u, int32_t &v); - void fetch_pixel(int channel); + template <int Channel> TIMER_CALLBACK_MEMBER(fetch_pixel); attotime calculate_field_rate(int channel); attotime calculate_fetch_rate(int channel); diff --git a/src/mame/machine/vsnes.cpp b/src/mame/machine/vsnes.cpp index a406ef4b3b2..b3d9b7d1269 100644 --- a/src/mame/machine/vsnes.cpp +++ b/src/mame/machine/vsnes.cpp @@ -549,7 +549,7 @@ void vsnes_state::init_vsdual() //********************************************************************************** // Vs. Super Mario Bros (Bootleg) -void vsnes_state::vsnes_bootleg_scanline(int scanline, int vblank, int blanked) +void vsnes_state::vsnes_bootleg_scanline(int scanline, bool vblank, bool blanked) { // Z80 IRQ is controlled by two factors: // - bit 6 of current (next) scanline number diff --git a/src/mame/machine/wpc.cpp b/src/mame/machine/wpc.cpp index 987d75c6258..9647a526192 100644 --- a/src/mame/machine/wpc.cpp +++ b/src/mame/machine/wpc.cpp @@ -43,7 +43,7 @@ void wpc_device::device_start() m_bank_w.resolve_safe(); m_dmdbank_w.resolve_safe(); - m_zc_timer = timer_alloc(TIMER_ZEROCROSS); + m_zc_timer = timer_alloc(FUNC(wpc_device::zerocross_set), this); m_zc_timer->adjust(attotime::from_hz(120),0,attotime::from_hz(120)); } @@ -55,14 +55,9 @@ void wpc_device::device_reset() m_alpha_pos = 0; } -void wpc_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(wpc_device::zerocross_set) { - switch(id) - { - case TIMER_ZEROCROSS: - m_zerocross = true; - break; - } + m_zerocross = true; } uint8_t wpc_device::read(offs_t offset) diff --git a/src/mame/machine/wpc.h b/src/mame/machine/wpc.h index 8a87278bacf..014dbb19f9c 100644 --- a/src/mame/machine/wpc.h +++ b/src/mame/machine/wpc.h @@ -78,9 +78,6 @@ class wpc_device : public device_t { public: - static constexpr device_timer_id TIMER_IRQ = 1; - static constexpr device_timer_id TIMER_ZEROCROSS = 2; - wpc_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock); uint8_t read(offs_t offset); @@ -111,7 +108,7 @@ 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; + TIMER_CALLBACK_MEMBER(zerocross_set); private: uint8_t m_shift_addr_high; diff --git a/src/mame/machine/wpc_lamp.cpp b/src/mame/machine/wpc_lamp.cpp index 8aaa2455285..1222d98c24c 100644 --- a/src/mame/machine/wpc_lamp.cpp +++ b/src/mame/machine/wpc_lamp.cpp @@ -23,11 +23,19 @@ void wpc_lamp_device::set_names(const char *const *_names) void wpc_lamp_device::update() { - for(int i=0; i<8; i++) - if(row & (1 << i)) - for(int j=0; j<8; j++) - if(col & (1 << j)) - state[(j<<3)|i] |= 0x80; + for (int i = 0; i < 8; i++) + { + if (row & (1 << i)) + { + for (int j = 0; j < 8; j++) + { + if (BIT(col, j)) + { + state[(j << 3) | i] |= 0x80; + } + } + } + } } void wpc_lamp_device::row_w(uint8_t data) @@ -48,7 +56,7 @@ void wpc_lamp_device::device_start() save_item(NAME(col)); save_item(NAME(row)); - timer = timer_alloc(0); + timer = timer_alloc(FUNC(wpc_lamp_device::update_lamps), this); } void wpc_lamp_device::device_reset() @@ -57,14 +65,16 @@ void wpc_lamp_device::device_reset() timer->adjust(attotime::from_hz(60), 0, attotime::from_hz(60)); } -void wpc_lamp_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(wpc_lamp_device::update_lamps) { - for(int i=0; i<64; i++) { + for (int i = 0; i < 64; i++) + { uint8_t s = state[i]; state[i] = s >> 1; - if((s & 0xc0) == 0x40 || (s & 0xc0) == 0x80) { + if ((s & 0xc0) == 0x40 || (s & 0xc0) == 0x80) + { char buffer[256]; - if(names && names[i]) + if (names && names[i]) sprintf(buffer, "l:%s", names[i]); else sprintf(buffer, "l:%d%d", 1+(i >> 3), 1 + (i & 7)); diff --git a/src/mame/machine/wpc_lamp.h b/src/mame/machine/wpc_lamp.h index 64f9b535b8a..1e32196e44d 100644 --- a/src/mame/machine/wpc_lamp.h +++ b/src/mame/machine/wpc_lamp.h @@ -20,16 +20,18 @@ public: void set_names(const char *const *lamp_names); protected: - uint8_t state[64]{}; - uint8_t col = 0, row = 0; - emu_timer *timer = nullptr; - const char *const *names; - 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_lamps); void update(); + + uint8_t state[64]{}; + uint8_t col = 0; + uint8_t row = 0; + emu_timer *timer = nullptr; + const char *const *names; }; DECLARE_DEVICE_TYPE(WPC_LAMP, wpc_lamp_device) diff --git a/src/mame/machine/wpc_out.cpp b/src/mame/machine/wpc_out.cpp index 9de9b6988ac..3f0ceef78ac 100644 --- a/src/mame/machine/wpc_out.cpp +++ b/src/mame/machine/wpc_out.cpp @@ -36,9 +36,13 @@ void wpc_out_device::gi_update() attotime now = machine().time(); attotime delta = now - previous_gi_update; uint32_t delta_us = delta.as_ticks(1e6); - for(int i=0; i<gi_count; i++) - if(gi & (1 <<i)) + for (int i = 0; i < gi_count; i++) + { + if (BIT(gi, i)) + { gi_time[i] += delta_us; + } + } previous_gi_update = now; } @@ -49,15 +53,18 @@ void wpc_out_device::send_output(int sid, int state) char buffer[32]; const char *name; - if(names && names[sid-1] && strcmp(names[sid-1], "s:")) - name = names[sid-1]; - else { + if (names && names[sid - 1] && strcmp(names[sid - 1], "s:")) + { + name = names[sid - 1]; + } + else + { sprintf(buffer, "u:output %02d", sid); name = buffer; } machine().output().set_value(name, state); - if(sid == 41) + if (sid == 41) machine().bookkeeping().coin_counter_w(0, state); } @@ -66,28 +73,33 @@ void wpc_out_device::out_w(offs_t offset, uint8_t data) first_after_led = false; uint8_t diff = state[offset] ^ data; state[offset] = data; - if(diff) - for(int i=0; i<8; i++) - if(diff & (1 << i)) { + if (diff) + { + for (int i = 0; i < 8; i++) + { + if (BIT(diff, i)) + { int id = (offset << 3) | i; int sid; - if(id <= 3) + if (id <= 3) sid = id + 25; - else if(id <= 7) + else if (id <= 7) sid = id + 33; - else if(id <= 15) - sid = id-7; - else if(id <= 23) - sid = id+1; - else if(id <= 31) - sid = id-15; - else if(id <= 39) - sid = id-3; + else if (id <= 15) + sid = id - 7; + else if (id <= 23) + sid = id + 1; + else if (id <= 31) + sid = id - 15; + else if (id <= 39) + sid = id - 3; else - sid = id+2; + sid = id + 2; - send_output(sid, (data & (1<<i)) != 0); + send_output(sid, BIT(data, i)); } + } + } } void wpc_out_device::out4_w(uint8_t data) @@ -119,7 +131,7 @@ void wpc_out_device::device_start() save_item(NAME(previous_gi_update)); save_item(NAME(gi_time)); - timer = timer_alloc(0); + timer = timer_alloc(FUNC(wpc_out_device::update_outputs), this); } void wpc_out_device::device_reset() @@ -132,10 +144,11 @@ void wpc_out_device::device_reset() timer->adjust(attotime::from_hz(10), 0, attotime::from_hz(10)); } -void wpc_out_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(wpc_out_device::update_outputs) { gi_update(); - for(int i=0; i<gi_count; i++) { + for (int i = 0; i < gi_count; i++) + { // fprintf(stderr, "gi[%d] = %d\n", i, gi_time[i]); gi_time[i] = 0; } diff --git a/src/mame/machine/wpc_out.h b/src/mame/machine/wpc_out.h index a45cd05d98b..e51a9722161 100644 --- a/src/mame/machine/wpc_out.h +++ b/src/mame/machine/wpc_out.h @@ -32,6 +32,15 @@ public: void set_gi_count(int _count); protected: + virtual void device_start() override; + virtual void device_reset() override; + + TIMER_CALLBACK_MEMBER(update_outputs); + + void gi_update(); + + void send_output(int sid, int state); + uint8_t state[6]{}, gi = 0; bool first_after_led = false; attotime previous_gi_update; @@ -40,14 +49,6 @@ protected: emu_timer *timer = nullptr; const char *const *names; handler_t handler_cb; - - void send_output(int sid, int state); - - virtual void device_start() override; - virtual void device_reset() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; - - void gi_update(); }; DECLARE_DEVICE_TYPE(WPC_OUT, wpc_out_device) diff --git a/src/mame/machine/x68k_hdc.cpp b/src/mame/machine/x68k_hdc.cpp index d3f108cb40b..f4e74b08c22 100644 --- a/src/mame/machine/x68k_hdc.cpp +++ b/src/mame/machine/x68k_hdc.cpp @@ -41,7 +41,7 @@ void x68k_hdc_image_device::device_start() m_status = 0x00; m_status_port = 0x00; m_phase = sasi_phase::BUSFREE; - m_req_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(x68k_hdc_image_device::req_timer_callback), this)); + m_req_timer = timer_alloc(FUNC(x68k_hdc_image_device::req_timer_callback), this); save_item(NAME(m_phase)); save_item(NAME(m_status_port)); diff --git a/src/mame/machine/xavix.cpp b/src/mame/machine/xavix.cpp index 317e5a3ee9e..d56ef68366e 100644 --- a/src/mame/machine/xavix.cpp +++ b/src/mame/machine/xavix.cpp @@ -784,12 +784,12 @@ void xavix_state::machine_start() // don't do this every reset or it breaks the baseball 2 secret mode toggle which flips a bit in RAM std::fill_n(&m_mainram[0], 0x4000 - nvram_size, 0xff); - m_interrupt_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(xavix_state::interrupt_gen), this)); - m_freq_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(xavix_state::freq_timer_done), this)); + m_interrupt_timer = timer_alloc(FUNC(xavix_state::interrupt_gen), this); + m_freq_timer = timer_alloc(FUNC(xavix_state::freq_timer_done), this); for (int i = 0; i < 4; i++) { - m_sound_timer[i] = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(xavix_state::sound_timer_done), this)); + m_sound_timer[i] = timer_alloc(FUNC(xavix_state::sound_timer_done), this); } if (m_nvram) diff --git a/src/mame/machine/xavix_adc.cpp b/src/mame/machine/xavix_adc.cpp index 527f6d542e2..e1271e39e47 100644 --- a/src/mame/machine/xavix_adc.cpp +++ b/src/mame/machine/xavix_adc.cpp @@ -33,7 +33,7 @@ void xavix_adc_device::device_start() m_in6_cb.resolve_safe(0xff); m_in7_cb.resolve_safe(0xff); - m_adc_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(xavix_adc_device::adc_timer_done), this)); + m_adc_timer = timer_alloc(FUNC(xavix_adc_device::adc_timer_done), this); save_item(NAME(m_adc_control)); save_item(NAME(m_adc_inlatch)); diff --git a/src/mame/machine/xavix_madfb_ball.cpp b/src/mame/machine/xavix_madfb_ball.cpp index 48b76ecdc68..b773460c990 100644 --- a/src/mame/machine/xavix_madfb_ball.cpp +++ b/src/mame/machine/xavix_madfb_ball.cpp @@ -77,7 +77,7 @@ ioport_constructor xavix_madfb_ball_device::device_input_ports() const void xavix_madfb_ball_device::device_start() { m_event_out_cb.resolve_safe(); - m_event_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(xavix_madfb_ball_device::event_timer), this)); + m_event_timer = timer_alloc(FUNC(xavix_madfb_ball_device::event_timer), this); } void xavix_madfb_ball_device::device_reset() diff --git a/src/mame/machine/xavix_mtrk_wheel.cpp b/src/mame/machine/xavix_mtrk_wheel.cpp index 7816bf3b06c..ad3e8b7982e 100644 --- a/src/mame/machine/xavix_mtrk_wheel.cpp +++ b/src/mame/machine/xavix_mtrk_wheel.cpp @@ -75,7 +75,7 @@ ioport_constructor xavix_mtrk_wheel_device::device_input_ports() const void xavix_mtrk_wheel_device::device_start() { m_event_out_cb.resolve_safe(); - m_event_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(xavix_mtrk_wheel_device::event_timer), this)); + m_event_timer = timer_alloc(FUNC(xavix_mtrk_wheel_device::event_timer), this); } void xavix_mtrk_wheel_device::device_reset() diff --git a/src/mame/machine/xbox_pci.cpp b/src/mame/machine/xbox_pci.cpp index 6027ab02591..b2d1f125cd7 100644 --- a/src/mame/machine/xbox_pci.cpp +++ b/src/mame/machine/xbox_pci.cpp @@ -722,7 +722,7 @@ void mcpx_ohci_device::device_start() m_interrupt_handler(state); } ); - timer = timer_alloc(0); + timer = timer_alloc(FUNC(mcpx_ohci_device::usb_update), this); ohci_usb->set_timer(timer); ohci_usb->start(); for (int i=0;i < connecteds_count;i++) @@ -757,10 +757,10 @@ void mcpx_ohci_device::device_config_complete() } } -void mcpx_ohci_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(mcpx_ohci_device::usb_update) { if (ohci_usb) - ohci_usb->timer(timer, id, param); + ohci_usb->timer(param); } uint32_t mcpx_ohci_device::ohci_r(offs_t offset) @@ -874,7 +874,7 @@ void mcpx_apu_device::device_start() memset(apust.voices_position_end, 0, sizeof(apust.voices_position_end)); memset(apust.voices_position_increment, 0, sizeof(apust.voices_position_increment)); apust.space = &cpu->space(); - apust.timer = timer_alloc(0); + apust.timer = timer_alloc(FUNC(mcpx_apu_device::audio_update), this); apust.timer->enable(false); } @@ -883,30 +883,25 @@ void mcpx_apu_device::device_reset() pci_device::device_reset(); } -void mcpx_apu_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(mcpx_apu_device::audio_update) { - int cmd; - int bb, b, v; - uint64_t bv; - uint32_t phys; - // this works only for outr2 // value at 0x810 is modified by the firmware that has been loaded on the gp dsp - cmd = apust.space->read_dword(apust.gpdsp_address + 0x800 + 0x10); + int cmd = apust.space->read_dword(apust.gpdsp_address + 0x800 + 0x10); if (cmd == 3) apust.space->write_dword(apust.gpdsp_address + 0x800 + 0x10, 0); /*else logerror("Audio_APU: unexpected value at address %d\n",apust.gpdsp_address+0x800+0x10);*/ // check all the 256 possible voices - for (b = 0; b < 4; b++) { - bv = 1; - for (bb = 0; bb < 64; bb++) { + for (int b = 0; b < 4; b++) { + uint64_t bv = 1; + for (int bb = 0; bb < 64; bb++) { if (apust.voices_active[b] & bv) { - v = bb + (b << 6); + int v = bb + (b << 6); apust.voices_position[v] += apust.voices_position_increment[v]; while (apust.voices_position[v] >= apust.voices_position_end[v]) apust.voices_position[v] = apust.voices_position_start[v] + apust.voices_position[v] - apust.voices_position_end[v] - 1000; - phys = apust.voicedata_address + 0x80 * v; + uint32_t phys = apust.voicedata_address + 0x80 * v; apust.space->write_dword(phys + 0x58, apust.voices_position[v] / 1000); } bv = bv << 1; diff --git a/src/mame/machine/xbox_usb.cpp b/src/mame/machine/xbox_usb.cpp index 5b2dca2be6e..aefa352a12a 100644 --- a/src/mame/machine/xbox_usb.cpp +++ b/src/mame/machine/xbox_usb.cpp @@ -220,9 +220,8 @@ void ohci_usb_controller::write(offs_t offset, uint32_t data) ohcist.hc_regs[offset] = data; } -void ohci_usb_controller::timer(emu_timer &timer, device_timer_id id, int param) +void ohci_usb_controller::timer(int param) { - uint32_t hcca; uint32_t plh; int changed = 0; int list = 1; @@ -230,7 +229,7 @@ void ohci_usb_controller::timer(emu_timer &timer, device_timer_id id, int param) bool retire = false; int pid, remain, mps, done; - hcca = ohcist.hc_regs[HcHCCA]; + uint32_t hcca = ohcist.hc_regs[HcHCCA]; if (ohcist.state == UsbOperational) { // increment frame number ohcist.framenumber = (ohcist.framenumber + 1) & 0xffff; diff --git a/src/mame/machine/z80ne.cpp b/src/mame/machine/z80ne.cpp index e2159af8010..5cdc78a3727 100644 --- a/src/mame/machine/z80ne.cpp +++ b/src/mame/machine/z80ne.cpp @@ -30,7 +30,7 @@ cassette_image_device* z80ne_state::cassette_device_image() return m_cassette1; } -TIMER_CALLBACK_MEMBER(z80ne_state::z80ne_cassette_tc) +TIMER_CALLBACK_MEMBER(z80ne_state::cassette_tc) { uint8_t cass_ws = 0; m_cass_data.input.length++; @@ -100,7 +100,7 @@ void z80netf_state::driver_init() } -TIMER_CALLBACK_MEMBER(z80ne_state::z80ne_kbd_scan) +TIMER_CALLBACK_MEMBER(z80ne_state::kbd_scan) { /* * NE555 is connected to a 74LS93 binary counter @@ -144,16 +144,9 @@ TIMER_CALLBACK_MEMBER(z80ne_state::z80ne_kbd_scan) } } -void z80ne_state::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(z80ne_state::pulse_nmi) { - switch (id) - { - case 0: - m_maincpu->pulse_input_line(INPUT_LINE_NMI, attotime::zero); - break; - default: - printf("Invalid timer %d encountered\n",id); - } + m_maincpu->pulse_input_line(INPUT_LINE_NMI, attotime::zero); } void z80net_state::reset_lx387() @@ -342,13 +335,13 @@ INPUT_CHANGED_MEMBER(z80net_state::z80net_nmi) void z80ne_state::machine_start() { - m_timer_nmi = timer_alloc(0); + m_timer_nmi = timer_alloc(FUNC(z80ne_state::pulse_nmi), this); m_lx383_digits.resolve(); m_lx385_ctrl = 0x1f; - m_cassette_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(z80ne_state::z80ne_cassette_tc), this)); - m_kbd_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(z80ne_state::z80ne_kbd_scan), this)); + m_cassette_timer = timer_alloc(FUNC(z80ne_state::cassette_tc), this); + m_kbd_timer = timer_alloc(FUNC(z80ne_state::kbd_scan), this); m_kbd_timer->adjust(attotime::from_hz(1000), 0, attotime::from_hz(1000)); } diff --git a/src/mame/machine/z88_impexp.cpp b/src/mame/machine/z88_impexp.cpp index 431fae75197..fbbdf8f80ad 100644 --- a/src/mame/machine/z88_impexp.cpp +++ b/src/mame/machine/z88_impexp.cpp @@ -51,7 +51,7 @@ z88_impexp_device::z88_impexp_device(const machine_config &mconfig, const char * void z88_impexp_device::device_start() { - m_timer_poll = timer_alloc(); + m_timer_poll = timer_alloc(FUNC(z88_impexp_device::poll_queue), this); } //------------------------------------------------- @@ -74,10 +74,10 @@ void z88_impexp_device::device_reset() } //------------------------------------------------- -// device_timer - handler timer events +// poll_queue - periodically update the queue //------------------------------------------------- -void z88_impexp_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(z88_impexp_device::poll_queue) { queue(); } diff --git a/src/mame/machine/z88_impexp.h b/src/mame/machine/z88_impexp.h index 67a818467bf..c73bc04a041 100644 --- a/src/mame/machine/z88_impexp.h +++ b/src/mame/machine/z88_impexp.h @@ -27,7 +27,6 @@ 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; // device_serial_interface overrides virtual void tra_callback() override; @@ -47,6 +46,8 @@ protected: virtual const char *image_type_name() const noexcept override { return "serial"; } virtual const char *image_brief_type_name() const noexcept override { return "serl"; } + TIMER_CALLBACK_MEMBER(poll_queue); + private: void check_filename(std::string &filename); void queue(); diff --git a/src/mame/machine/znmcu.cpp b/src/mame/machine/znmcu.cpp index a008ae0f954..75288a8af79 100644 --- a/src/mame/machine/znmcu.cpp +++ b/src/mame/machine/znmcu.cpp @@ -28,7 +28,7 @@ void znmcu_device::device_start() m_dataout_handler.resolve_safe(); m_dsr_handler.resolve_safe(); - m_mcu_timer = timer_alloc(0); + m_mcu_timer = timer_alloc(FUNC(znmcu_device::mcu_tick), this); m_dataout_handler(1); m_dsr_handler(1); @@ -96,7 +96,7 @@ WRITE_LINE_MEMBER(znmcu_device::write_clock) } } -void znmcu_device::device_timer(emu_timer &timer, device_timer_id tid, int param) +TIMER_CALLBACK_MEMBER(znmcu_device::mcu_tick) { m_dsr_handler(param); diff --git a/src/mame/machine/znmcu.h b/src/mame/machine/znmcu.h index f956ae87115..60166999897 100644 --- a/src/mame/machine/znmcu.h +++ b/src/mame/machine/znmcu.h @@ -26,7 +26,8 @@ public: 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(mcu_tick); private: devcb_read8 m_dsw_handler; diff --git a/src/mame/machine/zx.cpp b/src/mame/machine/zx.cpp index cd00c2673b8..cf08590c0fa 100644 --- a/src/mame/machine/zx.cpp +++ b/src/mame/machine/zx.cpp @@ -14,7 +14,7 @@ void zx_state::init_zx() { m_program = &m_maincpu->space(AS_PROGRAM); - m_tape_input = timer_alloc(TIMER_TAPE_INPUT); + m_tape_input = timer_alloc(FUNC(zx_state::zx_tape_input), this); if(m_ram->size() == 32768) m_program->unmap_readwrite(0x8000, 0xbfff); @@ -41,7 +41,7 @@ void zx_state::machine_reset() m_tape_input->adjust(attotime::from_hz(44100), 0, attotime::from_hz(44100)); } -void zx_state::zx_tape_input() +TIMER_CALLBACK_MEMBER(zx_state::zx_tape_input) { m_cassette_cur_level = m_cassette->input(); } diff --git a/src/mame/machine/zx8302.cpp b/src/mame/machine/zx8302.cpp index b2fd9acbfe2..49e0d9dde94 100644 --- a/src/mame/machine/zx8302.cpp +++ b/src/mame/machine/zx8302.cpp @@ -188,9 +188,9 @@ void zx8302_device::device_start() m_in_raw2_cb.resolve_safe(0); // allocate timers - m_baudx4_timer = timer_alloc(TIMER_BAUDX4); - m_rtc_timer = timer_alloc(TIMER_RTC); - m_gap_timer = timer_alloc(TIMER_GAP); + m_baudx4_timer = timer_alloc(FUNC(zx8302_device::baudx4_tick), this); + m_rtc_timer = timer_alloc(FUNC(zx8302_device::rtc_tick), this); + m_gap_timer = timer_alloc(FUNC(zx8302_device::trigger_gap_int), this); m_rtc_timer->adjust(attotime::zero, 0, attotime::from_hz(m_rtc_clock / 32768)); m_gap_timer->adjust(attotime::zero, 0, attotime::from_msec(31)); @@ -217,29 +217,23 @@ void zx8302_device::device_start() //------------------------------------------------- -// device_timer - handler timer events +// timer events //------------------------------------------------- -void zx8302_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(zx8302_device::baudx4_tick) { - switch (id) - { - case TIMER_BAUDX4: - m_baudx4 = !m_baudx4; - m_out_baudx4_cb(m_baudx4); - break; - - case TIMER_RTC: - m_ctr++; - break; + m_baudx4 = !m_baudx4; + m_out_baudx4_cb(m_baudx4); +} - case TIMER_GAP: - trigger_interrupt(INT_GAP); - break; +TIMER_CALLBACK_MEMBER(zx8302_device::rtc_tick) +{ + m_ctr++; +} - default: - break; - } +TIMER_CALLBACK_MEMBER(zx8302_device::trigger_gap_int) +{ + trigger_interrupt(INT_GAP); } diff --git a/src/mame/machine/zx8302.h b/src/mame/machine/zx8302.h index 7aa922a4b3a..5ec95729d17 100644 --- a/src/mame/machine/zx8302.h +++ b/src/mame/machine/zx8302.h @@ -89,7 +89,6 @@ public: protected: // device-level overrides virtual void device_start() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; // device_serial_interface overrides virtual void tra_callback() override; @@ -97,19 +96,16 @@ protected: virtual void rcv_callback() override; virtual void rcv_complete() override; + TIMER_CALLBACK_MEMBER(baudx4_tick); + TIMER_CALLBACK_MEMBER(rtc_tick); + TIMER_CALLBACK_MEMBER(trigger_gap_int); + inline void trigger_interrupt(uint8_t line); inline void transmit_ipc_data(); private: enum { - TIMER_BAUDX4 = 0, - TIMER_RTC, - TIMER_GAP - }; - - enum - { IPC_START, IPC_DATA, IPC_STOP |