Source Code

This source code is very close to the Apollo Guidance Computer software for the Apollo 13 Lunar module. This revision of the Luminary 131 program is from December of 1969, whereas there was a later revision in January of 1970, and still another revision in February, which is the code that flew on the mission. As far as this transcription is concerned, it was originally from a copy made in 1991 of a printout from the collection of AGC developer Don Eyles for collector David Craig. It was subsequently scanned by Gary Neff, reprocessed for online presentation at the now-discontinued History of Recent Science and Technology (HRST) website of MIT's Dibner Institute (the full-quality scans being discarded in the process), and finally transcribed by Ron Burkey for the Virtual AGC Project. Although a high-quality replacement scan for a completely illegible page was later provided by Gary Neff, the reduced legibility of the reprocessed HRST posting nevertheless caused many errors to be introduced into the transcription. Accordingly, a second scan of the same physical printout was made in 2017 for the Virtual AGC Project's collection at the Internet Archive, and used to correct the transcription errors. All of the scanned materials mentioned, as well as other Luminary 131 related material, are available online. Don Eyles apprently made additional hand-written notes in printout between 1991 and 2017, so the two scans are not identical in that respect. The page-headings in the printout read, in part:
	GAP:  ASSEMBLE REVISION 131 OF AGC PROGRAM LUMINARY BY NASA 2021112-091
	17:53 DEC. 19, 1969
Note that the date is the date the printout was made, not the date on which the program revision was released, although these happen to be very close together.

041864,000002:                                                                                                  ## Copyright:   Public domain.
041865,000003:                                                                                                  ## Filename:    LUNAR_AND_SOLAR_EPHEMERIDES_SUBROUTINES.agc
041866,000004:                                                                                                  ## Purpose:     A section of Luminary 1C, revision 131.
041867,000005:                                                                                                  ##              It is part of the source code for the Lunar Module's (LM)
041868,000006:                                                                                                  ##              Apollo Guidance Computer (AGC) for Apollo 13.
041869,000007:                                                                                                  ##              This file is intended to be a faithful transcription, except
041870,000008:                                                                                                  ##              that the code format has been changed to conform to the
041871,000009:                                                                                                  ##              requirements of the yaYUL assembler rather than the
041872,000010:                                                                                                  ##              original YUL assembler.
041873,000011:                                                                                                  ## Reference:   pp. 978-981
041874,000012:                                                                                                  ## Contact:     Ron Burkey <info@sandroid.org>.
041875,000013:                                                                                                  ## Website:     www.ibiblio.org/apollo/index.html
041876,000014:                                                                                                  ## Mod history: 05/29/03 RSB.   Began transcribing.
041877,000015:                                                                                                  ##              05/14/05 RSB    Corrected website reference above.
041878,000016:                                                                                                  ##              2017-01-06 RSB  Page numbers now agree with those on the
041879,000017:                                                                                                  ##                              original hardcopy, as opposed to the PDF page
041880,000018:                                                                                                  ##                              numbers in 1701.pdf.
041881,000019:                                                                                                  ##              2017-02-26 RSB  Proofed comment text using octopus/ProoferComments.
041882,000020:                                                                                                  ##              2017-03-13 RSB  Comment-text fixes noted in proofing Luminary 116.
041883,000021:                                                                                                  ##              2017-08-26 MAS  Fixed comment-text errors found while transcribing Zerlina 56.
041884,000022: 

Page 978

041886,000024:                                                                                                  #  NAME - LSPOS - LOCATE SUN AND MOON                    DATE - 25 OCT 67
041887,000025:                                                                                                  #  MOD NO.1
041888,000026:                                                                                                  #  MOD BY NEVILLE                                        ASSEMBLY SUNDANCE
041889,000027: 
041890,000028:                                                                                                  #  FUNCTIONAL DESCRIPTION
041891,000029: 
041892,000030:                                                                                                  #  COMPUTES UNIT POSITION VECTOR OF THE SUN AND MOON IN THE BASIC REFERENCE SYSTEM.  THE SUN VECTOR S IS
041893,000031:                                                                                                  #  LOCATED VIA TWO ANGLES.  THE FIRST ANGLE (OBLIQUITY) IS THE ANGLE BETWEEN THE EARTH EQUATOR AND THE ECLIPTIC. THE
041894,000032:                                                                                                  #  SECOND ANGLE IS THE LONGITUDE OF THE SUN MEASURED IN THE ECLIPTIC.
041895,000033:                                                                                                  #  THE POSITION VECTOR OF THE SUN IS
041896,000034:                                                                                                  #        -
041897,000035:                                                                                                  #        S = (COS(LOS), COS(OBL)*SIN(LOS), SIN(OBL)*SIN(LOS)), WHERE
041898,000036: 
041899,000037:                                                                                                  #        LOS = LOS +LOS *T-(C *SIN(2PI*T)/365.24 +C *COS(2PI*T)/365.24)
041900,000038:                                                                                                  #                 0    R     0                     1
041901,000039:                                                                                                  #        LOS  (RAD) IS THE LONGITUDE OF THE SUN FOR MIDNIGHT JUNE 30TH OF THE PARTICULAR YEAR.
041902,000040:                                                                                                  #           0
041903,000041:                                                                                                  #        LOS  (RAD/DAY) IS THE MEAN RATE FOR THE PARTICULAR YEAR.
041904,000042:                                                                                                  #           R
041905,000043: 
041906,000044:                                                                                                  #  LOS  AND LOS  ARE STORED AS LOSC AND LOSR IN RATESP.
041907,000045:                                                                                                  #     0        R
041908,000046:                                                                                                  #  COS(OBL) AND SIN(OBL) ARE STORED IN THE MATRIX KONMAT.
041909,000047: 
041910,000048:                                                                                                  #  T, TIME MEASURED IN DAYS (24 HOURS), IS STORED IN TIMEP.
041911,000049: 
041912,000050:                                                                                                  #  C  AND C  ARE FUDGE FACTORS TO MINIMIZE THE DEVIATION.  THEY ARE STORED AS ONE CONSTANT (CMOD), SINCE
041913,000051:                                                                                                  #   0      1                               2  2 1/2
041914,000052:                                                                                                  #  C *SIN(X)+C *COS(X) CAN BE WRITTEN AS (C +C )   *SIN(X+PHI), WHERE PHI=ARCTAN(C /C ).
041915,000053:                                                                                                  #   0         1                            0  1                                   1  0
041916,000054: 
041917,000055:                                                                                                  #  THE MOON IS LOCATED VIA FOUR ANGLES. THE FIRST IS THE OBLIQUITY. THE SECOND IS THE MEAN LONGITUDE OF THE MOON,
041918,000056:                                                                                                  #  MEASURED IN THE ECLIPTIC FROM THE MEAN EQUINOX TO THE MEAN ASCENDING NODE OF THE LUNAR ORBIT, AND THEN ALONG THE
041919,000057:                                                                                                  #  ORBIT.  THE THIRD ANGLE IS THE ANGLE BETWEEN THE ECLIPTIC AND THE LUNAR ORBIT.  THE FOURTH ANGLE IS THE LONGITUDE
041920,000058:                                                                                                  #  OF THE NODE OF THE MOON, MEASURED IN THE LUNAR ORBIT.  LET THESE ANGLES BE OBL,LOM,IM, AND LON RESPECTIVELY.
041921,000059: 
041922,000060:                                                                                                  #  THE SIMPLIFIED POSITION VECTOR OF THE MOON IS
041923,000061:                                                                                                  #        -
041924,000062:                                                                                                  #        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))
041925,000063: 
041926,000064:                                                                                                  #  WHERE
041927,000065:                                                                                                  #        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
041928,000066:                                                                                                  #               0    R     0                    1                     0               1
041929,000067:                                                                                                  #        LON=LON +LON
041930,000068:                                                                                                  #               0    R
041931,000069:                                                                                                  #  A , A , B  AND B  ARE STORED AS AMOD AND BMOD (SEE DESCRIPTION OF CMOD, ABOVE).  COS(OBL), SIN(OBL)*SIN(IM),
041932,000070:                                                                                                  #   0   1   0      1
041933,000071:                                                                                                  #  SIN(OBL), AND COS(OBL)*SIN(IM) ARE STORED IN KONMAT AS K1, K2, K3  AND K4, RESPECTIVELY.  LOM , LOM , LON , LON
041934,000072:                                                                                                  #  ARE STORED AS LOMO, LOMR, LONO, AND LONR IN RATESP.                                          0     R     0     R
041935,000073: 
041936,000074:                                                                                                  #  THE THREE PHIS ARE STORED AS AARG, BARG, AND CARG(SUN).  ALL CONSTANTS ARE UPDATED BY YEAR.
041937,000075: 
041938,000076:                                                                                                  #  CALLING SEQUENCE

Page 979

041940,000078:                                                                                                  #        CALL LSPOS.  RETURN IS VIA CPRET.
041941,000079: 
041942,000080:                                                                                                  #  ALARMS OR ABORTS
041943,000081:                                                                                                  #        NONE
041944,000082: 
041945,000083:                                                                                                  #  ERASABLE INITIALIZATION REQUIRED
041946,000084:                                                                                                  #        TEPHEM - TIME FROM MIDNIGHT 1 JULY PRECEDING THE LAUNCH TO THE TIME OF THE LAUNCH (WHEN THE AGC CLOCK WENT
041947,000085:                                                                                                  #        TO ZERO).  TEPHEM IS TP WITH UNITS OF CENTI-SECONDS.
041948,000086: 
041949,000087:                                                                                                  #        TIME2 AND TIME1 ARE IN MPAC AND MPAC +1 WHEN PROGRAM IS CALLED.
041950,000088: 
041951,000089:                                                                                                  #  OUTPUT
041952,000090:                                                                                                  #        UNIT POSITIONAL VECTOR OF SUN IN VSUN.  (SCALED B-1)
041953,000091:                                                                                                  #        UNIT POSITIONAL VECTOR OF MOON IN VMOON.  (SCALED B-1)
041954,000092: 
041955,000093:                                                                                                  #  SUBROUTINES USED
041956,000094:                                                                                                  #        NONE
041957,000095: 
041958,000096:                                                                                                  #  DEBRIS
041959,000097:                                                                                                  #        CURRENT CORE SET, WORK AREA AND FREEFLAG
041960,000098: 
041961,000099: 04,2773                                           BANK     04                                    
041962,000100: 15,2000                                           SETLOC   EPHEM                                 
041963,000101: 15,2000                                           BANK                                           
041964,000102: 
041965,000103: 15,3647  E5,1714                                  EBANK=   VSUN                                  
041966,000104: 15,3647                                           COUNT*   $$/EPHEM                              
041967,000105: 15,3647  15,3647               LUNPOS             EQUALS   LSPOS                                 
041968,000106: 
041969,000107: 15,3647           54201        LSPOS              SETPD    SR                                    
041970,000108: 15,3650           00001                                    0                                     
041971,000109: 15,3651           20617                                    14D                                   #  TP
041972,000110: 15,3652           56371                           TAD      DDV                                   
041973,000111: 15,3653           01707                                    TEPHEM                                #  TIME OF LAUNCH
041974,000112: 15,3654           12024                                    CSTODAY                               #  24 HOURS-8640000 CENTI-SECS/DAY B-33
041975,000113: 15,3655           00031                           STORE    TIMEP                                 #  T IN DAYS
041976,000114: 15,3656           77170                           AXT,1    AXT,2                                 
041977,000115: 15,3657           00000                                    0                                     
041978,000116: 15,3660           00000                                    0                                     
041979,000117: 15,3661           77614                           CLEAR                                          
041980,000118: 15,3662           00274                                    FREEFLAG                              #  SWITCH BIT
041981,000119: 15,3663           77745        POSITA             DLOAD                                          
041982,000120: 15,3664           12004                                    KONMAT     +2                         #  ZEROS
041983,000121: 15,3665           00027                           STORE    GTMP                                  
041984,000122: 15,3666           40745        POSITB             DLOAD    DMP*                                  
041985,000123: 15,3667           00031                                    TIMEP                                 #  T
041986,000124: 15,3670           12050                                    VAL67      +4,1                       #  1/27 OR 1/32 OR 1/365

Page 980

041988,000126: 15,3671           42661                           SL       DAD*                                  
041989,000127: 15,3672           20211                                    8D                                    
041990,000128: 15,3673           12046                                    VAL67      +2,1                       #  AARG
041991,000129: 15,3674           40756                           SIN      DMP*                                  #  SIN(T/27+PHI) OR T/32 OR T/365
041992,000130: 15,3675           12044                                    VAL67,1                               #  (A0**2+A1**2)**1/2 SIN(X+PHIA)
041993,000131: 15,3676           62015                           DAD      INCR,1                                #  PLUS
041994,000132: 15,3677           00027                                    GTMP                                  #  (B0**2+B1**2)**1/2 SIN(X+PHIB)
041995,000133: 15,3700           77771                           DEC      -6         B-14                       
041996,000134: 15,3701           00027                           STORE    GTMP                                  #  OR (C0**2+C1**2)**1/2 SIN(X+PHIC)
041997,000135: 15,3702           77614                           BOFSET                                         
041998,000136: 15,3703           00054                                    FREEFLAG                              
041999,000137: 15,3704           33666                                    POSITB                                
042000,000138: 15,3705           40745        POSITD             DLOAD    DMP*                                  
042001,000139: 15,3706           00031                                    TIMEP                                 #  T
042002,000140: 15,3707           65747                                    RATESP,2                              #  LOMR,LOSR,LONR
042003,000141: 15,3710           42661                           SL       DAD*                                  
042004,000142: 15,3711           20206                                    5D                                    
042005,000143: 15,3712           65741                                    RATESP     +6,2                       #  LOMO,LOSO,LONO
042006,000144: 15,3713           77625                           DSU                                            
042007,000145: 15,3714           00027                                    GTMP                                  
042008,000146: 15,3715           10021                           STORE    STMP,2                                #  LOM,LOS,LON
042009,000147: 15,3716           63135                           SLOAD    INCR,2                                
042010,000148: 15,3717           00050                                    X2                                    
042011,000149: 15,3720           77775                           DEC      -2         B-14                       
042012,000150: 15,3721           53015                           DAD      BZE                                   
042013,000151: 15,3722           12026                                    RCB-13                                #  PLUS 2
042014,000152: 15,3723           33753                                    POSITE                                #  2ND
042015,000153: 15,3724           77644                           BPL                                            
042016,000154: 15,3725           33663                                    POSITA                                #  1ST
042017,000155: 15,3726           45345        POSITF             DLOAD    DSU                                   #  3RD
042018,000156: 15,3727           00021                                    STMP                                  #  LOM
042019,000157: 15,3730           00025                                    STMP       +4                         #  LON
042020,000158: 15,3731           65356                           SIN      PDDL                                  #  SIN(LOM-LON)
042021,000159: 15,3732           00021                                    STMP                                  
042022,000160: 15,3733           65356                           SIN      PDDL                                  #  SIN LOM
042023,000161: 15,3734           00021                                    STMP                                  
042024,000162: 15,3735           55546                           COS      VDEF                                  #  COS LOM
042025,000163: 15,3736           53521                           MXV      UNIT                                  
042026,000164: 15,3737           12002                                    KONMAT                                #  K1,K2,K3,K4,
042027,000165: 15,3740           02723                           STORE    VMOON                                 
042028,000166: 15,3741           65345                           DLOAD    PDDL                                  
042029,000167: 15,3742           12004                                    KONMAT     +2                         #  ZERO
042030,000168: 15,3743           00023                                    STMP       +2                         
042031,000169: 15,3744           65356                           SIN      PDDL                                  #  SIN LOS
042032,000170: 15,3745           00023                                    STMP       +2                         
042033,000171: 15,3746           55546                           COS      VDEF                                  #  COS LOS
042034,000172: 15,3747           53521                           MXV      UNIT                                  
042035,000173: 15,3750           12002                                    KONMAT                                
042036,000174: 15,3751           02715                           STORE    VSUN                                  
042037,000175: 15,3752           77616                           RVQ                                            

Page 981

042039,000177: 15,3753           77745        POSITE             DLOAD                                          
042040,000178: 15,3754           12004                                    KONMAT     +2                         #  ZEROS
042041,000179: 15,3755           00027                           STORE    GTMP                                  
042042,000180: 15,3756           77650                           GOTO                                           
042043,000181: 15,3757           33705                                    POSITD                                
042044,000182: 05,2000                                           SETLOC   EPHEM1                                
042045,000183: 05,2000                                           BANK                                           
042046,000184: 
042047,000185: 05,3505                                           COUNT*   $$/EPHEM                              
042048,000186: 05,3505                        STMP               EQUALS   16D                                   
042049,000187: 05,3505                        GTMP               EQUALS   22D                                   
042050,000188: 05,3505                        TIMEP              EQUALS   24D                                   
042051,000189: 

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