home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / forth / compiler / fpc / tutor / l7p130 < prev    next >
Text File  |  1990-07-15  |  4KB  |  86 lines

  1.  
  2.        ╔═════════════════════════════════════════════════════╗
  3.        ║  Lesson 7 Part 130 F-PC 3.5 Tutorial by Jack Brown  ║
  4.        ╚═════════════════════════════════════════════════════╝
  5.  
  6.          ┌───────────────────────────────────────────────┐
  7.          │  Control Your Printer with CREATE ... DOES>   │
  8.          └───────────────────────────────────────────────┘
  9.  
  10. Here is another application of CREATE ... DOES> .  Remember that this
  11. idea of extending the compiler is new and unheard of in other languages.
  12. You will have to become familiar with all of the examples I have
  13. presented and then try to think of variations or application of the
  14. ideas to new areas.
  15.  
  16. You just bought a fancy EPSON FX85+ printer (or one of the many clones).
  17. It comes with a manual 1.5 inches thick documenting all the features and
  18. the escape sequences necessary to activate them.  Some of features
  19. require only one control code, some require 2 codes to be sent and yet
  20. others require more than 2 codes.
  21.  
  22. Here is the defining word that will create printer extensions. We are
  23. using EPSON FX85 printer control sequences for the examples.
  24. Usage would be as follows:
  25.  
  26. 1) Only one code to be sent.
  27.    15 1 FEATURE COMPRESSED   \ 15 or ^O is the EPSON code for this mode.
  28.  
  29. 2) Two codes must be sent. Note that the order of the codes is the
  30.    reverse of the order they will be sent.
  31.    64 27 2 FEATURE EPSON-RESET \ 27 64 , or ESC @ will resets printer.
  32.  
  33. 3) Three codes required.
  34.    49 78 27 3 FEATURE NEAR-LETTER-QUALITY
  35.    \ 27 78 49 or ESC "x1" will put FX85+ into NLQ mode.
  36.  
  37. k) If k codes were required you would follow the pattern below always
  38.    with the codes in the reverse order from the manual.  ie reverse
  39.    polish notation!  If you look at the definition you will see that
  40.    since the top stack number is compiled first they will actually
  41.    be compiled in the correct order in memory.
  42.    n1 n2 ... nk  k FEATURE  <name>
  43.  
  44. \ Print feature defining word.
  45. : FEATURE  ( n1 n2...nk k    -- )
  46.                     \ Below is the compile time routine.
  47.    CREATE DUP C,    \ Duplicate and compile the number of codes.
  48.     0 ?DO C, LOOP   \ Compile k codes to be sent to the printer
  49.                     \ This is the run time routine.
  50.     DOES>   COUNT   \ Fetch number of codes and increment address.
  51.     0 ?DO   COUNT   \ Fetch a code.
  52.            (PRINT)  \ Send code to printer only.
  53.        LOOP ;       \ Loop till all codes sent.
  54.  
  55. Notes:
  56.  
  57. 1) The word COUNT ( addr   addr+1 char ) actually fetches the byte
  58.    stored at  addr  and then increments addr by 1.  Its definition
  59.    would be  : COUNT  DUP 1+ SWAP C@ ;
  60.  
  61. 2) (PRINT) is an F-PC word that emits or sends the character
  62.    corresponding to the top stack number to the printer only.
  63.  
  64. Now all you have to do is go through the control code reference card
  65. at the end of the manual and make words for each series of codes.  You
  66. can even combine features.
  67.  
  68. ASCII M 27 ASCII E 27 ASCII @ 27 6 FEATURE EMPHASIZED-ELITE
  69.  
  70. This will reset the printer, put it in emphasized mode, and
  71. select elite pitch.
  72.  
  73. ╓───────────────╖
  74. ║  Problem 7.10 ║
  75. ╙───────────────╜
  76. a) Test FEATURE and provide examples of several other commands.
  77. b) Make a version of FEATURE that can send ANSI codes to the console.
  78.    To test your word you will have to turn off F-PC direct screen writes
  79.    by using the command  SLOW.
  80.  
  81. ┌────────────────────────────────────┐
  82. │  Please Move to Lesson 7 Part 140  │
  83. └────────────────────────────────────┘
  84.  
  85.  
  86.