A.N.A.L.O.G. ISSUE 14 / NOVEMBER 1983 / PAGE 70

Retrofire

by Tom Hudson

16K cassette 24K disk

This issue, A.N.A.L.O.G. continues its series of public-domain assembly-language game programs with Retrofire, a game of skill for one player.

Typing the program.

Before typing anything into your computer, take a look at the listings accompanying this article.

Listing 1 is the main data and data checking routine. This listing is used to create both cassette and disk versions of Retrofire. The data statements are listed in hexadecimal (base 16), so the program will fit in 16K cassette systems. This makes typing rather difficult, but it’s a necessary evil.

Listing 2 must be added to Listing 1 if you are using a 410 or 1010 cassette recorder.

Listing 3 must be added to Listing 1 if you are using a disk drive.

Listing 4 is the assembly-language source code for Retrofire, created with the ATARI Macro Assembler. You DO NOT have to type in this listing to play the game! It is provided for those readers interested in assembly language.

Follow the instructions below to make either a cassette or disk version of Retrofire.

Cassette instructions.

  1. Type Listing 1 into your computer and verify your typing with C:CHECK. (See page 58.)
  2. After Listing 1 has been entered into your computer, type in Listing 2. The program lines will merge with Listing 1. Make sure these lines were typed correctly. It’s a good idea to CSAVE the entire program at this point.
  3. Type RUN and press RETURN. The program will begin checking the DATA lines, printing the line number as it checks each one. It will alert you if it finds any problems. Fix any incorrect lines and re-RUN the program if necessary until all errors are eliminated.
  4. When all data lines are correct, the program will ask you to “READY CASSETTE AND PRESS RETURN.” Place a blank tape in your recorder, press RECORD and PLAY simultaneously and press RETURN. The message “WRITING FILE” will appear and the program will create a boot tape version of Retrofire, printing each DATA line number as it goes. When the READY prompt appears, you’re ready to load and play the game. Make sure your BASIC program has been CSAVED before continuing.
  5. From this point on, whenever you want to play Retrofire, do the following: Rewind the tape created by the BASIC program to the beginning. Turn your computer OFF and remove any cartridges. Press PLAY on your recorder, then turn your computer ON while holding down the START key. The computer will BEEP once. Press RETURN and Retrofire will load and run automatically.

Disk instructions.

  1. Type Listing 1 into your computer and check it with D:CHECK II (see p. 58) to eliminate any typing errors.
  2. After Listing 1 is correctly typed into your computer, type in Listing 3. The lines in this listing will merge with those in Listing 1. It’s a good idea to SAVE the entire BASIC program at this point.
  3. Type RUN and press RETURN. The program will begin verifying the DATA lines, printing the line number of each as it goes. It will alert you if it finds any problems. Fix incorrect lines and re-RUN the program if necessary until all errors are eliminated.
  4. When all the date lines are correct, the program will ask you to “INSERT DISK WITH DOS, PRESS RETURN.” Place a disk with DOS in drive 1 and press RETURN. The message “WRITING FILE” will appear and the program will create an AUTORUN.SYS file, printing each data line number as it goes. When the READY prompt appears, you’re ready to play the game. Make sure your BASIC program has been SAVEd before continuing.
  5. To play Retrofire, place the disk containing the AUTORUN.SYS file in drive 1. Turn the computer OFF, remove any cartridges and turn the computer ON. Retrofire will load and run automatically.

The game.

Your spacecraft was orbiting Jupiter when suddenly the radiation shielding failed. Forced to eject in an escape capsule, you must now land on Io, the only moon with a safe landing area. Your computers are able to take you to within 20,000 feet of the surface, where you must take the controls for the final approach and landing. Along with the obvious danger of crashing into the surface, you must avoid intense radiation from Jupiter and erupting volcanoes on Io’s surface!

Retrofire requires one joystick in port 1.

When the game begins you will be shown a display of your escape pod’s console, with the game credits. You have two factors that influence game difficulty, GRAVITY and FUEL.

The gravity level can be set to L (low), M (medium) or H (high). Low gravity is recommended for beginners. Select the desired gravity level by pressing the OPTION key.

The fuel level can range from 5,000 to 14,000 units. Select the desired fuel amount by pressing the SELECT key. Normal gravity/fuel amounts are: Low gravity, 7,000 units; Medium gravity, 10,000 units; and High gravity, 14,000 units.

There is one other option before beginning the game. The “C” key on the keyboard will toggle the playfield colors, enabling you to select the color combination you prefer.

Once you have selected the game difficulty, press START to begin the game.

The Retrofire display.

Figure 1 shows the Retrofire game display. This screen shows you all the information necessary to safely land your escape pod.

[game display]
Figure 1

Starting at the upper right side of the display, you will see a box with the word “RADIATION.” This is a vertical bar graph indicating the amount of radiation you have accumulated on your descent. The higher your ship is in Io’s thin atmosphere, the faster you accumulate radiation from Jupiter’s radiation belt, so it’s a good idea to get to a lower altitude as fast as possible.

Radiation can also be accumulated from Io’s many volcanoes, described below.

If the radiation level ever gets too high, your ship’s vital electronics will overload, and the craft will explode.

To the left of the radiation display is the navigational position readout. This display shows your ship’s coordinates as well as the coordinates of the landing pad.

While the base’s position is always known, at above 1,000 feet the navigational computer can only provide an approximation of your ship’s position. Once you pass below 1,000 feet, the computer must use landmarks to show your exact position. When you match your coordinates to the base’s coordinates, you are directly over the base and can land safely.

Below the navigational position displays are your five most important readouts.

The ALT reading shows your ship’s altitude (in feet) in relation to the landing pad. Beware: Mountain heights are not taken into account here!

The next three readouts are what make Retrofire different from other “Lunar Lander” type programs: three dimensions!

These three readings are the X, Y and Z velocities of your ship in feet per second. To the left of each velocity reading is an arrow indicating the direction of movement. The axis labeling in non-standard, so read carefully.

The X velocity (XV) tells how fast your ship is going up or down. If the arrow is pointing up, you are ascending. If it is pointing down, you are descending. Pushing your joystick up will fire the main retrorockets, slowing your descent. Pushing the stick down will force you down toward Io’s surface. The X velocity MUST be lower than 11 feet per second for a safe landing.

The Y velocity (YV) tells how fast your ship is going to the right or left over the terrain grid (described below). Once again, the arrow to the left of the velocity value indicates the direction of movement. Push your stick to the left to decrease the Y velocity and to the right to increase it. Your Y velocity MUST be lower than 6 feet per second for a safe landing.

The Z velocity (ZV) tells how fast your ship is going diagonally over the terrain grid, the third dimension in this game. You can think of this dimension as depth into your TV screen. Push your stick to the lower left to decrease this value and to the upper right to increase it. Your Z velocity MUST be lower than 6 feet per second for a safe landing.

Your ship has a “terminal velocity” of 500 feet per second. That is, your ship cannot go faster than 500 feet per second in any direction, no matter how much you try.

To the right of each velocity indicator is a color-coded engine temperature light. When green, the engine temperature is OK, and the engine is working normally. As you fire each engine, it heats up. When the engine is not being fired, it will cool down. Wise use of the engines will keep the engines cool and safe.

If, however, you fire an engine for too long, it will begin to overheat. As the engine heats up, the temperature light will go from green to yellow to red. As the engine heats up to the yellow and red zones, it will begin to fail, losing efficiency. If the engine is forced to operate in the red zone too long, the indicator will turn dark gray, indicating engine burnout. If this happens, the engine is dead and you will probably crash. Whenever the temperature status of an engine changes, you will be alerted with a short tone.

Below the velocity indicators is the ship’s fuel level. As you fire the engines, fuel is subtracted from your initial supply. When your fuel supply drops below 1000 units you will receive a warning message and a tone. If the fuel level reaches zero, an “OUT OF FUEL” message is displayed with a lower pitch tone.

Directly below the fuel indicator is a display showing the number of ships you have left.

The game score is shown below the number of ships left. Each time you land safely, you are awarded ten points for each unit of fuel remaining. This feature is primarily for competition between two players.

The largest area of the display is the graphic terrain display on the left side of the screen. This display shows the terrain directly below your ship. Your ship is displayed as a white square over the terrain grid, with a gray “shadow” on the grid to indicate your exact position and the terrain height below your ship.

Your objective is to land in the grid square which contains your landing pad, indicated by a flashing red “+.”

As your ship begins its descent, the terrain will appear very flat. This is because surface details cannot be seen at this altitude. As your ship descends below 800 feet, the computer will “zoom in” on the square your ship is over, enlarging it to a new 7×7 grid. At this point, terrain detail will begin to show up. You will notice that your spacecraft appears to move faster at this magnification, due to the “zoom” effect.

As your ship descends below 1000 feet, once again the computer will “zoom in” on the square below your ship, enlarging it to a new 7×7 grid. This is the final stage of your approach toward the surface. At this magnification level you must pay close attention to the terrain and your shadow. Your shadow indicates how close you are to the ground, and if your ship hits any peaks, you will be destroyed. A good rule of thumb is to cruise over the surface at an altitude of around 500 feet.

While you are below 1000 feet, you must watch out for volcanoes. These erupting mountains constantly spew radioactive debris. If your ship passes directly over a volcano at an altitude of less than 500 feet, you will be exposed to a potentially lethal dose of radiation. It’s a good idea to keep an eye on your radiation indicator at this point. The number of volcanoes increases each time you land successfully.

At the top of the graphic display window is a warning message area. This area will display fuel warning and other messages as necessary.

If you need to pause the game during descent, simply press the space bar. The game can be resumed by pressing the space bar a second time.

Some notes on playing Retrofire.

Those who are expecting Retrofire to be a fast-action shoot-em-up are in for a surprise. This is a fairly realistic simulation program with game elements, not something you’d expect to find in an arcade.

Retrofire can be quite difficult on the higher gravity settings but with practice it can be mastered.

Listing 1.

1 REM *** RETROFIRE ***
10 DATA 0,1,2,3,4,5,6,7,8,9,0,0,0,0,0,0,0,10,11,12,13,14,15
20 DIM DAT$(91),HEX(22):FOR X=0 TO 22:READ N:HEX(X)=N:NEXT X:LINE=990:RESTORE 1000:TRAP 60:? "CHECKING DATA"
25 LINE=LINE+10:? "LINE:";LINE:READ DAT$:IF LEN(DAT$)<>90 THEN 110
28 DATLIN=PEEK(183)+PEEK(184)*256:IF DATLIN<>LINE THEN ? "LINE ";LINE;" MISSING!":END 
30 FOR X=1 TO 89 STEP 2:D1=ASC(DAT$(X,X))-48:D2=ASC(DAT$(X+1,X+1))-48:BYTE=HEX(D1)*16+HEX(D2)
35 IF PASS=2 THEN PUT #1,BYTE:NEXT X:READ CHKSUM:GOTO 25
40 TOTAL=TOTAL+BYTE:IF TOTAL>999 THEN TOTAL=TOTAL-1000
45 NEXT X:READ CHKSUM:IF TOTAL=CHKSUM THEN 25
50 GOTO 110
60 IF PEEK(195)<>6 THEN 110
100 ? "WRITING FILE":PASS=2:LINE=990:RESTORE 1000:TRAP 60:GOTO 25
110 ? "BAD DATA: LINE ";LINE:END 
1000 DATA 488A48A6C5BD201C8D0AD48D15D0E6C568AA6840A9288590A900858FA90885B3A90085B2A000B18F91B2C8D0F9,856
1010 DATA E690E6B3A590C940D0EF4C3A08A2BEA90F9D001FCAD0FAA9708D001F8D011F8D021FA94F8D031F8D6B1FA9208D,30
1020 DATA 051FA9108D041FA9308D6D1FA9008D6C1FA9418DBC1FA91F8DBE1FA9008DBD1FA98F8D1F1F8D391F8D761F8D80,363
1030 DATA 1F8D8A1FA9018DCE1AD82065E4200413A900A27F9580CA10FB8D2F028D0ED48D08D28DC6028DC80220EE12A9FF,395
1040 DATA A2059D91079D9B079DA507CA10F4A97385DF206511A210BDD61A95EB9D251CCA10F5A90A8DC502A90F8DC002A9,654
1050 DATA 048DC102A9C08D03D0A9088D0102A9008D0002A9008D3002A91F8D3102A9008D07D4A215A0A1A907205CE4A93E,884
1060 DATA 8D2F02A9038D1DD0A9C08D0ED4A9028598A20086BFBDC41848BDD31848BDE21848BDB518F00F68858368858168,270
1070 DATA 85852087174C4F09688582688580688584201817A6BFE8E00FD0CBA24986A4BDF11885A1BD3B1985A2BD851985,638
1080 DATA A3208E13A6A4CA10E7AD0AD2291F18692885B6AD0AD2291F18692885B8A900A2059D821CCA10FA8D361C8D371C,239
1090 DATA 8D381C8D391CA9C48D221C8D231C8D241CA97985E6A90F8D7907A900A22F9D0007E8E07A90F820251220321220,504
1100 DATA 4512205B12207112207E12208B12A90085AE204413200A14201C13201F14ADCE1AF006CECE1A4CD40BA5E8D0FC,324
1110 DATA A5AAF0034C570FA90185AA854DA5EBC9039004A90085E7A5E7D025A5E5D009A6AEBDF91BF01A85E7A5E6C930B0,555
1120 DATA 034CBD0A38E90185E6AAA90F9D0007A90085E5F8AD361CF0064CB00C4CC90CA5AD38E5EF85ADA5EDE5EE85EDA5,409
1130 DATA ECE90085ECA5EBE90085EBC99090E0D8A5EE05F105F3D05CA5EFC911B056A5F2C906B050A5F4C906B04AA5CCC5,560
1140 DATA DCD044A201A00E206813A9FF85AAA5AAD0FCA20306F726F626F5CA10F7F8A20218B5F575F995F9CA10F7D8208B,998
1150 DATA 12A9F085AAA5AAD0FCA5DFC9FFF00818690A85DF2065114CA00CA5E6C92FD004A205D002A202A00E206813A5BE,588
1160 DATA 38E922A2139DB31CCA10FAA5BA38E9300AA2139D9F1CCA10FAA90085BA85BEA213AD0AD209109DC71CAD0AD209,811
1170 DATA 109DDB1CA9009DEF1C9D031DAD0AD20910293F9D8B1CCA10DB3004A5AAD0FCA90185AAA2138E171DBD8B1CF036,641
1180 DATA BD9F1C8580BDB31C8582203117A000BDB118518F918FAE171DDE8B1CF018BDC71C187DEF1C9DEF1C08E00AB00C,668
1190 DATA 28BD9F1CE9004C690B4C9A0B28BD9F1C69009D9F1CC9C0B033C90A902F8580BDDB1C187D031D9D031DBDB31CE9,333
1200 DATA 009DB31CC90A90178582203117A000BDB118518F918FAE171DCA300D4C220BAE171DA9009D8B1CF0EDA213A900,660
1210 DATA 1D8B1CCA10FAC900F0034C180BA9FF85AAA5AAD0FCC6F830034C9D0CA200A00E206813ADFC02C912D014AEAA18,876
1220 DATA ADAB188DAA188EAB18A9FF8DFC024C3A08A208A01E206813A209A02D206813A20AA037206813AECF1ABDD31A8D,439
1230 DATA 831AA207A04B206813ADCC1A09108D6A1AADCD1A09108D6B1AA206A055206813A5AAD0FCAD1FD0C907F09EC906,147
1240 DATA F049C903D012ADCF1A186901C903D002A9008DCF1A4C7C0CADCD1A1869018DCD1AC90AD00EA9008DCD1AADCC1A,878
1250 DATA 1869018DCC1AADCC1AF00CADCD1AC905D005A9008DCC1AA91E85AA4CD40BAD1FD0C907D0F9ADCC1A8DE01AADCD,447
1260 DATA 1A0A0A0A0A8DE11A4C9008207E12A20CBDD61A95EB9D251CCA10F54C7109A5AD1865EF85ADA5ED65EE85EDA5EC,699
1270 DATA 690085ECA5EB690085EBD8202512201610A200A5EBD00CA202A5ECDDA6189003CAD0F6E4AEF052B02986AEA901,399
1280 DATA 85C1A5B620DB0FB5D60A0A0A0A1865B485B6A5B820DB0FB5D90A0A0A0A1865B485B84C2F0D86AEA90185C1A5B6,355
1290 DATA 20C40F85B698A6AE95D5A5B820C40F85B898A6AE95D8201C13200A14201F14AD281CC905F02BF8AD2A1C18AECF,383
1300 DATA 1A7DD01A8D2A1C85F0AD291C69008D291C85EFAD281C69008D281C85EEA203A00020CB11203212AE780286ABBD,674
1310 DATA 1D1BD0034C3B0EA5F505F605F7D01FA5EA2901D016A5EA090185EAA9FF8D04D2A91485E9A204A00E2068134CD9,811
1320 DATA 0DA5F5D022A5F6C910B01CA5EA2902D016A5EA090285EAA9508D04D2A91485E9A203A00E206813A4ABBE1D1BBC,179
1330 DATA 871CB9F51BF005CD0AD2B0034C3B0EA90A85C3E6B1A5B12901D08FF8A5F738E90285F7A5F6E90085F6A5F5E900,443
1340 DATA 85F5D8207112A6ABBD5D1B85A8BD4D1B85A9BC2D1BC999F00AB9251CC905F0214C2B0EB9251CC995D007B9261C,534
1350 DATA C900F010BC3D1BBD2D1BAA20B511204512205B12A00620E90FA6AEBCAA1B4690668F88D0F9AD371CD00EA5B718,261
1360 DATA 658F85B79010E6B64C6A0EA5B738E58F85B7B002C6B6A90085C085C2A5B6C9B4B026C970904338E97085B6A6AE,582
1370 DATA F014B5D5186901C907D009A90095D5CAD0F0300295D5E6C04CBD0E18697085B6A6AEF012B5D538E9011009A906,123
1380 DATA 95D5CAD0F2300295D5E6C0A90185C2A6AEA5B64A4A4A4A95D6A900E8E003F00495D6D0F7A00220E911A00820E9,381
1390 DATA 0FA6AEBCAA1B4690668F88D0F9AD381CD00EA5B918658F85B99010E6B84C060FA5B938E58F85B9B002C6B8A5B8,264
1400 DATA C9B4B02AC970904738E97085B8A6AEF014B5D8186901C907D009A90095D8CAD0F0300295D8E6C0A90285C24C57,343
1410 DATA 0F18697085B8A6AEF012B5D838E9011009A90695D8CAD0F2300295D8E6C0A90385C2A6AEA5B84A4A4A4A95D9A9,274
1420 DATA 00E8E003F00495D9D0F7A00320E911A5C0F03B201C13A6C2BCAD1BA9078591BEB11BBD3A1CA6919D7A1C88C691,946
1430 DATA 10F0200A14A6C2BCAD1BA9078591A691BD7A1CBED11B9D3A1C88C69110F0201F14AD1FD0C907D0034CEB09AD1F,958
1440 DATA D0C907D0F94C3A08A000C910900738E910C84CC60F85910A1865910A65916085B4A90785B5A90020A411A6AE60,826
1450 DATA B9EC00290F858FB9EC004A4A4A4AAAA58F187D6D1B858FB9EB00290FAAA58F187D811B858FA9007D771B859060,683
1460 DATA EAA5ED290F85B2A90085B3A5ED4A4A4A4AAAA5B2187D6D1B85B2A5EC290FAAA5B2187D811B85B2A5B37D771B85,308
1470 DATA B3A5EC4A4A4A4AAAA5B2187D951B85B2A5B37D8B1B85B3A5EB290FAAA5B2187DA31B85B2A5B37D9F1B85B346B3,115
1480 DATA 66B246B366B2A6AEBDA71B85B5A5B285B4A5B320A411A5B84A4A85BFA5B64A1865BF18693885BAA5B84A85BFA9,152
1490 DATA C938E5BF85BF38E5B485BEA5B64A48290785CAA90738E5CA85CA6829F885CCA5B84A48290785CBA90738E5CB85,221
1500 DATA CB684A4A4A1865CC85CCC5E2D016A5E3F012A5EBD00EA5ECC905B008A90185E5A90085E7A6CCBD3A1C85CDBD3B,428
1510 DATA 1C85CEA5CB85C720341185CFA6CCBD421C85CDBD431C85CEA5CB85C720341185CEA5CF85CDA5CA85C720341185,333
1520 DATA CFA5BF38E5CF85BCC5BEB0034CBD0A60A5CDC5CE901138E5CE85C6208A11A5C84A4A4A1865CE60A5CE38E5CD85,597
1530 DATA C6A90838E5C785C7208A11A5C84A4A4A1865CD60A205AD0AD22907C907F0F795D0CA10F2A5D20A0A0A1865D585,984
1540 DATA DCA00020E911A00120E91160A90085C9A2080A26C906C690071865C79002E6C9CAD0EF85C860A20806B42AC5B5,217
1550 DATA 9004E5B5E6B4CAD0F260F8BD261C1865A89D261C95ECBD251C65A99D251C95EBC950B007A90099361CD860A900,816
1560 DATA 38FD261C95ECA900FD251C95EBA901D0E8B9031C85A2BE071CB4D0B90B1C85FCB9121C85FDB4D1B9191CF81865,407
1570 DATA FD85FDA5FC690085FCB5D21865FD85FDA5FC690085FCD8A90285A6A2114C9512A96285A2A90385A6A2004C9512,561
1580 DATA AD361C20C612A97085A2A90285A6A2034C9512A902186D371C20C612A97A85A2A90285A6A2064C9512A904186D,926
1590 DATA 381C20C612A98485A2A90285A6A2084C9512A99285A2A90385A6A20A4C9512A9A085A2A90185A6A20D4C9512A9,913
1600 DATA AA85A2A90385A6A20EA91F85A186A5A6A5B5EB20A912E6A5C6A6D0F36085A74A4A4A4A091085A3208E13E6A1A5,756
1610 DATA A7290F091085A3208E13E6A160484AAABD171B859EBD1A1B859FA000680A0A0AAAA90785A6BDE71A919EE89818,456
1620 DATA 6928A8C6A6D0F160A900A899000399000499000599000699000788D0EE60A21DA9208590A900858FA8918F88D0,397
1630 DATA FBCAD00160E690D0F2A90085BAA92F8590A9B2858FA248A015A900918F8810FBCAD00160A58F186928858F90EA,496
1640 DATA E690D0E6A9228590A942858FA208A015A900918F8810FBCAD00160A58F186928858F90EAE690D0E684A2BCCF19,674
1650 DATA A90285A1A21686AF84B0A6AFA4B0B9DA1985A3208E13C6AFD00160E6A1E6B0D0E9A5A2858FA9008590068F2690,834
1660 DATA 068F2690068F2690A58F186910859EA5906920859F068F2690068F2690A58F18659E859EA590659F859FA59E18,730
1670 DATA 65A1859E9002E69FA5A3858FA900859085A0068F2690068F2690068F2690A5901869E08590A4A0B18FA000919E,200
1680 DATA E6A0A5A0C908F00DA59E186928859E90E7E69FD0E360A23FA4AEAD0AD2290FD9A318B0F69D3A1CCA10F060D8A9,475
1690 DATA 0085E3A2008A9D0006CAD0FAA6AEF013A200B5D6D5D0D053B5D9D5D3D04DE8E4AED0EFA6AEB5D30A0A85BFB5D0,479
1700 DATA 0A0A0A1865BF18693D8D02D0B5D30A0A0A85BFA9C438E5BFA8A204BDFC1B990006C8CA10F6A6AEE002D013A6DC,757
1710 DATA A9009D3A1C9D3B1C9D421C9D431C4CE514A5AEC902D053AD0AD2C5DFB04CAD0AD22907C905B0F718690185E1AD,870
1720 DATA 0AD22907C905B0F718690185E00A0A0A1865E185E2A5E10A0A85BFA5E00A0A0A1865BF18693B85E3A5E10A0A0A,430
1730 DATA 85BFA9BA38E5BF85E4A6E2A9074C7D14A9018598A9108599A90085848585859C859AA900859BA8A59918659A99,312
1740 DATA 8000A9AA38E59B38A69CFD3A1C998200A59BD0062018174C1F15208717A5991869088599E69CA001A59B186908,895
1750 DATA 859BC93990C7A9108599A59A186910859AC97190B3A900859BA9FF859DE69DA59D859CA900859AA8A59918659A,33
1760 DATA 998000A9AA38E59BA69C38FD3A1C998200A59AD0062018174C7A15208717A59C186908859CA001A59A18691085,619
1770 DATA 9AC97190C9A5991869088599A59B186908859BC93990AC60D8A90085C5ADFC02C921D00BA5E849FF85E8A9FF8D,838
1780 DATA FC02A5E8F0034C62E4ADC302186901290709308DC302A5AAF002C6AAA5E7F002C6E7A5E3F0298D02D0AD0AD22D,551
1790 DATA 0AD2A4E4990006990406AD0AD22D0AD2990206AD0AD2293C990606A93A8DC202D015E6DDA5DD290FD00DE6DEA5,487
1800 DATA DE2901AABD011C8DC202A6BBA9FC3D00039D0003A9FC3D01039D0103A6BDA9F33D00039D0003A9F33D01039D01,747
1810 DATA 03A5BA8D04D08D05D0A6BE86BBA9021D00039D0003A9021D01039D0103A6BC86BDA9081D00039D0003A9081D01,466
1820 DATA 039D0103A9828D00D2A9088D02D2A5C38D01D24A4A4A8D03D2E6C4A5C42907D006A5C3F002C6C3AE7802BD1D1B,683
1830 DATA 85ACF01DAACABD851CC918B014BD821C1869019D821CBD851C69009D851C20FB16A202C6ACE4ACF026BD851CC9,33
1840 DATA 18B01FC900D007BD821CC9029014BD821C38E9029D821CBD851CE9009D851C20FB16CA10D3A5E9F00B38E90185,54
1850 DATA E94A09A08D05D24C62E4291F4A4A4A9D881CA8B9F11BDD221CF00B9D221CA91485E90A8D04D260203117A498BD,902
1860 DATA B11839A9188591BDAD18A000318F0591918F60A5820A858FA9002A8590068F2690068FA58F85922690A5908593,810
1870 DATA 068F2690068F2690A58F186592858FA59065938590A91018658F858FA92065908590A58029074AAAA5844AA580,862
1880 DATA 6A4A4A18658F858FA5906900859060A583C582900B38E582858CA901858ED00BA58238E583858CA9FF858EA585,558
1890 DATA C584901BD006A581C5809013A58138E580858AA585E584858BA901858DD011A58038E581858AA584E585858BA9,710
1900 DATA FF858DA9008588858685878589A58BD006A58AC58C9017A58B85978595A58A85968594A5954AA5946A85884C0F,711
1910 DATA 18A90085978595A58C859685944A8586A5960597D00160A58818658C8588A58969008589C595901CD006A588C5,198
1920 DATA 949014A58838E5948588A589E5958589A58218658E8582A58618658A8586A587658B8587C595903AD006A586C5,183
1930 DATA 949032A58638E5948586A587E5958587A58D30141002D0A5A58018658D8580A584690085844C8E18A58038E901,547
1940 DATA 8580A584E9008584201817A59638E9018596A597E90085970596D0CD600104080080100055AAFF3FCFF3FCC030,739
1950 DATA 0C030001010101000100010001000100010001010000000000010100000101010A36360A0AC0C0C03636C0C020,8
1960 DATA 20200A0AB4B40A0AB45E5E9D9D35350B5D1B1C1D1E1F191A1B1C1D191A1B1C1D191A1B1C1D1E1F202122191A1B,152
1970 DATA 1C1D191A1B1C1D191A1B1C191A1B191A1B191A1B191A1B1C1D191A1B1C1D1E191A1B1C1D1E2525252525252525,445
1980 DATA 2510101010101E1E1E1E1E28282828283A3A3A3A3A3A3A3A3A3A48484848485252525252626262627070707A7A,234
1990 DATA 7A8484849292929292A0A0A0A0A0A0AAAAAAAAAAAA111921293139414951332829301A39302F331A3A302F331A,568
2000 DATA 2F222A2523342936251A39302F331A3A302F331A212C341A38361A39361A3A361A2635252C1A33282930331A33,504
2010 DATA 232F32251A322124292134292F2E00162C42586E849AB0C6DC00000000000027212D25002F3625320000000000,630
2020 DATA 000000003335232325333326352C002C212E24292E270000000000262134212C00332829300023322133280000,952
2030 DATA 00002635252C002C2536252C00233229342923212C000000000000002F3534002F26002635252C000000000000,80
2040 DATA 0000322124292134292F2E002F3625322C2F212400000000000000002635252C1A000000101010000000000000,53
2050 DATA 0000000000273221362934391A0000000000000000000000000000322534322F26293225010000000000000000,808
2060 DATA 000022791A00346F6D00287564736F6E00000000000000212E212C2F2700236F6D707574696E67000000000500,19
2070 DATA 000A18302C2D280200000000000000000001000002000000001818187E3C180000183C7E1818180000180C7E7E,87
2080 DATA 0C18000018307E7E301800003C1C3464C0000000000C98B0E0F000AD3DCD313334000000000000030200030002,356
2090 DATA 000101000000000000000806000800060003030000000000000002010002000100000000000000000000000000,398
2100 DATA 9900990000990000000000000001010099009900019900000A141E28323C46505A000000010101020203030064,882
2110 DATA C82C90F458BC20840003070B0F13171B1F2300E8D0B8A0887058402800274E7500102030581603070401070F17,849
2120 DATA 1F38393A3B3C3D3E3F0001020304050607070F171F272F373F0008101820283038000102030405060738393A3B,146
2130 DATA 3C3D3E3F0008101820283038070F171F272F373FC4163402FFC85A0078FF008040F02010003248521E28000306,851
2140 DATA 0900000001010202004998479645940007142128354216C4000000000000000000000000000000000000000000,966
CHECKSUM DATA
(See p. 58)
1 DATA 883,955,686,427,745,192,617,545,276,445,496,549,158,838,360,8164
1820 DATA 262,191,90,722,60,802,965,818,722,119,175,234,47,59,134,5400
1170 DATA 136,137,207,899,90,108,995,291,428,213,923,42,160,921,937,6487
1320 DATA 111,204,113,909,31,858,964,184,928,963,983,38,771,167,225,7449
1470 DATA 213,133,178,272,189,423,978,759,16,231,22,694,753,57,44,4962
1620 DATA 633,21,40,7,789,733,131,276,138,53,934,994,749,106,822,6426
1770 DATA 197,933,200,978,658,4,284,129,113,697,696,953,796,910,682,8230
1920 DATA 775,701,645,666,830,697,476,704,306,162,873,59,2,614,340,7850
2070 DATA 201,116,424,770,384,230,428,639,3192

Listing 2.

2 REM *** CASSETTE VERSION ***
65 IF PASS=2 THEN FOR X=1 TO 33:PUT #1,0:NEXT X:CLOSE #1:END 
70 ? "READY CASSETTE AND PRESS RETURN";:OPEN #1,8,128,"C:":RESTORE 200:FOR X=1 TO 40:READ N:PUT #1,N:NEXT X
200 DATA 0,41,216,7,255,7,169,0,141,47,2,169,60,141,2,211,169,0,141,231,2,133,14,169,56,141,232,2
210 DATA 133,15,169,58,133,10,169,8,133,11,24,96

Listing 3.

2 REM *** DISK VERSION ***
65 IF PASS=2 THEN PUT #1,224:PUT #1,2:PUT #1,225:PUT #1,2:PUT #1,20:PUT #1,40:CLOSE #1:END 
70 ? "INSERT DISK WITH DOS, PRESS RETURN";:DIM IN$(1):INPUT IN$:OPEN #1,8,0,"D:AUTORUN.SYS"
90 PUT #1,255:PUT #1,255:PUT #1,0:PUT #1,40:PUT #1,54:PUT #1,60

Listing 4.

;	======================
;	      RETROFIRE!
;
;	    BY: TOM HUDSON
;	A.N.A.L.O.G. COMPUTING
;	======================

;	---------------
;	PAGE ZERO USAGE
;	---------------

	ORG	$80

PLOTX	DS	1	;PLOT X VALUE
DRAWX	DS	1	;DRAW X VALUE
PLOTY	DS	1	;PLOT Y VALUE
DRAWY	DS	1	;DRAW Y VALUE
PLXHI	DS	1	;PLOT X HI BYTE
DRXHI	DS	1	;PLOT Y HI BYTE
ACCX	DS	1	;DRAW X ACCUMULATOR
ACCXHI	DS	1
ACCY	DS	1	;DRAW Y ACCUMULATOR
ACCYHI	DS	1
DELTAX	DS	1	;DRAW WORK
DELXHI	DS	1	;DITTO
DELTAY	DS	1	;DITTO
INCX	DS	1	;DRAW X INCREMENT
INCY	DS	1	;DRAW Y INCREMENT
LO	DS	1	;INDIRECT ADDRESS
HI	DS	1
HOLD	DS	1	;TEMP STORAGE
LOHLD	DS	1
HIHLD	DS	1
ENDPT	DS	1	;DRAW ENDPOINT
ENDHI	DS	1
COUNTR	DS	1	;DRAW COUNTER
CNTHI	DS	1
COLOR	DS	1	;PLOT COLOR
XOFSET	DS	1	;PLOT X OFFSET
X	DS	1	;GRID COORD...
Y	DS	1	;HOLD AREAS
HGTIX	DS	1	;GRID HEIGHT
INDEX	DS	1	;GRID INDEX
DESTLO	DS	1	;MOVE DESTINATION...
DESTHI	DS	1	;HOLD AREA
COPCNT	DS	1	;BYTE COPY COUNT
CHARX	DS	1	;CHARACTER X LOC
CHARY	DS	1	;CHARACTER Y LOC
CHARNO	DS	1	;CHARACTER #
CHINDX	DS	1	;CHARACTER INDEX
SNUMIX	DS	1	;NUMBER INDEX
DIGITS	DS	1	;# OF DIGITS TO DISPLAY
SHOBYT	DS	1	;NUMBER HOLD
VELADL	DS	1	;VELOCITY ADD LOW
VELADH	DS	1	;VELOCITY ADD HIGH
TIMER	DS	1	;GENERAL EVENT TIMER
STKHLD	DS	1	;STICK POS. HOLD
STKPOS	DS	1	;STICK POSITION
ALTLOB	DS	1	;LOW ALTITUDE BYTE
GRDTYP	DS	1	;GRID TYPE
MSGCT	DS	1	;MESSAGE COUNT
MSGPTR	DS	1	;MESSAGE POINTER
THRCNT	DS	1	;THRUST COUNTER
BALO	DS	1	;BINARY ALTITUDE LOW
BAHI	DS	1	;BINARY ALTITUDE HI
RESULT	DS	1	;DIVISION RESULT
DIVISR	DS	1	;DIVISOR
SHIPY	DS	1	;SHIP GRID Y
SHIPYL	DS	1	;SHIP Y LOW
SHIPZ	DS	1	;SHIP GRID Z
SHIPZL	DS	1	;SHIP Z LOW
SHPLRX	DS	1	;SHIP PLAYER X POS
LASTSY	DS	1	;PREVIOUS SHIP Y
SHADOY	DS	1	;SHIP SHADOW Y
LSHADY	DS	1	;PREVIOUS SHADOW Y
SHPLRY	DS	1	;SHIP PLAYER Y
SHTEMP	DS	1	;TEMPORARY STORAGE
NEWGRD	DS	1	;NEW GRID FLAG
NOSPOS	DS	1	;NO SHIP SHOW FLAG
GRDDIR	DS	1	;SHIP'S MOVEMENT DIRECTION
THRVOL	DS	1	;THRUST VOLUME
THRTIM	DS	1	;THRUST TIME
DLICNT	DS	1	;DLI COUNTER
MULT1	DS	1	;MULTIPLY #1
MULT2	DS	1	;MULTIPLY #2
LRES	DS	1	;LOW MULT RESULT
HRES	DS	1	;HIGH MULT RESULT
SUBY	DS	1	;SHIP Y/Z
SUBZ	DS	1	;WORK AREAS
TERRIX	DS	1	;TERRAIN POSITION INDEX
T1	DS	1	;TERRAIN...
T2	DS	1	;HEIGHT...
T3	DS	1	;WORK AREAS
BASEY	DS	3	;BASE Y POSITIONS
BASEZ	DS	3	;BASE Z POSITIONS
GYP	DS	3	;SHIP Y POSITIONS
GZP	DS	3	;SHIP Z POSITIONS
BASEIX	DS	1	;BASE POSITION INDEX
PFLASH	DS	1	;PAD FLASH...
PFLIX	DS	1	;INDEXES
VCHANC	DS	1	;VOLCANO CHANCE
VOLY	DS	1	;VOLCANO Y AND Z...
VOLZ	DS	1	;POSITIONS
VOLIX	DS	1	;VOLCANO POSITION INDEX
VOLPX	DS	1	;VOLCANO PLAYER X
VOLPY	DS	1	;VOLCANO PLAYER Y
VOLRAD	DS	1	;VOLCANO RADIATION FLAG
RADLVL	DS	1	;RADIATION LEVEL
RADTIM	DS	1	;RADIATION LEVEL TIMER
PAUSED	DS	1	;PAUSE FLAG
SNDCNT	DS	1	;SOUND COUNTER
SSTATS	DS	1	;SOUND STATUSES
NUMBRS	DS	3	;ALTITUDE
	DS	3	;X VELOCITY
	DS	2	;Y VELOCITY
	DS	2	;Z VELOCITY
	DS	3	;FUEL
	DS	1	;SHIPS LEFT
	DS	3	;SCORE
POSNUM	DS	2	;SHIP/BASE POSITIONS

;	------------------
;	MISC. MEMORY USAGE
;	------------------

PMAREA	=	$0000	;PLAYERS/MISSILES
MISSLS	=	PMAREA+768
PL0	=	PMAREA+1024
PL1	=	PMAREA+1280
PL2	=	PMAREA+1536
PL3	=	PMAREA+1792
DLIST	=	$1F00	;DISPLAY LIST
DISP	=	$2010	;TOP OF DISPLAY
DISP2	=	$3000	;BOTTOM DISPLAY

;	--------------
;	SYSTEM EQUATES
;	--------------

VDSLST	=	$200	;DLI POINTER
WSYNC	=	$D40A	;WAIT FOR SYNC
KEY	=	$2FC	;KEYBOARD KEY
CONSOL	=	$D01F	;CONSOLE KEYS
PMBASE	=	$D407	;P/M BASE ADDRESS
RANDOM	=	$D20A	;RANDOM NUMBER
SETVBV	=	$E45C	;VBI SETUP
XITVBV	=	$E462	;VBLANK EXIT
COLBK	=	$2C8	;COLOR REGISTERS
COLPF0	=	$2C4
COLPF1	=	$2C5
COLPF2	=	$2C6
COLPF3	=	$2C7
AUDC1	=	$D201	;AUDIO CONTROLS
AUDC2	=	$D203
AUDC3	=	$D205
AUDC4	=	$D207
AUDF1	=	$D200
AUDF2	=	$D202
AUDF3	=	$D204
AUDF4	=	$D206
AUDCTL	=	$D208
PRIOR	=	$026F	;P/M PRIOITY
ATTRAC	=	$4D	;ATTRACT MODE
DMACTL	=	$22F	;DMA CONTROL
DLISTL	=	$230	;DISP LIST POINTER
GRACTL	=	$D01D	;GRAPHICS CONTROL
NMIEN	=	$D40E	;INTERRUPT ENABLE
PCOLR0	=	$D012	;P/M COLORS
COLPM0	=	$2C0
COLPM1	=	$2C1
COLPM2	=	$2C2
COLPM3	=	$2C3
HPOSP0	=	$D000	;PLAYER HORIZ POSITIONS
HPOSP1	=	$D001
HPOSP2	=	$D002
HPOSP3	=	$D003
HPOSM0	=	$D004
HPOSM1	=	$D005
STICK	=	$278	;JOYSTICK 1

	ORG	$2800	;LOAD ADDRESS
	LOC	$0800	;EXECUTE ADDRESS

;	----------------------
;	DISPLAY LIST INTERRUPT
;	----------------------

DLI	PHA		;SAVE ACCUM
	TXA		;SAVE X REGISTER
	PHA
	LDX	DLICNT	;GET DLI NUMBER
	LDA	ECOLOR,X	;AND RELATED COLOR
	STA	WSYNC	;WAIT FOR SYNC
	STA	$D015	;AND SAVE COLOR
	INC	DLICNT	;NEXT DLI
	PLA		;RESTORE X
	TAX
	PLA		;RESTORE ACCUM
	RTI		;ALL DONE!!

;	----------------------------
;	RELOCATE PROGRAM TO $800
;	(USED BY DISK VERSION ONLY!)
;	----------------------------

MOVEIT	LDA	#$2800/256	;SET UP ORIGIN
	STA	HI	;ADDRESS IN
	LDA	#$2800&255	;2-BYTE
	STA	LO	;POINTER,
	LDA	#$0800/256	;SET UP DESTINATION
	STA	BAHI	;ADDRESS IN
	LDA	#$0800&255	;2-BYTE
	STA	BALO	;POINTER
	LDY	#0	;RESET Y REG
MOVELP	LDA	(LO),Y	;MOVE A 256-BYTE
	STA	(BALO),Y	;BLOCK USING THE
	INY		;Y REG.
	BNE	MOVELP
	INC	HI	;NEXT 256-BYTE
	INC	BAHI	;BLOCK OF DATA
	LDA	HI
	CMP	#$40	;DONE YET

	BNE	MOVELP	;NO, KEEP MOVING!
	JMP	PFIRST	;ALL DONE, START GAME!!

;	------------------
;	MAIN PROGRAM START
;	------------------

PFIRST	LDX	#190
	LDA	#$0F	;GR.8
BDLOOP	STA	DLIST,X	;BUILD DISP LST
	DEX
	BNE	BDLOOP
	LDA	#$70	;BLANK 8 LINES
	STA	DLIST
	STA	DLIST+1
	STA	DLIST+2
	LDA	#$4F	;LOAD MEM SCAN
	STA	DLIST+3
	STA	DLIST+107
	LDA	#DISP/256	;DISP ADDRESS
	STA	DLIST+5
	LDA	#DISP&255
	STA	DLIST+4
	LDA	#DISP2/256	;DISP 2 ADDRESS
	STA	DLIST+109
	LDA	#DISP2&255
	STA	DLIST+108
	LDA	#$41	;JVB
	STA	DLIST+188
	LDA	#DLIST/256	;DLIST ADDRESS
	STA	DLIST+190
	LDA	#DLIST&255
	STA	DLIST+189
	LDA	#$8F	;DLI'S
	STA	DLIST+31
	STA	DLIST+57
	STA	DLIST+118
	STA	DLIST+128
	STA	DLIST+138
	LDA	#1	;IT'S OUR...
	STA	FTIME	;FIRST TIME!

PLANET	CLD		;NO DECIMAL MODE!
	JSR	$E465	;SETUP SOUND REGS
	JSR	CLSCRN	;CLEAR SCREEN

	LDA	#0	;ZERO OUT PAGE ZERO
	LDX	#127	;ONLY LAST 128 BYTES
CLPAG0	STA	$80,X	;CLEAR BYTE
	DEX		;MORE TO CLEAR

	BPL	CLPAG0	;YUP!

	STA	DMACTL	;SET ALL THESE
	STA	NMIEN	;VARIABLES TO
	STA	AUDCTL	;ZERO
	STA	COLPF2
	STA	COLBK

	JSR	PMCLR	;CLEAR P/M AREAS

	LDA	#$FF	;SET UP ENGINE...
	LDX	#5	;TEMP DISPLAYS
PSLOOP	STA	PL3+145,X	;IN PLAYER 3,
	STA	PL3+155,X	;EACH 6 SCAN LINES
	STA	PL3+165,X	;HIGH.
	DEX		;LOOP UNTIL DONE
	BPL	PSLOOP

;	--------------------------
;	INITIALIZE STARTING STATUS
;	--------------------------

	LDA	#115	;VOLCANO CHANCE
	STA	VCHANC	;(+-45%)

	JSR	RNDBAS	;RANDOM BASE LOCATION

	LDX	#16	;INITIALIZE THE
ININUM	LDA	ININBR,X	;ESSENTIAL NUMERIC
	STA	NUMBRS,X	;VALUES USING
	STA	UNSNUM,X	;ININBR (INITIAL NUMBERS)
	DEX		;MORE TO MOVE

	BPL	ININUM	;YUP!

	LDA	#$0A	;COLOR 1 WHITE
	STA	COLPF1

	LDA	#$0F	;PLAYER 0 WHITE
	STA	COLPM0	;(SHIP)
	LDA	#$04	;PLAYER 1 GRAY
	STA	COLPM1	;(SHADOW)
	LDA	#192	;PLAYER 3 (ENGINE TEMPS)
	STA	HPOSP3	;HORIZONTAL POSITION

	LDA	#DLI/256	;SET UP DLI
	STA	VDSLST+1	;ADDRESS
	LDA	#DLI&255
	STA	VDSLST
	LDA	#DLIST&255	;SET UP DISPLAY LIST
	STA	DLISTL	;ADDRESS
	LDA	#DLIST/256
	STA	DLISTL+1
	LDA	#PMAREA/256	;SET UP PLAYER-MISSILE
	STA	PMBASE	;ADDRESS
	LDX	#VBI/256	;SET UP VBI
	LDY	#VBI&255
	LDA	#7
	JSR	SETVBV
	LDA	#$3E	;TURN DMA ON
	STA	DMACTL
	LDA	#$3	;ENABLE P/M
	STA	GRACTL
	LDA	#$C0	;ENABLE INTERRUPTS
	STA	NMIEN

	LDA	#2	;MAKE BORDER...
	STA	COLOR	;COLOR 2

;	------------------------
;	DRAW BORDER USING TABLES
;	------------------------

	LDX	#0	;START WITH POINT #0
BDRLP	STX	SHTEMP	;SAVE INDEX
	LDA	XHIGH,X	;GET X COORD HI
	PHA		;SAVE ON STACK
	LDA	XLOW,X	;GET X COORD LOW
	PHA		;SAVE ON STACK
	LDA	YLOW,X	;GET Y COORD
	PHA		;SAVE ON STACK
	LDA	LINTYP,X	;PLOT

	BEQ	ITSPLT	;YUP!
	PLA		;PULL DRAW Y
	STA	DRAWY	;AND STORE
	PLA		;PULL DRAW X LOW
	STA	DRAWX	;AND STORE
	PLA		;PULL DRAW X HI
	STA	DRXHI	;AND STORE
	JSR	DRAW	;DRAW THE LINE
	JMP	NXTBDR	;DO NEXT POINT
ITSPLT	PLA		;PULL PLOT Y
	STA	PLOTY	;AND STORE
	PLA		;PULL PLOT X LOW
	STA	PLOTX	;AND STORE
	PLA		;PULL PLOT X HI
	STA	PLXHI	;AND STORE
	JSR	PLOTCL	;PLOT THE POINT
NXTBDR	LDX	SHTEMP	;RETRIEVE INDEX
	INX		;NEXT POINT
	CPX	#15	;DONE

	BNE	BDRLP	;NO!

;	-------------------------------
;	NOW SET UP CHARACTERS ON SCREEN
;	-------------------------------

	LDX	#73	;74 CHARACTERS
SETCH	STX	CHINDX	;SAVE INDEX
	LDA	XP,X	;GET CHAR X POS
	STA	CHARX	;AND SAVE
	LDA	YP,X	;GET CHAR Y POS
	STA	CHARY	;AND SAVE
	LDA	CH,X	;GET CHAR #
	STA	CHARNO	;AND SAVE
	JSR	SHONUM	;SHOW THE CHARACTER
	LDX	CHINDX	;GET INDEX,
	DEX		;MORE CHARACTERS

	BPL	SETCH	;YOU BET!

SHOWEM	LDA	RANDOM	;GET RANDOM #,
	AND	#$1F	;LIMIT TO 31 AND
	CLC		;ADD 40 TO GET RANGE
	ADC	#40	;OF 40-71
	STA	SHIPY	;STORE IT.

	LDA	RANDOM	;REPEAT FOR Z
	AND	#$1F
	CLC
	ADC	#40
	STA	SHIPZ

	LDA	#0	;NOW WE ZERO OUT
	LDX	#5	;ALL THE ENGINE
CLTEMP	STA	TEMP1,X	;TEMPERATURES (COOL)
	DEX
	BPL	CLTEMP

	STA	SIGNS	;AND ZERO THE
	STA	SIGNS+1	;SIGN VARIABLES
	STA	SIGNS+2
	STA	SIGNS+3

	LDA	#$C4	;ENGINE COLORS ALL GREEN
	STA	ECOLOR+2
	STA	ECOLOR+3
	STA	ECOLOR+4

	LDA	#121	;INIT RADIATION
	STA	RADLVL	;LEVEL TO LOW
	LDA	#$0F	;AND SHOW WITH
	STA	PL3+121	;PLAYER 3

	LDA	#0	;NEXT WE ERASE ANY
	LDX	#47	;OTHER RADIATION
CLRAD	STA	PL3,X	;GRAPHICS IN PLAYER 3
	INX
	CPX	#122	;ALL CLEAR

	BCC	CLRAD	;NOT YET!

	JSR	SHOALT	;SHOW ALTITUDE,
	JSR	SHOXV	;X VELOCITY,
	JSR	SHOYV	;Y VELOCITY
	JSR	SHOZV	;Z VELOCITY
	JSR	SHOFUL	;FUEL
	JSR	SHOSHP	;SHIPS LEFT
	JSR	SHOSCO	;AND SCORE
	LDA	#0	;GRID TYPE 0...
	STA	GRDTYP	;(HI ALTITUDE)
	JSR	CLMESS	;CLEAR MESSAGE AREA
	JSR	RNDGRD	;RANDOMIZE LAND GRID
	JSR	CLGRDA	;CLEAR GRID GRAPHICS AREA
	JSR	GRID	;DRAW LAND GRID
	LDA	FTIME	;FIRST TIME

	BEQ	MAINLN	;NO, CONTINUE
	DEC	FTIME	;NO LONGER 1ST TIME,
	JMP	RESTRT	;GO SHOW OPTIONS

MAINLN	LDA	PAUSED	;PAUSED

	BNE	MAINLN	;YES, WE'RE PAUSED!
	LDA	TIMER	;READY FOR PROCESSING

	BEQ	DOMESS	;YES!
	JMP	CKCONS	;NO, CHECK CONSOLE
DOMESS	LDA	#1	;RESET TIMER
	STA	TIMER	;TO 1/60 SEC
	STA	ATTRAC	;NO ATTRACT MODE

;	---------------------------
;	CHECK RADIATION LEVEL TIMER
;	---------------------------

	LDA	NUMBRS	;OVER 30000 FT

	CMP	#3
	BCC	CKRTIM	;NO!
	LDA	#0	;YES, HIGH RAD!
	STA	RADTIM
CKRTIM	LDA	RADTIM	;READY FOR MORE RADIATION

	BNE	ADJALT	;NOT YET.
	LDA	VOLRAD	;IS IT VOLCANO

	BNE	GOVOLR	;YES!
	LDX	GRDTYP	;GET GRID TYPE (ALT)
	LDA	RADINI,X	;IS THERE RADIATION

	BEQ	ADJALT	;NO RADIATION
	STA	RADTIM	;RESET RADIATION TIMER
GOVOLR	LDA	RADLVL	;GET RADIATION AMOUNT
	CMP	#48	;FATAL

	BCS	RADOK	;NO, WE'RE OK.
	JMP	CRASH	;KABOOM!!!
RADOK	SEC		;ONE...
	SBC	#1	;MORE...
	STA	RADLVL	;RADIATION UNIT!
	TAX		;USE AS INDEX,
	LDA	#$0F	;AND SHOW ON SCREEN
	STA	PL3,X	;USING PLAYER 3
	LDA	#0	;RESET VOLCANO
	STA	VOLRAD	;RADIATION FLAG

;	---------------
;	ADJUST ALTITUDE
;	---------------

ADJALT	SED		;SET DECIMAL MODE
	LDA	SIGNS	;ADD OR SUBTRACT

	BEQ	SUBALT	;SUBTRACT!
	JMP	ADDALT	;ADD!

JENDAJ	JMP	ENDAAJ

SUBALT	LDA	ALTLOB	;GET ALT FRACTION BYTE
	SEC		;SUBTRACT
	SBC	NUMBRS+4	;X VELOCITY LO
	STA	ALTLOB	;AND SAVE BACK
	LDA	NUMBRS+2	;GET ALT LO BYTE
	SBC	NUMBRS+3	;SUB XV MED
	STA	NUMBRS+2	;AND SAVE
	LDA	NUMBRS+1	;GET ALT MED BYTE
	SBC	#0	;SUB 0 & CARRY
	STA	NUMBRS+1	;AND SAVE
	LDA	NUMBRS	;GET ALT HI BYTE
	SBC	#0	;SUB 0 & CARRY
	STA	NUMBRS	;AND SAVE
	CMP	#$90	;NEGATIVE ALT

	BCC	JENDAJ	;NO, STILL IN AIR!

;	-------------------------------
;	AT THIS POINT, WE'VE HIT GROUND
;	-------------------------------

	CLD		;NO MORE DECIMAL MODE
	LDA	NUMBRS+3	;TALLY HIGH-ORDER
	ORA	NUMBRS+6	;VELOCITIES TO SEE
	ORA	NUMBRS+8	;IF ANY ARE >0
	BNE	CRASH	;TOO FAST!
	LDA	NUMBRS+4	;IS X VELOCITY
	CMP	#$11	;> 10 FEET/SEC

	BCS	CRASH	;YES!
	LDA	NUMBRS+7	;IS Y VELOCITY
	CMP	#$06	;>5 FEET/SEC

	BCS	CRASH	;YES!
	LDA	NUMBRS+9	;IS Z VELOCITY
	CMP	#$06	;>5 FEET/SEC

	BCS	CRASH	;YES!
	LDA	TERRIX	;DID WE LAND
	CMP	BASEIX	;ON THE BASE

	BNE	CRASH	;NO!
	LDX	#1	;SAFE LANDING
	LDY	#14	;AT 14TH SCREEN LINE
	JSR	SHOMSG	;SHOW THE MESSAGE
	LDA	#255	;WAIT 255/60
	STA	TIMER	;(4.25) SECONDS
LDELAY	LDA	TIMER	;TIME UP

	BNE	LDELAY	;NO, LOOP BACK

	LDX	#3
FSHFLP	ASL	NUMBRS+12	;MULT
	ROL	NUMBRS+11	;FUEL
	ROL	NUMBRS+10	;BY 10
	DEX		;(THIS IS 4 SHIFTS
	BPL	FSHFLP	;IN DECIMAL MODE)
	SED		;SELECT DECIMAL MODE
	LDX	#2
	CLC
ADSCLP	LDA	NUMBRS+10,X	;ADD
	ADC	NUMBRS+14,X	;FUEL X 10 TO
	STA	NUMBRS+14,X	;SCORE
	DEX
	BPL	ADSCLP
	CLD		;NO MORE DECIMAL
	JSR	SHOSCO	;SHOW SCORE

SCOTIM	LDA	#240	;WAIT 4 SECS
	STA	TIMER
STWAIT	LDA	TIMER	;TIME UP

	BNE	STWAIT	;NO, WAIT MORE
	LDA	VCHANC	;IS VOLC CHANCE
	CMP	#255	;AT MAXIMUM

	BEQ	GOAGIN	;YES!
	CLC		;NO, INCREMENT
	ADC	#10	;VOLCANO CHANCE
	STA	VCHANC	;BY ABOUT 4%
	JSR	RNDBAS	;GET NEW BASE LOC.
GOAGIN	JMP	NEWLND	;AND START LANDING CYCLE

CRASH	LDA	RADLVL	;WAS DEATH DUE
	CMP	#47	;TO RADIATION

	BNE	IMPCRS	;NO, DUE TO IMPACT
	LDX	#5	;POINT TO RAD MESSAGE
	BNE	SHOCMS	;GO SHOW THE MESSAGE
IMPCRS	LDX	#2	;POINT TO IMPACT MSG
SHOCMS	LDY	#14	;14TH SCREEN LINE
	JSR	SHOMSG	;SHOW THE MESSAGE!
CRSHLP	LDA	SHPLRY	;CONVERT PLAYER Y
	SEC		;COORD TO GR.8
	SBC	#34
	LDX	#19	;AND PUT IN ALL
SCEXY	STA	EXYP,X	;EXPLOSION Y COORDS
	DEX
	BPL	SCEXY
	LDA	SHPLRX	;CONVERT PLAYER X
	SEC		;COORD TO GR.8
	SBC	#48
	ASL	A
	LDX	#19	;AND PUT IN ALL
SCEXX	STA	EXXP,X	;EXPLOSION X COORDS
	DEX
	BPL	SCEXX
	LDA	#0	;POSITION SHIP
	STA	SHPLRX	;AND SHADOW
	STA	SHPLRY	;OFF-SCREEN
	LDX	#19	;NOW RANDOMIZE
SCEXIS	LDA	RANDOM	;EXPLOSION...
	ORA	#$10
	STA	EXXI,X	;X INCREMENT,
	LDA	RANDOM
	ORA	#$10
	STA	EXYI,X	;Y INCREMENT,
	LDA	#0
	STA	EXXA,X	;X ACCUMULATOR,
	STA	EXYA,X	;Y ACCUMULATOR,
	LDA	RANDOM
	ORA	#$10
	AND	#$3F
	STA	EXLV,X	;PIXEL LIFE.
	DEX
	BPL	SCEXIS
	BMI	SETEXT
EXGO	LDA	TIMER	;TIME TO ADVANCE EXPL

	BNE	EXGO	;NOT YET!
SETEXT	LDA	#1	;IT'S TIME!
	STA	TIMER	;RESET TIMER
	LDX	#19	;20 PIXELS
EXLP	STX	TEMPCX	;SAVE INDEX
	LDA	EXLV,X	;PIXEL ALIVE

	BEQ	JXDEC	;NO!
	LDA	EXXP,X	;NOW WE ERASE OLD
	STA	PLOTX	;PIXEL, SETTING UP
	LDA	EXYP,X	;THE X AND Y
	STA	PLOTY	;COORDINATES
	JSR	PCALC	;GET ADDRESS OF PLOT
	LDY	#0
	LDA	BMASK2,X	;MASK OFF PIXEL
	EOR	(LO),Y
	STA	(LO),Y	;AND ERASE IT!
	LDX	TEMPCX	;GET INDEX BACK
	DEC	EXLV,X	;DECREMENT LIFE
	BEQ	JXDEC	;IT'S DEAD!
	LDA	EXXI,X	;NOW MOVE PIXEL
	CLC		;IN X DIRECTION
	ADC	EXXA,X
	STA	EXXA,X
	PHP		;SAVE CARRY FLAG
	CPX	#10	;IF PIXEL >9,
	BCS	ADEXX	;ADD INCREMENT
	PLP		;RESTORE CARRY
	LDA	EXXP,X	;OTHERWISE,
	SBC	#0	;SUBTRACT IT!
	JMP	STOEXX	;GO STORE RESULT
JXDEC	JMP	EXDEC
ADEXX	PLP		;RESTORE CARRY
	LDA	EXXP,X	;AND ADD
	ADC	#0	;THE CARRY FLAG
STOEXX	STA	EXXP,X	;SAVE X POSITION
	CMP	#192	;IN DISPLAY WINDOW

	BCS	KILEXB	;TOO FAR RIGHT!
	CMP	#10	;OK ON LEFT

	BCC	KILEXB	;TOO FAR LEFT!
	STA	PLOTX	;SAVE IN PLOT COORD.
	LDA	EXYI,X	;INCREMENT Y POSITION
	CLC
	ADC	EXYA,X
	STA	EXYA,X
	LDA	EXYP,X
	SBC	#0	;SUBTRACT INCREMENT (UP)
	STA	EXYP,X	;SAVE IT
	CMP	#10	;ON SCREEN

	BCC	KILEXB	;OFF THE TOP!
	STA	PLOTY	;SAVE IN PLOT COORD.
	JSR	PCALC	;GET PLOT ADDRESS
	LDY	#0
	LDA	BMASK2,X
	EOR	(LO),Y
	STA	(LO),Y	;AND PLOT PIXEL!
EXDEC	LDX	TEMPCX	;MORE PIXELS

	DEX
	BMI	CHKEXF	;NO!
	JMP	EXLP
KILEXB	LDX	TEMPCX	;GET INDEX OF PIXEL
	LDA	#0	;AND ZERO OUT
	STA	EXLV,X	;LIFE BYTE (IT'S DEAD)
	BEQ	EXDEC	;DO NEXT PIXEL
CHKEXF	LDX	#19	;TALLY ALL LIFE
	LDA	#0	;INDICATORS
ACCUEX	ORA	EXLV,X
	DEX
	BPL	ACCUEX
	CMP	#0	;ANY ALIVE

	BEQ	EXDONE	;NO, EXPLOSION DONE!
	JMP	EXGO	;YES, DO MORE

EXDONE	LDA	#255	;WAIT 255/60 (4.25) SECS
	STA	TIMER
CTIMWT	LDA	TIMER	;TIME UP

	BNE	CTIMWT	;NO, WAIT MORE
	DEC	NUMBRS+13	;ONE LESS SHIP
	BMI	OUTSHP	;NO MORE SHIPS!
	JMP	NXTSHP	;GO DO NEXT SHIP
OUTSHP	LDX	#0	;GAME OVER MESSAGE
	LDY	#14	;14TH LINE ON SCREEN
	JSR	SHOMSG	;SHOW THE MESSAGE
RESTRT	LDA	KEY	;GET KEYBOARD KEY
	CMP	#$12	;IS IT A "C"

	BNE	NOCTGL	;NO TOGGLE
	LDX	COLORS+1	;SWAP COLORS 1 & 2
	LDA	COLORS+2
	STA	COLORS+1
	STX	COLORS+2
	LDA	#$FF	;CANCEL KEY
	STA	KEY
	JMP	PFIRST	;REDRAW SCREEN
NOCTGL	LDX	#8	;TITLE
	LDY	#30	;30TH LINE
	JSR	SHOMSG
	LDX	#9	;AUTHOR
	LDY	#45	;45TH LINE
	JSR	SHOMSG
	LDX	#10	;MAGAZINE
	LDY	#55	;55TH LINE
	JSR	SHOMSG
	LDX	GRAVTY	;GET GRAVITY INDEX
	LDA	GCHAR,X	;GET L/M/H
	STA	GRVMSG+15	;PUT IN MESSAGE
	LDX	#7	;GRAVITY
	LDY	#75	;75TH LINE
	JSR	SHOMSG
	LDA	IFUEL1	;GET FUEL CHAR1
	ORA	#$10	;GET CHARACTER OFFSET
	STA	IFUMSG+12	;PUT IN FUEL MESSAGE
	LDA	IFUEL2	;GET FUEL CHAR2
	ORA	#$10	;GET CHARACTER OFFSET
	STA	IFUMSG+13	;PUT IN FUEL MESSAGE
	LDX	#6	;FUEL
	LDY	#85	;85TH LINE
	JSR	SHOMSG
RSTTIM	LDA	TIMER	;CONSOLE TIME READY

	BNE	RSTTIM	;NOT YET
	LDA	CONSOL	;GET CONSOLE KEY
	CMP	#7	;ANY PRESSED

	BEQ	RESTRT	;NO!
	CMP	#6	;START KEY

	BEQ	RESTCK	;YES! RESTART
	CMP	#3	;OPTION KEY

	BNE	NOTOPT	;NO, IT'S SELECT!
	LDA	GRAVTY	;GET GRAVITY
	CLC		;ADD 1 TO GET NEXT
	ADC	#1	;GRAVITY LEVEL
	CMP	#3	;BEYOND 0-2

	BNE	STGRAV	;NO, STORE IT.
	LDA	#0	;WRAP TO 0
STGRAV	STA	GRAVTY	;STORE GRAVITY
	JMP	CDELAY	;AND DEBOUNCE CONSOLE

NOTOPT	LDA	IFUEL2	;INCREMENT FUEL
	CLC		;AMOUNT (5000-14000)
	ADC	#1
	STA	IFUEL2
	CMP	#10
	BNE	CKFLIM
	LDA	#0
	STA	IFUEL2
	LDA	IFUEL1
	CLC
	ADC	#1
	STA	IFUEL1
CKFLIM	LDA	IFUEL1	;FUEL > 9000

	BEQ	CDELAY	;NO, GO DEBOUNCE CONSOLE
	LDA	IFUEL2
	CMP	#5	;FUEL = 15000

	BNE	CDELAY	;NO
	LDA	#0	;RESET FUEL TO 5000
	STA	IFUEL1

CDELAY	LDA	#30	;WAIT 30/60 (1/2) SEC
	STA	TIMER
	JMP	RESTRT	;KEEP CHECKING CONSOLE

RESTCK	LDA	CONSOL	;CONSOLE RELEASED

	CMP	#7
	BNE	RESTCK	;NOT RELEASED, WAIT
	LDA	IFUEL1	;GET SELECTED FUEL
	STA	ININBR+10	;AND PLACE IN
	LDA	IFUEL2	;INITIAL NUMBER
	ASL	A	;TABLE FOR PROPER
	ASL	A	;INITIAL FUEL
	ASL	A
	ASL	A
	STA	ININBR+11
	JMP	PLANET	;RESTART GAME

NXTSHP	JSR	SHOSHP	;SHOW # OF SHIPS
NEWLND	LDX	#12	;NOW WE MUST
REINI	LDA	ININBR,X	;RE-INITIALIZE
	STA	NUMBRS,X	;ALL VITAL NUMBERS
	STA	UNSNUM,X	;AND UNSIGNED NUMBERS
	DEX
	BPL	REINI
	JMP	SHOWEM	;AND RESTART LANDING

ADDALT	LDA	ALTLOB	;THIS ROUTINE
	CLC		;ADDS OUR X VELOCITY
	ADC	NUMBRS+4	;TO THE ALTITUDE
	STA	ALTLOB	;WHEN WE'RE GOING UP.
	LDA	NUMBRS+2
	ADC	NUMBRS+3
	STA	NUMBRS+2
	LDA	NUMBRS+1
	ADC	#0
	STA	NUMBRS+1
	LDA	NUMBRS
	ADC	#0
	STA	NUMBRS
ENDAAJ	CLD		;NO MORE DECIMAL MODE
	JSR	SHOALT	;SHOW ALTITUDE
	JSR	SHCALC	;SHIP CALCS.
	LDX	#0	;FIND THE SCALE
	LDA	NUMBRS	;OF THE LANDING GRID
	BNE	GOTSIZ	;BASED ON OUR ALTITUDE
	LDX	#2
CKSIZE	LDA	NUMBRS+1	;COMPARE ALTITUDE TO
	CMP	GRDLIM,X	;GRID SCALE LIMITS
	BCC	GOTSIZ
	DEX
	BNE	CKSIZE
GOTSIZ	CPX	GRDTYP	;SAME SCALE AS PREVIOUS

	BEQ	DOGRAV	;YUP!
	BCS	GODOWN	;NO, WE'RE GOING DOWN!
	STX	GRDTYP	;SAVE NEW GRID TYPE
	LDA	#1	;GET RID OF SHIP
	STA	NOSPOS	;TEMPORARILY
	LDA	SHIPY	;CALCULATE NEW
	JSR	CSCUP	;SHIP Y COORD
	LDA	GYP,X
	ASL	A
	ASL	A
	ASL	A
	ASL	A
	CLC
	ADC	RESULT
	STA	SHIPY
	LDA	SHIPZ	;AND NEW Z COORD
	JSR	CSCUP
	LDA	GZP,X
	ASL	A
	ASL	A
	ASL	A
	ASL	A
	CLC
	ADC	RESULT
	STA	SHIPZ
	JMP	GENGRD	;GENERATE NEW GRID

GODOWN	STX	GRDTYP	;SAVE NEW GRID TYPE
	LDA	#1	;GET RID
	STA	NOSPOS	;OF SHIP
	LDA	SHIPY	;CALCULATE NEW
	JSR	CSCDN	;SHIP Y COORD
	STA	SHIPY
	TYA
	LDX	GRDTYP
	STA	GYP-1,X
	LDA	SHIPZ	;AND SHIP Z COORD
	JSR	CSCDN
	STA	SHIPZ
	TYA
	LDX	GRDTYP
	STA	GZP-1,X
GENGRD	JSR	CLGRDA	;CLEAR GRID AREA
	JSR	RNDGRD	;RANDOMIZE NEW GRID
	JSR	GRID	;AND DRAW GRID

DOGRAV	LDA	UNSNUM+3	;HAS SHIP REACHED
	CMP	#$05	;TERMINAL VELOCITY

	BEQ	NOGRAV	;YES--DON'T ACCELLERATE
	SED		;GO TO DECIMAL MODE
	LDA	UNSNUM+5	;GET X VELOCITY
	CLC
	LDX	GRAVTY	;GET GRAVITY INDEX 0-2
	ADC	GRAVS,X	;ADD PROPER GRAVITY
	STA	UNSNUM+5	;SAVE NEW XV
	STA	NUMBRS+5
	LDA	UNSNUM+4
	ADC	#0
	STA	UNSNUM+4
	STA	NUMBRS+4
	LDA	UNSNUM+3
	ADC	#0
	STA	UNSNUM+3
	STA	NUMBRS+3
	LDX	#3	;POINT TO XV
	LDY	#0	;SIGN INDEX
	JSR	NEGHAN	;CHECK FOR NEGATIVE
NOGRAV	JSR	SHOXV	;SHOW XV ON SCREEN
RDSTIK	LDX	STICK	;GET STICK POSITION
	STX	STKHLD	;SAVE IT
	LDA	ENGIX,X	;THRUSTING

	BNE	THRUST	;YUP!
JADJYZ	JMP	ADJYZP	;ADJUST Y/Z POS
THRUST	LDA	NUMBRS+10	;TALLY FUEL
	ORA	NUMBRS+11
	ORA	NUMBRS+12
	BNE	GOFUEL	;WE'VE GOT FUEL
	LDA	SSTATS	;DID WE ALREADY DO
	AND	#1	;OUT-OF-FUEL SOUND

	BNE	NOFUEL	;YES!
	LDA	SSTATS	;SET OUT-OF-FUEL FLAG
	ORA	#1
	STA	SSTATS
	LDA	#255	;LOW PITCH
	STA	AUDF3	;IN SOUND 3
	LDA	#20	;20/60 (1/3) SEC
	STA	SNDCNT	;SOUND DURATION
	LDX	#4	;OUT OF FUEL MESSAGE
	LDY	#14	;14TH SCREEN LINE
	JSR	SHOMSG	;SHOW MESSAGE
NOFUEL	JMP	NOTHR	;DON'T THRUST (NO FUEL)
GOFUEL	LDA	NUMBRS+10	;FUEL>10000

	BNE	FUELOK	;YES, WE'RE OK
	LDA	NUMBRS+11
	CMP	#$10	;FUEL>999

	BCS	FUELOK	;YES, STILL OK
	LDA	SSTATS	;HAVE WE DONE
	AND	#2	;FUEL LOW SOUND

	BNE	FUELOK	;YES, GO DO THRUST
	LDA	SSTATS	;SET FUEL LOW FLAG
	ORA	#2
	STA	SSTATS
	LDA	#80	;MEDIUM PITCH
	STA	AUDF3	;IN SOUND 3
	LDA	#20	;20/60 (1/3) SEC
	STA	SNDCNT	;SOUND DURATION
	LDX	#3	;FUEL LOW MESSAGE
	LDY	#14	;14TH SCREEN LINE
	JSR	SHOMSG	;SHOW THE MESSAGE
FUELOK	LDY	STKHLD	;GET STICK TO FIND
	LDX	ENGIX,Y	;WHICH ENGINE'S FIRING
	LDY	TEMPS-1,X	;GET ENGINE TEMPERATURE
	LDA	ENGTHR,Y	;AND THRUST FOR THAT TEMP
	BEQ	NOTHR	;ENGINE'S DEAD!
	CMP	RANDOM	;ENGINE MAY BE FIRING
	BCS	THROK	;IT IS!
NOTHR	JMP	ADJYZP	;NO THRUST!
THROK	LDA	#10	;SET UP
	STA	THRVOL	;THRUST VOLUME
	INC	THRCNT	;ONLY ALLOW THRUST
	LDA	THRCNT	;EVERY OTHER TIME
	AND	#1
	BNE	JADJYZ	;NO THRUST!
	SED		;GO TO DECIMAL MODE
	LDA	NUMBRS+12	;AND SUBTRACT
	SEC		;2 UNITS
	SBC	#2	;FROM FUEL
	STA	NUMBRS+12
	LDA	NUMBRS+11
	SBC	#0
	STA	NUMBRS+11
	LDA	NUMBRS+10
	SBC	#0
	STA	NUMBRS+10
	CLD		;NO MORE DECIMAL MODE
	JSR	SHOFUL	;SHOW THE NEW FUEL AMT.
	LDX	STKHLD	;GET STICK FOR INDEX,
	LDA	VAL,X	;AND GET AMOUNT
	STA	VELADL	;TO ALTER VELOCITY,
	LDA	VAH,X	;EITHER 1 OR -1
	STA	VELADH	;($01 OR $99)
	LDY	FUELIX,X	;GET INDEX TO VELOCITIES
	CMP	#$99	;NEGATIVE VEL ALTER

	BEQ	CKNLIM	;YES
	LDA	UNSNUM,Y	;AT MAXIMUM VELOCITY
	CMP	#$05	;OF 500 FT/SEC

	BEQ	ADJYZP	;YES!
	JMP	ADDTHR	;GO ADD THE THRUST
CKNLIM	LDA	UNSNUM,Y	;AT MINIMUM VELOCITY
	CMP	#$95	;OF -500 FT/SEC
	BNE	ADDTHR	;NO!
	LDA	UNSNUM+1,Y	;AT -500 FT/SEC

	CMP	#$00
	BEQ	ADJYZP	;YES!
ADDTHR	LDY	FSIGNS,X	;GET VELOCITY DIRECTION
	LDA	FUELIX,X	;AND VELOCITY INDEX
	TAX
	JSR	ADDV	;ADD THE VELOCITY
	JSR	SHOYV	;SHOW Y VELOCITY
	JSR	SHOZV	;AND Z VELOCITY

;	------------------
;	ADJUST THE Y COORD
;	------------------

ADJYZP	LDY	#6	;CONVERT YV
	JSR	CVDBIN	;TO BINARY
	LDX	GRDTYP	;GET GRID TYPE FOR SCALE
	LDY	VELSHF,X	;AND DIVIDE BY
SHFYLP	LSR	HI	;THE PROPER FACTOR
	ROR	LO	;FOR THE GRID'S
	DEY		;MAGNIFICATION
	BNE	SHFYLP
	LDA	SIGNS+1	;IS VELOCITY NEGATIVE

	BNE	SUBYV	;YES, SUBTRACT IT
	LDA	SHIPYL	;ADD SHIP'S VELOCITY
	CLC		;TO THE SHIP'S
	ADC	LO	;Y POSITION
	STA	SHIPYL
	BCC	CKYLIM
	INC	SHIPY
	JMP	CKYLIM	;AND CHECK LIMIT
SUBYV	LDA	SHIPYL	;SUBTRACT VELOCITY
	SEC		;FROM THE SHIP'S
	SBC	LO	;POSITION
	STA	SHIPYL
	BCS	CKYLIM
	DEC	SHIPY
CKYLIM	LDA	#0	;NOT ON
	STA	NEWGRD	;NEW GRID YET
	STA	GRDDIR	;ZERO GRID DIRECTION
	LDA	SHIPY	;IS SHIP Y
	CMP	#180	;< 0

	BCS	YLO	;YES!
	CMP	#112	;IS IT > 111

	BCC	NAVY	;NO, GO CHECK Z
	SEC		;ADJUST IT BACK
	SBC	#112	;DOWN WITHIN THE
	STA	SHIPY	;Y LIMIT
	LDX	GRDTYP	;NOW ADJUST THE
	BEQ	SETGYI	;SHIP'S NAVIGATIONAL
NXTGYI	LDA	GYP-1,X	;COORDINATES IF
	CLC		;WE'RE NOT ON
	ADC	#1	;GRID 0 (HIGHEST)
	CMP	#7
	BNE	STGYI
	LDA	#0
	STA	GYP-1,X
	DEX
	BNE	NXTGYI
	BMI	SETGYI
STGYI	STA	GYP-1,X
SETGYI	INC	NEWGRD	;GOING TO NEW GRID
	JMP	NAVY	;GO ADJUST Z
YLO	CLC		;ADJUST Y UP
	ADC	#112	;BY 112
	STA	SHIPY
	LDX	GRDTYP	;ADJUST NAVIGATIONAL
	BEQ	SETGYD	;COORDINATES
NXTGYD	LDA	GYP-1,X	;IF WE'RE NOT
	SEC		;ON GRID TYPE 0
	SBC	#1
	BPL	STGYD
	LDA	#6
	STA	GYP-1,X
	DEX
	BNE	NXTGYD
	BMI	SETGYD
STGYD	STA	GYP-1,X
SETGYD	INC	NEWGRD	;GOING TO NEW GRID
	LDA	#1	;DIRECTION 1
	STA	GRDDIR

NAVY	LDX	GRDTYP	;THIS ROUTINE FINDS
	LDA	SHIPY	;THE SHIP'S "Y"
	LSR	A	;NAVIGATIONAL POSITION
	LSR	A
	LSR	A
	LSR	A
	STA	GYP,X
	LDA	#0
SYFINE	INX
	CPX	#3
	BEQ	NOSYF
	STA	GYP,X
	BNE	SYFINE
NOSYF	LDY	#2	;SHOW SHIP Y
	JSR	SHOPOS	;NAVIGATIONAL POSITION

;	---------------
;	NOW THE Z COORD
;	---------------

	LDY	#8	;THIS ROUTINE IS THE
	JSR	CVDBIN	;SAME AS THE ABOVE
	LDX	GRDTYP	;"Y" ROUTINE, EXCEPT
	LDY	VELSHF,X	;THAT IT ADJUSTS THE
SHFZLP	LSR	HI	;SHIP "Z" COORD.
	ROR	LO
	DEY
	BNE	SHFZLP
	LDA	SIGNS+2
	BNE	SUBZV
	LDA	SHIPZL
	CLC
	ADC	LO
	STA	SHIPZL
	BCC	CKZLIM
	INC	SHIPZ
	JMP	CKZLIM
SUBZV	LDA	SHIPZL
	SEC
	SBC	LO
	STA	SHIPZL
	BCS	CKZLIM
	DEC	SHIPZ
CKZLIM	LDA	SHIPZ
	CMP	#180
	BCS	ZLO
	CMP	#112
	BCC	CKCONS
	SEC
	SBC	#112
	STA	SHIPZ
	LDX	GRDTYP
	BEQ	SETGZI
NXTGZI	LDA	GZP-1,X
	CLC
	ADC	#1
	CMP	#7
	BNE	STGZI
	LDA	#0
	STA	GZP-1,X
	DEX
	BNE	NXTGZI
	BMI	SETGZI
STGZI	STA	GZP-1,X
SETGZI	INC	NEWGRD
	LDA	#2	;DIRECTION 2
	STA	GRDDIR
	JMP	CKCONS
ZLO	CLC
	ADC	#112
	STA	SHIPZ
	LDX	GRDTYP
	BEQ	SETGZD
NXTGZD	LDA	GZP-1,X
	SEC
	SBC	#1
	BPL	STGZD
	LDA	#6
	STA	GZP-1,X
	DEX
	BNE	NXTGZD
	BMI	SETGZD
STGZD	STA	GZP-1,X
SETGZD	INC	NEWGRD
	LDA	#3	;DIRECTION 3
	STA	GRDDIR

CKCONS	LDX	GRDTYP	;FIND SHIP'S Z
	LDA	SHIPZ	;NAVIGATIONAL
	LSR	A	;COORDINATES
	LSR	A
	LSR	A
	LSR	A
	STA	GZP,X
	LDA	#0
SZFINE	INX
	CPX	#3
	BEQ	NOSZF
	STA	GZP,X
	BNE	SZFINE
NOSZF	LDY	#3	;SHOW SHIP'S Z
	JSR	SHOPOS	;NAVIGATIONAL POSITION
	LDA	NEWGRD	;ARE WE ON NEW GRID

	BEQ	NONEWG	;NO
	JSR	CLGRDA	;CLEAR GRID AREA
	LDX	GRDDIR	;GET GRID DIRECTION AND
	LDY	GDIX,X	;SAVE THE HEIGHTS OF
	LDA	#7	;THAT GRID SIDE.
	STA	HOLD
CGSIDE	LDX	HSAVE,Y
	LDA	HEIGHT,X	;SAVE
	LDX	HOLD
	STA	HGTSAV,X	;SIDE'S
	DEY		;COORDS
	DEC	HOLD
	BPL	CGSIDE

	JSR	RNDGRD	;RANDOMIZE NEW GRID

	LDX	GRDDIR	;MOVE THE COORDINATES
	LDY	GDIX,X	;WE JUST SAVED TO
	LDA	#7	;THE NEW GRID'S
	STA	HOLD	;OPPOSITE SIDE
RSTSID	LDX	HOLD
	LDA	HGTSAV,X
	LDX	HREST,Y
	STA	HEIGHT,X
	DEY
	DEC	HOLD
	BPL	RSTSID

	JSR	GRID	;DRAW THE GRID
NONEWG	LDA	CONSOL	;ARE ANY
	CMP	#7	;CONSOLE KEYS PRESSED

	BNE	WTRELS	;YES, WAIT FOR RELEASE
	JMP	MAINLN	;NO, KEEP PROCESSING
WTRELS	LDA	CONSOL	;IS CONSOLE KEY
	CMP	#7	;RELEASED

	BNE	WTRELS	;NOT YET!
	JMP	PFIRST	;RESTART GAME

;	-----------------------
;	DESCENT SCALING ROUTINE
;	-----------------------

CSCDN	LDY	#0	;DIVIDE SHIP COORD
CSCLP	CMP	#16	;BY 16.  PUT QUOTIENT
	BCC	NOCADJ	;IN Y AND REMAINDER
	SEC		;IN ACCUMULATOR
	SBC	#16
	INY
	JMP	CSCLP
NOCADJ	STA	HOLD	;NOT MULT A BY 7
	ASL	A	;*2
	CLC
	ADC	HOLD	;*3
	ASL	A	;*6
	ADC	HOLD	;*7
	RTS		;ALL DONE!

;	----------------------
;	ASCENT SCALING ROUTINE
;	----------------------

CSCUP	STA	RESULT	;DIVIDE SHIP COORD
	LDA	#7	;BY 7
	STA	DIVISR
	LDA	#0
	JSR	DIVIDE
	LDX	GRDTYP	;GET GRID TYPE
	RTS		;AND EXIT.

;	------------------------------
;	DECIMAL TO BINARY WORK ROUTINE
;	------------------------------

CVDBIN	LDA	NUMBRS+1,Y	;GET DECIMAL NUMBER
	AND	#$0F	;MASK OFF LOW DIGIT
	STA	LO	;SAVE
	LDA	NUMBRS+1,Y	;GET DECIMAL
	LSR	A	;MASK OFF HIGH DIGIT
	LSR	A
	LSR	A
	LSR	A
	TAX		;PUT IN INDEX
	LDA	LO	;GET PREVIOUS DIGIT
	CLC		;AND ADD
	ADC	ALT1L,X	;DIGIT2 X 10
	STA	LO	;SAVE IT
	LDA	NUMBRS,Y	;GET NEXT DECIMAL #
	AND	#$0F	;MASK OFF LOW DIGIT
	TAX		;PUT IN INDEX
	LDA	LO	;GET PREVIOUS RESULT
	CLC		;AND ADD
	ADC	ALT2L,X	;DIGIT3 X 100 PART 1
	STA	LO	;SAVE IT
	LDA	#0	;AND CARRY
	ADC	ALT2H,X	;DIGIT3 X 100 PART 2
	STA	HI	;AND SAVE IT
	RTS		;ALL DONE!

;	--------------
;	SHOW SPACESHIP
;	--------------

SHCALC	NOP

;	------------------------------
;	CONVERT BCD ALTITUDE TO BINARY
;	------------------------------

	LDA	NUMBRS+2	;SIMILAR TO ABOVE
	AND	#$0F	;ROUTINE BUT WILL
	STA	BALO	;WORK FOR 3 BCD DIGITS
	LDA	#0	;AND IS DEDICATED
	STA	BAHI	;FOR ALTITUDE ONLY
	LDA	NUMBRS+2
	LSR	A
	LSR	A
	LSR	A
	LSR	A
	TAX
	LDA	BALO
	CLC
	ADC	ALT1L,X
	STA	BALO
	LDA	NUMBRS+1
	AND	#$0F
	TAX
	LDA	BALO
	CLC
	ADC	ALT2L,X
	STA	BALO
	LDA	BAHI
	ADC	ALT2H,X
	STA	BAHI
	LDA	NUMBRS+1
	LSR	A
	LSR	A
	LSR	A
	LSR	A
	TAX
	LDA	BALO
	CLC
	ADC	ALT3L,X
	STA	BALO
	LDA	BAHI
	ADC	ALT3H,X
	STA	BAHI
	LDA	NUMBRS
	AND	#$0F
	TAX
	LDA	BALO
	CLC
	ADC	ALT4L,X
	STA	BALO
	LDA	BAHI
	ADC	ALT4H,X
	STA	BAHI

	LSR	BAHI	;DIVIDE ALT. BY
	ROR	BALO	;4
	LSR	BAHI
	ROR	BALO
	LDX	GRDTYP	;NOW DIVIDE BY
	LDA	GRDDIV,X	;GRID SCALING FACTOR
	STA	DIVISR
	LDA	BALO
	STA	RESULT
	LDA	BAHI
	JSR	DIVIDE	;DO THE DIVISION

;	----------------------
;	CALC SHIP PLYR X COORD
;	----------------------

	LDA	SHIPZ	;0-111
	LSR	A	;DIVIDE BY 4
	LSR	A	;(NOW 0-27)
	STA	SHTEMP	;SAVE IT
	LDA	SHIPY	;0-111
	LSR	A	;/2 = 0-55
	CLC
	ADC	SHTEMP	;NOW 0-82
	CLC
	ADC	#56	;ADD LEFT LIMIT
	STA	SHPLRX	;GOT X POS. OF PLAYER!

;	----------------------
;	CALC SHIP PLYR Y COORD
;	----------------------

	LDA	SHIPZ	;0-111
	LSR	A	;NOW 0-55
	STA	SHTEMP	;SAVE IT
	LDA	#201	;BOTTOM OF GRID
	SEC
	SBC	SHTEMP	;NOW 146-201
	STA	SHTEMP
	SEC		;NOW WE MUST SUBTRACT
	SBC	RESULT	;SCALED ALTITUDE
	STA	SHPLRY	;DONE!

;	------------------------------------
;	NOW ADJUST SHADOW HEIGHT FOR TERRAIN
;	------------------------------------

	LDA	SHIPY	;0-111
	LSR	A	;0-55
	PHA		;SAVE ON STACK
	AND	#7	;MASK TO 0-7
	STA	SUBY
	LDA	#7	;NOW SUBTRACT
	SEC		;THIS FROM 7
	SBC	SUBY	;TO FLIP IT AROUND
	STA	SUBY
	PLA		;GET SHIPY/2
	AND	#$F8	;MASK OFF TOP 5 BITS
	STA	TERRIX	;SAVE IN TERRAIN INDEX
	LDA	SHIPZ	;0-111
	LSR	A	;0-55
	PHA		;SAVE
	AND	#7	;MASK TO 0-7
	STA	SUBZ
	LDA	#7	;NOW SUBTRACT
	SEC		;THIS FROM 7
	SBC	SUBZ	;TO FLIP IT AROUND
	STA	SUBZ
	PLA		;GET SHIPZ/2
	LSR	A	;DIVIDE BY 8
	LSR	A	;(/16 TOTAL)
	LSR	A
	CLC
	ADC	TERRIX	;AND ADD TO
	STA	TERRIX	;TERRAIN INDEX

;	---------------------
;	HIT VOLCANO ERUPTION

;	---------------------

	CMP	VOLIX	;IS SHIP OVER VOLCANO

	BNE	NOVHIT	;NO
	LDA	VOLPX	;IS VOLCANO ACTIVE

	BEQ	NOVHIT	;NO
	LDA	NUMBRS	;IS ALT>9999

	BNE	NOVHIT	;YES, NO VOLCANO HIT
	LDA	NUMBRS+1	;IS ALT>499

	CMP	#5
	BCS	NOVHIT	;YES, SHIP SAFE
	LDA	#1	;UH-OH, WE'VE GOT
	STA	VOLRAD	;VOLCANO RADIATION!!!
	LDA	#0	;FORCE
	STA	RADTIM	;VOLCANO RADIATION

NOVHIT	LDX	TERRIX	;THIS ROUTINE GETS
	LDA	HEIGHT,X	;THE HEIGHTS OF THE
	STA	T1	;CORNERS OF THE
	LDA	HEIGHT+1,X	;TERRAIN WE'RE OVER
	STA	T2	;AND CALCULATES THE
	LDA	SUBZ	;HEIGHT OF THE
	STA	MULT2	;PARTICULAR POINT
	JSR	TERCAL	;UNDER OUR SHIP.
	STA	T3	;THIS ROUTINE IS VERY
	LDX	TERRIX	;COMPLICATED, AND
	LDA	HEIGHT+8,X	;SPACE DOES NOT PERMIT
	STA	T1	;IN-DEPTH DISCUSSION
	LDA	HEIGHT+9,X	;OF THE TECHNIQUE.
	STA	T2
	LDA	SUBZ
	STA	MULT2
	JSR	TERCAL
	STA	T2
	LDA	T3
	STA	T1
	LDA	SUBY
	STA	MULT2
	JSR	TERCAL
	STA	T3
	LDA	SHTEMP
	SEC
	SBC	T3
	STA	SHADOY	;GOT SHADOW HEIGHT
	CMP	SHPLRY	;SHIP BELOW SHADOW

	BCS	NOMTHT	;NO, SHIP'S AIRBORNE
	JMP	CRASH	;SPLAT!!!
NOMTHT	RTS		;ALL DONE

;	-------------------------
;	TERRAIN HEIGHT CALCULATOR
;	-------------------------

TERCAL	LDA	T1	;THIS SUBROUTINE
	CMP	T2	;IS USED BY THE ABOVE
	BCC	TC1	;SHADOW HEIGHT
	SEC		;ROUTINE TO FIND
	SBC	T2	;THE HEIGHT OF THE
	STA	MULT1	;GROUND AT A
	JSR	MULT	;SPECIFIED POINT.
	LDA	LRES
	LSR	A
	LSR	A
	LSR	A
	CLC
	ADC	T2
	RTS
TC1	LDA	T2
	SEC
	SBC	T1
	STA	MULT1
	LDA	#8
	SEC
	SBC	MULT2
	STA	MULT2
	JSR	MULT
	LDA	LRES
	LSR	A
	LSR	A
	LSR	A
	CLC
	ADC	T1
	RTS

;	--------------
;	RANDOMIZE BASE
;	--------------

RNDBAS	LDX	#5	;6 COORDS
INBASE	LDA	RANDOM	;GET A NUMBER
	AND	#7	;FROM 0-6
	CMP	#7	;IS IT 7

	BEQ	INBASE	;YES, DON'T ALLOW!
	STA	BASEY,X	;STORE IN Y/Z POSITION
	DEX
	BPL	INBASE

	LDA	BASEY+2	;NOW CALCULATE BASE
	ASL	A	;GRID INDEX WITH THE
	ASL	A	;FORMULA:
	ASL	A
	CLC		;IX=BASEY*8+BASEZ
	ADC	BASEZ+2
	STA	BASEIX

	LDY	#0	;SHOW BASE...
	JSR	SHOPOS	;Y POSITION
	LDY	#1	;SHOW BASE...
	JSR	SHOPOS	;Z POSITION

	RTS		;AND EXIT.

;	-------------------------------
;	MULTIPLY ROUTINE
;
;	THIS ROUTINE DOES AN UNSIGNED
;	MULTIPLY OF THE VALUES IN MULT1
;	AND MULT2, PLACING THE RESULT
;	IN HRES AND LRES.
;	-------------------------------

MULT	LDA	#0
	STA	HRES
	LDX	#8
MSHIFT	ASL	A
	ROL	HRES
	ASL	MULT1
	BCC	MLOOP
	CLC
	ADC	MULT2
	BCC	MLOOP
	INC	HRES
MLOOP	DEX
	BNE	MSHIFT
	STA	LRES
	RTS

;	--------------------------------
;	DIVIDE ROUTINE
;
;	THIS ROUTINE DIVIDES A 16-BIT
;	NUMBER (LO 8 BITS IN RESULT,
;	HI 8 BITS IN ACCUMULATOR) BY THE
;	VALUE IN DIVISR. THE QUOTIENT IS
;	PLACED IN RESULT.  THE REMAINDER
;	IS DISCARDED.
;	--------------------------------

DIVIDE	LDX	#8
DIVL1	ASL	RESULT
	ROL	A
	CMP	DIVISR
	BCC	DIVL2
	SBC	DIVISR
	INC	RESULT
DIVL2	DEX
	BNE	DIVL1
	RTS

;	---------------
;	ADD TO VELOCITY
;	---------------

ADDV	SED		;WANT DECIMAL MODE
	LDA	UNSNUM+1,X	;ADD VELOCITY INCREMENT
	CLC		;AMOUNT TO VELOCITY
	ADC	VELADL	;INDICATED BY
	STA	UNSNUM+1,X	;X REGISTER.
	STA	NUMBRS+1,X
	LDA	UNSNUM,X
	ADC	VELADH
	STA	UNSNUM,X
	STA	NUMBRS,X
NEGHAN	CMP	#$50	;IS IT NEGATIVE

	BCS	NEGVEL	;YES!
	LDA	#0	;SET SIGN TO 0 (+)
STOSGN	STA	SIGNS,Y	;STORE SIGN
	CLD		;NO MORE DECIMAL
	RTS		;AND EXIT!
NEGVEL	LDA	#0	;SUBTRACT UNSIGNED
	SEC		;VELOCITY VALUE FROM
	SBC	UNSNUM+1,X	;ZERO AND STORE IN
	STA	NUMBRS+1,X	;SIGNED VALUE
	LDA	#0
	SBC	UNSNUM,X
	STA	NUMBRS,X
	LDA	#1	;PUT 1 (-)...
	BNE	STOSGN	;IN SIGN

;	-----------------------------
;	SHOW SHIP/OBJECTIVE POSITIONS
;	-----------------------------

SHOPOS	LDA	PYPOS,Y	;GET Y POSITION
	STA	CHARY	;OF MESSAGE
	LDX	POSNIX,Y	;GET COORD INDEX
	LDY	BASEY,X	;GET COORD DIGIT 1
	LDA	HI1,Y	;CONVERT COORD
	STA	POSNUM	;TO DECIMAL
	LDA	HI2,Y	;AND PLACE IN
	STA	POSNUM+1	;WORK VARIABLE
	LDY	BASEY+1,X	;GET COORD DIGIT 2
	LDA	MED1,Y	;ADD DIGIT 2'S
	SED		;DECIMAL VALUE
	CLC		;TO WORK AREA
	ADC	POSNUM+1
	STA	POSNUM+1
	LDA	POSNUM
	ADC	#0
	STA	POSNUM
	LDA	BASEY+2,X	;ADD DIGIT 3'S
	CLC		;DECIMAL VALUE
	ADC	POSNUM+1	;TO WORK AREA
	STA	POSNUM+1
	LDA	POSNUM
	ADC	#0
	STA	POSNUM
	CLD
	LDA	#2	;2 DIGITS TO
	STA	DIGITS	;DISPLAY
	LDX	#17	;17TH IN "NUMBRS"
	JMP	SHOALL	;SHOW THE NUMBER
;	-------------
;	SHOW ALTITUDE
;	-------------

SHOALT	LDA	#98	;98TH SCREEN LINE
	STA	CHARY
	LDA	#3	;3 DIGITS TO SHOW
	STA	DIGITS
	LDX	#0	;0TH IN "NUMBRS"
	JMP	SHOALL	;SHOW THE NUMBER

;	---------------
;	SHOW X VELOCITY
;	---------------

SHOXV	LDA	SIGNS	;GET 1ST SIGN
	JSR	SHOARR	;SHOW ITS ARROW
	LDA	#112	;112TH SCREEN LINE
	STA	CHARY
	LDA	#2	;2 DIGITS TO SHOW
	STA	DIGITS
	LDX	#3	;3RD IN "NUMBRS"
	JMP	SHOALL	;SHOW IT

;	---------------
;	SHOW Y VELOCITY
;	---------------

SHOYV	LDA	#2	;GET 2ND SIGN
	CLC
	ADC	SIGNS+1
	JSR	SHOARR	;SHOW ITS ARROW
	LDA	#122	;122ND SCREEN LINE
	STA	CHARY
	LDA	#2	;2 DIGITS TO SHOW
	STA	DIGITS
	LDX	#6	;6TH IN "NUMBRS"
	JMP	SHOALL	;SHOW IT

;	---------------
;	SHOW Z VELOCITY
;	---------------

SHOZV	LDA	#4	;GET 3RD SIGN
	CLC
	ADC	SIGNS+2
	JSR	SHOARR	;SHOW ITS ARROW
	LDA	#132	;132ND SCREEN LINE
	STA	CHARY
	LDA	#2	;2 DIGITS TO SHOW
	STA	DIGITS
	LDX	#8	;8TH IN "NUMBRS"
	JMP	SHOALL	;SHOW IT

;	---------
;	SHOW FUEL
;	---------

SHOFUL	LDA	#146	;146TH SCREEN LINE
	STA	CHARY
	LDA	#3	;3 DIGITS TO SHOW
	STA	DIGITS
	LDX	#10	;10TH IN "NUMBRS"
	JMP	SHOALL	;SHOW IT

;	----------
;	SHOW SHIPS
;	----------

SHOSHP	LDA	#160	;160TH SCREEN LINE
	STA	CHARY
	LDA	#1	;1 DIGIT TO SHOW
	STA	DIGITS
	LDX	#13	;13TH IN "NUMBRS"
	JMP	SHOALL	;SHOW IT

;	----------
;	SHOW SCORE
;	----------

SHOSCO	LDA	#170	;170TH SCREEN LINE
	STA	CHARY
	LDA	#3	;3 DIGITS TO SHOW
	STA	DIGITS
	LDX	#14	;14TH IN "NUMBRS"

;	------------
;	SHOW NUMBERS
;	------------

SHOALL	LDA	#31	;31ST CHAR ACROSS
	STA	CHARX
	STX	SNUMIX	;SAVE "NUMBRS" INDEX
SNUMLP	LDX	SNUMIX	;GET INDEX
	LDA	NUMBRS,X	;GET BCD VALUE
	JSR	SHOBCD	;SHOW IT
	INC	SNUMIX	;NEXT BCD VALUE
	DEC	DIGITS	;1 LESS DIGIT
	BNE	SNUMLP	;NOT FINISHED YET!
	RTS		;ALL DONE

;	----------------
;	BCD CHAR DISPLAY
;	----------------

SHOBCD	STA	SHOBYT	;SAVE BCD VALUE
	LSR	A	;SHIFT RIGHT
	LSR	A	;TO GET
	LSR	A	;FIRST DIGIT
	LSR	A
	ORA	#$10	;ADD CHAR. OFFSET
	STA	CHARNO	;SAVE FOR DISPLAY
	JSR	SHONUM	;AND DISPLAY IT
	INC	CHARX	;NEXT POS. ON SCREEN
	LDA	SHOBYT	;GET BCD BACK
	AND	#$0F	;GET SECOND DIGIT
	ORA	#$10	;ADD CHAR OFFSET
	STA	CHARNO	;SAVE FOR DISPLAY
	JSR	SHONUM	;AND DISPLAY IT
	INC	CHARX	;NEXT SCREEN POSITION
	RTS		;AND EXIT

;	-----------
;	SHOW ARROWS
;	-----------

SHOARR	PHA		;SAVE ARROW #
	LSR	A	;DIV BY 2
	TAX		;USE FOR INDEX
	LDA	ARRLO,X	;GET SCREEN ADDRESS
	STA	DESTLO	;FOR THE ARROW
	LDA	ARRHI,X	;AND SAVE ON
	STA	DESTHI	;PAGE ZERO
	LDY	#0	;INITIALIZE COPY INDEX
	PLA		;GET ARROW #
	ASL	A	;MULTIPLY BY 8 FOR
	ASL	A	;OFFSET INTO ARROW
	ASL	A	;GRAPHICS TABLE
	TAX		;SAVE INDEX
	LDA	#7	;THERE ARE 8 BYTES
	STA	DIGITS	;IN EACH ARROW
COPARR	LDA	ARROWS,X	;GET GRAPHICS DATA,
	STA	(DESTLO),Y	;PUT ON SCREEN
	INX		;NEXT ARROW BYTE
	TYA		;ADD 40 TO Y REGISTER
	CLC		;TO POINT TO NEXT
	ADC	#40	;GRAPHICS 8 LINE
	TAY		;(40 BYTES PER LINE)
	DEC	DIGITS	;MORE ARROW DATA

	BNE	COPARR	;YES, KEEP COPYING
	RTS		;ALL DONE

;	--------------
;	CLEAR P/M AREA
;	--------------

PMCLR	LDA	#0	;PUT ZEROS IN
	TAY		;ALL 256 POSITIONS
PMCLP	STA	MISSLS,Y	;OF MISSILES,
	STA	PL0,Y	;PLAYER 0
	STA	PL1,Y	;PLAYER 1
	STA	PL2,Y	;PLAYER 2
	STA	PL3,Y	;PLAYER 3
	DEY		;DONE

	BNE	PMCLP	;NOT YET
	RTS		;EXIT

;	------------
;	CLEAR SCREEN
;	------------

CLSCRN	LDX	#29	;CLEAR 30*256 BYTES
	LDA	#DISP/256	;PUT DISPLAY
	STA	HI	;ADDRESS IN
	LDA	#0	;PAGE ZERO
	STA	LO	;WORK AREA
CLSLP1	TAY		;ZERO Y REGISTER
CLSLP2	STA	(LO),Y	;CLEAR A BYTE
	DEY		;DONE WITH 256

	BNE	CLSLP2	;NOPE!
	DEX		;DONE WITH 30

	BNE	NXTCLR	;NOPE!
	RTS		;ALL DONE!
NXTCLR	INC	HI	;NEXT 256-BYTE GROUP
	BNE	CLSLP1	;LOOP BACK

;	-------------------------
;	CLEAR GRID AREA OF SCREEN
;	-------------------------

CLGRDA	LDA	#0	;POINT TO 100TH LINE
	STA	SHPLRX	;OF SCREEN
	LDA	#[DISP+2+100*40]/256
	STA	HI
	LDA	#[DISP+2+100*40]&255
	STA	LO
	LDX	#72	;CLEAR 72 GROUPS
CGRDL1	LDY	#21	;OF 22 BYTES
	LDA	#0
CGRDL2	STA	(LO),Y	;CLEAR A BYTE
	DEY		;DONE WITH 22

	BPL	CGRDL2	;NOT YET!
	DEX		;DONE 72 GROUPS

	BNE	NXTCGD	;NOPE!
	RTS		;ALL DONE!
NXTCGD	LDA	LO	;POINT TO NEXT LINE
	CLC		;OF SCREEN
	ADC	#40	;(40 BYTES IN GR.8)
	STA	LO
	BCC	CGRDL1
	INC	HI
	BNE	CGRDL1

;	------------------
;	CLEAR MESSAGE AREA
;	------------------

;	POINT TO 14TH LINE OF SCREEN

CLMESS	LDA	#[DISP+2+14*40]/256
	STA	HI
	LDA	#[DISP+2+14*40]&255
	STA	LO
	LDX	#8	;CLEAR 8 GROUPS
CMESS1	LDY	#21	;OF 22 BYTES
	LDA	#0
CMESS2	STA	(LO),Y	;CLEAR A BYTE
	DEY		;DONE 22 BYTES

	BPL	CMESS2	;NOT YET!
	DEX		;DONE 8 GROUPS

	BNE	NXTCMS	;NOPE!
	RTS		;ALL DONE
NXTCMS	LDA	LO	;ADVANCE 40 BYTES
	CLC		;TO NEXT SCREEN LINE
	ADC	#40
	STA	LO
	BCC	CMESS1
	INC	HI
	BNE	CMESS1

;	------------
;	SHOW MESSAGE
;	------------

SHOMSG	STY	CHARY	;SET SCREEN LINE
	LDY	MSGIX,X	;POINT TO MESSAGE TEXT
	LDA	#2	;2ND CHAR ON SCREEN
	STA	CHARX
	LDX	#22	;22 CHARACTERS TO SHOW
	STX	MSGCT
	STY	MSGPTR
MSGLP	LDX	MSGCT	;GET COUNT IN MESSAGE
	LDY	MSGPTR	;POINT TO MESSAGE CHAR
	LDA	MESSGE,Y	;GET CHARACTER
	STA	CHARNO	;GET READY TO SHOW IT
	JSR	SHONUM	;SHOW IT!
	DEC	MSGCT	;LAST CHARACTER

	BNE	NXTMBT	;NOT YET!
	RTS		;ALL DONE
NXTMBT	INC	CHARX	;NEXT X POSITION
	INC	MSGPTR	;NEXT CHAR
	BNE	MSGLP	;LOOP BACK

;	--------------------------
;	GRAPHICS 8 CHAR. GENERATOR
;	--------------------------

SHONUM	LDA	CHARY
	STA	LO	;SAVE Y POS
	LDA	#0
	STA	HI
	ASL	LO	;*2
	ROL	HI
	ASL	LO	;*4
	ROL	HI
	ASL	LO	;*8
	ROL	HI
	LDA	LO
	CLC
	ADC	#DISP&255	;ADD DISPLAY START
	STA	DESTLO
	LDA	HI
	ADC	#DISP/256
	STA	DESTHI
	ASL	LO	;*16
	ROL	HI
	ASL	LO	;*32
	ROL	HI
	LDA	LO
	CLC
	ADC	DESTLO	;GET CHARACTER'S
	STA	DESTLO	;SCREEN ADDRESS
	LDA	HI
	ADC	DESTHI
	STA	DESTHI
	LDA	DESTLO	;ADD X OFFSET
	CLC		;FOR FINAL ADDRESS
	ADC	CHARX
	STA	DESTLO
	BCC	NODHIN
	INC	DESTHI
NODHIN	LDA	CHARNO	;GET OFFSET INTO
	STA	LO	;CHARACTER SET
	LDA	#0
	STA	HI
	STA	COPCNT	;ZERO COPY COUNT
	ASL	LO	;*2
	ROL	HI
	ASL	LO	;*4
	ROL	HI
	ASL	LO	;*8
	ROL	HI
	LDA	HI	;GET INFORMATION
	CLC		;FROM O.S. CHARACTER
	ADC	#$E0	;SET AT $E000
	STA	HI
COPNUM	LDY	COPCNT
	LDA	(LO),Y	;GET CHAR. IMAGE BYTE
	LDY	#0
	STA	(DESTLO),Y	;PUT ON SCREEN
	INC	COPCNT	;NEXT CHARACTER BYTE
	LDA	COPCNT	;ARE ALL 8 BYTES
	CMP	#8	;IN CHARACTER MOVED

	BEQ	FINISH	;YES!
	LDA	DESTLO	;ADD 40 BYTES TO
	CLC		;POINT TO NEXT LINE
	ADC	#40	;ON SCREEN
	STA	DESTLO
	BCC	COPNUM
	INC	DESTHI
	BNE	COPNUM
FINISH	RTS		;ALL DONE!

;	----------------------
;	RANDOMIZE GRID HEIGHTS
;	----------------------

RNDGRD	LDX	#63	;64 POINTS ON GRID
	LDY	GRDTYP	;GET GRID TYPE
RGLP	LDA	RANDOM	;GET RANDOM NUMBER BUT
	AND	#$0F	;LIMIT IT TO THE
	CMP	MAXHGT,Y	;MAXIMUM HEIGHT
	BCS	RGLP	;OF THE GRID TYPE
	STA	HEIGHT,X	;SAVE HEIGHT
	DEX		;DONE

	BPL	RGLP	;NO!
	RTS		;ALL DONE, EXIT

;	-------------
;	DRAW THE GRID
;	-------------

GRID	CLD
	LDA	#0
	STA	VOLPX	;NO VOLCANO
	LDX	#0	;CLEAR OUT
	TXA		;PLAYER 2
CP2LP	STA	PL2,X
	DEX
	BNE	CP2LP
	LDX	GRDTYP	;GRID TYPE 0 (HIGH)

	BEQ	GOTBAS	;YES, SHOW BASE
	LDX	#0	;COMPARE SHIP'S
BASCHK	LDA	GYP,X	;GRID POSITIONS
	CMP	BASEY,X	;TO BASE'S.
	BNE	NOBASE
	LDA	GZP,X
	CMP	BASEZ,X	;IF THEY'RE NOT EQUAL,
	BNE	NOBASE	;DON'T SHOW BASE!
	INX
	CPX	GRDTYP
	BNE	BASCHK
GOTBAS	LDX	GRDTYP

;	-----------------
;	CALC BASE X COORD
;	-----------------

	LDA	BASEZ,X	;THIS ROUTINE IS
	ASL	A	;SIMILAR TO THE
	ASL	A	;SHIP PLAYER POSITION
	STA	SHTEMP	;CALCULATOR ABOVE.
	LDA	BASEY,X	;IT FINDS THE VOLCANO'S
	ASL	A	;P/M COORDINATES.
	ASL	A
	ASL	A
	CLC
	ADC	SHTEMP
	CLC
	ADC	#61
	STA	HPOSP2

;	-----------------
;	CALC BASE Y COORD
;	-----------------

	LDA	BASEZ,X
	ASL	A
	ASL	A
	ASL	A
	STA	SHTEMP
	LDA	#196
	SEC
	SBC	SHTEMP
	TAY

;	----------------
;	COPY BASE SYMBOL
;	----------------

	LDX	#4	;5 BYTES IN BASE PIC.
BSCOPY	LDA	BASPIC,X	;GET BASE PICTURE BYTE
	STA	PL2,Y	;PUT IN PLAYER 2
	INY		;NEXT PLAYER BYTE
	DEX		;NEXT IMAGE BYTE
	BPL	BSCOPY	;COPY ALL 5 BYTES!

;	------------------------
;	MAKE BASE ZERO HEIGHT IF
;	WE'RE ON FINAL APPROACH
;	------------------------

	LDX	GRDTYP	;IF GRID IS NOT
	CPX	#2	;TYPE 2 (LOW)...
	BNE	NOBASE	;LEAVE TERRAIN ALONE!
	LDX	BASEIX	;OTHERWISE WE MUST
	LDA	#0	;MAKE THE 4 CORNERS
NEWHGT	STA	HEIGHT,X	;OF THE LANDING GRID
	STA	HEIGHT+1,X	;ALL ZERO HEIGHT!
	STA	HEIGHT+8,X
	STA	HEIGHT+9,X
	JMP	NOVOLC	;AND BYPASS NEXT CODE.

;	--------------------------------
;	IF THERE'S NO BASE, LET'S TRY TO
;	PLACE A DANGEROUS VOLCANO!
;	--------------------------------

NOBASE	LDA	GRDTYP	;ARE WE AT LOW ALT...
	CMP	#2	;(GRID TYPE 2)

	BNE	NOVOLC	;NO, NO VOLCANO!
	LDA	RANDOM	;GET RANDOM #
	CMP	VCHANC	;IS IT > VOLCANO CHANCE

	BCS	NOVOLC	;YES, NO VOLCANO!
VOLCZ	LDA	RANDOM	;GET RANDOM VOLCANO
	AND	#7	;Y AND Z COORDINATES
	CMP	#5	;FROM 1-5
	BCS	VOLCZ
	CLC
	ADC	#1
	STA	VOLZ
VOLCY	LDA	RANDOM
	AND	#7
	CMP	#5
	BCS	VOLCY
	CLC
	ADC	#1
	STA	VOLY	;NOW GET VOLCANO
	ASL	A	;POSITION INDEX
	ASL	A
	ASL	A
	CLC
	ADC	VOLZ
	STA	VOLIX

;	--------------------------
;	CALC VOLCANO PLAYER COORDS
;	--------------------------

	LDA	VOLZ	;THIS ROUTINE IS
	ASL	A	;SIMILAR TO THE BASE
	ASL	A	;PLAYER POSITION
	STA	SHTEMP	;ROUTINE.  IT USES
	LDA	VOLY	;VOLY & VOLZ TO
	ASL	A	;CALCULATE THE
	ASL	A	;VOLCANO'S PLAYER
	ASL	A	;COORDINATES.
	CLC
	ADC	SHTEMP
	CLC
	ADC	#59
	STA	VOLPX

	LDA	VOLZ
	ASL	A
	ASL	A
	ASL	A
	STA	SHTEMP
	LDA	#186
	SEC
	SBC	SHTEMP
	STA	VOLPY

	LDX	VOLIX	;NOW SET THE 4 CORNERS
	LDA	#7	;OF THE VOLCANO TO
	JMP	NEWHGT	;HEIGHT 7.

NOVOLC	LDA	#1	;SELECT PLOT COLOR
	STA	COLOR
	LDA	#16	;SET PLOT X OFFSET
	STA	XOFSET

;	--------------------------------
;	THE FOLLOWING CODE TAKES THE
;	HEIGHT VALUES FROM THE "HEIGHT"
;	TABLE AND PLOTS THE GRID ON THE
;	SCREEN.
;	--------------------------------

	LDA	#0
	STA	PLXHI
	STA	DRXHI
	STA	HGTIX
	STA	X
NEXTX1	LDA	#0	;ZERO Y INDEX
	STA	Y
	TAY		;PLOT FLAG
NEXTY1	LDA	XOFSET	;GET X POSITION
	CLC
	ADC	X
	STA	PLOTX,Y	;STORE IN PLOTX/DRAWX
	LDA	#170	;GET Y POSITION
	SEC
	SBC	Y
	SEC
	LDX	HGTIX
	SBC	HEIGHT,X	;SUBTRACT GRID HEIGHT
	STA	PLOTY,Y	;STORE IN PLOTY/DRAWY
	LDA	Y	;DRAWING

	BNE	DRWIT1	;YES!
	JSR	PLOTCL	;PLOT THE POINT
	JMP	ENDRW1	;DO NEXT POINT
DRWIT1	JSR	DRAW	;DRAW TO THE POINT
ENDRW1	LDA	XOFSET	;ADD 8 TO X OFFSET
	CLC
	ADC	#8
	STA	XOFSET
	INC	HGTIX	;NEXT HEIGHT VALUE
	LDY	#1	;NOW DRAW
	LDA	Y	;ADD 8 TO Y INDEX
	CLC
	ADC	#8
	STA	Y
	CMP	#57	;PAST LIMIT

	BCC	NEXTY1	;NO, LOOP BACK.
	LDA	#16	;RESET X OFFSET
	STA	XOFSET
	LDA	X	;AND INCREMENT X
	CLC		;FOR NEXT GRID LINE
	ADC	#16
	STA	X
	CMP	#113	;PAST LIMIT

	BCC	NEXTX1	;NO, LOOP BACK.

;	------------------------------
;	NOW DO OTHER DIRECTION OF GRID
;	------------------------------

	LDA	#0	;ZERO OUT Y
	STA	Y
	LDA	#$FF	;SET INDEX TO -1
	STA	INDEX
NEXTY2	INC	INDEX	;NEXT INDEX
	LDA	INDEX
	STA	HGTIX	;SAVE IN HEIGHT INDEX
	LDA	#0	;ZERO OUT X
	STA	X
	TAY		;SET Y REG FOR PLOT
NEXTX2	LDA	XOFSET	;FIND X POSITION
	CLC
	ADC	X
	STA	PLOTX,Y	;STORE IN PLOTX/DRAWX
	LDA	#170	;GET Y POSITION
	SEC
	SBC	Y
	LDX	HGTIX
	SEC
	SBC	HEIGHT,X	;ADJUST FOR HEIGHT
	STA	PLOTY,Y	;STORE IN PLOTY/DRAWY
	LDA	X	;PLOTTING

	BNE	DRWIT2	;NO, DRAW IT.
	JSR	PLOTCL	;PLOT THE POINT
	JMP	ENDRW2	;GO DO NEXT POINT
DRWIT2	JSR	DRAW	;DRAW TO THE POINT
ENDRW2	LDA	HGTIX	;NEXT HEIGHT VALUE
	CLC
	ADC	#8
	STA	HGTIX
	LDY	#1	;NOW DRAWING
	LDA	X	;NEXT X POSITION
	CLC
	ADC	#16
	STA	X
	CMP	#113	;PAST LIMIT

	BCC	NEXTX2	;NO
	LDA	XOFSET	;NEXT X OFFSET VALUE
	CLC
	ADC	#8
	STA	XOFSET
	LDA	Y	;NEXT Y VALUE
	CLC
	ADC	#8
	STA	Y
	CMP	#57	;PAST LIMIT

	BCC	NEXTY2	;NO, LOOP
	RTS		;ALL DONE.

;	--------------
;	VERTICAL BLANK
;	--------------

VBI	CLD		;NO DECIMAL MODE!
	LDA	#0	;RESET DLI INDEX
	STA	DLICNT

;	---------------
;	CHECK FOR PAUSE
;	---------------

	LDA	KEY	;GET KEYBOARD KET
	CMP	#$21	;SPACE BAR

	BNE	PCHK	;NO
	LDA	PAUSED	;FLIP THE
	EOR	#$FF	;PAUSE STATUS
	STA	PAUSED
	LDA	#$FF	;RESET KEYPRESS
	STA	KEY
PCHK	LDA	PAUSED	;WE PAUSED

	BEQ	NOPAU	;NO
	JMP	XITVBV	;PAUSED, NO PROCESSING!
NOPAU	LDA	COLPM3	;CYCLE
	CLC		;RADIATION
	ADC	#1	;COLOR
	AND	#$07	;BRIGHTNESS
	ORA	#$30
	STA	COLPM3
	LDA	TIMER	;HANDLE
	BEQ	NOTDEC	;GENERAL TIMER
	DEC	TIMER
NOTDEC	LDA	RADTIM	;HANDLE
	BEQ	NORDEC	;RADIATION TIMER
	DEC	RADTIM
NORDEC	LDA	VOLPX	;VOLCANO

	BEQ	FLSHP2	;NOPE
	STA	HPOSP2	;POSITION PLAYER 2
	LDA	RANDOM	;DO RANDOM
	AND	RANDOM	;ERUPTION GRAPHICS
	LDY	VOLPY
	STA	PL2,Y
	STA	PL2+4,Y
	LDA	RANDOM
	AND	RANDOM
	STA	PL2+2,Y
	LDA	RANDOM
	AND	#$3C
	STA	PL2+6,Y
	LDA	#$3A
	STA	COLPM2
	BNE	NOPFLS	;NO PAD FLASH
FLSHP2	INC	PFLASH	;INCREMENT
	LDA	PFLASH	;PAD FLASH TIMER
	AND	#$0F
	BNE	NOPFLS	;NO FLASH YET
	INC	PFLIX	;FLIP FLASH COLOR INDEX
	LDA	PFLIX
	AND	#1
	TAX		;USE FOR INDEX
	LDA	PCOLRS,X	;GET PAD COLOR
	STA	COLPM2	;PUT IN PLAYER 2 COLOR
NOPFLS	LDX	LASTSY	;NOW WE ERASE
	LDA	#$FC	;THE OLD SHIP...
	AND	MISSLS,X
	STA	MISSLS,X
	LDA	#$FC
	AND	MISSLS+1,X
	STA	MISSLS+1,X
	LDX	LSHADY	;AND SHADOW
	LDA	#$F3
	AND	MISSLS,X
	STA	MISSLS,X
	LDA	#$F3
	AND	MISSLS+1,X
	STA	MISSLS+1,X
	LDA	SHPLRX	;POSITION
	STA	HPOSM0	;THE SHIP
	STA	HPOSM1	;AND SHADOW
	LDX	SHPLRY
	STX	LASTSY	;SAVE POSITION,
	LDA	#$02	;DRAW SHIP...
	ORA	MISSLS,X
	STA	MISSLS,X
	LDA	#$02
	ORA	MISSLS+1,X
	STA	MISSLS+1,X
	LDX	SHADOY	;AND SHADOW
	STX	LSHADY
	LDA	#$08
	ORA	MISSLS,X
	STA	MISSLS,X
	LDA	#$08
	ORA	MISSLS+1,X
	STA	MISSLS+1,X

	LDA	#130	;SET UP THRUST
	STA	AUDF1	;FREQUENCY 1
	LDA	#8
	STA	AUDF2	;AND 2
	LDA	THRVOL	;GET THRUST VOLUME
	STA	AUDC1	;STORE IN AUDIO 1
	LSR	A	;DIVIDE BY 8
	LSR	A
	LSR	A
	STA	AUDC2	;AND PUT IN AUDIO 2
	INC	THRTIM	;TIME TO DECREMENT
	LDA	THRTIM	;THRUST VOLUME

	AND	#7
	BNE	DOTEMP	;NOT YET
	LDA	THRVOL	;IS VOLUME 0

	BEQ	DOTEMP	;YES, DON'T CHANGE!
	DEC	THRVOL	;LESS VOLUME!

DOTEMP	LDX	STICK	;GET STICK
	LDA	ENGIX,X	;AND ENGINE NUMBER
	STA	STKPOS	;IS ENGINE BEING USED

	BEQ	COOLIT	;NO, COOL ALL ENGINES
	TAX
	DEX
	LDA	TEMP2,X	;GET ENGINE TEMP
	CMP	#$18	;IS ENGINE DEAD

	BCS	COOLIT	;YES, DON'T HEAT MORE!
	LDA	TEMP1,X	;INCREMENT THE
	CLC		;TEMPERATURE.
	ADC	#1
	STA	TEMP1,X
	LDA	TEMP2,X
	ADC	#0
	STA	TEMP2,X
	JSR	SETCLR	;GO DO ENGINE COLORS

COOLIT	LDX	#2	;COOL ALL 3 ENGINES
	DEC	STKPOS
COOLP	CPX	STKPOS	;IS THIS ENGINE IN USE

	BEQ	NXCOOL	;IF SO, CON'T COOL IT!
	LDA	TEMP2,X	;GET ENGINE TEMP
	CMP	#$18	;IS IT DEAD

	BCS	NXCOOL	;YES, DON'T COOL IT.
	CMP	#0	;IS ENGINE HOT

	BNE	COOLOK	;YES, OK TO COOL
	LDA	TEMP1,X	;GET LOW TEMP BYTE
	CMP	#2	;IS ENGINE COLD

	BCC	NXCOOL	;YES, DON'T COOL
COOLOK	LDA	TEMP1,X	;COOL OFF THE
	SEC		;ENGINE BY
	SBC	#2	;SUBTRACTING 2
	STA	TEMP1,X	;FROM THE TEMP
	LDA	TEMP2,X
	SBC	#0
	STA	TEMP2,X
	JSR	SETCLR	;SHOW ENGINE COLOR
NXCOOL	DEX		;MORE ENGINES

	BPL	COOLP	;YUP!
VBDONE	LDA	SNDCNT	;GET WARNING TONE COUNT
	BEQ	NOSND	;IF 0, NO TONE.
	SEC		;OTHERWISE,
	SBC	#1	;SUBTRACT 1 FROM
	STA	SNDCNT	;THE COUNT,
	LSR	A	;DIVIDE BY 2
	ORA	#$A0	;AND MAKE IT THE
	STA	AUDC3	;VOLUME.
NOSND	JMP	XITVBV	;VBI DONE!

;	-----------------
;	SET ENGINE COLORS
;	-----------------

SETCLR	AND	#$1F	;MASK OFF HI TEMP,
	LSR	A	;DIVIDE BY 8
	LSR	A
	LSR	A
	STA	TEMPS,X	;GET TEMP COLOR INDEX
	TAY
	LDA	ENGCLS,Y	;GET COLOR
	CMP	ECOLOR+2,X	;SAME AS CURRENT

	BEQ	NOCCHG	;YES, NO CHANGE
	STA	ECOLOR+2,X	;NEW COLOR:
	LDA	#20	;SET UP ENGINE TEMP
	STA	SNDCNT	;TONE COUNT
	ASL	A	;AND FREQUENCY
	STA	AUDF3	;OF 40.
NOCCHG	RTS		;EXIT

;	--------------------------------
;	GR. 8+ PLOTTER ROUTINE
;
;	THIS ROUTINE PLOTS IN GRAPHICS 8
;	IN 4 COLORS, DETERMINED BY 0-3
;	IN "COLOR".
;	--------------------------------

PLOTCL	JSR	PCALC
	LDY	COLOR	;GET COLOR
	LDA	BMASK2,X	;AND MASK OFF
	AND	COLORS,Y	;PIXEL POSITION
	STA	HOLD	;SAVE IT,
	LDA	BMASK1,X	;MASK OFF PIXEL
	LDY	#0	;OF THE ADDRESS
	AND	(LO),Y	;TO BE ALTERED
	ORA	HOLD	;SET THE PLOT
	STA	(LO),Y	;BITS AND STORE!
	RTS		;FINIS!

;	---------------
;	PLOT CALCULATOR
;	---------------

PCALC	LDA	PLOTY
	ASL	A
	STA	LO
	LDA	#0
	ROL	A
	STA	HI	;*2
	ASL	LO
	ROL	HI	;*4
	ASL	LO
	LDA	LO
	STA	LOHLD
	ROL	HI
	LDA	HI
	STA	HIHLD	;*8
	ASL	LO
	ROL	HI	;*16
	ASL	LO
	ROL	HI	;*32
	LDA	LO
	CLC
	ADC	LOHLD
	STA	LO
	LDA	HI
	ADC	HIHLD
	STA	HI	;+*8=*40
	LDA	#DISP&255	;ADD THE DISPLAY
	CLC		;ADDRESS TO GET
	ADC	LO	;THE ACTUAL
	STA	LO	;ADDRESS OF THE
	LDA	#DISP/256	;BYTE THAT WILL
	ADC	HI	;BE ALTERED FOR
	STA	HI	;THE PLOT.
	LDA	PLOTX	;MASK PLOTX FOR
	AND	#7	;PLOT INDEX,
	LSR	A
	TAX		;PLACE IN X.
	LDA	PLXHI
	LSR	A
	LDA	PLOTX	;GET PLOTX AND
	ROR	A
	LSR	A	;DIVIDE
	LSR	A	;BY 8,
	CLC		;ADD TO
	ADC	LO	;PLOT ADDRESS
	STA	LO	;FOR FINAL PLOT
	LDA	HI	;ADDRESS.
	ADC	#0
	STA	HI
	RTS		;EXIT!

;	--------------------------------
;	GRAPHICS 8+ DRAW HANDLER
;
;	THIS ROUTINE IS A MODIFICATION
;	OF THE GRAPHICS 7+ HANDLER FROM
;	A.N.A.L.O.G. #11.
;	--------------------------------

DRAW	LDA	DRAWY	;GET DRAWTO Y
	CMP	PLOTY	;IS DRAWY>PLOTY

	BCC	YMINUS	;NO!
	SEC		;SUBTRACT
	SBC	PLOTY	;PLOTY FROM DRAWY
	STA	DELTAY	;AND SAVE DIFFERENCE
	LDA	#1	;Y INCREMENT
	STA	INCY	;=1 (DOWN)
	BNE	XVEC	;NOW DO X
YMINUS	LDA	PLOTY	;SUBTRACT
	SEC		;DRAWY FROM PLOTY
	SBC	DRAWY
	STA	DELTAY	;AND SAVE DIFFERENCE
	LDA	#255	;Y INCREMENT
	STA	INCY	;=-1 (UP)
XVEC	LDA	DRXHI	;IS DRAWX
	CMP	PLXHI	;> PLOTX

	BCC	XMINUS	;NO!
	BNE	NOCMP	;MAYBE...
	LDA	DRAWX
	CMP	PLOTX
	BCC	XMINUS	;NO!
NOCMP	LDA	DRAWX	;SUBTRACT PLOTX
	SEC		;FROM DRAWX
	SBC	PLOTX
	STA	DELTAX	;AND SAVE DIFFERENCE
	LDA	DRXHI
	SBC	PLXHI
	STA	DELXHI	;SAVE HI BYTE TOO
	LDA	#1	;X INCREMENT
	STA	INCX	;=1 (RIGHT)
	BNE	VECSET	;BRANCH!
XMINUS	LDA	PLOTX	;SUBTRACT
	SEC		;DRAWX FROM PLOTX
	SBC	DRAWX
	STA	DELTAX	;AND SAVE DIFFERENCE
	LDA	PLXHI
	SBC	DRXHI
	STA	DELXHI	;SAVE HI BYTE TOO
	LDA	#255	;X INCREMENT
	STA	INCX	;=-1 (LEFT)
VECSET	LDA	#0	;ZERO OUT
	STA	ACCY	;ALL ACCUMULATORS
	STA	ACCX
	STA	ACCXHI
	STA	ACCYHI
	LDA	DELXHI	;IS DELTAX>DELTAY

	BNE	XMAX	;YES!
	LDA	DELTAX	;MAYBE...
	CMP	DELTAY
	BCC	YMAX	;NO, Y IS LARGER
XMAX	LDA	DELXHI	;SET UP DRAW
	STA	CNTHI	;COUNTER AND
	STA	ENDHI	;ENDPOINT
	LDA	DELTAX
	STA	COUNTR
	STA	ENDPT
	LDA	ENDHI	;DIVIDE ENDPOINT
	LSR	A	;BY 2 FOR
	LDA	ENDPT	;Y ACCUMULATOR
	ROR	A
	STA	ACCY
	JMP	DRAWGO	;START DRAWING
YMAX	LDA	#0	;DELTA Y LARGER,
	STA	CNTHI	;STORE IT IN
	STA	ENDHI	;THE DRAW COUNTER
	LDA	DELTAY	;AND ENDPOINT
	STA	COUNTR
	STA	ENDPT
	LSR	A	;DIVIDE BY 2 AND
	STA	ACCX	;SET X ACCUMULATOR
DRAWGO	LDA	COUNTR	;IF COUNTR>0...
	ORA	CNTHI
	BNE	BEGIN	;WE DRAW!
	RTS		;OTHERWISE, EXIT
BEGIN	LDA	ACCY	;ADD DELTA Y
	CLC		;TO Y ACCUMULATOR
	ADC	DELTAY
	STA	ACCY
	LDA	ACCYHI
	ADC	#0
	STA	ACCYHI
	CMP	ENDHI	;AT ENDPOINT

	BCC	BEGIN2	;NO, DO X
	BNE	ADJY
	LDA	ACCY	;CHECK LOW BYTE
	CMP	ENDPT
	BCC	BEGIN2	;DO X
ADJY	LDA	ACCY	;SUBTRACT ENDPOINT
	SEC		;FROM Y ACCUMULATOR
	SBC	ENDPT
	STA	ACCY
	LDA	ACCYHI
	SBC	ENDHI
	STA	ACCYHI
	LDA	PLOTY	;INCREMENT Y
	CLC		;POSITION
	ADC	INCY
	STA	PLOTY
BEGIN2	LDA	ACCX	;ADD DELTA X TO
	CLC		;X ACCUMULATOR
	ADC	DELTAX
	STA	ACCX
	LDA	ACCXHI
	ADC	DELXHI
	STA	ACCXHI
	CMP	ENDHI	;AT ENDPOINT

	BCC	PLOTIT	;NO, GO PLOT!
	BNE	ADJX
	LDA	ACCX	;CHECK LOW BYTE
	CMP	ENDPT
	BCC	PLOTIT	;GO PLOT
ADJX	LDA	ACCX	;SUBTRACT ENDPOINT
	SEC		;FROM X ACCUMULATOR
	SBC	ENDPT
	STA	ACCX
	LDA	ACCXHI
	SBC	ENDHI
	STA	ACCXHI
	LDA	INCX	;WHICH DIRECTION

	BMI	SUBX	;GOING LEFT
	BPL	ADDX	;GOING RIGHT
BBEGIN	BNE	BEGIN	;LEAPFROG JUMP
ADDX	LDA	PLOTX	;ADD INCREMENT
	CLC		;TO PLOTX
	ADC	INCX
	STA	PLOTX
	LDA	PLXHI
	ADC	#0
	STA	PLXHI
	JMP	PLOTIT	;GO DO THE PLOT
SUBX	LDA	PLOTX	;SUBTRACT 1
	SEC		;FROM PLOTX
	SBC	#1
	STA	PLOTX
	LDA	PLXHI
	SBC	#0
	STA	PLXHI
PLOTIT	JSR	PLOTCL	;PLOT THE POINT
	LDA	COUNTR	;ONE LESS PIXEL
	SEC		;TO PLOT
	SBC	#1
	STA	COUNTR
	LDA	CNTHI
	SBC	#0
	STA	CNTHI
	ORA	COUNTR	;DONE PLOTTING

	BNE	BBEGIN	;NOT YET!
	RTS		;FINIS!

;	---------
;	GRID DATA
;	---------

MAXHGT	DB	1,4,8	;MAXIMUM GRID HEIGHTS

GRDLIM	DB	$00,$80,$10	;ALTITUDE LIMITS (X100')

;	-----------
;	PLOT TABLES
;	-----------

COLORS	DB	$00,$55,$AA,$FF
BMASK1	DB	$3F,$CF,$F3,$FC
BMASK2	DB	$C0,$30,$0C,$03

;	----------------
;	BORDER PLOT DATA
;	----------------

LINTYP	DB	0,1,1,1,1,0,1,0	;0=PLOT, 1=DRAW
	DB	1,0,1,0,1,0,1
XHIGH	DB	0,1,1,0,0,0,0,0
	DB	1,1,0,0,1,1,1
XLOW	DB	10,54,54,10,10,192,192	;COORDS
	DB	192,54,54,192,192,32,32
	DB	32
YLOW	DB	10,10,180,180,10,10,180
	DB	94,94,157,157,53,53,11
	DB	93

;	--------------------------------
;	SCREEN CHARACTER POSITIONS, DATA
;	--------------------------------

XP	DB	27,28,29,30,31,25,26,27
	DB	28,29,25,26,27,28,29
	DB	25,26,27,28,29,30,31,32
	DB	33,34,25,26,27,28,29
	DB	25,26,27,28,29
	DB	25,26,27,28,25,26,27
	DB	25,26,27,25,26,27,25
	DB	26,27,28,29,25,26,27
	DB	28,29,30,25,26,27,28
	DB	29,30,37,37,37,37,37
	DB	37,37,37,37
YP	DB	16,16,16,16,16,30,30,30
	DB	30,30,40,40,40,40,40
	DB	58,58,58,58,58,58,58,58
	DB	58,58,72,72,72,72,72
	DB	82,82,82,82,82
	DB	98,98,98,98,112,112,112
	DB	122,122,122,132,132,132,146
	DB	146,146,146,146,160,160,160
	DB	160,160,160,170,170,170,170
	DB	170,170,17,25,33,41,49
	DB	57,65,73,81
CH	DB	51,40,41,48,26,57,48,47
	DB	51,26,58,48,47,51,26
	DB	47,34,42,37,35,52,41
	DB	54,37,26,57,48,47,51,26
	DB	58,48,47,51,26
	DB	33,44,52,26,56,54,26
	DB	57,54,26,58,54,26,38
	DB	53,37,44,26,51,40,41
	DB	48,51,26,51,35,47,50
	DB	37,26,50,33,36,41,33
	DB	52,41,47,46

;	--------------------------------
;	TOP-OF-SCREEN MESSAGES & INDEXES
;	--------------------------------

MSGIX	DB	0,22,44,66,88,110,132
	DB	154,176,198,220

MESSGE	DB	0,0,0,0,0,0,39,33,45,37	;GAME OVER
	DB	0,47,54,37,50,0,0,0,0,0
	DB	0,0

SUCLAN	DB	0,0,51,53,35,35,37,51	;LANDED OK
	DB	51,38,53,44,0,44,33,46
	DB	36,41,46,39,0,0

CRSLAN	DB	0,0,0,38,33,52,33,44	;CRASH
	DB	0,51,40,41,48,0,35,50
	DB	33,51,40,0,0,0

LOWFU	DB	0,38,53,37,44,0,44,37	;LOW FUEL
	DB	54,37,44,0,35,50,41,52
	DB	41,35,33,44,0,0

OUTFU	DB	0,0,0,0,0,47,53,52,0,47	;OUT OF FUEL
	DB	38,0,38,53,37,44,0,0,0
	DB	0,0,0

RADCRS	DB	0,0,50,33,36,41,33,52	;RADIATION
	DB	41,47,46,0,47,54,37,50
	DB	44,47,33,36,0,0

IFUMSG	DB	0,0,0,0,0,0,38,53,37,44	;INIT FUEL
	DB	26,0,0,0,16,16,16,0,0,0
	DB	0,0

GRVMSG	DB	0,0,0,0,0,0,39,50,33,54	;GRAVITY
	DB	41,52,57,26,0,0,0,0,0,0
	DB	0,0

TTLMSG	DB	0,0,0,0,0,0,50,37,52,50	;TITLE
	DB	47,38,41,50,37,1,0,0,0
	DB	0,0,0

AUTMSG	DB	0,0,0,0,34,121,26,0,52	;AUTHOR
	DB	111,109,0,40,117,100
	DB	115,111,110,0,0,0,0

MAGMSG	DB	0,0,0,33,46,33,44,47,39	;MAGAZINE
	DB	0,35,111,109,112,117
	DB	116,105,110,103,0,0,0

IFUEL1	DB	0	;INITIAL FUEL
IFUEL2	DB	5
FTIME	DB	0
GRAVTY	DB	0	;GRAVITY LEVEL
GRAVS	DB	10,24,48	;GRAVITY FACTORS
GCHAR	DB	44,45,40	;L,M,H

;	----------------------
;	INITIAL NUMERICAL DATA
;	----------------------

ININBR	DB	$02,$00,$00	;ALT
	DB	$00,$00,$00	;XV
	DB	$00,$00	;YV
	DB	$00,$00	;ZV
	DB	$01,$00,$00	;FUEL
	DB	$02	;SHIPS
	DB	$00,$00,$00	;SCORE

;	----------------
;	DIRECTION ARROWS
;	----------------

ARROWS	DB	0,$18,$18,$18,$7E,$3C,$18,0
	DB	0,$18,$3C,$7E,$18,$18,$18,0
	DB	0,$18,$C,$7E,$7E,$C,$18,0
	DB	0,$18,$30,$7E,$7E,$30,$18,0
	DB	0,$3C,$1C,$34,$64,$C0,0,0
	DB	0,0,$C,$98,$B0,$E0,$F0,0
ARRLO	DB	LOW [DISP+29+112*40]
	DB	LOW [DISP+29+122*40]
	DB	LOW [DISP+29+132*40]
ARRHI	DB	HIGH [DISP+29+112*40]
	DB	HIGH [DISP+29+122*40]
	DB	HIGH [DISP+29+132*40]

;	---------------
;	JOYSTICK TABLES
;	---------------

ENGIX	DB	0,0,0,0,0,0,3,2	;ENGINE NUMBERS
	DB	0,3,0,2,0,1,1,0

FUELIX	DB	0,0,0,0,0,0,8,6	;FUEL DATA POINTERS
	DB	0,8,0,6,0,3,3,0

FSIGNS	DB	0,0,0,0,0,0,2,1	;DIRECTIONS
	DB	0,2,0,1,0,0,0,0

VAH	DB	0,0,0,0,0,0,0,0	;VELOCITY ADD VALS.
	DB	0,$99,0,$99,0,0,$99,0
VAL	DB	0,0,0,0,0,0,1,1
	DB	0,$99,0,$99,0,1,$99,0

;	----------------------
;	DECIMAL TO BINARY DATA
;	----------------------

ALT1L	DB	0,10,20,30,40
	DB	50,60,70,80,90
ALT2H	DB	0,0,0,1,1
	DB	1,2,2,3,3
ALT2L	DB	0,$64,$C8,$2C,$90
	DB	$F4,$58,$BC,$20,$84
ALT3H	DB	0,3,7,$B,$F
	DB	$13,$17,$1B,$1F,$23
ALT3L	DB	0,$E8,$D0,$B8,$A0
	DB	$88,$70,$58,$40,$28
ALT4H	DB	0,$27,$4E,$75
ALT4L	DB	0,$10,$20,$30

GRDDIV	DB	88,22,3	;GRID DIVISION FACTORS

VELSHF	DB	7,4,1	;VELOCITY DIVISION FACS

;	----------------------------
;	GRID TERRAIN SAVE WORK AREAS
;	----------------------------

GDIX	DB	7,15,23,31
HSAVE	DB	56,57,58,59,60,61,62,63
	DB	0,1,2,3,4,5,6,7
	DB	7,15,23,31,39,47,55,63
	DB	0,8,16,24,32,40,48,56
HREST	DB	0,1,2,3,4,5,6,7
	DB	56,57,58,59,60,61,62,63
	DB	0,8,16,24,32,40,48,56
	DB	7,15,23,31,39,47,55,63

ENGCLS	DB	$C4,$16,$34,$02	;ENGINE COLORS
ENGTHR	DB	255,200,90,0	;ENG EFFECTIVENESS

RADINI	DB	120,255,0	;RADIATION TIMES

BASPIC	DB	$80,$40,$F0,$20,$10	;PAD IMAGE
PCOLRS	DB	$00,$32	;PAD COLORS

PYPOS	DB	72,82,30,40
POSNIX	DB	0,3,6,9
HI1	DB	0,0,0,1,1,2,2
HI2	DB	0,$49,$98,$47,$96,$45,$94
MED1	DB	0,$07,$14,$21,$28,$35,$42

ECOLOR	DB	$16,$C4,0,0,0	;DLI COLORS
UNSNUM	DS	17	;UNSIGNED NUMBERS
SIGNS	DS	4	;SIGN INFORMATION
HEIGHT	DS	64	;GRID HEIGHT
HGTSAV	DS	8	;HEIGHT SAVE
TEMP1	DS	3	;ENGINE...
TEMP2	DS	3	;TEMPS
TEMPS	DS	3	;0,1,2,3 TEMPS

;	EXPLOSION DATA

EXLV	DS	20	;EXPLOSION LIFE
EXXP	DS	20	;X POSITIONS
EXYP	DS	20	;Y POSITIONS
EXXI	DS	20	;X INCREMENT
EXYI	DS	20	;Y INCREMENT
EXXA	DS	20	;X ACCUM
EXYA	DS	20	;Y ACCUM
TEMPCX	DS	1

	END	MOVEIT+$2000