Source Code

These source-code files derive from a printout of Luminary 210 (Apollo 15-17 Lunar Module guidance computer program), from the personal library of original AGC developer Don Eyles, digitally photographed at archive.org, financially sponsored by Jim Lawton, and transcribed to source code by a team of volunteers. This colorized, syntax-highlighted form was created by assembling that transcribed source code. Note that the full page images are available on the Virtual AGC project page at archive.org, while reduced-size images are presented at the VirtualAGC project website. Report or fix any transcription errors at the Virtual AGC project code repository.

Notations on the program listing read, in part:

	GAP: ASSEMBLE REVISION 210 OF AGC PROGRAM LUMINARY 
	BY NASA 2021112-161 17:11 MAR. 19,1971
Note that the date is the date of the printout, not the date of the program revision.

048552,000002:                                                                                                  ## Copyright:   Public domain.
048553,000003:                                                                                                  ## Filename:    LATITUDE_LONGITUDE_SUBROUTINES.agc
048554,000004:                                                                                                  ## Purpose:     A section of Luminary revision 210.
048555,000005:                                                                                                  ##              It is part of the source code for the Lunar Module's (LM)
048556,000006:                                                                                                  ##              Apollo Guidance Computer (AGC) for Apollo 15-17.
048557,000007:                                                                                                  ##              This file is intended to be a faithful transcription, except
048558,000008:                                                                                                  ##              that the code format has been changed to conform to the
048559,000009:                                                                                                  ##              requirements of the yaYUL assembler rather than the
048560,000010:                                                                                                  ##              original YUL assembler.
048561,000011:                                                                                                  ## Reference:   pp. 1131-1137
048562,000012:                                                                                                  ## Assembler:   yaYUL
048563,000013:                                                                                                  ## Contact:     Ron Burkey <info@sandroid.org>.
048564,000014:                                                                                                  ## Website:     www.ibiblio.org/apollo/index.html
048565,000015:                                                                                                  ## Mod history: 2016-11-17 JL   Created from Luminary131 version.
048566,000016:                                                                                                  ##              2016-12-12 MAS  Transcribed.
048567,000017:                                                                                                  ##              2016-12-26 RSB  Comment-text proofed using ProoferComments
048568,000018:                                                                                                  ##                              and corrected errors found.
048569,000019: 

Page 1131

048571,000021:                                                                                                  #  SUBROUTINE TO CONVERT RAD VECTOR AT GIVEN TIME TO LAT,LONG AND ALT
048572,000022: 
048573,000023:                                                                                                  #  CALLING SEQUENCE
048574,000024: 
048575,000025:                                                                                                  #    L-1    CALL
048576,000026:                                                                                                  #    L             LAT-LONG
048577,000027:                                                                                                  #  SUBROUTINES USED
048578,000028: 
048579,000029:                                                                                                  #   R-TO-RP,ARCTAN,SETGAMMA,SETRE
048580,000030:                                                                                                  #  ERASABLE INIT. REQ.
048581,000031: 
048582,000032:                                                                                                  #    AXO,-AYO,AZO,TEPHEM (SET AT LAUNCH TIME)
048583,000033:                                                                                                  #  ALPHAV = POSITION VECTOR METERS B-29
048584,000034:                                                                                                  #    MPAC-- TIME  (CSECS B-28)
048585,000035:                                                                                                  #   ERADFLAG =1, TO COMPUTE EARTH RADIUS, =0 FOR FIXED EARTH RADIUS
048586,000036:                                                                                                  #   LUNAFLAG=0 FOR EARTH,1 FOR MOON
048587,000037:                                                                                                  #  OUTPUT
048588,000038: 
048589,000039:                                                                                                  #    LATITUDE IN LAT   (REVS. B-0)
048590,000040:                                                                                                  #    LONGITUDE IN LONG   (REVS. B-0)
048591,000041:                                                                                                  #  ALTITUDE IN ALT METERS B-29
048592,000042: 30,3761                                           BANK     30                                    
048593,000043: 13,2000                                           SETLOC   LATLONG                               
048594,000044: 13,2000                                           BANK                                           
048595,000045: 
048596,000046: 13,2406                                           COUNT*   $$/LT-LG                              
048597,000047: 13,2406  E4,1431                                  EBANK=   ALPHAV                                
048598,000048: 13,2406           40220        LAT-LONG           STQ      SETPD                                 
048599,000049: 13,2407           03674                                    INCORPEX                              
048600,000050: 13,2410           00001                                    0D                                    
048601,000051: 13,2411           24007                           STOVL    6D                                    #  SAVE TIME IN 6-7D FOR R-TO-RP
048602,000052: 13,2412           02032                                    ALPHAV                                
048603,000053: 13,2413           51406                           PUSH     ABVAL                                 #  0-5D= R FOR R-TO-RP
048604,000054: 13,2414           16070                           STODL    ALPHAM                                #  ABS. VALUE OF R FOR ALT FORMULA BELOW
048605,000055: 13,2415           24007                                    ZEROVEC                               #  SET MPAC=0 FOR EARTH,NON-ZERO FOR MOON
048606,000056: 13,2416           71414                           BOFF     COS                                   #  USE COS(0) TO GET NON-ZERO IN MPAC
048607,000057: 13,2417           01743                                    LUNAFLAG                              #  0=EARTH,1=MOON
048608,000058: 13,2420           26421                                    CALLRTRP                              
048609,000059: 13,2421           77624        CALLRTRP           CALL                                           
048610,000060: 13,2422           51644                                    R-TO-RP                               #  RP VECTOR CONVERTED FROM R B-29
048611,000061: 13,2423           77656                           UNIT                                           #  UNIT RP B-1
048612,000062: 13,2424           36032                           STCALL   ALPHAV                                #  U2= 1/2 SINL FOR SETRE SUBR BELOW
048613,000063: 13,2425           26605                                    SETGAMMA                              #   SET GAMMA=B2/A2 FOR EARTH,=1 FOR MOON
048614,000064: 13,2426           77624                           CALL                                           #   SCALED B-1
048615,000065: 13,2427           26615                                    SETRE                                 #  CALC RE METERS B-29
048616,000066: 13,2430           63545                           DLOAD    DSQ                                   
048617,000067: 13,2431           02032                                    ALPHAV                                
048618,000068: 13,2432           63525                           PDDL     DSQ                                   
048619,000069: 13,2433           02034                                    ALPHAV     +2                         
048620,000070: 13,2434           75415                           DAD      SQRT                                  

Page 1132

048622,000072: 13,2435           76405                           DMP      SL1R                                  
048623,000073: 13,2436           00011                                    GAMRP                                 
048624,000074: 13,2437           14021                           STODL    COSTH                                 #  COS(LAT) B-1
048625,000075: 13,2440           02036                                    ALPHAV     +4                         
048626,000076: 13,2441           34023                           STCALL   SINTH                                 #  SIN(LAT) B-1
048627,000077: 13,2442           26545                                    ARCTAN                                
048628,000078: 13,2443           15120                           STODL    LAT                                   #  LAT B0
048629,000079: 13,2444           02032                                    ALPHAV                                
048630,000080: 13,2445           14021                           STODL    COSTH                                 #  COS(LONG) B-1
048631,000081: 13,2446           02034                                    ALPHAV     +2                         
048632,000082: 13,2447           34023                           STCALL   SINTH                                 #  SIN(LONG) B-1
048633,000083: 13,2450           26545                                    ARCTAN                                
048634,000084: 13,2451           15122                           STODL    LONG                                  #  LONG. REVS B-0 IN RANGE -1/2 TO 1/2
048635,000085: 13,2452           02070                                    ALPHAM                                
048636,000086: 13,2453           77625                           DSU                                            #  ALT= R-RE METERS B-29
048637,000087: 13,2454           03673                                    ERADM                                 
048638,000088: 13,2455           35124                           STCALL   ALT                                   #  EXIT WITH ALT METERS B-29
048639,000089: 13,2456           03674                                    INCORPEX                              

Page 1133

048641,000091:                                                                                                  #  SUBROUTINE TO CONVERT LAT,LONG,ALT AT GIVEN TIME TO RADIUS VECTOR
048642,000092:                                                                                                  #  CALLING SEQUENCE
048643,000093: 
048644,000094:                                                                                                  #    L-1    CALL
048645,000095:                                                                                                  #    L             LALOTORV
048646,000096:                                                                                                  #  SUBROUTINES USED
048647,000097: 
048648,000098:                                                                                                  #   SETGAMMA,SETRE,RP-TO-R
048649,000099:                                                                                                  #  ERASABLE INIT. REQ.
048650,000100: 
048651,000101:                                                                                                  #    AXO,AYO,AZO,TEPHEM  SET AT LAUNCH TIME
048652,000102:                                                                                                  #    LAT-- LATITUDE  (REVS B0)
048653,000103:                                                                                                  #    LONG-- LONGITUDE  (REVS B0)
048654,000104:                                                                                                  #  ALT--ALTITUDE (METERS) B-29
048655,000105:                                                                                                  #    MPAC-- TIME  (CSECS B-28)
048656,000106:                                                                                                  #    ERADFLAG =1 TO COMPUTE EARTH RADIUS, =0 FOR FIXED EARTH RADIUS
048657,000107:                                                                                                  #   LUNAFLAG=0 FOR EARTH,1 FOR MOON
048658,000108:                                                                                                  #  OUTPUT
048659,000109: 
048660,000110:                                                                                                  #  R-VECTOR IN ALPHAV (METERS B-29)
048661,000111: 13,2457           40220        LALOTORV           STQ      SETPD                                 #  LAT,LONG,ALT TO R VECTOR
048662,000112: 13,2460           03674                                    INCORPEX                              
048663,000113: 13,2461           00001                                    0D                                    
048664,000114: 13,2462           34007                           STCALL   6D                                    #  6-7D= TIME FOR RP-TO-R
048665,000115: 13,2463           26605                                    SETGAMMA                              #  GAMMA=B2/A2 FOR EARTH,1 FOR MOON B-1
048666,000116: 13,2464           73545                           DLOAD    SIN                                   #                COS(LONG)COS(LAT) IN MPAC
048667,000117: 13,2465           01120                                    LAT                                   #       UNIT RP= SIN(LONG)COS(LAT)    2-3D
048668,000118: 13,2466           65275                           DMPR     PDDL                                  #  PD 2          GAMMA*SIN(LAT)       0-1D
048669,000119: 13,2467           00011                                    GAMRP                                 
048670,000120: 13,2470           01120                                    LAT                                   #          0-1D= GAMMA*SIN(LAT) B-2
048671,000121: 13,2471           65346                           COS      PDDL                                  #  PD4      2-3D=COS(LAT) B-1 TEMPORARILY
048672,000122: 13,2472           01122                                    LONG                                  
048673,000123: 13,2473           57356                           SIN      DMPR                                  #  PD 2
048674,000124: 13,2474           71525                           PDDL     COS                                   #  PD 4    2-3D=SIN(LONG)COS(LAT) B-2
048675,000125: 13,2475           01120                                    LAT                                   
048676,000126: 13,2476           71525                           PDDL     COS                                   #  PD 6     4-5D=COS(LAT) B-1 TEMPORARILY
048677,000127: 13,2477           01122                                    LONG                                  
048678,000128: 13,2500           55475                           DMPR     VDEF                                  #  PD 4    MPAC= COS(LONG)COS(LAT) B-2
048679,000129: 13,2501           41456                           UNIT     PUSH                                  #  0-5D= UNIT RP FOR RP-TO-R SUBR.
048680,000130: 13,2502           36032                           STCALL   ALPHAV                                #  ALPHAV +4= SINL FOR SETRE SUBR.
048681,000131: 13,2503           26615                                    SETRE                                 #  RE METERS B-29
048682,000132: 13,2504           43145                           DLOAD    BOFF                                  #  SET MPAC=0 FOR EARTH,NON-ZERO FOR MOON
048683,000133: 13,2505           24007                                    ZEROVEC                               
048684,000134: 13,2506           01743                                    LUNAFLAG                              
048685,000135: 13,2507           26511                                    CALLRPRT                              
048686,000136: 13,2510           77746                           COS                                            #  USE COS(0) TO GET NON-ZERO IN MPAC
048687,000137: 13,2511           77624        CALLRPRT           CALL                                           
048688,000138: 13,2512           55716                                    RP-TO-R                               #  EXIT WITH UNIT R VECTOR IN MPAC
048689,000139: 13,2513           16032                           STODL    ALPHAV                                
048690,000140: 13,2514           03673                                    ERADM                                 

Page 1134

048692,000142: 13,2515           74215                           DAD      VXSC                                  #  (RE + ALT)(UNIT R) METERS B-30
048693,000143: 13,2516           01124                                    ALT                                   
048694,000144: 13,2517           02032                                    ALPHAV                                
048695,000145: 13,2520           77772                           VSL1                                           #  R METERS B-29
048696,000146: 13,2521           36032                           STCALL   ALPHAV                                #  EXIT WITH R IN METERS B-29
048697,000147: 13,2522           03674                                    INCORPEX                              
048698,000148:                                                                                                  #  SUBROUTINE TO COMPUTE EARTH RADIUS
048699,000149: 
048700,000150:                                                                                                  #  INPUT
048701,000151: 
048702,000152:                                                                                                  #    1/2 SIN LAT IN ALPHAV +4
048703,000153: 
048704,000154:                                                                                                  #  OUTPUT
048705,000155: 
048706,000156:                                                                                                  #    EARTH RADIUS IN ERADM AND MPAC  (METERS B-29)
048707,000157: 
048708,000158: 13,2523           63545        GETERAD            DLOAD    DSQ                                   
048709,000159: 13,2524           02036                                    ALPHAV     +4                         #  SIN**2(L)
048710,000160: 13,2525           44352                           SL1      BDSU                                  
048711,000161: 13,2526           24005                                    DP1/2                                 #  COS**2(L)
048712,000162: 13,2527           44275                           DMPR     BDSU                                  
048713,000163: 13,2530           26544                                    EE                                    
048714,000164: 13,2531           24005                                    DP1/2                                 
048715,000165: 13,2532           75465                           BDDV     SQRT                                  
048716,000166: 13,2533           26540                                    B2XSC                                 
048717,000167: 13,2534           77622                           SR4R                                           
048718,000168: 13,2535           03673                           STORE    ERADM                                 
048719,000169: 13,2536           77616                           RVQ                                            
048720,000170: 
048721,000171:                                                                                                  #  THE FOLLOWING CONSTANTS WERE COMPUTED WITH A=6378166,B=6356784 METERS
048722,000172:                                                                                                  #  B2XSC= B**2 SCALED B-51
048723,000173:                                                                                                  #  B2/A2= B**2/A**2 SCALED B-1
048724,000174:                                                                                                  #  EE=(1-B**2/A**2) SCALED B-0
048725,000175: 13,2537           00446 00305  B2XSC              2DEC     .0179450689                            #  B**2 SCALED B-51
048726,000176: 
048727,000177: 13,2541  12,2004               DP1/2              =        XUNIT                                 
048728,000178: 13,2541           17711 05254  B2/A2              2DEC     .9933064884 B-1                        #  GAMMA= B**2/A**2 B-1
048729,000179: 
048730,000180: 13,2543           00155 25250  EE                 2DEC     6.6935116  E-3                        #  (1-B**2/A**2) B-0
048731,000181: 

Page 1135

048733,000183:                                                                                                  #  ARCTAN SUBROUTINE
048734,000184: 
048735,000185: 
048736,000186:                                                                                                  #  CALLING SEQUENCE
048737,000187: 
048738,000188:                                                                                                  #    SIN THETA IN SINTH B-1
048739,000189:                                                                                                  #    COS THETA IN COSTH B-1
048740,000190:                                                                                                  #    CALL ARCTAN
048741,000191: 
048742,000192:                                                                                                  #  OUTPUT
048743,000193:                                                                                                  #     ARCTAN THETA IN MPAC AND THETA B-0 IN RANGE -1/2 TO +1/2
048744,000194: 
048745,000195: 
048746,000196: 13,2545           77600        ARCTAN             BOV                                            
048747,000197: 13,2546           26547                                    CLROVFLW                              
048748,000198: 13,2547           63545        CLROVFLW           DLOAD    DSQ                                   
048749,000199: 13,2550           00023                                    SINTH                                 
048750,000200: 13,2551           63525                           PDDL     DSQ                                   
048751,000201: 13,2552           00021                                    COSTH                                 
048752,000202: 13,2553           77615                           DAD                                            
048753,000203: 13,2554           75454                           BZE      SQRT                                  
048754,000204: 13,2555           26573                                    ARCTANXX                              #  ATAN=0/0  SET THETA=0
048755,000205: 13,2556           40065                           BDDV     BOV                                   
048756,000206: 13,2557           00023                                    SINTH                                 
048757,000207: 13,2560           26600                                    ATAN=90                               
048758,000208: 13,2561           67542                           SR1      ASIN                                  
048759,000209: 13,2562           00025                           STORE    THETA                                 
048760,000210: 13,2563           50125                           PDDL     BMN                                   
048761,000211: 13,2564           00021                                    COSTH                                 
048762,000212: 13,2565           26567                                    NEGCOS                                
048763,000213: 13,2566           43545                           DLOAD    RVQ                                   
048764,000214: 13,2567           57545        NEGCOS             DLOAD    DCOMP                                 
048765,000215: 13,2570           43244                           BPL      DAD                                   
048766,000216: 13,2571           26575                                    NEGOUT                                
048767,000217: 13,2572           24005                                    DP1/2                                 
048768,000218: 13,2573           00025        ARCTANXX           STORE    THETA                                 
048769,000219: 13,2574           77616                           RVQ                                            
048770,000220: 
048771,000221: 13,2575           52025        NEGOUT             DSU      GOTO                                  
048772,000222: 13,2576           24005                                    DP1/2                                 
048773,000223: 13,2577           26573                                    ARCTANXX                              
048774,000224: 13,2600           75345        ATAN=90            DLOAD    SIGN                                  
048775,000225: 13,2601           11040                                    LODP1/4                               
048776,000226: 13,2602           00023                                    SINTH                                 
048777,000227: 13,2603           00025                           STORE    THETA                                 
048778,000228: 13,2604           77616                           RVQ                                            
048779,000229: 
048780,000230: 13,2605  12,2006               2DZERO             =        DPZERO                                
048781,000231: 

Page 1136

048783,000233:                                                                                                  #  ..... SETGAMMA SUBROUTINE .....
048784,000234:                                                                                                  #  SUBROUTINE TO SET GAMMA FOR THE LAT-LONG AND LALOTORV SUBROUTINES
048785,000235: 
048786,000236:                                                                                                  #   GAMMA = B**2/A**2 FOR EARTH (B-1)
048787,000237:                                                                                                  #   GAMMA = 1 FOR MOON (B-1)
048788,000238: 
048789,000239:                                                                                                  #  CALLING SEQUENCE
048790,000240:                                                                                                  #   L       CALL
048791,000241:                                                                                                  #   L+1            SETGAMMA
048792,000242: 
048793,000243:                                                                                                  #  INPUT
048794,000244:                                                                                                  #   LUNAFLAG=0 FOR EARTH,=1 FOR MOON
048795,000245: 
048796,000246:                                                                                                  #  OUTPUT
048797,000247:                                                                                                  #   GAMMA IN GAMRP  (B-1)
048798,000248: 
048799,000249: 13,2605           43145        SETGAMMA           DLOAD    BOFF                                  #  BRANCH FOR EARTH
048800,000250: 13,2606           26542                                    B2/A2                                 #  EARTH GAMMA
048801,000251: 13,2607           01743                                    LUNAFLAG                              
048802,000252: 13,2610           26613                                    SETGMEX                               
048803,000253: 13,2611           77735                           SLOAD                                          
048804,000254: 13,2612           24005                                    1B1                                   #  MOON GAMMA
048805,000255: 13,2613           00011        SETGMEX            STORE    GAMRP                                 
048806,000256: 13,2614           77616                           RVQ                                            
048807,000257: 13,2615                        GAMRP              =        8D                                    
048808,000258: 

Page 1137

048810,000260:                                                                                                  #  .....SETRE SUBROUTINE .....
048811,000261:                                                                                                  #  SUBROUTINE TO SET RE (EARTH OR MOON RADIUS)
048812,000262: 
048813,000263:                                                                                                  #  RE= RM FOR MOON
048814,000264:                                                                                                  #   RE= RREF FOR FIXED EARTH RADIUS OR COMPUTED RF FOR FISCHER ELLIPSOID
048815,000265: 
048816,000266:                                                                                                  #  CALLING SEQUENCE
048817,000267:                                                                                                  #   L       CALL
048818,000268:                                                                                                  #   L+1            SETRE
048819,000269: 
048820,000270:                                                                                                  #  SUBROUTINES USED
048821,000271:                                                                                                  #   GETERAD
048822,000272: 
048823,000273:                                                                                                  #  INPUT
048824,000274:                                                                                                  #   ERADFLAG=0 FOR FIXED RE, 1 FOR COMPUTED RE
048825,000275:                                                                                                  #   ALPHAV +4= 1/2 SINL IF GETERAD IS CALLED
048826,000276:                                                                                                  #   LUNAFLAG=0 FOR EARTH,=1 FOR MOON
048827,000277: 
048828,000278:                                                                                                  #  OUTPUT
048829,000279:                                                                                                  #   ERADM= 504RM FOR MOON (METERS B-29)
048830,000280:                                                                                                  #   ERADM= ERAD OR COMPUTED RF FOR EARTH (METERS B-29)
048831,000281: 
048832,000282: 13,2615           71220        SETRE              STQ      DLOAD                                 
048833,000283: 13,2616           00051                                    SETREX                                
048834,000284: 13,2617           10003                                    504RM                                 
048835,000285: 13,2620           71214                           BON      DLOAD                                 #  BRANCH FOR MOON
048836,000286: 13,2621           01703                                    LUNAFLAG                              
048837,000287: 13,2622           26632                                    TSTRLSRM                              
048838,000288: 13,2623           10001                                    ERAD                                  
048839,000289: 13,2624           45014                           BOFF     CALL                                  #  ERADFLAG=0 FOR FIXED RE,1 FOR COMPUTED
048840,000290: 13,2625           00742                                    ERADFLAG                              
048841,000291: 13,2626           26630                                    SETRXX                                
048842,000292: 13,2627           26523                                    GETERAD                               
048843,000293: 13,2630           37673        SETRXX             STCALL   ERADM                                 #  EXIT WITH RE OR RM METERS B-29
048844,000294: 13,2631           00051                                    SETREX                                
048845,000295: 13,2632           77214        TSTRLSRM           BON      VLOAD                                 #  ERADFLAG=0,SET R0=RLS
048846,000296: 13,2633           00702                                    ERADFLAG                              #          =1     R0=RM
048847,000297: 13,2634           26630                                    SETRXX                                
048848,000298: 13,2635           02021                                    RLS                                   
048849,000299: 13,2636           64446                           ABVAL    SR2R                                  #  SCALE FROM B-27 TO B-29
048850,000300: 13,2637           77650                           GOTO                                           
048851,000301: 13,2640           26630                                    SETRXX                                
048852,000302: 13,2641  0000051               SETREX             =        S2                                    

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