fox32rom: Add EVENT_TYPE_KEY_DOWN and EVENT_TYPE_KEY_UP

This commit is contained in:
Ry 2022-04-17 16:21:56 -07:00
parent b908d98bb6
commit 06be1034f9
6 changed files with 67 additions and 23 deletions

View File

@ -3,9 +3,11 @@
; event types ; event types
const EVENT_TYPE_MOUSE_CLICK: 0x00000000 const EVENT_TYPE_MOUSE_CLICK: 0x00000000
const EVENT_TYPE_MOUSE_RELEASE: 0x00000001 const EVENT_TYPE_MOUSE_RELEASE: 0x00000001
const EVENT_TYPE_MENU_BAR_CLICK: 0x00000002 const EVENT_TYPE_KEY_DOWN: 0x00000002
const EVENT_TYPE_MENU_UPDATE: 0x00000003 const EVENT_TYPE_KEY_UP: 0x00000003
const EVENT_TYPE_MENU_CLICK: 0x00000004 const EVENT_TYPE_MENU_BAR_CLICK: 0x00000004
const EVENT_TYPE_MENU_UPDATE: 0x00000005
const EVENT_TYPE_MENU_CLICK: 0x00000006
const EVENT_TYPE_EMPTY: 0xFFFFFFFF const EVENT_TYPE_EMPTY: 0xFFFFFFFF
; block until an event is available ; block until an event is available

View File

@ -64,7 +64,9 @@ compare_memory_words: jmp [0xF004600C]
; event types ; event types
const EVENT_TYPE_MOUSE_CLICK: 0x00000000 const EVENT_TYPE_MOUSE_CLICK: 0x00000000
const EVENT_TYPE_MOUSE_RELEASE: 0x00000001 const EVENT_TYPE_MOUSE_RELEASE: 0x00000001
const EVENT_TYPE_MENU_BAR_CLICK: 0x00000002 const EVENT_TYPE_KEY_DOWN: 0x00000002
const EVENT_TYPE_MENU_UPDATE: 0x00000003 const EVENT_TYPE_KEY_UP: 0x00000003
const EVENT_TYPE_MENU_CLICK: 0x00000004 const EVENT_TYPE_MENU_BAR_CLICK: 0x00000004
const EVENT_TYPE_MENU_UPDATE: 0x00000005
const EVENT_TYPE_MENU_CLICK: 0x00000006
const EVENT_TYPE_EMPTY: 0xFFFFFFFF const EVENT_TYPE_EMPTY: 0xFFFFFFFF

37
keyboard.asm Normal file
View File

@ -0,0 +1,37 @@
; keyboard routines
; add events to the event queue if a key was pressed or released
; this should only be called by system_vsync_handler
keyboard_update:
; pop a key from the keyboard queue
in r0, 0x80000500
cmp r0, 0
ifz jmp keyboard_update_end
; check if this is a make or break scancode
bts r0, 7
ifnz jmp keyboard_update_break_scancode
mov r1, r0
mov r0, EVENT_TYPE_KEY_DOWN
mov r2, 0
mov r3, 0
mov r4, 0
mov r5, 0
mov r6, 0
mov r7, 0
call new_event
jmp keyboard_update_end
keyboard_update_break_scancode:
and r0, 0x7F
mov r1, r0
mov r0, EVENT_TYPE_KEY_UP
mov r2, 0
mov r3, 0
mov r4, 0
mov r5, 0
mov r6, 0
mov r7, 0
call new_event
keyboard_update_end:
ret

View File

@ -146,6 +146,7 @@ get_rom_version:
#include "draw_rectangle.asm" #include "draw_rectangle.asm"
#include "draw_text.asm" #include "draw_text.asm"
#include "event.asm" #include "event.asm"
#include "keyboard.asm"
#include "memory.asm" #include "memory.asm"
#include "menu.asm" #include "menu.asm"
#include "menu_bar.asm" #include "menu_bar.asm"

View File

@ -28,15 +28,6 @@ get_mouse_button:
; updates the cursor position and adds a event_type_mouse_click event to the event queue if the mouse button was clicked ; updates the cursor position and adds a event_type_mouse_click event to the event queue if the mouse button was clicked
; this should only be called by system_vsync_handler ; this should only be called by system_vsync_handler
mouse_update: mouse_update:
push r0
push r1
push r2
push r3
push r4
push r5
push r6
push r7
mov r0, 0x8000001F ; overlay 31: position mov r0, 0x8000001F ; overlay 31: position
in r2, 0x80000401 ; mouse position in r2, 0x80000401 ; mouse position
out r0, r2 out r0, r2
@ -125,12 +116,4 @@ mouse_update_menu_was_clicked:
call new_event call new_event
ret ret
mouse_update_end: mouse_update_end:
pop r7
pop r6
pop r5
pop r4
pop r3
pop r2
pop r1
pop r0
ret ret

View File

@ -1,5 +1,24 @@
; vsync interrupt routine ; vsync interrupt routine
system_vsync_handler: system_vsync_handler:
push r0
push r1
push r2
push r3
push r4
push r5
push r6
push r7
call mouse_update call mouse_update
call keyboard_update
pop r7
pop r6
pop r5
pop r4
pop r3
pop r2
pop r1
pop r0
reti reti