Source Code

These source-code files derive from a printout of Luminary 116 (the Apollo 12 Lunar Module guidance computer program), from the personal library of original AGC developer Don Eyles, digitally photographed at archive.org, financially sponsored by Ron Burkey, and transcribed to source code by a team of volunteers. This colorized, syntax-highlighted form was created by assembling that transcribed source code. Note that the full page images are available on the Virtual AGC project page at archive.org, while reduced-size images are presented at the VirtualAGC project website. Report or fix any transcription errors at the Virtual AGC project code repository.

Notations on the program listing read, in part:

	GAP:  ASSEMBLE REVISION 116 OF AGC PROGRAM LUMINARY BY NASA 2021112-071
	19:09 AUG. 11,1969
Note that the date is the date of the printout, not the date of the program revision.

042112,000002:                                                                                                  ## Copyright:   Public domain.
042113,000003:                                                                                                  ## Filename:    LUNAR_AND_SOLAR_EPHEMERIDES_SUBROUTINES.agc
042114,000004:                                                                                                  ## Purpose:     A section of Luminary revision 116.
042115,000005:                                                                                                  ##              It is part of the source code for the Lunar Module's (LM) 
042116,000006:                                                                                                  ##              Apollo Guidance Computer (AGC) for Apollo 12.
042117,000007:                                                                                                  ##              This file is intended to be a faithful transcription, except
042118,000008:                                                                                                  ##              that the code format has been changed to conform to the
042119,000009:                                                                                                  ##              requirements of the yaYUL assembler rather than the
042120,000010:                                                                                                  ##              original YUL assembler.
042121,000011:                                                                                                  ## Reference:   pp. 976-979
042122,000012:                                                                                                  ## Assembler:   yaYUL
042123,000013:                                                                                                  ## Contact:     Ron Burkey <info@sandroid.org>.
042124,000014:                                                                                                  ## Website:     www.ibiblio.org/apollo/index.html
042125,000015:                                                                                                  ## Mod history: 2017-01-22 MAS  Created from Luminary 99.
042126,000016:                                                                                                  ##              2017-01-31 RRB  Updated for Luminary 116.
042127,000017:                                                                                                  ##              2017-03-13 RSB  Proofed comment text via 3-way diff vs
042128,000018:                                                                                                  ##                              Luminary 99 and 131.
042129,000019:                                                                                                  ##              2017-08-26 MAS  Fixed comment-text errors found while transcribing Zerlina 56.
042130,000020:                                                                                                  ##              2021-05-30 ABS  Fixed a page number to match scans.
042131,000021: 

Page 976

042133,000023:                                                                                                  #  NAME - LSPOS - LOCATE SUN AND MOON                    DATE - 25 OCT 67
042134,000024:                                                                                                  #  MOD NO. 1
042135,000025:                                                                                                  #  MOD BY NEVILLE                                        ASSEMBLY SUNDANCE
042136,000026: 
042137,000027:                                                                                                  #  FUNCTIONAL DESCRIPTION
042138,000028: 
042139,000029:                                                                                                  #         COMPUTES UNIT POSITION VECTOR OF THE SUN AND MOON IN THE BASIC REFERENCE SYSTEM. THE SUN VECTOR S IS
042140,000030:                                                                                                  #  LOCATED VIA TWO ANGLES. THE FIRST ANGLE(OBLIQUITY) IS THE ANGLE BETWEEN THE EARTH EQUATOR AND THE ECLIPTIC. THE
042141,000031:                                                                                                  #  SECOND ANGLE IS THE LONGITUDE OF THE SUN MEASURED IN THE ECLIPTIC.
042142,000032:                                                                                                  #  THE POSITION VECTOR OF THE SUN IS
042143,000033:                                                                                                  #         -
042144,000034:                                                                                                  #         S = (COS(LOS), COS(OBL)*SIN(LOS), SIN(OBL)*SIN(LOS)), WHERE
042145,000035: 
042146,000036:                                                                                                  #       LOS = LOS +LOS *T-(C *SIN(2PI*T)/365.24 +C *COS(2PI*T)/365.24)
042147,000037:                                                                                                  #                0    R     0                     1
042148,000038:                                                                                                  #       LOS  (RAD) IS THE LONGITUDE OF THE SUN FOR MIDNIGHT JUNE 30TH OF THE PARTICULAR YEAR.
042149,000039:                                                                                                  #          0
042150,000040:                                                                                                  #       LOS  (RAD/DAY) IS THE MEAN RATE FOR THE PARTICULAR YEAR.
042151,000041:                                                                                                  #          R
042152,000042:                                                                                                  #  LOS  AND LOS  ARE STORED AS LOSC AND LOSR IN RATESP.
042153,000043:                                                                                                  #     0        R
042154,000044:                                                                                                  #  COS(OBL) AND SIN(OBL) ARE STORED IN THE MATRIX KONMAT.
042155,000045:                                                                                                  #  T, TIME MEASURED IN DAYS (24 HOURS), IS STORED IN TIMEP.
042156,000046:                                                                                                  #  C  AND C  ARE FUDGE FACTORS TO MINIMIZE THE DEVIATION.  THEY ARE STORED AS ONE CONSTANT (CMOD), SINCE
042157,000047:                                                                                                  #   0      1                               2  2 1/2
042158,000048:                                                                                                  #  C *SIN(X)+C *COS(X) CAN BE WRITTEN AS (C +C )   *SIN(X+PHI), WHERE PHI=ARCTAN(C /C ).
042159,000049:                                                                                                  #   0         1                            0  1                                   1  0
042160,000050: 
042161,000051:                                                                                                  #  THE MOON IS LOCATED VIA FOUR ANGLES. THE FIRST IS THE OBLIQUITY. THE SECOND IS THE MEAN LONGITUDE OF THE MOON,
042162,000052:                                                                                                  #  MEASURED IN THE ECLIPTIC FROM THE MEAN EQUINOX TO THE MEAN ASCENDING NODE OF THE LUNAR ORBIT, AND THEN ALONG THE
042163,000053:                                                                                                  #  ORBIT.  THE THIRD ANGLE IS THE ANGLE BETWEEN THE ECLIPTIC AND THE LUNAR ORBIT.  THE FOURTH ANGLE IS THE LONGITUDE
042164,000054:                                                                                                  #  OF THE NODE OF THE MOON, MEASURED IN THE LUNAR ORBIT.  LET THESE ANGLES BE OBL,LOM,IM, AND LON RESPECTIVELY.
042165,000055: 
042166,000056:                                                                                                  #  THE SIMPLIFIED POSITION VECTOR OF THE MOON IS
042167,000057:                                                                                                  #    -
042168,000058:                                                                                                  #    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))
042169,000059: 
042170,000060:                                                                                                  #    WHERE
042171,000061:                                                                                                  #       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
042172,000062:                                                                                                  #              0    R     0                    1                     0               1
042173,000063:                                                                                                  #       LON=LON +LON
042174,000064:                                                                                                  #              0    R
042175,000065:                                                                                                  #  A , A , B  AND B  ARE STORED AS AMOD AND BMOD (SEE DESCRIPTION OF CMOD, ABOVE).  COS(OBL), SIN(OBL)*SIN(IM),
042176,000066:                                                                                                  #   0   1   0      1
042177,000067:                                                                                                  #  SIN(OBL), AND COS(OBL)*SIN(IM) ARE STORED IN KONMAT AS K1, K2, K3 AND K4, RESPECTIVELY.  LOM , LOM , LON , LON                                   
042178,000068:                                                                                                  #  ARE STORED AS LOMO, LOMR, LONO, AND LONR IN RATESP.                                         0     R     0     R
042179,000069:                                                                                                  #  THE THREE PHIS ARE STORED AS AARG, BARG, AND CARG(SUN).  ALL CONSTANTS ARE UPDATED BY YEAR.
042180,000070: 
042181,000071:                                                                                                  #  CALLING SEQUENCE

Page 977

042183,000073:                                                                                                  #    CALL LSPOS.  RETURN IS VIA CPRET.
042184,000074: 
042185,000075:                                                                                                  #  ALARMS OR ABORTS
042186,000076:                                                                                                  #    NONE
042187,000077: 
042188,000078:                                                                                                  #  ERASABLE INITIALIZATION REQUIRED
042189,000079:                                                                                                  #    TEPHEM - TIME FROM MIDNIGHT 1 JULY PRECEDING THE LAUNCH TO THE TIME OF THE LAUNCH (WHEN THE AGC CLOCK WENT
042190,000080:                                                                                                  #  TO ZERO).  TEPHEM IS TP WITH UNITS OF CENTI-SECONDS.
042191,000081:                                                                                                  #    TIME2 AND TIME1 ARE IN MPAC AND MPAC +1 WHEN PROGRAM IS CALLED.
042192,000082: 
042193,000083:                                                                                                  #  OUTPUT
042194,000084:                                                                                                  #    UNIT POSITIONAL VECTOR OF SUN IN VSUN.  (SCALED B-1)
042195,000085:                                                                                                  #    UNIT POSITIONAL VECTOR OF MOON IN VMOON.  (SCALED B-1)
042196,000086: 
042197,000087:                                                                                                  #  SUBROUTINES USED
042198,000088:                                                                                                  #    NONE
042199,000089: 
042200,000090:                                                                                                  #  DEBRIS
042201,000091:                                                                                                  #    CURRENT CORE SET, WORK AREA AND FREEFLAG
042202,000092: 
042203,000093: 04,3011                                           BANK     04                                    
042204,000094: 15,2000                                           SETLOC   EPHEM                                 
042205,000095: 15,2000                                           BANK                                           
042206,000096: 
042207,000097: 15,3647  E5,1714                                  EBANK=   VSUN                                  
042208,000098: 15,3647                                           COUNT*   $$/EPHEM                              
042209,000099: 15,3647  15,3647               LUNPOS             EQUALS   LSPOS                                 
042210,000100: 
042211,000101: 15,3647           54201        LSPOS              SETPD    SR                                    
042212,000102: 15,3650           00001                                    0                                     
042213,000103: 15,3651           20617                                    14D                                   #  TP
042214,000104: 15,3652           56371                           TAD      DDV                                   
042215,000105: 15,3653           01707                                    TEPHEM                                #  TIME OF LAUNCH
042216,000106: 15,3654           12024                                    CSTODAY                               #  24 HOURS-8640000 CENTI-SECS/DAY B-33
042217,000107: 15,3655           00031                           STORE    TIMEP                                 #  T IN DAYS
042218,000108: 15,3656           77170                           AXT,1    AXT,2                                 
042219,000109: 15,3657           00000                                    0                                     
042220,000110: 15,3660           00000                                    0                                     
042221,000111: 15,3661           77614                           CLEAR                                          
042222,000112: 15,3662           00274                                    FREEFLAG                              #  SWITCH BIT
042223,000113: 15,3663           77745        POSITA             DLOAD                                          
042224,000114: 15,3664           12004                                    KONMAT     +2                         #  ZEROS
042225,000115: 15,3665           00027                           STORE    GTMP                                  
042226,000116: 15,3666           40745        POSITB             DLOAD    DMP*                                  
042227,000117: 15,3667           00031                                    TIMEP                                 #  T
042228,000118: 15,3670           12050                                    VAL67      +4,1                       #  1/27 OR 1/32 OR 1/365

Page 978

042230,000120: 15,3671           42661                           SL       DAD*                                  
042231,000121: 15,3672           20211                                    8D                                    
042232,000122: 15,3673           12046                                    VAL67      +2,1                       #  AARG
042233,000123: 15,3674           40756                           SIN      DMP*                                  #  SIN(T/27+PHI) OR T/32 OR T/365
042234,000124: 15,3675           12044                                    VAL67,1                               #  (A0**2+A1**2)**1/2 SIN(X+PHIA)
042235,000125: 15,3676           62015                           DAD      INCR,1                                #  PLUS
042236,000126: 15,3677           00027                                    GTMP                                  #  (B0**2+B1**2)**1/2 SIN(X+PHIB)
042237,000127: 15,3700           77771                           DEC      -6         B-14                       
042238,000128: 15,3701           00027                           STORE    GTMP                                  #  OR (C0**2+C1**2)**1/2 SIN(X+PHIC)
042239,000129: 15,3702           77614                           BOFSET                                         
042240,000130: 15,3703           00054                                    FREEFLAG                              
042241,000131: 15,3704           33666                                    POSITB                                
042242,000132: 15,3705           40745        POSITD             DLOAD    DMP*                                  
042243,000133: 15,3706           00031                                    TIMEP                                 #  T
042244,000134: 15,3707           65747                                    RATESP,2                              #  LOMR,LOSR,LONR
042245,000135: 15,3710           42661                           SL       DAD*                                  
042246,000136: 15,3711           20206                                    5D                                    
042247,000137: 15,3712           65741                                    RATESP     +6,2                       #  LOMO,LOSO,LONO
042248,000138: 15,3713           77625                           DSU                                            
042249,000139: 15,3714           00027                                    GTMP                                  
042250,000140: 15,3715           10021                           STORE    STMP,2                                #  LOM,LOS,LON
042251,000141: 15,3716           63135                           SLOAD    INCR,2                                
042252,000142: 15,3717           00050                                    X2                                    
042253,000143: 15,3720           77775                           DEC      -2         B-14                       
042254,000144: 15,3721           53015                           DAD      BZE                                   
042255,000145: 15,3722           12026                                    RCB-13                                #  PLUS 2
042256,000146: 15,3723           33753                                    POSITE                                #  2ND
042257,000147: 15,3724           77644                           BPL                                            
042258,000148: 15,3725           33663                                    POSITA                                #  1ST
042259,000149: 15,3726           45345        POSITF             DLOAD    DSU                                   #  3RD
042260,000150: 15,3727           00021                                    STMP                                  #  LOM
042261,000151: 15,3730           00025                                    STMP       +4                         #  LON
042262,000152: 15,3731           65356                           SIN      PDDL                                  #  SIN(LOM-LON)
042263,000153: 15,3732           00021                                    STMP                                  
042264,000154: 15,3733           65356                           SIN      PDDL                                  #  SIN LOM
042265,000155: 15,3734           00021                                    STMP                                  
042266,000156: 15,3735           55546                           COS      VDEF                                  #  COS LOM
042267,000157: 15,3736           53521                           MXV      UNIT                                  
042268,000158: 15,3737           12002                                    KONMAT                                #  K1,K2,K3,K4,
042269,000159: 15,3740           02723                           STORE    VMOON                                 
042270,000160: 15,3741           65345                           DLOAD    PDDL                                  
042271,000161: 15,3742           12004                                    KONMAT     +2                         #  ZERO
042272,000162: 15,3743           00023                                    STMP       +2                         
042273,000163: 15,3744           65356                           SIN      PDDL                                  #  SIN LOS
042274,000164: 15,3745           00023                                    STMP       +2                         
042275,000165: 15,3746           55546                           COS      VDEF                                  #  COS LOS
042276,000166: 15,3747           53521                           MXV      UNIT                                  
042277,000167: 15,3750           12002                                    KONMAT                                
042278,000168: 15,3751           02715                           STORE    VSUN                                  
042279,000169: 15,3752           77616                           RVQ                                            

Page 979

042281,000171: 15,3753           77745        POSITE             DLOAD                                          
042282,000172: 15,3754           12004                                    KONMAT     +2                         #  ZEROS
042283,000173: 15,3755           00027                           STORE    GTMP                                  
042284,000174: 15,3756           77650                           GOTO                                           
042285,000175: 15,3757           33705                                    POSITD                                
042286,000176: 05,2000                                           SETLOC   EPHEM1                                
042287,000177: 05,2000                                           BANK                                           
042288,000178: 
042289,000179: 05,3472                                           COUNT*   $$/EPHEM                              
042290,000180: 
042291,000181: 05,3472                        STMP               EQUALS   16D                                   
042292,000182: 
042293,000183: 05,3472                        GTMP               EQUALS   22D                                   
042294,000184: 
042295,000185: 05,3472                        TIMEP              EQUALS   24D                                   
042296,000186: 

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