.text
.align 2
ev_size=16
evdata_len=ev_size*4
.macro syswrite @ print the content of r1, must be ascii, buffer length r2 must be set
push {r0, r7}
mov r7, #4 @ system call number, 4 is 'write'
mov r0, #1 @ file descriptor 1 - stdout
svc 0 @ call the Linux kernel and print the ascii text
pop {r0, r7}
.endm
.macro syswritechar @ print what r1 points at, must be ascii, buffer length r2 must be set
push {r0, r2, r7}
mov r2, #1
mov r7, #4 @ system call number, 4 is 'write'
mov r0, #1 @ file descriptor 1 - stdout
svc 0 @ call the Linux kernel and print the ascii text
pop {r0, r2, r7}
.endm
.macro newline
ldr r1, =newline @ point on the buffer to write, \n, a newline
mov r2, #2 @ newline buffer length
syswrite
.endm
.global _start
_start:
getkey:
mov r2,#evdata_len
ldr r1, =evdata_ofs
sub r0, r0, r0
@ Clear evdata to evdata_len of zeroes
@ Set r0 to 'keyp' i.e. 0x7079656b (assuming I've got my endianness correct)
mov r7, #3
svc 0 @ Do sys_read
cmp r0, #ev_size
bge getkey_ok
@ Set r0 to 'gpio' i.e. 0x6f697067
svc 0 @ Do sys_read again, this time on gpio signals??
cmp r0,#ev_size
@ if lt, mov r0, #0 ; return - no key pressed
getkey_ok:
@ Got a valid key event
ldrh r2, [r1, #8]
ldrh r0, [r1, #10]
ldr r3, [r1, #12]
@ if r2==1 (#ev_key) and r3==1 (#ev_press), return key code in r0, else mov r0, #0 and return
newline
_disp_hex:
ldr r1, =asciicounter @ point on =asciicounter
mov r2, r0
mov r3, #15
mov r4, #8
_loop:
mov r2, r2, ror #28
and r5, r2, r3
cmp r5, #9
add r5, #48
ble _num
add r5, #7
_num:
str r5, [r1]
syswritechar
subs r4, #1
bne _loop
newline
mov r7, #1 @ exit
svc 0 @ call the Linux kernel and exit
.data
asciicounter: .word 0 @ must be initialized
newline: .asciz "\n" @ \n is a newline
evdata: .fill evdata_len,1,0
evdata_ofs: .word evdata