diff options
| author | 2026-04-18 16:54:42 +0200 | |
|---|---|---|
| committer | 2026-04-18 16:54:54 +0200 | |
| commit | 4366ce1fa1713d1cd0e5bf285ecb4122b6680fb4 (patch) | |
| tree | dd2e4e1f434420b72d7041f725c2f5c21328dacb /src/devices/machine/gmboard.cpp | |
| parent | 041f509424b67954baa3dff1fe963a4b3a6191fc (diff) | |
gmboard: improve hall effect sensor
Diffstat (limited to 'src/devices/machine/gmboard.cpp')
| -rw-r--r-- | src/devices/machine/gmboard.cpp | 78 |
1 files changed, 54 insertions, 24 deletions
diff --git a/src/devices/machine/gmboard.cpp b/src/devices/machine/gmboard.cpp index 9a988dbdc7f..ac8e033e9c9 100644 --- a/src/devices/machine/gmboard.cpp +++ b/src/devices/machine/gmboard.cpp @@ -197,35 +197,35 @@ void gmboard_device::realign_magnet_pos() } } -void gmboard_device::magnet_w(int state) +int gmboard_device::check_board(bool magnet, bool sensor) { - state = state ? 1 : 0; - - if (state == m_magnet) - return; - m_magnet = state; - - if (m_piece_hand) - realign_magnet_pos(); - output_magnet_pos(); + int piece_hand = m_piece_hand; double dx, dy; get_scaled_pos(&dx, &dy); int mx = dx + 0.5; int my = dy + 0.5; + + // assume that sensor is 1 step above magnet + if (sensor && my > 0) + my--; + int gx = mx, gy = my; // convert motors position into board coordinates int x = mx / 4 - 2; - int y = 7 - (my / 4); + int y = m_board->height() - 1 - (my / 4); if (x < 0) - x += 12; + x += m_board->width(); + + x = std::clamp(x, 0, m_board->width() - 1); + y = std::clamp(y, 0, m_board->height() - 1); const bool valid_pos = (mx & 3) == 2 && (my & 3) == 2; - if (state) + if (magnet || sensor) { if (valid_pos) { @@ -233,9 +233,9 @@ void gmboard_device::magnet_w(int state) const int pos = (y << 4 & 0xf0) | (x & 0x0f); if (pos != m_board->get_handpos()) { - m_piece_hand = m_board->read_piece(x, y); + piece_hand = m_board->read_piece(x, y); - if (m_piece_hand) + if (piece_hand && !sensor) { m_board->write_piece(x, y, 0); m_board->refresh(); @@ -243,7 +243,7 @@ void gmboard_device::magnet_w(int state) } } - if (!m_piece_hand) + if (!piece_hand) { int count = 0; @@ -253,8 +253,9 @@ void gmboard_device::magnet_w(int state) if (sy >= 0 && sx >= 0 && m_pieces_map[sy][sx] != 0) { gx = sx; gy = sy; - m_piece_hand = m_pieces_map[sy][sx]; - m_pieces_map[sy][sx] = 0; + piece_hand = m_pieces_map[sy][sx]; + if (!sensor) + m_pieces_map[sy][sx] = 0; count++; } @@ -262,14 +263,17 @@ void gmboard_device::magnet_w(int state) if (count > 1) popmessage("Internal collision!"); } + + if (sensor) + return piece_hand; } - if (m_piece_hand) + if (piece_hand) { - LOGMASKED(LOG_MAGNET, "%s piece %2d @ %2d,%2d (%2d,%2d)\n", state ? "grab" : "drop", m_piece_hand, x, y, gx, gy); + LOGMASKED(LOG_MAGNET, "%s piece %2d @ %2d,%2d (%2d,%2d)\n", magnet ? "grab" : "drop", piece_hand, x, y, gx, gy); // drop piece - if (!state) + if (!magnet) { if (valid_pos) { @@ -278,7 +282,7 @@ void gmboard_device::magnet_w(int state) popmessage("Collision at %c%d!", x + 'A', y + 1); else { - m_board->write_piece(x, y, m_piece_hand); + m_board->write_piece(x, y, piece_hand); m_board->refresh(); } } @@ -288,12 +292,38 @@ void gmboard_device::magnet_w(int state) if (m_pieces_map[my][mx] != 0) popmessage("Internal collision!"); else - m_pieces_map[my][mx] = m_piece_hand; + m_pieces_map[my][mx] = piece_hand; } - m_piece_hand = 0; + piece_hand = 0; } } + + m_piece_hand = piece_hand; + return piece_hand; +} + +void gmboard_device::magnet_w(int state) +{ + state = state ? 1 : 0; + + if (state == m_magnet) + return; + m_magnet = state; + + if (m_piece_hand) + realign_magnet_pos(); + output_magnet_pos(); + + check_board(state, false); +} + +int gmboard_device::magnet_r() +{ + if (m_piece_hand) + return 1; + + return check_board(true, true) ? 1 : 0; } TIMER_CALLBACK_MEMBER(gmboard_device::motor_count) |
