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, 1969Note 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. |
047178,000002: ## Copyright: Public domain.
047179,000003: ## Filename: LATITUDE_LONGITUDE_SUBROUTINES.agc
047180,000004: ## Purpose: A section of Luminary 1C, revision 131.
047181,000005: ## It is part of the source code for the Lunar Module's (LM)
047182,000006: ## Apollo Guidance Computer (AGC) for Apollo 13.
047183,000007: ## This file is intended to be a faithful transcription, except
047184,000008: ## that the code format has been changed to conform to the
047185,000009: ## requirements of the yaYUL assembler rather than the
047186,000010: ## original YUL assembler.
047187,000011: ## Reference: pp. 1127-1133
047188,000012: ## Contact: Ron Burkey <info@sandroid.org>.
047189,000013: ## Website: www.ibiblio.org/apollo/index.html
047190,000014: ## Mod history: 05/31/03 RSB. Began transcribing.
047191,000015: ## 05/14/05 RSB Corrected website reference above.
047192,000016: ## 2011-01-05 JL Fixed indentation of RVQ instruction.
047193,000017: ## 2017-01-06 RSB Page numbers now agree with those on the
047194,000018: ## original harcopy, as opposed to the PDF page
047195,000019: ## numbers in 1701.pdf.
047196,000020: ## 2017-02-05 RSB Back-ported comment corrections
047197,000021: ## identified while proofing Artemis 072.
047198,000022: ## 2017-02-27 RSB Proofed comment text using octopus/ProoferComments.
047199,000023: ## 2017-03-13 RSB Comment-text fixes noted in proofing Luminary 116.
047200,000024: ## 2017-03-15 RSB Comment-text fixes identified in 5-way
047201,000025: ## side-by-side diff of Luminary 69/99/116/131/210.
047202,000026:
![]() |
Page 1127 |
047204,000028: # SUBROUTINE TO CONVERT RAD VECTOR AT GIVEN TIME TO LAT,LONG AND ALT
047205,000029:
047206,000030: # CALLING SEQUENCE
047207,000031: # L-1 CALL
047208,000032: # L LAT-LONG
047209,000033:
047210,000034: # SUBROUTINES USED
047211,000035: # R-TO-RP, ARCTAN, SETGAMMA, SETRE
047212,000036:
047213,000037: # ERASABLE INIT. REQ.
047214,000038: # AXO, -AYO, AZO, TEPHEM (SET AT LAUNCH TIME)
047215,000039: # ALPHAV = POSITION VECTOR METERS B-29
047216,000040: # MPAC -- TIME (CSECS B-28)
047217,000041: # ERADFLAG =1, TO COMPUTE EARTH RADIUS, =0 FOR FIXED EARTH RADIUS
047218,000042: # LUNAFLAG=0 FOR EARTH, 1 FOR MOON
047219,000043:
047220,000044: # OUTPUT
047221,000045: # LATITUDE IN LAT (REVS. B-0)
047222,000046: # LONGITUDE IN LONG (REVS. B-0)
047223,000047: # ALTITUDE IN ALT METERS B-29
047224,000048:
047225,000049: 30,3766 BANK 30
047226,000050: 13,2000 SETLOC LATLONG
047227,000051: 13,2000 BANK
047228,000052:
047229,000053: 13,2347 COUNT* $$/LT-LG
047230,000054: 13,2347 E4,1431 EBANK= ALPHAV
047231,000055: 13,2347 40220 LAT-LONG STQ SETPD
047232,000056: 13,2350 03674 INCORPEX
047233,000057: 13,2351 00001 0D
047234,000058: 13,2352 24007 STOVL 6D # SAVE TIME IN 6-7D FOR R-TO-RP
047235,000059: 13,2353 02032 ALPHAV
047236,000060: 13,2354 51406 PUSH ABVAL # 0-5D= R FOR R-TO-RP
047237,000061: 13,2355 16070 STODL ALPHAM # ABS. VALUE OF R FOR ALT FORMULA BELOW
047238,000062: 13,2356 24007 ZEROVEC # SET MPAC=0 FOR EARTH, NON-ZERO FOR MOON
047239,000063: 13,2357 71414 BOFF COS # USE COS(0) TO GET NON-ZERO IN MPAC
047240,000064: 13,2360 01743 LUNAFLAG # 0=EARTH, 1=MOON
047241,000065: 13,2361 26362 CALLRTRP
047242,000066: 13,2362 77624 CALLRTRP CALL
047243,000067: 13,2363 51700 R-TO-RP # RP VECTOR CONVERTED FROM R B-29
047244,000068: 13,2364 77656 UNIT # UNIT RP B-1
047245,000069: 13,2365 36032 STCALL ALPHAV # U2= 1/2 SINL FOR SETRE SUBR BELOW
047246,000070: 13,2366 26546 SETGAMMA # SET GAMMA=B2/A2 FOR EARTH, =1 FOR MOON
047247,000071: 13,2367 77624 CALL # SCALED B-1
047248,000072: 13,2370 26556 SETRE # CALC RE METERS B-29
047249,000073: 13,2371 63545 DLOAD DSQ
047250,000074: 13,2372 02032 ALPHAV
047251,000075: 13,2373 63525 PDDL DSQ
047252,000076: 13,2374 02034 ALPHAV +2
047253,000077: 13,2375 75415 DAD SQRT
![]() |
Page 1128 |
047255,000079: 13,2376 76405 DMP SL1R
047256,000080: 13,2377 00011 GAMRP
047257,000081: 13,2400 14021 STODL COSTH # COS(LAT) B-1
047258,000082: 13,2401 02036 ALPHAV +4
047259,000083: 13,2402 34023 STCALL SINTH # SIN(LAT) B-1
047260,000084: 13,2403 26506 ARCTAN
047261,000085: 13,2404 15120 STODL LAT # LAT B0
047262,000086: 13,2405 02032 ALPHAV
047263,000087: 13,2406 14021 STODL COSTH # COS(LONG) B-1
047264,000088: 13,2407 02034 ALPHAV +2
047265,000089: 13,2410 34023 STCALL SINTH # SIN(LONG) B-1
047266,000090: 13,2411 26506 ARCTAN
047267,000091: 13,2412 15122 STODL LONG # LONG. REVS B-0 IN RANGE -1/2 TO 1/2
047268,000092: 13,2413 02070 ALPHAM
047269,000093: 13,2414 77625 DSU # ALT= R-RE METERS B-29
047270,000094: 13,2415 03673 ERADM
047271,000095: 13,2416 35124 STCALL ALT # EXIT WITH ALT METERS B-29
047272,000096: 13,2417 03674 INCORPEX
![]() |
Page 1129 |
047274,000098: # SUBROUTINE TO CONVERT LAT,LONG,ALT AT GIVEN TIME TO RADIUS VECTOR
047275,000099:
047276,000100: # CALLING SEQUENCE
047277,000101: # L-1 CALL
047278,000102: # L LALOTORV
047279,000103:
047280,000104: # SUBROUTINES USED
047281,000105: # SETGAMMA, SETRE, RP-TO-R
047282,000106:
047283,000107: # ERASABLE INIT. REQ.
047284,000108: # AXO, AYO, AZO, TEPHEM SET AT LAUNCH TIME
047285,000109: # LAT -- LATITUDE (REVS B0)
047286,000110: # LONG -- LONGITUDE (REVS B0)
047287,000111: # ALT -- ALTITUDE (METERS) B-29
047288,000112: # MPAC -- TIME (CSECS B-28)
047289,000113: # ERADFLAG =1 TO COMPUTE EARTH RADIUS, =0 FOR FIXED EARTH RADIUS
047290,000114: # LUNAFLAG=0 FOR EARTH, 1 FOR MOON
047291,000115:
047292,000116: # OUTPUT
047293,000117: # R-VECTOR IN ALPHAV (METERS B-29)
047294,000118:
047295,000119: 13,2420 40220 LALOTORV STQ SETPD # LAT,LONG,ALT TO R VECTOR
047296,000120: 13,2421 03674 INCORPEX
047297,000121: 13,2422 00001 0D
047298,000122: 13,2423 34007 STCALL 6D # 6-7D= TIME FOR RP-TO-R
047299,000123: 13,2424 26546 SETGAMMA # GAMMA=B2/A2 FOR EARTH, 1 FOR MOON B-1
047300,000124: 13,2425 73545 DLOAD SIN # COS(LONG)COS(LAT) IN MPAC
047301,000125: 13,2426 01120 LAT # UNIT RP = SIN(LONG)COS(LAT) 2-3D
047302,000126: 13,2427 65275 DMPR PDDL # PD 2 GAMMA*SIN(LAT) 0-1D
047303,000127: 13,2430 00011 GAMRP
047304,000128: 13,2431 01120 LAT # 0-1D= GAMMA*SIN(LAT) B-2
047305,000129: 13,2432 65346 COS PDDL # PD4 2-3D= COS(LAT) B-1 TEMPORARILY
047306,000130: 13,2433 01122 LONG
047307,000131: 13,2434 57356 SIN DMPR # PD 2
047308,000132: 13,2435 71525 PDDL COS # PD 4 2-3D = SIN(LONG)COS(LAT) B-2
047309,000133: 13,2436 01120 LAT
047310,000134: 13,2437 71525 PDDL COS # PD 6 4-5D = COS(LAT) B-1 TEMPORARILY
047311,000135: 13,2440 01122 LONG
047312,000136: 13,2441 55475 DMPR VDEF # PD4 MPAC= COS(LONG)COS(LAT) B-2
047313,000137: 13,2442 41456 UNIT PUSH # 0-5D= UNIT RP FOR RP-TO-R SUBR.
047314,000138: 13,2443 36032 STCALL ALPHAV # ALPHAV +4= SINL FOR SETRE SUBR.
047315,000139: 13,2444 26556 SETRE # RE METERS B-29
047316,000140: 13,2445 43145 DLOAD BOFF # SET MPAC=0 FOR EARTH, NON-ZERO FOR MOON
047317,000141: 13,2446 24007 ZEROVEC
047318,000142: 13,2447 01743 LUNAFLAG
047319,000143: 13,2450 26452 CALLRPRT
047320,000144: 13,2451 77746 COS # USE COS(0) TO GET NON-ZERO IN MPAC
047321,000145: 13,2452 77624 CALLRPRT CALL
047322,000146: 13,2453 55716 RP-TO-R # EXIT WITH UNIT R VECTOR IN MPAC
047323,000147: 13,2454 16032 STODL ALPHAV
047324,000148: 13,2455 03673 ERADM
![]() |
Page 1130 |
047326,000150: 13,2456 74215 DAD VXSC # (RE + ALT)(UNIT R) METERS B-30
047327,000151: 13,2457 01124 ALT
047328,000152: 13,2460 02032 ALPHAV
047329,000153: 13,2461 77772 VSL1 # R METERS B-29
047330,000154: 13,2462 36032 STCALL ALPHAV # EXIT WITH R IN METERS B-29
047331,000155: 13,2463 03674 INCORPEX
047332,000156:
047333,000157: # SUBROUTINE TO COMPUTE EARTH RADIUS
047334,000158:
047335,000159: # INPUT
047336,000160: # 1/2 SIN LAT IN ALPHAV +4
047337,000161:
047338,000162: # OUTPUT
047339,000163: # EARTH RADIUS IN ERADM AND MPAC (METERS B-29)
047340,000164:
047341,000165: 13,2464 63545 GETERAD DLOAD DSQ
047342,000166: 13,2465 02036 ALPHAV +4 # SIN**2(L)
047343,000167: 13,2466 44352 SL1 BDSU
047344,000168: 13,2467 24005 DP1/2 # COS**2(L)
047345,000169: 13,2470 44275 DMPR BDSU
047346,000170: 13,2471 26505 EE
047347,000171: 13,2472 24005 DP1/2
047348,000172: 13,2473 75465 BDDV SQRT
047349,000173: 13,2474 26501 B2XSC
047350,000174: 13,2475 77622 SR4R
047351,000175: 13,2476 03673 STORE ERADM
047352,000176: 13,2477 77616 RVQ
047353,000177:
047354,000178: # THE FOLLOWING CONSTANTS WERE COMPUTED WITH A=6378166, B=6356784 METERS
047355,000179: # B2XSC = B**2 SCALED B-51
047356,000180: # B2/A2 = B**2/A**2 SCALED B-1
047357,000181: # EE = (1-B**2/A**2) SCALED B-0
047358,000182:
047359,000183: 13,2500 00446 00305 B2XSC 2DEC .0179450689 # B**2 SCALED B-51
047360,000184: 13,2502 12,2004 DP1/2 = XUNIT
047361,000185: 13,2502 17711 05254 B2/A2 2DEC .9933064884 B-1 # GAMMA= B**2/A**2 B-1
047362,000186: 13,2504 00155 25250 EE 2DEC 6.6935116 E-3 # (1-B**2/A**2) B-0
047363,000187:
![]() |
Page 1131 |
047365,000189: # ARCTAN SUBROUTINE
047366,000190:
047367,000191: # CALLING SEQUENCE
047368,000192: # SIN THETA IN SINTH B-1
047369,000193: # COS THETA IN COSTH B-1
047370,000194: # CALL ARCTAN
047371,000195:
047372,000196: # OUTPUT
047373,000197: # ARCTAN THETA IN MPAC AND THETA B-0 IN RANGE -1/2 TO +1/2
047374,000198:
047375,000199: 13,2506 77600 ARCTAN BOV
047376,000200: 13,2507 26510 CLROVFLW
047377,000201: 13,2510 63545 CLROVFLW DLOAD DSQ
047378,000202: 13,2511 00023 SINTH
047379,000203: 13,2512 63525 PDDL DSQ
047380,000204: 13,2513 00021 COSTH
047381,000205: 13,2514 77615 DAD
047382,000206: 13,2515 75454 BZE SQRT
047383,000207: 13,2516 26534 ARCTANXX # ATAN=0/0 SET THETA=0
047384,000208: 13,2517 40065 BDDV BOV
047385,000209: 13,2520 00023 SINTH
047386,000210: 13,2521 26541 ATAN=90
047387,000211: 13,2522 67542 SR1 ASIN
047388,000212: 13,2523 00025 STORE THETA
047389,000213: 13,2524 50125 PDDL BMN
047390,000214: 13,2525 00021 COSTH
047391,000215: 13,2526 26530 NEGCOS
047392,000216: 13,2527 43545 DLOAD RVQ
047393,000217: 13,2530 57545 NEGCOS DLOAD DCOMP
047394,000218: 13,2531 43244 BPL DAD
047395,000219: 13,2532 26536 NEGOUT
047396,000220: 13,2533 24005 DP1/2
047397,000221: 13,2534 00025 ARCTANXX STORE THETA
047398,000222: 13,2535 77616 RVQ
047399,000223:
047400,000224: 13,2536 52025 NEGOUT DSU GOTO
047401,000225: 13,2537 24005 DP1/2
047402,000226: 13,2540 26534 ARCTANXX
047403,000227: 13,2541 75345 ATAN=90 DLOAD SIGN
047404,000228: 13,2542 11003 LODP1/4
047405,000229: 13,2543 00023 SINTH
047406,000230: 13,2544 00025 STORE THETA
047407,000231: 13,2545 77616 RVQ
047408,000232:
047409,000233: 13,2546 12,2006 2DZERO = DPZERO
047410,000234:
![]() |
Page 1132 |
047412,000236: # ..... SETGAMMA SUBROUTINE .....
047413,000237: # SUBROUTINE TO SET GAMMA FOR THE LAT-LONG AND LALOTORV SUBROUTINES
047414,000238:
047415,000239: # GAMMA = B**2/A**2 FOR EARTH (B-1)
047416,000240: # GAMMA = 1 FOR MOON (B-1)
047417,000241:
047418,000242: # CALLING SEQUENCE
047419,000243: # L CALL
047420,000244: # L+1 SETGAMMA
047421,000245:
047422,000246: # INPUT
047423,000247: # LUNAFLAG=0 FOR EARTH, =1 FOR MOON
047424,000248:
047425,000249: # OUTPUT
047426,000250: # GAMMA IN GAMRP (B-1)
047427,000251:
047428,000252: 13,2546 43145 SETGAMMA DLOAD BOFF # BRANCH FOR EARTH
047429,000253: 13,2547 26503 B2/A2 # EARTH GAMMA
047430,000254: 13,2550 01743 LUNAFLAG
047431,000255: 13,2551 26554 SETGMEX
047432,000256: 13,2552 77735 SLOAD
047433,000257: 13,2553 24005 1B1 # MOON GAMMA
047434,000258: 13,2554 00011 SETGMEX STORE GAMRP
047435,000259: 13,2555 77616 RVQ
047436,000260: 13,2556 GAMRP = 8D
047437,000261:
![]() |
Page 1133 |
047439,000263: # ..... SETRE SUBROUTINE .....
047440,000264: # SUBROUTINE TO SET RE (EARTH OR MOON RADIUS)
047441,000265:
047442,000266: # RE = RM FOR MOON
047443,000267: # RE = RREF FOR FIXED EARTH RADIUS OR COMPUTED RF FOR FISCHER ELLIPSOID
047444,000268:
047445,000269: # CALLING SEQUENCE
047446,000270: # L CALL
047447,000271: # L+1 SETRE
047448,000272:
047449,000273: # SUBROUTINES USED
047450,000274: # GETERAD
047451,000275:
047452,000276: # INPUT
047453,000277: # ERADFLAG = 0 FOR FIXED RE, 1 FOR COMPUTED RE
047454,000278: # ALPHAV +4 = 1/2 SINL IF GETERAD IS CALLED
047455,000279: # LUNAFLAG = 0 FOR EARTH, =1 FOR MOON
047456,000280:
047457,000281: # OUTPUT
047458,000282: # ERADM = 504RM FOR MOON (METERS B-29)
047459,000283: # ERADM = ERAD OR COMPUTED RF FOR EARTH (METERS B-29)
047460,000284:
047461,000285: 13,2556 71220 SETRE STQ DLOAD
047462,000286: 13,2557 00051 SETREX
047463,000287: 13,2560 10003 504RM
047464,000288: 13,2561 71214 BON DLOAD # BRANCH FOR MOON
047465,000289: 13,2562 01703 LUNAFLAG
047466,000290: 13,2563 26573 TSTRLSRM
047467,000291: 13,2564 10001 ERAD
047468,000292: 13,2565 45014 BOFF CALL # ERADFLAG=0 FOR FIXED RE, 1 FOR COMPUTED
047469,000293: 13,2566 00742 ERADFLAG
047470,000294: 13,2567 26571 SETRXX
047471,000295: 13,2570 26464 GETERAD
047472,000296: 13,2571 37673 SETRXX STCALL ERADM # EXIT WITH RE OR RM METERS B-29
047473,000297: 13,2572 00051 SETREX
047474,000298: 13,2573 77214 TSTRLSRM BON VLOAD # ERADFLAG=0, SET R0=RLS
047475,000299: 13,2574 00702 ERADFLAG # =1 R0=RM
047476,000300: 13,2575 26571 SETRXX
047477,000301: 13,2576 02023 RLS
047478,000302: 13,2577 64446 ABVAL SR2R # SCALE FROM B-27 TO B-29
047479,000303: 13,2600 77650 GOTO
047480,000304: 13,2601 26571 SETRXX
047481,000305: 13,2602 0000051 SETREX = S2
047482,000306:
047483,000307:
End of include-file LATITUDE_LONGITUDE_SUBROUTINES.agc. Parent file is MAIN.agc