Classic Computer Magazine Archive COMPUTE! ISSUE 53 / OCTOBER 1984 / PAGE 90

The Number Game

Lou Tylee

Software for children often benefits from large display characters and numbers. Here's a method for creating big numbers on the TI-99/4A, with a simple example program—a number recognition game which uses the larger digits. Includes versions for Commodore VIC and 64, Atari, Apple, IBM PC/PCjr, and the Color Computer.

The built-in number characters on the Texas Instruments 99/4A Home Computer are too small to really grab a child's attention. Using the character definition capabilities of the 99/4A, representations of the numbers 0 through 9 can be developed which are three times taller and wider than these built-in digits. And these larger number characters can be used in your own programs.

Magnifying The Numbers

In the May 1983 issue of COMPUTE!, C. Regena wrote a tutorial on the use of TI graphics ("Programming The TI: Graphics"). Regena explains that each character on the display screen is an 8 X 8 grid of 64 dots. When you press a number key on the TI keyboard, that number is displayed using one such character. By employing the CALL CHAR statement in TI BASIC to turn dots on and off within a particular 8 X 8 grid, custom characters can be defined. The larger numbers here each use 9 custom characters in a 3 X 3 array. The figure shows these numbers and corresponding hexadecimal codes for defining characters.

Examining the figure, you may wonder if these numbers could perhaps be defined in a simpler manner. For example, it is possible to represent each number by straight line segments only, such as are used on digital watches. Certainly, this would work, but it may not be advisable for teaching young children, because children learn numbers for the first time in a pattern recognition mode, trying to match similar objects. Hence, the numbers in the figure are designed to mimic (as closely as possible) the TI keyboard depictions of the numbers. For older children, who are used to seeing numbers written in different ways, the digital watch approach to number display would be fine.

Using The Magnified Numbers

Now that we have the character definitions, we need to efficiently incorporate them into a program. Ten digits, defined by nine characters each, is a total of 90 characters. Of these 90 characters, however, only 54 are distinct. Lines 150-290 of Program 1 assign each of these distinct characters to an index number in the array CI$. These 54 character indices fill an array N which is used to define the ten large digits. In lines 310-480 of Program 1, I is character N's row and J is character N's column within the 3 X 3 array used to define digit K. For example, character 17 (000000000103070F) defines the first row and second column of the number 4 (see the figure). So we can write N(4,l,2) = 17.

Next, we need to relate the two arrays CI$ and N to allow drawing large numbers on the display screen. One way to accomplish this is to load each of the 54 distinct characters into character codes 106 through 159 using CALL CHAR:

FOR 1=0 TO 53
CALL CHAR(I+106,CI$(D)
NEXT I

An alternative which eliminates the need for a CI$ array, is to read the character definitions directly from DATA statements

FOR 1=0 TO 53
READ C$
CALL CHAR(I+106,C$)
NEXT I
DATA …
DATA …

where the DATA statements are identical to those used earlier to define CI$. Then, to draw digit K starting at row R and column C on the screen, we use:

FOR I=R TO R+2
FORJ=CTOC+2
CALL HCHAR(IJ,106+N(K,I-R+1J-C+1))
NEXTJ
NEXT I

This will work fine, yet it has one drawback. It requires the use of 54 custom characters. This does not leave many characters available for their graphics use. We can use another technique rat only requires, at most, nine characters for each digit to be displayed on the screen at one me. So, if our application only displays two digits at any one time, just 18 characters must be defined.

Dynamic Character Definition

That technique, used in Program 1, can be called Dynamic character definition. That is, character codes are redefined and reused as each number displayed. Lines 1500-1580 draw digit K starting at row R, column C, and character code CC.

This approach requires that the contents of the CI$ array have already been assigned, as shown in lines 150-290. If we are using two digits at most, good choices for starting character codes are CC=126 for one digit and CC=135 for the other. This leaves many codes available for other graphics. As long as we require six or fewer different digits to be displayed, this method of dynamic character definition uses fewer character codes than the previous method.

The large numbers developed here have many applications. Math flash card drills, counting games, and guess-the-number games are just a few. As a sample application, the programs provide a preschool game to teach number recognition. In Program 1, which runs in either TI console BASIC or Extended BASIC, the computer randomly picks a number from 0 to 9 and displays it at the center of the screen. The child is then asked to find that number on the keyboard and press it. A correct response wins a snappy tune and a like number of blocks are drawn. An incorrect answer gets an "uh-oh" and the child is asked to try again. Since this program displays only one number at a time, dynamic character definition (CC = 135) is employed for display.