Classic Computer Magazine Archive ANTIC VOL. 5, NO. 9 / JANUARY 1987

Door Prize

Automated raffle picks

BY BILL MAROUARDT, ANTIC TECHNICAL ASSISTANT

Door Prize screen

Winning raffle numbers are picked and displayed by the Door Prize program. It's "just the ticket" for Atari users group meetings which hold monthly raffles. There's even an optional speech listing that announces the winners, when used with the Talking Typewriter speech circuit described in this issue. The BASIC program works on all 8-bit Atari computers of any memory size, with disk or cassette.

Door Prize automatically picks a random four-digit number and places it on your video screen in an eye-catching display. I was struck by the need for this kind of program because I regularly attend various Atari users group meetings that hold monthly raffles.

At one such meeting a member hurriedly typed in a BASIC program to generate random numbers, which finally worked after a few crashes. More often, someone would simply write out duplicate tickets and draw the winning numbers from a box- accompanied by typical good-natured audience comments casting doubt on the integrity of the person doing the drawing. User group meetings usually set up several computers with monitors facing the group, so why not use the Atari to do one of the things it does best?

And if you build the Talking Typewriter speech circuit described elsewhere in this issue, Door Prize's Listing 2 will enable your Atari to announce the winning number through the monitor or TV speaker, one digit at a time.

HOW IT WORKS

The Door Prize program is essentially a random number generator, using the built in BASIC RND function. The screen is in Graphics Mode 3+16 (ANTIC Mode 8). A small change in the display list allows two sizes of text to be displayed on what would normally be a graphics only screen. This minor miracle is accomplished in lines 320-336. Line 340 calculates the starting address of the screen display and sets the value in W. Next, we display the title. Lines 350-369 will read the three strings contained in the DATA statements at lines 366-369 and POKE the correct screen byte values into screen memory.

Player/Missile graphics are used for displaying the winning number large enough to be seen at a distance. To do this, we must first copy your Atari's built-in character set into Player/Missile memory. Every character in the Atari character set is defined by a series of eight bytes. Line 800 finds the starting address of the character table and adds 128 to this value. The resulting address contains the first byte of the first number in the character set- zero (0).

Each successive character starts eight bytes higher than the last. Once we know which digit we want to display, all we have to do is calculate that digit's position in the character set and copy each of its eight bytes into the Player/Missile memory. Along the way, we subtract each value from 255 to display the digit in inverse video. This technique is demonstrated in lines 403-421.

For more detailed understanding of all these procedures, read Atari Graphics and Arcade Game Design a 478-page book by Jeffrey Stanton with Dan Pinal. ($12.95, The Catalog, MG0103.)

When the program is RUN, you are asked for the lowest and highest possible winning ticket numbers. Any number between 0 and 9999 is acceptable for either entry-as long as the high number is higher than the low number. Door Prize will then continue to generate random winning numbers every time you press a key on the Atari keyboard or the joystick button. The program has been optimized for speed by eliminating the possibility of choosing random numbers that are out of range.

Because of the varied rules for raffles, I chose not to check for repeated winning numbers. Unless you are running a drawing with very few entrants, this should not be a problem. The program could be easily modified to add this feature by DIMensioning an array to hold the maximum number of draws, filling the array with an impossible number such as -1, and then checking the chosen random number against each element of the array before it is accepted as the winning number. Once chosen, the number would be placed into the array. Use an index variable to point to the -next "open" array element.

Other variations of this program come to mind, particularly if you add the speech module. How about an audible dice thrower?

TYPING IT IN

To use Door Prize, type in Listing 1, DOORPRIZ.BAS, check it with TYPO II and SAVE a copy before you RUN it.

If you want to add the speech programming lines that work with this issue's Talking Typewriter speech circuit project, type in Listing 2 and check it with TYPO II. LIST a copy to disk or cassette. Next, LOAD Listing 1 and then ENTER Listing 2. Remember to SAVE the combined program before you RUN it. Antic Disk owners will find the talking version of the program on the monthly disk under the filename DOORPRIZ.TLK.

Listing 1: DOORPRIZ.BAS Download

Listing 2: DOORPRIZ.TLK Download