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.

011703,000002:                                                                                                  ## Copyright:   Public domain.
011704,000003:                                                                                                  ## Filename:    LEM_GEOMETRY.agc
011705,000004:                                                                                                  ## Purpose:     A section of a reconstructed, mixed version of Sundance
011706,000005:                                                                                                  ##              It is part of the reconstructed source code for the Lunar
011707,000006:                                                                                                  ##              Module's (LM) Apollo Guidance Computer (AGC) for Apollo 9.
011708,000007:                                                                                                  ##              No original listings of this program are available;
011709,000008:                                                                                                  ##              instead, this file was created via disassembly of dumps
011710,000009:                                                                                                  ##              of various revisions of Sundance core rope modules.
011711,000010:                                                                                                  ## Assembler:   yaYUL
011712,000011:                                                                                                  ## Contact:     Ron Burkey <info@sandroid.org>.
011713,000012:                                                                                                  ## Website:     www.ibiblio.org/apollo/index.html
011714,000013:                                                                                                  ## Mod history: 2020-06-17 MAS  Created from Luminary 69.
011715,000014:                                                                                                  ##              2021-05-30 ABS  Replaced use of ANTENBIT with BIT12 to match
011716,000015:                                                                                                  ##                              Luminary 69.
011717,000016: 
011718,000017:                                                                                                  ## Sundance 302
011719,000018: 
011720,000019: 23,2000                                           BANK     23                                    
011721,000020: 13,2000                                           SETLOC   LEMGEOM                               
011722,000021: 13,2000                                           BANK                                           
011723,000022: 
011724,000023: 13,2042  30,2000                                  SBANK=   LOWSUPER                              
011725,000024: 13,2042  E5,1642                                  EBANK=   XSM                                   
011726,000025: 
011727,000026:                                                                                                  #  THESE TWO ROUTINES COMPUTE THE ACTUAL STATE VECTOR FOR LM,CSM BY ADDING
011728,000027:                                                                                                  #  THE CONIC R,V AND THE DEVIATIONSR,V. THE STATE VECTORS ARE CONVERTED TO
011729,000028:                                                                                                  #  METERS B-29 AND METERS/CSEC B-7 AND STORED APPROPRIATELY IN RN,VN OR
011730,000029:                                                                                                  #  R-OTHER , V-OTHER FOR DOWNLINK. THE ROUTINES NAMES ARE SWITCHED IN THE
011731,000030:                                                                                                  #  OTHER VEHICLES COMPUTER.
011732,000031: 
011733,000032:                                                                                                  #  INPUT
011734,000033:                                                                                                  #    STATE VECTOR IN TEMPORARY STORAGE AREA
011735,000034:                                                                                                  #    IF STATE VECTOR IS SCALED POS B27 AND VEL B5
011736,000035:                                                                                                  #       SET X2 TO +2
011737,000036:                                                                                                  #    IF STATE VECTOR IS SCALED POS B29 AND VEL B7
011738,000037:                                                                                                  #       SET X2 TO 0
011739,000038: 
011740,000039:                                                                                                  #  OUTPUT
011741,000040:                                                                                                  #    R(T) IN RN, V(T) IN VN, T IN PIPTIME
011742,000041:                                                                                                  #  OR
011743,000042:                                                                                                  #    R(T) IN R-OTHER, V(T) IN V-OTHER   (T IS DEFINED BY T-OTHER)
011744,000043: 
011745,000044: 13,2042                                           COUNT*   $$/GEOM                               
011746,000045: 13,2042           43414        SVDWN2             BOF      RVQ                                   #  SW=1=AVETOMID DOING W-MATRIX INTEG.
011747,000046: 13,2043           04756                                    AVEMIDSW                              
011748,000047: 13,2044           26045                                    +1                                    
011749,000048: 13,2045           53775                           VLOAD    VSL*                                  
011750,000049: 13,2046           01521                                    TDELTAV                               
011751,000050: 13,2047           57605                                    0          -7,2                       
011752,000051: 13,2050           53655                           VAD      VSL*                                  
011753,000052: 13,2051           01535                                    RCV                                   
011754,000053: 13,2052           57576                                    0,2                                   
011755,000054: 13,2053           25220                           STOVL    RN                                    
011756,000055: 13,2054           01527                                    TNUV                                  
011757,000056: 13,2055           53257                           VSL*     VAD                                   
011758,000057: 13,2056           57602                                    0          -4,2                       
011759,000058: 13,2057           01543                                    VCV                                   
011760,000059: 13,2060           77657                           VSL*                                           
011761,000060: 13,2061           57576                                    0,2                                   
011762,000061: 13,2062           15226                           STODL    VN                                    
011763,000062: 13,2063           01517                                    TET                                   
011764,000063: 13,2064           01234                           STORE    PIPTIME                               
011765,000064: 13,2065           77616                           RVQ                                            
011766,000065: 13,2066           53775        SVDWN1             VLOAD    VSL*                                  
011767,000066: 13,2067           01521                                    TDELTAV                               
011768,000067: 13,2070           57605                                    0          -7,2                       
011769,000068: 13,2071           53655                           VAD      VSL*                                  
011770,000069: 13,2072           01535                                    RCV                                   
011771,000070: 13,2073           57576                                    0,2                                   
011772,000071: 13,2074           25722                           STOVL    R-OTHER                               
011773,000072: 13,2075           01527                                    TNUV                                  
011774,000073: 13,2076           53257                           VSL*     VAD                                   
011775,000074: 13,2077           57602                                    0          -4,2                       
011776,000075: 13,2100           01543                                    VCV                                   
011777,000076: 13,2101           77657                           VSL*                                           
011778,000077: 13,2102           57576                                    0,2                                   
011779,000078: 13,2103           01730                           STORE    V-OTHER                               
011780,000079: 13,2104           77616                           RVQ                                            
011781,000080: 
011782,000081:                                                                                                  #           THE FOLLOWING ROUTINE TAKES A HALF UNIT TARGET VECTOR REFERRED TO NAV BASE COORDINATES AND FINDS BOTH
011783,000082:                                                                                                  #  GIMBAL ORIENTATIONS AT WHICH THE RR MIGHT SIGHT THE TARGET. THE GIMBAL ANGLES CORRESPONDING TO THE PRESENT MODE
011784,000083:                                                                                                  #  ARE LEFT IN MODEA AND THOSE WHICH WOULD BE USED AFTER A REMODE IN MODEB. THIS ROUTINE ASSUMES MODE 1 IS TRUNNION
011785,000084:                                                                                                  #  ANGLE LESS THAN 90 DEGS IN ABS VALUE WITH ARBITRARY SHAFT, WITH A CORRESPONDING DEFINITION FOR MODE 2. MODE
011786,000085:                                                                                                  #  SELECTION AND LIMIT CHECKING ARE DONE ELSEWHERE.
011787,000086: 
011788,000087:                                                                                                  #           THE MODE 1 CONFIGURATION IS CALCULATED FROM THE VECTOR AND THEN MODE 2 IS FOUND USING THE RELATIONS
011789,000088: 
011790,000089:                                                                                                  #           S(2) = 180 + S(1)
011791,000090:                                                                                                  #           T(2) = 180 - T(1)
011792,000091: 
011793,000092:                                                                                                  #      THE VECTOR ARRIVES IN MPAC WHERE TRG*SMNG OR *SMNB* WILL HAVE LEFT IT.
011794,000093: 
011795,000094: 13,2105           00041        RRANGLES           STORE    32D                                   
011796,000095: 13,2106           57545                           DLOAD    DCOMP                                 #  SINCE WE WILL FIND THE MODE 1 SHAFT
011797,000096: 13,2107           00043                                    34D                                   #  ANGLE LATER, WE CAN FIND THE MODE 1
011798,000097: 13,2110           67401                           SETPD    ASIN                                  #  TRUNNION BY SIMPLY TAKING THE ARCSIN OF
011799,000098: 13,2111           00001                                    0                                     #  THE Y COMPONENT, THE ASIN GIVING AN
011800,000099: 13,2112           44206                           PUSH     BDSU                                  #  ANSWER WHOSE ABS VAL IS LESS THAN 90 DEG
011801,000100: 13,2113           22274                                    LODPHALF                              
011802,000101: 13,2114           14005                           STODL    4                                     #  MODE 2 TRUNNION TO 4.
011803,000102: 
011804,000103: 13,2115           22276                                    LO6ZEROS                              
011805,000104: 13,2116           24043                           STOVL    34D                                   #  UNIT THE PROJECTION OF THE VECTOR
011806,000105: 13,2117           00041                                    32D                                   #    IN THE X-Z PLANE
011807,000106: 13,2120           41056                           UNIT     BOVB                                  #  IF OVERFLOW, TARGET VECTOR IS ALONG Y
011808,000107: 13,2121           52400                                    LUNDESCH                              #  CALL FOR MANEUVER UNLESS ON LUNAR SURF
011809,000108: 13,2122           14041                           STODL    32D                                   #  PROJECTION VECTOR.
011810,000109: 13,2123           00041                                    32D                                   
011811,000110: 13,2124           44142                           SR1      STQ                                   
011812,000111: 13,2125           00051                                    S2                                    
011813,000112: 13,2126           14023                           STODL    SINTH                                 #  USE ARCTRIG SINCE SHAFT COULD BE ARB.
011814,000113: 13,2127           00045                                    36D                                   
011815,000114: 13,2130           77742                           SR1                                            
011816,000115: 13,2131           34021                           STCALL   COSTH                                 
011817,000116: 13,2132           47030                                    ARCTRIG                               
011818,000117: 13,2133           43206                           PUSH     DAD                                   #  MODE 1 SHAFT TO 2.
011819,000118: 13,2134           22274                                    LODPHALF                              
011820,000119: 13,2135           24007                           STOVL    6                                     
011821,000120: 13,2136           00005                                    4                                     
011822,000121: 13,2137           77634                           RTB                                            #  FIND MODE 2 CDU ANGLES.
011823,000122: 13,2140           21533                                    2V1STO2S                              
011824,000123: 13,2141           25115                           STOVL    MODEB                                 
011825,000124: 13,2142           00001                                    0                                     
011826,000125: 13,2143           77634                           RTB                                            #  MODE 1 ANGLES TO MODE A.
011827,000126: 13,2144           21533                                    2V1STO2S                              
011828,000127: 13,2145           01113                           STORE    MODEA                                 
011829,000128: 13,2146           77776                           EXIT                                           
011830,000129: 
011831,000130: 13,2147           41101                           CS       RADMODES                              #  SWAP MODEA AND MODEB IF RR IN MODE 2.
011832,000131: 13,2150           75013                           MASK     BIT12                                 
011833,000132: 13,2151           10000                           CCS      A                                     
011834,000133: 13,2152           12156                           TCF      +4                                    
011835,000134: 
011836,000135: 13,2153           53113                           DXCH     MODEA                                 
011837,000136: 13,2154           53115                           DXCH     MODEB                                 
011838,000137: 13,2155           53113                           DXCH     MODEA                                 
011839,000138: 
011840,000139: 13,2156           06014                           TC       INTPRET                               
011841,000140: 13,2157           77650                           GOTO                                           
011842,000141: 13,2160           00051                                    S2                                    
011843,000142:                                                                                                  #  GIVEN RR TRUNNION AND SHAFT (T,S) IN TANGNB,+1, FIND THE ASSOCIATED
011844,000143:                                                                                                  #  LINE OF SIGHT IN NAV BASE AXES.  THE HALF UNIT VECTOR, .5(SIN(S)COS(T),
011845,000144:                                                                                                  #  -SIN(T),COS(S)COS(T)) IS LEFT IN MPAC AND 32D.
011846,000145: 
011847,000146: 23,2000                                           SETLOC   INFLIGHT                              
011848,000147: 23,2000                                           BANK                                           
011849,000148: 
011850,000149: 23,2000                                           COUNT*   $$/GEOM                               
011851,000150: 
011852,000151: 23,2000           47135        RRNB               SLOAD    RTB                                   
011853,000152: 23,2001           03744                                    TANGNB                                
011854,000153: 23,2002           21457                                    CDULOGIC                              
011855,000154: 23,2003           41401                           SETPD    PUSH                                  #  TRUNNION ANGLE TO 0
011856,000155: 23,2004           00001                                    0                                     
011857,000156: 23,2005           57556                           SIN      DCOMP                                 
011858,000157: 23,2006           14043                           STODL    34D                                   #  Y COMPONENT
011859,000158: 
011860,000159: 23,2007           41546                           COS      PUSH                                  #  .5 COS(T) TO 0
011861,000160: 23,2010           47135                           SLOAD    RTB                                   
011862,000161: 23,2011           03745                                    TANGNB     +1                         
011863,000162: 23,2012           21457                                    CDULOGIC                              
011864,000163: 23,2013           71406                           PUSH     COS                                   #  SHAFT ANGLE TO 2
011865,000164: 23,2014           72405                           DMP      SL1                                   
011866,000165: 23,2015           00001                                    0                                     
011867,000166: 23,2016           14045                           STODL    36D                                   #  Z COMPONENT
011868,000167: 
011869,000168: 23,2017           41356                           SIN      DMP                                   
011870,000169: 23,2020           77752                           SL1                                            
011871,000170: 23,2021           24041                           STOVL    32D                                   
011872,000171: 23,2022           00041                                    32D                                   
011873,000172: 23,2023           77616                           RVQ                                            

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