forked from fox32-arch/fox32rom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
event.asm
165 lines (135 loc) · 2.75 KB
/
event.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
; event system routines
; event types
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
const EVENT_TYPE_MENU_ACK: 0x00000007
const EVENT_TYPE_EMPTY: 0xFFFFFFFF
; block until an event is available
; inputs:
; none
; outputs:
; r0: event type
; r1-r7: event parameters
wait_for_event: jmp event_wait
; add an event to the event queue
; inputs:
; r0: event type
; r1-r7: event parameters
; outputs:
; none
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
; this is my child - lua
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
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
mov r8, EVENT_QUEUE_BOTTOM
call event__load
mov r8, EVENT_TEMP
call event__store
mov r9, EVENT_QUEUE_BOTTOM
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
jmp event_next_1
event_next_2:
mov r8, EVENT_TEMP
call event__load
sub [EVENT_QUEUE_POINTER], EVENT_SIZE
pop r9
pop r8
ise
ret
event_new:
call event__init
push r8
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
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]
add r8, 4
ret
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