home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / drdobbs / 1990 / 01 / rahner.exe / ANIMATE.FAX next >
Text File  |  1989-09-21  |  30KB  |  545 lines

  1.  
  2.  
  3.  
  4.         
  5.         
  6.                            Realtime Animation for EGA
  7.                                   Rahner James
  8.         
  9.         
  10.         
  11.                 "The distinction between a toy and a game is that
  12.                the game has a goal; therefore, life is not a game,
  13.                it is a toy."
  14.                                                             - GOK
  15.         
  16.         
  17.         I. Introduction
  18.         
  19.         As  a  child, I could not differentiate between  Bugs  Bunny  and 
  20.         Walter  Cronkite.  This is not to say that the man  America  most 
  21.         trusted had dental problems, but that the child did not have  the 
  22.         experience  to  see  the cartoon for what it was -  a  stream  of 
  23.         individually  drawn  pictures.   Skilled  professional  help  was 
  24.         required  to deal with the trauma caused by the  revealed  truth.  
  25.         Even  after the psychological defects were converted to scars,  I 
  26.         had to wait until I could create two-dimensional life for myself.
  27.         
  28.         The time has come.
  29.         
  30.         Animation is achieved by showing a series of incrementally chang-
  31.         ing  images.   Depending on the duration of time  that  a  single 
  32.         image is shown and the time it takes to switch to the next  image 
  33.         increment,  the  viewer's  visual  persistence  smooths  out  the 
  34.         image's  transition.  Anyone with a compiler and a  graphics  li-
  35.         brary can put a series of images on a computer display.  However, 
  36.         in  order to create smooth, non-flickering, realtime animation  a 
  37.         fair amount of thought is necessary.
  38.         
  39.         In  order  to support reasonable animation,  the  algorithm  must 
  40.         conform to the following rules:
  41.         
  42.         (1) Coordinate Movement
  43.         The routines must allow individual objects to be moved around  on 
  44.         the screen and placed on any pixel boundary.
  45.         
  46.         (2) Independent Motion
  47.         Each  object in the image should be able to show a chain  of  se-
  48.         quences independent of its coordinate movement.
  49.         
  50.         (3) Smooth Transitions
  51.         The  transition between image frames should have no  intermediate 
  52.         stages.   This  means that the viewer should  see  only  complete 
  53.         images  and no images that are half the first image and half  the 
  54.         second  image.   These half and half images are  perceived  as  a 
  55.         flicker and are distracting.
  56.         
  57.         (4) Regular Transitions
  58.         All  image  transitions should happen at regular  intervals.   If 
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.         this does not happen the sequence will appear to jerk like an old 
  66.         projector.
  67.         
  68.         (5) Sprites
  69.         If  an object has a hole, any objects that are behind  it  should 
  70.         show through.  Poorly done animation will not allow the viewer to 
  71.         see through a gap in an object.
  72.         
  73.         (6) Realistic Objects
  74.         There  is  a difference between what is shown on the  screen  and 
  75.         what  is perceived by the observer.  Up to a point, jagged  lines 
  76.         will be smoothed, imperfect colors accepted and stairstep corners 
  77.         rounded.   This  point, the point of realism, is  subjective  and 
  78.         entirely  dependent  on the target audience.  Below  this  point, 
  79.         other  unrelated  flaws can be magnified; above this  point,  the 
  80.         overall perception of the product is enhanced.
  81.         
  82.         The  elements of this list are all mutable by  targeted  hardware 
  83.         limitations.   Accurate shading may be difficult on  an  AT-class 
  84.         machine.  Absolute realism for anything but the simplest  geomet-
  85.         ric  shapes is impossible on CGA or EGA.  The finished  product's 
  86.         design  constraints  may adjust the significance of  one  element 
  87.         over  the  others.  These are Rahner rules - they may  be  burnt, 
  88.         bent or beatified.
  89.         
  90.         
  91.         II. Zippy Tries his Hand at CGA Animation 
  92.         
  93.         When  I first saw reasonable animated images on a CGA adapter,  I 
  94.         was  intrigued.  It was a simple CGA sprite demo - several  heli-
  95.         copters flying aimlessly around the display.  Since the demo only 
  96.         allowed the helicopters to start on a byte boundary (four  pixels 
  97.         per byte) and did not allow the helicopters to smoothly exit from 
  98.         the  side of the screen, I decided to try my hand at writing  the 
  99.         ultimate animation driver for CGA.
  100.         
  101.         After  a lazy Sunday's work, the ultimate was  completed.   Given 
  102.         CGA's limitations (four colors and 320x200 resolution),  ultimate 
  103.         was  probably too strong a word.  It was about the same as  tying 
  104.         the ultimate shoelace or throwing the ultimate dirt clod.   Anti-
  105.         climactic would be the correct word for polite company.
  106.         
  107.         Since  the initial attempt was an  unplanned,  seat-of-the-pants, 
  108.         I've-got-Fritos-diet Coke-and-plenty-of-time effort, my trial and 
  109.         error path would best illustrate some animation rudiments.
  110.         
  111.         The first attempt was to whip a series of changing pictures  past 
  112.         the  monitor.  This involved copying virtual screens that  I  had 
  113.         prearranged  onto  the CGA video RAM.  This had  the  interesting 
  114.         effect  of  flickering the screen with  seemingly  random  images 
  115.         caught in a blizzard.
  116.         
  117.         The flicker and snow storm were due to not waiting for the verti-
  118.         cal  retrace before displaying the next image.  What is  vertical 
  119.         retrace?   A good question, sir (ma'am?), since it  is  important 
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.         later.   The CRT monitor etches its pictures in the  orbitals  of 
  127.         fluorescent compounds with a single beam of electrons.  This beam 
  128.         sweeps horizontally back and forth across the screen.  In  either 
  129.         the back or the forth direction, the beam has to turn off, other-
  130.         wise it looks funny - the off direction is called the  horizontal 
  131.         retrace.  The beam winds its way down the screen in this back and 
  132.         forth  manner.  When it reaches the bottom it turns off  and  re-
  133.         turns  to  the top of the screen - this off time  is  called  the 
  134.         vertical  retrace.   On  the standard EGA  setup,  this  vertical 
  135.         retrace occurs 60 times a second.
  136.         
  137.         The standard CGA adapter has a bit that indicates when the  hori-
  138.         zontal refresh is occurring and another to show when the vertical 
  139.         refresh is occurring.  It was a simple task to change the program 
  140.         so  that it waited for the vertical retrace before  blasting  out 
  141.         the  next virtual screen.  Now, I saw a series of  pictures  end-
  142.         lessly circling, but without snow or flicker.
  143.         
  144.         Next, I noticed that most of the screen was stationary and only a 
  145.         small fraction of the image moved at any one time.  In fact, most 
  146.         of  the  things that did move were sets of pixels  that  did  not 
  147.         reposition  themselves  with respect to one  another,  only  with 
  148.         respect to the rest of the picture.  After much deliberation (and 
  149.         lunch), I named these sets sprites.  Later I had found that these 
  150.         sets had been noticed before and they had used my name for  them.  
  151.         Rather  than  risking a protracted legal battle, I  swallowed  my 
  152.         pride and have allowed the others before me to take the credit.
  153.         
  154.         The basic concept behind the sprite is simple. Cut a  rectangular 
  155.         section  out  of the screen and store it.  Then take the  set  of 
  156.         pixels  that comprise the sprite and replace the  cutout  section 
  157.         with them.
  158.         
  159.         Armed  with my 'new' creation, the series of virtual screens  was 
  160.         reduced to a simple background and a few sprites.  The background 
  161.         was  displayed first, then the sprites were moved  into  position 
  162.         before  the finish of the vertical retrace.  Now, I had the  same 
  163.         cinematograph  that I had before, but the program was more  effi-
  164.         cient  and the storage requirements were reduced.  Before  I  got 
  165.         bored  with  this  endless video cycle, I noticed  that  when  my 
  166.         sprites went in front of something the background was  completely 
  167.         covered  even  in  places that I should have  been  able  to  see 
  168.         through.
  169.         
  170.         This  meant  another change.  Instead of just storing  the  back-
  171.         ground, I masked off the solid areas of the sprite body.  Instead 
  172.         of  replacing  the  cutout, I OR'ed the sprite  onto  the  masked 
  173.         background, then replaced the cutout around the finished product.  
  174.         This  allowed  me to have 'holes' in the sprites,  for  increased 
  175.         realism.
  176.         
  177.         With  the inclusion of 'holes' in the sprites, I had my  ultimate 
  178.         CGA  sprite routine.  All the little fishes were swimming  around 
  179.         in my video aquarium without the need for food.  I was  satisfied 
  180.         and went to bed.
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.         
  188.         You may be asking "What does this have to do with EGA?".  You may 
  189.         be getting sleepy and ready to close the magazine.  You may  just 
  190.         be  hunting for good prices on software.  Well, to  the  shopping 
  191.         sportsman, there are no good prices in this article; to the  som-
  192.         nambulant peruser, good night; and to the inquisitor in the  back 
  193.         with his hand up - Everything!
  194.         
  195.         
  196.         III. The EGA and I
  197.         
  198.         In  its  640x350 pixel color graphics mode, an EGA  adapter  with 
  199.         256K  of  RAM is setup as four planes of 28,000 bytes  each.   It 
  200.         also  has two pages, one that is being viewed on the monitor  and 
  201.         one  that is in the ether.  Both pages can be addressed  directly 
  202.         by  the CPU.  The first page starts at memory address  A000:0000h 
  203.         and  the  second  page starts at A000:8000h.  Each  byte  of  EGA 
  204.         memory  represents  eight pixels with the  most  significant  bit 
  205.         (MSBit) being shown as the leftmost pixel.  A byte or bit of  any 
  206.         combination  of the planes may be addressed depending on how  the 
  207.         EGA registers have been set.
  208.         
  209.         Superficially,  there  seemed to be little difference  between  a 
  210.         sprite driver for the CGA and EGA adapters.  It seemed to be just 
  211.         another  block  of RAM that to which I needed to jam  out  bytes.  
  212.         Following  that line of thought, the first code translation  from 
  213.         CGA  was  conceptually simple.  The sprites were  placed  on  the 
  214.         visual  page, a plane at a time.  When I looked at it  the  first 
  215.         time,  I found myself almost back to square one.  No  matter  how 
  216.         efficiently I wrote the driver, there was a constant flicker.   I 
  217.         ran  to  the bookstore, hoping for a tome of  enlightenment.   My 
  218.         hope  was dashed by a limited selection.  A quick reread  of  the 
  219.         IBM  EGA Technical Reference manual, however,  provided  me  with 
  220.         the  answers: the EGA adapter can generate an interrupt  and  the 
  221.         visual page can be switched during the vertical retrace.
  222.         
  223.         
  224.         IV.  Writing a Bit Map to EGA Memory
  225.         
  226.         The EGA adapter has a fair number of features.  All the  features 
  227.         and  how the board reacts to CPU memory manipulations are  deter-
  228.         mined by the configuration registers.  Most of the registers  are 
  229.         setup  in pairs.  The first register accepts an index value  that 
  230.         determines  the functionality of the second register.  The  major 
  231.         register  pairs  that we need to concern ourselves with  are  the 
  232.         Sequencer  registers  and the Graphics 1 & 2  Address  registers.  
  233.         Another  register that is important for this discussion is  Input 
  234.         Status Register One.
  235.         
  236.         The Sequencer register is located at 3C4h with its index register 
  237.         at  3C5h.   It has five indexed registers - Reset  (0),  Clocking 
  238.         Mode (1), Map Mask (2), Character Map Select (3), and Memory Mode 
  239.         (4).  To access an indexed register, the index's number is output 
  240.         to  the Sequencer register followed by the value for  that  index 
  241.         output to the index port.  For example, say you want to place a 5 
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248.         in the Clocking Mode index register which is index number 1,  the 
  249.         following assembly code would do:
  250.         
  251.                   MOV       DX, 3C4h       ; DX -> Sequencer register
  252.                   MOV       AL, 1          ; AL = index 1, Clocking Mode
  253.                   OUT       DX, AL
  254.                   INC       DX             ; DX -> Sequencer index port
  255.                   MOV       AL, 5          ; AL = to put in Clocking Mode
  256.                   OUT       DX, AL
  257.         
  258.         Since all the register pairs are one right after the other,  this 
  259.         code segment could be replaced by the following segment:
  260.         
  261.                   MOV       DX, 3C4h       ; DX -> Sequencer reg. pair
  262.                   MOV       AX, 501h       ; AL = index 1, AH = value 5
  263.                   OUT       DX, AX         ; Puts AL out 3C4h, then
  264.                                            ;  AH out 3C5h
  265.         
  266.         This  replacement is usually valid except when slow  ports  cause 
  267.         timing difficulties.
  268.         
  269.         The  important  Sequencer  index register, with  respect  to  our 
  270.         driver,  is the Map Mask Register (index 2).  This register  ena-
  271.         bles  planes  so that the CPU can write to them.  Setting  bit  0 
  272.         enables  plane  0, bit 1 enables plane 1, etc.  Since  there  are 
  273.         only  four planes the four MSbits are not used and  ignored.   If 
  274.         you  wanted  to write the same information  to  multiple  planes, 
  275.         multiple  bits  could be set.  No easy assumptions  can  be  made 
  276.         about  the sprite data so we can't really take advantage of  this 
  277.         feature.
  278.         
  279.         The  Graphics 1 & 2 register set deals with colors,  pixel  masks 
  280.         and  the  Boolean graphic operations the EGA can  perform.   This 
  281.         register  is configured the same as the Sequencer  register  with 
  282.         nine  indexed  registers - Set/Reset (0), Enable  Set/Reset  (1), 
  283.         Color  Compare  (2), Data Rotate (3), Read Map Select  (4),  Mode 
  284.         Register  (5), Miscellaneous (6), Color Don't Care (7),  and  Bit 
  285.         Mask  (8).   The index registers of concern are the  Data  Rotate 
  286.         register and the Read Map Select register.
  287.         
  288.         The  Data Rotate register has two controls.  Bits  0-2  represent 
  289.         the  Rotate Count.  The Rotate Count is a binary  encoded  number 
  290.         that represents the bit positions to shift any data written to  a 
  291.         video  plane.  Since all our data will be unshifted at the  hard-
  292.         ware  level,  this  value should be 0.  Bits  3-4  represent  the 
  293.         Function  Select.  The Function Select indicates  which  Boolean-
  294.         type  operation is desired for pixels written to display  memory.  
  295.         The following table shows the available functions:
  296.         
  297.                   Value     Description
  298.                  -------   -------------
  299.                    0 0      Written data is not modified
  300.                    0 1      Written data is AND'ed with latched data
  301.                    1 0      Written data is OR'ed with latched data
  302.                    1 1      Written data is XOR'ed with latched data
  303.  
  304.  
  305.  
  306.  
  307.  
  308.  
  309.         
  310.         To  diverge for a moment, a definition for 'latched data'  is  in 
  311.         order.   No  matter how it appears, the video memory on  the  EGA 
  312.         adapter  is  never directly connected to the  PC-bus.   When  the 
  313.         registers  are  set  properly, the program  addresses  the  video 
  314.         memory  in exactly the same manner it would any other portion  of 
  315.         main  memory.  The memory can be accessed as a byte or word,  but 
  316.         those  accesses are processed through the EGA's  circuitry.   The 
  317.         circuitry performs some gyrations on the data then passes it  on.  
  318.         In  order  to properly swing the binary song, that  gyrating  EGA 
  319.         circuitry  latches  the byte or word in its  internal  read/write 
  320.         buffer.  A read of EGA memory will put that byte of pixels in the 
  321.         latch  which  can then be operated on by some  future  operation.  
  322.         Since each plane has a separate latch buffer, if all four  planes 
  323.         have  been  enabled,  32-bits at a time can  be  latched  (read), 
  324.         operated  on and then rewritten to EGA memory with a single  8086 
  325.         instruction.
  326.         
  327.         Give  me an inch and I'll take a while, diverging on to the  8086 
  328.         instructions.  When dealing with this aspect of the EGA  adapter, 
  329.         a close look at how some 8086 instructions actually work would be 
  330.         in order.  Let's start with the instruction:
  331.         
  332.                             OR     [DI], AL
  333.         
  334.         When  the 8086 sees this instruction, it loads the value  pointed 
  335.         at  by the register DI into the 8086 internal register, OR's  the 
  336.         value in register AL onto that internal register, then writes the 
  337.         result back out the location pointed to by DI.  If DI happened to 
  338.         point to EGA memory, this would latch up a number of pixels,  add 
  339.         in  pixels, then write the latch data back out to video memory  - 
  340.         all in a single instruction.  If an additional EGA function, such 
  341.         as a bit rotate, was added to the previous example some interest-
  342.         ing and possibly useful results could be achieved.  Now, I  don't 
  343.         use this in my routine, but, by jingo, it's just too nifty to  be 
  344.         ignored!
  345.         
  346.         The last register of importance is Input Status Register One.  It 
  347.         has  a few informative bits, but we will only be concerned  about 
  348.         the  Vertical Retrace bit (3).  As the name implies, this bit  is 
  349.         set  to 1 when the display is in a vertical retrace time.   As  I 
  350.         stated  before,  this was the time to write to the  video  memory 
  351.         with  the CGA adapter.  It has approximately the same value  with 
  352.         the EGA adapter, but not exactly.
  353.         
  354.         
  355.         V.  When Blazing Fast is Not Fast Enough to Start a Fire
  356.         
  357.         When I converted my CGA animation routines to work with the  EGA, 
  358.         there was an unexpected problem.  I found that no matter how fast 
  359.         I blasted my sprites out to video memory, the raster line (anoth-
  360.         er name for that beam of electrons described earlier) would catch 
  361.         up  to where I was writing pixels.  When the raster  would  catch 
  362.         up,  the  screen would flicker annoyingly.  Having to  deal  with 
  363.         four planes and EGA's higher resolution just took too much  time.  
  364.  
  365.  
  366.  
  367.  
  368.  
  369.  
  370.         I made my assembly code more efficient.  I made assumptions about 
  371.         the  data  I was displaying to cut corners.  I got  a  25MHz  386 
  372.         system.   Nothing worked.  I felt like a laundry  commercial.   I 
  373.         went back to the EGA Technical Reference manual.
  374.         
  375.         Almost  immediately the answer written by the IBM ancients  ques-
  376.         tioned my original thinking.  The standard EGA has 256K of RAM  - 
  377.         enough  for  two pages of display memory.  I could write  to  one 
  378.         page,  wait  for the next vertical retrace, then swap  pages.   I 
  379.         rewrote everything.
  380.         
  381.         Planning  ahead,  I  continued reading  the  Technical  Reference 
  382.         manual.   The  EGA can generate an interrupt request 2.   If  the 
  383.         driver could just swap pages whenever the video went into  verti-
  384.         cal  retrace,  then  I wouldn't have to waste  time  polling.   I 
  385.         rewrote it, again.
  386.         
  387.         
  388.         VI.  Animation Structures
  389.         
  390.         To become animated objects, sprites must have four basic  degrees 
  391.         of  freedom - Coordinate Motion, Self-relative Motion,  Rotation, 
  392.         and Perceived Distance.  Coordinate Motion is simply the movement 
  393.         from one point on the screen to another.  Self-relative Motion is 
  394.         the  movement that the sprite could make without moving to a  new 
  395.         coordinate  location.   Rotation is a revolution  of  the  sprite 
  396.         around  some  center point in its body.   Perceived  Distance  is 
  397.         basically  sizing the sprite according to its  apparent  distance 
  398.         from the viewer.
  399.         
  400.         The increment resolution of each degree of freedom is independent 
  401.         from the others.  A sprite picture of a person may be pumping its 
  402.         arm up and down a pixel at a time and traversing the screen  five 
  403.         pixels  at  time.  Given a monitor/graphics  adapter  combination 
  404.         that refreshed the screen an infinite number of times, the small-
  405.         er  the movement increment, the more realistic its  action  would 
  406.         be.   Since the standard EGA board refreshes the screen  at  60Hz 
  407.         (60  times  a second), the movement increment  should  be  judged 
  408.         relative  to  the apparent velocity of the  sprite,  the  display 
  409.         resolution and the level of the art.  Since I can only draw crude 
  410.         stick figures, my resolution granularity can be boulder-size.
  411.         
  412.         Two  of the four degrees of freedom (Rotation and Perceived  Dis-
  413.         tance)  should  not be a function of a sprite  driver.   A  good, 
  414.         general purpose rotation algorithm requires fairly heavy calcula-
  415.         tions.  These calculations are burdensome enough to detract  from 
  416.         the real-time nature of the animation driver.  Although Perceived 
  417.         Distance does not need as much time from the CPU, it should  just 
  418.         be  done at a higher level than the driver.   Perceived  Distance 
  419.         requires the sprite to be resized larger as it gets closer to the 
  420.         viewer and smaller as it gets farther.  As the size of the sprite 
  421.         approaches the minimum resolution of the monitor, details  disap-
  422.         pear.   No algorithm can make perfect decisions about which  fea-
  423.         tures of an object are important to the visual integrity of  that 
  424.         object.
  425.  
  426.  
  427.  
  428.  
  429.  
  430.  
  431.         
  432.         Self-relative  Motion  deals  with the movement of  each  of  the 
  433.         individual  pixels of the sprite with respect to each other,  but 
  434.         not  straying outside of the boundary of the sprite.   To  illus-
  435.         trate  Self-relative Motion without any other component,  I  have 
  436.         included  a  sprite of a flame.  Each of the  pixel  groups  that 
  437.         represent small flamelets rise to the top of the fire.  The pixel 
  438.         groups  that represent the edges of the flame billow in  the  up-
  439.         draft caused by the heated air.  In my routine, the effect of the 
  440.         motion  is  created by a linked list of sprite  frames.   In  the 
  441.         example, each successive frame shows the flame in the next  point 
  442.         of  time  (without regard to mathematical  proofs,  in  animation 
  443.         there is a quantum of time).  Since motion in most biological  or 
  444.         mechanical  systems  is cyclical, I join the terminal  points  of 
  445.         this  linked list into a sprite circle.  Each sprite can  proceed 
  446.         through  a  cycle of self-relative motions  whose  complexity  is 
  447.         determined by the circumference of the sprite circle.
  448.         
  449.         Coordinate  Motion  involves moving the sprite  circle  from  one 
  450.         point  to  another on the screen at some regular  velocity.   The 
  451.         sprite  velocity is determined by the number of pixels  that  the 
  452.         sprite circle will move divided by the number of times per second 
  453.         the visual image will be changed.  Say we make a sprite represen-
  454.         tation  of  a  five meter long car that is  drawn  32  pixels  in 
  455.         length.   To move that car from the right side of the  screen  to 
  456.         the  center  at an apparent velocity of 20  km/hour,  the  sprite 
  457.         would  have to move to the left 176 pixels per second  if  every-
  458.         thing  is kept to scale.  If our visual page changes come 20  per 
  459.         second,  the sprite would have to be moved 9 pixels to  the  left 
  460.         every page change.
  461.         
  462.         
  463.         VII. How the Routines Work
  464.         
  465.         The sprite routines are broken down into two parts.  The  portion 
  466.         that  deals with the EGA ports, memory and interrupt service  are 
  467.         written  in  8086  assembly language.  The  higher  level  sprite 
  468.         circle and list managers are written in Microsoft C.
  469.         
  470.         Some  assumptions were made about the nature of the  sprites  and 
  471.         the  background.  The sprite driver is written to for sprites  of 
  472.         any  dimension, but the driver is optimized for a sprite that  is 
  473.         32  bits  across.   In my application, it was  assumed  that  the 
  474.         observer  could pan or tilt the viewing perspective.   Since  the 
  475.         perspective  can be changing in smooth real-time, the  background 
  476.         is not a set quantity; so it is being regenerated in every visual 
  477.         frame.  Additionally, since the 8086 family drops at least  eight 
  478.         clock  ticks every time it makes a JMP or CALL, the  code  favors 
  479.         execution speed (ie. very few jumps, calls or loops) over program 
  480.         size.
  481.         
  482.         The  basic  algorithm is simple.  Before any  operations  can  be 
  483.         performed,  the  sprite driver needs to be  installed  using  the 
  484.         function EGA_INSTALL().  This preps the adapter, initializes some 
  485.         variables and installs the interrupt vector.  The first sprite of 
  486.  
  487.  
  488.  
  489.  
  490.  
  491.  
  492.         a  sprite circle is inserted into the linked list of  circles  by 
  493.         calling  the  function INSERT_SPRITE(  START_X,  START_Y,  END_X, 
  494.         END_Y,  SPEED_X, SPEED_Y, DEPTH, SPRITE_CIRCLE );  where  START_X 
  495.         and START_Y are the starting X,Y coordinate of the sprite,  END_X 
  496.         and  END_Y are the ending X,Y coordinate of the  sprite,  SPEED_X 
  497.         and  SPEED_Y  are the amounts that the X and Y  coordinates  will 
  498.         change per visual frame, DEPTH is the perceived distance from the 
  499.         observer,  and SPRITE_CIRCLE is a pointer to the first  entry  of 
  500.         the  sprite circle.  Additional sprites can be added to the  cir-
  501.         cumference of a sprite circle with the function ADD_SPRITE.  Once 
  502.         all  the sprite circles have been figured out and  inserted  into 
  503.         the  sprite list, call DO_SPRITE_LIST() whenever it is  appropri-
  504.         ate.   DO_SPRITE_LIST() figures out the new sprite positions  and 
  505.         places  them on the non-visual page.  When it has placed all  the 
  506.         sprites, it sets the flag DO_PAGE_FLIP, clears DONE_PAGE_FLIP and 
  507.         returns.   The main program boy is then free to do anything  with 
  508.         the  sprite  structures.  At some time in the future,  the  EGA's 
  509.         vertical  interrupts  and the interrupt service  routine  decides 
  510.         whether  to  swap pages or not.  If it does swap  the  pages,  it 
  511.         clears  DO_PAGE_FLIP and sets DONE_PAGE_FLIP.  Although the  rou-
  512.         tines  are  not completely reentrant, they are fairly  immune  to 
  513.         interrupts;  so, they can be called from other interrupt  service 
  514.         routines such as the timer tick or a mouse driver.
  515.         
  516.         With  regards  to  visual timing, movies project  24  frames  per 
  517.         second on the silver screen.  To decrease the cost of  animation, 
  518.         some  cartoon  manufacturers will keep the same  picture  on  the 
  519.         screen  for more than one frame.  The interrupt  service  routine 
  520.         has a counter that can be used to allow it to skip any number  of 
  521.         vertical  retraces between page changes.  If your CPU is slow  or 
  522.         the  main  body of your program needs more time to do  its  work, 
  523.         altering  the  skip  count has the effect of  smoothing  out  the 
  524.         movement  of the sprites.  To counteract the slowing  effect  in-
  525.         creasing the skip count would have, you must increase the veloci-
  526.         ty of any coordinate motion proportionately.
  527.         
  528.         
  529.         VIII.  Finishing Thoughts
  530.         
  531.         There is so much that can be written about real-time animation, a 
  532.         conclusion  at any point leaves the feeling that a lot  was  left 
  533.         out.  The scope of this article does not allow me to explore  all 
  534.         the  avenues  with  the depth that they  deserve.   Possibly  the 
  535.         routines that have been provided with this article can be used as 
  536.         learning aids to go beyond what has been written.  Animation is a 
  537.         form for the presentation of ideas.  Seminars, product demonstra-
  538.         tions, and computer modeling programs can all be enhanced by  the 
  539.         addition of animation graphics.  Of course, the most obvious  use 
  540.         only  reinforces what I have always said.  The only useful  thing 
  541.         someone can do with a computer is play a game on it.
  542.  
  543.  
  544. RRJ
  545.