sensorboard: add callback for clear board

This commit is contained in:
hap 2023-09-04 13:48:10 +02:00
parent 7b93d2021a
commit ab7c7486d1
5 changed files with 58 additions and 33 deletions

View File

@ -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)

View File

@ -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;

View File

@ -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();
}

View File

@ -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));

View File

@ -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);