diff options
author | 2022-06-04 09:14:21 +0200 | |
---|---|---|
committer | 2022-06-04 17:14:21 +1000 | |
commit | 1bc5484698bb746c6f9f7dae58b005d2472f1215 (patch) | |
tree | 54d6a10bc728cc7ce9858d771788a595e324141c /src/devices/bus/sms_ctrl/lphaser.cpp | |
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/bus/sms_ctrl/lphaser.cpp')
-rw-r--r-- | src/devices/bus/sms_ctrl/lphaser.cpp | 80 |
1 files changed, 33 insertions, 47 deletions
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()); - } -} |