AtariAge Logo Section Icon
  Have You Played Atari Today? 2600|5200|7800|Lynx|Jaguar|Forums|Store  
Title:

System:

Region:

---------------------------------------------------------------------------
BASIC PROGRAMME EXAMPLES FOR ATARI 2600 (BASIC PROGRAMMING & CompuMate).
---------------------------------------------------------------------------
AUTHOR: Graham.J.Percy
EMAIL: gjp57@yahoo.com
PHONE: (61) 03 5978 7198

FAQ Version 1.0, 25th September, 1998.

Copyright (c) 1998 Graham.J.Percy

All rights reserved. This document may be reproduced, in whole or in part,
provided the copyright notice remains intact and no fee is charged.
The data contained herein is provided for informational purposes only.
No warranty is made with regards to the accuracy of the information.

---------------------------------------------------------------------------
INTRODUCTION

Having dabbled in basic programming for some years I was fascinated to
learn that there are two basic programming interpreters available for
use on the Atari 2600. This presents a tantalizing challenge to see what
can be achieved on the 2600.

This FAQ documents the results of several weeks of pondering.

Hope you enjoy!

---------------------------------------------------------------------------
BASIC PROGRAMMES FOR "BASIC PROGRAMMING" Atari CX2620

The simple keypad input using four-colour cursor selection is really
user friendly and you have complete control over which elements are displayed
during programme execution. I love it!
It came as a blow then to discover that there is a tiny sixty-four
character limit to programme size. Economical use of commands is therefore
priority-one. Armed with this knowledge it is still possible to come up
with some new and worthwhile programmes :-)

NOTE:- I have not shown line wrap-around since this does not affect the
way in which the instructions are actually entered. Also, the
convention for showing the left pointing arrow and the divide
sign is as per "BASIC PROGRAMMING" instructions from Greg Chance's
2600 ROM library at http://www.videogames.org Quote:-

" This manual contains numerous uses of a left-arrow symbol. Because
there is no ASCII equivalent, I will use an exclamation point (!)
to represent the left-arrow. Also, wherever the division sign is
used (a - with dots over and below it), I will use a /. "


*************************** SAMPLE PROGRAMME #1 ***************************

BALL AND PADDLE (with two-directional control of paddle)

Use number keypad to control paddle. <4> = Left, <6> = Right
Try to keep the white ball from passing. (Set speed to 60).

1 A!Key
2 Hor1!Hor1 + 10xA - A/Ax50
3 Hor2!Hor2 + 8
4 Ver2!Ver2 - 3
5 If Hit Then Ver2!24
6 Goto 1

NOTE:- the term A/Ax50 in line #2 is used to prevent the graphics dot
from moving when there is no keyboard input.ie. when A=0.
Most other Basic Programming interpreters would return a divide
overflow error in this instance but Basic Programming (2600)
returns a value of 0/0x50 = 0 . This saves adding one more
conditional if-then statement.


*************************** SAMPLE PROGRAMME #2 ***************************

MOVING DOT (demonstration of Four-directional control of graphics dot)

Use number keypad to control the graphics dot.
<4> = Left, <6> = Right, <2> = Up, <8> = Down

1 A!Key
2 If A Mod6=2 Then Goto 5
3 Hor1!Hor1 + 8xA - A/Ax40
4 Goto 1
5 Ver1!Ver1 + 3xA - 15
6 Goto 1


---------------------------------------------------------------------------
BASIC PROGRAMMES FOR THE SPECTRAVIDEO CompuMate

The CompuMate has two built-in programmes, namely a music programme
and a paint programme. These are completely seperate from the text based
interpreter which cannot access music/sound or graphic functions.
Not withstanding this the basic programming function of the CompuMate
allows for a very much larger programme size (2K) and therefore a greater
scope in programming.
There is also the added advantage of being able to save your work
on audio tape at any time.

The manual supplied with the CompuMate provides only an introduction
to the use of basic programming on the CompuMate. (Some of the available
functions are not even mentioned in the manual. eg. Int, Step, <> (does
not equal)). I have therefore experimented with command usage and found
the commands to be far more flexible than the manual suggests.
The sample program "QUEST-A" shows this best.

Anyway, check these out :-)


*************************** SAMPLE PROGRAMME #3 ***************************

NUMBER GUESS

5 LetA=Rnd[19]
10 LetB=A+1
15 IfD<5Goto30
20 Prt"NO MORE GUESSES THE","NUMBER WAS",B,""
25 Goto80
30 Prt"GUESS NUMBR,1 TO 20"
35 InpC
40 LetD=D+1
45 IfC=BGoto75
50 IfC<BGoto65
55 Prt"TOO HIGH",""
60 Goto15
65 Prt"TOO LOW",""
70 Goto15
75 Prt"YES, WELL DONE"
80 Prt"TRY AGAIN"

NOTES:- A = random number 0 to 19
B = random number 1 to 20
C = player's guess at number
D = number of guesses


*************************** SAMPLE PROGRAMME #4 ***************************

SQUARE ROOT

70 Inp"NUMBER",N
71 Rem SET UP PROBLEM
72 IfN=1Goto92
73 IfN>1Goto76
74 LetA=N,B=1
75 Goto78
76 LetA=1,B=N
77 Rem ITERATE TO SOLUTION
78 LetC=[A+B]/2
79 LetD=C*C
80 LetE=D-N
81 PrtC
82 IfE<0.000ThenLetE=-E
83 IfE<.003ThenGoto90
84 IfD<NThenGoto87
85 LetB=C
86 Goto78
87 LetA=C
88 Goto78
89 Rem OUTPUT RESULTS
90 Prt"SQU ROOT OF",N,"=",C
91 Goto93
92 Prt"SQU ROOT OF 1 IS 1"
93 Prt"DONE"

NOTES:-

Syntax of lines 82 & 83 is critical, so enter these as shown.

Programme works for input Numbers from about 0.1 to 100.

N = number for which square root is to be found
A & B = lower & upper limit of search
C = predicted value of root
D = square of C
E = error between square of C and N
(line 82 ensures that E is positive sign)
(line 83 sets the accuracy with which to find the root)



*************************** SAMPLE PROGRAMME #5 ***************************

QUEST-A

1 LetQ$="+---------+"
2 PrtQ$," QUEST-A",Q$," BY"
3 Prt"GRAHAM PERCY","1=PLAY"
4 InpC
5 LetR$="[ ]"
6 LetS$="+--- ---+"
7 LetT$=" ]"
9 LetV$="+---+-+---+"
10 LetW$="[ O++ ]"
11 LetY$="1=DN 2=RGHT"
12 PrtS$,R$,R$,T$,R$,Q$
13 Prt"A BIG ROOM","1=LEFT 2=UP"
14 Inp"ACTION=",B
15 IfB=1ThenGoto32
16 IfB<>2ThenGoto14
18 IfK<>1ThenPrtQ$,W$
20 IfK=1ThenPrtQ$,R$
21 PrtT$,R$,S$,"LONG HALL"
23 Prt"1=LEFT 2=DN"
24 IfK<>1ThenPrt"3=GET KEY"
25 Inp"ACTION=",B
26 IfB=2ThenGoto12
27 IfB=1ThenGoto48
28 IfB<>3ThenGoto25
29 IfK=0ThenPrt"YOU GOT KEY"
30 LetK=1
31 Goto18
32 PrtS$,R$,"[",Q$,"A DARK HALL"
33 IfP=1ThenGoto38
34 LetG=Rnd[2],F=Rnd[3]
35 IfG<>2ThenGoto38
36 Prt"OGRE HERE","1=UP 2=RGHT","3=FIGHT"
37 Goto39
38 Prt"1=UP 2=RGHT"
39 Inp"ACTION=",B
40 IfB=3ThenIfG=2ThenIfF=3ThenGoto96
41 IfB=2ThenGoto12
42 IfB=1ThenGoto48
43 IfB<>3ThenGoto39
44 Prt"GOT THE OGREGOT ARMOUR"
45 LetP=1
46 Goto32
48 IfD=1ThenIfE=3ThenGoto70
49 IfD=0ThenIfE=3ThenGoto77
50 PrtV$,R$,"[",R$,S$
51 Prt"TROLL, DOOR",Y$,"3=OPN 4=FGT"
52 Inp"ACTION=",B
53 IfB=1ThenGoto32
54 IfB=2ThenGoto18
55 IfB=3ThenIfK=1ThenGoto60
56 IfB=3ThenPrt"NEED A KEY"
57 IfB=4ThenGos88
59 Goto48
60 Prt"TROL SAY NO"
61 Goto48
70 PrtS$,R$,"[",R$,S$,"OPEN DOOR",Y$,"3=UP"
71 Inp"ACTION=",B
72 IfB=1ThenGoto32
73 IfB=2ThenGoto18
74 IfB<>3ThenGoto71
75 Prt"* * *"," *","",R$,R$,S$,"YOU,RE FREE"
76 Goto97
77 PrtV$,R$,"[",R$,S$,"A DOOR",Y$,"3=OPEN DOOR"
79 Inp"ACTION=",B
80 IfB=1ThenGoto32
81 IfB=2ThenGoto18
82 IfB=3ThenIfK=1ThenGoto85
83 IfB=3ThenPrt"NEED A KEY"
84 Goto79
85 Prt"YOU OPEN IT"
86 LetD=1
87 Goto70
88 IfP=0ThenLetF=Rnd[1],E=E+1
89 IfP=1ThenLetF=Rnd[14],E=E+1
90 Prt"YOU ATTACK,"
91 IfF=0ThenGoto96
92 IfE=3ThenPrt"GOT HIM"
93 Rtn
96 Prt"HE GOT YOU"
97 Prt"BYE"


NOTES:-

Add one more line to the above programme and you will get an ERR 2 message
(programme too big).

Character variables are assigned fixed values and are then used to help with
text style graphics! Wow! :o)

Number variables are used to control programme flow.

B is used to nominate an action by the player
K = 1 when you have the key
P = 1 when you have killed the ogre and have gained armour
D = 1 after you open the door
E is the damage inflicted on the troll, he dies when E = 3

Also, random numbers are generated for a little unpredictability.

G is used to determine the ogre's presence
F decides who will win a fight with the ogre or troll
(when you have the armour, your chances against the
troll are much better)

---------------------------------------------------------------------------
There must be plenty of programmers out there who have programmes of their
own for BASIC PROGRAMMING or CompuMate, so how about emailing them to me
for inclusion in this FAQ. (With due credit of course). I also invite any
comments you might otherwise have regarding this FAQ.

Happy gaming! GP
---------------------------------------------------------------------------
AtariAge - basic programming and compumate