PRINT ASC “A”
PRINT ASC “<backspace>”
PRINT ASC “<F6>”
PRINT ASC “<left arrow>”
how it works, but my comments just made things more
confusing. Here’s what’s going on, line by line:
• Line 10 sets the Propeller I/O pin we’ll be using to 24,
which is the left channel of the Amigo audio section.
• Line 15 sets the direction of our audio pin to output,
but for now masks the output with a 1. In the Propeller
chip, a cog counter output bit is OR’d with the
corresponding bit of the output register, and AND’d with
the corresponding bit of the direction register.
So, OUTA[p]=1 sets both output and direction
registers to 1, creating a masked output on the pin. We’ll
use OUTA[p]=0 to unmask the counter output pin in Line
The FILE command can be used on either side of the
“equals sign” assignment operator to read or write the
next byte of the currently open file. The code that follows
(available to download) creates the file TEST.DAT on the
SD card and then uses FILE to write the alphabet to it. It
then reopens the file and uses FILE to read and print bytes
until it finds the end of file.
• Line 20 sets the value-to-add register to 24365, which
for the Amigo is the FRQx for 130.8 Hz (one octave
below middle C). From the Parallax application note (you
really should take a look at it!), the NCO frequency is
Note that Color BASIC adds a -1 as the end-of-file
character on file closure, and that on opening, FILE points
to the first record of the file.
fhz = FRQx / 232 x System Frequency
for values of FRQx between 0 and $8000_0000. For the
Amigo, with its 80 MHz clock, this arithmetic simplifies to
FRQx = 186.26 fhz. So, middle C (261.6 Hz) is FRQx =
48730; A4 (440 Hz) is FRQx = 81954; and so forth.
• Line 25 left shifts the value for Single-Ended NCO mode
(%00100) into the C TRMODE field of C TRA and then
adds 24 into the APIN field. The PLLDIV and BPIN fields
are not used in this counter mode of operation.
At this point, the counter is now operating, but the
output is being masked by the 1 we placed in the output
register in Line 15.
5 REM —- FILE.BAS —-
15 OPEN “test.dat”,W
20 PRINT “Writing alphabet to TEST.DAT...”
25 FOR n=65 TO 90
30 FILE = n
35 NEXT n
40 PRINT “Closing file...”
50 DISPLAY 13,13: PRINT “Press a key to
55 IF INKEY =0 THEN GOTO 55
60 DISPLAY 13,13: PRINT “Reading data from
65 OPEN “test.dat”,R
• Line 30 places a 0 in the output register for pin 24,
unmasking the APIN output from the counter and
applying it to the Amigo left audio channel.
Command Action Performed
ASC “n” Returns the ASCII value of the single character enclosed in quotes.
• Line 35 lets the counter run, applying a steady tone to
the audio channel until you press a key.
Reads or writes the next byte in the
currently open file on the SD card.
• Lines 40-55 adjust FRQA to slide the tone up an octave,
then hold it there for one second.
VARIABLE = FILE reads a byte from a file
open in the Read mode. FILE =
• Line 60 turns the counter off.
<expression> writes a byte to a file in the
Write or Append mode.
With our introduction of the counter commands
complete, let’s finish up the remaining Color BASIC
commands that were not covered in the initial Mentor’s
Friend documentation. These are summarized in Figure 8,
and we’ll briefly cover each with an example.
Like the BYTE command, but with a 16-bit
value. Reads or writes a 16-bit value to the
Amigo main memory address specified,
where nnnnn is between 0 and 32767. The
command can be used on either side of
the “equals sign” assignment operator,
and the least significant bit of the address
The ASC command is a convenient way to find the
ASCII code of a character or key on the keyboard. To
demonstrate this, type in the commands below, entering
Like the WORD command, but with a 32-
bit value. The least significant two bits of
the address nnnnn are ignored.
CNT Reads (only) the value of the Propeller system counter register.
FIGURE 8: The remaining “missing” commands. An
updated list of all Color BASIC 2.2L commands is
available in the downloads for this article.
July/August 2018 55