From 1f0b6e76d8e7fde4ecfc0d9be940326e7127496b Mon Sep 17 00:00:00 2001 From: Vas Crabb Date: Mon, 15 Apr 2024 01:22:39 +1000 Subject: -ui/menu.cpp, ui/selmenu.cpp: Handle mouse wheel units properly. -Fixed a few more class memory access warnings. --- src/devices/bus/qbus/dvk_mx.cpp | 36 ++++++++++++++++--- src/devices/bus/qbus/dvk_mx.h | 4 +++ src/devices/machine/1801vp128.cpp | 36 ++++++++++++++++--- src/devices/machine/1801vp128.h | 4 +++ src/devices/machine/fdc_pll.h | 4 +-- src/devices/machine/iopdma.cpp | 6 ++-- src/frontend/mame/ui/menu.cpp | 40 +++++++++++++++------ src/frontend/mame/ui/menu.h | 2 ++ src/frontend/mame/ui/selmenu.cpp | 73 +++++++++++++++++++++++++++++++-------- src/frontend/mame/ui/selmenu.h | 2 ++ src/mame/fujitsu/fmtowns.cpp | 4 +-- src/mame/pc/mc1502.cpp | 3 +- src/mame/pc/poisk1.cpp | 2 +- src/mame/rm/rmnimbus_m.cpp | 2 +- 14 files changed, 177 insertions(+), 41 deletions(-) diff --git a/src/devices/bus/qbus/dvk_mx.cpp b/src/devices/bus/qbus/dvk_mx.cpp index fb95431e270..757262481ec 100644 --- a/src/devices/bus/qbus/dvk_mx.cpp +++ b/src/devices/bus/qbus/dvk_mx.cpp @@ -53,6 +53,38 @@ DEFINE_DEVICE_TYPE(DVK_MX, dvk_mx_device, "dvk_mx", "DVK MX floppy controller") + +inline dvk_mx_device::floppy_info::floppy_info() + : tm(nullptr) + , dev(nullptr) + , id(0) + , main_state(0) + , sub_state(0) + , dir(0) + , counter(0) + , live(false) + , index(false) +{ +} + + +inline dvk_mx_device::live_info::live_info() + : tm(attotime::never) + , state(IDLE) + , next_state(-1) + , fi(nullptr) + , shift_reg(0) + , bit_counter(0) + , byte_counter(0) + , data_separator_phase(false) + , data_reg(0) + , cksum(0) + , pll() +{ +} + + + //************************************************************************** // LIVE DEVICE //************************************************************************** @@ -66,10 +98,6 @@ dvk_mx_device::dvk_mx_device(const machine_config &mconfig, const char *tag, dev , device_qbus_card_interface(mconfig, *this) , m_connectors(*this, "%u", 0U) { - memset(&cur_live, 0x00, sizeof(cur_live)); - cur_live.tm = attotime::never; - cur_live.state = IDLE; - cur_live.next_state = -1; } diff --git a/src/devices/bus/qbus/dvk_mx.h b/src/devices/bus/qbus/dvk_mx.h index 6dc8482398e..f65b4ec1b27 100644 --- a/src/devices/bus/qbus/dvk_mx.h +++ b/src/devices/bus/qbus/dvk_mx.h @@ -101,6 +101,8 @@ private: }; struct floppy_info { + floppy_info(); + emu_timer *tm; floppy_image_device *dev; int id; @@ -110,6 +112,8 @@ private: }; struct live_info { + live_info(); + attotime tm; int state, next_state; floppy_info *fi; diff --git a/src/devices/machine/1801vp128.cpp b/src/devices/machine/1801vp128.cpp index 58d399dbd2d..2c1f089f557 100644 --- a/src/devices/machine/1801vp128.cpp +++ b/src/devices/machine/1801vp128.cpp @@ -49,6 +49,38 @@ DEFINE_DEVICE_TYPE(K1801VP128, k1801vp128_device, "1801vp1-128", "1801VP1-128") +inline k1801vp128_device::floppy_info::floppy_info() + : tm(nullptr) + , dev(nullptr) + , id(0) + , main_state(0) + , sub_state(0) + , dir(0) + , counter(0) + , live(false) + , index(false) +{ +} + + +inline k1801vp128_device::live_info::live_info() + : tm(attotime::never) + , state(IDLE) + , next_state(-1) + , fi(nullptr) + , shift_reg(0) + , crc(0) + , bit_counter(0) + , data_separator_phase(false) + , data_bit_context(false) + , crc_init(false) + , data_reg(0) + , pll() +{ +} + + + //************************************************************************** // LIVE DEVICE //************************************************************************** @@ -62,10 +94,6 @@ k1801vp128_device::k1801vp128_device(const machine_config &mconfig, const char * , m_connectors(*this, "%u", 0U) , m_read_ds(*this, -1) { - memset(&cur_live, 0x00, sizeof(cur_live)); - cur_live.tm = attotime::never; - cur_live.state = IDLE; - cur_live.next_state = -1; } diff --git a/src/devices/machine/1801vp128.h b/src/devices/machine/1801vp128.h index 339ddcbd423..4a83f58b018 100644 --- a/src/devices/machine/1801vp128.h +++ b/src/devices/machine/1801vp128.h @@ -139,6 +139,8 @@ private: struct floppy_info { + floppy_info(); + emu_timer *tm; floppy_image_device *dev; int id; @@ -149,6 +151,8 @@ private: struct live_info { + live_info(); + attotime tm; int state, next_state; floppy_info *fi; diff --git a/src/devices/machine/fdc_pll.h b/src/devices/machine/fdc_pll.h index e232260162c..c048f5d2618 100644 --- a/src/devices/machine/fdc_pll.h +++ b/src/devices/machine/fdc_pll.h @@ -17,8 +17,8 @@ public: attotime write_start_time; attotime write_buffer[32]; - int write_position; - int freq_hist; + int write_position = 0; + int freq_hist = 0; void set_clock(const attotime &period); void reset(const attotime &when); diff --git a/src/devices/machine/iopdma.cpp b/src/devices/machine/iopdma.cpp index 784bc16b515..8ca904d1747 100644 --- a/src/devices/machine/iopdma.cpp +++ b/src/devices/machine/iopdma.cpp @@ -14,6 +14,8 @@ #include "cpu/mips/ps2vu.h" +#include + DEFINE_DEVICE_TYPE(SONYIOP_DMA, iop_dma_device, "iopdma", "PlayStation 2 IOP DMAC") @@ -72,8 +74,8 @@ void iop_dma_device::device_start() void iop_dma_device::device_reset() { - memset(m_channels, 0, sizeof(channel_t) * 16); - memset(m_int_ctrl, 0, sizeof(intctrl_t) * 2); + std::fill(std::begin(m_channels), std::end(m_channels), channel_t()); + std::fill(std::begin(m_int_ctrl), std::end(m_int_ctrl), intctrl_t{ 0, 0, false }); m_dpcr[0] = 0; m_dpcr[1] = 0; m_dicr[0] = 0; diff --git a/src/frontend/mame/ui/menu.cpp b/src/frontend/mame/ui/menu.cpp index a5c82aa90c2..00710e073a9 100644 --- a/src/frontend/mame/ui/menu.cpp +++ b/src/frontend/mame/ui/menu.cpp @@ -227,10 +227,7 @@ uint32_t menu::global_state::ui_handler(render_container &container) // ensure topmost menu is active - need a loop because it could push another menu while (m_stack && !m_stack->is_active()) { - m_stack->m_items_drawn = false; - m_stack->m_pointer_state = track_pointer::IDLE; - m_stack->m_active = true; - m_stack->menu_activated(); + m_stack->activate_menu(); if (m_stack && m_stack->is_active()) { // menu activated - draw it to ensure it's on-screen before it can process input @@ -414,6 +411,7 @@ menu::menu(mame_ui_manager &mui, render_container &container) , m_pointer_updated(0.0F, 0.0F) , m_pointer_line(0) , m_pointer_repeat(std::chrono::steady_clock::time_point::min()) + , m_accumulated_wheel(0) , m_process_flags(0) , m_selected(0) , m_special_main_menu(false) @@ -1044,9 +1042,16 @@ bool menu::handle_events(uint32_t flags, event &ev) case ui_event::type::MOUSE_WHEEL: if ((track_pointer::IDLE == m_pointer_state) || (track_pointer::IGNORED == m_pointer_state)) { - if (!custom_mouse_scroll((0 < local_menu_event.zdelta) ? -local_menu_event.num_lines : local_menu_event.num_lines) && !(flags & (PROCESS_ONLYCHAR | PROCESS_CUSTOM_NAV))) + // the value is scaled to 120 units per "click" + m_accumulated_wheel += local_menu_event.zdelta * local_menu_event.num_lines; + int const lines((m_accumulated_wheel + ((0 < local_menu_event.zdelta) ? 36 : -36)) / 120); + if (!lines) + break; + m_accumulated_wheel -= lines * 120; + + if (!custom_mouse_scroll(-lines) && !(flags & (PROCESS_ONLYCHAR | PROCESS_CUSTOM_NAV))) { - if (local_menu_event.zdelta > 0) + if (lines > 0) { if (is_first_selected()) { @@ -1054,12 +1059,12 @@ bool menu::handle_events(uint32_t flags, event &ev) } else { - m_selected -= local_menu_event.num_lines; + m_selected -= lines; validate_selection(-1); } top_line -= (m_selected <= top_line && top_line != 0); if (m_selected <= top_line && m_visible_items != m_visible_lines) - top_line -= local_menu_event.num_lines; + top_line -= lines; } else { @@ -1069,12 +1074,12 @@ bool menu::handle_events(uint32_t flags, event &ev) } else { - m_selected += local_menu_event.num_lines; + m_selected -= lines; validate_selection(1); } top_line += (m_selected >= top_line + m_visible_items + (top_line != 0)); if (m_selected >= (top_line + m_visible_items + (top_line != 0))) - top_line += local_menu_event.num_lines; + top_line -= lines; } } } @@ -1899,6 +1904,21 @@ void menu::validate_selection(int scandir) } +//------------------------------------------------- +// activate_menu - handle becoming top of the +// menu stack +//------------------------------------------------- + +void menu::activate_menu() +{ + m_items_drawn = false; + m_pointer_state = track_pointer::IDLE; + m_accumulated_wheel = 0; + m_active = true; + menu_activated(); +} + + //------------------------------------------------- // check_metrics - recompute metrics if target // geometry has changed diff --git a/src/frontend/mame/ui/menu.h b/src/frontend/mame/ui/menu.h index 791432482b5..14031fb2c08 100644 --- a/src/frontend/mame/ui/menu.h +++ b/src/frontend/mame/ui/menu.h @@ -511,6 +511,7 @@ private: void extra_text_draw_box(float origx1, float origx2, float origy, float yspan, std::string_view text, int direction); + void activate_menu(); bool check_metrics(); bool do_rebuild(); bool first_item_visible() const { return top_line <= 0; } @@ -562,6 +563,7 @@ private: std::pair m_pointer_updated; // location where pointer tracking was updated int m_pointer_line; // the line we're tracking pointer motion in std::chrono::steady_clock::time_point m_pointer_repeat; + int m_accumulated_wheel; // accumulated scroll wheel/gesture movement uint32_t m_process_flags; // event processing options int m_selected; // which item is selected diff --git a/src/frontend/mame/ui/selmenu.cpp b/src/frontend/mame/ui/selmenu.cpp index a5645e79ca8..5655c226d3f 100644 --- a/src/frontend/mame/ui/selmenu.cpp +++ b/src/frontend/mame/ui/selmenu.cpp @@ -533,6 +533,8 @@ menu_select_launch::menu_select_launch(mame_ui_manager &mui, render_container &c , m_base_pointer(0.0F, 0.0F) , m_last_pointer(0.0F, 0.0F) , m_clicked_line(0) + , m_wheel_target(focused_menu::MAIN) + , m_wheel_movement(0) , m_primary_vbounds(0.0F, -1.0F) , m_primary_items_top(-1.0F) , m_primary_items_hbounds(0.0F, -1.0F) @@ -938,6 +940,8 @@ void menu_select_launch::custom_render(u32 flags, void *selectedref, float top, void menu_select_launch::menu_activated() { m_panels_status = ui().options().hide_panels(); + m_wheel_target = focused_menu::MAIN; + m_wheel_movement = 0; } @@ -1645,22 +1649,57 @@ bool menu_select_launch::handle_events(u32 flags, event &ev) case ui_event::type::MOUSE_WHEEL: if ((&machine().render().ui_target() == local_menu_event.target) && pointer_idle() && !m_ui_error) { + // check whether it's over something scrollable float x, y; bool const hit(local_menu_event.target->map_point_container(local_menu_event.mouse_x, local_menu_event.mouse_y, container(), x, y)); if (!hit) + { + m_wheel_movement = 0; break; - + } + focused_menu hover; if ((x >= m_primary_items_hbounds.first) && (x < m_primary_items_hbounds.second) && (y >= m_primary_items_top) && (y < (m_primary_items_top + (float(m_primary_lines) * line_height())))) { - if (local_menu_event.zdelta > 0) + hover = focused_menu::MAIN; + } + else if (show_left_panel() && (x >= m_left_items_hbounds.first) && (x < m_left_items_hbounds.second) && (y >= m_left_items_top) && (y < (m_left_items_top + (float(m_left_visible_lines) * m_info_line_height)))) + { + hover = focused_menu::LEFT; + } + else if (show_right_panel() && (x >= m_right_content_hbounds.first) && (x < m_right_content_hbounds.second) && (y >= m_right_content_vbounds.first) && (y < m_right_content_vbounds.second)) + { + hover = focused_menu::RIGHTBOTTOM; + } + else + { + m_wheel_movement = 0; + break; + } + + // clear out leftovers if it isn't the last thing to be scrolled + if (hover != m_wheel_target) + m_wheel_movement = 0; + m_wheel_target = hover; + + // the value is scaled to 120 units per "click" + m_wheel_movement += local_menu_event.zdelta * local_menu_event.num_lines; + int const lines((m_wheel_movement + ((0 < local_menu_event.zdelta) ? 36 : -36)) / 120); + if (!lines) + break; + m_wheel_movement -= lines * 120; + + switch (hover) + { + case focused_menu::MAIN: + if (lines > 0) { if ((selected_index() >= m_available_items) || is_first_selected()) break; stop = true; ev.iptkey = IPT_CUSTOM; // stop processing events so info can be rebuilt - set_selected_index(selected_index() - local_menu_event.num_lines); + set_selected_index(selected_index() - lines); if (selected_index() < top_line + (top_line != 0)) - top_line -= local_menu_event.num_lines; + top_line -= lines; } else { @@ -1668,20 +1707,26 @@ bool menu_select_launch::handle_events(u32 flags, event &ev) break; stop = true; ev.iptkey = IPT_CUSTOM; // stop processing events so info can be rebuilt - set_selected_index(std::min(selected_index() + local_menu_event.num_lines, m_available_items - 1)); + set_selected_index(std::min(selected_index() - lines, m_available_items - 1)); if (selected_index() >= top_line + m_visible_items + (top_line != 0)) - top_line += local_menu_event.num_lines; + top_line -= lines; } - } - else if ((x >= m_right_content_hbounds.first) && (x < m_right_content_hbounds.second) && (y >= m_right_content_vbounds.first) && (y < m_right_content_vbounds.second)) - { - if (show_right_panel() && (RP_INFOS == m_right_panel)) + break; + case focused_menu::LEFT: { - if (local_menu_event.zdelta > 0) - m_topline_datsview -= local_menu_event.num_lines; - else - m_topline_datsview += local_menu_event.num_lines; + m_left_visible_top = std::clamp(m_left_visible_top - lines, 0, m_left_item_count - m_left_visible_lines); + int const first(left_at_top() ? 0 : (m_left_visible_top + 1)); + int const last(m_left_visible_top + m_left_visible_lines - (left_at_bottom() ? 1 : 2)); + m_filter_highlight = std::clamp(m_filter_highlight, first, last); + m_filter_highlight = std::clamp(m_filter_highlight - lines, 0, m_left_item_count - 1); } + break; + case focused_menu::RIGHTBOTTOM: + if (RP_INFOS == m_right_panel) + m_topline_datsview -= lines; + break; + case focused_menu::RIGHTTOP: + break; // never gets here } } break; diff --git a/src/frontend/mame/ui/selmenu.h b/src/frontend/mame/ui/selmenu.h index b6793994a1f..d03bae9de8f 100644 --- a/src/frontend/mame/ui/selmenu.h +++ b/src/frontend/mame/ui/selmenu.h @@ -435,6 +435,8 @@ private: std::pair m_base_pointer; std::pair m_last_pointer; int m_clicked_line; + focused_menu m_wheel_target; + int m_wheel_movement; std::pair m_primary_vbounds; float m_primary_items_top; diff --git a/src/mame/fujitsu/fmtowns.cpp b/src/mame/fujitsu/fmtowns.cpp index c16ce16cf3b..6208cc12c42 100644 --- a/src/mame/fujitsu/fmtowns.cpp +++ b/src/mame/fujitsu/fmtowns.cpp @@ -2357,8 +2357,8 @@ void towns_state::driver_start() m_towns_status_timer = timer_alloc(FUNC(towns_state::towns_cd_status_ready), this); m_towns_cdda_timer = timer_alloc(FUNC(towns_state::towns_delay_cdda), this); - memset(&m_video,0,sizeof(struct towns_video_controller)); - memset(&m_towns_cd,0,sizeof(struct towns_cdrom_controller)); + m_video = towns_video_controller(); + m_towns_cd = towns_cdrom_controller(); m_towns_cd.status = 0x01; // CDROM controller ready m_towns_cd.buffer_ptr = -1; m_towns_cd.read_timer = timer_alloc(FUNC(towns_state::towns_cdrom_read_byte), this); diff --git a/src/mame/pc/mc1502.cpp b/src/mame/pc/mc1502.cpp index dd47022b30b..234f9e67984 100644 --- a/src/mame/pc/mc1502.cpp +++ b/src/mame/pc/mc1502.cpp @@ -274,7 +274,8 @@ void mc1502_state::machine_start() Last pulse causes BIOS to write a 'break' scancode into port 60h. */ m_pic8259->ir1_w(1); - memset(&m_kbd, 0, sizeof(m_kbd)); + m_kbd.pulsing = 0; + m_kbd.mask = 0; m_kbd.keyb_signal_timer = timer_alloc(FUNC(mc1502_state::keyb_signal_callback), this); m_kbd.keyb_signal_timer->adjust(attotime::from_msec(20), 0, attotime::from_msec(20)); } diff --git a/src/mame/pc/poisk1.cpp b/src/mame/pc/poisk1.cpp index 6094d0e8538..b2065bbda07 100644 --- a/src/mame/pc/poisk1.cpp +++ b/src/mame/pc/poisk1.cpp @@ -429,7 +429,7 @@ void p1_state::video_start() { address_space &space = m_maincpu->space(AS_PROGRAM); - memset(&m_video, 0, sizeof(m_video)); + m_video = decltype(m_video)(); m_video.videoram_base = std::make_unique(0x8000); m_video.videoram = m_video.videoram_base.get(); m_video.stride = 80; diff --git a/src/mame/rm/rmnimbus_m.cpp b/src/mame/rm/rmnimbus_m.cpp index 2a17d32882f..fedc14e6ee4 100644 --- a/src/mame/rm/rmnimbus_m.cpp +++ b/src/mame/rm/rmnimbus_m.cpp @@ -696,7 +696,7 @@ void rmnimbus_state::pc8031_reset() { logerror("peripheral controller reset\n"); - memset(&m_ipc_interface,0,sizeof(m_ipc_interface)); + m_ipc_interface = decltype(m_ipc_interface)(); } -- cgit v1.2.3