etherforth_logo

Node 013

This node processes a-z characters and non-printable keys Enter, Esc, Backspace, Tab, and Space.

Source code

usb node 012 node 014 node 013
013 chars
host *, ca 40 * or , ; target

nprt 00 B esc 0 *, C bs 2F *, A ent 32 *,
D tab 35 *, E sp 37 *,

mask 05 cm-cmf over over 3F and or ;
nprt? 08 cm-c mask if drop drop ;
then drop 2/ 2/ 2/ 2/ 2/ 2/
20000 or pop drop pop drop ;
alpha 11 sc -4 . + -if ahead * swap
then dup -66 . + - -if ahead * swap
then drop -26 . + -if 36 . + ; then
dup dup or 'nprt a! 4 for @+ nprt? next
8000 or ; then then *
go 25 left a! @ @ @ if go ;
then drop sc alpha over !b !b go ; 2C

init right b! go ; 2F

6 d 4 r 0 ether

Definitions

*,
This word is defined in colorForth host dictionary. It takes character code c and address a, shifts a 6 bits left, combines the two together, and compiles the result into image.
nprt
Table of non-printable characters. Low six bits correspond to scan code, top 12 bits are address of the corresponding f18 code (bits 17 and 16 not relevant).
mask
Expect keyboard scan code in S and a mask from nprt table in T. It keeps the stack and returns flag in T. If scan code not found return true, else zero.
nprt?
Expect key code in S and mask in from nprt table T. Test with mask and if not found drop both flag and mask and return. Else combine the address with call instruction, drop loop index and return address (from nprt?) and return directly from alpha to go to send the result out.
alpha
Expect shift byte in S (not used here) and key code in T. First subtract 4 from key code. If negative, we either have no key pressed or we have key roll over or any other error. At any rate, jump directly to go. Then we check if the key code is greater than 63. If so, we disregard this key and jump to go. Then we subtract 26 and if the result is negative, we have alpha character, which we convert to etherforth character code by adding 36, and we return back to go and send the character out.

If not negative, then it may be a non-printable character. Set address of nprt table (zero) and start a loop reading data from the table and testing with nprt?. If not found in the table, we set bit 15 of the key code and send out for further processing in node 012.

go
Get control byte, key scan code, and error flag from node 014. If error non-zero disregard this data and jump back to go. Else analyze data with alpha and send control byte and result of the analysis (either etherforth character code or a call f18 instruction corresponding to non-printable keys) or non-processed data word (with bit 15 set) to node 012. Then wait for new data from node 014.
init
Set B, and jump to go.

Description

This node reads data from USB keyboard controller, determines if the data are valid (no error in data, only one new key pressed), and attempts to convert the key scan code into character or function code. It does so by arithmetic manipulation of each key scan code. Function codes are read from nprt table. Key scan codes not converted here are passed to node 012. A useful reference to keyboard scan codes is given here.