Atari Basic Programming
The following programming will teach you some simple concepts of Atari Basic programming that don’t get too advanced. The program “Losing Lottery” is meant to be funny since you have to enter 8 numbers that must match the computers randomly generated 8 numbers.
This is an impossible feat, but pokes fun at the lottery which plays a similar game.
When learning to program you will first need to understand instructions that the computer can use to build upon.
Some of the common things covered by this simple Atari Basic Programming task is initializing arrays, utilizing loops, prompt the user for a respond, and using a subroutine to communicate tasks that are used more than once.
Atari Basic Programming
Each line will be evaluated in sections. First we will initialize multiple arrays used by the program. The explanation is listed here:
TICKET() – Is used by the computer to generate 8 different numbers that will be compared against the tickets drawn.
CHOICE() – The prompt (variable) that handles the 8 numbers chosen by the user.
GUESS() – This variable will save selected numbers entered by a user
MATCH() – This data will save the results of any matching numbers that were selected by the user.
The program first sets up 4 arrays (TICKET, CHOICE,GUESS, and MATCH.
15 DIM TICKET(10),GUESS(10),MATCH(15)
Atari Basic Loop
After the arrays are setup for this Atari Basic Programming example, the screen is cleared (GRAPHICS 0) and the screen color is set to dark green.
Next a loop stores 8 random numbers (LOTTERY) into an array (TICKET)
20 GRAPHICS 0: POKE 710,160
30 FOR A=1 TO 8
40 LOTTERY=INT(RND(0)*8)+1
50 TICKET(A)=LOTTERY
60 NEXT A
The next step is to compare the tickets generated to a jackpot of numbers entered by the user.
First the screen is cleared. Then 8 numbers are entered at the prompt (using INPUT) and the results are saved in the array (GUESS).
If the value entered (CHOICE) is less then 1 or greater than 8 then the line jumps to the subroutine at line 300. The program is directed back to line 100 to force a different number choice from the user.
The entered choices are saved in an array (GUESS).
70 REM COMPARE TICKET TO JACKPOT
75 PRINT CHR$(125)
80 FOR E=1 TO 8
90 PRINT: PRINT “ENTER A NUMBER BETWEEN 1-8”
100 INPUT CHOICE: IF CHOICE<1 THEN GOSUB 300:GOTO 75
110 REM
120 GUESS(E)=CHOICE
130 NEXT E
At line 300 a bell is rang (accessing the ASCII character 253). Next the cursor is turned off by placed a one in register 752.
The message “INVALID CHOICE! TRY AGAIN!” is displayed. After this a loop waits, the cursor is returned, and a RETURN exists this subroutine.
300 PRINT CHR$(253): POKE 752,1
305 PRINT”INAVLID CHOICE! TRY AGAIN!”
310 FOR W=1 TO 250:NEXT W:POKE 752,0
320 RETURN
Finally it is time to compare the Atari Basic Programming example results to see if we have a winner.
First we jump to a subroutine at line 400 that clears data contained in the MATCH array and returns back. This was done since I was receiving strange exponential numbers here.
400 FOR T=1 TO 8:MATCH(T)=0:NEXT T
410 RETURN
Now we setup a loop that counts from 1 though 8. This ticket Atari Basic compares the results saved in the TICKET array to what was stored in the GUESS array.
If a match is found a variable (MT) is increased to store accumulated results in the MATCH array.
150 FOR A=1 TO 8
160 IF TICKET(A)=GUESS(A) THEN MT=MT+1:MATCH(MT)=TICKET(A)
170 NEXT A
Then our Atari Basic Programming results display “FINISHED. RESULTS ARE IN. MATCHES SHOW AS…”
Next a loop counts from 1 through 8 and the finalized results are printed from the array (MATCH).
180 PRINT “FINISHED. RESULTS ARE IN. MATCHES SHOW AS…”
190 FOR A=1 TO 8
200 PRINT MATCH(A);”,”;
210 NEXT A
Now the Atari program displays “THANK YOU FOR PLAYING THE LOSING LOTTERY TODAY. HAVE A GREAT DAY!”
If the user did not get all 8 entries matched the computer correctly, the message prints as “I’M SORRY YOU LOST TODAY. THANK YOU FOR YOUR PATRONAGE THOUGH!”
Finally the program ends and that completes our example.
215 PRINT
220 PRINT “THANK YOU FOR PLAYING THE LOSING LOTTERY TODAY. HAVE A GREAT DAY!”
225 IF MT<9 THEN PRINT “I’M SORRY YOU LOST TODAY. THANK YOU FOR YOUR PATRONAGE THOUGH!”
230 END
Now the Atari program displays “THANK YOU FOR PLAYING THE LOSING LOTTERY TODAY. HAVE A GREAT DAY!”
If the user did not get all 8 entries matched the computer correctly, the message prints as “I’M SORRY YOU LOST TODAY. THANK YOU FOR YOUR PATRONAGE THOUGH!”
Finally the program ends and that completes our example.
The program first sets up 4 arrays (TICKET, CHOICE,GUESS, and MATCH.