home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
forth
/
compiler
/
fpc
/
source
/
l7p040.seq
< prev
next >
Wrap
Text File
|
1990-04-29
|
2KB
|
58 lines
\ ╔════════════════════════════════════════════════════╗
\ ║ Lesson 7 Part 4 F-PC 3.5 Tutorial by Jack Brown ║
\ ╚════════════════════════════════════════════════════╝
\ ┌───────────────────────────────────────┐
\ │ Creating and Using New Vocabularies │
\ └───────────────────────────────────────┘
ONLY FORTH ALSO DEFINITIONS \ Default search order
VOCABULARY SOUND \ Make a new vocabulary
\ Place duplicate copy of the SOUND vocabulary in the ROOT directory
\ so that it can be found when the FORTH directory is not in the
\ search path.
ROOT DEFINITIONS \ Place an extra copy in ROOT
: SOUND SOUND ; \ vocabulary.
\ Get ready to add some new word definitions to the SOUND vocabulary.
SOUND DEFINITIONS
\ New words to fetch and store to 8 bit I/O ports.
\ PC! ( byte n -- ) Output byte to port number n.
\ PC@ ( n byte ) Input byte from port number n.
HEX
: S.ON ( -- ) \ Turn speaker on.
61 PC@ 3 OR 61 PC! ;
: S.OFF ( -- ) \ Turn speaker off.
61 PC@ FFFC AND 61 PC! ;
DECIMAL
: TONE ( freq -- ) \ Make tone of specified frequency.
21 MAX \ Lowest frequency.
1.190000 ROT \ Get divisor for timer.
MU/MOD \ 16bit.rem 32bit.quot
DROP NIP \ Keep 16-bit quotient only.
[ HEX ] \ Want HEX radix base for following.
0B6 043 PC! \ Write to timer mode register.
100 /MOD SWAP \ Split into hi and low byte.
42 PC! 42 PC! \ Store low and high byte in timer.
S.ON ; \ turn speaker on.
DECIMAL
\ Define some notes.
: C ( -- ) 131 TONE ; : D ( -- ) 147 TONE ;
: E ( -- ) 165 TONE ; : F ( -- ) 175 TONE ;
: G ( -- ) 196 TONE ; : A ( -- ) 220 TONE ;
: B ( -- ) 247 TONE ; : CC ( -- ) 262 TONE ;
\ Delay for one beat time period.
: BEAT ( -- ) 1 SECONDS ( 20000 0 DO LOOP ) ;
: SCALE ( -- ) \ Play the musical scale.
C BEAT D BEAT E BEAT F BEAT G BEAT
A BEAT B BEAT CC BEAT BEAT BEAT S.OFF ;