-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmodule.s
More file actions
326 lines (280 loc) · 8.71 KB
/
module.s
File metadata and controls
326 lines (280 loc) · 8.71 KB
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
GET hdr.include
AREA |!!!Module$$Header|, CODE, READONLY, PIC
IMPORT |__RelocCode|
ENTRY
;----------------------------------------------------------------------------
; Setting/Clearing V for errors. All other flags undefined
;----------------------------------------------------------------------------
MACRO
ClrErr
cmp R0,#0
MEND
MACRO
SetErr
cmp R0,#1<<31
cmnvc R0,#1<<31
MEND
;----------------------------------------------------------------------------
; Module Header
;----------------------------------------------------------------------------
module_base
DCD 0 ; Start address
DCD module_init - module_base ; Initialise code
DCD module_die - module_base ; Finalise code
DCD 0 ; Service call handler
DCD module_title - module_base ; Title
DCD module_help_str - module_base ; Infomation string
DCD module_commands - module_base ; CLI command table
DCD 0 ; SWI base
DCD 0 ; SWI handler
DCD 0 ; SWI names table
DCD 0 ; SWI decoding code
DCD 0 ; Messages filename
DCD module_flags - module_base ; Module flags
module_title
DCB "KeyMapper",0
module_help_str
DCB "KeyMapper",9,"1.00"
DCB " (":CC:("$BUILDDATE":RIGHT:11):CC:")"
DCB " © James Peacock",0
ALIGN
module_flags
DCD 1 ; 32-bit compatible
;----------------------------------------------------------------------------
; Module initialisation
;----------------------------------------------------------------------------
; => r10 => Environment string
; r11 = 0 or Instantiation No. or I/O base address
; r12 => Private word
; r13 = Supervisor sp.
;
; <= Preserve Mode, Interrupt state, r7-r11,r13.
; Can corrupt r0-r6,r12,r14, flags.
; Return V set/R0=>Error block to stop module loading.
module_init
mov r6,r12
ldr ws,[r6]
teq ws,#0
movne pc,lr
stmfd sp!,{lr}
bl |__RelocCode|
mov r0,#6
mov r3,#no_keys
swi XOS_Module
bvs module_init_exit
str r2,[r6]
mov ws,r2
mov r0,#KeyV
adr r1,key_v
swi XOS_Claim
bvs module_init_failed
bl reset_key_map
ClrErr
module_init_exit
ldmfd sp!,{pc}
module_init_failed
mov r5,r0
mov r0,#7
mov r2,ws
swi XOS_Module
mov r0,#0
str r0,[r6]
mov r0,r5
SetErr
ldmfd sp!,{pc}
;----------------------------------------------------------------------------
; Module finalisation
;----------------------------------------------------------------------------
; => r10 = Fatality: 0=>Non-fatal; 1=>Fatal
; r11 = Instantiation No.
; r12 => Private word
; r13 = Supervisor sp.
;
; <= Preserve Mode, Interrupt state, r7-r11,r13.
; Can corrupt r0-r6,r12,r14, flags.
; Return V set/R0=>Error block to stop module being removed.
module_die
mov r6,r12
ldr ws,[r6]
teq ws,#0
moveq pc,lr
stmfd sp!,{lr}
mov r0,#KeyV
adr r1,key_v
mov r2,ws
swi XOS_Release
ldmvsfd sp!,{pc}
mov r0,#7
mov r2,ws
swi XOS_Module
ClrErr
mov r0,#0
str r0,[r6]
ldmfd sp!,{pc}
;----------------------------------------------------------------------------
; KeyV interception
;----------------------------------------------------------------------------
; => r0 = Reason code (only interested in KeyUp/KeyDown)
; r1 = Internal Key Number
key_v
teq r0,#KeyV_KeyPressed
teqne r0,#KeyV_KeyReleased
movne pc,lr
cmp r1,#no_keys
ldrlob r1,[ws,r1]
mov pc,lr
;----------------------------------------------------------------------------
; *Command Table
;----------------------------------------------------------------------------
module_commands
DCB "KeyMap",0
ALIGN
DCD command_key_map - module_base
DCD &00020300
DCD command_key_map_syntax - module_base
DCD command_key_map_help - module_base
DCB "KeyMapReset",0
ALIGN
DCD command_reset_key_map - module_base
DCD &00020300
DCD command_reset_key_map_syntax - module_base
DCD command_reset_key_map_help - module_base
DCD 0
;----------------------------------------------------------------------------
; *KeyMap <PhysicalKeyCode> <LogicalKeyCode>
;----------------------------------------------------------------------------
; => r0 => Command tail
; r1 = Number of parameters
; r12 => Private word
; r13 = SVC stack pointer
; r14 = Return address
;
; <= r0 => Error block, if V set.
; r0-r6,r12,r14, flags corruptable.
command_key_map
stmfd sp!,{lr}
ldr ws,[r12]
bl read_key_code
bvs command_key_map_exit
cmn r1,#1
beq command_key_map_dump_all
mov r2,r1 ; r2 = physical key
bl read_key_code ; r1 = logical key
bvs command_key_map_exit
cmn r1,#1
beq command_key_map_dump_one
strb r1,[ws,r2]
command_key_map_exit
ldmfd sp!,{pc}
command_key_map_dump_one
mov r0,r2
bl print_key_code
bvs command_key_map_exit
swi XOS_WriteS
DCB " --> ",0
ALIGN
ldrvcb r0,[ws,r2]
blvc print_key_code
swivc XOS_NewLine
b command_key_map_exit
command_key_map_dump_all
mov r1,#0
command_key_map_dump_all_loop
ldrb r2,[ws,r1]
teq r1,r2
beq command_key_map_dump_all_skip
mov r0,r1
bl print_key_code
bvs command_key_map_exit
swi XOS_WriteS
DCB " --> ",0
ALIGN
movvc r0,r2
blvc print_key_code
swivc XOS_NewLine
command_key_map_dump_all_skip
add r1,r1,#1
cmp r1,#no_keys
bne command_key_map_dump_all_loop
b command_key_map_exit
command_key_map_help
DCB "*",27,0," allows the internal key number returned when a "
DCB "keyboard key or mouse button (<from>) is pressed to be "
DCB "mapped to different value (<to>) before reaching the "
DCB "kernel. The key codes are internal key numbers (see the OS "
DCB "StrongHelp manual). If <to> is omitted, its current "
DCB "mapping is shown; if both keys are omitted, all mappings "
DCB "are shown.",13,10
command_key_map_syntax
DCB 27,1," [<from> [<to>]]",0
ALIGN
;----------------------------------------------------------------------------
; *ResetKeyMap
;----------------------------------------------------------------------------
command_reset_key_map
stmfd sp!,{lr}
ldr ws,[r12]
bl reset_key_map
ClrErr
ldmfd sp!,{pc}
command_reset_key_map_help
DCB "*",27,0," removes all key mappings",13,10
command_reset_key_map_syntax
DCB 27,1,0
ALIGN
;----------------------------------------------------------------------------
; read_key_code
;----------------------------------------------------------------------------
; => r0 = Pointer to CTRL terminated string
;
; <= r0 Updated to end of key code/string terminator
; r1 = Internal key number or -1 if none.
;
; V set, r0 => Error block tro return an error, r1 undefined.
read_key_code
stmfd sp!,{r2,lr}
read_key_code_loop
ldrb r14,[r0],#1
cmp r14,#32
beq read_key_code_loop
sub r0,r0,#1
mvnlo r1,#0
blo read_keu_code_exit
mov r1,r0
mov r0,#10
orr r0,r0,#1:SHL:29
mov r2,#no_keys-1
swi XOS_ReadUnsigned
mvnvs r1,#0
ldmvsfd sp!,{r2,pc}
mov r0,r1
mov r1,r2
read_keu_code_exit
ClrErr
ldmfd sp!,{r2,pc}
;----------------------------------------------------------------------------
; print_key_code
;----------------------------------------------------------------------------
; => r0 = Key code
; <= r0 Corrupted/error (if V set)
print_key_code
stmfd sp!,{r1-r2,lr}
sub sp,sp,#32
mov r1,sp
mov r2,#32
swi XOS_ConvertCardinal4
swivc XOS_Write0
add sp,sp,#32
ldmfd sp!,{r1-r2,pc}
;----------------------------------------------------------------------------
; reset_key_map
;----------------------------------------------------------------------------
; Corrupts R0, flags
reset_key_map
mov r0,#no_keys
reset_key_map_loop
subs r0,r0,#1
strb r0,[ws,r0]
bne reset_key_map_loop
mov pc,lr
END