home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / forth / compiler / fpc / source / l3p070.seq < prev    next >
Text File  |  1990-04-01  |  2KB  |  57 lines

  1. \ Lesson 3 Part 7  ( F-PC 3.5 Tutorial by Jack Brown )
  2. COMMENT:
  3. Further discussion of the KEY_TEST program from Lesson 3 Part 5.
  4.  
  5. New Word:  KEY   Wait for user to press key on keyboard and
  6. KEY  ( --   n )  return the key code n.  If n is < 128 then n
  7.                  is the ASCII code for the key pressed.  If n
  8.                  is > 128 then n is the function key scan code
  9.                  + 128.
  10.  
  11. Old Word:  EXIT  Stops compilation when not in a colon definition
  12. EXIT ( -- )      When compiled in a word, EXIT , will cause
  13.                  termination of word execution when encountered.
  14. COMMENT;
  15. :  KEY_TEST ( -- )
  16.         BEGIN  CR  KEY       \  Wait for key press by user.
  17.         DUP  CONTROL M  =    \  Control M is return key.
  18.         IF DROP EXIT THEN    \  Exit infinite loop if pressed.
  19.         DUP .  EMIT          \  Otherwise show key pressed.
  20.         AGAIN ;
  21.  
  22. COMMENT:
  23. Another version of KEY...  or  We don't always like F-PC's  KEY so we
  24. made our own version of KEY that we call  PCKEY .
  25.  
  26. Here is our PCKEY definition.  Our version returns a flag that can
  27. be immediately tested to determine whether an ASCII key was pressed
  28. (true flag returned) or a function key was pressed (false flag
  29. returned).
  30.  
  31. Note:   BIOSKEY ( -- n) Is a primitive keyboard input word that returns
  32. a 16-bit number whose high 8 bits consist of the keyboard scan code and
  33. whose low 8-bits consist of the ASCII code of the key pressed.  If the
  34. key is not an ASCII key then the low 8-bits are zero.
  35. COMMENT;
  36.  
  37. \ This is a different type of keyboard input routine.
  38. \ Return  ASCII code and tf or  function key scan code and ff.
  39. : PCKEY  ( --   n  flag )
  40.        BIOSKEY DUP 127 AND    \ Mask of low 8-bits to check for ASCII
  41.        IF   127 AND TRUE      \ Yes its ASCII, mask off ASCII value.
  42.        ELSE FLIP    FALSE     \ Its a function key,  leave scan code.
  43.        THEN ;
  44.  
  45.  
  46. \ Test ascii keys and function keys.
  47. :  PCKEY_TEST  ( -- )
  48.         BEGIN  CR  PCKEY
  49.         IF   DUP  CONTROL M  =         \  Control M is return key.
  50.              IF   DROP EXIT THEN       \  Exit infinite loop if pressed.
  51.              ." ASCII key character code = "
  52.              DUP .  EMIT               \  Display code and character.
  53.         ELSE ." Function  key  scan code = " .  \ Display scan code.
  54.         THEN
  55.         AGAIN ;
  56.  
  57.