Vintage Computing
column/row coordinates to Propeller main memory values
you can use in your Color BASIC programs:
Cell Content = BYTE [2931 - Y* 50 - X]
Foreground Color = BYTE [21449 + 2*X + 100*Y] SHR 2
Background Color = BYTE [21448 + 2*X + 100*Y] SHR 2
Note that while cell content memory contains the
whole eight-bit byte representing the character in that cell,
foreground or background color information in the palette
cells is contained in bits 2 through 7. So, you have to do
some bit shifting when you read or write a color value.
Without getting too much into the weeds, the palette
cells for each screen location are consecutive, and each
contains the VGA red, green, and blue levels in bits 7.. 6,
5.. 4, and 3.. 2, respectively. Bits 1..0 are reserved for
horizontal and vertical sync of the video signal and are
provided by the PASM module in the Color BASIC code
that manages the VGA interface. So, we have to shift the
six color bits two bits left to write our desired color to the
palette cells, and two bits to the right to read a color value
from them.
FIGURE 5: Cool trick: You can read and write to video
memory with the BYTE command.
10 REM —- SCRN-RW.BAS —-
15 COLOR 63,22
20 CLS
25 LOCATE 8,0: PRINT “Reading / Writing the
Amigo Screen”
30 LOCATE 2,2: INPUT “Screen Cell Coordinates
(X,Y)? “;x,y
35 IF x>49 THEN x=49
40 IF y>36 THEN y=36
45 LOCATE 2,4: INPUT “Content, Foreground,
Background? “;c,f,b
50 LOCATE 2,6: PRINT “Writing to Screen...”
55 PAUSE 1000
60 BYTE [2931-50*y-x] = c
65 PAUSE 1000
70 BYTE [21449+2*x+100*y] = f SHL 2
75 PAUSE 1000
80 BYTE [21448+2*x+100*y] = b SHL 2
85 LOCATE 2,8: PRINT “Reading from Screen...”
90 LOCATE 4,10: PRINT “c = “;BYTE [2931-50*y-x]
95 LOCATE 4,11: PRINT “f = “;BYTE
[21449+2*x+100*y] SHR 2
100 LOCATE 4,12: PRINT “b = “;BYTE
[21448+2*x+100*y] SHR 2
105 LOCATE 2,16: PRINT “Again (Y/N)?”
110 k=INKEY : IF k=0 THEN GOTO 110
115 IF k<>”N””AND k<>”n””THEN GOTO 20
120 LOCATE 2,18: PRINT “Bye!”
125 END
Here’s a code snippet that demonstrates this trick. It’s
fairly straightforward, and shows how to use the address
formulas above to move bytes to and from screen
memory. You can copy this code ( SCRN-RW.BAS) from
the downloads.
Controlling Hardware Counters
Figure 5 shows one example of this little program at
work. I hope you find this capability helpful!
Next, let’s look at the capability of your Amigo to
control the hardware counters on one cog of the amazing
Propeller chip. You may recall that the Propeller consists
of eight identical processors (cogs), and Color BASIC uses
those to provide a tinyBASIC interpreter and manage all
the I/O of your Amigo: keyboard, monitor, SD card, audio,
and so forth.
You may also recall that one of the key features of the
Propeller is that each of the eight cogs contains two
independent hardware counters — configurable state
machines that can generate or sense signals as often as
every clock cycle.
You can configure these programmable hardware
counters with Spin or PASM for 32 different modes of
operation, and they will continue operating in that
configuration without further software interaction or
overhead.
This is a hugely powerful capability, and the “big
brains” who created Color BASIC had the wisdom to
include access to two of these counters in your Color
BASIC toolkit. That means you can create a wide variety
of useful hardware projects with little or no actual
hardware on the Amigo breadboard.
A detailed explanation of these counters is beyond
the scope of this article, which intends just to introduce
Color BASIC commands that were not listed in the original
Mentor’s Friend documentation. We can do that
July/August 2018 53