A.N.A.L.O.G. ISSUE 40 / MARCH 1986 / PAGE 44

The Clash of Kings

32K Cassette or Disk

by Bryan Schappel and Barry Kolbe

Welcome, one and all. Welcome to the 48th Intergalactic Clash of Kings. Today, we have with us the champions, humanoids from the planet Zorn, of the Ribos system. Their worthy opponents have just arrived from planet Mechtron, of the Aldeberon system. (Mechtron is inhabited only by a race of robots.) As is well known, the challengers have their choice in the form of combat to be used. This year, the game will be Terri-wars (terrain wars, for those with no imagination). The champions will return to their home planet with the Trophy of Kings.

I can see in the distance that the teams (each team is composed of nine players) are taking their positions on the field now.

Allow me to quickly explain the rules of Terri-wars, for those of you who are attending for the first time. Turn up your interpreters and listen. The goal is to destroy the opponent’s king. Simple?

As the game begins, players are positioned on a maplike field. The players move alternately, one square at a time. Diagonal moves are not permitted, and if an illegal move is attempted the team is alerted either by a tone or a verbal explanation. Combat is initiated by moving on an opponent. The two players involved are then whisked away to their Hell-Battle Globes (HBGs). At this point, the viewing monitor shifts to the Terri-wars battlefield.

The HBGs are equipped with Plasmaton Disruptors (also known as highly high-tech, extremely dangerous, very nasty Zappo-guns). These are traditionally used to ionize your opponent in some way. But this year, when an HBG is hit, the instant before impact a supremely intelligent super-computer teleports the lucky occupant to safety, or so the theory goes. You see, this year the teleportation systems were provided by Defectron, whose slogan is: “If it doesn’t work it needed fixing, anyway.”

Each player begins with a certain number of strength points, displayed as a bar graph at the bottom of your viewing screen. Each hit an HBG receives reduces the player’s strength by one. When a player’s strength reaches zero, that person is removed from play. (This is actually quite true. The teleportation systems have one minor flaw: each time someone is teleported, some body mass is lost, and the player’s strength is decreased. When the points reach zero, the remainder of the player is collected and transported to the hospital for the severely impaired.) The players, board positions, names and strength points are given below.

Board positions.
5               E
62               BF
731             ACG
84               DH
9               I

Humanoid — Planet: Zorn.
Player #NamePoints
1King9
2, 4Vipers7
3Canine4
6, 8Bipeds3
5, 7, 9Scorpions5

Robots — Planet: Mechtron.
Player #NamePoints
ACyborg9
C, EServ Droids7
BLand Rover4
F, HWarbots3
D, G, IAvions5

This year, to make Terri-wars more challenging, the battlefield has a randomly changing maze of pylon stars. Players aren’t allowed to move through these, but bumping into them doesn’t damage the battle globe.

The field also has randomly generated terrain features at the beginning of each game. There’s at least one path through the terrain composed of rocks, trees and mountains. Players aren’t allowed to move over these terrain features.

Notes on the program.

The impressive introduction screen for Clash of Kings was achieved by a Display List Interrupt (DLI) and a little fine vertical scrolling. The DLI will shade any object that’s 16 scan lines high (equal to a graphics 2 character in height) in all the shades of one color. This makes the text look as if it were cut from a polished metal bar.

The terrain board border was accomplished by using a character that was defined with every other bit turned on. This technique was also used to create the multi-colored terrain features. The players’ pieces are composed of four redefined characters, forming a 2×2 grid. The cursor was done with player in double width.

The battlefield was done in graphics mode 2, and the HBGs are players and 1, while the missiles are players 2 and 3. The battlefield portion runs almost completely in the vertical blank. Explosion sound effects were borrowed from Tom Hudson and Kyle Peacock’s game, Fire Bug (issue 23).

Typing it in.

Listing 1 is the BASIC data and data checking routines. This listing is used to create both cassette and disk versions of Clash of Kings. The data statements are listed in hexadecimal (base 16), so the program will fit in 16K systems.

The assembly language source code for the game was written with MAC/65 from OSS. Those readers interested in how the game works can obtain the listing on the disk version or on the ANALOG Computing TCS.

Cassette instructions.

  1. Type Listing 1 into your computer, using the BASIC cartridge, and verify your typing with Unicheck (see page 10).
  2. Type RUN and press RETURN. The program will ask:
    MAKE CASSETTE (0), OR DISK (1)? Type 0 and press RETURN. The program will begin checking the data statements, printing the line numbers as it goes. It will alert you to any problems. Fix any incorrect lines and re-RUN the program until all errors are eliminated.
  3. When all your data lines are correct, the computer will beep twice and prompt you to READY CASSETTE AND PRESS RETURN. Now, insert a blank cassette in your recorder, press the RECORD and PLAY buttons simultaneously, and hit RETURN. The message WRITING FILE will appear, and the program will create a machine language boot tape version of Clash of Kings, printing each data line mmiber as it goes. When the READY prompt appears, the game is recorded and ready to play. CSAVE the BASIC program on a separate tape before continuing.
  4. To play the game, rewind the tape created with the BASIC program to the beginning. Turn the computer off and remove all cartridges. Press the PLAY button on your recorder and turn on your computer, while holding down the START key. If you have an XL or XE series computer, you must hold the START and OPTION keys when you turn on the power. The computer will beep once. Hit RETURN, and Clash of Kings will load and run automatically.

Disk instructions.

  1. Type Listing 1 into your computer, using the BASIC cartridge, and verify your typing with Unicheck.
  2. Type RUN and press RETURN. The program will ask:
    MAKE CASSETTE (0), OR DISK (1)? Type 1 and press RETURN. The program will begin checking the data lines, printing each line number as it goes. It will alert you to any problems. Fix incorrect lines and re-RUN the program, if necessary, until all errors are eliminated.
  3. When all data lines are correct, you will be asked to INSERT DISK WITH DOS, PRESS RETURN. Put a disk containing DOS Version 2 in drive 1 and press RETURN. The message WRITING FILE will appear, and the program will create an AUTORUN.SYS file on the disk, displaying the line numbers as it goes. When the READY prompt appears, the game is ready to play. Be sure to SAVE the BASIC program before continuing.
  4. To play the game, insert the disk containing the AUTORUN.SYS file in drive 1. Turn off your computer, remove all cartridges, and turn the computer back on. Clash of Kings will load and run automatically.

Playing the game.

The Clash of Kings is a two-player game that requires two joysticks plugged into ports 1 and 2. The joystick in port 1 controls the player on the left, and stick 2 controls the player on the right. To move a player on the terrain board, move the cursor over the player you want and press the fire button. A short tone is given when a player is chosen.

Once you choose a player, it must be moved; illegal moves are not permitted, so choose with caution and skill. If you choose a player which can’t be moved, you’ll be told, and you may choose another piece. Move the cursor in one of the four cardinal directions and press the fire button again to make the choice final.

The cursor is on a rubber band. If you try to move it more than once in one direction, it snaps back to its original position for another choice. Clash of Kings will wait one-half second before snapping back the cursor. During this time, you may press the trigger to select a piece destination. Move onto a square held by your opponent to do battle. You’re not permitted to move onto your own pieces.

On the battlefield, control the Battle Globes by moving your stick in the four cardinal directions. To fire a Plasmaton Disruptor, press the stick button and move the stick in the direction you want to fire. You can only fire one shot at a time, and you can’t fire again until your Disruptor hits an object.

Pressing RESET at any time will return you to the title screen, ready to play again.

Well, that’s all. We hope you enjoy winning the Trophy of Kings and taking it back to your home planet. Now, let the games begin. H

Barry Kolbe is a mathematics teacher in Madison, WI. He uses the Atari to demonstrate graphing in his classroom. His former student Bryan Schappel studies Computer Science at the University of Wisconsin. This is their first major project as a team.

Listing 1.
BASIC Listing.

10 REM *** CLASH ***
20 TRAP 20:? "MAKE CASSETTE (0), OR DISK (1)";:INPUT DSK:IF DSK>1 THEN 20
30 TRAP 40000:DATA 0,1,2,3,4,5,6,7,8,9,0,0,0,0,0,0,0,10,11,12,13,14,15
40 DIM DAT$(91),HEX(22):FOR X=0 TO 22:READ N:HEX(X)=N:NEXT X:LINE=990:RESTORE 1000:TRAP 120:? "CHECKING DATA"
50 LINE=LINE+10:? "LINE:";LINE:READ DAT$:IF LEN(DAT$)<>90 THEN 220
60 DATLIN=PEEK(183)+PEEK(184)*256:IF DATLIN<>LINE THEN ? "LINE ";LINE;" MISSING!":END 
70 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)
80 IF PASS=2 THEN PUT #1,BYTE:NEXT X:READ CHKSUM:GOTO 50
90 TOTAL=TOTAL+BYTE:IF TOTAL>999 THEN TOTAL=TOTAL-1000
100 NEXT X:READ CHKSUM:IF TOTAL=CHKSUM THEN 50
110 GOTO 220
120 IF PEEK(195)<>6 THEN 220
130 IF PASS=0 THEN 170
140 IF  NOT DSK THEN 160
150 PUT #1,224:PUT #1,2:PUT #1,225:PUT #1,2:PUT #1,236:PUT #1,42:CLOSE #1:END 
160 FOR X=1 TO 71:PUT #1,0:NEXT X:CLOSE #1:END 
170 IF  NOT DSK THEN 200
180 ? "INSERT DISK WITH DOS, PRESS RETURN";:DIM IN$(1):INPUT IN$:OPEN #1,8,0,"D:AUTORUN.SYS"
190 PUT #1,255:PUT #1,255:PUT #1,0:PUT #1,32:PUT #1,144:PUT #1,52:GOTO 210
200 ? "READY CASSETTE AND PRESS RETURN";:OPEN #1,8,0,"C:"
210 ? :? "WRITING FILE":PASS=2:LINE=990:RESTORE 1000:TRAP 120:GOTO 50
220 ? "BAD DATA: LINE ";LINE:END 
230 DATA 0,42,216,31,255,31,169,0,141,47,2,169,60,141,2,211,169,0,141,231,2,133,14,169,56,141,232,2
240 DATA 133,15,169,0,133,10,169,32,133,11,24,96
1000 DATA 0000000000000000DBDB18E7E718DBDB0000000707FFFF00084A34DC3B2C5210FF7E3C187E183CFF0000000000,395
1010 DATA 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000,395
1020 DATA 00000000000000000000001C1C38000000000000000000000000003C3C00000000000000000000FE66EE76667E,567
1030 DATA 000018787818187E00007C664C18367E00007ECE180C663E00000C1C3C6CFE0C0000FE60FC06667C00007CE07C,823
1040 DATA E6667E0000FE660C18303000003C663CE666FE0000FE66FE060C380000003C3C003C3C00000000000000000006,507
1050 DATA 0C0C3C0C0C060000000000000000006030303C303060000000000000000000000000000000000000F83C66667E,703
1060 DATA E70000FC66FC66667C0000FE6660F0667E0000F86C66E66C7C0000FE607CE0667E0000FE63FC6C60600000FE66,895
1070 DATA 60EE667E000076367E36367600007E183C18187E00000E0606F6663C0000E66EF8786E660000F060E060767E00,619
1080 DATA 00E377FF6B6377000066767E7E6E760000FE66E666667E0000FC66EE7C60700000FE66E6666C760000FC66E67C,707
1090 DATA 6C760000FE607E06667E00007ED81818181C0000E666E6667E7C0000E666E6667E180000E363EB7F77630000E6,949
1100 DATA 663C3C66760000E6663C1838380000FE6C1830667E00000103193F3D1F0000000000000000000080C098FCBCF8,925
1110 DATA 0000000003070C1830183060C080000000000303030707070100E0E0E0C0CCCCF00000001F7070707000000000,529
1120 DATA F000F8F8000000000000007F00007E66667E1CCC00000C0F0F070301000018F8F8F0E0C0000000007060607000,725
1130 DATA 00000000F8F8F8000000000103077F00000000C0E0F0F0000000001F03637F00000000C00606FE000000000307,231
1140 DATA 0707000000000080809800181F0F0F0307670030F0E0C08080D800000701010307070000F0C0C0E0F0F0AAAAAA,891
1150 DATA AAAAAAAAAA000F030606070E000086C76767E67700006F66E6EEE667000080C06060C0C00000000000020A0A28,652
1160 DATA 000000008020A08800000001050515150000000040405050000003070A0A2A2A000000848E8AEAAA0000000000,379
1170 DATA 0000000101010707060700C0C0F0F030303C007F7F303038000000C0C0C0C0E0000000606C6C6C6F607F00CCCC,989
1180 DATA CCCCCC0CFC001B0F1B030F0F0C0FE6FCE6E0F030303C717F7F3F30303800C0F0F0C0C0C0E00007030F30361F00,538
1190 DATA 00F0E0F80E6EF800007F7F63030F000000E0800000000000007FC7070F0C1C3C00F09880C0E060E0007F63070F,297
1200 DATA 0C0C3C00F0D8C0C0E060E00003030F3F3F0F0600E0E0F87E7EF830005555555555555555000000000000000000,857
1210 DATA 000000000000000000000000000000000000000000000022280A0200000000A888208000000000020202020205,422
1220 DATA 00008080808080400000AAAAAA0000000000AAAAAA00000000000000000000000000707070425724F070704200,201
1230 DATA 100202020202020202020282700270467F24704693244100247070707042A6247070F0C7C624077070F0E20010,618
1240 DATA 22222222222222024124247070704700100707070707070707070707414324000034282500232C213328002F26,80
1250 DATA 002B292E27330000001C231E00212E212C2F27001119181500000000000000706C617965725A00690000000000,570
1260 DATA 0000006D656E5A4059000000006D656E5A405900808080A1AEA1ACAFA780A3AFADB0B5B4A9AEA780B0B2A5B3A5,767
1270 DATA AEB4B39A808080C0C0C0F4E8E5FEFFE3ECE1F3E8C0C0C0C0FBFDC0EFE6C0EBE9EEE7F3C0FBFDC0000000004041,113
1280 DATA 606140416061424362634243626342436263444564654445646548496869464766674A4B6A6B4A4B6A6B4C4D6C,979
1290 DATA 6D4C4D6C6D4C4D6C6D4E4F6E6F4E4F6E6F5253727350517071595A797A5B5C7B7C5D5E7D7E0003808080808080,425
1300 DATA 808080800C0000010680808080808080800F0A000004080980808080808012110D000002078080808080808080,875
1310 DATA 100B000005808080808080808080800E003332242322302F2E3B3C3D3E303132332E2F30313F40414200FC8484,952
1320 DATA 8484848484848484848484848484FC00FF01F20E05060506662981299C29BB2981296629BB299C29FFFFFFFF03,85
1330 DATA 0305050507070409030305050507070409C60F020000212C21330C00392F350023212E2E2F34002D2F36258E30,355
1340 DATA 2C2139253200000C00392F350037292E0034282500048E00000E26322F2D1AFF00000580A2A2AB8000252E3425,565
1350 DATA 323032293325330011191815FF0000000A23322126342524000022391AFF00000A222132323900002B2F2C2225,337
1360 DATA FF000E55565758FF0009223239212E00332328213030252CFF000000000340414647000030322533330080B3B4,24
1370 DATA A1B2B480000050514A4BFF036061666700000000342F00222527292E000000000070716A6BFE08111A08E67446,100
1380 DATA 0000005600000C1A29688814226152860A64180000000000000F1030E8081224D8A24C30000000000000000000,881
1390 DATA 9E6A1D649EE3400000000000000000004020100916E8E70000000000000000000000000000000000FDF9F5F1ED,554
1400 DATA EAE6E2DEDAD6D3CFCBC7C3BFBCB8B4B0ACA8A5A18A86827E7B77736F6B6764605C5854504D4945413936322E2A,777
1410 DATA 26221F1B17130F0B0804978B8074685D51463A2E23170C00834383C3070B0E0D01FFEC14161700008C786E6478,759
1420 DATA 645A141527283B3C4F506364517677788B8C9FA018FF1824244291A1B5A3D74E3C187E18003C187F183C42FFFF,71
1430 DATA 81A5A581FF7E1818181824244291A1B5A3D74E3C18FF18007F18FE183C42FFFF81939381FF7E18187E18242442,914
1440 DATA 89919D93D74E3C18181800FE183C183C42FFFF81C9C981FF7E180024661818662400003C425A5A423C00000000,744
1450 DATA 00000000000000000000000000A00098990014990015990016990017C8D0F160A203A0008485A9108586989185,971
1460 DATA C8D0FBE686CA10F660A027A90099E3118810FA60858B848C201F28C8B18B1002297F99E811B18B3003C8D0F0A0,743
1470 DATA 772007298810FA60A205204228CAD0FA60A5921869508D9A24A5931869508DA42460A900854D4C5FE4A919D002,492
1480 DATA A9648D00D2A9AA8D01D2208C28A9008D00D28D02D28D01D28D03D260A0032007298810FA60A2008EC8028EC602,279
1490 DATA A20E8EC502A2508E0002A22E8E0102A2C08E0ED4A23E8E2F0260A2008E2F024C0729A2008EC2028EC302E88E6F,569
1500 DATA 028E08D020F627A9FC8DC002A9108D07D4A9038D0AD08D0BD08D1DD0A9FFA03E990016990017C8C0A0D0F5A92C,31
1510 DATA 8D02D0A9B48D03D060A58D4901858D60A9008514A514F0FC60858E3018F018C913B014A58DD008A58EC90AB008,275
1520 DATA 9008A58EC90AB00218603860A5838D00D0A484A2008A99001488D0FAA484BD9C25990014C8E8E014D0F4990014,555
1530 DATA C8D0FA60A48AB9B8258D6429B9B9258D65294CFFFFA482B9FF05F013A0078488C683200729203029A4888810F1,231
1540 DATA C68260A482B90106F0F8A0078488E683200729203029A4888810F1E68260A58238E90EA8B90006F0328482A00F,459
1550 DATA 8488C684200729203029A4888810F160A58218690EA8B90006F0138482A00F8488E684200729203029A4888810,823
1560 DATA F160A68DA90F9D7802A9019D8402A58A8591A9FF858ABD7802C90FF022C90BD004A900F016C907D004A902D00E,136
1570 DATA C90ED004A904D006C90DD0DDA906858A3860BD8402D0D21860A20BA9008DC6028DC802A9078585A9108586A019,157
1580 DATA A95491858810FBA5851869288585A58669008586CA10E760A014AD0AD2C90F90F9C951B0F5AAAD0AD2C90190F9,83
1590 DATA C904B0F5858EBD000610E2A58E1869129D00068810D7AD0AD22903C903F0F70A0A0AA8A207B984258488A8A980,987
1600 DATA 990006A488C8CA10EF60A000A9008D3002A9248D3102B90E06F03F1002A9000A0A8488AA980AA8B900078580B9,237
1610 DATA 01078581A000BDE6249180E8C8C002D0F5A000A5801869288580A58169008581BDE6249180E8C8C002D0F5A488,125
1620 DATA C8C046D0B760D8A9018509A9EC850CA92A850DA9038D0FD2A9008D44028D08D2A2809500E8D0FBA8990006C8D0,651
1630 DATA FAA90985928593A045B93E25990E068810F7A011B9CC2599B0068810F7A9008580A9078581A200A92C858BA910,760
1640 DATA 858CA000A58B186902858B9180A58C6900C89180858CC8C01CD0E9A58018691C8580A58169008581A58B186934,47
1650 DATA 858BA58C6900858CE8E005D0C820412D204A2A20B728A065A228A906205CE4200928201E2A20962A20BF282095,259
1660 DATA 28A94E8583A9468584A90F8582A9008D8D24A58DF00DA9A68583A91A8582A9698D8D2420542820962A203029A6,123
1670 DATA 8D20EA2990062055294CC32BA003A9FF99C8258810FAA482848FB90006859030DBC913B0D7A68DD006C90A9006,369
1680 DATA B0CDC90A90C9A003B9B4258D0E2CB9B0258D0D2C8488A482B9FFFF201029B007A488980A99C825A4888810DCA0,879
1690 DATA 03B9C82510108810F8A9E3A025202A28201F284CC32B206C2820DA29A58A30F9A003D9C825F0098810F8207028,381
1700 DATA 4C3A2C20552920DA299028A68DA01DA9008514BD8402F01BA514F0F78810F0A491B9C0258D7C2CB9C1258D7D2C,421
1710 DATA 20FFFF4C3A2C206C28A482B900061012A590990006A48FA9809900062000294C9B2BA8C90A900A849A88B9B006,740
1720 DATA 85C3D008849988B9B00685C2A490C00A900A849A88B9B00685C3D008849988B9B00685C220B728A9408D0ED420,398
1730 DATA B02EA201B499B5C28899B006CA10F5A58DAAC598D00A4901AAA590A482990006A980A48F990006200029D692AD,843
1740 DATA B806F008ADC106F0034C802B8A49011869118D0026200928205428201E2A20962A20BF28209528A9F9A025202A,418
1750 DATA 28204B2820F627A9408D0ED420B7284CEC2AA9008D2F02A9248D3002A9248D3102AD0AD229F08597A9208DF402,829
1760 DATA 20F627200928A9218D0002A92E8D0102A9C08D0ED4A004B9DE2599C4028810F7A9008585A9118586A200BD1126,311
1770 DATA F012A8E8BD1126C9FFF009C9FEF0169185C8D0EFA5851869208585A58669008586E84C862DA93D8D2F02A9108D,189
1780 DATA 3724A9008D3624854D8594A9008587200729E687A587C908F00C8D05D4AD1FD0C906F03FD0E9A00084878C05D4,319
1790 DATA AD36241869208D3624AD372469008D3724E694A594C925F0B2A002D9A726F0058810F830B9A9008514A514C978,212
1800 DATA F0AFAD1FD0C906D0F3A9408D0ED44CB728488696A5978595A207A5958D0AD48D19D01869028595CA10F0A207A5,975
1810 DATA 9538E9028D0AD48D19D08595CA10F068A6964048A9028D0AD48D18D0A9658D0002A92E8D0102684048A9008D0A,687
1820 DATA D48D18D0A9508D0002A92E8D01026840A013A90199001099B4108810F7A90085A5A91085A6A20820A22EA901A0,148
1830 DATA 0091A5A01391A5CA10F060A5A518691485A5A5A6690085A660AD8402F0FBAD8502F0F6A232A058A907205CE4A9,858
1840 DATA 0185A1200928A9008DC4028DC5028DC6028DC702A9438D3002A9248D3102200931207A2E20603320362F20422F,336
1850 DATA 20F62720902F20BA308D1ED0201633204C33A5A0F0F6207833C6A0A6A020C533A6A0D6C2B5C2F0062085334CC7,609
1860 DATA 2E8A49018598207833208533A907A2E4A062205CE44CB728A004B9AA2699C4028810F760A93E8D2F02A9018D6F,292
1870 DATA 02A93A8DC0028DC202A9AA8DC1028DC302A9108D07D4A9038D1DD0A900A2039D00D09D08D0CA10F7A90085B985,458
1880 DATA BA60A900A0FF99001688D0FA60A900A0FF99001788D0FA60A06FA20FBD7627990014BD862799101588CA10F0A9,921
1890 DATA 388D00D085A9A9C08D01D085AAA96085ADA97085AE60A9008D1ED0B5C4F04FB5B5C907D025B5C4C908D0152026,841
1900 DATA 31B5B3F007201834A5CBD005A90095C460F6B1F6A9B5A99D00D0D6C460C90BD020B5C4C908D010202631B5B3F0,836
1910 DATA DE201834A5CBF0D7D6B1D6A9B5A99D00D0D6C460B5C6F074B5B5C90ED036B5C6C910D01A202631B5B3F0072018,170
1920 DATA 34A5CBD005A90095C660B5B138E91495B120AD308884A3A000B1A591A3C8C011D0F7D6ADD6C660C90DD034B5C6,514
1930 DATA C910D015202631B5B3F0CD201834A5CBF0C6B5B118691495B120AD30C884A3A011B1A591A38810F9C8A90091A5,286
1940 DATA F6ADD6C660BD780295B5C907D005A90895C460C90BD002F0F5C90ED005A91095C660C90DF0F760BD642785A685,413
1950 DATA A4B5ADA884A560A95185B1A97685B2A90385A2859EA91E85CEA90F85CFA90085BC85BD85C485C585C685C785A0,897
1960 DATA 85BB85C985A160A00F20F33099E62788D0F760AD0AD2C91690F9C9B2B0F5A20FDD6627F0EECA10F86020E730A2,409
1970 DATA 0FBDE627A886B7AD0AD22903AABD4D27A6B7990010CAD0E96086A7A90095B3B5B185A8B5B5A203DD5127F003CA,306
1980 DATA 10F8BD55271865A8A884A8A6A7B90010D004A90195B3608D1ED0B5BCD02ABD8402F00160B5B586A8A203DD5127,812
1990 DATA F00ACA10F8A900A6A895BC60A6A895BCA90785C9A90985CA20F83186A7B5BCC907D00BB5AB18690295AB9D02D0,754
2000 DATA 60C90BD00BB5AB38E90295AB9D02D060C90ED01EA90285C820EC318884C0A000B1BE91C0C8C008D0F7D6AFC6C8,947
2010 DATA A5C8D0E760C90DF00160A90285C820EC31C884C0A007B1BE91C08810F9A0009891BEF6AFC6C8A5C8D0E460BD59,656
2020 DATA 2785BF85C1B4AF84BE60B5A995ABB5AD18690495AF86A7E000D01B207A2FB4AFA200BDD627990016C8E8E008D0,566
2030 DATA F4A6A7B5AB9D02D06020852FB4AFA200BDDE27990017C8E8E008D0F4A6A74C1E3260A978859CA900859BC69BA5,567
2040 DATA 9BD0FAC69CA59CD0F060A946859CD0E9A5BBF0062003344C62E4A5A1F006207D284C62E4E69DA59DC909F0034C,864
2050 DATA F532A900859DE69FA59FC9039002A900859FA59FD017A9768DD632A9278DD732A9868DE632A9278DE7324CD132,692
2060 DATA C901D017A9968DD632A9278DD732A9A68DE632A9278DE7324CD132A9B68DD632A9278DD732A9C68DE632A9278D,691
2070 DATA E732A4ADA200BD9627990014C8E8E010D0F4A4AEA200BDA627990015C8E8E010D0F4A900854D8D1ED0A2002051,371
2080 DATA 31E8205131A20020BB2FE820BB2F208E3320B0332039344C62E4AD06D0F007A90085BC8D02D0AD07D0F007A900,46
2090 DATA 85BD8D03D0AD0ED02902F006A90185BA85A1AD0FD02901F006A90185B985A18D1ED060A20086A0A001B5B9F003,354
2100 DATA 84A060E8C8B5B9D0F760A200B4C288A90299C9108810FAE8B4C28899D3108810FA60A90085BC85BD8D02D08D03,633
2110 DATA D060A9008D00D08D01D060C69EA59EF00160A902859EA6A2F00EA9848D01D2BDAF268D00D2C6A260A20286A260,379
2120 DATA A5C9D00160A6C9A9AA8D03D2BD5B278D02D2C6C960B4ADA94385BB84A3A90585A8A92685A6A9B285A5BD642785,568
2130 DATA A4A000B1A591A3C8C010D0F7203D3218A5A5691085A5A5A6690085A6C6A8A5A8D0DF203D3260A6BBD00160A6BB,436
2140 DATA A98A8D03D2BD02278D02D2C6BB6086CCA90085CBE000D00EE8A5A8D5B1D002F002E6CBA6CC60CAA5A8D5B1D0F4,133
2150 DATA F0F4C6CEA5CEF00160A91E85CEA6CFBDE627A8A90099001020F330A6CF9DE627A8AD0AD22903AABD4D27990010,975
2160 DATA C6CFA5CFD004A90F85CF6000000000000000000000000000000000000000000000000000000000000000000000,584
2170 REM * 5265 BYTES

Listing 2.
Assembly Listing.

;
;Start of prog
;
	.OPT	NOLIST
;
; THE CLASH OF KINGS
; BY: Bryan Schappel
; and Barry Kolbe
;
; Chess section by:
; Bryan Schappel (c) 1985
;
; Equates
;
PMBASE	=	$D407	;PM base
GRACTL	=	$D01D	;PM enable
HPOSP0	=	$D000	;Horizontal
HPOSP1	=	$D001	;P/M positions
HPOSP2	=	$D002
HPOSP3	=	$D003
HITCLR	=	$D01E	;hit clear
SIZEP0	=	$D008	;P/M sizes
SIZEP1	=	$D009
SIZEP2	=	$D00A
SIZEP3	=	$D00B
SDMCTL	=	$022F	;DMA screen
SDLSTL	=	$0230	;display list
GPRIOR	=	$026F	;priority reg
PCOLR0	=	$02C0	;P/M colors
PCOLR1	=	$02C1
PCOLR2	=	$02C2
PCOLR3	=	$02C3
COLOR0	=	$02C4	;Playfield
COLOR1	=	$02C5	;colors
COLOR2	=	$02C6
COLOR3	=	$02C7
COLOR4	=	$02C8
COLPF0	=	$D016	;hardware color
COLPF1	=	$D017	;registers
COLPF2	=	$D018
COLPF3	=	$D019
COLBK	=	$D01A
WSYNC	=	$D40A	;wait for sync
CHBAS	=	$02F4	;char set
VDSLST	=	$0200	;DLI vector
NMIEN	=	$D40E	;NMI enable
SKCTL	=	$D20F	;sound controls
AUDCTL	=	$D208
AUDF1	=	$D200	;freq. registers
AUDF2	=	$D202
AUDF3	=	$D204
AUDF4	=	$D206
AUDC1	=	$D201	;volumes +
AUDC2	=	$D203	;distortions
AUDC3	=	$D205
AUDC4	=	$D207
VSCROL	=	$D405	;vertical scrol
CONSOL	=	$D01F	;console keys
STICK0	=	$0278	;joy stick
STRIG0	=	$0284	;fire button
RTCLOK	=	$14	;jiffy clock
SETVBV	=	$E45C	;Set VBLANK vec
SYSVBV	=	$E45F	;system Vblank
XITVBV	=	$E462	;exit VBV
ATRACT	=	$4D	;atract mode
BOOT?	=	$09	;boot flag
DOSINI	=	$0C	;init vector
COLDST	=	$0244	;cold start
RANDOM	=	$D20A	;random number
;
MYPM	=	$1000	;P/M memory
PLR0	=	MYPM+$0400
PLR1	=	MYPM+$0500
PLR2	=	MYPM+$0600
PLR3	=	MYPM+$0700
GAMBRD	=	$0600	;current board
HTAB	=	$06B0	;hit table
MYSCRN	=	MYPM
MYLINE	=	MYSCRN+$01E8
SCRTAB	=	$0700	;scr mem table
SLN1	=	MYSCRN	;scroll memory
SCMEM	=	MYSCRN
PMB	=	MYPM	;player base
ZPAGE	=	$00	;zero page
;
BORD	=	$01	;border char
BAR	=	$02	;hit point bar
STAR	=	$03	;boulder(star)
;
; Zero page usage
;
	*=	$80
INDR	*=	*+2	;indr temp hold
TABPOS	*=	*+1	;table posit
PLRX	*=	*+1	;cursor X-pos
PLRY	*=	*+1	;cursor Y-pos
SCR	*=	*+2	;screen pntr
SCROLC	*=	*+1	;scroll index
SAVEY	*=	*+1	;Y hold
SAVEX	*=	*+1	;X hold
MOVED	*=	*+1	;last move
IND2	*=	*+2	;temp indr hold
PLAYER	*=	*+1	;current PLYR
SAVEA	*=	*+1	;temp A hold
OLDPOS	*=	*+1	;old TABPOS
OLDPCE	*=	*+1	;old piece
OMOVE	*=	*+1	;old move
MEN1	*=	*+1	;lives left
MEN2	*=	*+1
LINES	*=	*+1	;lines scrolled
DCLOR	*=	*+1	;DLI color
DLIX	*=	*+1	;DLI save X
INTC	*=	*+1	;DLI base color
WINNER	*=	*+1	;battle winner
PLRTYPE	*=	*+2	;player type
TIMER	*=	*+2	;fade timer
VTIME	*=	*+1	;plyr def timer
STIME	*=	*+1	;sound timer
PTYPE	*=	*+1	;plyr type
RFLG	*=	*+1	;who hit flag
EXEC	*=	*+1	;vblank exec flg
WSR	*=	*+1	;whirley sound
PMFR	*=	*+2	;player pntrs
PMTO	*=	*+2
XTEM	*=	*+1	;save x
TEMP	*=	*+1	;temp location
XPOS0	*=	*+1	;plyr positions
XPOS1	*=	*+1	;x coord
XPOS2	*=	*+1
XPOS3	*=	*+1
YPOS0	*=	*+1	;ditto-y coord
YPOS1	*=	*+1
YPOS2	*=	*+1
YPOS3	*=	*+1
SCX	*=	*+2	;scr pos of plyr
WC	*=	*+2	;wall check flg
SAVST	*=	*+2	;saves sticks
X1	*=	*+1	;store x
X2	*=	*+1	;store x
ZAP	*=	*+2	;plyr hit flag
BSR	*=	*+1	;blowup snd reg
MISM	*=	*+2	;miss direction
MISF	*=	*+2	;missile from
MIST	*=	*+2	;missile to
HTS	*=	*+2	;# hits left
HSCL	*=	*+2	;h scrl reg
VSCL	*=	*+2	;v scrl reg
UDFL	*=	*+1	;missile Up/Dn?
MSR	*=	*+1	;missile sound
MTIME	*=	*+1	;missile timer
PFLG	*=	*+1	;hit plyr flg
PCX	*=	*+1	;store x
TRY	*=	*+1	;other plyr pos
ZTIME	*=	*+1	;maze timer
MZR	*=	*+1	;random maze ptr

	*=	$2000

;
;Redefined Character Set Data
;
;by: Bryan Schappel with
;    Barry Kolbe (c) 1985
;
	.BYTE	$00,$00,$00,$00
	.BYTE	$00,$00,$00,$00
	.BYTE	$DB,$DB,$18,$E7
	.BYTE	$E7,$18,$DB,$DB
	.BYTE	$00,$00,$00,$07
	.BYTE	$07,$FF,$FF,$00
	.BYTE	$08,$4A,$34,$DC
	.BYTE	$3B,$2C,$52,$10
	.BYTE	$FF,$7E,$3C,$18
	.BYTE	$7E,$18,$3C,$FF
	.BYTE	$00,$00,$00,$00
	.BYTE	$00,$00,$00,$00
	.BYTE	$00,$00,$00,$00
	.BYTE	$00,$00,$00,$00
	.BYTE	$00,$00,$00,$00
	.BYTE	$00,$00,$00,$00
	.BYTE	$00,$00,$00,$00
	.BYTE	$00,$00,$00,$00
	.BYTE	$00,$00,$00,$00
	.BYTE	$00,$00,$00,$00
	.BYTE	$00,$00,$00,$00
	.BYTE	$00,$00,$00,$00
	.BYTE	$00,$00,$00,$00
	.BYTE	$00,$00,$00,$00
	.BYTE	$00,$00,$00,$00
	.BYTE	$00,$1C,$1C,$38
	.BYTE	$00,$00,$00,$00
	.BYTE	$00,$00,$00,$00
	.BYTE	$00,$00,$00,$00
	.BYTE	$00,$3C,$3C,$00
	.BYTE	$00,$00,$00,$00
	.BYTE	$00,$00,$00,$00
	.BYTE	$00,$FE,$66,$EE
	.BYTE	$76,$66,$7E,$00
	.BYTE	$00,$18,$78,$78
	.BYTE	$18,$18,$7E,$00
	.BYTE	$00,$7C,$66,$4C
	.BYTE	$18,$36,$7E,$00
	.BYTE	$00,$7E,$CE,$18
	.BYTE	$0C,$66,$3E,$00
	.BYTE	$00,$0C,$1C,$3C
	.BYTE	$6C,$FE,$0C,$00
	.BYTE	$00,$FE,$60,$FC
	.BYTE	$06,$66,$7C,$00
	.BYTE	$00,$7C,$E0,$7C
	.BYTE	$E6,$66,$7E,$00
	.BYTE	$00,$FE,$66,$0C
	.BYTE	$18,$30,$30,$00
	.BYTE	$00,$3C,$66,$3C
	.BYTE	$E6,$66,$FE,$00
	.BYTE	$00,$FE,$66,$FE
	.BYTE	$06,$0C,$38,$00
	.BYTE	$00,$00,$3C,$3C
	.BYTE	$00,$3C,$3C,$00
	.BYTE	$00,$00,$00,$00
	.BYTE	$00,$00,$00,$00
	.BYTE	$06,$0C,$0C,$3C
	.BYTE	$0C,$0C,$06,$00
	.BYTE	$00,$00,$00,$00
	.BYTE	$00,$00,$00,$00
	.BYTE	$60,$30,$30,$3C
	.BYTE	$30,$30,$60,$00
	.BYTE	$00,$00,$00,$00
	.BYTE	$00,$00,$00,$00
	.BYTE	$00,$00,$00,$00
	.BYTE	$00,$00,$00,$00
	.BYTE	$00,$F8,$3C,$66
	.BYTE	$66,$7E,$E7,$00
	.BYTE	$00,$FC,$66,$FC
	.BYTE	$66,$66,$7C,$00
	.BYTE	$00,$FE,$66,$60
	.BYTE	$F0,$66,$7E,$00
	.BYTE	$00,$F8,$6C,$66
	.BYTE	$E6,$6C,$7C,$00
	.BYTE	$00,$FE,$60,$7C
	.BYTE	$E0,$66,$7E,$00
	.BYTE	$00,$FE,$63,$FC
	.BYTE	$6C,$60,$60,$00
	.BYTE	$00,$FE,$66,$60
	.BYTE	$EE,$66,$7E,$00
	.BYTE	$00,$76,$36,$7E
	.BYTE	$36,$36,$76,$00
	.BYTE	$00,$7E,$18,$3C
	.BYTE	$18,$18,$7E,$00
	.BYTE	$00,$0E,$06,$06
	.BYTE	$F6,$66,$3C,$00
	.BYTE	$00,$E6,$6E,$F8
	.BYTE	$78,$6E,$66,$00
	.BYTE	$00,$F0,$60,$E0
	.BYTE	$60,$76,$7E,$00
	.BYTE	$00,$E3,$77,$FF
	.BYTE	$6B,$63,$77,$00
	.BYTE	$00,$66,$76,$7E
	.BYTE	$7E,$6E,$76,$00
	.BYTE	$00,$FE,$66,$E6
	.BYTE	$66,$66,$7E,$00
	.BYTE	$00,$FC,$66,$EE
	.BYTE	$7C,$60,$70,$00
	.BYTE	$00,$FE,$66,$E6
	.BYTE	$66,$6C,$76,$00
	.BYTE	$00,$FC,$66,$E6
	.BYTE	$7C,$6C,$76,$00
	.BYTE	$00,$FE,$60,$7E
	.BYTE	$06,$66,$7E,$00
	.BYTE	$00,$7E,$D8,$18
	.BYTE	$18,$18,$1C,$00
	.BYTE	$00,$E6,$66,$E6
	.BYTE	$66,$7E,$7C,$00
	.BYTE	$00,$E6,$66,$E6
	.BYTE	$66,$7E,$18,$00
	.BYTE	$00,$E3,$63,$EB
	.BYTE	$7F,$77,$63,$00
	.BYTE	$00,$E6,$66,$3C
	.BYTE	$3C,$66,$76,$00
	.BYTE	$00,$E6,$66,$3C
	.BYTE	$18,$38,$38,$00
	.BYTE	$00,$FE,$6C,$18
	.BYTE	$30,$66,$7E,$00
	.BYTE	$00,$01,$03,$19
	.BYTE	$3F,$3D,$1F,$00
	.BYTE	$00,$00,$00,$00
	.BYTE	$00,$00,$00,$00
	.BYTE	$00,$80,$C0,$98
	.BYTE	$FC,$BC,$F8,$00
	.BYTE	$00,$00,$00,$03
	.BYTE	$07,$0C,$18,$30
	.BYTE	$18,$30,$60,$C0
	.BYTE	$80,$00,$00,$00
	.BYTE	$00,$03,$03,$03
	.BYTE	$07,$07,$07,$01
	.BYTE	$00,$E0,$E0,$E0
	.BYTE	$C0,$CC,$CC,$F0
	.BYTE	$00,$00,$00,$1F
	.BYTE	$70,$70,$70,$70
	.BYTE	$00,$00,$00,$00
	.BYTE	$F0,$00,$F8,$F8
	.BYTE	$00,$00,$00,$00
	.BYTE	$00,$00,$00,$7F
	.BYTE	$00,$00,$7E,$66
	.BYTE	$66,$7E,$1C,$CC
	.BYTE	$00,$00,$0C,$0F
	.BYTE	$0F,$07,$03,$01
	.BYTE	$00,$00,$18,$F8
	.BYTE	$F8,$F0,$E0,$C0
	.BYTE	$00,$00,$00,$00
	.BYTE	$70,$60,$60,$70
	.BYTE	$00,$00,$00,$00
	.BYTE	$00,$F8,$F8,$F8
	.BYTE	$00,$00,$00,$00
	.BYTE	$01,$03,$07,$7F
	.BYTE	$00,$00,$00,$00
	.BYTE	$C0,$E0,$F0,$F0
	.BYTE	$00,$00,$00,$00
	.BYTE	$1F,$03,$63,$7F
	.BYTE	$00,$00,$00,$00
	.BYTE	$C0,$06,$06,$FE
	.BYTE	$00,$00,$00,$00
	.BYTE	$03,$07,$07,$07
	.BYTE	$00,$00,$00,$00
	.BYTE	$00,$80,$80,$98
	.BYTE	$00,$18,$1F,$0F
	.BYTE	$0F,$03,$07,$67
	.BYTE	$00,$30,$F0,$E0
	.BYTE	$C0,$80,$80,$D8
	.BYTE	$00,$00,$07,$01
	.BYTE	$01,$03,$07,$07
	.BYTE	$00,$00,$F0,$C0
	.BYTE	$C0,$E0,$F0,$F0
	.BYTE	$AA,$AA,$AA,$AA
	.BYTE	$AA,$AA,$AA,$AA
	.BYTE	$00,$0F,$03,$06
	.BYTE	$06,$07,$0E,$00
	.BYTE	$00,$86,$C7,$67
	.BYTE	$67,$E6,$77,$00
	.BYTE	$00,$6F,$66,$E6
	.BYTE	$EE,$E6,$67,$00
	.BYTE	$00,$80,$C0,$60
	.BYTE	$60,$C0,$C0,$00
	.BYTE	$00,$00,$00,$00
	.BYTE	$02,$0A,$0A,$28
	.BYTE	$00,$00,$00,$00
	.BYTE	$80,$20,$A0,$88
	.BYTE	$00,$00,$00,$01
	.BYTE	$05,$05,$15,$15
	.BYTE	$00,$00,$00,$00
	.BYTE	$40,$40,$50,$50
	.BYTE	$00,$00,$03,$07
	.BYTE	$0A,$0A,$2A,$2A
	.BYTE	$00,$00,$00,$84
	.BYTE	$8E,$8A,$EA,$AA
	.BYTE	$00,$00,$00,$00
	.BYTE	$00,$00,$00,$00
	.BYTE	$01,$01,$01,$07
	.BYTE	$07,$06,$07,$00
	.BYTE	$C0,$C0,$F0,$F0
	.BYTE	$30,$30,$3C,$00
	.BYTE	$7F,$7F,$30,$30
	.BYTE	$38,$00,$00,$00
	.BYTE	$C0,$C0,$C0,$C0
	.BYTE	$E0,$00,$00,$00
	.BYTE	$60,$6C,$6C,$6C
	.BYTE	$6F,$60,$7F,$00
	.BYTE	$CC,$CC,$CC,$CC
	.BYTE	$CC,$0C,$FC,$00
	.BYTE	$1B,$0F,$1B,$03
	.BYTE	$0F,$0F,$0C,$0F
	.BYTE	$E6,$FC,$E6,$E0
	.BYTE	$F0,$30,$30,$3C
	.BYTE	$71,$7F,$7F,$3F
	.BYTE	$30,$30,$38,$00
	.BYTE	$C0,$F0,$F0,$C0
	.BYTE	$C0,$C0,$E0,$00
	.BYTE	$07,$03,$0F,$30
	.BYTE	$36,$1F,$00,$00
	.BYTE	$F0,$E0,$F8,$0E
	.BYTE	$6E,$F8,$00,$00
	.BYTE	$7F,$7F,$63,$03
	.BYTE	$0F,$00,$00,$00
	.BYTE	$E0,$80,$00,$00
	.BYTE	$00,$00,$00,$00
	.BYTE	$7F,$C7,$07,$0F
	.BYTE	$0C,$1C,$3C,$00
	.BYTE	$F0,$98,$80,$C0
	.BYTE	$E0,$60,$E0,$00
	.BYTE	$7F,$63,$07,$0F
	.BYTE	$0C,$0C,$3C,$00
	.BYTE	$F0,$D8,$C0,$C0
	.BYTE	$E0,$60,$E0,$00
	.BYTE	$03,$03,$0F,$3F
	.BYTE	$3F,$0F,$06,$00
	.BYTE	$E0,$E0,$F8,$7E
	.BYTE	$7E,$F8,$30,$00
	.BYTE	$55,$55,$55,$55
	.BYTE	$55,$55,$55,$55
	.BYTE	$00,$00,$00,$00
	.BYTE	$00,$00,$00,$00
	.BYTE	$00,$00,$00,$00
	.BYTE	$00,$00,$00,$00
	.BYTE	$00,$00,$00,$00
	.BYTE	$00,$00,$00,$00
	.BYTE	$00,$00,$00,$00
	.BYTE	$00,$00,$00,$00
	.BYTE	$22,$28,$0A,$02
	.BYTE	$00,$00,$00,$00
	.BYTE	$A8,$88,$20,$80
	.BYTE	$00,$00,$00,$00
	.BYTE	$02,$02,$02,$02
	.BYTE	$02,$05,$00,$00
	.BYTE	$80,$80,$80,$80
	.BYTE	$80,$40,$00,$00
	.BYTE	$AA,$AA,$AA,$00
	.BYTE	$00,$00,$00,$00
	.BYTE	$AA,$AA,$AA,$00
	.BYTE	$00,$00,$00,$00
	.BYTE	$00,$00,$00,$00
	.BYTE	$00,$00,$00,$00
;
;Game board display list
;
DLIST1	.BYTE	$70,$70,$70,$42
	.WORD	PNAME
	.BYTE	$F0,$70,$70
	.BYTE	$42,<MYSCRN,>MYSCRN
	.BYTE	$02,$02,$02,$02
	.BYTE	$02,$02,$02,$02
	.BYTE	$02,$02,$82,$70
	.BYTE	$02,$70,$46
	.WORD	PLAER
	.BYTE	$70
	.BYTE	$46,<MENL,>MENL
	.BYTE	$41,<DLIST1,>DLIST1
;
;Intro Display List
;
IDLST	.BYTE	$70,$70,$70,$70
	.BYTE	$42,<PRES,>PRES
	.BYTE	$70,$70,$F0,$C7
	.WORD	PNAM2
	.BYTE	$07
	.BYTE	$70,$70,$F0
DVC	.BYTE	$E2,<SLN1,>SLN1
	.BYTE	$22,$22,$22,$22,$22
	.BYTE	$22,$22,$02
	.BYTE	$41,<IDLST,>IDLST
;
;Battle Display List
;
DLIST	.BYTE	$70,$70,$70,$47
	.WORD	SCMEM
	.BYTE	$07,$07,$07,$07,$07
	.BYTE	$07,$07,$07,$07,$07
	.BYTE	$07,$41
	.WORD	DLIST
;
;Screen Memory
;
PNAME	.SBYTE	"  THE CLASH OF KINGS   <C> ANALOG 1985  "
PLAER	.SBYTE	"     player",26," i      "
MENL	.SBYTE	"  men",26,0,25,"    men",26,0,25," "
PRES	.SBYTE	+$80,"   ANALOG COMPUTING PRESENTS:   "
PNAM2	.SBYTE	+$C0,"   THE^_CLASH   "
	.SBYTE	+$C0," [] OF KINGS [] "
;
;Player 1 Pieces
;
CHARS	.BYTE	$00,$00,$00,$00
;HUMAN W/ PACK #1-2
	.BYTE	$40,$41,$60,$61
	.BYTE	$40,$41,$60,$61
;SCORPION #3-5
	.BYTE	$42,$43,$62,$63
	.BYTE	$42,$43,$62,$63
	.BYTE	$42,$43,$62,$63
;VIPER #6-7
	.BYTE	$44,$45,$64,$65
	.BYTE	$44,$45,$64,$65
;CANINE #8
	.BYTE	$48,$49,$68,$69
;KING #9
	.BYTE	$46,$47,$66,$67
;
;Player 2 Pieces
;
;TANK DROID #10-11
	.BYTE	$4A,$4B,$6A,$6B
	.BYTE	$4A,$4B,$6A,$6B
;PLANE #12-14
	.BYTE	$4C,$4D,$6C,$6D
	.BYTE	$4C,$4D,$6C,$6D
	.BYTE	$4C,$4D,$6C,$6D
;SERVICE DROID #15-16
	.BYTE	$4E,$4F,$6E,$6F
	.BYTE	$4E,$4F,$6E,$6F
;TRANSPORT #17
	.BYTE	$52,$53,$72,$73
;CYBORG #18
	.BYTE	$50,$51,$70,$71
;TERRAIN PIECES #19-21
	.BYTE	$59,$5A,$79,$7A
	.BYTE	$5B,$5C,$7B,$7C
	.BYTE	$5D,$5E,$7D,$7E
;
;Game board initial set-up
;structure DATA table
;
BRDSET
;
;Line #1
;
	.BYTE	$00,$03,$80,$80,$80
	.BYTE	$80,$80,$80,$80,$80
	.BYTE	$80,$80,$0C,$00
;
;Line #2
;
	.BYTE	$00,$01,$06,$80,$80
	.BYTE	$80,$80,$80,$80,$80
	.BYTE	$80,$0F,$0A,$00
;
;Line #3
;
	.BYTE	$00,$04,$08,$09,$80
	.BYTE	$80,$80,$80,$80,$80
	.BYTE	$12,$11,$0D,$00
;
;Line #4
;
	.BYTE	$00,$02,$07,$80,$80
	.BYTE	$80,$80,$80,$80,$80
	.BYTE	$80,$10,$0B,$00
;
;Line #5
;
	.BYTE	$00,$05,$80,$80,$80
	.BYTE	$80,$80,$80,$80,$80
	.BYTE	$80,$80,$0E,$00
;
;Path positions
;
PATHS	.BYTE	51,50,36,35,34
	.BYTE	48,47,46
	.BYTE	59,60,61,62,48
	.BYTE	49,50,51
	.BYTE	46,47,48,49,63
	.BYTE	64,65,66
;
;Cursor Definition
;
DEFPL1	.BYTE	$00,$FC,$84,$84,$84
	.BYTE	$84,$84,$84,$84,$84
	.BYTE	$84,$84,$84,$84,$84
	.BYTE	$84,$84,$84,$FC,$00
;
;Game table vectors (LSB)
;
GTABL	.BYTE	<[GAMBRD-1]	;Left
	.BYTE	<[GAMBRD+1]
	.BYTE	<[GAMBRD-14]	;Up
	.BYTE	<[GAMBRD+14]	;Down
;
;Game table (MSB)
;
GTABH	.BYTE	>[GAMBRD-1]
	.BYTE	>[GAMBRD+1]
	.BYTE	>[GAMBRD-14]
	.BYTE	>[GAMBRD+14]
;
;Table of movement routines
;
MOVTAB	.WORD	LEFT
	.WORD	RIGHT
	.WORD	UP
	.WORD	DOWN
;
;Un-move vector table
;
NEGTAB	.WORD	RIGHT
	.WORD	LEFT
	.WORD	DOWN
	.WORD	UP
;
;Move holder
;
MOVES	.BYTE	$FF,$FF,$FF,$FF
;
;Hit point table
;
HITTAB	.BYTE	3,3,5,5,5,7,7,4,9
	.BYTE	3,3,5,5,5,7,7,4,9
;
;Intro colors
;
ICLR	.BYTE	$C6,$0F,$02,$00,$00
;
;Text
;
ALAS	.SBYTE	"ALAS, YOU CANNOT MOVE."
TROPHY	.SBYTE	"PLAYER  , YOU WIN THE $."
STXT	.BYTE	0,0,14
	.SBYTE	"FROM:",$FF
	.BYTE	0,0	;blanks
	.BYTE	5	;BBK enter
	.SBYTE	" BBK  ENTERPRISES "
	.SBYTE	"1985",$FF
	.BYTE	0,0,0	;blank lines
	.BYTE	10
	.SBYTE	"CRAFTED  BY:",$FF
	.BYTE	0,0	;blank
	.BYTE	10
	.SBYTE	"BARRY  KOLBE",$FF
	.BYTE	0
	.BYTE	14
	.SBYTE	"....",$FF
	.BYTE	0
	.BYTE	9
	.SBYTE	"BRYAN SCHAPPEL",$FF
	.BYTE	0	;blank
	.BYTE	0	;blank
	.BYTE	0
	.BYTE	0
	.BYTE	3
	.SBYTE	"....  PRESS  START   ...."
	.BYTE	$FF
	.BYTE	3
	.SBYTE	".afg    TO BEGIN     pqjk"
	.BYTE	$FE
;
;Lines to pause scrolling on
;
PLINS	.BYTE	8,17,26
;
;battle field colors
;
BFCLR	.BYTE	$08,$E6,$74,$46,$00
;
;whirly snd data
;
WSN	.BYTE	$00,$00,$56
;
;plyr explode data
;
EXPLR	.BYTE	$00,$00,$0C,$1A
	.BYTE	$29,$68,$88,$14
	.BYTE	$22,$61,$52,$86
	.BYTE	$0A,$64,$18,$00
	.BYTE	$00,$00,$00,$00
	.BYTE	$00,$0F,$10,$30
	.BYTE	$E8,$08,$12,$24
	.BYTE	$D8,$A2,$4C,$30
	.BYTE	$00,$00,$00,$00
	.BYTE	$00,$00,$00,$00
	.BYTE	$00,$9E,$6A,$1D
	.BYTE	$64,$9E,$E3,$40
	.BYTE	$00,$00,$00,$00
	.BYTE	$00,$00,$00,$00
	.BYTE	$00,$40,$20,$10
	.BYTE	$09,$16,$E8,$E7
	.BYTE	$00,$00,$00,$00
	.BYTE	$00,$00,$00,$00
	.BYTE	$00,$00,$00,$00
	.BYTE	$00,$00,$00,$00
;
;explosion snd data
;
EXF	.BYTE	$00,$FD,$F9,$F5
	.BYTE	$F1,$ED,$EA,$E6
	.BYTE	$E2,$DE,$DA,$D6
	.BYTE	$D3,$CF,$CB,$C7
	.BYTE	$C3,$BF,$BC,$B8
	.BYTE	$B4,$B0,$AC,$A8
	.BYTE	$A5,$A1,$8A,$86
	.BYTE	$82,$7E,$7B,$77
	.BYTE	$73,$6F,$6B,$67
	.BYTE	$64,$60,$5C,$58
	.BYTE	$54,$50,$4D,$49
	.BYTE	$45,$41,$39,$36
	.BYTE	$32,$2E,$2A,$26
	.BYTE	$22,$1F,$1B,$17
	.BYTE	$13,$0F,$0B,$08
	.BYTE	$04,$97,$8B,$80
	.BYTE	$74,$68,$5D,$51
	.BYTE	$46,$3A,$2E,$23
	.BYTE	$17,$0C,$00
;
;maze color table
;
MZCOL	.BYTE	$83,$43,$83,$C3
;
;stick directions
;
WALLTAB	.BYTE	$07,$0B,$0E,$0D
;
;adder table to add 1 left-right
;up or down
;
ADDER	.BYTE	$01,$FF,$EC,$14
;
;missile pages
;
MSUP	.BYTE	>PLR2,>PLR3
;
;missile snd data
;
MSN	.BYTE	$00,$00,$8C,$78
	.BYTE	$6E,$64,$78,$64
	.BYTE	$5A
;
;plyr pages
;
UDTAB	.BYTE	>PLR0,>PLR1
;
;table to check maze
;
MZCK	.BYTE	$27,$28,$3B,$3C
	.BYTE	$4F,$50,$63,$64
	.BYTE	$51,$76,$77,$78
	.BYTE	$8B,$8C,$9F,$A0
;
;player definitions
;
PLY1	.BYTE	$18,$FF,$18,$24
	.BYTE	$24,$42,$91,$A1
	.BYTE	$B5,$A3,$D7,$4E
	.BYTE	$3C,$18,$7E,$18
PLY2	.BYTE	$00,$3C,$18,$7F
	.BYTE	$18,$3C,$42,$FF
	.BYTE	$FF,$81,$A5,$A5
	.BYTE	$81,$FF,$7E,$18
PLY3	.BYTE	$18,$18,$18,$24
	.BYTE	$24,$42,$91,$A1
	.BYTE	$B5,$A3,$D7,$4E
	.BYTE	$3C,$18,$FF,$18
PLY4	.BYTE	$00,$7F,$18,$FE
	.BYTE	$18,$3C,$42,$FF
	.BYTE	$FF,$81,$93,$93
	.BYTE	$81,$FF,$7E,$18
PLY5	.BYTE	$18,$7E,$18,$24
	.BYTE	$24,$42,$89,$91
	.BYTE	$9D,$93,$D7,$4E
	.BYTE	$3C,$18,$18,$18
PLY6	.BYTE	$00,$FE,$18,$3C
	.BYTE	$18,$3C,$42,$FF
	.BYTE	$FF,$81,$C9,$C9
	.BYTE	$81,$FF,$7E,$18
MISS0	.BYTE	$00,$24,$66,$18
	.BYTE	$18,$66,$24,$00
MISS1	.BYTE	$00,$3C,$42,$5A
	.BYTE	$5A,$42,$3C,$00
;
;maze table
;
MZTAB	.BYTE	$00,$00,$00,$00,$00
	.BYTE	$00,$00,$00,$00,$00
	.BYTE	$00,$00,$00,$00,$00
	.BYTE	$00
;
;Erase P/M Memory
;
CLRPM	LDY	#0	;zero A + Y
	TYA
CPM1	STA	PLR0,Y	;zap plyr's
	STA	PLR1,Y
	STA	PLR2,Y
	STA	PLR3,Y
	INY
	BNE	CPM1	;loop again
	RTS		;bye.
;
;Erase screen memory
;
CLRSCR	LDX	#3	;do 1K
	LDY	#0
	STY	SCR
	LDA	# >MYSCRN
	STA	SCR+1
	TYA
CS1	STA	(SCR),Y
	INY
	BNE	CS1	;page yet?
	INC	SCR+1
	DEX		;next page
	BPL	CS1
	RTS		;done.
;
;Erase MYLINE
;
ERMYLN	LDY	#39	;40 chars
	LDA	#0
ERL	STA	MYLINE-5,Y	;on scrn
	DEY
	BPL	ERL
	RTS		;done
;
;Print routine
;
EPRINT	STA	IND2	;save address
	STY	IND2+1
	JSR	ERMYLN	;clear line
	INY		;Y = 0
PRL1	LDA	(IND2),Y	;first char
	BPL	PRL2	;normal? print
	AND	#$7F	;mask inverse
PRL2	STA	MYLINE,Y	;on screen
	LDA	(IND2),Y	;get again
	BMI	PRL3	;if>$80 end
	INY		;up count
	BNE	PRL1	;go again
PRL3	LDY	#119	;two seconds
PRL4	JSR	WAIT	;wait jiffy
	DEY		;dec loop
	BPL	PRL4
	RTS		;leave
PRL5	LDX	#5	;wait 10 sec.
PRL6	JSR	PRL3
	DEX
	BNE	PRL6
	RTS
;
;Show number of men left
;
MENLEFT	LDA	MEN1	;player one
	CLC		;add color
	ADC	#80
	STA	MENL+7	;on scrn
	LDA	MEN2	;same for
	CLC		;player two
	ADC	#80
	STA	MENL+17
	RTS		;done.
;
;Vertical Blank Routine
;
VBLANK1	LDA	#0	;just KILL
	STA	ATRACT	;atract mode.
	JMP	SYSVBV
;
;Audio prompts
;
BEEP	LDA	#25	;high tone
	BNE	BTONE	;play it
;
BOOP	LDA	#100	;low tone
BTONE	STA	AUDF1	;save freq
	LDA	#$AA	;pure sound
	STA	AUDC1
	JSR	BWAIT	;and leave on
;
;Sound Off
;
SNDOFF	LDA	#0	;now zero
	STA	AUDF1	;the sound
	STA	AUDF2	;registers
	STA	AUDC1
	STA	AUDC2
	RTS
;
;Wait 4 jiffies
;
BWAIT	LDY	#3	;wait 4 jiffies
DOW	JSR	WAIT	;pause 1 jiffy
	DEY		;decrease loop
	BPL	DOW	;do again
	RTS		;leave
;
;Turn on screen
;
TURNON	LDX	#0
	STX	COLOR4	;in color
	STX	COLOR2
	LDX	#14
	STX	COLOR1
	LDX	# <GDLI	;point to DLI
	STX	VDSLST
	LDX	# >GDLI
	STX	VDSLST+1
	LDX	#$C0	;turn it on
	STX	NMIEN
	LDX	#62
	STX	SDMCTL
	RTS		;done
;
;Turn off screen
;
TURNOFF	LDX	#0
	STX	SDMCTL	;turn off scrn
	JMP	WAIT
;
;Posit players for board
;
POSPM	LDX	#0	;get zero
	STX	PCOLR2
	STX	PCOLR3
	INX
	STX	GPRIOR	;set priority
	STX	SIZEP0	;double wide
	JSR	CLRPM	;erase P/M
	LDA	#$FC	;gold color
	STA	PCOLR0
	LDA	# >MYPM	;set PMBASE
	STA	PMBASE
	LDA	#3	;set sizes
	STA	SIZEP2
	STA	SIZEP3
	STA	GRACTL	;turn on P/M
	LDA	#$FF	;define plyrs
	LDY	#62	;2 + 3 as the
PDF1	STA	PLR2,Y	;borders
	STA	PLR3,Y
	INY
	CPY	#160
	BNE	PDF1
	LDA	#44	;now position
	STA	HPOSP2	;them on the
	LDA	#180	;screen
	STA	HPOSP3
	RTS		;later.
;
;Switch players
;
SWITCH	LDA	PLAYER	;get player
	EOR	#1	;flip it
	STA	PLAYER	;store
	RTS		;done.
;
;Wait a 1 jiffy
;
WAIT	LDA	#0	;zero the clock
	STA	RTCLOK
W1	LDA	RTCLOK	;get clock
	BEQ	W1	;if same loop
	RTS		;leave
;
;Test player move
;
TESTIT	STA	SAVEA	;save A
	BMI	MVOK	;empty? yes.
	BEQ	MVNK	;bad move
	CMP	#19	;objects?
	BCS	MVNK
	LDA	PLAYER	;get plyr #
	BNE	HAV2	;player 2
	LDA	SAVEA	;char
	CMP	#10	;equal 10?
	BCS	MVOK	;no. good.
	BCC	MVNK	;bad move.
HAV2	LDA	SAVEA	;restore A
	CMP	#10	;> 10?
	BCS	MVNK	;yes. bad one.
MVOK	CLC		;signal good.
	RTS		;leave.
MVNK	SEC		;signal bad.
	RTS		;leave
;
;Move + define cursor
;
DEFINE	LDA	PLRX	;get X pos
	STA	HPOSP0	;in horizontal
	LDY	PLRY	;get Y pos
	LDX	#0	;and erase top
	TXA		;half of the
DEF0	STA	PLR0,Y	;cursor
	DEY
	BNE	DEF0
	LDY	PLRY	;get Y again
DEF1	LDA	DEFPL1,X	;and put in
	STA	PLR0,Y	;the definition
	INY
	INX
	CPX	#20	;20 bytes yet?
	BNE	DEF1	;no.
DEF2	STA	PLR0,Y	;now erase under
	INY		;the cursor.
	BNE	DEF2
	RTS		;done.
;
;Perform a cursor move
;
DOMOVE	LDY	MOVED	;get move
	LDA	MOVTAB,Y	;load and store
	STA	MOVJMP+1	;vector in
	LDA	MOVTAB+1,Y	;the table
	STA	MOVJMP+2
MOVJMP	JMP	$FFFF	;Move it!
;
;Move LEFT
;
LEFT	LDY	TABPOS	;get pos
	LDA	GAMBRD-1,Y	;look left
	BEQ	DN1	;bad move!
	LDY	#7	;okeh move it
LLP	STY	SAVEY	;back 8 pixels
	DEC	PLRX
	JSR	WAIT	;wait a jiffy
	JSR	DEFINE
	LDY	SAVEY
	DEY
	BPL	LLP
	DEC	TABPOS	;new posit
DN1	RTS		;done.
;
;Move RIGHT
;
RIGHT	LDY	TABPOS	;position
	LDA	GAMBRD+1,Y	;look right
	BEQ	DN1	;bad one
	LDY	#7	;move right
RLP	STY	SAVEY	;8 pixels.
	INC	PLRX
	JSR	WAIT
	JSR	DEFINE
	LDY	SAVEY
	DEY
	BPL	RLP
	INC	TABPOS
	RTS
;
;Move UP
;
UP	LDA	TABPOS	;posit
	SEC		;up one line
	SBC	#14
	TAY
	LDA	GAMBRD,Y	;look in board
	BEQ	DN2	;bad move!
	STY	TABPOS	;save posit
	LDY	#15	;move player
ULP	STY	SAVEY	;up 16 pixels
	DEC	PLRY
	JSR	WAIT
	JSR	DEFINE
	LDY	SAVEY
	DEY
	BPL	ULP
	RTS
;
;Move DOWN
;
DOWN	LDA	TABPOS	;posit
	CLC		;add 13 for line
	ADC	#14	;down
	TAY
	LDA	GAMBRD,Y	;get piece
	BEQ	DN2	;bad
	STY	TABPOS	;save posit
	LDY	#15	;move player
DLP	STY	SAVEY	;down 16 pixels
	INC	PLRY
	JSR	WAIT
	JSR	DEFINE
	LDY	SAVEY
	DEY
	BPL	DLP
DN2	RTS		;all done
;
;Read Stick + button
;
;MOVED = 0 for left
;      = 2 for right
;      = 4 for up
;      = 6 for down
;
STICK	LDX	PLAYER	;get player
	LDA	#15	;and reset
	STA	STICK0,X	;stick values
	LDA	#1
	STA	STRIG0,X
	LDA	MOVED	;put last move
	STA	OMOVE	;in hold area
STCK	LDA	#$FF
	STA	MOVED	;no move made
CSTK	LDA	STICK0,X	;read stick
	CMP	#15	;no move
	BEQ	TRYTRG	;try trigger
	CMP	#11	;left?
	BNE	ST0	;no.
	LDA	#0	;move is 0
	BEQ	STDN
ST0	CMP	#7	;right?
	BNE	ST1	;no.
	LDA	#2	;table offset
	BNE	STDN	;=2
ST1	CMP	#14	;up?
	BNE	ST2	;no.
	LDA	#4	;offset = 4
	BNE	STDN
ST2	CMP	#13	;down?
	BNE	CSTK	;no. read again
	LDA	#6	;make a 6
STDN	STA	MOVED	;save move
	SEC		;signal move
	RTS
TRYTRG	LDA	STRIG0,X	;trigger
	BNE	CSTK	;read stick
	CLC		;signal fire
	RTS
;
;Add border to game board
;
ADDBORD	LDX	#11	;12 lines
	LDA	#0	;make the
	STA	COLOR2	;screen black
	STA	COLOR4
	LDA	# <[MYSCRN+7]
	STA	SCR
	LDA	# >[MYSCRN+7]
	STA	SCR+1
BOR0	LDY	#25	;26 chars
	LDA	#84	;red space
BOR1	STA	(SCR),Y	;on screen
	DEY		;down loop
	BPL	BOR1	;and run again
	LDA	SCR	;now add 40
	CLC		;to screen
	ADC	#40	;pointer to
	STA	SCR	;get to next
	LDA	SCR+1	;screen line
	ADC	#0
	STA	SCR+1
	DEX		;dec outer loop
	BPL	BOR0	;do again
	RTS		;all done
;
;Randomize terrain features
;
TERRAIN	LDY	#20	;21 features
TERR1	LDA	RANDOM	;number
	CMP	#15
	BCC	TERR1
	CMP	#81
	BCS	TERR1
	TAX
TERR2	LDA	RANDOM	;next number
	CMP	#1	;check if piece
	BCC	TERR2
	CMP	#4
	BCS	TERR2
	STA	SAVEA	;save it
	LDA	GAMBRD,X	;get piece
	BPL	TERR1	;<128 no good
	LDA	SAVEA	;get feature
	CLC		;and add 18
	ADC	#18
	STA	GAMBRD,X	;put in
	DEY		;board
	BPL	TERR1	;do again
;
;Now assure a path through
;
DOPATH	LDA	RANDOM
	AND	#3	;only 0-3
	CMP	#3	;=3?
	BEQ	DOPATH	;yes do again
	ASL	A	;times 8
	ASL	A
	ASL	A
	TAY
	LDX	#7	;do 8 spaces
PATH2	LDA	PATHS,Y	;get posit
	STY	SAVEY	;save Y
	TAY
	LDA	#$80	;get blank
	STA	GAMBRD,Y	;put in
	LDY	SAVEY	;board. get Y
	INY		;up posit
	DEX		;dec loop
	BPL	PATH2	;and loop again
	RTS		;all done
;
;Fill play field
;
SETSCR	LDY	#0
	LDA	# <DLIST1	;install my
	STA	SDLSTL	;display list
	LDA	# >DLIST1
	STA	SDLSTL+1
SE1	LDA	GAMBRD+14,Y	;get a piece
	BEQ	SNXT	;leave alone
	BPL	SE2	;have character
	LDA	#0	;get empty
SE2	ASL	A	;* 2
	ASL	A	;* 4
	STY	SAVEY	;save y
	TAX		;char index
	TYA		;screen posit
	ASL	A	;* 2
	TAY
	LDA	SCRTAB,Y	;look up addr
	STA	INDR	;and save it
	LDA	SCRTAB+1,Y
	STA	INDR+1
	LDY	#0
SE3	LDA	CHARS,X	;get char
	STA	(INDR),Y	;on screen
	INX		;up count
	INY
	CPY	#2	;2 yet?
	BNE	SE3	;no.
	LDY	#0
	LDA	INDR	;add 40 to scrn
	CLC		;position
	ADC	#40
	STA	INDR
	LDA	INDR+1
	ADC	#0
	STA	INDR+1
SE4	LDA	CHARS,X	;next half of
	STA	(INDR),Y	;character
	INX		;goes on screen
	INY
	CPY	#2
	BNE	SE4
	LDY	SAVEY	;restore Y
SNXT	INY		;up it.
	CPY	#70	;70 yet?
	BNE	SE1	;no.
	RTS		;done.
;
;Copy game board
;
BEGIN	CLD		;no decimal
	LDA	#1	;fix boot status
	STA	BOOT?
	LDA	# <BEGIN	;make program
	STA	DOSINI	;reset proof
	LDA	# >BEGIN
	STA	DOSINI+1
	LDA	#3	;init sound
	STA	SKCTL	;stuff
	LDA	#0	;kill cold start
	STA	COLDST
	STA	AUDCTL
	LDX	#$80	;erase bottom
ERZPG	STA	ZPAGE,X	;half of
	INX		;page zero
	BNE	ERZPG
	TAY
ZGB	STA	GAMBRD,Y	;erase GAMBRD
	INY
	BNE	ZGB
	LDA	#9	;set # of men
	STA	MEN1
	STA	MEN2
	LDY	#69	;now copy in
BEG1	LDA	BRDSET,Y	;the new
	STA	GAMBRD+14,Y	;board
	DEY
	BPL	BEG1
	LDY	#17	;copy in the
HTB	LDA	HITTAB,Y	;hit point
	STA	HTAB,Y	;table
	DEY
	BPL	HTB
	LDA	# <SCRTAB	;now we make
	STA	INDR	;up the screen
	LDA	# >SCRTAB	;definition
	STA	INDR+1	;table.
	LDX	#0
	LDA	# <[MYSCRN+44]	;start
	STA	IND2	;screen posit
	LDA	# >[MYSCRN+44]
	STA	IND2+1
SC1	LDY	#0
SC2	LDA	IND2	;get scrn
	CLC		;and add 2
	ADC	#2
	STA	IND2
	STA	(INDR),Y	;save in table
	LDA	IND2+1
	ADC	#0	;now do hi byte
	INY
	STA	(INDR),Y	;in table
	STA	IND2+1
	INY
	CPY	#28	;28 yet?
	BNE	SC2	;no.
	LDA	INDR	;now add offset
	CLC		;to table
	ADC	#28	;position
	STA	INDR	;and store it.
	LDA	INDR+1
	ADC	#0
	STA	INDR+1
	LDA	IND2	;now update
	CLC		;screen pointer
	ADC	#52	;52 chars later
	STA	IND2
	LDA	IND2+1
	ADC	#0
	STA	IND2+1
	INX		;up line count
	CPX	#5	;5 yet?
	BNE	SC1	;no.
	JSR	INTRO	;display intro
	JSR	TERRAIN
;
;Start of game
;
CHESS	JSR	TURNOFF
	LDY	# <VBLANK1	;set Vblank
	LDX	# >VBLANK1	;vector
	LDA	#6	;Immediate mode
	JSR	SETVBV	;set it!
	JSR	CLRSCR	;erase screen
	JSR	ADDBORD	;add border
	JSR	SETSCR	;set board up
	JSR	POSPM	;add P/M
	JSR	TURNON	;turn it on
;
LOOP0	LDA	#78	;position player
	STA	PLRX
	LDA	#70
	STA	PLRY
	LDA	#15	;set tabpos.
	STA	TABPOS
	LDA	#0	;make player 1
	STA	PLAER+14
	LDA	PLAYER	;get player
	BEQ	SCRON
	LDA	#166	;player 2
	STA	PLRX	;reset cursor
	LDA	#26	;and tabpos
	STA	TABPOS	;pntrs.
	LDA	#105	;player II
	STA	PLAER+14
;
SCRON	JSR	MENLEFT	;# men left
	JSR	SETSCR	;update scrn
LOOP	JSR	DEFINE	;put on cursor
	LDX	PLAYER	;player num
	JSR	STCK	;read stick
	BCC	FIRED	;pressed fire
	JSR	DOMOVE	;move cursor
	JMP	LOOP	;and loop....
FIRED	LDY	#3	;zero out move
	LDA	#$FF	;table
FR1	STA	MOVES,Y
	DEY
	BPL	FR1
	LDY	TABPOS	;get table pos
	STY	OLDPOS	;and save it
	LDA	GAMBRD,Y	;get piece
	STA	OLDPCE	;save it.
	BMI	LOOP	;blank. loop.
	CMP	#19	;trying to move
	BCS	LOOP	;on terrain?
	LDX	PLAYER	;get player
	BNE	PL2	;have player 2
	CMP	#10	;trying to move
	BCC	CHOK	;on yourself?
	BCS	LOOP	;yes!
PL2	CMP	#10	;same thing.
	BCC	LOOP
;
;Now we see if the piece
;selection was a good one
;
CHOK	LDY	#3	;check 4
MCK0	LDA	GTABH,Y	;inset table
	STA	MCHECK+2	;position
	LDA	GTABL,Y	;in program
	STA	MCHECK+1
	STY	SAVEY	;save Y
	LDY	TABPOS	;get pos.
MCHECK	LDA	$FFFF,Y	;and piece
	JSR	TESTIT	;test players
	BCS	UPLP	;bad one
	LDY	SAVEY	;restore Y
	TYA		;possible move
	ASL	A	;* 2 and
	STA	MOVES,Y	;save move
UPLP	LDY	SAVEY	;get Y again
	DEY		;and loop again
	BPL	MCK0
;
;Now see if any move is
;possible this time.
;
	LDY	#3
SMV	LDA	MOVES,Y
	BPL	HAVMOV	;got one!
	DEY
	BPL	SMV
	LDA	# <ALAS	;print can't
	LDY	# >ALAS	;move.
	JSR	EPRINT
	JSR	ERMYLN	;erase line
	JMP	LOOP	;loop again.
HAVMOV	JSR	BEEP	;beep!
TRYMOV	JSR	STICK	;read stick
	LDA	MOVED
	BMI	TRYMOV	;mask out button
	LDY	#3	;test against
CMV	CMP	MOVES,Y	;possible moves
	BEQ	GMOVE	;good move!
	DEY
	BPL	CMV
	JSR	BOOP	;Error!
	JMP	TRYMOV	;try again
GMOVE	JSR	DOMOVE
	JSR	STICK
	BCC	BEP
	LDX	PLAYER	;player #
	LDY	#29	;wait 1/2 second
GVM	LDA	#0	;and check for
	STA	RTCLOK	;press of fire
GVM1	LDA	STRIG0,X	;button
	BEQ	BEP
	LDA	RTCLOK	;get clock
	BEQ	GVM1	;=0? yes.
GVM2	DEY		;loop again
	BPL	GVM
	LDY	OMOVE	;now we move
	LDA	NEGTAB,Y	;the cursor
	STA	UNJSR+1	;back to its
	LDA	NEGTAB+1,Y	;original
	STA	UNJSR+2	;position.
UNJSR	JSR	$FFFF
	JMP	TRYMOV	;go again
BEP	JSR	BEEP	;signal move
	LDY	TABPOS	;get posit
	LDA	GAMBRD,Y	;and piece
	BPL	DOBATTLE	;do a combat!
	LDA	OLDPCE	;just move old
	STA	GAMBRD,Y	;piece on the
	LDY	OLDPOS	;board
	LDA	#$80	;remove previous
	STA	GAMBRD,Y	;character
	JSR	SWITCH	;flip player
	JMP	LOOP0	;and loop
;
DOBATTLE	TAY
	CMP	#10	;player >10?
	BCC	GP1	;no.
	STY	PLRTYPE+1	;player type
	DEY		;decrease index
	LDA	HTAB,Y	;get hit points
	STA	HTS+1	;save em
	BNE	INH0	;player 1 hits
GP1	STY	PLRTYPE	;player 1
	DEY		;down index
	LDA	HTAB,Y	;hit points
	STA	HTS	;save
INH0	LDY	OLDPCE	;old piece
	CPY	#10	;>10?
	BCC	GP11	;no.
	STY	PLRTYPE+1	;move player 1
	DEY		;hits out of
	LDA	HTAB,Y	;table
	STA	HTS+1
	BNE	INH1	;play game
GP11	STY	PLRTYPE	;player #1
	DEY		;and get out
	LDA	HTAB,Y	;their hits
	STA	HTS
INH1	JSR	TURNOFF	;screen off
;
	LDA	#$40
	STA	NMIEN	;kill DLI's
	JSR	BATTLE	;Do battle!
	LDX	#1	;do 2 players
UH0	LDY	PLRTYPE,X	;type #
	LDA	HTS,X	;new hit points
	DEY
	STA	HTAB,Y	;save in table
	DEX
	BPL	UH0	;do next
	LDA	PLAYER	;get the player
	TAX		;X holds plr #
	CMP	WINNER	;same as winner?
	BNE	CHANGE	;no. lost.
	EOR	#1
	TAX
	LDA	OLDPCE	;old piece
	LDY	TABPOS	;and move to
	STA	GAMBRD,Y	;the new square
;
CHANGE	LDA	#$80	;erase old guy
	LDY	OLDPOS
	STA	GAMBRD,Y	;save in board.
	JSR	SWITCH	;flip players
	DEC	MEN1,X	;lower men left
	LDA	HTAB+8	;check if kings
	BEQ	DEATH	;are dead yet.
	LDA	HTAB+17
	BEQ	DEATH
	JMP	CHESS	;and play chess
;
;Handle Death of a team
;
DEATH	TXA		;get player
	EOR	#1	;flip it
	CLC		;make scr mem
	ADC	#17
	STA	TROPHY+7	;save in string
	JSR	CLRSCR
	JSR	MENLEFT	;show # left
	JSR	ADDBORD	;add border
	JSR	SETSCR
	JSR	POSPM	;put on P/M
	JSR	TURNON
	LDA	# <TROPHY	;print trophy
	LDY	# >TROPHY	;message.
	JSR	EPRINT
	JSR	PRL5	;wait 10 sec
	JSR	CLRPM	;remove P/M
	LDA	#$40
	STA	NMIEN
	JSR	TURNOFF
	JMP	BEGIN	;start over.
;
;Introduction Screen
;
INTRO	LDA	#0	;screen off
	STA	SDMCTL
	LDA	# <IDLST	;install disp.
	STA	SDLSTL	;list.
	LDA	# >IDLST
	STA	SDLSTL+1
	LDA	RANDOM	;random #
	AND	#$F0	;hit nybble
	STA	INTC	;save in color
	LDA	#$20	;and add charac.
	STA	CHBAS	;set.
	JSR	CLRPM	;remove players
	JSR	CLRSCR
	LDA	# <DLI1	;install DLI
	STA	VDSLST	;address in
	LDA	# >DLI1	;vector.
	STA	VDSLST+1
	LDA	#$C0	;fire DLI!
	STA	NMIEN
	LDY	#4	;copy 4 nums.
IC	LDA	ICLR,Y	;get number
	STA	COLOR0,Y	;save in color
	DEY		;dec loop
	BPL	IC	;do again
;
;Now add text to intro
;
	LDA	# <[SLN1+256]	;start adr
	STA	SCR	;of where text
	LDA	# >[SLN1+256]	;goes in
	STA	SCR+1	;memory.
	LDX	#0	;zero X
PTIL	LDA	STXT,X	;get a position
	BEQ	LINFD	;if 0 line feed
	TAY		;in Y reg
PTIL2	INX		;up X
	LDA	STXT,X	;next char
	CMP	#$FF	;if $FF lin feed
	BEQ	LINFD
	CMP	#$FE	;if $FE then end
	BEQ	STITL
	STA	(SCR),Y	;in memory
	INY		;up Y
	BNE	PTIL2	;and do again
LINFD	LDA	SCR	;now add a 32
	CLC		;to memory
	ADC	#$20	;pointer
	STA	SCR	;save it.
	LDA	SCR+1	;get hi byte
	ADC	#0	;and add carry
	STA	SCR+1	;save it.
	INX		;up X
	JMP	PTIL	;do again.
;
;Scroll Title Screen
;
STITL	LDA	#61	;turn on narrow
	STA	SDMCTL	;screen.
	LDA	# >SLN1	;set LMS to my
	STA	DVC+2	;memory.
	LDA	#0
	STA	DVC+1
	STA	ATRACT	;kill atract
	STA	LINES	;lines = 0
DOLN	LDA	#0	;scroll counter
	STA	SCROLC	;is zero.
LNL	JSR	WAIT	;wait 1 jiffy
	INC	SCROLC	;inc scrol count
	LDA	SCROLC	;get it.
	CMP	#8	;done 8 yet?
	BEQ	LNDN	;yes. line done
	STA	VSCROL	;in VSCROL
	LDA	CONSOL	;check START key
	CMP	#6
	BEQ	STARTUP	;if pressed go!
	BNE	LNL	;loop again.
LNDN	LDY	#0	;zero Y
	STY	SCROLC	;counter nil
	STY	VSCROL	;same for VSCROL
	LDA	DVC+1	;now add 32 to
	CLC		;the LMS
	ADC	#$20	;instruction
	STA	DVC+1
	LDA	DVC+2	;and take care
	ADC	#0	;of hi byte.
	STA	DVC+2
	INC	LINES	;inc lines done
	LDA	LINES	;get it.
	CMP	#37	;37 lines yet?
	BEQ	STITL	;yes. start over
	LDY	#2	;check if this
CLN	CMP	PLINS,Y	;line is one
	BEQ	WSEC	;we pause on.
	DEY		;not this one
	BPL	CLN	;try next.
	BMI	DOLN	;do next line.
WSEC	LDA	#0	;zero clock
	STA	RTCLOK
WSC1	LDA	RTCLOK	;get it and
	CMP	#120	;wait 2 seconds
	BEQ	DOLN
	LDA	CONSOL	;check CONSOL
	CMP	#6	;START?
	BNE	WSC1	;no. loop.
STARTUP	LDA	#$40	;kill DLI
	STA	NMIEN
	JMP	TURNOFF	;and play game.
;
;DLI for intro colors
;
DLI1	PHA		;save A
	STX	DLIX	;and X regis.
DLL0	LDA	INTC	;color
	STA	DCLOR	;save it
	LDX	#7	;loop 8 times
DLL1	LDA	DCLOR	;get color
	STA	WSYNC	;wait sync
	STA	COLPF3	;store it
	CLC		;add for next
	ADC	#2	;luminance
	STA	DCLOR	;and save it.
	DEX		;dec loop count
	BPL	DLL1	;and do again
;
	LDX	#7	;loop 8 more
DLL2	LDA	DCLOR	;get color
	SEC		;and subtract 2
	SBC	#2	;from luminance
	STA	WSYNC	;wait for sync
	STA	COLPF3	;store it
	STA	DCLOR	;save color
	DEX		;dec loop
	BPL	DLL2	;and do again
	PLA		;restore A
	LDX	DLIX	;and X regs.
	RTI		;done.
;
;Game board DLI1
;
GDLI	PHA
	LDA	#2
	STA	WSYNC
	STA	COLPF2
	LDA	# <GDLI2
	STA	VDSLST
	LDA	# >GDLI2
	STA	VDSLST+1
	PLA
	RTI
;
;Game board DLI2
;
GDLI2	PHA
	LDA	#0
	STA	WSYNC
	STA	COLPF2
	LDA	# <GDLI
	STA	VDSLST
	LDA	# >GDLI
	STA	VDSLST+1
	PLA
	RTI
;
;Battle portion of
;CLASH OF KINGS
;
;Written by: Barry Kolbe
;
MAKSCR	LDY	#19	;set up screen
	LDA	#BORD	;do top border
SQ1	STA	SCMEM,Y
	STA	SCMEM+180,Y
	DEY
	BPL	SQ1
	LDA	# <SCMEM	;now do
	STA	PMTO	;sides
	LDA	# >SCMEM
	STA	PMTO+1
	LDX	#8
SQ2	JSR	ADD20	;add 20
	LDA	#BORD	;do edge
	LDY	#0
	STA	(PMTO),Y
	LDY	#19
	STA	(PMTO),Y
	DEX
	BPL	SQ2
	RTS		;border done
;
ADD20	LDA	PMTO	;add 20 to scr
	CLC		;memory ptr.
	ADC	#20
	STA	PMTO
	LDA	PMTO+1
	ADC	#0
	STA	PMTO+1
	RTS
;
BATTLE	LDA	STRIG0	;wait until
	BEQ	BATTLE	;players release
	LDA	STRIG0+1	;buttons
	BEQ	BATTLE
	LDX	# >VBLAN	;set up
	LDY	# <VBLAN	;vblank
	LDA	#7
	JSR	SETVBV
	LDA	#1	;turn off vblank
	STA	EXEC
START2	JSR	CLRSCR	;start here
	LDA	#0	;turn all
	STA	COLOR0	;colors black
	STA	COLOR1	;at first
	STA	COLOR2
	STA	COLOR3
	LDA	# <DLIST	;install
	STA	560	;gr.2 display
	LDA	# >DLIST	;list
	STA	561
;
	JSR	PUTMAZE	;put maze scrn
	JSR	MAKSCR	;do border
	JSR	SHOWSC	;show hits
	JSR	SETCL	;fade colors
	JSR	PMINIT	;init. pm
	JSR	CLRPM	;clear pm
	JSR	DEFPLR	;define plyrs
	JSR	INITGM	;intial game
	STA	HITCLR	;clear collision
MAIN	JSR	CHKHIT	;chk hits
	JSR	CHKZAP	;check if hit
	LDA	RFLG	;restart flg
	BEQ	MAIN	;no hit
	JSR	REMMIS	;rem miss
	DEC	RFLG	;get plyr #
	LDX	RFLG	;0 or 1
	JSR	EXPLOD	;do explosion
	LDX	RFLG	;get x back
	DEC	HTS,X	;1 less hit
	LDA	HTS,X	;done yet?
	BEQ	QUIT	;yes
	JSR	REMPLR	;plyrs off
	JMP	START2	;set up again
QUIT	TXA
	EOR	#1	;flip loser to
	STA	WINNER	;winner
	JSR	REMMIS	;all done
	JSR	REMPLR	;no miss/plrys
	LDA	#7
	LDX	# >XITVBV	;get rid
	LDY	# <XITVBV	;of vblan
	JSR	SETVBV
	JMP	TURNOFF
;
;turn colors on
;
SETCL	LDY	#4
QS1	LDA	BFCLR,Y
	STA	COLOR0,Y
	DEY
	BPL	QS1
	RTS
;
;initialize plyrs
;
PMINIT	LDA	#62	;single line
	STA	SDMCTL	;res.
	LDA	#1
	STA	GPRIOR
	LDA	#58	;drk orange
	STA	PCOLR0
	STA	PCOLR2
	LDA	#170	;blue gray
	STA	PCOLR1
	STA	PCOLR3
	LDA	# >PMB	;pmbase
	STA	PMBASE
	LDA	#3
	STA	GRACTL	;turn on pm
	LDA	#0
	LDX	#3	;put plyrs off
PM1	STA	HPOSP0,X	;screen
	STA	SIZEP0,X	;normal size
	DEX
	BPL	PM1
	LDA	#0	;clear zap
	STA	ZAP	;registers
	STA	ZAP+1
	RTS
;
CLRM0	LDA	#0	;clear miss 0
	LDY	#$FF	;i.e. plyr 2
MC1	STA	PLR2,Y
	DEY
	BNE	MC1
	RTS
;
CLRM1	LDA	#0	;clear miss 1
	LDY	#$FF	;i.e. plyr 3
MC2	STA	PLR3,Y
	DEY
	BNE	MC2
	RTS
;
;define players
;
DEFPLR	LDY	#111
	LDX	#15
DF	LDA	PLY1,X
	STA	PLR0,Y
	LDA	PLY2,X
	STA	PLR0+272,Y
	DEY
	DEX
	BPL	DF
	LDA	#56	;init x pos
	STA	HPOSP0	;plyr 0
	STA	XPOS0
	LDA	#192	;ditto plyr 1
	STA	HPOSP1
	STA	XPOS1
	LDA	#96	;init y pos.
	STA	YPOS0
	LDA	#112
	STA	YPOS1
	RTS
;
; move playrs
;
MOVEP	LDA	#0	;clear collisions
	STA	HITCLR
	LDA	HSCL,X	;moving lft or rt?
	BEQ	TRYUD	;no try up-dn
	LDA	SAVST,X	;which direction
	CMP	#7	;rt?
	BNE	LFM	;no
	LDA	HSCL,X	;first time to
	CMP	#8	;scroll?
	BNE	RTOK	;no
	JSR	WALLCK	;check if wall
	LDA	WC,X	;or star
	BEQ	NOHS	;no move
	JSR	CHKPLR	;is other plyr
	LDA	PFLG	;there?
	BNE	RT	;no
NOHS	LDA	#0	;do not scroll
	STA	HSCL,X	;plyr
	RTS
RT	INC	SCX,X	;change screen pos
RTOK	INC	XPOS0,X	;chng horz.pos
	LDA	XPOS0,X
	STA	HPOSP0,X	;do move
	DEC	HSCL,X	;scroll reg.-1
	RTS
LFM	CMP	#11	;try left
	BNE	TRYUD	;nope
	LDA	HSCL,X	;moving?
	CMP	#8	;first time?
	BNE	LFOK	;nope
	JSR	WALLCK	;check wall
	LDA	WC,X	;& star
	BEQ	NOHS	;no move
	JSR	CHKPLR	;plyr in way?
	LDA	PFLG
	BEQ	NOHS	;yup
	DEC	SCX,X	;ok scrn pos -1
LFOK	DEC	XPOS0,X	;do lft move
	LDA	XPOS0,X
	STA	HPOSP0,X
	DEC	HSCL,X	;scroll reg.-1
	RTS
TRYUD	LDA	VSCL,X	;try moving
	BEQ	GETST	;up-dn
	LDA	SAVST,X	;get direct.
	CMP	#14	;up?
	BNE	TRDN	;try dn
	LDA	VSCL,X	;moving yet?
	CMP	#16
	BNE	UPOK	;yup
	JSR	WALLCK	;chk wall & star
	LDA	WC,X
	BEQ	NOVS	;no move
	JSR	CHKPLR	;chk plyr
	LDA	PFLG	;in way
	BNE	UL	;ok
NOVS	LDA	#0	;no move
	STA	VSCL,X
	RTS
UL	LDA	SCX,X	;subt. 20 from
	SEC		;scrn. pos.
	SBC	#20
	STA	SCX,X
UPOK	JSR	UPDOWN	;get pmg page
	DEY		;set up to move
	STY	PMFR
	LDY	#0
UPL	LDA	(PMTO),Y	;move 17 bytes
	STA	(PMFR),Y	;down in memry
	INY
	CPY	#17
	BNE	UPL
	DEC	YPOS0,X	;chng y pos ptr
	DEC	VSCL,X	;scrll -1
	RTS
TRDN	CMP	#13	;down?
	BNE	GETST	;no get stick
	LDA	VSCL,X	;moving?
	CMP	#16
	BNE	DNOK
	JSR	WALLCK	;chk wall & star
	LDA	WC,X
	BEQ	NOVS
	JSR	CHKPLR	;chk other guy
	LDA	PFLG	;he there?
	BEQ	NOVS	;yup
	LDA	SCX,X	;add 20 to scrn
	CLC		;memry location
	ADC	#20
	STA	SCX,X
DNOK	JSR	UPDOWN	;set up pages
	INY		;to move
	STY	PMFR	;player up in
	LDY	#17	;memry
DNL	LDA	(PMTO),Y
	STA	(PMFR),Y
	DEY
	BPL	DNL
	INY
	LDA	#0	;knock out the
	STA	(PMTO),Y	;last byte
	INC	YPOS0,X	;new y pos.
	DEC	VSCL,X	;scroll-1
	RTS		;all done moving
GETST	LDA	STICK0,X
	STA	SAVST,X
	CMP	#7
	BNE	T11
T7	LDA	#8
	STA	HSCL,X
	RTS
T11	CMP	#11
	BNE	T14
	BEQ	T7
T14	CMP	#14
	BNE	T13
T15	LDA	#16
	STA	VSCL,X
	RTS
T13	CMP	#13
	BEQ	T15
	RTS
;
;
UPDOWN	LDA	UDTAB,X	;set up pages
	STA	PMTO+1	;for plyr moves
	STA	PMFR+1
	LDA	YPOS0,X
	TAY
	STY	PMTO
	RTS
;
;Initialize variables
;
INITGM	LDA	#81
	STA	SCX
	LDA	#118
	STA	SCX+1
	LDA	#3
	STA	WSR
	STA	STIME
	LDA	#30
	STA	ZTIME
	LDA	#15
	STA	MZR
	LDA	#0
	STA	MISM
	STA	MISM+1
	STA	HSCL
	STA	HSCL+1
	STA	VSCL
	STA	VSCL+1
	STA	RFLG
	STA	BSR	;no blowup
	STA	MSR	;no missile snd
	STA	EXEC
	RTS
;
;do the maze
;
MAZE	LDY	#15
PCK1	JSR	RND
	STA	MZTAB,Y
	DEY
	BNE	PCK1
	RTS
;
;
RND	LDA	RANDOM
	CMP	#22
	BCC	RND
	CMP	#178
	BCS	RND
	LDX	#15
CRN	CMP	MZCK,X
	BEQ	RND
	DEX
	BPL	CRN
	RTS
;
;
;put maze on screen
;
PUTMAZE	JSR	MAZE
	LDX	#15
MZ1	LDA	MZTAB,X
	TAY
	STX	X1
	LDA	RANDOM
	AND	#3
	TAX
	LDA	MZCOL,X
	LDX	X1
	STA	SCMEM,Y
	DEX
	BNE	MZ1
	RTS
;
;
;
;check if wall
;
WALLCK	STX	XTEM
	LDA	#0	;0=no move
	STA	WC,X
	LDA	SCX,X	;pos. in sc.mem
	STA	TEMP	;0-239
	LDA	SAVST,X
	LDX	#3	;get dir
WCK	CMP	WALLTAB,X
	BEQ	WCK1
	DEX
	BPL	WCK
WCK1	LDA	ADDER,X
	CLC
	ADC	TEMP
	TAY
	STY	TEMP	;hang on to loc
	LDX	XTEM
	LDA	SCMEM,Y	;get byte
	BNE	RT1	;not 0 >no move
	LDA	#1	;ok to move
	STA	WC,X	;move flag
RT1	RTS
;
;move missile routine
;
MOVEM	STA	HITCLR
	LDA	MISM,X	;direction or
	BNE	MOK	;0=not moving
	LDA	STRIG0,X
	BEQ	PMIS	;0=pressed
	RTS		;not pressed
PMIS	LDA	SAVST,X	;get direct
	STX	TEMP	;save x
	LDX	#3
CKMD	CMP	WALLTAB,X	;chk direct
	BEQ	PMOK	;ok valid
	DEX
	BPL	CKMD
	LDA	#0	;not valid
	LDX	TEMP	;direct
	STA	MISM,X
	RTS
PMOK	LDX	TEMP
	STA	MISM,X	;save direction
	LDA	#7	;set up missile
	STA	MSR	;snd rout.
	LDA	#9
	STA	MTIME
	JSR	PUTMIS
MOK	STX	XTEM
	LDA	MISM,X	;get dir
	CMP	#7	;rt?
	BNE	N1
	LDA	XPOS2,X
	CLC
	ADC	#2
	STA	XPOS2,X
	STA	HPOSP2,X
	RTS
N1	CMP	#11
	BNE	N2
	LDA	XPOS2,X
	SEC
	SBC	#2
	STA	XPOS2,X
	STA	HPOSP2,X
	RTS
N2	CMP	#14	;up?
	BNE	N3
	LDA	#2
	STA	UDFL
UPAGN	JSR	MSUPDN
	DEY
	STY	MIST
	LDY	#0
N5	LDA	(MISF),Y
	STA	(MIST),Y
	INY
	CPY	#8
	BNE	N5
	DEC	YPOS2,X
	DEC	UDFL
	LDA	UDFL
	BNE	UPAGN
	RTS
N3	CMP	#13
	BEQ	N7
	RTS
N7	LDA	#2
	STA	UDFL
DNAGN	JSR	MSUPDN
	INY
	STY	MIST
	LDY	#7	;only 8 bytes
N6	LDA	(MISF),Y
	STA	(MIST),Y
	DEY
	BPL	N6
	LDY	#0
	TYA
	STA	(MISF),Y
	INC	YPOS2,X
	DEC	UDFL
	LDA	UDFL
	BNE	DNAGN
	RTS
;
;set page ptrs miss
;
MSUPDN	LDA	MSUP,X
	STA	MISF+1
	STA	MIST+1
	LDY	YPOS2,X
	STY	MISF
	RTS		;rtn with y
;
;
;put missile on scn
;
PUTMIS	LDA	XPOS0,X
	STA	XPOS2,X
	LDA	YPOS0,X
	CLC
	ADC	#4
	STA	YPOS2,X
;
;define missiles
;
	STX	XTEM
	CPX	#0	;miss 0 or 1
	BNE	MM1	;do miss1
	JSR	CLRM0
	LDY	YPOS2,X	;get y pos
	LDX	#0
MM2	LDA	MISS0,X
	STA	PLR2,Y
	INY
	INX
	CPX	#8
	BNE	MM2
	LDX	XTEM
MM4	LDA	XPOS2,X
	STA	HPOSP2,X
	RTS
MM1	JSR	CLRM1
	LDY	YPOS2,X
	LDX	#0
MM3	LDA	MISS1,X
	STA	PLR3,Y
	INY
	INX
	CPX	#8
	BNE	MM3
	LDX	XTEM
	JMP	MM4
	RTS
;
; delays
;
DELAY	LDA	#120
	STA	TIMER+1
DEL2	LDA	#0
	STA	TIMER
DEL3	DEC	TIMER
	LDA	TIMER
	BNE	DEL3
	DEC	TIMER+1
	LDA	TIMER+1
	BNE	DEL2
	RTS
;
;longer delay
;
DELAY1	LDA	#70
	STA	TIMER+1
	BNE	DEL2
;
;vblank routine
;
VBLAN	LDA	BSR
	BEQ	VNS
	JSR	BLOWUP
	JMP	XITVBV
VNS	LDA	EXEC
	BEQ	VOK
	JSR	SNDOFF
	JMP	XITVBV
VOK	INC	VTIME
	LDA	VTIME
	CMP	#9
	BEQ	VB1
	JMP	TRYMIS	;done
VB1	LDA	#0
	STA	VTIME
	INC	PTYPE	;next def
	LDA	PTYPE
	CMP	#3
	BCC	PT
	LDA	#0
PT	STA	PTYPE
	LDA	PTYPE	;plyr type 0/1
	BNE	VB3
	LDA	# <PLY1
	STA	VB2+1
	LDA	# >PLY1
	STA	VB2+2
	LDA	# <PLY2
	STA	VB4+1
	LDA	# >PLY2
	STA	VB4+2
	JMP	VB5
VB3	CMP	#1
	BNE	VB6
	LDA	# <PLY3
	STA	VB2+1
	LDA	# >PLY3
	STA	VB2+2
	LDA	# <PLY4
	STA	VB4+1
	LDA	# >PLY4
	STA	VB4+2
	JMP	VB5
VB6	LDA	# <PLY5
	STA	VB2+1
	LDA	# >PLY5
	STA	VB2+2
	LDA	# <PLY6
	STA	VB4+1
	LDA	# >PLY6
	STA	VB4+2
VB5	LDY	YPOS0	;plyr 0
	LDX	#0	; 16 bytes
VB2	LDA	PLY3,X
	STA	PLR0,Y
	INY
	INX
	CPX	#16
	BNE	VB2
	LDY	YPOS1	;plyr 1
	LDX	#0	;16
VB4	LDA	PLY4,X
	STA	PLR1,Y
	INY
	INX
	CPX	#16
	BNE	VB4
	LDA	#0
	STA	77	;kill attract
TRYMIS	STA	HITCLR
VB7	LDX	#0
	JSR	MOVEM
	INX
	JSR	MOVEM
	LDX	#0
	JSR	MOVEP
	INX
	JSR	MOVEP
	JSR	WHIRLY
	JSR	MISHOT
	JSR	CHMAZE
	JMP	XITVBV
;
;check for hits
;
CHKHIT	LDA	53254	;plyr2=miss0
	BEQ	K1	;no
K3	LDA	#0	;yes
	STA	MISM	;don't move
	STA	HPOSP2	;get off scn
K1	LDA	53255
	BEQ	K2	;no
	LDA	#0
	STA	MISM+1
	STA	HPOSP3
K2	LDA	53262
	AND	#2	;hit plyr1?
	BEQ	K4	;no
	LDA	#1
	STA	ZAP+1
	STA	EXEC	;killvblank
K4	LDA	53263
	AND	#1	;hit plyr0?
	BEQ	K5
	LDA	#1
	STA	ZAP
	STA	EXEC	;kill vblank
K5	STA	HITCLR
	RTS
;
;check zap
;
CHKZAP	LDX	#0
	STX	RFLG	;defalt =0
	LDY	#1
	LDA	ZAP,X
	BEQ	ZP1
ZP2	STY	RFLG
	RTS
ZP1	INX
	INY
	LDA	ZAP,X
	BNE	ZP2
	RTS
;
;show score
;
SHOWSC	LDX	#0
	LDY	HTS,X
	DEY
	LDA	#BAR
SH1	STA	SCMEM+201,Y
	DEY
	BPL	SH1
	INX
	LDY	HTS,X
	DEY
SH2	STA	SCMEM+211,Y
	DEY
	BPL	SH2
	RTS
;
;remove missls
;
REMMIS	LDA	#0
	STA	MISM
	STA	MISM+1
	STA	HPOSP2
	STA	HPOSP3
	RTS
;
;remove plrs
;
REMPLR	LDA	#0
	STA	HPOSP0
	STA	HPOSP1
	RTS
;
;whirlybird snd
;
WHIRLY	DEC	STIME
	LDA	STIME
	BEQ	DOSND
	RTS
DOSND	LDA	#2
	STA	STIME
	LDX	WSR
	BEQ	CHWS
	LDA	#$84
	STA	AUDC1
	LDA	WSN,X
	STA	AUDF1
	DEC	WSR
	RTS
CHWS	LDX	#2
	STX	WSR
	RTS
;
;miss shot
;
MISHOT	LDA	MSR
	BNE	SNOK
	RTS
SNOK	LDX	MSR
	LDA	#$AA
	STA	AUDC2
	LDA	MSN,X
	STA	AUDF2
	DEC	MSR
	RTS
;
;explosion
;
EXPLOD	LDY	YPOS0,X	;get y pos
	LDA	#67
	STA	BSR
	STY	PMFR
	LDA	#5
	STA	TEMP
	LDA	# >EXPLR
	STA	PMTO+1	;hi byte
	LDA	# <EXPLR	;low
	STA	PMTO
	LDA	UDTAB,X
	STA	PMFR+1
EX1	LDY	#0
EX	LDA	(PMTO),Y
	STA	(PMFR),Y
	INY
	CPY	#16
	BNE	EX
	JSR	DELAY
	CLC
	LDA	PMTO
	ADC	#16
	STA	PMTO
	LDA	PMTO+1
	ADC	#0	;add 16
	STA	PMTO+1
	DEC	TEMP	;1 less def.
	LDA	TEMP
	BNE	EX1
	JSR	DELAY
	RTS
;
;explosion snd
;
BLOWUP	LDX	BSR	;blowup snd reg.
	BNE	BOK
	RTS		;no blowup
BOK	LDX	BSR	;blowup snd reg.
	LDA	#$8A
	STA	AUDC2
	LDA	EXF,X	;get freq.
	STA	AUDF2
	DEC	BSR
	RTS
;
;check if run into plyr
;
CHKPLR	STX	PCX	;save x
	LDA	#0
	STA	PFLG	;flag
	CPX	#0	;which plyr?
	BNE	CP2	;1
	INX
	LDA	TEMP	;test pos
	CMP	SCX,X	;= other guy?
	BNE	CKPOK
	BEQ	RT3
CKPOK	INC	PFLG	;now 1
RT3	LDX	PCX
	RTS
CP2	DEX		;now 0
	LDA	TEMP	;other guy
	CMP	SCX,X	;= ?
	BNE	CKPOK
	BEQ	RT3
;
;change maze
;
CHMAZE	DEC	ZTIME	;maze timer
	LDA	ZTIME
	BEQ	MZ4
	RTS		;not yet
MZ4	LDA	#30
	STA	ZTIME	;reset timer
	LDX	MZR
	LDA	MZTAB,X
	TAY
	LDA	#0	;get rid of
	STA	SCMEM,Y	;star
	JSR	RND
	LDX	MZR
	STA	MZTAB,X	;new
	TAY		;position
	LDA	RANDOM
	AND	#3
	TAX
	LDA	MZCOL,X
	STA	SCMEM,Y	;put new *
	DEC	MZR
	LDA	MZR
	BNE	MZ5
	LDA	#15
	STA	MZR
MZ5	RTS

	*=	$02E0
	.WORD	BEGIN
	.END