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

  1. \       ╔════════════════════════════════════════════════════╗
  2. \       ║  Lesson 7 Part 4  F-PC 3.5 Tutorial by Jack Brown  ║
  3. \       ╚════════════════════════════════════════════════════╝
  4.  
  5. \             ┌───────────────────────────────────────┐
  6. \             │  Creating and Using New Vocabularies  │
  7. \             └───────────────────────────────────────┘
  8.  
  9. ONLY FORTH ALSO DEFINITIONS    \ Default search order
  10.  
  11. VOCABULARY SOUND               \ Make a new vocabulary
  12.  
  13. \ Place duplicate copy of the SOUND vocabulary in the ROOT directory
  14. \ so that it can be found when the FORTH directory is not in the
  15. \ search path.
  16.  
  17. ROOT DEFINITIONS      \ Place an extra copy in ROOT
  18. : SOUND  SOUND ;      \ vocabulary.
  19.  
  20. \ Get ready to add some new word definitions to the SOUND vocabulary.
  21. SOUND DEFINITIONS
  22.  
  23. \  New words to fetch and store to 8 bit I/O ports.
  24. \  PC!  ( byte  n   --  )  Output byte to port number n.
  25. \  PC@  ( n        byte )  Input  byte from port number n.
  26.  
  27. HEX
  28. :   S.ON  ( -- )      \  Turn speaker on.
  29.         61 PC@ 3  OR   61 PC! ;
  30. :   S.OFF ( -- )       \ Turn speaker off.
  31.         61 PC@  FFFC AND  61 PC! ;
  32. DECIMAL
  33.  
  34. : TONE  ( freq -- )        \ Make tone of specified frequency.
  35.     21 MAX                 \ Lowest frequency.
  36.     1.190000  ROT          \ Get divisor for timer.
  37.     MU/MOD                 \ 16bit.rem   32bit.quot
  38.     DROP NIP               \ Keep 16-bit quotient only.
  39.     [ HEX ]                \ Want HEX radix base for following.
  40.     0B6   043 PC!          \ Write to timer mode register.
  41.     100  /MOD SWAP         \ Split into hi and low byte.
  42.     42 PC! 42 PC!          \ Store low and high byte in timer.
  43.       S.ON ;               \ turn speaker on.
  44. DECIMAL
  45. \ Define some notes.
  46. : C  ( -- )  131 TONE ;   : D  ( -- )  147 TONE ;
  47. : E  ( -- )  165 TONE ;   : F  ( -- )  175 TONE ;
  48. : G  ( -- )  196 TONE ;   : A  ( -- )  220 TONE ;
  49. : B  ( -- )  247 TONE ;   : CC ( -- )  262 TONE ;
  50.  
  51. \ Delay for one beat time period.
  52. : BEAT   ( -- ) 1 SECONDS ( 20000 0 DO LOOP ) ;
  53.  
  54. : SCALE  ( -- ) \ Play the musical scale.
  55.          C BEAT D BEAT E BEAT F BEAT G BEAT
  56.          A BEAT B BEAT CC BEAT BEAT BEAT S.OFF ;
  57.  
  58.