From ab7c7486d1ed7d589cd9761837f3880bbd68d4b9 Mon Sep 17 00:00:00 2001 From: hap Date: Mon, 4 Sep 2023 13:48:10 +0200 Subject: [PATCH] sensorboard: add callback for clear board --- src/devices/machine/sensorboard.cpp | 42 +++++++++++++++-------------- src/devices/machine/sensorboard.h | 22 ++++++++------- src/mame/chess/ave_arb.cpp | 4 ++- src/mame/fidelity/phantom.cpp | 8 +++++- src/mame/novag/robotadv.cpp | 15 ++++++++++- 5 files changed, 58 insertions(+), 33 deletions(-) diff --git a/src/devices/machine/sensorboard.cpp b/src/devices/machine/sensorboard.cpp index 56164a2d0ab..e3e3827f17b 100644 --- a/src/devices/machine/sensorboard.cpp +++ b/src/devices/machine/sensorboard.cpp @@ -76,10 +76,11 @@ sensorboard_device::sensorboard_device(const machine_config &mconfig, const char m_inp_spawn(*this, "SPAWN"), m_inp_ui(*this, "UI"), m_inp_conf(*this, "CONF"), - m_custom_init_cb(*this), - m_custom_sensor_cb(*this, 0), - m_custom_spawn_cb(*this, 0), - m_custom_output_cb(*this) + m_clear_cb(*this), + m_init_cb(*this), + m_sensor_cb(*this, 0), + m_spawn_cb(*this, 0), + m_output_cb(*this) { m_nvram_auto = false; m_nosensors = false; @@ -87,6 +88,7 @@ sensorboard_device::sensorboard_device(const machine_config &mconfig, const char m_inductive = false; m_ui_enabled = 7; set_delay(attotime::never); + clear_cb().set(*this, FUNC(sensorboard_device::clear_board)); // set defaults for most common use case (aka chess) set_size(8, 8); @@ -101,7 +103,7 @@ sensorboard_device::sensorboard_device(const machine_config &mconfig, const char void sensorboard_device::device_start() { - if (m_custom_output_cb.isunset()) + if (m_output_cb.isunset()) { m_out_piece.resolve(); m_out_pui.resolve(); @@ -190,8 +192,8 @@ void sensorboard_device::device_reset() if (!nvram_on()) { - clear_board(); - m_custom_init_cb(0); + m_clear_cb(0); + m_init_cb(0); } undo_reset(); refresh(); @@ -205,8 +207,8 @@ void sensorboard_device::device_reset() void sensorboard_device::nvram_default() { - clear_board(); - m_custom_init_cb(1); + m_clear_cb(0); + m_init_cb(0); } bool sensorboard_device::nvram_read(util::read_stream &file) @@ -316,20 +318,20 @@ void sensorboard_device::refresh() if (machine().phase() < machine_phase::RESET) return; - bool custom_out = !m_custom_output_cb.isunset(); + bool custom_out = !m_output_cb.isunset(); // output spawn icons for (int i = 0; i < m_maxspawn; i++) { if (custom_out) - m_custom_output_cb(i + 0x101, i + 1); + m_output_cb(i + 0x101, i + 1); else m_out_pui[i + 1] = i + 1; } // output hand piece if (custom_out) - m_custom_output_cb(0x100, m_hand); + m_output_cb(0x100, m_hand); else m_out_pui[0] = m_hand; @@ -345,7 +347,7 @@ void sensorboard_device::refresh() piece += m_maxid; if (custom_out) - m_custom_output_cb(pos, piece); + m_output_cb(pos, piece); else m_out_piece[x][y] = piece; } @@ -376,8 +378,8 @@ void sensorboard_device::refresh() if (custom_out) { - m_custom_output_cb(0x200, c0); - m_custom_output_cb(0x201, c1); + m_output_cb(0x200, c0); + m_output_cb(0x201, c1); } else { @@ -478,7 +480,7 @@ INPUT_CHANGED_MEMBER(sensorboard_device::sensor) // optional custom handling: // return d0 = block drop piece // return d1 = block pick up piece - u8 custom = m_custom_sensor_cb(pos); + u8 custom = m_sensor_cb(pos); // drop piece if (m_hand != 0) @@ -505,8 +507,8 @@ INPUT_CHANGED_MEMBER(sensorboard_device::ui_spawn) m_handpos = -1; // optional callback to change piece id - if (!m_custom_spawn_cb.isunset()) - m_hand = m_custom_spawn_cb(pos); + if (!m_spawn_cb.isunset()) + m_hand = m_spawn_cb(pos); refresh(); } @@ -600,10 +602,10 @@ INPUT_CHANGED_MEMBER(sensorboard_device::ui_init) cancel_sensor(); cancel_hand(); - clear_board(); + m_clear_cb(init ? 0 : 1); if (init) - m_custom_init_cb(0); + m_init_cb(1); // rotate pieces if (m_inp_ui->read() & 2) diff --git a/src/devices/machine/sensorboard.h b/src/devices/machine/sensorboard.h index b2d12e8a3d1..f8fb056e57b 100644 --- a/src/devices/machine/sensorboard.h +++ b/src/devices/machine/sensorboard.h @@ -34,12 +34,13 @@ public: sensorboard_device &set_ui_enable(bool b) { if (!b) m_maxspawn = 0; m_ui_enabled = (b) ? 7 : 0; return *this; } // enable UI inputs sensorboard_device &set_mod_enable(bool b) { if (b) m_ui_enabled |= 1; else m_ui_enabled &= ~1; return *this; } // enable modifier keys - auto init_cb() { return m_custom_init_cb.bind(); } // for setting pieces starting position - auto sensor_cb() { return m_custom_sensor_cb.bind(); } // x = offset & 0xf, y = offset >> 4 & 0xf - auto spawn_cb() { return m_custom_spawn_cb.bind(); } // spawnpoint/piece = offset, retval = new piece id - auto output_cb() { return m_custom_output_cb.bind(); } // pos = offset(A8 for ui/board, A9 for count), id = data + auto clear_cb() { return m_clear_cb.bind(); } // 0 = internal clear, 1 = user presses clear + auto init_cb() { return m_init_cb.bind(); } // for setting pieces starting position + auto sensor_cb() { return m_sensor_cb.bind(); } // x = offset & 0xf, y = offset >> 4 & 0xf + auto spawn_cb() { return m_spawn_cb.bind(); } // spawnpoint/piece = offset, retval = new piece id + auto output_cb() { return m_output_cb.bind(); } // pos = offset(A8 for ui/board, A9 for count), id = data - void preset_chess(int state); // init_cb() preset for chessboards + void preset_chess(int state = 0); // init_cb() preset for chessboards // read sensors u8 read_sensor(u8 x, u8 y); @@ -51,7 +52,7 @@ public: // handle board state u8 read_piece(u8 x, u8 y) { return m_curstate[y * m_width + x]; } void write_piece(u8 x, u8 y, u8 id) { m_curstate[y * m_width + x] = id; } - void clear_board() { memset(m_curstate, 0, sizeof(m_curstate)); } + void clear_board(int state = 0) { memset(m_curstate, 0, sizeof(m_curstate)); } // default clear_cb() void refresh(); void cancel_sensor(); @@ -99,10 +100,11 @@ private: required_ioport m_inp_ui; required_ioport m_inp_conf; - devcb_write_line m_custom_init_cb; - devcb_read8 m_custom_sensor_cb; - devcb_read8 m_custom_spawn_cb; - devcb_write16 m_custom_output_cb; + devcb_write_line m_clear_cb; + devcb_write_line m_init_cb; + devcb_read8 m_sensor_cb; + devcb_read8 m_spawn_cb; + devcb_write16 m_output_cb; bool m_nosensors; bool m_magnets; diff --git a/src/mame/chess/ave_arb.cpp b/src/mame/chess/ave_arb.cpp index c2db3231071..241aaf16c79 100644 --- a/src/mame/chess/ave_arb.cpp +++ b/src/mame/chess/ave_arb.cpp @@ -150,13 +150,15 @@ void arb_state::init_board(int state) { // different board setup for checkers if (m_altboard) + { for (int i = 0; i < 12; i++) { m_board->write_piece((i % 4) * 2 + ((i / 4) & 1), i / 4, 13); // white m_board->write_piece((i % 4) * 2 + (~(i / 4) & 1), i / 4 + 5, 14); // black } + } else - m_board->preset_chess(state); + m_board->preset_chess(); } diff --git a/src/mame/fidelity/phantom.cpp b/src/mame/fidelity/phantom.cpp index d9038c65c0a..387307ed94b 100644 --- a/src/mame/fidelity/phantom.cpp +++ b/src/mame/fidelity/phantom.cpp @@ -112,6 +112,7 @@ protected: u8 hmotor_ff_clear_r(); u8 vmotor_ff_clear_r(); + void clear_board(int state); void check_rotation(); TIMER_DEVICE_CALLBACK_MEMBER(motors_timer); void update_pieces_position(int state); @@ -158,10 +159,14 @@ void phantom_state::machine_start() void phantom_state::machine_reset() { m_rombank->set_entry(0); + output_magnet_pos(); +} +void phantom_state::clear_board(int state) +{ memset(m_pieces_map, 0, sizeof(m_pieces_map)); m_piece_hand = 0; - output_magnet_pos(); + m_board->clear_board(); } void phantom_state::init_phantom() @@ -591,6 +596,7 @@ void phantom_state::phantom(machine_config &config) SENSORBOARD(config, m_board).set_type(sensorboard_device::BUTTONS); m_board->set_size(8+4, 8); + m_board->clear_cb().set(FUNC(phantom_state::clear_board)); m_board->init_cb().set(m_board, FUNC(sensorboard_device::preset_chess)); m_board->set_delay(attotime::from_msec(100)); diff --git a/src/mame/novag/robotadv.cpp b/src/mame/novag/robotadv.cpp index 9e118c6bdfb..a70671698c8 100644 --- a/src/mame/novag/robotadv.cpp +++ b/src/mame/novag/robotadv.cpp @@ -94,6 +94,7 @@ private: u8 counters_r(); TIMER_DEVICE_CALLBACK_MEMBER(refresh_timer) { refresh(); } + void clear_board(int state); void refresh(); void update_counters(); void update_limits(); @@ -111,6 +112,12 @@ private: attotime m_pwm_last; }; + + +/******************************************************************************* + Initialization +*******************************************************************************/ + void robotadv_state::machine_start() { // resolve outputs @@ -132,10 +139,15 @@ void robotadv_state::machine_start() void robotadv_state::machine_reset() { - m_piece_hand = 0; refresh(); } +void robotadv_state::clear_board(int state) +{ + m_piece_hand = 0; + m_board->clear_board(); +} + /******************************************************************************* @@ -502,6 +514,7 @@ void robotadv_state::robotadv(machine_config &config) SENSORBOARD(config, m_board).set_type(sensorboard_device::MAGNETS); m_board->set_size(8+4, 8); + m_board->clear_cb().set(FUNC(robotadv_state::clear_board)); m_board->init_cb().set(m_board, FUNC(sensorboard_device::preset_chess)); m_board->set_delay(attotime::from_msec(150)); m_board->set_nvram_enable(true);