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.

058208,000002:                                                                                                  ## Copyright:   Public domain.
058209,000003:                                                                                                  ## Filename:    TRIM_GIMBAL_CONTROL_SYSTEM.agc
058210,000004:                                                                                                  ## Purpose:     A section of a reconstructed, mixed version of Sundance
058211,000005:                                                                                                  ##              It is part of the reconstructed source code for the Lunar
058212,000006:                                                                                                  ##              Module's (LM) Apollo Guidance Computer (AGC) for Apollo 9.
058213,000007:                                                                                                  ##              No original listings of this program are available;
058214,000008:                                                                                                  ##              instead, this file was created via disassembly of dumps
058215,000009:                                                                                                  ##              of various revisions of Sundance core rope modules.
058216,000010:                                                                                                  ## Assembler:   yaYUL
058217,000011:                                                                                                  ## Contact:     Ron Burkey <info@sandroid.org>.
058218,000012:                                                                                                  ## Website:     www.ibiblio.org/apollo/index.html
058219,000013:                                                                                                  ## Mod history: 2020-06-17 MAS  Created from Luminary 69.
058220,000014:                                                                                                  ##              2021-05-30 ABS  GTSGO+DN -> GTSGO+ON
058221,000015:                                                                                                  ##                              MAXISHIFT -> MAXISHFT
058222,000016:                                                                                                  ##                              MINISHIFT -> MINISHFT
058223,000017: 
058224,000018:                                                                                                  ## Sundance 302
058225,000019: 
058226,000020: 21,3055                                           BANK     21                                    
058227,000021: 21,3055  E6,1451                                  EBANK=   QDIFF                                 
058228,000022: 21,2000                                           SETLOC   DAPS4                                 
058229,000023: 21,2000                                           BANK                                           
058230,000024: 
058231,000025: 21,3055                                           COUNT*   $$/DAPGT                              
058232,000026: 
058233,000027:                                                                                                  #  CONTROL REACHES THIS POINT UNDER EITHER OF THE FOLLOWING TWO CONDITIONS ONCE THE DESCENT ENGINE AND THE DIGITAL
058234,000028:                                                                                                  #  AUTOPILOT ARE BOTH ON:
058235,000029:                                                                                                  #        A) THE TRIM GIMBAL CONTROL LAW WAS ON DURING THE PREVIOUS Q,R-AXIS TIME5 INTERRUPT (OR THE DAPIDLER
058236,000030:                                                                                                  #           INITIALIZATION WAS SET FOR TRIM GIMBAL CONTROL AND THIS IS THE FIRST PASS), OR
058237,000031:                                                                                                  #        B) THE Q,R-AXES RCS AUTOPILOT DETERMINED THAT THE VEHICLE WAS ENTERING (OR HAD JUST ENTERED) A COAST
058238,000032:                                                                                                  #           ZONE WITH A SMALL OFFSET ANGULAR ACCELERATION.
058239,000033:                                                                                                  #  GTS IS THE ENTRY TO THE GIMBAL TRIM SYSTEM FOR CONTROLLING ATTITUDE ERRORS AND RATES AS WELL AS ACCELERATIONS.
058240,000034: 
058241,000035: 21,3055           37721        GTS                CAF      NEGONE                                #  MAKE THE NEXT PASS THROUGH THE DAP BE
058242,000036: 21,3056           55625                           TS       COTROLER                              #        THROUGH RCS CONTROL,
058243,000037: 21,3057           35024                           CAF      FOUR                                  #        AND ENSURE THAT IT IS NOT A SKIP.
058244,000038: 21,3060           55530                           TS       SKIPU                                 
058245,000039: 21,3061           55531                           TS       SKIPV                                 
058246,000040: 
058247,000041: 21,3062           35025                           CAF      TWO                                   
058248,000042: 21,3063           55627                           TS       INGTS                                 #  SET INDICATOR OF GTS CONTROL POSITIVE.
058249,000043: 21,3064           55626                           TS       QGIMTIMR                              #  SET TIMERS TO 200 MSEC TO AVOID BOTH
058250,000044: 21,3065           55630                           TS       RGIMTIMR                              #  RUNAWAY AND INTERFERENCE BY NULLING.
058251,000045: 
058252,000046:                                                                                                  #  THE DRIVE SETTING ALGORITHM
058253,000047: 
058254,000048:                                                                                                  #        DEL = SGN(OMEGA*K + ALPHA*ABS(ALPHA)/2).
058255,000049: 
058256,000050:                                                                                                  #        NEGUSUM = ERROR.K(2) + DEL(OMEGA.K.DEL + ALPHA(2)/2)(3/2) + ALPHA(OMEGA.K.DEL + ALPHA(2)/3)
058257,000051: 
058258,000052:                                                                                                  #        DRIVE = -SGN(NEGUSUM)
058259,000053: 
058260,000054: 21,3066           30021                           CA       SR                                    #  SAVE THE SR.  SHIFT IT LEFT TO CORRECT
058261,000055: 21,3067           60000                           AD       A                                     #  FOR THE RIGHT SHIFT DUE TO EDITING.
058262,000056: 21,3070           55471                           TS       SAVESR                                
058263,000057: 
058264,000058: 21,3071           35025        GTSGO+ON           CAF      TWO                                   #  SET INDEXER FOR R-AXIS CALCULATIONS.
058265,000059: 21,3072           55745                           TS       QRCNTR                                
058266,000060: 21,3073           31534                           CA       AOSR                                  
058267,000061: 21,3074           00006                           EXTEND                                         
058268,000062: 21,3075           75024                           MP       BIT3                                  
058269,000063: 21,3076           31435                           CA       EDOTR                                 
058270,000064: 21,3077           13106                           TCF      GTSQAXIS                              
058271,000065: 
058272,000066: 21,3100           35030        GOQTRIMG           CAF      ZERO                                  #  SET INDEXER FOR Q-AXIS CALCULATIONS
058273,000067: 21,3101           55745                           TS       QRCNTR                                
058274,000068: 21,3102           31532                           CA       AOSQ                                  
058275,000069: 21,3103           00006                           EXTEND                                         
058276,000070: 21,3104           75024                           MP       BIT3                                  
058277,000071: 21,3105           31434                           CA       EDOTQ                                 
058278,000072: 21,3106           53743        GTSQAXIS           DXCH     WCENTRAL                              
058279,000073: 21,3107           00006                           EXTEND                                         
058280,000074: 21,3110           51745                           INDEX    QRCNTR                                #  PICK UP K AND K(2) FOR THIS AXIS
058281,000075: 21,3111           31504                           DCA      KQ                                    
058282,000076: 21,3112           53741                           DXCH     KCENTRAL                              
058283,000077: 
058284,000078: 21,3113           11745                           CCS      QRCNTR                                
058285,000079: 21,3114           50000                           INDEX    A                                     #  QDIFF, RDIFF ARE STORED IN D.P.
058286,000080: 21,3115           31451                           CAE      QDIFF                                 
058287,000081: 
058288,000082: 21,3116           00006        ALGORTHM           EXTEND                                         #  Q(R)DIFF IS THETA (ERROR) SCALED AT PI.
058289,000083: 21,3117           71741                           MP       K2CNTRAL                              #  FORM K(2)*THETA IN D.P.
058290,000084: 21,3120           23734                           LXCH     K2THETA                               
058291,000085: 21,3121           00006                           EXTEND                                         #  FORM K(2)*THETA*SF2 IN D.P.
058292,000086: 21,3122           75016                           MP       BIT9                                  
058293,000087: 21,3123           53735                           DXCH     K2THETA                               
058294,000088: 21,3124           00006                           EXTEND                                         
058295,000089: 21,3125           75016                           MP       BIT9                                  
058296,000090: 21,3126           27735                           ADS      K2THETA    +1                         
058297,000091: 
058298,000092: 21,3127           31742                           CAE      WCENTRAL                              #  GET OMEGA
058299,000093: 21,3130           00006                           EXTEND                                         
058300,000094: 21,3131           71740                           MP       KCENTRAL                              #  FORM K*OMEGA IN D.P.
058301,000095: 21,3132           23740                           LXCH     OMEGA.K                               
058302,000096: 21,3133           00006                           EXTEND                                         #  FORM OMEGA*K*SF1 IN D.P.
058303,000097: 21,3134           75013                           MP       BIT12                                 
058304,000098: 21,3135           53741                           DXCH     OMEGA.K                               
058305,000099: 21,3136           00006                           EXTEND                                         
058306,000100: 21,3137           75013                           MP       BIT12                                 
058307,000101: 21,3140           27741                           ADS      OMEGA.K    +1                         
058308,000102: 
058309,000103: 21,3141           31743                           CAE      ACENTRAL                              #  FORM ALPHA(2)/2 IN D.P.
058310,000104: 21,3142           00006                           EXTEND                                         
058311,000105: 21,3143           70000                           SQUARE                                         
058312,000106: 21,3144           53737                           DXCH     A2CNTRAL                              
058313,000107: 
058314,000108: 21,3145           31743                           CAE      ACENTRAL                              #  GET ALPHA*ABS(ALPHA)/2, IF ALPHA GREATER
058315,000109:                                                                                                  #  THAN 0. OTHERWISE TAKE NEGATIVE OF ABOVE
058316,000110: 21,3146           00006                           EXTEND                                         
058317,000111: 21,3147           63153                           BZMF     +4                                    
058318,000112: 21,3150           00006                           EXTEND                                         
058319,000113: 21,3151           31737                           DCA      A2CNTRAL                              
058320,000114: 21,3152           13155                           TCF      +3                                    
058321,000115: 21,3153           00006                           EXTEND                                         
058322,000116: 21,3154           41737                           DCS      A2CNTRAL                              
058323,000117: 21,3155           53474                           DXCH     FUNCTION                              #  SAVE AS SGN(ALPHA)*ALPHA(2)/2
058324,000118: 21,3156           00006                           EXTEND                                         
058325,000119: 21,3157           31741                           DCA      OMEGA.K                               
058326,000120: 21,3160           21474                           DAS      FUNCTION                              #  FORM FUNCT1
058327,000121: 
058328,000122: 21,3161           11473                           CCS      FUNCTION                              #  DEL = +1 FOR FUNCT1 GREATER THAN ZERO.
058329,000123: 21,3162           13166                           TCF      POSFNCT1                              #  OTHERWISE DEL = -1
058330,000124: 21,3163           13165                           TCF      +2                                    
058331,000125: 21,3164           13170                           TCF      NEGFNCT1                              
058332,000126: 
058333,000127: 21,3165           11474                           CCS      FUNCTION   +1                         #  USE LOW ORDER WORD SINCE HIGH IS ZERO
058334,000128: 21,3166           35026        POSFNCT1           CAF      BIT1                                  
058335,000129: 21,3167           13171                           TCF      +2                                    
058336,000130: 21,3170           45026        NEGFNCT1           CS       BIT1                                  
058337,000131: 21,3171           55744                           TS       DEL                                   
058338,000132: 
058339,000133: 21,3172           11744                           CCS      DEL                                   #  MAKE OMEGA*K REALLY DEL*OMEGA*K
058340,000134: 21,3173           13200                           TCF      FUNCT2                                #  (NOTHING NEED BE DONE)
058341,000135: 21,3174           13200                           TCF      FUNCT2                                
058342,000136: 21,3175           00006                           EXTEND                                         
058343,000137: 21,3176           41741                           DCS      OMEGA.K                               
058344,000138: 21,3177           53741                           DXCH     OMEGA.K                               #  CHANGE SIGN OF OMEGA*K
058345,000139: 
058346,000140: 21,3200           00006        FUNCT2             EXTEND                                         
058347,000141: 21,3201           31741                           DCA      OMEGA.K                               
058348,000142: 21,3202           53474                           DXCH     FUNCTION                              #  DEL*OMEGA*K
058349,000143: 21,3203           00006                           EXTEND                                         
058350,000144: 21,3204           31737                           DCA      A2CNTRAL                              
058351,000145: 21,3205           21474                           DAS      FUNCTION                              #  DEL*OMEGA*K + ALPHA(2)/2
058352,000146: 21,3206           31736        FUNCT3             CAE      A2CNTRAL                              #  CALCULATE (2/3)*ALPHA(2)/2 = ALPHA(2)/3
058353,000147: 21,3207           00006                           EXTEND                                         
058354,000148: 21,3210           73302                           MP       .66667                                
058355,000149: 21,3211           53737                           DXCH     A2CNTRAL                              
058356,000150: 21,3212           56001                           XCH      L                                     
058357,000151: 21,3213           00006                           EXTEND                                         
058358,000152: 21,3214           73302                           MP       .66667                                
058359,000153: 21,3215           27737                           ADS      A2CNTRAL   +1                         
058360,000154: 21,3216           54001                           TS       L                                     
058361,000155: 21,3217           13221                           TCF      +2                                    
058362,000156: 21,3220           27736                           ADS      A2CNTRAL                              
058363,000157: 21,3221           53741                           DXCH     OMEGA.K                               #  DEL*OMEGA*K + ALPHA(2)/3 = G
058364,000158: 21,3222           21737                           DAS      A2CNTRAL                              
058365,000159: 21,3223           31736                           CAE      A2CNTRAL                              #  G*ALPHA IN D.P.
058366,000160: 21,3224           00006                           EXTEND                                         
058367,000161: 21,3225           71743                           MP       ACENTRAL                              
058368,000162: 21,3226           53737                           DXCH     A2CNTRAL                              
058369,000163: 21,3227           56001                           XCH      L                                     
058370,000164: 21,3230           00006                           EXTEND                                         
058371,000165: 21,3231           71743                           MP       ACENTRAL                              
058372,000166: 21,3232           27737                           ADS      A2CNTRAL   +1                         
058373,000167: 21,3233           54001                           TS       L                                     
058374,000168: 21,3234           13236                           TCF      +2                                    
058375,000169: 21,3235           27736                           ADS      A2CNTRAL                              
058376,000170: 
058377,000171: 21,3236           53737                           DXCH     A2CNTRAL                              #  FIRST AND THIRD TERMS
058378,000172: 21,3237           21735                           DAS      K2THETA                               #  SUMMED IN D.P.
058379,000173: 
058380,000174: 21,3240           13410                           TCF      RSTOFGTS                              
058381,000175: 
058382,000176:                                                                                                  #  THE WRCHN12 SUBROUTINE SETS BITS 9,10,11,12 OF CHANNEL 12 ON THE BASIS OF THE CONTENTS OF NEGUQ,NEGUR WHICH ARE
058383,000177:                                                                                                  #  THE NEGATIVES OF THE DESIRED ACCELERATION CHANGES.  ACDT+C12 SETS Q(R)ACCDOT TO REFLECT THE NEW DRIVES.
058384,000178: 
058385,000179:                                                                                                  #  WARNING:  ACDT+C12 AND WRCHN12 MUST BE CALLED WITH INTERRUPT INHIBITED.
058386,000180: 
058387,000181: 21,3241           07400        BGIM               OCTAL    07400                                 
058388,000182: 21,3242     0066               CHNL12             EQUALS   ITEMP6                                
058389,000183: 21,3242           31102        ACDT+C12           CA       DAPBOOLS                              
058390,000184: 21,3243           75011                           MASK     USEQRJTS                              
058391,000185: 21,3244           00006                           EXTEND                                         
058392,000186: 21,3245           13251                           BZF      +4                                    
058393,000187: 21,3246           35030                           CAF      ZERO                                  
058394,000188: 21,3247           55500                           TS       NEGUQ                                 
058395,000189: 21,3250           55502                           TS       NEGUR                                 
058396,000190: 
058397,000191: 21,3251           41500                           CS       NEGUQ                                 
058398,000192: 21,3252           00006                           EXTEND                                         #  GIMBAL DRIVE REQUESTS.
058399,000193: 21,3253           71507                           MP       ACCDOTQ                               
058400,000194: 21,3254           23510                           LXCH     QACCDOT                               
058401,000195: 21,3255           41502                           CS       NEGUR                                 
058402,000196: 21,3256           00006                           EXTEND                                         
058403,000197: 21,3257           71511                           MP       ACCDOTR                               
058404,000198: 21,3260           23512                           LXCH     RACCDOT                               
058405,000199: 
058406,000200: 21,3261           11500                           CCS      NEGUQ                                 
058407,000201: 21,3262           35015                           CAF      BIT10                                 
058408,000202: 21,3263           13265                           TCF      +2                                    
058409,000203: 21,3264           35016                           CAF      BIT9                                  
058410,000204: 21,3265           54066                           TS       CHNL12                                
058411,000205: 
058412,000206: 21,3266           11502                           CCS      NEGUR                                 
058413,000207: 21,3267           35013                           CAF      BIT12                                 
058414,000208: 21,3270           13272                           TCF      +2                                    
058415,000209: 21,3271           35014                           CAF      BIT11                                 
058416,000210: 21,3272           26066                           ADS      CHNL12                                #  (STORED RESULT NOT USED AT PRESENT)
058417,000211: 
058418,000212: 21,3273           43241                           CS       BGIM                                  
058419,000213: 21,3274           00006                           EXTEND                                         
058420,000214: 21,3275           03012                           WAND     CHAN12                                
058421,000215: 21,3276           30066                           CA       CHNL12                                
058422,000216: 21,3277           00006                           EXTEND                                         
058423,000217: 21,3300           05012                           WOR      CHAN12                                
058424,000218: 
058425,000219: 21,3301           00002                           TC       Q                                     #  RETURN TO CALLER.
058426,000220: 
058427,000221: 21,3302                                           BANK     21                                    
058428,000222: 21,3302  E6,1451                                  EBANK=   QDIFF                                 
058429,000223: 21,2000                                           SETLOC   DAPS4                                 
058430,000224: 21,2000                                           BANK                                           
058431,000225: 
058432,000226:                                                                                                  #  SUBROUTINE TIMEGMBL:  MOD 0, OCTOBER 1967, CRAIG WORK
058433,000227: 
058434,000228:                                                                                                  #  TIMEGMBL COMPUTES THE DRIVE TIME NEEDED FOR THE TRIM GIMBAL TO POSITION THE DESCENT ENGINE NOZZLE SO AS TO NULL
058435,000229:                                                                                                  #  THE OFFSET ANGULAR ACCELERATION ABOUT THE Q (OR R) AXIS.  INSTEAD OF USING AOSQ(R), TIMEGMBL USES .4*AOSQ(R),
058436,000230:                                                                                                  #  SCALED AT PI/8.                         FOR EACH AXIS, THE DRIVE TIME IS COMPUTED AS ABS(ALPHA/ACCDOT).  A ZERO
058437,000231:                                                                                                  #  ALPHA OR ACCDOT OR A ZERO QUOTIENT TURNS OFF THE GIMBAL DRIVE IMMEDIATELY.  OTHERWISE, THE GIMBAL IS TURNED ON
058438,000232:                                                                                                  #  DRIVING IN THE CORRECT DIRECTION. THE Q(R)GIMTIMR IS SET TO TERMINATE THE DRIVE AND Q(R)ACCDOT
058439,000233:                                                                                                  #  IS STORED TO REFLECT THE NEW ACCELERATION DERIVATIVE.  NEGUQ(R) WILL CONTAIN +1,+0,-1 FOR A Q(R)ACCDOT VALUE
058440,000234:                                                                                                  #  WHICH IS NEGATIVE, ZERO, OR POSITIVE.
058441,000235: 
058442,000236:                                                                                                  #  INPUTS:       AOSQ,AOSR, SCALED AT P1/2, AND ACCDOTQ, ACCDOTR AT PI/2(7).     PI/2(7).
058443,000237: 
058444,000238:                                                                                                  #  OUTPUTS:      NEW GIMBAL DRIVE BITS IN CHANNEL 12,NEGUQ,NEGUR,QACCDOT AND RACCDOT, THE LAST SCALED AT PI/2(7).
058445,000239:                                                                                                  #                Q(R)GIMTIMR WILL BE SET TO TIME AND TERMINATE GIMBAL DRIVE(S)
058446,000240: 
058447,000241:                                                                                                  #  DEBRIS:       A,L,Q, ITEMPS 2,3,6, RUPTREG2 AND ACDT+C12 DEBRIS.
058448,000242: 
058449,000243:                                                                                                  #  EXITS:        VIA TC Q.
058450,000244: 
058451,000245:                                                                                                  #  ALARMS, ABORTS, :  NONE
058452,000246: 
058453,000247:                                                                                                  #  SUBROUTINES:  ACDT+C12, IBNKCALL
058454,000248: 
058455,000249:                                                                                                  #  WARNING:      THIS SUBROUTINE WRITES INTO CHANNEL 12 AND USES THE ITEMPS.  THEREFORE IT MAY ONLY BE CALLED WITH
058456,000250:                                                                                                  #  INTERRUPT INHIBITED.
058457,000251: 
058458,000252:                                                                                                  #  ERASABLE STORAGE CONFIGURATION (NEEDED BY THE INDEXING METHODS):
058459,000253:                                                                                                  #        NEGUQ           ERASE   +2              NEGATIVE OF Q-AXIS GIMBAL DRIVE
058460,000254:                                                                                                  #        (SPWORD)        EQUALS  NEGUQ +1        ANY S.P. ERASABLE NUMBER, NOW THRSTCMD
058461,000255:                                                                                                  #        NEGUR           EQUALS  NEGUQ +2        NEGATIVE OF R-AXIS GIMBAL DRIVE
058462,000256: 
058463,000257:                                                                                                  #        ACCDOTQ         ERASE   +2              Q-JERK TERM SCALED AT PI/2(7) RAD/SEC(3)
058464,000258:                                                                                                  #        (SPWORD)        EQUALS  ACCDOTQ +1      ANY S.P. ERASABLE NUMBER NOW QACCDOT
058465,000259:                                                                                                  #        ACCDOTR         EQUALS  ACCDOTQ +2      R-JERK TERM SCALED AT PI/2(7) RAD/SEC(3)
058466,000260:                                                                                                  #                                                ACCDOTQ, ACCDOTR ARE MAGNITUDES.
058467,000261:                                                                                                  #        AOSQ            ERASE   +4              Q-AXIS ACC., D.P. AT PI/2 R/SEC(2)
058468,000262:                                                                                                  #        AOSR            EQUALS  AOSQ +2         R-AXIS ACCELERATION SCALED AT PI/2 R/S2
058469,000263: 
058470,000264: 21,3302     0066               QRNDXER            EQUALS   ITEMP6                                
058471,000265: 21,3302           25253        .66667             DEC      .66667                                
058472,000266: 21,3303           23146        OCT23146           OCTAL    23146                                 #  DECIMAL .6
058473,000267: 21,3304     0063               NZACCDOT           EQUALS   ITEMP3                                
058474,000268: 
058475,000269: 21,3304           35026        TIMEGMBL           CAF      ONE                                   #  INITIALIZE ALLOWGTS.
058476,000270: 21,3305           55624                           TS       ALLOWGTS                              
058477,000271: 
058478,000272: 21,3306           35025                           CAF      TWO                                   #  SET UP LOOP FOR R AXIS.
058479,000273: 21,3307           22002                           LXCH     Q                                     #  SAVE RETURN ADDRESS.
058480,000274: 21,3310           22071                           LXCH     RUPTREG2                              
058481,000275: 21,3311           13313                           TCF      +2                                    
058482,000276: 21,3312           35030        TIMQGMBL           CAF      ZERO                                  #  NOW DO THE Q-AXIS
058483,000277: 21,3313           54066                           TS       QRNDXER                               
058484,000278: 21,3314           50066                           INDEX    QRNDXER                               
058485,000279: 21,3315           31507                           CA       ACCDOTQ                               #  ACCDOT IS PRESUMED TO BE AT PI/2(7).
058486,000280: 21,3316           00006                           EXTEND                                         
058487,000281: 21,3317           63367                           BZMF     TGOFFNOW                              #  IS ACCDOT LESS THAN OR EQUAL TO 0?
058488,000282: 21,3320           54063                           TS       NZACCDOT                              #  NO.  STORE NON-ZERO, POSITIVE ACCDOT.
058489,000283: 
058490,000284: 21,3321           50066        ALPHATRY           INDEX    QRNDXER                               
058491,000285: 21,3322           41532                           CS       AOSQ                                  
058492,000286: 21,3323           00006                           EXTEND                                         
058493,000287: 21,3324           13367                           BZF      TGOFFNOW                              #  IS ALPHA ZERO?
058494,000288: 
058495,000289: 21,3325           54002                           TS       Q                                     #  SAVE A COPY OF -AOS.
058496,000290: 21,3326           00006                           EXTEND                                         #  NO.  RESCALE FOR TIMEGMBL USE.
058497,000291: 21,3327           73303                           MP       OCT23146                              #  OCTAL 23146 IS DECIMAL .6
058498,000292: 21,3330           60002                           AD       Q                                     #  -1.6*AOS AT PI/2 = -.4*AOS AT PI/8.
058499,000293: 21,3331           54001                           TS       L                                     #  WAS THERE OVERFLOW?
058500,000294: 21,3332           13337                           TCF      SETNEGU                               #  NO.  COMPUTE DRIVE TIME.
058501,000295: 
058502,000296: 21,3333           40000                           CS       A                                     #  RECOVER  -SGN(AOS) IN THE A REGISTER.
058503,000297: 21,3334           50066                           INDEX    QRNDXER                               #  YES.  START DRIVE WITHOUT WAITLIST.
058504,000298: 21,3335           57500                           XCH      NEGUQ                                 
058505,000299: 21,3336           13373                           TCF      NOTALLOW                              #  KNOCK DOWN THE ALLOWGTS FLAG.
058506,000300: 
058507,000301: 21,3337           00006        SETNEGU            EXTEND                                         
058508,000302: 21,3340           63345                           BZMF     POSALPH                               
058509,000303: 
058510,000304: 21,3341           40000                           COM                                            
058511,000305: 21,3342           54062                           TS       ITEMP2                                #  STORE -ABS(.4*AOS) SCALED AT PI/8.
058512,000306: 21,3343           45026                           CS       BIT1                                  
058513,000307: 21,3344           13347                           TCF      POSALPH    +2                         
058514,000308: 21,3345           54062        POSALPH            TS       ITEMP2                                #  STORE -ABS(.4*AOS) SCALED AT PI/8.
058515,000309: 21,3346           35026                           CA       BIT1                                  
058516,000310: 21,3347           50066                 +2        INDEX    QRNDXER                               #  SGN(AOS) INTO NEGU
058517,000311: 21,3350           55500                           TS       NEGUQ                                 #  STORE SGN(APLHA) AS NEGU
058518,000312: 
058519,000313: 21,3351           30063                           CA       NZACCDOT                              
058520,000314: 21,3352           00006                           EXTEND                                         
058521,000315: 21,3353           75013                           MP       BIT12                                 #  2*ACCDOT, SCALED AT PI/8.
058522,000316: 21,3354           60062                           AD       ITEMP2                                #  -ABS(ALPHA) + 2*ACCDOT, AT PI/8.
058523,000317: 21,3355           00006                           EXTEND                                         
058524,000318: 21,3356           63373                           BZMF     NOTALLOW                              #  IS DRIVE TIME MORE THAN TWO SECONDS?
058525,000319: 21,3357           40062                           CS       ITEMP2                                #  NO.  COMPUTE DRIVE TIME.
058526,000320: 21,3360           00006                           EXTEND                                         #  ABS(ALPHA) AT PI/8.
058527,000321: 21,3361           73407                           MP       OCT00240                              #  DECIMAL 10/1024
058528,000322: 21,3362           00006                           EXTEND                                         #  QUOTIENT IS DRIVE TIME AT WAITLIST.
058529,000323: 21,3363           10063                           DV       NZACCDOT                              #  ABS(ALPHA)/ACCDOT AT 2(14)/100
058530,000324: 21,3364           00006                           EXTEND                                         
058531,000325: 21,3365           13367                           BZF      TGOFFNOW                              #  DRIVE TIME MUST BE GREATER THAN ZERO.
058532,000326: 
058533,000327: 21,3366           13401                           TCF      DRIVEON                               
058534,000328: 
058535,000329: 21,3367           35030        TGOFFNOW           CAF      ZERO                                  #  TURN OFF GIMBAL NOW.
058536,000330: 21,3370           50066                           INDEX    QRNDXER                               
058537,000331: 21,3371           55500                           TS       NEGUQ                                 
058538,000332: 
058539,000333: 21,3372           13403                           TCF      DONEYET                               
058540,000334: 
058541,000335: 21,3373           34113        NOTALLOW           CAF      OCT31                                 
058542,000336: 21,3374           50066                           INDEX    QRNDXER                               
058543,000337: 21,3375           55626                           TS       QGIMTIMR                              
058544,000338: 21,3376           35030                           CAF      ZERO                                  #  DRIVE TIME IS MORE THAN 2 SECONDS, SO
058545,000339: 21,3377           55624                           TS       ALLOWGTS                              #  DO NOT PERMIT FURTHER GTS ATTITUDE-RATE
058546,000340:                                                                                                  #  CONTROL UNTIL AOSTASK APPROVES.
058547,000341: 21,3400           13403                           TCF      DONEYET                               #  NO WAITLIST CALL IS MADE.
058548,000342: 
058549,000343: 21,3401           50066        DRIVEON            INDEX    QRNDXER                               
058550,000344: 21,3402           55626                           TS       QGIMTIMR                              #  CHOOSE Q OR R AXIS.
058551,000345: 
058552,000346: 21,3403           10066        DONEYET            CCS      QRNDXER                               
058553,000347: 21,3404           13312                           TCF      TIMQGMBL                              
058554,000348: 
058555,000349: 21,3405           03242                           TC       ACDT+C12                              #  TURN OF CHANNEL BITS, SET Q(R)ACCDOTS.
058556,000350: 
058557,000351: 21,3406           00071                           TC       RUPTREG2                              #  RETURN TO CALLER.
058558,000352: 
058559,000353: 21,3407           00240        OCT00240           OCTAL    00240                                 #  DECIMAL 10/1024
058560,000354: 
058561,000355:                                                                                                  #  THE FOLLOWING SECTION IS A CONTINUATION OF THE TRIM GIMBAL CONTROL FROM THE LAST GTS ENTRY.  THE QUANTITY NEGUSUM
058562,000356:                                                                                                  #  IS COMPUTED FOR EACH AXIS (Q,R), .707*DEL*FUNCTION(3/2) + K2THETA = NEGUSUM.  NEW DRIVES ARE ENTERED TO CH 12.
058563,000357: 
058564,000358: 21,3410           11473        RSTOFGTS           CCS      FUNCTION                              
058565,000359: 21,3411           13430                           TCF      GOODARG                               #  FUNCTION IS POSITIVE.  GET 3/2 POWER.
058566,000360: 21,3412           13414                           TCF      +2                                    #  HIGH ORDER WORD IS ZERO.  TRY THE LOWER.
058567,000361: 21,3413           13541                           TCF      NEGUSUM                               #  NEGATIVE.  USE ZERO FOR 3/2 POWER.
058568,000362: 
058569,000363: 21,3414           41474                           CS       FUNCTION   +1                         #  IF ARG IS LESS THAN 2(-18), THEN THE 3/2
058570,000364: 21,3415           65014                           AD       BIT11                                 #  POWER IS LESS THAN 2(-27).  USE ZERO.
058571,000365: 21,3416           00006                           EXTEND                                         
058572,000366: 21,3417           63421                           BZMF     ZEROHIGH                              #  BRANCH IF ARG NOT LESS THAN 2(-18).
058573,000367: 
058574,000368: 21,3420           13541                           TCF      NEGUSUM                               
058575,000369: 
058576,000370: 21,3421           34331        ZEROHIGH           CA       FOURTEEN                              #  ARG LESS THAN 2(-14) MEANS 3/2 POWER
058577,000371:                                                                                                  #  WILL BE LESS THAN 2(-21).
058578,000372: 21,3422           55736                           TS       SHFTFLAG                              
058579,000373: 
058580,000374: 21,3423           35025                           CA       TWO                                   
058581,000375: 21,3424           55737                           TS       ININDEX                               #  INITIALIZE THE SHIFT LOOP.
058582,000376: 
058583,000377:                                                                                                  #  COLLECT THE 14 MOST SIGNIFICANT BITS OF
058584,000378: 21,3425           57474                           XCH      FUNCTION   +1                         #  THE 28 INTO THE HIGH ORDER WORD.
058585,000379: 21,3426           57473                           XCH      FUNCTION                              
058586,000380: 21,3427           13443                           TCF      SCALLOOP                              
058587,000381: 21,3430           35743        GOODARG            CA       TWELVE                                
058588,000382: 21,3431           55737                           TS       ININDEX                               #  INITIALIZE THE SHIFT LOOP.
058589,000383: 21,3432           35030                           CA       ZERO                                  #  THERE ARE SIGNIFICANT BITS IN THE HIGH
058590,000384: 21,3433           55736                           TS       SHFTFLAG                              #  ORDER WORD, SO SET SHFTFLAG TO ZERO.
058591,000385: 
058592,000386: 21,3434           13443                           TCF      SCALLOOP                              
058593,000387: 
058594,000388: 21,3435           31473        SCALSTRT           CA       FUNCTION                              
058595,000389: 21,3436           13460                           TCF      SCALDONE                              
058596,000390: 
058597,000391: 21,3437           37720        MULBUSH            CA       NEG2                                  #  IF ARG IS NOT LESS THAN 1/4, INDEX IS
058598,000392: 21,3440           27737                           ADS      ININDEX                               #  ZERO, INDICATING NO SHIFT NEEDED.
058599,000393: 21,3441           00006                           EXTEND                                         #  BRANCH IF ARG IS NOT LESS THAN 1/4.
058600,000394: 21,3442           63435                           BZMF     SCALSTRT                              #  OTHERWISE COMPARE ARG WITH A REFERENCE
058601,000395:                                                                                                  #  WHICH IS 4 TIMES LARGER THAN THE LAST.
058602,000396: 21,3443           41473        SCALLOOP           CS       FUNCTION                              
058603,000397: 21,3444           51737                           INDEX    ININDEX                               
058604,000398: 21,3445           65010                           AD       BIT15                                 #  REFERENCE MAGNITUDE LESS OR EQUAL TO 1/4
058605,000399: 21,3446           00006                           EXTEND                                         
058606,000400: 21,3447           63437                           BZMF     MULBUSH                               #  IF ARG IS NOT LESS THAN REFERENCE, GO
058607,000401:                                                                                                  #  AROUND THE MULBERRY BUSH ONCE MORE.
058608,000402: 21,3450           51737                           INDEX    ININDEX                               
058609,000403: 21,3451           35010                           CA       BIT15                                 #  THIS IS THE SCALE MAGNITUDE
058610,000404: 21,3452           56002                           XCH      Q                                     #  2**(-ININDEX) IS THE SHIFT DIVISOR.
058611,000405: 21,3453           00006                           EXTEND                                         #  RESCALE ARGUMENT.
058612,000406: 21,3454           31474                           DCA      FUNCTION                              
058613,000407: 21,3455           00006                           EXTEND                                         
058614,000408: 21,3456           10002                           DV       Q                                     
058615,000409: 21,3457           55473                           TS       FUNCTION                              #  ININDEX AND SHFTFLAG PRESERVE INFO FOR
058616,000410:                                                                                                  #  RESCALING AFTER ROOT PROCESS.
058617,000411: 21,3460           00006        SCALDONE           EXTEND                                         #  AFTER 3/2 POWER IS TAKEN, SCALE FACTOR
058618,000412: 21,3461           75012                           MP       BIT13                                 #  OF SQRT(1/2) WILL BE NEEDED, SO FACTOR
058619,000413: 21,3462           55742                           TS       HALFARG                               #  OF 1/2 IS INCLUDED NOW, BEFORE SQRT.
058620,000414: 
058621,000415: 21,3463           33567                           CA       STARTER                               #  INITIAL GUESS FOR SQRT ALGORITHM.
058622,000416: 21,3464           03570                           TC       ROOTCYCL                              
058623,000417: 21,3465           03570                           TC       ROOTCYCL                              
058624,000418: 21,3466           03570                           TC       ROOTCYCL                              
058625,000419: 
058626,000420: 21,3467           00006                           EXTEND                                         #  SQRT(1/2)*SQRT(ARG) IN A.
058627,000421: 21,3470           71473                           MP       FUNCTION                              #  SQRT(1/2)*ARG*SQRT(ARG) IN A,L.
058628,000422: 21,3471           53474                           DXCH     FUNCTION                              
058629,000423: 
058630,000424: 21,3472           31736        DOSHIFT            CA       SHFTFLAG                              #  HOW MANY SHIFT BITS ARE THERE?
058631,000425: 21,3473           61737                           AD       ININDEX                               #  2**(-ININDEX) WAS SHIFT DIVISOR.
058632,000426: 21,3474           54021                           TS       SR                                    
058633,000427: 21,3475           60021                           AD       SR                                    #  THIS MANY SHIFTS ARE REQUIRED.
058634,000428: 21,3476           54002        SAVESHFT           TS       Q                                     #  Q BOUNDS ARE ZERO AND 24 (DECIMAL).
058635,000429: 21,3477           00006                           EXTEND                                         
058636,000430: 21,3500           63526                           BZMF     SUMNEGU                               #  BRANCH IF SHIFTING IS UNNECESSARY.
058637,000431: 
058638,000432: 21,3501           44331                           CS       FOURTEEN                              
058639,000433: 21,3502           60002                           AD       Q                                     
058640,000434: 21,3503           00006                           EXTEND                                         #  Q = 0(MOD 3), SO A REG IS NON-ZERO.
058641,000435: 21,3504           63511                           BZMF     MINISHFT                              #  BRANCH IF SMALL SHIFT SUFFICES.
058642,000436: 
058643,000437: 21,3505           54002        MAXISHFT           TS       Q                                     #  14 BIT SHIFT RIGHT NOW.
058644,000438: 21,3506           35030                           CA       ZERO                                  
058645,000439: 21,3507           57473                           XCH      FUNCTION                              
058646,000440: 21,3510           55474                           TS       FUNCTION   +1                         
058647,000441: 
058648,000442: 21,3511           50002        MINISHFT           INDEX    Q                                     #  C(Q) ARE GREATER THAN ZERO.
058649,000443: 21,3512           35010                           CA       BIT15                                 
058650,000444: 21,3513           54002                           TS       Q                                     #  2**(-Q) WILL BE SHIFT MULTIPLIER.
058651,000445: 21,3514           00006                           EXTEND                                         
058652,000446: 21,3515           71474                           MP       FUNCTION   +1                         
058653,000447: 21,3516           56001                           XCH      L                                     
058654,000448: 21,3517           35030                           CA       ZERO                                  
058655,000449: 21,3520           53474                           DXCH     FUNCTION                              #  LOWER WORD SHIFTED NOW.
058656,000450: 21,3521           00006                           EXTEND                                         
058657,000451: 21,3522           63526                           BZMF     SUMNEGU                               #  BRANCH IF UPPER WORD WAS ZERO.
058658,000452: 21,3523           00006                           EXTEND                                         #  SHIFT UPPER WORD.
058659,000453: 21,3524           70002                           MP       Q                                     
058660,000454: 21,3525           21474                           DAS      FUNCTION                              #  NO OVERFLOW POSSIBLE.
058661,000455: 
058662,000456: 21,3526           41744        SUMNEGU            CS       DEL                                   #  INCLUDE DEL FACTOR IN PRODUCT TERM.
058663,000457: 21,3527           00006                           EXTEND                                         
058664,000458: 21,3530           63534                           BZMF     SUMTERMS                              
058665,000459: 
058666,000460: 21,3531           00006                           EXTEND                                         #  DEL FACTOR IS MINUS ONE.
058667,000461: 21,3532           41474                           DCS      FUNCTION                              
058668,000462: 21,3533           13540                           TCF      NEGUSUM    -1                         #  NOW ADD IN THE K2THETA TERM.
058669,000463: 
058670,000464: 21,3534           00006        SUMTERMS           EXTEND                                         
058671,000465: 21,3535           13541                           BZF      NEGUSUM                               #  BRANCH IF DEL IS ZERO.
058672,000466: 
058673,000467: 21,3536           00006                           EXTEND                                         #  DEL FACTOR IS +1.
058674,000468: 21,3537           31474                           DCA      FUNCTION                              
058675,000469: 21,3540           21735                           DAS      K2THETA                               #  NOW ADD IN THE K2THETA TERM.
058676,000470: 21,3541           11734        NEGUSUM            CCS      K2THETA                               #  TEST SIGN OF HIGH ORDER PART.
058677,000471: 21,3542           13546                           TCF      NEGDRIVE                              
058678,000472: 21,3543           13545                           TCF      +2                                    
058679,000473: 21,3544           13550                           TCF      POSDRIVE                              
058680,000474: 
058681,000475: 21,3545           11735                           CCS      K2THETA    +1                         #  SIGN TEST FOR LOW ORDER PART.
058682,000476: 21,3546           35026        NEGDRIVE           CA       BIT1                                  
058683,000477: 21,3547           13551                           TCF      +2                                    #  STOP GIMBAL DRIVE FOR A ZERO NEGUSUM.
058684,000478: 21,3550           45026        POSDRIVE           CS       BIT1                                  
058685,000479: 21,3551           51745                           INDEX    QRCNTR                                
058686,000480: 21,3552           55500                           TS       NEGUQ                                 
058687,000481: 
058688,000482: 21,3553           11745                           CCS      QRCNTR                                #  HAVE BOTH AXES BEEN PROCESSED?
058689,000483: 21,3554           13100                           TCF      GOQTRIMG                              #  NO.  DO Q AXIS NEXT.
058690,000484: 
058691,000485: 21,3555           00004                           INHINT                                         
058692,000486: 21,3556           03242                           TC       ACDT+C12                              
058693,000487: 21,3557           00003                           RELINT                                         
058694,000488: 
058695,000489: 21,3560           31471                           CA       SAVESR                                #  RESTORE THE SR
058696,000490: 21,3561           54021                           TS       SR                                    
058697,000491: 
058698,000492: 21,3562           00006        GOCLOSE            EXTEND                                         #  TERMINATE THE JASK.
058699,000493: 21,3563           33566                           DCA      CLOSEADR                              
058700,000494: 21,3564           52006                           DTCB                                           
058701,000495: 
058702,000496: 21,3565  E6,1532                                  EBANK=   AOSQ                                  
058703,000497: 21,3565           03021 36106  CLOSEADR           2CADR    CLOSEOUT                              #  TERMINATE THE JASK.
058704,000498: 
058705,000499: 21,3567     5743               TWELVE             EQUALS   OCT14                                 
058706,000500: 21,3567           20761        STARTER            DEC      .53033                                #  INITIAL VALUE FOR SQRT ALGORITHM.
058707,000501: 
058708,000502:                                                                                                  #  SUBROUTINE ROOTCYCL:  BY CRAIG WORK,3 APRIL 68
058709,000503: 
058710,000504:                                                                                                  #  ROOTCYCL IS A SUBROUTINE WHICH EXECUTES ONE NEWTON SQUARE ROOT ALGORITHM ITERATION.  THE INITIAL GUESS AT THE
058711,000505:                                                                                                  #  SQUARE ROOT IS PRESUMED TO BE IN THE A REGISTER AND ONE-HALF THE SQUARE IS TAKEN FROM HALFARG.  THE NEW APPROXI-
058712,000506:                                                                                                  #  MATION TO THE SQUARE ROOT IS RETURNED IN THE A REGISTER.  DEBRIS:  A,L,SR,SCRATCH.   ROOTCYCL IS CALLED FROM
058713,000507:                                                                                                  #  LOCATION (LOC) BY A TC ROOTCYCL, AND RETURNS (TC Q) TO LOC +1.
058714,000508: 
058715,000509:                                                                                                  #  WARNING:  IF THE INITIAL GUESS IS NOT GREATER THAN THE SQUARE, DIVIDE OR ADD OVERFLOW IS A REAL POSSIBILITY.
058716,000510: 
058717,000511: 21,3570           55741        ROOTCYCL           TS       SCRATCH                               #  STORE X
058718,000512: 21,3571           54021                           TS       SR                                    #  X/2 NOW IN SR
058719,000513: 21,3572           31742                           CA       HALFARG                               #  ARG/2 IN THE A REG
058720,000514: 21,3573           22007                           ZL                                             #  PREPARE FOR DIVISION
058721,000515: 21,3574           00006                           EXTEND                                         
058722,000516: 21,3575           11741                           DV       SCRATCH                               #  (ARG/X)/2
058723,000517: 21,3576           60021                           AD       SR                                    #  (X + ARG/X)/2 IN THE A REG
058724,000518: 21,3577           00002                           TC       Q                                     
058725,000519: 
058726,000520: 

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