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.

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

Page 1131

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

Page 1132

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

Page 1133

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

Page 1134

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

Page 1135

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

Page 1136

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

Page 1137

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

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