ORBIT
by SM King
from ZX Computing Summer 1982

S M King from Bristol takes you and your ZX81 far out into space, where you can
observe the four innermost planets of the solar system - Mercury, Venus, good
old Earth and Mars - happily circling the sun.


Orbit is a program which was originally intended to produce an animated
simulation of the movement of the four inner planets in our solar system around
the sun. However, it soon became apparent that producing accurate elliptical
orbits was going to be rather difficult, especially with the limited 64x44
resolution available. The result is that the program uses circular orbits to
display the relative motion of the planets at the expense of accuracy. Whilst
it may still find use in an instructive role it would be much better placed in,
say, a "Star Trek" type of program as a "long-range scanner report".


The program

The program was written on a Sinclair ZX81 with 8K Floating-point BASIC and 16K
of RAM, although it by no means uses this much. With the omission of REM
statements and with the use of other space-saving tips (which will be discussed
later) the program should fit easily within 7K - with four planets.

Documentation is given to aid conversion to other micros and the program should
RUN unaltered on a ZX80 with the 8K BASIC.


= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

Lines 30-76     PRINT the introduction. Line 35, for example,
                PRINTs one blank line.
Lines 80-85     cause the introduction to be displayed for 4000/50 (80)
                seconds. The POKE instruction simply resets the system
                variable. These lines could be replaced by a FOR/NEXT loop.
Line 90         CLS is the "Clear Screen" instruction.
Lines 100-115   assign variables to the number of radians each planet moves
                per day. The numbers are expressed in scientific notation;
                ie. 57.10e-03 = 0.0571.
Lines 120-125   pixel co-ordinates for the start position of Mercury (Hermes).
Lines 130-135   pixel co-ordinates for the start position of Venus.
Lines 140-145   pixel co-ordinates for the start position of Earth.
Lines 150-155   pixel co-ordinates for the start position of Mars.
Lines 165-180   assign variables to the "orbital radii" of each planet. The
                numbers are the number of pixels.
Lines 200-220   display the first "question". The animated display will show
                successive Earth days, months or years.
Line 225        causes the program to wait until a number (the choice) is
                entered.
Line 230        checks to see if the number entered is a 1, 2 or 3. If it is
                then the program continues at line 245. If not, then a
                reminder is PRINTed (line 235) and the program returns to the
                INPUT statement at 225.
Lines 250-260   choose the period incrementing factor (in days).
Line 265        sets the period counter to one.
Lines 300-305   display the second "question". How many days, months or years
                are to be displayed?
Line 315        makes the number entered at line 310 an integer if it was a
                decimal. It has no effect if the number was already an integer.
                Note that the number must be greater than one for the program
                to continue.
Line 335        displays the third "question". What real-time time delay is
                required between successive "frames" of the animation?
                Line 345 prevents the delay from being zero seconds. Line 350
                converts the figure entered into a number used by the PAUSE
                instruction.
Lines 415-443   DIMension 8 arrays (2 per planet) to hold the pixel co-
                ordinates for PLOTting and UNPLOTting. The first array in each
                case holds X-coords, the second Y-coords.
Lines 445-520   calculate the positions that each of the four planets will be
                at during the simulation. Lines 450, 470, 490 and 510
                calculate X pixel co-ordinates, whilst Lines 455, 475, 495 and
                515 calculate Y pixel co-ordinates.
Lines 525-540   "black-in" the starting positions of the planets.
Line 545        sets the main loop counter to one.
Line 550        increments the period counter.
Lines 560-575   display the positions of the planets during the simulation.
Line 587        checks to see if the required number of days/months/years have
                been displayed. If they have then the program jumps to line 700.
Lines 590-605   "black-in" the positions of the planets during the simulation.
Line 610        increments the loop counter.
Line 620        returns the loop.

PROGRAM BETWEEN LINES 700 AND 999 ONLY WORKS
WHEN THE MAIN SIMULATION HAS FINISHED.

Lines 700-706   PRINT the fourth "question" down the right hand side of the
                screen.
Line 710        waits until a letter is entered. Line 715 causes the program
                to jump to line 730 if a "Y" is entered. If an "N" is entered
                then the program STOPs, otherwise the program waits at the
                INPUT statement at line 710.
Lines 735-780   display the fifth "question" and wait for a proper INPUT at
                line 775.
Lines 790-840   execute the various subroutines.
Line 999        causes the program to halt. Equivalent to an END statement.

SUBROUTINE AT LINE 1000:
                "blacks-in" the left 3/4 of the screen. Line 1010 contains 23
                inverse spaces. Line 1025 puts the sun (an inverse asterisk)
                in the centre of the black square.
SUBROUTINE AT LINE 1050:
                displays the planets in their starting positions.
SUBROUTINE AT LINE 1100:
                displays the period.
SUBROUTINE AT LINE 1145:
                removes any print statements on the right-hand side by PRINTing
                blank lines. 9 spaces are contained in the string in line 1155.
SUBROUTINES AT LINES 1495,1595, 1695 and 1795:
                contain the different pieces of data on each of the four planets.
SUBROUTINE AT LINE 1995:
                PRINTs the general headings for the data.
SUBROUTINE AT LINE 2100:
                converts plot co-ordinates to PRINT AT co-ordinates and then
                displays each planet's initial letter by the pixel square
                representing it on the display.
                Line 2145 contains an inverse "H".
                Line 2150 contains an inverse "V".
                Line 2155 contains an inverse "E".
                Line 2160 contains an inverse "M".


= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

The Display

(a) PRINT AT co-ordinates:
    The ZX81 PRINT AT statement is of the form -
    9999 PRINT AT (line),(column);"(whatever is to be PRINTed)" - where:
    line numbers are from 0 to 21 inclusive.
    column numbers are from 0 to 31 inclusive.
(b) PLOT/UNPLOT co-ordinates:
    The ZX81 PLOT/UNPLOT statements are of the form -
    9999 PLOT (X pixel coord),(Y pixel coord) ... "blacks-in" pixel
    9999 UNPLOT (X pixel coord),(Y pixel coord) ... "whites-out" pixel - where:
    X coords are from 0 to 63 inclusive
    Y coords are from 0 to 43 inclusive

Normally, the ZX81 prints BLACK ON WHITE. During the simulation, the first 23
columns (down all 22 lines) are "blacked-in" (Line 1010).

So that the planets and sun can be seen on the black background an UNPLOT
statement DISPLAYS the planet, whilst a PLOT statement will "black-in" the
square again. If your computer normally writes WHITE ON BLACK then it may be
found better to make the right hand side of your screen WHITE with your inverse
spaces. If you do so remember to change all writing in PRINT statements after
line 620 to your inverse graphics, delete lines 1000, 1005, 1010 and 1015, and
change the characters in lines 1025, 2145, 2150, 2155 and 2160 to your "normal"
and NOT inverse characters.

It may have been noticed that in lines 560-575 and 590-605 the Y coords are
being deducted from 44 (The greatest Y pixel coord). This causes the planets to
revolve ANTICLOCKWISE about the sun. If the "44 - " is omitted then the planets
revolve CLOCKWISE. All PRINT AT, PLOT/UNPLOT statements are referenced to the
top LEFT-HAND corner of the screen.


= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

Space Saving

If the program IS to be used as part of some space-borne adventure game then
its length will undoubtedly want to be shortened. I suggest the following
course of action:
1. Remove the REM statements.
2. Remove the introduction and the first THREE "questions".
3. Replace the INPUT statements for the three "questions" by LETs.
4. Put variables AH, AV, AE, AM, SXH & SYH, SXV & SYV, SXE & SYE, SXM & SYM,
   RH, RV, RE and RM into their respective routines.
5. Reduce the number of planets.)
Again there is no reason why the planets should be called Mercury, Venus or
whatever. The program was written in a "modular" form to aid conversion but
this does make it rather lengthy.


**********************************************************************
