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.

047218,000002:                                                                                                  ## Copyright:   Public domain.
047219,000003:                                                                                                  ## Filename:    LATITUDE_LONGITUDE_SUBROUTINES.agc
047220,000004:                                                                                                  ## Purpose:     A section of Luminary 1C, revision 131.
047221,000005:                                                                                                  ##              It is part of the source code for the Lunar Module's (LM)
047222,000006:                                                                                                  ##              Apollo Guidance Computer (AGC) for Apollo 13.
047223,000007:                                                                                                  ##              This file is intended to be a faithful transcription, except
047224,000008:                                                                                                  ##              that the code format has been changed to conform to the
047225,000009:                                                                                                  ##              requirements of the yaYUL assembler rather than the
047226,000010:                                                                                                  ##              original YUL assembler.
047227,000011:                                                                                                  ## Reference:   pp. 1127-1133
047228,000012:                                                                                                  ## Contact:     Ron Burkey <info@sandroid.org>.
047229,000013:                                                                                                  ## Website:     www.ibiblio.org/apollo/index.html
047230,000014:                                                                                                  ## Mod history: 05/31/03 RSB.   Began transcribing.
047231,000015:                                                                                                  ##              05/14/05 RSB    Corrected website reference above.
047232,000016:                                                                                                  ##              2011-01-05 JL   Fixed indentation of RVQ instruction.
047233,000017:                                                                                                  ##              2017-01-06 RSB  Page numbers now agree with those on the
047234,000018:                                                                                                  ##                              original harcopy, as opposed to the PDF page
047235,000019:                                                                                                  ##                              numbers in 1701.pdf.
047236,000020:                                                                                                  ##              2017-02-05 RSB  Back-ported comment corrections 
047237,000021:                                                                                                  ##                              identified while proofing Artemis 072.
047238,000022:                                                                                                  ##              2017-02-27 RSB  Proofed comment text using octopus/ProoferComments.
047239,000023:                                                                                                  ##              2017-03-13 RSB  Comment-text fixes noted in proofing Luminary 116.
047240,000024:                                                                                                  ##              2017-03-15 RSB  Comment-text fixes identified in 5-way
047241,000025:                                                                                                  ##                              side-by-side diff of Luminary 69/99/116/131/210.
047242,000026: 

Page 1127

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

Page 1128

047295,000079: 13,2376           76405                           DMP      SL1R                                  
047296,000080: 13,2377           00011                                    GAMRP                                 
047297,000081: 13,2400           14021                           STODL    COSTH                                 #  COS(LAT) B-1
047298,000082: 13,2401           02036                                    ALPHAV     +4                         
047299,000083: 13,2402           34023                           STCALL   SINTH                                 #  SIN(LAT) B-1
047300,000084: 13,2403           26506                                    ARCTAN                                
047301,000085: 13,2404           15120                           STODL    LAT                                   #  LAT B0
047302,000086: 13,2405           02032                                    ALPHAV                                
047303,000087: 13,2406           14021                           STODL    COSTH                                 #  COS(LONG) B-1
047304,000088: 13,2407           02034                                    ALPHAV     +2                         
047305,000089: 13,2410           34023                           STCALL   SINTH                                 #  SIN(LONG) B-1
047306,000090: 13,2411           26506                                    ARCTAN                                
047307,000091: 13,2412           15122                           STODL    LONG                                  #  LONG. REVS B-0 IN RANGE -1/2 TO 1/2
047308,000092: 13,2413           02070                                    ALPHAM                                
047309,000093: 13,2414           77625                           DSU                                            #  ALT= R-RE METERS B-29
047310,000094: 13,2415           03673                                    ERADM                                 
047311,000095: 13,2416           35124                           STCALL   ALT                                   #  EXIT WITH ALT METERS B-29
047312,000096: 13,2417           03674                                    INCORPEX                              

Page 1129

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

Page 1130

047366,000150: 13,2456           74215                           DAD      VXSC                                  #  (RE + ALT)(UNIT R) METERS B-30
047367,000151: 13,2457           01124                                    ALT                                   
047368,000152: 13,2460           02032                                    ALPHAV                                
047369,000153: 13,2461           77772                           VSL1                                           #  R METERS B-29
047370,000154: 13,2462           36032                           STCALL   ALPHAV                                #  EXIT WITH R IN METERS B-29
047371,000155: 13,2463           03674                                    INCORPEX                              
047372,000156: 
047373,000157:                                                                                                  #  SUBROUTINE TO COMPUTE EARTH RADIUS
047374,000158: 
047375,000159:                                                                                                  #  INPUT
047376,000160:                                                                                                  #        1/2 SIN LAT IN ALPHAV +4
047377,000161: 
047378,000162:                                                                                                  #  OUTPUT
047379,000163:                                                                                                  #        EARTH RADIUS IN ERADM AND MPAC (METERS B-29)
047380,000164: 
047381,000165: 13,2464           63545        GETERAD            DLOAD    DSQ                                   
047382,000166: 13,2465           02036                                    ALPHAV     +4                         #  SIN**2(L)
047383,000167: 13,2466           44352                           SL1      BDSU                                  
047384,000168: 13,2467           24005                                    DP1/2                                 #  COS**2(L)
047385,000169: 13,2470           44275                           DMPR     BDSU                                  
047386,000170: 13,2471           26505                                    EE                                    
047387,000171: 13,2472           24005                                    DP1/2                                 
047388,000172: 13,2473           75465                           BDDV     SQRT                                  
047389,000173: 13,2474           26501                                    B2XSC                                 
047390,000174: 13,2475           77622                           SR4R                                           
047391,000175: 13,2476           03673                           STORE    ERADM                                 
047392,000176: 13,2477           77616                           RVQ                                            
047393,000177: 
047394,000178:                                                                                                  #  THE FOLLOWING CONSTANTS WERE COMPUTED WITH A=6378166, B=6356784 METERS
047395,000179:                                                                                                  #  B2XSC = B**2 SCALED B-51
047396,000180:                                                                                                  #  B2/A2 = B**2/A**2 SCALED B-1
047397,000181:                                                                                                  #  EE = (1-B**2/A**2) SCALED B-0
047398,000182: 
047399,000183: 13,2500           00446 00305  B2XSC              2DEC     .0179450689                            #  B**2 SCALED B-51
047400,000184: 13,2502  12,2004               DP1/2              =        XUNIT                                 
047401,000185: 13,2502           17711 05254  B2/A2              2DEC     .9933064884 B-1                        #  GAMMA= B**2/A**2 B-1
047402,000186: 13,2504           00155 25250  EE                 2DEC     6.6935116  E-3                        #  (1-B**2/A**2) B-0
047403,000187: 

Page 1131

047405,000189:                                                                                                  #  ARCTAN SUBROUTINE
047406,000190: 
047407,000191:                                                                                                  #  CALLING SEQUENCE
047408,000192:                                                                                                  #        SIN THETA IN SINTH B-1
047409,000193:                                                                                                  #        COS THETA IN COSTH B-1
047410,000194:                                                                                                  #        CALL ARCTAN
047411,000195: 
047412,000196:                                                                                                  #  OUTPUT
047413,000197:                                                                                                  #        ARCTAN THETA IN MPAC AND THETA B-0 IN RANGE -1/2 TO +1/2
047414,000198: 
047415,000199: 13,2506           77600        ARCTAN             BOV                                            
047416,000200: 13,2507           26510                                    CLROVFLW                              
047417,000201: 13,2510           63545        CLROVFLW           DLOAD    DSQ                                   
047418,000202: 13,2511           00023                                    SINTH                                 
047419,000203: 13,2512           63525                           PDDL     DSQ                                   
047420,000204: 13,2513           00021                                    COSTH                                 
047421,000205: 13,2514           77615                           DAD                                            
047422,000206: 13,2515           75454                           BZE      SQRT                                  
047423,000207: 13,2516           26534                                    ARCTANXX                              #  ATAN=0/0  SET THETA=0
047424,000208: 13,2517           40065                           BDDV     BOV                                   
047425,000209: 13,2520           00023                                    SINTH                                 
047426,000210: 13,2521           26541                                    ATAN=90                               
047427,000211: 13,2522           67542                           SR1      ASIN                                  
047428,000212: 13,2523           00025                           STORE    THETA                                 
047429,000213: 13,2524           50125                           PDDL     BMN                                   
047430,000214: 13,2525           00021                                    COSTH                                 
047431,000215: 13,2526           26530                                    NEGCOS                                
047432,000216: 13,2527           43545                           DLOAD    RVQ                                   
047433,000217: 13,2530           57545        NEGCOS             DLOAD    DCOMP                                 
047434,000218: 13,2531           43244                           BPL      DAD                                   
047435,000219: 13,2532           26536                                    NEGOUT                                
047436,000220: 13,2533           24005                                    DP1/2                                 
047437,000221: 13,2534           00025        ARCTANXX           STORE    THETA                                 
047438,000222: 13,2535           77616                           RVQ                                            
047439,000223: 
047440,000224: 13,2536           52025        NEGOUT             DSU      GOTO                                  
047441,000225: 13,2537           24005                                    DP1/2                                 
047442,000226: 13,2540           26534                                    ARCTANXX                              
047443,000227: 13,2541           75345        ATAN=90            DLOAD    SIGN                                  
047444,000228: 13,2542           11003                                    LODP1/4                               
047445,000229: 13,2543           00023                                    SINTH                                 
047446,000230: 13,2544           00025                           STORE    THETA                                 
047447,000231: 13,2545           77616                           RVQ                                            
047448,000232: 
047449,000233: 13,2546  12,2006               2DZERO             =        DPZERO                                
047450,000234: 

Page 1132

047452,000236:                                                                                                  #  ..... SETGAMMA SUBROUTINE .....
047453,000237:                                                                                                  #  SUBROUTINE TO SET GAMMA FOR THE LAT-LONG AND LALOTORV SUBROUTINES
047454,000238: 
047455,000239:                                                                                                  #  GAMMA = B**2/A**2 FOR EARTH (B-1)
047456,000240:                                                                                                  #  GAMMA = 1 FOR MOON (B-1)
047457,000241: 
047458,000242:                                                                                                  #  CALLING SEQUENCE
047459,000243:                                                                                                  #        L       CALL
047460,000244:                                                                                                  #        L+1             SETGAMMA
047461,000245: 
047462,000246:                                                                                                  #  INPUT
047463,000247:                                                                                                  #        LUNAFLAG=0 FOR EARTH, =1 FOR MOON
047464,000248: 
047465,000249:                                                                                                  #  OUTPUT
047466,000250:                                                                                                  #        GAMMA IN GAMRP (B-1)
047467,000251: 
047468,000252: 13,2546           43145        SETGAMMA           DLOAD    BOFF                                  #  BRANCH FOR EARTH
047469,000253: 13,2547           26503                                    B2/A2                                 #  EARTH GAMMA
047470,000254: 13,2550           01743                                    LUNAFLAG                              
047471,000255: 13,2551           26554                                    SETGMEX                               
047472,000256: 13,2552           77735                           SLOAD                                          
047473,000257: 13,2553           24005                                    1B1                                   #  MOON GAMMA
047474,000258: 13,2554           00011        SETGMEX            STORE    GAMRP                                 
047475,000259: 13,2555           77616                           RVQ                                            
047476,000260: 13,2556                        GAMRP              =        8D                                    
047477,000261: 

Page 1133

047479,000263:                                                                                                  #  ..... SETRE SUBROUTINE .....
047480,000264:                                                                                                  #  SUBROUTINE TO SET RE (EARTH OR MOON RADIUS)
047481,000265: 
047482,000266:                                                                                                  #        RE = RM FOR MOON
047483,000267:                                                                                                  #        RE = RREF FOR FIXED EARTH RADIUS OR COMPUTED RF FOR FISCHER ELLIPSOID
047484,000268: 
047485,000269:                                                                                                  #  CALLING SEQUENCE
047486,000270:                                                                                                  #        L       CALL
047487,000271:                                                                                                  #        L+1             SETRE
047488,000272: 
047489,000273:                                                                                                  #  SUBROUTINES USED
047490,000274:                                                                                                  #        GETERAD
047491,000275: 
047492,000276:                                                                                                  #  INPUT
047493,000277:                                                                                                  #        ERADFLAG = 0 FOR FIXED RE, 1 FOR COMPUTED RE
047494,000278:                                                                                                  #        ALPHAV +4 = 1/2 SINL IF GETERAD IS CALLED
047495,000279:                                                                                                  #        LUNAFLAG = 0 FOR EARTH, =1 FOR MOON
047496,000280: 
047497,000281:                                                                                                  #  OUTPUT
047498,000282:                                                                                                  #        ERADM = 504RM FOR MOON (METERS B-29)
047499,000283:                                                                                                  #        ERADM = ERAD OR COMPUTED RF FOR EARTH (METERS B-29)
047500,000284: 
047501,000285: 13,2556           71220        SETRE              STQ      DLOAD                                 
047502,000286: 13,2557           00051                                    SETREX                                
047503,000287: 13,2560           10003                                    504RM                                 
047504,000288: 13,2561           71214                           BON      DLOAD                                 #  BRANCH FOR MOON
047505,000289: 13,2562           01703                                    LUNAFLAG                              
047506,000290: 13,2563           26573                                    TSTRLSRM                              
047507,000291: 13,2564           10001                                    ERAD                                  
047508,000292: 13,2565           45014                           BOFF     CALL                                  #  ERADFLAG=0 FOR FIXED RE, 1 FOR COMPUTED
047509,000293: 13,2566           00742                                    ERADFLAG                              
047510,000294: 13,2567           26571                                    SETRXX                                
047511,000295: 13,2570           26464                                    GETERAD                               
047512,000296: 13,2571           37673        SETRXX             STCALL   ERADM                                 #  EXIT WITH RE OR RM METERS B-29
047513,000297: 13,2572           00051                                    SETREX                                
047514,000298: 13,2573           77214        TSTRLSRM           BON      VLOAD                                 #  ERADFLAG=0, SET R0=RLS
047515,000299: 13,2574           00702                                    ERADFLAG                              #          =1      R0=RM
047516,000300: 13,2575           26571                                    SETRXX                                
047517,000301: 13,2576           02023                                    RLS                                   
047518,000302: 13,2577           64446                           ABVAL    SR2R                                  #  SCALE FROM B-27 TO B-29
047519,000303: 13,2600           77650                           GOTO                                           
047520,000304: 13,2601           26571                                    SETRXX                                
047521,000305: 13,2602  0000051               SETREX             =        S2                                    
047522,000306: 
047523,000307: 

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