\ a place for the output of the serial driver wvariable inchar 100 inchar W! \ demo ( -- ) : demo \ start the serial cog, make sure there is nothing connected to the pin \ that will drive it, by specifying the same pin for rx and tx the serial driver \ is effectively in loopback mode d d e100 5 startserialcog 10 delms \ get the current output ptr of cog 5, leave on the stack 5 cogio 2+ W@ \ set the output of cog5 to point to inchar inchar 5 cogio 2+ W! \ get the current output ptr of this cog, leave on the stack io 2+ W@ \ set the output ptr of thsi cog to the input of cog 5 5 cogio io 2+ W! \ emit 128 characters 80 0 do i emit loop \ restore this cogs output pointer io 2+ W! \ teh serial port buffers up to 128 characters on input, so they should all be there 80 0 do i . \ poll for a char, 4096 times max 1000 0 do \ is there a character from the serial port inchar W@ 100 and 0= if \ get the char inchar W@ \ set inchar ready to receive next char 100 inchar W! . leave then loop cr loop 5 cogio 2+ W! ; \ IO for propforth is done via an io channel. An io channel is a long which is treated \ as 2 words. The io channel which connects to the interpreter is at the beginning \ of the cog data area. It is defined as io. Any cogs io is defined as n cogio. \ \ The structure of the long is 2 words as follows: \ io (word) - this is the input, if the 0x0100 bit is set, it means the interpreter \ is ready to accept input. To send a byte to the input write 0x00cc, \ where cc is the byte value. This word is used by key? and key \ io + 2 (word) - this is a pointer to the where the output of the channel goes \ This word is used by emit? and emit. \ If this word is 0, the ouput destination is not valid and emit \ will simply "throw away the output. If it is not zero, it is assumed \ to be a pointer to an io channel. Thus the output of an io channel \ always points to the input of another io channel. \