This procedure waits for a single keystroke from user and returns to caller with response in RAX, or more specifically AL, with an optional prompting string in RDI. Primarily the algorithms scope is expecting 0-9, A-Z for menu selections lets say and Y or N as input.
Ask: enter termios.size * 2, 0
push r15
push rbx
or edi, edi
jz $ + 7
call Show
lea rdi, [rbp-termios.size*2]
mov esi, TCGETS
call TermAttr
push rdi
push rsi
mov ecx, eax
mov cl, 6
mov rsi, rdi
lea rdi, [rbp-termios.size]
mov rbx, rdi
rep movsq
and byte [rbx+termios.c_lflag], ~(ICANON | ECHO | ISIG)
mov word [rbx+termios.c_cc+VTIME], 0x100
mov rdi, rsi
pop rsi
mov si, TCSETSF
push rsi
call TermAttr
At this point, console is set to noncanonical mode, waiting for a single keystore from user.
xor eax, eax
mov edi, eax
mov edx, eax
inc dl
push byte 0
mov rsi, rsp
syscall
RSP points to the 8 byte buffer filled with nulls created by push byte 0
and in most cases, this buffer will have but one byte of input. Instead of returning with buffer flushed I want RAX to return with all input. For example F12 would return 7E34321B
.
pop r15
pop rsi
pop rdi
call TermAttr ; STDIN is flushed here
pop rbx
mov rax, r15
pop r15
leave
ret
To my understanding, I have two options;
- Polling read MIN = 0; VTIME = 0
- Read with interbyte timeout MIN = 0; VTIME > 0
I believe polling is the most viable option but have a hard time interpreting;
read(2) returns immediately with the lesser of the number of bytes availiable, or the number of bytes requested.
If no data is availiable, read(2) returns 0.
Is my thinking correct that if F12
is pressed, which I would know something other than 7FH - 20H was pressed by ESC in AL, that the next read would return 3 and then I could do whatever to read the remaining characters?