From 7f830cdcebaed884489345579f54e7fef7995e9b Mon Sep 17 00:00:00 2001 From: Ry Date: Sat, 16 Apr 2022 15:15:03 -0700 Subject: [PATCH] fox32+fox32rom: Add EVENT_TYPE_MOUSE_RELEASE --- fox32rom.def | 7 ++++--- main.asm | 4 ++++ menu.asm | 2 +- mouse.asm | 39 +++++++++++++++++++++++++++++++++------ 4 files changed, 42 insertions(+), 10 deletions(-) diff --git a/fox32rom.def b/fox32rom.def index 350952b..f982669 100644 --- a/fox32rom.def +++ b/fox32rom.def @@ -60,7 +60,8 @@ compare_memory_words: jmp [0xF004600C] ; event types const EVENT_TYPE_MOUSE_CLICK: 0x00000000 -const EVENT_TYPE_MENU_BAR_CLICK: 0x00000001 -const EVENT_TYPE_MENU_UPDATE: 0x00000002 -const EVENT_TYPE_MENU_CLICK: 0x00000003 +const EVENT_TYPE_MOUSE_RELEASE: 0x00000001 +const EVENT_TYPE_MENU_BAR_CLICK: 0x00000002 +const EVENT_TYPE_MENU_UPDATE: 0x00000003 +const EVENT_TYPE_MENU_CLICK: 0x00000004 const EVENT_TYPE_EMPTY: 0xFFFFFFFF diff --git a/main.asm b/main.asm index ef4b5ef..7651b99 100644 --- a/main.asm +++ b/main.asm @@ -77,6 +77,10 @@ event_loop: cmp r0, EVENT_TYPE_MOUSE_CLICK ;ifz call mouse_click_event + ; was the mouse released? + cmp r0, EVENT_TYPE_MOUSE_RELEASE + ;ifz call mouse_release_event + ; did the user click the menu bar? cmp r0, EVENT_TYPE_MENU_BAR_CLICK ifz mov r0, menu_items_root diff --git a/menu.asm b/menu.asm index 1d4380d..b68a4b8 100644 --- a/menu.asm +++ b/menu.asm @@ -229,7 +229,7 @@ menu_update_event_no_redraw: ; check the mouse held bit ; this is kinda hacky but it works call get_mouse_button - bts r0, 1 + bts r0, 2 ifnz jmp menu_update_event_clicked jmp menu_update_event_end_add diff --git a/mouse.asm b/mouse.asm index 5e75fd6..4e4a6c8 100644 --- a/mouse.asm +++ b/mouse.asm @@ -49,8 +49,19 @@ mouse_update: in r3, r2 ; check click bit + push r2 + push r3 bts r3, 0 - ifz jmp mouse_update_end + ifnz call mouse_update_clicked + pop r3 + pop r2 + + ; check release bit + bts r3, 1 + ifnz call mouse_update_released + + jmp mouse_update_end +mouse_update_clicked: ; mouse was clicked, clear the click bit bcl r3, 0 out r2, r3 @@ -65,16 +76,16 @@ mouse_update: ; first check if the menu bar is enabled in r3, 0x8000031E ; overlay 30: enable status cmp r3, 0 - ifz jmp mouse_update_no_menu + ifz jmp mouse_update_clicked_no_menu cmp r1, 17 ifc jmp mouse_update_menu_was_clicked -mouse_update_no_menu: +mouse_update_clicked_no_menu: ; if a menu is open, don't push a click event ; this is hacky as fuck in r3, 0x8000031D ; overlay 29: enable status cmp r3, 0 - ifnz jmp mouse_update_end + ifnz ret ; otherwise, just add a standard mouse click event to the event queue mov r2, r1 ; copy Y position to event parameter 1 @@ -84,9 +95,24 @@ mouse_update_no_menu: mov r5, 0 mov r6, 0 mov r7, 0 - mov r0, EVENT_TYPE_MOUSE_CLICK ; set event type to mouse type + mov r0, EVENT_TYPE_MOUSE_CLICK ; set event type to mouse click call new_event - jmp mouse_update_end + ret +mouse_update_released: + ; mouse was released, clear the release bit + bcl r3, 1 + out r2, r3 + + mov r2, r1 ; copy Y position to event parameter 1 + mov r1, r0 ; copy X position to event parameter 0 + mov r3, 0 + mov r4, 0 + mov r5, 0 + mov r6, 0 + mov r7, 0 + mov r0, EVENT_TYPE_MOUSE_RELEASE ; set event type to mouse release + call new_event + ret mouse_update_menu_was_clicked: mov r2, r1 ; copy Y position to event parameter 1 mov r1, r0 ; copy X position to event parameter 0 @@ -97,6 +123,7 @@ mouse_update_menu_was_clicked: mov r7, 0 mov r0, EVENT_TYPE_MENU_BAR_CLICK ; set event type to menu bar click type call new_event + ret mouse_update_end: pop r7 pop r6