fox32rom/event.asm

164 lines
2.7 KiB
NASM
Raw Normal View History

; event system routines
; event types
2022-04-16 23:59:19 +02:00
const EVENT_TYPE_MOUSE_CLICK: 0x00000000
const EVENT_TYPE_MOUSE_RELEASE: 0x00000001
const EVENT_TYPE_KEY_DOWN: 0x00000002
const EVENT_TYPE_KEY_UP: 0x00000003
const EVENT_TYPE_MENU_BAR_CLICK: 0x00000004
const EVENT_TYPE_MENU_UPDATE: 0x00000005
const EVENT_TYPE_MENU_CLICK: 0x00000006
2022-04-16 23:59:19 +02:00
const EVENT_TYPE_EMPTY: 0xFFFFFFFF
; block until an event is available
; inputs:
; none
; outputs:
; r0: event type
; r1-r7: event parameters
2022-04-16 23:59:19 +02:00
wait_for_event: jmp event_wait
; add an event to the event queue
; inputs:
; r0: event type
; r1-r7: event parameters
; outputs:
; none
2022-04-16 23:59:19 +02:00
new_event: jmp event_new
; get the next event and remove it from the event queue
; inputs:
; none
; outputs:
; r0: event type
; r1-r7: event parameters
get_next_event: jmp event_next
; implementation
const EVENT_SIZE: 32
const EVENT_TEMP: 0x01FFFBDA
const EVENT_QUEUE_POINTER: 0x01FFFBFA
const EVENT_QUEUE_BOTTOM: 0x01FFFBFE
event_wait:
call event__init
event_wait_0:
ise
halt
2022-04-16 23:59:19 +02:00
cmp [EVENT_QUEUE_POINTER], EVENT_QUEUE_BOTTOM
ifz jmp event_wait_0
jmp event_next_0
event_next:
call event__init
cmp [EVENT_QUEUE_POINTER], EVENT_QUEUE_BOTTOM
ifz jmp event__empty
event_next_0:
icl
push r8
push r9
2022-02-12 05:44:11 +01:00
mov r8, EVENT_QUEUE_BOTTOM
2022-04-16 23:59:19 +02:00
call event__load
mov r8, EVENT_TEMP
call event__store
2022-04-16 23:59:19 +02:00
mov r9, EVENT_QUEUE_BOTTOM
2022-04-16 23:59:19 +02:00
event_next_1:
add r9, EVENT_SIZE
cmp [EVENT_QUEUE_POINTER], r9
ifz jmp event_next_2
mov r8, r9
call event__load
mov r8, r9
sub r8, EVENT_SIZE
call event__store
2022-04-16 23:59:19 +02:00
jmp event_next_1
event_next_2:
mov r8, EVENT_TEMP
call event__load
sub [EVENT_QUEUE_POINTER], EVENT_SIZE
pop r9
pop r8
2022-04-16 23:59:19 +02:00
ise
ret
2022-04-16 23:59:19 +02:00
event_new:
call event__init
push r8
2022-04-16 23:59:19 +02:00
mov r8, [EVENT_QUEUE_POINTER]
call event__store
mov [EVENT_QUEUE_POINTER], r8
pop r8
ret
event__init:
cmp [EVENT_QUEUE_POINTER], 0
ifz mov [EVENT_QUEUE_POINTER], EVENT_QUEUE_BOTTOM
ret
event__empty:
mov r0, EVENT_TYPE_EMPTY
mov r1, 0
mov r2, 0
mov r3, 0
mov r4, 0
mov r5, 0
mov r6, 0
mov r7, 0
ret
2022-04-16 23:59:19 +02:00
event__load:
mov r0, [r8]
add r8, 4
mov r1, [r8]
add r8, 4
mov r2, [r8]
add r8, 4
mov r3, [r8]
add r8, 4
mov r4, [r8]
add r8, 4
mov r5, [r8]
add r8, 4
mov r6, [r8]
add r8, 4
mov r7, [r8]
2022-04-16 23:59:19 +02:00
add r8, 4
ret
2022-04-16 23:59:19 +02:00
event__store:
mov [r8], r0
add r8, 4
mov [r8], r1
add r8, 4
mov [r8], r2
add r8, 4
mov [r8], r3
add r8, 4
mov [r8], r4
add r8, 4
mov [r8], r5
add r8, 4
mov [r8], r6
add r8, 4
mov [r8], r7
add r8, 4
ret