Source Code

These source-code files are part of a reconstructed copy of LM131 revision 1, the final release of the Apollo 13 Lunar Module (LM) Apollo Guidance Computer (AGC) software.

The source reconstruction began with source code of Luminary 131 previously transcribed from a digitized copy of that program. A dump of the flight spare core rope memory module B5, part number 2010802-171, serial number RAY 411, was obtained. This module is the only module different between Luminary 131 and LM131 revision 1. The dump was disassembled and all changes were incorporated into these source files. Note that page numbers in the reconstructed code match those on the Luminary 131 printout, although the changed code would likely have changed page numbers for a real LM131 revision 1 listing.

Comments from the original source code are prefixed with a single '#' symbol, whereas comments added later are prefixed by "##" or "###". Report any errors noted by creating an issue report at the Virtual AGC project's GitHub repository.

047128,000002:                                                                                                  ## Copyright:   Public domain.
047129,000003:                                                                                                  ## Filename:    LATITUDE_LONGITUDE_SUBROUTINES.agc
047130,000004:                                                                                                  ## Purpose:     A section of LM131 revision 1.
047131,000005:                                                                                                  ##              It is part of the reconstructed source code for the final
047132,000006:                                                                                                  ##              release of the flight software for the Lunar Module's (LM)
047133,000007:                                                                                                  ##              Apollo Guidance Computer (AGC) for Apollo 13. The code has
047134,000008:                                                                                                  ##              been reconstructed from a listing of Luminary 131 and a dump
047135,000009:                                                                                                  ##              of a core rope memory module B5, part number 2010802-171,
047136,000010:                                                                                                  ##              which is the only module different between LM131 revision 1
047137,000011:                                                                                                  ##              and Luminary 131. The executable generated from this source
047138,000012:                                                                                                  ##              has been verified against the module dump, so while the names,
047139,000013:                                                                                                  ##              comments, and ordering may not be exactly correct, the
047140,000014:                                                                                                  ##              resulting binary is.
047141,000015:                                                                                                  ## Reference:   pp. 1127-1133
047142,000016:                                                                                                  ## Assembler:   yaYUL
047143,000017:                                                                                                  ## Contact:     Ron Burkey <info@sandroid.org>.
047144,000018:                                                                                                  ## Website:     www.ibiblio.org/apollo/index.html
047145,000019:                                                                                                  ## Mod history: 2022-10-28 MAS  Created from Luminary 131.
047146,000020: 

Page 1127

047148,000022:                                                                                                  #  SUBROUTINE TO CONVERT RAD VECTOR AT GIVEN TIME TO LAT,LONG AND ALT
047149,000023: 
047150,000024:                                                                                                  #  CALLING SEQUENCE
047151,000025:                                                                                                  #        L-1     CALL
047152,000026:                                                                                                  #        L               LAT-LONG
047153,000027: 
047154,000028:                                                                                                  #  SUBROUTINES USED
047155,000029:                                                                                                  #        R-TO-RP, ARCTAN, SETGAMMA, SETRE
047156,000030: 
047157,000031:                                                                                                  #  ERASABLE INIT. REQ.
047158,000032:                                                                                                  #        AXO, -AYO, AZO, TEPHEM (SET AT LAUNCH TIME)
047159,000033:                                                                                                  #        ALPHAV = POSITION VECTOR METERS B-29
047160,000034:                                                                                                  #        MPAC -- TIME (CSECS B-28)
047161,000035:                                                                                                  #        ERADFLAG =1, TO COMPUTE EARTH RADIUS, =0 FOR FIXED EARTH RADIUS
047162,000036:                                                                                                  #        LUNAFLAG=0 FOR EARTH, 1 FOR MOON
047163,000037: 
047164,000038:                                                                                                  #  OUTPUT
047165,000039:                                                                                                  #        LATITUDE IN LAT         (REVS. B-0)
047166,000040:                                                                                                  #        LONGITUDE IN LONG       (REVS. B-0)
047167,000041:                                                                                                  #        ALTITUDE IN ALT METERS  B-29
047168,000042: 
047169,000043: 30,3766                                           BANK     30                                    
047170,000044: 13,2000                                           SETLOC   LATLONG                               
047171,000045: 13,2000                                           BANK                                           
047172,000046: 
047173,000047: 13,2347                                           COUNT*   $$/LT-LG                              
047174,000048: 13,2347  E4,1431                                  EBANK=   ALPHAV                                
047175,000049: 13,2347           40220        LAT-LONG           STQ      SETPD                                 
047176,000050: 13,2350           03674                                    INCORPEX                              
047177,000051: 13,2351           00001                                    0D                                    
047178,000052: 13,2352           24007                           STOVL    6D                                    #  SAVE TIME IN 6-7D FOR R-TO-RP
047179,000053: 13,2353           02032                                    ALPHAV                                
047180,000054: 13,2354           51406                           PUSH     ABVAL                                 #  0-5D= R FOR R-TO-RP
047181,000055: 13,2355           16070                           STODL    ALPHAM                                #  ABS. VALUE OF R FOR ALT FORMULA BELOW
047182,000056: 13,2356           24007                                    ZEROVEC                               #  SET MPAC=0 FOR EARTH, NON-ZERO FOR MOON
047183,000057: 13,2357           71414                           BOFF     COS                                   #  USE COS(0) TO GET NON-ZERO IN MPAC
047184,000058: 13,2360           01743                                    LUNAFLAG                              #  0=EARTH, 1=MOON
047185,000059: 13,2361           26362                                    CALLRTRP                              
047186,000060: 13,2362           77624        CALLRTRP           CALL                                           
047187,000061: 13,2363           51700                                    R-TO-RP                               #  RP VECTOR CONVERTED FROM R B-29
047188,000062: 13,2364           77656                           UNIT                                           #  UNIT RP B-1
047189,000063: 13,2365           36032                           STCALL   ALPHAV                                #  U2= 1/2 SINL FOR SETRE SUBR BELOW
047190,000064: 13,2366           26546                                    SETGAMMA                              #        SET GAMMA=B2/A2 FOR EARTH, =1 FOR MOON
047191,000065: 13,2367           77624                           CALL                                           #        SCALED B-1
047192,000066: 13,2370           26556                                    SETRE                                 #  CALC RE METERS B-29
047193,000067: 13,2371           63545                           DLOAD    DSQ                                   
047194,000068: 13,2372           02032                                    ALPHAV                                
047195,000069: 13,2373           63525                           PDDL     DSQ                                   
047196,000070: 13,2374           02034                                    ALPHAV     +2                         
047197,000071: 13,2375           75415                           DAD      SQRT                                  

Page 1128

047199,000073: 13,2376           76405                           DMP      SL1R                                  
047200,000074: 13,2377           00011                                    GAMRP                                 
047201,000075: 13,2400           14021                           STODL    COSTH                                 #  COS(LAT) B-1
047202,000076: 13,2401           02036                                    ALPHAV     +4                         
047203,000077: 13,2402           34023                           STCALL   SINTH                                 #  SIN(LAT) B-1
047204,000078: 13,2403           26506                                    ARCTAN                                
047205,000079: 13,2404           15120                           STODL    LAT                                   #  LAT B0
047206,000080: 13,2405           02032                                    ALPHAV                                
047207,000081: 13,2406           14021                           STODL    COSTH                                 #  COS(LONG) B-1
047208,000082: 13,2407           02034                                    ALPHAV     +2                         
047209,000083: 13,2410           34023                           STCALL   SINTH                                 #  SIN(LONG) B-1
047210,000084: 13,2411           26506                                    ARCTAN                                
047211,000085: 13,2412           15122                           STODL    LONG                                  #  LONG. REVS B-0 IN RANGE -1/2 TO 1/2
047212,000086: 13,2413           02070                                    ALPHAM                                
047213,000087: 13,2414           77625                           DSU                                            #  ALT= R-RE METERS B-29
047214,000088: 13,2415           03673                                    ERADM                                 
047215,000089: 13,2416           35124                           STCALL   ALT                                   #  EXIT WITH ALT METERS B-29
047216,000090: 13,2417           03674                                    INCORPEX                              

Page 1129

047218,000092:                                                                                                  #  SUBROUTINE TO CONVERT LAT,LONG,ALT AT GIVEN TIME TO RADIUS VECTOR
047219,000093: 
047220,000094:                                                                                                  #  CALLING SEQUENCE
047221,000095:                                                                                                  #        L-1     CALL
047222,000096:                                                                                                  #        L               LALOTORV
047223,000097: 
047224,000098:                                                                                                  #  SUBROUTINES USED
047225,000099:                                                                                                  #        SETGAMMA, SETRE, RP-TO-R
047226,000100: 
047227,000101:                                                                                                  #  ERASABLE INIT. REQ.
047228,000102:                                                                                                  #        AXO, AYO, AZO, TEPHEM SET AT LAUNCH TIME
047229,000103:                                                                                                  #        LAT -- LATITUDE         (REVS B0)
047230,000104:                                                                                                  #        LONG -- LONGITUDE       (REVS B0)
047231,000105:                                                                                                  #        ALT -- ALTITUDE         (METERS) B-29
047232,000106:                                                                                                  #        MPAC -- TIME            (CSECS B-28)
047233,000107:                                                                                                  #        ERADFLAG =1 TO COMPUTE EARTH RADIUS, =0 FOR FIXED EARTH RADIUS
047234,000108:                                                                                                  #        LUNAFLAG=0 FOR EARTH, 1 FOR MOON
047235,000109: 
047236,000110:                                                                                                  #  OUTPUT
047237,000111:                                                                                                  #        R-VECTOR IN ALPHAV      (METERS B-29)
047238,000112: 
047239,000113: 13,2420           40220        LALOTORV           STQ      SETPD                                 #  LAT,LONG,ALT TO R VECTOR
047240,000114: 13,2421           03674                                    INCORPEX                              
047241,000115: 13,2422           00001                                    0D                                    
047242,000116: 13,2423           34007                           STCALL   6D                                    #  6-7D= TIME FOR RP-TO-R
047243,000117: 13,2424           26546                                    SETGAMMA                              #  GAMMA=B2/A2 FOR EARTH, 1 FOR MOON B-1
047244,000118: 13,2425           73545                           DLOAD    SIN                                   #            COS(LONG)COS(LAT) IN MPAC
047245,000119: 13,2426           01120                                    LAT                                   #  UNIT RP = SIN(LONG)COS(LAT)    2-3D
047246,000120: 13,2427           65275                           DMPR     PDDL                                  #  PD 2      GAMMA*SIN(LAT)       0-1D
047247,000121: 13,2430           00011                                    GAMRP                                 
047248,000122: 13,2431           01120                                    LAT                                   #      0-1D= GAMMA*SIN(LAT) B-2
047249,000123: 13,2432           65346                           COS      PDDL                                  #  PD4 2-3D= COS(LAT) B-1 TEMPORARILY
047250,000124: 13,2433           01122                                    LONG                                  
047251,000125: 13,2434           57356                           SIN      DMPR                                  #  PD 2
047252,000126: 13,2435           71525                           PDDL     COS                                   #  PD 4 2-3D = SIN(LONG)COS(LAT) B-2
047253,000127: 13,2436           01120                                    LAT                                   
047254,000128: 13,2437           71525                           PDDL     COS                                   #  PD 6 4-5D = COS(LAT) B-1 TEMPORARILY
047255,000129: 13,2440           01122                                    LONG                                  
047256,000130: 13,2441           55475                           DMPR     VDEF                                  #  PD4 MPAC= COS(LONG)COS(LAT) B-2
047257,000131: 13,2442           41456                           UNIT     PUSH                                  #  0-5D= UNIT RP FOR RP-TO-R SUBR.
047258,000132: 13,2443           36032                           STCALL   ALPHAV                                #  ALPHAV +4= SINL FOR SETRE SUBR.
047259,000133: 13,2444           26556                                    SETRE                                 #  RE METERS B-29
047260,000134: 13,2445           43145                           DLOAD    BOFF                                  #  SET MPAC=0 FOR EARTH, NON-ZERO FOR MOON
047261,000135: 13,2446           24007                                    ZEROVEC                               
047262,000136: 13,2447           01743                                    LUNAFLAG                              
047263,000137: 13,2450           26452                                    CALLRPRT                              
047264,000138: 13,2451           77746                           COS                                            #  USE COS(0) TO GET NON-ZERO IN MPAC
047265,000139: 13,2452           77624        CALLRPRT           CALL                                           
047266,000140: 13,2453           55716                                    RP-TO-R                               #  EXIT WITH UNIT R VECTOR IN MPAC
047267,000141: 13,2454           16032                           STODL    ALPHAV                                
047268,000142: 13,2455           03673                                    ERADM                                 

Page 1130

047270,000144: 13,2456           74215                           DAD      VXSC                                  #  (RE + ALT)(UNIT R) METERS B-30
047271,000145: 13,2457           01124                                    ALT                                   
047272,000146: 13,2460           02032                                    ALPHAV                                
047273,000147: 13,2461           77772                           VSL1                                           #  R METERS B-29
047274,000148: 13,2462           36032                           STCALL   ALPHAV                                #  EXIT WITH R IN METERS B-29
047275,000149: 13,2463           03674                                    INCORPEX                              
047276,000150: 
047277,000151:                                                                                                  #  SUBROUTINE TO COMPUTE EARTH RADIUS
047278,000152: 
047279,000153:                                                                                                  #  INPUT
047280,000154:                                                                                                  #        1/2 SIN LAT IN ALPHAV +4
047281,000155: 
047282,000156:                                                                                                  #  OUTPUT
047283,000157:                                                                                                  #        EARTH RADIUS IN ERADM AND MPAC (METERS B-29)
047284,000158: 
047285,000159: 13,2464           63545        GETERAD            DLOAD    DSQ                                   
047286,000160: 13,2465           02036                                    ALPHAV     +4                         #  SIN**2(L)
047287,000161: 13,2466           44352                           SL1      BDSU                                  
047288,000162: 13,2467           24005                                    DP1/2                                 #  COS**2(L)
047289,000163: 13,2470           44275                           DMPR     BDSU                                  
047290,000164: 13,2471           26505                                    EE                                    
047291,000165: 13,2472           24005                                    DP1/2                                 
047292,000166: 13,2473           75465                           BDDV     SQRT                                  
047293,000167: 13,2474           26501                                    B2XSC                                 
047294,000168: 13,2475           77622                           SR4R                                           
047295,000169: 13,2476           03673                           STORE    ERADM                                 
047296,000170: 13,2477           77616                           RVQ                                            
047297,000171: 
047298,000172:                                                                                                  #  THE FOLLOWING CONSTANTS WERE COMPUTED WITH A=6378166, B=6356784 METERS
047299,000173:                                                                                                  #  B2XSC = B**2 SCALED B-51
047300,000174:                                                                                                  #  B2/A2 = B**2/A**2 SCALED B-1
047301,000175:                                                                                                  #  EE = (1-B**2/A**2) SCALED B-0
047302,000176: 
047303,000177: 13,2500           00446 00305  B2XSC              2DEC     .0179450689                            #  B**2 SCALED B-51
047304,000178: 13,2502  12,2004               DP1/2              =        XUNIT                                 
047305,000179: 13,2502           17711 05254  B2/A2              2DEC     .9933064884 B-1                        #  GAMMA= B**2/A**2 B-1
047306,000180: 13,2504           00155 25250  EE                 2DEC     6.6935116  E-3                        #  (1-B**2/A**2) B-0
047307,000181: 

Page 1131

047309,000183:                                                                                                  #  ARCTAN SUBROUTINE
047310,000184: 
047311,000185:                                                                                                  #  CALLING SEQUENCE
047312,000186:                                                                                                  #        SIN THETA IN SINTH B-1
047313,000187:                                                                                                  #        COS THETA IN COSTH B-1
047314,000188:                                                                                                  #        CALL ARCTAN
047315,000189: 
047316,000190:                                                                                                  #  OUTPUT
047317,000191:                                                                                                  #        ARCTAN THETA IN MPAC AND THETA B-0 IN RANGE -1/2 TO +1/2
047318,000192: 
047319,000193: 13,2506           77600        ARCTAN             BOV                                            
047320,000194: 13,2507           26510                                    CLROVFLW                              
047321,000195: 13,2510           63545        CLROVFLW           DLOAD    DSQ                                   
047322,000196: 13,2511           00023                                    SINTH                                 
047323,000197: 13,2512           63525                           PDDL     DSQ                                   
047324,000198: 13,2513           00021                                    COSTH                                 
047325,000199: 13,2514           77615                           DAD                                            
047326,000200: 13,2515           75454                           BZE      SQRT                                  
047327,000201: 13,2516           26534                                    ARCTANXX                              #  ATAN=0/0  SET THETA=0
047328,000202: 13,2517           40065                           BDDV     BOV                                   
047329,000203: 13,2520           00023                                    SINTH                                 
047330,000204: 13,2521           26541                                    ATAN=90                               
047331,000205: 13,2522           67542                           SR1      ASIN                                  
047332,000206: 13,2523           00025                           STORE    THETA                                 
047333,000207: 13,2524           50125                           PDDL     BMN                                   
047334,000208: 13,2525           00021                                    COSTH                                 
047335,000209: 13,2526           26530                                    NEGCOS                                
047336,000210: 13,2527           43545                           DLOAD    RVQ                                   
047337,000211: 13,2530           57545        NEGCOS             DLOAD    DCOMP                                 
047338,000212: 13,2531           43244                           BPL      DAD                                   
047339,000213: 13,2532           26536                                    NEGOUT                                
047340,000214: 13,2533           24005                                    DP1/2                                 
047341,000215: 13,2534           00025        ARCTANXX           STORE    THETA                                 
047342,000216: 13,2535           77616                           RVQ                                            
047343,000217: 
047344,000218: 13,2536           52025        NEGOUT             DSU      GOTO                                  
047345,000219: 13,2537           24005                                    DP1/2                                 
047346,000220: 13,2540           26534                                    ARCTANXX                              
047347,000221: 13,2541           75345        ATAN=90            DLOAD    SIGN                                  
047348,000222: 13,2542           11003                                    LODP1/4                               
047349,000223: 13,2543           00023                                    SINTH                                 
047350,000224: 13,2544           00025                           STORE    THETA                                 
047351,000225: 13,2545           77616                           RVQ                                            
047352,000226: 
047353,000227: 13,2546  12,2006               2DZERO             =        DPZERO                                
047354,000228: 

Page 1132

047356,000230:                                                                                                  #  ..... SETGAMMA SUBROUTINE .....
047357,000231:                                                                                                  #  SUBROUTINE TO SET GAMMA FOR THE LAT-LONG AND LALOTORV SUBROUTINES
047358,000232: 
047359,000233:                                                                                                  #  GAMMA = B**2/A**2 FOR EARTH (B-1)
047360,000234:                                                                                                  #  GAMMA = 1 FOR MOON (B-1)
047361,000235: 
047362,000236:                                                                                                  #  CALLING SEQUENCE
047363,000237:                                                                                                  #        L       CALL
047364,000238:                                                                                                  #        L+1             SETGAMMA
047365,000239: 
047366,000240:                                                                                                  #  INPUT
047367,000241:                                                                                                  #        LUNAFLAG=0 FOR EARTH, =1 FOR MOON
047368,000242: 
047369,000243:                                                                                                  #  OUTPUT
047370,000244:                                                                                                  #        GAMMA IN GAMRP (B-1)
047371,000245: 
047372,000246: 13,2546           43145        SETGAMMA           DLOAD    BOFF                                  #  BRANCH FOR EARTH
047373,000247: 13,2547           26503                                    B2/A2                                 #  EARTH GAMMA
047374,000248: 13,2550           01743                                    LUNAFLAG                              
047375,000249: 13,2551           26554                                    SETGMEX                               
047376,000250: 13,2552           77735                           SLOAD                                          
047377,000251: 13,2553           24005                                    1B1                                   #  MOON GAMMA
047378,000252: 13,2554           00011        SETGMEX            STORE    GAMRP                                 
047379,000253: 13,2555           77616                           RVQ                                            
047380,000254: 13,2556                        GAMRP              =        8D                                    
047381,000255: 

Page 1133

047383,000257:                                                                                                  #  ..... SETRE SUBROUTINE .....
047384,000258:                                                                                                  #  SUBROUTINE TO SET RE (EARTH OR MOON RADIUS)
047385,000259: 
047386,000260:                                                                                                  #        RE = RM FOR MOON
047387,000261:                                                                                                  #        RE = RREF FOR FIXED EARTH RADIUS OR COMPUTED RF FOR FISCHER ELLIPSOID
047388,000262: 
047389,000263:                                                                                                  #  CALLING SEQUENCE
047390,000264:                                                                                                  #        L       CALL
047391,000265:                                                                                                  #        L+1             SETRE
047392,000266: 
047393,000267:                                                                                                  #  SUBROUTINES USED
047394,000268:                                                                                                  #        GETERAD
047395,000269: 
047396,000270:                                                                                                  #  INPUT
047397,000271:                                                                                                  #        ERADFLAG = 0 FOR FIXED RE, 1 FOR COMPUTED RE
047398,000272:                                                                                                  #        ALPHAV +4 = 1/2 SINL IF GETERAD IS CALLED
047399,000273:                                                                                                  #        LUNAFLAG = 0 FOR EARTH, =1 FOR MOON
047400,000274: 
047401,000275:                                                                                                  #  OUTPUT
047402,000276:                                                                                                  #        ERADM = 504RM FOR MOON (METERS B-29)
047403,000277:                                                                                                  #        ERADM = ERAD OR COMPUTED RF FOR EARTH (METERS B-29)
047404,000278: 
047405,000279: 13,2556           71220        SETRE              STQ      DLOAD                                 
047406,000280: 13,2557           00051                                    SETREX                                
047407,000281: 13,2560           10003                                    504RM                                 
047408,000282: 13,2561           71214                           BON      DLOAD                                 #  BRANCH FOR MOON
047409,000283: 13,2562           01703                                    LUNAFLAG                              
047410,000284: 13,2563           26573                                    TSTRLSRM                              
047411,000285: 13,2564           10001                                    ERAD                                  
047412,000286: 13,2565           45014                           BOFF     CALL                                  #  ERADFLAG=0 FOR FIXED RE, 1 FOR COMPUTED
047413,000287: 13,2566           00742                                    ERADFLAG                              
047414,000288: 13,2567           26571                                    SETRXX                                
047415,000289: 13,2570           26464                                    GETERAD                               
047416,000290: 13,2571           37673        SETRXX             STCALL   ERADM                                 #  EXIT WITH RE OR RM METERS B-29
047417,000291: 13,2572           00051                                    SETREX                                
047418,000292: 13,2573           77214        TSTRLSRM           BON      VLOAD                                 #  ERADFLAG=0, SET R0=RLS
047419,000293: 13,2574           00702                                    ERADFLAG                              #          =1      R0=RM
047420,000294: 13,2575           26571                                    SETRXX                                
047421,000295: 13,2576           02023                                    RLS                                   
047422,000296: 13,2577           64446                           ABVAL    SR2R                                  #  SCALE FROM B-27 TO B-29
047423,000297: 13,2600           77650                           GOTO                                           
047424,000298: 13,2601           26571                                    SETRXX                                
047425,000299: 13,2602  0000051               SETREX             =        S2                                    
047426,000300: 
047427,000301: 

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