Paolo, > > key? . < 0 ok
means "no unread key available" (the 0) > > depth . < 0 ok > > begin key? until < ok begin and until make only sense inside a colon definition. Used interactivly they do the wrong thing. Namely > > depth . < 1 ok > > . < 4516 ok place a flash address on the data stack. > > > > I have some questions: why the loop exits immediatly w/o typing any char on > keyboard? Try the following > : key-test begin key? until ; > key-test key-test now blocks until a key is pressed. And leave in the input buffer, you'll have to use KEY to get the character. To make things more complicated: the amforth interpreter does this for you and you'll see the character that caused the key-test to exit as the first character of the next input line at the command prompt (I pressed a and got) ok > a > What is the behaviour of “key?” KEY? is a standard Forth word. It checks whether a key stroke (aka an unread character) is available. It does not block and waits for one, it only checks. In amforth, KEY? is a deferred word that may be changed at runtime. The standard KEY? checks the USART Input Buffer, the one that is filled by an interrupt service routine, not the one REFILL and SOURCE use. > I expected the mcu to freeze until I type a key. Am I wrong? It does so. > What is “4516”? A flash address, since BEGIN and UNTIL use such numbers for their work. Again: these two words are not made for interactive use. > > Another question about “key” (w/o question mark): > > > key < ?? > > depth . < 1 ok > > . < 27 ok > > key . < 7 ok > > key dup . < 7 ok > > . < 27 ok > > depth . < 0 ok > > key dup . . < 7 27 ok > > > > It seems “key” to eat a char from output buffer... KEY waits for a key-event using KEY? and reads the character to the data stack. Maybe related to the next topic? > > key < ?? <------ Here the result was ‘\nok\r\n> ‘ and not ‘\n > > ok\r\n> ‘ as expected, a space was eaten > > key . < 7 ok <------ Here, after I type an <ESC>, the result was ‘\n7 > > ok\r\n> ‘ instead ‘\n27 ok\r\n> ‘ as expected, a “2” was eaten. Strange, I'd guess that you use the amforth-shell, aren't you? That shell uses a special character flow control that is great for uploading source code but completely useless for interactive work with KEY and KEY? please use some other, more direct terminal like minicom or putty, with minicom I cannot reproduce your errors, but see what you (and I) expect. Matthias ------------------------------------------------------------------------------ _______________________________________________ Amforth-devel mailing list for http://amforth.sf.net/ Amforth-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/amforth-devel