diff options
author | MooglyGuy <MooglyGuy@users.noreply.github.com> | 2022-06-04 09:14:21 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-04 17:14:21 +1000 |
commit | 1bc5484698bb746c6f9f7dae58b005d2472f1215 (patch) | |
tree | 54d6a10bc728cc7ce9858d771788a595e324141c /src/devices | |
parent | cd83335913a6cfe4aa2db720692fa34487b1d7a3 (diff) |
- Removed device_timer, device_timer_id, et al in favor of direct callback members. (#9788)
Primarily, this removes device_t::device_timer, device_t::timer_set,
device_t::synchronize, device_t::timer_expired, and device_timer_id.
Use of device_timer often resulted in unnecessary trampolining in
addition to switch/case overhead on a driver/device level, and
additional logic to manage delegated vs. ID-based timers on a core
level. In the worst cases, devices were performing a switch/case with
only one valid case.
device_scheduler::timer_set is marked deprecated as the only remaining
direct uses are via the Lua engine and a few drivers that need
refactoring anyway. The remaining uses occur via
device_scheduler::synchronize.
As a middle ground between the extremely short timer_alloc() and the
extremely long
machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(widget_device::contoso_tick), this)),
a helper function in device_t has been added which can be invoked with
the following syntax:
timer_alloc(FUNC(widget_device::contoso_tick), this)
- Additional changes/cleanups performed along the way:
- Converted to use logmacro:
* src/devices/bus/ieee488/hp9895.cpp
* src/devices/bus/ieee488/remote488.cpp
* src/devices/bus/isa/hdc.cpp
* src/devices/bus/isa/omti8621.cpp
* src/devices/bus/isa/sc499.cpp
* src/devices/bus/vip/vp550.cpp
* src/devices/cpu/i86/i186.cpp
* src/devices/cpu/lc8670/lc8670.cpp
* src/devices/machine/68230pit.cpp
* src/devices/machine/corvushd.cpp
* src/devices/machine/ds1994.cpp
* src/devices/machine/ticket.cpp
* src/mame/audio/pinsnd88.cpp
* src/mame/drivers/notetaker.cpp
* src/mame/machine/asic65.cpp
* src/mame/machine/rmnimbus.cpp
* src/mame/machine/victor9k_fdc.cpp
* src/mame/video/uv201.cpp
- Made usage of m_member prefix consistent:
* src/devices/bus/isa/hdc.cpp
* src/devices/bus/isa/omti8621.cpp
* src/devices/bus/vme/vme_fccpu20.cpp
* src/devices/machine/ds1386.cpp
* src/devices/machine/i7220.cpp
- Spacing consistency pass:
* src/devices/bus/isa/hdc.cpp
* src/devices/bus/isa/omti8621.cpp
* src/devices/bus/thomson/nanoresau.cpp
* src/devices/bus/ti99/internal/992board.cpp
* src/devices/bus/ti99/internal/genkbd.cpp
* src/devices/bus/ti99/internal/joyport/handset.cpp
* src/devices/bus/vme/vme_fccpu20.cpp
* src/devices/cpu/i86/i186.cpp
* src/devices/cpu/lc8670/lc8670.cpp
* src/devices/machine/68230pit.cpp
* src/devices/machine/cop452.cpp
* src/devices/machine/corvushd.cpp
* src/devices/machine/hp_dc100_tape.cpp
* src/devices/machine/hp_taco.cpp
* src/devices/machine/meters.cpp
* src/devices/machine/microtch.cpp
* src/devices/machine/phi.cpp
* src/devices/video/ef9365.cpp
* src/devices/video/v9938.cpp
* src/mame/drivers/alphaskop41xx.cpp
* src/mame/drivers/myb3k.cpp
* src/mame/drivers/notetaker.cpp
* src/mame/drivers/wpc_an.cpp
* src/mame/machine/midikbd.cpp
* src/mame/machine/rmnimbus.cpp
* src/mame/machine/wpc_lamp.cpp
* src/mame/machine/wpc_out.cpp
- Removed string-based ioport lookups:
* src/devices/bus/ti99/internal/joyport/handset.cpp
* src/devices/bus/ti99/internal/joyport/mecmouse.cpp
* src/devices/bus/vme/vme_hcpu30.cpp
* src/mame/machine/k7659kb.cpp
* src/mame/machine/ti85.cpp
- Adjustments to grammar/wording in comments
* src/devices/bus/sms_ctrl/lphaser.cpp
* src/devices/bus/sms_ctrl/sports.cpp
* src/devices/bus/snes/event.cpp
* src/devices/bus/snes/sa1.cpp
* src/devices/bus/thomson/nanoresau.cpp
* src/devices/bus/z88/z88.cpp
* src/devices/machine/ds1386.cpp
* src/devices/machine/vic_pl192.cpp
- Favored BIT() macro for single-bit checks
* src/devices/bus/ti99/internal/992board.cpp
* src/devices/bus/ti99/joyport/handset.cpp
* src/mame/drivers/notetaker.cpp
* src/mame/machine/wpc_lamp.cpp
* src/mame/machine/wpc_out.cpp
- Removed C89-style variable declarations when noticed
* src/devices/bus/isa/hdc.cpp
* src/devices/bus/sms_ctrl/lphaser.cpp
* src/devices/bus/ti99/joyport/mecmouse.cpp
* src/devices/machine/acorn_vidc.cpp
* src/devices/sound/ymz280b.cpp
* src/devices/video/vic4567.cpp
- Removed FUNCNAME to avoid compiler-specific #define checks in devices
* src/devices/bus/vme/vme_fccpu20.cpp
* src/devices/bus/vme/vme_hcpu30.cpp
* src/devices/machine/68230pit.cpp
* src/devices/machine/mc14411.cpp
* src/mame/drivers/myb3k.cpp
- Removed unecessary member prefixes/suffixes
* src/devices/video/ef9340_1.cpp
* src/mame/drivers/fuukifg2.cpp
* src/mame/drivers/fuukifg3.cpp
* src/mame/drivers/intv.cpp
* src/mame/drivers/simpsons.cpp
* src/mame/drivers/socrates.cpp
* src/mame/drivers/special_gambl.cpp
* src/mame/drivers/sprint4.cpp
* src/mame/drivers/ti990_10.cpp
* src/mame/drivers/tubep.cpp
* src/mame/drivers/vectrex.cpp
* src/mame/drivers/wpc_an.cpp
* src/mame/drivers/wpc_dot.cpp
* src/mame/drivers/wpc_flip1.cpp
* src/mame/drivers/wpc_flip2.cpp
* src/mame/machine/z80ne.cpp
* src/mame/video/rollerg.cpp
- Switched to lower-case hex constants
* src/devices/video/ef9365.cpp
* src/mame/machine/rmnimbus.cpp
- Re-ordered driver overrides and function members
* src/mame/drivers/boxer.cpp
* src/mame/drivers/eurocom2.cpp
* src/mame/drivers/exidy.cpp
* src/mame/drivers/gpworld.cpp
* src/mame/drivers/h19.cpp
* src/mame/drivers/ibmpcjr.cpp
* src/mame/drivers/mekd5.cpp
* src/mame/drivers/mgolf.cpp
* src/mame/drivers/myb3k.cpp
* src/mame/drivers/nightmare.cpp
* src/mame/drivers/notetaker.cpp
* src/mame/drivers/ptcsol.cpp
* src/mame/drivers/pwrview.cpp
* src/mame/drivers/rabbit.cpp
* src/mame/drivers/sitcom.cpp
* src/mame/drivers/socrates.cpp
* src/mame/drivers/sprint4.cpp
* src/mame/drivers/techno.cpp
* src/mame/drivers/thayers.cpp
* src/mame/drivers/ti990_10.cpp
* src/mame/drivers/ti990_4.cpp
* src/mame/drivers/tv912.cpp
* src/mame/drivers/tv990.cpp
* src/mame/drivers/uchroma68.cpp
* src/mame/drivers/vk100.cpp
* src/mame/drivers/votrhv.cpp
* src/mame/drivers/wicat.cpp
* src/mame/drivers/wpc_an.cpp
* src/mame/includes/abc80.h
* src/mame/includes/asterix.h
* src/mame/includes/fuukifg2.h
* src/mame/includes/fuukifg3.h
* src/mame/includes/gunbustr.h
* src/mame/includes/intv.h
* src/mame/includes/namcona1.h
* src/mame/includes/newbrain.h
* src/mame/includes/poly.h
* src/mame/includes/prof80.h
* src/mame/includes/rollerg.h
* src/mame/includes/s11.h
* src/mame/includes/segahang.h
* src/mame/includes/simpsons.h
* src/mame/includes/spacefb.h
* src/mame/includes/tandy2k.h
* src/mame/includes/trucocl.h
* src/mame/includes/tubebp.h
* src/mame/includes/vidbrain.h
* src/mame/includes/wolfpack.h
* src/mame/includes/wpc_dot.h
- Made capitalization consistent on class members
* src/devices/machine/meters.cpp
* src/mame/drivers/namcona1.cpp
* src/mame/drivers/notetaker.cpp
-src/devices/bus/isa/hdc.cpp:
* Removed fixed-size std::vector in favor of std::unique_ptr
-src/devices/bus/isa/s3virge.cpp:
* Moved unusually large (for a header) functions into .cpp from header
-src/devices/bus/vip/vp550.cpp
* Switched to required_device_array to simplify code paths
-src/devices/machine/arm_iomd.cpp
* Added initializers to constructor
* Favored std::size over fixed static sizes
-src/devices/machine/ds1386.cpp
* Moved register #defines into header enums
-src/devices/machine/mc68901.cpp
* Removed unnecessary parameters and emu_timer::enable calls
-src/devices/machine/mccs1850.cpp
* Removed inline overuse
-src/devices/machine/meters.cpp
* Removed unused members
-src/devices/machine/mos6526.cpp
* Removed inline overuse
-src/devices/machine/nsc810.cpp
* Converted to arrays rather than individually-numbered members
-src/devices/machine/pxa255.cpp
* Simplified DMA transfer code
-src/devices/machine/saa1043.cpp
* Removed extraneous members in favor of resolve_all_safe
-src/devices/machine/vic_pl192.cpp
* Shifted constructors, start-up, and maps to be at the top of the source file
-src/devices/machine/z8536.cpp
* Removed stray uses of device_timer_id
-src/devices/sound/cdp1869.cpp
* Removed inline overuse
-src/devices/sound/mos7360.cpp
* Converted to arrays rather than individually-numbered members
-src/emu/device.cpp
* Removed ID-based timer_alloc
* Removed timer_set
* Removed synchronize
* Removed timer_expired
* Added shorthand timer_alloc to avoid lengthy machine().scheduler().timer_alloc() calls
-src/emu/schedule.cpp
* Removed now-unused m_id and m_device members
-src/mame/audio/alesis.cpp
* Added initializers to constructor
-src/mame/drivers/alto2.cpp
* Removed custom-named driver init in favor of driver_init override
* Removed octal constant in favor of more standard hex
-src/mame/drivers/astinvad.cpp
* Fixed 'kamizake' typo
-src/mame/drivers/tm990189.cpp
* Removed unnecessary machine reset override
-src/mame/drivers/unichamp.cpp
* Removed custom-named driver init in favor of driver_init override
-src/mame/drivers/votrhv.cpp
* Fixed ROM_LOAD macros and region() usage in memory maps
-src/mame/machine/victor9k_fdc.cpp
* Made bracing style consistent across the file
-src/mame/video/gime.cpp
* Removed unnecessary void specifiers in function prototypes
Diffstat (limited to 'src/devices')
855 files changed, 10657 insertions, 12276 deletions
diff --git a/src/devices/bus/a2bus/a2mcms.cpp b/src/devices/bus/a2bus/a2mcms.cpp index 7e154ad99f7..f23a647f4a8 100644 --- a/src/devices/bus/a2bus/a2mcms.cpp +++ b/src/devices/bus/a2bus/a2mcms.cpp @@ -207,8 +207,8 @@ void mcms_device::device_start() { m_write_irq.resolve(); m_stream = stream_alloc(0, 2, 31250); - m_timer = timer_alloc(0); - m_clrtimer = timer_alloc(1); + m_timer = timer_alloc(FUNC(mcms_device::set_irq_tick), this); + m_clrtimer = timer_alloc(FUNC(mcms_device::clr_irq_tick), this); m_enabled = false; memset(m_vols, 0, sizeof(m_vols)); memset(m_table, 0, sizeof(m_table)); @@ -238,18 +238,16 @@ void mcms_device::device_reset() m_enabled = false; } -void mcms_device::device_timer(emu_timer &timer, device_timer_id tid, int param) +TIMER_CALLBACK_MEMBER(mcms_device::set_irq_tick) { - if (tid == 0) - { - m_write_irq(ASSERT_LINE); - // clear this IRQ in 10 cycles (?) - m_clrtimer->adjust(attotime::from_usec(10), 0); - } - else if (tid == 1) - { - m_write_irq(CLEAR_LINE); - } + m_write_irq(ASSERT_LINE); + // clear this IRQ in 10 cycles (?) + m_clrtimer->adjust(attotime::from_usec(10), 0); +} + +TIMER_CALLBACK_MEMBER(mcms_device::clr_irq_tick) +{ + m_write_irq(CLEAR_LINE); } void mcms_device::sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) diff --git a/src/devices/bus/a2bus/a2mcms.h b/src/devices/bus/a2bus/a2mcms.h index f6244dfbf74..371c74c54fa 100644 --- a/src/devices/bus/a2bus/a2mcms.h +++ b/src/devices/bus/a2bus/a2mcms.h @@ -40,13 +40,16 @@ protected: // device-level overrides virtual void device_start() override; virtual void device_reset() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; virtual void sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) override; + TIMER_CALLBACK_MEMBER(set_irq_tick); + TIMER_CALLBACK_MEMBER(clr_irq_tick); + private: sound_stream *m_stream; - emu_timer *m_timer, *m_clrtimer; + emu_timer *m_timer; + emu_timer *m_clrtimer; a2bus_mcms1_device *m_pBusDevice; bool m_enabled; uint8_t m_vols[16]; diff --git a/src/devices/bus/a2bus/a2parprn.cpp b/src/devices/bus/a2bus/a2parprn.cpp index 7931472b732..c79f04f6da8 100644 --- a/src/devices/bus/a2bus/a2parprn.cpp +++ b/src/devices/bus/a2bus/a2parprn.cpp @@ -213,7 +213,7 @@ ioport_constructor a2bus_parprn_device::device_input_ports() const void a2bus_parprn_device::device_start() { - m_strobe_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(a2bus_parprn_device::update_strobe), this)); + m_strobe_timer = timer_alloc(FUNC(a2bus_parprn_device::update_strobe), this); save_item(NAME(m_next_strobe)); save_item(NAME(m_ack_latch)); diff --git a/src/devices/bus/a2bus/a2pic.cpp b/src/devices/bus/a2bus/a2pic.cpp index 7fe1487187e..321155f2cf8 100644 --- a/src/devices/bus/a2bus/a2pic.cpp +++ b/src/devices/bus/a2bus/a2pic.cpp @@ -343,7 +343,7 @@ ioport_constructor a2bus_pic_device::device_input_ports() const void a2bus_pic_device::device_start() { - m_strobe_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(a2bus_pic_device::release_strobe), this)); + m_strobe_timer = timer_alloc(FUNC(a2bus_pic_device::release_strobe), this); m_firmware_base = 0x0100U; m_data_latch = 0xffU; diff --git a/src/devices/bus/a2bus/a2sd.cpp b/src/devices/bus/a2bus/a2sd.cpp index 5d1306abab6..c5f1e743d0f 100644 --- a/src/devices/bus/a2bus/a2sd.cpp +++ b/src/devices/bus/a2bus/a2sd.cpp @@ -101,7 +101,7 @@ a2bus_a2sd_device::a2bus_a2sd_device(const machine_config &mconfig, const char * void a2bus_a2sd_device::device_start() { - m_shift_timer = timer_alloc(0); + m_shift_timer = timer_alloc(FUNC(a2bus_a2sd_device::shift_tick), this); save_item(NAME(m_datain)); save_item(NAME(m_in_latch)); @@ -119,7 +119,7 @@ void a2bus_a2sd_device::device_reset() m_sdcard->spi_clock_w(CLEAR_LINE); } -void a2bus_a2sd_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(a2bus_a2sd_device::shift_tick) { LOGMASKED(LOG_SPI, ">>>>>>> SHIFT %d (%c)\n", m_shift_count, (m_shift_count & 1) ? 'L' : 'S'); if (!(m_shift_count & 1)) diff --git a/src/devices/bus/a2bus/a2sd.h b/src/devices/bus/a2bus/a2sd.h index 85165248319..88414ec39d3 100644 --- a/src/devices/bus/a2bus/a2sd.h +++ b/src/devices/bus/a2bus/a2sd.h @@ -36,7 +36,6 @@ protected: virtual void device_reset() override; virtual void device_add_mconfig(machine_config &config) 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; // overrides of standard a2bus slot functions virtual u8 read_c0nx(u8 offset) override; @@ -49,6 +48,7 @@ protected: // SPI 4-wire interface WRITE_LINE_MEMBER(spi_miso_w) { m_in_bit = state; } + TIMER_CALLBACK_MEMBER(shift_tick); private: required_device<at28c64b_device> m_flash; required_device<spi_sdcard_device> m_sdcard; diff --git a/src/devices/bus/a2bus/agat840k_hle.cpp b/src/devices/bus/a2bus/agat840k_hle.cpp index 76afe57518c..cd6d01389b4 100644 --- a/src/devices/bus/a2bus/agat840k_hle.cpp +++ b/src/devices/bus/a2bus/agat840k_hle.cpp @@ -89,6 +89,8 @@ a2bus_agat840k_hle_device::a2bus_agat840k_hle_device(const machine_config &mconf , m_floppy_image(*this, "floppy%u", 0U) , m_d14(*this, "d14") , m_d15(*this, "d15") + , m_timer_wait(nullptr) + , m_timer_seek(nullptr) , m_rom(nullptr) { } @@ -137,8 +139,8 @@ void a2bus_agat840k_hle_device::device_start() m_mxcs = MXCSR_SYNC; - m_timer_wait = timer_alloc(TIMER_ID_WAIT); - m_timer_seek = timer_alloc(TIMER_ID_SEEK); + m_timer_wait = timer_alloc(FUNC(a2bus_agat840k_hle_device::timer_wait_tick), this); + m_timer_seek = timer_alloc(FUNC(a2bus_agat840k_hle_device::timer_seek_tick), this); m_seektime = 6000; // 6 ms, per es5323.txt m_waittime = 32; // 16 bits x 2 us @@ -226,29 +228,24 @@ void a2bus_agat840k_hle_device::device_reset() m_mxcs &= ~MXCSR_TR; } -void a2bus_agat840k_hle_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(a2bus_agat840k_hle_device::timer_wait_tick) { - switch (id) - { - case TIMER_ID_WAIT: - { - m_count_read++; - m_count_read %= 6250; - m_d15->pc4_w(0); - m_d15->pc4_w(1); - if (BIT(m_tracks[(2 * m_floppy->floppy_drive_get_current_track()) + m_side][m_count_read], 15)) - m_mxcs &= ~MXCSR_SYNC; - } - break; + m_count_read++; + m_count_read %= 6250; + m_d15->pc4_w(0); + m_d15->pc4_w(1); + if (BIT(m_tracks[(2 * m_floppy->floppy_drive_get_current_track()) + m_side][m_count_read], 15)) + m_mxcs &= ~MXCSR_SYNC; +} - case TIMER_ID_SEEK: - m_floppy->floppy_stp_w(1); - m_floppy->floppy_stp_w(0); - break; - } +TIMER_CALLBACK_MEMBER(a2bus_agat840k_hle_device::timer_seek_tick) +{ + m_floppy->floppy_stp_w(1); + m_floppy->floppy_stp_w(0); } + /*------------------------------------------------- read_c0nx - called for reads from this card's c0nx space -------------------------------------------------*/ diff --git a/src/devices/bus/a2bus/agat840k_hle.h b/src/devices/bus/a2bus/agat840k_hle.h index f51bda3324f..a497f2bc7aa 100644 --- a/src/devices/bus/a2bus/agat840k_hle.h +++ b/src/devices/bus/a2bus/agat840k_hle.h @@ -55,7 +55,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; virtual void device_add_mconfig(machine_config &config) override; virtual const tiny_rom_entry *device_rom_region() const override; @@ -64,11 +63,8 @@ protected: virtual void write_c0nx(uint8_t offset, uint8_t data) override; virtual uint8_t read_cnxx(uint8_t offset) override; - enum - { - TIMER_ID_WAIT = 0, - TIMER_ID_SEEK - }; + TIMER_CALLBACK_MEMBER(timer_wait_tick); + TIMER_CALLBACK_MEMBER(timer_seek_tick); required_device_array<legacy_floppy_image_device, 2> m_floppy_image; required_device<i8255_device> m_d14; @@ -91,8 +87,8 @@ private: int m_seektime; int m_waittime; - emu_timer *m_timer_wait = nullptr; - emu_timer *m_timer_seek = nullptr; + emu_timer *m_timer_wait; + emu_timer *m_timer_seek; uint8_t *m_rom; }; diff --git a/src/devices/bus/a2bus/agat_fdc.cpp b/src/devices/bus/a2bus/agat_fdc.cpp index f6743c35964..dc88c7ea39e 100644 --- a/src/devices/bus/a2bus/agat_fdc.cpp +++ b/src/devices/bus/a2bus/agat_fdc.cpp @@ -140,8 +140,8 @@ void a2bus_agat_fdc_device::device_start() m_mxcs = MXCSR_SYNC; - m_timer_lss = timer_alloc(TIMER_ID_LSS); - m_timer_motor = timer_alloc(TIMER_ID_MOTOR); + m_timer_lss = timer_alloc(FUNC(a2bus_agat_fdc_device::lss_sync), this); + m_timer_motor = timer_alloc(FUNC(a2bus_agat_fdc_device::motor_off), this); m_seektime = 6; // ms, per es5323.txt m_waittime = 32; // us - 16 bits x 2 us @@ -162,19 +162,10 @@ void a2bus_agat_fdc_device::device_reset() m_timer_lss->adjust(attotime::from_msec(10), 0, attotime::from_msec(10)); } -void a2bus_agat_fdc_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(a2bus_agat_fdc_device::motor_off) { - switch (id) - { - case TIMER_ID_LSS: - lss_sync(); - break; - - case TIMER_ID_MOTOR: - active = 0; - floppy->mon_w(1); - break; - } + active = 0; + floppy->mon_w(1); } uint64_t a2bus_agat_fdc_device::time_to_cycles(const attotime &tm) @@ -199,7 +190,7 @@ void a2bus_agat_fdc_device::lss_start() bits = 8; } -void a2bus_agat_fdc_device::lss_sync() +TIMER_CALLBACK_MEMBER(a2bus_agat_fdc_device::lss_sync) { if(!active) return; @@ -301,7 +292,7 @@ uint8_t a2bus_agat_fdc_device::read_c0nx(uint8_t offset) { u8 data; - lss_sync(); + lss_sync(0); switch (offset) { @@ -328,7 +319,7 @@ uint8_t a2bus_agat_fdc_device::read_c0nx(uint8_t offset) void a2bus_agat_fdc_device::write_c0nx(uint8_t offset, uint8_t data) { - lss_sync(); + lss_sync(0); switch (offset) { diff --git a/src/devices/bus/a2bus/agat_fdc.h b/src/devices/bus/a2bus/agat_fdc.h index e209902c709..950027151cd 100644 --- a/src/devices/bus/a2bus/agat_fdc.h +++ b/src/devices/bus/a2bus/agat_fdc.h @@ -49,7 +49,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; virtual void device_add_mconfig(machine_config &config) override; virtual const tiny_rom_entry *device_rom_region() const override; @@ -76,7 +75,9 @@ private: attotime cycles_to_time(uint64_t cycles); void lss_start(); - void lss_sync(); + TIMER_CALLBACK_MEMBER(lss_sync); + + TIMER_CALLBACK_MEMBER(motor_off); floppy_image_device *floppy; int active, bits; diff --git a/src/devices/bus/a2bus/corvfdc02.cpp b/src/devices/bus/a2bus/corvfdc02.cpp index 5f80726d1bc..12c7aed06ac 100644 --- a/src/devices/bus/a2bus/corvfdc02.cpp +++ b/src/devices/bus/a2bus/corvfdc02.cpp @@ -101,7 +101,7 @@ void a2bus_corvfdc02_device::device_start() { m_rom = device().machine().root_device().memregion(this->subtag(FDC02_ROM_REGION).c_str())->base(); - m_timer = timer_alloc(0); + m_timer = timer_alloc(FUNC(a2bus_corvfdc02_device::tc_tick), this); save_item(NAME(m_fdc_local_status)); save_item(NAME(m_fdc_local_command)); @@ -118,7 +118,7 @@ void a2bus_corvfdc02_device::device_reset() m_timer->adjust(attotime::never); } -void a2bus_corvfdc02_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(a2bus_corvfdc02_device::tc_tick) { m_fdc->tc_w(true); m_fdc->tc_w(false); diff --git a/src/devices/bus/a2bus/corvfdc02.h b/src/devices/bus/a2bus/corvfdc02.h index 028770450cd..825d68d564b 100644 --- a/src/devices/bus/a2bus/corvfdc02.h +++ b/src/devices/bus/a2bus/corvfdc02.h @@ -35,7 +35,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; virtual void device_add_mconfig(machine_config &config) override; virtual const tiny_rom_entry *device_rom_region() const override; @@ -44,6 +43,8 @@ protected: virtual void write_c0nx(uint8_t offset, uint8_t data) override; virtual uint8_t read_cnxx(uint8_t offset) override; + TIMER_CALLBACK_MEMBER(tc_tick); + required_device<upd765a_device> m_fdc; required_device<floppy_connector> m_con1; required_device<floppy_connector> m_con2; diff --git a/src/devices/bus/a2bus/grappler.cpp b/src/devices/bus/a2bus/grappler.cpp index 68f49edcf37..c09ff95e8fc 100644 --- a/src/devices/bus/a2bus/grappler.cpp +++ b/src/devices/bus/a2bus/grappler.cpp @@ -746,7 +746,7 @@ void a2bus_grapplerplus_device::device_start() { a2bus_grapplerplus_device_base::device_start(); - m_strobe_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(a2bus_grapplerplus_device::update_strobe), this)); + m_strobe_timer = timer_alloc(FUNC(a2bus_grapplerplus_device::update_strobe), this); m_next_strobe = 1U; diff --git a/src/devices/bus/a2bus/transwarp.cpp b/src/devices/bus/a2bus/transwarp.cpp index 719fe7993df..a87f724a704 100644 --- a/src/devices/bus/a2bus/transwarp.cpp +++ b/src/devices/bus/a2bus/transwarp.cpp @@ -158,7 +158,7 @@ a2bus_transwarp_device::a2bus_transwarp_device(const machine_config &mconfig, co void a2bus_transwarp_device::device_start() { - m_timer = timer_alloc(0); + m_timer = timer_alloc(FUNC(a2bus_transwarp_device::clock_adjust_tick), this); save_item(NAME(m_bEnabled)); save_item(NAME(m_bReadA2ROM)); @@ -187,7 +187,7 @@ void a2bus_transwarp_device::device_reset() } } -void a2bus_transwarp_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(a2bus_transwarp_device::clock_adjust_tick) { if (m_bIn1MHzMode) { diff --git a/src/devices/bus/a2bus/transwarp.h b/src/devices/bus/a2bus/transwarp.h index 1401f61776b..1213ea26c8b 100644 --- a/src/devices/bus/a2bus/transwarp.h +++ b/src/devices/bus/a2bus/transwarp.h @@ -33,7 +33,6 @@ protected: virtual void device_reset() override; virtual void device_add_mconfig(machine_config &config) override; virtual ioport_constructor device_input_ports() const 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; // overrides of standard a2bus slot functions @@ -49,6 +48,8 @@ private: required_region_ptr<uint8_t> m_rom; required_ioport m_dsw1, m_dsw2; + TIMER_CALLBACK_MEMBER(clock_adjust_tick); + uint8_t dma_r(offs_t offset); void dma_w(offs_t offset, uint8_t data); diff --git a/src/devices/bus/a2bus/uniprint.cpp b/src/devices/bus/a2bus/uniprint.cpp index 99b90223a42..d451a45fe89 100644 --- a/src/devices/bus/a2bus/uniprint.cpp +++ b/src/devices/bus/a2bus/uniprint.cpp @@ -185,7 +185,7 @@ ioport_constructor a2bus_uniprint_device::device_input_ports() const void a2bus_uniprint_device::device_start() { - m_strobe_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(a2bus_uniprint_device::update_strobe), this)); + m_strobe_timer = timer_alloc(FUNC(a2bus_uniprint_device::update_strobe), this); m_next_strobe = 1U; diff --git a/src/devices/bus/a800/cassette.cpp b/src/devices/bus/a800/cassette.cpp index 6e2c0073691..32d9fe0b390 100644 --- a/src/devices/bus/a800/cassette.cpp +++ b/src/devices/bus/a800/cassette.cpp @@ -26,7 +26,6 @@ TODO: //************************************************************************** DEFINE_DEVICE_TYPE(A8SIO_CASSETTE, a8sio_cassette_device, "a8sio_cass", "Atari 8 bit cassette") -const device_timer_id TIMER_CASSETTE_READ = 1; void a8sio_cassette_device::device_add_mconfig(machine_config &config) { @@ -60,7 +59,7 @@ void a8sio_cassette_device::device_start() save_item(NAME(m_old_cass_signal)); save_item(NAME(m_signal_count)); - m_read_timer = timer_alloc(TIMER_CASSETTE_READ); + m_read_timer = timer_alloc(FUNC(a8sio_cassette_device::read_tick), this); } void a8sio_cassette_device::device_reset() @@ -82,27 +81,22 @@ WRITE_LINE_MEMBER( a8sio_cassette_device::motor_w ) } } -void a8sio_cassette_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(a8sio_cassette_device::read_tick) { - switch (id) + uint8_t cass_signal = m_cassette->input() < 0 ? 0 : 1; + + if (m_signal_count < 20) + { + m_signal_count++; + } + + if (cass_signal != m_old_cass_signal) { - case TIMER_CASSETTE_READ: - uint8_t cass_signal = m_cassette->input() < 0 ? 0 : 1; - - if (m_signal_count < 20) - { - m_signal_count++; - } - - if (cass_signal != m_old_cass_signal) - { - //printf("cass_signal: %d, count: %d, data: %d\n", cass_signal, m_signal_count, m_signal_count < 5 ? 1 : 0); - // ~4 kHz -> 0 - // ~5 kHz -> 1 - m_a8sio->data_in_w((m_signal_count < 5) ? 1 : 0); - m_signal_count = 0; - m_old_cass_signal = cass_signal; - } - break; + //printf("cass_signal: %d, count: %d, data: %d\n", cass_signal, m_signal_count, m_signal_count < 5 ? 1 : 0); + // ~4 kHz -> 0 + // ~5 kHz -> 1 + m_a8sio->data_in_w((m_signal_count < 5) ? 1 : 0); + m_signal_count = 0; + m_old_cass_signal = cass_signal; } } diff --git a/src/devices/bus/a800/cassette.h b/src/devices/bus/a800/cassette.h index ed75b00bdc8..d1c91c5a2fa 100644 --- a/src/devices/bus/a800/cassette.h +++ b/src/devices/bus/a800/cassette.h @@ -36,9 +36,10 @@ 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(read_tick); + required_device<cassette_image_device> m_cassette; emu_timer *m_read_timer; diff --git a/src/devices/bus/abckb/abc77.cpp b/src/devices/bus/abckb/abc77.cpp index 0175916e700..442ff553e2f 100644 --- a/src/devices/bus/abckb/abc77.cpp +++ b/src/devices/bus/abckb/abc77.cpp @@ -382,7 +382,7 @@ inline void abc77_device::serial_output(int state) // serial_clock - //------------------------------------------------- -inline void abc77_device::serial_clock() +TIMER_CALLBACK_MEMBER(abc77_device::serial_clock) { m_clock = !m_clock; @@ -442,10 +442,10 @@ abc77_device::abc77_device(const machine_config &mconfig, const char *tag, devic void abc77_device::device_start() { // allocate timers - m_serial_timer = timer_alloc(TIMER_SERIAL); + m_serial_timer = timer_alloc(FUNC(abc77_device::serial_clock), this); m_serial_timer->adjust(attotime::from_hz(19200), 0, attotime::from_hz(19200)); // ALE/32 - m_reset_timer = timer_alloc(TIMER_RESET); + m_reset_timer = timer_alloc(FUNC(abc77_device::reset_tick), this); } @@ -469,21 +469,12 @@ void abc77_device::device_reset() //------------------------------------------------- -// device_timer - handler timer events +// reset_tick - handle delayed reset //------------------------------------------------- -void abc77_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(abc77_device::reset_tick) { - switch (id) - { - case TIMER_SERIAL: - serial_clock(); - break; - - case TIMER_RESET: - m_maincpu->set_input_line(INPUT_LINE_RESET, CLEAR_LINE); - break; - } + m_maincpu->set_input_line(INPUT_LINE_RESET, CLEAR_LINE); } diff --git a/src/devices/bus/abckb/abc77.h b/src/devices/bus/abckb/abc77.h index ccfb1b8effd..f6147c52c66 100644 --- a/src/devices/bus/abckb/abc77.h +++ b/src/devices/bus/abckb/abc77.h @@ -40,7 +40,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; // optional information overrides virtual const tiny_rom_entry *device_rom_region() const override; @@ -57,9 +56,11 @@ private: TIMER_RESET }; - inline void serial_output(int state); - inline void serial_clock(); - inline void key_down(int state); + void serial_output(int state); + void key_down(int state); + + TIMER_CALLBACK_MEMBER(serial_clock); + TIMER_CALLBACK_MEMBER(reset_tick); required_device<i8035_device> m_maincpu; required_device<watchdog_timer_device> m_watchdog; diff --git a/src/devices/bus/abckb/abc800kb.cpp b/src/devices/bus/abckb/abc800kb.cpp index 21c30b245ab..571a62d5a6e 100644 --- a/src/devices/bus/abckb/abc800kb.cpp +++ b/src/devices/bus/abckb/abc800kb.cpp @@ -268,7 +268,7 @@ ioport_constructor abc800_keyboard_device::device_input_ports() const // serial_output - //------------------------------------------------- -inline void abc800_keyboard_device::serial_output(int state) +void abc800_keyboard_device::serial_output(int state) { if (m_txd != state) { @@ -283,7 +283,7 @@ inline void abc800_keyboard_device::serial_output(int state) // serial_clock - //------------------------------------------------- -inline void abc800_keyboard_device::serial_clock() +TIMER_CALLBACK_MEMBER(abc800_keyboard_device::serial_clock) { m_clk = !m_clk; @@ -295,7 +295,7 @@ inline void abc800_keyboard_device::serial_clock() // keydown - //------------------------------------------------- -inline void abc800_keyboard_device::key_down(int state) +void abc800_keyboard_device::key_down(int state) { if (m_keydown != state) { @@ -337,7 +337,7 @@ abc800_keyboard_device::abc800_keyboard_device(const machine_config &mconfig, co void abc800_keyboard_device::device_start() { // allocate timers - m_serial_timer = timer_alloc(); + m_serial_timer = timer_alloc(FUNC(abc800_keyboard_device::serial_clock), this); m_serial_timer->adjust(attotime::from_hz(XTAL(5'990'400)/(3*5)/20), 0, attotime::from_hz(XTAL(5'990'400)/(3*5)/20)); // ??? // state saving @@ -358,15 +358,6 @@ void abc800_keyboard_device::device_reset() } -//------------------------------------------------- -// device_timer - handler timer events -//------------------------------------------------- - -void abc800_keyboard_device::device_timer(emu_timer &timer, device_timer_id id, int param) -{ - serial_clock(); -} - //------------------------------------------------- // txd_w - diff --git a/src/devices/bus/abckb/abc800kb.h b/src/devices/bus/abckb/abc800kb.h index acbd19ef299..39f54e2f854 100644 --- a/src/devices/bus/abckb/abc800kb.h +++ b/src/devices/bus/abckb/abc800kb.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; // optional information overrides virtual const tiny_rom_entry *device_rom_region() const override; @@ -46,9 +45,9 @@ protected: virtual ioport_constructor device_input_ports() const override; private: - inline void serial_output(int state); - inline void serial_clock(); - inline void key_down(int state); + void serial_output(int state); + TIMER_CALLBACK_MEMBER(serial_clock); + void key_down(int state); uint8_t kb_p1_r(); void kb_p1_w(uint8_t data); diff --git a/src/devices/bus/abckb/abc99.cpp b/src/devices/bus/abckb/abc99.cpp index 3c05f749227..3273e625a4b 100644 --- a/src/devices/bus/abckb/abc99.cpp +++ b/src/devices/bus/abckb/abc99.cpp @@ -398,15 +398,11 @@ ioport_constructor abc99_device::device_input_ports() const -//************************************************************************** -// INLINE HELPERS -//************************************************************************** - //------------------------------------------------- // serial_input - //------------------------------------------------- -inline void abc99_device::serial_input() +void abc99_device::serial_input() { m_maincpu->set_input_line(MCS48_INPUT_IRQ, (m_si || m_si_en) ? CLEAR_LINE : ASSERT_LINE); m_mousecpu->set_input_line(MCS48_INPUT_IRQ, m_si ? CLEAR_LINE : ASSERT_LINE); @@ -417,7 +413,7 @@ inline void abc99_device::serial_input() // serial_output - //------------------------------------------------- -inline void abc99_device::serial_output(int state) +void abc99_device::serial_output(int state) { if (m_txd != state) { @@ -432,7 +428,7 @@ inline void abc99_device::serial_output(int state) // serial_clock - //------------------------------------------------- -inline void abc99_device::serial_clock() +TIMER_CALLBACK_MEMBER(abc99_device::serial_clock) { m_slot->trxc_w(1); m_slot->trxc_w(0); @@ -440,25 +436,25 @@ inline void abc99_device::serial_clock() //------------------------------------------------- -// keydown - +// scan_mouse - //------------------------------------------------- -inline void abc99_device::key_down(int state) +TIMER_CALLBACK_MEMBER(abc99_device::scan_mouse) { - if (m_keydown != state) - { - m_slot->keydown_w(state); - m_keydown = state; - } } //------------------------------------------------- -// scan_mouse - +// keydown - //------------------------------------------------- -inline void abc99_device::scan_mouse() +void abc99_device::key_down(int state) { + if (m_keydown != state) + { + m_slot->keydown_w(state); + m_keydown = state; + } } @@ -502,10 +498,10 @@ void abc99_device::device_start() { m_leds.resolve(); // allocate timers - m_serial_timer = timer_alloc(TIMER_SERIAL); + m_serial_timer = timer_alloc(FUNC(abc99_device::serial_clock), this); m_serial_timer->adjust(MCS48_ALE_CLOCK(XTAL(6'000'000)/3), 0, MCS48_ALE_CLOCK(XTAL(6'000'000)/3)); - m_mouse_timer = timer_alloc(TIMER_MOUSE); + m_mouse_timer = timer_alloc(FUNC(abc99_device::scan_mouse), this); // state saving save_item(NAME(m_si)); @@ -536,25 +532,6 @@ void abc99_device::device_reset() //------------------------------------------------- -// device_timer - handler timer events -//------------------------------------------------- - -void abc99_device::device_timer(emu_timer &timer, device_timer_id id, int param) -{ - switch (id) - { - case TIMER_SERIAL: - serial_clock(); - break; - - case TIMER_MOUSE: - scan_mouse(); - break; - } -} - - -//------------------------------------------------- // txd_w - //------------------------------------------------- diff --git a/src/devices/bus/abckb/abc99.h b/src/devices/bus/abckb/abc99.h index 7f7fbbfbd73..d2c30db1f4f 100644 --- a/src/devices/bus/abckb/abc99.h +++ b/src/devices/bus/abckb/abc99.h @@ -37,7 +37,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; // optional information overrides virtual const tiny_rom_entry *device_rom_region() const override; @@ -50,12 +49,6 @@ protected: private: enum { - TIMER_SERIAL, - TIMER_MOUSE - }; - - enum - { LED_1 = 0, LED_2, LED_3, @@ -69,11 +62,11 @@ private: LED_CAPS_LOCK }; - inline void serial_input(); - inline void serial_output(int state); - inline void serial_clock(); - inline void key_down(int state); - inline void scan_mouse(); + void serial_input(); + void serial_output(int state); + TIMER_CALLBACK_MEMBER(serial_clock); + TIMER_CALLBACK_MEMBER(scan_mouse); + void key_down(int state); void z2_p1_w(uint8_t data); uint8_t z2_p2_r(); diff --git a/src/devices/bus/amiga/keyboard/mitsumi.cpp b/src/devices/bus/amiga/keyboard/mitsumi.cpp index 7557d04b95c..ccc68d5d1d4 100644 --- a/src/devices/bus/amiga/keyboard/mitsumi.cpp +++ b/src/devices/bus/amiga/keyboard/mitsumi.cpp @@ -209,8 +209,8 @@ protected: { mitsumi_keyboard_base::device_start(); - m_wd_timeout = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(mitsumi_watchdog_keyboard_base::wd_timeout), this)); - m_wd_pulse = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(mitsumi_watchdog_keyboard_base::wd_pulse), this)); + m_wd_timeout = timer_alloc(FUNC(mitsumi_watchdog_keyboard_base::wd_timeout), this); + m_wd_pulse = timer_alloc(FUNC(mitsumi_watchdog_keyboard_base::wd_pulse), this); m_pd7 = 0x01U; @@ -284,7 +284,7 @@ protected: { mitsumi_watchdog_keyboard_base::device_start(); - m_reset_pulse = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(a500_keyboard_base::reset_pulse), this)); + m_reset_pulse = timer_alloc(FUNC(a500_keyboard_base::reset_pulse), this); m_reset_active = 0U; @@ -344,7 +344,7 @@ protected: { mitsumi_keyboard_base::device_start(); - m_reset_pulse = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(a600_keyboard_base::reset_pulse), this)); + m_reset_pulse = timer_alloc(FUNC(a600_keyboard_base::reset_pulse), this); m_reset_trigger = 0U; m_reset_active = 0U; diff --git a/src/devices/bus/astrocde/lightpen.cpp b/src/devices/bus/astrocde/lightpen.cpp index 407f2a9e852..40a7ec415de 100644 --- a/src/devices/bus/astrocde/lightpen.cpp +++ b/src/devices/bus/astrocde/lightpen.cpp @@ -31,7 +31,7 @@ astrocade_lightpen_device::~astrocade_lightpen_device() void astrocade_lightpen_device::device_start() { - m_pen_timer = timer_alloc(TIMER_TRIGGER); + m_pen_timer = timer_alloc(FUNC(astrocade_lightpen_device::trigger_tick), this); save_item(NAME(m_retrigger)); } @@ -42,20 +42,17 @@ void astrocade_lightpen_device::device_reset() m_retrigger = false; } -void astrocade_lightpen_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(astrocade_lightpen_device::trigger_tick) { - if (id == TIMER_TRIGGER) - { - write_ltpen(1); - write_ltpen(0); - if (m_retrigger) - m_pen_timer->adjust(m_screen->time_until_pos(m_lighty->read(), m_lightx->read())); - else - m_pen_timer->adjust(attotime::never); - } + write_ltpen(1); + write_ltpen(0); + if (m_retrigger) + m_pen_timer->adjust(m_screen->time_until_pos(m_lighty->read(), m_lightx->read())); + else + m_pen_timer->adjust(attotime::never); } -INPUT_CHANGED_MEMBER( astrocade_lightpen_device::trigger ) +INPUT_CHANGED_MEMBER(astrocade_lightpen_device::trigger) { if (newval) { diff --git a/src/devices/bus/astrocde/lightpen.h b/src/devices/bus/astrocde/lightpen.h index 136ea918a81..dd75c807443 100644 --- a/src/devices/bus/astrocde/lightpen.h +++ b/src/devices/bus/astrocde/lightpen.h @@ -22,16 +22,15 @@ public: astrocade_lightpen_device(machine_config const &mconfig, char const *tag, device_t *owner, uint32_t clock = 0U); virtual ~astrocade_lightpen_device(); - DECLARE_INPUT_CHANGED_MEMBER( trigger ); + DECLARE_INPUT_CHANGED_MEMBER(trigger); protected: // device_t implementation virtual void device_start() override; virtual void device_reset() override; virtual ioport_constructor device_input_ports() const override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; - static const device_timer_id TIMER_TRIGGER = 0; + TIMER_CALLBACK_MEMBER(trigger_tick); private: required_ioport m_trigger; diff --git a/src/devices/bus/ata/atahle.cpp b/src/devices/bus/ata/atahle.cpp index 8a654096531..0ba22e2773b 100644 --- a/src/devices/bus/ata/atahle.cpp +++ b/src/devices/bus/ata/atahle.cpp @@ -110,8 +110,8 @@ void ata_hle_device::device_start() save_item(NAME(m_identify_buffer)); - m_busy_timer = timer_alloc(TID_BUSY); - m_buffer_empty_timer = timer_alloc(TID_BUFFER_EMPTY); + m_busy_timer = timer_alloc(FUNC(ata_hle_device::busy_tick), this); + m_buffer_empty_timer = timer_alloc(FUNC(ata_hle_device::empty_tick), this); } void ata_hle_device::device_reset() @@ -151,20 +151,16 @@ void ata_hle_device::soft_reset() start_busy(DIAGNOSTIC_TIME, PARAM_DIAGNOSTIC); } -void ata_hle_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(ata_hle_device::busy_tick) { - switch(id) - { - case TID_BUSY: - m_status &= ~IDE_STATUS_BSY; + m_status &= ~IDE_STATUS_BSY; + finished_busy(param); +} - finished_busy(param); - break; - case TID_BUFFER_EMPTY: - m_buffer_empty_timer->enable(false); - fill_buffer(); - break; - } +TIMER_CALLBACK_MEMBER(ata_hle_device::empty_tick) +{ + m_buffer_empty_timer->enable(false); + fill_buffer(); } void ata_hle_device::finished_busy(int param) diff --git a/src/devices/bus/ata/atahle.h b/src/devices/bus/ata/atahle.h index 2c5f2ba803c..5fcfa90c478 100644 --- a/src/devices/bus/ata/atahle.h +++ b/src/devices/bus/ata/atahle.h @@ -35,7 +35,9 @@ 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(busy_tick); + TIMER_CALLBACK_MEMBER(empty_tick); void set_irq(int state); void set_dmarq(int state); diff --git a/src/devices/bus/ata/idehd.cpp b/src/devices/bus/ata/idehd.cpp index 9b20827d4fd..ba5829e6d9c 100644 --- a/src/devices/bus/ata/idehd.cpp +++ b/src/devices/bus/ata/idehd.cpp @@ -812,7 +812,7 @@ void ide_hdd_device::device_start() ata_mass_storage_device::device_start(); /* create a timer for timing status */ - m_last_status_timer = timer_alloc(TID_NULL); + m_last_status_timer = machine().scheduler().timer_alloc(timer_expired_delegate()); } //------------------------------------------------- diff --git a/src/devices/bus/bbc/1mhzbus/m5000.cpp b/src/devices/bus/bbc/1mhzbus/m5000.cpp index 2e3a525622d..ae3fd948969 100644 --- a/src/devices/bus/bbc/1mhzbus/m5000.cpp +++ b/src/devices/bus/bbc/1mhzbus/m5000.cpp @@ -247,7 +247,7 @@ void htmusic_device::device_start() m_stream = stream_alloc(0, 2, clock() / 128); // allocate timer - m_dsp_timer = timer_alloc(0); + m_dsp_timer = timer_alloc(FUNC(htmusic_device::dsp_tick), this); // register for save states save_item(NAME(m_wave_ram)); @@ -303,7 +303,7 @@ void htmusic_device::device_reset() #define INVERT(c) (BIT(CTL(c), 4)) #define PAN(c) (CTL(c) & 0x0f) -void htmusic_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(htmusic_device::dsp_tick) { // 4-bit channel select uint8_t channel = (m_counter >> 3) & 0x0f; diff --git a/src/devices/bus/bbc/1mhzbus/m5000.h b/src/devices/bus/bbc/1mhzbus/m5000.h index f49f2804187..116bc17cebe 100644 --- a/src/devices/bus/bbc/1mhzbus/m5000.h +++ b/src/devices/bus/bbc/1mhzbus/m5000.h @@ -41,8 +41,6 @@ public: void ram_w(offs_t offset, uint8_t data) { m_wave_ram[offset & 0x7ff] = data; } - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; - protected: // device-level overrides virtual void device_start() override; @@ -51,6 +49,8 @@ protected: // sound stream update overrides virtual void sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) override; + TIMER_CALLBACK_MEMBER(dsp_tick); + private: uint16_t m_antilog[128]; uint8_t m_wave_ram[0x800]; diff --git a/src/devices/bus/bbc/joyport/mouse.cpp b/src/devices/bus/bbc/joyport/mouse.cpp index 044722268a7..1cd91caeaa5 100644 --- a/src/devices/bus/bbc/joyport/mouse.cpp +++ b/src/devices/bus/bbc/joyport/mouse.cpp @@ -75,7 +75,7 @@ bbcmc_mouse_device::bbcmc_mouse_device(const machine_config &mconfig, const char void bbcmc_mouse_device::device_start() { - m_mouse_timer = timer_alloc(); + m_mouse_timer = timer_alloc(FUNC(bbcmc_mouse_device::update), this); } @@ -100,7 +100,7 @@ void bbcmc_mouse_device::device_reset() // IMPLEMENTATION //************************************************************************** -void bbcmc_mouse_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(bbcmc_mouse_device::update) { int x = m_mouse_x->read(); int y = m_mouse_y->read(); diff --git a/src/devices/bus/bbc/joyport/mouse.h b/src/devices/bus/bbc/joyport/mouse.h index d65bbbe5ffa..0e2c6947104 100644 --- a/src/devices/bus/bbc/joyport/mouse.h +++ b/src/devices/bus/bbc/joyport/mouse.h @@ -31,13 +31,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 ioport_constructor device_input_ports() const override; virtual uint8_t pb_r() override; + TIMER_CALLBACK_MEMBER(update); + private: required_ioport m_mouse_x; required_ioport m_mouse_y; diff --git a/src/devices/bus/bbc/userport/pointer.cpp b/src/devices/bus/bbc/userport/pointer.cpp index 18c861265d4..cff7c1570e2 100644 --- a/src/devices/bus/bbc/userport/pointer.cpp +++ b/src/devices/bus/bbc/userport/pointer.cpp @@ -151,7 +151,7 @@ bbc_tracker_device::bbc_tracker_device(const machine_config &mconfig, const char void bbc_pointer_device::device_start() { - m_pointer_timer = timer_alloc(); + m_pointer_timer = timer_alloc(FUNC(bbc_pointer_device::update), this); } @@ -176,7 +176,7 @@ void bbc_pointer_device::device_reset() // IMPLEMENTATION //************************************************************************** -void bbc_pointer_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(bbc_pointer_device::update) { int x = m_pointer_x->read(); int y = m_pointer_y->read(); diff --git a/src/devices/bus/bbc/userport/pointer.h b/src/devices/bus/bbc/userport/pointer.h index c830caf7f00..865a9c91270 100644 --- a/src/devices/bus/bbc/userport/pointer.h +++ b/src/devices/bus/bbc/userport/pointer.h @@ -29,7 +29,8 @@ protected: // device-level overrides virtual void device_start() override; virtual void device_reset() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; + + TIMER_CALLBACK_MEMBER(update); required_ioport m_pointer_x; required_ioport m_pointer_y; diff --git a/src/devices/bus/c64/c128_partner.cpp b/src/devices/bus/c64/c128_partner.cpp index c17bf49f792..7c6cf1aea97 100644 --- a/src/devices/bus/c64/c128_partner.cpp +++ b/src/devices/bus/c64/c128_partner.cpp @@ -98,7 +98,7 @@ c128_partner_cartridge_device::c128_partner_cartridge_device(const machine_confi void c128_partner_cartridge_device::device_start() { // simulate the 16.7ms pulse from CIA1 PB2 that would arrive thru the joystick port dongle - t_joyb2 = timer_alloc(); + t_joyb2 = timer_alloc(FUNC(c128_partner_cartridge_device::update_joyb2), this); t_joyb2->adjust(attotime::from_msec(16), 0, attotime::from_msec(16)); // state saving @@ -127,10 +127,10 @@ void c128_partner_cartridge_device::device_reset() //------------------------------------------------- -// device_timer - +// update_joyb2 - //------------------------------------------------- -void c128_partner_cartridge_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(c128_partner_cartridge_device::update_joyb2) { if (m_ls74_cd) { diff --git a/src/devices/bus/c64/c128_partner.h b/src/devices/bus/c64/c128_partner.h index 6f45b32a64f..3f91afbb0e9 100644 --- a/src/devices/bus/c64/c128_partner.h +++ b/src/devices/bus/c64/c128_partner.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; // device_c64_expansion_card_interface overrides virtual uint8_t c64_cd_r(offs_t offset, uint8_t data, int sphi2, int ba, int roml, int romh, int io1, int io2) override; @@ -48,6 +47,8 @@ protected: // device_vcs_control_port_interface overrides virtual void vcs_joy_w(uint8_t data); + TIMER_CALLBACK_MEMBER(update_joyb2); + private: memory_share_creator<uint8_t> m_ram; diff --git a/src/devices/bus/c64/epyx_fast_load.cpp b/src/devices/bus/c64/epyx_fast_load.cpp index 7f398bf1963..21352ddef63 100644 --- a/src/devices/bus/c64/epyx_fast_load.cpp +++ b/src/devices/bus/c64/epyx_fast_load.cpp @@ -51,7 +51,7 @@ c64_epyx_fast_load_cartridge_device::c64_epyx_fast_load_cartridge_device(const m void c64_epyx_fast_load_cartridge_device::device_start() { // allocate timer - m_exrom_timer = timer_alloc(); + m_exrom_timer = timer_alloc(FUNC(c64_epyx_fast_load_cartridge_device::update_exrom), this); } @@ -67,10 +67,10 @@ void c64_epyx_fast_load_cartridge_device::device_reset() //------------------------------------------------- -// device_timer - handler timer events +// update_exrom - update exrom flag //------------------------------------------------- -void c64_epyx_fast_load_cartridge_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(c64_epyx_fast_load_cartridge_device::update_exrom) { m_exrom = 1; } diff --git a/src/devices/bus/c64/epyx_fast_load.h b/src/devices/bus/c64/epyx_fast_load.h index 1e825b89397..8a2ebcaa9b0 100644 --- a/src/devices/bus/c64/epyx_fast_load.h +++ b/src/devices/bus/c64/epyx_fast_load.h @@ -33,12 +33,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; // device_c64_expansion_card_interface overrides virtual uint8_t c64_cd_r(offs_t offset, uint8_t data, int sphi2, int ba, int roml, int romh, int io1, int io2) override; virtual void c64_cd_w(offs_t offset, uint8_t data, int sphi2, int ba, int roml, int romh, int io1, int io2) override; + TIMER_CALLBACK_MEMBER(update_exrom); + private: emu_timer *m_exrom_timer; }; diff --git a/src/devices/bus/c64/super_explode.cpp b/src/devices/bus/c64/super_explode.cpp index 8867845fa52..b01e2e25fba 100644 --- a/src/devices/bus/c64/super_explode.cpp +++ b/src/devices/bus/c64/super_explode.cpp @@ -51,7 +51,7 @@ c64_super_explode_cartridge_device::c64_super_explode_cartridge_device(const mac void c64_super_explode_cartridge_device::device_start() { // allocate timer - m_exrom_timer = timer_alloc(); + m_exrom_timer = timer_alloc(FUNC(c64_super_explode_cartridge_device::update_exrom), this); // state saving save_item(NAME(m_bank)); @@ -72,10 +72,10 @@ void c64_super_explode_cartridge_device::device_reset() //------------------------------------------------- -// device_timer - handler timer events +// update_exram - update exrom flag for banking //------------------------------------------------- -void c64_super_explode_cartridge_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(c64_super_explode_cartridge_device::update_exrom) { m_exrom = 1; } diff --git a/src/devices/bus/c64/super_explode.h b/src/devices/bus/c64/super_explode.h index a90a7a697ca..b2cedd35c55 100644 --- a/src/devices/bus/c64/super_explode.h +++ b/src/devices/bus/c64/super_explode.h @@ -33,12 +33,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; // device_c64_expansion_card_interface overrides virtual uint8_t c64_cd_r(offs_t offset, uint8_t data, int sphi2, int ba, int roml, int romh, int io1, int io2) override; virtual void c64_cd_w(offs_t offset, uint8_t data, int sphi2, int ba, int roml, int romh, int io1, int io2) override; + TIMER_CALLBACK_MEMBER(update_exrom); + private: uint8_t m_bank; diff --git a/src/devices/bus/c64/vw64.cpp b/src/devices/bus/c64/vw64.cpp index 266eb3c2017..81a56e478b8 100644 --- a/src/devices/bus/c64/vw64.cpp +++ b/src/devices/bus/c64/vw64.cpp @@ -81,7 +81,7 @@ c64_vizawrite_cartridge_device::c64_vizawrite_cartridge_device(const machine_con void c64_vizawrite_cartridge_device::device_start() { // allocate timer - m_game_timer = timer_alloc(); + m_game_timer = timer_alloc(FUNC(c64_vizawrite_cartridge_device::update_game), this); } @@ -98,10 +98,11 @@ void c64_vizawrite_cartridge_device::device_reset() //------------------------------------------------- -// device_timer - handler timer events +// update_game - update mapping flags for game +// data //------------------------------------------------- -void c64_vizawrite_cartridge_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(c64_vizawrite_cartridge_device::update_game) { m_game = 1; } diff --git a/src/devices/bus/c64/vw64.h b/src/devices/bus/c64/vw64.h index 805d40a975c..00b94969413 100644 --- a/src/devices/bus/c64/vw64.h +++ b/src/devices/bus/c64/vw64.h @@ -33,12 +33,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; // device_c64_expansion_card_interface overrides virtual uint8_t c64_cd_r(offs_t offset, uint8_t data, int sphi2, int ba, int roml, int romh, int io1, int io2) override; virtual int c64_exrom_r(offs_t offset, int sphi2, int ba, int rw) override { return 0; } + TIMER_CALLBACK_MEMBER(update_game); + private: emu_timer *m_game_timer; }; diff --git a/src/devices/bus/cbus/pc9801_86.cpp b/src/devices/bus/cbus/pc9801_86.cpp index ab53d87cce2..ec54475ae45 100644 --- a/src/devices/bus/cbus/pc9801_86.cpp +++ b/src/devices/bus/cbus/pc9801_86.cpp @@ -229,7 +229,7 @@ void pc9801_86_device::device_start() m_io_base = 0; - m_dac_timer = timer_alloc(); + m_dac_timer = timer_alloc(FUNC(pc9801_86_device::dac_tick), this); save_item(NAME(m_count)); save_item(NAME(m_queue)); save_item(NAME(m_irq_rate)); @@ -382,10 +382,8 @@ u8 pc9801_86_device::queue_pop() return ret; } -void pc9801_86_device::device_timer(emu_timer& timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(pc9801_86_device::dac_tick) { - int16_t lsample, rsample; - m_pcm_clk = !m_pcm_clk; if((m_pcm_ctrl & 0x40) || !(m_pcm_ctrl & 0x80)) return; @@ -402,24 +400,24 @@ void pc9801_86_device::device_timer(emu_timer& timer, device_timer_id id, int pa case 0x50: // 8bit right only m_rdac->write(queue_pop() << 8); break; - case 0x30: // 16bit stereo - lsample = queue_pop() << 8; + case 0x30: { // 16bit stereo + int16_t lsample = queue_pop() << 8; lsample |= queue_pop(); - rsample = queue_pop() << 8; + int16_t rsample = queue_pop() << 8; rsample |= queue_pop(); m_ldac->write(lsample); m_rdac->write(rsample); - break; - case 0x20: // 16bit left only - lsample = queue_pop() << 8; + } break; + case 0x20: { // 16bit left only + int16_t lsample = queue_pop() << 8; lsample |= queue_pop(); m_ldac->write(lsample); - break; - case 0x10: // 16bit right only - rsample = queue_pop() << 8; + } break; + case 0x10: { // 16bit right only + int16_t rsample = queue_pop() << 8; rsample |= queue_pop(); m_rdac->write(rsample); - break; + } break; } if((queue_count() < m_irq_rate) && (m_pcm_ctrl & 0x20)) { diff --git a/src/devices/bus/cbus/pc9801_86.h b/src/devices/bus/cbus/pc9801_86.h index 858a1193c75..7903f11e0b9 100644 --- a/src/devices/bus/cbus/pc9801_86.h +++ b/src/devices/bus/cbus/pc9801_86.h @@ -41,10 +41,11 @@ protected: void opna_reset_routes_config(machine_config &config); virtual ioport_constructor device_input_ports() const 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; void pc9801_86_config(machine_config &config); virtual u16 read_io_base() override; + TIMER_CALLBACK_MEMBER(dac_tick); + required_device<pc9801_slot_device> m_bus; required_device<ym2608_device> m_opna; diff --git a/src/devices/bus/centronics/epson_lx810l.cpp b/src/devices/bus/centronics/epson_lx810l.cpp index a1b0891dbe0..24f9b90c50f 100644 --- a/src/devices/bus/centronics/epson_lx810l.cpp +++ b/src/devices/bus/centronics/epson_lx810l.cpp @@ -329,7 +329,7 @@ void epson_lx810l_device::device_start() m_online_led.resolve(); m_ready_led.resolve(); - m_cr_timer = timer_alloc(TIMER_CR); + m_cr_timer = timer_alloc(FUNC(epson_lx810l_device::cr_tick), this); } @@ -344,26 +344,22 @@ void epson_lx810l_device::device_reset() //------------------------------------------------- -// device_timer - device-specific timer +// cr_tick - handle a carriage return //------------------------------------------------- -void epson_lx810l_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(epson_lx810l_device::cr_tick) { - switch (id) { - case TIMER_CR: - /* The firmware issues two half-steps in sequence, one immediately - * after the other. At full speed, the motor does two half-steps at - * each 833 microseconds. A timer fires the printhead twice, with - * the same period as each half-step (417 microseconds), but with - * a 356 microseconds delay relative to the motor steps. - */ - m_in_between_offset += param; + /* The firmware issues two half-steps in sequence, one immediately + * after the other. At full speed, the motor does two half-steps at + * each 833 microseconds. A timer fires the printhead twice, with + * the same period as each half-step (417 microseconds), but with + * a 356 microseconds delay relative to the motor steps. + */ + m_in_between_offset += param; - m_real_cr_steps--; - if (m_real_cr_steps) - m_cr_timer->adjust(attotime::from_usec(400), m_bitmap_printer->m_cr_direction); - break; - } + m_real_cr_steps--; + if (m_real_cr_steps) + m_cr_timer->adjust(attotime::from_usec(400), m_bitmap_printer->m_cr_direction); } diff --git a/src/devices/bus/centronics/epson_lx810l.h b/src/devices/bus/centronics/epson_lx810l.h index 82ec40cc1c2..1b5581a606b 100644 --- a/src/devices/bus/centronics/epson_lx810l.h +++ b/src/devices/bus/centronics/epson_lx810l.h @@ -57,7 +57,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; // optional information overrides virtual const tiny_rom_entry *device_rom_region() const override; @@ -74,6 +73,8 @@ private: uint8_t portc_r(offs_t offset); void portc_w(offs_t offset, uint8_t data); + TIMER_CALLBACK_MEMBER(cr_tick); + /* fake memory I/O to get past memory reset check */ uint8_t fakemem_r(); void fakemem_w(uint8_t data); diff --git a/src/devices/bus/centronics/printer.cpp b/src/devices/bus/centronics/printer.cpp index c954c85c95c..b1b136cfc66 100644 --- a/src/devices/bus/centronics/printer.cpp +++ b/src/devices/bus/centronics/printer.cpp @@ -27,17 +27,39 @@ centronics_printer_device::centronics_printer_device(const machine_config &mconf m_printer(*this, "printer") { } + //------------------------------------------------- // device_add_mconfig - add device configuration //------------------------------------------------- - void centronics_printer_device::device_add_mconfig(machine_config &config) { PRINTER(config, m_printer, 0); m_printer->online_callback().set(FUNC(centronics_printer_device::printer_online)); } +void centronics_printer_device::device_start() +{ + m_ack_timer = timer_alloc(FUNC(centronics_printer_device::ack_timer_tick), this); + m_busy_timer = timer_alloc(FUNC(centronics_printer_device::busy_timer_tick), this); + + /* register for state saving */ + save_item(NAME(m_strobe)); + save_item(NAME(m_data)); + save_item(NAME(m_busy)); +} + +void centronics_printer_device::device_reset() +{ + m_busy = false; + output_busy(m_busy); + output_fault(1); + output_ack(1); + output_select(1); +} + + + /*------------------------------------------------- printer_online - callback that sets us busy when the printer goes offline @@ -48,58 +70,45 @@ WRITE_LINE_MEMBER(centronics_printer_device::printer_online) output_perror(!state); } -void centronics_printer_device::device_timer(emu_timer &timer, device_timer_id id, int param) +/*------------------------------------------------- + ack_timer_tick - update the printer + acknowledge line after an appropriate delay +-------------------------------------------------*/ + +TIMER_CALLBACK_MEMBER(centronics_printer_device::ack_timer_tick) { - switch (id) + output_ack(param); + + if (!param) { - case TIMER_ACK: - output_ack(param); - - if (param == false) - { - /* data is now ready, output it */ - m_printer->output(m_data); - - /* ready to receive more data, return BUSY to low */ - m_busy_timer->adjust(attotime::from_usec(7), false); - } - break; - - case TIMER_BUSY: - m_busy = param; - output_busy(m_busy); - - if (param == true) - { - /* timer to turn ACK low to receive data */ - m_ack_timer->adjust(attotime::from_usec(10), false); - } - else - { - /* timer to return ACK to high state */ - m_ack_timer->adjust(attotime::from_usec(5), true); - } + /* data is now ready, output it */ + m_printer->output(m_data); + + /* ready to receive more data, return BUSY to low */ + m_busy_timer->adjust(attotime::from_usec(7), 0); } } -void centronics_printer_device::device_start() -{ - m_ack_timer = timer_alloc(TIMER_ACK); - m_busy_timer = timer_alloc(TIMER_BUSY); - - /* register for state saving */ - save_item(NAME(m_strobe)); - save_item(NAME(m_data)); - save_item(NAME(m_busy)); -} +/*------------------------------------------------- + busy_timer_tick - update the printer's + busy state +-------------------------------------------------*/ -void centronics_printer_device::device_reset() +TIMER_CALLBACK_MEMBER(centronics_printer_device::busy_timer_tick) { - m_busy = false; + m_busy = param; output_busy(m_busy); - output_fault(1); - output_ack(1); - output_select(1); + + if (param) + { + /* timer to turn ACK low to receive data */ + m_ack_timer->adjust(attotime::from_usec(10), 0); + } + else + { + /* timer to return ACK to high state */ + m_ack_timer->adjust(attotime::from_usec(5), 1); + } } /*------------------------------------------------- diff --git a/src/devices/bus/centronics/printer.h b/src/devices/bus/centronics/printer.h index 7d2e1623ae9..e959959be0c 100644 --- a/src/devices/bus/centronics/printer.h +++ b/src/devices/bus/centronics/printer.h @@ -33,17 +33,14 @@ 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 bool supports_pin35_5v() override { return true; } + private: DECLARE_WRITE_LINE_MEMBER( printer_online ); - enum - { - TIMER_ACK, - TIMER_BUSY - }; + TIMER_CALLBACK_MEMBER(ack_timer_tick); + TIMER_CALLBACK_MEMBER(busy_timer_tick); emu_timer *m_ack_timer; emu_timer *m_busy_timer; diff --git a/src/devices/bus/coco/cococart.cpp b/src/devices/bus/coco/cococart.cpp index 2dbf679f363..ec387378fb8 100644 --- a/src/devices/bus/coco/cococart.cpp +++ b/src/devices/bus/coco/cococart.cpp @@ -90,14 +90,6 @@ CONSTANTS ***************************************************************************/ -enum -{ - TIMER_CART, - TIMER_NMI, - TIMER_HALT -}; - - // definitions of RPK PCBs in layout.xml static const char *coco_rpk_pcbdefs[] = { @@ -149,11 +141,11 @@ cococart_slot_device::cococart_slot_device(const machine_config &mconfig, const void cococart_slot_device::device_start() { - for(int i=0; i<TIMER_POOL; i++ ) + for(int i=0; i < TIMER_POOL; i++ ) { - m_cart_line.timer[i] = timer_alloc(TIMER_CART); - m_nmi_line.timer[i] = timer_alloc(TIMER_NMI); - m_halt_line.timer[i] = timer_alloc(TIMER_HALT); + m_cart_line.timer[i] = timer_alloc(FUNC(cococart_slot_device::cart_line_timer_tick), this); + m_nmi_line.timer[i] = timer_alloc(FUNC(cococart_slot_device::nmi_line_timer_tick), this); + m_halt_line.timer[i] = timer_alloc(FUNC(cococart_slot_device::halt_line_timer_tick), this); } m_cart_line.timer_index = 0; @@ -204,28 +196,37 @@ void cococart_slot_device::device_start() //------------------------------------------------- -// device_timer - handle timer callbacks +// cart_line_timer_tick - update the output +// value for the cart's line to PIA1 CB1 //------------------------------------------------- -void cococart_slot_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(cococart_slot_device::cart_line_timer_tick) { - switch(id) - { - case TIMER_CART: - set_line(line::CART, m_cart_line, (line_value) param); - break; + set_line(line::CART, m_cart_line, (line_value) param); +} - case TIMER_NMI: - set_line(line::NMI, m_nmi_line, (line_value) param); - break; +//------------------------------------------------- +// nmi_line_timer_tick - update the output +// value sent to the CPU's NMI line +//------------------------------------------------- - case TIMER_HALT: - set_line(line::HALT, m_halt_line, (line_value) param); - break; - } +TIMER_CALLBACK_MEMBER(cococart_slot_device::nmi_line_timer_tick) +{ + set_line(line::NMI, m_nmi_line, (line_value) param); +} + +//------------------------------------------------- +// halt_line_timer_tick - update the output +// value sent to the CPU's HALT line +//------------------------------------------------- + +TIMER_CALLBACK_MEMBER(cococart_slot_device::halt_line_timer_tick) +{ + set_line(line::HALT, m_halt_line, (line_value) param); } + //------------------------------------------------- // cts_read //------------------------------------------------- diff --git a/src/devices/bus/coco/cococart.h b/src/devices/bus/coco/cococart.h index 1918ba05c40..b686ac0748d 100644 --- a/src/devices/bus/coco/cococart.h +++ b/src/devices/bus/coco/cococart.h @@ -69,7 +69,6 @@ public: // device-level overrides virtual void device_start() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; // image-level overrides virtual image_init_result call_load() override; @@ -121,10 +120,12 @@ private: coco_cartridge_line m_cart_line; coco_cartridge_line m_nmi_line; coco_cartridge_line m_halt_line; + public: devcb_write_line m_cart_callback; devcb_write_line m_nmi_callback; devcb_write_line m_halt_callback; + private: // cartridge device_cococart_interface *m_cart; @@ -133,6 +134,11 @@ private: void set_line(line ln, coco_cartridge_line &line, line_value value); void set_line_timer(coco_cartridge_line &line, line_value value); void twiddle_line_if_q(coco_cartridge_line &line); + + TIMER_CALLBACK_MEMBER(cart_line_timer_tick); + TIMER_CALLBACK_MEMBER(nmi_line_timer_tick); + TIMER_CALLBACK_MEMBER(halt_line_timer_tick); + public: static const char *line_value_string(line_value value); }; diff --git a/src/devices/bus/compucolor/floppy.cpp b/src/devices/bus/compucolor/floppy.cpp index 99a89e4f543..9c8a33870c1 100644 --- a/src/devices/bus/compucolor/floppy.cpp +++ b/src/devices/bus/compucolor/floppy.cpp @@ -127,7 +127,7 @@ void compucolor_floppy_port_device::device_start() void compucolor_floppy_device::device_start() { // allocate timer - m_timer = timer_alloc(); + m_timer = timer_alloc(FUNC(compucolor_floppy_device::rxd_tick), this); m_timer->adjust(attotime::from_hz(9600*8), 0, attotime::from_hz(9600*8)); // state saving @@ -138,10 +138,10 @@ void compucolor_floppy_device::device_start() //------------------------------------------------- -// device_timer - handle timer events +// rxd_tick - //------------------------------------------------- -void compucolor_floppy_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(compucolor_floppy_device::rxd_tick) { if (!m_sel && !m_rw) { diff --git a/src/devices/bus/compucolor/floppy.h b/src/devices/bus/compucolor/floppy.h index 8342a3668ed..66247ac9601 100644 --- a/src/devices/bus/compucolor/floppy.h +++ b/src/devices/bus/compucolor/floppy.h @@ -75,7 +75,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; // optional information overrides virtual void device_add_mconfig(machine_config &config) override; @@ -93,6 +92,7 @@ private: required_device<floppy_connector> m_floppy; + TIMER_CALLBACK_MEMBER(rxd_tick); bool read_bit(); void write_bit(bool bit); diff --git a/src/devices/bus/dmv/k210.cpp b/src/devices/bus/dmv/k210.cpp index 169ce2ed5f6..90f39e5bf0e 100644 --- a/src/devices/bus/dmv/k210.cpp +++ b/src/devices/bus/dmv/k210.cpp @@ -46,7 +46,7 @@ dmv_k210_device::dmv_k210_device(const machine_config &mconfig, const char *tag, void dmv_k210_device::device_start() { - m_clk1_timer = timer_alloc(0); + m_clk1_timer = timer_alloc(FUNC(dmv_k210_device::strobe_tick), this); // register for state saving save_item(NAME(m_portb)); @@ -65,10 +65,10 @@ void dmv_k210_device::device_reset() } //------------------------------------------------- -// device_timer - handler timer events +// strobe_tick - //------------------------------------------------- -void dmv_k210_device::device_timer(emu_timer &timer, device_timer_id tid, int param) +TIMER_CALLBACK_MEMBER(dmv_k210_device::strobe_tick) { m_centronics->write_strobe(CLEAR_LINE); } diff --git a/src/devices/bus/dmv/k210.h b/src/devices/bus/dmv/k210.h index ea29bf31f08..d49673b2415 100644 --- a/src/devices/bus/dmv/k210.h +++ b/src/devices/bus/dmv/k210.h @@ -28,7 +28,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 tid, int param) override; // optional information overrides virtual void device_add_mconfig(machine_config &config) override; @@ -53,6 +52,8 @@ private: DECLARE_WRITE_LINE_MEMBER(cent_autofd_w); DECLARE_WRITE_LINE_MEMBER(cent_init_w); + TIMER_CALLBACK_MEMBER(strobe_tick); + required_device<i8255_device> m_ppi; required_device<centronics_device> m_centronics; required_device<input_buffer_device> m_cent_data_in; diff --git a/src/devices/bus/ecbbus/grip.cpp b/src/devices/bus/ecbbus/grip.cpp index b4a09f78523..6de51191cd5 100644 --- a/src/devices/bus/ecbbus/grip.cpp +++ b/src/devices/bus/ecbbus/grip.cpp @@ -571,7 +571,20 @@ ecb_grip21_device::ecb_grip21_device(const machine_config &mconfig, const char * m_j3a(*this, "J3A"), m_j3b(*this, "J3B"), m_j7(*this, "J7"), - m_centronics_busy(0), m_centronics_fault(0), m_vol0(0), m_vol1(0), m_ia(0), m_ib(0), m_keydata(0), m_kbf(0), m_lps(0), m_page(0), m_flash(0), m_base(0), m_ppi_pa(0), m_ppi_pc(0), m_kb_timer(nullptr) + m_centronics_busy(0), + m_centronics_fault(0), + m_vol0(0), + m_vol1(0), + m_ia(0), + m_ib(0), + m_keydata(0), + m_kbf(0), + m_lps(0), + m_page(0), + m_flash(0), + m_base(0), + m_ppi_pa(0), + m_ppi_pc(0) { } @@ -585,10 +598,6 @@ void ecb_grip21_device::device_start() membank("videoram")->configure_entries(0, 2, m_video_ram, 0x8000); membank("videoram")->set_entry(0); - // allocate keyboard scan timer - m_kb_timer = timer_alloc(); - m_kb_timer->adjust(attotime::zero, 0, attotime::from_hz(2500)); - // register for state saving save_item(NAME(m_vol0)); save_item(NAME(m_vol1)); diff --git a/src/devices/bus/ecbbus/grip.h b/src/devices/bus/ecbbus/grip.h index a0914f28137..024a820e4e3 100644 --- a/src/devices/bus/ecbbus/grip.h +++ b/src/devices/bus/ecbbus/grip.h @@ -100,9 +100,6 @@ private: uint8_t m_ppi_pa; // PPI port A data uint8_t m_ppi_pc; // PPI port C data - // timers - emu_timer *m_kb_timer; - void vol0_w(uint8_t data); void vol1_w(uint8_t data); void flash_w(uint8_t data); diff --git a/src/devices/bus/econet/e01.cpp b/src/devices/bus/econet/e01.cpp index 3b6d137ebf1..256e545c702 100644 --- a/src/devices/bus/econet/e01.cpp +++ b/src/devices/bus/econet/e01.cpp @@ -426,7 +426,7 @@ void econet_e01_device::device_start() m_led.resolve(); // allocate timers - m_clk_timer = timer_alloc(); + m_clk_timer = timer_alloc(FUNC(econet_e01_device::clk_tick), this); // register for state saving save_item(NAME(m_adlc_ie)); @@ -451,10 +451,10 @@ void econet_e01_device::device_reset() //------------------------------------------------- -// device_timer - handler timer events +// clk_tick - update our clock output //------------------------------------------------- -void econet_e01_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(econet_e01_device::clk_tick) { if (m_clk_en) { diff --git a/src/devices/bus/econet/e01.h b/src/devices/bus/econet/e01.h index acffa76d13c..695e18c47cd 100644 --- a/src/devices/bus/econet/e01.h +++ b/src/devices/bus/econet/e01.h @@ -44,7 +44,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; // optional information overrides virtual const tiny_rom_entry *device_rom_region() const override; @@ -65,6 +64,9 @@ private: DECLARE_WRITE_LINE_MEMBER( fdc_drq_w ); DECLARE_WRITE_LINE_MEMBER( scsi_bsy_w ); DECLARE_WRITE_LINE_MEMBER( scsi_req_w ); + + TIMER_CALLBACK_MEMBER(clk_tick); + uint8_t read(offs_t offset); void write(offs_t offset, uint8_t data); uint8_t ram_select_r(); diff --git a/src/devices/bus/epson_sio/pf10.cpp b/src/devices/bus/epson_sio/pf10.cpp index e77edae7b77..067931da4e8 100644 --- a/src/devices/bus/epson_sio/pf10.cpp +++ b/src/devices/bus/epson_sio/pf10.cpp @@ -109,7 +109,7 @@ epson_pf10_device::epson_pf10_device(const machine_config &mconfig, const char * void epson_pf10_device::device_start() { - m_timer = timer_alloc(0); + m_timer = timer_alloc(FUNC(epson_pf10_device::serial_clk_tick), this); } //------------------------------------------------- @@ -122,17 +122,13 @@ void epson_pf10_device::device_reset() } //------------------------------------------------- -// device_timer - handler timer events +// serial_clk_tick - tick the CPU's external +// serial clock //------------------------------------------------- -void epson_pf10_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER( epson_pf10_device::serial_clk_tick ) { - switch (id) - { - case 0: - m_cpu->m6801_clock_serial(); - break; - } + m_cpu->m6801_clock_serial(); } diff --git a/src/devices/bus/epson_sio/pf10.h b/src/devices/bus/epson_sio/pf10.h index 266705ae924..ce5f2ee6f3d 100644 --- a/src/devices/bus/epson_sio/pf10.h +++ b/src/devices/bus/epson_sio/pf10.h @@ -34,7 +34,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; // optional information overrides virtual const tiny_rom_entry *device_rom_region() const override; @@ -63,6 +62,8 @@ private: uint8_t port2_r(); void port2_w(uint8_t data); + TIMER_CALLBACK_MEMBER( serial_clk_tick ); + void cpu_mem(address_map &map); required_device<hd6303y_cpu_device> m_cpu; diff --git a/src/devices/bus/epson_sio/tf20.cpp b/src/devices/bus/epson_sio/tf20.cpp index cd16fe2f9b1..a2f9c2e9320 100644 --- a/src/devices/bus/epson_sio/tf20.cpp +++ b/src/devices/bus/epson_sio/tf20.cpp @@ -149,8 +149,8 @@ void epson_tf20_device::device_start() if (!m_ram->started()) throw device_missing_dependencies(); - m_timer_serial = timer_alloc(0); - m_timer_tc = timer_alloc(1); + m_timer_serial = timer_alloc(FUNC(epson_tf20_device::serial_tick), this); + m_timer_tc = timer_alloc(FUNC(epson_tf20_device::tc_tick), this); // enable second half of ram m_cpu->space(AS_PROGRAM).install_ram(0x8000, 0xffff, m_ram->pointer() + 0x8000); @@ -175,31 +175,32 @@ void epson_tf20_device::device_reset() } //------------------------------------------------- -// device_timer - handler timer events +// serial_tick - update serial clocks //------------------------------------------------- -void epson_tf20_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER( epson_tf20_device::serial_tick ) { - switch (id) - { - case 0: - m_mpsc->rxca_w(1); - m_mpsc->rxca_w(0); - m_mpsc->txca_w(1); - m_mpsc->txca_w(0); - m_mpsc->rxcb_w(1); - m_mpsc->rxcb_w(0); - m_mpsc->txcb_w(1); - m_mpsc->txcb_w(0); - break; - - case 1: - logerror("%s: tc off\n", tag()); - m_fdc->tc_w(false); - break; - } + m_mpsc->rxca_w(1); + m_mpsc->rxca_w(0); + m_mpsc->txca_w(1); + m_mpsc->txca_w(0); + m_mpsc->rxcb_w(1); + m_mpsc->rxcb_w(0); + m_mpsc->txcb_w(1); + m_mpsc->txcb_w(0); } +//------------------------------------------------- +// tc_tick - update the FDC terminal count flag +//------------------------------------------------- + +TIMER_CALLBACK_MEMBER( epson_tf20_device::tc_tick ) +{ + logerror("%s: tc off\n", tag()); + m_fdc->tc_w(false); +} + + //************************************************************************** // CPU & MEMORY diff --git a/src/devices/bus/epson_sio/tf20.h b/src/devices/bus/epson_sio/tf20.h index 98602ec2562..906ae0a4b9c 100644 --- a/src/devices/bus/epson_sio/tf20.h +++ b/src/devices/bus/epson_sio/tf20.h @@ -36,7 +36,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; // optional information overrides virtual const tiny_rom_entry *device_rom_region() const override; @@ -60,6 +59,9 @@ private: uint8_t upd765_tc_r(); void fdc_control_w(uint8_t data); + TIMER_CALLBACK_MEMBER( serial_tick ); + TIMER_CALLBACK_MEMBER( tc_tick ); + void cpu_io(address_map &map); void cpu_mem(address_map &map); diff --git a/src/devices/bus/gio64/newport.cpp b/src/devices/bus/gio64/newport.cpp index c5a071eb786..ab796ba3645 100644 --- a/src/devices/bus/gio64/newport.cpp +++ b/src/devices/bus/gio64/newport.cpp @@ -1111,7 +1111,7 @@ gio64_xl24_device::gio64_xl24_device(const machine_config &mconfig, const char * void newport_base_device::device_start() { - m_dcb_timeout_timer = timer_alloc(DCB_TIMEOUT); + m_dcb_timeout_timer = timer_alloc(FUNC(newport_base_device::dcb_timeout_tick), this); save_item(NAME(m_rex3.m_draw_mode0)); save_item(NAME(m_rex3.m_color_host)); @@ -1282,12 +1282,9 @@ void newport_base_device::stop_logging() } #endif -void newport_base_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(newport_base_device::dcb_timeout_tick) { - if (id == DCB_TIMEOUT) - { - m_rex3.m_status &= ~STATUS_BACKBUSY; - } + m_rex3.m_status &= ~STATUS_BACKBUSY; } uint32_t newport_base_device::screen_update(screen_device &device, bitmap_rgb32 &bitmap, const rectangle &cliprect) diff --git a/src/devices/bus/gio64/newport.h b/src/devices/bus/gio64/newport.h index 3dd1a27ba40..101ca7a6e61 100644 --- a/src/devices/bus/gio64/newport.h +++ b/src/devices/bus/gio64/newport.h @@ -311,7 +311,6 @@ public: protected: // device_t overrides - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; virtual void device_add_mconfig(machine_config &config) override; virtual void device_start() override; virtual void device_reset() override; @@ -319,7 +318,7 @@ protected: void device_add_mconfig(machine_config &config, uint32_t xmap_revision, uint32_t cmap_revision, uint32_t global_mask); void mem_map(address_map &map) override; - static constexpr device_timer_id DCB_TIMEOUT = 0; + TIMER_CALLBACK_MEMBER(dcb_timeout_tick); enum { diff --git a/src/devices/bus/hp9845_io/98035.cpp b/src/devices/bus/hp9845_io/98035.cpp index ff092246ab6..79017edd4c2 100644 --- a/src/devices/bus/hp9845_io/98035.cpp +++ b/src/devices/bus/hp9845_io/98035.cpp @@ -186,8 +186,8 @@ void hp98035_io_card_device::device_start() save_item(NAME(m_prev_clock_keys)); save_item(NAME(m_clock_key_cnt)); - m_msec_timer = timer_alloc(MSEC_TMR_ID); - m_clock_timer = timer_alloc(CLOCK_TMR_ID); + m_msec_timer = timer_alloc(FUNC(hp98035_io_card_device::msec_tick), this); + m_clock_timer = timer_alloc(FUNC(hp98035_io_card_device::clock_tick), this); } void hp98035_io_card_device::device_reset() @@ -207,50 +207,51 @@ void hp98035_io_card_device::device_reset() half_init(); } -void hp98035_io_card_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(hp98035_io_card_device::msec_tick) { - if (id == MSEC_TMR_ID) { - // On real hw there's a full 4-bit decimal counter, but only the LSB is used to - // generate interrupts - m_np_irq = !m_np_irq; - update_dc(); - } else if (id == CLOCK_TMR_ID) { - // Update digit multiplexer - if (m_clock_state == CLOCK_OFF) { - m_clock_mux = 0; - } else { - m_clock_mux <<= 1; - if ((m_clock_mux & 7) == 0) { - m_clock_mux = 1; - } - } - // Act on clock chip "keys" - if (m_clock_keys == 0 || m_clock_keys != m_prev_clock_keys) { - m_clock_key_cnt = 0; - if (m_clock_keys == 0 && m_clock_state == CLOCK_HHMM) { - // Keys released in HHMM state -> turn display off - // In real hw there is probably 1 s delay - m_clock_state = CLOCK_OFF; - regen_clock_image(); - } - } else if (m_clock_key_cnt < KEY_PRESS_LONG) { - m_clock_key_cnt++; - if (m_clock_key_cnt == KEY_PRESS_SHORT) { - /// Short key press - clock_short_press(); - } else if (m_clock_key_cnt == KEY_PRESS_LONG) { - // Long key press - clock_long_press(); - } + // On real hw there's a full 4-bit decimal counter, but only the LSB is used to + // generate interrupts + m_np_irq = !m_np_irq; + update_dc(); +} + +TIMER_CALLBACK_MEMBER(hp98035_io_card_device::clock_tick) +{ + // Update digit multiplexer + if (m_clock_state == CLOCK_OFF) { + m_clock_mux = 0; + } else { + m_clock_mux <<= 1; + if ((m_clock_mux & 7) == 0) { + m_clock_mux = 1; } - m_prev_clock_keys = m_clock_keys; - // Count seconds - m_clock_1s_div++; - if (m_clock_1s_div >= DIGIT_MUX_FREQ.value()) { - m_clock_1s_div = 0; - advance_seconds(); + } + // Act on clock chip "keys" + if (m_clock_keys == 0 || m_clock_keys != m_prev_clock_keys) { + m_clock_key_cnt = 0; + if (m_clock_keys == 0 && m_clock_state == CLOCK_HHMM) { + // Keys released in HHMM state -> turn display off + // In real hw there is probably 1 s delay + m_clock_state = CLOCK_OFF; regen_clock_image(); } + } else if (m_clock_key_cnt < KEY_PRESS_LONG) { + m_clock_key_cnt++; + if (m_clock_key_cnt == KEY_PRESS_SHORT) { + /// Short key press + clock_short_press(); + } else if (m_clock_key_cnt == KEY_PRESS_LONG) { + // Long key press + clock_long_press(); + } + } + m_prev_clock_keys = m_clock_keys; + // Count seconds + m_clock_1s_div++; + if (m_clock_1s_div >= DIGIT_MUX_FREQ.value()) { + m_clock_1s_div = 0; + advance_seconds(); + regen_clock_image(); } } diff --git a/src/devices/bus/hp9845_io/98035.h b/src/devices/bus/hp9845_io/98035.h index 48091cf24e3..f92e1734047 100644 --- a/src/devices/bus/hp9845_io/98035.h +++ b/src/devices/bus/hp9845_io/98035.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-level overrides virtual ioport_constructor device_input_ports() const override; @@ -57,6 +56,9 @@ private: uint8_t clr_inten_r(); void clr_inten_w(uint8_t data); + TIMER_CALLBACK_MEMBER(msec_tick); + TIMER_CALLBACK_MEMBER(clock_tick); + void np_io_map(address_map &map); void np_program_map(address_map &map); diff --git a/src/devices/bus/hp9845_io/hp9885.cpp b/src/devices/bus/hp9845_io/hp9885.cpp index 40692291cbe..1fadbc54679 100644 --- a/src/devices/bus/hp9845_io/hp9885.cpp +++ b/src/devices/bus/hp9845_io/hp9885.cpp @@ -336,9 +336,9 @@ void hp9885_device::device_start() save_item(NAME(m_am_detector)); save_item(NAME(m_crc)); - m_fsm_timer = timer_alloc(FSM_TMR_ID); - m_head_timer = timer_alloc(HEAD_TMR_ID); - m_bit_byte_timer = timer_alloc(BIT_BYTE_TMR_ID); + m_fsm_timer = timer_alloc(FUNC(hp9885_device::fsm_tick), this); + m_head_timer = timer_alloc(FUNC(hp9885_device::head_tick), this); + m_bit_byte_timer = timer_alloc(FUNC(hp9885_device::bit_byte_tick), this); m_drive = m_drive_connector->get_device(); @@ -359,172 +359,170 @@ void hp9885_device::device_reset() set_state(FSM_IDLE); } -void hp9885_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(hp9885_device::fsm_tick) { - LOG_TIMER("Tmr %.06f ID %d FSM %d HD %d\n" , machine().time().as_double() , id , m_fsm_state , m_head_state); + LOG_TIMER("Tmr %.06f ID %d FSM %d HD %d\n" , machine().time().as_double() , FSM_TMR_ID , m_fsm_state , m_head_state); + do_FSM(); +} - switch (id) { - case FSM_TMR_ID: +TIMER_CALLBACK_MEMBER(hp9885_device::head_tick) +{ + LOG_TIMER("Tmr %.06f ID %d FSM %d HD %d\n" , machine().time().as_double() , HEAD_TMR_ID , m_fsm_state , m_head_state); + if (m_head_state == HEAD_SETTLING) { + LOG_HEAD("%.06f Head loaded\n" , machine().time().as_double()); + m_head_state = HEAD_LOADED; + // Trigger actions to be done on head loading do_FSM(); - break; + m_head_timer->adjust(attotime::from_msec(HEAD_TO_MS - HD_SETTLE_MS)); + } else { + LOG_HEAD("%.06f Head unloaded\n" , machine().time().as_double()); + m_head_state = HEAD_UNLOADED; + } +} - case HEAD_TMR_ID: - if (m_head_state == HEAD_SETTLING) { - LOG_HEAD("%.06f Head loaded\n" , machine().time().as_double()); - m_head_state = HEAD_LOADED; - // Trigger actions to be done on head loading - do_FSM(); - m_head_timer->adjust(attotime::from_msec(HEAD_TO_MS - HD_SETTLE_MS)); - } else { - LOG_HEAD("%.06f Head unloaded\n" , machine().time().as_double()); - m_head_state = HEAD_UNLOADED; - } - break; +TIMER_CALLBACK_MEMBER(hp9885_device::bit_byte_tick) +{ + LOG_TIMER("Tmr %.06f ID %d FSM %d HD %d\n" , machine().time().as_double() , BIT_BYTE_TMR_ID , m_fsm_state , m_head_state); - case BIT_BYTE_TMR_ID: + switch (m_fsm_state) { + case FSM_WAIT_ID_AM: + case FSM_WAIT_DATA_AM: { - switch (m_fsm_state) { - case FSM_WAIT_ID_AM: - case FSM_WAIT_DATA_AM: - { - attotime edge; - attotime tm; - edge = m_drive->get_next_transition(m_pll.ctime); - bool half_bit = m_pll.feed_read_data(tm , edge , attotime::never); - m_am_detector <<= 1; - m_am_detector |= half_bit; - if (m_am_detector == 0x55552a54) { - // ID AM - // CDCDCDCDCDCDCDCD - // 0 0 0 0 1 1 1 0 - // 0 1 1 1 0 0 0 0 - LOG_DISK("Got ID AM\n"); + attotime edge; + attotime tm; + edge = m_drive->get_next_transition(m_pll.ctime); + bool half_bit = m_pll.feed_read_data(tm , edge , attotime::never); + m_am_detector <<= 1; + m_am_detector |= half_bit; + if (m_am_detector == 0x55552a54) { + // ID AM + // CDCDCDCDCDCDCDCD + // 0 0 0 0 1 1 1 0 + // 0 1 1 1 0 0 0 0 + LOG_DISK("Got ID AM\n"); + preset_crc(); + m_word_cnt = 2; + set_state(FSM_RD_ID); + } else if (m_am_detector == 0x55552a44) { + // DATA AM + // CDCDCDCDCDCDCDCD + // 0 0 0 0 1 0 1 0 + // 0 1 1 1 0 0 0 0 + LOG_DISK("Got Data AM\n"); + if (m_fsm_state == FSM_WAIT_DATA_AM) { + m_rev_cnt = 0; + if (BIT(m_status , STS_XFER_COMPLETE)) { + output_status(); + return; + } else { preset_crc(); - m_word_cnt = 2; - set_state(FSM_RD_ID); - } else if (m_am_detector == 0x55552a44) { - // DATA AM - // CDCDCDCDCDCDCDCD - // 0 0 0 0 1 0 1 0 - // 0 1 1 1 0 0 0 0 - LOG_DISK("Got Data AM\n"); - if (m_fsm_state == FSM_WAIT_DATA_AM) { - m_rev_cnt = 0; - if (BIT(m_status , STS_XFER_COMPLETE)) { - output_status(); - return; - } else { - preset_crc(); - if (m_op == OP_READ) { - m_word_cnt = 129; - set_state(FSM_RD_DATA); - } else { - m_word_cnt = 130; - set_state(FSM_WR_DATA); - m_pll.start_writing(m_pll.ctime); - m_had_transition = false; - wr_word(m_input); - set_ibf(false); - } - } + if (m_op == OP_READ) { + m_word_cnt = 129; + set_state(FSM_RD_DATA); + } else { + m_word_cnt = 130; + set_state(FSM_WR_DATA); + m_pll.start_writing(m_pll.ctime); + m_had_transition = false; + wr_word(m_input); + set_ibf(false); } } } - break; + } + } + break; - case FSM_RD_ID: - { - // This is needed when state is switched to one of the AM waiting states - m_am_detector = 0; - auto word = rd_word(); - m_word_cnt--; - LOG_DISK("W %04x C %u\n" , word , m_word_cnt); - if (m_word_cnt && word != ((m_seek_sector << 8) | m_track)) { - set_state(FSM_WAIT_ID_AM); - } else if (m_word_cnt == 0) { - if (m_crc) { - LOG_DISK("Wrong CRC in ID\n"); - set_state(FSM_WAIT_ID_AM); - } else { - LOG_DISK("Sector found\n"); - set_state(FSM_WAIT_DATA_AM); - } - } + case FSM_RD_ID: + { + // This is needed when state is switched to one of the AM waiting states + m_am_detector = 0; + auto word = rd_word(); + m_word_cnt--; + LOG_DISK("W %04x C %u\n" , word , m_word_cnt); + if (m_word_cnt && word != ((m_seek_sector << 8) | m_track)) { + set_state(FSM_WAIT_ID_AM); + } else if (m_word_cnt == 0) { + if (m_crc) { + LOG_DISK("Wrong CRC in ID\n"); + set_state(FSM_WAIT_ID_AM); + } else { + LOG_DISK("Sector found\n"); + set_state(FSM_WAIT_DATA_AM); } - break; + } + } + break; - case FSM_RD_DATA: - { - auto word = rd_word(); - m_word_cnt--; - LOG_DISK("W %04x C %u\n" , word , m_word_cnt); - if (m_word_cnt >= 1) { - if (!BIT(m_status , STS_XFER_COMPLETE)) { - m_output = word; - m_obf = true; - update_busy(); - } - } else if (m_word_cnt == 0) { - if (m_crc) { - LOG_DISK("Wrong CRC in data\n"); - } - // Move to next sector - adv_sector(); - if (BIT(m_status , STS_XFER_COMPLETE) || m_sector_cnt == 0) { - BIT_SET(m_status , STS_XFER_COMPLETE); - output_status(); - } else { - set_state(FSM_POSITIONING); - do_FSM(); - } - return; - } + case FSM_RD_DATA: + { + auto word = rd_word(); + m_word_cnt--; + LOG_DISK("W %04x C %u\n" , word , m_word_cnt); + if (m_word_cnt >= 1) { + if (!BIT(m_status , STS_XFER_COMPLETE)) { + m_output = word; + m_obf = true; + update_busy(); } - break; + } else if (m_word_cnt == 0) { + if (m_crc) { + LOG_DISK("Wrong CRC in data\n"); + } + // Move to next sector + adv_sector(); + if (BIT(m_status , STS_XFER_COMPLETE) || m_sector_cnt == 0) { + BIT_SET(m_status , STS_XFER_COMPLETE); + output_status(); + } else { + set_state(FSM_POSITIONING); + do_FSM(); + } + return; + } + } + break; - case FSM_WR_DATA: - { - m_word_cnt--; - if (m_word_cnt > 2) { - if (BIT(m_status , STS_XFER_COMPLETE)) { - wr_word(0); - } else { - wr_word(m_input); - if (m_word_cnt > 3) { - set_ibf(false); - } - } - } else if (m_word_cnt == 2) { - wr_word(m_crc); - } else if (m_word_cnt == 1) { - // Post-amble - wr_word(0); - } else { - m_pll.stop_writing(m_drive , m_pll.ctime); - // Move to next sector - adv_sector(); - if (BIT(m_status , STS_XFER_COMPLETE) || m_sector_cnt == 0) { - BIT_SET(m_status , STS_XFER_COMPLETE); - output_status(); - } else { - set_ibf(false); - set_state(FSM_POSITIONING); - do_FSM(); - } - return; + case FSM_WR_DATA: + { + m_word_cnt--; + if (m_word_cnt > 2) { + if (BIT(m_status , STS_XFER_COMPLETE)) { + wr_word(0); + } else { + wr_word(m_input); + if (m_word_cnt > 3) { + set_ibf(false); } } - break; - - default: - LOG("Invalid FSM state %d\n" , m_fsm_state); - set_state(FSM_IDLE); + } else if (m_word_cnt == 2) { + wr_word(m_crc); + } else if (m_word_cnt == 1) { + // Post-amble + wr_word(0); + } else { + m_pll.stop_writing(m_drive , m_pll.ctime); + // Move to next sector + adv_sector(); + if (BIT(m_status , STS_XFER_COMPLETE) || m_sector_cnt == 0) { + BIT_SET(m_status , STS_XFER_COMPLETE); + output_status(); + } else { + set_ibf(false); + set_state(FSM_POSITIONING); + do_FSM(); + } return; } - timer.adjust(m_pll.ctime - machine().time()); } break; + + default: + LOG("Invalid FSM state %d\n" , m_fsm_state); + set_state(FSM_IDLE); + return; } + m_bit_byte_timer->adjust(m_pll.ctime - machine().time()); } void hp9885_device::floppy_ready_cb(floppy_image_device *floppy , int state) diff --git a/src/devices/bus/hp9845_io/hp9885.h b/src/devices/bus/hp9845_io/hp9885.h index a782df5d7df..1c9af5c3066 100644 --- a/src/devices/bus/hp9845_io/hp9885.h +++ b/src/devices/bus/hp9845_io/hp9885.h @@ -38,7 +38,6 @@ protected: virtual void device_add_mconfig(machine_config &config) override; virtual void device_start() override; virtual void device_reset() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; private: // FSM states @@ -106,6 +105,10 @@ private: // PLL fdc_pll_t m_pll; + TIMER_CALLBACK_MEMBER(fsm_tick); + TIMER_CALLBACK_MEMBER(head_tick); + TIMER_CALLBACK_MEMBER(bit_byte_tick); + void floppy_ready_cb(floppy_image_device *floppy , int state); void floppy_index_cb(floppy_image_device *floppy , int state); diff --git a/src/devices/bus/ieee488/c2040fdc.cpp b/src/devices/bus/ieee488/c2040fdc.cpp index 5998bb43435..18c02bba831 100644 --- a/src/devices/bus/ieee488/c2040fdc.cpp +++ b/src/devices/bus/ieee488/c2040fdc.cpp @@ -111,7 +111,7 @@ void c2040_fdc_device::device_start() m_write_error.resolve_safe(); // allocate timer - t_gen = timer_alloc(0); + t_gen = timer_alloc(FUNC(c2040_fdc_device::update_state), this); // register for state saving save_item(NAME(m_mtr0)); @@ -149,10 +149,10 @@ void c2040_fdc_device::device_reset() //------------------------------------------------- -// device_timer - handler timer events +// update_state - pump our 'live' events //------------------------------------------------- -void c2040_fdc_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(c2040_fdc_device::update_state) { live_sync(); live_run(); diff --git a/src/devices/bus/ieee488/c2040fdc.h b/src/devices/bus/ieee488/c2040fdc.h index f7b045cc0b3..2198f6aa738 100644 --- a/src/devices/bus/ieee488/c2040fdc.h +++ b/src/devices/bus/ieee488/c2040fdc.h @@ -59,11 +59,12 @@ protected: virtual void device_start() override; virtual void device_clock_changed() override; virtual void device_reset() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; // optional information overrides virtual const tiny_rom_entry *device_rom_region() const override; + TIMER_CALLBACK_MEMBER(update_state); + void stp_w(floppy_image_device *floppy, int mtr, int &old_stp, int stp); enum { diff --git a/src/devices/bus/ieee488/c8050fdc.cpp b/src/devices/bus/ieee488/c8050fdc.cpp index f08e434ea20..eea107417c9 100644 --- a/src/devices/bus/ieee488/c8050fdc.cpp +++ b/src/devices/bus/ieee488/c8050fdc.cpp @@ -112,7 +112,7 @@ void c8050_fdc_device::device_start() m_write_error.resolve_safe(); // allocate timer - t_gen = timer_alloc(0); + t_gen = timer_alloc(FUNC(c8050_fdc_device::update_state), this); // register for state saving save_item(NAME(m_mtr0)); @@ -141,10 +141,10 @@ void c8050_fdc_device::device_reset() //------------------------------------------------- -// device_timer - handler timer events +// update_state - pump our 'live' events //------------------------------------------------- -void c8050_fdc_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(c8050_fdc_device::update_state) { live_sync(); live_run(); diff --git a/src/devices/bus/ieee488/c8050fdc.h b/src/devices/bus/ieee488/c8050fdc.h index b4c8b96c52e..dd390b1b7c5 100644 --- a/src/devices/bus/ieee488/c8050fdc.h +++ b/src/devices/bus/ieee488/c8050fdc.h @@ -60,11 +60,12 @@ protected: // device-level overrides virtual void device_start() override; virtual void device_reset() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; // optional information overrides virtual const tiny_rom_entry *device_rom_region() const override; + TIMER_CALLBACK_MEMBER(update_state); + void stp_w(floppy_image_device *floppy, int mtr, int &old_stp, int stp); enum { diff --git a/src/devices/bus/ieee488/grid2102.cpp b/src/devices/bus/ieee488/grid2102.cpp index 9ef4fac6abf..4e6bc92c391 100644 --- a/src/devices/bus/ieee488/grid2102.cpp +++ b/src/devices/bus/ieee488/grid2102.cpp @@ -86,10 +86,10 @@ grid210x_device::grid210x_device(const machine_config &mconfig, device_type type void grid210x_device::device_start() { m_bus->ndac_w(this, 1); m_bus->nrfd_w(this, 1); - m_delay_timer = timer_alloc(0); + m_delay_timer = timer_alloc(FUNC(grid210x_device::delay_tick), this); } -void grid210x_device::device_timer(emu_timer &timer, device_timer_id id, int param) { +TIMER_CALLBACK_MEMBER(grid210x_device::delay_tick) { if (m_floppy_loop_state == GRID210X_STATE_READING_DATA) { std::unique_ptr<uint8_t[]> data(new uint8_t[io_size]); fseek(floppy_sector_number * 512, SEEK_SET); diff --git a/src/devices/bus/ieee488/grid2102.h b/src/devices/bus/ieee488/grid2102.h index 8bc475d6f84..11cdbcecdd0 100644 --- a/src/devices/bus/ieee488/grid2102.h +++ b/src/devices/bus/ieee488/grid2102.h @@ -33,7 +33,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_ieee488_interface overrides virtual void ieee488_eoi(int state) override; @@ -56,7 +55,10 @@ protected: void accept_transfer(); void update_ndac(int atn); + private: + TIMER_CALLBACK_MEMBER(delay_tick); + int m_gpib_loop_state; int m_floppy_loop_state; uint8_t m_last_recv_byte; @@ -74,6 +76,7 @@ private: std::queue<uint8_t> m_output_data_buffer; uint16_t io_size; emu_timer *m_delay_timer; + protected: attotime read_delay; }; diff --git a/src/devices/bus/ieee488/hp9122c.cpp b/src/devices/bus/ieee488/hp9122c.cpp index 2a001d2a4d0..f9619617ca1 100644 --- a/src/devices/bus/ieee488/hp9122c.cpp +++ b/src/devices/bus/ieee488/hp9122c.cpp @@ -91,7 +91,7 @@ void hp9122c_device::device_start() save_item(NAME(m_ds0)); save_item(NAME(m_ds1)); - m_motor_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(hp9122c_device::motor_timeout), this)); + m_motor_timer = timer_alloc(FUNC(hp9122c_device::motor_timeout), this); } TIMER_CALLBACK_MEMBER(hp9122c_device::motor_timeout) diff --git a/src/devices/bus/ieee488/hp9895.cpp b/src/devices/bus/ieee488/hp9895.cpp index b133c7fbf3e..3cd380d5eb8 100644 --- a/src/devices/bus/ieee488/hp9895.cpp +++ b/src/devices/bus/ieee488/hp9895.cpp @@ -58,11 +58,11 @@ #include "hp9895.h" #include "formats/hpi_dsk.h" -// Debugging -#define VERBOSE 1 -#define LOG(x) do { if (VERBOSE) logerror x; } while (0) -#define VERBOSE_0 0 -#define LOG_0(x) do { if (VERBOSE_0) logerror x; } while (0) +#define LOG_LEVEL0 (0x1U << 1) +#define LOG_LEVEL1 (0x3U << 1) + +#define VERBOSE (LOG_LEVEL1) +#include "logmacro.h" // Macros to clear/set single bits #define BIT_MASK(n) (1U << (n)) @@ -116,13 +116,6 @@ #define REG_SWITCHES_TIMEOUT_BIT 6 // TIMEOUT (1) #define REG_SWITCHES_AMDT_BIT 7 // Address mark detected (1) -// Timers -enum { - TIMEOUT_TMR_ID, - BYTE_TMR_ID, - HALF_BIT_TMR_ID -}; - // Timings #define TIMEOUT_MSEC 450 // Timeout duration (ms) #define HPMODE_BIT_FREQ 500000 // HP-mode bit frequency (Hz) @@ -198,9 +191,9 @@ void hp9895_device::device_start() save_item(NAME(m_hiden)); save_item(NAME(m_mgnena)); - m_timeout_timer = timer_alloc(TIMEOUT_TMR_ID); - m_byte_timer = timer_alloc(BYTE_TMR_ID); - m_half_bit_timer = timer_alloc(HALF_BIT_TMR_ID); + m_timeout_timer = timer_alloc(FUNC(hp9895_device::timeout_timer_tick), this); + m_byte_timer = timer_alloc(FUNC(hp9895_device::byte_timer_tick), this); + m_half_bit_timer = timer_alloc(FUNC(hp9895_device::half_bit_timer_tick), this); for (auto& d : m_drives) { d->get_device()->setup_ready_cb(floppy_image_device::ready_cb(&hp9895_device::floppy_ready_cb , this)); @@ -236,159 +229,150 @@ void hp9895_device::device_reset() m_half_bit_timer->reset(); } -void hp9895_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(hp9895_device::timeout_timer_tick) { - switch (id) { - case TIMEOUT_TMR_ID: - LOG(("Timeout!\n")); - m_timeout = true; - if (m_mgnena) { - // CPU is resumed by timeout if MGNENA=1 - m_cpu->trigger(1); - } - break; + LOGMASKED(LOG_LEVEL1, "Timeout\n"); + m_timeout = true; + if (m_mgnena) { + // CPU is resumed by timeout if MGNENA=1 + m_cpu->trigger(1); + } +} - case BYTE_TMR_ID: - { - if (m_accdata) { - // Resume CPU when it's waiting for SDOK - m_cpu->trigger(1); +TIMER_CALLBACK_MEMBER(hp9895_device::byte_timer_tick) +{ + if (m_accdata) { + // Resume CPU when it's waiting for SDOK + m_cpu->trigger(1); + } else { + // No access to data register by CPU + LOGMASKED(LOG_LEVEL1, "Data overrun\n"); + m_overrun = true; + } + m_accdata = false; + + m_crcerr_syn = m_crc != 0; + + if (!BIT(m_cntl_reg , REG_CNTL_CRCON_BIT)) { + // CRC not enabled, keep it in preset state (all ones) + preset_crc(); + } + + attotime sdok_time{machine().time()}; + LOGMASKED(LOG_LEVEL0, "SDOK @ %.06f\n" , sdok_time.as_double()); + bool do_crc_upd = true; + if (BIT(m_cntl_reg , REG_CNTL_WRITON_BIT)) { + // Writing + m_pll.commit(get_write_device() , sdok_time); + m_pll.ctime = sdok_time; + + // Check for AMDT when in loopback mode + if (!m_lckup && !m_amdt && BIT(m_cntl_reg , REG_CNTL_READON_BIT)) { + if (m_hiden) { + m_amdt = m_data_sr != 0xff; } else { - // No access to data register by CPU - LOG(("Data overrun!\n")); - m_overrun = true; + m_amdt = m_data_sr != 0; } - m_accdata = false; - - m_crcerr_syn = m_crc != 0; + } - if (!BIT(m_cntl_reg , REG_CNTL_CRCON_BIT)) { - // CRC not enabled, keep it in preset state (all ones) - preset_crc(); + LOGMASKED(LOG_LEVEL0, "WR D=%02x/C=%02x\n" , m_data_sr , m_clock_sr); + do_crc_upd = false; + for (unsigned i = 0; i < 8; i++) { + bool clock_bit; + bool data_bit; + + clock_bit = shift_sr(m_clock_sr, false); + data_bit = shift_sr(m_data_sr, true); + + if (BIT(m_cntl_reg , REG_CNTL_CRCOUT_BIT)) { + // Substitute data bits from DSR with those from CRC when CRCOUT=1 + data_bit = BIT(m_crc , 15); + m_crc <<= 1; + } else if (BIT(m_cntl_reg , REG_CNTL_CRCON_BIT)) { + // Update CRC + update_crc(data_bit); } + write_bit(data_bit, clock_bit); + } + // When shifting is done DSR is filled with 1s and CSR with 0s + } + if (BIT(m_cntl_reg , REG_CNTL_READON_BIT)) { + // Reading + m_pll.ctime = sdok_time; - attotime sdok_time{machine().time()}; - LOG_0(("SDOK @ %.06f\n" , sdok_time.as_double())); - bool do_crc_upd = true; + for (unsigned i = 0; i < 8; i++) { + read_bit(do_crc_upd); + } + LOGMASKED(LOG_LEVEL0, "RD D=%02x/C=%02x\n" , m_data_sr , m_clock_sr); + } + LOGMASKED(LOG_LEVEL0, "next SDOK @ %.06f\n" , m_pll.ctime.as_double()); + m_byte_timer->adjust(m_pll.ctime - sdok_time); +} + +TIMER_CALLBACK_MEMBER(hp9895_device::half_bit_timer_tick) +{ + m_pll.ctime = machine().time(); + if (m_lckup) { + // Trying to lock on synchronization bytes + attotime edge; + attotime tm; + get_next_transition(m_pll.ctime, edge); + bool half_bit0 = m_pll.feed_read_data(tm , edge , attotime::never); + get_next_transition(m_pll.ctime, edge); + bool half_bit1 = m_pll.feed_read_data(tm , edge , attotime::never); + if (half_bit0 == half_bit1) { + // If half bits are equal, no synch + LOGMASKED(LOG_LEVEL0, "Reset sync_cnt\n"); + m_sync_cnt = 0; + } else if (++m_sync_cnt >= MIN_SYNC_BITS) { + // Synchronized, now wait for AM + LOGMASKED(LOG_LEVEL0, "Synchronized @ %.6f\n" , machine().time().as_double()); + m_lckup = false; if (BIT(m_cntl_reg , REG_CNTL_WRITON_BIT)) { - // Writing - m_pll.commit(get_write_device() , sdok_time); - m_pll.ctime = sdok_time; - - // Check for AMDT when in loopback mode - if (!m_lckup && !m_amdt && BIT(m_cntl_reg , REG_CNTL_READON_BIT)) { - if (m_hiden) { - m_amdt = m_data_sr != 0xff; - } else { - m_amdt = m_data_sr != 0; - } + // When loopback is active, leave AM detection to byte timer as + // byte boundary is already synchronized + m_half_bit_timer->reset(); + return; + } else { + // Align with bit cell + // Synchronization bits in HP mode: 32x 1s -> C/D bits = 01010101... + // Synchronization bits in IBM mode: 32x 0s -> C/D bits = 10101010... + if (m_hiden != half_bit1) { + // Discard 1/2 bit cell if synchronization achieved in the clock part + get_next_transition(m_pll.ctime, edge); + m_pll.feed_read_data(tm , edge , attotime::never); } - - LOG_0(("WR D=%02x/C=%02x\n" , m_data_sr , m_clock_sr)); - do_crc_upd = false; - for (unsigned i = 0; i < 8; i++) { - bool clock_bit; - bool data_bit; - - clock_bit = shift_sr(m_clock_sr, false); - data_bit = shift_sr(m_data_sr, true); - - if (BIT(m_cntl_reg , REG_CNTL_CRCOUT_BIT)) { - // Substitute data bits from DSR with those from CRC when CRCOUT=1 - data_bit = BIT(m_crc , 15); - m_crc <<= 1; - } else if (BIT(m_cntl_reg , REG_CNTL_CRCON_BIT)) { - // Update CRC - update_crc(data_bit); - } - write_bit(data_bit, clock_bit); + // Load CSR & DSR as they are after synchronization bits + if (m_hiden) { + m_clock_sr = 0; + m_data_sr = ~0; + } else { + m_clock_sr = ~0; + m_data_sr = 0; } - // When shifting is done DSR is filled with 1s and CSR with 0s } - if (BIT(m_cntl_reg , REG_CNTL_READON_BIT)) { - // Reading - m_pll.ctime = sdok_time; - - for (unsigned i = 0; i < 8; i++) { - read_bit(do_crc_upd); - } - LOG_0(("RD D=%02x/C=%02x\n" , m_data_sr , m_clock_sr)); - } - LOG_0(("next SDOK @ %.06f\n" , m_pll.ctime.as_double())); - timer.adjust(m_pll.ctime - sdok_time); } - break; - - case HALF_BIT_TMR_ID: - { - m_pll.ctime = machine().time(); - if (m_lckup) { - // Trying to lock on synchronization bytes - attotime edge; - attotime tm; - get_next_transition(m_pll.ctime, edge); - bool half_bit0 = m_pll.feed_read_data(tm , edge , attotime::never); - get_next_transition(m_pll.ctime, edge); - bool half_bit1 = m_pll.feed_read_data(tm , edge , attotime::never); - if (half_bit0 == half_bit1) { - // If half bits are equal, no synch - LOG_0(("Reset sync_cnt\n")); - m_sync_cnt = 0; - } else if (++m_sync_cnt >= MIN_SYNC_BITS) { - // Synchronized, now wait for AM - LOG_0(("Synchronized @ %.6f\n" , machine().time().as_double())); - m_lckup = false; - if (BIT(m_cntl_reg , REG_CNTL_WRITON_BIT)) { - // When loopback is active, leave AM detection to byte timer as - // byte boundary is already synchronized - timer.reset(); - return; - } else { - // Align with bit cell - // Synchronization bits in HP mode: 32x 1s -> C/D bits = 01010101... - // Synchronization bits in IBM mode: 32x 0s -> C/D bits = 10101010... - if (m_hiden != half_bit1) { - // Discard 1/2 bit cell if synchronization achieved in the clock part - get_next_transition(m_pll.ctime, edge); - m_pll.feed_read_data(tm , edge , attotime::never); - } - // Load CSR & DSR as they are after synchronization bits - if (m_hiden) { - m_clock_sr = 0; - m_data_sr = ~0; - } else { - m_clock_sr = ~0; - m_data_sr = 0; - } - } - } - } else { - // Looking for AM - /// CRC is not updated because it can't be possibly enabled at this point + } else { + // Looking for AM + /// CRC is not updated because it can't be possibly enabled at this point + read_bit(false); + if ((m_hiden && !BIT(m_data_sr , 7)) || + (!m_hiden && BIT(m_data_sr , 0))) { + // Got AM as soon as bits being shifted into DSR change value wrt synchronization bits + m_amdt = true; + // Finish the current byte + for (unsigned i = 0; i < 7; i++) { read_bit(false); - if ((m_hiden && !BIT(m_data_sr , 7)) || - (!m_hiden && BIT(m_data_sr , 0))) { - // Got AM as soon as bits being shifted into DSR change value wrt synchronization bits - m_amdt = true; - // Finish the current byte - for (unsigned i = 0; i < 7; i++) { - read_bit(false); - } - attotime adjust{m_pll.ctime - machine().time()}; - LOG_0(("Got AM @ %.6f, ctime=%.6f, adj=%.6f, D=%02x/C=%02x\n" , machine().time().as_double() , m_pll.ctime.as_double() , adjust.as_double() , m_data_sr , m_clock_sr)); - // Disable half-bit timer & enable byte timer - timer.reset(); - m_byte_timer->adjust(adjust); - return; - } } - timer.adjust(m_pll.ctime - machine().time()); + attotime adjust{m_pll.ctime - machine().time()}; + LOGMASKED(LOG_LEVEL0, "Got AM @ %.6f, ctime=%.6f, adj=%.6f, D=%02x/C=%02x\n" , machine().time().as_double() , m_pll.ctime.as_double() , adjust.as_double() , m_data_sr , m_clock_sr); + // Disable half-bit timer & enable byte timer + m_half_bit_timer->reset(); + m_byte_timer->adjust(adjust); + return; } - break; - - default: - break; } + m_half_bit_timer->adjust(m_pll.ctime - machine().time()); } void hp9895_device::ieee488_eoi(int state) @@ -514,7 +498,7 @@ void hp9895_device::z80_m1_w(uint8_t data) void hp9895_device::data_w(uint8_t data) { - LOG_0(("W DATA=%02x\n" , data)); + LOGMASKED(LOG_LEVEL0, "W DATA=%02x\n" , data); // CPU stalls until next SDOK m_cpu->suspend_until_trigger(1 , true); m_data_sr = data; @@ -524,13 +508,13 @@ void hp9895_device::data_w(uint8_t data) void hp9895_device::clock_w(uint8_t data) { - LOG_0(("W CLOCK=%02x\n" , data)); + LOGMASKED(LOG_LEVEL0, "W CLOCK=%02x\n" , data); m_clock_reg = data; } void hp9895_device::reset_w(uint8_t data) { - LOG_0(("W RESET=%02x\n" , data)); + LOGMASKED(LOG_LEVEL0, "W RESET=%02x\n" , data); if (BIT(data , REG_RESET_TIMEOUT_START_BIT)) { m_timeout = false; m_timeout_timer->adjust(attotime::from_msec(TIMEOUT_MSEC)); @@ -543,14 +527,14 @@ void hp9895_device::reset_w(uint8_t data) void hp9895_device::leds_w(uint8_t data) { - LOG(("W LEDS=%02x %c%c%c%c%c\n" , data , BIT(data , 4) ? '.' : '*' , BIT(data , 3) ? '.' : '*' , BIT(data , 2) ? '.' : '*' , BIT(data , 1) ? '.' : '*' , BIT(data , 0) ? '.' : '*')); + LOGMASKED(LOG_LEVEL1, "W LEDS=%02x %c%c%c%c%c\n" , data , BIT(data , 4) ? '.' : '*' , BIT(data , 3) ? '.' : '*' , BIT(data , 2) ? '.' : '*' , BIT(data , 1) ? '.' : '*' , BIT(data , 0) ? '.' : '*'); // TODO: } void hp9895_device::cntl_w(uint8_t data) { if (data != m_cntl_reg) { - LOG_0(("W CNTL=%02x -> %02x\n" , m_cntl_reg , data)); + LOGMASKED(LOG_LEVEL0, "W CNTL=%02x -> %02x\n" , m_cntl_reg , data); uint8_t old_cntl_reg = m_cntl_reg; m_cntl_reg = data; @@ -563,11 +547,11 @@ void hp9895_device::cntl_w(uint8_t data) bool byte_timer_needed = new_writon || (new_readon && m_amdt); if (!byte_timer_running && byte_timer_needed) { - LOG_0(("Enable byte tmr\n")); + LOGMASKED(LOG_LEVEL0, "Enable byte tmr\n"); attotime byte_period = get_half_bit_cell_period() * 16; m_byte_timer->adjust(byte_period); } else if (byte_timer_running && !byte_timer_needed) { - LOG_0(("Disable byte tmr\n")); + LOGMASKED(LOG_LEVEL0, "Disable byte tmr\n"); m_byte_timer->reset(); } @@ -577,24 +561,24 @@ void hp9895_device::cntl_w(uint8_t data) if (!old_writon && new_writon) { // Writing enabled - LOG_0(("Start writing..\n")); + LOGMASKED(LOG_LEVEL0, "Start writing\n"); m_pll.start_writing(machine().time()); m_wr_context = 0; m_had_transition = false; } else if (old_writon && !new_writon) { // Writing disabled - LOG_0(("Stop writing..\n")); + LOGMASKED(LOG_LEVEL0, "Stop writing\n"); m_pll.stop_writing(get_write_device() , machine().time()); } if (!old_readon && new_readon) { // Reading enabled - LOG_0(("Start reading..\n")); + LOGMASKED(LOG_LEVEL0, "Start reading\n"); m_pll.read_reset(machine().time()); m_sync_cnt = 0; m_half_bit_timer->adjust(get_half_bit_cell_period()); } else if (old_readon && !new_readon) { // Reading disabled - LOG_0(("Stop reading..\n")); + LOGMASKED(LOG_LEVEL0, "Stop reading\n"); m_half_bit_timer->reset(); m_lckup = true; m_amdt = false; @@ -610,7 +594,7 @@ void hp9895_device::cntl_w(uint8_t data) void hp9895_device::drv_w(uint8_t data) { - LOG_0(("W DRV=%02x\n" , data)); + LOGMASKED(LOG_LEVEL0, "W DRV=%02x\n" , data); m_mgnena = BIT(data , REG_DRV_MGNENA_BIT); if (m_current_drive != nullptr) { m_current_drive->stp_w(!BIT(data , REG_DRV_STEP_BIT)); @@ -622,11 +606,11 @@ void hp9895_device::drv_w(uint8_t data) void hp9895_device::xv_w(uint8_t data) { - LOG_0(("W XV=%02x\n" , data)); + LOGMASKED(LOG_LEVEL0, "W XV=%02x\n" , data); // Disk Changed flag is cleared when drive is ready and it is deselected if (m_current_drive_idx < 2 && (data & xv_drive_masks[ m_current_drive_idx ]) == 0 && !m_current_drive->ready_r()) { if (m_dskchg[ m_current_drive_idx ]) { - LOG(("Dskchg %u cleared\n" , m_current_drive_idx)); + LOGMASKED(LOG_LEVEL1, "Dskchg %u cleared\n" , m_current_drive_idx); } m_dskchg[ m_current_drive_idx ] = false; } @@ -648,7 +632,7 @@ uint8_t hp9895_device::data_r() { m_clock_reg = m_clock_sr; m_accdata = true; - LOG_0(("R DATA=%02x\n" , m_data_sr)); + LOGMASKED(LOG_LEVEL0, "R DATA=%02x\n" , m_data_sr); // CPU stalls until next SDOK m_cpu->suspend_until_trigger(1 , true); return m_data_sr; @@ -689,7 +673,7 @@ uint8_t hp9895_device::drivstat_r() if (m_overrun) { BIT_SET(res , REG_DRIVSTAT_OVERUN_BIT); } - LOG_0(("R DRIVSTAT=%02x\n" , res)); + LOGMASKED(LOG_LEVEL0, "R DRIVSTAT=%02x\n" , res); return res; } @@ -711,7 +695,7 @@ void hp9895_device::floppy_ready_cb(floppy_image_device *floppy , int state) // Set Disk Changed flag when a drive is not ready for (unsigned i = 0; i < 2; i++) { if (floppy == m_drives[ i ]->get_device()) { - LOG(("Dskchg %u set\n" , i)); + LOGMASKED(LOG_LEVEL1, "Dskchg %u set\n" , i); m_dskchg[ i ] = true; break; } diff --git a/src/devices/bus/ieee488/hp9895.h b/src/devices/bus/ieee488/hp9895.h index 69d939940d2..1cb77d60090 100644 --- a/src/devices/bus/ieee488/hp9895.h +++ b/src/devices/bus/ieee488/hp9895.h @@ -29,7 +29,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-level overrides virtual ioport_constructor device_input_ports() const override; @@ -87,6 +86,20 @@ private: // Floppy drive interface void floppy_ready_cb(floppy_image_device *floppy , int state); + TIMER_CALLBACK_MEMBER(timeout_timer_tick); + TIMER_CALLBACK_MEMBER(byte_timer_tick); + TIMER_CALLBACK_MEMBER(half_bit_timer_tick); + + uint8_t get_switches2(void) const; + attotime get_half_bit_cell_period(void) const; + floppy_image_device *get_write_device(void) const; + void preset_crc(void); + void update_crc(bool bit); + bool shift_sr(uint8_t& sr , bool input_bit); + void get_next_transition(const attotime& from_when , attotime& edge); + void read_bit(bool crc_upd); + void write_bit(bool data_bit , bool clock_bit); + void z80_io_map(address_map &map); void z80_program_map(address_map &map); @@ -123,16 +136,6 @@ private: // PLL fdc_pll_t m_pll; - - uint8_t get_switches2(void) const; - attotime get_half_bit_cell_period(void) const; - floppy_image_device *get_write_device(void) const; - void preset_crc(void); - void update_crc(bool bit); - bool shift_sr(uint8_t& sr , bool input_bit); - void get_next_transition(const attotime& from_when , attotime& edge); - void read_bit(bool crc_upd); - void write_bit(bool data_bit , bool clock_bit); }; // device type definition diff --git a/src/devices/bus/ieee488/remote488.cpp b/src/devices/bus/ieee488/remote488.cpp index 4feaf3c0647..d559622dad6 100644 --- a/src/devices/bus/ieee488/remote488.cpp +++ b/src/devices/bus/ieee488/remote488.cpp @@ -188,11 +188,12 @@ #include "remote488.h" // Debugging -#include "logmacro.h" -#define LOG_PARSER_MASK (LOG_GENERAL << 1) +#define LOG_PARSER_MASK (1U << 1) #define LOG_PARSER(...) LOGMASKED(LOG_PARSER_MASK, __VA_ARGS__) -#undef VERBOSE -#define VERBOSE LOG_GENERAL + +#define VERBOSE (LOG_GENERAL) + +#include "logmacro.h" // Bit manipulation namespace { @@ -222,16 +223,16 @@ namespace { } // Message types -constexpr char MSG_SIGNAL_CLEAR = 'R'; // I/O: Clear signal(s) -constexpr char MSG_SIGNAL_SET = 'S'; // I/O: Set signal(s) -constexpr char MSG_DATA_BYTE = 'D'; // I/O: Cmd/data byte (no EOI) -constexpr char MSG_END_BYTE = 'E'; // I/O: Data byte (with EOI) -constexpr char MSG_PP_DATA = 'P'; // I: Parallel poll data -constexpr char MSG_PP_REQUEST = 'Q'; // O: Request PP data -constexpr char MSG_ECHO_REQ = 'J'; // O: Heartbeat msg: echo request -constexpr char MSG_ECHO_REPLY = 'K'; // I: Heartbeat msg: echo reply -constexpr char MSG_CHECKPOINT = 'X'; // I/O: Checkpoint in byte stream -constexpr char MSG_CP_REACHED = 'Y'; // I/O: Checkpoint reached +constexpr char MSG_SIGNAL_CLEAR = 'R'; // I/O: Clear signal(s) +constexpr char MSG_SIGNAL_SET = 'S'; // I/O: Set signal(s) +constexpr char MSG_DATA_BYTE = 'D'; // I/O: Cmd/data byte (no EOI) +constexpr char MSG_END_BYTE = 'E'; // I/O: Data byte (with EOI) +constexpr char MSG_PP_DATA = 'P'; // I: Parallel poll data +constexpr char MSG_PP_REQUEST = 'Q'; // O: Request PP data +constexpr char MSG_ECHO_REQ = 'J'; // O: Heartbeat msg: echo request +constexpr char MSG_ECHO_REPLY = 'K'; // I: Heartbeat msg: echo reply +constexpr char MSG_CHECKPOINT = 'X'; // I/O: Checkpoint in byte stream +constexpr char MSG_CHECKPOINT_REACHED = 'Y'; // I/O: Checkpoint reached // Timings constexpr unsigned POLL_PERIOD_US = 20; // Poll period (µs) @@ -304,9 +305,9 @@ void remote488_device::ieee488_ren(int state) void remote488_device::device_start() { - m_poll_timer = timer_alloc(TMR_ID_POLL); - m_hb_timer = timer_alloc(TMR_ID_HEARTBEAT); - m_ah_timer = timer_alloc(TMR_ID_AH); + m_poll_timer = timer_alloc(FUNC(remote488_device::process_input_msgs), this); + m_hb_timer = timer_alloc(FUNC(remote488_device::heartbeat_tick), this); + m_ah_timer = timer_alloc(FUNC(remote488_device::checkpoint_timeout_tick), this); } void remote488_device::device_reset() @@ -327,7 +328,7 @@ void remote488_device::device_reset() m_ibf = false; m_flush_bytes = false; - m_waiting_cp = false; + m_waiting_checkpoint = false; bus_reset(); } @@ -344,7 +345,7 @@ void remote488_device::bus_reset() update_pp(); } -void remote488_device::process_input_msgs() +TIMER_CALLBACK_MEMBER(remote488_device::process_input_msgs) { uint8_t data; char msg_ch; @@ -383,13 +384,13 @@ void remote488_device::process_input_msgs() break; case MSG_CHECKPOINT: - send_update(MSG_CP_REACHED , m_flush_bytes); + send_update(MSG_CHECKPOINT_REACHED , m_flush_bytes); m_flush_bytes = false; break; - case MSG_CP_REACHED: - if (m_waiting_cp) { - m_waiting_cp = false; + case MSG_CHECKPOINT_REACHED: + if (m_waiting_checkpoint) { + m_waiting_checkpoint = false; update_ah_fsm(); } break; @@ -403,29 +404,19 @@ void remote488_device::process_input_msgs() } } -void remote488_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(remote488_device::heartbeat_tick) { - switch (id) { - case TMR_ID_POLL: - process_input_msgs(); - break; - - case TMR_ID_HEARTBEAT: - if (m_connected && m_connect_cnt && --m_connect_cnt == 0) { - set_connection(false); - } - send_update(MSG_ECHO_REQ , 0); - break; - - case TMR_ID_AH: - if (!m_waiting_cp) { - LOG("CP T/O\n"); - ah_checkpoint(); - } - break; + if (m_connected && m_connect_cnt && --m_connect_cnt == 0) { + set_connection(false); + } + send_update(MSG_ECHO_REQ , 0); +} - default: - break; +TIMER_CALLBACK_MEMBER(remote488_device::checkpoint_timeout_tick) +{ + if (!m_waiting_checkpoint) { + LOG("Checkpoint T/O\n"); + ah_checkpoint(); } } @@ -570,7 +561,7 @@ bool remote488_device::is_msg_type(char c) c == MSG_PP_DATA || c == MSG_ECHO_REPLY || c == MSG_CHECKPOINT || - c == MSG_CP_REACHED; + c == MSG_CHECKPOINT_REACHED; } bool remote488_device::is_terminator(char c) @@ -668,7 +659,7 @@ bool remote488_device::is_local_atn_active() const void remote488_device::ah_checkpoint() { - m_waiting_cp = true; + m_waiting_checkpoint = true; m_ah_timer->reset(); send_update(MSG_CHECKPOINT , 0); } @@ -698,7 +689,7 @@ void remote488_device::update_ah_fsm() case REM_AH_ACDS: if (m_bus->dav_r()) { m_ah_state = REM_AH_ACRS; - } else if (!m_waiting_cp) { + } else if (!m_waiting_checkpoint) { uint8_t dio = ~m_bus->dio_r(); if (!m_bus->eoi_r()) { diff --git a/src/devices/bus/ieee488/remote488.h b/src/devices/bus/ieee488/remote488.h index 9832c7d1d76..bcb64866a05 100644 --- a/src/devices/bus/ieee488/remote488.h +++ b/src/devices/bus/ieee488/remote488.h @@ -31,18 +31,10 @@ public: virtual void ieee488_atn(int state) override; virtual void ieee488_ren(int state) override; - // Timers - enum { - TMR_ID_POLL, - TMR_ID_HEARTBEAT, - TMR_ID_AH - }; - 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: // Position of signals in "S/R" msgs @@ -101,10 +93,14 @@ private: bool m_pp_requested; uint8_t m_pp_dio; uint8_t m_sh_dio; - bool m_waiting_cp; + bool m_waiting_checkpoint; + + + TIMER_CALLBACK_MEMBER(process_input_msgs); + TIMER_CALLBACK_MEMBER(heartbeat_tick); + TIMER_CALLBACK_MEMBER(checkpoint_timeout_tick); void bus_reset(); - void process_input_msgs(); void set_connection(bool state); void recvd_data_byte(uint8_t data , bool eoi); void flush_data(); diff --git a/src/devices/bus/intellec4/tapereader.cpp b/src/devices/bus/intellec4/tapereader.cpp index 1606c4e3e21..aa1acd9e963 100644 --- a/src/devices/bus/intellec4/tapereader.cpp +++ b/src/devices/bus/intellec4/tapereader.cpp @@ -85,7 +85,7 @@ void imm4_90_device::call_unload() void imm4_90_device::device_start() { - m_step_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(imm4_90_device::step), this)); + m_step_timer = timer_alloc(FUNC(imm4_90_device::step), this); save_item(NAME(m_data)); save_item(NAME(m_ready)); diff --git a/src/devices/bus/interpro/keyboard/hle.cpp b/src/devices/bus/interpro/keyboard/hle.cpp index 66be76a22ec..8d773a9fa85 100644 --- a/src/devices/bus/interpro/keyboard/hle.cpp +++ b/src/devices/bus/interpro/keyboard/hle.cpp @@ -285,7 +285,7 @@ void hle_device_base::device_add_mconfig(machine_config &config) void hle_device_base::device_start() { - m_click_timer = timer_alloc(CLICK_TIMER_ID); + m_click_timer = timer_alloc(FUNC(hle_device_base::click_tick), this); save_item(NAME(m_make_count)); save_item(NAME(m_rx_state)); @@ -316,18 +316,10 @@ void hle_device_base::device_reset() start_processing(attotime::from_hz(1'200)); } -void hle_device_base::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(hle_device_base::click_tick) { - switch (id) - { - case CLICK_TIMER_ID: - m_beeper_state &= ~u8(BEEPER_CLICK); - m_beeper->set_state(m_beeper_state ? 1 : 0); - break; - - default: - break; - } + m_beeper_state &= ~u8(BEEPER_CLICK); + m_beeper->set_state(m_beeper_state ? 1 : 0); } void hle_device_base::tra_callback() diff --git a/src/devices/bus/interpro/keyboard/hle.h b/src/devices/bus/interpro/keyboard/hle.h index 5cacaf80d86..607b7b42087 100644 --- a/src/devices/bus/interpro/keyboard/hle.h +++ b/src/devices/bus/interpro/keyboard/hle.h @@ -31,7 +31,6 @@ protected: virtual void device_add_mconfig(machine_config &config) override; virtual void device_start() override; virtual void device_reset() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; // device_buffered_serial_interface overrides virtual void tra_callback() override; @@ -87,6 +86,8 @@ private: COMMAND_LAYOUT = 0x0fU }; + TIMER_CALLBACK_MEMBER(click_tick); + // device_buffered_serial_interface overrides virtual void received_byte(u8 byte) override; diff --git a/src/devices/bus/interpro/sr/gt.cpp b/src/devices/bus/interpro/sr/gt.cpp index 4005aca569f..15158ede040 100644 --- a/src/devices/bus/interpro/sr/gt.cpp +++ b/src/devices/bus/interpro/sr/gt.cpp @@ -616,9 +616,9 @@ void gt_device_base::device_start() save_item(NAME(m_control)); // allocate timers - m_blit_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(gt_device_base::blit), this)); - m_line_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(gt_device_base::line), this)); - m_done_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(gt_device_base::done), this)); + m_blit_timer = timer_alloc(FUNC(gt_device_base::blit), this); + m_line_timer = timer_alloc(FUNC(gt_device_base::line), this); + m_done_timer = timer_alloc(FUNC(gt_device_base::done), this); } void gt_device_base::control_w(offs_t offset, u32 data, u32 mem_mask) diff --git a/src/devices/bus/iq151/staper.cpp b/src/devices/bus/iq151/staper.cpp index 1381bc63d24..63a365282d0 100644 --- a/src/devices/bus/iq151/staper.cpp +++ b/src/devices/bus/iq151/staper.cpp @@ -52,8 +52,15 @@ iq151_staper_device::iq151_staper_device(const machine_config &mconfig, const ch void iq151_staper_device::device_start() { - m_printer_timer = timer_alloc(TIMER_PRINTER); - m_printer_timer->reset(); + m_printer_timer = timer_alloc(FUNC(iq151_staper_device::pc2_low_tick), this); +} + +//------------------------------------------------- +// device_reset - device-specific reset +//------------------------------------------------- + +void iq151_staper_device::device_reset() +{ } //------------------------------------------------- @@ -71,13 +78,12 @@ void iq151_staper_device::device_add_mconfig(machine_config &config) } //------------------------------------------------- -// device_timer - handler timer events +// pc2_low_tick - lower PPI Port C bit 2 //------------------------------------------------- -void iq151_staper_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(iq151_staper_device::pc2_low_tick) { - if (id == TIMER_PRINTER) - m_ppi->pc2_w(0); + m_ppi->pc2_w(0); } diff --git a/src/devices/bus/iq151/staper.h b/src/devices/bus/iq151/staper.h index 83095ee2d48..98aefb609d1 100644 --- a/src/devices/bus/iq151/staper.h +++ b/src/devices/bus/iq151/staper.h @@ -26,7 +26,7 @@ public: protected: // device-level overrides virtual void device_start() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; + virtual void device_reset() override; // optional information overrides virtual void device_add_mconfig(machine_config &config) override; @@ -41,7 +41,7 @@ private: void ppi_portb_w(uint8_t data); void ppi_portc_w(uint8_t data); - static const device_timer_id TIMER_PRINTER = 0; + TIMER_CALLBACK_MEMBER(pc2_low_tick); required_device<i8255_device> m_ppi; required_device<printer_image_device> m_printer; diff --git a/src/devices/bus/isa/gus.cpp b/src/devices/bus/isa/gus.cpp index b1af6dc12c6..7884ac37c8d 100644 --- a/src/devices/bus/isa/gus.cpp +++ b/src/devices/bus/isa/gus.cpp @@ -140,7 +140,7 @@ void gf1_device::adlib_w(offs_t offset, uint8_t data) } } -void gf1_device::update_volume_ramps() +TIMER_CALLBACK_MEMBER(gf1_device::update_volume_ramps) { int x; @@ -207,45 +207,41 @@ void gf1_device::update_volume_ramps() } } -void gf1_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(gf1_device::adlib_timer1_tick) { - switch(id) + if(m_adlib_timer1_enable != 0) { - case ADLIB_TIMER1: - if(m_adlib_timer1_enable != 0) + if(m_timer1_count == 0xff) { - if(m_timer1_count == 0xff) - { - m_adlib_status |= 0xc0; - m_timer1_count = m_timer1_value; - if(m_timer_ctrl & 0x04) - m_timer1_irq_handler(1); - } - m_timer1_count++; + m_adlib_status |= 0xc0; + m_timer1_count = m_timer1_value; + if(m_timer_ctrl & 0x04) + m_timer1_irq_handler(1); } - break; - case ADLIB_TIMER2: - if(m_adlib_timer2_enable != 0) + m_timer1_count++; + } +} + +TIMER_CALLBACK_MEMBER(gf1_device::adlib_timer2_tick) +{ + if(m_adlib_timer2_enable != 0) + { + if(m_timer2_count == 0xff) { - if(m_timer2_count == 0xff) - { - m_adlib_status |= 0xa0; - m_timer2_count = m_timer2_value; - if(m_timer_ctrl & 0x08) - m_timer2_irq_handler(1); - } - m_timer2_count++; + m_adlib_status |= 0xa0; + m_timer2_count = m_timer2_value; + if(m_timer_ctrl & 0x08) + m_timer2_irq_handler(1); } - break; - case DMA_TIMER: - m_drq1_handler(1); - break; - case VOL_RAMP_TIMER: - update_volume_ramps(); - break; + m_timer2_count++; } } +TIMER_CALLBACK_MEMBER(gf1_device::dma_tick) +{ + m_drq1_handler(1); +} + void gf1_device::sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) { int x; @@ -406,10 +402,10 @@ void gf1_device::device_start() m_stream = stream_alloc(0,2,clock() / (14 * 16)); // init timers - m_timer1 = timer_alloc(ADLIB_TIMER1); - m_timer2 = timer_alloc(ADLIB_TIMER2); - m_dmatimer = timer_alloc(DMA_TIMER); - m_voltimer = timer_alloc(VOL_RAMP_TIMER); + m_timer1 = timer_alloc(FUNC(gf1_device::adlib_timer1_tick), this); + m_timer2 = timer_alloc(FUNC(gf1_device::adlib_timer2_tick), this); + m_dmatimer = timer_alloc(FUNC(gf1_device::dma_tick), this); + m_voltimer = timer_alloc(FUNC(gf1_device::update_volume_ramps), this); save_item(NAME(m_wave_ram)); diff --git a/src/devices/bus/isa/gus.h b/src/devices/bus/isa/gus.h index 3e555dfa125..c39695997da 100644 --- a/src/devices/bus/isa/gus.h +++ b/src/devices/bus/isa/gus.h @@ -121,11 +121,18 @@ public: void dack_w(int line,uint8_t data); void eop_w(int state); - // optional information overrides - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; + // device_sound_interface overrides virtual void sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) override; protected: + // device-level overrides + virtual void device_start() override; + virtual void device_reset() override; + virtual void device_stop() override; + virtual void device_clock_changed() override; + + virtual void update_irq() override; + // voice-specific registers gus_voice m_voice[32]; @@ -147,18 +154,13 @@ protected: void set_irq(uint8_t source, uint8_t voice); void reset_irq(uint8_t source); - void update_volume_ramps(); - - std::vector<uint8_t> m_wave_ram; - - // device-level overrides - virtual void device_start() override; - virtual void device_reset() override; - virtual void device_stop() override; - virtual void device_clock_changed() override; - virtual void update_irq() override; + TIMER_CALLBACK_MEMBER(adlib_timer1_tick); + TIMER_CALLBACK_MEMBER(adlib_timer2_tick); + TIMER_CALLBACK_MEMBER(dma_tick); + TIMER_CALLBACK_MEMBER(update_volume_ramps); + std::vector<uint8_t> m_wave_ram; private: // internal state sound_stream* m_stream; @@ -199,11 +201,6 @@ private: uint32_t m_dma_current; uint16_t m_volume_table[4096]; - static const device_timer_id ADLIB_TIMER1 = 0; - static const device_timer_id ADLIB_TIMER2 = 1; - static const device_timer_id DMA_TIMER = 2; - static const device_timer_id VOL_RAMP_TIMER = 3; - int m_txirq; int m_rxirq; diff --git a/src/devices/bus/isa/hdc.cpp b/src/devices/bus/isa/hdc.cpp index d508b428b12..74d2a23d11b 100644 --- a/src/devices/bus/isa/hdc.cpp +++ b/src/devices/bus/isa/hdc.cpp @@ -9,9 +9,12 @@ #include "emu.h" #include "hdc.h" -#define LOG_HDC_STATUS 0 -#define LOG_HDC_CALL 0 -#define LOG_HDC_DATA 0 +#define LOG_HDC_STATUS (1U << 1) +#define LOG_HDC_CALL (1U << 2) +#define LOG_HDC_DATA (1U << 3) + +#define VERBOSE (0) +#include "logmacro.h" #define CMD_TESTREADY 0x00 #define CMD_RECALIBRATE 0x01 @@ -52,7 +55,7 @@ #define CTL_PIO 0x00 #define CTL_DMA 0x01 -static const char *const hdc_command_names[] = +const char *const s_hdc_command_names[] = { "CMD_TESTREADY", /* 0x00 */ "CMD_RECALIBRATE", /* 0x01 */ @@ -153,9 +156,23 @@ xt_hdc_device::xt_hdc_device(const machine_config &mconfig, const char *tag, dev xt_hdc_device::xt_hdc_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock) : device_t(mconfig, type, tag, owner, clock), - buffer_ptr(nullptr), csb(0), status(0), error(0), m_type(0), m_current_cmd(0), + m_buffer_ptr(nullptr), + m_csb(0), + m_status(0), + m_error(0), + m_type(0), + m_current_cmd(0), m_irq_handler(*this), - m_drq_handler(*this), drv(0), timer(nullptr), data_cnt(0), hdc_control(0), hdcdma_src(nullptr), hdcdma_dst(nullptr), hdcdma_read(0), hdcdma_write(0), hdcdma_size(0) + m_drq_handler(*this), + m_drv(0), + m_timer(nullptr), + m_data_cnt(0), + m_hdc_control(0), + m_hdcdma_src(nullptr), + m_hdcdma_dst(nullptr), + m_hdcdma_read(0), + m_hdcdma_write(0), + m_hdcdma_size(0) { } @@ -177,43 +194,43 @@ st11m_device::st11m_device(const machine_config &mconfig, const char *tag, devic void xt_hdc_device::device_start() { - buffer.resize(256*512); // maximum possible transfer - timer = timer_alloc(); + m_buffer = std::make_unique<uint8_t[]>(256*512); // maximum possible transfer + m_timer = timer_alloc(FUNC(xt_hdc_device::process_command), this); m_irq_handler.resolve_safe(); m_drq_handler.resolve_safe(); } void xt_hdc_device::device_reset() { - drv = 0; - data_cnt = 0; - buffer_ptr = nullptr; - hdc_control = 0; + m_drv = 0; + m_data_cnt = 0; + m_buffer_ptr = nullptr; + m_hdc_control = 0; for (int i = 0; i < 2; i++) { - cylinders[i] = 612; - rwc[i] = 613; - wp[i] = 613; - heads[i] = 4; - ecc[i] = 11; + m_cylinders[i] = 612; + m_rwc[i] = 613; + m_wp[i] = 613; + m_heads[i] = 4; + m_ecc[i] = 11; /* indexes */ - cylinder[i] = 0; - head[i] = 0; - sector[i] = 0; - sector_cnt[i] = 0; - control[i] = 0; + m_cylinder[i] = 0; + m_head[i] = 0; + m_sector[i] = 0; + m_sector_cnt[i] = 0; + m_control[i] = 0; } - csb = 0; - status = 0; - error = 0; + m_csb = 0; + m_status = 0; + m_error = 0; } hard_disk_file *xt_hdc_device::pc_hdc_file(int id) { harddisk_image_device *img = nullptr; - switch( id ) + switch (id) { case 0: img = subdevice<harddisk_image_device>("primary"); @@ -222,7 +239,7 @@ hard_disk_file *xt_hdc_device::pc_hdc_file(int id) img = subdevice<harddisk_image_device>("slave"); break; } - if ( img == nullptr ) + if (img == nullptr) return nullptr; if (!img->exists()) @@ -231,64 +248,57 @@ hard_disk_file *xt_hdc_device::pc_hdc_file(int id) return img->get_hard_disk_file(); } -void xt_hdc_device::pc_hdc_result(int set_error_info) +void xt_hdc_device::pc_hdc_result(bool set_error_info) { - if ( ( hdc_control & 0x02 )) + if (m_hdc_control & 0x02) { // dip switch selected IRQ 5 or 2 m_irq_handler(1); } - if (LOG_HDC_STATUS) - logerror("pc_hdc_result(): $%02x to $%04x\n", csb, data_cnt); + LOGMASKED(LOG_HDC_STATUS, "pc_hdc_result(): $%02x to $%04x\n", m_csb, m_data_cnt); - buffer[data_cnt++] = csb; + m_buffer[m_data_cnt++] = m_csb; - if (set_error_info && ( csb & CSB_ERROR ) ) + if (set_error_info && (m_csb & CSB_ERROR)) { - buffer[data_cnt++] = error; - if (error & 0x80) + m_buffer[m_data_cnt++] = m_error; + if (m_error & 0x80) { - buffer[data_cnt++] = (drv << 5) | head[drv]; - buffer[data_cnt++] = ((cylinder[drv] >> 2) & 0xc0) | sector[drv]; - buffer[data_cnt++] = cylinder[drv] & 0xff; + m_buffer[m_data_cnt++] = (m_drv << 5) | m_head[m_drv]; + m_buffer[m_data_cnt++] = ((m_cylinder[m_drv] >> 2) & 0xc0) | m_sector[m_drv]; + m_buffer[m_data_cnt++] = m_cylinder[m_drv] & 0xff; - if (LOG_HDC_STATUS) - { - logerror("pc_hdc_result(): result [%02x %02x %02x %02x]\n", - buffer[data_cnt-4], buffer[data_cnt-3], buffer[data_cnt-2], buffer[data_cnt-1]); - } + LOGMASKED(LOG_HDC_STATUS, "pc_hdc_result(): result [%02x %02x %02x %02x]\n", + m_buffer[m_data_cnt - 4], m_buffer[m_data_cnt - 3], m_buffer[m_data_cnt - 2], m_buffer[m_data_cnt - 1]); } else { - if (LOG_HDC_STATUS) - logerror("pc_hdc_result(): result [%02x]\n", buffer[data_cnt-1]); + LOGMASKED(LOG_HDC_STATUS, "pc_hdc_result(): result [%02x]\n", m_buffer[m_data_cnt - 1]); } } - status |= STA_INTERRUPT | STA_INPUT | STA_REQUEST | STA_COMMAND | STA_READY; + m_status |= STA_INTERRUPT | STA_INPUT | STA_REQUEST | STA_COMMAND | STA_READY; } -int xt_hdc_device::no_dma(void) +bool xt_hdc_device::no_dma() { - return (hdc_control & CTL_DMA) == 0; + return (m_hdc_control & CTL_DMA) == 0; } int xt_hdc_device::get_lbasector() { - int lbasector; - - hard_disk_file *file = pc_hdc_file(drv); + hard_disk_file *file = pc_hdc_file(m_drv); const auto &info = file->get_info(); - lbasector = cylinder[drv]; + int lbasector = m_cylinder[m_drv]; lbasector *= info.heads; - lbasector += head[drv]; + lbasector += m_head[m_drv]; lbasector *= info.sectors; - lbasector += sector[drv]; + lbasector += m_sector[m_drv]; return lbasector; } @@ -304,42 +314,43 @@ int xt_hdc_device::get_lbasector() int xt_hdc_device::dack_r() { - uint8_t result; - - hard_disk_file *file = pc_hdc_file(drv); + hard_disk_file *file = pc_hdc_file(m_drv); if (!file) return 0; const auto &info = file->get_info(); - if (hdcdma_read == 0) + if (m_hdcdma_read == 0) { - file->read(get_lbasector(), hdcdma_data); - hdcdma_read = 512; - hdcdma_size -= 512; - hdcdma_src = hdcdma_data; - sector[drv]++; + file->read(get_lbasector(), m_hdcdma_data); + m_hdcdma_read = 512; + m_hdcdma_size -= 512; + m_hdcdma_src = m_hdcdma_data; + m_sector[m_drv]++; } - result = *(hdcdma_src++); + uint8_t result = *(m_hdcdma_src++); - if( --hdcdma_read == 0 ) + if (--m_hdcdma_read == 0) { /* end of cylinder ? */ - if (sector[drv] >= info.sectors) + if (m_sector[m_drv] >= info.sectors) { - sector[drv] = 0; - if (++head[drv] >= info.heads) /* beyond heads? */ + m_sector[m_drv] = 0; + if (++m_head[m_drv] >= info.heads) /* beyond heads? */ { - head[drv] = 0; /* reset head */ - cylinder[drv]++; /* next cylinder */ + m_head[m_drv] = 0; /* reset head */ + m_cylinder[m_drv]++; /* next cylinder */ } } } if (!no_dma()) { - m_drq_handler((hdcdma_read || hdcdma_size ) ? 1 : 0); - if(!(hdcdma_read || hdcdma_size)) pc_hdc_result(0); + m_drq_handler((m_hdcdma_read || m_hdcdma_size) ? 1 : 0); + if (!(m_hdcdma_read || m_hdcdma_size)) + { + pc_hdc_result(false); + } } return result; @@ -347,64 +358,68 @@ int xt_hdc_device::dack_r() int xt_hdc_device::dack_rs() { - uint8_t result; + logerror("%s dack_rs(%d %d)\n", machine().describe_context(), m_hdcdma_read, m_hdcdma_size); - logerror("%s dack_rs(%d %d)\n", machine().describe_context(), hdcdma_read, hdcdma_size); - - if (hdcdma_read == 0) + if (m_hdcdma_read == 0) { - hdcdma_read = 512; - hdcdma_size -= 512; - hdcdma_src = hdcdma_data; + m_hdcdma_read = 512; + m_hdcdma_size -= 512; + m_hdcdma_src = m_hdcdma_data; } - result = *(hdcdma_src++); + uint8_t m_result = *(m_hdcdma_src++); - hdcdma_read--; + m_hdcdma_read--; if (!no_dma()) { - m_drq_handler((hdcdma_read) ? 1 : 0); - if(!(hdcdma_read)) pc_hdc_result(0); + m_drq_handler(m_hdcdma_read ? 1 : 0); + if (!m_hdcdma_read) + { + pc_hdc_result(false); + } } - return result; + return m_result; } void xt_hdc_device::dack_w(int data) { - hard_disk_file *file = pc_hdc_file(drv); + hard_disk_file *file = pc_hdc_file(m_drv); if (!file) return; const auto &info = file->get_info(); - *(hdcdma_dst++) = data; + *(m_hdcdma_dst++) = data; - if( --hdcdma_write == 0 ) + if (--m_hdcdma_write == 0) { - file->write(get_lbasector(), hdcdma_data); - hdcdma_write = 512; - hdcdma_size -= 512; + file->write(get_lbasector(), m_hdcdma_data); + m_hdcdma_write = 512; + m_hdcdma_size -= 512; /* end of cylinder ? */ - if( ++sector[drv] >= info.sectors ) + if (++m_sector[m_drv] >= info.sectors) { - sector[drv] = 0; - if (++head[drv] >= info.heads) /* beyond heads? */ + m_sector[m_drv] = 0; + if (++m_head[m_drv] >= info.heads) /* beyond heads? */ { - head[drv] = 0; /* reset head */ - cylinder[drv]++; /* next cylinder */ + m_head[m_drv] = 0; /* reset head */ + m_cylinder[m_drv]++; /* next cylinder */ } } - hdcdma_dst = hdcdma_data; + m_hdcdma_dst = m_hdcdma_data; } if (!no_dma()) { - m_drq_handler(hdcdma_size ? 1 : 0); - if(!hdcdma_size) pc_hdc_result(1); + m_drq_handler(m_hdcdma_size ? 1 : 0); + if (!m_hdcdma_size) + { + pc_hdc_result(true); + } } } @@ -412,19 +427,22 @@ void xt_hdc_device::dack_w(int data) void xt_hdc_device::dack_ws(int data) { - *(hdcdma_dst++) = data; + *(m_hdcdma_dst++) = data; - if( --hdcdma_write == 0 ) + if (--m_hdcdma_write == 0) { - hdcdma_write = 512; - hdcdma_size -= 512; - hdcdma_dst = hdcdma_data; + m_hdcdma_write = 512; + m_hdcdma_size -= 512; + m_hdcdma_dst = m_hdcdma_data; } if (!no_dma()) { - m_drq_handler(hdcdma_size ? 1 : 0); - if(!hdcdma_size) pc_hdc_result(1); + m_drq_handler(m_hdcdma_size ? 1 : 0); + if (!m_hdcdma_size) + { + pc_hdc_result(true); + } } } @@ -432,46 +450,48 @@ void xt_hdc_device::dack_ws(int data) void xt_hdc_device::execute_read() { - hard_disk_file *disk; - int size = sector_cnt[drv] * 512; - int read_ = 0; + int size = m_sector_cnt[m_drv] * 512; - if(sector_cnt[drv] == 0) + if (m_sector_cnt[m_drv] == 0) size = 256 * 512; - disk = pc_hdc_file(drv); + hard_disk_file *disk = pc_hdc_file(m_drv); if (!disk) return; - status |= STA_READY; // ready to receive data - status &= ~STA_INPUT; - status &= ~STA_COMMAND; + m_status |= STA_READY; // ready to receive data + m_status &= ~(STA_INPUT | STA_COMMAND); - hdcdma_src = hdcdma_data; - hdcdma_read = read_; - hdcdma_size = size; + m_hdcdma_src = m_hdcdma_data; + m_hdcdma_read = 0; + m_hdcdma_size = size; - if(!no_dma()) + if (!no_dma()) { m_drq_handler(1); - if(!hdcdma_size) pc_hdc_result(0); + if (!m_hdcdma_size) + { + pc_hdc_result(false); + } } } void xt_hdc_device::execute_readsbuff() { - status |= STA_READY; // ready to receive data - status &= ~STA_INPUT; - status &= ~STA_COMMAND; + m_status |= STA_READY; // ready to receive data + m_status &= ~(STA_INPUT | STA_COMMAND); - hdcdma_src = hdcdma_data; - hdcdma_read = 512; - hdcdma_size = 512; + m_hdcdma_src = m_hdcdma_data; + m_hdcdma_read = 512; + m_hdcdma_size = 512; - if(!no_dma()) + if (!no_dma()) { m_drq_handler(1); - if(!hdcdma_size) pc_hdc_result(0); + if (!m_hdcdma_size) + { + pc_hdc_result(false); + } } } @@ -479,24 +499,22 @@ void xt_hdc_device::execute_readsbuff() void xt_hdc_device::execute_write() { - hard_disk_file *disk; - int size = sector_cnt[drv] * 512; - int write_ = 512; + int size = m_sector_cnt[m_drv] * 512; - if(sector_cnt[drv] == 0) + if (m_sector_cnt[m_drv] == 0) size = 256 * 512; - disk = pc_hdc_file(drv); + hard_disk_file *disk = pc_hdc_file(m_drv); if (!disk) return; - status |= STA_READY; // ready to receive data - status |= STA_INPUT; - status &= ~STA_COMMAND; + m_status |= STA_READY; // ready to receive data + m_status |= STA_INPUT; + m_status &= ~STA_COMMAND; - hdcdma_dst = hdcdma_data; - hdcdma_write = write_; - hdcdma_size = size; + m_hdcdma_dst = m_hdcdma_data; + m_hdcdma_write = 512; + m_hdcdma_size = size; if (!no_dma()) { @@ -508,13 +526,13 @@ void xt_hdc_device::execute_write() void xt_hdc_device::execute_writesbuff() { - hdcdma_dst = hdcdma_data; - hdcdma_write = 512; - hdcdma_size = 512; + m_hdcdma_dst = m_hdcdma_data; + m_hdcdma_write = 512; + m_hdcdma_size = 512; - status |= STA_READY; // ready to receive data - status |= STA_INPUT; - status &= ~STA_COMMAND; + m_status |= STA_READY; // ready to receive data + m_status |= STA_INPUT; + m_status &= ~STA_COMMAND; if (!no_dma()) { @@ -526,75 +544,76 @@ void xt_hdc_device::execute_writesbuff() void xt_hdc_device::get_drive() { - drv = (buffer[1] >> 5) & 1; - csb = (drv) ? CSB_LUN : 0x00; + m_drv = BIT(m_buffer[1], 5); + m_csb = m_drv ? CSB_LUN : 0x00; } void xt_hdc_device::get_chsn() { - head[drv] = buffer[1] & 0x1f; - sector[drv] = buffer[2] & 0x3f; - cylinder[drv] = (buffer[2] & 0xc0) << 2; - cylinder[drv] |= buffer[3]; - sector_cnt[drv] = buffer[4]; - control[drv] = buffer[5]; /* 7: no retry, 6: no ecc retry, 210: step rate */ - - error = 0x80; /* a potential error has C/H/S/N info */ + m_head[m_drv] = m_buffer[1] & 0x1f; + m_sector[m_drv] = m_buffer[2] & 0x3f; + m_cylinder[m_drv] = (m_buffer[2] & 0xc0) << 2; + m_cylinder[m_drv] |= m_buffer[3]; + m_sector_cnt[m_drv] = m_buffer[4]; + m_control[m_drv] = m_buffer[5]; /* 7: no retry, 6: no ecc retry, 210: step rate */ + + m_error = 0x80; /* a potential error has C/H/S/N info */ } -int xt_hdc_device::test_ready() +bool xt_hdc_device::test_ready() { - if( !pc_hdc_file(drv) ) + if (!pc_hdc_file(m_drv)) { - csb |= CSB_ERROR; - error |= 0x04; /* drive not ready */ - return 0; + m_csb |= CSB_ERROR; + m_error |= 0x04; /* drive not ready */ + return false; } - return 1; + return true; } -void xt_hdc_device::command() +TIMER_CALLBACK_MEMBER(xt_hdc_device::process_command) { - int set_error_info = 1; - int old_error = error; /* Previous error data is needed for CMD_SENSE */ - const char *command_name; + int old_error = m_error; /* Previous error data is needed for CMD_SENSE */ - csb = 0x00; - error = 0; + m_csb = 0x00; + m_error = 0; - buffer_ptr = &buffer[0]; + m_buffer_ptr = &m_buffer[0]; get_drive(); - data_cnt = 0; + m_data_cnt = 0; - if (LOG_HDC_STATUS) - { - command_name = hdc_command_names[m_current_cmd] ? hdc_command_names[m_current_cmd] : "Unknown"; - logerror("%s pc_hdc_command(): Executing command; cmd=0x%02x (%s) drv=%d\n", - machine().describe_context(), m_current_cmd, command_name, drv); - } + LOGMASKED(LOG_HDC_STATUS, "%s pc_hdc_command(): Executing command; cmd=0x%02x (%s) drv=%d\n", + machine().describe_context(), m_current_cmd, s_hdc_command_names[m_current_cmd] ? s_hdc_command_names[m_current_cmd] : "Unknown", m_drv); switch (m_current_cmd) { case CMD_TESTREADY: - set_error_info = 0; test_ready(); - if(no_dma()) pc_hdc_result(set_error_info); + if (no_dma()) + { + pc_hdc_result(false); + } break; case CMD_SENSE: /* Perform error code translation. This may need to be expanded in the future. */ - buffer[data_cnt++] = ( old_error & 0xC0 ) | ( ( old_error & 0x04 ) ? 0x04 : 0x00 ) ; - buffer[data_cnt++] = (drv << 5) | head[drv]; - buffer[data_cnt++] = ((cylinder[drv] >> 2) & 0xc0) | sector[drv]; - buffer[data_cnt++] = cylinder[drv] & 0xff; - set_error_info = 0; - if(no_dma()) pc_hdc_result(set_error_info); + m_buffer[m_data_cnt++] = (old_error & 0xc0) | (old_error & 0x04); + m_buffer[m_data_cnt++] = (m_drv << 5) | m_head[m_drv]; + m_buffer[m_data_cnt++] = ((m_cylinder[m_drv] >> 2) & 0xc0) | m_sector[m_drv]; + m_buffer[m_data_cnt++] = m_cylinder[m_drv] & 0xff; + if (no_dma()) + { + pc_hdc_result(false); + } break; case CMD_RECALIBRATE: get_chsn(); - if(no_dma()) pc_hdc_result(set_error_info); + if (no_dma()) + { + pc_hdc_result(true); + } break; case CMD_FORMATDRV: @@ -605,31 +624,27 @@ void xt_hdc_device::command() case CMD_DRIVEDIAG: get_chsn(); test_ready(); - if(no_dma()) pc_hdc_result(set_error_info); + if (no_dma()) + { + pc_hdc_result(true); + } break; case CMD_READ: case CMD_READLONG: get_chsn(); - if (LOG_HDC_STATUS) - { - logerror("%s hdc read D:%d C:%d H:%d S:%d N:%d CTL:$%02x\n", - machine().describe_context(), drv, cylinder[drv], head[drv], sector[drv], sector_cnt[drv], control[drv]); - } + LOGMASKED(LOG_HDC_STATUS, "%s hdc read D:%d C:%d H:%d S:%d N:%d CTL:$%02x\n", + machine().describe_context(), m_drv, m_cylinder[m_drv], m_head[m_drv], m_sector[m_drv], m_sector_cnt[m_drv], m_control[m_drv]); if (test_ready()) execute_read(); else - pc_hdc_result(1); - set_error_info = 0; + pc_hdc_result(true); break; case CMD_READSBUFF: - if (LOG_HDC_STATUS) - { - logerror("%s hdc read sector buffer\n", machine().describe_context()); - } + LOGMASKED(LOG_HDC_STATUS, "%s hdc read sector buffer\n", machine().describe_context()); execute_readsbuff(); break; @@ -638,53 +653,50 @@ void xt_hdc_device::command() case CMD_WRITELONG: get_chsn(); - if (LOG_HDC_STATUS) - { - logerror("%s hdc write D:%d C:%d H:%d S:%d N:%d CTL:$%02x\n", - machine().describe_context(), drv, cylinder[drv], head[drv], sector[drv], sector_cnt[drv], control[drv]); - } + LOGMASKED(LOG_HDC_STATUS, "%s hdc write D:%d C:%d H:%d S:%d N:%d CTL:$%02x\n", + machine().describe_context(), m_drv, m_cylinder[m_drv], m_head[m_drv], m_sector[m_drv], m_sector_cnt[m_drv], m_control[m_drv]); if (test_ready()) execute_write(); break; case CMD_WRITESBUFF: - if (LOG_HDC_STATUS) - { - logerror("%s hdc write sector buffer\n", machine().describe_context()); - } + LOGMASKED(LOG_HDC_STATUS, "%s hdc write sector buffer\n", machine().describe_context()); execute_writesbuff(); break; case CMD_SETPARAM: get_chsn(); - cylinders[drv] = ((buffer[6]&3)<<8) | buffer[7]; - heads[drv] = buffer[8] & 0x1f; - rwc[drv] = ((buffer[9]&3)<<8) | buffer[10]; - wp[drv] = ((buffer[11]&3)<<8) | buffer[12]; - ecc[drv] = buffer[13]; - if(no_dma()) pc_hdc_result(set_error_info); + m_cylinders[m_drv] = ((m_buffer[6] & 3) << 8) | m_buffer[7]; + m_heads[m_drv] = m_buffer[8] & 0x1f; + m_rwc[m_drv] = ((m_buffer[9] & 3) << 8) | m_buffer[10]; + m_wp[m_drv] = ((m_buffer[11] & 3) << 8) | m_buffer[12]; + m_ecc[m_drv] = m_buffer[13]; + if (no_dma()) + { + pc_hdc_result(true); + } break; case CMD_GETECC: - buffer[data_cnt++] = ecc[drv]; - if(no_dma()) pc_hdc_result(set_error_info); + m_buffer[m_data_cnt++] = m_ecc[m_drv]; + if (no_dma()) + { + pc_hdc_result(true); + } break; case CMD_RAMDIAG: case CMD_INTERNDIAG: - if(no_dma()) pc_hdc_result(set_error_info); + if (no_dma()) + { + pc_hdc_result(true); + } break; } } -void xt_hdc_device::device_timer(emu_timer &timer, device_timer_id id, int param) -{ - command(); -} - - /* Command format * Bits Description * 7 0 @@ -705,43 +717,41 @@ void xt_hdc_device::device_timer(emu_timer &timer, device_timer_id id, int param * cccccccc write precomp l * eeeeeeee ecc */ -void xt_hdc_device::data_w(int data) +void xt_hdc_device::data_w(uint8_t data) { - if(!(status & STA_COMMAND) && m_current_cmd != CMD_SETPARAM) + if (!(m_status & STA_COMMAND) && m_current_cmd != CMD_SETPARAM) { - if (LOG_HDC_DATA) - logerror("hdc_data_w PIO $%02x (%i) (%s): \n", data,data_cnt,hdc_command_names[m_current_cmd] ? hdc_command_names[m_current_cmd] : "Unknown"); + LOGMASKED(LOG_HDC_DATA, "hdc_data_w PIO $%02x (%i) (%s): \n", data, m_data_cnt, s_hdc_command_names[m_current_cmd] ? s_hdc_command_names[m_current_cmd] : "Unknown"); // PIO data transfer - buffer[data_cnt++] = data; - if(data_cnt >= hdcdma_size) + m_buffer[m_data_cnt++] = data; + if (m_data_cnt >= m_hdcdma_size) { - data_cnt = 0; + m_data_cnt = 0; // write to disk do { - if(m_current_cmd == CMD_WRITESBUFF) - dack_ws(buffer[data_cnt++]); + if (m_current_cmd == CMD_WRITESBUFF) + dack_ws(m_buffer[m_data_cnt++]); else - dack_w(buffer[data_cnt++]); + dack_w(m_buffer[m_data_cnt++]); } - while (hdcdma_size); - data_cnt = 0; - pc_hdc_result(1); + while (m_hdcdma_size); + m_data_cnt = 0; + pc_hdc_result(true); } return; } - if( data_cnt == 0 ) + if (m_data_cnt == 0) { - buffer_ptr = &buffer[0]; + m_buffer_ptr = &m_buffer[0]; m_current_cmd = data; - data_cnt = 6; /* expect 6 bytes including this one */ - status &= ~STA_READY; - status &= ~STA_INPUT; + m_data_cnt = 6; /* expect 6 bytes including this one */ + m_status &= ~(STA_READY | STA_INPUT); switch (data) { case CMD_SETPARAM: - data_cnt += 8; + m_data_cnt += 8; break; case CMD_TESTREADY: @@ -765,76 +775,73 @@ void xt_hdc_device::data_w(int data) break; default: - data_cnt = 0; - status |= STA_INPUT; - csb |= CSB_ERROR | 0x20; /* unknown command */ - pc_hdc_result(1); + m_data_cnt = 0; + m_status |= STA_INPUT; + m_csb |= CSB_ERROR | 0x20; /* unknown command */ + pc_hdc_result(true); break; } - if( data_cnt ) - status |= STA_REQUEST; + if (m_data_cnt) + m_status |= STA_REQUEST; } - if (data_cnt) + if (m_data_cnt) { - if (LOG_HDC_DATA) - logerror("hdc_data_w $%02x (%i) (%s): \n", data,data_cnt,hdc_command_names[m_current_cmd] ? hdc_command_names[m_current_cmd] : "Unknown"); + LOGMASKED(LOG_HDC_DATA, "hdc_data_w $%02x (%i) (%s): \n", data, m_data_cnt, s_hdc_command_names[m_current_cmd] ? s_hdc_command_names[m_current_cmd] : "Unknown"); - *buffer_ptr++ = data; + *m_buffer_ptr++ = data; // XXX ec1841 wants this - if (m_current_cmd == CMD_SETPARAM && data_cnt == 9 && (m_type == EC1841)) { - status &= ~STA_READY; - } else { - status |= STA_READY; - if(m_current_cmd == CMD_SETPARAM && data_cnt == 9) // some controllers want geometry info as data, not as a command (true for the Seagate ST11M?) - status &= ~STA_COMMAND; + if (m_current_cmd == CMD_SETPARAM && m_data_cnt == 9 && m_type == EC1841) + { + m_status &= ~STA_READY; } - if (--data_cnt == 0) + else { - if (LOG_HDC_STATUS) - logerror("%s pc_hdc_data_w(): Launching command\n", machine().describe_context()); - - status &= ~STA_COMMAND; - status &= ~STA_REQUEST; - status &= ~STA_READY; - status &= ~STA_INPUT; - timer->adjust(attotime::from_msec(1),0); + m_status |= STA_READY; + if (m_current_cmd == CMD_SETPARAM && m_data_cnt == 9) // some controllers want geometry info as data, not as a command (true for the Seagate ST11M?) + m_status &= ~STA_COMMAND; + } + if (--m_data_cnt == 0) + { + LOGMASKED(LOG_HDC_STATUS, "%s pc_hdc_data_w(): Launching command\n", machine().describe_context()); + + m_status &= ~(STA_COMMAND | STA_REQUEST | STA_READY | STA_INPUT); + m_timer->adjust(attotime::from_msec(1)); } } } -void xt_hdc_device::reset_w(int data) +void xt_hdc_device::reset_w(uint8_t data) { - cylinder[0] = cylinder[1] = 0; - head[0] = head[1] = 0; - sector[0] = sector[1] = 0; - csb = 0; - status = STA_COMMAND | STA_READY; - memset(&buffer[0], 0, buffer.size()); - buffer_ptr = &buffer[0]; - data_cnt = 0; + m_cylinder[0] = m_cylinder[1] = 0; + m_head[0] = m_head[1] = 0; + m_sector[0] = m_sector[1] = 0; + m_csb = 0; + m_status = STA_COMMAND | STA_READY; + std::fill_n(&m_buffer[0], 256*512, 0); + m_buffer_ptr = &m_buffer[0]; + m_data_cnt = 0; } -void xt_hdc_device::select_w(int data) +void xt_hdc_device::select_w(uint8_t data) { - status &= ~STA_INTERRUPT; - status |= STA_SELECT; + m_status &= ~STA_INTERRUPT; + m_status |= STA_SELECT; } -void xt_hdc_device::control_w(int data) +void xt_hdc_device::control_w(uint8_t data) { - if (LOG_HDC_STATUS) - logerror("%s: pc_hdc_control_w(): control write %d\n", machine().describe_context(), data); + LOGMASKED(LOG_HDC_STATUS, "%s: pc_hdc_control_w(): control write %d\n", machine().describe_context(), data); - hdc_control = data; + m_hdc_control = data; - if (!(hdc_control & 0x02)) + if (!(m_hdc_control & 0x02)) { m_irq_handler(0); } @@ -846,44 +853,40 @@ uint8_t xt_hdc_device::data_r() { uint8_t data = 0xff; - if(!(status & STA_COMMAND) && (m_current_cmd == CMD_READ || m_current_cmd == CMD_READLONG || m_current_cmd == CMD_READSBUFF)) + if (!(m_status & STA_COMMAND) && (m_current_cmd == CMD_READ || m_current_cmd == CMD_READLONG || m_current_cmd == CMD_READSBUFF)) { // PIO data transfer - if(data_cnt == 0) + if (m_data_cnt == 0) { do { if (m_current_cmd == CMD_READSBUFF) - buffer[data_cnt++] = dack_rs(); + m_buffer[m_data_cnt++] = dack_rs(); else - buffer[data_cnt++] = dack_r(); - } while (hdcdma_read); - data_cnt = 0; + m_buffer[m_data_cnt++] = dack_r(); + } while (m_hdcdma_read); + m_data_cnt = 0; } - data = buffer[data_cnt++]; - if(data_cnt >= ((sector_cnt[drv]!=0) ? (sector_cnt[drv] * 512) : (256 * 512))) + data = m_buffer[m_data_cnt++]; + if (m_data_cnt >= ((m_sector_cnt[m_drv] != 0) ? (m_sector_cnt[m_drv] * 512) : (256 * 512))) { - data_cnt = 0; - pc_hdc_result(1); + m_data_cnt = 0; + pc_hdc_result(true); } - if (LOG_HDC_DATA) - logerror("hdc_data_r PIO $%02x (%i): \n", data,data_cnt); + LOGMASKED(LOG_HDC_DATA, "hdc_data_r PIO $%02x (%i): \n", data, m_data_cnt); return data; } - if( data_cnt ) + if (m_data_cnt) { - data = *buffer_ptr++; - status &= ~STA_INTERRUPT; - if( --data_cnt == 0 ) + data = *m_buffer_ptr++; + m_status &= ~STA_INTERRUPT; + if (--m_data_cnt == 0) { - status &= ~STA_INPUT; - status &= ~STA_REQUEST; - status &= ~STA_SELECT; - status |= STA_COMMAND; + m_status &= ~(STA_INPUT | STA_REQUEST | STA_SELECT); + m_status |= STA_COMMAND; } - if (LOG_HDC_DATA) - logerror("hdc_data_r $%02x (%i): \n", data,data_cnt); + LOGMASKED(LOG_HDC_DATA, "hdc_data_r $%02x (%i): \n", data, m_data_cnt); } return data; } @@ -892,12 +895,12 @@ uint8_t xt_hdc_device::data_r() uint8_t xt_hdc_device::status_r() { - return status; + return m_status; } void xt_hdc_device::set_ready() { - status |= STA_READY; // XXX + m_status |= STA_READY; // XXX } //************************************************************************** @@ -963,7 +966,8 @@ isa8_hdc_device::isa8_hdc_device(const machine_config &mconfig, const char *tag, isa8_hdc_device::isa8_hdc_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock) : device_t(mconfig, type, tag, owner, clock), device_isa8_card_interface(mconfig, *this), - m_hdc(*this,"hdc"), dip(0) + m_hdc(*this,"hdc"), + m_dip(0) { } @@ -990,7 +994,7 @@ void isa8_hdc_device::device_start() void isa8_hdc_device::device_reset() { - dip = ioport("HDD")->read(); + m_dip = ioport("HDD")->read(); if (ioport("ROM")->read() == 1 && m_hdc->install_rom()) m_isa->install_rom(this, 0xc8000, 0xc9fff, "hdc"); @@ -1002,11 +1006,12 @@ void isa8_hdc_device::device_reset() * hard disk controller * *************************************************************************/ + uint8_t isa8_hdc_device::pc_hdc_r(offs_t offset) { uint8_t data = 0xff; - switch( offset ) + switch (offset) { case 0: data = m_hdc->data_r(); break; case 1: data = m_hdc->status_r(); break; @@ -1014,18 +1019,16 @@ uint8_t isa8_hdc_device::pc_hdc_r(offs_t offset) case 3: break; } - if (LOG_HDC_CALL) - logerror("%s pc_hdc_r(): offs=%d result=0x%02x\n", machine().describe_context(), offset, data); + LOGMASKED(LOG_HDC_CALL, "%s pc_hdc_r(): offs=%d result=0x%02x\n", machine().describe_context(), offset, data); return data; } void isa8_hdc_device::pc_hdc_w(offs_t offset, uint8_t data) { - if (LOG_HDC_CALL) - logerror("%s pc_hdc_w(): offs=%d data=0x%02x\n", machine().describe_context(), offset, data); + LOGMASKED(LOG_HDC_CALL, "%s pc_hdc_w(): offs=%d data=0x%02x\n", machine().describe_context(), offset, data); - switch( offset ) + switch (offset) { case 0: m_hdc->data_w(data); break; case 1: m_hdc->reset_w(data); break; @@ -1043,7 +1046,7 @@ uint8_t isa8_hdc_device::dack_r(int line) return m_hdc->dack_r(); } -void isa8_hdc_device::dack_w(int line,uint8_t data) +void isa8_hdc_device::dack_w(int line, uint8_t data) { if (m_hdc->get_command() == CMD_WRITESBUFF) m_hdc->dack_ws(data); @@ -1069,20 +1072,19 @@ void isa8_hdc_device::dack_w(int line,uint8_t data) uint8_t isa8_hdc_device::pc_hdc_dipswitch_r() { m_hdc->set_ready(); - if (LOG_HDC_STATUS) - logerror("%s: pc_hdc_dipswitch_r: status $%02X\n", machine().describe_context(), m_hdc->status_r()); - return dip; + LOGMASKED(LOG_HDC_STATUS, "%s: pc_hdc_dipswitch_r: status $%02X\n", machine().describe_context(), m_hdc->status_r()); + return m_dip; } -WRITE_LINE_MEMBER( isa8_hdc_device::irq_w ) +WRITE_LINE_MEMBER(isa8_hdc_device::irq_w) { - if (BIT(dip, 6)) + if (BIT(m_dip, 6)) m_isa->irq5_w(state); else m_isa->irq2_w(state); } -WRITE_LINE_MEMBER( isa8_hdc_device::drq_w ) +WRITE_LINE_MEMBER(isa8_hdc_device::drq_w) { m_isa->drq3_w(state); } diff --git a/src/devices/bus/isa/hdc.h b/src/devices/bus/isa/hdc.h index 64d02ee033d..0f49d2118f9 100644 --- a/src/devices/bus/isa/hdc.h +++ b/src/devices/bus/isa/hdc.h @@ -35,15 +35,14 @@ public: void dack_w(int data); void dack_ws(int data); - virtual void command(); - void data_w(int data); - void reset_w(int data); - void select_w(int data); - void control_w(int data); + void data_w(uint8_t data); + void reset_w(uint8_t data); + void select_w(uint8_t data); + void control_w(uint8_t data); uint8_t data_r(); uint8_t status_r(); void set_ready(); - uint8_t get_command() { return buffer[0]; } + uint8_t get_command() { return m_buffer[0]; } bool install_rom() { return (m_type != EC1841); } protected: @@ -52,10 +51,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; + hard_disk_file *pc_hdc_file(int id); - void pc_hdc_result(int set_error_info); - int no_dma(void); + void pc_hdc_result(bool set_error_info); + bool no_dma(); int get_lbasector(); void execute_read(); void execute_readsbuff(); @@ -63,13 +62,15 @@ protected: void execute_writesbuff(); void get_drive(); void get_chsn(); - int test_ready(); + bool test_ready(); + + TIMER_CALLBACK_MEMBER(process_command); - std::vector<uint8_t> buffer; /* data buffer */ - uint8_t *buffer_ptr; /* data pointer */ - int csb; /* command status byte */ - int status; /* drive status */ - int error; /* error code */ + std::unique_ptr<uint8_t[]> m_buffer; /* data buffer */ + uint8_t *m_buffer_ptr; /* data pointer */ + int m_csb; /* command status byte */ + int m_status; /* drive status */ + int m_error; /* error code */ enum { STANDARD, @@ -82,31 +83,31 @@ protected: devcb_write_line m_drq_handler; private: - int drv; /* 0 master, 1 slave drive */ - int cylinders[2]; /* number of cylinders */ - int rwc[2]; /* reduced write current from cyl */ - int wp[2]; /* write precompensation from cyl */ - int heads[2]; /* heads */ - int ecc[2]; /* ECC bytes */ + int m_drv; /* 0 master, 1 slave drive */ + int m_cylinders[2]; /* number of cylinders */ + int m_rwc[2]; /* reduced write current from cyl */ + int m_wp[2]; /* write precompensation from cyl */ + int m_heads[2]; /* heads */ + int m_ecc[2]; /* ECC bytes */ /* indexes */ - int cylinder[2]; /* current cylinder */ - int head[2]; /* current head */ - int sector[2]; /* current sector */ - int sector_cnt[2]; /* sector count */ - int control[2]; /* control */ - - emu_timer *timer; - - int data_cnt; /* data count */ - uint8_t hdc_control; - - uint8_t hdcdma_data[512]; - uint8_t *hdcdma_src; - uint8_t *hdcdma_dst; - int hdcdma_read; - int hdcdma_write; - int hdcdma_size; + int m_cylinder[2]; /* current cylinder */ + int m_head[2]; /* current head */ + int m_sector[2]; /* current sector */ + int m_sector_cnt[2]; /* sector count */ + int m_control[2]; /* control */ + + emu_timer *m_timer; + + int m_data_cnt; /* data count */ + uint8_t m_hdc_control; + + uint8_t m_hdcdma_data[512]; + uint8_t *m_hdcdma_src; + uint8_t *m_hdcdma_dst; + int m_hdcdma_read; + int m_hdcdma_write; + int m_hdcdma_size; }; class ec1841_device : public xt_hdc_device @@ -166,7 +167,7 @@ public: virtual void dack_w(int line,uint8_t data) override; uint8_t pc_hdc_dipswitch_r(); - int dip; /* dip switches */ + int m_dip; /* dip switches */ }; diff --git a/src/devices/bus/isa/mc1502_fdc.cpp b/src/devices/bus/isa/mc1502_fdc.cpp index 85c8eda25aa..ad1c1bd8b8c 100644 --- a/src/devices/bus/isa/mc1502_fdc.cpp +++ b/src/devices/bus/isa/mc1502_fdc.cpp @@ -217,7 +217,7 @@ void mc1502_fdc_device::device_start() m_isa->install_device(0x0048, 0x004b, read8sm_delegate(*m_fdc, FUNC(fd1793_device::read)), write8sm_delegate(*m_fdc, FUNC(fd1793_device::write))); m_isa->install_device(0x004c, 0x004f, read8sm_delegate(*this, FUNC(mc1502_fdc_device::mc1502_fdcv2_r)), write8sm_delegate(*this, FUNC(mc1502_fdc_device::mc1502_fdc_w))); - motor_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(mc1502_fdc_device::motor_callback),this)); + motor_timer = timer_alloc(FUNC(mc1502_fdc_device::motor_callback), this); motor_on = 0; m_control = 0; } diff --git a/src/devices/bus/isa/omti8621.cpp b/src/devices/bus/isa/omti8621.cpp index a90df0ea019..880e4e110ea 100644 --- a/src/devices/bus/isa/omti8621.cpp +++ b/src/devices/bus/isa/omti8621.cpp @@ -20,14 +20,13 @@ #include "formats/naslite_dsk.h" #include "formats/apollo_dsk.h" -#define VERBOSE 0 +#define LOG_LEVEL0 (0x1U << 1) +#define LOG_LEVEL1 (0x3U << 1) +#define LOG_LEVEL2 (0x7U << 1) +#define LOG_LEVEL3 (0xfU << 1) -static int verbose = VERBOSE; - -#define LOG(x) { logerror ("%s: ", cpu_context()); logerror x; logerror ("\n"); } -#define LOG1(x) { if (verbose > 0) LOG(x)} -#define LOG2(x) { if (verbose > 1) LOG(x)} -#define LOG3(x) { if (verbose > 2) LOG(x)} +#define VERBOSE (LOG_LEVEL0) +#include "logmacro.h" #define OMTI_DISK_SECTOR_SIZE 1056 @@ -105,7 +104,7 @@ public: #define OMTI_STATUS_REQ 0x01 // Request (1 = request transfer of data via data in/out register) #define OMTI_STATUS_IO 0x02 // In/Out (1 = direction of transfer is from controller to host) -#define OMTI_STATUS_CD 0x04 // Command/Data ( 1 = byte transferred is command or status byte) +#define OMTI_STATUS_CD 0x04 // Command/Data (1 = byte transferred is command or status byte) #define OMTI_STATUS_BUSY 0x08 // Busy (0 = controller is idle, 1 = controller selected) #define OMTI_STATUS_DREQ 0x10 // Data Request (0 = no DMA request, 1 = DMA cycle requested) #define OMTI_STATUS_IREQ 0x20 // Interrupt Request (0 = no interrupt, 1 = command complete) @@ -281,15 +280,15 @@ ioport_constructor omti8621_device::device_input_ports() const void omti8621_device::device_start() { - LOG2(("device_start")); + LOGMASKED(LOG_LEVEL2, "device_start"); set_isa_device(); m_installed = false; - sector_buffer.resize(OMTI_DISK_SECTOR_SIZE*OMTI_MAX_BLOCK_COUNT); + m_sector_buffer.resize(OMTI_DISK_SECTOR_SIZE*OMTI_MAX_BLOCK_COUNT); - m_timer = timer_alloc(0); + m_timer = timer_alloc(FUNC(omti8621_device::trigger_interrupt), this); our_disks[0] = subdevice<omti_disk_image_device>(OMTI_DISK0_TAG); our_disks[1] = subdevice<omti_disk_image_device>(OMTI_DISK1_TAG); @@ -303,7 +302,7 @@ void omti8621_device::device_reset() { static const int io_bases[8] = { 0x320, 0x324, 0x328, 0x32c, 0x1a0, 0x1a4, 0x1a8, 0x1ac }; - LOG2(("device_reset")); + LOGMASKED(LOG_LEVEL2, "device_reset"); // you can't read I/O ports in device_start() even if they're required_ioport<> in your class! if (!m_installed) @@ -331,38 +330,38 @@ void omti8621_device::device_reset() set_jumper(our_disks[0]->m_type); // should go from reset to idle after 100 us - // state->omti_state = OMTI_STATE_RESET; - omti_state = OMTI_STATE_IDLE; + // m_omti_state = OMTI_STATE_RESET; + m_omti_state = OMTI_STATE_IDLE; - status_port = OMTI_STATUS_NU6 | OMTI_STATUS_NU7; - config_port = ~jumper; - mask_port = 0; + m_status_port = OMTI_STATUS_NU6 | OMTI_STATUS_NU7; + m_config_port = ~m_jumper; + m_mask_port = 0; // default the sector data buffer with model and status information // (i.e. set sector data buffer for cmd=0x0e READ SECTOR BUFFER) - memset(§or_buffer[0], 0, OMTI_DISK_SECTOR_SIZE); - memcpy(§or_buffer[0], "8621VB.4060487xx", 0x10); - sector_buffer[0x10] = 0; // ROM Checksum error - sector_buffer[0x11] = 0; // Processor Register error - sector_buffer[0x12] = 0; // Buffer RAM error - sector_buffer[0x13] = 0; // Sequencer Register File error - sector_buffer[0x14] = 0xc0; // 32K buffer size + memset(&m_sector_buffer[0], 0, OMTI_DISK_SECTOR_SIZE); + memcpy(&m_sector_buffer[0], "8621VB.4060487xx", 0x10); + m_sector_buffer[0x10] = 0; // ROM Checksum error + m_sector_buffer[0x11] = 0; // Processor Register error + m_sector_buffer[0x12] = 0; // Buffer RAM error + m_sector_buffer[0x13] = 0; // Sequencer Register File error + m_sector_buffer[0x14] = 0xc0; // 32K buffer size // TODO: add missing Default values for LUN 0, 1 and 3 - command_length = 0; - command_index = 0; - command_status = 0; + m_command_length = 0; + m_command_index = 0; + m_command_status = 0; - data_index = 0; - data_length = 0; + m_data_index = 0; + m_data_length = 0; clear_sense_data(); - diskaddr_ecc_error = 0; - diskaddr_format_bad_track = 0; - alternate_track_address[0] = 0; - alternate_track_address[1] = 0; + m_diskaddr_ecc_error = 0; + m_diskaddr_format_bad_track = 0; + m_alternate_track_address[0] = 0; + m_alternate_track_address[1] = 0; fd_moten_w(0); fd_rate_w(0); @@ -395,8 +394,22 @@ omti8621_device::omti8621_device( , m_floppy(*this, OMTI_FDC_TAG":%u", 0U) , m_iobase(*this, "IO_BASE") , m_biosopts(*this, "BIOS_OPTS") - , jumper(0), omti_state(0), status_port(0), config_port(0), mask_port(0), command_length(0), command_index(0), command_status(0), data_buffer(nullptr) - , data_length(0), data_index(0), diskaddr_ecc_error(0), diskaddr_format_bad_track(0), m_timer(nullptr), m_moten(0), m_installed(false) + , m_jumper(0) + , m_omti_state(0) + , m_status_port(0) + , m_config_port(0) + , m_mask_port(0) + , m_command_length(0) + , m_command_index(0) + , m_command_status(0) + , m_data_buffer(nullptr) + , m_data_length(0) + , m_data_index(0) + , m_diskaddr_ecc_error(0) + , m_diskaddr_format_bad_track(0) + , m_timer(nullptr) + , m_moten(0) + , m_installed(false) { } @@ -404,13 +417,13 @@ omti8621_device::omti8621_device( set_interrupt - update the IRQ state -------------------------------------------------*/ -void omti8621_device::set_interrupt(enum line_state line_state) +void omti8621_device::set_interrupt(line_state state) { - LOG2(("set_interrupt: status_port=%x, line_state %d", status_port, line_state)); - m_isa->irq14_w(line_state); + LOGMASKED(LOG_LEVEL2, "%s: set_interrupt: status_port=%x, line_state %d", cpu_context(), m_status_port, state); + m_isa->irq14_w(state); } -void omti8621_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(omti8621_device::trigger_interrupt) { set_interrupt(ASSERT_LINE); } @@ -420,8 +433,8 @@ void omti8621_device::device_timer(emu_timer &timer, device_timer_id id, int par ***************************************************************************/ void omti8621_device::clear_sense_data() { - LOG2(("clear_sense_data")); - memset(sense_data, 0, sizeof(sense_data)); + LOGMASKED(LOG_LEVEL2, "%s: clear_sense_data", cpu_context()); + std::fill_n(m_sense_data, std::size(m_sense_data), 0); } /*************************************************************************** @@ -429,11 +442,11 @@ void omti8621_device::clear_sense_data() { ***************************************************************************/ void omti8621_device::set_sense_data(uint8_t code, const uint8_t * cdb) { - LOG2(("set_sense_data code=%x", code)); - sense_data[0]=code; - sense_data[1]=cdb[1]; - sense_data[2]=cdb[2]; - sense_data[3]=cdb[3]; + LOGMASKED(LOG_LEVEL2, "%s: set_sense_data code=%x", cpu_context(), code); + m_sense_data[0] = code; + m_sense_data[1] = cdb[1]; + m_sense_data[2] = cdb[2]; + m_sense_data[3] = cdb[3]; } /*************************************************************************** @@ -441,7 +454,7 @@ void omti8621_device::set_sense_data(uint8_t code, const uint8_t * cdb) { ***************************************************************************/ void omti8621_device::set_configuration_data(uint8_t lun) { - LOG2(("set_configuration_data lun=%x", lun)); + LOGMASKED(LOG_LEVEL2, "%s: set_configuration_data lun=%x", cpu_context(), lun); // initialize the configuration data omti_disk_image_device *disk = our_disks[lun]; @@ -485,7 +498,7 @@ uint8_t omti8621_device::check_disk_address(const uint8_t *cdb) uint32_t disk_addr = (disk_track * disk->m_sectors) + sector; if (block_count > OMTI_MAX_BLOCK_COUNT) { - LOG(("########### check_disk_address: unexpected block count %x", block_count)); + LOGMASKED(LOG_LEVEL0, "%s: ########### check_disk_address: unexpected block count %x", cpu_context(), block_count); sense_code = OMTI_SENSE_CODE_ILLEGAL_ADDRESS | OMTI_SENSE_CODE_ADDRESS_VALID; } @@ -499,18 +512,18 @@ uint8_t omti8621_device::check_disk_address(const uint8_t *cdb) sense_code = OMTI_SENSE_CODE_ILLEGAL_ADDRESS | OMTI_SENSE_CODE_ADDRESS_VALID; } else if (cylinder >= disk->m_cylinders) { sense_code = OMTI_SENSE_CODE_ILLEGAL_ADDRESS | OMTI_SENSE_CODE_ADDRESS_VALID; - } else if ( disk_track == diskaddr_format_bad_track && disk_track != 0) { + } else if (disk_track == m_diskaddr_format_bad_track && disk_track != 0) { sense_code = OMTI_SENSE_CODE_BAD_TRACK; - } else if (disk_addr == diskaddr_ecc_error && disk_addr != 0) { + } else if (disk_addr == m_diskaddr_ecc_error && disk_addr != 0) { sense_code = OMTI_SENSE_CODE_ECC_ERROR; - } else if (disk_track == alternate_track_address[1] && disk_track != 0) { + } else if (disk_track == m_alternate_track_address[1] && disk_track != 0) { sense_code = OMTI_SENSE_CODE_ALTERNATE_TRACK; } if (sense_code == OMTI_SENSE_CODE_NO_ERROR) { clear_sense_data(); } else { - command_status |= OMTI_COMMAND_STATUS_ERROR; + m_command_status |= OMTI_COMMAND_STATUS_ERROR; set_sense_data(sense_code, cdb); } return sense_code == OMTI_SENSE_CODE_NO_ERROR; @@ -544,29 +557,29 @@ uint32_t omti8621_device::get_disk_address(const uint8_t * cdb) { void omti8621_device::set_data_transfer(uint8_t *data, uint16_t length) { // set controller for read data transfer - omti_state = OMTI_STATE_DATA; - status_port |= OMTI_STATUS_REQ | OMTI_STATUS_IO | OMTI_STATUS_BUSY; - status_port &= ~OMTI_STATUS_CD; + m_omti_state = OMTI_STATE_DATA; + m_status_port |= OMTI_STATUS_REQ | OMTI_STATUS_IO | OMTI_STATUS_BUSY; + m_status_port &= ~OMTI_STATUS_CD; - data_buffer = data; - data_length = length; - data_index = 0; + m_data_buffer = data; + m_data_length = length; + m_data_index = 0; } /*************************************************************************** - read_sectors_from_disk - read sectors starting at diskaddr into sector_buffer + read_sectors_from_disk - read sectors starting at diskaddr into m_sector_buffer ***************************************************************************/ void omti8621_device::read_sectors_from_disk(int32_t diskaddr, uint8_t count, uint8_t lun) { - uint8_t *data_buffer = §or_buffer[0]; + uint8_t *data_buffer = &m_sector_buffer[0]; device_image_interface *image = our_disks[lun]->m_image; while (count-- > 0) { - LOG2(("read_sectors_from_disk lun=%d diskaddr=%x", lun, diskaddr)); + LOGMASKED(LOG_LEVEL2, "%s: read_sectors_from_disk lun=%d diskaddr=%x", cpu_context(), lun, diskaddr); - image->fseek( diskaddr * OMTI_DISK_SECTOR_SIZE, SEEK_SET); - image->fread( data_buffer, OMTI_DISK_SECTOR_SIZE); + image->fseek(diskaddr * OMTI_DISK_SECTOR_SIZE, SEEK_SET); + image->fread(data_buffer, OMTI_DISK_SECTOR_SIZE); diskaddr++; data_buffer += OMTI_DISK_SECTOR_SIZE; @@ -574,23 +587,23 @@ void omti8621_device::read_sectors_from_disk(int32_t diskaddr, uint8_t count, ui } /*************************************************************************** - write_sectors_to_disk - write sectors starting at diskaddr from sector_buffer + write_sectors_to_disk - write sectors starting at diskaddr from m_sector_buffer ***************************************************************************/ void omti8621_device::write_sectors_to_disk(int32_t diskaddr, uint8_t count, uint8_t lun) { - uint8_t *data_buffer = §or_buffer[0]; + uint8_t *data_buffer = &m_sector_buffer[0]; device_image_interface *image = our_disks[lun]->m_image; while (count-- > 0) { - LOG2(("write_sectors_to_disk lun=%d diskaddr=%x", lun, diskaddr)); + LOGMASKED(LOG_LEVEL2, "%s: write_sectors_to_disk lun=%d diskaddr=%x", cpu_context(), lun, diskaddr); - image->fseek( diskaddr * OMTI_DISK_SECTOR_SIZE, SEEK_SET); - image->fwrite( data_buffer, OMTI_DISK_SECTOR_SIZE); + image->fseek(diskaddr * OMTI_DISK_SECTOR_SIZE, SEEK_SET); + image->fwrite(data_buffer, OMTI_DISK_SECTOR_SIZE); - if (diskaddr == diskaddr_ecc_error) { + if (diskaddr == m_diskaddr_ecc_error) { // reset previous ECC error - diskaddr_ecc_error = 0; + m_diskaddr_ecc_error = 0; } diskaddr++; @@ -606,18 +619,18 @@ void omti8621_device::copy_sectors(int32_t dst_addr, int32_t src_addr, uint8_t c { device_image_interface *image = our_disks[lun]->m_image; - LOG2(("copy_sectors lun=%d src_addr=%x dst_addr=%x count=%x", lun, src_addr, dst_addr, count)); + LOGMASKED(LOG_LEVEL2, "%s: copy_sectors lun=%d src_addr=%x dst_addr=%x count=%x", cpu_context(), lun, src_addr, dst_addr, count); while (count-- > 0) { - image->fseek( src_addr * OMTI_DISK_SECTOR_SIZE, SEEK_SET); - image->fread( §or_buffer[0], OMTI_DISK_SECTOR_SIZE); + image->fseek(src_addr * OMTI_DISK_SECTOR_SIZE, SEEK_SET); + image->fread(&m_sector_buffer[0], OMTI_DISK_SECTOR_SIZE); - image->fseek( dst_addr * OMTI_DISK_SECTOR_SIZE, SEEK_SET); - image->fwrite( §or_buffer[0], OMTI_DISK_SECTOR_SIZE); + image->fseek(dst_addr * OMTI_DISK_SECTOR_SIZE, SEEK_SET); + image->fwrite(&m_sector_buffer[0], OMTI_DISK_SECTOR_SIZE); - if (dst_addr == diskaddr_ecc_error) { + if (dst_addr == m_diskaddr_ecc_error) { // reset previous ECC error - diskaddr_ecc_error = 0; + m_diskaddr_ecc_error = 0; } src_addr++; @@ -635,29 +648,29 @@ void omti8621_device::format_track(const uint8_t * cdb) uint32_t disk_addr = get_disk_address(cdb); uint32_t disk_track = get_disk_track(cdb); - if (diskaddr_ecc_error == disk_addr) { + if (m_diskaddr_ecc_error == disk_addr) { // reset previous ECC error - diskaddr_ecc_error = 0; + m_diskaddr_ecc_error = 0; } - if (diskaddr_format_bad_track == disk_track) { + if (m_diskaddr_format_bad_track == disk_track) { // reset previous bad track formatting - diskaddr_format_bad_track = 0; + m_diskaddr_format_bad_track = 0; } - if (alternate_track_address[0] == disk_track) { + if (m_alternate_track_address[0] == disk_track) { // reset source of alternate track address - alternate_track_address[0] = 0; + m_alternate_track_address[0] = 0; } - if (alternate_track_address[1] == disk_track) { + if (m_alternate_track_address[1] == disk_track) { // reset alternate track address - alternate_track_address[1] = 0; + m_alternate_track_address[1] = 0; } if (check_disk_address(cdb) ) { if ((cdb[5] & 0x40) == 0) { - memset(§or_buffer[0], 0x6C, OMTI_DISK_SECTOR_SIZE * our_disks[lun]->m_sectors); + memset(&m_sector_buffer[0], 0x6C, OMTI_DISK_SECTOR_SIZE * our_disks[lun]->m_sectors); } write_sectors_to_disk(disk_addr, our_disks[lun]->m_sectors, lun); } @@ -696,8 +709,7 @@ void omti8621_device::logerror(Format &&fmt, Params &&... args) const void omti8621_device::log_command(const uint8_t cdb[], const uint16_t cdb_length) { - if (verbose > 0) { - int i; + if (VERBOSE & (LOG_LEVEL1 | LOG_LEVEL2 | LOG_LEVEL3)) { logerror("%s: OMTI command ", cpu_context()); switch (cdb[0]) { case OMTI_CMD_TEST_DRIVE_READY: // 0x00 @@ -770,7 +782,7 @@ void omti8621_device::log_command(const uint8_t cdb[], const uint16_t cdb_length logerror("!!! Unexpected Command !!!"); } // logerror(" (%02x, length=%02x)", cdb[0], cdb_length); - for (i = 0; i < cdb_length; i++) { + for (int i = 0; i < cdb_length; i++) { logerror(" %02x", cdb[i]); } @@ -795,15 +807,14 @@ void omti8621_device::log_command(const uint8_t cdb[], const uint16_t cdb_length void omti8621_device::log_data() { - if (verbose > 0) { - int i; - logerror("%s: OMTI data (length=%02x)", cpu_context(), - data_length); - for (i = 0; i < data_length && i < OMTI_DISK_SECTOR_SIZE; i++) { - logerror(" %02x", data_buffer[i]); + if (VERBOSE & LOG_LEVEL1) { + logerror("%s: OMTI data (length=%02x)", cpu_context(), m_data_length); + uint16_t i; + for (i = 0; i < m_data_length && i < OMTI_DISK_SECTOR_SIZE; i++) { + logerror(" %02x", m_data_buffer[i]); } - if (i < data_length) { + if (i < m_data_length) { logerror(" ..."); } logerror("\n"); @@ -820,19 +831,19 @@ void omti8621_device::do_command(const uint8_t cdb[], const uint16_t cdb_length) omti_disk_image_device *disk = our_disks[lun]; int command_duration = 0; // ms - log_command( cdb, cdb_length); + log_command(cdb, cdb_length); // default to read status and status is successful completion - omti_state = OMTI_STATE_STATUS; - status_port |= OMTI_STATUS_IO | OMTI_STATUS_CD; - command_status = lun ? OMTI_COMMAND_STATUS_LUN : 0; + m_omti_state = OMTI_STATE_STATUS; + m_status_port |= OMTI_STATUS_IO | OMTI_STATUS_CD; + m_command_status = lun ? OMTI_COMMAND_STATUS_LUN : 0; - if (mask_port & OMTI_MASK_INTE) { + if (m_mask_port & OMTI_MASK_INTE) { set_interrupt(CLEAR_LINE); } if (!disk->m_image->exists()) { - command_status |= OMTI_COMMAND_STATUS_ERROR; // no such drive + m_command_status |= OMTI_COMMAND_STATUS_ERROR; // no such drive } switch (cdb[0]) { @@ -847,7 +858,7 @@ void omti8621_device::do_command(const uint8_t cdb[], const uint16_t cdb_length) break; case OMTI_CMD_REQUEST_SENSE: // 0x03 - set_data_transfer(sense_data, sizeof(sense_data)); + set_data_transfer(m_sense_data, sizeof(m_sense_data)); break; case OMTI_CMD_READ_VERIFY: // 0x05 @@ -859,14 +870,14 @@ void omti8621_device::do_command(const uint8_t cdb[], const uint16_t cdb_length) break; case OMTI_CMD_FORMAT_BAD_TRACK: // 0x07 - diskaddr_format_bad_track = get_disk_address(cdb); + m_diskaddr_format_bad_track = get_disk_address(cdb); break; case OMTI_CMD_READ: // 0x08 if (check_disk_address(cdb)) { // read data from controller read_sectors_from_disk(get_disk_address(cdb), cdb[4], lun); - set_data_transfer(§or_buffer[0], OMTI_DISK_SECTOR_SIZE*cdb[4]); + set_data_transfer(&m_sector_buffer[0], OMTI_DISK_SECTOR_SIZE*cdb[4]); } break; @@ -882,7 +893,7 @@ void omti8621_device::do_command(const uint8_t cdb[], const uint16_t cdb_length) break; case OMTI_CMD_READ_SECTOR_BUFFER: // 0x0E - set_data_transfer(§or_buffer[0], OMTI_DISK_SECTOR_SIZE*cdb[4]); + set_data_transfer(&m_sector_buffer[0], OMTI_DISK_SECTOR_SIZE*cdb[4]); break; case OMTI_CMD_WRITE_SECTOR_BUFFER: // 0x0F @@ -904,8 +915,8 @@ void omti8621_device::do_command(const uint8_t cdb[], const uint16_t cdb_length) #if 0 // this command seems unused by Domain/OS, and it's unclear what the intent of the code is (it makes some versions of GCC quite unhappy) case OMTI_CMD_ASSIGN_ALTERNATE_TRACK: // 0x11 log_data(); - alternate_track_address[0] = get_disk_track(cdb); - alternate_track_address[1] = get_disk_track(alternate_track_buffer-1); + m_alternate_track_address[0] = get_disk_track(cdb); + m_alternate_track_address[1] = get_disk_track(m_alternate_track_buffer - 1); break; #endif @@ -935,7 +946,7 @@ void omti8621_device::do_command(const uint8_t cdb[], const uint16_t cdb_length) if (check_disk_address(cdb)) { // read data from controller read_sectors_from_disk(get_disk_address(cdb), cdb[4], lun); - set_data_transfer(§or_buffer[0], OMTI_DISK_SECTOR_SIZE+6); + set_data_transfer(&m_sector_buffer[0], OMTI_DISK_SECTOR_SIZE+6); } break; @@ -945,7 +956,7 @@ void omti8621_device::do_command(const uint8_t cdb[], const uint16_t cdb_length) uint32_t diskaddr = get_disk_address(cdb); write_sectors_to_disk(diskaddr, cdb[4], lun); // this will spoil the ECC code - diskaddr_ecc_error = diskaddr; + m_diskaddr_ecc_error = diskaddr; } break; @@ -956,28 +967,28 @@ void omti8621_device::do_command(const uint8_t cdb[], const uint16_t cdb_length) case OMTI_CMD_INVALID_COMMAND: // 0xFF set_sense_data(OMTI_SENSE_CODE_INVALID_COMMAND, cdb); - command_status |= OMTI_COMMAND_STATUS_ERROR; + m_command_status |= OMTI_COMMAND_STATUS_ERROR; break; default: - LOG(("do_command: UNEXPECTED command %02x",cdb[0])); + LOGMASKED(LOG_LEVEL0, "%s: do_command: UNEXPECTED command %02x", cpu_context(), cdb[0]); set_sense_data(OMTI_SENSE_CODE_INVALID_COMMAND, cdb); - command_status |= OMTI_COMMAND_STATUS_ERROR; + m_command_status |= OMTI_COMMAND_STATUS_ERROR; break; } - if (mask_port & OMTI_MASK_INTE) { -// if (omti_state != OMTI_STATE_STATUS) { -// LOG(("do_command: UNEXPECTED omti_state %02x",omti_state)); + if (m_mask_port & OMTI_MASK_INTE) { +// if (m_omti_state != OMTI_STATE_STATUS) { +// LOGMASKED(LOG_LEVEL0, "%s: do_command: UNEXPECTED omti_state %02x", cpu_context(), m_omti_state)); // } - status_port |= OMTI_STATUS_IREQ; + m_status_port |= OMTI_STATUS_IREQ; if (command_duration == 0) { set_interrupt(ASSERT_LINE); } else { - // FIXME: should delay omti_state and status_port as well + // FIXME: should delay m_omti_state and m_status_port as well m_timer->adjust(attotime::from_msec(command_duration), 0); } } @@ -999,16 +1010,16 @@ uint8_t omti8621_device::get_command_length(uint8_t command_byte) uint16_t omti8621_device::get_data() { uint16_t data = 0xff; - if (data_index < data_length) { - data = data_buffer[data_index++]; - data |= data_buffer[data_index++] << 8; - if (data_index >= data_length) { - omti_state = OMTI_STATE_STATUS; - status_port |= OMTI_STATUS_IO | OMTI_STATUS_CD; + if (m_data_index < m_data_length) { + data = m_data_buffer[m_data_index++]; + data |= m_data_buffer[m_data_index++] << 8; + if (m_data_index >= m_data_length) { + m_omti_state = OMTI_STATE_STATUS; + m_status_port |= OMTI_STATUS_IO | OMTI_STATUS_CD; log_data(); } } else { - LOG(("UNEXPECTED reading OMTI 8621 data (buffer length exceeded)")); + LOGMASKED(LOG_LEVEL0, "%s: UNEXPECTED reading OMTI 8621 data (buffer length exceeded)", cpu_context()); } return data; } @@ -1019,14 +1030,14 @@ uint16_t omti8621_device::get_data() void omti8621_device::set_data(uint16_t data) { - if (data_index < data_length) { - data_buffer[data_index++] = data & 0xff; - data_buffer[data_index++] = data >> 8; - if (data_index >= data_length) { - do_command(command_buffer, command_index); + if (m_data_index < m_data_length) { + m_data_buffer[m_data_index++] = data & 0xff; + m_data_buffer[m_data_index++] = data >> 8; + if (m_data_index >= m_data_length) { + do_command(m_command_buffer, m_command_index); } } else { - LOG(("UNEXPECTED writing OMTI 8621 data (buffer length exceeded)")); + LOGMASKED(LOG_LEVEL0, "%s: UNEXPECTED writing OMTI 8621 data (buffer length exceeded)", cpu_context()); } } @@ -1057,91 +1068,89 @@ void omti8621_device::write8(offs_t offset, uint8_t data) switch (offset) { case OMTI_PORT_DATA_OUT: // 0x00 - switch (omti_state) { + switch (m_omti_state) { case OMTI_STATE_COMMAND: - LOG2(("writing OMTI 8621 Command Register at offset %02x = %02x", offset, data)); - if (command_index == 0) { - command_length = get_command_length(data); + LOGMASKED(LOG_LEVEL2, "%s: writing OMTI 8621 Command Register at offset %02x = %02x", cpu_context(), offset, data); + if (m_command_index == 0) { + m_command_length = get_command_length(data); } - if (command_index < command_length) { - command_buffer[command_index++] = data; + if (m_command_index < m_command_length) { + m_command_buffer[m_command_index++] = data; } else { - LOG(("UNEXPECTED writing OMTI 8621 Data Register at offset %02x = %02x (command length exceeded)", offset, data)); + LOGMASKED(LOG_LEVEL0, "%s: UNEXPECTED writing OMTI 8621 Data Register at offset %02x = %02x (command length exceeded)", cpu_context(), offset, data); } - if (command_index == command_length) { - switch (command_buffer[0]) { + if (m_command_index == m_command_length) { + switch (m_command_buffer[0]) { case OMTI_CMD_WRITE: // 0x0A // TODO: check diskaddr - // Fall through + [[fallthrough]]; case OMTI_CMD_WRITE_SECTOR_BUFFER: // 0x0F - set_data_transfer(§or_buffer[0], - OMTI_DISK_SECTOR_SIZE * command_buffer[4]); - status_port &= ~OMTI_STATUS_IO; + set_data_transfer(&m_sector_buffer[0], OMTI_DISK_SECTOR_SIZE * m_command_buffer[4]); + m_status_port &= ~OMTI_STATUS_IO; break; case OMTI_CMD_ASSIGN_ALTERNATE_TRACK: // 0x11 - set_data_transfer(alternate_track_buffer, sizeof(alternate_track_buffer)); - status_port &= ~OMTI_STATUS_IO; + set_data_transfer(m_alternate_track_buffer, sizeof(m_alternate_track_buffer)); + m_status_port &= ~OMTI_STATUS_IO; break; case OMTI_CMD_WRITE_LONG: // 0xE6 // TODO: check diskaddr - set_data_transfer(§or_buffer[0], - (OMTI_DISK_SECTOR_SIZE +6) * command_buffer[4]); - status_port &= ~OMTI_STATUS_IO; + set_data_transfer(&m_sector_buffer[0], (OMTI_DISK_SECTOR_SIZE +6) * m_command_buffer[4]); + m_status_port &= ~OMTI_STATUS_IO; break; default: - do_command(command_buffer, command_index); + do_command(m_command_buffer, m_command_index); break; } } break; case OMTI_STATE_DATA: - LOG(("UNEXPECTED: writing OMTI 8621 Data Register at offset %02x = %02x", offset, data)); + LOGMASKED(LOG_LEVEL0, "%s: UNEXPECTED: writing OMTI 8621 Data Register at offset %02x = %02x", cpu_context(), offset, data); break; default: - LOG(("UNEXPECTED writing OMTI 8621 Data Register at offset %02x = %02x (omti state = %02x)", offset, data, omti_state)); + LOGMASKED(LOG_LEVEL0, "%s: UNEXPECTED writing OMTI 8621 Data Register at offset %02x = %02x (omti state = %02x)", cpu_context(), offset, data, m_omti_state); break; } break; case OMTI_PORT_RESET: // 0x01 - LOG2(("writing OMTI 8621 Reset Register at offset %02x = %02x", offset, data)); + LOGMASKED(LOG_LEVEL2, "%s: writing OMTI 8621 Reset Register at offset %02x = %02x", cpu_context(), offset, data); device_reset(); break; case OMTI_PORT_SELECT: // 0x02 - LOG2(("writing OMTI 8621 Select Register at offset %02x = %02x (omti state = %02x)", offset, data, omti_state)); - omti_state = OMTI_STATE_COMMAND; + LOGMASKED(LOG_LEVEL2, "%s: writing OMTI 8621 Select Register at offset %02x = %02x (omti state = %02x)", cpu_context(), offset, data, m_omti_state); + m_omti_state = OMTI_STATE_COMMAND; - status_port |= OMTI_STATUS_BUSY | OMTI_STATUS_REQ | OMTI_STATUS_CD; - status_port &= ~OMTI_STATUS_IO; + m_status_port |= OMTI_STATUS_BUSY | OMTI_STATUS_REQ | OMTI_STATUS_CD; + m_status_port &= ~OMTI_STATUS_IO; - command_status = 0; - command_index = 0; + m_command_status = 0; + m_command_index = 0; break; case OMTI_PORT_MASK: // 0x03 - LOG2(("writing OMTI 8621 Mask Register at offset %02x = %02x", offset, data)); - mask_port = data; + LOGMASKED(LOG_LEVEL2, "%s: writing OMTI 8621 Mask Register at offset %02x = %02x", cpu_context(), offset, data); + m_mask_port = data; if ((data & OMTI_MASK_INTE) == 0) { - status_port &= ~OMTI_STATUS_IREQ; + m_status_port &= ~OMTI_STATUS_IREQ; set_interrupt(CLEAR_LINE); } if ((data & OMTI_MASK_DMAE) == 0) { - status_port &= ~OMTI_STATUS_DREQ; + m_status_port &= ~OMTI_STATUS_DREQ; } break; default: - LOG(("UNEXPECTED writing OMTI 8621 Register at offset %02x = %02x", offset, data)); + LOGMASKED(LOG_LEVEL0, "%s: UNEXPECTED writing OMTI 8621 Register at offset %02x = %02x", cpu_context(), offset, data); break; } } @@ -1166,69 +1175,64 @@ uint8_t omti8621_device::read8(offs_t offset) switch (offset) { case OMTI_PORT_DATA_IN: // 0x00 - if (status_port & OMTI_STATUS_CD) + if (m_status_port & OMTI_STATUS_CD) { - data = command_status; - switch (omti_state) + data = m_command_status; + switch (m_omti_state) { case OMTI_STATE_COMMAND: - LOG2(("reading OMTI 8621 Data Status Register 1 at offset %02x = %02x (omti state = %02x)", offset, data, omti_state)); + LOGMASKED(LOG_LEVEL2, "%s: reading OMTI 8621 Data Status Register 1 at offset %02x = %02x (omti state = %02x)", cpu_context(), offset, data, m_omti_state); break; case OMTI_STATE_STATUS: - omti_state = OMTI_STATE_IDLE; - status_port &= ~(OMTI_STATUS_BUSY | OMTI_STATUS_CD | OMTI_STATUS_IO | OMTI_STATUS_REQ); - LOG2(("reading OMTI 8621 Data Status Register 2 at offset %02x = %02x", offset, data)); + m_omti_state = OMTI_STATE_IDLE; + m_status_port &= ~(OMTI_STATUS_BUSY | OMTI_STATUS_CD | OMTI_STATUS_IO | OMTI_STATUS_REQ); + LOGMASKED(LOG_LEVEL2, "%s: reading OMTI 8621 Data Status Register 2 at offset %02x = %02x", cpu_context(), offset, data); break; default: - LOG(("UNEXPECTED reading OMTI 8621 Data Status Register 3 at offset %02x = %02x (omti state = %02x)", offset, data, omti_state)); + LOGMASKED(LOG_LEVEL0, "%s: UNEXPECTED reading OMTI 8621 Data Status Register 3 at offset %02x = %02x (omti state = %02x)", cpu_context(), offset, data, m_omti_state); break; } } else { - LOG(("UNEXPECTED reading OMTI 8621 Data Register 4 at offset %02x = %02x (status bit C/D = 0)", offset, data)); + LOGMASKED(LOG_LEVEL0, "%s: UNEXPECTED reading OMTI 8621 Data Register 4 at offset %02x = %02x (status bit C/D = 0)", cpu_context(), offset, data); } break; case OMTI_PORT_STATUS: // 0x01 - data = status_port; + data = m_status_port; // omit excessive logging if (data != last_data) { - LOG2(("reading OMTI 8621 Status Register 5 at offset %02x = %02x", offset, data)); + LOGMASKED(LOG_LEVEL2, "%s: reading OMTI 8621 Status Register 5 at offset %02x = %02x", cpu_context(), offset, data); // last_data = data; } break; case OMTI_PORT_CONFIG: // 0x02 - data = config_port; - LOG2(("reading OMTI 8621 Configuration Register at offset %02x = %02x", offset, data)); + data = m_config_port; + LOGMASKED(LOG_LEVEL2, "%s: reading OMTI 8621 Configuration Register at offset %02x = %02x", cpu_context(), offset, data); break; case OMTI_PORT_MASK: // 0x03 - data = mask_port ; + data = m_mask_port; // win.dex will update the mask register with read-modify-write - // LOG2(("reading OMTI 8621 Mask Register at offset %02x = %02x (UNEXPECTED!)", offset, data)); + // LOGMASKED(LOG_LEVEL2, "%s: reading OMTI 8621 Mask Register at offset %02x = %02x (UNEXPECTED!)", cpu_context(), offset, data); break; default: - LOG(("UNEXPECTED reading OMTI 8621 Register at offset %02x = %02x", offset, data)); + LOGMASKED(LOG_LEVEL0, "%s: UNEXPECTED reading OMTI 8621 Register at offset %02x = %02x", cpu_context(), offset, data); break; } return data; } -void omti8621_device::set_verbose(int on_off) -{ - verbose = on_off == 0 ? 0 : VERBOSE > 1 ? VERBOSE : 1; -} - /*************************************************************************** get_sector - get sector diskaddr of logical unit lun into data_buffer ***************************************************************************/ -uint32_t omti8621_apollo_device::get_sector(int32_t diskaddr, uint8_t *data_buffer, uint32_t length, uint8_t lun) +uint32_t omti8621_apollo_device::get_sector(int32_t diskaddr, uint8_t *buffer, uint32_t length, uint8_t lun) { omti_disk_image_device *disk = our_disks[lun]; @@ -1238,13 +1242,13 @@ uint32_t omti8621_apollo_device::get_sector(int32_t diskaddr, uint8_t *data_buff } else { -// LOG1(("omti8621_get_sector %x on lun %d", diskaddr, lun)); +// LOGMASKED(LOG_LEVEL1, "%s: omti8621_get_sector %x on lun %d", cpu_context(), diskaddr, lun); // restrict length to size of 1 sector (i.e. 1024 Byte) length = length < OMTI_DISK_SECTOR_SIZE ? length : OMTI_DISK_SECTOR_SIZE; disk->m_image->fseek(diskaddr * OMTI_DISK_SECTOR_SIZE, SEEK_SET); - disk->m_image->fread(data_buffer, length); + disk->m_image->fread(buffer, length); return length; } @@ -1256,17 +1260,17 @@ uint32_t omti8621_apollo_device::get_sector(int32_t diskaddr, uint8_t *data_buff void omti8621_device::set_jumper(uint16_t disk_type) { - LOG1(("set_jumper: disk type=%x", disk_type)); + LOGMASKED(LOG_LEVEL1, "%s: set_jumper: disk type=%x", cpu_context(), disk_type); switch (disk_type) { case OMTI_DISK_TYPE_348_MB: // Maxtor 380 MB (348-MB FA formatted) - jumper = OMTI_CONFIG_W22 | OMTI_CONFIG_W23; + m_jumper = OMTI_CONFIG_W22 | OMTI_CONFIG_W23; break; case OMTI_DISK_TYPE_155_MB: // Micropolis 170 MB (155-MB formatted) default: - jumper = OMTI_CONFIG_W20; + m_jumper = OMTI_CONFIG_W20; break; } } diff --git a/src/devices/bus/isa/omti8621.h b/src/devices/bus/isa/omti8621.h index ccc4ae0785b..3e5cce1c59a 100644 --- a/src/devices/bus/isa/omti8621.h +++ b/src/devices/bus/isa/omti8621.h @@ -33,8 +33,6 @@ public: uint16_t read(offs_t offset, uint16_t mem_mask = 0xffff); void write(offs_t offset, uint16_t data, uint16_t mem_mask = 0xffff); - static void set_verbose(int on_off); - protected: static constexpr unsigned OMTI_MAX_LUN = 1; static constexpr unsigned CDB_SIZE = 10; @@ -50,7 +48,6 @@ 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 device_add_mconfig(machine_config &config) override; virtual ioport_constructor device_input_ports() const override; @@ -59,7 +56,9 @@ protected: virtual void dack_line_w(int line, int state) override; virtual void eop_w(int state) override; - void set_interrupt(enum line_state line_state); + void set_interrupt(line_state state); + + TIMER_CALLBACK_MEMBER(trigger_interrupt); required_device<upd765a_device> m_fdc; optional_device_array<floppy_connector, 2> m_floppy; @@ -82,34 +81,34 @@ private: void fdc_map(address_map &map); - uint16_t jumper; + uint16_t m_jumper; - uint8_t omti_state; + uint8_t m_omti_state; - uint8_t status_port; - uint8_t config_port; - uint8_t mask_port; + uint8_t m_status_port; + uint8_t m_config_port; + uint8_t m_mask_port; // command descriptor block - uint8_t command_buffer[CDB_SIZE]; - int command_length; - int command_index; - int command_status; + uint8_t m_command_buffer[CDB_SIZE]; + uint8_t m_command_length; + uint16_t m_command_index; + uint8_t m_command_status; // data buffer - std::vector<uint8_t> sector_buffer; - uint8_t *data_buffer; - int data_length; - int data_index; + std::vector<uint8_t> m_sector_buffer; + uint8_t *m_data_buffer; + uint16_t m_data_length; + uint16_t m_data_index; // sense data - uint8_t sense_data[4]; + uint8_t m_sense_data[4]; // these are used only to satisfy dex - uint32_t diskaddr_ecc_error; - uint32_t diskaddr_format_bad_track; - uint8_t alternate_track_buffer[4]; - uint32_t alternate_track_address[2]; + uint32_t m_diskaddr_ecc_error; + uint32_t m_diskaddr_format_bad_track; + uint8_t m_alternate_track_buffer[4]; + uint32_t m_alternate_track_address[2]; emu_timer *m_timer; @@ -162,7 +161,7 @@ public: omti8621_apollo_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock); // get sector diskaddr of logical unit lun into data_buffer - uint32_t get_sector(int32_t diskaddr, uint8_t *data_buffer, uint32_t length, uint8_t lun); + uint32_t get_sector(int32_t diskaddr, uint8_t *buffer, uint32_t length, uint8_t lun); protected: virtual void device_add_mconfig(machine_config &config) override; diff --git a/src/devices/bus/isa/s3virge.cpp b/src/devices/bus/isa/s3virge.cpp index 0f6edd65976..63930b308b1 100644 --- a/src/devices/bus/isa/s3virge.cpp +++ b/src/devices/bus/isa/s3virge.cpp @@ -83,8 +83,8 @@ void s3virge_vga_device::device_start() save_item(vga.sequencer.data,"Sequencer Registers"); save_item(vga.attribute.data,"Attribute Registers"); - m_vblank_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(vga_device::vblank_timer_cb),this)); - m_draw_timer = timer_alloc(TIMER_DRAW_STEP); + m_vblank_timer = timer_alloc(FUNC(vga_device::vblank_timer_cb), this); + m_draw_timer = timer_alloc(FUNC(s3virge_vga_device::draw_step_tick), this); memset(&s3, 0, sizeof(s3)); memset(&s3virge, 0, sizeof(s3virge)); @@ -1427,35 +1427,96 @@ void s3virge_vga_device::bitblt_monosrc_step() s3virge.s3d.bitblt_step_count++; } -void s3virge_vga_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(s3virge_vga_device::draw_step_tick) { // TODO: S3D state timing - if(id == TIMER_DRAW_STEP) + switch(s3virge.s3d.state) { - switch(s3virge.s3d.state) - { - case S3D_STATE_IDLE: - m_draw_timer->adjust(attotime::zero); - break; - case S3D_STATE_2DLINE: - line2d_step(); - break; - case S3D_STATE_2DPOLY: - poly2d_step(); - break; - case S3D_STATE_3DLINE: - line3d_step(); - break; - case S3D_STATE_3DPOLY: - poly3d_step(); - break; - case S3D_STATE_BITBLT: - bitblt_step(); - break; - } + case S3D_STATE_IDLE: + m_draw_timer->adjust(attotime::zero); + break; + case S3D_STATE_2DLINE: + line2d_step(); + break; + case S3D_STATE_2DPOLY: + poly2d_step(); + break; + case S3D_STATE_3DLINE: + line3d_step(); + break; + case S3D_STATE_3DPOLY: + poly3d_step(); + break; + case S3D_STATE_BITBLT: + bitblt_step(); + break; } } +inline void s3virge_vga_device::write_pixel32(uint32_t base, uint16_t x, uint16_t y, uint32_t val) +{ + if(s3virge.s3d.cmd_fifo[s3virge.s3d.cmd_fifo_current_ptr].reg[S3D_REG_COMMAND] & 0x00000002) + if(x < s3virge.s3d.clip_l || x > s3virge.s3d.clip_r || y < s3virge.s3d.clip_t || y > s3virge.s3d.clip_b) + return; + vga.memory[(base + (x*4) + (y*dest_stride())) % vga.svga_intf.vram_size] = val & 0xff; + vga.memory[(base + 1 + (x*4) + (y*dest_stride())) % vga.svga_intf.vram_size] = (val >> 8) & 0xff; + vga.memory[(base + 2 + (x*4) + (y*dest_stride())) % vga.svga_intf.vram_size] = (val >> 16) & 0xff; + vga.memory[(base + 3 + (x*4) + (y*dest_stride())) % vga.svga_intf.vram_size] = (val >> 24) & 0xff; +} + +inline void s3virge_vga_device::write_pixel24(uint32_t base, uint16_t x, uint16_t y, uint32_t val) +{ + if(s3virge.s3d.cmd_fifo[s3virge.s3d.cmd_fifo_current_ptr].reg[S3D_REG_COMMAND] & 0x00000002) + if(x < s3virge.s3d.clip_l || x > s3virge.s3d.clip_r || y < s3virge.s3d.clip_t || y > s3virge.s3d.clip_b) + return; + vga.memory[(base + (x*3) + (y*dest_stride())) % vga.svga_intf.vram_size] = val & 0xff; + vga.memory[(base + 1 + (x*3) + (y*dest_stride())) % vga.svga_intf.vram_size] = (val >> 8) & 0xff; + vga.memory[(base + 2 + (x*3) + (y*dest_stride())) % vga.svga_intf.vram_size] = (val >> 16) & 0xff; +} + +inline void s3virge_vga_device::write_pixel16(uint32_t base, uint16_t x, uint16_t y, uint16_t val) +{ + if(s3virge.s3d.cmd_fifo[s3virge.s3d.cmd_fifo_current_ptr].reg[S3D_REG_COMMAND] & 0x00000002) + if(x < s3virge.s3d.clip_l || x > s3virge.s3d.clip_r || y < s3virge.s3d.clip_t || y > s3virge.s3d.clip_b) + return; + vga.memory[(base + (x*2) + (y*dest_stride())) % vga.svga_intf.vram_size] = val & 0xff; + vga.memory[(base + 1 + (x*2) + (y*dest_stride())) % vga.svga_intf.vram_size] = (val >> 8) & 0xff; +} + +inline void s3virge_vga_device::write_pixel8(uint32_t base, uint16_t x, uint16_t y, uint8_t val) +{ + if(s3virge.s3d.cmd_fifo[s3virge.s3d.cmd_fifo_current_ptr].reg[S3D_REG_COMMAND] & 0x00000002) + if(x < s3virge.s3d.clip_l || x > s3virge.s3d.clip_r || y < s3virge.s3d.clip_t || y > s3virge.s3d.clip_b) + return; + vga.memory[(base + x + (y*dest_stride())) % vga.svga_intf.vram_size] = val; +} + +inline uint32_t s3virge_vga_device::read_pixel32(uint32_t base, uint16_t x, uint16_t y) +{ + return (vga.memory[(base + (x*4) + (y*dest_stride())) % vga.svga_intf.vram_size] << 24) | + (vga.memory[(base + 1 + (x*4) + (y*dest_stride())) % vga.svga_intf.vram_size] << 16) | + (vga.memory[(base + 2 + (x*4) + (y*dest_stride())) % vga.svga_intf.vram_size] << 8) | + vga.memory[(base + 3 + (x*4) + (y*dest_stride())) % vga.svga_intf.vram_size]; +} + +inline uint32_t s3virge_vga_device::read_pixel24(uint32_t base, uint16_t x, uint16_t y) +{ + return (vga.memory[(base + (x*3) + (y*dest_stride())) % vga.svga_intf.vram_size]) | + (vga.memory[(base + 1 + (x*3) + (y*dest_stride())) % vga.svga_intf.vram_size] << 8) | + (vga.memory[(base + 2 + (x*3) + (y*dest_stride())) % vga.svga_intf.vram_size] << 16); +} + +inline uint16_t s3virge_vga_device::read_pixel16(uint32_t base, uint16_t x, uint16_t y) +{ + return (vga.memory[(base + (x*2) + (y*dest_stride()) % vga.svga_intf.vram_size)]) | + (vga.memory[(base + 1 + (x*2) + (y*dest_stride())) % vga.svga_intf.vram_size] << 8); +} + +inline uint8_t s3virge_vga_device::read_pixel8(uint32_t base, uint16_t x, uint16_t y) +{ + return vga.memory[(base + x + (y*dest_stride())) % vga.svga_intf.vram_size]; +} + // 2D command register format - A500 (BitBLT), A900 (2D line), AD00 (2D Polygon) // bit 0 - Autoexecute, if set command is executed when the highest relevant register is written to (A50C / A97C / AD7C) // bit 1 - Enable hardware clipping diff --git a/src/devices/bus/isa/s3virge.h b/src/devices/bus/isa/s3virge.h index 89023e3bafc..aec31340d7b 100644 --- a/src/devices/bus/isa/s3virge.h +++ b/src/devices/bus/isa/s3virge.h @@ -74,12 +74,6 @@ public: ibm8514a_device* get_8514() { fatalerror("s3virge requested non-existent 8514/A device\n"); return nullptr; } - enum - { - TIMER_DRAW_STEP = 10 - }; - - protected: s3virge_vga_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock); @@ -184,59 +178,17 @@ protected: } s3d; } s3virge; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; - void write_pixel32(uint32_t base, uint16_t x, uint16_t y, uint32_t val) - { - if(s3virge.s3d.cmd_fifo[s3virge.s3d.cmd_fifo_current_ptr].reg[S3D_REG_COMMAND] & 0x00000002) - if(x < s3virge.s3d.clip_l || x > s3virge.s3d.clip_r || y < s3virge.s3d.clip_t || y > s3virge.s3d.clip_b) - return; - vga.memory[(base + (x*4) + (y*dest_stride())) % vga.svga_intf.vram_size] = val & 0xff; - vga.memory[(base + 1 + (x*4) + (y*dest_stride())) % vga.svga_intf.vram_size] = (val >> 8) & 0xff; - vga.memory[(base + 2 + (x*4) + (y*dest_stride())) % vga.svga_intf.vram_size] = (val >> 16) & 0xff; - vga.memory[(base + 3 + (x*4) + (y*dest_stride())) % vga.svga_intf.vram_size] = (val >> 24) & 0xff; - } - void write_pixel24(uint32_t base, uint16_t x, uint16_t y, uint32_t val) - { - if(s3virge.s3d.cmd_fifo[s3virge.s3d.cmd_fifo_current_ptr].reg[S3D_REG_COMMAND] & 0x00000002) - if(x < s3virge.s3d.clip_l || x > s3virge.s3d.clip_r || y < s3virge.s3d.clip_t || y > s3virge.s3d.clip_b) - return; - vga.memory[(base + (x*3) + (y*dest_stride())) % vga.svga_intf.vram_size] = val & 0xff; - vga.memory[(base + 1 + (x*3) + (y*dest_stride())) % vga.svga_intf.vram_size] = (val >> 8) & 0xff; - vga.memory[(base + 2 + (x*3) + (y*dest_stride())) % vga.svga_intf.vram_size] = (val >> 16) & 0xff; - } - void write_pixel16(uint32_t base, uint16_t x, uint16_t y, uint16_t val) - { - if(s3virge.s3d.cmd_fifo[s3virge.s3d.cmd_fifo_current_ptr].reg[S3D_REG_COMMAND] & 0x00000002) - if(x < s3virge.s3d.clip_l || x > s3virge.s3d.clip_r || y < s3virge.s3d.clip_t || y > s3virge.s3d.clip_b) - return; - vga.memory[(base + (x*2) + (y*dest_stride())) % vga.svga_intf.vram_size] = val & 0xff; - vga.memory[(base + 1 + (x*2) + (y*dest_stride())) % vga.svga_intf.vram_size] = (val >> 8) & 0xff; - } - void write_pixel8(uint32_t base, uint16_t x, uint16_t y, uint8_t val) - { - if(s3virge.s3d.cmd_fifo[s3virge.s3d.cmd_fifo_current_ptr].reg[S3D_REG_COMMAND] & 0x00000002) - if(x < s3virge.s3d.clip_l || x > s3virge.s3d.clip_r || y < s3virge.s3d.clip_t || y > s3virge.s3d.clip_b) - return; - vga.memory[(base + x + (y*dest_stride())) % vga.svga_intf.vram_size] = val; - } - uint32_t read_pixel32(uint32_t base, uint16_t x, uint16_t y) - { - return (vga.memory[(base + (x*4) + (y*dest_stride())) % vga.svga_intf.vram_size] << 24) | (vga.memory[(base + 1 + (x*4) + (y*dest_stride())) % vga.svga_intf.vram_size] << 16) - | (vga.memory[(base + 2 + (x*4) + (y*dest_stride())) % vga.svga_intf.vram_size] << 8) | vga.memory[(base + 3 + (x*4) + (y*dest_stride())) % vga.svga_intf.vram_size]; - } - uint32_t read_pixel24(uint32_t base, uint16_t x, uint16_t y) - { - return (vga.memory[(base + (x*3) + (y*dest_stride())) % vga.svga_intf.vram_size]) | (vga.memory[(base + 1 + (x*3) + (y*dest_stride())) % vga.svga_intf.vram_size] << 8) - | (vga.memory[(base + 2 + (x*3) + (y*dest_stride())) % vga.svga_intf.vram_size] << 16); - } - uint16_t read_pixel16(uint32_t base, uint16_t x, uint16_t y) - { - return (vga.memory[(base + (x*2) + (y*dest_stride()) % vga.svga_intf.vram_size)]) | (vga.memory[(base + 1 + (x*2) + (y*dest_stride())) % vga.svga_intf.vram_size] << 8); - } - uint8_t read_pixel8(uint32_t base, uint16_t x, uint16_t y) - { - return vga.memory[(base + x + (y*dest_stride())) % vga.svga_intf.vram_size]; - } + TIMER_CALLBACK_MEMBER(draw_step_tick); + + inline void write_pixel32(uint32_t base, uint16_t x, uint16_t y, uint32_t val); + inline void write_pixel24(uint32_t base, uint16_t x, uint16_t y, uint32_t val); + inline void write_pixel16(uint32_t base, uint16_t x, uint16_t y, uint16_t val); + inline void write_pixel8(uint32_t base, uint16_t x, uint16_t y, uint8_t val); + inline uint32_t read_pixel32(uint32_t base, uint16_t x, uint16_t y); + inline uint32_t read_pixel24(uint32_t base, uint16_t x, uint16_t y); + inline uint16_t read_pixel16(uint32_t base, uint16_t x, uint16_t y); + inline uint8_t read_pixel8(uint32_t base, uint16_t x, uint16_t y); + uint32_t GetROP(uint8_t rop, uint32_t src, uint32_t dst, uint32_t pat); bool advance_pixel(); diff --git a/src/devices/bus/isa/sb16.cpp b/src/devices/bus/isa/sb16.cpp index 25fbd3a51a5..333703f2cfc 100644 --- a/src/devices/bus/isa/sb16.cpp +++ b/src/devices/bus/isa/sb16.cpp @@ -717,7 +717,7 @@ void sb16_lle_device::device_start() m_isa->install_device(0x0228, 0x0229, read8sm_delegate(ymf262, FUNC(ymf262_device::read)), write8sm_delegate(ymf262, FUNC(ymf262_device::write))); m_isa->set_dma_channel(1, this, false); m_isa->set_dma_channel(5, this, false); - m_timer = timer_alloc(); + m_timer = timer_alloc(FUNC(sb16_lle_device::timer_tick), this); } @@ -742,7 +742,7 @@ void sb16_lle_device::device_reset() m_dma8_done = m_dma16_done = false; } -void sb16_lle_device::device_timer(emu_timer &timer, device_timer_id tid, int param) +TIMER_CALLBACK_MEMBER(sb16_lle_device::timer_tick) { uint16_t dacl = 0, dacr = 0, adcl = 0, adcr = 0; if(m_mode & 2) diff --git a/src/devices/bus/isa/sb16.h b/src/devices/bus/isa/sb16.h index 5e7325a2e1b..8710574ba85 100644 --- a/src/devices/bus/isa/sb16.h +++ b/src/devices/bus/isa/sb16.h @@ -27,8 +27,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; - // optional information overrides virtual const tiny_rom_entry *device_rom_region() const override; virtual void device_add_mconfig(machine_config &config) override; @@ -88,6 +86,8 @@ private: void control_timer(bool start); + TIMER_CALLBACK_MEMBER(timer_tick); + required_device<dac_word_interface> m_ldac; required_device<dac_word_interface> m_rdac; required_device<pc_joy_device> m_joy; diff --git a/src/devices/bus/isa/sblaster.cpp b/src/devices/bus/isa/sblaster.cpp index 53eadc6aa99..33905e05da3 100644 --- a/src/devices/bus/isa/sblaster.cpp +++ b/src/devices/bus/isa/sblaster.cpp @@ -1341,7 +1341,7 @@ void isa16_sblaster16_device::device_start() void sb_device::device_start() { - m_timer = timer_alloc(0); + m_timer = timer_alloc(FUNC(sb_device::timer_tick), this); save_item(NAME(m_dack_out)); save_item(NAME(m_onebyte_midi)); @@ -1559,11 +1559,8 @@ void sb_device::dack_w(int line, uint8_t data) } } -void sb_device::device_timer(emu_timer &timer, device_timer_id tid, int param) +TIMER_CALLBACK_MEMBER(sb_device::timer_tick) { - if (tid) - return; - // printf("DMA timer expire\n"); uint16_t lsample, rsample; switch (m_dsp.flags) { diff --git a/src/devices/bus/isa/sblaster.h b/src/devices/bus/isa/sblaster.h index 7d5d5775f91..f09f05957be 100644 --- a/src/devices/bus/isa/sblaster.h +++ b/src/devices/bus/isa/sblaster.h @@ -110,13 +110,13 @@ protected: // device-level overrides virtual void device_start() override; virtual void device_reset() override; + uint8_t dack_r(int line); void dack_w(int line, uint8_t data); - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; virtual void drq16_w(int state) { } virtual void drq_w(int state) { } virtual void irq_w(int state, int source) { } - virtual void mixer_reset() {} + virtual void mixer_reset() { } void adpcm_decode(uint8_t sample, int size); // serial overrides @@ -126,6 +126,8 @@ protected: static constexpr unsigned MIDI_RING_SIZE = 2048; + TIMER_CALLBACK_MEMBER(timer_tick); + required_device<dac_16bit_r2r_device> m_ldac; required_device<dac_16bit_r2r_device> m_rdac; required_device<pc_joy_device> m_joy; diff --git a/src/devices/bus/isa/sc499.cpp b/src/devices/bus/isa/sc499.cpp index 77e3497c7f8..e27b85d7fb8 100644 --- a/src/devices/bus/isa/sc499.cpp +++ b/src/devices/bus/isa/sc499.cpp @@ -17,15 +17,13 @@ #include "emu.h" #include "sc499.h" +#define LOG_LEVEL0 (0x1U << 1) +#define LOG_LEVEL1 (0x3U << 1) +#define LOG_LEVEL2 (0x7U << 1) +#define LOG_LEVEL3 (0xfU << 1) -#define VERBOSE 0 - -static int verbose = VERBOSE; - -#define LOG(x) { logerror ("%s: ", cpu_context()); logerror x; logerror ("\n"); } -#define LOG1(x) { if (verbose > 0) LOG(x)} -#define LOG2(x) { if (verbose > 1) LOG(x)} -#define LOG3(x) { if (verbose > 2) LOG(x)} +#define VERBOSE (LOG_LEVEL0) +#include "logmacro.h" #define SC499_CTAPE_TAG "sc499_ctape" DECLARE_DEVICE_TYPE(SC499_CTAPE, sc499_ctape_image_device) @@ -332,20 +330,20 @@ void sc499_device::device_start() { set_isa_device(); - LOG1(("start sc499")); + LOGMASKED(LOG_LEVEL1, "%s: start sc499", cpu_context()); - m_timer = timer_alloc(0); - m_timer1 = timer_alloc(1); + m_timer = timer_alloc(FUNC(sc499_device::timer_func), this); + m_timer1 = timer_alloc(FUNC(sc499_device::timer_func), this); m_installed = false; if (!m_image->is_open()) { - LOG2(("start sc499: no cartridge tape")); + LOGMASKED(LOG_LEVEL2, "%s: start sc499: no cartridge tape", cpu_context()); } else { - LOG2(("start sc499: cartridge tape image is %s", m_image->filename())); + LOGMASKED(LOG_LEVEL2, "%s: start sc499: cartridge tape image is %s", cpu_context(), m_image->filename()); } m_ctape_block_buffer.resize(SC499_CTAPE_BLOCK_SIZE); @@ -410,16 +408,6 @@ std::string sc499_device::cpu_context() const } /*------------------------------------------------- - logerror - log an error message (w/o device tags) - -------------------------------------------------*/ - -template <typename Format, typename... Params> -void sc499_device::logerror(Format &&fmt, Params &&... args) const -{ - machine().logerror(std::forward<Format>(fmt), std::forward<Params>(args)...); -} - -/*------------------------------------------------- tape_status_clear - clear bits in tape status -------------------------------------------------*/ @@ -472,7 +460,7 @@ void sc499_device::check_tape() m_ctape_block_count = (uint32_t)((m_image_length + SC499_CTAPE_BLOCK_SIZE - 1) / SC499_CTAPE_BLOCK_SIZE); } - LOG1(("check_tape: tape image is %s with %d blocks", m_image->filename(), m_ctape_block_count)); + LOGMASKED(LOG_LEVEL1, "%s: check_tape: tape image is %s with %d blocks", cpu_context(), m_image->filename(), m_ctape_block_count); } else { @@ -481,7 +469,7 @@ void sc499_device::check_tape() m_image_length = 0; m_ctape_block_count = 0; - LOG1(("check_tape: no cartridge tape")); + LOGMASKED(LOG_LEVEL1, "%s: check_tape: no cartridge tape", cpu_context()); } } @@ -489,9 +477,9 @@ void sc499_device::check_tape() timer_func - handle timer interrupts -------------------------------------------------*/ -void sc499_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(sc499_device::timer_func) { - LOG2(("timer_func param=%d status=%x", param, m_status)); + LOGMASKED(LOG_LEVEL2, "%s: timer_func param=%d status=%x", cpu_context(), param, m_status); switch (param) { @@ -556,20 +544,20 @@ void sc499_device::device_timer(emu_timer &timer, device_timer_id id, int param) tape_status_clear(SC499_ST_CLEAR_ALL); tape_status_set(SC499_ST_READ_ERROR); - LOG(("timer_func param=%d status=%x tape_pos=%d - read data underrun aborted at %d", - param, m_status, m_tape_pos, m_underrun_counter)); + LOGMASKED(LOG_LEVEL0, "%s: timer_func param=%d status=%x tape_pos=%d - read data underrun aborted at %d", + cpu_context(), param, m_status, m_tape_pos, m_underrun_counter); } else { - LOG2(("timer_func param=%d status=%x tape_pos=%d - read data underrun %d", - param, m_status, m_tape_pos, m_underrun_counter)); + LOGMASKED(LOG_LEVEL2, "%s: timer_func param=%d status=%x tape_pos=%d - read data underrun %d", + cpu_context(), param, m_status, m_tape_pos, m_underrun_counter); } break; } else if ( m_tape_pos > m_ctape_block_count || !(m_status & SC499_STAT_RDY)) { - LOG1(("timer_func param=%d status=%x tape_pos=%d - end-of-tape or not ready", - param, m_status, m_tape_pos)); + LOGMASKED(LOG_LEVEL1, "%s: timer_func param=%d status=%x tape_pos=%d - end-of-tape or not ready", + cpu_context(), param, m_status, m_tape_pos); m_timer1->adjust(attotime::never, param, attotime::never); m_status &= ~SC499_STAT_EXC; m_status &= ~SC499_STAT_DIR; @@ -584,8 +572,8 @@ void sc499_device::device_timer(emu_timer &timer, device_timer_id id, int param) { if (m_underrun_counter > 0) { - LOG1(("timer_func param=%d status=%x tape_pos=%d - read data underrun ended at %d", - param, m_status, m_tape_pos, m_underrun_counter)); + LOGMASKED(LOG_LEVEL1, "%s: timer_func param=%d status=%x tape_pos=%d - read data underrun ended at %d", + cpu_context(), param, m_status, m_tape_pos, m_underrun_counter); } read_block(); @@ -623,7 +611,7 @@ void sc499_device::device_timer(emu_timer &timer, device_timer_id id, int param) break; default: - LOG(("timer_func param=%d UNEXPECTED", param)); + LOGMASKED(LOG_LEVEL0, "%s: timer_func param=%d UNEXPECTED", cpu_context(), param); m_timer->reset(); break; } @@ -638,7 +626,7 @@ void sc499_device::set_interrupt(enum line_state state) { if (state != irq_state) { - LOG2(("set_interrupt(%d)",state)); + LOGMASKED(LOG_LEVEL2, "%s: set_interrupt(%d)", cpu_context(), state); switch (m_irq) { case 2: m_isa->irq2_w(state); break; @@ -661,7 +649,7 @@ void sc499_device::set_dma_drq(enum line_state state) { if (state != dma_drq_state) { - LOG2(("set_dma_drq(%d)",state)); + LOGMASKED(LOG_LEVEL2, "%s: set_dma_drq(%d)", cpu_context(), state); switch (m_drq) { @@ -686,36 +674,36 @@ void sc499_device::log_command(uint8_t data) case SC499_CMD_SEL_2: case SC499_CMD_SEL_3: case SC499_CMD_SEL_4: - LOG1(("write_command_port: %02x Select %x", data, data & 0x1f)); + LOGMASKED(LOG_LEVEL1, "%s: write_command_port: %02x Select %x", cpu_context(), data, data & 0x1f); break; case SC499_CMD_REWIND: // rewind tape - LOG1(("write_command_port: %02x Rewind Tape", data)); + LOGMASKED(LOG_LEVEL1, "%s: write_command_port: %02x Rewind Tape", cpu_context(), data); break; case SC499_CMD_ERASE: // erase tape - LOG1(("write_command_port: %02x Erase Tape", data)); + LOGMASKED(LOG_LEVEL1, "%s: write_command_port: %02x Erase Tape", cpu_context(), data); break; case SC499_CMD_RETEN: // retention tape - LOG1(("write_command_port: %02x Retention Tape", data)); + LOGMASKED(LOG_LEVEL1, "%s: write_command_port: %02x Retention Tape", cpu_context(), data); break; case SC499_CMD_WRITE_DATA: - LOG1(("write_command_port: %02x Write Data %d ...", data, m_tape_pos)); + LOGMASKED(LOG_LEVEL1, "%s: write_command_port: %02x Write Data %d ...", cpu_context(), data, m_tape_pos); break; case SC499_CMD_WRITE_FILEMARK: - LOG1(("write_command_port: %02x Write File Mark %d", data, m_tape_pos)); + LOGMASKED(LOG_LEVEL1, "%s: write_command_port: %02x Write File Mark %d", cpu_context(), data, m_tape_pos); break; case SC499_CMD_READ_DATA: - LOG1(("write_command_port: %02x Read Data %d ...", data, m_tape_pos)); + LOGMASKED(LOG_LEVEL1, "%s: write_command_port: %02x Read Data %d ...", cpu_context(), data, m_tape_pos); break; case SC499_CMD_READ_FILE_MARK: - LOG1(("write_command_port: %02x Read File Mark %d", data, m_tape_pos)); + LOGMASKED(LOG_LEVEL1, "%s: write_command_port: %02x Read File Mark %d", cpu_context(), data, m_tape_pos); break; case SC499_CMD_READ_STATUS: - LOG1(("write_command_port: %02x Read Status (%04x %04x %04x)", data, - m_tape_status, m_data_error_counter, m_underrun_counter)); + LOGMASKED(LOG_LEVEL1, "%s: write_command_port: %02x Read Status (%04x %04x %04x)", cpu_context(), data, + m_tape_status, m_data_error_counter, m_underrun_counter); break; case SC499_CMD_RESERVED: // Reserved default: - LOG(("write_command_port: %02x Unexpected Command!", data)); + LOGMASKED(LOG_LEVEL0, "%s: write_command_port: %02x Unexpected Command!", cpu_context(), data); break; } } @@ -784,7 +772,7 @@ void sc499_device::do_command(uint8_t data) { // SC499_CMD_READ_DATA pending m_status &= ~SC499_STAT_DIR; - LOG1(("do_command: Read data -> Read File Mark at %d", m_tape_pos)); + LOGMASKED(LOG_LEVEL1, "%s: do_command: Read data -> Read File Mark at %d", cpu_context(), m_tape_pos); } else { @@ -819,7 +807,7 @@ void sc499_device::do_command(uint8_t data) void sc499_device::do_reset() { - LOG1(("do_reset: Reset controller microprocessor")); + LOGMASKED(LOG_LEVEL1, "%s: do_reset: Reset controller microprocessor", cpu_context()); m_data = 0; m_command = SC499_CMD_NO_COMMAND; @@ -861,7 +849,7 @@ uint8_t sc499_device::read_data_port() // omit excessive logging if (m_last_data != m_data) { - LOG2(("read_data_port: %02x", m_data)); + LOGMASKED(LOG_LEVEL2, "%s: read_data_port: %02x", cpu_context(), m_data); m_last_data = m_data; } @@ -876,7 +864,7 @@ uint8_t sc499_device::read_data_port() void sc499_device::write_control_port( uint8_t data) { - LOG2(("write_control_port: %02x", data)); + LOGMASKED(LOG_LEVEL2, "%s: write_control_port: %02x", cpu_context(), data); if ((data ^ m_control) & SC499_CTR_RST) { @@ -897,7 +885,7 @@ void sc499_device::write_control_port( uint8_t data) // Request to LSI chip has changed if (data & SC499_CTR_REQ) { - LOG3(("write_control_port: Request to LSI chip = On")); + LOGMASKED(LOG_LEVEL3, "%s: write_control_port: Request to LSI chip = On", cpu_context()); if (m_command == SC499_CMD_READ_STATUS) { m_status |= SC499_STAT_EXC; @@ -922,7 +910,7 @@ void sc499_device::write_control_port( uint8_t data) } else { - LOG2(("write_control_port: Request to LSI chip = Off (%d)", m_data_index)); + LOGMASKED(LOG_LEVEL2, "%s: write_control_port: Request to LSI chip = Off (%d)", cpu_context(), m_data_index); if (!(m_status & SC499_STAT_DIR)) { @@ -948,7 +936,7 @@ uint8_t sc499_device::read_status_port() // omit excessive logging if (m_last_status != m_status) { - LOG2(("read_status_port: %02x", m_status)); + LOGMASKED(LOG_LEVEL2, "%s: read_status_port: %02x", cpu_context(), m_status); m_last_status = m_status; } @@ -963,7 +951,7 @@ uint8_t sc499_device::read_status_port() void sc499_device::write_dma_go( uint8_t data) { - LOG2(("write_dma_go: %02x", data)); + LOGMASKED(LOG_LEVEL2, "%s: write_dma_go: %02x", cpu_context(), data); m_status &= ~SC499_STAT_DON; @@ -1008,7 +996,7 @@ void sc499_device::write_dma_go( uint8_t data) void sc499_device::write_dma_reset( uint8_t data) { - LOG2(("write_dma_reset: %02x", data)); + LOGMASKED(LOG_LEVEL2, "%s: write_dma_reset: %02x", cpu_context(), data); m_status &= ~SC499_STAT_DON; m_control = 0; @@ -1031,7 +1019,7 @@ void sc499_device::write(offs_t offset, uint8_t data) write_dma_reset(data); break; default: - LOG(("writing sc499 Register at offset %02x = %02x", offset, data)); + LOGMASKED(LOG_LEVEL0, "%s: writing sc499 Register at offset %02x = %02x", cpu_context(), offset, data); break; } } @@ -1050,7 +1038,7 @@ uint8_t sc499_device::read(offs_t offset) // set_interrupt(CLEAR_LINE); break; default: - LOG(("reading sc499 Register at offset %02x = %02x", offset, data)); + LOGMASKED(LOG_LEVEL0, "%s: reading sc499 Register at offset %02x = %02x", cpu_context(), offset, data); break; } @@ -1059,7 +1047,7 @@ uint8_t sc499_device::read(offs_t offset) void sc499_device::eop_w(int state) { - LOG2(("set_tc_state: block=%d state=%x", m_tape_pos-1, state)); + LOGMASKED(LOG_LEVEL2, "%s: set_tc_state: block=%d state=%x", cpu_context(), m_tape_pos - 1, state); if (state == 0) { m_status |= SC499_STAT_DON; // 37ec @@ -1091,7 +1079,7 @@ uint8_t sc499_device::dack_r(int line) if (m_ctape_block_index >= SC499_CTAPE_BLOCK_SIZE) { - LOG3(("dack_read: read_block")); + LOGMASKED(LOG_LEVEL3, "%s: dack_read: read_block", cpu_context()); read_block(); m_nasty_readahead++; @@ -1106,7 +1094,7 @@ uint8_t sc499_device::dack_r(int line) data = m_ctape_block_buffer[m_ctape_block_index++]; if (m_ctape_block_index < 2 || m_ctape_block_index > 511) { - LOG2(("dack_read: data[%d]=%x status=%x", m_ctape_block_index-1, data, m_status)); + LOGMASKED(LOG_LEVEL2, "%s: dack_read: data[%d]=%x status=%x", cpu_context(), m_ctape_block_index - 1, data, m_status); } // if (m_ctape_block_index < SC499_CTAPE_BLOCK_SIZE) @@ -1119,7 +1107,7 @@ uint8_t sc499_device::dack_r(int line) void sc499_device::dack_w(int line, uint8_t data) { - LOG3(("dack_write: data=%x", data)); + LOGMASKED(LOG_LEVEL3, "%s: dack_write: data=%x", cpu_context(), data); if (m_ctape_block_index < SC499_CTAPE_BLOCK_SIZE) { @@ -1128,7 +1116,7 @@ void sc499_device::dack_w(int line, uint8_t data) if (m_ctape_block_index == SC499_CTAPE_BLOCK_SIZE) { - LOG3(("dack_write: write_block")); + LOGMASKED(LOG_LEVEL3, "%s: dack_write: write_block", cpu_context()); write_block(); } } @@ -1141,7 +1129,7 @@ void sc499_device::log_block(const char *text) { int data_length = 16; - if (verbose > 0) { + if (VERBOSE & (LOG_LEVEL1 | LOG_LEVEL2 | LOG_LEVEL3)) { int i; logerror("%s: %s %d -", cpu_context(), text, m_tape_pos); for (i = 0; i < data_length && i < SC499_CTAPE_BLOCK_SIZE; i++) { @@ -1190,7 +1178,7 @@ void sc499_device::read_block() { memcpy(&m_ctape_block_buffer[0], tape, SC499_CTAPE_BLOCK_SIZE); - // if (verbose > 1 || m_tape_pos % 100 == 0) + // if (m_tape_pos % 100 == 0) { log_block("read_block"); } @@ -1203,7 +1191,7 @@ void sc499_device::read_block() // FIXME: we must read first block twice (in MD for 'di c' and 'ld' or 'ex ...') // why is this necessary??? m_tape_pos = 0; - LOG(("read_block - duplicating block %d", m_tape_pos)); + LOGMASKED(LOG_LEVEL0, "%s: read_block - duplicating block %d", cpu_context(), m_tape_pos); } m_first_block_hack = 0; @@ -1261,9 +1249,9 @@ int sc499_device::block_is_filemark() static const uint8_t fm_pattern[] = {0xDE, 0xAF, 0xFA, 0xED}; int is_filemark = memcmp(&m_ctape_block_buffer[0], fm_pattern, 4) == 0 && - memcmp(&m_ctape_block_buffer[0], &m_ctape_block_buffer[4], SC499_CTAPE_BLOCK_SIZE-4) == 0; + memcmp(&m_ctape_block_buffer[0], &m_ctape_block_buffer[4], SC499_CTAPE_BLOCK_SIZE - 4) == 0; - LOG3(("block_is_filemark for block %d = %d", m_tape_pos-1, is_filemark)); + LOGMASKED(LOG_LEVEL3, "%s: block_is_filemark for block %d = %d", cpu_context(), m_tape_pos - 1, is_filemark); return is_filemark; } diff --git a/src/devices/bus/isa/sc499.h b/src/devices/bus/isa/sc499.h index 5d51d8cb7dd..ffcd8c37a85 100644 --- a/src/devices/bus/isa/sc499.h +++ b/src/devices/bus/isa/sc499.h @@ -66,7 +66,6 @@ private: // device-level overrides virtual void device_start() override; virtual void device_reset() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; virtual void device_add_mconfig(machine_config &config) override; virtual ioport_constructor device_input_ports() const override; @@ -76,7 +75,6 @@ private: virtual void eop_w(int state) override; std::string cpu_context() const; - template <typename Format, typename... Params> void logerror(Format &&fmt, Params &&... args) const; void tape_status_clear(uint16_t value); void tape_status_set(uint16_t value); @@ -108,6 +106,8 @@ private: int block_is_filemark(); void block_set_filemark(); + TIMER_CALLBACK_MEMBER(timer_func); + uint8_t m_data; uint8_t m_command; uint8_t m_status; diff --git a/src/devices/bus/isa/stereo_fx.cpp b/src/devices/bus/isa/stereo_fx.cpp index 1380055572d..70f3c5160c7 100644 --- a/src/devices/bus/isa/stereo_fx.cpp +++ b/src/devices/bus/isa/stereo_fx.cpp @@ -215,7 +215,7 @@ void stereo_fx_device::device_start() m_isa->install_device(0x022e, 0x022f, read8smo_delegate(*this, FUNC(stereo_fx_device::dsp_rbuf_status_r)), write8smo_delegate(*this, FUNC(stereo_fx_device::invalid_w))); m_isa->install_device(0x0388, 0x0389, read8sm_delegate(ym3812, FUNC(ym3812_device::read)), write8sm_delegate(ym3812, FUNC(ym3812_device::write))); m_isa->install_device(0x0228, 0x0229, read8sm_delegate(ym3812, FUNC(ym3812_device::read)), write8sm_delegate(ym3812, FUNC(ym3812_device::write))); - m_timer = timer_alloc(); + m_timer = timer_alloc(FUNC(stereo_fx_device::clock_tick), this); m_timer->adjust(attotime::from_hz(2000000), 0, attotime::from_hz(2000000)); m_isa->set_dma_channel(1, this, false); } @@ -232,7 +232,7 @@ void stereo_fx_device::device_reset() m_t0 = CLEAR_LINE; } -void stereo_fx_device::device_timer(emu_timer &timer, device_timer_id tid, int param) +TIMER_CALLBACK_MEMBER(stereo_fx_device::clock_tick) { m_t0 = !m_t0; m_cpu->set_input_line(MCS51_T0_LINE, m_t0); diff --git a/src/devices/bus/isa/stereo_fx.h b/src/devices/bus/isa/stereo_fx.h index bd98ea82c85..376d5dbff98 100644 --- a/src/devices/bus/isa/stereo_fx.h +++ b/src/devices/bus/isa/stereo_fx.h @@ -28,8 +28,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; - // optional information overrides virtual const tiny_rom_entry *device_rom_region() const override; virtual void device_add_mconfig(machine_config &config) override; @@ -53,6 +51,8 @@ private: uint8_t m_t0; uint8_t m_t1; + TIMER_CALLBACK_MEMBER(clock_tick); + // mcu ports uint8_t dev_dsp_data_r(); void dev_dsp_data_w(uint8_t data); diff --git a/src/devices/bus/isa/trident.cpp b/src/devices/bus/isa/trident.cpp index 693aaf5e991..943f0de3432 100644 --- a/src/devices/bus/isa/trident.cpp +++ b/src/devices/bus/isa/trident.cpp @@ -179,7 +179,7 @@ void trident_vga_device::device_start() save_pointer(tri.accel_pattern,"Pattern Data", 0x80); save_pointer(tri.lutdac_reg,"LUTDAC registers", 0x100); - m_vblank_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(vga_device::vblank_timer_cb),this)); + m_vblank_timer = timer_alloc(FUNC(vga_device::vblank_timer_cb), this); vga.svga_intf.seq_regcount = 0x0f; vga.svga_intf.crtc_regcount = 0x60; memset(&tri, 0, sizeof(tri)); diff --git a/src/devices/bus/kc/d004.cpp b/src/devices/bus/kc/d004.cpp index a2018c5867a..45905b23b1d 100644 --- a/src/devices/bus/kc/d004.cpp +++ b/src/devices/bus/kc/d004.cpp @@ -131,7 +131,7 @@ void kc_d004_device::device_start() { m_rom = memregion(Z80_TAG)->base(); - m_reset_timer = timer_alloc(TIMER_RESET); + m_reset_timer = timer_alloc(FUNC(kc_d004_device::reset_tick), this); } //------------------------------------------------- @@ -185,17 +185,12 @@ const tiny_rom_entry *kc_d004_device::device_rom_region() const } //------------------------------------------------- -// device_timer - handler timer events +// reset_tick - reset the main CPU when needed //------------------------------------------------- -void kc_d004_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(kc_d004_device::reset_tick) { - switch(id) - { - case TIMER_RESET: - m_cpu->set_input_line(INPUT_LINE_RESET, ASSERT_LINE); - break; - } + m_cpu->set_input_line(INPUT_LINE_RESET, ASSERT_LINE); } /*------------------------------------------------- diff --git a/src/devices/bus/kc/d004.h b/src/devices/bus/kc/d004.h index 3e47cfaf4d9..570f378b4fa 100644 --- a/src/devices/bus/kc/d004.h +++ b/src/devices/bus/kc/d004.h @@ -34,7 +34,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; // optional information overrides virtual void device_add_mconfig(machine_config &config) override; @@ -47,6 +46,8 @@ protected: virtual void io_read(offs_t offset, uint8_t &data) override; virtual void io_write(offs_t offset, uint8_t data) override; + TIMER_CALLBACK_MEMBER(reset_tick); + uint8_t hw_input_gate_r(); void fdd_select_w(uint8_t data); void hw_terminal_count_w(uint8_t data); @@ -61,8 +62,6 @@ private: void kc_d004_io(address_map &map); void kc_d004_mem(address_map &map); - static const device_timer_id TIMER_RESET = 0; - required_device<upd765a_device> m_fdc; required_device<floppy_connector> m_floppy0; required_device<floppy_connector> m_floppy1; diff --git a/src/devices/bus/mackbd/keyboard.cpp b/src/devices/bus/mackbd/keyboard.cpp index 7818797904b..bda86980a05 100644 --- a/src/devices/bus/mackbd/keyboard.cpp +++ b/src/devices/bus/mackbd/keyboard.cpp @@ -278,8 +278,8 @@ protected: virtual void device_start() override { - m_watchdog_timeout = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(peripheral_base::watchdog_timeout), this)); - m_watchdog_output = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(peripheral_base::watchdog_output), this)); + m_watchdog_timeout = timer_alloc(FUNC(peripheral_base::watchdog_timeout), this); + m_watchdog_output = timer_alloc(FUNC(peripheral_base::watchdog_output), this); m_row_drive = make_bitmask<u16>(Rows); m_host_clock_out = 1U; diff --git a/src/devices/bus/macpds/pds_tpdfpd.cpp b/src/devices/bus/macpds/pds_tpdfpd.cpp index 84c2383ac49..c6eeb68c466 100644 --- a/src/devices/bus/macpds/pds_tpdfpd.cpp +++ b/src/devices/bus/macpds/pds_tpdfpd.cpp @@ -114,7 +114,7 @@ void macpds_sedisplay_device::device_start() m_macpds->install_device(0x770000, 0x77000f, read16s_delegate(*this, FUNC(macpds_sedisplay_device::ramdac_r)), write16s_delegate(*this, FUNC(macpds_sedisplay_device::ramdac_w))); m_macpds->install_device(0xc10000, 0xc2ffff, read16sm_delegate(*this, FUNC(macpds_sedisplay_device::sedisplay_r)), write16sm_delegate(*this, FUNC(macpds_sedisplay_device::sedisplay_w))); - m_timer = timer_alloc(0); + m_timer = timer_alloc(FUNC(macpds_sedisplay_device::vbl_tick), this); m_timer->adjust(screen().time_until_pos(879, 0), 0); } @@ -135,7 +135,7 @@ void macpds_sedisplay_device::device_reset() } -void macpds_sedisplay_device::device_timer(emu_timer &timer, device_timer_id tid, int param) +TIMER_CALLBACK_MEMBER(macpds_sedisplay_device::vbl_tick) { if (!m_vbl_disable) { diff --git a/src/devices/bus/macpds/pds_tpdfpd.h b/src/devices/bus/macpds/pds_tpdfpd.h index a46bfefcf7b..3b9fd803c7e 100644 --- a/src/devices/bus/macpds/pds_tpdfpd.h +++ b/src/devices/bus/macpds/pds_tpdfpd.h @@ -28,7 +28,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; // optional information overrides virtual void device_add_mconfig(machine_config &config) override; @@ -42,6 +41,8 @@ private: uint32_t screen_update(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect); + TIMER_CALLBACK_MEMBER(vbl_tick); + std::unique_ptr<uint8_t[]> m_vram; uint32_t m_vbl_disable; uint32_t m_palette[256], m_colors[3], m_count, m_clutoffs; diff --git a/src/devices/bus/multibus/isbc202.cpp b/src/devices/bus/multibus/isbc202.cpp index 3b4ff08808c..f537cfcbe4a 100644 --- a/src/devices/bus/multibus/isbc202.cpp +++ b/src/devices/bus/multibus/isbc202.cpp @@ -100,13 +100,6 @@ constexpr unsigned HALF_BIT_CELL_US = 1;// Half bit cell duration in µs constexpr unsigned BIT_FREQUENCY = 500000; // Frequency of bit cells in Hz constexpr uint16_t CRC_POLY = 0x1021; // CRC-CCITT -// Timers -enum { - TIMEOUT_TMR_ID, - BYTE_TMR_ID, - F_TMR_ID -}; - // device type definition DEFINE_DEVICE_TYPE(ISBC202, isbc202_device, "isbc202", "iSBC-202 floppy controller") @@ -404,9 +397,9 @@ void isbc202_device::device_start() d->get_device()->setup_index_pulse_cb(floppy_image_device::index_pulse_cb(&isbc202_device::floppy_index_cb , this)); } - m_timeout_timer = timer_alloc(TIMEOUT_TMR_ID); - m_byte_timer = timer_alloc(BYTE_TMR_ID); - m_f_timer = timer_alloc(F_TMR_ID); + m_timeout_timer = timer_alloc(FUNC(isbc202_device::timeout_tick), this); + m_byte_timer = timer_alloc(FUNC(isbc202_device::byte_tick), this); + m_f_timer = timer_alloc(FUNC(isbc202_device::f_tick), this); m_mem_space = &m_bus->space(AS_PROGRAM); m_bus->space(AS_IO).install_readwrite_handler(0x78, 0x7f, read8m_delegate(*this, FUNC(isbc202_device::io_r)), write8m_delegate(*this, FUNC(isbc202_device::io_w))); @@ -438,37 +431,32 @@ void isbc202_device::device_reset() m_f_timer->reset(); } -void isbc202_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(isbc202_device::timeout_tick) { - switch (id) { - case TIMEOUT_TMR_ID: - m_inputs[ IN_SEL_TIMEOUT ] = true; - break; - - case BYTE_TMR_ID: - m_inputs[ IN_SEL_F ] = true; - m_f_timer->adjust(attotime::from_usec(HALF_BIT_CELL_US * 2)); - m_dlyd_amwrt = m_amwrt; - if (m_reading) { - m_last_f_time = machine().time(); - rd_bits(8); - m_byte_timer->adjust(m_pll.ctime - machine().time()); - // Updating of AZ flag actually happens when F goes low - m_inputs[ IN_SEL_AZ ] = m_crc == 0; - } - break; + m_inputs[ IN_SEL_TIMEOUT ] = true; +} - case F_TMR_ID: - m_inputs[ IN_SEL_F ] = false; - if (m_writing) { - write_byte(); - m_data_sr = dbus_r(); - m_byte_timer->adjust(attotime::from_usec(HALF_BIT_CELL_US * 14)); - } - break; +TIMER_CALLBACK_MEMBER(isbc202_device::byte_tick) +{ + m_inputs[ IN_SEL_F ] = true; + m_f_timer->adjust(attotime::from_usec(HALF_BIT_CELL_US * 2)); + m_dlyd_amwrt = m_amwrt; + if (m_reading) { + m_last_f_time = machine().time(); + rd_bits(8); + m_byte_timer->adjust(m_pll.ctime - machine().time()); + // Updating of AZ flag actually happens when F goes low + m_inputs[ IN_SEL_AZ ] = m_crc == 0; + } +} - default: - break; +TIMER_CALLBACK_MEMBER(isbc202_device::f_tick) +{ + m_inputs[ IN_SEL_F ] = false; + if (m_writing) { + write_byte(); + m_data_sr = dbus_r(); + m_byte_timer->adjust(attotime::from_usec(HALF_BIT_CELL_US * 14)); } } diff --git a/src/devices/bus/multibus/isbc202.h b/src/devices/bus/multibus/isbc202.h index c1f3b1d036d..686065a9c53 100644 --- a/src/devices/bus/multibus/isbc202.h +++ b/src/devices/bus/multibus/isbc202.h @@ -39,16 +39,19 @@ protected: // device_t overrides virtual void device_start() override; virtual void device_reset() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; virtual const tiny_rom_entry *device_rom_region() const override; virtual void device_add_mconfig(machine_config &config) override; + // device_execute_interface overrides virtual uint32_t execute_min_cycles() const noexcept override { return 1; } virtual void execute_run() override; + // device_memory_interface overrides virtual space_config_vector memory_space_config() const override; + // device_disasm_interface overrides virtual std::unique_ptr<util::disasm_interface> create_disassembler() override; + // device_state_interface overrides virtual void state_import(const device_state_entry &entry) override; virtual void state_export(const device_state_entry &entry) override; @@ -133,6 +136,10 @@ private: emu_timer *m_byte_timer; emu_timer *m_f_timer; + TIMER_CALLBACK_MEMBER(timeout_tick); + TIMER_CALLBACK_MEMBER(byte_tick); + TIMER_CALLBACK_MEMBER(f_tick); + void set_output(); unsigned selected_drive() const; unsigned drive_idx(floppy_image_device *drive); diff --git a/src/devices/bus/nasbus/floppy.cpp b/src/devices/bus/nasbus/floppy.cpp index 3ada48aa19a..905f5eef087 100644 --- a/src/devices/bus/nasbus/floppy.cpp +++ b/src/devices/bus/nasbus/floppy.cpp @@ -80,7 +80,7 @@ nascom_fdc_device::nascom_fdc_device(const machine_config &mconfig, const char * void nascom_fdc_device::device_start() { // timer to turn off the drive motor line - m_motor = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(nascom_fdc_device::motor_off), this)); + m_motor = timer_alloc(FUNC(nascom_fdc_device::motor_off), this); save_item(NAME(m_select)); } diff --git a/src/devices/bus/nes/bandai.cpp b/src/devices/bus/nes/bandai.cpp index 1f3eb653876..9bb61da4262 100644 --- a/src/devices/bus/nes/bandai.cpp +++ b/src/devices/bus/nes/bandai.cpp @@ -122,7 +122,7 @@ void nes_oekakids_device::pcb_reset() void nes_fcg_device::device_start() { common_start(); - irq_timer = timer_alloc(TIMER_IRQ); + irq_timer = timer_alloc(FUNC(nes_fcg_device::irq_timer_tick), this); irq_timer->adjust(attotime::zero, 0, clocks_to_attotime(1)); save_item(NAME(m_irq_enable)); @@ -142,7 +142,7 @@ void nes_fcg_device::pcb_reset() void nes_lz93d50_24c01_device::device_start() { common_start(); - irq_timer = timer_alloc(TIMER_IRQ); + irq_timer = timer_alloc(FUNC(nes_lz93d50_24c01_device::irq_timer_tick), this); irq_timer->adjust(attotime::zero, 0, clocks_to_attotime(1)); save_item(NAME(m_irq_enable)); @@ -164,7 +164,7 @@ void nes_lz93d50_24c01_device::pcb_reset() void nes_fjump2_device::device_start() { common_start(); - irq_timer = timer_alloc(TIMER_IRQ); + irq_timer = timer_alloc(FUNC(nes_fjump2_device::irq_timer_tick), this); irq_timer->adjust(attotime::zero, 0, clocks_to_attotime(1)); save_item(NAME(m_reg)); @@ -278,25 +278,22 @@ void nes_oekakids_device::write_h(offs_t offset, uint8_t data) -------------------------------------------------*/ -void nes_fcg_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(nes_fcg_device::irq_timer_tick) { - if (id == TIMER_IRQ) + if (m_irq_enable) { - if (m_irq_enable) + // 16bit counter, IRQ fired when the counter goes from 1 to 0 + // after firing, the counter is *not* reloaded, but next clock + // counter wraps around from 0 to 0xffff + if (!m_irq_count) + m_irq_count = 0xffff; + else + m_irq_count--; + + if (!m_irq_count) { - // 16bit counter, IRQ fired when the counter goes from 1 to 0 - // after firing, the counter is *not* reloaded, but next clock - // counter wraps around from 0 to 0xffff - if (!m_irq_count) - m_irq_count = 0xffff; - else - m_irq_count--; - - if (!m_irq_count) - { - set_irq_line(ASSERT_LINE); - m_irq_enable = 0; - } + set_irq_line(ASSERT_LINE); + m_irq_enable = 0; } } } diff --git a/src/devices/bus/nes/bandai.h b/src/devices/bus/nes/bandai.h index 9427a7fca8e..1a21f8a3052 100644 --- a/src/devices/bus/nes/bandai.h +++ b/src/devices/bus/nes/bandai.h @@ -45,20 +45,19 @@ public: // construction/destruction nes_fcg_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock); - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; void fcg_write(offs_t offset, uint8_t data); virtual void write_m(offs_t offset, uint8_t data) override; virtual void pcb_reset() override; protected: - static constexpr device_timer_id TIMER_IRQ = 0; - nes_fcg_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock); // device-level overrides virtual void device_start() override; + TIMER_CALLBACK_MEMBER(irq_timer_tick); + uint16_t m_irq_count; int m_irq_enable; diff --git a/src/devices/bus/nes/batlab.cpp b/src/devices/bus/nes/batlab.cpp index 868174ed232..e117e6fbf5e 100644 --- a/src/devices/bus/nes/batlab.cpp +++ b/src/devices/bus/nes/batlab.cpp @@ -162,7 +162,7 @@ void nes_batmap_000_device::write_h(offs_t offset, u8 data) -------------------------------------------------*/ // IRQ based on our MMC3 implementation, details for SRR are unclear -void nes_batmap_srrx_device::hblank_irq(int scanline, int vblank, int blanked) +void nes_batmap_srrx_device::hblank_irq(int scanline, bool vblank, bool blanked) { if (scanline < ppu2c0x_device::BOTTOM_VISIBLE_SCANLINE) { diff --git a/src/devices/bus/nes/batlab.h b/src/devices/bus/nes/batlab.h index 0d2e3dca507..9861afe8a87 100644 --- a/src/devices/bus/nes/batlab.h +++ b/src/devices/bus/nes/batlab.h @@ -35,7 +35,7 @@ public: virtual u8 read_h(offs_t offset) override; virtual void write_h(offs_t offset, u8 data) override; - virtual void hblank_irq(int scanline, int vblank, int blanked) override; + virtual void hblank_irq(int scanline, bool vblank, bool blanked) override; virtual void pcb_reset() override; protected: diff --git a/src/devices/bus/nes/bootleg.cpp b/src/devices/bus/nes/bootleg.cpp index ba9cfc43f5d..c0ac3e1a35c 100644 --- a/src/devices/bus/nes/bootleg.cpp +++ b/src/devices/bus/nes/bootleg.cpp @@ -259,7 +259,7 @@ void nes_sc127_device::pcb_reset() void nes_mbaby_device::device_start() { common_start(); - irq_timer = timer_alloc(TIMER_IRQ); + irq_timer = timer_alloc(FUNC(nes_mbaby_device::irq_timer_tick), this); irq_timer->adjust(attotime::zero, 0, clocks_to_attotime(1)); save_item(NAME(m_irq_enable)); @@ -293,7 +293,7 @@ void nes_asn_device::pcb_reset() void nes_smb3p_device::device_start() { common_start(); - irq_timer = timer_alloc(TIMER_IRQ); + irq_timer = timer_alloc(FUNC(nes_smb3p_device::irq_timer_tick), this); irq_timer->adjust(attotime::zero, 0, clocks_to_attotime(1)); save_item(NAME(m_irq_enable)); @@ -316,7 +316,7 @@ void nes_smb3p_device::pcb_reset() void nes_batmanfs_device::device_start() { common_start(); - irq_timer = timer_alloc(TIMER_IRQ); + irq_timer = timer_alloc(FUNC(nes_batmanfs_device::irq_timer_tick), this); irq_timer->adjust(attotime::zero, 0, clocks_to_attotime(1)); save_item(NAME(m_irq_enable)); @@ -356,7 +356,7 @@ void nes_btl_dn_device::pcb_reset() void nes_smb2j_device::device_start() { common_start(); - irq_timer = timer_alloc(TIMER_IRQ); + irq_timer = timer_alloc(FUNC(nes_smb2j_device::irq_timer_tick), this); irq_timer->adjust(attotime::zero, 0, clocks_to_attotime(1)); save_item(NAME(m_irq_enable)); @@ -378,7 +378,7 @@ void nes_smb2j_device::pcb_reset() void nes_smb2ja_device::device_start() { common_start(); - irq_timer = timer_alloc(TIMER_IRQ); + irq_timer = timer_alloc(FUNC(nes_smb2ja_device::irq_timer_tick), this); irq_timer->adjust(attotime::zero, 0, clocks_to_attotime(1)); save_item(NAME(m_irq_enable)); @@ -400,7 +400,7 @@ void nes_smb2ja_device::pcb_reset() void nes_smb2jb_device::device_start() { common_start(); - irq_timer = timer_alloc(TIMER_IRQ); + irq_timer = timer_alloc(FUNC(nes_smb2jb_device::irq_timer_tick), this); irq_timer->adjust(attotime::zero, 0, clocks_to_attotime(1)); save_item(NAME(m_irq_enable)); @@ -445,7 +445,7 @@ void nes_0353_device::pcb_reset() void nes_09034a_device::device_start() { common_start(); - irq_timer = timer_alloc(TIMER_IRQ); + irq_timer = timer_alloc(FUNC(nes_09034a_device::irq_timer_tick), this); irq_timer->adjust(attotime::zero, 0, clocks_to_attotime(1)); save_item(NAME(m_irq_enable)); @@ -466,7 +466,7 @@ void nes_09034a_device::pcb_reset() void nes_l001_device::device_start() { common_start(); - irq_timer = timer_alloc(TIMER_IRQ); + irq_timer = timer_alloc(FUNC(nes_l001_device::irq_timer_tick), this); irq_timer->adjust(attotime::zero, 0, clocks_to_attotime(1)); save_item(NAME(m_irq_count)); @@ -587,7 +587,7 @@ void nes_lh51_device::pcb_reset() void nes_lh53_device::device_start() { common_start(); - irq_timer = timer_alloc(TIMER_IRQ); + irq_timer = timer_alloc(FUNC(nes_lh53_device::irq_timer_tick), this); irq_timer->adjust(attotime::zero, 0, clocks_to_attotime(1)); save_item(NAME(m_irq_enable)); @@ -645,7 +645,7 @@ void nes_rt01_device::pcb_reset() void nes_yung08_device::device_start() { common_start(); - irq_timer = timer_alloc(TIMER_IRQ); + irq_timer = timer_alloc(FUNC(nes_yung08_device::irq_timer_tick), this); irq_timer->adjust(attotime::zero, 0, clocks_to_attotime(1)); save_item(NAME(m_irq_count)); @@ -681,7 +681,7 @@ void nes_yung08_device::pcb_reset() -------------------------------------------------*/ -void nes_sc127_device::hblank_irq(int scanline, int vblank, int blanked) +void nes_sc127_device::hblank_irq(int scanline, bool vblank, bool blanked) { if (scanline < ppu2c0x_device::BOTTOM_VISIBLE_SCANLINE && m_irq_enable) { @@ -751,17 +751,14 @@ void nes_sc127_device::write_h(offs_t offset, uint8_t data) -------------------------------------------------*/ -void nes_mbaby_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(nes_mbaby_device::irq_timer_tick) { - if (id == TIMER_IRQ) + if (m_irq_enable) { - if (m_irq_enable) - { - m_irq_count = (m_irq_count + 1) & 0x7fff; // unverified 15-bit counter based on FCEUX + m_irq_count = (m_irq_count + 1) & 0x7fff; // unverified 15-bit counter based on FCEUX - if (m_irq_count >= 0x6000) - set_irq_line(ASSERT_LINE); - } + if (m_irq_count >= 0x6000) + set_irq_line(ASSERT_LINE); } } @@ -838,16 +835,13 @@ uint8_t nes_asn_device::read_m(offs_t offset) -------------------------------------------------*/ -void nes_smb3p_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(nes_smb3p_device::irq_timer_tick) { - if (id == TIMER_IRQ) - { - // counter does not stop when interrupts are disabled - if (m_irq_count != 0xffff) - m_irq_count++; - else if (m_irq_enable) - set_irq_line(ASSERT_LINE); - } + // counter does not stop when interrupts are disabled + if (m_irq_count != 0xffff) + m_irq_count++; + else if (m_irq_enable) + set_irq_line(ASSERT_LINE); } void nes_smb3p_device::write_h(offs_t offset, u8 data) @@ -943,7 +937,7 @@ void nes_btl_cj_device::write_h(offs_t offset, u8 data) -------------------------------------------------*/ /* Scanline based IRQ ? */ -void nes_btl_dn_device::hblank_irq(int scanline, int vblank, int blanked ) +void nes_btl_dn_device::hblank_irq(int scanline, bool vblank, bool blanked) { if (!m_irq_count || ++m_irq_count < 240) return; @@ -1056,16 +1050,13 @@ void nes_lh31_device::write_h(offs_t offset, u8 data) // submapper 2 -------------------------------------------------*/ -void nes_smb2j_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(nes_smb2j_device::irq_timer_tick) { - if (id == TIMER_IRQ) + if (m_irq_enable) { - if (m_irq_enable) - { - m_irq_count = (m_irq_count + 1) & 0xfff; - if (!m_irq_count) - set_irq_line(ASSERT_LINE); - } + m_irq_count = (m_irq_count + 1) & 0xfff; + if (!m_irq_count) + set_irq_line(ASSERT_LINE); } } @@ -1143,18 +1134,15 @@ u8 nes_smb2j_device::read_m(offs_t offset) -------------------------------------------------*/ -void nes_smb2ja_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(nes_smb2ja_device::irq_timer_tick) { - if (id == TIMER_IRQ) + if (m_irq_enable) { - if (m_irq_enable) - { - m_irq_count = (m_irq_count + 1) & 0x1fff; // 13-bit counter - if (BIT(m_irq_count, 12)) - set_irq_line(ASSERT_LINE); - else if (!m_irq_count) - set_irq_line(CLEAR_LINE); // CD4020 acknowledges on overflow - } + m_irq_count = (m_irq_count + 1) & 0x1fff; // 13-bit counter + if (BIT(m_irq_count, 12)) + set_irq_line(ASSERT_LINE); + else if (!m_irq_count) + set_irq_line(CLEAR_LINE); // CD4020 acknowledges on overflow } } @@ -1198,15 +1186,12 @@ u8 nes_smb2ja_device::read_m(offs_t offset) -------------------------------------------------*/ -void nes_smb2jb_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(nes_smb2jb_device::irq_timer_tick) { - if (id == TIMER_IRQ) + if (m_irq_enable) { - if (m_irq_enable) - { - if (BIT(++m_irq_count, 12)) - set_irq_line(ASSERT_LINE); - } + if (BIT(++m_irq_count, 12)) + set_irq_line(ASSERT_LINE); } } @@ -1347,16 +1332,13 @@ void nes_0353_device::write_h(offs_t offset, u8 data) -------------------------------------------------*/ -void nes_09034a_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(nes_09034a_device::irq_timer_tick) { - if (id == TIMER_IRQ) + if (m_irq_enable) { - if (m_irq_enable) - { - m_irq_count = (m_irq_count + 1) & 0x0fff; - if (!m_irq_count) - set_irq_line(ASSERT_LINE); - } + m_irq_count = (m_irq_count + 1) & 0x0fff; + if (!m_irq_count) + set_irq_line(ASSERT_LINE); } } @@ -1419,15 +1401,12 @@ u8 nes_09034a_device::read_m(offs_t offset) -------------------------------------------------*/ -void nes_l001_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(nes_l001_device::irq_timer_tick) { - if (id == TIMER_IRQ) + if (BIT(m_irq_count, 15)) { - if (BIT(m_irq_count, 15)) - { - if (++m_irq_count == 0) - set_irq_line(ASSERT_LINE); - } + if (++m_irq_count == 0) + set_irq_line(ASSERT_LINE); } } @@ -1470,15 +1449,12 @@ void nes_l001_device::write_h(offs_t offset, u8 data) -------------------------------------------------*/ -void nes_batmanfs_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(nes_batmanfs_device::irq_timer_tick) { - if (id == TIMER_IRQ) - { - // 10-bit counter does not stop when interrupts are disabled - m_irq_count = (m_irq_count + 1) & 0x3ff; - if (m_irq_enable && !m_irq_count) - set_irq_line(ASSERT_LINE); - } + // 10-bit counter does not stop when interrupts are disabled + m_irq_count = (m_irq_count + 1) & 0x3ff; + if (m_irq_enable && !m_irq_count) + set_irq_line(ASSERT_LINE); } void nes_batmanfs_device::write_h(offs_t offset, u8 data) @@ -1850,18 +1826,15 @@ void nes_lh51_device::write_h(offs_t offset, u8 data) -------------------------------------------------*/ -void nes_lh53_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(nes_lh53_device::irq_timer_tick) { - if (id == TIMER_IRQ) + if (m_irq_enable) { - if (m_irq_enable) + m_irq_count++; + if (m_irq_count > 7560)//value from FCEUMM... { - m_irq_count++; - if (m_irq_count > 7560)//value from FCEUMM... - { - m_irq_count = 0; - set_irq_line(ASSERT_LINE); - } + m_irq_count = 0; + set_irq_line(ASSERT_LINE); } } } @@ -2086,16 +2059,13 @@ uint8_t nes_rt01_device::read_h(offs_t offset) -------------------------------------------------*/ -void nes_yung08_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(nes_yung08_device::irq_timer_tick) { - if (id == TIMER_IRQ) + if (BIT(m_irq_latch, 0)) { - if (BIT(m_irq_latch, 0)) - { - m_irq_count = (m_irq_count + 1) & 0x0fff; - if (!m_irq_count) - set_irq_line(ASSERT_LINE); - } + m_irq_count = (m_irq_count + 1) & 0x0fff; + if (!m_irq_count) + set_irq_line(ASSERT_LINE); } } diff --git a/src/devices/bus/nes/bootleg.h b/src/devices/bus/nes/bootleg.h index 2f97f94444e..93cdaa2ec6f 100644 --- a/src/devices/bus/nes/bootleg.h +++ b/src/devices/bus/nes/bootleg.h @@ -15,7 +15,7 @@ public: nes_sc127_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock); virtual void write_h(offs_t offset, uint8_t data) override; - virtual void hblank_irq(int scanline, int vblank, int blanked) override; + virtual void hblank_irq(int scanline, bool vblank, bool blanked) override; virtual void pcb_reset() override; protected: @@ -44,14 +44,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; + + TIMER_CALLBACK_MEMBER(irq_timer_tick); private: u16 m_irq_count; int m_irq_enable; u8 m_latch; - static constexpr device_timer_id TIMER_IRQ = 0; emu_timer *irq_timer; }; @@ -94,13 +94,13 @@ 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(irq_timer_tick); private: u16 m_irq_count; int m_irq_enable; - static const device_timer_id TIMER_IRQ = 0; emu_timer *irq_timer; }; @@ -127,7 +127,7 @@ public: nes_btl_dn_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock); virtual void write_h(offs_t offset, uint8_t data) override; - virtual void hblank_irq(int scanline, int vblank, int blanked) override; + virtual void hblank_irq(int scanline, bool vblank, bool blanked) override; virtual void pcb_reset() override; protected: @@ -158,7 +158,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(irq_timer_tick); private: void update_irq(u8 data); @@ -166,7 +167,6 @@ private: u16 m_irq_count; int m_irq_enable; - static const device_timer_id TIMER_IRQ = 0; emu_timer *irq_timer; }; @@ -187,13 +187,13 @@ 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(irq_timer_tick); private: u16 m_irq_count; int m_irq_enable; - static const device_timer_id TIMER_IRQ = 0; emu_timer *irq_timer; }; @@ -217,7 +217,8 @@ 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(irq_timer_tick); u16 m_irq_count; int m_irq_enable; @@ -227,7 +228,6 @@ private: void write_45(offs_t offset, u8 data); const u8 m_bank67; - static const device_timer_id TIMER_IRQ = 0; emu_timer *irq_timer; }; @@ -285,14 +285,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; + + TIMER_CALLBACK_MEMBER(irq_timer_tick); private: u16 m_irq_count; int m_irq_enable; u8 m_reg; - static const device_timer_id TIMER_IRQ = 0; emu_timer *irq_timer; }; @@ -312,12 +312,12 @@ 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(irq_timer_tick); private: u16 m_irq_count; - static const device_timer_id TIMER_IRQ = 0; emu_timer *irq_timer; }; @@ -337,13 +337,13 @@ 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(irq_timer_tick); private: u16 m_irq_count; int m_irq_enable; - static const device_timer_id TIMER_IRQ = 0; emu_timer *irq_timer; }; @@ -583,14 +583,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; + + TIMER_CALLBACK_MEMBER(irq_timer_tick); private: uint16_t m_irq_count; int m_irq_enable; uint8_t m_reg; - static const device_timer_id TIMER_IRQ = 0; emu_timer *irq_timer; attotime timer_freq; }; @@ -688,14 +688,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; + + TIMER_CALLBACK_MEMBER(irq_timer_tick); private: void write_45(offs_t offset, u8 data); u16 m_irq_count; int m_irq_latch; - static const device_timer_id TIMER_IRQ = 0; emu_timer *irq_timer; }; diff --git a/src/devices/bus/nes/cony.cpp b/src/devices/bus/nes/cony.cpp index 4baafff89c1..3e73f35a4bf 100644 --- a/src/devices/bus/nes/cony.cpp +++ b/src/devices/bus/nes/cony.cpp @@ -62,7 +62,7 @@ nes_yoko_device::nes_yoko_device(const machine_config &mconfig, const char *tag, void nes_cony_device::device_start() { common_start(); - irq_timer = timer_alloc(TIMER_IRQ); + irq_timer = timer_alloc(FUNC(nes_cony_device::irq_timer_tick), this); irq_timer->adjust(attotime::zero, 0, clocks_to_attotime(1)); save_item(NAME(m_irq_enable)); @@ -112,18 +112,15 @@ void nes_cony_device::pcb_reset() -------------------------------------------------*/ -void nes_cony_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(nes_cony_device::irq_timer_tick) { - if (id == TIMER_IRQ) + if (m_irq_enable) { - if (m_irq_enable) + m_irq_count += BIT(m_mode_reg, 6) ? -1 : 1; + if (!m_irq_count) { - m_irq_count += BIT(m_mode_reg, 6) ? -1 : 1; - if (!m_irq_count) - { - set_irq_line(ASSERT_LINE); - m_irq_enable = 0; - } + set_irq_line(ASSERT_LINE); + m_irq_enable = 0; } } } diff --git a/src/devices/bus/nes/cony.h b/src/devices/bus/nes/cony.h index 29fff1908e9..8f2faea4a40 100644 --- a/src/devices/bus/nes/cony.h +++ b/src/devices/bus/nes/cony.h @@ -30,15 +30,15 @@ protected: // device-level overrides virtual void device_start() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; virtual void set_prg(); virtual void set_chr(); + TIMER_CALLBACK_MEMBER(irq_timer_tick); + u16 m_irq_count; int m_irq_enable; - static constexpr device_timer_id TIMER_IRQ = 0; emu_timer *irq_timer; u8 m_mmc_prg_bank[4]; diff --git a/src/devices/bus/nes/datach.cpp b/src/devices/bus/nes/datach.cpp index c5f5f3c7f9a..5e71e0af6bc 100644 --- a/src/devices/bus/nes/datach.cpp +++ b/src/devices/bus/nes/datach.cpp @@ -231,8 +231,8 @@ nes_datach_device::nes_datach_device(const machine_config &mconfig, const char * void nes_datach_device::device_start() { common_start(); - irq_timer = timer_alloc(TIMER_IRQ); - serial_timer = timer_alloc(TIMER_SERIAL); + irq_timer = timer_alloc(FUNC(nes_datach_device::irq_timer_tick), this); + serial_timer = timer_alloc(FUNC(nes_datach_device::serial_tick), this); irq_timer->adjust(attotime::zero, 0, clocks_to_attotime(1)); serial_timer->adjust(attotime::zero, 0, clocks_to_attotime(1000)); @@ -377,32 +377,34 @@ void nes_datach_device::device_add_mconfig(machine_config &config) //------------------------------------------------- -// device_timer - handler timer events +// irq_timer_tick - handle IRQ timer //------------------------------------------------- -void nes_datach_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(nes_datach_device::irq_timer_tick) { - if (id == TIMER_IRQ) + if (m_irq_enable) { - if (m_irq_enable) + // 16bit counter, IRQ fired when the counter goes from 1 to 0 + // after firing, the counter is *not* reloaded, but next clock + // counter wraps around from 0 to 0xffff + if (!m_irq_count) + m_irq_count = 0xffff; + else + m_irq_count--; + + if (!m_irq_count) { - // 16bit counter, IRQ fired when the counter goes from 1 to 0 - // after firing, the counter is *not* reloaded, but next clock - // counter wraps around from 0 to 0xffff - if (!m_irq_count) - m_irq_count = 0xffff; - else - m_irq_count--; - - if (!m_irq_count) - { - set_irq_line(ASSERT_LINE); - m_irq_enable = 0; - } + set_irq_line(ASSERT_LINE); + m_irq_enable = 0; } } - if (id == TIMER_SERIAL) - { - m_datach_latch = (m_reader->read_pixel() << 3); - } +} + +//------------------------------------------------- +// serial_tick - tick in a serial bit +//------------------------------------------------- + +TIMER_CALLBACK_MEMBER(nes_datach_device::serial_tick) +{ + m_datach_latch = (m_reader->read_pixel() << 3); } diff --git a/src/devices/bus/nes/datach.h b/src/devices/bus/nes/datach.h index abdbf36bdaa..80770904596 100644 --- a/src/devices/bus/nes/datach.h +++ b/src/devices/bus/nes/datach.h @@ -155,9 +155,11 @@ public: protected: // device-level overrides virtual void device_start() 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(irq_timer_tick); + TIMER_CALLBACK_MEMBER(serial_tick); + uint8_t m_datach_latch; required_device<i2cmem_device> m_i2cmem; required_device<barcode_reader_device> m_reader; @@ -165,7 +167,6 @@ protected: uint8_t m_i2c_dir; uint8_t m_i2c_in_use; - static const device_timer_id TIMER_SERIAL = 1; emu_timer *serial_timer; }; diff --git a/src/devices/bus/nes/disksys.cpp b/src/devices/bus/nes/disksys.cpp index 71622a3a9e6..d53a2be2aab 100644 --- a/src/devices/bus/nes/disksys.cpp +++ b/src/devices/bus/nes/disksys.cpp @@ -121,7 +121,7 @@ void nes_disksys_device::device_start() m_disk->floppy_install_load_proc(nes_disksys_device::load_proc); m_disk->floppy_install_unload_proc(nes_disksys_device::unload_proc); - irq_timer = timer_alloc(TIMER_IRQ); + irq_timer = timer_alloc(FUNC(nes_disksys_device::irq_timer_tick), this); irq_timer->adjust(attotime::zero, 0, clocks_to_attotime(1)); save_item(NAME(m_fds_motor_on)); @@ -212,7 +212,7 @@ uint8_t nes_disksys_device::read_m(offs_t offset) return m_prgram[offset]; } -void nes_disksys_device::hblank_irq(int scanline, int vblank, int blanked) +void nes_disksys_device::hblank_irq(int scanline, bool vblank, bool blanked) { // FIXME: This looks like a gross hack that ties the disk byte transfer IRQ to the PPU. Seriously? if (m_irq_transfer) @@ -403,25 +403,22 @@ uint8_t nes_disksys_device::read_ex(offs_t offset) } //------------------------------------------------- -// device_timer - handler timer events +// irq_timer_tick - handle IRQ timer //------------------------------------------------- -void nes_disksys_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(nes_disksys_device::irq_timer_tick) { - if (id == TIMER_IRQ) + if (m_irq_enable) { - if (m_irq_enable) + if (m_irq_count) + m_irq_count--; + else { - if (m_irq_count) - m_irq_count--; - else - { - set_irq_line(ASSERT_LINE); - m_irq_count = m_irq_count_latch; - if (!m_irq_repeat) - m_irq_enable = 0; - m_fds_status0 |= 0x01; - } + set_irq_line(ASSERT_LINE); + m_irq_count = m_irq_count_latch; + if (!m_irq_repeat) + m_irq_enable = 0; + m_fds_status0 |= 0x01; } } } diff --git a/src/devices/bus/nes/disksys.h b/src/devices/bus/nes/disksys.h index 61bd9dd2048..021be514029 100644 --- a/src/devices/bus/nes/disksys.h +++ b/src/devices/bus/nes/disksys.h @@ -27,13 +27,12 @@ public: virtual void disk_flip_side() override; - virtual void hblank_irq(int scanline, int vblank, int blanked) override; + virtual void hblank_irq(int scanline, bool vblank, bool blanked) override; virtual void pcb_reset() override; protected: // device-level overrides virtual void device_start() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; virtual void device_add_mconfig(machine_config &config) override; virtual const tiny_rom_entry *device_rom_region() const override; @@ -44,11 +43,12 @@ private: static void load_proc(device_image_interface &image, bool is_created); static void unload_proc(device_image_interface &image); + TIMER_CALLBACK_MEMBER(irq_timer_tick); + std::unique_ptr<uint8_t[]> m_fds_data; // here, we store a copy of the disk required_device<legacy_floppy_image_device> m_disk; required_device<rp2c33_sound_device> m_sound; - static const device_timer_id TIMER_IRQ = 0; emu_timer *irq_timer; void load_disk(device_image_interface &image); diff --git a/src/devices/bus/nes/event.cpp b/src/devices/bus/nes/event.cpp index 0ebc4ace30a..70aee4b90e0 100644 --- a/src/devices/bus/nes/event.cpp +++ b/src/devices/bus/nes/event.cpp @@ -61,7 +61,7 @@ void nes_event_device::device_start() { nes_sxrom_device::device_start(); - event_timer = timer_alloc(TIMER_EVENT); + event_timer = timer_alloc(FUNC(nes_event_device::event_tick), this); event_timer->adjust(attotime::never); save_item(NAME(m_nwc_init)); @@ -87,7 +87,7 @@ void nes_event2_device::device_start() { mmc3_start(); - event_timer = timer_alloc(TIMER_EVENT); + event_timer = timer_alloc(FUNC(nes_event2_device::event_tick), this); event_timer->adjust(attotime::zero, 0, clocks_to_attotime(1)); save_item(NAME(m_tqrom_mode)); @@ -296,12 +296,12 @@ ioport_constructor nes_event2_device::device_input_ports() const //------------------------------------------------- -// device_timer - handler timer events +// event_tick - tick the event timer //------------------------------------------------- -void nes_event_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(nes_event_device::event_tick) { - if (id == TIMER_EVENT && m_timer_on) + if (m_timer_on) { if (++m_timer_count >= (0x10 | m_dsw->read()) << 25) { @@ -311,8 +311,8 @@ void nes_event_device::device_timer(emu_timer &timer, device_timer_id id, int pa } } -void nes_event2_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(nes_event2_device::event_tick) { - if (id == TIMER_EVENT && m_timer_enabled) + if (m_timer_enabled) m_timer_count++; } diff --git a/src/devices/bus/nes/event.h b/src/devices/bus/nes/event.h index 51875802695..b10a3f95ee1 100644 --- a/src/devices/bus/nes/event.h +++ b/src/devices/bus/nes/event.h @@ -22,17 +22,17 @@ public: protected: // device-level overrides virtual void device_start() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; virtual ioport_constructor device_input_ports() const override; virtual void set_prg() override; virtual void set_chr() override; + TIMER_CALLBACK_MEMBER(event_tick); + required_ioport m_dsw; int m_nwc_init; - static constexpr device_timer_id TIMER_EVENT = 0; emu_timer *event_timer; u32 m_timer_count; @@ -58,14 +58,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; virtual ioport_constructor device_input_ports() const override; + TIMER_CALLBACK_MEMBER(event_tick); + required_ioport m_dsw; bool m_tqrom_mode; - static constexpr device_timer_id TIMER_EVENT = 0; emu_timer *event_timer; u32 m_timer_count; diff --git a/src/devices/bus/nes/ggenie.h b/src/devices/bus/nes/ggenie.h index 49681c1ed5f..6370301d19a 100644 --- a/src/devices/bus/nes/ggenie.h +++ b/src/devices/bus/nes/ggenie.h @@ -28,8 +28,8 @@ public: virtual u8 nt_r(offs_t offset) override; virtual void nt_w(offs_t offset, u8 data) override; - void hblank_irq(int scanline, int vblank, int blanked) override { if (m_gg_bypass && m_ggslot->m_cart) m_ggslot->m_cart->hblank_irq(scanline, vblank, blanked); } - void scanline_irq(int scanline, int vblank, int blanked) override { if (m_gg_bypass && m_ggslot->m_cart) m_ggslot->m_cart->scanline_irq(scanline, vblank, blanked); } + void hblank_irq(int scanline, bool vblank, bool blanked) override { if (m_gg_bypass && m_ggslot->m_cart) m_ggslot->m_cart->hblank_irq(scanline, vblank, blanked); } + void scanline_irq(int scanline, bool vblank, bool blanked) override { if (m_gg_bypass && m_ggslot->m_cart) m_ggslot->m_cart->scanline_irq(scanline, vblank, blanked); } void ppu_latch(offs_t offset) override { if (m_gg_bypass && m_ggslot->m_cart) m_ggslot->m_cart->ppu_latch(offset); } virtual void pcb_reset() override; diff --git a/src/devices/bus/nes/irem.cpp b/src/devices/bus/nes/irem.cpp index d0bc4d48857..f90959825a9 100644 --- a/src/devices/bus/nes/irem.cpp +++ b/src/devices/bus/nes/irem.cpp @@ -115,7 +115,7 @@ void nes_g101_device::pcb_reset() void nes_h3001_device::device_start() { nes_g101_device::device_start(); - irq_timer = timer_alloc(TIMER_IRQ); + irq_timer = timer_alloc(FUNC(nes_h3001_device::irq_timer_tick), this); irq_timer->adjust(attotime::zero, 0, clocks_to_attotime(1)); save_item(NAME(m_irq_enable)); @@ -260,22 +260,19 @@ void nes_g101_device::write_h(offs_t offset, u8 data) -------------------------------------------------*/ -void nes_h3001_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(nes_h3001_device::irq_timer_tick) { - if (id == TIMER_IRQ) + if (m_irq_enable) { - if (m_irq_enable) - { - // 16bit counter, IRQ fired when the counter reaches 0 - // after firing, the counter is *not* reloaded and does not wrap - if (m_irq_count) - m_irq_count--; + // 16bit counter, IRQ fired when the counter reaches 0 + // after firing, the counter is *not* reloaded and does not wrap + if (m_irq_count) + m_irq_count--; - if (!m_irq_count) - { - set_irq_line(ASSERT_LINE); - m_irq_enable = 0; - } + if (!m_irq_count) + { + set_irq_line(ASSERT_LINE); + m_irq_enable = 0; } } } diff --git a/src/devices/bus/nes/irem.h b/src/devices/bus/nes/irem.h index 476d85f6735..eef809ca7b5 100644 --- a/src/devices/bus/nes/irem.h +++ b/src/devices/bus/nes/irem.h @@ -93,13 +93,13 @@ 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(irq_timer_tick); private: u16 m_irq_count, m_irq_count_latch; u8 m_irq_enable; - static constexpr device_timer_id TIMER_IRQ = 0; emu_timer *irq_timer; }; diff --git a/src/devices/bus/nes/jaleco.cpp b/src/devices/bus/nes/jaleco.cpp index e88af117c12..a83ebfb5a04 100644 --- a/src/devices/bus/nes/jaleco.cpp +++ b/src/devices/bus/nes/jaleco.cpp @@ -159,7 +159,7 @@ void nes_jf17_device::pcb_reset() void nes_ss88006_device::device_start() { common_start(); - irq_timer = timer_alloc(TIMER_IRQ); + irq_timer = timer_alloc(FUNC(nes_ss88006_device::irq_timer_tick), this); irq_timer->adjust(attotime::zero, 0, clocks_to_attotime(1)); save_item(NAME(m_mmc_prg_bank)); @@ -315,26 +315,23 @@ void nes_jf17_device::write_h(offs_t offset, u8 data) -------------------------------------------------*/ -void nes_ss88006_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(nes_ss88006_device::irq_timer_tick) { - if (id == TIMER_IRQ) + if (m_irq_enable) { - if (m_irq_enable) - { - u16 mask = 0xffff; // 16-bit counter (default) - - if (BIT(m_irq_mode, 3)) // 4-bit counter - mask = 0x000f; - else if (BIT(m_irq_mode, 2)) // 8-bit counter - mask = 0x00ff; - else if (BIT(m_irq_mode, 1)) // 12-bit counter - mask = 0x0fff; - - m_irq_count = (m_irq_count & ~mask) | ((m_irq_count - 1) & mask); - - if ((m_irq_count & mask) == mask) - set_irq_line(ASSERT_LINE); - } + u16 mask = 0xffff; // 16-bit counter (default) + + if (BIT(m_irq_mode, 3)) // 4-bit counter + mask = 0x000f; + else if (BIT(m_irq_mode, 2)) // 8-bit counter + mask = 0x00ff; + else if (BIT(m_irq_mode, 1)) // 12-bit counter + mask = 0x0fff; + + m_irq_count = (m_irq_count & ~mask) | ((m_irq_count - 1) & mask); + + if ((m_irq_count & mask) == mask) + set_irq_line(ASSERT_LINE); } } diff --git a/src/devices/bus/nes/jaleco.h b/src/devices/bus/nes/jaleco.h index 0b81626c4bf..7ed1b13d25a 100644 --- a/src/devices/bus/nes/jaleco.h +++ b/src/devices/bus/nes/jaleco.h @@ -135,7 +135,8 @@ 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(irq_timer_tick); optional_device<samples_device> m_samples; @@ -144,7 +145,6 @@ private: u8 m_irq_mode; u8 m_irq_enable; - static constexpr device_timer_id TIMER_IRQ = 0; emu_timer *irq_timer; u8 m_mmc_prg_bank[3]; diff --git a/src/devices/bus/nes/jy.cpp b/src/devices/bus/nes/jy.cpp index 0aae4039ff9..655634f22ef 100644 --- a/src/devices/bus/nes/jy.cpp +++ b/src/devices/bus/nes/jy.cpp @@ -73,7 +73,7 @@ nes_jy_typec_device::nes_jy_typec_device(const machine_config &mconfig, const ch void nes_jy_typea_device::device_start() { common_start(); - irq_timer = timer_alloc(TIMER_IRQ); + irq_timer = timer_alloc(FUNC(nes_jy_typea_device::irq_timer_tick), this); irq_timer->reset(); timer_freq = clocks_to_attotime(1); @@ -146,18 +146,18 @@ void nes_jy_typea_device::pcb_reset() uint8_t nes_jy_typea_device::nt_r(offs_t offset) { int page = ((offset & 0xc00) >> 10); - irq_clock(0, 2); + irq_clock(false, 2); return m_nt_access[page][offset & 0x3ff]; } uint8_t nes_jy_typea_device::chr_r(offs_t offset) { int bank = offset >> 10; - irq_clock(0, 2); + irq_clock(false, 2); return m_chr_access[bank][offset & 0x3ff]; } -void nes_jy_typea_device::irq_clock(int mode, int blanked) +void nes_jy_typea_device::irq_clock(bool blanked, int mode) { bool clock = false, fire = false; @@ -224,15 +224,12 @@ void nes_jy_typea_device::irq_clock(int mode, int blanked) } } -void nes_jy_typea_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(nes_jy_typea_device::irq_timer_tick) { - if (id == TIMER_IRQ) - { - irq_clock(0, 0); - } + irq_clock(false, 0); } -void nes_jy_typea_device::scanline_irq(int scanline, int vblank, int blanked) +void nes_jy_typea_device::scanline_irq(int scanline, bool vblank, bool blanked) { if (scanline < ppu2c0x_device::BOTTOM_VISIBLE_SCANLINE) irq_clock(blanked, 1); @@ -572,7 +569,7 @@ uint8_t nes_jy_typec_device::chr_r(offs_t offset) { int bank = offset >> 10; - irq_clock(0, 2); + irq_clock(false, 2); switch (offset & 0xff0) { case 0xfd0: diff --git a/src/devices/bus/nes/jy.h b/src/devices/bus/nes/jy.h index ac4cf8e397e..69c4ea8b04e 100644 --- a/src/devices/bus/nes/jy.h +++ b/src/devices/bus/nes/jy.h @@ -24,7 +24,7 @@ public: virtual uint8_t chr_r(offs_t offset) override; virtual uint8_t nt_r(offs_t offset) override; - virtual void scanline_irq(int scanline, int vblank, int blanked) override; + virtual void scanline_irq(int scanline, bool vblank, bool blanked) override; virtual void pcb_reset() override; protected: @@ -32,9 +32,10 @@ protected: // device-level overrides virtual void device_start() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; - void irq_clock(int blanked, int mode); + TIMER_CALLBACK_MEMBER(irq_timer_tick); + + void irq_clock(bool blanked, int mode); void update_banks(int reg); void update_prg(); void update_chr(); @@ -61,7 +62,6 @@ protected: int m_irq_enable; int m_irq_up, m_irq_down; - static const device_timer_id TIMER_IRQ = 0; emu_timer *irq_timer; attotime timer_freq; }; diff --git a/src/devices/bus/nes/kaiser.cpp b/src/devices/bus/nes/kaiser.cpp index f0f37d2ba2b..4635c699895 100644 --- a/src/devices/bus/nes/kaiser.cpp +++ b/src/devices/bus/nes/kaiser.cpp @@ -188,7 +188,7 @@ void nes_ks7022_device::pcb_reset() void nes_ks7032_device::device_start() { common_start(); - irq_timer = timer_alloc(TIMER_IRQ); + irq_timer = timer_alloc(FUNC(nes_ks7032_device::irq_timer_tick), this); irq_timer->adjust(attotime::zero, 0, clocks_to_attotime(1)); save_item(NAME(m_latch)); @@ -230,7 +230,7 @@ void nes_ks7016_device::pcb_reset() void nes_ks7017_device::device_start() { common_start(); - irq_timer = timer_alloc(TIMER_IRQ); + irq_timer = timer_alloc(FUNC(nes_ks7017_device::irq_timer_tick), this); irq_timer->adjust(attotime::zero, 0, clocks_to_attotime(1)); save_item(NAME(m_latch)); @@ -443,18 +443,15 @@ u8 nes_ks7022_device::read_h(offs_t offset) -------------------------------------------------*/ -void nes_ks7032_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(nes_ks7032_device::irq_timer_tick) { - if (id == TIMER_IRQ) + if (m_irq_enable) { - if (m_irq_enable) + if (++m_irq_count == 0) { - if (++m_irq_count == 0) - { - set_irq_line(ASSERT_LINE); - m_irq_enable = 0; - m_irq_count = m_irq_count_latch; - } + set_irq_line(ASSERT_LINE); + m_irq_enable = 0; + m_irq_count = m_irq_count_latch; } } } @@ -611,18 +608,15 @@ void nes_ks7016_device::write_h(offs_t offset, u8 data) -------------------------------------------------*/ -void nes_ks7017_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(nes_ks7017_device::irq_timer_tick) { - if (id == TIMER_IRQ) + if (m_irq_enable) { - if (m_irq_enable) + if (--m_irq_count == 0) { - if (--m_irq_count == 0) - { - set_irq_line(ASSERT_LINE); - m_irq_enable = 0; - m_irq_status |= 0x01; - } + set_irq_line(ASSERT_LINE); + m_irq_enable = 0; + m_irq_status |= 0x01; } } } diff --git a/src/devices/bus/nes/kaiser.h b/src/devices/bus/nes/kaiser.h index 4c19ff2c2a0..bfed01f40f9 100644 --- a/src/devices/bus/nes/kaiser.h +++ b/src/devices/bus/nes/kaiser.h @@ -80,7 +80,8 @@ 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(irq_timer_tick); u8 m_reg[8]; @@ -91,7 +92,6 @@ private: u16 m_irq_count, m_irq_count_latch; u8 m_irq_enable; - static const device_timer_id TIMER_IRQ = 0; emu_timer *irq_timer; }; @@ -162,7 +162,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(irq_timer_tick); private: u8 m_latch; @@ -171,7 +172,6 @@ private: u8 m_irq_status; u8 m_irq_enable; - static const device_timer_id TIMER_IRQ = 0; emu_timer *irq_timer; }; diff --git a/src/devices/bus/nes/konami.cpp b/src/devices/bus/nes/konami.cpp index ae7c30dcb9b..64835930218 100644 --- a/src/devices/bus/nes/konami.cpp +++ b/src/devices/bus/nes/konami.cpp @@ -122,7 +122,7 @@ void nes_konami_vrc2_device::pcb_reset() void nes_konami_vrc3_device::device_start() { common_start(); - irq_timer = timer_alloc(TIMER_IRQ); + irq_timer = timer_alloc(FUNC(nes_konami_vrc3_device::irq_timer_tick), this); irq_timer->adjust(attotime::zero, 0, clocks_to_attotime(1)); save_item(NAME(m_irq_mode)); @@ -148,7 +148,7 @@ void nes_konami_vrc3_device::pcb_reset() void nes_konami_vrc4_device::device_start() { common_start(); - irq_timer = timer_alloc(TIMER_IRQ); + irq_timer = timer_alloc(FUNC(nes_konami_vrc4_device::irq_timer_tick), this); irq_timer->adjust(attotime::zero, 0, clocks_to_attotime(1)); save_item(NAME(m_irq_mode)); @@ -309,21 +309,18 @@ void nes_konami_vrc2_device::write_h(offs_t offset, u8 data) -------------------------------------------------*/ -void nes_konami_vrc3_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(nes_konami_vrc3_device::irq_timer_tick) { - if (id == TIMER_IRQ) + if (m_irq_enable) { - if (m_irq_enable) - { - u16 mask = m_irq_mode ? 0x00ff : 0xffff; // 8 or 16 bit mode? + u16 mask = m_irq_mode ? 0x00ff : 0xffff; // 8 or 16 bit mode? - // upper byte only incremented and reloaded in 16-bit mode - m_irq_count = (m_irq_count & ~mask) | ((m_irq_count + 1) & mask); - if (!(m_irq_count & mask)) - { - set_irq_line(ASSERT_LINE); - m_irq_count = (m_irq_count & ~mask) | (m_irq_count_latch & mask); - } + // upper byte only incremented and reloaded in 16-bit mode + m_irq_count = (m_irq_count & ~mask) | ((m_irq_count + 1) & mask); + if (!(m_irq_count & mask)) + { + set_irq_line(ASSERT_LINE); + m_irq_count = (m_irq_count & ~mask) | (m_irq_count_latch & mask); } } } @@ -384,26 +381,23 @@ void nes_konami_vrc4_device::irq_tick() m_irq_count++; } -void nes_konami_vrc4_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(nes_konami_vrc4_device::irq_timer_tick) { - if (id == TIMER_IRQ) + if (m_irq_enable) { - if (m_irq_enable) + if (m_irq_mode) // cycle mode + irq_tick(); + else // scanline mode { - if (m_irq_mode) // cycle mode - irq_tick(); - else // scanline mode + // A prescaler divides the passing CPU cycles by 114, 114, then 113 (and repeats that order). + // This approximates 113+2/3 CPU cycles, which is one NTSC scanline. + // Since this is a CPU-based IRQ, though, it is triggered also during non visible scanlines... + m_irq_prescale -= 3; + + if (m_irq_prescale <= 0) { - // A prescaler divides the passing CPU cycles by 114, 114, then 113 (and repeats that order). - // This approximates 113+2/3 CPU cycles, which is one NTSC scanline. - // Since this is a CPU-based IRQ, though, it is triggered also during non visible scanlines... - m_irq_prescale -= 3; - - if (m_irq_prescale <= 0) - { - m_irq_prescale += 341; - irq_tick(); - } + m_irq_prescale += 341; + irq_tick(); } } } diff --git a/src/devices/bus/nes/konami.h b/src/devices/bus/nes/konami.h index add13c379d9..ced0f7f4648 100644 --- a/src/devices/bus/nes/konami.h +++ b/src/devices/bus/nes/konami.h @@ -73,14 +73,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; + + TIMER_CALLBACK_MEMBER(irq_timer_tick); private: u16 m_irq_count, m_irq_count_latch; int m_irq_enable, m_irq_enable_latch; int m_irq_mode; - static constexpr device_timer_id TIMER_IRQ = 0; emu_timer *irq_timer; }; @@ -105,7 +105,8 @@ 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(irq_timer_tick); void set_mirror(u8 data); void set_prg(int prg_base, int prg_mask); @@ -126,7 +127,6 @@ protected: int m_irq_mode; int m_irq_prescale; - static constexpr device_timer_id TIMER_IRQ = 0; emu_timer *irq_timer; }; diff --git a/src/devices/bus/nes/legacy.cpp b/src/devices/bus/nes/legacy.cpp index 61ac1e6bdae..8625c4fab97 100644 --- a/src/devices/bus/nes/legacy.cpp +++ b/src/devices/bus/nes/legacy.cpp @@ -62,7 +62,7 @@ nes_ffe8_device::nes_ffe8_device(const machine_config &mconfig, const char *tag, void nes_ffe4_device::device_start() { common_start(); - irq_timer = timer_alloc(TIMER_IRQ); + irq_timer = timer_alloc(FUNC(nes_ffe4_device::irq_timer_tick), this); irq_timer->adjust(attotime::zero, 0, clocks_to_attotime(1)); save_item(NAME(m_exram)); @@ -141,21 +141,18 @@ void nes_ffe3_device::write_h(offs_t offset, uint8_t data) -------------------------------------------------*/ -void nes_ffe4_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(nes_ffe4_device::irq_timer_tick) { - if (id == TIMER_IRQ) + if (m_irq_enable) { - if (m_irq_enable) + if (m_irq_count == 0xffff) { - if (m_irq_count == 0xffff) - { - set_irq_line(ASSERT_LINE); - m_irq_count = 0; - m_irq_enable = 0; - } - else - m_irq_count++; + set_irq_line(ASSERT_LINE); + m_irq_count = 0; + m_irq_enable = 0; } + else + m_irq_count++; } } diff --git a/src/devices/bus/nes/legacy.h b/src/devices/bus/nes/legacy.h index 8f2c0419ff1..191a718da45 100644 --- a/src/devices/bus/nes/legacy.h +++ b/src/devices/bus/nes/legacy.h @@ -36,13 +36,12 @@ public: virtual void pcb_reset() override; protected: - static constexpr device_timer_id TIMER_IRQ = 0; - nes_ffe4_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock); // 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(irq_timer_tick); uint16_t m_irq_count; int m_irq_enable; diff --git a/src/devices/bus/nes/mmc3.cpp b/src/devices/bus/nes/mmc3.cpp index 4dd3422cb54..ff9774882fd 100644 --- a/src/devices/bus/nes/mmc3.cpp +++ b/src/devices/bus/nes/mmc3.cpp @@ -204,7 +204,7 @@ void nes_zz_device::pcb_reset() -------------------------------------------------*/ /* Here, IRQ counter decrements every scanline. */ -void nes_txrom_device::hblank_irq(int scanline, int vblank, int blanked) +void nes_txrom_device::hblank_irq(int scanline, bool vblank, bool blanked) { if (scanline < ppu2c0x_device::BOTTOM_VISIBLE_SCANLINE) { diff --git a/src/devices/bus/nes/mmc3.h b/src/devices/bus/nes/mmc3.h index 3d5f72b63e0..1bc3cc0536c 100644 --- a/src/devices/bus/nes/mmc3.h +++ b/src/devices/bus/nes/mmc3.h @@ -23,7 +23,7 @@ public: virtual void prg_cb(int start, int bank); virtual void chr_cb(int start, int bank, int source); - virtual void hblank_irq(int scanline, int vblank, int blanked) override; + virtual void hblank_irq(int scanline, bool vblank, bool blanked) override; virtual void pcb_reset() override; protected: diff --git a/src/devices/bus/nes/mmc5.cpp b/src/devices/bus/nes/mmc5.cpp index 2c923f562fd..f15b1a7658b 100644 --- a/src/devices/bus/nes/mmc5.cpp +++ b/src/devices/bus/nes/mmc5.cpp @@ -235,7 +235,7 @@ void nes_exrom_device::update_prg() } } -void nes_exrom_device::hblank_irq(int scanline, int vblank, int blanked ) +void nes_exrom_device::hblank_irq(int scanline, bool vblank, bool blanked) { m_vcount = scanline; diff --git a/src/devices/bus/nes/mmc5.h b/src/devices/bus/nes/mmc5.h index 27a9709cafd..a806c704883 100644 --- a/src/devices/bus/nes/mmc5.h +++ b/src/devices/bus/nes/mmc5.h @@ -31,7 +31,7 @@ public: virtual uint8_t nt_r(offs_t offset) override; virtual void nt_w(offs_t offset, uint8_t data) override; - virtual void hblank_irq(int scanline, int vblank, int blanked) override; + virtual void hblank_irq(int scanline, bool vblank, bool blanked) override; virtual void pcb_reset() override; protected: diff --git a/src/devices/bus/nes/namcot.cpp b/src/devices/bus/nes/namcot.cpp index 1d44b13624f..31f72761751 100644 --- a/src/devices/bus/nes/namcot.cpp +++ b/src/devices/bus/nes/namcot.cpp @@ -140,7 +140,7 @@ void nes_namcot3425_device::pcb_reset() void nes_namcot340_device::device_start() { common_start(); - irq_timer = timer_alloc(TIMER_IRQ); + irq_timer = timer_alloc(FUNC(nes_namcot340_device::irq_timer_tick), this); irq_timer->adjust(attotime::zero, 0, clocks_to_attotime(1)); save_item(NAME(m_irq_enable)); @@ -165,7 +165,7 @@ void nes_namcot340_device::pcb_reset() void nes_namcot175_device::device_start() { common_start(); - irq_timer = timer_alloc(TIMER_IRQ); + irq_timer = timer_alloc(FUNC(nes_namcot175_device::irq_timer_tick), this); irq_timer->adjust(attotime::zero, 0, clocks_to_attotime(1)); save_item(NAME(m_irq_enable)); @@ -192,7 +192,7 @@ void nes_namcot175_device::pcb_reset() void nes_namcot163_device::device_start() { common_start(); - irq_timer = timer_alloc(TIMER_IRQ); + irq_timer = timer_alloc(FUNC(nes_namcot163_device::irq_timer_tick), this); irq_timer->adjust(attotime::zero, 0, clocks_to_attotime(1)); save_item(NAME(m_irq_enable)); @@ -397,17 +397,14 @@ void nes_namcot3425_device::write_h(offs_t offset, uint8_t data) -------------------------------------------------*/ -void nes_namcot340_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(nes_namcot340_device::irq_timer_tick) { - if (id == TIMER_IRQ) + if (m_irq_enable) { - if (m_irq_enable) - { - if (m_irq_count == 0x7fff) // counter does not wrap to 0! - set_irq_line(ASSERT_LINE); - else - m_irq_count++; - } + if (m_irq_count == 0x7fff) // counter does not wrap to 0! + set_irq_line(ASSERT_LINE); + else + m_irq_count++; } } diff --git a/src/devices/bus/nes/namcot.h b/src/devices/bus/nes/namcot.h index e8fb0430fee..13d30804b8a 100644 --- a/src/devices/bus/nes/namcot.h +++ b/src/devices/bus/nes/namcot.h @@ -94,13 +94,12 @@ public: virtual void pcb_reset() override; protected: - static constexpr device_timer_id TIMER_IRQ = 0; - nes_namcot340_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock); // 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(irq_timer_tick); uint16_t m_irq_count; int m_irq_enable; diff --git a/src/devices/bus/nes/nanjing.cpp b/src/devices/bus/nes/nanjing.cpp index 3618024830c..6a451b3c59d 100644 --- a/src/devices/bus/nes/nanjing.cpp +++ b/src/devices/bus/nes/nanjing.cpp @@ -91,7 +91,7 @@ void nes_nanjing_device::pcb_reset() -------------------------------------------------*/ -void nes_nanjing_device::hblank_irq(int scanline, int vblank, int blanked) +void nes_nanjing_device::hblank_irq(int scanline, bool vblank, bool blanked) { if (BIT(m_reg[0], 7)) { diff --git a/src/devices/bus/nes/nanjing.h b/src/devices/bus/nes/nanjing.h index c5a71032573..979fbb1e5ee 100644 --- a/src/devices/bus/nes/nanjing.h +++ b/src/devices/bus/nes/nanjing.h @@ -22,7 +22,7 @@ public: virtual uint8_t read_l(offs_t offset) override; virtual void write_l(offs_t offset, uint8_t data) override; - virtual void hblank_irq(int scanline, int vblank, int blanked) override; + virtual void hblank_irq(int scanline, bool vblank, bool blanked) override; virtual void pcb_reset() override; protected: diff --git a/src/devices/bus/nes/nes_slot.h b/src/devices/bus/nes/nes_slot.h index f87ee4273c5..932bff1d41d 100644 --- a/src/devices/bus/nes/nes_slot.h +++ b/src/devices/bus/nes/nes_slot.h @@ -251,8 +251,8 @@ public: uint32_t get_misc_rom_size() const { return m_misc_rom_size; } virtual void ppu_latch(offs_t offset) {} - virtual void hblank_irq(int scanline, int vblank, int blanked) {} - virtual void scanline_irq(int scanline, int vblank, int blanked) {} + virtual void hblank_irq(int scanline, bool vblank, bool blanked) {} + virtual void scanline_irq(int scanline, bool vblank, bool blanked) {} virtual void pcb_reset() {} // many pcb expect specific PRG/CHR banking at start virtual void pcb_start(running_machine &machine, uint8_t *ciram_ptr, bool cart_mounted); diff --git a/src/devices/bus/nes/pirate.cpp b/src/devices/bus/nes/pirate.cpp index f7a5fbd6362..81a06c7d655 100644 --- a/src/devices/bus/nes/pirate.cpp +++ b/src/devices/bus/nes/pirate.cpp @@ -372,7 +372,7 @@ uint8_t nes_fukutake_device::read_m(offs_t offset) -------------------------------------------------*/ -void nes_futuremedia_device::hblank_irq(int scanline, int vblank, int blanked) +void nes_futuremedia_device::hblank_irq(int scanline, bool vblank, bool blanked) { // if (scanline < ppu2c0x_device::BOTTOM_VISIBLE_SCANLINE) { @@ -577,7 +577,7 @@ uint8_t nes_edu2k_device::read_m(offs_t offset) -------------------------------------------------*/ -void nes_jy830623c_device::hblank_irq(int scanline, int vblank, int blanked) +void nes_jy830623c_device::hblank_irq(int scanline, bool vblank, bool blanked) { if (scanline < ppu2c0x_device::BOTTOM_VISIBLE_SCANLINE) { diff --git a/src/devices/bus/nes/pirate.h b/src/devices/bus/nes/pirate.h index 55ce92a81be..9f7be76cc56 100644 --- a/src/devices/bus/nes/pirate.h +++ b/src/devices/bus/nes/pirate.h @@ -69,7 +69,7 @@ public: virtual void write_h(offs_t offset, u8 data) override; - virtual void hblank_irq(int scanline, int vblank, int blanked) override; + virtual void hblank_irq(int scanline, bool vblank, bool blanked) override; virtual void pcb_reset() override; protected: @@ -177,7 +177,7 @@ public: virtual void write_m(offs_t offset, u8 data) override; virtual void write_h(offs_t offset, u8 data) override; - virtual void hblank_irq(int scanline, int vblank, int blanked) override; + virtual void hblank_irq(int scanline, bool vblank, bool blanked) override; virtual void pcb_reset() override; protected: diff --git a/src/devices/bus/nes/sunsoft.cpp b/src/devices/bus/nes/sunsoft.cpp index 1a049a2aafd..ffe5aec9005 100644 --- a/src/devices/bus/nes/sunsoft.cpp +++ b/src/devices/bus/nes/sunsoft.cpp @@ -110,7 +110,7 @@ void nes_sunsoft_2_device::pcb_reset() void nes_sunsoft_3_device::device_start() { common_start(); - irq_timer = timer_alloc(TIMER_IRQ); + irq_timer = timer_alloc(FUNC(nes_sunsoft_3_device::irq_timer_tick), this); irq_timer->adjust(attotime::zero, 0, clocks_to_attotime(1)); save_item(NAME(m_irq_enable)); @@ -149,7 +149,7 @@ void nes_sunsoft_4_device::pcb_reset() void nes_sunsoft_fme7_device::device_start() { common_start(); - irq_timer = timer_alloc(TIMER_IRQ); + irq_timer = timer_alloc(FUNC(nes_sunsoft_fme7_device::irq_timer_tick), this); irq_timer->adjust(attotime::zero, 0, clocks_to_attotime(1)); save_item(NAME(m_wram_bank)); @@ -242,15 +242,12 @@ void nes_sunsoft_2_device::write_h(offs_t offset, uint8_t data) -------------------------------------------------*/ -void nes_sunsoft_3_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(nes_sunsoft_3_device::irq_timer_tick) { - if (id == TIMER_IRQ) + if (m_irq_enable && --m_irq_count == 0xffff) { - if (m_irq_enable && --m_irq_count == 0xffff) - { - set_irq_line(ASSERT_LINE); - m_irq_enable = 0; - } + set_irq_line(ASSERT_LINE); + m_irq_enable = 0; } } @@ -382,17 +379,14 @@ u8 nes_sunsoft_4_device::read_m(offs_t offset) -------------------------------------------------*/ -void nes_sunsoft_fme7_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(nes_sunsoft_fme7_device::irq_timer_tick) { - if (id == TIMER_IRQ) + if (BIT(m_irq_enable, 7)) // counter decrement enabled { - if (BIT(m_irq_enable, 7)) // counter decrement enabled + if (--m_irq_count == 0xffff) { - if (--m_irq_count == 0xffff) - { - if (BIT(m_irq_enable, 0)) // IRQs enabled - set_irq_line(ASSERT_LINE); - } + if (BIT(m_irq_enable, 0)) // IRQs enabled + set_irq_line(ASSERT_LINE); } } } diff --git a/src/devices/bus/nes/sunsoft.h b/src/devices/bus/nes/sunsoft.h index ebbb8048e83..000150922c7 100644 --- a/src/devices/bus/nes/sunsoft.h +++ b/src/devices/bus/nes/sunsoft.h @@ -52,13 +52,13 @@ 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(irq_timer_tick); private: uint16_t m_irq_count; int m_irq_enable, m_irq_toggle; - static const device_timer_id TIMER_IRQ = 0; emu_timer *irq_timer; }; @@ -113,13 +113,13 @@ 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(irq_timer_tick); private: uint16_t m_irq_count; int m_irq_enable; - static const device_timer_id TIMER_IRQ = 0; emu_timer *irq_timer; uint8_t m_latch; diff --git a/src/devices/bus/nes/sunsoft_dcs.cpp b/src/devices/bus/nes/sunsoft_dcs.cpp index e107c26b9d4..7f291e741ed 100644 --- a/src/devices/bus/nes/sunsoft_dcs.cpp +++ b/src/devices/bus/nes/sunsoft_dcs.cpp @@ -168,7 +168,7 @@ void nes_sunsoft_dcs_device::device_start() { nes_sunsoft_4_device::device_start(); - ntb_enable_timer = timer_alloc(TIMER_PROTECT); + ntb_enable_timer = timer_alloc(FUNC(nes_sunsoft_dcs_device::protect_tick), this); ntb_enable_timer->reset(); timer_freq = clocks_to_attotime(107520); @@ -281,14 +281,11 @@ void nes_sunsoft_dcs_device::device_add_mconfig(machine_config &config) //------------------------------------------------- -// device_timer - handler timer events +// protect_tick - handler NTB-ROM timer elapsing //------------------------------------------------- -void nes_sunsoft_dcs_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(nes_sunsoft_dcs_device::protect_tick) { - if (id == TIMER_PROTECT) - { - m_timer_on = 0; - ntb_enable_timer->reset(); - } + m_timer_on = 0; + ntb_enable_timer->reset(); } diff --git a/src/devices/bus/nes/sunsoft_dcs.h b/src/devices/bus/nes/sunsoft_dcs.h index 983b5a97b06..e9f6594a452 100644 --- a/src/devices/bus/nes/sunsoft_dcs.h +++ b/src/devices/bus/nes/sunsoft_dcs.h @@ -137,13 +137,11 @@ public: protected: // device-level overrides virtual void device_start() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; - virtual void device_add_mconfig(machine_config &config) override; -private: - static constexpr device_timer_id TIMER_PROTECT = 0; + TIMER_CALLBACK_MEMBER(protect_tick); +private: int m_timer_on, m_exrom_enable; required_device<nes_ntb_slot_device> m_subslot; diff --git a/src/devices/bus/nes/taito.cpp b/src/devices/bus/nes/taito.cpp index 4a620a09283..a3689c8f4a7 100644 --- a/src/devices/bus/nes/taito.cpp +++ b/src/devices/bus/nes/taito.cpp @@ -120,7 +120,7 @@ void nes_x1_005_device::pcb_reset() void nes_x1_017_device::device_start() { common_start(); - irq_timer = timer_alloc(TIMER_IRQ); + irq_timer = timer_alloc(FUNC(nes_x1_017_device::irq_timer_tick), this); irq_timer->adjust(attotime::zero, 0, clocks_to_attotime(1)); save_item(NAME(m_irq_enable)); @@ -217,7 +217,7 @@ void nes_tc0190fmc_device::write_h(offs_t offset, u8 data) -------------------------------------------------*/ -void nes_tc0190fmc_pal16r4_device::hblank_irq(int scanline, int vblank, int blanked) +void nes_tc0190fmc_pal16r4_device::hblank_irq(int scanline, bool vblank, bool blanked) { if (scanline < ppu2c0x_device::BOTTOM_VISIBLE_SCANLINE) { @@ -359,15 +359,12 @@ u8 nes_x1_005_device::read_m(offs_t offset) -------------------------------------------------*/ -void nes_x1_017_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(nes_x1_017_device::irq_timer_tick) { - if (id == TIMER_IRQ) - { - if ((m_irq_enable & 0x05) == 1 && m_irq_count) // counting enabled? - m_irq_count--; - if (!m_irq_count && BIT(m_irq_enable, 1)) - set_irq_line(ASSERT_LINE); - } + if ((m_irq_enable & 0x05) == 1 && m_irq_count) // counting enabled? + m_irq_count--; + if (!m_irq_count && BIT(m_irq_enable, 1)) + set_irq_line(ASSERT_LINE); } void nes_x1_017_device::set_chr() diff --git a/src/devices/bus/nes/taito.h b/src/devices/bus/nes/taito.h index 9c01438f687..6f3981aa993 100644 --- a/src/devices/bus/nes/taito.h +++ b/src/devices/bus/nes/taito.h @@ -35,7 +35,7 @@ public: virtual void write_h(offs_t offset, u8 data) override; - virtual void hblank_irq(int scanline, int vblank, int blanked) override; + virtual void hblank_irq(int scanline, bool vblank, bool blanked) override; virtual void pcb_reset() override; protected: @@ -90,7 +90,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(irq_timer_tick); private: void set_chr(); @@ -104,7 +105,6 @@ private: u8 m_irq_count_latch; u8 m_irq_enable; - static constexpr device_timer_id TIMER_IRQ = 0; emu_timer *irq_timer; }; diff --git a/src/devices/bus/nes/tengen.cpp b/src/devices/bus/nes/tengen.cpp index 5281d1e2fb2..3b74a13f2cd 100644 --- a/src/devices/bus/nes/tengen.cpp +++ b/src/devices/bus/nes/tengen.cpp @@ -60,7 +60,7 @@ nes_tengen037_device::nes_tengen037_device(const machine_config &mconfig, const void nes_tengen032_device::device_start() { common_start(); - irq_timer = timer_alloc(TIMER_IRQ); + irq_timer = timer_alloc(FUNC(nes_tengen032_device::irq_timer_tick), this); timer_freq = clocks_to_attotime(4); irq_timer->adjust(attotime::zero, 0, timer_freq); @@ -146,23 +146,20 @@ inline void nes_tengen032_device::irq_clock(int blanked) // we use the HBLANK IRQ latch from PPU for the scanline based IRQ mode // and a timer for the cycle based IRQ mode, which both call irq_clock -void nes_tengen032_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(nes_tengen032_device::irq_timer_tick) { - if (id == TIMER_IRQ) + if (m_irq_pending) { - if (m_irq_pending) - { - set_irq_line(ASSERT_LINE); - m_irq_pending = 0; - } - - if (m_irq_mode) - irq_clock(0); + set_irq_line(ASSERT_LINE); + m_irq_pending = 0; } + + if (m_irq_mode) + irq_clock(0); } -void nes_tengen032_device::hblank_irq(int scanline, int vblank, int blanked) +void nes_tengen032_device::hblank_irq(int scanline, bool vblank, bool blanked) { if (!m_irq_mode) // we are in scanline mode! { diff --git a/src/devices/bus/nes/tengen.h b/src/devices/bus/nes/tengen.h index 6c2af124841..d5dbec1e88b 100644 --- a/src/devices/bus/nes/tengen.h +++ b/src/devices/bus/nes/tengen.h @@ -16,7 +16,7 @@ public: virtual void write_h(offs_t offset, u8 data) override; - virtual void hblank_irq(int scanline, int vblank, int blanked) override; + virtual void hblank_irq(int scanline, bool vblank, bool blanked) override; virtual void pcb_reset() override; protected: @@ -24,10 +24,11 @@ protected: // device-level overrides virtual void device_start() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; virtual void set_chr(); + TIMER_CALLBACK_MEMBER(irq_timer_tick); + u8 m_latch; u8 m_mmc_vrom_bank[8]; @@ -41,7 +42,6 @@ private: u8 m_mmc_prg_bank[3]; - static constexpr device_timer_id TIMER_IRQ = 0; emu_timer *irq_timer; attotime timer_freq; }; diff --git a/src/devices/bus/nes/vrc_clones.cpp b/src/devices/bus/nes/vrc_clones.cpp index c29ba0e588d..506857df85f 100644 --- a/src/devices/bus/nes/vrc_clones.cpp +++ b/src/devices/bus/nes/vrc_clones.cpp @@ -140,7 +140,7 @@ void nes_2yudb_device::pcb_reset() void nes_900218_device::device_start() { nes_konami_vrc2_device::device_start(); - irq_timer = timer_alloc(TIMER_IRQ); + irq_timer = timer_alloc(FUNC(nes_900218_device::irq_timer_tick), this); irq_timer->adjust(attotime::zero, 0, clocks_to_attotime(1)); save_item(NAME(m_irq_enable)); @@ -268,7 +268,7 @@ void nes_tf1201_device::device_start() void nes_th21311_device::device_start() { nes_konami_vrc2_device::device_start(); - irq_timer = timer_alloc(TIMER_IRQ); + irq_timer = timer_alloc(FUNC(nes_th21311_device::irq_timer_tick), this); irq_timer->adjust(attotime::zero, 0, clocks_to_attotime(1)); save_item(NAME(m_irq_enable)); @@ -322,15 +322,12 @@ void nes_waixing_sgz_device::device_start() -------------------------------------------------*/ -void nes_900218_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(nes_900218_device::irq_timer_tick) { - if (id == TIMER_IRQ) + if (m_irq_enable) { - if (m_irq_enable) - { - m_irq_count++; - set_irq_line(BIT(m_irq_count, 10) ? ASSERT_LINE : CLEAR_LINE); - } + m_irq_count++; + set_irq_line(BIT(m_irq_count, 10) ? ASSERT_LINE : CLEAR_LINE); } } @@ -580,18 +577,15 @@ void nes_tf1201_device::irq_ack_w() -------------------------------------------------*/ -void nes_th21311_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(nes_th21311_device::irq_timer_tick) { - if (id == TIMER_IRQ) + if (m_irq_enable) { - if (m_irq_enable) - { - m_irq_count = (m_irq_count + 1) & 0xfff; // 12-bit counter - if (m_irq_count == 0x800) - m_irq_latch--; - if (!m_irq_latch && m_irq_count < 0x800) - set_irq_line(ASSERT_LINE); - } + m_irq_count = (m_irq_count + 1) & 0xfff; // 12-bit counter + if (m_irq_count == 0x800) + m_irq_latch--; + if (!m_irq_latch && m_irq_count < 0x800) + set_irq_line(ASSERT_LINE); } } diff --git a/src/devices/bus/nes/vrc_clones.h b/src/devices/bus/nes/vrc_clones.h index 856e9b34503..c6fe5b55550 100644 --- a/src/devices/bus/nes/vrc_clones.h +++ b/src/devices/bus/nes/vrc_clones.h @@ -46,13 +46,13 @@ 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(irq_timer_tick); private: u16 m_irq_count; int m_irq_enable; - static const device_timer_id TIMER_IRQ = 0; emu_timer *irq_timer; }; @@ -246,14 +246,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; + + TIMER_CALLBACK_MEMBER(irq_timer_tick); private: u16 m_irq_count; u8 m_irq_latch; int m_irq_enable; - static const device_timer_id TIMER_IRQ = 0; emu_timer *irq_timer; }; diff --git a/src/devices/bus/nes_ctrl/bcbattle.cpp b/src/devices/bus/nes_ctrl/bcbattle.cpp index 7d97236b6e4..26973cfc51c 100644 --- a/src/devices/bus/nes_ctrl/bcbattle.cpp +++ b/src/devices/bus/nes_ctrl/bcbattle.cpp @@ -27,47 +27,44 @@ void nes_bcbattle_device::device_add_mconfig(machine_config &config) //------------------------------------------------- -// device_timer - handler timer events +// scan_tick - periodic scan kludge //------------------------------------------------- // This part is the hacky replacement for the real Barcode unit [shared with SNES implementation]: // code periodically checks whether a new code has been scanned and it moves it to the // m_current_barcode array -void nes_bcbattle_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(nes_bcbattle_device::scan_tick) { - if (id == TIMER_BATTLER) + int old = m_new_code; + // has something new been scanned? + if (old < m_reader->get_pending_code()) { - int old = m_new_code; - // has something new been scanned? - if (old < m_reader->get_pending_code()) + if (m_reader->get_byte_length() == 13) { - if (m_reader->get_byte_length() == 13) - { - for (int i = 0; i < 13; i++) - m_current_barcode[i] = m_reader->read_code() + '0'; - } - else if (m_reader->get_byte_length() == 8) - { - for (int i = 0; i < 5; i++) - m_current_barcode[i] = 0x20; - for (int i = 5; i < 13; i++) - m_current_barcode[i] = m_reader->read_code() + '0'; - } - // read one more, to reset the internal byte counter - m_reader->read_code(); - - // the string "SUNSOFT" is accepted as well by Barcode World - m_current_barcode[13] = 'E'; - m_current_barcode[14] = 'P'; - m_current_barcode[15] = 'O'; - m_current_barcode[16] = 'C'; - m_current_barcode[17] = 'H'; - m_current_barcode[18] = 0x0d; - m_current_barcode[19] = 0x0a; - m_pending_code = 1; + for (int i = 0; i < 13; i++) + m_current_barcode[i] = m_reader->read_code() + '0'; + } + else if (m_reader->get_byte_length() == 8) + { + for (int i = 0; i < 5; i++) + m_current_barcode[i] = 0x20; + for (int i = 5; i < 13; i++) + m_current_barcode[i] = m_reader->read_code() + '0'; } - m_new_code = m_reader->get_pending_code(); + // read one more, to reset the internal byte counter + m_reader->read_code(); + + // the string "SUNSOFT" is accepted as well by Barcode World + m_current_barcode[13] = 'E'; + m_current_barcode[14] = 'P'; + m_current_barcode[15] = 'O'; + m_current_barcode[16] = 'C'; + m_current_barcode[17] = 'H'; + m_current_barcode[18] = 0x0d; + m_current_barcode[19] = 0x0a; + m_pending_code = 1; } + m_new_code = m_reader->get_pending_code(); } //************************************************************************** @@ -96,7 +93,7 @@ void nes_bcbattle_device::device_start() // lacking emulation of the standalone Barcode Battler, we refresh periodically the input from the reader // proper emulation would have the standalone unit acknowledging that a new barcode has been scanned // and sending the proper serial bits, instead of our read_current_bit() function! - battler_timer = timer_alloc(TIMER_BATTLER); + battler_timer = timer_alloc(FUNC(nes_bcbattle_device::scan_tick), this); battler_timer->adjust(attotime::zero, 0, machine().device<cpu_device>("maincpu")->cycles_to_attotime(1000)); save_item(NAME(m_current_barcode)); diff --git a/src/devices/bus/nes_ctrl/bcbattle.h b/src/devices/bus/nes_ctrl/bcbattle.h index cc4827477cb..c51f2db64ac 100644 --- a/src/devices/bus/nes_ctrl/bcbattle.h +++ b/src/devices/bus/nes_ctrl/bcbattle.h @@ -31,17 +31,16 @@ public: virtual uint8_t read_exp(offs_t offset) override; protected: - static constexpr device_timer_id TIMER_BATTLER = 1; - // device-level overrides virtual void device_start() override; virtual void device_reset() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; virtual void device_add_mconfig(machine_config &config) override; int read_current_bit(); + TIMER_CALLBACK_MEMBER(scan_tick); + required_device<barcode_reader_device> m_reader; uint8_t m_current_barcode[20]; int m_pending_code, m_new_code, m_transmitting, m_cur_bit, m_cur_byte; diff --git a/src/devices/bus/nes_ctrl/miracle.cpp b/src/devices/bus/nes_ctrl/miracle.cpp index ae5aa437de3..4945358c028 100644 --- a/src/devices/bus/nes_ctrl/miracle.cpp +++ b/src/devices/bus/nes_ctrl/miracle.cpp @@ -31,15 +31,12 @@ void nes_miracle_device::device_add_mconfig(machine_config &config) //------------------------------------------------- -// device_timer - handler timer events +// strobe_tick - increment strobe counter //------------------------------------------------- -void nes_miracle_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(nes_miracle_device::strobe_tick) { - if (id == TIMER_STROBE_ON) - { - m_strobe_clock++; - } + m_strobe_clock++; } //************************************************************************** @@ -67,7 +64,7 @@ nes_miracle_device::nes_miracle_device(const machine_config &mconfig, const char void nes_miracle_device::device_start() { - strobe_timer = timer_alloc(TIMER_STROBE_ON); + strobe_timer = timer_alloc(FUNC(nes_miracle_device::strobe_tick), this); strobe_timer->adjust(attotime::never); save_item(NAME(m_strobe_on)); save_item(NAME(m_sent_bits)); diff --git a/src/devices/bus/nes_ctrl/miracle.h b/src/devices/bus/nes_ctrl/miracle.h index 168590b4b19..f06480d9a43 100644 --- a/src/devices/bus/nes_ctrl/miracle.h +++ b/src/devices/bus/nes_ctrl/miracle.h @@ -38,15 +38,14 @@ public: protected: static constexpr int XMIT_RING_SIZE = 64; static constexpr int RECV_RING_SIZE = 64; - static constexpr device_timer_id TIMER_STROBE_ON = 0; // device-level overrides virtual void device_start() override; virtual void device_reset() override; - - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; virtual void device_add_mconfig(machine_config &config) override; + TIMER_CALLBACK_MEMBER(strobe_tick); + private: // serial overrides virtual void rcv_complete() override; // Rx completed receiving byte diff --git a/src/devices/bus/nubus/nubus_48gc.cpp b/src/devices/bus/nubus/nubus_48gc.cpp index a79350687df..b9f6801e3cf 100644 --- a/src/devices/bus/nubus/nubus_48gc.cpp +++ b/src/devices/bus/nubus/nubus_48gc.cpp @@ -114,7 +114,7 @@ void jmfb_device::device_start() nubus().install_device(slotspace+0x200000, slotspace+0x2003ff, read32s_delegate(*this, FUNC(jmfb_device::mac_48gc_r)), write32s_delegate(*this, FUNC(jmfb_device::mac_48gc_w))); - m_timer = timer_alloc(0); + m_timer = timer_alloc(FUNC(jmfb_device::vbl_tick), this); m_screen = nullptr; // can we look this up now? } @@ -143,7 +143,7 @@ void jmfb_device::device_reset() ***************************************************************************/ -void jmfb_device::device_timer(emu_timer &timer, device_timer_id tid, int param) +TIMER_CALLBACK_MEMBER(jmfb_device::vbl_tick) { if (!m_vbl_disable) { diff --git a/src/devices/bus/nubus/nubus_48gc.h b/src/devices/bus/nubus/nubus_48gc.h index f25c89af939..fc3cc59e8f4 100644 --- a/src/devices/bus/nubus/nubus_48gc.h +++ b/src/devices/bus/nubus/nubus_48gc.h @@ -25,12 +25,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 void device_add_mconfig(machine_config &config) override; virtual const tiny_rom_entry *device_rom_region() const override; + TIMER_CALLBACK_MEMBER(vbl_tick); + private: uint32_t mac_48gc_r(offs_t offset, uint32_t mem_mask = ~0); void mac_48gc_w(offs_t offset, uint32_t data, uint32_t mem_mask = ~0); diff --git a/src/devices/bus/nubus/nubus_m2hires.cpp b/src/devices/bus/nubus/nubus_m2hires.cpp index 033d443610a..7c590595f3a 100644 --- a/src/devices/bus/nubus/nubus_m2hires.cpp +++ b/src/devices/bus/nubus/nubus_m2hires.cpp @@ -97,7 +97,7 @@ void nubus_m2hires_device::device_start() nubus().install_device(slotspace+0x900000, slotspace+VRAM_SIZE-1+0x900000, read32s_delegate(*this, FUNC(nubus_m2hires_device::vram_r)), write32s_delegate(*this, FUNC(nubus_m2hires_device::vram_w))); nubus().install_device(slotspace+0x80000, slotspace+0xeffff, read32s_delegate(*this, FUNC(nubus_m2hires_device::m2hires_r)), write32s_delegate(*this, FUNC(nubus_m2hires_device::m2hires_w))); - m_timer = timer_alloc(0); + m_timer = timer_alloc(FUNC(nubus_m2hires_device::vbl_tick), this); m_timer->adjust(screen().time_until_pos(479, 0), 0); } @@ -119,7 +119,7 @@ void nubus_m2hires_device::device_reset() } -void nubus_m2hires_device::device_timer(emu_timer &timer, device_timer_id tid, int param) +TIMER_CALLBACK_MEMBER(nubus_m2hires_device::vbl_tick) { if (!m_vbl_disable) { diff --git a/src/devices/bus/nubus/nubus_m2hires.h b/src/devices/bus/nubus/nubus_m2hires.h index 773ccccbe35..43870794dfb 100644 --- a/src/devices/bus/nubus/nubus_m2hires.h +++ b/src/devices/bus/nubus/nubus_m2hires.h @@ -28,12 +28,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 void device_add_mconfig(machine_config &config) override; virtual const tiny_rom_entry *device_rom_region() const override; + TIMER_CALLBACK_MEMBER(vbl_tick); + private: uint32_t m2hires_r(offs_t offset, uint32_t mem_mask = ~0); void m2hires_w(offs_t offset, uint32_t data, uint32_t mem_mask = ~0); diff --git a/src/devices/bus/nubus/nubus_m2video.cpp b/src/devices/bus/nubus/nubus_m2video.cpp index 2ca21d0baee..55bc936f4d2 100644 --- a/src/devices/bus/nubus/nubus_m2video.cpp +++ b/src/devices/bus/nubus/nubus_m2video.cpp @@ -99,7 +99,7 @@ void nubus_m2video_device::device_start() nubus().install_device(slotspace+0x900000, slotspace+VRAM_SIZE-1+0x900000, read32s_delegate(*this, FUNC(nubus_m2video_device::vram_r)), write32s_delegate(*this, FUNC(nubus_m2video_device::vram_w))); nubus().install_device(slotspace+0x80000, slotspace+0xeffff, read32s_delegate(*this, FUNC(nubus_m2video_device::m2video_r)), write32s_delegate(*this, FUNC(nubus_m2video_device::m2video_w))); - m_timer = timer_alloc(0); + m_timer = timer_alloc(FUNC(nubus_m2video_device::vbl_tick), this); m_timer->adjust(screen().time_until_pos(479, 0), 0); } @@ -121,7 +121,7 @@ void nubus_m2video_device::device_reset() } -void nubus_m2video_device::device_timer(emu_timer &timer, device_timer_id tid, int param) +TIMER_CALLBACK_MEMBER(nubus_m2video_device::vbl_tick) { if (!m_vbl_disable) { diff --git a/src/devices/bus/nubus/nubus_m2video.h b/src/devices/bus/nubus/nubus_m2video.h index 65dfd42ed54..38467dbe75d 100644 --- a/src/devices/bus/nubus/nubus_m2video.h +++ b/src/devices/bus/nubus/nubus_m2video.h @@ -28,12 +28,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 void device_add_mconfig(machine_config &config) override; virtual const tiny_rom_entry *device_rom_region() const override; + TIMER_CALLBACK_MEMBER(vbl_tick); + private: uint32_t m2video_r(offs_t offset, uint32_t mem_mask = ~0); void m2video_w(offs_t offset, uint32_t data, uint32_t mem_mask = ~0); diff --git a/src/devices/bus/nubus/nubus_radiustpd.cpp b/src/devices/bus/nubus/nubus_radiustpd.cpp index 0017a33e2f5..f2f68f4bb8c 100644 --- a/src/devices/bus/nubus/nubus_radiustpd.cpp +++ b/src/devices/bus/nubus/nubus_radiustpd.cpp @@ -99,7 +99,7 @@ void nubus_radiustpd_device::device_start() nubus().install_device(slotspace+0x80000, slotspace+0xeffff, read32s_delegate(*this, FUNC(nubus_radiustpd_device::radiustpd_r)), write32s_delegate(*this, FUNC(nubus_radiustpd_device::radiustpd_w))); nubus().install_device(slotspace+0x980000, slotspace+0x9effff, read32s_delegate(*this, FUNC(nubus_radiustpd_device::radiustpd_r)), write32s_delegate(*this, FUNC(nubus_radiustpd_device::radiustpd_w))); - m_timer = timer_alloc(0); + m_timer = timer_alloc(FUNC(nubus_radiustpd_device::vbl_tick), this); m_timer->adjust(screen().time_until_pos(479, 0), 0); } @@ -121,7 +121,7 @@ void nubus_radiustpd_device::device_reset() } -void nubus_radiustpd_device::device_timer(emu_timer &timer, device_timer_id tid, int param) +TIMER_CALLBACK_MEMBER(nubus_radiustpd_device::vbl_tick) { if (!m_vbl_disable) { diff --git a/src/devices/bus/nubus/nubus_radiustpd.h b/src/devices/bus/nubus/nubus_radiustpd.h index a1f0b0e9723..ef8d8fac1eb 100644 --- a/src/devices/bus/nubus/nubus_radiustpd.h +++ b/src/devices/bus/nubus/nubus_radiustpd.h @@ -28,12 +28,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 void device_add_mconfig(machine_config &config) override; virtual const tiny_rom_entry *device_rom_region() const override; + TIMER_CALLBACK_MEMBER(vbl_tick); + private: uint32_t radiustpd_r(offs_t offset, uint32_t mem_mask = ~0); void radiustpd_w(offs_t offset, uint32_t data, uint32_t mem_mask = ~0); diff --git a/src/devices/bus/nubus/nubus_spec8.cpp b/src/devices/bus/nubus/nubus_spec8.cpp index 0a71dd847f7..3cbe4062578 100644 --- a/src/devices/bus/nubus/nubus_spec8.cpp +++ b/src/devices/bus/nubus/nubus_spec8.cpp @@ -101,7 +101,7 @@ void nubus_spec8s3_device::device_start() nubus().install_device(slotspace+0x900000, slotspace+VRAM_SIZE-1+0x900000, read32s_delegate(*this, FUNC(nubus_spec8s3_device::vram_r)), write32s_delegate(*this, FUNC(nubus_spec8s3_device::vram_w))); nubus().install_device(slotspace+0xd0000, slotspace+0xfffff, read32s_delegate(*this, FUNC(nubus_spec8s3_device::spec8s3_r)), write32s_delegate(*this, FUNC(nubus_spec8s3_device::spec8s3_w))); - m_timer = timer_alloc(0); + m_timer = timer_alloc(FUNC(nubus_spec8s3_device::vbl_tick), this); m_timer->adjust(screen().time_until_pos(767, 0), 0); } @@ -125,7 +125,7 @@ void nubus_spec8s3_device::device_reset() } -void nubus_spec8s3_device::device_timer(emu_timer &timer, device_timer_id tid, int param) +TIMER_CALLBACK_MEMBER(nubus_spec8s3_device::vbl_tick) { if (!m_vbl_disable) { diff --git a/src/devices/bus/nubus/nubus_spec8.h b/src/devices/bus/nubus/nubus_spec8.h index 88da09528e4..caf0a0ef60b 100644 --- a/src/devices/bus/nubus/nubus_spec8.h +++ b/src/devices/bus/nubus/nubus_spec8.h @@ -32,7 +32,8 @@ protected: // optional information overrides virtual void device_add_mconfig(machine_config &config) 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; + + TIMER_CALLBACK_MEMBER(vbl_tick); private: uint32_t spec8s3_r(offs_t offset, uint32_t mem_mask = ~0); diff --git a/src/devices/bus/nubus/nubus_specpdq.cpp b/src/devices/bus/nubus/nubus_specpdq.cpp index cd3977022be..9f878e1b85a 100644 --- a/src/devices/bus/nubus/nubus_specpdq.cpp +++ b/src/devices/bus/nubus/nubus_specpdq.cpp @@ -117,7 +117,7 @@ void nubus_specpdq_device::device_start() nubus().install_device(slotspace, slotspace+VRAM_SIZE-1, read32s_delegate(*this, FUNC(nubus_specpdq_device::vram_r)), write32s_delegate(*this, FUNC(nubus_specpdq_device::vram_w))); nubus().install_device(slotspace+0x400000, slotspace+0xfbffff, read32s_delegate(*this, FUNC(nubus_specpdq_device::specpdq_r)), write32s_delegate(*this, FUNC(nubus_specpdq_device::specpdq_w))); - m_timer = timer_alloc(0); + m_timer = timer_alloc(FUNC(nubus_specpdq_device::vbl_tick), this); m_timer->adjust(screen().time_until_pos(843, 0), 0); } @@ -139,7 +139,7 @@ void nubus_specpdq_device::device_reset() } -void nubus_specpdq_device::device_timer(emu_timer &timer, device_timer_id tid, int param) +TIMER_CALLBACK_MEMBER(nubus_specpdq_device::vbl_tick) { if (!m_vbl_disable) { diff --git a/src/devices/bus/nubus/nubus_specpdq.h b/src/devices/bus/nubus/nubus_specpdq.h index fd30e112525..c133c0fa4db 100644 --- a/src/devices/bus/nubus/nubus_specpdq.h +++ b/src/devices/bus/nubus/nubus_specpdq.h @@ -33,7 +33,8 @@ protected: // optional information overrides virtual void device_add_mconfig(machine_config &config) 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; + + TIMER_CALLBACK_MEMBER(vbl_tick); private: uint32_t specpdq_r(offs_t offset, uint32_t mem_mask = ~0); diff --git a/src/devices/bus/nubus/nubus_wsportrait.cpp b/src/devices/bus/nubus/nubus_wsportrait.cpp index 960db9199ae..cbbaed619c8 100644 --- a/src/devices/bus/nubus/nubus_wsportrait.cpp +++ b/src/devices/bus/nubus/nubus_wsportrait.cpp @@ -100,7 +100,7 @@ void nubus_wsportrait_device::device_start() nubus().install_device(slotspace+0x900000, slotspace+0x900000+VRAM_SIZE-1, read32s_delegate(*this, FUNC(nubus_wsportrait_device::vram_r)), write32s_delegate(*this, FUNC(nubus_wsportrait_device::vram_w))); nubus().install_device(slotspace+0x80000, slotspace+0xeffff, read32s_delegate(*this, FUNC(nubus_wsportrait_device::wsportrait_r)), write32s_delegate(*this, FUNC(nubus_wsportrait_device::wsportrait_w))); - m_timer = timer_alloc(0); + m_timer = timer_alloc(FUNC(nubus_wsportrait_device::vbl_tick), this); m_timer->adjust(screen().time_until_pos(869, 0), 0); } @@ -119,7 +119,7 @@ void nubus_wsportrait_device::device_reset() } -void nubus_wsportrait_device::device_timer(emu_timer &timer, device_timer_id tid, int param) +TIMER_CALLBACK_MEMBER(nubus_wsportrait_device::vbl_tick) { if (!m_vbl_disable) { diff --git a/src/devices/bus/nubus/nubus_wsportrait.h b/src/devices/bus/nubus/nubus_wsportrait.h index 0aa0aa67072..afbb7abdd67 100644 --- a/src/devices/bus/nubus/nubus_wsportrait.h +++ b/src/devices/bus/nubus/nubus_wsportrait.h @@ -28,12 +28,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 void device_add_mconfig(machine_config &config) override; virtual const tiny_rom_entry *device_rom_region() const override; + TIMER_CALLBACK_MEMBER(vbl_tick); + private: uint32_t wsportrait_r(offs_t offset, uint32_t mem_mask = ~0); void wsportrait_w(offs_t offset, uint32_t data, uint32_t mem_mask = ~0); diff --git a/src/devices/bus/nubus/pds30_30hr.cpp b/src/devices/bus/nubus/pds30_30hr.cpp index f2439b56152..efbc761d4af 100644 --- a/src/devices/bus/nubus/pds30_30hr.cpp +++ b/src/devices/bus/nubus/pds30_30hr.cpp @@ -99,7 +99,7 @@ void nubus_xceed30hr_device::device_start() nubus().install_device(slotspace, slotspace+VRAM_SIZE-1, read32s_delegate(*this, FUNC(nubus_xceed30hr_device::vram_r)), write32s_delegate(*this, FUNC(nubus_xceed30hr_device::vram_w))); nubus().install_device(slotspace+0x800000, slotspace+0xefffff, read32s_delegate(*this, FUNC(nubus_xceed30hr_device::xceed30hr_r)), write32s_delegate(*this, FUNC(nubus_xceed30hr_device::xceed30hr_w))); - m_timer = timer_alloc(0); + m_timer = timer_alloc(FUNC(nubus_xceed30hr_device::vbl_tick), this); m_timer->adjust(screen().time_until_pos(479, 0), 0); } @@ -121,7 +121,7 @@ void nubus_xceed30hr_device::device_reset() } -void nubus_xceed30hr_device::device_timer(emu_timer &timer, device_timer_id tid, int param) +TIMER_CALLBACK_MEMBER(nubus_xceed30hr_device::vbl_tick) { if (!m_vbl_disable) { diff --git a/src/devices/bus/nubus/pds30_30hr.h b/src/devices/bus/nubus/pds30_30hr.h index 39d47215d5c..f3592acdb1c 100644 --- a/src/devices/bus/nubus/pds30_30hr.h +++ b/src/devices/bus/nubus/pds30_30hr.h @@ -28,12 +28,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 void device_add_mconfig(machine_config &config) override; virtual const tiny_rom_entry *device_rom_region() const override; + TIMER_CALLBACK_MEMBER(vbl_tick); + private: uint32_t xceed30hr_r(offs_t offset, uint32_t mem_mask = ~0); void xceed30hr_w(offs_t offset, uint32_t data, uint32_t mem_mask = ~0); diff --git a/src/devices/bus/nubus/pds30_cb264.cpp b/src/devices/bus/nubus/pds30_cb264.cpp index b3f09219093..ce7a2f7372e 100644 --- a/src/devices/bus/nubus/pds30_cb264.cpp +++ b/src/devices/bus/nubus/pds30_cb264.cpp @@ -96,7 +96,7 @@ void nubus_cb264se30_device::device_start() nubus().install_device(slotspace, slotspace+VRAM_SIZE-1, read32s_delegate(*this, FUNC(nubus_cb264se30_device::vram_r)), write32s_delegate(*this, FUNC(nubus_cb264se30_device::vram_w))); nubus().install_device(slotspace+0xf00000, slotspace+0xfeffff, read32s_delegate(*this, FUNC(nubus_cb264se30_device::cb264se30_r)), write32s_delegate(*this, FUNC(nubus_cb264se30_device::cb264se30_w))); - m_timer = timer_alloc(0); + m_timer = timer_alloc(FUNC(nubus_cb264se30_device::vbl_tick), this); m_timer->adjust(screen().time_until_pos(479, 0), 0); } @@ -118,7 +118,7 @@ void nubus_cb264se30_device::device_reset() } -void nubus_cb264se30_device::device_timer(emu_timer &timer, device_timer_id tid, int param) +TIMER_CALLBACK_MEMBER(nubus_cb264se30_device::vbl_tick) { if (!m_vbl_disable) { diff --git a/src/devices/bus/nubus/pds30_cb264.h b/src/devices/bus/nubus/pds30_cb264.h index 275c652562f..9c94a6afc1c 100644 --- a/src/devices/bus/nubus/pds30_cb264.h +++ b/src/devices/bus/nubus/pds30_cb264.h @@ -28,12 +28,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 void device_add_mconfig(machine_config &config) override; virtual const tiny_rom_entry *device_rom_region() const override; + TIMER_CALLBACK_MEMBER(vbl_tick); + private: uint32_t cb264se30_r(offs_t offset, uint32_t mem_mask = ~0); void cb264se30_w(offs_t offset, uint32_t data, uint32_t mem_mask = ~0); diff --git a/src/devices/bus/nubus/pds30_mc30.cpp b/src/devices/bus/nubus/pds30_mc30.cpp index b0d36996a09..ede7240cc9a 100644 --- a/src/devices/bus/nubus/pds30_mc30.cpp +++ b/src/devices/bus/nubus/pds30_mc30.cpp @@ -98,7 +98,7 @@ void nubus_xceedmc30_device::device_start() nubus().install_device(slotspace, slotspace+VRAM_SIZE-1, read32s_delegate(*this, FUNC(nubus_xceedmc30_device::vram_r)), write32s_delegate(*this, FUNC(nubus_xceedmc30_device::vram_w))); nubus().install_device(slotspace+0x800000, slotspace+0xefffff, read32s_delegate(*this, FUNC(nubus_xceedmc30_device::xceedmc30_r)), write32s_delegate(*this, FUNC(nubus_xceedmc30_device::xceedmc30_w))); - m_timer = timer_alloc(0); + m_timer = timer_alloc(FUNC(nubus_xceedmc30_device::vbl_tick), this); m_timer->adjust(screen().time_until_pos(479, 0), 0); } @@ -120,7 +120,7 @@ void nubus_xceedmc30_device::device_reset() } -void nubus_xceedmc30_device::device_timer(emu_timer &timer, device_timer_id tid, int param) +TIMER_CALLBACK_MEMBER(nubus_xceedmc30_device::vbl_tick) { if (!m_vbl_disable) { diff --git a/src/devices/bus/nubus/pds30_mc30.h b/src/devices/bus/nubus/pds30_mc30.h index 29d13b5e671..518f863667a 100644 --- a/src/devices/bus/nubus/pds30_mc30.h +++ b/src/devices/bus/nubus/pds30_mc30.h @@ -28,12 +28,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 void device_add_mconfig(machine_config &config) override; virtual const tiny_rom_entry *device_rom_region() const override; + TIMER_CALLBACK_MEMBER(vbl_tick); + private: uint32_t xceedmc30_r(offs_t offset, uint32_t mem_mask = ~0); void xceedmc30_w(offs_t offset, uint32_t data, uint32_t mem_mask = ~0); diff --git a/src/devices/bus/nubus/pds30_procolor816.cpp b/src/devices/bus/nubus/pds30_procolor816.cpp index bfa655c9dbd..14fc289ec0f 100644 --- a/src/devices/bus/nubus/pds30_procolor816.cpp +++ b/src/devices/bus/nubus/pds30_procolor816.cpp @@ -99,7 +99,7 @@ void nubus_procolor816_device::device_start() nubus().install_device(slotspace+0x900000, slotspace+VRAM_SIZE-1+0x900000, read32s_delegate(*this, FUNC(nubus_procolor816_device::vram_r)), write32s_delegate(*this, FUNC(nubus_procolor816_device::vram_w))); nubus().install_device(slotspace+0xf00000, slotspace+0xff7fff, read32s_delegate(*this, FUNC(nubus_procolor816_device::procolor816_r)), write32s_delegate(*this, FUNC(nubus_procolor816_device::procolor816_w))); - m_timer = timer_alloc(0); + m_timer = timer_alloc(FUNC(nubus_procolor816_device::vbl_tick), this); m_timer->adjust(screen().time_until_pos(479, 0), 0); } @@ -121,7 +121,7 @@ void nubus_procolor816_device::device_reset() } -void nubus_procolor816_device::device_timer(emu_timer &timer, device_timer_id tid, int param) +TIMER_CALLBACK_MEMBER(nubus_procolor816_device::vbl_tick) { if (!m_vbl_disable) { diff --git a/src/devices/bus/nubus/pds30_procolor816.h b/src/devices/bus/nubus/pds30_procolor816.h index 631b92957f2..c5b5ec5068b 100644 --- a/src/devices/bus/nubus/pds30_procolor816.h +++ b/src/devices/bus/nubus/pds30_procolor816.h @@ -28,12 +28,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 void device_add_mconfig(machine_config &config) override; virtual const tiny_rom_entry *device_rom_region() const override; + TIMER_CALLBACK_MEMBER(vbl_tick); + private: uint32_t procolor816_r(offs_t offset, uint32_t mem_mask = ~0); void procolor816_w(offs_t offset, uint32_t data, uint32_t mem_mask = ~0); diff --git a/src/devices/bus/nubus/pds30_sigmalview.cpp b/src/devices/bus/nubus/pds30_sigmalview.cpp index d13c164df1a..d116496d7ec 100644 --- a/src/devices/bus/nubus/pds30_sigmalview.cpp +++ b/src/devices/bus/nubus/pds30_sigmalview.cpp @@ -94,7 +94,7 @@ void nubus_lview_device::device_start() nubus().install_device(slotspace+0x900000, slotspace+VRAM_SIZE-1+0x900000, read32s_delegate(*this, FUNC(nubus_lview_device::vram_r)), write32s_delegate(*this, FUNC(nubus_lview_device::vram_w))); nubus().install_device(slotspace+0xb0000, slotspace+0xbffff, read32s_delegate(*this, FUNC(nubus_lview_device::lview_r)), write32s_delegate(*this, FUNC(nubus_lview_device::lview_w))); - m_timer = timer_alloc(0); + m_timer = timer_alloc(FUNC(nubus_lview_device::vbl_tick), this); m_timer->adjust(screen().time_until_pos(599, 0), 0); } @@ -114,7 +114,7 @@ void nubus_lview_device::device_reset() } -void nubus_lview_device::device_timer(emu_timer &timer, device_timer_id tid, int param) +TIMER_CALLBACK_MEMBER(nubus_lview_device::vbl_tick) { if (!m_vbl_disable) { diff --git a/src/devices/bus/nubus/pds30_sigmalview.h b/src/devices/bus/nubus/pds30_sigmalview.h index ca08a9d118a..677d59ee4c2 100644 --- a/src/devices/bus/nubus/pds30_sigmalview.h +++ b/src/devices/bus/nubus/pds30_sigmalview.h @@ -28,12 +28,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 void device_add_mconfig(machine_config &config) override; virtual const tiny_rom_entry *device_rom_region() const override; + TIMER_CALLBACK_MEMBER(vbl_tick); + private: uint32_t lview_r(offs_t offset, uint32_t mem_mask = ~0); void lview_w(offs_t offset, uint32_t data, uint32_t mem_mask = ~0); diff --git a/src/devices/bus/pc8801/pc8801_31.cpp b/src/devices/bus/pc8801/pc8801_31.cpp index 0a490076594..f979e59162b 100644 --- a/src/devices/bus/pc8801/pc8801_31.cpp +++ b/src/devices/bus/pc8801/pc8801_31.cpp @@ -82,7 +82,7 @@ void pc8801_31_device::device_resolve_objects() void pc8801_31_device::device_start() { - m_sel_off_timer = timer_alloc(0); + m_sel_off_timer = timer_alloc(FUNC(pc8801_31_device::select_off), this); save_item(NAME(m_clock_hb)); save_item(NAME(m_cddrive_enable)); @@ -102,14 +102,9 @@ void pc8801_31_device::device_reset() m_sel_off_timer->adjust(attotime::never); } -void pc8801_31_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(pc8801_31_device::select_off) { - switch(id) - { - case 0: - m_scsibus->ctrl_w(0, 0, nscsi_device::S_SEL); - break; - } + m_scsibus->ctrl_w(0, 0, nscsi_device::S_SEL); } diff --git a/src/devices/bus/pc8801/pc8801_31.h b/src/devices/bus/pc8801/pc8801_31.h index a08782df780..fd580002610 100644 --- a/src/devices/bus/pc8801/pc8801_31.h +++ b/src/devices/bus/pc8801/pc8801_31.h @@ -37,7 +37,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(select_off); private: required_device<nscsi_bus_device> m_scsibus; diff --git a/src/devices/bus/pc_joy/pc_joy_sw.cpp b/src/devices/bus/pc_joy/pc_joy_sw.cpp index 813f6972241..8c9b2c75d4b 100644 --- a/src/devices/bus/pc_joy/pc_joy_sw.cpp +++ b/src/devices/bus/pc_joy/pc_joy_sw.cpp @@ -24,7 +24,7 @@ pc_mssw_pad_device::pc_mssw_pad_device(const machine_config& mconfig, const char void pc_mssw_pad_device::device_start() { - m_timer = timer_alloc(); + m_timer = timer_alloc(FUNC(pc_mssw_pad_device::timer_tick), this); } void pc_mssw_pad_device::device_reset() @@ -35,7 +35,7 @@ void pc_mssw_pad_device::device_reset() m_timer->adjust(attotime::never, 0); } -void pc_mssw_pad_device::device_timer(emu_timer &timer, device_timer_id tid, int param) +TIMER_CALLBACK_MEMBER(pc_mssw_pad_device::timer_tick) { uint16_t pad_state = 0; // only multibit mode for now diff --git a/src/devices/bus/pc_joy/pc_joy_sw.h b/src/devices/bus/pc_joy/pc_joy_sw.h index 0d7aaa55605..5d83a10d0c1 100644 --- a/src/devices/bus/pc_joy/pc_joy_sw.h +++ b/src/devices/bus/pc_joy/pc_joy_sw.h @@ -19,7 +19,8 @@ public: protected: virtual void device_start() override; virtual void device_reset() override; - virtual void device_timer(emu_timer &timer, device_timer_id tid, int param) override; + + TIMER_CALLBACK_MEMBER(timer_tick); private: required_ioport m_btn1; diff --git a/src/devices/bus/pc_kbd/hle_mouse.cpp b/src/devices/bus/pc_kbd/hle_mouse.cpp index d56cfb3c92f..15ac7854d09 100644 --- a/src/devices/bus/pc_kbd/hle_mouse.cpp +++ b/src/devices/bus/pc_kbd/hle_mouse.cpp @@ -104,8 +104,8 @@ void hle_ps2_mouse_device::device_start() set_pc_kbdc_device(); - m_serial = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(hle_ps2_mouse_device::serial), this)); - m_sample = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(hle_ps2_mouse_device::sample), this)); + m_serial = timer_alloc(FUNC(hle_ps2_mouse_device::serial), this); + m_sample = timer_alloc(FUNC(hle_ps2_mouse_device::sample), this); } void hle_ps2_mouse_device::device_reset() diff --git a/src/devices/bus/pet/c2n.cpp b/src/devices/bus/pet/c2n.cpp index b89d42d9996..94f0dc4dca3 100644 --- a/src/devices/bus/pet/c2n.cpp +++ b/src/devices/bus/pet/c2n.cpp @@ -84,16 +84,16 @@ c1531_device::c1531_device(const machine_config &mconfig, const char *tag, devic void c2n_device::device_start() { // allocate timers - m_read_timer = timer_alloc(); + m_read_timer = timer_alloc(FUNC(c2n_device::read_tick), this); m_read_timer->adjust(attotime::from_hz(44100), 0, attotime::from_hz(44100)); } //------------------------------------------------- -// device_timer - handler timer events +// read_tick - periodically read the datasette //------------------------------------------------- -void c2n_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(c2n_device::read_tick) { if (m_motor) { diff --git a/src/devices/bus/pet/c2n.h b/src/devices/bus/pet/c2n.h index 8a8b04b4a42..86d8e5df288 100644 --- a/src/devices/bus/pet/c2n.h +++ b/src/devices/bus/pet/c2n.h @@ -35,7 +35,6 @@ 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 void device_add_mconfig(machine_config &config) override; @@ -46,6 +45,8 @@ protected: virtual int datassette_sense() override; virtual void datassette_motor(int state) override; + TIMER_CALLBACK_MEMBER(read_tick); + private: required_device<cassette_image_device> m_cassette; diff --git a/src/devices/bus/plus4/c1551.cpp b/src/devices/bus/plus4/c1551.cpp index 859912a5563..42bca7daa57 100644 --- a/src/devices/bus/plus4/c1551.cpp +++ b/src/devices/bus/plus4/c1551.cpp @@ -439,7 +439,7 @@ void c1551_device::device_start() m_leds.resolve(); // allocate timers - m_irq_timer = timer_alloc(); + m_irq_timer = timer_alloc(FUNC(c1551_device::irq_timer_tick), this); m_irq_timer->adjust(attotime::zero, CLEAR_LINE); // install image callbacks @@ -475,10 +475,10 @@ void c1551_device::device_reset() //------------------------------------------------- -// device_timer - handler timer events +// irq_timer_tick - update IRQ line state //------------------------------------------------- -void c1551_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(c1551_device::irq_timer_tick) { m_maincpu->set_input_line(M6502_IRQ_LINE, param); diff --git a/src/devices/bus/plus4/c1551.h b/src/devices/bus/plus4/c1551.h index a8f65a36cfa..eddad2c8046 100644 --- a/src/devices/bus/plus4/c1551.h +++ b/src/devices/bus/plus4/c1551.h @@ -36,7 +36,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; // optional information overrides virtual const tiny_rom_entry *device_rom_region() const override; @@ -47,6 +46,8 @@ protected: virtual uint8_t plus4_cd_r(offs_t offset, uint8_t data, int ba, int cs0, int c1l, int c2l, int cs1, int c1h, int c2h) override; virtual void plus4_cd_w(offs_t offset, uint8_t data, int ba, int cs0, int c1l, int c2l, int cs1, int c1h, int c2h) override; + TIMER_CALLBACK_MEMBER(irq_timer_tick); + private: uint8_t port_r(); void port_w(uint8_t data); diff --git a/src/devices/bus/psx/memcard.cpp b/src/devices/bus/psx/memcard.cpp index b5b193931e5..682439ff76e 100644 --- a/src/devices/bus/psx/memcard.cpp +++ b/src/devices/bus/psx/memcard.cpp @@ -67,7 +67,7 @@ psxcard_device::psxcard_device(const machine_config &mconfig, const char *tag, d void psxcard_device::device_start() { m_owner = dynamic_cast<psx_controller_port_device *>(owner()); - m_ack_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(psxcard_device::ack_timer), this)); + m_ack_timer = timer_alloc(FUNC(psxcard_device::ack_timer), this); m_ack = true; m_disabled = false; diff --git a/src/devices/bus/qbus/pc11.cpp b/src/devices/bus/qbus/pc11.cpp index f62f8ce0073..2fc73ada4df 100644 --- a/src/devices/bus/qbus/pc11.cpp +++ b/src/devices/bus/qbus/pc11.cpp @@ -82,8 +82,8 @@ void pc11_device::device_start() save_item(NAME(m_tbuf)); // about 300 cps - emu_timer *timer = timer_alloc(); - timer->adjust(attotime::from_usec(333), 0, attotime::from_usec(333)); + m_read_timer = timer_alloc(FUNC(pc11_device::read_tick), this); + m_read_timer->adjust(attotime::from_usec(333), 0, attotime::from_usec(333)); } @@ -214,14 +214,14 @@ void pc11_device::write(offs_t offset, uint16_t data) } } -void pc11_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(pc11_device::read_tick) { uint8_t reply; if (!(m_rcsr & CSR_BUSY)) return; - LOGDBG("Timer rcsr %06o id %d param %d m_fd %p\n", m_rcsr, id, param, m_fd); + LOGDBG("Timer rcsr %06o param %d m_fd %p\n", m_rcsr, param, m_fd); m_rcsr = (m_rcsr | CSR_ERR) & ~CSR_BUSY; if (m_fd && m_fd->exists() && (m_fd->fread(&reply, 1) == 1)) diff --git a/src/devices/bus/qbus/pc11.h b/src/devices/bus/qbus/pc11.h index 8d32925f459..cbc0d134f47 100644 --- a/src/devices/bus/qbus/pc11.h +++ b/src/devices/bus/qbus/pc11.h @@ -50,13 +50,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; // device_z80daisy_interface overrides virtual int z80daisy_irq_state() override; virtual int z80daisy_irq_ack() override; virtual void z80daisy_irq_reti() override; + TIMER_CALLBACK_MEMBER(read_tick); + private: int m_rxvec; int m_txvec; @@ -71,6 +72,8 @@ private: uint16_t m_tcsr; uint16_t m_tbuf; + emu_timer *m_read_timer; + const char *pc11_regnames[4]; }; diff --git a/src/devices/bus/rs232/null_modem.cpp b/src/devices/bus/rs232/null_modem.cpp index f2830ef2088..5b19f1d8e29 100644 --- a/src/devices/bus/rs232/null_modem.cpp +++ b/src/devices/bus/rs232/null_modem.cpp @@ -50,7 +50,7 @@ ioport_constructor null_modem_device::device_input_ports() const void null_modem_device::device_start() { - m_timer_poll = timer_alloc(TIMER_POLL); + m_timer_poll = timer_alloc(FUNC(null_modem_device::update_queue), this); } WRITE_LINE_MEMBER(null_modem_device::update_serial) @@ -81,23 +81,10 @@ WRITE_LINE_MEMBER(null_modem_device::update_serial) void null_modem_device::device_reset() { update_serial(0); - queue(); + update_queue(0); } -void null_modem_device::device_timer(emu_timer &timer, device_timer_id id, int param) -{ - switch (id) - { - case TIMER_POLL: - queue(); - break; - - default: - break; - } -} - -void null_modem_device::queue() +TIMER_CALLBACK_MEMBER(null_modem_device::update_queue) { if (is_transmit_register_empty()) { @@ -131,7 +118,7 @@ void null_modem_device::tra_callback() void null_modem_device::tra_complete() { - queue(); + update_queue(0); } void null_modem_device::rcv_complete() diff --git a/src/devices/bus/rs232/null_modem.h b/src/devices/bus/rs232/null_modem.h index 206ddfa6a1c..bd9b2520fc4 100644 --- a/src/devices/bus/rs232/null_modem.h +++ b/src/devices/bus/rs232/null_modem.h @@ -26,7 +26,6 @@ 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; virtual void device_add_mconfig(machine_config &config) override; virtual void tra_callback() override; @@ -34,9 +33,7 @@ protected: virtual void rcv_complete() override; private: - static constexpr int TIMER_POLL = 1; - - void queue(); + TIMER_CALLBACK_MEMBER(update_queue); required_device<bitbanger_device> m_stream; diff --git a/src/devices/bus/rs232/pty.cpp b/src/devices/bus/rs232/pty.cpp index 107846896e6..3cef298dc6c 100644 --- a/src/devices/bus/rs232/pty.cpp +++ b/src/devices/bus/rs232/pty.cpp @@ -63,7 +63,7 @@ ioport_constructor pseudo_terminal_device::device_input_ports() const void pseudo_terminal_device::device_start() { - m_timer_poll = timer_alloc(TIMER_POLL); + m_timer_poll = timer_alloc(FUNC(pseudo_terminal_device::update_queue), this); open(); } @@ -76,20 +76,7 @@ void pseudo_terminal_device::device_stop() void pseudo_terminal_device::device_reset() { update_serial(0); - queue(); -} - -void pseudo_terminal_device::device_timer(emu_timer &timer, device_timer_id id, int param) -{ - switch (id) - { - case TIMER_POLL: - queue(); - break; - - default: - break; - } + update_queue(0); } void pseudo_terminal_device::tra_callback() @@ -99,7 +86,7 @@ void pseudo_terminal_device::tra_callback() void pseudo_terminal_device::tra_complete() { - queue(); + update_queue(0); } void pseudo_terminal_device::rcv_complete() @@ -108,7 +95,7 @@ void pseudo_terminal_device::rcv_complete() write(get_received_char()); } -void pseudo_terminal_device::queue(void) +TIMER_CALLBACK_MEMBER(pseudo_terminal_device::update_queue) { if (is_transmit_register_empty()) { diff --git a/src/devices/bus/rs232/pty.h b/src/devices/bus/rs232/pty.h index 2037d43885d..f9fefec5e72 100644 --- a/src/devices/bus/rs232/pty.h +++ b/src/devices/bus/rs232/pty.h @@ -26,14 +26,13 @@ protected: virtual void device_start() override; virtual void device_stop() override; virtual void device_reset() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; virtual void tra_callback() override; virtual void tra_complete() override; virtual void rcv_complete() override; private: - void queue(void); + TIMER_CALLBACK_MEMBER(update_queue); required_ioport m_rs232_txbaud; required_ioport m_rs232_rxbaud; diff --git a/src/devices/bus/rs232/rs232_sync_io.cpp b/src/devices/bus/rs232/rs232_sync_io.cpp index acca54df979..8403c41e2cf 100644 --- a/src/devices/bus/rs232/rs232_sync_io.cpp +++ b/src/devices/bus/rs232/rs232_sync_io.cpp @@ -55,11 +55,6 @@ namespace { } } -// Timers -enum { - TMR_ID_CLK -}; - rs232_sync_io_device::rs232_sync_io_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) : device_t(mconfig , RS232_SYNC_IO , tag , owner , clock) , device_rs232_port_interface(mconfig , *this) @@ -118,7 +113,7 @@ void rs232_sync_io_device::device_add_mconfig(machine_config &config) void rs232_sync_io_device::device_start() { - m_clk_timer = timer_alloc(TMR_ID_CLK); + m_clk_timer = timer_alloc(FUNC(rs232_sync_io_device::clock_tick), this); } void rs232_sync_io_device::device_reset() @@ -141,65 +136,58 @@ void rs232_sync_io_device::device_reset() output_rxc(1); } -void rs232_sync_io_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(rs232_sync_io_device::clock_tick) { - switch (id) { - case TMR_ID_CLK: - m_clk = !m_clk; - if (m_clk) { - output_txc(1); - output_rxc(1); - if (m_tx_enabled) { - // Rising edge: capture TxD - m_tx_byte = (m_tx_byte >> 1) & 0x7f; - if (m_txd) { - BIT_SET(m_tx_byte , 7); - } - if (++m_tx_counter >= 8) { - LOG("Tx %02x @%s\n" , m_tx_byte , machine().time().to_string()); - m_tx_counter = 0; - m_stream->output(m_tx_byte); - m_tx_enabled = false; - } - } - } else { - if (!m_tx_enabled) { - m_tx_enabled = !m_rts || !m_rts_duplex->read(); - output_cts(!m_tx_enabled); + m_clk = !m_clk; + if (m_clk) { + output_txc(1); + output_rxc(1); + if (m_tx_enabled) { + // Rising edge: capture TxD + m_tx_byte = (m_tx_byte >> 1) & 0x7f; + if (m_txd) { + BIT_SET(m_tx_byte , 7); } - if (m_tx_enabled || m_txc_setting->read() == 0) { - output_txc(0); + if (++m_tx_counter >= 8) { + LOG("Tx %02x @%s\n" , m_tx_byte , machine().time().to_string()); + m_tx_counter = 0; + m_stream->output(m_tx_byte); + m_tx_enabled = false; } - if (!m_rx_enabled) { - m_rx_enabled = m_rts || !m_rts_duplex->read(); - if (m_rx_enabled) { - if (m_stream->input(&m_rx_byte , 1) == 0) { - m_rx_byte = ~0; - if (m_rxc_setting->read() == 2) { - m_rx_enabled = false; - } - } else { - LOG("Rx %02x @%s\n" , m_rx_byte , machine().time().to_string()); + } + } else { + if (!m_tx_enabled) { + m_tx_enabled = !m_rts || !m_rts_duplex->read(); + output_cts(!m_tx_enabled); + } + if (m_tx_enabled || m_txc_setting->read() == 0) { + output_txc(0); + } + if (!m_rx_enabled) { + m_rx_enabled = m_rts || !m_rts_duplex->read(); + if (m_rx_enabled) { + if (m_stream->input(&m_rx_byte , 1) == 0) { + m_rx_byte = ~0; + if (m_rxc_setting->read() == 2) { + m_rx_enabled = false; } + } else { + LOG("Rx %02x @%s\n" , m_rx_byte , machine().time().to_string()); } } - if (m_rx_enabled || m_rxc_setting->read() == 0) { - output_rxc(0); - } - if (m_rx_enabled) { - // Falling edge: update RxD - output_rxd(BIT(m_rx_byte , 0)); - m_rx_byte >>= 1; - if (++m_rx_counter >= 8) { - m_rx_counter = 0; - m_rx_enabled = false; - } + } + if (m_rx_enabled || m_rxc_setting->read() == 0) { + output_rxc(0); + } + if (m_rx_enabled) { + // Falling edge: update RxD + output_rxd(BIT(m_rx_byte , 0)); + m_rx_byte >>= 1; + if (++m_rx_counter >= 8) { + m_rx_counter = 0; + m_rx_enabled = false; } } - break; - - default: - break; } } diff --git a/src/devices/bus/rs232/rs232_sync_io.h b/src/devices/bus/rs232/rs232_sync_io.h index dce3aa4297f..a5b6818de48 100644 --- a/src/devices/bus/rs232/rs232_sync_io.h +++ b/src/devices/bus/rs232/rs232_sync_io.h @@ -34,7 +34,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(clock_tick); private: required_device<bitbanger_device> m_stream; diff --git a/src/devices/bus/rs232/xvd701.cpp b/src/devices/bus/rs232/xvd701.cpp index e51ff0449ce..a04365f2239 100644 --- a/src/devices/bus/rs232/xvd701.cpp +++ b/src/devices/bus/rs232/xvd701.cpp @@ -58,7 +58,7 @@ void jvc_xvd701_device::device_start() output_ri(0); output_cts(0); - m_timer_response = timer_alloc(TIMER_RESPONSE); + m_timer_response = timer_alloc(FUNC(jvc_xvd701_device::send_response), this); } void jvc_xvd701_device::device_reset() @@ -73,19 +73,6 @@ void jvc_xvd701_device::device_reset() m_playback_status = STATUS_STOP; } -void jvc_xvd701_device::device_timer(emu_timer &timer, device_timer_id id, int param) -{ - switch (id) - { - case TIMER_RESPONSE: - send_response(); - break; - - default: - break; - } -} - void jvc_xvd701_device::tra_callback() { output_rxd(transmit_register_get_data_bit()); @@ -119,7 +106,7 @@ void jvc_xvd701_device::create_packet(unsigned char status, const unsigned char m_timer_response->adjust(attotime::from_msec(100)); } -void jvc_xvd701_device::send_response() +TIMER_CALLBACK_MEMBER(jvc_xvd701_device::send_response) { if (m_response_index < sizeof(m_response) && is_transmit_register_empty()) { diff --git a/src/devices/bus/rs232/xvd701.h b/src/devices/bus/rs232/xvd701.h index da9fbce0502..8e85e377f76 100644 --- a/src/devices/bus/rs232/xvd701.h +++ b/src/devices/bus/rs232/xvd701.h @@ -18,7 +18,6 @@ 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; virtual void device_add_mconfig(machine_config &config) override; virtual void tra_callback() override; @@ -26,8 +25,6 @@ protected: virtual void rcv_complete() override; private: - static constexpr int TIMER_RESPONSE = 1; - enum jvc_xvd701_media_type : uint32_t { JVC_MEDIA_VCD = 0, @@ -41,7 +38,7 @@ private: STATUS_PAUSE = 2, }; - void send_response(); + TIMER_CALLBACK_MEMBER(send_response); unsigned char sum(unsigned char *buffer, int length); void create_packet(unsigned char status, const unsigned char response[6]); diff --git a/src/devices/bus/s100/ascsasi.cpp b/src/devices/bus/s100/ascsasi.cpp index ef8b2d329e3..73cacf9680a 100644 --- a/src/devices/bus/s100/ascsasi.cpp +++ b/src/devices/bus/s100/ascsasi.cpp @@ -89,8 +89,8 @@ asc_sasi_device::asc_sasi_device(const machine_config &mconfig, const char *tag, void asc_sasi_device::device_start() { // initialize timers - m_sel_off_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(asc_sasi_device::sel_off), this)); - m_rst_off_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(asc_sasi_device::rst_off), this)); + m_sel_off_timer = timer_alloc(FUNC(asc_sasi_device::sel_off), this); + m_rst_off_timer = timer_alloc(FUNC(asc_sasi_device::rst_off), this); // save state save_item(NAME(m_data_latch)); diff --git a/src/devices/bus/samcoupe/mouse/mouse.cpp b/src/devices/bus/samcoupe/mouse/mouse.cpp index 02f80626e79..fbacfa67c7a 100644 --- a/src/devices/bus/samcoupe/mouse/mouse.cpp +++ b/src/devices/bus/samcoupe/mouse/mouse.cpp @@ -64,7 +64,7 @@ sam_mouse_device::sam_mouse_device(const machine_config &mconfig, const char *ta void sam_mouse_device::device_start() { // allocate timer - m_reset = timer_alloc(); + m_reset = timer_alloc(FUNC(sam_mouse_device::reset_tick), this); // register for savestates save_item(NAME(m_mouse_index)); @@ -85,10 +85,10 @@ void sam_mouse_device::device_reset() } //------------------------------------------------- -// device_timer - handler timer events +// reset_tick - reset the mouse index //------------------------------------------------- -void sam_mouse_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(sam_mouse_device::reset_tick) { m_mouse_index = 0; } diff --git a/src/devices/bus/samcoupe/mouse/mouse.h b/src/devices/bus/samcoupe/mouse/mouse.h index 008b1f9b750..076f3035b6d 100644 --- a/src/devices/bus/samcoupe/mouse/mouse.h +++ b/src/devices/bus/samcoupe/mouse/mouse.h @@ -33,7 +33,8 @@ 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; + + TIMER_CALLBACK_MEMBER(reset_tick); private: required_ioport m_io_buttons; diff --git a/src/devices/bus/scsi/scsihle.cpp b/src/devices/bus/scsi/scsihle.cpp index a177d25ddb3..09a0fa84eca 100644 --- a/src/devices/bus/scsi/scsihle.cpp +++ b/src/devices/bus/scsi/scsihle.cpp @@ -82,9 +82,9 @@ void scsihle_device::device_start() { t10_start(*this); - req_timer = timer_alloc(0); - sel_timer = timer_alloc(1); - dataout_timer = timer_alloc(2); + req_timer = timer_alloc(FUNC(scsihle_device::req_tick), this); + sel_timer = timer_alloc(FUNC(scsihle_device::sel_tick), this); + dataout_timer = timer_alloc(FUNC(scsihle_device::dataout_tick), this); } void scsihle_device::device_reset() @@ -206,27 +206,24 @@ void scsihle_device::scsibus_write_data() data_idx=0; } -void scsihle_device::device_timer(emu_timer &timer, device_timer_id tid, int param) +TIMER_CALLBACK_MEMBER(scsihle_device::req_tick) { - switch (tid) - { - case 0: - output_req(param); - break; + output_req(param); +} - case 1: - output_bsy(param); - break; +TIMER_CALLBACK_MEMBER(scsihle_device::sel_tick) +{ + output_bsy(param); +} - case 2: - // Some drives, notably the ST225N and ST125N, accept fromat unit commands - // with flags set indicating that bad block data should be transferred but - // don't then implemnt a data in phase, this timeout it to catch these ! - if (IS_COMMAND(SCSI_CMD_FORMAT_UNIT) && (data_idx==0)) - { - scsi_change_phase(SCSI_PHASE_STATUS); - } - break; +TIMER_CALLBACK_MEMBER(scsihle_device::dataout_tick) +{ + // Some drives, notably the ST225N and ST125N, accept fromat unit commands + // with flags set indicating that bad block data should be transferred but + // don't then implemnt a data in phase, this timeout it to catch these + if (IS_COMMAND(SCSI_CMD_FORMAT_UNIT) && (data_idx==0)) + { + scsi_change_phase(SCSI_PHASE_STATUS); } } diff --git a/src/devices/bus/scsi/scsihle.h b/src/devices/bus/scsi/scsihle.h index d810be70dcc..ea6f577a592 100644 --- a/src/devices/bus/scsi/scsihle.h +++ b/src/devices/bus/scsi/scsihle.h @@ -43,7 +43,10 @@ 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; + + TIMER_CALLBACK_MEMBER(req_tick); + TIMER_CALLBACK_MEMBER(sel_tick); + TIMER_CALLBACK_MEMBER(dataout_tick); private: required_ioport m_scsi_id; diff --git a/src/devices/bus/sg1000_exp/kblink.cpp b/src/devices/bus/sg1000_exp/kblink.cpp index 4a2cd10786a..8d98e006f94 100644 --- a/src/devices/bus/sg1000_exp/kblink.cpp +++ b/src/devices/bus/sg1000_exp/kblink.cpp @@ -81,9 +81,9 @@ sk1100_link_cable_device::sk1100_link_cable_device(const machine_config &mconfig void sk1100_link_cable_device::device_start() { - m_timer_poll = timer_alloc(TIMER_POLL); - m_timer_send = timer_alloc(TIMER_SEND); - m_timer_read = timer_alloc(TIMER_READ); + m_timer_poll = timer_alloc(FUNC(sk1100_link_cable_device::update_queue), this); + m_timer_send = timer_alloc(FUNC(sk1100_link_cable_device::send_tick), this); + m_timer_read = timer_alloc(FUNC(sk1100_link_cable_device::read_tick), this); /* register for state saving */ save_item(NAME(m_data)); @@ -103,7 +103,7 @@ void sk1100_link_cable_device::device_start() void sk1100_link_cable_device::device_reset() { - queue(); + update_queue(0); } @@ -116,29 +116,7 @@ void sk1100_link_cable_device::device_add_mconfig(machine_config &config) BITBANGER(config, m_stream, 0); } - -void sk1100_link_cable_device::device_timer(emu_timer &timer, device_timer_id id, int param) -{ - switch (id) - { - case TIMER_POLL: - queue(); - break; - - case TIMER_SEND: - m_stream->output(u8(param)); - break; - - case TIMER_READ: - m_update_received_data = true; - break; - - default: - break; - } -} - -void sk1100_link_cable_device::queue() +TIMER_CALLBACK_MEMBER(sk1100_link_cable_device::update_queue) { if (m_input_index == m_input_count) { @@ -151,6 +129,16 @@ void sk1100_link_cable_device::queue() } } +TIMER_CALLBACK_MEMBER(sk1100_link_cable_device::send_tick) +{ + m_stream->output(u8(param)); +} + +TIMER_CALLBACK_MEMBER(sk1100_link_cable_device::read_tick) +{ + m_update_received_data = true; +} + void sk1100_link_cable_device::set_data_read() { // Check if a new byte from the input buffer was read for this timeslice. @@ -162,7 +150,7 @@ void sk1100_link_cable_device::set_data_read() // there is no way to read what was sent from peer as feed bit. m_fault = BIT(byte, 0); // sent from peer as data bit m_busy = BIT(byte, 1); // sent from peer as reset bit - queue(); + update_queue(0); } // Set to read next byte only after the end of this timeslice. m_update_received_data = false; diff --git a/src/devices/bus/sg1000_exp/kblink.h b/src/devices/bus/sg1000_exp/kblink.h index 2c64dd312bf..561c1b79455 100644 --- a/src/devices/bus/sg1000_exp/kblink.h +++ b/src/devices/bus/sg1000_exp/kblink.h @@ -37,11 +37,9 @@ protected: // device-level overrides virtual void device_start() override; virtual void device_reset() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; virtual void device_add_mconfig(machine_config &config) override; // device_sk1100_link_cable_interface overrides - virtual DECLARE_WRITE_LINE_MEMBER( input_data ) override { m_data = state; set_data_transfer(); } virtual DECLARE_WRITE_LINE_MEMBER( input_reset ) override { m_reset = state; set_data_transfer(); } virtual DECLARE_WRITE_LINE_MEMBER( input_feed ) override { m_feed = state; set_data_transfer(); } @@ -49,6 +47,10 @@ protected: virtual DECLARE_READ_LINE_MEMBER( output_fault ) override { set_data_read(); return m_fault; } virtual DECLARE_READ_LINE_MEMBER( output_busy ) override { set_data_read(); return m_busy; } + TIMER_CALLBACK_MEMBER(update_queue); + TIMER_CALLBACK_MEMBER(send_tick); + TIMER_CALLBACK_MEMBER(read_tick); + private: static constexpr int TIMER_POLL = 1; static constexpr int TIMER_SEND = 2; diff --git a/src/devices/bus/sgikbd/hlekbd.cpp b/src/devices/bus/sgikbd/hlekbd.cpp index 68883f37d7d..42ffb0eb76c 100644 --- a/src/devices/bus/sgikbd/hlekbd.cpp +++ b/src/devices/bus/sgikbd/hlekbd.cpp @@ -201,8 +201,8 @@ void hle_device::device_add_mconfig(machine_config &config) void hle_device::device_start() { m_leds.resolve(); - m_click_timer = timer_alloc(TIMER_CLICK); - m_beep_timer = timer_alloc(TIMER_BEEP); + m_click_timer = timer_alloc(FUNC(hle_device::click_off), this); + m_beep_timer = timer_alloc(FUNC(hle_device::beep_off), this); save_item(NAME(m_make_count)); save_item(NAME(m_keyclick)); @@ -247,23 +247,16 @@ void hle_device::device_reset() start_processing(attotime::from_hz(600)); } -void hle_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(hle_device::click_off) { - switch (id) - { - case TIMER_CLICK: - m_beeper_state &= ~BEEPER_CLICK; - m_beeper->set_state(m_beeper_state ? 1 : 0); - break; - - case TIMER_BEEP: - m_beeper_state &= ~BEEPER_BELL; - m_beeper->set_state(m_beeper_state ? 1 : 0); - break; + m_beeper_state &= ~BEEPER_CLICK; + m_beeper->set_state(m_beeper_state ? 1 : 0); +} - default: - break; - } +TIMER_CALLBACK_MEMBER(hle_device::beep_off) +{ + m_beeper_state &= ~BEEPER_BELL; + m_beeper->set_state(m_beeper_state ? 1 : 0); } void hle_device::tra_callback() diff --git a/src/devices/bus/sgikbd/hlekbd.h b/src/devices/bus/sgikbd/hlekbd.h index afa9fb03949..ce066e90c55 100644 --- a/src/devices/bus/sgikbd/hlekbd.h +++ b/src/devices/bus/sgikbd/hlekbd.h @@ -31,7 +31,6 @@ protected: virtual void device_add_mconfig(machine_config &config) override; virtual void device_start() override; virtual void device_reset() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; virtual ioport_constructor device_input_ports() const override; // device_buffered_serial_interface overrides @@ -45,13 +44,10 @@ protected: // customised transmit_byte method void transmit_byte(uint8_t byte); -private: - enum - { - TIMER_CLICK = 30000, - TIMER_BEEP = 30001 - }; + TIMER_CALLBACK_MEMBER(click_off); + TIMER_CALLBACK_MEMBER(beep_off); +private: enum { LED_NUM, diff --git a/src/devices/bus/sms_ctrl/lphaser.cpp b/src/devices/bus/sms_ctrl/lphaser.cpp index d9fb0443ec8..7e64e7c7236 100644 --- a/src/devices/bus/sms_ctrl/lphaser.cpp +++ b/src/devices/bus/sms_ctrl/lphaser.cpp @@ -45,7 +45,9 @@ READ_LINE_MEMBER( sms_light_phaser_device::th_pin_r ) INPUT_CHANGED_MEMBER( sms_light_phaser_device::position_changed ) { if (newval != oldval) - sensor_check(); + { + sensor_check(0); + } } @@ -87,7 +89,9 @@ sms_light_phaser_device::sms_light_phaser_device(const machine_config &mconfig, device_sms_control_port_interface(mconfig, *this), m_lphaser_pins(*this, "CTRL_PORT"), m_lphaser_x(*this, "LPHASER_X"), - m_lphaser_y(*this, "LPHASER_Y"), m_sensor_last_state(0), m_lphaser_timer(nullptr) + m_lphaser_y(*this, "LPHASER_Y"), + m_sensor_last_state(0), + m_lphaser_timer(nullptr) { } @@ -99,7 +103,7 @@ sms_light_phaser_device::sms_light_phaser_device(const machine_config &mconfig, void sms_light_phaser_device::device_start() { save_item(NAME(m_sensor_last_state)); - m_lphaser_timer = timer_alloc(TIMER_LPHASER); + m_lphaser_timer = timer_alloc(FUNC(sms_light_phaser_device::sensor_check), this); } @@ -121,28 +125,28 @@ uint8_t sms_light_phaser_device::peripheral_r() /* Light Phaser (light gun) emulation notes: - - The sensor is activated based on color brightness of some individual - pixels being drawn by the beam, at circular area where the gun is aiming. + - The sensor is activated based on the brightness of individual pixels being + drawn by the beam, in circular area where the gun is aiming. - Currently, brightness is calculated based only on single pixels. - In general, after the trigger is pressed, games draw the next frame using - a light color pattern, to make sure sensor will be activated. If emulation - skips that frame, sensor may stay deactivated. Frameskip set to 0 (no skip) + a bright pattern, to make sure the sensor will be activated. If the emulation + skips that frame, the sensor may stay deactivated. Setting frameskip to 0 is recommended to avoid problems. - - When sensor switches from on (0) to off (1), a value is latched for the + - When the sensor switches from on (0) to off (1), a value is latched for the HCount register. - - When sensor switches from off to on, a flag is set. The emulation uses the - flag to signal that TH line is activated when the status of the input port - is read. After read, the flag is cleared, or else it is cleared later when - the Pause status is read (end of a frame). This is necessary because the + - When the sensor switches from off to on, a flag is set. The emulation uses + this flag to signal that the TH line is activated during status reads of the + input port. After reading, the flag is cleared, or it is cleared when the + Pause status is read at the end of a frame. This is necessary because the "Color & Switch Test" ROM only reads the TH state after VINT occurs. - - The gun test of "Color & Switch Test" is an example that requires checks - of sensor status independent of other events, like trigger press or TH bit + - The gun test in "Color & Switch Test" is an example that requires checks + of the sensor status independent of other events, like trigger press or TH bit reads. Another example is the title screen of "Hang-On & Safari Hunt", where - the game only reads HCount register in a loop, expecting a latch by the gun. - - The whole procedure is managed by a timer callback, that always reschedule - itself to run in some intervals when the beam is at the circular area. + the game only reads the HCount register in a loop, expecting a latch by the gun. + - The whole procedure is managed by a periodic timer callback, which is scheduled + to run in intervals when the beam is within the circular area. */ -int sms_light_phaser_device::bright_aim_area( emu_timer *timer, int lgun_x, int lgun_y ) +int sms_light_phaser_device::bright_aim_area(int lgun_x, int lgun_y) { const int r_x_r = LGUN_RADIUS * LGUN_RADIUS; const rectangle &visarea = m_port->m_screen->visible_area(); @@ -151,8 +155,7 @@ int sms_light_phaser_device::bright_aim_area( emu_timer *timer, int lgun_x, int int beam_y = m_port->m_screen->vpos(); int beam_x_orig = beam_x; int beam_y_orig = beam_y; - int dy, result = 1; - double dx_radius; + int result = 1; bool new_check_point = false; aim_area.min_y = std::max(lgun_y - LGUN_RADIUS, visarea.min_y); @@ -166,23 +169,21 @@ int sms_light_phaser_device::bright_aim_area( emu_timer *timer, int lgun_x, int { beam_y = aim_area.min_y; } - dy = abs(beam_y - lgun_y); + int dy = abs(beam_y - lgun_y); /* Caculate distance in x of the radius, relative to beam's y distance. First try some shortcuts. */ - switch (dy) + double dx_radius = 0; + if (dy == 0) { - case LGUN_RADIUS: - dx_radius = 0; - break; - case 0: dx_radius = LGUN_RADIUS; - break; - default: + } + else if (dy != LGUN_RADIUS) + { /* step 1: r^2 = dx^2 + dy^2 */ /* step 2: dx^2 = r^2 - dy^2 */ /* step 3: dx = sqrt(r^2 - dy^2) */ - dx_radius = ceil((float) sqrt((float) (r_x_r - (dy * dy)))); + dx_radius = ceil(sqrt(double(r_x_r - (dy * dy)))); } aim_area.min_x = std::max(int32_t(lgun_x - dx_radius), visarea.min_x); @@ -252,7 +253,7 @@ int sms_light_phaser_device::bright_aim_area( emu_timer *timer, int lgun_x, int } } - timer->adjust(m_port->m_screen->time_until_pos(beam_y, beam_x)); + m_lphaser_timer->adjust(m_port->m_screen->time_until_pos(beam_y, beam_x)); return result; } @@ -273,30 +274,15 @@ uint16_t sms_light_phaser_device::screen_vpos_nonscaled(int scaled_vpos) } -void sms_light_phaser_device::sensor_check() +TIMER_CALLBACK_MEMBER(sms_light_phaser_device::sensor_check) { - int sensor_new_state; - const int x = screen_hpos_nonscaled(m_lphaser_x->read()); const int y = screen_vpos_nonscaled(m_lphaser_y->read()); - sensor_new_state = bright_aim_area(m_lphaser_timer, x, y); + int sensor_new_state = bright_aim_area(x, y); if (sensor_new_state != m_sensor_last_state) { m_port->th_pin_w(sensor_new_state); m_sensor_last_state = sensor_new_state; } } - - -void sms_light_phaser_device::device_timer(emu_timer &timer, device_timer_id id, int param) -{ - switch (id) - { - case TIMER_LPHASER: - sensor_check(); - break; - default: - throw emu_fatalerror("sms_light_phaser_device(%s): Unknown timer ID", tag()); - } -} diff --git a/src/devices/bus/sms_ctrl/lphaser.h b/src/devices/bus/sms_ctrl/lphaser.h index 3e1a4d41960..a75f4a0d042 100644 --- a/src/devices/bus/sms_ctrl/lphaser.h +++ b/src/devices/bus/sms_ctrl/lphaser.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; // device_sms_control_port_interface overrides virtual uint8_t peripheral_r() override; @@ -51,10 +50,9 @@ private: int m_sensor_last_state; emu_timer *m_lphaser_timer; - static const device_timer_id TIMER_LPHASER = 0; - void sensor_check(); - int bright_aim_area( emu_timer *timer, int lgun_x, int lgun_y ); + TIMER_CALLBACK_MEMBER(sensor_check); + int bright_aim_area(int lgun_x, int lgun_y ); uint16_t screen_hpos_nonscaled(int scaled_hpos); uint16_t screen_vpos_nonscaled(int scaled_vpos); }; diff --git a/src/devices/bus/sms_ctrl/sports.cpp b/src/devices/bus/sms_ctrl/sports.cpp index 0995af24f5c..d58cfb68095 100644 --- a/src/devices/bus/sms_ctrl/sports.cpp +++ b/src/devices/bus/sms_ctrl/sports.cpp @@ -11,29 +11,28 @@ Release data from the Sega Retro project: TODO: -- For low-level emulation, a device for the TMP42C66P, a Toshiba 4bit - microcontroller, needs to be created, but a dump of its internal ROM - seems to be required. +- For low-level emulation, a device for the TMP42C66P, a Toshiba 4-bit + microcontroller, is needed along with a dump of its internal ROM. - Auto-repeat and Control/Sports mode switches are not emulated. Notes: Games designed for the US model of the Sports Pad controller use the - TH line of the controller port to select which nibble, of the two axis - bytes, will be read at a time. The Japanese cartridge Sports Pad Soccer - uses a different mode when not detect a SMSJ, because the Sega Mark III - lacks the TH line. There is a different Sports Pad model released in - Japan and no information was found about it supporting both modes, so + TH line of the controller port to select which nibble of the two axis + to read. The Japanese cartridge Sports Pad Soccer uses a different mode + when it does not detect use by a Japanese SMS console, because the Sega + Mark III lacks the TH line. There was a different Sports Pad model released + in Japan and no information was found about it supporting both modes, so that model is currently emulated as a different device (see sportsjp.c). It was discovered that games designed for the Paddle Controller, released - in Japan, switch to a mode incompatible with the original Paddle when - detect the system region as Export. Similar to how the US model of the - Sports Pad works, that mode uses the TH line as output to select which + in Japan, will switch to a mode incompatible with the original Paddle when + the system region is detected as Export. Similar to how the US model of the + Sports Pad works, that mode uses the TH line as an output to select which nibble of the X axis will be read. So, on an Export console version, paddle games are somewhat playable with the US Sport Pad model, though it - needs to be used inverted and the trackball needs to be moved slowly, else - the software for the paddle think it's moving backward. + needs to be used inverted and the trackball needs to be moved slowly, + otherwise the software for the paddle think it's moving backward. See http://mametesters.org/view.php?id=5872 for discussion. **********************************************************************/ @@ -53,28 +52,20 @@ DEFINE_DEVICE_TYPE(SMS_SPORTS_PAD, sms_sports_pad_device, "sms_sports_pad", "Seg #define SPORTS_PAD_INTERVAL attotime::from_hz(XTAL(10'738'635)/3/512) -void sms_sports_pad_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(sms_sports_pad_device::read_tick) { - switch (id) + // values for x and y axis need to be reset for Sports Pad games, but + // are not reset for paddle games, so it was assumed the reset occurs + // only when this timer fires after the read state reaches its maximum value. + if (m_read_state == 3) { - case TIMER_SPORTSPAD: - // values for x and y axis need to be resetted for Sports Pad games, but - // are not resetted for paddle games, so it was assumed the reset occurs - // only when this timer fires after the read state reached maximum value. - if (m_read_state == 3) - { - m_x_axis_reset_value = m_sports_x->read(); - m_y_axis_reset_value = m_sports_y->read(); - } - else - { - // set to maximum value, so it wraps to 0 at next increment - m_read_state = 3; - } - - break; - default: - throw emu_fatalerror("sms_sports_pad_device(%s): Unknown timer ID", tag()); + m_x_axis_reset_value = m_sports_x->read(); + m_y_axis_reset_value = m_sports_y->read(); + } + else + { + // set to maximum value, so it wraps to 0 at next increment + m_read_state = 3; } } @@ -169,7 +160,7 @@ sms_sports_pad_device::sms_sports_pad_device(const machine_config &mconfig, cons m_sports_y(*this, "SPORTS_Y"), m_read_state(0), m_th_pin_state(0), - m_x_axis_reset_value(0x80), // value 0x80 helps when start playing paddle games. + m_x_axis_reset_value(0x80), // value 0x80 helps when starting paddle games. m_y_axis_reset_value(0x80), m_interval(SPORTS_PAD_INTERVAL), m_sportspad_timer(nullptr) @@ -183,7 +174,7 @@ sms_sports_pad_device::sms_sports_pad_device(const machine_config &mconfig, cons void sms_sports_pad_device::device_start() { - m_sportspad_timer = timer_alloc(TIMER_SPORTSPAD); + m_sportspad_timer = timer_alloc(FUNC(sms_sports_pad_device::read_tick), this); save_item(NAME(m_read_state)); save_item(NAME(m_th_pin_state)); @@ -191,21 +182,11 @@ void sms_sports_pad_device::device_start() save_item(NAME(m_y_axis_reset_value)); } - -//------------------------------------------------- -// sms_peripheral_r - sports pad read -//------------------------------------------------- - uint8_t sms_sports_pad_device::peripheral_r() { return m_sports_in->read(); } - -//------------------------------------------------- -// sms_peripheral_w - sports pad write -//------------------------------------------------- - void sms_sports_pad_device::peripheral_w(uint8_t data) { m_sports_out->write(data); diff --git a/src/devices/bus/sms_ctrl/sports.h b/src/devices/bus/sms_ctrl/sports.h index ed7c8a97eef..cdf1202befd 100644 --- a/src/devices/bus/sms_ctrl/sports.h +++ b/src/devices/bus/sms_ctrl/sports.h @@ -56,9 +56,8 @@ private: uint8_t m_y_axis_reset_value; const attotime m_interval; emu_timer *m_sportspad_timer; - static const device_timer_id TIMER_SPORTSPAD = 0; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; + TIMER_CALLBACK_MEMBER(read_tick); }; diff --git a/src/devices/bus/snes/event.cpp b/src/devices/bus/snes/event.cpp index 26a66971e67..5ce5bbca97c 100644 --- a/src/devices/bus/snes/event.cpp +++ b/src/devices/bus/snes/event.cpp @@ -4,7 +4,7 @@ Super NES/Famicom Event cartridges emulation (for SNES/SFC) - TODO: figure out how the Test Mode switch works... + TODO: Figure out how the Test Mode switch works ***********************************************************************************************************/ @@ -38,7 +38,7 @@ void sns_pfest94_device::device_start() { m_dsp_prg.resize(0x2000/sizeof(uint32_t)); m_dsp_data.resize(0x800/sizeof(uint16_t)); - pfest94_timer = timer_alloc(TIMER_EVENT); + pfest94_timer = timer_alloc(FUNC(sns_pfest94_device::event_tick), this); pfest94_timer->reset(); save_item(NAME(m_base_bank)); @@ -102,7 +102,7 @@ uint8_t sns_pfest94_device::read_h(offs_t offset) } -// these are used for two diff effects: both to select game from menu and to access the DSP when running SMK! +// these are used both to select game from the menu and to access the DSP when running Super Mario Kart. uint8_t sns_pfest94_device::chip_read(offs_t offset) { if (offset & 0x8000) @@ -166,6 +166,7 @@ inline uint32_t get_prg(uint8_t *CPU, uint32_t addr) { return ((CPU[addr * 4] << 24) | (CPU[addr * 4 + 1] << 16) | (CPU[addr * 4 + 2] << 8) | 0x00); } + inline uint16_t get_data(uint8_t *CPU, uint32_t addr) { return ((CPU[addr * 2] << 8) | CPU[addr * 2 + 1]); @@ -183,7 +184,7 @@ void sns_pfest94_device::speedup_addon_bios_access() } -// DSP dump contains prg at offset 0 and data at offset 0x2000 +// DSP dump contains program code at offset 0 and data at offset 0x2000 uint32_t sns_pfest94_device::necdsp_prg_r(offs_t offset) { return get_prg(&m_bios[0], offset); @@ -262,20 +263,12 @@ ioport_constructor sns_pfest94_device::device_input_ports() const return INPUT_PORTS_NAME( pfest94_dsw ); } - -//------------------------------------------------- -// device_timer - handler timer events -//------------------------------------------------- - -void sns_pfest94_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(sns_pfest94_device::event_tick) { - if (id == TIMER_EVENT) + if (!m_count) { - if (!m_count) - { - m_status |= 2; - pfest94_timer->reset(); - } - m_count--; + m_status |= 2; + pfest94_timer->reset(); } + m_count--; } diff --git a/src/devices/bus/snes/event.h b/src/devices/bus/snes/event.h index 1885b3fa328..5c075b50b27 100644 --- a/src/devices/bus/snes/event.h +++ b/src/devices/bus/snes/event.h @@ -19,13 +19,10 @@ public: sns_pfest94_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock); protected: - static constexpr device_timer_id TIMER_EVENT = 0; - // device-level overrides virtual void device_start() override; virtual void device_reset() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; virtual void device_add_mconfig(machine_config &config) override; virtual ioport_constructor device_input_ports() const override; @@ -40,6 +37,8 @@ protected: virtual uint32_t necdsp_prg_r(offs_t offset); virtual uint16_t necdsp_data_r(offs_t offset); + TIMER_CALLBACK_MEMBER(event_tick); + private: required_device<upd7725_device> m_upd7725; required_ioport m_dsw; diff --git a/src/devices/bus/snes/sa1.cpp b/src/devices/bus/snes/sa1.cpp index 39b2bd080e3..43835642806 100644 --- a/src/devices/bus/snes/sa1.cpp +++ b/src/devices/bus/snes/sa1.cpp @@ -5,17 +5,17 @@ SA-1 add-on chip emulation (for SNES/SFC) Note: - - SA-1 register description below is based on no$cash docs. - - about bankswitch handling: no matter what is ROM size, at loading the ROM is mirrored up to 8MB and a + - SA-1 register description below is based on nocash docs. + - Bankswitch handling: no matter what ROM size is used, at loading the ROM is mirrored up to 8MB and a rom_bank_map[0x100] array is built as a lookup table for 256x32KB banks filling the 8MB accessible ROM - area; this allows to handle any 0-7 value written to CXB/DXB/EXB/FXB SA-1 registers without any masking! - - about BWRAM "bitmap mode": in 2bits mode + area; this allows any value from 0-7 being written to CXB/DXB/EXB/FXB SA-1 registers without any masking. + - about BWRAM "bitmap mode": in 2-bit mode 600000h.Bit0-1 mirrors to 400000h.Bit0-1 600001h.Bit0-1 mirrors to 400000h.Bit2-3 600002h.Bit0-1 mirrors to 400000h.Bit4-5 600003h.Bit0-1 mirrors to 400000h.Bit6-7 ... - in 4bits mode + in 4-bit mode 600000h.Bit0-3 mirrors to 400000h.Bit0-3 600001h.Bit0-3 mirrors to 400000h.Bit4-7 600002h.Bit0-3 mirrors to 400001h.Bit0-3 @@ -24,10 +24,10 @@ to handle the separate modes, bitmap accesses go to offset + 0x100000 TODO: - - test case for BWRAM write protect (bsnes does not seem to ever protect either, so it's not implemented + - Test case for BWRAM write protect (bsnes does not seem to protect either, so it's not implemented for the moment) - - almost everything CPU related! - - Bus conflict (also seen: https://github.com/VitorVilela7/SnesSpeedTest) + - Almost everything CPU related + - Bus conflicts Compatibility: asahishi: plays OK @@ -61,8 +61,8 @@ sshogi3: plays OK taikyoid: plays OK takemiya: plays OK - [Note: for Igo & Shougi games, "plays OK" means you can get ingame and the CPU replies to your moves... subtle bugs - might indeed exist...] + Note: for Igo & Shougi games, "plays OK" means you can get ingame and the CPU replies to your moves; subtle bugs + might indeed exist. ***********************************************************************************************************/ @@ -110,7 +110,7 @@ sns_sa1_device::sns_sa1_device(const machine_config &mconfig, const char *tag, d void sns_sa1_device::device_start() { m_internal_ram = make_unique_clear<u8[]>(0x800); - m_sa1_timer = timer_alloc(TIMER_SA1); + m_sa1_timer = timer_alloc(FUNC(sns_sa1_device::timer_tick), this); m_scpu_ctrl = 0; m_nmi_vector = 0; @@ -220,65 +220,59 @@ void sns_sa1_device::device_reset() m_cconv1_dma_active = false; m_cconv2_line = 0; - // sa-1 CPU starts out not running? + // SA-1 CPU starts out not running m_sa1->set_input_line(INPUT_LINE_HALT, ASSERT_LINE); - // timer is run parallely with CPUs + // Timer is run in sync with the CPU m_sa1_timer->adjust(m_sa1->clocks_to_attotime(2), 0, m_sa1->clocks_to_attotime(2)); } -void sns_sa1_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(sns_sa1_device::timer_tick) { - switch (id) + if (TMC_HVSELB()) { - case TIMER_SA1: - if (TMC_HVSELB()) - { - // 18 bit Linear timer - m_hpos++; - m_vpos += m_hpos >> 9; - m_hpos &= 0x1ff; - m_vpos &= 0x1ff; - } - else + // 18 bit Linear timer + m_hpos++; + m_vpos += m_hpos >> 9; + m_hpos &= 0x1ff; + m_vpos &= 0x1ff; + } + else + { + // H/V timer + if (++m_hpos >= 341) { - // H/V timer - if (++m_hpos >= 341) - { - m_hpos = 0; - if (++m_vpos >= scanlines_r()) - m_vpos = 0; - } + m_hpos = 0; + if (++m_vpos >= scanlines_r()) + m_vpos = 0; } - // send timer IRQ - if (TMC_HEN() && TMC_VEN()) // both H and V count enabled + } + // send timer IRQ + if (TMC_HEN() && TMC_VEN()) // both H and V count enabled + { + if ((m_hpos == m_hcount) && (m_vpos == m_vcount)) { - if ((m_hpos == m_hcount) && (m_vpos == m_vcount)) - { - m_sa1_flags |= SA1_IRQ_TIMER; - recalc_irqs(); - } + m_sa1_flags |= SA1_IRQ_TIMER; + recalc_irqs(); } - else if (TMC_HEN()) // H count only + } + else if (TMC_HEN()) // H count only + { + if (m_hpos == m_hcount) { - if (m_hpos == m_hcount) - { - m_sa1_flags |= SA1_IRQ_TIMER; - recalc_irqs(); - } + m_sa1_flags |= SA1_IRQ_TIMER; + recalc_irqs(); } - else if (TMC_VEN()) // V count only + } + else if (TMC_VEN()) // V count only + { + if ((m_hpos == 0) && (m_vpos == m_vcount)) { - if ((m_hpos == 0) && (m_vpos == m_vcount)) - { - m_sa1_flags |= SA1_IRQ_TIMER; - recalc_irqs(); - } + m_sa1_flags |= SA1_IRQ_TIMER; + recalc_irqs(); } - break; - // Math & DMA timer here? - default: - throw emu_fatalerror("Unknown id in sns_sa1_device::device_timer"); } + + // TODO: Math & DMA timer } /*------------------------------------------------- @@ -309,11 +303,11 @@ void sns_sa1_device::recalc_irqs() -------------------------------------------------*/ -// handle this separately to avoid accessing recursively the regs? +// TODO: Handle this separately to avoid accessing the regs recursively u8 sns_sa1_device::var_length_read(offs_t offset) { - // TODO: memory accessing cycle? + // TODO: memory access cycle // handle 0xffea/0xffeb/0xffee/0xffef if ((offset & 0xffffe0) == 0x00ffe0) { @@ -349,11 +343,9 @@ u8 sns_sa1_device::var_length_read(offs_t offset) void sns_sa1_device::dma_transfer() { -// printf("DMA src %08x (%d), dst %08x (%d) cnt %d\n", m_src_addr, m_dma_ctrl & 3, m_dst_addr, m_dma_ctrl & 4, m_dma_cnt); - while (m_dma_cnt--) { - u8 data = 0; // open bus? + u8 data = 0; // TODO: open bus const u32 dma_src = m_src_addr++; const u32 dma_dst = m_dst_addr++; @@ -363,7 +355,7 @@ void sns_sa1_device::dma_transfer() if (((DCNT_SD()) == 1) && (DCNT_DD())) continue; if (((DCNT_SD()) == 2) && (!(DCNT_DD()))) continue; - int cycle = 1; // 1 cycle per memory accessing + int cycle = 1; // 1 cycle per memory access switch (DCNT_SD()) { case 0: // ROM @@ -423,7 +415,7 @@ void sns_sa1_device::dma_cctype2_transfer() const u32 ty = (BIT(m_cconv2_line, 0, 3) << 1); const u32 dst_addr = (m_dst_addr & ~((1 << (7 - m_dma_cconv_bits)) - 1)) + tx + ty; - // TODO: memory access/process cycle? + // TODO: memory access/process cycle for (u8 bit = 0; bit < bpp; bit++) { u8 byte = 0; @@ -462,7 +454,7 @@ u8 sns_sa1_device::host_r(offs_t offset) u8 sns_sa1_device::read_regs(offs_t offset) { u8 value = 0xff; // unverified - offset &= 0x1ff; // $2200 + offset gives the reg value to compare with docs + offset &= 0x1ff; // $2200 + offset gives the reg value to compare with docs switch (offset) { @@ -474,11 +466,11 @@ u8 sns_sa1_device::read_regs(offs_t offset) // H-Count Read Low if (!machine().side_effects_disabled()) { - //latch counters + // latch counters m_hcr = m_hpos; m_vcr = m_vpos; } - //then return h-count + // return h-count value = (m_hcr >> 0) & 0xff; break; case 0x103: @@ -494,27 +486,27 @@ u8 sns_sa1_device::read_regs(offs_t offset) value = (m_vcr >> 8) & 0xff; break; case 0x106: - // Math Result bits0-7 + // Math Result bits 0-7 value = (u64)(m_math_res >> 0) & 0xff; break; case 0x107: - // Math Result bits8-15 + // Math Result bits 8-15 value = (u64)(m_math_res >> 8) & 0xff; break; case 0x108: - // Math Result bits16-23 + // Math Result bits 16-23 value = (u64)(m_math_res >> 16) & 0xff; break; case 0x109: - // Math Result bits24-31 + // Math Result bits 24-31 value = (u64)(m_math_res >> 24) & 0xff; break; case 0x10a: - // Math Result bits32-39 + // Math Result bits 32-39 value = (u64)(m_math_res >> 32) & 0xff; break; case 0x10b: - // Math Overflow (above 40bit result) + // Math Overflow (above 40-bit result) value = m_math_overflow; break; case 0x10c: @@ -535,7 +527,7 @@ u8 sns_sa1_device::read_regs(offs_t offset) { if (m_drm) { - //auto-increment mode + // auto-increment mode m_vbit += m_vlen; m_vda += (m_vbit >> 3); m_vbit &= 7; @@ -560,20 +552,17 @@ void sns_sa1_device::host_w(offs_t offset, u8 data) { case 0x000: // SA-1 control flags -// printf("%02x to SA-1 control\n", data); if (CCNT_SA1_CPU_RDYB() && BIT(data, 5)) // Pull up reset pin m_sa1_reset_flag = true; if ((BIT(data, 5, 2) != 0) && (BIT(m_sa1_ctrl, 5, 2) == 0)) { -// printf("Engaging SA-1 reset\n"); m_sa1->set_input_line(INPUT_LINE_HALT, ASSERT_LINE); if (BIT(data, 5)) // Pull up reset pin m_sa1_reset_flag = true; } else if ((BIT(data, 5, 2) == 0) && (BIT(m_sa1_ctrl, 5, 2) != 0)) { -// printf("Releasing SA-1 reset\n"); m_sa1->set_input_line(INPUT_LINE_HALT, CLEAR_LINE); if (m_sa1_reset_flag && (!BIT(data, 5))) { @@ -594,13 +583,12 @@ void sns_sa1_device::host_w(offs_t offset, u8 data) recalc_irqs(); break; case 0x001: - // SNES SIE 00h SNES CPU Int Enable (W) + // SNES CPU Int Enable m_scpu_sie = data; -// printf("S-CPU IE = %02x\n", data); recalc_irqs(); break; case 0x002: - // SNES SIC 00h SNES CPU Int Clear (W) + // SNES CPU Int Clear if (BIT(data, 7)) // ack IRQ from SA-1 m_scpu_flags &= ~SCPU_IRQ_SA1; @@ -610,52 +598,52 @@ void sns_sa1_device::host_w(offs_t offset, u8 data) recalc_irqs(); break; case 0x003: - // SNES CRV - SA-1 CPU Reset Vector Lsb (W) + // SA-1 CPU Reset Vector LSB m_sa1_reset_vector &= 0xff00; m_sa1_reset_vector |= data; break; case 0x004: - // SNES CRV - SA-1 CPU Reset Vector Msb (W) + // SA-1 CPU Reset Vector MSB m_sa1_reset_vector &= 0x00ff; m_sa1_reset_vector |= (data<<8); break; case 0x005: - // SNES CNV - SA-1 CPU NMI Vector Lsb (W) + // SA-1 CPU NMI Vector LSB m_sa1_nmi_vector &= 0xff00; m_sa1_nmi_vector |= data; break; case 0x006: - // SNES CNV - SA-1 CPU NMI Vector Msb (W) + // SA-1 CPU NMI Vector MSB m_sa1_nmi_vector &= 0x00ff; m_sa1_nmi_vector |= (data<<8); break; case 0x007: - // SNES CIV - SA-1 CPU IRQ Vector Lsb (W) + // SA-1 CPU IRQ Vector LSB m_sa1_irq_vector &= 0xff00; m_sa1_irq_vector |= data; break; case 0x008: - // SNES CIV - SA-1 CPU IRQ Vector Msb (W) + // SA-1 CPU IRQ Vector MSB m_sa1_irq_vector &= 0x00ff; m_sa1_irq_vector |= (data<<8); break; case 0x020: - // SNES CXB - Super MMC Bank C (W) + // Super MMC Bank C m_bank_hi[0] = BIT(data, 7); // [00-1f][8000-ffff] is mirror of [c0-cf][0000-ffff] bank or first 1MB of ROM m_bank_rom[0] = data & 0x07; // ROM 1MB bank for [c0-cf] break; case 0x021: - // SNES DXB - Super MMC Bank D (W) + // Super MMC Bank D m_bank_hi[1] = BIT(data, 7); // [20-3f][8000-ffff] is mirror of [d0-df][0000-ffff] bank or second 1MB of ROM m_bank_rom[1] = data & 0x07; // ROM 1MB bank for [d0-df] break; case 0x022: - // SNES EXB - Super MMC Bank E (W) + // Super MMC Bank E m_bank_hi[2] = BIT(data, 7); // [80-9f][8000-ffff] is mirror of [e0-ef][0000-ffff] bank or third 1MB of ROM m_bank_rom[2] = data & 0x07; // ROM 1MB bank for [e0-ef] break; case 0x023: - // SNES FXB - Super MMC Bank F (W) + // Super MMC Bank F m_bank_hi[3] = BIT(data, 7); // [a0-bf][8000-ffff] is mirror of [e0-ef][0000-ffff] bank or fourth 1MB of ROM m_bank_rom[3] = data & 0x07; // ROM 1MB bank for [f0-ff] break; @@ -675,7 +663,7 @@ void sns_sa1_device::host_w(offs_t offset, u8 data) // enable writing to IRAM from SNES (1 bit for each 0x100 chunk) m_iram_write_snes = data; break; - case 0x031: // Both CDMA 00h Character Conversion DMA Parameters (W) + case 0x031: // Character Conversion DMA Parameters case 0x032: // DMA Source Device Start Address Low case 0x033: // DMA Source Device Start Address Mid case 0x034: // DMA Source Device Start Address High @@ -702,25 +690,21 @@ void sns_sa1_device::write_regs(offs_t offset, u8 data) if (SCNT_SNESCPU_IRQ()) { m_scpu_flags |= SCPU_IRQ_SA1; -// printf("SA-1 cause S-CPU IRQ\n"); } - // clear IRQ/NMI override flags in flags word + // acquire IRQ/NMI override flags from data m_scpu_flags &= ~(SCPU_IRQV_ALT|SCPU_NMIV_ALT); - - // and set them m_scpu_flags |= (data & (SCPU_IRQV_ALT|SCPU_NMIV_ALT)); recalc_irqs(); break; case 0x00a: - // SA-1 CIE 00h SA-1 CPU Int Enable (W) + // SA-1 CPU Int Enable m_sa1_sie = data; -// printf("SA-1 IE = %02x\n", data); recalc_irqs(); break; case 0x00b: - // SA-1 CIC 00h SA-1 CPU Int Clear (W) + // SA-1 CPU Int Clear if (BIT(data, 7)) m_sa1_flags &= ~SA1_IRQ_SCPU; @@ -736,27 +720,27 @@ void sns_sa1_device::write_regs(offs_t offset, u8 data) recalc_irqs(); break; case 0x00c: - // NMI Vector Low + // SA-1 NMI Vector Low m_nmi_vector = (m_nmi_vector & 0xff00) | (data << 0); break; case 0x00d: - // NMI Vector High + // SA-1 NMI Vector High m_nmi_vector = (m_nmi_vector & 0x00ff) | (data << 8); break; case 0x00e: - // IRQ Vector Low + // SA-1 IRQ Vector Low m_irq_vector = (m_irq_vector & 0xff00) | (data << 0); break; case 0x00f: - // IRQ Vector High + // SA-1 IRQ Vector High m_irq_vector = (m_irq_vector & 0x00ff) | (data << 8); break; case 0x010: - // SA-1 TMC 00h H/V Timer Control (W) + // H/V Timer Control m_timer_ctrl = data; break; case 0x011: - // SA-1 CTR - SA-1 CPU Timer Restart (W) + // CPU Timer Restart m_hpos = m_vpos = 0; m_sa1_timer->adjust(m_sa1->clocks_to_attotime(2), 0, m_sa1->clocks_to_attotime(2)); break; @@ -778,8 +762,8 @@ void sns_sa1_device::write_regs(offs_t offset, u8 data) break; case 0x025: // BWRAM bank & type from SA-1 side - m_bwram_sa1_source = BIT(data, 7); // 0 = normal, 1 = bitmap? - m_bwram_sa1 = data & 0x7f; // up to 128x8K banks here? + m_bwram_sa1_source = BIT(data, 7); // 0 = normal, 1 = bitmap + m_bwram_sa1 = data & 0x7f; // up to 128x8K banks here break; case 0x027: // enable writing to BWRAM from SA-1 @@ -790,11 +774,10 @@ void sns_sa1_device::write_regs(offs_t offset, u8 data) m_iram_write_sa1 = data; break; case 0x030: - // SA-1 DCNT 00h DMA Control (W) -// printf("%02x to SA-1 DMA control\n", data); + // DMA Control (W) m_dma_ctrl = data; break; - case 0x031: // Both CDMA 00h Character Conversion DMA Parameters (W) + case 0x031: // Character Conversion DMA Parameters (W) case 0x032: // DMA Source Device Start Address Low case 0x033: // DMA Source Device Start Address Mid case 0x034: // DMA Source Device Start Address High @@ -804,18 +787,18 @@ void sns_sa1_device::write_regs(offs_t offset, u8 data) shared_regs_w(offset, data); break; case 0x038: - // SA-1 DTC - DMA Terminal Counter Lsb (W) + // DMA Terminal Counter LSB m_dma_cnt &= 0xff00; m_dma_cnt |= data; break; case 0x039: - // SA-1 DTC - DMA Terminal Counter Msb (W) + // DMA Terminal Counter MSB m_dma_cnt &= 0x00ff; m_dma_cnt |= (data<<8); break; case 0x03f: // Format for BWRAM when mapped to bitmap - m_bwram_sa1_format = BIT(data, 7); // 0 = 4bit, 1 = 2bit + m_bwram_sa1_format = BIT(data, 7); // 0 = 4-bit, 1 = 2-bit break; case 0x040: case 0x041: @@ -839,7 +822,6 @@ void sns_sa1_device::write_regs(offs_t offset, u8 data) { if (DCNT_CDEN() && (!(DCNT_CDSEL()))) // CC DMA Type 2 { -// printf("SA-1: CC DMA type 2\n"); dma_cctype2_transfer(); } } @@ -865,14 +847,14 @@ void sns_sa1_device::write_regs(offs_t offset, u8 data) case 0x054: // Math B High m_math_b = (data << 8) | (m_math_b & 0x00ff); - // After Math B has been written, we do math + // After Math B has been written, perform the operation switch (m_math_ctlr) { - case 0: //signed multiplication (5 cycle required) + case 0: // signed multiplication (5 cycles required) m_math_res = (s16)m_math_a * (s16)m_math_b; m_math_b = 0; break; - case 1: //unsigned division (5 cycle required) + case 1: // unsigned division (5 cycles required) if (m_math_b == 0) m_math_res = 0; else @@ -882,7 +864,7 @@ void sns_sa1_device::write_regs(offs_t offset, u8 data) m_math_res = (u64)((remainder << 16) | quotient); } break; - case 2: //sigma (accumulative multiplication) (6 cycle required) + case 2: // sigma (accumulative multiplication) (6 cycles required) case 3: u64 acum = (s16)m_math_a * (s16)m_math_b; u64 mask = 0xffffffffffU; @@ -902,7 +884,7 @@ void sns_sa1_device::write_regs(offs_t offset, u8 data) if (!m_drm) { - //fixed mode + // fixed mode m_vbit += m_vlen; m_vda += (m_vbit >> 3); m_vbit &= 7; @@ -934,7 +916,7 @@ void sns_sa1_device::shared_regs_w(offs_t offset, u8 data) switch (offset) { case 0x031: - // Both CDMA 00h Character Conversion DMA Parameters (W) + // Character Conversion DMA Parameters (W) m_dma_ccparam = data; m_dma_cconv_size = CDMA_SIZE(); m_dma_cconv_bits = CDMA_CB(); @@ -976,7 +958,6 @@ void sns_sa1_device::shared_regs_w(offs_t offset, u8 data) { if ((!(DCNT_CDEN())) && DCNT_DD()) // Normal DMA to BWRAM { -// printf("SA-1: normal DMA to BWRAM\n"); dma_transfer(); } } @@ -1013,7 +994,7 @@ u8 sns_sa1_device::read_cconv1_dma(offs_t offset) const u32 tx = tile & ((1 << m_dma_cconv_size) - 1); u32 bwram_src = m_src_addr + ty * 8 * tile_stride + tx * bpp; - // TODO: memory access/process cycle? + // TODO: memory access/process cycle for (u32 y = 0; y < 8; y++) { u64 raw_pixels = 0; @@ -1062,14 +1043,14 @@ u8 sns_sa1_device::read_bwram(offs_t offset, bool bitmap) if (m_bwram_sa1_format) { - // 2bits mode + // 2-bit mode shift = ((offset & 3) << 1); mask = 0x03; offset >>= 2; } else { - // 4bits mode + // 4-bit mode shift = ((offset & 1) << 2); mask = 0x0f; offset >>= 1; @@ -1096,14 +1077,14 @@ void sns_sa1_device::write_bwram(offs_t offset, u8 data, bool bitmap) if (m_bwram_sa1_format) { - // 2bits mode + // 2-bit mode data = (data & 0x03) << ((offset & 3) << 1); mask = 0x03 << ((offset & 3) << 1); offset >>= 2; } else { - // 4bits mode + // 4-bit mode data = (data & 0x0f) << ((offset & 1) << 2); mask = 0x0f << ((offset & 1) << 2); offset >>= 1; @@ -1131,9 +1112,9 @@ u8 sns_sa1_device::rom_r(offs_t offset) const u8 slot = (BIT(offset, 23) << 1) | BIT(offset, 21); u8 bank; // 256 banks (64 Mbit limited) - if (!m_bank_hi[slot]) // when HiROM mapping is disabled, we always access each 1MB here + if (!m_bank_hi[slot]) // when HiROM mapping is disabled, we always access each 1MB here bank = BIT(offset, 16, 5) | (slot << 5); - else // when HiROM mapping is enabled, we mirror [(cx,dx,ex,fx)][0000-ffff] bank + else // when HiROM mapping is enabled, we mirror [(cx,dx,ex,fx)][0000-ffff] bank bank = BIT(offset, 16, 5) | (m_bank_rom[slot] << 5); ret = m_rom[(rom_bank_map[bank] << 15) | (offset & 0x7fff)]; @@ -1174,13 +1155,13 @@ u8 sns_sa1_device::chip_read(offs_t offset) u16 address = offset & 0xffff; if (offset < 0x400000 && address >= 0x2200 && address < 0x2400) - return host_r(address & 0x1ff); // SA-1 Regs + return host_r(address & 0x1ff); // SA-1 Regs if (offset < 0x400000 && address >= 0x3000 && address < 0x3800) - return read_iram(address & 0x7ff); // Internal SA-1 RAM (2K) + return read_iram(address & 0x7ff); if (offset < 0x400000 && address >= 0x6000 && address < 0x8000) - return read_bwram<false>((m_bwram_snes * 0x2000) + (offset & 0x1fff)); // SA-1 BWRAM + return read_bwram<false>((m_bwram_snes * 0x2000) + (offset & 0x1fff)); if (offset >= 0x400000 && offset < 0x500000) return read_bwram<false>(offset & 0xfffff); // SA-1 BWRAM again (but not called for the [c0-cf] range, because it's not mirrored) @@ -1194,16 +1175,16 @@ void sns_sa1_device::chip_write(offs_t offset, u8 data) u16 address = offset & 0xffff; if (offset < 0x400000 && address >= 0x2200 && address < 0x2400) - host_w(address & 0x1ff, data); // SA-1 Regs + host_w(address & 0x1ff, data); // SA-1 Regs if (offset < 0x400000 && address >= 0x3000 && address < 0x3800) { if (BIT(m_iram_write_snes, BIT(address, 8, 3))) - write_iram(address & 0x7ff, data); // Internal SA-1 RAM (2K) + write_iram(address & 0x7ff, data); } if (offset < 0x400000 && address >= 0x6000 && address < 0x8000) - write_bwram((m_bwram_snes * 0x2000) + (offset & 0x1fff), data); // SA-1 BWRAM + write_bwram((m_bwram_snes * 0x2000) + (offset & 0x1fff), data); if (offset >= 0x400000 && offset < 0x500000) write_bwram(offset & 0xfffff, data); // SA-1 BWRAM again (but not called for the [c0-cf] range, because it's not mirrored) @@ -1220,7 +1201,7 @@ void sns_sa1_device::chip_write(offs_t offset, u8 data) u8 sns_sa1_device::sa1_rom_r(offs_t offset) { - if (bus_conflict_rom()) // bus conflict? + if (bus_conflict_rom()) m_sa1->adjust_icount(-1); // wait 1 cycle return rom_r(offset); @@ -1228,24 +1209,24 @@ u8 sns_sa1_device::sa1_rom_r(offs_t offset) u8 sns_sa1_device::sa1_iram_r(offs_t offset) { - if (bus_conflict_iram()) // bus conflict? - m_sa1->adjust_icount(-2); // wait 2 cycle + if (bus_conflict_iram()) + m_sa1->adjust_icount(-2); // wait 2 cycles return read_iram(offset & 0x7ff); } void sns_sa1_device::sa1_iram_w(offs_t offset, u8 data) { - if (bus_conflict_iram()) // bus conflict? - m_sa1->adjust_icount(-2); // wait 2 cycle + if (bus_conflict_iram()) + m_sa1->adjust_icount(-2); // wait 2 cycles if (BIT(m_iram_write_sa1, BIT(offset, 8, 3))) - write_iram(offset & 0x7ff, data); // Internal SA-1 RAM (2K) + write_iram(offset & 0x7ff, data); } u8 sns_sa1_device::sa1_bwram_r(offs_t offset, bool bitmap) { - if (bus_conflict_bwram()) // bus conflict? - m_sa1->adjust_icount(-3); // wait 3 cycle + if (bus_conflict_bwram()) + m_sa1->adjust_icount(-3); // wait 3 cycles else m_sa1->adjust_icount(-1); // wait 1 cycle @@ -1254,8 +1235,8 @@ u8 sns_sa1_device::sa1_bwram_r(offs_t offset, bool bitmap) void sns_sa1_device::sa1_bwram_w(offs_t offset, u8 data, bool bitmap) { - if (bus_conflict_bwram()) // bus conflict? - m_sa1->adjust_icount(-3); // wait 3 cycle + if (bus_conflict_bwram()) + m_sa1->adjust_icount(-3); // wait 3 cycles else m_sa1->adjust_icount(-1); // wait 1 cycle @@ -1272,21 +1253,21 @@ u8 sns_sa1_device::sa1_hi_r(offs_t offset) if (address < 0x6000) { if (address < 0x0800) - return sa1_iram_r(offset); // Internal SA-1 RAM (2K) + return sa1_iram_r(offset); else if (address >= 0x2200 && address < 0x2400) - return read_regs(offset & 0x1ff); // SA-1 Regs + return read_regs(offset & 0x1ff); else if (address >= 0x3000 && address < 0x3800) - return sa1_iram_r(offset); // Internal SA-1 RAM (2K) + return sa1_iram_r(offset); } else if (address < 0x8000) - return sa1_bwram_r((m_bwram_sa1 * 0x2000) + (offset & 0x1fff), m_bwram_sa1_source); // SA-1 BWRAM + return sa1_bwram_r((m_bwram_sa1 * 0x2000) + (offset & 0x1fff), m_bwram_sa1_source); else - return sa1_rom_r(offset | 0x800000); // ROM + return sa1_rom_r(offset | 0x800000); - return 0xff; // maybe open bus? same as the main system one or diff? (currently not accessible from carts anyway...) + return 0xff; // TOOD: Maybe open bus. Check if same as the main system or different (currently not accessible from carts anyway). } else - return sa1_rom_r(offset | 0xc00000); // ROM + return sa1_rom_r(offset | 0xc00000); } u8 sns_sa1_device::sa1_lo_r(offs_t offset) @@ -1298,17 +1279,17 @@ u8 sns_sa1_device::sa1_lo_r(offs_t offset) if (address < 0x6000) { if (address < 0x0800) - return sa1_iram_r(offset); // Internal SA-1 RAM (2K) + return sa1_iram_r(offset); else if (address >= 0x2200 && address < 0x2400) - return read_regs(offset & 0x1ff); // SA-1 Regs + return read_regs(offset & 0x1ff); else if (address >= 0x3000 && address < 0x3800) - return sa1_iram_r(offset); // Internal SA-1 RAM (2K) + return sa1_iram_r(offset); } else if (address < 0x8000) - return sa1_bwram_r((m_bwram_sa1 * 0x2000) + (offset & 0x1fff), m_bwram_sa1_source); // SA-1 BWRAM + return sa1_bwram_r((m_bwram_sa1 * 0x2000) + (offset & 0x1fff), m_bwram_sa1_source); // SA-1 BWRAM else { - if (bus_conflict_rom()) // bus conflict? + if (bus_conflict_rom()) m_sa1->adjust_icount(-1); // wait 1 cycle if (offset == 0xffee) @@ -1336,17 +1317,17 @@ u8 sns_sa1_device::sa1_lo_r(offs_t offset) return m_sa1_reset_vector >> 8; } else - return rom_r(offset); // ROM + return rom_r(offset); } - return 0xff; // maybe open bus? same as the main system one or diff? (currently not accessible from carts anyway...) + return 0xff; // TOOD: Maybe open bus. Check if same as the main system or different (currently not accessible from carts anyway). } else if (offset < 0x500000) - return sa1_bwram_r(offset & 0xfffff, false); // SA-1 BWRAM (not mirrored above!) + return sa1_bwram_r(offset & 0xfffff, false); // SA-1 BWRAM (not mirrored above) else if (offset >= 0x600000 && offset < 0x700000) return sa1_bwram_r(offset & 0xfffff, true); // SA-1 BWRAM Bitmap mode else - return 0xff; // nothing should be mapped here, so maybe open bus? + return 0xff; // nothing should be mapped here, so maybe open bus } void sns_sa1_device::sa1_hi_w(offs_t offset, u8 data) @@ -1357,23 +1338,23 @@ void sns_sa1_device::sa1_hi_w(offs_t offset, u8 data) if (address < 0x6000) { if (address < 0x0800) - sa1_iram_w(offset, data); // Internal SA-1 RAM (2K) + sa1_iram_w(offset, data); else if (address >= 0x2200 && address < 0x2400) - write_regs(offset & 0x1ff, data); // SA-1 Regs + write_regs(offset & 0x1ff, data); else if (address >= 0x3000 && address < 0x3800) - sa1_iram_w(offset, data); // Internal SA-1 RAM (2K) + sa1_iram_w(offset, data); } else if (address < 0x8000) - sa1_bwram_w((m_bwram_sa1 * 0x2000) + (offset & 0x1fff), data, m_bwram_sa1_source); // SA-1 BWRAM + sa1_bwram_w((m_bwram_sa1 * 0x2000) + (offset & 0x1fff), data, m_bwram_sa1_source); } } void sns_sa1_device::sa1_lo_w(offs_t offset, u8 data) { if (offset >= 0x400000 && offset < 0x500000) - sa1_bwram_w(offset & 0xfffff, data, false); // SA-1 BWRAM (not mirrored above!) + sa1_bwram_w(offset & 0xfffff, data, false); // SA-1 BWRAM (not mirrored above) else if (offset >= 0x600000 && offset < 0x700000) - sa1_bwram_w(offset & 0xfffff, data, true); // SA-1 BWRAM Bitmap mode + sa1_bwram_w(offset & 0xfffff, data, true); // SA-1 BWRAM Bitmap mode else sa1_hi_w(offset, data); } diff --git a/src/devices/bus/snes/sa1.h b/src/devices/bus/snes/sa1.h index fcc9bbd9dc1..8b68820a826 100644 --- a/src/devices/bus/snes/sa1.h +++ b/src/devices/bus/snes/sa1.h @@ -20,14 +20,11 @@ public: sns_sa1_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock); protected: - static const device_timer_id TIMER_SA1 = 0; // SA-1 internal timer (18 bit linear timer or HV timer) - // device-level overrides 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; // reading and writing virtual u8 read_l(offs_t offset) override; @@ -39,6 +36,8 @@ protected: virtual u8 chip_read(offs_t offset) override; virtual void chip_write(offs_t offset, u8 data) override; + TIMER_CALLBACK_MEMBER(timer_tick); + private: u8 var_length_read(offs_t offset); void dma_transfer(); diff --git a/src/devices/bus/snes_ctrl/bcbattle.cpp b/src/devices/bus/snes_ctrl/bcbattle.cpp index 3b8f6e8542d..c5d78bc04b3 100644 --- a/src/devices/bus/snes_ctrl/bcbattle.cpp +++ b/src/devices/bus/snes_ctrl/bcbattle.cpp @@ -26,47 +26,40 @@ void snes_bcbattle_device::device_add_mconfig(machine_config &config) } -//------------------------------------------------- -// device_timer - handler timer events -//------------------------------------------------- - -// This part is the hacky replacement for the real Barcode unit [shared with NES implementation]: +// This part is a hacky replacement for the real Barcode unit [shared with NES implementation]: // code periodically checks whether a new code has been scanned and it moves it to the // m_current_barcode array -void snes_bcbattle_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(snes_bcbattle_device::scan_tick) { - if (id == TIMER_BATTLER) + int old = m_new_code; + m_new_code = m_reader->get_pending_code(); + // has something new been scanned? + if (old < m_new_code) { - int old = m_new_code; - m_new_code = m_reader->get_pending_code(); - // has something new been scanned? - if (old < m_new_code) + if (m_reader->get_byte_length() == 13) { - if (m_reader->get_byte_length() == 13) - { - for (int i = 0; i < 13; i++) - m_current_barcode[i] = m_reader->read_code() + '0'; - } - else if (m_reader->get_byte_length() == 8) - { - for (int i = 0; i < 5; i++) - m_current_barcode[i] = 0x20; - for (int i = 5; i < 13; i++) - m_current_barcode[i] = m_reader->read_code() + '0'; - } - // read one more, to reset the internal byte counter - m_reader->read_code(); - - // the string "SUNSOFT" is accepted as well by Barcode World - m_current_barcode[13] = 'E'; - m_current_barcode[14] = 'P'; - m_current_barcode[15] = 'O'; - m_current_barcode[16] = 'C'; - m_current_barcode[17] = 'H'; - m_current_barcode[18] = 0x0d; - m_current_barcode[19] = 0x0a; - m_pending_code = 1; + for (int i = 0; i < 13; i++) + m_current_barcode[i] = m_reader->read_code() + '0'; + } + else if (m_reader->get_byte_length() == 8) + { + for (int i = 0; i < 5; i++) + m_current_barcode[i] = 0x20; + for (int i = 5; i < 13; i++) + m_current_barcode[i] = m_reader->read_code() + '0'; } + // read one more, to reset the internal byte counter + m_reader->read_code(); + + // the string "SUNSOFT" is accepted as well by Barcode World + m_current_barcode[13] = 'E'; + m_current_barcode[14] = 'P'; + m_current_barcode[15] = 'O'; + m_current_barcode[16] = 'C'; + m_current_barcode[17] = 'H'; + m_current_barcode[18] = 0x0d; + m_current_barcode[19] = 0x0a; + m_pending_code = 1; } } @@ -98,7 +91,7 @@ void snes_bcbattle_device::device_start() // lacking emulation of the standalone Barcode Battler, we refresh periodically the input from the reader // proper emulation would have the standalone unit acknowledging that a new barcode has been scanned // and sending the proper serial bits, instead of our read_current_bit() function! - battler_timer = timer_alloc(TIMER_BATTLER); + battler_timer = timer_alloc(FUNC(snes_bcbattle_device::scan_tick), this); battler_timer->adjust(attotime::zero, 0, machine().device<cpu_device>("maincpu")->cycles_to_attotime(1000)); save_item(NAME(m_current_barcode)); diff --git a/src/devices/bus/snes_ctrl/bcbattle.h b/src/devices/bus/snes_ctrl/bcbattle.h index 13c53dd9b38..a7073ac4ba0 100644 --- a/src/devices/bus/snes_ctrl/bcbattle.h +++ b/src/devices/bus/snes_ctrl/bcbattle.h @@ -32,7 +32,6 @@ protected: // device-level overrides virtual void device_start() override; virtual void device_reset() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; virtual void device_add_mconfig(machine_config &config) override; @@ -42,9 +41,9 @@ protected: int read_current_bit(); -private: - static constexpr device_timer_id TIMER_BATTLER = 1; + TIMER_CALLBACK_MEMBER(scan_tick); +private: required_device<barcode_reader_device> m_reader; uint8_t m_current_barcode[20]; int m_pending_code, m_new_code, m_transmitting, m_cur_bit, m_cur_byte; diff --git a/src/devices/bus/snes_ctrl/miracle.cpp b/src/devices/bus/snes_ctrl/miracle.cpp index ec84ef3dc3c..f20647a10b4 100644 --- a/src/devices/bus/snes_ctrl/miracle.cpp +++ b/src/devices/bus/snes_ctrl/miracle.cpp @@ -32,15 +32,12 @@ void snes_miracle_device::device_add_mconfig(machine_config &config) //------------------------------------------------- -// device_timer - handler timer events +// strobe_tick - increment strobe counter //------------------------------------------------- -void snes_miracle_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(snes_miracle_device::strobe_tick) { - if (id == TIMER_STROBE_ON) - { - m_strobe_clock++; - } + m_strobe_clock++; } //************************************************************************** @@ -70,7 +67,7 @@ snes_miracle_device::snes_miracle_device(const machine_config &mconfig, const ch void snes_miracle_device::device_start() { - strobe_timer = timer_alloc(TIMER_STROBE_ON); + strobe_timer = timer_alloc(FUNC(snes_miracle_device::strobe_tick), this); strobe_timer->adjust(attotime::never); save_item(NAME(m_strobe_on)); save_item(NAME(m_sent_bits)); diff --git a/src/devices/bus/snes_ctrl/miracle.h b/src/devices/bus/snes_ctrl/miracle.h index 53306d36496..b2bf08d2a49 100644 --- a/src/devices/bus/snes_ctrl/miracle.h +++ b/src/devices/bus/snes_ctrl/miracle.h @@ -31,15 +31,12 @@ public: snes_miracle_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock); protected: - static constexpr device_timer_id TIMER_STROBE_ON = 0; - static constexpr int XMIT_RING_SIZE = 64; static constexpr int RECV_RING_SIZE = 64; // device-level overrides virtual void device_start() override; virtual void device_reset() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; virtual void device_add_mconfig(machine_config &config) override; @@ -54,6 +51,8 @@ protected: void xmit_char(uint8_t data); + TIMER_CALLBACK_MEMBER(strobe_tick); + required_device<midi_port_device> m_midiin, m_midiout; emu_timer *strobe_timer; diff --git a/src/devices/bus/spc1000/fdd.cpp b/src/devices/bus/spc1000/fdd.cpp index 36c4c90b958..fe668127328 100644 --- a/src/devices/bus/spc1000/fdd.cpp +++ b/src/devices/bus/spc1000/fdd.cpp @@ -156,7 +156,7 @@ spc1000_fdd_exp_device::spc1000_fdd_exp_device(const machine_config &mconfig, co void spc1000_fdd_exp_device::device_start() { - m_timer_tc = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(spc1000_fdd_exp_device::tc_off), this)); + m_timer_tc = timer_alloc(FUNC(spc1000_fdd_exp_device::tc_off), this); } //------------------------------------------------- diff --git a/src/devices/bus/spectrum/mgt.cpp b/src/devices/bus/spectrum/mgt.cpp index e8f04df4aa0..581a748dcea 100644 --- a/src/devices/bus/spectrum/mgt.cpp +++ b/src/devices/bus/spectrum/mgt.cpp @@ -378,6 +378,8 @@ void spectrum_disciple_device::device_start() save_item(NAME(m_map)); save_item(NAME(m_control)); save_item(NAME(m_reset_delay)); + + m_reset_timer = timer_alloc(FUNC(spectrum_disciple_device::reset_tick), this); } //------------------------------------------------- @@ -394,7 +396,7 @@ void spectrum_disciple_device::device_reset() m_romcs = 0; m_map = false; m_reset_delay = true; - timer_set(attotime::from_usec(10), TIMER_RESET); // delay time is a guess + m_reset_timer->adjust(attotime::from_usec(10)); // delay time is a guess } //************************************************************************** @@ -716,14 +718,7 @@ void spectrum_disciple_device::mreq_w(offs_t offset, uint8_t data) m_exp->mreq_w(offset, data); } -void spectrum_disciple_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(spectrum_disciple_device::reset_tick) { - switch (id) - { - case TIMER_RESET: - m_reset_delay = false; - break; - default: - throw emu_fatalerror("Unknown id in spectrum_disciple_device::device_timer"); - } + m_reset_delay = false; } diff --git a/src/devices/bus/spectrum/mgt.h b/src/devices/bus/spectrum/mgt.h index 628477c1f8a..35d168b10ae 100644 --- a/src/devices/bus/spectrum/mgt.h +++ b/src/devices/bus/spectrum/mgt.h @@ -74,15 +74,9 @@ public: DECLARE_INPUT_CHANGED_MEMBER(inhibit_button) { if (!newval) m_romcs = 0; } protected: - enum - { - TIMER_RESET - }; - // 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 void device_add_mconfig(machine_config &config) override; @@ -96,6 +90,8 @@ protected: virtual void iorq_w(offs_t offset, uint8_t data) override; virtual DECLARE_READ_LINE_MEMBER(romcs) override; + TIMER_CALLBACK_MEMBER(reset_tick); + private: required_device<spectrum_expansion_slot_device> m_exp; required_ioport m_joy1; @@ -105,6 +101,7 @@ private: bool m_map; u8 m_control; bool m_reset_delay; + emu_timer *m_reset_timer; }; diff --git a/src/devices/bus/ss50/dc5.cpp b/src/devices/bus/ss50/dc5.cpp index 764b6ada245..dd58758722a 100644 --- a/src/devices/bus/ss50/dc5.cpp +++ b/src/devices/bus/ss50/dc5.cpp @@ -292,7 +292,7 @@ void ss50_dc5_device::device_start() m_fdc_status = 0; m_control_register = 0; m_fdc_side = 0; - m_floppy_motor_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(ss50_dc5_device::floppy_motor_callback),this)); + m_floppy_motor_timer = timer_alloc(FUNC(ss50_dc5_device::floppy_motor_callback), this); m_motor_timer_out = 0; m_fdc->set_force_ready(0); m_fdc_prog_clock_div = 12; diff --git a/src/devices/bus/ss50/mpt.cpp b/src/devices/bus/ss50/mpt.cpp index 28b8b711d50..f9078aee4ac 100644 --- a/src/devices/bus/ss50/mpt.cpp +++ b/src/devices/bus/ss50/mpt.cpp @@ -89,7 +89,7 @@ void ss50_mpt_device::device_add_mconfig(machine_config &config) void ss50_mpt_device::device_start() { - m_mpt_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(ss50_mpt_device::mpt_timer_callback),this)); + m_mpt_timer = timer_alloc(FUNC(ss50_mpt_device::mpt_timer_callback), this); m_mpt_timer_state = 0; save_item(NAME(m_mpt_timer_state)); diff --git a/src/devices/bus/sunkbd/hlekbd.cpp b/src/devices/bus/sunkbd/hlekbd.cpp index 94ff16a5fce..db798a716fb 100644 --- a/src/devices/bus/sunkbd/hlekbd.cpp +++ b/src/devices/bus/sunkbd/hlekbd.cpp @@ -998,7 +998,7 @@ void hle_device_base::device_add_mconfig(machine_config &config) void hle_device_base::device_start() { m_leds.resolve(); - m_click_timer = timer_alloc(CLICK_TIMER_ID); + m_click_timer = timer_alloc(FUNC(hle_device_base::click_off), this); save_item(NAME(m_make_count)); save_item(NAME(m_rx_state)); @@ -1054,22 +1054,13 @@ void hle_device_base::device_reset() /*-------------------------------------------------- - hle_device_base::device_timer - handle timed events + click_off - turn the clicker off --------------------------------------------------*/ -void hle_device_base::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(hle_device_base::click_off) { - switch (id) - { - case CLICK_TIMER_ID: - m_beeper_state &= ~uint8_t(BEEPER_CLICK); - m_beeper->set_state(m_beeper_state ? 1 : 0); - break; - - default: - break; - } + m_beeper_state &= ~uint8_t(BEEPER_CLICK); + m_beeper->set_state(m_beeper_state ? 1 : 0); } diff --git a/src/devices/bus/sunkbd/hlekbd.h b/src/devices/bus/sunkbd/hlekbd.h index b57ebec9ae5..3ed680b24c6 100644 --- a/src/devices/bus/sunkbd/hlekbd.h +++ b/src/devices/bus/sunkbd/hlekbd.h @@ -38,7 +38,6 @@ protected: virtual void device_add_mconfig(machine_config &config) override; virtual void device_start() override; virtual void device_reset() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; // device_buffered_serial_interface overrides virtual void tra_callback() override; @@ -51,6 +50,8 @@ protected: // customised transmit_byte method void transmit_byte(uint8_t byte); + TIMER_CALLBACK_MEMBER(click_off); + required_ioport m_dips; private: diff --git a/src/devices/bus/thomson/cd90_015.cpp b/src/devices/bus/thomson/cd90_015.cpp index 976fb6a8884..6f9b2822647 100644 --- a/src/devices/bus/thomson/cd90_015.cpp +++ b/src/devices/bus/thomson/cd90_015.cpp @@ -61,15 +61,15 @@ void cd90_015_device::device_add_mconfig(machine_config &config) FLOPPY_CONNECTOR(config, m_floppy[3], floppy_drives, nullptr, floppy_formats).enable_sound(true); } -void cd90_015_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(cd90_015_device::motor_tick) { - m_floppy[id]->get_device()->mon_w(1); + m_floppy[param]->get_device()->mon_w(1); } void cd90_015_device::device_start() { for(int i=0; i != 4; i++) - m_motor_timer[i] = timer_alloc(i); + m_motor_timer[i] = timer_alloc(FUNC(cd90_015_device::motor_tick), this); save_item(NAME(m_select)); } @@ -101,7 +101,7 @@ void cd90_015_device::select_w(u8 data) if(started & (1 << i)) { if(m_floppy[i]->get_device()) { m_floppy[i]->get_device()->mon_w(0); - m_motor_timer[i]->adjust(attotime::from_seconds(5)); + m_motor_timer[i]->adjust(attotime::from_seconds(5), i); } } diff --git a/src/devices/bus/thomson/cd90_015.h b/src/devices/bus/thomson/cd90_015.h index b8e1ff17a83..b2a4069e8cc 100644 --- a/src/devices/bus/thomson/cd90_015.h +++ b/src/devices/bus/thomson/cd90_015.h @@ -26,7 +26,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(motor_tick); private: required_device<mc6843_device> m_fdc; diff --git a/src/devices/bus/thomson/cd90_351.cpp b/src/devices/bus/thomson/cd90_351.cpp index c43880dbc70..44962c00115 100644 --- a/src/devices/bus/thomson/cd90_351.cpp +++ b/src/devices/bus/thomson/cd90_351.cpp @@ -78,7 +78,7 @@ void cd90_351_device::device_add_mconfig(machine_config &config) void cd90_351_device::device_start() { m_rom_bank->configure_entries(0, 4, m_rom->base(), 0x800); - m_timer_motoroff = timer_alloc(ID_MOTOROFF); + m_timer_motoroff = timer_alloc(FUNC(cd90_351_device::motor_off), this); save_item(NAME(m_cmd0)); save_item(NAME(m_cmd1)); @@ -122,15 +122,11 @@ void cd90_351_device::device_reset() m_cur_floppy = nullptr; } -void cd90_351_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(cd90_351_device::motor_off) { - switch(id) { - case ID_MOTOROFF: - logerror("motor off\n"); - if(m_cur_floppy) - m_cur_floppy->mon_w(1); - break; - } + logerror("motor off\n"); + if(m_cur_floppy) + m_cur_floppy->mon_w(1); } void cd90_351_device::device_post_load() diff --git a/src/devices/bus/thomson/cd90_351.h b/src/devices/bus/thomson/cd90_351.h index 78d0bda9033..6609eddf7a8 100644 --- a/src/devices/bus/thomson/cd90_351.h +++ b/src/devices/bus/thomson/cd90_351.h @@ -26,14 +26,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 void device_post_load() override; -private: - enum { - ID_MOTOROFF = 0, - }; + TIMER_CALLBACK_MEMBER(motor_off); +private: enum { S0_BYTE = 0x80, S0_END = 0x10, diff --git a/src/devices/bus/thomson/nanoreseau.cpp b/src/devices/bus/thomson/nanoreseau.cpp index 579400aab01..418d9ce59e5 100644 --- a/src/devices/bus/thomson/nanoreseau.cpp +++ b/src/devices/bus/thomson/nanoreseau.cpp @@ -86,7 +86,7 @@ void nanoreseau_device::rom_map(address_map &map) void nanoreseau_device::io_map(address_map &map) { map(0, 3).rw(m_mc6854, FUNC(mc6854_device::read), FUNC(mc6854_device::write)); - if(!m_no_id) + if (!m_no_id) map(8, 8).r(FUNC(nanoreseau_device::id_r)); } @@ -108,7 +108,7 @@ void nanoreseau_device::device_add_mconfig(machine_config &config) void nanoreseau_device::device_start() { - m_timer = timer_alloc(0); + m_timer = timer_alloc(FUNC(nanoreseau_device::answer_tick), this); save_item(NAME(m_answer_step)); } @@ -127,14 +127,13 @@ ioport_constructor nanoreseau_device::device_input_ports() const /*********************** Network ************************/ /* The network extension is built as an external floppy controller. - It uses the same ROM and I/O space, and so, it is natural to have the - toplevel network emulation here! -*/ + It uses the same ROM and I/O space, so it is natural to have the + top-level network emulation here. -/* NOTE: This is work in progress! - For the moment, only hand-checks works: the TO7 can take the line, then - perform a DKBOOT request. We do not have the server emulated yet, so, - no way to answer the request. + NOTE: This is work in progress. + For the moment, only hand-checks work: the TO7 can take the line, then + perform a DKBOOT request. We do not have the server emulated yet, so + there is no way to answer the request. */ /* consigne DKBOOT @@ -166,11 +165,11 @@ ioport_constructor nanoreseau_device::device_input_ports() const */ -void nanoreseau_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(nanoreseau_device::answer_tick) { - m_answer_step ++; + m_answer_step++; m_mc6854->set_cts(m_answer_step & 1); - if(m_answer_step < 4) + if (m_answer_step < 4) m_timer->adjust(attotime::from_usec(100)); } @@ -181,7 +180,7 @@ void nanoreseau_device::got_frame(uint8_t *data, int length) frame += util::string_format(" %02x", data[i]); logerror("%s\n", frame); - if(data[1] == 0xff) { + if (data[1] == 0xff) { logerror("frame: %d phones %d\n", data[2], data[0]); m_answer_step = 0; m_timer->adjust(attotime::from_usec(100)); @@ -192,7 +191,7 @@ void nanoreseau_device::got_frame(uint8_t *data, int length) memcpy(name, data + 12, 32); name[32] = 0; for(int i=0; i<32; i++) - if(name[i] < 32 || name[i] >= 127) + if (name[i] < 32 || name[i] >= 127) name[i]='.'; logerror("DKBOOT system %s appli %s\n", data[10] == 0 ? "TO7" : data[10] == 1 ? "MO5" : data[10] == 2 ? "TO7/70" : "?", name); } diff --git a/src/devices/bus/thomson/nanoreseau.h b/src/devices/bus/thomson/nanoreseau.h index 85b48e02f6c..1d7cde2ce9a 100644 --- a/src/devices/bus/thomson/nanoreseau.h +++ b/src/devices/bus/thomson/nanoreseau.h @@ -25,7 +25,8 @@ protected: virtual void device_start() override; virtual void device_reset() 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(answer_tick); private: required_device<mc6854_device> m_mc6854; diff --git a/src/devices/bus/ti8x/bitsocket.cpp b/src/devices/bus/ti8x/bitsocket.cpp index d824bf35331..1c4feb4ed4f 100644 --- a/src/devices/bus/ti8x/bitsocket.cpp +++ b/src/devices/bus/ti8x/bitsocket.cpp @@ -26,18 +26,14 @@ public: bit_socket_device(machine_config const &mconfig, char const *tag, device_t *owner, uint32_t clock); protected: - enum - { - TIMER_ID_POLL = 1 - }; - virtual void device_add_mconfig(machine_config &config) override; virtual void device_start() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; virtual DECLARE_WRITE_LINE_MEMBER(input_tip) override; virtual DECLARE_WRITE_LINE_MEMBER(input_ring) override; + TIMER_CALLBACK_MEMBER(poll_tick); + private: required_device<bitbanger_device> m_stream; emu_timer * m_poll_timer; @@ -68,7 +64,7 @@ void bit_socket_device::device_add_mconfig(machine_config &config) void bit_socket_device::device_start() { - m_poll_timer = timer_alloc(TIMER_ID_POLL); + m_poll_timer = timer_alloc(FUNC(bit_socket_device::poll_tick), this); save_item(NAME(m_tip_in)); save_item(NAME(m_ring_in)); @@ -79,23 +75,13 @@ void bit_socket_device::device_start() } -void bit_socket_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(bit_socket_device::poll_tick) { - switch (id) + u8 data; + while (m_stream->input(&data, 1)) { - case TIMER_ID_POLL: - { - u8 data; - while (m_stream->input(&data, 1)) - { - if (BIT(data, 1)) output_tip(BIT(data, 0)); - if (BIT(data, 2)) output_ring(BIT(data, 0)); - } - } - break; - - default: - break; + if (BIT(data, 1)) output_tip(BIT(data, 0)); + if (BIT(data, 2)) output_ring(BIT(data, 0)); } } diff --git a/src/devices/bus/ti99/internal/992board.cpp b/src/devices/bus/ti99/internal/992board.cpp index bb1c9be5a78..7dae38759ee 100644 --- a/src/devices/bus/ti99/internal/992board.cpp +++ b/src/devices/bus/ti99/internal/992board.cpp @@ -20,14 +20,14 @@ #include "992board.h" #define LOG_WARN (1U<<1) // Warnings -#define LOG_CRU (1U<<2) // CRU logging -#define LOG_CASSETTE (1U<<3) // Cassette logging -#define LOG_HEXBUS (1U<<4) // Hexbus logging -#define LOG_BANK (1U<<5) // Change ROM banks +#define LOG_CRU (1U<<2) // CRU logging +#define LOG_CASSETTE (1U<<3) // Cassette logging +#define LOG_HEXBUS (1U<<4) // Hexbus logging +#define LOG_BANK (1U<<5) // Change ROM banks #define LOG_KEYBOARD (1U<<6) // Keyboard operation #define LOG_EXPRAM (1U<<7) // Expansion RAM -#define VERBOSE ( LOG_GENERAL | LOG_WARN ) +#define VERBOSE (LOG_GENERAL | LOG_WARN) #include "logmacro.h" @@ -165,28 +165,28 @@ std::string video992_device::tts(attotime t) { char buf[256]; const char *sign = ""; - if(t.seconds() < 0) { - t = attotime::zero-t; + if (t.seconds() < 0) { + t = attotime::zero - t; sign = "-"; } int nsec = t.attoseconds() / ATTOSECONDS_PER_NANOSECOND; - sprintf(buf, "%s%04d.%03d,%03d,%03d", sign, int(t.seconds()), nsec/1000000, (nsec/1000)%1000, nsec % 1000); + sprintf(buf, "%s%04d.%03d,%03d,%03d", sign, int(t.seconds()), nsec / 1000000, (nsec / 1000) % 1000, nsec % 1000); return buf; } - -void video992_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(video992_device::hold_cpu) { int raw_vpos = screen().vpos(); - if (id == HOLD_TIME) - { - // logerror("release time: %s, diff: %s\n", tts(machine().time()), tts(machine().time()-m_hold_time)); - // We're holding the CPU; release it until the next start - m_hold_cb(CLEAR_LINE); - m_free_timer->adjust(screen().time_until_pos((raw_vpos+1) % screen().height(), HORZ_DISPLAY_START)); - return; - } + // logerror("release time: %s, diff: %s\n", tts(machine().time()), tts(machine().time()-m_hold_time)); + // We're holding the CPU; release it until the next start + m_hold_cb(CLEAR_LINE); + m_free_timer->adjust(screen().time_until_pos((raw_vpos+1) % screen().height(), HORZ_DISPLAY_START)); +} + +TIMER_CALLBACK_MEMBER(video992_device::free_cpu) +{ + int raw_vpos = screen().vpos(); // logerror("hold time: %s\n", tts(machine().time())); if (m_videna) @@ -210,23 +210,23 @@ void video992_device::device_timer(emu_timer &timer, device_timer_id id, int par // logerror("draw line %d\n", vpos); // Get control byte uint8_t control = m_mem_read_cb(0xef00); - bool text_white = ((control & 0x04)!=0); - bool border_white = ((control & 0x02)!=0); - bool background_white = ((control & 0x01)!=0)? text_white : !text_white; + bool text_white = BIT(control, 2); + bool border_white = BIT(control, 1); + bool background_white = BIT(control, 0) ? text_white : !text_white; int y = vpos - m_top_border; if (y < 0 || y >= 192) { // Draw border colour for (int i = 0; i < TOTAL_HORZ; i++) - p[i] = border_white? rgb_t::white() : rgb_t::black(); + p[i] = border_white ? rgb_t::white() : rgb_t::black(); // vblank is set at the last cycle of the first inactive line // not confirmed by the specs, just doing like 9928A. - if ( y == 193 ) + if (y == 193) { - m_int_cb( ASSERT_LINE ); - m_int_cb( CLEAR_LINE ); + m_int_cb(ASSERT_LINE); + m_int_cb(CLEAR_LINE); } } else @@ -234,12 +234,12 @@ void video992_device::device_timer(emu_timer &timer, device_timer_id id, int par // Draw regular line // Left border for (int i = 0; i < HORZ_DISPLAY_START; i++) - p[i] = border_white? rgb_t::white() : rgb_t::black(); + p[i] = border_white ? rgb_t::white() : rgb_t::black(); int addr = ((y << 2) & 0x3e0) | 0xec00; // Active display - for (int x = HORZ_DISPLAY_START; x<HORZ_DISPLAY_START+256; x+=8) + for (int x = HORZ_DISPLAY_START; x < HORZ_DISPLAY_START + 256; x+=8) { uint8_t charcode = 0; uint8_t pattern = 0; @@ -255,16 +255,16 @@ void video992_device::device_timer(emu_timer &timer, device_timer_id id, int par if (!endofline && m_videna) { // Get the pattern - int addrp = 0x1c00 | (charcode << 3) | (y%8); + int addrp = 0x1c00 | (charcode << 3) | (y & 7); pattern = m_mem_read_cb(addrp); linelength++; } for (int i = 0; i < 8; i++) { - if ((pattern & 0x80)!=0) - p[x+i] = text_white? rgb_t::white() : rgb_t::black(); + if (BIT(pattern, 7)) + p[x+i] = text_white ? rgb_t::white() : rgb_t::black(); else - p[x+i] = background_white? rgb_t::white() : rgb_t::black(); + p[x+i] = background_white ? rgb_t::white() : rgb_t::black(); pattern <<= 1; } @@ -273,27 +273,27 @@ void video992_device::device_timer(emu_timer &timer, device_timer_id id, int par // Right border for (int i = HORZ_DISPLAY_START + 256; i < TOTAL_HORZ; i++) - p[i] = border_white? rgb_t::white() : rgb_t::black(); + p[i] = border_white ? rgb_t::white() : rgb_t::black(); } // +1 for the minimum hold time // logerror("line length: %d\n", linelength); - m_hold_timer->adjust(screen().time_until_pos(raw_vpos, HORZ_DISPLAY_START + linelength*8 + 1)); + m_hold_timer->adjust(screen().time_until_pos(raw_vpos, HORZ_DISPLAY_START + linelength * 8 + 1)); } -uint32_t video992_device::screen_update( screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect ) +uint32_t video992_device::screen_update(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect) { - copybitmap( bitmap, m_tmpbmp, 0, 0, 0, 0, cliprect ); + copybitmap(bitmap, m_tmpbmp, 0, 0, 0, 0, cliprect); return 0; } /* VIDENA pin, positive logic */ -WRITE_LINE_MEMBER( video992_device::videna ) +WRITE_LINE_MEMBER(video992_device::videna) { - m_videna = (state==ASSERT_LINE); + m_videna = state; } void video992_device::device_start() @@ -302,8 +302,8 @@ void video992_device::device_start() m_vertical_size = TOTAL_VERT_NTSC; m_tmpbmp.allocate(TOTAL_HORZ, TOTAL_VERT_NTSC); - m_hold_timer = timer_alloc(HOLD_TIME); - m_free_timer = timer_alloc(FREE_TIME); + m_hold_timer = timer_alloc(FUNC(video992_device::hold_cpu), this); + m_free_timer = timer_alloc(FUNC(video992_device::free_cpu), this); m_border_color = rgb_t::black(); m_background_color = rgb_t::white(); @@ -463,12 +463,12 @@ void io992_device::device_start() uint8_t io992_device::cruread(offs_t offset) { - int address = offset << 1; + offs_t address = offset << 1; double inp = 0; // CRU E000-E7fE: Keyboard // Read: 1110 0*** **** xxx0 (mirror 07f0) - if ((address & 0xf800)==0xe000) + if ((address & 0xf800) == 0xe000) return BIT(m_keyboard[m_key_row]->read(), offset & 7); // CRU E800-EFFE: Hexbus and other functions @@ -480,21 +480,21 @@ uint8_t io992_device::cruread(offs_t offset) case 0xe802: case 0xe804: case 0xe806: - return data_bit(offset&3); + return data_bit(offset & 3); case 0xe808: - return (bus_hsk_level()==ASSERT_LINE)? 0:1; + return (bus_hsk_level() == ASSERT_LINE) ? 0 : 1; case 0xe80a: - return (bus_bav_level()==ASSERT_LINE)? 0:1; + return (bus_bav_level() == ASSERT_LINE) ? 0 : 1; case 0xe80c: // e80c (bit 6) seems to indicate that the HSK* line has been released // and is now asserted again - return (m_hsk_released && (bus_hsk_level()==ASSERT_LINE))? 1:0; + return (m_hsk_released && (bus_hsk_level() == ASSERT_LINE)) ? 1 : 0; case 0xe80e: inp = m_cassette->input(); LOGMASKED(LOG_CASSETTE, "value=%f\n", inp); - return (inp > 0)? 1:0; + return (inp > 0) ? 1 : 0; default: LOGMASKED(LOG_CRU, "Invalid CRU access to %04x\n", address); @@ -504,7 +504,7 @@ uint8_t io992_device::cruread(offs_t offset) void io992_device::cruwrite(offs_t offset, uint8_t data) { - int address = (offset << 1) & 0xf80e; + offs_t address = (offset << 1) & 0xf80e; LOGMASKED(LOG_CRU, "CRU %04x <- %1x\n", address, data); @@ -519,7 +519,7 @@ void io992_device::cruwrite(offs_t offset, uint8_t data) if (m_have_banked_rom) { LOGMASKED(LOG_BANK, "set bank = %d\n", data); - m_set_rom_bank(data==1); + m_set_rom_bank(data == 1); } [[fallthrough]]; case 0xe002: @@ -527,7 +527,7 @@ void io992_device::cruwrite(offs_t offset, uint8_t data) case 0xe006: case 0xe008: case 0xe00a: - if (data == 0) m_key_row = offset&7; + if (data == 0) m_key_row = offset & 7; break; case 0xe00c: LOGMASKED(LOG_WARN, "Unmapped CRU write to address e00c\n"); @@ -546,12 +546,12 @@ void io992_device::cruwrite(offs_t offset, uint8_t data) break; case 0xe80a: // BAV - set_bav_line(data!=0? CLEAR_LINE : ASSERT_LINE); + set_bav_line(data != 0 ? CLEAR_LINE : ASSERT_LINE); break; case 0xe808: // HSK - set_hsk_line(data!=0? CLEAR_LINE : ASSERT_LINE); - m_hsk_released = (bus_hsk_level()==CLEAR_LINE); + set_hsk_line(data != 0 ? CLEAR_LINE : ASSERT_LINE); + m_hsk_released = (bus_hsk_level() == CLEAR_LINE); break; case 0xe80c: @@ -561,7 +561,7 @@ void io992_device::cruwrite(offs_t offset, uint8_t data) case 0xe80e: LOGMASKED(LOG_CRU, "Cassette output = %d\n", data); // Tape output. See also ti99_4x.cpp. - m_cassette->output((data==1)? +1 : -1); + m_cassette->output((data == 1) ? +1 : -1); break; } } @@ -580,13 +580,13 @@ void io992_device::hexbus_value_changed(uint8_t data) { // Only latch the incoming data when BAV* is asserted and the Hexbus // is not inhibited - if (own_bav_level()==ASSERT_LINE) + if (own_bav_level() == ASSERT_LINE) { - if (bus_hsk_level()==ASSERT_LINE) + if (bus_hsk_level() == ASSERT_LINE) { // According to the Hexbus spec, the incoming HSK must be latched // by hardware - LOGMASKED(LOG_HEXBUS, "Latching HSK*; got data %01x\n", (data>>4)|(data&3)); + LOGMASKED(LOG_HEXBUS, "Latching HSK*; got data %01x\n", (data >> 4) | (data & 3)); latch_hsk(); } else @@ -596,7 +596,7 @@ void io992_device::hexbus_value_changed(uint8_t data) } } else - LOGMASKED(LOG_HEXBUS, "Ignoring Hexbus change (to %02x), BAV*=%d\n", data, (own_bav_level()==ASSERT_LINE)? 0:1); + LOGMASKED(LOG_HEXBUS, "Ignoring Hexbus change (to %02x), BAV*=%d\n", data, (own_bav_level() == ASSERT_LINE) ? 0 : 1); } ioport_constructor io992_device::device_input_ports() const @@ -651,7 +651,7 @@ void ti992_expram_device::readz(offs_t offset, uint8_t *value) // 011 -> 011 111 -> 111 offs_t address = offset; if ((offset & 0x6000) != 0x6000) address ^= 0x8000; - if ((address & 0x8000)==0) + if ((address & 0x8000) == 0) { *value = m_ram->read(address); LOGMASKED(LOG_EXPRAM, "expram %04x -> %02x\n", offset, *value); @@ -662,7 +662,7 @@ void ti992_expram_device::write(offs_t offset, uint8_t value) { offs_t address = offset; if ((offset & 0x6000) != 0x6000) address ^= 0x8000; - if ((address & 0x8000)==0) + if ((address & 0x8000) == 0) { m_ram->write(address, value); LOGMASKED(LOG_EXPRAM, "expram %04x <- %02x\n", offset, value); diff --git a/src/devices/bus/ti99/internal/992board.h b/src/devices/bus/ti99/internal/992board.h index 78ca51193cd..5a6ab8b5a8f 100644 --- a/src/devices/bus/ti99/internal/992board.h +++ b/src/devices/bus/ti99/internal/992board.h @@ -59,12 +59,11 @@ 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: - static const device_timer_id HOLD_TIME = 0; - static const device_timer_id FREE_TIME = 1; + TIMER_CALLBACK_MEMBER(hold_cpu); + TIMER_CALLBACK_MEMBER(free_cpu); +private: std::string tts(attotime t); devcb_read8 m_mem_read_cb; // Callback to read memory devcb_write_line m_hold_cb; diff --git a/src/devices/bus/ti99/internal/genkbd.cpp b/src/devices/bus/ti99/internal/genkbd.cpp index fa65058d7c8..5e22f27ee33 100644 --- a/src/devices/bus/ti99/internal/genkbd.cpp +++ b/src/devices/bus/ti99/internal/genkbd.cpp @@ -35,7 +35,7 @@ #define LOG_TRANSFER (1U<<3) #define LOG_LINES (1U<<4) -#define VERBOSE ( LOG_GENERAL | LOG_WARN ) +#define VERBOSE (LOG_GENERAL | LOG_WARN) #include "logmacro.h" @@ -203,42 +203,34 @@ geneve_xt_101_hle_keyboard_device::geneve_xt_101_hle_keyboard_device(const machi { } -/* - Called by the poll timer -*/ -void geneve_xt_101_hle_keyboard_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(geneve_xt_101_hle_keyboard_device::poll_tick) +{ + poll(); + send_key(); +} + +TIMER_CALLBACK_MEMBER(geneve_xt_101_hle_keyboard_device::send_tick) { - if (id==0) + // Send timer + if (m_shift_count == 10) { - poll(); - send_key(); + // Done, all sent + m_pc_kbdc->clock_write_from_kb(1); + m_pc_kbdc->data_write_from_kb(1); + m_send_timer->reset(); + m_shift_count = 0; + + // Adjust the queue + m_queue_head = (m_queue_head + 1) % KEYQUEUESIZE; + m_queue_length--; } else { - if (id==1) - { - // Send timer - if (m_shift_count==10) - { - // Done, all sent - m_pc_kbdc->clock_write_from_kb(1); - m_pc_kbdc->data_write_from_kb(1); - m_send_timer->reset(); - m_shift_count = 0; - - // Adjust the queue - m_queue_head = (m_queue_head + 1) % KEYQUEUESIZE; - m_queue_length--; - } - else - { - m_pc_kbdc->clock_write_from_kb(1); - m_pc_kbdc->data_write_from_kb(m_shift_reg&1); - m_pc_kbdc->clock_write_from_kb(0); - m_shift_reg>>=1; - m_shift_count++; - } - } + m_pc_kbdc->clock_write_from_kb(1); + m_pc_kbdc->data_write_from_kb(BIT(m_shift_reg, 0)); + m_pc_kbdc->clock_write_from_kb(0); + m_shift_reg >>= 1; + m_shift_count++; } } @@ -271,38 +263,32 @@ static const uint8_t MF1_CODE[0xe] = void geneve_xt_101_hle_keyboard_device::poll() { - uint32_t keystate; - uint32_t key_transitions; - uint32_t mask; - bool pressed = false; - int keycode = 0; - if (m_resetting) return; // We're testing two 16-bit ports at once // but only if we have enough space in the queue - for (int i=0; (i < 4) && (m_queue_length <= (KEYQUEUESIZE-MAXKEYMSGLENGTH)); i++) + for (uint8_t i = 0; i < 4 && m_queue_length <= (KEYQUEUESIZE - MAXKEYMSGLENGTH); i++) { // Get those two ports and calculate the difference - keystate = m_keys[2*i]->read() | (m_keys[2*i + 1]->read() << 16); - key_transitions = keystate ^ m_key_state_save[i]; + uint32_t keystate = m_keys[2 * i]->read() | (m_keys[2 * i + 1]->read() << 16); + uint32_t key_transitions = keystate ^ m_key_state_save[i]; if (key_transitions != 0) { - mask = 0x00000001; + uint32_t mask = 0x00000001; // Some key(s) has/have changed (pressed/released) - for (int j=0; (j < 32) && (m_queue_length <= (KEYQUEUESIZE-MAXKEYMSGLENGTH)); j++) + for (uint8_t j = 0; j < 32 && m_queue_length <= (KEYQUEUESIZE - MAXKEYMSGLENGTH); j++) { - if ((key_transitions & mask)!=0) + if ((key_transitions & mask) != 0) { // Found one changed key (i is a 32-key block) - keycode = (i<<5) | j; - pressed = (keystate & mask)!=0; + uint8_t keycode = (i << 5) | j; + bool pressed = (bool)(keystate & mask); // Auto-repeat if (pressed) { m_autorepeat_code = keycode; - m_autorepeat_timer = KEYAUTOREPEATDELAY+1; + m_autorepeat_timer = KEYAUTOREPEATDELAY + 1; m_key_state_save[i] |= mask; } else @@ -358,9 +344,9 @@ void geneve_xt_101_hle_keyboard_device::poll() } // Extended keycodes - if ((keycode >= 0x60) && (keycode < 0x6e)) + if (keycode >= 0x60 && keycode < 0x6e) { - if ((keycode >= 0x63) && pressed) + if (keycode >= 0x63 && pressed) { // Handle shift state if (keycode == 0x63) // Slash @@ -373,14 +359,14 @@ void geneve_xt_101_hle_keyboard_device::poll() } else { // Key function with NumLock=0 - if (m_numlock && (!m_left_shift) && (!m_right_shift)) + if (m_numlock && !m_left_shift && !m_right_shift) { // Fake shift press if numlock is active m_fake_shift_state = true; } else { - if ((!m_numlock) && (m_left_shift || m_right_shift)) + if (!m_numlock && (m_left_shift || m_right_shift)) { // Fake shift unpress if shift is down m_fake_unshift_state = true; @@ -400,7 +386,7 @@ void geneve_xt_101_hle_keyboard_device::poll() post_in_key_queue(0xaa); } } - keycode = MF1_CODE[keycode-0x60]; + keycode = MF1_CODE[keycode - 0x60]; if (!pressed) keycode |= 0x80; post_in_key_queue(0xe0); post_in_key_queue(keycode); @@ -422,7 +408,7 @@ void geneve_xt_101_hle_keyboard_device::poll() else { // Handle shift state - if (pressed && (!m_left_shift) && (!m_right_shift) && (!m_left_ctrl) && (!m_right_ctrl)) + if (pressed && !m_left_shift && !m_right_shift && !m_left_ctrl && !m_right_ctrl) { // Fake shift press post_in_key_queue(0xe0); post_in_key_queue(0x2a); @@ -481,13 +467,13 @@ void geneve_xt_101_hle_keyboard_device::poll() if (m_autorepeat_code != 0) { m_autorepeat_timer--; - if ((m_autorepeat_timer == 0) && (m_queue_length <= (KEYQUEUESIZE-MAXKEYMSGLENGTH))) + if (m_autorepeat_timer == 0 && m_queue_length <= (KEYQUEUESIZE - MAXKEYMSGLENGTH)) { // Extended code - if ((m_autorepeat_code >= 0x60) && (m_autorepeat_code < 0x6e)) + if (m_autorepeat_code >= 0x60 && m_autorepeat_code < 0x6e) { post_in_key_queue(0xe0); - post_in_key_queue(MF1_CODE[m_autorepeat_code-0x60]); + post_in_key_queue(MF1_CODE[m_autorepeat_code - 0x60]); } else { @@ -521,7 +507,7 @@ void geneve_xt_101_hle_keyboard_device::send_key() if (m_clock_line == CLEAR_LINE) { m_reset_timer--; - if (m_reset_timer==0) + if (m_reset_timer == 0) { LOG("Reset triggered\n"); reset_line(0); @@ -530,7 +516,7 @@ void geneve_xt_101_hle_keyboard_device::send_key() } else { - if (m_data_line==1) + if (m_data_line) { // Dequeue a key if (m_queue_length != 0) @@ -558,7 +544,7 @@ void geneve_xt_101_hle_keyboard_device::post_in_key_queue(int keycode) // clock_write - //------------------------------------------------- -WRITE_LINE_MEMBER( geneve_xt_101_hle_keyboard_device::clock_write ) +WRITE_LINE_MEMBER(geneve_xt_101_hle_keyboard_device::clock_write) { LOGMASKED(LOG_LINES, "Clock write: %d\n", state); m_clock_line = (line_state)state; @@ -576,7 +562,7 @@ WRITE_LINE_MEMBER( geneve_xt_101_hle_keyboard_device::clock_write ) // data_write - //------------------------------------------------- -WRITE_LINE_MEMBER( geneve_xt_101_hle_keyboard_device::data_write ) +WRITE_LINE_MEMBER(geneve_xt_101_hle_keyboard_device::data_write) { LOGMASKED(LOG_LINES, "Data write: %d\n", state); m_data_line = (line_state)state; @@ -590,14 +576,14 @@ WRITE_LINE_MEMBER( geneve_xt_101_hle_keyboard_device::data_write ) void geneve_xt_101_hle_keyboard_device::device_start() { set_pc_kbdc_device(); - m_poll_timer = timer_alloc(0); - m_send_timer = timer_alloc(1); + m_poll_timer = timer_alloc(FUNC(geneve_xt_101_hle_keyboard_device::poll_tick), this); + m_send_timer = timer_alloc(FUNC(geneve_xt_101_hle_keyboard_device::send_tick), this); // state saving save_item(NAME(m_queue_length)); save_item(NAME(m_queue_head)); - save_pointer(NAME(m_key_state_save),4); - save_pointer(NAME(m_queue),KEYQUEUESIZE); + save_pointer(NAME(m_key_state_save), 4); + save_pointer(NAME(m_queue), KEYQUEUESIZE); } @@ -614,9 +600,9 @@ void geneve_xt_101_hle_keyboard_device::device_reset() } -WRITE_LINE_MEMBER( geneve_xt_101_hle_keyboard_device::reset_line ) +WRITE_LINE_MEMBER(geneve_xt_101_hle_keyboard_device::reset_line) { - m_resetting = (state==0); + m_resetting = !state; if (m_resetting) { @@ -645,4 +631,3 @@ WRITE_LINE_MEMBER( geneve_xt_101_hle_keyboard_device::reset_line ) post_in_key_queue(0xaa); } } - diff --git a/src/devices/bus/ti99/internal/genkbd.h b/src/devices/bus/ti99/internal/genkbd.h index a54951e2134..cf67ea8ee6c 100644 --- a/src/devices/bus/ti99/internal/genkbd.h +++ b/src/devices/bus/ti99/internal/genkbd.h @@ -26,18 +26,20 @@ class geneve_xt_101_hle_keyboard_device : public device_t, public device_pc_kbd_ public: // construction/destruction geneve_xt_101_hle_keyboard_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock); - DECLARE_WRITE_LINE_MEMBER( reset_line ); + DECLARE_WRITE_LINE_MEMBER(reset_line); protected: // device-level overrides virtual void device_start() override; virtual void device_reset() override; virtual ioport_constructor device_input_ports() const override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; // device_pc_kbd_interface overrides - virtual DECLARE_WRITE_LINE_MEMBER( clock_write ) override; - virtual DECLARE_WRITE_LINE_MEMBER( data_write ) override; + virtual DECLARE_WRITE_LINE_MEMBER(clock_write) override; + virtual DECLARE_WRITE_LINE_MEMBER(data_write) override; + + TIMER_CALLBACK_MEMBER(poll_tick); + TIMER_CALLBACK_MEMBER(send_tick); private: emu_timer *m_poll_timer; diff --git a/src/devices/bus/ti99/joyport/handset.cpp b/src/devices/bus/ti99/joyport/handset.cpp index ab55d84f277..046873f5fe6 100644 --- a/src/devices/bus/ti99/joyport/handset.cpp +++ b/src/devices/bus/ti99/joyport/handset.cpp @@ -45,7 +45,7 @@ #define LOG_HANDSET (1U<<4) #define LOG_CLOCK (1U<<5) -#define VERBOSE ( LOG_CONFIG | LOG_WARN ) +#define VERBOSE (LOG_CONFIG | LOG_WARN) #include "logmacro.h" @@ -54,19 +54,17 @@ DEFINE_DEVICE_TYPE(TI99_HANDSET, bus::ti99::joyport::ti99_handset_device, "ti99_ namespace bus::ti99::joyport { -#define TRACE_HANDSET 0 -#define TRACE_JOYSTICK 0 - -static const char *const joynames[2][4] = -{ - { "JOY0", "JOY2", "JOY4", "JOY6" }, // X axis - { "JOY1", "JOY3", "JOY5", "JOY7" } // Y axis -}; - -static const char *const keynames[] = { "KP0", "KP1", "KP2", "KP3", "KP4" }; - ti99_handset_device::ti99_handset_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) - : device_t(mconfig, TI99_HANDSET, tag, owner, clock), device_ti99_joyport_interface(mconfig, *this), m_ack(0), m_clock_high(false), m_buf(0), m_buflen(0), m_delay_timer(nullptr) + : device_t(mconfig, TI99_HANDSET, tag, owner, clock) + , device_ti99_joyport_interface(mconfig, *this) + , m_joyx(*this, "JOYX%u", 0U) + , m_joyy(*this, "JOYY%u", 0U) + , m_keys(*this, "KP%u", 0U) + , m_ack(0) + , m_clock_high(false) + , m_buf(0) + , m_buflen(0) + , m_delay_timer(nullptr) { } @@ -85,7 +83,7 @@ ti99_handset_device::ti99_handset_device(const machine_config &mconfig, const ch */ uint8_t ti99_handset_device::read_dev() { - return (m_buf & 0xf) | 0x10 | (m_clock_high? 0x20:0) | ( m_buflen==3? 0x00:0x40); + return (m_buf & 0xf) | 0x10 | (m_clock_high ? 0x20 : 0x00) | (m_buflen == 3 ? 0x00 : 0x40); } void ti99_handset_device::write_dev(uint8_t data) @@ -100,7 +98,7 @@ void ti99_handset_device::write_dev(uint8_t data) of P0 is changed, because, in one occasion, the ISR asserts the line before it reads the data, so we need to delay the acknowledge process. */ -void ti99_handset_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(ti99_handset_device::delayed_data_ack) { m_clock_high = !m_clock_high; m_buf >>= 4; @@ -120,8 +118,10 @@ void ti99_handset_device::device_timer(emu_timer &timer, device_timer_id id, int } if (m_buflen == 0) - /* See if we need to post a new event */ - do_task(); + { + // See if we need to post a new event + do_task(); + } } /* @@ -129,10 +129,10 @@ void ti99_handset_device::device_timer(emu_timer &timer, device_timer_id id, int */ void ti99_handset_device::set_acknowledge(int data) { - if ((m_buflen !=0) && (data != m_ack)) + if (m_buflen != 0 && data != m_ack) { m_ack = data; - if ((data!=0) == m_clock_high) + if (data != 0 && m_clock_high) { // I don't know what the real delay is, but 30us apears to be enough m_delay_timer->adjust(attotime::from_usec(30)); @@ -167,54 +167,58 @@ void ti99_handset_device::post_message(int message) */ bool ti99_handset_device::poll_keyboard(int num) { - uint32_t key_buf; uint8_t current_key; - int i; - /* read current key state */ - key_buf = (ioport(keynames[num])->read() | (ioport(keynames[num + 1])->read() << 16) ) >> (4*num); + // read current key state + uint32_t key_buf = (m_keys[num]->read() | (m_keys[num + 1]->read() << 16)) >> (4*num); // If a key was previously pressed, this key was not shift, and this key is // still down, then don't change the current key press. - if (previous_key[num] !=0 && (previous_key[num] != 0x24) - && (key_buf & (1 << (previous_key[num] & 0x1f)))) + if (previous_key[num] !=0 && previous_key[num] != 0x24 && BIT(key_buf, previous_key[num] & 0x1f)) { - /* check the shift modifier state */ - if (((previous_key[num] & 0x20) != 0) == ((key_buf & 0x0008) != 0)) - /* the shift modifier state has not changed */ + // check the shift modifier state + if (BIT(previous_key[num], 5) == BIT(key_buf, 3)) + { + // the shift modifier state has not changed return false; + } else { // The shift modifier state has changed: we need to update the // keyboard state if (key_buf & 0x0008) - { /* shift has been pressed down */ - previous_key[num] = current_key = previous_key[num] | 0x20; + { + // shift has been pressed down + current_key = previous_key[num] | 0x20; + previous_key[num] = current_key; } else { - previous_key[num] = current_key = previous_key[num] & ~0x20; + current_key = previous_key[num] & ~0x20; + previous_key[num] = current_key; } - /* post message */ - post_message((((unsigned)current_key) << 4) | (num << 1)); + // post message + post_message(((uint32_t)current_key << 4) | (num << 1)); return true; } } - current_key = 0; /* default value if no key is down */ - for (i=0; i<20; i++) + current_key = 0; // default value if no key is down + for (int i = 0; i < 20; i++) { - if (key_buf & (1 << i)) + if (BIT(key_buf, i)) { current_key = i + 1; - if (key_buf & 0x0008) - current_key |= 0x20; /* set shift flag */ + if (BIT(key_buf, 3)) + current_key |= 0x20; // set shift flag if (current_key != 0x24) + { // If this is the shift key, any other key we may find will // have higher priority; otherwise, we may exit the loop and keep // the key we have just found. break; + } } } @@ -222,8 +226,8 @@ bool ti99_handset_device::poll_keyboard(int num) { previous_key[num] = current_key; - /* post message */ - post_message((((unsigned) current_key) << 4) | (num << 1)); + // post message + post_message(((uint32_t)current_key << 4) | (num << 1)); return true; } return false; @@ -238,42 +242,39 @@ bool ti99_handset_device::poll_keyboard(int num) */ bool ti99_handset_device::poll_joystick(int num) { - uint8_t current_joy; - int current_joy_x, current_joy_y; int message; - /* read joystick position */ - current_joy_x = ioport(joynames[0][num])->read(); - current_joy_y = ioport(joynames[1][num])->read(); + // read joystick position + uint8_t current_joy_x = m_joyx[num]->read(); + uint8_t current_joy_y = m_joyy[num]->read(); - /* compare with last saved position */ - current_joy = current_joy_x | (current_joy_y << 4); + // compare with last saved position + uint8_t current_joy = current_joy_x | (current_joy_y << 4); if (current_joy != previous_joy[num]) { - /* save position */ + // save position previous_joy[num] = current_joy; - /* transform position to signed quantity */ + // transform position to signed quantity current_joy_x -= 7; current_joy_y -= 7; message = 0; - /* set sign */ - // note that we set the sign if the joystick position is 0 to work + // set sign, note that we set the sign if the joystick position is 0 to work // around a bug in the ti99/4 ROMs if (current_joy_x <= 0) { message |= 0x040; - current_joy_x = - current_joy_x; + current_joy_x = -current_joy_x; } if (current_joy_y <= 0) { message |= 0x400; - current_joy_y = - current_joy_y; + current_joy_y = -current_joy_y; } - /* convert absolute values to Gray code and insert in message */ + // convert absolute values to Gray code and insert in message if (current_joy_x & 4) current_joy_x ^= 3; if (current_joy_x & 2) @@ -286,10 +287,10 @@ bool ti99_handset_device::poll_joystick(int num) current_joy_y ^= 1; message |= current_joy_y << 7; - /* set joystick address */ + // set joystick address message |= (num << 1) | 0x1; - /* post message */ + // post message post_message(message); return true; } @@ -302,25 +303,23 @@ bool ti99_handset_device::poll_joystick(int num) */ void ti99_handset_device::do_task() { - int i; - if (m_buflen == 0) { - /* poll every handset */ - for (i=0; i < MAX_HANDSETS; i++) - if (poll_joystick(i)==true) return; - for (i=0; i < MAX_HANDSETS; i++) - if (poll_keyboard(i)==true) return; + // poll every handset + for (int i = 0; i < MAX_HANDSETS; i++) + if (poll_joystick(i)) return; + for (int i = 0; i < MAX_HANDSETS; i++) + if (poll_keyboard(i)) return; } else if (m_buflen == 3) { /* update messages after they have been posted */ if (m_buf & 1) { /* keyboard */ - poll_keyboard((~(m_buf >> 1)) & 0x3); + poll_keyboard(~(m_buf >> 1) & 0x3); } else { /* joystick */ - poll_joystick((~(m_buf >> 1)) & 0x3); + poll_joystick(~(m_buf >> 1) & 0x3); } } } @@ -333,7 +332,7 @@ void ti99_handset_device::pulse_clock() void ti99_handset_device::device_start() { - m_delay_timer = timer_alloc(DELAY_TIMER); + m_delay_timer = timer_alloc(FUNC(ti99_handset_device::delayed_data_ack), this); save_item(NAME(m_ack)); save_item(NAME(m_clock_high)); save_item(NAME(m_buf)); @@ -358,28 +357,28 @@ INPUT_PORTS_START( handset ) /* 13 pseudo-ports for IR remote handsets */ /* 8 pseudo-ports for the 4 IR joysticks */ - PORT_START("JOY0") /* joystick 1, X axis */ + PORT_START("JOYX0") /* joystick 1, X axis */ PORT_BIT( 0xf, 0x7, IPT_AD_STICK_X) PORT_SENSITIVITY(JOYSTICK_SENSITIVITY) PORT_KEYDELTA(JOYSTICK_DELTA) PORT_MINMAX(0,0xe) PORT_PLAYER(1) - PORT_START("JOY1") /* joystick 1, Y axis */ + PORT_START("JOYY0") /* joystick 1, Y axis */ PORT_BIT( 0xf, 0x7, IPT_AD_STICK_Y) PORT_SENSITIVITY(JOYSTICK_SENSITIVITY) PORT_KEYDELTA(JOYSTICK_DELTA) PORT_MINMAX(0,0xe) PORT_PLAYER(1) PORT_REVERSE - PORT_START("JOY2") /* joystick 2, X axis */ + PORT_START("JOYX1") /* joystick 2, X axis */ PORT_BIT( 0xf, 0x7, IPT_AD_STICK_X) PORT_SENSITIVITY(JOYSTICK_SENSITIVITY) PORT_KEYDELTA(JOYSTICK_DELTA) PORT_MINMAX(0,0xe) PORT_PLAYER(2) - PORT_START("JOY3") /* joystick 2, Y axis */ + PORT_START("JOYY1") /* joystick 2, Y axis */ PORT_BIT( 0xf, 0x7, IPT_AD_STICK_Y) PORT_SENSITIVITY(JOYSTICK_SENSITIVITY) PORT_KEYDELTA(JOYSTICK_DELTA) PORT_MINMAX(0,0xe) PORT_PLAYER(2) PORT_REVERSE - PORT_START("JOY4") /* joystick 3, X axis */ + PORT_START("JOYX2") /* joystick 3, X axis */ PORT_BIT( 0xf, 0x7, IPT_AD_STICK_X) PORT_SENSITIVITY(JOYSTICK_SENSITIVITY) PORT_KEYDELTA(JOYSTICK_DELTA) PORT_MINMAX(0,0xe) PORT_PLAYER(3) - PORT_START("JOY5") /* joystick 3, Y axis */ + PORT_START("JOYY2") /* joystick 3, Y axis */ PORT_BIT( 0xf, 0x7, IPT_AD_STICK_Y) PORT_SENSITIVITY(JOYSTICK_SENSITIVITY) PORT_KEYDELTA(JOYSTICK_DELTA) PORT_MINMAX(0,0xe) PORT_PLAYER(3) PORT_REVERSE - PORT_START("JOY6") /* joystick 4, X axis */ + PORT_START("JOYX3") /* joystick 4, X axis */ PORT_BIT( 0xf, 0x7, IPT_AD_STICK_X) PORT_SENSITIVITY(JOYSTICK_SENSITIVITY) PORT_KEYDELTA(JOYSTICK_DELTA) PORT_MINMAX(0,0xe) PORT_PLAYER(4) - PORT_START("JOY7") /* joystick 4, Y axis */ + PORT_START("JOYY3") /* joystick 4, Y axis */ PORT_BIT( 0xf, 0x7, IPT_AD_STICK_Y) PORT_SENSITIVITY(JOYSTICK_SENSITIVITY) PORT_KEYDELTA(JOYSTICK_DELTA) PORT_MINMAX(0,0xe) PORT_PLAYER(4) PORT_REVERSE /* 5 pseudo-ports for the 4 IR remote keypads */ @@ -508,7 +507,9 @@ INPUT_PORTS_START( joysticks ) INPUT_PORTS_END ti99_twin_joystick_device::ti99_twin_joystick_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) - : device_t(mconfig, TI99_JOYSTICK, tag, owner, clock), device_ti99_joyport_interface(mconfig, *this), m_joystick(0) + : device_t(mconfig, TI99_JOYSTICK, tag, owner, clock), device_ti99_joyport_interface(mconfig, *this) + , m_joystick(0) + , m_joys(*this, "JOY%u", 1U) { } @@ -524,12 +525,10 @@ void ti99_twin_joystick_device::device_start() */ uint8_t ti99_twin_joystick_device::read_dev() { - uint8_t value; - if (m_joystick==1) value = ioport("JOY1")->read(); - else + uint8_t value = 0xff; + if (m_joystick > 0 && m_joystick <= 2) { - if (m_joystick==2) value = ioport("JOY2")->read(); - else value = 0xff; + value = m_joys[m_joystick - 1]->read(); } LOGMASKED(LOG_JOYSTICK, "joy%d = %02x\n", m_joystick, value); return value; diff --git a/src/devices/bus/ti99/joyport/handset.h b/src/devices/bus/ti99/joyport/handset.h index ca64889ec43..344f74bed7a 100644 --- a/src/devices/bus/ti99/joyport/handset.h +++ b/src/devices/bus/ti99/joyport/handset.h @@ -38,7 +38,7 @@ protected: virtual void device_reset() 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(delayed_data_ack); private: static constexpr unsigned MAX_HANDSETS = 4; @@ -49,6 +49,10 @@ private: bool poll_joystick(int num); void set_acknowledge(int data); + required_ioport_array<4> m_joyx; + required_ioport_array<4> m_joyy; + required_ioport_array<5> m_keys; + int m_ack; bool m_clock_high; int m_buf; @@ -78,6 +82,8 @@ private: // In reality this is no latch but GND is put on one of the selector lines // and then routed back to the port via the joystick int m_joystick; + + required_ioport_array<2> m_joys; }; } // end namespace bus::ti99::joyport diff --git a/src/devices/bus/ti99/joyport/mecmouse.cpp b/src/devices/bus/ti99/joyport/mecmouse.cpp index a95162f44ea..68e17da3ec1 100644 --- a/src/devices/bus/ti99/joyport/mecmouse.cpp +++ b/src/devices/bus/ti99/joyport/mecmouse.cpp @@ -55,10 +55,21 @@ DEFINE_DEVICE_TYPE(TI99_MECMOUSE, bus::ti99::joyport::mecmouse_device, "ti99_mec namespace bus::ti99::joyport { -#define POLL_TIMER 1 - mecmouse_device::mecmouse_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) - : device_t(mconfig, TI99_MECMOUSE, tag, owner, clock), device_ti99_joyport_interface(mconfig, *this), m_last_select(0), m_read_y_axis(false), m_x(0), m_y(0), m_x_buf(0), m_y_buf(0), m_last_mx(0), m_last_my(0), m_poll_timer(nullptr) + : device_t(mconfig, TI99_MECMOUSE, tag, owner, clock) + , device_ti99_joyport_interface(mconfig, *this) + , m_mousex(*this, "MOUSEX") + , m_mousey(*this, "MOUSEY") + , m_mousebutton(*this, "MOUSE0") + , m_last_select(0) + , m_read_y_axis(false) + , m_x(0) + , m_y(0) + , m_x_buf(0) + , m_y_buf(0) + , m_last_mx(0) + , m_last_my(0) + , m_poll_timer(nullptr) { } @@ -66,7 +77,7 @@ mecmouse_device::mecmouse_device(const machine_config &mconfig, const char *tag, uint8_t mecmouse_device::read_dev() { int answer; - int buttons = ioport("MOUSE0")->read() & 3; + int buttons = m_mousebutton->read() & 3; answer = (m_read_y_axis? m_y_buf : m_x_buf) << 1; @@ -132,17 +143,14 @@ void mecmouse_device::write_dev(uint8_t data) } } -void mecmouse_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(mecmouse_device::poll_mouse) { // Poll the movement - int new_mx, new_my; - int delta_x, delta_y; - - new_mx = ioport("MOUSEX")->read(); - new_my = ioport("MOUSEY")->read(); + int new_mx = m_mousex->read(); + int new_my = m_mousey->read(); // compute x delta - delta_x = new_mx - m_last_mx; + int delta_x = new_mx - m_last_mx; // Prevent unplausible values at startup. if (delta_x > 10000 || delta_x<-10000) delta_x = 0; @@ -150,7 +158,7 @@ void mecmouse_device::device_timer(emu_timer &timer, device_timer_id id, int par m_last_mx = new_mx; // compute y delta - delta_y = new_my - m_last_my; + int delta_y = new_my - m_last_my; if (delta_y > 10000 || delta_y<-10000) delta_y = 0; @@ -163,7 +171,7 @@ void mecmouse_device::device_timer(emu_timer &timer, device_timer_id id, int par void mecmouse_device::device_start() { - m_poll_timer = timer_alloc(POLL_TIMER); + m_poll_timer = timer_alloc(FUNC(mecmouse_device::poll_mouse), this); // The poll time cannot depend on the console settings, since the TI-99/4A // has no clock line on the joystick port. The rate is not mentioned in // the specs; however, if it is too low, the mouse pointer will do jumps diff --git a/src/devices/bus/ti99/joyport/mecmouse.h b/src/devices/bus/ti99/joyport/mecmouse.h index 8bbecc7d78d..0ee23ade546 100644 --- a/src/devices/bus/ti99/joyport/mecmouse.h +++ b/src/devices/bus/ti99/joyport/mecmouse.h @@ -30,9 +30,14 @@ protected: virtual void device_start() override; virtual void device_reset() 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(poll_mouse); private: + required_ioport m_mousex; + required_ioport m_mousey; + required_ioport m_mousebutton; + int m_last_select; bool m_read_y_axis; int m_x; diff --git a/src/devices/bus/ti99/peb/hfdc.cpp b/src/devices/bus/ti99/peb/hfdc.cpp index 98b42c5afbb..d760f09da20 100644 --- a/src/devices/bus/ti99/peb/hfdc.cpp +++ b/src/devices/bus/ti99/peb/hfdc.cpp @@ -84,8 +84,6 @@ namespace bus::ti99::peb { #define NONE -1 -#define MOTOR_TIMER 1 - #define TAPE_ADDR 0x0fc0 #define HDC_R_ADDR 0x0fd0 #define HDC_W_ADDR 0x0fd2 @@ -507,7 +505,7 @@ void myarc_hfdc_device::cruwrite(offs_t offset, uint8_t data) /* Monoflop has gone back to the OFF state. */ -void myarc_hfdc_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(myarc_hfdc_device::motor_off) { set_floppy_motors_running(false); } @@ -885,7 +883,7 @@ void myarc_hfdc_device::write_buffer(uint8_t data) void myarc_hfdc_device::device_start() { m_dsrrom = memregion(TI99_DSRROM)->base(); - m_motor_on_timer = timer_alloc(MOTOR_TIMER); + m_motor_on_timer = timer_alloc(FUNC(myarc_hfdc_device::motor_off), this); // The HFDC does not use READY; it has on-board RAM for DMA m_current_floppy = nullptr; m_current_harddisk = nullptr; diff --git a/src/devices/bus/ti99/peb/hfdc.h b/src/devices/bus/ti99/peb/hfdc.h index c7c17834b79..ee167421e48 100644 --- a/src/devices/bus/ti99/peb/hfdc.h +++ b/src/devices/bus/ti99/peb/hfdc.h @@ -46,7 +46,6 @@ public: protected: virtual void device_config_complete() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; virtual void device_start() override; virtual void device_reset() override; @@ -54,6 +53,8 @@ protected: virtual void device_add_mconfig(machine_config &config) override; virtual ioport_constructor device_input_ports() const override; + TIMER_CALLBACK_MEMBER(motor_off); + private: DECLARE_WRITE_LINE_MEMBER( dmarq_w ); DECLARE_WRITE_LINE_MEMBER( intrq_w ); diff --git a/src/devices/bus/ti99/peb/tipi.cpp b/src/devices/bus/ti99/peb/tipi.cpp index 5f98313b47b..1dc8b1d3c3d 100644 --- a/src/devices/bus/ti99/peb/tipi.cpp +++ b/src/devices/bus/ti99/peb/tipi.cpp @@ -406,7 +406,7 @@ void tipi_card_device::process_message() Default for port is 9901. */ -void tipi_card_device::open_websocket() +TIMER_CALLBACK_MEMBER(tipi_card_device::open_websocket) { if (m_rpiconn) { @@ -539,15 +539,6 @@ void tipi_card_device::websocket_error(const std::error_code& code) } } -/* - Restart the websocket connection -*/ -void tipi_card_device::device_timer(emu_timer &timer, device_timer_id id, int param) -{ - open_websocket(); -} - - void tipi_card_device::websocket_closed(int i, const std::string& msg) { LOG("Closing connection\n"); @@ -573,7 +564,7 @@ void tipi_card_device::device_start() save_item(NAME(m_rc)); save_item(NAME(m_lasttc)); - m_restart_timer = timer_alloc(0); + m_restart_timer = timer_alloc(FUNC(tipi_card_device::open_websocket), this); m_rpiconn = (m_rpi->exists()); } @@ -586,7 +577,7 @@ void tipi_card_device::device_reset() m_dsr = false; m_portaccess = false; if (!m_rpiconn) LOGMASKED(LOG_CONFIG, "No Raspberry Pi connected\n"); - open_websocket(); + open_websocket(0); m_connected = false; m_lasttc = 0; m_attempts = 5; diff --git a/src/devices/bus/ti99/peb/tipi.h b/src/devices/bus/ti99/peb/tipi.h index 485ee7139a2..f0fb6753758 100644 --- a/src/devices/bus/ti99/peb/tipi.h +++ b/src/devices/bus/ti99/peb/tipi.h @@ -51,8 +51,7 @@ private: void websocket_incoming(std::shared_ptr<webpp::ws_client::Message> message); void websocket_error(const std::error_code& code); void websocket_closed(int i, const std::string& msg); - void open_websocket(); - void device_timer(emu_timer &timer, device_timer_id id, int param); + TIMER_CALLBACK_MEMBER(open_websocket); void send(const char* message); void send(u8* message, int len); diff --git a/src/devices/bus/vcs/dpc.cpp b/src/devices/bus/vcs/dpc.cpp index 26f790e754b..4e6989bf86a 100644 --- a/src/devices/bus/vcs/dpc.cpp +++ b/src/devices/bus/vcs/dpc.cpp @@ -2,7 +2,6 @@ // copyright-holders:Fabio Priuli /*************************************************************************** - Atari 2600 cart with DPC chip (Pitfall II) ***************************************************************************/ @@ -32,7 +31,7 @@ dpc_device::dpc_device(const machine_config& mconfig, const char* tag, device_t* void dpc_device::device_start() { - m_oscillator = timer_alloc(TIMER_OSC); + m_oscillator = timer_alloc(FUNC(dpc_device::oscillator_tick), this); m_oscillator->reset(); save_item(STRUCT_MEMBER(m_df, top)); @@ -52,7 +51,7 @@ void dpc_device::device_start() void dpc_device::device_reset() { - for (auto & elem : m_df) + for (df_t & elem : m_df) { elem.osc_clk = 0; elem.flag = 0; @@ -88,20 +87,16 @@ void dpc_device::decrement_counter(uint8_t data_fetcher) //------------------------------------------------- -// device_timer - handler timer events +// oscillator_tick //------------------------------------------------- -void dpc_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(dpc_device::oscillator_tick) { - if (id == TIMER_OSC) + for (int data_fetcher = 5; data_fetcher < 8; data_fetcher++) { - // callback - for (int data_fetcher = 5; data_fetcher < 8; data_fetcher++) + if (m_df[data_fetcher].osc_clk) { - if (m_df[data_fetcher].osc_clk) - { - decrement_counter(data_fetcher); - } + decrement_counter(data_fetcher); } } } diff --git a/src/devices/bus/vcs/dpc.h b/src/devices/bus/vcs/dpc.h index 40dd844e800..1b339c98515 100644 --- a/src/devices/bus/vcs/dpc.h +++ b/src/devices/bus/vcs/dpc.h @@ -11,9 +11,7 @@ // TYPE DEFINITIONS //************************************************************************** -// TO DO: DPC should be made a separate device! - -// m_dpc.oscillator = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(a2600_state::modeDPC_timer_callback),this)); +// TODO: DPC should be made a separate device class dpc_device : public device_t { @@ -27,7 +25,11 @@ public: virtual void write(offs_t offset, uint8_t data); protected: - static constexpr device_timer_id TIMER_OSC = 0; + // device-level overrides + virtual void device_start() override; + virtual void device_reset() override; + + TIMER_CALLBACK_MEMBER(oscillator_tick); struct df_t { uint8_t top; @@ -39,11 +41,6 @@ protected: uint8_t osc_clk; /* Only used by data fetchers 5,6, and 7 */ }; - // 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; - df_t m_df[8]; uint8_t m_movamt; uint8_t m_latch_62; diff --git a/src/devices/bus/vip/vp550.cpp b/src/devices/bus/vip/vp550.cpp index 66a00dbfebd..1135b1b9f9d 100644 --- a/src/devices/bus/vip/vp550.cpp +++ b/src/devices/bus/vip/vp550.cpp @@ -4,40 +4,18 @@ RCA VIP Super Sound System VP550 emulation -**********************************************************************/ - -/* - - TODO: + TODO: Implement VP551 variant - - VP551 - -*/ +**********************************************************************/ #include "emu.h" #include "vp550.h" - #include "speaker.h" +#define VERBOSE (0) +#include "logmacro.h" -//************************************************************************** -// MACROS / CONSTANTS -//************************************************************************** - -#define LOG 0 - - -#define CDP1863_A_TAG "u1" -#define CDP1863_B_TAG "u2" - - -enum -{ - CHANNEL_A = 0, - CHANNEL_B -}; - //************************************************************************** // DEVICE DEFINITIONS @@ -47,20 +25,20 @@ DEFINE_DEVICE_TYPE(VP550, vp550_device, "vp550", "VP-550 Super Sound") //------------------------------------------------- -// machine_config( vp550 ) +// device_add_mconfig //------------------------------------------------- void vp550_device::device_add_mconfig(machine_config &config) { SPEAKER(config, "mono").front_center(); - CDP1863(config, m_pfg_a, 0); - m_pfg_a->set_clock2(0); - m_pfg_a->add_route(ALL_OUTPUTS, "mono", 1.0); + CDP1863(config, m_pfg[0], 0); + m_pfg[0]->set_clock2(0); + m_pfg[0]->add_route(ALL_OUTPUTS, "mono", 1.0); - CDP1863(config, m_pfg_b, 0); - m_pfg_b->set_clock2(0); - m_pfg_b->add_route(ALL_OUTPUTS, "mono", 1.0); + CDP1863(config, m_pfg[1], 0); + m_pfg[1]->set_clock2(0); + m_pfg[1]->add_route(ALL_OUTPUTS, "mono", 1.0); } @@ -76,8 +54,7 @@ void vp550_device::device_add_mconfig(machine_config &config) vp550_device::vp550_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) : device_t(mconfig, VP550, tag, owner, clock), device_vip_expansion_card_interface(mconfig, *this), - m_pfg_a(*this, CDP1863_A_TAG), - m_pfg_b(*this, CDP1863_B_TAG), + m_pfg(*this, "u%u", 1U), m_sync_timer(nullptr) { } @@ -90,19 +67,19 @@ vp550_device::vp550_device(const machine_config &mconfig, const char *tag, devic void vp550_device::device_start() { // allocate timers - m_sync_timer = timer_alloc(); + m_sync_timer = timer_alloc(FUNC(vp550_device::sync_tick), this); m_sync_timer->adjust(attotime::from_hz(50), 0, attotime::from_hz(50)); m_sync_timer->enable(0); } //------------------------------------------------- -// device_timer - handler timer events +// sync_timer - fire an interrupt on host //------------------------------------------------- -void vp550_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(vp550_device::sync_tick) { - if (LOG) logerror("VP550 '%s' Interrupt\n", tag()); + LOG("VP550 '%s' Interrupt\n", tag()); m_slot->interrupt_w(ASSERT_LINE); } @@ -120,8 +97,8 @@ void vp550_device::vip_program_w(offs_t offset, uint8_t data, int cdef, int *min switch (offset & 0x03) { - case 1: m_pfg_a->str_w(data); break; - case 2: m_pfg_b->str_w(data); break; + case 1: m_pfg[0]->str_w(data); break; + case 2: m_pfg[1]->str_w(data); break; case 3: octave_w(data); break; } @@ -143,7 +120,7 @@ void vp550_device::vip_sc_w(int n, int sc) { if (BIT(sc, 1)) { - if (LOG) logerror("VP550 '%s' Clear Interrupt\n", tag()); + LOG("VP550 '%s' Clear Interrupt\n", tag()); m_slot->interrupt_w(CLEAR_LINE); } @@ -156,8 +133,8 @@ void vp550_device::vip_sc_w(int n, int sc) void vp550_device::vip_q_w(int state) { - m_pfg_a->oe_w(state); - m_pfg_b->oe_w(state); + m_pfg[0]->oe_w(state); + m_pfg[1]->oe_w(state); } @@ -169,8 +146,8 @@ void vp550_device::vip_run_w(int state) { if (!state) { - m_pfg_a->reset(); - m_pfg_b->reset(); + m_pfg[0]->reset(); + m_pfg[1]->reset(); } } @@ -184,24 +161,14 @@ void vp550_device::octave_w(uint8_t data) int channel = (data >> 2) & 0x03; int clock2 = 0; - if (data & 0x10) + if (BIT(data, 4)) { - switch (data & 0x03) - { - case 0: clock2 = m_slot->clock() / 8; break; - case 1: clock2 = m_slot->clock() / 4; break; - case 2: clock2 = m_slot->clock() / 2; break; - case 3: clock2 = m_slot->clock(); break; - } + clock2 = m_slot->clock() >> (3 - (data & 0x03)); } - switch (channel) - { - case CHANNEL_A: m_pfg_a->set_clk2(clock2); break; - case CHANNEL_B: m_pfg_b->set_clk2(clock2); break; - } + m_pfg[BIT(data, 2)]->set_clk2(clock2); - if (LOG) logerror("VP550 '%s' Clock %c: %u Hz\n", tag(), 'A' + channel, clock2); + LOG("VP550 '%s' Clock %c: %u Hz\n", tag(), 'A' + channel, clock2); } @@ -211,11 +178,10 @@ void vp550_device::octave_w(uint8_t data) void vp550_device::vlmna_w(uint8_t data) { - if (LOG) logerror("VP550 '%s' A Volume: %u\n", tag(), data & 0x0f); + LOG("VP550 '%s' A Volume: %u\n", tag(), data & 0x0f); - float gain = (data & 0x0f) * 0.0666; - - m_pfg_a->set_output_gain(0, gain); + float gain = (data & 0x0f) / 15.0f; + m_pfg[0]->set_output_gain(0, gain); } @@ -225,11 +191,10 @@ void vp550_device::vlmna_w(uint8_t data) void vp550_device::vlmnb_w(uint8_t data) { - if (LOG) logerror("VP550 '%s' B Volume: %u\n", tag(), data & 0x0f); - - float gain = (data & 0x0f) * 0.0666; + LOG("VP550 '%s' B Volume: %u\n", tag(), data & 0x0f); - m_pfg_b->set_output_gain(0, gain); + float gain = (data & 0x0f) / 15.0f; + m_pfg[1]->set_output_gain(0, gain); } @@ -239,7 +204,7 @@ void vp550_device::vlmnb_w(uint8_t data) void vp550_device::sync_w(uint8_t data) { - if (LOG) logerror("VP550 '%s' Interrupt Enable: %u\n", tag(), BIT(data, 0)); + LOG("VP550 '%s' Interrupt Enable: %u\n", tag(), BIT(data, 0)); m_sync_timer->enable(BIT(data, 0)); } diff --git a/src/devices/bus/vip/vp550.h b/src/devices/bus/vip/vp550.h index 1a777ebebbb..c7f629bbf9d 100644 --- a/src/devices/bus/vip/vp550.h +++ b/src/devices/bus/vip/vp550.h @@ -32,7 +32,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; virtual void device_add_mconfig(machine_config &config) override; // device_vip_expansion_card_interface overrides @@ -41,14 +40,15 @@ protected: virtual void vip_q_w(int state) override; virtual void vip_run_w(int state) override; + TIMER_CALLBACK_MEMBER(sync_tick); + private: void octave_w(uint8_t data); void vlmna_w(uint8_t data); void vlmnb_w(uint8_t data); void sync_w(uint8_t data); - required_device<cdp1863_device> m_pfg_a; - required_device<cdp1863_device> m_pfg_b; + required_device_array<cdp1863_device, 2> m_pfg; // timers emu_timer *m_sync_timer; diff --git a/src/devices/bus/vme/vme_cp31.cpp b/src/devices/bus/vme/vme_cp31.cpp index 9f5d5d614b0..2a59f92b7ed 100644 --- a/src/devices/bus/vme/vme_cp31.cpp +++ b/src/devices/bus/vme/vme_cp31.cpp @@ -288,7 +288,7 @@ vme_cp31_card_device::vme_cp31_card_device(const machine_config &mconfig, const void vme_cp31_card_device::device_start() { - m_bus_error_timer = timer_alloc(0); + m_bus_error_timer = timer_alloc(FUNC(vme_cp31_card_device::bus_error_off), this); } void vme_cp31_card_device::device_reset() @@ -314,7 +314,7 @@ void vme_cp31_card_device::device_reset() &m_rom_shadow_tap); } -void vme_cp31_card_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(vme_cp31_card_device::bus_error_off) { m_bus_error = false; } diff --git a/src/devices/bus/vme/vme_cp31.h b/src/devices/bus/vme/vme_cp31.h index 5921eef9fe8..38ff78d69b3 100644 --- a/src/devices/bus/vme/vme_cp31.h +++ b/src/devices/bus/vme/vme_cp31.h @@ -32,7 +32,8 @@ protected: virtual void device_add_mconfig(machine_config &config) override; virtual const tiny_rom_entry *device_rom_region() const 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(bus_error_off); private: required_device<m68000_base_device> m_maincpu; diff --git a/src/devices/bus/vme/vme_fccpu20.cpp b/src/devices/bus/vme/vme_fccpu20.cpp index 084e5ba14e5..c85f6fd6a7f 100644 --- a/src/devices/bus/vme/vme_fccpu20.cpp +++ b/src/devices/bus/vme/vme_fccpu20.cpp @@ -204,11 +204,7 @@ #define LOGSETUP(...) LOGMASKED(LOG_SETUP, __VA_ARGS__) #define LOGINT(...) LOGMASKED(LOG_INT, __VA_ARGS__) -#ifdef _MSC_VER -#define FUNCNAME __func__ -#else -#define FUNCNAME __PRETTY_FUNCTION__ -#endif + //************************************************************************** // GLOBAL VARIABLES @@ -387,7 +383,7 @@ vme_fccpu20_device::vme_fccpu20_device(const machine_config &mconfig, device_typ , m_mpcc3 (*this, "mpcc3") , m_board_id(board_id) { - LOG("%s\n", FUNCNAME); + LOG("vme_fccpu20_device ctor\n"); } //************************************************************************** @@ -396,67 +392,61 @@ vme_fccpu20_device::vme_fccpu20_device(const machine_config &mconfig, device_typ vme_fccpu20_card_device::vme_fccpu20_card_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) : vme_fccpu20_card_device(mconfig, VME_FCCPU20, tag, owner, clock) { - LOG("%s %s\n", tag, FUNCNAME); + LOG("vme_fccpu20_card_device ctor: %s\n", tag); } vme_fccpu21s_card_device::vme_fccpu21s_card_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) : vme_fccpu21s_card_device(mconfig, VME_FCCPU21S, tag, owner, clock) { - LOG("%s %s\n", tag, FUNCNAME); + LOG("vme_fccpu21s_card_device ctor: %s\n", tag); } vme_fccpu21_card_device::vme_fccpu21_card_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) : vme_fccpu21_card_device(mconfig, VME_FCCPU21, tag, owner, clock) { - LOG("%s %s\n", tag, FUNCNAME); + LOG("vme_fccpu21_card_device ctor: %s\n", tag); } vme_fccpu21a_card_device::vme_fccpu21a_card_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) : vme_fccpu21a_card_device(mconfig, VME_FCCPU21A, tag, owner, clock) { - LOG("%s %s\n", tag, FUNCNAME); + LOG("vme_fccpu21a_card_device ctor: %s\n", tag); } // TODO: Change to 2MB on board RAM and move FLME memory and find/verify memory map vme_fccpu21ya_card_device::vme_fccpu21ya_card_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) : vme_fccpu21ya_card_device(mconfig, VME_FCCPU21YA, tag, owner, clock) { - LOG("%s %s\n", tag, FUNCNAME); + LOG("vme_fccpu21ya_card_device ctor: %s\n", tag); } vme_fccpu21b_card_device::vme_fccpu21b_card_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) : vme_fccpu21b_card_device(mconfig, VME_FCCPU21B, tag, owner, clock) { - LOG("%s %s\n", tag, FUNCNAME); + LOG("vme_fccpu21b_card_device ctor: %s\n", tag); } // TODO: Change to 2MB on board RAM and move FLME memory and find/verify memory map vme_fccpu21yb_card_device::vme_fccpu21yb_card_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) : vme_fccpu21yb_card_device(mconfig, VME_FCCPU21YB, tag, owner, clock) { - LOG("%s %s\n", tag, FUNCNAME); + LOG("vme_fccpu21yb_card_device ctor: %s\n", tag); } -enum -{ - TIMER_ID_BUS_GRANT -}; - -/* Start it up */ void vme_fccpu20_device::device_start() { - LOG("%s\n", FUNCNAME); + LOG("vme_fccpu20_device::device_start\n"); - save_pointer (NAME (m_sysrom), sizeof(m_sysrom)); - save_pointer (NAME (m_sysram), sizeof(m_sysram)); + save_pointer(NAME(m_sysrom), sizeof(m_sysrom)); + save_pointer(NAME(m_sysram), sizeof(m_sysram)); // save_item(NAME(m_board_id)); // TODO: Save this "non base type" item /* TODO: setup this RAM from (not yet) optional SRAM-2x board and also support 2MB versions */ //m_maincpu->space(AS_PROGRAM).install_ram(0x80000, m_ram->size() + 0x7ffff, m_ram->pointer()); /* Setup pointer to bootvector in ROM for bootvector handler bootvect_r */ - m_sysrom = (uint32_t*)(memregion ("roms")->base()); + m_sysrom = (uint32_t*)(memregion("roms")->base()); #if 0 // TODO: Setup VME access handlers for shared memory area uint32_t base = 0xFFFF5000; @@ -465,43 +455,36 @@ void vme_fccpu20_device::device_start() m_vme->install_device(base + 2, base + 3, // Channel B - Control read8_delegate(*subdevice<z80sio_device>("pit"), FUNC(z80sio_device::cb_r)), write8_delegate(*subdevice<z80sio_device>("pit"), FUNC(z80sio_device::cb_w)), 0x00ff); #endif - m_arbiter_start = timer_alloc(TIMER_ID_BUS_GRANT); + m_arbiter_start = timer_alloc(FUNC(vme_fccpu20_device::grant_bus), this); } void vme_fccpu20_device::device_reset() { - LOG("%s\n", FUNCNAME); + LOG("vme_fccpu20_device::device_reset\n"); /* We need to delay the static bus grant signal until we have it from the VME interface or MAME supports bus arbitration */ - m_arbiter_start->adjust(attotime::from_msec(10), TIMER_ID_BUS_GRANT, attotime::never); + m_arbiter_start->adjust(attotime::from_msec(10)); } //------------------------------------------------- -// device_timer - handler timer events +// grant_bus //------------------------------------------------- -void vme_fccpu20_device::device_timer (emu_timer &timer, device_timer_id id, int param) + +TIMER_CALLBACK_MEMBER(vme_fccpu20_device::grant_bus) { - switch(id) - { - case TIMER_ID_BUS_GRANT: - m_pit->h1_w(ASSERT_LINE); // Grant bus always - break; - default: - LOG("Unhandled Timer ID %d\n", id); - break; - } + m_pit->h1_w(ASSERT_LINE); // Grant bus always } /* Boot vector handler, the PCB hardwires the first 8 bytes from 0xff800000 to 0x0 at reset*/ uint32_t vme_fccpu20_device::bootvect_r(offs_t offset) { - LOG("%s\n", FUNCNAME); + LOG("vme_fccpu20_device::bootvect_r\n"); return m_sysrom[offset]; } void vme_fccpu20_device::bootvect_w(offs_t offset, uint32_t data, uint32_t mem_mask) { - LOG("%s\n", FUNCNAME); + LOG("vme_fccpu20_device::bootvect_w\n"); m_sysram[offset % std::size(m_sysram)] &= ~mem_mask; m_sysram[offset % std::size(m_sysram)] |= (data & mem_mask); m_sysrom = &m_sysram[0]; // redirect all upcoming accesses to masking RAM until reset. @@ -509,29 +492,29 @@ void vme_fccpu20_device::bootvect_w(offs_t offset, uint32_t data, uint32_t mem_m WRITE_LINE_MEMBER(vme_fccpu20_device::bim_irq_callback) { - LOGINT("%s(%02x)\n", FUNCNAME, state); + LOGINT("vme_fccpu20_device::bim_irq_callback(%02x)\n", state); - bim_irq_state = state; - bim_irq_level = m_bim->get_irq_level(); - LOGINT(" - BIM irq level %s\n", bim_irq_level == CLEAR_LINE ? "Cleared" : "Asserted"); + m_bim_irq_state = state; + m_bim_irq_level = m_bim->get_irq_level(); + LOGINT(" - BIM irq level %s\n", m_bim_irq_level == CLEAR_LINE ? "Cleared" : "Asserted"); update_irq_to_maincpu(); } void vme_fccpu20_device::update_irq_to_maincpu() { - LOGINT("%s()\n", FUNCNAME); - LOGINT(" - bim_irq_level: %02x\n", bim_irq_level); - LOGINT(" - bim_irq_state: %02x\n", bim_irq_state); - switch (bim_irq_level & 0x07) + LOGINT("vme_fccpu20_device::update_irq_to_maincpu()\n"); + LOGINT(" - m_bim_irq_level: %02x\n", m_bim_irq_level); + LOGINT(" - m_bim_irq_state: %02x\n", m_bim_irq_state); + switch (m_bim_irq_level & 0x07) { - case 1: m_maincpu->set_input_line(M68K_IRQ_1, bim_irq_state); break; - case 2: m_maincpu->set_input_line(M68K_IRQ_2, bim_irq_state); break; - case 3: m_maincpu->set_input_line(M68K_IRQ_3, bim_irq_state); break; - case 4: m_maincpu->set_input_line(M68K_IRQ_4, bim_irq_state); break; - case 5: m_maincpu->set_input_line(M68K_IRQ_5, bim_irq_state); break; - case 6: m_maincpu->set_input_line(M68K_IRQ_6, bim_irq_state); break; - case 7: m_maincpu->set_input_line(M68K_IRQ_7, bim_irq_state); break; - default: logerror("Programmatic error in %s, please report\n", FUNCNAME); + case 1: m_maincpu->set_input_line(M68K_IRQ_1, m_bim_irq_state); break; + case 2: m_maincpu->set_input_line(M68K_IRQ_2, m_bim_irq_state); break; + case 3: m_maincpu->set_input_line(M68K_IRQ_3, m_bim_irq_state); break; + case 4: m_maincpu->set_input_line(M68K_IRQ_4, m_bim_irq_state); break; + case 5: m_maincpu->set_input_line(M68K_IRQ_5, m_bim_irq_state); break; + case 6: m_maincpu->set_input_line(M68K_IRQ_6, m_bim_irq_state); break; + case 7: m_maincpu->set_input_line(M68K_IRQ_7, m_bim_irq_state); break; + default: logerror("Unsupported BIM IRQ line value 0 in vme_fccpu20_device::update_irq_to_maincpu, please report\n"); } } @@ -557,14 +540,14 @@ void vme_fccpu20_device::update_irq_to_maincpu() uint8_t vme_fccpu20_device::pita_r() { - LOG("%s\n", FUNCNAME); + LOG("vme_fccpu20_device::pita_r\n"); return FORCEBUG | BR7N9600; } /* Enabling/Disabling of VME IRQ 1-7 */ uint8_t vme_fccpu20_device::pitb_r() { - LOG("%s\n", FUNCNAME); + LOG("vme_fccpu20_device::pitb_r\n"); return 0xff; } @@ -574,7 +557,7 @@ uint8_t vme_fccpu20_device::pitc_r() { uint8_t board_id = 0; - LOG("%s Board id:%02x\n", FUNCNAME, m_board_id); + LOG("vme_fccpu20_device::pitc_r Board id:%02x\n", m_board_id); switch (m_board_id) { @@ -589,8 +572,9 @@ uint8_t vme_fccpu20_device::pitc_r() case cpu21: board_id = CPU21; break; - default: logerror("Attempt to set unknown board type %02x, defaulting to CPU20\n", board_id); + default: logerror("Attempted to set unknown board type %02x, defaulting to CPU20\n", board_id); board_id = CPU20; + break; } return board_id | 0xbf; @@ -615,7 +599,7 @@ ROM_END const tiny_rom_entry *vme_fccpu20_device::device_rom_region() const { - LOG("%s\n", FUNCNAME); + LOG("vme_fccpu20_device::device_rom_region\n"); switch (m_board_id) { @@ -626,7 +610,7 @@ const tiny_rom_entry *vme_fccpu20_device::device_rom_region() const case cpu21yb: return ROM_NAME( fccpu21yb ); break; case cpu21s: return ROM_NAME( fccpu21s ); break; case cpu21: return ROM_NAME( fccpu21 ); break; - default: logerror("Attempt to get rom set for unknown board type %02x, defaulting to CPU20\n", m_board_id); + default: logerror("Attempted to get rom set for unknown board type %02x, defaulting to CPU20\n", m_board_id); return ROM_NAME( fccpu20 ); } } diff --git a/src/devices/bus/vme/vme_fccpu20.h b/src/devices/bus/vme/vme_fccpu20.h index ae26d07eccc..42569041f87 100644 --- a/src/devices/bus/vme/vme_fccpu20.h +++ b/src/devices/bus/vme/vme_fccpu20.h @@ -43,14 +43,15 @@ 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; // optional information overrides virtual void device_add_mconfig(machine_config &config) override; virtual const tiny_rom_entry *device_rom_region() const override; - uint8_t bim_irq_state; - int bim_irq_level; + TIMER_CALLBACK_MEMBER(grant_bus); + + int m_bim_irq_state; + uint8_t m_bim_irq_level; emu_timer *m_arbiter_start; // Need a startup delay because it is hooked up to the sense inputs of the PIT diff --git a/src/devices/bus/vme/vme_hcpu30.cpp b/src/devices/bus/vme/vme_hcpu30.cpp index 7aa814794e7..a68cdb319f2 100644 --- a/src/devices/bus/vme/vme_hcpu30.cpp +++ b/src/devices/bus/vme/vme_hcpu30.cpp @@ -44,12 +44,6 @@ #define LOGSETUP(...) LOGMASKED(LOG_SETUP, __VA_ARGS__) #define LOGINT(...) LOGMASKED(LOG_INT, __VA_ARGS__) -#ifdef _MSC_VER -#define FUNCNAME __func__ -#else -#define FUNCNAME __PRETTY_FUNCTION__ -#endif - #define DUSCC_CLOCK XTAL(14'745'600) /* XXX Unverified */ #define RS232P1_TAG "rs232p1" @@ -117,24 +111,24 @@ void vme_hcpu30_card_device::oscpu_space_map(address_map &map) static INPUT_PORTS_START(hcpu30) PORT_START("SA1") - PORT_DIPNAME(0x03, 0x00, "Console port speed") + PORT_DIPNAME(0x03, 0x00, "Console Port Speed") PORT_DIPSETTING(0x00, "9600") PORT_DIPSETTING(0x01, "19200") PORT_DIPSETTING(0x02, "38400") PORT_DIPSETTING(0x03, "4800") - PORT_DIPNAME(0x04, 0x04, "Boot into...") + PORT_DIPNAME(0x04, 0x04, "Boot Mode") PORT_DIPSETTING(0x00, "UNIX") PORT_DIPSETTING(0x04, "Monitor") PORT_DIPNAME(0x08, 0x00, "Undefined 1") PORT_DIPSETTING(0x00, "Off") PORT_DIPSETTING(0x08, "On") - PORT_DIPNAME(0x10, 0x00, "VME bus width") + PORT_DIPNAME(0x10, 0x00, "VME Bus Width") PORT_DIPSETTING(0x00, "32 bits") PORT_DIPSETTING(0x10, "16 bits") - PORT_DIPNAME(0x20, 0x00, "VME bus free") + PORT_DIPNAME(0x20, 0x00, "VME Bus Free") PORT_DIPSETTING(0x00, "ROR") PORT_DIPSETTING(0x20, "REC") - PORT_DIPNAME(0x40, 0x00, "Cache burst mode") + PORT_DIPNAME(0x40, 0x00, "Cache Burst Mode") PORT_DIPSETTING(0x00, "Off") PORT_DIPSETTING(0x40, "On") PORT_DIPNAME(0x80, 0x00, "Undefined 2") @@ -265,20 +259,20 @@ uint32_t vme_hcpu30_card_device::rtc_r(offs_t offset) if (offset == 0) { data &= 0xffffff; - data |= ioport("SA1")->read() << 24; + data |= m_dips->read() << 24; } if (offset == 7) { data &= 0xff00ffff; data |= (m_cent_status_in->read() ^ 0xff) << 16; } - LOG("%s(%02x)==%08x%s\n", FUNCNAME, offset, data, m_rtc_hack ? " hacked" : ""); + LOG("vme_hcpu30_card_device::rtc_r(%02x) == %08x %s\n", offset, data, m_rtc_hack ? "(hacked)" : ""); return data; } void vme_hcpu30_card_device::rtc_w(offs_t offset, uint32_t data, uint32_t mem_mask) { - LOG("%s(%02x,%08x)<-%08x\n", FUNCNAME, offset, mem_mask, data); + LOG("vme_hcpu30_card_device::rtc_w(%02x, %08x)<-%08x\n", offset, mem_mask, data); if (mem_mask == 0xffff0000) { m_rtc->write(offset << 1, (data >> 4) & 15); @@ -293,7 +287,7 @@ void vme_hcpu30_card_device::rtc_w(offs_t offset, uint32_t data, uint32_t mem_ma m_rtc->write((offset << 1) + 1, (data >> 20) & 15); m_rtc_reg[(offset << 1) + 1] = (data >> 20) & 15; } - if (offset < 6 || (offset == 6 && mem_mask == 0xffff0000)) m_rtc_hack = true; else m_rtc_hack = false; + m_rtc_hack = (offset < 6 || (offset == 6 && mem_mask == 0xffff0000)); } uint32_t vme_hcpu30_card_device::dma_r(offs_t offset) @@ -333,46 +327,46 @@ uint32_t vme_hcpu30_card_device::trap_r(offs_t offset, uint32_t mem_mask) void vme_hcpu30_card_device::trap_w(offs_t offset, uint32_t data, uint32_t mem_mask) { - LOG("%s(%08x,%08X)\n", FUNCNAME, offset << 2, data); + LOG("vme_hcpu30_card_device::trap_w(%08x, %08X)\n", offset << 2, data); if (!machine().side_effects_disabled()) set_bus_error((offset << 2), false, mem_mask); } -// AH? +// Active High? WRITE_LINE_MEMBER(vme_hcpu30_card_device::dusirq_callback) { - LOGINT("%s(%02x)\n", FUNCNAME, state); - m_irq_state &= ~(1 << (8+4)); - m_irq_state |= (state << (8+4)); + LOGINT("vme_hcpu30_card_device::dusirq_callback(%02x)\n", state); + m_irq_state &= ~(1 << 12); + m_irq_state |= (state << 12); } -// AL? +// Active Low? WRITE_LINE_MEMBER(vme_hcpu30_card_device::scsiirq_callback) { - LOGINT("%s(%02x)\n", FUNCNAME, state); + LOGINT("vme_hcpu30_card_device::scsiirq_callback(%02x)\n", state); m_irq_state &= ~(1 << 8); m_irq_state |= (state << 8); } -// AL? +// Active Low? WRITE_LINE_MEMBER(vme_hcpu30_card_device::scsidrq_callback) { - LOGINT("%s(%02x)\n", FUNCNAME, state); + LOGINT("vme_hcpu30_card_device::scsidrq_callback(%02x)\n", state); m_irq_state &= ~(1 << 7); m_irq_state |= (state << 7); } -// AL? +// Active Low? WRITE_LINE_MEMBER(vme_hcpu30_card_device::fdcirq_callback) { - LOGINT("%s(%02x)\n", FUNCNAME, state); + LOGINT("vme_hcpu30_card_device::fdcirq_callback(%02x)\n", state); m_irq_state &= ~(1 << (8+2)); m_irq_state |= (state << (8+2)); } -// AL? +// Active Low? WRITE_LINE_MEMBER(vme_hcpu30_card_device::fdcdrq_callback) { - LOGINT("%s(%02x)\n", FUNCNAME, state); + LOGINT("vme_hcpu30_card_device::fdcdrq_callback(%02x)\n", state); #if 0 if (state) { @@ -455,12 +449,10 @@ void vme_hcpu30_card_device::update_030_irq(int irq, line_state state) // 15 - INTENA* "enable input" pin of LS148 priority encoder void vme_hcpu30_card_device::irq_mask_w(offs_t offset, uint32_t data, uint32_t mem_mask) { - uint16_t diff; - data >>= 16; - diff = data ^ m_irq_mask; + uint16_t diff = data ^ m_irq_mask; - LOG("%s(%04x,%04x)\n", FUNCNAME, data, diff); + LOG("vme_hcpu30_card_device::irq_mask_w(%04x,%04x)\n", data, diff); if (BIT(diff, 15)) { @@ -551,8 +543,9 @@ vme_hcpu30_card_device::vme_hcpu30_card_device(const machine_config &mconfig, de , m_mailbox(*this, "mailbox") , m_p_ram(*this, "dram") , m_sysrom(*this, "user1") + , m_dips(*this, "SA1") { - LOG("%s %s\n", tag, FUNCNAME); + LOG("vme_hcpu30_card_device::vme_hcpu30_card_device ctor: %s\n", tag); m_slot = 1; } @@ -565,16 +558,16 @@ vme_hcpu30_card_device::vme_hcpu30_card_device(const machine_config &mconfig, co void vme_hcpu30_card_device::device_start() { - LOG("%s %s\n", tag(), FUNCNAME); + LOG("vme_hcpu30_card_device::device_start %s\n", tag()); - m_bus_error_timer = timer_alloc(0); + m_bus_error_timer = timer_alloc(FUNC(vme_hcpu30_card_device::bus_error_off), this); } void vme_hcpu30_card_device::device_reset() { address_space &program = m_maincpu->space(AS_PROGRAM); - LOG("%s %s\n", tag(), FUNCNAME); + LOG("vme_hcpu30_card_device::device_reset %s\n", tag()); m_irq_state = (1 << 10) | (1 << 6); // fdcirq | irq30* m_irq_mask = 0; m_rtc_hack = false; @@ -600,7 +593,7 @@ void vme_hcpu30_card_device::device_reset() &m_rom_shadow_tap); } -void vme_hcpu30_card_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(vme_hcpu30_card_device::bus_error_off) { m_bus_error = false; } diff --git a/src/devices/bus/vme/vme_hcpu30.h b/src/devices/bus/vme/vme_hcpu30.h index 656e8b716b6..14c5e0059b0 100644 --- a/src/devices/bus/vme/vme_hcpu30.h +++ b/src/devices/bus/vme/vme_hcpu30.h @@ -36,7 +36,8 @@ protected: virtual void device_add_mconfig(machine_config &config) override; virtual const tiny_rom_entry *device_rom_region() const 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(bus_error_off); private: required_device<m68000_base_device> m_maincpu; @@ -53,6 +54,7 @@ private: required_shared_ptr<uint32_t> m_mailbox; required_shared_ptr<uint32_t> m_p_ram; required_region_ptr<uint32_t> m_sysrom; + required_ioport m_dips; DECLARE_WRITE_LINE_MEMBER(dusirq_callback); DECLARE_WRITE_LINE_MEMBER(scsiirq_callback); diff --git a/src/devices/bus/vsmile/keyboard.cpp b/src/devices/bus/vsmile/keyboard.cpp index e91ae85c967..2c2501ecd8e 100644 --- a/src/devices/bus/vsmile/keyboard.cpp +++ b/src/devices/bus/vsmile/keyboard.cpp @@ -67,12 +67,9 @@ void vsmile_keyboard_device::device_start() { vsmile_ctrl_device_base::device_start(); - m_idle_timer = machine().scheduler().timer_alloc( - timer_expired_delegate(FUNC(vsmile_keyboard_device::handle_idle), this)); - m_hello_timer = machine().scheduler().timer_alloc( - timer_expired_delegate(FUNC(vsmile_keyboard_device::handle_hello), this)); - m_hello_timeout_timer = machine().scheduler().timer_alloc( - timer_expired_delegate(FUNC(vsmile_keyboard_device::handle_hello_timeout), this)); + m_idle_timer = timer_alloc(FUNC(vsmile_keyboard_device::handle_idle), this); + m_hello_timer = timer_alloc(FUNC(vsmile_keyboard_device::handle_hello), this); + m_hello_timeout_timer = timer_alloc(FUNC(vsmile_keyboard_device::handle_hello_timeout), this); save_item(NAME(m_state)); save_item(NAME(m_sent_joy)); diff --git a/src/devices/bus/vsmile/pad.cpp b/src/devices/bus/vsmile/pad.cpp index 5cf7940ab39..7383de09475 100644 --- a/src/devices/bus/vsmile/pad.cpp +++ b/src/devices/bus/vsmile/pad.cpp @@ -49,8 +49,7 @@ void vsmile_pad_device::device_start() { vsmile_ctrl_device_base::device_start(); - m_idle_timer = machine().scheduler().timer_alloc( - timer_expired_delegate(FUNC(vsmile_pad_device::handle_idle), this)); + m_idle_timer = timer_alloc(FUNC(vsmile_pad_device::handle_idle), this); m_idle_timer->adjust(attotime::from_seconds(1)); m_sent_joy = 0x0000U; diff --git a/src/devices/bus/vsmile/vsmile_ctrl.cpp b/src/devices/bus/vsmile/vsmile_ctrl.cpp index fa937beb1ad..f253e800fab 100644 --- a/src/devices/bus/vsmile/vsmile_ctrl.cpp +++ b/src/devices/bus/vsmile/vsmile_ctrl.cpp @@ -115,12 +115,10 @@ vsmile_ctrl_device_base::~vsmile_ctrl_device_base() void vsmile_ctrl_device_base::device_start() { // allocate a timer to limit transmit rate to something realistic - m_tx_timer = machine().scheduler().timer_alloc( - timer_expired_delegate(FUNC(vsmile_ctrl_device_base::tx_timer_expired), this)); + m_tx_timer = timer_alloc(FUNC(vsmile_ctrl_device_base::tx_timer_expired), this); // allocate a timer for RTS timeouts - m_rts_timer = machine().scheduler().timer_alloc( - timer_expired_delegate(FUNC(vsmile_ctrl_device_base::rts_timer_expired), this)); + m_rts_timer = timer_alloc(FUNC(vsmile_ctrl_device_base::rts_timer_expired), this); // start with transmit queue empty m_tx_fifo_head = m_tx_fifo_tail = 0U; diff --git a/src/devices/bus/vtech/memexp/sdloader.cpp b/src/devices/bus/vtech/memexp/sdloader.cpp index 1799bac84ba..84df085c86a 100644 --- a/src/devices/bus/vtech/memexp/sdloader.cpp +++ b/src/devices/bus/vtech/memexp/sdloader.cpp @@ -130,7 +130,7 @@ void vtech_sdloader_device::device_start() m_expbank->configure_entry(1, m_ram.get() + 0x18000); // allocate timer for sdcard - m_spi_clock = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(vtech_sdloader_device::spi_clock), this)); + m_spi_clock = timer_alloc(FUNC(vtech_sdloader_device::spi_clock), this); // register for savestates save_item(NAME(m_spi_clock_state)); diff --git a/src/devices/bus/wswan/rom.cpp b/src/devices/bus/wswan/rom.cpp index 3f015fbc8e1..2d089989989 100644 --- a/src/devices/bus/wswan/rom.cpp +++ b/src/devices/bus/wswan/rom.cpp @@ -89,7 +89,7 @@ void ws_rom_device::device_start() // Set up RTC timer if (m_has_rtc) { - rtc_timer = timer_alloc(TIMER_RTC); + rtc_timer = timer_alloc(FUNC(ws_rom_device::rtc_tick), this); rtc_timer->adjust(attotime::zero, 0, attotime::from_seconds(1)); } @@ -196,44 +196,41 @@ void ws_rom_eeprom_device::device_reset() //------------------------------------------------- -// device_timer - handler timer events +// rtc_tick //------------------------------------------------- -void ws_rom_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(ws_rom_device::rtc_tick) { - if (id == TIMER_RTC) - { - // a second passed - m_rtc_second++; - if ((m_rtc_second & 0x0f) > 9) - m_rtc_second = (m_rtc_second & 0xf0) + 0x10; + // a second passed + m_rtc_second++; + if ((m_rtc_second & 0x0f) > 9) + m_rtc_second = (m_rtc_second & 0xf0) + 0x10; - // check for minute passed - if (m_rtc_second >= 0x60) - { - m_rtc_second = 0; - m_rtc_minute++; - if ((m_rtc_minute & 0x0f) > 9) - m_rtc_minute = (m_rtc_minute & 0xf0) + 0x10; - } + // check for minute passed + if (m_rtc_second >= 0x60) + { + m_rtc_second = 0; + m_rtc_minute++; + if ((m_rtc_minute & 0x0f) > 9) + m_rtc_minute = (m_rtc_minute & 0xf0) + 0x10; + } - // check for hour passed - if (m_rtc_minute >= 0x60) - { - m_rtc_minute = 0; - m_rtc_hour++; - if ((m_rtc_hour & 0x0f) > 9) - m_rtc_hour = (m_rtc_hour & 0xf0) + 0x10; - if (m_rtc_hour == 0x12) - m_rtc_hour |= 0x80; - } + // check for hour passed + if (m_rtc_minute >= 0x60) + { + m_rtc_minute = 0; + m_rtc_hour++; + if ((m_rtc_hour & 0x0f) > 9) + m_rtc_hour = (m_rtc_hour & 0xf0) + 0x10; + if (m_rtc_hour == 0x12) + m_rtc_hour |= 0x80; + } - // check for day passed - if (m_rtc_hour >= 0x24) - { - m_rtc_hour = 0; - m_rtc_day++; - } + // check for day passed + if (m_rtc_hour >= 0x24) + { + m_rtc_hour = 0; + m_rtc_day++; } } diff --git a/src/devices/bus/wswan/rom.h b/src/devices/bus/wswan/rom.h index 6a99f98e3a4..9a47ebf8023 100644 --- a/src/devices/bus/wswan/rom.h +++ b/src/devices/bus/wswan/rom.h @@ -23,14 +23,13 @@ public: virtual void write_io(offs_t offset, u16 data, u16 mem_mask) override; protected: - static constexpr device_timer_id TIMER_RTC = 0; - ws_rom_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, u32 clock); // 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); u16 m_io_regs[8]; u32 m_base20, m_base30, m_base40; diff --git a/src/devices/bus/z88/z88.cpp b/src/devices/bus/z88/z88.cpp index 65c71c8d686..8a12bb47b82 100644 --- a/src/devices/bus/z88/z88.cpp +++ b/src/devices/bus/z88/z88.cpp @@ -26,7 +26,7 @@ DEFINE_DEVICE_TYPE(Z88CART_SLOT, z88cart_slot_device, "z88cart_slot", "Z88 Cartr //************************************************************************** -// Z88 cartridges Interface +// Z88 Cartridge Interface //************************************************************************** //------------------------------------------------- @@ -76,22 +76,19 @@ void z88cart_slot_device::device_start() // resolve callbacks m_out_flp_cb.resolve_safe(); - m_flp_timer = timer_alloc(TIMER_FLP_CLEAR); + m_flp_timer = timer_alloc(FUNC(z88cart_slot_device::close_flap), this); m_flp_timer->reset(); } //------------------------------------------------- -// device_timer - handler timer events +// close_flap //------------------------------------------------- -void z88cart_slot_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(z88cart_slot_device::close_flap) { - if (id == TIMER_FLP_CLEAR) - { - // close the flap - m_out_flp_cb(CLEAR_LINE); - } + // close the flap + m_out_flp_cb(CLEAR_LINE); } /*------------------------------------------------- @@ -126,7 +123,7 @@ image_init_result z88cart_slot_device::call_load() // open the flap m_out_flp_cb(ASSERT_LINE); - // setup the timer for close the flap + // setup the timer to close the flap m_flp_timer->adjust(CLOSE_FLAP_TIME); return image_init_result::PASS; @@ -151,7 +148,7 @@ void z88cart_slot_device::call_unload() // open the flap m_out_flp_cb(ASSERT_LINE); - // setup the timer for close the flap + // setup the timer to close the flap m_flp_timer->adjust(CLOSE_FLAP_TIME); } diff --git a/src/devices/bus/z88/z88.h b/src/devices/bus/z88/z88.h index f4f655f1e95..bece08cbf72 100644 --- a/src/devices/bus/z88/z88.h +++ b/src/devices/bus/z88/z88.h @@ -124,11 +124,10 @@ public: protected: // device-level overrides virtual void device_start() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; -private: - static constexpr device_timer_id TIMER_FLP_CLEAR = 0; + TIMER_CALLBACK_MEMBER(close_flap); +private: devcb_write_line m_out_flp_cb; device_z88cart_interface* m_cart; emu_timer * m_flp_timer; diff --git a/src/devices/cpu/alto2/a2disk.cpp b/src/devices/cpu/alto2/a2disk.cpp index 5000095ff7e..0e031a0cd85 100644 --- a/src/devices/cpu/alto2/a2disk.cpp +++ b/src/devices/cpu/alto2/a2disk.cpp @@ -1741,16 +1741,16 @@ void alto2_cpu_device::init_disk() m_dsk.kcom = 066000; - m_dsk.strobon_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(alto2_cpu_device::disk_strobon),this)); + m_dsk.strobon_timer = timer_alloc(FUNC(alto2_cpu_device::disk_strobon), this); m_dsk.strobon_timer->reset(); - m_dsk.seclate_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(alto2_cpu_device::disk_seclate),this)); + m_dsk.seclate_timer = timer_alloc(FUNC(alto2_cpu_device::disk_seclate), this); m_dsk.seclate_timer->reset(); - m_dsk.ok_to_run_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(alto2_cpu_device::disk_ok_to_run),this)); + m_dsk.ok_to_run_timer = timer_alloc(FUNC(alto2_cpu_device::disk_ok_to_run), this); m_dsk.ok_to_run_timer->adjust(attotime::from_nsec(35 * ALTO2_UCYCLE / 1000), 1); - m_dsk.ready_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(alto2_cpu_device::disk_ready_mf31a),this)); + m_dsk.ready_timer = timer_alloc(FUNC(alto2_cpu_device::disk_ready_mf31a), this); m_dsk.ready_timer->reset(); m_dsk.bitclk_time[0] = static_cast<int>(attotime::from_nsec(300).as_attoseconds() / 1000000); diff --git a/src/devices/cpu/alto2/a2ether.cpp b/src/devices/cpu/alto2/a2ether.cpp index 883259d7445..87ee4268370 100644 --- a/src/devices/cpu/alto2/a2ether.cpp +++ b/src/devices/cpu/alto2/a2ether.cpp @@ -1325,10 +1325,10 @@ void alto2_cpu_device::init_ether(int task) m_eth.rx_packet = std::make_unique<uint16_t[]>(sizeof(uint16_t)*ALTO2_ETHER_PACKET_SIZE); m_eth.tx_packet = std::make_unique<uint16_t[]>(sizeof(uint16_t)*ALTO2_ETHER_PACKET_SIZE); - m_eth.tx_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(alto2_cpu_device::tx_packet),this)); + m_eth.tx_timer = timer_alloc(FUNC(alto2_cpu_device::tx_packet), this); m_eth.tx_timer->reset(); - m_eth.rx_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(alto2_cpu_device::rx_breath_of_life),this)); + m_eth.rx_timer = timer_alloc(FUNC(alto2_cpu_device::rx_breath_of_life), this); m_eth.rx_timer->reset(); } diff --git a/src/devices/cpu/amis2000/amis2000.cpp b/src/devices/cpu/amis2000/amis2000.cpp index 96864b875ce..468b29acd98 100644 --- a/src/devices/cpu/amis2000/amis2000.cpp +++ b/src/devices/cpu/amis2000/amis2000.cpp @@ -188,7 +188,7 @@ void amis2152_cpu_device::device_start() { amis2000_base_device::device_start(); - m_d2f_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(amis2152_cpu_device::d2f_timer_cb), this)); + m_d2f_timer = timer_alloc(FUNC(amis2152_cpu_device::d2f_timer_cb), this); // zerofill m_d2f_latch = 0; diff --git a/src/devices/cpu/arm7/upd800468.cpp b/src/devices/cpu/arm7/upd800468.cpp index edf483eef6e..16b6928bf7c 100644 --- a/src/devices/cpu/arm7/upd800468.cpp +++ b/src/devices/cpu/arm7/upd800468.cpp @@ -61,7 +61,7 @@ void upd800468_timer_device::control_w(u8 data) void upd800468_timer_device::device_start() { - m_timer = timer_alloc(0); + m_timer = timer_alloc(FUNC(upd800468_timer_device::irq_timer_tick), this); m_irq_cb.resolve_safe(); @@ -74,7 +74,7 @@ void upd800468_timer_device::device_reset() m_rate = m_control = 0; } -void upd800468_timer_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(upd800468_timer_device::irq_timer_tick) { if (BIT(m_control, 0)) m_irq_cb(1); diff --git a/src/devices/cpu/arm7/upd800468.h b/src/devices/cpu/arm7/upd800468.h index 6e9a5db4ae3..7f662581c7f 100644 --- a/src/devices/cpu/arm7/upd800468.h +++ b/src/devices/cpu/arm7/upd800468.h @@ -32,7 +32,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(irq_timer_tick); private: devcb_write_line m_irq_cb; diff --git a/src/devices/cpu/cop400/cop400.cpp b/src/devices/cpu/cop400/cop400.cpp index 5c92d3cbc3c..dcd9a6edc0f 100644 --- a/src/devices/cpu/cop400/cop400.cpp +++ b/src/devices/cpu/cop400/cop400.cpp @@ -1031,7 +1031,7 @@ void cop400_cpu_device::serial_tick() } } -void cop400_cpu_device::counter_tick() +TIMER_CALLBACK_MEMBER(cop400_cpu_device::advance_counter) { T++; @@ -1061,17 +1061,6 @@ void cop400_cpu_device::inil_tick() INITIALIZATION ***************************************************************************/ -void cop400_cpu_device::device_timer(emu_timer &timer, device_timer_id id, int param) -{ - switch (id) - { - case TIMER_COUNTER: - counter_tick(); - break; - } -} - - void cop400_cpu_device::device_start() { /* find address spaces */ @@ -1095,7 +1084,7 @@ void cop400_cpu_device::device_start() m_counter_timer = nullptr; if (m_has_counter) { - m_counter_timer = timer_alloc(TIMER_COUNTER); + m_counter_timer = timer_alloc(FUNC(cop400_cpu_device::advance_counter), this); m_counter_timer->adjust(attotime::zero, 0, attotime::from_ticks(m_cki * 4, clock())); } diff --git a/src/devices/cpu/cop400/cop400.h b/src/devices/cpu/cop400/cop400.h index bd068e4f367..45b2b4d0f25 100644 --- a/src/devices/cpu/cop400/cop400.h +++ b/src/devices/cpu/cop400/cop400.h @@ -73,8 +73,6 @@ enum cop400_cko_bond { class cop400_cpu_device : public cpu_device { public: - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; - // L pins: 8-bit bi-directional auto read_l() { return m_read_l.bind(); } auto write_l() { return m_write_l.bind(); } @@ -154,6 +152,8 @@ protected: // device_disasm_interface overrides virtual std::unique_ptr<util::disasm_interface> create_disassembler() override; + TIMER_CALLBACK_MEMBER(advance_counter); + address_space_config m_program_config; address_space_config m_data_config; diff --git a/src/devices/cpu/e0c6200/e0c6s46.cpp b/src/devices/cpu/e0c6200/e0c6s46.cpp index 7c5b1196fb0..5e30570ae76 100644 --- a/src/devices/cpu/e0c6200/e0c6s46.cpp +++ b/src/devices/cpu/e0c6200/e0c6s46.cpp @@ -83,11 +83,11 @@ void e0c6s46_device::device_start() m_pixel_update_cb.resolve(); // create timers - m_core_256_handle = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(e0c6s46_device::core_256_cb), this)); + m_core_256_handle = timer_alloc(FUNC(e0c6s46_device::core_256_cb), this); m_core_256_handle->adjust(attotime::from_ticks(64, unscaled_clock())); - m_prgtimer_handle = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(e0c6s46_device::prgtimer_cb), this)); + m_prgtimer_handle = timer_alloc(FUNC(e0c6s46_device::prgtimer_cb), this); m_prgtimer_handle->adjust(attotime::never); - m_buzzer_handle = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(e0c6s46_device::buzzer_cb), this)); + m_buzzer_handle = timer_alloc(FUNC(e0c6s46_device::buzzer_cb), this); m_buzzer_handle->adjust(attotime::never); // zerofill diff --git a/src/devices/cpu/e132xs/e132xs.cpp b/src/devices/cpu/e132xs/e132xs.cpp index 49e09694136..1331bb1a890 100644 --- a/src/devices/cpu/e132xs/e132xs.cpp +++ b/src/devices/cpu/e132xs/e132xs.cpp @@ -1140,7 +1140,7 @@ void hyperstone_device::init(int scale_mask) } m_io = &space(AS_IO); - m_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(hyperstone_device::timer_callback), this)); + m_timer = timer_alloc(FUNC(hyperstone_device::timer_callback), this); m_core->clock_scale_mask = scale_mask; for (uint8_t i = 0; i < 16; i++) diff --git a/src/devices/cpu/f2mc16/mb9061x.cpp b/src/devices/cpu/f2mc16/mb9061x.cpp index 9a425f7ad95..e8940162329 100644 --- a/src/devices/cpu/f2mc16/mb9061x.cpp +++ b/src/devices/cpu/f2mc16/mb9061x.cpp @@ -41,11 +41,11 @@ void mb9061x_device::device_start() { f2mc16_device::device_start(); - m_tbtc_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(mb9061x_device::tbtc_tick), this)); + m_tbtc_timer = timer_alloc(FUNC(mb9061x_device::tbtc_tick), this); m_tbtc_timer->adjust(attotime::never); - m_timer[0] = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(mb9061x_device::timer0_tick), this)); + m_timer[0] = timer_alloc(FUNC(mb9061x_device::timer0_tick), this); m_timer[0]->adjust(attotime::never); - m_timer[1] = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(mb9061x_device::timer1_tick), this)); + m_timer[1] = timer_alloc(FUNC(mb9061x_device::timer1_tick), this); m_timer[1]->adjust(attotime::never); } diff --git a/src/devices/cpu/h8/h8_sci.cpp b/src/devices/cpu/h8/h8_sci.cpp index 9faaefa08d8..6bc650af5c6 100644 --- a/src/devices/cpu/h8/h8_sci.cpp +++ b/src/devices/cpu/h8/h8_sci.cpp @@ -249,7 +249,7 @@ void h8_sci_device::device_start() tx_cb.resolve_safe(); clk_cb.resolve_safe(); - sync_timer = timer_alloc(0); + sync_timer = timer_alloc(FUNC(h8_sci_device::sync_tick), this); if(external_clock_period.is_never()) { internal_to_external_ratio = 0; @@ -309,7 +309,7 @@ void h8_sci_device::device_reset() cur_sync_time = attotime::never; } -void h8_sci_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(h8_sci_device::sync_tick) { // Used only to force system-wide syncs } @@ -368,7 +368,7 @@ uint64_t h8_sci_device::internal_update(uint64_t current_time) bool new_clock = delta >= divider; if(new_clock != clock_value) { - cpu->synchronize(); + machine().scheduler().synchronize(); if((!new_clock) && (clock_state & CLK_TX)) tx_dropped_edge(); @@ -397,7 +397,7 @@ uint64_t h8_sci_device::internal_update(uint64_t current_time) assert(delta < fp); bool new_clock = delta >= divider*8; if(new_clock != clock_value) { - cpu->synchronize(); + machine().scheduler().synchronize(); if((!new_clock) && (clock_state & CLK_TX)) tx_dropped_edge(); @@ -423,7 +423,7 @@ uint64_t h8_sci_device::internal_update(uint64_t current_time) delta &= 1; bool new_clock = delta >= 1; if(new_clock != clock_value) { - cpu->synchronize(); + machine().scheduler().synchronize(); if((!new_clock) && (clock_state & CLK_TX)) tx_dropped_edge(); @@ -447,7 +447,7 @@ uint64_t h8_sci_device::internal_update(uint64_t current_time) delta &= 15; bool new_clock = delta >= 8; if(new_clock != clock_value) { - cpu->synchronize(); + machine().scheduler().synchronize(); if((!new_clock) && (clock_state & CLK_TX)) tx_dropped_edge(); @@ -485,7 +485,7 @@ void h8_sci_device::clock_start(int mode) return; if(!clock_state) { - cpu->synchronize(); + machine().scheduler().synchronize(); clock_state = mode; switch(clock_mode) { case CLKM_INTERNAL_ASYNC: diff --git a/src/devices/cpu/h8/h8_sci.h b/src/devices/cpu/h8/h8_sci.h index b2a2e575738..8c07ffe5ec2 100644 --- a/src/devices/cpu/h8/h8_sci.h +++ b/src/devices/cpu/h8/h8_sci.h @@ -122,7 +122,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(sync_tick); void clock_start(int mode); void clock_stop(int mode); diff --git a/src/devices/cpu/hd61700/hd61700.cpp b/src/devices/cpu/hd61700/hd61700.cpp index 5ccdd4d79a7..2241855cf1c 100644 --- a/src/devices/cpu/hd61700/hd61700.cpp +++ b/src/devices/cpu/hd61700/hd61700.cpp @@ -34,8 +34,8 @@ #define REG_SX m_regsir[0] #define REG_SY m_regsir[1] #define REG_SZ m_regsir[2] -#define READ_SREG(a) (m_regsir[((a)>>5) & 0x03] & 0x1f) -#define WRITE_SREG(a,d) (m_regsir[((a)>>5) & 0x03] = (d) & 0x1f) +#define READ_SREG(a) (m_regsir[((a) >> 5) & 0x03] & 0x1f) +#define WRITE_SREG(a,d) (m_regsir[((a) >> 5) & 0x03] = (d) & 0x1f) // 8 bit registers #define REG_PE m_reg8bit[0] @@ -60,14 +60,14 @@ #define READ_REG(a) (m_regmain[(a) & 0x1f]) #define WRITE_REG(a,d) (m_regmain[(a) & 0x1f] = d) #define COPY_REG(d,s) (m_regmain[(d) & 0x1f] = m_regmain[(s) & 0x1f]) -#define REG_GET16(r) (((m_regmain[((r)) & 0x1f]<<0)) | (m_regmain[((r) + 1) & 0x1f]<<8)) -#define REG_PUT16(r,d) do{(m_regmain[(r) & 0x1f] = (((d)>>0) & 0xff)); (m_regmain[((r)+1)&0x1f]=(((d)>>8)&0xff));}while(0) +#define REG_GET16(r) (m_regmain[(r) & 0x1f] | (m_regmain[((r) + 1) & 0x1f] << 8)) +#define REG_PUT16(r,d) do { m_regmain[(r) & 0x1f] = (uint8_t)(d); m_regmain[((r) + 1) & 0x1f] = (uint8_t)((d) >> 8); } while(0) // opcode -#define GET_REG_IDX(a,b) (((a<<2) & 0x04) | ((b>>5) & 0x03)) -#define RESTORE_REG(o,r,pr) r = (o&0x02) ? r : pr -#define COND_WRITE_REG(o,a,d) if (o&0x08) WRITE_REG(a,d) -#define GET_IM3(d) (((d>>5)&0x07) + 1) +#define GET_REG_IDX(a,b) (((a << 2) & 0x04) | ((b >> 5) & 0x03)) +#define RESTORE_REG(o,r,pr) r = (o & 0x02) ? r : pr +#define COND_WRITE_REG(o,a,d) if (o & 0x08) WRITE_REG(a,d) +#define GET_IM3(d) (((d >> 5) & 0x07) + 1) // flags #define SET_FLAG_C m_flags |= FLAG_C @@ -77,20 +77,20 @@ #define CLEAR_FLAGS m_flags &= ~(FLAG_Z | FLAG_C | FLAG_LZ | FLAG_UZ) #define CHECK_FLAG_Z(d) if((d) != 0) CLEAR_FLAG_Z -#define CHECK_FLAG_C(d,l) if (d > l) SET_FLAG_C +#define CHECK_FLAG_C(d,l) if ((d) > l) SET_FLAG_C #define CHECK_FLAGB_LZ(d) if(((d) & 0x0f) != 0) CLEAR_FLAG_LZ #define CHECK_FLAGB_UZ(d) if(((d) & 0xf0) != 0) CLEAR_FLAG_UZ #define CHECK_FLAGW_LZ(d) if(((d) & 0x0f00) != 0) CLEAR_FLAG_LZ #define CHECK_FLAGW_UZ(d) if(((d) & 0xf000) != 0) CLEAR_FLAG_UZ -#define CHECK_FLAGB_UZ_LZ(d) do{CHECK_FLAGB_LZ(d); CHECK_FLAGB_UZ(d);}while(0) -#define CHECK_FLAGW_UZ_LZ(d) do{CHECK_FLAGW_LZ(d); CHECK_FLAGW_UZ(d);}while(0) +#define CHECK_FLAGB_UZ_LZ(d) do{ CHECK_FLAGB_LZ(d); CHECK_FLAGB_UZ(d); } while(0) +#define CHECK_FLAGW_UZ_LZ(d) do{ CHECK_FLAGW_LZ(d); CHECK_FLAGW_UZ(d); } while(0) //CPU state #define CPU_FAST 0x01 #define CPU_SLP 0x02 /* HD61700 IRQ vector */ -static const uint16_t irq_vector[] = {0x0032, 0x0042, 0x0052, 0x0062, 0x0072}; +static const uint16_t irq_vector[] = { 0x0032, 0x0042, 0x0052, 0x0062, 0x0072 }; //************************************************************************** // HD61700 DEVICE @@ -135,7 +135,7 @@ void hd61700_cpu_device::device_start() { m_program = &space(AS_PROGRAM); - m_sec_timer = timer_alloc(SEC_TIMER); + m_sec_timer = timer_alloc(FUNC(hd61700_cpu_device::second_tick), this); m_sec_timer->adjust(attotime::from_seconds(1), 0, attotime::from_seconds(1)); m_lcd_ctrl_cb.resolve_safe(); @@ -223,33 +223,23 @@ void hd61700_cpu_device::device_reset() elem = CLEAR_LINE; } - - -//------------------------------------------------- -// device_timer - handler timer events -//------------------------------------------------- -void hd61700_cpu_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(hd61700_cpu_device::second_tick) { - switch(id) + REG_TM++; + if ((REG_TM & 0x3f) == 60) { - case SEC_TIMER: - REG_TM++; - if ((REG_TM&0x3f) == 60) - { - REG_TM = (REG_TM & 0xc0) + 0x40; + REG_TM = (REG_TM & 0xc0) + 0x40; - if (((REG_IE>>3) & (1<<HD61700_TIMER_INT))) - { - REG_IB |= (1<<HD61700_TIMER_INT); + if (((REG_IE >> 3) & (1 << HD61700_TIMER_INT))) + { + REG_IB |= (1 << HD61700_TIMER_INT); - if (REG_IB & 0x20) - { - m_state &= ~CPU_SLP; - m_flags |= FLAG_APO; - } - } + if (REG_IB & 0x20) + { + m_state &= ~CPU_SLP; + m_flags |= FLAG_APO; } - break; + } } } @@ -310,13 +300,13 @@ std::unique_ptr<util::disasm_interface> hd61700_cpu_device::create_disassembler( bool hd61700_cpu_device::check_irqs() { - for (int i=4; i>=0; i--) + for (int i = 4; i >= 0; i--) { - if (REG_IB & (1<<i) && !(m_irq_status & (1<<i))) + if (BIT(REG_IB, i) && !BIT(m_irq_status, i)) { - m_irq_status |= (1<<i); - push(REG_SS, (m_pc>>8)&0xff); - push(REG_SS, (m_pc>>0)&0xff); + m_irq_status |= (1 << i); + push(REG_SS, (uint8_t)(m_pc >> 8)); + push(REG_SS, (uint8_t)m_pc); set_pc(irq_vector[i]); m_icount -= 12; @@ -348,15 +338,13 @@ void hd61700_cpu_device::execute_run() } else { - uint8_t op; - check_irqs(); // instruction fetch - op = read_op(); + uint8_t op = read_op(); // execute the instruction - switch ( op ) + switch (op) { case 0x00: //adc case 0x01: //sbc @@ -365,12 +353,12 @@ void hd61700_cpu_device::execute_run() { uint8_t arg = read_op(); uint8_t src = READ_REG(get_sir_im8(arg)); - uint16_t res = READ_REG(arg) + ((op&1) ? -src : +src); + uint16_t res = READ_REG(arg) + ((op & 1) ? -src : +src); - COND_WRITE_REG(op, arg, res & 0xff); + COND_WRITE_REG(op, arg, (uint8_t)res); CLEAR_FLAGS; - CHECK_FLAG_Z(res & 0xff); + CHECK_FLAG_Z((uint8_t)res); CHECK_FLAGB_UZ_LZ(res); CHECK_FLAG_C(res, 0xff); @@ -405,11 +393,11 @@ void hd61700_cpu_device::execute_run() COND_WRITE_REG(op, arg, res); CLEAR_FLAGS; - CHECK_FLAG_Z(res & 0xff); + CHECK_FLAG_Z((uint8_t)res); CHECK_FLAGB_UZ_LZ(res); //na(c) and or(c) always set C flag - if ((op&3) == 1 || (op&3) == 2) + if ((op & 3) == 1 || (op & 3) == 2) SET_FLAG_C; check_optional_jr(arg); @@ -431,7 +419,7 @@ void hd61700_cpu_device::execute_run() WRITE_REG(arg, res & 0xff); CLEAR_FLAGS; - CHECK_FLAG_Z(res & 0xff); + CHECK_FLAG_Z((uint8_t)res); CHECK_FLAGB_UZ_LZ(res); CHECK_FLAG_C(res, 0xff); @@ -446,7 +434,7 @@ void hd61700_cpu_device::execute_run() uint8_t src = get_sir_im8(arg); uint16_t offset = REG_GET16(src); - mem_writebyte(REG_UA>>4, offset, READ_REG(arg)); + mem_writebyte(REG_UA >> 4, offset, READ_REG(arg)); check_optional_jr(arg); m_icount -= 8; @@ -459,7 +447,7 @@ void hd61700_cpu_device::execute_run() uint8_t src = get_sir_im8(arg); uint16_t offset = REG_GET16(src); - WRITE_REG(arg, mem_readbyte(REG_UA>>4, offset)); + WRITE_REG(arg, mem_readbyte(REG_UA >> 4, offset)); check_optional_jr(arg); m_icount -= 8; @@ -469,7 +457,7 @@ void hd61700_cpu_device::execute_run() case 0x12: //stl { uint8_t arg = read_op(); - m_lcd_write_cb((offs_t)0, READ_REG(arg)); + m_lcd_write_cb(0, READ_REG(arg)); check_optional_jr(arg); m_icount -= 11; @@ -498,7 +486,7 @@ void hd61700_cpu_device::execute_run() } else { - m_lcd_ctrl_cb((offs_t)0, READ_REG(arg)); + m_lcd_ctrl_cb(READ_REG(arg)); } check_optional_jr(arg); @@ -528,7 +516,7 @@ void hd61700_cpu_device::execute_run() case 0: //PE case 1: //PD WRITE_REG8(idx, src); - m_port_write_cb((offs_t)0, REG_PD & REG_PE); + m_port_write_cb(REG_PD & REG_PE); break; case 2: //IB REG_IB = (REG_IB & 0x1f) | (src & 0xe0); @@ -537,12 +525,12 @@ void hd61700_cpu_device::execute_run() WRITE_REG8(idx, src); break; case 4: //IA - m_kb_write_cb((offs_t)0, src); + m_kb_write_cb(src); WRITE_REG8(idx, src); break; case 5: //IE - REG_IB &= (((src>>3)&0x1f) | 0xe0); - m_irq_status &= ((src>>3)&0x1f); + REG_IB &= 0xe0 | (src >> 3); + m_irq_status &= src >> 3; WRITE_REG8(idx, src); break; case 6: //TM @@ -559,24 +547,24 @@ void hd61700_cpu_device::execute_run() case 0x18: { uint8_t arg = read_op(); - uint8_t op1 = (arg>>5) & 0x03; + uint8_t op1 = (arg >> 5) & 0x03; switch (op1) { case 0x00: //rod case 0x02: //bid { uint8_t src = READ_REG(arg); - uint8_t res = (src>>1)&0x7f; + uint8_t res = src >> 1; - if (!(op1&0x02)) - res = res | ((m_flags&FLAG_C) !=0 )<<7; + if (!(op1 & 0x02)) + res = res | ((m_flags & FLAG_C) ? 0x80 : 0x00); WRITE_REG(arg, res); CLEAR_FLAGS; - CHECK_FLAG_Z(res & 0xff); + CHECK_FLAG_Z((uint8_t)res); CHECK_FLAGB_UZ_LZ(res); - if (src&0x01) SET_FLAG_C; + if (src & 0x01) SET_FLAG_C; } break; @@ -584,15 +572,15 @@ void hd61700_cpu_device::execute_run() case 0x03: //biu { uint8_t src = READ_REG(arg); - uint8_t res = (src<<1)&0xfe; + uint8_t res = src << 1; - if (!(op1&0x02)) - res = res | ((m_flags&FLAG_C) !=0 )<<0; + if (!(op1 & 0x02)) + res = res | ((m_flags & FLAG_C) ? 0x01 : 0x00); WRITE_REG(arg, res); CLEAR_FLAGS; - CHECK_FLAG_Z(res & 0xff); + CHECK_FLAG_Z((uint8_t)res); CHECK_FLAGB_UZ_LZ(res); if (src&0x80) SET_FLAG_C; } @@ -607,7 +595,7 @@ void hd61700_cpu_device::execute_run() case 0x1a: { uint8_t arg = read_op(); - uint8_t op1 = (arg>>5) & 0x03; + uint8_t op1 = (arg >> 5) & 0x03; switch (op1) { case 0x00: //did @@ -615,15 +603,15 @@ void hd61700_cpu_device::execute_run() { uint8_t res; - if (op1&0x01) - res = (READ_REG(arg)<<4)&0xf0; + if (op1 & 0x01) + res = READ_REG(arg) << 4; else - res = (READ_REG(arg)>>4)&0x0f; + res = READ_REG(arg) >> 4; WRITE_REG(arg, res); CLEAR_FLAGS; - CHECK_FLAG_Z(res & 0xff); + CHECK_FLAG_Z((uint8_t)res); CHECK_FLAGB_UZ_LZ(res); } break; @@ -644,13 +632,13 @@ void hd61700_cpu_device::execute_run() case 0x1b: //cmp/inv { uint8_t arg = read_op(); - uint8_t res = ~(READ_REG(arg)); + uint8_t res = ~READ_REG(arg); if (!(arg & 0x40)) res++; WRITE_REG(arg, res); CLEAR_FLAGS; - CHECK_FLAG_Z(res & 0xff); + CHECK_FLAG_Z((uint8_t)res); CHECK_FLAGB_UZ_LZ(res); if (res || (arg & 0x40)) SET_FLAG_C; @@ -664,14 +652,14 @@ void hd61700_cpu_device::execute_run() uint8_t arg = read_op(); uint8_t src; - if (arg&0x40) + if (arg & 0x40) { src = m_flags; } else { - src = m_port_read_cb(0); - src&=(~REG_PE); + src = m_port_read_cb(); + src &= ~REG_PE; } WRITE_REG(arg, src); @@ -708,7 +696,7 @@ void hd61700_cpu_device::execute_run() uint16_t prev_ir = REG_IX; REG_IX += get_sign_mreg(arg); - mem_writebyte(REG_UA>>4, REG_IX++, READ_REG(arg)); + mem_writebyte(REG_UA >> 4, REG_IX++, READ_REG(arg)); RESTORE_REG(op, REG_IX, prev_ir); @@ -723,7 +711,7 @@ void hd61700_cpu_device::execute_run() uint16_t prev_ir = REG_IZ; REG_IZ += get_sign_mreg(arg); - mem_writebyte(REG_UA>>6, REG_IZ++, READ_REG(arg)); + mem_writebyte(REG_UA >> 6, REG_IZ++, READ_REG(arg)); RESTORE_REG(op, REG_IZ, prev_ir); @@ -736,7 +724,7 @@ void hd61700_cpu_device::execute_run() uint8_t arg = read_op(); REG_IX += get_sign_mreg(arg); - mem_writebyte(REG_UA>>4, REG_IX, READ_REG(arg)); + mem_writebyte(REG_UA >> 4, REG_IX, READ_REG(arg)); m_icount -= 6; } break; @@ -746,26 +734,18 @@ void hd61700_cpu_device::execute_run() uint8_t arg = read_op(); REG_IZ += get_sign_mreg(arg); - mem_writebyte(REG_UA>>6, REG_IZ, READ_REG(arg)); + mem_writebyte(REG_UA >> 6, REG_IZ, READ_REG(arg)); m_icount -= 6; } break; case 0x26: //phs - { - uint8_t arg = read_op(); - - push(REG_SS, READ_REG(arg)); - m_icount -= 9; - } + push(REG_SS, READ_REG(read_op())); + m_icount -= 9; break; case 0x27: //phu - { - uint8_t arg = read_op(); - - push(REG_US, READ_REG(arg)); - m_icount -= 9; - } + push(REG_US, READ_REG(read_op())); + m_icount -= 9; break; case 0x28: //ld @@ -775,7 +755,7 @@ void hd61700_cpu_device::execute_run() uint16_t prev_ir = REG_IX; REG_IX += get_sign_mreg(arg); - WRITE_REG(arg, mem_readbyte(REG_UA>>4, REG_IX++)); + WRITE_REG(arg, mem_readbyte(REG_UA >> 4, REG_IX++)); RESTORE_REG(op, REG_IX, prev_ir); @@ -790,7 +770,7 @@ void hd61700_cpu_device::execute_run() uint16_t prev_ir = REG_IZ; REG_IZ += get_sign_mreg(arg); - WRITE_REG(arg, mem_readbyte(REG_UA>>6, REG_IZ++)); + WRITE_REG(arg, mem_readbyte(REG_UA >> 6, REG_IZ++)); RESTORE_REG(op, REG_IZ, prev_ir); @@ -803,7 +783,7 @@ void hd61700_cpu_device::execute_run() uint8_t arg = read_op(); REG_IX += get_sign_mreg(arg); - WRITE_REG(arg, mem_readbyte(REG_UA>>4, REG_IX)); + WRITE_REG(arg, mem_readbyte(REG_UA >> 4, REG_IX)); m_icount -= 6; } @@ -814,7 +794,7 @@ void hd61700_cpu_device::execute_run() uint8_t arg = read_op(); REG_IZ += get_sign_mreg(arg); - WRITE_REG(arg, mem_readbyte(REG_UA>>6, REG_IZ)); + WRITE_REG(arg, mem_readbyte(REG_UA >> 6, REG_IZ)); m_icount -= 6; } @@ -824,7 +804,6 @@ void hd61700_cpu_device::execute_run() { uint8_t arg = read_op(); WRITE_REG(arg, pop(REG_SS)); - m_icount -= 11; } break; @@ -832,7 +811,6 @@ void hd61700_cpu_device::execute_run() { uint8_t arg = read_op(); WRITE_REG(arg, pop(REG_US)); - m_icount -= 11; } break; @@ -851,7 +829,7 @@ void hd61700_cpu_device::execute_run() uint8_t msb = read_op(); if (check_cond(op)) - set_pc((msb<<8) | lsb); + set_pc((msb << 8) | lsb); m_icount -= 3; } break; @@ -863,15 +841,15 @@ void hd61700_cpu_device::execute_run() { uint8_t arg = read_op(); uint16_t offset = REG_IX + get_sign_mreg(arg); - uint8_t src = mem_readbyte(REG_UA>>4, offset); + uint8_t src = mem_readbyte(REG_UA >> 4, offset); uint16_t res = src + ((op & 2) ? -READ_REG(arg) : +READ_REG(arg)) ; - if ((op & 4)) - mem_writebyte(REG_UA>>4, offset, res & 0xff); + if (op & 4) + mem_writebyte(REG_UA >> 4, offset, res & 0xff); CLEAR_FLAGS; - CHECK_FLAG_Z(res & 0xff); + CHECK_FLAG_Z((uint8_t)res); CHECK_FLAGB_UZ_LZ(res); CHECK_FLAG_C(res, 0xff); @@ -886,15 +864,15 @@ void hd61700_cpu_device::execute_run() { uint8_t arg = read_op(); uint16_t offset = REG_IZ + get_sign_mreg(arg); - uint8_t src = mem_readbyte(REG_UA>>6, offset); + uint8_t src = mem_readbyte(REG_UA >> 6, offset); uint16_t res = src + ((op & 2) ? -READ_REG(arg) : +READ_REG(arg)) ; - if ((op & 4)) - mem_writebyte(REG_UA>>6, offset, res & 0xff); + if (op & 4) + mem_writebyte(REG_UA >> 6, offset, res & 0xff); CLEAR_FLAGS; - CHECK_FLAG_Z(res & 0xff); + CHECK_FLAG_Z((uint8_t)res); CHECK_FLAGB_UZ_LZ(res); CHECK_FLAG_C(res, 0xff); @@ -909,12 +887,12 @@ void hd61700_cpu_device::execute_run() { uint8_t arg = read_op(); uint8_t src = read_op(); - uint16_t res = READ_REG(arg) + ((op&1) ? -src : +src); + uint16_t res = READ_REG(arg) + ((op & 1) ? -src : +src); - COND_WRITE_REG(op, arg, res & 0xff); + COND_WRITE_REG(op, arg, (uint8_t)res); CLEAR_FLAGS; - CHECK_FLAG_Z(res & 0xff); + CHECK_FLAG_Z((uint8_t)res); CHECK_FLAGB_UZ_LZ(res); CHECK_FLAG_C(res, 0xff); @@ -926,7 +904,7 @@ void hd61700_cpu_device::execute_run() case 0x42: //ld { uint8_t arg = read_op(); - uint8_t src = read_op() ; + uint8_t src = read_op(); WRITE_REG(arg, src); @@ -952,11 +930,11 @@ void hd61700_cpu_device::execute_run() COND_WRITE_REG(op, arg, res); CLEAR_FLAGS; - CHECK_FLAG_Z(res & 0xff); + CHECK_FLAG_Z((uint8_t)res); CHECK_FLAGB_UZ_LZ(res); //na(c) and or(c) always set C flag - if ((op&3) == 1 || (op&3) == 2) + if ((op & 3) == 1 || (op & 3) == 2) SET_FLAG_C; check_optional_jr(arg); @@ -976,10 +954,10 @@ void hd61700_cpu_device::execute_run() else res = make_bcd_add(READ_REG(arg), src); - WRITE_REG(arg, res & 0xff); + WRITE_REG(arg, (uint8_t)res); CLEAR_FLAGS; - CHECK_FLAG_Z(res & 0xff); + CHECK_FLAG_Z((uint8_t)res); CHECK_FLAGB_UZ_LZ(res); CHECK_FLAG_C(res, 0xff); @@ -994,7 +972,7 @@ void hd61700_cpu_device::execute_run() uint8_t src = read_op(); uint16_t offset = REG_GET16(READ_SREG(arg)); - mem_writebyte(REG_UA>>4, offset, src); + mem_writebyte(REG_UA >> 4, offset, src); m_icount -= 8; } break; @@ -1012,7 +990,7 @@ void hd61700_cpu_device::execute_run() case 0x52: //stl { uint8_t arg = read_op(); - m_lcd_write_cb((offs_t)0, arg); + m_lcd_write_cb(0, arg); m_icount -= 12; } @@ -1029,7 +1007,7 @@ void hd61700_cpu_device::execute_run() } else { - m_lcd_ctrl_cb((offs_t)0, src); + m_lcd_ctrl_cb(src); } m_icount -= 3; @@ -1057,7 +1035,7 @@ void hd61700_cpu_device::execute_run() case 0: //PE case 1: //PD WRITE_REG8(idx, src); - m_port_write_cb((offs_t)0, REG_PD & REG_PE); + m_port_write_cb(REG_PD & REG_PE); break; case 2: //IB REG_IB = (REG_IB & 0x1f) | (src & 0xe0); @@ -1066,12 +1044,12 @@ void hd61700_cpu_device::execute_run() WRITE_REG8(idx, src); break; case 4: //IA - m_kb_write_cb((offs_t)0, src); + m_kb_write_cb(src); WRITE_REG8(idx, src); break; case 5: //IE - REG_IB &= (((src>>3)&0x1f) | 0xe0); - m_irq_status &= ((src>>3)&0x1f); + REG_IB &= 0xe0 | (src >> 3); + m_irq_status &= src >> 3; WRITE_REG8(idx, src); break; case 6: //TM @@ -1088,25 +1066,24 @@ void hd61700_cpu_device::execute_run() case 0x59: //bdns { uint8_t arg = read_op(); - uint8_t tmp; uint16_t res; for(;;) { - tmp = mem_readbyte(REG_UA>>4, REG_IX); - mem_writebyte(REG_UA>>6, REG_IZ, tmp); + uint8_t tmp = mem_readbyte(REG_UA >> 4, REG_IX); + mem_writebyte(REG_UA >> 6, REG_IZ, tmp); res = tmp - arg; if (REG_IX == REG_IY || !res) break; - REG_IX += ((op&1) ? -1 : +1); - REG_IZ += ((op&1) ? -1 : +1); + REG_IX += ((op & 1) ? -1 : +1); + REG_IZ += ((op & 1) ? -1 : +1); m_icount -= 6; } CLEAR_FLAGS; - CHECK_FLAG_Z(res & 0xff); + CHECK_FLAG_Z((uint8_t)res); CHECK_FLAGB_UZ_LZ(res); CHECK_FLAG_C(res, 0xff); @@ -1122,17 +1099,17 @@ void hd61700_cpu_device::execute_run() for(;;) { - res = mem_readbyte(REG_UA>>4, REG_IX) - arg; + res = mem_readbyte(REG_UA >> 4, REG_IX) - arg; if (REG_IX == REG_IY || !res) break; - REG_IX += ((op&1) ? -1 : +1); + REG_IX += ((op & 1) ? -1 : +1); m_icount -= 6; } CLEAR_FLAGS; - CHECK_FLAG_Z(res & 0xff); + CHECK_FLAG_Z((uint8_t)res); CHECK_FLAGB_UZ_LZ(res); CHECK_FLAG_C(res, 0xff); @@ -1147,7 +1124,7 @@ void hd61700_cpu_device::execute_run() uint16_t prev_ir = REG_IX; REG_IX += get_sign_im8(arg); - mem_writebyte(REG_UA>>4, REG_IX++, READ_REG(arg)); + mem_writebyte(REG_UA >> 4, REG_IX++, READ_REG(arg)); RESTORE_REG(op, REG_IX, prev_ir); @@ -1162,7 +1139,7 @@ void hd61700_cpu_device::execute_run() uint16_t prev_ir = REG_IZ; REG_IZ += get_sign_im8(arg); - mem_writebyte(REG_UA>>6, REG_IZ++, READ_REG(arg)); + mem_writebyte(REG_UA >> 6, REG_IZ++, READ_REG(arg)); RESTORE_REG(op, REG_IZ, prev_ir); m_icount -= 8; @@ -1174,7 +1151,7 @@ void hd61700_cpu_device::execute_run() uint8_t arg = read_op(); REG_IX += get_sign_im8(arg); - mem_writebyte(REG_UA>>4, REG_IX, READ_REG(arg)); + mem_writebyte(REG_UA >> 4, REG_IX, READ_REG(arg)); m_icount -= 6; } break; @@ -1184,7 +1161,7 @@ void hd61700_cpu_device::execute_run() uint8_t arg = read_op(); REG_IZ += get_sign_im8(arg); - mem_writebyte(REG_UA>>6, REG_IZ, READ_REG(arg)); + mem_writebyte(REG_UA >> 6, REG_IZ, READ_REG(arg)); m_icount -= 6; } break; @@ -1196,7 +1173,7 @@ void hd61700_cpu_device::execute_run() uint16_t prev_ir = REG_IX; REG_IX += get_sign_im8(arg); - WRITE_REG(arg, mem_readbyte(REG_UA>>4, REG_IX++)); + WRITE_REG(arg, mem_readbyte(REG_UA >> 4, REG_IX++)); RESTORE_REG(op, REG_IX, prev_ir); m_icount -= 8; @@ -1210,7 +1187,7 @@ void hd61700_cpu_device::execute_run() uint16_t prev_ir = REG_IZ; REG_IZ += get_sign_im8(arg); - WRITE_REG(arg, mem_readbyte(REG_UA>>6, REG_IZ++)); + WRITE_REG(arg, mem_readbyte(REG_UA >> 6, REG_IZ++)); RESTORE_REG(op, REG_IZ, prev_ir); m_icount -= 8; @@ -1222,7 +1199,7 @@ void hd61700_cpu_device::execute_run() uint8_t arg = read_op(); REG_IX += get_sign_im8(arg); - WRITE_REG(arg, mem_readbyte(REG_UA>>4, REG_IX)); + WRITE_REG(arg, mem_readbyte(REG_UA >> 4, REG_IX)); m_icount -= 6; } break; @@ -1232,7 +1209,7 @@ void hd61700_cpu_device::execute_run() uint8_t arg = read_op(); REG_IZ += get_sign_im8(arg); - WRITE_REG(arg, mem_readbyte(REG_UA>>6, REG_IZ)); + WRITE_REG(arg, mem_readbyte(REG_UA >> 6, REG_IZ)); m_icount -= 6; } break; @@ -1253,10 +1230,10 @@ void hd61700_cpu_device::execute_run() if (check_cond(op)) { m_pc--; - push(REG_SS, (m_pc>>8)&0xff); - push(REG_SS, (m_pc>>0)&0xff); + push(REG_SS, (uint8_t)(m_pc >> 8)); + push(REG_SS, (uint8_t)m_pc); - set_pc((msb<<8) | lsb); + set_pc((msb << 8) | lsb); m_icount -= 6; } m_icount -= 3; @@ -1270,15 +1247,15 @@ void hd61700_cpu_device::execute_run() { uint8_t arg = read_op(); uint16_t offset = REG_IX + get_sign_im8(arg); - uint8_t src = mem_readbyte(REG_UA>>4, offset); + uint8_t src = mem_readbyte(REG_UA >> 4, offset); uint16_t res = src + ((op & 2) ? -READ_REG(arg) : +READ_REG(arg)) ; - if ((op & 4)) - mem_writebyte(REG_UA>>4, offset, res & 0xff); + if (op & 4) + mem_writebyte(REG_UA >> 4, offset, (uint8_t)res); CLEAR_FLAGS; - CHECK_FLAG_Z(res & 0xff); + CHECK_FLAG_Z((uint8_t)res); CHECK_FLAGB_UZ_LZ(res); CHECK_FLAG_C(res, 0xff); @@ -1293,15 +1270,15 @@ void hd61700_cpu_device::execute_run() { uint8_t arg = read_op(); uint16_t offset = REG_IZ + get_sign_im8(arg); - uint8_t src = mem_readbyte(REG_UA>>6, offset); + uint8_t src = mem_readbyte(REG_UA >> 6, offset); uint16_t res = src + ((op & 2) ? -READ_REG(arg) : +READ_REG(arg)) ; - if ((op & 4)) - mem_writebyte(REG_UA>>6, offset, res & 0xff); + if (op & 4) + mem_writebyte(REG_UA >> 6, offset, (uint8_t)res); CLEAR_FLAGS; - CHECK_FLAG_Z(res & 0xff); + CHECK_FLAG_Z((uint8_t)res); CHECK_FLAGB_UZ_LZ(res); CHECK_FLAG_C(res, 0xff); @@ -1318,10 +1295,10 @@ void hd61700_cpu_device::execute_run() uint8_t src = get_sir_im8(arg); uint32_t res = REG_GET16(arg) + ((op & 0x01) ? -REG_GET16(src) : +REG_GET16(src)); - if (op & 0x08) REG_PUT16(arg, res&0xffff); + if (op & 0x08) REG_PUT16(arg, (uint16_t)res); CLEAR_FLAGS; - CHECK_FLAG_Z(res & 0xffff); + CHECK_FLAG_Z((uint16_t)res); CHECK_FLAGW_UZ_LZ(res); CHECK_FLAG_C(res, 0xffff); @@ -1336,7 +1313,7 @@ void hd61700_cpu_device::execute_run() uint8_t src = get_sir_im8(arg); COPY_REG(arg, src); - COPY_REG(arg+1, src+1); + COPY_REG(arg + 1, src + 1); check_optional_jr(arg); m_icount -= 8; @@ -1358,7 +1335,7 @@ void hd61700_cpu_device::execute_run() uint8_t res0 = make_logic(op, READ_REG(arg), READ_REG(src)); COND_WRITE_REG(op, arg, res0); - uint8_t res1 = make_logic(op, READ_REG(arg+1), READ_REG(src+1)); + uint8_t res1 = make_logic(op, READ_REG(arg + 1), READ_REG(src + 1)); COND_WRITE_REG(op, arg+1, res1); CLEAR_FLAGS; @@ -1366,7 +1343,7 @@ void hd61700_cpu_device::execute_run() CHECK_FLAGB_UZ_LZ(res1); //na(c) and or(c) always set C flag - if ((op&3) == 1 || (op&3) == 2) + if ((op & 3) == 1 || (op & 3) == 2) SET_FLAG_C; check_optional_jr(arg); @@ -1386,16 +1363,16 @@ void hd61700_cpu_device::execute_run() else res0 = make_bcd_add(READ_REG(arg), READ_REG(src)); - WRITE_REG(arg, res0 & 0xff); + WRITE_REG(arg, (uint8_t)res0); - res1 = (res0>0xff) ? 1 : 0 ; + res1 = (res0 > 0xff) ? 1 : 0; if (op & 0x01) - res1 = make_bcd_sub(READ_REG(arg+1), READ_REG(src+1) + res1); + res1 = make_bcd_sub(READ_REG(arg + 1), READ_REG(src + 1) + res1); else - res1 = make_bcd_add(READ_REG(arg+1), READ_REG(src+1) + res1); + res1 = make_bcd_add(READ_REG(arg + 1), READ_REG(src + 1) + res1); - WRITE_REG(arg+1, res1 & 0xff); + WRITE_REG(arg + 1, (uint8_t)res1); CLEAR_FLAGS; CHECK_FLAG_Z(res0 || res1); @@ -1413,8 +1390,8 @@ void hd61700_cpu_device::execute_run() uint8_t src = get_sir_im8(arg); uint16_t offset = REG_GET16(src); - mem_writebyte(REG_UA>>4, offset+0, READ_REG(arg+0)); - mem_writebyte(REG_UA>>4, offset+1, READ_REG(arg+1)); + mem_writebyte(REG_UA >> 4, offset, READ_REG(arg)); + mem_writebyte(REG_UA >> 4, offset + 1, READ_REG(arg + 1)); check_optional_jr(arg); m_icount -= 11; @@ -1427,8 +1404,8 @@ void hd61700_cpu_device::execute_run() uint8_t src = get_sir_im8(arg); uint16_t offset = REG_GET16(src); - WRITE_REG(arg+0, mem_readbyte(REG_UA>>4, offset+0)); - WRITE_REG(arg+1, mem_readbyte(REG_UA>>4, offset+1)); + WRITE_REG(arg, mem_readbyte(REG_UA >> 4, offset)); + WRITE_REG(arg + 1, mem_readbyte(REG_UA >> 4, offset + 1)); check_optional_jr(arg); m_icount -= 11; @@ -1439,8 +1416,8 @@ void hd61700_cpu_device::execute_run() { uint8_t arg = read_op(); - m_lcd_write_cb((offs_t)0, READ_REG(arg)); - m_lcd_write_cb((offs_t)0, READ_REG(arg+1)); + m_lcd_write_cb(0, READ_REG(arg)); + m_lcd_write_cb(0, READ_REG(arg + 1)); check_optional_jr(arg); m_icount -= 19; @@ -1450,13 +1427,12 @@ void hd61700_cpu_device::execute_run() case 0x93: //ldcw { uint8_t arg = read_op(); - uint8_t reg0, reg1; - reg0 = m_lcd_read_cb(0); - reg1 = m_lcd_read_cb(0); + uint8_t reg0 = m_lcd_read_cb(0); + uint8_t reg1 = m_lcd_read_cb(0); - WRITE_REG(arg+0, reg0); - WRITE_REG(arg+1, reg1); + WRITE_REG(arg, reg0); + WRITE_REG(arg + 1, reg1); check_optional_jr(arg); m_icount -= 19; @@ -1480,22 +1456,22 @@ void hd61700_cpu_device::execute_run() case 0x98: //rodw { uint8_t arg = read_op(); - uint8_t op1 = (arg>>5) & 0x03; + uint8_t op1 = (arg >> 5) & 0x03; switch (op1) { case 0x00: //rodw case 0x02: //bidw { - uint16_t src = REG_GET16(arg-1); - uint16_t res = (src>>1)&0x7fff; + uint16_t src = REG_GET16(arg - 1); + uint16_t res = src >> 1; - if (!(op1&0x02)) - res = res | ((m_flags&FLAG_C) !=0 )<<15; + if (!(op1 & 0x02)) + res = res | ((m_flags & FLAG_C) ? 0x8000 : 0x0000); - REG_PUT16(arg-1, res); + REG_PUT16(arg - 1, res); CLEAR_FLAGS; - CHECK_FLAG_Z(res & 0xffff); + CHECK_FLAG_Z((uint16_t)res); CHECK_FLAGB_UZ_LZ(res); if (src&0x01) SET_FLAG_C; } @@ -1505,15 +1481,15 @@ void hd61700_cpu_device::execute_run() case 0x03: //biuw { uint16_t src = REG_GET16(arg); - uint16_t res = (src<<1)&0xfffe; + uint16_t res = src << 1; - if (!(op1&0x02)) - res = res | ((m_flags&FLAG_C) !=0 )<<0; + if (!(op1 & 0x02)) + res = res | ((m_flags & FLAG_C) ? 0x0001 : 0x0000); REG_PUT16(arg, res); CLEAR_FLAGS; - CHECK_FLAG_Z(res & 0xffff); + CHECK_FLAG_Z((uint16_t)res); CHECK_FLAGW_UZ_LZ(res); if (src&0x8000) SET_FLAG_C; } @@ -1528,27 +1504,27 @@ void hd61700_cpu_device::execute_run() case 0x9a: { uint8_t arg = read_op(); - uint8_t op1 = (arg>>5) & 0x03; + uint8_t op1 = (arg >> 5) & 0x03; switch (op1) { case 0x00: //didw { - uint16_t src = (REG_GET16(arg-1)>>4)&0x0fff; - REG_PUT16(arg-1, src); + uint16_t src = REG_GET16(arg - 1) >> 4; + REG_PUT16(arg - 1, src); CLEAR_FLAGS; - CHECK_FLAG_Z(src & 0xffff); + CHECK_FLAG_Z((uint16_t)src); CHECK_FLAGB_UZ_LZ(src); } break; case 0x01: //diuw { - uint16_t src = (REG_GET16(arg)<<4)&0xfff0; + uint16_t src = REG_GET16(arg) << 4; REG_PUT16(arg, src); CLEAR_FLAGS; - CHECK_FLAG_Z(src & 0xffff); + CHECK_FLAG_Z((uint16_t)src); CHECK_FLAGW_UZ_LZ(src); } break; @@ -1558,10 +1534,10 @@ void hd61700_cpu_device::execute_run() uint8_t src = READ_REG(arg); WRITE_REG(arg, 0); - WRITE_REG(arg-1, src); + WRITE_REG(arg - 1, src); CLEAR_FLAGS; - CHECK_FLAG_Z(src & 0xff); + CHECK_FLAG_Z((uint8_t)src); CHECK_FLAGB_UZ_LZ(src); } break; @@ -1571,10 +1547,10 @@ void hd61700_cpu_device::execute_run() uint8_t src = READ_REG(arg); WRITE_REG(arg, 0); - WRITE_REG(arg+1, src); + WRITE_REG(arg + 1, src); CLEAR_FLAGS; - CHECK_FLAG_Z(src & 0xff); + CHECK_FLAG_Z((uint8_t)src); CHECK_FLAGB_UZ_LZ(src); } break; @@ -1588,13 +1564,13 @@ void hd61700_cpu_device::execute_run() case 0x9b: //cmpw/invw { uint8_t arg = read_op(); - uint16_t res = ~(REG_GET16(arg)); + uint16_t res = ~REG_GET16(arg); if (!(arg & 0x40)) res++; REG_PUT16(arg, res); CLEAR_FLAGS; - CHECK_FLAG_Z(res & 0xffff); + CHECK_FLAG_Z((uint16_t)res); CHECK_FLAGW_UZ_LZ(res); if (res || (arg & 0x40)) SET_FLAG_C; @@ -1615,16 +1591,12 @@ void hd61700_cpu_device::execute_run() } else { - reg0 = m_port_read_cb(0); - reg1 = m_port_read_cb(0); - - reg0&=(~REG_PE); - reg1&=(~REG_PE); - + reg0 = m_port_read_cb() & ~REG_PE; + reg1 = m_port_read_cb() & ~REG_PE; } - WRITE_REG(arg+0, reg0); - WRITE_REG(arg+1, reg1); + WRITE_REG(arg, reg0); + WRITE_REG(arg + 1, reg1); check_optional_jr(arg); m_icount -= 8; @@ -1662,8 +1634,8 @@ void hd61700_cpu_device::execute_run() REG_IX += ((arg & 0x80) ? -ir_inc : +ir_inc); - mem_writebyte(REG_UA>>4, REG_IX++, READ_REG(arg+0)); - mem_writebyte(REG_UA>>4, REG_IX++, READ_REG(arg+1)); + mem_writebyte(REG_UA >> 4, REG_IX++, READ_REG(arg)); + mem_writebyte(REG_UA >> 4, REG_IX++, READ_REG(arg + 1)); RESTORE_REG(op, REG_IX, prev_ir); m_icount -= 11; @@ -1679,8 +1651,8 @@ void hd61700_cpu_device::execute_run() REG_IZ += ((arg & 0x80) ? -ir_inc : +ir_inc); - mem_writebyte(REG_UA>>6, REG_IZ++, READ_REG(arg+0)); - mem_writebyte(REG_UA>>6, REG_IZ++, READ_REG(arg+1)); + mem_writebyte(REG_UA >> 6, REG_IZ++, READ_REG(arg)); + mem_writebyte(REG_UA >> 6, REG_IZ++, READ_REG(arg + 1)); RESTORE_REG(op, REG_IZ, prev_ir); m_icount -= 11; @@ -1694,8 +1666,8 @@ void hd61700_cpu_device::execute_run() REG_IX += ((arg & 0x80) ? -ir_inc : +ir_inc); - mem_writebyte(REG_UA>>4, REG_IX--, READ_REG(arg-0)); - mem_writebyte(REG_UA>>4, REG_IX, READ_REG(arg-1)); + mem_writebyte(REG_UA >> 4, REG_IX--, READ_REG(arg)); + mem_writebyte(REG_UA >> 4, REG_IX, READ_REG(arg - 1)); m_icount -= 9; } @@ -1707,8 +1679,8 @@ void hd61700_cpu_device::execute_run() REG_IZ += ((arg & 0x80) ? -ir_inc : +ir_inc); - mem_writebyte(REG_UA>>6, REG_IZ--, READ_REG(arg-0)); - mem_writebyte(REG_UA>>6, REG_IZ, READ_REG(arg-1)); + mem_writebyte(REG_UA >> 6, REG_IZ--, READ_REG(arg)); + mem_writebyte(REG_UA >> 6, REG_IZ, READ_REG(arg - 1)); m_icount -= 9; } @@ -1718,7 +1690,7 @@ void hd61700_cpu_device::execute_run() { uint8_t arg = read_op(); push(REG_SS, READ_REG(arg)); - push(REG_SS, READ_REG(arg-1)); + push(REG_SS, READ_REG(arg - 1)); m_icount -= 12; } @@ -1727,7 +1699,7 @@ void hd61700_cpu_device::execute_run() { uint8_t arg = read_op(); push(REG_US, READ_REG(arg)); - push(REG_US, READ_REG(arg-1)); + push(REG_US, READ_REG(arg - 1)); m_icount -= 12; } @@ -1742,8 +1714,8 @@ void hd61700_cpu_device::execute_run() REG_IX += ((arg & 0x80) ? -ir_inc : +ir_inc); - WRITE_REG(arg+0, mem_readbyte(REG_UA>>4, REG_IX++)); - WRITE_REG(arg+1, mem_readbyte(REG_UA>>4, REG_IX++)); + WRITE_REG(arg, mem_readbyte(REG_UA >> 4, REG_IX++)); + WRITE_REG(arg + 1, mem_readbyte(REG_UA >> 4, REG_IX++)); RESTORE_REG(op, REG_IX, prev_ir); @@ -1760,8 +1732,8 @@ void hd61700_cpu_device::execute_run() REG_IZ += ((arg & 0x80) ? -ir_inc : +ir_inc); - WRITE_REG(arg+0, mem_readbyte(REG_UA>>6, REG_IZ++)); - WRITE_REG(arg+1, mem_readbyte(REG_UA>>6, REG_IZ++)); + WRITE_REG(arg, mem_readbyte(REG_UA >> 6, REG_IZ++)); + WRITE_REG(arg + 1, mem_readbyte(REG_UA >> 6, REG_IZ++)); RESTORE_REG(op, REG_IZ, prev_ir); @@ -1776,8 +1748,8 @@ void hd61700_cpu_device::execute_run() REG_IX += ((arg & 0x80) ? -ir_inc : +ir_inc); - WRITE_REG(arg-0, mem_readbyte(REG_UA>>4, REG_IX--)); - WRITE_REG(arg-1, mem_readbyte(REG_UA>>4, REG_IX)); + WRITE_REG(arg, mem_readbyte(REG_UA >> 4, REG_IX--)); + WRITE_REG(arg - 1, mem_readbyte(REG_UA >> 4, REG_IX)); m_icount -= 9; } @@ -1790,8 +1762,8 @@ void hd61700_cpu_device::execute_run() REG_IZ += ((arg & 0x80) ? -ir_inc : +ir_inc); - WRITE_REG(arg-0, mem_readbyte(REG_UA>>6, REG_IZ--)); - WRITE_REG(arg-1, mem_readbyte(REG_UA>>6, REG_IZ)); + WRITE_REG(arg, mem_readbyte(REG_UA >> 6, REG_IZ--)); + WRITE_REG(arg - 1, mem_readbyte(REG_UA >> 6, REG_IZ)); m_icount -= 9; } @@ -1802,8 +1774,8 @@ void hd61700_cpu_device::execute_run() { uint8_t arg = read_op(); - WRITE_REG(arg, pop((op&1) ? REG_US : REG_SS)); - WRITE_REG(arg+1, pop((op&1) ? REG_US : REG_SS)); + WRITE_REG(arg, pop((op & 1) ? REG_US : REG_SS)); + WRITE_REG(arg + 1, pop((op & 1) ? REG_US : REG_SS)); m_icount -= 14; } @@ -1819,7 +1791,7 @@ void hd61700_cpu_device::execute_run() case 0xb7: //unconditional jr { uint8_t arg = read_op(); - uint32_t new_pc = m_pc-1 + get_im_7(arg); + uint32_t new_pc = (m_pc - 1) + get_im_7(arg); if (check_cond(op)) set_pc(new_pc); @@ -1835,13 +1807,13 @@ void hd61700_cpu_device::execute_run() uint16_t offset = REG_IX + ((arg & 0x80) ? -ir_inc : +ir_inc); - uint16_t src0 = mem_readbyte(REG_UA>>4, offset) + READ_REG(arg); - uint16_t src1 = mem_readbyte(REG_UA>>4, offset+1) + READ_REG(arg+1) + ((src0>0xff) ? 1 : 0); + uint16_t src0 = mem_readbyte(REG_UA >> 4, offset) + READ_REG(arg); + uint16_t src1 = mem_readbyte(REG_UA >> 4, offset + 1) + READ_REG(arg + 1) + ((src0 > 0xff) ? 1 : 0); if (op&0x04) { - mem_writebyte(REG_UA>>4, offset+0, src0 & 0xff); - mem_writebyte(REG_UA>>4, offset+1, src1 & 0xff); + mem_writebyte(REG_UA >> 4, offset, (uint8_t)src0); + mem_writebyte(REG_UA >> 4, offset + 1, (uint8_t)src1); } CLEAR_FLAGS; @@ -1861,13 +1833,13 @@ void hd61700_cpu_device::execute_run() uint16_t offset = REG_IX + ((arg & 0x80) ? -ir_inc : +ir_inc); - uint16_t src0 = mem_readbyte(REG_UA>>4, offset) - READ_REG(arg); - uint16_t src1 = mem_readbyte(REG_UA>>4, offset+1) - READ_REG(arg+1) - ((src0>0xff) ? 1 : 0); + uint16_t src0 = mem_readbyte(REG_UA >> 4, offset) - READ_REG(arg); + uint16_t src1 = mem_readbyte(REG_UA >> 4, offset+1) - READ_REG(arg + 1) - ((src0 > 0xff) ? 1 : 0); if (op&0x04) { - mem_writebyte(REG_UA>>4, offset+0, src0 & 0xff); - mem_writebyte(REG_UA>>4, offset+1, src1 & 0xff); + mem_writebyte(REG_UA >> 4, offset, (uint8_t)src0); + mem_writebyte(REG_UA >> 4, offset + 1, (uint8_t)src1); } CLEAR_FLAGS; @@ -1887,13 +1859,13 @@ void hd61700_cpu_device::execute_run() uint16_t offset = REG_IZ + ((arg & 0x80) ? -ir_inc : +ir_inc); - uint16_t src0 = mem_readbyte(REG_UA>>6, offset) + READ_REG(arg); - uint16_t src1 = mem_readbyte(REG_UA>>6, offset+1) + READ_REG(arg+1) + ((src0>0xff) ? 1 : 0); + uint16_t src0 = mem_readbyte(REG_UA >> 6, offset) + READ_REG(arg); + uint16_t src1 = mem_readbyte(REG_UA >> 6, offset + 1) + READ_REG(arg + 1) + ((src0 > 0xff) ? 1 : 0); - if (op&0x04) + if (op & 0x04) { - mem_writebyte(REG_UA>>6, offset+0, src0 & 0xff); - mem_writebyte(REG_UA>>6, offset+1, src1 & 0xff); + mem_writebyte(REG_UA >> 6, offset, (uint8_t)src0); + mem_writebyte(REG_UA >> 6, offset + 1, (uint8_t)src1); } CLEAR_FLAGS; @@ -1913,13 +1885,13 @@ void hd61700_cpu_device::execute_run() uint16_t offset = REG_IZ + ((arg & 0x80) ? -ir_inc : +ir_inc); - uint16_t src0 = mem_readbyte(REG_UA>>6, offset) - READ_REG(arg); - uint16_t src1 = mem_readbyte(REG_UA>>6, offset+1) - READ_REG(arg+1) - ((src0>0xff) ? 1 : 0); + uint16_t src0 = mem_readbyte(REG_UA >> 6, offset) - READ_REG(arg); + uint16_t src1 = mem_readbyte(REG_UA >> 6, offset + 1) - READ_REG(arg + 1) - ((src0 > 0xff) ? 1 : 0); if (op&0x04) { - mem_writebyte(REG_UA>>6, offset+0, src0 & 0xff); - mem_writebyte(REG_UA>>6, offset+1, src1 & 0xff); + mem_writebyte(REG_UA >> 6, offset, (uint8_t)src0); + mem_writebyte(REG_UA >> 6, offset + 1, (uint8_t)src1); } CLEAR_FLAGS; @@ -1940,11 +1912,11 @@ void hd61700_cpu_device::execute_run() uint8_t arg1 = read_op(); uint8_t dst = arg; uint8_t src = get_sir_im8(arg, arg1); - uint8_t c, f; uint16_t res = 0; - c = f = 0; - for (int n=GET_IM3(arg1); n>0; n--) + uint8_t c = 0; + uint8_t f = 0; + for (int n = GET_IM3(arg1); n > 0; n--) { if (op & 0x01) res = make_bcd_sub(READ_REG(dst), READ_REG(src) + c); @@ -1953,10 +1925,11 @@ void hd61700_cpu_device::execute_run() c = (res > 0xff) ? 1 : 0; - COND_WRITE_REG(op, dst, res&0xff); + COND_WRITE_REG(op, dst, (uint8_t)res); - f |= (res&0xff); - dst++; src++; + f |= (uint8_t)res; + dst++; + src++; m_icount -= 5; } @@ -1978,7 +1951,7 @@ void hd61700_cpu_device::execute_run() uint8_t dst = arg; uint8_t src = get_sir_im8(arg, arg1); - for (int n=GET_IM3(arg1); n>0; n--) + for (int n = GET_IM3(arg1); n > 0; n--) { COPY_REG(dst++, src++); m_icount -= 5; @@ -2002,9 +1975,10 @@ void hd61700_cpu_device::execute_run() uint8_t arg1 = read_op(); uint8_t dst = arg; uint8_t src = get_sir_im8(arg, arg1); - uint8_t res = 0, f = 0; + uint8_t res = 0; + uint8_t f = 0; - for (int n=GET_IM3(arg1); n>0; n--) + for (int n = GET_IM3(arg1); n > 0; n--) { res = make_logic(op, READ_REG(dst), READ_REG(src)); @@ -2012,7 +1986,8 @@ void hd61700_cpu_device::execute_run() f |= res; - dst++; src++; + dst++; + src++; m_icount -= 3; } @@ -2022,7 +1997,7 @@ void hd61700_cpu_device::execute_run() CHECK_FLAGB_UZ_LZ(res); //na(c) and or(c) always set C flag - if ((op&3) == 1 || (op&3) == 2) + if ((op & 3) == 1 || (op & 3) == 2) SET_FLAG_C; check_optional_jr(arg); @@ -2036,11 +2011,10 @@ void hd61700_cpu_device::execute_run() uint8_t arg1 = read_op(); uint8_t dst = arg; uint16_t res = 0; - uint8_t src, f; - src = arg1 & 0x1f; - f = 0; + uint8_t src = arg1 & 0x1f; + uint8_t f = 0; - for (int n=GET_IM3(arg1); n>0; n--) + for (int n = GET_IM3(arg1); n > 0; n--) { if (op & 0x01) res = make_bcd_sub(READ_REG(dst), src); @@ -2049,9 +2023,9 @@ void hd61700_cpu_device::execute_run() src = (res > 0xff) ? 1 : 0; - COND_WRITE_REG(op, dst, res&0xff); + COND_WRITE_REG(op, dst, (uint8_t)res); - f |= (res&0xff); + f |= (uint8_t)res; dst++; m_icount -= 5; @@ -2072,8 +2046,8 @@ void hd61700_cpu_device::execute_run() uint8_t arg = read_op(); uint16_t offset = REG_GET16(READ_SREG(arg)); - mem_writebyte(REG_UA>>4, offset+0, read_op()); - mem_writebyte(REG_UA>>4, offset+1, read_op()); + mem_writebyte(REG_UA >> 4, offset, read_op()); + mem_writebyte(REG_UA >> 4, offset + 1, read_op()); m_icount -= 11; } @@ -2085,8 +2059,8 @@ void hd61700_cpu_device::execute_run() uint8_t reg0 = read_op(); uint8_t reg1 = read_op(); - WRITE_REG(arg+0, reg0); - WRITE_REG(arg+1, reg1); + WRITE_REG(arg, reg0); + WRITE_REG(arg + 1, reg1); m_icount -= 11; } break; @@ -2096,9 +2070,9 @@ void hd61700_cpu_device::execute_run() uint8_t arg = read_op(); uint8_t arg1 = read_op(); - for (int n=GET_IM3(arg1); n>0; n--) + for (int n = GET_IM3(arg1); n > 0; n--) { - m_lcd_write_cb((offs_t)0, READ_REG(arg)); + m_lcd_write_cb(0, READ_REG(arg)); arg++; m_icount -= 8; @@ -2112,11 +2086,10 @@ void hd61700_cpu_device::execute_run() { uint8_t arg = read_op(); uint8_t arg1 = read_op(); - uint8_t src; - for (int n=GET_IM3(arg1); n>0; n--) + for (int n = GET_IM3(arg1); n > 0; n--) { - src = m_lcd_read_cb(0); + uint8_t src = m_lcd_read_cb(0); WRITE_REG(arg, src++); @@ -2136,7 +2109,7 @@ void hd61700_cpu_device::execute_run() uint8_t idx = GET_REG_IDX(op, arg); if (idx < 5) - m_reg16bit[idx] = (msb<<8) | lsb; + m_reg16bit[idx] = (msb << 8) | lsb; m_icount -= 8; } @@ -2144,41 +2117,39 @@ void hd61700_cpu_device::execute_run() case 0xd8: //bup case 0xd9: //bdn + for(;;) { - uint8_t src; - for(;;) - { - src = mem_readbyte(REG_UA>>4, REG_IX); - mem_writebyte(REG_UA>>6, REG_IZ, src); + uint8_t src = mem_readbyte(REG_UA >> 4, REG_IX); + mem_writebyte(REG_UA >> 6, REG_IZ, src); - if (REG_IX == REG_IY) - break; + if (REG_IX == REG_IY) + break; - REG_IX += ((op&1) ? -1 : +1); - REG_IZ += ((op&1) ? -1 : +1); - m_icount -= 6; - } - - m_icount -= 9; + REG_IX += ((op & 1) ? -1 : +1); + REG_IZ += ((op & 1) ? -1 : +1); + m_icount -= 6; } + + m_icount -= 9; break; case 0xda: { uint8_t arg = read_op(); - uint8_t op1 = (arg>>5) & 0x03; + uint8_t op1 = (arg >> 5) & 0x03; switch (op1) { case 0x00: //didm { uint8_t arg1 = read_op(); - uint8_t r1 = 0, r2 = 0; + uint8_t r1 = 0; + uint8_t r2 = 0; - for (int n=GET_IM3(arg1); n>0; n--) + for (int n = GET_IM3(arg1); n > 0; n--) { r2 = r1; r1 = READ_REG(arg); - r2 = ((r1>>4)&0x0f) | ((r2<<4)&0xf0); + r2 = (r1 >> 4) | (r2 << 4); WRITE_REG(arg--, r2); m_icount -= 5; } @@ -2192,13 +2163,14 @@ void hd61700_cpu_device::execute_run() case 0x01: //dium { uint8_t arg1 = read_op(); - uint8_t r1 = 0, r2 = 0; + uint8_t r1 = 0; + uint8_t r2 = 0; - for (int n=GET_IM3(arg1); n>0; n--) + for (int n = GET_IM3(arg1); n > 0; n--) { r2 = r1; r1 = READ_REG(arg); - r2 = ((r1<<4)&0xf0) | ((r2>>4)&0x0f); + r2 = (r1 << 4) | (r2 >> 4); WRITE_REG(arg++, r2); m_icount -= 5; } @@ -2212,9 +2184,11 @@ void hd61700_cpu_device::execute_run() case 0x02: //bydm { uint8_t arg1 = read_op(); - uint8_t r1 = 0, r2 = 0, f = 0; + uint8_t r1 = 0; + uint8_t r2 = 0; + uint8_t f = 0; - for (int n=GET_IM3(arg1); n>0; n--) + for (int n = GET_IM3(arg1); n > 0; n--) { r2 = r1; r1 = READ_REG(arg); @@ -2232,9 +2206,11 @@ void hd61700_cpu_device::execute_run() case 0x03: //byum { uint8_t arg1 = read_op(); - uint8_t r1 = 0, r2 = 0, f = 0; + uint8_t r1 = 0; + uint8_t r2 = 0; + uint8_t f = 0; - for (int n=GET_IM3(arg1); n>0; n--) + for (int n = GET_IM3(arg1); n > 0; n--) { r2 = r1; r1 = READ_REG(arg); @@ -2256,11 +2232,12 @@ void hd61700_cpu_device::execute_run() { uint8_t arg = read_op(); uint8_t arg1 = read_op(); - uint8_t r1 = 0, r2, f = 0; + uint8_t r1 = 0; + uint8_t f = 0; - r2 = (arg&0x40) ? 0 : 1; + uint8_t r2 = BIT(~arg, 6); - for (int n=GET_IM3(arg1); n>0; n--) + for (int n = GET_IM3(arg1); n > 0; n--) { r1 = r2 + (~READ_REG(arg)); WRITE_REG(arg++, r1); @@ -2274,7 +2251,7 @@ void hd61700_cpu_device::execute_run() CLEAR_FLAGS; CHECK_FLAG_Z(f); CHECK_FLAGB_UZ_LZ(r1); - if (f != 0 || (arg & 0x40)) + if (f != 0 || BIT(arg, 6)) SET_FLAG_C; } break; @@ -2287,17 +2264,17 @@ void hd61700_cpu_device::execute_run() for(;;) { - res = mem_readbyte(REG_UA>>4, REG_IX) - READ_REG(arg); + res = mem_readbyte(REG_UA >> 4, REG_IX) - READ_REG(arg); if (REG_IX == REG_IY || !res) break; - REG_IX += ((op&1) ? -1 : +1); + REG_IX += ((op & 1) ? -1 : +1); m_icount -= 6; } CLEAR_FLAGS; - CHECK_FLAG_Z(res & 0xff); + CHECK_FLAG_Z((uint8_t)res); CHECK_FLAGB_UZ_LZ(res); CHECK_FLAG_C(res, 0xff); @@ -2309,7 +2286,6 @@ void hd61700_cpu_device::execute_run() { uint8_t arg = read_op(); set_pc(REG_GET16(arg)); - m_icount -= 5; } break; @@ -2318,10 +2294,10 @@ void hd61700_cpu_device::execute_run() { uint8_t arg = read_op(); uint16_t offset = REG_GET16(arg); - uint8_t lsb = mem_readbyte(REG_UA>>4, offset+0); - uint8_t msb = mem_readbyte(REG_UA>>4, offset+1); + uint8_t lsb = mem_readbyte(REG_UA >> 4, offset); + uint8_t msb = mem_readbyte(REG_UA >> 4, offset + 1); - set_pc((msb<<8) | lsb); + set_pc((msb << 8) | lsb); m_icount -= 5; } @@ -2337,9 +2313,9 @@ void hd61700_cpu_device::execute_run() REG_IX += ((arg & 0x80) ? -ir_inc : +ir_inc); - for (int n=GET_IM3(arg1); n>0; n--) + for (int n = GET_IM3(arg1); n > 0; n--) { - mem_writebyte(REG_UA>>4, REG_IX++, READ_REG(arg++)); + mem_writebyte(REG_UA >> 4, REG_IX++, READ_REG(arg++)); m_icount -= 3; } @@ -2359,9 +2335,9 @@ void hd61700_cpu_device::execute_run() REG_IZ += ((arg & 0x80) ? -ir_inc : +ir_inc); - for (int n=GET_IM3(arg1); n>0; n--) + for (int n = GET_IM3(arg1); n > 0; n--) { - mem_writebyte(REG_UA>>6, REG_IZ++, READ_REG(arg++)); + mem_writebyte(REG_UA >> 6, REG_IZ++, READ_REG(arg++)); m_icount -= 3; } @@ -2379,9 +2355,9 @@ void hd61700_cpu_device::execute_run() REG_IX += ((arg & 0x80) ? -ir_inc : +ir_inc); - for (int n=GET_IM3(arg1); n>0; n--) + for (int n = GET_IM3(arg1); n > 0; n--) { - mem_writebyte(REG_UA>>4, REG_IX--, READ_REG(arg--)); + mem_writebyte(REG_UA >> 4, REG_IX--, READ_REG(arg--)); m_icount -= 3; } @@ -2399,9 +2375,9 @@ void hd61700_cpu_device::execute_run() REG_IZ += ((arg & 0x80) ? -ir_inc : +ir_inc); - for (int n=GET_IM3(arg1); n>0; n--) + for (int n = GET_IM3(arg1); n > 0; n--) { - mem_writebyte(REG_UA>>6, REG_IZ--, READ_REG(arg--)); + mem_writebyte(REG_UA >> 6, REG_IZ--, READ_REG(arg--)); m_icount -= 3; } @@ -2417,9 +2393,9 @@ void hd61700_cpu_device::execute_run() uint8_t arg = read_op(); uint8_t arg1 = read_op(); - for (int n=GET_IM3(arg1); n>0; n--) + for (int n = GET_IM3(arg1); n > 0; n--) { - push((op&1) ? REG_US : REG_SS, READ_REG(arg--)); + push((op & 1) ? REG_US : REG_SS, READ_REG(arg--)); m_icount -= 3; } @@ -2438,9 +2414,9 @@ void hd61700_cpu_device::execute_run() REG_IX += ((arg & 0x80) ? -ir_inc : +ir_inc); - for (int n=GET_IM3(arg1); n>0; n--) + for (int n = GET_IM3(arg1); n > 0; n--) { - WRITE_REG(arg++, mem_readbyte(REG_UA>>4, REG_IX++)); + WRITE_REG(arg++, mem_readbyte(REG_UA >> 4, REG_IX++)); m_icount -= 3; } @@ -2460,9 +2436,9 @@ void hd61700_cpu_device::execute_run() REG_IZ += ((arg & 0x80) ? -ir_inc : +ir_inc); - for (int n=GET_IM3(arg1); n>0; n--) + for (int n = GET_IM3(arg1); n > 0; n--) { - WRITE_REG(arg++, mem_readbyte(REG_UA>>6, REG_IZ++)); + WRITE_REG(arg++, mem_readbyte(REG_UA >> 6, REG_IZ++)); m_icount -= 3; } @@ -2480,9 +2456,9 @@ void hd61700_cpu_device::execute_run() REG_IX += ((arg & 0x80) ? -ir_inc : +ir_inc); - for (int n=GET_IM3(arg1); n>0; n--) + for (int n = GET_IM3(arg1); n > 0; n--) { - WRITE_REG(arg--, mem_readbyte(REG_UA>>4, REG_IX--)); + WRITE_REG(arg--, mem_readbyte(REG_UA >> 4, REG_IX--)); m_icount -= 3; } @@ -2500,9 +2476,9 @@ void hd61700_cpu_device::execute_run() REG_IZ += ((arg & 0x80) ? -ir_inc : +ir_inc); - for (int n=GET_IM3(arg1); n>0; n--) + for (int n = GET_IM3(arg1); n > 0; n--) { - WRITE_REG(arg--, mem_readbyte(REG_UA>>6, REG_IZ--)); + WRITE_REG(arg--, mem_readbyte(REG_UA >> 6, REG_IZ--)); m_icount -= 3; } @@ -2518,9 +2494,9 @@ void hd61700_cpu_device::execute_run() uint8_t arg = read_op(); uint8_t arg1 = read_op(); - for (int n=GET_IM3(arg1); n>0; n--) + for (int n = GET_IM3(arg1); n > 0; n--) { - WRITE_REG(arg++, pop((op&1) ? REG_US : REG_SS)); + WRITE_REG(arg++, pop((op & 1) ? REG_US : REG_SS)); m_icount -= 3; } @@ -2539,32 +2515,32 @@ void hd61700_cpu_device::execute_run() { if (check_cond(op)) { - uint8_t lsb = pop(REG_SS) ; + uint8_t lsb = pop(REG_SS); uint8_t msb = pop(REG_SS); - set_pc((((msb<<8) | (lsb<<0)) + 1)); + set_pc(((msb << 8) | lsb) + 1); } m_icount -= 3; } break; case 0xf8: //nop - m_icount -= 3; + m_icount -= 3; break; case 0xf9: //clt - REG_TM = 0; - m_icount -= 3; + REG_TM = 0; + m_icount -= 3; break; case 0xfa: //fst - m_state |= CPU_FAST; - m_icount -= 3; + m_state |= CPU_FAST; + m_icount -= 3; break; case 0xfb: //slw - m_state &= ~CPU_FAST; - m_icount -= 3; + m_state &= ~CPU_FAST; + m_icount -= 3; break; case 0xfd: //rtni @@ -2572,58 +2548,52 @@ void hd61700_cpu_device::execute_run() uint8_t lsb = pop(REG_SS); uint8_t msb = pop(REG_SS); - set_pc((msb<<8) | (lsb<<0)); + set_pc((msb << 8) | lsb); m_icount -= 5; } [[fallthrough]]; case 0xfc: //cani + for (uint8_t arg = 0x10; arg > 0; arg >>= 1) { - for (uint8_t arg=0x10; arg>0; arg>>=1) + if (REG_IB & arg) { - if (REG_IB & arg) - { - REG_IB &= (~arg); - m_irq_status &= (~arg); - break; - } + REG_IB &= ~arg; + m_irq_status &= ~arg; + break; } - - m_icount -= 3; } + + m_icount -= 3; break; case 0xfe: //off - { - set_pc(0); - REG_UA = REG_IA = 0; - REG_IX = REG_IY = REG_IZ = 0; - REG_PE = 0; - REG_IE = (REG_IE&0x0c) | ((REG_IB>>1) & 0x10); - REG_IB &= 0xe3; - if (m_flags & FLAG_SW) - m_flags |= FLAG_APO; - else - m_flags &= ~FLAG_APO; + set_pc(0); + REG_UA = REG_IA = 0; + REG_IX = REG_IY = REG_IZ = 0; + REG_PE = 0; + REG_IE = (REG_IE & 0x0c) | ((REG_IB >> 1) & 0x10); + REG_IB &= 0xe3; + if (m_flags & FLAG_SW) + m_flags |= FLAG_APO; + else + m_flags &= ~FLAG_APO; - m_state |= CPU_SLP; + m_state |= CPU_SLP; - m_irq_status = 0; - m_lcd_ctrl_cb((offs_t)0, 0); - m_kb_write_cb((offs_t)0, 0); - m_icount -= 3; - } + m_irq_status = 0; + m_lcd_ctrl_cb(0); + m_kb_write_cb(0); + m_icount -= 3; break; case 0xff: //trp - { - m_pc--; - push(REG_SS, (m_pc>>8)&0xff); - push(REG_SS, (m_pc>>0)&0xff); - set_pc(0x0022); - m_icount -= 9; - } + m_pc--; + push(REG_SS, (uint8_t)(m_pc >> 8)); + push(REG_SS, (uint8_t)m_pc); + set_pc(0x0022); + m_icount -= 9; break; case 0x03: @@ -2657,7 +2627,7 @@ void hd61700_cpu_device::execute_run() //if is in the internal ROM align the pc if (!WORD_ALIGNED(m_fetch_addr) && m_pc < INT_ROM) - set_pc((m_fetch_addr+1)>>1); + set_pc((m_fetch_addr + 1) >> 1); m_icount -= 3; } while (m_icount > 0); @@ -2685,33 +2655,33 @@ void hd61700_cpu_device::execute_set_input(int inputnum, int state) set_pc(0x0000); break; case HD61700_KEY_INT: //level sensitive line - if (((REG_IE>>3) & (1<<inputnum)) && state != CLEAR_LINE) - REG_IB |= (1<<inputnum); + if (BIT(REG_IE >> 3, inputnum) && state != CLEAR_LINE) + REG_IB |= (1 << inputnum); break; case HD61700_INT1: //edge sensitive line - if (((REG_IE>>3) & (1<<inputnum)) && (m_lines_status[inputnum] != state)) - REG_IB |= (1<<inputnum); + if (BIT(REG_IE >> 3, inputnum) && m_lines_status[inputnum] != state) + REG_IB |= (1 << inputnum); if (m_lines_status[inputnum] == CLEAR_LINE && state != CLEAR_LINE) REG_IE = (REG_IE & 0xfd) | 0x02; //rising edge else if (m_lines_status[inputnum] != CLEAR_LINE && state == CLEAR_LINE) REG_IE = (REG_IE & 0xfd) | 0x00; //falling edge - REG_KY = (REG_KY & 0xf7ff) | ((state != CLEAR_LINE)<<11); + REG_KY = (REG_KY & 0xf7ff) | ((state != CLEAR_LINE) << 11); break; case HD61700_INT2: //level sensitive line - if (((REG_IE>>3) & (1<<inputnum)) && state != CLEAR_LINE) - REG_IB |= (1<<inputnum); + if (BIT(REG_IE >> 3, inputnum) && state != CLEAR_LINE) + REG_IB |= (1 << inputnum); REG_IE = (REG_IE & 0xfe) | (state != CLEAR_LINE); - REG_KY = (REG_KY & 0xfbff) | ((state != CLEAR_LINE)<<10); + REG_KY = (REG_KY & 0xfbff) | ((state != CLEAR_LINE) << 10); break; case HD61700_ON_INT: //level sensitive line - if ((REG_IE>>3) & (1<<inputnum) && state != CLEAR_LINE) - REG_IB |= (1<<inputnum); + if (BIT(REG_IE >> 3, inputnum) && state != CLEAR_LINE) + REG_IB |= (1 << inputnum); - REG_KY = (REG_KY & 0xfdff) | ((state != CLEAR_LINE)<<9); + REG_KY = (REG_KY & 0xfdff) | ((state != CLEAR_LINE) << 9); break; case HD61700_SW: //level sensitive line @@ -2725,7 +2695,7 @@ void hd61700_cpu_device::execute_set_input(int inputnum, int state) } } - m_flags |= ((state != CLEAR_LINE)<<3); + m_flags |= (state != CLEAR_LINE) << 3; break; } @@ -2742,43 +2712,43 @@ inline void hd61700_cpu_device::set_pc(int32_t new_pc) m_curpc = (m_curpc & 0x30000) | new_pc; m_pc = new_pc & 0xffff; m_ppc = m_curpc; - m_fetch_addr = new_pc<<1; + m_fetch_addr = new_pc << 1; } inline uint8_t hd61700_cpu_device::read_op() { uint16_t data; - uint32_t addr18 = make_18bit_addr((m_irq_status) ? 0 : prev_ua, m_pc); + uint32_t addr18 = make_18bit_addr(m_irq_status ? 0 : prev_ua, m_pc); if (m_pc <= INT_ROM) { data = m_program->read_word(addr18); - if (!(m_fetch_addr&1)) - data = (data>>8) ; + if (!(m_fetch_addr & 1)) + data >>= 8; } else { - if (m_fetch_addr&1) + if (m_fetch_addr & 1) data = m_program->read_word(addr18 + 1); else - data = m_program->read_word(addr18 + 0); + data = m_program->read_word(addr18); } - m_fetch_addr += ((m_pc > INT_ROM) ? 2 : 1); + m_fetch_addr += (m_pc > INT_ROM) ? 2 : 1; - m_pc = m_fetch_addr>>1; + m_pc = m_fetch_addr >> 1; - m_curpc = make_18bit_addr((m_irq_status) ? 0 : prev_ua, m_pc); + m_curpc = make_18bit_addr(m_irq_status ? 0 : prev_ua, m_pc); prev_ua = REG_UA; - return (data&0xff); + return (uint8_t)data; } inline uint8_t hd61700_cpu_device::mem_readbyte(uint8_t segment, uint16_t offset) { - return m_program->read_word(make_18bit_addr(segment, offset)) & 0xff; + return (uint8_t)m_program->read_word(make_18bit_addr(segment, offset)); } inline void hd61700_cpu_device::mem_writebyte(uint8_t segment, uint16_t offset, uint8_t data) @@ -2789,7 +2759,7 @@ inline void hd61700_cpu_device::mem_writebyte(uint8_t segment, uint16_t offset, inline uint32_t hd61700_cpu_device::make_18bit_addr(uint8_t segment, uint16_t offset) { if (offset >= ((REG_IB>>6) & 0x03) * 0x4000) - return (uint32_t)((offset | ((segment&0x03)<<16)) & 0x3ffff); + return (uint32_t)((offset | ((segment & 0x03) << 16)) & 0x3ffff); else return offset; } @@ -2797,52 +2767,52 @@ inline uint32_t hd61700_cpu_device::make_18bit_addr(uint8_t segment, uint16_t of inline void hd61700_cpu_device::push(uint16_t &offset, uint8_t data) { offset--; - mem_writebyte(REG_UA>>2, offset, data); + mem_writebyte(REG_UA >> 2, offset, data); } inline uint8_t hd61700_cpu_device::pop(uint16_t &offset) { - uint8_t data = mem_readbyte(REG_UA>>2, offset); + uint8_t data = mem_readbyte(REG_UA >> 2, offset); offset++; return data; } inline int hd61700_cpu_device::check_cond(uint32_t op) { - switch ( op & 0x07 ) + switch (op & 0x07) { case 0x00: // Z set - if ( !(m_flags & FLAG_Z) ) + if (!(m_flags & FLAG_Z)) return 1; break; case 0x01: // NC set - if ( !(m_flags & FLAG_C) ) + if (!(m_flags & FLAG_C)) return 1; break; case 0x02: // LZ set - if ( !(m_flags & FLAG_LZ) ) + if (!(m_flags & FLAG_LZ)) return 1; break; case 0x03: // UZ set - if ( !(m_flags & FLAG_UZ) ) + if (!(m_flags & FLAG_UZ)) return 1; break; case 0x04: // NZ set - if ( m_flags & FLAG_Z ) + if (m_flags & FLAG_Z) return 1; break; case 0x05: // C set - if ( m_flags & FLAG_C ) + if (m_flags & FLAG_C) return 1; break; case 0x06: // NLZ clear - if ( m_flags & FLAG_LZ ) + if (m_flags & FLAG_LZ) return 1; break; @@ -2855,7 +2825,7 @@ inline int hd61700_cpu_device::check_cond(uint32_t op) inline uint8_t hd61700_cpu_device::make_logic(uint8_t type, uint8_t d1, uint8_t d2) { - switch (type&3) + switch (type & 3) { case 0: //and return d1 & d2; @@ -2887,11 +2857,9 @@ inline void hd61700_cpu_device::check_optional_jr(uint8_t arg) inline uint8_t hd61700_cpu_device::get_sir_im8(uint8_t arg) { - if (((arg>>5) & 0x03) == 0x03) + if (((arg >> 5) & 0x03) == 0x03) { - uint8_t arg1 = read_op(); - - return arg1&0x1f; + return read_op() & 0x1f; } else { @@ -2901,9 +2869,9 @@ inline uint8_t hd61700_cpu_device::get_sir_im8(uint8_t arg) inline uint8_t hd61700_cpu_device::get_sir_im8(uint8_t arg, uint8_t arg1) { - if (((arg>>5) & 0x03) == 0x03) + if (((arg >> 5) & 0x03) == 0x03) { - return arg1&0x1f; + return arg1 & 0x1f; } else { @@ -2931,7 +2899,7 @@ inline int hd61700_cpu_device::get_sign_im8(uint8_t arg) inline int hd61700_cpu_device::get_im_7(uint8_t data) { - if (data&0x80) + if (data & 0x80) return 0x80 - data; else return data; @@ -2939,7 +2907,7 @@ inline int hd61700_cpu_device::get_im_7(uint8_t data) inline uint16_t hd61700_cpu_device::make_bcd_sub(uint8_t arg1, uint8_t arg2) { - uint32_t ret = (arg1&0x0f) - (arg2&0x0f); + uint32_t ret = (arg1 & 0x0f) - (arg2 & 0x0f); uint8_t carry; if (ret > 0x09) @@ -2950,24 +2918,24 @@ inline uint16_t hd61700_cpu_device::make_bcd_sub(uint8_t arg1, uint8_t arg2) else carry = 0; - ret += ((arg1&0xf0) - (arg2&0xf0) - (carry<<4)); + ret += ((arg1 & 0xf0) - (arg2 & 0xf0) - (carry << 4)); if (ret > 0x9f) { - ret = (ret - 0x60) & 0x0ff; + ret = (uint8_t)(ret - 0x60); carry = 1; } else carry = 0; - ret -= (carry<<8); + ret -= carry << 8; return ret; } inline uint16_t hd61700_cpu_device::make_bcd_add(uint8_t arg1, uint8_t arg2) { - uint32_t ret = (arg1&0x0f) + (arg2&0x0f); + uint32_t ret = (arg1 & 0x0f) + (arg2 & 0x0f); uint8_t carry; if (ret > 0x09) @@ -2978,17 +2946,17 @@ inline uint16_t hd61700_cpu_device::make_bcd_add(uint8_t arg1, uint8_t arg2) else carry = 0; - ret += ((arg1&0xf0) + (arg2&0xf0) + (carry<<4)); + ret += ((arg1 & 0xf0) + (arg2 & 0xf0) + (carry << 4)); if (ret > 0x9f) { - ret = (ret + 0x60) & 0x0ff; + ret = (uint8_t)(ret + 0x60); carry = 1; } else carry = 0; - ret += (carry<<8); + ret += carry << 8; return ret; } diff --git a/src/devices/cpu/hd61700/hd61700.h b/src/devices/cpu/hd61700/hd61700.h index d51247e7c13..6f7ef9462ff 100644 --- a/src/devices/cpu/hd61700/hd61700.h +++ b/src/devices/cpu/hd61700/hd61700.h @@ -47,7 +47,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_execute_interface overrides virtual uint32_t execute_min_cycles() const noexcept override { return 1; } @@ -69,24 +68,26 @@ protected: // interrupts bool check_irqs(); - // inline helpers - inline void set_pc(int32_t new_pc); - inline uint8_t read_op(); - inline uint8_t mem_readbyte(uint8_t segment, uint16_t offset); - inline void mem_writebyte(uint8_t segment, uint16_t offset, uint8_t data); - inline uint32_t make_18bit_addr(uint8_t segment, uint16_t offset); - inline int check_cond( uint32_t op ); - inline void push(uint16_t &offset, uint8_t data); - inline uint8_t pop(uint16_t &offset); - inline uint8_t make_logic(uint8_t type, uint8_t d1, uint8_t d2); - inline void check_optional_jr(uint8_t arg); - inline uint8_t get_sir_im8(uint8_t arg); - inline uint8_t get_sir_im8(uint8_t arg, uint8_t arg1); - inline int get_sign_mreg(uint8_t op1); - inline int get_sign_im8(uint8_t op1); - inline int get_im_7(uint8_t data); - inline uint16_t make_bcd_sub(uint8_t arg1, uint8_t arg2); - inline uint16_t make_bcd_add(uint8_t arg1, uint8_t arg2); + // helpers + void set_pc(int32_t new_pc); + uint8_t read_op(); + uint8_t mem_readbyte(uint8_t segment, uint16_t offset); + void mem_writebyte(uint8_t segment, uint16_t offset, uint8_t data); + uint32_t make_18bit_addr(uint8_t segment, uint16_t offset); + int check_cond( uint32_t op ); + void push(uint16_t &offset, uint8_t data); + uint8_t pop(uint16_t &offset); + uint8_t make_logic(uint8_t type, uint8_t d1, uint8_t d2); + void check_optional_jr(uint8_t arg); + uint8_t get_sir_im8(uint8_t arg); + uint8_t get_sir_im8(uint8_t arg, uint8_t arg1); + int get_sign_mreg(uint8_t op1); + int get_sign_im8(uint8_t op1); + int get_im_7(uint8_t data); + uint16_t make_bcd_sub(uint8_t arg1, uint8_t arg2); + uint16_t make_bcd_add(uint8_t arg1, uint8_t arg2); + + TIMER_CALLBACK_MEMBER(second_tick); // registers enum @@ -96,8 +97,6 @@ protected: HD61700_IY, HD61700_IZ, HD61700_US, HD61700_SS, HD61700_KY, HD61700_MAINREG }; - static constexpr device_timer_id SEC_TIMER = 1; - // internal state address_space_config m_program_config; emu_timer *m_sec_timer; diff --git a/src/devices/cpu/i86/i186.cpp b/src/devices/cpu/i86/i186.cpp index 8ebcaf3b1db..477d53c3ad1 100644 --- a/src/devices/cpu/i86/i186.cpp +++ b/src/devices/cpu/i86/i186.cpp @@ -11,11 +11,15 @@ #include "i186.h" #include "i86inline.h" -#define LOG_PORTS 0 -#define LOG_INTERRUPTS 0 -#define LOG_INTERRUPTS_EXT 0 -#define LOG_TIMER 0 -#define LOG_DMA 0 +#define LOG_PORTS (1U << 1) +#define LOG_INTERRUPTS (1U << 2) +#define LOG_INTERRUPTS_EXT (1U << 3) +#define LOG_TIMER (1U << 4) +#define LOG_DMA (1U << 5) +#define LOG_DMA_HIFREQ (1U << 6) + +#define VERBOSE (0) +#include "logmacro.h" /* external int priority masks */ @@ -154,7 +158,7 @@ i80186_cpu_device::i80186_cpu_device(const machine_config &mconfig, device_type device_memory_interface::space_config_vector i80186_cpu_device::memory_space_config() const { - if(has_configured_map(AS_OPCODES)) + if (has_configured_map(AS_OPCODES)) return space_config_vector { std::make_pair(AS_PROGRAM, &m_program_config), std::make_pair(AS_OPCODES, &m_opcodes_config), @@ -176,25 +180,25 @@ uint8_t i80186_cpu_device::fetch() void i80186_cpu_device::execute_run() { - while(m_icount > 0 ) + while (m_icount > 0) { - if((m_dma[0].drq_state && (m_dma[0].control & ST_STOP)) || (m_dma[1].drq_state && (m_dma[1].control & ST_STOP))) + if ((m_dma[0].drq_state && (m_dma[0].control & ST_STOP)) || (m_dma[1].drq_state && (m_dma[1].control & ST_STOP))) { int channel = m_last_dma ? 0 : 1; m_last_dma = !m_last_dma; - if(!(m_dma[1].drq_state && (m_dma[1].control & ST_STOP))) + if (!(m_dma[1].drq_state && (m_dma[1].control & ST_STOP))) channel = 0; - else if(!(m_dma[0].drq_state && (m_dma[0].control & ST_STOP))) + else if (!(m_dma[0].drq_state && (m_dma[0].control & ST_STOP))) channel = 1; - else if((m_dma[0].control & CHANNEL_PRIORITY) && !(m_dma[1].control & CHANNEL_PRIORITY)) + else if ((m_dma[0].control & CHANNEL_PRIORITY) && !(m_dma[1].control & CHANNEL_PRIORITY)) channel = 0; - else if((m_dma[1].control & CHANNEL_PRIORITY) && !(m_dma[0].control & CHANNEL_PRIORITY)) + else if ((m_dma[1].control & CHANNEL_PRIORITY) && !(m_dma[0].control & CHANNEL_PRIORITY)) channel = 1; m_icount--; drq_callback(channel); continue; } - if ( m_seg_prefix_next ) + if (m_seg_prefix_next) { m_seg_prefix = true; m_seg_prefix_next = false; @@ -205,15 +209,15 @@ void i80186_cpu_device::execute_run() m_seg_prefix = false; /* Dispatch IRQ */ - if ( m_pending_irq && m_no_interrupt == 0 ) + if (m_pending_irq && m_no_interrupt == 0) { - if ( m_pending_irq & NMI_IRQ ) + if (m_pending_irq & NMI_IRQ) { interrupt(2); m_pending_irq &= ~NMI_IRQ; m_halt = false; } - else if ( m_IF ) + else if (m_IF) { /* the actual vector is retrieved after pushing flags */ /* and clearing the IF */ @@ -222,22 +226,22 @@ void i80186_cpu_device::execute_run() } } - if(m_halt) + if (m_halt) { m_icount = 0; return; } /* No interrupt allowed between last instruction and this one */ - if ( m_no_interrupt ) + if (m_no_interrupt) { m_no_interrupt--; } /* trap should allow one instruction to be executed */ - if ( m_fire_trap ) + if (m_fire_trap) { - if ( m_fire_trap >= 2 ) + if (m_fire_trap >= 2) { interrupt(1); m_fire_trap = 0; @@ -285,12 +289,11 @@ void i80186_cpu_device::execute_run() case 0x62: // i_bound { - uint32_t low,high,tmp; m_modrm = fetch(); - low = GetRMWord(); - high = GetnextRMWord(); - tmp = RegWord(); - if (tmp<low || tmp>high) + uint32_t low = GetRMWord(); + uint32_t high = GetnextRMWord(); + uint32_t tmp = RegWord(); + if (tmp < low || tmp > high) interrupt(5); CLK(BOUND); logerror("%06x: bound %04x high %04x low %04x tmp\n", m_pc, high, low, tmp); @@ -298,16 +301,15 @@ void i80186_cpu_device::execute_run() break; case 0x68: // i_push_d16 - PUSH( fetch_word() ); + PUSH(fetch_word()); CLK(PUSH_IMM); break; case 0x69: // i_imul_d16 { - uint32_t tmp; DEF_r16w(); - tmp = fetch_word(); - m_dst = (int32_t)((int16_t)m_src)*(int32_t)((int16_t)tmp); + uint32_t tmp = fetch_word(); + m_dst = (int32_t)((int16_t)m_src) * (int32_t)((int16_t)tmp); m_CarryVal = m_OverVal = (((int32_t)m_dst) >> 15 != 0) && (((int32_t)m_dst) >> 15 != -1); RegWord(m_dst); CLKM(IMUL_RRI16, IMUL_RMI16); @@ -315,16 +317,15 @@ void i80186_cpu_device::execute_run() break; case 0x6a: // i_push_d8 - PUSH( (uint16_t)((int16_t)((int8_t)fetch())) ); + PUSH((uint16_t)((int16_t)((int8_t)fetch()))); CLK(PUSH_IMM); break; case 0x6b: // i_imul_d8 { - uint32_t src2; DEF_r16w(); - src2= (uint16_t)((int16_t)((int8_t)fetch())); - m_dst = (int32_t)((int16_t)m_src)*(int32_t)((int16_t)src2); + uint32_t src2 = (uint16_t)(int8_t)fetch(); + m_dst = (int32_t)((int16_t)m_src) * (int32_t)((int16_t)src2); m_CarryVal = m_OverVal = (((int32_t)m_dst) >> 15 != 0) && (((int32_t)m_dst) >> 15 != -1); RegWord(m_dst); CLKM(IMUL_RRI8, IMUL_RMI8); @@ -350,7 +351,7 @@ void i80186_cpu_device::execute_run() case 0x8e: // i_mov_sregw m_modrm = fetch(); m_src = GetRMWord(); - CLKM(MOV_SR,MOV_SM); + CLKM(MOV_SR, MOV_SM); switch (m_modrm & 0x38) { case 0x00: /* mov es,ew */ @@ -373,21 +374,20 @@ void i80186_cpu_device::execute_run() case 0xc0: // i_rotshft_bd8 { - uint8_t c; m_modrm = fetch(); m_src = GetRMByte(); m_dst = m_src; - c = fetch() & 0x1f; - CLKM(ROT_REG_BASE,ROT_M8_BASE); + uint8_t c = fetch() & 0x1f; + CLKM(ROT_REG_BASE, ROT_M8_BASE); m_icount -= m_timing[ROT_REG_BIT] * c; if (c) { - switch ( m_modrm & 0x38 ) + switch (m_modrm & 0x38) { - case 0x00: do { ROL_BYTE(); c--; } while (c>0); PutbackRMByte(m_dst); break; - case 0x08: do { ROR_BYTE(); c--; } while (c>0); PutbackRMByte(m_dst); break; - case 0x10: do { ROLC_BYTE(); c--; } while (c>0); PutbackRMByte(m_dst); break; - case 0x18: do { RORC_BYTE(); c--; } while (c>0); PutbackRMByte(m_dst); break; + case 0x00: do { ROL_BYTE(); c--; } while (c > 0); PutbackRMByte(m_dst); break; + case 0x08: do { ROR_BYTE(); c--; } while (c > 0); PutbackRMByte(m_dst); break; + case 0x10: do { ROLC_BYTE(); c--; } while (c > 0); PutbackRMByte(m_dst); break; + case 0x18: do { RORC_BYTE(); c--; } while (c > 0); PutbackRMByte(m_dst); break; case 0x30: case 0x20: SHL_BYTE(c); break; case 0x28: SHR_BYTE(c); break; @@ -399,21 +399,20 @@ void i80186_cpu_device::execute_run() case 0xc1: // i_rotshft_wd8 { - uint8_t c; m_modrm = fetch(); m_src = GetRMWord(); m_dst = m_src; - c = fetch() & 0x1f; - CLKM(ROT_REG_BASE,ROT_M16_BASE); + uint8_t c = fetch() & 0x1f; + CLKM(ROT_REG_BASE, ROT_M16_BASE); m_icount -= m_timing[ROT_REG_BIT] * c; if (c) { - switch ( m_modrm & 0x38 ) + switch (m_modrm & 0x38) { - case 0x00: do { ROL_WORD(); c--; } while (c>0); PutbackRMWord(m_dst); break; - case 0x08: do { ROR_WORD(); c--; } while (c>0); PutbackRMWord(m_dst); break; - case 0x10: do { ROLC_WORD(); c--; } while (c>0); PutbackRMWord(m_dst); break; - case 0x18: do { RORC_WORD(); c--; } while (c>0); PutbackRMWord(m_dst); break; + case 0x00: do { ROL_WORD(); c--; } while (c > 0); PutbackRMWord(m_dst); break; + case 0x08: do { ROR_WORD(); c--; } while (c > 0); PutbackRMWord(m_dst); break; + case 0x10: do { ROLC_WORD(); c--; } while (c > 0); PutbackRMWord(m_dst); break; + case 0x18: do { RORC_WORD(); c--; } while (c > 0); PutbackRMWord(m_dst); break; case 0x30: case 0x20: SHL_WORD(c); break; case 0x28: SHR_WORD(c); break; @@ -426,19 +425,18 @@ void i80186_cpu_device::execute_run() case 0xc8: // i_enter { uint16_t nb = fetch(); - uint32_t level; - nb |= fetch() << 8; - level = fetch(); + + uint32_t level = fetch(); CLK(!level ? ENTER0 : (level == 1) ? ENTER1 : ENTER_BASE); - if(level > 1) + if (level > 1) m_icount -= level * m_timing[ENTER_COUNT]; PUSH(m_regs.w[BP]); m_regs.w[BP] = m_regs.w[SP]; m_regs.w[SP] -= nb; - for (int i=1; i<level; i++) + for (int i = 1; i < level; i++) { - PUSH( GetMemW(SS,m_regs.w[BP] - i*2) ); + PUSH(GetMemW(SS, m_regs.w[BP] - i * 2)); } if (level) { @@ -455,22 +453,20 @@ void i80186_cpu_device::execute_run() case 0xd2: // i_rotshft_bcl { - uint8_t c; - m_modrm = fetch(); m_src = GetRMByte(); m_dst = m_src; - c = m_regs.b[CL] & 0x1f; - CLKM(ROT_REG_BASE,ROT_M16_BASE); + uint8_t c = m_regs.b[CL] & 0x1f; + CLKM(ROT_REG_BASE, ROT_M16_BASE); m_icount -= m_timing[ROT_REG_BIT] * c; if (c) { - switch ( m_modrm & 0x38 ) + switch (m_modrm & 0x38) { - case 0x00: do { ROL_BYTE(); c--; } while (c>0); PutbackRMByte(m_dst); break; - case 0x08: do { ROR_BYTE(); c--; } while (c>0); PutbackRMByte(m_dst); break; - case 0x10: do { ROLC_BYTE(); c--; } while (c>0); PutbackRMByte(m_dst); break; - case 0x18: do { RORC_BYTE(); c--; } while (c>0); PutbackRMByte(m_dst); break; + case 0x00: do { ROL_BYTE(); c--; } while (c > 0); PutbackRMByte(m_dst); break; + case 0x08: do { ROR_BYTE(); c--; } while (c > 0); PutbackRMByte(m_dst); break; + case 0x10: do { ROLC_BYTE(); c--; } while (c > 0); PutbackRMByte(m_dst); break; + case 0x18: do { RORC_BYTE(); c--; } while (c > 0); PutbackRMByte(m_dst); break; case 0x30: case 0x20: SHL_BYTE(c); break; case 0x28: SHR_BYTE(c); break; @@ -482,22 +478,20 @@ void i80186_cpu_device::execute_run() case 0xd3: // i_rotshft_wcl { - uint8_t c; - m_modrm = fetch(); m_src = GetRMWord(); m_dst = m_src; - c = m_regs.b[CL] & 0x1f; - CLKM(ROT_REG_BASE,ROT_M16_BASE); + uint8_t c = m_regs.b[CL] & 0x1f; + CLKM(ROT_REG_BASE, ROT_M16_BASE); m_icount -= m_timing[ROT_REG_BIT] * c; if (c) { - switch ( m_modrm & 0x38 ) + switch (m_modrm & 0x38) { - case 0x00: do { ROL_WORD(); c--; } while (c>0); PutbackRMWord(m_dst); break; - case 0x08: do { ROR_WORD(); c--; } while (c>0); PutbackRMWord(m_dst); break; - case 0x10: do { ROLC_WORD(); c--; } while (c>0); PutbackRMWord(m_dst); break; - case 0x18: do { RORC_WORD(); c--; } while (c>0); PutbackRMWord(m_dst); break; + case 0x00: do { ROL_WORD(); c--; } while (c > 0); PutbackRMWord(m_dst); break; + case 0x08: do { ROR_WORD(); c--; } while (c > 0); PutbackRMWord(m_dst); break; + case 0x10: do { ROLC_WORD(); c--; } while (c > 0); PutbackRMWord(m_dst); break; + case 0x18: do { RORC_WORD(); c--; } while (c > 0); PutbackRMWord(m_dst); break; case 0x30: case 0x20: SHL_WORD(c); break; case 0x28: SHR_WORD(c); break; @@ -515,7 +509,7 @@ void i80186_cpu_device::execute_run() case 0xdd: case 0xde: case 0xdf: - if(m_reloc & 0x8000) + if (m_reloc & 0x8000) { m_ip = m_prev_ip; interrupt(7); @@ -525,7 +519,7 @@ void i80186_cpu_device::execute_run() GetRMByte(); CLK(NOP); // The 80187 has the FSTSW AX instruction - if((m_modrm == 0xe0) && (op == 0xdf)) + if ((m_modrm == 0xe0) && (op == 0xdf)) m_regs.w[AX] = 0xffff; // FPU not present break; @@ -548,26 +542,78 @@ void i80186_cpu_device::execute_run() switch (next) { - case 0x6c: CLK(OVERRIDE); if (c) do { i_insb(); c--; } while (c>0 && m_icount>0); m_regs.w[CX]=c; m_seg_prefix = false; m_seg_prefix_next = false; break; - case 0x6d: CLK(OVERRIDE); if (c) do { i_insw(); c--; } while (c>0 && m_icount>0); m_regs.w[CX]=c; m_seg_prefix = false; m_seg_prefix_next = false; break; - case 0x6e: CLK(OVERRIDE); if (c) do { i_outsb(); c--; } while (c>0 && m_icount>0); m_regs.w[CX]=c; m_seg_prefix = false; m_seg_prefix_next = false; break; - case 0x6f: CLK(OVERRIDE); if (c) do { i_outsw(); c--; } while (c>0 && m_icount>0); m_regs.w[CX]=c; m_seg_prefix = false; m_seg_prefix_next = false; break; + case 0x6c: + CLK(OVERRIDE); + if (c) + { + do + { + i_insb(); + c--; + } while (c > 0 && m_icount > 0); + } + m_regs.w[CX] = c; + m_seg_prefix = false; + m_seg_prefix_next = false; + break; + case 0x6d: + CLK(OVERRIDE); + if (c) + { + do + { + i_insw(); + c--; + } while (c > 0 && m_icount > 0); + } + m_regs.w[CX] = c; + m_seg_prefix = false; + m_seg_prefix_next = false; + break; + case 0x6e: + CLK(OVERRIDE); + if (c) + { + do + { + i_outsb(); + c--; + } while (c > 0 && m_icount > 0); + } + m_regs.w[CX] = c; + m_seg_prefix = false; + m_seg_prefix_next = false; + break; + case 0x6f: + CLK(OVERRIDE); + if (c) + { + do + { + i_outsw(); + c--; + } while (c > 0 && m_icount > 0); + } + m_regs.w[CX] = c; + m_seg_prefix = false; + m_seg_prefix_next = false; + break; default: // Decrement IP and pass on m_ip -= 1 + (m_seg_prefix_next ? 1 : 0); pass = true; break; } - if(!pass) + if (!pass) { - if(c) + if (c) m_ip = m_prev_ip; break; } } [[fallthrough]]; default: - if(!common_op(op)) + if (!common_op(op)) { m_icount -= 10; // UD fault timing? logerror("%06x: Invalid Opcode %02x\n", m_pc, op); @@ -669,9 +715,9 @@ void i80186_cpu_device::device_start() m_reloc = 0; m_last_dma = 0; - m_timer[0].int_timer = timer_alloc(TIMER_INT0); - m_timer[1].int_timer = timer_alloc(TIMER_INT1); - m_timer[2].int_timer = timer_alloc(TIMER_INT2); + m_timer[0].int_timer = timer_alloc(FUNC(i80186_cpu_device::timer_elapsed), this); + m_timer[1].int_timer = timer_alloc(FUNC(i80186_cpu_device::timer_elapsed), this); + m_timer[2].int_timer = timer_alloc(FUNC(i80186_cpu_device::timer_elapsed), this); m_out_tmrout0_func.resolve_safe(); m_out_tmrout1_func.resolve_safe(); @@ -707,13 +753,13 @@ void i80186_cpu_device::device_reset() m_reloc = 0x20ff; m_mem.upper = 0xfffb; - for (auto & elem : m_dma) + for (dma_state &elem : m_dma) { elem.drq_state = false; elem.control = 0; } - for (auto & elem : m_timer) + for (timer_state &elem : m_timer) { elem.control = 0; elem.maxA = 0; @@ -724,9 +770,9 @@ void i80186_cpu_device::device_reset() uint8_t i80186_cpu_device::read_port_byte(uint16_t port) { - if(!(m_reloc & 0x1000) && (port >> 8) == (m_reloc & 0xff)) + if (!(m_reloc & 0x1000) && (port >> 8) == (m_reloc & 0xff)) { - if(port & 1) + if (port & 1) return internal_port_r((port >> 1) & 0x7f, 0xff00) >> 8; else return internal_port_r((port >> 1) & 0x7f, 0x00ff) & 0xff; @@ -736,10 +782,10 @@ uint8_t i80186_cpu_device::read_port_byte(uint16_t port) uint16_t i80186_cpu_device::read_port_word(uint16_t port) { - if(!(m_reloc & 0x1000) && (port >> 8) == (m_reloc & 0xff)) + if (!(m_reloc & 0x1000) && (port >> 8) == (m_reloc & 0xff)) { // Unaligned reads from the internal bus are swapped rather than split - if(port & 1) + if (port & 1) return swapendian_int16(internal_port_r((port >> 1) & 0x7f)); else return internal_port_r((port >> 1) & 0x7f); @@ -749,9 +795,9 @@ uint16_t i80186_cpu_device::read_port_word(uint16_t port) void i80186_cpu_device::write_port_byte(uint16_t port, uint8_t data) { - if(!(m_reloc & 0x1000) && (port >> 8) == (m_reloc & 0xff)) + if (!(m_reloc & 0x1000) && (port >> 8) == (m_reloc & 0xff)) { - if(port & 1) + if (port & 1) internal_port_w((port >> 1) & 0x7f, data << 8); else internal_port_w((port >> 1) & 0x7f, data); @@ -762,10 +808,10 @@ void i80186_cpu_device::write_port_byte(uint16_t port, uint8_t data) void i80186_cpu_device::write_port_byte_al(uint16_t port) { - if(!(m_reloc & 0x1000) && (port >> 8) == (m_reloc & 0xff)) + if (!(m_reloc & 0x1000) && (port >> 8) == (m_reloc & 0xff)) { // Both AH and AL are written onto the internal bus - if(port & 1) + if (port & 1) internal_port_w((port >> 1) & 0x7f, swapendian_int16(m_regs.w[AX])); else internal_port_w((port >> 1) & 0x7f, m_regs.w[AX]); @@ -776,10 +822,10 @@ void i80186_cpu_device::write_port_byte_al(uint16_t port) void i80186_cpu_device::write_port_word(uint16_t port, uint16_t data) { - if(!(m_reloc & 0x1000) && (port >> 8) == (m_reloc & 0xff)) + if (!(m_reloc & 0x1000) && (port >> 8) == (m_reloc & 0xff)) { // Unaligned writes to the internal bus are swapped rather than split - if(port & 1) + if (port & 1) internal_port_w((port >> 1) & 0x7f, swapendian_int16(data)); else internal_port_w((port >> 1) & 0x7f, data); @@ -790,7 +836,7 @@ void i80186_cpu_device::write_port_word(uint16_t port, uint16_t data) uint8_t i80186_cpu_device::read_byte(uint32_t addr) { - if((m_reloc & 0x1000) && (addr >> 8) == (m_reloc & 0xfff)) + if ((m_reloc & 0x1000) && (addr >> 8) == (m_reloc & 0xfff)) { uint16_t ret = internal_port_r((addr >> 1) & 0x7f, (addr & 1) ? 0xff00 : 0x00ff); return (addr & 1) ? (ret >> 8) : (ret & 0xff); @@ -800,10 +846,10 @@ uint8_t i80186_cpu_device::read_byte(uint32_t addr) uint16_t i80186_cpu_device::read_word(uint32_t addr) { - if((m_reloc & 0x1000) && (addr >> 8) == (m_reloc & 0xfff)) + if ((m_reloc & 0x1000) && (addr >> 8) == (m_reloc & 0xfff)) { // Unaligned reads from the internal bus are swapped rather than split - if(addr & 1) + if (addr & 1) return swapendian_int16(internal_port_r((addr >> 1) & 0x7f)); else return internal_port_r((addr >> 1) & 0x7f); @@ -813,7 +859,7 @@ uint16_t i80186_cpu_device::read_word(uint32_t addr) void i80186_cpu_device::write_byte(uint32_t addr, uint8_t data) { - if((m_reloc & 0x1000) && (addr >> 8) == (m_reloc & 0xfff)) + if ((m_reloc & 0x1000) && (addr >> 8) == (m_reloc & 0xfff)) internal_port_w((addr >> 1) & 0x7f, (addr & 1) ? (data << 8) : data); else m_program->write_byte(addr, data); @@ -821,10 +867,10 @@ void i80186_cpu_device::write_byte(uint32_t addr, uint8_t data) void i80186_cpu_device::write_word(uint32_t addr, uint16_t data) { - if((m_reloc & 0x1000) && (addr >> 8) == (m_reloc & 0xfff)) + if ((m_reloc & 0x1000) && (addr >> 8) == (m_reloc & 0xfff)) { // Unaligned writes from the internal bus are swapped rather than split - if(addr & 1) + if (addr & 1) internal_port_w((addr >> 1) & 0x7f, swapendian_int16(data)); else internal_port_w((addr >> 1) & 0x7f, data); @@ -851,42 +897,38 @@ IRQ_CALLBACK_MEMBER(i80186_cpu_device::inta_callback) IRQ_CALLBACK_MEMBER(i80186_cpu_device::int_callback) { - uint8_t vector; - uint16_t old; - uint16_t oldreq; - - if (LOG_INTERRUPTS) - logerror("(%f) **** Acknowledged interrupt vector %02X\n", machine().time().as_double(), m_intr.poll_status & 0x1f); + LOGMASKED(LOG_INTERRUPTS, "(%f) **** Acknowledged interrupt vector %02X\n", machine().time().as_double(), m_intr.poll_status & 0x1f); /* clear the interrupt */ set_input_line(0, CLEAR_LINE); m_intr.pending = 0; - oldreq = m_intr.request; + uint16_t oldreq = m_intr.request; /* clear the request and set the in-service bit */ - if(m_intr.ack_mask & 0xf0) + if (m_intr.ack_mask & 0xf0) { int i; - for(i = 0; i < 4; i++) - if((m_intr.ack_mask >> (i + 4)) & 1) + for (i = 0; i < 4; i++) + if (BIT(m_intr.ack_mask, i + 4)) break; - if(!(m_intr.ext[i] & EXTINT_CTRL_LTM)) + if (!(m_intr.ext[i] & EXTINT_CTRL_LTM)) m_intr.request &= ~m_intr.ack_mask; } else m_intr.request &= ~m_intr.ack_mask; - if((LOG_INTERRUPTS) && (m_intr.request!=oldreq)) - logerror("intr.request changed from %02X to %02X\n",oldreq,m_intr.request); + if (m_intr.request != oldreq) + LOGMASKED(LOG_INTERRUPTS, "intr.request changed from %02X to %02X\n", oldreq, m_intr.request); - old = m_intr.in_service; + uint16_t old = m_intr.in_service; m_intr.in_service |= m_intr.ack_mask; - if((LOG_INTERRUPTS) && (m_intr.in_service!=old)) - logerror("intr.in_service changed from %02X to %02X\n",old,m_intr.in_service); + if (m_intr.in_service != old) + LOGMASKED(LOG_INTERRUPTS, "intr.in_service changed from %02X to %02X\n",old,m_intr.in_service); + uint8_t vector; if (!BIT(m_reloc, 14)) { if (m_intr.ack_mask == 0x0001) @@ -914,9 +956,9 @@ IRQ_CALLBACK_MEMBER(i80186_cpu_device::int_callback) { if (m_intr.ack_mask & 1) m_intr.status &= ~0x01; - else if(m_intr.ack_mask & 0x10) + else if (m_intr.ack_mask & 0x10) m_intr.status &= ~0x02; - else if(m_intr.ack_mask & 0x20) + else if (m_intr.ack_mask & 0x20) m_intr.status &= ~0x04; } vector = m_intr.poll_status & 0xff; @@ -926,11 +968,8 @@ IRQ_CALLBACK_MEMBER(i80186_cpu_device::int_callback) /* a request no longer pending */ m_intr.poll_status &= ~0x8000; - if (LOG_INTERRUPTS) - { - logerror("intr.ext[0]=%04X intr.ext[1]=%04X\n",m_intr.ext[0],m_intr.ext[1]); - logerror("Int %02X Calling vector %02X\n",m_intr.poll_status,vector); - } + LOGMASKED(LOG_INTERRUPTS, "intr.ext[0]=%04X intr.ext[1]=%04X\n", m_intr.ext[0], m_intr.ext[1]); + LOGMASKED(LOG_INTERRUPTS, "Int %02X Calling vector %02X\n", m_intr.poll_status, vector); return vector; } @@ -939,23 +978,20 @@ IRQ_CALLBACK_MEMBER(i80186_cpu_device::int_callback) void i80186_cpu_device::update_interrupt_state() { int new_vector = 0; - int Priority; - int IntNo; - if (LOG_INTERRUPTS) - logerror("update_interrupt_status: req=%04X stat=%04X serv=%04X priority_mask=%4X\n", m_intr.request, m_intr.status, m_intr.in_service, m_intr.priority_mask); + LOGMASKED(LOG_INTERRUPTS, "update_interrupt_status: req=%04X stat=%04X serv=%04X priority_mask=%4X\n", m_intr.request, m_intr.status, m_intr.in_service, m_intr.priority_mask); /* loop over priorities */ - for (Priority = 0; Priority <= m_intr.priority_mask; Priority++) + for (int priority = 0; priority <= m_intr.priority_mask; priority++) { /* note: by checking 4 bits, we also verify that the mask is off */ if (BIT(m_reloc, 14)) { - for (IntNo = 0; IntNo < 3; IntNo++) + for (int int_num = 0; int_num < 3; int_num++) { - if ((m_intr.timer[IntNo] & 0x0F) == Priority) + if ((m_intr.timer[int_num] & 0x0f) == priority) { - int irq = (1 << IntNo); + int irq = (1 << int_num); /* if we're already servicing something at this level, don't generate anything new */ if (m_intr.in_service & 0x01) return; @@ -963,9 +999,9 @@ void i80186_cpu_device::update_interrupt_state() /* if there's something pending, generate an interrupt */ if (m_intr.status & irq) { - new_vector = m_intr.vector | Priority; + new_vector = m_intr.vector | priority; /* set the clear mask and generate the int */ - m_intr.ack_mask = IntNo ? (8 << IntNo) : 1; + m_intr.ack_mask = int_num ? (8 << int_num) : 1; goto generate_int; } } @@ -973,7 +1009,7 @@ void i80186_cpu_device::update_interrupt_state() } else { - if ((m_intr.timer[0] & 0x0F) == Priority) + if ((m_intr.timer[0] & 0x0f) == priority) { /* if we're already servicing something at this level, don't generate anything new */ if (m_intr.in_service & 0x01) @@ -999,23 +1035,23 @@ void i80186_cpu_device::update_interrupt_state() } /* check DMA interrupts */ - for (IntNo = 0; IntNo < 2; IntNo++) - if ((m_intr.dma[IntNo] & 0x0F) == Priority) + for (int int_num = 0; int_num < 2; int_num++) + if ((m_intr.dma[int_num] & 0x0F) == priority) { /* if we're already servicing something at this level, don't generate anything new */ - if (m_intr.in_service & (0x04 << IntNo)) + if (m_intr.in_service & (0x04 << int_num)) return; /* if there's something pending, generate an interrupt */ - if (m_intr.request & (0x04 << IntNo)) + if (m_intr.request & (0x04 << int_num)) { if (BIT(m_reloc, 14)) - new_vector = m_intr.vector | Priority; + new_vector = m_intr.vector | priority; else - new_vector = 0x0a + IntNo; + new_vector = 0x0a + int_num; /* set the clear mask and generate the int */ - m_intr.ack_mask = 0x0004 << IntNo; + m_intr.ack_mask = 0x0004 << int_num; goto generate_int; } } @@ -1024,34 +1060,33 @@ void i80186_cpu_device::update_interrupt_state() continue; /* check external interrupts */ - for (IntNo = 0; IntNo < 4; IntNo++) + for (int int_num = 0; int_num < 4; int_num++) { - if ((m_intr.ext[IntNo] & 0x0F) == Priority) + if ((m_intr.ext[int_num] & 0x0f) == priority) { - if (LOG_INTERRUPTS) - logerror("Int%d priority=%d\n",IntNo,Priority); + LOGMASKED(LOG_INTERRUPTS, "Int%d priority=%d\n", int_num, priority); /* if we're already servicing something at this level, don't generate anything new */ - if ((m_intr.in_service & (0x10 << IntNo)) && !(m_intr.ext[IntNo] & EXTINT_CTRL_SFNM)) + if ((m_intr.in_service & (0x10 << int_num)) && !(m_intr.ext[int_num] & EXTINT_CTRL_SFNM)) return; /* if there's something pending, generate an interrupt */ - if (m_intr.request & (0x10 << IntNo)) + if (m_intr.request & (0x10 << int_num)) { - if((IntNo >= 2) && (m_intr.ext[IntNo - 2] & EXTINT_CTRL_CASCADE)) + if((int_num >= 2) && (m_intr.ext[int_num - 2] & EXTINT_CTRL_CASCADE)) { - logerror("i186: %06x: irq %d use when set for cascade mode\n", m_pc, IntNo); - m_intr.request &= ~(0x10 << IntNo); + logerror("i186: %06x: irq %d use when set for cascade mode\n", m_pc, int_num); + m_intr.request &= ~(0x10 << int_num); continue; } /* otherwise, generate an interrupt for this request */ - new_vector = 0x0c + IntNo; + new_vector = 0x0c + int_num; /* set the clear mask and generate the int */ - m_intr.ack_mask = 0x0010 << IntNo; + m_intr.ack_mask = 0x0010 << int_num; goto generate_int; } - else if ((m_intr.in_service & (0x10 << IntNo)) && (m_intr.ext[IntNo] & EXTINT_CTRL_SFNM)) + else if ((m_intr.in_service & (0x10 << int_num)) && (m_intr.ext[int_num] & EXTINT_CTRL_SFNM)) return; // if an irq is in service and sfnm is enabled, stop here } } @@ -1074,15 +1109,13 @@ generate_int: m_irmx_irq_cb(ASSERT_LINE); } m_intr.pending = 1; - if (LOG_INTERRUPTS) logerror("(%f) **** Requesting interrupt vector %02X\n", machine().time().as_double(), new_vector); + LOGMASKED(LOG_INTERRUPTS, "(%f) **** Requesting interrupt vector %02X\n", machine().time().as_double(), new_vector); } void i80186_cpu_device::handle_eoi(int data) { - int Priority; - int IntNo; - int handled=0; + bool handled = false; /* specific case */ if (!(data & 0x8000)) @@ -1101,58 +1134,57 @@ void i80186_cpu_device::handle_eoi(int data) case 0x0f: m_intr.in_service &= ~0x80; break; default: logerror("%05X:ERROR - 80186 EOI with unknown vector %02X\n", m_pc, data & 0x1f); } - if (LOG_INTERRUPTS) logerror("(%f) **** Got EOI for vector %02X\n", machine().time().as_double(), data & 0x1f); + LOGMASKED(LOG_INTERRUPTS, "(%f) **** Got EOI for vector %02X\n", machine().time().as_double(), data & 0x1f); } - /* non-specific case */ else { /* loop over priorities */ - for (Priority = 0; ((Priority <= 7) && !handled); Priority++) + for (int priority = 0; priority <= 7 && !handled; priority++) { /* check for in-service timers */ if (BIT(m_reloc, 14)) { - for (IntNo = 0; ((IntNo < 2) && !handled) ; IntNo++) + for (int int_num = 0; int_num < 2 && !handled; int_num++) { - int mask = IntNo ? (8 << IntNo) : 1; - if ((m_intr.timer[IntNo] & 0x07) == Priority && (m_intr.in_service & mask)) + int mask = int_num ? (8 << int_num) : 1; + if ((m_intr.timer[int_num] & 0x07) == priority && (m_intr.in_service & mask)) { m_intr.in_service &= ~mask; - if (LOG_INTERRUPTS) logerror("(%f) **** Got EOI for timer%d\n", machine().time().as_double(), IntNo); - handled=1; + LOGMASKED(LOG_INTERRUPTS, "(%f) **** Got EOI for timer%d\n", machine().time().as_double(), int_num); + handled = true; } } } else { - if ((m_intr.timer[0] & 0x07) == Priority && (m_intr.in_service & 0x01)) + if ((m_intr.timer[0] & 0x07) == priority && (m_intr.in_service & 0x01)) { m_intr.in_service &= ~0x01; - if (LOG_INTERRUPTS) logerror("(%f) **** Got EOI for timer\n", machine().time().as_double()); - handled=1; + LOGMASKED(LOG_INTERRUPTS, "(%f) **** Got EOI for timer\n", machine().time().as_double()); + handled = true; } } /* check for in-service DMA interrupts */ - for (IntNo = 0; ((IntNo < 2) && !handled) ; IntNo++) - if ((m_intr.dma[IntNo] & 0x07) == Priority && (m_intr.in_service & (0x04 << IntNo))) + for (int int_num = 0; int_num < 2 && !handled; int_num++) + if ((m_intr.dma[int_num] & 0x07) == priority && (m_intr.in_service & (0x04 << int_num))) { - m_intr.in_service &= ~(0x04 << IntNo); - if (LOG_INTERRUPTS) logerror("(%f) **** Got EOI for DMA%d\n", machine().time().as_double(), IntNo); - handled=1; + m_intr.in_service &= ~(0x04 << int_num); + LOGMASKED(LOG_INTERRUPTS, "(%f) **** Got EOI for DMA%d\n", machine().time().as_double(), int_num); + handled = true; } if (BIT(m_reloc, 14)) continue; /* check external interrupts */ - for (IntNo = 0; ((IntNo < 4) && !handled) ; IntNo++) - if ((m_intr.ext[IntNo] & 0x07) == Priority && (m_intr.in_service & (0x10 << IntNo))) + for (int int_num = 0; int_num < 4 && !handled; int_num++) + if ((m_intr.ext[int_num] & 0x07) == priority && (m_intr.in_service & (0x10 << int_num))) { - m_intr.in_service &= ~(0x10 << IntNo); - if (LOG_INTERRUPTS) logerror("(%f) **** Got EOI for INT%d\n", machine().time().as_double(), IntNo); - handled=1; + m_intr.in_service &= ~(0x10 << int_num); + LOGMASKED(LOG_INTERRUPTS, "(%f) **** Got EOI for INT%d\n", machine().time().as_double(), int_num); + handled = true; } } } @@ -1160,34 +1192,34 @@ void i80186_cpu_device::handle_eoi(int data) } /* Trigger an external interrupt, optionally supplying the vector to take */ -void i80186_cpu_device::external_int(uint16_t intno, int state) +void i80186_cpu_device::external_int(uint16_t int_num, int state) { if (BIT(m_reloc, 14)) { - if (!intno) + if (!int_num) { set_input_line(0, state); return; } - logerror("irq to line %d in irmx mode\n",intno); + logerror("irq to line %d in irmx mode\n", int_num); return; } - if (!(m_intr.ext_state & (1 << intno)) == !state) + if (!(m_intr.ext_state & (1 << int_num)) == !state) return; - if (LOG_INTERRUPTS_EXT) logerror("generating external int %02X\n",intno); + LOGMASKED(LOG_INTERRUPTS_EXT, "generating external int %02X\n", int_num); if (!state) { - m_intr.request &= ~(0x10 << intno); - m_intr.ack_mask &= ~(0x10 << intno); - m_intr.ext_state &= ~(1 << intno); + m_intr.request &= ~(0x10 << int_num); + m_intr.ack_mask &= ~(0x10 << int_num); + m_intr.ext_state &= ~(1 << int_num); } else // Turn on the requested request bit and handle interrupt { - m_intr.request |= (0x10 << intno); - m_intr.ext_state |= (1 << intno); + m_intr.request |= 0x10 << int_num; + m_intr.ext_state |= 1 << int_num; } update_interrupt_state(); } @@ -1198,82 +1230,70 @@ void i80186_cpu_device::external_int(uint16_t intno, int state) * *************************************/ -void i80186_cpu_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(i80186_cpu_device::timer_elapsed) { - switch(id) - { - case TIMER_INT0: - case TIMER_INT1: - case TIMER_INT2: - { - int which = param; - timer_state *t = &m_timer[which]; + int which = param; + timer_state *t = &m_timer[which]; - if (LOG_TIMER) logerror("Hit interrupt callback for timer %d\n", which); + LOGMASKED(LOG_TIMER, "Hit interrupt callback for timer %d", which); - /* set the max count bit */ - t->control |= 0x0020; + /* set the max count bit */ + t->control |= 0x0020; - /* request an interrupt */ - if (t->control & 0x2000) - { - m_intr.status |= 0x01 << which; - update_interrupt_state(); - if (LOG_TIMER) logerror(" Generating timer interrupt\n"); - } + /* request an interrupt */ + if (t->control & 0x2000) + { + m_intr.status |= 0x01 << which; + update_interrupt_state(); + LOGMASKED(LOG_TIMER, " Generating timer interrupt"); + } - if(which == 2) - { - if((m_dma[0].control & (TIMER_DRQ | ST_STOP)) == TIMER_DRQ) - drq_callback(0); - if((m_dma[1].control & (TIMER_DRQ | ST_STOP)) == TIMER_DRQ) - drq_callback(1); - if((m_timer[0].control & 0x800c) == 0x8008) - inc_timer(0); - if((m_timer[1].control & 0x800c) == 0x8008) - inc_timer(1); - } + if (which == 2) + { + if ((m_dma[0].control & (TIMER_DRQ | ST_STOP)) == TIMER_DRQ) + drq_callback(0); + if ((m_dma[1].control & (TIMER_DRQ | ST_STOP)) == TIMER_DRQ) + drq_callback(1); + if ((m_timer[0].control & 0x800c) == 0x8008) + inc_timer(0); + if ((m_timer[1].control & 0x800c) == 0x8008) + inc_timer(1); + } + else + { + if (!(t->control & 2)) + { + if (which) + m_out_tmrout1_func(1); else - { - if(!(t->control & 2)) - { - if(which) - m_out_tmrout1_func(1); - else - m_out_tmrout0_func(1); - } - else - { - if(which) - m_out_tmrout1_func((t->control & 0x1000) ? 1 : 0); - else - m_out_tmrout0_func((t->control & 0x1000) ? 1 : 0); - } - } - - /* if we're continuous or altcounting, reset */ - if((t->control & 1) || ((t->control & 2) && !(t->control & 0x1000))) - { - if((t->control & 2) && !(t->control & 0x1000)) - t->control |= 0x1000; - else - t->control &= ~0x1000; - - restart_timer(which); - if (LOG_TIMER) logerror(" Repriming interrupt\n"); - } + m_out_tmrout0_func(1); + } + else + { + if (which) + m_out_tmrout1_func((t->control & 0x1000) ? 1 : 0); else - { - t->int_timer->adjust(attotime::never, which); - t->control &= ~0x9000; - } - t->count = 0; - break; + m_out_tmrout0_func((t->control & 0x1000) ? 1 : 0); } + } - default: - break; + /* if we're continuous or altcounting, reset */ + if ((t->control & 1) || ((t->control & 2) && !(t->control & 0x1000))) + { + if ((t->control & 2) && !(t->control & 0x1000)) + t->control |= 0x1000; + else + t->control &= ~0x1000; + + restart_timer(which); + LOGMASKED(LOG_TIMER, " Repriming interrupt"); + } + else + { + t->int_timer->adjust(attotime::never, which); + t->control &= ~0x9000; } + t->count = 0; } @@ -1281,8 +1301,8 @@ void i80186_cpu_device::restart_timer(int which) { timer_state *t = &m_timer[which]; int count = (t->control & 0x1000) ? t->maxB : t->maxA; - if(!(t->control & 4)) - t->int_timer->adjust((attotime::from_hz(clock()/8) * (count ? count : 0x10000)), which); + if (!(t->control & 4)) + t->int_timer->adjust((attotime::from_hz(clock() / 8) * (count ? count : 0x10000)), which); } void i80186_cpu_device::internal_timer_sync(int which) @@ -1302,19 +1322,18 @@ void i80186_cpu_device::inc_timer(int which) if (t->control & 2) { if (t->count == ((t->control & 0x1000) ? t->maxB : t->maxA)) - device_timer(*t->int_timer, which, which); + timer_elapsed(which); } else if (t->count == t->maxA) - device_timer(*t->int_timer, which, which); + timer_elapsed(which); } void i80186_cpu_device::internal_timer_update(int which, int new_count, int new_maxA, int new_maxB, int new_control) { timer_state *t = &m_timer[which]; - int update_int_timer = 0; + bool update_int_timer = false; - if (LOG_TIMER) - logerror("internal_timer_update: %d, new_count=%d, new_maxA=%d, new_maxB=%d,new_control=%d\n", which, new_count, new_maxA, new_maxB, new_control); + LOGMASKED(LOG_TIMER, "internal_timer_update: %d, new_count=%d, new_maxA=%d, new_maxB=%d, new_control=%d", which, new_count, new_maxA, new_maxB, new_control); /* if we have a new count and we're on, update things */ if (new_count != -1) @@ -1322,7 +1341,7 @@ void i80186_cpu_device::internal_timer_update(int which, int new_count, int new_ if (t->control & 0x8000) { internal_timer_sync(which); - update_int_timer = 1; + update_int_timer = true; } t->count = new_count; } @@ -1333,7 +1352,7 @@ void i80186_cpu_device::internal_timer_update(int which, int new_count, int new_ if (t->control & 0x8000) { internal_timer_sync(which); - update_int_timer = 1; + update_int_timer = true; } t->maxA = new_maxA; @@ -1350,7 +1369,7 @@ void i80186_cpu_device::internal_timer_update(int which, int new_count, int new_ if (t->control & 0x8000) { internal_timer_sync(which); - update_int_timer = 1; + update_int_timer = true; } t->maxB = new_maxB; @@ -1383,20 +1402,20 @@ void i80186_cpu_device::internal_timer_update(int which, int new_count, int new_ { /* compute the final count */ internal_timer_sync(which); - update_int_timer = 1; + update_int_timer = true; } /* if we're going on, start the timers running except with external clock or prescale */ else if ((diff & 0x8000) && (new_control & 0x8000) && !(new_control & 0xc)) { - update_int_timer = 1; + update_int_timer = true; } /* if something about the interrupt timer changed, force an update */ if (!(diff & 0x8000) && (diff & 0x2000)) { internal_timer_sync(which); - update_int_timer = 1; + update_int_timer = true; } } @@ -1417,7 +1436,7 @@ void i80186_cpu_device::internal_timer_update(int which, int new_count, int new_ if (diff <= 0) diff += 0x10000; t->int_timer->adjust(attotime::from_hz(clock()/8) * diff, which); - if (LOG_TIMER) logerror("Set interrupt timer for %d\n", which); + LOGMASKED(LOG_TIMER, "Set interrupt timer for %d\n", which); } else { @@ -1437,7 +1456,7 @@ void i80186_cpu_device::external_tmrin(int which, int state) { m_timer[which].count = 0; restart_timer(which); - if (LOG_TIMER) logerror("Retriggered timer %d\n", which); + LOGMASKED(LOG_TIMER, "Retriggered timer %d\n", which); } } } @@ -1453,7 +1472,6 @@ void i80186_cpu_device::external_tmrin(int which, int state) void i80186_cpu_device::update_dma_control(int which, int new_control) { dma_state *d = &m_dma[which]; - int diff; /* handle the CHG bit */ if (!(new_control & CHG_NOCHG)) @@ -1461,11 +1479,11 @@ void i80186_cpu_device::update_dma_control(int which, int new_control) new_control &= ~CHG_NOCHG; /* check for control bits we don't handle */ - diff = new_control ^ d->control; - if ((LOG_DMA) && (diff & 0x6811)) - logerror("%05X:ERROR! - unsupported DMA mode %04X\n", m_pc, new_control); + int diff = new_control ^ d->control; + if (diff & 0x6811) + LOGMASKED(LOG_DMA, "%05X:ERROR! - unsupported DMA mode %04X\n", m_pc, new_control); - if (LOG_DMA) logerror("Initiated DMA %d - count = %04X, source = %04X, dest = %04X\n", which, d->count, d->source, d->dest); + LOGMASKED(LOG_DMA, "Initiated DMA %d - count = %04X, source = %04X, dest = %04X\n", which, d->count, d->source, d->dest); /* set the new control register */ d->control = new_control; @@ -1479,13 +1497,11 @@ void i80186_cpu_device::drq_callback(int which) uint8_t dma_byte; uint8_t incdec_size; - if (LOG_DMA>1) - logerror("Control=%04X, src=%05X, dest=%05X, count=%04X\n",dma->control,dma->source,dma->dest,dma->count); + LOGMASKED(LOG_DMA_HIFREQ, "Control=%04X, src=%05X, dest=%05X, count=%04X\n", dma->control, dma->source, dma->dest, dma->count); if (!(dma->control & ST_STOP)) { - if(LOG_DMA) - logerror("%05X:ERROR! - drq%d with dma channel stopped\n", m_pc, which); + LOGMASKED(LOG_DMA, "%05X:ERROR! - drq%d with dma channel stopped\n", m_pc, which); return; } @@ -1531,16 +1547,16 @@ void i80186_cpu_device::drq_callback(int which) dma->count -= 1; // Terminate if count is zero, and terminate flag set - if (((dma->control & TERMINATE_ON_ZERO) || !(dma->control & SYNC_MASK)) && (dma->count == 0)) + if (((dma->control & TERMINATE_ON_ZERO) || !(dma->control & SYNC_MASK)) && dma->count == 0) { dma->control &= ~ST_STOP; - if (LOG_DMA) logerror("DMA terminated\n"); + LOGMASKED(LOG_DMA, "DMA terminated\n"); } // Interrupt if count is zero, and interrupt flag set - if ((dma->control & INTERRUPT_ON_ZERO) && (dma->count == 0)) + if ((dma->control & INTERRUPT_ON_ZERO) && dma->count == 0) { - if (LOG_DMA>1) logerror("DMA%d - requesting interrupt: count = %04X, source = %04X\n", which, dma->count, dma->source); + LOGMASKED(LOG_DMA_HIFREQ, "DMA%d - requesting interrupt: count = %04X, source = %04X\n", which, dma->count, dma->source); m_intr.request |= 0x04 << which; update_interrupt_state(); } @@ -1553,25 +1569,25 @@ uint16_t i80186_cpu_device::internal_port_r(offs_t offset, uint16_t mem_mask) switch (offset) { case 0x10: - if (LOG_PORTS) logerror("%05X:read interrupt vector\n", m_pc); + LOGMASKED(LOG_PORTS, "%05X:read interrupt vector\n", m_pc); return m_intr.vector; case 0x11: - if (LOG_PORTS) logerror("%05X:ERROR - read from 80186 EOI\n", m_pc); + LOGMASKED(LOG_PORTS, "%05X:ERROR - read from 80186 EOI\n", m_pc); break; case 0x12: - if (LOG_PORTS) logerror("%05X:read 80186 interrupt poll\n", m_pc); + LOGMASKED(LOG_PORTS, "%05X:read 80186 interrupt poll\n", m_pc); if (m_intr.poll_status & 0x8000) inta_callback(*this, 0); return m_intr.poll_status; case 0x13: - if (LOG_PORTS) logerror("%05X:read 80186 interrupt poll status\n", m_pc); + LOGMASKED(LOG_PORTS, "%05X:read 80186 interrupt poll status\n", m_pc); return m_intr.poll_status; case 0x14: - if (LOG_PORTS) logerror("%05X:read 80186 interrupt mask\n", m_pc); + LOGMASKED(LOG_PORTS, "%05X:read 80186 interrupt mask\n", m_pc); temp = (m_intr.timer[0] >> 3) & 0x01; temp |= (m_intr.dma[0] >> 1) & 0x04; temp |= (m_intr.dma[1] >> 0) & 0x08; @@ -1590,59 +1606,59 @@ uint16_t i80186_cpu_device::internal_port_r(offs_t offset, uint16_t mem_mask) return temp; case 0x15: - if (LOG_PORTS) logerror("%05X:read 80186 interrupt priority mask\n", m_pc); + LOGMASKED(LOG_PORTS, "%05X:read 80186 interrupt priority mask\n", m_pc); return m_intr.priority_mask; case 0x16: - if (LOG_PORTS) logerror("%05X:read 80186 interrupt in-service\n", m_pc); + LOGMASKED(LOG_PORTS, "%05X:read 80186 interrupt in-service\n", m_pc); return m_intr.in_service; case 0x17: - if (LOG_PORTS) logerror("%05X:read 80186 interrupt request\n", m_pc); + LOGMASKED(LOG_PORTS, "%05X:read 80186 interrupt request\n", m_pc); temp = m_intr.request & ~0x0001; if (m_intr.status & 0x0007) temp |= 1; return temp; case 0x18: - if (LOG_PORTS) logerror("%05X:read 80186 interrupt status\n", m_pc); + LOGMASKED(LOG_PORTS, "%05X:read 80186 interrupt status\n", m_pc); return m_intr.status; case 0x19: - if (LOG_PORTS) logerror("%05X:read 80186 timer interrupt control\n", m_pc); + LOGMASKED(LOG_PORTS, "%05X:read 80186 timer interrupt control\n", m_pc); return m_intr.timer[0]; case 0x1a: - if (LOG_PORTS) logerror("%05X:read 80186 DMA 0 interrupt control\n", m_pc); + LOGMASKED(LOG_PORTS, "%05X:read 80186 DMA 0 interrupt control\n", m_pc); return m_intr.dma[0]; case 0x1b: - if (LOG_PORTS) logerror("%05X:read 80186 DMA 1 interrupt control\n", m_pc); + LOGMASKED(LOG_PORTS, "%05X:read 80186 DMA 1 interrupt control\n", m_pc); return m_intr.dma[1]; case 0x1c: - if (LOG_PORTS) logerror("%05X:read 80186 INT 0 interrupt control\n", m_pc); + LOGMASKED(LOG_PORTS, "%05X:read 80186 INT 0 interrupt control\n", m_pc); if (BIT(m_reloc, 14)) return m_intr.timer[1]; else return m_intr.ext[0]; case 0x1d: - if (LOG_PORTS) logerror("%05X:read 80186 INT 1 interrupt control\n", m_pc); + LOGMASKED(LOG_PORTS, "%05X:read 80186 INT 1 interrupt control\n", m_pc); if (BIT(m_reloc, 14)) return m_intr.timer[2]; else return m_intr.ext[1]; case 0x1e: - if (LOG_PORTS) logerror("%05X:read 80186 INT 2 interrupt control\n", m_pc); + LOGMASKED(LOG_PORTS, "%05X:read 80186 INT 2 interrupt control\n", m_pc); if (BIT(m_reloc, 14)) return 0; else return m_intr.ext[2]; case 0x1f: - if (LOG_PORTS) logerror("%05X:read 80186 INT 3 interrupt control\n", m_pc); + LOGMASKED(LOG_PORTS, "%05X:read 80186 INT 3 interrupt control\n", m_pc); if (BIT(m_reloc, 14)) return 0; else @@ -1651,7 +1667,7 @@ uint16_t i80186_cpu_device::internal_port_r(offs_t offset, uint16_t mem_mask) case 0x28: case 0x2c: case 0x30: - if (LOG_PORTS) logerror("%05X:read 80186 Timer %d count\n", m_pc, (offset - 0x28) / 4); + LOGMASKED(LOG_PORTS, "%05X:read 80186 Timer %d count\n", m_pc, (offset - 0x28) / 4); which = (offset - 0x28) / 4; if (ACCESSING_BITS_0_7) internal_timer_sync(which); @@ -1660,76 +1676,76 @@ uint16_t i80186_cpu_device::internal_port_r(offs_t offset, uint16_t mem_mask) case 0x29: case 0x2d: case 0x31: - if (LOG_PORTS) logerror("%05X:read 80186 Timer %d max A\n", m_pc, (offset - 0x29) / 4); + LOGMASKED(LOG_PORTS, "%05X:read 80186 Timer %d max A\n", m_pc, (offset - 0x29) / 4); which = (offset - 0x29) / 4; return m_timer[which].maxA; case 0x2a: case 0x2e: - if (LOG_PORTS) logerror("%05X:read 80186 Timer %d max B\n", m_pc, (offset - 0x2a) / 4); + LOGMASKED(LOG_PORTS, "%05X:read 80186 Timer %d max B\n", m_pc, (offset - 0x2a) / 4); which = (offset - 0x2a) / 4; return m_timer[which].maxB; case 0x2b: case 0x2f: case 0x33: - if (LOG_PORTS) logerror("%05X:read 80186 Timer %d control\n", m_pc, (offset - 0x2b) / 4); + LOGMASKED(LOG_PORTS, "%05X:read 80186 Timer %d control\n", m_pc, (offset - 0x2b) / 4); which = (offset - 0x2b) / 4; return m_timer[which].control; case 0x50: - if (LOG_PORTS) logerror("%05X:read 80186 upper chip select\n", m_pc); + LOGMASKED(LOG_PORTS, "%05X:read 80186 upper chip select\n", m_pc); return m_mem.upper; case 0x51: - if (LOG_PORTS) logerror("%05X:read 80186 lower chip select\n", m_pc); + LOGMASKED(LOG_PORTS, "%05X:read 80186 lower chip select\n", m_pc); return m_mem.lower; case 0x52: - if (LOG_PORTS) logerror("%05X:read 80186 peripheral chip select\n", m_pc); + LOGMASKED(LOG_PORTS, "%05X:read 80186 peripheral chip select\n", m_pc); return m_mem.peripheral; case 0x53: - if (LOG_PORTS) logerror("%05X:read 80186 middle chip select\n", m_pc); + LOGMASKED(LOG_PORTS, "%05X:read 80186 middle chip select\n", m_pc); return m_mem.middle; case 0x54: - if (LOG_PORTS) logerror("%05X:read 80186 middle P chip select\n", m_pc); + LOGMASKED(LOG_PORTS, "%05X:read 80186 middle P chip select\n", m_pc); return m_mem.middle_size; case 0x60: case 0x68: - if (LOG_PORTS) logerror("%05X:read 80186 DMA%d lower source address\n", m_pc, (offset - 0x60) / 8); + LOGMASKED(LOG_PORTS, "%05X:read 80186 DMA%d lower source address\n", m_pc, (offset - 0x60) / 8); which = (offset - 0x60) / 8; return m_dma[which].source; case 0x61: case 0x69: - if (LOG_PORTS) logerror("%05X:read 80186 DMA%d upper source address\n", m_pc, (offset - 0x61) / 8); + LOGMASKED(LOG_PORTS, "%05X:read 80186 DMA%d upper source address\n", m_pc, (offset - 0x61) / 8); which = (offset - 0x61) / 8; return m_dma[which].source >> 16; case 0x62: case 0x6a: - if (LOG_PORTS) logerror("%05X:read 80186 DMA%d lower dest address\n", m_pc, (offset - 0x62) / 8); + LOGMASKED(LOG_PORTS, "%05X:read 80186 DMA%d lower dest address\n", m_pc, (offset - 0x62) / 8); which = (offset - 0x62) / 8; return m_dma[which].dest; case 0x63: case 0x6b: - if (LOG_PORTS) logerror("%05X:read 80186 DMA%d upper dest address\n", m_pc, (offset - 0x63) / 8); + LOGMASKED(LOG_PORTS, "%05X:read 80186 DMA%d upper dest address\n", m_pc, (offset - 0x63) / 8); which = (offset - 0x63) / 8; return m_dma[which].dest >> 16; case 0x64: case 0x6c: - if (LOG_PORTS) logerror("%05X:read 80186 DMA%d transfer count\n", m_pc, (offset - 0x64) / 8); + LOGMASKED(LOG_PORTS, "%05X:read 80186 DMA%d transfer count\n", m_pc, (offset - 0x64) / 8); which = (offset - 0x64) / 8; return m_dma[which].count; case 0x65: case 0x6d: - if (LOG_PORTS) logerror("%05X:read 80186 DMA%d control\n", m_pc, (offset - 0x65) / 8); + LOGMASKED(LOG_PORTS, "%05X:read 80186 DMA%d control\n", m_pc, (offset - 0x65) / 8); which = (offset - 0x65) / 8; return m_dma[which].control; @@ -1737,7 +1753,7 @@ uint16_t i80186_cpu_device::internal_port_r(offs_t offset, uint16_t mem_mask) return m_reloc; default: - if (LOG_PORTS) logerror("%05X:read 80186 port %02X\n", m_pc, offset); + LOGMASKED(LOG_PORTS, "%05X:read 80186 port %02X\n", m_pc, offset); break; } @@ -1757,26 +1773,26 @@ void i80186_cpu_device::internal_port_w(offs_t offset, uint16_t data) switch (offset) { case 0x10: - if (LOG_PORTS) logerror("%05X:write interrupt vector = %04X\n", m_pc, data); + LOGMASKED(LOG_PORTS, "%05X:write interrupt vector = %04X\n", m_pc, data); m_intr.vector = data & 0xf8; break; case 0x11: - if (LOG_PORTS) logerror("%05X:80186 EOI = %04X\n", m_pc, data); + LOGMASKED(LOG_PORTS, "%05X:80186 EOI = %04X\n", m_pc, data); handle_eoi(data); update_interrupt_state(); break; case 0x12: - if (LOG_PORTS) logerror("%05X:ERROR - write to 80186 interrupt poll = %04X\n", m_pc, data); + LOGMASKED(LOG_PORTS, "%05X:ERROR - write to 80186 interrupt poll = %04X\n", m_pc, data); break; case 0x13: - if (LOG_PORTS) logerror("%05X:ERROR - write to 80186 interrupt poll status = %04X\n", m_pc, data); + LOGMASKED(LOG_PORTS, "%05X:ERROR - write to 80186 interrupt poll status = %04X\n", m_pc, data); break; case 0x14: - if (LOG_PORTS) logerror("%05X:80186 interrupt mask = %04X\n", m_pc, data); + LOGMASKED(LOG_PORTS, "%05X:80186 interrupt mask = %04X\n", m_pc, data); m_intr.timer[0] = (m_intr.timer[0] & ~0x08) | ((data << 3) & 0x08); m_intr.dma[0] = (m_intr.dma[0] & ~0x08) | ((data << 1) & 0x08); m_intr.dma[1] = (m_intr.dma[1] & ~0x08) | ((data << 0) & 0x08); @@ -1796,49 +1812,49 @@ void i80186_cpu_device::internal_port_w(offs_t offset, uint16_t data) break; case 0x15: - if (LOG_PORTS) logerror("%05X:80186 interrupt priority mask = %04X\n", m_pc, data); + LOGMASKED(LOG_PORTS, "%05X:80186 interrupt priority mask = %04X\n", m_pc, data); m_intr.priority_mask = data & 0x0007; update_interrupt_state(); break; case 0x16: - if (LOG_PORTS) logerror("%05X:80186 interrupt in-service = %04X\n", m_pc, data); + LOGMASKED(LOG_PORTS, "%05X:80186 interrupt in-service = %04X\n", m_pc, data); m_intr.in_service = data & 0x00ff; update_interrupt_state(); break; case 0x17: - if (LOG_PORTS) logerror("%05X:80186 interrupt request = %04X\n", m_pc, data); + LOGMASKED(LOG_PORTS, "%05X:80186 interrupt request = %04X\n", m_pc, data); m_intr.request = (m_intr.request & ~0x000c) | (data & 0x000c); update_interrupt_state(); break; case 0x18: - if (LOG_PORTS) logerror("%05X:WARNING - wrote to 80186 interrupt status = %04X\n", m_pc, data); + LOGMASKED(LOG_PORTS, "%05X:WARNING - wrote to 80186 interrupt status = %04X\n", m_pc, data); m_intr.status = (m_intr.status & ~0x8007) | (data & 0x8007); update_interrupt_state(); break; case 0x19: - if (LOG_PORTS) logerror("%05X:80186 timer interrupt contol = %04X\n", m_pc, data); + LOGMASKED(LOG_PORTS, "%05X:80186 timer interrupt contol = %04X\n", m_pc, data); m_intr.timer[0] = data & 0x000f; update_interrupt_state(); break; case 0x1a: - if (LOG_PORTS) logerror("%05X:80186 DMA 0 interrupt control = %04X\n", m_pc, data); + LOGMASKED(LOG_PORTS, "%05X:80186 DMA 0 interrupt control = %04X\n", m_pc, data); m_intr.dma[0] = data & 0x000f; update_interrupt_state(); break; case 0x1b: - if (LOG_PORTS) logerror("%05X:80186 DMA 1 interrupt control = %04X\n", m_pc, data); + LOGMASKED(LOG_PORTS, "%05X:80186 DMA 1 interrupt control = %04X\n", m_pc, data); m_intr.dma[1] = data & 0x000f; update_interrupt_state(); break; case 0x1c: - if (LOG_PORTS) logerror("%05X:80186 INT 0 interrupt control = %04X\n", m_pc, data); + LOGMASKED(LOG_PORTS, "%05X:80186 INT 0 interrupt control = %04X\n", m_pc, data); if (BIT(m_reloc, 14)) m_intr.timer[1] = data & 0x000f; else @@ -1847,7 +1863,7 @@ void i80186_cpu_device::internal_port_w(offs_t offset, uint16_t data) break; case 0x1d: - if (LOG_PORTS) logerror("%05X:80186 INT 1 interrupt control = %04X\n", m_pc, data); + LOGMASKED(LOG_PORTS, "%05X:80186 INT 1 interrupt control = %04X\n", m_pc, data); if (BIT(m_reloc, 14)) m_intr.timer[2] = data & 0x000f; else @@ -1856,14 +1872,14 @@ void i80186_cpu_device::internal_port_w(offs_t offset, uint16_t data) break; case 0x1e: - if (LOG_PORTS) logerror("%05X:80186 INT 2 interrupt control = %04X\n", m_pc, data); + LOGMASKED(LOG_PORTS, "%05X:80186 INT 2 interrupt control = %04X\n", m_pc, data); if (!BIT(m_reloc, 14)) m_intr.ext[2] = data & 0x001f; update_interrupt_state(); break; case 0x1f: - if (LOG_PORTS) logerror("%05X:80186 INT 3 interrupt control = %04X\n", m_pc, data); + LOGMASKED(LOG_PORTS, "%05X:80186 INT 3 interrupt control = %04X\n", m_pc, data); if (!BIT(m_reloc, 14)) m_intr.ext[3] = data & 0x001f; update_interrupt_state(); @@ -1872,7 +1888,7 @@ void i80186_cpu_device::internal_port_w(offs_t offset, uint16_t data) case 0x28: case 0x2c: case 0x30: - if (LOG_PORTS) logerror("%05X:80186 Timer %d count = %04X\n", m_pc, (offset - 0x28) / 4, data); + LOGMASKED(LOG_PORTS, "%05X:80186 Timer %d count = %04X\n", m_pc, (offset - 0x28) / 4, data); which = (offset - 0x28) / 4; internal_timer_update(which, data, -1, -1, -1); break; @@ -1880,14 +1896,14 @@ void i80186_cpu_device::internal_port_w(offs_t offset, uint16_t data) case 0x29: case 0x2d: case 0x31: - if (LOG_PORTS) logerror("%05X:80186 Timer %d max A = %04X\n", m_pc, (offset - 0x29) / 4, data); + LOGMASKED(LOG_PORTS, "%05X:80186 Timer %d max A = %04X\n", m_pc, (offset - 0x29) / 4, data); which = (offset - 0x29) / 4; internal_timer_update(which, -1, data, -1, -1); break; case 0x2a: case 0x2e: - if (LOG_PORTS) logerror("%05X:80186 Timer %d max B = %04X\n", m_pc, (offset - 0x2a) / 4, data); + LOGMASKED(LOG_PORTS, "%05X:80186 Timer %d max B = %04X\n", m_pc, (offset - 0x2a) / 4, data); which = (offset - 0x2a) / 4; internal_timer_update(which, -1, -1, data, -1); break; @@ -1895,79 +1911,79 @@ void i80186_cpu_device::internal_port_w(offs_t offset, uint16_t data) case 0x2b: case 0x2f: case 0x33: - if (LOG_PORTS) logerror("%05X:80186 Timer %d control = %04X\n", m_pc, (offset - 0x2b) / 4, data); + LOGMASKED(LOG_PORTS, "%05X:80186 Timer %d control = %04X\n", m_pc, (offset - 0x2b) / 4, data); which = (offset - 0x2b) / 4; internal_timer_update(which, -1, -1, -1, data); break; case 0x50: - if (LOG_PORTS) logerror("%05X:80186 upper chip select = %04X\n", m_pc, data); + LOGMASKED(LOG_PORTS, "%05X:80186 upper chip select = %04X\n", m_pc, data); m_mem.upper = data | 0xc038; m_out_chip_select_func(0, m_mem.upper, 0xffff); break; case 0x51: - if (LOG_PORTS) logerror("%05X:80186 lower chip select = %04X\n", m_pc, data); + LOGMASKED(LOG_PORTS, "%05X:80186 lower chip select = %04X\n", m_pc, data); m_mem.lower = (data & 0x3fff) | 0x0038; m_out_chip_select_func(1, m_mem.lower, 0xffff); break; case 0x52: - if (LOG_PORTS) logerror("%05X:80186 peripheral chip select = %04X\n", m_pc, data); + LOGMASKED(LOG_PORTS, "%05X:80186 peripheral chip select = %04X\n", m_pc, data); m_mem.peripheral = data | 0x0038; m_out_chip_select_func(2, m_mem.peripheral, 0xffff); break; case 0x53: - if (LOG_PORTS) logerror("%05X:80186 middle chip select = %04X\n", m_pc, data); + LOGMASKED(LOG_PORTS, "%05X:80186 middle chip select = %04X\n", m_pc, data); m_mem.middle = data | 0x01f8; m_out_chip_select_func(3, m_mem.middle, 0xffff); break; case 0x54: - if (LOG_PORTS) logerror("%05X:80186 middle P chip select = %04X\n", m_pc, data); + LOGMASKED(LOG_PORTS, "%05X:80186 middle P chip select = %04X\n", m_pc, data); m_mem.middle_size = data | 0x8038; m_out_chip_select_func(4, m_mem.middle_size, 0xffff); break; case 0x60: case 0x68: - if (LOG_PORTS) logerror("%05X:80186 DMA%d lower source address = %04X\n", m_pc, (offset - 0x60) / 8, data); + LOGMASKED(LOG_PORTS, "%05X:80186 DMA%d lower source address = %04X\n", m_pc, (offset - 0x60) / 8, data); which = (offset - 0x60) / 8; m_dma[which].source = (m_dma[which].source & ~0x0ffff) | (data & 0x0ffff); break; case 0x61: case 0x69: - if (LOG_PORTS) logerror("%05X:80186 DMA%d upper source address = %04X\n", m_pc, (offset - 0x61) / 8, data); + LOGMASKED(LOG_PORTS, "%05X:80186 DMA%d upper source address = %04X\n", m_pc, (offset - 0x61) / 8, data); which = (offset - 0x61) / 8; m_dma[which].source = (m_dma[which].source & ~0xf0000) | ((data << 16) & 0xf0000); break; case 0x62: case 0x6a: - if (LOG_PORTS) logerror("%05X:80186 DMA%d lower dest address = %04X\n", m_pc, (offset - 0x62) / 8, data); + LOGMASKED(LOG_PORTS, "%05X:80186 DMA%d lower dest address = %04X\n", m_pc, (offset - 0x62) / 8, data); which = (offset - 0x62) / 8; m_dma[which].dest = (m_dma[which].dest & ~0x0ffff) | (data & 0x0ffff); break; case 0x63: case 0x6b: - if (LOG_PORTS) logerror("%05X:80186 DMA%d upper dest address = %04X\n", m_pc, (offset - 0x63) / 8, data); + LOGMASKED(LOG_PORTS, "%05X:80186 DMA%d upper dest address = %04X\n", m_pc, (offset - 0x63) / 8, data); which = (offset - 0x63) / 8; m_dma[which].dest = (m_dma[which].dest & ~0xf0000) | ((data << 16) & 0xf0000); break; case 0x64: case 0x6c: - if (LOG_PORTS) logerror("%05X:80186 DMA%d transfer count = %04X\n", m_pc, (offset - 0x64) / 8, data); + LOGMASKED(LOG_PORTS, "%05X:80186 DMA%d transfer count = %04X\n", m_pc, (offset - 0x64) / 8, data); which = (offset - 0x64) / 8; m_dma[which].count = data; break; case 0x65: case 0x6d: - if (LOG_PORTS) logerror("%05X:80186 DMA%d control = %04X\n", m_pc, (offset - 0x65) / 8, data); + LOGMASKED(LOG_PORTS, "%05X:80186 DMA%d control = %04X\n", m_pc, (offset - 0x65) / 8, data); which = (offset - 0x65) / 8; update_dma_control(which, data); if((m_dma[which].control & (SYNC_MASK | ST_STOP | TIMER_DRQ)) == ST_STOP) @@ -1980,12 +1996,12 @@ void i80186_cpu_device::internal_port_w(offs_t offset, uint16_t data) case 0x7f: // 80188 byte output to this port is *not* masked! - if (LOG_PORTS) logerror("%05X:80186 relocation register = %04X\n", m_pc, data); + LOGMASKED(LOG_PORTS, "%05X:80186 relocation register = %04X\n", m_pc, data); m_reloc = data; break; default: - if (LOG_PORTS) logerror("%05X:80186 port %02X = %04X\n", m_pc, offset, data); + LOGMASKED(LOG_PORTS, "%05X:80186 port %02X = %04X\n", m_pc, offset, data); break; } } diff --git a/src/devices/cpu/i86/i186.h b/src/devices/cpu/i86/i186.h index 5d43d2a660e..47f258f74e4 100644 --- a/src/devices/cpu/i86/i186.h +++ b/src/devices/cpu/i86/i186.h @@ -65,7 +65,6 @@ protected: virtual void execute_run() 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 uint32_t execute_input_lines() const noexcept override { return 1; } virtual uint8_t fetch() override; uint32_t update_pc() { return m_pc = (m_sregs[CS] << 4) + m_ip; } @@ -96,6 +95,8 @@ private: uint16_t internal_port_r(offs_t offset, uint16_t mem_mask = ~0); void internal_port_w(offs_t offset, uint16_t data); + TIMER_CALLBACK_MEMBER(timer_elapsed); + struct mem_state { uint16_t lower; @@ -145,10 +146,6 @@ private: mem_state m_mem; bool m_last_dma; - static const device_timer_id TIMER_INT0 = 0; - static const device_timer_id TIMER_INT1 = 1; - static const device_timer_id TIMER_INT2 = 2; - uint16_t m_reloc; address_space_config m_program_config; diff --git a/src/devices/cpu/lc8670/lc8670.cpp b/src/devices/cpu/lc8670/lc8670.cpp index a4d038e3bf1..613d6495881 100644 --- a/src/devices/cpu/lc8670/lc8670.cpp +++ b/src/devices/cpu/lc8670/lc8670.cpp @@ -19,12 +19,11 @@ #include "lc8670.h" #include "lc8670dsm.h" -//*************************************************************************** -// DEBUGGING -//*************************************************************************** +#define LOG_TIMERS (1U << 1) +#define LOG_IRQ (1U << 2) -#define LOG_TIMERS 0 -#define LOG_IRQ 0 +#define VERBOSE (0) +#include "logmacro.h" //************************************************************************** @@ -206,9 +205,9 @@ void lc8670_cpu_device::device_start() m_lcd_update_func.resolve(); // setup timers - m_basetimer = timer_alloc(BASE_TIMER); + m_basetimer = timer_alloc(FUNC(lc8670_cpu_device::base_timer_update), this); m_basetimer->adjust(attotime::from_hz(m_clocks[unsigned(clock_source::SUB)]), 0, attotime::from_hz(m_clocks[unsigned(clock_source::SUB)])); - m_clocktimer = timer_alloc(CLOCK_TIMER); + m_clocktimer = timer_alloc(FUNC(lc8670_cpu_device::clock_timer_update), this); // register state for debugger state_add(LC8670_PC , "PC" , m_pc).callimport().callexport().formatstr("%04X"); @@ -328,26 +327,27 @@ void lc8670_cpu_device::device_reset() //------------------------------------------------- -// device_timer - handler timer events +// base_timer_update //------------------------------------------------- -void lc8670_cpu_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(lc8670_cpu_device::base_timer_update) { - switch(id) - { - case BASE_TIMER: - if (!(REG_ISL & 0x10)) - base_timer_tick(); - break; + if (!(REG_ISL & 0x10)) + base_timer_tick(); +} - case CLOCK_TIMER: - timer0_prescaler_tick(); - timer1_tick(); - if ((REG_ISL & 0x30) == 0x10) - base_timer_tick(); - break; - } +//------------------------------------------------- +// clock_timer_update +//------------------------------------------------- + +TIMER_CALLBACK_MEMBER(lc8670_cpu_device::clock_timer_update) +{ + timer0_prescaler_tick(); + timer1_tick(); + + if ((REG_ISL & 0x30) == 0x10) + base_timer_tick(); } @@ -454,7 +454,7 @@ void lc8670_cpu_device::execute_run() void lc8670_cpu_device::execute_set_input(int inputnum, int state) { - switch(inputnum) + switch (inputnum) { case LC8670_EXT_INT0: if ((REG_I01CR & 0x0c) == 0x00 && m_input_lines[inputnum] && !state) // falling edge @@ -595,13 +595,15 @@ void lc8670_cpu_device::check_irqs() // high priority IRQ else if ((REG_IE & 0x80) && ((REG_IP<<3) & m_irq_flag)) { - for(int i=3; i<=10; i++) - if ((m_irq_flag & (REG_IP<<3)) & (1<<i)) + for(int i = 3; i <= 10; i++) + { + if (BIT(m_irq_flag & (REG_IP << 3), i)) { irq = i; priority = 1; break; } + } } // low priority IRQ @@ -617,37 +619,39 @@ void lc8670_cpu_device::check_irqs() } else if (REG_IE & 0x80) { - for(int i=3; i<=10; i++) - if (m_irq_flag & (1<<i)) + for(int i = 3; i <= 10; i++) + { + if (BIT(m_irq_flag, i)) { irq = i; priority = 0; break; } + } } // IRQ with less priority of current interrupt are not executed until the end of the current interrupt routine if (irq != 0 && ((m_irq_lev & (1<<priority)) || (priority == 0 && (m_irq_lev & 0x06)) || (priority == 1 && (m_irq_lev & 0x04)))) { - if (LOG_IRQ) logerror("%s: interrupt %d (Priority=%d, Level=%d) delayed\n", tag(), irq, priority, m_irq_lev); + LOGMASKED(LOG_IRQ, "%s: interrupt %d (Priority=%d, Level=%d) delayed\n", tag(), irq, priority, m_irq_lev); irq = 0; } if (irq != 0) { - if (LOG_IRQ) logerror("%s: interrupt %d (Priority=%d, Level=%d) executed\n", tag(), irq, priority, m_irq_lev); + LOGMASKED(LOG_IRQ, "%s: interrupt %d (Priority=%d, Level=%d) executed\n", tag(), irq, priority, m_irq_lev); - m_irq_lev |= (1<<priority); + m_irq_lev |= (1 << priority); - push((m_pc>>0) & 0xff); - push((m_pc>>8) & 0xff); + push((uint8_t)m_pc); + push((uint8_t)(m_pc >> 8)); set_pc(s_irq_vectors[irq]); REG_PCON &= ~HALT_MODE; // interrupts resume from HALT state // clear the IRQ flag - m_irq_flag &= ~(1<<irq); + m_irq_flag &= ~(1 << irq); standard_irq_callback(irq); } @@ -676,14 +680,14 @@ void lc8670_cpu_device::base_timer_tick() if (base_counter_h & 0x40) { - if (LOG_TIMERS) logerror("%s: base timer 0 overflow, IRQ: %d\n", tag(), BIT(REG_BTCR,0)); + LOGMASKED(LOG_TIMERS, "%s: base timer 0 overflow, IRQ: %d\n", tag(), BIT(REG_BTCR, 0)); REG_BTCR |= 0x02; if (REG_BTCR & 0x01) set_irq_flag(4); } bool bt1_req = false; - switch(REG_BTCR & 0x30) + switch (REG_BTCR & 0x30) { case 0x00: if (base_counter_l & 0x20) @@ -705,7 +709,7 @@ void lc8670_cpu_device::base_timer_tick() if (bt1_req) { - if (LOG_TIMERS) logerror("%s: base timer 1 overflow, IRQ: %d\n", tag(), BIT(REG_BTCR,3)); + LOGMASKED(LOG_TIMERS, "%s: base timer 1 overflow, IRQ: %d\n", tag(), BIT(REG_BTCR, 3)); REG_BTCR |= 0x08; if (REG_BTCR & 0x04) set_irq_flag(4); @@ -716,7 +720,7 @@ void lc8670_cpu_device::base_timer_tick() else update_port1(m_p1_data & 0xbf); - m_base_timer[0] = base_counter_l & 0xff; + m_base_timer[0] = (uint8_t)base_counter_l; m_base_timer[1] = base_counter_h & 0x3f; } } @@ -730,7 +734,7 @@ void lc8670_cpu_device::timer0_prescaler_tick() uint16_t prescaler = m_timer0_prescaler + 1; if (prescaler & 0x100) { - if (LOG_TIMERS) logerror("%s: timer0 prescaler overflow\n", tag()); + LOGMASKED(LOG_TIMERS, "%s: timer0 prescaler overflow\n", tag()); if ((REG_ISL & 0x30) == 0x30) base_timer_tick(); @@ -741,7 +745,7 @@ void lc8670_cpu_device::timer0_prescaler_tick() } else { - m_timer0_prescaler = prescaler & 0xff; + m_timer0_prescaler = (uint8_t)prescaler; } } @@ -762,7 +766,7 @@ void lc8670_cpu_device::timer0_tick(bool ext_line) if (timer0 & 0x10000) { - if (LOG_TIMERS) logerror("%s: timer0 long overflow, IRQ: %d\n", tag(), BIT(REG_T0CNT,3)); + LOGMASKED(LOG_TIMERS, "%s: timer0 long overflow, IRQ: %d\n", tag(), BIT(REG_T0CNT, 3)); m_timer0[0] = REG_T0LR; m_timer0[1] = REG_T0HR; REG_T0CNT |= 0x0a; @@ -771,8 +775,8 @@ void lc8670_cpu_device::timer0_tick(bool ext_line) } else { - m_timer0[0] = (timer0>>0) & 0xff; - m_timer0[1] = (timer0>>8) & 0xff; + m_timer0[0] = (uint8_t)timer0; + m_timer0[1] = (uint8_t)(timer0 >> 8); } } } @@ -785,7 +789,7 @@ void lc8670_cpu_device::timer0_tick(bool ext_line) if (timer0l & 0x100) { - if (LOG_TIMERS) logerror("%s: timer0 low overflow, IRQ: %d\n", tag(), BIT(REG_T0CNT,0)); + LOGMASKED(LOG_TIMERS, "%s: timer0 low overflow, IRQ: %d\n", tag(), BIT(REG_T0CNT, 0)); m_timer0[0] = REG_T0LR; REG_T0CNT |= 0x02; if (REG_T0CNT & 0x01) @@ -793,15 +797,15 @@ void lc8670_cpu_device::timer0_tick(bool ext_line) } else { - m_timer0[0] = timer0l & 0xff; + m_timer0[0] = (uint8_t)timer0l; } } - if ((REG_T0CNT & 0x80) && !ext_line) + if ((REG_T0CNT & 0x80) && !ext_line) { uint16_t timer0h = m_timer0[1] + 1; if (timer0h & 0x100) { - if (LOG_TIMERS) logerror("%s: timer0 high overflow, IRQ: %d\n", tag(), BIT(REG_T0CNT,3)); + LOGMASKED(LOG_TIMERS, "%s: timer0 high overflow, IRQ: %d\n", tag(), BIT(REG_T0CNT,3)); m_timer0[1] = REG_T0HR; REG_T0CNT |= 0x08; if (REG_T0CNT & 0x04) @@ -809,7 +813,7 @@ void lc8670_cpu_device::timer0_tick(bool ext_line) } else { - m_timer0[1] = timer0h & 0xff; + m_timer0[1] = (uint8_t)timer0h; } } } @@ -838,7 +842,7 @@ void lc8670_cpu_device::timer1_tick() if (timer1h & 0x100) { - if (LOG_TIMERS) logerror("%s: timer1 long overflow, IRQ: %d\n", tag(), BIT(REG_T1CNT,3)); + LOGMASKED(LOG_TIMERS, "%s: timer1 long overflow, IRQ: %d\n", tag(), BIT(REG_T1CNT, 3)); m_timer1[1] = REG_T1HR; REG_T1CNT |= 0x08; if (REG_T1CNT & 0x05) @@ -846,12 +850,12 @@ void lc8670_cpu_device::timer1_tick() } else { - m_timer1[1] = timer1h & 0xff; + m_timer1[1] = (uint8_t)timer1h; } } else { - m_timer1[0] = timer1l & 0xff; + m_timer1[0] = (uint8_t)timer1l; } } } @@ -867,7 +871,7 @@ void lc8670_cpu_device::timer1_tick() if (timer1l & 0x100) { - if (LOG_TIMERS) logerror("%s: timer1 low overflow, IRQ: %d\n", tag(), BIT(REG_T1CNT,0)); + LOGMASKED(LOG_TIMERS, "%s: timer1 low overflow, IRQ: %d\n", tag(), BIT(REG_T1CNT, 0)); m_timer1[0] = REG_T1LR; update_port1(m_p1_data & 0x7f); REG_T1CNT |= 0x02; @@ -876,7 +880,7 @@ void lc8670_cpu_device::timer1_tick() } else { - m_timer1[0] = timer1l & 0xff; + m_timer1[0] = (uint8_t)timer1l; } } if (REG_T1CNT & 0x80) @@ -885,7 +889,7 @@ void lc8670_cpu_device::timer1_tick() if (timer1h & 0x100) { - if (LOG_TIMERS) logerror("%s: timer1 high overflow, IRQ: %d\n", tag(), BIT(REG_T1CNT,3)); + LOGMASKED(LOG_TIMERS, "%s: timer1 high overflow, IRQ: %d\n", tag(), BIT(REG_T1CNT, 3)); m_timer1[1] = REG_T1HR; REG_T1CNT |= 0x08; if (REG_T1CNT & 0x04) @@ -893,7 +897,7 @@ void lc8670_cpu_device::timer1_tick() } else { - m_timer1[1] = timer1h & 0xff; + m_timer1[1] = (uint8_t)timer1h; } } } @@ -907,26 +911,26 @@ void lc8670_cpu_device::timer1_tick() uint8_t lc8670_cpu_device::mram_r(offs_t offset) { - return m_mram[BIT(REG_PSW,1)*0x100 + offset]; + return m_mram[(BIT(REG_PSW, 1) << 8) + offset]; } void lc8670_cpu_device::mram_w(offs_t offset, uint8_t data) { - m_mram[BIT(REG_PSW,1)*0x100 + offset] = data; + m_mram[(BIT(REG_PSW, 1) << 8) + offset] = data; } uint8_t lc8670_cpu_device::xram_r(offs_t offset) { if (!(REG_VCCR & 0x40) || machine().side_effects_disabled()) // XRAM access enabled { - uint8_t * xram_bank = m_xram + (REG_XBNK & 0x03) * 0x60; + uint8_t *xram_bank = m_xram + (REG_XBNK & 0x03) * 0x60; - switch(REG_XBNK & 0x03) + switch (REG_XBNK & 0x03) { case 0: case 1: if ((offset & 0x0f) < 0x0c) - return xram_bank[(offset>>4) * 0x0c + (offset & 0x0f)]; + return xram_bank[(offset >> 4) * 0x0c + (offset & 0x0f)]; break; case 2: if (offset < 0x06) @@ -942,14 +946,14 @@ void lc8670_cpu_device::xram_w(offs_t offset, uint8_t data) { if (!(REG_VCCR & 0x40) || machine().side_effects_disabled()) // XRAM access enabled { - uint8_t * xram_bank = m_xram + (REG_XBNK & 0x03) * 0x60; + uint8_t *xram_bank = m_xram + (REG_XBNK & 0x03) * 0x60; switch(REG_XBNK & 0x03) { case 0: case 1: if ((offset & 0x0f) < 0x0c) - xram_bank[(offset>>4) * 0x0c + (offset & 0x0f)] = data; + xram_bank[(offset >> 4) * 0x0c + (offset & 0x0f)] = data; break; case 2: if (offset < 0x06) @@ -979,12 +983,12 @@ uint8_t lc8670_cpu_device::regs_r(offs_t offset) return m_io.read_byte(LC8670_PORT7) | 0xf0; // 4-bit read-only port case 0x66: { - uint8_t data = m_vtrbf[((REG_VRMAD2<<8) | REG_VRMAD1) & 0x1ff]; + uint8_t data = m_vtrbf[((REG_VRMAD2 << 8) | REG_VRMAD1) & 0x1ff]; if (!machine().side_effects_disabled() && (REG_VSEL & 0x10)) { - uint16_t vrmad = (REG_VRMAD1 | (REG_VRMAD2<<8)) + 1; - REG_VRMAD1 = vrmad & 0xff; - REG_VRMAD2 = (vrmad >> 8) & 0x01; + uint16_t vrmad = ((REG_VRMAD1 | (REG_VRMAD2 << 8)) + 1) & 0x1ff; + REG_VRMAD1 = (uint8_t)vrmad; + REG_VRMAD2 = (uint8_t)(vrmad >> 8); } return data; } @@ -1049,9 +1053,9 @@ void lc8670_cpu_device::regs_w(offs_t offset, uint8_t data) m_vtrbf[((REG_VRMAD2<<8) | REG_VRMAD1) & 0x1ff] = data; if (!machine().side_effects_disabled() && (REG_VSEL & 0x10)) { - uint16_t vrmad = (REG_VRMAD1 | (REG_VRMAD2<<8)) + 1; - REG_VRMAD1 = vrmad & 0xff; - REG_VRMAD2 = (vrmad >> 8) & 0x01; + uint16_t vrmad = ((REG_VRMAD1 | (REG_VRMAD2 << 8)) + 1) & 0x1ff; + REG_VRMAD1 = (uint8_t)vrmad; + REG_VRMAD2 = (uint8_t)(vrmad >> 8); } break; case 0x7f: @@ -1144,7 +1148,7 @@ inline uint16_t lc8670_cpu_device::get_addr() if (mode > 0x01 && mode <= 0x03) addr = GET_D9; else if (mode > 0x03 && mode <= 0x07) - addr = read_data(GET_RI | ((REG_PSW>>1) & 0x0c)) | ((GET_RI & 0x02) ? 0x100 : 0x00); + addr = read_data(GET_RI | ((REG_PSW >> 1) & 0x0c)) | ((GET_RI & 0x02) ? 0x100 : 0x00); else fatalerror("%s: invalid get_addr in mode %x\n", machine().describe_context().c_str(), mode); @@ -1191,7 +1195,7 @@ inline void lc8670_cpu_device::change_clock_source() inline void lc8670_cpu_device::check_p_flag() { uint8_t p_plag = 0; - for(int i=0; i<8; i++) + for(int i = 0; i < 8; i++) p_plag ^= BIT(REG_A, i); if (p_plag) @@ -1215,8 +1219,8 @@ inline void lc8670_cpu_device::check_p3int() inline void lc8670_cpu_device::set_irq_flag(int source) { - if (LOG_IRQ) logerror("%s: set interrupt flag: %d\n", tag(), source); - m_irq_flag |= 1<<source; + LOGMASKED(LOG_IRQ, "%s: set interrupt flag: %d\n", tag(), source); + m_irq_flag |= 1 << source; } int lc8670_cpu_device::decode_op(uint8_t op) @@ -1238,7 +1242,7 @@ int lc8670_cpu_device::decode_op(uint8_t op) break; } - return ((op>>4) & 0x0f) * 5 + idx; + return (op >> 4) * 5 + idx; } //************************************************************************** @@ -1270,8 +1274,8 @@ int lc8670_cpu_device::op_call() { uint16_t new_pc = GET_A12; - push((m_pc>>0) & 0xff); - push((m_pc>>8) & 0xff); + push((uint8_t)m_pc); + push((uint8_t)(m_pc >> 8)); set_pc((m_pc & 0xf000) | new_pc); @@ -1282,10 +1286,10 @@ int lc8670_cpu_device::op_call() int lc8670_cpu_device::op_callr() { uint16_t r16 = fetch(); - r16 |= fetch()<<8; + r16 |= fetch() << 8; - push((m_pc>>0) & 0xff); - push((m_pc>>8) & 0xff); + push((uint8_t)m_pc); + push((uint8_t)(m_pc >> 8)); set_pc(m_pc - 1 + r16); return 4; @@ -1294,7 +1298,7 @@ int lc8670_cpu_device::op_callr() int lc8670_cpu_device::op_brf() { uint16_t r16 = fetch(); - r16 |= fetch()<<8; + r16 |= fetch() << 8; set_pc(m_pc - 1 + r16); return 4; @@ -1309,11 +1313,11 @@ int lc8670_cpu_device::op_st() int lc8670_cpu_device::op_callf() { - uint16_t a16 = fetch()<<8; + uint16_t a16 = fetch() << 8; a16 |= fetch(); - push((m_pc>>0) & 0xff); - push((m_pc>>8) & 0xff); + push((uint8_t)m_pc); + push((uint8_t)(m_pc >> 8)); set_pc(a16); return 2; @@ -1321,7 +1325,7 @@ int lc8670_cpu_device::op_callf() int lc8670_cpu_device::op_jmpf() { - uint16_t a16 = fetch()<<8; + uint16_t a16 = fetch() << 8; a16 |= fetch(); set_pc(a16); @@ -1349,11 +1353,11 @@ int lc8670_cpu_device::op_jmp() int lc8670_cpu_device::op_mul() { - uint32_t res = REG_B * ((REG_A<<8) | REG_C); + uint32_t res = REG_B * ((REG_A << 8) | REG_C); - REG_A = (res>>8) & 0xff; - REG_B = (res>>16) & 0xff; - REG_C = (res>>0) & 0xff; + REG_A = (uint8_t)(res >> 8); + REG_B = (uint8_t)(res >> 16); + REG_C = (uint8_t)res; SET_OV(REG_B != 0 ? 1 : 0); SET_CY(0); @@ -1396,13 +1400,13 @@ int lc8670_cpu_device::op_div() if (REG_B != 0) { - uint16_t v = ((REG_A<<8) | REG_C); + uint16_t v = ((REG_A << 8) | REG_C); res = v / REG_B; mod = v % REG_B; - REG_A = (res>>8) & 0xff; - REG_C = (res>>0) & 0xff; - REG_B = mod & 0xff; + REG_A = (uint8_t)(res >> 8); + REG_C = (uint8_t)res; + REG_B = (uint8_t)mod; SET_OV(0); } else @@ -1446,7 +1450,7 @@ int lc8670_cpu_device::op_bne_ri() int lc8670_cpu_device::op_ldf() { - uint16_t addr = REG_TRL | (REG_TRH<<8); + uint16_t addr = REG_TRL | (REG_TRH << 8); m_bankswitch_func(REG_FPR & 0x01 ? 2 : 1); REG_A = m_program.read_byte(addr); @@ -1458,7 +1462,7 @@ int lc8670_cpu_device::op_ldf() int lc8670_cpu_device::op_stf() { - uint16_t addr = REG_TRL | (REG_TRH<<8); + uint16_t addr = REG_TRL | (REG_TRH << 8); m_bankswitch_func(REG_FPR & 0x01 ? 2 : 1); m_program.write_byte(addr, REG_A); @@ -1488,9 +1492,9 @@ int lc8670_cpu_device::op_bpc() uint8_t r8 = GET_R8; uint8_t data = read_data_latch(d9); - if (data & (1<<b3)) + if (BIT(data, b3)) { - write_data_latch(d9, data & ~(1<<b3)); + write_data_latch(d9, data & ~(1 << b3)); set_pc(m_pc + SIGNED(r8)); } @@ -1521,7 +1525,7 @@ int lc8670_cpu_device::op_bp() uint16_t d9 = GET_D9B3; uint8_t r8 = GET_R8; - if (read_data(d9) & (1<<b3)) + if (BIT(read_data(d9), b3)) set_pc(m_pc + SIGNED(r8)); return 2; @@ -1564,7 +1568,7 @@ int lc8670_cpu_device::op_add() SET_AC(((REG_A & 0x0f) + (data & 0x0f)) > 0x0f ? 1 : 0); SET_OV((REG_A & data) & (data ^ res) & 0x80 ? 1 : 0); - REG_A = res & 0xff; + REG_A = (uint8_t)res; CHECK_P(); return 1; @@ -1576,7 +1580,7 @@ int lc8670_cpu_device::op_bn() uint16_t d9 = GET_D9B3; uint8_t r8 = GET_R8; - if (!(read_data(d9) & (1<<b3))) + if (!BIT(read_data(d9), b3)) set_pc(m_pc + SIGNED(r8)); return 2; @@ -1599,7 +1603,7 @@ int lc8670_cpu_device::op_addc() SET_CY(res > 0xff ? 1 : 0); SET_AC(((REG_A & 0x0f) + (data & 0x0f) + GET_CY) > 0x0f ? 1 : 0); - SET_OV(((REG_A+GET_CY) & data) & (data ^ res) & 0x80 ? 1 : 0); + SET_OV(((REG_A + GET_CY) & data) & (data ^ res) & 0x80 ? 1 : 0); REG_A = res & 0xff; CHECK_P(); @@ -1609,7 +1613,7 @@ int lc8670_cpu_device::op_addc() int lc8670_cpu_device::op_ret() { - uint16_t new_pc = pop()<<8; + uint16_t new_pc = pop() << 8; new_pc |= pop(); set_pc(new_pc); @@ -1625,7 +1629,7 @@ int lc8670_cpu_device::op_sub() SET_AC(((REG_A & 0x0f) - (data & 0x0f)) < 0x00 ? 1 : 0); SET_OV((REG_A ^ data) & (data & res) & 0x80 ? 1 : 0); - REG_A = res & 0xff; + REG_A = (uint8_t)res; CHECK_P(); return 1; @@ -1636,7 +1640,7 @@ int lc8670_cpu_device::op_not1() uint16_t d9 = GET_D9B3; uint8_t data = read_data_latch(d9); - data ^= (1<<GET_B3); + data ^= (1 << GET_B3); write_data_latch(d9, data); return 1; @@ -1644,17 +1648,19 @@ int lc8670_cpu_device::op_not1() int lc8670_cpu_device::op_reti() { - uint16_t new_pc = pop()<<8; + uint16_t new_pc = pop() << 8; new_pc |= pop(); set_pc(new_pc); - if (LOG_IRQ) logerror("%s: RETI from level %d\n", machine().describe_context(), m_irq_lev); - for(int i=2; i>=0; i--) - if (m_irq_lev & (1<<i)) + LOGMASKED(LOG_IRQ, "%s: RETI from level %d\n", machine().describe_context(), m_irq_lev); + for(int i = 2; i >= 0; i--) + { + if (BIT(m_irq_lev, i)) { - m_irq_lev &= ~(1<<i); + m_irq_lev &= ~(1 << i); break; } + } m_after_reti = true; @@ -1670,7 +1676,7 @@ int lc8670_cpu_device::op_subc() SET_AC(((REG_A & 0x0f) - (data & 0x0f) - GET_CY) < 0x00 ? 1 : 0); SET_OV((REG_A ^ (data + GET_CY)) & (data & res) & 0x80 ? 1 : 0); - REG_A = res & 0xff; + REG_A = (uint8_t)res; CHECK_P(); return 1; @@ -1678,7 +1684,7 @@ int lc8670_cpu_device::op_subc() int lc8670_cpu_device::op_ror() { - REG_A = ((REG_A & 0x01) << 7) | (REG_A>>1); + REG_A = ((REG_A & 0x01) << 7) | (REG_A >> 1); CHECK_P(); return 1; @@ -1686,7 +1692,7 @@ int lc8670_cpu_device::op_ror() int lc8670_cpu_device::op_ldc() { - REG_A = m_program.read_byte(((REG_TRH<<8) | REG_TRL) + REG_A); + REG_A = m_program.read_byte(((REG_TRH << 8) | REG_TRL) + REG_A); CHECK_P(); return 2; @@ -1709,7 +1715,7 @@ int lc8670_cpu_device::op_clr1() uint16_t d9 = GET_D9B3; uint8_t data = read_data_latch(d9); - data &= ~(1<<GET_B3); + data &= ~(1 << GET_B3); write_data_latch(d9, data); return 1; @@ -1717,9 +1723,9 @@ int lc8670_cpu_device::op_clr1() int lc8670_cpu_device::op_rorc() { - uint8_t a = (REG_A>>1) | (GET_CY ? 0x80 : 0x00); + uint8_t a = (REG_A >> 1) | (GET_CY ? 0x80 : 0x00); - SET_CY(BIT(REG_A,0)); + SET_CY(BIT(REG_A, 0)); REG_A = a; CHECK_P(); @@ -1736,7 +1742,7 @@ int lc8670_cpu_device::op_or() int lc8670_cpu_device::op_rol() { - REG_A = ((REG_A & 0x80) >> 7) | (REG_A<<1); + REG_A = ((REG_A & 0x80) >> 7) | (REG_A << 1); CHECK_P(); return 1; @@ -1755,7 +1761,7 @@ int lc8670_cpu_device::op_set1() uint16_t d9 = GET_D9B3; uint8_t data = read_data_latch(d9); - data |= (1<<GET_B3); + data |= (1 << GET_B3); write_data_latch(d9, data); return 1; @@ -1763,9 +1769,9 @@ int lc8670_cpu_device::op_set1() int lc8670_cpu_device::op_rolc() { - uint8_t a = (REG_A<<1) | (GET_CY ? 0x01 : 0x00); + uint8_t a = (REG_A << 1) | (GET_CY ? 0x01 : 0x00); - SET_CY(BIT(REG_A,7)); + SET_CY(BIT(REG_A, 7)); REG_A = a; CHECK_P(); diff --git a/src/devices/cpu/lc8670/lc8670.h b/src/devices/cpu/lc8670/lc8670.h index 37904e6ebe9..a00658a7d4d 100644 --- a/src/devices/cpu/lc8670/lc8670.h +++ b/src/devices/cpu/lc8670/lc8670.h @@ -93,7 +93,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_execute_interface overrides virtual uint32_t execute_min_cycles() const noexcept override { return 1; } @@ -112,6 +111,9 @@ protected: // device_disasm_interface overrides virtual std::unique_ptr<util::disasm_interface> create_disassembler() override; + TIMER_CALLBACK_MEMBER(base_timer_update); + TIMER_CALLBACK_MEMBER(clock_timer_update); + private: // helpers inline uint8_t fetch(); @@ -195,8 +197,6 @@ private: memory_access< 8, 0, 0, ENDIANNESS_BIG>::specific m_io; // I/O ports // timers - static const device_timer_id BASE_TIMER = 1; - static const device_timer_id CLOCK_TIMER = 2; emu_timer * m_basetimer; emu_timer * m_clocktimer; diff --git a/src/devices/cpu/m37710/m37710.cpp b/src/devices/cpu/m37710/m37710.cpp index e8e121c5f21..6ca096d1e4f 100644 --- a/src/devices/cpu/m37710/m37710.cpp +++ b/src/devices/cpu/m37710/m37710.cpp @@ -1354,12 +1354,12 @@ void m37710_cpu_device::device_start() for (int i = 0; i < 8; i++) { - m_timers[i] = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(m37710_cpu_device::m37710_timer_cb), this)); + m_timers[i] = timer_alloc(FUNC(m37710_cpu_device::m37710_timer_cb), this); m_reload[i] = attotime::never; m_timer_out[i] = 0; } - m_ad_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(m37710_cpu_device::ad_timer_cb), this)); + m_ad_timer = timer_alloc(FUNC(m37710_cpu_device::ad_timer_cb), this); save_item(NAME(m_a)); save_item(NAME(m_b)); diff --git a/src/devices/cpu/m6502/m3745x.cpp b/src/devices/cpu/m6502/m3745x.cpp index b591fdfcc1f..20b881f217e 100644 --- a/src/devices/cpu/m6502/m3745x.cpp +++ b/src/devices/cpu/m6502/m3745x.cpp @@ -62,10 +62,11 @@ void m3745x_device::device_start() m_write_p.resolve_all_safe(); m_read_ad.resolve_all_safe(0); - for (int i = 0; i < NUM_TIMERS; i++) + for (int i = TIMER_1; i <= TIMER_3; i++) { - m_timers[i] = timer_alloc(i); + m_timers[i] = machine().scheduler().timer_alloc(timer_expired_delegate()); } + m_timers[TIMER_ADC] = timer_alloc(FUNC(m3745x_device::adc_complete), this); m740_device::device_start(); @@ -116,22 +117,13 @@ void m3745x_device::device_reset() m_last_all_ints = 0; } -void m3745x_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(m3745x_device::adc_complete) { - switch (id) - { - case TIMER_ADC: - m_timers[TIMER_ADC]->adjust(attotime::never); - - m_adctrl |= ADCTRL_COMPLETE; - m_intreq2 |= IRQ2_ADC; - recalc_irqs(); - break; + m_timers[TIMER_ADC]->adjust(attotime::never); - default: - printf("M3775x: unknown timer expire %d\n", id); - break; - } + m_adctrl |= ADCTRL_COMPLETE; + m_intreq2 |= IRQ2_ADC; + recalc_irqs(); } void m3745x_device::execute_set_input(int inputnum, int state) diff --git a/src/devices/cpu/m6502/m3745x.h b/src/devices/cpu/m6502/m3745x.h index 6036362765b..bab3558e0a2 100644 --- a/src/devices/cpu/m6502/m3745x.h +++ b/src/devices/cpu/m6502/m3745x.h @@ -58,7 +58,6 @@ protected: // device-level overrides virtual void device_start() override; virtual void device_reset() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; virtual space_config_vector memory_space_config() const override; // device_execute_interface overrides @@ -66,6 +65,8 @@ protected: virtual uint64_t execute_cycles_to_clocks(uint64_t cycles) const noexcept override { return (cycles * 4); } virtual void execute_set_input(int inputnum, int state) override; + TIMER_CALLBACK_MEMBER(adc_complete); + void send_port(uint8_t offset, uint8_t data); uint8_t read_port(uint8_t offset); diff --git a/src/devices/cpu/m6502/m5074x.cpp b/src/devices/cpu/m6502/m5074x.cpp index 251902f3f0f..2d961b694a5 100644 --- a/src/devices/cpu/m6502/m5074x.cpp +++ b/src/devices/cpu/m6502/m5074x.cpp @@ -69,10 +69,10 @@ void m5074x_device::device_start() m_read_p.resolve_all_safe(0); m_write_p.resolve_all_safe(); - for (int i = 0; i < NUM_TIMERS; i++) - { - m_timers[i] = timer_alloc(i); - } + m_timers[TIMER_1] = timer_alloc(FUNC(m5074x_device::timer1_tick), this); + m_timers[TIMER_2] = timer_alloc(FUNC(m5074x_device::timer2_tick), this); + m_timers[TIMER_X] = timer_alloc(FUNC(m5074x_device::timerx_tick), this); + m_timers[TIMER_ADC] = timer_alloc(FUNC(m5074x_device::adc_complete), this); m740_device::device_start(); @@ -122,42 +122,39 @@ void m5074x_device::device_reset() m_tmr1 = m_tmr2 = m_tmrx = 0; } -void m5074x_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(m5074x_device::timer1_tick) { - switch (id) - { - case TIMER_1: - m_tmr1--; + m_tmr1--; - if (m_tmr1 <= 0) - { - m_intctrl |= IRQ_TMR1REQ; - m_tmr1 = m_tmr1latch; - recalc_irqs(); - } - break; + if (m_tmr1 <= 0) + { + m_intctrl |= IRQ_TMR1REQ; + m_tmr1 = m_tmr1latch; + recalc_irqs(); + } +} - case TIMER_2: - m_tmr2--; +TIMER_CALLBACK_MEMBER(m5074x_device::timer2_tick) +{ + m_tmr2--; - if (m_tmr2 <= 0) - { - m_intctrl |= IRQ_TMR2REQ; - m_tmr2 = m_tmr2latch; - recalc_irqs(); - } - break; + if (m_tmr2 <= 0) + { + m_intctrl |= IRQ_TMR2REQ; + m_tmr2 = m_tmr2latch; + recalc_irqs(); + } +} - case TIMER_X: - m_tmrx--; +TIMER_CALLBACK_MEMBER(m5074x_device::timerx_tick) +{ + m_tmrx--; - if (m_tmrx <= 0) - { - m_tmrctrl |= TMRC_TMRXREQ; - m_tmrx = m_tmrxlatch; - recalc_irqs(); - } - break; + if (m_tmrx <= 0) + { + m_tmrctrl |= TMRC_TMRXREQ; + m_tmrx = m_tmrxlatch; + recalc_irqs(); } } @@ -607,23 +604,14 @@ void m50753_device::execute_set_input(int inputnum, int state) recalc_irqs(); } -void m50753_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(m50753_device::adc_complete) { - switch (id) - { - case TIMER_ADC: - m_timers[TIMER_ADC]->adjust(attotime::never); + m_timers[TIMER_ADC]->adjust(attotime::never); - // if interrupt source is the ADC, do it. - if (m_ad_control & 4) - { - m_intctrl |= IRQ_50753_INTADC; - recalc_irqs(); - } - break; - - default: - m5074x_device::device_timer(timer, id, param); - break; + // if interrupt source is the ADC, do it. + if (m_ad_control & 4) + { + m_intctrl |= IRQ_50753_INTADC; + recalc_irqs(); } } diff --git a/src/devices/cpu/m6502/m5074x.h b/src/devices/cpu/m6502/m5074x.h index 72b7f918e3f..2b860a56e83 100644 --- a/src/devices/cpu/m6502/m5074x.h +++ b/src/devices/cpu/m6502/m5074x.h @@ -56,7 +56,6 @@ protected: // device-level overrides virtual void device_start() override; virtual void device_reset() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; virtual space_config_vector memory_space_config() const override; // device_execute_interface overrides (TODO: /8 in M50740A/41/52/57/58 SLW mode) @@ -64,6 +63,11 @@ protected: virtual uint64_t execute_cycles_to_clocks(uint64_t cycles) const noexcept override { return (cycles * 4); } virtual void execute_set_input(int inputnum, int state) override; + TIMER_CALLBACK_MEMBER(timer1_tick); + TIMER_CALLBACK_MEMBER(timer2_tick); + TIMER_CALLBACK_MEMBER(timerx_tick); + virtual TIMER_CALLBACK_MEMBER(adc_complete) { } + void send_port(uint8_t offset, uint8_t data); uint8_t read_port(uint8_t offset); @@ -128,10 +132,11 @@ protected: // device-level overrides virtual void device_start() override; virtual void device_reset() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; virtual void execute_set_input(int inputnum, int state) override; + virtual TIMER_CALLBACK_MEMBER(adc_complete) override; + private: void m50753_map(address_map &map); diff --git a/src/devices/cpu/m6502/st2204.cpp b/src/devices/cpu/m6502/st2204.cpp index 2523f34d5a8..0e8541be87a 100644 --- a/src/devices/cpu/m6502/st2204.cpp +++ b/src/devices/cpu/m6502/st2204.cpp @@ -91,9 +91,9 @@ void st2204_device::device_start() init_base_timer(0x0020); init_lcd_timer(0x0040); - m_timer[0] = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(st2204_device::t0_interrupt), this)); - m_timer[1] = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(st2204_device::t1_interrupt), this)); - m_psg_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(st2204_device::psg_interrupt), this)); + m_timer[0] = timer_alloc(FUNC(st2204_device::t0_interrupt), this); + m_timer[1] = timer_alloc(FUNC(st2204_device::t1_interrupt), this); + m_psg_timer = timer_alloc(FUNC(st2204_device::psg_interrupt), this); save_item(NAME(m_tmode)); save_item(NAME(m_tcntr)); diff --git a/src/devices/cpu/m6502/st2205u.cpp b/src/devices/cpu/m6502/st2205u.cpp index 0dfde79e388..ac50492e325 100644 --- a/src/devices/cpu/m6502/st2205u.cpp +++ b/src/devices/cpu/m6502/st2205u.cpp @@ -130,10 +130,10 @@ void st2205u_base_device::base_init(std::unique_ptr<mi_st2xxx> &&intf) { m_stream = stream_alloc(0, 4, 48000); - m_timer_12bit[0] = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(st2205u_device::t0_interrupt), this)); - m_timer_12bit[1] = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(st2205u_device::t1_interrupt), this)); - m_timer_12bit[2] = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(st2205u_device::t2_interrupt), this)); - m_timer_12bit[3] = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(st2205u_device::t3_interrupt), this)); + m_timer_12bit[0] = timer_alloc(FUNC(st2205u_device::t0_interrupt), this); + m_timer_12bit[1] = timer_alloc(FUNC(st2205u_device::t1_interrupt), this); + m_timer_12bit[2] = timer_alloc(FUNC(st2205u_device::t2_interrupt), this); + m_timer_12bit[3] = timer_alloc(FUNC(st2205u_device::t3_interrupt), this); init_base_timer(0x0040); init_lcd_timer(0x0080); diff --git a/src/devices/cpu/m6502/st2xxx.cpp b/src/devices/cpu/m6502/st2xxx.cpp index d0428332878..480460bbe67 100644 --- a/src/devices/cpu/m6502/st2xxx.cpp +++ b/src/devices/cpu/m6502/st2xxx.cpp @@ -132,7 +132,7 @@ void st2xxx_device::init_base_timer(u16 ireq) if (st2xxx_bt_divider(n) != 0) { m_bt_mask |= 1 << n; - m_base_timer[n] = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(st2xxx_device::bt_interrupt), this)); + m_base_timer[n] = timer_alloc(FUNC(st2xxx_device::bt_interrupt), this); } } @@ -151,7 +151,7 @@ void st2xxx_device::init_lcd_timer(u16 ireq) m_lcd_ireq = ireq; assert(m_lcd_ireq != 0); - m_lcd_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(st2xxx_device::lcd_interrupt), this)); + m_lcd_timer = timer_alloc(FUNC(st2xxx_device::lcd_interrupt), this); } void st2xxx_device::save_common_registers() diff --git a/src/devices/cpu/m6800/m6801.cpp b/src/devices/cpu/m6800/m6801.cpp index a5e3226d770..e759a0b57cc 100644 --- a/src/devices/cpu/m6800/m6801.cpp +++ b/src/devices/cpu/m6800/m6801.cpp @@ -1041,7 +1041,7 @@ void m6801_cpu_device::device_start() { m6800_cpu_device::device_start(); - m_sci_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(m6801_cpu_device::sci_tick),this)); + m_sci_timer = timer_alloc(FUNC(m6801_cpu_device::sci_tick), this); m_irq_state[M6801_IS_LINE] = 0; m_port_ddr[3] = 0; diff --git a/src/devices/cpu/mb88xx/mb88xx.cpp b/src/devices/cpu/mb88xx/mb88xx.cpp index 5333d7466b8..1ef53c5e00b 100644 --- a/src/devices/cpu/mb88xx/mb88xx.cpp +++ b/src/devices/cpu/mb88xx/mb88xx.cpp @@ -193,7 +193,7 @@ void mb88_cpu_device::device_start() m_read_si.resolve_safe(0); m_write_so.resolve_safe(); - m_serial = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(mb88_cpu_device::serial_timer), this)); + m_serial = timer_alloc(FUNC(mb88_cpu_device::serial_timer), this); m_ctr = 0; diff --git a/src/devices/cpu/melps4/m58846.cpp b/src/devices/cpu/melps4/m58846.cpp index 7ba2dafb36a..0440375e47d 100644 --- a/src/devices/cpu/melps4/m58846.cpp +++ b/src/devices/cpu/melps4/m58846.cpp @@ -39,7 +39,7 @@ m58846_device::m58846_device(const machine_config &mconfig, const char *tag, dev void m58846_device::device_start() { melps4_cpu_device::device_start(); - m_timer = timer_alloc(0); + m_timer = timer_alloc(FUNC(m58846_device::timer_update), this); } @@ -66,11 +66,8 @@ void m58846_device::reset_timer() m_timer->adjust(base); } -void m58846_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(m58846_device::timer_update) { - if (id != 0) - return; - // timer 1: 7-bit fixed counter (manual specifically says 127) if (++m_tmr_count[0] == 127) { diff --git a/src/devices/cpu/melps4/m58846.h b/src/devices/cpu/melps4/m58846.h index 5c365e48898..2ba855e3dd2 100644 --- a/src/devices/cpu/melps4/m58846.h +++ b/src/devices/cpu/melps4/m58846.h @@ -30,8 +30,8 @@ protected: virtual void execute_one() override; // timers - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; virtual void write_v(u8 data) override; + TIMER_CALLBACK_MEMBER(timer_update); void data_128x4(address_map &map); void program_2kx9(address_map &map); diff --git a/src/devices/cpu/mips/mips3.cpp b/src/devices/cpu/mips/mips3.cpp index 08ea4197a34..9b6067e5fa4 100644 --- a/src/devices/cpu/mips/mips3.cpp +++ b/src/devices/cpu/mips/mips3.cpp @@ -429,7 +429,7 @@ void mips3_device::device_start() m_program->accessors(m_memory); /* allocate a timer for the compare interrupt */ - m_compare_int_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(mips3_device::compare_int_callback), this)); + m_compare_int_timer = timer_alloc(FUNC(mips3_device::compare_int_callback), this); uint32_t flags = 0; /* initialize the UML generator */ diff --git a/src/devices/cpu/mips/r4000.cpp b/src/devices/cpu/mips/r4000.cpp index 5cd174d48d5..1cf885379cc 100644 --- a/src/devices/cpu/mips/r4000.cpp +++ b/src/devices/cpu/mips/r4000.cpp @@ -187,7 +187,7 @@ void r4000_base_device::device_start() m_hard_reset = true; - m_cp0_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(r4000_base_device::cp0_timer_callback), this)); + m_cp0_timer = timer_alloc(FUNC(r4000_base_device::cp0_timer_callback), this); // compute icache line selection mask and allocate tag and data unsigned const config_ic = (m_cp0[CP0_Config] & CONFIG_IC) >> 9; diff --git a/src/devices/cpu/mn10200/mn10200.cpp b/src/devices/cpu/mn10200/mn10200.cpp index 0dcc3aef4ec..64da0efe23f 100644 --- a/src/devices/cpu/mn10200/mn10200.cpp +++ b/src/devices/cpu/mn10200/mn10200.cpp @@ -150,7 +150,7 @@ void mn10200_device::device_start() for (int tmr = 0; tmr < MN10200_NUM_TIMERS_8BIT; tmr++) { - m_timer_timers[tmr] = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(mn10200_device::simple_timer_cb), this)); + m_timer_timers[tmr] = timer_alloc(FUNC(mn10200_device::simple_timer_cb), this); m_timer_timers[tmr]->adjust(attotime::never, tmr); } diff --git a/src/devices/cpu/nec/v25.cpp b/src/devices/cpu/nec/v25.cpp index 20a87c5c50f..4b24f752623 100644 --- a/src/devices/cpu/nec/v25.cpp +++ b/src/devices/cpu/nec/v25.cpp @@ -555,7 +555,7 @@ void v25_common_device::device_start() m_E16 = 0; for (i = 0; i < 4; i++) - m_timers[i] = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(v25_common_device::v25_timer_callback),this)); + m_timers[i] = timer_alloc(FUNC(v25_common_device::v25_timer_callback), this); std::fill_n(&m_intp_state[0], 3, 0); std::fill_n(&m_ems[0], 3, 0); diff --git a/src/devices/cpu/powerpc/ppccom.cpp b/src/devices/cpu/powerpc/ppccom.cpp index 450b89ae643..aecc85d1709 100644 --- a/src/devices/cpu/powerpc/ppccom.cpp +++ b/src/devices/cpu/powerpc/ppccom.cpp @@ -754,22 +754,22 @@ void ppc_device::device_start() /* allocate a timer for the compare interrupt */ if ((m_cap & PPCCAP_OEA) && (m_tb_divisor)) - m_decrementer_int_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(ppc_device::decrementer_int_callback), this)); + m_decrementer_int_timer = timer_alloc(FUNC(ppc_device::decrementer_int_callback), this); /* and for the 4XX interrupts if needed */ if (m_cap & PPCCAP_4XX) { - m_fit_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(ppc_device::ppc4xx_fit_callback), this)); - m_pit_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(ppc_device::ppc4xx_pit_callback), this)); - m_spu.timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(ppc_device::ppc4xx_spu_callback), this)); + m_fit_timer = timer_alloc(FUNC(ppc_device::ppc4xx_fit_callback), this); + m_pit_timer = timer_alloc(FUNC(ppc_device::ppc4xx_pit_callback), this); + m_spu.timer = timer_alloc(FUNC(ppc_device::ppc4xx_spu_callback), this); } if (m_cap & PPCCAP_4XX) { - m_buffered_dma_timer[0] = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(ppc_device::ppc4xx_buffered_dma_callback), this)); - m_buffered_dma_timer[1] = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(ppc_device::ppc4xx_buffered_dma_callback), this)); - m_buffered_dma_timer[2] = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(ppc_device::ppc4xx_buffered_dma_callback), this)); - m_buffered_dma_timer[3] = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(ppc_device::ppc4xx_buffered_dma_callback), this)); + m_buffered_dma_timer[0] = timer_alloc(FUNC(ppc_device::ppc4xx_buffered_dma_callback), this); + m_buffered_dma_timer[1] = timer_alloc(FUNC(ppc_device::ppc4xx_buffered_dma_callback), this); + m_buffered_dma_timer[2] = timer_alloc(FUNC(ppc_device::ppc4xx_buffered_dma_callback), this); + m_buffered_dma_timer[3] = timer_alloc(FUNC(ppc_device::ppc4xx_buffered_dma_callback), this); m_buffered_dma_rate[0] = 10000; m_buffered_dma_rate[1] = 10000; diff --git a/src/devices/cpu/psx/dma.cpp b/src/devices/cpu/psx/dma.cpp index 0b69e01df37..f4376472d98 100644 --- a/src/devices/cpu/psx/dma.cpp +++ b/src/devices/cpu/psx/dma.cpp @@ -64,7 +64,7 @@ void psxdma_device::device_start() { psx_dma_channel *dma = &m_channel[ index ]; - dma->timer = timer_alloc(index); + dma->timer = timer_alloc( FUNC( psxdma_device::dma_finished ), this ); save_item( NAME( dma->n_base ), index ); save_item( NAME( dma->n_blockcontrol ), index ); @@ -129,8 +129,9 @@ void psxdma_device::dma_interrupt_update() m_dicr &= 0x00ffffff | ( m_dicr << 8 ); } -void psxdma_device::dma_finished( int index ) +TIMER_CALLBACK_MEMBER( psxdma_device::dma_finished ) { + const int index = param; psx_dma_channel *dma = &m_channel[ index ]; if( dma->n_channelcontrol == 0x01000401 && index == 2 ) @@ -196,11 +197,6 @@ void psxdma_device::dma_finished( int index ) dma_stop_timer( index ); } -void psxdma_device::device_timer(emu_timer &timer, device_timer_id id, int param) -{ - dma_finished(id); -} - void psxdma_device::install_read_handler( int index, read_delegate p_fn_dma_read ) { m_channel[ index ].fn_read = p_fn_dma_read; diff --git a/src/devices/cpu/psx/dma.h b/src/devices/cpu/psx/dma.h index 96c6aebf46b..0d81d67da7d 100644 --- a/src/devices/cpu/psx/dma.h +++ b/src/devices/cpu/psx/dma.h @@ -39,7 +39,6 @@ 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: struct psx_dma_channel @@ -58,7 +57,7 @@ private: void dma_stop_timer( int n_channel ); void dma_timer_adjust( int n_channel ); void dma_interrupt_update(); - void dma_finished( int n_channel ); + TIMER_CALLBACK_MEMBER( dma_finished ); psx_dma_channel m_channel[7]; uint32_t m_dpcp; diff --git a/src/devices/cpu/psx/rcnt.cpp b/src/devices/cpu/psx/rcnt.cpp index 590cb49bde0..210c6359323 100644 --- a/src/devices/cpu/psx/rcnt.cpp +++ b/src/devices/cpu/psx/rcnt.cpp @@ -58,7 +58,7 @@ void psxrcnt_device::device_start() for( n = 0; n < 3; n++ ) { - root_counter[ n ].timer = timer_alloc(n); + root_counter[ n ].timer = timer_alloc( FUNC( psxrcnt_device::timer_update ), this ); save_item(NAME(root_counter[ n ].n_count), n); save_item(NAME(root_counter[ n ].n_mode), n); save_item(NAME(root_counter[ n ].n_target), n); @@ -227,9 +227,9 @@ void psxrcnt_device::root_timer_adjust( int n_counter ) } } -void psxrcnt_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER( psxrcnt_device::timer_update ) { - int n_counter = id; + int n_counter = param; psx_root *root = &root_counter[ n_counter ]; verboselog( *this, 2, "root_finished( %d ) %04x\n", n_counter, root_current( n_counter ) ); diff --git a/src/devices/cpu/psx/rcnt.h b/src/devices/cpu/psx/rcnt.h index dd9b1a3cc89..8e0a471f4e1 100644 --- a/src/devices/cpu/psx/rcnt.h +++ b/src/devices/cpu/psx/rcnt.h @@ -41,7 +41,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; + + TIMER_CALLBACK_MEMBER( timer_update ); private: struct psx_root diff --git a/src/devices/cpu/psx/sio.cpp b/src/devices/cpu/psx/sio.cpp index fe3fef083f6..0f6b2c39001 100644 --- a/src/devices/cpu/psx/sio.cpp +++ b/src/devices/cpu/psx/sio.cpp @@ -63,7 +63,7 @@ void psxsio_device::device_start() m_dtr_handler.resolve_safe(); m_rts_handler.resolve_safe(); - m_timer = timer_alloc( 0 ); + m_timer = timer_alloc( FUNC( psxsio_device::sio_tick ), this ); m_mode = 0; m_control = 0; m_baud = 0; @@ -138,7 +138,7 @@ void psxsio_device::sio_timer_adjust() m_timer->adjust( n_time ); } -void psxsio_device::device_timer(emu_timer &timer, device_timer_id tid, int param) +TIMER_CALLBACK_MEMBER( psxsio_device::sio_tick ) { verboselog( *this, 2, "sio tick\n" ); diff --git a/src/devices/cpu/psx/sio.h b/src/devices/cpu/psx/sio.h index 940b7737c46..482a8081d6a 100644 --- a/src/devices/cpu/psx/sio.h +++ b/src/devices/cpu/psx/sio.h @@ -54,9 +54,10 @@ protected: // device-level overrides virtual void device_start() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; virtual void device_post_load() override; + TIMER_CALLBACK_MEMBER( sio_tick ); + private: void sio_interrupt(); void sio_timer_adjust(); diff --git a/src/devices/cpu/rii/riscii.cpp b/src/devices/cpu/rii/riscii.cpp index e5e021ff90e..f7c642a2f0a 100644 --- a/src/devices/cpu/rii/riscii.cpp +++ b/src/devices/cpu/rii/riscii.cpp @@ -207,8 +207,8 @@ void riscii_series_device::device_start() set_icountptr(m_icount); - m_timer0 = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(riscii_series_device::timer0), this)); - m_speech_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(riscii_series_device::speech_timer), this)); + m_timer0 = timer_alloc(FUNC(riscii_series_device::timer0), this); + m_speech_timer = timer_alloc(FUNC(riscii_series_device::speech_timer), this); state_add<u32>(RII_PC, "PC", [this]() { return m_pc; }, [this](u32 pc) { debug_set_pc(pc); }).mask(m_pcmask); state_add<u32>(STATE_GENPC, "GENPC", [this]() { return m_pc; }, [this](u32 pc) { debug_set_pc(pc); }).mask(m_pcmask).noshow(); diff --git a/src/devices/cpu/sc61860/sc61860.cpp b/src/devices/cpu/sc61860/sc61860.cpp index cac673f70e7..9719ebc7069 100644 --- a/src/devices/cpu/sc61860/sc61860.cpp +++ b/src/devices/cpu/sc61860/sc61860.cpp @@ -105,7 +105,7 @@ void sc61860_device::device_reset() void sc61860_device::device_start() { - m_2ms_tick_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(sc61860_device::sc61860_2ms_tick), this)); + m_2ms_tick_timer = timer_alloc(FUNC(sc61860_device::sc61860_2ms_tick), this); m_2ms_tick_timer->adjust(attotime::from_hz(500), 0, attotime::from_hz(500)); space(AS_PROGRAM).cache(m_cache); diff --git a/src/devices/cpu/sh/sh2.cpp b/src/devices/cpu/sh/sh2.cpp index 302b1082284..63a981b754b 100644 --- a/src/devices/cpu/sh/sh2.cpp +++ b/src/devices/cpu/sh/sh2.cpp @@ -514,15 +514,15 @@ void sh2_device::device_start() { sh_common_execution::device_start(); - m_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(sh2_device::sh2_timer_callback), this)); + m_timer = timer_alloc(FUNC(sh2_device::sh2_timer_callback), this); m_timer->adjust(attotime::never); - m_wdtimer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(sh2_device::sh2_wdtimer_callback), this)); + m_wdtimer = timer_alloc(FUNC(sh2_device::sh2_wdtimer_callback), this); m_wdtimer->adjust(attotime::never); - m_dma_current_active_timer[0] = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(sh2_device::sh2_dma_current_active_callback), this)); + m_dma_current_active_timer[0] = timer_alloc(FUNC(sh2_device::sh2_dma_current_active_callback), this); m_dma_current_active_timer[0]->adjust(attotime::never); - m_dma_current_active_timer[1] = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(sh2_device::sh2_dma_current_active_callback), this)); + m_dma_current_active_timer[1] = timer_alloc(FUNC(sh2_device::sh2_dma_current_active_callback), this); m_dma_current_active_timer[1]->adjust(attotime::never); /* resolve callbacks */ diff --git a/src/devices/cpu/sh/sh4.cpp b/src/devices/cpu/sh/sh4.cpp index c3dde9ed3e1..7d64546d741 100644 --- a/src/devices/cpu/sh/sh4.cpp +++ b/src/devices/cpu/sh/sh4.cpp @@ -2037,21 +2037,21 @@ void sh34_base_device::device_start() for (int i = 0; i < 3; i++) { - m_timer[i] = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(sh34_base_device::sh4_timer_callback), this)); + m_timer[i] = timer_alloc(FUNC(sh34_base_device::sh4_timer_callback), this); m_timer[i]->adjust(attotime::never, i); } for (int i = 0; i < 4; i++) { - m_dma_timer[i] = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(sh34_base_device::sh4_dmac_callback), this)); + m_dma_timer[i] = timer_alloc(FUNC(sh34_base_device::sh4_dmac_callback), this); m_dma_timer[i]->adjust(attotime::never, i); } - m_refresh_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(sh34_base_device::sh4_refresh_timer_callback), this)); + m_refresh_timer = timer_alloc(FUNC(sh34_base_device::sh4_refresh_timer_callback), this); m_refresh_timer->adjust(attotime::never); m_refresh_timer_base = 0; - m_rtc_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(sh34_base_device::sh4_rtc_timer_callback), this)); + m_rtc_timer = timer_alloc(FUNC(sh34_base_device::sh4_rtc_timer_callback), this); m_rtc_timer->adjust(attotime::never); sh4_parse_configuration(); diff --git a/src/devices/cpu/sharc/sharc.cpp b/src/devices/cpu/sharc/sharc.cpp index a2b262d83e1..7ce22652570 100644 --- a/src/devices/cpu/sharc/sharc.cpp +++ b/src/devices/cpu/sharc/sharc.cpp @@ -580,7 +580,7 @@ void adsp21062_device::device_start() m_core->cache_dirty = 1; - m_core->delayed_iop_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(adsp21062_device::sharc_iop_delayed_write_callback), this)); + m_core->delayed_iop_timer = timer_alloc(FUNC(adsp21062_device::sharc_iop_delayed_write_callback), this); for (auto & elem : m_core->dma_op) { @@ -594,7 +594,7 @@ void adsp21062_device::device_start() elem.pmode = 0; elem.chained_direction = 0; elem.active = false; - elem.timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(adsp21062_device::sharc_dma_callback), this)); + elem.timer = timer_alloc(FUNC(adsp21062_device::sharc_dma_callback), this); } for (int i=0; i < 16; i++) diff --git a/src/devices/cpu/sm510/sm510base.cpp b/src/devices/cpu/sm510/sm510base.cpp index 6501e24d693..05768cdd95d 100644 --- a/src/devices/cpu/sm510/sm510base.cpp +++ b/src/devices/cpu/sm510/sm510base.cpp @@ -200,7 +200,7 @@ TIMER_CALLBACK_MEMBER(sm510_base_device::lcd_timer_cb) void sm510_base_device::init_lcd_driver() { // note: in reality, this timer runs at high frequency off the main divider, strobing one segment at a time - m_lcd_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(sm510_base_device::lcd_timer_cb), this)); + m_lcd_timer = timer_alloc(FUNC(sm510_base_device::lcd_timer_cb), this); attotime period = attotime::from_ticks(0x20, unscaled_clock()); // default 1kHz m_lcd_timer->adjust(period, 0, period); } @@ -223,7 +223,7 @@ TIMER_CALLBACK_MEMBER(sm510_base_device::div_timer_cb) void sm510_base_device::init_divider() { - m_div_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(sm510_base_device::div_timer_cb), this)); + m_div_timer = timer_alloc(FUNC(sm510_base_device::div_timer_cb), this); attotime period = attotime::from_ticks(1, unscaled_clock()); m_div_timer->adjust(period, 0, period); } diff --git a/src/devices/cpu/tlcs870/tlcs870.cpp b/src/devices/cpu/tlcs870/tlcs870.cpp index 13f92343786..c010de7e03b 100644 --- a/src/devices/cpu/tlcs870/tlcs870.cpp +++ b/src/devices/cpu/tlcs870/tlcs870.cpp @@ -1244,13 +1244,13 @@ void tlcs870_device::device_start() m_port_analog_in_cb.resolve_all_safe(0xff); m_serial_out_cb.resolve_all_safe(); - m_serial_transmit_timer[0] = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(tlcs870_device::sio0_transmit_cb), this)); - m_serial_transmit_timer[1] = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(tlcs870_device::sio1_transmit_cb), this)); + m_serial_transmit_timer[0] = timer_alloc(FUNC(tlcs870_device::sio0_transmit_cb), this); + m_serial_transmit_timer[1] = timer_alloc(FUNC(tlcs870_device::sio1_transmit_cb), this); - m_tcx_timer[0] = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(tlcs870_device::tc1_cb), this)); - m_tcx_timer[1] = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(tlcs870_device::tc2_cb), this)); - m_tcx_timer[2] = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(tlcs870_device::tc3_cb), this)); - m_tcx_timer[3] = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(tlcs870_device::tc4_cb), this)); + m_tcx_timer[0] = timer_alloc(FUNC(tlcs870_device::tc1_cb), this); + m_tcx_timer[1] = timer_alloc(FUNC(tlcs870_device::tc2_cb), this); + m_tcx_timer[2] = timer_alloc(FUNC(tlcs870_device::tc3_cb), this); + m_tcx_timer[3] = timer_alloc(FUNC(tlcs870_device::tc4_cb), this); } diff --git a/src/devices/cpu/tlcs90/tlcs90.cpp b/src/devices/cpu/tlcs90/tlcs90.cpp index a363781636c..148f2dbd4a8 100644 --- a/src/devices/cpu/tlcs90/tlcs90.cpp +++ b/src/devices/cpu/tlcs90/tlcs90.cpp @@ -2950,9 +2950,9 @@ void tlcs90_device::device_start() // Timers for (int i = 0; i < 4; i++) - m_timer[i] = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(tlcs90_device::t90_timer_callback),this)); + m_timer[i] = timer_alloc(FUNC(tlcs90_device::t90_timer_callback), this); - m_timer[4] = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(tlcs90_device::t90_timer4_callback),this)); + m_timer[4] = timer_alloc(FUNC(tlcs90_device::t90_timer4_callback), this); state_add( T90_PC, "PC", m_pc.w.l).formatstr("%04X"); state_add( T90_SP, "SP", m_sp.w.l).formatstr("%04X"); diff --git a/src/devices/cpu/tms34010/tms34010.cpp b/src/devices/cpu/tms34010/tms34010.cpp index 42faac82b5d..729b6ed0bf6 100644 --- a/src/devices/cpu/tms34010/tms34010.cpp +++ b/src/devices/cpu/tms34010/tms34010.cpp @@ -740,7 +740,7 @@ void tms340x0_device::device_start() } /* allocate a scanline timer and set it to go off at the start */ - m_scantimer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(tms340x0_device::scanline_callback), this)); + m_scantimer = timer_alloc(FUNC(tms340x0_device::scanline_callback), this); m_scantimer->adjust(attotime::zero); save_item(NAME(m_pc)); diff --git a/src/devices/cpu/tms7000/tms7000.cpp b/src/devices/cpu/tms7000/tms7000.cpp index 5f1cb0f1308..3ce6f001ca2 100644 --- a/src/devices/cpu/tms7000/tms7000.cpp +++ b/src/devices/cpu/tms7000/tms7000.cpp @@ -222,7 +222,7 @@ void tms7000_device::device_start() for (int tmr = 0; tmr < 2; tmr++) { - m_timer_handle[tmr] = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(tms7000_device::simple_timer_cb), this)); + m_timer_handle[tmr] = timer_alloc(FUNC(tms7000_device::simple_timer_cb), this); m_timer_handle[tmr]->adjust(attotime::never, tmr); m_timer_data[tmr] = 0; diff --git a/src/devices/cpu/ucom4/ucom4.cpp b/src/devices/cpu/ucom4/ucom4.cpp index db273f65297..ade42ba1e12 100644 --- a/src/devices/cpu/ucom4/ucom4.cpp +++ b/src/devices/cpu/ucom4/ucom4.cpp @@ -160,7 +160,7 @@ void ucom4_cpu_device::device_start() m_datamask = (1 << m_datawidth) - 1; m_dph_mask = m_datamask >> 4; - m_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(ucom4_cpu_device::simple_timer_cb), this)); + m_timer = timer_alloc(FUNC(ucom4_cpu_device::simple_timer_cb), this); // resolve callbacks m_read_a.resolve_safe(0); diff --git a/src/devices/cpu/z8/z8.cpp b/src/devices/cpu/z8/z8.cpp index ec63bb86d89..d59651b683b 100644 --- a/src/devices/cpu/z8/z8.cpp +++ b/src/devices/cpu/z8/z8.cpp @@ -1260,8 +1260,8 @@ void z8_device::device_start() space(AS_IO).specific(m_regs); /* allocate timers */ - m_internal_timer[0] = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(z8_device::timeout<0>), this)); - m_internal_timer[1] = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(z8_device::timeout<1>), this)); + m_internal_timer[0] = timer_alloc(FUNC(z8_device::timeout<0>), this); + m_internal_timer[1] = timer_alloc(FUNC(z8_device::timeout<1>), this); /* Clear state */ std::fill(std::begin(m_irq_line), std::end(m_irq_line), CLEAR_LINE); diff --git a/src/devices/cpu/z80/kp63.cpp b/src/devices/cpu/z80/kp63.cpp index 675586377cb..db42ef30ecb 100644 --- a/src/devices/cpu/z80/kp63.cpp +++ b/src/devices/cpu/z80/kp63.cpp @@ -153,20 +153,20 @@ TIMER_CALLBACK_MEMBER(kp63_device::pwm_off) void kp63_device::device_start() { // Setup timers - m_timer[0] = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(kp63_device::timer_expired<0>), this)); - m_strobe_timer[0] = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(kp63_device::strobe_off<0>), this)); - m_pwm_timer[0] = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(kp63_device::pwm_off<0>), this)); - m_timer[1] = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(kp63_device::timer_expired<1>), this)); - m_strobe_timer[1] = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(kp63_device::strobe_off<1>), this)); - m_pwm_timer[1] = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(kp63_device::pwm_off<1>), this)); - m_timer[2] = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(kp63_device::timer_expired<2>), this)); - m_strobe_timer[2] = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(kp63_device::strobe_off<2>), this)); - m_pwm_timer[2] = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(kp63_device::pwm_off<2>), this)); + m_timer[0] = timer_alloc(FUNC(kp63_device::timer_expired<0>), this); + m_strobe_timer[0] = timer_alloc(FUNC(kp63_device::strobe_off<0>), this); + m_pwm_timer[0] = timer_alloc(FUNC(kp63_device::pwm_off<0>), this); + m_timer[1] = timer_alloc(FUNC(kp63_device::timer_expired<1>), this); + m_strobe_timer[1] = timer_alloc(FUNC(kp63_device::strobe_off<1>), this); + m_pwm_timer[1] = timer_alloc(FUNC(kp63_device::pwm_off<1>), this); + m_timer[2] = timer_alloc(FUNC(kp63_device::timer_expired<2>), this); + m_strobe_timer[2] = timer_alloc(FUNC(kp63_device::strobe_off<2>), this); + m_pwm_timer[2] = timer_alloc(FUNC(kp63_device::pwm_off<2>), this); if (c_num_counters > 3) { - m_timer[3] = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(kp63_device::timer_expired<3>), this)); - m_strobe_timer[3] = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(kp63_device::strobe_off<3>), this)); - m_pwm_timer[3] = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(kp63_device::pwm_off<3>), this)); + m_timer[3] = timer_alloc(FUNC(kp63_device::timer_expired<3>), this); + m_strobe_timer[3] = timer_alloc(FUNC(kp63_device::strobe_off<3>), this); + m_pwm_timer[3] = timer_alloc(FUNC(kp63_device::pwm_off<3>), this); } // Save state diff --git a/src/devices/cpu/z80/tmpz84c015.cpp b/src/devices/cpu/z80/tmpz84c015.cpp index 329aec51f9f..3df10f19c6c 100644 --- a/src/devices/cpu/z80/tmpz84c015.cpp +++ b/src/devices/cpu/z80/tmpz84c015.cpp @@ -116,7 +116,7 @@ void tmpz84c015_device::device_start() m_wdtout_cb.resolve(); // setup watchdog timer - m_watchdog_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(tmpz84c015_device::watchdog_timeout), this)); + m_watchdog_timer = timer_alloc(FUNC(tmpz84c015_device::watchdog_timeout), this); // register for save states save_item(NAME(m_irq_priority)); diff --git a/src/devices/imagedev/avivideo.cpp b/src/devices/imagedev/avivideo.cpp index 5c6742d8a6e..f1a2b7e1cdc 100644 --- a/src/devices/imagedev/avivideo.cpp +++ b/src/devices/imagedev/avivideo.cpp @@ -46,7 +46,7 @@ avivideo_image_device::~avivideo_image_device() void avivideo_image_device::device_start() { - m_frame_timer = timer_alloc(TIMER_FRAME); + m_frame_timer = timer_alloc(FUNC(avivideo_image_device::frame_timer), this); m_frame_timer->adjust(attotime::never); save_item(NAME(m_frame_count)); @@ -58,29 +58,26 @@ void avivideo_image_device::device_reset() m_frame_num = 0; } -void avivideo_image_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(avivideo_image_device::frame_timer) { - if (id == TIMER_FRAME) + if (m_avi != nullptr) { - if (m_avi != nullptr) + avi_file::error avierr = m_avi->read_uncompressed_video_frame(m_frame_num, *m_frame); + if (avierr != avi_file::error::NONE) { - avi_file::error avierr = m_avi->read_uncompressed_video_frame(m_frame_num, *m_frame); - if (avierr != avi_file::error::NONE) - { - m_frame_timer->adjust(attotime::never); - return; - } - m_frame_num++; - if (m_frame_num >= m_frame_count) - { - m_frame_num = 0; - } + m_frame_timer->adjust(attotime::never); + return; } - else + m_frame_num++; + if (m_frame_num >= m_frame_count) { - m_frame_timer->adjust(attotime::never); + m_frame_num = 0; } } + else + { + m_frame_timer->adjust(attotime::never); + } } image_init_result avivideo_image_device::call_load() diff --git a/src/devices/imagedev/avivideo.h b/src/devices/imagedev/avivideo.h index b32a32d8bbe..5af11df4187 100644 --- a/src/devices/imagedev/avivideo.h +++ b/src/devices/imagedev/avivideo.h @@ -47,11 +47,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; -private: - static constexpr device_timer_id TIMER_FRAME = 0; + TIMER_CALLBACK_MEMBER(frame_timer); +private: bitmap_argb32 *m_frame; avi_file::ptr m_avi; diff --git a/src/devices/imagedev/flopdrv.cpp b/src/devices/imagedev/flopdrv.cpp index 50214966b42..eba391f966e 100644 --- a/src/devices/imagedev/flopdrv.cpp +++ b/src/devices/imagedev/flopdrv.cpp @@ -129,7 +129,7 @@ void legacy_floppy_image_device::floppy_drive_init() /* initialise flags */ m_flags = 0; m_index_pulse_callback = nullptr; - m_index_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(legacy_floppy_image_device::floppy_drive_index_callback),this)); + m_index_timer = timer_alloc(FUNC(legacy_floppy_image_device::floppy_drive_index_callback), this); m_idx = 0; floppy_drive_set_geometry(m_config->floppy_type); @@ -692,6 +692,9 @@ void legacy_floppy_image_device::device_start() /* disk changed */ m_dskchg = CLEAR_LINE; // m_out_dskchg_func(m_dskchg); + + /* write-protect callback */ + m_wpt_timer = timer_alloc(FUNC(legacy_floppy_image_device::set_wpt), this); } @@ -746,7 +749,7 @@ image_init_result legacy_floppy_image_device::call_load() else next_wpt = 0; - machine().scheduler().timer_set(attotime::from_msec(250), timer_expired_delegate(FUNC(legacy_floppy_image_device::set_wpt),this), next_wpt); + m_wpt_timer->adjust(attotime::from_msec(250), next_wpt); return retVal; } @@ -768,7 +771,7 @@ void legacy_floppy_image_device::call_unload() //m_out_wpt_func(m_wpt); /* set timer for disk eject */ - machine().scheduler().timer_set(attotime::from_msec(250), timer_expired_delegate(FUNC(legacy_floppy_image_device::set_wpt),this), 1); + m_wpt_timer->adjust(attotime::from_msec(250), 1); } bool legacy_floppy_image_device::is_creatable() const noexcept diff --git a/src/devices/imagedev/flopdrv.h b/src/devices/imagedev/flopdrv.h index 7582d156285..a3241cc4b89 100644 --- a/src/devices/imagedev/flopdrv.h +++ b/src/devices/imagedev/flopdrv.h @@ -210,6 +210,7 @@ protected: /* rotation per minute => gives index pulse frequency */ float m_rpm; + emu_timer *m_wpt_timer; int m_id_index; device_t *m_controller; diff --git a/src/devices/imagedev/floppy.cpp b/src/devices/imagedev/floppy.cpp index a550a1e8f1b..d5894530337 100644 --- a/src/devices/imagedev/floppy.cpp +++ b/src/devices/imagedev/floppy.cpp @@ -447,7 +447,7 @@ void floppy_image_device::device_start() stp = 1; wpt = 0; dskchg = exists() ? 1 : 0; - index_timer = timer_alloc(0); + index_timer = timer_alloc(FUNC(floppy_image_device::index_resync), this); image_dirty = false; ready = true; ready_counter = 0; @@ -525,11 +525,6 @@ void floppy_image_device::device_reset() cache_clear(); } -void floppy_image_device::device_timer(emu_timer &timer, device_timer_id id, int param) -{ - index_resync(); -} - const floppy_image_format_t *floppy_image_device::identify(std::string_view filename) { util::core_file::ptr fd; @@ -565,7 +560,7 @@ void floppy_image_device::init_floppy_load(bool write_supported) revolution_start_time = mon ? attotime::never : machine().time(); revolution_count = 0; - index_resync(); + index_resync(0); wpt = 1; // disk sleeve is covering the sensor if (!cur_wpt_cb.isnull()) @@ -875,7 +870,7 @@ void floppy_image_device::mon_w(int state) } else { ready_counter = 2; } - index_resync(); + index_resync(0); } /* on -> off */ @@ -900,7 +895,7 @@ attotime floppy_image_device::time_next_index() } /* index pulses at rpm/60 Hz, and stays high for ~2ms at 300rpm */ -void floppy_image_device::index_resync() +TIMER_CALLBACK_MEMBER(floppy_image_device::index_resync) { if(revolution_start_time.is_never()) { if(idx) { diff --git a/src/devices/imagedev/floppy.h b/src/devices/imagedev/floppy.h index b9ff120e200..02b181d5540 100644 --- a/src/devices/imagedev/floppy.h +++ b/src/devices/imagedev/floppy.h @@ -137,7 +137,6 @@ public: void dskchg_w(int state) { if (dskchg_writable) dskchg = state; } void ds_w(int state) { ds = state; check_led(); } - void index_resync(); attotime time_next_index(); attotime get_next_transition(const attotime &from_when); void write_flux(const attotime &start, const attotime &end, int transition_count, const attotime *transitions); @@ -169,13 +168,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; virtual void device_config_complete() override; virtual void device_add_mconfig(machine_config &config) override; // device_image_interface implementation virtual const software_list_loader &get_software_list_loader() const override; + TIMER_CALLBACK_MEMBER(index_resync); + virtual void track_changed(); virtual void setup_characteristics() = 0; diff --git a/src/devices/imagedev/mfmhd.cpp b/src/devices/imagedev/mfmhd.cpp index de67f3eb887..7bbab1e97da 100644 --- a/src/devices/imagedev/mfmhd.cpp +++ b/src/devices/imagedev/mfmhd.cpp @@ -293,7 +293,6 @@ enum { INDEX_TM = 0, - SPINUP_TM, SEEK_TM, CACHE_TM }; @@ -350,10 +349,10 @@ mfm_harddisk_device::~mfm_harddisk_device() void mfm_harddisk_device::device_start() { - m_index_timer = timer_alloc(INDEX_TM); - m_spinup_timer = timer_alloc(SPINUP_TM); - m_seek_timer = timer_alloc(SEEK_TM); - m_cache_timer = timer_alloc(CACHE_TM); + m_index_timer = timer_alloc(FUNC(mfm_harddisk_device::index_timer), this); + m_spinup_timer = timer_alloc(FUNC(mfm_harddisk_device::recalibrate), this); + m_seek_timer = timer_alloc(FUNC(mfm_harddisk_device::seek_update), this); + m_cache_timer = timer_alloc(FUNC(mfm_harddisk_device::cache_update), this); m_rev_time = attotime::from_hz(m_rpm/60); m_index_timer->adjust(attotime::from_hz(m_rpm/60), 0, attotime::from_hz(m_rpm/60)); @@ -628,86 +627,80 @@ attotime mfm_harddisk_device::track_end_time() return endtime; } -void mfm_harddisk_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(mfm_harddisk_device::index_timer) { - switch (id) + // Simple index hole handling. We assume that there is only a short pulse. + m_revolution_start_time = machine().time(); + if (!m_index_pulse_cb.isnull()) { - case INDEX_TM: - // Simple index hole handling. We assume that there is only a short pulse. - m_revolution_start_time = machine().time(); - if (!m_index_pulse_cb.isnull()) - { - m_index_pulse_cb(this, ASSERT_LINE); - m_index_pulse_cb(this, CLEAR_LINE); - } - break; + m_index_pulse_cb(this, ASSERT_LINE); + m_index_pulse_cb(this, CLEAR_LINE); + } +} - case SPINUP_TM: - recalibrate(); - break; +TIMER_CALLBACK_MEMBER(mfm_harddisk_device::recalibrate) +{ + LOGMASKED(LOG_STEPS, "Recalibrate to track 0\n"); + direction_in_w(CLEAR_LINE); + while (-m_track_delta < m_phys_cylinders) + { + step_w(ASSERT_LINE); + step_w(CLEAR_LINE); + } +} - case CACHE_TM: - m_cache->write_back_one(); +TIMER_CALLBACK_MEMBER(mfm_harddisk_device::seek_update) +{ + switch (m_step_phase) + { + case STEP_COLLECT: + // Collect timer has expired; start moving head + head_move(); break; - - case SEEK_TM: - switch (m_step_phase) + case STEP_MOVING: + // Head has reached final position + // Check whether we have a new delta + if (m_track_delta == 0) { - case STEP_COLLECT: - // Collect timer has expired; start moving head + // Start the settle timer + m_step_phase = STEP_SETTLE; + m_seek_timer->adjust(m_settle_time); + LOGMASKED(LOG_STEPSDETAIL, "Arrived at target cylinder %d, settling ...\n", m_current_cylinder); + } + else + { + // need to move the head again head_move(); - break; - case STEP_MOVING: - // Head has reached final position - // Check whether we have a new delta - if (m_track_delta == 0) - { - // Start the settle timer - m_step_phase = STEP_SETTLE; - m_seek_timer->adjust(m_settle_time); - LOGMASKED(LOG_STEPSDETAIL, "Arrived at target cylinder %d, settling ...\n", m_current_cylinder); - } - else + } + break; + case STEP_SETTLE: + // Do we have new step pulses? + if (m_track_delta != 0) head_move(); + else + { + // Seek completed + if (!m_recalibrated) { - // need to move the head again - head_move(); + m_ready = true; + m_recalibrated = true; + LOGMASKED(LOG_CONFIG, "Spinup complete, drive recalibrated and positioned at cylinder %d; drive is READY\n", m_current_cylinder); + if (!m_ready_cb.isnull()) m_ready_cb(this, ASSERT_LINE); } - break; - case STEP_SETTLE: - // Do we have new step pulses? - if (m_track_delta != 0) head_move(); else { - // Seek completed - if (!m_recalibrated) - { - m_ready = true; - m_recalibrated = true; - LOGMASKED(LOG_CONFIG, "Spinup complete, drive recalibrated and positioned at cylinder %d; drive is READY\n", m_current_cylinder); - if (!m_ready_cb.isnull()) m_ready_cb(this, ASSERT_LINE); - } - else - { - LOGMASKED(LOG_SIGNALS, "Settling done at cylinder %d, seek complete\n", m_current_cylinder); - } - m_seek_complete = true; - if (!m_seek_complete_cb.isnull()) m_seek_complete_cb(this, ASSERT_LINE); - m_step_phase = STEP_COLLECT; + LOGMASKED(LOG_SIGNALS, "Settling done at cylinder %d, seek complete\n", m_current_cylinder); } - break; + m_seek_complete = true; + if (!m_seek_complete_cb.isnull()) m_seek_complete_cb(this, ASSERT_LINE); + m_step_phase = STEP_COLLECT; } + break; } } -void mfm_harddisk_device::recalibrate() +TIMER_CALLBACK_MEMBER(mfm_harddisk_device::cache_update) { - LOGMASKED(LOG_STEPS, "Recalibrate to track 0\n"); - direction_in_w(CLEAR_LINE); - while (-m_track_delta < m_phys_cylinders) - { - step_w(ASSERT_LINE); - step_w(CLEAR_LINE); - } + m_cache->write_back_one(); } void mfm_harddisk_device::head_move() diff --git a/src/devices/imagedev/mfmhd.h b/src/devices/imagedev/mfmhd.h index 409c70a537c..ce66a43fa3b 100644 --- a/src/devices/imagedev/mfmhd.h +++ b/src/devices/imagedev/mfmhd.h @@ -118,7 +118,11 @@ 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; + + TIMER_CALLBACK_MEMBER(index_timer); + TIMER_CALLBACK_MEMBER(recalibrate); + TIMER_CALLBACK_MEMBER(seek_update); + TIMER_CALLBACK_MEMBER(cache_update); emu_timer *m_index_timer, *m_spinup_timer, *m_seek_timer, *m_cache_timer; index_pulse_cb m_index_pulse_cb; @@ -166,7 +170,6 @@ private: mfmhd_image_format_t* m_format; chd_file *m_chd; void head_move(); - void recalibrate(); // Common routine for read/write bool find_position(attotime &from_when, const attotime &limit, int &bytepos, int &bitpos); diff --git a/src/devices/imagedev/microdrv.cpp b/src/devices/imagedev/microdrv.cpp index aecaee95f81..02168270523 100644 --- a/src/devices/imagedev/microdrv.cpp +++ b/src/devices/imagedev/microdrv.cpp @@ -70,7 +70,7 @@ void microdrive_image_device::device_start() m_right = std::make_unique<uint8_t[]>(MDV_IMAGE_LENGTH / 2); // allocate timers - m_bit_timer = timer_alloc(); + m_bit_timer = timer_alloc(FUNC(microdrive_image_device::bit_timer), this); m_bit_timer->adjust(attotime::zero, 0, attotime::from_hz(MDV_BITRATE)); m_bit_timer->enable(0); @@ -106,7 +106,7 @@ void microdrive_image_device::call_unload() memset(m_right.get(), 0, MDV_IMAGE_LENGTH / 2); } -void microdrive_image_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(microdrive_image_device::bit_timer) { m_bit_offset++; diff --git a/src/devices/imagedev/microdrv.h b/src/devices/imagedev/microdrv.h index 92432051411..5bd7d6a37da 100644 --- a/src/devices/imagedev/microdrv.h +++ b/src/devices/imagedev/microdrv.h @@ -60,7 +60,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(bit_timer); private: devcb_write_line m_write_comms_out; diff --git a/src/devices/imagedev/midiin.cpp b/src/devices/imagedev/midiin.cpp index 3c2ad7f2fa1..d75d9495026 100644 --- a/src/devices/imagedev/midiin.cpp +++ b/src/devices/imagedev/midiin.cpp @@ -74,7 +74,7 @@ ioport_constructor midiin_device::device_input_ports() const void midiin_device::device_start() { m_input_cb.resolve_safe(); - m_timer = timer_alloc(0); + m_timer = timer_alloc(FUNC(midiin_device::midi_update), this); m_midi.reset(); m_timer->enable(false); } @@ -91,69 +91,66 @@ void midiin_device::device_reset() } /*------------------------------------------------- - device_timer + midi_update -------------------------------------------------*/ -void midiin_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(midiin_device::midi_update) { - if (id == 0) + // if there's a sequence playing, that takes priority + midi_event *event = m_sequence.current_event(); + if (event != nullptr) { - // if there's a sequence playing, that takes priority - midi_event *event = m_sequence.current_event(); - if (event != nullptr) + attotime curtime = m_timer->expire(); + if (curtime < m_sequence_start) { - attotime curtime = timer.expire(); - if (curtime < m_sequence_start) - { - // we could get called before we're supposed to start; show a countdown - attotime delta = m_sequence_start - curtime; - popmessage("Waiting to start MIDI playback... %d", delta.seconds()); - m_timer->adjust(std::min(delta, attotime(1, 0))); - } - else + // we could get called before we're supposed to start; show a countdown + attotime delta = m_sequence_start - curtime; + popmessage("Waiting to start MIDI playback... %d", delta.seconds()); + m_timer->adjust(std::min(delta, attotime(1, 0))); + } + else + { + // update the playback time + curtime -= m_sequence_start; + popmessage("Playing MIDI file: %d:%02d / %d:%02d", curtime.seconds() / 60, curtime.seconds() % 60, m_sequence.duration().seconds() / 60, m_sequence.duration().seconds() % 60); + + // if it's time to process the current event, do it and advance + if (curtime >= event->time()) { - // update the playback time - curtime -= m_sequence_start; - popmessage("Playing MIDI file: %d:%02d / %d:%02d", curtime.seconds() / 60, curtime.seconds() % 60, m_sequence.duration().seconds() / 60, m_sequence.duration().seconds() % 60); + const u8 force_channel = m_config->read(); - // if it's time to process the current event, do it and advance - if (curtime >= event->time()) + for (u8 curbyte : event->data()) { - const u8 force_channel = m_config->read(); - - for (u8 curbyte : event->data()) - { - if (force_channel <= 15 && curbyte >= 0x80 && curbyte < 0xf0) - curbyte = (curbyte & 0xf0) | force_channel; + if (force_channel <= 15 && curbyte >= 0x80 && curbyte < 0xf0) + curbyte = (curbyte & 0xf0) | force_channel; - xmit_char(curbyte); - } - event = m_sequence.advance_event(); + xmit_char(curbyte); } - - // if there are more events, set a timer to trigger them - // (minimum duration 1 sec so that our playback time doesn't skip) - if (event != nullptr) - m_timer->adjust(std::min(event->time() - curtime, attotime(1, 0))); - else - popmessage("End of MIDI file"); + event = m_sequence.advance_event(); } + + // if there are more events, set a timer to trigger them + // (minimum duration 1 sec so that our playback time doesn't skip) + if (event != nullptr) + m_timer->adjust(std::min(event->time() - curtime, attotime(1, 0))); + else + popmessage("End of MIDI file"); } - else if (m_midi) + } + else if (m_midi) + { + uint8_t buf[8192*4]; + int bytesRead; + + while (m_midi->poll()) { - uint8_t buf[8192*4]; - int bytesRead; + bytesRead = m_midi->read(buf); - while (m_midi->poll()) + if (bytesRead > 0) { - bytesRead = m_midi->read(buf); - - if (bytesRead > 0) + for (int i = 0; i < bytesRead; i++) { - for (int i = 0; i < bytesRead; i++) - { - xmit_char(buf[i]); - } + xmit_char(buf[i]); } } } diff --git a/src/devices/imagedev/midiin.h b/src/devices/imagedev/midiin.h index 22cc81f7238..3d39a88c845 100644 --- a/src/devices/imagedev/midiin.h +++ b/src/devices/imagedev/midiin.h @@ -50,12 +50,12 @@ 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; - // serial overrides virtual void tra_complete() override; // Tx completed sending byte virtual void tra_callback() override; // Tx send bit + TIMER_CALLBACK_MEMBER(midi_update); + private: static const int XMIT_RING_SIZE = (8192*4*4); diff --git a/src/devices/imagedev/snapquik.cpp b/src/devices/imagedev/snapquik.cpp index 1940fc7a834..53c682827ea 100644 --- a/src/devices/imagedev/snapquik.cpp +++ b/src/devices/imagedev/snapquik.cpp @@ -64,7 +64,7 @@ void snapshot_image_device::device_start() m_load.resolve(); /* allocate a timer */ - m_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(snapshot_image_device::process_snapshot_or_quickload),this)); + m_timer = timer_alloc(FUNC(snapshot_image_device::process_snapshot_or_quickload), this); } /*------------------------------------------------- diff --git a/src/devices/machine/53c7xx.cpp b/src/devices/machine/53c7xx.cpp index a99b9d797cb..754d2714909 100644 --- a/src/devices/machine/53c7xx.cpp +++ b/src/devices/machine/53c7xx.cpp @@ -113,7 +113,7 @@ void ncr53c7xx_device::device_start() m_host_read.resolve_safe(0); m_host_write.resolve_safe(); - m_tm = timer_alloc(0); + m_tm = timer_alloc(FUNC(ncr53c7xx_device::step_timer), this); // The SCRIPTS processor runs at ~2 MIPS so approximate this set_unscaled_clock(2000000); @@ -757,11 +757,11 @@ void ncr53c7xx_device::recv_byte() //------------------------------------------------- -// device_timer - callback to step the SCSI +// step_timer - callback to step the SCSI // state machine //------------------------------------------------- -void ncr53c7xx_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(ncr53c7xx_device::step_timer) { step(true); } diff --git a/src/devices/machine/53c7xx.h b/src/devices/machine/53c7xx.h index 4abefb15403..2d6c695acd2 100644 --- a/src/devices/machine/53c7xx.h +++ b/src/devices/machine/53c7xx.h @@ -35,9 +35,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; virtual void execute_run() override; + TIMER_CALLBACK_MEMBER(step_timer); + int m_icount; private: diff --git a/src/devices/machine/64h156.cpp b/src/devices/machine/64h156.cpp index 29e343521c1..bf859402e55 100644 --- a/src/devices/machine/64h156.cpp +++ b/src/devices/machine/64h156.cpp @@ -92,7 +92,7 @@ void c64h156_device::device_start() m_write_byte.resolve_safe(); // allocate timer - t_gen = timer_alloc(0); + t_gen = timer_alloc(FUNC(c64h156_device::update_tick), this); // register for state saving save_item(NAME(m_mtr)); @@ -130,10 +130,10 @@ void c64h156_device::device_reset() //------------------------------------------------- -// device_timer - handler timer events +// update_tick - pump the device life cycle //------------------------------------------------- -void c64h156_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(c64h156_device::update_tick) { live_sync(); live_run(); diff --git a/src/devices/machine/64h156.h b/src/devices/machine/64h156.h index b5ee42035d1..0f6508caab6 100644 --- a/src/devices/machine/64h156.h +++ b/src/devices/machine/64h156.h @@ -108,7 +108,8 @@ protected: virtual void device_start() override; virtual void device_clock_changed() override; virtual void device_reset() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; + + TIMER_CALLBACK_MEMBER(update_tick); private: enum { diff --git a/src/devices/machine/6522via.cpp b/src/devices/machine/6522via.cpp index 81817bbbbcb..12f4a918be4 100644 --- a/src/devices/machine/6522via.cpp +++ b/src/devices/machine/6522via.cpp @@ -267,12 +267,12 @@ void via6522_device::device_start() m_sr = 0; m_time2 = m_time1 = machine().time(); - m_t1 = timer_alloc(TIMER_T1); - m_t2 = timer_alloc(TIMER_T2); - m_ca2_timer = timer_alloc(TIMER_CA2); - m_cb2_timer = timer_alloc(TIMER_CB2); - m_shift_timer = timer_alloc(TIMER_SHIFT); - m_shift_irq_timer = timer_alloc(TIMER_SHIFT_IRQ); + m_t1 = timer_alloc(FUNC(via6522_device::t1_tick), this); + m_t2 = timer_alloc(FUNC(via6522_device::t2_tick), this); + m_ca2_timer = timer_alloc(FUNC(via6522_device::ca2_tick), this); + m_cb2_timer = machine().scheduler().timer_alloc(timer_expired_delegate()); + m_shift_timer = timer_alloc(FUNC(via6522_device::shift_tick), this); + m_shift_irq_timer = timer_alloc(FUNC(via6522_device::shift_irq_tick), this); /* save state register */ save_item(NAME(m_in_a)); @@ -426,7 +426,7 @@ void via6522_device::clear_int(int data) /*------------------------------------------------- - via_shift + shift_out -------------------------------------------------*/ void via6522_device::shift_out() @@ -480,81 +480,83 @@ void via6522_device::shift_in() m_shift_counter = (m_shift_counter - 1) & 0x0f; // Count all edges } -void via6522_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(via6522_device::shift_irq_tick) { - switch (id) + // This timer event is a delayed IRQ for improved cycle accuracy + set_int(INT_SR); // triggered from shift_in or shift_out on the last rising edge + m_shift_irq_timer->adjust(attotime::never); // Not needed really... +} + +TIMER_CALLBACK_MEMBER(via6522_device::shift_tick) +{ + LOGSHIFT("SHIFT timer event CB1 %s edge, %d\n", m_out_cb1 & 1 ? "falling" : "raising", m_shift_counter); + m_out_cb1 ^= 1; + m_cb1_handler(m_out_cb1); + + // we call shift methods for all edges + if (SO_T2_RATE(m_acr) || SO_T2_CONTROL(m_acr) || SO_O2_CONTROL(m_acr)) { - case TIMER_SHIFT_IRQ: // This timer event is a delayed IRQ for improved cycle accuracy - set_int(INT_SR); // triggered from shift_in or shift_out on the last rising edge - m_shift_irq_timer->adjust(attotime::never); // Not needed really... - break; - case TIMER_SHIFT: - LOGSHIFT("SHIFT timer event CB1 %s edge, %d\n", m_out_cb1 & 1 ? "falling" : "raising", m_shift_counter); - m_out_cb1 ^= 1; - m_cb1_handler(m_out_cb1); + shift_out(); + } + else if (SI_T2_CONTROL(m_acr) || SI_O2_CONTROL(m_acr)) + { + shift_in(); + } - // we call shift methods for all edges - if (SO_T2_RATE(m_acr) || SO_T2_CONTROL(m_acr) || SO_O2_CONTROL(m_acr)) - { - shift_out(); - } - else if (SI_T2_CONTROL(m_acr) || SI_O2_CONTROL(m_acr)) - { - shift_in(); - } + // If in continous mode or the shifter is still shifting we re-arm the timer + if (SO_T2_RATE(m_acr) || (m_shift_counter < 0x0f)) + { + if (SI_O2_CONTROL(m_acr) || SO_O2_CONTROL(m_acr)) + { + m_shift_timer->adjust(clocks_to_attotime(1)); + } + else if (SO_T2_RATE(m_acr) || SO_T2_CONTROL(m_acr) || SI_T2_CONTROL(m_acr)) + { + m_shift_timer->adjust(clocks_to_attotime(m_t2ll + 2) / 2); + } + else // otherwise we stop it + { + m_shift_timer->adjust(attotime::never); + } + } +} - // If in continous mode or the shifter is still shifting we re-arm the timer - if (SO_T2_RATE(m_acr) || (m_shift_counter < 0x0f)) - { - if (SI_O2_CONTROL(m_acr) || SO_O2_CONTROL(m_acr)) - { - m_shift_timer->adjust(clocks_to_attotime(1)); - } - else if (SO_T2_RATE(m_acr) || SO_T2_CONTROL(m_acr) || SI_T2_CONTROL(m_acr)) - { - m_shift_timer->adjust(clocks_to_attotime(m_t2ll + 2) / 2); - } - else // otherwise we stop it - { - m_shift_timer->adjust(attotime::never); - } - } - break; - case TIMER_T1: - if (T1_CONTINUOUS (m_acr)) - { - m_t1_pb7 = !m_t1_pb7; - m_t1->adjust(clocks_to_attotime(TIMER1_VALUE + IFR_DELAY)); - } - else - { - m_t1_pb7 = 1; - m_t1_active = 0; - m_time1 = machine().time(); - } +TIMER_CALLBACK_MEMBER(via6522_device::t1_tick) +{ + if (T1_CONTINUOUS (m_acr)) + { + m_t1_pb7 = !m_t1_pb7; + m_t1->adjust(clocks_to_attotime(TIMER1_VALUE + IFR_DELAY)); + } + else + { + m_t1_pb7 = 1; + m_t1_active = 0; + m_time1 = machine().time(); + } - if (T1_SET_PB7(m_acr)) - { - output_pb(); - } + if (T1_SET_PB7(m_acr)) + { + output_pb(); + } - LOGINT("T1 INT request "); - set_int(INT_T1); - break; + LOGINT("T1 INT request "); + set_int(INT_T1); +} - case TIMER_T2: - m_t2_active = 0; - m_time2 = machine().time(); +TIMER_CALLBACK_MEMBER(via6522_device::t2_tick) +{ + m_t2_active = 0; + m_time2 = machine().time(); - LOGINT("T2 INT request "); - set_int(INT_T2); - break; + LOGINT("T2 INT request "); + set_int(INT_T2); +} - case TIMER_CA2: - m_out_ca2 = 1; - m_ca2_handler(m_out_ca2); - break; - } +TIMER_CALLBACK_MEMBER(via6522_device::ca2_tick) +{ + m_out_ca2 = 1; + m_ca2_handler(m_out_ca2); } uint8_t via6522_device::input_pa() diff --git a/src/devices/machine/6522via.h b/src/devices/machine/6522via.h index c31c8fbbff2..813a74a63d5 100644 --- a/src/devices/machine/6522via.h +++ b/src/devices/machine/6522via.h @@ -123,17 +123,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; - -private: - static constexpr device_timer_id TIMER_SHIFT = 0; - static constexpr device_timer_id TIMER_T1 = 1; - static constexpr device_timer_id TIMER_T2 = 2; - static constexpr device_timer_id TIMER_CA2 = 3; - static constexpr device_timer_id TIMER_SHIFT_IRQ = 4; - static constexpr device_timer_id TIMER_CB2 = 5; + TIMER_CALLBACK_MEMBER(shift_irq_tick); + TIMER_CALLBACK_MEMBER(shift_tick); + TIMER_CALLBACK_MEMBER(t1_tick); + TIMER_CALLBACK_MEMBER(t2_tick); + TIMER_CALLBACK_MEMBER(ca2_tick); +private: uint16_t get_counter1_value(); void counter2_decrement(); diff --git a/src/devices/machine/6532riot.cpp b/src/devices/machine/6532riot.cpp index 4afac5fcd2a..cdeb8e673af 100644 --- a/src/devices/machine/6532riot.cpp +++ b/src/devices/machine/6532riot.cpp @@ -114,7 +114,7 @@ uint8_t riot6532_device::get_timer() -void riot6532_device::timer_end() +TIMER_CALLBACK_MEMBER(riot6532_device::timer_end) { assert(m_timerstate != TIMER_IDLE); @@ -450,7 +450,7 @@ void riot6532_device::device_start() m_irq_cb.resolve_safe(); /* allocate timers */ - m_timer = timer_alloc(TIMER_END_CB); + m_timer = timer_alloc(FUNC(riot6532_device::timer_end), this); /* register for save states */ save_item(NAME(m_port[0].m_in)); @@ -501,15 +501,3 @@ void riot6532_device::device_reset() m_timerstate = TIMER_COUNTING; m_timer->adjust(attotime::from_ticks(256 << m_timershift, clock())); } - -void riot6532_device::device_timer(emu_timer &timer, device_timer_id id, int param) -{ - switch (id) - { - case TIMER_END_CB: - timer_end(); - break; - default: - throw emu_fatalerror("Unknown id in riot6532_device::device_timer"); - } -} diff --git a/src/devices/machine/6532riot.h b/src/devices/machine/6532riot.h index a14de90483a..56156f929c3 100644 --- a/src/devices/machine/6532riot.h +++ b/src/devices/machine/6532riot.h @@ -64,8 +64,6 @@ public: uint8_t porta_out_get(); uint8_t portb_out_get(); - void timer_end(); - protected: class riot6532_port { @@ -80,10 +78,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; virtual void device_post_load() override { } virtual void device_clock_changed() override { } + TIMER_CALLBACK_MEMBER(timer_end); private: void update_irqstate(); @@ -91,29 +89,24 @@ private: void update_pa7_state(); uint8_t get_timer(); - riot6532_port m_port[2]; + riot6532_port m_port[2]; - devcb_read8 m_in_pa_cb; - devcb_write8 m_out_pa_cb; - devcb_read8 m_in_pb_cb; - devcb_write8 m_out_pb_cb; - devcb_write_line m_irq_cb; + devcb_read8 m_in_pa_cb; + devcb_write8 m_out_pa_cb; + devcb_read8 m_in_pb_cb; + devcb_write8 m_out_pb_cb; + devcb_write_line m_irq_cb; uint8_t m_irqstate; uint8_t m_irqenable; - int m_irq; + int m_irq; uint8_t m_pa7dir; /* 0x80 = high-to-low, 0x00 = low-to-high */ uint8_t m_pa7prev; uint8_t m_timershift; uint8_t m_timerstate; - emu_timer * m_timer; - - enum - { - TIMER_END_CB - }; + emu_timer * m_timer; }; diff --git a/src/devices/machine/68230pit.cpp b/src/devices/machine/68230pit.cpp index 0512464a3ab..d5aeafd4c76 100644 --- a/src/devices/machine/68230pit.cpp +++ b/src/devices/machine/68230pit.cpp @@ -24,12 +24,11 @@ #include "emu.h" #include "68230pit.h" -#define LOG_GENERAL 0x01 -#define LOG_SETUP 0x02 -#define LOG_READ 0x04 -#define LOG_BIT 0x08 -#define LOG_DR 0x10 -#define LOG_INT 0x20 +#define LOG_SETUP (1U << 1) +#define LOG_READ (1U << 2) +#define LOG_BIT (1U << 3) +#define LOG_DR (1U << 4) +#define LOG_INT (1U << 5) #define VERBOSE 0 //(LOG_SETUP | LOG_GENERAL | LOG_INT | LOG_BIT | LOG_DR) #include "logmacro.h" @@ -40,12 +39,6 @@ #define LOGDR(...) LOGMASKED(LOG_DR, __VA_ARGS__) #define LOGINT(...) LOGMASKED(LOG_INT, __VA_ARGS__) -#ifdef _MSC_VER -#define FUNCNAME __func__ -#else -#define FUNCNAME __PRETTY_FUNCTION__ -#endif - //************************************************************************** // DEVICE TYPE DEFINITIONS //************************************************************************** @@ -102,9 +95,9 @@ pit68230_device::pit68230_device(const machine_config &mconfig, const char *tag, //------------------------------------------------- // device_start - device-specific startup //------------------------------------------------- -void pit68230_device::device_start () +void pit68230_device::device_start() { - LOGSETUP("%s\n", FUNCNAME); + LOGSETUP("pit68230_device::device_start\n"); // NOTE: // Not using resolve_safe for the m_px_in_cb's is a temporary way to be able to check @@ -132,7 +125,7 @@ void pit68230_device::device_start () m_pirq_out_cb.resolve_safe(); // Timers - pit_timer = timer_alloc(TIMER_ID_PIT); + pit_timer = timer_alloc(FUNC(pit68230_device::tick_clock), this); // state saving save_item(NAME(m_pgcr)); @@ -157,9 +150,9 @@ void pit68230_device::device_start () //------------------------------------------------- // device_reset - device-specific reset //------------------------------------------------- -void pit68230_device::device_reset () +void pit68230_device::device_reset() { - LOGSETUP("%s %s \n",tag(), FUNCNAME); + LOGSETUP("pit68230_device::device_reset %s\n", tag()); m_pgcr = 0; m_psrr = 0; @@ -176,7 +169,7 @@ void pit68230_device::device_reset () m_tcr = 0; m_tivr = 0x0f; m_tirq_out_cb(CLEAR_LINE); m_tsr = 0; - LOGSETUP("%s %s DONE!\n",tag(), FUNCNAME); + LOGSETUP("pit68230_device::device_reset %s DONE!\n",tag()); } /* @@ -184,7 +177,7 @@ void pit68230_device::device_reset () */ uint8_t pit68230_device::irq_piack() { - LOGINT("%s %s <- %02x\n",tag(), FUNCNAME, m_pivr); + LOGINT("%s pit68230_device::irq_piack <- %02x\n",tag(), m_pivr); return m_pivr; } @@ -193,7 +186,7 @@ uint8_t pit68230_device::irq_piack() */ uint8_t pit68230_device::irq_tiack() { - LOGINT("%s %s <- %02x\n",tag(), FUNCNAME, m_tivr); + LOGINT("%s pit68230_device::irq_tiack <- %02x\n", tag(), m_tivr); return m_tivr; } @@ -203,13 +196,13 @@ uint8_t pit68230_device::irq_tiack() */ void pit68230_device::trigger_interrupt(int source) { - LOGINT("%s %s Source: %02x\n",tag(), FUNCNAME, source); + LOGINT("%s pit68230_device::trigger_interrupt Source: %02x\n", tag(), source); if (source == INT_TIMER) { // TODO: implement priorities and support nested interrupts - if ( (m_tcr & REG_TCR_TOUT_TIACK_MASK) == REG_TCR_TOUT_TIACK_INT || - (m_tcr & REG_TCR_TOUT_TIACK_MASK) == REG_TCR_TOUT_PC7_INT ) + if ((m_tcr & REG_TCR_TOUT_TIACK_MASK) == REG_TCR_TOUT_TIACK_INT || + (m_tcr & REG_TCR_TOUT_TIACK_MASK) == REG_TCR_TOUT_PC7_INT) { m_tirq_out_cb(ASSERT_LINE); } @@ -221,7 +214,7 @@ void pit68230_device::trigger_interrupt(int source) } } -void pit68230_device::tick_clock() +TIMER_CALLBACK_MEMBER(pit68230_device::tick_clock) { if (m_tcr & REG_TCR_TIMER_ENABLE) { @@ -238,25 +231,9 @@ void pit68230_device::tick_clock() } } -//------------------------------------------------- -// device_timer - handler timer events -//------------------------------------------------- -void pit68230_device::device_timer (emu_timer &timer, device_timer_id id, int param) -{ - switch(id) - { - case TIMER_ID_PIT: - tick_clock(); - break; - default: - LOG("Unhandled Timer ID %d\n", id); - break; - } -} - WRITE_LINE_MEMBER( pit68230_device::h1_w ) { - LOGBIT("%s %s H1 set to %d\n", tag(), FUNCNAME, state); + LOGBIT("%s pit68230_device::h1_w H1 set to %d\n", tag(), state); // Set the direct level in PSR m_psr = ((state == 0) ? (m_psr & ~REG_PSR_H1L) : (m_psr | REG_PSR_H1L)); @@ -270,7 +247,7 @@ WRITE_LINE_MEMBER( pit68230_device::h1_w ) WRITE_LINE_MEMBER( pit68230_device::h2_w ) { - LOGBIT("%s %s H2 set to %d\n", tag(), FUNCNAME, state); + LOGBIT("%s pit68230_device::h2_w H2 set to %d\n", tag(), state); // Set the direct level in PSR m_psr = ((state == 0) ? (m_psr & ~REG_PSR_H2L) : (m_psr | REG_PSR_H2L)); @@ -284,7 +261,7 @@ WRITE_LINE_MEMBER( pit68230_device::h2_w ) WRITE_LINE_MEMBER( pit68230_device::h3_w ) { - LOGBIT("%s %s H3 set to %d\n", tag(), FUNCNAME, state); + LOGBIT("%s pit68230_device::h3_w H3 set to %d\n", tag(), state); // Set the direct level in PSR m_psr = ((state == 0) ? (m_psr & ~REG_PSR_H3L) : (m_psr | REG_PSR_H3L)); @@ -298,7 +275,7 @@ WRITE_LINE_MEMBER( pit68230_device::h3_w ) WRITE_LINE_MEMBER( pit68230_device::h4_w ) { - LOGBIT("%s %s H4 set to %d\n", tag(), FUNCNAME, state); + LOGBIT("%s pit68230_device::h4_w H4 set to %d\n", tag(), state); // Set the direct level in PSR m_psr = ((state == 0) ? (m_psr & ~REG_PSR_H4L) : (m_psr | REG_PSR_H4L)); @@ -313,14 +290,17 @@ WRITE_LINE_MEMBER( pit68230_device::h4_w ) // TODO: remove this method and replace it with a call to pb_update_bit() in force68k.cpp void pit68230_device::portb_setbit(uint8_t bit, uint8_t state) { - if (state) m_pbdr |= (1 << bit); else m_pbdr &= ~(1 << bit); + if (state) + m_pbdr |= (1 << bit); + else + m_pbdr &= ~(1 << bit); } void pit68230_device::pa_update_bit(uint8_t bit, uint8_t state) { - LOGBIT("%s %s bit %d to %d\n", tag(), FUNCNAME, bit, state); + LOGBIT("%s pit68230_device::pa_update_bit bit %d to %d\n", tag(), bit, state); // Check if requested bit is an output bit and can't be affected - if (m_paddr & (1 << bit)) + if (BIT(m_paddr, bit)) { LOG("- 68230 PIT: tried to set input bit at port A that is programmed as output!\n"); return; @@ -339,9 +319,9 @@ void pit68230_device::pa_update_bit(uint8_t bit, uint8_t state) void pit68230_device::pb_update_bit(uint8_t bit, uint8_t state) { - LOGBIT("%s %s bit %d to %d\n",tag(), FUNCNAME, bit, state); + LOGBIT("%s pit68230_device::pb_update_bit bit %d to %d\n", tag(), bit, state); // Check if requested bit is an output bit and can't be affected - if (m_pbddr & (1 << bit)) + if (BIT(m_pbddr, bit)) { LOG("- 68230 PIT: tried to set input bit at port B that is programmed as output!\n"); return; @@ -361,9 +341,9 @@ void pit68230_device::pb_update_bit(uint8_t bit, uint8_t state) // TODO: Make sure port C is in the right alternate mode void pit68230_device::pc_update_bit(uint8_t bit, uint8_t state) { - LOGBIT("%s %s bit %d to %d\n",tag(), FUNCNAME, bit, state); + LOGBIT("%s pit68230_device::pc_update_bit bit %d to %d\n", tag(), bit, state); // Check if requested bit is an output bit and can't be affected - if (m_pcddr & (1 << bit)) + if (BIT(m_pcddr, bit)) { LOG("- 68230 PIT: tried to set input bit at port C that is programmed as output!\n"); return; @@ -385,7 +365,7 @@ void pit68230_device::update_tin(uint8_t state) // Tick clock on falling edge. TODO: check what flank is correct if (state == CLEAR_LINE) { - tick_clock(); + tick_clock(0); } pc_update_bit(REG_PCDR_TIN_BIT, state == ASSERT_LINE ? 0 : 1); @@ -399,9 +379,9 @@ static int32_t ow_ofs = 0; void pit68230_device::wr_pitreg_pgcr(uint8_t data) { - LOG("%s(%02x) \"%s\": %s - %02x\n", FUNCNAME, data, tag(), FUNCNAME, data); - LOGSETUP("PGCR - Mode %d,", (data >> 6) & 3 ); - LOGSETUP(" H34:%s, H12:%s,", (data & 0x20) ? "enabled" : "disabled", (data & 0x10) ? "enabled" : "disabled" ); + LOG("pit68230_device::wr_pitreg_pgcr(%02x) \"%s\": pit68230_device::wr_pitreg_pgcr - %02x\n", data, tag(), data); + LOGSETUP("PGCR - Mode %d,", (data >> 6) & 3); + LOGSETUP(" H34:%s, H12:%s,", (data & 0x20) ? "enabled" : "disabled", (data & 0x10) ? "enabled" : "disabled"); LOGSETUP(" Sense assert H4:%s, H3:%s, H2:%s, H1:%s\n", data & 0x04 ? "Hi" : "Lo", data & 0x03 ? "Hi" : "Lo", data & 0x02 ? "Hi" : "Lo", data & 0x01 ? "Hi" : "Lo"); @@ -410,18 +390,18 @@ void pit68230_device::wr_pitreg_pgcr(uint8_t data) void pit68230_device::wr_pitreg_psrr(uint8_t data) { - LOG("%s(%02x) \"%s\": %s - %02x\n", FUNCNAME, data, tag(), FUNCNAME, data); + LOG("pit68230_device::wr_pitreg_psrr(%02x) \"%s\": pit68230_device::wr_pitreg_psrr - %02x\n", data, tag(), data); LOGSETUP("PSSR - %s pin activated,", data & 0x40 ? "DMA" : "PC4"); LOGSETUP(" %s pin support %s interrupts,", data & 0x80 ? "PIRQ" : "PC5", - data & 0x08 ? "no" : (data & 0x10 ? "vectored" : "autovectored" ) ); - LOGSETUP(" H prio mode:%d\n", data & 0x03 ); + data & 0x08 ? "no" : (data & 0x10 ? "vectored" : "autovectored")); + LOGSETUP(" H prio mode:%d\n", data & 0x03); m_psrr = data; } void pit68230_device::wr_pitreg_paddr(uint8_t data) { - LOG("%s(%02x) \"%s\": %s - %02x\n", FUNCNAME, data, tag(), FUNCNAME, data); + LOG("pit68230_device::wr_pitreg_paddr(%02x) \"%s\": pit68230_device::wr_pitreg_paddr - %02x\n", data, tag(), data); LOGSETUP("%s PADDR: %02x\n", tag(), data); m_paddr = data; } @@ -434,21 +414,21 @@ void pit68230_device::wr_pitreg_pbddr(uint8_t data) void pit68230_device::wr_pitreg_pcddr(uint8_t data) { - LOG("%s(%02x) \"%s\": %s - %02x\n", FUNCNAME, data, tag(), FUNCNAME, data); + LOG("pit68230_device::wr_pitreg_pcddr(%02x) \"%s\": pit68230_device::wr_pitreg_pcddr - %02x\n", data, tag(), data); LOGSETUP("%s PCDDR: %02x\n", tag(), data); m_pcddr = data; } void pit68230_device::wr_pitreg_pivr(uint8_t data) { - LOG("%s(%02x) \"%s\": %s - %02x\n", FUNCNAME, data, tag(), FUNCNAME, data); + LOG("pit68230_device::wr_pitreg_pivr(%02x) \"%s\": pit68230_device::wr_pitreg_pivr - %02x\n", data, tag(), data); LOGSETUP("%s PIVR: %02x\n", tag(), data); m_pivr = data & 0xfc; // lowest two bits are read as zero } void pit68230_device::wr_pitreg_pacr(uint8_t data) { - LOG("%s(%02x) \"%s\": %s - %02x\n", FUNCNAME, data, tag(), FUNCNAME, data); + LOG("pit68230_device::wr_pitreg_pacr(%02x) \"%s\": pit68230_device::wr_pitreg_pacr - %02x\n", data, tag(), data); LOGSETUP("%s PACR", tag()); m_pacr = data; // callbacks @@ -471,7 +451,7 @@ void pit68230_device::wr_pitreg_pacr(uint8_t data) { if (m_pacr & REG_PACR_H2_CTRL_IN_OUT) { - switch(m_pacr & REG_PACR_H2_CTRL_MASK) + switch (m_pacr & REG_PACR_H2_CTRL_MASK) { case REG_PACR_H2_CTRL_OUT_00: LOGSETUP(" - H2 cleared\n"); @@ -487,7 +467,7 @@ void pit68230_device::wr_pitreg_pacr(uint8_t data) case REG_PACR_H2_CTRL_OUT_11: LOGSETUP(" - pulsed handshake not implemented\n"); break; - default: logerror(("Undefined H2 mode, broken driver - please report!\n")); + default: logerror("Undefined H2 mode %02x in pit68230_device - please report\n", m_pacr & REG_PACR_H2_CTRL_MASK); } } } @@ -501,13 +481,13 @@ void pit68230_device::wr_pitreg_pacr(uint8_t data) // TODO add support for sense status void pit68230_device::wr_pitreg_pbcr(uint8_t data) { - LOG("%s(%02x) \"%s\": %s - %02x\n", FUNCNAME, data, tag(), FUNCNAME, data); + LOG("pit68230_device::wr_pitreg_pbcr(%02x) \"%s\": pit68230_device::wr_pitreg_pbcr - %02x\n", data, tag(), data); m_pbcr = data; if ((m_pgcr & REG_PGCR_H34_ENABLE) || ((m_pbcr & REG_PBCR_SUBMODE_MASK) == REG_PBCR_SUBMODE_1X)) { if (m_pbcr & REG_PBCR_H4_CTRL_IN_OUT) { - switch(m_pbcr & REG_PBCR_H4_CTRL_MASK) + switch (m_pbcr & REG_PBCR_H4_CTRL_MASK) { case REG_PBCR_H4_CTRL_OUT_00: LOG(" - H4 cleared\n"); @@ -523,7 +503,7 @@ void pit68230_device::wr_pitreg_pbcr(uint8_t data) case REG_PBCR_H4_CTRL_OUT_11: LOGSETUP(" - pulsed handshake not implemented\n"); break; - default: logerror(("Undefined H4 mode, broken driver - please report!\n")); + default: logerror("Undefined H4 mode %02x in pit68230_device - please report\n", m_pbcr & REG_PBCR_H4_CTRL_MASK); } } } @@ -536,34 +516,34 @@ void pit68230_device::wr_pitreg_pbcr(uint8_t data) void pit68230_device::wr_pitreg_padr(uint8_t data) { - LOG("%s(%02x) \"%s\": %s - %02x\n", FUNCNAME, data, tag(), FUNCNAME, data); - m_padr = (data & m_paddr); + LOG("pit68230_device::wr_pitreg_padr(%02x) \"%s\": pit68230_device::wr_pitreg_padr - %02x\n", data, tag(), data); + m_padr = data & m_paddr; // callback - m_pa_out_cb ((offs_t)0, m_padr); + m_pa_out_cb(m_padr); } void pit68230_device::wr_pitreg_pbdr(uint8_t data) { - LOG("%s(%02x) \"%s\": %s - %02x\n", FUNCNAME, data, tag(), FUNCNAME, data); - m_pbdr = (data & m_pbddr); + LOG("pit68230_device::wr_pitreg_pbdr(%02x) \"%s\": pit68230_device::wr_pitreg_pbdr - %02x\n", data, tag(), data); + m_pbdr = data & m_pbddr; // callback - m_pb_out_cb ((offs_t)0, m_pbdr & m_pbddr); + m_pb_out_cb(m_pbdr & m_pbddr); } void pit68230_device::wr_pitreg_pcdr(uint8_t data) { - LOG("%s(%02x) \"%s\": %s - %02x\n", FUNCNAME, data, tag(), FUNCNAME, data); - m_pcdr = (data & m_pcddr); + LOG("pit68230_device::wr_pitreg_pcdr(%02x) \"%s\": pit68230_device::wr_pitreg_pcdr - %02x\n", data, tag(), data); + m_pcdr = data & m_pcddr; // callback - m_pc_out_cb ((offs_t)0, m_pcdr); + m_pc_out_cb(m_pcdr); } void pit68230_device::wr_pitreg_psr(uint8_t data) { - LOG("%s(%02x) \"%s\": %s - %02x\n", FUNCNAME, data, tag(), FUNCNAME, data); + LOG("pit68230_device::wr_pitreg_psr(%02x) \"%s\": pit68230_device::wr_pitreg_psr - %02x\n", data, tag(), data); m_psr = data; } @@ -639,7 +619,7 @@ void pit68230_device::wr_pitreg_tcr(uint8_t data) int pen = 0; //int sqr = 0; - LOG("%s(%02x) %s\n", FUNCNAME, data, tag()); + LOG("pit68230_device::wr_pitreg_tcr(%02x) %s\n", data, tag()); m_tcr = data; switch (m_tcr & REG_TCR_TOUT_TIACK_MASK) { @@ -674,46 +654,46 @@ void pit68230_device::wr_pitreg_tcr(uint8_t data) if (clk == 1) { int rate = clock() / (psc == 1 ? 32 : 1); - pit_timer->adjust(attotime::from_hz(rate), TIMER_ID_PIT, attotime::from_hz(rate)); + pit_timer->adjust(attotime::from_hz(rate), 0, attotime::from_hz(rate)); LOG("PIT timer started @ rate: %d and CLK: %d,\n", rate, clock()); } } else { - pit_timer->adjust(attotime::never, TIMER_ID_PIT, attotime::never); + pit_timer->adjust(attotime::never, 0, attotime::never); } } void pit68230_device::wr_pitreg_tivr(uint8_t data) { - LOG("%s(%02x) \"%s\": \n", FUNCNAME, data, tag()); + LOG("pit68230_device::wr_pitreg_tivr(%02x) \"%s\": \n", data, tag()); m_tivr = data; } void pit68230_device::wr_pitreg_cprh(uint8_t data) { - LOG("%s(%02x) \"%s\": %s - %02x\n", FUNCNAME, data, tag(), FUNCNAME, data); + LOG("pit68230_device::wr_pitreg_cprh(%02x) \"%s\": pit68230_device::wr_pitreg_cprh - %02x\n", data, tag(), data); m_cpr &= ~0xff0000; m_cpr |= ((data << 16) & 0xff0000); } void pit68230_device::wr_pitreg_cprm(uint8_t data) { - LOG("%s(%02x) \"%s\": %s - %02x\n", FUNCNAME, data, tag(), FUNCNAME, data); + LOG("pit68230_device::wr_pitreg_cprm(%02x) \"%s\": pit68230_device::wr_pitreg_cprm - %02x\n", data, tag(), data); m_cpr &= ~0x00ff00; m_cpr |= ((data << 8) & 0x00ff00); } void pit68230_device::wr_pitreg_cprl(uint8_t data) { - LOG("%s(%02x) \"%s\": %s - %02x\n", FUNCNAME, data, tag(), FUNCNAME, data); + LOG("pit68230_device::wr_pitreg_cprl(%02x) \"%s\": pit68230_device::wr_pitreg_cprl - %02x\n", data, tag(), data); m_cpr &= ~0x0000ff; - m_cpr |= ((data << 0) & 0x0000ff); + m_cpr |= data & 0x0000ff; } void pit68230_device::wr_pitreg_tsr(uint8_t data) { - LOG("%s(%02x) \"%s\": \n", FUNCNAME, data, tag()); + LOG("pit68230_device::wr_pitreg_tsr(%02x) \"%s\": \n", data, tag()); if (data & 1) { m_tsr = 0; // A write resets the TSR; @@ -723,9 +703,10 @@ void pit68230_device::wr_pitreg_tsr(uint8_t data) void pit68230_device::write(offs_t offset, uint8_t data) { - LOG("\"%s\" %s: Register write '%02x' -> [%02x]\n", tag(), FUNCNAME, data, offset ); + LOG("\"%s\" pit68230_device::write: Register write '%02x' -> [%02x]\n", tag(), data, offset); LOGSETUP(" * %s Reg %02x <- %02x \n", tag(), offset, data); - switch (offset) { + switch (offset) + { case PIT_68230_PGCR: wr_pitreg_pgcr(data); break; case PIT_68230_PSRR: wr_pitreg_psrr(data); break; case PIT_68230_PADDR: wr_pitreg_paddr(data); break; @@ -754,7 +735,8 @@ void pit68230_device::write(offs_t offset, uint8_t data) } #if VERBOSE > 2 - if (offset != ow_ofs || data != ow_data || ow_cnt >= 1000) { + if (offset != ow_ofs || data != ow_data || ow_cnt >= 1000) + { if (ow_cnt > 1) { logerror ("\npit68230_device::write: previous identical operation performed %02x times\n", ow_cnt); @@ -778,49 +760,49 @@ static int32_t or_ofs = 0; uint8_t pit68230_device::rr_pitreg_pgcr() { - LOGR("%s %s <- %02x\n",tag(), FUNCNAME, m_pgcr); + LOGR("%s pit68230_device::rr_pitreg_pgcr <- %02x\n", tag(), m_pgcr); return m_pgcr; } uint8_t pit68230_device::rr_pitreg_psrr() { - LOGR("%s %s <- %02x\n",tag(), FUNCNAME, m_psrr); + LOGR("%s pit68230_device::rr_pitreg_psrr <- %02x\n", tag(), m_psrr); return m_psrr & 0x7f; // mask out unused bits } uint8_t pit68230_device::rr_pitreg_paddr() { - LOGR("%s %s <- %02x\n",tag(), FUNCNAME, m_paddr); + LOGR("%s pit68230_device::rr_pitreg_paddr <- %02x\n", tag(), m_paddr); return m_paddr; } uint8_t pit68230_device::rr_pitreg_pbddr() { - LOGR("%s %s <- %02x\n",tag(), FUNCNAME, m_pbddr); + LOGR("%s pit68230_device::rr_pitreg_pbddr <- %02x\n", tag(), m_pbddr); return m_pbddr; } uint8_t pit68230_device::rr_pitreg_pcddr() { - LOGR("%s %s <- %02x\n",tag(), FUNCNAME, m_pcddr); + LOGR("%s pit68230_device::rr_pitreg_pcddr <- %02x\n", tag(), m_pcddr); return m_pcddr; } uint8_t pit68230_device::rr_pitreg_pivr() { - LOGR("%s %s <- %02x\n",tag(), FUNCNAME, m_pivr); + LOGR("%s pit68230_device::rr_pitreg_pivr <- %02x\n", tag(), m_pivr); return m_pivr; } uint8_t pit68230_device::rr_pitreg_pacr() { - LOGR("%s %s <- %02x\n",tag(), FUNCNAME, m_pacr); + LOGR("%s pit68230_device::rr_pitreg_pacr <- %02x\n", tag(), m_pacr); return m_pacr; } uint8_t pit68230_device::rr_pitreg_pbcr() { - LOGR("%s %s <- %02x\n",tag(), FUNCNAME, m_pbcr); + LOGR("%s pit68230_device::rr_pitreg_pbcr <- %02x\n", tag(), m_pbcr); return m_pbcr; } @@ -829,13 +811,13 @@ uint8_t pit68230_device::rr_pitreg_padr() m_padr &= m_paddr; if (!m_pa_in_cb.isnull()) { - m_padr |= (m_pa_in_cb() & ~m_paddr); + m_padr |= m_pa_in_cb() & ~m_paddr; } else { - m_padr |= (m_pail & ~m_paddr); + m_padr |= m_pail & ~m_paddr; } - LOGDR("%s %s <- %02x\n",tag(), FUNCNAME, m_padr); + LOGDR("%s pit68230_device::rr_pitreg_padr <- %02x\n", tag(), m_padr); return m_padr; } @@ -851,14 +833,14 @@ uint8_t pit68230_device::rr_pitreg_pbdr() m_pbdr &= m_pbddr; if (!m_pb_in_cb.isnull()) { - m_pbdr |= (m_pb_in_cb() & ~m_pbddr); + m_pbdr |= m_pb_in_cb() & ~m_pbddr; } else { - m_pbdr |= (m_pbil & ~m_pbddr); + m_pbdr |= m_pbil & ~m_pbddr; } - LOGDR("%s %s <- %02x\n",tag(), FUNCNAME, m_pbdr); + LOGDR("%s pit68230_device::rr_pitreg_pbdr <- %02x\n", tag(), m_pbdr); return m_pbdr; } @@ -868,14 +850,17 @@ uint8_t pit68230_device::rr_pitreg_pcdr() m_pcdr &= m_pcddr; if (!m_pc_in_cb.isnull()) // Port C has alternate functions that may set bits apart from callback { - m_pcdr |= (m_pc_in_cb() & ~m_pcddr); + m_pcdr |= m_pc_in_cb() & ~m_pcddr; } else { - m_pcdr |= (m_pcil & ~m_pcddr); + m_pcdr |= m_pcil & ~m_pcddr; } - if (m_pcdr != 0) { LOGDR("%s %s <- %02x\n",tag(), FUNCNAME, m_pcdr); } + if (m_pcdr != 0) + { + LOGDR("%s pit68230_device::rr_pitreg_pcdr <- %02x\n", tag(), m_pcdr); + } return m_pcdr; } @@ -886,9 +871,8 @@ the instantaneous pin level is read and no input latching is performed except at data bus interface. Writes to this address are answered with DTACK, but the data is ignored.*/ uint8_t pit68230_device::rr_pitreg_paar() { - uint8_t ret; - ret = m_pa_in_cb.isnull() ? 0 : m_pa_in_cb(); - LOGR("%s %s <- %02x\n",tag(), FUNCNAME, ret); + uint8_t ret = m_pa_in_cb.isnull() ? 0 : m_pa_in_cb(); + LOGR("%s pit68230_device::rr_pitreg_paar <- %02x\n", tag(), ret); return ret; } @@ -898,9 +882,8 @@ the instantaneous pin level is read and no input latching is performed except at data bus interface.Writes to this address are answered with DTACK, but the data is ignored.*/ uint8_t pit68230_device::rr_pitreg_pbar() { - uint8_t ret; - ret = m_pb_in_cb.isnull() ? 0 : m_pb_in_cb(); - LOGR("%s %s <- %02x\n",tag(), FUNCNAME, ret); + uint8_t ret = m_pb_in_cb.isnull() ? 0 : m_pb_in_cb(); + LOGR("%s pit68230_device::rr_pitreg_pbar <- %02x\n", tag(), ret); return ret; } @@ -912,68 +895,70 @@ uint8_t pit68230_device::rr_pitreg_pbar() * 3-0 a one is the active or asserted state. */ uint8_t pit68230_device::rr_pitreg_psr() { - LOGR("%s %s <- %02x\n",tag(), FUNCNAME, m_psr); + LOGR("%s pit68230_device::rr_pitreg_psr <- %02x\n", tag(), m_psr); return m_psr; } uint8_t pit68230_device::rr_pitreg_tcr() { - LOGR("%s %s <- %02x\n",tag(), FUNCNAME, m_tcr); + LOGR("%s pit68230_device::rr_pitreg_tcr <- %02x\n", tag(), m_tcr); return m_tcr; } uint8_t pit68230_device::rr_pitreg_tivr() { - LOGR("%s %s <- %02x\n",tag(), FUNCNAME, m_tivr); + LOGR("%s pit68230_device::rr_pitreg_tivr <- %02x\n", tag(), m_tivr); return m_tivr; } uint8_t pit68230_device::rr_pitreg_cprh() { - LOGR("%s %s <- %02x\n",tag(), FUNCNAME, (m_cpr >> 16) & 0xff); + LOGR("%s pit68230_device::rr_pitreg_cprh <- %02x\n", tag(), (m_cpr >> 16) & 0xff); return (m_cpr >> 16) & 0xff; } uint8_t pit68230_device::rr_pitreg_cprm() { - LOGR("%s %s <- %02x\n",tag(), FUNCNAME, (m_cpr >> 8) & 0xff); + LOGR("%s pit68230_device::rr_pitreg_cprm <- %02x\n", tag(), (m_cpr >> 8) & 0xff); return (m_cpr >> 8) & 0xff; } uint8_t pit68230_device::rr_pitreg_cprl() { - LOGR("%s %s <- %02x\n",tag(), FUNCNAME, (m_cpr >> 0) & 0xff); - return (m_cpr >> 0) & 0xff; + LOGR("%s pit68230_device::rr_pitreg_cprl <- %02x\n", tag(), m_cpr & 0xff); + return m_cpr & 0xff; } uint8_t pit68230_device::rr_pitreg_cntrh() { - LOGR("%s %s <- %02x\n",tag(), FUNCNAME, (m_cntr >> 16) & 0xff); + LOGR("%s pit68230_device::rr_pitreg_cntrh <- %02x\n", tag(), (m_cntr >> 16) & 0xff); return (m_cntr >> 16) & 0xff; } uint8_t pit68230_device::rr_pitreg_cntrm() { - LOGR("%s %s <- %02x\n",tag(), FUNCNAME, (m_cntr >> 8) & 0xff); + LOGR("%s pit68230_device::rr_pitreg_cntrm <- %02x\n", tag(), (m_cntr >> 8) & 0xff); return (m_cntr >> 8) & 0xff; } uint8_t pit68230_device::rr_pitreg_cntrl() { - LOGR("%s %s <- %02x\n",tag(), FUNCNAME, (m_cntr >> 0) & 0xff); - return (m_cntr >> 0) & 0xff; + LOGR("%s pit68230_device::rr_pitreg_cntrl <- %02x\n", tag(), m_cntr & 0xff); + return m_cntr & 0xff; } uint8_t pit68230_device::rr_pitreg_tsr() { - LOGR("%s %s <- %02x\n",tag(), FUNCNAME, m_tsr); + LOGR("%s pit68230_device::rr_pitreg_tsr <- %02x\n", tag(), m_tsr); return m_tsr; } -uint8_t pit68230_device::read(offs_t offset){ +uint8_t pit68230_device::read(offs_t offset) +{ uint8_t data; - switch (offset) { + switch (offset) + { case PIT_68230_PGCR: data = rr_pitreg_pgcr(); break; case PIT_68230_PSRR: data = rr_pitreg_psrr(); break; case PIT_68230_PADDR: data = rr_pitreg_paddr(); break; @@ -1003,12 +988,13 @@ uint8_t pit68230_device::read(offs_t offset){ } #if VERBOSE > 2 - if (offset != or_ofs || data != or_data || or_cnt >= 1000) { + if (offset != or_ofs || data != or_data || or_cnt >= 1000) + { LOGSETUP(" * %s Reg %02x -> %02x \n", tag(), offset, data); if (or_cnt > 1) { - logerror ("\npit68230_device::read: previous identical operation performed %02x times\n", or_cnt); - logerror (" - pit68230_device::read: offset=%02x data=%02x %s\n", offset, data, machine().describe_context()); + logerror("\npit68230_device::read: previous identical operation performed %02x times\n", or_cnt); + logerror(" - pit68230_device::read: offset=%02x data=%02x %s\n", offset, data, machine().describe_context()); } or_cnt = 0; or_data = data; diff --git a/src/devices/machine/68230pit.h b/src/devices/machine/68230pit.h index 560006e3b18..f99c3e541ee 100644 --- a/src/devices/machine/68230pit.h +++ b/src/devices/machine/68230pit.h @@ -68,7 +68,7 @@ //************************************************************************** // TYPE DEFINITIONS //************************************************************************** -class pit68230_device : public device_t//, public device_execute_interface +class pit68230_device : public device_t { public: // construction/destruction @@ -272,19 +272,16 @@ protected: REG_TCR_TOUT_PC7_INT = 0xe0, // 1 1 1 }; - void tick_clock(); - pit68230_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock, uint32_t variant); // 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; // Interrupt methods void trigger_interrupt(int source); - int m_icount; + TIMER_CALLBACK_MEMBER(tick_clock); devcb_write8 m_pa_out_cb; devcb_read8 m_pa_in_cb; @@ -330,11 +327,6 @@ protected: // Timers emu_timer *pit_timer; - - enum - { - TIMER_ID_PIT - }; }; // device type definition diff --git a/src/devices/machine/68307tmu.cpp b/src/devices/machine/68307tmu.cpp index 474dd2ef19b..8800387be64 100644 --- a/src/devices/machine/68307tmu.cpp +++ b/src/devices/machine/68307tmu.cpp @@ -132,12 +132,12 @@ void m68307_cpu_device::m68307_timer::init(m68307_cpu_device *device) single_timer* tptr; tptr = &singletimer[0]; - tptr->mametimer = device->machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(m68307_timer::timer0_callback),this)); + tptr->mametimer = device->timer_alloc(FUNC(m68307_timer::timer0_callback), this); tptr = &singletimer[1]; - tptr->mametimer = device->machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(m68307_timer::timer1_callback),this)); + tptr->mametimer = device->timer_alloc(FUNC(m68307_timer::timer1_callback), this); - wd_mametimer = device->machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(m68307_timer::wd_timer_callback),this)); + wd_mametimer = device->timer_alloc(FUNC(m68307_timer::wd_timer_callback), this); } uint16_t m68307_cpu_device::m68307_timer::read_tcn(uint16_t mem_mask, int which) diff --git a/src/devices/machine/68340sim.cpp b/src/devices/machine/68340sim.cpp index 7e1f8457224..865a7eafc52 100644 --- a/src/devices/machine/68340sim.cpp +++ b/src/devices/machine/68340sim.cpp @@ -438,7 +438,7 @@ void m68340_cpu_device::start_68340_sim() { LOG("%s\n", FUNCNAME); LOGCLOCK( " - Clock: %d [0x%08x]\n", clock(), clock()); - m_irq_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(m68340_cpu_device::periodic_interrupt_timer_callback),this)); + m_irq_timer = timer_alloc(FUNC(m68340_cpu_device::periodic_interrupt_timer_callback), this); // resolve callbacks Port A m_pa_out_cb.resolve_safe(); diff --git a/src/devices/machine/68340tmu.cpp b/src/devices/machine/68340tmu.cpp index 96157eafc53..6eddadf6f94 100644 --- a/src/devices/machine/68340tmu.cpp +++ b/src/devices/machine/68340tmu.cpp @@ -312,7 +312,7 @@ void mc68340_timer_module_device::device_start() m_cpu = downcast<m68340_cpu_device *>(owner()); - m_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(mc68340_timer_module_device::timer_callback),this)); + m_timer = timer_alloc(FUNC(mc68340_timer_module_device::timer_callback), this); // Resolve Timer callbacks m_tout_out_cb.resolve_safe(); diff --git a/src/devices/machine/6840ptm.cpp b/src/devices/machine/6840ptm.cpp index 9d37533917a..8d0039e2a92 100644 --- a/src/devices/machine/6840ptm.cpp +++ b/src/devices/machine/6840ptm.cpp @@ -95,9 +95,9 @@ void ptm6840_device::device_start() m_out_cb.resolve_all_safe(); m_irq_cb.resolve_safe(); - m_timer[0] = timer_alloc(0); - m_timer[1] = timer_alloc(1); - m_timer[2] = timer_alloc(2); + m_timer[0] = timer_alloc(FUNC(ptm6840_device::timeout), this); + m_timer[1] = timer_alloc(FUNC(ptm6840_device::timeout), this); + m_timer[2] = timer_alloc(FUNC(ptm6840_device::timeout), this); for (auto & elem : m_timer) { @@ -162,15 +162,6 @@ void ptm6840_device::device_resolve_objects() m_gate[i] = 0; } -//------------------------------------------------- -// device_timer - handle timer callbacks -//------------------------------------------------- - -void ptm6840_device::device_timer(emu_timer &timer, device_timer_id id, int param) -{ - timeout(id); -} - //------------------------------------------------- // subtract_from_counter - Subtract from Counter @@ -246,7 +237,7 @@ void ptm6840_device::subtract_from_counter(int counter, int count) { duration *= m_t3_divisor; } - m_timer[counter]->adjust(duration); + m_timer[counter]->adjust(duration, counter); } } @@ -429,7 +420,7 @@ void ptm6840_device::reload_count(int idx) LOGMASKED(LOG_COUNTERS, "Timer #%d reload_count: output = %f\n", idx + 1, duration.as_double()); m_enabled[idx] = 1; - m_timer[idx]->adjust(duration); + m_timer[idx]->adjust(duration, idx); m_timer[idx]->enable(true); } } @@ -606,57 +597,57 @@ void ptm6840_device::write(offs_t offset, uint8_t data) // timeout - Called if timer is mature //------------------------------------------------- -void ptm6840_device::timeout(int idx) +TIMER_CALLBACK_MEMBER(ptm6840_device::timeout) { - LOGMASKED(LOG_TIMEOUTS, "**ptm6840 t%d timeout**\n", idx + 1); + LOGMASKED(LOG_TIMEOUTS, "**ptm6840 t%d timeout**\n", param + 1); // Set the interrupt flag - m_status_reg |= (1 << idx); - m_status_read_since_int &= ~(1 << idx); + m_status_reg |= (1 << param); + m_status_read_since_int &= ~(1 << param); update_interrupts(); - if (m_control_reg[idx] & COUNT_OUT_EN) + if (m_control_reg[param] & COUNT_OUT_EN) { - switch (m_mode[idx]) + switch (m_mode[param]) { case 0: case 2: - if (m_control_reg[idx] & COUNT_MODE_8BIT) + if (m_control_reg[param] & COUNT_MODE_8BIT) { - m_hightime[idx] = !m_hightime[idx]; - m_output[idx] = m_hightime[idx]; - m_out_cb[idx](m_output[idx]); + m_hightime[param] = !m_hightime[param]; + m_output[param] = m_hightime[param]; + m_out_cb[param](m_output[param]); } else { - m_output[idx] = m_output[idx] ^ 1; - m_out_cb[idx](m_output[idx]); + m_output[param] = m_output[param] ^ 1; + m_out_cb[param](m_output[param]); } - LOGMASKED(LOG_TIMEOUTS, "%6.6f: **ptm6840 t%d output %d **\n", machine().time().as_double(), idx + 1, m_output[idx]); + LOGMASKED(LOG_TIMEOUTS, "%6.6f: **ptm6840 t%d output %d **\n", machine().time().as_double(), param + 1, m_output[param]); break; case 4: case 6: - if (!m_fired[idx]) + if (!m_fired[param]) { - m_output[idx] = 1; - LOGMASKED(LOG_TIMEOUTS, "**ptm6840 t%d output %d **\n", idx + 1, m_output[idx]); + m_output[param] = 1; + LOGMASKED(LOG_TIMEOUTS, "**ptm6840 t%d output %d **\n", param + 1, m_output[param]); - m_out_cb[idx](m_output[idx]); + m_out_cb[param](m_output[param]); // No changes in output until reinit - m_fired[idx] = 1; + m_fired[param] = 1; - m_status_reg |= (1 << idx); - m_status_read_since_int &= ~(1 << idx); + m_status_reg |= (1 << param); + m_status_read_since_int &= ~(1 << param); update_interrupts(); } break; } } - m_enabled[idx]= 0; - reload_count(idx); + m_enabled[param]= 0; + reload_count(param); } @@ -737,7 +728,7 @@ void ptm6840_device::set_ext_clock(int counter, double clock) } m_enabled[counter] = 1; - m_timer[counter]->adjust(duration); + m_timer[counter]->adjust(duration, counter); m_timer[counter]->enable(true); } } diff --git a/src/devices/machine/6840ptm.h b/src/devices/machine/6840ptm.h index 249b71f0bba..99da9522c7b 100644 --- a/src/devices/machine/6840ptm.h +++ b/src/devices/machine/6840ptm.h @@ -59,12 +59,11 @@ protected: virtual void device_start() override; virtual void device_reset() override; virtual void device_resolve_objects() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; private: void subtract_from_counter(int counter, int count); void tick(int counter, int count); - void timeout(int idx); + TIMER_CALLBACK_MEMBER(timeout); uint16_t compute_counter(int counter) const; void reload_count(int idx); diff --git a/src/devices/machine/74123.cpp b/src/devices/machine/74123.cpp index 6596bf58bf3..d895a72c4e4 100644 --- a/src/devices/machine/74123.cpp +++ b/src/devices/machine/74123.cpp @@ -29,7 +29,8 @@ DEFINE_DEVICE_TYPE(TTL74123, ttl74123_device, "ttl74123", "74123 TTL") ttl74123_device::ttl74123_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) : device_t(mconfig, TTL74123, tag, owner, clock), - m_timer(nullptr), + m_clear_timer(nullptr), + m_output_timer(nullptr), m_connection_type(TTL74123_NOT_GROUNDED_NO_DIODE), m_res(1.0), m_cap(1.0), @@ -48,7 +49,8 @@ void ttl74123_device::device_start() { m_output_changed_cb.resolve_safe(); - m_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(ttl74123_device::clear_callback),this)); + m_clear_timer = timer_alloc(FUNC(ttl74123_device::clear_callback), this); + m_output_timer = timer_alloc(FUNC(ttl74123_device::output_callback), this); /* register for state saving */ save_item(NAME(m_a)); @@ -110,8 +112,7 @@ attotime ttl74123_device::compute_duration() int ttl74123_device::timer_running() { - return (m_timer->remaining() > attotime::zero) && - (m_timer->remaining() != attotime::never); + return m_clear_timer->remaining() > attotime::zero && !m_clear_timer->remaining().is_never(); } @@ -133,7 +134,7 @@ void ttl74123_device::set_output() { int output = timer_running(); - machine().scheduler().timer_set( attotime::zero, timer_expired_delegate(FUNC(ttl74123_device::output_callback ),this), output); + m_output_timer->adjust(attotime::zero, output); LOG("74123: Output: %d\n", output); } @@ -163,9 +164,9 @@ void ttl74123_device::start_pulse() /* retriggering, but not if we are called to quickly */ attotime delay_time = attotime(0, ATTOSECONDS_PER_SECOND * m_cap * 220); - if(m_timer->elapsed() >= delay_time) + if(m_clear_timer->elapsed() >= delay_time) { - m_timer->adjust(duration); + m_clear_timer->adjust(duration); LOG("74123: Retriggering pulse. Duration: %f\n", duration.as_double()); } @@ -177,7 +178,7 @@ void ttl74123_device::start_pulse() else { /* starting */ - m_timer->adjust(duration); + m_clear_timer->adjust(duration); set_output(); @@ -206,7 +207,7 @@ WRITE_LINE_MEMBER( ttl74123_device::a_w ) // b_w - write register b data //------------------------------------------------- -WRITE_LINE_MEMBER( ttl74123_device::b_w) +WRITE_LINE_MEMBER( ttl74123_device::b_w ) { /* start/regtrigger pulse if A=LO and rising edge on B (while clear is HI) */ if (state && !m_b && !m_a && m_clear) @@ -222,7 +223,7 @@ WRITE_LINE_MEMBER( ttl74123_device::b_w) // clear_w - write register clear data //------------------------------------------------- -WRITE_LINE_MEMBER( ttl74123_device::clear_w) +WRITE_LINE_MEMBER( ttl74123_device::clear_w ) { /* start/regtrigger pulse if B=HI and A=LO and rising edge on clear */ if (state && !m_a && m_b && !m_clear) @@ -231,7 +232,7 @@ WRITE_LINE_MEMBER( ttl74123_device::clear_w) } else if (!state) /* clear the output */ { - m_timer->adjust(attotime::zero); + m_clear_timer->adjust(attotime::zero); LOG("74123: Cleared\n"); } @@ -243,7 +244,7 @@ WRITE_LINE_MEMBER( ttl74123_device::clear_w) // reset_w - reset device //------------------------------------------------- -WRITE_LINE_MEMBER( ttl74123_device::reset_w) +WRITE_LINE_MEMBER( ttl74123_device::reset_w ) { set_output(); } diff --git a/src/devices/machine/74123.h b/src/devices/machine/74123.h index bdff8d29aee..1aeed9d3ef7 100644 --- a/src/devices/machine/74123.h +++ b/src/devices/machine/74123.h @@ -107,7 +107,8 @@ private: void set_output(); attotime compute_duration(); - emu_timer *m_timer; + emu_timer *m_clear_timer; + emu_timer *m_output_timer; int m_connection_type; /* the hook up type - one of the constants above */ double m_res; /* resistor connected to RCext */ double m_cap; /* capacitor connected to Cext and RCext */ diff --git a/src/devices/machine/8042kbdc.cpp b/src/devices/machine/8042kbdc.cpp index cfc2a0f6e0f..6c918c172cb 100644 --- a/src/devices/machine/8042kbdc.cpp +++ b/src/devices/machine/8042kbdc.cpp @@ -80,7 +80,7 @@ void kbdc8042_device::device_start() m_speaker = 0; m_offset1 = 0; - m_update_timer = timer_alloc(TIMER_UPDATE); + m_update_timer = timer_alloc(FUNC(kbdc8042_device::update_timer), this); m_update_timer->adjust(attotime::never); } @@ -223,14 +223,11 @@ void kbdc8042_device::at_8042_clear_keyboard_received() m_mouse.received = 0; } -void kbdc8042_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(kbdc8042_device::update_timer) { - if (id == TIMER_UPDATE) - { - at_8042_check_keyboard(); - if (m_mouse.on) - at_8042_check_mouse(); - } + at_8042_check_keyboard(); + if (m_mouse.on) + at_8042_check_mouse(); } void kbdc8042_device::mouse_enqueue(uint8_t value) diff --git a/src/devices/machine/8042kbdc.h b/src/devices/machine/8042kbdc.h index 698a521a9f0..64a45c8993a 100644 --- a/src/devices/machine/8042kbdc.h +++ b/src/devices/machine/8042kbdc.h @@ -64,12 +64,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; virtual ioport_constructor device_input_ports() const override; - void mouse_enqueue(uint8_t value); + TIMER_CALLBACK_MEMBER(update_timer); - static const device_timer_id TIMER_UPDATE = 0; + void mouse_enqueue(uint8_t value); private: uint8_t m_inport; diff --git a/src/devices/machine/8364_paula.cpp b/src/devices/machine/8364_paula.cpp index d16739f0cc3..befdb45d7b6 100644 --- a/src/devices/machine/8364_paula.cpp +++ b/src/devices/machine/8364_paula.cpp @@ -67,7 +67,7 @@ void paula_8364_device::device_start() for (int i = 0; i < 4; i++) { m_channel[i].index = i; - m_channel[i].irq_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(paula_8364_device::signal_irq), this)); + m_channel[i].irq_timer = timer_alloc(FUNC(paula_8364_device::signal_irq), this); } // create the stream diff --git a/src/devices/machine/8530scc.cpp b/src/devices/machine/8530scc.cpp index 0bdff03073e..a2e066500e3 100644 --- a/src/devices/machine/8530scc.cpp +++ b/src/devices/machine/8530scc.cpp @@ -111,23 +111,19 @@ void scc8530_legacy_device::resetchannel(int ch) } /*------------------------------------------------- - scc8530_baud_expire - baud rate timer expiry + baud_expire - baud rate timer expiry -------------------------------------------------*/ -void scc8530_legacy_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(scc8530_legacy_device::baud_expire) { - Chan *pChan = &channel[id]; - int brconst = pChan->reg_val[13]<<8 | pChan->reg_val[14]; - int rate; + Chan *pChan = &channel[param]; + int brconst = pChan->reg_val[13] << 8 | pChan->reg_val[14]; + int rate = 0; if (brconst) { rate = clock() / brconst; } - else - { - rate = 0; - } // is baud counter IRQ enabled on this channel? // always flag pending in case it's enabled after this @@ -146,11 +142,11 @@ void scc8530_legacy_device::device_timer(emu_timer &timer, device_timer_id id, i if (rate) { attotime attorate = attotime::from_hz(rate); - timer.adjust(attorate, 0, attorate); + channel[param].baudtimer->adjust(attorate, param, attorate); } else { - timer.adjust(attotime::never, 0, attotime::never); + channel[param].baudtimer->adjust(attotime::never, param, attotime::never); } } @@ -172,8 +168,8 @@ void scc8530_legacy_device::device_start() lastIRQStat = 0; IRQType = IRQ_NONE; - channel[0].baudtimer = timer_alloc(0); - channel[1].baudtimer = timer_alloc(1); + channel[0].baudtimer = timer_alloc(FUNC(scc8530_legacy_device::baud_expire), this); + channel[1].baudtimer = timer_alloc(FUNC(scc8530_legacy_device::baud_expire), this); } diff --git a/src/devices/machine/8530scc.h b/src/devices/machine/8530scc.h index 29b7c138226..fb1045861be 100644 --- a/src/devices/machine/8530scc.h +++ b/src/devices/machine/8530scc.h @@ -46,7 +46,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(baud_expire); private: struct Chan { diff --git a/src/devices/machine/acorn_ioc.cpp b/src/devices/machine/acorn_ioc.cpp index aa778ff7760..3f59b4a66d1 100644 --- a/src/devices/machine/acorn_ioc.cpp +++ b/src/devices/machine/acorn_ioc.cpp @@ -51,7 +51,7 @@ void acorn_ioc_device::device_resolve_objects() void acorn_ioc_device::device_start() { for (int i=0; i <4; i++) - m_timers[i] = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(acorn_ioc_device::timer_tick), this)); + m_timers[i] = timer_alloc(FUNC(acorn_ioc_device::timer_tick), this); save_item(NAME(m_ir)); save_item(NAME(m_if)); diff --git a/src/devices/machine/acorn_vidc.cpp b/src/devices/machine/acorn_vidc.cpp index cf739af4360..856106d8fc1 100644 --- a/src/devices/machine/acorn_vidc.cpp +++ b/src/devices/machine/acorn_vidc.cpp @@ -168,8 +168,8 @@ void acorn_vidc10_device::device_start() save_pointer(NAME(m_cursor_vram), m_cursor_vram_size); save_pointer(NAME(m_stereo_image), m_sound_max_channels); - m_video_timer = timer_alloc(TIMER_VIDEO); - m_sound_timer = timer_alloc(TIMER_SOUND); + m_video_timer = timer_alloc(FUNC(acorn_vidc10_device::vblank_timer), this); + m_sound_timer = timer_alloc(FUNC(acorn_vidc10_device::sound_drq_timer), this); // generate u255 law lookup table // cfr. page 48 of the VIDC20 manual, page 33 of the VIDC manual @@ -216,22 +216,15 @@ void acorn_vidc10_device::device_reset() m_sound_timer->adjust(attotime::never); } -//------------------------------------------------- -// device_timer - device-specific timer -//------------------------------------------------- +TIMER_CALLBACK_MEMBER(acorn_vidc10_device::vblank_timer) +{ + m_vblank_cb(ASSERT_LINE); + screen_vblank_line_update(); +} -void acorn_vidc10_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(acorn_vidc10_device::sound_drq_timer) { - switch (id) - { - case TIMER_VIDEO: - m_vblank_cb(ASSERT_LINE); - screen_vblank_line_update(); - break; - case TIMER_SOUND: - m_sound_drq_cb(ASSERT_LINE); - break; - } + m_sound_drq_cb(ASSERT_LINE); } //************************************************************************** @@ -305,13 +298,11 @@ void acorn_vidc10_device::write(offs_t offset, u32 data, u32 mem_mask) inline void acorn_vidc10_device::update_4bpp_palette(u16 index, u32 paldata) { - int r,g,b; - // TODO: for TV Tuner we need to output this, also check if cursor mode actually sets this up for offset = 0 // i = (paldata & 0x1000) >> 12; //supremacy bit - b = (paldata & 0x0f00) >> 8; - g = (paldata & 0x00f0) >> 4; - r = (paldata & 0x000f) >> 0; + int b = (paldata & 0x0f00) >> 8; + int g = (paldata & 0x00f0) >> 4; + int r = (paldata & 0x000f) >> 0; set_pen_color(index, pal4bit(r), pal4bit(g), pal4bit(b) ); screen().update_partial(screen().vpos()); @@ -444,8 +435,7 @@ void acorn_vidc10_device::sound_frequency_w(u32 data) void acorn_vidc10_device::write_dac(u8 channel, u8 data) { - int16_t res; - res = m_ulaw_lookup[data]; + int16_t res = m_ulaw_lookup[data]; m_dac[channel & 7]->write(res); } @@ -505,29 +495,25 @@ void acorn_vidc10_device::draw(bitmap_rgb32 &bitmap, const rectangle &cliprect, u32 acorn_vidc10_device::screen_update(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect) { - int xstart,ystart,xend,yend; - int xsize,ysize; - int calc_dxs = 0,calc_dxe = 0; - /* border color */ bitmap.fill(pen(m_pal_border_base), cliprect); /* define X display area through BPP mode register */ - calc_dxs = m_crtc_regs[CRTC_HDSR]; - calc_dxe = m_crtc_regs[CRTC_HDER]; + int calc_dxs = m_crtc_regs[CRTC_HDSR]; + int calc_dxe = m_crtc_regs[CRTC_HDER]; /* now calculate display clip rectangle start/end areas */ - xstart = (calc_dxs)-m_crtc_regs[CRTC_HBSR]; - ystart = (m_crtc_regs[CRTC_VDSR]-m_crtc_regs[CRTC_VBSR]); - xend = (calc_dxe)+xstart; - yend = (m_crtc_regs[CRTC_VDER] * (m_crtc_interlace+1))+ystart; + int xstart = (calc_dxs)-m_crtc_regs[CRTC_HBSR]; + int ystart = (m_crtc_regs[CRTC_VDSR]-m_crtc_regs[CRTC_VBSR]); + int xend = (calc_dxe)+xstart; + int yend = (m_crtc_regs[CRTC_VDER] * (m_crtc_interlace+1))+ystart; /* disable the screen if display params are invalid */ if(xstart > xend || ystart > yend) return 0; - xsize = calc_dxe-calc_dxs; - ysize = m_crtc_regs[CRTC_VDER]-m_crtc_regs[CRTC_VDSR]; + int xsize = calc_dxe-calc_dxs; + int ysize = m_crtc_regs[CRTC_VDER]-m_crtc_regs[CRTC_VDSR]; if (xsize <= 0 || ysize <= 0) return 0; @@ -653,12 +639,6 @@ void arm_vidc20_device::device_reset() write_dac32(1, 0); } -void arm_vidc20_device::device_timer(emu_timer &timer, device_timer_id id, int param) -{ - acorn_vidc10_device::device_timer(timer, id, param); - // TODO: other timers -} - inline void arm_vidc20_device::refresh_stereo_image(u8 channel) { // TODO: set_input_gain hampers with both QS1000 and serial DAC mode @@ -669,13 +649,11 @@ inline void arm_vidc20_device::refresh_stereo_image(u8 channel) inline void arm_vidc20_device::update_8bpp_palette(u16 index, u32 paldata) { - int r,g,b; - // TODO: ext hookup, supremacy plus other stuff according to the manual // ext = (paldata & 0x0f000000) >> 24; - b = (paldata & 0x00ff0000) >> 16; - g = (paldata & 0x0000ff00) >> 8; - r = (paldata & 0x000000ff) >> 0; + int b = (paldata & 0x00ff0000) >> 16; + int g = (paldata & 0x0000ff00) >> 8; + int r = (paldata & 0x000000ff) >> 0; set_pen_color(index, r, g, b ); screen().update_partial(screen().vpos()); diff --git a/src/devices/machine/acorn_vidc.h b/src/devices/machine/acorn_vidc.h index d5e86cb1e30..10584dddead 100644 --- a/src/devices/machine/acorn_vidc.h +++ b/src/devices/machine/acorn_vidc.h @@ -58,12 +58,15 @@ protected: virtual void device_config_complete() override; virtual void device_start() override; virtual void device_reset() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; virtual space_config_vector memory_space_config() const override; u32 screen_update(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect); virtual u32 get_pixel_clock(); + TIMER_CALLBACK_MEMBER(vblank_timer); + TIMER_CALLBACK_MEMBER(sound_drq_timer); + address_space_config m_space_config; + void regs_map(address_map &map); enum { @@ -71,10 +74,6 @@ protected: CRTC_VCR, CRTC_VSWR, CRTC_VBSR, CRTC_VDSR, CRTC_VDER, CRTC_VBER, CRTC_VCSR, CRTC_VCER }; u32 m_crtc_regs[16]; - enum { - TIMER_VIDEO = 1, - TIMER_SOUND = 2 - }; inline void screen_vblank_line_update(); inline void screen_dynamic_res_change(); @@ -165,7 +164,6 @@ protected: virtual void device_start() override; virtual void device_reset() override; virtual void device_config_complete() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; u32 screen_update(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect); virtual u32 get_pixel_clock() override; diff --git a/src/devices/machine/adc0804.cpp b/src/devices/machine/adc0804.cpp index 048b99734b6..12eb9e7754d 100644 --- a/src/devices/machine/adc0804.cpp +++ b/src/devices/machine/adc0804.cpp @@ -118,7 +118,7 @@ void adc0804_device::device_start() m_fclk_rc = attotime::from_double(m_res * m_cap / 1.1); // create timer - m_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(adc0804_device::conversion_done), this)); + m_timer = timer_alloc(FUNC(adc0804_device::conversion_done), this); // save state if (m_rd_mode == RD_BITBANGED) diff --git a/src/devices/machine/adc0808.cpp b/src/devices/machine/adc0808.cpp index eb8c62435b7..a55c11077c7 100644 --- a/src/devices/machine/adc0808.cpp +++ b/src/devices/machine/adc0808.cpp @@ -84,7 +84,7 @@ void adc0808_device::device_start() m_in_cb.resolve_all_safe(0xff); // allocate timers - m_cycle_timer = timer_alloc(); + m_cycle_timer = timer_alloc(FUNC(adc0808_device::update_state), this); m_cycle_timer->adjust(attotime::zero, 0, attotime::from_hz(clock())); // register for save states @@ -96,10 +96,10 @@ void adc0808_device::device_start() } //------------------------------------------------- -// device_timer - handler timer events +// update_state //------------------------------------------------- -void adc0808_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(adc0808_device::update_state) { switch (m_state) { diff --git a/src/devices/machine/adc0808.h b/src/devices/machine/adc0808.h index 5fd14efdf3e..9d69c67daef 100644 --- a/src/devices/machine/adc0808.h +++ b/src/devices/machine/adc0808.h @@ -65,7 +65,8 @@ protected: // device-level overrides virtual void device_start() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; + + TIMER_CALLBACK_MEMBER(update_state); private: // callbacks diff --git a/src/devices/machine/adc0844.cpp b/src/devices/machine/adc0844.cpp index a4e3ce04809..bbdafc68aec 100644 --- a/src/devices/machine/adc0844.cpp +++ b/src/devices/machine/adc0844.cpp @@ -67,7 +67,7 @@ void adc0844_device::device_start() m_ch4_cb.resolve_safe(0xff); // allocate timers - m_conversion_timer = timer_alloc(); + m_conversion_timer = timer_alloc(FUNC(adc0844_device::conversion_complete), this); // register for save states save_item(NAME(m_channel)); @@ -100,10 +100,10 @@ uint8_t adc0844_device::clamp(int value) } //------------------------------------------------- -// device_timer - handler timer events +// conversion_complete - finish ADC conversion //------------------------------------------------- -void adc0844_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(adc0844_device::conversion_complete) { switch (m_channel) { @@ -132,7 +132,7 @@ void adc0844_device::device_timer(emu_timer &timer, device_timer_id id, int para m_intr_cb(ASSERT_LINE); } -void adc0848_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(adc0848_device::conversion_complete) { switch (m_channel) { diff --git a/src/devices/machine/adc0844.h b/src/devices/machine/adc0844.h index b8080e73d8d..98ac8b211d4 100644 --- a/src/devices/machine/adc0844.h +++ b/src/devices/machine/adc0844.h @@ -51,7 +51,8 @@ protected: // device-level overrides virtual void device_start() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; + + virtual TIMER_CALLBACK_MEMBER(conversion_complete); uint8_t clamp(int value); @@ -83,7 +84,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; + + virtual TIMER_CALLBACK_MEMBER(conversion_complete) override; private: devcb_read8 m_ch5_cb, m_ch6_cb, m_ch7_cb, m_ch8_cb; diff --git a/src/devices/machine/aic6250.cpp b/src/devices/machine/aic6250.cpp index 71859bdee05..fb885c3b5e3 100644 --- a/src/devices/machine/aic6250.cpp +++ b/src/devices/machine/aic6250.cpp @@ -182,7 +182,7 @@ void aic6250_device::device_start() m_rev_cntrl = 0x02; - m_state_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(aic6250_device::state_loop), this)); + m_state_timer = timer_alloc(FUNC(aic6250_device::state_loop), this); m_state = IDLE; m_int_asserted = false; diff --git a/src/devices/machine/aicartc.cpp b/src/devices/machine/aicartc.cpp index bd5f4c198d8..c4f14b0a9f4 100644 --- a/src/devices/machine/aicartc.cpp +++ b/src/devices/machine/aicartc.cpp @@ -54,7 +54,7 @@ void aicartc_device::device_validity_check(validity_checker &valid) const void aicartc_device::device_start() { - m_clock_timer = timer_alloc(); + m_clock_timer = timer_alloc(FUNC(aicartc_device::clock_tick), this); m_clock_timer->adjust(attotime::from_hz(clock()), 0, attotime::from_hz(clock())); } @@ -107,11 +107,10 @@ void aicartc_device::device_reset() //------------------------------------------------- -// device_timer - handler timer events +// clock_tick - advance the RTC counter //------------------------------------------------- - -void aicartc_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(aicartc_device::clock_tick) { m_rtc_tick++; if(m_rtc_tick & 0x8000) diff --git a/src/devices/machine/aicartc.h b/src/devices/machine/aicartc.h index 512d567f13b..fb1955ec685 100644 --- a/src/devices/machine/aicartc.h +++ b/src/devices/machine/aicartc.h @@ -33,13 +33,14 @@ 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; // device_rtc_interface overrides virtual bool rtc_feature_y2k() const override { return true; } virtual bool rtc_feature_leap_year() const override { return true; } virtual void rtc_clock_updated(int year, int month, int day, int day_of_week, int hour, int minute, int second) override; + TIMER_CALLBACK_MEMBER(clock_tick); + private: emu_timer *m_clock_timer; }; diff --git a/src/devices/machine/akiko.cpp b/src/devices/machine/akiko.cpp index 40e73df64d9..13ae686a972 100644 --- a/src/devices/machine/akiko.cpp +++ b/src/devices/machine/akiko.cpp @@ -143,8 +143,8 @@ void akiko_device::device_start() m_cdrom_cmd_resp = 0; m_cdrom_toc = nullptr; - m_dma_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(akiko_device::dma_proc), this)); - m_frame_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(akiko_device::frame_proc), this)); + m_dma_timer = timer_alloc(FUNC(akiko_device::dma_proc), this); + m_frame_timer = timer_alloc(FUNC(akiko_device::frame_proc), this); } //------------------------------------------------- @@ -718,7 +718,7 @@ void akiko_device::update_cdrom() { m_cdrom_cmd_start = (m_cdrom_cmd_start + 3) & 0xff; - machine().scheduler().timer_set( attotime::from_msec(1), timer_expired_delegate(FUNC(akiko_device::cd_delayed_cmd ), this), resp[0]); + machine().scheduler().timer_set( attotime::from_msec(1), timer_expired_delegate( FUNC( akiko_device::cd_delayed_cmd ), this ), resp[0] ); break; } diff --git a/src/devices/machine/am2910.cpp b/src/devices/machine/am2910.cpp index eaca32a34d8..158b4b83bb7 100644 --- a/src/devices/machine/am2910.cpp +++ b/src/devices/machine/am2910.cpp @@ -70,7 +70,7 @@ void am2910_device::device_start() m_vect.resolve_safe(); if (clock()) - m_execute_timer = timer_alloc(TIMER_CLOCK); + m_execute_timer = timer_alloc(FUNC(am2910_device::clock_tick), this); else m_execute_timer = nullptr; } @@ -86,12 +86,9 @@ void am2910_device::device_reset() m_execute_timer->adjust(attotime::from_hz(clock()), 0, attotime::from_hz(clock())); } -void am2910_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(am2910_device::clock_tick) { - if (id == TIMER_CLOCK) - { - cp_w(m_cp ? 0 : 1); - } + cp_w(m_cp ? 0 : 1); } WRITE_LINE_MEMBER(am2910_device::cc_w) diff --git a/src/devices/machine/am2910.h b/src/devices/machine/am2910.h index 6ff5047014c..52c075ea52a 100644 --- a/src/devices/machine/am2910.h +++ b/src/devices/machine/am2910.h @@ -42,9 +42,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; - static constexpr device_timer_id TIMER_CLOCK = 0; + TIMER_CALLBACK_MEMBER(clock_tick); emu_timer *m_execute_timer; diff --git a/src/devices/machine/am53cf96.cpp b/src/devices/machine/am53cf96.cpp index 9d1171c3f66..41b62e145f0 100644 --- a/src/devices/machine/am53cf96.cpp +++ b/src/devices/machine/am53cf96.cpp @@ -47,7 +47,7 @@ uint8_t am53cf96_device::read(offs_t offset) return rv; } -void am53cf96_device::device_timer(emu_timer &timer, device_timer_id tid, int param) +TIMER_CALLBACK_MEMBER(am53cf96_device::irq_timer_tick) { scsi_regs[REG_IRQSTATE] = 8; // indicate success scsi_regs[REG_STATUS] |= 0x80; // indicate IRQ @@ -169,7 +169,7 @@ void am53cf96_device::device_start() save_item( NAME( xfer_state ) ); save_item( NAME( last_id ) ); - m_transfer_timer = timer_alloc( TIMER_TRANSFER ); + m_transfer_timer = timer_alloc( FUNC( am53cf96_device::irq_timer_tick ), this ); } // retrieve data from the SCSI controller diff --git a/src/devices/machine/am53cf96.h b/src/devices/machine/am53cf96.h index 989da69d4c6..6fdd801f6df 100644 --- a/src/devices/machine/am53cf96.h +++ b/src/devices/machine/am53cf96.h @@ -51,11 +51,10 @@ protected: // device-level overrides virtual void device_start() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; -private: - static constexpr device_timer_id TIMER_TRANSFER = 0; + TIMER_CALLBACK_MEMBER(irq_timer_tick); +private: uint8_t scsi_regs[32]; uint8_t fifo[16]; uint8_t fptr; diff --git a/src/devices/machine/am79c90.cpp b/src/devices/machine/am79c90.cpp index ce2fb4837fe..f47457680ec 100644 --- a/src/devices/machine/am79c90.cpp +++ b/src/devices/machine/am79c90.cpp @@ -87,7 +87,7 @@ void am7990_device_base::device_start() m_dma_in_cb.resolve_safe(0); m_dma_out_cb.resolve_safe(); - m_transmit_poll = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(am7990_device_base::transmit_poll), this)); + m_transmit_poll = timer_alloc(FUNC(am7990_device_base::transmit_poll), this); m_transmit_poll->adjust(TX_POLL_PERIOD, 0, TX_POLL_PERIOD); save_item(NAME(m_rap)); diff --git a/src/devices/machine/am9513.cpp b/src/devices/machine/am9513.cpp index c22eb0fc735..1c8c3692369 100644 --- a/src/devices/machine/am9513.cpp +++ b/src/devices/machine/am9513.cpp @@ -113,7 +113,7 @@ void am9513_device::device_start() // Set up frequency timers for (int f = 0; f < 5; f++) { - m_freq_timer[f] = timer_alloc(TIMER_F1 + f); + m_freq_timer[f] = timer_alloc(FUNC(am9513_device::timer_tick), this); m_freq_timer_selected[f] = (f == 0) ? (m_fout_cb.isnull() ? 0x3e : 0x3f) : 0; m_freq_timer_cycle[f] = 0; } @@ -205,9 +205,9 @@ void am9513_device::init_freq_timer(int f) attotime freq = clocks_to_attotime(scale); if (m_freq_timer_cycle[f] == 0) - m_freq_timer[f]->adjust(freq, 0, freq); + m_freq_timer[f]->adjust(freq, f, freq); else - m_freq_timer[f]->adjust(freq / 2, 0, freq / 2); + m_freq_timer[f]->adjust(freq / 2, f, freq / 2); m_freq_timer[f]->enable(m_freq_timer_selected[f] != 0); LOGMASKED(LOG_GENERAL, "F%d = %f Hz (%s cycle emulation)\n", f + 1, double(clock()) / scale, @@ -228,21 +228,18 @@ void am9513_device::device_clock_changed() //------------------------------------------------- -// device_timer - called whenever a device timer -// fires +// timer_tick - advance our counters //------------------------------------------------- -void am9513_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(am9513_device::timer_tick) { - assert(id >= TIMER_F1 && id <= TIMER_F5); - - int cycle = m_freq_timer_cycle[id - TIMER_F1] == 0 ? 2 : 1; + int cycle = m_freq_timer_cycle[param] == 0 ? 2 : 1; while (cycle-- > 0) { - m_f ^= 1 << (id - TIMER_F1); - bool level = BIT(m_f, id - TIMER_F1); + m_f ^= 1 << param; + bool level = BIT(m_f, param); - int source = id - TIMER_F1 + 11; + int source = param + 11; for (int c = 0; c < 5; c++) { if ((m_counter_mode[c] & 0x0f00) >> 8 == source && BIT(m_counter_mode[c], 12) == !level) @@ -250,7 +247,7 @@ void am9513_device::device_timer(emu_timer &timer, device_timer_id id, int param } // FOUT Source = Fn - if ((m_mmr & 0x00f0) >> 4 == source || ((m_mmr & 0x00f0) == 0 && id == TIMER_F1)) + if ((m_mmr & 0x00f0) >> 4 == source || ((m_mmr & 0x00f0) == 0 && param == 0)) fout_tick(); } } diff --git a/src/devices/machine/am9513.h b/src/devices/machine/am9513.h index 78e54799363..34c3cc3598c 100644 --- a/src/devices/machine/am9513.h +++ b/src/devices/machine/am9513.h @@ -93,11 +93,11 @@ protected: // device-level overrides virtual void device_start() override; virtual void device_clock_changed() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; private: // internal helpers TIMER_CALLBACK_MEMBER(clear_outputs); + TIMER_CALLBACK_MEMBER(timer_tick); void master_reset(); void init_freq_timer(int f); void select_freq_timer(int f, int c, bool selected, bool cycle); @@ -161,14 +161,6 @@ private: // frequency timer u8 m_f; - enum - { - TIMER_F1, - TIMER_F2, - TIMER_F3, - TIMER_F4, - TIMER_F5 - }; emu_timer *m_freq_timer[5]; u8 m_freq_timer_selected[5]; u8 m_freq_timer_cycle[5]; diff --git a/src/devices/machine/am9519.cpp b/src/devices/machine/am9519.cpp index 64d36a8acaa..d7b38ef6d16 100644 --- a/src/devices/machine/am9519.cpp +++ b/src/devices/machine/am9519.cpp @@ -11,7 +11,72 @@ //#define VERBOSE (LOG_GENERAL) #include "logmacro.h" -void am9519_device::device_timer(emu_timer &timer, device_timer_id id, int param) + +DEFINE_DEVICE_TYPE(AM9519, am9519_device, "am9519", "AMD AM9519 Universal Interrupt Controller") + +am9519_device::am9519_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock) + : device_t(mconfig, AM9519, tag, owner, clock) + , m_out_int_func(*this) + , m_irr(0) + , m_irq_lines(0) + , m_irq_check_timer(nullptr) +{ +} + + +//------------------------------------------------- +// device_start - device-specific startup +//------------------------------------------------- + +void am9519_device::device_start() +{ + // resolve callbacks + m_out_int_func.resolve_safe(); + + // Register save state items + save_item(NAME(m_isr)); + save_item(NAME(m_irr)); + save_item(NAME(m_prio)); + save_item(NAME(m_imr)); + save_item(NAME(m_irq_lines)); + save_item(NAME(m_mode)); + save_item(NAME(m_count)); + save_item(NAME(m_resp)); + save_item(NAME(m_aclear)); + save_item(NAME(m_cmd)); + + m_irq_check_timer = timer_alloc(FUNC(am9519_device::check_irqs), this); + m_irq_check_timer->adjust(attotime::never); +} + + +//------------------------------------------------- +// device_reset - device-specific reset +//------------------------------------------------- + +void am9519_device::device_reset() +{ + m_isr = 0; + m_irr = 0; + m_irq_lines = 0; + m_prio = 0; + m_imr = 0xff; + m_mode = 0; + m_aclear = 0; + m_cmd = 0; + m_curcnt = 0; + for(int i = 0; i < 8; i++) + { + m_count[i] = 0; + m_resp[i][0] = 0; + m_resp[i][1] = 0; + m_resp[i][2] = 0; + m_resp[i][3] = 0; + } +} + + +TIMER_CALLBACK_MEMBER(am9519_device::check_irqs) { if(!BIT(m_mode, 7)) // chip disabled return; @@ -63,7 +128,7 @@ void am9519_device::set_irq_line(int irq, int state) m_irq_lines &= ~mask; m_irr &= ~mask; } - set_timer(); + m_irq_check_timer->adjust(attotime::zero); } @@ -82,7 +147,7 @@ u32 am9519_device::acknowledge() m_isr |= mask; m_irr &= ~mask; - set_timer(); + m_irq_check_timer->adjust(attotime::zero); u32 ret = 0; int irqr = BIT(m_mode, 1) ? 0 : irq; @@ -219,7 +284,7 @@ void am9519_device::cmd_w(u8 data) m_curcnt = 0; break; } - set_timer(); + m_irq_check_timer->adjust(attotime::zero); } void am9519_device::data_w(u8 data) @@ -246,63 +311,5 @@ void am9519_device::data_w(u8 data) } m_cmd = 0; } - set_timer(); -} - -//------------------------------------------------- -// device_start - device-specific startup -//------------------------------------------------- - -void am9519_device::device_start() -{ - // resolve callbacks - m_out_int_func.resolve_safe(); - - // Register save state items - save_item(NAME(m_isr)); - save_item(NAME(m_irr)); - save_item(NAME(m_prio)); - save_item(NAME(m_imr)); - save_item(NAME(m_irq_lines)); - save_item(NAME(m_mode)); - save_item(NAME(m_count)); - save_item(NAME(m_resp)); - save_item(NAME(m_aclear)); - save_item(NAME(m_cmd)); -} - - -//------------------------------------------------- -// device_reset - device-specific reset -//------------------------------------------------- - -void am9519_device::device_reset() -{ - m_isr = 0; - m_irr = 0; - m_irq_lines = 0; - m_prio = 0; - m_imr = 0xff; - m_mode = 0; - m_aclear = 0; - m_cmd = 0; - m_curcnt = 0; - for(int i = 0; i < 8; i++) - { - m_count[i] = 0; - m_resp[i][0] = 0; - m_resp[i][1] = 0; - m_resp[i][2] = 0; - m_resp[i][3] = 0; - } -} - -DEFINE_DEVICE_TYPE(AM9519, am9519_device, "am9519", "AMD AM9519 Universal Interrupt Controller") - -am9519_device::am9519_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock) - : device_t(mconfig, AM9519, tag, owner, clock) - , m_out_int_func(*this) - , m_irr(0) - , m_irq_lines(0) -{ + m_irq_check_timer->adjust(attotime::zero); } diff --git a/src/devices/machine/am9519.h b/src/devices/machine/am9519.h index 9de7746b4c7..bccd4534faf 100644 --- a/src/devices/machine/am9519.h +++ b/src/devices/machine/am9519.h @@ -57,12 +57,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; -private: - static constexpr device_timer_id TIMER_CHECK_IRQ = 0; + TIMER_CALLBACK_MEMBER(check_irqs); - inline void set_timer() { timer_set(attotime::zero, TIMER_CHECK_IRQ); } +private: void set_irq_line(int irq, int state); devcb_write_line m_out_int_func; @@ -79,6 +77,8 @@ private: u8 m_aclear; u8 m_count[8]; u8 m_resp[8][4]; + + emu_timer *m_irq_check_timer; }; DECLARE_DEVICE_TYPE(AM9519, am9519_device) diff --git a/src/devices/machine/amigafdc.cpp b/src/devices/machine/amigafdc.cpp index adb31fc76ea..15694a95f49 100644 --- a/src/devices/machine/amigafdc.cpp +++ b/src/devices/machine/amigafdc.cpp @@ -86,7 +86,7 @@ void amiga_fdc_device::device_start() floppy = nullptr; - t_gen = timer_alloc(0); + t_gen = timer_alloc(FUNC(amiga_fdc_device::update_tick), this); } void amiga_fdc_device::device_reset() @@ -485,7 +485,7 @@ uint16_t amiga_fdc_device::dskbytr_r() return res; } -void amiga_fdc_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(amiga_fdc_device::update_tick) { live_sync(); live_run(); diff --git a/src/devices/machine/amigafdc.h b/src/devices/machine/amigafdc.h index b6623fca16f..02e8c823539 100644 --- a/src/devices/machine/amigafdc.h +++ b/src/devices/machine/amigafdc.h @@ -37,7 +37,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(update_tick); private: // Running states diff --git a/src/devices/machine/applefdc.cpp b/src/devices/machine/applefdc.cpp index bd052d18263..8b6c5fec524 100644 --- a/src/devices/machine/applefdc.cpp +++ b/src/devices/machine/applefdc.cpp @@ -55,10 +55,6 @@ #define IWM_Q6 0x40 #define IWM_Q7 0x80 -const device_timer_id TIMER_MOTOR_ONOFF = 1; - - - /*************************************************************************** @@ -122,7 +118,7 @@ applefdc_base_device::applefdc_base_device(applefdc_base_device::applefdc_t fdc_ void applefdc_base_device::device_start() { // timer - m_motor_timer = timer_alloc(TIMER_MOTOR_ONOFF); + m_motor_timer = timer_alloc(FUNC(applefdc_base_device::turn_motor_onoff), this); // state m_write_byte = 0x00; @@ -155,22 +151,6 @@ void applefdc_base_device::device_reset(void) //------------------------------------------------- -// device_timer - device-specific timer callbacks -//------------------------------------------------- - -void applefdc_base_device::device_timer(emu_timer &timer, device_timer_id id, int param) -{ - switch(id) - { - case TIMER_MOTOR_ONOFF: - turn_motor_onoff(param != 0); - break; - } -} - - - -//------------------------------------------------- // get_interface - gets the interface //------------------------------------------------- @@ -345,12 +325,12 @@ void applefdc_base_device::write_reg(uint8_t data) // motor on or off //------------------------------------------------- -void applefdc_base_device::turn_motor_onoff(bool status) +TIMER_CALLBACK_MEMBER(applefdc_base_device::turn_motor_onoff) { const applefdc_interface *intf = get_interface(); int enable_lines; - if (status) + if (param) { m_lines |= IWM_MOTOR; enable_lines = (m_lines & IWM_DRIVE) ? 2 : 1; @@ -370,7 +350,7 @@ void applefdc_base_device::turn_motor_onoff(bool status) intf->set_enable_lines(this, enable_lines); if (LOG_APPLEFDC_EXTRA) - logerror("iwm_turnmotor_onoff(): Turning motor %s\n", status ? "on" : "off"); + logerror("iwm_turnmotor_onoff(): Turning motor %s\n", param ? "on" : "off"); } diff --git a/src/devices/machine/applefdc.h b/src/devices/machine/applefdc.h index 30a2bb50fc2..80fbea87954 100644 --- a/src/devices/machine/applefdc.h +++ b/src/devices/machine/applefdc.h @@ -83,11 +83,11 @@ protected: // device-level overrides virtual void device_start() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; // other protecteds virtual void iwm_modereg_w(uint8_t data); + private: // data that is constant for the lifetime of the emulation emu_timer * m_motor_timer; @@ -107,7 +107,7 @@ private: uint8_t statusreg_r(); uint8_t read_reg(int lines); void write_reg(uint8_t data); - void turn_motor_onoff(bool status); + TIMER_CALLBACK_MEMBER(turn_motor_onoff); void iwm_access(int offset); }; diff --git a/src/devices/machine/applepic.cpp b/src/devices/machine/applepic.cpp index 54f68a483c7..0383bb6817c 100644 --- a/src/devices/machine/applepic.cpp +++ b/src/devices/machine/applepic.cpp @@ -81,7 +81,7 @@ void applepic_device::device_resolve_objects() void applepic_device::device_start() { // Initialize timer - m_timer1 = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(applepic_device::timer1_callback), this)); + m_timer1 = timer_alloc(FUNC(applepic_device::timer1_callback), this); // Save internal state save_item(NAME(m_timer_last_expired)); diff --git a/src/devices/machine/arm_iomd.cpp b/src/devices/machine/arm_iomd.cpp index 0fc1c9ad174..e1c32d8d3f3 100644 --- a/src/devices/machine/arm_iomd.cpp +++ b/src/devices/machine/arm_iomd.cpp @@ -145,6 +145,15 @@ arm_iomd_device::arm_iomd_device(const machine_config &mconfig, device_type type , m_iocr_write_od_cb(*this) , m_iocr_read_id_cb(*this) , m_iocr_write_id_cb(*this) + , m_sndcur(0) + , m_sndend(0) + , m_sndcur_reg{ 0, 0 } + , m_sndend_reg{ 0, 0 } + , m_sndstop_reg{ false, false } + , m_sndlast_reg{ false, false } + , m_sndbuffer_ok{ false, false } + , m_sound_dma_on(false) + , m_sndcur_buffer(0) { } @@ -243,28 +252,28 @@ void arm_iomd_device::device_start() save_item(NAME(m_videqual)); save_item(NAME(m_cursor_enable)); save_item(NAME(m_cursinit)); - save_pointer(NAME(m_irq_mask), IRQ_SOURCES_SIZE); - save_pointer(NAME(m_irq_status), IRQ_SOURCES_SIZE); + save_pointer(NAME(m_irq_mask), std::size(m_irq_mask)); + save_pointer(NAME(m_irq_status), std::size(m_irq_status)); m_host_space = &m_host_cpu->space(AS_PROGRAM); - m_timer[0] = timer_alloc(T0_TIMER); - m_timer[1] = timer_alloc(T1_TIMER); - save_pointer(NAME(m_timer_in), timer_ch_size); - save_pointer(NAME(m_timer_out), timer_ch_size); - save_pointer(NAME(m_timer_counter), timer_ch_size); - save_pointer(NAME(m_timer_readinc), timer_ch_size); + m_timer[0] = timer_alloc(FUNC(arm_iomd_device::timer_elapsed), this); + m_timer[1] = timer_alloc(FUNC(arm_iomd_device::timer_elapsed), this); + save_pointer(NAME(m_timer_in), std::size(m_timer_in)); + save_pointer(NAME(m_timer_out), std::size(m_timer_out)); + save_pointer(NAME(m_timer_counter), std::size(m_timer_counter)); + save_pointer(NAME(m_timer_readinc), std::size(m_timer_readinc)); save_item(NAME(m_sndcur)); save_item(NAME(m_sndend)); save_item(NAME(m_sound_dma_on)); save_item(NAME(m_sndcur_buffer)); - save_pointer(NAME(m_sndcur_reg), sounddma_ch_size); - save_pointer(NAME(m_sndend_reg), sounddma_ch_size); - save_pointer(NAME(m_sndstop_reg), sounddma_ch_size); - save_pointer(NAME(m_sndlast_reg), sounddma_ch_size); - save_pointer(NAME(m_sndbuffer_ok), sounddma_ch_size); + save_pointer(NAME(m_sndcur_reg), std::size(m_sndcur_reg)); + save_pointer(NAME(m_sndend_reg), std::size(m_sndend_reg)); + save_pointer(NAME(m_sndstop_reg), std::size(m_sndstop_reg)); + save_pointer(NAME(m_sndlast_reg), std::size(m_sndlast_reg)); + save_pointer(NAME(m_sndbuffer_ok), std::size(m_sndbuffer_ok)); // TODO: jumps to EASI space at $0c0016xx for RiscPC if POR is on? } @@ -288,28 +297,27 @@ void arm7500fe_iomd_device::device_start() void arm_iomd_device::device_reset() { - int i; m_iocr_ddr = 0x0b; m_video_enable = false; // TODO: defaults for these m_vidinita = 0; m_vidend = 0; - for (i=0; i<IRQ_SOURCES_SIZE; i++) - { - m_irq_status[i] = 0; - m_irq_mask[i] = 0; - } + std::fill_n(m_irq_status, std::size(m_irq_status), 0); + std::fill_n(m_irq_mask, std::size(m_irq_mask), 0); - for (i = 0; i < timer_ch_size; i++) + for (int i = 0; i < std::size(m_timer); i++) m_timer[i]->adjust(attotime::never); + m_sndcur = 0; + m_sndend = 0; + std::fill_n(m_sndcur_reg, std::size(m_sndcur_reg), 0); + std::fill_n(m_sndend_reg, std::size(m_sndend_reg), 0); + std::fill_n(m_sndstop_reg, std::size(m_sndstop_reg), false); + std::fill_n(m_sndlast_reg, std::size(m_sndlast_reg), false); + std::fill_n(m_sndbuffer_ok, std::size(m_sndbuffer_ok), false); m_sound_dma_on = false; - for (i = 0; i < sounddma_ch_size; i++) - { - m_sndbuffer_ok[i] = false; - m_sndcur_reg[i] = 0; - } + m_sndcur_buffer = 0; // ... } @@ -324,15 +332,9 @@ void arm7500fe_iomd_device::device_reset() m_iolines_ddr = 0xff; } -void arm_iomd_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(arm_iomd_device::timer_elapsed) { - switch(id) - { - case T0_TIMER: - case T1_TIMER: - trigger_irq<IRQA>(id == T1_TIMER ? 0x40 : 0x20); - break; - } + trigger_irq<IRQA>((uint8_t)param); } //************************************************************************** @@ -500,7 +502,7 @@ inline void arm_iomd_device::trigger_timer(unsigned Which) if(val==0) m_timer[Which]->adjust(attotime::never); else - m_timer[Which]->adjust(attotime::from_usec(val), 0, attotime::from_usec(val)); + m_timer[Which]->adjust(attotime::from_usec(val), Which ? 0x40 : 0x20, attotime::from_usec(val)); } // TODO: live updates aren't really supported here diff --git a/src/devices/machine/arm_iomd.h b/src/devices/machine/arm_iomd.h index 8600c55cf22..e072a7c8a31 100644 --- a/src/devices/machine/arm_iomd.h +++ b/src/devices/machine/arm_iomd.h @@ -62,7 +62,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(timer_elapsed); void base_map(address_map &map); u16 m_id; @@ -117,13 +118,15 @@ private: u32 cursinit_r(); void cursinit_w(offs_t offset, u32 data, u32 mem_mask = ~0); - static constexpr int sounddma_ch_size = 2; - u32 m_sndcur = 0, m_sndend = 0; - u32 m_sndcur_reg[sounddma_ch_size]{}, m_sndend_reg[sounddma_ch_size]{}; - bool m_sndstop_reg[sounddma_ch_size]{}, m_sndlast_reg[sounddma_ch_size]{}; - bool m_sndbuffer_ok[sounddma_ch_size]{}; - bool m_sound_dma_on = false; - u8 m_sndcur_buffer = 0; + u32 m_sndcur; + u32 m_sndend; + u32 m_sndcur_reg[2]; + u32 m_sndend_reg[2]; + bool m_sndstop_reg[2]; + bool m_sndlast_reg[2]; + bool m_sndbuffer_ok[2]; + bool m_sound_dma_on; + u8 m_sndcur_buffer; inline void sounddma_swap_buffer(); template <unsigned Which> u32 sdcur_r(); template <unsigned Which> void sdcur_w(offs_t offset, u32 data, u32 mem_mask = ~0); @@ -138,11 +141,6 @@ private: inline void flush_irq(unsigned Which); template <unsigned Which> inline void trigger_irq(u8 irq_type); - static constexpr int timer_ch_size = 2; - enum { - T0_TIMER = 1, - T1_TIMER - }; inline void trigger_timer(unsigned Which); u16 m_timer_in[2]; u16 m_timer_out[2]; diff --git a/src/devices/machine/at28c16.cpp b/src/devices/machine/at28c16.cpp index 575b7e71308..38dbdc25117 100644 --- a/src/devices/machine/at28c16.cpp +++ b/src/devices/machine/at28c16.cpp @@ -72,7 +72,7 @@ device_memory_interface::space_config_vector at28c16_device::memory_space_config void at28c16_device::device_start() { - m_write_timer = timer_alloc(0); + m_write_timer = timer_alloc( FUNC( at28c16_device::write_complete ), this ); save_item( NAME(m_a9_12v) ); save_item( NAME(m_oe_12v) ); @@ -229,12 +229,7 @@ WRITE_LINE_MEMBER( at28c16_device::set_oe_12v ) } -void at28c16_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER( at28c16_device::write_complete ) { - switch( id ) - { - case 0: - m_last_write = -1; - break; - } + m_last_write = -1; } diff --git a/src/devices/machine/at28c16.h b/src/devices/machine/at28c16.h index cdfe55243f1..ca412d7c0af 100644 --- a/src/devices/machine/at28c16.h +++ b/src/devices/machine/at28c16.h @@ -35,7 +35,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_memory_interface overrides virtual space_config_vector memory_space_config() const override; @@ -57,6 +56,7 @@ private: // I/O operations DECLARE_WRITE_LINE_MEMBER( set_a9_12v ); DECLARE_WRITE_LINE_MEMBER( set_oe_12v ); + TIMER_CALLBACK_MEMBER( write_complete ); void at28c16_map8(address_map &map); }; diff --git a/src/devices/machine/at28c64b.cpp b/src/devices/machine/at28c64b.cpp index 098454a771e..e3b33128be8 100644 --- a/src/devices/machine/at28c64b.cpp +++ b/src/devices/machine/at28c64b.cpp @@ -74,7 +74,7 @@ device_memory_interface::space_config_vector at28c64b_device::memory_space_confi void at28c64b_device::device_start() { - m_write_timer = timer_alloc(0); + m_write_timer = timer_alloc( FUNC( at28c64b_device::write_complete ), this ); save_item( NAME(m_a9_12v) ); save_item( NAME(m_oe_12v) ); @@ -273,12 +273,7 @@ WRITE_LINE_MEMBER( at28c64b_device::set_oe_12v ) } -void at28c64b_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER( at28c64b_device::write_complete ) { - switch( id ) - { - case 0: - m_last_write = -1; - break; - } + m_last_write = -1; } diff --git a/src/devices/machine/at28c64b.h b/src/devices/machine/at28c64b.h index 83d74cda5a4..c94ac1eec62 100644 --- a/src/devices/machine/at28c64b.h +++ b/src/devices/machine/at28c64b.h @@ -35,7 +35,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_memory_interface overrides virtual space_config_vector memory_space_config() const override; @@ -69,6 +68,7 @@ private: // I/O operations DECLARE_WRITE_LINE_MEMBER( set_a9_12v ); DECLARE_WRITE_LINE_MEMBER( set_oe_12v ); + TIMER_CALLBACK_MEMBER( write_complete ); void at28c64b_map8(address_map &map); }; diff --git a/src/devices/machine/at29x.cpp b/src/devices/machine/at29x.cpp index c701c13c557..bf0544ede0f 100644 --- a/src/devices/machine/at29x.cpp +++ b/src/devices/machine/at29x.cpp @@ -52,11 +52,6 @@ #include "logmacro.h" -enum -{ - PRGTIMER = 1 -}; - /* Constructor for all variants */ @@ -138,7 +133,7 @@ bool at29x_device::nvram_write(util::write_stream &file) /* Programming timer callback */ -void at29x_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(at29x_device::step_programming) { switch (m_pgm) { @@ -482,7 +477,7 @@ void at29x_device::device_start() { m_programming_buffer = std::make_unique<uint8_t[]>(m_sector_size); m_eememory = std::make_unique<uint8_t[]>(m_memory_size+2); - m_programming_timer = timer_alloc(PRGTIMER); + m_programming_timer = timer_alloc(FUNC(at29x_device::step_programming), this); // TODO: Complete 16-bit handling m_address_mask = m_memory_size/(m_word_width/8) - 1; diff --git a/src/devices/machine/at29x.h b/src/devices/machine/at29x.h index d32c159b8b6..5df3672877f 100644 --- a/src/devices/machine/at29x.h +++ b/src/devices/machine/at29x.h @@ -29,12 +29,13 @@ protected: virtual void device_start(void) override; virtual void device_reset(void) override; virtual void device_stop(void) override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; virtual void nvram_default() override; virtual bool nvram_read(util::read_stream &file) override; virtual bool nvram_write(util::write_stream &file) override; + TIMER_CALLBACK_MEMBER(step_programming); + int get_sector_number(offs_t address) { return address / m_sector_size; } const int m_memory_size; // bytes diff --git a/src/devices/machine/bq4847.cpp b/src/devices/machine/bq4847.cpp index 7c8b2060869..91fca4b8edd 100644 --- a/src/devices/machine/bq4847.cpp +++ b/src/devices/machine/bq4847.cpp @@ -450,9 +450,9 @@ void bq4847_device::update_int() void bq4847_device::device_start() { - m_update_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(bq4847_device::update_callback), this)); - m_periodic_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(bq4847_device::periodic_callback), this)); - m_watchdog_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(bq4847_device::watchdog_callback), this)); + m_update_timer = timer_alloc(FUNC(bq4847_device::update_callback), this); + m_periodic_timer = timer_alloc(FUNC(bq4847_device::periodic_callback), this); + m_watchdog_timer = timer_alloc(FUNC(bq4847_device::watchdog_callback), this); m_int_handler.resolve_safe(); m_wdo_handler.resolve_safe(); diff --git a/src/devices/machine/bq48x2.cpp b/src/devices/machine/bq48x2.cpp index 55434819a10..849f019ce6c 100644 --- a/src/devices/machine/bq48x2.cpp +++ b/src/devices/machine/bq48x2.cpp @@ -507,13 +507,13 @@ int bq48x2_device::get_delay() void bq48x2_device::device_start() { - m_clock_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(bq48x2_device::rtc_clock_cb), this)); + m_clock_timer = timer_alloc(FUNC(bq48x2_device::rtc_clock_cb), this); // Periodic timer - m_periodic_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(bq48x2_device::rtc_periodic_cb), this)); + m_periodic_timer = timer_alloc(FUNC(bq48x2_device::rtc_periodic_cb), this); // Watchdog timer - m_watchdog_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(bq48x2_device::rtc_watchdog_cb), this)); + m_watchdog_timer = timer_alloc(FUNC(bq48x2_device::rtc_watchdog_cb), this); // Interrupt line m_interrupt_cb.resolve_safe(); diff --git a/src/devices/machine/busmouse.cpp b/src/devices/machine/busmouse.cpp index 6734661b301..2def623649b 100644 --- a/src/devices/machine/busmouse.cpp +++ b/src/devices/machine/busmouse.cpp @@ -144,7 +144,7 @@ void bus_mouse_device::device_start() // resolve callbacks m_write_extint.resolve_safe(); - m_irq_timer = timer_alloc(0); + m_irq_timer = timer_alloc(FUNC(bus_mouse_device::irq_timer_tick), this); } @@ -165,7 +165,7 @@ void bus_mouse_device::device_reset() LOG("irq rate: %d Hz\n", hz); } -void bus_mouse_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(bus_mouse_device::irq_timer_tick) { irq = !irq; diff --git a/src/devices/machine/busmouse.h b/src/devices/machine/busmouse.h index 3f523946358..29c20d236ee 100644 --- a/src/devices/machine/busmouse.h +++ b/src/devices/machine/busmouse.h @@ -28,7 +28,6 @@ protected: // device-level overrides virtual void device_start() override; virtual void device_reset() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; virtual void device_add_mconfig(machine_config &config) override; // optional information overrides @@ -38,6 +37,8 @@ protected: uint8_t ppi_c_r(); void ppi_c_w(uint8_t data); + TIMER_CALLBACK_MEMBER(irq_timer_tick); + private: emu_timer *m_irq_timer; bool irq, irq_disabled; diff --git a/src/devices/machine/cdp1852.cpp b/src/devices/machine/cdp1852.cpp index b98b9a34fef..b4850ac669e 100644 --- a/src/devices/machine/cdp1852.cpp +++ b/src/devices/machine/cdp1852.cpp @@ -66,8 +66,8 @@ void cdp1852_device::device_start() m_write_data.resolve_safe(); // allocate timers - m_update_do_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(cdp1852_device::update_do), this)); - m_update_sr_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(cdp1852_device::update_sr), this)); + m_update_do_timer = timer_alloc(FUNC(cdp1852_device::update_do), this); + m_update_sr_timer = timer_alloc(FUNC(cdp1852_device::update_sr), this); // register for state saving save_item(NAME(m_new_data)); diff --git a/src/devices/machine/cdp1871.cpp b/src/devices/machine/cdp1871.cpp index fe1980fe004..3e32512c30f 100644 --- a/src/devices/machine/cdp1871.cpp +++ b/src/devices/machine/cdp1871.cpp @@ -152,7 +152,7 @@ void cdp1871_device::device_start() change_output_lines(); // allocate timers - m_scan_timer = timer_alloc(); + m_scan_timer = timer_alloc(FUNC(cdp1871_device::perform_scan), this); m_scan_timer->adjust(attotime::zero, 0, attotime::from_hz(clock())); // register for state saving @@ -172,10 +172,10 @@ void cdp1871_device::device_start() //------------------------------------------------- -// device_timer - handler timer events +// perform_scan - periodically scan for keys //------------------------------------------------- -void cdp1871_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(cdp1871_device::perform_scan) { change_output_lines(); clock_scan_counters(); diff --git a/src/devices/machine/cdp1871.h b/src/devices/machine/cdp1871.h index b6529479491..a359980f7fb 100644 --- a/src/devices/machine/cdp1871.h +++ b/src/devices/machine/cdp1871.h @@ -66,12 +66,13 @@ public: protected: // device-level overrides virtual void device_start() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; void change_output_lines(); void clock_scan_counters(); void detect_keypress(); + TIMER_CALLBACK_MEMBER(perform_scan); + private: devcb_read8 m_read_d1; devcb_read8 m_read_d2; diff --git a/src/devices/machine/cdp1879.cpp b/src/devices/machine/cdp1879.cpp index 8f9b8f6081c..f6687f73226 100644 --- a/src/devices/machine/cdp1879.cpp +++ b/src/devices/machine/cdp1879.cpp @@ -36,7 +36,7 @@ cdp1879_device::cdp1879_device(const machine_config &mconfig, const char *tag, d void cdp1879_device::device_start() { // allocate timers - m_clock_timer = timer_alloc(); + m_clock_timer = timer_alloc(FUNC(cdp1879_device::clock_tick), this); m_clock_timer->adjust(attotime::from_seconds(1), 0, attotime::from_seconds(1)); m_irq_w.resolve_safe(); @@ -61,10 +61,10 @@ void cdp1879_device::device_reset() //------------------------------------------------- -// device_timer - handler timer events +// clock_tick - advance the clock //------------------------------------------------- -void cdp1879_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(cdp1879_device::clock_tick) { advance_seconds(); diff --git a/src/devices/machine/cdp1879.h b/src/devices/machine/cdp1879.h index 7b839cc8d44..4dc761b5fd7 100644 --- a/src/devices/machine/cdp1879.h +++ b/src/devices/machine/cdp1879.h @@ -29,7 +29,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; @@ -38,6 +37,8 @@ protected: void set_irq(int bit); void update_rtc(); + TIMER_CALLBACK_MEMBER(clock_tick); + private: // registers enum diff --git a/src/devices/machine/clock.cpp b/src/devices/machine/clock.cpp index 9c0fd67a3ef..4c2ad3afd7a 100644 --- a/src/devices/machine/clock.cpp +++ b/src/devices/machine/clock.cpp @@ -44,8 +44,8 @@ void clock_device::device_start() save_item(NAME(m_thigh)); save_item(NAME(m_tlow)); - m_timer_init = timer_alloc(TID_CLOCK_INIT); - m_timer_tick = timer_alloc(TID_CLOCK_TICK); + m_timer_init = timer_alloc(FUNC(clock_device::clock_init), this); + m_timer_tick = timer_alloc(FUNC(clock_device::clock_tick), this); reinit(); } @@ -67,77 +67,67 @@ void clock_device::output() } } -void clock_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(clock_device::clock_init) { - switch (id) + attotime period = (m_clock > 0) ? attotime::from_hz(m_clock) : m_period; + assert(!period.is_zero()); + + if (period.is_never()) + { + m_timer_tick->adjust(attotime::never); + return; + } + + if (!m_pw.is_never()) { - case TID_CLOCK_INIT: + // set timing via pulse width + attotime pw = m_pw; + if (pw > period) + pw = period; + + m_thigh = pw; + m_tlow = period - pw; + } + else + { + // set timing via duty cycle + if (m_duty == 0.5) { - attotime period = (m_clock > 0) ? attotime::from_hz(m_clock) : m_period; - assert(!period.is_zero()); - - if (period.is_never()) - { - m_timer_tick->adjust(attotime::never); - return; - } - - if (!m_pw.is_never()) - { - // set timing via pulse width - attotime pw = m_pw; - if (pw > period) - pw = period; - - m_thigh = pw; - m_tlow = period - pw; - } - else - { - // set timing via duty cycle - if (m_duty == 0.5) - { - m_thigh = period / 2; - m_tlow = m_thigh; - } - else if (m_duty == 0.0) - { - m_thigh = attotime::zero; - m_tlow = period; - } - else if (m_duty == 1.0) - { - m_thigh = period; - m_tlow = attotime::zero; - } - else - { - double p = period.as_double(); - m_thigh = attotime::from_double(m_duty * p); - m_tlow = attotime::from_double((1.0 - m_duty) * p); - } - } - - attotime next = m_signal ? m_thigh : m_tlow; - if (next < m_timer_tick->remaining()) - m_timer_tick->adjust(next); - - break; + m_thigh = period / 2; + m_tlow = m_thigh; } + else if (m_duty == 0.0) + { + m_thigh = attotime::zero; + m_tlow = period; + } + else if (m_duty == 1.0) + { + m_thigh = period; + m_tlow = attotime::zero; + } + else + { + double p = period.as_double(); + m_thigh = attotime::from_double(m_duty * p); + m_tlow = attotime::from_double((1.0 - m_duty) * p); + } + } - case TID_CLOCK_TICK: - if (m_thigh.is_zero()) - m_signal = 0; - else if (m_tlow.is_zero()) - m_signal = 1; - else - m_signal ^= 1; - - m_timer_tick->adjust(m_signal ? m_thigh : m_tlow); - output(); - break; + attotime next = m_signal ? m_thigh : m_tlow; + if (next < m_timer_tick->remaining()) + m_timer_tick->adjust(next); +} - default: - break; - } +TIMER_CALLBACK_MEMBER(clock_device::clock_tick) +{ + if (m_thigh.is_zero()) + m_signal = 0; + else if (m_tlow.is_zero()) + m_signal = 1; + else + m_signal ^= 1; + + m_timer_tick->adjust(m_signal ? m_thigh : m_tlow); + output(); } diff --git a/src/devices/machine/clock.h b/src/devices/machine/clock.h index 27270653a32..1dc4739ce6c 100644 --- a/src/devices/machine/clock.h +++ b/src/devices/machine/clock.h @@ -26,13 +26,12 @@ public: protected: virtual void device_start() override; virtual void device_reset() override { output(); } - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; virtual void device_clock_changed() override { reinit(); } -private: - static constexpr device_timer_id TID_CLOCK_INIT = 0; - static constexpr device_timer_id TID_CLOCK_TICK = 1; + TIMER_CALLBACK_MEMBER(clock_init); + TIMER_CALLBACK_MEMBER(clock_tick); +private: void reinit(); void output(); diff --git a/src/devices/machine/com8116.cpp b/src/devices/machine/com8116.cpp index 5ad58710e85..38364b4b101 100644 --- a/src/devices/machine/com8116.cpp +++ b/src/devices/machine/com8116.cpp @@ -142,11 +142,11 @@ void com8116_device::device_start() // allocate timers if (!m_fx4_handler.isnull()) { - m_fx4_timer = timer_alloc(TIMER_FX4); + m_fx4_timer = timer_alloc(FUNC(com8116_device::fx4_tick), this); m_fx4_timer->adjust(attotime::from_hz((clock() / 4) * 2), 0, attotime::from_hz((clock() / 4)) * 2); } - m_fr_timer = timer_alloc(TIMER_FR); - m_ft_timer = timer_alloc(TIMER_FT); + m_fr_timer = timer_alloc(FUNC(com8116_device::fr_tick), this); + m_ft_timer = timer_alloc(FUNC(com8116_device::ft_tick), this); for (int i = 0; i < 16; i++) LOGMASKED(LOG_TABLE, "Output Frequency %01X: 16X %f Hz\n", i, double(clock()) / m_divisors[i] / 16.0); @@ -171,28 +171,35 @@ void com8116_device::device_reset() //------------------------------------------------- -// device_timer - handler timer events +// fx4_tick - toggle the FX4 timer output //------------------------------------------------- -void com8116_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(com8116_device::fx4_tick) { - switch (id) - { - case TIMER_FX4: - m_fx4 = !m_fx4; - m_fx4_handler(m_fx4); - break; - - case TIMER_FR: - m_fr = !m_fr; - m_fr_handler(m_fr); - break; - - case TIMER_FT: - m_ft = !m_ft; - m_ft_handler(m_ft); - break; - } + m_fx4 = !m_fx4; + m_fx4_handler(m_fx4); +} + + +//------------------------------------------------- +// fr_tick - toggle the FR timer output +//------------------------------------------------- + +TIMER_CALLBACK_MEMBER(com8116_device::fr_tick) +{ + m_fr = !m_fr; + m_fr_handler(m_fr); +} + + +//------------------------------------------------- +// ft_tick - toggle the FT timer output +//------------------------------------------------- + +TIMER_CALLBACK_MEMBER(com8116_device::ft_tick) +{ + m_ft = !m_ft; + m_ft_handler(m_ft); } diff --git a/src/devices/machine/com8116.h b/src/devices/machine/com8116.h index 13131b85f41..908d7c782d2 100644 --- a/src/devices/machine/com8116.h +++ b/src/devices/machine/com8116.h @@ -63,16 +63,12 @@ protected: // device-level overrides virtual void device_start() override; virtual void device_reset() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int m_param) override; -private: - enum - { - TIMER_FX4, - TIMER_FR, - TIMER_FT - }; + TIMER_CALLBACK_MEMBER(fx4_tick); + TIMER_CALLBACK_MEMBER(fr_tick); + TIMER_CALLBACK_MEMBER(ft_tick); +private: devcb_write_line m_fx4_handler; devcb_write_line m_fr_handler; devcb_write_line m_ft_handler; diff --git a/src/devices/machine/cop452.cpp b/src/devices/machine/cop452.cpp index 7d1da25efe3..87e2d0954d5 100644 --- a/src/devices/machine/cop452.cpp +++ b/src/devices/machine/cop452.cpp @@ -20,7 +20,7 @@ DEFINE_DEVICE_TYPE(COP452, cop452_device, "cop452", "National Semiconductor COP452 frequency generator") cop452_device::cop452_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock) -: device_t(mconfig , COP452 , tag , owner , clock) +: device_t(mconfig, COP452, tag, owner, clock) , m_out_handlers(*this) { } @@ -39,7 +39,7 @@ WRITE_LINE_MEMBER(cop452_device::sk_w) { if (!m_cs && !m_sk && state) { // Rising edge on SK - LOG("bit %d %u\n" , m_di , m_spi_state); + LOG("bit %d %u\n", m_di, m_spi_state); if (m_spi_state == 0 && m_di) { // Got start bit m_spi_state = 1; @@ -48,31 +48,31 @@ WRITE_LINE_MEMBER(cop452_device::sk_w) m_sr = (m_sr << 1) | m_di; m_spi_state++; if (m_spi_state == 6) { - LOG("Inst = %x\n" , m_sr); + LOG("Inst = %x\n", m_sr); m_spi_state = 22; - unsigned idx = !BIT(m_sr , 0); + unsigned idx = !BIT(m_sr, 0); char reg = idx ? 'B' : 'A'; switch (m_sr) { case 0b00000: case 0b00001: // LDRA/B - LOG("LDR%c\n" , reg); + LOG("LDR%c\n", reg); m_spi_state = 6; - m_reg[ idx ] = 0; + m_reg[idx] = 0; break; case 0b00010: case 0b00011: // RDRA/B // TODO: not implemented ATM - LOG("RDR%c\n" , reg); + LOG("RDR%c\n", reg); break; case 0b00100: case 0b00101: // TRCA/B - LOG("TRC%c\n" , reg); - m_cnt[ idx ] = m_reg[ idx ]; + LOG("TRC%c\n", reg); + m_cnt[idx] = m_reg[idx]; set_timer(idx); break; @@ -80,7 +80,7 @@ WRITE_LINE_MEMBER(cop452_device::sk_w) case 0b00111: // TCRA/B // TODO: - LOG("TCR%c\n" , reg); + LOG("TCR%c\n", reg); break; case 0b01000: @@ -99,17 +99,17 @@ WRITE_LINE_MEMBER(cop452_device::sk_w) if (m_sr & 0b10000) { // LDM m_mode = m_sr & 0b01111; - LOG("LDM %x\n" , m_mode); + LOG("LDM %x\n", m_mode); set_timer(0); set_timer(1); if (m_mode == MODE_NUMBER_PULSES) { // Always start with OA = 1 - set_output(0 , true); + set_output(0, true); } else if (m_mode == MODE_WHITE_NOISE || m_mode == MODE_GATED_WHITE) { // Preset bit 15 & 16 of register A when entering // white noise modes - m_reg[ 0 ] |= 0x8000; + m_reg[0] |= 0x8000; m_regA_b16 = true; } } else { @@ -121,12 +121,11 @@ WRITE_LINE_MEMBER(cop452_device::sk_w) } } else if (m_spi_state >= 6 && m_spi_state < 22) { // Loading A/B register - unsigned idx = !BIT(m_sr , 0); - char reg = idx ? 'B' : 'A'; - m_reg[ idx ] = (m_reg[ idx ] << 1) | m_di; + unsigned idx = !BIT(m_sr, 0); + m_reg[idx] = (m_reg[idx] << 1) | m_di; m_spi_state++; if (m_spi_state == 22) { - LOG("REG%c = %04x\n" , reg , m_reg[ idx ]); + LOG("REG%c = %04x\n", idx ? 'B' : 'A', m_reg[idx]); } } } @@ -148,8 +147,8 @@ void cop452_device::device_start() { m_out_handlers.resolve_all_safe(); - m_timers[ 0 ] = timer_alloc(0); - m_timers[ 1 ] = timer_alloc(1); + m_timers[0] = timer_alloc(FUNC(cop452_device::timer_tick), this); + m_timers[1] = timer_alloc(FUNC(cop452_device::timer_tick), this); save_item(NAME(m_mode)); save_item(NAME(m_clk_div_4)); @@ -169,20 +168,20 @@ void cop452_device::device_reset() // Set reset mode m_mode = MODE_RESET; m_clk_div_4 = true; - m_out[ 0 ] = m_out[ 1 ] = true; - set_output(0 , false); - set_output(1 , false); + m_out[0] = m_out[1] = true; + set_output(0, false); + set_output(1, false); m_spi_state = 0; m_sr = 0; - m_timers[ 0 ]->reset(); - m_timers[ 1 ]->reset(); + m_timers[0]->reset(); + m_timers[1]->reset(); } -void cop452_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(cop452_device::timer_tick) { switch (m_mode) { case MODE_DUAL_FREQ: - toggle_n_reload(id); + toggle_n_reload(param); break; case MODE_TRIG_PULSE: @@ -190,12 +189,12 @@ void cop452_device::device_timer(emu_timer &timer, device_timer_id id, int param break; case MODE_NUMBER_PULSES: - if (id == 0) { + if (param == 0) { toggle_n_reload(0); - if (!m_out[ 0 ]) { + if (!m_out[0]) { // It seems that cnt B decrements each time OA goes low - if (m_cnt[ 1 ] != 0) { - m_cnt[ 1 ]--; + if (m_cnt[1] != 0) { + m_cnt[1]--; } else { // End of pulse train toggle_n_reload(1); @@ -228,22 +227,22 @@ void cop452_device::device_timer(emu_timer &timer, device_timer_id id, int param case MODE_WHITE_NOISE: case MODE_GATED_WHITE: { - if (id == 0) { + if (param == 0) { // Reg A & its 17th bit (m_regA_b16) form a 17-bit LFSR // LFSR uses X^17+X^14+1 polynomial to generate a pseudo-random // maximal-length sequence - bool feedback = m_regA_b16 ^ BIT(m_reg[ 0 ] , 13); - m_regA_b16 = BIT(m_reg[ 0 ] , 15); - m_reg[ 0 ] <<= 1; - m_reg[ 0 ] |= feedback; + bool feedback = m_regA_b16 ^ BIT(m_reg[0], 13); + m_regA_b16 = BIT(m_reg[0], 15); + m_reg[0] <<= 1; + m_reg[0] |= feedback; } else { toggle_n_reload(1); } bool new_out_0 = m_regA_b16; if (m_mode == MODE_GATED_WHITE) { - new_out_0 &= m_out[ 1 ]; + new_out_0 &= m_out[1]; } - set_output(0 , new_out_0); + set_output(0, new_out_0); } break; @@ -251,7 +250,7 @@ void cop452_device::device_timer(emu_timer &timer, device_timer_id id, int param break; } - set_timer(id); + set_timer(param); } attotime cop452_device::counts_to_attotime(unsigned counts) const @@ -270,7 +269,7 @@ void cop452_device::set_timer(unsigned idx) switch (m_mode) { case MODE_DUAL_FREQ: // Cnt A & B count independently - target = counts_to_attotime(m_cnt[ idx ]); + target = counts_to_attotime(m_cnt[idx]); break; case MODE_TRIG_PULSE: @@ -281,7 +280,7 @@ void cop452_device::set_timer(unsigned idx) // Cnt A generates OA frequency // Cnt B counts the periods to output if (idx == 0) { - target = counts_to_attotime(m_cnt[ 0 ]); + target = counts_to_attotime(m_cnt[0]); } break; @@ -312,7 +311,7 @@ void cop452_device::set_timer(unsigned idx) if (idx == 0) { target = counts_to_attotime(0); } else { - target = counts_to_attotime(m_cnt[ 1 ]); + target = counts_to_attotime(m_cnt[1]); } break; @@ -320,26 +319,26 @@ void cop452_device::set_timer(unsigned idx) break; } - m_timers[ idx ]->adjust(target); + m_timers[idx]->adjust(target, idx); } -void cop452_device::set_output(unsigned idx , bool state) +void cop452_device::set_output(unsigned idx, bool state) { - if (m_out[ idx ] != state) { - m_out[ idx ] = state; - LOG("OUT %u=%d @%s\n" , idx , state , machine().time().as_string()); - m_out_handlers[ idx ](state); + if (m_out[idx] != state) { + m_out[idx] = state; + LOG("OUT %u=%d @%s\n", idx, state, machine().time().as_string()); + m_out_handlers[idx](state); } } void cop452_device::toggle_output(unsigned idx) { - set_output(idx , !m_out[ idx ]); + set_output(idx, !m_out[idx]); } void cop452_device::toggle_n_reload(unsigned idx) { // Toggle output OA/OB and reload its associated counter toggle_output(idx); - m_cnt[ idx ] = m_reg[ idx ]; + m_cnt[idx] = m_reg[idx]; } diff --git a/src/devices/machine/cop452.h b/src/devices/machine/cop452.h index 048c8c7d5cd..238e5c8b5ca 100644 --- a/src/devices/machine/cop452.h +++ b/src/devices/machine/cop452.h @@ -35,21 +35,22 @@ public: DECLARE_READ_LINE_MEMBER(do_r); // Signal outputs - auto oa_w() { return m_out_handlers[ 0 ].bind(); } - auto ob_w() { return m_out_handlers[ 1 ].bind(); } + auto oa_w() { return m_out_handlers[0].bind(); } + auto ob_w() { return m_out_handlers[1].bind(); } 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(timer_tick); private: // Index 0 is for "A" side, 1 is for "B" side devcb_write_line::array<2> m_out_handlers; // Timers - emu_timer *m_timers[ 2 ]; + emu_timer *m_timers[2]; // State uint8_t m_mode; @@ -57,10 +58,10 @@ private: bool m_cs; bool m_sk; bool m_di; - bool m_out[ 2 ]; + bool m_out[2]; bool m_regA_b16; - uint16_t m_reg[ 2 ]; - uint16_t m_cnt[ 2 ]; + uint16_t m_reg[2]; + uint16_t m_cnt[2]; // 0 : idle // 1..5 : shifting instruction in // 6..21: shifting register in @@ -70,22 +71,22 @@ private: // Operating modes enum : uint8_t { - MODE_DUAL_FREQ, // 0000 Dual frequency - MODE_TRIG_PULSE, // 0001 Triggered pulse - MODE_NUMBER_PULSES, // 0010 Number of pulses - MODE_DUTY_CYCLE, // 0011 Duty cycle - MODE_FREQ_COUNT, // 0100 Frequency and count - MODE_DUAL_COUNT, // 0101 Dual count - MODE_WAVE_MEAS, // 0110 Waveform measurement - MODE_TRIG_COUNT, // 0111 Triggered pulse and count - MODE_WHITE_NOISE, // 1000 White noise & frequency - MODE_GATED_WHITE, // 1001 Gated white noise - MODE_RESET = 15 // 1111 Reset + MODE_DUAL_FREQ, // 0000 Dual frequency + MODE_TRIG_PULSE, // 0001 Triggered pulse + MODE_NUMBER_PULSES, // 0010 Number of pulses + MODE_DUTY_CYCLE, // 0011 Duty cycle + MODE_FREQ_COUNT, // 0100 Frequency and count + MODE_DUAL_COUNT, // 0101 Dual count + MODE_WAVE_MEAS, // 0110 Waveform measurement + MODE_TRIG_COUNT, // 0111 Triggered pulse and count + MODE_WHITE_NOISE, // 1000 White noise & frequency + MODE_GATED_WHITE, // 1001 Gated white noise + MODE_RESET = 15 // 1111 Reset }; attotime counts_to_attotime(unsigned counts) const; void set_timer(unsigned idx); - void set_output(unsigned idx , bool state); + void set_output(unsigned idx, bool state); void toggle_output(unsigned idx); void toggle_n_reload(unsigned idx); }; diff --git a/src/devices/machine/corvushd.cpp b/src/devices/machine/corvushd.cpp index f4194cdfb46..b0c819b33f8 100644 --- a/src/devices/machine/corvushd.cpp +++ b/src/devices/machine/corvushd.cpp @@ -67,6 +67,10 @@ #include "emu.h" #include "machine/corvushd.h" +#define LOG_RESPONSES (1U << 1) + +#define VERBOSE (0) +#include "logmacro.h" // // Controller Commands @@ -241,8 +245,6 @@ corvus_hdc_device::corvus_hdc_device(const machine_config &mconfig, const char * { } -#define VERBOSE 0 -#define VERBOSE_RESPONSES 0 #define ROM_VERSION 1 // Controller ROM version #define MAX_COMMAND_SIZE 4096 // The maximum size of a command packet (the controller only has 5K of RAM...) #define SPARE_TRACKS 7 // This is a Rev B drive, so 7 it is @@ -254,8 +256,7 @@ corvus_hdc_device::corvus_hdc_device(const machine_config &mconfig, const char * #define INTERBYTE_DELAY 5 // Inter-byte delay in microseconds communicating between controller and host #define INTERSECTOR_DELAY 25000 // 25ms delay between sectors (4800 RPM = 80 Rev/Second. Maximum 2 sectors transferred / Rev) -#define LOG(x) do { if (VERBOSE) logerror x; } while (0) -#define LOG_BUFFER(p,s) do { if (VERBOSE) dump_buffer(p,s); } while (0) +#define LOG_BUFFER(p,s) do { if (VERBOSE & LOG_RESPONSES) dump_buffer(p,s); } while (0) @@ -272,26 +273,26 @@ corvus_hdc_device::corvus_hdc_device(const machine_config &mconfig, const char * // nada // void corvus_hdc_device::dump_buffer(uint8_t *buffer, uint16_t length) { - uint16_t offset; - char ascii_dump[16]; - - logerror("dump_buffer: Dump of %d bytes:\n", length); - logerror("Base 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f ASCII\n"); - logerror("---- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- ----------------"); - - for(offset=0; offset < length; offset++) { - if(offset % 16 == 0) { // WHY IS 0 % 16 == 0??? - if(offset > 0 && offset % 16 == 0) - logerror("%16.16s", ascii_dump); - logerror("\n%4.4x: %2.2x ", offset, *(buffer + offset)); - } else { - logerror("%2.2x ", *(buffer + offset)); + LOGMASKED(LOG_RESPONSES, "dump_buffer: Dump of %d bytes:\n", length); + LOGMASKED(LOG_RESPONSES, "Base 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f ASCII\n"); + LOGMASKED(LOG_RESPONSES, "---- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- ----------------"); + + char data_buf[128]; + char ascii_buf[17]; + for(uint16_t offset = 0; offset < length; offset += 16) { + int buf_offset = 0; + for(uint8_t byte_idx = 0; byte_idx < 16 && (offset + byte_idx) < length; byte_idx++) { + sprintf(data_buf + buf_offset, "%02x ", *(buffer + offset)); + ascii_buf[byte_idx] = isprint(*(buffer + offset)) ? *(buffer + offset) : '.'; } - ascii_dump[offset % 16] = isprint(*(buffer + offset)) ? *(buffer + offset) : '.'; + if((length - offset) < 16) { + memset(data_buf + buf_offset, 0, (length - offset) * 3); + buf_offset += (length - offset) * 3; + } + data_buf[buf_offset] = '\0'; + ascii_buf[16] = '\0'; + LOGMASKED(LOG_RESPONSES, "%04x: %s%s", offset, data_buf, ascii_buf); } - if(offset % 16) - logerror("%.*s", (16 - (offset % 16)) * 3, " "); - logerror("%.*s\n", (offset % 16) ? (offset % 16) : 16, ascii_dump); } @@ -314,7 +315,7 @@ void corvus_hdc_device::dump_buffer(uint8_t *buffer, uint16_t length) { bool corvus_hdc_device::parse_hdc_command(uint8_t data) { m_awaiting_modifier = false; // This is the case by definition - LOG(("parse_hdc_command: Called with data: 0x%2.2x, Prep mode is: %d\n", data, m_prep_mode)); + LOG("parse_hdc_command: Called with data: 0x%2.2x, Prep mode is: %d\n", data, m_prep_mode); if(!m_prep_mode) { switch(data) { @@ -340,8 +341,8 @@ bool corvus_hdc_device::parse_hdc_command(uint8_t data) { case PREP_MODE_SELECT: m_recv_bytes = corvus_cmd[data][0].recv_bytes; m_xmit_bytes = corvus_cmd[data][0].xmit_bytes; - LOG(("parse_hdc_command: Single byte command recognized: 0x%2.2x, to recv: %d, to xmit: %d\n", data, - m_recv_bytes, m_xmit_bytes)); + LOG("parse_hdc_command: Single byte command recognized: 0x%2.2x, to recv: %d, to xmit: %d\n", data, + m_recv_bytes, m_xmit_bytes); break; // // Double-byte commands @@ -363,13 +364,13 @@ bool corvus_hdc_device::parse_hdc_command(uint8_t data) { // case DELACTIVENUM_OMNI_CODE: // case FINDACTIVE_CODE: m_awaiting_modifier = true; - LOG(("parse_hdc_command: Double byte command recognized: 0x%2.2x\n", data)); + LOG("parse_hdc_command: Double byte command recognized: 0x%2.2x\n", data); break; default: // This is an INVALID command m_recv_bytes = 1; m_xmit_bytes = 1; - LOG(("parse_hdc_command: Invalid command detected: 0x%2.2x\n", data)); + LOG("parse_hdc_command: Invalid command detected: 0x%2.2x\n", data); return true; } } else { @@ -386,14 +387,14 @@ bool corvus_hdc_device::parse_hdc_command(uint8_t data) { case PREP_WRITE_FIRMWARE: m_recv_bytes = corvus_prep_cmd[data].recv_bytes; m_xmit_bytes = corvus_prep_cmd[data].xmit_bytes; - LOG(("parse_hdc_command: Prep command recognized: 0x%2.2x, to recv: %d, to xmit: %d\n", data, - m_recv_bytes, m_xmit_bytes)); + LOG("parse_hdc_command: Prep command recognized: 0x%2.2x, to recv: %d, to xmit: %d\n", data, + m_recv_bytes, m_xmit_bytes); break; default: // This is an INVALID prep command m_recv_bytes = 1; m_xmit_bytes = 1; - LOG(("parse_hdc_command: Invalid Prep command detected: 0x%2.2x\n", data)); + LOG("parse_hdc_command: Invalid Prep command detected: 0x%2.2x\n", data); return true; } } // if(!prep_mode) @@ -423,7 +424,7 @@ uint8_t corvus_hdc_device::corvus_write_sector(uint8_t drv, uint32_t sector, uin uint8_t tbuffer[512]; // Buffer to hold an entire sector uint16_t cylinder; // Cylinder this sector resides on - LOG(("corvus_write_sector: Write Drive: %d, physical sector: 0x%5.5x\n", drv, sector)); + LOG("corvus_write_sector: Write Drive: %d, physical sector: 0x%5.5x\n", drv, sector); disk = corvus_hdc_file(drv); if(!disk) { @@ -454,7 +455,7 @@ uint8_t corvus_hdc_device::corvus_write_sector(uint8_t drv, uint32_t sector, uin m_last_cylinder = cylinder; - LOG(("corvus_write_sector: Full sector dump on a write of %d bytes follows:\n", len)); + LOG("corvus_write_sector: Full sector dump on a write of %d bytes follows:\n", len); LOG_BUFFER(len == 512 ? buffer : tbuffer, 512); return STAT_SUCCESS; @@ -491,8 +492,8 @@ uint8_t corvus_hdc_device::corvus_write_logical_sector(dadr_t *dadr, uint8_t *bu drv = (dadr->address_msn_and_drive & 0x0f); sector = (dadr->address_msn_and_drive & 0xf0 << 12) | (dadr->address_mid << 8) | dadr->address_lsb; - LOG(("corvus_write_logical_sector: Writing based on DADR: 0x%6.6x, logical sector: 0x%5.5x, drive: %d\n", - dadr->address_msn_and_drive << 16 | dadr->address_lsb << 8 | dadr->address_mid, sector, drv)); + LOG("corvus_write_logical_sector: Writing based on DADR: 0x%6.6x, logical sector: 0x%5.5x, drive: %d\n", + dadr->address_msn_and_drive << 16 | dadr->address_lsb << 8 | dadr->address_mid, sector, drv); // Set m_tracks_per_cylinder and m_sectors_per_track corvus_hdc_file(drv); @@ -531,7 +532,7 @@ uint8_t corvus_hdc_device::corvus_read_sector(uint8_t drv, uint32_t sector, uint uint8_t tbuffer[512]; // Buffer to store full sector results in uint16_t cylinder; - LOG(("corvus_read_sector: Read Drive: %d, physical sector: 0x%5.5x\n", drv, sector)); + LOG("corvus_read_sector: Read Drive: %d, physical sector: 0x%5.5x\n", drv, sector); disk = corvus_hdc_file(drv); if(!disk) { @@ -551,7 +552,7 @@ uint8_t corvus_hdc_device::corvus_read_sector(uint8_t drv, uint32_t sector, uint m_last_cylinder = cylinder; - LOG(("corvus_read_sector: Data read follows:\n")); + LOG("corvus_read_sector: Data read follows:\n"); LOG_BUFFER(tbuffer, len); return STAT_SUCCESS; @@ -588,8 +589,8 @@ uint8_t corvus_hdc_device::corvus_read_logical_sector(dadr_t *dadr, uint8_t *buf drv = (dadr->address_msn_and_drive & 0x0f); sector = (dadr->address_msn_and_drive & 0xf0 << 12) | (dadr->address_mid << 8) | dadr->address_lsb; - LOG(("corvus_read_logical_sector: Reading based on DADR: 0x%6.6x, logical sector: 0x%5.5x, drive: %d\n", - dadr->address_msn_and_drive << 16 | dadr->address_lsb << 8 | dadr->address_mid, sector, drv)); + LOG("corvus_read_logical_sector: Reading based on DADR: 0x%6.6x, logical sector: 0x%5.5x, drive: %d\n", + dadr->address_msn_and_drive << 16 | dadr->address_lsb << 8 | dadr->address_mid, sector, drv); // Set up m_tracks_per_cylinder and m_sectors_per_track corvus_hdc_file(drv); @@ -887,7 +888,7 @@ uint8_t corvus_hdc_device::corvus_get_drive_parameters(uint8_t drv) { m_buffer.drive_param_response.physical_capacity.midb = (raw_capacity & 0x00ff00) >> 8; m_buffer.drive_param_response.physical_capacity.lsb = (raw_capacity & 0x0000ff); - LOG(("corvus_get_drive_parameters: Drive Parameter packet follows:\n")); + LOG("corvus_get_drive_parameters: Drive Parameter packet follows:\n"); LOG_BUFFER(m_buffer.raw_data, 110); return STAT_SUCCESS; @@ -907,7 +908,7 @@ uint8_t corvus_hdc_device::corvus_get_drive_parameters(uint8_t drv) { // status: Status of read operation // uint8_t corvus_hdc_device::corvus_read_boot_block(uint8_t block) { - LOG(("corvus_read_boot_block: Reading boot block: %d\n", block)); + LOG("corvus_read_boot_block: Reading boot block: %d\n", block); return corvus_read_sector(1, 25 + block, m_buffer.read_512_response.data, 512); } @@ -957,7 +958,7 @@ uint8_t corvus_hdc_device::corvus_enter_prep_mode(uint8_t drv, uint8_t *prep_blo return STAT_FATAL_ERR | STAT_DRIVE_NOT_ONLINE; } - LOG(("corvus_enter_prep_mode: Prep mode entered for drive %d, prep block follows:\n", drv)); + LOG("corvus_enter_prep_mode: Prep mode entered for drive %d, prep block follows:\n", drv); LOG_BUFFER(prep_block, 512); m_prep_mode = true; @@ -976,7 +977,7 @@ uint8_t corvus_hdc_device::corvus_enter_prep_mode(uint8_t drv, uint8_t *prep_blo // Status of command (always success) // uint8_t corvus_hdc_device::corvus_exit_prep_mode() { - LOG(("corvus_exit_prep_mode: Prep mode exited\n")); + LOG("corvus_exit_prep_mode: Prep mode exited\n"); m_prep_mode = false; m_prep_drv = 0; return STAT_SUCCESS; @@ -1002,8 +1003,8 @@ uint8_t corvus_hdc_device::corvus_read_firmware_block(uint8_t head, uint8_t sect relative_sector = head * m_sectors_per_track + sector; - LOG(("corvus_read_firmware_block: Reading firmware head: 0x%2.2x, sector: 0x%2.2x, relative_sector: 0x%2.2x\n", - head, sector, relative_sector)); + LOG("corvus_read_firmware_block: Reading firmware head: 0x%2.2x, sector: 0x%2.2x, relative_sector: 0x%2.2x\n", + head, sector, relative_sector); status = corvus_read_sector(m_prep_drv, relative_sector, m_buffer.read_512_response.data, 512); return status; @@ -1030,8 +1031,8 @@ uint8_t corvus_hdc_device::corvus_write_firmware_block(uint8_t head, uint8_t sec relative_sector = head * m_sectors_per_track + sector; - LOG(("corvus_write_firmware_block: Writing firmware head: 0x%2.2x, sector: 0x%2.2x, relative_sector: 0x%2.2x\n", - head, sector, relative_sector)); + LOG("corvus_write_firmware_block: Writing firmware head: 0x%2.2x, sector: 0x%2.2x, relative_sector: 0x%2.2x\n", + head, sector, relative_sector); status = corvus_write_sector(m_prep_drv, relative_sector, buffer, 512); return status; @@ -1069,7 +1070,7 @@ uint8_t corvus_hdc_device::corvus_format_drive(uint8_t *pattern, uint16_t len) { pattern = tbuffer; } - LOG(("corvus_format_drive: Formatting drive with 0x%5.5x sectors, pattern buffer (passed length: %d) follows\n", max_sector, 512)); + LOG("corvus_format_drive: Formatting drive with 0x%5.5x sectors, pattern buffer (passed length: %d) follows\n", max_sector, 512); LOG_BUFFER(pattern, 512); for(sector = 0; sector <= max_sector; sector++) { @@ -1124,7 +1125,7 @@ hard_disk_file *corvus_hdc_device::corvus_hdc_file(int drv) { m_tracks_per_cylinder = info.heads; m_cylinders_per_drive = info.cylinders; - LOG(("corvus_hdc_file: Attached to drive %u image: H:%d, C:%d, S:%d\n", drv, info.heads, info.cylinders, info.sectors)); + LOG("corvus_hdc_file: Attached to drive %u image: H:%d, C:%d, S:%d\n", drv, info.heads, info.cylinders, info.sectors); return file; } @@ -1143,11 +1144,8 @@ hard_disk_file *corvus_hdc_device::corvus_hdc_file(int drv) { // Nothing // void corvus_hdc_device::corvus_process_command_packet(bool invalid_command_flag) { - if (VERBOSE_RESPONSES) - { - LOG(("corvus_hdc_data_w: Complete packet received. Dump follows:\n")); - LOG_BUFFER(m_buffer.raw_data, m_offset); - } + LOGMASKED(LOG_RESPONSES, "corvus_hdc_data_w: Complete packet received. Dump follows:\n"); + LOG_BUFFER(m_buffer.raw_data, m_offset); if(!invalid_command_flag) { if(!m_prep_mode) { @@ -1266,12 +1264,9 @@ void corvus_hdc_device::corvus_process_command_packet(bool invalid_command_flag) logerror("corvus_hdc_data_w: Unimplemented Prep command %02x, returning FATAL FAULT status!\n", m_buffer.command.code); } } - if (VERBOSE_RESPONSES) - { - LOG(("corvus_hdc_data_w: Command execution complete, status: 0x%2.2x. Response dump follows:\n", - m_buffer.single_byte_response.status)); - LOG_BUFFER(m_buffer.raw_data, m_xmit_bytes); - } + LOGMASKED(LOG_RESPONSES, "corvus_hdc_data_w: Command execution complete, status: 0x%2.2x. Response dump follows:\n", + m_buffer.single_byte_response.status); + LOG_BUFFER(m_buffer.raw_data, m_xmit_bytes); } // if(!invalid_command_flag) @@ -1292,12 +1287,11 @@ void corvus_hdc_device::corvus_process_command_packet(bool invalid_command_flag) // m_offset = 0; // Point to beginning of buffer for response - LOG(("corvus_hdc_data_w: Setting one-time mame timer of %d microseconds to simulate disk function\n", m_delay)); + LOG("corvus_hdc_data_w: Setting one-time mame timer of %d microseconds to simulate disk function\n", m_delay); // // Set up timers for command completion and timeout from host // - //machine.scheduler().timer_set(attotime::from_usec(m_delay), FUNC(corvus_hdc_callback), CALLBACK_CTH_MODE); m_cmd_timer->adjust(attotime::from_usec(m_delay), CALLBACK_CTH_MODE); m_timeout_timer->enable(0); // We've received enough data, disable the timeout timer @@ -1305,54 +1299,51 @@ void corvus_hdc_device::corvus_process_command_packet(bool invalid_command_flag) } +//------------------------------------------------- +// process_timeout - handle a command timeout +//------------------------------------------------- -// -// Corvus_HDC_Callback -// -// Callback routine for completion of controller functions -// -// Pass: -// Callback Function -// -// Returns: -// Nothing -// -void corvus_hdc_device::device_timer(emu_timer &timer, device_timer_id id, int param) -{ +TIMER_CALLBACK_MEMBER(corvus_hdc_device::process_timeout) { + if(m_offset < m_recv_bytes || (m_offset > m_recv_bytes && m_recv_bytes != 0)) { + m_buffer.single_byte_response.status = STAT_TIMEOUT; + m_status |= CONTROLLER_DIRECTION; + m_status &= ~(CONTROLLER_BUSY); + m_recv_bytes = 0; + m_xmit_bytes = 1; + logerror("corvus_hdc_callback: Exceeded four-second timeout for data from host, resetting communications\n"); + } else { // if(m_recv_bytes == 0) This was a variable-size command + LOG("corvus_hdc_callback: Executing variable-length command via four-second timeout\n"); + corvus_process_command_packet(0); // Process the command + } +} + +//------------------------------------------------- +// complete_function - callback to complete a +// controller function +//------------------------------------------------- + +TIMER_CALLBACK_MEMBER(corvus_hdc_device::complete_function) { int function = param; - switch(function) { + switch (param) { case CALLBACK_CTH_MODE: m_status |= CONTROLLER_DIRECTION; // Set to Controller-to-Host, Ready mode m_status &= ~(CONTROLLER_BUSY); - LOG(("corvus_hdc_callback: Callback executed with function CALLBACK_CTH_MODE\n")); - + LOG("corvus_hdc_callback: Callback executed with function CALLBACK_CTH_MODE\n"); break; + case CALLBACK_HTC_MODE: m_status &= ~(CONTROLLER_DIRECTION | CONTROLLER_BUSY); // Set to Host-to-Controller, Ready mode - LOG(("corvus_hdc_callback: Callback executed with function CALLBACK_HTC_MODE\n")); - + LOG("corvus_hdc_callback: Callback executed with function CALLBACK_HTC_MODE\n"); break; + case CALLBACK_SAME_MODE: m_status &= ~(CONTROLLER_BUSY); // Set the controller to Ready mode - - break; - case CALLBACK_TIMEOUT: // We reached a four-second timeout threshold - if(m_offset < m_recv_bytes || (m_offset > m_recv_bytes && m_recv_bytes != 0)) { - m_buffer.single_byte_response.status = STAT_TIMEOUT; - m_status |= CONTROLLER_DIRECTION; - m_status &= ~(CONTROLLER_BUSY); - m_recv_bytes = 0; - m_xmit_bytes = 1; - logerror("corvus_hdc_callback: Exceeded four-second timeout for data from host, resetting communications\n"); - } else { // if(m_recv_bytes == 0) This was a variable-size command - LOG(("corvus_hdc_callback: Executing variable-length command via four-second timeout\n")); - corvus_process_command_packet(0); // Process the command - } break; + default: logerror("corvus_hdc_callback: FATAL ERROR -- Unknown callback function: %d\n", function); assert(0); @@ -1383,11 +1374,12 @@ void corvus_hdc_device::device_start() { m_xmit_bytes = 0; // We don't have anything to say to the host m_recv_bytes = 0; // We aren't waiting on additional data from the host - m_timeout_timer = timer_alloc(TIMER_TIMEOUT); // Set up a timer to handle the four-second host-to-controller timeout - m_timeout_timer->adjust(attotime::from_seconds(4), CALLBACK_TIMEOUT); + // Set up a timer to handle the four-second host-to-controller timeout + m_timeout_timer = timer_alloc(FUNC(corvus_hdc_device::process_timeout), this); + m_timeout_timer->adjust(attotime::from_seconds(4)); m_timeout_timer->enable(0); // Start this timer out disabled - m_cmd_timer = timer_alloc(TIMER_COMMAND); + m_cmd_timer = timer_alloc(FUNC(corvus_hdc_device::complete_function), this); // // Define all of the packet sizes for the commands @@ -1487,7 +1479,7 @@ void corvus_hdc_device::device_start() { corvus_prep_cmd[PREP_WRITE_FIRMWARE].recv_bytes = 514; corvus_prep_cmd[PREP_WRITE_FIRMWARE].xmit_bytes = 1; - LOG(("corvus_hdc_init: Drive structures initialized\n")); + LOG("corvus_hdc_init: Drive structures initialized\n"); } @@ -1537,7 +1529,7 @@ uint8_t corvus_hdc_device::read() { result = m_buffer.raw_data[m_offset++]; if(m_offset == m_xmit_bytes) { - LOG(("corvus_hdc_data_r: Finished transmitting %d bytes of data. Returning to idle mode.\n", m_xmit_bytes)); + LOG("corvus_hdc_data_r: Finished transmitting %d bytes of data. Returning to idle mode.\n", m_xmit_bytes); m_offset = 0; // We've reached the end of valid data m_xmit_bytes = 0; // We don't have anything more to say @@ -1589,12 +1581,12 @@ void corvus_hdc_device::write(uint8_t data) { // We're supposed to be paying attention. Make a decision about the data received // if(m_offset == 0) { // First byte of a packet - LOG(("corvus_hdc_data_w: Received a byte with m_offset == 0. Processing as command: 0x%2.2x\n", data)); + LOG("corvus_hdc_data_w: Received a byte with m_offset == 0. Processing as command: 0x%2.2x\n", data); m_invalid_command_flag = parse_hdc_command(data); m_timeout_timer->reset((attotime::from_seconds(4))); m_timeout_timer->enable(1); // Start our four-second timer } else if(m_offset == 1 && m_awaiting_modifier) { // Second byte of a packet - LOG(("corvus_hdc_data_w: Received a byte while awaiting modifier with m_offset == 0. Processing as modifier: 0x%2.2x\n", data)); + LOG("corvus_hdc_data_w: Received a byte while awaiting modifier with m_offset == 0. Processing as modifier: 0x%2.2x\n", data); m_awaiting_modifier = false; m_recv_bytes = corvus_cmd[m_buffer.command.code][data].recv_bytes; m_xmit_bytes = corvus_cmd[m_buffer.command.code][data].xmit_bytes; diff --git a/src/devices/machine/corvushd.h b/src/devices/machine/corvushd.h index 01af8f2bd52..13a86a40378 100644 --- a/src/devices/machine/corvushd.h +++ b/src/devices/machine/corvushd.h @@ -37,14 +37,15 @@ 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(process_timeout); + TIMER_CALLBACK_MEMBER(complete_function); private: static constexpr unsigned MAX_COMMAND_SIZE = 4096; // The maximum size of a command packet (the controller only has 5K of RAM...) enum { - TIMER_TIMEOUT, TIMER_COMMAND }; @@ -56,18 +57,22 @@ private: }; uint8_t m_status; // Controller status byte (DIRECTION + BUSY/READY) + // Prep mode bool m_prep_mode; // Whether the controller is in Prep Mode or not uint8_t m_prep_drv; // If in prep mode, Corvus drive id (1..15) being prepped + // Physical drive info uint8_t m_sectors_per_track; // Number of sectors per track for this drive uint8_t m_tracks_per_cylinder;// Number of tracks per cylinder (heads) uint16_t m_cylinders_per_drive;// Number of cylinders per drive + // Command Processing uint16_t m_offset; // Current offset into raw_data buffer bool m_awaiting_modifier; // We've received a two-byte command and we're waiting for the mod uint16_t m_recv_bytes; // Number of bytes expected to be received from Host uint16_t m_xmit_bytes; // Number of bytes expected to be transmitted to host + // Timing-related values uint16_t m_last_cylinder; // Last cylinder accessed - for calculating seek times uint32_t m_delay; // Delay in microseconds for callback diff --git a/src/devices/machine/cr511b.cpp b/src/devices/machine/cr511b.cpp index 9199ca5389e..9eb07578de0 100644 --- a/src/devices/machine/cr511b.cpp +++ b/src/devices/machine/cr511b.cpp @@ -50,7 +50,6 @@ cr511b_device::cr511b_device(const machine_config &mconfig, const char *tag, dev m_dten_handler(*this), m_scor_handler(*this), m_xaen_handler(*this), - m_frame_timer(nullptr), //m_motor(false), m_enabled(-1), m_cmd(-1) @@ -70,9 +69,6 @@ void cr511b_device::device_start() m_dten_handler.resolve_safe(); m_scor_handler.resolve_safe(); m_xaen_handler.resolve_safe(); - - m_frame_timer = timer_alloc(0); - m_frame_timer->adjust(attotime::never); } //------------------------------------------------- @@ -83,15 +79,6 @@ void cr511b_device::device_reset() { } -//------------------------------------------------- -// device_timer - device-specific timer events -//------------------------------------------------- - -void cr511b_device::device_timer(emu_timer &timer, device_timer_id tid, int param) -{ -} - - //************************************************************************** // IMPLEMENTATION //************************************************************************** diff --git a/src/devices/machine/cr511b.h b/src/devices/machine/cr511b.h index a2e4d7d1858..aae738145fd 100644 --- a/src/devices/machine/cr511b.h +++ b/src/devices/machine/cr511b.h @@ -63,7 +63,6 @@ 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: enum @@ -88,8 +87,6 @@ private: devcb_write_line m_scor_handler; devcb_write_line m_xaen_handler; - emu_timer *m_frame_timer; - //bool m_motor; // state of lines diff --git a/src/devices/machine/cxd1185.cpp b/src/devices/machine/cxd1185.cpp index 02602aeb527..9417def1ff8 100644 --- a/src/devices/machine/cxd1185.cpp +++ b/src/devices/machine/cxd1185.cpp @@ -100,7 +100,7 @@ void cxd1185_device::device_start() save_item(NAME(m_scsi_ctrl)); save_item(NAME(m_ioport)); - m_state_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(cxd1185_device::state_timer), this)); + m_state_timer = timer_alloc(FUNC(cxd1185_device::state_timer), this); m_state = IDLE; m_irq_asserted = false; diff --git a/src/devices/machine/diablo_hd.cpp b/src/devices/machine/diablo_hd.cpp index c963d582989..2ce1707058c 100644 --- a/src/devices/machine/diablo_hd.cpp +++ b/src/devices/machine/diablo_hd.cpp @@ -1316,7 +1316,7 @@ void diablo_hd_device::device_start() m_packs = 1; // FIXME: get from configuration? m_unit = strstr(m_image->tag(), "diablo0") ? 0 : 1; - m_timer = timer_alloc(1); + m_timer = timer_alloc(FUNC(diablo_hd_device::sector_mark_tick), this); } void diablo_hd_device::device_reset() @@ -1386,7 +1386,7 @@ void diablo_hd_device::device_reset() return; // for units with a CHD assigned to them start the timer m_bits = std::make_unique<std::unique_ptr<uint32_t[]>[]>(m_pages); - timer_set(m_sector_time - m_sector_mark_0_time, 1, 0); + m_timer->adjust(m_sector_time - m_sector_mark_0_time); read_sector(); } @@ -1401,9 +1401,9 @@ void diablo_hd_device::device_reset() * @param id timer id * @param arg argument supplied to timer_insert (unused) */ -void diablo_hd_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(diablo_hd_device::sector_mark_tick) { - LOG_DRIVE(9,"[DHD%u] TIMER id=%d param=%d @%.0fns\n", m_unit, id, param, timer.elapsed().as_double() * ATTOSECONDS_PER_NANOSECOND); + LOG_DRIVE(9, "[DHD%u] TIMER param=%d @%.0fns\n", m_unit, param, m_timer->elapsed().as_double() * ATTOSECONDS_PER_NANOSECOND); if (!m_disk) return; @@ -1412,20 +1412,20 @@ void diablo_hd_device::device_timer(emu_timer &timer, device_timer_id id, int pa // assert sector mark sector_mark_0(); // next sector timer event is in the middle between sector_mark going 0 and back to 1 - timer.adjust(m_sector_mark_0_time, 1); + m_timer->adjust(m_sector_mark_0_time, 1); break; case 1: /* call the sector_callback, if any */ if (m_sector_callback) (void)(*m_sector_callback)(m_sector_callback_cookie, m_unit); // next sector timer event is deassert of sector_mark_0 (set to 1) - timer.adjust(m_sector_mark_1_time, 2); + m_timer->adjust(m_sector_mark_1_time, 2); break; case 2: // deassert sector mark sector_mark_1(); // next sector timer event is sector_mark_0 for next sector - timer.adjust(m_sector_time - m_sector_mark_0_time, 0); + m_timer->adjust(m_sector_time - m_sector_mark_0_time, 0); break; } } diff --git a/src/devices/machine/diablo_hd.h b/src/devices/machine/diablo_hd.h index eec79c648ba..43524706967 100644 --- a/src/devices/machine/diablo_hd.h +++ b/src/devices/machine/diablo_hd.h @@ -67,9 +67,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(sector_mark_tick); + private: template <typename Format, typename... Params> void logprintf(int level, Format &&fmt, Params &&... args); diff --git a/src/devices/machine/dp83932c.cpp b/src/devices/machine/dp83932c.cpp index cadef10e602..efe877ca4d2 100644 --- a/src/devices/machine/dp83932c.cpp +++ b/src/devices/machine/dp83932c.cpp @@ -82,7 +82,7 @@ void dp83932c_device::device_start() { m_out_int.resolve(); - m_command = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(dp83932c_device::command), this)); + m_command = timer_alloc(FUNC(dp83932c_device::command), this); save_item(NAME(m_int_state)); save_item(NAME(m_reg)); diff --git a/src/devices/machine/dp8573.cpp b/src/devices/machine/dp8573.cpp index 86682d1c7a3..f862bec4deb 100644 --- a/src/devices/machine/dp8573.cpp +++ b/src/devices/machine/dp8573.cpp @@ -35,7 +35,7 @@ void dp8573_device::device_start() save_item(NAME(m_pfr)); save_item(NAME(m_millis)); - m_timer = timer_alloc(TIMER_ID); + m_timer = timer_alloc(FUNC(dp8573_device::msec_tick), this); m_timer->adjust(attotime::never); m_intr_cb.resolve_safe(); @@ -79,7 +79,7 @@ void dp8573_device::save_registers() m_ram[REG_SAVE_MONTH] = m_ram[REG_MONTH]; } -void dp8573_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(dp8573_device::msec_tick) { if ((m_pfr & PFR_OSF) || !(m_ram[REG_RTMR] & RTMR_CSS)) { diff --git a/src/devices/machine/dp8573.h b/src/devices/machine/dp8573.h index 6a184ae8c6b..1730884e1b4 100644 --- a/src/devices/machine/dp8573.h +++ b/src/devices/machine/dp8573.h @@ -31,7 +31,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_nvram_interface overrides virtual void nvram_default() override; @@ -43,7 +42,7 @@ protected: void set_interrupt(uint8_t mask); void clear_interrupt(uint8_t mask); - static const device_timer_id TIMER_ID = 0; + TIMER_CALLBACK_MEMBER(msec_tick); enum { diff --git a/src/devices/machine/ds1302.cpp b/src/devices/machine/ds1302.cpp index 7bc8689f3a2..8d32c3fd3ff 100644 --- a/src/devices/machine/ds1302.cpp +++ b/src/devices/machine/ds1302.cpp @@ -101,7 +101,7 @@ ds1202_device::ds1202_device(const machine_config &mconfig, const char *tag, dev void ds1302_device::device_start() { // allocate timers - m_clock_timer = timer_alloc(); + m_clock_timer = timer_alloc(FUNC(ds1302_device::clock_tick), this); m_clock_timer->adjust(attotime::from_hz(clock() / 32768), 0, attotime::from_hz(clock() / 32768)); m_clk = 0; @@ -129,10 +129,10 @@ void ds1302_device::device_start() //------------------------------------------------- -// device_timer - handler timer events +// clock_tick - advance the clock if enabled //------------------------------------------------- -void ds1302_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(ds1302_device::clock_tick) { if (!CLOCK_HALT) { diff --git a/src/devices/machine/ds1302.h b/src/devices/machine/ds1302.h index ea0a0d4e809..9b1d09e9840 100644 --- a/src/devices/machine/ds1302.h +++ b/src/devices/machine/ds1302.h @@ -46,7 +46,6 @@ protected: // device-level overrides virtual void device_start() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; // device_nvram_interface overrides virtual void nvram_default() override; @@ -58,6 +57,8 @@ protected: virtual bool rtc_feature_leap_year() const override { return true; } private: + TIMER_CALLBACK_MEMBER(clock_tick); + void load_shift_register(); void input_bit(); void output_bit(); diff --git a/src/devices/machine/ds1386.cpp b/src/devices/machine/ds1386.cpp index e9455585242..6f91625bde4 100644 --- a/src/devices/machine/ds1386.cpp +++ b/src/devices/machine/ds1386.cpp @@ -12,20 +12,6 @@ #include "ds1386.h" #include "machine/timehelp.h" -#define DISABLE_OSC (0x80) -#define DISABLE_SQW (0x40) - -#define COMMAND_TE (0x80) -#define COMMAND_IPSW (0x40) -#define COMMAND_IBH_LO (0x20) -#define COMMAND_PU_LVL (0x10) -#define COMMAND_WAM (0x08) -#define COMMAND_TDM (0x04) -#define COMMAND_WAF (0x02) -#define COMMAND_TDF (0x01) - -#define HOURS_12_24 (0x40) -#define HOURS_AM_PM (0x20) DEFINE_DEVICE_TYPE(DS1286, ds1286_device, "ds1286", "DS1286 Watchdog Timekeeper") DEFINE_DEVICE_TYPE(DS1386_8K, ds1386_8k_device, "ds1386_8k", "DS1386-8K RAMified Watchdog Timekeeper") @@ -77,48 +63,30 @@ ds1386_32k_device::ds1386_32k_device(const machine_config &mconfig, const char * { } -void ds1386_device::safe_inta_cb(int state) -{ - if (!m_inta_cb.isnull()) - m_inta_cb(state); -} - -void ds1386_device::safe_intb_cb(int state) -{ - if (!m_intb_cb.isnull()) - m_intb_cb(state); -} - -void ds1386_device::safe_sqw_cb(int state) -{ - if (!m_sqw_cb.isnull()) - m_sqw_cb(state); -} - void ds1386_device::device_start() { - m_inta_cb.resolve(); - m_intb_cb.resolve(); - m_sqw_cb.resolve(); + m_inta_cb.resolve_safe(); + m_intb_cb.resolve_safe(); + m_sqw_cb.resolve_safe(); m_tod_alarm = 0; m_watchdog_alarm = 0; m_square = 1; - safe_inta_cb(0); - safe_intb_cb(0); - safe_sqw_cb(1); + m_inta_cb(0); + m_intb_cb(0); + m_sqw_cb(1); // allocate timers - m_clock_timer = timer_alloc(CLOCK_TIMER); + m_clock_timer = timer_alloc(FUNC(ds1386_device::advance_hundredths), this); m_clock_timer->adjust(attotime::from_hz(100), 0, attotime::from_hz(100)); - m_square_timer = timer_alloc(SQUAREWAVE_TIMER); + m_square_timer = timer_alloc(FUNC(ds1386_device::square_tick), this); m_square_timer->adjust(attotime::never); - m_watchdog_timer = timer_alloc(WATCHDOG_TIMER); + m_watchdog_timer = timer_alloc(FUNC(ds1386_device::watchdog_tick), this); m_watchdog_timer->adjust(attotime::never); - m_inta_timer= timer_alloc(INTA_TIMER); + m_inta_timer = timer_alloc(FUNC(ds1386_device::inta_timer_elapsed), this); m_inta_timer->adjust(attotime::never); - m_intb_timer= timer_alloc(INTB_TIMER); + m_intb_timer = timer_alloc(FUNC(ds1386_device::intb_timer_elapsed), this); m_intb_timer->adjust(attotime::never); // state saving @@ -160,7 +128,7 @@ void ds1386_device::time_of_day_alarm() if (m_ram[REGISTER_COMMAND] & COMMAND_IPSW) { - safe_inta_cb(m_tod_alarm); + m_inta_cb(m_tod_alarm); if (m_ram[REGISTER_COMMAND] & COMMAND_PU_LVL) { m_inta_timer->adjust(attotime::from_msec(3)); @@ -168,7 +136,7 @@ void ds1386_device::time_of_day_alarm() } else { - safe_intb_cb(m_tod_alarm); + m_intb_cb(m_tod_alarm); if (m_ram[REGISTER_COMMAND] & COMMAND_PU_LVL) { m_intb_timer->adjust(attotime::from_msec(3)); @@ -183,7 +151,7 @@ void ds1386_device::watchdog_alarm() if (m_ram[REGISTER_COMMAND] & COMMAND_IPSW) { - safe_intb_cb(m_watchdog_alarm); + m_intb_cb(m_watchdog_alarm); if (m_ram[REGISTER_COMMAND] & COMMAND_PU_LVL) { m_intb_timer->adjust(attotime::from_msec(3)); @@ -191,7 +159,7 @@ void ds1386_device::watchdog_alarm() } else { - safe_inta_cb(m_watchdog_alarm); + m_inta_cb(m_watchdog_alarm); if (m_ram[REGISTER_COMMAND] & COMMAND_PU_LVL) { m_inta_timer->adjust(attotime::from_msec(3)); @@ -199,51 +167,37 @@ void ds1386_device::watchdog_alarm() } } -void ds1386_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(ds1386_device::square_tick) { - switch (id) - { - case CLOCK_TIMER: - advance_hundredths(); - break; - - case SQUAREWAVE_TIMER: - m_square = ((m_square == 0) ? 1 : 0); - safe_sqw_cb(m_square); - break; - - case WATCHDOG_TIMER: - if ((m_ram[REGISTER_COMMAND] & COMMAND_WAF) == 0) - watchdog_alarm(); - break; - - case INTA_TIMER: - if (m_ram[REGISTER_COMMAND] & COMMAND_IPSW) - { - m_tod_alarm = 0; - } - else - { - m_watchdog_alarm = 0; - } - safe_inta_cb(0); - break; + m_square = 1 - m_square; + m_sqw_cb(m_square); +} - case INTB_TIMER: - if (m_ram[REGISTER_COMMAND] & COMMAND_IPSW) - { - m_watchdog_alarm = 0; - } - else - { - m_tod_alarm = 0; - } - safe_intb_cb(0); - break; - } +TIMER_CALLBACK_MEMBER(ds1386_device::watchdog_tick) +{ + if ((m_ram[REGISTER_COMMAND] & COMMAND_WAF) == 0) + watchdog_alarm(); } -void ds1386_device::advance_hundredths() +TIMER_CALLBACK_MEMBER(ds1386_device::inta_timer_elapsed) +{ + if (m_ram[REGISTER_COMMAND] & COMMAND_IPSW) + m_tod_alarm = 0; + else + m_watchdog_alarm = 0; + m_inta_cb(0); +} + +TIMER_CALLBACK_MEMBER(ds1386_device::intb_timer_elapsed) +{ + if (m_ram[REGISTER_COMMAND] & COMMAND_IPSW) + m_watchdog_alarm = 0; + else + m_tod_alarm = 0; + m_intb_cb(0); +} + +TIMER_CALLBACK_MEMBER(ds1386_device::advance_hundredths) { if ((m_ram[REGISTER_COMMAND] & COMMAND_TE) != 0) { @@ -378,9 +332,6 @@ void ds1386_device::check_tod_alarm() bool zeroes = (m_hundredths == 0 && m_seconds == 0); if (zeroes && (m_ram[REGISTER_COMMAND] & COMMAND_TDF) == 0) { - bool minutes_match = (m_minutes & 0x7f) == (m_minutes_alarm & 0x7f); - bool hours_match = (m_hours & 0x7f) == (m_hours_alarm & 0x7f); - bool days_match = (m_days & 0x7) == (m_days_alarm & 0x07); bool alarm_match = false; switch (mode) { @@ -388,13 +339,13 @@ void ds1386_device::check_tod_alarm() alarm_match = true; break; case ALARM_MINUTES_MATCH: - alarm_match = minutes_match; + alarm_match = (m_minutes & 0x7f) == (m_minutes_alarm & 0x7f); break; case ALARM_HOURS_MATCH: - alarm_match = hours_match; + alarm_match = (m_hours & 0x7f) == (m_hours_alarm & 0x7f); break; case ALARM_DAYS_MATCH: - alarm_match = days_match; + alarm_match = (m_days & 0x7) == (m_days_alarm & 0x07); break; default: break; @@ -439,7 +390,7 @@ void ds1386_device::data_w(offs_t offset, uint8_t data) { case 0x00: // hundredths case 0x03: // minutes alarm - case 0x05: // horus alarm + case 0x05: // hours alarm case 0x0a: // years m_ram[offset] = data; break; @@ -470,24 +421,16 @@ void ds1386_device::data_w(offs_t offset, uint8_t data) if (changed & DISABLE_SQW) { if (m_ram[offset] & DISABLE_SQW) - { m_square_timer->adjust(attotime::never); - } else - { m_square_timer->adjust(attotime::from_hz(2048)); - } } if (changed & DISABLE_OSC) { if (m_ram[offset] & DISABLE_OSC) - { m_clock_timer->adjust(attotime::never); - } else - { m_clock_timer->adjust(attotime::from_hz(100)); - } } break; } @@ -500,9 +443,9 @@ void ds1386_device::data_w(offs_t offset, uint8_t data) m_ram[REGISTER_COMMAND] &= ~COMMAND_WAF; m_watchdog_alarm = 0; if (m_ram[REGISTER_COMMAND] & COMMAND_IPSW) - safe_intb_cb(0); + m_intb_cb(0); else - safe_inta_cb(0); + m_inta_cb(0); } m_ram[offset] = data; uint8_t wd_hundredths = m_ram[REGISTER_WATCHDOG_HUNDREDTHS]; @@ -532,16 +475,16 @@ void ds1386_device::data_w(offs_t offset, uint8_t data) if (a_changed) { if (m_ram[offset] & COMMAND_IPSW) - safe_inta_cb(m_tod_alarm); + m_inta_cb(m_tod_alarm); else - safe_inta_cb(m_watchdog_alarm); + m_inta_cb(m_watchdog_alarm); } if (b_changed) { if (m_ram[offset] & COMMAND_IPSW) - safe_intb_cb(m_watchdog_alarm); + m_intb_cb(m_watchdog_alarm); else - safe_intb_cb(m_tod_alarm); + m_intb_cb(m_tod_alarm); } } if (changed & COMMAND_WAM) @@ -549,16 +492,16 @@ void ds1386_device::data_w(offs_t offset, uint8_t data) if (m_ram[offset] & COMMAND_WAF) { if (m_ram[offset] & COMMAND_IPSW) - safe_intb_cb(0); + m_intb_cb(0); else - safe_inta_cb(0); + m_inta_cb(0); } else if (m_watchdog_alarm) { if (m_ram[offset] & COMMAND_IPSW) - safe_intb_cb(m_watchdog_alarm); + m_intb_cb(m_watchdog_alarm); else - safe_inta_cb(m_watchdog_alarm); + m_inta_cb(m_watchdog_alarm); } } if (changed & COMMAND_TDM) @@ -566,16 +509,16 @@ void ds1386_device::data_w(offs_t offset, uint8_t data) if (m_ram[offset] & COMMAND_TDF) { if (m_ram[offset] & COMMAND_IPSW) - safe_inta_cb(0); + m_inta_cb(0); else - safe_intb_cb(0); + m_intb_cb(0); } else if (m_tod_alarm) { if (m_ram[offset] & COMMAND_IPSW) - safe_inta_cb(m_tod_alarm); + m_inta_cb(m_tod_alarm); else - safe_intb_cb(m_tod_alarm); + m_intb_cb(m_tod_alarm); } } break; diff --git a/src/devices/machine/ds1386.h b/src/devices/machine/ds1386.h index 4029fe558b0..dd07c49c79f 100644 --- a/src/devices/machine/ds1386.h +++ b/src/devices/machine/ds1386.h @@ -125,7 +125,6 @@ protected: // device-level overrides virtual void device_start() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; // device_nvram_interface overrides virtual void nvram_default() override; @@ -137,13 +136,32 @@ protected: virtual bool rtc_feature_leap_year() const override { return true; } virtual void rtc_clock_updated(int year, int month, int day, int day_of_week, int hour, int minute, int second) override; - static constexpr device_timer_id CLOCK_TIMER = 0; - static constexpr device_timer_id SQUAREWAVE_TIMER = 1; - static constexpr device_timer_id WATCHDOG_TIMER = 2; - static constexpr device_timer_id INTA_TIMER = 3; - static constexpr device_timer_id INTB_TIMER = 4; - protected: + enum + { + DISABLE_OSC = 0x80, + DISABLE_SQW = 0x40, + + COMMAND_TE = 0x80, + COMMAND_IPSW = 0x40, + COMMAND_IBH_LO = 0x20, + COMMAND_PU_LVL = 0x10, + COMMAND_WAM = 0x08, + COMMAND_TDM = 0x04, + COMMAND_WAF = 0x02, + COMMAND_TDF = 0x01, + + HOURS_12_24 = 0x40, + HOURS_AM_PM = 0x20 + }; + + + TIMER_CALLBACK_MEMBER(advance_hundredths); + TIMER_CALLBACK_MEMBER(square_tick); + TIMER_CALLBACK_MEMBER(watchdog_tick); + TIMER_CALLBACK_MEMBER(inta_timer_elapsed); + TIMER_CALLBACK_MEMBER(intb_timer_elapsed); + void safe_inta_cb(int state); void safe_intb_cb(int state); void safe_sqw_cb(int state); @@ -154,8 +172,6 @@ protected: void time_of_day_alarm(); void watchdog_alarm(); - void advance_hundredths(); - void copy_ram_to_registers(); void copy_registers_to_ram(); diff --git a/src/devices/machine/ds1994.cpp b/src/devices/machine/ds1994.cpp index d6dacf90815..cff5a921c05 100644 --- a/src/devices/machine/ds1994.cpp +++ b/src/devices/machine/ds1994.cpp @@ -10,27 +10,23 @@ */ // FIXME: convert to device_rtc_interface and remove time.h -// FIXME: convert logging to use logmacro.h #include "emu.h" #include "machine/ds1994.h" #include <ctime> -#define VERBOSE_LEVEL 0 +#define LOG_ERRORS (1U << 1) +#define LOG_1WIRE (1U << 2) +#define LOG_ROM_COMMANDS (1U << 3) +#define LOG_COMMANDS (1U << 4) +#define LOG_STATES (1U << 5) +#define LOG_RESETS (1U << 6) +#define LOG_WRITES (1U << 7) +#define LOG_READS (1U << 8) -inline void ds1994_device::verboselog(int n_level, const char *s_fmt, ...) -{ - if (VERBOSE_LEVEL >= n_level) - { - va_list v; - char buf[32768]; - va_start(v, s_fmt); - vsprintf(buf, s_fmt, v); - va_end(v); - logerror("ds1994 %s: %s", machine().describe_context(), buf); - } -} +#define VERBOSE (0) +#include "logmacro.h" // device type definition DEFINE_DEVICE_TYPE(DS1994, ds1994_device, "ds1994", "DS1994 iButton 4Kb Memory Plus Time") @@ -115,9 +111,9 @@ void ds1994_device::device_start() elem = STATE_IDLE; // timers - m_timer_main = timer_alloc(TIMER_MAIN); - m_timer_reset = timer_alloc(TIMER_RESET); - m_timer_clock = timer_alloc(TIMER_CLOCK); + m_timer_main = timer_alloc(FUNC(ds1994_device::main_tick), this); + m_timer_reset = timer_alloc(FUNC(ds1994_device::reset_tick), this); + m_timer_clock = timer_alloc(FUNC(ds1994_device::clock_tick), this); m_timer_clock->adjust(attotime::from_hz(256), 0, attotime::from_hz(256)); } @@ -144,11 +140,11 @@ void ds1994_device::device_reset() memcpy(m_regs, region->base() + ROM_SIZE + SPD_SIZE + DATA_SIZE + RTC_SIZE, REGS_SIZE); return; } - verboselog(0, "ds1994 %s: Wrong region length for data, expected 0x%x, got 0x%x\n", tag(), ROM_SIZE + SPD_SIZE + DATA_SIZE + RTC_SIZE + REGS_SIZE, region->bytes()); + LOGMASKED(LOG_ERRORS, "ds1994 %s: Wrong region length for data, expected 0x%x, got 0x%x\n", tag(), ROM_SIZE + SPD_SIZE + DATA_SIZE + RTC_SIZE + REGS_SIZE, region->bytes()); } else { - verboselog(0, "ds1994 %s: Warning, no id provided, answer will be all zeroes.\n", tag()); + LOGMASKED(LOG_ERRORS, "ds1994 %s: Warning, no id provided, answer will be all zeroes.\n", tag()); memset(m_rom, 0, ROM_SIZE); memset(m_ram, 0, SPD_SIZE); memset(m_sram, 0, DATA_SIZE); @@ -168,11 +164,11 @@ bool ds1994_device::one_wire_tx_bit(uint8_t value) if (!m_bit) { m_shift = value; - verboselog(1, "one_wire_tx_bit: Byte to send %02x\n", m_shift); + LOGMASKED(LOG_1WIRE, "one_wire_tx_bit: Byte to send %02x\n", m_shift); } m_tx = m_shift & 1; m_shift >>= 1; - verboselog(1, "one_wire_tx_bit: State %d\n", m_tx); + LOGMASKED(LOG_1WIRE, "one_wire_tx_bit: State %d\n", m_tx); m_bit++; if (m_bit == 8) return true; else @@ -186,11 +182,11 @@ bool ds1994_device::one_wire_rx_bit(void) { m_shift |= 0x80; } - verboselog(1, "one_wire_rx_bit: State %d\n", m_rx); + LOGMASKED(LOG_1WIRE, "one_wire_rx_bit: State %d\n", m_rx); m_bit++; if (m_bit == 8) { - verboselog(1, "one_wire_rx_bit: Byte Received %02x\n", m_shift); + LOGMASKED(LOG_1WIRE, "one_wire_rx_bit: Byte Received %02x\n", m_shift); return true; } else @@ -203,29 +199,29 @@ bool ds1994_device::one_wire_rx_bit(void) /* */ /********************************************/ -void ds1994_device::ds1994_rom_cmd(void) +void ds1994_device::handle_rom_cmd(void) { - verboselog(2, "timer_main state_rom_command\n"); + LOGMASKED(LOG_ROM_COMMANDS, "rom_cmd\n"); if (one_wire_rx_bit()) { switch (m_shift) { case ROMCMD_READROM: - verboselog(1, "timer_main rom_cmd readrom\n"); + LOGMASKED(LOG_ROM_COMMANDS, "rom_cmd readrom\n"); m_bit = 0; m_byte = 0; m_state[0] = STATE_READROM; m_state_ptr = 0; break; case ROMCMD_SKIPROM: - verboselog(1, "timer_main rom_cmd skiprom\n"); + LOGMASKED(LOG_ROM_COMMANDS, "rom_cmd skiprom\n"); m_bit = 0; m_byte = 0; m_state[0] = STATE_COMMAND; m_state_ptr = 0; break; case ROMCMD_MATCHROM: - verboselog(1, "timer_main rom_cmd matchrom\n"); + LOGMASKED(LOG_ROM_COMMANDS, "rom_cmd matchrom\n"); m_bit = 0; m_byte = 0; m_state[0] = STATE_MATCHROM; @@ -233,11 +229,11 @@ void ds1994_device::ds1994_rom_cmd(void) break; case ROMCMD_SEARCHROM: case ROMCMD_SEARCHINT: - verboselog(0, "timer_main rom_command not implemented %02x\n", m_shift); + LOGMASKED(LOG_ERRORS, "rom_command not implemented %02x\n", m_shift); m_state[m_state_ptr] = STATE_COMMAND; break; default: - verboselog(0, "timer_main rom_command not found %02x\n", m_shift); + LOGMASKED(LOG_ERRORS, "rom_command not found %02x\n", m_shift); m_state[m_state_ptr] = STATE_IDLE; break; } @@ -250,15 +246,15 @@ void ds1994_device::ds1994_rom_cmd(void) /* */ /********************************************/ -void ds1994_device::ds1994_cmd(void) +void ds1994_device::handle_cmd(void) { - verboselog(2, "timer_main state_command\n"); + LOGMASKED(LOG_COMMANDS, "state_command\n"); if (one_wire_rx_bit()) { switch (m_shift) { case COMMAND_READ_MEMORY: - verboselog(1, "timer_main cmd read_memory\n"); + LOGMASKED(LOG_COMMANDS, "cmd read_memory\n"); m_bit = 0; m_byte = 0; m_state[0] = STATE_ADDRESS1; @@ -268,7 +264,7 @@ void ds1994_device::ds1994_cmd(void) m_state_ptr = 0; break; case COMMAND_WRITE_SCRATCHPAD: - verboselog(1, "timer_main cmd write_scratchpad\n"); + LOGMASKED(LOG_COMMANDS, "cmd write_scratchpad\n"); m_bit = 0; m_byte = 0; m_offs_ro = false; @@ -279,7 +275,7 @@ void ds1994_device::ds1994_cmd(void) m_state_ptr = 0; break; case COMMAND_READ_SCRATCHPAD: - verboselog(1, "timer_main cmd read_scratchpad\n"); + LOGMASKED(LOG_COMMANDS, "cmd read_scratchpad\n"); m_bit = 0; m_byte = 0; m_state[0] = STATE_TXADDRESS1; @@ -290,7 +286,7 @@ void ds1994_device::ds1994_cmd(void) m_state_ptr = 0; break; case COMMAND_COPY_SCRATCHPAD: - verboselog(1, "timer_main cmd copy_scratchpad\n"); + LOGMASKED(LOG_COMMANDS, "cmd copy_scratchpad\n"); m_bit = 0; m_byte = 0; m_offs_ro = true; @@ -303,7 +299,7 @@ void ds1994_device::ds1994_cmd(void) m_state_ptr = 0; break; default: - verboselog(0, "timer_main command not handled %02x\n", m_shift); + LOGMASKED(LOG_COMMANDS, "command not handled %02x\n", m_shift); m_state[m_state_ptr] = STATE_IDLE; break; } @@ -316,7 +312,7 @@ void ds1994_device::ds1994_cmd(void) /* */ /********************************************/ -uint8_t ds1994_device::ds1994_readmem() +uint8_t ds1994_device::readmem() { if (m_address < 0x200) { @@ -332,7 +328,7 @@ uint8_t ds1994_device::ds1994_readmem() return 0; } -void ds1994_device::ds1994_writemem(uint8_t value) +void ds1994_device::writemem(uint8_t value) { if (m_address < 0x200) { @@ -353,231 +349,232 @@ void ds1994_device::ds1994_writemem(uint8_t value) /* */ /*************************************************/ -void ds1994_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(ds1994_device::main_tick) { - switch (id) + switch (m_state[m_state_ptr]) { - case TIMER_CLOCK: - for (auto & elem : m_rtc) + case STATE_RESET1: + LOGMASKED(LOG_STATES, "timer_main state_reset1 %d\n", m_rx); + m_tx = false; + m_state[m_state_ptr] = STATE_RESET2; + m_timer_main->adjust(t_pdl); + break; + case STATE_RESET2: + LOGMASKED(LOG_STATES, "timer_main state_reset2 %d\n", m_rx); + m_tx = true; + m_bit = 0; + m_shift = 0; + m_state[m_state_ptr] = STATE_ROMCMD; + break; + case STATE_ROMCMD: + handle_rom_cmd(); + break; + case STATE_COMMAND: + handle_cmd(); + break; + case STATE_MATCHROM: + LOGMASKED(LOG_STATES, "timer_main state_matchrom - Data to match: <- %d\n", m_rx); + if (one_wire_rx_bit()) { - elem++; - if (elem != 0) + if (m_rom[7- m_byte] == m_shift) { - break; + m_byte++; + m_bit = 0; + LOGMASKED(LOG_STATES, "timer_main state_matchrom: datamatch %x - byte=%d\n", m_shift, m_byte); + } + else + { + m_state[m_state_ptr] = STATE_IDLE; + LOGMASKED(LOG_STATES, "timer_main state_matchrom: no match rx=%x <> mem=%x - byte:%d\n", m_shift, m_rom[7 - m_byte], m_byte); } } + if (m_byte == ROM_SIZE) + { + LOGMASKED(LOG_STATES, "timer_main matchrom finished\n"); + m_state[m_state_ptr] = STATE_COMMAND; + } break; - case TIMER_RESET: - verboselog(1, "timer_reset\n"); - m_state[m_state_ptr] = STATE_RESET; - m_timer_reset->adjust(attotime::never); + case STATE_ADDRESS1: + LOGMASKED(LOG_STATES, "timer_main state_address1\n"); + if (one_wire_rx_bit()) + { + m_bit = 0; + if (m_offs_ro) + { + if (m_a1 != m_shift) m_auth = false; + LOGMASKED(LOG_STATES, "timer_main state_address1 - TA1=%02x - Auth_Code 1=%02x\n", m_a1, m_shift); + } + else + { + m_a1 = m_shift & 0xff; + LOGMASKED(LOG_STATES, "timer_main state_address1 - Address1=%02x\n", m_a1); + } + m_state_ptr++; + } break; - case TIMER_MAIN: - switch (m_state[m_state_ptr]) + case STATE_ADDRESS2: + LOGMASKED(LOG_STATES, "timer_main state_address2\n"); + if (one_wire_rx_bit()) { - case STATE_RESET1: - verboselog(2, "timer_main state_reset1 %d\n", m_rx); - m_tx = false; - m_state[m_state_ptr] = STATE_RESET2; - m_timer_main->adjust(t_pdl); - break; - case STATE_RESET2: - verboselog(2, "timer_main state_reset2 %d\n", m_rx); - m_tx = true; - m_bit = 0; - m_shift = 0; - m_state[m_state_ptr] = STATE_ROMCMD; - break; - case STATE_ROMCMD: - ds1994_rom_cmd(); - break; - case STATE_COMMAND: - ds1994_cmd(); - break; - case STATE_MATCHROM: - verboselog(2, "timer_main state_matchrom - Data to match: <- %d\n", m_rx); - if (one_wire_rx_bit()) - { - if (m_rom[7- m_byte] == m_shift) - { - m_byte++; - m_bit = 0; - verboselog(2, "timer_main state_matchrom: datamatch %x - byte=%d\n", m_shift, m_byte); - } - else - { - m_state[m_state_ptr] = STATE_IDLE; - verboselog(1, "timer_main state_matchrom: no match rx=%x <> mem=%x - byte:%d\n", m_shift, m_rom[7 - m_byte], m_byte); - } - } - if (m_byte == ROM_SIZE) - { - verboselog(2, "timer_main matchrom finished\n"); - m_state[m_state_ptr] = STATE_COMMAND; - } - break; - case STATE_ADDRESS1: - verboselog(2, "timer_main state_address1\n"); - if (one_wire_rx_bit()) - { - m_bit = 0; - if (m_offs_ro) - { - if (m_a1 != m_shift) m_auth = false; - verboselog(1, "timer_main state_address1 - TA1=%02x - Auth_Code 1=%02x\n", m_a1, m_shift); - } - else - { - m_a1 = m_shift & 0xff; - verboselog(2, "timer_main state_address1 - Address1=%02x\n", m_a1); - } - m_state_ptr++; - } - break; - case STATE_ADDRESS2: - verboselog(2, "timer_main state_address2\n"); - if (one_wire_rx_bit()) - { - m_bit = 0; - if (m_offs_ro) - { - if ( m_a2 != m_shift ) - m_auth = false; - verboselog(1, "timer_main state_address1 - TA2=%02x - Auth_Code 2=%02x\n", m_a1, m_shift); - } - else - { - m_a2 = m_shift & 0xff; - verboselog(2, "timer_main state_address2 - Address2=%02x\n", m_a2); - } - m_state_ptr++; - } - break; - case STATE_OFFSET: - verboselog(2, "timer_main state_offset\n"); - if (one_wire_rx_bit()) - { - m_bit = 0; - if (m_offs_ro) - { - if (m_a2 != m_shift) - m_auth = false; - verboselog(1, "timer_main state_address1 - OFS_ES=%02x - Auth_Code 3=%02x\n", m_offset, m_shift); - } - else - { - m_offset = m_shift & 0x1f; - verboselog(2, "timer_main state_address2 - Offset=%02x\n", m_offset); - } - m_state_ptr++; - } - break; - case STATE_WRITE_SCRATCHPAD: - verboselog(2, "timer_main state_write_scratchpad\n"); - if (one_wire_rx_bit()) - { - m_bit = 0; - m_ram[m_offset & 0x1f] = m_shift & 0xff; - m_offset++; - } - verboselog(2, "timer_main state_write_scratchpad %d Offs=%02x\n", m_rx, m_offset); - break; - case STATE_READROM: - m_tx = true; - if (m_byte == ROM_SIZE) - { - verboselog(1, "timer_main readrom finished\n"); - m_state[m_state_ptr] = STATE_COMMAND; - } - else - verboselog(2, "timer_main readrom window closed\n"); - break; - case STATE_TXADDRESS1: - m_tx = true; - if (m_byte == 1) - { - verboselog(1, "timer_main txaddress1 finished m_byte=%d\n", m_byte); - m_byte = 0; - m_state_ptr++; - } - else - verboselog(2, "timer_main txaddress1 window closed\n"); - break; - case STATE_TXADDRESS2: - m_tx = true; - if (m_byte == 1) - { - verboselog(1, "timer_main txaddress2 finished m_byte=%d\n", m_byte); - m_byte = 0; - m_state_ptr++; - } - else - verboselog(2, "timer_main txaddress2 window closed\n"); - break; - case STATE_TXOFFSET: - m_tx = true; - if (m_byte == 1) - { - verboselog(1, "timer_main txoffset finished - m_byte=%d\n", m_byte); - m_byte = 0; - m_state_ptr++; - } - else - verboselog(2, "timer_main txoffset window closed\n"); - break; - case STATE_READ_MEMORY: - verboselog(2, "timer_main state_readmemory\n"); - break; - case STATE_COPY_SCRATCHPAD: - verboselog(2, "timer_main state_copy_scratchpad\n"); - break; - case STATE_READ_SCRATCHPAD: - verboselog(2, "timer_main state_read_scratchpad\n"); - break; - default: - verboselog(0, "timer_main state not handled: %d\n", m_state[m_state_ptr]); - break; + m_bit = 0; + if (m_offs_ro) + { + if ( m_a2 != m_shift ) + m_auth = false; + LOGMASKED(LOG_STATES, "timer_main state_address1 - TA2=%02x - Auth_Code 2=%02x\n", m_a1, m_shift); + } + else + { + m_a2 = m_shift & 0xff; + LOGMASKED(LOG_STATES, "timer_main state_address2 - Address2=%02x\n", m_a2); + } + m_state_ptr++; } - if (m_state[m_state_ptr] == STATE_INIT_COMMAND) + break; + case STATE_OFFSET: + LOGMASKED(LOG_STATES, "timer_main state_offset\n"); + if (one_wire_rx_bit()) { - switch (m_state[m_state_ptr + 1]) + m_bit = 0; + if (m_offs_ro) + { + if (m_a2 != m_shift) + m_auth = false; + LOGMASKED(LOG_STATES, "timer_main state_address1 - OFS_ES=%02x - Auth_Code 3=%02x\n", m_offset, m_shift); + } + else { - case STATE_IDLE: - case STATE_COMMAND: - case STATE_ADDRESS1: - case STATE_ADDRESS2: - case STATE_OFFSET: - break; - case STATE_READ_MEMORY: - verboselog(2, "timer_main (init_cmd) -> state_read_memory - set address\n"); - m_address = (m_a2 << 8) | m_a1; - break; - case STATE_WRITE_SCRATCHPAD: - verboselog(2, "timer_main (init_cmd) -> state_write_scratchpad - set address\n"); - m_offs_ro = false; - m_offset = 0; - break; - case STATE_READ_SCRATCHPAD: - verboselog(2, "timer_main (init_cmd) -> state_read_scratchpad - set address\n"); - m_address = 0; - break; - case STATE_COPY_SCRATCHPAD: - verboselog(2, "timer_main (init_cmd) -> state_copy_scratchpad - do copy\n"); - if (m_auth) - { - m_address = (m_a2 << 8) | m_a1; - for (int i = 0; i <= m_offset; i++) - { - ds1994_writemem(m_ram[i]); - m_address++; - } - } - else - verboselog(1, "timer_main (init_cmd) -> state_copy_scratchpad - Auth-Rejected\n"); - break; + m_offset = m_shift & 0x1f; + LOGMASKED(LOG_STATES, "timer_main state_address2 - Offset=%02x\n", m_offset); } m_state_ptr++; } + break; + case STATE_WRITE_SCRATCHPAD: + LOGMASKED(LOG_STATES, "timer_main state_write_scratchpad\n"); + if (one_wire_rx_bit()) + { + m_bit = 0; + m_ram[m_offset & 0x1f] = m_shift & 0xff; + m_offset++; + } + LOGMASKED(LOG_STATES, "timer_main state_write_scratchpad %d Offs=%02x\n", m_rx, m_offset); + break; + case STATE_READROM: + m_tx = true; + if (m_byte == ROM_SIZE) + { + LOGMASKED(LOG_STATES, "timer_main readrom finished\n"); + m_state[m_state_ptr] = STATE_COMMAND; + } + else + LOGMASKED(LOG_STATES, "timer_main readrom window closed\n"); + break; + case STATE_TXADDRESS1: + m_tx = true; + if (m_byte == 1) + { + LOGMASKED(LOG_STATES, "timer_main txaddress1 finished m_byte=%d\n", m_byte); + m_byte = 0; + m_state_ptr++; + } + else + LOGMASKED(LOG_STATES, "timer_main txaddress1 window closed\n"); + break; + case STATE_TXADDRESS2: + m_tx = true; + if (m_byte == 1) + { + LOGMASKED(LOG_STATES, "timer_main txaddress2 finished m_byte=%d\n", m_byte); + m_byte = 0; + m_state_ptr++; + } + else + LOGMASKED(LOG_STATES, "timer_main txaddress2 window closed\n"); + break; + case STATE_TXOFFSET: + m_tx = true; + if (m_byte == 1) + { + LOGMASKED(LOG_STATES, "timer_main txoffset finished - m_byte=%d\n", m_byte); + m_byte = 0; + m_state_ptr++; + } + else + LOGMASKED(LOG_STATES, "timer_main txoffset window closed\n"); + break; + case STATE_READ_MEMORY: + LOGMASKED(LOG_STATES, "timer_main state_readmemory\n"); + break; + case STATE_COPY_SCRATCHPAD: + LOGMASKED(LOG_STATES, "timer_main state_copy_scratchpad\n"); + break; + case STATE_READ_SCRATCHPAD: + LOGMASKED(LOG_STATES, "timer_main state_read_scratchpad\n"); + break; + default: + LOGMASKED(LOG_ERRORS, "timer_main state not handled: %d\n", m_state[m_state_ptr]); + break; + } + + if (m_state[m_state_ptr] == STATE_INIT_COMMAND) + { + switch (m_state[m_state_ptr + 1]) + { + case STATE_IDLE: + case STATE_COMMAND: + case STATE_ADDRESS1: + case STATE_ADDRESS2: + case STATE_OFFSET: + break; + case STATE_READ_MEMORY: + LOGMASKED(LOG_STATES, "timer_main (init_cmd) -> state_read_memory - set address\n"); + m_address = (m_a2 << 8) | m_a1; + break; + case STATE_WRITE_SCRATCHPAD: + LOGMASKED(LOG_STATES, "timer_main (init_cmd) -> state_write_scratchpad - set address\n"); + m_offs_ro = false; + m_offset = 0; + break; + case STATE_READ_SCRATCHPAD: + LOGMASKED(LOG_STATES, "timer_main (init_cmd) -> state_read_scratchpad - set address\n"); + m_address = 0; + break; + case STATE_COPY_SCRATCHPAD: + LOGMASKED(LOG_STATES, "timer_main (init_cmd) -> state_copy_scratchpad - do copy\n"); + if (m_auth) + { + m_address = (m_a2 << 8) | m_a1; + for (int i = 0; i <= m_offset; i++) + { + writemem(m_ram[i]); + m_address++; + } + } + else + LOGMASKED(LOG_STATES, "timer_main (init_cmd) -> state_copy_scratchpad - Auth-Rejected\n"); + break; + } + m_state_ptr++; + } +} + +TIMER_CALLBACK_MEMBER(ds1994_device::reset_tick) +{ + LOGMASKED(LOG_RESETS, "timer_reset\n"); + m_state[m_state_ptr] = STATE_RESET; + m_timer_reset->adjust(attotime::never); +} + +TIMER_CALLBACK_MEMBER(ds1994_device::clock_tick) +{ + for (uint8_t &elem : m_rtc) + { + elem++; + if (elem != 0) + { + break; + } } } @@ -589,7 +586,7 @@ void ds1994_device::device_timer(emu_timer &timer, device_timer_id id, int param WRITE_LINE_MEMBER(ds1994_device::write) { - verboselog(1, "write(%d)\n", state); + LOGMASKED(LOG_WRITES, "write(%d)\n", state); if (!state && m_rx) { switch (m_state[m_state_ptr]) @@ -598,27 +595,27 @@ WRITE_LINE_MEMBER(ds1994_device::write) case STATE_INIT_COMMAND: break; case STATE_ROMCMD: - verboselog(2, "state_romcommand\n"); + LOGMASKED(LOG_WRITES, "state_romcommand\n"); m_timer_main->adjust(t_samp); break; case STATE_COMMAND: - verboselog(2, "state_command\n"); + LOGMASKED(LOG_WRITES, "state_command\n"); m_timer_main->adjust(t_samp); break; case STATE_ADDRESS1: - verboselog(2, "state_address1\n"); + LOGMASKED(LOG_WRITES, "state_address1\n"); m_timer_main->adjust(t_samp); break; case STATE_ADDRESS2: - verboselog(2, "state_address2\n"); + LOGMASKED(LOG_WRITES, "state_address2\n"); m_timer_main->adjust(t_samp); break; case STATE_OFFSET: - verboselog(2, "state_offset\n"); + LOGMASKED(LOG_WRITES, "state_offset\n"); m_timer_main->adjust(t_samp); break; case STATE_TXADDRESS1: - verboselog(2, "state_txaddress1\n"); + LOGMASKED(LOG_WRITES, "state_txaddress1\n"); if (one_wire_tx_bit(m_a1)) { m_bit = 0; @@ -627,7 +624,7 @@ WRITE_LINE_MEMBER(ds1994_device::write) m_timer_main->adjust(t_rdv); break; case STATE_TXADDRESS2: - verboselog(2, "state_txaddress2\n"); + LOGMASKED(LOG_WRITES, "state_txaddress2\n"); if (one_wire_tx_bit(m_a2)) { m_bit = 0; @@ -636,7 +633,7 @@ WRITE_LINE_MEMBER(ds1994_device::write) m_timer_main->adjust(t_rdv); break; case STATE_TXOFFSET: - verboselog(2, "state_txoffset\n"); + LOGMASKED(LOG_WRITES, "state_txoffset\n"); if (one_wire_tx_bit(m_offset)) { m_bit = 0; @@ -645,7 +642,7 @@ WRITE_LINE_MEMBER(ds1994_device::write) m_timer_main->adjust(t_rdv); break; case STATE_READROM: - verboselog(2, "state_readrom\n"); + LOGMASKED(LOG_WRITES, "state_readrom\n"); if (one_wire_tx_bit(m_rom[7 - m_byte])) { m_bit = 0; @@ -654,8 +651,8 @@ WRITE_LINE_MEMBER(ds1994_device::write) m_timer_main->adjust(t_rdv); break; case STATE_READ_MEMORY: - verboselog(2, "state_read_memory\n"); - if (one_wire_tx_bit(ds1994_readmem())) + LOGMASKED(LOG_WRITES, "state_read_memory\n"); + if (one_wire_tx_bit(readmem())) { m_bit = 0; if (m_address < DATA_SIZE + RTC_SIZE + REGS_SIZE) @@ -666,29 +663,29 @@ WRITE_LINE_MEMBER(ds1994_device::write) m_timer_main->adjust(t_rdv); break; case STATE_MATCHROM: - verboselog(2, "state_matchrom\n"); + LOGMASKED(LOG_WRITES, "state_matchrom\n"); m_timer_main->adjust(t_rdv); break; case STATE_COPY_SCRATCHPAD: if (m_auth) { - verboselog(2, "state_copy_scratchpad Auth_Code Match: %d\n", m_tx); + LOGMASKED(LOG_WRITES, "state_copy_scratchpad Auth_Code Match: %d\n", m_tx); m_tx = true; m_auth = false; } else { m_tx = false; - verboselog(1, "state_copy_scratchpad Auth_Code No Match: %d\n", m_tx); + LOGMASKED(LOG_WRITES, "state_copy_scratchpad Auth_Code No Match: %d\n", m_tx); } m_timer_main->adjust(t_rdv); break; case STATE_WRITE_SCRATCHPAD: - verboselog(2, "state_write_scratchpad\n"); + LOGMASKED(LOG_WRITES, "state_write_scratchpad\n"); m_timer_main->adjust(t_samp); break; case STATE_READ_SCRATCHPAD: - verboselog(2, "state_read_scratchpad\n"); + LOGMASKED(LOG_WRITES, "state_read_scratchpad\n"); if (one_wire_tx_bit(m_ram[m_address])) { m_bit = 0; @@ -700,7 +697,7 @@ WRITE_LINE_MEMBER(ds1994_device::write) m_timer_main->adjust(t_rdv); break; default: - verboselog(0, "state not handled: %d\n", m_state[m_state_ptr]); + LOGMASKED(LOG_ERRORS | LOG_WRITES, "state not handled: %d\n", m_state[m_state_ptr]); break; } m_timer_reset->adjust(t_rstl); @@ -728,7 +725,7 @@ WRITE_LINE_MEMBER(ds1994_device::write) READ_LINE_MEMBER(ds1994_device::read) { - verboselog(2, "read %d\n", m_tx && m_rx); + LOGMASKED(LOG_READS, "read %d\n", m_tx && m_rx); return m_tx && m_rx; } diff --git a/src/devices/machine/ds1994.h b/src/devices/machine/ds1994.h index df5c5216e30..c6629b6fbb9 100644 --- a/src/devices/machine/ds1994.h +++ b/src/devices/machine/ds1994.h @@ -37,7 +37,6 @@ class ds1994_device : public device_t, public device_nvram_interface // 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_nvram_interface overrides virtual void nvram_default() override; @@ -65,12 +64,6 @@ class ds1994_device : public device_t, public device_nvram_interface }; enum { - TIMER_MAIN, - TIMER_RESET, - TIMER_CLOCK - }; - - enum { STATE_IDLE, STATE_RESET, STATE_RESET1, @@ -93,14 +86,20 @@ class ds1994_device : public device_t, public device_nvram_interface STATE_COPY_SCRATCHPAD }; - void ds1994_rom_cmd(void); - void ds1994_cmd(void); + void handle_rom_cmd(void); + void handle_cmd(void); bool one_wire_tx_bit(uint8_t value); bool one_wire_rx_bit(void); - uint8_t ds1994_readmem(); - void ds1994_writemem(uint8_t value); + uint8_t readmem(); + void writemem(uint8_t value); - emu_timer *m_timer_main, *m_timer_reset, *m_timer_clock; + TIMER_CALLBACK_MEMBER(main_tick); + TIMER_CALLBACK_MEMBER(reset_tick); + TIMER_CALLBACK_MEMBER(clock_tick); + + emu_timer *m_timer_main; + emu_timer *m_timer_reset; + emu_timer *m_timer_clock; uint32_t m_ref_year; uint8_t m_ref_month; @@ -124,8 +123,6 @@ class ds1994_device : public device_t, public device_nvram_interface bool m_offs_ro; attotime t_samp, t_rdv, t_rstl, t_pdh, t_pdl; - - inline void verboselog(int n_level, const char *s_fmt, ...) ATTR_PRINTF(3, 4); }; // device type definition diff --git a/src/devices/machine/ds2401.cpp b/src/devices/machine/ds2401.cpp index 4da3b923bbe..3ceabcb66f2 100644 --- a/src/devices/machine/ds2401.cpp +++ b/src/devices/machine/ds2401.cpp @@ -60,8 +60,8 @@ void ds2401_device::device_start() save_item(NAME(m_rx)); save_item(NAME(m_tx)); - m_timer_main = timer_alloc(TIMER_MAIN); - m_timer_reset = timer_alloc(TIMER_RESET); + m_timer_main = timer_alloc(FUNC(ds2401_device::main_tick), this); + m_timer_reset = timer_alloc(FUNC(ds2401_device::reset_tick), this); } void ds2401_device::device_reset() @@ -92,81 +92,78 @@ void ds2401_device::device_reset() memset(m_data, 0, SIZE_DATA); } -void ds2401_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(ds2401_device::reset_tick) { - switch(id) + verboselog(1, "timer_reset\n"); + m_state = STATE_RESET; + m_timer_reset->adjust(attotime::never); +} + +TIMER_CALLBACK_MEMBER(ds2401_device::main_tick) +{ + switch(m_state) { - case TIMER_RESET: - verboselog(1, "timer_reset\n"); - m_state = STATE_RESET; - m_timer_reset->adjust(attotime::never); + case STATE_RESET1: + verboselog(2, "timer_main state_reset1 %d\n", m_rx); + m_tx = false; + m_state = STATE_RESET2; + m_timer_main->adjust(t_pdl); break; - case TIMER_MAIN: - switch(m_state) - { - case STATE_RESET1: - verboselog(2, "timer_main state_reset1 %d\n", m_rx); - m_tx = false; - m_state = STATE_RESET2; - m_timer_main->adjust(t_pdl); - break; + case STATE_RESET2: + verboselog(2, "timer_main state_reset2 %d\n", m_rx); + m_tx = true; + m_bit = 0; + m_shift = 0; + m_state = STATE_COMMAND; + break; - case STATE_RESET2: - verboselog(2, "timer_main state_reset2 %d\n", m_rx); - m_tx = true; - m_bit = 0; - m_shift = 0; - m_state = STATE_COMMAND; - break; + case STATE_COMMAND: + verboselog(2, "timer_main state_command %d\n", m_rx); - case STATE_COMMAND: - verboselog(2, "timer_main state_command %d\n", m_rx); + m_shift >>= 1; + if(m_rx) + { + m_shift |= 0x80; + } - m_shift >>= 1; - if(m_rx) + m_bit++; + if(m_bit == 8) + { + switch(m_shift) { - m_shift |= 0x80; - } + case COMMAND_READROM: + case COMMAND_READROM_COMPAT: + verboselog(1, "timer_main readrom\n"); + m_bit = 0; + m_byte = 0; + m_state = STATE_READROM; + break; - m_bit++; - if(m_bit == 8) - { - switch(m_shift) - { - case COMMAND_READROM: - case COMMAND_READROM_COMPAT: - verboselog(1, "timer_main readrom\n"); - m_bit = 0; - m_byte = 0; - m_state = STATE_READROM; - break; - - default: - verboselog(0, "timer_main command not handled %02x\n", m_shift); - m_state = STATE_IDLE; - break; - } + default: + verboselog(0, "timer_main command not handled %02x\n", m_shift); + m_state = STATE_IDLE; + break; } - break; + } + break; - case STATE_READROM: - m_tx = true; + case STATE_READROM: + m_tx = true; - if( m_byte == SIZE_DATA ) - { - verboselog(1, "timer_main readrom finished\n"); - m_state = STATE_IDLE; - } - else - { - verboselog(2, "timer_main readrom window closed\n"); - } - break; - default: - verboselog(0, "timer_main state not handled: %d\n", m_state); - break; + if( m_byte == SIZE_DATA ) + { + verboselog(1, "timer_main readrom finished\n"); + m_state = STATE_IDLE; } + else + { + verboselog(2, "timer_main readrom window closed\n"); + } + break; + default: + verboselog(0, "timer_main state not handled: %d\n", m_state); + break; } } diff --git a/src/devices/machine/ds2401.h b/src/devices/machine/ds2401.h index a78b7471a03..f29132d381e 100644 --- a/src/devices/machine/ds2401.h +++ b/src/devices/machine/ds2401.h @@ -45,15 +45,12 @@ protected: STATE_READROM }; - enum { - TIMER_MAIN, - TIMER_RESET - }; - // 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(reset_tick); + TIMER_CALLBACK_MEMBER(main_tick); // internal state int m_state, m_bit, m_shift; diff --git a/src/devices/machine/ds2404.cpp b/src/devices/machine/ds2404.cpp index 6a279d80986..68845d86dc3 100644 --- a/src/devices/machine/ds2404.cpp +++ b/src/devices/machine/ds2404.cpp @@ -73,7 +73,7 @@ void ds2404_device::device_start() for (auto & elem : m_state) elem = STATE_IDLE; - m_tick_timer = timer_alloc(0); + m_tick_timer = timer_alloc(FUNC(ds2404_device::timer_tick), this); m_tick_timer->adjust(attotime::from_hz(256), 0, attotime::from_hz(256)); } @@ -317,22 +317,13 @@ void ds2404_device::clk_w(uint8_t data) } } -void ds2404_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(ds2404_device::timer_tick) { - switch(id) + for(uint8_t &elem : m_rtc) { - case 0: - // tick - for(auto &elem : m_rtc) - { - elem++; - if(elem != 0) - break; - } + elem++; + if(elem != 0) break; - - default: - throw emu_fatalerror("Unknown id in ds2404_device::device_timer"); } } diff --git a/src/devices/machine/ds2404.h b/src/devices/machine/ds2404.h index 4301c2a050f..1ed22887b87 100644 --- a/src/devices/machine/ds2404.h +++ b/src/devices/machine/ds2404.h @@ -46,7 +46,7 @@ protected: virtual bool nvram_read(util::read_stream &file) override; virtual bool nvram_write(util::write_stream &file) override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; + TIMER_CALLBACK_MEMBER(timer_tick); private: void rom_cmd(uint8_t cmd); diff --git a/src/devices/machine/e0516.cpp b/src/devices/machine/e0516.cpp index baa2751cb91..29fe42e3f17 100644 --- a/src/devices/machine/e0516.cpp +++ b/src/devices/machine/e0516.cpp @@ -54,7 +54,7 @@ e0516_device::e0516_device(const machine_config &mconfig, const char *tag, devic void e0516_device::device_start() { // allocate timers - m_timer = timer_alloc(); + m_timer = timer_alloc(FUNC(e0516_device::timer_tick), this); m_timer->adjust(attotime::from_hz(clock() / 32768), 0, attotime::from_hz(clock() / 32768)); // state saving @@ -70,10 +70,11 @@ void e0516_device::device_start() //------------------------------------------------- -// device_timer - handler timer events +// timer_tick - call into dirtc at 1Hz to +// increment the seconds counter //------------------------------------------------- -void e0516_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(e0516_device::timer_tick) { advance_seconds(); } diff --git a/src/devices/machine/e0516.h b/src/devices/machine/e0516.h index 8246974130d..d3807ff5968 100644 --- a/src/devices/machine/e0516.h +++ b/src/devices/machine/e0516.h @@ -38,11 +38,12 @@ 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_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; + TIMER_CALLBACK_MEMBER(timer_tick); + private: int m_cs; // chip select int m_clk; // clock diff --git a/src/devices/machine/edlc.cpp b/src/devices/machine/edlc.cpp index 480b0520c03..956528aa8b7 100644 --- a/src/devices/machine/edlc.cpp +++ b/src/devices/machine/edlc.cpp @@ -67,8 +67,8 @@ void seeq8003_device::device_start() //save_item(NAME(m_rx_fifo)); //save_item(NAME(m_tx_fifo)); - m_tx_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(seeq8003_device::transmit), this)); - m_int_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(seeq8003_device::interrupt), this)); + m_tx_timer = timer_alloc(FUNC(seeq8003_device::transmit), this); + m_int_timer = timer_alloc(FUNC(seeq8003_device::interrupt), this); m_int_state = 0; m_reset_state = 1; diff --git a/src/devices/machine/er1400.cpp b/src/devices/machine/er1400.cpp index 79ec1bc7d6e..695f22ac27a 100644 --- a/src/devices/machine/er1400.cpp +++ b/src/devices/machine/er1400.cpp @@ -75,7 +75,7 @@ void er1400_device::device_start() m_data_array = std::make_unique<u16[]>(100); save_pointer(NAME(m_data_array), 100); - m_data_propagation_timer = timer_alloc(PROPAGATION_TIMER); + m_data_propagation_timer = timer_alloc(FUNC(er1400_device::propagate_data), this); } @@ -297,24 +297,18 @@ WRITE_LINE_MEMBER(er1400_device::c3_w) //------------------------------------------------- -// device_timer - called whenever a device timer -// fires +// propagate_data - clock data out from the chip //------------------------------------------------- -void er1400_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(er1400_device::propagate_data) { - switch (id) + if (m_code_input == 5) { - case PROPAGATION_TIMER: - if (m_code_input == 5) - { - m_data_output = BIT(m_data_register, 13); - LOG("Data output %d bit\n", m_data_output); - } - else - m_data_output = false; - break; + m_data_output = BIT(m_data_register, 13); + LOG("Data output %d bit\n", m_data_output); } + else + m_data_output = false; } diff --git a/src/devices/machine/er1400.h b/src/devices/machine/er1400.h index f8c6edb5614..9988edd6744 100644 --- a/src/devices/machine/er1400.h +++ b/src/devices/machine/er1400.h @@ -45,13 +45,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; // device_nvram_interface overrides virtual void nvram_default() override; virtual bool nvram_read(util::read_stream &file) override; virtual bool nvram_write(util::write_stream &file) override; + TIMER_CALLBACK_MEMBER(propagate_data); + private: enum { diff --git a/src/devices/machine/exorterm.cpp b/src/devices/machine/exorterm.cpp index 7edb65e875b..17e0f98a662 100644 --- a/src/devices/machine/exorterm.cpp +++ b/src/devices/machine/exorterm.cpp @@ -755,8 +755,8 @@ void exorterm155_device::device_start() save_item(NAME(m_kbd_start_holdoff)); // Keyboard - m_kbd_scan_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(exorterm155_device::kbd_scan_row), this)); - m_kbd_repeat_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(exorterm155_device::kbd_repeat), this)); + m_kbd_scan_timer = timer_alloc(FUNC(exorterm155_device::kbd_scan_row), this); + m_kbd_repeat_timer = timer_alloc(FUNC(exorterm155_device::kbd_repeat), this); kbd_reset_state(); kbd_repeat_stop(); diff --git a/src/devices/machine/exorterm.h b/src/devices/machine/exorterm.h index 784fdd83e6b..07944bff805 100644 --- a/src/devices/machine/exorterm.h +++ b/src/devices/machine/exorterm.h @@ -128,7 +128,6 @@ private: void kbd_repeat_start(u8 row, u8 column); void kbd_repeat_restart(); void kbd_repeat_stop(); - void kbd_repeat(); void kbd_send_translated(u8 code); TIMER_CALLBACK_MEMBER(kbd_scan_row); diff --git a/src/devices/machine/f3853.cpp b/src/devices/machine/f3853.cpp index 4f7b6ff798b..dbea3f30533 100644 --- a/src/devices/machine/f3853.cpp +++ b/src/devices/machine/f3853.cpp @@ -113,7 +113,7 @@ void f3853_device::device_start() reg = reg << 1 | (BIT(reg,7) ^ BIT(reg,5) ^ BIT(reg,4) ^ BIT(reg,3) ^ 1); } - m_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(f3853_device::timer_callback),this)); + m_timer = timer_alloc(FUNC(f3853_device::timer_callback), this); // zerofill (what's not in constructor) m_external_int_enable = false; diff --git a/src/devices/machine/fga002.cpp b/src/devices/machine/fga002.cpp index 3aa117736ec..14ed175fb9e 100644 --- a/src/devices/machine/fga002.cpp +++ b/src/devices/machine/fga002.cpp @@ -104,7 +104,7 @@ void fga002_device::device_start() m_liack7_cb.resolve_safe(0); // Timers - fga_timer = timer_alloc(TIMER_ID_FGA); + fga_timer = timer_alloc(FUNC(fga002_device::timer_tick), this); save_pointer (NAME (m_fga002), sizeof(m_fga002)); @@ -143,31 +143,24 @@ void fga002_device::device_reset() } //------------------------------------------------- -// device_timer - handler timer events +// timer_tick - decrement timer 0 //------------------------------------------------- -void fga002_device::device_timer (emu_timer &timer, device_timer_id id, int param) + +TIMER_CALLBACK_MEMBER(fga002_device::timer_tick) { - switch(id) + if (m_tim0count-- == 0) // Zero detect { - case TIMER_ID_FGA: - if (m_tim0count-- == 0) // Zero detect + if ((m_fga002[FGA_TIM0CTL] & REG_TIM0CTL_ZERO_STOP) == 0) { - if ((m_fga002[FGA_TIM0CTL] & REG_TIM0CTL_ZERO_STOP) == 0) - { - fga_timer->adjust(attotime::never, TIMER_ID_FGA, attotime::never); - } + fga_timer->adjust(attotime::never); + } + else + { + if ((m_fga002[FGA_TIM0CTL] & REG_TIM0CTL_AUTOPRELOAD) == 0) + m_tim0count &= 0xff; else - { - if ((m_fga002[FGA_TIM0CTL] & REG_TIM0CTL_AUTOPRELOAD) == 0) - m_tim0count &= 0xff; - else - m_tim0count = m_fga002[FGA_TIM0PRELOAD]; - } + m_tim0count = m_fga002[FGA_TIM0PRELOAD]; } - break; - default: - LOG("Unhandled Timer ID %d\n", id); - break; } } @@ -408,27 +401,27 @@ void fga002_device::do_fga002reg_tim0ctl_w(uint8_t data) if ((data & REG_TIM0CTL_START_STOP) != (m_fga002[FGA_TIM0CTL] & REG_TIM0CTL_START_STOP)) { if ((data & REG_TIM0CTL_START_STOP) == 0) - fga_timer->adjust(attotime::never, TIMER_ID_FGA, attotime::never); + fga_timer->adjust(attotime::never); else { switch (data & REG_TIM0CTL_CLK_MSK) { - case REG_TIM0CTL_CLK_1_MIC: fga_timer->adjust(attotime::from_usec(1), TIMER_ID_FGA, attotime::from_usec(1)); break; - case REG_TIM0CTL_CLK_2_MIC: fga_timer->adjust(attotime::from_usec(2), TIMER_ID_FGA, attotime::from_usec(2)); break; - case REG_TIM0CTL_CLK_4_MIC: fga_timer->adjust(attotime::from_usec(4), TIMER_ID_FGA, attotime::from_usec(4)); break; - case REG_TIM0CTL_CLK_8_MIC: fga_timer->adjust(attotime::from_usec(8), TIMER_ID_FGA, attotime::from_usec(8)); break; - case REG_TIM0CTL_CLK_16_MIC: fga_timer->adjust(attotime::from_usec(16), TIMER_ID_FGA, attotime::from_usec(16)); break; - case REG_TIM0CTL_CLK_32_MIC: fga_timer->adjust(attotime::from_usec(32), TIMER_ID_FGA, attotime::from_usec(32)); break; - case REG_TIM0CTL_CLK_64_MIC: fga_timer->adjust(attotime::from_usec(64), TIMER_ID_FGA, attotime::from_usec(64)); break; - case REG_TIM0CTL_CLK_128_MIC: fga_timer->adjust(attotime::from_usec(128), TIMER_ID_FGA, attotime::from_usec(128)); break; - case REG_TIM0CTL_CLK_256_MIC: fga_timer->adjust(attotime::from_usec(256), TIMER_ID_FGA, attotime::from_usec(256)); break; - case REG_TIM0CTL_CLK_512_MIC: fga_timer->adjust(attotime::from_usec(512), TIMER_ID_FGA, attotime::from_usec(512)); break; - case REG_TIM0CTL_CLK_2_MIL: fga_timer->adjust(attotime::from_msec(2), TIMER_ID_FGA, attotime::from_msec(2)); break; - case REG_TIM0CTL_CLK_8_MIL: fga_timer->adjust(attotime::from_msec(8), TIMER_ID_FGA, attotime::from_msec(8)); break; - case REG_TIM0CTL_CLK_32_MIL: fga_timer->adjust(attotime::from_msec(32), TIMER_ID_FGA, attotime::from_msec(32)); break; - case REG_TIM0CTL_CLK_125_MIL: fga_timer->adjust(attotime::from_msec(125), TIMER_ID_FGA, attotime::from_msec(125)); break; - case REG_TIM0CTL_CLK_500_MIL: fga_timer->adjust(attotime::from_msec(500), TIMER_ID_FGA, attotime::from_msec(500)); break; - case REG_TIM0CTL_CLK_2_SEC: fga_timer->adjust(attotime::from_seconds(2), TIMER_ID_FGA, attotime::from_seconds(2)); break; + case REG_TIM0CTL_CLK_1_MIC: fga_timer->adjust(attotime::from_usec(1), 0, attotime::from_usec(1)); break; + case REG_TIM0CTL_CLK_2_MIC: fga_timer->adjust(attotime::from_usec(2), 0, attotime::from_usec(2)); break; + case REG_TIM0CTL_CLK_4_MIC: fga_timer->adjust(attotime::from_usec(4), 0, attotime::from_usec(4)); break; + case REG_TIM0CTL_CLK_8_MIC: fga_timer->adjust(attotime::from_usec(8), 0, attotime::from_usec(8)); break; + case REG_TIM0CTL_CLK_16_MIC: fga_timer->adjust(attotime::from_usec(16), 0, attotime::from_usec(16)); break; + case REG_TIM0CTL_CLK_32_MIC: fga_timer->adjust(attotime::from_usec(32), 0, attotime::from_usec(32)); break; + case REG_TIM0CTL_CLK_64_MIC: fga_timer->adjust(attotime::from_usec(64), 0, attotime::from_usec(64)); break; + case REG_TIM0CTL_CLK_128_MIC: fga_timer->adjust(attotime::from_usec(128), 0, attotime::from_usec(128)); break; + case REG_TIM0CTL_CLK_256_MIC: fga_timer->adjust(attotime::from_usec(256), 0, attotime::from_usec(256)); break; + case REG_TIM0CTL_CLK_512_MIC: fga_timer->adjust(attotime::from_usec(512), 0, attotime::from_usec(512)); break; + case REG_TIM0CTL_CLK_2_MIL: fga_timer->adjust(attotime::from_msec(2), 0, attotime::from_msec(2)); break; + case REG_TIM0CTL_CLK_8_MIL: fga_timer->adjust(attotime::from_msec(8), 0, attotime::from_msec(8)); break; + case REG_TIM0CTL_CLK_32_MIL: fga_timer->adjust(attotime::from_msec(32), 0, attotime::from_msec(32)); break; + case REG_TIM0CTL_CLK_125_MIL: fga_timer->adjust(attotime::from_msec(125), 0, attotime::from_msec(125)); break; + case REG_TIM0CTL_CLK_500_MIL: fga_timer->adjust(attotime::from_msec(500), 0, attotime::from_msec(500)); break; + case REG_TIM0CTL_CLK_2_SEC: fga_timer->adjust(attotime::from_seconds(2), 0, attotime::from_seconds(2)); break; default: logerror("REG_TIM0CTL programmer error, please report\n"); break; // Should never happen } } diff --git a/src/devices/machine/fga002.h b/src/devices/machine/fga002.h index efea2f54a23..35785189421 100644 --- a/src/devices/machine/fga002.h +++ b/src/devices/machine/fga002.h @@ -57,7 +57,8 @@ class fga002_device : public device_t virtual int z80daisy_irq_ack() override; virtual void z80daisy_irq_reti() override; #endif - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; + + TIMER_CALLBACK_MEMBER(timer_tick); devcb_write_line m_out_int_cb; devcb_read8 m_liack4_cb; @@ -86,10 +87,7 @@ class fga002_device : public device_t uint8_t do_fga002reg_istim0_r(); void do_fga002reg_istim0_w(uint8_t data); emu_timer *fga_timer; - enum - { - TIMER_ID_FGA - }; + enum { REG_TIM0CTL_ZERO_STOP = 0x80, REG_TIM0CTL_AUTOPRELOAD = 0x40, diff --git a/src/devices/machine/gen_fifo.cpp b/src/devices/machine/gen_fifo.cpp index 56eba309f92..6dd2c3137d4 100644 --- a/src/devices/machine/gen_fifo.cpp +++ b/src/devices/machine/gen_fifo.cpp @@ -52,56 +52,51 @@ template<typename T> void generic_fifo_device_base<T>::device_start() m_empty_cb.resolve_safe(); m_full_cb.resolve_safe(); - m_sync_empty = timer_alloc(0); - m_sync_full = timer_alloc(1); + m_sync_empty = timer_alloc(FUNC(generic_fifo_device_base<T>::sync_empty), this); + m_sync_full = timer_alloc(FUNC(generic_fifo_device_base<T>::sync_full), this); // This is not saving the fifo, let's hope it's empty... save_item(NAME(m_empty_triggered)); save_item(NAME(m_full_triggered)); } -template<typename T> void generic_fifo_device_base<T>::device_timer(emu_timer &timer, device_timer_id id, int param) +template<typename T> TIMER_CALLBACK_MEMBER(generic_fifo_device_base<T>::sync_empty) { - switch(id) { - case T_FULL: { - // Add the extra values in if there's space - bool was_empty = is_empty(); - bool was_full = is_full(); - - while(!m_extra_values.empty() && !is_full()) { - T t(std::move(m_extra_values.front())); - m_extra_values.erase(m_extra_values.begin()); - m_values.emplace_back(std::move(t)); + // Sync was called for a fifo empty, is it still empty? + if(is_empty()) { + // If yes, stop the destination if not done yet + if(!m_empty_triggered) { + m_empty_triggered = true; + m_on_fifo_empty_post_sync(); } + } +} - // Adjust devcb lines as needed - if(was_empty && !is_empty()) - m_empty_cb(false); - if(!was_full && is_full()) - m_full_cb(true); +template<typename T> TIMER_CALLBACK_MEMBER(generic_fifo_device_base<T>::sync_full) +{ + // Add the extra values in if there's space + bool was_empty = is_empty(); + bool was_full = is_full(); - // Are there still values that don't fit? - if(!m_extra_values.empty()) { - // If yes, stop the source if not done yet - if(!m_full_triggered) { - m_full_triggered = true; - m_on_fifo_full_post_sync(); - } - } - break; + while(!m_extra_values.empty() && !is_full()) { + T t(std::move(m_extra_values.front())); + m_extra_values.erase(m_extra_values.begin()); + m_values.emplace_back(std::move(t)); } - case T_EMPTY: { - // Sync was called for a fifo empty, is it still empty? - if(is_empty()) { - // If yes, stop the destination if not done yet - if(!m_empty_triggered) { - m_empty_triggered = true; - m_on_fifo_empty_post_sync(); - } + // Adjust devcb lines as needed + if(was_empty && !is_empty()) + m_empty_cb(false); + if(!was_full && is_full()) + m_full_cb(true); + + // Are there still values that don't fit? + if(!m_extra_values.empty()) { + // If yes, stop the source if not done yet + if(!m_full_triggered) { + m_full_triggered = true; + m_on_fifo_full_post_sync(); } - break; - } } } diff --git a/src/devices/machine/gen_fifo.h b/src/devices/machine/gen_fifo.h index 0b9cc36244c..8e27ef73b6a 100644 --- a/src/devices/machine/gen_fifo.h +++ b/src/devices/machine/gen_fifo.h @@ -197,7 +197,9 @@ private: bool m_empty_triggered, m_full_triggered; virtual void device_start() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; + + TIMER_CALLBACK_MEMBER(sync_empty); + TIMER_CALLBACK_MEMBER(sync_full); }; class generic_fifo_u32_device : public generic_fifo_device_base<u32> diff --git a/src/devices/machine/generalplus_gpl16250soc.cpp b/src/devices/machine/generalplus_gpl16250soc.cpp index 2c2f7062d91..7718c586d43 100644 --- a/src/devices/machine/generalplus_gpl16250soc.cpp +++ b/src/devices/machine/generalplus_gpl16250soc.cpp @@ -1586,7 +1586,7 @@ void sunplus_gcm394_base_device::device_start() m_nand_read_cb.resolve_safe(0); - m_unk_timer = timer_alloc(0); + m_unk_timer = timer_alloc(FUNC(sunplus_gcm394_base_device::unknown_tick), this); m_unk_timer->adjust(attotime::never); save_item(NAME(m_dma_params)); @@ -1785,20 +1785,13 @@ void sunplus_gcm394_base_device::checkirq6() */ -void sunplus_gcm394_base_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(sunplus_gcm394_base_device::unknown_tick) { - switch (id) - { - case 0: - { - m_7935 |= 0x0100; - set_state_unsynced(UNSP_IRQ6_LINE, ASSERT_LINE); - //set_state_unsynced(UNSP_IRQ4_LINE, ASSERT_LINE); + m_7935 |= 0x0100; + set_state_unsynced(UNSP_IRQ6_LINE, ASSERT_LINE); + //set_state_unsynced(UNSP_IRQ4_LINE, ASSERT_LINE); // checkirq6(); - break; - } - } } diff --git a/src/devices/machine/generalplus_gpl16250soc.h b/src/devices/machine/generalplus_gpl16250soc.h index e3dfd6aeb20..214cc7e8ace 100644 --- a/src/devices/machine/generalplus_gpl16250soc.h +++ b/src/devices/machine/generalplus_gpl16250soc.h @@ -360,7 +360,8 @@ private: void checkirq6(); emu_timer *m_unk_timer; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; + + TIMER_CALLBACK_MEMBER(unknown_tick); inline uint16_t read_space(uint32_t offset); inline void write_space(uint32_t offset, uint16_t data); diff --git a/src/devices/machine/generalplus_gpl16250soc_video.cpp b/src/devices/machine/generalplus_gpl16250soc_video.cpp index 52668a71d17..7d2b7f68385 100644 --- a/src/devices/machine/generalplus_gpl16250soc_video.cpp +++ b/src/devices/machine/generalplus_gpl16250soc_video.cpp @@ -210,7 +210,7 @@ void gcm394_base_video_device::device_start() m_space_read_cb.resolve_safe(0); - m_screenpos_timer = timer_alloc(TIMER_SCREENPOS); + m_screenpos_timer = timer_alloc(FUNC(gcm394_base_video_device::screen_pos_reached), this); m_screenpos_timer->adjust(attotime::never); save_item(NAME(m_page0_addr_lsb)); @@ -1132,27 +1132,20 @@ WRITE_LINE_MEMBER(gcm394_base_video_device::vblank) } } -void gcm394_base_video_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(gcm394_base_video_device::screen_pos_reached) { - switch (id) + if (m_video_irq_enable & 2) { - case TIMER_SCREENPOS: - { - if (m_video_irq_enable & 2) - { - m_video_irq_status |= 2; - check_video_irq(); - } + m_video_irq_status |= 2; + check_video_irq(); + } - //printf("firing irq timer\n"); + //printf("firing irq timer\n"); - m_screen->update_partial(m_screen->vpos()); + m_screen->update_partial(m_screen->vpos()); - // fire again, jak_dbz pinball needs this - m_screenpos_timer->adjust(m_screen->time_until_pos(m_yirqpos-19, m_xirqpos)); - break; - } - } + // fire again, jak_dbz pinball needs this + m_screenpos_timer->adjust(m_screen->time_until_pos(m_yirqpos-19, m_xirqpos)); } diff --git a/src/devices/machine/generalplus_gpl16250soc_video.h b/src/devices/machine/generalplus_gpl16250soc_video.h index 328525b7359..22b4275a990 100644 --- a/src/devices/machine/generalplus_gpl16250soc_video.h +++ b/src/devices/machine/generalplus_gpl16250soc_video.h @@ -140,8 +140,7 @@ public: protected: - static const device_timer_id TIMER_SCREENPOS = 2; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; + TIMER_CALLBACK_MEMBER(screen_pos_reached); inline void check_video_irq(); diff --git a/src/devices/machine/glukrs.cpp b/src/devices/machine/glukrs.cpp index 515f448dbb9..aee7348b3e0 100644 --- a/src/devices/machine/glukrs.cpp +++ b/src/devices/machine/glukrs.cpp @@ -26,7 +26,7 @@ void glukrs_device::device_start() { m_nvram->set_base(&m_cmos, sizeof(m_cmos)); - m_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(glukrs_device::timer_callback), this)); + m_timer = timer_alloc(FUNC(glukrs_device::timer_callback), this); m_timer->adjust(attotime::from_hz(clock() / XTAL(32'768)), 0, attotime::from_hz(clock() / XTAL(32'768))); } diff --git a/src/devices/machine/gt64xxx.cpp b/src/devices/machine/gt64xxx.cpp index 4c698e12809..ea16a9b0573 100644 --- a/src/devices/machine/gt64xxx.cpp +++ b/src/devices/machine/gt64xxx.cpp @@ -208,7 +208,7 @@ void gt64xxx_device::device_start() status = 0x0; // DMA timer - m_dma_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(gt64xxx_device::perform_dma), this)); + m_dma_timer = timer_alloc(FUNC(gt64xxx_device::perform_dma), this); // Leave the timer disabled. m_dma_timer->adjust(attotime::never, 0, DMA_TIMER_PERIOD); @@ -231,10 +231,10 @@ void gt64xxx_device::device_start() } // allocate timers for the galileo - m_timer[0].timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(gt64xxx_device::timer_callback), this)); - m_timer[1].timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(gt64xxx_device::timer_callback), this)); - m_timer[2].timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(gt64xxx_device::timer_callback), this)); - m_timer[3].timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(gt64xxx_device::timer_callback), this)); + m_timer[0].timer = timer_alloc(FUNC(gt64xxx_device::timer_callback), this); + m_timer[1].timer = timer_alloc(FUNC(gt64xxx_device::timer_callback), this); + m_timer[2].timer = timer_alloc(FUNC(gt64xxx_device::timer_callback), this); + m_timer[3].timer = timer_alloc(FUNC(gt64xxx_device::timer_callback), this); // Save states save_item(NAME(m_irq_pending)); diff --git a/src/devices/machine/gt913_io.cpp b/src/devices/machine/gt913_io.cpp index 2853a50ec98..d1b091fa308 100644 --- a/src/devices/machine/gt913_io.cpp +++ b/src/devices/machine/gt913_io.cpp @@ -32,8 +32,8 @@ void gt913_io_hle_device::device_start() m_cpu_io = &m_cpu->space(AS_IO); m_intc = siblingdevice<h8_intc_device>(m_intc_tag); - m_timer[0] = timer_alloc(0); - m_timer[1] = timer_alloc(1); + m_timer[0] = timer_alloc(FUNC(gt913_io_hle_device::irq_timer_tick), this); + m_timer[1] = timer_alloc(FUNC(gt913_io_hle_device::irq_timer_tick), this); save_item(NAME(m_timer_control)); save_item(NAME(m_timer_rate)); @@ -54,10 +54,10 @@ void gt913_io_hle_device::device_reset() m_adc_data[0] = m_adc_data[1] = 0; } -void gt913_io_hle_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(gt913_io_hle_device::irq_timer_tick) { - m_timer_irq_pending[id] = true; - timer_check_irq(id); + m_timer_irq_pending[param] = true; + timer_check_irq((offs_t)param); } void gt913_io_hle_device::timer_control_w(offs_t offset, uint8_t data) @@ -65,7 +65,7 @@ void gt913_io_hle_device::timer_control_w(offs_t offset, uint8_t data) assert(offset < 2); // TODO: ctk551 clears and sets bit 4 during the respective timer's IRQ, what should this do? pause/restart the timer? m_timer_control[offset] = data; - timer_check_irq(offset); + timer_check_irq((int)offset); } uint8_t gt913_io_hle_device::timer_control_r(offs_t offset) @@ -106,15 +106,16 @@ void gt913_io_hle_device::timer_adjust(offs_t num) { default: logerror("unknown timer %u prescaler %u (pc = %04x)\n", num, m_timer_control[num] & 0x7, m_cpu->pc()); - [[fallthrough]]; + break; case 0: break; case 2: - clocks <<= 9; break; + clocks <<= 9; + break; } attotime period = m_cpu->clocks_to_attotime(clocks); - m_timer[num]->adjust(period, 0, period); + m_timer[num]->adjust(period, (int)num, period); } } diff --git a/src/devices/machine/gt913_io.h b/src/devices/machine/gt913_io.h index 5bfed441c64..335c7b2719f 100644 --- a/src/devices/machine/gt913_io.h +++ b/src/devices/machine/gt913_io.h @@ -47,7 +47,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(irq_timer_tick); private: required_device<cpu_device> m_cpu; diff --git a/src/devices/machine/hd63450.cpp b/src/devices/machine/hd63450.cpp index 9d8226c3f9e..5006729badf 100644 --- a/src/devices/machine/hd63450.cpp +++ b/src/devices/machine/hd63450.cpp @@ -50,7 +50,7 @@ void hd63450_device::device_start() // Initialise timers and registers for (int x = 0; x < 4; x++) - m_timer[x] = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(hd63450_device::dma_transfer_timer), this)); + m_timer[x] = timer_alloc(FUNC(hd63450_device::dma_transfer_timer), this); save_item(STRUCT_MEMBER(m_reg, csr)); save_item(STRUCT_MEMBER(m_reg, cer)); diff --git a/src/devices/machine/hd64610.cpp b/src/devices/machine/hd64610.cpp index 5090e162b41..2a2c3064705 100644 --- a/src/devices/machine/hd64610.cpp +++ b/src/devices/machine/hd64610.cpp @@ -175,7 +175,7 @@ void hd64610_device::device_start() m_out_1hz_cb.resolve_safe(); // allocate timers - m_counter_timer = timer_alloc(TIMER_UPDATE_COUNTER); + m_counter_timer = timer_alloc(FUNC(hd64610_device::update_counter), this); m_counter_timer->adjust(attotime::from_hz(clock() / 256), 0, attotime::from_hz(clock() / 256)); // state saving @@ -186,37 +186,32 @@ void hd64610_device::device_start() //------------------------------------------------- -// device_timer - handler timer events +// update_counter - update our count registers //------------------------------------------------- -void hd64610_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(hd64610_device::update_counter) { - switch (id) + if(m_hline_state || (m_regs[REG_CRB] & CRB_S)) { - case TIMER_UPDATE_COUNTER: - if(m_hline_state || (m_regs[REG_CRB] & CRB_S)) - { - m_regs[REG_64HZ]++; + m_regs[REG_64HZ]++; - if (m_regs[REG_64HZ] & 0x80) - { - // update seconds - advance_seconds(); + if (m_regs[REG_64HZ] & 0x80) + { + // update seconds + advance_seconds(); - // set carry flag - m_regs[REG_CRA] |= CRA_CF; + // set carry flag + m_regs[REG_CRA] |= CRA_CF; - m_regs[REG_64HZ] &= 0x7f; - } + m_regs[REG_64HZ] &= 0x7f; + } - // update 1Hz out - m_out_1hz_cb(BIT(m_regs[REG_64HZ], 6)); + // update 1Hz out + m_out_1hz_cb(BIT(m_regs[REG_64HZ], 6)); - // update IRQ - check_alarm(); - set_irq_line(); - } - break; + // update IRQ + check_alarm(); + set_irq_line(); } } diff --git a/src/devices/machine/hd64610.h b/src/devices/machine/hd64610.h index ebbb1356042..9dda6ed03e5 100644 --- a/src/devices/machine/hd64610.h +++ b/src/devices/machine/hd64610.h @@ -48,7 +48,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_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; @@ -58,14 +57,14 @@ protected: virtual bool nvram_read(util::read_stream &file) override; virtual bool nvram_write(util::write_stream &file) override; + TIMER_CALLBACK_MEMBER(update_counter); + private: void set_irq_line(); uint8_t read_counter(int counter); void write_counter(int counter, uint8_t value); void check_alarm(); - static const device_timer_id TIMER_UPDATE_COUNTER = 0; - devcb_write_line m_out_irq_cb; devcb_write_line m_out_1hz_cb; diff --git a/src/devices/machine/hdc92x4.cpp b/src/devices/machine/hdc92x4.cpp index 51661ef5e2d..1abdcf02abc 100644 --- a/src/devices/machine/hdc92x4.cpp +++ b/src/devices/machine/hdc92x4.cpp @@ -294,15 +294,6 @@ enum }; /* - Timers -*/ -enum -{ - GEN_TIMER = 1, - COM_TIMER -}; - -/* Definition of bits in the Mode register */ enum { @@ -4764,22 +4755,22 @@ void hdc92x4_device::set_clock_divider(int line, int value) } /* - This is reached when a timer has expired + These are reached when the relevant timer has expired */ -void hdc92x4_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(hdc92x4_device::gen_timer_expired) { live_sync(); m_timed_wait = false; - switch (id) - { - case GEN_TIMER: - reenter_command_processing(); - break; - case COM_TIMER: - process_command(); - break; - } + reenter_command_processing(); +} + +TIMER_CALLBACK_MEMBER(hdc92x4_device::com_timer_expired) +{ + live_sync(); + m_timed_wait = false; + + process_command(); } /* @@ -4804,9 +4795,9 @@ void hdc92x4_device::device_start() m_in_dma.resolve_safe(0); // allocate timers - m_timer = timer_alloc(GEN_TIMER); - m_cmd_timer = timer_alloc(COM_TIMER); - // m_live_timer = timer_alloc(LIVE_TIMER); + m_timer = timer_alloc(FUNC(hdc92x4_device::gen_timer_expired), this); + m_cmd_timer = timer_alloc(FUNC(hdc92x4_device::com_timer_expired), this); + // m_live_timer = timer_alloc(FUNC(hdc92x4_device::live_timer_expired), this); m_live_state.state = IDLE; } diff --git a/src/devices/machine/hdc92x4.h b/src/devices/machine/hdc92x4.h index 733a59b2733..4527efc6c91 100644 --- a/src/devices/machine/hdc92x4.h +++ b/src/devices/machine/hdc92x4.h @@ -83,8 +83,8 @@ protected: virtual void device_start() override; virtual void device_reset() override; - // Timer callback - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; + TIMER_CALLBACK_MEMBER(gen_timer_expired); + TIMER_CALLBACK_MEMBER(com_timer_expired); private: const bool m_is_hdc9234; diff --git a/src/devices/machine/hp_dc100_tape.cpp b/src/devices/machine/hp_dc100_tape.cpp index 4e94a6d2999..2afd9d78beb 100644 --- a/src/devices/machine/hp_dc100_tape.cpp +++ b/src/devices/machine/hp_dc100_tape.cpp @@ -33,16 +33,18 @@ #include "util/ioprocsfilter.h" // Debugging -#include "logmacro.h" + #define LOG_TMR_MASK (LOG_GENERAL << 1) -#define LOG_TMR(...) LOGMASKED(LOG_TMR_MASK, __VA_ARGS__) #define LOG_DBG_MASK (LOG_TMR_MASK << 1) -#define LOG_DBG(...) LOGMASKED(LOG_DBG_MASK, __VA_ARGS__) #define LOG_RW_MASK (LOG_DBG_MASK << 1) + +#define LOG_TMR(...) LOGMASKED(LOG_TMR_MASK, __VA_ARGS__) +#define LOG_DBG(...) LOGMASKED(LOG_DBG_MASK, __VA_ARGS__) #define LOG_RW(...) LOGMASKED(LOG_RW_MASK, __VA_ARGS__) -#undef VERBOSE + //#define VERBOSE (LOG_GENERAL | LOG_TMR_MASK | LOG_DBG_MASK | LOG_RW_MASK) #define VERBOSE (LOG_GENERAL) +#include "logmacro.h" // Bit manipulation namespace { @@ -51,12 +53,12 @@ namespace { return (T)1U << n; } - template<typename T> void BIT_CLR(T& w , unsigned n) + template<typename T> void BIT_CLR(T& w, unsigned n) { w &= ~BIT_MASK<T>(n); } - template<typename T> void BIT_SET(T& w , unsigned n) + template<typename T> void BIT_SET(T& w, unsigned n) { w |= BIT_MASK<T>(n); } @@ -65,20 +67,12 @@ namespace { // Device type definition DEFINE_DEVICE_TYPE(HP_DC100_TAPE, hp_dc100_tape_device, "hp_dc100_tape", "HP DC100 tape drive") -// Timers -enum { - BIT_TMR_ID, - TACHO_TMR_ID, - HOLE_TMR_ID, - MOTION_TMR_ID -}; - // Constants constexpr double MOTION_MARGIN = 1e-5; // Margin to ensure motion events have passed when timer expires (10 µs) constexpr hti_format_t::tape_pos_t TAPE_INIT_POS = 80 * hti_format_t::ONE_INCH_POS; // Initial tape position: 80" from beginning (just past the punched part) hp_dc100_tape_device::hp_dc100_tape_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) - : microtape_image_device(mconfig , HP_DC100_TAPE , tag , owner , clock) + : microtape_image_device(mconfig, HP_DC100_TAPE, tag, owner, clock) , m_cart_out_handler(*this) , m_hole_handler(*this) , m_tacho_tick_handler(*this) @@ -103,7 +97,7 @@ image_init_result hp_dc100_tape_device::call_create(int format_type, util::optio void hp_dc100_tape_device::call_unload() { - LOG("call_unload dirty=%d\n" , m_image_dirty); + LOG("call_unload dirty=%d\n", m_image_dirty); device_reset(); @@ -152,7 +146,7 @@ std::string hp_dc100_tape_device::call_display() int pos_in = get_approx_pos() / hti_format_t::ONE_INCH_POS; - buffer += string_format("%c %c%c [%04d/1824]" , r_w , m1 , m2 , pos_in); + buffer += string_format("%c %c%c [%04d/1824]", r_w, m1, m2, pos_in); return buffer; } @@ -167,7 +161,7 @@ void hp_dc100_tape_device::set_acceleration(double accel) m_acceleration = accel; } -void hp_dc100_tape_device::set_set_points(double slow_sp , double fast_sp) +void hp_dc100_tape_device::set_set_points(double slow_sp, double fast_sp) { m_slow_set_point = slow_sp; m_fast_set_point = fast_sp; @@ -196,7 +190,7 @@ void hp_dc100_tape_device::set_name(const std::string& name) void hp_dc100_tape_device::set_track_no(unsigned track) { if (m_track != track && track < m_image.no_of_tracks()) { - LOG_DBG("Setting track %u (op=%d)\n" , track , static_cast<int>(m_current_op)); + LOG_DBG("Setting track %u (op=%d)\n", track, static_cast<int>(m_current_op)); auto saved_op = m_current_op; if (m_current_op != OP_IDLE) { // Close current op on old track @@ -210,7 +204,7 @@ void hp_dc100_tape_device::set_track_no(unsigned track) } } -bool hp_dc100_tape_device::set_speed_setpoint(tape_speed_t speed , bool fwd) +bool hp_dc100_tape_device::set_speed_setpoint(tape_speed_t speed, bool fwd) { if (!m_present) { return false; @@ -220,7 +214,7 @@ bool hp_dc100_tape_device::set_speed_setpoint(tape_speed_t speed , bool fwd) if (m_set_point != new_setpoint) { update_speed_pos(); - LOG_DBG("Speed SP changed %f->%f %.6f p=%d\n" , m_set_point , new_setpoint , machine().time().as_double() , m_tape_pos); + LOG_DBG("Speed SP changed %f->%f %.6f p=%d\n", m_set_point, new_setpoint, machine().time().as_double(), m_tape_pos); m_tape_speed = speed; m_set_point = new_setpoint; // Speed set point changed, accelerate/decelerate @@ -240,13 +234,13 @@ bool hp_dc100_tape_device::set_speed_setpoint(tape_speed_t speed , bool fwd) } } -void hp_dc100_tape_device::set_op(tape_op_t op , bool force) +void hp_dc100_tape_device::set_op(tape_op_t op, bool force) { if (!m_present || m_start_time.is_never()) { return; } if (!m_in_set_op && (op != m_current_op || force)) { - LOG_DBG("Op %d->%d (f=%d)\n" , m_current_op , op , force); + LOG_DBG("Op %d->%d (f=%d)\n", m_current_op, op, force); m_in_set_op = true; update_speed_pos(); auto prev_op = m_current_op; @@ -265,21 +259,21 @@ void hp_dc100_tape_device::set_op(tape_op_t op , bool force) LOG("Starting RD after WR?\n"); } if (fabs(m_speed) < m_slow_set_point) { - LOG("Starting RD at %f speed?\n" , m_speed); + LOG("Starting RD at %f speed?\n", m_speed); } - m_rd_it_valid = m_image.next_data(get_track_no() , m_tape_pos , is_moving_fwd() , false , m_rd_it); + m_rd_it_valid = m_image.next_data(get_track_no(), m_tape_pos, is_moving_fwd(), false, m_rd_it); load_rd_word(); m_gap_detect_start = m_tape_pos; break; case OP_WRITE: if (m_accelerating || fabs(m_speed) != m_slow_set_point) { - LOG("Starting WR at %f speed (acc=%d)?\n" , m_speed , m_accelerating); + LOG("Starting WR at %f speed (acc=%d)?\n", m_speed, m_accelerating); } if (prev_op == OP_READ) { // Switching from RD to WR // Clear out the part of m_rw_word that is going to be written - LOG_RW("Switch RD->WR @%d, idx=%d, w=%04x\n" , m_rw_pos , m_bit_idx , m_rw_word); + LOG_RW("Switch RD->WR @%d, idx=%d, w=%04x\n", m_rw_pos, m_bit_idx, m_rw_word); if (is_moving_fwd()) { if (--m_bit_idx >= 0) { m_rw_word &= 0xffffU << (m_bit_idx + 1); @@ -311,7 +305,7 @@ void hp_dc100_tape_device::set_op(tape_op_t op , bool force) break; case OP_ERASE: - LOG_DBG("Start GAP @%d\n" , m_tape_pos); + LOG_DBG("Start GAP @%d\n", m_tape_pos); m_rw_pos = m_tape_pos; break; @@ -351,11 +345,11 @@ void hp_dc100_tape_device::update_speed_pos() double acceleration = m_set_point > m_speed ? m_acceleration : -m_acceleration; bool retrigger_motion = false; if (delta_time_double < time_to_const_v) { - space_const_a = const_a_space(acceleration , delta_time_double); + space_const_a = const_a_space(acceleration, delta_time_double); m_speed += delta_time_double * acceleration; time_const_v = 0.0; } else { - space_const_a = const_a_space(acceleration , time_to_const_v); + space_const_a = const_a_space(acceleration, time_to_const_v); time_const_v = delta_time_double - time_to_const_v; LOG_DBG("Acceleration ends\n"); m_accelerating = false; @@ -371,13 +365,13 @@ void hp_dc100_tape_device::update_speed_pos() (fabs(prev_speed) - m_go_threshold) * (fabs(m_speed) - m_go_threshold) < 0.0) { // Slow speed threshold crossed // In-motion threshold crossed - LOG_DBG("Thr crossed %f->%f\n" , prev_speed , m_speed); + LOG_DBG("Thr crossed %f->%f\n", prev_speed, m_speed); motion_event = true; retrigger_motion = true; } if (prev_speed * m_speed < 0.0) { // Direction inverted (speed sign flipped) - LOG_DBG("Dir inverted s=%f\n" , m_speed); + LOG_DBG("Dir inverted s=%f\n", m_speed); inverted = true; retrigger_motion = true; } @@ -390,8 +384,8 @@ void hp_dc100_tape_device::update_speed_pos() } hti_format_t::tape_pos_t delta_pos = (hti_format_t::tape_pos_t)((space_const_a + m_speed * time_const_v) * hti_format_t::ONE_INCH_POS); - LOG_DBG("dp=%d\n" , delta_pos); - if (!hti_format_t::pos_offset(m_tape_pos , true , delta_pos)) { + LOG_DBG("dp=%d\n", delta_pos); + if (!hti_format_t::pos_offset(m_tape_pos, true, delta_pos)) { LOG("Tape unspooled!\n"); } @@ -418,7 +412,7 @@ hti_format_t::tape_pos_t hp_dc100_tape_device::get_approx_pos() const attotime delta_time{ machine().time() - m_start_time }; hti_format_t::tape_pos_t delta_pos = (hti_format_t::tape_pos_t)(delta_time.as_double() * m_speed * hti_format_t::ONE_INCH_POS); auto tape_pos = m_tape_pos; - hti_format_t::pos_offset(tape_pos , true , delta_pos); + hti_format_t::pos_offset(tape_pos, true, delta_pos); return tape_pos; } @@ -429,15 +423,15 @@ bool hp_dc100_tape_device::gap_reached(hti_format_t::tape_pos_t min_gap_size) if (m_gap_detect_start != hti_format_t::NULL_TAPE_POS && abs(m_gap_detect_start - m_tape_pos) >= min_gap_size) { auto tmp = m_tape_pos; - hti_format_t::pos_offset(tmp , is_moving_fwd() , -min_gap_size); - if (m_image.just_gap(get_track_no() , tmp , m_tape_pos)) { + hti_format_t::pos_offset(tmp, is_moving_fwd(), -min_gap_size); + if (m_image.just_gap(get_track_no(), tmp, m_tape_pos)) { return true; } } return false; } -void hp_dc100_tape_device::time_to_next_gap(hti_format_t::tape_pos_t min_gap_size , bool new_gap , emu_timer *target_timer) +void hp_dc100_tape_device::time_to_next_gap(hti_format_t::tape_pos_t min_gap_size, bool new_gap, emu_timer *target_timer) { update_speed_pos(); @@ -446,17 +440,17 @@ void hp_dc100_tape_device::time_to_next_gap(hti_format_t::tape_pos_t min_gap_siz bool found = true; if (new_gap) { hti_format_t::track_iterator_t it; - found = m_image.next_data(get_track_no() , tmp , fwd , true , it); + found = m_image.next_data(get_track_no(), tmp, fwd, true, it); if (found) { - tmp = m_image.farthest_end(it , !fwd); + tmp = m_image.farthest_end(it, !fwd); } } - if (found && m_image.next_gap(get_track_no() , tmp , fwd , min_gap_size)) { + if (found && m_image.next_gap(get_track_no(), tmp, fwd, min_gap_size)) { hti_format_t::tape_pos_t dummy; - LOG_DBG("TTNG T%u S%d N%d %d->%d\n" , get_track_no() , min_gap_size , new_gap , m_tape_pos , tmp); + LOG_DBG("TTNG T%u S%d N%d %d->%d\n", get_track_no(), min_gap_size, new_gap, m_tape_pos, tmp); time_to_distance(tmp - m_tape_pos, dummy, target_timer); } else { - LOG_DBG("TTNG T%u S%d N%d %d->X\n" , get_track_no() , min_gap_size , new_gap , m_tape_pos); + LOG_DBG("TTNG T%u S%d N%d %d->X\n", get_track_no(), min_gap_size, new_gap, m_tape_pos); target_timer->reset(); } } @@ -493,10 +487,10 @@ void hp_dc100_tape_device::device_start() save_item(NAME(m_next_hole_pos)); save_item(NAME(m_image_dirty)); - m_bit_timer = timer_alloc(BIT_TMR_ID); - m_tacho_timer = timer_alloc(TACHO_TMR_ID); - m_hole_timer = timer_alloc(HOLE_TMR_ID); - m_motion_timer = timer_alloc(MOTION_TMR_ID); + m_bit_timer = timer_alloc(FUNC(hp_dc100_tape_device::bit_timer_tick), this); + m_tacho_timer = timer_alloc(FUNC(hp_dc100_tape_device::tacho_timer_tick), this); + m_hole_timer = timer_alloc(FUNC(hp_dc100_tape_device::hole_timer_tick), this); + m_motion_timer = timer_alloc(FUNC(hp_dc100_tape_device::motion_timer_tick), this); } void hp_dc100_tape_device::device_reset() @@ -504,71 +498,76 @@ void hp_dc100_tape_device::device_reset() clear_state(); } -void hp_dc100_tape_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(hp_dc100_tape_device::bit_timer_tick) { - LOG_TMR("%.6f TMR %d p=%d s=%.3f(%.3f) a=%d\n" , machine().time().as_double() , id , m_tape_pos , m_speed , m_set_point , m_accelerating); + LOG_TMR("%.6f TMR 0 p=%d s=%.3f(%.3f) a=%d\n", machine().time().as_double(), m_tape_pos, m_speed, m_set_point, m_accelerating); update_speed_pos(); - switch (id) { - case BIT_TMR_ID: - m_tape_pos = m_next_bit_pos; - if (m_current_op == OP_READ) { - bool bit = BIT(m_rd_it->second , m_bit_idx); - m_rd_bit_handler(bit); - if (is_moving_fwd()) { - if (--m_bit_idx >= 0) { - time_to_distance(m_image.bit_length(BIT(m_rd_it->second , m_bit_idx)), m_next_bit_pos, m_bit_timer); - } else { - m_rd_it_valid = m_image.adv_it(get_track_no() , true , m_rd_it) != hti_format_t::ADV_NO_MORE_DATA; - load_rd_word(); - } + m_tape_pos = m_next_bit_pos; + if (m_current_op == OP_READ) { + bool bit = BIT(m_rd_it->second, m_bit_idx); + m_rd_bit_handler(bit); + if (is_moving_fwd()) { + if (--m_bit_idx >= 0) { + time_to_distance(m_image.bit_length(BIT(m_rd_it->second, m_bit_idx)), m_next_bit_pos, m_bit_timer); } else { - if (++m_bit_idx < 16) { - time_to_distance(-m_image.bit_length(BIT(m_rd_it->second , m_bit_idx)), m_next_bit_pos, m_bit_timer); - } else { - m_rd_it_valid = m_image.adv_it(get_track_no() , false , m_rd_it) != hti_format_t::ADV_NO_MORE_DATA; - load_rd_word(); - } - } - } else if (m_current_op == OP_WRITE) { - bool bit = m_wr_bit_handler(); - hti_format_t::tape_pos_t bit_len = m_image.bit_length(bit); - if (bit) { - BIT_SET(m_rw_word , m_bit_idx); + m_rd_it_valid = m_image.adv_it(get_track_no(), true, m_rd_it) != hti_format_t::ADV_NO_MORE_DATA; + load_rd_word(); } - if (is_moving_fwd()) { - if (--m_bit_idx < 0) { - store_wr_word(); - } + } else { + if (++m_bit_idx < 16) { + time_to_distance(-m_image.bit_length(BIT(m_rd_it->second, m_bit_idx)), m_next_bit_pos, m_bit_timer); } else { - if (++m_bit_idx >= 16) { - store_wr_word(); - } - bit_len = -bit_len; + m_rd_it_valid = m_image.adv_it(get_track_no(), false, m_rd_it) != hti_format_t::ADV_NO_MORE_DATA; + load_rd_word(); } - time_to_distance(bit_len, m_next_bit_pos, m_bit_timer); } - break; + } else if (m_current_op == OP_WRITE) { + bool bit = m_wr_bit_handler(); + hti_format_t::tape_pos_t bit_len = m_image.bit_length(bit); + if (bit) { + BIT_SET(m_rw_word, m_bit_idx); + } + if (is_moving_fwd()) { + if (--m_bit_idx < 0) { + store_wr_word(); + } + } else { + if (++m_bit_idx >= 16) { + store_wr_word(); + } + bit_len = -bit_len; + } + time_to_distance(bit_len, m_next_bit_pos, m_bit_timer); + } +} - case TACHO_TMR_ID: - m_tape_pos = m_next_tacho_pos; - m_tacho_tick_handler(1); - adjust_tacho_timer(); - break; +TIMER_CALLBACK_MEMBER(hp_dc100_tape_device::tacho_timer_tick) +{ + LOG_TMR("%.6f TMR 1 p=%d s=%.3f(%.3f) a=%d\n", machine().time().as_double(), m_tape_pos, m_speed, m_set_point, m_accelerating); + update_speed_pos(); - case HOLE_TMR_ID: - m_tape_pos = m_next_hole_pos; - m_hole_handler(1); - adjust_hole_timer(); - break; + m_tape_pos = m_next_tacho_pos; + m_tacho_tick_handler(1); + adjust_tacho_timer(); +} - case MOTION_TMR_ID: - // In itself it does nothing (all work is in update_speed_pos) - break; +TIMER_CALLBACK_MEMBER(hp_dc100_tape_device::hole_timer_tick) +{ + LOG_TMR("%.6f TMR 2 p=%d s=%.3f(%.3f) a=%d\n", machine().time().as_double(), m_tape_pos, m_speed, m_set_point, m_accelerating); + update_speed_pos(); - default: - break; - } + m_tape_pos = m_next_hole_pos; + m_hole_handler(1); + adjust_hole_timer(); +} + +TIMER_CALLBACK_MEMBER(hp_dc100_tape_device::motion_timer_tick) +{ + LOG_TMR("%.6f TMR 2 p=%d s=%.3f(%.3f) a=%d\n", machine().time().as_double(), m_tape_pos, m_speed, m_set_point, m_accelerating); + update_speed_pos(); + + // All work is in update_speed_pos } void hp_dc100_tape_device::clear_state() @@ -599,7 +598,7 @@ void hp_dc100_tape_device::clear_state() image_init_result hp_dc100_tape_device::internal_load(bool is_create) { - LOG("load %d\n" , is_create); + LOG("load %d\n", is_create); device_reset(); @@ -624,7 +623,7 @@ image_init_result hp_dc100_tape_device::internal_load(bool is_create) } if (!m_image.load_tape(*io)) { LOG("load failed\n"); - seterror(image_error::INVALIDIMAGE , "Wrong format"); + seterror(image_error::INVALIDIMAGE, "Wrong format"); set_tape_present(false); return image_init_result::FAIL; } @@ -645,7 +644,7 @@ void hp_dc100_tape_device::set_tape_present(bool present) } } -double hp_dc100_tape_device::compute_set_point(tape_speed_t speed , bool fwd) const +double hp_dc100_tape_device::compute_set_point(tape_speed_t speed, bool fwd) const { double sp; @@ -666,7 +665,7 @@ double hp_dc100_tape_device::compute_set_point(tape_speed_t speed , bool fwd) co void hp_dc100_tape_device::start_tape() { - LOG_DBG("Tape started %.6f p=%d\n" , machine().time().as_double() , m_tape_pos); + LOG_DBG("Tape started %.6f p=%d\n", machine().time().as_double(), m_tape_pos); m_start_time = machine().time(); m_accelerating = true; m_speed = 0; @@ -674,7 +673,7 @@ void hp_dc100_tape_device::start_tape() void hp_dc100_tape_device::stop_tape() { - LOG_DBG("Tape stops %.6f p=%d\n" , machine().time().as_double() , m_tape_pos); + LOG_DBG("Tape stops %.6f p=%d\n", machine().time().as_double(), m_tape_pos); m_start_time = attotime::never; m_accelerating = false; m_speed = 0; @@ -684,34 +683,34 @@ void hp_dc100_tape_device::stop_tape() stop_op(); } -double hp_dc100_tape_device::const_a_space(double a , double t) const +double hp_dc100_tape_device::const_a_space(double a, double t) const { // Space traveled in time 't' at constant acceleration 'a' starting with 'm_speed' speed return t * (m_speed + a / 2 * t); } -attotime hp_dc100_tape_device::time_to_threshold(double threshold , bool zero_allowed) const +attotime hp_dc100_tape_device::time_to_threshold(double threshold, bool zero_allowed) const { attotime time{ attotime::never }; auto delta_sp = m_set_point - m_speed; auto delta_t = threshold - m_speed; - LOG_DBG("Dsp=%.6f D+th=%.6f\n" , delta_sp , delta_t); + LOG_DBG("Dsp=%.6f D+th=%.6f\n", delta_sp, delta_t); if ((delta_sp * delta_t > 0.0 && fabs(delta_t) <= fabs(delta_sp)) || (zero_allowed && delta_t == 0.0)) { time = attotime::from_double(fabs(delta_t) / m_acceleration); - LOG_DBG("Time to +th: %.6f\n" , time.as_double()); + LOG_DBG("Time to +th: %.6f\n", time.as_double()); } delta_t = -threshold - m_speed; - LOG_DBG("Dsp=%.6f D-th=%.6f\n" , delta_sp , delta_t); + LOG_DBG("Dsp=%.6f D-th=%.6f\n", delta_sp, delta_t); if ((delta_sp * delta_t > 0.0 && fabs(delta_t) <= fabs(delta_sp)) || (zero_allowed && delta_t == 0.0)) { double tm = fabs(delta_t) / m_acceleration; if (tm < time.as_double()) { time = attotime::from_double(tm); - LOG_DBG("Time to -th: %.6f\n" , time.as_double()); + LOG_DBG("Time to -th: %.6f\n", time.as_double()); } } return time; @@ -728,16 +727,16 @@ void hp_dc100_tape_device::set_motion_timer() // 3. Tape direction reverses // 4. Set point is reached // Motion timer is set to expire at the event that occurs first - attotime time{ time_to_threshold(m_slow_set_point , true) }; + attotime time{ time_to_threshold(m_slow_set_point, true) }; - attotime tmp{ time_to_threshold(m_go_threshold , false) }; + attotime tmp{ time_to_threshold(m_go_threshold, false) }; if (tmp < time) { time = tmp; } // Time to the moment when tape inverts its motion // (i.e. when m_speed crosses 0) - tmp = time_to_threshold(0.0 , false); + tmp = time_to_threshold(0.0, false); if (tmp < time) { time = tmp; } @@ -760,7 +759,7 @@ void hp_dc100_tape_device::set_motion_timer() } } -void hp_dc100_tape_device::time_to_distance(hti_format_t::tape_pos_t distance , hti_format_t::tape_pos_t& target_pos , emu_timer *target_timer) const +void hp_dc100_tape_device::time_to_distance(hti_format_t::tape_pos_t distance, hti_format_t::tape_pos_t& target_pos, emu_timer *target_timer) const { if (m_start_time.is_never()) { // If tape is stopped we'll never get there.. @@ -769,7 +768,7 @@ void hp_dc100_tape_device::time_to_distance(hti_format_t::tape_pos_t distance , } target_pos = m_tape_pos; - if (!hti_format_t::pos_offset(target_pos , true , distance)) { + if (!hti_format_t::pos_offset(target_pos, true, distance)) { // Beyond end of tape target_timer->reset(); return; @@ -792,11 +791,11 @@ void hp_dc100_tape_device::time_to_distance(hti_format_t::tape_pos_t distance , if (has_root) { double time_in_const_a_pos = (sqrt(delta) - m_speed) / acceleration; double time_in_const_a_neg = -(sqrt(delta) + m_speed) / acceleration; - LOG_DBG("TTD %.6f %.6f\n" , time_in_const_a_pos , time_in_const_a_neg); + LOG_DBG("TTD %.6f %.6f\n", time_in_const_a_pos, time_in_const_a_neg); if (time_in_const_a_pos >= 0.0) { if (time_in_const_a_neg >= 0.0) { // pos + neg + - time_in_const_a = std::min(time_in_const_a_pos , time_in_const_a_neg); + time_in_const_a = std::min(time_in_const_a_pos, time_in_const_a_neg); } else { // pos + neg - time_in_const_a = time_in_const_a_pos; @@ -811,14 +810,14 @@ void hp_dc100_tape_device::time_to_distance(hti_format_t::tape_pos_t distance , } } } - LOG_DBG("TTD %d %d %.6f %.6f %.6f\n" , distance , has_root , m_speed , time_to_const_v , time_in_const_a); + LOG_DBG("TTD %d %d %.6f %.6f %.6f\n", distance, has_root, m_speed, time_to_const_v, time_in_const_a); if (has_root && time_in_const_a <= time_to_const_v) { // Entirely in the constant A phase time_const_a = time_in_const_a; space = 0.0; } else { // Partly in const A & partly in const V - double space_in_const_a = const_a_space(acceleration , time_to_const_v); + double space_in_const_a = const_a_space(acceleration, time_to_const_v); space -= space_in_const_a; time_const_a = time_to_const_v; } @@ -843,7 +842,7 @@ void hp_dc100_tape_device::time_to_distance(hti_format_t::tape_pos_t distance , } else { time_const_v = 0.0; } - LOG_DBG("TTD %.6f %.6f\n" , time_const_a , time_const_v); + LOG_DBG("TTD %.6f %.6f\n", time_const_a, time_const_v); target_timer->adjust(attotime::from_double(time_const_a + time_const_v)); } @@ -864,13 +863,13 @@ void hp_dc100_tape_device::adjust_tacho_timer() // on a tick (tick_fract == 0) dist_to_next = -m_tick_size; } - LOG_DBG("Next tick @%d (pos=%d)\n" , dist_to_next , m_tape_pos); + LOG_DBG("Next tick @%d (pos=%d)\n", dist_to_next, m_tape_pos); time_to_distance(dist_to_next, m_next_tacho_pos, m_tacho_timer); } void hp_dc100_tape_device::adjust_hole_timer() { - auto hole_pos = m_image.next_hole(m_tape_pos , is_moving_fwd()); + auto hole_pos = m_image.next_hole(m_tape_pos, is_moving_fwd()); if (hole_pos == hti_format_t::NULL_TAPE_POS) { m_hole_timer->reset(); } else { @@ -883,8 +882,8 @@ void hp_dc100_tape_device::stop_op() if (m_current_op == OP_WRITE) { store_wr_word(); } else if (m_current_op == OP_ERASE) { - LOG_DBG("Wr gap from %d to %d\n" , m_rw_pos , m_tape_pos); - m_image.write_gap(get_track_no() , m_rw_pos , m_tape_pos); + LOG_DBG("Wr gap from %d to %d\n", m_rw_pos, m_tape_pos); + m_image.write_gap(get_track_no(), m_rw_pos, m_tape_pos); m_image_dirty = true; } m_bit_timer->reset(); @@ -902,16 +901,16 @@ void hp_dc100_tape_device::load_rd_word() m_bit_idx = 0; } // This is actually the nearest end (dir is inverted) - m_rw_pos = m_next_bit_pos = m_image.farthest_end(m_rd_it , !fwd); + m_rw_pos = m_next_bit_pos = m_image.farthest_end(m_rd_it, !fwd); // Compute end of bit cell - hti_format_t::tape_pos_t bit_len = m_image.bit_length(BIT(m_rd_it->second , m_bit_idx)); + hti_format_t::tape_pos_t bit_len = m_image.bit_length(BIT(m_rd_it->second, m_bit_idx)); if (!fwd) { bit_len = -bit_len; } - time_to_distance(m_next_bit_pos + bit_len - m_tape_pos , m_next_bit_pos , m_bit_timer); - LOG_RW("RD %04x @%d\n" , m_rd_it->second , m_next_bit_pos); + time_to_distance(m_next_bit_pos + bit_len - m_tape_pos, m_next_bit_pos, m_bit_timer); + LOG_RW("RD %04x @%d\n", m_rd_it->second, m_next_bit_pos); } else { - LOG_RW("End of RD data @%d\n" , m_tape_pos); + LOG_RW("End of RD data @%d\n", m_tape_pos); stop_op(); m_gap_detect_start = m_tape_pos; } @@ -928,8 +927,8 @@ void hp_dc100_tape_device::store_wr_word() if (!fwd) { m_rw_pos -= word_length; } - LOG_RW("WR %04x @%d\n" , m_rw_word , m_rw_pos); - m_image.write_word(get_track_no() , m_rw_pos , m_rw_word , word_length , fwd); + LOG_RW("WR %04x @%d\n", m_rw_word, m_rw_pos); + m_image.write_word(get_track_no(), m_rw_pos, m_rw_word, word_length, fwd); m_image_dirty = true; m_rw_word = 0; if (fwd) { diff --git a/src/devices/machine/hp_dc100_tape.h b/src/devices/machine/hp_dc100_tape.h index 3ee166466ce..fd8ff3b5425 100644 --- a/src/devices/machine/hp_dc100_tape.h +++ b/src/devices/machine/hp_dc100_tape.h @@ -103,7 +103,11 @@ protected: // device-level overrides virtual void device_start() override; virtual void device_reset() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; + + TIMER_CALLBACK_MEMBER(bit_timer_tick); + TIMER_CALLBACK_MEMBER(tacho_timer_tick); + TIMER_CALLBACK_MEMBER(hole_timer_tick); + TIMER_CALLBACK_MEMBER(motion_timer_tick); private: devcb_write_line m_cart_out_handler; diff --git a/src/devices/machine/hp_taco.cpp b/src/devices/machine/hp_taco.cpp index 02cbfa2199d..8896edf0fc2 100644 --- a/src/devices/machine/hp_taco.cpp +++ b/src/devices/machine/hp_taco.cpp @@ -141,16 +141,18 @@ #include "hp_taco.h" // Debugging -#include "logmacro.h" + #define LOG_DBG_MASK (LOG_GENERAL << 1) -#define LOG_DBG(...) LOGMASKED(LOG_DBG_MASK, __VA_ARGS__) #define LOG_RW_MASK (LOG_DBG_MASK << 1) -#define LOG_RW(...) LOGMASKED(LOG_RW_MASK, __VA_ARGS__) #define LOG_REG_MASK (LOG_RW_MASK << 1) + +#define LOG_DBG(...) LOGMASKED(LOG_DBG_MASK, __VA_ARGS__) +#define LOG_RW(...) LOGMASKED(LOG_RW_MASK, __VA_ARGS__) #define LOG_REG(...) LOGMASKED(LOG_REG_MASK, __VA_ARGS__) -#undef VERBOSE + //#define VERBOSE (LOG_GENERAL | LOG_DBG_MASK | LOG_RW_MASK | LOG_REG_MASK) #define VERBOSE (LOG_GENERAL) +#include "logmacro.h" // Bit manipulation namespace { @@ -159,24 +161,17 @@ namespace { return (T)1U << n; } - template<typename T> void BIT_CLR(T& w , unsigned n) + template<typename T> void BIT_CLR(T& w, unsigned n) { w &= ~BIT_MASK<T>(n); } - template<typename T> void BIT_SET(T& w , unsigned n) + template<typename T> void BIT_SET(T& w, unsigned n) { w |= BIT_MASK<T>(n); } } -// Timers -enum { - GAP_TMR_ID, - EVD_TMR_ID, - ERROR_TMR_ID -}; - // **** Constants **** constexpr unsigned TACH_FREQ_FAST = 87196; // Tachometer pulse frequency for fast speed (90.08 ips) constexpr unsigned TACH_FREQ_SLOW = 21276; // Tachometer pulse frequency for slow speed (21.98 ips) @@ -281,7 +276,7 @@ DEFINE_DEVICE_TYPE(HP_TACO, hp_taco_device, "hp_taco", "HP TACO") // Constructors hp_taco_device::hp_taco_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock) : device_t(mconfig, type, tag, owner, clock) - , m_tape(*this , "drive") + , m_tape(*this, "drive") , m_irq_handler(*this) , m_flg_handler(*this) , m_sts_handler(*this) @@ -300,7 +295,7 @@ void hp_taco_device::set_name(const std::string& name) void hp_taco_device::reg_w(offs_t offset, uint16_t data) { - LOG_REG("wr R%u = %04x\n", 4 + offset , data); + LOG_REG("wr R%u = %04x\n", 4 + offset, data); // Any I/O activity clears IRQ irq_w(false); @@ -344,9 +339,9 @@ uint16_t hp_taco_device::reg_r(offs_t offset) case 1: // Command & status register if (m_tape->gap_reached(SHORT_GAP_LENGTH)) { - BIT_SET(m_status_reg , CMD_ST_GAP); + BIT_SET(m_status_reg, CMD_ST_GAP); } else { - BIT_CLR(m_status_reg , CMD_ST_GAP); + BIT_CLR(m_status_reg, CMD_ST_GAP); } res = (m_cmd_reg & CMD_REG_MASK) | (m_status_reg & STATUS_REG_MASK); break; @@ -363,7 +358,7 @@ uint16_t hp_taco_device::reg_r(offs_t offset) break; } - LOG_REG("rd R%u = %04x\n", 4 + offset , res); + LOG_REG("rd R%u = %04x\n", 4 + offset, res); return res; } @@ -380,10 +375,10 @@ READ_LINE_MEMBER(hp_taco_device::sts_r) WRITE_LINE_MEMBER(hp_taco_device::cart_out_w) { - LOG_DBG("cart_out_w %d\n" , state); + LOG_DBG("cart_out_w %d\n", state); set_tape_present(!state); if (state && m_cmd_state != CMD_IDLE) { - set_error(true , false); + set_error(true, false); m_cmd_state = CMD_IDLE; } } @@ -393,10 +388,10 @@ WRITE_LINE_MEMBER(hp_taco_device::hole_w) if (state) { LOG_DBG("hole_w\n"); if (m_cmd_state != CMD_IDLE && m_cmd_state != CMD_STOPPING && - (!is_double_hole_cmd(m_cmd_reg) || BIT(m_status_reg , CMD_ST_HOLE))) { - set_error(true , false); + (!is_double_hole_cmd(m_cmd_reg) || BIT(m_status_reg, CMD_ST_HOLE))) { + set_error(true, false); } - BIT_SET(m_status_reg , CMD_ST_HOLE); + BIT_SET(m_status_reg, CMD_ST_HOLE); } } @@ -427,7 +422,7 @@ WRITE_LINE_MEMBER(hp_taco_device::tacho_tick_w) if (m_cmd_state == CMD_PH2) { m_tach_reg++; if (m_tach_reg == 0) { - if (!BIT(m_cmd_reg , CMD_ST_G0)) { + if (!BIT(m_cmd_reg, CMD_ST_G0)) { irq_w(true); } send_stop(); @@ -465,7 +460,7 @@ WRITE_LINE_MEMBER(hp_taco_device::motion_w) WRITE_LINE_MEMBER(hp_taco_device::rd_bit_w) { - LOG_RW("RD bit %d (st=%d,w=%04x,i=%u)\n" , state , m_cmd_state , m_working_reg , m_bit_idx); + LOG_RW("RD bit %d (st=%d,w=%04x,i=%u)\n", state, m_cmd_state, m_working_reg, m_bit_idx); if (m_cmd_state != CMD_IDLE) { switch (get_cmd(m_cmd_reg)) { case CMD_RD_6UPD: @@ -479,7 +474,7 @@ WRITE_LINE_MEMBER(hp_taco_device::rd_bit_w) // Synchronized LOG_RW("RD synced!\n"); m_cmd_state = CMD_PH2; - m_bit_idx = BIT(m_cmd_reg , CMD_ST_G0) ? 17 : 15; + m_bit_idx = BIT(m_cmd_reg, CMD_ST_G0) ? 17 : 15; m_working_reg = 0; } } else if (m_cmd_state == CMD_PH2) { @@ -489,15 +484,15 @@ WRITE_LINE_MEMBER(hp_taco_device::rd_bit_w) break; } else if (m_bit_idx != 16 && state) { // Skip 17th bit when reading in 9825 format - BIT_SET(m_working_reg , m_bit_idx); + BIT_SET(m_working_reg, m_bit_idx); } if (adv_bit_idx()) { m_data_reg = m_working_reg; m_working_reg = 0; - if (!BIT(m_cmd_reg , CMD_ST_G2)) { + if (!BIT(m_cmd_reg, CMD_ST_G2)) { update_checksum(m_data_reg); } - LOG_RW("RD word %04x csum=%04x\n" , m_data_reg , m_checksum_reg); + LOG_RW("RD word %04x csum=%04x\n", m_data_reg, m_checksum_reg); irq_w(true); } } @@ -529,7 +524,7 @@ READ_LINE_MEMBER(hp_taco_device::wr_bit_r) // HP9825 format: 17th bit bit = true; } else { - bit = BIT(m_working_reg , m_bit_idx); + bit = BIT(m_working_reg, m_bit_idx); } if (adv_bit_idx()) { m_working_reg = m_data_reg; @@ -537,20 +532,20 @@ READ_LINE_MEMBER(hp_taco_device::wr_bit_r) if ((get_cmd(m_cmd_reg) & ~BIT_MASK<uint8_t>(0)) != CMD_WR_CSUM) { update_checksum(m_data_reg); } - LOG_RW("WR word %04x csum=%04x\n" , m_working_reg , m_checksum_reg); + LOG_RW("WR word %04x csum=%04x\n", m_working_reg, m_checksum_reg); m_data_reg = m_checksum_reg; irq_w(true); } } - LOG_RW("WR bit %d (w=%04x,i=%u)\n" , bit , m_working_reg , m_bit_idx); + LOG_RW("WR bit %d (w=%04x,i=%u)\n", bit, m_working_reg, m_bit_idx); return bit; } void hp_taco_device::device_add_mconfig(machine_config &config) { - HP_DC100_TAPE(config , m_tape , 0); + HP_DC100_TAPE(config, m_tape, 0); m_tape->set_acceleration(ACCELERATION); - m_tape->set_set_points(SLOW_SPEED , FAST_SPEED); + m_tape->set_set_points(SLOW_SPEED, FAST_SPEED); m_tape->set_tick_size(TACH_TICK_LEN); m_tape->set_image_format(hti_format_t::HTI_DELTA_MOD_16_BITS); m_tape->set_go_threshold(MOVING_THRESHOLD); @@ -583,9 +578,9 @@ void hp_taco_device::device_start() save_item(NAME(m_working_reg)); save_item(NAME(m_bit_idx)); - m_gap_timer = timer_alloc(GAP_TMR_ID); - m_evd_timer = timer_alloc(EVD_TMR_ID); - m_error_timer = timer_alloc(ERROR_TMR_ID); + m_gap_timer = timer_alloc(FUNC(hp_taco_device::gap_timer_tick), this); + m_evd_timer = timer_alloc(FUNC(hp_taco_device::evd_timer_tick), this); + m_error_timer = timer_alloc(FUNC(hp_taco_device::error_timer_tick), this); } void hp_taco_device::device_reset() @@ -600,69 +595,51 @@ void hp_taco_device::device_reset() m_irq_handler(false); m_flg_handler(true); m_sts_handler(true); - set_error(false , false); + set_error(false, false); m_gap_timer->reset(); m_evd_timer->reset(); m_error_timer->reset(); } -void hp_taco_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(hp_taco_device::gap_timer_tick) { - switch (id) { - case GAP_TMR_ID: - m_tape->update_speed_pos(); - LOG_DBG("Gap tmr @%g pos=%d cmd %02x st %d\n" , machine().time().as_double() , m_tape->get_pos() , get_cmd(m_cmd_reg) , m_cmd_state); - - switch (get_cmd(m_cmd_reg)) { - case CMD_INT_ON_GAP: - if (m_cmd_state == CMD_PH1) { - irq_and_end(); - } - break; - - case CMD_STOP_IN_GAP: - case CMD_STOP_IN_GAP1: - if (m_cmd_state == CMD_PH1) { - // Count 256 ticks - m_tach_reg = 0xff00; - m_cmd_state = CMD_PH2; - } - break; - - case CMD_INT_N_GAP: - if (m_cmd_state == CMD_PH1) { - m_tach_reg++; - if (m_tach_reg == 0) { - irq_and_end(); - } else { - set_gap_timer(); - } - } - break; + m_tape->update_speed_pos(); + LOG_DBG("Gap tmr @%g pos=%d cmd %02x st %d\n", machine().time().as_double(), m_tape->get_pos(), get_cmd(m_cmd_reg), m_cmd_state); - case CMD_RD_6UPD: - case CMD_RD_9825_6UPD: - case CMD_RD_CSUM_6UPD: - case CMD_RD_9825_CSUM6: - // Gap in read error - set_error(false , true); - break; + switch (get_cmd(m_cmd_reg)) { + case CMD_INT_ON_GAP: + if (m_cmd_state == CMD_PH1) { + irq_and_end(); + } + break; - default: - break; + case CMD_STOP_IN_GAP: + case CMD_STOP_IN_GAP1: + if (m_cmd_state == CMD_PH1) { + // Count 256 ticks + m_tach_reg = 0xff00; + m_cmd_state = CMD_PH2; } break; - case EVD_TMR_ID: - m_tape->update_speed_pos(); - LOG_DBG("EVD tmr @%g pos=%d cmd %02x st %d\n" , machine().time().as_double() , m_tape->get_pos() , get_cmd(m_cmd_reg) , m_cmd_state); - set_error(true , false); + case CMD_INT_N_GAP: + if (m_cmd_state == CMD_PH1) { + m_tach_reg++; + if (m_tach_reg == 0) { + irq_and_end(); + } else { + set_gap_timer(); + } + } break; - case ERROR_TMR_ID: - LOG_DBG("Error tmr\n"); - irq_w(true); + case CMD_RD_6UPD: + case CMD_RD_9825_6UPD: + case CMD_RD_CSUM_6UPD: + case CMD_RD_9825_CSUM6: + // Gap in read error + set_error(false, true); break; default: @@ -670,6 +647,19 @@ void hp_taco_device::device_timer(emu_timer &timer, device_timer_id id, int para } } +TIMER_CALLBACK_MEMBER(hp_taco_device::evd_timer_tick) +{ + m_tape->update_speed_pos(); + LOG_DBG("EVD tmr @%g pos=%d cmd %02x st %d\n", machine().time().as_double(), m_tape->get_pos(), get_cmd(m_cmd_reg), m_cmd_state); + set_error(true, false); +} + +TIMER_CALLBACK_MEMBER(hp_taco_device::error_timer_tick) +{ + LOG_DBG("Error tmr\n"); + irq_w(true); +} + void hp_taco_device::clear_state() { m_data_reg = 0; @@ -691,7 +681,7 @@ void hp_taco_device::irq_w(bool state) if (state != m_irq) { m_irq = state; m_irq_handler(state); - LOG_DBG("IRQ = %d\n" , state); + LOG_DBG("IRQ = %d\n", state); } } @@ -700,13 +690,13 @@ void hp_taco_device::sts_w(bool state) if (state != m_sts) { m_sts = state; m_sts_handler(state); - LOG_DBG("STS = %d\n" , state); + LOG_DBG("STS = %d\n", state); } } -void hp_taco_device::set_error(bool error , bool gap_in_read) +void hp_taco_device::set_error(bool error, bool gap_in_read) { - LOG_DBG("Error %d %d\n" , error , gap_in_read); + LOG_DBG("Error %d %d\n", error, gap_in_read); m_error = error; m_gap_in_read = gap_in_read; @@ -718,7 +708,7 @@ void hp_taco_device::set_error(bool error , bool gap_in_read) m_cmd_state = CMD_IDLE; } sts_w(false); - m_error_timer->adjust(attotime::zero , 0 , clocks_to_attotime(ERROR_IRQ_PERIOD)); + m_error_timer->adjust(attotime::zero, 0, clocks_to_attotime(ERROR_IRQ_PERIOD)); if (m_error) { send_stop(); } @@ -729,17 +719,17 @@ void hp_taco_device::set_error(bool error , bool gap_in_read) hti_format_t::tape_pos_t hp_taco_device::min_gap_size() const { - return BIT(m_cmd_reg , CMD_ST_FGAP) ? LONG_GAP_LENGTH : SHORT_GAP_LENGTH; + return BIT(m_cmd_reg, CMD_ST_FGAP) ? LONG_GAP_LENGTH : SHORT_GAP_LENGTH; } void hp_taco_device::set_gap_timer() { - m_tape->time_to_next_gap(min_gap_size() , true , m_gap_timer); + m_tape->time_to_next_gap(min_gap_size(), true, m_gap_timer); } void hp_taco_device::set_evd_timer() { - m_tape->time_to_next_gap(EVD_GAP_LENGTH , false , m_evd_timer); + m_tape->time_to_next_gap(EVD_GAP_LENGTH, false, m_evd_timer); } void hp_taco_device::set_tape_present(bool present) @@ -761,18 +751,18 @@ void hp_taco_device::send_go() { hp_dc100_tape_device::tape_speed_t speed; - if (BIT(m_cmd_reg , CMD_ST_FST)) { + if (BIT(m_cmd_reg, CMD_ST_FST)) { speed = hp_dc100_tape_device::SP_FAST; } else { speed = hp_dc100_tape_device::SP_SLOW; } - m_tape->set_speed_setpoint(speed , BIT(m_cmd_reg , CMD_ST_FWD)); + m_tape->set_speed_setpoint(speed, BIT(m_cmd_reg, CMD_ST_FWD)); } void hp_taco_device::send_stop() { m_tape->set_op(hp_dc100_tape_device::OP_IDLE); - if (m_tape->set_speed_setpoint(hp_dc100_tape_device::SP_STOP , false)) { + if (m_tape->set_speed_setpoint(hp_dc100_tape_device::SP_STOP, false)) { m_cmd_state = CMD_STOPPING; } } @@ -800,7 +790,7 @@ void hp_taco_device::start_rd() if (m_tape->get_op() != hp_dc100_tape_device::OP_READ) { m_tape->set_op(hp_dc100_tape_device::OP_READ); // TODO: check - m_tape->time_to_next_gap(GIR_GAP_LENGTH , true , m_gap_timer); + m_tape->time_to_next_gap(GIR_GAP_LENGTH, true, m_gap_timer); set_evd_timer(); } } @@ -817,7 +807,7 @@ bool hp_taco_device::adv_bit_idx() if (m_bit_idx) { m_bit_idx--; } else { - m_bit_idx = BIT(m_cmd_reg , CMD_ST_G0) ? 16 : 15; + m_bit_idx = BIT(m_cmd_reg, CMD_ST_G0) ? 16 : 15; } return m_bit_idx == 15; } @@ -942,7 +932,7 @@ void hp_taco_device::cmd_fsm() } } if (prev_state != m_cmd_state) { - LOG_DBG("FSM st %d->%d\n" , prev_state , m_cmd_state); + LOG_DBG("FSM st %d->%d\n", prev_state, m_cmd_state); } } @@ -955,17 +945,17 @@ uint8_t hp_taco_device::get_cmd(uint16_t cmd_reg) bool hp_taco_device::is_cmd_rd_wr(uint16_t cmd_reg) { - return BIT(cmd_reg , CMD_ST_G1); + return BIT(cmd_reg, CMD_ST_G1); } bool hp_taco_device::is_cmd_rd(uint16_t cmd_reg) { - return is_cmd_rd_wr(cmd_reg) && BIT(cmd_reg , CMD_ST_G3); + return is_cmd_rd_wr(cmd_reg) && BIT(cmd_reg, CMD_ST_G3); } bool hp_taco_device::is_cmd_wr(uint16_t cmd_reg) { - return is_cmd_rd_wr(cmd_reg) && !BIT(cmd_reg , CMD_ST_G3); + return is_cmd_rd_wr(cmd_reg) && !BIT(cmd_reg, CMD_ST_G3); } bool hp_taco_device::is_double_hole_cmd(uint16_t cmd_reg) @@ -975,7 +965,7 @@ bool hp_taco_device::is_double_hole_cmd(uint16_t cmd_reg) void hp_taco_device::start_cmd_exec(uint16_t new_cmd_reg) { - LOG_DBG("New cmd %02x D=%d S=%d @ %g cmd %02x st %d\n" , get_cmd(new_cmd_reg) , BIT(new_cmd_reg , CMD_ST_FWD) , BIT(new_cmd_reg , CMD_ST_FST) , machine().time().as_double() , get_cmd(m_cmd_reg) , m_cmd_state); + LOG_DBG("New cmd %02x D=%d S=%d @ %g cmd %02x st %d\n", get_cmd(new_cmd_reg), BIT(new_cmd_reg, CMD_ST_FWD), BIT(new_cmd_reg, CMD_ST_FST), machine().time().as_double(), get_cmd(m_cmd_reg), m_cmd_state); m_tape->update_speed_pos(); @@ -983,7 +973,7 @@ void hp_taco_device::start_cmd_exec(uint16_t new_cmd_reg) if (new_cmd_code == CMD_CLEAR_ST) { // Clear status - set_error(false , false); + set_error(false, false); sts_w(true); if (!m_tape->cart_out_r()) { BIT_CLR(m_status_reg, CMD_ST_CART_OUT); @@ -998,7 +988,7 @@ void hp_taco_device::start_cmd_exec(uint16_t new_cmd_reg) hp_dc100_tape_device::tape_op_t op = hp_dc100_tape_device::OP_IDLE; if (m_gap_in_read) { - set_error(false , false); + set_error(false, false); } m_cmd_state = CMD_PH0; @@ -1048,11 +1038,11 @@ void hp_taco_device::start_cmd_exec(uint16_t new_cmd_reg) case CMD_SET_TRACK: // 1. Set A/B track - if (BIT(new_cmd_reg , CMD_ST_MOD)) { - BIT_SET(m_status_reg , CMD_ST_TRB); + if (BIT(new_cmd_reg, CMD_ST_MOD)) { + BIT_SET(m_status_reg, CMD_ST_TRB); m_tape->set_track_no(1); } else { - BIT_CLR(m_status_reg , CMD_ST_TRB); + BIT_CLR(m_status_reg, CMD_ST_TRB); m_tape->set_track_no(0); } start_tape = false; @@ -1128,16 +1118,16 @@ void hp_taco_device::start_cmd_exec(uint16_t new_cmd_reg) break; default: - LOG("Unrecognized command %x\n" , new_cmd_code); + LOG("Unrecognized command %x\n", new_cmd_code); start_tape = false; break; } if (start_tape) { if (m_error || - (BIT(m_status_reg , CMD_ST_HOLE) && !is_double_hole_cmd(new_cmd_reg)) || - BIT(m_status_reg , CMD_ST_CART_OUT)) { - set_error(true , false); + (BIT(m_status_reg, CMD_ST_HOLE) && !is_double_hole_cmd(new_cmd_reg)) || + BIT(m_status_reg, CMD_ST_CART_OUT)) { + set_error(true, false); return; } else { send_go(); diff --git a/src/devices/machine/hp_taco.h b/src/devices/machine/hp_taco.h index e6c212b6505..f409946a988 100644 --- a/src/devices/machine/hp_taco.h +++ b/src/devices/machine/hp_taco.h @@ -52,7 +52,10 @@ 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(evd_timer_tick); + TIMER_CALLBACK_MEMBER(error_timer_tick); private: required_device<hp_dc100_tape_device> m_tape; diff --git a/src/devices/machine/i7220.cpp b/src/devices/machine/i7220.cpp index 64a582ddd18..9d9c788759f 100644 --- a/src/devices/machine/i7220.cpp +++ b/src/devices/machine/i7220.cpp @@ -79,7 +79,7 @@ void i7220_device::device_start() intrq_cb.resolve_safe(); drq_cb.resolve_safe(); - bi.tm = timer_alloc(0); + m_bi.tm = timer_alloc(FUNC(i7220_device::general_continue), this); // register for state saving save_item(NAME(m_regs)); @@ -96,9 +96,9 @@ void i7220_device::device_start() void i7220_device::device_reset() { - main_phase = PHASE_IDLE; - bi.main_state = IDLE; - bi.sub_state = IDLE; + m_main_phase = PHASE_IDLE; + m_bi.main_state = IDLE; + m_bi.sub_state = IDLE; set_drq(false); set_irq(false); @@ -108,11 +108,6 @@ void i7220_device::device_reset() memset(&m_regs, 0, sizeof(m_regs)); } -void i7220_device::device_timer(emu_timer &timer, device_timer_id id, int param) -{ - general_continue(bi); -} - image_init_result i7220_device::call_load() { if (length() != (m_data_size * I7110_MBM_SIZE)) @@ -125,25 +120,25 @@ image_init_result i7220_device::call_load() void i7220_device::set_drq(bool state) { - if (state != drq) + if (state != m_drq) { - drq = state; - drq_cb(drq); + m_drq = state; + drq_cb(m_drq); } } void i7220_device::set_irq(bool state) { - if (state != irq) + if (state != m_irq) { - irq = state; - intrq_cb(irq); + m_irq = state; + intrq_cb(m_irq); } } void i7220_device::update_drq() { - switch (bi.main_state) + switch (m_bi.main_state) { case READ_DATA: set_drq(m_fifo_size < 22 ? false : true); @@ -175,7 +170,7 @@ uint8_t i7220_device::fifo_pop() { val = m_fifo.dequeue(); m_fifo_size--; - if (main_phase == PHASE_EXEC) + if (m_main_phase == PHASE_EXEC) { update_drq(); } @@ -193,7 +188,7 @@ void i7220_device::fifo_push(uint8_t val) { m_fifo.enqueue(val); m_fifo_size++; - if (main_phase == PHASE_EXEC) + if (m_main_phase == PHASE_EXEC) { update_drq(); } @@ -204,16 +199,16 @@ void i7220_device::update_regs() { m_blr = (m_regs[R_BLR_M] << 8) + m_regs[R_BLR_L]; m_ar = (m_regs[R_AR_M] << 8) + m_regs[R_AR_L]; - blr_count = m_blr & 0x7ff; - blr_nfc = (m_blr >> 12) ? ((m_blr >> 12) << 1) : 1; - ar_addr = m_ar & 0x7ff; - ar_mbm = (m_ar >> 11) & 15; + m_blr_count = m_blr & 0x7ff; + m_blr_nfc = (m_blr >> 12) ? ((m_blr >> 12) << 1) : 1; + m_ar_addr = m_ar & 0x7ff; + m_ar_mbm = (m_ar >> 11) & 15; } void i7220_device::start_command(int cmd) { - main_phase = PHASE_EXEC; + m_main_phase = PHASE_EXEC; m_str &= ~SR_CLEAR; switch (cmd) @@ -224,45 +219,45 @@ void i7220_device::start_command(int cmd) // MBM GROUP SELECT bits in the AR must select the last MBM in the system. case C_INIT: LOG("BMC INIT: BLR %04x (NFC %d pages %d) AR %04x (MBM %d addr %03x) ER %02d\n", - m_blr, blr_nfc, blr_count, m_ar, ar_mbm, ar_addr, m_regs[R_ER]); - if (blr_nfc != 2) + m_blr, m_blr_nfc, m_blr_count, m_ar, m_ar_mbm, m_ar_addr, m_regs[R_ER]); + if (m_blr_nfc != 2) { - command_fail_start(bi); + command_fail_start(); } else { - init_start(bi); + init_start(); } break; case C_READ_FSA_STATUS: - read_fsa_start(bi); + read_fsa_start(); break; // all parametric registers must be properly set up before issuing Read Bubble Data command case C_READ: LOG("BMC RBD: BLR %04x (NFC %d pages %d) AR %04x (MBM %d addr %03x) ER %02d\n", - m_blr, blr_nfc, blr_count, m_ar, ar_mbm, ar_addr, m_regs[R_ER]); - if (ar_mbm >= m_data_size || blr_nfc != 2) + m_blr, m_blr_nfc, m_blr_count, m_ar, m_ar_mbm, m_ar_addr, m_regs[R_ER]); + if (m_ar_mbm >= m_data_size || m_blr_nfc != 2) { - command_fail_start(bi); + command_fail_start(); } else { - read_data_start(bi); + read_data_start(); } break; case C_WRITE: LOG("BMC WBD: BLR %04x (NFC %d pages %d) AR %04x (MBM %d addr %03x) ER %02d\n", - m_blr, blr_nfc, blr_count, m_ar, ar_mbm, ar_addr, m_regs[R_ER]); - if (ar_mbm >= m_data_size || blr_nfc != 2) + m_blr, m_blr_nfc, m_blr_count, m_ar, m_ar_mbm, m_ar_addr, m_regs[R_ER]); + if (m_ar_mbm >= m_data_size || m_blr_nfc != 2) { - command_fail_start(bi); + command_fail_start(); } else { - write_data_start(bi); + write_data_start(); } break; @@ -271,28 +266,28 @@ void i7220_device::start_command(int cmd) m_regs[R_AR_L] = 0; m_regs[R_AR_M] &= ~7; update_regs(); - main_phase = PHASE_RESULT; + m_main_phase = PHASE_RESULT; m_str |= SR_DONE; break; // controlled termination of currently executing command. command accepted in BUSY state. // if not BUSY, clears FIFO. case C_ABORT: - if (main_phase == PHASE_IDLE) + if (m_main_phase == PHASE_IDLE) { fifo_clear(); } else { - main_phase = PHASE_RESULT; - bi.main_state = bi.sub_state = IDLE; + m_main_phase = PHASE_RESULT; + m_bi.main_state = m_bi.sub_state = IDLE; } m_str |= SR_DONE; break; case C_RESET_FIFO: fifo_clear(); - main_phase = PHASE_RESULT; + m_main_phase = PHASE_RESULT; m_str |= SR_DONE; break; @@ -300,45 +295,45 @@ void i7220_device::start_command(int cmd) case C_RESET: m_regs[R_UR] = 0; fifo_clear(); - main_phase = PHASE_RESULT; + m_main_phase = PHASE_RESULT; m_str |= SR_DONE; break; default: - command_fail_start(bi); + command_fail_start(); break; } } -void i7220_device::general_continue(bubble_info &bi) +TIMER_CALLBACK_MEMBER(i7220_device::general_continue) { - switch (bi.main_state) + switch (m_bi.main_state) { case IDLE: break; case INIT: - init_continue(bi); + init_continue(); break; case FAIL: - command_fail_continue(bi); + command_fail_continue(); break; case READ_FSA: - read_fsa_continue(bi); + read_fsa_continue(); break; case READ_DATA: - read_data_continue(bi); + read_data_continue(); break; case WRITE_DATA: - write_data_continue(bi); + write_data_continue(); break; default: - LOG("BMC general_continue on unknown main-state %d\n", bi.main_state); + LOG("BMC general_continue on unknown main-state %d\n", m_bi.main_state); break; } } @@ -348,11 +343,11 @@ void i7220_device::delay_cycles(emu_timer *tm, int cycles) tm->adjust(attotime::from_double(double(cycles) / clock())); } -void i7220_device::command_end(bubble_info &bi, bool success) +void i7220_device::command_end(bool success) { LOG("command done (%s) - %02x\n", success ? "success" : "fail", m_str); - main_phase = PHASE_RESULT; - bi.main_state = bi.sub_state = IDLE; + m_main_phase = PHASE_RESULT; + m_bi.main_state = m_bi.sub_state = IDLE; if (success) { m_str |= SR_DONE; @@ -364,88 +359,88 @@ void i7220_device::command_end(bubble_info &bi, bool success) } -void i7220_device::command_fail_start(bubble_info &bi) +void i7220_device::command_fail_start() { - bi.main_state = FAIL; - bi.sub_state = INITIALIZE; + m_bi.main_state = FAIL; + m_bi.sub_state = INITIALIZE; - command_fail_continue(bi); + command_fail_continue(); } -void i7220_device::command_fail_continue(bubble_info &bi) +void i7220_device::command_fail_continue() { - switch (bi.sub_state) + switch (m_bi.sub_state) { case INITIALIZE: - bi.sub_state = COMMAND_DONE; - delay_cycles(bi.tm, 1200); // XXX + m_bi.sub_state = COMMAND_DONE; + delay_cycles(m_bi.tm, 1200); // XXX return; case COMMAND_DONE: - command_end(bi, false); + command_end(false); return; default: - LOG("BMC fail unknown sub-state %d\n", bi.sub_state); + LOG("BMC fail unknown sub-state %d\n", m_bi.sub_state); return; } } -void i7220_device::init_start(bubble_info &bi) +void i7220_device::init_start() { - bi.main_state = INIT; - bi.sub_state = INITIALIZE; + m_bi.main_state = INIT; + m_bi.sub_state = INITIALIZE; - init_continue(bi); + init_continue(); } -void i7220_device::init_continue(bubble_info &bi) +void i7220_device::init_continue() { for (;;) { - switch (bi.sub_state) + switch (m_bi.sub_state) { case INITIALIZE: - bi.sub_state = WAIT_FSA_REPLY; - delay_cycles(bi.tm, m_data_size * 60); // p. 4-16 of BPK72UM + m_bi.sub_state = WAIT_FSA_REPLY; + delay_cycles(m_bi.tm, m_data_size * 60); // p. 4-16 of BPK72UM return; case WAIT_FSA_REPLY: - bi.sub_state = COMMAND_DONE; + m_bi.sub_state = COMMAND_DONE; break; case COMMAND_DONE: - command_end(bi, true); + command_end(true); return; default: - LOG("BMC init unknown sub-state %d\n", bi.sub_state); + LOG("BMC init unknown sub-state %d\n", m_bi.sub_state); return; } } } -void i7220_device::read_fsa_start(bubble_info &bi) +void i7220_device::read_fsa_start() { - bi.main_state = READ_FSA; - bi.sub_state = INITIALIZE; + m_bi.main_state = READ_FSA; + m_bi.sub_state = INITIALIZE; - read_fsa_continue(bi); + read_fsa_continue(); } -void i7220_device::read_fsa_continue(bubble_info &bi) +void i7220_device::read_fsa_continue() { for (;;) { - switch (bi.sub_state) + switch (m_bi.sub_state) { case INITIALIZE: - bi.sub_state = WAIT_FSA_REPLY; - delay_cycles(bi.tm, m_data_size * 60); // p. 4-16 of BPK72UM + m_bi.sub_state = WAIT_FSA_REPLY; + delay_cycles(m_bi.tm, m_data_size * 60); // p. 4-16 of BPK72UM return; case WAIT_FSA_REPLY: - bi.sub_state = COMMAND_DONE; + m_bi.sub_state = COMMAND_DONE; break; case COMMAND_DONE: @@ -455,113 +450,113 @@ void i7220_device::read_fsa_continue(bubble_info &bi) fifo_push(0x28); // FIFOMT | ECF/F fifo_push(0x28); } - command_end(bi, true); + command_end(true); return; default: - LOG("BMC read fsa unknown sub-state %d\n", bi.sub_state); + LOG("BMC read fsa unknown sub-state %d\n", m_bi.sub_state); return; } } } -void i7220_device::read_data_start(bubble_info &bi) +void i7220_device::read_data_start() { - bi.main_state = READ_DATA; - bi.sub_state = INITIALIZE; + m_bi.main_state = READ_DATA; + m_bi.sub_state = INITIALIZE; - read_data_continue(bi); + read_data_continue(); } -void i7220_device::read_data_continue(bubble_info &bi) +void i7220_device::read_data_continue() { for (;;) { - switch (bi.sub_state) + switch (m_bi.sub_state) { case INITIALIZE: - bi.sub_state = SECTOR_READ; - bi.counter = 0; // 256-bit pages - bi.limit = blr_count * blr_nfc; - fseek((ar_addr * 32 * blr_nfc) + (ar_mbm * I7110_MBM_SIZE) + (bi.counter * 32), SEEK_SET); + m_bi.sub_state = SECTOR_READ; + m_bi.counter = 0; // 256-bit pages + m_bi.limit = m_blr_count * m_blr_nfc; + fseek((m_ar_addr * 32 * m_blr_nfc) + (m_ar_mbm * I7110_MBM_SIZE) + (m_bi.counter * 32), SEEK_SET); break; case SECTOR_READ: - fread(buf, 32); - bi.sub_state = WAIT_FSA_REPLY; - delay_cycles(bi.tm, 270 * 20); // p. 4-14 of BPK72UM + fread(m_buf, 32); + m_bi.sub_state = WAIT_FSA_REPLY; + delay_cycles(m_bi.tm, 270 * 20); // p. 4-14 of BPK72UM break; case WAIT_FSA_REPLY: - LOGDBG("BMC read data: ct %02d limit %02d\n", bi.counter, bi.limit); - if (bi.counter < bi.limit) + LOGDBG("BMC read data: ct %02d limit %02d\n", m_bi.counter, m_bi.limit); + if (m_bi.counter < m_bi.limit) { for (int a = 0; a < 32; a++) - fifo_push(buf[a]); - bi.sub_state = SECTOR_READ; - bi.counter++; - delay_cycles(bi.tm, 270 * 20); // p. 4-14 of BPK72UM + fifo_push(m_buf[a]); + m_bi.sub_state = SECTOR_READ; + m_bi.counter++; + delay_cycles(m_bi.tm, 270 * 20); // p. 4-14 of BPK72UM return; } - bi.sub_state = COMMAND_DONE; + m_bi.sub_state = COMMAND_DONE; break; case COMMAND_DONE: - command_end(bi, true); + command_end(true); return; default: - LOG("BMC read data unknown sub-state %d\n", bi.sub_state); + LOG("BMC read data unknown sub-state %d\n", m_bi.sub_state); return; } } } -void i7220_device::write_data_start(bubble_info &bi) +void i7220_device::write_data_start() { - bi.main_state = WRITE_DATA; - bi.sub_state = INITIALIZE; + m_bi.main_state = WRITE_DATA; + m_bi.sub_state = INITIALIZE; - write_data_continue(bi); + write_data_continue(); } -void i7220_device::write_data_continue(bubble_info &bi) +void i7220_device::write_data_continue() { for (;;) { - switch (bi.sub_state) + switch (m_bi.sub_state) { case INITIALIZE: - bi.sub_state = WAIT_FIFO; - bi.counter = 0; - bi.limit = blr_count * blr_nfc * 32; - delay_cycles(bi.tm, 270 * 20); // p. 4-14 of BPK72UM + m_bi.sub_state = WAIT_FIFO; + m_bi.counter = 0; + m_bi.limit = m_blr_count * m_blr_nfc * 32; + delay_cycles(m_bi.tm, 270 * 20); // p. 4-14 of BPK72UM return; case WAIT_FIFO: - LOGDBG("BMC write data: fifo %02d ct %02d limit %02d\n", m_fifo_size, bi.counter, bi.limit); + LOGDBG("BMC write data: fifo %02d ct %02d limit %02d\n", m_fifo_size, m_bi.counter, m_bi.limit); if (m_fifo_size >= 32) { for (int a = 0; a < 32; a++) - buf[a] = fifo_pop(); - fseek((ar_addr * 32 * blr_nfc) + (ar_mbm * I7110_MBM_SIZE) + bi.counter, SEEK_SET); - fwrite(buf, 32); - bi.counter += 32; + m_buf[a] = fifo_pop(); + fseek((m_ar_addr * 32 * m_blr_nfc) + (m_ar_mbm * I7110_MBM_SIZE) + m_bi.counter, SEEK_SET); + fwrite(m_buf, 32); + m_bi.counter += 32; } - if (bi.counter < bi.limit) + if (m_bi.counter < m_bi.limit) { - delay_cycles(bi.tm, 270 * 20); // p. 4-14 of BPK72UM + delay_cycles(m_bi.tm, 270 * 20); // p. 4-14 of BPK72UM return; } - bi.sub_state = COMMAND_DONE; + m_bi.sub_state = COMMAND_DONE; break; case COMMAND_DONE: - command_end(bi, true); + command_end(true); return; default: - LOG("BMC write data unknown sub-state %d\n", bi.sub_state); + LOG("BMC write data unknown sub-state %d\n", m_bi.sub_state); return; } } @@ -595,10 +590,10 @@ uint8_t i7220_device::read(offs_t offset) case 1: data = m_str; - if (main_phase == PHASE_EXEC) + if (m_main_phase == PHASE_EXEC) { data |= SR_BUSY; - switch (bi.main_state) + switch (m_bi.main_state) { case READ_DATA: if (!m_fifo.empty()) // XXX @@ -623,10 +618,10 @@ uint8_t i7220_device::read(offs_t offset) } } LOGREG("BMC R status == %02x (phase %d state %d:%d fifo %d drq %d)\n", - data, main_phase, bi.main_state, bi.sub_state, m_fifo_size, drq); - if (main_phase == PHASE_RESULT) + data, m_main_phase, m_bi.main_state, m_bi.sub_state, m_fifo_size, m_drq); + if (m_main_phase == PHASE_RESULT) { - main_phase = PHASE_IDLE; + m_main_phase = PHASE_IDLE; } break; } @@ -689,10 +684,10 @@ void i7220_device::write(offs_t offset, uint8_t data) else if (BIT(data, 4)) { m_cmdr = data & 15; - if (main_phase == PHASE_IDLE) + if (m_main_phase == PHASE_IDLE) { LOG("BMC command %02x '%s'\n", data, commands[m_cmdr]); - main_phase = PHASE_CMD; + m_main_phase = PHASE_CMD; start_command(m_cmdr); } } diff --git a/src/devices/machine/i7220.h b/src/devices/machine/i7220.h index 99d8466226c..f961d64559e 100644 --- a/src/devices/machine/i7220.h +++ b/src/devices/machine/i7220.h @@ -67,7 +67,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(general_continue); int m_data_size; @@ -168,34 +169,37 @@ private: void update_drq(); void start_command(int cmd); - void general_continue(bubble_info &bi); - void command_end(bubble_info &bi, bool success); + void command_end(bool success); - void command_fail_start(bubble_info &bi); - void command_fail_continue(bubble_info &bi); + void command_fail_start(); + void command_fail_continue(); - void init_start(bubble_info &bi); - void init_continue(bubble_info &bi); + void init_start(); + void init_continue(); - void read_fsa_start(bubble_info &bi); - void read_fsa_continue(bubble_info &bi); + void read_fsa_start(); + void read_fsa_continue(); - void read_data_start(bubble_info &bi); - void read_data_continue(bubble_info &bi); + void read_data_start(); + void read_data_continue(); - void write_data_start(bubble_info &bi); - void write_data_continue(bubble_info &bi); + void write_data_start(); + void write_data_continue(); void fifo_clear(); void fifo_push(uint8_t val); uint8_t fifo_pop(); - int main_phase; - bool drq, irq; - bubble_info bi; + int m_main_phase; + bool m_drq; + bool m_irq; + bubble_info m_bi; - uint8_t buf[32]; - int blr_count, blr_nfc, ar_addr, ar_mbm; + uint8_t m_buf[32]; + int m_blr_count; + int m_blr_nfc; + int m_ar_addr; + int m_ar_mbm; devcb_write_line intrq_cb; devcb_write_line drq_cb; diff --git a/src/devices/machine/i8087.cpp b/src/devices/machine/i8087.cpp index 30015f0bb0c..4235d734d7e 100644 --- a/src/devices/machine/i8087.cpp +++ b/src/devices/machine/i8087.cpp @@ -209,13 +209,11 @@ void i8087_device::device_start() m_int_handler.resolve_safe(); m_busy_handler.resolve_safe(); - m_int_handler(0); - m_busy_handler(1); - m_timer = timer_alloc(); + m_timer = timer_alloc(FUNC(i8087_device::release_busy), this); build_opcode_table(); } -void i8087_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(i8087_device::release_busy) { m_busy_handler(1); } diff --git a/src/devices/machine/i8087.h b/src/devices/machine/i8087.h index c9bab30b0db..af3dea07f08 100644 --- a/src/devices/machine/i8087.h +++ b/src/devices/machine/i8087.h @@ -26,7 +26,8 @@ protected: i8087_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, u32 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; + + TIMER_CALLBACK_MEMBER(release_busy); private: address_space &space() { return *m_space; } diff --git a/src/devices/machine/i8155.cpp b/src/devices/machine/i8155.cpp index 996faed2f42..fee07c4a919 100644 --- a/src/devices/machine/i8155.cpp +++ b/src/devices/machine/i8155.cpp @@ -321,8 +321,8 @@ void i8155_device::device_start() m_ram = make_unique_clear<uint8_t[]>(256); // allocate timers - m_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(i8155_device::timer_half_counted), this)); - m_timer_tc = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(i8155_device::timer_tc), this)); + m_timer = timer_alloc(FUNC(i8155_device::timer_half_counted), this); + m_timer_tc = timer_alloc(FUNC(i8155_device::timer_tc), this); // register for state saving save_item(NAME(m_io_m)); diff --git a/src/devices/machine/i82357.cpp b/src/devices/machine/i82357.cpp index 80319a8a52a..91de890a03d 100644 --- a/src/devices/machine/i82357.cpp +++ b/src/devices/machine/i82357.cpp @@ -210,7 +210,7 @@ void i82357_device::device_start() m_out_nmi.resolve_safe(); m_out_spkr.resolve_safe(); - m_nmi_check = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(i82357_device::nmi_check), this)); + m_nmi_check = timer_alloc(FUNC(i82357_device::nmi_check), this); } void i82357_device::device_reset() diff --git a/src/devices/machine/i82586.cpp b/src/devices/machine/i82586.cpp index 360d404836c..b95ec84b9a1 100644 --- a/src/devices/machine/i82586.cpp +++ b/src/devices/machine/i82586.cpp @@ -164,7 +164,7 @@ void i82586_base_device::device_start() m_out_irq.resolve_safe(); - m_cu_timer = timer_alloc(CU_TIMER); + m_cu_timer = timer_alloc(FUNC(i82586_base_device::cu_execute), this); m_cu_timer->enable(false); save_item(NAME(m_cx)); @@ -204,16 +204,6 @@ void i82586_base_device::device_reset() m_mac_multi = 0; } -void i82586_base_device::device_timer(emu_timer &timer, device_timer_id id, int param) -{ - switch (id) - { - case CU_TIMER: - cu_execute(); - break; - } -} - device_memory_interface::space_config_vector i82586_base_device::memory_space_config() const { return space_config_vector { @@ -407,7 +397,7 @@ void i82586_base_device::update_scb() set_irq(m_cx || m_fr || m_cna || m_rnr); } -void i82586_base_device::cu_execute() +TIMER_CALLBACK_MEMBER(i82586_base_device::cu_execute) { // fetch the command block command/status const u32 cb_cs = m_space->read_dword(m_cba); diff --git a/src/devices/machine/i82586.h b/src/devices/machine/i82586.h index 65ecff63329..f05547662c6 100644 --- a/src/devices/machine/i82586.h +++ b/src/devices/machine/i82586.h @@ -167,7 +167,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; virtual space_config_vector memory_space_config() const override; // device_network_interface overrides @@ -181,7 +180,7 @@ protected: virtual void update_scb(); // command unit - virtual void cu_execute(); + virtual TIMER_CALLBACK_MEMBER(cu_execute); virtual void cu_complete(const u16 status); virtual bool cu_iasetup() = 0; virtual bool cu_configure() = 0; @@ -211,7 +210,6 @@ protected: address_space *m_space; devcb_write_line m_out_irq; - static const device_timer_id CU_TIMER = 0; emu_timer *m_cu_timer; // interrupt state diff --git a/src/devices/machine/i8271.cpp b/src/devices/machine/i8271.cpp index 70e27fa9bfd..48d734288f4 100644 --- a/src/devices/machine/i8271.cpp +++ b/src/devices/machine/i8271.cpp @@ -47,7 +47,7 @@ void i8271_device::device_start() for(int i=0; i != 2; i++) { char name[2]; - flopi[i].tm = timer_alloc(i); + flopi[i].tm = timer_alloc(FUNC(i8271_device::floppy_tick), this); flopi[i].id = i; if(select_connected) { name[0] = '0'+i; @@ -316,7 +316,7 @@ void i8271_device::live_delay(int state) { cur_live.next_state = state; if(cur_live.tm != machine().time()) - cur_live.fi->tm->adjust(cur_live.tm - machine().time()); + cur_live.fi->tm->adjust(cur_live.tm - machine().time(), cur_live.fi->id); else live_sync(); } @@ -380,7 +380,7 @@ void i8271_device::live_run(attotime limit) // infinity looking for data too. limit = machine().time() + attotime::from_msec(1); - cur_live.fi->tm->adjust(attotime::from_msec(1)); + cur_live.fi->tm->adjust(attotime::from_msec(1), cur_live.fi->id); } } @@ -945,9 +945,9 @@ void i8271_device::seek_start(floppy_info &fi) seek_continue(fi); } -void i8271_device::delay_cycles(emu_timer *tm, int cycles) +void i8271_device::delay_cycles(floppy_info &fi, int cycles) { - tm->adjust(attotime::from_double(double(cycles)/cur_rate)); + fi.tm->adjust(attotime::from_double(double(cycles)/cur_rate), fi.id); } void i8271_device::seek_continue(floppy_info &fi) @@ -960,7 +960,7 @@ void i8271_device::seek_continue(floppy_info &fi) fi.dev->stp_w(0); } fi.sub_state = SEEK_WAIT_STEP_SIGNAL_TIME; - fi.tm->adjust(attotime::from_nsec(2500)); + fi.tm->adjust(attotime::from_nsec(2500), fi.id); return; case SEEK_WAIT_STEP_SIGNAL_TIME: @@ -977,7 +977,7 @@ void i8271_device::seek_continue(floppy_info &fi) fi.pcn++; } while((fi.pcn == fi.badtrack[0]) || (fi.pcn == fi.badtrack[1])); fi.sub_state = SEEK_WAIT_STEP_TIME; - delay_cycles(fi.tm, 500*srate); + delay_cycles(fi, 500*srate); return; case SEEK_WAIT_STEP_TIME: @@ -1115,7 +1115,7 @@ void i8271_device::read_data_continue(floppy_info &fi) fi.dev->stp_w(0); } fi.sub_state = SEEK_WAIT_STEP_SIGNAL_TIME; - fi.tm->adjust(attotime::from_nsec(2500)); + fi.tm->adjust(attotime::from_nsec(2500), fi.id); return; case SEEK_WAIT_STEP_SIGNAL_TIME: @@ -1126,7 +1126,7 @@ void i8271_device::read_data_continue(floppy_info &fi) fi.dev->stp_w(1); fi.sub_state = SEEK_WAIT_STEP_TIME; - delay_cycles(fi.tm, 500*srate); + delay_cycles(fi, 500*srate); return; case SEEK_WAIT_STEP_TIME: @@ -1256,7 +1256,7 @@ void i8271_device::write_data_continue(floppy_info &fi) fi.dev->stp_w(0); } fi.sub_state = SEEK_WAIT_STEP_SIGNAL_TIME; - fi.tm->adjust(attotime::from_nsec(2500)); + fi.tm->adjust(attotime::from_nsec(2500), fi.id); return; case SEEK_WAIT_STEP_SIGNAL_TIME: @@ -1267,7 +1267,7 @@ void i8271_device::write_data_continue(floppy_info &fi) fi.dev->stp_w(1); fi.sub_state = SEEK_WAIT_STEP_TIME; - delay_cycles(fi.tm, 500*srate); + delay_cycles(fi, 500*srate); return; case SEEK_WAIT_STEP_TIME: @@ -1383,7 +1383,7 @@ void i8271_device::format_track_continue(floppy_info &fi) fi.dev->stp_w(0); } fi.sub_state = SEEK_WAIT_STEP_SIGNAL_TIME; - fi.tm->adjust(attotime::from_nsec(2500)); + fi.tm->adjust(attotime::from_nsec(2500), fi.id); return; case SEEK_WAIT_STEP_SIGNAL_TIME: @@ -1394,7 +1394,7 @@ void i8271_device::format_track_continue(floppy_info &fi) fi.dev->stp_w(1); fi.sub_state = SEEK_WAIT_STEP_TIME; - delay_cycles(fi.tm, 500*srate); + delay_cycles(fi, 500*srate); return; case SEEK_WAIT_STEP_TIME: @@ -1476,7 +1476,7 @@ void i8271_device::read_id_continue(floppy_info &fi) fi.dev->stp_w(0); } fi.sub_state = SEEK_WAIT_STEP_SIGNAL_TIME; - fi.tm->adjust(attotime::from_nsec(2500)); + fi.tm->adjust(attotime::from_nsec(2500), fi.id); return; case SEEK_WAIT_STEP_SIGNAL_TIME: @@ -1487,7 +1487,7 @@ void i8271_device::read_id_continue(floppy_info &fi) fi.dev->stp_w(1); fi.sub_state = SEEK_WAIT_STEP_TIME; - delay_cycles(fi.tm, 500*srate); + delay_cycles(fi, 500*srate); return; case SEEK_WAIT_STEP_TIME: @@ -1546,11 +1546,11 @@ std::string i8271_device::ttsn() const return machine().time().to_string(); } -void i8271_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(i8271_device::floppy_tick) { live_sync(); - floppy_info &fi = flopi[id]; + floppy_info &fi = flopi[param]; switch(fi.sub_state) { case SEEK_WAIT_STEP_SIGNAL_TIME: fi.sub_state = SEEK_WAIT_STEP_SIGNAL_TIME_DONE; diff --git a/src/devices/machine/i8271.h b/src/devices/machine/i8271.h index c337ac98df4..92880af57d4 100644 --- a/src/devices/machine/i8271.h +++ b/src/devices/machine/i8271.h @@ -44,7 +44,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(floppy_tick); private: enum { @@ -234,7 +235,7 @@ private: void cmd_w(uint8_t data); void param_w(uint8_t data); - void delay_cycles(emu_timer *tm, int cycles); + void delay_cycles(floppy_info &fi, int cycles); void set_drq(bool state); void set_irq(bool state); bool get_ready(int fid); diff --git a/src/devices/machine/i8279.cpp b/src/devices/machine/i8279.cpp index 474dfbbf170..9de96d806e0 100644 --- a/src/devices/machine/i8279.cpp +++ b/src/devices/machine/i8279.cpp @@ -120,7 +120,7 @@ void i8279_device::device_start() m_in_shift_cb.resolve(); m_in_ctrl_cb.resolve(); m_scanclock = clock(); - m_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(i8279_device::timerproc_callback), this)); + m_timer = timer_alloc(FUNC(i8279_device::timerproc_callback), this); // save state save_item(NAME(m_d_ram)); diff --git a/src/devices/machine/ibm21s850.cpp b/src/devices/machine/ibm21s850.cpp index cd44591645c..c58622cace6 100644 --- a/src/devices/machine/ibm21s850.cpp +++ b/src/devices/machine/ibm21s850.cpp @@ -43,7 +43,7 @@ void ibm21s85x_base_device::device_start() { save_item(NAME(m_regs)); - m_reset_timer = timer_alloc(TIMER_RESET); + m_reset_timer = timer_alloc(FUNC(ibm21s85x_base_device::reset_tick), this); m_reset_cb.resolve_safe(); } @@ -81,20 +81,17 @@ void ibm21s851_device::device_reset() m_regs[REG_COUNT_OFFS] |= 0x0b; // 11 registers following the standard block on 21S851 } -void ibm21s85x_base_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(ibm21s85x_base_device::reset_tick) { - if (id == TIMER_RESET) + if (param) { - if (param) - { - m_reset_cb(0); - m_reset_timer->adjust(attotime::never); - } - else - { - m_reset_cb(1); - m_reset_timer->adjust(attotime::from_usec(26266), 1); // RC reset circuit, 3.3V in, 2.3V out, 10KOhm resistor, 2.2uF capacitor - } + m_reset_cb(0); + m_reset_timer->adjust(attotime::never); + } + else + { + m_reset_cb(1); + m_reset_timer->adjust(attotime::from_usec(26266), 1); // RC reset circuit, 3.3V in, 2.3V out, 10KOhm resistor, 2.2uF capacitor } } diff --git a/src/devices/machine/ibm21s850.h b/src/devices/machine/ibm21s850.h index e0725a7cbd3..dde6cf59a4d 100644 --- a/src/devices/machine/ibm21s850.h +++ b/src/devices/machine/ibm21s850.h @@ -30,11 +30,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; - void power_on_reset(); + TIMER_CALLBACK_MEMBER(reset_tick); - static const device_timer_id TIMER_RESET = 0; + void power_on_reset(); enum : uint32_t { diff --git a/src/devices/machine/icm7170.cpp b/src/devices/machine/icm7170.cpp index 3960545ee94..3abcf04ea38 100644 --- a/src/devices/machine/icm7170.cpp +++ b/src/devices/machine/icm7170.cpp @@ -60,8 +60,6 @@ enum IRQ_BIT_ALARM = 0x01 }; -static constexpr int ICM7170_TIMER_ID = 0; - //************************************************************************** // LIVE DEVICE //************************************************************************** @@ -88,7 +86,7 @@ void icm7170_device::device_start() // resolve callbacks m_out_irq_cb.resolve_safe(); - m_timer = timer_alloc(ICM7170_TIMER_ID); + m_timer = timer_alloc(FUNC(icm7170_device::clock_tick), this); // TODO: frequency should be based on input clock and divisor m_timer->adjust(attotime::from_hz(100), 0, attotime::from_hz(100)); @@ -110,10 +108,10 @@ void icm7170_device::device_reset() } //------------------------------------------------- -// device_timer - handles timer events +// clock_tick - advance the RTC's counters //------------------------------------------------- -void icm7170_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(icm7170_device::clock_tick) { // advance hundredths m_irq_status |= IRQ_BIT_100TH_SECOND; @@ -122,11 +120,11 @@ void icm7170_device::device_timer(emu_timer &timer, device_timer_id id, int para m_regs[REG_CNT_100TH_SEC] = 0; if (m_regs[REG_COMMAND] & CMD_REG_24_HOUR) - LOG("device_timer %02d-%02d-%02d %02d:%02d:%02d\n", + LOG("clock_tick %02d-%02d-%02d %02d:%02d:%02d\n", m_regs[REG_CNT_YEAR], m_regs[REG_CNT_MONTH], m_regs[REG_CNT_DAY], m_regs[REG_CNT_HOURS], m_regs[REG_CNT_MINUTES], m_regs[REG_CNT_SECONDS]); else - LOG("device_timer %02d-%02d-%02d %02d:%02d:%02d %s\n", + LOG("clock_tick %02d-%02d-%02d %02d:%02d:%02d %s\n", m_regs[REG_CNT_YEAR], m_regs[REG_CNT_MONTH], m_regs[REG_CNT_DAY], m_regs[REG_CNT_HOURS] & 0xf, m_regs[REG_CNT_MINUTES], m_regs[REG_CNT_SECONDS], (m_regs[REG_CNT_HOURS] & 0x80) ? "pm" : "am"); diff --git a/src/devices/machine/icm7170.h b/src/devices/machine/icm7170.h index 384dd00af8b..2fef930fa04 100644 --- a/src/devices/machine/icm7170.h +++ b/src/devices/machine/icm7170.h @@ -61,7 +61,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; @@ -71,6 +70,8 @@ protected: virtual bool nvram_read(util::read_stream &file) override; virtual bool nvram_write(util::write_stream &file) override; + TIMER_CALLBACK_MEMBER(clock_tick); + private: void recalc_irqs(); diff --git a/src/devices/machine/ie15.cpp b/src/devices/machine/ie15.cpp index a8a77900e51..603c6034ca9 100644 --- a/src/devices/machine/ie15.cpp +++ b/src/devices/machine/ie15.cpp @@ -166,7 +166,7 @@ void ie15_device::beep_w(uint8_t data) { LOG("beep (%s)\n", m_long_beep ? "short" : "long"); } - machine().scheduler().timer_set(attotime::from_msec(length), timer_expired_delegate(FUNC(ie15_device::ie15_beepoff),this)); + m_beepoff_timer->adjust(attotime::from_msec(length)); m_beeper->set_state(1); } @@ -229,28 +229,23 @@ uint8_t ie15_device::kb_s_lin_r() return m_io_keyboard->read() & ie15_keyboard_device::IE_KB_LIN ? IE_TRUE : 0; } -/* serial port */ - -void ie15_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(ie15_device::hblank_onoff_tick) { - switch (id) + if (m_hblank) // Transitioning from in blanking to out of blanking { - case TIMER_HBLANK: - if (m_hblank) // Transitioning from in blanking to out of blanking - { - m_hblank = 0; - m_hblank_timer->adjust(m_screen->time_until_pos((m_vpos + 1) % IE15_TOTAL_VERT, 0)); - scanline_callback(); - } - else // Transitioning from out of blanking to in blanking - { - m_hblank = 1; - m_hblank_timer->adjust(m_screen->time_until_pos(m_vpos, IE15_HORZ_START)); - } - break; + m_hblank = 0; + m_hblank_timer->adjust(m_screen->time_until_pos((m_vpos + 1) % IE15_TOTAL_VERT, 0)); + scanline_callback(); + } + else // Transitioning from out of blanking to in blanking + { + m_hblank = 1; + m_hblank_timer->adjust(m_screen->time_until_pos(m_vpos, IE15_HORZ_START)); } } +/* serial port */ + WRITE_LINE_MEMBER(ie15_device::rs232_conn_rxd_w) { device_serial_interface::rx_w(state); @@ -494,9 +489,10 @@ void ie15_device::device_start() m_sdv_led.resolve(); m_prd_led.resolve(); - m_hblank_timer = timer_alloc(TIMER_HBLANK); + m_hblank_timer = timer_alloc(FUNC(ie15_device::hblank_onoff_tick), this); m_hblank_timer->adjust(attotime::never); + m_beepoff_timer = timer_alloc(FUNC(ie15_device::ie15_beepoff), this); m_video.ptr1 = m_video.ptr2 = m_latch = 0; m_tmpbmp = std::make_unique<uint32_t[]>(IE15_TOTAL_HORZ * IE15_TOTAL_VERT); diff --git a/src/devices/machine/ie15.h b/src/devices/machine/ie15.h index 496874c5a86..89eaf0cfd8b 100644 --- a/src/devices/machine/ie15.h +++ b/src/devices/machine/ie15.h @@ -56,18 +56,18 @@ 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 void device_add_mconfig(machine_config &config) override; virtual ioport_constructor device_input_ports() const override; virtual const tiny_rom_entry *device_rom_region() const override; + TIMER_CALLBACK_MEMBER(hblank_onoff_tick); + virtual void rcv_complete() override; virtual void tra_callback() override; virtual void tra_complete() override; private: - static const device_timer_id TIMER_HBLANK = 0; void scanline_callback(); void update_leds(); void draw_scanline(uint32_t *p, uint16_t offset, uint8_t scanline); @@ -106,32 +106,33 @@ private: std::unique_ptr<uint32_t[]> m_tmpbmp; - emu_timer *m_hblank_timer; + emu_timer *m_hblank_timer = nullptr; + emu_timer *m_beepoff_timer = nullptr; - uint8_t m_long_beep; - uint8_t m_kb_control; - uint8_t m_kb_data; - uint8_t m_kb_flag0; - uint8_t m_kb_flag; - uint8_t m_kb_ruslat; - uint8_t m_latch; + uint8_t m_long_beep = 0; + uint8_t m_kb_control = 0; + uint8_t m_kb_data = 0; + uint8_t m_kb_flag0 = 0; + uint8_t m_kb_flag = 0; + uint8_t m_kb_ruslat = 0; + uint8_t m_latch = 0; struct { - uint8_t cursor; - uint8_t enable; - uint8_t line25; - uint32_t ptr1; - uint32_t ptr2; + uint8_t cursor = 0; + uint8_t enable = 0; + uint8_t line25 = 0; + uint32_t ptr1 = 0; + uint32_t ptr2 = 0; } m_video; - uint8_t m_serial_rx_ready; - uint8_t m_serial_rx_char; - uint8_t m_serial_tx_ready; - int m_hblank; - int m_vpos; - int m_marker_scanline; - bool m_kbd_sdv; + uint8_t m_serial_rx_ready = 0; + uint8_t m_serial_rx_char = 0; + uint8_t m_serial_tx_ready = 0; + int m_hblank = 0; + int m_vpos = 0; + int m_marker_scanline = 0; + bool m_kbd_sdv = 0; required_device<cpu_device> m_maincpu; required_region_ptr<u8> m_p_videoram; diff --git a/src/devices/machine/ins8250.cpp b/src/devices/machine/ins8250.cpp index 0d766619254..63a68550e2d 100644 --- a/src/devices/machine/ins8250.cpp +++ b/src/devices/machine/ins8250.cpp @@ -689,7 +689,7 @@ void ins8250_uart_device::device_reset() void ns16550_device::device_start() { - m_timeout = timer_alloc(); + m_timeout = timer_alloc(FUNC(ns16550_device::timeout_expired), this); ins8250_uart_device::device_start(); save_item(NAME(m_rintlvl)); save_item(NAME(m_rfifo)); @@ -713,13 +713,10 @@ void ns16550_device::device_reset() ins8250_uart_device::device_reset(); } -void ns16550_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(ns16550_device::timeout_expired) { - if(!id) - { - trigger_int(COM_INT_PENDING_CHAR_TIMEOUT); - m_timeout->adjust(attotime::never); - } + trigger_int(COM_INT_PENDING_CHAR_TIMEOUT); + m_timeout->adjust(attotime::never); } void ns16550_device::push_tx(u8 data) diff --git a/src/devices/machine/ins8250.h b/src/devices/machine/ins8250.h index b40ff23ef65..f79715decc3 100644 --- a/src/devices/machine/ins8250.h +++ b/src/devices/machine/ins8250.h @@ -117,12 +117,14 @@ public: protected: virtual void device_start() override; virtual void device_reset() override; + virtual void rcv_complete() override; virtual void tra_complete() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; virtual void set_fcr(u8 data) override; virtual void push_tx(u8 data) override; virtual u8 pop_rx() override; + + TIMER_CALLBACK_MEMBER(timeout_expired); private: void set_timer() { m_timeout->adjust(attotime::from_hz((clock()*4*8)/(m_regs.dl*16))); } int m_rintlvl; diff --git a/src/devices/machine/intelfsh.cpp b/src/devices/machine/intelfsh.cpp index abbee1b0a39..9c4b86abe21 100644 --- a/src/devices/machine/intelfsh.cpp +++ b/src/devices/machine/intelfsh.cpp @@ -531,7 +531,7 @@ tms_29f040_device::tms_29f040_device(const machine_config &mconfig, const char * void intelfsh_device::device_start() { m_data = std::make_unique<uint8_t []>(m_size); - m_timer = timer_alloc(); + m_timer = timer_alloc(FUNC(intelfsh_device::delay_tick), this); save_item( NAME(m_status) ); save_item( NAME(m_flash_mode) ); @@ -541,10 +541,10 @@ void intelfsh_device::device_start() //------------------------------------------------- -// device_timer - handler timer events +// delay_tick - handle delayed commands/events //------------------------------------------------- -void intelfsh_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(intelfsh_device::delay_tick) { switch( m_flash_mode ) { diff --git a/src/devices/machine/intelfsh.h b/src/devices/machine/intelfsh.h index 7752a6d8379..31f1475cf90 100644 --- a/src/devices/machine/intelfsh.h +++ b/src/devices/machine/intelfsh.h @@ -66,7 +66,6 @@ protected: // device-level overrides virtual void device_start() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; // device_nvram_interface overrides virtual void nvram_default() override; @@ -77,6 +76,8 @@ protected: uint32_t read_full(uint32_t offset); void write_full(uint32_t offset, uint32_t data); + TIMER_CALLBACK_MEMBER(delay_tick); + optional_memory_region m_region; // configuration state diff --git a/src/devices/machine/iopsio2.cpp b/src/devices/machine/iopsio2.cpp index 6ffe90c0737..c5b6de09546 100644 --- a/src/devices/machine/iopsio2.cpp +++ b/src/devices/machine/iopsio2.cpp @@ -32,7 +32,7 @@ iop_sio2_device::~iop_sio2_device() void iop_sio2_device::device_start() { if (!m_response_timer) - m_response_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(iop_sio2_device::response_timer), this)); + m_response_timer = timer_alloc(FUNC(iop_sio2_device::response_timer), this); save_item(NAME(m_buffer)); save_item(NAME(m_curr_byte)); diff --git a/src/devices/machine/ioptimer.cpp b/src/devices/machine/ioptimer.cpp index 487c795ef26..54864a00901 100644 --- a/src/devices/machine/ioptimer.cpp +++ b/src/devices/machine/ioptimer.cpp @@ -39,10 +39,10 @@ void iop_timer_device::device_start() m_int_cb.resolve_safe(); if (!m_compare_timer) - m_compare_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(iop_timer_device::compare), this)); + m_compare_timer = timer_alloc(FUNC(iop_timer_device::compare), this); if (!m_overflow_timer) - m_overflow_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(iop_timer_device::overflow), this)); + m_overflow_timer = timer_alloc(FUNC(iop_timer_device::overflow), this); } void iop_timer_device::device_reset() diff --git a/src/devices/machine/iwm.cpp b/src/devices/machine/iwm.cpp index 331305dab4f..b52c01eec83 100644 --- a/src/devices/machine/iwm.cpp +++ b/src/devices/machine/iwm.cpp @@ -34,7 +34,7 @@ void iwm_device::device_start() { applefdintf_device::device_start(); - m_timer = timer_alloc(); + m_timer = timer_alloc(FUNC(iwm_device::update_timer_tick), this); save_item(NAME(m_last_sync)); save_item(NAME(m_next_state_change)); save_item(NAME(m_sync_update)); @@ -82,7 +82,7 @@ void iwm_device::device_reset() m_q3_clock_active = false; } -void iwm_device::device_timer(emu_timer &, device_timer_id, int) +TIMER_CALLBACK_MEMBER(iwm_device::update_timer_tick) { if(m_active == MODE_DELAY) { flush_write(); diff --git a/src/devices/machine/iwm.h b/src/devices/machine/iwm.h index c4f13c09e6d..73045890d0d 100644 --- a/src/devices/machine/iwm.h +++ b/src/devices/machine/iwm.h @@ -37,7 +37,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(update_timer_tick); private: enum { diff --git a/src/devices/machine/kb3600.cpp b/src/devices/machine/kb3600.cpp index c0e450f601a..9be5846e0c8 100644 --- a/src/devices/machine/kb3600.cpp +++ b/src/devices/machine/kb3600.cpp @@ -82,7 +82,7 @@ void ay3600_device::device_start() m_write_ako.resolve_safe(); // allocate timers - m_scan_timer = timer_alloc(); + m_scan_timer = timer_alloc(FUNC(ay3600_device::perform_scan), this); m_scan_timer->adjust(attotime::from_hz(60), 0, attotime::from_hz(60)); m_ako = 0; @@ -103,10 +103,10 @@ void ay3600_device::device_reset() } //------------------------------------------------- -// device_timer - handler timer events +// perform_scan - scan the keyboard matrix //------------------------------------------------- -void ay3600_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(ay3600_device::perform_scan) { int ako = 0; diff --git a/src/devices/machine/kb3600.h b/src/devices/machine/kb3600.h index 35a2a192a5c..c65bbea3a6f 100644 --- a/src/devices/machine/kb3600.h +++ b/src/devices/machine/kb3600.h @@ -83,7 +83,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(perform_scan); devcb_read16 m_read_x0, m_read_x1, m_read_x2, m_read_x3, m_read_x4, m_read_x5, m_read_x6, m_read_x7, m_read_x8; devcb_read_line m_read_shift, m_read_control; diff --git a/src/devices/machine/kr2376.cpp b/src/devices/machine/kr2376.cpp index 8f6b6a4b4fd..f77bf3d93dc 100644 --- a/src/devices/machine/kr2376.cpp +++ b/src/devices/machine/kr2376.cpp @@ -158,7 +158,7 @@ void kr2376_device::device_start() change_output_lines(); /* create the timers */ - m_scan_timer = timer_alloc(TIMER_SCAN_TICK); + m_scan_timer = timer_alloc(FUNC(kr2376_device::perform_scan), this); m_scan_timer->adjust(attotime::zero, 0, attotime::from_hz(clock())); /* register for state saving */ @@ -263,16 +263,11 @@ void kr2376_device::detect_keypress() } } -void kr2376_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(kr2376_device::perform_scan) { - switch (id) - { - case TIMER_SCAN_TICK: - change_output_lines(); - clock_scan_counters(); - detect_keypress(); - break; - } + change_output_lines(); + clock_scan_counters(); + detect_keypress(); } /* Keyboard Data */ diff --git a/src/devices/machine/kr2376.h b/src/devices/machine/kr2376.h index 9b9715a8742..6f8306bb30d 100644 --- a/src/devices/machine/kr2376.h +++ b/src/devices/machine/kr2376.h @@ -71,9 +71,10 @@ public: protected: // device-level overrides virtual void device_start() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; virtual uint8_t key_codes(int mode, int x, int y) { return 0x00; } + TIMER_CALLBACK_MEMBER(perform_scan); + private: // internal state int m_pins[41]; @@ -92,11 +93,6 @@ private: devcb_read_line m_read_shift, m_read_control; devcb_write_line m_write_strobe; - enum - { - TIMER_SCAN_TICK - }; - void change_output_lines(); void clock_scan_counters(); void detect_keypress(); diff --git a/src/devices/machine/laserdsc.cpp b/src/devices/machine/laserdsc.cpp index 45304a428f7..596d8689f68 100644 --- a/src/devices/machine/laserdsc.cpp +++ b/src/devices/machine/laserdsc.cpp @@ -226,6 +226,9 @@ void laserdisc_device::device_start() init_video(); init_audio(); + // register our timer + m_vbi_fetch_timer = timer_alloc(FUNC(laserdisc_device::fetch_vbi_data), this); + // register callbacks machine().configuration().config_register( "laserdisc", @@ -349,35 +352,30 @@ void laserdisc_device::device_validity_check(validity_checker &valid) const { } + //------------------------------------------------- -// device_timer - handle timers set by this -// device +// fetch_vbi_data - perform an update and +// process the track that was read, including +// VBI data //------------------------------------------------- -void laserdisc_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(laserdisc_device::fetch_vbi_data) { - switch (id) - { - case TID_VBI_FETCH: - { - // wait for previous read and decode to finish - process_track_data(); + // wait for previous read and decode to finish + process_track_data(); - // update current track based on slider speed - update_slider_pos(); + // update current track based on slider speed + update_slider_pos(); - // update the state - add_and_clamp_track(player_update(m_metadata[m_fieldnum], m_fieldnum, machine().time())); + // update the state + add_and_clamp_track(player_update(m_metadata[m_fieldnum], m_fieldnum, machine().time())); - // flush any audio before we read more - m_stream->update(); + // flush any audio before we read more + m_stream->update(); - // start reading the track data for the next round - m_fieldnum ^= 1; - read_track_data(); - break; - } - } + // start reading the track data for the next round + m_fieldnum ^= 1; + read_track_data(); } @@ -948,8 +946,8 @@ void laserdisc_device::vblank_state_changed(screen_device &screen, bool vblank_s // call the player's VSYNC callback player_vsync(m_metadata[m_fieldnum], m_fieldnum, machine().time()); - // set a timer to begin fetching the next frame just before the VBI data would be fetched - timer_set(screen.time_until_pos(16*2), TID_VBI_FETCH); + // set our timer to begin fetching the next frame just before the VBI data would be fetched + m_vbi_fetch_timer->adjust(screen.time_until_pos(16*2)); } } diff --git a/src/devices/machine/laserdsc.h b/src/devices/machine/laserdsc.h index 15a107804f1..abc536a3be0 100644 --- a/src/devices/machine/laserdsc.h +++ b/src/devices/machine/laserdsc.h @@ -150,13 +150,6 @@ public: } protected: - // timer IDs - enum - { - TID_VBI_FETCH, - TID_FIRST_PLAYER_TIMER - }; - // common laserdisc states enum player_state : uint32_t { @@ -218,12 +211,13 @@ protected: virtual void device_start() override; virtual void device_stop() override; virtual void device_reset() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; virtual void device_validity_check(validity_checker &valid) const override; // device_sound_interface overrides virtual void sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) override; + virtual TIMER_CALLBACK_MEMBER(fetch_vbi_data); + // subclass helpers void set_audio_squelch(bool squelchleft, bool squelchright) { m_stream->update(); m_audiosquelch = (squelchleft ? 1 : 0) | (squelchright ? 2 : 0); } void set_video_squelch(bool squelch) { m_videosquelch = squelch; } @@ -241,6 +235,8 @@ protected: player_state_info m_player_state; // active state player_state_info m_saved_state; // saved state during temporary operations + emu_timer *m_vbi_fetch_timer; // fetcher for our VBI data + private: // internal type definitions struct frame_data diff --git a/src/devices/machine/ldpr8210.cpp b/src/devices/machine/ldpr8210.cpp index 360b7d93a45..a51d84b19ea 100644 --- a/src/devices/machine/ldpr8210.cpp +++ b/src/devices/machine/ldpr8210.cpp @@ -276,6 +276,10 @@ void pioneer_pr8210_device::control_w(uint8_t data) void pioneer_pr8210_device::device_start() { + // alocate timers + m_process_vbi_timer = timer_alloc(FUNC(pioneer_pr8210_device::process_vbi_data), this); + m_vsync_off_timer = timer_alloc(FUNC(pioneer_pr8210_device::vsync_off), this); + // resolve outputs m_audio1.resolve(); m_audio2.resolve(); @@ -312,71 +316,66 @@ void pioneer_pr8210_device::device_reset() //------------------------------------------------- -// device_timer - handle timers set by this -// device +// process_vbi_data - process VBI data which was +// fetched by the parent device //------------------------------------------------- -void pioneer_pr8210_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(pioneer_pr8210_device::process_vbi_data) { - switch (id) + // update the VBI data in the PIA as soon as it is ready; + // this must happen early in the frame because the player + // logic relies on fetching it here + + // logging + if (LOG_VBLANK_VBI) { - // update the VBI data in the PIA as soon as it is ready; - // this must happen early in the frame because the player - // logic relies on fetching it here - case TID_VBI_DATA_FETCH: + uint32_t line1718 = get_field_code(LASERDISC_CODE_LINE1718, false); + if ((line1718 & VBI_MASK_CAV_PICTURE) == VBI_CODE_CAV_PICTURE) + logerror("%3d:VBI(%05d)\n", screen().vpos(), VBI_CAV_PICTURE(line1718)); + else + logerror("%3d:VBI()\n", screen().vpos()); + } - // logging - if (LOG_VBLANK_VBI) - { - uint32_t line1718 = get_field_code(LASERDISC_CODE_LINE1718, false); - if ((line1718 & VBI_MASK_CAV_PICTURE) == VBI_CODE_CAV_PICTURE) - logerror("%3d:VBI(%05d)\n", screen().vpos(), VBI_CAV_PICTURE(line1718)); - else - logerror("%3d:VBI()\n", screen().vpos()); - } + // update PIA registers based on vbi code + m_pia.vbi1 = 0xff; + m_pia.vbi2 = 0xff; + if (focus_on() && laser_on()) + { + uint32_t line16 = get_field_code(LASERDISC_CODE_LINE16, false); + uint32_t line1718 = get_field_code(LASERDISC_CODE_LINE1718, false); + if (line1718 == VBI_CODE_LEADIN) + m_pia.vbi1 &= ~0x01; + if (line1718 == VBI_CODE_LEADOUT) + m_pia.vbi1 &= ~0x02; + if (line16 == VBI_CODE_STOP) + m_pia.vbi1 &= ~0x04; + // unsure what this bit means: m_pia.vbi1 &= ~0x08; + if ((line1718 & VBI_MASK_CAV_PICTURE) == VBI_CODE_CAV_PICTURE) + { + m_pia.vbi1 &= ~0x10; + m_pia.frame[2] = 0xf0 | ((line1718 >> 16) & 0x07); + m_pia.frame[3] = 0xf0 | ((line1718 >> 12) & 0x0f); + m_pia.frame[4] = 0xf0 | ((line1718 >> 8) & 0x0f); + m_pia.frame[5] = 0xf0 | ((line1718 >> 4) & 0x0f); + m_pia.frame[6] = 0xf0 | ((line1718 >> 0) & 0x0f); + } + if ((line1718 & VBI_MASK_CHAPTER) == VBI_CODE_CHAPTER) + { + m_pia.vbi2 &= ~0x01; + m_pia.frame[0] = 0xf0 | ((line1718 >> 16) & 0x07); + m_pia.frame[1] = 0xf0 | ((line1718 >> 12) & 0x0f); + } + } +} - // update PIA registers based on vbi code - m_pia.vbi1 = 0xff; - m_pia.vbi2 = 0xff; - if (focus_on() && laser_on()) - { - uint32_t line16 = get_field_code(LASERDISC_CODE_LINE16, false); - uint32_t line1718 = get_field_code(LASERDISC_CODE_LINE1718, false); - if (line1718 == VBI_CODE_LEADIN) - m_pia.vbi1 &= ~0x01; - if (line1718 == VBI_CODE_LEADOUT) - m_pia.vbi1 &= ~0x02; - if (line16 == VBI_CODE_STOP) - m_pia.vbi1 &= ~0x04; - // unsure what this bit means: m_pia.vbi1 &= ~0x08; - if ((line1718 & VBI_MASK_CAV_PICTURE) == VBI_CODE_CAV_PICTURE) - { - m_pia.vbi1 &= ~0x10; - m_pia.frame[2] = 0xf0 | ((line1718 >> 16) & 0x07); - m_pia.frame[3] = 0xf0 | ((line1718 >> 12) & 0x0f); - m_pia.frame[4] = 0xf0 | ((line1718 >> 8) & 0x0f); - m_pia.frame[5] = 0xf0 | ((line1718 >> 4) & 0x0f); - m_pia.frame[6] = 0xf0 | ((line1718 >> 0) & 0x0f); - } - if ((line1718 & VBI_MASK_CHAPTER) == VBI_CODE_CHAPTER) - { - m_pia.vbi2 &= ~0x01; - m_pia.frame[0] = 0xf0 | ((line1718 >> 16) & 0x07); - m_pia.frame[1] = 0xf0 | ((line1718 >> 12) & 0x0f); - } - } - break; - // clear the VSYNC flag - case TID_VSYNC_OFF: - m_vsync = false; - break; +//------------------------------------------------- +// vsync_off - clear the VSYNC flag +//------------------------------------------------- - // pass everything else onto the parent - default: - laserdisc_device::device_timer(timer, id, param); - break; - } +TIMER_CALLBACK_MEMBER(pioneer_pr8210_device::vsync_off) +{ + m_vsync = false; } @@ -425,10 +424,10 @@ void pioneer_pr8210_device::player_vsync(const vbi_metadata &vbi, int fieldnum, // signal VSYNC and set a timer to turn it off m_vsync = true; - timer_set(screen().scan_period() * 4, TID_VSYNC_OFF); + m_vsync_off_timer->adjust(screen().scan_period() * 4); // also set a timer to fetch the VBI data when it is ready - timer_set(screen().time_until_pos(19*2), TID_VBI_DATA_FETCH); + m_process_vbi_timer->adjust(screen().time_until_pos(19*2)); } @@ -905,7 +904,7 @@ simutrek_special_device::simutrek_special_device(const machine_config &mconfig, void simutrek_special_device::data_w(uint8_t data) { - synchronize(TID_LATCH_DATA, data); + m_latch_data_timer->adjust(attotime::zero, data); if (LOG_SIMUTREK) logerror("%03d:**** Simutrek Command = %02X\n", screen().vpos(), data); } @@ -950,7 +949,7 @@ void simutrek_special_device::player_vsync(const vbi_metadata &vbi, int fieldnum if (LOG_SIMUTREK) logerror("%3d:VSYNC IRQ\n", screen().vpos()); m_i8748_cpu->set_input_line(MCS48_INPUT_IRQ, ASSERT_LINE); - timer_set(screen().scan_period(), TID_IRQ_OFF); + m_irq_off_timer->adjust(screen().scan_period()); } } @@ -961,6 +960,10 @@ void simutrek_special_device::player_vsync(const vbi_metadata &vbi, int fieldnum void simutrek_special_device::device_start() { + // alocate timers + m_irq_off_timer = timer_alloc(FUNC(simutrek_special_device::irq_off), this); + m_latch_data_timer = timer_alloc(FUNC(simutrek_special_device::latch_data), this); + // pass through to the parent pioneer_pr8210_device::device_start(); } @@ -982,30 +985,23 @@ void simutrek_special_device::device_reset() //------------------------------------------------- -// device_timer - handle timers set by this -// device +// irq_off - clear the 8748 IRQ //------------------------------------------------- -void simutrek_special_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(simutrek_special_device::irq_off) { - switch (id) - { - // clear the 8748 IRQ - case TID_IRQ_OFF: - m_i8748_cpu->set_input_line(MCS48_INPUT_IRQ, CLEAR_LINE); - break; + m_i8748_cpu->set_input_line(MCS48_INPUT_IRQ, CLEAR_LINE); +} - // latch data - case TID_LATCH_DATA: - m_data = param; - m_data_ready = true; - break; - // pass everything else onto the parent - default: - pioneer_pr8210_device::device_timer(timer, id, param); - break; - } +//------------------------------------------------- +// latch_data - perform delayed latching of data +//------------------------------------------------- + +TIMER_CALLBACK_MEMBER(simutrek_special_device::latch_data) +{ + m_data = param; + m_data_ready = true; } diff --git a/src/devices/machine/ldpr8210.h b/src/devices/machine/ldpr8210.h index 79453d5604b..4bc4615c03c 100644 --- a/src/devices/machine/ldpr8210.h +++ b/src/devices/machine/ldpr8210.h @@ -44,20 +44,11 @@ public: void control_w(uint8_t data); protected: - // timer IDs - enum - { - TID_VSYNC_OFF = TID_FIRST_PLAYER_TIMER, - TID_VBI_DATA_FETCH, - TID_FIRST_SUBCLASS_TIMER - }; - pioneer_pr8210_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock); // device-level overrides virtual void device_start() override; virtual void device_reset() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; virtual const tiny_rom_entry *device_rom_region() const override; virtual void device_add_mconfig(machine_config &config) override; @@ -67,6 +58,8 @@ protected: virtual void player_overlay(bitmap_yuy16 &bitmap) override; // internal helpers + TIMER_CALLBACK_MEMBER(process_vbi_data); + TIMER_CALLBACK_MEMBER(vsync_off); bool focus_on() const { return !(m_i8049_port1 & 0x08); } bool spdl_on() const { return !(m_i8049_port1 & 0x10); } bool laser_on() const { return !(m_i8049_port2 & 0x01); } @@ -115,6 +108,10 @@ protected: output_finder<> m_pause; output_finder<> m_standby; + // timers + emu_timer *m_process_vbi_timer; + emu_timer *m_vsync_off_timer; + // internal state uint8_t m_control; // control line state uint8_t m_lastcommand; // last command seen @@ -153,20 +150,12 @@ public: void set_external_audio_squelch(int state); protected: - // timer IDs - enum - { - TID_IRQ_OFF = TID_FIRST_SUBCLASS_TIMER, - TID_LATCH_DATA - }; - // subclass overrides virtual void player_vsync(const vbi_metadata &vbi, int fieldnum, const attotime &curtime) override; // device-level overrides virtual void device_start() override; virtual void device_reset() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; virtual const tiny_rom_entry *device_rom_region() const override; virtual void device_add_mconfig(machine_config &config) override; @@ -175,6 +164,9 @@ protected: virtual void update_audio_squelch() override { set_audio_squelch(m_audio_squelch, m_audio_squelch); } private: + TIMER_CALLBACK_MEMBER(irq_off); + TIMER_CALLBACK_MEMBER(latch_data); + // internal read/write handlers uint8_t i8748_data_r(); uint8_t i8748_port2_r(); @@ -185,10 +177,12 @@ private: // internal state required_device<i8748_device> m_i8748_cpu; - uint8_t m_audio_squelch; // audio squelch value + emu_timer *m_irq_off_timer; + emu_timer *m_latch_data_timer; + uint8_t m_audio_squelch; // audio squelch value uint8_t m_data; // parallel data for simutrek - bool m_data_ready; // ready flag for simutrek data - uint8_t m_i8748_port2; // 8748 port 2 state + bool m_data_ready; // ready flag for simutrek data + uint8_t m_i8748_port2; // 8748 port 2 state uint8_t m_controlnext; // latch to control next pair of fields uint8_t m_controlthis; // latched value for our control over the current pair of fields }; diff --git a/src/devices/machine/ldv1000.cpp b/src/devices/machine/ldv1000.cpp index 5ef4a5cd1a9..3c866118c76 100644 --- a/src/devices/machine/ldv1000.cpp +++ b/src/devices/machine/ldv1000.cpp @@ -155,7 +155,9 @@ void pioneer_ldv1000_device::device_start() laserdisc_device::device_start(); // allocate timers - m_multitimer = timer_alloc(TID_MULTIJUMP); + m_multitimer = timer_alloc(FUNC(pioneer_ldv1000_device::multijump_tick), this); + m_vsync_off_timer = timer_alloc(FUNC(pioneer_ldv1000_device::vsync_off), this); + m_process_vbi_timer = timer_alloc(FUNC(pioneer_ldv1000_device::process_vbi_data), this); m_command_strobe_cb.resolve_safe(); } @@ -187,73 +189,72 @@ void pioneer_ldv1000_device::device_reset() //------------------------------------------------- -// device_timer - handle timers set by this -// device +// vsync_off - clear the VSYNC flag //------------------------------------------------- -void pioneer_ldv1000_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(pioneer_ldv1000_device::vsync_off) { - switch (id) - { - case TID_MULTIJUMP: - { - // bit 5 of port B on PPI 1 selects the direction of slider movement - int direction = (m_portb1 & 0x20) ? 1 : -1; - advance_slider(direction); - - // update down counter and reschedule - if (--m_counter != 0) - timer.adjust(MULTIJUMP_TRACK_TIME); - break; - } + m_vsync = false; +} + + +//------------------------------------------------- +// multijump_tick - move the slider across +// multiple tracks +//------------------------------------------------- + +TIMER_CALLBACK_MEMBER(pioneer_ldv1000_device::multijump_tick) +{ + // bit 5 of port B on PPI 1 selects the direction of slider movement + int direction = (m_portb1 & 0x20) ? 1 : -1; + advance_slider(direction); + + // update down counter and reschedule + if (--m_counter != 0) + m_multitimer->adjust(MULTIJUMP_TRACK_TIME); +} + - case TID_VSYNC_OFF: - m_vsync = false; - break; +//------------------------------------------------- +// process_vbi_data - process VBI data which was +// fetched by the parent device +//------------------------------------------------- - case TID_VBI_DATA_FETCH: +TIMER_CALLBACK_MEMBER(pioneer_ldv1000_device::process_vbi_data) +{ + // appears to return data in reverse order + uint32_t lines[3]; + lines[0] = get_field_code(LASERDISC_CODE_LINE1718, false); + lines[1] = get_field_code(LASERDISC_CODE_LINE17, false); + lines[2] = get_field_code(LASERDISC_CODE_LINE16, false); + + // fill in the details + memset(m_vbi, 0, sizeof(m_vbi)); + if (focus_on() && laser_on()) + { + // loop over lines + for (int line = 0; line < 3; line++) { - // appears to return data in reverse order - uint32_t lines[3]; - lines[0] = get_field_code(LASERDISC_CODE_LINE1718, false); - lines[1] = get_field_code(LASERDISC_CODE_LINE17, false); - lines[2] = get_field_code(LASERDISC_CODE_LINE16, false); - - // fill in the details - memset(m_vbi, 0, sizeof(m_vbi)); - if (focus_on() && laser_on()) + uint8_t *dest = &m_vbi[line * 7]; + uint32_t data = lines[line]; + + // the logic only processes leadin/leadout/frame number codes + if (data == VBI_CODE_LEADIN || data == VBI_CODE_LEADOUT || (data & VBI_MASK_CAV_PICTURE) == VBI_CODE_CAV_PICTURE) { - // loop over lines - for (int line = 0; line < 3; line++) - { - uint8_t *dest = &m_vbi[line * 7]; - uint32_t data = lines[line]; - - // the logic only processes leadin/leadout/frame number codes - if (data == VBI_CODE_LEADIN || data == VBI_CODE_LEADOUT || (data & VBI_MASK_CAV_PICTURE) == VBI_CODE_CAV_PICTURE) - { - *dest++ = 0x09 | (((data & VBI_MASK_CAV_PICTURE) == VBI_CODE_CAV_PICTURE) ? 0x02 : 0x00); - *dest++ = 0x08; - *dest++ = (data >> 16) & 0x0f; - *dest++ = (data >> 12) & 0x0f; - *dest++ = (data >> 8) & 0x0f; - *dest++ = (data >> 4) & 0x0f; - *dest++ = (data >> 0) & 0x0f; - } - } + *dest++ = 0x09 | (((data & VBI_MASK_CAV_PICTURE) == VBI_CODE_CAV_PICTURE) ? 0x02 : 0x00); + *dest++ = 0x08; + *dest++ = (data >> 16) & 0x0f; + *dest++ = (data >> 12) & 0x0f; + *dest++ = (data >> 8) & 0x0f; + *dest++ = (data >> 4) & 0x0f; + *dest++ = (data >> 0) & 0x0f; } - - // signal that data is ready and reset the readback index - m_vbiready = true; - m_vbiindex = 0; - break; } - - // pass everything else onto the parent - default: - laserdisc_device::device_timer(timer, id, param); - break; } + + // signal that data is ready and reset the readback index + m_vbiready = true; + m_vbiindex = 0; } @@ -309,10 +310,10 @@ void pioneer_ldv1000_device::player_vsync(const vbi_metadata &vbi, int fieldnum, // signal VSYNC and set a timer to turn it off m_vsync = true; - timer_set(screen().scan_period() * 4, TID_VSYNC_OFF); + m_vsync_off_timer->adjust(screen().scan_period() * 4); // also set a timer to fetch the VBI data when it is ready - timer_set(screen().time_until_pos(19*2), TID_VBI_DATA_FETCH); + m_process_vbi_timer->adjust(screen().time_until_pos(19*2)); // boost interleave for the first 1ms to improve communications machine().scheduler().boost_interleave(attotime::zero, attotime::from_msec(1)); diff --git a/src/devices/machine/ldv1000.h b/src/devices/machine/ldv1000.h index a4ea232429a..a4ffa12f5b2 100644 --- a/src/devices/machine/ldv1000.h +++ b/src/devices/machine/ldv1000.h @@ -51,18 +51,9 @@ public: uint8_t command_strobe_r() const { return (m_portc1 & 0x10) ? ASSERT_LINE : CLEAR_LINE; } protected: - // timer IDs - enum - { - TID_MULTIJUMP = TID_FIRST_PLAYER_TIMER, - TID_VSYNC_OFF, - TID_VBI_DATA_FETCH - }; - // device-level overrides virtual void device_start() override; virtual void device_reset() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; virtual const tiny_rom_entry *device_rom_region() const override; virtual void device_add_mconfig(machine_config &config) override; @@ -71,6 +62,10 @@ protected: virtual int32_t player_update(const vbi_metadata &vbi, int fieldnum, const attotime &curtime) override; virtual void player_overlay(bitmap_yuy16 &bitmap) override { } + TIMER_CALLBACK_MEMBER(vsync_off); + TIMER_CALLBACK_MEMBER(multijump_tick); + TIMER_CALLBACK_MEMBER(process_vbi_data); + private: // internal helpers bool focus_on() const { return !(m_portb1 & 0x01); } @@ -97,19 +92,21 @@ private: void ldv1000_portmap(address_map &map); // internal state - required_device<z80_device> m_z80_cpu; /* CPU index of the Z80 */ - required_device<z80ctc_device> m_z80_ctc; /* CTC device */ - emu_timer * m_multitimer; /* multi-jump timer device */ + required_device<z80_device> m_z80_cpu; /* CPU index of the Z80 */ + required_device<z80ctc_device> m_z80_ctc; /* CTC device */ + emu_timer * m_multitimer; /* multi-jump timer device */ + emu_timer * m_vsync_off_timer; /* vsync-shutoff timer device */ + emu_timer * m_process_vbi_timer; /* VBI processing timer device */ devcb_write_line m_command_strobe_cb; /* communication status */ - uint8_t m_command; /* command byte to the player */ + uint8_t m_command; /* command byte to the player */ uint8_t m_status; /* status byte from the player */ - bool m_vsync; /* VSYNC state */ + bool m_vsync; /* VSYNC state */ /* I/O port states */ uint8_t m_counter_start; /* starting value for counter */ - uint8_t m_counter; /* current counter value */ + uint8_t m_counter; /* current counter value */ uint8_t m_portc0; /* port C on PPI 0 */ uint8_t m_portb1; /* port B on PPI 1 */ uint8_t m_portc1; /* port C on PPI 1 */ @@ -118,9 +115,9 @@ private: uint8_t m_portselect; /* selection of which port to access */ uint8_t m_display[2][20]; /* display lines */ uint8_t m_dispindex; /* index within the display line */ - uint8_t m_vbi[7*3]; /* VBI data */ - bool m_vbiready; /* VBI ready flag */ - uint8_t m_vbiindex; /* index within the VBI data */ + uint8_t m_vbi[7*3]; /* VBI data */ + bool m_vbiready; /* VBI ready flag */ + uint8_t m_vbiindex; /* index within the VBI data */ }; diff --git a/src/devices/machine/ldv4200hle.cpp b/src/devices/machine/ldv4200hle.cpp index fba4c1750a2..db8f86a2a03 100644 --- a/src/devices/machine/ldv4200hle.cpp +++ b/src/devices/machine/ldv4200hle.cpp @@ -683,7 +683,7 @@ void pioneer_ldv4200hle_device::device_start() m_serial_tx.resolve_safe(); // allocate timers - m_vbi_fetch = timer_alloc(TID_VBI_DATA_FETCH); + m_vbi_fetch = timer_alloc(FUNC(pioneer_ldv4200hle_device::process_vbi_data), this); // register state saving save_item(NAME(m_cmd_buffer)); @@ -771,124 +771,112 @@ void pioneer_ldv4200hle_device::device_reset() //------------------------------------------------- -// device_timer - handle timers set by this -// device +// process_vbi_data - process VBI data and +// act on search/play seeking //------------------------------------------------- -void pioneer_ldv4200hle_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(pioneer_ldv4200hle_device::process_vbi_data) { - switch (id) + uint32_t line = get_field_code(LASERDISC_CODE_LINE1718, false); + if ((line & 0xf80000) == 0xf80000 || line == VBI_CODE_LEADIN || line == VBI_CODE_LEADOUT) { - case TID_VBI_DATA_FETCH: + uint32_t old_frame = m_curr_frame; + if (line == VBI_CODE_LEADIN) + m_curr_frame = 0; + else if (line == VBI_CODE_LEADOUT) + m_curr_frame = 54000; + else + m_curr_frame = bcd_to_literal(line & 0x7ffff); + + LOGMASKED(LOG_FRAMES, "Current frame is %d (VBI 16: %06x, VBI 17: %06x, VBI 18: %06x, VBI 1718: %06x\n", m_curr_frame, + get_field_code(LASERDISC_CODE_LINE16, false), + get_field_code(LASERDISC_CODE_LINE17, false), + get_field_code(LASERDISC_CODE_LINE18, false), + line); + + if (m_mode != MODE_STILL && m_mode != MODE_PAUSE) { - uint32_t line = get_field_code(LASERDISC_CODE_LINE1718, false); - if ((line & 0xf80000) == 0xf80000 || line == VBI_CODE_LEADIN || line == VBI_CODE_LEADOUT) + if (m_mark_frame != ~uint32_t(0) && m_search_frame == ~uint32_t(0)) { - uint32_t old_frame = m_curr_frame; - if (line == VBI_CODE_LEADIN) - m_curr_frame = 0; - else if (line == VBI_CODE_LEADOUT) - m_curr_frame = 54000; - else - m_curr_frame = bcd_to_literal(line & 0x7ffff); + int32_t old_delta = (int32_t)m_mark_frame - (int32_t)old_frame; + int32_t curr_delta = (int32_t)m_mark_frame - (int32_t)m_curr_frame; + LOGMASKED(LOG_STOPS, "%s: Stop Mark is currently %d, old frame is %d, current frame is %d, old delta %d, curr delta %d\n", machine().describe_context(), m_mark_frame, old_frame, m_curr_frame, old_delta, curr_delta); + if (curr_delta == 0 || std::signbit(old_delta) != std::signbit(curr_delta)) + { + m_mark_frame = ~uint32_t(0); + if (is_cav_disc()) + { + LOGMASKED(LOG_STOPS | LOG_SQUELCHES, "%s: Stop Mark: Zero delta w/ CAV disc, entering still mode and squelching audio\n", machine().describe_context()); + m_mode = MODE_STILL; + update_video_enable(); + } + else + { + LOGMASKED(LOG_STOPS | LOG_SQUELCHES, "%s: Stop Mark: Zero delta w/ CLV disc, entering still mode and squelching video+audio\n", machine().describe_context()); + m_mode = MODE_PAUSE; + video_enable(false); + } + + set_audio_squelch(true, true); - LOGMASKED(LOG_FRAMES, "Current frame is %d (VBI 16: %06x, VBI 17: %06x, VBI 18: %06x, VBI 1718: %06x\n", m_curr_frame, - get_field_code(LASERDISC_CODE_LINE16, false), - get_field_code(LASERDISC_CODE_LINE17, false), - get_field_code(LASERDISC_CODE_LINE18, false), - line); + if (m_cmd_running) + { + LOGMASKED(LOG_SEARCHES | LOG_COMMANDS, "%s: Stop Mark: Command running, sending reply\n", machine().describe_context()); + m_cmd_running = false; + queue_reply("R\x0d"); + } + } + } - if (m_mode != MODE_STILL && m_mode != MODE_PAUSE) + if (m_search_frame != ~uint32_t(0)) + { + // TODO: Chapter-search support + int32_t delta = (int32_t)m_search_frame - (int32_t)m_curr_frame; + LOGMASKED(LOG_SEARCHES, "%s: Searching from current frame %d with delta %d\n", machine().describe_context(), m_curr_frame, delta); + if (delta == 0) { - if (m_mark_frame != ~uint32_t(0) && m_search_frame == ~uint32_t(0)) + // We've found our frame, enter play, pause or still mode. + m_search_frame = ~uint32_t(0); + if (is_cav_disc()) { - int32_t old_delta = (int32_t)m_mark_frame - (int32_t)old_frame; - int32_t curr_delta = (int32_t)m_mark_frame - (int32_t)m_curr_frame; - LOGMASKED(LOG_STOPS, "%s: Stop Mark is currently %d, old frame is %d, current frame is %d, old delta %d, curr delta %d\n", machine().describe_context(), m_mark_frame, old_frame, m_curr_frame, old_delta, curr_delta); - if (curr_delta == 0 || std::signbit(old_delta) != std::signbit(curr_delta)) - { - m_mark_frame = ~uint32_t(0); - if (is_cav_disc()) - { - LOGMASKED(LOG_STOPS | LOG_SQUELCHES, "%s: Stop Mark: Zero delta w/ CAV disc, entering still mode and squelching audio\n", machine().describe_context()); - m_mode = MODE_STILL; - update_video_enable(); - } - else - { - LOGMASKED(LOG_STOPS | LOG_SQUELCHES, "%s: Stop Mark: Zero delta w/ CLV disc, entering still mode and squelching video+audio\n", machine().describe_context()); - m_mode = MODE_PAUSE; - video_enable(false); - } - - set_audio_squelch(true, true); - - if (m_cmd_running) - { - LOGMASKED(LOG_SEARCHES | LOG_COMMANDS, "%s: Stop Mark: Command running, sending reply\n", machine().describe_context()); - m_cmd_running = false; - queue_reply("R\x0d"); - } - } + LOGMASKED(LOG_SEARCHES | LOG_SQUELCHES, "%s: Search Mark: Zero delta w/ CAV disc, entering still mode and squelching audio\n", machine().describe_context()); + m_mode = MODE_STILL; + update_video_enable(); } + else + { + LOGMASKED(LOG_SEARCHES | LOG_SQUELCHES, "%s: Search Mark: Zero delta w/ CLV disc, entering still mode and squelching video+audio\n", machine().describe_context()); + m_mode = MODE_PAUSE; + video_enable(false); + } + + set_audio_squelch(true, true); - if (m_search_frame != ~uint32_t(0)) + if (m_cmd_running) { - // TODO: Chapter-search support - int32_t delta = (int32_t)m_search_frame - (int32_t)m_curr_frame; - LOGMASKED(LOG_SEARCHES, "%s: Searching from current frame %d with delta %d\n", machine().describe_context(), m_curr_frame, delta); - if (delta == 0) - { - // We've found our frame, enter play, pause or still mode. - m_search_frame = ~uint32_t(0); - if (is_cav_disc()) - { - LOGMASKED(LOG_SEARCHES | LOG_SQUELCHES, "%s: Search Mark: Zero delta w/ CAV disc, entering still mode and squelching audio\n", machine().describe_context()); - m_mode = MODE_STILL; - update_video_enable(); - } - else - { - LOGMASKED(LOG_SEARCHES | LOG_SQUELCHES, "%s: Search Mark: Zero delta w/ CLV disc, entering still mode and squelching video+audio\n", machine().describe_context()); - m_mode = MODE_PAUSE; - video_enable(false); - } - - set_audio_squelch(true, true); - - if (m_cmd_running) - { - LOGMASKED(LOG_SEARCHES | LOG_COMMANDS, "%s: Search Mark: Command running, sending reply\n", machine().describe_context()); - m_cmd_running = false; - queue_reply("R\x0d"); - } - } - else if (delta <= 2 && delta > 0) - { - LOGMASKED(LOG_SEARCHES, "%s: Positive near delta, letting disc run to current\n", machine().describe_context()); - // We're approaching our frame, let it run up. - } - else - { - if (delta < 0) - { - advance_slider(std::min(-2, delta / 2)); - } - else - { - advance_slider(std::max(1, delta / 2)); - } - } + LOGMASKED(LOG_SEARCHES | LOG_COMMANDS, "%s: Search Mark: Command running, sending reply\n", machine().describe_context()); + m_cmd_running = false; + queue_reply("R\x0d"); + } + } + else if (delta <= 2 && delta > 0) + { + LOGMASKED(LOG_SEARCHES, "%s: Positive near delta, letting disc run to current\n", machine().describe_context()); + // We're approaching our frame, let it run up. + } + else + { + if (delta < 0) + { + advance_slider(std::min(-2, delta / 2)); + } + else + { + advance_slider(std::max(1, delta / 2)); } } } - break; } - - // pass everything else onto the parent - default: - laserdisc_device::device_timer(timer, id, param); - break; } } diff --git a/src/devices/machine/ldv4200hle.h b/src/devices/machine/ldv4200hle.h index f57763698eb..c7ee5738e2a 100644 --- a/src/devices/machine/ldv4200hle.h +++ b/src/devices/machine/ldv4200hle.h @@ -51,16 +51,9 @@ public: auto serial_tx() { return m_serial_tx.bind(); } protected: - // timer IDs - enum - { - TID_VBI_DATA_FETCH = TID_FIRST_PLAYER_TIMER - }; - // 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; // laserdisc overrides virtual void player_vsync(const vbi_metadata &vbi, int fieldnum, const attotime &curtime) override; @@ -72,6 +65,8 @@ protected: virtual void tra_complete() override; virtual void tra_callback() override; + TIMER_CALLBACK_MEMBER(process_vbi_data); + private: enum player_command : uint16_t { diff --git a/src/devices/machine/ldvp931.cpp b/src/devices/machine/ldvp931.cpp index 056a6b1d2ab..d610ed1bc1d 100644 --- a/src/devices/machine/ldvp931.cpp +++ b/src/devices/machine/ldvp931.cpp @@ -80,7 +80,11 @@ ROM_END philips_22vp931_device::philips_22vp931_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) : laserdisc_device(mconfig, PHILIPS_22VP931, tag, owner, clock), m_i8049_cpu(*this, "vp931"), - m_tracktimer(nullptr), + m_process_vbi_timer(nullptr), + m_irq_off_timer(nullptr), + m_strobe_off_timer(nullptr), + m_erp_off_timer(nullptr), + m_track_timer(nullptr), m_i8049_out0(0), m_i8049_out1(0), m_i8049_port1(0), @@ -144,8 +148,13 @@ void philips_22vp931_device::device_start() // pass through to the parent laserdisc_device::device_start(); - // allocate a timer - m_tracktimer = timer_alloc(TID_HALF_TRACK); + // allocate timers + m_initial_vbi_timer = timer_alloc(FUNC(philips_22vp931_device::process_vbi_data), this); + m_process_vbi_timer = timer_alloc(FUNC(philips_22vp931_device::process_vbi_data), this); + m_irq_off_timer = timer_alloc(FUNC(philips_22vp931_device::irq_off), this); + m_strobe_off_timer = timer_alloc(FUNC(philips_22vp931_device::data_strobe_off), this); + m_erp_off_timer = timer_alloc(FUNC(philips_22vp931_device::erp_off), this); + m_track_timer = timer_alloc(FUNC(philips_22vp931_device::half_track_tick), this); } @@ -181,92 +190,110 @@ void philips_22vp931_device::device_reset() //------------------------------------------------- -// device_timer - handle timers set by this -// device +// process_vbi_data - process VBI data which was +// fetched by the parent device //------------------------------------------------- -void philips_22vp931_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(philips_22vp931_device::process_vbi_data) { - switch (id) + uint32_t line = param >> 2; + int which = param & 3; + uint32_t code = 0; + + // fetch the code and compute the DATIC latched value + if (line >= LASERDISC_CODE_LINE16 && line <= LASERDISC_CODE_LINE18) + code = get_field_code(laserdisc_field_code(line), false); + + // at the start of each line, signal an interrupt and use a timer to turn it off + if (which == 0) { - case TID_VBI_DATA_FETCH: - { - uint32_t line = param >> 2; - int which = param & 3; - uint32_t code = 0; - - // fetch the code and compute the DATIC latched value - if (line >= LASERDISC_CODE_LINE16 && line <= LASERDISC_CODE_LINE18) - code = get_field_code(laserdisc_field_code(line), false); - - // at the start of each line, signal an interrupt and use a timer to turn it off - if (which == 0) - { - m_i8049_cpu->set_input_line(MCS48_INPUT_IRQ, ASSERT_LINE); - timer_set(attotime::from_nsec(5580), TID_IRQ_OFF); - } - - // clock the data strobe on each subsequent callback - else if (code != 0) - { - m_daticval = code >> (8 * (3 - which)); - m_datastrobe = 1; - timer_set(attotime::from_nsec(5000), TID_DATA_STROBE_OFF); - } - - // determine the next bit to fetch and reprime ourself - if (++which == 4) - { - which = 0; - line++; - } - if (line <= LASERDISC_CODE_LINE18 + 1) - timer_set(screen().time_until_pos(line*2, which * 2 * screen().width() / 4), TID_VBI_DATA_FETCH, (line << 2) + which); - break; - } + m_i8049_cpu->set_input_line(MCS48_INPUT_IRQ, ASSERT_LINE); + m_irq_off_timer->adjust(attotime::from_nsec(5580)); + } + + // clock the data strobe on each subsequent callback + else if (code != 0) + { + m_daticval = code >> (8 * (3 - which)); + m_datastrobe = 1; + m_strobe_off_timer->adjust(attotime::from_nsec(5000)); + } + + // determine the next bit to fetch and reprime ourself + if (++which == 4) + { + which = 0; + line++; + } + if (line <= LASERDISC_CODE_LINE18 + 1) + m_process_vbi_timer->adjust(screen().time_until_pos(line*2, which * 2 * screen().width() / 4), (line << 2) + which); +} + + +//------------------------------------------------- +// process_deferred_data - +//------------------------------------------------- + +TIMER_CALLBACK_MEMBER(philips_22vp931_device::process_deferred_data) +{ + // set the value and mark it pending + if (LOG_COMMANDS && m_fromcontroller_pending) + printf("Dropped previous command byte\n"); + m_fromcontroller = param; + m_fromcontroller_pending = true; + + // track the commands for debugging purposes + if (m_cmdcount < std::size(m_cmdbuf)) + { + m_cmdbuf[m_cmdcount++ % 3] = param; + if (LOG_COMMANDS && m_cmdcount % 3 == 0) + printf("Cmd: %02X %02X %02X\n", m_cmdbuf[0], m_cmdbuf[1], m_cmdbuf[2]); + } +} + + +//------------------------------------------------- +// irq_off - +//------------------------------------------------- + +TIMER_CALLBACK_MEMBER(philips_22vp931_device::irq_off) +{ + m_i8049_cpu->set_input_line(MCS48_INPUT_IRQ, CLEAR_LINE); +} + + +//------------------------------------------------- +// data_strobe_off - +//------------------------------------------------- + +TIMER_CALLBACK_MEMBER(philips_22vp931_device::data_strobe_off) +{ + m_datastrobe = 0; +} - case TID_DEFERRED_DATA: - // set the value and mark it pending - if (LOG_COMMANDS && m_fromcontroller_pending) - printf("Dropped previous command byte\n"); - m_fromcontroller = param; - m_fromcontroller_pending = true; - - // track the commands for debugging purposes - if (m_cmdcount < std::size(m_cmdbuf)) - { - m_cmdbuf[m_cmdcount++ % 3] = param; - if (LOG_COMMANDS && m_cmdcount % 3 == 0) - printf("Cmd: %02X %02X %02X\n", m_cmdbuf[0], m_cmdbuf[1], m_cmdbuf[2]); - } - break; - - case TID_IRQ_OFF: - m_i8049_cpu->set_input_line(MCS48_INPUT_IRQ, CLEAR_LINE); - break; - - case TID_DATA_STROBE_OFF: - m_datastrobe = 0; - break; - - case TID_ERP_OFF: - m_daticerp = 0; - break; - - case TID_HALF_TRACK: - // advance by the count and toggle the state - m_trackstate ^= 1; - if ((m_trackdir < 0 && !m_trackstate) || (m_trackdir > 0 && m_trackstate)) - { - advance_slider(m_trackdir); - m_advanced += m_trackdir; - } - break; - - // pass everything else onto the parent - default: - laserdisc_device::device_timer(timer, id, param); - break; + +//------------------------------------------------- +// erp_off - +//------------------------------------------------- + +TIMER_CALLBACK_MEMBER(philips_22vp931_device::erp_off) +{ + m_daticerp = 0; +} + + +//------------------------------------------------- +// half_track_tick - advance the slider by the +// current count and toggle the track state +//------------------------------------------------- + +TIMER_CALLBACK_MEMBER(philips_22vp931_device::half_track_tick) +{ + m_trackstate ^= 1; + if ((m_trackdir < 0 && !m_trackstate) || (m_trackdir > 0 && m_trackstate)) + { + advance_slider(m_trackdir); + m_advanced += m_trackdir; } } @@ -311,7 +338,7 @@ void philips_22vp931_device::player_vsync(const vbi_metadata &vbi, int fieldnum, // set the ERP signal to 1 to indicate start of frame, and set a timer to turn it off m_daticerp = 1; - timer_set(screen().time_until_pos(15*2), TID_ERP_OFF); + m_erp_off_timer->adjust(screen().time_until_pos(15*2)); } @@ -322,8 +349,9 @@ void philips_22vp931_device::player_vsync(const vbi_metadata &vbi, int fieldnum, int32_t philips_22vp931_device::player_update(const vbi_metadata &vbi, int fieldnum, const attotime &curtime) { - // set the first VBI timer to go at the start of line 16 - timer_set(screen().time_until_pos(16*2), TID_VBI_DATA_FETCH, LASERDISC_CODE_LINE16 << 2); + // player_update is invoked by the parent device at line 16, so call our VBI processing timer directly + m_initial_vbi_timer->adjust(screen().time_until_pos(16*2), LASERDISC_CODE_LINE16 << 2); + //process_vbi_data(LASERDISC_CODE_LINE16 << 2); // play forward by default return fieldnum; @@ -572,22 +600,18 @@ void philips_22vp931_device::i8049_port1_w(uint8_t data) } } - // if we have a timer, adjust it - if (m_tracktimer != nullptr) - { - // turn it off if we're not tracking - if (m_trackdir == 0) - m_tracktimer->reset(); + // turn off the track timer if we're not tracking + if (m_trackdir == 0) + m_track_timer->reset(); - // if we just started tracking, or if the speed was changed, reprime the timer - else if (((m_i8049_port1 ^ data) & 0x11) != 0) - { - // speeds here are just guesses, but work with the player logic; this is the time per half-track - attotime speed = (data & 0x10) ? attotime::from_usec(60) : attotime::from_usec(10); + // if we just started tracking, or if the speed was changed, reprime the timer + else if (((m_i8049_port1 ^ data) & 0x11) != 0) + { + // speeds here are just guesses, but work with the player logic; this is the time per half-track + attotime speed = (data & 0x10) ? attotime::from_usec(60) : attotime::from_usec(10); - // always start with an initial long delay; the code expects this - m_tracktimer->adjust(attotime::from_usec(100), 0, speed); - } + // always start with an initial long delay; the code expects this + m_track_timer->adjust(attotime::from_usec(100), 0, speed); } m_i8049_port1 = data; diff --git a/src/devices/machine/ldvp931.h b/src/devices/machine/ldvp931.h index a1eee3be52e..cffc81cc9dc 100644 --- a/src/devices/machine/ldvp931.h +++ b/src/devices/machine/ldvp931.h @@ -43,7 +43,7 @@ public: philips_22vp931_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock); // input and output - void data_w(uint8_t data) { synchronize(TID_DEFERRED_DATA, data); } + void data_w(uint8_t data) { machine().scheduler().synchronize(timer_expired_delegate(FUNC(philips_22vp931_device::process_deferred_data), this), data); } void reset_w(uint8_t data); uint8_t data_r(); uint8_t ready_r() { return m_fromcontroller_pending ? CLEAR_LINE : ASSERT_LINE; } @@ -53,21 +53,9 @@ public: void set_data_ready_callback(data_ready_delegate callback) { m_data_ready = callback; } protected: - // timer IDs - enum - { - TID_IRQ_OFF = TID_FIRST_PLAYER_TIMER, - TID_DATA_STROBE_OFF, - TID_ERP_OFF, - TID_HALF_TRACK, - TID_VBI_DATA_FETCH, - TID_DEFERRED_DATA - }; - // device-level overrides virtual void device_start() override; virtual void device_reset() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; virtual const tiny_rom_entry *device_rom_region() const override; virtual void device_add_mconfig(machine_config &config) override; @@ -76,6 +64,13 @@ protected: virtual int32_t player_update(const vbi_metadata &vbi, int fieldnum, const attotime &curtime) override; virtual void player_overlay(bitmap_yuy16 &bitmap) override { } + TIMER_CALLBACK_MEMBER(process_vbi_data); + TIMER_CALLBACK_MEMBER(process_deferred_data); + TIMER_CALLBACK_MEMBER(irq_off); + TIMER_CALLBACK_MEMBER(data_strobe_off); + TIMER_CALLBACK_MEMBER(erp_off); + TIMER_CALLBACK_MEMBER(half_track_tick); + private: // internal read/write handlers void i8049_output0_w(uint8_t data); @@ -96,9 +91,14 @@ private: void vp931_portmap(address_map &map); // internal state - required_device<i8049_device> m_i8049_cpu; // CPU index of the 8049 - emu_timer * m_tracktimer; // timer device - data_ready_delegate m_data_ready; // data ready callback + required_device<i8049_device> m_i8049_cpu; // CPU index of the 8049 + emu_timer * m_initial_vbi_timer; + emu_timer * m_process_vbi_timer; + emu_timer * m_irq_off_timer; + emu_timer * m_strobe_off_timer; + emu_timer * m_erp_off_timer; + emu_timer * m_track_timer; // half-track timer device + data_ready_delegate m_data_ready; // data ready callback // I/O port states uint8_t m_i8049_out0; // output 0 state @@ -111,11 +111,11 @@ private: uint8_t m_datastrobe; // DATA STROBE line from DATIC // communication status - //uint8_t m_reset_state; // state of the reset input + //uint8_t m_reset_state; // state of the reset input uint8_t m_fromcontroller; // command byte from the controller - bool m_fromcontroller_pending; // true if data is pending + bool m_fromcontroller_pending; // true if data is pending uint8_t m_tocontroller; // command byte to the controller - bool m_tocontroller_pending; // true if data is pending + bool m_tocontroller_pending; // true if data is pending // tracking int8_t m_trackdir; // direction of tracking diff --git a/src/devices/machine/m3002.cpp b/src/devices/machine/m3002.cpp index a6a674c19e3..1e021571896 100644 --- a/src/devices/machine/m3002.cpp +++ b/src/devices/machine/m3002.cpp @@ -83,7 +83,7 @@ void m3002_device::device_resolve_objects() void m3002_device::device_start() { // Setup timer - m_second_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(m3002_device::second_timer), this)); + m_second_timer = timer_alloc(FUNC(m3002_device::second_timer), this); // Save internal state save_item(NAME(m_ram)); diff --git a/src/devices/machine/m68sfdc.cpp b/src/devices/machine/m68sfdc.cpp index 51fbc23f5e7..99a0b3b4580 100644 --- a/src/devices/machine/m68sfdc.cpp +++ b/src/devices/machine/m68sfdc.cpp @@ -73,8 +73,8 @@ void m68sfdc_device::device_start() m_irq_handler.resolve_safe(); m_nmi_handler.resolve_safe(); - m_timer_head_load = timer_alloc(TM_HEAD_LOAD); - m_timer_timeout = timer_alloc(TM_TIMEOUT); + m_timer_head_load = timer_alloc(FUNC(m68sfdc_device::head_load_update), this); + m_timer_timeout = timer_alloc(FUNC(m68sfdc_device::timeout_expired), this); save_item(NAME(m_select_0)); save_item(NAME(m_select_1)); save_item(NAME(m_select_2)); @@ -97,7 +97,7 @@ void m68sfdc_device::device_start() m_floppy = nullptr; - t_gen = timer_alloc(TM_GEN); + t_gen = timer_alloc(FUNC(m68sfdc_device::general_update), this); } void m68sfdc_device::device_reset() @@ -148,37 +148,30 @@ WRITE_LINE_MEMBER(m68sfdc_device::handle_nmi) m_nmi_handler(state); } -void m68sfdc_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(m68sfdc_device::head_load_update) { - switch (id) - { - case TM_HEAD_LOAD: - { - live_sync(); - m_head_load2 = 0; - u8 head_load = m_head_load1 && m_head_load2; - if (head_load != m_head_load) - { - // TODO sound? - m_head_load = head_load; - } - break; - } - case TM_TIMEOUT: + live_sync(); + m_head_load2 = 0; + u8 head_load = m_head_load1 && m_head_load2; + if (head_load != m_head_load) { - live_sync(); - m_pia->ca1_w(0); - break; - } - case TM_GEN: - live_sync(); - live_run(); - break; - default: - throw emu_fatalerror("Unknown id in m68sfdc_device::device_timer"); + // TODO sound? + m_head_load = head_load; } } +TIMER_CALLBACK_MEMBER(m68sfdc_device::timeout_expired) +{ + live_sync(); + m_pia->ca1_w(0); +} + +TIMER_CALLBACK_MEMBER(m68sfdc_device::general_update) +{ + live_sync(); + live_run(); +} + uint8_t m68sfdc_device::flip_bits(uint8_t data) diff --git a/src/devices/machine/m68sfdc.h b/src/devices/machine/m68sfdc.h index 81a26a1de58..605ac628583 100644 --- a/src/devices/machine/m68sfdc.h +++ b/src/devices/machine/m68sfdc.h @@ -30,6 +30,12 @@ public: void set_floppies_4(floppy_connector*, floppy_connector*, floppy_connector*, floppy_connector*); private: + virtual void device_start() override; + virtual void device_reset() override; + virtual void device_resolve_objects() override; + virtual void device_add_mconfig(machine_config &config) override; + virtual ioport_constructor device_input_ports() const override; + required_device<pia6821_device> m_pia; required_device<mc6852_device> m_ssda; emu_timer *m_timer_head_load; @@ -37,6 +43,7 @@ private: devcb_write_line m_irq_handler; devcb_write_line m_nmi_handler; + DECLARE_WRITE_LINE_MEMBER(handle_irq); DECLARE_WRITE_LINE_MEMBER(handle_nmi); @@ -79,16 +86,12 @@ private: floppy_connector *m_floppy0, *m_floppy1, *m_floppy2, *m_floppy3; floppy_image_device *m_floppy; // Currently selected floppy. - 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 void device_add_mconfig(machine_config &config) override; - virtual ioport_constructor device_input_ports() const override; - - enum { TM_HEAD_LOAD, TM_TIMEOUT, TM_GEN }; + TIMER_CALLBACK_MEMBER(head_load_update); + TIMER_CALLBACK_MEMBER(timeout_expired); + TIMER_CALLBACK_MEMBER(general_update); - enum { + enum + { // General "doing nothing" state IDLE, @@ -103,7 +106,8 @@ private: WRITE_BITS, }; - struct live_info { + struct live_info + { enum { PT_NONE, PT_CRC_1, PT_CRC_2 }; attotime tm; diff --git a/src/devices/machine/mb3773.cpp b/src/devices/machine/mb3773.cpp index b23b2c2ca20..e5ce23e13e6 100644 --- a/src/devices/machine/mb3773.cpp +++ b/src/devices/machine/mb3773.cpp @@ -41,7 +41,7 @@ mb3773_device::mb3773_device( const machine_config &mconfig, const char *tag, de void mb3773_device::device_start() { - m_watchdog_timer = timer_alloc(); + m_watchdog_timer = timer_alloc(FUNC(mb3773_device::watchdog_expired), this); save_item( NAME(m_ck) ); } @@ -56,7 +56,7 @@ void mb3773_device::device_reset() reset_timer(); } -void mb3773_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(mb3773_device::watchdog_expired) { logerror("Reset caused by watchdog\n"); diff --git a/src/devices/machine/mb3773.h b/src/devices/machine/mb3773.h index 377c705f6b0..5955c1fa372 100644 --- a/src/devices/machine/mb3773.h +++ b/src/devices/machine/mb3773.h @@ -27,7 +27,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(watchdog_expired); private: void reset_timer(); diff --git a/src/devices/machine/mb87030.cpp b/src/devices/machine/mb87030.cpp index a9c87cfc11b..1898f69ec67 100644 --- a/src/devices/machine/mb87030.cpp +++ b/src/devices/machine/mb87030.cpp @@ -433,8 +433,8 @@ void mb87030_device::step(bool timeout) void mb87030_device::device_start() { - m_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(mb87030_device::timeout), this)); - m_delay_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(mb87030_device::delay_timeout), this)); + m_timer = timer_alloc(FUNC(mb87030_device::timeout), this); + m_delay_timer = timer_alloc(FUNC(mb87030_device::delay_timeout), this); m_irq_handler.resolve_safe(); m_dreq_handler.resolve_safe(); diff --git a/src/devices/machine/mb8795.cpp b/src/devices/machine/mb8795.cpp index 544d954f35e..957b53a2655 100644 --- a/src/devices/machine/mb8795.cpp +++ b/src/devices/machine/mb8795.cpp @@ -52,8 +52,8 @@ void mb8795_device::device_start() drq_rx_cb.resolve(); memset(mac, 0, 6); - timer_tx = timer_alloc(TIMER_TX); - timer_rx = timer_alloc(TIMER_RX); + timer_tx = timer_alloc(FUNC(mb8795_device::tx_update), this); + timer_rx = timer_alloc(FUNC(mb8795_device::rx_update), this); } void mb8795_device::device_reset() @@ -323,15 +323,16 @@ bool mb8795_device::recv_is_multicast() return rxbuf[0] & 0x01; } -void mb8795_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(mb8795_device::tx_update) { - if(id == TIMER_TX) { - drq_tx = true; - if(!drq_tx_cb.isnull()) - drq_tx_cb(drq_tx); - } + drq_tx = true; + if(!drq_tx_cb.isnull()) + drq_tx_cb(drq_tx); +} - if(id == TIMER_RX && rxlen) { +TIMER_CALLBACK_MEMBER(mb8795_device::rx_update) +{ + if(rxlen) { drq_rx = true; if(!drq_rx_cb.isnull()) drq_rx_cb(drq_rx); diff --git a/src/devices/machine/mb8795.h b/src/devices/machine/mb8795.h index ba590d776f3..7129f047ebe 100644 --- a/src/devices/machine/mb8795.h +++ b/src/devices/machine/mb8795.h @@ -22,10 +22,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 void recv_cb(uint8_t *buf, int len) override; + TIMER_CALLBACK_MEMBER(tx_update); + TIMER_CALLBACK_MEMBER(rx_update); + private: enum { TIMER_TX, TIMER_RX }; diff --git a/src/devices/machine/mb89352.cpp b/src/devices/machine/mb89352.cpp index 4412cf8bd44..24777cd0289 100644 --- a/src/devices/machine/mb89352.cpp +++ b/src/devices/machine/mb89352.cpp @@ -181,7 +181,7 @@ void mb89352_device::device_start() m_drq_cb.resolve_safe(); // allocate read timer - m_transfer_timer = timer_alloc(TIMER_TRANSFER); + m_transfer_timer = timer_alloc(FUNC(mb89352_device::transfer_tick), this); } void mb89352_device::device_reset() @@ -217,17 +217,10 @@ int mb89352_device::get_scsi_cmd_len(uint8_t cbyte) //return 6; } -void mb89352_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(mb89352_device::transfer_tick) { - switch(id) - { - case TIMER_TRANSFER: - // TODO: check interrupts are actually enabled - { - m_drq_cb(1); - } - break; - } + // TODO: check interrupts are actually enabled + m_drq_cb(1); } void mb89352_device::set_phase(int phase) diff --git a/src/devices/machine/mb89352.h b/src/devices/machine/mb89352.h index 9ce98c6380f..1032dd547d7 100644 --- a/src/devices/machine/mb89352.h +++ b/src/devices/machine/mb89352.h @@ -31,12 +31,10 @@ 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; -private: - // internal device state goes here - static const device_timer_id TIMER_TRANSFER = 0; + TIMER_CALLBACK_MEMBER(transfer_tick); +private: int get_scsi_cmd_len(uint8_t cbyte); //void set_ints(uint8_t flag); diff --git a/src/devices/machine/mc14411.cpp b/src/devices/machine/mc14411.cpp index 9d4cb73bf12..722de11b35e 100644 --- a/src/devices/machine/mc14411.cpp +++ b/src/devices/machine/mc14411.cpp @@ -44,12 +44,6 @@ //#define LOG(...) LOGMASKED(LOG_GENERAL, __VA_ARGS__) // Already defined in logmacro.h #define LOGSETUP(...) LOGMASKED(LOG_SETUP, __VA_ARGS__) -#ifdef _MSC_VER -#define FUNCNAME __func__ -#else -#define FUNCNAME __PRETTY_FUNCTION__ -#endif - /*************************************************************************** INTERNAL TABLES @@ -115,20 +109,21 @@ mc14411_device::mc14411_device(const machine_config &mconfig, device_type type, void mc14411_device::device_start() { - LOGSETUP("%s\n", FUNCNAME); + LOGSETUP("mc14411_device::device_start\n"); for (int i = TIMER_F1; i <= TIMER_F16; i++) { + m_fx_timers[i].timer = timer_alloc(FUNC(mc14411_device::timer_tick), this); + m_fx_timers[i].enabled = true; m_out_fx_cbs[i].resolve(); - m_fx_timer[i] = timer_alloc(i); - m_timer_enabled[i] = !m_out_fx_cbs[i].isnull(); } save_item(NAME(m_divider)); save_item(NAME(m_reset)); - save_item(NAME(m_timer_enabled)); + save_item(STRUCT_MEMBER(m_fx_timers, state)); + save_item(STRUCT_MEMBER(m_fx_timers, enabled)); - m_reset_timer = timer_alloc(TIMER_ID_RESET); + m_reset_timer = timer_alloc(FUNC(mc14411_device::reset_tick), this); } @@ -141,7 +136,7 @@ void mc14411_device::device_clock_changed() { for (int i = TIMER_F1; i <= TIMER_F16; i++) { - if (m_timer_enabled[i]) + if (m_fx_timers[i].enabled) arm_timer(i); } } @@ -154,18 +149,18 @@ void mc14411_device::device_clock_changed() void mc14411_device::timer_enable(timer_id i, bool enable) { assert(i >= TIMER_F1 && i <= TIMER_F16); - m_timer_enabled[i] = enable; + m_fx_timers[i].enabled = enable; if (!enable) - m_fx_timer[i]->enable(false); - else if (!m_fx_timer[i]->enabled()) + m_fx_timers[i].timer->enable(false); + else if (!m_fx_timers[i].timer->enabled()) arm_timer(i); } void mc14411_device::timer_disable_all() { for (int i = TIMER_F1; i <= TIMER_F16; i++) - timer_enable((timer_id) i, false); + timer_enable((timer_id)i, false); } //------------------------------------------------- @@ -175,13 +170,13 @@ void mc14411_device::timer_disable_all() void mc14411_device::arm_timer(int i) { - assert(!m_out_fx_cbs[i].isnull()); - + if (m_out_fx_cbs[i].isnull()) + return; int divider = s_counter_divider[i]; if (i < TIMER_F15) divider *= s_divider_select[m_divider]; attotime half_cycle = clocks_to_attotime(divider) / 2; // 2 flanks per cycle - m_fx_timer[i]->adjust(half_cycle, i, half_cycle); + m_fx_timers[i].timer->adjust(half_cycle, i, half_cycle); LOGSETUP(" - arming timer for F%d at %fHz (/%d)\n", i + 1, double(clock()) / divider, divider); } @@ -193,47 +188,47 @@ void mc14411_device::arm_timer(int i) void mc14411_device::device_reset() { - LOGSETUP("%s\n", FUNCNAME); + LOGSETUP("mc14411_device::device_reset\n"); for (int i = TIMER_F1; i <= TIMER_F16; i++) { + // Reset line according to datasheet and remember it for transitions to come + m_fx_timers[i].state = !(i < TIMER_F15); if (!m_out_fx_cbs[i].isnull()) - { - // Reset line according to datasheet and remember it for transitions to come - (m_out_fx_cbs[i])(m_fx_state[i] = (i < TIMER_F15 ? 0 : 1)); - } + m_out_fx_cbs[i](m_fx_timers[i].state); } if (m_reset == ASSERT_LINE) { - m_reset_timer->adjust(attotime::from_nsec((double)900), TIMER_ID_RESET, attotime::from_nsec((double)900)); + m_reset_timer->adjust(attotime::from_nsec(900)); } } //------------------------------------------------- -// device_timer - handler timer events +// timer_tick - update the output state for a +// given Fx timer //------------------------------------------------- -void mc14411_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(mc14411_device::timer_tick) { - if (id >= TIMER_F1 && id <= TIMER_F16) - { - (m_out_fx_cbs[id])(m_fx_state[id]++ & 1); - } - else if (id == TIMER_ID_RESET) - { - // NOTE: This check could be triggered by either faulty hardware design or non accurate emulation so is just informative if the reset line is handled - // explicitelly instead of relying on calling device_reset - if (!(m_reset == ASSERT_LINE)) - { - LOG("Reset pulse is too short, should be 900nS minimum"); - logerror("Reset pulse is too short, should be 900nS minimum"); - } - } - else + m_out_fx_cbs[param](m_fx_timers[param].state); + m_fx_timers[param].state = !m_fx_timers[param].state; +} + + +//------------------------------------------------- +// reset_tick - log information if the device's +// reset pulse is too short +//------------------------------------------------- + +TIMER_CALLBACK_MEMBER(mc14411_device::reset_tick) +{ + // NOTE: This check could be triggered by either faulty hardware design or non accurate emulation so is just informative if the reset line is handled + // explicitelly instead of relying on calling device_reset + if (!(m_reset == ASSERT_LINE)) { - LOG("Unhandled Timer ID %d\n", id); + LOG("Reset pulse is too short, should be 900nS minimum"); } } @@ -246,7 +241,7 @@ void mc14411_device::device_timer(emu_timer &timer, device_timer_id id, int para void mc14411_device::rate_select_w(uint8_t data) { - LOGSETUP("%s %02x\n", FUNCNAME, data); + LOGSETUP("mc14411_device::rate_select_w %02x\n", data); if (m_divider != (data & 3)) { @@ -263,7 +258,7 @@ void mc14411_device::rate_select_w(uint8_t data) void mc14411_device::rsa_w(int state) { - LOGSETUP("%s %02x\n", FUNCNAME, state); + LOGSETUP("mc14411_device::rsa_w %02x\n", state); if ((m_divider & RSA) != (state == ASSERT_LINE ? RSA : 0)) { @@ -280,7 +275,7 @@ void mc14411_device::rsa_w(int state) void mc14411_device::rsb_w(int state) { - LOGSETUP("%s %02x\n", FUNCNAME, state); + LOGSETUP("mc14411_device::rsb_w %02x\n", state); if ((m_divider & RSB) != (state == ASSERT_LINE ? RSB : 0)) { @@ -297,7 +292,7 @@ void mc14411_device::rsb_w(int state) void mc14411_device::reset_w(int state) { - LOGSETUP("%s %02x\n", FUNCNAME, state); + LOGSETUP("mc14411_device::reset_w %02x\n", state); m_reset = state; diff --git a/src/devices/machine/mc14411.h b/src/devices/machine/mc14411.h index 47d081b128b..422e381bcb2 100644 --- a/src/devices/machine/mc14411.h +++ b/src/devices/machine/mc14411.h @@ -29,26 +29,25 @@ class mc14411_device : public device_t { public: - // timers - enum timer_id // indexes + // timer indices + enum timer_id : int { - TIMER_F1 = 0, - TIMER_F2 = 1, - TIMER_F3 = 2, - TIMER_F4 = 3, - TIMER_F5 = 4, - TIMER_F6 = 5, - TIMER_F7 = 6, - TIMER_F8 = 7, - TIMER_F9 = 8, - TIMER_F10 = 9, - TIMER_F11 = 10, - TIMER_F12 = 11, - TIMER_F13 = 12, - TIMER_F14 = 13, - TIMER_F15 = 14, - TIMER_F16 = 15, - TIMER_ID_RESET = 16 + TIMER_F1, + TIMER_F2, + TIMER_F3, + TIMER_F4, + TIMER_F5, + TIMER_F6, + TIMER_F7, + TIMER_F8, + TIMER_F9, + TIMER_F10, + TIMER_F11, + TIMER_F12, + TIMER_F13, + TIMER_F14, + TIMER_F15, + TIMER_F16 }; // rate select inputs @@ -78,26 +77,31 @@ protected: virtual void device_start() override; virtual void device_clock_changed() override; virtual void device_reset() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; + + TIMER_CALLBACK_MEMBER(timer_tick); + TIMER_CALLBACK_MEMBER(reset_tick); private: void arm_timer(int i); - emu_timer *m_fx_timer[16]; - emu_timer *m_reset_timer; - - uint32_t m_fx_state[16]; // F1-F16 output line states + struct fx_timer + { + emu_timer *timer; + bool state; + bool enabled; + }; - // divider matrix - static const int s_counter_divider[16]; - static const int s_divider_select[4]; + fx_timer m_fx_timers[16]; + emu_timer *m_reset_timer; devcb_write_line::array<16> m_out_fx_cbs; uint32_t m_divider; // main divider to use, 0-3 column index into counter_divider uint32_t m_reset; // Reset line state - bool m_timer_enabled[16]; + // divider matrix + static const int s_counter_divider[16]; + static const int s_divider_select[4]; }; DECLARE_DEVICE_TYPE(MC14411, mc14411_device) diff --git a/src/devices/machine/mc146818.cpp b/src/devices/machine/mc146818.cpp index ead6f1de5a7..c5cabdfd528 100644 --- a/src/devices/machine/mc146818.cpp +++ b/src/devices/machine/mc146818.cpp @@ -54,7 +54,9 @@ mc146818_device::mc146818_device(const machine_config &mconfig, device_type type device_nvram_interface(mconfig, *this), m_region(*this, DEVICE_SELF), m_index(0), - m_clock_timer(nullptr), m_update_timer(nullptr), m_periodic_timer(nullptr), + m_clock_timer(nullptr), + m_update_timer(nullptr), + m_periodic_timer(nullptr), m_write_irq(*this), m_write_sqw(*this), m_century_index(-1), @@ -75,9 +77,9 @@ mc146818_device::mc146818_device(const machine_config &mconfig, device_type type void mc146818_device::device_start() { m_data = make_unique_clear<uint8_t[]>(data_size()); - m_clock_timer = timer_alloc(TIMER_CLOCK); - m_update_timer = timer_alloc(TIMER_UPDATE); - m_periodic_timer = timer_alloc(TIMER_PERIODIC); + m_clock_timer = timer_alloc(FUNC(mc146818_device::clock_tick), this); + m_update_timer = timer_alloc(FUNC(mc146818_device::time_tick), this); + m_periodic_timer = timer_alloc(FUNC(mc146818_device::periodic_tick), this); m_write_irq.resolve_safe(); m_write_sqw.resolve_safe(); @@ -105,141 +107,137 @@ void mc146818_device::device_reset() } //------------------------------------------------- -// device_timer - handler timer events +// timer events //------------------------------------------------- -void mc146818_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(mc146818_device::periodic_tick) { - switch (id) + m_sqw_state = !m_sqw_state; + + if (m_data[REG_B] & REG_B_SQWE) + m_write_sqw(m_sqw_state); + + // periodic flag/interrupt on rising edge of periodic timer + if (m_sqw_state) { - case TIMER_PERIODIC: - m_sqw_state = !m_sqw_state; + m_data[REG_C] |= REG_C_PF; + update_irq(); + } +} - if (m_data[REG_B] & REG_B_SQWE) - m_write_sqw(m_sqw_state); +TIMER_CALLBACK_MEMBER(mc146818_device::clock_tick) +{ + if (!(m_data[REG_B] & REG_B_SET)) + { + m_data[REG_A] |= REG_A_UIP; - // periodic flag/interrupt on rising edge of periodic timer - if (m_sqw_state) - { - m_data[REG_C] |= REG_C_PF; - update_irq(); - } - break; + m_update_timer->adjust(attotime::from_usec(244)); + } +} - case TIMER_CLOCK: - if (!(m_data[REG_B] & REG_B_SET)) +TIMER_CALLBACK_MEMBER(mc146818_device::time_tick) +{ + if (!param) + { + /// TODO: find out how the real chip deals with updates when binary/bcd values are already outside the normal range + int seconds = get_seconds() + 1; + if (seconds < 60) { - m_data[REG_A] |= REG_A_UIP; - - m_update_timer->adjust(attotime::from_usec(244)); + set_seconds(seconds); } - break; - - case TIMER_UPDATE: - if (!param) + else { - /// TODO: find out how the real chip deals with updates when binary/bcd values are already outside the normal range - int seconds = get_seconds() + 1; - if (seconds < 60) + set_seconds(0); + + int minutes = get_minutes() + 1; + if (minutes < 60) { - set_seconds(seconds); + set_minutes(minutes); } else { - set_seconds(0); + set_minutes(0); - int minutes = get_minutes() + 1; - if (minutes < 60) + int hours = get_hours() + 1; + if (hours < 24) { - set_minutes(minutes); + set_hours(hours); } else { - set_minutes(0); + set_hours(0); - int hours = get_hours() + 1; - if (hours < 24) + int dayofweek = get_dayofweek() + 1; + if (dayofweek <= 7) { - set_hours(hours); + set_dayofweek(dayofweek); } else { - set_hours(0); + set_dayofweek(1); + } - int dayofweek = get_dayofweek() + 1; - if (dayofweek <= 7) - { - set_dayofweek(dayofweek); - } - else - { - set_dayofweek(1); - } + int dayofmonth = get_dayofmonth() + 1; + if (dayofmonth <= gregorian_days_in_month(get_month(), get_year() + 2000)) + { + set_dayofmonth(dayofmonth); + } + else + { + set_dayofmonth(1); - int dayofmonth = get_dayofmonth() + 1; - if (dayofmonth <= gregorian_days_in_month(get_month(), get_year() + 2000)) + int month = get_month() + 1; + if (month <= 12) { - set_dayofmonth(dayofmonth); + set_month(month); } else { - set_dayofmonth(1); + set_month(1); - int month = get_month() + 1; - if (month <= 12) + int year = get_year() + 1; + if (year <= 99) { - set_month(month); + set_year(year); } else { - set_month(1); + set_year(0); - int year = get_year() + 1; - if (year <= 99) + if (century_count_enabled()) { - set_year(year); - } - else - { - set_year(0); - - if (century_count_enabled()) - { - set_century((get_century() + 1) % 100); - } + set_century((get_century() + 1) % 100); } } } } } } + } - if ((m_data[REG_ALARM_SECONDS] == m_data[REG_SECONDS] || (m_data[REG_ALARM_SECONDS] & ALARM_DONTCARE) == ALARM_DONTCARE) && - (m_data[REG_ALARM_MINUTES] == m_data[REG_MINUTES] || (m_data[REG_ALARM_MINUTES] & ALARM_DONTCARE) == ALARM_DONTCARE) && - (m_data[REG_ALARM_HOURS] == m_data[REG_HOURS] || (m_data[REG_ALARM_HOURS] & ALARM_DONTCARE) == ALARM_DONTCARE)) - { - // set the alarm interrupt flag AF - m_data[REG_C] |= REG_C_AF; - } + if ((m_data[REG_ALARM_SECONDS] == m_data[REG_SECONDS] || (m_data[REG_ALARM_SECONDS] & ALARM_DONTCARE) == ALARM_DONTCARE) && + (m_data[REG_ALARM_MINUTES] == m_data[REG_MINUTES] || (m_data[REG_ALARM_MINUTES] & ALARM_DONTCARE) == ALARM_DONTCARE) && + (m_data[REG_ALARM_HOURS] == m_data[REG_HOURS] || (m_data[REG_ALARM_HOURS] & ALARM_DONTCARE) == ALARM_DONTCARE)) + { + // set the alarm interrupt flag AF + m_data[REG_C] |= REG_C_AF; + } - // defer the update end sequence if update cycle time is non-zero - if (m_tuc) - { - m_update_timer->adjust(attotime::from_usec(m_tuc), 1); - break; - } + // defer the update end sequence if update cycle time is non-zero + if (m_tuc) + { + m_update_timer->adjust(attotime::from_usec(m_tuc), 1); + return; } + } - // clear update in progress and set update ended - m_data[REG_A] &= ~REG_A_UIP; - m_data[REG_C] |= REG_C_UF; + // clear update in progress and set update ended + m_data[REG_A] &= ~REG_A_UIP; + m_data[REG_C] |= REG_C_UF; - update_irq(); - break; - } + update_irq(); } - //------------------------------------------------- // nvram_default - called to initialize NVRAM to // its default state diff --git a/src/devices/machine/mc146818.h b/src/devices/machine/mc146818.h index cceb83b8848..44eb0a54337 100644 --- a/src/devices/machine/mc146818.h +++ b/src/devices/machine/mc146818.h @@ -53,7 +53,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_nvram_interface overrides virtual void nvram_default() override; @@ -71,6 +70,10 @@ protected: virtual uint8_t internal_read(offs_t offset); virtual void internal_write(offs_t offset, uint8_t data); + TIMER_CALLBACK_MEMBER(periodic_tick); + TIMER_CALLBACK_MEMBER(clock_tick); + TIMER_CALLBACK_MEMBER(time_tick); + enum { REG_SECONDS = 0, @@ -157,10 +160,6 @@ protected: uint8_t m_index; std::unique_ptr<uint8_t[]> m_data; - static const device_timer_id TIMER_CLOCK = 0; - static const device_timer_id TIMER_UPDATE = 1; - static const device_timer_id TIMER_PERIODIC = 2; - emu_timer *m_clock_timer; emu_timer *m_update_timer; emu_timer *m_periodic_timer; diff --git a/src/devices/machine/mc68328.cpp b/src/devices/machine/mc68328.cpp index 2a6546c51c5..e1753110d56 100644 --- a/src/devices/machine/mc68328.cpp +++ b/src/devices/machine/mc68328.cpp @@ -289,10 +289,10 @@ void mc68328_device::device_start() { m68000_device::device_start(); - m_gptimer[0] = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(mc68328_device::timer_tick<0>),this)); - m_gptimer[1] = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(mc68328_device::timer_tick<1>),this)); - m_rtc = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(mc68328_device::rtc_tick),this)); - m_pwm = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(mc68328_device::pwm_tick),this)); + m_gptimer[0] = timer_alloc(FUNC(mc68328_device::timer_tick<0>), this); + m_gptimer[1] = timer_alloc(FUNC(mc68328_device::timer_tick<1>), this); + m_rtc = timer_alloc(FUNC(mc68328_device::rtc_tick), this); + m_pwm = timer_alloc(FUNC(mc68328_device::pwm_tick), this); register_state_save(); } diff --git a/src/devices/machine/mc6843.cpp b/src/devices/machine/mc6843.cpp index e169049a0d3..0987b494a27 100644 --- a/src/devices/machine/mc6843.cpp +++ b/src/devices/machine/mc6843.cpp @@ -18,7 +18,7 @@ mc6843_device::mc6843_device(const machine_config &mconfig, const char *tag, dev void mc6843_device::device_start() { m_irq.resolve_safe(); - m_timer = timer_alloc(0); + m_timer = timer_alloc(FUNC(mc6843_device::update_tick), this); m_floppy = nullptr; m_dir = 0x00; @@ -300,7 +300,7 @@ void mc6843_device::ready_callback(floppy_image_device *floppy, int state) } } -void mc6843_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(mc6843_device::update_tick) { live_sync(); run(true, false, false); diff --git a/src/devices/machine/mc6843.h b/src/devices/machine/mc6843.h index 63b03a8aa44..86a92757279 100644 --- a/src/devices/machine/mc6843.h +++ b/src/devices/machine/mc6843.h @@ -30,7 +30,8 @@ protected: // device-level overrides virtual void device_start() override; virtual void device_reset() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; + + TIMER_CALLBACK_MEMBER(update_tick); private: // Status flags diff --git a/src/devices/machine/mc6846.cpp b/src/devices/machine/mc6846.cpp index 72b3f1added..7cacedc9656 100644 --- a/src/devices/machine/mc6846.cpp +++ b/src/devices/machine/mc6846.cpp @@ -62,8 +62,8 @@ mc6846_device::mc6846_device(const machine_config &mconfig, const char *tag, dev void mc6846_device::device_start() { - m_interval = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(mc6846_device::timer_expire), this)); - m_one_shot = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(mc6846_device::timer_one_shot), this)); + m_interval = timer_alloc(FUNC(mc6846_device::timer_expire), this); + m_one_shot = timer_alloc(FUNC(mc6846_device::timer_one_shot), this); m_out_port_cb.resolve(); /* 8-bit output */ m_out_cp2_cb.resolve(); /* 1-bit output */ diff --git a/src/devices/machine/mc6854.cpp b/src/devices/machine/mc6854.cpp index ed5eb02b8b5..55418ee0d23 100644 --- a/src/devices/machine/mc6854.cpp +++ b/src/devices/machine/mc6854.cpp @@ -194,7 +194,7 @@ void mc6854_device::device_start() m_out_rts_cb.resolve_safe(); m_out_dtr_cb.resolve_safe(); - m_ttimer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(mc6854_device::tfifo_cb), this)); + m_ttimer = timer_alloc(FUNC(mc6854_device::tfifo_cb), this); save_item(NAME(m_cr1)); save_item(NAME(m_cr2)); diff --git a/src/devices/machine/mc68681.cpp b/src/devices/machine/mc68681.cpp index 9d78834d166..8e647f4c2ab 100644 --- a/src/devices/machine/mc68681.cpp +++ b/src/devices/machine/mc68681.cpp @@ -208,7 +208,7 @@ void duart_base_device::device_start() read_inport.resolve(); write_outport.resolve_safe(); - duart_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(duart_base_device::duart_timer_callback),this)); + duart_timer = timer_alloc(FUNC(duart_base_device::duart_timer_callback), this); save_item(NAME(ACR)); save_item(NAME(IMR)); diff --git a/src/devices/machine/mc68901.cpp b/src/devices/machine/mc68901.cpp index 5160e27eee9..ed0282770e9 100644 --- a/src/devices/machine/mc68901.cpp +++ b/src/devices/machine/mc68901.cpp @@ -152,7 +152,6 @@ enum : u8 { #define DIVISOR PRESCALER[data & 0x07] - const u16 mc68901_device::INT_MASK_GPIO[] = { IR_GPIP_0, IR_GPIP_1, IR_GPIP_2, IR_GPIP_3, @@ -230,34 +229,34 @@ inline void mc68901_device::rx_error() } } -inline void mc68901_device::timer_count(int index) +TIMER_CALLBACK_MEMBER(mc68901_device::timer_count) { - if (m_tmc[index] == 0x01) + if (m_tmc[param] == 0x01) { /* toggle timer output signal */ - m_to[index] = !m_to[index]; + m_to[param] = !m_to[param]; - switch (index) + switch (param) { - case TIMER_A: m_out_tao_cb(m_to[index]); break; - case TIMER_B: m_out_tbo_cb(m_to[index]); break; - case TIMER_C: m_out_tco_cb(m_to[index]); break; - case TIMER_D: m_out_tdo_cb(m_to[index]); break; + case TIMER_A: m_out_tao_cb(m_to[param]); break; + case TIMER_B: m_out_tbo_cb(m_to[param]); break; + case TIMER_C: m_out_tco_cb(m_to[param]); break; + case TIMER_D: m_out_tdo_cb(m_to[param]); break; } - if (m_ier & INT_MASK_TIMER[index]) + if (m_ier & INT_MASK_TIMER[param]) { /* signal timer elapsed interrupt */ - take_interrupt(INT_MASK_TIMER[index]); + take_interrupt(INT_MASK_TIMER[param]); } /* load main counter */ - m_tmc[index] = m_tdr[index]; + m_tmc[param] = m_tdr[param]; } else { /* count down */ - m_tmc[index]--; + m_tmc[param]--; } } @@ -406,10 +405,10 @@ void mc68901_device::device_start() m_iack_chain_cb.resolve(); /* create the timers */ - m_timer[TIMER_A] = timer_alloc(TIMER_A); - m_timer[TIMER_B] = timer_alloc(TIMER_B); - m_timer[TIMER_C] = timer_alloc(TIMER_C); - m_timer[TIMER_D] = timer_alloc(TIMER_D); + m_timer[TIMER_A] = timer_alloc(FUNC(mc68901_device::timer_count), this); + m_timer[TIMER_B] = timer_alloc(FUNC(mc68901_device::timer_count), this); + m_timer[TIMER_C] = timer_alloc(FUNC(mc68901_device::timer_count), this); + m_timer[TIMER_D] = timer_alloc(FUNC(mc68901_device::timer_count), this); /* register for state saving */ save_item(NAME(m_gpip)); @@ -500,17 +499,6 @@ void mc68901_device::device_reset() //------------------------------------------------- -// device_timer - handler timer events -//------------------------------------------------- - -void mc68901_device::device_timer(emu_timer &timer, device_timer_id id, int param) -{ - if(id >= TIMER_A && id <= TIMER_D) - timer_count(id); -} - - -//------------------------------------------------- // read - read from one MFP register //------------------------------------------------- @@ -696,7 +684,7 @@ void mc68901_device::write(offs_t offset, u8 data) { int divisor = PRESCALER[m_tacr & 0x07]; LOG("MC68901 Timer A Delay Mode : %u Prescale\n", divisor); - m_timer[TIMER_A]->adjust(attotime::from_hz(m_timer_clock / divisor), 0, attotime::from_hz(m_timer_clock / divisor)); + m_timer[TIMER_A]->adjust(attotime::from_hz(m_timer_clock / divisor), TIMER_A, attotime::from_hz(m_timer_clock / divisor)); } break; @@ -712,12 +700,8 @@ void mc68901_device::write(offs_t offset, u8 data) case TCR_TIMER_PULSE_64: case TCR_TIMER_PULSE_100: case TCR_TIMER_PULSE_200: - { - int divisor = PRESCALER[m_tacr & 0x07]; - LOG("MC68901 Timer A Pulse Width Mode : %u Prescale\n", divisor); - m_timer[TIMER_A]->adjust(attotime::never, 0, attotime::from_hz(m_timer_clock / divisor)); - m_timer[TIMER_A]->enable(false); - } + LOG("MC68901 Timer A Pulse Width Mode\n"); + m_timer[TIMER_A]->adjust(attotime::never); break; } @@ -749,9 +733,9 @@ void mc68901_device::write(offs_t offset, u8 data) case TCR_TIMER_DELAY_100: case TCR_TIMER_DELAY_200: { - int divisor = PRESCALER[m_tbcr & 0x07]; - LOG("MC68901 Timer B Delay Mode : %u Prescale\n", divisor); - m_timer[TIMER_B]->adjust(attotime::from_hz(m_timer_clock / divisor), 0, attotime::from_hz(m_timer_clock / divisor)); + int divisor = PRESCALER[m_tbcr & 0x07]; + LOG("MC68901 Timer B Delay Mode : %u Prescale\n", divisor); + m_timer[TIMER_B]->adjust(attotime::from_hz(m_timer_clock / divisor), TIMER_B, attotime::from_hz(m_timer_clock / divisor)); } break; @@ -767,12 +751,8 @@ void mc68901_device::write(offs_t offset, u8 data) case TCR_TIMER_PULSE_64: case TCR_TIMER_PULSE_100: case TCR_TIMER_PULSE_200: - { - int divisor = PRESCALER[m_tbcr & 0x07]; - LOG("MC68901 Timer B Pulse Width Mode : %u Prescale\n", DIVISOR); - m_timer[TIMER_B]->adjust(attotime::never, 0, attotime::from_hz(m_timer_clock / divisor)); - m_timer[TIMER_B]->enable(false); - } + LOG("MC68901 Timer B Pulse Width Mode\n"); + m_timer[TIMER_B]->adjust(attotime::never); break; } @@ -806,7 +786,7 @@ void mc68901_device::write(offs_t offset, u8 data) { int divisor = PRESCALER[m_tcdcr & 0x07]; LOG("MC68901 Timer D Delay Mode : %u Prescale\n", divisor); - m_timer[TIMER_D]->adjust(attotime::from_hz(m_timer_clock / divisor), 0, attotime::from_hz(m_timer_clock / divisor)); + m_timer[TIMER_D]->adjust(attotime::from_hz(m_timer_clock / divisor), TIMER_D, attotime::from_hz(m_timer_clock / divisor)); } break; } @@ -828,7 +808,7 @@ void mc68901_device::write(offs_t offset, u8 data) { int divisor = PRESCALER[(m_tcdcr >> 4) & 0x07]; LOG("MC68901 Timer C Delay Mode : %u Prescale\n", divisor); - m_timer[TIMER_C]->adjust(attotime::from_hz(m_timer_clock / divisor), 0, attotime::from_hz(m_timer_clock / divisor)); + m_timer[TIMER_C]->adjust(attotime::from_hz(m_timer_clock / divisor), TIMER_C, attotime::from_hz(m_timer_clock / divisor)); } break; } diff --git a/src/devices/machine/mc68901.h b/src/devices/machine/mc68901.h index de640fac657..0e992c78941 100644 --- a/src/devices/machine/mc68901.h +++ b/src/devices/machine/mc68901.h @@ -91,7 +91,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; void check_interrupts(); void take_interrupt(u16 mask); @@ -99,7 +98,7 @@ protected: void tx_error(); void rx_buffer_full(); void rx_error(); - void timer_count(int index); + TIMER_CALLBACK_MEMBER(timer_count); void timer_input(int index, int value); void gpio_input(int bit, int state); void gpio_output(); diff --git a/src/devices/machine/mccs1850.cpp b/src/devices/machine/mccs1850.cpp index abbddf5b9be..367b58af135 100644 --- a/src/devices/machine/mccs1850.cpp +++ b/src/devices/machine/mccs1850.cpp @@ -105,7 +105,7 @@ DEFINE_DEVICE_TYPE(MCCS1850, mccs1850_device, "mccs1850", "MCCS1850 RTC") //************************************************************************** -// INLINE HELPERS +// DEVICE FUNCTIONS //************************************************************************** //------------------------------------------------- @@ -247,7 +247,7 @@ inline void mccs1850_device::write_register(offs_t offset, uint8_t data) // advance_seconds - //------------------------------------------------- -inline void mccs1850_device::advance_seconds() +TIMER_CALLBACK_MEMBER(mccs1850_device::advance_seconds) { uint32_t alarm = (m_ram[REGISTER_ALARM_LATCH] << 24) | (m_ram[REGISTER_ALARM_LATCH + 1] << 16) | (m_ram[REGISTER_ALARM_LATCH + 2] << 8) | m_ram[REGISTER_ALARM_LATCH + 3]; @@ -324,7 +324,7 @@ void mccs1850_device::device_start() nuc_cb.resolve(); // allocate timers - m_clock_timer = timer_alloc(TIMER_CLOCK); + m_clock_timer = timer_alloc(FUNC(mccs1850_device::advance_seconds), this); m_clock_timer->adjust(attotime::from_hz(clock() / 32768), 0, attotime::from_hz(clock() / 32768)); // state saving @@ -356,21 +356,6 @@ void mccs1850_device::device_reset() //------------------------------------------------- -// device_timer - handler timer events -//------------------------------------------------- - -void mccs1850_device::device_timer(emu_timer &timer, device_timer_id id, int param) -{ - switch (id) - { - case TIMER_CLOCK: - advance_seconds(); - break; - } -} - - -//------------------------------------------------- // nvram_default - called to initialize NVRAM to // its default state //------------------------------------------------- diff --git a/src/devices/machine/mccs1850.h b/src/devices/machine/mccs1850.h index 87def943008..cdd3b2853bc 100644 --- a/src/devices/machine/mccs1850.h +++ b/src/devices/machine/mccs1850.h @@ -55,7 +55,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_nvram_interface overrides virtual void nvram_default() override; @@ -66,13 +65,11 @@ protected: virtual void rtc_clock_updated(int year, int month, int day, int day_of_week, int hour, int minute, int second) override; private: - inline void check_interrupt(); - inline void set_pse_line(bool state); - inline uint8_t read_register(offs_t offset); - inline void write_register(offs_t offset, uint8_t data); - inline void advance_seconds(); - - static const device_timer_id TIMER_CLOCK = 0; + void check_interrupt(); + void set_pse_line(bool state); + uint8_t read_register(offs_t offset); + void write_register(offs_t offset, uint8_t data); + TIMER_CALLBACK_MEMBER(advance_seconds); devcb_write_line int_cb, pse_cb, nuc_cb; diff --git a/src/devices/machine/mcf5206e.cpp b/src/devices/machine/mcf5206e.cpp index 640550fcdec..eb4695be03a 100644 --- a/src/devices/machine/mcf5206e.cpp +++ b/src/devices/machine/mcf5206e.cpp @@ -846,7 +846,7 @@ void mcf5206e_peripheral_device::device_start() { init_regs(true); - m_timer1 = machine().scheduler().timer_alloc( timer_expired_delegate( FUNC( mcf5206e_peripheral_device::timer1_callback ), this) ); + m_timer1 = timer_alloc( FUNC( mcf5206e_peripheral_device::timer1_callback ), this ); save_item(NAME(m_ICR)); save_item(NAME(m_CSAR)); diff --git a/src/devices/machine/meters.cpp b/src/devices/machine/meters.cpp index a1c9a77b076..fca2abc6e2a 100644 --- a/src/devices/machine/meters.cpp +++ b/src/devices/machine/meters.cpp @@ -1,11 +1,10 @@ // license:BSD-3-Clause // copyright-holders:James Wallace -/////////////////////////////////////////////////////////////////////////// -// // -// Electro mechanical meters // -// // -// // -/////////////////////////////////////////////////////////////////////////// +/********************************************************************** + + Electromechanical Meter device + +**********************************************************************/ #include "emu.h" #include "meters.h" @@ -30,19 +29,17 @@ meters_device::meters_device(const machine_config &mconfig, const char *tag, dev void meters_device::device_start() { - if ( m_number_mtr > MAXMECHMETERS ) + if (m_number_mtr > MAXMECHMETERS) m_number_mtr = MAXMECHMETERS; - for ( int i = 0; i < m_number_mtr; i++ ) + for (int i = 0; i < m_number_mtr; i++) { m_meter_info[i].reacttime = METERREACTTIME; m_meter_info[i].state = 0; m_meter_info[i].count = 0; m_meter_info[i].on = 0; - m_meter_info[i].meter_timer = timer_alloc(i); - m_meter_info[i].meter_timer->reset(); + m_meter_info[i].meter_timer = timer_alloc(FUNC(meters_device::count_tick), this); - //save_item(NAME(m_meter_info[i].reacttime), i); //enable if void ReactTime(int id, int32_t cycles) gets used save_item(NAME(m_meter_info[i].state), i); save_item(NAME(m_meter_info[i].count), i); save_item(NAME(m_meter_info[i].on), i); @@ -58,89 +55,42 @@ void meters_device::device_reset() } //------------------------------------------------- -// device_timer - device-specific timer events +// count_tick - advance the meter's counter //------------------------------------------------- -void meters_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(meters_device::count_tick) { - if (id >= m_number_mtr) - throw emu_fatalerror("Unknown id in meters_device::device_timer"); - m_meter_info[param].count++; } -/////////////////////////////////////////////////////////////////////////// - -int meters_device::GetNumberMeters(void) // currently unused -{ - return m_number_mtr; -} - -/////////////////////////////////////////////////////////////////////////// - -void meters_device::Setcount(int id, int32_t count) // currently unused -{ - if ( id >= m_number_mtr ) - return; - - m_meter_info[id].count = count; -} - -/////////////////////////////////////////////////////////////////////////// - -int32_t meters_device::Getcount(int id) // currently unused -{ - int32_t result = 0; - - if ( id < m_number_mtr ) - result = m_meter_info[id].count; - - return result; -} - -/////////////////////////////////////////////////////////////////////////// - -void meters_device::ReactTime(int id, int32_t cycles) // currently unused -{ - if ( id >= m_number_mtr ) - return; - - m_meter_info[id].reacttime = cycles; -} - -/////////////////////////////////////////////////////////////////////////// - -int meters_device::GetActivity(int id) +int meters_device::get_activity(int id) { return m_meter_info[id].on; } -/////////////////////////////////////////////////////////////////////////// - int meters_device::update(int id, int state) { - int res = 0; - - if ( id >= m_number_mtr ) - return res; + if (id >= m_number_mtr) + return 0; - state = state?1:0; + state = state ? 1 : 0; - if ( m_meter_info[id].state != state ) + if (m_meter_info[id].state != state) { // meter state is changing m_meter_info[id].state = state; - if ( state ) + if (state) { - m_meter_info[id].on =1; + m_meter_info[id].on = true; m_meter_info[id].meter_timer->adjust(attotime::from_seconds(m_meter_info[id].reacttime), id); } else { - m_meter_info[id].on =0; - m_meter_info[id].meter_timer->adjust(attotime::never, id); + m_meter_info[id].on = false; + m_meter_info[id].meter_timer->adjust(attotime::never); } } + return m_meter_info[id].on; } diff --git a/src/devices/machine/meters.h b/src/devices/machine/meters.h index b8da53bfe1b..e7dda1802d0 100644 --- a/src/devices/machine/meters.h +++ b/src/devices/machine/meters.h @@ -1,13 +1,10 @@ // license:BSD-3-Clause // copyright-holders:James Wallace -/////////////////////////////////////////////////////////////////////////// -// // -// Electro mechanical meters // -// // -// 23-07-2004: Re-Animator // -// // -// // -/////////////////////////////////////////////////////////////////////////// +/********************************************************************** + + Electromechanical Meter device + +**********************************************************************/ #ifndef MAME_MACHINE_METERS_H #define MAME_MACHINE_METERS_H @@ -18,36 +15,31 @@ class meters_device : public device_t { public: - static constexpr unsigned MAXMECHMETERS = 8; - - static constexpr double METERREACTTIME = 0.025; // number of seconds meter has to be active to tick - meters_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock); void set_number(int number) { m_number_mtr = number; } int update(int id, int state); - int GetActivity(int id); - - int GetNumberMeters(void); // currently unused - void Setcount(int id, int32_t count); // currently unused - int32_t Getcount(int id); // currently unused - void ReactTime(int id, int32_t cycles); // currently unused + int get_activity(int id); 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(count_tick); private: + static constexpr unsigned MAXMECHMETERS = 8; + static constexpr double METERREACTTIME = 0.025; // number of seconds meter has to be active to tick + // internal state struct meter_info { - bool on; // Activity of reel + bool on; // Reel active int32_t reacttime; - int32_t count; // mechmeter value - bool state; // state 0/1 + int32_t count; // Meter value + bool state; emu_timer *meter_timer; }; diff --git a/src/devices/machine/microtch.cpp b/src/devices/machine/microtch.cpp index dfcf1e52d3d..7f4562f02f1 100644 --- a/src/devices/machine/microtch.cpp +++ b/src/devices/machine/microtch.cpp @@ -80,10 +80,10 @@ microtouch_device::microtouch_device(const machine_config &mconfig, const char * int microtouch_device::check_command( const char* commandtocheck, int command_len, uint8_t* command_data ) { - if ( (command_len == (strlen(commandtocheck) + 2)) && + if ((command_len == (strlen(commandtocheck) + 2)) && (command_data[0] == 0x01) && (strncmp(commandtocheck, (const char*)command_data + 1, strlen(commandtocheck)) == 0) && - (command_data[command_len-1] == 0x0d) ) + (command_data[command_len-1] == 0x0d)) { return 1; } @@ -111,10 +111,10 @@ void microtouch_device::send_format_decimal_packet(int x, int y) int decx, decy; decx = x / 16; - if ( decx > 999 ) + if (decx > 999) decx = 999; decy = y / 16; - if ( decy > 999 ) + if (decy > 999) decy = 999; // header byte @@ -138,12 +138,11 @@ void microtouch_device::send_touch_packet() int tx = m_touchx->read(); int ty = m_touchy->read(); - if ( m_out_touch_cb.isnull() || - m_out_touch_cb( &tx, &ty ) != 0 ) + if (m_out_touch_cb.isnull() || m_out_touch_cb(&tx, &ty) != 0) { ty = 0x4000 - ty; - switch( m_format ) + switch (m_format) { case FORMAT_TABLET: send_format_table_packet(0xc8, tx, ty); @@ -160,54 +159,49 @@ void microtouch_device::send_touch_packet() } } -void microtouch_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(microtouch_device::update_output) { - if (!id) + if (m_tx_buffer_ptr < m_tx_buffer_num) { - if ( m_tx_buffer_ptr < m_tx_buffer_num ) + if (is_transmit_register_empty()) { - if(is_transmit_register_empty()) - { - m_output = m_tx_buffer[m_tx_buffer_ptr++]; - m_output_valid = true; - tra_complete(); - } - - if ( m_tx_buffer_ptr == m_tx_buffer_num ) - { - m_tx_buffer_ptr = m_tx_buffer_num = 0; - } - return; + m_output = m_tx_buffer[m_tx_buffer_ptr++]; + m_output_valid = true; + tra_complete(); } - if ( (m_reset_done == 0) || - (m_format == FORMAT_UNKNOWN) || - (m_mode != MODE_STREAM)) + if (m_tx_buffer_ptr == m_tx_buffer_num) { - return; + m_tx_buffer_ptr = m_tx_buffer_num = 0; } + return; + } - // send format tablet packet - if (m_touch->read()) - { - send_touch_packet(); - } - else + if (m_reset_done == 0 || m_format == FORMAT_UNKNOWN || m_mode != MODE_STREAM) + { + return; + } + + // send format tablet packet + if (m_touch->read()) + { + send_touch_packet(); + } + else + { + if (m_last_touch_state == 1) { - if ( m_last_touch_state == 1 ) + m_last_touch_state = 0; + switch (m_format) { - m_last_touch_state = 0; - switch( m_format ) - { - case FORMAT_TABLET: - send_format_table_packet(0x88, m_last_x, m_last_y); - break; - case FORMAT_DECIMAL: - send_format_decimal_packet(m_last_x, m_last_y); - break; - case FORMAT_UNKNOWN: - break; - } + case FORMAT_TABLET: + send_format_table_packet(0x88, m_last_x, m_last_y); + break; + case FORMAT_DECIMAL: + send_format_decimal_packet(m_last_x, m_last_y); + break; + case FORMAT_UNKNOWN: + break; } } } @@ -227,7 +221,7 @@ void microtouch_device::device_start() m_last_y = 0; m_last_touch_state = -1; - m_timer = timer_alloc(); + m_timer = timer_alloc(FUNC(microtouch_device::update_output), this); m_timer->adjust(attotime::from_hz(167*5), 0, attotime::from_hz(167*5)); m_format = FORMAT_UNKNOWN; @@ -261,10 +255,10 @@ void microtouch_device::rcv_complete() receive_register_extract(); m_rx_buffer[m_rx_buffer_ptr] = get_received_char(); m_rx_buffer_ptr++; - if(m_rx_buffer_ptr == 16) + if (m_rx_buffer_ptr == 16) return; - if (m_rx_buffer_ptr > 0 && (m_rx_buffer[m_rx_buffer_ptr-1] == 0x0d)) + if (m_rx_buffer_ptr > 0 && m_rx_buffer[m_rx_buffer_ptr-1] == 0x0d) { if (VERBOSE) { @@ -274,32 +268,32 @@ void microtouch_device::rcv_complete() LOG("Microtouch: received command %s\n", command); } // check command - if ( check_command( "MS", m_rx_buffer_ptr, m_rx_buffer ) ) + if (check_command("MS", m_rx_buffer_ptr, m_rx_buffer)) { m_mode = MODE_STREAM; } - else if ( check_command( "MI", m_rx_buffer_ptr, m_rx_buffer ) ) + else if (check_command("MI", m_rx_buffer_ptr, m_rx_buffer)) { m_mode = MODE_INACTIVE; } - else if ( check_command( "MP", m_rx_buffer_ptr, m_rx_buffer ) ) + else if (check_command("MP", m_rx_buffer_ptr, m_rx_buffer)) { m_mode = MODE_POINT; } - else if ( check_command( "R", m_rx_buffer_ptr, m_rx_buffer ) ) + else if (check_command("R", m_rx_buffer_ptr, m_rx_buffer)) { m_tx_buffer_num = 0; m_reset_done = 1; } - else if ( check_command( "FT", m_rx_buffer_ptr, m_rx_buffer ) ) + else if (check_command("FT", m_rx_buffer_ptr, m_rx_buffer)) { m_format = FORMAT_TABLET; } - else if ( check_command( "FD", m_rx_buffer_ptr, m_rx_buffer ) ) + else if (check_command("FD", m_rx_buffer_ptr, m_rx_buffer)) { m_format = FORMAT_DECIMAL; } - else if ( check_command("OI", m_rx_buffer_ptr, m_rx_buffer ) ) + else if (check_command("OI", m_rx_buffer_ptr, m_rx_buffer)) { // output identity - SMT3, ver 01.00 m_tx_buffer[m_tx_buffer_num++] = 0x01; @@ -313,7 +307,7 @@ void microtouch_device::rcv_complete() m_rx_buffer_ptr = 0; return; } - else if ( check_command("OS", m_rx_buffer_ptr, m_rx_buffer ) ) + else if (check_command("OS", m_rx_buffer_ptr, m_rx_buffer)) { // output status m_tx_buffer[m_tx_buffer_num++] = 0x01; @@ -347,9 +341,9 @@ void microtouch_device::rcv_complete() } } -INPUT_CHANGED_MEMBER( microtouch_device::touch ) +INPUT_CHANGED_MEMBER(microtouch_device::touch) { - if ( newval && ( m_mode == MODE_POINT ) ) + if (newval && (m_mode == MODE_POINT)) { send_touch_packet(); } @@ -368,11 +362,11 @@ ROM_END static INPUT_PORTS_START(microtouch) PORT_START("TOUCH") - PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_BUTTON1 ) PORT_NAME( "Touch screen" ) PORT_CHANGED_MEMBER( DEVICE_SELF,microtouch_device, touch, 0 ) + PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_BUTTON1) PORT_NAME("Touch screen") PORT_CHANGED_MEMBER(DEVICE_SELF, microtouch_device, touch, 0) PORT_START("TOUCH_X") - PORT_BIT( 0x3fff, 0x2000, IPT_LIGHTGUN_X ) PORT_CROSSHAIR(X, 1.0, 0.0, 0) PORT_SENSITIVITY(45) PORT_KEYDELTA(15) + PORT_BIT(0x3fff, 0x2000, IPT_LIGHTGUN_X) PORT_CROSSHAIR(X, 1.0, 0.0, 0) PORT_SENSITIVITY(45) PORT_KEYDELTA(15) PORT_START("TOUCH_Y") - PORT_BIT( 0x3fff, 0x2000, IPT_LIGHTGUN_Y ) PORT_CROSSHAIR(Y, 1.0, 0.0, 0) PORT_SENSITIVITY(45) PORT_KEYDELTA(15) + PORT_BIT(0x3fff, 0x2000, IPT_LIGHTGUN_Y) PORT_CROSSHAIR(Y, 1.0, 0.0, 0) PORT_SENSITIVITY(45) PORT_KEYDELTA(15) INPUT_PORTS_END ioport_constructor microtouch_device::device_input_ports() const @@ -387,7 +381,7 @@ void microtouch_device::tra_callback() void microtouch_device::tra_complete() { - if(m_output_valid) + if (m_output_valid) { transmit_register_setup(m_output); m_output_valid = false; diff --git a/src/devices/machine/microtch.h b/src/devices/machine/microtch.h index 3eba8bfbb68..b7242f4cca3 100644 --- a/src/devices/machine/microtch.h +++ b/src/devices/machine/microtch.h @@ -26,7 +26,6 @@ protected: // device_t implementation virtual ioport_constructor device_input_ports() const override; virtual void device_start() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; // device_serial_interface implementation virtual void tra_callback() override; @@ -36,6 +35,8 @@ protected: // ROM region (unused, as the device is HLE'd) virtual const tiny_rom_entry *device_rom_region() const override; + TIMER_CALLBACK_MEMBER(update_output); + private: int check_command( const char* commandtocheck, int command_len, uint8_t* command_data ); void send_format_table_packet(uint8_t flag, int x, int y); @@ -56,25 +57,25 @@ private: MODE_POINT }; - uint8_t m_rx_buffer[16]; + uint8_t m_rx_buffer[16]; int m_rx_buffer_ptr; - uint8_t m_tx_buffer[16]; - uint8_t m_tx_buffer_num; - uint8_t m_tx_buffer_ptr; + uint8_t m_tx_buffer[16]; + uint8_t m_tx_buffer_num; + uint8_t m_tx_buffer_ptr; int m_reset_done; int m_format; int m_mode; int m_last_touch_state; int m_last_x; int m_last_y; - touch_cb m_out_touch_cb; + touch_cb m_out_touch_cb; devcb_write_line m_out_stx_func; required_ioport m_touch; required_ioport m_touchx; required_ioport m_touchy; emu_timer* m_timer; - bool m_output_valid; - uint8_t m_output; + bool m_output_valid; + uint8_t m_output; }; DECLARE_DEVICE_TYPE(MICROTOUCH, microtouch_device) diff --git a/src/devices/machine/mm5307.cpp b/src/devices/machine/mm5307.cpp index 312d7cff86b..30032913ad0 100644 --- a/src/devices/machine/mm5307.cpp +++ b/src/devices/machine/mm5307.cpp @@ -140,7 +140,7 @@ void mm5307_device::device_resolve_objects() void mm5307_device::device_start() { // Create timer - m_periodic_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(mm5307_device::periodic_update), this)); + m_periodic_timer = timer_alloc(FUNC(mm5307_device::periodic_update), this); // Register for saving save_item(NAME(m_freq_control)); diff --git a/src/devices/machine/mm5740.cpp b/src/devices/machine/mm5740.cpp index 43a44024200..feabf787fe0 100644 --- a/src/devices/machine/mm5740.cpp +++ b/src/devices/machine/mm5740.cpp @@ -79,7 +79,7 @@ void mm5740_device::device_start() m_write_data_ready.resolve_safe(); // allocate timers - m_scan_timer = timer_alloc(); + m_scan_timer = timer_alloc(FUNC(mm5740_device::perform_scan), this); m_scan_timer->adjust(attotime::from_hz(clock()), 0, attotime::from_hz(clock())); // state saving @@ -97,12 +97,12 @@ void mm5740_device::device_reset() } //------------------------------------------------- -// device_timer - handler timer events +// perform_scan - scan the keyboard matrix //------------------------------------------------- -void mm5740_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(mm5740_device::perform_scan) { - int ako = 0; + bool ako = false; for (int x = 0; x < 9; x++) { @@ -116,7 +116,6 @@ void mm5740_device::device_timer(emu_timer &timer, device_timer_id id, int param for (int y = 0; y < 10; y++) { - if (BIT(data, y)) { uint8_t *rom = m_rom->base(); @@ -131,7 +130,7 @@ void mm5740_device::device_timer(emu_timer &timer, device_timer_id id, int param uint16_t b = (((common & 0x10) << 4) | ((uniq & 0x0f) << 4) | (common & 0x0f)) ^ 0x1ff; - ako = 1; + ako = true; if (!BIT(m_x_mask[x], y)) { diff --git a/src/devices/machine/mm5740.h b/src/devices/machine/mm5740.h index 91d2280f3fb..c1e4eb81f70 100644 --- a/src/devices/machine/mm5740.h +++ b/src/devices/machine/mm5740.h @@ -105,13 +105,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; virtual const tiny_rom_entry *device_rom_region() const override; + TIMER_CALLBACK_MEMBER(perform_scan); + private: devcb_read16::array<9> m_read_x; - devcb_read_line m_read_shift, m_read_control; + devcb_read_line m_read_shift; + devcb_read_line m_read_control; devcb_write_line m_write_data_ready; required_memory_region m_rom; // Internal ROM diff --git a/src/devices/machine/mm58167.cpp b/src/devices/machine/mm58167.cpp index b4f311408be..152a23de195 100644 --- a/src/devices/machine/mm58167.cpp +++ b/src/devices/machine/mm58167.cpp @@ -67,7 +67,7 @@ mm58167_device::mm58167_device(const machine_config &mconfig, const char *tag, d void mm58167_device::device_start() { // allocate timers - m_clock_timer = timer_alloc(); + m_clock_timer = timer_alloc(FUNC(mm58167_device::clock_tick), this); m_clock_timer->adjust(attotime::from_hz(clock() / 32.768f), 0, attotime::from_hz(clock() / 32.768f)); m_irq_w.resolve_safe(); @@ -94,10 +94,10 @@ void mm58167_device::device_reset() //------------------------------------------------- -// device_timer - handler timer events +// clock_tick - advance the RTC's registers //------------------------------------------------- -void mm58167_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(mm58167_device::clock_tick) { m_milliseconds++; diff --git a/src/devices/machine/mm58167.h b/src/devices/machine/mm58167.h index 08def7cd569..82cf173ca95 100644 --- a/src/devices/machine/mm58167.h +++ b/src/devices/machine/mm58167.h @@ -38,12 +38,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; // 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; virtual bool rtc_feature_leap_year() const override { return true; } + TIMER_CALLBACK_MEMBER(clock_tick); + void set_irq(int bit); void update_rtc(); diff --git a/src/devices/machine/mm58174.cpp b/src/devices/machine/mm58174.cpp index bf0759bea22..3d15060666a 100644 --- a/src/devices/machine/mm58174.cpp +++ b/src/devices/machine/mm58174.cpp @@ -50,9 +50,9 @@ mm58174_device::mm58174_device(const machine_config &mconfig, const char *tag, d void mm58174_device::device_start() { - m_increment_rtc = timer_alloc(); - m_increment_rtc->adjust(attotime::zero, 0, attotime::from_msec(100)); - m_interrupt_timer = timer_alloc(); + m_rtc_timer = timer_alloc(FUNC(mm58174_device::clock_tick), this); + m_rtc_timer->adjust(attotime::zero, 0, attotime::from_msec(100)); + m_interrupt_timer = timer_alloc(FUNC(mm58174_device::scheduler_sync), this); // register for state saving save_item(NAME(m_control)); @@ -282,10 +282,8 @@ void mm58174_device::write(offs_t offset, uint8_t data) // Increment RTC clock (timed interrupt every 1/10s) -void mm58174_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(mm58174_device::clock_tick) { - if (id > 0) return; - if (m_control & ctl_clkrun) { if ((++m_tenths) == 10) @@ -295,3 +293,12 @@ void mm58174_device::device_timer(emu_timer &timer, device_timer_id id, int para } } } + +// TODO: Investigate if this is necessary, or if there's missing functionality from the device. +// Prior to the device_timer removal, m_interrupt_timer was being allocated with the same default ID as m_rtc_timer. +// As there was no interrupt-related logic in the existing device_timer implementation, the only possible thing that +// m_interrupt_timer could possibly do, functionally, is force a scheduler sync by elapsing, and also cause the +// RTC to tick at an erroneous rate. +TIMER_CALLBACK_MEMBER(mm58174_device::scheduler_sync) +{ +} diff --git a/src/devices/machine/mm58174.h b/src/devices/machine/mm58174.h index 01db657255d..72fbfc85502 100644 --- a/src/devices/machine/mm58174.h +++ b/src/devices/machine/mm58174.h @@ -23,12 +23,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; // 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; virtual bool rtc_feature_leap_year() const override { return true; } + TIMER_CALLBACK_MEMBER(clock_tick); + TIMER_CALLBACK_MEMBER(scheduler_sync); + void update_rtc(); private: @@ -54,7 +56,7 @@ private: int m_seconds2; int m_tenths; /* tenths of second (BCD : 0-9) */ - emu_timer *m_increment_rtc; + emu_timer *m_rtc_timer; emu_timer *m_interrupt_timer; }; diff --git a/src/devices/machine/mm58274c.cpp b/src/devices/machine/mm58274c.cpp index c7e7f49a78e..cfc50472653 100644 --- a/src/devices/machine/mm58274c.cpp +++ b/src/devices/machine/mm58274c.cpp @@ -61,9 +61,9 @@ mm58274c_device::mm58274c_device(const machine_config &mconfig, const char *tag, void mm58274c_device::device_start() { - m_increment_rtc = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(mm58274c_device::rtc_increment_cb),this)); + m_increment_rtc = timer_alloc(FUNC(mm58274c_device::rtc_increment_cb), this); m_increment_rtc->adjust(attotime::zero, 0, attotime::from_msec(100)); - m_interrupt_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(mm58274c_device::rtc_interrupt_cb),this)); + m_interrupt_timer = timer_alloc(FUNC(mm58274c_device::rtc_interrupt_cb), this); // register for state saving save_item(NAME(m_mode24)); diff --git a/src/devices/machine/mm74c922.cpp b/src/devices/machine/mm74c922.cpp index af3fd1047d6..add765a1b1e 100644 --- a/src/devices/machine/mm74c922.cpp +++ b/src/devices/machine/mm74c922.cpp @@ -72,7 +72,7 @@ void mm74c922_device::device_start() change_output_lines(); // allocate timers - m_scan_timer = timer_alloc(); + m_scan_timer = timer_alloc(FUNC(mm74c922_device::perform_scan), this); m_scan_timer->adjust(attotime::zero, 0, attotime::from_hz(500)); // approximate rate from a 100n capacitor // register for state saving @@ -87,10 +87,10 @@ void mm74c922_device::device_start() //------------------------------------------------- -// device_timer - handler timer events +// perform_scan - scan the keyboard matrix //------------------------------------------------- -void mm74c922_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(mm74c922_device::perform_scan) { change_output_lines(); clock_scan_counters(); diff --git a/src/devices/machine/mm74c922.h b/src/devices/machine/mm74c922.h index bd265b87bfa..43c958bb4b7 100644 --- a/src/devices/machine/mm74c922.h +++ b/src/devices/machine/mm74c922.h @@ -67,7 +67,8 @@ 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(perform_scan); private: void change_output_lines(); diff --git a/src/devices/machine/mos6526.cpp b/src/devices/machine/mos6526.cpp index 0ccb524d233..a35d9a9c573 100644 --- a/src/devices/machine/mos6526.cpp +++ b/src/devices/machine/mos6526.cpp @@ -120,14 +120,14 @@ DEFINE_DEVICE_TYPE(MOS5710, mos5710_device, "mos5710", "MOS 5710 CIA") //************************************************************************** -// INLINE HELPERS +// DEVICE FUNCTIONS //************************************************************************** //------------------------------------------------- // update_pa - update port A //------------------------------------------------- -inline void mos6526_device::update_pa() +void mos6526_device::update_pa() { uint8_t pa = m_pra | (m_pa_in & ~m_ddra); @@ -143,7 +143,7 @@ inline void mos6526_device::update_pa() // update_pb - update port B //------------------------------------------------- -inline void mos6526_device::update_pb() +void mos6526_device::update_pb() { uint8_t pb = m_prb | (m_pb_in & ~m_ddrb); @@ -175,7 +175,7 @@ inline void mos6526_device::update_pb() // set_cra - control register A write //------------------------------------------------- -inline void mos6526_device::set_cra(uint8_t data) +void mos6526_device::set_cra(uint8_t data) { if (!CRA_STARTED && (data & CRA_START)) { @@ -205,7 +205,7 @@ inline void mos6526_device::set_cra(uint8_t data) // set_crb - control register B write //------------------------------------------------- -inline void mos6526_device::set_crb(uint8_t data) +void mos6526_device::set_crb(uint8_t data) { if (!CRB_STARTED && (data & CRB_START)) { @@ -221,7 +221,7 @@ inline void mos6526_device::set_crb(uint8_t data) // bcd_increment - //------------------------------------------------- -inline uint8_t mos6526_device::bcd_increment(uint8_t value) +uint8_t mos6526_device::bcd_increment(uint8_t value) { value++; @@ -236,7 +236,7 @@ inline uint8_t mos6526_device::bcd_increment(uint8_t value) // clock_tod - time-of-day clock pulse //------------------------------------------------- -inline void mos6526_device::clock_tod() +void mos6526_device::clock_tod() { uint8_t subsecond = (uint8_t) (m_tod >> 0); uint8_t second = (uint8_t) (m_tod >> 8); @@ -290,7 +290,7 @@ inline void mos6526_device::clock_tod() // clock_tod - time-of-day clock pulse //------------------------------------------------- -inline void mos8520_device::clock_tod() +void mos8520_device::clock_tod() { m_tod++; m_tod &= 0xffffff; @@ -301,7 +301,7 @@ inline void mos8520_device::clock_tod() // read_tod - time-of-day read //------------------------------------------------- -inline uint8_t mos6526_device::read_tod(int offset) +uint8_t mos6526_device::read_tod(int offset) { int shift = 8 * offset; @@ -320,7 +320,7 @@ inline uint8_t mos6526_device::read_tod(int offset) // write_tod - time-of-day write //------------------------------------------------- -inline void mos6526_device::write_tod(int offset, uint8_t data) +void mos6526_device::write_tod(int offset, uint8_t data) { int shift = 8 * offset; @@ -339,7 +339,7 @@ inline void mos6526_device::write_tod(int offset, uint8_t data) // serial_input - //------------------------------------------------- -inline void mos6526_device::serial_input() +void mos6526_device::serial_input() { m_shift <<= 1; m_bits++; @@ -360,7 +360,7 @@ inline void mos6526_device::serial_input() // clock_ta - clock timer A //------------------------------------------------- -inline void mos6526_device::clock_ta() +void mos6526_device::clock_ta() { if (m_count_a3) { @@ -394,7 +394,7 @@ inline void mos6526_device::clock_ta() // serial_output - //------------------------------------------------- -inline void mos6526_device::serial_output() +void mos6526_device::serial_output() { if (m_ta_out && CRA_SPMODE) { @@ -438,7 +438,7 @@ inline void mos6526_device::serial_output() // clock_tb - clock timer B //------------------------------------------------- -inline void mos6526_device::clock_tb() +void mos6526_device::clock_tb() { if (m_count_b3) { @@ -472,7 +472,7 @@ inline void mos6526_device::clock_tb() // update_interrupt - //------------------------------------------------- -inline void mos6526_device::update_interrupt() +void mos6526_device::update_interrupt() { if (!m_irq && m_ir1) { @@ -498,7 +498,7 @@ inline void mos6526_device::update_interrupt() // clock_pipeline - clock pipeline //------------------------------------------------- -inline void mos6526_device::clock_pipeline() +void mos6526_device::clock_pipeline() { // timer A pipeline m_count_a3 = m_count_a2; @@ -556,7 +556,7 @@ inline void mos6526_device::clock_pipeline() // synchronize - //------------------------------------------------- -inline void mos6526_device::synchronize() +void mos6526_device::synchronize() { if (!m_pc) { @@ -642,9 +642,9 @@ void mos6526_device::device_start() m_write_pb.resolve_safe(); // allocate timer - if (m_tod_clock > 0) + if (m_tod_clock != 0) { - m_tod_timer = timer_alloc(); + m_tod_timer = timer_alloc(FUNC(mos6526_device::advance_tod_clock), this); m_tod_timer->adjust(attotime::from_hz(m_tod_clock), 0, attotime::from_hz(m_tod_clock)); } @@ -758,11 +758,7 @@ void mos6526_device::device_reset() } -//------------------------------------------------- -// device_timer - handler timer events -//------------------------------------------------- - -void mos6526_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(mos6526_device::advance_tod_clock) { tod_w(1); tod_w(0); diff --git a/src/devices/machine/mos6526.h b/src/devices/machine/mos6526.h index f86cf960461..1f515271537 100644 --- a/src/devices/machine/mos6526.h +++ b/src/devices/machine/mos6526.h @@ -113,28 +113,29 @@ protected: // device-level overrides virtual void device_start() override; virtual void device_reset() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; virtual void execute_run() override; + TIMER_CALLBACK_MEMBER(advance_tod_clock); + int m_icount; const int m_variant; int m_tod_clock; - inline void update_interrupt(); - inline void update_pa(); - inline void update_pb(); - inline void set_cra(uint8_t data); - inline void set_crb(uint8_t data); - inline void serial_input(); - inline void serial_output(); - inline void clock_ta(); - inline void clock_tb(); - inline void clock_pipeline(); - inline uint8_t bcd_increment(uint8_t value); - virtual inline void clock_tod(); - inline uint8_t read_tod(int offset); - inline void write_tod(int offset, uint8_t data); - inline void synchronize(); + void update_interrupt(); + void update_pa(); + void update_pb(); + void set_cra(uint8_t data); + void set_crb(uint8_t data); + void serial_input(); + void serial_output(); + void clock_ta(); + void clock_tb(); + void clock_pipeline(); + uint8_t bcd_increment(uint8_t value); + virtual void clock_tod(); + uint8_t read_tod(int offset); + void write_tod(int offset, uint8_t data); + void synchronize(); devcb_write_line m_write_irq; devcb_write_line m_write_pc; @@ -232,7 +233,7 @@ public: void write(offs_t offset, uint8_t data); protected: - virtual inline void clock_tod() override; + virtual void clock_tod() override; }; diff --git a/src/devices/machine/mos6530.cpp b/src/devices/machine/mos6530.cpp index 45d2ec6cf29..3862b0699e8 100644 --- a/src/devices/machine/mos6530.cpp +++ b/src/devices/machine/mos6530.cpp @@ -66,7 +66,7 @@ void mos6530_device::device_start() m_out_pb_cb.resolve_safe(); /* allocate timers */ - m_timer = timer_alloc(TIMER_END_CALLBACK); + m_timer = timer_alloc(FUNC(mos6530_device::end_state), this); /* register for save states */ save_item(NAME(m_port[0].m_in)); @@ -153,36 +153,29 @@ uint8_t mos6530_device::get_timer() ***************************************************************************/ /*------------------------------------------------- - timer_end_callback - callback to process the - timer + end_state - callback to process the timer -------------------------------------------------*/ -void mos6530_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(mos6530_device::end_state) { - switch (id) - { - // deferred reset - case TIMER_END_CALLBACK: - assert(m_timerstate != TIMER_IDLE); + assert(m_timerstate != TIMER_IDLE); - /* if we finished counting, switch to the finishing state */ - if (m_timerstate == TIMER_COUNTING) - { - m_timerstate = TIMER_FINISHING; - m_timer->adjust(attotime::from_ticks(256, m_clock)); + /* if we finished counting, switch to the finishing state */ + if (m_timerstate == TIMER_COUNTING) + { + m_timerstate = TIMER_FINISHING; + m_timer->adjust(attotime::from_ticks(256, m_clock)); - /* signal timer IRQ as well */ - m_irqstate |= TIMER_FLAG; - update_irqstate(); - } + /* signal timer IRQ as well */ + m_irqstate |= TIMER_FLAG; + update_irqstate(); + } - /* if we finished finishing, switch to the idle state */ - else if (m_timerstate == TIMER_FINISHING) - { - m_timerstate = TIMER_IDLE; - m_timer->adjust(attotime::never); - } - break; + /* if we finished finishing, switch to the idle state */ + else if (m_timerstate == TIMER_FINISHING) + { + m_timerstate = TIMER_IDLE; + m_timer->adjust(attotime::never); } } diff --git a/src/devices/machine/mos6530.h b/src/devices/machine/mos6530.h index f6385a32ec6..25e11a38f97 100644 --- a/src/devices/machine/mos6530.h +++ b/src/devices/machine/mos6530.h @@ -66,14 +66,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; -private: - enum - { - TIMER_END_CALLBACK - }; + TIMER_CALLBACK_MEMBER(end_state); +private: struct mos6530_port { uint8_t m_in; diff --git a/src/devices/machine/mos6530n.cpp b/src/devices/machine/mos6530n.cpp index 384b35375a8..aeaef720af5 100644 --- a/src/devices/machine/mos6530n.cpp +++ b/src/devices/machine/mos6530n.cpp @@ -184,7 +184,7 @@ void mos6530_device_base::device_start() m_out_pb_cb.resolve_all_safe(); // allocate timer - t_gen = timer_alloc(0); + t_gen = timer_alloc(FUNC(mos6530_device_base::update), this); // state saving save_item(NAME(m_pa_in)); @@ -239,10 +239,10 @@ void mos6530_device_base::device_reset() //------------------------------------------------- -// device_timer - handler timer events +// update - update the current device state //------------------------------------------------- -void mos6530_device_base::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(mos6530_device_base::update) { live_sync(); live_run(); diff --git a/src/devices/machine/mos6530n.h b/src/devices/machine/mos6530n.h index ee246e1eb69..0f1aa96a05e 100644 --- a/src/devices/machine/mos6530n.h +++ b/src/devices/machine/mos6530n.h @@ -101,7 +101,8 @@ protected: // device-level overrides virtual void device_start() override; virtual void device_reset() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; + + TIMER_CALLBACK_MEMBER(update); enum { diff --git a/src/devices/machine/mpu401.cpp b/src/devices/machine/mpu401.cpp index e4099571fc4..e2959a432a9 100644 --- a/src/devices/machine/mpu401.cpp +++ b/src/devices/machine/mpu401.cpp @@ -127,7 +127,7 @@ mpu401_device::mpu401_device(const machine_config &mconfig, const char *tag, dev void mpu401_device::device_start() { write_irq.resolve_safe(); - m_timer = timer_alloc(0); + m_timer = timer_alloc(FUNC(mpu401_device::serial_tick), this); } //------------------------------------------------- @@ -145,10 +145,10 @@ void mpu401_device::device_reset() } //------------------------------------------------- -// device_timer - called when our device timer expires +// serial_tick - update the 6801's serial clock //------------------------------------------------- -void mpu401_device::device_timer(emu_timer &timer, device_timer_id tid, int param) +TIMER_CALLBACK_MEMBER(mpu401_device::serial_tick) { m_ourcpu->m6801_clock_serial(); } diff --git a/src/devices/machine/mpu401.h b/src/devices/machine/mpu401.h index e2a0cd5cdab..a76cc53dcdd 100644 --- a/src/devices/machine/mpu401.h +++ b/src/devices/machine/mpu401.h @@ -28,9 +28,10 @@ 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 device_add_mconfig(machine_config &config) override; + TIMER_CALLBACK_MEMBER(serial_tick); + private: void midi_rx_w(int state); diff --git a/src/devices/machine/msm5832.cpp b/src/devices/machine/msm5832.cpp index 5459fd77fc6..65db2dda469 100644 --- a/src/devices/machine/msm5832.cpp +++ b/src/devices/machine/msm5832.cpp @@ -110,7 +110,7 @@ msm5832_device::msm5832_device(const machine_config &mconfig, const char *tag, d void msm5832_device::device_start() { // allocate timers - m_clock_timer = timer_alloc(TIMER_CLOCK); + m_clock_timer = timer_alloc(FUNC(msm5832_device::clock_tick), this); m_clock_timer->adjust(attotime::from_hz(clock() / 32768), 0, attotime::from_hz(clock() / 32768)); // state saving @@ -125,19 +125,14 @@ void msm5832_device::device_start() //------------------------------------------------- -// device_timer - handler timer events +// clock_tick - advance the RTC if enabled //------------------------------------------------- -void msm5832_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(msm5832_device::clock_tick) { - switch (id) + if (!m_hold) { - case TIMER_CLOCK: - if (!m_hold) - { - advance_seconds(); - } - break; + advance_seconds(); } } diff --git a/src/devices/machine/msm5832.h b/src/devices/machine/msm5832.h index 82988d5b023..2e55dc21b97 100644 --- a/src/devices/machine/msm5832.h +++ b/src/devices/machine/msm5832.h @@ -56,14 +56,13 @@ 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_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; -private: - static constexpr device_timer_id TIMER_CLOCK = 0; + TIMER_CALLBACK_MEMBER(clock_tick); +private: inline int read_counter(int counter); inline void write_counter(int counter, int value); diff --git a/src/devices/machine/msm58321.cpp b/src/devices/machine/msm58321.cpp index 9dc1f8df642..72aa2b09d33 100644 --- a/src/devices/machine/msm58321.cpp +++ b/src/devices/machine/msm58321.cpp @@ -209,15 +209,15 @@ void msm58321_device::device_start() m_busy_handler.resolve_safe(); // allocate timers - m_clock_timer = timer_alloc(TIMER_CLOCK); + m_clock_timer = timer_alloc(FUNC(msm58321_device::clock_tick), this); m_clock_timer->adjust(clocks_to_attotime(32768/1024), 0, clocks_to_attotime(32768/1024)); // busy signal active period is approximately 427 µs - m_busy_timer = timer_alloc(TIMER_BUSY); + m_busy_timer = timer_alloc(FUNC(msm58321_device::release_busy), this); m_busy_timer->adjust(clocks_to_attotime(32768 - 14), 0, clocks_to_attotime(32768)); // standard signal active period is approximately 122 µs - m_standard_timer = timer_alloc(TIMER_STANDARD); + m_standard_timer = timer_alloc(FUNC(msm58321_device::assert_standard), this); m_standard_timer->adjust(clocks_to_attotime(32768-4), 0, clocks_to_attotime(32768)); // state saving @@ -244,56 +244,59 @@ void msm58321_device::device_start() //------------------------------------------------- -// device_timer - handler timer events +// clock_tick - advance the RTC //------------------------------------------------- -void msm58321_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(msm58321_device::clock_tick) { - switch (id) + if (m_khz_ctr & 1) { - case TIMER_CLOCK: + m_reg[REGISTER_REF0] |= 1; + m_reg[REGISTER_REF1] |= 1; + } + else + { + m_reg[REGISTER_REF0] &= ~1; + m_reg[REGISTER_REF1] &= ~1; + } - if (m_khz_ctr & 1) + if (++m_khz_ctr >= 1024) + { + m_khz_ctr = 0; + if (!m_stop) { - m_reg[REGISTER_REF0] |= 1; - m_reg[REGISTER_REF1] |= 1; + advance_seconds(); } - else + + if (!m_busy) { - m_reg[REGISTER_REF0] &= ~1; - m_reg[REGISTER_REF1] &= ~1; + m_busy = 1; + m_busy_handler(m_busy); } + } +} - if (++m_khz_ctr >= 1024) - { - m_khz_ctr = 0; - if (!m_stop) - { - advance_seconds(); - } - if (!m_busy) - { - m_busy = 1; - m_busy_handler(m_busy); - } - } - break; +//------------------------------------------------- +// release_busy - release the 'busy' line after +// an appropriate amount of time +//------------------------------------------------- - case TIMER_BUSY: - if (!m_cs1 || !m_cs2 || !m_write || m_address != REGISTER_RESET) - { - m_busy = 0; - m_busy_handler(m_busy); - } - break; - case TIMER_STANDARD: - m_reg[REGISTER_REF0] = 0x0e; - m_reg[REGISTER_REF1] = 0x0e; - break; +TIMER_CALLBACK_MEMBER(msm58321_device::release_busy) +{ + if (!m_cs1 || !m_cs2 || !m_write || m_address != REGISTER_RESET) + { + m_busy = 0; + m_busy_handler(m_busy); } } +TIMER_CALLBACK_MEMBER(msm58321_device::assert_standard) +{ + m_reg[REGISTER_REF0] = 0x0e; + m_reg[REGISTER_REF1] = 0x0e; +} + void msm58321_device::update_standard() { uint8_t reg = 0; diff --git a/src/devices/machine/msm58321.h b/src/devices/machine/msm58321.h index 323e2e9daa2..6f28b05eecf 100644 --- a/src/devices/machine/msm58321.h +++ b/src/devices/machine/msm58321.h @@ -73,7 +73,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_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; @@ -85,11 +84,11 @@ protected: virtual bool nvram_write(util::write_stream &file) override; virtual bool rtc_feature_leap_year() const override { return true; } -private: - static constexpr device_timer_id TIMER_CLOCK = 0; - static constexpr device_timer_id TIMER_BUSY = 1; - static constexpr device_timer_id TIMER_STANDARD = 2; + TIMER_CALLBACK_MEMBER(clock_tick); + TIMER_CALLBACK_MEMBER(release_busy); + TIMER_CALLBACK_MEMBER(assert_standard); +private: void update_input(); void update_output(); void update_standard(); diff --git a/src/devices/machine/msm6242.cpp b/src/devices/machine/msm6242.cpp index 14f206d15c7..c7beb22694a 100644 --- a/src/devices/machine/msm6242.cpp +++ b/src/devices/machine/msm6242.cpp @@ -100,7 +100,7 @@ void msm6242_device::device_start() m_out_int_handler.resolve(); // let's call the timer callback every tick - m_timer = timer_alloc(TIMER_RTC_CALLBACK); + m_timer = timer_alloc(FUNC(msm6242_device::rtc_timer_callback), this); m_timer->adjust(attotime::zero); // set up registers @@ -164,22 +164,6 @@ void msm6242_device::device_post_load() //------------------------------------------------- -// device_timer - called whenever a device timer -// fires -//------------------------------------------------- - -void msm6242_device::device_timer(emu_timer &timer, device_timer_id id, int param) -{ - switch(id) - { - case TIMER_RTC_CALLBACK: - rtc_timer_callback(); - break; - } -} - - -//------------------------------------------------- // set_irq - set the IRQ flag and output //------------------------------------------------- @@ -377,7 +361,7 @@ void msm6242_device::rtc_clock_updated(int year, int month, int day, int day_of_ // rtc_timer_callback //------------------------------------------------- -void msm6242_device::rtc_timer_callback() +TIMER_CALLBACK_MEMBER(msm6242_device::rtc_timer_callback) { update_rtc_registers(); update_timer(); diff --git a/src/devices/machine/msm6242.h b/src/devices/machine/msm6242.h index 17afe8794d2..427a2337d24 100644 --- a/src/devices/machine/msm6242.h +++ b/src/devices/machine/msm6242.h @@ -62,7 +62,6 @@ protected: virtual void device_reset() 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; // rtc overrides virtual void rtc_clock_updated(int year, int month, int day, int day_of_week, int hour, int minute, int second) override; @@ -87,7 +86,7 @@ private: u64 m_last_update_time; // last update time, in clock cycles // methods - void rtc_timer_callback(); + TIMER_CALLBACK_MEMBER(rtc_timer_callback); u64 current_time(); void set_irq(bool active); void irq(u8 irq_type); diff --git a/src/devices/machine/myb3k_kbd.cpp b/src/devices/machine/myb3k_kbd.cpp index 9fb46201fd2..768ae3bda91 100644 --- a/src/devices/machine/myb3k_kbd.cpp +++ b/src/devices/machine/myb3k_kbd.cpp @@ -124,7 +124,6 @@ #include "emu.h" #include "myb3k_kbd.h" -//#define LOG_GENERAL (1U << 0) //defined in logmacro.h already #define LOG_MOD (1U << 1) #define LOG_BYTES (1U << 2) @@ -356,13 +355,16 @@ ioport_constructor myb3k_keyboard_device::device_input_ports() const void myb3k_keyboard_device::device_start() { m_keyboard_cb.resolve(); + m_scan_timer = timer_alloc(FUNC(myb3k_keyboard_device::scan_keys), this); + m_first_byte_timer = timer_alloc(FUNC(myb3k_keyboard_device::send_first_byte), this); + m_second_byte_timer = timer_alloc(FUNC(myb3k_keyboard_device::send_second_byte), this); } void myb3k_keyboard_device::device_reset() { m_modifier_keys = 0; memset(m_io_kbd_state, 0, sizeof(m_io_kbd_state)); - timer_set(attotime::from_msec(100), TIMER_ID_SCAN_KEYS); + m_scan_timer->adjust(attotime::from_msec(100)); m_modifier_keys = 0; } @@ -391,7 +393,7 @@ void myb3k_keyboard_device::key_changed(int x, int y, bool pressed) (y & 0x7); } -void myb3k_keyboard_device::scan_keys() +TIMER_CALLBACK_MEMBER(myb3k_keyboard_device::scan_keys) { // Iterate over all columns (m_x) // and for each column iterate over all rows (m_y) @@ -408,7 +410,7 @@ void myb3k_keyboard_device::scan_keys() update_modifiers(m_y, bit); } - timer_set(attotime::from_msec(3), TIMER_ID_FIRST_BYTE); + m_first_byte_timer->adjust(attotime::from_msec(3)); wait_for_timer = true; } @@ -420,7 +422,7 @@ void myb3k_keyboard_device::scan_keys() m_y = 0; // Done scanning the matrix. Now sleep for a while, // then start scanning again. Scan ~50 times per second. - timer_set(attotime::from_msec(20), TIMER_ID_SCAN_KEYS); + m_scan_timer->adjust(attotime::from_msec(20)); wait_for_timer = true; // (The final switch x=11 y=7 is not electrically connected. // Thus if we get here, then there can be no key changed @@ -456,31 +458,24 @@ void myb3k_keyboard_device::update_modifiers(int y, bool down) m_modifier_keys = (m_modifier_keys & mask) | (down?bit:0); } -void myb3k_keyboard_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(myb3k_keyboard_device::send_first_byte) { - switch (id) - { - case TIMER_ID_SCAN_KEYS: - scan_keys(); - break; + LOGBYTES("FIRST_BYTE %02x %s (with modifiers %s%s%s%s%s)\n", m_first_byte, + (m_first_byte&MYB3K_KEY_ON)?"Pressed":"Released", + (m_first_byte&MYB3K_KEY_CTRL)?"CTRL ":"", + (m_first_byte&MYB3K_KEY_GRAPH)?"GRAPH ":"", + (m_first_byte&MYB3K_KEY_LSHIFT)?"LSHIFT ":"", + (m_first_byte&MYB3K_KEY_RSHIFT)?"RSHIFT ":"", + (m_first_byte&MYB3K_KEY_CAP)?"CAP ":""); + send_byte(m_first_byte); + m_second_byte_timer->adjust(attotime::from_msec(3)); +} - case TIMER_ID_FIRST_BYTE: - LOGBYTES("FIRST_BYTE %02x %s (with modifiers %s%s%s%s%s)\n", m_first_byte, - (m_first_byte&MYB3K_KEY_ON)?"Pressed":"Released", - (m_first_byte&MYB3K_KEY_CTRL)?"CTRL ":"", - (m_first_byte&MYB3K_KEY_GRAPH)?"GRAPH ":"", - (m_first_byte&MYB3K_KEY_LSHIFT)?"LSHIFT ":"", - (m_first_byte&MYB3K_KEY_RSHIFT)?"RSHIFT ":"", - (m_first_byte&MYB3K_KEY_CAP)?"CAP ":""); - send_byte(m_first_byte); - timer_set(attotime::from_msec(3), TIMER_ID_SECOND_BYTE); - break; - case TIMER_ID_SECOND_BYTE: - LOGBYTES("SECOND_BYTE %02x x=%d y=%d \n\n\n", m_second_byte, (m_second_byte >> 3)&0xf, (m_second_byte)&0x7); - send_byte(m_second_byte); - timer_set(attotime::from_msec(10), TIMER_ID_SCAN_KEYS); - break; - } +TIMER_CALLBACK_MEMBER(myb3k_keyboard_device::send_second_byte) +{ + LOGBYTES("SECOND_BYTE %02x x=%d y=%d \n\n\n", m_second_byte, (m_second_byte >> 3)&0xf, (m_second_byte)&0x7); + send_byte(m_second_byte); + m_scan_timer->adjust(attotime::from_msec(10)); } stepone_keyboard_device::stepone_keyboard_device( diff --git a/src/devices/machine/myb3k_kbd.h b/src/devices/machine/myb3k_kbd.h index 752c8e32546..fa8f6570640 100644 --- a/src/devices/machine/myb3k_kbd.h +++ b/src/devices/machine/myb3k_kbd.h @@ -36,13 +36,6 @@ public: device_t *owner, u32 clock); - enum - { - TIMER_ID_SCAN_KEYS, - TIMER_ID_FIRST_BYTE, - TIMER_ID_SECOND_BYTE - }; - template <typename... T> void set_keyboard_callback(T &&... args) { @@ -61,15 +54,21 @@ protected: virtual void device_reset() override; virtual void send_byte(u8 code); void key_changed(int x, int y, bool down); - void scan_keys(); void update_modifiers(int y, bool down); - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; + + TIMER_CALLBACK_MEMBER(scan_keys); + TIMER_CALLBACK_MEMBER(send_first_byte); + TIMER_CALLBACK_MEMBER(send_second_byte); output_delegate m_keyboard_cb; required_ioport_array<12> m_io_kbd_t; u8 m_io_kbd_state[12][8]; - int m_x, m_y; + emu_timer *m_scan_timer; + emu_timer *m_first_byte_timer; + emu_timer *m_second_byte_timer; + int m_x; + int m_y; u8 m_first_byte; u8 m_second_byte; u8 m_modifier_keys; diff --git a/src/devices/machine/ncr5380.cpp b/src/devices/machine/ncr5380.cpp index 9eeafad0587..96a1c549bf7 100644 --- a/src/devices/machine/ncr5380.cpp +++ b/src/devices/machine/ncr5380.cpp @@ -72,7 +72,7 @@ void ncr5380_device::device_start() m_irq_handler.resolve_safe(); m_drq_handler.resolve_safe(); - m_state_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(ncr5380_device::state_timer), this)); + m_state_timer = timer_alloc(FUNC(ncr5380_device::state_timer), this); save_item(NAME(m_state)); diff --git a/src/devices/machine/ncr5390.cpp b/src/devices/machine/ncr5390.cpp index c9f55ad655e..7a52d237982 100644 --- a/src/devices/machine/ncr5390.cpp +++ b/src/devices/machine/ncr5390.cpp @@ -199,7 +199,7 @@ void ncr5390_device::device_start() config = 0; bus_id = 0; select_timeout = 0; - tm = timer_alloc(0); + tm = timer_alloc(FUNC(ncr5390_device::update_tick), this); } void ncr5390_device::device_reset() @@ -251,7 +251,7 @@ void ncr5390_device::scsi_ctrl_changed() step(false); } -void ncr5390_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(ncr5390_device::update_tick) { step(true); } diff --git a/src/devices/machine/ncr5390.h b/src/devices/machine/ncr5390.h index 98a4cb40701..ba38e1b52cf 100644 --- a/src/devices/machine/ncr5390.h +++ b/src/devices/machine/ncr5390.h @@ -52,7 +52,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(update_tick); enum { MODE_D, MODE_T, MODE_I }; enum { IDLE }; diff --git a/src/devices/machine/ncr539x.cpp b/src/devices/machine/ncr539x.cpp index 90b2e6bb8ec..67cfdadae76 100644 --- a/src/devices/machine/ncr539x.cpp +++ b/src/devices/machine/ncr539x.cpp @@ -137,7 +137,7 @@ void ncr539x_device::device_start() m_out_irq_cb.resolve_safe(); m_out_drq_cb.resolve_safe(); - m_operation_timer = timer_alloc(0); + m_operation_timer = timer_alloc(FUNC(ncr539x_device::execute_operation), this); } //------------------------------------------------- @@ -177,107 +177,99 @@ void ncr539x_device::dma_write_data(int bytes, uint8_t *pData) write_data(pData, bytes); } -void ncr539x_device::device_timer(emu_timer &timer, device_timer_id tid, int param) +TIMER_CALLBACK_MEMBER(ncr539x_device::execute_operation) { - //printf("539X: device_timer expired, param = %d, m_command = %02x\n", param, m_command); + //printf("539X: m_operation_timer expired, param = %d, m_command = %02x\n", param, m_command); - switch (param) + // if this is a DMA command, raise DRQ now + if (m_command & 0x80) { - case TIMER_539X_COMMAND: - // if this is a DMA command, raise DRQ now - if (m_command & 0x80) - { - m_out_drq_cb(ASSERT_LINE); - } + m_out_drq_cb(ASSERT_LINE); + } - switch (m_command & 0x7f) + switch (m_command & 0x7f) + { + case 0x41: // select without ATN steps + if (select(m_last_id)) { - case 0x41: // select without ATN steps - if (select(m_last_id)) - { - m_irq_status |= IRQ_STATUS_SERVICE_REQUEST | IRQ_STATUS_SUCCESS; - // we should now be in the command phase - m_status &= ~7; // clear bus phases - m_status |= MAIN_STATUS_INTERRUPT | SCSI_PHASE_COMMAND; - m_fifo_ptr = 0; - m_selected = true; - - LOG("Selecting w/o ATN, irq_status = %02x, status = %02x!\n", m_irq_status, m_status); - - // if DMA is not enabled, there should already be a command loaded into the FIFO - if (!(m_command & 0x80)) - { - exec_fifo(); - } - update_fifo_internal_state(0); - } - else - { - LOG("Select failed, no device @ ID %d!\n", m_last_id); - m_status |= MAIN_STATUS_INTERRUPT; - m_irq_status |= IRQ_STATUS_DISCONNECTED; - } - m_out_irq_cb(ASSERT_LINE); - break; + m_irq_status |= IRQ_STATUS_SERVICE_REQUEST | IRQ_STATUS_SUCCESS; + // we should now be in the command phase + m_status &= ~7; // clear bus phases + m_status |= MAIN_STATUS_INTERRUPT | SCSI_PHASE_COMMAND; + m_fifo_ptr = 0; + m_selected = true; - case 0x42: // Select with ATN steps - if (select(m_last_id)) - { - m_irq_status |= IRQ_STATUS_SERVICE_REQUEST | IRQ_STATUS_SUCCESS; - // we should now be in the command phase - m_status &= ~7; // clear bus phases - m_status |= MAIN_STATUS_INTERRUPT | SCSI_PHASE_COMMAND; - m_fifo_ptr = 0; - m_selected = true; - LOG("Selecting with ATN, irq_status = %02x, status = %02x!\n", m_irq_status, m_status); + LOG("Selecting w/o ATN, irq_status = %02x, status = %02x!\n", m_irq_status, m_status); - // if DMA is not enabled, there should already be a command loaded into the FIFO - if (!(m_command & 0x80)) - { - exec_fifo(); - } - update_fifo_internal_state(0); - } - else - { - LOG("Select failed, no device @ ID %d!\n", m_last_id); - m_status |= MAIN_STATUS_INTERRUPT; - m_irq_status |= IRQ_STATUS_DISCONNECTED; - } - m_out_irq_cb(ASSERT_LINE); - break; + // if DMA is not enabled, there should already be a command loaded into the FIFO + if (!(m_command & 0x80)) + { + exec_fifo(); + } + update_fifo_internal_state(0); + } + else + { + LOG("Select failed, no device @ ID %d!\n", m_last_id); + m_status |= MAIN_STATUS_INTERRUPT; + m_irq_status |= IRQ_STATUS_DISCONNECTED; + } + m_out_irq_cb(ASSERT_LINE); + break; - case 0x11: // initiator command complete - LOG("Initiator command complete\n"); - m_irq_status = IRQ_STATUS_SERVICE_REQUEST; - m_status &= ~7; // clear phase bits - m_status |= MAIN_STATUS_INTERRUPT | SCSI_PHASE_DATAIN; // go to data in phase (?) - m_out_irq_cb(ASSERT_LINE); + case 0x42: // Select with ATN steps + if (select(m_last_id)) + { + m_irq_status |= IRQ_STATUS_SERVICE_REQUEST | IRQ_STATUS_SUCCESS; + // we should now be in the command phase + m_status &= ~7; // clear bus phases + m_status |= MAIN_STATUS_INTERRUPT | SCSI_PHASE_COMMAND; + m_fifo_ptr = 0; + m_selected = true; + LOG("Selecting with ATN, irq_status = %02x, status = %02x!\n", m_irq_status, m_status); + + // if DMA is not enabled, there should already be a command loaded into the FIFO + if (!(m_command & 0x80)) + { + exec_fifo(); + } + update_fifo_internal_state(0); + } + else + { + LOG("Select failed, no device @ ID %d!\n", m_last_id); + m_status |= MAIN_STATUS_INTERRUPT; + m_irq_status |= IRQ_STATUS_DISCONNECTED; + } + m_out_irq_cb(ASSERT_LINE); + break; - // this puts status and message bytes into the FIFO (todo: what are these?) - m_fifo_ptr = 0; - m_xfer_count = 2; - m_buffer_remaining = m_total_data = 0; - m_fifo[0] = 0; // status byte - m_fifo[1] = 0; // message byte - m_selected = false; - update_fifo_internal_state(2); - break; + case 0x11: // initiator command complete + LOG("Initiator command complete\n"); + m_irq_status = IRQ_STATUS_SERVICE_REQUEST; + m_status &= ~7; // clear phase bits + m_status |= MAIN_STATUS_INTERRUPT | SCSI_PHASE_DATAIN; // go to data in phase (?) + m_out_irq_cb(ASSERT_LINE); - case 0x12: // message accepted - LOG("Message accepted\n"); - m_irq_status = IRQ_STATUS_SERVICE_REQUEST; - m_status |= MAIN_STATUS_INTERRUPT; - m_out_irq_cb(ASSERT_LINE); - break; + // this puts status and message bytes into the FIFO (todo: what are these?) + m_fifo_ptr = 0; + m_xfer_count = 2; + m_buffer_remaining = m_total_data = 0; + m_fifo[0] = 0; // status byte + m_fifo[1] = 0; // message byte + m_selected = false; + update_fifo_internal_state(2); + break; - default: - fatalerror("539x: Unhandled command %02x\n", m_command); - } + case 0x12: // message accepted + LOG("Message accepted\n"); + m_irq_status = IRQ_STATUS_SERVICE_REQUEST; + m_status |= MAIN_STATUS_INTERRUPT; + m_out_irq_cb(ASSERT_LINE); break; default: - break; + fatalerror("539x: Unhandled command %02x\n", m_command); } } @@ -614,11 +606,11 @@ void ncr539x_device::write(offs_t offset, uint8_t data) // 1x commands happen much faster if ((m_command & 0x70) == 0x10) { - m_operation_timer->adjust(attotime::from_hz(65536), TIMER_539X_COMMAND); + m_operation_timer->adjust(attotime::from_hz(65536)); } else { - m_operation_timer->adjust(attotime::from_hz(16384), TIMER_539X_COMMAND); + m_operation_timer->adjust(attotime::from_hz(16384)); } break; } diff --git a/src/devices/machine/ncr539x.h b/src/devices/machine/ncr539x.h index 62fd58a8e47..9ba24b3ba47 100644 --- a/src/devices/machine/ncr539x.h +++ b/src/devices/machine/ncr539x.h @@ -35,7 +35,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(execute_operation); private: void fifo_write(uint8_t data); diff --git a/src/devices/machine/netlist.cpp b/src/devices/machine/netlist.cpp index 536d97367b9..973a5f2cb25 100644 --- a/src/devices/machine/netlist.cpp +++ b/src/devices/machine/netlist.cpp @@ -343,18 +343,18 @@ void netlist_mame_device::register_memregion_source(netlist::nlparse_t &parser, void netlist_mame_analog_input_device::write(const double val) { - m_value_for_device_timer = val * m_mult + m_offset; - if (m_value_for_device_timer != (*m_param)()) + m_value_to_sync = val * m_mult + m_offset; + if (m_value_to_sync != (*m_param)()) { - synchronize(); + machine().scheduler().synchronize(timer_expired_delegate(FUNC(netlist_mame_analog_input_device::sync_callback), this)); } } -void netlist_mame_analog_input_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(netlist_mame_analog_input_device::sync_callback) { update_to_current_time(); - nl_owner().log_csv().log_add(m_param_name, m_value_for_device_timer, true); - m_param->set(m_value_for_device_timer); + nl_owner().log_csv().log_add(m_param_name, m_value_to_sync, true); + m_param->set(m_value_to_sync); } void netlist_mame_int_input_device::write(const uint32_t val) @@ -363,7 +363,7 @@ void netlist_mame_int_input_device::write(const uint32_t val) if (v != (*m_param)()) { LOGDEBUG("write %s\n", this->tag()); - synchronize(0, v); + machine().scheduler().synchronize(timer_expired_delegate(FUNC(netlist_mame_int_input_device::sync_callback), this), v); } } @@ -373,25 +373,25 @@ void netlist_mame_logic_input_device::write(const uint32_t val) if (v != (*m_param)()) { LOGDEBUG("write %s\n", this->tag()); - synchronize(0, v); + machine().scheduler().synchronize(timer_expired_delegate(FUNC(netlist_mame_logic_input_device::sync_callback), this), v); } } -void netlist_mame_int_input_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(netlist_mame_int_input_device::sync_callback) { update_to_current_time(); nl_owner().log_csv().log_add(m_param_name, param, false); m_param->set(param); } -void netlist_mame_logic_input_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(netlist_mame_logic_input_device::sync_callback) { update_to_current_time(); nl_owner().log_csv().log_add(m_param_name, param, false); m_param->set(param); } -void netlist_mame_ram_pointer_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(netlist_mame_ram_pointer_device::sync_callback) { m_data = (*m_param)(); } @@ -432,7 +432,7 @@ netlist_mame_analog_input_device::netlist_mame_analog_input_device(const machine , m_param(nullptr) , m_auto_port(true) , m_param_name(param_name) - , m_value_for_device_timer(0) + , m_value_to_sync(0) { } @@ -442,7 +442,7 @@ netlist_mame_analog_input_device::netlist_mame_analog_input_device(const machine , m_param(nullptr) , m_auto_port(true) , m_param_name("") - , m_value_for_device_timer(0) + , m_value_to_sync(0) { } diff --git a/src/devices/machine/netlist.h b/src/devices/machine/netlist.h index f14095deaab..dc1f651e1c4 100644 --- a/src/devices/machine/netlist.h +++ b/src/devices/machine/netlist.h @@ -407,13 +407,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; + + TIMER_CALLBACK_MEMBER(sync_callback); private: netlist::param_num_t<netlist::nl_fptype> *m_param; bool m_auto_port; const char *m_param_name; - double m_value_for_device_timer; + double m_value_to_sync; }; // ---------------------------------------------------------------------------------------- @@ -507,7 +508,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(sync_callback); private: netlist::param_num_t<int> *m_param; @@ -548,7 +550,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(sync_callback); private: netlist::param_num_t<bool> *m_param; @@ -576,7 +579,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(sync_callback); private: netlist::param_ptr_t *m_param; diff --git a/src/devices/machine/ns32081.cpp b/src/devices/machine/ns32081.cpp index 39bd7a80aae..c158a7e8942 100644 --- a/src/devices/machine/ns32081.cpp +++ b/src/devices/machine/ns32081.cpp @@ -102,7 +102,7 @@ void ns32081_device::device_start() save_item(NAME(m_state)); save_item(NAME(m_tcy)); - m_complete = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(ns32081_device::complete), this)); + m_complete = timer_alloc(FUNC(ns32081_device::complete), this); } void ns32081_device::device_reset() diff --git a/src/devices/machine/ns32202.cpp b/src/devices/machine/ns32202.cpp index 14dae99c348..ba97c22ab06 100644 --- a/src/devices/machine/ns32202.cpp +++ b/src/devices/machine/ns32202.cpp @@ -103,9 +103,9 @@ void ns32202_device::device_start() save_item(NAME(m_out_int_state)); save_item(NAME(m_out_cout_state)); - m_interrupt = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(ns32202_device::interrupt), this)); - m_counter[0] = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(ns32202_device::counter<0>), this)); - m_counter[1] = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(ns32202_device::counter<1>), this)); + m_interrupt = timer_alloc(FUNC(ns32202_device::interrupt), this); + m_counter[0] = timer_alloc(FUNC(ns32202_device::counter<0>), this); + m_counter[1] = timer_alloc(FUNC(ns32202_device::counter<1>), this); } void ns32202_device::device_reset() diff --git a/src/devices/machine/nsc810.cpp b/src/devices/machine/nsc810.cpp index c077a86eff1..a416e6ccca4 100644 --- a/src/devices/machine/nsc810.cpp +++ b/src/devices/machine/nsc810.cpp @@ -29,12 +29,6 @@ nsc810_device::nsc810_device(const machine_config &mconfig, const char *tag, dev m_portA_latch(0), m_portB_latch(0), m_portC_latch(0), m_ddrA(0), m_ddrB(0), m_ddrC(0), m_mode(0), - m_timer0(nullptr), m_timer1(nullptr), - m_timer0_mode(0), m_timer1_mode(0), - m_timer0_counter(0), m_timer1_counter(0), - m_timer0_base(0), m_timer1_base(0), - m_timer0_running(false), m_timer1_running(false), - m_timer0_clock(0), m_timer1_clock(0), m_ramselect(false), m_portA_r(*this), m_portB_r(*this), @@ -42,9 +36,14 @@ nsc810_device::nsc810_device(const machine_config &mconfig, const char *tag, dev m_portA_w(*this), m_portB_w(*this), m_portC_w(*this), - m_timer0_out(*this), - m_timer1_out(*this) + m_timer_out(*this) { + std::fill(std::begin(m_timer), std::end(m_timer), nullptr); + std::fill(std::begin(m_timer_mode), std::end(m_timer_mode), 0); + std::fill(std::begin(m_timer_counter), std::end(m_timer_counter), 0); + std::fill(std::begin(m_timer_base), std::end(m_timer_base), 0); + std::fill(std::begin(m_timer_running), std::end(m_timer_running), false); + std::fill(std::begin(m_timer_clock), std::end(m_timer_clock), 0); } void nsc810_device::device_start() @@ -55,17 +54,16 @@ void nsc810_device::device_start() m_portA_w.resolve_safe(); m_portB_w.resolve_safe(); m_portC_w.resolve_safe(); - m_timer0_out.resolve_safe(); - m_timer1_out.resolve_safe(); + m_timer_out.resolve_all_safe(); m_portA_w(0); m_portB_w(0); m_portC_w(0); - m_timer0_out(0); - m_timer1_out(0); + m_timer_out[0](0); + m_timer_out[1](0); - m_timer0 = timer_alloc(TIMER0_CLOCK); - m_timer1 = timer_alloc(TIMER1_CLOCK); + m_timer[0] = timer_alloc(FUNC(nsc810_device::timer_tick<0>), this); + m_timer[1] = timer_alloc(FUNC(nsc810_device::timer_tick<1>), this); } void nsc810_device::device_reset() @@ -77,43 +75,27 @@ void nsc810_device::device_reset() m_ddrB = 0; m_ddrC = 0; m_mode = 0; - m_timer0_mode = 0; - m_timer1_mode = 0; - m_timer0_counter = 0; - m_timer1_counter = 0; - m_timer0_running = false; - m_timer1_running = false; + m_timer_mode[0] = 0; + m_timer_mode[1] = 0; + m_timer_counter[0] = 0; + m_timer_counter[1] = 0; + m_timer_running[0] = false; + m_timer_running[1] = false; m_ramselect = false; } -void nsc810_device::device_timer(emu_timer &timer, device_timer_id id, int param) +template <int Timer> +TIMER_CALLBACK_MEMBER(nsc810_device::timer_tick) { - switch(id) + m_timer_counter[Timer]--; + if ((m_timer_mode[Timer] & 0x07) == 0x01 || (m_timer_mode[Timer] & 0x07) == 0x02) { - case TIMER0_CLOCK: - m_timer0_counter--; - if((m_timer0_mode & 0x07) == 0x01 || (m_timer0_mode & 0x07) == 0x02) + if (m_timer_counter[Timer] == 0) { - if(m_timer0_counter == 0) - { - m_timer0_out(ASSERT_LINE); - m_timer0_counter = m_timer0_base; - LOG("NSC810: Timer 0 output set\n"); - } - } - break; - case TIMER1_CLOCK: - m_timer1_counter--; - if((m_timer1_mode & 0x07) == 0x01 || (m_timer1_mode & 0x07) == 0x02) - { - if(m_timer1_counter == 0) - { - m_timer1_out(ASSERT_LINE); - m_timer1_counter = m_timer1_base; - LOG("NSC810: Timer 1 output set\n"); - } + m_timer_out[Timer](ASSERT_LINE); + m_timer_counter[Timer] = m_timer_base[Timer]; + LOG("NSC810: Timer %d output set\n", Timer); } - break; } } @@ -121,70 +103,70 @@ uint8_t nsc810_device::read(offs_t offset) { uint8_t res = 0xff; - if(m_ramselect) + if (m_ramselect) { // TODO: 128 byte RAM access } else { // Register access - switch(offset & 0x1f) + switch (offset & 0x1f) { case REG_PORTA: res = m_portA_latch &= m_ddrA; res |= (m_portA_r() & ~m_ddrA); - //LOG("NSC810: Port A data read %02x\n",res); + //LOG("NSC810: Port A data read %02x\n", res); break; case REG_PORTB: res = m_portB_latch &= m_ddrB; res |= (m_portB_r() & ~m_ddrB); - //LOG("NSC810: Port B data read %02x\n",res); + //LOG("NSC810: Port B data read %02x\n", res); break; case REG_PORTC: res = m_portC_latch &= m_ddrC; res |= (m_portC_r() & ~m_ddrC); - //LOG("NSC810: Port C data read %02x\n",res); + //LOG("NSC810: Port C data read %02x\n", res); break; case REG_MODE_TIMER0: - res = m_timer0_mode; + res = m_timer_mode[0]; break; case REG_MODE_TIMER1: - res = m_timer1_mode; + res = m_timer_mode[1]; break; case REG_TIMER0_LOW: - res = m_timer0_counter & 0xff; - if((m_timer0_mode & 0x07) == 0x01 || (m_timer0_mode & 0x07) == 0x02) + res = m_timer_counter[0] & 0xff; + if ((m_timer_mode[0] & 0x07) == 0x01 || (m_timer_mode[0] & 0x07) == 0x02) { - m_timer0_out(CLEAR_LINE); + m_timer_out[0](CLEAR_LINE); LOG("NSC810: Timer 0 output reset\n"); } break; case REG_TIMER0_HIGH: - res = m_timer0_counter >> 8; - if((m_timer0_mode & 0x07) == 0x01 || (m_timer0_mode & 0x07) == 0x02) + res = m_timer_counter[0] >> 8; + if ((m_timer_mode[0] & 0x07) == 0x01 || (m_timer_mode[0] & 0x07) == 0x02) { - m_timer0_out(CLEAR_LINE); + m_timer_out[0](CLEAR_LINE); LOG("NSC810: Timer 0 output reset\n"); } break; case REG_TIMER1_LOW: - res = m_timer1_counter & 0xff; - if((m_timer1_mode & 0x07) == 0x01 || (m_timer1_mode & 0x07) == 0x02) + res = m_timer_counter[1] & 0xff; + if ((m_timer_mode[1] & 0x07) == 0x01 || (m_timer_mode[1] & 0x07) == 0x02) { - m_timer1_out(0); + m_timer_out[1](0); LOG("NSC810: Timer 1 output reset\n"); } break; case REG_TIMER1_HIGH: - res = m_timer1_counter >> 8; - if((m_timer1_mode & 0x07) == 0x01 || (m_timer1_mode & 0x07) == 0x02) + res = m_timer_counter[1] >> 8; + if ((m_timer_mode[1] & 0x07) == 0x01 || (m_timer_mode[1] & 0x07) == 0x02) { - m_timer1_out(0); + m_timer_out[1](0); LOG("NSC810: Timer 1 output reset\n"); } break; default: - LOG("NSC810: unused port %02x read\n",offset); + LOG("NSC810: unused port %02x read\n", offset); } } return res; @@ -194,41 +176,41 @@ void nsc810_device::write(offs_t offset, uint8_t data) { uint32_t rate; - if(m_ramselect) + if (m_ramselect) { // TODO: 128 byte RAM access } else { // Register access - switch(offset & 0x1f) + switch (offset & 0x1f) { case REG_PORTA: m_portA_latch = data & ~m_ddrA; m_portA_w((0xff & ~m_ddrA) | (data & m_ddrA)); - LOG("NSC810: Port A data write %02x\n",data); + LOG("NSC810: Port A data write %02x\n", data); break; case REG_PORTB: m_portB_latch = data & ~m_ddrB; m_portB_w((0xff & ~m_ddrB) | (data & m_ddrB)); - LOG("NSC810: Port B data write %02x\n",data); + LOG("NSC810: Port B data write %02x\n", data); break; case REG_PORTC: m_portC_latch = data & ~m_ddrC; m_portC_w((0xff & ~m_ddrC) | (data & m_ddrC)); - LOG("NSC810: Port C data write %02x\n",data); + LOG("NSC810: Port C data write %02x\n", data); break; case REG_DDRA: m_ddrA = data; - LOG("NSC810: Port A direction write %02x\n",data); + LOG("NSC810: Port A direction write %02x\n", data); break; case REG_DDRB: m_ddrB = data; - LOG("NSC810: Port B direction write %02x\n",data); + LOG("NSC810: Port B direction write %02x\n", data); break; case REG_DDRC: m_ddrC = data; - LOG("NSC810: Port C direction write %02x\n",data); + LOG("NSC810: Port C direction write %02x\n", data); break; case REG_MODE_DEF: if ((data & 0x01) == 0x00) @@ -239,106 +221,106 @@ void nsc810_device::write(offs_t offset, uint8_t data) m_mode = 2; else if ((data & 0x07) == 0x07) m_mode = 3; - LOG("NSC810: Mode Definition write %02x\n",data); + LOG("NSC810: Mode Definition write %02x\n", data); break; case REG_PORTA_BITCLR: m_portA_latch &= ~data; m_portA_w((0xff & ~m_ddrA) | (m_portA_latch & m_ddrA)); - LOG("NSC810: Port A bit-clear write %02x (PA=%02x)\n",data,m_portA_latch); + LOG("NSC810: Port A bit-clear write %02x (PA=%02x)\n", data, m_portA_latch); break; case REG_PORTB_BITCLR: m_portB_latch &= ~data; m_portB_w((0xff & ~m_ddrB) | (m_portB_latch & m_ddrB)); - LOG("NSC810: Port B bit-clear write %02x (PB=%02x)\n",data,m_portB_latch); + LOG("NSC810: Port B bit-clear write %02x (PB=%02x)\n", data, m_portB_latch); break; case REG_PORTC_BITCLR: m_portC_latch &= ~data; m_portC_w((0xff & ~m_ddrC) | (m_portC_latch & m_ddrC)); - LOG("NSC810: Port C bit-clear write %02x (PC=%02x)\n",data,m_portC_latch); + LOG("NSC810: Port C bit-clear write %02x (PC=%02x)\n", data, m_portC_latch); break; case REG_PORTA_BITSET: m_portA_latch |= data; m_portA_w((0xff & ~m_ddrA) | (m_portA_latch & m_ddrA)); - LOG("NSC810: Port A bit-set write %02x (PA=%02x)\n",data,m_portA_latch); + LOG("NSC810: Port A bit-set write %02x (PA=%02x)\n", data, m_portA_latch); break; case REG_PORTB_BITSET: m_portB_latch |= data; m_portB_w((0xff & ~m_ddrB) | (m_portB_latch & m_ddrB)); - LOG("NSC810: Port B bit-set write %02x (PB=%02x)\n",data,m_portB_latch); + LOG("NSC810: Port B bit-set write %02x (PB=%02x)\n", data, m_portB_latch); break; case REG_PORTC_BITSET: m_portC_latch |= data; m_portC_w((0xff & ~m_ddrC) | (m_portC_latch & m_ddrC)); - LOG("NSC810: Port C bit-set write %02x (PC=%02x)\n",data,m_portC_latch); + LOG("NSC810: Port C bit-set write %02x (PC=%02x)\n", data, m_portC_latch); break; case REG_TIMER0_LOW: - m_timer0_base = (m_timer0_base & 0xff00) | data; - m_timer0_counter = (m_timer0_counter & 0xff00) | data; - LOG("NSC810: Timer 0 low-byte write %02x (base=%04x)\n",data,m_timer0_base); + m_timer_base[0] = (m_timer_base[0] & 0xff00) | data; + m_timer_counter[0] = (m_timer_counter[0] & 0xff00) | data; + LOG("NSC810: Timer 0 low-byte write %02x (base=%04x)\n", data, m_timer_base[0]); break; case REG_TIMER0_HIGH: - m_timer0_base = (m_timer0_base & 0x00ff) | (data << 8); - m_timer0_counter = (m_timer0_counter & 0x00ff) | (data << 8); - LOG("NSC810: Timer 0 high-byte write %02x (base=%04x)\n",data,m_timer0_base); + m_timer_base[0] = (m_timer_base[0] & 0x00ff) | (data << 8); + m_timer_counter[0] = (m_timer_counter[0] & 0x00ff) | (data << 8); + LOG("NSC810: Timer 0 high-byte write %02x (base=%04x)\n", data, m_timer_base[0]); break; case REG_TIMER1_LOW: - m_timer1_base = (m_timer1_base & 0xff00) | data; - m_timer1_counter = (m_timer1_counter & 0xff00) | data; - LOG("NSC810: Timer 1 low-byte write %02x (base=%04x)\n",data,m_timer1_base); + m_timer_base[1] = (m_timer_base[1] & 0xff00) | data; + m_timer_counter[1] = (m_timer_counter[1] & 0xff00) | data; + LOG("NSC810: Timer 1 low-byte write %02x (base=%04x)\n", data, m_timer_base[1]); break; case REG_TIMER1_HIGH: - m_timer1_base = (m_timer1_base & 0x00ff) | (data << 8); - m_timer1_counter = (m_timer1_counter & 0x00ff) | (data << 8); - LOG("NSC810: Timer 1 high-byte write %02x (base=%04x)\n",data,m_timer1_base); + m_timer_base[1] = (m_timer_base[1] & 0x00ff) | (data << 8); + m_timer_counter[1] = (m_timer_counter[1] & 0x00ff) | (data << 8); + LOG("NSC810: Timer 1 high-byte write %02x (base=%04x)\n", data, m_timer_base[1]); break; case REG_TIMER0_STOP: - m_timer0_running = false; - m_timer0->reset(); - LOG("NSC810: Timer 0 Stop write %02x\n",tag(),data); + m_timer_running[0] = false; + m_timer[0]->reset(); + LOG("NSC810: Timer 0 Stop write %02x\n", tag(), data); break; case REG_TIMER0_START: - if((m_timer0_mode & 0x07) != 0x00 && (m_timer0_mode & 0x07) != 0x07) + if ((m_timer_mode[0] & 0x07) != 0x00 && (m_timer_mode[0] & 0x07) != 0x07) { - m_timer0_running = true; - if(m_timer0_mode & 0x10) - rate = m_timer0_clock / 64; + m_timer_running[0] = true; + if (m_timer_mode[0] & 0x10) + rate = m_timer_clock[0] / 64; else - if(m_timer0_mode & 0x08) - rate = m_timer0_clock / 2; + if (m_timer_mode[0] & 0x08) + rate = m_timer_clock[0] / 2; else - rate = m_timer0_clock; - m_timer0->adjust(attotime::zero,0,attotime::from_hz(rate)); + rate = m_timer_clock[0]; + m_timer[0]->adjust(attotime::zero, 0, attotime::from_hz(rate)); } - LOG("NSC810: Timer 0 Start write %02x\n",data); + LOG("NSC810: Timer 0 Start write %02x\n", data); break; case REG_TIMER1_STOP: - m_timer1_running = false; - m_timer1->reset(); - LOG("NSC810: Timer 1 Stop write %02x\n",data); + m_timer_running[1] = false; + m_timer[1]->reset(); + LOG("NSC810: Timer 1 Stop write %02x\n", data); break; case REG_TIMER1_START: - if((m_timer1_mode & 0x07) != 0x00 && (m_timer1_mode & 0x07) != 0x07) + if ((m_timer_mode[1] & 0x07) != 0x00 && (m_timer_mode[1] & 0x07) != 0x07) { - m_timer1_running = true; + m_timer_running[1] = true; // no /64 prescaler on timer 1 - if(m_timer0_mode & 0x08) - rate = m_timer0_clock / 2; + if (m_timer_mode[0] & 0x08) + rate = m_timer_clock[0] / 2; else - rate = m_timer0_clock; - m_timer1->adjust(attotime::zero,0,attotime::from_hz(rate)); + rate = m_timer_clock[0]; + m_timer[1]->adjust(attotime::zero, 0, attotime::from_hz(rate)); } - LOG("NSC810: Timer 1 Start write %02x\n",data); + LOG("NSC810: Timer 1 Start write %02x\n", data); break; case REG_MODE_TIMER0: - m_timer0_mode = data; - LOG("NSC810: Timer 0 Mode write %02x\n",data); + m_timer_mode[0] = data; + LOG("NSC810: Timer 0 Mode write %02x\n", data); break; case REG_MODE_TIMER1: - m_timer1_mode = data; - LOG("NSC810: Timer 1 Mode write %02x\n",data); + m_timer_mode[1] = data; + LOG("NSC810: Timer 1 Mode write %02x\n", data); break; default: - logerror("NSC810: Unused register %02x write %02x\n",offset,data); + logerror("NSC810: Unused register %02x write %02x\n", offset, data); } } } diff --git a/src/devices/machine/nsc810.h b/src/devices/machine/nsc810.h index f6ad2042959..08a35465cc4 100644 --- a/src/devices/machine/nsc810.h +++ b/src/devices/machine/nsc810.h @@ -38,12 +38,12 @@ public: auto portA_write_callback() { return m_portA_w.bind(); } auto portB_write_callback() { return m_portB_w.bind(); } auto portC_write_callback() { return m_portC_w.bind(); } - auto timer0_callback() { return m_timer0_out.bind(); } - auto timer1_callback() { return m_timer1_out.bind(); } + auto timer0_callback() { return m_timer_out[0].bind(); } + auto timer1_callback() { return m_timer_out[1].bind(); } - void set_timer0_clock(uint32_t clk) { m_timer0_clock = clk; } + void set_timer0_clock(uint32_t clk) { m_timer_clock[0] = clk; } void set_timer0_clock(const XTAL &clk) { set_timer0_clock(clk.value()); } - void set_timer1_clock(uint32_t clk) { m_timer1_clock = clk; } + void set_timer1_clock(uint32_t clk) { m_timer_clock[1] = clk; } void set_timer1_clock(const XTAL &clk) { set_timer1_clock(clk.value()); } uint8_t read(offs_t offset); @@ -52,7 +52,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; + + template <int Timer> TIMER_CALLBACK_MEMBER(timer_tick); private: uint8_t m_portA_latch; @@ -62,18 +63,12 @@ private: uint8_t m_ddrB; uint8_t m_ddrC; uint8_t m_mode; - emu_timer* m_timer0; - emu_timer* m_timer1; - uint8_t m_timer0_mode; - uint8_t m_timer1_mode; - uint16_t m_timer0_counter; - uint16_t m_timer1_counter; - uint16_t m_timer0_base; - uint16_t m_timer1_base; - bool m_timer0_running; - bool m_timer1_running; - uint32_t m_timer0_clock; - uint32_t m_timer1_clock; + emu_timer* m_timer[2]; + uint8_t m_timer_mode[2]; + uint16_t m_timer_counter[2]; + uint16_t m_timer_base[2]; + bool m_timer_running[2]; + uint32_t m_timer_clock[2]; bool m_ramselect; devcb_read8 m_portA_r; @@ -82,11 +77,7 @@ private: devcb_write8 m_portA_w; devcb_write8 m_portB_w; devcb_write8 m_portC_w; - devcb_write_line m_timer0_out; - devcb_write_line m_timer1_out; - - static constexpr device_timer_id TIMER0_CLOCK = 0; - static constexpr device_timer_id TIMER1_CLOCK = 1; + devcb_write_line::array<2> m_timer_out; enum { diff --git a/src/devices/machine/nscsi_bus.cpp b/src/devices/machine/nscsi_bus.cpp index 89f18a902e2..eeaf2c2722a 100644 --- a/src/devices/machine/nscsi_bus.cpp +++ b/src/devices/machine/nscsi_bus.cpp @@ -233,7 +233,7 @@ const char *const nscsi_full_device::command_names[256] = { void nscsi_full_device::device_start() { nscsi_device::device_start(); - scsi_timer = timer_alloc(SCSI_TIMER); + scsi_timer = timer_alloc(FUNC(nscsi_full_device::update_tick), this); save_item(NAME(scsi_cmdbuf)); save_item(NAME(scsi_sense_buffer)); save_item(NAME(scsi_cmdsize)); @@ -266,13 +266,9 @@ void nscsi_full_device::device_reset() sense(false, SK_NO_SENSE); } -void nscsi_full_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(nscsi_full_device::update_tick) { - if(id != SCSI_TIMER) - return; - step(true); - } void nscsi_full_device::scsi_ctrl_changed() diff --git a/src/devices/machine/nscsi_bus.h b/src/devices/machine/nscsi_bus.h index 997844c4342..6cd99732bf9 100644 --- a/src/devices/machine/nscsi_bus.h +++ b/src/devices/machine/nscsi_bus.h @@ -144,9 +144,8 @@ class nscsi_full_device : public nscsi_device, public nscsi_slot_card_interface { public: virtual void scsi_ctrl_changed() override; -protected: - enum { SCSI_TIMER = 100 }; +protected: // SCSI status returns enum { SS_GOOD = 0x00, @@ -316,12 +315,13 @@ 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 scsi_message(); virtual void scsi_command(); virtual bool scsi_command_done(uint8_t command, uint8_t length); + TIMER_CALLBACK_MEMBER(update_tick); + void scsi_unknown_command(); void scsi_status_complete(uint8_t st); void scsi_data_in(int buf, int size); diff --git a/src/devices/machine/pcf8573.cpp b/src/devices/machine/pcf8573.cpp index 09cb4c340d3..791336b4bf5 100644 --- a/src/devices/machine/pcf8573.cpp +++ b/src/devices/machine/pcf8573.cpp @@ -61,7 +61,7 @@ void pcf8573_device::device_start() m_sec_cb.resolve_safe(); // allocate timers - m_clock_timer = timer_alloc(); + m_clock_timer = timer_alloc(FUNC(pcf8573_device::clock_tick), this); m_clock_timer->adjust(attotime::from_hz(clock() / 32768), 0, attotime::from_hz(clock() / 32768)); // state saving @@ -80,10 +80,10 @@ void pcf8573_device::device_start() } //------------------------------------------------- -// device_timer - handler timer events +// clock_tick - advance the RTC //------------------------------------------------- -void pcf8573_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(pcf8573_device::clock_tick) { advance_seconds(); diff --git a/src/devices/machine/pcf8573.h b/src/devices/machine/pcf8573.h index d5b3bc5283e..a6b31e83ed7 100644 --- a/src/devices/machine/pcf8573.h +++ b/src/devices/machine/pcf8573.h @@ -64,11 +64,12 @@ 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_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; + TIMER_CALLBACK_MEMBER(clock_tick); + private: static constexpr uint8_t PCF8573_SLAVE_ADDRESS = 0xd0; diff --git a/src/devices/machine/pcf8583.cpp b/src/devices/machine/pcf8583.cpp index 63a755d1077..c09a6fce138 100644 --- a/src/devices/machine/pcf8583.cpp +++ b/src/devices/machine/pcf8583.cpp @@ -55,7 +55,7 @@ pcf8583_device::pcf8583_device(const machine_config &mconfig, const char *tag, d void pcf8583_device::device_start() { - m_timer = timer_alloc(TIMER_TICK); + m_timer = timer_alloc(FUNC(pcf8583_device::clock_tick), this); m_timer->adjust(attotime::from_hz(100), 0, attotime::from_hz(100)); save_item(NAME(m_scl)); @@ -73,15 +73,10 @@ void pcf8583_device::device_start() m_irq_cb.resolve_safe(); } -void pcf8583_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(pcf8583_device::clock_tick) { - switch (id) - { - case TIMER_TICK: - if (!BIT(m_data[REG_CONTROL], CONTROL_STOP_BIT)) - advance_hundredths(); - break; - } + if (!BIT(m_data[REG_CONTROL], CONTROL_STOP_BIT)) + advance_hundredths(); } void pcf8583_device::advance_hundredths() diff --git a/src/devices/machine/pcf8583.h b/src/devices/machine/pcf8583.h index 900ea145c10..d5018160788 100644 --- a/src/devices/machine/pcf8583.h +++ b/src/devices/machine/pcf8583.h @@ -88,7 +88,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_rtc_interface overrides virtual bool rtc_feature_y2k() const override { return true; } @@ -100,6 +99,8 @@ protected: virtual bool nvram_read(util::read_stream &file) override; virtual bool nvram_write(util::write_stream &file) override; + TIMER_CALLBACK_MEMBER(clock_tick); + private: static constexpr uint8_t PCF8583_SLAVE_ADDRESS = 0xa0; @@ -128,8 +129,6 @@ private: CONTROL_STOP_BIT = 7 }; - static const device_timer_id TIMER_TICK = 0; - // get/set date uint8_t get_date_year() { return (m_data[REG_YEAR_DATE] >> 6) & 3; } void set_date_year(uint8_t year) { m_data[REG_YEAR_DATE] = (m_data[REG_YEAR_DATE] & 0x3f) | ((year % 4) << 6); } diff --git a/src/devices/machine/pcf8593.cpp b/src/devices/machine/pcf8593.cpp index cc2e372d4b8..3ba4f1af89b 100644 --- a/src/devices/machine/pcf8593.cpp +++ b/src/devices/machine/pcf8593.cpp @@ -63,7 +63,7 @@ void pcf8593_device::device_start() { _logerror( 0, ("pcf8593_init\n")); memset(m_register, 0, sizeof(m_register)); - m_timer = timer_alloc(TIMER_UPDATE_COUNTER); + m_timer = timer_alloc(FUNC(pcf8593_device::clock_tick), this); m_timer->adjust(attotime::from_seconds(1), 0, attotime::from_seconds(1)); } @@ -87,20 +87,15 @@ void pcf8593_device::device_reset() //------------------------------------------------- -// device_timer - handler timer events +// clock_tick - advance the RTC if enabled //------------------------------------------------- -void pcf8593_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(pcf8593_device::clock_tick) { - switch(id) - { - case TIMER_UPDATE_COUNTER: - _logerror( 2, ("pcf8593_timer_callback (%d)\n", param)); - // check if counting is enabled - if (!(m_data[0] & 0x80)) - advance_seconds(); - break; - } + _logerror( 2, ("pcf8593_timer_callback (%d)\n", param)); + // check if counting is enabled + if (!(m_data[0] & 0x80)) + advance_seconds(); } diff --git a/src/devices/machine/pcf8593.h b/src/devices/machine/pcf8593.h index 419aebad224..3720ac1bb53 100644 --- a/src/devices/machine/pcf8593.h +++ b/src/devices/machine/pcf8593.h @@ -32,7 +32,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 bool rtc_feature_y2k() const override { return true; } @@ -43,11 +42,11 @@ protected: virtual bool nvram_read(util::read_stream &file) override; virtual bool nvram_write(util::write_stream &file) override; + TIMER_CALLBACK_MEMBER(clock_tick); + private: void clear_buffer_rx(); - static const device_timer_id TIMER_UPDATE_COUNTER = 0; - // internal state uint8_t m_data[16]; int m_pin_scl; diff --git a/src/devices/machine/pckeybrd.cpp b/src/devices/machine/pckeybrd.cpp index 8defcd0297e..c2b46fbe4b7 100644 --- a/src/devices/machine/pckeybrd.cpp +++ b/src/devices/machine/pckeybrd.cpp @@ -300,7 +300,7 @@ at_keyboard_device::at_keyboard_device(const machine_config &mconfig, const char } -void pc_keyboard_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(pc_keyboard_device::poll_keys) { polling(); if(!charqueue_empty()) @@ -326,7 +326,7 @@ void pc_keyboard_device::device_start() ioport_charqueue_empty_delegate(&pc_keyboard_device::charqueue_empty, this)); m_out_keypress_func.resolve_safe(); - m_keyboard_timer = timer_alloc(); + m_keyboard_timer = timer_alloc(FUNC(at_keyboard_device::poll_keys), this); } void at_keyboard_device::device_start() diff --git a/src/devices/machine/pckeybrd.h b/src/devices/machine/pckeybrd.h index eb685ec175e..e52981b10c4 100644 --- a/src/devices/machine/pckeybrd.h +++ b/src/devices/machine/pckeybrd.h @@ -40,7 +40,9 @@ 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; + + TIMER_CALLBACK_MEMBER(poll_keys); + void queue_insert(uint8_t data); void clear_buffer(); diff --git a/src/devices/machine/phi.cpp b/src/devices/machine/phi.cpp index 8e44c2fb49b..7659a0359a1 100644 --- a/src/devices/machine/phi.cpp +++ b/src/devices/machine/phi.cpp @@ -48,12 +48,12 @@ namespace { return (T)1U << n; } - template<typename T> void BIT_CLR(T& w , unsigned n) + template<typename T> void BIT_CLR(T& w, unsigned n) { w &= ~BIT_MASK<T>(n); } - template<typename T> void BIT_SET(T& w , unsigned n) + template<typename T> void BIT_SET(T& w, unsigned n) { w |= BIT_MASK<T>(n); } @@ -205,42 +205,42 @@ phi_device::phi_device(const machine_config &mconfig, const char *tag, device_t WRITE_LINE_MEMBER(phi_device::eoi_w) { - set_ext_signal(PHI_488_EOI , state); + set_ext_signal(PHI_488_EOI, state); } WRITE_LINE_MEMBER(phi_device::dav_w) { - set_ext_signal(PHI_488_DAV , state); + set_ext_signal(PHI_488_DAV, state); } WRITE_LINE_MEMBER(phi_device::nrfd_w) { - set_ext_signal(PHI_488_NRFD , state); + set_ext_signal(PHI_488_NRFD, state); } WRITE_LINE_MEMBER(phi_device::ndac_w) { - set_ext_signal(PHI_488_NDAC , state); + set_ext_signal(PHI_488_NDAC, state); } WRITE_LINE_MEMBER(phi_device::ifc_w) { - set_ext_signal(PHI_488_IFC , state); + set_ext_signal(PHI_488_IFC, state); } WRITE_LINE_MEMBER(phi_device::srq_w) { - set_ext_signal(PHI_488_SRQ , state); + set_ext_signal(PHI_488_SRQ, state); } WRITE_LINE_MEMBER(phi_device::atn_w) { - set_ext_signal(PHI_488_ATN , state); + set_ext_signal(PHI_488_ATN, state); } WRITE_LINE_MEMBER(phi_device::ren_w) { - set_ext_signal(PHI_488_REN , state); + set_ext_signal(PHI_488_REN, state); } void phi_device::bus_dio_w(uint8_t data) @@ -248,27 +248,27 @@ void phi_device::bus_dio_w(uint8_t data) update_pp(); } -void phi_device::set_ext_signal(phi_488_signal_t signal , int state) +void phi_device::set_ext_signal(phi_488_signal_t signal, int state) { state = !state; - if (m_ext_signals[ signal ] != state) { - m_ext_signals[ signal ] = state; - LOG_NOISY("EXT EOI %d DAV %d NRFD %d NDAC %d IFC %d SRQ %d ATN %d REN %d\n" , - m_ext_signals[ PHI_488_EOI ] , - m_ext_signals[ PHI_488_DAV ] , - m_ext_signals[ PHI_488_NRFD ] , - m_ext_signals[ PHI_488_NDAC ] , - m_ext_signals[ PHI_488_IFC ] , - m_ext_signals[ PHI_488_SRQ ] , - m_ext_signals[ PHI_488_ATN ] , - m_ext_signals[ PHI_488_REN ]); + if (m_ext_signals[signal] != state) { + m_ext_signals[signal] = state; + LOG_NOISY("EXT EOI %d DAV %d NRFD %d NDAC %d IFC %d SRQ %d ATN %d REN %d\n", + m_ext_signals[PHI_488_EOI], + m_ext_signals[PHI_488_DAV], + m_ext_signals[PHI_488_NRFD], + m_ext_signals[PHI_488_NDAC], + m_ext_signals[PHI_488_IFC], + m_ext_signals[PHI_488_SRQ], + m_ext_signals[PHI_488_ATN], + m_ext_signals[PHI_488_REN]); update_fsm(); } } void phi_device::reg16_w(offs_t offset, uint16_t data) { - int_reg_w(offset , data & REG_ALL_MASK); + int_reg_w(offset, data & REG_ALL_MASK); } uint16_t phi_device::reg16_r(offs_t offset) @@ -330,13 +330,13 @@ uint16_t phi_device::reg16_r(offs_t offset) ((res & REG_D0D1_MASK) >> (REG_D0D1_SHIFT - REG_STATUS_D0D1_BIT)); } - LOG_REG("R %u=%04x\n" , offset , res); + LOG_REG("R %u=%04x\n", offset, res); return res; } void phi_device::reg8_w(offs_t offset, uint8_t data) { - int_reg_w(offset , data); + int_reg_w(offset, data); } uint8_t phi_device::reg8_r(offs_t offset) @@ -381,8 +381,8 @@ void phi_device::device_start() m_dmarq_write_func.resolve_safe(); m_sys_cntrl_read_func.resolve_safe(0); - m_sh_dly_timer = timer_alloc(SH_DELAY_TMR_ID); - m_c_dly_timer = timer_alloc(C_DELAY_TMR_ID); + m_sh_dly_timer = timer_alloc(FUNC(phi_device::delayed_update), this); + m_c_dly_timer = timer_alloc(FUNC(phi_device::delayed_update), this); } void phi_device::device_reset() @@ -417,20 +417,20 @@ void phi_device::device_reset() update_488(); } -void phi_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(phi_device::delayed_update) { - LOG_NOISY("tmr %d enabled %d\n" , id , timer.enabled()); + LOG_NOISY("tmr %d enabled\n", param); update_fsm(); } -void phi_device::int_reg_w(offs_t offset , uint16_t data) +void phi_device::int_reg_w(offs_t offset, uint16_t data) { - if (BIT(m_reg_control , REG_CTRL_8BIT_PROC_BIT)) { + if (BIT(m_reg_control, REG_CTRL_8BIT_PROC_BIT)) { // In 8-bit mode, D0/D1 come from status register data = (data & REG_D08D15_MASK) | ((m_reg_status << (REG_D0D1_SHIFT - REG_STATUS_D0D1_BIT)) & REG_D0D1_MASK); } - LOG_REG("W %u=%04x\n" , offset , data); + LOG_REG("W %u=%04x\n", offset, data); switch (offset) { case REG_W_INT_COND: @@ -457,7 +457,7 @@ void phi_device::int_reg_w(offs_t offset , uint16_t data) // Copy D0/D1 access bits into status register m_reg_status = (m_reg_status & ~(3U << REG_STATUS_D0D1_BIT)) | (data & (3U << REG_STATUS_D0D1_BIT)); - if (BIT(data , REG_STATUS_DATA_FREEZE_BIT) && m_fifo_in.empty()) { + if (BIT(data, REG_STATUS_DATA_FREEZE_BIT) && m_fifo_in.empty()) { BIT_CLR(m_reg_status, REG_STATUS_DATA_FREEZE_BIT); } update_fsm(); @@ -466,17 +466,17 @@ void phi_device::int_reg_w(offs_t offset , uint16_t data) case REG_W_CONTROL: // D0/D1/D15 are not mapped into register m_reg_control = data & 0xfe; - if (BIT(data , REG_CTRL_INIT_OFIFO_BIT)) { + if (BIT(data, REG_CTRL_INIT_OFIFO_BIT)) { m_fifo_out.clear(); if (m_c_state == PHI_C_CSBS) { // Take control asynchronously m_c_state = PHI_C_CSWS; - m_c_dly_timer->adjust(attotime::from_nsec(DELAY_T7)); + m_c_dly_timer->adjust(attotime::from_nsec(DELAY_T7), 1); } } if (m_loopback) { // TODO: better? - m_id_enabled = BIT(m_reg_control , REG_CTRL_PP_RESPONSE_BIT); + m_id_enabled = BIT(m_reg_control, REG_CTRL_PP_RESPONSE_BIT); } update_fsm(); break; @@ -485,18 +485,18 @@ void phi_device::int_reg_w(offs_t offset , uint16_t data) { // No D0/D1 in register data &= REG_D08D15_MASK; - bool prev_ol = BIT(m_reg_address , REG_ADDR_ONLINE_BIT); + bool prev_ol = BIT(m_reg_address, REG_ADDR_ONLINE_BIT); m_reg_address = data; - bool current_ol = BIT(m_reg_address , REG_ADDR_ONLINE_BIT); + bool current_ol = BIT(m_reg_address, REG_ADDR_ONLINE_BIT); m_sys_controller = !current_ol || m_sys_cntrl_read_func(); m_loopback = !current_ol; if (!current_ol) { // IDENTIFY is enabled by PP_RESPONSE bit in control register - m_id_enabled = BIT(m_reg_control , REG_CTRL_PP_RESPONSE_BIT); + m_id_enabled = BIT(m_reg_control, REG_CTRL_PP_RESPONSE_BIT); } else if (!prev_ol) { // Going on-line pon_msg(); - m_id_enabled = BIT(m_reg_control , REG_CTRL_PP_RESPONSE_BIT); + m_id_enabled = BIT(m_reg_control, REG_CTRL_PP_RESPONSE_BIT); } configure_pp_response(); if (prev_ol != current_ol) { @@ -536,7 +536,7 @@ uint8_t phi_device::get_dio(void) void phi_device::set_dio(uint8_t data) { if (data != m_dio) { - LOG_NOISY("DIO=%02x\n" , data); + LOG_NOISY("DIO=%02x\n", data); m_dio = data; if (!m_loopback) { m_dio_write_func(~data); @@ -547,27 +547,27 @@ void phi_device::set_dio(uint8_t data) bool phi_device::get_signal(phi_488_signal_t signal) { if (m_loopback) { - return m_signals[ signal ]; + return m_signals[signal]; } else { - return m_ext_signals[ signal ]; + return m_ext_signals[signal]; } } -void phi_device::set_signal(phi_488_signal_t signal , bool state) +void phi_device::set_signal(phi_488_signal_t signal, bool state) { - if (state != m_signals[ signal ]) { - m_signals[ signal ] = state; - LOG_NOISY("INT EOI %d DAV %d NRFD %d NDAC %d IFC %d SRQ %d ATN %d REN %d\n" , - m_signals[ PHI_488_EOI ] , - m_signals[ PHI_488_DAV ] , - m_signals[ PHI_488_NRFD ] , - m_signals[ PHI_488_NDAC ] , - m_signals[ PHI_488_IFC ] , - m_signals[ PHI_488_SRQ ] , - m_signals[ PHI_488_ATN ] , - m_signals[ PHI_488_REN ]); + if (state != m_signals[signal]) { + m_signals[signal] = state; + LOG_NOISY("INT EOI %d DAV %d NRFD %d NDAC %d IFC %d SRQ %d ATN %d REN %d\n", + m_signals[PHI_488_EOI], + m_signals[PHI_488_DAV], + m_signals[PHI_488_NRFD], + m_signals[PHI_488_NDAC], + m_signals[PHI_488_IFC], + m_signals[PHI_488_SRQ], + m_signals[PHI_488_ATN], + m_signals[PHI_488_REN]); if (!m_loopback) { - m_signal_wr_fns[ signal ](!state); + m_signal_wr_fns[signal](!state); } } } @@ -598,7 +598,7 @@ void phi_device::update_488(void) } else { m_dio_write_func(~m_dio); for (unsigned i = 0; i < PHI_488_SIGNAL_COUNT; i++) { - m_signal_wr_fns[ i ](!m_signals[ i ]); + m_signal_wr_fns[i](!m_signals[i]); } } } @@ -612,13 +612,13 @@ void phi_device::update_fsm(void) } m_no_recursion = true; - set_signal(PHI_488_IFC , m_sys_controller && BIT(m_reg_control , REG_CTRL_IFC_BIT)); - set_signal(PHI_488_REN , m_sys_controller && BIT(m_reg_control , REG_CTRL_REN_BIT)); + set_signal(PHI_488_IFC, m_sys_controller && BIT(m_reg_control, REG_CTRL_IFC_BIT)); + set_signal(PHI_488_REN, m_sys_controller && BIT(m_reg_control, REG_CTRL_REN_BIT)); // TODO: improve (see SR FSM) // This is not entirely correct but it works for now (on HP64K, the only system // where it's relevant) - set_signal(PHI_488_SRQ , BIT(m_reg_control , REG_CTRL_SERVICE_REQ_BIT)); + set_signal(PHI_488_SRQ, BIT(m_reg_control, REG_CTRL_SERVICE_REQ_BIT)); bool changed = true; int prev_state; @@ -628,10 +628,10 @@ void phi_device::update_fsm(void) // TODO: SR FSM // Loop until all changes settle while (changed) { - LOG_NOISY("SH %d AH %d T %d SPMS %d L %d SR %d PP %d PPR %u S %d C %d SA %d\n" , - m_sh_state , m_ah_state , m_t_state , m_t_spms , m_l_state , m_sr_state , - m_pp_state , m_ppr_msg , m_s_sense , m_c_state , m_sa_state); - LOG_NOISY("O E/F=%d/%d I E/F=%d/%d\n" , m_fifo_out.empty() , m_fifo_out.full() , m_fifo_in.empty() , m_fifo_in.full()); + LOG_NOISY("SH %d AH %d T %d SPMS %d L %d SR %d PP %d PPR %u S %d C %d SA %d\n", + m_sh_state, m_ah_state, m_t_state, m_t_spms, m_l_state, m_sr_state, + m_pp_state, m_ppr_msg, m_s_sense, m_c_state, m_sa_state); + LOG_NOISY("O E/F=%d/%d I E/F=%d/%d\n", m_fifo_out.empty(), m_fifo_out.full(), m_fifo_in.empty(), m_fifo_in.full()); changed = false; // SH FSM @@ -656,10 +656,10 @@ void phi_device::update_fsm(void) break; case PHI_SH_SGNS: - if ((m_nba_origin = nba_msg(new_byte , new_eoi)) != NBA_NONE) { + if ((m_nba_origin = nba_msg(new_byte, new_eoi)) != NBA_NONE) { m_sh_state = PHI_SH_SDYS; - m_sh_dly_timer->adjust(attotime::from_nsec(DELAY_T1)); - LOG_NOISY("SH DLY enabled %d\n" , m_sh_dly_timer->enabled()); + m_sh_dly_timer->adjust(attotime::from_nsec(DELAY_T1), 0); + LOG_NOISY("SH DLY enabled %d\n", m_sh_dly_timer->enabled()); } break; @@ -671,14 +671,14 @@ void phi_device::update_fsm(void) case PHI_SH_STRS: if (!get_signal(PHI_488_NDAC)) { - LOG("%.6f TX %02x/%d\n" , machine().time().as_double() , m_dio , m_signals[ PHI_488_EOI ]); + LOG("%.6f TX %02x/%d\n", machine().time().as_double(), m_dio, m_signals[PHI_488_EOI]); m_sh_state = PHI_SH_SGNS; clear_nba((nba_origin_t)m_nba_origin); } break; default: - logerror("Invalid SH state %d\n" , m_sh_state); + logerror("Invalid SH state %d\n", m_sh_state); m_sh_state = PHI_SH_SIDS; } } @@ -690,9 +690,9 @@ void phi_device::update_fsm(void) // EOI is controlled by SH & C FSMs bool eoi_signal = false; uint8_t dio_byte = 0; - set_signal(PHI_488_DAV , m_sh_state == PHI_SH_STRS); + set_signal(PHI_488_DAV, m_sh_state == PHI_SH_STRS); if (m_sh_state == PHI_SH_SDYS || m_sh_state == PHI_SH_STRS) { - nba_msg(new_byte , new_eoi); + nba_msg(new_byte, new_eoi); dio_byte = new_byte; eoi_signal = new_eoi; } @@ -733,9 +733,9 @@ void phi_device::update_fsm(void) uint8_t if_cmd = get_dio(); bool parity_ok = odd_parity(if_cmd); if (!parity_ok) { - BIT_SET(m_reg_int_cond , REG_INT_PARITY_ERR_BIT); + BIT_SET(m_reg_int_cond, REG_INT_PARITY_ERR_BIT); } - if (BIT(m_reg_control , REG_CTRL_PAR_FREEZE_BIT) && !parity_ok) { + if (BIT(m_reg_control, REG_CTRL_PAR_FREEZE_BIT) && !parity_ok) { // With even parity and PARITY FREEZE set, command is ignored and // AH FSM freezes in ACDS m_ah_state = PHI_AH_ACDS_FROZEN; @@ -746,7 +746,7 @@ void phi_device::update_fsm(void) m_ah_state = PHI_AH_AWNS; } } - } else if (byte_received(get_dio() , get_signal(PHI_488_EOI))) { + } else if (byte_received(get_dio(), get_signal(PHI_488_EOI))) { m_ah_state = PHI_AH_AWNS; } break; @@ -759,7 +759,7 @@ void phi_device::update_fsm(void) break; default: - logerror("Invalid AH state %d\n" , m_ah_state); + logerror("Invalid AH state %d\n", m_ah_state); m_ah_state = PHI_AH_AIDS; } } @@ -767,8 +767,8 @@ void phi_device::update_fsm(void) changed = true; } // AH outputs - set_signal(PHI_488_NRFD , m_ah_state == PHI_AH_ANRS || m_ah_state == PHI_AH_ACDS || m_ah_state == PHI_AH_ACDS_FROZEN || m_ah_state == PHI_AH_AWNS); - set_signal(PHI_488_NDAC , m_ah_state == PHI_AH_ANRS || m_ah_state == PHI_AH_ACRS || m_ah_state == PHI_AH_ACDS || m_ah_state == PHI_AH_ACDS_FROZEN); + set_signal(PHI_488_NRFD, m_ah_state == PHI_AH_ANRS || m_ah_state == PHI_AH_ACDS || m_ah_state == PHI_AH_ACDS_FROZEN || m_ah_state == PHI_AH_AWNS); + set_signal(PHI_488_NDAC, m_ah_state == PHI_AH_ANRS || m_ah_state == PHI_AH_ACRS || m_ah_state == PHI_AH_ACDS || m_ah_state == PHI_AH_ACDS_FROZEN); // T FSM prev_state = m_t_state; @@ -828,7 +828,7 @@ void phi_device::update_fsm(void) break; default: - logerror("Invalid T state %d\n" , m_t_state); + logerror("Invalid T state %d\n", m_t_state); m_t_state = PHI_T_TIDS; } } @@ -862,7 +862,7 @@ void phi_device::update_fsm(void) break; default: - logerror("Invalid L state %d\n" , m_l_state); + logerror("Invalid L state %d\n", m_l_state); m_l_state = PHI_L_LIDS; } } @@ -897,15 +897,15 @@ void phi_device::update_fsm(void) break; default: - logerror("Invalid PP state %d\n" , m_pp_state); + logerror("Invalid PP state %d\n", m_pp_state); m_pp_state = PHI_PP_PPIS; } if (m_pp_state != prev_state) { changed = true; } // PP outputs - if (m_pp_state == PHI_PP_PPAS && m_s_sense == !!BIT(m_reg_control , REG_CTRL_PP_RESPONSE_BIT)) { - LOG("%.6f PP %u\n" , machine().time().as_double() , m_ppr_msg); + if (m_pp_state == PHI_PP_PPAS && m_s_sense == !!BIT(m_reg_control, REG_CTRL_PP_RESPONSE_BIT)) { + LOG("%.6f PP %u\n", machine().time().as_double(), m_ppr_msg); dio_byte |= BIT_MASK<uint8_t>(m_ppr_msg); } @@ -931,7 +931,7 @@ void phi_device::update_fsm(void) case PHI_C_CACS: // If there are ifcmds to send, just stay in CACS // else wait for SH to finish its current transfer then decide what to do - if (nba_msg(new_byte , new_eoi) != NBA_CMD_FROM_OFIFO && + if (nba_msg(new_byte, new_eoi) != NBA_CMD_FROM_OFIFO && m_sh_state != PHI_SH_STRS && m_sh_state != PHI_SH_SDYS) { if (!m_fifo_out.empty()) { // Possible cases @@ -953,14 +953,14 @@ void phi_device::update_fsm(void) case PHI_C_CPPS: if (!rpp_msg()) { m_c_state = PHI_C_CAWS; - m_c_dly_timer->adjust(attotime::from_nsec(DELAY_T9)); + m_c_dly_timer->adjust(attotime::from_nsec(DELAY_T9), 1); } break; case PHI_C_CSBS: if (tcs_msg() && m_ah_state == PHI_AH_ANRS) { m_c_state = PHI_C_CSHS; - m_c_dly_timer->adjust(attotime::from_nsec(DELAY_T10)); + m_c_dly_timer->adjust(attotime::from_nsec(DELAY_T10), 1); } break; @@ -968,7 +968,7 @@ void phi_device::update_fsm(void) // tcs_msg cannot go false here if (!m_c_dly_timer->enabled()) { m_c_state = PHI_C_CSWS; - m_c_dly_timer->adjust(attotime::from_nsec(DELAY_T7)); + m_c_dly_timer->adjust(attotime::from_nsec(DELAY_T7), 1); } break; @@ -990,12 +990,12 @@ void phi_device::update_fsm(void) case PHI_C_CSWS: if (m_t_state == PHI_T_TADS || !m_c_dly_timer->enabled()) { m_c_state = PHI_C_CAWS; - m_c_dly_timer->adjust(attotime::from_nsec(DELAY_T9)); + m_c_dly_timer->adjust(attotime::from_nsec(DELAY_T9), 1); } break; default: - logerror("Invalid C state %d\n" , m_c_state); + logerror("Invalid C state %d\n", m_c_state); m_c_state = PHI_C_CIDS; } } @@ -1003,11 +1003,11 @@ void phi_device::update_fsm(void) changed = true; } // C outputs - set_signal(PHI_488_ATN , m_c_state == PHI_C_CACS || + set_signal(PHI_488_ATN, m_c_state == PHI_C_CACS || m_c_state == PHI_C_CPPS || m_c_state == PHI_C_CSWS || m_c_state == PHI_C_CAWS || m_c_state == PHI_C_CTRS); eoi_signal = eoi_signal || m_c_state == PHI_C_CPPS; - set_signal(PHI_488_EOI , eoi_signal); + set_signal(PHI_488_EOI, eoi_signal); set_dio(dio_byte); } @@ -1035,7 +1035,7 @@ void phi_device::update_fsm(void) } m_reg_int_cond &= ~REG_INT_STATE_MASK; if (m_fifo_out.empty()) { - BIT_SET(m_reg_int_cond , REG_INT_FIFO_IDLE_BIT); + BIT_SET(m_reg_int_cond, REG_INT_FIFO_IDLE_BIT); } if (!m_fifo_in.empty()) { BIT_SET(m_reg_int_cond, REG_INT_FIFO_AV_BIT); @@ -1053,7 +1053,7 @@ void phi_device::update_fsm(void) m_no_recursion = false; } -phi_device::nba_origin_t phi_device::nba_msg(uint8_t& new_byte , bool& new_eoi) const +phi_device::nba_origin_t phi_device::nba_msg(uint8_t& new_byte, bool& new_eoi) const { if (controller_in_charge() && m_c_state == PHI_C_CACS && !m_fifo_out.empty()) { uint16_t word = m_fifo_out.peek(); @@ -1070,14 +1070,14 @@ phi_device::nba_origin_t phi_device::nba_msg(uint8_t& new_byte , bool& new_eoi) switch (m_t_state) { case PHI_T_TACS: - if (!BIT(m_reg_status , REG_STATUS_DATA_FREEZE_BIT) && - !BIT(m_reg_int_cond , REG_INT_DEV_CLEAR_BIT) && + if (!BIT(m_reg_status, REG_STATUS_DATA_FREEZE_BIT) && + !BIT(m_reg_int_cond, REG_INT_DEV_CLEAR_BIT) && !m_fifo_out.empty()) { uint16_t word = m_fifo_out.peek(); - if (!BIT(word , REG_OFIFO_SPECIAL_BIT)) { + if (!BIT(word, REG_OFIFO_SPECIAL_BIT)) { // Talker sends a data byte new_byte = (uint8_t)word; - new_eoi = BIT(word , REG_OFIFO_END_BIT); + new_eoi = BIT(word, REG_OFIFO_END_BIT); return NBA_BYTE_FROM_OFIFO; } } @@ -1131,7 +1131,7 @@ void phi_device::clear_nba(nba_origin_t origin) bool phi_device::if_cmd_received(uint8_t byte) { - LOG("%.6f RX cmd: %02x\n" , machine().time().as_double() , byte); + LOG("%.6f RX cmd: %02x\n", machine().time().as_double(), byte); bool accepted = true; @@ -1264,9 +1264,9 @@ bool phi_device::if_cmd_received(uint8_t byte) case PHI_SA_PACS: if ((byte & IFCMD_PPX_MASK) == IFCMD_PPE_VALUE && m_pp_state == PHI_PP_PPIS) { // PPE - m_s_sense = BIT(byte , IFCMD_PPE_S_BIT); + m_s_sense = BIT(byte, IFCMD_PPE_S_BIT); m_ppr_msg = byte & IFCMD_PPE_PPR_MASK; - LOG("PPE s=%d ppr=%u\n" , m_s_sense , m_ppr_msg); + LOG("PPE s=%d ppr=%u\n", m_s_sense, m_ppr_msg); m_pp_state = PHI_PP_PPSS; } else if ((byte & IFCMD_PPX_MASK) == IFCMD_PPD_VALUE && m_pp_state == PHI_PP_PPSS) { // PPD @@ -1277,7 +1277,7 @@ bool phi_device::if_cmd_received(uint8_t byte) case PHI_SA_TPAS: case PHI_SA_LPAS: // command is a secondary address after MTA or MLA - if (m_fifo_in.full() || BIT(m_reg_int_cond , REG_INT_DEV_CLEAR_BIT)) { + if (m_fifo_in.full() || BIT(m_reg_int_cond, REG_INT_DEV_CLEAR_BIT)) { // No room for secondary address in FIFO, stall handshake accepted = false; } else { @@ -1304,7 +1304,7 @@ bool phi_device::if_cmd_received(uint8_t byte) return accepted; } -bool phi_device::byte_received(uint8_t byte , bool eoi) +bool phi_device::byte_received(uint8_t byte, bool eoi) { // Start with D0/D1 = 00 uint16_t word = byte; @@ -1321,7 +1321,7 @@ bool phi_device::byte_received(uint8_t byte , bool eoi) // Monitoring bytes being transferred on the bus if (eoi) { end_of_transfer = true; - } else if (!BIT(be_word , REG_OFIFO_LF_INH_BIT) && byte == 0x0a) { + } else if (!BIT(be_word, REG_OFIFO_LF_INH_BIT) && byte == 0x0a) { // LF received -> D0/D1 = 11 word |= REG_IFIFO_LAST_MASK; end_of_transfer = true; @@ -1332,10 +1332,10 @@ bool phi_device::byte_received(uint8_t byte , bool eoi) } } - LOG("%.6f RX word:%04x\n" , machine().time().as_double() , word); + LOG("%.6f RX word:%04x\n", machine().time().as_double(), word); if (m_l_state == PHI_L_LACS) { - if (m_fifo_in.full() || BIT(m_reg_int_cond , REG_INT_DEV_CLEAR_BIT)) { + if (m_fifo_in.full() || BIT(m_reg_int_cond, REG_INT_DEV_CLEAR_BIT)) { // No room for received byte, stall handshake LOG_NOISY("..stalled\n"); return false; @@ -1366,12 +1366,12 @@ void phi_device::rx_n_data_freeze(uint16_t word) bool phi_device::ton_msg(void) const { - return BIT(m_reg_address , REG_ADDR_TA_BIT); + return BIT(m_reg_address, REG_ADDR_TA_BIT); } bool phi_device::lon_msg(void) const { - return BIT(m_reg_address , REG_ADDR_LA_BIT); + return BIT(m_reg_address, REG_ADDR_LA_BIT); } bool phi_device::odd_parity(uint8_t byte) const @@ -1401,7 +1401,7 @@ bool phi_device::tcs_msg(void) const // * There's an interface command to be sent at head of OFIFO return (m_c_state == PHI_C_CSBS || m_c_state == PHI_C_CSHS || m_c_state == PHI_C_CSWS) && (rpp_msg() || - nba_msg(new_byte , new_eoi) == NBA_CMD_FROM_OFIFO); + nba_msg(new_byte, new_eoi) == NBA_CMD_FROM_OFIFO); } bool phi_device::rpp_msg(void) const @@ -1437,9 +1437,9 @@ void phi_device::update_pp() { if (m_c_state == PHI_C_CPPS) { if (m_fifo_in.empty() && get_pp_response()) { - BIT_SET(m_reg_int_cond , REG_INT_PP_RESPONSE_BIT); + BIT_SET(m_reg_int_cond, REG_INT_PP_RESPONSE_BIT); } else { - BIT_CLR(m_reg_int_cond , REG_INT_PP_RESPONSE_BIT); + BIT_CLR(m_reg_int_cond, REG_INT_PP_RESPONSE_BIT); } update_interrupt(); } @@ -1451,7 +1451,7 @@ void phi_device::update_interrupt() bool int_line = false; if (int_pending) { BIT_SET(m_reg_int_cond, REG_INT_PENDING_BIT); - if (BIT(m_reg_int_mask , REG_INT_PENDING_BIT)) { + if (BIT(m_reg_int_mask, REG_INT_PENDING_BIT)) { int_line = true; } } else { @@ -1459,7 +1459,7 @@ void phi_device::update_interrupt() } if (int_line != m_int_line) { m_int_line = int_line; - LOG_INT("INT %d\n" , m_int_line); + LOG_INT("INT %d\n", m_int_line); m_int_write_func(m_int_line); } } @@ -1467,14 +1467,14 @@ void phi_device::update_interrupt() void phi_device::update_dmarq() { bool new_dmarq_line; - if (BIT(m_reg_control , REG_CTRL_DMA_FIFO_BIT)) { - new_dmarq_line = BIT(m_reg_int_cond , REG_INT_FIFO_ROOM_BIT); + if (BIT(m_reg_control, REG_CTRL_DMA_FIFO_BIT)) { + new_dmarq_line = BIT(m_reg_int_cond, REG_INT_FIFO_ROOM_BIT); } else { - new_dmarq_line = BIT(m_reg_int_cond , REG_INT_FIFO_AV_BIT); + new_dmarq_line = BIT(m_reg_int_cond, REG_INT_FIFO_AV_BIT); } if (new_dmarq_line != m_dmarq_line) { m_dmarq_line = new_dmarq_line; - LOG_INT("DRQ %d\n" , m_dmarq_line); + LOG_INT("DRQ %d\n", m_dmarq_line); m_dmarq_write_func(m_dmarq_line); } } diff --git a/src/devices/machine/phi.h b/src/devices/machine/phi.h index 6e6e1cf54cf..4eb74b6bbca 100644 --- a/src/devices/machine/phi.h +++ b/src/devices/machine/phi.h @@ -36,14 +36,14 @@ public: auto dio_read_cb() { return m_dio_read_func.bind(); } auto dio_write_cb() { return m_dio_write_func.bind(); } // Set write callbacks to access uniline signals on IEEE-488 - auto eoi_write_cb() { return m_signal_wr_fns[ PHI_488_EOI ].bind(); } - auto dav_write_cb() { return m_signal_wr_fns[ PHI_488_DAV ].bind(); } - auto nrfd_write_cb() { return m_signal_wr_fns[ PHI_488_NRFD ].bind(); } - auto ndac_write_cb() { return m_signal_wr_fns[ PHI_488_NDAC ].bind(); } - auto ifc_write_cb() { return m_signal_wr_fns[ PHI_488_IFC ].bind(); } - auto srq_write_cb() { return m_signal_wr_fns[ PHI_488_SRQ ].bind(); } - auto atn_write_cb() { return m_signal_wr_fns[ PHI_488_ATN ].bind(); } - auto ren_write_cb() { return m_signal_wr_fns[ PHI_488_REN ].bind(); } + auto eoi_write_cb() { return m_signal_wr_fns[PHI_488_EOI].bind(); } + auto dav_write_cb() { return m_signal_wr_fns[PHI_488_DAV].bind(); } + auto nrfd_write_cb() { return m_signal_wr_fns[PHI_488_NRFD].bind(); } + auto ndac_write_cb() { return m_signal_wr_fns[PHI_488_NDAC].bind(); } + auto ifc_write_cb() { return m_signal_wr_fns[PHI_488_IFC].bind(); } + auto srq_write_cb() { return m_signal_wr_fns[PHI_488_SRQ].bind(); } + auto atn_write_cb() { return m_signal_wr_fns[PHI_488_ATN].bind(); } + auto ren_write_cb() { return m_signal_wr_fns[PHI_488_REN].bind(); } // Set write callback for INT signal auto int_write_cb() { return m_int_write_func.bind(); } // Set write callback for DMARQ signal @@ -62,7 +62,7 @@ public: void bus_dio_w(uint8_t data); - void set_ext_signal(phi_488_signal_t signal , int state); + void set_ext_signal(phi_488_signal_t signal, int state); // Register read/write // Mapping of PHI register bits: @@ -95,7 +95,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(delayed_update); private: // Depth of inbound/outbound FIFOs @@ -113,8 +114,8 @@ private: // Internal copy of bus signals // These signals have the "right" polarity (i.e. the opposite of bus signals, 1=L) uint8_t m_dio; - bool m_signals[ PHI_488_SIGNAL_COUNT ]; - bool m_ext_signals[ PHI_488_SIGNAL_COUNT ]; + bool m_signals[PHI_488_SIGNAL_COUNT]; + bool m_ext_signals[PHI_488_SIGNAL_COUNT]; bool m_no_recursion; @@ -227,8 +228,8 @@ private: uint16_t m_reg_2nd_id; uint16_t m_reg_control; uint16_t m_reg_address; - util::fifo<uint16_t , FIFO_SIZE> m_fifo_in; - util::fifo<uint16_t , FIFO_SIZE> m_fifo_out; + util::fifo<uint16_t, FIFO_SIZE> m_fifo_in; + util::fifo<uint16_t, FIFO_SIZE> m_fifo_out; typedef enum { NBA_NONE, @@ -245,20 +246,20 @@ private: emu_timer *m_sh_dly_timer; emu_timer *m_c_dly_timer; - void int_reg_w(offs_t offset , uint16_t data); + void int_reg_w(offs_t offset, uint16_t data); uint8_t get_dio(void); void set_dio(uint8_t data); bool get_signal(phi_488_signal_t signal); - void set_signal(phi_488_signal_t signal , bool state); + void set_signal(phi_488_signal_t signal, bool state); void pon_msg(void); void update_488(void); void update_fsm(void); - nba_origin_t nba_msg(uint8_t& new_byte , bool& new_eoi) const; + nba_origin_t nba_msg(uint8_t& new_byte, bool& new_eoi) const; void clear_nba(nba_origin_t origin); bool if_cmd_received(uint8_t byte); - bool byte_received(uint8_t byte , bool eoi); + bool byte_received(uint8_t byte, bool eoi); void rx_n_data_freeze(uint16_t word); bool ton_msg(void) const; bool lon_msg(void) const; diff --git a/src/devices/machine/pic8259.cpp b/src/devices/machine/pic8259.cpp index 591336e4a20..385f38cfbdb 100644 --- a/src/devices/machine/pic8259.cpp +++ b/src/devices/machine/pic8259.cpp @@ -29,7 +29,7 @@ ALLOW_SAVE_TYPE(pic8259_device::state_t); // allow save_item on a non-fundamental type -void pic8259_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(pic8259_device::irq_timer_tick) { /* check the various IRQs */ for (int n = 0, irq = m_prio; n < 8; n++, irq = (irq + 1) & 7) @@ -84,7 +84,7 @@ void pic8259_device::set_irq_line(int irq, int state) } if (m_inta_sequence == 0) - set_timer(); + m_irq_timer->adjust(attotime::zero); } @@ -105,7 +105,7 @@ uint8_t pic8259_device::acknowledge() if (!m_auto_eoi) m_isr |= mask; - set_timer(); + m_irq_timer->adjust(attotime::zero); } if ((m_cascade!=0) && (m_master!=0) && (mask & m_slave)) @@ -167,7 +167,7 @@ uint8_t pic8259_device::acknowledge() m_inta_sequence = 0; if (m_auto_eoi && m_current_level != -1) m_isr &= ~(1 << m_current_level); - set_timer(); + m_irq_timer->adjust(attotime::zero); } if (m_cascade && m_master && m_current_level != -1 && BIT(m_slave, m_current_level)) return m_read_slave_ack_func(m_current_level); @@ -205,7 +205,7 @@ uint8_t pic8259_device::read(offs_t offset) if (!m_auto_eoi) m_isr |= 1 << m_current_level; - set_timer(); + m_irq_timer->adjust(attotime::zero); } } else @@ -376,7 +376,7 @@ void pic8259_device::write(offs_t offset, uint8_t data) } break; } - set_timer(); + m_irq_timer->adjust(attotime::zero); } @@ -427,6 +427,8 @@ void pic8259_device::device_start() save_item(NAME(m_inta_sequence)); m_inta_sequence = 0; + + m_irq_timer = timer_alloc(FUNC(pic8259_device::irq_timer_tick), this); } diff --git a/src/devices/machine/pic8259.h b/src/devices/machine/pic8259.h index daa846b871e..333cadced09 100644 --- a/src/devices/machine/pic8259.h +++ b/src/devices/machine/pic8259.h @@ -59,17 +59,14 @@ 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 bool is_x86() const { return m_is_x86; } -private: - static constexpr device_timer_id TIMER_CHECK_IRQ = 0; + TIMER_CALLBACK_MEMBER(irq_timer_tick); - inline void set_timer() { timer_set(attotime::zero, TIMER_CHECK_IRQ); } +private: void set_irq_line(int irq, int state); - enum class state_t : u8 { ICW1, @@ -83,6 +80,7 @@ private: devcb_read_line m_in_sp_func; devcb_read8 m_read_slave_ack_func; + emu_timer *m_irq_timer; state_t m_state; uint8_t m_isr; diff --git a/src/devices/machine/pit8253.cpp b/src/devices/machine/pit8253.cpp index f09684f782a..fc7c79cc289 100644 --- a/src/devices/machine/pit8253.cpp +++ b/src/devices/machine/pit8253.cpp @@ -112,8 +112,8 @@ void pit8253_device::device_resolve_objects() void pit_counter_device::device_start() { - /* initialize timer */ - m_updatetimer = timer_alloc(TID_UPDATE); + /* initialize timers */ + m_update_timer = timer_alloc(FUNC(pit_counter_device::update_tick), this); adjust_timer(attotime::never); /* set up state save values */ @@ -204,7 +204,7 @@ inline void pit_counter_device::adjust_timer(attotime target) // if (target != m_next_update) { m_next_update = target; - m_updatetimer->adjust(target - machine().time()); + m_update_timer->adjust(target - machine().time()); } } @@ -972,30 +972,15 @@ void pit8254_device::readback_command(uint8_t data) m_counter[timer]->readback(read_command); } -void pit_counter_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(pit_counter_device::update_tick) { update(); - switch (id) - { - case TID_UPDATE: - break; - - case TID_CONTROL: - control_w_deferred(param); - break; - - case TID_COUNT: - count_w_deferred(param); - break; - - case TID_GATE: - gate_w_deferred(param); - break; - } } -void pit_counter_device::control_w_deferred(uint8_t data) +TIMER_CALLBACK_MEMBER(pit_counter_device::control_w_deferred) { + update(); + uint8_t data = (uint8_t)param; if (CTRL_ACCESS(data) == 0) { LOG1("write(): readback\n"); @@ -1017,8 +1002,10 @@ void pit_counter_device::control_w_deferred(uint8_t data) } } -void pit_counter_device::count_w_deferred(uint8_t data) +TIMER_CALLBACK_MEMBER(pit_counter_device::count_w_deferred) { + update(); + uint8_t data = (uint8_t)param; bool middle_of_a_cycle = (machine().time() > m_last_updated && m_clockin != 0); switch (CTRL_ACCESS(m_control)) @@ -1102,8 +1089,10 @@ void pit8253_device::write(offs_t offset, uint8_t data) m_counter[offset]->count_w(data); } -void pit_counter_device::gate_w_deferred(int state) +TIMER_CALLBACK_MEMBER(pit_counter_device::gate_w_deferred) { + update(); + int state = param; LOG2("gate_w(): state=%d\n", state); if (state != m_gate) diff --git a/src/devices/machine/pit8253.h b/src/devices/machine/pit8253.h index 430563ebebf..0c069a217d8 100644 --- a/src/devices/machine/pit8253.h +++ b/src/devices/machine/pit8253.h @@ -42,14 +42,6 @@ class pit_counter_device : public device_t friend class pit8253_device; friend class pit8254_device; - enum - { - TID_UPDATE = 1, - TID_CONTROL, - TID_COUNT, - TID_GATE - }; - public: // construction/destruction pit_counter_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock); @@ -58,7 +50,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: inline uint32_t adjusted_count() const; @@ -67,17 +58,18 @@ private: void load_counter_value(); void set_output(int output); void simulate(int64_t elapsed_cycles); + TIMER_CALLBACK_MEMBER(update_tick); void update(); uint16_t masked_value() const; uint8_t read(); void load_count(uint16_t newcount); void readback(int command); - void control_w(uint8_t data) { synchronize(TID_CONTROL, data); } - void control_w_deferred(uint8_t data); - void count_w(uint8_t data) { synchronize(TID_COUNT, data); } - void count_w_deferred(uint8_t data); - void gate_w(int state) { synchronize(TID_GATE, state); } - void gate_w_deferred(int state); + void control_w(uint8_t data) { machine().scheduler().synchronize(timer_expired_delegate(FUNC(pit_counter_device::control_w_deferred), this), data); } + TIMER_CALLBACK_MEMBER(control_w_deferred); + void count_w(uint8_t data) { machine().scheduler().synchronize(timer_expired_delegate(FUNC(pit_counter_device::count_w_deferred), this), data); } + TIMER_CALLBACK_MEMBER(count_w_deferred); + void gate_w(int state) { machine().scheduler().synchronize(timer_expired_delegate(FUNC(pit_counter_device::gate_w_deferred), this), state); } + TIMER_CALLBACK_MEMBER(gate_w_deferred); void set_clock_signal(int state); void set_clockin(double new_clockin); @@ -90,7 +82,7 @@ private: attotime m_last_updated; // time when last updated attotime m_next_update; // time of next update - emu_timer *m_updatetimer; // MAME timer to process updates + emu_timer *m_update_timer; // MAME timer to process updates uint16_t m_value; // current counter value ("CE" in Intel docs) uint16_t m_latch; // latched counter value ("OL" in Intel docs) diff --git a/src/devices/machine/ps2timer.cpp b/src/devices/machine/ps2timer.cpp index 2f7111b1a22..667fed7622c 100644 --- a/src/devices/machine/ps2timer.cpp +++ b/src/devices/machine/ps2timer.cpp @@ -42,10 +42,10 @@ ps2_timer_device::ps2_timer_device(const machine_config &mconfig, const char *ta void ps2_timer_device::device_start() { if (!m_compare_timer) - m_compare_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(ps2_timer_device::compare), this)); + m_compare_timer = timer_alloc(FUNC(ps2_timer_device::compare), this); if (!m_overflow_timer) - m_overflow_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(ps2_timer_device::overflow), this)); + m_overflow_timer = timer_alloc(FUNC(ps2_timer_device::overflow), this); } void ps2_timer_device::device_reset() diff --git a/src/devices/machine/pxa255.cpp b/src/devices/machine/pxa255.cpp index 55aba8af310..d387347dd98 100644 --- a/src/devices/machine/pxa255.cpp +++ b/src/devices/machine/pxa255.cpp @@ -57,7 +57,7 @@ pxa255_periphs_device::pxa255_periphs_device(const machine_config &mconfig, cons uint32_t pxa255_periphs_device::i2s_r(offs_t offset, uint32_t mem_mask) { - switch(PXA255_I2S_BASE_ADDR | (offset << 2)) + switch (PXA255_I2S_BASE_ADDR | (offset << 2)) { case PXA255_SACR0: LOGMASKED(LOG_I2S, "pxa255_i2s_r: Serial Audio Controller Global Control Register: %08x & %08x\n", m_i2s_regs.sacr0, mem_mask); @@ -89,7 +89,7 @@ uint32_t pxa255_periphs_device::i2s_r(offs_t offset, uint32_t mem_mask) void pxa255_periphs_device::i2s_w(offs_t offset, uint32_t data, uint32_t mem_mask) { - switch(PXA255_I2S_BASE_ADDR | (offset << 2)) + switch (PXA255_I2S_BASE_ADDR | (offset << 2)) { case PXA255_SACR0: LOGMASKED(LOG_I2S, "pxa255_i2s_w: Serial Audio Controller Global Control Register: %08x & %08x\n", data, mem_mask); @@ -109,11 +109,11 @@ void pxa255_periphs_device::i2s_w(offs_t offset, uint32_t data, uint32_t mem_mas break; case PXA255_SAICR: LOGMASKED(LOG_I2S, "pxa255_i2s_w: Serial Audio Interrupt Clear Register: %08x & %08x\n", data, mem_mask); - if(m_i2s_regs.saicr & PXA255_SAICR_ROR) + if (m_i2s_regs.saicr & PXA255_SAICR_ROR) { m_i2s_regs.sasr0 &= ~PXA255_SASR0_ROR; } - if(m_i2s_regs.saicr & PXA255_SAICR_TUR) + if (m_i2s_regs.saicr & PXA255_SAICR_TUR) { m_i2s_regs.sasr0 &= ~PXA255_SASR0_TUR; } @@ -182,7 +182,7 @@ void pxa255_periphs_device::dma_load_descriptor_and_start(int channel) m_dma_regs.ddadr[channel] = space.read_dword(m_dma_regs.ddadr[channel]); // Start our end-of-transfer timer - switch(channel) + switch (channel) { case 3: m_dma_regs.timer[channel]->adjust(attotime::from_hz((147600000 / m_i2s_regs.sadiv) / (4 * 64)) * (m_dma_regs.dcmd[channel] & 0x00001fff), channel); @@ -193,7 +193,7 @@ void pxa255_periphs_device::dma_load_descriptor_and_start(int channel) } // Interrupt as necessary - if(m_dma_regs.dcmd[channel] & PXA255_DCMD_STARTIRQEN) + if (m_dma_regs.dcmd[channel] & PXA255_DCMD_STARTIRQEN) { m_dma_regs.dcsr[channel] |= PXA255_DCSR_STARTINTR; } @@ -201,89 +201,69 @@ void pxa255_periphs_device::dma_load_descriptor_and_start(int channel) m_dma_regs.dcsr[channel] &= ~PXA255_DCSR_STOPSTATE; } -void pxa255_periphs_device::dma_end_tick(int channel) +TIMER_CALLBACK_MEMBER(pxa255_periphs_device::audio_dma_end_tick) { - uint32_t sadr = m_dma_regs.dsadr[channel]; - uint32_t tadr = m_dma_regs.dtadr[channel]; - uint32_t count = m_dma_regs.dcmd[channel] & 0x00001fff; - address_space &space = m_maincpu->space(AS_PROGRAM); - switch (channel) + const uint32_t count = m_dma_regs.dcmd[3] & 0x00001fff; + uint32_t sadr = m_dma_regs.dsadr[3]; + + int16_t *out_samples = &m_samples[0]; + for (uint32_t index = 0; index < count; index += 4, sadr += 4) { - case 3: - for (uint32_t index = 0; index < count; index += 4) - { - m_words[index >> 2] = space.read_dword(sadr); - m_samples[(index >> 1) + 0] = (int16_t)(m_words[index >> 2] >> 16); - m_samples[(index >> 1) + 1] = (int16_t)(m_words[index >> 2] & 0xffff); - sadr += 4; - } - for (int index = 0; index < 2; index++) - { - m_dmadac[index]->flush(); - m_dmadac[index]->transfer(index, 2, 2, count/4, m_samples.get()); - } - break; - default: - for (uint32_t index = 0; index < count;) - { - switch (m_dma_regs.dcmd[channel] & PXA255_DCMD_SIZE) - { - case PXA255_DCMD_SIZE_8: - space.write_byte(tadr, space.read_byte(sadr)); - index++; - break; - case PXA255_DCMD_SIZE_16: - space.write_word(tadr, space.read_word(sadr)); - index += 2; - break; - case PXA255_DCMD_SIZE_32: - space.write_dword(tadr, space.read_dword(sadr)); - index += 4; - break; - default: - logerror( "pxa255_dma_dma_end: Unsupported DMA size\n" ); - break; - } + const uint32_t word = space.read_dword(sadr); + *out_samples++ = (int16_t)(word >> 16); + *out_samples++ = (int16_t)(word & 0xffff); + } - if (m_dma_regs.dcmd[channel] & PXA255_DCMD_INCSRCADDR) - { - switch(m_dma_regs.dcmd[channel] & PXA255_DCMD_SIZE) - { - case PXA255_DCMD_SIZE_8: - sadr++; - break; - case PXA255_DCMD_SIZE_16: - sadr += 2; - break; - case PXA255_DCMD_SIZE_32: - sadr += 4; - break; - default: - break; - } - } - if(m_dma_regs.dcmd[channel] & PXA255_DCMD_INCTRGADDR) - { - switch(m_dma_regs.dcmd[channel] & PXA255_DCMD_SIZE) - { - case PXA255_DCMD_SIZE_8: - tadr++; - break; - case PXA255_DCMD_SIZE_16: - tadr += 2; - break; - case PXA255_DCMD_SIZE_32: - tadr += 4; - break; - default: - break; - } - } - } - break; + for (int index = 0; index < 2; index++) + { + m_dmadac[index]->flush(); + m_dmadac[index]->transfer(index, 2, 2, count/4, m_samples.get()); } + dma_finish(param); +} + +TIMER_CALLBACK_MEMBER(pxa255_periphs_device::dma_end_tick) +{ + address_space &space = m_maincpu->space(AS_PROGRAM); + const uint32_t count = m_dma_regs.dcmd[param] & 0x00001fff; + uint32_t sadr = m_dma_regs.dsadr[param]; + uint32_t tadr = m_dma_regs.dtadr[param]; + + static const uint32_t s_inc_size[4] = { 0, 1, 2, 4 }; + const uint32_t inc_index = (m_dma_regs.dcmd[param] >> PXA255_DCMD_SIZE_SHIFT) & PXA255_DCMD_SIZE_MASK; + const uint32_t inc_val = s_inc_size[inc_index]; + const uint32_t sadr_inc = (m_dma_regs.dcmd[param] & PXA255_DCMD_INCSRCADDR) ? inc_val : 0; + const uint32_t tadr_inc = (m_dma_regs.dcmd[param] & PXA255_DCMD_INCTRGADDR) ? inc_val : 0; + + if (inc_val > 0) + { + switch (inc_val) + { + case PXA255_DCMD_SIZE_8: + for (uint32_t index = 0; index < count; index += inc_val, sadr += sadr_inc, tadr += tadr_inc) + space.write_byte(tadr, space.read_byte(sadr)); + break; + case PXA255_DCMD_SIZE_16: + for (uint32_t index = 0; index < count; index += inc_val, sadr += sadr_inc, tadr += tadr_inc) + space.write_word(tadr, space.read_byte(sadr)); + break; + case PXA255_DCMD_SIZE_32: + for (uint32_t index = 0; index < count; index += inc_val, sadr += sadr_inc, tadr += tadr_inc) + space.write_dword(tadr, space.read_byte(sadr)); + break; + default: + logerror( "pxa255_dma_dma_end: Unsupported DMA size\n" ); + break; + } + } + + dma_finish(param); +} + +void pxa255_periphs_device::dma_finish(int channel) +{ if (m_dma_regs.dcmd[channel] & PXA255_DCMD_ENDIRQEN) { m_dma_regs.dcsr[channel] |= PXA255_DCSR_ENDINTR; @@ -312,7 +292,7 @@ void pxa255_periphs_device::dma_end_tick(int channel) uint32_t pxa255_periphs_device::dma_r(offs_t offset, uint32_t mem_mask) { - switch(PXA255_DMA_BASE_ADDR | (offset << 2)) + switch (PXA255_DMA_BASE_ADDR | (offset << 2)) { case PXA255_DCSR0: case PXA255_DCSR1: case PXA255_DCSR2: case PXA255_DCSR3: case PXA255_DCSR4: case PXA255_DCSR5: case PXA255_DCSR6: case PXA255_DCSR7: @@ -389,7 +369,7 @@ void pxa255_periphs_device::dma_w(offs_t offset, uint32_t data, uint32_t mem_mas dma_load_descriptor_and_start(offset); } - else if(!(data & PXA255_DCSR_RUN)) + else if (!(data & PXA255_DCSR_RUN)) { m_dma_regs.dcsr[offset] &= ~PXA255_DCSR_RUN; } @@ -455,7 +435,7 @@ void pxa255_periphs_device::dma_w(offs_t offset, uint32_t data, uint32_t mem_mas */ -void pxa255_periphs_device::rtc_tick() +TIMER_CALLBACK_MEMBER(pxa255_periphs_device::rtc_tick) { m_rtc_regs.rcnr++; if (BIT(m_rtc_regs.rtsr, 3)) @@ -476,7 +456,7 @@ void pxa255_periphs_device::rtc_tick() uint32_t pxa255_periphs_device::rtc_r(offs_t offset, uint32_t mem_mask) { - switch(PXA255_RTC_BASE_ADDR | (offset << 2)) + switch (PXA255_RTC_BASE_ADDR | (offset << 2)) { case PXA255_RCNR: LOGMASKED(LOG_RTC, "%s: pxa255 rtc_r: RTC Counter Register: %08x\n", machine().describe_context(), m_rtc_regs.rcnr); @@ -499,7 +479,7 @@ uint32_t pxa255_periphs_device::rtc_r(offs_t offset, uint32_t mem_mask) void pxa255_periphs_device::rtc_w(offs_t offset, uint32_t data, uint32_t mem_mask) { - switch(PXA255_RTC_BASE_ADDR | (offset << 2)) + switch (PXA255_RTC_BASE_ADDR | (offset << 2)) { case PXA255_RCNR: LOGMASKED(LOG_RTC, "pxa255 rtc_w: RTC Counter Register: %08x & %08x\n", machine().describe_context(), data, mem_mask); @@ -552,16 +532,16 @@ void pxa255_periphs_device::ostimer_irq_check() //set_irq_line(PXA255_INT_OSTIMER3, (m_ostimer_regs.oier & PXA255_OIER_E3) ? ((m_ostimer_regs.ossr & PXA255_OSSR_M3) ? 1 : 0) : 0); } -void pxa255_periphs_device::ostimer_match_tick(int channel) +TIMER_CALLBACK_MEMBER(pxa255_periphs_device::ostimer_match_tick) { - m_ostimer_regs.ossr |= (1 << channel); - m_ostimer_regs.oscr = m_ostimer_regs.osmr[channel]; + m_ostimer_regs.ossr |= (1 << param); + m_ostimer_regs.oscr = m_ostimer_regs.osmr[param]; ostimer_irq_check(); } uint32_t pxa255_periphs_device::ostimer_r(offs_t offset, uint32_t mem_mask) { - switch(PXA255_OSTMR_BASE_ADDR | (offset << 2)) + switch (PXA255_OSTMR_BASE_ADDR | (offset << 2)) { case PXA255_OSMR0: LOGMASKED(LOG_OSTIMER, "pxa255_ostimer_r: OS Timer Match Register 0: %08x & %08x\n", m_ostimer_regs.osmr[0], mem_mask); @@ -598,14 +578,14 @@ uint32_t pxa255_periphs_device::ostimer_r(offs_t offset, uint32_t mem_mask) void pxa255_periphs_device::ostimer_w(offs_t offset, uint32_t data, uint32_t mem_mask) { - switch(PXA255_OSTMR_BASE_ADDR | (offset << 2)) + switch (PXA255_OSTMR_BASE_ADDR | (offset << 2)) { case PXA255_OSMR0: LOGMASKED(LOG_OSTIMER, "pxa255_ostimer_w: OS Timer Match Register 0: %08x & %08x\n", data, mem_mask); m_ostimer_regs.osmr[0] = data; if (m_ostimer_regs.oier & PXA255_OIER_E0) { - m_ostimer_regs.timer[0]->adjust(attotime::from_hz(3846400) * (m_ostimer_regs.osmr[0] - m_ostimer_regs.oscr)); + m_ostimer_regs.timer[0]->adjust(attotime::from_hz(3846400) * (m_ostimer_regs.osmr[0] - m_ostimer_regs.oscr), 0); } break; case PXA255_OSMR1: @@ -828,7 +808,7 @@ void pxa255_periphs_device::gpio_bit_w(offs_t offset, uint8_t data, uint8_t mem_ uint32_t pxa255_periphs_device::gpio_r(offs_t offset, uint32_t mem_mask) { - switch(PXA255_GPIO_BASE_ADDR | (offset << 2)) + switch (PXA255_GPIO_BASE_ADDR | (offset << 2)) { case PXA255_GPLR0: { @@ -929,7 +909,7 @@ uint32_t pxa255_periphs_device::gpio_r(offs_t offset, uint32_t mem_mask) void pxa255_periphs_device::gpio_w(offs_t offset, uint32_t data, uint32_t mem_mask) { - switch(PXA255_GPIO_BASE_ADDR | (offset << 2)) + switch (PXA255_GPIO_BASE_ADDR | (offset << 2)) { case PXA255_GPLR0: LOGMASKED(LOG_GPIO, "pxa255_gpio_w: (Invalid Write) GPIO Pin-Level Register 0: %08x & %08x\n", data, mem_mask); @@ -1093,7 +1073,7 @@ void pxa255_periphs_device::lcd_load_dma_descriptor(address_space & space, uint3 void pxa255_periphs_device::lcd_irq_check() { - if(((m_lcd_regs.lcsr & PXA255_LCSR_BS) != 0 && (m_lcd_regs.lccr0 & PXA255_LCCR0_BM) == 0) || + if (((m_lcd_regs.lcsr & PXA255_LCSR_BS) != 0 && (m_lcd_regs.lccr0 & PXA255_LCCR0_BM) == 0) || ((m_lcd_regs.lcsr & PXA255_LCSR_EOF) != 0 && (m_lcd_regs.lccr0 & PXA255_LCCR0_EFM) == 0) || ((m_lcd_regs.lcsr & PXA255_LCSR_SOF) != 0 && (m_lcd_regs.lccr0 & PXA255_LCCR0_SFM) == 0)) { @@ -1107,20 +1087,20 @@ void pxa255_periphs_device::lcd_irq_check() void pxa255_periphs_device::lcd_dma_kickoff(int channel) { - if(m_lcd_regs.dma[channel].fdadr != 0) + if (m_lcd_regs.dma[channel].fdadr != 0) { attotime period = attotime::from_hz(20000000) * (m_lcd_regs.dma[channel].ldcmd & 0x000fffff); m_lcd_regs.dma[channel].eof->adjust(period, channel); - if(m_lcd_regs.dma[channel].ldcmd & PXA255_LDCMD_SOFINT) + if (m_lcd_regs.dma[channel].ldcmd & PXA255_LDCMD_SOFINT) { m_lcd_regs.liidr = m_lcd_regs.dma[channel].fidr; m_lcd_regs.lcsr |= PXA255_LCSR_SOF; lcd_irq_check(); } - if(m_lcd_regs.dma[channel].ldcmd & PXA255_LDCMD_PAL) + if (m_lcd_regs.dma[channel].ldcmd & PXA255_LDCMD_PAL) { address_space &space = m_maincpu->space(AS_PROGRAM); int length = m_lcd_regs.dma[channel].ldcmd & 0x000fffff; @@ -1147,7 +1127,7 @@ void pxa255_periphs_device::lcd_dma_kickoff(int channel) void pxa255_periphs_device::lcd_check_load_next_branch(int channel) { - if(m_lcd_regs.fbr[channel] & 1) + if (m_lcd_regs.fbr[channel] & 1) { LOGMASKED(LOG_LCD_DMA, "lcd_check_load_next_branch: Taking branch\n" ); m_lcd_regs.fbr[channel] &= ~1; @@ -1157,10 +1137,10 @@ void pxa255_periphs_device::lcd_check_load_next_branch(int channel) lcd_load_dma_descriptor(space, m_lcd_regs.fbr[channel] & 0xfffffff0, 0); m_lcd_regs.fbr[channel] = (space.read_dword(m_lcd_regs.fbr[channel] & 0xfffffff0) & 0xfffffff0) | (m_lcd_regs.fbr[channel] & 0x00000003); lcd_dma_kickoff(0); - if(m_lcd_regs.fbr[channel] & 2) + if (m_lcd_regs.fbr[channel] & 2) { m_lcd_regs.fbr[channel] &= ~2; - if(!(m_lcd_regs.lccr0 & PXA255_LCCR0_BM)) + if (!(m_lcd_regs.lccr0 & PXA255_LCCR0_BM)) { m_lcd_regs.lcsr |= PXA255_LCSR_BS; } @@ -1172,21 +1152,21 @@ void pxa255_periphs_device::lcd_check_load_next_branch(int channel) } } -void pxa255_periphs_device::lcd_dma_eof_tick(int channel) +TIMER_CALLBACK_MEMBER(pxa255_periphs_device::lcd_dma_eof_tick) { LOGMASKED(LOG_LCD_DMA, "End of frame callback\n" ); - if(m_lcd_regs.dma[channel].ldcmd & PXA255_LDCMD_EOFINT) + if (m_lcd_regs.dma[param].ldcmd & PXA255_LDCMD_EOFINT) { - m_lcd_regs.liidr = m_lcd_regs.dma[channel].fidr; + m_lcd_regs.liidr = m_lcd_regs.dma[param].fidr; m_lcd_regs.lcsr |= PXA255_LCSR_EOF; } - lcd_check_load_next_branch(channel); + lcd_check_load_next_branch(param); lcd_irq_check(); } uint32_t pxa255_periphs_device::lcd_r(offs_t offset, uint32_t mem_mask) { - switch(PXA255_LCD_BASE_ADDR | (offset << 2)) + switch (PXA255_LCD_BASE_ADDR | (offset << 2)) { case PXA255_LCCR0: // 0x44000000 LOGMASKED(LOG_LCD, "pxa255_lcd_r: LCD Control 0: %08x & %08x\n", m_lcd_regs.lccr0, mem_mask); @@ -1251,7 +1231,7 @@ uint32_t pxa255_periphs_device::lcd_r(offs_t offset, uint32_t mem_mask) void pxa255_periphs_device::lcd_w(address_space &space, offs_t offset, uint32_t data, uint32_t mem_mask) { - switch(PXA255_LCD_BASE_ADDR | (offset << 2)) + switch (PXA255_LCD_BASE_ADDR | (offset << 2)) { case PXA255_LCCR0: // 0x44000000 LOGMASKED(LOG_LCD, "pxa255_lcd_w: LCD Control 0: %08x & %08x\n", data, mem_mask); @@ -1272,7 +1252,7 @@ void pxa255_periphs_device::lcd_w(address_space &space, offs_t offset, uint32_t case PXA255_FBR0: // 0x44000020 LOGMASKED(LOG_LCD, "pxa255_lcd_w: LCD Frame Branch Register 0: %08x & %08x\n", data, mem_mask); m_lcd_regs.fbr[0] = data & 0xfffffff3; - if(!m_lcd_regs.dma[0].eof->enabled()) + if (!m_lcd_regs.dma[0].eof->enabled()) { LOGMASKED(LOG_LCD, "ch0 EOF timer is not enabled, taking branch now\n" ); lcd_check_load_next_branch(0); @@ -1282,7 +1262,7 @@ void pxa255_periphs_device::lcd_w(address_space &space, offs_t offset, uint32_t case PXA255_FBR1: // 0x44000024 LOGMASKED(LOG_LCD, "pxa255_lcd_w: LCD Frame Branch Register 1: %08x & %08x\n", data, mem_mask); m_lcd_regs.fbr[1] = data & 0xfffffff3; - if(!m_lcd_regs.dma[1].eof->enabled()) + if (!m_lcd_regs.dma[1].eof->enabled()) { LOGMASKED(LOG_LCD, "ch1 EOF timer is not enabled, taking branch now\n" ); lcd_check_load_next_branch(1); @@ -1307,7 +1287,7 @@ void pxa255_periphs_device::lcd_w(address_space &space, offs_t offset, uint32_t break; case PXA255_FDADR0: // 0x44000200 LOGMASKED(LOG_LCD, "pxa255_lcd_w: LCD DMA Frame Descriptor Address Register 0: %08x & %08x\n", data, mem_mask); - if(!m_lcd_regs.dma[0].eof->enabled()) + if (!m_lcd_regs.dma[0].eof->enabled()) { lcd_load_dma_descriptor(space, data & 0xfffffff0, 0); } @@ -1328,7 +1308,7 @@ void pxa255_periphs_device::lcd_w(address_space &space, offs_t offset, uint32_t break; case PXA255_FDADR1: // 0x44000210 LOGMASKED(LOG_LCD, "pxa255_lcd_w: LCD DMA Frame Descriptor Address Register 1: %08x & %08x\n", data, mem_mask); - if(!m_lcd_regs.dma[1].eof->enabled()) + if (!m_lcd_regs.dma[1].eof->enabled()) { lcd_load_dma_descriptor(space, data & 0xfffffff0, 1); } @@ -1355,7 +1335,7 @@ void pxa255_periphs_device::lcd_w(address_space &space, offs_t offset, uint32_t uint32_t pxa255_periphs_device::power_r(offs_t offset, uint32_t mem_mask) { - switch(PXA255_POWER_BASE_ADDR | (offset << 2)) + switch (PXA255_POWER_BASE_ADDR | (offset << 2)) { case PXA255_PMCR: LOGMASKED(LOG_POWER, "%s: power_r: Power Manager Control Register: %08x\n", machine().describe_context(), m_power_regs.pmcr); @@ -1405,7 +1385,7 @@ uint32_t pxa255_periphs_device::power_r(offs_t offset, uint32_t mem_mask) void pxa255_periphs_device::power_w(offs_t offset, uint32_t data, uint32_t mem_mask) { - switch(PXA255_POWER_BASE_ADDR | (offset << 2)) + switch (PXA255_POWER_BASE_ADDR | (offset << 2)) { case PXA255_PMCR: LOGMASKED(LOG_POWER, "%s: power_w: Power Manager Control Register = %08x & %08x\n", machine().describe_context(), data, mem_mask); @@ -1471,7 +1451,7 @@ void pxa255_periphs_device::power_w(offs_t offset, uint32_t data, uint32_t mem_m uint32_t pxa255_periphs_device::clocks_r(offs_t offset, uint32_t mem_mask) { - switch(PXA255_CLOCKS_BASE_ADDR | (offset << 2)) + switch (PXA255_CLOCKS_BASE_ADDR | (offset << 2)) { case PXA255_CCCR: LOGMASKED(LOG_CLOCKS, "%s: clocks_r: Core Clock Configuration Register: %08x\n", machine().describe_context(), m_clocks_regs.cccr); @@ -1491,7 +1471,7 @@ uint32_t pxa255_periphs_device::clocks_r(offs_t offset, uint32_t mem_mask) void pxa255_periphs_device::clocks_w(offs_t offset, uint32_t data, uint32_t mem_mask) { - switch(PXA255_CLOCKS_BASE_ADDR | (offset << 2)) + switch (PXA255_CLOCKS_BASE_ADDR | (offset << 2)) { case PXA255_CCCR: LOGMASKED(LOG_CLOCKS, "%s: clocks_w: Core Clock Configuration Register = %08x & %08x\n", machine().describe_context(), data, mem_mask); @@ -1519,20 +1499,26 @@ void pxa255_periphs_device::device_start() { for (int index = 0; index < 16; index++) { - m_dma_regs.timer[index] = timer_alloc(TIMER_DMA0 + index); + if (index != 3) + { + m_dma_regs.timer[index] = timer_alloc(FUNC(pxa255_periphs_device::dma_end_tick), this); + } + else + { + m_dma_regs.timer[index] = timer_alloc(FUNC(pxa255_periphs_device::audio_dma_end_tick), this); + } } for (int index = 0; index < 4; index++) { - m_ostimer_regs.timer[index] = timer_alloc(TIMER_OSTIMER0 + index); + m_ostimer_regs.timer[index] = timer_alloc(FUNC(pxa255_periphs_device::ostimer_match_tick), this); } - m_lcd_regs.dma[0].eof = timer_alloc(TIMER_LCD_EOF0); - m_lcd_regs.dma[1].eof = timer_alloc(TIMER_LCD_EOF0 + 1); + m_lcd_regs.dma[0].eof = timer_alloc(FUNC(pxa255_periphs_device::lcd_dma_eof_tick), this); + m_lcd_regs.dma[1].eof = timer_alloc(FUNC(pxa255_periphs_device::lcd_dma_eof_tick), this); m_lcd_palette = make_unique_clear<uint32_t[]>(0x100); m_lcd_framebuffer = make_unique_clear<uint8_t[]>(0x100000); - m_words = make_unique_clear<uint32_t[]>(0x800); m_samples = make_unique_clear<int16_t[]>(0x1000); m_gpio0_w.resolve_safe(); @@ -1542,7 +1528,7 @@ void pxa255_periphs_device::device_start() m_gpio1_r.resolve_safe(0xffffffff); m_gpio2_r.resolve_safe(0xffffffff); - m_rtc_regs.timer = timer_alloc(TIMER_RTC); + m_rtc_regs.timer = timer_alloc(FUNC(pxa255_periphs_device::rtc_tick), this); } void pxa255_periphs_device::device_reset() @@ -1567,18 +1553,6 @@ void pxa255_periphs_device::device_reset() memset(&m_clocks_regs, 0, sizeof(m_clocks_regs)); } -void pxa255_periphs_device::device_timer(emu_timer &timer, device_timer_id id, int param) -{ - if (id < TIMER_OSTIMER0) - dma_end_tick(id); - else if (id < TIMER_LCD_EOF0) - ostimer_match_tick(id - TIMER_OSTIMER0); - else if (id < TIMER_RTC) - lcd_dma_eof_tick(id - TIMER_LCD_EOF0); - else if (id == TIMER_RTC) - rtc_tick(); -} - uint32_t pxa255_periphs_device::screen_update(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect) { for (int y = 0; y <= (m_lcd_regs.lccr2 & PXA255_LCCR2_LPP); y++) diff --git a/src/devices/machine/pxa255.h b/src/devices/machine/pxa255.h index 22ee82a4b8a..75eadbac2c5 100644 --- a/src/devices/machine/pxa255.h +++ b/src/devices/machine/pxa255.h @@ -65,12 +65,6 @@ protected: virtual void device_add_mconfig(machine_config &config) override; virtual void device_start() override; virtual void device_reset() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; - - static const device_timer_id TIMER_DMA0 = 0; - static const device_timer_id TIMER_OSTIMER0 = 16; - static const device_timer_id TIMER_LCD_EOF0 = 20; - static const device_timer_id TIMER_RTC = 22; void dma_irq_check(); void dma_load_descriptor_and_start(int channel); @@ -83,11 +77,13 @@ protected: uint32_t screen_update(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect); - void dma_end_tick(int channel); - void ostimer_match_tick(int channel); - void lcd_dma_eof_tick(int channel); - void rtc_tick(); + TIMER_CALLBACK_MEMBER(dma_end_tick); + TIMER_CALLBACK_MEMBER(audio_dma_end_tick); + TIMER_CALLBACK_MEMBER(ostimer_match_tick); + TIMER_CALLBACK_MEMBER(lcd_dma_eof_tick); + TIMER_CALLBACK_MEMBER(rtc_tick); + void dma_finish(int channel); void set_irq_line(uint32_t line, int state); struct dma_regs @@ -269,7 +265,6 @@ protected: std::unique_ptr<uint32_t[]> m_lcd_palette; // 0x100 std::unique_ptr<uint8_t[]> m_lcd_framebuffer; // 0x100000 - std::unique_ptr<uint32_t[]> m_words; // 0x800 std::unique_ptr<int16_t[]> m_samples; // 0x1000 }; diff --git a/src/devices/machine/pxa255defs.h b/src/devices/machine/pxa255defs.h index 9857a0871d3..424eeb0c53c 100644 --- a/src/devices/machine/pxa255defs.h +++ b/src/devices/machine/pxa255defs.h @@ -156,11 +156,12 @@ #define PXA255_DCMD_STARTIRQEN (0x00400000) #define PXA255_DCMD_ENDIRQEN (0x00200000) #define PXA255_DCMD_ENDIAN (0x00040000) - #define PXA255_DCMD_SIZE (0x00030000) - #define PXA255_DCMD_SIZE_0 (0x00000000) - #define PXA255_DCMD_SIZE_8 (0x00010000) - #define PXA255_DCMD_SIZE_16 (0x00020000) - #define PXA255_DCMD_SIZE_32 (0x00030000) + #define PXA255_DCMD_SIZE_SHIFT (16) + #define PXA255_DCMD_SIZE_MASK (0x00000003) + #define PXA255_DCMD_SIZE_0 (0x00000000) + #define PXA255_DCMD_SIZE_8 (0x00000001) + #define PXA255_DCMD_SIZE_16 (0x00000002) + #define PXA255_DCMD_SIZE_32 (0x00000003) #define PXA255_DCMD_WIDTH (0x0000c000) #define PXA255_DCMD_WIDTH_0 (0x00000000) #define PXA255_DCMD_WIDTH_1 (0x00004000) diff --git a/src/devices/machine/r10788.cpp b/src/devices/machine/r10788.cpp index cb1b7d9a374..4a8a8161ad5 100644 --- a/src/devices/machine/r10788.cpp +++ b/src/devices/machine/r10788.cpp @@ -80,7 +80,7 @@ void r10788_device::device_start() save_item(NAME(m_io_counter)); save_item(NAME(m_scan_counter)); - m_timer = timer_alloc(TIMER_DISPLAY); + m_timer = timer_alloc(FUNC(r10788_device::display_update), this); // recurring timer every 36 cycles m_timer->adjust(clocks_to_attotime(36), 0, clocks_to_attotime(36)); } @@ -102,27 +102,11 @@ void r10788_device::device_reset() } -/** - * @brief r10788_device::device_timer timer event callback - * @param timer emu_timer which fired - * @param id timer identifier - * @param param parameter - * @param ptr pointer parameter - */ -void r10788_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(r10788_device::display_update) { - uint8_t data; - switch (id) - { - case TIMER_DISPLAY: - data = (m_reg[0][m_scan_counter] & m_mask_a) + - 16 * (m_reg[1][m_scan_counter] & m_mask_b); - LOG("%s: scan counter:%2d data:%02x\n", __FUNCTION__, m_scan_counter, data); - m_display(m_scan_counter, data, 0xff); - break; - default: - LOG("%s: invalid timer id:%d\n", __FUNCTION__, id); - } + uint8_t data = ((m_reg[1][m_scan_counter] & m_mask_b) << 4) | (m_reg[0][m_scan_counter] & m_mask_a); + LOG("display_update: scan counter:%2d data:%02x\n", m_scan_counter, data); + m_display(m_scan_counter, data, 0xff); m_scan_counter = (m_scan_counter + 1) % 16; } diff --git a/src/devices/machine/r10788.h b/src/devices/machine/r10788.h index 452d9e14429..9a94ad65b5c 100644 --- a/src/devices/machine/r10788.h +++ b/src/devices/machine/r10788.h @@ -43,11 +43,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; -private: - static const device_timer_id TIMER_DISPLAY = 0; + TIMER_CALLBACK_MEMBER(display_update); +private: uint8_t m_reg[2][16]; //!< display registers uint8_t m_ktr; //!< transfer keyboard return value uint8_t m_kts; //!< transfer keyboard strobe value diff --git a/src/devices/machine/ripple_counter.cpp b/src/devices/machine/ripple_counter.cpp index 32db0862b93..e8fc5ad544f 100644 --- a/src/devices/machine/ripple_counter.cpp +++ b/src/devices/machine/ripple_counter.cpp @@ -94,7 +94,7 @@ void ripple_counter_device::device_resolve_objects() void ripple_counter_device::device_start() { // initialize timers - m_count_timer = timer_alloc(TIMER_COUNT); + m_count_timer = timer_alloc(FUNC(ripple_counter_device::advance_counter), this); // register internal state save_item(NAME(m_count)); @@ -174,16 +174,10 @@ WRITE_LINE_MEMBER(ripple_counter_device::reset_w) //------------------------------------------------- -// device_timer - called whenever a device timer -// fires +// advance_counter - //------------------------------------------------- -void ripple_counter_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(ripple_counter_device::advance_counter) { - switch (id) - { - case TIMER_COUNT: - set_count((m_count + 1) & m_count_mask); - break; - } + set_count((m_count + 1) & m_count_mask); } diff --git a/src/devices/machine/ripple_counter.h b/src/devices/machine/ripple_counter.h index 6436723d738..dd0ee3adced 100644 --- a/src/devices/machine/ripple_counter.h +++ b/src/devices/machine/ripple_counter.h @@ -43,12 +43,13 @@ protected: virtual void device_resolve_objects() override; virtual void device_start() override; virtual void device_clock_changed() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; // device_rom_interface overrides virtual space_config_vector memory_space_config() const override; virtual void rom_bank_updated() override; + TIMER_CALLBACK_MEMBER(advance_counter); + private: // internal helpers void set_count(u32 count); @@ -58,10 +59,6 @@ private: devcb_write8 m_rom_out_cb; // device timers - enum - { - TIMER_COUNT - }; emu_timer *m_count_timer; // configuration parameters diff --git a/src/devices/machine/rp5c01.cpp b/src/devices/machine/rp5c01.cpp index 50443421ba5..8a59f07e9f8 100644 --- a/src/devices/machine/rp5c01.cpp +++ b/src/devices/machine/rp5c01.cpp @@ -201,10 +201,10 @@ void rp5c01_device::device_start() // allocate timers if (clock() > 0) { - m_clock_timer = timer_alloc(TIMER_CLOCK); + m_clock_timer = timer_alloc(FUNC(rp5c01_device::advance_1hz_clock), this); m_clock_timer->adjust(attotime::from_hz(clock() / 16384), 0, attotime::from_hz(clock() / 16384)); - m_16hz_timer = timer_alloc(TIMER_16HZ); + m_16hz_timer = timer_alloc(FUNC(rp5c01_device::advance_16hz_clock), this); m_16hz_timer->adjust(attotime::from_hz(clock() / 1024), 0, attotime::from_hz(clock() / 1024)); } @@ -227,28 +227,29 @@ void rp5c01_device::device_start() //------------------------------------------------- -// device_timer - handler timer events +// advance_1hz_clock - //------------------------------------------------- -void rp5c01_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(rp5c01_device::advance_1hz_clock) { - switch (id) + if (m_1hz && (m_mode & MODE_TIMER_EN)) { - case TIMER_CLOCK: - if (m_1hz && (m_mode & MODE_TIMER_EN)) - { - advance_seconds(); - } + advance_seconds(); + } - m_1hz = !m_1hz; - set_alarm_line(); - break; + m_1hz = !m_1hz; + set_alarm_line(); +} - case TIMER_16HZ: - m_16hz = !m_16hz; - set_alarm_line(); - break; - } + +//------------------------------------------------- +// advance_16hz_clock - +//------------------------------------------------- + +TIMER_CALLBACK_MEMBER(rp5c01_device::advance_16hz_clock) +{ + m_16hz = !m_16hz; + set_alarm_line(); } diff --git a/src/devices/machine/rp5c01.h b/src/devices/machine/rp5c01.h index 14c44b385a5..0cbcdf4d2a5 100644 --- a/src/devices/machine/rp5c01.h +++ b/src/devices/machine/rp5c01.h @@ -54,7 +54,6 @@ protected: // device-level overrides virtual void device_start() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; // device_rtc_interface overrides virtual bool rtc_feature_leap_year() const override { return true; } @@ -67,15 +66,15 @@ protected: virtual bool nvram_write(util::write_stream &file) override; virtual bool nvram_can_write() override { return m_battery_backed; } + TIMER_CALLBACK_MEMBER(advance_1hz_clock); + TIMER_CALLBACK_MEMBER(advance_16hz_clock); + private: inline void set_alarm_line(); inline int read_counter(int counter); inline void write_counter(int counter, int value); inline void check_alarm(); - static const device_timer_id TIMER_CLOCK = 0; - static const device_timer_id TIMER_16HZ = 1; - devcb_write_line m_out_alarm_cb; bool m_battery_backed; diff --git a/src/devices/machine/rp5c15.cpp b/src/devices/machine/rp5c15.cpp index a0700a3069f..a37b779c6fd 100644 --- a/src/devices/machine/rp5c15.cpp +++ b/src/devices/machine/rp5c15.cpp @@ -207,13 +207,13 @@ void rp5c15_device::device_start() m_out_clkout_cb.resolve_safe(); // allocate timers - m_clock_timer = timer_alloc(TIMER_CLOCK); + m_clock_timer = timer_alloc(FUNC(rp5c15_device::advance_1hz_clock), this); m_clock_timer->adjust(attotime::from_hz(clock() / 16384), 0, attotime::from_hz(clock() / 16384)); - m_16hz_timer = timer_alloc(TIMER_16HZ); + m_16hz_timer = timer_alloc(FUNC(rp5c15_device::advance_16hz_clock), this); m_16hz_timer->adjust(attotime::from_hz(clock() / 1024), 0, attotime::from_hz(clock() / 1024)); - m_clkout_timer = timer_alloc(TIMER_CLKOUT); + m_clkout_timer = timer_alloc(FUNC(rp5c15_device::advance_output_clock), this); memset(m_reg, 0, sizeof(m_reg)); memset(m_ram, 0, sizeof(m_ram)); @@ -239,33 +239,40 @@ void rp5c15_device::device_start() //------------------------------------------------- -// device_timer - handler timer events +// advance_1hz_clock - //------------------------------------------------- -void rp5c15_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(rp5c15_device::advance_1hz_clock) { - switch (id) + if (m_1hz && (m_mode & MODE_TIMER_EN)) { - case TIMER_CLOCK: - if (m_1hz && (m_mode & MODE_TIMER_EN)) - { - advance_seconds(); - } + advance_seconds(); + } - m_1hz = !m_1hz; - set_alarm_line(); - break; + m_1hz = !m_1hz; + set_alarm_line(); +} - case TIMER_16HZ: - m_16hz = !m_16hz; - set_alarm_line(); - break; - case TIMER_CLKOUT: - m_clkout = !m_clkout; - m_out_clkout_cb(m_clkout); - break; - } +//------------------------------------------------- +// advance_16hz_clock - +//------------------------------------------------- + +TIMER_CALLBACK_MEMBER(rp5c15_device::advance_16hz_clock) +{ + m_16hz = !m_16hz; + set_alarm_line(); +} + + +//------------------------------------------------- +// advance_output_clock - +//------------------------------------------------- + +TIMER_CALLBACK_MEMBER(rp5c15_device::advance_output_clock) +{ + m_clkout = !m_clkout; + m_out_clkout_cb(m_clkout); } diff --git a/src/devices/machine/rp5c15.h b/src/devices/machine/rp5c15.h index 7d981a9ec87..15936a02445 100644 --- a/src/devices/machine/rp5c15.h +++ b/src/devices/machine/rp5c15.h @@ -41,22 +41,21 @@ 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_rtc_interface overrides virtual bool rtc_feature_leap_year() const override { return true; } virtual void rtc_clock_updated(int year, int month, int day, int day_of_week, int hour, int minute, int second) override; + TIMER_CALLBACK_MEMBER(advance_1hz_clock); + TIMER_CALLBACK_MEMBER(advance_16hz_clock); + TIMER_CALLBACK_MEMBER(advance_output_clock); + private: inline void set_alarm_line(); inline int read_counter(int counter); inline void write_counter(int counter, int value); inline void check_alarm(); - static const device_timer_id TIMER_CLOCK = 0; - static const device_timer_id TIMER_16HZ = 1; - static const device_timer_id TIMER_CLKOUT = 2; - devcb_write_line m_out_alarm_cb; devcb_write_line m_out_clkout_cb; diff --git a/src/devices/machine/rtc4543.cpp b/src/devices/machine/rtc4543.cpp index 32ae1a7a3dd..773724a4170 100644 --- a/src/devices/machine/rtc4543.cpp +++ b/src/devices/machine/rtc4543.cpp @@ -73,7 +73,7 @@ void rtc4543_device::device_start() m_data_cb.resolve_safe(); // allocate timers - m_clock_timer = timer_alloc(); + m_clock_timer = timer_alloc(FUNC(rtc4543_device::advance_clock), this); m_clock_timer->adjust(attotime::from_hz(clock() / 32768), 0, attotime::from_hz(clock() / 32768)); // state saving @@ -101,10 +101,10 @@ void rtc4543_device::device_reset() //------------------------------------------------- -// device_timer - handler timer events +// advance_clock - //------------------------------------------------- -void rtc4543_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(rtc4543_device::advance_clock) { advance_seconds(); } diff --git a/src/devices/machine/rtc4543.h b/src/devices/machine/rtc4543.h index 0f2d7b689f8..a29cbb9ec30 100644 --- a/src/devices/machine/rtc4543.h +++ b/src/devices/machine/rtc4543.h @@ -44,7 +44,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; @@ -60,6 +59,8 @@ protected: void advance_bit(); void update_effective(); + TIMER_CALLBACK_MEMBER(advance_clock); + devcb_write_line m_data_cb; int m_ce; diff --git a/src/devices/machine/rtc65271.cpp b/src/devices/machine/rtc65271.cpp index 5ddc59ddb5f..dc7aad8d210 100644 --- a/src/devices/machine/rtc65271.cpp +++ b/src/devices/machine/rtc65271.cpp @@ -405,7 +405,7 @@ void rtc65271_device::write(int xramsel, offs_t offset, uint8_t data) { attotime period = attotime::from_hz(SQW_freq_table[data & reg_A_RS]); attotime half_period = period / 2; - attotime elapsed = m_update_timer->elapsed(); + attotime elapsed = m_begin_update_timer->elapsed(); if (half_period > elapsed) m_SQW_timer->adjust(half_period - elapsed); @@ -510,7 +510,7 @@ TIMER_CALLBACK_MEMBER(rtc65271_device::rtc_begin_update_cb) m_regs[reg_A] |= reg_A_UIP; /* schedule end of update cycle */ - machine().scheduler().timer_set(UPDATE_CYCLE_TIME, timer_expired_delegate(FUNC(rtc65271_device::rtc_end_update_cb), this)); + m_end_update_timer->adjust(UPDATE_CYCLE_TIME); } } @@ -682,9 +682,11 @@ rtc65271_device::rtc65271_device(const machine_config &mconfig, const char *tag, //------------------------------------------------- void rtc65271_device::device_start() { - m_update_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(rtc65271_device::rtc_begin_update_cb), this)); - m_update_timer->adjust(attotime::from_seconds(1), 0, attotime::from_seconds(1)); - m_SQW_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(rtc65271_device::rtc_SQW_cb), this)); + m_begin_update_timer = timer_alloc(FUNC(rtc65271_device::rtc_begin_update_cb), this); + m_begin_update_timer->adjust(attotime::from_seconds(1), 0, attotime::from_seconds(1)); + m_end_update_timer = timer_alloc(FUNC(rtc65271_device::rtc_end_update_cb), this); + m_end_update_timer->adjust(attotime::never); + m_SQW_timer = timer_alloc(FUNC(rtc65271_device::rtc_SQW_cb), this); m_interrupt_cb.resolve(); save_item(NAME(m_regs)); diff --git a/src/devices/machine/rtc65271.h b/src/devices/machine/rtc65271.h index 70ea033953e..a3d77bf3fa9 100644 --- a/src/devices/machine/rtc65271.h +++ b/src/devices/machine/rtc65271.h @@ -55,7 +55,8 @@ private: uint8_t m_cur_xram_page; /* update timer: called every second */ - emu_timer *m_update_timer; + emu_timer *m_begin_update_timer = nullptr; + emu_timer *m_end_update_timer = nullptr; /* SQW timer: called every periodic clock half-period */ emu_timer *m_SQW_timer; diff --git a/src/devices/machine/rtc9701.cpp b/src/devices/machine/rtc9701.cpp index a16ce296dde..3dab4bd1835 100644 --- a/src/devices/machine/rtc9701.cpp +++ b/src/devices/machine/rtc9701.cpp @@ -92,7 +92,7 @@ void rtc9701_device::device_validity_check(validity_checker &valid) const void rtc9701_device::device_start() { /* let's call the timer callback every second */ - m_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(rtc9701_device::timer_callback), this)); + m_timer = timer_alloc(FUNC(rtc9701_device::timer_callback), this); m_timer->adjust(attotime::from_hz(clock() / XTAL(32'768)), 0, attotime::from_hz(clock() / XTAL(32'768))); system_time systime; diff --git a/src/devices/machine/s3520cf.cpp b/src/devices/machine/s3520cf.cpp index 6bc9bbf64eb..86676ca3d2b 100644 --- a/src/devices/machine/s3520cf.cpp +++ b/src/devices/machine/s3520cf.cpp @@ -105,7 +105,7 @@ void s3520cf_device::device_validity_check(validity_checker &valid) const void s3520cf_device::device_start() { /* let's call the timer callback every second for now */ - m_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(s3520cf_device::timer_callback), this)); + m_timer = timer_alloc(FUNC(s3520cf_device::timer_callback), this); m_timer->adjust(attotime::from_hz(clock() / XTAL(32'768)), 0, attotime::from_hz(clock() / XTAL(32'768))); system_time systime; diff --git a/src/devices/machine/s3c24xx.hxx b/src/devices/machine/s3c24xx.hxx index acddd0ad7e0..b5ad9be6312 100644 --- a/src/devices/machine/s3c24xx.hxx +++ b/src/devices/machine/s3c24xx.hxx @@ -3272,15 +3272,15 @@ void S3C24_CLASS_NAME::s3c24xx_device_start() m_nand_data_w_cb.resolve(); #endif for (int i = 0; i < 5; i++) - m_pwm.timer[i] = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(S3C24_CLASS_NAME::s3c24xx_pwm_timer_exp), this)); + m_pwm.timer[i] = timer_alloc(FUNC(S3C24_CLASS_NAME::s3c24xx_pwm_timer_exp), this); for (auto & elem : m_dma) - elem.timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(S3C24_CLASS_NAME::s3c24xx_dma_timer_exp), this)); - m_iic.timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(S3C24_CLASS_NAME::s3c24xx_iic_timer_exp), this)); - m_iis.timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(S3C24_CLASS_NAME::s3c24xx_iis_timer_exp), this)); - m_lcd.timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(S3C24_CLASS_NAME::s3c24xx_lcd_timer_exp), this)); - m_rtc.timer_tick_count = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(S3C24_CLASS_NAME::s3c24xx_rtc_timer_tick_count_exp), this)); - m_rtc.timer_update = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(S3C24_CLASS_NAME::s3c24xx_rtc_timer_update_exp), this)); - m_wdt.timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(S3C24_CLASS_NAME::s3c24xx_wdt_timer_exp), this)); + elem.timer = timer_alloc(FUNC(S3C24_CLASS_NAME::s3c24xx_dma_timer_exp), this); + m_iic.timer = timer_alloc(FUNC(S3C24_CLASS_NAME::s3c24xx_iic_timer_exp), this); + m_iis.timer = timer_alloc(FUNC(S3C24_CLASS_NAME::s3c24xx_iis_timer_exp), this); + m_lcd.timer = timer_alloc(FUNC(S3C24_CLASS_NAME::s3c24xx_lcd_timer_exp), this); + m_rtc.timer_tick_count = timer_alloc(FUNC(S3C24_CLASS_NAME::s3c24xx_rtc_timer_tick_count_exp), this); + m_rtc.timer_update = timer_alloc(FUNC(S3C24_CLASS_NAME::s3c24xx_rtc_timer_update_exp), this); + m_wdt.timer = timer_alloc(FUNC(S3C24_CLASS_NAME::s3c24xx_wdt_timer_exp), this); #if defined(DEVICE_S3C2410) || defined(DEVICE_S3C2440) int om0 = iface_core_pin_r(S3C24XX_CORE_PIN_OM0); diff --git a/src/devices/machine/s3c44b0.cpp b/src/devices/machine/s3c44b0.cpp index 746c6ba0e32..f3ea869bdd5 100644 --- a/src/devices/machine/s3c44b0.cpp +++ b/src/devices/machine/s3c44b0.cpp @@ -266,17 +266,17 @@ void s3c44b0_device::device_start() m_cpu->space(AS_PROGRAM).cache(m_cache); - for (int i = 0; i < 6; i++) m_pwm.timer[i] = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(s3c44b0_device::pwm_timer_exp),this)); - for (auto & elem : m_uart) elem.timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(s3c44b0_device::uart_timer_exp),this)); - for (auto & elem : m_zdma) elem.timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(s3c44b0_device::zdma_timer_exp),this)); - for (auto & elem : m_bdma) elem.timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(s3c44b0_device::bdma_timer_exp),this)); - - m_lcd.timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(s3c44b0_device::lcd_timer_exp),this)); - m_wdt.timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(s3c44b0_device::wdt_timer_exp),this)); - m_sio.timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(s3c44b0_device::sio_timer_exp),this)); - m_adc.timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(s3c44b0_device::adc_timer_exp),this)); - m_iic.timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(s3c44b0_device::iic_timer_exp),this)); - m_iis.timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(s3c44b0_device::iis_timer_exp),this)); + for (int i = 0; i < 6; i++) m_pwm.timer[i] = timer_alloc(FUNC(s3c44b0_device::pwm_timer_exp), this); + for (auto & elem : m_uart) elem.timer = timer_alloc(FUNC(s3c44b0_device::uart_timer_exp), this); + for (auto & elem : m_zdma) elem.timer = timer_alloc(FUNC(s3c44b0_device::zdma_timer_exp), this); + for (auto & elem : m_bdma) elem.timer = timer_alloc(FUNC(s3c44b0_device::bdma_timer_exp), this); + + m_lcd.timer = timer_alloc(FUNC(s3c44b0_device::lcd_timer_exp), this); + m_wdt.timer = timer_alloc(FUNC(s3c44b0_device::wdt_timer_exp), this); + m_sio.timer = timer_alloc(FUNC(s3c44b0_device::sio_timer_exp), this); + m_adc.timer = timer_alloc(FUNC(s3c44b0_device::adc_timer_exp), this); + m_iic.timer = timer_alloc(FUNC(s3c44b0_device::iic_timer_exp), this); + m_iis.timer = timer_alloc(FUNC(s3c44b0_device::iis_timer_exp), this); video_start(); diff --git a/src/devices/machine/s_smp.cpp b/src/devices/machine/s_smp.cpp index 277d40f3533..d6693943c1c 100644 --- a/src/devices/machine/s_smp.cpp +++ b/src/devices/machine/s_smp.cpp @@ -89,7 +89,7 @@ void s_smp_device::device_start() space(AS_DATA).specific(m_data); space(AS_DATA).cache(m_dcache); - m_tick_timer = timer_alloc(TIMER_TICK_ID); + m_tick_timer = timer_alloc(FUNC(s_smp_device::update_timers), this); save_item(NAME(m_timer_enabled)); save_item(NAME(m_subcounter)); @@ -179,11 +179,8 @@ inline void s_smp_device::update_timer_tick(u8 which) } } -void s_smp_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(s_smp_device::update_timers) { - if (id != TIMER_TICK_ID) - throw emu_fatalerror("Unknown id in s_smp_device::device_timer"); - for (int ch = 0; ch < 3; ch++) update_timer_tick(ch); } diff --git a/src/devices/machine/s_smp.h b/src/devices/machine/s_smp.h index 2654db91776..45f83755507 100644 --- a/src/devices/machine/s_smp.h +++ b/src/devices/machine/s_smp.h @@ -31,7 +31,8 @@ protected: virtual void device_start() override; virtual void device_reset() override; virtual void device_clock_changed() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; + + TIMER_CALLBACK_MEMBER(update_timers); // device_memory_interface configuration virtual space_config_vector memory_space_config() const override; @@ -56,10 +57,6 @@ private: u8 io_r(offs_t offset); void io_w(offs_t offset, u8 data); - enum - { - TIMER_TICK_ID = 1 - }; /* timers */ emu_timer *m_tick_timer; bool m_timer_enabled[3]; diff --git a/src/devices/machine/sa1110.cpp b/src/devices/machine/sa1110.cpp index 11afedeef51..5bcc62ba456 100644 --- a/src/devices/machine/sa1110.cpp +++ b/src/devices/machine/sa1110.cpp @@ -2314,12 +2314,12 @@ void sa1110_periphs_device::device_start() save_item(NAME(m_icp_regs.uart.rx_fifo_read_idx)); save_item(NAME(m_icp_regs.uart.rx_fifo_write_idx)); save_item(NAME(m_icp_regs.uart.rx_fifo_count)); - m_icp_regs.uart_rx_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(sa1110_periphs_device::icp_rx_callback), this)); + m_icp_regs.uart_rx_timer = timer_alloc(FUNC(sa1110_periphs_device::icp_rx_callback), this); save_item(NAME(m_icp_regs.uart.tx_fifo)); save_item(NAME(m_icp_regs.uart.tx_fifo_read_idx)); save_item(NAME(m_icp_regs.uart.tx_fifo_write_idx)); save_item(NAME(m_icp_regs.uart.tx_fifo_count)); - m_icp_regs.uart_tx_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(sa1110_periphs_device::icp_tx_callback), this)); + m_icp_regs.uart_tx_timer = timer_alloc(FUNC(sa1110_periphs_device::icp_tx_callback), this); save_item(NAME(m_icp_regs.uart.rx_break_interlock)); save_item(NAME(m_icp_regs.utcr4)); @@ -2331,12 +2331,12 @@ void sa1110_periphs_device::device_start() save_item(NAME(m_icp_regs.hssp.rx_fifo_read_idx)); save_item(NAME(m_icp_regs.hssp.rx_fifo_write_idx)); save_item(NAME(m_icp_regs.hssp.rx_fifo_count)); - m_icp_regs.hssp.rx_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(sa1110_periphs_device::hssp_rx_callback), this)); + m_icp_regs.hssp.rx_timer = timer_alloc(FUNC(sa1110_periphs_device::hssp_rx_callback), this); save_item(NAME(m_icp_regs.hssp.tx_fifo)); save_item(NAME(m_icp_regs.hssp.tx_fifo_read_idx)); save_item(NAME(m_icp_regs.hssp.tx_fifo_write_idx)); save_item(NAME(m_icp_regs.hssp.tx_fifo_count)); - m_icp_regs.hssp.tx_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(sa1110_periphs_device::hssp_tx_callback), this)); + m_icp_regs.hssp.tx_timer = timer_alloc(FUNC(sa1110_periphs_device::hssp_tx_callback), this); save_item(NAME(m_uart_regs.utcr)); save_item(NAME(m_uart_regs.utsr0)); @@ -2363,7 +2363,7 @@ void sa1110_periphs_device::device_start() save_item(NAME(m_mcp_regs.audio_tx_fifo_read_idx)); save_item(NAME(m_mcp_regs.audio_tx_fifo_write_idx)); save_item(NAME(m_mcp_regs.audio_tx_fifo_count)); - m_mcp_regs.audio_tx_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(sa1110_periphs_device::mcp_audio_tx_callback), this)); + m_mcp_regs.audio_tx_timer = timer_alloc(FUNC(sa1110_periphs_device::mcp_audio_tx_callback), this); save_item(NAME(m_mcp_regs.telecom_rx_fifo)); save_item(NAME(m_mcp_regs.telecom_rx_fifo_read_idx)); save_item(NAME(m_mcp_regs.telecom_rx_fifo_write_idx)); @@ -2372,7 +2372,7 @@ void sa1110_periphs_device::device_start() save_item(NAME(m_mcp_regs.telecom_tx_fifo_read_idx)); save_item(NAME(m_mcp_regs.telecom_tx_fifo_write_idx)); save_item(NAME(m_mcp_regs.telecom_tx_fifo_count)); - m_mcp_regs.telecom_tx_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(sa1110_periphs_device::mcp_telecom_tx_callback), this)); + m_mcp_regs.telecom_tx_timer = timer_alloc(FUNC(sa1110_periphs_device::mcp_telecom_tx_callback), this); save_item(NAME(m_ssp_regs.sscr0)); save_item(NAME(m_ssp_regs.sscr1)); @@ -2381,12 +2381,12 @@ void sa1110_periphs_device::device_start() save_item(NAME(m_ssp_regs.rx_fifo_read_idx)); save_item(NAME(m_ssp_regs.rx_fifo_write_idx)); save_item(NAME(m_ssp_regs.rx_fifo_count)); - m_ssp_regs.rx_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(sa1110_periphs_device::ssp_rx_callback), this)); + m_ssp_regs.rx_timer = timer_alloc(FUNC(sa1110_periphs_device::ssp_rx_callback), this); save_item(NAME(m_ssp_regs.tx_fifo)); save_item(NAME(m_ssp_regs.tx_fifo_read_idx)); save_item(NAME(m_ssp_regs.tx_fifo_write_idx)); save_item(NAME(m_ssp_regs.tx_fifo_count)); - m_ssp_regs.tx_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(sa1110_periphs_device::ssp_tx_callback), this)); + m_ssp_regs.tx_timer = timer_alloc(FUNC(sa1110_periphs_device::ssp_tx_callback), this); save_item(NAME(m_ostmr_regs.osmr)); save_item(NAME(m_ostmr_regs.oscr)); @@ -2395,14 +2395,14 @@ void sa1110_periphs_device::device_start() save_item(NAME(m_ostmr_regs.oier)); for (int i = 0; i < 4; i++) { - m_ostmr_regs.timer[i] = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(sa1110_periphs_device::ostimer_tick_cb), this)); + m_ostmr_regs.timer[i] = timer_alloc(FUNC(sa1110_periphs_device::ostimer_tick_cb), this); } save_item(NAME(m_rtc_regs.rtar)); save_item(NAME(m_rtc_regs.rcnr)); save_item(NAME(m_rtc_regs.rttr)); save_item(NAME(m_rtc_regs.rtsr)); - m_rtc_regs.tick_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(sa1110_periphs_device::rtc_tick_cb), this)); + m_rtc_regs.tick_timer = timer_alloc(FUNC(sa1110_periphs_device::rtc_tick_cb), this); save_item(NAME(m_power_regs.pmcr)); save_item(NAME(m_power_regs.pssr)); diff --git a/src/devices/machine/sa1111.cpp b/src/devices/machine/sa1111.cpp index 89ebf0a1784..3a2dd300f78 100644 --- a/src/devices/machine/sa1111.cpp +++ b/src/devices/machine/sa1111.cpp @@ -2080,13 +2080,13 @@ void sa1111_device::device_start() save_item(NAME(m_card_regs.pcssr)); save_item(NAME(m_card_regs.pcsr)); - m_audio_regs.rx_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(sa1111_device::audio_rx_callback), this)); - m_audio_regs.rx_dma_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(sa1111_device::audio_rx_dma_callback), this)); - m_audio_regs.tx_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(sa1111_device::audio_tx_callback), this)); - m_audio_regs.tx_dma_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(sa1111_device::audio_tx_dma_callback), this)); + m_audio_regs.rx_timer = timer_alloc(FUNC(sa1111_device::audio_rx_callback), this); + m_audio_regs.rx_dma_timer = timer_alloc(FUNC(sa1111_device::audio_rx_dma_callback), this); + m_audio_regs.tx_timer = timer_alloc(FUNC(sa1111_device::audio_tx_callback), this); + m_audio_regs.tx_dma_timer = timer_alloc(FUNC(sa1111_device::audio_tx_dma_callback), this); - m_ssp_regs.rx_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(sa1111_device::ssp_rx_callback), this)); - m_ssp_regs.tx_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(sa1111_device::ssp_tx_callback), this)); + m_ssp_regs.rx_timer = timer_alloc(FUNC(sa1111_device::ssp_rx_callback), this); + m_ssp_regs.tx_timer = timer_alloc(FUNC(sa1111_device::ssp_tx_callback), this); m_irq_out.resolve_safe(); m_gpio_out.resolve_all_safe(); diff --git a/src/devices/machine/saa1043.cpp b/src/devices/machine/saa1043.cpp index 1c310643dcc..053945c9a7e 100644 --- a/src/devices/machine/saa1043.cpp +++ b/src/devices/machine/saa1043.cpp @@ -24,7 +24,6 @@ saa1043_device::saa1043_device(const machine_config &mconfig, const char *tag, d , m_outputs(*this) , m_type(PAL) { - std::fill(std::begin(m_outputs_hooked), std::end(m_outputs_hooked), false); } void saa1043_device::device_start() @@ -32,50 +31,26 @@ void saa1043_device::device_start() m_h = attotime::from_ticks(320, clock() * 2); m_line_count = s_line_counts[m_type]; - // resolve callbacks - for (uint32_t i = 0; i < OUT_COUNT; i++) - { - m_outputs[i].resolve_safe(); - if (m_outputs_hooked[i]) - { - m_timers[i] = timer_alloc(i); - switch(i) - { - case V2: - m_timers[V2]->adjust(m_h * 6, 1); - break; - default: - // Not yet implemented - break; - } - } - } + m_outputs.resolve_all_safe(); + + m_timers[OUT_V2] = timer_alloc(FUNC(saa1043_device::toggle_v2), this); + m_timers[OUT_V2]->adjust(m_h * 6, 1); } void saa1043_device::device_reset() { - // Clear any existing clock states for (uint32_t i = 0; i < OUT_COUNT; i++) { m_outputs[i](CLEAR_LINE); } - m_outputs[V2](ASSERT_LINE); + m_outputs[OUT_V2](ASSERT_LINE); } -void saa1043_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(saa1043_device::toggle_v2) { - switch (id) - { - case V2: - m_outputs[V2](1 - param); - if (param) - m_timers[V2]->adjust(m_h * (m_line_count - 9), 0); - else - m_timers[V2]->adjust(m_h * 9, 1); - break; - - default: - // Not yet implemented - break; - } + m_outputs[OUT_V2](1 - param); + if (param) + m_timers[OUT_V2]->adjust(m_h * (m_line_count - 9), 0); + else + m_timers[OUT_V2]->adjust(m_h * 9, 1); } diff --git a/src/devices/machine/saa1043.h b/src/devices/machine/saa1043.h index d6b7271dce7..3a5851d0f42 100644 --- a/src/devices/machine/saa1043.h +++ b/src/devices/machine/saa1043.h @@ -46,24 +46,24 @@ public: enum outputs : uint32_t { - BC, - FH2, - FH3, - FH80, - PH, - NS, - RI, - WMP, - RR, - V1, - V2, - CLP, - DL, - H1, - H2, - CB, - CS, - ID, + OUT_BC, + OUT_FH2, + OUT_FH3, + OUT_FH80, + OUT_PH, + OUT_NS, + OUT_RI, + OUT_WMP, + OUT_RR, + OUT_V1, + OUT_V2, + OUT_CLP, + OUT_DL, + OUT_H1, + OUT_H2, + OUT_CB, + OUT_CS, + OUT_ID, OUT_COUNT }; @@ -78,34 +78,34 @@ public: void set_type(signal_type type) { m_type = type; } - auto bc_callback() { m_outputs_hooked[BC] = true; return m_outputs[BC].bind(); } - auto fh2_callback() { m_outputs_hooked[FH2] = true; return m_outputs[FH2].bind(); } - auto fh3_callback() { m_outputs_hooked[FH3] = true; return m_outputs[FH3].bind(); } - auto fh80_callback() { m_outputs_hooked[FH80] = true; return m_outputs[FH80].bind(); } - auto ph_callback() { m_outputs_hooked[PH] = true; return m_outputs[PH].bind(); } - auto ns_callback() { m_outputs_hooked[NS] = true; return m_outputs[NS].bind(); } - auto ri_callback() { m_outputs_hooked[RI] = true; return m_outputs[RI].bind(); } - auto wmp_callback() { m_outputs_hooked[WMP] = true; return m_outputs[WMP].bind(); } - auto rr_callback() { m_outputs_hooked[RR] = true; return m_outputs[RR].bind(); } - auto v1_callback() { m_outputs_hooked[V1] = true; return m_outputs[V1].bind(); } - auto v2_callback() { m_outputs_hooked[V2] = true; return m_outputs[V2].bind(); } - auto clp_callback() { m_outputs_hooked[CLP] = true; return m_outputs[CLP].bind(); } - auto dl_callback() { m_outputs_hooked[DL] = true; return m_outputs[DL].bind(); } - auto h1_callback() { m_outputs_hooked[H1] = true; return m_outputs[H1].bind(); } - auto h2_callback() { m_outputs_hooked[H2] = true; return m_outputs[H2].bind(); } - auto cb_callback() { m_outputs_hooked[CB] = true; return m_outputs[CB].bind(); } - auto cs_callback() { m_outputs_hooked[CS] = true; return m_outputs[CS].bind(); } - auto id_callback() { m_outputs_hooked[ID] = true; return m_outputs[ID].bind(); } + auto bc_callback() { return m_outputs[OUT_BC].bind(); } + auto fh2_callback() { return m_outputs[OUT_FH2].bind(); } + auto fh3_callback() { return m_outputs[OUT_FH3].bind(); } + auto fh80_callback() { return m_outputs[OUT_FH80].bind(); } + auto ph_callback() { return m_outputs[OUT_PH].bind(); } + auto ns_callback() { return m_outputs[OUT_NS].bind(); } + auto ri_callback() { return m_outputs[OUT_RI].bind(); } + auto wmp_callback() { return m_outputs[OUT_WMP].bind(); } + auto rr_callback() { return m_outputs[OUT_RR].bind(); } + auto v1_callback() { return m_outputs[OUT_V1].bind(); } + auto v2_callback() { return m_outputs[OUT_V2].bind(); } + auto clp_callback() { return m_outputs[OUT_CLP].bind(); } + auto dl_callback() { return m_outputs[OUT_DL].bind(); } + auto h1_callback() { return m_outputs[OUT_H1].bind(); } + auto h2_callback() { return m_outputs[OUT_H2].bind(); } + auto cb_callback() { return m_outputs[OUT_CB].bind(); } + auto cs_callback() { return m_outputs[OUT_CS].bind(); } + auto id_callback() { return m_outputs[OUT_ID].bind(); } 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(toggle_v2); private: devcb_write_line::array<OUT_COUNT> m_outputs; - bool m_outputs_hooked[OUT_COUNT]; emu_timer *m_timers[OUT_COUNT]; signal_type m_type; diff --git a/src/devices/machine/scc2698b.cpp b/src/devices/machine/scc2698b.cpp index db7ed52d4aa..892c37c24bf 100644 --- a/src/devices/machine/scc2698b.cpp +++ b/src/devices/machine/scc2698b.cpp @@ -364,17 +364,10 @@ scc2698b_device::scc2698b_device(const machine_config &mconfig, const char *tag, write_mpp2(*this), write_mpo(*this) { - } -void scc2698b_device::device_timer(emu_timer &timer, device_timer_id id, int param) -{ - -} - - void scc2698b_device::device_start() { write_intr_A.resolve_safe(); @@ -398,7 +391,6 @@ void scc2698b_device::device_start() void scc2698b_device::device_reset() { - } diff --git a/src/devices/machine/scc2698b.h b/src/devices/machine/scc2698b.h index 8b2921e3224..d883b45d0b9 100644 --- a/src/devices/machine/scc2698b.h +++ b/src/devices/machine/scc2698b.h @@ -114,7 +114,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; virtual void device_add_mconfig(machine_config &config) override; devcb_write_line write_intr_A, write_intr_B, write_intr_C, write_intr_D; diff --git a/src/devices/machine/scc68070.cpp b/src/devices/machine/scc68070.cpp index 9bde1e65982..63c7dc01dce 100644 --- a/src/devices/machine/scc68070.cpp +++ b/src/devices/machine/scc68070.cpp @@ -183,13 +183,13 @@ void scc68070_device::device_start() save_item(STRUCT_MEMBER(m_mmu.desc, segment)); save_item(STRUCT_MEMBER(m_mmu.desc, base)); - m_timers.timer0_timer = timer_alloc(TIMER_TMR0); + m_timers.timer0_timer = timer_alloc(FUNC(scc68070_device::timer0_callback), this); m_timers.timer0_timer->adjust(attotime::never); - m_uart.rx_timer = timer_alloc(TIMER_UART_RX); + m_uart.rx_timer = timer_alloc(FUNC(scc68070_device::rx_callback), this); m_uart.rx_timer->adjust(attotime::never); - m_uart.tx_timer = timer_alloc(TIMER_UART_TX); + m_uart.tx_timer = timer_alloc(FUNC(scc68070_device::tx_callback), this); m_uart.tx_timer->adjust(attotime::never); } @@ -263,20 +263,6 @@ void scc68070_device::device_reset() m_timers.timer0_timer->adjust(attotime::never); } -//------------------------------------------------- -// device_timer - device-specific timer callback -//------------------------------------------------- - -void scc68070_device::device_timer(emu_timer &timer, device_timer_id id, int param) -{ - if (id == TIMER_TMR0) - timer0_callback(); - else if (id == TIMER_UART_RX) - rx_callback(); - else if (id == TIMER_UART_TX) - tx_callback(); -} - void scc68070_device::m68k_reset_peripherals() { m_lir = 0; @@ -469,7 +455,7 @@ void scc68070_device::set_timer_callback(int channel) } } -void scc68070_device::timer0_callback() +TIMER_CALLBACK_MEMBER(scc68070_device::timer0_callback) { m_timers.timer0 = m_timers.reload_register; m_timers.timer_status_register |= TSR_OV0; @@ -500,7 +486,7 @@ void scc68070_device::uart_tx(uint8_t data) m_uart.status_register &= ~USR_TXEMT; } -void scc68070_device::rx_callback() +TIMER_CALLBACK_MEMBER(scc68070_device::rx_callback) { if ((m_uart.command_register & 3) == 1) { @@ -535,7 +521,7 @@ void scc68070_device::rx_callback() } } -void scc68070_device::tx_callback() +TIMER_CALLBACK_MEMBER(scc68070_device::tx_callback) { if (((m_uart.command_register >> 2) & 3) == 1) { diff --git a/src/devices/machine/scc68070.h b/src/devices/machine/scc68070.h index 77e46e9d45f..5fe621abd64 100644 --- a/src/devices/machine/scc68070.h +++ b/src/devices/machine/scc68070.h @@ -149,14 +149,14 @@ public: DECLARE_WRITE_LINE_MEMBER(int1_w); DECLARE_WRITE_LINE_MEMBER(int2_w); + TIMER_CALLBACK_MEMBER(timer0_callback); + TIMER_CALLBACK_MEMBER(rx_callback); + TIMER_CALLBACK_MEMBER(tx_callback); + // external callbacks void uart_rx(uint8_t data); void uart_ctsn(int state); - void timer0_callback(); - void rx_callback(); - void tx_callback(); - // register structures struct i2c_regs_t { @@ -264,7 +264,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; // device_execute_interface overrides virtual u64 execute_clocks_to_cycles(u64 clocks) const noexcept override { return (clocks + 2 - 1) / 2; } @@ -277,10 +276,6 @@ private: void internal_map(address_map &map); void cpu_space_map(address_map &map); - static constexpr device_timer_id TIMER_TMR0 = 0; - static constexpr device_timer_id TIMER_UART_RX = 1; - static constexpr device_timer_id TIMER_UART_TX = 2; - void update_ipl(); uint8_t iack_r(offs_t offset); diff --git a/src/devices/machine/scn_pci.cpp b/src/devices/machine/scn_pci.cpp index 73ef2590e66..43d450c4738 100644 --- a/src/devices/machine/scn_pci.cpp +++ b/src/devices/machine/scn_pci.cpp @@ -303,7 +303,7 @@ void scn2641_device::device_resolve_objects() void scn_pci_device::device_start() { // Create timer for baud rate generator - m_brg_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(scn_pci_device::brg_tick), this)); + m_brg_timer = timer_alloc(FUNC(scn_pci_device::brg_tick), this); // Save state save_item(NAME(m_rhr)); diff --git a/src/devices/machine/scnxx562.cpp b/src/devices/machine/scnxx562.cpp index 1b936cc85e7..4f2da74c258 100644 --- a/src/devices/machine/scnxx562.cpp +++ b/src/devices/machine/scnxx562.cpp @@ -618,9 +618,9 @@ void duscc_channel::device_start() m_cid = (m_uart->m_variant & duscc_device::SET_CMOS) ? 0x7f : 0xff; // TODO: support CMOS rev A = 0xbf // Timers - duscc_timer = timer_alloc(TIMER_ID); - rtxc_timer = timer_alloc(TIMER_ID_RTXC); - trxc_timer = timer_alloc(TIMER_ID_TRXC); + duscc_timer = timer_alloc(FUNC(duscc_channel::check_zero_detect), this); + rtxc_timer = timer_alloc(FUNC(duscc_channel::rtxc_tick), this); + trxc_timer = timer_alloc(FUNC(duscc_channel::trxc_tick), this); // state saving save_item(NAME(m_cmr1)); @@ -745,95 +745,90 @@ void duscc_channel::device_reset() m_a7 = 0; } -void duscc_channel::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(duscc_channel::check_zero_detect) { - switch(id) + if (m_ct-- == 0) // Zero detect { - case TIMER_ID: - if (m_ct-- == 0) // Zero detect + m_ictsr |= REG_ICTSR_ZERO_DET; // set zero detection bit + + // Generate interrupt? + if ( ( (m_ctcr & REG_CTCR_ZERO_DET_INT) == REG_CTCR_ZERO_DET_INT ) && + ( (m_uart->m_icr & (m_index == duscc_device::CHANNEL_A ? duscc_device::REG_ICR_CHA : duscc_device::REG_ICR_CHB) ) != 0) ) { - m_ictsr |= REG_ICTSR_ZERO_DET; // set zero detection bit + LOG("Zero Detect Interrupt pending\n"); + m_uart->trigger_interrupt(m_index, INT_EXTCTSTAT); + } - // Generate interrupt? - if ( ( (m_ctcr & REG_CTCR_ZERO_DET_INT) == REG_CTCR_ZERO_DET_INT ) && - ( (m_uart->m_icr & (m_index == duscc_device::CHANNEL_A ? duscc_device::REG_ICR_CHA : duscc_device::REG_ICR_CHB) ) != 0) ) - { - LOG("Zero Detect Interrupt pending\n"); - m_uart->trigger_interrupt(m_index, INT_EXTCTSTAT); - } + // Preload or rollover? + if (( m_ctcr & REG_CTCR_ZERO_DET_CTL) == 0) + { + m_ct = m_ctpr; + } + else + { + m_ct = 0xffff; + } - // Preload or rollover? - if (( m_ctcr & REG_CTCR_ZERO_DET_CTL) == 0) + // Is Counter/Timer output on the RTxC pin? + if (( m_pcr & REG_PCR_RTXC_MASK) == REG_PCR_RTXC_CNTR_OUT) + { + if ((m_ctcr & REG_CTCR_TIM_OC) == 0) // Toggle? { - m_ct = m_ctpr; + m_rtxc = (~m_rtxc) & 1; } - else + else // Pulse! { - m_ct = 0xffff; + m_rtxc = 1; + rtxc_timer->adjust(attotime::from_hz(clock()), 0, attotime::from_hz(clock())); } + if (m_index == duscc_device::CHANNEL_A) + m_uart->m_out_rtxca_cb(m_rtxc); + else + m_uart->m_out_rtxcb_cb(m_rtxc); + } - // Is Counter/Timer output on the RTxC pin? - if (( m_pcr & REG_PCR_RTXC_MASK) == REG_PCR_RTXC_CNTR_OUT) + // Is Counter/Timer output on the TRXC pin? + if (( m_pcr & REG_PCR_TRXC_MASK) == REG_PCR_TRXC_CNTR_OUT) + { + if ((m_ctcr & REG_CTCR_TIM_OC) == 0) // Toggle? { - if ((m_ctcr & REG_CTCR_TIM_OC) == 0) // Toggle? - { - m_rtxc = (~m_rtxc) & 1; - } - else // Pulse! - { - m_rtxc = 1; - rtxc_timer->adjust(attotime::from_hz(clock()), TIMER_ID_RTXC, attotime::from_hz(clock())); - } - if (m_index == duscc_device::CHANNEL_A) - m_uart->m_out_rtxca_cb(m_rtxc); - else - m_uart->m_out_rtxcb_cb(m_rtxc); + m_trxc = (~m_trxc) & 1; } - - // Is Counter/Timer output on the TRXC pin? - if (( m_pcr & REG_PCR_TRXC_MASK) == REG_PCR_TRXC_CNTR_OUT) + else // Pulse! { - if ((m_ctcr & REG_CTCR_TIM_OC) == 0) // Toggle? - { - m_trxc = (~m_trxc) & 1; - } - else // Pulse! - { - m_trxc = 1; - trxc_timer->adjust(attotime::from_hz(clock()), TIMER_ID_TRXC, attotime::from_hz(clock())); - } - if (m_index == duscc_device::CHANNEL_A) - m_uart->m_out_trxca_cb(m_trxc); - else - m_uart->m_out_trxcb_cb(m_trxc); + m_trxc = 1; + trxc_timer->adjust(attotime::from_hz(clock()), 0, attotime::from_hz(clock())); } + if (m_index == duscc_device::CHANNEL_A) + m_uart->m_out_trxca_cb(m_trxc); + else + m_uart->m_out_trxcb_cb(m_trxc); } - else - { // clear zero detection bit - m_ictsr &= ~REG_ICTSR_ZERO_DET; - } - break; - case TIMER_ID_RTXC: // Terminate zero detection pulse - m_rtxc = 0; - rtxc_timer->adjust(attotime::never); - if (m_index == duscc_device::CHANNEL_A) - m_uart->m_out_rtxca_cb(m_rtxc); - else - m_uart->m_out_rtxcb_cb(m_rtxc); - break; - case TIMER_ID_TRXC: // Terminate zero detection pulse - m_trxc = 0; - trxc_timer->adjust(attotime::never); - if (m_index == duscc_device::CHANNEL_A) - m_uart->m_out_trxca_cb(m_trxc); - else - m_uart->m_out_trxcb_cb(m_trxc); - break; - default: - LOGR("Unhandled Timer ID %d\n", id); - break; } - // LOG("%s %d\n", FUNCNAME, id); + else + { // clear zero detection bit + m_ictsr &= ~REG_ICTSR_ZERO_DET; + } +} + +TIMER_CALLBACK_MEMBER(duscc_channel::rtxc_tick) +{ + m_rtxc = 0; + rtxc_timer->adjust(attotime::never); + if (m_index == duscc_device::CHANNEL_A) + m_uart->m_out_rtxca_cb(m_rtxc); + else + m_uart->m_out_rtxcb_cb(m_rtxc); +} + +TIMER_CALLBACK_MEMBER(duscc_channel::trxc_tick) +{ + m_trxc = 0; + trxc_timer->adjust(attotime::never); + if (m_index == duscc_device::CHANNEL_A) + m_uart->m_out_trxca_cb(m_trxc); + else + m_uart->m_out_trxcb_cb(m_trxc); } /* The DUSCC 16 bit Timer @@ -2037,7 +2032,7 @@ void duscc_channel::do_dusccreg_ccr_w(uint8_t data) /* Start. Starts the counteritimer and prescaler. */ case REG_CCR_START_TIMER: LOG("- Start Counter/Timer\n"); rate = 100; // TODO: calculate correct rate - duscc_timer->adjust(attotime::from_hz(rate), TIMER_ID_RTXC, attotime::from_hz(rate)); + duscc_timer->adjust(attotime::from_hz(rate), 0, attotime::from_hz(rate)); break; /* Stop. Stops the counter/timer and prescaler. Since the command may be asynchronous with the selected clock source, diff --git a/src/devices/machine/scnxx562.h b/src/devices/machine/scnxx562.h index 9df50f0d16e..c9ac458b44c 100644 --- a/src/devices/machine/scnxx562.h +++ b/src/devices/machine/scnxx562.h @@ -152,7 +152,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_serial_interface overrides virtual void tra_callback() override; @@ -160,6 +159,10 @@ protected: virtual void rcv_callback() override; virtual void rcv_complete() override; + TIMER_CALLBACK_MEMBER(check_zero_detect); + TIMER_CALLBACK_MEMBER(rtxc_tick); + TIMER_CALLBACK_MEMBER(trxc_tick); + int m_rxc; int m_txc; int m_tra; @@ -435,13 +438,6 @@ protected: REG_CTCR_TIM_OC = 0x20, }; - enum - { - TIMER_ID, - TIMER_ID_RTXC, - TIMER_ID_TRXC - }; - uint16_t m_brg_rx_rate; uint16_t m_brg_tx_rate; uint16_t m_brg_const; diff --git a/src/devices/machine/sega_scu.cpp b/src/devices/machine/sega_scu.cpp index 7b049c7425f..c2e7191d7cb 100644 --- a/src/devices/machine/sega_scu.cpp +++ b/src/devices/machine/sega_scu.cpp @@ -235,9 +235,9 @@ void sega_scu_device::device_start() m_hostspace = &m_hostcpu->space(AS_PROGRAM); - m_dma_timer[0] = timer_alloc(DMALV0_ID); - m_dma_timer[1] = timer_alloc(DMALV1_ID); - m_dma_timer[2] = timer_alloc(DMALV2_ID); + m_dma_timer[0] = timer_alloc(FUNC(sega_scu_device::dma_tick<DMALV0_ID>), this); + m_dma_timer[1] = timer_alloc(FUNC(sega_scu_device::dma_tick<DMALV1_ID>), this); + m_dma_timer[2] = timer_alloc(FUNC(sega_scu_device::dma_tick<DMALV2_ID>), this); } @@ -269,32 +269,20 @@ void sega_scu_device::device_reset_after_children() m_scudsp->set_input_line(INPUT_LINE_RESET, ASSERT_LINE); } - -void sega_scu_device::device_timer(emu_timer &timer, device_timer_id id, int param) +template <int Level> +TIMER_CALLBACK_MEMBER(sega_scu_device::dma_tick) { + const int irqlevel = Level == 0 ? 5 : 6; + const int irqvector = 0x4b - Level; + const uint16_t irqmask = 1 << (11 - Level); - switch(id) - { - case DMALV0_ID: - case DMALV1_ID: - case DMALV2_ID: - { - const int irqlevel = id == 0 ? 5 : 6; - const int irqvector = 0x4b - id; - const uint16_t irqmask = 1 << (11-id); - - if(!(m_ism & irqmask)) - m_hostcpu->set_input_line_and_vector(irqlevel, HOLD_LINE, irqvector); // SH2 - else - m_ist |= (irqmask); + if(!(m_ism & irqmask)) + m_hostcpu->set_input_line_and_vector(irqlevel, HOLD_LINE, irqvector); // SH2 + else + m_ist |= (irqmask); - update_dma_status(id,false); - machine().scheduler().synchronize(); // force resync - break; - } - default: - break; - } + update_dma_status((uint8_t)Level,false); + machine().scheduler().synchronize(); // force resync } //************************************************************************** diff --git a/src/devices/machine/sega_scu.h b/src/devices/machine/sega_scu.h index c454862bea0..4ee8dd1f08d 100644 --- a/src/devices/machine/sega_scu.h +++ b/src/devices/machine/sega_scu.h @@ -63,12 +63,13 @@ protected: 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; + + template <int Level> TIMER_CALLBACK_MEMBER(dma_tick); private: required_device<scudsp_cpu_device> m_scudsp; - enum { + enum dma_id : int { DMALV0_ID = 0, DMALV1_ID, DMALV2_ID diff --git a/src/devices/machine/sensorboard.cpp b/src/devices/machine/sensorboard.cpp index e9edf3a892a..a729aa4c126 100644 --- a/src/devices/machine/sensorboard.cpp +++ b/src/devices/machine/sensorboard.cpp @@ -114,8 +114,8 @@ void sensorboard_device::device_start() m_out_count.resolve(); } - m_undotimer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(sensorboard_device::undo_tick),this)); - m_sensortimer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(sensorboard_device::sensor_off),this)); + m_undotimer = timer_alloc(FUNC(sensorboard_device::undo_tick), this); + m_sensortimer = timer_alloc(FUNC(sensorboard_device::sensor_off), this); cancel_sensor(); u16 wmask = ~((1 << m_width) - 1); diff --git a/src/devices/machine/smc91c9x.cpp b/src/devices/machine/smc91c9x.cpp index 3b661933e42..3ca3fbeed13 100644 --- a/src/devices/machine/smc91c9x.cpp +++ b/src/devices/machine/smc91c9x.cpp @@ -82,7 +82,7 @@ void smc91c9x_device::device_start() m_buffer = std::make_unique<u8[]>(ETHER_BUFFER_SIZE * m_num_ebuf); // TX timer - m_tx_poll = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(smc91c9x_device::tx_poll), this)); + m_tx_poll = timer_alloc(FUNC(smc91c9x_device::tx_poll), this); m_irq_handler.resolve_safe(); diff --git a/src/devices/machine/smioc.cpp b/src/devices/machine/smioc.cpp index cd871e3d0a8..06c3e03adb1 100644 --- a/src/devices/machine/smioc.cpp +++ b/src/devices/machine/smioc.cpp @@ -214,8 +214,8 @@ smioc_device::smioc_device(const machine_config &mconfig, const char *tag, devic void smioc_device::device_start() { - m_dma_timer = timer_alloc(0); - m_451_timer = timer_alloc(1); + m_dma_timer = timer_alloc(FUNC(smioc_device::raise_drq), this); + m_451_timer = timer_alloc(FUNC(smioc_device::raise_int1), this); /* Resolve callbacks */ m_m68k_r_cb.resolve_safe(0); @@ -245,20 +245,17 @@ void smioc_device::SoftReset() m_deviceBusy = 1; } - -void smioc_device::device_timer(emu_timer &timer, device_timer_id tid, int param) +TIMER_CALLBACK_MEMBER(smioc_device::raise_drq) { - switch (tid) - { - case 0: // DMA Timer - m_smioccpu->drq0_w(1); - break; + // DMA Timer + m_smioccpu->drq0_w(1); +} - case 1: // 451 emulation timer - Trigger the SMIOC to read from C0180 and store data - m_smioccpu->int1_w(CLEAR_LINE); - m_smioccpu->int1_w(HOLD_LINE); - break; - } +TIMER_CALLBACK_MEMBER(smioc_device::raise_int1) +{ + // 451 emulation timer - Trigger the SMIOC to read from C0180 and store data + m_smioccpu->int1_w(CLEAR_LINE); + m_smioccpu->int1_w(HOLD_LINE); } void smioc_device::SendCommand(u16 command) diff --git a/src/devices/machine/smioc.h b/src/devices/machine/smioc.h index 4939fb53b1b..73dd874d149 100644 --- a/src/devices/machine/smioc.h +++ b/src/devices/machine/smioc.h @@ -108,7 +108,9 @@ protected: /* Optional information overrides */ virtual void device_add_mconfig(machine_config &config) 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; + + TIMER_CALLBACK_MEMBER(raise_drq); + TIMER_CALLBACK_MEMBER(raise_int1); u16 ReadDmaParameter(smioc_dma_parameter_t param); int DmaParameterAddress(smioc_dma_parameter_t param); diff --git a/src/devices/machine/smpc.cpp b/src/devices/machine/smpc.cpp index 30047cb51f1..7161d97b7f9 100644 --- a/src/devices/machine/smpc.cpp +++ b/src/devices/machine/smpc.cpp @@ -285,10 +285,10 @@ void smpc_hle_device::device_start() save_item(NAME(m_rtc_data)); save_item(NAME(m_smem)); - m_cmd_timer = timer_alloc(COMMAND_ID); - m_rtc_timer = timer_alloc(RTC_ID); - m_intback_timer = timer_alloc(INTBACK_ID); - m_sndres_timer = timer_alloc(SNDRES_ID); + m_cmd_timer = timer_alloc(FUNC(smpc_hle_device::handle_command), this); + m_rtc_timer = timer_alloc(FUNC(smpc_hle_device::handle_rtc_increment), this); + m_intback_timer = timer_alloc(FUNC(smpc_hle_device::intback_continue_request), this); + m_sndres_timer = timer_alloc(FUNC(smpc_hle_device::sound_reset), this); m_rtc_data[0] = DectoBCD(systime.local_time.year / 100); m_rtc_data[1] = DectoBCD(systime.local_time.year % 100); @@ -564,132 +564,119 @@ void smpc_hle_device::command_register_w(uint8_t data) } -void smpc_hle_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(smpc_hle_device::handle_command) { - switch(id) + switch(m_comreg) { - case COMMAND_ID: - { - switch(m_comreg) - { - case 0x00: // MSHON - // enable Master SH2 - m_mshres(m_comreg & 1); - break; - - case 0x02: // SSHON - case 0x03: // SSHOFF - // enable or disable Slave SH2 - m_sshres(m_comreg & 1); - break; - - case 0x06: // SNDON - case 0x07: // SNDOFF - // enable or disable 68k - m_sndres(m_comreg & 1); - break; - - case 0x08: // CDON - case 0x09: // CDOFF - // ... - m_command_in_progress = false; - m_oreg[31] = m_comreg; - // TODO: diagnostic also wants this to have bit 3 high - sf_ack(true); //set hand-shake flag - return; - - case 0x0a: // NETLINKON - // TODO: understand where NetLink actually lies and implement delegation accordingly - // (is it really an SH1 device like suggested by the space access or it overlays on CS2 bus?) - popmessage("%s: NetLink enabled", this->tag()); - [[fallthrough]]; - case 0x0b: // NETLINKOFF - break; - - case 0x0d: // SYSRES - // send a 1 -> 0 to device reset lines - m_sysres(1); - m_sysres(0); - - // send a 1 -> 0 transition to reset line (was PULSE_LINE) - m_mshres(1); - m_mshres(0); - break; - - case 0x0e: // CKCHG352 - case 0x0f: // CKCHG320 - m_dotsel(m_comreg & 1); - - // assert Slave SH2 line - m_sshres(1); - // clear PLL system halt - m_syshalt(0); - - // setup the new dot select - m_cur_dotsel = (m_comreg & 1) ^ 1; - - // send a NMI to Master SH2 if enabled - // it is unconditionally requested: - // bigichig, capgen1, capgen4 and capgen5 triggers a SLEEP opcode from BIOS call and expects this to wake them up. - //if(m_NMI_reset == false) - master_sh2_nmi(); - break; - - case 0x10: // INTBACK - resolve_intback(); - return; - - case 0x16: // SETTIME - { - for(int i=0;i<7;i++) - m_rtc_data[i] = m_ireg[i]; - break; - } - - case 0x17: // SETSMEM - { - for(int i=0;i<4;i++) - m_smem[i] = m_ireg[i]; - - // clear the SETIME variable, simulate a cr2032 battery alive in the system - m_smem[4] = 0xff; - break; - } - - case 0x18: // NMIREQ - // NMI is unconditionally requested - master_sh2_nmi(); - break; - - case 0x19: // RESENAB - case 0x1a: // RESDISA - m_NMI_reset = m_comreg & 1; - break; - - default: - logerror("%s: unemulated %02x command\n",this->tag(),m_comreg); - return; - } + case 0x00: // MSHON + // enable Master SH2 + m_mshres(m_comreg & 1); + break; + case 0x02: // SSHON + case 0x03: // SSHOFF + // enable or disable Slave SH2 + m_sshres(m_comreg & 1); + break; + + case 0x06: // SNDON + case 0x07: // SNDOFF + // enable or disable 68k + m_sndres(m_comreg & 1); + break; + + case 0x08: // CDON + case 0x09: // CDOFF + // ... m_command_in_progress = false; m_oreg[31] = m_comreg; - sf_ack(false); + // TODO: diagnostic also wants this to have bit 3 high + sf_ack(true); //set hand-shake flag + return; + + case 0x0a: // NETLINKON + // TODO: understand where NetLink actually lies and implement delegation accordingly + // (is it really an SH1 device like suggested by the space access or it overlays on CS2 bus?) + popmessage("%s: NetLink enabled", this->tag()); + [[fallthrough]]; + case 0x0b: // NETLINKOFF + break; + + case 0x0d: // SYSRES + // send a 1 -> 0 to device reset lines + m_sysres(1); + m_sysres(0); + + // send a 1 -> 0 transition to reset line (was PULSE_LINE) + m_mshres(1); + m_mshres(0); + break; + + case 0x0e: // CKCHG352 + case 0x0f: // CKCHG320 + m_dotsel(m_comreg & 1); + + // assert Slave SH2 line + m_sshres(1); + // clear PLL system halt + m_syshalt(0); + + // setup the new dot select + m_cur_dotsel = (m_comreg & 1) ^ 1; + + // send a NMI to Master SH2 if enabled + // it is unconditionally requested: + // bigichig, capgen1, capgen4 and capgen5 triggers a SLEEP opcode from BIOS call and expects this to wake them up. + //if(m_NMI_reset == false) + master_sh2_nmi(); + break; + + case 0x10: // INTBACK + resolve_intback(); + return; + + case 0x16: // SETTIME + { + for(int i=0;i<7;i++) + m_rtc_data[i] = m_ireg[i]; break; } - case INTBACK_ID: intback_continue_request(); break; - case RTC_ID: handle_rtc_increment(); break; + case 0x17: // SETSMEM + { + for(int i=0;i<4;i++) + m_smem[i] = m_ireg[i]; + + // clear the SETIME variable, simulate a cr2032 battery alive in the system + m_smem[4] = 0xff; + break; + } - // from m68k reset opcode trigger - case SNDRES_ID: - m_sndres(1); - m_sndres(0); + case 0x18: // NMIREQ + // NMI is unconditionally requested + master_sh2_nmi(); break; - default: - printf("%d\n",id); + case 0x19: // RESENAB + case 0x1a: // RESDISA + m_NMI_reset = m_comreg & 1; break; + + default: + logerror("%s: unemulated %02x command\n",this->tag(),m_comreg); + return; } + + m_command_in_progress = false; + m_oreg[31] = m_comreg; + sf_ack(false); +} + +TIMER_CALLBACK_MEMBER(smpc_hle_device::sound_reset) +{ + // from m68k reset opcode trigger + m_sndres(1); + m_sndres(0); } void smpc_hle_device::resolve_intback() @@ -749,7 +736,7 @@ void smpc_hle_device::resolve_intback() m_intback_stage = (m_intback_buf[1] & 8) >> 3; // first peripheral sr_set(0x40); m_oreg[31] = 0x10; - intback_continue_request(); + intback_continue_request(0); } else { @@ -759,7 +746,7 @@ void smpc_hle_device::resolve_intback() } } -void smpc_hle_device::intback_continue_request() +TIMER_CALLBACK_MEMBER(smpc_hle_device::intback_continue_request) { if( m_has_ctrl_ports == true ) read_saturn_ports(); @@ -801,7 +788,7 @@ int smpc_hle_device::DectoBCD(int num) // RTC handling //************************************************************************** -void smpc_hle_device::handle_rtc_increment() +TIMER_CALLBACK_MEMBER(smpc_hle_device::handle_rtc_increment) { const uint8_t dpm[12] = { 0x31, 0x28, 0x31, 0x30, 0x31, 0x30, 0x31, 0x31, 0x30, 0x31, 0x30, 0x31 }; int year_num, year_count; diff --git a/src/devices/machine/smpc.h b/src/devices/machine/smpc.h index a2f7c140ef0..60b461b6ad3 100644 --- a/src/devices/machine/smpc.h +++ b/src/devices/machine/smpc.h @@ -86,18 +86,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; private: const address_space_config m_space_config; - enum { - COMMAND_ID = 1, - RTC_ID, - INTBACK_ID, - SNDRES_ID - }; emu_timer *m_cmd_timer; emu_timer *m_rtc_timer; @@ -142,8 +135,10 @@ private: void irq_request(); void resolve_intback(); - void intback_continue_request(); - void handle_rtc_increment(); + TIMER_CALLBACK_MEMBER(intback_continue_request); + TIMER_CALLBACK_MEMBER(handle_rtc_increment); + TIMER_CALLBACK_MEMBER(sound_reset); + TIMER_CALLBACK_MEMBER(handle_command); void read_saturn_ports(); void sr_set(uint8_t data); diff --git a/src/devices/machine/spg290_cdservo.cpp b/src/devices/machine/spg290_cdservo.cpp index 3370724ece2..7d03836a486 100644 --- a/src/devices/machine/spg290_cdservo.cpp +++ b/src/devices/machine/spg290_cdservo.cpp @@ -36,7 +36,7 @@ void spg290_cdservo_device::device_start() m_irq_cb.resolve_safe(); m_space_write_cb.resolve_safe(); - m_cdtimer = timer_alloc(); + m_cdtimer = timer_alloc(FUNC(spg290_cdservo_device::cd_update), this); m_dsp_memory = std::make_unique<uint32_t[]>(0x10000); save_item(NAME(m_addr)); @@ -101,7 +101,7 @@ void spg290_cdservo_device::device_reset() change_status(); } -void spg290_cdservo_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(spg290_cdservo_device::cd_update) { if (!(m_control1 & 0x04) && m_cur_sector == m_seek_lba + SPG290_LEADIN_LEN) { diff --git a/src/devices/machine/spg290_cdservo.h b/src/devices/machine/spg290_cdservo.h index aff8cb62447..aa1d8077407 100644 --- a/src/devices/machine/spg290_cdservo.h +++ b/src/devices/machine/spg290_cdservo.h @@ -31,7 +31,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(cd_update); private: void change_status(); diff --git a/src/devices/machine/spg290_i2c.cpp b/src/devices/machine/spg290_i2c.cpp index 0475824c9bc..e360a451736 100644 --- a/src/devices/machine/spg290_i2c.cpp +++ b/src/devices/machine/spg290_i2c.cpp @@ -26,7 +26,7 @@ void spg290_i2c_device::device_start() m_irq_cb.resolve_safe(); m_i2c_read_cb.resolve_safe(0); m_i2c_write_cb.resolve_safe(); - m_i2c_timer = timer_alloc(); + m_i2c_timer = timer_alloc(FUNC(spg290_i2c_device::i2c_update), this); save_item(NAME(m_config)); save_item(NAME(m_irq_control)); @@ -52,7 +52,7 @@ void spg290_i2c_device::device_reset() m_irq_cb(CLEAR_LINE); } -void spg290_i2c_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(spg290_i2c_device::i2c_update) { if (m_config & 0x40) m_rdata = m_i2c_read_cb(m_port_addr); diff --git a/src/devices/machine/spg290_i2c.h b/src/devices/machine/spg290_i2c.h index 5e9fd0b3347..2dca1d145f4 100644 --- a/src/devices/machine/spg290_i2c.h +++ b/src/devices/machine/spg290_i2c.h @@ -23,7 +23,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(i2c_update); private: devcb_write_line m_irq_cb; diff --git a/src/devices/machine/spg290_timer.cpp b/src/devices/machine/spg290_timer.cpp index e574f3fcf39..8b02f751696 100644 --- a/src/devices/machine/spg290_timer.cpp +++ b/src/devices/machine/spg290_timer.cpp @@ -22,7 +22,7 @@ spg290_timer_device::spg290_timer_device(const machine_config &mconfig, const ch void spg290_timer_device::device_start() { m_irq_cb.resolve_safe(); - m_tick_timer = timer_alloc(); + m_tick_timer = timer_alloc(FUNC(spg290_timer_device::timer_update), this); save_item(NAME(m_enabled)); save_item(NAME(m_control)); @@ -56,7 +56,7 @@ void spg290_timer_device::device_clock_changed() m_tick_timer->adjust(attotime::never); } -void spg290_timer_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(spg290_timer_device::timer_update) { if (!BIT(m_control, 31)) return; diff --git a/src/devices/machine/spg290_timer.h b/src/devices/machine/spg290_timer.h index 9f3c3fe1e80..486011cb90b 100644 --- a/src/devices/machine/spg290_timer.h +++ b/src/devices/machine/spg290_timer.h @@ -22,7 +22,7 @@ protected: virtual void device_reset() override; virtual void device_clock_changed() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; + TIMER_CALLBACK_MEMBER(timer_update); private: devcb_write_line m_irq_cb; diff --git a/src/devices/machine/spg2xx_audio.cpp b/src/devices/machine/spg2xx_audio.cpp index 8c6c76c3fab..e8518bdaa59 100644 --- a/src/devices/machine/spg2xx_audio.cpp +++ b/src/devices/machine/spg2xx_audio.cpp @@ -73,7 +73,7 @@ sunplus_gcm394_audio_device::sunplus_gcm394_audio_device(const machine_config &m void spg2xx_audio_device::device_start() { - m_audio_beat = timer_alloc(TIMER_BEAT); + m_audio_beat = timer_alloc(FUNC(spg2xx_audio_device::audio_beat_tick), this); m_audio_beat->adjust(attotime::never); m_stream = stream_alloc(0, 2, 281250/4); @@ -107,7 +107,7 @@ void spg2xx_audio_device::device_start() memset(m_adpcm36_state + i, 0, sizeof(adpcm36_state)); - m_channel_irq[i] = timer_alloc(TIMER_IRQ + i); + m_channel_irq[i] = timer_alloc(FUNC(spg2xx_audio_device::irq_tick), this); m_channel_irq[i]->adjust(attotime::never); } @@ -159,24 +159,12 @@ void spg2xx_audio_device::device_stop() #endif } -void spg2xx_audio_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(spg2xx_audio_device::irq_tick) { - if (id >= TIMER_IRQ && id < (TIMER_IRQ + 16)) + if (!BIT(m_audio_ctrl_regs[AUDIO_CHANNEL_FIQ_STATUS], param)) { - const uint32_t bit = id - TIMER_IRQ; - if (!BIT(m_audio_ctrl_regs[AUDIO_CHANNEL_FIQ_STATUS], bit)) - { - m_audio_ctrl_regs[AUDIO_CHANNEL_FIQ_STATUS] |= (1 << (id - TIMER_IRQ)); - m_ch_irq_cb(1); - } - return; - } - - switch (id) - { - case TIMER_BEAT: - audio_beat_tick(); - break; + m_audio_ctrl_regs[AUDIO_CHANNEL_FIQ_STATUS] |= (1 << param); + m_ch_irq_cb(1); } } @@ -480,7 +468,7 @@ void spg2xx_audio_device::audio_ctrl_w(offs_t offset, uint16_t data) m_audio_ctrl_regs[offset] |= mask; if (BIT(m_audio_ctrl_regs[AUDIO_CHANNEL_FIQ_ENABLE], channel_bit)) { - m_channel_irq[channel_bit]->adjust(attotime::from_hz(m_channel_rate[channel_bit]), 0, attotime::from_hz(m_channel_rate[channel_bit])); + m_channel_irq[channel_bit]->adjust(attotime::from_hz(m_channel_rate[channel_bit]), channel_bit, attotime::from_hz(m_channel_rate[channel_bit])); } else { @@ -1250,7 +1238,7 @@ inline void spg2xx_audio_device::loop_channel(const uint32_t channel) LOGMASKED(LOG_SAMPLES, "Channel %d: Looping to address %08x\n", channel, m_sample_addr[channel]); } -void spg2xx_audio_device::audio_beat_tick() +TIMER_CALLBACK_MEMBER(spg2xx_audio_device::audio_beat_tick) { if (m_audio_curr_beat_base_count > 0) { diff --git a/src/devices/machine/spg2xx_audio.h b/src/devices/machine/spg2xx_audio.h index 72d9fd736d5..d0712139134 100644 --- a/src/devices/machine/spg2xx_audio.h +++ b/src/devices/machine/spg2xx_audio.h @@ -35,7 +35,8 @@ protected: // sound stream update overrides virtual void sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) override; - void audio_beat_tick(); + TIMER_CALLBACK_MEMBER(irq_tick); + TIMER_CALLBACK_MEMBER(audio_beat_tick); void audio_rampdown_tick(const uint32_t channel); bool audio_envelope_tick(const uint32_t channel); inline uint32_t get_rampdown_frame_count(const uint32_t channel); @@ -329,15 +330,11 @@ protected: int16_t m_prevsamp[2]; }; - static const device_timer_id TIMER_BEAT = 3; - static const device_timer_id TIMER_IRQ = 4; - void check_irqs(const uint16_t changed); 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; uint16_t read_space(offs_t offset); diff --git a/src/devices/machine/spg2xx_io.cpp b/src/devices/machine/spg2xx_io.cpp index b465fdcc546..13fa8a04c4f 100644 --- a/src/devices/machine/spg2xx_io.cpp +++ b/src/devices/machine/spg2xx_io.cpp @@ -99,24 +99,24 @@ void spg2xx_io_device::device_start() m_fiq_vector_w.resolve_safe(); - m_tmb1 = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(spg2xx_io_device::tmb_timer_tick<0>), this)); - m_tmb2 = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(spg2xx_io_device::tmb_timer_tick<1>), this)); + m_tmb1 = timer_alloc(FUNC(spg2xx_io_device::tmb_timer_tick<0>), this); + m_tmb2 = timer_alloc(FUNC(spg2xx_io_device::tmb_timer_tick<1>), this); - m_uart_tx_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(spg2xx_io_device::uart_transmit_tick), this)); - m_uart_rx_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(spg2xx_io_device::uart_receive_tick), this)); + m_uart_tx_timer = timer_alloc(FUNC(spg2xx_io_device::uart_transmit_tick), this); + m_uart_rx_timer = timer_alloc(FUNC(spg2xx_io_device::uart_receive_tick), this); - m_4khz_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(spg2xx_io_device::system_timer_tick), this)); + m_4khz_timer = timer_alloc(FUNC(spg2xx_io_device::system_timer_tick), this); - m_timer_src_ab = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(spg2xx_io_device::timer_ab_tick), this)); - m_timer_src_c = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(spg2xx_io_device::timer_c_tick), this)); - m_rng_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(spg2xx_io_device::rng_clock_tick), this)); - m_watchdog_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(spg2xx_io_device::watchdog_tick), this)); - m_spi_tx_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(spg2xx_io_device::spi_tx_tick), this)); + m_timer_src_ab = timer_alloc(FUNC(spg2xx_io_device::timer_ab_tick), this); + m_timer_src_c = timer_alloc(FUNC(spg2xx_io_device::timer_c_tick), this); + m_rng_timer = timer_alloc(FUNC(spg2xx_io_device::rng_clock_tick), this); + m_watchdog_timer = timer_alloc(FUNC(spg2xx_io_device::watchdog_tick), this); + m_spi_tx_timer = timer_alloc(FUNC(spg2xx_io_device::spi_tx_tick), this); - m_adc_timer[0] = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(spg2xx_io_device::adc_convert_tick<0>), this)); - m_adc_timer[1] = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(spg2xx_io_device::adc_convert_tick<1>), this)); - m_adc_timer[2] = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(spg2xx_io_device::adc_convert_tick<2>), this)); - m_adc_timer[3] = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(spg2xx_io_device::adc_convert_tick<3>), this)); + m_adc_timer[0] = timer_alloc(FUNC(spg2xx_io_device::adc_convert_tick<0>), this); + m_adc_timer[1] = timer_alloc(FUNC(spg2xx_io_device::adc_convert_tick<1>), this); + m_adc_timer[2] = timer_alloc(FUNC(spg2xx_io_device::adc_convert_tick<2>), this); + m_adc_timer[3] = timer_alloc(FUNC(spg2xx_io_device::adc_convert_tick<3>), this); save_item(NAME(m_io_regs)); diff --git a/src/devices/machine/spg2xx_video.cpp b/src/devices/machine/spg2xx_video.cpp index cdf93b52c51..b8d9fa2d22d 100644 --- a/src/devices/machine/spg2xx_video.cpp +++ b/src/devices/machine/spg2xx_video.cpp @@ -31,13 +31,13 @@ spg2xx_video_device::spg2xx_video_device(const machine_config &mconfig, device_t m_guny_in(*this), m_gunx_in(*this), m_sprlimit_read_cb(*this), + m_video_irq_cb(*this), m_cpu(*this, finder_base::DUMMY_TAG), m_screen(*this, finder_base::DUMMY_TAG), m_scrollram(*this, "scrollram"), m_hcompram(*this, "hcompram"), m_paletteram(*this, "paletteram"), m_spriteram(*this, "spriteram"), - m_video_irq_cb(*this), m_renderer(*this, "renderer") { } @@ -52,7 +52,7 @@ void spg2xx_video_device::device_start() m_guny_in.resolve_safe(0); m_gunx_in.resolve_safe(0); - m_screenpos_timer = timer_alloc(TIMER_SCREENPOS); + m_screenpos_timer = timer_alloc(FUNC(spg2xx_video_device::screenpos_hit), this); m_screenpos_timer->adjust(attotime::never); save_item(NAME(m_video_regs)); @@ -463,24 +463,17 @@ void spg2xx_video_device::check_video_irq() m_video_irq_cb((VIDEO_IRQ_STATUS & VIDEO_IRQ_ENABLE) ? ASSERT_LINE : CLEAR_LINE); } -void spg2xx_video_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(spg2xx_video_device::screenpos_hit) { - switch (id) + if (VIDEO_IRQ_ENABLE & 2) { - case TIMER_SCREENPOS: - { - if (VIDEO_IRQ_ENABLE & 2) - { - VIDEO_IRQ_STATUS |= 2; - check_video_irq(); - } - m_screen->update_partial(m_screen->vpos()); - - // fire again, jak_dbz pinball needs this - m_screenpos_timer->adjust(m_screen->time_until_pos(m_video_regs[0x36], m_video_regs[0x37] << 1)); - break; - } + VIDEO_IRQ_STATUS |= 2; + check_video_irq(); } + m_screen->update_partial(m_screen->vpos()); + + // fire again, jak_dbz pinball needs this + m_screenpos_timer->adjust(m_screen->time_until_pos(m_video_regs[0x36], m_video_regs[0x37] << 1)); } diff --git a/src/devices/machine/spg2xx_video.h b/src/devices/machine/spg2xx_video.h index f4d3e5e93b6..b484c42d1af 100644 --- a/src/devices/machine/spg2xx_video.h +++ b/src/devices/machine/spg2xx_video.h @@ -35,26 +35,19 @@ public: auto write_video_irq_callback() { return m_video_irq_cb.bind(); } protected: - virtual void device_add_mconfig(machine_config &config) override; - - devcb_read16 m_guny_in; - devcb_read16 m_gunx_in; - - inline void check_video_irq(); - - static const device_timer_id TIMER_SCREENPOS = 2; - 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; - void do_sprite_dma(uint32_t len); + void check_video_irq(); + TIMER_CALLBACK_MEMBER(screenpos_hit); - uint16_t m_video_regs[0x100]; + void do_sprite_dma(uint32_t len); + devcb_read16 m_guny_in; + devcb_read16 m_gunx_in; devcb_read16 m_sprlimit_read_cb; - - emu_timer *m_screenpos_timer; + devcb_write_line m_video_irq_cb; required_device<unsp_device> m_cpu; required_device<screen_device> m_screen; @@ -62,10 +55,10 @@ protected: required_shared_ptr<uint16_t> m_hcompram; required_shared_ptr<uint16_t> m_paletteram; required_shared_ptr<uint16_t> m_spriteram; - - devcb_write_line m_video_irq_cb; - required_device<spg_renderer_device> m_renderer; + + emu_timer *m_screenpos_timer; + uint16_t m_video_regs[0x100]; }; class spg24x_video_device : public spg2xx_video_device diff --git a/src/devices/machine/sun4c_mmu.cpp b/src/devices/machine/sun4c_mmu.cpp index 655326ccc1a..16b63c17dc1 100644 --- a/src/devices/machine/sun4c_mmu.cpp +++ b/src/devices/machine/sun4c_mmu.cpp @@ -100,7 +100,7 @@ void sun4_mmu_base_device::device_start() m_type1_w.resolve_safe(); // allocate timer for system reset - m_reset_timer = timer_alloc(TIMER_RESET); + m_reset_timer = timer_alloc(FUNC(sun4_mmu_base_device::reset_off_tick), this); m_reset_timer->adjust(attotime::never); m_segmap = std::make_unique<std::unique_ptr<uint8_t[]>[]>(16); @@ -221,13 +221,10 @@ void sun4_mmu_base_device::device_reset() memset(&m_cachedata[0], 0, sizeof(uint32_t) * 16384); } -void sun4_mmu_base_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(sun4_mmu_base_device::reset_off_tick) { - if (id == TIMER_RESET) - { - m_reset_timer->adjust(attotime::never); - m_cpu->set_input_line(SPARC_RESET, CLEAR_LINE); - } + m_reset_timer->adjust(attotime::never); + m_cpu->set_input_line(SPARC_RESET, CLEAR_LINE); } uint32_t sun4_mmu_base_device::fetch_insn(const bool supervisor, uint32_t offset) diff --git a/src/devices/machine/sun4c_mmu.h b/src/devices/machine/sun4c_mmu.h index 10e6afe8812..48f8517f33b 100644 --- a/src/devices/machine/sun4c_mmu.h +++ b/src/devices/machine/sun4c_mmu.h @@ -122,12 +122,11 @@ protected: uint8_t pad[3]; }; - static const device_timer_id TIMER_RESET = 0; - 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; + + TIMER_CALLBACK_MEMBER(reset_off_tick); uint32_t page_entry_to_uint(uint32_t index); void merge_page_entry(uint32_t index, uint32_t data, uint32_t mem_mask); diff --git a/src/devices/machine/swim1.cpp b/src/devices/machine/swim1.cpp index d3d36dfd777..2d0adc04c60 100644 --- a/src/devices/machine/swim1.cpp +++ b/src/devices/machine/swim1.cpp @@ -22,7 +22,7 @@ void swim1_device::device_start() { applefdintf_device::device_start(); - m_timer = timer_alloc(); + m_timer = timer_alloc(FUNC(swim1_device::update), this); save_item(NAME(m_last_sync)); save_item(NAME(m_flux_write_start)); save_item(NAME(m_flux_write)); @@ -381,7 +381,7 @@ void swim1_device::ism_write(offs_t offset, u8 data) } } -void swim1_device::device_timer(emu_timer &, device_timer_id, int) +TIMER_CALLBACK_MEMBER(swim1_device::update) { if(m_iwm_active == MODE_DELAY) { flush_write(); diff --git a/src/devices/machine/swim1.h b/src/devices/machine/swim1.h index dd87bf3fb43..dd0b372d54f 100644 --- a/src/devices/machine/swim1.h +++ b/src/devices/machine/swim1.h @@ -35,7 +35,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(update); private: enum { diff --git a/src/devices/machine/swim2.cpp b/src/devices/machine/swim2.cpp index 45d8447c367..d1834aad676 100644 --- a/src/devices/machine/swim2.cpp +++ b/src/devices/machine/swim2.cpp @@ -79,10 +79,6 @@ void swim2_device::device_reset() m_last_sync = machine().time().as_ticks(clock()); } -void swim2_device::device_timer(emu_timer &, device_timer_id, int) -{ -} - void swim2_device::set_floppy(floppy_image_device *floppy) { if(m_floppy == floppy) diff --git a/src/devices/machine/swim2.h b/src/devices/machine/swim2.h index 8cf665986c8..bab440e4ec9 100644 --- a/src/devices/machine/swim2.h +++ b/src/devices/machine/swim2.h @@ -36,7 +36,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; private: enum { diff --git a/src/devices/machine/swim3.cpp b/src/devices/machine/swim3.cpp index 41f313c3ee5..6c93ee6b0c4 100644 --- a/src/devices/machine/swim3.cpp +++ b/src/devices/machine/swim3.cpp @@ -24,7 +24,7 @@ void swim3_device::device_start() m_irq_cb.resolve_safe(); m_drq_cb.resolve_safe(); - m_timer = timer_alloc(0); + m_timer = timer_alloc(FUNC(swim3_device::update), this); save_item(NAME(m_mode)); save_item(NAME(m_setup)); @@ -300,7 +300,8 @@ void swim3_device::index_callback(floppy_image_device *floppy, int state) run(false, true); } } -void swim3_device::device_timer(emu_timer &timer, device_timer_id id, int param) + +TIMER_CALLBACK_MEMBER(swim3_device::update) { sync(); run(true, false); diff --git a/src/devices/machine/swim3.h b/src/devices/machine/swim3.h index e6a1cba19d1..61e280850e0 100644 --- a/src/devices/machine/swim3.h +++ b/src/devices/machine/swim3.h @@ -42,7 +42,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(update); private: enum { diff --git a/src/devices/machine/swtpc8212.cpp b/src/devices/machine/swtpc8212.cpp index f33176f8771..4d214e43175 100644 --- a/src/devices/machine/swtpc8212.cpp +++ b/src/devices/machine/swtpc8212.cpp @@ -323,14 +323,9 @@ MC6845_UPDATE_ROW(swtpc8212_device::update_row) } } -void swtpc8212_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(swtpc8212_device::bell_off) { - switch (id) - { - case BELL_TIMER_ID: - m_beeper->set_state(0); - break; - } + m_beeper->set_state(0); } void swtpc8212_device::rs232_conn_dcd_w(int state) @@ -382,7 +377,7 @@ void swtpc8212_device::device_resolve_objects() void swtpc8212_device::device_start() { - m_bell_timer = timer_alloc(BELL_TIMER_ID); + m_bell_timer = timer_alloc(FUNC(swtpc8212_device::bell_off), this); save_item(NAME(m_latch_data)); save_item(NAME(m_keyboard_data)); diff --git a/src/devices/machine/swtpc8212.h b/src/devices/machine/swtpc8212.h index 673a958b4ef..0d363860c14 100644 --- a/src/devices/machine/swtpc8212.h +++ b/src/devices/machine/swtpc8212.h @@ -39,18 +39,14 @@ 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 void device_add_mconfig(machine_config &config) override; virtual ioport_constructor device_input_ports() const override; virtual const tiny_rom_entry *device_rom_region() const override; -private: - enum - { - BELL_TIMER_ID = 1 - }; + TIMER_CALLBACK_MEMBER(bell_off); +private: void mem_map(address_map &map); required_device<m6802_cpu_device> m_maincpu; diff --git a/src/devices/machine/terminal.cpp b/src/devices/machine/terminal.cpp index 9dd98c13a00..fc1b5cf3092 100644 --- a/src/devices/machine/terminal.cpp +++ b/src/devices/machine/terminal.cpp @@ -346,7 +346,7 @@ void generic_terminal_device::device_add_mconfig(machine_config &config) void generic_terminal_device::device_start() { m_buffer = std::make_unique<uint8_t []>(m_width * m_height); - m_bell_timer = timer_alloc(BELL_TIMER_ID); + m_bell_timer = timer_alloc(FUNC(generic_terminal_device::bell_off), this); m_keyboard_cb.resolve(); save_pointer(NAME(m_buffer), m_width * m_height); save_item(NAME(m_x_pos)); @@ -361,14 +361,9 @@ void generic_terminal_device::device_reset() m_framecnt = 0; } -void generic_terminal_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(generic_terminal_device::bell_off) { - switch (id) - { - case BELL_TIMER_ID: - m_beeper->set_state(0); - break; - } + m_beeper->set_state(0); } /* diff --git a/src/devices/machine/terminal.h b/src/devices/machine/terminal.h index 620d04c3c1e..5ebf1468b22 100644 --- a/src/devices/machine/terminal.h +++ b/src/devices/machine/terminal.h @@ -34,18 +34,17 @@ public: void kbd_put(u8 data); protected: - enum { BELL_TIMER_ID = 20'000 }; - generic_terminal_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock, unsigned w, unsigned h); virtual void term_write(uint8_t data); 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; virtual void device_add_mconfig(machine_config &config) override; virtual void send_key(uint8_t code) { if (!m_keyboard_cb.isnull()) m_keyboard_cb(code); } + TIMER_CALLBACK_MEMBER(bell_off); + required_ioport m_io_term_conf; static constexpr unsigned TERMINAL_WIDTH = 80; diff --git a/src/devices/machine/ticket.cpp b/src/devices/machine/ticket.cpp index a3ab3072393..35c5d5625a8 100644 --- a/src/devices/machine/ticket.cpp +++ b/src/devices/machine/ticket.cpp @@ -17,7 +17,9 @@ //************************************************************************** #define DEBUG_TICKET 0 -#define LOG(x) do { if (DEBUG_TICKET) logerror x; } while (0) + +#define VERBOSE (DEBUG_TICKET) +#include "logmacro.h" @@ -99,7 +101,7 @@ WRITE_LINE_MEMBER( ticket_dispenser_device::motor_w ) { if (!m_power) { - LOG(("%s: Ticket Power On\n", machine().describe_context())); + LOG("%s: Ticket Power On\n", machine().describe_context()); m_timer->adjust(m_period); m_power = true; m_status = m_ticketnotdispensed; @@ -111,7 +113,7 @@ WRITE_LINE_MEMBER( ticket_dispenser_device::motor_w ) { if (m_hopper_type == false || m_status == m_ticketnotdispensed) { - LOG(("%s: Ticket Power Off\n", machine().describe_context())); + LOG("%s: Ticket Power Off\n", machine().describe_context()); m_timer->adjust(attotime::never); m_output = 0; } @@ -135,7 +137,7 @@ void ticket_dispenser_device::device_start() m_ticketdispensed = (m_status_sense == TICKET_STATUS_ACTIVE_HIGH); m_ticketnotdispensed = !m_ticketdispensed; - m_timer = timer_alloc(); + m_timer = timer_alloc(FUNC(ticket_dispenser_device::update_output_state), this); m_output.resolve(); @@ -156,22 +158,22 @@ void ticket_dispenser_device::device_reset() //------------------------------------------------- -// device_timer - handle timer callbacks +// update_output_state - //------------------------------------------------- -void ticket_dispenser_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(ticket_dispenser_device::update_output_state) { // if we still have power, keep toggling ticket states if (m_power) { m_status = !m_status; - LOG(("Ticket Status Changed to %02X\n", m_status)); + LOG("Ticket Status Changed to %02X\n", m_status); m_timer->adjust(m_period); } else if (m_hopper_type) { m_status = !m_status; - LOG(("%s: Ticket Power Off\n", machine().describe_context())); + LOG("%s: Ticket Power Off\n", machine().describe_context()); m_timer->adjust(attotime::never); m_output = 0; } @@ -183,6 +185,6 @@ void ticket_dispenser_device::device_timer(emu_timer &timer, device_timer_id id, if (m_status == m_ticketdispensed) { machine().bookkeeping().increment_dispensed_tickets(1); - LOG(("Ticket Dispensed\n")); + LOG("Ticket Dispensed\n"); } } diff --git a/src/devices/machine/ticket.h b/src/devices/machine/ticket.h index ee4e2bfed1d..0bf9dd106c3 100644 --- a/src/devices/machine/ticket.h +++ b/src/devices/machine/ticket.h @@ -69,9 +69,10 @@ protected: ticket_dispenser_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock = 0); // device-level overrides - virtual void device_start() override ATTR_COLD; - virtual void device_reset() override ATTR_COLD; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; + virtual void device_start() override; + virtual void device_reset() override; + + TIMER_CALLBACK_MEMBER(update_output_state); // configuration state uint8_t m_motor_sense; diff --git a/src/devices/machine/timekpr.cpp b/src/devices/machine/timekpr.cpp index 645a4604c8a..5825aa72100 100644 --- a/src/devices/machine/timekpr.cpp +++ b/src/devices/machine/timekpr.cpp @@ -227,10 +227,10 @@ void timekeeper_device::device_start() save_item(NAME(m_data)); save_item(NAME(m_watchdog_delay)); - emu_timer *timer = timer_alloc(); + emu_timer *timer = timer_alloc(FUNC(timekeeper_device::timer_tick), this); timer->adjust(attotime::from_seconds(1), 0, attotime::from_seconds(1)); - m_watchdog_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(timekeeper_device::watchdog_callback), this)); + m_watchdog_timer = timer_alloc(FUNC(timekeeper_device::watchdog_callback), this); m_watchdog_timer->adjust(attotime::never); m_reset_cb.resolve_safe(); m_irq_cb.resolve_safe(); @@ -240,7 +240,9 @@ void timekeeper_device::device_start() // device_reset - device-specific reset //------------------------------------------------- -void timekeeper_device::device_reset() { } +void timekeeper_device::device_reset() +{ +} void timekeeper_device::counters_to_ram() { @@ -268,7 +270,7 @@ void timekeeper_device::counters_from_ram() m_century = counter_from_ram(&m_data[0], m_offset_century); } -void timekeeper_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(timekeeper_device::timer_tick) { LOGMASKED(LOG_TICKS, "Tick\n"); if ((m_seconds & SECONDS_ST) != 0 || diff --git a/src/devices/machine/timekpr.h b/src/devices/machine/timekpr.h index 4c38a4e1784..9d6d04fafb4 100644 --- a/src/devices/machine/timekpr.h +++ b/src/devices/machine/timekpr.h @@ -46,13 +46,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; // device_nvram_interface overrides virtual void nvram_default() override; virtual bool nvram_read(util::read_stream &file) override; virtual bool nvram_write(util::write_stream &file) override; + TIMER_CALLBACK_MEMBER(timer_tick); TIMER_CALLBACK_MEMBER(watchdog_callback); devcb_write_line m_reset_cb; devcb_write_line m_irq_cb; diff --git a/src/devices/machine/timer.cpp b/src/devices/machine/timer.cpp index d5e0efe9394..67621f1085f 100644 --- a/src/devices/machine/timer.cpp +++ b/src/devices/machine/timer.cpp @@ -102,8 +102,10 @@ void timer_device::device_validity_check(validity_checker &valid) const void timer_device::device_start() { - // allocate the timer - m_timer = timer_alloc(); + if (m_type == TIMER_TYPE_SCANLINE) + m_timer = timer_alloc(FUNC(timer_device::scanline_tick), this); + else + m_timer = timer_alloc(FUNC(timer_device::generic_tick), this); m_callback.resolve(); @@ -153,44 +155,31 @@ void timer_device::device_reset() } -//------------------------------------------------- -// device_timer - handle timer expiration events -//------------------------------------------------- - -void timer_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(timer_device::generic_tick) { - switch (m_type) - { - // general periodic timers just call through - case TIMER_TYPE_GENERIC: - case TIMER_TYPE_PERIODIC: - if (!m_callback.isnull()) - (m_callback)(*this, param); - break; - - // scanline timers have to do some additional bookkeeping - case TIMER_TYPE_SCANLINE: - { - // by default, we fire at the first position - int next_vpos = m_first_vpos; + if (!m_callback.isnull()) + (m_callback)(*this, param); +} - // the first time through we just go with the default position - if (!m_first_time) - { - // call the real callback - int vpos = m_screen->vpos(); - if (!m_callback.isnull()) - (m_callback)(*this, vpos); - - // advance by the increment only if we will still be within the screen bounds - if (m_increment != 0 && (vpos + m_increment) < m_screen->height()) - next_vpos = vpos + m_increment; - } - m_first_time = false; +TIMER_CALLBACK_MEMBER(timer_device::scanline_tick) +{ + // by default, we fire at the first position + int next_vpos = m_first_vpos; - // adjust the timer - m_timer->adjust(m_screen->time_until_pos(next_vpos)); - break; - } + // the first time through we just go with the default position + if (!m_first_time) + { + // call the real callback + int vpos = m_screen->vpos(); + if (!m_callback.isnull()) + (m_callback)(*this, vpos); + + // advance by the increment only if we will still be within the screen bounds + if (m_increment != 0 && (vpos + m_increment) < m_screen->height()) + next_vpos = vpos + m_increment; } + m_first_time = false; + + // adjust the timer + m_timer->adjust(m_screen->time_until_pos(next_vpos)); } diff --git a/src/devices/machine/timer.h b/src/devices/machine/timer.h index c2e5bcefa6c..c002bd3148a 100644 --- a/src/devices/machine/timer.h +++ b/src/devices/machine/timer.h @@ -108,7 +108,9 @@ private: 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; + + TIMER_CALLBACK_MEMBER(generic_tick); + TIMER_CALLBACK_MEMBER(scanline_tick); // timer types enum timer_type diff --git a/src/devices/machine/tmp68301.cpp b/src/devices/machine/tmp68301.cpp index f6cd84dd318..bd3d2dc06f1 100644 --- a/src/devices/machine/tmp68301.cpp +++ b/src/devices/machine/tmp68301.cpp @@ -161,7 +161,7 @@ void tmp68301_device::device_start() m68000_device::device_start(); for (int i = 0; i < 3; i++) - m_tmp68301_timer[i] = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(tmp68301_device::timer_callback), this)); + m_tmp68301_timer[i] = timer_alloc(FUNC(tmp68301_device::timer_callback), this); m_in_parallel_cb.resolve_safe(0); m_out_parallel_cb.resolve_safe(); diff --git a/src/devices/machine/tms5501.cpp b/src/devices/machine/tms5501.cpp index 43d30a2c2d0..f5844d1c8bf 100644 --- a/src/devices/machine/tms5501.cpp +++ b/src/devices/machine/tms5501.cpp @@ -88,11 +88,11 @@ void tms5501_device::device_start() m_write_xo.resolve_safe(); // create timers - m_timer[TIMER_1] = timer_alloc(TIMER_1); - m_timer[TIMER_2] = timer_alloc(TIMER_2); - m_timer[TIMER_3] = timer_alloc(TIMER_3); - m_timer[TIMER_4] = timer_alloc(TIMER_4); - m_timer[TIMER_5] = timer_alloc(TIMER_5); + m_timer[TIMER_1] = timer_alloc(FUNC(tms5501_device::timer_expired), this); + m_timer[TIMER_2] = timer_alloc(FUNC(tms5501_device::timer_expired), this); + m_timer[TIMER_3] = timer_alloc(FUNC(tms5501_device::timer_expired), this); + m_timer[TIMER_4] = timer_alloc(FUNC(tms5501_device::timer_expired), this); + m_timer[TIMER_5] = timer_alloc(FUNC(tms5501_device::timer_expired), this); // state saving save_item(NAME(m_rb)); @@ -122,38 +122,22 @@ void tms5501_device::device_reset() //------------------------------------------------- -// device_timer - handle timer events +// timer_expired - //------------------------------------------------- -void tms5501_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(tms5501_device::timer_expired) { - switch (id) + if (param == TIMER_5) { - case TIMER_1: - set_interrupt(IRQ_TMR1); - break; - - case TIMER_2: - set_interrupt(IRQ_TMR2); - break; - - case TIMER_3: - set_interrupt(IRQ_TMR3); - break; - - case TIMER_4: - set_interrupt(IRQ_TMR4); - break; - - case TIMER_5: if (!(m_cmd & CMD_XI7)) { set_interrupt(IRQ_TMR5); } - break; - - default: - break; + } + else + { + static uint8_t const s_irq_ids[4] = { IRQ_TMR1, IRQ_TMR2, IRQ_TMR3, IRQ_TMR4 }; + set_interrupt(s_irq_ids[param]); } } @@ -406,7 +390,7 @@ void tms5501_device::tmr_w(offs_t offset, uint8_t data) { if (LOG) logerror("TMS5501 '%s' Timer %u %02x\n", tag(), offset, data); - m_timer[offset]->adjust(attotime::from_double((double) data / (clock() / 128.0))); + m_timer[offset]->adjust(attotime::from_double((double) data / (clock() / 128.0)), (int)offset); } diff --git a/src/devices/machine/tms5501.h b/src/devices/machine/tms5501.h index f2acc942478..e916141d12c 100644 --- a/src/devices/machine/tms5501.h +++ b/src/devices/machine/tms5501.h @@ -80,13 +80,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; // device_serial_interface overrides virtual void tra_callback() override; virtual void tra_complete() override; virtual void rcv_complete() override; + TIMER_CALLBACK_MEMBER(timer_expired); + private: enum { diff --git a/src/devices/machine/tms9901.cpp b/src/devices/machine/tms9901.cpp index e09d546cc4c..6714945fa2a 100644 --- a/src/devices/machine/tms9901.cpp +++ b/src/devices/machine/tms9901.cpp @@ -161,7 +161,7 @@ Clock mode: #define LOG_INT (1U << 4) #define LOG_CLOCK (1U << 5) -#define VERBOSE ( LOG_GENERAL ) +#define VERBOSE (LOG_GENERAL) #include "logmacro.h" /* @@ -466,17 +466,14 @@ void tms9901_device::update_clock() } /* - Timer callback + decrement_tick Decrementer counts down the value set in clock mode; when it reaches 0, raises an interrupt and resets to the start value */ -void tms9901_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(tms9901_device::decrement_tick) { - if (id==DECREMENTER) // we have only that one - { - timer_clock_in(ASSERT_LINE); - timer_clock_in(CLEAR_LINE); - } + timer_clock_in(ASSERT_LINE); + timer_clock_in(CLEAR_LINE); } void tms9901_device::timer_clock_in(line_state clk) @@ -627,7 +624,7 @@ void tms9901_device::device_start() // Allow for using asynchronous and synchronous clocks if (clock() != 0) { - m_decrementer = timer_alloc(DECREMENTER); + m_decrementer = timer_alloc(FUNC(tms9901_device::decrement_tick), this); m_decrementer->adjust(attotime::from_hz(clock() / 64.), 0, attotime::from_hz(clock() / 64.)); } diff --git a/src/devices/machine/tms9901.h b/src/devices/machine/tms9901.h index 68a8b1cd4cd..3d4808654a3 100644 --- a/src/devices/machine/tms9901.h +++ b/src/devices/machine/tms9901.h @@ -89,14 +89,13 @@ public: void update_clock(); private: - static constexpr device_timer_id DECREMENTER = 0; + 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; - void soft_reset(); + TIMER_CALLBACK_MEMBER(decrement_tick); - void device_start() override; - void device_stop() override; - void device_reset() override; + void soft_reset(); // Common method for device_reset and rst1_line void do_reset(); diff --git a/src/devices/machine/tms9902.cpp b/src/devices/machine/tms9902.cpp index 6c5b54a6095..68c0f671155 100644 --- a/src/devices/machine/tms9902.cpp +++ b/src/devices/machine/tms9902.cpp @@ -63,13 +63,6 @@ #define LOGSETTING(...) LOGMASKED(LOG_SETTING, __VA_ARGS__) -enum -{ - DECTIMER, - RECVTIMER, - SENDTIMER -}; - // Polling frequency. We use a much higher value to allow for line state changes // happening between character transmissions (which happen in parallel in real // communications but which must be serialized here) @@ -254,39 +247,36 @@ void tms9902_device::rcv_break(bool value) //------------------------------------------------ /* - Timer callback + Timer callbacks */ -void tms9902_device::device_timer(emu_timer &timer, device_timer_id id, int param) + +TIMER_CALLBACK_MEMBER(tms9902_device::decrementer_expired) { - switch (id) - { - // This call-back is called by the MAME timer system when the decrementer - // reaches 0. - case DECTIMER: - m_TIMERR = m_TIMELP; - m_TIMELP = true; - field_interrupts(); - break; + // This call-back is called when the decrementer reaches 0. + m_TIMERR = m_TIMELP; + m_TIMELP = true; + field_interrupts(); +} +TIMER_CALLBACK_MEMBER(tms9902_device::recv_tick) +{ // Callback for the autonomous operations of the chip. This is normally // controlled by an external clock of 3-4 MHz, internally divided by 3 or 4, // depending on CLK4M. With this timer, reception of characters becomes // possible. - case RECVTIMER: - m_rcv_cb(ASSERT_LINE); - break; + m_rcv_cb(ASSERT_LINE); +} - case SENDTIMER: - // Byte has been sent - m_XSRE = true; +TIMER_CALLBACK_MEMBER(tms9902_device::send_tick) +{ + // Byte has been sent + m_XSRE = true; - // In the meantime, the CPU may have pushed a new byte into the XBR - // so we loop until all data are transferred - if (!m_XBRE && m_CTSin) - { - initiate_transmit(); - } - break; + // In the meantime, the CPU may have pushed a new byte into the XBR + // so we loop until all data are transferred + if (!m_XBRE && m_CTSin) + { + initiate_transmit(); } } @@ -297,10 +287,8 @@ void tms9902_device::reload_interval_timer() { if (m_TMR) { /* reset clock interval */ - m_dectimer->adjust( - attotime::from_double((double) m_TMR / (m_clock_rate / ((m_CLK4M) ? 4. : 3.) / 64.)), - 0, - attotime::from_double((double) m_TMR / (m_clock_rate / ((m_CLK4M) ? 4. : 3.) / 64.))); + attotime rate = attotime::from_double((double) m_TMR / (m_clock_rate / ((m_CLK4M) ? 4. : 3.) / 64.)); + m_dectimer->adjust(rate, 0, rate); } else { /* clock interval == 0 -> no timer */ @@ -925,9 +913,9 @@ void tms9902_device::device_start() m_xmit_cb.resolve_safe(); m_ctrl_cb.resolve_safe(); - m_dectimer = timer_alloc(DECTIMER); - m_recvtimer = timer_alloc(RECVTIMER); - m_sendtimer = timer_alloc(SENDTIMER); + m_dectimer = timer_alloc(FUNC(tms9902_device::decrementer_expired), this); + m_recvtimer = timer_alloc(FUNC(tms9902_device::recv_tick), this); + m_sendtimer = timer_alloc(FUNC(tms9902_device::send_tick), this); save_item(NAME(m_LDCTRL)); save_item(NAME(m_LDIR)); diff --git a/src/devices/machine/tms9902.h b/src/devices/machine/tms9902.h index 37570b9ba5e..c784687bbe8 100644 --- a/src/devices/machine/tms9902.h +++ b/src/devices/machine/tms9902.h @@ -73,11 +73,14 @@ public: void cruwrite(offs_t offset, uint8_t data); protected: - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; virtual void device_start() override; virtual void device_reset() override; virtual void device_stop() override; + TIMER_CALLBACK_MEMBER(decrementer_expired); + TIMER_CALLBACK_MEMBER(recv_tick); + TIMER_CALLBACK_MEMBER(send_tick); + private: void field_interrupts(); void reload_interval_timer(); diff --git a/src/devices/machine/tms9914.cpp b/src/devices/machine/tms9914.cpp index 0c230efebeb..14cfcb7b039 100644 --- a/src/devices/machine/tms9914.cpp +++ b/src/devices/machine/tms9914.cpp @@ -20,11 +20,13 @@ // Debugging #define LOG_NOISY_MASK (LOG_GENERAL << 1) -#define LOG_NOISY(...) LOGMASKED(LOG_NOISY_MASK, __VA_ARGS__) #define LOG_REG_MASK (LOG_NOISY_MASK << 1) -#define LOG_REG(...) LOGMASKED(LOG_REG_MASK, __VA_ARGS__) #define LOG_INT_MASK (LOG_REG_MASK << 1) + +#define LOG_NOISY(...) LOGMASKED(LOG_NOISY_MASK, __VA_ARGS__) +#define LOG_REG(...) LOGMASKED(LOG_REG_MASK, __VA_ARGS__) #define LOG_INT(...) LOGMASKED(LOG_INT_MASK, __VA_ARGS__) + //#define VERBOSE (LOG_GENERAL) #include "logmacro.h" @@ -530,9 +532,9 @@ void tms9914_device::device_start() m_int_write_func.resolve_safe(); m_accrq_write_func.resolve_safe(); - m_sh_dly_timer = timer_alloc(SH_DELAY_TMR_ID); - m_ah_dly_timer = timer_alloc(AH_DELAY_TMR_ID); - m_c_dly_timer = timer_alloc(C_DELAY_TMR_ID); + m_sh_dly_timer = timer_alloc(FUNC(tms9914_device::fsm_tick), this); + m_ah_dly_timer = timer_alloc(FUNC(tms9914_device::fsm_tick), this); + m_c_dly_timer = timer_alloc(FUNC(tms9914_device::fsm_tick), this); } void tms9914_device::device_reset() @@ -593,9 +595,8 @@ void tms9914_device::device_reset() update_ren(); } -void tms9914_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(tms9914_device::fsm_tick) { - LOG_NOISY("tmr %d\n" , id); update_fsm(); } diff --git a/src/devices/machine/tms9914.h b/src/devices/machine/tms9914.h index 7b346a2e1d3..d67b85de025 100644 --- a/src/devices/machine/tms9914.h +++ b/src/devices/machine/tms9914.h @@ -94,7 +94,8 @@ private: // 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(fsm_tick); devcb_read8 m_dio_read_func; devcb_write8 m_dio_write_func; @@ -239,12 +240,6 @@ private: int m_c_state; // Timers - enum { - SH_DELAY_TMR_ID, - AH_DELAY_TMR_ID, - C_DELAY_TMR_ID - }; - emu_timer *m_sh_dly_timer; emu_timer *m_ah_dly_timer; emu_timer *m_c_dly_timer; diff --git a/src/devices/machine/upd1990a.cpp b/src/devices/machine/upd1990a.cpp index 8cad6a3bd3f..191d2b634cb 100644 --- a/src/devices/machine/upd1990a.cpp +++ b/src/devices/machine/upd1990a.cpp @@ -92,11 +92,11 @@ void upd1990a_device::device_start() m_testmode = false; // allocate timers - m_timer_clock = timer_alloc(TIMER_CLOCK); + m_timer_clock = timer_alloc(FUNC(upd1990a_device::clock_tick), this); m_timer_clock->adjust(attotime::from_hz(clock() / 32768.0), 0, attotime::from_hz(clock() / 32768.0)); // 1 second on XTAL(32'768) - m_timer_tp = timer_alloc(TIMER_TP); - m_timer_data_out = timer_alloc(TIMER_DATA_OUT); - m_timer_test_mode = timer_alloc(TIMER_TEST_MODE); + m_timer_tp = timer_alloc(FUNC(upd1990a_device::tp_tick), this); + m_timer_data_out = timer_alloc(FUNC(upd1990a_device::data_out_tick), this); + m_timer_test_mode = timer_alloc(FUNC(upd1990a_device::test_tick), this); // state saving save_item(NAME(m_time_counter)); @@ -130,58 +130,55 @@ void upd1990a_device::rtc_clock_updated(int year, int month, int day, int day_of //------------------------------------------------- -// device_timer - handler timer events +// timer handlers //------------------------------------------------- -void upd1990a_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(upd1990a_device::clock_tick) { - switch (id) - { - case TIMER_CLOCK: - advance_seconds(); - break; + advance_seconds(); +} - case TIMER_TP: - m_tp = !m_tp; - m_write_tp(m_tp); - break; +TIMER_CALLBACK_MEMBER(upd1990a_device::tp_tick) +{ + m_tp = !m_tp; + m_write_tp(m_tp); +} + +TIMER_CALLBACK_MEMBER(upd1990a_device::data_out_tick) +{ + m_data_out = !m_data_out; + m_write_data(get_data_out()); +} - case TIMER_DATA_OUT: - m_data_out = !m_data_out; +TIMER_CALLBACK_MEMBER(upd1990a_device::test_tick) +{ + if (m_oe) + { + /* TODO: completely untested */ + /* time counter is advanced from "Second" counter input */ + int max_shift = is_serial_mode() ? 6 : 5; + m_data_out = (m_time_counter[max_shift - 1] == 0); m_write_data(get_data_out()); - break; - case TIMER_TEST_MODE: - if (m_oe) + for (int i = 0; i < max_shift; i++) { - /* TODO: completely untested */ - /* time counter is advanced from "Second" counter input */ - int max_shift = is_serial_mode() ? 6 : 5; - m_data_out = (m_time_counter[max_shift - 1] == 0); - m_write_data(get_data_out()); - - for (int i = 0; i < max_shift; i++) - { - m_time_counter[i]++; - if (m_time_counter[i] != 0) - return; - } + m_time_counter[i]++; + if (m_time_counter[i] != 0) + return; } - else - { - /* each counter is advanced in parallel, overflow carry does not affect next counter */ - m_data_out = 0; + } + else + { + /* each counter is advanced in parallel, overflow carry does not affect next counter */ + m_data_out = 0; - int max_shift = is_serial_mode() ? 6 : 5; - for (int i = 0; i < max_shift; i++) - { - m_time_counter[i]++; - m_data_out |= (m_time_counter[i] == 0); - } - m_write_data(get_data_out()); + int max_shift = is_serial_mode() ? 6 : 5; + for (int i = 0; i < max_shift; i++) + { + m_time_counter[i]++; + m_data_out |= (m_time_counter[i] == 0); } - - break; + m_write_data(get_data_out()); } } diff --git a/src/devices/machine/upd1990a.h b/src/devices/machine/upd1990a.h index 9d41cf24f56..8a170a15021 100644 --- a/src/devices/machine/upd1990a.h +++ b/src/devices/machine/upd1990a.h @@ -55,11 +55,15 @@ protected: upd1990a_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock, uint32_t variant); virtual void device_start() 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; + TIMER_CALLBACK_MEMBER(clock_tick); + TIMER_CALLBACK_MEMBER(tp_tick); + TIMER_CALLBACK_MEMBER(data_out_tick); + TIMER_CALLBACK_MEMBER(test_tick); + enum { TYPE_1990A = 0, @@ -69,14 +73,6 @@ protected: private: enum { - TIMER_CLOCK, - TIMER_TP, - TIMER_DATA_OUT, - TIMER_TEST_MODE - }; - - enum - { MODE_REGISTER_HOLD = 0, MODE_SHIFT, MODE_TIME_SET, diff --git a/src/devices/machine/upd4991a.cpp b/src/devices/machine/upd4991a.cpp index 0252ccb2266..0f1419d7270 100644 --- a/src/devices/machine/upd4991a.cpp +++ b/src/devices/machine/upd4991a.cpp @@ -62,21 +62,16 @@ void upd4991a_device::device_validity_check(validity_checker &valid) const void upd4991a_device::device_start() { - m_timer_clock = timer_alloc(TIMER_CLOCK); + m_timer_clock = timer_alloc(FUNC(upd4991a_device::clock_tick), this); m_timer_clock->adjust(attotime::from_hz(clock() / 32768), 0, attotime::from_hz(clock() / 32768)); save_item(NAME(m_address)); } -void upd4991a_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(upd4991a_device::clock_tick) { - switch (id) - { - case TIMER_CLOCK: - advance_seconds(); - break; - } + advance_seconds(); } //------------------------------------------------- diff --git a/src/devices/machine/upd4991a.h b/src/devices/machine/upd4991a.h index 9b2d797ac7b..9a9da912279 100644 --- a/src/devices/machine/upd4991a.h +++ b/src/devices/machine/upd4991a.h @@ -35,18 +35,11 @@ protected: // device-level overrides virtual void device_validity_check(validity_checker &valid) const override; virtual void device_start() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; virtual void rtc_clock_updated(int year, int month, int day, int day_of_week, int hour, int minute, int second) override; -private: - enum - { - TIMER_CLOCK - //TIMER_TP, - //TIMER_DATA_OUT, - //TIMER_TEST_MODE - }; + TIMER_CALLBACK_MEMBER(clock_tick); +private: emu_timer *m_timer_clock; u8 m_rtc_regs[8]; u8 m_address; diff --git a/src/devices/machine/upd4992.cpp b/src/devices/machine/upd4992.cpp index 04ffb207350..52e3f8d9f10 100644 --- a/src/devices/machine/upd4992.cpp +++ b/src/devices/machine/upd4992.cpp @@ -58,19 +58,14 @@ void upd4992_device::device_validity_check(validity_checker &valid) const void upd4992_device::device_start() { - m_timer_clock = timer_alloc(TIMER_CLOCK); + m_timer_clock = timer_alloc(FUNC(upd4992_device::clock_tick), this); m_timer_clock->adjust(attotime::from_hz(clock() / 32768), 0, attotime::from_hz(clock() / 32768)); } -void upd4992_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(upd4992_device::clock_tick) { - switch (id) - { - case TIMER_CLOCK: - advance_seconds(); - break; - } + advance_seconds(); } //------------------------------------------------- diff --git a/src/devices/machine/upd4992.h b/src/devices/machine/upd4992.h index edf58cbeb3e..3151aa12eaa 100644 --- a/src/devices/machine/upd4992.h +++ b/src/devices/machine/upd4992.h @@ -34,18 +34,11 @@ protected: // device-level overrides virtual void device_validity_check(validity_checker &valid) const override; virtual void device_start() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; virtual void rtc_clock_updated(int year, int month, int day, int day_of_week, int hour, int minute, int second) override; -private: - enum - { - TIMER_CLOCK - //TIMER_TP, - //TIMER_DATA_OUT, - //TIMER_TEST_MODE - }; + TIMER_CALLBACK_MEMBER(clock_tick); +private: emu_timer *m_timer_clock; u8 m_rtc_regs[8]; }; diff --git a/src/devices/machine/upd7001.cpp b/src/devices/machine/upd7001.cpp index d4607e7a479..a6ae938b64c 100644 --- a/src/devices/machine/upd7001.cpp +++ b/src/devices/machine/upd7001.cpp @@ -85,8 +85,8 @@ void upd7001_device::device_start() m_fck_rc = attotime::from_double(m_res * m_cap * 1.97); // initialize timers - m_conv_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(upd7001_device::conversion_done), this)); - m_scsk_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(upd7001_device::output_enabled), this)); + m_conv_timer = timer_alloc(FUNC(upd7001_device::conversion_done), this); + m_scsk_timer = timer_alloc(FUNC(upd7001_device::output_enabled), this); // save state save_item(NAME(m_cs_active)); diff --git a/src/devices/machine/upd7002.cpp b/src/devices/machine/upd7002.cpp index 4288035eeba..da1036d109d 100644 --- a/src/devices/machine/upd7002.cpp +++ b/src/devices/machine/upd7002.cpp @@ -32,6 +32,7 @@ upd7002_device::upd7002_device(const machine_config &mconfig, const char *tag, d void upd7002_device::device_start() { + m_conversion_timer = timer_alloc(FUNC(upd7002_device::conversion_complete), this); m_get_analogue_cb.resolve(); m_eoc_cb.resolve(); @@ -68,31 +69,21 @@ READ_LINE_MEMBER( upd7002_device::eoc_r ) } -void upd7002_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(upd7002_device::conversion_complete) { - switch (id) + if (param == m_conversion_counter) { - case TIMER_CONVERSION_COMPLETE: - { - int counter_value = param; - if (counter_value == m_conversion_counter) - { - // this really always does a 12 bit conversion - m_data1 = m_digitalvalue >> 8; - m_data0 = m_digitalvalue & 0xf0; - - // set the status register with top 2 MSB, not busy and conversion complete - m_status = (m_status & 0x0f) | ((m_data1 & 0xc0) >> 2) | 0x40; - - // call the EOC function with EOC from status - // eoc_r(0) this has just been set to 0 - if (!m_eoc_cb.isnull()) m_eoc_cb(0); - m_conversion_counter=0; - } - } - break; - default: - throw emu_fatalerror("Unknown id in upd7002_device::device_timer"); + // this really always does a 12 bit conversion + m_data1 = m_digitalvalue >> 8; + m_data0 = m_digitalvalue & 0xf0; + + // set the status register with top 2 MSB, not busy and conversion complete + m_status = (m_status & 0x0f) | ((m_data1 & 0xc0) >> 2) | 0x40; + + // call the EOC function with EOC from status + // eoc_r(0) this has just been set to 0 + if (!m_eoc_cb.isnull()) m_eoc_cb(0); + m_conversion_counter = 0; } } @@ -155,12 +146,12 @@ void upd7002_device::write(offs_t offset, uint8_t data) if (m_status & 0x08) { // 12 bit conversion takes 10ms - timer_set(attotime::from_msec(10), TIMER_CONVERSION_COMPLETE, m_conversion_counter); + m_conversion_timer->adjust(attotime::from_msec(10), m_conversion_counter); } else { // 8 bit conversion takes 4ms - timer_set(attotime::from_msec(4), TIMER_CONVERSION_COMPLETE, m_conversion_counter); + m_conversion_timer->adjust(attotime::from_msec(4), m_conversion_counter); } break; diff --git a/src/devices/machine/upd7002.h b/src/devices/machine/upd7002.h index 06d353ca1fd..7069a68361d 100644 --- a/src/devices/machine/upd7002.h +++ b/src/devices/machine/upd7002.h @@ -38,7 +38,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(conversion_complete); private: // internal state @@ -77,10 +78,7 @@ private: get_analogue_delegate m_get_analogue_cb; eoc_delegate m_eoc_cb; - enum - { - TIMER_CONVERSION_COMPLETE - }; + emu_timer *m_conversion_timer; }; DECLARE_DEVICE_TYPE(UPD7002, upd7002_device) diff --git a/src/devices/machine/upd7004.cpp b/src/devices/machine/upd7004.cpp index bd3df848884..a5fb2cba78f 100644 --- a/src/devices/machine/upd7004.cpp +++ b/src/devices/machine/upd7004.cpp @@ -59,7 +59,7 @@ void upd7004_device::device_start() m_in_cb.resolve_all_safe(0x3ff); // allocate timers - m_cycle_timer = timer_alloc(); + m_cycle_timer = timer_alloc(FUNC(upd7004_device::update_state), this); m_cycle_timer->adjust(attotime::never); // register for save states @@ -71,10 +71,10 @@ void upd7004_device::device_start() } //------------------------------------------------- -// device_timer - handler timer events +// update_state - //------------------------------------------------- -void upd7004_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(upd7004_device::update_state) { switch (m_state) { diff --git a/src/devices/machine/upd7004.h b/src/devices/machine/upd7004.h index 6f52e1533a3..78d7eae559c 100644 --- a/src/devices/machine/upd7004.h +++ b/src/devices/machine/upd7004.h @@ -49,7 +49,8 @@ public: // device-level overrides virtual void device_start() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; + + TIMER_CALLBACK_MEMBER(update_state); private: // callbacks diff --git a/src/devices/machine/upd71071.cpp b/src/devices/machine/upd71071.cpp index de46ffe53c5..0a928be5361 100644 --- a/src/devices/machine/upd71071.cpp +++ b/src/devices/machine/upd71071.cpp @@ -117,7 +117,7 @@ void upd71071_device::device_start() m_dma_write_cb.resolve_all_safe(); m_out_dack_cb.resolve_all_safe(); for (auto &elem : m_timer) - elem = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(upd71071_device::dma_transfer_timer), this)); + elem = timer_alloc(FUNC(upd71071_device::dma_transfer_timer), this); m_selected_channel = 0; m_reg.device_control = 0; diff --git a/src/devices/machine/upd765.cpp b/src/devices/machine/upd765.cpp index 0db88c35c6e..b65afca6de1 100644 --- a/src/devices/machine/upd765.cpp +++ b/src/devices/machine/upd765.cpp @@ -216,7 +216,7 @@ void upd765_family_device::device_start() for(int i=0; i != 4; i++) { char name[2]; - flopi[i].tm = timer_alloc(i); + flopi[i].tm = timer_alloc(FUNC(upd765_family_device::update_floppy), this); flopi[i].id = i; if(select_connected) { name[0] = '0'+i; @@ -257,7 +257,7 @@ void upd765_family_device::device_start() cur_live.fi = nullptr; if(ready_polled) { - poll_timer = timer_alloc(TIMER_DRIVE_READY_POLLING); + poll_timer = timer_alloc(FUNC(upd765_family_device::run_drive_ready_polling), this); poll_timer->adjust(attotime::from_usec(100), 0, attotime::from_usec(1024)); } else poll_timer = nullptr; @@ -767,7 +767,7 @@ void upd765_family_device::live_delay(int state) { cur_live.next_state = state; if(cur_live.tm != machine().time()) - cur_live.fi->tm->adjust(cur_live.tm - machine().time()); + cur_live.fi->tm->adjust(cur_live.tm - machine().time(), cur_live.fi->id); else live_sync(); } @@ -831,7 +831,7 @@ void upd765_family_device::live_run(attotime limit) // infinity looking for data too. limit = machine().time() + attotime::from_msec(1); - cur_live.fi->tm->adjust(attotime::from_msec(1)); + cur_live.fi->tm->adjust(attotime::from_msec(1), cur_live.fi->id); } } @@ -1618,9 +1618,9 @@ void upd765_family_device::seek_start(floppy_info &fi) seek_continue(fi); } -void upd765_family_device::delay_cycles(emu_timer *tm, int cycles) +void upd765_family_device::delay_cycles(floppy_info &fi, int cycles) { - tm->adjust(attotime::from_double(double(cycles)/cur_rate)); + fi.tm->adjust(attotime::from_double(double(cycles)/cur_rate), fi.id); } void upd765_family_device::seek_continue(floppy_info &fi) @@ -1634,7 +1634,7 @@ void upd765_family_device::seek_continue(floppy_info &fi) fi.dev->stp_w(0); } fi.sub_state = SEEK_WAIT_STEP_SIGNAL_TIME; - fi.tm->adjust(attotime::from_nsec(2500)); + fi.tm->adjust(attotime::from_nsec(2500), fi.id); return; case SEEK_WAIT_STEP_SIGNAL_TIME: @@ -1653,7 +1653,7 @@ void upd765_family_device::seek_continue(floppy_info &fi) fi.pcn++; } fi.sub_state = SEEK_WAIT_STEP_TIME; - delay_cycles(fi.tm, 500*(16-(spec >> 12))); + delay_cycles(fi, 500*(16-(spec >> 12))); return; case SEEK_WAIT_STEP_TIME: @@ -1684,7 +1684,7 @@ void upd765_family_device::seek_continue(floppy_info &fi) if(done) { fi.sub_state = SEEK_WAIT_DONE; // recalibrate and seek takes some time, even if we don't move - fi.tm->adjust(attotime::from_nsec((fi.main_state == RECALIBRATE) ? 20000 : 10000)); + fi.tm->adjust(attotime::from_nsec((fi.main_state == RECALIBRATE) ? 20000 : 10000), fi.id); return; } fi.sub_state = SEEK_MOVE; @@ -1796,7 +1796,7 @@ void upd765_family_device::read_data_continue(floppy_info &fi) switch(fi.sub_state) { case HEAD_LOAD: LOGSTATE("HEAD_LOAD\n"); - delay_cycles(fi.tm, 500*(spec & 0x00fe)); + delay_cycles(fi, 500*(spec & 0x00fe)); fi.sub_state = HEAD_LOAD_DONE; break; case HEAD_LOAD_DONE: @@ -1811,7 +1811,7 @@ void upd765_family_device::read_data_continue(floppy_info &fi) fi.dev->stp_w(0); } fi.sub_state = SEEK_WAIT_STEP_SIGNAL_TIME; - fi.tm->adjust(attotime::from_nsec(2500)); + fi.tm->adjust(attotime::from_nsec(2500), fi.id); return; case SEEK_WAIT_STEP_SIGNAL_TIME: @@ -1824,7 +1824,7 @@ void upd765_family_device::read_data_continue(floppy_info &fi) fi.dev->stp_w(1); fi.sub_state = SEEK_WAIT_STEP_TIME; - delay_cycles(fi.tm, 500*(16-(spec >> 12))); + delay_cycles(fi, 500*(16-(spec >> 12))); return; case SEEK_WAIT_STEP_TIME: @@ -2027,7 +2027,7 @@ void upd765_family_device::write_data_continue(floppy_info &fi) switch(fi.sub_state) { case HEAD_LOAD: LOGSTATE("HEAD_LOAD\n"); - delay_cycles(fi.tm, 500*(spec & 0x00fe)); + delay_cycles(fi, 500*(spec & 0x00fe)); fi.sub_state = HEAD_LOAD_DONE; break; case HEAD_LOAD_DONE: @@ -2168,7 +2168,7 @@ void upd765_family_device::read_track_continue(floppy_info &fi) switch(fi.sub_state) { case HEAD_LOAD: LOGSTATE("HEAD_LOAD\n"); - delay_cycles(fi.tm, 500*(spec & 0x00fe)); + delay_cycles(fi, 500*(spec & 0x00fe)); fi.sub_state = HEAD_LOAD_DONE; break; case HEAD_LOAD_DONE: @@ -2183,7 +2183,7 @@ void upd765_family_device::read_track_continue(floppy_info &fi) fi.dev->stp_w(0); } fi.sub_state = SEEK_WAIT_STEP_SIGNAL_TIME; - fi.tm->adjust(attotime::from_nsec(2500)); + fi.tm->adjust(attotime::from_nsec(2500), fi.id); return; case SEEK_WAIT_STEP_SIGNAL_TIME: @@ -2196,7 +2196,7 @@ void upd765_family_device::read_track_continue(floppy_info &fi) fi.dev->stp_w(1); fi.sub_state = SEEK_WAIT_STEP_TIME; - delay_cycles(fi.tm, 500*(16-(spec >> 12))); + delay_cycles(fi, 500*(16-(spec >> 12))); return; case SEEK_WAIT_STEP_TIME: @@ -2357,7 +2357,7 @@ void upd765_family_device::format_track_continue(floppy_info &fi) switch(fi.sub_state) { case HEAD_LOAD: LOGSTATE("HEAD_LOAD\n"); - delay_cycles(fi.tm, 500*(spec & 0x00fe)); + delay_cycles(fi, 500*(spec & 0x00fe)); fi.sub_state = HEAD_LOAD_DONE; break; case HEAD_LOAD_DONE: @@ -2442,7 +2442,7 @@ void upd765_family_device::read_id_continue(floppy_info &fi) switch(fi.sub_state) { case HEAD_LOAD: LOGSTATE("HEAD_LOAD\n"); - delay_cycles(fi.tm, 500*(spec & 0x00fe)); + delay_cycles(fi, 500*(spec & 0x00fe)); fi.sub_state = HEAD_LOAD_DONE; break; case HEAD_LOAD_DONE: @@ -2526,16 +2526,11 @@ std::string upd765_family_device::ttsn() const return machine().time().to_string(); } -void upd765_family_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(upd765_family_device::update_floppy) { - if(id == TIMER_DRIVE_READY_POLLING) { - run_drive_ready_polling(); - return; - } - live_sync(); - floppy_info &fi = flopi[id]; + floppy_info &fi = flopi[param]; switch(fi.sub_state) { case SEEK_WAIT_STEP_SIGNAL_TIME: fi.sub_state = SEEK_WAIT_STEP_SIGNAL_TIME_DONE; @@ -2548,7 +2543,7 @@ void upd765_family_device::device_timer(emu_timer &timer, device_timer_id id, in general_continue(fi); } -void upd765_family_device::run_drive_ready_polling() +TIMER_CALLBACK_MEMBER(upd765_family_device::run_drive_ready_polling) { if(main_phase != PHASE_CMD || (fifocfg & FIF_POLL) || command_pos) return; diff --git a/src/devices/machine/upd765.h b/src/devices/machine/upd765.h index b8840e712a2..f4441e72543 100644 --- a/src/devices/machine/upd765.h +++ b/src/devices/machine/upd765.h @@ -64,11 +64,8 @@ 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; - enum { - TIMER_DRIVE_READY_POLLING = 4 - }; + TIMER_CALLBACK_MEMBER(update_floppy); enum { PHASE_CMD, PHASE_EXEC, PHASE_RESULT @@ -290,7 +287,7 @@ protected: void end_reset(); - void delay_cycles(emu_timer *tm, int cycles); + void delay_cycles(floppy_info &fi, int cycles); void check_irq(); void fifo_expect(int size, bool write); void fifo_push(uint8_t data, bool internal); @@ -303,7 +300,7 @@ protected: void disable_transfer(); int calc_sector_size(uint8_t size); - void run_drive_ready_polling(); + TIMER_CALLBACK_MEMBER(run_drive_ready_polling); virtual int check_command(); virtual void start_command(int cmd); diff --git a/src/devices/machine/v3021.cpp b/src/devices/machine/v3021.cpp index 559a617340a..6d84109e2ec 100644 --- a/src/devices/machine/v3021.cpp +++ b/src/devices/machine/v3021.cpp @@ -153,7 +153,7 @@ void v3021_device::device_validity_check(validity_checker &valid) const void v3021_device::device_start() { /* let's call the timer callback every second */ - m_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(v3021_device::timer_callback), this)); + m_timer = timer_alloc(FUNC(v3021_device::timer_callback), this); m_timer->adjust(attotime::from_hz(clock() / XTAL(32'768)), 0, attotime::from_hz(clock() / XTAL(32'768))); copy_clock_to_ram(); diff --git a/src/devices/machine/vic_pl192.cpp b/src/devices/machine/vic_pl192.cpp index 23cae3a5445..2e7a2f4ad85 100644 --- a/src/devices/machine/vic_pl192.cpp +++ b/src/devices/machine/vic_pl192.cpp @@ -1,13 +1,11 @@ // license:BSD-3-Clause // copyright-holders:Devin Acker, Melissa Goad -// ARM PrimeCell PL910/PL192 VIC emulation +// ARM PrimeCell PL190/PL192 VIC emulation #include "emu.h" #include "machine/vic_pl192.h" -#define LOG_GENERAL (1U << 0) - #define VERBOSE (LOG_GENERAL) #include "logmacro.h" @@ -15,31 +13,188 @@ DEFINE_DEVICE_TYPE(PL190_VIC, vic_pl190_device, "vic_pl190", "ARM PL190 VIC") DEFINE_DEVICE_TYPE(UPD800468_VIC, vic_upd800468_device, "vic_upd800468", "NEC uPD800468 VIC") DEFINE_DEVICE_TYPE(PL192_VIC, vic_pl192_device, "vic_pl192", "ARM PL192 VIC") -void vic_pl190_device::device_timer(emu_timer &timer, device_timer_id id, int param) +vic_pl190_device::vic_pl190_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock) + : device_t(mconfig, type, tag, owner, clock) + , device_memory_interface(mconfig, *this) + , num_vectors(16) + , periph_id{0x92, 0x11, 0x04, 0x00} + , pcell_id{0x0d, 0xf0, 0x05, 0xb1} + , m_irq_sync_timer(nullptr) + , m_mmio_config("mmio", ENDIANNESS_LITTLE, 32, 32, 0) + , m_out_irq_func(*this) + , m_out_fiq_func(*this) +{ +} + +vic_pl190_device::vic_pl190_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) + : vic_pl190_device(mconfig, PL190_VIC, tag, owner, clock) +{ +} + +vic_upd800468_device::vic_upd800468_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) + : vic_pl190_device(mconfig, UPD800468_VIC, tag, owner, clock) +{ + num_vectors = 32; +} + +vic_pl192_device::vic_pl192_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) + : vic_pl190_device(mconfig, PL192_VIC, tag, owner, clock) +{ + num_vectors = 32; +} + +void vic_pl190_device::device_start() +{ + save_item(NAME(raw_intr)); + save_item(NAME(intr_select)); + save_item(NAME(intr_en)); + save_item(NAME(soft_intr)); + save_item(NAME(vectaddr)); + save_item(NAME(defaddress)); + save_item(NAME(vicaddress)); + save_item(NAME(priority_mask)); + save_item(NAME(priority)); + save_item(NAME(protection)); + + m_irq_sync_timer = timer_alloc(FUNC(vic_pl190_device::irq_sync_tick), this); +} + +void vic_pl192_device::device_start() +{ + vic_pl190_device::device_start(); + + save_item(NAME(sw_priority_mask)); + save_item(NAME(daisy_priority)); +} + +void vic_pl190_device::device_reset() +{ + raw_intr = intr_select = intr_en = soft_intr = 0; + defaddress = vicaddress = protection = 0; + + priority_mask = ~0; + priority = ~0; + + for(int i = 0; i < 32; i++) + { + vectaddr[i] = 0; + vectctl[i] = 0; + } +} + +void vic_pl192_device::device_reset() +{ + vic_pl190_device::device_reset(); + + sw_priority_mask = 0xffff; + daisy_priority = 0xf; + + for (int i = 0; i < 32; i++) + { + vectctl[i] = 0xf; + } +} + +device_memory_interface::space_config_vector vic_pl190_device::memory_space_config() const +{ + return space_config_vector{ + std::make_pair(0, &m_mmio_config) + }; +} + +void vic_pl190_device::device_resolve_objects() +{ + // resolve callbacks + m_out_irq_func.resolve_safe(); + m_out_fiq_func.resolve_safe(); +} + +void vic_pl190_device::map(address_map &map) +{ + map(0x000, 0x003).r(FUNC(vic_pl190_device::irq_status_r)); + map(0x004, 0x007).r(FUNC(vic_pl190_device::fiq_status_r)); + map(0x008, 0x00b).r(FUNC(vic_pl190_device::raw_intr_r)); + map(0x00c, 0x00f).rw(FUNC(vic_pl190_device::int_select_r), FUNC(vic_pl190_device::int_select_w)); + map(0x010, 0x013).rw(FUNC(vic_pl190_device::int_enable_r), FUNC(vic_pl190_device::int_enable_w)); + map(0x014, 0x017).w(FUNC(vic_pl190_device::int_en_clear_w)); + map(0x018, 0x01b).rw(FUNC(vic_pl190_device::soft_int_r), FUNC(vic_pl190_device::soft_int_w)); + map(0x01c, 0x01f).w(FUNC(vic_pl190_device::soft_int_clear_w)); + map(0x020, 0x020).rw(FUNC(vic_pl190_device::protection_r), FUNC(vic_pl190_device::protection_w)).umask32(0x000000ff); + map(0x030, 0x033).rw(FUNC(vic_pl190_device::cur_vect_addr_r), FUNC(vic_pl190_device::cur_vect_addr_w)); + map(0x034, 0x037).rw(FUNC(vic_pl190_device::def_vect_addr_r), FUNC(vic_pl190_device::def_vect_addr_w)); + map(0x100, 0x13f).rw(FUNC(vic_pl190_device::vect_addr_r), FUNC(vic_pl190_device::vect_addr_w)); + map(0x200, 0x23f).rw(FUNC(vic_pl190_device::vect_ctl_r), FUNC(vic_pl190_device::vect_ctl_w)); + map(0xfe0, 0xfe0).lr8([this](offs_t offset){ return periph_id[0]; }, "periph_id0").umask32(0x000000ff); + map(0xfe4, 0xfe4).lr8([this](offs_t offset){ return periph_id[1]; }, "periph_id1").umask32(0x000000ff); + map(0xfe8, 0xfe8).lr8([this](offs_t offset){ return periph_id[2]; }, "periph_id2").umask32(0x000000ff); + map(0xfec, 0xfec).lr8([this](offs_t offset){ return periph_id[3]; }, "periph_id3").umask32(0x000000ff); + map(0xff0, 0xff0).lr8([this](offs_t offset){ return pcell_id[0]; }, "pcell_id0").umask32(0x000000ff); + map(0xff4, 0xff4).lr8([this](offs_t offset){ return pcell_id[1]; }, "pcell_id1").umask32(0x000000ff); + map(0xff8, 0xff8).lr8([this](offs_t offset){ return pcell_id[2]; }, "pcell_id2").umask32(0x000000ff); + map(0xffc, 0xffc).lr8([this](offs_t offset){ return pcell_id[3]; }, "pcell_id3").umask32(0x000000ff); +} + +void vic_upd800468_device::map(address_map &map) +{ + vic_pl190_device::map(map); + + map(0x100, 0x17f).rw(FUNC(vic_pl190_device::vect_addr_r), FUNC(vic_pl190_device::vect_addr_w)); + map(0x200, 0x27f).rw(FUNC(vic_pl190_device::vect_ctl_r), FUNC(vic_pl190_device::vect_ctl_w)); + map(0x2c8, 0x2cb).w(FUNC(vic_upd800468_device::int_clear_w)); +} + +void vic_pl192_device::map(address_map &map) +{ + map(0x000, 0x003).r(FUNC(vic_pl190_device::irq_status_r)); + map(0x004, 0x007).r(FUNC(vic_pl190_device::fiq_status_r)); + map(0x008, 0x00b).r(FUNC(vic_pl190_device::raw_intr_r)); + map(0x00c, 0x00f).rw(FUNC(vic_pl190_device::int_select_r), FUNC(vic_pl190_device::int_select_w)); + map(0x010, 0x013).rw(FUNC(vic_pl190_device::int_enable_r), FUNC(vic_pl190_device::int_enable_w)); + map(0x014, 0x017).w(FUNC(vic_pl190_device::int_en_clear_w)); + map(0x018, 0x01b).rw(FUNC(vic_pl190_device::soft_int_r), FUNC(vic_pl190_device::soft_int_w)); + map(0x01c, 0x01f).w(FUNC(vic_pl190_device::soft_int_clear_w)); + map(0x020, 0x020).rw(FUNC(vic_pl190_device::protection_r), FUNC(vic_pl190_device::protection_w)).umask32(0x000000ff); + map(0x024, 0x025).rw(FUNC(vic_pl192_device::sw_priority_r), FUNC(vic_pl192_device::sw_priority_w)).umask32(0x0000ffff); + map(0x028, 0x028).rw(FUNC(vic_pl192_device::daisy_priority_r), FUNC(vic_pl192_device::daisy_priority_w)).umask32(0x000000ff); + map(0x100, 0x17f).rw(FUNC(vic_pl190_device::vect_addr_r), FUNC(vic_pl190_device::vect_addr_w)); + map(0x200, 0x27f).rw(FUNC(vic_pl190_device::vect_ctl_r), FUNC(vic_pl190_device::vect_ctl_w)); + map(0xf00, 0xf03).rw(FUNC(vic_pl190_device::cur_vect_addr_r), FUNC(vic_pl190_device::cur_vect_addr_w)); + map(0xfe0, 0xfe0).lr8([this](offs_t offset) { return periph_id[0]; }, "periph_id0").umask32(0x000000ff); + map(0xfe4, 0xfe4).lr8([this](offs_t offset) { return periph_id[1]; }, "periph_id1").umask32(0x000000ff); + map(0xfe8, 0xfe8).lr8([this](offs_t offset) { return periph_id[2]; }, "periph_id2").umask32(0x000000ff); + map(0xfec, 0xfec).lr8([this](offs_t offset) { return periph_id[3]; }, "periph_id3").umask32(0x000000ff); + map(0xff0, 0xff0).lr8([this](offs_t offset) { return pcell_id[0]; }, "pcell_id0").umask32(0x000000ff); + map(0xff4, 0xff4).lr8([this](offs_t offset) { return pcell_id[1]; }, "pcell_id1").umask32(0x000000ff); + map(0xff8, 0xff8).lr8([this](offs_t offset) { return pcell_id[2]; }, "pcell_id2").umask32(0x000000ff); + map(0xffc, 0xffc).lr8([this](offs_t offset) { return pcell_id[3]; }, "pcell_id3").umask32(0x000000ff); +} + +TIMER_CALLBACK_MEMBER(vic_pl190_device::irq_sync_tick) { u32 intrs = (raw_intr | soft_intr) & intr_en; - if (intrs & intr_select) m_out_fiq_func(1); - else m_out_fiq_func(0); + if (intrs & intr_select) + m_out_fiq_func(1); + else + m_out_fiq_func(0); - if (intrs & ~intr_select & priority_mask) m_out_irq_func(1); - else m_out_irq_func(0); + if (intrs & ~intr_select & priority_mask) + m_out_irq_func(1); + else + m_out_irq_func(0); } void vic_pl190_device::set_irq_line(int irq, int state) { u32 mask = (1 << irq); - if(state) - { + if (state) raw_intr |= mask; - } else - { raw_intr &= ~mask; - } - timer_set(attotime::zero, TIMER_CHECK_IRQ); + + m_irq_sync_timer->adjust(attotime::zero); } u32 vic_pl190_device::irq_status_r() @@ -65,7 +220,7 @@ u32 vic_pl190_device::int_select_r() void vic_pl190_device::int_select_w(u32 data) { intr_select = data; - timer_set(attotime::zero, TIMER_CHECK_IRQ); + m_irq_sync_timer->adjust(attotime::zero); } u32 vic_pl190_device::int_enable_r() @@ -76,13 +231,13 @@ u32 vic_pl190_device::int_enable_r() void vic_pl190_device::int_enable_w(u32 data) { intr_en |= data; - timer_set(attotime::zero, TIMER_CHECK_IRQ); + m_irq_sync_timer->adjust(attotime::zero); } void vic_pl190_device::int_en_clear_w(u32 data) { intr_en &= ~data; - timer_set(attotime::zero, TIMER_CHECK_IRQ); + m_irq_sync_timer->adjust(attotime::zero); } u32 vic_pl190_device::soft_int_r() @@ -93,13 +248,13 @@ u32 vic_pl190_device::soft_int_r() void vic_pl190_device::soft_int_w(u32 data) { soft_intr |= data; - timer_set(attotime::zero, TIMER_CHECK_IRQ); + m_irq_sync_timer->adjust(attotime::zero); } void vic_pl190_device::soft_int_clear_w(u32 data) { soft_intr &= ~data; - timer_set(attotime::zero, TIMER_CHECK_IRQ); + m_irq_sync_timer->adjust(attotime::zero); } u8 vic_pl190_device::protection_r() @@ -124,7 +279,7 @@ void vic_pl190_device::cur_vect_addr_w(u32 data) { priority_mask = ~0; priority = ~0; - timer_set(attotime::zero, TIMER_CHECK_IRQ); + m_irq_sync_timer->adjust(attotime::zero); } u32 vic_pl190_device::def_vect_addr_r() @@ -194,114 +349,12 @@ void vic_pl190_device::update_vector() vicaddress = defaddress; } -void vic_pl190_device::map(address_map &map) -{ - map(0x000, 0x003).r(FUNC(vic_pl190_device::irq_status_r)); - map(0x004, 0x007).r(FUNC(vic_pl190_device::fiq_status_r)); - map(0x008, 0x00b).r(FUNC(vic_pl190_device::raw_intr_r)); - map(0x00c, 0x00f).rw(FUNC(vic_pl190_device::int_select_r), FUNC(vic_pl190_device::int_select_w)); - map(0x010, 0x013).rw(FUNC(vic_pl190_device::int_enable_r), FUNC(vic_pl190_device::int_enable_w)); - map(0x014, 0x017).w(FUNC(vic_pl190_device::int_en_clear_w)); - map(0x018, 0x01b).rw(FUNC(vic_pl190_device::soft_int_r), FUNC(vic_pl190_device::soft_int_w)); - map(0x01c, 0x01f).w(FUNC(vic_pl190_device::soft_int_clear_w)); - map(0x020, 0x020).rw(FUNC(vic_pl190_device::protection_r), FUNC(vic_pl190_device::protection_w)).umask32(0x000000ff); - map(0x030, 0x033).rw(FUNC(vic_pl190_device::cur_vect_addr_r), FUNC(vic_pl190_device::cur_vect_addr_w)); - map(0x034, 0x037).rw(FUNC(vic_pl190_device::def_vect_addr_r), FUNC(vic_pl190_device::def_vect_addr_w)); - map(0x100, 0x13f).rw(FUNC(vic_pl190_device::vect_addr_r), FUNC(vic_pl190_device::vect_addr_w)); - map(0x200, 0x23f).rw(FUNC(vic_pl190_device::vect_ctl_r), FUNC(vic_pl190_device::vect_ctl_w)); - map(0xfe0, 0xfe0).lr8([this](offs_t offset){ return periph_id[0]; }, "periph_id0").umask32(0x000000ff); - map(0xfe4, 0xfe4).lr8([this](offs_t offset){ return periph_id[1]; }, "periph_id1").umask32(0x000000ff); - map(0xfe8, 0xfe8).lr8([this](offs_t offset){ return periph_id[2]; }, "periph_id2").umask32(0x000000ff); - map(0xfec, 0xfec).lr8([this](offs_t offset){ return periph_id[3]; }, "periph_id3").umask32(0x000000ff); - map(0xff0, 0xff0).lr8([this](offs_t offset){ return pcell_id[0]; }, "pcell_id0").umask32(0x000000ff); - map(0xff4, 0xff4).lr8([this](offs_t offset){ return pcell_id[1]; }, "pcell_id1").umask32(0x000000ff); - map(0xff8, 0xff8).lr8([this](offs_t offset){ return pcell_id[2]; }, "pcell_id2").umask32(0x000000ff); - map(0xffc, 0xffc).lr8([this](offs_t offset){ return pcell_id[3]; }, "pcell_id3").umask32(0x000000ff); -} - -device_memory_interface::space_config_vector vic_pl190_device::memory_space_config() const -{ - return space_config_vector{ - std::make_pair(0, &m_mmio_config) - }; -} - -void vic_pl190_device::device_resolve_objects() -{ - // resolve callbacks - m_out_irq_func.resolve_safe(); - m_out_fiq_func.resolve_safe(); -} - -void vic_pl190_device::device_start() -{ - save_item(NAME(raw_intr)); - save_item(NAME(intr_select)); - save_item(NAME(intr_en)); - save_item(NAME(soft_intr)); - save_item(NAME(vectaddr)); - save_item(NAME(defaddress)); - save_item(NAME(vicaddress)); - save_item(NAME(priority_mask)); - save_item(NAME(priority)); - save_item(NAME(protection)); -} - -void vic_pl190_device::device_reset() -{ - raw_intr = intr_select = intr_en = soft_intr = 0; - defaddress = vicaddress = protection = 0; - - priority_mask = ~0; - priority = ~0; - - for(int i = 0; i < 32; i++) - { - vectaddr[i] = 0; - vectctl[i] = 0; - } -} - -vic_pl190_device::vic_pl190_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock) - : device_t(mconfig, type, tag, owner, clock) - , device_memory_interface(mconfig, *this) - , num_vectors(16) - , periph_id{0x92, 0x11, 0x04, 0x00} - , pcell_id{0x0d, 0xf0, 0x05, 0xb1} - , m_mmio_config("mmio", ENDIANNESS_LITTLE, 32, 32, 0) - , m_out_irq_func(*this) - , m_out_fiq_func(*this) -{ -} - -vic_pl190_device::vic_pl190_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) - : vic_pl190_device(mconfig, PL190_VIC, tag, owner, clock) -{ -} - - - - void vic_upd800468_device::int_clear_w(u32 data) { raw_intr &= ~data; - timer_set(attotime::zero, TIMER_CHECK_IRQ); -} - -void vic_upd800468_device::map(address_map &map) -{ - vic_pl190_device::map(map); - - map(0x100, 0x17f).rw(FUNC(vic_pl190_device::vect_addr_r), FUNC(vic_pl190_device::vect_addr_w)); - map(0x200, 0x27f).rw(FUNC(vic_pl190_device::vect_ctl_r), FUNC(vic_pl190_device::vect_ctl_w)); - map(0x2c8, 0x2cb).w(FUNC(vic_upd800468_device::int_clear_w)); + m_irq_sync_timer->adjust(attotime::zero); } -vic_upd800468_device::vic_upd800468_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) - : vic_pl190_device(mconfig, UPD800468_VIC, tag, owner, clock) -{ - num_vectors = 32; -} @@ -354,56 +407,3 @@ void vic_pl192_device::update_vector() } priority_mask = newmask; } - -void vic_pl192_device::map(address_map &map) -{ - map(0x000, 0x003).r(FUNC(vic_pl190_device::irq_status_r)); - map(0x004, 0x007).r(FUNC(vic_pl190_device::fiq_status_r)); - map(0x008, 0x00b).r(FUNC(vic_pl190_device::raw_intr_r)); - map(0x00c, 0x00f).rw(FUNC(vic_pl190_device::int_select_r), FUNC(vic_pl190_device::int_select_w)); - map(0x010, 0x013).rw(FUNC(vic_pl190_device::int_enable_r), FUNC(vic_pl190_device::int_enable_w)); - map(0x014, 0x017).w(FUNC(vic_pl190_device::int_en_clear_w)); - map(0x018, 0x01b).rw(FUNC(vic_pl190_device::soft_int_r), FUNC(vic_pl190_device::soft_int_w)); - map(0x01c, 0x01f).w(FUNC(vic_pl190_device::soft_int_clear_w)); - map(0x020, 0x020).rw(FUNC(vic_pl190_device::protection_r), FUNC(vic_pl190_device::protection_w)).umask32(0x000000ff); - map(0x024, 0x025).rw(FUNC(vic_pl192_device::sw_priority_r), FUNC(vic_pl192_device::sw_priority_w)).umask32(0x0000ffff); - map(0x028, 0x028).rw(FUNC(vic_pl192_device::daisy_priority_r), FUNC(vic_pl192_device::daisy_priority_w)).umask32(0x000000ff); - map(0x100, 0x17f).rw(FUNC(vic_pl190_device::vect_addr_r), FUNC(vic_pl190_device::vect_addr_w)); - map(0x200, 0x27f).rw(FUNC(vic_pl190_device::vect_ctl_r), FUNC(vic_pl190_device::vect_ctl_w)); - map(0xf00, 0xf03).rw(FUNC(vic_pl190_device::cur_vect_addr_r), FUNC(vic_pl190_device::cur_vect_addr_w)); - map(0xfe0, 0xfe0).lr8([this](offs_t offset) { return periph_id[0]; }, "periph_id0").umask32(0x000000ff); - map(0xfe4, 0xfe4).lr8([this](offs_t offset) { return periph_id[1]; }, "periph_id1").umask32(0x000000ff); - map(0xfe8, 0xfe8).lr8([this](offs_t offset) { return periph_id[2]; }, "periph_id2").umask32(0x000000ff); - map(0xfec, 0xfec).lr8([this](offs_t offset) { return periph_id[3]; }, "periph_id3").umask32(0x000000ff); - map(0xff0, 0xff0).lr8([this](offs_t offset) { return pcell_id[0]; }, "pcell_id0").umask32(0x000000ff); - map(0xff4, 0xff4).lr8([this](offs_t offset) { return pcell_id[1]; }, "pcell_id1").umask32(0x000000ff); - map(0xff8, 0xff8).lr8([this](offs_t offset) { return pcell_id[2]; }, "pcell_id2").umask32(0x000000ff); - map(0xffc, 0xffc).lr8([this](offs_t offset) { return pcell_id[3]; }, "pcell_id3").umask32(0x000000ff); -} - -void vic_pl192_device::device_start() -{ - vic_pl190_device::device_start(); - - save_item(NAME(sw_priority_mask)); - save_item(NAME(daisy_priority)); -} - -void vic_pl192_device::device_reset() -{ - vic_pl190_device::device_reset(); - - sw_priority_mask = 0xffff; - daisy_priority = 0xf; - - for (int i = 0; i < 32; i++) - { - vectctl[i] = 0xf; - } -} - -vic_pl192_device::vic_pl192_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) - : vic_pl190_device(mconfig, PL192_VIC, tag, owner, clock) -{ - num_vectors = 32; -} diff --git a/src/devices/machine/vic_pl192.h b/src/devices/machine/vic_pl192.h index 01c58e9d241..6ef01a3a935 100644 --- a/src/devices/machine/vic_pl192.h +++ b/src/devices/machine/vic_pl192.h @@ -50,12 +50,19 @@ public: void vect_ctl_w(offs_t offset, u32 data); protected: - static constexpr device_timer_id TIMER_CHECK_IRQ = 0; - vic_pl190_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock); + // device-level overrides + virtual void device_start() override; + virtual void device_reset() override; + virtual void device_resolve_objects() override; + + virtual space_config_vector memory_space_config() const override; + virtual void update_vector(); + TIMER_CALLBACK_MEMBER(irq_sync_tick); + u8 num_vectors; // number of available vectored interrupts u32 raw_intr, intr_select, intr_en, soft_intr; @@ -66,13 +73,7 @@ protected: u8 priority; // priority level of the current interrupt, if any u8 periph_id[4], pcell_id[4]; - // device-level overrides - 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; + emu_timer *m_irq_sync_timer; private: void set_irq_line(int irq, int state); diff --git a/src/devices/machine/vrc4373.cpp b/src/devices/machine/vrc4373.cpp index d0dbb96e55a..1100df8b375 100644 --- a/src/devices/machine/vrc4373.cpp +++ b/src/devices/machine/vrc4373.cpp @@ -151,7 +151,7 @@ void vrc4373_device::device_start() m_cpu->add_fastram(0x1fc00000, 0x1fcfffff, true, m_romRegion->base()); // DMA timer - m_dma_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(vrc4373_device::dma_transfer), this)); + m_dma_timer = timer_alloc(FUNC(vrc4373_device::dma_transfer), this); // Leave the timer disabled. m_dma_timer->adjust(attotime::never, 0, DMA_TIMER_PERIOD); diff --git a/src/devices/machine/vrc5074.cpp b/src/devices/machine/vrc5074.cpp index a2e1c0ea061..e812cf20d25 100644 --- a/src/devices/machine/vrc5074.cpp +++ b/src/devices/machine/vrc5074.cpp @@ -230,14 +230,14 @@ void vrc5074_device::device_start() m_cpu->add_fastram(0x1fc00000, 0x1fcfffff, true, m_romRegion->base()); // DMA timer - m_dma_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(vrc5074_device::dma_transfer), this)); + m_dma_timer = timer_alloc(FUNC(vrc5074_device::dma_transfer), this); // Leave the timer disabled. m_dma_timer->adjust(attotime::never, 0, DMA_TIMER_PERIOD); /* allocate timers for the NILE */ m_timer[0] = machine().scheduler().timer_alloc(timer_expired_delegate()); m_timer[1] = machine().scheduler().timer_alloc(timer_expired_delegate()); - m_timer[2] = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(vrc5074_device::nile_timer_callback), this)); - m_timer[3] = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(vrc5074_device::nile_timer_callback), this)); + m_timer[2] = timer_alloc(FUNC(vrc5074_device::nile_timer_callback), this); + m_timer[3] = timer_alloc(FUNC(vrc5074_device::nile_timer_callback), this); // Save states // m_sdram diff --git a/src/devices/machine/vrender0.cpp b/src/devices/machine/vrender0.cpp index c4e1c3ce5e1..f59edbe4a2e 100644 --- a/src/devices/machine/vrender0.cpp +++ b/src/devices/machine/vrender0.cpp @@ -164,10 +164,10 @@ void vrender0soc_device::device_start() if (this->clock() == 0) fatalerror("%s: bus clock not setup properly",this->tag()); - m_Timer[0] = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(vrender0soc_device::Timercb<0>),this)); - m_Timer[1] = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(vrender0soc_device::Timercb<1>),this)); - m_Timer[2] = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(vrender0soc_device::Timercb<2>),this)); - m_Timer[3] = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(vrender0soc_device::Timercb<3>),this)); + m_Timer[0] = timer_alloc(FUNC(vrender0soc_device::Timercb<0>), this); + m_Timer[1] = timer_alloc(FUNC(vrender0soc_device::Timercb<1>), this); + m_Timer[2] = timer_alloc(FUNC(vrender0soc_device::Timercb<2>), this); + m_Timer[3] = timer_alloc(FUNC(vrender0soc_device::Timercb<3>), this); write_tx.resolve_all_safe(); diff --git a/src/devices/machine/watchdog.cpp b/src/devices/machine/watchdog.cpp index 01f363b0a28..3d7e17178d4 100644 --- a/src/devices/machine/watchdog.cpp +++ b/src/devices/machine/watchdog.cpp @@ -60,7 +60,7 @@ void watchdog_timer_device::device_start() { // initialize the watchdog m_counter = 0; - m_timer = timer_alloc(); + m_timer = timer_alloc(FUNC(watchdog_timer_device::watchdog_expired), this); if (m_vblank_count != 0) { @@ -87,10 +87,10 @@ void watchdog_timer_device::device_reset() //------------------------------------------------- -// device_timer - handle timer expiration events +// watchdog_expired - handle expired timer //------------------------------------------------- -void watchdog_timer_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(watchdog_timer_device::watchdog_expired) { watchdog_fired(); } diff --git a/src/devices/machine/watchdog.h b/src/devices/machine/watchdog.h index a140b13e319..aaeed0fa494 100644 --- a/src/devices/machine/watchdog.h +++ b/src/devices/machine/watchdog.h @@ -42,7 +42,8 @@ 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; + + TIMER_CALLBACK_MEMBER(watchdog_expired); private: // internal helpers diff --git a/src/devices/machine/wd1000.cpp b/src/devices/machine/wd1000.cpp index dcb620720e5..848c368e6b6 100644 --- a/src/devices/machine/wd1000.cpp +++ b/src/devices/machine/wd1000.cpp @@ -62,8 +62,8 @@ void wd1000_device::device_start() m_drq_cb.resolve(); // Allocate timers - m_seek_timer = timer_alloc(TIMER_SEEK); - m_drq_timer = timer_alloc(TIMER_DRQ); + m_seek_timer = timer_alloc(FUNC(wd1000_device::update_seek), this); + m_drq_timer = timer_alloc(FUNC(wd1000_device::delayed_drq), this); // Empty buffer. m_buffer_index = 0; @@ -111,49 +111,47 @@ void wd1000_device::device_reset() } //------------------------------------------------- -// device_timer - device-specific timer +// update_seek - //------------------------------------------------- -void wd1000_device::device_timer(emu_timer &timer, device_timer_id tid, int param) +TIMER_CALLBACK_MEMBER(wd1000_device::update_seek) { - switch (tid) - { - case TIMER_SEEK: - - m_drive_cylinder[drive()] = param; - m_status |= S_SC; - - switch (m_command >> 4) - { - case CMD_RESTORE: - cmd_restore(); - break; - - case CMD_SEEK: - cmd_seek(); - break; + m_drive_cylinder[drive()] = param; + m_status |= S_SC; - case CMD_READ_SECTOR: - cmd_read_sector(); - break; + switch (m_command >> 4) + { + case CMD_RESTORE: + cmd_restore(); + break; - case CMD_WRITE_SECTOR: - cmd_write_sector(); - break; + case CMD_SEEK: + cmd_seek(); + break; - case CMD_WRITE_FORMAT: - cmd_format_sector(); - break; - } + case CMD_READ_SECTOR: + cmd_read_sector(); + break; + case CMD_WRITE_SECTOR: + cmd_write_sector(); break; - case TIMER_DRQ: - set_drq(); + case CMD_WRITE_FORMAT: + cmd_format_sector(); break; } } +//------------------------------------------------- +// delayed_drq - set DRQ after a necessary delay +//------------------------------------------------- + +TIMER_CALLBACK_MEMBER(wd1000_device::delayed_drq) +{ + set_drq(); +} + void wd1000_device::set_error(int error) { if (error) diff --git a/src/devices/machine/wd1000.h b/src/devices/machine/wd1000.h index 6b12f325b1c..4e2882ee81c 100644 --- a/src/devices/machine/wd1000.h +++ b/src/devices/machine/wd1000.h @@ -45,7 +45,9 @@ protected: // device-level overrides virtual void device_start() override; virtual void device_reset() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; + + TIMER_CALLBACK_MEMBER(update_seek); + TIMER_CALLBACK_MEMBER(delayed_drq); private: enum @@ -77,12 +79,6 @@ private: CMD_SEEK = 7 }; - enum - { - TIMER_SEEK, - TIMER_DRQ, - }; - void set_error(int error); void set_intrq(int state); void set_drq(); diff --git a/src/devices/machine/wd1010.cpp b/src/devices/machine/wd1010.cpp index 859b5bbe2bf..cef0b5d9dd2 100644 --- a/src/devices/machine/wd1010.cpp +++ b/src/devices/machine/wd1010.cpp @@ -96,9 +96,9 @@ void wd1010_device::device_start() m_out_data_cb.resolve_safe(); // allocate timer - m_seek_timer = timer_alloc(TIMER_SEEK); - m_read_timer = timer_alloc(TIMER_READ); - m_write_timer = timer_alloc(TIMER_WRITE); + m_seek_timer = timer_alloc(FUNC(wd1010_device::update_seek), this); + m_read_timer = timer_alloc(FUNC(wd1010_device::delayed_read), this); + m_write_timer = timer_alloc(FUNC(wd1010_device::delayed_write), this); // register for save states save_item(NAME(m_intrq)); @@ -124,59 +124,62 @@ void wd1010_device::device_reset() } //------------------------------------------------- -// device_timer - device-specific timer +// update_seek - //------------------------------------------------- -void wd1010_device::device_timer(emu_timer &timer, device_timer_id tid, int param) +TIMER_CALLBACK_MEMBER(wd1010_device::update_seek) { - switch (tid) + if ((m_command >> 4) != CMD_SCAN_ID) { - case TIMER_SEEK: - - if ((m_command >> 4) != CMD_SCAN_ID) - { - LOGSEEK("Seek complete\n"); - m_drives[drive()].cylinder = param; - m_status |= STATUS_SC; - } + LOGSEEK("Seek complete\n"); + m_drives[drive()].cylinder = param; + m_status |= STATUS_SC; + } - switch (m_command >> 4) - { - case CMD_RESTORE: - cmd_restore(); - break; - - case CMD_SEEK: - cmd_seek(); - break; - - case CMD_READ_SECTOR: - cmd_read_sector(); - break; - - case CMD_WRITE_SECTOR: - case CMD_WRITE_FORMAT: - cmd_write_sector(); - break; - - case CMD_SCAN_ID: - cmd_scan_id(); - break; - } + switch (m_command >> 4) + { + case CMD_RESTORE: + cmd_restore(); + break; + case CMD_SEEK: + cmd_seek(); break; - case TIMER_READ: + case CMD_READ_SECTOR: cmd_read_sector(); break; - case TIMER_WRITE: + case CMD_WRITE_SECTOR: + case CMD_WRITE_FORMAT: cmd_write_sector(); break; + + case CMD_SCAN_ID: + cmd_scan_id(); + break; } } //------------------------------------------------- +// delayed_read - +//------------------------------------------------- + +TIMER_CALLBACK_MEMBER(wd1010_device::delayed_read) +{ + cmd_read_sector(); +} + +//------------------------------------------------- +// delayed_write - +//------------------------------------------------- + +TIMER_CALLBACK_MEMBER(wd1010_device::delayed_write) +{ + cmd_write_sector(); +} + +//------------------------------------------------- // set_error - set error and adjust status //------------------------------------------------- diff --git a/src/devices/machine/wd1010.h b/src/devices/machine/wd1010.h index 980c0518f32..70d8a687163 100644 --- a/src/devices/machine/wd1010.h +++ b/src/devices/machine/wd1010.h @@ -54,7 +54,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(update_seek); + TIMER_CALLBACK_MEMBER(delayed_read); + TIMER_CALLBACK_MEMBER(delayed_write); private: enum @@ -91,13 +94,6 @@ private: CMD_SEEK = 7 }; - enum - { - TIMER_SEEK, - TIMER_READ, - TIMER_WRITE - }; - void set_error(int error); void set_intrq(int state); void set_bdrq(int state); diff --git a/src/devices/machine/wd2010.cpp b/src/devices/machine/wd2010.cpp index fd4fbac41a1..840d0f6f4d8 100644 --- a/src/devices/machine/wd2010.cpp +++ b/src/devices/machine/wd2010.cpp @@ -202,18 +202,12 @@ void wd2010_device::device_start() m_in_sc_cb.resolve_safe(0); /* allocate a timer for commands */ - cmd_timer = timer_alloc(0); - complete_write_when_buffer_ready_high = timer_alloc(1); - deassert_write_when_buffer_ready_low = timer_alloc(2); - deassert_read_when_buffer_ready_high = timer_alloc(3); + m_cmd_timer = timer_alloc(FUNC(wd2010_device::command_complete), this); + m_complete_write_timer = timer_alloc(FUNC(wd2010_device::complete_write), this); + m_deassert_write_timer = timer_alloc(FUNC(wd2010_device::deassert_write), this); + m_deassert_read_timer = timer_alloc(FUNC(wd2010_device::deassert_read), this); } -// timers -#define COMMAND_TIMER 0 -#define COMPLETE_WRITE_SECTOR 1 -#define DE_ASSERT_WRITE 2 -#define DE_ASSERT_READ 3 - //------------------------------------------------- // device_reset - device-specific reset @@ -430,7 +424,7 @@ void wd2010_device::restore(uint8_t data) // NOTE: calculation needs 'data' (extracted from command register) float step_ms = SETTLING_MS + LATENCY_MS + ( (float)sqrt(1.0 * step_pulses) * STEP_RATE_MS ); - cmd_timer->adjust(attotime::from_usec(1000 * step_ms), newstatus); + m_cmd_timer->adjust(attotime::from_usec(1000 * step_ms), newstatus); return; } @@ -532,7 +526,7 @@ void wd2010_device::seek(uint8_t data) m_task_file[TASK_FILE_CYLINDER_LOW] = (m_present_cylinder - ((m_task_file[TASK_FILE_CYLINDER_HIGH] << 8) )) & 0xff; //LOGERROR("SEEK (END) - m_present_cylinder = %u SDH CYL L/H %02x / %02x\n", m_present_cylinder,m_task_file[TASK_FILE_CYLINDER_LOW],m_task_file[TASK_FILE_CYLINDER_HIGH]); - cmd_timer->adjust(attotime::from_usec(1000 * step_ms), newstatus); + m_cmd_timer->adjust(attotime::from_usec(1000 * step_ms), newstatus); } //------------------------------------------------- @@ -644,7 +638,7 @@ void wd2010_device::read_sector(uint8_t data) // NOTE : (intrq_at_end = 0) - INTRQ occurs when the command is completed newstatus |= (m_status & ~(STATUS_CIP | STATUS_DRQ)) | intrq_at_end; // de-assert CIP + DRQ (BSY already reset) - deassert_read_when_buffer_ready_high->adjust(attotime::from_usec(1), newstatus); // complete command ON *RISING EDGE * OF BUFFER_READY + m_deassert_read_timer->adjust(attotime::from_usec(1), newstatus); // complete command ON *RISING EDGE * OF BUFFER_READY } @@ -671,7 +665,7 @@ void wd2010_device::write_sector(uint8_t data) m_out_bdrq_cb(1); // WAIT UNTIL BRDY ASSERTED (-> timer): - complete_write_when_buffer_ready_high->adjust(attotime::from_usec(1), data); // 1 usec + m_complete_write_timer->adjust(attotime::from_usec(1), data); // 1 usec } @@ -728,7 +722,7 @@ void wd2010_device::complete_write_sector(uint8_t data) } // -------------------------------------------------------- // 'complete_cmd' ON THE FALLING EDGE OF _BUFFER_READY_ ( set by WRITE_SECTOR ) ! - deassert_write_when_buffer_ready_low->adjust(attotime::from_usec(1), newstatus); + m_deassert_write_timer->adjust(attotime::from_usec(1), newstatus); } // ****************************************************** @@ -862,7 +856,7 @@ void wd2010_device::format(uint8_t data) m_out_wg_cb(0); // (transition from WG 1 -> 0). Actual write. // ** DELAY INTRQ UNTIL WRITE IS COMPLETE : - complete_write_when_buffer_ready_high->adjust(attotime::from_usec(1), newstatus | STATUS_DRQ); // 1 USECs + m_complete_write_timer->adjust(attotime::from_usec(1), newstatus | STATUS_DRQ); // 1 USECs } @@ -875,65 +869,63 @@ void wd2010_device::buffer_ready(bool state) } -void wd2010_device::device_timer(emu_timer &timer, device_timer_id tid, int param) +TIMER_CALLBACK_MEMBER(wd2010_device::command_complete) { - switch (tid) - { - case COMMAND_TIMER: - cmd_timer->adjust(attotime::never); - complete_immediate(param); - break; - - case COMPLETE_WRITE_SECTOR: // when BUFFER_READY -> HIGH - if (is_buffer_ready) - { - complete_write_when_buffer_ready_high->adjust(attotime::never); - complete_write_sector(param); - } - else - { - complete_write_when_buffer_ready_high->reset(); - complete_write_when_buffer_ready_high->adjust(attotime::from_usec(1), param); // DELAY ANOTHER 1 USEC (!) - } - break; + m_cmd_timer->adjust(attotime::never); + complete_immediate(param); +} - case DE_ASSERT_WRITE: // waiting for BUFFER_READY -> LOW - if (!(is_buffer_ready)) - { - deassert_write_when_buffer_ready_low->adjust(attotime::never); - complete_immediate(param); - } - else - { - deassert_write_when_buffer_ready_low->reset(); - deassert_write_when_buffer_ready_low->adjust(attotime::from_usec(1), param); // DELAY ANOTHER 1 USEC (!) - } - break; +TIMER_CALLBACK_MEMBER(wd2010_device::complete_write) +{ + // when BUFFER_READY -> HIGH + if (is_buffer_ready) + { + m_complete_write_timer->adjust(attotime::never); + complete_write_sector(param); + } + else + { + m_complete_write_timer->reset(); + m_complete_write_timer->adjust(attotime::from_usec(1), param); // DELAY ANOTHER 1 USEC (!) + } +} - case DE_ASSERT_READ: // when BUFFER_READY -> HIGH - if (is_buffer_ready) - { - deassert_read_when_buffer_ready_high->adjust(attotime::never); +TIMER_CALLBACK_MEMBER(wd2010_device::deassert_write) +{ + // waiting for BUFFER_READY -> LOW + if (!(is_buffer_ready)) + { + m_deassert_write_timer->adjust(attotime::never); + complete_immediate(param); + } + else + { + m_deassert_write_timer->reset(); + m_deassert_write_timer->adjust(attotime::from_usec(1), param); // DELAY ANOTHER 1 USEC (!) + } +} - m_error &= ~ERROR_ID; - param &= ~STATUS_ERR; +TIMER_CALLBACK_MEMBER(wd2010_device::deassert_read) +{ + // when BUFFER_READY -> HIGH + if (is_buffer_ready) + { + m_deassert_read_timer->adjust(attotime::never); - m_out_bdrq_cb(0); - complete_immediate(param); - } - else - { - deassert_read_when_buffer_ready_high->reset(); - deassert_read_when_buffer_ready_high->adjust(attotime::from_usec(1), param); // DELAY ANOTHER 1 USEC (!) - } - break; + m_error &= ~ERROR_ID; + param &= ~STATUS_ERR; - default: - break; + m_out_bdrq_cb(0); + complete_immediate(param); + } + else + { + m_deassert_read_timer->reset(); + m_deassert_read_timer->adjust(attotime::from_usec(1), param); // DELAY ANOTHER 1 USEC (!) } } -// Called by 'device_timer' - +// Called by timer callbacks - void wd2010_device::complete_immediate(uint8_t status) { // re-evaluate external signals at end of command @@ -964,5 +956,5 @@ void wd2010_device::complete_immediate(uint8_t status) void wd2010_device::complete_cmd(uint8_t status) { - cmd_timer->adjust(attotime::from_msec(1), status); + m_cmd_timer->adjust(attotime::from_msec(1), status); } diff --git a/src/devices/machine/wd2010.h b/src/devices/machine/wd2010.h index 5f5acc6ebfd..a39935326ba 100644 --- a/src/devices/machine/wd2010.h +++ b/src/devices/machine/wd2010.h @@ -50,7 +50,10 @@ 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(command_complete); + TIMER_CALLBACK_MEMBER(complete_write); + TIMER_CALLBACK_MEMBER(deassert_write); + TIMER_CALLBACK_MEMBER(deassert_read); private: void compute_correction(uint8_t data); @@ -84,10 +87,10 @@ private: uint8_t m_error; uint8_t m_task_file[8]; - emu_timer *cmd_timer; - emu_timer *complete_write_when_buffer_ready_high; - emu_timer *deassert_write_when_buffer_ready_low; - emu_timer *deassert_read_when_buffer_ready_high; + emu_timer *m_cmd_timer; + emu_timer *m_complete_write_timer; + emu_timer *m_deassert_write_timer; + emu_timer *m_deassert_read_timer; void complete_write_sector(uint8_t status); void complete_cmd(uint8_t status); diff --git a/src/devices/machine/wd33c9x.cpp b/src/devices/machine/wd33c9x.cpp index dd7fa07a7c4..cb59256cea1 100644 --- a/src/devices/machine/wd33c9x.cpp +++ b/src/devices/machine/wd33c9x.cpp @@ -390,7 +390,7 @@ void wd33c9x_base_device::device_start() { m_irq_cb.resolve_safe(); m_drq_cb.resolve_safe(); - m_timer = timer_alloc(0); + m_timer = timer_alloc(FUNC(wd33c9x_base_device::update_step), this); save_item(NAME(m_addr)); save_item(NAME(m_regs)); save_item(NAME(m_command_length)); @@ -443,10 +443,10 @@ void wd33c9x_base_device::device_reset() //------------------------------------------------- -// device_timer - device-specific timer handler +// update_step - //------------------------------------------------- -void wd33c9x_base_device::device_timer(emu_timer &timer, device_timer_id tid, int param) +TIMER_CALLBACK_MEMBER(wd33c9x_base_device::update_step) { step(true); } diff --git a/src/devices/machine/wd33c9x.h b/src/devices/machine/wd33c9x.h index fcc3e50051a..8fb9e8ea78a 100644 --- a/src/devices/machine/wd33c9x.h +++ b/src/devices/machine/wd33c9x.h @@ -43,7 +43,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(update_step); virtual void scsi_ctrl_changed() override; diff --git a/src/devices/machine/wd_fdc.cpp b/src/devices/machine/wd_fdc.cpp index fa1b4013f49..c942f0b82c2 100644 --- a/src/devices/machine/wd_fdc.cpp +++ b/src/devices/machine/wd_fdc.cpp @@ -175,10 +175,10 @@ void wd_fdc_device_base::device_start() if (!has_enmf && !enmf_cb.isnull()) logerror("Warning, this chip doesn't have an ENMF line.\n"); - t_gen = timer_alloc(TM_GEN); - t_cmd = timer_alloc(TM_CMD); - t_track = timer_alloc(TM_TRACK); - t_sector = timer_alloc(TM_SECTOR); + t_gen = timer_alloc(FUNC(wd_fdc_device_base::generic_tick), this); + t_cmd = timer_alloc(FUNC(wd_fdc_device_base::cmd_w_tick), this); + t_track = timer_alloc(FUNC(wd_fdc_device_base::track_w_tick), this); + t_sector = timer_alloc(FUNC(wd_fdc_device_base::sector_w_tick), this); dden = disable_mfm; enmf = false; floppy = nullptr; @@ -315,18 +315,35 @@ WRITE_LINE_MEMBER(wd_fdc_device_base::dden_w) } } -void wd_fdc_device_base::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(wd_fdc_device_base::generic_tick) { - LOGEVENT("Event fired for timer %s\n", (id==TM_GEN)? "TM_GEN" : (id==TM_CMD)? "TM_CMD" : (id==TM_TRACK)? "TM_TRACK" : "TM_SECTOR"); + LOGEVENT("Event fired for TM_GEN\n"); live_sync(); + do_generic(); + general_continue(); +} - switch(id) { - case TM_GEN: do_generic(); break; - case TM_CMD: do_cmd_w(); break; - case TM_TRACK: do_track_w(); break; - case TM_SECTOR: do_sector_w(); break; - } +TIMER_CALLBACK_MEMBER(wd_fdc_device_base::cmd_w_tick) +{ + LOGEVENT("Event fired for TM_CMD\n"); + live_sync(); + do_cmd_w(); + general_continue(); +} +TIMER_CALLBACK_MEMBER(wd_fdc_device_base::track_w_tick) +{ + LOGEVENT("Event fired for TM_TRACK\n"); + live_sync(); + do_track_w(); + general_continue(); +} + +TIMER_CALLBACK_MEMBER(wd_fdc_device_base::sector_w_tick) +{ + LOGEVENT("Event fired for TM_SECTOR\n"); + live_sync(); + do_sector_w(); general_continue(); } diff --git a/src/devices/machine/wd_fdc.h b/src/devices/machine/wd_fdc.h index c205bfe3afd..8cb047b4518 100644 --- a/src/devices/machine/wd_fdc.h +++ b/src/devices/machine/wd_fdc.h @@ -117,7 +117,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; virtual int calc_sector_size(uint8_t size, uint8_t command) const; virtual int settle_time() const; @@ -131,9 +130,12 @@ protected: virtual void pll_save_checkpoint() = 0; virtual void pll_retrieve_checkpoint() = 0; -private: - enum { TM_GEN, TM_CMD, TM_TRACK, TM_SECTOR }; + TIMER_CALLBACK_MEMBER(generic_tick); + TIMER_CALLBACK_MEMBER(cmd_w_tick); + TIMER_CALLBACK_MEMBER(track_w_tick); + TIMER_CALLBACK_MEMBER(sector_w_tick); +private: // State machine general behaviour: // // There are three levels of state. diff --git a/src/devices/machine/wozfdc.cpp b/src/devices/machine/wozfdc.cpp index 9b3aa213dbf..bb28baba13e 100644 --- a/src/devices/machine/wozfdc.cpp +++ b/src/devices/machine/wozfdc.cpp @@ -79,8 +79,8 @@ void wozfdc_device::device_start() { m_rom_p6 = machine().root_device().memregion(this->subtag(DISKII_P6_REGION).c_str())->base(); - timer = timer_alloc(0); - delay_timer = timer_alloc(1); + timer = timer_alloc(FUNC(wozfdc_device::generic_tick), this); + delay_timer = timer_alloc(FUNC(wozfdc_device::delayed_tick), this); save_item(NAME(last_6502_write)); save_item(NAME(mode_write)); @@ -178,12 +178,18 @@ void appleiii_fdc_device::device_reset() enable1 = 1; } -void wozfdc_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(wozfdc_device::generic_tick) +{ + if(active) + lss_sync(); +} + +TIMER_CALLBACK_MEMBER(wozfdc_device::delayed_tick) { if(active) lss_sync(); - if(id == 1 && active == MODE_DELAY) { + if(active == MODE_DELAY) { if(floppy) floppy->mon_w(true); active = MODE_IDLE; diff --git a/src/devices/machine/wozfdc.h b/src/devices/machine/wozfdc.h index ad638ec16f0..f92ccaec39f 100644 --- a/src/devices/machine/wozfdc.h +++ b/src/devices/machine/wozfdc.h @@ -39,7 +39,9 @@ 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(generic_tick); + TIMER_CALLBACK_MEMBER(delayed_tick); void control(int offset); void set_phase(uint8_t data); diff --git a/src/devices/machine/ym2148.cpp b/src/devices/machine/ym2148.cpp index bc07d809f19..88f7db02b1e 100644 --- a/src/devices/machine/ym2148.cpp +++ b/src/devices/machine/ym2148.cpp @@ -45,7 +45,7 @@ void ym2148_device::device_start() // Start a timer to trigger at clock / 8 / 16 const attotime rate = clocks_to_attotime(8 * 16); - m_timer = timer_alloc(0); + m_timer = timer_alloc(FUNC(ym2148_device::serial_clock_tick), this); m_timer->adjust(rate, 0, rate); } @@ -136,7 +136,7 @@ void ym2148_device::update_irq() } -void ym2148_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(ym2148_device::serial_clock_tick) { receive_clock(); transmit_clock(); diff --git a/src/devices/machine/ym2148.h b/src/devices/machine/ym2148.h index 70130ce3f5d..07cacfbc589 100644 --- a/src/devices/machine/ym2148.h +++ b/src/devices/machine/ym2148.h @@ -40,7 +40,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(serial_clock_tick); private: devcb_write_line m_txd_handler; diff --git a/src/devices/machine/ym3802.cpp b/src/devices/machine/ym3802.cpp index 85a0bea0292..4a8f6a7ffae 100644 --- a/src/devices/machine/ym3802.cpp +++ b/src/devices/machine/ym3802.cpp @@ -30,17 +30,16 @@ ym3802_device::ym3802_device(const machine_config &mconfig, const char *tag, dev , m_vector(0) , m_clkm_rate(500000) // TODO: make these configurable , m_clkf_rate(614400) - { - } +{ +} void ym3802_device::device_start() { m_irq_handler.resolve_safe(); m_txd_handler.resolve_safe(); m_rxd_handler.resolve_safe(0xff); - m_clock_timer = timer_alloc(TIMER_SYSTEM_CLOCK); - m_midi_timer = timer_alloc(TIMER_TX_CLOCK); - m_midi_counter_timer = timer_alloc(TIMER_MIDI_CLOCK); + m_midi_timer = timer_alloc(FUNC(ym3802_device::transmit_clk), this); + m_midi_counter_timer = timer_alloc(FUNC(ym3802_device::midi_clk), this); save_item(NAME(m_reg)); } @@ -54,20 +53,6 @@ void ym3802_device::device_reset() set_comms_mode(); } -void ym3802_device::device_timer(emu_timer &timer, device_timer_id id, int param) -{ - // TODO: support clock and timers - switch(id) - { - case TIMER_TX_CLOCK: - transmit_clk(); - break; - case TIMER_MIDI_CLOCK: - midi_clk(); - break; - } -} - void ym3802_device::set_irq(uint8_t irq) { uint8_t x; @@ -90,7 +75,7 @@ void ym3802_device::reset_irq(uint8_t irq) m_irq_handler(CLEAR_LINE); } -void ym3802_device::transmit_clk() +TIMER_CALLBACK_MEMBER(ym3802_device::transmit_clk) { if(m_reg[REG_TCR] & 0x01) // Tx Enable { @@ -116,7 +101,7 @@ void ym3802_device::transmit_clk() } } -void ym3802_device::midi_clk() +TIMER_CALLBACK_MEMBER(ym3802_device::midi_clk) { if(m_midi_counter_base > 1) // counter is not guaranteed to work if set to 0 or 1. { diff --git a/src/devices/machine/ym3802.h b/src/devices/machine/ym3802.h index 05adada6b4f..00e6683ed25 100644 --- a/src/devices/machine/ym3802.h +++ b/src/devices/machine/ym3802.h @@ -3,7 +3,10 @@ /* * ym3802.h - Yamaha YM3802/YM3523 MCS MIDI Communication and Service Controller * - * * Registers: + * CLK input - anywhere from 1MHz up to 4MHz + * CLKM input - usually either 1MHz or 0.5MHz, or CLKF input - usually 614.4kHz + * + * Registers: * reg0 : IVR (read-only) * reg1 : RGR (bit 8 = reset, bits 0-3 = register bank select) * reg2 : ISR (read-only) @@ -26,7 +29,7 @@ class ym3802_device : public device_t, public device_serial_interface { public: - // construction/destruction + // construction/destruction ym3802_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock); // configuration helpers @@ -41,7 +44,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; private: enum @@ -118,15 +120,8 @@ private: IRQ_GENERAL_TIMER = 0x80 }; - enum - { - TIMER_SYSTEM_CLOCK = 0x200, // CLK input - anywhere from 1MHz up to 4MHz - TIMER_TX_CLOCK, - TIMER_MIDI_CLOCK // CLKM input - usually either 1MHz or 0.5MHz, or CLKF input - usually 614.4kHz - }; - - void transmit_clk(); - void midi_clk(); + TIMER_CALLBACK_MEMBER(transmit_clk); + TIMER_CALLBACK_MEMBER(midi_clk); void reset_midi_timer(); void set_comms_mode(); void set_irq(uint8_t irq); @@ -135,7 +130,6 @@ private: devcb_write_line m_irq_handler; devcb_write_line m_txd_handler; devcb_read_line m_rxd_handler; - emu_timer* m_clock_timer; emu_timer* m_midi_timer; emu_timer* m_midi_counter_timer; diff --git a/src/devices/machine/z8038.cpp b/src/devices/machine/z8038.cpp index e8e8203049b..699c43898ca 100644 --- a/src/devices/machine/z8038.cpp +++ b/src/devices/machine/z8038.cpp @@ -91,7 +91,7 @@ void z8038_device::device_start() //save_item(NAME(m_fifo)); - m_int_check = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(z8038_device::int_check), this)); + m_int_check = timer_alloc(FUNC(z8038_device::int_check), this); // suppress startup interrupt line changes m_port[0].int_asserted = false; diff --git a/src/devices/machine/z80ctc.cpp b/src/devices/machine/z80ctc.cpp index 3dbd8b25ad1..6a6e728d548 100644 --- a/src/devices/machine/z80ctc.cpp +++ b/src/devices/machine/z80ctc.cpp @@ -308,8 +308,8 @@ z80ctc_channel_device::z80ctc_channel_device(const machine_config &mconfig, cons void z80ctc_channel_device::device_start() { // initialize state - m_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(z80ctc_channel_device::timer_callback), this)); - m_zc_to_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(z80ctc_channel_device::zc_to_callback), this)); + m_timer = timer_alloc(FUNC(z80ctc_channel_device::timer_callback), this); + m_zc_to_timer = timer_alloc(FUNC(z80ctc_channel_device::zc_to_callback), this); // register for save states save_item(NAME(m_mode)); diff --git a/src/devices/machine/z80dma.cpp b/src/devices/machine/z80dma.cpp index 38148ff6350..65da965144e 100644 --- a/src/devices/machine/z80dma.cpp +++ b/src/devices/machine/z80dma.cpp @@ -181,7 +181,7 @@ void z80dma_device::device_start() m_out_iorq_cb.resolve_safe(); // allocate timer - m_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(z80dma_device::timerproc), this)); + m_timer = timer_alloc(FUNC(z80dma_device::timerproc), this); // register for state saving save_item(NAME(m_regs)); diff --git a/src/devices/machine/z80scc.cpp b/src/devices/machine/z80scc.cpp index 731571602d6..746bc7ee757 100644 --- a/src/devices/machine/z80scc.cpp +++ b/src/devices/machine/z80scc.cpp @@ -1072,7 +1072,7 @@ void z80scc_channel::device_start() m_rxc = 0x00; m_txc = 0x00; - m_baudtimer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(z80scc_channel::brg_tick), this)); + m_baudtimer = timer_alloc(FUNC(z80scc_channel::brg_tick), this); // state saving save_item(NAME(m_rr0)); diff --git a/src/devices/machine/z80sio.cpp b/src/devices/machine/z80sio.cpp index 5095dd4cb9b..8306c48bab4 100644 --- a/src/devices/machine/z80sio.cpp +++ b/src/devices/machine/z80sio.cpp @@ -1087,7 +1087,7 @@ void mk68564_channel::device_start() { z80sio_channel::device_start(); - m_brg_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(mk68564_channel::brg_timeout), this)); + m_brg_timer = timer_alloc(FUNC(mk68564_channel::brg_timeout), this); save_item(NAME(m_tx_auto_enable)); save_item(NAME(m_brg_tc)); diff --git a/src/devices/machine/z80sti.cpp b/src/devices/machine/z80sti.cpp index f049c3d19fa..a72a370ec79 100644 --- a/src/devices/machine/z80sti.cpp +++ b/src/devices/machine/z80sti.cpp @@ -121,10 +121,10 @@ void z80sti_device::device_start() m_out_tdo_cb.resolve_safe(); // create the counter timers - m_timer[TIMER_A] = timer_alloc(TIMER_A); - m_timer[TIMER_B] = timer_alloc(TIMER_B); - m_timer[TIMER_C] = timer_alloc(TIMER_C); - m_timer[TIMER_D] = timer_alloc(TIMER_D); + m_timer[TIMER_A] = timer_alloc(FUNC(z80sti_device::timer_count), this); + m_timer[TIMER_B] = timer_alloc(FUNC(z80sti_device::timer_count), this); + m_timer[TIMER_C] = timer_alloc(FUNC(z80sti_device::timer_count), this); + m_timer[TIMER_D] = timer_alloc(FUNC(z80sti_device::timer_count), this); // create serial receive clock timer if (m_rx_clock > 0) @@ -176,16 +176,6 @@ void z80sti_device::device_reset() //------------------------------------------------- -// device_timer - handler timer events -//------------------------------------------------- - -void z80sti_device::device_timer(emu_timer &timer, device_timer_id id, int param) -{ - timer_count(id); -} - - -//------------------------------------------------- // tra_callback - //------------------------------------------------- @@ -618,46 +608,46 @@ void z80sti_device::write(offs_t offset, uint8_t data) // timer_count - timer count down //------------------------------------------------- -void z80sti_device::timer_count(int index) +TIMER_CALLBACK_MEMBER(z80sti_device::timer_count) { - if (m_tmc[index] == 0x01) + if (m_tmc[param] == 0x01) { - //LOG("Z80STI Timer %c Expired\n", 'A' + index); + //LOG("Z80STI Timer %c Expired\n", 'A' + param); // toggle timer output signal - m_to[index] = !m_to[index]; + m_to[param] = !m_to[param]; - switch (index) + switch (param) { case TIMER_A: - m_out_tao_cb(m_to[index]); + m_out_tao_cb(m_to[param]); break; case TIMER_B: - m_out_tbo_cb(m_to[index]); + m_out_tbo_cb(m_to[param]); break; case TIMER_C: - m_out_tco_cb(m_to[index]); + m_out_tco_cb(m_to[param]); break; case TIMER_D: - m_out_tdo_cb(m_to[index]); + m_out_tdo_cb(m_to[param]); break; } - if (m_ier & (1 << INT_LEVEL_TIMER[index])) + if (m_ier & (1 << INT_LEVEL_TIMER[param])) { - LOG("Z80STI for Timer %c\n", 'A' + index); + LOG("Z80STI for Timer %c\n", 'A' + param); // signal timer elapsed interrupt - take_interrupt(INT_LEVEL_TIMER[index]); + take_interrupt(INT_LEVEL_TIMER[param]); } // load timer main counter - m_tmc[index] = m_tdr[index]; + m_tmc[param] = m_tdr[param]; } else { // count down - m_tmc[index]--; + m_tmc[param]--; } } diff --git a/src/devices/machine/z80sti.h b/src/devices/machine/z80sti.h index 2d5dba0f397..9cd0ff40d59 100644 --- a/src/devices/machine/z80sti.h +++ b/src/devices/machine/z80sti.h @@ -148,7 +148,6 @@ private: // 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_serial_interface overrides virtual void tra_callback() override; @@ -163,7 +162,7 @@ private: // internal helpers void check_interrupts(); void take_interrupt(int level); - void timer_count(int index); + TIMER_CALLBACK_MEMBER(timer_count); void gpip_input(int bit, int state); // device callbacks diff --git a/src/devices/machine/z8536.cpp b/src/devices/machine/z8536.cpp index e95dfe7574a..c30868d0dbb 100644 --- a/src/devices/machine/z8536.cpp +++ b/src/devices/machine/z8536.cpp @@ -564,7 +564,7 @@ void cio_base_device::write_register(offs_t offset, u8 data, u8 mask) // counter_enabled - is counter enabled? //------------------------------------------------- -bool cio_base_device::counter_enabled(device_timer_id id) +bool cio_base_device::counter_enabled(int id) { bool enabled = false; @@ -591,7 +591,7 @@ bool cio_base_device::counter_enabled(device_timer_id id) // counter_external_output - //------------------------------------------------- -bool cio_base_device::counter_external_output(device_timer_id id) +bool cio_base_device::counter_external_output(int id) { return (m_register[COUNTER_TIMER_1_MODE_SPECIFICATION + id] & CTMS_EOE) ? true : false; } @@ -601,7 +601,7 @@ bool cio_base_device::counter_external_output(device_timer_id id) // counter_external_count - //------------------------------------------------- -bool cio_base_device::counter_external_count(device_timer_id id) +bool cio_base_device::counter_external_count(int id) { return (m_register[COUNTER_TIMER_1_MODE_SPECIFICATION + id] & CTMS_ECE) ? true : false; } @@ -611,7 +611,7 @@ bool cio_base_device::counter_external_count(device_timer_id id) // counter_external_trigger - //------------------------------------------------- -bool cio_base_device::counter_external_trigger(device_timer_id id) +bool cio_base_device::counter_external_trigger(int id) { return (m_register[COUNTER_TIMER_1_MODE_SPECIFICATION + id] & CTMS_ETE) ? true : false; } @@ -621,7 +621,7 @@ bool cio_base_device::counter_external_trigger(device_timer_id id) // counter_external_gate - //------------------------------------------------- -bool cio_base_device::counter_external_gate(device_timer_id id) +bool cio_base_device::counter_external_gate(int id) { return (m_register[COUNTER_TIMER_1_MODE_SPECIFICATION + id] & CTMS_EDE) ? true : false; } @@ -631,7 +631,7 @@ bool cio_base_device::counter_external_gate(device_timer_id id) // counter_gated - //------------------------------------------------- -bool cio_base_device::counter_gated(device_timer_id id) +bool cio_base_device::counter_gated(int id) { return (m_register[COUNTER_TIMER_1_COMMAND_AND_STATUS + id] & CTCS_GCB) ? true : false; } @@ -641,7 +641,7 @@ bool cio_base_device::counter_gated(device_timer_id id) // count - count down //------------------------------------------------- -void cio_base_device::count(device_timer_id id) +void cio_base_device::count(int id) { if (!counter_gated(id)) return; if (!(m_register[COUNTER_TIMER_1_COMMAND_AND_STATUS + id] & CTCS_CIP)) return; @@ -686,7 +686,7 @@ void cio_base_device::count(device_timer_id id) // trigger - //------------------------------------------------- -void cio_base_device::trigger(device_timer_id id) +void cio_base_device::trigger(int id) { // ignore triggers during countdown if retrigger is disabled if (!(m_register[COUNTER_TIMER_1_MODE_SPECIFICATION + id] & CTMS_REB) && (m_register[COUNTER_TIMER_1_COMMAND_AND_STATUS + id] & CTCS_CIP)) return; @@ -705,7 +705,7 @@ void cio_base_device::trigger(device_timer_id id) // gate - //------------------------------------------------- -void cio_base_device::gate(device_timer_id id, int state) +void cio_base_device::gate(int id, int state) { // TODO } @@ -826,7 +826,7 @@ void cio_base_device::device_start() } // allocate timer - m_timer = timer_alloc(); + m_timer = timer_alloc(FUNC(cio_base_device::advance_counters), this); m_timer->adjust(attotime::from_hz(clock() / 2), 0, attotime::from_hz(clock() / 2)); // resolve callbacks @@ -885,10 +885,10 @@ void z8536_device::device_reset() //------------------------------------------------- -// device_timer - handler timer events +// advance_counters - //------------------------------------------------- -void cio_base_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(cio_base_device::advance_counters) { if (counter_enabled(TIMER_1) && !counter_external_count(TIMER_1)) { diff --git a/src/devices/machine/z8536.h b/src/devices/machine/z8536.h index 442b3e7a00f..382649a15f9 100644 --- a/src/devices/machine/z8536.h +++ b/src/devices/machine/z8536.h @@ -109,11 +109,12 @@ protected: // device-level overrides virtual void device_start() override; virtual void device_reset() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; + + TIMER_CALLBACK_MEMBER(advance_counters); bool is_reset() const { return (m_register[MASTER_INTERRUPT_CONTROL] & MICR_RESET) != 0; } - enum + enum : int { TIMER_1 = 0, TIMER_2, @@ -121,7 +122,7 @@ protected: }; // ports - enum + enum : int { PORT_A = 0, PORT_B, @@ -369,15 +370,15 @@ protected: void write_register(offs_t offset, u8 data); void write_register(offs_t offset, u8 data, u8 mask); - bool counter_enabled(device_timer_id id); - bool counter_external_output(device_timer_id id); - bool counter_external_count(device_timer_id id); - bool counter_external_trigger(device_timer_id id); - bool counter_external_gate(device_timer_id id); - bool counter_gated(device_timer_id id); - void count(device_timer_id id); - void trigger(device_timer_id id); - void gate(device_timer_id id, int state); + bool counter_enabled(int id); + bool counter_external_output(int id); + bool counter_external_count(int id); + bool counter_external_trigger(int id); + bool counter_external_gate(int id); + bool counter_gated(int id); + void count(int id); + void trigger(int id); + void gate(int id, int state); void match_pattern(int port); void external_port_w(int port, int bit, int state); diff --git a/src/devices/sound/ad1848.cpp b/src/devices/sound/ad1848.cpp index 414edc6ecb0..7c62b4912ef 100644 --- a/src/devices/sound/ad1848.cpp +++ b/src/devices/sound/ad1848.cpp @@ -32,7 +32,7 @@ void ad1848_device::device_add_mconfig(machine_config &config) void ad1848_device::device_start() { - m_timer = timer_alloc(0); + m_timer = timer_alloc(FUNC(ad1848_device::update_tick), this); m_irq_cb.resolve_safe(); m_drq_cb.resolve_safe(); save_item(NAME(m_regs.idx)); @@ -156,7 +156,7 @@ void ad1848_device::dack_w(uint8_t data) m_drq_cb(CLEAR_LINE); } -void ad1848_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(ad1848_device::update_tick) { if(!m_play) return; diff --git a/src/devices/sound/ad1848.h b/src/devices/sound/ad1848.h index ad50c964556..1fd354c3427 100644 --- a/src/devices/sound/ad1848.h +++ b/src/devices/sound/ad1848.h @@ -24,9 +24,9 @@ public: protected: virtual void device_start() override; virtual void device_reset() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; virtual void device_add_mconfig(machine_config &config) override; + TIMER_CALLBACK_MEMBER(update_tick); private: union { diff --git a/src/devices/sound/aica.cpp b/src/devices/sound/aica.cpp index 235ce7a5acc..a746f80eae0 100644 --- a/src/devices/sound/aica.cpp +++ b/src/devices/sound/aica.cpp @@ -444,9 +444,9 @@ void aica_device::Init() space().specific(m_DSP.space); space().cache(m_DSP.cache); - m_timerA = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(aica_device::timerA_cb), this)); - m_timerB = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(aica_device::timerB_cb), this)); - m_timerC = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(aica_device::timerC_cb), this)); + m_timerA = timer_alloc(FUNC(aica_device::timerA_cb), this); + m_timerB = timer_alloc(FUNC(aica_device::timerB_cb), this); + m_timerC = timer_alloc(FUNC(aica_device::timerC_cb), this); for (i = 0; i < 0x400; ++i) { diff --git a/src/devices/sound/asc.cpp b/src/devices/sound/asc.cpp index aee85be2d45..255d6043dcf 100644 --- a/src/devices/sound/asc.cpp +++ b/src/devices/sound/asc.cpp @@ -66,7 +66,7 @@ void asc_device::device_start() memset(m_regs, 0, sizeof(m_regs)); - m_timer = timer_alloc(0); + m_timer = timer_alloc(FUNC(asc_device::delayed_stream_update), this); save_item(NAME(m_fifo_a_rdptr)); save_item(NAME(m_fifo_b_rdptr)); @@ -104,10 +104,10 @@ void asc_device::device_reset() } //------------------------------------------------- -// device_timer - called when our device timer expires +// delayed_stream_update - //------------------------------------------------- -void asc_device::device_timer(emu_timer &timer, device_timer_id tid, int param) +TIMER_CALLBACK_MEMBER(asc_device::delayed_stream_update) { m_stream->update(); } diff --git a/src/devices/sound/asc.h b/src/devices/sound/asc.h index c6293366f1c..591c95d71af 100644 --- a/src/devices/sound/asc.h +++ b/src/devices/sound/asc.h @@ -76,10 +76,11 @@ protected: // device-level overrides virtual void device_start() override; virtual void device_reset() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; virtual void sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) override; + TIMER_CALLBACK_MEMBER(delayed_stream_update); + devcb_write_line write_irq; sound_stream *m_stream; diff --git a/src/devices/sound/bsmt2000.cpp b/src/devices/sound/bsmt2000.cpp index 5ffa2209c66..ee7e4e4ee86 100644 --- a/src/devices/sound/bsmt2000.cpp +++ b/src/devices/sound/bsmt2000.cpp @@ -126,6 +126,11 @@ void bsmt2000_device::device_start() save_item(NAME(m_left_data)); save_item(NAME(m_right_data)); save_item(NAME(m_write_pending)); + + // allocate timers + m_deferred_reset = timer_alloc(FUNC(bsmt2000_device::deferred_reset), this); + m_deferred_reg_write = timer_alloc(FUNC(bsmt2000_device::deferred_reg_write), this); + m_deferred_data_write = timer_alloc(FUNC(bsmt2000_device::deferred_data_write), this); } @@ -135,41 +140,47 @@ void bsmt2000_device::device_start() void bsmt2000_device::device_reset() { - synchronize(TIMER_ID_RESET); + m_deferred_reset->adjust(attotime::zero); +} + + + +//------------------------------------------------- +// deferred_reset - +//------------------------------------------------- + +TIMER_CALLBACK_MEMBER(bsmt2000_device::deferred_reset) +{ + m_stream->update(); + m_cpu->reset(); } //------------------------------------------------- -// device_timer - handle deferred writes and -// resets as a timer callback +// deferred_reg_write - //------------------------------------------------- -void bsmt2000_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(bsmt2000_device::deferred_reg_write) { - switch (id) - { - // deferred reset - case TIMER_ID_RESET: - m_stream->update(); - m_cpu->reset(); - break; - - // deferred register write - case TIMER_ID_REG_WRITE: - m_register_select = param & 0xffff; - break; - - // deferred data write - case TIMER_ID_DATA_WRITE: - m_write_data = param & 0xffff; - if (m_write_pending) logerror("BSMT2000: Missed data\n"); - m_write_pending = true; - break; - } + m_register_select = param & 0xffff; } + +//------------------------------------------------- +// deferred_data_write - +//------------------------------------------------- + +TIMER_CALLBACK_MEMBER(bsmt2000_device::deferred_data_write) +{ + m_write_data = param & 0xffff; + if (m_write_pending) logerror("BSMT2000: Missed data\n"); + m_write_pending = true; +} + + + //------------------------------------------------- // sound_stream_update - handle update requests // for our sound stream @@ -211,7 +222,7 @@ uint16_t bsmt2000_device::read_status() void bsmt2000_device::write_reg(uint16_t data) { - synchronize(TIMER_ID_REG_WRITE, data); + m_deferred_reg_write->adjust(attotime::zero, data); } @@ -222,7 +233,7 @@ void bsmt2000_device::write_reg(uint16_t data) void bsmt2000_device::write_data(uint16_t data) { - synchronize(TIMER_ID_DATA_WRITE, data); + m_deferred_data_write->adjust(attotime::zero, data); // boost the interleave on a write so that the caller detects the status more accurately machine().scheduler().boost_interleave(attotime::from_usec(1), attotime::from_usec(10)); diff --git a/src/devices/sound/bsmt2000.h b/src/devices/sound/bsmt2000.h index abf084d7ae1..777a06c8ac6 100644 --- a/src/devices/sound/bsmt2000.h +++ b/src/devices/sound/bsmt2000.h @@ -50,7 +50,6 @@ protected: virtual void device_add_mconfig(machine_config &config) override; virtual void device_start() override; virtual void device_reset() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; // device_sound_interface overrides virtual void sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) override; @@ -58,6 +57,10 @@ protected: // device_rom_interface overrides virtual void rom_bank_updated() override; + TIMER_CALLBACK_MEMBER(deferred_reset); + TIMER_CALLBACK_MEMBER(deferred_reg_write); + TIMER_CALLBACK_MEMBER(deferred_data_write); + public: // internal TMS I/O callbacks uint16_t tms_register_r(); @@ -72,7 +75,6 @@ private: // timers enum { - TIMER_ID_RESET, TIMER_ID_REG_WRITE, TIMER_ID_DATA_WRITE }; @@ -83,13 +85,16 @@ private: // internal state sound_stream * m_stream; required_device<tms32015_device> m_cpu; - uint16_t m_register_select; - uint16_t m_write_data; - uint16_t m_rom_address; - uint16_t m_rom_bank; - int16_t m_left_data; - int16_t m_right_data; + uint16_t m_register_select; + uint16_t m_write_data; + uint16_t m_rom_address; + uint16_t m_rom_bank; + int16_t m_left_data; + int16_t m_right_data; bool m_write_pending; + emu_timer * m_deferred_reset; + emu_timer * m_deferred_reg_write; + emu_timer * m_deferred_data_write; DECLARE_READ_LINE_MEMBER( tms_write_pending_r ); }; diff --git a/src/devices/sound/c140.cpp b/src/devices/sound/c140.cpp index b04a35a0f31..28eea0d508b 100644 --- a/src/devices/sound/c140.cpp +++ b/src/devices/sound/c140.cpp @@ -117,7 +117,7 @@ void c140_device::device_start() m_sample_rate = m_baserate = clock(); m_int1_callback.resolve_safe(); - m_int1_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(c140_device::int1_on), this)); + m_int1_timer = timer_alloc(FUNC(c140_device::int1_on), this); m_stream = stream_alloc(0, 2, m_sample_rate); diff --git a/src/devices/sound/cdp1864.cpp b/src/devices/sound/cdp1864.cpp index 87b5ea830d0..a3e8f5c037f 100644 --- a/src/devices/sound/cdp1864.cpp +++ b/src/devices/sound/cdp1864.cpp @@ -122,10 +122,9 @@ void cdp1864_device::device_start() m_stream = stream_alloc(0, 1, SAMPLE_RATE_OUTPUT_ADAPTIVE); // allocate timers - m_int_timer = timer_alloc(TIMER_INT); - m_efx_timer = timer_alloc(TIMER_EFX); - m_dma_timer = timer_alloc(TIMER_DMA); - m_hsync_timer = timer_alloc(TIMER_HSYNC); + m_int_timer = timer_alloc(FUNC(cdp1864_device::int_tick), this); + m_efx_timer = timer_alloc(FUNC(cdp1864_device::efx_tick), this); + m_dma_timer = timer_alloc(FUNC(cdp1864_device::dma_tick), this); // find devices screen().register_screen_bitmap(m_bitmap); @@ -163,91 +162,88 @@ void cdp1864_device::device_reset() //------------------------------------------------- -// device_timer - handle timer events +// timer events //------------------------------------------------- -void cdp1864_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(cdp1864_device::int_tick) { - int scanline = screen().vpos(); - - switch (id) + if (screen().vpos() == SCANLINE_INT_START) { - case TIMER_INT: - if (scanline == SCANLINE_INT_START) + if (m_disp) { - if (m_disp) - { - m_write_int(ASSERT_LINE); - } - - m_int_timer->adjust(screen().time_until_pos(SCANLINE_INT_END, 0)); + m_write_int(ASSERT_LINE); } - else - { - if (m_disp) - { - m_write_int(CLEAR_LINE); - } - m_int_timer->adjust(screen().time_until_pos(SCANLINE_INT_START, 0)); + m_int_timer->adjust(screen().time_until_pos(SCANLINE_INT_END, 0)); + } + else + { + if (m_disp) + { + m_write_int(CLEAR_LINE); } + + m_int_timer->adjust(screen().time_until_pos(SCANLINE_INT_START, 0)); + } +} + +TIMER_CALLBACK_MEMBER(cdp1864_device::efx_tick) +{ + int scanline = screen().vpos(); + switch (scanline) + { + case SCANLINE_EFX_TOP_START: + m_write_efx(ASSERT_LINE); + m_efx_timer->adjust(screen().time_until_pos(SCANLINE_EFX_TOP_END, 0)); break; - case TIMER_EFX: - switch (scanline) - { - case SCANLINE_EFX_TOP_START: - m_write_efx(ASSERT_LINE); - m_efx_timer->adjust(screen().time_until_pos(SCANLINE_EFX_TOP_END, 0)); - break; - - case SCANLINE_EFX_TOP_END: - m_write_efx(CLEAR_LINE); - m_efx_timer->adjust(screen().time_until_pos(SCANLINE_EFX_BOTTOM_START, 0)); - break; - - case SCANLINE_EFX_BOTTOM_START: - m_write_efx(ASSERT_LINE); - m_efx_timer->adjust(screen().time_until_pos(SCANLINE_EFX_BOTTOM_END, 0)); - break; - - case SCANLINE_EFX_BOTTOM_END: - m_write_efx(CLEAR_LINE); - m_efx_timer->adjust(screen().time_until_pos(SCANLINE_EFX_TOP_START, 0)); - break; - } + case SCANLINE_EFX_TOP_END: + m_write_efx(CLEAR_LINE); + m_efx_timer->adjust(screen().time_until_pos(SCANLINE_EFX_BOTTOM_START, 0)); + break; + + case SCANLINE_EFX_BOTTOM_START: + m_write_efx(ASSERT_LINE); + m_efx_timer->adjust(screen().time_until_pos(SCANLINE_EFX_BOTTOM_END, 0)); + break; + + case SCANLINE_EFX_BOTTOM_END: + m_write_efx(CLEAR_LINE); + m_efx_timer->adjust(screen().time_until_pos(SCANLINE_EFX_TOP_START, 0)); break; + } +} - case TIMER_DMA: - if (m_dmaout) +TIMER_CALLBACK_MEMBER(cdp1864_device::dma_tick) +{ + int scanline = screen().vpos(); + if (m_dmaout) + { + if (m_disp) { - if (m_disp) + if (scanline >= SCANLINE_DISPLAY_START && scanline < SCANLINE_DISPLAY_END) { - if (scanline >= SCANLINE_DISPLAY_START && scanline < SCANLINE_DISPLAY_END) - { - m_write_dma_out(CLEAR_LINE); - } + m_write_dma_out(CLEAR_LINE); } + } - m_dma_timer->adjust(clocks_to_attotime(CDP1864_CYCLES_DMA_WAIT)); + m_dma_timer->adjust(clocks_to_attotime(CDP1864_CYCLES_DMA_WAIT)); - m_dmaout = 0; - } - else + m_dmaout = 0; + } + else + { + if (m_disp) { - if (m_disp) + if (scanline >= SCANLINE_DISPLAY_START && scanline < SCANLINE_DISPLAY_END) { - if (scanline >= SCANLINE_DISPLAY_START && scanline < SCANLINE_DISPLAY_END) - { - m_write_dma_out(ASSERT_LINE); - } + m_write_dma_out(ASSERT_LINE); } + } - m_dma_timer->adjust(clocks_to_attotime(CDP1864_CYCLES_DMA_ACTIVE)); + m_dma_timer->adjust(clocks_to_attotime(CDP1864_CYCLES_DMA_ACTIVE)); - m_dmaout = 1; - } - break; + m_dmaout = 1; } } diff --git a/src/devices/sound/cdp1864.h b/src/devices/sound/cdp1864.h index db2bd156f3a..8dc1eb04e8e 100644 --- a/src/devices/sound/cdp1864.h +++ b/src/devices/sound/cdp1864.h @@ -112,20 +112,15 @@ protected: virtual void device_config_complete() override; virtual void device_start() override; virtual void device_reset() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; // internal callbacks virtual void sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) override; -private: - enum - { - TIMER_INT, - TIMER_EFX, - TIMER_DMA, - TIMER_HSYNC - }; + TIMER_CALLBACK_MEMBER(int_tick); + TIMER_CALLBACK_MEMBER(efx_tick); + TIMER_CALLBACK_MEMBER(dma_tick); +private: void initialize_palette(); static constexpr int bckgnd[4] = { 2, 0, 4, 1 }; @@ -164,7 +159,6 @@ private: emu_timer *m_int_timer; emu_timer *m_efx_timer; emu_timer *m_dma_timer; - emu_timer *m_hsync_timer; }; diff --git a/src/devices/sound/cdp1869.cpp b/src/devices/sound/cdp1869.cpp index ac7533ac316..70e4718f212 100644 --- a/src/devices/sound/cdp1869.cpp +++ b/src/devices/sound/cdp1869.cpp @@ -95,14 +95,36 @@ void cdp1869_device::cdp1869(address_map &map) //************************************************************************** -// INLINE HELPERS +// DEVICE FUNCTIONS //************************************************************************** //------------------------------------------------- +// get_rgb - get RGB value +//------------------------------------------------- + +rgb_t cdp1869_device::get_rgb(int i, int c, int l) +{ + int luma = 0; + + luma += (l & 4) ? CDP1869_WEIGHT_RED : 0; + luma += (l & 1) ? CDP1869_WEIGHT_GREEN : 0; + luma += (l & 2) ? CDP1869_WEIGHT_BLUE : 0; + + luma = (luma * 0xff) / 100; + + int const r = (c & 4) ? luma : 0; + int const g = (c & 1) ? luma : 0; + int const b = (c & 2) ? luma : 0; + + return rgb_t(r, g, b); +} + + +//------------------------------------------------- // is_ntsc - is device in NTSC mode //------------------------------------------------- -inline bool cdp1869_device::is_ntsc() +bool cdp1869_device::is_ntsc() { return m_read_pal_ntsc() ? false : true; } @@ -113,7 +135,7 @@ inline bool cdp1869_device::is_ntsc() // the given address //------------------------------------------------- -inline uint8_t cdp1869_device::read_page_ram_byte(offs_t pma) +uint8_t cdp1869_device::read_page_ram_byte(offs_t pma) { return space().read_byte(pma); } @@ -124,7 +146,7 @@ inline uint8_t cdp1869_device::read_page_ram_byte(offs_t pma) // the given address //------------------------------------------------- -inline void cdp1869_device::write_page_ram_byte(offs_t pma, uint8_t data) +void cdp1869_device::write_page_ram_byte(offs_t pma, uint8_t data) { space().write_byte(pma, data); } @@ -135,7 +157,7 @@ inline void cdp1869_device::write_page_ram_byte(offs_t pma, uint8_t data) // the given address //------------------------------------------------- -inline uint8_t cdp1869_device::read_char_ram_byte(offs_t pma, offs_t cma, uint8_t pmd) +uint8_t cdp1869_device::read_char_ram_byte(offs_t pma, offs_t cma, uint8_t pmd) { uint8_t data = 0; @@ -153,7 +175,7 @@ inline uint8_t cdp1869_device::read_char_ram_byte(offs_t pma, offs_t cma, uint8_ // the given address //------------------------------------------------- -inline void cdp1869_device::write_char_ram_byte(offs_t pma, offs_t cma, uint8_t pmd, uint8_t data) +void cdp1869_device::write_char_ram_byte(offs_t pma, offs_t cma, uint8_t pmd, uint8_t data) { if (!m_out_char_ram_func.isnull()) { @@ -166,7 +188,7 @@ inline void cdp1869_device::write_char_ram_byte(offs_t pma, offs_t cma, uint8_t // read_pcb - read page control bit //------------------------------------------------- -inline int cdp1869_device::read_pcb(offs_t pma, offs_t cma, uint8_t pmd) +int cdp1869_device::read_pcb(offs_t pma, offs_t cma, uint8_t pmd) { int pcb = 0; @@ -183,7 +205,7 @@ inline int cdp1869_device::read_pcb(offs_t pma, offs_t cma, uint8_t pmd) // update_prd_changed_timer - //------------------------------------------------- -inline void cdp1869_device::update_prd_changed_timer() +void cdp1869_device::update_prd_changed_timer() { int start = SCANLINE_PREDISPLAY_START_PAL; int end = SCANLINE_PREDISPLAY_END_PAL; @@ -224,32 +246,10 @@ inline void cdp1869_device::update_prd_changed_timer() //------------------------------------------------- -// get_rgb - get RGB value -//------------------------------------------------- - -inline rgb_t cdp1869_device::get_rgb(int i, int c, int l) -{ - int luma = 0; - - luma += (l & 4) ? CDP1869_WEIGHT_RED : 0; - luma += (l & 1) ? CDP1869_WEIGHT_GREEN : 0; - luma += (l & 2) ? CDP1869_WEIGHT_BLUE : 0; - - luma = (luma * 0xff) / 100; - - int const r = (c & 4) ? luma : 0; - int const g = (c & 1) ? luma : 0; - int const b = (c & 2) ? luma : 0; - - return rgb_t(r, g, b); -} - - -//------------------------------------------------- // get_lines - get number of character lines //------------------------------------------------- -inline int cdp1869_device::get_lines() +int cdp1869_device::get_lines() { if (m_line16 && !m_dblpage) { @@ -270,7 +270,7 @@ inline int cdp1869_device::get_lines() // get_pmemsize - get page memory size //------------------------------------------------- -inline uint16_t cdp1869_device::get_pmemsize(int cols, int rows) +uint16_t cdp1869_device::get_pmemsize(int cols, int rows) { int pmemsize = cols * rows; @@ -285,7 +285,7 @@ inline uint16_t cdp1869_device::get_pmemsize(int cols, int rows) // get_pma - get page memory address //------------------------------------------------- -inline uint16_t cdp1869_device::get_pma() +uint16_t cdp1869_device::get_pma() { if (m_dblpage) { @@ -302,7 +302,7 @@ inline uint16_t cdp1869_device::get_pma() // get_pen - get pen for color bits //------------------------------------------------- -inline int cdp1869_device::get_pen(int ccb0, int ccb1, int pcb) +int cdp1869_device::get_pen(int ccb0, int ccb1, int pcb) { int r = 0, g = 0, b = 0; @@ -392,7 +392,7 @@ void cdp1869_device::device_start() m_out_char_ram_func.resolve(); // allocate timers - m_prd_timer = timer_alloc(); + m_prd_timer = timer_alloc(FUNC(cdp1869_device::prd_update), this); m_dispoff = 0; update_prd_changed_timer(); @@ -456,10 +456,10 @@ void cdp1869_device::device_post_load() //------------------------------------------------- -// device_timer - handler timer events +// prd_update - //------------------------------------------------- -void cdp1869_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(cdp1869_device::prd_update) { m_write_prd(param); m_prd = param; diff --git a/src/devices/sound/cdp1869.h b/src/devices/sound/cdp1869.h index e40a9705333..6ce373a6931 100644 --- a/src/devices/sound/cdp1869.h +++ b/src/devices/sound/cdp1869.h @@ -210,7 +210,6 @@ protected: virtual void device_add_mconfig(machine_config &config) override; virtual void device_start() override; virtual void device_post_load() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; // device_memory_interface overrides virtual space_config_vector memory_space_config() const override; @@ -218,18 +217,21 @@ protected: // device_sound_interface callbacks virtual void sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) override; - inline bool is_ntsc(); - inline uint8_t read_page_ram_byte(offs_t address); - inline void write_page_ram_byte(offs_t address, uint8_t data); - inline uint8_t read_char_ram_byte(offs_t pma, offs_t cma, uint8_t pmd); - inline void write_char_ram_byte(offs_t pma, offs_t cma, uint8_t pmd, uint8_t data); - inline int read_pcb(offs_t pma, offs_t cma, uint8_t pmd); - inline void update_prd_changed_timer(); + TIMER_CALLBACK_MEMBER(prd_update); + static rgb_t get_rgb(int i, int c, int l); - inline int get_lines(); - inline uint16_t get_pmemsize(int cols, int rows); - inline uint16_t get_pma(); - inline int get_pen(int ccb0, int ccb1, int pcb); + + bool is_ntsc(); + uint8_t read_page_ram_byte(offs_t address); + void write_page_ram_byte(offs_t address, uint8_t data); + uint8_t read_char_ram_byte(offs_t pma, offs_t cma, uint8_t pmd); + void write_char_ram_byte(offs_t pma, offs_t cma, uint8_t pmd, uint8_t data); + int read_pcb(offs_t pma, offs_t cma, uint8_t pmd); + void update_prd_changed_timer(); + int get_lines(); + uint16_t get_pmemsize(int cols, int rows); + uint16_t get_pma(); + int get_pen(int ccb0, int ccb1, int pcb); void draw_line(bitmap_rgb32 &bitmap, const rectangle &rect, int x, int y, uint8_t data, int color); void draw_char(bitmap_rgb32 &bitmap, const rectangle &rect, int x, int y, uint16_t pma); diff --git a/src/devices/sound/dave.cpp b/src/devices/sound/dave.cpp index 8a7386e640b..44719ab4584 100644 --- a/src/devices/sound/dave.cpp +++ b/src/devices/sound/dave.cpp @@ -83,10 +83,10 @@ void dave_device::device_start() m_write_rh.resolve_safe(); // allocate timers - m_timer_1hz = timer_alloc(TIMER_1HZ); + m_timer_1hz = timer_alloc(FUNC(dave_device::update_1hz_timer), this); m_timer_1hz->adjust(attotime::from_hz(2), 0, attotime::from_hz(2)); - m_timer_50hz = timer_alloc(TIMER_50HZ); + m_timer_50hz = timer_alloc(FUNC(dave_device::update_50hz_timer), this); m_timer_50hz->adjust(attotime::from_hz(2000), 0, attotime::from_hz(2000)); // state saving @@ -146,27 +146,30 @@ void dave_device::device_reset() //------------------------------------------------- -// device_timer - handler timer events +// update_1hz_timer - //------------------------------------------------- -void dave_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(dave_device::update_1hz_timer) { - switch (id) - { - case TIMER_1HZ: - m_irq_status ^= IRQ_1HZ_DIVIDER; + m_irq_status ^= IRQ_1HZ_DIVIDER; - if (m_irq_status & IRQ_1HZ_DIVIDER) - m_irq_status |= IRQ_1HZ_LATCH; - break; + if (m_irq_status & IRQ_1HZ_DIVIDER) + m_irq_status |= IRQ_1HZ_LATCH; - case TIMER_50HZ: - m_irq_status ^= IRQ_50HZ_DIVIDER; + update_interrupt(); +} - if (m_irq_status & IRQ_50HZ_DIVIDER) - m_irq_status |= IRQ_50HZ_LATCH; - break; - } + +//------------------------------------------------- +// update_50hz_timer - +//------------------------------------------------- + +TIMER_CALLBACK_MEMBER(dave_device::update_50hz_timer) +{ + m_irq_status ^= IRQ_50HZ_DIVIDER; + + if (m_irq_status & IRQ_50HZ_DIVIDER) + m_irq_status |= IRQ_50HZ_LATCH; update_interrupt(); } diff --git a/src/devices/sound/dave.h b/src/devices/sound/dave.h index 7a6a521738f..82c024f748e 100644 --- a/src/devices/sound/dave.h +++ b/src/devices/sound/dave.h @@ -41,7 +41,6 @@ protected: // device-level overrides virtual void device_start() override; virtual void device_reset() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; // device_memory_interface overrides virtual space_config_vector memory_space_config() const override; @@ -49,6 +48,9 @@ protected: // sound stream update overrides virtual void sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) override; + TIMER_CALLBACK_MEMBER(update_1hz_timer); + TIMER_CALLBACK_MEMBER(update_50hz_timer); + uint8_t program_r(offs_t offset); void program_w(offs_t offset, uint8_t data); @@ -58,12 +60,6 @@ protected: private: enum { - TIMER_1HZ, - TIMER_50HZ - }; - - enum - { IRQ_50HZ_DIVIDER = 0x01, IRQ_50HZ_LATCH = 0x02, IRQ_1HZ_DIVIDER = 0x04, diff --git a/src/devices/sound/es1373.cpp b/src/devices/sound/es1373.cpp index d6baac9ad01..d254527b0bc 100644 --- a/src/devices/sound/es1373.cpp +++ b/src/devices/sound/es1373.cpp @@ -122,7 +122,7 @@ void es1373_device::device_start() // create the stream m_stream = stream_alloc(0, 2, 44100/2); - m_timer = timer_alloc(0); + m_timer = timer_alloc(FUNC(es1373_device::delayed_stream_update), this); m_timer->adjust(attotime::zero, 0, attotime::from_hz(44100/2/16)); // Save states @@ -222,9 +222,9 @@ void es1373_device::map_extra(uint64_t memory_window_start, uint64_t memory_wind } //------------------------------------------------- -// device_timer - called when our device timer expires +// delayed_stream_update - //------------------------------------------------- -void es1373_device::device_timer(emu_timer &timer, device_timer_id tid, int param) +TIMER_CALLBACK_MEMBER(es1373_device::delayed_stream_update) { m_stream->update(); } diff --git a/src/devices/sound/es1373.h b/src/devices/sound/es1373.h index ba246a05535..6d493391ae4 100644 --- a/src/devices/sound/es1373.h +++ b/src/devices/sound/es1373.h @@ -26,11 +26,12 @@ protected: virtual void device_start() override; virtual void device_stop() override; virtual void device_reset() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; virtual void device_add_mconfig(machine_config &config) override; virtual void device_post_load() override; virtual void sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) override; + TIMER_CALLBACK_MEMBER(delayed_stream_update); + // Sound stream sound_stream *m_stream; diff --git a/src/devices/sound/es5503.cpp b/src/devices/sound/es5503.cpp index 365254301b6..50bef4568d2 100644 --- a/src/devices/sound/es5503.cpp +++ b/src/devices/sound/es5503.cpp @@ -67,10 +67,10 @@ es5503_device::es5503_device(const machine_config &mconfig, const char *tag, dev //------------------------------------------------- -// device_timer - called when our device timer expires +// delayed_stream_update - //------------------------------------------------- -void es5503_device::device_timer(emu_timer &timer, device_timer_id tid, int param) +TIMER_CALLBACK_MEMBER(es5503_device::delayed_stream_update) { m_stream->update(); } @@ -235,7 +235,7 @@ void es5503_device::device_start() output_rate = (clock() / 8) / (oscsenabled + 2); m_stream = stream_alloc(0, output_channels, output_rate); - m_timer = timer_alloc(0); + m_timer = timer_alloc(FUNC(es5503_device::delayed_stream_update), this); } void es5503_device::device_clock_changed() diff --git a/src/devices/sound/es5503.h b/src/devices/sound/es5503.h index fde389ef250..153e0a79fe1 100644 --- a/src/devices/sound/es5503.h +++ b/src/devices/sound/es5503.h @@ -33,7 +33,6 @@ protected: virtual void device_start() override; virtual void device_clock_changed() override; virtual void device_reset() override; - virtual void device_timer(emu_timer &timer, device_timer_id tid, int param) override; // device_sound_interface overrides virtual void sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) override; @@ -41,6 +40,8 @@ protected: // device_rom_interface overrides virtual void rom_bank_updated() override; + TIMER_CALLBACK_MEMBER(delayed_stream_update); + sound_stream *m_stream; devcb_write_line m_irq_func; diff --git a/src/devices/sound/gb.cpp b/src/devices/sound/gb.cpp index a139b72ca3e..643ecf9ec68 100644 --- a/src/devices/sound/gb.cpp +++ b/src/devices/sound/gb.cpp @@ -143,7 +143,7 @@ cgb04_apu_device::cgb04_apu_device(const machine_config &mconfig, const char *ta void gameboy_sound_device::device_start() { m_channel = stream_alloc(0, 2, SAMPLE_RATE_OUTPUT_ADAPTIVE); - m_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(gameboy_sound_device::timer_callback),this)); + m_timer = timer_alloc(FUNC(gameboy_sound_device::timer_callback), this); m_timer->adjust(clocks_to_attotime(FRAME_CYCLES/128), 0, clocks_to_attotime(FRAME_CYCLES/128)); save_item(NAME(m_last_updated)); diff --git a/src/devices/sound/huc6230.cpp b/src/devices/sound/huc6230.cpp index ed297c36cf8..d257572f79e 100644 --- a/src/devices/sound/huc6230.cpp +++ b/src/devices/sound/huc6230.cpp @@ -181,7 +181,7 @@ void huc6230_device::device_start() m_vca_cb.resolve_safe(); m_stream = stream_alloc(2, 2, clock() / 6); - m_adpcm_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(huc6230_device::adpcm_timer),this)); + m_adpcm_timer = timer_alloc(FUNC(huc6230_device::adpcm_timer), this); for (int i = 0; i < 2; i++) { diff --git a/src/devices/sound/ics2115.cpp b/src/devices/sound/ics2115.cpp index 9eca1102f88..4b9f1ef152b 100644 --- a/src/devices/sound/ics2115.cpp +++ b/src/devices/sound/ics2115.cpp @@ -59,8 +59,8 @@ void ics2115_device::device_start() space(0).cache(m_cache); - m_timer[0].timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(ics2115_device::timer_cb_0),this)); - m_timer[1].timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(ics2115_device::timer_cb_1),this)); + m_timer[0].timer = timer_alloc(FUNC(ics2115_device::timer_cb_0), this); + m_timer[1].timer = timer_alloc(FUNC(ics2115_device::timer_cb_1), this); m_stream = stream_alloc(0, 2, clock() / (32 * 32)); m_irq_cb.resolve_safe(); diff --git a/src/devices/sound/iopspu.cpp b/src/devices/sound/iopspu.cpp index b2599eae2cd..55e6cd3b789 100644 --- a/src/devices/sound/iopspu.cpp +++ b/src/devices/sound/iopspu.cpp @@ -31,10 +31,10 @@ void iop_spu_device::device_start() m_ram = std::make_unique<uint16_t[]>(2 * 1024 * 1024); // ? if (!m_core[0].m_autodma_done_timer_hack) - m_core[0].m_autodma_done_timer_hack = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(iop_spu_device::autodma_done_timer_hack), this)); + m_core[0].m_autodma_done_timer_hack = timer_alloc(FUNC(iop_spu_device::autodma_done_timer_hack), this); if (!m_core[1].m_autodma_done_timer_hack) - m_core[1].m_autodma_done_timer_hack = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(iop_spu_device::autodma_done_timer_hack), this)); + m_core[1].m_autodma_done_timer_hack = timer_alloc(FUNC(iop_spu_device::autodma_done_timer_hack), this); save_item(NAME(m_core[0].m_status)); save_item(NAME(m_core[0].m_start_port_addr)); diff --git a/src/devices/sound/k053260.cpp b/src/devices/sound/k053260.cpp index b2e1e6cb0a0..9a85fa97811 100644 --- a/src/devices/sound/k053260.cpp +++ b/src/devices/sound/k053260.cpp @@ -126,7 +126,7 @@ void k053260_device::device_start() for (int i = 0; i < 4; i++) m_voice[i].voice_start(i); - m_timer = timer_alloc(0); + m_timer = timer_alloc(FUNC(k053260_device::update_state_outputs), this); } @@ -164,7 +164,7 @@ void k053260_device::rom_bank_updated() } -void k053260_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(k053260_device::update_state_outputs) { switch(m_timer_state) { case 0: m_sh1_cb(ASSERT_LINE); break; diff --git a/src/devices/sound/k053260.h b/src/devices/sound/k053260.h index dc8d918117e..401d3d2e34f 100644 --- a/src/devices/sound/k053260.h +++ b/src/devices/sound/k053260.h @@ -39,7 +39,6 @@ protected: virtual void device_start() override; virtual void device_clock_changed() override; virtual void device_reset() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; // sound stream update overrides virtual void sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) override; @@ -47,6 +46,8 @@ protected: // device_rom_interface overrides virtual void rom_bank_updated() override; + TIMER_CALLBACK_MEMBER(update_state_outputs); + private: // Pan multipliers static const int pan_mul[8][2]; diff --git a/src/devices/sound/k054539.cpp b/src/devices/sound/k054539.cpp index b30dbcbc724..ae0ac92e310 100644 --- a/src/devices/sound/k054539.cpp +++ b/src/devices/sound/k054539.cpp @@ -307,7 +307,7 @@ void k054539_device::sound_stream_update(sound_stream &stream, std::vector<read_ } -void k054539_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(k054539_device::call_timer_handler) { if (regs[0x22f] & 0x20) m_timer_handler(m_timer_state ^= 1); @@ -507,7 +507,7 @@ u8 k054539_device::read(offs_t offset) void k054539_device::device_start() { - m_timer = timer_alloc(0); + m_timer = timer_alloc(FUNC(k054539_device::call_timer_handler), this); // resolve / bind callbacks m_timer_handler.resolve_safe(); diff --git a/src/devices/sound/k054539.h b/src/devices/sound/k054539.h index c58f6021af3..406836af65a 100644 --- a/src/devices/sound/k054539.h +++ b/src/devices/sound/k054539.h @@ -64,7 +64,6 @@ protected: virtual void device_clock_changed() override; virtual void device_reset() override; virtual void device_post_load() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; // device_sound_interface overrides virtual void sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) override; @@ -72,6 +71,8 @@ protected: // device_rom_interface overrides virtual void rom_bank_updated() override; + TIMER_CALLBACK_MEMBER(call_timer_handler); + private: struct channel { uint32_t pos; diff --git a/src/devices/sound/ks0164.cpp b/src/devices/sound/ks0164.cpp index 99cb75ab878..f5c3c4d02e9 100644 --- a/src/devices/sound/ks0164.cpp +++ b/src/devices/sound/ks0164.cpp @@ -54,7 +54,7 @@ void ks0164_device::device_start() m_stream = stream_alloc(0, 2, clock()/3/2/2/32); space().cache(m_mem_cache); - m_timer = timer_alloc(0); + m_timer = timer_alloc(FUNC(ks0164_device::irq_timer_tick), this); m_midi_tx.resolve_safe(); @@ -98,7 +98,7 @@ void ks0164_device::device_reset() m_timer->adjust(attotime::from_msec(1), 0, attotime::from_msec(1)); } -void ks0164_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(ks0164_device::irq_timer_tick) { m_timer_interrupt = true; if(m_irqen_76 & 0x40) diff --git a/src/devices/sound/ks0164.h b/src/devices/sound/ks0164.h index 6024ae62669..208176c6e2e 100644 --- a/src/devices/sound/ks0164.h +++ b/src/devices/sound/ks0164.h @@ -30,12 +30,13 @@ protected: virtual void sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) override; virtual void device_add_mconfig(machine_config &config) override; virtual space_config_vector memory_space_config() const override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; virtual void tra_callback() override; virtual void tra_complete() override; virtual void rcv_complete() override; + TIMER_CALLBACK_MEMBER(irq_timer_tick); + private: enum { MPUS_RX_FULL = 0x01, diff --git a/src/devices/sound/mea8000.cpp b/src/devices/sound/mea8000.cpp index 3cf2ad51a6e..e557d046db4 100644 --- a/src/devices/sound/mea8000.cpp +++ b/src/devices/sound/mea8000.cpp @@ -137,7 +137,7 @@ void mea8000_device::device_start() m_stream = stream_alloc(0, 1, clock() / 60); save_item(NAME(m_output)); - m_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(mea8000_device::timer_expire),this)); + m_timer = timer_alloc(FUNC(mea8000_device::timer_expire), this); save_item(NAME(m_state)); save_item(NAME(m_buf)); diff --git a/src/devices/sound/mm5837.cpp b/src/devices/sound/mm5837.cpp index b9125b5c616..ae6687655f3 100644 --- a/src/devices/sound/mm5837.cpp +++ b/src/devices/sound/mm5837.cpp @@ -47,7 +47,7 @@ void mm5837_device::device_start() m_output_cb.resolve_safe(); // get timer - m_timer = timer_alloc(0); + m_timer = timer_alloc(FUNC(mm5837_device::update_clock_output), this); // register for save states save_item(NAME(m_source.m_shift)); @@ -70,10 +70,10 @@ void mm5837_device::device_reset() //------------------------------------------------- -// device_timer - handle timer callbacks +// update_clock_output - //------------------------------------------------- -void mm5837_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(mm5837_device::update_clock_output) { m_output_cb(m_source.clock()); } diff --git a/src/devices/sound/mm5837.h b/src/devices/sound/mm5837.h index 21d37596c45..df76f6171fd 100644 --- a/src/devices/sound/mm5837.h +++ b/src/devices/sound/mm5837.h @@ -168,7 +168,8 @@ protected: // device-level overrides virtual void device_start() override; virtual void device_reset() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; + + TIMER_CALLBACK_MEMBER(update_clock_output); private: // internal state diff --git a/src/devices/sound/mos6560.cpp b/src/devices/sound/mos6560.cpp index 1a007c80693..bd35429c31c 100644 --- a/src/devices/sound/mos6560.cpp +++ b/src/devices/sound/mos6560.cpp @@ -459,7 +459,7 @@ uint8_t mos6560_device::bus_r() mos6560_raster_interrupt_gen -------------------------------------------------*/ -void mos6560_device::raster_interrupt_gen() +TIMER_CALLBACK_MEMBER(mos6560_device::raster_interrupt_gen) { m_rasterline++; if (m_rasterline >= m_total_lines) @@ -760,7 +760,7 @@ void mos6560_device::device_start() } // allocate timers - m_line_timer = timer_alloc(TIMER_LINE); + m_line_timer = timer_alloc(FUNC(mos6560_device::raster_interrupt_gen), this); m_line_timer->adjust(screen().scan_period(), 0, screen().scan_period()); // initialize sound @@ -862,20 +862,6 @@ void mos6560_device::device_reset() //------------------------------------------------- -// device_timer - handler timer events -//------------------------------------------------- - -void mos6560_device::device_timer(emu_timer &timer, device_timer_id id, int param) -{ - switch (id) - { - case TIMER_LINE: - raster_interrupt_gen(); - break; - } -} - -//------------------------------------------------- // sound_stream_update - handle a stream update //------------------------------------------------- diff --git a/src/devices/sound/mos6560.h b/src/devices/sound/mos6560.h index eb902f5471e..fa950450389 100644 --- a/src/devices/sound/mos6560.h +++ b/src/devices/sound/mos6560.h @@ -121,7 +121,6 @@ protected: // device-level overrides virtual void device_start() override; virtual void device_reset() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; // sound stream update overrides virtual void sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) override; @@ -134,7 +133,7 @@ protected: void drawlines( int first, int last ); void soundport_w( int offset, int data ); void sound_start(); - void raster_interrupt_gen(); + TIMER_CALLBACK_MEMBER(raster_interrupt_gen); const int m_variant; diff --git a/src/devices/sound/mos7360.cpp b/src/devices/sound/mos7360.cpp index c4749b2fb9b..c76e1d8adb7 100644 --- a/src/devices/sound/mos7360.cpp +++ b/src/devices/sound/mos7360.cpp @@ -285,12 +285,12 @@ void mos7360_device::device_start() m_read_k.resolve_safe(0xff); // allocate timers - m_timer1 = timer_alloc(TIMER_ID_1); - m_timer2 = timer_alloc(TIMER_ID_2); - m_timer3 = timer_alloc(TIMER_ID_3); - m_line_timer = timer_alloc(TIMER_LINE); + m_timer[TIMER_ID_1] = timer_alloc(FUNC(mos7360_device::timer_expired), this); + m_timer[TIMER_ID_2] = timer_alloc(FUNC(mos7360_device::timer_expired), this); + m_timer[TIMER_ID_3] = timer_alloc(FUNC(mos7360_device::timer_expired), this); + m_line_timer = timer_alloc(FUNC(mos7360_device::raster_interrupt_gen), this); m_line_timer->adjust(screen().scan_period(), 0, screen().scan_period()); - m_frame_timer = timer_alloc(TIMER_FRAME); + m_frame_timer = timer_alloc(FUNC(mos7360_device::frame_interrupt_gen), this); m_frame_timer->adjust(screen().frame_period(), 0, screen().frame_period()); // allocate screen bitmap @@ -340,9 +340,7 @@ void mos7360_device::device_start() save_item(NAME(m_rom)); save_item(NAME(m_frame_count)); save_item(NAME(m_lines)); - save_item(NAME(m_timer1_active)); - save_item(NAME(m_timer2_active)); - save_item(NAME(m_timer3_active)); + save_item(NAME(m_timer_active)); save_item(NAME(m_cursor1)); save_item(NAME(m_chargenaddr)); save_item(NAME(m_bitmapaddr)); @@ -382,8 +380,10 @@ void mos7360_device::device_reset() m_rom = 1; // FIXME: at start should be RAM or ROM? old c16 code set it to ROM at init: is it correct? m_lines = TED7360_LINES; - m_chargenaddr = m_bitmapaddr = m_videoaddr = 0; - m_timer1_active = m_timer2_active = m_timer3_active = 0; + m_chargenaddr = 0; + m_bitmapaddr = 0; + m_videoaddr = 0; + std::fill(std::begin(m_timer_active), std::end(m_timer_active), false); m_cursor1 = 0; m_rasterline = 0; @@ -416,40 +416,25 @@ void mos7360_device::device_reset() //------------------------------------------------- -// device_timer - handler timer events +// timer_expired - //------------------------------------------------- -void mos7360_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(mos7360_device::timer_expired) { - switch (id) - { - case TIMER_ID_1: - // proved by digisound of several intros like eoroidpro - m_timer1->adjust(clocks_to_attotime(TIMER1), 1); - m_timer1_active = 1; - set_interrupt(0x08); - break; - - case TIMER_ID_2: - m_timer2->adjust(clocks_to_attotime(0x10000), 2); - m_timer2_active = 1; - set_interrupt(0x10); - break; - - case TIMER_ID_3: - m_timer3->adjust(clocks_to_attotime(0x10000), 3); - m_timer3_active = 1; - set_interrupt(0x40); - break; - - case TIMER_LINE: - raster_interrupt_gen(); - break; + static const uint8_t s_irq_values[3] = { 0x08, 0x10, 0x40 }; - case TIMER_FRAME: - frame_interrupt_gen(); - break; + if (param == TIMER_ID_1) + { + // proven by digital sound of several intros like eoroidpro + m_timer[param]->adjust(clocks_to_attotime(TIMER1), param); } + else + { + m_timer[param]->adjust(clocks_to_attotime(0x10000), param); + } + + m_timer_active[param] = true; + set_interrupt(s_irq_values[param]); } @@ -825,22 +810,22 @@ uint8_t mos7360_device::read(offs_t offset, int &cs0, int &cs1) switch (offset) { case 0xff00: - val = attotime_to_clocks(m_timer1->remaining()) & 0xff; + val = attotime_to_clocks(m_timer[0]->remaining()) & 0xff; break; case 0xff01: - val = attotime_to_clocks(m_timer1->remaining()) >> 8; + val = attotime_to_clocks(m_timer[0]->remaining()) >> 8; break; case 0xff02: - val = attotime_to_clocks(m_timer2->remaining()) & 0xff; + val = attotime_to_clocks(m_timer[1]->remaining()) & 0xff; break; case 0xff03: - val = attotime_to_clocks(m_timer2->remaining()) >> 8; + val = attotime_to_clocks(m_timer[1]->remaining()) >> 8; break; case 0xff04: - val = attotime_to_clocks(m_timer3->remaining()) & 0xff; + val = attotime_to_clocks(m_timer[2]->remaining()) & 0xff; break; case 0xff05: - val = attotime_to_clocks(m_timer3->remaining()) >> 8; + val = attotime_to_clocks(m_timer[2]->remaining()) >> 8; break; case 0xff07: val = (m_reg[offset & 0x1f] & ~0x40); @@ -922,45 +907,45 @@ void mos7360_device::write(offs_t offset, uint8_t data, int &cs0, int &cs1) case 0xff00: /* stop timer 1 */ m_reg[offset & 0x1f] = data; - if (m_timer1_active) + if (m_timer_active[0]) { - m_reg[1] = attotime_to_clocks(m_timer1->remaining()) >> 8; - m_timer1->reset(); - m_timer1_active = 0; + m_reg[1] = attotime_to_clocks(m_timer[0]->remaining()) >> 8; + m_timer[0]->reset(); + m_timer_active[0] = false; } break; case 0xff01: /* start timer 1 */ m_reg[offset & 0x1f] = data; - m_timer1->adjust(clocks_to_attotime(TIMER1), 1); - m_timer1_active = 1; + m_timer[0]->adjust(clocks_to_attotime(TIMER1), TIMER_ID_1); + m_timer_active[0] = true; break; case 0xff02: /* stop timer 2 */ m_reg[offset & 0x1f] = data; - if (m_timer2_active) + if (m_timer_active[1]) { - m_reg[3] = attotime_to_clocks(m_timer2->remaining()) >> 8; - m_timer2->reset(); - m_timer2_active = 0; + m_reg[3] = attotime_to_clocks(m_timer[1]->remaining()) >> 8; + m_timer[1]->reset(); + m_timer_active[1] = false; } break; case 0xff03: /* start timer 2 */ m_reg[offset & 0x1f] = data; - m_timer2->adjust(clocks_to_attotime(TIMER2), 2); - m_timer2_active = 1; + m_timer[1]->adjust(clocks_to_attotime(TIMER2), TIMER_ID_2); + m_timer_active[1] = true; break; case 0xff04: /* stop timer 3 */ m_reg[offset & 0x1f] = data; - if (m_timer3_active) + if (m_timer_active[2]) { - m_reg[5] = attotime_to_clocks(m_timer3->remaining()) >> 8; - m_timer3->reset(); - m_timer3_active = 0; + m_reg[5] = attotime_to_clocks(m_timer[2]->remaining()) >> 8; + m_timer[2]->reset(); + m_timer_active[2] = false; } break; case 0xff05: /* start timer 3 */ m_reg[offset & 0x1f] = data; - m_timer3->adjust(clocks_to_attotime(TIMER3), 3); - m_timer3_active = 1; + m_timer[2]->adjust(clocks_to_attotime(TIMER3), TIMER_ID_2); + m_timer_active[2] = true; break; case 0xff06: if (m_reg[offset & 0x1f] != data) @@ -1145,7 +1130,7 @@ uint32_t mos7360_device::screen_update(screen_device &screen, bitmap_rgb32 &bitm return 0; } -void mos7360_device::frame_interrupt_gen() +TIMER_CALLBACK_MEMBER(mos7360_device::frame_interrupt_gen) { if ((m_reg[0x1f] & 0xf) >= 0x0f) { @@ -1158,7 +1143,7 @@ void mos7360_device::frame_interrupt_gen() m_reg[0x1f]++; } -void mos7360_device::raster_interrupt_gen() +TIMER_CALLBACK_MEMBER(mos7360_device::raster_interrupt_gen) { m_rasterline++; m_rastertime = machine().time().as_double(); diff --git a/src/devices/sound/mos7360.h b/src/devices/sound/mos7360.h index c34dd2036f4..fd0a51f597b 100644 --- a/src/devices/sound/mos7360.h +++ b/src/devices/sound/mos7360.h @@ -99,15 +99,12 @@ protected: { TIMER_ID_1, TIMER_ID_2, - TIMER_ID_3, - TIMER_LINE, - TIMER_FRAME + TIMER_ID_3 }; // device-level overrides virtual void device_start() override; virtual void device_reset() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; // device_sound_interface callbacks virtual void sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) override; @@ -125,8 +122,9 @@ protected: void draw_cursor(int ybegin, int yend, int yoff, int xoff, int color); void drawlines(int first, int last); void soundport_w(int offset, int data); - void frame_interrupt_gen(); - void raster_interrupt_gen(); + TIMER_CALLBACK_MEMBER(timer_expired); + TIMER_CALLBACK_MEMBER(frame_interrupt_gen); + TIMER_CALLBACK_MEMBER(raster_interrupt_gen); int cs0_r(offs_t offset); int cs1_r(offs_t offset); @@ -147,16 +145,24 @@ protected: int m_frame_count; int m_lines; - int m_timer1_active, m_timer2_active, m_timer3_active; - emu_timer *m_timer1, *m_timer2, *m_timer3; + bool m_timer_active[3]; + emu_timer *m_timer[3]; int m_cursor1; - int m_chargenaddr, m_bitmapaddr, m_videoaddr; + int m_chargenaddr; + int m_bitmapaddr; + int m_videoaddr; int m_x_begin, m_x_end; int m_y_begin, m_y_end; - uint16_t m_c16_bitmap[2], m_bitmapmulti[4], m_mono[2], m_monoinversed[2], m_multi[4], m_ecmcolor[2], m_colors[5]; + uint16_t m_c16_bitmap[2]; + uint16_t m_bitmapmulti[4]; + uint16_t m_mono[2]; + uint16_t m_monoinversed[2]; + uint16_t m_multi[4]; + uint16_t m_ecmcolor[2]; + uint16_t m_colors[5]; int m_rasterline, m_lastline; double m_rastertime; diff --git a/src/devices/sound/msm5205.cpp b/src/devices/sound/msm5205.cpp index 382e69ca54e..ba196a419a3 100644 --- a/src/devices/sound/msm5205.cpp +++ b/src/devices/sound/msm5205.cpp @@ -99,8 +99,8 @@ void msm5205_device::device_start() /* stream system initialize */ m_stream = stream_alloc(0, 1, clock()); - m_vck_timer = timer_alloc(TIMER_VCK); - m_capture_timer = timer_alloc(TIMER_ADPCM_CAPTURE); + m_vck_timer = timer_alloc(FUNC(msm5205_device::toggle_vck), this); + m_capture_timer = timer_alloc(FUNC(msm5205_device::update_adpcm), this); /* register for save states */ save_item(NAME(m_data)); @@ -172,29 +172,19 @@ void msm5205_device::compute_tables() //------------------------------------------------- -// device_timer - called whenever a device timer -// fires +// toggle_vck - //------------------------------------------------- -void msm5205_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(msm5205_device::toggle_vck) { - switch (id) - { - case TIMER_VCK: - m_vck = !m_vck; - m_vck_cb(m_vck); - if (!m_vck) - m_capture_timer->adjust(attotime::from_hz(clock()/6)); // 15.6 usec at 384KHz - break; - - case TIMER_ADPCM_CAPTURE: - update_adpcm(); - break; - } + m_vck = !m_vck; + m_vck_cb(m_vck); + if (!m_vck) + m_capture_timer->adjust(attotime::from_hz(clock() / adpcm_capture_divisor())); } // timer callback at VCK low edge on MSM5205 (at rising edge on MSM6585) -void msm5205_device::update_adpcm() +TIMER_CALLBACK_MEMBER(msm5205_device::update_adpcm) { int val; int new_signal; @@ -226,7 +216,7 @@ void msm5205_device::update_adpcm() } /* update when signal changed */ - if( m_signal != new_signal) + if (m_signal != new_signal) { m_stream->update(); m_signal = new_signal; @@ -378,29 +368,6 @@ void msm5205_device::sound_stream_update(sound_stream &stream, std::vector<read_ //------------------------------------------------- -// device_timer - called whenever a device timer -// fires -//------------------------------------------------- - -void msm6585_device::device_timer(emu_timer &timer, device_timer_id id, int param) -{ - switch (id) - { - case TIMER_VCK: - m_vck = !m_vck; - m_vck_cb(m_vck); - if (m_vck) - m_capture_timer->adjust(attotime::from_hz(clock()/2)); // 3 usec at 640KHz - break; - - case TIMER_ADPCM_CAPTURE: - update_adpcm(); - break; - } -} - - -//------------------------------------------------- // sound_stream_update - handle a stream update //------------------------------------------------- diff --git a/src/devices/sound/msm5205.h b/src/devices/sound/msm5205.h index 1bbe1f56036..d38fc6e530d 100644 --- a/src/devices/sound/msm5205.h +++ b/src/devices/sound/msm5205.h @@ -60,15 +60,16 @@ protected: virtual void device_start() override; virtual void device_reset() override; virtual void device_clock_changed() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; - void update_adpcm(); + TIMER_CALLBACK_MEMBER(toggle_vck); + TIMER_CALLBACK_MEMBER(update_adpcm); // sound stream update overrides virtual void sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) override; void compute_tables(); virtual int get_prescaler() const; + virtual double adpcm_capture_divisor() const { return 6.0; } // internal state sound_stream *m_stream; // number of stream system @@ -103,9 +104,7 @@ public: protected: virtual int get_prescaler() const override; - - // device-level overrides - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; + virtual double adpcm_capture_divisor() const override { return 2.0; } // sound stream update overrides virtual void sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) override; diff --git a/src/devices/sound/pokey.cpp b/src/devices/sound/pokey.cpp index d90504499a9..d80e17f74d2 100644 --- a/src/devices/sound/pokey.cpp +++ b/src/devices/sound/pokey.cpp @@ -180,7 +180,10 @@ pokey_device::pokey_device(const machine_config &mconfig, const char *tag, devic m_serout_w_cb(*this), m_keyboard_r(*this), m_irq_f(*this), - m_output_type(LEGACY_LINEAR) + m_output_type(LEGACY_LINEAR), + m_serout_ready_timer(nullptr), + m_serout_complete_timer(nullptr), + m_serin_ready_timer(nullptr) { } @@ -258,10 +261,9 @@ void pokey_device::device_start() m_stream = stream_alloc(0, 1, clock()); - timer_alloc(SYNC_WRITE); /* timer for sync operation */ - timer_alloc(SYNC_NOOP); - timer_alloc(SYNC_POT); - timer_alloc(SYNC_SET_IRQST); + m_serout_ready_timer = timer_alloc(FUNC(pokey_device::serout_ready_irq), this); + m_serout_complete_timer = timer_alloc(FUNC(pokey_device::serout_complete_irq), this); + m_serin_ready_timer = timer_alloc(FUNC(pokey_device::serin_ready_irq), this); save_item(STRUCT_MEMBER(m_channel, m_borrow_cnt)); save_item(STRUCT_MEMBER(m_channel, m_counter)); @@ -354,63 +356,57 @@ void pokey_device::device_clock_changed() } //------------------------------------------------- -// stream_generate - handle update requests for -// our sound stream +// timer callbacks //------------------------------------------------- -void pokey_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(pokey_device::serout_ready_irq) { - switch (id) + if (m_IRQEN & IRQ_SEROR) { - case 3: - /* serout_ready_cb */ - if (m_IRQEN & IRQ_SEROR) - { - m_IRQST |= IRQ_SEROR; - if (!m_irq_f.isnull()) - m_irq_f(IRQ_SEROR); - } - break; - case 4: - /* serout_complete */ - if (m_IRQEN & IRQ_SEROC) - { - m_IRQST |= IRQ_SEROC; - if (!m_irq_f.isnull()) - m_irq_f(IRQ_SEROC); - } - break; - case 5: - /* serin_ready */ - if (m_IRQEN & IRQ_SERIN) - { - m_IRQST |= IRQ_SERIN; - if (!m_irq_f.isnull()) - m_irq_f(IRQ_SERIN); - } - break; - case SYNC_WRITE: - { - offs_t offset = (param >> 8) & 0xff; - uint8_t data = param & 0xff; - write_internal(offset, data); - } - break; - case SYNC_NOOP: - /* do nothing, caused by a forced resync */ - break; - case SYNC_POT: - //logerror("x %02x \n", (param & 0x20)); - m_ALLPOT |= (param & 0xff); - break; - case SYNC_SET_IRQST: - m_IRQST |= (param & 0xff); - break; - default: - throw emu_fatalerror("Unknown id in pokey_device::device_timer"); + m_IRQST |= IRQ_SEROR; + if (!m_irq_f.isnull()) + m_irq_f(IRQ_SEROR); + } +} + +TIMER_CALLBACK_MEMBER(pokey_device::serout_complete_irq) +{ + if (m_IRQEN & IRQ_SEROC) + { + m_IRQST |= IRQ_SEROC; + if (!m_irq_f.isnull()) + m_irq_f(IRQ_SEROC); + } +} + +TIMER_CALLBACK_MEMBER(pokey_device::serin_ready_irq) +{ + if (m_IRQEN & IRQ_SERIN) + { + m_IRQST |= IRQ_SERIN; + if (!m_irq_f.isnull()) + m_irq_f(IRQ_SERIN); } } +TIMER_CALLBACK_MEMBER(pokey_device::sync_write) +{ + offs_t offset = (param >> 8) & 0xff; + uint8_t data = param & 0xff; + write_internal(offset, data); +} + +TIMER_CALLBACK_MEMBER(pokey_device::sync_pot) +{ + //logerror("x %02x \n", (param & 0x20)); + m_ALLPOT |= (param & 0xff); +} + +TIMER_CALLBACK_MEMBER(pokey_device::sync_set_irqst) +{ + m_IRQST |= (param & 0xff); +} + void pokey_device::execute_run() { do @@ -531,7 +527,7 @@ void pokey_device::step_pot() } // some pots latched? if (upd != 0) - synchronize(SYNC_POT, upd); + machine().scheduler().synchronize(timer_expired_delegate(FUNC(pokey_device::sync_pot), this), upd); } /* @@ -755,7 +751,7 @@ uint8_t pokey_device::read(offs_t offset) { int data, pot; - synchronize(SYNC_NOOP); /* force resync */ + machine().scheduler().synchronize(); /* force resync */ switch (offset & 15) { @@ -849,7 +845,7 @@ uint8_t pokey_device::read(offs_t offset) void pokey_device::write(offs_t offset, uint8_t data) { - synchronize(SYNC_WRITE, (offset << 8) | data); + machine().scheduler().synchronize(timer_expired_delegate(FUNC(pokey_device::sync_write), this), (offset << 8) | data); } void pokey_device::write_internal(offs_t offset, uint8_t data) @@ -946,9 +942,9 @@ void pokey_device::write_internal(offs_t offset, uint8_t data) * loaders from Ballblazer and Escape from Fractalus * The real times are unknown */ - timer_set(attotime::from_usec(200), 3); + m_serout_ready_timer->adjust(attotime::from_usec(200)); /* 10 bits (assumption 1 start, 8 data and 1 stop bit) take how long? */ - timer_set(attotime::from_usec(2000), 4);// FUNC(pokey_serout_complete), 0, p); + m_serout_complete_timer->adjust(attotime::from_usec(2000)); break; case IRQEN_C: @@ -1023,7 +1019,7 @@ WRITE_LINE_MEMBER( pokey_device::sid_w ) void pokey_device::serin_ready(int after) { - timer_set(m_clock_period * after, 5, 0); + m_serin_ready_timer->adjust(m_clock_period * after, 0); } //------------------------------------------------- diff --git a/src/devices/sound/pokey.h b/src/devices/sound/pokey.h index c9d58e18eeb..1a111646df1 100644 --- a/src/devices/sound/pokey.h +++ b/src/devices/sound/pokey.h @@ -114,14 +114,6 @@ public: SKSTAT_C = 0x0F }; - enum /* sync-operations */ - { - SYNC_NOOP = 11, - SYNC_SET_IRQST = 12, - SYNC_POT = 13, - SYNC_WRITE = 14 - }; - enum output_type { LEGACY_LINEAR = 0, @@ -190,7 +182,6 @@ protected: virtual void device_reset() override; virtual void device_post_load() override; virtual void device_clock_changed() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; // device_sound_interface overrides virtual void sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) override; @@ -201,6 +192,13 @@ protected: // other internal states int m_icount; + TIMER_CALLBACK_MEMBER(serout_ready_irq); + TIMER_CALLBACK_MEMBER(serout_complete_irq); + TIMER_CALLBACK_MEMBER(serin_ready_irq); + TIMER_CALLBACK_MEMBER(sync_write); + TIMER_CALLBACK_MEMBER(sync_pot); + TIMER_CALLBACK_MEMBER(sync_set_irqst); + private: class pokey_channel @@ -228,7 +226,7 @@ private: if (m_parent->m_IRQEN & m_INTMask) { /* Exposed state has changed: This should only be updated after a resync ... */ - m_parent->synchronize(SYNC_SET_IRQST, m_INTMask); + m_parent->machine().scheduler().synchronize(timer_expired_delegate(FUNC(pokey_device::sync_set_irqst), m_parent), m_INTMask); } } } @@ -312,6 +310,10 @@ private: double m_r_pullup; double m_cap; double m_v_ref; + + emu_timer *m_serout_ready_timer; + emu_timer *m_serout_complete_timer; + emu_timer *m_serin_ready_timer; }; diff --git a/src/devices/sound/qs1000.cpp b/src/devices/sound/qs1000.cpp index 8a98b85111a..ff45ec51093 100644 --- a/src/devices/sound/qs1000.cpp +++ b/src/devices/sound/qs1000.cpp @@ -312,15 +312,6 @@ void qs1000_device::device_reset() //------------------------------------------------- -// device_timer - handle deferred writes and -// resets as a timer callback -//------------------------------------------------- -void qs1000_device::device_timer(emu_timer &timer, device_timer_id id, int param) -{ -} - - -//------------------------------------------------- // p0_r //------------------------------------------------- uint8_t qs1000_device::p0_r() diff --git a/src/devices/sound/qs1000.h b/src/devices/sound/qs1000.h index d992c6a9e7b..2624d893739 100644 --- a/src/devices/sound/qs1000.h +++ b/src/devices/sound/qs1000.h @@ -70,7 +70,6 @@ protected: virtual void device_add_mconfig(machine_config &config) override; virtual void device_start() override; virtual void device_reset() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; // device_sound_interface overrides virtual void sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) override; diff --git a/src/devices/sound/scsp.cpp b/src/devices/sound/scsp.cpp index 1b9a5a8cb8f..f58907b8611 100644 --- a/src/devices/sound/scsp.cpp +++ b/src/devices/sound/scsp.cpp @@ -579,9 +579,9 @@ void scsp_device::init() m_MidiOutR = m_MidiOutW = 0; m_DSP.space = &this->space(); - m_timerA = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(scsp_device::timerA_cb), this)); - m_timerB = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(scsp_device::timerB_cb), this)); - m_timerC = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(scsp_device::timerC_cb), this)); + m_timerA = timer_alloc(FUNC(scsp_device::timerA_cb), this); + m_timerB = timer_alloc(FUNC(scsp_device::timerB_cb), this); + m_timerC = timer_alloc(FUNC(scsp_device::timerC_cb), this); for (i = 0; i < 0x400; ++i) { diff --git a/src/devices/sound/sn76496.cpp b/src/devices/sound/sn76496.cpp index e204b0355cb..96c6a3ba789 100644 --- a/src/devices/sound/sn76496.cpp +++ b/src/devices/sound/sn76496.cpp @@ -280,7 +280,7 @@ void sn76496_base_device::device_start() m_ready_state = true; - m_ready_timer = timer_alloc(0); + m_ready_timer = timer_alloc(FUNC(sn76496_base_device::delayed_ready), this); m_ready_handler(ASSERT_LINE); register_for_save_states(); @@ -298,7 +298,7 @@ void sn76496_base_device::stereo_w(u8 data) else fatalerror("sn76496_base_device: Call to stereo write with mono chip!\n"); } -void sn76496_base_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(sn76496_base_device::delayed_ready) { m_ready_state = true; m_ready_handler(ASSERT_LINE); diff --git a/src/devices/sound/sn76496.h b/src/devices/sound/sn76496.h index d8cc4442314..f5484248715 100644 --- a/src/devices/sound/sn76496.h +++ b/src/devices/sound/sn76496.h @@ -27,26 +27,16 @@ public: DECLARE_READ_LINE_MEMBER( ready_r ) { return m_ready_state ? 1 : 0; } protected: - sn76496_base_device( - const machine_config &mconfig, - device_type type, - const char *tag, - int feedbackmask, - int noisetap1, - int noisetap2, - bool negate, - bool stereo, - int clockdivider, - bool ncr, - bool sega, - device_t *owner, - uint32_t clock); - - virtual void device_start() override; - virtual void device_clock_changed() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; + sn76496_base_device(const machine_config &mconfig, device_type type, const char *tag, + int feedbackmask, int noisetap1, int noisetap2, bool negate, bool stereo, int clockdivider, + bool ncr, bool sega, device_t *owner, uint32_t clock); + + virtual void device_start() override; + virtual void device_clock_changed() override; virtual void sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) override; + TIMER_CALLBACK_MEMBER(delayed_ready); + private: inline bool in_noise_mode(); void register_for_save_states(); diff --git a/src/devices/sound/sp0250.cpp b/src/devices/sound/sp0250.cpp index 6d9ed63ecd3..9544adb3c38 100644 --- a/src/devices/sound/sp0250.cpp +++ b/src/devices/sound/sp0250.cpp @@ -25,6 +25,7 @@ DEFINE_DEVICE_TYPE(SP0250, sp0250_device, "sp0250", "GI SP0250 LPC") sp0250_device::sp0250_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) : device_t(mconfig, SP0250, tag, owner, clock), device_sound_interface(mconfig, *this), + m_timer(nullptr), m_pwm_mode(false), m_pwm_index(PWM_CLOCKS), m_pwm_count(0), @@ -72,7 +73,8 @@ void sp0250_device::device_start() { m_drq(ASSERT_LINE); attotime period = attotime::from_hz(frame_rate); - timer_alloc()->adjust(period, 0, period); + m_timer = timer_alloc(FUNC(sp0250_device::delayed_stream_update), this); + m_timer->adjust(period, 0, period); } // PWM state @@ -108,7 +110,7 @@ void sp0250_device::device_reset() load_values(); } -void sp0250_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(sp0250_device::delayed_stream_update) { m_stream->update(); } diff --git a/src/devices/sound/sp0250.h b/src/devices/sound/sp0250.h index 260e77ad695..31c32ef4d5d 100644 --- a/src/devices/sound/sp0250.h +++ b/src/devices/sound/sp0250.h @@ -20,11 +20,12 @@ protected: // device-level overrides virtual void device_start() override; virtual void device_reset() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; // sound stream update overrides virtual void sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) override; + TIMER_CALLBACK_MEMBER(delayed_stream_update); + private: // internal helpers int8_t next(); @@ -47,6 +48,9 @@ private: int16_t z1, z2; }; + // timer for stream updates + emu_timer *m_timer; + // PWM state bool m_pwm_mode; uint8_t m_pwm_index; diff --git a/src/devices/sound/sp0256.cpp b/src/devices/sound/sp0256.cpp index b1219f70cd7..7f709ec90c0 100644 --- a/src/devices/sound/sp0256.cpp +++ b/src/devices/sound/sp0256.cpp @@ -106,7 +106,7 @@ void sp0256_device::device_start() // TODO: because of this, check if the bitrev functions are even used anywhere else // bitrevbuff(m_rom, 0, 0xffff); - m_lrq_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(sp0256_device::set_lrq_timer_proc),this)); + m_lrq_timer = timer_alloc(FUNC(sp0256_device::set_lrq_timer_proc), this); // save device variables save_item(NAME(m_sby_line)); diff --git a/src/devices/sound/tms5110.cpp b/src/devices/sound/tms5110.cpp index e96a9c6e736..a9d3395a4d2 100644 --- a/src/devices/sound/tms5110.cpp +++ b/src/devices/sound/tms5110.cpp @@ -1051,7 +1051,7 @@ void tms5110_device::device_start() m_stream = stream_alloc(0, 1, clock() / 80); m_state = CTL_STATE_INPUT; /* most probably not defined */ - m_romclk_hack_timer = timer_alloc(0); + m_romclk_hack_timer = timer_alloc(FUNC(tms5110_device::romclk_hack_toggle), this); register_for_save_states(); } @@ -1187,17 +1187,15 @@ uint8_t m58817_device::status_r() return (TALK_STATUS() << 0); /*CTL1 = still talking ? */ } -/****************************************************************************** - - tms5110_romclk_hack_r -- read status of romclk - -******************************************************************************/ - -void tms5110_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(tms5110_device::romclk_hack_toggle) { m_romclk_hack_state = !m_romclk_hack_state; } +//------------------------------------------------- +// romclk_hack_r - read status of romclk +//------------------------------------------------- + int tms5110_device::romclk_hack_r() { /* bring up to date first */ @@ -1322,7 +1320,7 @@ void tmsprom_device::update_prom_cnt() m_prom_cnt &= 0x0f; } -void tmsprom_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(tmsprom_device::update_romclk) { /* only 16 bytes needed ... The original dump is bad. This * is what is needed to get speech to work. The prom data has @@ -1332,10 +1330,8 @@ void tmsprom_device::device_timer(emu_timer &timer, device_timer_id id, int para * static const int prom[16] = {0x00, 0x00, 0x02, 0x00, 0x00, 0x02, 0x00, 0x00, * 0x02, 0x00, 0x40, 0x00, 0x04, 0x06, 0x04, 0x84 }; */ - uint16_t ctrl; - update_prom_cnt(); - ctrl = (m_prom[m_prom_cnt] | 0x200); + uint16_t ctrl = (m_prom[m_prom_cnt] | 0x200); //if (m_enable && m_prom_cnt < 0x10) printf("ctrl %04x, enable %d cnt %d\n", ctrl, m_enable, m_prom_cnt); m_prom_cnt = ((m_prom_cnt + 1) & 0x0f) | (m_prom_cnt & 0x10); @@ -1359,7 +1355,7 @@ void tmsprom_device::device_start() m_pdc_cb.resolve_safe(); m_ctl_cb.resolve_safe(); - m_romclk_timer = timer_alloc(0); + m_romclk_timer = timer_alloc(FUNC(tmsprom_device::update_romclk), this); m_romclk_timer->adjust(attotime::zero, 0, attotime::from_hz(clock())); m_bit = 0; diff --git a/src/devices/sound/tms5110.h b/src/devices/sound/tms5110.h index e49ea9e93cc..9d907668a70 100644 --- a/src/devices/sound/tms5110.h +++ b/src/devices/sound/tms5110.h @@ -57,7 +57,7 @@ protected: virtual void device_reset() override; virtual void device_clock_changed() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; + TIMER_CALLBACK_MEMBER(romclk_hack_toggle); // sound stream update overrides virtual void sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) override; @@ -285,7 +285,7 @@ protected: // device-level overrides virtual void device_start() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; + TIMER_CALLBACK_MEMBER(update_romclk); private: void register_for_save_states(); diff --git a/src/devices/sound/tms5220.cpp b/src/devices/sound/tms5220.cpp index 47d1ab02fc2..77622b12fef 100644 --- a/src/devices/sound/tms5220.cpp +++ b/src/devices/sound/tms5220.cpp @@ -1653,7 +1653,7 @@ void tms5220_device::device_start() /* initialize a stream */ m_stream = stream_alloc(0, 1, clock() / 80); - m_timer_io_ready = timer_alloc(0); + m_timer_io_ready = timer_alloc(FUNC(tms5220_device::set_io_ready), this); /* not during reset which is called from within a write! */ m_io_ready = true; @@ -1729,60 +1729,49 @@ void tms5220_device::device_reset() } -/********************************************************************************************** - - True timing - -***********************************************************************************************/ - -void tms5220_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(tms5220_device::set_io_ready) { - switch(id) + /* bring up to date first */ + m_stream->update(); + LOGMASKED(LOG_IO_READY, "m_timer_io_ready timer fired, param = %02x, m_rs_ws = %02x\n", param, m_rs_ws); + if (param) // low->high ready state { - case 0: // m_timer_io_ready - /* bring up to date first */ - m_stream->update(); - LOGMASKED(LOG_IO_READY, "m_timer_io_ready timer fired, param = %02x, m_rs_ws = %02x\n", param, m_rs_ws); - if (param) // low->high ready state + switch (m_rs_ws) { - switch (m_rs_ws) + case 0x02: + /* Write */ + LOGMASKED(LOG_IO_READY, "m_timer_io_ready: Attempting to service write...\n"); + if ((m_fifo_count >= FIFO_SIZE) && m_DDIS) // if FIFO is full and we're in speak external mode { - case 0x02: - /* Write */ - LOGMASKED(LOG_IO_READY, "m_timer_io_ready: Attempting to service write...\n"); - if ((m_fifo_count >= FIFO_SIZE) && m_DDIS) // if FIFO is full and we're in speak external mode - { - LOGMASKED(LOG_IO_READY, "m_timer_io_ready: in SPKEXT and FIFO was full! cannot service write now, delaying 16 cycles...\n"); - m_timer_io_ready->adjust(clocks_to_attotime(16), 1); - break; - } - else - { - LOGMASKED(LOG_IO_READY, "m_timer_io_ready: Serviced write: %02x\n", m_write_latch); - data_write(m_write_latch); - m_io_ready = param; - break; - } - case 0x01: - /* Read */ - m_read_latch = status_read(true); - LOGMASKED(LOG_IO_READY, "m_timer_io_ready: Serviced read, returning %02x\n", m_read_latch); - m_io_ready = param; - break; - case 0x03: - /* High Impedance */ - m_io_ready = param; + LOGMASKED(LOG_IO_READY, "m_timer_io_ready: in SPKEXT and FIFO was full! cannot service write now, delaying 16 cycles...\n"); + m_timer_io_ready->adjust(clocks_to_attotime(16), 1); break; - case 0x00: - /* illegal */ + } + else + { + LOGMASKED(LOG_IO_READY, "m_timer_io_ready: Serviced write: %02x\n", m_write_latch); + data_write(m_write_latch); m_io_ready = param; break; } + case 0x01: + /* Read */ + m_read_latch = status_read(true); + LOGMASKED(LOG_IO_READY, "m_timer_io_ready: Serviced read, returning %02x\n", m_read_latch); + m_io_ready = param; + break; + case 0x03: + /* High Impedance */ + m_io_ready = param; + break; + case 0x00: + /* illegal */ + m_io_ready = param; + break; } - - update_ready_state(); - break; } + + update_ready_state(); } /* diff --git a/src/devices/sound/tms5220.h b/src/devices/sound/tms5220.h index 826a78ec291..82a589c486d 100644 --- a/src/devices/sound/tms5220.h +++ b/src/devices/sound/tms5220.h @@ -72,11 +72,11 @@ protected: virtual void device_reset() override; virtual void device_clock_changed() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; - // sound stream update overrides virtual void sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) override; + TIMER_CALLBACK_MEMBER(set_io_ready); + private: static constexpr unsigned FIFO_SIZE = 16; diff --git a/src/devices/sound/upd1771.cpp b/src/devices/sound/upd1771.cpp index 2ec1d767ba0..4e865ea2c42 100644 --- a/src/devices/sound/upd1771.cpp +++ b/src/devices/sound/upd1771.cpp @@ -253,7 +253,7 @@ void upd1771c_device::device_start() /* resolve callbacks */ m_ack_handler.resolve_safe(); - m_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(upd1771c_device::ack_callback),this)); + m_timer = timer_alloc(FUNC(upd1771c_device::ack_callback), this); m_channel = stream_alloc(0, 1, clock() / 4); diff --git a/src/devices/sound/upd7759.cpp b/src/devices/sound/upd7759.cpp index 36738f029a5..2da49639c82 100644 --- a/src/devices/sound/upd7759.cpp +++ b/src/devices/sound/upd7759.cpp @@ -268,21 +268,12 @@ void upd7759_device::device_start() m_sample_offset_shift = 1; - m_timer = timer_alloc(TID_SLAVE_UPDATE); + m_timer = timer_alloc(FUNC(upd7759_device::drq_update), this); m_drqcallback.resolve_safe(); - - device_reset(); } -void upd7756_device::device_start() -{ - upd775x_device::device_start(); - - device_reset(); -} - //------------------------------------------------- // device_reset - device-specific reset //------------------------------------------------- @@ -574,54 +565,29 @@ void upd775x_device::advance_state() } } -/************************************************************ - - DRQ callback - -*************************************************************/ +TIMER_CALLBACK_MEMBER(upd775x_device::sync_port_write) +{ + m_fifo_in = param; +} -void upd7759_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(upd7759_device::drq_update) { uint8_t olddrq = m_drq; int old_state = m_state; - switch (id) - { - case TID_PORT_WRITE: - m_fifo_in = param; - break; - - case TID_RESET_WRITE: - internal_reset_w(param); - break; - - case TID_START_WRITE: - internal_start_w(param); - break; - - case TID_MD_WRITE: - internal_md_w(param); - break; - - case TID_SLAVE_UPDATE: - m_channel->update(); - - advance_state(); - - LOG_STATE("upd7759_slave_update: DRQ %d->%d\n", olddrq, m_drq); - if (olddrq != m_drq) - { - LOG_DRQ("DRQ changed %d->%d\n", olddrq, m_drq); - m_drqcallback(m_drq); - } + m_channel->update(); - if (m_state != STATE_IDLE || old_state != STATE_IDLE) - m_timer->adjust(m_clock_period * m_clocks_left); - break; + advance_state(); - default: - throw emu_fatalerror("Unknown id in upd7759_device::device_timer"); + LOG_STATE("upd7759_slave_update: DRQ %d->%d\n", olddrq, m_drq); + if (olddrq != m_drq) + { + LOG_DRQ("DRQ changed %d->%d\n", olddrq, m_drq); + m_drqcallback(m_drq); } + + if (m_state != STATE_IDLE || old_state != STATE_IDLE) + m_timer->adjust(m_clock_period * m_clocks_left); } /************************************************************ @@ -632,13 +598,13 @@ void upd7759_device::device_timer(emu_timer &timer, device_timer_id id, int para WRITE_LINE_MEMBER( upd775x_device::reset_w ) { - synchronize(TID_RESET_WRITE, state); + machine().scheduler().synchronize(timer_expired_delegate(FUNC(upd775x_device::internal_reset_w), this), state); } -void upd775x_device::internal_reset_w(int state) +TIMER_CALLBACK_MEMBER(upd775x_device::internal_reset_w) { uint8_t oldreset = m_reset; - m_reset = (state != 0); + m_reset = (param != 0); m_channel->update(); @@ -646,10 +612,10 @@ void upd775x_device::internal_reset_w(int state) device_reset(); } -void upd7759_device::internal_reset_w(int state) +TIMER_CALLBACK_MEMBER(upd7759_device::internal_reset_w) { uint8_t oldreset = m_reset; - upd775x_device::internal_reset_w(state); + upd775x_device::internal_reset_w(param); if (!oldreset && m_reset) { @@ -664,7 +630,7 @@ void upd7759_device::internal_reset_w(int state) WRITE_LINE_MEMBER( upd775x_device::start_w ) { - synchronize(TID_START_WRITE, state); + machine().scheduler().synchronize(timer_expired_delegate(FUNC(upd775x_device::internal_start_w), this), state); } void upd7759_device::internal_start_w(int state) @@ -710,14 +676,14 @@ WRITE_LINE_MEMBER(upd7759_device::md_w) m_md = state; return; } - synchronize(TID_MD_WRITE, state); + machine().scheduler().synchronize(timer_expired_delegate(FUNC(upd7759_device::internal_md_w), this), state); } -void upd7759_device::internal_md_w(int state) +TIMER_CALLBACK_MEMBER(upd7759_device::internal_md_w) { uint8_t old_md = m_md; - m_md = (state != 0); + m_md = (param != 0); LOG_STATE("upd7759_md_w: %d->%d\n", old_md, m_md); @@ -741,7 +707,7 @@ void upd7759_device::internal_md_w(int state) void upd775x_device::port_w(u8 data) { - synchronize(TID_PORT_WRITE, data); + machine().scheduler().synchronize(timer_expired_delegate(FUNC(upd775x_device::sync_port_write), this), data); } diff --git a/src/devices/sound/upd7759.h b/src/devices/sound/upd7759.h index 23f24ad1ae5..1f1d0e38dfd 100644 --- a/src/devices/sound/upd7759.h +++ b/src/devices/sound/upd7759.h @@ -27,8 +27,8 @@ public: void set_start_delay(uint32_t data) { m_start_delay = data; } protected: - virtual void internal_start_w(int state) = 0; - virtual void internal_reset_w(int state); + virtual TIMER_CALLBACK_MEMBER(internal_start_w) = 0; + virtual TIMER_CALLBACK_MEMBER(internal_reset_w); enum { @@ -78,6 +78,8 @@ protected: void update_adpcm(int data); virtual void advance_state(); + TIMER_CALLBACK_MEMBER(sync_port_write); + // internal state sound_stream *m_channel; // stream channel for playback @@ -131,14 +133,15 @@ public: DECLARE_WRITE_LINE_MEMBER( md_w ); protected: - virtual void internal_start_w(int state) override; - virtual void internal_reset_w(int state) override; - upd7759_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock); virtual void device_start() override; virtual void device_reset() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; + + virtual TIMER_CALLBACK_MEMBER(internal_start_w) override; + virtual TIMER_CALLBACK_MEMBER(internal_reset_w) override; + + TIMER_CALLBACK_MEMBER(drq_update); void internal_md_w(int state); @@ -151,14 +154,12 @@ class upd7756_device : public upd775x_device public: upd7756_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock = STANDARD_CLOCK); - virtual void device_reset() override; - protected: - virtual void internal_start_w(int state) override; - upd7756_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock); - virtual void device_start() override; + virtual void device_reset() override; + + virtual TIMER_CALLBACK_MEMBER(internal_start_w) override; }; DECLARE_DEVICE_TYPE(UPD7759, upd7759_device) diff --git a/src/devices/sound/votrax.cpp b/src/devices/sound/votrax.cpp index ee4a21a3c9f..1ec2343f72f 100644 --- a/src/devices/sound/votrax.cpp +++ b/src/devices/sound/votrax.cpp @@ -170,7 +170,7 @@ void votrax_sc01_device::device_start() m_sclock = m_mainclock / 18.0; m_cclock = m_mainclock / 36.0; m_stream = stream_alloc(0, 1, m_sclock); - m_timer = timer_alloc(); + m_timer = timer_alloc(FUNC(votrax_sc01_device::phone_tick), this); // reset outputs m_ar_cb.resolve_safe(); @@ -331,10 +331,10 @@ void votrax_sc01_device::device_clock_changed() //------------------------------------------------- -// device_timer - handle device timer +// phone_tick - process transitions //------------------------------------------------- -void votrax_sc01_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(votrax_sc01_device::phone_tick) { m_stream->update(); diff --git a/src/devices/sound/votrax.h b/src/devices/sound/votrax.h index 87c466b1875..2dcc7d087da 100644 --- a/src/devices/sound/votrax.h +++ b/src/devices/sound/votrax.h @@ -34,11 +34,12 @@ protected: virtual void device_start() override; virtual void device_reset() override; virtual void device_clock_changed() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; // device_sound_interface overrides virtual void sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) override; + TIMER_CALLBACK_MEMBER(phone_tick); + private: // Possible timer parameters enum { diff --git a/src/devices/sound/ym2154.cpp b/src/devices/sound/ym2154.cpp index 8be2888175b..287529aeeec 100644 --- a/src/devices/sound/ym2154.cpp +++ b/src/devices/sound/ym2154.cpp @@ -177,7 +177,7 @@ void ym2154_device::write(offs_t offset, u8 data) void ym2154_device::device_start() { // allocate our timer - m_timer = timer_alloc(0); + m_timer = timer_alloc(FUNC(ym2154_device::delayed_irq), this); // resolve the handlers m_update_irq.resolve(); @@ -237,10 +237,10 @@ void ym2154_device::device_clock_changed() //------------------------------------------------- -// sound_stream_update - generate sound data +// delayed_irq - //------------------------------------------------- -void ym2154_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(ym2154_device::delayed_irq) { update_irq_state(1); m_timer->adjust((2048 - m_timer_count) * attotime::from_hz(sample_rate())); diff --git a/src/devices/sound/ym2154.h b/src/devices/sound/ym2154.h index 3736b6aa367..e7f287409fa 100644 --- a/src/devices/sound/ym2154.h +++ b/src/devices/sound/ym2154.h @@ -37,7 +37,6 @@ protected: virtual void device_start() override; virtual void device_reset() override; virtual void device_clock_changed() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; // sound overrides virtual void sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) override; @@ -45,6 +44,8 @@ protected: // memory space configuration virtual space_config_vector memory_space_config() const override; + TIMER_CALLBACK_MEMBER(delayed_irq); + private: struct channel { diff --git a/src/devices/sound/ymf271.cpp b/src/devices/sound/ymf271.cpp index 6e82ee97607..b8240df9c72 100644 --- a/src/devices/sound/ymf271.cpp +++ b/src/devices/sound/ymf271.cpp @@ -1309,46 +1309,38 @@ void ymf271_device::ymf271_write_pcm(uint8_t address, uint8_t data) } } -void ymf271_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(ymf271_device::timer_a_expired) { - switch(id) - { - case 0: - m_status |= 1; - - // assert IRQ - if (m_enable & 4) - { - m_irqstate |= 1; - - if (!m_irq_handler.isnull()) - m_irq_handler(1); - } + m_status |= 1; - // reload timer - m_timA->adjust(clocks_to_attotime(384 * (1024 - m_timerA)), 0); - break; + // assert IRQ + if (m_enable & 4) + { + m_irqstate |= 1; - case 1: - m_status |= 2; + if (!m_irq_handler.isnull()) + m_irq_handler(1); + } - // assert IRQ - if (m_enable & 8) - { - m_irqstate |= 2; + // reload timer + m_timA->adjust(clocks_to_attotime(384 * (1024 - m_timerA)), 0); +} - if (!m_irq_handler.isnull()) - m_irq_handler(1); - } +TIMER_CALLBACK_MEMBER(ymf271_device::timer_b_expired) +{ + m_status |= 2; - // reload timer - m_timB->adjust(clocks_to_attotime(384 * 16 * (256 - m_timerB)), 0); - break; + // assert IRQ + if (m_enable & 8) + { + m_irqstate |= 2; - default: - throw emu_fatalerror("Unknown id in ymf271_device::device_timer"); - break; + if (!m_irq_handler.isnull()) + m_irq_handler(1); } + + // reload timer + m_timB->adjust(clocks_to_attotime(384 * 16 * (256 - m_timerB)), 0); } void ymf271_device::ymf271_write_timer(uint8_t address, uint8_t data) @@ -1732,8 +1724,8 @@ void ymf271_device::init_state() void ymf271_device::device_start() { - m_timA = timer_alloc(0); - m_timB = timer_alloc(1); + m_timA = timer_alloc(FUNC(ymf271_device::timer_a_expired), this); + m_timB = timer_alloc(FUNC(ymf271_device::timer_b_expired), this); m_irq_handler.resolve(); diff --git a/src/devices/sound/ymf271.h b/src/devices/sound/ymf271.h index 6dbf1a9408f..5c6e432649b 100644 --- a/src/devices/sound/ymf271.h +++ b/src/devices/sound/ymf271.h @@ -24,7 +24,6 @@ protected: // device-level overrides virtual void device_start() override; virtual void device_reset() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; virtual void device_clock_changed() override; // sound stream update overrides @@ -33,6 +32,9 @@ protected: // device_rom_interface overrides virtual void rom_bank_updated() override; + TIMER_CALLBACK_MEMBER(timer_a_expired); + TIMER_CALLBACK_MEMBER(timer_b_expired); + private: struct YMF271Slot { diff --git a/src/devices/sound/ymfm_mame.h b/src/devices/sound/ymfm_mame.h index d22fc9ad8b2..d0161426619 100644 --- a/src/devices/sound/ymfm_mame.h +++ b/src/devices/sound/ymfm_mame.h @@ -138,7 +138,7 @@ protected: { // allocate our timers for (int tnum = 0; tnum < 2; tnum++) - m_timer[tnum] = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(ym_generic_device::fm_timer_handler), this)); + m_timer[tnum] = timer_alloc(FUNC(ym_generic_device::fm_timer_handler), this); // resolve the handlers m_update_irq.resolve(); diff --git a/src/devices/sound/ymz280b.cpp b/src/devices/sound/ymz280b.cpp index f6e6a0e3935..319b03a381b 100644 --- a/src/devices/sound/ymz280b.cpp +++ b/src/devices/sound/ymz280b.cpp @@ -81,7 +81,7 @@ void ymz280b_device::update_irq_state() } -void ymz280b_device::update_step(struct YMZ280BVoice *voice) +void ymz280b_device::update_step(YMZ280BVoice *voice) { int frequency; @@ -94,7 +94,7 @@ void ymz280b_device::update_step(struct YMZ280BVoice *voice) } -void ymz280b_device::update_volumes(struct YMZ280BVoice *voice) +void ymz280b_device::update_volumes(YMZ280BVoice *voice) { if (voice->pan == 8) { @@ -118,24 +118,24 @@ void ymz280b_device::update_volumes(struct YMZ280BVoice *voice) void ymz280b_device::device_post_load() { - for (auto & elem : m_voice) + for (size_t i = 0; i < std::size(m_voice); i++) { - struct YMZ280BVoice *voice = &elem; + YMZ280BVoice *voice = &m_voice[i]; update_step(voice); if(voice->irq_schedule) - voice->timer->adjust(attotime::zero); + voice->timer->adjust(attotime::zero, i); } } -void ymz280b_device::update_irq_state_timer_common(int voicenum) +TIMER_CALLBACK_MEMBER(ymz280b_device::update_irq_state_timer_common) { - struct YMZ280BVoice *voice = &m_voice[voicenum]; + YMZ280BVoice *voice = &m_voice[param]; if(!voice->irq_schedule) return; voice->playing = 0; - m_status_register |= 1 << voicenum; + m_status_register |= 1 << param; update_irq_state(); voice->irq_schedule = 0; } @@ -164,7 +164,7 @@ static void compute_tables() ***********************************************************************************************/ -int ymz280b_device::generate_adpcm(struct YMZ280BVoice *voice, s16 *buffer, int samples) +int ymz280b_device::generate_adpcm(YMZ280BVoice *voice, s16 *buffer, int samples) { int position = voice->position; int signal = voice->signal; @@ -276,7 +276,7 @@ int ymz280b_device::generate_adpcm(struct YMZ280BVoice *voice, s16 *buffer, int ***********************************************************************************************/ -int ymz280b_device::generate_pcm8(struct YMZ280BVoice *voice, s16 *buffer, int samples) +int ymz280b_device::generate_pcm8(YMZ280BVoice *voice, s16 *buffer, int samples) { int position = voice->position; int val; @@ -346,7 +346,7 @@ int ymz280b_device::generate_pcm8(struct YMZ280BVoice *voice, s16 *buffer, int s ***********************************************************************************************/ -int ymz280b_device::generate_pcm16(struct YMZ280BVoice *voice, s16 *buffer, int samples) +int ymz280b_device::generate_pcm16(YMZ280BVoice *voice, s16 *buffer, int samples) { int position = voice->position; int val; @@ -428,7 +428,7 @@ void ymz280b_device::sound_stream_update(sound_stream &stream, std::vector<read_ /* loop over voices */ for (v = 0; v < 8; v++) { - struct YMZ280BVoice *voice = &m_voice[v]; + YMZ280BVoice *voice = &m_voice[v]; s16 prev = voice->last_sample; s16 curr = voice->curr_sample; s16 *curr_data = m_scratch.get(); @@ -501,7 +501,7 @@ void ymz280b_device::sound_stream_update(sound_stream &stream, std::vector<read_ voice->playing = 0; /* set update_irq_state_timer. IRQ is signaled on next CPU execution. */ - voice->timer->adjust(attotime::zero); + voice->timer->adjust(attotime::zero, v); voice->irq_schedule = 1; } } @@ -556,7 +556,7 @@ void ymz280b_device::device_start() for (int i = 0; i < 8; i++) { - m_voice[i].timer = timer_alloc(i); + m_voice[i].timer = timer_alloc(FUNC(ymz280b_device::update_irq_state_timer_common), this); } /* create the stream */ @@ -629,7 +629,7 @@ void ymz280b_device::device_reset() /* clear other voice parameters */ for (auto &elem : m_voice) { - struct YMZ280BVoice *voice = &elem; + YMZ280BVoice *voice = &elem; voice->curr_sample = 0; voice->last_sample = 0; @@ -639,15 +639,6 @@ void ymz280b_device::device_reset() } -void ymz280b_device::device_timer(emu_timer &timer, device_timer_id id, int param) -{ - if (id < 8) - update_irq_state_timer_common( id ); - else - throw emu_fatalerror("Unknown id in ymz280b_device::device_timer"); -} - - void ymz280b_device::device_clock_changed() { m_master_clock = (double)clock() / 384.0; @@ -669,13 +660,10 @@ void ymz280b_device::rom_bank_updated() void ymz280b_device::write_to_register(int data) { - struct YMZ280BVoice *voice; - int i; - /* lower registers follow a pattern */ if (m_current_register < 0x80) { - voice = &m_voice[(m_current_register >> 2) & 7]; + YMZ280BVoice *voice = &m_voice[(m_current_register >> 2) & 7]; switch (m_current_register & 0xe3) { @@ -687,8 +675,10 @@ void ymz280b_device::write_to_register(int data) case 0x01: /* pitch upper 1 bit, loop, key on, mode */ voice->fnum = (voice->fnum & 0xff) | ((data & 0x01) << 8); voice->looping = (data & 0x10) >> 4; - if ((data & 0x60) == 0) data &= 0x7f; /* ignore mode setting and set to same state as KON=0 */ - else voice->mode = (data & 0x60) >> 5; + if ((data & 0x60) == 0) + data &= 0x7f; /* ignore mode setting and set to same state as KON=0 */ + else + voice->mode = (data & 0x60) >> 5; if (!voice->keyon && (data & 0x80) && m_keyon_enable) { voice->playing = 1; @@ -822,7 +812,7 @@ void ymz280b_device::write_to_register(int data) if (m_keyon_enable && !(data & 0x80)) { - for (i = 0; i < 8; i++) + for (int i = 0; i < 8; i++) { m_voice[i].playing = 0; @@ -832,7 +822,7 @@ void ymz280b_device::write_to_register(int data) } else if (!m_keyon_enable && (data & 0x80)) { - for (i = 0; i < 8; i++) + for (int i = 0; i < 8; i++) { if (m_voice[i].keyon && m_voice[i].looping) m_voice[i].playing = 1; diff --git a/src/devices/sound/ymz280b.h b/src/devices/sound/ymz280b.h index c35d4be20fc..04b229de4d3 100644 --- a/src/devices/sound/ymz280b.h +++ b/src/devices/sound/ymz280b.h @@ -32,7 +32,6 @@ protected: virtual void device_start() override; virtual void device_post_load() override; virtual void device_reset() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; virtual void device_clock_changed() override; // sound stream update overrides @@ -80,17 +79,17 @@ private: }; void update_irq_state(); - void update_step(struct YMZ280BVoice *voice); - void update_volumes(struct YMZ280BVoice *voice); - void update_irq_state_timer_common(int voicenum); - int generate_adpcm(struct YMZ280BVoice *voice, s16 *buffer, int samples); - int generate_pcm8(struct YMZ280BVoice *voice, s16 *buffer, int samples); - int generate_pcm16(struct YMZ280BVoice *voice, s16 *buffer, int samples); + void update_step(YMZ280BVoice *voice); + void update_volumes(YMZ280BVoice *voice); + TIMER_CALLBACK_MEMBER(update_irq_state_timer_common); + int generate_adpcm(YMZ280BVoice *voice, s16 *buffer, int samples); + int generate_pcm8(YMZ280BVoice *voice, s16 *buffer, int samples); + int generate_pcm16(YMZ280BVoice *voice, s16 *buffer, int samples); void write_to_register(int data); int compute_status(); // internal state - struct YMZ280BVoice m_voice[8]; /* the 8 voices */ + YMZ280BVoice m_voice[8]; /* the 8 voices */ u8 m_current_register; /* currently accessible register */ u8 m_status_register; /* current status register */ u8 m_irq_state; /* current IRQ state */ diff --git a/src/devices/video/315_5124.cpp b/src/devices/video/315_5124.cpp index 9afe518b6bc..7bb4fd18407 100644 --- a/src/devices/video/315_5124.cpp +++ b/src/devices/video/315_5124.cpp @@ -478,94 +478,81 @@ void sega315_5377_device::set_sega315_5124_compatibility_mode(bool sega315_5124_ } -void sega315_5124_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(sega315_5124_device::eol_flag_check) { - switch (id) - { - case TIMER_LINE: - process_line_timer(); - break; - - case TIMER_FLAGS: - /* Activate flags that were pending until the end of the line. */ - check_pending_flags(); - break; - - case TIMER_DRAW: - update_palette(); - draw_scanline(LBORDER_START + LBORDER_WIDTH, param, screen().vpos() - param); - break; + /* Activate flags that were pending until the end of the line. */ + check_pending_flags(); +} - case TIMER_LBORDER: - { - rectangle rec; - rec.min_y = rec.max_y = param; +TIMER_CALLBACK_MEMBER(sega315_5124_device::draw_lborder) +{ + rectangle rec; + rec.min_y = rec.max_y = param; - update_palette(); + update_palette(); - /* Draw left border */ - rec.min_x = LBORDER_START; - rec.max_x = LBORDER_START + LBORDER_WIDTH - 1; - m_tmpbitmap.fill(m_palette_lut->pen(m_current_palette[BACKDROP_COLOR]), rec); - m_y1_bitmap.fill((m_reg[0x07] & 0x0f) ? 1 : 0, rec); - } - break; + /* Draw left border */ + rec.min_x = LBORDER_START; + rec.max_x = LBORDER_START + LBORDER_WIDTH - 1; + m_tmpbitmap.fill(m_palette_lut->pen(m_current_palette[BACKDROP_COLOR]), rec); + m_y1_bitmap.fill((m_reg[0x07] & 0x0f) ? 1 : 0, rec); +} - case TIMER_RBORDER: - { - rectangle rec; - rec.min_y = rec.max_y = param; +TIMER_CALLBACK_MEMBER(sega315_5124_device::draw_rborder) +{ + rectangle rec; + rec.min_y = rec.max_y = param; - update_palette(); + update_palette(); - /* Draw right border */ - rec.min_x = LBORDER_START + LBORDER_WIDTH + 256; - rec.max_x = rec.min_x + RBORDER_WIDTH - 1; - m_tmpbitmap.fill(m_palette_lut->pen(m_current_palette[BACKDROP_COLOR]), rec); - m_y1_bitmap.fill((m_reg[0x07] & 0x0f) ? 1 : 0, rec); - } - break; + /* Draw right border */ + rec.min_x = LBORDER_START + LBORDER_WIDTH + 256; + rec.max_x = rec.min_x + RBORDER_WIDTH - 1; + m_tmpbitmap.fill(m_palette_lut->pen(m_current_palette[BACKDROP_COLOR]), rec); + m_y1_bitmap.fill((m_reg[0x07] & 0x0f) ? 1 : 0, rec); +} - case TIMER_HINT: - if (m_pending_hint || m_hint_occurred) +TIMER_CALLBACK_MEMBER(sega315_5124_device::trigger_hint) +{ + if (m_pending_hint || m_hint_occurred) + { + if (BIT(m_reg[0x00], 4)) { - if (BIT(m_reg[0x00], 4)) - { - m_n_int_state = 0; + m_n_int_state = 0; - if (!m_n_int_cb.isnull()) - m_n_int_cb(ASSERT_LINE); - } + if (!m_n_int_cb.isnull()) + m_n_int_cb(ASSERT_LINE); } - break; + } +} - case TIMER_VINT: - if ((m_pending_status & STATUS_VINT) || (m_status & STATUS_VINT)) +TIMER_CALLBACK_MEMBER(sega315_5124_device::trigger_vint) +{ + if ((m_pending_status & STATUS_VINT) || (m_status & STATUS_VINT)) + { + if (BIT(m_reg[0x01], 5)) { - if (BIT(m_reg[0x01], 5)) - { - m_n_int_state = 0; + m_n_int_state = 0; - if (!m_n_int_cb.isnull()) - m_n_int_cb(ASSERT_LINE); - } + if (!m_n_int_cb.isnull()) + m_n_int_cb(ASSERT_LINE); } - break; + } +} - case TIMER_NMI: - if (!m_n_nmi_in_state) - { - if (m_n_nmi_state) - m_n_nmi_cb(ASSERT_LINE); - } - else - { - if (!m_n_nmi_state) - m_n_nmi_cb(CLEAR_LINE); - } - m_n_nmi_state = m_n_nmi_in_state; - break; +TIMER_CALLBACK_MEMBER(sega315_5124_device::update_nmi) +{ + if (!m_n_nmi_in_state) + { + if (m_n_nmi_state) + m_n_nmi_cb(ASSERT_LINE); } + else + { + if (!m_n_nmi_state) + m_n_nmi_cb(CLEAR_LINE); + } + m_n_nmi_state = m_n_nmi_in_state; } @@ -583,7 +570,7 @@ void sega315_5377_device::vblank_end(int vpos) } -void sega315_5124_device::process_line_timer() +TIMER_CALLBACK_MEMBER(sega315_5124_device::process_line_timer) { const int vpos = screen().vpos(); int vpos_limit = m_frame_timing[VERTICAL_SYNC] + m_frame_timing[TOP_BLANKING] @@ -1723,8 +1710,14 @@ void sega315_5124_device::draw_scanline_mode3(int *line_buffer, int line) } -void sega315_5124_device::draw_scanline(int pixel_offset_x, int pixel_plot_y, int line) +TIMER_CALLBACK_MEMBER(sega315_5124_device::draw_scanline) { + int pixel_offset_x = LBORDER_START + LBORDER_WIDTH; + int pixel_plot_y = param; + int line = screen().vpos() - param; + + update_palette(); + int blitline_buffer[256]; int priority_selected[256]; @@ -2021,16 +2014,16 @@ void sega315_5124_device::device_start() screen().register_screen_bitmap(m_tmpbitmap); screen().register_screen_bitmap(m_y1_bitmap); - m_display_timer = timer_alloc(TIMER_LINE); + m_display_timer = timer_alloc(FUNC(sega315_5124_device::process_line_timer), this); m_display_timer->adjust(screen().time_until_pos(0, DISPLAY_CB_HPOS), 0, screen().scan_period()); - m_pending_flags_timer = timer_alloc(TIMER_FLAGS); + m_pending_flags_timer = timer_alloc(FUNC(sega315_5124_device::eol_flag_check), this); m_pending_flags_timer->adjust(screen().time_until_pos(0, WIDTH - 1), 0, screen().scan_period()); - m_draw_timer = timer_alloc(TIMER_DRAW); - m_lborder_timer = timer_alloc(TIMER_LBORDER); - m_rborder_timer = timer_alloc(TIMER_RBORDER); - m_hint_timer = timer_alloc(TIMER_HINT); - m_vint_timer = timer_alloc(TIMER_VINT); - m_nmi_timer = timer_alloc(TIMER_NMI); + m_draw_timer = timer_alloc(FUNC(sega315_5124_device::draw_scanline), this); + m_lborder_timer = timer_alloc(FUNC(sega315_5124_device::draw_lborder), this); + m_rborder_timer = timer_alloc(FUNC(sega315_5124_device::draw_rborder), this); + m_hint_timer = timer_alloc(FUNC(sega315_5124_device::trigger_hint), this); + m_vint_timer = timer_alloc(FUNC(sega315_5124_device::trigger_vint), this); + m_nmi_timer = timer_alloc(FUNC(sega315_5124_device::update_nmi), this); save_item(NAME(m_status)); save_item(NAME(m_pending_status)); diff --git a/src/devices/video/315_5124.h b/src/devices/video/315_5124.h index eaa78b0ac03..913fdb71e18 100644 --- a/src/devices/video/315_5124.h +++ b/src/devices/video/315_5124.h @@ -94,7 +94,6 @@ protected: virtual void device_post_load() 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 void device_add_mconfig(machine_config &config) override; virtual space_config_vector memory_space_config() const override; @@ -116,7 +115,6 @@ protected: virtual void select_sprites(int line); virtual void sprite_collision(int line, int sprite_col_x); virtual void sprite_count_overflow(int line, int sprite_index); - virtual void draw_scanline(int pixel_offset_x, int pixel_plot_y, int line); virtual void blit_scanline(int *line_buffer, int *priority_selected, int pixel_offset_x, int pixel_plot_y, int line); virtual void draw_leftmost_pixels_mode4(int *line_buffer, int *priority_selected, int fine_x_scroll, int palette_selected, int tile_line); virtual u16 name_row_mode4(u16 row); @@ -124,7 +122,14 @@ protected: virtual u16 tile2_select_mode4(u16 tile_number); virtual u8 sprite_attribute_extra_offset_mode4(u8 offset); virtual u8 sprite_tile_select_mode4(u8 tile_number); - void process_line_timer(); + TIMER_CALLBACK_MEMBER(process_line_timer); + TIMER_CALLBACK_MEMBER(eol_flag_check); + TIMER_CALLBACK_MEMBER(draw_lborder); + TIMER_CALLBACK_MEMBER(draw_rborder); + TIMER_CALLBACK_MEMBER(trigger_hint); + TIMER_CALLBACK_MEMBER(trigger_vint); + TIMER_CALLBACK_MEMBER(update_nmi); + TIMER_CALLBACK_MEMBER(draw_scanline); void draw_scanline_mode4(int *line_buffer, int *priority_selected, int line); void draw_sprites_mode4(int *line_buffer, int *priority_selected, int line); void draw_sprites_tms9918_mode(int *line_buffer, int line); @@ -198,16 +203,6 @@ protected: const address_space_config m_space_config; - /* Timers */ - static constexpr device_timer_id TIMER_LINE = 0; - static constexpr device_timer_id TIMER_DRAW = 1; - static constexpr device_timer_id TIMER_LBORDER = 2; - static constexpr device_timer_id TIMER_RBORDER = 3; - static constexpr device_timer_id TIMER_HINT = 4; - static constexpr device_timer_id TIMER_VINT = 5; - static constexpr device_timer_id TIMER_NMI = 6; - static constexpr device_timer_id TIMER_FLAGS = 7; - required_device<palette_device> m_palette_lut; required_device<sn76496_base_device> m_snsnd; }; diff --git a/src/devices/video/315_5313.cpp b/src/devices/video/315_5313.cpp index fad6d4a39de..c42ab3815e5 100644 --- a/src/devices/video/315_5313.cpp +++ b/src/devices/video/315_5313.cpp @@ -370,9 +370,9 @@ void sega315_5313_device::device_start() if (m_use_alt_timing) save_pointer(NAME(m_render_line), 1280); - m_irq6_on_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(sega315_5313_device::irq6_on_timer_callback), this)); - m_irq4_on_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(sega315_5313_device::irq4_on_timer_callback), this)); - m_render_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(sega315_5313_device::render_scanline), this)); + m_irq6_on_timer = timer_alloc(FUNC(sega315_5313_device::irq6_on_timer_callback), this); + m_irq4_on_timer = timer_alloc(FUNC(sega315_5313_device::irq4_on_timer_callback), this); + m_render_timer = timer_alloc(FUNC(sega315_5313_device::render_scanline), this); m_space68k = &m_cpu68k->space(); diff --git a/src/devices/video/catseye.cpp b/src/devices/video/catseye.cpp index dba0c6ac43f..46eeb917f37 100644 --- a/src/devices/video/catseye.cpp +++ b/src/devices/video/catseye.cpp @@ -70,7 +70,7 @@ void catseye_device::device_start() { m_int_write_func.resolve_safe(); - m_blink_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(catseye_device::blink_callback), this)); + m_blink_timer = timer_alloc(FUNC(catseye_device::blink_callback), this); m_blink_timer->adjust(attotime::from_hz(3)); save_item(NAME(m_changed)); diff --git a/src/devices/video/cdp1861.cpp b/src/devices/video/cdp1861.cpp index d8318896412..e19074045aa 100644 --- a/src/devices/video/cdp1861.cpp +++ b/src/devices/video/cdp1861.cpp @@ -115,9 +115,9 @@ void cdp1861_device::device_start() m_write_efx.resolve_safe(); // allocate timers - m_int_timer = timer_alloc(TIMER_INT); - m_efx_timer = timer_alloc(TIMER_EFX); - m_dma_timer = timer_alloc(TIMER_DMA); + m_int_timer = timer_alloc(FUNC(cdp1861_device::int_tick), this); + m_efx_timer = timer_alloc(FUNC(cdp1861_device::efx_tick), this); + m_dma_timer = timer_alloc(FUNC(cdp1861_device::dma_tick), this); // find devices screen().register_screen_bitmap(m_bitmap); @@ -151,91 +151,87 @@ void cdp1861_device::device_reset() //------------------------------------------------- -// device_timer - handle timer events +// timer events //------------------------------------------------- -void cdp1861_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(cdp1861_device::int_tick) { - int scanline = screen().vpos(); - - switch (id) + if (screen().vpos() == SCANLINE_INT_START) { - case TIMER_INT: - if (scanline == SCANLINE_INT_START) + if (m_disp) { - if (m_disp) - { - m_write_int(ASSERT_LINE); - } - - m_int_timer->adjust(screen().time_until_pos( SCANLINE_INT_END, 0)); + m_write_int(ASSERT_LINE); } - else - { - if (m_disp) - { - m_write_int(CLEAR_LINE); - } - m_int_timer->adjust(screen().time_until_pos(SCANLINE_INT_START, 0)); + m_int_timer->adjust(screen().time_until_pos( SCANLINE_INT_END, 0)); + } + else + { + if (m_disp) + { + m_write_int(CLEAR_LINE); } + + m_int_timer->adjust(screen().time_until_pos(SCANLINE_INT_START, 0)); + } +} + +TIMER_CALLBACK_MEMBER(cdp1861_device::efx_tick) +{ + switch (screen().vpos()) + { + case SCANLINE_EFX_TOP_START: + m_write_efx(ASSERT_LINE); + m_efx_timer->adjust(screen().time_until_pos(SCANLINE_EFX_TOP_END, 0)); break; - case TIMER_EFX: - switch (scanline) - { - case SCANLINE_EFX_TOP_START: - m_write_efx(ASSERT_LINE); - m_efx_timer->adjust(screen().time_until_pos(SCANLINE_EFX_TOP_END, 0)); - break; - - case SCANLINE_EFX_TOP_END: - m_write_efx(CLEAR_LINE); - m_efx_timer->adjust(screen().time_until_pos(SCANLINE_EFX_BOTTOM_START, 0)); - break; - - case SCANLINE_EFX_BOTTOM_START: - m_write_efx(ASSERT_LINE); - m_efx_timer->adjust(screen().time_until_pos(SCANLINE_EFX_BOTTOM_END, 0)); - break; - - case SCANLINE_EFX_BOTTOM_END: - m_write_efx(CLEAR_LINE); - m_efx_timer->adjust(screen().time_until_pos(SCANLINE_EFX_TOP_START, 0)); - break; - } + case SCANLINE_EFX_TOP_END: + m_write_efx(CLEAR_LINE); + m_efx_timer->adjust(screen().time_until_pos(SCANLINE_EFX_BOTTOM_START, 0)); + break; + + case SCANLINE_EFX_BOTTOM_START: + m_write_efx(ASSERT_LINE); + m_efx_timer->adjust(screen().time_until_pos(SCANLINE_EFX_BOTTOM_END, 0)); break; - case TIMER_DMA: - if (m_dmaout) + case SCANLINE_EFX_BOTTOM_END: + m_write_efx(CLEAR_LINE); + m_efx_timer->adjust(screen().time_until_pos(SCANLINE_EFX_TOP_START, 0)); + break; + } +} + +TIMER_CALLBACK_MEMBER(cdp1861_device::dma_tick) +{ + int scanline = screen().vpos(); + if (m_dmaout) + { + if (m_disp) { - if (m_disp) + if (scanline >= SCANLINE_DISPLAY_START && scanline < SCANLINE_DISPLAY_END) { - if (scanline >= SCANLINE_DISPLAY_START && scanline < SCANLINE_DISPLAY_END) - { - m_write_dma_out(CLEAR_LINE); - } + m_write_dma_out(CLEAR_LINE); } + } - m_dma_timer->adjust(clocks_to_attotime(CDP1861_CYCLES_DMA_WAIT)); + m_dma_timer->adjust(clocks_to_attotime(CDP1861_CYCLES_DMA_WAIT)); - m_dmaout = CLEAR_LINE; - } - else + m_dmaout = CLEAR_LINE; + } + else + { + if (m_disp) { - if (m_disp) + if (scanline >= SCANLINE_DISPLAY_START && scanline < SCANLINE_DISPLAY_END) { - if (scanline >= SCANLINE_DISPLAY_START && scanline < SCANLINE_DISPLAY_END) - { - m_write_dma_out(ASSERT_LINE); - } + m_write_dma_out(ASSERT_LINE); } + } - m_dma_timer->adjust(clocks_to_attotime(CDP1861_CYCLES_DMA_ACTIVE)); + m_dma_timer->adjust(clocks_to_attotime(CDP1861_CYCLES_DMA_ACTIVE)); - m_dmaout = ASSERT_LINE; - } - break; + m_dmaout = ASSERT_LINE; } } diff --git a/src/devices/video/cdp1861.h b/src/devices/video/cdp1861.h index 5e7eca7f8fc..c038223a50e 100644 --- a/src/devices/video/cdp1861.h +++ b/src/devices/video/cdp1861.h @@ -81,16 +81,12 @@ protected: virtual void device_config_complete() override; virtual void device_start() override; virtual void device_reset() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; -private: - enum - { - TIMER_INT, - TIMER_EFX, - TIMER_DMA - }; + TIMER_CALLBACK_MEMBER(int_tick); + TIMER_CALLBACK_MEMBER(efx_tick); + TIMER_CALLBACK_MEMBER(dma_tick); +private: devcb_write_line m_write_int; devcb_write_line m_write_dma_out; devcb_write_line m_write_efx; diff --git a/src/devices/video/clgd542x.cpp b/src/devices/video/clgd542x.cpp index d7e20f1cd2d..978e38e792e 100644 --- a/src/devices/video/clgd542x.cpp +++ b/src/devices/video/clgd542x.cpp @@ -89,7 +89,7 @@ void cirrus_gd5428_device::device_start() save_pointer(vga.attribute.data,"Attribute Registers", 0x15); save_item(NAME(m_chip_id)); - m_vblank_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(vga_device::vblank_timer_cb),this)); + m_vblank_timer = timer_alloc(FUNC(vga_device::vblank_timer_cb), this); m_chip_id = 0x98; // GD5428 - Rev 0 } diff --git a/src/devices/video/crt9007.cpp b/src/devices/video/crt9007.cpp index de8d7554b1a..347a06382a1 100644 --- a/src/devices/video/crt9007.cpp +++ b/src/devices/video/crt9007.cpp @@ -505,13 +505,13 @@ void crt9007_device::device_resolve_objects() void crt9007_device::device_start() { // allocate timers - m_hsync_timer = timer_alloc(TIMER_HSYNC); - m_vsync_timer = timer_alloc(TIMER_VSYNC); - m_vlt_timer = timer_alloc(TIMER_VLT); - m_curs_timer = timer_alloc(TIMER_CURS); - m_drb_timer = timer_alloc(TIMER_DRB); - m_dma_timer = timer_alloc(TIMER_DMA); - m_frame_timer = timer_alloc(TIMER_FRAME); + m_hsync_timer = timer_alloc(FUNC(crt9007_device::hsync_update), this); + m_vsync_timer = timer_alloc(FUNC(crt9007_device::vsync_update), this); + m_vlt_timer = timer_alloc(FUNC(crt9007_device::vlt_update), this); + m_curs_timer = timer_alloc(FUNC(crt9007_device::cursor_update), this); + m_drb_timer = timer_alloc(FUNC(crt9007_device::drb_update), this); + m_dma_timer = timer_alloc(FUNC(crt9007_device::dma_update), this); + m_frame_timer = timer_alloc(FUNC(crt9007_device::frame_update), this); // save state save_item(NAME(m_reg)); @@ -605,100 +605,97 @@ void crt9007_device::device_clock_changed() //------------------------------------------------- -// device_timer - handle timer events +// timer events //------------------------------------------------- -void crt9007_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(crt9007_device::hsync_update) { - int x = screen().hpos(); - int y = screen().vpos(); - - switch (id) - { - case TIMER_HSYNC: - m_hs = bool(param); - - LOG("CRT9007 y %03u x %04u : HS %u\n", y, x, m_hs); + m_hs = bool(param); - m_write_hs(m_hs); + LOG("CRT9007 y %03u x %04u : HS %u\n", screen().vpos(), screen().hpos(), m_hs); - update_cblank_line(); + m_write_hs(m_hs); - update_hsync_timer(m_hs); - break; + update_cblank_line(); - case TIMER_VSYNC: - m_vs = bool(param); + update_hsync_timer(m_hs); +} - LOG("CRT9007 y %03u x %04u : VS %u\n", y, x, m_vs); +TIMER_CALLBACK_MEMBER(crt9007_device::vsync_update) +{ + m_vs = bool(param); - m_write_vs(m_vs); + LOG("CRT9007 y %03u x %04u : VS %u\n", screen().vpos(), screen().hpos(), m_vs); - if (m_vs) - { - // reset all other bits except Light Pen Update to logic 0 - m_status &= (STATUS_LIGHT_PEN_UPDATE | STATUS_INTERRUPT_PENDING); - } - else - { - trigger_interrupt(IE_VERTICAL_RETRACE); + m_write_vs(m_vs); - update_cblank_line(); - } + if (m_vs) + { + // reset all other bits except Light Pen Update to logic 0 + m_status &= (STATUS_LIGHT_PEN_UPDATE | STATUS_INTERRUPT_PENDING); + } + else + { + trigger_interrupt(IE_VERTICAL_RETRACE); - update_vsync_timer(m_vs); - break; + update_cblank_line(); + } - case TIMER_VLT: - m_vlt = bool(param); + update_vsync_timer(m_vs); +} - LOG("CRT9007 y %03u x %04u : VLT %u\n", y, x, m_vlt); +TIMER_CALLBACK_MEMBER(crt9007_device::vlt_update) +{ + m_vlt = bool(param); - m_write_vlt(m_vlt); + LOG("CRT9007 y %03u x %04u : VLT %u\n", screen().vpos(), screen().hpos(), m_vlt); - update_vlt_timer(m_vlt); - break; + m_write_vlt(m_vlt); - case TIMER_CURS: - LOG("CRT9007 y %03u x %04u : CURS %u\n", y, x, param); + update_vlt_timer(m_vlt); +} - m_write_curs(param); +TIMER_CALLBACK_MEMBER(crt9007_device::cursor_update) +{ + LOG("CRT9007 y %03u x %04u : CURS %u\n", screen().vpos(), screen().hpos(), param); - update_curs_timer(param); - break; + m_write_curs(param); - case TIMER_DRB: - m_drb = bool(param); + update_curs_timer(param); +} - LOG("CRT9007 y %03u x %04u : DRB %u\n", y, x, m_drb); +TIMER_CALLBACK_MEMBER(crt9007_device::drb_update) +{ + m_drb = bool(param); - m_write_drb(m_drb); + LOG("CRT9007 y %03u x %04u : DRB %u\n", screen().vpos(), screen().hpos(), m_drb); - if (!m_drb && !DMA_DISABLE) - { - // start DMA burst sequence - m_dma_count = CHARACTERS_PER_DATA_ROW; - m_dma_burst = DMA_BURST_COUNT ? (DMA_BURST_COUNT * 4) : CHARACTERS_PER_DATA_ROW; - m_dma_delay = DMA_BURST_DELAY; - m_dmar = true; - - LOG("CRT9007 DMAR 1\n"); - m_write_dmar(ASSERT_LINE); - } + m_write_drb(m_drb); - update_drb_timer(m_drb); - break; + if (!m_drb && !DMA_DISABLE) + { + // start DMA burst sequence + m_dma_count = CHARACTERS_PER_DATA_ROW; + m_dma_burst = DMA_BURST_COUNT ? (DMA_BURST_COUNT * 4) : CHARACTERS_PER_DATA_ROW; + m_dma_delay = DMA_BURST_DELAY; + m_dmar = true; + + LOG("CRT9007 DMAR 1\n"); + m_write_dmar(ASSERT_LINE); + } - case TIMER_DMA: - readbyte(AUXILIARY_ADDRESS_2); + update_drb_timer(m_drb); +} - update_dma_timer(); - break; +TIMER_CALLBACK_MEMBER(crt9007_device::dma_update) +{ + readbyte(AUXILIARY_ADDRESS_2); + update_dma_timer(); +} - case TIMER_FRAME: - trigger_interrupt(IE_FRAME_TIMER); - break; - } +TIMER_CALLBACK_MEMBER(crt9007_device::frame_update) +{ + trigger_interrupt(IE_FRAME_TIMER); } diff --git a/src/devices/video/crt9007.h b/src/devices/video/crt9007.h index efa591bd1d0..433ca521f01 100644 --- a/src/devices/video/crt9007.h +++ b/src/devices/video/crt9007.h @@ -78,23 +78,19 @@ protected: virtual void device_reset() override; virtual void device_post_load() override; virtual void device_clock_changed() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; // device_memory_interface overrides virtual space_config_vector memory_space_config() const override; -private: - enum - { - TIMER_HSYNC, - TIMER_VSYNC, - TIMER_VLT, - TIMER_CURS, - TIMER_DRB, - TIMER_DMA, - TIMER_FRAME - }; + TIMER_CALLBACK_MEMBER(hsync_update); + TIMER_CALLBACK_MEMBER(vsync_update); + TIMER_CALLBACK_MEMBER(vlt_update); + TIMER_CALLBACK_MEMBER(cursor_update); + TIMER_CALLBACK_MEMBER(drb_update); + TIMER_CALLBACK_MEMBER(dma_update); + TIMER_CALLBACK_MEMBER(frame_update); +private: void crt9007(address_map &map); inline uint8_t readbyte(offs_t address); diff --git a/src/devices/video/crtc_ega.cpp b/src/devices/video/crtc_ega.cpp index 184800f2ef9..9e0accfc870 100644 --- a/src/devices/video/crtc_ega.cpp +++ b/src/devices/video/crtc_ega.cpp @@ -38,7 +38,8 @@ crtc_ega_device::crtc_ega_device(const machine_config &mconfig, const char *tag, , m_hpixels_per_column(0), m_cur(0), m_hsync(0), m_vsync(0), m_vblank(0), m_de(0) , m_character_counter(0), m_hsync_width_counter(0), m_line_counter(0), m_raster_counter(0), m_vsync_width_counter(0) , m_line_enable_ff(false), m_vsync_ff(0), m_adjust_active(0), m_line_address(0), m_cursor_x(0) - , m_line_timer(nullptr), m_de_off_timer(nullptr), m_cur_on_timer(nullptr), m_cur_off_timer(nullptr), m_hsync_on_timer(nullptr), m_hsync_off_timer(nullptr), m_light_pen_latch_timer(nullptr) + , m_line_timer(nullptr), m_de_off_timer(nullptr), m_cursor_on_timer(nullptr), m_cursor_off_timer(nullptr) + , m_hsync_on_timer(nullptr), m_hsync_off_timer(nullptr), m_light_pen_latch_timer(nullptr) , m_horiz_pix_total(0), m_vert_pix_total(0), m_max_visible_x(0), m_max_visible_y(0) , m_hsync_on_pos(0), m_hsync_off_pos(0), m_vsync_on_pos(0), m_vsync_off_pos(0) , m_current_disp_addr(0), m_light_pen_latched(0), m_has_valid_parameters(false) @@ -298,7 +299,7 @@ void crtc_ega_device::set_cur(int state) } -void crtc_ega_device::handle_line_timer() +TIMER_CALLBACK_MEMBER(crtc_ega_device::handle_line_timer) { int new_vsync = m_vsync; @@ -375,7 +376,7 @@ void crtc_ega_device::handle_line_timer() m_cursor_x = m_cursor_addr - m_line_address; /* Schedule CURSOR ON signal */ - m_cur_on_timer->adjust( attotime::from_ticks( m_cursor_x, m_clock ) ); + m_cursor_on_timer->adjust( attotime::from_ticks( m_cursor_x, m_clock ), 1 ); } } @@ -396,56 +397,49 @@ void crtc_ega_device::handle_line_timer() set_de( m_line_enable_ff ? true : false ); } - -void crtc_ega_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(crtc_ega_device::de_off_tick) { - switch (id) - { - case TIMER_LINE: - handle_line_timer(); - break; - - case TIMER_DE_OFF: - set_de( false ); - break; + set_de( false ); +} - case TIMER_CUR_ON: - set_cur( true ); +TIMER_CALLBACK_MEMBER(crtc_ega_device::cursor_on) +{ + set_cur( true ); - /* Schedule CURSOR off signal */ - m_cur_off_timer->adjust( attotime::from_ticks( 1, m_clock ) ); - break; + /* Schedule CURSOR off signal */ + m_cursor_off_timer->adjust( attotime::from_ticks( 1, m_clock ), 0 ); +} - case TIMER_CUR_OFF: - set_cur( false ); - break; +TIMER_CALLBACK_MEMBER(crtc_ega_device::cursor_off) +{ + set_cur( false ); +} - case TIMER_HSYNC_ON: - { - int8_t hsync_width = ( 0x20 | m_horiz_blank_end ) - ( m_horiz_blank_start & 0x1f ); +TIMER_CALLBACK_MEMBER(crtc_ega_device::hsync_on) +{ + int8_t hsync_width = ( 0x20 | m_horiz_blank_end ) - ( m_horiz_blank_start & 0x1f ); - if ( hsync_width <= 0 ) - { - hsync_width += 0x20; - } + if ( hsync_width <= 0 ) + { + hsync_width += 0x20; + } - m_hsync_width_counter = 0; - set_hsync( true ); + m_hsync_width_counter = 0; + set_hsync( true ); - /* Schedule HSYNC off signal */ - m_hsync_off_timer->adjust( attotime::from_ticks( hsync_width, m_clock ) ); - } - break; + /* Schedule HSYNC off signal */ + m_hsync_off_timer->adjust( attotime::from_ticks( hsync_width, m_clock ) ); +} - case TIMER_HSYNC_OFF: - set_hsync( false ); - break; +TIMER_CALLBACK_MEMBER(crtc_ega_device::hsync_off) +{ + set_hsync( false ); +} - case TIMER_LIGHT_PEN_LATCH: - m_light_pen_addr = get_ma(); - m_light_pen_latched = true; - break; - } +TIMER_CALLBACK_MEMBER(crtc_ega_device::latch_light_pen) +{ + m_light_pen_addr = get_ma(); + m_light_pen_latched = true; } @@ -605,13 +599,13 @@ void crtc_ega_device::device_start() m_end_update_cb.resolve(); /* create the timers */ - m_line_timer = timer_alloc(TIMER_LINE); - m_de_off_timer = timer_alloc(TIMER_DE_OFF); - m_cur_on_timer = timer_alloc(TIMER_CUR_ON); - m_cur_off_timer = timer_alloc(TIMER_CUR_OFF); - m_hsync_on_timer = timer_alloc(TIMER_HSYNC_ON); - m_hsync_off_timer = timer_alloc(TIMER_HSYNC_OFF); - m_light_pen_latch_timer = timer_alloc(TIMER_LIGHT_PEN_LATCH); + m_line_timer = timer_alloc(FUNC(crtc_ega_device::handle_line_timer), this); + m_de_off_timer = timer_alloc(FUNC(crtc_ega_device::de_off_tick), this); + m_cursor_on_timer = timer_alloc(FUNC(crtc_ega_device::cursor_on), this); + m_cursor_off_timer = timer_alloc(FUNC(crtc_ega_device::cursor_off), this); + m_hsync_on_timer = timer_alloc(FUNC(crtc_ega_device::hsync_on), this); + m_hsync_off_timer = timer_alloc(FUNC(crtc_ega_device::hsync_off), this); + m_light_pen_latch_timer = timer_alloc(FUNC(crtc_ega_device::latch_light_pen), this); /* Use some large startup values */ m_horiz_char_total = 0xff; diff --git a/src/devices/video/crtc_ega.h b/src/devices/video/crtc_ega.h index 1f1e65597ae..0a18cf7014a 100644 --- a/src/devices/video/crtc_ega.h +++ b/src/devices/video/crtc_ega.h @@ -73,7 +73,6 @@ 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: devcb_write_line m_res_out_de_cb; @@ -155,18 +154,10 @@ private: int16_t m_cursor_x; /* timers */ - static constexpr device_timer_id TIMER_LINE = 0; - static constexpr device_timer_id TIMER_DE_OFF = 1; - static constexpr device_timer_id TIMER_CUR_ON = 2; - static constexpr device_timer_id TIMER_CUR_OFF = 3; - static constexpr device_timer_id TIMER_HSYNC_ON = 4; - static constexpr device_timer_id TIMER_HSYNC_OFF = 5; - static constexpr device_timer_id TIMER_LIGHT_PEN_LATCH = 6; - emu_timer *m_line_timer; emu_timer *m_de_off_timer; - emu_timer *m_cur_on_timer; - emu_timer *m_cur_off_timer; + emu_timer *m_cursor_on_timer; + emu_timer *m_cursor_off_timer; emu_timer *m_hsync_on_timer; emu_timer *m_hsync_off_timer; emu_timer *m_light_pen_latch_timer; @@ -191,7 +182,13 @@ private: void set_vsync(int state); void set_vblank(int state); void set_cur(int state); - void handle_line_timer(); + TIMER_CALLBACK_MEMBER(handle_line_timer); + TIMER_CALLBACK_MEMBER(de_off_tick); + TIMER_CALLBACK_MEMBER(cursor_on); + TIMER_CALLBACK_MEMBER(cursor_off); + TIMER_CALLBACK_MEMBER(hsync_on); + TIMER_CALLBACK_MEMBER(hsync_off); + TIMER_CALLBACK_MEMBER(latch_light_pen); void update_cursor_state(); }; diff --git a/src/devices/video/dp8350.cpp b/src/devices/video/dp8350.cpp index 22e918b3374..e93960b5662 100644 --- a/src/devices/video/dp8350.cpp +++ b/src/devices/video/dp8350.cpp @@ -218,10 +218,10 @@ void dp835x_device::device_resolve_objects() void dp835x_device::device_start() { // create timers - m_hblank_start_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(dp835x_device::hblank_start), this)); - m_hblank_near_end_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(dp835x_device::hblank_near_end), this)); - m_hsync_on_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(dp835x_device::hsync_update), this)); - m_hsync_off_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(dp835x_device::hsync_update), this)); + m_hblank_start_timer = timer_alloc(FUNC(dp835x_device::hblank_start), this); + m_hblank_near_end_timer = timer_alloc(FUNC(dp835x_device::hblank_near_end), this); + m_hsync_on_timer = timer_alloc(FUNC(dp835x_device::hsync_update), this); + m_hsync_off_timer = timer_alloc(FUNC(dp835x_device::hsync_update), this); // save state save_item(NAME(m_60hz_refresh)); diff --git a/src/devices/video/ef9340_1.cpp b/src/devices/video/ef9340_1.cpp index 19a636d6ffb..05415b68c19 100644 --- a/src/devices/video/ef9340_1.cpp +++ b/src/devices/video/ef9340_1.cpp @@ -65,10 +65,10 @@ void ef9340_1_device::device_start() // let the screen create our temporary bitmap with the screen's dimensions screen().register_screen_bitmap(m_tmp_bitmap); - m_line_timer = timer_alloc(TIMER_LINE); + m_line_timer = timer_alloc(FUNC(ef9340_1_device::draw_scanline), this); m_line_timer->adjust(screen().time_until_pos(0, 0), 0, screen().scan_period()); - m_blink_timer = timer_alloc(TIMER_BLINK); + m_blink_timer = timer_alloc(FUNC(ef9340_1_device::blink_update), this); m_blink_timer->adjust(screen().time_until_pos(0, 0), 0, screen().frame_period()); // zerofill @@ -107,29 +107,19 @@ void ef9340_1_device::device_start() } -void ef9340_1_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(ef9340_1_device::blink_update) { - switch (id) - { - case TIMER_LINE: - ef9340_scanline(screen().vpos()); - break; - - case TIMER_BLINK: - // blink rate is approximately 0.5s - m_ef9340.blink_prescaler = (m_ef9340.blink_prescaler + 1) & 0x1f; - if (m_ef9340.R & 0x40 && m_ef9340.blink_prescaler == 24) - m_ef9340.blink_prescaler = 0; + // blink rate is approximately 0.5s + m_ef9340.blink_prescaler = (m_ef9340.blink_prescaler + 1) & 0x1f; + if (m_ef9340.R & 0x40 && m_ef9340.blink_prescaler == 24) + m_ef9340.blink_prescaler = 0; - if (m_ef9340.blink_prescaler == 0) - m_ef9340.blink = !m_ef9340.blink; - - break; - } + if (m_ef9340.blink_prescaler == 0) + m_ef9340.blink = !m_ef9340.blink; } -u16 ef9340_1_device::ef9340_get_c_addr(u8 x, u8 y) +u16 ef9340_1_device::get_c_addr(u8 x, u8 y) { if ((y & 0x18) == 0x18) { @@ -143,7 +133,7 @@ u16 ef9340_1_device::ef9340_get_c_addr(u8 x, u8 y) } -void ef9340_1_device::ef9340_inc_c() +void ef9340_1_device::inc_c() { m_ef9340.X++; if (m_ef9340.X == 40 || m_ef9340.X == 48 || m_ef9340.X == 56 || m_ef9340.X == 64) @@ -181,7 +171,7 @@ void ef9340_1_device::ef9341_write(u8 command, u8 b, u8 data) m_ef9340.X = m_ef9341.TA & 0x3f; break; case 0x60: // increment C - ef9340_inc_c(); + inc_c(); break; case 0x80: // load M m_ef9340.M = m_ef9341.TA; @@ -206,7 +196,7 @@ void ef9340_1_device::ef9341_write(u8 command, u8 b, u8 data) { if (b) { - u16 addr = ef9340_get_c_addr(m_ef9340.X, m_ef9340.Y) & 0x3ff; + u16 addr = get_c_addr(m_ef9340.X, m_ef9340.Y) & 0x3ff; m_ef9341.TB = data; m_ef9341.busy = true; @@ -215,7 +205,7 @@ void ef9340_1_device::ef9341_write(u8 command, u8 b, u8 data) case 0x00: // write m_ram_a[addr] = m_ef9341.TA; m_ram_b[addr] = m_ef9341.TB; - ef9340_inc_c(); + inc_c(); break; case 0x40: // write without increment @@ -271,7 +261,7 @@ u8 ef9340_1_device::ef9341_read(u8 command, u8 b) { if (b) { - u16 addr = ef9340_get_c_addr(m_ef9340.X, m_ef9340.Y) & 0x3ff; + u16 addr = get_c_addr(m_ef9340.X, m_ef9340.Y) & 0x3ff; data = m_ef9341.TB; m_ef9341.busy = true; @@ -280,7 +270,7 @@ u8 ef9340_1_device::ef9341_read(u8 command, u8 b) case 0x20: // read m_ef9341.TA = m_ram_a[addr]; m_ef9341.TB = m_ram_b[addr]; - ef9340_inc_c(); + inc_c(); break; case 0x60: // read without increment @@ -321,8 +311,9 @@ u8 ef9340_1_device::ef9341_read(u8 command, u8 b) } -void ef9340_1_device::ef9340_scanline(int vpos) +TIMER_CALLBACK_MEMBER(ef9340_1_device::draw_scanline) { + int vpos = screen().vpos(); vpos -= m_offset_y; if (vpos < 0) return; @@ -370,7 +361,7 @@ void ef9340_1_device::ef9340_scanline(int vpos) for (int x = 0; x < 40; x++) { int s = slice; - u16 addr = ef9340_get_c_addr(x, y_row); + u16 addr = get_c_addr(x, y_row); u8 a = m_ram_a[addr]; u8 b = m_ram_b[addr]; bool blink = m_ef9340.R & 0x80 && m_ef9340.blink; diff --git a/src/devices/video/ef9340_1.h b/src/devices/video/ef9340_1.h index 8f5c12e17fe..82e82eade27 100644 --- a/src/devices/video/ef9340_1.h +++ b/src/devices/video/ef9340_1.h @@ -68,18 +68,15 @@ public: protected: // device-level overrides virtual void device_start() 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; - inline u16 ef9340_get_c_addr(u8 x, u8 y); - inline void ef9340_inc_c(); + inline u16 get_c_addr(u8 x, u8 y); + inline void inc_c(); - void ef9340_scanline(int vpos); + TIMER_CALLBACK_MEMBER(draw_scanline); + TIMER_CALLBACK_MEMBER(blink_update); // timers - static constexpr device_timer_id TIMER_LINE = 0; - static constexpr device_timer_id TIMER_BLINK = 1; - emu_timer *m_line_timer; emu_timer *m_blink_timer; diff --git a/src/devices/video/ef9345.cpp b/src/devices/video/ef9345.cpp index 981b40f0c5e..df596e7f7a4 100644 --- a/src/devices/video/ef9345.cpp +++ b/src/devices/video/ef9345.cpp @@ -132,8 +132,8 @@ ts9347_device::ts9347_device(const machine_config &mconfig, const char *tag, dev void ef9345_device::device_start() { - m_busy_timer = timer_alloc(BUSY_TIMER); - m_blink_timer = timer_alloc(BLINKING_TIMER); + m_busy_timer = timer_alloc(FUNC(ef9345_device::clear_busy_flag), this); + m_blink_timer = timer_alloc(FUNC(ef9345_device::blink_tick), this); m_videoram = &space(0); @@ -192,20 +192,17 @@ void ef9345_device::device_reset() } //------------------------------------------------- -// device_timer - handler timer events +// timer events //------------------------------------------------- -void ef9345_device::device_timer(emu_timer &timer, device_timer_id id, int param) + +TIMER_CALLBACK_MEMBER(ef9345_device::clear_busy_flag) { - switch(id) - { - case BUSY_TIMER: - m_bf = 0; - break; + m_bf = 0; +} - case BLINKING_TIMER: - m_blink = !m_blink; - break; - } +TIMER_CALLBACK_MEMBER(ef9345_device::blink_tick) +{ + m_blink = !m_blink; } diff --git a/src/devices/video/ef9345.h b/src/devices/video/ef9345.h index 7c2f923574c..05db63cc150 100644 --- a/src/devices/video/ef9345.h +++ b/src/devices/video/ef9345.h @@ -52,7 +52,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_config_memory_interface overrides virtual space_config_vector memory_space_config() const override; @@ -60,12 +59,15 @@ protected: // address space configurations const address_space_config m_space_config; - // inline helper + // inline helpers inline uint16_t indexram(uint8_t r); inline uint16_t indexrom(uint8_t r); inline void inc_x(uint8_t r); inline void inc_y(uint8_t r); + TIMER_CALLBACK_MEMBER(clear_busy_flag); + TIMER_CALLBACK_MEMBER(blink_tick); + private: void set_busy_flag(int period); void draw_char_40(uint8_t *c, uint16_t x, uint16_t y); @@ -89,9 +91,6 @@ private: void ef9345(address_map &map); // internal state - static const device_timer_id BUSY_TIMER = 0; - static const device_timer_id BLINKING_TIMER = 1; - required_region_ptr<uint8_t> m_charset; address_space *m_videoram; diff --git a/src/devices/video/ef9365.cpp b/src/devices/video/ef9365.cpp index 774437e15ff..bb1495836c9 100644 --- a/src/devices/video/ef9365.cpp +++ b/src/devices/video/ef9365.cpp @@ -12,7 +12,7 @@ This is natively a "black and white" chip (1 bitplane), but it is possible to add more bitplanes to have colors with a hardware trick. The system don't have direct access to the video - memory, but indirect access is possible through the 0x0F command + memory, but indirect access is possible through the 0x0f command and some hardware glue logics. The current implementation emulate the main functions : @@ -39,7 +39,7 @@ - Clear Screen - Fill Screen - Clear X & Y registers - - Video RAM readback supported (Command 0x0F) + - Video RAM readback supported (Command 0x0f) What is NOT yet currently implemented: - Light pen support @@ -80,10 +80,10 @@ namespace { #define EF936X_REG_DELTAY 0x07 #define EF936X_REG_X_MSB 0x08 #define EF936X_REG_X_LSB 0x09 -#define EF936X_REG_Y_MSB 0x0A -#define EF936X_REG_Y_LSB 0x0B -#define EF936X_REG_XLP 0x0C -#define EF936X_REG_YLP 0x0D +#define EF936X_REG_Y_MSB 0x0a +#define EF936X_REG_Y_LSB 0x0b +#define EF936X_REG_XLP 0x0c +#define EF936X_REG_YLP 0x0d //------------------------------------------------- @@ -144,8 +144,8 @@ const char *const commands_names[]= DEFINE_DEVICE_TYPE(EF9365, ef9365_device, "ef9365", "Thomson EF9365") ROM_START( ef9365 ) - ROM_REGION( 0x1E0, "ef9365", 0 ) - ROM_LOAD( "charset_ef9365.rom", 0x0000, 0x01E0, CRC(8d3053be) SHA1(0f9a64d217a0f7f04ee0720d49c5b680ad0ae359) ) + ROM_REGION( 0x1e0, "ef9365", 0 ) + ROM_LOAD( "charset_ef9365.rom", 0x0000, 0x01e0, CRC(8d3053be) SHA1(0f9a64d217a0f7f04ee0720d49c5b680ad0ae359) ) ROM_END //------------------------------------------------- @@ -211,7 +211,7 @@ ef9365_device::ef9365_device(const machine_config &mconfig, const char *tag, dev void ef9365_device::set_nb_bitplanes(int nb_bitplanes) { - if( nb_bitplanes > 0 && nb_bitplanes <= 8 ) + if (nb_bitplanes > 0 && nb_bitplanes <= 8) { nb_of_bitplanes = nb_bitplanes; nb_of_colors = pow(2, nb_bitplanes); @@ -230,44 +230,44 @@ void ef9365_device::set_display_mode(int display_mode) bitplane_xres = 256; bitplane_yres = 256; vsync_scanline_pos = 250; - overflow_mask_x = 0xFF00; - overflow_mask_y = 0xFF00; + overflow_mask_x = 0xff00; + overflow_mask_y = 0xff00; break; case DISPLAY_MODE_512x512: bitplane_xres = 512; bitplane_yres = 512; vsync_scanline_pos = 506; - overflow_mask_x = 0xFE00; - overflow_mask_y = 0xFE00; + overflow_mask_x = 0xfe00; + overflow_mask_y = 0xfe00; break; case DISPLAY_MODE_512x256: bitplane_xres = 512; bitplane_yres = 256; vsync_scanline_pos = 250; - overflow_mask_x = 0xFE00; - overflow_mask_y = 0xFF00; + overflow_mask_x = 0xfe00; + overflow_mask_y = 0xff00; break; case DISPLAY_MODE_128x128: bitplane_xres = 128; bitplane_yres = 128; vsync_scanline_pos = 124; - overflow_mask_x = 0xFF80; - overflow_mask_y = 0xFF80; + overflow_mask_x = 0xff80; + overflow_mask_y = 0xff80; break; case DISPLAY_MODE_64x64: bitplane_xres = 64; bitplane_yres = 64; vsync_scanline_pos = 62; - overflow_mask_x = 0xFFC0; - overflow_mask_y = 0xFFC0; + overflow_mask_x = 0xffc0; + overflow_mask_y = 0xffc0; break; default: logerror("Invalid EF9365 Display mode: %02x\n", display_mode); bitplane_xres = 256; bitplane_yres = 256; vsync_scanline_pos = 250; - overflow_mask_x = 0xFF00; - overflow_mask_y = 0xFF00; + overflow_mask_x = 0xff00; + overflow_mask_y = 0xff00; break; } } @@ -277,9 +277,9 @@ void ef9365_device::set_display_mode(int display_mode) // into the palette //------------------------------------------------- -void ef9365_device::set_color_entry( int index, uint8_t r, uint8_t g, uint8_t b ) +void ef9365_device::set_color_entry(int index, uint8_t r, uint8_t g, uint8_t b) { - if( index < nb_of_colors ) + if (index < nb_of_colors) { m_palette->set_pen_color(index, rgb_t(r, g, b)); } @@ -294,7 +294,7 @@ void ef9365_device::set_color_entry( int index, uint8_t r, uint8_t g, uint8_t b // used by the chip to draw/fill the memory //------------------------------------------------- -void ef9365_device::set_color_filler( uint8_t color ) +void ef9365_device::set_color_filler(uint8_t color) { m_current_color = color; } @@ -307,7 +307,7 @@ void ef9365_device::device_start() { m_irq_handler.resolve_safe(); - m_busy_timer = timer_alloc(BUSY_TIMER); + m_busy_timer = timer_alloc(FUNC(ef9365_device::clear_busy_flag), this); m_videoram = &space(0); m_current_color = 0x00; @@ -317,7 +317,7 @@ void ef9365_device::device_start() m_irq_rdy = 0; m_irq_state = 0; - m_screen_out.allocate( bitplane_xres, screen().height() ); + m_screen_out.allocate(bitplane_xres, screen().height()); save_item(NAME(m_border)); save_item(NAME(m_registers)); @@ -362,9 +362,9 @@ void ef9365_device::device_reset() //------------------------------------------------- void ef9365_device::update_interrupts() { - int new_state = ( m_irq_vb && (m_registers[EF936X_REG_CTRL1] & 0x20) ) - || ( m_irq_rdy && (m_registers[EF936X_REG_CTRL1] & 0x40) ) - || ( m_irq_lb && (m_registers[EF936X_REG_CTRL1] & 0x10) ); + int new_state = (m_irq_vb && (m_registers[EF936X_REG_CTRL1] & 0x20)) + || (m_irq_rdy && (m_registers[EF936X_REG_CTRL1] & 0x40)) + || (m_irq_lb && (m_registers[EF936X_REG_CTRL1] & 0x10)); if (new_state != m_irq_state) { @@ -374,25 +374,19 @@ void ef9365_device::update_interrupts() } //------------------------------------------------- -// device_timer - handler timer events +// clear_busy_flag - //------------------------------------------------- -void ef9365_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(ef9365_device::clear_busy_flag) { - switch(id) - { - case BUSY_TIMER: - m_bf = 0; - - if( m_registers[EF936X_REG_CTRL1] & 0x40 ) - { - m_irq_rdy = 1; - } - - update_interrupts(); + m_bf = 0; - break; + if (m_registers[EF936X_REG_CTRL1] & 0x40) + { + m_irq_rdy = 1; } + + update_interrupts(); } //------------------------------------------------- @@ -412,7 +406,7 @@ void ef9365_device::set_busy_flag(int period) uint16_t ef9365_device::get_x_reg() { - return ((m_registers[EF936X_REG_X_MSB] & 0x0F)<<8) | m_registers[EF936X_REG_X_LSB]; + return ((m_registers[EF936X_REG_X_MSB] & 0x0f) << 8) | m_registers[EF936X_REG_X_LSB]; } //------------------------------------------------- @@ -421,7 +415,7 @@ uint16_t ef9365_device::get_x_reg() uint16_t ef9365_device::get_y_reg() { - return ((m_registers[EF936X_REG_Y_MSB] & 0x0F)<<8) | m_registers[EF936X_REG_Y_LSB]; + return ((m_registers[EF936X_REG_Y_MSB] & 0x0f) << 8) | m_registers[EF936X_REG_Y_LSB]; } //------------------------------------------------- @@ -430,8 +424,8 @@ uint16_t ef9365_device::get_y_reg() void ef9365_device::set_x_reg(uint16_t x) { - m_registers[EF936X_REG_X_MSB] = ( x >> 8 ) & 0x0F; - m_registers[EF936X_REG_X_LSB] = x & 0xFF; + m_registers[EF936X_REG_X_MSB] = (x >> 8) & 0x0f; + m_registers[EF936X_REG_X_LSB] = x & 0xff; } //------------------------------------------------- @@ -440,8 +434,8 @@ void ef9365_device::set_x_reg(uint16_t x) void ef9365_device::set_y_reg(uint16_t y) { - m_registers[EF936X_REG_Y_MSB] = ( y >> 8 ) & 0x0F; - m_registers[EF936X_REG_Y_LSB] = y & 0xFF; + m_registers[EF936X_REG_Y_MSB] = (y >> 8) & 0x0f; + m_registers[EF936X_REG_Y_LSB] = y & 0xff; } //------------------------------------------------- @@ -469,12 +463,12 @@ void ef9365_device::set_video_mode(void) // bitplane words //------------------------------------------------- -uint8_t ef9365_device::get_last_readback_word(int bitplane_number, int * pixel_offset) +uint8_t ef9365_device::get_last_readback_word(int bitplane_number, int *pixel_offset) { - if( pixel_offset ) + if (pixel_offset) *pixel_offset = m_readback_latch_pix_offset; - if( bitplane_number < nb_of_bitplanes ) + if (bitplane_number < nb_of_bitplanes) { return m_readback_latch[bitplane_number]; } @@ -486,7 +480,7 @@ uint8_t ef9365_device::get_last_readback_word(int bitplane_number, int * pixel_o //------------------------------------------------- // draw_border: Draw the left and right borders -// ( No border for the moment ;) ) +// ( No border for the moment ) //------------------------------------------------- void ef9365_device::draw_border(uint16_t line) @@ -498,33 +492,35 @@ void ef9365_device::draw_border(uint16_t line) // at the x & y position with the m_current_color color //------------------------------------------------- -void ef9365_device::plot(int x_pos,int y_pos) +void ef9365_device::plot(int x_pos, int y_pos) { - int p; - - if( ( x_pos >= 0 && y_pos >= 0 ) && ( x_pos < bitplane_xres && y_pos < bitplane_yres ) ) + if ((x_pos >= 0 && y_pos >= 0) && (x_pos < bitplane_xres && y_pos < bitplane_yres)) { - if ( m_registers[EF936X_REG_CTRL1] & 0x01 ) + if (m_registers[EF936X_REG_CTRL1] & 0x01) { - y_pos = ( (bitplane_yres - 1) - y_pos ); + y_pos = (bitplane_yres - 1) - y_pos; - if( (m_registers[EF936X_REG_CTRL1] & 0x02) ) + if (m_registers[EF936X_REG_CTRL1] & 0x02) { // Pen - for( p = 0 ; p < nb_of_bitplanes ; p++ ) + for (int p = 0; p < nb_of_bitplanes; p++) { - if( m_current_color & (0x01 << p) ) - m_videoram->write_byte ( (BITPLANE_MAX_SIZE*p) + (((y_pos*bitplane_xres) + x_pos)>>3), m_videoram->read_byte( (BITPLANE_MAX_SIZE*p) + (((y_pos*bitplane_xres) + x_pos)>>3)) | (0x80 >> (((y_pos*bitplane_xres) + x_pos)&7) ) ); + offs_t offset = BITPLANE_MAX_SIZE * p + ((y_pos * bitplane_xres + x_pos) >> 3); + uint8_t current_pix = m_videoram->read_byte(offset); + if (BIT(m_current_color, p)) + m_videoram->write_byte(offset, current_pix | (0x80 >> ((y_pos * bitplane_xres + x_pos) & 7))); else - m_videoram->write_byte ( (BITPLANE_MAX_SIZE*p) + (((y_pos*bitplane_xres) + x_pos)>>3), m_videoram->read_byte( (BITPLANE_MAX_SIZE*p) + (((y_pos*bitplane_xres) + x_pos)>>3)) & ~(0x80 >> (((y_pos*bitplane_xres) + x_pos)&7) ) ); + m_videoram->write_byte(offset, current_pix & ~(0x80 >> ((y_pos * bitplane_xres + x_pos) & 7))); } } else { // Eraser - for( p = 0 ; p < nb_of_bitplanes ; p++ ) + for (int p = 0; p < nb_of_bitplanes; p++) { - m_videoram->write_byte ( (BITPLANE_MAX_SIZE*p) + (((y_pos*bitplane_xres) + x_pos)>>3), m_videoram->read_byte( (BITPLANE_MAX_SIZE*p) + (((y_pos*bitplane_xres) + x_pos)>>3)) | (0x80 >> (((y_pos*bitplane_xres) + x_pos)&7) ) ); + offs_t offset = BITPLANE_MAX_SIZE * p + ((y_pos * bitplane_xres + x_pos) >> 3); + uint8_t current_pix = m_videoram->read_byte(offset); + m_videoram->write_byte(offset, current_pix | (0x80 >> ((y_pos * bitplane_xres + x_pos) & 7))); } } } @@ -532,68 +528,46 @@ void ef9365_device::plot(int x_pos,int y_pos) } -const static unsigned int vectortype_code[][8] = +const static uint8_t vectortype_code[4][8] = { - {0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, // Continuous drawing - {0x82,0x02,0x00,0x00,0x00,0x00,0x00,0x00}, // Dotted - 2 dots on, 2 dots off - {0x84,0x04,0x00,0x00,0x00,0x00,0x00,0x00}, // Dashed - 4 dots on, 4 dots off - {0x8A,0x02,0x82,0x02,0x00,0x00,0x00,0x00} // Dotted-Dashed - 10 dots on, 2 dots off, 2 dots on, 2 dots off + { 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // Continuous drawing + { 0x82, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // Dotted - 2 dots on, 2 dots off + { 0x84, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // Dashed - 4 dots on, 4 dots off + { 0x8a, 0x02, 0x82, 0x02, 0x00, 0x00, 0x00, 0x00 } // Dotted-Dashed - 10 dots on, 2 dots off, 2 dots on, 2 dots off }; //------------------------------------------------- // draw_vector: Vector drawing function -// from the start_x & start_y position to the start_x+delta_x & start_y+delta_y position -// with the m_current_color color +// from (start_x, start_y) to (start_x + delta_x, start_y + delta_y) +// with m_current_color // (Bresenham's line algorithm) //------------------------------------------------- -int ef9365_device::draw_vector(uint16_t start_x,uint16_t start_y,short delta_x,short delta_y) +int ef9365_device::draw_vector(uint16_t start_x, uint16_t start_y, int16_t delta_x, int16_t delta_y) { - int dx; - int dy,t; - int e; - int x,y,dest_x,dest_y,end_x,end_y; - int incy; - int diago,horiz; - unsigned char c1; + LOG("EF9365 draw_vector : Start=(%d,%d) End=(%d,%d)\n", start_x, start_y, start_x + delta_x, start_y + delta_y); - int pen_state; - unsigned int state_counter; - int dot_code_ptr; - int compute_cycles; + int compute_cycles = 0; - LOG("EF9365 draw_vector : Start=(%d,%d) End=(%d,%d)\n", start_x,start_y,start_x+delta_x,start_y+delta_y); + int16_t dest_x = start_x + delta_x; + int16_t dest_y = start_y + delta_y; - compute_cycles = 0; + int16_t end_x = dest_x; + int16_t end_y = dest_y; - dest_x = start_x + delta_x; - dest_y = start_y + delta_y; + uint8_t c1 = 0; + int16_t incy = 1; - end_x = dest_x; - end_y = dest_y; - - c1=0; - incy=1; - - dot_code_ptr = 0; - state_counter = vectortype_code[m_registers[EF936X_REG_CTRL2] & 0x3][dot_code_ptr&7]; - if(state_counter&0x80) - pen_state = 1; - else - pen_state = 0; + uint8_t dot_code_ptr = 0; + uint8_t state_counter = vectortype_code[m_registers[EF936X_REG_CTRL2] & 3][dot_code_ptr & 7]; + uint8_t pen_state = BIT(state_counter, 7); state_counter &= ~0x80; - if( dest_x > start_x ) - dx = dest_x - start_x; - else - dx = start_x - dest_x; - - if( dest_y > start_y ) - dy = dest_y - start_y; - else - dy = start_y - dest_y; + int16_t dx = (dest_x > start_x) ? (dest_x - start_x) : (start_x - dest_x); + int16_t dy = (dest_y > start_y) ? (dest_y - start_y) : (start_y - dest_y); - if( dy > dx ) + int16_t t; + if (dy > dx) { t = dest_y; dest_y = dest_x; @@ -610,7 +584,7 @@ int ef9365_device::draw_vector(uint16_t start_x,uint16_t start_y,short delta_x,s c1 = 1; } - if( start_x > dest_x ) + if (start_x > dest_x) { t = dest_y; dest_y = start_y; @@ -621,23 +595,23 @@ int ef9365_device::draw_vector(uint16_t start_x,uint16_t start_y,short delta_x,s dest_x = t; } - horiz = dy<<1; - diago = ( dy - dx )<<1; - e = ( dy<<1 ) - dx; + int16_t horiz = dy << 1; + int16_t diago = (dy - dx) << 1; + int16_t e = (dy << 1) - dx; - if( start_y <= dest_y ) + if (start_y <= dest_y) incy = 1; else incy = -1; - x = start_x; - y = start_y; + int16_t x = start_x; + int16_t y = start_y; - if(c1) + if (c1) { do { - if(pen_state) + if (pen_state) plot(y % bitplane_xres, x % bitplane_yres); compute_cycles++; @@ -647,31 +621,23 @@ int ef9365_device::draw_vector(uint16_t start_x,uint16_t start_y,short delta_x,s state_counter--; - if( !state_counter ) + if (!state_counter) { dot_code_ptr++; - state_counter = vectortype_code[m_registers[EF936X_REG_CTRL2] & 0x3][dot_code_ptr&7]; + state_counter = vectortype_code[m_registers[EF936X_REG_CTRL2] & 3][dot_code_ptr & 7]; - if(!state_counter) + if (!state_counter) { dot_code_ptr = 0; - state_counter = vectortype_code[m_registers[EF936X_REG_CTRL2] & 0x3][dot_code_ptr&7]; - } - - if( state_counter & 0x80 ) - { - pen_state = 1; - } - else - { - pen_state = 0; + state_counter = vectortype_code[m_registers[EF936X_REG_CTRL2] & 3][dot_code_ptr & 7]; } + pen_state = BIT(state_counter, 7); state_counter &= ~0x80; } - if( e > 0 ) + if (e > 0) { y = y + incy; e = e + diago; @@ -689,7 +655,7 @@ int ef9365_device::draw_vector(uint16_t start_x,uint16_t start_y,short delta_x,s { do { - if(pen_state) + if (pen_state) plot(x % bitplane_xres, y % bitplane_yres); compute_cycles++; @@ -699,31 +665,23 @@ int ef9365_device::draw_vector(uint16_t start_x,uint16_t start_y,short delta_x,s state_counter--; - if( !state_counter ) + if (!state_counter) { dot_code_ptr++; - state_counter = vectortype_code[m_registers[EF936X_REG_CTRL2] & 0x3][dot_code_ptr&7]; + state_counter = vectortype_code[m_registers[EF936X_REG_CTRL2] & 3][dot_code_ptr&7]; - if(!state_counter) + if (!state_counter) { dot_code_ptr = 0; - state_counter = vectortype_code[m_registers[EF936X_REG_CTRL2] & 0x3][dot_code_ptr&7]; - } - - if( state_counter & 0x80 ) - { - pen_state = 1; - } - else - { - pen_state = 0; + state_counter = vectortype_code[m_registers[EF936X_REG_CTRL2] & 3][dot_code_ptr&7]; } + pen_state = BIT(state_counter, 7); state_counter &= ~0x80; } - if( e > 0 ) + if (e > 0) { y = y + incy; e = e + diago; @@ -749,18 +707,16 @@ int ef9365_device::draw_vector(uint16_t start_x,uint16_t start_y,short delta_x,s // from the charset. //------------------------------------------------- -int ef9365_device::get_char_pix( unsigned char c, int x, int y ) +int ef9365_device::get_char_pix(uint8_t c, int x, int y) { - int char_base,char_pix; - - if(c<96) + if (c < 96) { - if( x < 5 && y < 8 ) + if (x < 5 && y < 8) { - char_base = c * 5; - char_pix = ( y * 5 ) + x; + uint32_t char_base = c * 5; + uint32_t char_pix = (y * 5) + x; - if ( m_charset[char_base + (char_pix>>3)] & ( 0x80 >> (char_pix&7)) ) + if (BIT(m_charset[char_base + (char_pix >> 3)], ~char_pix & 7)) return 1; else return 0; @@ -776,87 +732,73 @@ int ef9365_device::get_char_pix( unsigned char c, int x, int y ) // Set block to draw a 5x8 block //------------------------------------------------- -int ef9365_device::draw_character( unsigned char c, int block, int smallblock ) +int ef9365_device::draw_character(uint8_t c, bool block, bool smallblock) { - int x_char,y_char; - unsigned int x, y; - int x_char_res,y_char_res; - int p_factor,q_factor,p,q; - int compute_cycles; - - x = get_x_reg(); - y = get_y_reg(); + uint16_t x = get_x_reg(); + uint16_t y = get_y_reg(); - x_char_res = 5; - y_char_res = 8; + int x_char_res = 5; + int y_char_res = 8; - if( smallblock ) + if (smallblock) { - block = 1; + block = true; x_char_res = 4; y_char_res = 4; } - p_factor = (m_registers[EF936X_REG_CSIZE] >> 4); - if(!p_factor) + uint8_t p_factor = m_registers[EF936X_REG_CSIZE] >> 4; + if (!p_factor) p_factor = 16; - q_factor = (m_registers[EF936X_REG_CSIZE] & 0xF); - if(!q_factor) + uint8_t q_factor = m_registers[EF936X_REG_CSIZE] & 0xf; + if (!q_factor) q_factor = 16; - compute_cycles = ( ( x_char_res + 1 ) * p_factor ) * ( y_char_res * q_factor ); + int compute_cycles = ((x_char_res + 1) * p_factor) * (y_char_res * q_factor); - if(c<96) + if (c < 0x60) { - for( x_char=0 ; x_char < x_char_res ; x_char++ ) + for (int x_char = 0; x_char < x_char_res; x_char++) { - for( y_char = y_char_res - 1 ; y_char >= 0 ; y_char-- ) + for (int y_char = y_char_res - 1; y_char >= 0; y_char--) { - if ( block || get_char_pix( c, x_char, ( (y_char_res - 1) - y_char ) ) ) + if (block || get_char_pix(c, x_char, ((y_char_res - 1) - y_char))) { - if( m_registers[EF936X_REG_CTRL2] & 0x04) // Tilted character + if (m_registers[EF936X_REG_CTRL2] & 0x04) // Oblique mode { - for(q = 0; q < q_factor; q++) + for (uint16_t q = 0; q < q_factor; q++) { - for(p = 0; p < p_factor; p++) + for (uint16_t p = 0; p < p_factor; p++) { - if( !(m_registers[EF936X_REG_CTRL2] & 0x08) ) - { // Tilted - Horizontal orientation - plot( - x + ( (y_char*q_factor) + q ) + ( (x_char*p_factor) + p ), - y + ( (y_char*q_factor) + q ) - ); + if (!(m_registers[EF936X_REG_CTRL2] & 0x08)) + { + // Oblique - Horizontal orientation + plot(x + ((y_char * q_factor) + q) + ((x_char * p_factor) + p), y + ((y_char * q_factor) + q)); } else - { // Tilted - Vertical orientation - plot( - x - ( (y_char*q_factor)+ q ), - y + ( (x_char*p_factor)+ p ) - ( ( ( (y_char_res - 1 ) - y_char) * q_factor ) + ( q_factor - q ) ) - ); + { + // Oblique - Vertical orientation + plot(x - ((y_char * q_factor) + q), y + ((x_char * p_factor) + p) - ((((y_char_res - 1) - y_char) * q_factor) + (q_factor - q))); } } } } else { - for(q = 0; q < q_factor; q++) + for (uint16_t q = 0; q < q_factor; q++) { - for(p = 0; p < p_factor; p++) + for (uint16_t p = 0; p < p_factor; p++) { - if( !(m_registers[EF936X_REG_CTRL2] & 0x08) ) - { // Normal - Horizontal orientation - plot( - x + ( (x_char*p_factor) + p ), - y + ( (y_char*q_factor) + q ) - ); + if (!(m_registers[EF936X_REG_CTRL2] & 0x08)) + { + // Normal - Horizontal orientation + plot(x + ((x_char * p_factor) + p), y + ((y_char * q_factor) + q)); } else - { // Normal - Vertical orientation - plot( - x - ( (y_char*q_factor) + q ), - y + ( (x_char*p_factor) + p ) - ); + { + // Normal - Vertical orientation + plot(x - ((y_char * q_factor) + q), y + ((x_char * p_factor) + p)); } } } @@ -864,17 +806,15 @@ int ef9365_device::draw_character( unsigned char c, int block, int smallblock ) } } } + } - if(!(m_registers[EF936X_REG_CTRL2] & 0x08)) - { - x = x + ( (x_char_res + 1 ) * p_factor ) ; - set_x_reg(x); - } - else - { - y = y + ( (x_char_res + 1 ) * p_factor ) ; - set_y_reg(y); - } + if (!(m_registers[EF936X_REG_CTRL2] & 0x08)) + { + set_x_reg(x + (x_char_res + 1) * p_factor); + } + else + { + set_y_reg(y + (x_char_res + 1) * p_factor); } return compute_cycles; @@ -886,7 +826,7 @@ int ef9365_device::draw_character( unsigned char c, int block, int smallblock ) int ef9365_device::cycles_to_us(int cycles) { - return ( (float)cycles * ( (float)1000000 / (float)clock_freq ) ); + return (int)(cycles * (1000000.f / clock_freq)); } //------------------------------------------------- @@ -897,62 +837,66 @@ int ef9365_device::cycles_to_us(int cycles) void ef9365_device::dump_bitplanes_word() { - int p; - int pixel_ptr; + int pixel_ptr = (((bitplane_yres - 1) - (get_y_reg() & (bitplane_yres - 1))) * bitplane_xres) + (get_x_reg() & (bitplane_xres - 1)); - pixel_ptr = ( ( ( ( bitplane_yres - 1 ) - ( get_y_reg() & ( bitplane_yres - 1 ) ) ) * bitplane_xres ) + ( get_x_reg() & ( bitplane_xres - 1 ) ) ); + LOG("dump : x = %d , y = %d\n", get_x_reg(), get_y_reg()); - LOG("dump : x = %d , y = %d\n", get_x_reg() ,get_y_reg()); - - for( p = 0; p < nb_of_bitplanes ; p++ ) + for (int p = 0; p < nb_of_bitplanes; p++) { - if( pixel_ptr & 0x4 ) + const uint8_t value = m_videoram->read_byte(BITPLANE_MAX_SIZE * p + (pixel_ptr >> 3)); + if (pixel_ptr & 0x4) { - m_readback_latch[p] = ( m_videoram->read_byte( (BITPLANE_MAX_SIZE*p) + (pixel_ptr>>3) ) ) & 0xF ; + m_readback_latch[p] = value & 0xf; } else { - m_readback_latch[p] = ( m_videoram->read_byte( (BITPLANE_MAX_SIZE*p) + (pixel_ptr>>3) ) >> 4 ) & 0xF ; + m_readback_latch[p] = (value >> 4) & 0xf; } } - m_readback_latch_pix_offset = pixel_ptr & 0x3; + m_readback_latch_pix_offset = pixel_ptr & 3; } //------------------------------------------------- // screen_scanning: Fill / Clear framebuffer memory //------------------------------------------------- -void ef9365_device::screen_scanning( int force_clear ) +void ef9365_device::screen_scanning(bool force_clear) { - int x,y,p; - - if( (m_registers[EF936X_REG_CTRL1] & 0x02) && !force_clear ) + if ((m_registers[EF936X_REG_CTRL1] & 0x02) && !force_clear) { - for( y = 0; y < bitplane_yres; y++ ) + for (int y = 0; y < bitplane_yres; y++) { - for( x = 0; x < bitplane_xres; x++ ) + for (int x = 0; x < bitplane_xres; x++) { - for( p = 0 ; p < nb_of_bitplanes ; p++ ) + for (int p = 0; p < nb_of_bitplanes; p++) { - if( m_current_color & (0x01 << p) ) - m_videoram->write_byte ( (BITPLANE_MAX_SIZE*p) + (((y*bitplane_xres) + x)>>3), m_videoram->read_byte( (BITPLANE_MAX_SIZE*p) + (((y*bitplane_xres) + x)>>3)) | (0x80 >> (((y*bitplane_xres) + x)&7) ) ); + offs_t offset = BITPLANE_MAX_SIZE * p + ((y * bitplane_xres + x) >> 3); + uint8_t current_pix = m_videoram->read_byte(offset); + if (BIT(m_current_color, p)) + { + m_videoram->write_byte(offset, current_pix | (0x80 >> ((y * bitplane_xres + x) & 7))); + } else - m_videoram->write_byte ( (BITPLANE_MAX_SIZE*p) + (((y*bitplane_xres) + x)>>3), m_videoram->read_byte( (BITPLANE_MAX_SIZE*p) + (((y*bitplane_xres) + x)>>3)) & ~(0x80 >> (((y*bitplane_xres) + x)&7) ) ); + { + m_videoram->write_byte(offset, current_pix & ~(0x80 >> ((y * bitplane_xres + x) & 7))); + } } } } } else { - for( y = 0; y < bitplane_yres; y++) + for (int y = 0; y < bitplane_yres; y++) { - for( x = 0; x < bitplane_xres; x++) + for (int x = 0; x < bitplane_xres; x++) { - for( p = 0 ; p < nb_of_bitplanes ; p++ ) + for (int p = 0; p < nb_of_bitplanes; p++) { - m_videoram->write_byte ( (BITPLANE_MAX_SIZE*p) + (((y*bitplane_xres) + x)>>3), m_videoram->read_byte( (BITPLANE_MAX_SIZE*p) + (((y*bitplane_xres) + x)>>3)) | (0x80 >> (((y*bitplane_xres) + x)&7) ) ); + offs_t offset = BITPLANE_MAX_SIZE * p + ((y * bitplane_xres + x) >> 3); + uint8_t current_pix = m_videoram->read_byte(offset); + m_videoram->write_byte(offset, current_pix | (0x80 >> ((y * bitplane_xres + x) & 7))); } } } @@ -965,177 +909,177 @@ void ef9365_device::screen_scanning( int force_clear ) void ef9365_device::ef9365_exec(uint8_t cmd) { - int tmp_delta_x,tmp_delta_y; - int busy_cycles = 0; m_state = 0; - if( ( cmd>>4 ) == 0 ) + if ((cmd >> 4) == 0) { - LOG("EF9365 Command : %s\n", commands_names[cmd & 0xF]); + LOG("EF9365 Command : %s\n", commands_names[cmd & 0xf]); - switch(cmd & 0xF) + // All commands need time checked on the real hardware + int busy_cycles = 4; + switch(cmd & 0xf) { case 0x0: // Set bit 1 of CTRL1 : Pen Selection m_registers[EF936X_REG_CTRL1] |= 0x02; - set_busy_flag( cycles_to_us( 4 ) ); // Timing to check on the real hardware - break; + break; case 0x1: // Clear bit 1 of CTRL1 : Eraser Selection m_registers[EF936X_REG_CTRL1] &= (~0x02); - set_busy_flag( cycles_to_us( 4 ) ); // Timing to check on the real hardware - break; + break; case 0x2: // Set bit 0 of CTRL1 : Pen/Eraser down selection m_registers[EF936X_REG_CTRL1] |= 0x01; - set_busy_flag( cycles_to_us( 4 ) ); // Timing to check on the real hardware - break; + break; case 0x3: // Clear bit 0 of CTRL1 : Pen/Eraser up selection m_registers[EF936X_REG_CTRL1] &= (~0x01); - set_busy_flag( cycles_to_us( 4 ) ); // Timing to check on the real hardware - break; + break; case 0x4: // Clear screen screen_scanning(1); - set_busy_flag( cycles_to_us( bitplane_xres*bitplane_yres ) ); // Timing to check on the real hardware - break; + busy_cycles = bitplane_xres * bitplane_yres; + break; case 0x5: // X and Y registers reset to 0 set_x_reg(0); set_y_reg(0); - set_busy_flag( cycles_to_us( 4 ) ); // Timing to check on the real hardware - break; + break; case 0x6: // X and Y registers reset to 0 and clear screen set_x_reg(0); set_y_reg(0); screen_scanning(1); - set_busy_flag( cycles_to_us( bitplane_xres*bitplane_yres ) ); // Timing to check on the real hardware - break; + busy_cycles = bitplane_xres * bitplane_yres; + break; case 0x7: // Clear screen, set CSIZE to code "minsize". All other registers reset to 0 m_registers[EF936X_REG_CSIZE] = 0x11; screen_scanning(1); - set_busy_flag( cycles_to_us( bitplane_xres*bitplane_yres ) ); // Timing to check on the real hardware - break; + busy_cycles = bitplane_xres * bitplane_yres; + break; case 0x8: // Light-pen initialization (/White forced low) - set_busy_flag( cycles_to_us( 4 ) ); // Timing to check on the real hardware - break; + break; case 0x9: // Light-pen initialization - set_busy_flag( cycles_to_us( 4 ) ); // Timing to check on the real hardware - break; - case 0xA: // 5x8 block drawing (size according to CSIZE) - busy_cycles = draw_character( 0x00 , 1 , 0 ); - set_busy_flag( cycles_to_us( busy_cycles ) ); - break; - case 0xB: // 4x4 block drawing (size according to CSIZE) - busy_cycles = draw_character( 0x00 , 1 , 1 ); - set_busy_flag( cycles_to_us( busy_cycles ) ); - break; - case 0xC: // Screen scanning : pen or Eraser as defined by CTRL1 + break; + case 0xa: // 5x8 block drawing (size according to CSIZE) + busy_cycles = draw_character(0x00, true, false); + break; + case 0xb: // 4x4 block drawing (size according to CSIZE) + busy_cycles = draw_character(0x00, true, true); + break; + case 0xc: // Screen scanning : pen or Eraser as defined by CTRL1 screen_scanning(0); - set_busy_flag( cycles_to_us( bitplane_xres*bitplane_yres ) ); // Timing to check on the real hardware - break; - case 0xD: // X reset to 0 + busy_cycles = bitplane_xres * bitplane_yres; + break; + case 0xd: // X reset to 0 set_x_reg(0); - set_busy_flag( cycles_to_us( 4 ) ); // Timing to check on the real hardware - break; - case 0xE: // Y reset to 0 + break; + case 0xe: // Y reset to 0 set_y_reg(0); - set_busy_flag( cycles_to_us( 4 ) ); // Timing to check on the real hardware - break; - case 0xF: // Direct image memory access request for the next free cycle. - set_busy_flag( cycles_to_us( 64 ) ); // Timing to check on the real hardware + break; + case 0xf: // Direct image memory access request for the next free cycle. + busy_cycles = 64; dump_bitplanes_word(); - break; + break; default: logerror("Unemulated EF9365 cmd: %02x\n", cmd); + busy_cycles = 0; + break; + } + + if (busy_cycles) + { + set_busy_flag(cycles_to_us(busy_cycles)); } } else { - if ( ( cmd>>4 ) == 1 ) + if ((cmd >> 4) == 1) { - if( cmd & 0x08 ) + int busy_cycles = 0; + + if (cmd & 0x08) LOG("EF9365 Command : [0x%.2X] %s\n", cmd, commands_names[0x11]); else LOG("EF9365 Command : [0x%.2X] %s\n", cmd, commands_names[0x10]); - tmp_delta_x = m_registers[EF936X_REG_DELTAX]; - tmp_delta_y = m_registers[EF936X_REG_DELTAY]; + int tmp_delta_x = m_registers[EF936X_REG_DELTAX]; + int tmp_delta_y = m_registers[EF936X_REG_DELTAY]; - if( cmd & 0x08 ) + if (cmd & 0x08) { - if(tmp_delta_x > tmp_delta_y ) + if (tmp_delta_x > tmp_delta_y) tmp_delta_y = tmp_delta_x; - if(tmp_delta_y > tmp_delta_x ) + if (tmp_delta_y > tmp_delta_x) tmp_delta_y = tmp_delta_x; } // Vector / Special direction vector generation - switch ( cmd & 0x7 ) // Direction code + switch (cmd & 0x7) // Direction code { case 0x1: - busy_cycles = draw_vector ( get_x_reg(), get_y_reg(), tmp_delta_x, tmp_delta_y ); - break; + busy_cycles = draw_vector(get_x_reg(), get_y_reg(), tmp_delta_x, tmp_delta_y); + break; case 0x3: - busy_cycles = draw_vector ( get_x_reg(), get_y_reg(), -tmp_delta_x, tmp_delta_y ); - break; + busy_cycles = draw_vector(get_x_reg(), get_y_reg(), -tmp_delta_x, tmp_delta_y); + break; case 0x5: - busy_cycles = draw_vector ( get_x_reg(), get_y_reg(), tmp_delta_x, -tmp_delta_y ); - break; + busy_cycles = draw_vector(get_x_reg(), get_y_reg(), tmp_delta_x, -tmp_delta_y); + break; case 0x7: - busy_cycles = draw_vector ( get_x_reg(), get_y_reg(), -tmp_delta_x, -tmp_delta_y ); - break; + busy_cycles = draw_vector(get_x_reg(), get_y_reg(), -tmp_delta_x, -tmp_delta_y); + break; case 0x0: - busy_cycles = draw_vector ( get_x_reg(), get_y_reg(), tmp_delta_x, 0 ); - break; + busy_cycles = draw_vector(get_x_reg(), get_y_reg(), tmp_delta_x, 0); + break; case 0x2: - busy_cycles = draw_vector ( get_x_reg(), get_y_reg(), 0, tmp_delta_y ); - break; + busy_cycles = draw_vector(get_x_reg(), get_y_reg(), 0, tmp_delta_y); + break; case 0x4: - busy_cycles = draw_vector ( get_x_reg(), get_y_reg(), 0, -tmp_delta_y ); - break; + busy_cycles = draw_vector(get_x_reg(), get_y_reg(), 0, -tmp_delta_y); + break; case 0x6: - busy_cycles = draw_vector ( get_x_reg(), get_y_reg(), -tmp_delta_x , 0 ); - break; + busy_cycles = draw_vector(get_x_reg(), get_y_reg(), -tmp_delta_x, 0); + break; } - set_busy_flag( cycles_to_us( busy_cycles ) ); + set_busy_flag(cycles_to_us(busy_cycles)); } else { - if( ( cmd>>4 ) >= 0x8 ) + if ((cmd >> 4) >= 0x8) { + int busy_cycles = 0; + LOG("EF9365 Command : [0x%.2X] %s\n", cmd, commands_names[0x13]); - tmp_delta_x = ( cmd >> 5 ) & 3; - tmp_delta_y = ( cmd >> 3 ) & 3; + int tmp_delta_x = (cmd >> 5) & 3; + int tmp_delta_y = (cmd >> 3) & 3; // Small vector. - switch ( cmd & 0x7 ) // Direction code + switch (cmd & 0x7) // Direction code { case 0x1: - busy_cycles = draw_vector ( get_x_reg(), get_y_reg(), tmp_delta_x, tmp_delta_y ); - break; + busy_cycles = draw_vector(get_x_reg(), get_y_reg(), tmp_delta_x, tmp_delta_y); + break; case 0x3: - busy_cycles = draw_vector ( get_x_reg(), get_y_reg(), -tmp_delta_x, tmp_delta_y ); - break; + busy_cycles = draw_vector(get_x_reg(), get_y_reg(), -tmp_delta_x, tmp_delta_y); + break; case 0x5: - busy_cycles = draw_vector ( get_x_reg(), get_y_reg(), tmp_delta_x, -tmp_delta_y ); - break; + busy_cycles = draw_vector(get_x_reg(), get_y_reg(), tmp_delta_x, -tmp_delta_y); + break; case 0x7: - busy_cycles = draw_vector ( get_x_reg(), get_y_reg(), -tmp_delta_x, -tmp_delta_y ); - break; + busy_cycles = draw_vector(get_x_reg(), get_y_reg(), -tmp_delta_x, -tmp_delta_y); + break; case 0x0: - busy_cycles = draw_vector ( get_x_reg(), get_y_reg(), tmp_delta_x, 0 ); - break; + busy_cycles = draw_vector(get_x_reg(), get_y_reg(), tmp_delta_x, 0); + break; case 0x2: - busy_cycles = draw_vector ( get_x_reg(), get_y_reg(), 0, tmp_delta_y ); - break; + busy_cycles = draw_vector(get_x_reg(), get_y_reg(), 0, tmp_delta_y); + break; case 0x4: - busy_cycles = draw_vector ( get_x_reg(), get_y_reg(), 0, -tmp_delta_y ); - break; + busy_cycles = draw_vector(get_x_reg(), get_y_reg(), 0, -tmp_delta_y); + break; case 0x6: - busy_cycles = draw_vector ( get_x_reg(), get_y_reg(), -tmp_delta_x, 0 ); - break; + busy_cycles = draw_vector(get_x_reg(), get_y_reg(), -tmp_delta_x, 0); + break; } - set_busy_flag( cycles_to_us( busy_cycles ) ); + set_busy_flag(cycles_to_us(busy_cycles)); } else { @@ -1143,8 +1087,8 @@ void ef9365_device::ef9365_exec(uint8_t cmd) LOG("EF9365 Command : [0x%.2X] %s\n", cmd, commands_names[0x12]); - busy_cycles = draw_character( cmd - 0x20, 0 , 0 ); - set_busy_flag( cycles_to_us( busy_cycles ) ); + int busy_cycles = draw_character(cmd - 0x20, false, false); + set_busy_flag(cycles_to_us(busy_cycles)); } } } @@ -1156,23 +1100,23 @@ void ef9365_device::ef9365_exec(uint8_t cmd) uint32_t ef9365_device::screen_update(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect) { - for(int j=0;j<bitplane_yres;j++) + for (int j = 0; j < bitplane_yres; j++) { - for(int i=0;i<bitplane_xres;i++) + for (int i = 0; i < bitplane_xres; i++) { - unsigned char color_index = 0x00; + uint8_t color_index = 0x00; - int ptr = ( bitplane_xres * j ) + i; + int ptr = (bitplane_xres * j) + i; - for(int p = 0; p < nb_of_bitplanes; p++) + for (int p = 0; p < nb_of_bitplanes; p++) { - if( m_videoram->read_byte( (BITPLANE_MAX_SIZE*p) + (ptr>>3)) & (0x80>>(ptr&7))) + if (BIT(m_videoram->read_byte(BITPLANE_MAX_SIZE * p + (ptr >> 3)), ~ptr & 7)) { - color_index |= (0x01<<p); + color_index |= 0x01 << p; } } - m_screen_out.pix(j, i) = m_palette->pen( color_index ); + m_screen_out.pix(j, i) = m_palette->pen(color_index); } } @@ -1188,8 +1132,8 @@ void ef9365_device::update_scanline(uint16_t scanline) { if (scanline == vsync_scanline_pos) { - m_state |= (0x02); // vsync - if( m_registers[EF936X_REG_CTRL1] & 0x20 ) + m_state |= 0x02; // vsync + if (m_registers[EF936X_REG_CTRL1] & 0x20) { m_irq_vb = 1; } @@ -1199,7 +1143,7 @@ void ef9365_device::update_scanline(uint16_t scanline) if (scanline == 0) { - m_state &= (~0x02); + m_state &= ~0x02; draw_border(0); } } @@ -1210,39 +1154,39 @@ void ef9365_device::update_scanline(uint16_t scanline) uint8_t ef9365_device::data_r(offs_t offset) { - unsigned char return_value; + uint8_t return_value; - switch(offset & 0xF) + switch (offset & 0xf) { case EF936X_REG_STATUS: if (m_bf) - m_state &= (~0x04); + m_state &= ~0x04; else m_state |= 0x04; - if ( ( overflow_mask_x & get_x_reg() ) || ( overflow_mask_y & get_y_reg() ) ) + if ((overflow_mask_x & get_x_reg()) || (overflow_mask_y & get_y_reg())) { m_state |= 0x08; } - if( m_irq_vb || m_irq_lb || m_irq_rdy ) + if (m_irq_vb || m_irq_lb || m_irq_rdy) { m_state |= 0x80; } - if( m_irq_lb ) + if (m_irq_lb) { m_state |= 0x10; m_irq_lb = 0; } - if( m_irq_vb ) + if (m_irq_vb) { m_state |= 0x20; m_irq_vb = 0; } - if( m_irq_rdy ) + if (m_irq_rdy) { m_state |= 0x40; m_irq_rdy = 0; @@ -1251,46 +1195,46 @@ uint8_t ef9365_device::data_r(offs_t offset) update_interrupts(); return_value = m_state; - break; + break; case EF936X_REG_CTRL1: - return_value = m_registers[EF936X_REG_CTRL1] & 0x7F; - break; + return_value = m_registers[EF936X_REG_CTRL1] & 0x7f; + break; case EF936X_REG_CTRL2: - return_value = m_registers[EF936X_REG_CTRL2] & 0x0F; - break; + return_value = m_registers[EF936X_REG_CTRL2] & 0x0f; + break; case EF936X_REG_CSIZE: return_value = m_registers[EF936X_REG_CSIZE]; - break; + break; case EF936X_REG_DELTAX: return_value = m_registers[EF936X_REG_DELTAX]; - break; + break; case EF936X_REG_DELTAY: return_value = m_registers[EF936X_REG_DELTAY]; - break; + break; case EF936X_REG_X_MSB: - return_value = m_registers[EF936X_REG_X_MSB] & 0x0F; - break; + return_value = m_registers[EF936X_REG_X_MSB] & 0x0f; + break; case EF936X_REG_X_LSB: return_value = m_registers[EF936X_REG_X_LSB]; - break; + break; case EF936X_REG_Y_MSB: - return_value = m_registers[EF936X_REG_Y_MSB] & 0x0F; - break; + return_value = m_registers[EF936X_REG_Y_MSB] & 0x0f; + break; case EF936X_REG_Y_LSB: return_value = m_registers[EF936X_REG_Y_LSB]; - break; + break; case EF936X_REG_XLP: - return_value = m_registers[EF936X_REG_XLP] & 0xFD; - break; + return_value = m_registers[EF936X_REG_XLP] & 0xfd; + break; case EF936X_REG_YLP: return_value = m_registers[EF936X_REG_YLP]; - break; + break; default: - return_value = 0xFF; - break; + return_value = 0xff; + break; } - LOG("EF9365 [ %s ] RD> [ 0x%.2X ] - %s\n", register_names[offset&0xF],return_value, machine().describe_context() ); + LOG("EF9365 [ %s ] RD> [ 0x%.2X ] - %s\n", register_names[offset & 0xf], return_value, machine().describe_context()); return return_value; } @@ -1301,45 +1245,45 @@ uint8_t ef9365_device::data_r(offs_t offset) void ef9365_device::data_w(offs_t offset, uint8_t data) { - LOG("EF9365 [ %s ] <WR [ 0x%.2X ] - %s\n", register_names[offset&0xF],data, machine().describe_context() ); + LOG("EF9365 [ %s ] <WR [ 0x%.2X ] - %s\n", register_names[offset & 0xf], data, machine().describe_context()); - switch(offset & 0xF) + switch (offset & 0xf) { case EF936X_REG_CMD: - ef9365_exec( data & 0xff); - break; + ef9365_exec(data & 0xff); + break; case EF936X_REG_CTRL1: - m_registers[EF936X_REG_CTRL1] = data & 0x7F; - break; + m_registers[EF936X_REG_CTRL1] = data & 0x7f; + break; case EF936X_REG_CTRL2: - m_registers[EF936X_REG_CTRL2] = data & 0x0F; - break; + m_registers[EF936X_REG_CTRL2] = data & 0x0f; + break; case EF936X_REG_CSIZE: m_registers[EF936X_REG_CSIZE] = data; - break; + break; case EF936X_REG_DELTAX: m_registers[EF936X_REG_DELTAX] = data; - break; + break; case EF936X_REG_DELTAY: m_registers[EF936X_REG_DELTAY] = data; - break; + break; case EF936X_REG_X_MSB: - m_registers[EF936X_REG_X_MSB] = data & 0x0F; - break; + m_registers[EF936X_REG_X_MSB] = data & 0x0f; + break; case EF936X_REG_X_LSB: m_registers[EF936X_REG_X_LSB] = data; - break; + break; case EF936X_REG_Y_MSB: - m_registers[EF936X_REG_Y_MSB] = data & 0x0F; - break; + m_registers[EF936X_REG_Y_MSB] = data & 0x0f; + break; case EF936X_REG_Y_LSB: m_registers[EF936X_REG_Y_LSB] = data; - break; + break; case EF936X_REG_XLP: - break; + break; case EF936X_REG_YLP: - break; + break; default: - break; + break; } } diff --git a/src/devices/video/ef9365.h b/src/devices/video/ef9365.h index 7017b4e4587..fd3e7497e11 100644 --- a/src/devices/video/ef9365.h +++ b/src/devices/video/ef9365.h @@ -61,7 +61,6 @@ protected: // device-level overrides virtual void device_start() override; virtual void device_reset() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; virtual const tiny_rom_entry *device_rom_region() const override; // device_config_memory_interface overrides @@ -70,18 +69,20 @@ protected: // address space configurations const address_space_config m_space_config; + TIMER_CALLBACK_MEMBER(clear_busy_flag); + private: - int get_char_pix( unsigned char c, int x, int y ); - void plot(int x_pos,int y_pos); - int draw_character( unsigned char c, int block, int smallblock ); - int draw_vector(uint16_t start_x,uint16_t start_y,short delta_x,short delta_y); + int get_char_pix(uint8_t c, int x, int y); + void plot(int x_pos, int y_pos); + int draw_character(uint8_t c, bool block, bool smallblock); + int draw_vector(uint16_t start_x, uint16_t start_y, int16_t delta_x, int16_t delta_y); uint16_t get_x_reg(); uint16_t get_y_reg(); void set_x_reg(uint16_t x); void set_y_reg(uint16_t y); - void screen_scanning( int force_clear ); + void screen_scanning(bool force_clear); void set_busy_flag(int period); - void set_video_mode(void); + void set_video_mode(); void draw_border(uint16_t line); void ef9365_exec(uint8_t cmd); int cycles_to_us(int cycles); @@ -91,8 +92,6 @@ private: void ef9365(address_map &map); // internal state - static constexpr device_timer_id BUSY_TIMER = 0; - required_region_ptr<uint8_t> m_charset; address_space *m_videoram; diff --git a/src/devices/video/epic12.cpp b/src/devices/video/epic12.cpp index d48e8a7726d..d0dfbf1fcae 100644 --- a/src/devices/video/epic12.cpp +++ b/src/devices/video/epic12.cpp @@ -58,7 +58,7 @@ void epic12_device::device_start() m_ram16_copy = std::make_unique<u16[]>(m_main_ramsize / 2); - m_blitter_delay_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(epic12_device::blitter_delay_callback),this)); + m_blitter_delay_timer = timer_alloc(FUNC(epic12_device::blitter_delay_callback), this); m_blitter_delay_timer->adjust(attotime::never); m_firmware_pos = 0; diff --git a/src/devices/video/fixfreq.h b/src/devices/video/fixfreq.h index f0f279a2832..bb2fdde34a9 100644 --- a/src/devices/video/fixfreq.h +++ b/src/devices/video/fixfreq.h @@ -301,7 +301,6 @@ 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); virtual ioport_constructor device_input_ports() const override; diff --git a/src/devices/video/gb_lcd.cpp b/src/devices/video/gb_lcd.cpp index baa139b0803..ac81c1398f3 100644 --- a/src/devices/video/gb_lcd.cpp +++ b/src/devices/video/gb_lcd.cpp @@ -365,7 +365,7 @@ void dmg_ppu_device::common_start() m_vram = make_unique_clear<uint8_t[]>(m_vram_size); machine().save().register_postload(save_prepost_delegate(FUNC(dmg_ppu_device::videoptr_restore), this)); - m_lcd_timer = timer_alloc(); + m_lcd_timer = timer_alloc(FUNC(dmg_ppu_device::update_tick), this); m_program_space = &m_lr35902->space(AS_PROGRAM); @@ -1917,7 +1917,7 @@ void dmg_ppu_device::increment_scanline() } -void dmg_ppu_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(dmg_ppu_device::update_tick) { update_state(); } diff --git a/src/devices/video/gb_lcd.h b/src/devices/video/gb_lcd.h index d3f98ac1265..418868e5ce0 100644 --- a/src/devices/video/gb_lcd.h +++ b/src/devices/video/gb_lcd.h @@ -80,7 +80,8 @@ protected: // device-level overrides virtual void device_start() override; virtual void device_reset() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; + + TIMER_CALLBACK_MEMBER(update_tick); void common_start(); void common_reset(); diff --git a/src/devices/video/gba_lcd.cpp b/src/devices/video/gba_lcd.cpp index f5df7fa01e6..2d5f79306ef 100644 --- a/src/devices/video/gba_lcd.cpp +++ b/src/devices/video/gba_lcd.cpp @@ -1765,8 +1765,8 @@ void gba_lcd_device::device_start() screen().register_screen_bitmap(m_bitmap); /* create a timer to fire scanline functions */ - m_scan_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(gba_lcd_device::perform_scan),this)); - m_hbl_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(gba_lcd_device::perform_hbl),this)); + m_scan_timer = timer_alloc(FUNC(gba_lcd_device::perform_scan), this); + m_hbl_timer = timer_alloc(FUNC(gba_lcd_device::perform_hbl), this); m_scan_timer->adjust(screen().time_until_pos(0, 0)); save_item(NAME(m_regs)); diff --git a/src/devices/video/hd44352.cpp b/src/devices/video/hd44352.cpp index 404119e6c71..12d431b21ef 100644 --- a/src/devices/video/hd44352.cpp +++ b/src/devices/video/hd44352.cpp @@ -57,7 +57,7 @@ void hd44352_device::device_start() { m_on_cb.resolve_safe(); - m_on_timer = timer_alloc(ON_TIMER); + m_on_timer = timer_alloc(FUNC(hd44352_device::on_tick), this); m_on_timer->adjust(attotime::from_hz(m_clock/16384), 0, attotime::from_hz(m_clock/16384)); save_item( NAME(m_control_lines)); @@ -112,20 +112,12 @@ void hd44352_device::device_reset() } -//------------------------------------------------- -// device_timer - handler timer events -//------------------------------------------------- -void hd44352_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(hd44352_device::on_tick) { - switch(id) + if (m_control_lines & 0x40) { - case ON_TIMER: - if (m_control_lines & 0x40) - { - m_on_cb(ASSERT_LINE); - m_on_cb(CLEAR_LINE); - } - break; + m_on_cb(ASSERT_LINE); + m_on_cb(CLEAR_LINE); } } diff --git a/src/devices/video/hd44352.h b/src/devices/video/hd44352.h index 2b81a5345de..a5b311c0e9f 100644 --- a/src/devices/video/hd44352.h +++ b/src/devices/video/hd44352.h @@ -36,14 +36,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; virtual void device_validity_check(validity_checker &valid) const override; + TIMER_CALLBACK_MEMBER(on_tick); + private: uint8_t compute_newval(uint8_t type, uint8_t oldval, uint8_t newval); uint8_t get_char(uint16_t pos); - static const device_timer_id ON_TIMER = 1; emu_timer *m_on_timer; uint8_t m_video_ram[2][0x180]; diff --git a/src/devices/video/hd44780.cpp b/src/devices/video/hd44780.cpp index 3fbea6e8349..7a543cf5077 100644 --- a/src/devices/video/hd44780.cpp +++ b/src/devices/video/hd44780.cpp @@ -113,8 +113,8 @@ void hd44780_device::device_start() m_pixel_update_cb.resolve(); - m_busy_timer = timer_alloc(TIMER_BUSY); - m_blink_timer = timer_alloc(TIMER_BLINKING); + m_busy_timer = timer_alloc(FUNC(hd44780_device::clear_busy_flag), this); + m_blink_timer = timer_alloc(FUNC(hd44780_device::blink_tick), this); m_blink_timer->adjust(attotime::from_msec(409), 0, attotime::from_msec(409)); // state saving @@ -178,21 +178,17 @@ void hd44780_device::device_reset() //------------------------------------------------- -// device_timer - handler timer events +// timer events //------------------------------------------------- -void hd44780_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(hd44780_device::clear_busy_flag) { - switch (id) - { - case TIMER_BUSY: - m_busy_flag = false; - break; + m_busy_flag = false; +} - case TIMER_BLINKING: - m_blink = !m_blink; - break; - } +TIMER_CALLBACK_MEMBER(hd44780_device::blink_tick) +{ + m_blink = !m_blink; } diff --git a/src/devices/video/hd44780.h b/src/devices/video/hd44780.h index f09747c2583..b1731ca6198 100644 --- a/src/devices/video/hd44780.h +++ b/src/devices/video/hd44780.h @@ -58,11 +58,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; + TIMER_CALLBACK_MEMBER(clear_busy_flag); + TIMER_CALLBACK_MEMBER(blink_tick); + // charset enum { @@ -96,9 +98,6 @@ private: void pixel_update(bitmap_ind16 &bitmap, u8 line, u8 pos, u8 y, u8 x, int state); // internal state - static constexpr device_timer_id TIMER_BUSY = 0; - static constexpr device_timer_id TIMER_BLINKING = 1; - emu_timer * m_blink_timer; emu_timer * m_busy_timer; diff --git a/src/devices/video/hd61830.cpp b/src/devices/video/hd61830.cpp index 14fff0b3dff..9d2a8a5eb67 100644 --- a/src/devices/video/hd61830.cpp +++ b/src/devices/video/hd61830.cpp @@ -97,7 +97,7 @@ hd61830_device::hd61830_device(const machine_config &mconfig, const char *tag, d void hd61830_device::device_start() { // allocate timers - m_busy_timer = timer_alloc(); + m_busy_timer = timer_alloc(FUNC(hd61830_device::clear_busy_flag), this); // resolve callbacks m_read_rd.resolve_safe(0); @@ -134,12 +134,11 @@ void hd61830_device::device_reset() //------------------------------------------------- -// device_timer - handler timer events +// clear_busy_flag - //------------------------------------------------- -void hd61830_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(hd61830_device::clear_busy_flag) { - // clear busy flag m_bf = false; } diff --git a/src/devices/video/hd61830.h b/src/devices/video/hd61830.h index c1177a908fc..83f5639ca14 100644 --- a/src/devices/video/hd61830.h +++ b/src/devices/video/hd61830.h @@ -41,7 +41,6 @@ protected: virtual const tiny_rom_entry *device_rom_region() 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_memory_interface overrides virtual space_config_vector memory_space_config() const override; @@ -49,6 +48,8 @@ protected: uint8_t readbyte(offs_t address) { return space().read_byte(address); } void writebyte(offs_t address, uint8_t data) { space().write_byte(address, data); } + TIMER_CALLBACK_MEMBER(clear_busy_flag); + private: enum { diff --git a/src/devices/video/hd63484.h b/src/devices/video/hd63484.h index 816aa6a8ce5..67383810bf6 100644 --- a/src/devices/video/hd63484.h +++ b/src/devices/video/hd63484.h @@ -47,7 +47,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); inline uint16_t readword(offs_t address); inline void writeword(offs_t address, uint16_t data); diff --git a/src/devices/video/hlcd0438.cpp b/src/devices/video/hlcd0438.cpp index 42317ddb087..fadc164dcb6 100644 --- a/src/devices/video/hlcd0438.cpp +++ b/src/devices/video/hlcd0438.cpp @@ -36,7 +36,7 @@ void hlcd0438_device::device_start() m_write_data.resolve_safe(); // timer (when LCD pin is oscillator) - m_lcd_timer = timer_alloc(); + m_lcd_timer = timer_alloc(FUNC(hlcd0438_device::toggle_lcd), this); attotime period = (clock() != 0) ? attotime::from_hz(2 * clock()) : attotime::never; m_lcd_timer->adjust(period, 0, period); @@ -55,6 +55,11 @@ void hlcd0438_device::device_start() // handlers //------------------------------------------------- +TIMER_CALLBACK_MEMBER(hlcd0438_device::toggle_lcd) +{ + lcd_w(!m_lcd); +} + void hlcd0438_device::clock_w(int state) { state = state ? 1 : 0; diff --git a/src/devices/video/hlcd0438.h b/src/devices/video/hlcd0438.h index c76bb4835ed..da6da51da39 100644 --- a/src/devices/video/hlcd0438.h +++ b/src/devices/video/hlcd0438.h @@ -58,7 +58,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 { lcd_w(!m_lcd); } + + TIMER_CALLBACK_MEMBER(toggle_lcd); private: emu_timer *m_lcd_timer; diff --git a/src/devices/video/hlcd0488.cpp b/src/devices/video/hlcd0488.cpp index 984a5600e6c..98ab3937f54 100644 --- a/src/devices/video/hlcd0488.cpp +++ b/src/devices/video/hlcd0488.cpp @@ -37,7 +37,7 @@ hlcd0488_device::hlcd0488_device(const machine_config &mconfig, const char *tag, void hlcd0488_device::device_start() { m_write_cols.resolve_safe(); - m_sync_timer = timer_alloc(); + m_sync_timer = timer_alloc(FUNC(hlcd0488_device::sync_update), this); // register for savestates save_item(NAME(m_latch_pulse)); @@ -55,7 +55,7 @@ void hlcd0488_device::device_start() // handlers //------------------------------------------------- -void hlcd0488_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(hlcd0488_device::sync_update) { // Latch pulse, when high, resets the %8 latch address counter if (m_latch_pulse) diff --git a/src/devices/video/hlcd0488.h b/src/devices/video/hlcd0488.h index 66d72616374..c2302fbc88b 100644 --- a/src/devices/video/hlcd0488.h +++ b/src/devices/video/hlcd0488.h @@ -54,7 +54,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(sync_update); private: // pin state diff --git a/src/devices/video/hlcd0515.cpp b/src/devices/video/hlcd0515.cpp index 55a0183a11c..7af99f99657 100644 --- a/src/devices/video/hlcd0515.cpp +++ b/src/devices/video/hlcd0515.cpp @@ -63,7 +63,7 @@ void hlcd0515_device::device_start() m_write_data.resolve_safe(); // timer - m_lcd_timer = timer_alloc(); + m_lcd_timer = timer_alloc(FUNC(hlcd0515_device::scan_lcd), this); attotime period = attotime::from_hz(clock() / 2); m_lcd_timer->adjust(period, 0, period); @@ -99,10 +99,10 @@ void hlcd0515_device::device_start() //------------------------------------------------- -// device_timer - handle timer events +// scan_lcd - //------------------------------------------------- -void hlcd0515_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(hlcd0515_device::scan_lcd) { if (m_rowout > m_rowmax) m_rowout = 0; diff --git a/src/devices/video/hlcd0515.h b/src/devices/video/hlcd0515.h index fd1a5d2c147..c6ef5e118bf 100644 --- a/src/devices/video/hlcd0515.h +++ b/src/devices/video/hlcd0515.h @@ -60,7 +60,8 @@ 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(scan_lcd); virtual void set_control(); void clock_data(int col = 0); diff --git a/src/devices/video/hlcd0538.cpp b/src/devices/video/hlcd0538.cpp index a5f731313e9..3cf1fd4a6f6 100644 --- a/src/devices/video/hlcd0538.cpp +++ b/src/devices/video/hlcd0538.cpp @@ -51,7 +51,7 @@ void hlcd0538_device::device_start() m_write_interrupt.resolve_safe(); // timer (when LCD pin is oscillator) - m_lcd_timer = timer_alloc(); + m_lcd_timer = timer_alloc(FUNC(hlcd0538_device::toggle_lcd), this); attotime period = (clock() != 0) ? attotime::from_hz(2 * clock()) : attotime::never; m_lcd_timer->adjust(period, 0, period); @@ -67,6 +67,11 @@ void hlcd0538_device::device_start() // handlers //------------------------------------------------- +TIMER_CALLBACK_MEMBER(hlcd0538_device::toggle_lcd) +{ + lcd_w(!m_lcd); +} + WRITE_LINE_MEMBER(hlcd0538_device::clk_w) { state = (state) ? 1 : 0; diff --git a/src/devices/video/hlcd0538.h b/src/devices/video/hlcd0538.h index f14598ac6c8..08a2f8ef437 100644 --- a/src/devices/video/hlcd0538.h +++ b/src/devices/video/hlcd0538.h @@ -58,7 +58,8 @@ protected: // device-level overrides virtual void device_start() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override { lcd_w(!m_lcd); } + + TIMER_CALLBACK_MEMBER(toggle_lcd); emu_timer *m_lcd_timer; diff --git a/src/devices/video/huc6260.cpp b/src/devices/video/huc6260.cpp index 0830aa2bf90..cc41b86ac1d 100644 --- a/src/devices/video/huc6260.cpp +++ b/src/devices/video/huc6260.cpp @@ -63,7 +63,7 @@ huc6260_device::huc6260_device(const machine_config &mconfig, const char *tag, d } -void huc6260_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(huc6260_device::update_events) { int vpos = screen().vpos(); int hpos = screen().hpos(); @@ -255,7 +255,7 @@ void huc6260_device::write(offs_t offset, uint8_t data) void huc6260_device::device_start() { - m_timer = timer_alloc(); + m_timer = timer_alloc(FUNC(huc6260_device::update_events), this); m_bmp = std::make_unique<bitmap_ind16>(WPF, LPF); /* Resolve callbacks */ diff --git a/src/devices/video/huc6260.h b/src/devices/video/huc6260.h index ef33f7a5cea..387bc6cd7f7 100644 --- a/src/devices/video/huc6260.h +++ b/src/devices/video/huc6260.h @@ -43,10 +43,11 @@ protected: // device-level overrides virtual void device_start() override; virtual void device_reset() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; virtual uint32_t palette_entries() const override { return PALETTE_SIZE; } + TIMER_CALLBACK_MEMBER(update_events); + private: void palette_init(); diff --git a/src/devices/video/huc6261.cpp b/src/devices/video/huc6261.cpp index 546f117cf2d..27bd06c7e33 100644 --- a/src/devices/video/huc6261.cpp +++ b/src/devices/video/huc6261.cpp @@ -94,7 +94,7 @@ void huc6261_device::apply_pal_offs(uint16_t *pix_data) *pix_data &= 0x1ff; } -void huc6261_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(huc6261_device::update_events) { int vpos = screen().vpos(); int hpos = screen().hpos(); @@ -414,7 +414,7 @@ void huc6261_device::write(offs_t offset, uint16_t data) void huc6261_device::device_start() { - m_timer = timer_alloc(); + m_timer = timer_alloc(FUNC(huc6261_device::update_events), this); m_bmp = std::make_unique<bitmap_rgb32>(WPF, LPF); diff --git a/src/devices/video/huc6261.h b/src/devices/video/huc6261.h index b9d9b351c80..9995a20673b 100644 --- a/src/devices/video/huc6261.h +++ b/src/devices/video/huc6261.h @@ -38,7 +38,8 @@ protected: // device-level overrides virtual void device_start() override; virtual void device_reset() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; + + TIMER_CALLBACK_MEMBER(update_events); private: required_device<huc6270_device> m_huc6270_a; diff --git a/src/devices/video/i8244.cpp b/src/devices/video/i8244.cpp index 8ec529afee5..bea7014d9ad 100644 --- a/src/devices/video/i8244.cpp +++ b/src/devices/video/i8244.cpp @@ -153,10 +153,10 @@ void i8244_device::device_start() m_irq_func.resolve_safe(); // allocate timers - m_vblank_timer = timer_alloc(TIMER_VBLANK_START); + m_vblank_timer = timer_alloc(FUNC(i8244_device::vblank_start), this); m_vblank_timer->adjust(screen().time_until_pos(m_vblank_start, m_hblank_start - 1), 0, screen().frame_period()); - m_hblank_timer = timer_alloc(TIMER_HBLANK_START); + m_hblank_timer = timer_alloc(FUNC(i8244_device::hblank_start), this); m_hblank_timer->adjust(screen().time_until_pos(0, m_hblank_start), 0, screen().scan_period()); // allocate a stream @@ -185,27 +185,20 @@ void i8244_device::device_start() //------------------------------------------------- -// device_timer - handle timer callbacks +// timer events //------------------------------------------------- -void i8244_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(i8244_device::hblank_start) { - switch (id) - { - case TIMER_HBLANK_START: - // hblank starts (updates sound shift register) - sound_update(); - break; - - case TIMER_VBLANK_START: - // vblank starts - m_control_status |= 0x08; - m_irq_func(ASSERT_LINE); - break; + // hblank starts (updates sound shift register) + sound_update(); +} - default: - break; - } +TIMER_CALLBACK_MEMBER(i8244_device::vblank_start) +{ + // vblank starts + m_control_status |= 0x08; + m_irq_func(ASSERT_LINE); } diff --git a/src/devices/video/i8244.h b/src/devices/video/i8244.h index 909d39b057d..f87382fa461 100644 --- a/src/devices/video/i8244.h +++ b/src/devices/video/i8244.h @@ -111,12 +111,14 @@ protected: // device-level overrides virtual void device_config_complete() override; virtual void device_start() 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; // device_sound_interface overrides virtual void sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) override; + TIMER_CALLBACK_MEMBER(hblank_start); + TIMER_CALLBACK_MEMBER(vblank_start); + virtual void set_default_params(); inline bool is_ntsc() { return m_vtotal == 263; } @@ -129,10 +131,6 @@ protected: void draw_minor(int scanline, bitmap_ind16 &bitmap, const rectangle &cliprect); void char_pixel(u8 index, int x, int y, u8 pixel, u16 color, bitmap_ind16 &bitmap, const rectangle &cliprect); - /* timers */ - static constexpr device_timer_id TIMER_VBLANK_START = 0; - static constexpr device_timer_id TIMER_HBLANK_START = 1; - // callbacks devcb_write_line m_irq_func; diff --git a/src/devices/video/i82730.cpp b/src/devices/video/i82730.cpp index 70feabd7909..ba853c41680 100644 --- a/src/devices/video/i82730.cpp +++ b/src/devices/video/i82730.cpp @@ -81,7 +81,7 @@ void i82730_device::device_start() m_update_row_cb.resolve(); // allocate row timer - m_row_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(i82730_device::row_update), this)); + m_row_timer = timer_alloc(FUNC(i82730_device::row_update), this); } //------------------------------------------------- diff --git a/src/devices/video/i8275.cpp b/src/devices/video/i8275.cpp index 2ea9570d712..1e080986e22 100644 --- a/src/devices/video/i8275.cpp +++ b/src/devices/video/i8275.cpp @@ -158,9 +158,9 @@ void i8275_device::device_start() m_display_cb.resolve(); // allocate timers - m_hrtc_on_timer = timer_alloc(TIMER_HRTC_ON); - m_drq_on_timer = timer_alloc(TIMER_DRQ_ON); - m_scanline_timer = timer_alloc(TIMER_SCANLINE); + m_hrtc_on_timer = timer_alloc(FUNC(i8275_device::hrtc_on), this); + m_drq_on_timer = timer_alloc(FUNC(i8275_device::drq_on), this); + m_scanline_timer = timer_alloc(FUNC(i8275_device::scanline_tick), this); // state saving save_item(NAME(m_status)); @@ -260,209 +260,198 @@ void i8275_device::dma_start() //------------------------------------------------- -// device_timer - handle timer events +// timer events //------------------------------------------------- -void i8275_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(i8275_device::hrtc_on) { - //int y = screen().vpos(); - //int x = screen().hpos(); - int rc = m_scanline / SCANLINES_PER_ROW; - int lc = m_scanline % SCANLINES_PER_ROW; + m_write_hrtc(1); +} - switch (id) - { - case TIMER_HRTC_ON: - //LOG("I8275 y %u x %u HRTC 1\n", y, x); - m_write_hrtc(1); - break; +TIMER_CALLBACK_MEMBER(i8275_device::drq_on) +{ + m_write_drq(1); +} - case TIMER_DRQ_ON: - //LOG("I8275 y %u x %u DRQ 1\n", y, x); - m_write_drq(1); - break; +TIMER_CALLBACK_MEMBER(i8275_device::scanline_tick) +{ + int rc = m_scanline / SCANLINES_PER_ROW; + int lc = m_scanline % SCANLINES_PER_ROW; - case TIMER_SCANLINE: - //LOG("I8275 y %u x %u HRTC 0\n", y, x); - int line_counter = OFFSET_LINE_COUNTER ? ((lc - 1) % SCANLINES_PER_ROW) : lc; - m_write_lc(line_counter); - m_write_hrtc(0); + int line_counter = OFFSET_LINE_COUNTER ? ((lc - 1) % SCANLINES_PER_ROW) : lc; + m_write_lc(line_counter); + m_write_hrtc(0); - if (m_scanline == 0) - vrtc_end(); + if (m_scanline == 0) + vrtc_end(); - if (lc == 0 && m_scanline < m_vrtc_scanline) + if (lc == 0 && m_scanline < m_vrtc_scanline) + { + if (!m_dma_stop && m_buffer_idx < CHARACTERS_PER_ROW) { - if (!m_dma_stop && m_buffer_idx < CHARACTERS_PER_ROW) - { - m_status |= ST_DU; - m_dma_stop = true; - - // blank screen until after VRTC - m_end_of_screen = true; - - //LOG("I8275 y %u x %u DMA Underrun\n", y, x); - - m_write_drq(0); - } - - if (!m_dma_stop) - { - // swap line buffers - m_buffer_dma = !m_buffer_dma; + m_status |= ST_DU; + m_dma_stop = true; - if (m_scanline < (m_vrtc_scanline - SCANLINES_PER_ROW)) - dma_start(); - } - } + // blank screen until after VRTC + m_end_of_screen = true; - if ((m_status & ST_IE) && !(m_status & ST_IR) && m_scanline == m_irq_scanline) - { - //LOG("I8275 y %u x %u IRQ 1\n", y, x); - m_status |= ST_IR; - m_write_irq(ASSERT_LINE); + m_write_drq(0); } - if (m_scanline == m_vrtc_scanline) - vrtc_start(); - - if (!m_dma_stop && m_scanline == m_vrtc_drq_scanline) + if (!m_dma_stop) { // swap line buffers m_buffer_dma = !m_buffer_dma; - // start DMA burst - dma_start(); + if (m_scanline < (m_vrtc_scanline - SCANLINES_PER_ROW)) + dma_start(); } + } + + if ((m_status & ST_IE) && !(m_status & ST_IR) && m_scanline == m_irq_scanline) + { + m_status |= ST_IR; + m_write_irq(ASSERT_LINE); + } + + if (m_scanline == m_vrtc_scanline) + vrtc_start(); - if ((m_status & ST_VE) && m_scanline < m_vrtc_scanline) + if (!m_dma_stop && m_scanline == m_vrtc_drq_scanline) + { + // swap line buffers + m_buffer_dma = !m_buffer_dma; + + // start DMA burst + dma_start(); + } + + if ((m_status & ST_VE) && m_scanline < m_vrtc_scanline) + { + bool end_of_row = false; + bool blank_row = (UNDERLINE >= 8) && ((lc == 0) || (lc == SCANLINES_PER_ROW - 1)); + int fifo_idx = 0; + m_field_attr = m_stored_attr; + + for (int sx = 0; sx < CHARACTERS_PER_ROW; sx++) { - bool end_of_row = false; - bool blank_row = (UNDERLINE >= 8) && ((lc == 0) || (lc == SCANLINES_PER_ROW - 1)); - int fifo_idx = 0; - m_field_attr = m_stored_attr; + int lineattr = 0; - for (int sx = 0; sx < CHARACTERS_PER_ROW; sx++) - { - int lineattr = 0; + uint8_t data = (end_of_row || m_end_of_screen) ? 0 : m_buffer[!m_buffer_dma][sx]; + uint8_t attr = m_field_attr; - uint8_t data = (end_of_row || m_end_of_screen) ? 0 : m_buffer[!m_buffer_dma][sx]; - uint8_t attr = m_field_attr; + if ((data & 0xc0) == 0x80) + { + // field attribute code + m_field_attr = data & (FAC_H | FAC_B | FAC_GG | FAC_R | FAC_U); - if ((data & 0xc0) == 0x80) + if (!VISIBLE_FIELD_ATTRIBUTE) { - // field attribute code - m_field_attr = data & (FAC_H | FAC_B | FAC_GG | FAC_R | FAC_U); - - if (!VISIBLE_FIELD_ATTRIBUTE) - { - attr = m_field_attr; - data = m_fifo[!m_buffer_dma][fifo_idx]; - - fifo_idx++; - fifo_idx &= 0xf; - - if (blank_row) - attr |= FAC_B; - else if (!(m_char_blink < 32)) - attr &= ~FAC_B; - if (lc != UNDERLINE) - attr &= ~FAC_U; - } - else - { - // simply blank the attribute character itself - attr = FAC_B; - } + attr = m_field_attr; + data = m_fifo[!m_buffer_dma][fifo_idx]; + + fifo_idx++; + fifo_idx &= 0xf; + + if (blank_row) + attr |= FAC_B; + else if (!(m_char_blink < 32)) + attr &= ~FAC_B; + if (lc != UNDERLINE) + attr &= ~FAC_U; } - else if (data >= 0xf0 || end_of_row || m_end_of_screen) + else { - // special control character - switch (data) - { - case SCC_END_OF_ROW: - case SCC_END_OF_ROW_DMA: - end_of_row = true; - break; - - case SCC_END_OF_SCREEN: - case SCC_END_OF_SCREEN_DMA: - m_end_of_screen = true; - break; - } + // simply blank the attribute character itself attr = FAC_B; } - else if (data >= 0xc0) + } + else if (data >= 0xf0 || end_of_row || m_end_of_screen) + { + // special control character + switch (data) { - // character attribute code - attr = data & (m_char_blink < 32 ? (CA_H | CA_B) : CA_H); - - uint8_t ca; - int cccc = (data >> 2) & 0x0f; - - if (lc < UNDERLINE) - { - ca = character_attribute[0][cccc]; - } - else if (lc == UNDERLINE) - { - ca = character_attribute[1][cccc]; - } - else - { - ca = character_attribute[2][cccc]; - } + case SCC_END_OF_ROW: + case SCC_END_OF_ROW_DMA: + end_of_row = true; + break; + + case SCC_END_OF_SCREEN: + case SCC_END_OF_SCREEN_DMA: + m_end_of_screen = true; + break; + } + attr = FAC_B; + } + else if (data >= 0xc0) + { + // character attribute code + attr = data & (m_char_blink < 32 ? (CA_H | CA_B) : CA_H); - if (ca & CA_LTEN) - attr |= FAC_U; - if (ca & CA_VSP) - attr |= FAC_B; - lineattr = ca >> 2; + uint8_t ca; + int cccc = (data >> 2) & 0x0f; + + if (lc < UNDERLINE) + { + ca = character_attribute[0][cccc]; + } + else if (lc == UNDERLINE) + { + ca = character_attribute[1][cccc]; } else { - if (blank_row) - attr |= FAC_B; - else if (!(m_char_blink < 32)) - attr &= ~FAC_B; - if (lc != UNDERLINE) - attr &= ~FAC_U; + ca = character_attribute[2][cccc]; } - if ((rc == m_param[REG_CUR_ROW]) && (sx == m_param[REG_CUR_COL])) + if (ca & CA_LTEN) + attr |= FAC_U; + if (ca & CA_VSP) + attr |= FAC_B; + lineattr = ca >> 2; + } + else + { + if (blank_row) + attr |= FAC_B; + else if (!(m_char_blink < 32)) + attr &= ~FAC_B; + if (lc != UNDERLINE) + attr &= ~FAC_U; + } + + if ((rc == m_param[REG_CUR_ROW]) && (sx == m_param[REG_CUR_COL])) + { + if ((CURSOR_FORMAT & 0x02) || (m_cursor_blink < 16)) { - if ((CURSOR_FORMAT & 0x02) || (m_cursor_blink < 16)) - { - if (CURSOR_FORMAT & 0x01) - attr |= (lc == UNDERLINE) ? FAC_U : 0; - else - attr ^= FAC_R; - } + if (CURSOR_FORMAT & 0x01) + attr |= (lc == UNDERLINE) ? FAC_U : 0; + else + attr ^= FAC_R; } - - if (!m_display_cb.isnull()) - m_display_cb(m_bitmap, - sx * m_hpixels_per_column, // x position on screen of starting point - m_scanline, // y position on screen - line_counter, // current line of char - (data & 0x7f), // char code to be displayed - lineattr, // line attribute code - (attr & FAC_U) ? 1 : 0, // light enable signal - (attr & FAC_R) ? 1 : 0, // reverse video signal - (attr & FAC_B) ? 1 : 0, // video suppression - (attr & FAC_GG) >> 2, // general purpose attribute code - (attr & FAC_H) ? 1 : 0 // highlight - ); } - if ((SCANLINES_PER_ROW - lc) == 1) - m_stored_attr = m_field_attr; + if (!m_display_cb.isnull()) + m_display_cb(m_bitmap, + sx * m_hpixels_per_column, // x position on screen of starting point + m_scanline, // y position on screen + line_counter, // current line of char + (data & 0x7f), // char code to be displayed + lineattr, // line attribute code + (attr & FAC_U) ? 1 : 0, // light enable signal + (attr & FAC_R) ? 1 : 0, // reverse video signal + (attr & FAC_B) ? 1 : 0, // video suppression + (attr & FAC_GG) >> 2, // general purpose attribute code + (attr & FAC_H) ? 1 : 0 // highlight + ); } - m_scanline++; - m_scanline %= ((CHARACTER_ROWS_PER_FRAME + VRTC_ROW_COUNT) * SCANLINES_PER_ROW); - break; + if ((SCANLINES_PER_ROW - lc) == 1) + m_stored_attr = m_field_attr; } + + m_scanline++; + m_scanline %= ((CHARACTER_ROWS_PER_FRAME + VRTC_ROW_COUNT) * SCANLINES_PER_ROW); } diff --git a/src/devices/video/i8275.h b/src/devices/video/i8275.h index 34f7f24419b..2b49dee6362 100644 --- a/src/devices/video/i8275.h +++ b/src/devices/video/i8275.h @@ -85,7 +85,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(hrtc_on); + TIMER_CALLBACK_MEMBER(drq_on); + TIMER_CALLBACK_MEMBER(scanline_tick); void vrtc_start(); void vrtc_end(); @@ -95,13 +98,6 @@ protected: enum { - TIMER_HRTC_ON, - TIMER_DRQ_ON, - TIMER_SCANLINE - }; - - enum - { ST_IE = 0x40, ST_IR = 0x20, ST_LP = 0x10, diff --git a/src/devices/video/imagetek_i4100.cpp b/src/devices/video/imagetek_i4100.cpp index 080d2159553..5b9cc568e03 100644 --- a/src/devices/video/imagetek_i4100.cpp +++ b/src/devices/video/imagetek_i4100.cpp @@ -384,7 +384,7 @@ void imagetek_i4100_device::device_start() m_gfxrom_size = m_gfxrom.bytes(); m_irq_cb.resolve_safe(); - m_blit_done_timer = timer_alloc(TIMER_BLIT_END); + m_blit_done_timer = timer_alloc(FUNC(imagetek_i4100_device::blit_done), this); m_spritelist = std::make_unique<sprite_t []>(0x1000 / 8); m_sprite_end = m_spritelist.get(); @@ -533,15 +533,10 @@ void imagetek_i4300_device::update_irq_state() m_irq_cb(level); } -void imagetek_i4100_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(imagetek_i4100_device::blit_done) { - switch (id) - { - case TIMER_BLIT_END: - if (m_blit_irq_level != -1) - set_irq(m_blit_irq_level); - break; - } + if (m_blit_irq_level != -1) + set_irq(m_blit_irq_level); } //************************************************************************** diff --git a/src/devices/video/imagetek_i4100.h b/src/devices/video/imagetek_i4100.h index f8c0f78c034..94635dee733 100644 --- a/src/devices/video/imagetek_i4100.h +++ b/src/devices/video/imagetek_i4100.h @@ -78,10 +78,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 void update_irq_state(); + TIMER_CALLBACK_MEMBER(blit_done); + required_shared_ptr_array<u16, 3> m_vram; required_shared_ptr<u16> m_scratchram; required_shared_ptr<u16> m_blitter_regs; diff --git a/src/devices/video/lc7985.cpp b/src/devices/video/lc7985.cpp index 6608ad6fc71..ef01cbb6a2c 100644 --- a/src/devices/video/lc7985.cpp +++ b/src/devices/video/lc7985.cpp @@ -31,7 +31,7 @@ const tiny_rom_entry *lc7985_device::device_rom_region() const void lc7985_device::device_start() { m_cgrom = m_cgrom_region.found() ? m_cgrom_region : memregion("cgrom")->base(); - m_busy_timer = timer_alloc(0); + m_busy_timer = timer_alloc(FUNC(lc7985_device::clear_busy_flag), this); save_item(NAME(m_ddram)); save_item(NAME(m_cgram)); @@ -66,7 +66,7 @@ void lc7985_device::busy(attotime time) m_busy_timer->adjust(time); } -void lc7985_device::device_timer(emu_timer &, device_timer_id, int) +TIMER_CALLBACK_MEMBER(lc7985_device::clear_busy_flag) { m_busy_flag = false; } diff --git a/src/devices/video/lc7985.h b/src/devices/video/lc7985.h index 1d989e83e85..353822e7462 100644 --- a/src/devices/video/lc7985.h +++ b/src/devices/video/lc7985.h @@ -27,9 +27,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 const tiny_rom_entry *device_rom_region() const override; + TIMER_CALLBACK_MEMBER(clear_busy_flag); + private: optional_region_ptr<u8> m_cgrom_region; // internal chargen ROM u8 m_render_buffer[16*40]; diff --git a/src/devices/video/mc6845.cpp b/src/devices/video/mc6845.cpp index c1e3ca971aa..553839da2b1 100644 --- a/src/devices/video/mc6845.cpp +++ b/src/devices/video/mc6845.cpp @@ -843,7 +843,7 @@ bool hd6845s_device::check_cursor_visible(uint16_t ra, uint16_t line_addr) } -void mc6845_device::handle_line_timer() +TIMER_CALLBACK_MEMBER(mc6845_device::handle_line_timer) { bool new_vsync = m_vsync; @@ -932,7 +932,7 @@ void mc6845_device::handle_line_timer() m_cursor_x = m_cursor_addr - m_line_address; /* Schedule CURSOR ON signal */ - m_cur_on_timer->adjust(cclks_to_attotime(m_cursor_x)); + m_cursor_on_timer->adjust(cclks_to_attotime(m_cursor_x)); } } @@ -948,99 +948,82 @@ void mc6845_device::handle_line_timer() } -void mc6845_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(mc6845_device::de_off_tick) { - switch (id) - { - case TIMER_LINE: - handle_line_timer(); - break; - - case TIMER_DE_OFF: - set_de( false ); - break; - - case TIMER_CUR_ON: - set_cur( true ); + set_de( false ); +} - /* Schedule CURSOR off signal */ - m_cur_off_timer->adjust(cclks_to_attotime(1)); - break; +TIMER_CALLBACK_MEMBER(mc6845_device::cursor_on) +{ + set_cur(true); - case TIMER_CUR_OFF: - set_cur( false ); - break; + /* Schedule CURSOR off signal */ + m_cursor_off_timer->adjust(cclks_to_attotime(1)); +} - case TIMER_HSYNC_ON: - { - uint8_t hsync_width = ( m_sync_width & 0x0f ) ? ( m_sync_width & 0x0f ) : 0x10; +TIMER_CALLBACK_MEMBER(mc6845_device::cursor_off) +{ + set_cur(false); +} - m_hsync_width_counter = 0; - set_hsync( true ); +TIMER_CALLBACK_MEMBER(mc6845_device::hsync_on) +{ + uint8_t hsync_width = ( m_sync_width & 0x0f ) ? ( m_sync_width & 0x0f ) : 0x10; - /* Schedule HSYNC off signal */ - m_hsync_off_timer->adjust(cclks_to_attotime(hsync_width)); - } - break; + m_hsync_width_counter = 0; + set_hsync( true ); - case TIMER_HSYNC_OFF: - set_hsync( false ); - break; + /* Schedule HSYNC off signal */ + m_hsync_off_timer->adjust(cclks_to_attotime(hsync_width)); +} - case TIMER_LIGHT_PEN_LATCH: - m_light_pen_addr = get_ma(); - m_light_pen_latched = true; - break; +TIMER_CALLBACK_MEMBER(mc6845_device::hsync_off) +{ + set_hsync( false ); +} - case TIMER_UPD_ADR: - /* fire a update address strobe */ - call_on_update_address(MODE_UPDATE_STROBE); - break; +TIMER_CALLBACK_MEMBER(mc6845_device::latch_light_pen) +{ + m_light_pen_addr = get_ma(); + m_light_pen_latched = true; +} - case TIMER_UPD_TRANS: - { - int addr = (param >> 8); - int strobe = (param & 0xff); +TIMER_CALLBACK_MEMBER(mc6845_device::adr_update_tick) +{ + /* fire a update address strobe */ + call_on_update_address(MODE_UPDATE_STROBE); +} - /* call the callback function -- we know it exists */ - m_on_update_addr_changed_cb(addr, strobe); +TIMER_CALLBACK_MEMBER(mc6845_device::transparent_update_tick) +{ + int addr = (param >> 8); + int strobe = (param & 0xff); - if(!m_update_ready_bit && MODE_TRANSPARENT_BLANK) - { - m_update_addr++; - m_update_addr &= 0x3fff; - m_update_ready_bit = true; - } - } - break; + /* call the callback function -- we know it exists */ + m_on_update_addr_changed_cb(addr, strobe); + if(!m_update_ready_bit && MODE_TRANSPARENT_BLANK) + { + m_update_addr++; + m_update_addr &= 0x3fff; + m_update_ready_bit = true; } } -void mos8563_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(mos8563_device::block_copy_tick) { - switch (id) - { - case TIMER_BLOCK_COPY: - { - uint8_t data = VSS_COPY ? read_videoram(m_block_addr++) : m_data; + uint8_t data = VSS_COPY ? read_videoram(m_block_addr++) : m_data; - write_videoram(m_update_addr++, data); + write_videoram(m_update_addr++, data); - if (--m_word_count) - { - m_block_copy_timer->adjust(cclks_to_attotime(1)); - } - else - { - m_update_ready_bit = 1; - } - break; + if (--m_word_count) + { + m_block_copy_timer->adjust(cclks_to_attotime(1)); } - default: - mc6845_device::device_timer(timer, id, param); - break; + else + { + m_update_ready_bit = 1; } } @@ -1237,15 +1220,15 @@ void mc6845_device::device_start() m_out_vsync_cb.resolve_safe(); /* create the timers */ - m_line_timer = timer_alloc(TIMER_LINE); - m_de_off_timer = timer_alloc(TIMER_DE_OFF); - m_cur_on_timer = timer_alloc(TIMER_CUR_ON); - m_cur_off_timer = timer_alloc(TIMER_CUR_OFF); - m_hsync_on_timer = timer_alloc(TIMER_HSYNC_ON); - m_hsync_off_timer = timer_alloc(TIMER_HSYNC_OFF); - m_light_pen_latch_timer = timer_alloc(TIMER_LIGHT_PEN_LATCH); - m_upd_adr_timer = timer_alloc(TIMER_UPD_ADR); - m_upd_trans_timer = timer_alloc(TIMER_UPD_TRANS); + m_line_timer = timer_alloc(FUNC(mc6845_device::handle_line_timer), this); + m_de_off_timer = timer_alloc(FUNC(mc6845_device::de_off_tick), this); + m_cursor_on_timer = timer_alloc(FUNC(mc6845_device::cursor_on), this); + m_cursor_off_timer = timer_alloc(FUNC(mc6845_device::cursor_off), this); + m_hsync_on_timer = timer_alloc(FUNC(mc6845_device::hsync_on), this); + m_hsync_off_timer = timer_alloc(FUNC(mc6845_device::hsync_off), this); + m_light_pen_latch_timer = timer_alloc(FUNC(mc6845_device::latch_light_pen), this); + m_upd_adr_timer = timer_alloc(FUNC(mc6845_device::adr_update_tick), this); + m_upd_trans_timer = timer_alloc(FUNC(mc6845_device::transparent_update_tick), this); /* Use some large startup values */ m_horiz_char_total = 0xff; @@ -1475,7 +1458,7 @@ void mos8563_device::device_start() mc6845_device::device_start(); /* create the timers */ - m_block_copy_timer = timer_alloc(TIMER_BLOCK_COPY); + m_block_copy_timer = timer_alloc(FUNC(mos8563_device::block_copy_tick), this); m_supports_status_reg_d5 = true; m_supports_status_reg_d6 = true; diff --git a/src/devices/video/mc6845.h b/src/devices/video/mc6845.h index 3be35da59c3..bfbf4715e96 100644 --- a/src/devices/video/mc6845.h +++ b/src/devices/video/mc6845.h @@ -132,7 +132,6 @@ protected: virtual void device_reset() override; virtual void device_post_load() override; virtual void device_clock_changed() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; attotime cclks_to_attotime(uint64_t clocks) const { return clocks_to_attotime(clocks * m_clk_scale); } uint64_t attotime_to_cclks(const attotime &duration) const { return attotime_to_clocks(duration) / m_clk_scale; } @@ -188,20 +187,10 @@ protected: int16_t m_cursor_x; /* timers */ - static const device_timer_id TIMER_LINE = 0; - static const device_timer_id TIMER_DE_OFF = 1; - static const device_timer_id TIMER_CUR_ON = 2; - static const device_timer_id TIMER_CUR_OFF = 3; - static const device_timer_id TIMER_HSYNC_ON = 4; - static const device_timer_id TIMER_HSYNC_OFF = 5; - static const device_timer_id TIMER_LIGHT_PEN_LATCH = 6; - static const device_timer_id TIMER_UPD_ADR = 7; - static const device_timer_id TIMER_UPD_TRANS = 8; - emu_timer *m_line_timer; emu_timer *m_de_off_timer; - emu_timer *m_cur_on_timer; - emu_timer *m_cur_off_timer; + emu_timer *m_cursor_on_timer; + emu_timer *m_cursor_off_timer; emu_timer *m_hsync_on_timer; emu_timer *m_hsync_off_timer; emu_timer *m_light_pen_latch_timer; @@ -237,7 +226,15 @@ protected: void set_cur(int state); bool match_line(); virtual bool check_cursor_visible(uint16_t ra, uint16_t line_addr); - void handle_line_timer(); + TIMER_CALLBACK_MEMBER(handle_line_timer); + TIMER_CALLBACK_MEMBER(de_off_tick); + TIMER_CALLBACK_MEMBER(cursor_on); + TIMER_CALLBACK_MEMBER(cursor_off); + TIMER_CALLBACK_MEMBER(hsync_on); + TIMER_CALLBACK_MEMBER(hsync_off); + TIMER_CALLBACK_MEMBER(latch_light_pen); + TIMER_CALLBACK_MEMBER(adr_update_tick); + TIMER_CALLBACK_MEMBER(transparent_update_tick); virtual void update_cursor_state(); virtual uint8_t draw_scanline(int y, bitmap_rgb32 &bitmap, const rectangle &cliprect); @@ -425,7 +422,6 @@ protected: // device-level overrides virtual void device_start() override; virtual void device_reset() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; // device_memory_interface overrides virtual space_config_vector memory_space_config() const override; @@ -433,6 +429,8 @@ protected: // device_palette_interface overrides virtual uint32_t palette_entries() const override { return 16; } + TIMER_CALLBACK_MEMBER(block_copy_tick); + const address_space_config m_videoram_space_config; uint8_t m_char_buffer[80]; @@ -463,8 +461,6 @@ protected: virtual void update_cursor_state() override; virtual uint8_t draw_scanline(int y, bitmap_rgb32 &bitmap, const rectangle &cliprect) override; - static const device_timer_id TIMER_BLOCK_COPY = 9; - emu_timer *m_block_copy_timer; void mos8563_videoram_map(address_map &map); diff --git a/src/devices/video/mc6847.cpp b/src/devices/video/mc6847.cpp index 972e77d0165..eb3b6f355cc 100644 --- a/src/devices/video/mc6847.cpp +++ b/src/devices/video/mc6847.cpp @@ -148,23 +148,6 @@ mc6847_friend_device::mc6847_friend_device(const machine_config &mconfig, device //------------------------------------------------- -// setup_timer - sets up a single timer relative -// to the clock -//------------------------------------------------- - -inline emu_timer *mc6847_friend_device::setup_timer(device_timer_id id, double offset, double period) -{ - emu_timer *timer = timer_alloc(id); - timer->adjust( - clocks_to_attotime(offset * m_divider), - 0, - clocks_to_attotime(period * m_divider)); - return timer; -} - - - -//------------------------------------------------- // device_start - device-specific startup //------------------------------------------------- @@ -174,10 +157,14 @@ void mc6847_friend_device::device_start() m_write_fsync.resolve_safe(); /* create the timers */ - m_frame_timer = setup_timer( TIMER_FRAME, 0, m_tpfs * TIMER_HSYNC_PERIOD); - m_hsync_on_timer = setup_timer( TIMER_HSYNC_ON, TIMER_HSYNC_ON_TIME, TIMER_HSYNC_PERIOD); - m_hsync_off_timer = setup_timer(TIMER_HSYNC_OFF, TIMER_HSYNC_OFF_TIME, TIMER_HSYNC_PERIOD); - m_fsync_timer = timer_alloc(TIMER_FSYNC); + m_frame_timer = timer_alloc(FUNC(mc6847_friend_device::new_frame), this); + m_hsync_on_timer = timer_alloc(FUNC(mc6847_friend_device::change_horizontal_sync), this); + m_hsync_off_timer = timer_alloc(FUNC(mc6847_friend_device::change_horizontal_sync), this); + m_fsync_timer = timer_alloc(FUNC(mc6847_friend_device::change_field_sync), this); + + m_frame_timer->adjust(clocks_to_attotime(0), 0, clocks_to_attotime(m_tpfs * TIMER_HSYNC_PERIOD * m_divider)); + m_hsync_on_timer->adjust(clocks_to_attotime(TIMER_HSYNC_ON_TIME * m_divider), 1, clocks_to_attotime(TIMER_HSYNC_PERIOD * m_divider)); + m_hsync_off_timer->adjust(clocks_to_attotime(TIMER_HSYNC_OFF_TIME * m_divider), 0, clocks_to_attotime(TIMER_HSYNC_PERIOD * m_divider)); m_top_border_scanlines = 0; m_body_scanlines = 0; @@ -250,27 +237,10 @@ void mc6847_friend_device::update_field_sync_timer() //------------------------------------------------- -// device_timer -//------------------------------------------------- - -void mc6847_friend_device::device_timer(emu_timer &timer, device_timer_id id, int param) -{ - switch(id) - { - case TIMER_FRAME: new_frame(); break; - case TIMER_HSYNC_ON: change_horizontal_sync(true); break; - case TIMER_HSYNC_OFF: change_horizontal_sync(false); break; - case TIMER_FSYNC: change_field_sync(param != 0); break; - } -} - - - -//------------------------------------------------- // new_frame //------------------------------------------------- -inline void mc6847_friend_device::new_frame() +TIMER_CALLBACK_MEMBER(mc6847_friend_device::new_frame) { m_physical_scanline = 0; m_logical_scanline = 0; @@ -306,8 +276,9 @@ std::string mc6847_friend_device::scanline_zone_string(scanline_zone zone) const // change_horizontal_sync //------------------------------------------------- -inline void mc6847_friend_device::change_horizontal_sync(bool line) +TIMER_CALLBACK_MEMBER(mc6847_friend_device::change_horizontal_sync) { + bool line = (bool)param; g_profiler.start(PROFILER_USER1); // are we on a rising edge? @@ -374,8 +345,9 @@ inline void mc6847_friend_device::change_horizontal_sync(bool line) // change_field_sync //------------------------------------------------- -inline void mc6847_friend_device::change_field_sync(bool line) +TIMER_CALLBACK_MEMBER(mc6847_friend_device::change_field_sync) { + bool line = (bool)param; /* output field sync */ if (line != m_field_sync) { @@ -446,7 +418,7 @@ inline void mc6847_friend_device::next_scanline() // horizontal_sync_changed //------------------------------------------------- -void mc6847_friend_device::horizontal_sync_changed(bool line) +TIMER_CALLBACK_MEMBER(mc6847_friend_device::horizontal_sync_changed) { } diff --git a/src/devices/video/mc6847.h b/src/devices/video/mc6847.h index c26582fc4c6..03fb55084a5 100644 --- a/src/devices/video/mc6847.h +++ b/src/devices/video/mc6847.h @@ -60,12 +60,6 @@ protected: mc6847_friend_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock, const uint8_t *fontdata, bool is_mc6847t1, double tpfs, int field_sync_falling_edge_scanline, int divider, bool supports_partial_body_scanlines); - // timer constants - static constexpr device_timer_id TIMER_FRAME = 0; - static constexpr device_timer_id TIMER_HSYNC_OFF = 1; - static constexpr device_timer_id TIMER_HSYNC_ON = 2; - static constexpr device_timer_id TIMER_FSYNC = 3; - // fonts static const uint8_t pal_round_fontdata8x12[]; static const uint8_t pal_square_fontdata8x12[]; @@ -275,13 +269,12 @@ protected: // device-level overrides virtual void device_start() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; virtual void device_reset() override; virtual void device_post_load() override; // other overridables - virtual void new_frame(); - virtual void horizontal_sync_changed(bool line); + virtual TIMER_CALLBACK_MEMBER(new_frame); + virtual TIMER_CALLBACK_MEMBER(horizontal_sync_changed); virtual void field_sync_changed(bool line); virtual void enter_bottom_border(); virtual void record_border_scanline(uint16_t physical_scanline); @@ -292,9 +285,6 @@ protected: void video_flush(); std::string describe_context() const; - // setup functions - emu_timer *setup_timer(device_timer_id id, double offset, double period); - // converts to B&W static pixel_t black_and_white(rgb_t color) { @@ -499,8 +489,8 @@ private: uint32_t m_partial_scanline_clocks; // functions - void change_horizontal_sync(bool line); - void change_field_sync(bool line); + virtual TIMER_CALLBACK_MEMBER(change_horizontal_sync); + TIMER_CALLBACK_MEMBER(change_field_sync); void update_field_sync_timer(); void next_scanline(); int32_t get_clocks_since_hsync(); diff --git a/src/devices/video/nt7534.cpp b/src/devices/video/nt7534.cpp index d72bdbe2b4a..e1065376860 100644 --- a/src/devices/video/nt7534.cpp +++ b/src/devices/video/nt7534.cpp @@ -44,7 +44,7 @@ nt7534_device::nt7534_device(const machine_config &mconfig, device_type type, co void nt7534_device::device_start() { - m_busy_timer = timer_alloc(TIMER_BUSY); + m_busy_timer = timer_alloc(FUNC(nt7534_device::clear_busy_flag), this); m_pixel_update_cb.resolve(); @@ -97,17 +97,12 @@ void nt7534_device::device_reset() //------------------------------------------------- -// device_timer - handler timer events +// clear_busy_flag - //------------------------------------------------- -void nt7534_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(nt7534_device::clear_busy_flag) { - switch (id) - { - case TIMER_BUSY: - m_busy_flag = false; - break; - } + m_busy_flag = false; } diff --git a/src/devices/video/nt7534.h b/src/devices/video/nt7534.h index 7b4db9d51c9..126d5dfff92 100644 --- a/src/devices/video/nt7534.h +++ b/src/devices/video/nt7534.h @@ -48,15 +48,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; + + TIMER_CALLBACK_MEMBER(clear_busy_flag); + private: // internal helper void set_busy_flag(uint16_t usec); void update_nibble(int rs, int rw); // internal state - static constexpr device_timer_id TIMER_BUSY = 0; - emu_timer * m_busy_timer; pixel_update_delegate m_pixel_update_cb; // pixel update callback diff --git a/src/devices/video/pc_vga.cpp b/src/devices/video/pc_vga.cpp index a553813a8d7..35c2f6e5d0b 100644 --- a/src/devices/video/pc_vga.cpp +++ b/src/devices/video/pc_vga.cpp @@ -351,7 +351,7 @@ void vga_device::device_start() save_item(NAME(vga.dac.color)); save_item(NAME(vga.dac.dirty)); - m_vblank_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(vga_device::vblank_timer_cb),this)); + m_vblank_timer = timer_alloc(FUNC(vga_device::vblank_timer_cb), this); } void svga_device::device_start() diff --git a/src/devices/video/pcf2100.cpp b/src/devices/video/pcf2100.cpp index 12df4488d0a..7cdcd044c6f 100644 --- a/src/devices/video/pcf2100.cpp +++ b/src/devices/video/pcf2100.cpp @@ -59,7 +59,7 @@ void pcf2100_device::device_start() m_write_segs.resolve_safe(); // timer - m_lcd_timer = timer_alloc(); + m_lcd_timer = timer_alloc(FUNC(pcf2100_device::update_output_latches), this); attotime period = attotime::from_hz(clock()); m_lcd_timer->adjust(period, 0, period); @@ -78,7 +78,7 @@ void pcf2100_device::device_start() // handlers //------------------------------------------------- -void pcf2100_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(pcf2100_device::update_output_latches) { // transfer latches to output m_write_segs(m_bpout, m_latch[m_bpout]); diff --git a/src/devices/video/pcf2100.h b/src/devices/video/pcf2100.h index 74a830f0712..c4e657fef19 100644 --- a/src/devices/video/pcf2100.h +++ b/src/devices/video/pcf2100.h @@ -47,7 +47,8 @@ protected: // device-level overrides virtual void device_start() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; + + TIMER_CALLBACK_MEMBER(update_output_latches); emu_timer *m_lcd_timer; diff --git a/src/devices/video/ppu2c0x.cpp b/src/devices/video/ppu2c0x.cpp index ce52232d372..d8f3ca4748b 100644 --- a/src/devices/video/ppu2c0x.cpp +++ b/src/devices/video/ppu2c0x.cpp @@ -220,9 +220,9 @@ void ppu2c0x_device::start_nopalram() m_int_callback.resolve_safe(); // allocate timers - m_hblank_timer = timer_alloc(TIMER_HBLANK); - m_nmi_timer = timer_alloc(TIMER_NMI); - m_scanline_timer = timer_alloc(TIMER_SCANLINE); + m_hblank_timer = timer_alloc(FUNC(ppu2c0x_device::hblank_tick), this); + m_nmi_timer = timer_alloc(FUNC(ppu2c0x_device::nmi_tick), this); + m_scanline_timer = timer_alloc(FUNC(ppu2c0x_device::scanline_tick), this); /* initialize the scanline handling portion */ m_scanline_timer->adjust(screen().time_until_pos(1)); @@ -492,100 +492,94 @@ void ppu2c04_clone_device::init_palette_tables() *************************************/ //------------------------------------------------- -// device_timer - handle timer events +// timer events //------------------------------------------------- -void ppu2c0x_device::device_timer(emu_timer& timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(ppu2c0x_device::hblank_tick) { - int blanked, vblank; + bool blanked = (m_regs[PPU_CONTROL1] & (PPU_CONTROL1_BACKGROUND | PPU_CONTROL1_SPRITES)) == 0; + bool vblank = (m_scanline >= m_vblank_first_scanline - 1) && (m_scanline < m_scanlines_per_frame - 1); - switch (id) - { - case TIMER_HBLANK: - blanked = (m_regs[PPU_CONTROL1] & (PPU_CONTROL1_BACKGROUND | PPU_CONTROL1_SPRITES)) == 0; - vblank = ((m_scanline >= m_vblank_first_scanline - 1) && (m_scanline < m_scanlines_per_frame - 1)) ? 1 : 0; + //update_scanline(); - //update_scanline(); + if (!m_hblank_callback_proc.isnull()) + m_hblank_callback_proc(m_scanline, vblank, blanked); - if (!m_hblank_callback_proc.isnull()) - m_hblank_callback_proc(m_scanline, vblank, blanked); + m_hblank_timer->adjust(attotime::never); +} - m_hblank_timer->adjust(attotime::never); - break; +TIMER_CALLBACK_MEMBER(ppu2c0x_device::nmi_tick) +{ + // Actually fire the VMI + m_int_callback(ASSERT_LINE); + m_int_callback(CLEAR_LINE); - case TIMER_NMI: - // Actually fire the VMI - m_int_callback(ASSERT_LINE); - m_int_callback(CLEAR_LINE); + m_nmi_timer->adjust(attotime::never); +} - m_nmi_timer->adjust(attotime::never); - break; +TIMER_CALLBACK_MEMBER(ppu2c0x_device::scanline_tick) +{ + bool blanked = (m_regs[PPU_CONTROL1] & (PPU_CONTROL1_BACKGROUND | PPU_CONTROL1_SPRITES)) == 0; + bool vblank = ((m_scanline >= m_vblank_first_scanline - 1) && (m_scanline < m_scanlines_per_frame - 1)) ? 1 : 0; - case TIMER_SCANLINE: - blanked = (m_regs[PPU_CONTROL1] & (PPU_CONTROL1_BACKGROUND | PPU_CONTROL1_SPRITES)) == 0; - vblank = ((m_scanline >= m_vblank_first_scanline - 1) && (m_scanline < m_scanlines_per_frame - 1)) ? 1 : 0; - int next_scanline; + /* if a callback is available, call it */ + if (!m_scanline_callback_proc.isnull()) + m_scanline_callback_proc(m_scanline, vblank, blanked); - /* if a callback is available, call it */ - if (!m_scanline_callback_proc.isnull()) - m_scanline_callback_proc(m_scanline, vblank, blanked); + /* update the scanline that just went by */ + update_scanline(); - /* update the scanline that just went by */ - update_scanline(); + /* increment our scanline count */ + m_scanline++; - /* increment our scanline count */ - m_scanline++; + //logerror("starting scanline %d (MAME %d, beam %d)\n", m_scanline, device->screen().vpos(), device->screen().hpos()); - //logerror("starting scanline %d (MAME %d, beam %d)\n", m_scanline, device->screen().vpos(), device->screen().hpos()); + /* Note: this is called at the _end_ of each scanline */ + if (m_scanline == m_vblank_first_scanline) + { + // logerror("vblank starting\n"); + /* We just entered VBLANK */ + m_regs[PPU_STATUS] |= PPU_STATUS_VBLANK; - /* Note: this is called at the _end_ of each scanline */ - if (m_scanline == m_vblank_first_scanline) + /* If NMI's are set to be triggered, go for it */ + if (m_regs[PPU_CONTROL0] & PPU_CONTROL0_NMI) { - // logerror("vblank starting\n"); - /* We just entered VBLANK */ - m_regs[PPU_STATUS] |= PPU_STATUS_VBLANK; - - /* If NMI's are set to be triggered, go for it */ - if (m_regs[PPU_CONTROL0] & PPU_CONTROL0_NMI) - { - // We need an ever-so-slight delay between entering vblank and firing an NMI - enough so that - // a game can read the high bit of $2002 before the NMI is called (potentially resetting the bit - // via a read from $2002 in the NMI handler). - // B-Wings is an example game that needs this. - m_nmi_timer->adjust(m_cpu->cycles_to_attotime(4)); - } + // We need an ever-so-slight delay between entering vblank and firing an NMI - enough so that + // a game can read the high bit of $2002 before the NMI is called (potentially resetting the bit + // via a read from $2002 in the NMI handler). + // B-Wings is an example game that needs this. + m_nmi_timer->adjust(m_cpu->cycles_to_attotime(4)); } + } - if (m_scanline == m_scanlines_per_frame - 1) - { - //logerror("vblank ending\n"); - /* clear the vblank & sprite hit flag */ - m_regs[PPU_STATUS] &= ~(PPU_STATUS_VBLANK | PPU_STATUS_SPRITE0_HIT | PPU_STATUS_8SPRITES); - } + if (m_scanline == m_scanlines_per_frame - 1) + { + //logerror("vblank ending\n"); + /* clear the vblank & sprite hit flag */ + m_regs[PPU_STATUS] &= ~(PPU_STATUS_VBLANK | PPU_STATUS_SPRITE0_HIT | PPU_STATUS_8SPRITES); + } - /* see if we rolled */ - else if (m_scanline == m_scanlines_per_frame) - { - /* if background or sprites are enabled, copy the ppu address latch */ - if (!blanked) - m_refresh_data = m_refresh_latch; + /* see if we rolled */ + else if (m_scanline == m_scanlines_per_frame) + { + /* if background or sprites are enabled, copy the ppu address latch */ + if (!blanked) + m_refresh_data = m_refresh_latch; - /* reset the scanline count */ - m_scanline = 0; - //logerror("sprite 0 x: %d y: %d num: %d\n", m_spriteram[3], m_spriteram[0] + 1, m_spriteram[1]); - } + /* reset the scanline count */ + m_scanline = 0; + //logerror("sprite 0 x: %d y: %d num: %d\n", m_spriteram[3], m_spriteram[0] + 1, m_spriteram[1]); + } - next_scanline = m_scanline + 1; - if (next_scanline == m_scanlines_per_frame) - next_scanline = 0; + int next_scanline = m_scanline + 1; + if (next_scanline == m_scanlines_per_frame) + next_scanline = 0; - // Call us back when the hblank starts for this scanline - m_hblank_timer->adjust(m_cpu->cycles_to_attotime(260) / 3); // ??? FIXME - hardcoding NTSC, need better calculation + // Call us back when the hblank starts for this scanline + m_hblank_timer->adjust(m_cpu->cycles_to_attotime(260) / 3); // ??? FIXME - hardcoding NTSC, need better calculation - // trigger again at the start of the next scanline - m_scanline_timer->adjust(screen().time_until_pos(next_scanline * m_scan_scale)); - break; - } + // trigger again at the start of the next scanline + m_scanline_timer->adjust(screen().time_until_pos(next_scanline * m_scan_scale)); } diff --git a/src/devices/video/ppu2c0x.h b/src/devices/video/ppu2c0x.h index e1e3fb07367..0be6231b97d 100644 --- a/src/devices/video/ppu2c0x.h +++ b/src/devices/video/ppu2c0x.h @@ -45,8 +45,8 @@ class ppu2c0x_device : public device_t, public device_video_interface { public: - typedef device_delegate<void (int scanline, int vblank, int blanked)> scanline_delegate; - typedef device_delegate<void (int scanline, int vblank, int blanked)> hblank_delegate; + typedef device_delegate<void (int scanline, bool vblank, bool blanked)> scanline_delegate; + typedef device_delegate<void (int scanline, bool vblank, bool blanked)> hblank_delegate; typedef device_delegate<void (int *ppu_regs)> nmi_delegate; typedef device_delegate<int (int address, int data)> vidaccess_delegate; typedef device_delegate<void (offs_t offset)> latch_delegate; @@ -177,12 +177,15 @@ protected: ppu2c0x_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock = 0); virtual void device_start() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; virtual void device_config_complete() override; // device_config_memory_interface overrides virtual space_config_vector memory_space_config() const override; + TIMER_CALLBACK_MEMBER(hblank_tick); + TIMER_CALLBACK_MEMBER(nmi_tick); + TIMER_CALLBACK_MEMBER(scanline_tick); + // address space configurations const address_space_config m_space_config; @@ -214,15 +217,11 @@ protected: int m_tilecount; /* MMC5 can change attributes to subsets of the 34 visible tiles */ latch_delegate m_latch; - uint8_t readbyte(offs_t address); uint32_t m_nespens[0x40*8]; -private: - static constexpr device_timer_id TIMER_HBLANK = 0; - static constexpr device_timer_id TIMER_NMI = 1; - static constexpr device_timer_id TIMER_SCANLINE = 2; +private: inline void writebyte(offs_t address, uint8_t data); inline uint16_t apply_grayscale_and_emphasis(uint8_t color); diff --git a/src/devices/video/pwm.cpp b/src/devices/video/pwm.cpp index 70fc9f44724..5258b204392 100644 --- a/src/devices/video/pwm.cpp +++ b/src/devices/video/pwm.cpp @@ -98,7 +98,7 @@ void pwm_display_device::device_start() for (auto &bri : m_bri) std::fill(std::begin(bri), std::end(bri), 0.0); - m_frame_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(pwm_display_device::frame_tick),this)); + m_frame_timer = timer_alloc(FUNC(pwm_display_device::frame_tick), this); m_sync_time = machine().time(); // register for savestates diff --git a/src/devices/video/scn2674.cpp b/src/devices/video/scn2674.cpp index 96e1e7d3ca5..3461a15083c 100644 --- a/src/devices/video/scn2674.cpp +++ b/src/devices/video/scn2674.cpp @@ -112,9 +112,9 @@ void scn2674_device::device_start() m_mbc_cb.resolve_safe(); m_mbc_char_cb.resolve(); m_mbc_attr_cb.resolve(); - m_scanline_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(scn2674_device::scanline_timer), this)); - m_breq_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(scn2674_device::breq_timer), this)); - m_vblank_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(scn2674_device::vblank_timer), this)); + m_scanline_timer = timer_alloc(FUNC(scn2674_device::scanline_timer), this); + m_breq_timer = timer_alloc(FUNC(scn2674_device::breq_timer), this); + m_vblank_timer = timer_alloc(FUNC(scn2674_device::vblank_timer), this); screen().register_screen_bitmap(m_bitmap); m_char_space = &space(0); diff --git a/src/devices/video/sed1500.cpp b/src/devices/video/sed1500.cpp index abea4b94bc9..57f7a026e4c 100644 --- a/src/devices/video/sed1500.cpp +++ b/src/devices/video/sed1500.cpp @@ -69,7 +69,7 @@ void sed1500_device::device_start() m_write_segs.resolve_safe(); // timer - m_lcd_timer = timer_alloc(); + m_lcd_timer = timer_alloc(FUNC(sed1500_device::update_segs), this); attotime period = attotime::from_hz(clock() / 64); m_lcd_timer->adjust(period, 0, period); @@ -84,7 +84,7 @@ void sed1500_device::device_start() // handlers //------------------------------------------------- -void sed1500_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(sed1500_device::update_segs) { u64 data = 0; diff --git a/src/devices/video/sed1500.h b/src/devices/video/sed1500.h index 1186cbc7e14..21981c35034 100644 --- a/src/devices/video/sed1500.h +++ b/src/devices/video/sed1500.h @@ -44,7 +44,8 @@ protected: // device-level overrides virtual void device_start() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; + + TIMER_CALLBACK_MEMBER(update_segs); emu_timer *m_lcd_timer; diff --git a/src/devices/video/tms34061.cpp b/src/devices/video/tms34061.cpp index 16d7ba65fa8..8d987b06701 100644 --- a/src/devices/video/tms34061.cpp +++ b/src/devices/video/tms34061.cpp @@ -97,7 +97,7 @@ void tms34061_device::device_start() m_regs[TMS34061_VERCOUNTER] = 0x0000; /* start vertical interrupt timer */ - m_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(tms34061_device::interrupt), this)); + m_timer = timer_alloc(FUNC(tms34061_device::interrupt), this); save_item(NAME(m_regs)); save_item(NAME(m_xmask)); diff --git a/src/devices/video/tms9927.cpp b/src/devices/video/tms9927.cpp index 7ef7fb143ca..6ae31a1a9d5 100644 --- a/src/devices/video/tms9927.cpp +++ b/src/devices/video/tms9927.cpp @@ -89,8 +89,8 @@ void tms9927_device::device_start() m_write_hsyn.resolve(); // allocate timers - m_vsync_timer = timer_alloc(TIMER_VSYNC); - m_hsync_timer = timer_alloc(TIMER_HSYNC); + m_vsync_timer = timer_alloc(FUNC(tms9927_device::toggle_vsync), this); + m_hsync_timer = timer_alloc(FUNC(tms9927_device::toggle_hsync), this); // register for state saving save_item(NAME(m_reg)); @@ -137,46 +137,42 @@ void tms9927_device::device_stop() //------------------------------------------------- -// device_timer - handle timer events +// timer events //------------------------------------------------- -void tms9927_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(tms9927_device::toggle_vsync) { - switch (id) + m_vsyn = !m_vsyn; + m_write_vsyn(m_vsyn ? 1 : 0); + + if (m_vsyn) { - case TIMER_VSYNC: - m_vsyn = !m_vsyn; - m_write_vsyn(m_vsyn ? 1 : 0); - - if (m_vsyn) - { - m_vsync_timer->adjust(screen().time_until_pos(m_vsyn_end, m_hsyn_start)); - } - else - { - m_vsync_timer->adjust(screen().time_until_pos(m_vsyn_start, m_hsyn_start)); - } - break; - - case TIMER_HSYNC: - m_hsyn = !m_hsyn; - m_write_hsyn(m_hsyn ? 1 : 0); - - uint16_t vpos = screen().vpos(); - if (m_hsyn) - { - screen().update_now(); - if (screen().hpos() > m_hsyn_end) - vpos = (vpos + 1) % m_total_vpix; - m_hsync_timer->adjust(screen().time_until_pos(vpos, m_hsyn_end)); - } - else - { - if (screen().hpos() > m_hsyn_start) - vpos = (vpos + 1) % m_total_vpix; - m_hsync_timer->adjust(screen().time_until_pos(vpos, m_hsyn_start)); - } - break; + m_vsync_timer->adjust(screen().time_until_pos(m_vsyn_end, m_hsyn_start)); + } + else + { + m_vsync_timer->adjust(screen().time_until_pos(m_vsyn_start, m_hsyn_start)); + } +} + +TIMER_CALLBACK_MEMBER(tms9927_device::toggle_hsync) +{ + m_hsyn = !m_hsyn; + m_write_hsyn(m_hsyn ? 1 : 0); + + uint16_t vpos = screen().vpos(); + if (m_hsyn) + { + screen().update_now(); + if (screen().hpos() > m_hsyn_end) + vpos = (vpos + 1) % m_total_vpix; + m_hsync_timer->adjust(screen().time_until_pos(vpos, m_hsyn_end)); + } + else + { + if (screen().hpos() > m_hsyn_start) + vpos = (vpos + 1) % m_total_vpix; + m_hsync_timer->adjust(screen().time_until_pos(vpos, m_hsyn_start)); } } diff --git a/src/devices/video/tms9927.h b/src/devices/video/tms9927.h index f407cddb15f..79e42685494 100644 --- a/src/devices/video/tms9927.h +++ b/src/devices/video/tms9927.h @@ -45,9 +45,11 @@ protected: virtual void device_stop() override; virtual void device_reset() override; virtual void device_clock_changed() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; virtual void device_post_load() override; + TIMER_CALLBACK_MEMBER(toggle_vsync); + TIMER_CALLBACK_MEMBER(toggle_hsync); + private: enum { diff --git a/src/devices/video/tms9928a.cpp b/src/devices/video/tms9928a.cpp index 9ff0bbbfa52..dffe7b8ba72 100644 --- a/src/devices/video/tms9928a.cpp +++ b/src/devices/video/tms9928a.cpp @@ -351,17 +351,14 @@ void tms9928a_device::register_write(u8 data) } } -void tms9928a_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(tms9928a_device::clock_grom) { - // Handle GROM clock if present - if (id==GROMCLK) - { - // Pulse it - m_out_gromclk_cb(ASSERT_LINE); - m_out_gromclk_cb(CLEAR_LINE); - return; - } + m_out_gromclk_cb(ASSERT_LINE); + m_out_gromclk_cb(CLEAR_LINE); +} +TIMER_CALLBACK_MEMBER(tms9928a_device::update_line) +{ int raw_vpos = screen().vpos(); int vpos = raw_vpos * m_vertical_size / screen().height(); uint16_t BackColour = m_Regs[7] & 15; @@ -737,8 +734,8 @@ void tms9928a_device::device_start() /* back bitmap */ m_tmpbmp.allocate(m_total_horz, TOTAL_VERT_PAL); - m_line_timer = timer_alloc(TIMER_LINE); - m_gromclk_timer = timer_alloc(GROMCLK); + m_line_timer = timer_alloc(FUNC(tms9928a_device::update_line), this); + m_gromclk_timer = timer_alloc(FUNC(tms9928a_device::clock_grom), this); m_INT = 1; // force initial update diff --git a/src/devices/video/tms9928a.h b/src/devices/video/tms9928a.h index addae9e0a20..34dfc7d270f 100644 --- a/src/devices/video/tms9928a.h +++ b/src/devices/video/tms9928a.h @@ -95,7 +95,6 @@ protected: virtual void device_config_complete() override; virtual void device_start() override; virtual void device_reset() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; // device_memory_interface overrides virtual space_config_vector memory_space_config() const override; @@ -103,6 +102,9 @@ protected: // device_palette_interface overrides virtual uint32_t palette_entries() const override { return 16; } + TIMER_CALLBACK_MEMBER(clock_grom); + TIMER_CALLBACK_MEMBER(update_line); + private: void change_register(uint8_t reg, uint8_t val); void check_interrupt(); @@ -112,11 +114,8 @@ private: void memmap(address_map &map); - static const device_timer_id TIMER_LINE = 0; - static const device_timer_id GROMCLK = 1; - int m_vram_size; /* 4K, 8K, or 16K. This should be replaced by fetching data from an address space? */ - devcb_write_line m_out_int_line_cb; /* Callback is called whenever the state of the INT output changes */ + devcb_write_line m_out_int_line_cb; /* Callback is called whenever the state of the INT output changes */ devcb_write_line m_out_gromclk_cb; // GROMCLK line is optional; if present, pulse it by XTAL/24 rate /* TMS9928A internal settings */ @@ -132,12 +131,12 @@ private: uint16_t m_nametbl; uint16_t m_spriteattribute; uint16_t m_spritepattern; - int m_colourmask; - int m_patternmask; + int m_colourmask; + int m_patternmask; const uint16_t m_total_horz; - const bool m_50hz; - const bool m_reva; - const bool m_99; + const bool m_50hz; + const bool m_reva; + const bool m_99; /* memory */ const address_space_config m_space_config; @@ -146,7 +145,7 @@ private: bitmap_rgb32 m_tmpbmp; emu_timer *m_line_timer; emu_timer *m_gromclk_timer; - uint8_t m_mode; + uint8_t m_mode; /* emulation settings */ int m_top_border; diff --git a/src/devices/video/topcat.cpp b/src/devices/video/topcat.cpp index 79b679b8e77..5ba43d81e44 100644 --- a/src/devices/video/topcat.cpp +++ b/src/devices/video/topcat.cpp @@ -25,7 +25,7 @@ topcat_device::topcat_device(const machine_config &mconfig, const char *tag, dev void topcat_device::device_start() { m_int_write_func.resolve_safe(); - m_cursor_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(topcat_device::cursor_callback), this)); + m_cursor_timer = timer_alloc(FUNC(topcat_device::cursor_callback), this); m_cursor_timer->adjust(attotime::from_hz(3)); save_item(NAME(m_vblank)); diff --git a/src/devices/video/upd3301.cpp b/src/devices/video/upd3301.cpp index 3e40384e387..9e213a6c292 100644 --- a/src/devices/video/upd3301.cpp +++ b/src/devices/video/upd3301.cpp @@ -152,9 +152,8 @@ void upd3301_device::device_start() m_attr_fetch_cb.resolve(); // allocate timers - m_hrtc_timer = timer_alloc(TIMER_HRTC); - m_vrtc_timer = timer_alloc(TIMER_VRTC); - m_drq_timer = timer_alloc(TIMER_DRQ); + m_hrtc_timer = timer_alloc(FUNC(upd3301_device::hrtc_update), this); + m_vrtc_timer = timer_alloc(FUNC(upd3301_device::vrtc_update), this); // state saving save_item(NAME(m_y)); @@ -223,7 +222,7 @@ void upd3301_device::device_clock_changed() //------------------------------------------------- -// device_timer - handle timer events +// timer events //------------------------------------------------- // this snipped was inside screen_update fn @@ -254,45 +253,37 @@ inline void upd3301_device::reset_fifo_vrtc() m_bitmap.fill(0, screen().visible_area()); } -void upd3301_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(upd3301_device::hrtc_update) { - switch (id) - { - case TIMER_HRTC: - LOGHRTC("HRTC: %u at beam %d x %d\n", param, screen().hpos(), screen().vpos()); - - m_write_hrtc(param); - m_hrtc = param; + LOGHRTC("HRTC: %u at beam %d x %d\n", param, screen().hpos(), screen().vpos()); - update_hrtc_timer(param); - break; + m_write_hrtc(param); + m_hrtc = param; - case TIMER_VRTC: - LOGINT("VRTC: %u at y %d\n", param, screen().vpos()); - - m_write_vrtc(param); - m_vrtc = param; + update_hrtc_timer(param); +} - update_vrtc_timer(param); - if(!get_display_status()) - break; +TIMER_CALLBACK_MEMBER(upd3301_device::vrtc_update) +{ + LOGINT("VRTC: %u at y %d\n", param, screen().vpos()); - if (!param) - { - reset_fifo_vrtc(); - set_drq(1); - } + m_write_vrtc(param); + m_vrtc = param; - if (param && !m_me) - { - m_status |= STATUS_E; - set_interrupt(1); - } + update_vrtc_timer(param); + if (!get_display_status()) + return; - break; + if (!param) + { + reset_fifo_vrtc(); + set_drq(1); + } - case TIMER_DRQ: - break; + if (param && !m_me) + { + m_status |= STATUS_E; + set_interrupt(1); } } diff --git a/src/devices/video/upd3301.h b/src/devices/video/upd3301.h index 93f0910cf01..9343f6275b2 100644 --- a/src/devices/video/upd3301.h +++ b/src/devices/video/upd3301.h @@ -91,16 +91,11 @@ protected: virtual void device_start() override; virtual void device_reset() override; virtual void device_clock_changed() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; -private: - enum - { - TIMER_HRTC, - TIMER_VRTC, - TIMER_DRQ - }; + TIMER_CALLBACK_MEMBER(hrtc_update); + TIMER_CALLBACK_MEMBER(vrtc_update); +private: void set_interrupt(int state); void set_drq(int state); void set_display(int state); @@ -177,7 +172,6 @@ private: // timers emu_timer *m_hrtc_timer; emu_timer *m_vrtc_timer; - emu_timer *m_drq_timer; }; diff --git a/src/devices/video/upd7220.cpp b/src/devices/video/upd7220.cpp index fb4da2002ac..9925dc60da8 100644 --- a/src/devices/video/upd7220.cpp +++ b/src/devices/video/upd7220.cpp @@ -673,9 +673,9 @@ void upd7220_device::device_start() m_write_blank.resolve_safe(); // allocate timers - m_vsync_timer = timer_alloc(TIMER_VSYNC); - m_hsync_timer = timer_alloc(TIMER_HSYNC); - m_blank_timer = timer_alloc(TIMER_BLANK); + m_vsync_timer = timer_alloc(FUNC(upd7220_device::vsync_update), this); + m_hsync_timer = timer_alloc(FUNC(upd7220_device::hsync_update), this); + m_blank_timer = timer_alloc(FUNC(upd7220_device::blank_update), this); // register for state saving save_item(NAME(m_ra)); @@ -735,58 +735,55 @@ void upd7220_device::device_reset() //------------------------------------------------- -// device_timer - handler timer events +// timer events //------------------------------------------------- -void upd7220_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(upd7220_device::hsync_update) { - switch (id) + if (param) { - case TIMER_HSYNC: - if (param) - { - m_sr |= UPD7220_SR_HBLANK_ACTIVE; - } - else - { - m_sr &= ~UPD7220_SR_HBLANK_ACTIVE; - } + m_sr |= UPD7220_SR_HBLANK_ACTIVE; + } + else + { + m_sr &= ~UPD7220_SR_HBLANK_ACTIVE; + } - m_write_hsync(param); + m_write_hsync(param); - update_hsync_timer(param); - break; + update_hsync_timer(param); +} - case TIMER_VSYNC: - if (param) - { - m_sr |= UPD7220_SR_VSYNC_ACTIVE; - } - else - { - m_sr &= ~UPD7220_SR_VSYNC_ACTIVE; - } +TIMER_CALLBACK_MEMBER(upd7220_device::vsync_update) +{ + if (param) + { + m_sr |= UPD7220_SR_VSYNC_ACTIVE; + } + else + { + m_sr &= ~UPD7220_SR_VSYNC_ACTIVE; + } - m_write_vsync(param); + m_write_vsync(param); - update_vsync_timer(param); - break; + update_vsync_timer(param); +} - case TIMER_BLANK: - if (param) - { - m_sr |= UPD7220_SR_HBLANK_ACTIVE; - } - else - { - m_sr &= ~UPD7220_SR_HBLANK_ACTIVE; - } +TIMER_CALLBACK_MEMBER(upd7220_device::blank_update) +{ + if (param) + { + m_sr |= UPD7220_SR_HBLANK_ACTIVE; + } + else + { + m_sr &= ~UPD7220_SR_HBLANK_ACTIVE; + } - m_write_blank(param); + m_write_blank(param); - update_blank_timer(param); - break; - } + update_blank_timer(param); } diff --git a/src/devices/video/upd7220.h b/src/devices/video/upd7220.h index 67c370aecb5..fa476bb3662 100644 --- a/src/devices/video/upd7220.h +++ b/src/devices/video/upd7220.h @@ -85,13 +85,17 @@ protected: // device-level overrides virtual void device_start() override; virtual void device_reset() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; virtual const tiny_rom_entry *device_rom_region() const override; virtual space_config_vector memory_space_config() const override; + TIMER_CALLBACK_MEMBER(hsync_update); + TIMER_CALLBACK_MEMBER(vsync_update); + TIMER_CALLBACK_MEMBER(blank_update); + void start_dma(); void stop_dma(); + private: enum { diff --git a/src/devices/video/v9938.cpp b/src/devices/video/v9938.cpp index 9aa2d4b0aa8..906e92353f7 100644 --- a/src/devices/video/v9938.cpp +++ b/src/devices/video/v9938.cpp @@ -172,11 +172,11 @@ void v99x8_device::device_config_complete() } -void v99x8_device::device_timer(emu_timer &timer, device_timer_id id, int param) +TIMER_CALLBACK_MEMBER(v99x8_device::update_line) { int scanline = (m_scanline - (m_scanline_start + m_offset_y)); - update_command (); + update_command(); // set flags if (m_scanline == (m_scanline_start + m_offset_y)) @@ -626,7 +626,7 @@ void v99x8_device::device_start() for (int addr = m_vram_size; addr < 0x30000; addr++) m_vram_space->write_byte(addr, 0xff); } - m_line_timer = timer_alloc(TIMER_LINE); + m_line_timer = timer_alloc(FUNC(v99x8_device::update_line), this); palette_init(); diff --git a/src/devices/video/v9938.h b/src/devices/video/v9938.h index 0e41ced86ab..b4ac02771da 100644 --- a/src/devices/video/v9938.h +++ b/src/devices/video/v9938.h @@ -88,7 +88,6 @@ protected: // construction/destruction v99x8_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock, int model); - static constexpr device_timer_id TIMER_LINE = 0; const address_space_config m_space_config; address_space* m_vram_space; @@ -100,7 +99,6 @@ protected: virtual void device_config_complete() override; virtual void device_start() override; virtual void device_reset() override; - virtual void device_timer(emu_timer &timer, device_timer_id id, int param) override; virtual void device_post_load() override; // device_memory_interface overrides @@ -109,6 +107,8 @@ protected: virtual void palette_init() = 0; virtual u32 palette_entries() const override { return 16 + 256; } + TIMER_CALLBACK_MEMBER(update_line); + void configure_pal_ntsc(); void set_screen_parameters(); diff --git a/src/devices/video/vic4567.cpp b/src/devices/video/vic4567.cpp index 99f2e5af476..5f1c756c50d 100644 --- a/src/devices/video/vic4567.cpp +++ b/src/devices/video/vic4567.cpp @@ -172,10 +172,8 @@ vic3_device::vic3_device(const machine_config &mconfig, const char *tag, device_ void vic3_device::device_start() { - int width, height; - - width = screen().width(); - height = screen().height(); + int width = screen().width(); + int height = screen().height(); m_bitmap = std::make_unique<bitmap_ind16>(width, height); @@ -1983,7 +1981,7 @@ void vic3_device::raster_interrupt_gen() if (LIGHTPEN_BUTTON) { /* lightpen timer start */ - machine().scheduler().timer_set(attotime(0, 0), timer_expired_delegate(FUNC(vic3_device::timer_timeout),this), 1); + machine().scheduler().synchronize(timer_expired_delegate(FUNC(vic3_device::timer_timeout), this), 1); } } diff --git a/src/devices/video/vic4567.h b/src/devices/video/vic4567.h index 64fedb3da16..8afe986c41c 100644 --- a/src/devices/video/vic4567.h +++ b/src/devices/video/vic4567.h @@ -191,7 +191,8 @@ private: uint16_t m_c64_bitmap[2], m_bitmapmulti[4], m_mono[2], m_multi[4], m_ecmcolor[2], m_colors[4], m_spritemulti[4]; - int m_lastline, m_rasterline; + int m_lastline; + int m_rasterline; int m_interlace; int m_columns, m_rows; diff --git a/src/devices/video/voodoo.cpp b/src/devices/video/voodoo.cpp index 23b44b4c90b..94c9a5ca7c7 100644 --- a/src/devices/video/voodoo.cpp +++ b/src/devices/video/voodoo.cpp @@ -924,8 +924,8 @@ void voodoo_1_device::device_start() m_stall_trigger = 51324 + index; // allocate timers for VBLANK - m_vsync_stop_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(voodoo_1_device::vblank_stop), this)); - m_vsync_start_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(voodoo_1_device::vblank_start),this)); + m_vsync_stop_timer = timer_alloc(FUNC(voodoo_1_device::vblank_stop), this); + m_vsync_start_timer = timer_alloc(FUNC(voodoo_1_device::vblank_start),this); // add TMUs to the chipmask if memory is specified (later chips leave // the tmumem values at 0 and set the chipmask directly to indicate @@ -1011,7 +1011,7 @@ void voodoo_1_device::device_start() // set up the PCI FIFO m_pci_fifo.configure(m_pci_fifo_mem, 64*2); m_stall_state = NOT_STALLED; - m_stall_resume_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(voodoo_1_device::stall_resume_callback), this)); + m_stall_resume_timer = timer_alloc(FUNC(voodoo_1_device::stall_resume_callback), this); // initialize registers m_init_enable = 0; diff --git a/src/devices/video/zeus2.cpp b/src/devices/video/zeus2.cpp index 2772c4d1c12..300b5ad2d0c 100644 --- a/src/devices/video/zeus2.cpp +++ b/src/devices/video/zeus2.cpp @@ -49,16 +49,13 @@ TIMER_CALLBACK_MEMBER(zeus2_device::display_irq_off) // vblank_period = screen().frame_period(); //vblank_timer->adjust(vblank_period); vblank_timer->adjust(screen().time_until_vblank_start()); - //machine().scheduler().timer_set(attotime::from_hz(30000000), timer_expired_delegate(FUNC(zeus2_device::display_irq), this)); } TIMER_CALLBACK_MEMBER(zeus2_device::display_irq) { m_vblank(ASSERT_LINE); /* set a timer for the next off state */ - //machine().scheduler().timer_set(screen().time_until_pos(0), timer_expired_delegate(FUNC(zeus2_device::display_irq_off), this)); - machine().scheduler().timer_set(screen().time_until_vblank_end(), timer_expired_delegate(FUNC(zeus2_device::display_irq_off), this)); - //machine().scheduler().timer_set(attotime::from_hz(30000000), timer_expired_delegate(FUNC(zeus2_device::display_irq_off), this)); + vblank_off_timer->adjust(screen().time_until_vblank_end()); } TIMER_CALLBACK_MEMBER(zeus2_device::int_timer_callback) @@ -88,9 +85,9 @@ void zeus2_device::device_start() /* we need to cleanup on exit */ //machine().add_notifier(MACHINE_NOTIFY_EXIT, machine_notify_delegate(&zeus2_device::exit_handler2, this)); - int_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(zeus2_device::int_timer_callback), this)); - - vblank_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(zeus2_device::display_irq), this)); + int_timer = timer_alloc(FUNC(zeus2_device::int_timer_callback), this); + vblank_timer = timer_alloc(FUNC(zeus2_device::display_irq), this); + vblank_off_timer = timer_alloc(FUNC(zeus2_device::display_irq_off), this); //printf("%s\n", machine().system().name); // Set system type diff --git a/src/devices/video/zeus2.h b/src/devices/video/zeus2.h index cdc38aa2227..459fff99799 100644 --- a/src/devices/video/zeus2.h +++ b/src/devices/video/zeus2.h @@ -147,6 +147,7 @@ public: emu_timer *int_timer; emu_timer *vblank_timer; + emu_timer *vblank_off_timer; int yoffs; int texel_width; float zbase; |