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.

038318,000002:                                                                                                  ## Copyright:   Public domain.
038319,000003:                                                                                                  ## Filename:    LUNAR_AND_SOLAR_EPHEMERIDES_SUBROUTINES.agc
038320,000004:                                                                                                  ## Purpose:     A section of a reconstructed, mixed version of Sundance
038321,000005:                                                                                                  ##              It is part of the reconstructed source code for the Lunar
038322,000006:                                                                                                  ##              Module's (LM) Apollo Guidance Computer (AGC) for Apollo 9.
038323,000007:                                                                                                  ##              No original listings of this program are available;
038324,000008:                                                                                                  ##              instead, this file was created via disassembly of dumps
038325,000009:                                                                                                  ##              of various revisions of Sundance core rope modules.
038326,000010:                                                                                                  ## Assembler:   yaYUL
038327,000011:                                                                                                  ## Contact:     Ron Burkey <info@sandroid.org>.
038328,000012:                                                                                                  ## Website:     www.ibiblio.org/apollo/index.html
038329,000013:                                                                                                  ## Mod history: 2020-06-17 MAS  Created from Luminary 69.
038330,000014:                                                                                                  ##              2021-05-30 ABS  2DEC* -> DEC for non extended address field.
038331,000015: 
038332,000016:                                                                                                  ## Sundance 302
038333,000017: 
038334,000018:                                                                                                  #  NAME - LSPOS  - LOCATE SUN AND MOON                   DATE - 25 OCT 67
038335,000019:                                                                                                  #  MOD NO.1
038336,000020:                                                                                                  #  MOD BY NEVILLE                                        ASSEMBLY SUNDANCE
038337,000021: 
038338,000022:                                                                                                  #  FUNCTIONAL DESCRIPTION
038339,000023: 
038340,000024:                                                                                                  #         COMPUTES UNIT POSITION VECTOR OF THE SUN AND MOON IN THE BASIC REFERENCE SYSTEM. THE SUN VECTOR S IS
038341,000025:                                                                                                  #  LOCATED VIA TWO ANGLES. THE FIRST ANGLE(OBLIQUITY) IS THE ANGLE BETWEEN THE EARTH EQUATOR AND THE ECLIPTIC. THE
038342,000026:                                                                                                  #  SECOND ANGLE IS THE LONGITUDE OF THE SUN MEASURED IN THE ECLIPTIC.
038343,000027:                                                                                                  #  THE POSITION VECTOR OF THE SUN IS
038344,000028:                                                                                                  #        -
038345,000029:                                                                                                  #        S = (COS(LOS), COS(OBL)*SIN(LOS), SIN(OBL)*SIN(LOS)), WHERE
038346,000030: 
038347,000031:                                                                                                  #        LOS = LOS +LOS *T-(C *SIN(2PI*T)/365.24 +C *COS(2PI*T)/365.24)
038348,000032:                                                                                                  #                 0    R     0                     1
038349,000033:                                                                                                  #        LOS  (RAD) IS THE LONGITUDE OF THE SUN FOR MIDNIGHT JUNE 30TH OF THE PARTICULAR YEAR.
038350,000034:                                                                                                  #           0
038351,000035:                                                                                                  #        LOS  (RAD/DAY) IS THE MEAN RATE FOR THE PARTICULAR YEAR.
038352,000036:                                                                                                  #           R
038353,000037: 
038354,000038:                                                                                                  #  LOS  AND LOS  ARE STORED AS LOSC AND LOSR IN RATESP.
038355,000039:                                                                                                  #     0        R
038356,000040:                                                                                                  #  COS(OBL) AND SIN(OBL) ARE STORED IN THE MATRIX KONMAT.
038357,000041:                                                                                                  #  T, TIME MEASURED IN DAYS (24 HOURS), IS STORED IN TIMEP.
038358,000042:                                                                                                  #  C  AND C  ARE FUDGE FACTORS TO MINIMIZE THE DEVIATION.  THEY ARE STORED AS ONE CONSTANT (CMOD), SINCE
038359,000043:                                                                                                  #   0      1                               2  2 1/2
038360,000044:                                                                                                  #  C *SIN(X)+C *COS(X) CAN BE WRITTEN AS (C +C )   *SIN(X+PHI), WHERE PHI=ARCTAN(C /C ).
038361,000045:                                                                                                  #   0         1                            0  1                                   1  0
038362,000046: 
038363,000047:                                                                                                  #  THE MOON IS LOCATED VIA FOUR ANGLES. THE FIRST IS THE OBLIQUITY. THE SECOND IS THE MEAN LONGITUDE OF THE MOON,
038364,000048:                                                                                                  #  MEASURED IN THE ECLIPTIC FROM THE MEAN EQUINOX TO THE MEAN ASCENDING NODE OF THE LUNAR ORBIT, AND THEN ALONG THE
038365,000049:                                                                                                  #  ORBIT.  THE THIRD ANGLE IS THE ANGLE BETWEEN THE ECLIPTIC AND THE LUNAR ORBIT.  THE FOURTH ANGLE IS THE LONGITUDE
038366,000050:                                                                                                  #  OF THE NODE OF THE MOON, MEASURED IN THE LUNAR ORBIT.  LET THESE ANGLES BE OBL,LOM,IM, AND LON RESPECTIVELY.
038367,000051: 
038368,000052:                                                                                                  #  THE SIMPLIFIED POSITION VECTOR OF THE MOON IS
038369,000053:                                                                                                  #        -
038370,000054:                                                                                                  #        M=(COS(LOM), COS(OBL)*SIN(LOM)-SIN(OBL)*SIN(IM)*SIN(LOM-LON), SIN(OBL)*SIN(LOM)+COS(OBL)*SIN(IM)*SIN(LOM-LON))
038371,000055: 
038372,000056:                                                                                                  #  WHERE
038373,000057:                                                                                                  #        LOM=LOM +LOM *T-(A *SIN 2PI*T/27.5545+A *COS(2PI*T/27.5545)+B *SIN 2PI*T/32+B *COS(2PI*T/32)), AND
038374,000058:                                                                                                  #               0    R     0                    1                     0               1
038375,000059:                                                                                                  #        LON=LON +LON
038376,000060:                                                                                                  #               0    R
038377,000061:                                                                                                  #  A , A , B  AND B  ARE STORED AS AMOD AND BMOD (SEE DESCRIPTION OF CMOD, ABOVE).  COS(OBL), SIN(OBL)*SIN(IM),
038378,000062:                                                                                                  #   0   1   0      1
038379,000063:                                                                                                  #  SIN(OBL), AND COS(OBL)*SIN(IM) ARE STORED IN KONMAT AS K1, K2, K3 AND K4, RESPECTIVELY.  LOM , LOM , LON , LON                                   
038380,000064:                                                                                                  #  ARE STORED AS LOMO, LOMR, LONO, AND LONR IN RATESP.                                         0     R     0     R
038381,000065:                                                                                                  #  THE THREE PHIS ARE STORED AS AARG, BARG, AND CARG(SUN).  ALL CONSTANTS ARE UPDATED BY YEAR.
038382,000066: 
038383,000067:                                                                                                  #  CALLING SEQUENCE
038384,000068:                                                                                                  #        CALL LSPOS.  RETURN IS VIA CPRET.
038385,000069: 
038386,000070:                                                                                                  #  ALARMS OR ABORTS
038387,000071:                                                                                                  #        NONE
038388,000072: 
038389,000073:                                                                                                  #  ERASABLE INITIALIZATION REQUIRED
038390,000074:                                                                                                  #        TEPHEM - TIME FROM MIDNIGHT 1 JULY PRECEDING THE LAUNCH TO THE TIME OF THE LAUNCH (WHEN THE AGC CLOCK WENT
038391,000075:                                                                                                  #        TO ZERO).  TEPHEM IS TP WITH UNITS OF CENTI-SECONDS.
038392,000076: 
038393,000077:                                                                                                  #        TIME2 AND TIME1 ARE IN MPAC AND MPAC +1 WHEN PROGRAM IS CALLED.
038394,000078: 
038395,000079:                                                                                                  #  OUTPUT
038396,000080:                                                                                                  #        UNIT POSITIONAL VECTOR OF SUN IN VSUN.  (SCALED B-1)
038397,000081:                                                                                                  #        UNIT POSITIONAL VECTOR OF MOON IN VMOON.  (SCALED B-1)
038398,000082: 
038399,000083:                                                                                                  #  SUBROUTINES USED
038400,000084:                                                                                                  #        NONE
038401,000085: 
038402,000086:                                                                                                  #  DEBRIS
038403,000087:                                                                                                  #        CURRENT CORE SET, WORK AREA AND FREEFLAG
038404,000088: 
038405,000089: 04,2663                                           BANK     04                                    
038406,000090: 15,2000                                           SETLOC   EPHEM                                 
038407,000091: 15,2000                                           BANK                                           
038408,000092: 
038409,000093: 15,3236  E5,1714                                  EBANK=   VSUN                                  
038410,000094: 15,3236                                           COUNT*   $$/EPHEM                              
038411,000095: 15,3236  15,3236               LUNPOS             EQUALS   LSPOS                                 
038412,000096: 
038413,000097: 15,3236           54201        LSPOS              SETPD    SR                                    
038414,000098: 15,3237           00001                                    0                                     
038415,000099: 15,3240           20617                                    14D                                   #  TP
038416,000100: 15,3241           56371                           TAD      DDV                                   
038417,000101: 15,3242           01707                                    TEPHEM                                #  TIME OF LAUNCH
038418,000102: 15,3243           31334                                    CSTODAY                               #  24 HOURS-8640000 CENTI-SECS/DAY B-33
038419,000103: 15,3244           00031                           STORE    TIMEP                                 #  T IN DAYS
038420,000104: 15,3245           77170                           AXT,1    AXT,2                                 
038421,000105: 15,3246           00000                                    0                                     
038422,000106: 15,3247           00000                                    0                                     
038423,000107: 15,3250           77614                           CLEAR                                          
038424,000108: 15,3251           00274                                    FREEFLAG                              #  SWITCH BIT
038425,000109: 15,3252           77745        POSITA             DLOAD                                          
038426,000110: 15,3253           31314                                    KONMAT     +2                         #  ZEROS
038427,000111: 15,3254           00027                           STORE    GTMP                                  
038428,000112: 15,3255           40745        POSITB             DLOAD    DMP*                                  
038429,000113: 15,3256           00031                                    TIMEP                                 #  T
038430,000114: 15,3257           31360                                    VAL67      +4,1                       #  1/27 OR 1/32 OR 1/365
038431,000115: 15,3260           42661                           SL       DAD*                                  
038432,000116: 15,3261           20211                                    8D                                    
038433,000117: 15,3262           31356                                    VAL67      +2,1                       #  AARG
038434,000118: 15,3263           40756                           SIN      DMP*                                  #  SIN(T/27+PHI) OR T/32 OR T/365
038435,000119: 15,3264           31354                                    VAL67,1                               #  (A0**2+A1**2)**1/2 SIN(X+PHIA)
038436,000120: 15,3265           62015                           DAD      INCR,1                                #  PLUS
038437,000121: 15,3266           00027                                    GTMP                                  #  (B0**2+B1**2)**1/2 SIN(X+PHIB)
038438,000122: 15,3267           77771                           DEC      -6         B-14                       
038439,000123: 15,3270           00027                           STORE    GTMP                                  #  OR (C0**2+C1**2)**1/2 SIN(X+PHIC)
038440,000124: 15,3271           77614                           BOFSET                                         
038441,000125: 15,3272           00054                                    FREEFLAG                              
038442,000126: 15,3273           33255                                    POSITB                                
038443,000127: 15,3274           40745        POSITD             DLOAD    DMP*                                  
038444,000128: 15,3275           00031                                    TIMEP                                 #  T
038445,000129: 15,3276           46437                                    RATESP,2                              #  LOMR,LOSR,LONR
038446,000130: 15,3277           42661                           SL       DAD*                                  
038447,000131: 15,3300           20206                                    5D                                    
038448,000132: 15,3301           46431                                    RATESP     +6,2                       #  LOMO,LOSO,LONO
038449,000133: 15,3302           77625                           DSU                                            
038450,000134: 15,3303           00027                                    GTMP                                  
038451,000135: 15,3304           10021                           STORE    STMP,2                                #  LOM,LOS,LON
038452,000136: 15,3305           63135                           SLOAD    INCR,2                                
038453,000137: 15,3306           00050                                    X2                                    
038454,000138: 15,3307           77775                           DEC      -2         B-14                       
038455,000139: 15,3310           53015                           DAD      BZE                                   
038456,000140: 15,3311           31336                                    RCB-13                                #  PLUS 2
038457,000141: 15,3312           33342                                    POSITE                                #  2ND
038458,000142: 15,3313           77644                           BPL                                            
038459,000143: 15,3314           33252                                    POSITA                                #  1ST
038460,000144: 15,3315           45345        POSITF             DLOAD    DSU                                   #  3RD
038461,000145: 15,3316           00021                                    STMP                                  #  LOM
038462,000146: 15,3317           00025                                    STMP       +4                         #  LON
038463,000147: 15,3320           65356                           SIN      PDDL                                  #  SIN(LOM-LON)
038464,000148: 15,3321           00021                                    STMP                                  
038465,000149: 15,3322           65356                           SIN      PDDL                                  #  SIN LOM
038466,000150: 15,3323           00021                                    STMP                                  
038467,000151: 15,3324           55546                           COS      VDEF                                  #  COS LOM
038468,000152: 15,3325           53521                           MXV      UNIT                                  
038469,000153: 15,3326           31312                                    KONMAT                                #  K1,K2,K3,K4,
038470,000154: 15,3327           02723                           STORE    VMOON                                 
038471,000155: 15,3330           65345                           DLOAD    PDDL                                  
038472,000156: 15,3331           31314                                    KONMAT     +2                         #  ZERO
038473,000157: 15,3332           00023                                    STMP       +2                         
038474,000158: 15,3333           65356                           SIN      PDDL                                  #  SIN LOS
038475,000159: 15,3334           00023                                    STMP       +2                         
038476,000160: 15,3335           55546                           COS      VDEF                                  #  COS LOS
038477,000161: 15,3336           53521                           MXV      UNIT                                  
038478,000162: 15,3337           31312                                    KONMAT                                
038479,000163: 15,3340           02715                           STORE    VSUN                                  
038480,000164: 15,3341           77616                           RVQ                                            
038481,000165: 15,3342           77745        POSITE             DLOAD                                          
038482,000166: 15,3343           31314                                    KONMAT     +2                         #  ZEROS
038483,000167: 15,3344           00027                           STORE    GTMP                                  
038484,000168: 15,3345           77650                           GOTO                                           
038485,000169: 15,3346           33274                                    POSITD                                
038486,000170: 15,3347           77616        LUNVEL             RVQ                                            #         TO FOOL INTEGRATION
038487,000171: 
038488,000172: 15,3350                        STMP               EQUALS   16D                                   
038489,000173: 
038490,000174: 15,3350                        GTMP               EQUALS   22D                                   
038491,000175: 
038492,000176: 15,3350                        TIMEP              EQUALS   24D                                   
038493,000177: 
038494,000178: 14,2000                                           SETLOC   EPHEM1                                
038495,000179: 14,2000                                           BANK                                           
038496,000180: 14,3311                                           COUNT*   $$/EPHEM                              
038497,000181: 
038498,000182: 14,3311           20000 00000  KONMAT             2DEC     1.0        B-1                        #          *************
038499,000183: 14,3313           00000 00000                     2DEC     0          B-28                       #                      *
038500,000184: 14,3315           00000 00000                     2DEC     0          B-28                       #                      *
038501,000185: 14,3317           00000 00000                     2DEC     0          B-28                       #                      *
038502,000186: 14,3321           16533 30007                     2DEC     .91745     B-1                        #  K1 COS(OBL)         *
038503,000187: 14,3323           77333 56654                     2DEC     -.03571    B-1                        #  K2 SIN(OBL)SIN(IM)  *
038504,000188: 14,3325           00000 00000                     2DEC     0          B-28                       #                      *
038505,000189: 14,3327           06273 03275                     2DEC     .39784     B-1                        #  K3 SIN(OBL)         *
038506,000190: 
038507,000191: 14,3331           01242 24467                     2DEC     .082354    B-1                        #  K4 COS(OBL)SIN(IM)  *
038508,000192: 14,3333           00020 17260  CSTODAY            2DEC     8640000    B-33                       #                      * NOTE           *
038509,000193: 14,3335           00002        RCB-13             OCT      00002                                 #                      * TABLES CONTAIN *
038510,000194: 14,3336           00000                           OCT      00000                                 #                      * CONSTANTS FOR  *
038511,000195: 14,3337           22572 27214  RATESP             2DEC     .03660098  B+4                        #                      * 1968 - 1969    *
038512,000196: 14,3341           01315 26177                     2DEC     .00273779  B+4                        #  LOSR                *
038513,000197: 14,3343           77731 55217                     2DEC     -.00014719 B+4                        #  LONR                *
038514,000198: 14,3345           16455 04475                     2DEC     .455880394                            #  LOMO                *
038515,000199: 14,3347           10637 04312                     2DEC     .275337971                            #  LOSO                *
038516,000200: 14,3351           01215 26351                     2DEC     .0398987882                            #  LONO                *
038517,000201: 14,3353           01070 35243  VAL67              2DEC     .017361944 B+1                        #  AMOD                *
038518,000202: 14,3355           11126 14467                     2DEC     .286523072                            #  AARG                *
038519,000203: 14,3357           02245 06475                     2DEC     .036291712 B+1                        #  1/27                *
038520,000204: 14,3361           00163 32331                     2DEC     .003534722 B+1                        #  BMOD                *
038521,000205: 14,3363           03476 03302                     2DEC     .113165625                            #  BARG                *
038522,000206: 14,3365           02000 00000                     2DEC     .03125     B+1                        #  1/32                *
038523,000207: 14,3367           00256 25374                     2DEC     .005330555 B+1                        #  CMOD                *
038524,000208: 14,3371           77525 53143                     2DEC     -.010415660                            #  CARG       VALUE COMPUTED USING 1/364.24
038525,000209: 14,3373           00131 26730                     2DEC     .002737925 B+1                        #  1/365   *************
038526,000210:                                                                                                  #  ************************************************************************

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