Source Code
These source-code files are part of a reconstructed copy of Comanche 72/3 (AKA Manche72 revision 3),
the final, flown mission release of the Apollo Guidance Computer (AGC) Command Module (CM) software
for Apollo 13.
The starting point was the source code of Comanche 72 (itself previously reconstructed). Comanche 72 source code was then modified by incorporating changes known from contemporary documentation to have been made between revisions 72 and 72/3. The resulting code assembles to have identical memory-bank checksums as those specified in NASA drawing 2021153G; this gives reasonably high confidence that the changes that have been made are correct. In places where ambiguity exists, this ambiguity is discussed in "## Reconstruction:" comments. Since no contemporary listings of Comanche 72/3 are available as source material, all comments and labels are approximate. They have been taken from other AGC programs where possible, or, in some places, written from scratch to match what we believe would have been in the original listing. |
062860,000002: ## Copyright: Public domain.
062861,000003: ## Filename: RTB_OP_CODES.agc
062862,000004: ## Purpose: A section of Manche72 revision 3.
062863,000005: ## It is part of the reconstructed source code for the final, flown
062864,000006: ## release of the software for the Command Module's (CM) Apollo
062865,000007: ## Guidance Computer (AGC) for Apollo 13. No original listings
062866,000008: ## of this program are available; instead, this file was recreated
062867,000009: ## from a reconstructed copy of Comanche 072. It has been adapted
062868,000010: ## such that the resulting bugger words exactly match those
062869,000011: ## specified for Manche72 revision 3 in NASA drawing 2021153G,
062870,000012: ## which gives relatively high confidence that the reconstruction
062871,000013: ## is correct.
062872,000014: ## Assembler: yaYUL
062873,000015: ## Contact: Ron Burkey <info@sandroid.org>.
062874,000016: ## Website: www.ibiblio.org/apollo/index.html
062875,000017: ## Mod history: 2024-05-19 MAS Created from Comanche 072.
062876,000018: ## 2024-05-21 MAS Added implementation of PCR-984, "Avoid Coarse
062877,000019: ## Align during Saturn".
062878,000020:
062879,000021: 22,3510 BANK 22
062880,000022: 22,2000 SETLOC RTBCODES
062881,000023: 22,2000 BANK
062882,000024:
062883,000025: 22,3510 E5,1713 EBANK= XNB
062884,000026: 22,3510 COUNT* $$/RTB
062885,000027:
062886,000028: # LOAD TIME2, TIME1 INTO MPAC:
062887,000029:
062888,000030: 22,3510 00006 LOADTIME EXTEND
062889,000031: 22,3511 30025 DCA TIME2
062890,000032: 22,3512 16024 TCF SLOAD2
062891,000033:
062892,000034: # CONVERT THE SINGLE PRECISION 2'S COMPLEMENT NUMBER ARRIVING IN MPAC (SCALED IN HALF-REVOLUTIONS) TO A
062893,000035: # DP 1'S COMPLEMENT NUMBER SCALED IN REVOLUTIONS.
062894,000036:
062895,000037: 22,3513 10154 CDULOGIC CCS MPAC
062896,000038: 22,3514 35035 CAF ZERO
062897,000039: 22,3515 13520 TCF +3
062898,000040: 22,3516 13517 NOOP
062899,000041: 22,3517 45016 CS HALF
062900,000042:
062901,000043: 22,3520 54155 TS MPAC +1
062902,000044: 22,3521 35035 CAF ZERO
062903,000045: 22,3522 56154 XCH MPAC
062904,000046: 22,3523 00006 EXTEND
062905,000047: 22,3524 75016 MP HALF
062906,000048: 22,3525 20155 DAS MPAC
062907,000049: 22,3526 16030 TCF DANZIG # MODE IS ALREADY AT DOUBLE-PRECISION
062908,000050:
062909,000051: # READ THE PIPS INTO MPAC WITHOUT CHANGING THEM:
062910,000052:
062911,000053: 22,3527 00004 READPIPS INHINT
062912,000054: 22,3530 30037 CA PIPAX
062913,000055: 22,3531 54154 TS MPAC
062914,000056: 22,3532 30040 CA PIPAY
062915,000057: 22,3533 54157 TS MPAC +3
062916,000058: 22,3534 30041 CA PIPAZ
062917,000059: 22,3535 00003 RELINT
062918,000060: 22,3536 54161 TS MPAC +5
062919,000061:
062920,000062: 22,3537 35035 CAF ZERO
062921,000063: 22,3540 54155 TS MPAC +1
062922,000064: 22,3541 54160 TS MPAC +4
062923,000065: 22,3542 54162 TS MPAC +6
062924,000066: 22,3543 16470 VECMODE TCF VMODE
062925,000067:
062926,000068: # FORCE TP SIGN AGREEMENT IN MPAC:
062927,000069:
062928,000070: 22,3544 07226 SGNAGREE TC TPAGREE
062929,000071:
062930,000072:
062931,000073: 22,3545 16030 TCF DANZIG
062932,000074:
062933,000075: # CONVERT THE DP 1'S COMPLEMENT ANGLE SCALED IN REVOLUTIONS TO A SINGLE PRECISION 2'S COMPLEMENT ANGLE
062934,000076: # SCALED IN HALF-REVOLUTIONS.
062935,000077:
062936,000078: 22,3546 03576 1STO2S TC 1TO2SUB
062937,000079: 22,3547 35035 CAF ZERO
062938,000080: 22,3550 54155 TS MPAC +1
062939,000081: 22,3551 16027 TCF NEWMODE
062940,000082:
062941,000083: # DO 1STO2S ON A VECTOR OF ANGLES:
062942,000084:
062943,000085: 22,3552 03576 V1STO2S TC 1TO2SUB # ANSWER ARRIVES IN A AND MPAC.
062944,000086:
062945,000087: 22,3553 52162 DXCH MPAC +5
062946,000088: 22,3554 52155 DXCH MPAC
062947,000089: 22,3555 03576 TC 1TO2SUB
062948,000090: 22,3556 54156 TS MPAC +2
062949,000091:
062950,000092: 22,3557 52160 DXCH MPAC +3
062951,000093: 22,3560 52155 DXCH MPAC
062952,000094: 22,3561 03576 TC 1TO2SUB
062953,000095: 22,3562 54155 TS MPAC +1
062954,000096:
062955,000097: 22,3563 30161 CA MPAC +5
062956,000098: 22,3564 54154 TS MPAC
062957,000099:
062958,000100: 22,3565 35033 TPMODE CAF ONE # MODE IS TP.
062959,000101: 22,3566 16027 TCF NEWMODE
062960,000102:
062961,000103: # V1STO2S FOR 2 COMPONENT VECTOR. USED BY RR.
062962,000104:
062963,000105: 22,3567 03576 2V1STO2S TC 1TO2SUB
062964,000106: 22,3570 52160 DXCH MPAC +3
062965,000107: 22,3571 52155 DXCH MPAC
062966,000108: 22,3572 03576 TC 1TO2SUB
062967,000109: 22,3573 54001 TS L
062968,000110: 22,3574 30157 CA MPAC +3
062969,000111: 22,3575 16024 TCF SLOAD2
062970,000112:
062971,000113: # SUBROUTINE TO DO DOUBLING AND 1'S TO 2'S CONVERSION:
062972,000114:
062973,000115: 22,3576 52155 1TO2SUB DXCH MPAC # FINAL MPAC +1 UNSPECIFIED.
062974,000116: 22,3577 20001 DDOUBL
062975,000117: 22,3600 10000 CCS A
062976,000118: 22,3601 65033 AD ONE
062977,000119: 22,3602 13604 TCF +2
062978,000120: 22,3603 40000 COM # THIS WAS REVERSE OF MSU.
062979,000121:
062980,000122: 22,3604 54154 TS MPAC # AND SKIP ON OVERFLOW.
062981,000123: 22,3605 00002 TC Q
062982,000124:
062983,000125: 22,3606 50000 INDEX A # OVERFLOW UNCORRECT AND IN MSU.
062984,000126: 22,3607 35014 CAF LIMITS
062985,000127: 22,3610 26154 ADS MPAC
062986,000128: 22,3611 00002 TC Q
062987,000129:
062988,000130: # SUBROUTINE TO INCREMENT CDUS
062989,000131:
062990,000132: 22,3612 33625 INCRCDUS CAF LOCTHETA
062991,000133: 22,3613 54130 TS BUF # PLACE ADRES(THETA) IN BUF.
062992,000134: 22,3614 30154 CAE MPAC # INCREMENT IN 1S COMPL.
062993,000135: 22,3615 03626 TC CDUINC
062994,000136:
062995,000137: 22,3616 24130 INCR BUF
062996,000138: 22,3617 30157 CAE MPAC +3
062997,000139: 22,3620 03626 TC CDUINC
062998,000140:
062999,000141: 22,3621 24130 INCR BUF
063000,000142: 22,3622 30161 CAE MPAC +5
063001,000143: 22,3623 03626 TC CDUINC
063002,000144:
063003,000145: 22,3624 13543 TCF VECMODE
063004,000146:
063005,000147: 22,3625 01155 LOCTHETA ADRES THETAD
063006,000148:
063007,000149: # THE FOLLOWING ROUTINE INCREMENTS IN 2S COMPLEMENT THE REGISTER WHOSE ADDRESS IS IN BUF BY THE 1S COMPL.
063008,000150: # QUANTITY FOUND IN TEM2. THIS MAY BE USED TO INCREMENT DESIRED IMU AND OPTICS CDU ANGLES OR ANY OTHER 2S COMPL.
063009,000151: # (+0 UNEQUAL TO -0) QUANTITY. MAY BE CALLED BY BANKCALL/SWCALL.
063010,000152:
063011,000153: 22,3626 54142 CDUINC TS TEM2 # 1S COMPL. QUANT. ARRIVES IN ACC. STORE IT
063012,000154: 22,3627 50130 INDEX BUF
063013,000155: 22,3630 10000 CCS 0 # CHANGE 2S COMPL. ANGLE (IN BUF) INTO 1S
063014,000156: 22,3631 65033 AD ONE
063015,000157: 22,3632 13636 TCF +4
063016,000158: 22,3633 65033 AD ONE
063017,000159: 22,3634 65033 AD ONE # OVERFLOW HERE IF 2S COMPL. IS 180 DEG.
063018,000160: 22,3635 40000 COM
063019,000161:
063020,000162: 22,3636 60142 AD TEM2 # SULT MOVES FROM 2ND TO 3D QUAD. (OR BACK)
063021,000163: 22,3637 10000 CCS A # BACK TO 2S COMPL.
063022,000164: 22,3640 65033 AD ONE
063023,000165: 22,3641 13643 TCF +2
063024,000166: 22,3642 40000 COM
063025,000167: 22,3643 54142 TS TEM2 # STORE 14BIT QUANTITY WITH PRESENT SIGN
063026,000168: 22,3644 13650 TCF +4
063027,000169: 22,3645 50000 INDEX A # SIGN.
063028,000170: 22,3646 35014 CAF LIMITS # FIX IT, BY ADDING IN 37777 OR 40000
063029,000171: 22,3647 60142 AD TEM2
063030,000172:
063031,000173: 22,3650 50130 INDEX BUF
063032,000174: 22,3651 54000 TS 0 # STORE NEW ANGLE IN 2S COMPLEMENT.
063033,000175: 22,3652 00002 TC Q
063034,000176:
063035,000177: # RTB TO TORQUE GYROS, EXCEPT FOR THE CALL TO IMUSTALL. ECADR OF COMMANDS ARRIVES IN X1.
063036,000178:
063037,000179: 22,3653 50120 PULSEIMU INDEX FIXLOC # ADDRESS OF GYRO COMMANDS SHOULD BE IN X1
063038,000180: 22,3654 30046 CA X1
063039,000181: 22,3655 04676 TC BANKCALL
063040,000182: 22,3656 17206 CADR IMUPULSE
063041,000183: 22,3657 16030 TCF DANZIG
063042,000184:
063043,000185: # EACH ROUTINE TAKES A 3X3 MATRIX STORED IN DOUBLE PRECISION IN A FIXED AREA OF ERASABLE MEMORY AND REPLACES IT
063044,000186: # WITH THE TRANSPOSE MATRIX. TRANSP1 USES LOCATIONS XNB+0,+1 THROUGH XNB+16D, 17D AND TRANSP2 USES LOCATIONS
063045,000187: # XNB1+0,+1 THROUGH XNB1+16D, 17D. EACH MATRIX IS STORED BY ROWS.
063046,000188:
063047,000189: 22,3660 02713 XNBEB ECADR XNB
063048,000190: 22,3661 02554 XNB1EB ECADR XNB1
063049,000191:
063050,000192: 22,3662 E5,1713 EBANK= XNB
063051,000193:
063052,000194: 22,3662 33660 TRANSP1 CAF XNBEB
063053,000195: 22,3663 54003 TS EBANK
063054,000196: 22,3664 53716 DXCH XNB +2
063055,000197: 22,3665 53722 DXCH XNB +6
063056,000198: 22,3666 53716 DXCH XNB +2
063057,000199:
063058,000200: 22,3667 53720 DXCH XNB +4
063059,000201: 22,3670 53730 DXCH XNB +12D
063060,000202: 22,3671 53720 DXCH XNB +4
063061,000203:
063062,000204: 22,3672 53726 DXCH XNB +10D
063063,000205: 22,3673 53732 DXCH XNB +14D
063064,000206: 22,3674 53726 DXCH XNB +10D
063065,000207: 22,3675 16030 TCF DANZIG
063066,000208: 22,3676 E5,1554 EBANK= XNB1
063067,000209:
063068,000210: 22,3676 33661 TRANSP2 CAF XNB1EB
063069,000211: 22,3677 54003 TS EBANK
063070,000212: 22,3700 53557 DXCH XNB1 +2
063071,000213: 22,3701 53563 DXCH XNB1 +6
063072,000214: 22,3702 53557 DXCH XNB1 +2
063073,000215:
063074,000216: 22,3703 53561 DXCH XNB1 +4
063075,000217: 22,3704 53571 DXCH XNB1 +12D
063076,000218: 22,3705 53561 DXCH XNB1 +4
063077,000219:
063078,000220: 22,3706 53567 DXCH XNB1 +10D
063079,000221: 22,3707 53573 DXCH XNB1 +14D
063080,000222: 22,3710 53567 DXCH XNB1 +10D
063081,000223: 22,3711 16030 TCF DANZIG
063082,000224:
063083,000225: # THE SUBROUTINE SIGNMPAC SETS C(MPAC, MPAC +1) TO SIGN(MPAC).
063084,000226: # FOR THIS, ONLY THE CONTENTS OF MPAC ARE EXAMINED. ALSO +0 YIELDS POSMAX AND -0 YIELDS NEGMAX.
063085,000227:
063086,000228: # ENTRY MAY BE BY EITHER OF THE FOLLOWING:
063087,000229: # 1. LIMIT THE SIZE OF MPAC ON INTERPRETIVE OVERFLOW:
063088,000230: # ENTRY: BOVB
063089,000231: # SIGNMPAC
063090,000232: # 2. GENERATE IN MPAC THE SIGNUM FUNCTION OF MPAC:
063091,000233: # ENTRY: RTB
063092,000234: # SIGNMPAC
063093,000235: # IN EITHER CASE, RETURN IS TO THE NEXT INTERPRETIVE INSTRUCTION IN THE CALLING SEQUENCE.
063094,000236:
063095,000237: 22,3712 00006 SIGNMPAC EXTEND
063096,000238: 22,3713 35013 DCA DPOSMAX
063097,000239: 22,3714 52155 DXCH MPAC
063098,000240: 22,3715 10000 CCS A
063099,000241: 22,3716 35035 DPMODE CAF ZERO # SETS MPAC +2 TO ZERO IN THE PROCESS
063100,000242: 22,3717 16026 TCF SLOAD2 +2
063101,000243: 22,3720 13721 TCF +1
063102,000244: 22,3721 00006 EXTEND
063103,000245: 22,3722 45013 DCS DPOSMAX
063104,000246: 22,3723 16024 TCF SLOAD2
063105,000247:
063106,000248: # RTB OP CODE NORMUNIT IS LIKE INTERPRETIVE INSTRUCTION UNIT, EXCEPT THAT IT CAN BE DEPENDED ON NOT TO BLOW
063107,000249: # UP WHEN THE VECTOR BEING UNITIZED IS VERY SMALL -- IT WILL BLOW UP WHEN ALL COMPONENTS ARE ZERO. IF NORMUNIT
063108,000250: # IS USED AND THE UPPER ORDER HALVES OF ALL COMPONENTS ARE ZERO, THE MAGNITUDE RETURNED IN 36D WILL BE TOO LARGE
063109,000251: # BY A FACTOR OF 2(13) AND THE SQUARED MAGNITUDE RETURNED AT 34D WILL BE TOO BIG BY A FACTOR OF 2(26).
063110,000252:
063111,000253: 22,3724 35033 NORMUNX1 CAF ONE
063112,000254: 22,3725 13727 TCF NORMUNIT +1
063113,000255: 22,3726 35035 NORMUNIT CAF ZERO
063114,000256: 22,3727 60120 AD FIXLOC
063115,000257: 22,3730 54156 TS MPAC +2
063116,000258: 22,3731 04676 TC BANKCALL # GET SIGN AGREEMENT IN ALL COMPONENTS
063117,000259: 22,3732 01010 CADR VECAGREE
063118,000260: 22,3733 10154 CCS MPAC
063119,000261: 22,3734 13770 TCF NOSHIFT
063120,000262: 22,3735 13737 TCF +2
063121,000263: 22,3736 13770 TCF NOSHIFT
063122,000264: 22,3737 10157 CCS MPAC +3
063123,000265: 22,3740 13770 TCF NOSHIFT
063124,000266: 22,3741 13743 TCF +2
063125,000267: 22,3742 13770 TCF NOSHIFT
063126,000268: 22,3743 10161 CCS MPAC +5
063127,000269: 22,3744 13770 TCF NOSHIFT
063128,000270: 22,3745 13747 TCF +2
063129,000271: 22,3746 13770 TCF NOSHIFT
063130,000272: 22,3747 30155 CA MPAC +1 # SHIFT ALL COMPONENTS LEFT 13
063131,000273: 22,3750 00006 EXTEND
063132,000274: 22,3751 75016 MP BIT14
063133,000275: 22,3752 20155 DAS MPAC # DAS GAINS A LITTLE ACCURACY
063134,000276: 22,3753 30160 CA MPAC +4
063135,000277: 22,3754 00006 EXTEND
063136,000278: 22,3755 75016 MP BIT14
063137,000279: 22,3756 20160 DAS MPAC +3
063138,000280: 22,3757 30162 CA MPAC +6
063139,000281: 22,3760 00006 EXTEND
063140,000282: 22,3761 75016 MP BIT14
063141,000283: 22,3762 20162 DAS MPAC +5
063142,000284: 22,3763 35041 CAF THIRTEEN
063143,000285: 22,3764 50156 INDEX MPAC +2
063144,000286: 22,3765 54045 TS 37D
063145,000287: 22,3766 04715 OFFTUNIT TC POSTJUMP
063146,000288: 22,3767 01024 CADR UNIT +1 # SKIP THE "TC VECAGREE" DONE AT UNIT
063147,000289:
063148,000290: 22,3770 35035 NOSHIFT CAF ZERO
063149,000291: 22,3771 13764 TCF OFFTUNIT -2
063150,000292:
063151,000293: # RTB VECSGNAG ... FORCES SIGN AGREEMENT OF VECTOR IN MPAC.
063152,000294:
063153,000295: 22,3772 04676 VECSGNAG TC BANKCALL
063154,000296: 22,3773 01010 CADR VECAGREE
063155,000297: 22,3774 06030 TC DANZIG
063156,000298:
Reconstruction: The following code implements PCR-984, "Avoid Coarse Align during Saturn". This change was added in MANCHE72 revision 3 as a single-module change from Comanche 72. It was added in response to the Apollo 12 launch, in which a lightning strike caused the AGC to incorrectly attempt to coarse align the IMU during launch, leading to a tumbling IMU. We have placed it here, at the end of RTB OP CODES, to mimic the placement of single-module-change code in the Apollo 11 software Comanche 55. This implementation closely mirrors the implementation of PCR-984 in Artemis 72, with slight modifications to remove PCN-1041 ("Add AVEGFLAG check in implementation of PCR-984") and make jumps use inter-bank calls. This implementation results in a correct banksum, but it is a sufficiently large change that there may be other implementations that also achieve a correct banksum. As such, we do not currently know if this implementation is exactly correct. |
063171,000313:
063172,000314: 11,2000 SETLOC MODCHG1
063173,000315: 11,2000 BANK
063174,000316: 11,3760 COUNT* $$/T4RPT
063175,000317:
063176,000318: 11,3760 10000 GLOCKCK1 CCS A
063177,000319: 11,3761 13770 TCF NOGIMRN1
063178,000320:
063179,000321: 11,3762 E6,1466 EBANK= DAPDATR1
063180,000322: 11,3762 35073 CAF EBANK6
063181,000323: 11,3763 54003 TS EBANK
063182,000324: 11,3764 41466 CS DAPDATR1
063183,000325: 11,3765 74371 MASK PRIO30
063184,000326: 11,3766 10000 CCS A
063185,000327: 11,3767 13772 TCF CALLCRS1 # NO
063186,000328:
063187,000329: 11,3770 04754 NOGIMRN1 TC IBNKCALL # YES, DON'T COARSE ALIGN
063188,000330: 11,3771 14455 CADR NOGIMRUN
063189,000331:
063190,000332: 11,3772 04754 CALLCRS1 TC IBNKCALL
063191,000333: 11,3773 14447 CADR CALLCRS
End of include-file RTB_OP_CODES.agc. Parent file is MAIN.agc