Reading a simple switch is just a matter of reading the port (either #Status or #Command that has the switch attached to it), see Listing 1. There are, of course, a few minor complications. First, as mentioned above, we should be sure to use pullup resistors on the open collector lines. Second, bit 7 of the #Status port is inverted in hardware so that it reads a zero when the line is high and reads a one when the line is low, bits 0, 2 and 3 of #Command are also inverted. Further, on an MS-DOS system, if your Forth reads the I/O ports via calls through the BIOS, then bits 3 and 6 of #Status are also inverted.
If you are using PFE V0.9.14 and Linux you might have to make some minor patches to the source file support.c (this depends upon the version of the GNU C compiler you are using; I am using V2.7.0). If you can properly read the switch only the first time the ``file'' to the I/O ports is opened, and you get the same value for all subsequent reads then you will have to apply the following diff patch to support.c and rebuild Forth: