Back to MrGibson.com | | Back to Tandy CoCo page


Tandy CoCo BASIC

This manual is for Extended Color BASIC 1.0, 1.1, 1.3




ABS (numeric) - Computes absolute value Example: 100 V = ABS(5)
ASC (str) - Returns ASCII code of first charactr of specifed string. Example: 100 A = ASC( T$ )
ATN (numeric) - Returns arctangent in radians. Example 100 Y = ATN(X/3)
CHR$(n) - used to find character from ASCII code. Below is a partial table printed on the Tandy (32 being a space): CHR$ can also be used to print graphic characters in default text/semigraphics mode. This is also set with the command PMODE 0,[X] . Starting at 128 are the Graphic Blocks Colors for Coco 2 with Extended Color BASIC 1.x
  128 - 143 is Green and Black blocks     143 = Green solid block
  144 - 159 is Yellow and Black blocks    159 = Yellow solid block
  160 - 175 is Blue and Black blocks      175 = Blue solid block
  176 - 191 is Red and Black blocks       191 = Red solid Block
  192 - 207 is Buff and Black             207 = Buff (white-ish) solid block
  208 - 223 is Cyan and Black             223 = Cyan solid block
  224 - 239 is Magenta and Black          239 = Magenta solid Block
  240 - 255 is Orange and Black           255 = Orage solid block
  

CLS c – Clears text screen, optionally filling it with a color (0-8). CLS c Clears display to specified color c. If color is not specified, green is used. 0-Black 1-Green 2-Yellow 3-Blue 4-Red 5-Buff (white-ish) 6-Cyan 7-Magenta 8-Orange Example: CLS 7 Note: This is the clear screen command for text mode. For graphics mode use PCLS
COLOR (forground,background) - Sets forground and background color. Example: COLOR 1, 3
CONT - Continues program execution after pressing or (break) useing STOP statement
DRAW "string" - Draws a line beginning at specified starting point of specified length of specified color. Will also draw to scale, draw blank lines, draw non-updated lines, and execute substrings. If starting point in not specified, the last DRAW position or default of (128,96) is used. Example1: 40 DRAW "U20R20D20L20" the example will draw a box Example2: 40 DRAW "BM100,100;S10;U25;BR25;ND25,XA$;" Movement Commands The DRAW command uses specific character codes to determine direction and movement: Un: Up Dn: Down Ln: Left Rn: Right En: Diagonal Up/Right Fn: Diagonal Down/Right Gn: Diagonal Down/Left Hn: Diagonal Up/Left "n" represents the number of pixels to move. For example, DRAW "U10 R5" moves the cursor 10 pixels up and then 5 pixels right. Special Control Commands M x,y: Move to absolute coordinate (x,y) or relative (+x,+y) if a + or - sign is used. B: Move without drawing (Blank). E.g., DRAW "BU10" moves up 10 pixels without plotting them. Like with the U and other movement commands, B and M can be combined as for example: DRAW "BM100,100" N: Move and draw, but return to the original position afterward (No-update). For example, drawing down for 25: DRAW "ND25" Cn: Set color (n = 0-3 for CoCo 1 and 2, or higher with CoCo 3 palettes). Sn: Set scale factor (n). Default is 4. Scale 1 is smallest, 255 is largest. An: Set angle (n = 0, 1, 2, 3). 0=0°, 1=90°, 2=180°, 3=270°.
END - Ends execution of BASIC code.
FOR and NEXT and optional STEP - Create a stepped loop Example: 10 FOR I = 1 TO 10 20 PRINT I 30 NEXT I To print every other number use the STEP Example2: 10 FOR I = 1 TO 10 STEP 2 20 PRINT I 30 NEXT I
GOSUB line-number - Calls a subroutine beginning at specified line number. Example: GOSUB 500
GOTO line-number - Jumps to a specified line number. Example: 10 GOTO 300
IF and THEN and optional ELSE - check values for condtions Example 1: 10 IF A=5 THEN 30 will jump to line 30 if the value of A is 5. Example 2: 10 IF A>B THEN 100 will jump to line 100 if the value of A is greater than the value of B Example 3: 100 IF X=10 THEN PRINT "YES" ELSE PRINT "NO"
INPUT var - Takes input from keyboard Example 1: 10 INPUT A$ This will read and store a string from the keyboard 10 INPUT D This will read and store a number from the keyboard
MEM - Finds the amount of free memory. Example: PRINT MEM
MID$ (str,pos,length) - Returns a substring of another string starting at pos. If lenght is omitted, the entire string right of position is returned. Example: 100 F$ = MID$( A$, 3) Example2: PRINT MID$(A$, 3, 2)
PCLS - graphic clear screen see PMODE
PEEK looks at a memory address Example Command: PRINT PEEK(116)*256 + PEEK(117) + 2 ; "BYTES" Result: Shows how much RAM the computer has, but a 64K machine will appear to be a 32K machine (32768 Bytes) because Basic only uses the first 32K of RAM in a 64K machine. Result: Returns maximum memory in System.
PLAY "string" PLAY "note" PlAY "length;note" PLAY "volume;note" MUSICAL NOTE/NUMBER Number Note 1 C 2 C#/D 3 D 4 E-/D# 5 E/F 6 F/E# 7 F#/G 8 G 9 G#/A 10 A 11 A#/B 12 B Note: PLAY does not recognize the notation B# or C-. Play A note: PLAY "A" Add another note: PLAY "A;A#" Add pause PLAY "A;P2;A#" Change Volume PLAY "V5;A;P2; V10;A;P2; V30;A;P2" Change Note Length PLAY "L2;A;L4;A;A;L2;A;A"
PMODE number,number - Set graphic mode The first number is the mode number, the second number is the start page. PMODE and POKE are used to change video graphic modes. CoCo 1 and CoCo 2 Motorola 6847 VIDEO DISPLAY GENERATOR (VDG) offers Full Graphic Modes resolution in densities of: Mode POKE Resolution TYPE Colors Screens Byte Detail PMODE 4 high RG6 2 2 256x192 (2 colors or 4 artifact colors*) PMODE 3 medium CG6 4 2 128x192 (4 colors) PMODE 2 medium RG3 2 4 128x192 (2 colors or 4 artifact colors*) PMODE 1 low CG3 4 4 128x96 (4 colors) X SG24 9 64x192 (9 colors) X low SG12 9 64x96 (9 colors) X low SG6 9 2x3 64×48 (9 colors) PMODE 0 low SG4 2/9 8 2x2 64x32 (9 colors grx and 2 colors text) (text is 32 cols x 16 lines ) * Artifact colors work on composite video displays and RF displays. They don't work with S-Video. With S-Video, there will only be 2 colors. Use the SCREEN command to choose the color palette of the mode. Example: 10 PMODE 4,1:SCREEN 1,1 'Set graphics mode 20 PCLS 0 'Clear screen NOTE: Something better than these 5 Microsoft defined modes (PMODE). PMODE 0 is the same as Semigraphics-4 mode or SG4 There are three modes not defined with the PMODE command: - Semigraphics-6 mode or SG6 - Semigraphics-12 mode or SG12 - Semigraphics-24 mode or SG24 Like SG4, SG6, SG12 and SG24 can also use all colors available. Semigraphics-24 mode (SG24) is basically a 64x192 character screen with the 9 colors in a 4 on and 4 off pattern - giving the user a 64x192. This mode is like crossing PMODE 0 and PMODE 4. Example image created in the SG24 mode. Semigraphics-24 (or SG24) is a "hybrid" display mode that combines text and graphics modes to achieve a unique 9-color display that is much better than the PMODE 0 9-color display. Key Technical Details Mechanism: It works by tricking the Motorola 6847 Video Display Generator (VDG). By setting the Synchronous Address Multiplexer (SAM) to a high-resolution graphics mode while leaving the VDG in an alphanumeric/semigraphics mode, the screen is subdivided into smaller "slices". Resolution: It provides a 64×192 effective resolution. In this mode, each 8×12 pixel character box is split into six vertically stacked blocks, each 4×2 pixels in size. Color Palette: It allows the use of all 9 available colors (green, yellow, blue, red, buff, cyan, magenta, orange, and black) simultaneously on one screen. Memory Usage: A full Semigraphics-24 screen consumes 6,144 bytes of RAM. Example code to enable the SG24 mode: 10 CLS 20 POKE &HFF22,0 : REM RESET VDG TO SEMIGRAPHICS ZERO IS SG MODE 30 POKE &HFFC3,1 : REM SET SAM TO GRAPHICS MODE (GM1) = 1 40 POKE &HFFC5,1 : REM SET SAM TO GRAPHICS MODE (GM2) = 1 50 POKE &HFFC0,0 : REM ENSURE SAM RESOLUTION BIT 0 IS LOW (GM0) 55 REM is set for CG6 Mode while still in SG mode Example code to enable the SG12 mode 10 CLS 20 POKE &HFF22,0 : REM RESET VDG TO SEMIGRAPHICS ZERO IS SG MODE 30 POKE &HFFC3,0 : REM SET SAM TO GRAPHIC MODE (GM1) = 0 40 POKE &HFFC5,0 : REM SET SAM TO GRAPHIC MODE (GM2) = 0 50 POKE &HFFC7,0 : REM ENSURE VDG IS IN ALPHANUMERIC MODE - Note on POKEs and what they are for (see table 1 above): POKE &HFF22,0 Resets the VDG to SEMIGRAPHICS - ZERO is SG Mode POKE &HFFC0,0 V0 clear POKE &HFFC1,0/1 V0 Set to 0 or 1 POKE &HFFC2,0 V1 clear POKE &HFFC3,0/1 V1 Set to 0 or 1 POKE &HFFC4,0 v2 clear POKE &HFFC5,0/1 V2 Set to 0 or 1
POKE (location, value) - Puts value (0-255) into specified memory location. Example: POKE 25,6:POKE 26,1:POKE 1536,0:NEW Makes maximum memory available for basic programs. Any basic program in memory is cleared. Not compatible with disk systems. Does not allow the use of graphics. Example Command2: POKE 280,PEEK(275) Result: Helps COCO Generate 'TRUE' Random Numbers. Remarks: Same as the Ext. Basic Statement X = RND(-TIMER).
PRESET(number,number) - Reset a point to background color. Example: PRESET (5,6)
PRINT - Prints specified message or number to screen. Example: PRINT "HI THERE" The print command can be substitued with the ? Example2: ? "Hi THERE" The PRINT command can concatenate with the ; Example 3: 100 X=5 110 PRINT "THE VALUE IS ";X Example 3 will print THE VALUE IS 5 Example 4: 100 PRINT "HELLO "; 110 PRINT "THERE" Example 4 will print HELLO THERE Using the @ with print will allow placement at a location Example 5: 100 PRINT @5,"WELCOME!" Will print WELCOME at row 1 and column 5 on the screen. Example 6: 100 PRINT USING "###",NUM Will format a number 3 places right justified. Great for columns that need alocated space so not to alter text or graphics around the number.
REM - Non executed comment or a remark usually for documenting purpose. Example: 100 REM THIS LINE DOES NOTHING
RETURN - Used to return to the place of the GOSUB
RND - Creates a random number Example: RND(0) Returns a random floating-point number between 0 and 0.99999999999999. Example 2: 10 X = RND(-TIMER) :REM Seed the generator 20 FOR I = 1 TO 10 30 PRINT RND(10); :REM Print 10 random numbers between 1-10 40 NEXT I
SCREEN n1,n2 n1 = is the screen n2 = is the color set Both depending on PMODE *see PMODE command 2-Color 4-Color SCREEN 1,0 Black/Green Green/Yellow/Blue/Red SCREEN 1,1 Black/Buff Buff/Cyan/Magenta/Orange
SGN (numeric) - Returns sign of specified numeric expression
SIN (numeric) - Returns sine af angle gleen in radians
SOUND tone, duration tone can be 1 to 255 duration can be 1 to 255 Example: 10 PRINT "TO MAKE ME CHANGE MY TONE" 20 PRINT "TYPE IN A NUMBER FROM 1 TO 255" 30 INPUT T 40 SOUND T, 50 50 GOTO 10 The example will play the tone of the number entered between 1 and 255 SOUND 1,2 = 1 is lowest octive SOUND 39,2 = is Middle C SOUND 120,2 = is C SOUND 255,2 = 255 is hight octive
STRINGS (length, code or string) - Returns a string of characters (of specified length) specified by ASCll code or by the first character of the string.
SQR (numeric) - Square root of a number Example: Y=SQR(5+2)