Source Code

This source code is very close to the Apollo Guidance Computer software for the Apollo 13 Lunar module. This revision of the Luminary 131 program is from December of 1969, whereas there was a later revision in January of 1970, and still another revision in February, which is the code that flew on the mission. As far as this transcription is concerned, it was originally from a copy made in 1991 of a printout from the collection of AGC developer Don Eyles for collector David Craig. It was subsequently scanned by Gary Neff, reprocessed for online presentation at the now-discontinued History of Recent Science and Technology (HRST) website of MIT's Dibner Institute (the full-quality scans being discarded in the process), and finally transcribed by Ron Burkey for the Virtual AGC Project. Although a high-quality replacement scan for a completely illegible page was later provided by Gary Neff, the reduced legibility of the reprocessed HRST posting nevertheless caused many errors to be introduced into the transcription. Accordingly, a second scan of the same physical printout was made in 2017 for the Virtual AGC Project's collection at the Internet Archive, and used to correct the transcription errors. All of the scanned materials mentioned, as well as other Luminary 131 related material, are available online. Don Eyles apprently made additional hand-written notes in printout between 1991 and 2017, so the two scans are not identical in that respect. The page-headings in the printout read, in part:
	GAP:  ASSEMBLE REVISION 131 OF AGC PROGRAM LUMINARY BY NASA 2021112-091
	17:53 DEC. 19, 1969
Note that the date is the date the printout was made, not the date on which the program revision was released, although these happen to be very close together.

058643,000002:                                                                                                  ## Copyright:   Public domain.
058644,000003:                                                                                                  ## Filename:    RTB_OP_CODES.agc
058645,000004:                                                                                                  ## Purpose:     A section of Luminary 1C, revision 131.
058646,000005:                                                                                                  ##              It is part of the source code for the Lunar Module's (LM)
058647,000006:                                                                                                  ##              Apollo Guidance Computer (AGC) for Apollo 13.
058648,000007:                                                                                                  ##              This file is intended to be a faithful transcription, except
058649,000008:                                                                                                  ##              that the code format has been changed to conform to the
058650,000009:                                                                                                  ##              requirements of the yaYUL assembler rather than the
058651,000010:                                                                                                  ##              original YUL assembler.
058652,000011:                                                                                                  ## Reference:   pp. 1389-1394
058653,000012:                                                                                                  ## Contact:     Ron Burkey <info@sandroid.org>.
058654,000013:                                                                                                  ## Website:     www.ibiblio.org/apollo/index.html
058655,000014:                                                                                                  ## Mod history: 06/07/03 RSB.   Began transcribing.
058656,000015:                                                                                                  ##              05/14/05 RSB    Corrected website references above.
058657,000016:                                                                                                  ##              2017-01-06 RSB  Page numbers now agree with those on the
058658,000017:                                                                                                  ##                              original hardcopy, as opposed to the PDF page
058659,000018:                                                                                                  ##                              numbers in 1701.pdf.
058660,000019:                                                                                                  ##              2017-02-28 RSB  Proofed comment text using octopus/ProoferComments.
058661,000020: 

Page 1389

058663,000022: 22,3773                                           BANK     22                                    
058664,000023: 10,2000                                           SETLOC   RTBCODES                              
058665,000024: 10,2000                                           BANK                                           
058666,000025: 
058667,000026: 10,3574  E5,1664                                  EBANK=   XNB                                   
058668,000027: 10,3574                                           COUNT*   $$/RTB                                
058669,000028: 
058670,000029:                                                                                                  #  LOAD TIME2, TIME1 INTO MPAC:
058671,000030: 
058672,000031: 10,3574           00006        LOADTIME           EXTEND                                         
058673,000032: 10,3575           30025                           DCA      TIME2                                 
058674,000033: 10,3576           16060                           TCF      SLOAD2                                
058675,000034: 
058676,000035:                                                                                                  #  CONVERT THE SINGLE PRECISION 2'S COMPLEMENT NUMBER ARRIVING IN MPAC (SCALED IN HALF-REVOLUTIONS) TO A
058677,000036:                                                                                                  #  DP 1'S COMPLEMENT NUMBER SCALED IN REVOLUTIONS.
058678,000037: 
058679,000038: 10,3577           10154        CDULOGIC           CCS      MPAC                                  
058680,000039: 10,3600           34755                           CAF      ZERO                                  
058681,000040: 10,3601           13604                           TCF      +3                                    
058682,000041: 10,3602           13603                           NOOP                                           
058683,000042: 10,3603           44736                           CS       HALF                                  
058684,000043: 
058685,000044: 10,3604           54155                           TS       MPAC       +1                         
058686,000045: 10,3605           34755                           CAF      ZERO                                  
058687,000046: 10,3606           56154                           XCH      MPAC                                  
058688,000047: 10,3607           00006                           EXTEND                                         
058689,000048: 10,3610           74736                           MP       HALF                                  
058690,000049: 10,3611           20155                           DAS      MPAC                                  
058691,000050: 10,3612           16064                           TCF      DANZIG                                #  MODE IS ALREADY AT DOUBLE-PRECISION
058692,000051: 
058693,000052:                                                                                                  #  FORCE TP SIGN AGREEMENT IN MPAC:
058694,000053: 
058695,000054: 10,3613           07262        SGNAGREE           TC       TPAGREE                               
058696,000055: 10,3614           16064                           TCF      DANZIG                                
058697,000056: 
058698,000057:                                                                                                  #  CONVERT THE DP 1'S COMPLEMENT ANGLE SCALED IN REVOLUTIONS TO A SINGLE PRECISION 2'S COMPLEMENT ANGLE
058699,000058:                                                                                                  #  SCALED IN HALF-REVOLUTIONS.
058700,000059: 
058701,000060: 10,3615           03645        1STO2S             TC       1TO2SUB                               
058702,000061: 10,3616           34755                           CAF      ZERO                                  
058703,000062: 10,3617           54155                           TS       MPAC       +1                         
058704,000063: 10,3620           16063                           TCF      NEWMODE                               
058705,000064: 
058706,000065:                                                                                                  #  DO 1STO2S ON A VECTOR OF ANGLES:
058707,000066: 
058708,000067: 10,3621           03645        V1STO2S            TC       1TO2SUB                               #  ANSWER ARRIVES IN A AND MPAC.
058709,000068: 
058710,000069: 10,3622           52162                           DXCH     MPAC       +5                         
058711,000070: 10,3623           52155                           DXCH     MPAC                                  
058712,000071: 10,3624           03645                           TC       1TO2SUB                               

Page 1390

058714,000073: 10,3625           54156                           TS       MPAC       +2                         
058715,000074: 
058716,000075: 10,3626           52160                           DXCH     MPAC       +3                         
058717,000076: 10,3627           52155                           DXCH     MPAC                                  
058718,000077: 10,3630           03645                           TC       1TO2SUB                               
058719,000078: 10,3631           54155                           TS       MPAC       +1                         
058720,000079: 
058721,000080: 10,3632           30161                           CA       MPAC       +5                         
058722,000081: 10,3633           54154                           TS       MPAC                                  
058723,000082: 
058724,000083: 10,3634           34753        TPMODE             CAF      ONE                                   #  MODE IS TP.
058725,000084: 10,3635           16063                           TCF      NEWMODE                               
058726,000085: 
058727,000086:                                                                                                  #  V1STO2S FOR 2 COMPONENT VECTOR. USED BY RR.
058728,000087: 
058729,000088: 10,3636           03645        2V1STO2S           TC       1TO2SUB                               
058730,000089: 10,3637           52160                           DXCH     MPAC       +3                         
058731,000090: 10,3640           52155                           DXCH     MPAC                                  
058732,000091: 10,3641           03645                           TC       1TO2SUB                               
058733,000092: 10,3642           54001                           TS       L                                     
058734,000093: 10,3643           30157                           CA       MPAC       +3                         
058735,000094: 10,3644           16060                           TCF      SLOAD2                                
058736,000095: 
058737,000096:                                                                                                  #  SUBROUTINE TO DO DOUBLING AND 1'S TO 2'S CONVERSION:
058738,000097: 
058739,000098: 10,3645           52155        1TO2SUB            DXCH     MPAC                                  #  FINAL MPAC +1 UNSPECIFIED.
058740,000099: 10,3646           20001                           DDOUBL                                         
058741,000100: 10,3647           10000                           CCS      A                                     
058742,000101: 10,3650           64753                           AD       ONE                                   
058743,000102: 10,3651           13653                           TCF      +2                                    
058744,000103: 10,3652           40000                           COM                                            #  THIS WAS REVERSE OF MSU.
058745,000104: 
058746,000105: 10,3653           54154                           TS       MPAC                                  #  AND SKIP ON OVERFLOW.
058747,000106: 10,3654           00002                           TC       Q                                     
058748,000107: 
058749,000108: 10,3655           50000                           INDEX    A                                     #  OVERFLOW UNCORRECT AND IN MSU.
058750,000109: 10,3656           34734                           CAF      LIMITS                                
058751,000110: 10,3657           26154                           ADS      MPAC                                  
058752,000111: 10,3660           00002                           TC       Q                                     
058753,000112: 
058754,000113:                                                                                                  #  THE FOLLOWING ROUTINE INCREMENTS IN 2S COMPLEMENT THE REGISTER WHOSE ADDRESS IS IN BUF BY THE 1S COMPL.
058755,000114:                                                                                                  #  QUANTITY FOUND IN TEM2.  THIS MAY BE USED TO INCREMENT DESIRED IMU AND OPTICS CDU ANGLES OR ANY OTHER 2S COMPL.
058756,000115:                                                                                                  #  (+0 UNEQUAL TO -0) QUANTITY.  MAY BE CALLED BY BANKCALL/SWCALL.
058757,000116: 
058758,000117: 10,3661           54142        CDUINC             TS       TEM2                                  #  1S COMPL. QUANT. ARRIVES IN ACC.  STORE IT
058759,000118: 10,3662           50130                           INDEX    BUF                                   
058760,000119: 10,3663           10000                           CCS      0                                     #  CHANGE 2S COMPL. ANGLE(IN BUF)INTO 1S
058761,000120: 10,3664           64753                           AD       ONE                                   
058762,000121: 10,3665           13671                           TCF      +4                                    
058763,000122: 10,3666           64753                           AD       ONE                                   

Page 1391

058765,000124: 10,3667           64753                           AD       ONE                                   #  OVERFLOW HERE IF 2S COMPL. IS 180 DEG.
058766,000125: 10,3670           40000                           COM                                            
058767,000126: 
058768,000127: 10,3671           60142                           AD       TEM2                                  #  SULT MOVES FROM 2ND TO 3D QUAD. (OR BACK)
058769,000128: 10,3672           10000                           CCS      A                                     #  BACK TO 2S COMPL.
058770,000129: 10,3673           64753                           AD       ONE                                   
058771,000130: 10,3674           13676                           TCF      +2                                    
058772,000131: 10,3675           40000                           COM                                            
058773,000132: 10,3676           54142                           TS       TEM2                                  #  STORE 14BIT QUANTITY WITH PRESENT SIGN
058774,000133: 10,3677           13703                           TCF      +4                                    
058775,000134: 10,3700           50000                           INDEX    A                                     #  SIGN.
058776,000135: 10,3701           34734                           CAF      LIMITS                                #  FIX IT, BY ADDING IN 37777 OR 40000
058777,000136: 10,3702           60142                           AD       TEM2                                  
058778,000137: 
058779,000138: 10,3703           50130                           INDEX    BUF                                   
058780,000139: 10,3704           54000                           TS       0                                     #  STORE NEW ANGLE IN 2S COMPLEMENT.
058781,000140: 10,3705           00002                           TC       Q                                     
058782,000141: 

Page 1392

058784,000143:                                                                                                  #  RTB TO TORQUE GYROS, EXCEPT FOR THE CALL TO IMUSTALL.  ECADR OF COMMANDS ARRIVES IN X1.
058785,000144: 
058786,000145: 10,3706           50120        PULSEIMU           INDEX    FIXLOC                                #  ADDRESS OF GYRO COMMANDS SHOULD BE IN X1
058787,000146: 10,3707           30046                           CA       X1                                    
058788,000147: 10,3710           04616                           TC       BANKCALL                              
058789,000148: 10,3711           17314                           CADR     IMUPULSE                              
058790,000149: 10,3712           16064                           TCF      DANZIG                                
058791,000150: 

Page 1393

058793,000152:                                                                                                  #  THE SUBROUTINE  SIGNMPAC  SETS C(MPAC, MPAC +1) TO SIGN(MPAC).
058794,000153:                                                                                                  #  FOR THIS, ONLY THE CONTENTS OF MPAC ARE EXAMINED.  ALSO +0 YIELDS POSMAX AND -0 YIELDS NEGMAX.
058795,000154: 
058796,000155:                                                                                                  #  ENTRY MAY BE BY EITHER OF THE FOLLOWING:
058797,000156:                                                                                                  #        1.      LIMIT THE SIZE OF MPAC ON INTERPRETIVE OVERFLOW:
058798,000157:                                                                                                  #                ENTRY:          BOVB
058799,000158:                                                                                                  #                                        SIGNMPAC
058800,000159:                                                                                                  #        2.      GENERATE IN MPAC THE SIGNUM FUNCTION OF MPAC:
058801,000160:                                                                                                  #                ENTRY:          RTB
058802,000161:                                                                                                  #                                        SIGNMPAC
058803,000162:                                                                                                  #  IN EITHER CASE, RETURN IS TO THE NEXT INTERPRETIVE INSTRUCTION IN THE CALLING SEQUENCE.
058804,000163: 
058805,000164: 10,3713           00006        SIGNMPAC           EXTEND                                         
058806,000165: 10,3714           34733                           DCA      DPOSMAX                               
058807,000166: 10,3715           52155                           DXCH     MPAC                                  
058808,000167: 10,3716           10000                           CCS      A                                     
058809,000168: 10,3717           34755        DPMODE             CAF      ZERO                                  #  SETS MPAC +2 TO ZERO IN THE PROCESS
058810,000169: 10,3720           16062                           TCF      SLOAD2     +2                         
058811,000170: 10,3721           13722                           TCF      +1                                    
058812,000171: 10,3722           00006                           EXTEND                                         
058813,000172: 10,3723           44733                           DCS      DPOSMAX                               
058814,000173: 10,3724           16060                           TCF      SLOAD2                                
058815,000174: 
058816,000175:                                                                                                  #  RTB OP CODE NORMUNIT IS LIKE INTERPRETIVE INSTRUCTION UNIT, EXCEPT THAT IT CAN BE DEPENDED ON NOT TO BLOW
058817,000176:                                                                                                  #  UP WHEN THE VECTOR BEING UNITIZED IS VERY SMALL -- IT WILL BLOW UP WHEN ALL COMPONENTS ARE ZERO.  IF NORMUNIT
058818,000177:                                                                                                  #  IS USED AND THE UPPER ORDER HALVES OF ALL COMPONENTS ARE ZERO, THE MAGNITUDE RETURNED IN 36D WILL BE TOO LARGE
058819,000178:                                                                                                  #  BY A FACTOR OF 2(13) AND THE SQUARED MAGNITUDE RETURNED AT 34D WILL BE TOO BIG BY A FACTOR OF 2(26).
058820,000179: 
058821,000180: 10,3725           34753        NORMUNX1           CAF      ONE                                   
058822,000181: 10,3726           13730                           TCF      NORMUNIT   +1                         
058823,000182: 10,3727           34755        NORMUNIT           CAF      ZERO                                  
058824,000183: 10,3730           60120                           AD       FIXLOC                                
058825,000184: 10,3731           54156                           TS       MPAC       +2                         
058826,000185: 10,3732           04616                           TC       BANKCALL                              #  GET SIGN AGREEMENT IN ALL COMPONENTS
058827,000186: 10,3733           01010                           CADR     VECAGREE                              
058828,000187: 10,3734           10154                           CCS      MPAC                                  
058829,000188: 10,3735           13771                           TCF      NOSHIFT                               
058830,000189: 10,3736           13740                           TCF      +2                                    
058831,000190: 10,3737           13771                           TCF      NOSHIFT                               
058832,000191: 10,3740           10157                           CCS      MPAC       +3                         
058833,000192: 10,3741           13771                           TCF      NOSHIFT                               
058834,000193: 10,3742           13744                           TCF      +2                                    
058835,000194: 10,3743           13771                           TCF      NOSHIFT                               
058836,000195: 10,3744           10161                           CCS      MPAC       +5                         
058837,000196: 10,3745           13771                           TCF      NOSHIFT                               
058838,000197: 10,3746           13750                           TCF      +2                                    
058839,000198: 10,3747           13771                           TCF      NOSHIFT                               

Page 1394

058841,000200: 10,3750           30155                           CA       MPAC       +1                         #  SHIFT ALL COMPONENTS LEFT 13
058842,000201: 10,3751           00006                           EXTEND                                         
058843,000202: 10,3752           74736                           MP       BIT14                                 
058844,000203: 10,3753           20155                           DAS      MPAC                                  #  DAS GAINS A LITTLE ACCURACY
058845,000204: 10,3754           30160                           CA       MPAC       +4                         
058846,000205: 10,3755           00006                           EXTEND                                         
058847,000206: 10,3756           74736                           MP       BIT14                                 
058848,000207: 10,3757           20160                           DAS      MPAC       +3                         
058849,000208: 10,3760           30162                           CA       MPAC       +6                         
058850,000209: 10,3761           00006                           EXTEND                                         
058851,000210: 10,3762           74736                           MP       BIT14                                 
058852,000211: 10,3763           20162                           DAS      MPAC       +5                         
058853,000212: 10,3764           34761                           CAF      THIRTEEN                              
058854,000213: 10,3765           50156                           INDEX    MPAC       +2                         
058855,000214: 10,3766           54045                           TS       37D                                   
058856,000215: 10,3767           04635        OFFTUNIT           TC       POSTJUMP                              
058857,000216: 10,3770           01024                           CADR     UNIT       +1                         #  SKIP THE "TC VECAGREE" DONE AT UNIT
058858,000217: 
058859,000218: 10,3771           34755        NOSHIFT            CAF      ZERO                                  
058860,000219: 10,3772           13765                           TCF      OFFTUNIT   -2                         
058861,000220: 
058862,000221:                                                                                                  #  RTB VECSGNAG ... FORCES SIGN AGREEMENT OF VECTOR IN MPAC.
058863,000222: 
058864,000223: 10,3773           04616        VECSGNAG           TC       BANKCALL                              
058865,000224: 10,3774           01010                           CADR     VECAGREE                              
058866,000225: 10,3775           06064                           TC       DANZIG                                
058867,000226: 
058868,000227: 

End of include-file RTB_OP_CODES.agc.  Parent file is MAIN.agc