Source Code

These source-code files derive from a printout of Luminary 210 (Apollo 15-17 Lunar Module guidance computer program), from the personal library of original AGC developer Don Eyles, digitally photographed at archive.org, financially sponsored by Jim Lawton, 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 210 OF AGC PROGRAM LUMINARY 
	BY NASA 2021112-161 17:11 MAR. 19,1971
Note that the date is the date of the printout, not the date of the program revision.

030785,000002:                                                                                                  ## Copyright:   Public domain.
030786,000003:                                                                                                  ## Filename:    R31.agc
030787,000004:                                                                                                  ## Purpose:     A section of Luminary revision 210.
030788,000005:                                                                                                  ##              It is part of the source code for the Lunar Module's (LM)
030789,000006:                                                                                                  ##              Apollo Guidance Computer (AGC) for Apollo 15-17.
030790,000007:                                                                                                  ##              This file is intended to be a faithful transcription, except
030791,000008:                                                                                                  ##              that the code format has been changed to conform to the
030792,000009:                                                                                                  ##              requirements of the yaYUL assembler rather than the
030793,000010:                                                                                                  ##              original YUL assembler.
030794,000011:                                                                                                  ## Reference:   pp. 706-710
030795,000012:                                                                                                  ## Assembler:   yaYUL
030796,000013:                                                                                                  ## Contact:     Ron Burkey <info@sandroid.org>.
030797,000014:                                                                                                  ## Website:     www.ibiblio.org/apollo/index.html
030798,000015:                                                                                                  ## Mod history: 2016-11-17 JL   Created from Luminary131 version.
030799,000016:                                                                                                  ##              2016-12-01 RSB  Completed.  Other than correction of typos
030800,000017:                                                                                                  ##                              in comments and change in the positioning
030801,000018:                                                                                                  ##                              of the constant V16N54, there were no changes.
030802,000019:                                                                                                  ##              2016-12-01 HG   fix operand V15N54  -> V16N54
030803,000020:                                                                                                  ##                              remove V16N54 from its old location 
030804,000021:                                                                                                  ##              2016-12-25 RSB  Comment-text proofed using ProoferComments
030805,000022:                                                                                                  ##                              and corrected errors found.
030806,000023: 

Page 706

030808,000025: 40,3741                                           BANK     40                                    
030809,000026: 40,2000                                           SETLOC   R31LOC                                
030810,000027: 40,2000                                           BANK                                           
030811,000028: 
030812,000029: 40,3741                                           COUNT*   $$/R31                                
030813,000030: 
030814,000031: 40,3741           35006        R31CALL            CAF      PRIO3                                 
030815,000032: 40,3742           05076                           TC       FINDVAC                               
030816,000033: 40,3743  E7,1470                                  EBANK=   SUBEXIT                               
030817,000034: 40,3743           03113 76067                     2CADR    V83CALL                               
030818,000035: 
030819,000036: 40,3745           05223        DSPDELAY           TC       FIXDELAY                              
030820,000037: 40,3746           00144                           DEC      100        B-14                       
030821,000038: 40,3747           31043                           CA       EXTVBACT                              
030822,000039: 40,3750           74731                           MASK     BIT12                                 
030823,000040: 40,3751           00006                           EXTEND                                         
030824,000041: 40,3752           13745                           BZF      DSPDELAY                              
030825,000042: 
030826,000043: 40,3753           35010                           CAF      PRIO5                                 
030827,000044: 40,3754           05063                           TC       NOVAC                                 
030828,000045: 40,3755  E7,1611                                  EBANK=   TSTRT                                 
030829,000046: 40,3755           03761 60107                     2CADR    DISPN5X                               
030830,000047: 
030831,000048: 40,3757           15263                           TCF      TASKOVER                              
030832,000049: 
030833,000050: 40,3760           04066        V16N54             VN       1654                                  
030834,000051: 40,3761           33760        DISPN5X            CAF      V16N54                                
030835,000052: 40,3762           04607                           TC       BANKCALL                              
030836,000053: 40,3763           20323                           CADR     GOMARKF                               
030837,000054: 40,3764           05565                           TC       B5OFF                                 
030838,000055: 40,3765           05565                           TC       B5OFF                                 
030839,000056: 40,3766           13761                           TCF      DISPN5X                               
030840,000057: 
030841,000058: 37,3113                                           BANK     37                                    
030842,000059: 37,2000                                           SETLOC   R31                                   
030843,000060: 37,2000                                           BANK                                           
030844,000061: 
030845,000062: 37,3113           40103        V83CALL            CS       FLAGWRD7                              #  TEST AVERAGE G FLAG
030846,000063: 37,3114           74740                           MASK     AVEGFBIT                              
030847,000064: 37,3115           00006                           EXTEND                                         
030848,000065: 37,3116           13371                           BZF      MUNG?                                 #  ON - TEST MUNFLAG
030849,000066: 
030850,000067: 37,3117           40104                           CS       FLAGWRD8                              
030851,000068: 37,3120           74735                           MASK     SURFFBIT                              
030852,000069: 37,3121           00006                           EXTEND                                         
030853,000070: 37,3122           13375                           BZF      ONEBASE                               #  ON SURFACE - BYPASS LEMPREC
030854,000071: 
030855,000072: 37,3123           06060                           TC       INTPRET                               #  EXTRAPOLATE BOTH STATE VECTORS
030856,000073: 37,3124           77634                           RTB                                            

Page 707

030858,000075: 37,3125           21603                                    LOADTIME                              
030859,000076: 37,3126           34041                           STCALL   TDEC1                                 
030860,000077: 37,3127           27115                                    LEMPREC                               #  PRECISION BASE VECTOR FOR LM
030861,000078: 37,3130           77775                           VLOAD                                          
030862,000079: 37,3131           00017                                    RATT1                                 
030863,000080: 37,3132           26161                           STOVL    BASETHP                               
030864,000081: 37,3133           00025                                    VATT1                                 
030865,000082: 37,3134           16104                           STODL    BASETHV                               
030866,000083: 37,3135           00015                                    TAT                                   
030867,000084: 37,3136           02113        DOCMBASE           STORE    BASETIME                              #  PRECISION BASE VECTOR FOR CM
030868,000085: 37,3137           34041                           STCALL   TDEC1                                 
030869,000086: 37,3140           27101                                    CSMPREC                               
030870,000087: 37,3141           77775                           VLOAD                                          
030871,000088: 37,3142           00017                                    RATT1                                 
030872,000089: 37,3143           26131                           STOVL    BASEOTP                               
030873,000090: 37,3144           00025                                    VATT1                                 
030874,000091: 37,3145           02172                           STORE    BASEOTV                               
030875,000092: 37,3146           77776                           EXIT                                           
030876,000093: 
030877,000094: 37,3147           40103        REV83              CS       FLAGWRD7                              
030878,000095: 37,3150           74740                           MASK     AVEGFBIT                              
030879,000096: 37,3151           00006                           EXTEND                                         
030880,000097: 37,3152           13320                           BZF      GETRVN                                #  IF AVEGFLAG SET, USE RN,VN
030881,000098: 
030882,000099: 37,3153           40104                           CS       FLAGWRD8                              
030883,000100: 37,3154           74735                           MASK     SURFFBIT                              
030884,000101: 37,3155           00006                           EXTEND                                         
030885,000102: 37,3156           13362                           BZF      R31SURF                               #  IF ON SURFACE, USE LEMAREC
030886,000103: 
030887,000104: 37,3157           06060                           TC       INTPRET                               #  DO CONIC EXTRAPOLATION FOR BOTH VEHICLES
030888,000105: 37,3160           77634                           RTB                                            
030889,000106: 37,3161           21603                                    LOADTIME                              
030890,000107: 37,3162           34041                           STCALL   TDEC1                                 
030891,000108: 37,3163           27447                                    INTSTALL                              
030892,000109: 37,3164           43175                           VLOAD    CLEAR                                 
030893,000110: 37,3165           02161                                    BASETHP                               
030894,000111: 37,3166           00263                                    MOONFLAG                              
030895,000112: 37,3167           25535                           STOVL    RCV                                   
030896,000113: 37,3170           02104                                    BASETHV                               
030897,000114: 37,3171           15543                           STODL    VCV                                   
030898,000115: 37,3172           02113                                    BASETIME                              
030899,000116: 37,3173           43014                           BOF      SET                                   #  GET APPROPRIATE MOONFLAG SETTING
030900,000117: 37,3174           04344                                    MOONTHIS                              
030901,000118: 37,3175           77177                                    +2                                    
030902,000119: 37,3176           00063                                    MOONFLAG                              
030903,000120: 37,3177           77614                           SET                                            
030904,000121: 37,3200           01473                                    INTYPFLG                              #  CONIC EXTRAP.
030905,000122: 37,3201           35517                           STCALL   TET                                   
030906,000123: 37,3202           27145                                    INTEGRVS                              #  INTEGRATION --- AT LAST---
030907,000124: 37,3203           77775        OTHCONIC           VLOAD                                          

Page 708

030909,000126: 37,3204           00001                                    RATT                                  
030910,000127: 37,3205           26200                           STOVL    RONE                                  
030911,000128: 37,3206           00007                                    VATT                                  
030912,000129: 37,3207           36206                           STCALL   VONE                                  #  GET SET FOR CONIC EXTRAP.,OTHER.
030913,000130: 37,3210           27447                                    INTSTALL                              
030914,000131: 37,3211           71214                           SET      DLOAD                                 
030915,000132: 37,3212           01473                                    INTYPFLG                              
030916,000133: 37,3213           00015                                    TAT                                   
030917,000134: 37,3214           00041        OTHINT             STORE    TDEC1                                 
030918,000135: 37,3215           43175                           VLOAD    CLEAR                                 
030919,000136: 37,3216           02131                                    BASEOTP                               
030920,000137: 37,3217           00263                                    MOONFLAG                              
030921,000138: 37,3220           25535                           STOVL    RCV                                   
030922,000139: 37,3221           02172                                    BASEOTV                               
030923,000140: 37,3222           15543                           STODL    VCV                                   
030924,000141: 37,3223           02113                                    BASETIME                              
030925,000142: 37,3224           43014                           BOF      SET                                   
030926,000143: 37,3225           04344                                    MOONTHIS                              
030927,000144: 37,3226           77230                                    +2                                    
030928,000145: 37,3227           00063                                    MOONFLAG                              
030929,000146: 37,3230           35517                           STCALL   TET                                   
030930,000147: 37,3231           27145                                    INTEGRVS                              
030931,000148: 37,3232           52375        COMPDISP           VLOAD    VSU                                   
030932,000149: 37,3233           00001                                    RATT                                  
030933,000150: 37,3234           02200                                    RONE                                  
030934,000151: 37,3235           65234                           RTB      PDDL                                  
030935,000152: 37,3236           21722                                    NORMUNX1                              #  UNIT(RANGE) TO PD 0-5
030936,000153: 37,3237           00045                                    36D                                   
030937,000154: 37,3240           77657                           SL*                                            #  RESCALE AFTER NORMUNIT
030938,000155: 37,3241           20201                                    0,1                                   
030939,000156: 37,3242           26214                           STOVL    RANGE                                 #  SCALED 2(29)M
030940,000157: 37,3243           00007                                    VATT                                  
030941,000158: 37,3244           50251                           VSU      DOT                                   #  (VCM-VLM).UNIT(LOS), PD=0
030942,000159: 37,3245           02206                                    VONE                                  
030943,000160: 37,3246           77752                           SL1                                            #  SCALED 2(7)M/CS
030944,000161: 37,3247           26216                           STOVL    RRATE                                 
030945,000162: 37,3250           02200                                    RONE                                  
030946,000163: 37,3251           63256                           UNIT     PDVL                                  #  UNIT(R) TO PD 0-5
030947,000164: 37,3252           06477                                    UNITZ                                 
030948,000165: 37,3253           77624                           CALL                                           
030949,000166: 37,3254           47653                                    CDU*NBSM                              
030950,000167: 37,3255           41505                           VXM      PUSH                                  #  UNIT(Z)/4 TO PD 6-11
030951,000168: 37,3256           01732                                    REFSMMAT                              
030952,000169: 37,3257           72431                           VPROJ    VSL2                                  #  UNIT(P)=UNIT(UZ-(UZ)PROJ(UR))
030953,000170: 37,3260           00001                                    0D                                    
030954,000171: 37,3261           53445                           BVSU     UNIT                                  
030955,000172: 37,3262           00007                                    6D                                    
030956,000173: 37,3263           47315                           PDVL     VXV                                   #  UNIT(P) TO PD 12-17
030957,000174: 37,3264           00001                                    0D                                    #  UNIT(RL)
030958,000175: 37,3265           02206                                    VONE                                  

Page 709

030960,000177: 37,3266           50235                           VXV      DOT                                   #  (UR * VL)*UR . U(P)
030961,000178: 37,3267           00001                                    0D                                    
030962,000179: 37,3270           00015                                    12D                                   
030963,000180: 37,3271           77715                           PDVL                                           #  SIGN TO 12-13 , LOAD U(P)
030964,000181: 37,3272           75241                           DOT      SIGN                                  
030965,000182: 37,3273           00007                                    6D                                    
030966,000183: 37,3274           00015                                    12D                                   
030967,000184: 37,3275           65512                           SL2      ACOS                                  #  ARCCOS(UP.UZ(SIGN))
030968,000185: 37,3276           26220                           STOVL    RTHETA                                
030969,000186: 37,3277           00001                                    0D                                    
030970,000187: 37,3300           51041                           DOT      BPL                                   #  IF UR.UZ NEG,
030971,000188: 37,3301           00007                                    6D                                    #    RTHETA = 1 - RTHETA
030972,000189: 37,3302           77307                                    +5                                    
030973,000190: 37,3303           45345                           DLOAD    DSU                                   
030974,000191: 37,3304           06513                                    DPPOSMAX                              
030975,000192: 37,3305           02220                                    RTHETA                                
030976,000193: 37,3306           02220                           STORE    RTHETA                                
030977,000194: 37,3307           77776                           EXIT                                           
030978,000195: 
030979,000196: 37,3310           34740                           CA       BIT5                                  
030980,000197: 37,3311           71043                           MASK     EXTVBACT                              
030981,000198: 37,3312           00006                           EXTEND                                         #  IF ANSWERED,
030982,000199: 37,3313           15474                           BZF      ENDEXT                                #         TERMINATE
030983,000200: 
030984,000201: 37,3314           41043                           CS       EXTVBACT                              
030985,000202: 37,3315           74731                           MASK     BIT12                                 
030986,000203: 37,3316           27043                           ADS      EXTVBACT                              #  SET BIT 12
030987,000204: 37,3317           13147                           TCF      REV83                                 #  AND START AGAIN.
030988,000205: 
030989,000206: 37,3320           37731        GETRVN             CA       PRIO22                                #  INHIBIT SERVICER
030990,000207: 37,3321           05137                           TC       PRIOCHNG                              
030991,000208: 37,3322           06060                           TC       INTPRET                               
030992,000209: 37,3323           40375                           VLOAD    SETPD                                 
030993,000210: 37,3324           01220                                    RN                                    #  LM STATE VECTOR IN RN,VN
030994,000211: 37,3325           00001                                    0                                     
030995,000212: 37,3326           26200                           STOVL    RONE                                  
030996,000213: 37,3327           01226                                    VN                                    
030997,000214: 37,3330           26206                           STOVL    VONE                                  #  LOAD R(CSM),V(CSM) IN CASE MUNFLAG SET
030998,000215: 37,3331           01724                                    V(CSM)                                #  (TO INSURE TIME COMPATABILITY)
030999,000216: 37,3332           65315                           PDVL     PDDL                                  
031000,000217: 37,3333           01716                                    R(CSM)                                
031001,000218: 37,3334           01234                                    PIPTIME                               
031002,000219: 37,3335           77776                           EXIT                                           
031003,000220: 37,3336           35006                           CA       PRIO3                                 
031004,000221: 37,3337           05137                           TC       PRIOCHNG                              
031005,000222: 37,3340           06060                           TC       INTPRET                               
031006,000223: 37,3341           77214                           BOFF     VLOAD                                 
031007,000224: 37,3342           03347                                    MUNFLAG                               
031008,000225: 37,3343           77355                                    GETRVN2                               #  IF MUNFLAG RESET, DO CM DELTA PRECISION

Page 710

031010,000227: 37,3344           60505                           VXM      VSR4                                  #  CHANGE TO REFERENCE SYSTEM AND RESCALE
031011,000228: 37,3345           01732                                    REFSMMAT                              
031012,000229: 37,3346           77715                           PDVL                                           #  R TO PD 0-5
031013,000230: 37,3347           76505                           VXM      VSL1                                  
031014,000231: 37,3350           01732                                    REFSMMAT                              
031015,000232: 37,3351           40206                           PUSH     SETPD                                 #  V TO PD 5-11
031016,000233: 37,3352           00001                                    0                                     
031017,000234: 37,3353           77650                           GOTO                                           
031018,000235: 37,3354           77232                                    COMPDISP                              
031019,000236: 
031020,000237: 37,3355           77624        GETRVN2            CALL                                           
031021,000238: 37,3356           27447                                    INTSTALL                              
031022,000239: 37,3357           52014                           CLEAR    GOTO                                  
031023,000240: 37,3360           01673                                    INTYPFLG                              #  PREC EXTRAP FOR OTHER
031024,000241: 37,3361           77214                                    OTHINT                                
031025,000242: 37,3362           06060        R31SURF            TC       INTPRET                               
031026,000243: 37,3363           77634                           RTB                                            #  LM IS ON SURFACE, SO PRECISION
031027,000244: 37,3364           21603                                    LOADTIME                              #  INTEGRATION USES PLANETARY INERTIAL
031028,000245: 37,3365           34041                           STCALL   TDEC1                                 #  ORIENTATION SUBROUTINE
031029,000246: 37,3366           27115                                    LEMPREC                               
031030,000247: 37,3367           77650                           GOTO                                           #  DO CSM CONIC
031031,000248: 37,3370           77203                                    OTHCONIC                              
031032,000249: 37,3371           40102        MUNG?              CS       FLAGWRD6                              
031033,000250: 37,3372           74735                           MASK     MUNFLBIT                              
031034,000251: 37,3373           00006                           EXTEND                                         
031035,000252: 37,3374           13320                           BZF      GETRVN                                #  IF MUNFLAG SET, CSM BASE NOT NEEDED
031036,000253: 
031037,000254: 37,3375           06060        ONEBASE            TC       INTPRET                               #  GET CSM BASE VECTOR
031038,000255: 37,3376           52034                           RTB      GOTO                                  
031039,000256: 37,3377           21603                                    LOADTIME                              
031040,000257: 37,3400           77136                                    DOCMBASE                              
031041,000258: 

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