Source Code

These source code files are a reconstruction of Sundance, the Apollo 9 LM (Lunar Module) AGC (Apollo Guidance Computer) flight software, created from binary dumps of original core rope program modules, as follows:
  • B1 — Revision 292
  • B2 — Revision 302
  • B3 — Revision 302
  • B4 — Revision 302
  • B5 — Revision 292
  • B6 — Revision 306
This means that source code does not represent a specific historical revision of Sundance, but rather a mixture of the three released versions. Nonetheless, it is capable of flying the whole Apollo 9 mission. This source code matches the binary dumps, as closely as feasible, but 100% match is not possible, due mostly to changes in memory addresses at which code and variables were allocated in different revisions of Sundance. Refer to this list of explanations for each binary mismatch.

Since only binary dumps (rather than listings) of Sundance are available as source material, all comments and labels are approximate. They have been taken from other AGC programs where possible, or, in some places, written from scratch to match what we believe would have been in the original listing.

043476,000002:                                                                                                  ## Copyright:   Public domain.
043477,000003:                                                                                                  ## Filename:    LATITUDE_LONGITUDE_SUBROUTINES.agc
043478,000004:                                                                                                  ## Purpose:     A section of a reconstructed, mixed version of Sundance
043479,000005:                                                                                                  ##              It is part of the reconstructed source code for the Lunar
043480,000006:                                                                                                  ##              Module's (LM) Apollo Guidance Computer (AGC) for Apollo 9.
043481,000007:                                                                                                  ##              No original listings of this program are available;
043482,000008:                                                                                                  ##              instead, this file was created via disassembly of dumps
043483,000009:                                                                                                  ##              of various revisions of Sundance core rope modules.
043484,000010:                                                                                                  ## Assembler:   yaYUL
043485,000011:                                                                                                  ## Contact:     Ron Burkey <info@sandroid.org>.
043486,000012:                                                                                                  ## Website:     www.ibiblio.org/apollo/index.html
043487,000013:                                                                                                  ## Mod history: 2020-06-17 MAS  Created from Luminary 69.
043488,000014: 
043489,000015:                                                                                                  ## Sundance 302
043490,000016: 
043491,000017:                                                                                                  #  SUBROUTINE TO CONVERT RAD VECTOR AT GIVEN TIME TO LAT,LONG AND ALT
043492,000018: 
043493,000019:                                                                                                  #  CALLING SEQUENCE
043494,000020:                                                                                                  #        L-1     CALL
043495,000021:                                                                                                  #        L               LAT-LONG
043496,000022: 
043497,000023:                                                                                                  #  SUBROUTINES USED
043498,000024:                                                                                                  #        R-TO-RP,ARCTAN,SETGAMMA,SETRE
043499,000025: 
043500,000026:                                                                                                  #  ERASABLE INIT. REQ.
043501,000027:                                                                                                  #        AXO,-AYO,AZO,TEPHEM (SET AT LAUNCH TIME)
043502,000028:                                                                                                  #        ALPHAV = POSITION VECTOR METERS B-29
043503,000029:                                                                                                  #        MPAC-- TIME (CSECS B-28)
043504,000030:                                                                                                  #        ERADFLAG =1, TO COMPUTE EARTH RADIUS, =0 FOR FIXED EARTH RADIUS
043505,000031:                                                                                                  #        LUNAFLAG=0 FOR EARTH, 1 FOR MOON
043506,000032: 
043507,000033:                                                                                                  #  OUTPUT
043508,000034:                                                                                                  #        LATITUDE IN LAT         (REVS. B-0)
043509,000035:                                                                                                  #        LONGITUDE IN LONG       (REVS. B-0)
043510,000036:                                                                                                  #        ALTITUDE IN ALT         METERS B-29
043511,000037: 
043512,000038: 30,3645                                           BANK     30                                    
043513,000039: 13,2000                                           SETLOC   LATLONG                               
043514,000040: 13,2000                                           BANK                                           
043515,000041: 
043516,000042: 13,2323                                           COUNT*   $$/LT-LG                              
043517,000043: 13,2323  E4,1433                                  EBANK=   ALPHAV                                
043518,000044: 13,2323           40220        LAT-LONG           STQ      SETPD                                 
043519,000045: 13,2324           03661                                    INCORPEX                              
043520,000046: 13,2325           00001                                    0D                                    
043521,000047: 13,2326           24007                           STOVL    6D                                    #  SAVE TIME IN 6-7D FOR R-TO-RP
043522,000048: 13,2327           02034                                    ALPHAV                                
043523,000049: 13,2330           51406                           PUSH     ABVAL                                 #  0-5D= R FOR R-TO-RP
043524,000050: 13,2331           16072                           STODL    ALPHAM                                #  ABS. VALUE OF R FOR ALT FORMULA BELOW
043525,000051: 13,2332           22276                                    ZEROVEC                               #  SET MPAC=0 FOR EARTH, NON-ZERO FOR MOON
043526,000052: 13,2333           71414                           BOFF     COS                                   #  USE COS(0) TO GET NON-ZERO IN MPAC
043527,000053: 13,2334           01743                                    LUNAFLAG                              #  0=EARTH, 1=MOON
043528,000054: 13,2335           26336                                    CALLRTRP                              
043529,000055: 13,2336           77624        CALLRTRP           CALL                                           
043530,000056: 13,2337           51245                                    R-TO-RP                               #  RP VECTOR CONVERTED FROM R B-29
043531,000057: 13,2340           77656                           UNIT                                           #  UNIT RP B-1
043532,000058: 13,2341           36034                           STCALL   ALPHAV                                #  U2= 1/2 SINL FOR SETRE SUBR BELOW
043533,000059: 13,2342           26524                                    SETGAMMA                              #        SET GAMMA=B2/A2 FOR EARTH,=1 FOR MOON
043534,000060: 13,2343           77624                           CALL                                           #        SCALED B-1
043535,000061: 13,2344           26534                                    SETRE                                 #  CALC RE METERS B-29
043536,000062: 13,2345           63545                           DLOAD    DSQ                                   
043537,000063: 13,2346           02034                                    ALPHAV                                
043538,000064: 13,2347           63525                           PDDL     DSQ                                   
043539,000065: 13,2350           02036                                    ALPHAV     +2                         
043540,000066: 13,2351           75415                           DAD      SQRT                                  
043541,000067: 13,2352           76405                           DMP      SL1R                                  
043542,000068: 13,2353           00011                                    GAMRP                                 
043543,000069: 13,2354           14021                           STODL    COSTH                                 #  COS(LAT) B-1
043544,000070: 13,2355           02040                                    ALPHAV     +4                         
043545,000071: 13,2356           34023                           STCALL   SINTH                                 #  SIN(LAT) B-1
043546,000072: 13,2357           26464                                    ARCTAN                                
043547,000073: 13,2360           15124                           STODL    LAT                                   #  LAT B0
043548,000074: 13,2361           02034                                    ALPHAV                                
043549,000075: 13,2362           14021                           STODL    COSTH                                 #  COS(LONG) B-1
043550,000076: 13,2363           02036                                    ALPHAV     +2                         
043551,000077: 13,2364           34023                           STCALL   SINTH                                 #  SIN(LONG) B-1
043552,000078: 13,2365           26464                                    ARCTAN                                
043553,000079: 13,2366           15126                           STODL    LONG                                  #  LONG. REVS B-0 IN RANGE -1/2 TO 1/2
043554,000080: 13,2367           02072                                    ALPHAM                                
043555,000081: 13,2370           77625                           DSU                                            #  ALT= R-RE METERS B-29
043556,000082: 13,2371           03660                                    ERADM                                 
043557,000083: 13,2372           35130                           STCALL   ALT                                   #  EXIT WITH ALT METERS B-29
043558,000084: 13,2373           03661                                    INCORPEX                              
043559,000085:                                                                                                  #  SUBROUTINE TO CONVERT LAT,LONG,ALT AT GIVEN TIME TO RADIUS VECTOR
043560,000086: 
043561,000087:                                                                                                  #  CALLING SEQUENCE
043562,000088:                                                                                                  #        L-1     CALL
043563,000089:                                                                                                  #        L               LALOTORV
043564,000090: 
043565,000091:                                                                                                  #  SUBROUTINES USED
043566,000092:                                                                                                  #        SETGAMMA,SETRE,RP-TO-R
043567,000093: 
043568,000094:                                                                                                  #  ERASABLE INIT. REQ.
043569,000095:                                                                                                  #        AXO,AYO,AZO,TEPHEM SET AT LAUNCH TIME
043570,000096:                                                                                                  #        LAT-- LATITUDE  (REVS B0)
043571,000097:                                                                                                  #        LONG-- LONGITUDE        (REVS B0)
043572,000098:                                                                                                  #        ALT--ALTITUDE           (METERS) B-29
043573,000099:                                                                                                  #        MPAC-- TIME             (CSECS B-28)
043574,000100:                                                                                                  #        ERADFLAG =1 TO COMPUTE EARTH RADIUS, =0 FOR FIXED EARTH RADIUS
043575,000101:                                                                                                  #        LUNAFLAG=0 FOR EARTH, 1 FOR MOON
043576,000102: 
043577,000103:                                                                                                  #  OUTPUT
043578,000104:                                                                                                  #        R-VECTOR IN ALPHAV      (METERS B-29)
043579,000105: 
043580,000106: 13,2374           40220        LALOTORV           STQ      SETPD                                 #  LAT,LONG,ALT TO R VECTOR
043581,000107: 13,2375           03661                                    INCORPEX                              
043582,000108: 13,2376           00001                                    0D                                    
043583,000109: 13,2377           34007                           STCALL   6D                                    #  6-7D= TIME FOR RP-TO-R
043584,000110: 13,2400           26524                                    SETGAMMA                              #  GAMMA=B2/A2 FOR EARTH,1 FOR MOON B-1
043585,000111: 13,2401           73545                           DLOAD    SIN                                   #                COS(LONG)COS(LAT) IN MPAC
043586,000112: 13,2402           01124                                    LAT                                   #      UNIT RP=  SIN(LONG)COS(LAT)    2-3D
043587,000113: 13,2403           65275                           DMPR     PDDL                                  #  PD 2          GAMMA*SIN(LAT)       0-1D
043588,000114: 13,2404           00011                                    GAMRP                                 
043589,000115: 13,2405           01124                                    LAT                                   #         0-1D=  GAMMA*SIN(LAT) B-2
043590,000116: 13,2406           65346                           COS      PDDL                                  #  PD 4     2-3D=COS(LAT) B-1 TEMPORARILY
043591,000117: 13,2407           01126                                    LONG                                  
043592,000118: 13,2410           57356                           SIN      DMPR                                  #  PD 2
043593,000119: 13,2411           71525                           PDDL     COS                                   #  PD 4   2-3D=SIN(LONG)COS(LAT) B-2
043594,000120: 13,2412           01124                                    LAT                                   
043595,000121: 13,2413           71525                           PDDL     COS                                   #  PD 6   4-5D=COS(LAT) B-1 TEMPORARILY
043596,000122: 13,2414           01126                                    LONG                                  
043597,000123: 13,2415           55475                           DMPR     VDEF                                  #  PD 4   MPAC=  COS(LONG)COS(LAT) B-2
043598,000124: 13,2416           41456                           UNIT     PUSH                                  #  0-5D= UNIT RP FOR RP-TO-R SUBR.
043599,000125: 13,2417           36034                           STCALL   ALPHAV                                #  ALPHAV +4= SINL FOR SETRE SUBR.
043600,000126: 13,2420           26534                                    SETRE                                 #  RE METERS B-29
043601,000127: 13,2421           43145                           DLOAD    BOFF                                  #  SET MPAC=0 FOR EARTH, NON-ZERO FOR MOON
043602,000128: 13,2422           22276                                    ZEROVEC                               
043603,000129: 13,2423           01743                                    LUNAFLAG                              
043604,000130: 13,2424           26426                                    CALLRPRT                              
043605,000131: 13,2425           77746                           COS                                            #  USE COS(0) TO GET NON-ZERO IN MPAC
043606,000132: 13,2426           77624        CALLRPRT           CALL                                           
043607,000133: 13,2427           51220                                    RP-TO-R                               #  EXIT WITH UNIT R VECTOR IN MPAC
043608,000134: 13,2430           16034                           STODL    ALPHAV                                
043609,000135: 13,2431           03660                                    ERADM                                 
043610,000136: 13,2432           74215                           DAD      VXSC                                  #  (RE + ALT)(UNIT R) METERS B-30
043611,000137: 13,2433           01130                                    ALT                                   
043612,000138: 13,2434           02034                                    ALPHAV                                
043613,000139: 13,2435           77772                           VSL1                                           #  R METERS B-29
043614,000140: 13,2436           36034                           STCALL   ALPHAV                                #  EXIT WITH R IN METERS B-29
043615,000141: 13,2437           03661                                    INCORPEX                              
043616,000142: 
043617,000143:                                                                                                  #  SUBROUTINE TO COMPUTE EARTH RADIUS
043618,000144: 
043619,000145:                                                                                                  #  INPUT
043620,000146:                                                                                                  #        1/2 SIN LAT IN ALPHAV +4
043621,000147: 
043622,000148:                                                                                                  #  OUTPUT
043623,000149:                                                                                                  #        EARTH RADIUS IN ERADM AND MPAC (METERS B-29)
043624,000150: 
043625,000151: 13,2440           63545        GETERAD            DLOAD    DSQ                                   
043626,000152: 13,2441           02040                                    ALPHAV     +4                         #  SIN**2(L)
043627,000153: 13,2442           44352                           SL1      BDSU                                  
043628,000154: 13,2443           22274                                    DP1/2                                 #  COS**2(L)
043629,000155: 13,2444           44275                           DMPR     BDSU                                  
043630,000156: 13,2445           26461                                    EE                                    
043631,000157: 13,2446           22274                                    DP1/2                                 
043632,000158: 13,2447           75465                           BDDV     SQRT                                  
043633,000159: 13,2450           26455                                    B2XSC                                 
043634,000160: 13,2451           77622                           SR4R                                           
043635,000161: 13,2452           03660                           STORE    ERADM                                 
043636,000162: 13,2453           77616                           RVQ                                            
043637,000163: 
043638,000164:                                                                                                  #  THE FOLLOWING CONSTANTS WERE COMPUTED WITH A=6378166, B=6356784 METERS
043639,000165:                                                                                                  #  B2XSC= B**2 SCALED B-51
043640,000166:                                                                                                  #  B2/A2= B**2/A**2 SCALED B-1
043641,000167:                                                                                                  #  EE=(1-B**2/A**2) SCALED B-0
043642,000168: 
043643,000169: 13,2454           00446 00305  B2XSC              2DEC     .0179450689                            #  B**2 SCALED B-51
043644,000170: 13,2456  11,2273               DP1/2              =        XUNIT                                 
043645,000171: 13,2456           17711 05254  B2/A2              2DEC     .9933064884 B-1                        #  GAMMA= B**2/A**2 B-1
043646,000172: 13,2460           00155 25250  EE                 2DEC     6.6935116  E-3                        #  (1-B**2/A**2) B-0
043647,000173: 13,2462           00302 17755  ERAD               2DEC     6373338    B-29                       #  PAD RADIUS
043648,000174: 
043649,000175:                                                                                                  #  ARCTAN SUBROUTINE
043650,000176: 
043651,000177:                                                                                                  #  CALLING SEQUENCE
043652,000178:                                                                                                  #        SIN THETA IN SINTH B-1
043653,000179:                                                                                                  #        COS THETA IN COSTH B-1
043654,000180:                                                                                                  #        CALL ARCTAN
043655,000181: 
043656,000182:                                                                                                  #  OUTPUT
043657,000183:                                                                                                  #        ARCTAN THETA IN MPAC AND THETA B-0 IN RANGE -1/2 TO +1/2
043658,000184: 
043659,000185: 13,2464           77600        ARCTAN             BOV                                            
043660,000186: 13,2465           26466                                    CLROVFLW                              
043661,000187: 13,2466           63545        CLROVFLW           DLOAD    DSQ                                   
043662,000188: 13,2467           00023                                    SINTH                                 
043663,000189: 13,2470           63525                           PDDL     DSQ                                   
043664,000190: 13,2471           00021                                    COSTH                                 
043665,000191: 13,2472           77615                           DAD                                            
043666,000192: 13,2473           75454                           BZE      SQRT                                  
043667,000193: 13,2474           26512                                    ARCTANXX                              #  ATAN=0/0  SET THETA=0
043668,000194: 13,2475           40065                           BDDV     BOV                                   
043669,000195: 13,2476           00023                                    SINTH                                 
043670,000196: 13,2477           26517                                    ATAN=90                               
043671,000197: 13,2500           67542                           SR1      ASIN                                  
043672,000198: 13,2501           00025                           STORE    THETA                                 
043673,000199: 13,2502           50125                           PDDL     BMN                                   
043674,000200: 13,2503           00021                                    COSTH                                 
043675,000201: 13,2504           26506                                    NEGCOS                                
043676,000202: 13,2505           43545                           DLOAD    RVQ                                   
043677,000203: 13,2506           57545        NEGCOS             DLOAD    DCOMP                                 
043678,000204: 13,2507           43244                           BPL      DAD                                   
043679,000205: 13,2510           26514                                    NEGOUT                                
043680,000206: 13,2511           22274                                    DP1/2                                 
043681,000207: 13,2512           00025        ARCTANXX           STORE    THETA                                 
043682,000208: 13,2513           77616                           RVQ                                            
043683,000209: 
043684,000210: 13,2514           52025        NEGOUT             DSU      GOTO                                  
043685,000211: 13,2515           22274                                    DP1/2                                 
043686,000212: 13,2516           26512                                    ARCTANXX                              
043687,000213: 13,2517           75345        ATAN=90            DLOAD    SIGN                                  
043688,000214: 13,2520           10673                                    LODP1/4                               
043689,000215: 13,2521           00023                                    SINTH                                 
043690,000216: 13,2522           00025                           STORE    THETA                                 
043691,000217: 13,2523           77616                           RVQ                                            
043692,000218: 
043693,000219: 13,2524  11,2275               2DZERO             =        DPZERO                                
043694,000220: 
043695,000221:                                                                                                  #  ..... SETGAMMA SUBROUTINE .....
043696,000222:                                                                                                  #  SUBROUTINE TO SET GAMMA FOR THE LAT-LONG AND LALOTORV SUBROUTINES
043697,000223: 
043698,000224:                                                                                                  #  GAMMA = B**2/A**2 FOR EARTH (B-1)
043699,000225:                                                                                                  #  GAMMA = 1 FOR MOON (B-1)
043700,000226: 
043701,000227:                                                                                                  #  CALLING SEQUENCE
043702,000228:                                                                                                  #        L       CALL
043703,000229:                                                                                                  #        L+1             SETGAMMA
043704,000230: 
043705,000231:                                                                                                  #  INPUT
043706,000232:                                                                                                  #        LUNAFLAG=0 FOR EARTH,=1 FOR MOON
043707,000233: 
043708,000234:                                                                                                  #  OUTPUT
043709,000235:                                                                                                  #        GAMMA IN GAMRP (B-1)
043710,000236: 
043711,000237: 13,2524           43145        SETGAMMA           DLOAD    BOFF                                  #  BRANCH FOR EARTH
043712,000238: 13,2525           26457                                    B2/A2                                 #  EARTH GAMMA
043713,000239: 13,2526           01743                                    LUNAFLAG                              
043714,000240: 13,2527           26532                                    SETGMEX                               
043715,000241: 13,2530           77735                           SLOAD                                          
043716,000242: 13,2531           22274                                    1B1                                   #  MOON GAMMA
043717,000243: 13,2532           00011        SETGMEX            STORE    GAMRP                                 
043718,000244: 13,2533           77616                           RVQ                                            
043719,000245: 13,2534                        GAMRP              =        8D                                    
043720,000246: 
043721,000247:                                                                                                  #  ..... SETRE SUBROUTINE .....
043722,000248:                                                                                                  #  SUBROUTINE TO SET RE (EARTH OR MOON RADIUS)
043723,000249: 
043724,000250:                                                                                                  #        RE= RM FOR MOON
043725,000251:                                                                                                  #                RE= RREF FOR FIXED EARTH RADIUS OR COMPUTED RF FOR FISCHER ELLIPSOID
043726,000252: 
043727,000253:                                                                                                  #  CALLING SEQUENCE
043728,000254:                                                                                                  #        L       CALL
043729,000255:                                                                                                  #        L+1             SETRE
043730,000256: 
043731,000257:                                                                                                  #  SUBROUTINES USED
043732,000258:                                                                                                  #        GETERAD
043733,000259: 
043734,000260:                                                                                                  #  INPUT
043735,000261:                                                                                                  #        ERADFLAG=0 FOR FIXED RE, 1 FOR COMPUTED RE
043736,000262:                                                                                                  #        ALPHAV +4= 1/2 SINL IF GETERAD IS CALLED
043737,000263:                                                                                                  #        LUNAFLAG=0 FOR EARTH,=1 FOR MOON
043738,000264: 
043739,000265:                                                                                                  #  OUTPUT
043740,000266:                                                                                                  #        ERADM= 504RM FOR MOON (METERS B-29)
043741,000267:                                                                                                  #        ERADM= ERAD OR COMPUTED RF FOR EARTH (METERS B-29)
043742,000268: 
043743,000269: 13,2534           71220        SETRE              STQ      DLOAD                                 
043744,000270: 13,2535           00051                                    SETREX                                
043745,000271: 13,2536           26561                                    504RM                                 
043746,000272: 13,2537           71214                           BON      DLOAD                                 #  BRANCH FOR MOON
043747,000273: 13,2540           01703                                    LUNAFLAG                              
043748,000274: 13,2541           26551                                    TSTRLSRM                              
043749,000275: 13,2542           26463                                    ERAD                                  
043750,000276: 13,2543           45014                           BOFF     CALL                                  #  ERADFLAG=0 FOR FIXED RE, 1 FOR COMPUTED
043751,000277: 13,2544           00742                                    ERADFLAG                              
043752,000278: 13,2545           26547                                    SETRXX                                
043753,000279: 13,2546           26440                                    GETERAD                               
043754,000280: 13,2547           37660        SETRXX             STCALL   ERADM                                 #  EXIT WITH RE OR RM METERS B-29
043755,000281: 13,2550           00051                                    SETREX                                
043756,000282: 13,2551           77214        TSTRLSRM           BON      VLOAD                                 #  ERADFLAG=0, SET R0=RLS
043757,000283: 13,2552           00702                                    ERADFLAG                              #          =1      R0=RM
043758,000284: 13,2553           26547                                    SETRXX                                
043759,000285: 13,2554           02025                                    RLS                                   
043760,000286: 13,2555           64446                           ABVAL    SR2R                                  #  SCALE FROM B-27 TO B-29
043761,000287: 13,2556           77650                           GOTO                                           
043762,000288: 13,2557           26547                                    SETRXX                                
043763,000289: 13,2560  0000051               SETREX             =        S2                                    
043764,000290: 13,2560           00065 01265  504RM              2DEC     1738090    B-29                       #  METERS B-29 (EQUATORIAL MOON RADIUS)

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