Classic Computer Magazine Archive ANTIC VOL. 3, NO. 6 / OCTOBER 1984

ANTIC 4/5 EDITOR ANIMATOR

by Paul Chabot

This article lets you design and produce smooth animation sequences in four colors with blocks of characters in ANTIC Modes 4 and 5 (Graphics 12 and 13 on XL series computers).  The BASIC programs require a disk drive and a minimum of 48K memory, and run on all Atari computers.  Antic Disk subscribers, RUN "D:ANIMATE.BAS".  All necessary data files are on the disk.

This program lets you edit characters in ANTIC Modes 4 and 5, combine them into three-by-two character blocks, and combine the blocks into fast, four-color animation sequences.  ANTIC 4 is one of Atari's two special character modes.  With planning, you can use it to simulate Atari's highest resolution four-color mode, Mode 7 1/2, with no loss of resolution, and animation is easy to create.  An added benefit is that an ANTIC 4 screen requires only about one-seventh the memory of a Mode 7 1/2 screen.  ANTIC 5 gives you characters that are twice as high as ANTIC 4. If you want to know more about this overall subject, read "Character Graphics," Antic, February 1984.

(Please note: This is a richly powerful program.  We've tried to make the instructions as clear as possible, but you may need to re-read this article several times in order to fully grasp how all the program elements fit together -ANTIC ED)

GETTING STARTED
Type in Listings 1 and 2, check them with TYPO, and SAVE backup copies of each.  Give Listing 1 the filename D:ANIMATE.BAS and call Listing 2 D: MAKESETS.BAS. Make sure there's a disk with copies of both ANIMATE.BAS and MAKESETS.BAS in the drive, and RUN "D:ANIMATE.BAS". There will be a title screen that changes color after a few seconds.  The program ends by RUNning D:MAKESETS.BAS, which creates the binary data files ROM.SET and ANTED.SET. The program MAKESETS.BAS ends by LOADing ANIMATE.BAS. When the READY prompt appears, LIST 72 and change D:MAKESETS.BAS to D:ANTED.BAS, then execute a SAVE "D:ANIMATE.BAS" to store the program with the altered line 72.
   Now type in the main program, ANTED.BAS (Listing 3), and Listing 4, HYPNO.BAS. Check and SAVE both, then RUN "D:HYPNO.BAS". The screen will go black for a few minutes while the program reads and checks its data.  If it finds an error, it stops, turns on the screen, and prints an error message.  If there are no errors, press [RETURN] at the prompt to create the animation file HYPNO.2X3.  Now when you RUN "D: ANIMATE.BAS" (make sure ANTED.BAS, ROM.SET, HYPNO.2X3 and ANTED.SET are on a disk in the drive) you'll see the title screen, the background color will change, and the main program will load and begin to initialize.
   Soon you'll see the editing screen and the message "<any key> - to BEGIN." The dazzling opening animation sequence is provided by the data file HYPNO.2X3.  Press a key, and the program will replace HYPNO with the standard Atari character set and copy the first figure (figure #0) to the grid, and you're ready to go.

THE DISPLAY SCREEN
This section contains brief descriptions of the various sections of the editing screen.  Refer to Figure 1.
   GRID (upper right): A three-color 16-by-12 checkerboard for editing a two-by-three block of characters.  When editing, you control a small cursor in this region with the joystick.
   EW (upper right): There are four Edit Windows to the right of the grid.  You'll see three copies of the grid object in ANTIC 4, and below them, one ANTIC 5 copy.  These images immediately reflect changes you make to the grid object.
   AW (upper center): There are four Animation Windows; three ANTIC 4 copies to the left of the grid, and one ANTIC 5 copy to the left of the ANTIC 5 EW.  These let you view animation sequences you create.
   AN area (upper left): Numbered 0 to 9 are the 10 ANTIC 4 animation frames in two rows.  ANTIC 5 copies of the frames appear in a single row just below.  Each frame will be one step, or view, in your final animated sequence.  Sequences may be of any length between one to ten frames, inclusive.
   MAIN MENU (center): Contains the program functions.  To choose a function, press the appropriate letter without pressing [RETURN].
   FN area (bottom): There are 20 ANTIC 4 figures, each made up of a group of six characters.  This is the figure set being edited.  The Figure Number (FN) used throughout the program is the number of the object from this group that you're editing in the grid.

GRID EDITING
This is the default, or normal function of the Editor/Animator.  You control a small cursor in the grid area with a joystick.  Press the trigger to switch between setting a pixel in the current color and turning the pixel off (or setting it to the background color).
   The current color appears in a vertical bar on either side of the grid, and you can change it by pressing any key that doesn't correspond to a menu selection (e.g. the space bar).  Hold the trigger down while pressing the joystick to draw a continuous line in that direction, regardless of the pixels' previous state.  You'll see any alterations you make to the grid in each EW region, in figure number FN at the bottom of the screen, and in animation frame AN.

MAIN MENU
Choose a menu selection by pressing the indicated key.  No [RETURN] is needed.
   A (Edit): Use this to select which figure to edit.  Your joystick controls a large box-like cursor in the bottom FN region.  A copy of the figure currently inside this cursor appears in all AW regions.  Pressing the trigger selects that figure and moves a copy into the EW regions.  If you press any key before pressing the trigger, you'll abort the process and return to grid editing.  After you choose the figure, you must choose the animation frame into which to place the figure.  Push your joystick to move the cursor in the AN region, and press the fire button to place the figure.  The figure is copied into that frame as well as the grid.  Finally, you're turned to grid editing.
   B (Next): This is a handy aid for producing animation sequences.  The current AN and FN numbers (located just above the Main Menu on the right side) are both incremented and the current grid object is copied to the next animation frame.  The grid isn't altered.  You can simply make minor changes for this frame in the sequence and press [B] again to go to the next frame.
   C (Save): Allows you to save the current figure (at screen bottom) to a disk file.  After you press [C], a directory of the current disk appears.  Type in a filename at the prompt, press [RETURN], and then [S] to complete the save.  The program adds the extender .2X3 to all file names.  Pressing any other key at this point aborts the process and returns you to grid editing.
   D (Load): Analogous to Save, except you're loading from a disk file.  This affects the AN region and resets both AN and FN to zero.
   E (Topload): Use this to mix and match parts of your data files.  This loads only 512 bytes, so only to the top row of the figure set is affected.  Note that this function does not alter the AN region.  Use in combination with M (Swap) to combine halves of two different figure set files.
   F (Animate): This allows you to see your animation after you've created the frames in the sequence.  At the start, each of the Animation Windows contains a copy of AN frame #0.  Press [N] to see the next frame in the same window.  This continues until the animation limit is reached (see Menu selection G), at which point the sequence restarts with frame 0. Animate continuously by holding down the joystick trigger, Escape this function by pressing any key other than [N].
   G (IncAL): Use this before using the Animate function (selection F).  The current animation limit (AL), or final frame in a sequence, is indicated by a block of color immediately to the right of that number in an AN area.  Press [G] to increase the AL and move the block to the next frame.  After nine, the value of AL wraps around to zero.
   H (Clear): Clears the grid, each Edit Window, and the current FN and AN areas.
   I (Clear S): This clears the section of the grid that contains the cursor.  There are six sectors whose sequence corresponds to the order of the six characters being edited.  Across the top are sectors 0, 2, and 4, and across the bottom are sectors 1, 3, and 5.
   J (Restore): For peace of mind.  This restores the figure you're currently editing to its original state at the time of the most recent load.  When you load a figure set, two sets are actually loaded.  The second set is never altered and is used for this purpose.
   K (Copy to): The joystick controls the FN cursor.  Pressing the trigger copies the contents of the current Edit Window to the selected figure.  The previous data for that figure is discarded.  Neither an AN nor FN is affected.
   L (Exchange): The joystick controls the FN cursor.  Pressing the trigger copies the contents of the current Edit Window to that figure.  That figure is copied to the current FN.  Then FN is altered to reflect the new location of the figure you're editing.
   M (Swap): This swaps the top ten figures in the current set with the bottom ten.  FN is altered appropriately.  Use this together with function E (Topload) to combine parts of different figure sets.
   N (AN to F): You first control the AN cursor and press the trigger to select an animation frame.  Next you control the FN cursor to select a position in the figure set to place that animation frame.
   O (Color): A special menu will appear.  You control the asterisk's movement with the joystick.  Pressing the trigger increments the corresponding value of hue or luminance.  You'll see the effects of changing the color immediately throughout the screen.  Press [R] to reset the original program (default) values.  Any other key terminates this section.
   Cursor keys (shift grid): Use the cursor keys without [CTRL] to shift the entire contents of the editing grid one row in the desired direciton.  The last row becomes blank.

HOW IT WORKS
What this program calls a figure set is actually a character set whose members the editor combines into twenty groups of six, for a total of 120 characters.  A complete character set has 128 characters, though, so this program discards the initial four and final four characters.  You can use your own character set that's produced with another utility (you must add the .2X3 extender to the filename), but unless you've designed the set specifically with this program in mind, the characters probably won't be grouped correctly.
   The program creates animation by loading two character sets into RAM, telling the Operating System to use one, and then copying blocks of 48 bytes (one two-by-three character matrix) from the second to the first at machine-language speed.  This changes the data in the current character set, which is reflected immediately on the screen.  Each animation frame contains six characters of eight bytes each, so the program must move 48 bytes at a time.  Machine language accomplishes this so fast that the animation looks smooth.

DEMONSTRATION PROGRAM
Listing 5, called DEMO.BAS, shows techniques for using animation sequences in your own programs.  Type in this program, use TYPO to check for typing errors, and SAVE a copy.  When you RUN it, make sure there's a disk with ROM.SET on it in drive 1. When the program starts, you see a screen full of rapidly animated two-by-three groups of characters.
   Plug in a joystick and move it vertically or horizontally, and you'll see one of the groups of characters move around the screen according to joystick movement.  This group is the "eater," and the others are "dots." The object of this demonstration game is to move the eater around the screen to "eat" the dots.  If you press the fire button, more dots appear while the background changes colors.  The edges of the screen show the twelve individual characters in two blocks.
   To create this game, I first determined which characters to print to the screen.  These make up your "windows," into which data from the successive animation frames will be copied to create the animation.  The dots are comprised of the first six characters in the second half of the character set.  The "eater" uses the second group of six characters in the set.  The pointers to these two areas in the set are set in line 230.  Because of the difference between internal character code (the order of the characters within the character set) and the ATASCII table, this means that the dot "window" uses CHR$(0) to CHR$(5), and the eater uses CHR$(6) to CHR$(11).
   Next, I established pointers to the various animation frames being used.  The eater uses ten frames.  Line 234 uses the index I to set up array ES (Eater Sequence) with the locations of these frames in the animation set.  Line 232 does the same for five frames used in the animation sequence for the dots.  The two animation sequences use figures 0 to 9 and 10 to 14 respectively Once the eater and dots are on the screen, USR calls to the machine-language routine COPY animates them rapidly.  The eater is animated with lines 22 and 24, and the dots are animated with lines 26 and 28.

MOTION
DEMO.BAS uses the fairly slow technique of printing, erasing, and printing in a new position to move the eater around the screen, which is achieved in the subroutine in lines 10 to 18.  You could obtain much faster motion by writing a specialized USR routine to POKE the fixed values that define the eater into screen memory at the desired position.  If you want to be able to tell when two objects on the screen have collided, use LOCATE to check the eater's next position (actually, six locations) between the erasure and the redrawing.  This does slow things down and cause "blinking" motion, though, so you might consider writing another USR routine to check screen memory.
   As your first experience in using the Editor/Animator, create an animation sequence with ten frames (FN 0 to 9) for the eater, then a five-frame sequence (FN 10 to 14) for the dots.  Save the figure using the [C] selection from the menu.  Suppose you call it EATDOT.  Now LOAD "D:DEMO.BAS" and change the file specification on line 414 to "D:EATDOT.2X3". The sample program will now use your animation sequences.  By the way, HYPNO.2X3 has five frames of an "eater" sequence.
   A common saying among programmers is that no program is ever completely finished, and this one is no exception.  Since most of the program is in BASIC, feel free to alter its characteristics any way you like.  I chose a two-by-three array for pragmatic reasons.  Among the factors in my decision were the sizes of the different elements in the editor layout, the size of the actual characters, and the fact that you can use the two-by-three matrix to edit arrays of dimensions one-by-one, two-by-one, and two-by-two (but not one-by-two or one-by-three, because of the array's layout).  If you want to change the editor's opening animation, design new sequences and change line 2810 in the editor to show the new name.

Paul Chabot is a professor in the department of Mathematics and Computer Science at California State University at Los Angeles.  His Player/Missile Editor utility program will appear in our forthcoming book, Antic's Book of Games (working title).

Listing 1: ANIMATE.BAS Download

Listing 2: ANTED.BAS Download

Listing 3: ANTED.SET Download

Listing 4: HYPNO.2X3 Download

Listing 5: DEMO.BAS Download

ROM.SET Download