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.

047193,000002:                                                                                                  ## Copyright:   Public domain.
047194,000003:                                                                                                  ## Filename:    LATITUDE_LONGITUDE_SUBROUTINES.agc
047195,000004:                                                                                                  ## Purpose:     A section of Luminary 1C, revision 131.
047196,000005:                                                                                                  ##              It is part of the source code for the Lunar Module's (LM)
047197,000006:                                                                                                  ##              Apollo Guidance Computer (AGC) for Apollo 13.
047198,000007:                                                                                                  ##              This file is intended to be a faithful transcription, except
047199,000008:                                                                                                  ##              that the code format has been changed to conform to the
047200,000009:                                                                                                  ##              requirements of the yaYUL assembler rather than the
047201,000010:                                                                                                  ##              original YUL assembler.
047202,000011:                                                                                                  ## Reference:   pp. 1127-1133
047203,000012:                                                                                                  ## Contact:     Ron Burkey <info@sandroid.org>.
047204,000013:                                                                                                  ## Website:     www.ibiblio.org/apollo/index.html
047205,000014:                                                                                                  ## Mod history: 05/31/03 RSB.   Began transcribing.
047206,000015:                                                                                                  ##              05/14/05 RSB    Corrected website reference above.
047207,000016:                                                                                                  ##              2011-01-05 JL   Fixed indentation of RVQ instruction.
047208,000017:                                                                                                  ##              2017-01-06 RSB  Page numbers now agree with those on the
047209,000018:                                                                                                  ##                              original harcopy, as opposed to the PDF page
047210,000019:                                                                                                  ##                              numbers in 1701.pdf.
047211,000020:                                                                                                  ##              2017-02-05 RSB  Back-ported comment corrections 
047212,000021:                                                                                                  ##                              identified while proofing Artemis 072.
047213,000022:                                                                                                  ##              2017-02-27 RSB  Proofed comment text using octopus/ProoferComments.
047214,000023:                                                                                                  ##              2017-03-13 RSB  Comment-text fixes noted in proofing Luminary 116.
047215,000024:                                                                                                  ##              2017-03-15 RSB  Comment-text fixes identified in 5-way
047216,000025:                                                                                                  ##                              side-by-side diff of Luminary 69/99/116/131/210.
047217,000026: 

Page 1127

047219,000028:                                                                                                  #  SUBROUTINE TO CONVERT RAD VECTOR AT GIVEN TIME TO LAT,LONG AND ALT
047220,000029: 
047221,000030:                                                                                                  #  CALLING SEQUENCE
047222,000031:                                                                                                  #        L-1     CALL
047223,000032:                                                                                                  #        L               LAT-LONG
047224,000033: 
047225,000034:                                                                                                  #  SUBROUTINES USED
047226,000035:                                                                                                  #        R-TO-RP, ARCTAN, SETGAMMA, SETRE
047227,000036: 
047228,000037:                                                                                                  #  ERASABLE INIT. REQ.
047229,000038:                                                                                                  #        AXO, -AYO, AZO, TEPHEM (SET AT LAUNCH TIME)
047230,000039:                                                                                                  #        ALPHAV = POSITION VECTOR METERS B-29
047231,000040:                                                                                                  #        MPAC -- TIME (CSECS B-28)
047232,000041:                                                                                                  #        ERADFLAG =1, TO COMPUTE EARTH RADIUS, =0 FOR FIXED EARTH RADIUS
047233,000042:                                                                                                  #        LUNAFLAG=0 FOR EARTH, 1 FOR MOON
047234,000043: 
047235,000044:                                                                                                  #  OUTPUT
047236,000045:                                                                                                  #        LATITUDE IN LAT         (REVS. B-0)
047237,000046:                                                                                                  #        LONGITUDE IN LONG       (REVS. B-0)
047238,000047:                                                                                                  #        ALTITUDE IN ALT METERS  B-29
047239,000048: 
047240,000049: 30,3766                                           BANK     30                                    
047241,000050: 13,2000                                           SETLOC   LATLONG                               
047242,000051: 13,2000                                           BANK                                           
047243,000052: 
047244,000053: 13,2347                                           COUNT*   $$/LT-LG                              
047245,000054: 13,2347  E4,1431                                  EBANK=   ALPHAV                                
047246,000055: 13,2347           40220        LAT-LONG           STQ      SETPD                                 
047247,000056: 13,2350           03674                                    INCORPEX                              
047248,000057: 13,2351           00001                                    0D                                    
047249,000058: 13,2352           24007                           STOVL    6D                                    #  SAVE TIME IN 6-7D FOR R-TO-RP
047250,000059: 13,2353           02032                                    ALPHAV                                
047251,000060: 13,2354           51406                           PUSH     ABVAL                                 #  0-5D= R FOR R-TO-RP
047252,000061: 13,2355           16070                           STODL    ALPHAM                                #  ABS. VALUE OF R FOR ALT FORMULA BELOW
047253,000062: 13,2356           24007                                    ZEROVEC                               #  SET MPAC=0 FOR EARTH, NON-ZERO FOR MOON
047254,000063: 13,2357           71414                           BOFF     COS                                   #  USE COS(0) TO GET NON-ZERO IN MPAC
047255,000064: 13,2360           01743                                    LUNAFLAG                              #  0=EARTH, 1=MOON
047256,000065: 13,2361           26362                                    CALLRTRP                              
047257,000066: 13,2362           77624        CALLRTRP           CALL                                           
047258,000067: 13,2363           51700                                    R-TO-RP                               #  RP VECTOR CONVERTED FROM R B-29
047259,000068: 13,2364           77656                           UNIT                                           #  UNIT RP B-1
047260,000069: 13,2365           36032                           STCALL   ALPHAV                                #  U2= 1/2 SINL FOR SETRE SUBR BELOW
047261,000070: 13,2366           26546                                    SETGAMMA                              #        SET GAMMA=B2/A2 FOR EARTH, =1 FOR MOON
047262,000071: 13,2367           77624                           CALL                                           #        SCALED B-1
047263,000072: 13,2370           26556                                    SETRE                                 #  CALC RE METERS B-29
047264,000073: 13,2371           63545                           DLOAD    DSQ                                   
047265,000074: 13,2372           02032                                    ALPHAV                                
047266,000075: 13,2373           63525                           PDDL     DSQ                                   
047267,000076: 13,2374           02034                                    ALPHAV     +2                         
047268,000077: 13,2375           75415                           DAD      SQRT                                  

Page 1128

047270,000079: 13,2376           76405                           DMP      SL1R                                  
047271,000080: 13,2377           00011                                    GAMRP                                 
047272,000081: 13,2400           14021                           STODL    COSTH                                 #  COS(LAT) B-1
047273,000082: 13,2401           02036                                    ALPHAV     +4                         
047274,000083: 13,2402           34023                           STCALL   SINTH                                 #  SIN(LAT) B-1
047275,000084: 13,2403           26506                                    ARCTAN                                
047276,000085: 13,2404           15120                           STODL    LAT                                   #  LAT B0
047277,000086: 13,2405           02032                                    ALPHAV                                
047278,000087: 13,2406           14021                           STODL    COSTH                                 #  COS(LONG) B-1
047279,000088: 13,2407           02034                                    ALPHAV     +2                         
047280,000089: 13,2410           34023                           STCALL   SINTH                                 #  SIN(LONG) B-1
047281,000090: 13,2411           26506                                    ARCTAN                                
047282,000091: 13,2412           15122                           STODL    LONG                                  #  LONG. REVS B-0 IN RANGE -1/2 TO 1/2
047283,000092: 13,2413           02070                                    ALPHAM                                
047284,000093: 13,2414           77625                           DSU                                            #  ALT= R-RE METERS B-29
047285,000094: 13,2415           03673                                    ERADM                                 
047286,000095: 13,2416           35124                           STCALL   ALT                                   #  EXIT WITH ALT METERS B-29
047287,000096: 13,2417           03674                                    INCORPEX                              

Page 1129

047289,000098:                                                                                                  #  SUBROUTINE TO CONVERT LAT,LONG,ALT AT GIVEN TIME TO RADIUS VECTOR
047290,000099: 
047291,000100:                                                                                                  #  CALLING SEQUENCE
047292,000101:                                                                                                  #        L-1     CALL
047293,000102:                                                                                                  #        L               LALOTORV
047294,000103: 
047295,000104:                                                                                                  #  SUBROUTINES USED
047296,000105:                                                                                                  #        SETGAMMA, SETRE, RP-TO-R
047297,000106: 
047298,000107:                                                                                                  #  ERASABLE INIT. REQ.
047299,000108:                                                                                                  #        AXO, AYO, AZO, TEPHEM SET AT LAUNCH TIME
047300,000109:                                                                                                  #        LAT -- LATITUDE         (REVS B0)
047301,000110:                                                                                                  #        LONG -- LONGITUDE       (REVS B0)
047302,000111:                                                                                                  #        ALT -- ALTITUDE         (METERS) B-29
047303,000112:                                                                                                  #        MPAC -- TIME            (CSECS B-28)
047304,000113:                                                                                                  #        ERADFLAG =1 TO COMPUTE EARTH RADIUS, =0 FOR FIXED EARTH RADIUS
047305,000114:                                                                                                  #        LUNAFLAG=0 FOR EARTH, 1 FOR MOON
047306,000115: 
047307,000116:                                                                                                  #  OUTPUT
047308,000117:                                                                                                  #        R-VECTOR IN ALPHAV      (METERS B-29)
047309,000118: 
047310,000119: 13,2420           40220        LALOTORV           STQ      SETPD                                 #  LAT,LONG,ALT TO R VECTOR
047311,000120: 13,2421           03674                                    INCORPEX                              
047312,000121: 13,2422           00001                                    0D                                    
047313,000122: 13,2423           34007                           STCALL   6D                                    #  6-7D= TIME FOR RP-TO-R
047314,000123: 13,2424           26546                                    SETGAMMA                              #  GAMMA=B2/A2 FOR EARTH, 1 FOR MOON B-1
047315,000124: 13,2425           73545                           DLOAD    SIN                                   #            COS(LONG)COS(LAT) IN MPAC
047316,000125: 13,2426           01120                                    LAT                                   #  UNIT RP = SIN(LONG)COS(LAT)    2-3D
047317,000126: 13,2427           65275                           DMPR     PDDL                                  #  PD 2      GAMMA*SIN(LAT)       0-1D
047318,000127: 13,2430           00011                                    GAMRP                                 
047319,000128: 13,2431           01120                                    LAT                                   #      0-1D= GAMMA*SIN(LAT) B-2
047320,000129: 13,2432           65346                           COS      PDDL                                  #  PD4 2-3D= COS(LAT) B-1 TEMPORARILY
047321,000130: 13,2433           01122                                    LONG                                  
047322,000131: 13,2434           57356                           SIN      DMPR                                  #  PD 2
047323,000132: 13,2435           71525                           PDDL     COS                                   #  PD 4 2-3D = SIN(LONG)COS(LAT) B-2
047324,000133: 13,2436           01120                                    LAT                                   
047325,000134: 13,2437           71525                           PDDL     COS                                   #  PD 6 4-5D = COS(LAT) B-1 TEMPORARILY
047326,000135: 13,2440           01122                                    LONG                                  
047327,000136: 13,2441           55475                           DMPR     VDEF                                  #  PD4 MPAC= COS(LONG)COS(LAT) B-2
047328,000137: 13,2442           41456                           UNIT     PUSH                                  #  0-5D= UNIT RP FOR RP-TO-R SUBR.
047329,000138: 13,2443           36032                           STCALL   ALPHAV                                #  ALPHAV +4= SINL FOR SETRE SUBR.
047330,000139: 13,2444           26556                                    SETRE                                 #  RE METERS B-29
047331,000140: 13,2445           43145                           DLOAD    BOFF                                  #  SET MPAC=0 FOR EARTH, NON-ZERO FOR MOON
047332,000141: 13,2446           24007                                    ZEROVEC                               
047333,000142: 13,2447           01743                                    LUNAFLAG                              
047334,000143: 13,2450           26452                                    CALLRPRT                              
047335,000144: 13,2451           77746                           COS                                            #  USE COS(0) TO GET NON-ZERO IN MPAC
047336,000145: 13,2452           77624        CALLRPRT           CALL                                           
047337,000146: 13,2453           55716                                    RP-TO-R                               #  EXIT WITH UNIT R VECTOR IN MPAC
047338,000147: 13,2454           16032                           STODL    ALPHAV                                
047339,000148: 13,2455           03673                                    ERADM                                 

Page 1130

047341,000150: 13,2456           74215                           DAD      VXSC                                  #  (RE + ALT)(UNIT R) METERS B-30
047342,000151: 13,2457           01124                                    ALT                                   
047343,000152: 13,2460           02032                                    ALPHAV                                
047344,000153: 13,2461           77772                           VSL1                                           #  R METERS B-29
047345,000154: 13,2462           36032                           STCALL   ALPHAV                                #  EXIT WITH R IN METERS B-29
047346,000155: 13,2463           03674                                    INCORPEX                              
047347,000156: 
047348,000157:                                                                                                  #  SUBROUTINE TO COMPUTE EARTH RADIUS
047349,000158: 
047350,000159:                                                                                                  #  INPUT
047351,000160:                                                                                                  #        1/2 SIN LAT IN ALPHAV +4
047352,000161: 
047353,000162:                                                                                                  #  OUTPUT
047354,000163:                                                                                                  #        EARTH RADIUS IN ERADM AND MPAC (METERS B-29)
047355,000164: 
047356,000165: 13,2464           63545        GETERAD            DLOAD    DSQ                                   
047357,000166: 13,2465           02036                                    ALPHAV     +4                         #  SIN**2(L)
047358,000167: 13,2466           44352                           SL1      BDSU                                  
047359,000168: 13,2467           24005                                    DP1/2                                 #  COS**2(L)
047360,000169: 13,2470           44275                           DMPR     BDSU                                  
047361,000170: 13,2471           26505                                    EE                                    
047362,000171: 13,2472           24005                                    DP1/2                                 
047363,000172: 13,2473           75465                           BDDV     SQRT                                  
047364,000173: 13,2474           26501                                    B2XSC                                 
047365,000174: 13,2475           77622                           SR4R                                           
047366,000175: 13,2476           03673                           STORE    ERADM                                 
047367,000176: 13,2477           77616                           RVQ                                            
047368,000177: 
047369,000178:                                                                                                  #  THE FOLLOWING CONSTANTS WERE COMPUTED WITH A=6378166, B=6356784 METERS
047370,000179:                                                                                                  #  B2XSC = B**2 SCALED B-51
047371,000180:                                                                                                  #  B2/A2 = B**2/A**2 SCALED B-1
047372,000181:                                                                                                  #  EE = (1-B**2/A**2) SCALED B-0
047373,000182: 
047374,000183: 13,2500           00446 00305  B2XSC              2DEC     .0179450689                            #  B**2 SCALED B-51
047375,000184: 13,2502  12,2004               DP1/2              =        XUNIT                                 
047376,000185: 13,2502           17711 05254  B2/A2              2DEC     .9933064884 B-1                        #  GAMMA= B**2/A**2 B-1
047377,000186: 13,2504           00155 25250  EE                 2DEC     6.6935116  E-3                        #  (1-B**2/A**2) B-0
047378,000187: 

Page 1131

047380,000189:                                                                                                  #  ARCTAN SUBROUTINE
047381,000190: 
047382,000191:                                                                                                  #  CALLING SEQUENCE
047383,000192:                                                                                                  #        SIN THETA IN SINTH B-1
047384,000193:                                                                                                  #        COS THETA IN COSTH B-1
047385,000194:                                                                                                  #        CALL ARCTAN
047386,000195: 
047387,000196:                                                                                                  #  OUTPUT
047388,000197:                                                                                                  #        ARCTAN THETA IN MPAC AND THETA B-0 IN RANGE -1/2 TO +1/2
047389,000198: 
047390,000199: 13,2506           77600        ARCTAN             BOV                                            
047391,000200: 13,2507           26510                                    CLROVFLW                              
047392,000201: 13,2510           63545        CLROVFLW           DLOAD    DSQ                                   
047393,000202: 13,2511           00023                                    SINTH                                 
047394,000203: 13,2512           63525                           PDDL     DSQ                                   
047395,000204: 13,2513           00021                                    COSTH                                 
047396,000205: 13,2514           77615                           DAD                                            
047397,000206: 13,2515           75454                           BZE      SQRT                                  
047398,000207: 13,2516           26534                                    ARCTANXX                              #  ATAN=0/0  SET THETA=0
047399,000208: 13,2517           40065                           BDDV     BOV                                   
047400,000209: 13,2520           00023                                    SINTH                                 
047401,000210: 13,2521           26541                                    ATAN=90                               
047402,000211: 13,2522           67542                           SR1      ASIN                                  
047403,000212: 13,2523           00025                           STORE    THETA                                 
047404,000213: 13,2524           50125                           PDDL     BMN                                   
047405,000214: 13,2525           00021                                    COSTH                                 
047406,000215: 13,2526           26530                                    NEGCOS                                
047407,000216: 13,2527           43545                           DLOAD    RVQ                                   
047408,000217: 13,2530           57545        NEGCOS             DLOAD    DCOMP                                 
047409,000218: 13,2531           43244                           BPL      DAD                                   
047410,000219: 13,2532           26536                                    NEGOUT                                
047411,000220: 13,2533           24005                                    DP1/2                                 
047412,000221: 13,2534           00025        ARCTANXX           STORE    THETA                                 
047413,000222: 13,2535           77616                           RVQ                                            
047414,000223: 
047415,000224: 13,2536           52025        NEGOUT             DSU      GOTO                                  
047416,000225: 13,2537           24005                                    DP1/2                                 
047417,000226: 13,2540           26534                                    ARCTANXX                              
047418,000227: 13,2541           75345        ATAN=90            DLOAD    SIGN                                  
047419,000228: 13,2542           11003                                    LODP1/4                               
047420,000229: 13,2543           00023                                    SINTH                                 
047421,000230: 13,2544           00025                           STORE    THETA                                 
047422,000231: 13,2545           77616                           RVQ                                            
047423,000232: 
047424,000233: 13,2546  12,2006               2DZERO             =        DPZERO                                
047425,000234: 

Page 1132

047427,000236:                                                                                                  #  ..... SETGAMMA SUBROUTINE .....
047428,000237:                                                                                                  #  SUBROUTINE TO SET GAMMA FOR THE LAT-LONG AND LALOTORV SUBROUTINES
047429,000238: 
047430,000239:                                                                                                  #  GAMMA = B**2/A**2 FOR EARTH (B-1)
047431,000240:                                                                                                  #  GAMMA = 1 FOR MOON (B-1)
047432,000241: 
047433,000242:                                                                                                  #  CALLING SEQUENCE
047434,000243:                                                                                                  #        L       CALL
047435,000244:                                                                                                  #        L+1             SETGAMMA
047436,000245: 
047437,000246:                                                                                                  #  INPUT
047438,000247:                                                                                                  #        LUNAFLAG=0 FOR EARTH, =1 FOR MOON
047439,000248: 
047440,000249:                                                                                                  #  OUTPUT
047441,000250:                                                                                                  #        GAMMA IN GAMRP (B-1)
047442,000251: 
047443,000252: 13,2546           43145        SETGAMMA           DLOAD    BOFF                                  #  BRANCH FOR EARTH
047444,000253: 13,2547           26503                                    B2/A2                                 #  EARTH GAMMA
047445,000254: 13,2550           01743                                    LUNAFLAG                              
047446,000255: 13,2551           26554                                    SETGMEX                               
047447,000256: 13,2552           77735                           SLOAD                                          
047448,000257: 13,2553           24005                                    1B1                                   #  MOON GAMMA
047449,000258: 13,2554           00011        SETGMEX            STORE    GAMRP                                 
047450,000259: 13,2555           77616                           RVQ                                            
047451,000260: 13,2556                        GAMRP              =        8D                                    
047452,000261: 

Page 1133

047454,000263:                                                                                                  #  ..... SETRE SUBROUTINE .....
047455,000264:                                                                                                  #  SUBROUTINE TO SET RE (EARTH OR MOON RADIUS)
047456,000265: 
047457,000266:                                                                                                  #        RE = RM FOR MOON
047458,000267:                                                                                                  #        RE = RREF FOR FIXED EARTH RADIUS OR COMPUTED RF FOR FISCHER ELLIPSOID
047459,000268: 
047460,000269:                                                                                                  #  CALLING SEQUENCE
047461,000270:                                                                                                  #        L       CALL
047462,000271:                                                                                                  #        L+1             SETRE
047463,000272: 
047464,000273:                                                                                                  #  SUBROUTINES USED
047465,000274:                                                                                                  #        GETERAD
047466,000275: 
047467,000276:                                                                                                  #  INPUT
047468,000277:                                                                                                  #        ERADFLAG = 0 FOR FIXED RE, 1 FOR COMPUTED RE
047469,000278:                                                                                                  #        ALPHAV +4 = 1/2 SINL IF GETERAD IS CALLED
047470,000279:                                                                                                  #        LUNAFLAG = 0 FOR EARTH, =1 FOR MOON
047471,000280: 
047472,000281:                                                                                                  #  OUTPUT
047473,000282:                                                                                                  #        ERADM = 504RM FOR MOON (METERS B-29)
047474,000283:                                                                                                  #        ERADM = ERAD OR COMPUTED RF FOR EARTH (METERS B-29)
047475,000284: 
047476,000285: 13,2556           71220        SETRE              STQ      DLOAD                                 
047477,000286: 13,2557           00051                                    SETREX                                
047478,000287: 13,2560           10003                                    504RM                                 
047479,000288: 13,2561           71214                           BON      DLOAD                                 #  BRANCH FOR MOON
047480,000289: 13,2562           01703                                    LUNAFLAG                              
047481,000290: 13,2563           26573                                    TSTRLSRM                              
047482,000291: 13,2564           10001                                    ERAD                                  
047483,000292: 13,2565           45014                           BOFF     CALL                                  #  ERADFLAG=0 FOR FIXED RE, 1 FOR COMPUTED
047484,000293: 13,2566           00742                                    ERADFLAG                              
047485,000294: 13,2567           26571                                    SETRXX                                
047486,000295: 13,2570           26464                                    GETERAD                               
047487,000296: 13,2571           37673        SETRXX             STCALL   ERADM                                 #  EXIT WITH RE OR RM METERS B-29
047488,000297: 13,2572           00051                                    SETREX                                
047489,000298: 13,2573           77214        TSTRLSRM           BON      VLOAD                                 #  ERADFLAG=0, SET R0=RLS
047490,000299: 13,2574           00702                                    ERADFLAG                              #          =1      R0=RM
047491,000300: 13,2575           26571                                    SETRXX                                
047492,000301: 13,2576           02023                                    RLS                                   
047493,000302: 13,2577           64446                           ABVAL    SR2R                                  #  SCALE FROM B-27 TO B-29
047494,000303: 13,2600           77650                           GOTO                                           
047495,000304: 13,2601           26571                                    SETRXX                                
047496,000305: 13,2602  0000051               SETREX             =        S2                                    
047497,000306: 
047498,000307: 

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