Vintage Computing
140 L=INKEY
145 IF L=0 THEN GOTO 140
150 IF L=”Y””OR L=”y””THEN GOTO 20
155 IF L<>”N””AND L<>”n””THEN GOTO 140
160 LOCATE 2,26: PRINT “Bye!”
199 END
200 REM —- Save 32-Bit Integer —-
205 REM ... Expects Address in a, Integer in n
210 FOR i=0 TO 3
215 POKE a+i, n SHR (8*i)
220 NEXT i
230 RETURN
300 REM —- Retrieve 32-Bit Integer —-
305 REM ... Expects Address a, Returns Integer n
310 n=0
315 FOR i=a+3 TO a STEP -1
320 n=n SHL 8 + PEEK i
325 NEXT i
330 RETURN
400 REM —- Save a String —-
405 REM ... Address in a, String Start in x,y
410 s=2931-y*50-x REM <——Memory location of x,y
415 t=BYTE [s]
420 POKE a,t
425 a=a+1: s=s-1
430 IF t<>5 THEN GOTO 415
435 RETURN
500 REM —- Retrieve a String —-
505 REM ... Address in a, ASCII 5 as Terminator
510 t=PEEK a
515 IF t=5 THEN RETURN
520 DISPLAY t
525 a=a+1
530 GOTO 510
terminator, and it seems to work just fine.
• Lines 200-230 save the 32-bit integer n to SRAM, with
the least significant byte starting at address a. In each
iteration of the FOR/NEXT loop, the next eight-bit byte of
n is moved to bits 0-7 of the expression n SHR ( 8*i).
These bits are then poked into the next SRAM address.
• Lines 300-330 retrieve a 32-bit integer n from SRAM,
starting with the most significant of the four bytes stored
at SRAM address a+ 3. Line 320 uses the SHL operator to
move each byte to the left in each iteration of the
FOR/NEXT loop.
• Lines 400-435 copy a string of characters from the
screen location starting at column/row coordinates x,y to
SRAM, beginning at address a. I used ASCII character 5 as
the string terminator, but you can use any character that
prints in the next screen location.
The “secret sauce” of this approach is the formula in
Line 410, which maps the x,y coordinates of a cell on the
Amigo display to its location in Propeller main memory,
where its contents are available using the BYTE command.
(More on this trick shortly.)
So, 2931 is the top left corner of the screen; 2930 is
one cell to the right; 1082 is the bottom right corner; and
so forth.
Line 410 places the starting point of the string (passed
to the subroutine in x,y) in s, then Lines 415-430 get the
character at that location; POKE it to SRAM; increment
the SRAM address and move to the next screen memory
location; and repeat the process until the string terminator
(ASCII 5) is found.
Here’s what going on with this code:
• Lines 500-530 retrieve a string of characters from SRAM
starting at address a and place them on the screen,
starting at the current cursor location and placing
characters until a string terminator is found. Again, ASCII 5
is used as the string terminator, but in this case, it is not
printed on the screen.
• Lines 10-199 provide the body of this little program,
handling the user interface and calling subroutines to store
and retrieve 32-bit integers and strings. Only two items
here may need some explanation.
Our explanation of saving strings to SRAM touched
on direct access to Amigo screen memory, so let’s discuss
that useful trick next.
First, x and y in Line 50 save the column/row
coordinates of the first letter of the string being input.
(We’ll use a trick to get the string characters from screen
memory, and we’ll need these coordinates to do that.)
Second, Lines 55-70 place keystroke characters on the
screen, parsing them to exclude non-printable characters
Color BASIC uses over 5K of the 32K Propeller main
memory to support the 50x37 character video display,
with three bytes of memory dedicated to each character
cell. These three bytes provide character, foreground color,
and background color information about that specific cell
of the display, and their position on the memory map
doesn’t change with a given Color BASIC binary.
(Line 70), provide a backspace capability (Line 65), and
identify the end-of-string (Line 60).
Note ASCII 13 <Enter> is used to stop placing
characters on the screen. You can’t use it as the string
terminator because it jumps to the beginning of the next
line on the screen, and we need to use contiguous cells in
screen memory for SRAM input.
In other words, as long as you’re running the Color
BASIC 2.2L that ships with the Amigo, the screen memory
map remains constant regardless of what your program or
your onboard experiment is doing.
I used the ASCII 5 graphics character as the string
With a little detective work, it’s possible to discover
this memory map and then use the BYTE command to
read from or write to screen memory directly. Here are
the formulas you can use to convert screen XY
52 July/August 2018