text
stringlengths 0
99.6k
|
|---|
Example:
|
: GETNAME ." Please type your name " NAME$ INPUT$ ;
|
This example will prompt the user, and store his response in NAME$.
|
VALUE$
|
This word will convert a string stored at an address to a double number on the stack. Example:
|
NUMBER$ VALUE$ ( convert the string in NUMBER$ to a double number on the stack.)
|
Using these basic string operations, all necessary string handling operations may be carried out. You can also easily define your own custom string handling words. For example, if you are particularly fond of BASIC's string handling procedures, it is easy to define Forth equivalents using these operators. For example:
|
: LEFT$ ( addr1 n addr2 --)
|
>R 1 SWAP R> COPY$ ( move n leftmost characters of addr1 to addr2) ;
|
Which you would use as follows:
|
NAME$ 4 TEMP$ LEFT$ ( the 4 leftmost characters in NAME$ are left in TEMP$)
|
: RIGHT$ ( Move n right most characters of addr1 to addr2.
|
Stack: addr1 n addr2 -- )
|
>R OVER $LENGTH 1+ SWAP - OVER $LENGTH R> COPY$ ;
|
You would use RIGHT$ as follows:
|
NAME$ 4 TEMP$ RIGHT$ ( the 4 rightmost characters of NAME$ are left in TEMP$.)
|
You can use definitions like these to easily convert BASIC programs to FORTH. Personally, I think you will find it more flexible in the long run to use indexes into the strings, rather than the less flexible BASIC type of command. That's only an opinion - many people have lived long and productive lives, and never once indexed into a string.
|
*lk:blazin.doc4
|
*hd3:Blazin' Forth Documentation,SID Support,-#-
|
*cn1;SID Chip Support*cn0
|
Blazin' Forth Contains all the words necessary to access the SID (Sound Interface Device) of the C64. Forths speed and flexibility make it ideal for this kind of real time control. Included with the source code is an extensive example of using Blazin' Forth to program music. This is loaded by typing: 105 124 THRU . (Remember, you must type MOUNT before using THRU or LOAD. You need only issue MOUNT once, of course. See MOUNT for more information.)
|
MUSIC.ON
|
This word *must* be executed before executing any of the note words. It clears the sound chip, initializes important variables and then starts up a interrupt driven routine that is responsible for timing the voices, and gating off the sounds at the proper time.
|
MUSIC.OFF
|
This word should be at the end of the music program. It restores the 64's normal interrupt system, and shuts off SID. Note that peculiar results will occur if these two words are not used in their proper order. (Note: Typing RUN/STOP RESTORE will have the same effect as MUSIC.OFF)
|
V1 V2 V3
|
These words set the current voice. For example, typing V1 will cause all of the following commands to affect only voice 1.
|
*fp0
|
ATTACK DECAY SUSTAIN RELEASE
|
These set the envelope parameters for the sid chip. Each one takes a parameter between 0 and 15. Example:
|
V1 0 ATTACK 15 DECAY 0 SUSTAIN 0 RELEASE ( setparams for voice 1)
|
V2 15 ATTACK 0 DECAY 15 SUSTAIN 15 RELEASE ( setparameters for voice 2)
|
VOLUME
|
Takes a value between 0 and 15. Note that this command sets the volume for all voices.
|
15 VOLUME ( set volume for all voices to max)
|
C D E F G A B C# D# F# G# A# D< E< F< E# G< A< B< R
|
These words do the actual playing of the notes. Note that the sign "<" by some of the notes is actually the left arrow sign, but EZ-script won't allow that to be entered into a document. It means the notes are flatted. There is also a word R , which acts like a REST. (TIP: You may find music which has long passages of rests for one voice, while the others continue. It is not necessary to code all of these rests. Once R has been executed, the voice will remain off until it is reactivated with one of the note words. This is a great memory and patience saver. The only thing you must be careful of when coding this way is to make sure the rest specified isn't *longer* than the actual rest, since Blazin' Forth will not play any note before its time.)
|
1/32 .1/32 1/16 .1/16 1/8 .1/8 1/4 .1/4 1/2 .1/2 WHOLE TRIPLET TIE
|
These words set the rythmic duration of the note values. Note that you need to set a rythmic value for a particular voice only once - setting other rythmic values for other voices will not affect each other.
|
OC0 OC1 OC2 OC3 OC4 OC5 OC6 OC7
|
These words set the octaves for each voice. Note that, as for the note length values, once an octave has been set for a voice, it remains set for that voice until you specifically change it - specifying a new octave for a different voice will affect only the new voice, not any of the others. A C64 octave extends from C to B, with OC4 C playing a middle C.
|
TEMPO
|
This word sets the tempo and the release time (which is a fraction of the tempo) for each note. The tempo value is stored in MAAZEL, while the amount of time the note spends in its release cycle is stored in REL.TIME. (Note for music hackers: You may tweek the value in REL.TIME after you have set it with TEMPO. For example, if you don't wish the note to be gated off at all, you can store a 0 in REL.TIME, while if you would like the notes in the piece to spend more time in the release cycle, you can increase the value stored here by the system.)
|
TRIANGLE SAWTOOTH PULSE NOISE SYNCH RING
|
These words set the waveform for the current voice. Example:
|
V1 TRIANGLE ( set voice 1 to a triangle wave)
|
*fp0
|
PULSE.WIDTH
|
This word takes a value on the stack, which sets the pulse width for the current voice. (Note that you must have selected the PULSE waveform for this command to have any effect.) This is a number between 0 and 4095. Typing 2048 PULSE.WIDTH will make a square wave.
|
Now that we have covered the basics, here are some examples:
|
MUSIC.ON ( initialize SID and timing routine)
|
100 TEMPO 15 VOLUME ( set tempo and volume)
|
V1 TRIANGLE 0 ATTACK 9 DECAY ( set waveform and envelope for voice 1 )
|
1/4 OC4 ( set quarter notes and octave)
|
C C# D D# E F F# G G# A A# B OC5 C (play a chromatic scale)
|
MUSIC.OFF ( turn everything off)
|
This is the basic form of all music programs in Blazin' Forth. Note that MUSIC.ON is executed before any paramaters are set, and that the tempo, volume, and note lengths are set before any notes are played.
|
Here is a slightly more complex example. You may enter this interactively, or edit it onto a screen.
|
: SETTINGS ( setup to play some Bach)
|
100 TEMPO 15 VOLUME
|
V1 9 SUSTAIN SAWTOOTH ( voice 1 params)
|
V2 9 SUSTAIN SAWTOOTH ( voice 2 params) ;
|
: BACH1 ( two part invention# 1, first measure)
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.