Sextant Navigation

Home | Political Science | Way Of Life theory | Philosophy Of Science

Merlin II main program

This program doesn't work on its own. A Merlin II navigation computer is made by first loading (with a cassette tape) the short preliminary program "P4" on to the PC-1248 and then running P4 which stores (POKEs) data, mainly for computing the moon, into certain machine memories. After P4 has done its job, it is overwritten by loading this main program. The machine is then ready for use.

Program P4 can be found under Merlin II-PC-1248 tech info.

To see the program in the computer, the password is QQQQ. Don't forget to restore the password so the program won't be accidentally corrupted.

If you need a Merlin II reprogrammed email

  dimitrios@bogiatzoules.de

unless you are within Australia, in which case email me.

The comments to the main program below were added about 1990 when it was fresh in my mind. Some seem a bit cryptic now. If you want to understand the program you'd need to consult the Merlin II instruction manual and maybe also the Sharp manual for the PC-1248 or a similar model. The commands POKE and PEEK store and view machine memory locations. The P4 program and the other technical information sheets show what the memory locations are doing so it should be possible to sort it all out.

If you have a query I will do my best to answer.
mike.pepperday@gmail.com

The character ๐”ผ is the exponent: ๐”ผ3 means 10 to the power of 3

Line 1 along with lines 390 and 510 are irrelevant confusions

1 WAIT :X=128:W=31: GOSUB 390: RETURN

Lines 4 to 6 operate on Wโ€”converts degrees dot minutes to and from decimal degrees and line 3 does two numbers, Z and X, deciding which conversion to do with M which can be 4 or 5.

3 W=Z: GOSUB M:Z=W:W=X: GOSUB M:X=W: RETURN
4 V=.6: GOTO 6
5 V=1/.6
6 W=((ABS W- INT ABS W)*V+ INT ABS W)* SGN W: USING "####.###": RETURN

subroutine 7 is the basic spherical transform

7 W= ASN ( SIN X* SIN Y+ COS X* COS Y* COS Z):Z= ACS ((SIN X* SIN W- SIN Y)/ COS X/ COS W)* SGN SIN Z+180: RETURN

subroutine 8-9 prints S (for south) if Z is negative otherwise North.

8 M$=" S": IF Z>0 LET M$=" N
9 PRINT STR$ ( INT ( ABS Z*๐”ผ3)/๐”ผ3);M$;X: RETURN

13 and 14 are user utilities to subroutines 4 or 5

13 " " AREAD W: GOSUB 5: PRINT W: END
14 "=" AREAD W: GOSUB 4: PRINT W: END

DEF S clears memories F(1) to F(8) which are for the fix computation, takes the current DR position, converts to decimal and stores in memories L and O.

30 "S" LPRINT "": PRINT "**START SIGHTS**": FOR V=1 TO 8:F(V)=0: NEXT V:M=5:Z=L(2):X=L(3): GOSUB 3:L=Z:O=X

DEF C dodges the clearing of the previous fix. B is body number: -2, -1, 1 to 59, 90 to 95.

32 "C"Y=B:M$="":P$=": STAR ":Y=Y+90*(B=0): IF Y<-2 OR Y>95 OR (Y>60 AND Y<90) LET Y=90
33 IF Y=-2 GOTO 192

36 generates the characters of the names SUNL, SUNC etc from machine memory.

36 B=Y: IF B>89 LET V=(B-90)*5+7955: FOR W=V TO V+4:M$=M$+ CHR$ ( PEEK W): NEXT W:P$=":BODY
37 PRINT STR$ (F(5)+1);P$; STR$ B;" "+M$: INPUT "BODY OR TIME?";Y: IF Y- INT Y<>0 THEN 39
38 B=Y: GOTO 32

Input time, T, is added to clock correction, K, to give Greenwich time, G. If T is more than 12 hours less than the fix time (the first time entered, in memory F(8),) then 24 hours is added to it.

39 LPRINT USING ;"T",Y:M=0:T=Y:T=T+(T<F(8)-12)*24:G=DEG T+ DEG K: IF B=95 GOTO 340

J is year (temporarily) and P is Julian day number at 0 hours GMT.

41 J= INT ((F- INT F-.19)*๐”ผ4)
42 P= INT 365.25J+32* INT F- INT (1.44* INT F)-33.5+D: IF INT F<3 LET P=P+1+ INT (J/4- INT .25J+.8)
43 Q=259-.053P:S(1)=.005* SIN Q:Q=66.548+356๐”ผ-9P-.0026* COS Q

These are just calculations to give needed parameters. Don't shorten decimal places.

44 A=(G/24+P)*.985647335+99.691-360J-S(1):N=B:W=65: ON B+2 GOTO 180,660 [B is 0 for DEF H identification]
45 IF N<60 GOTO 88 [to compute star coordinates]
46 IF B=60 GOSUB 64: GOTO 350 [to compute a user-entered 'extra' star]
47 IF B=93 OR B=94 GOTO 400 [to moon calculation]

48-49 are only for the sun. S(0) holds semidiameter corr to sun's computed altitude

48 X=101.194+.017186J-A:Z=270-A+ SIN X*(1.914+( COS X)/25):X=Q
49 S(0)=(-.005* COS (Z+9)+.267)*(B-91):Y=0

Subroutine 7 here converts ecliptic lat long to geocentric GHA and dec

50 GOSUB 7:J=W:U=A+15G+O+90+Z [U holds LHA of the body]

Subroutine 7 here converts geocentric LHA and dec to observer's az and alt

51 Z=U:Y=J:X=L: GOSUB 7: IF B=95 OR B=60 LET X=W: GOTO 55 [X is now comp alt]
52 X=W+S(0): IF B<0 RETURN [X is the computed altitude corrected for semidiameter. If B<0 return to 180: W=M-X...]
53 GOSUB 64: IF M=-1 RETURN [M is set to -1 in line 810, noon calculations]
54 M=0 [flag M=0 then =1 the first time, M will become 2 in line 56 when comp alt has been seen.
55 W=56: GOSUB 65:W=W-X: GOTO 58 [W is now the intercept in degrees, not minutes]
56 M=M+1: IF M=2 GOTO 32 [line 32 is to enter the next sight]

Line 57 prints azimuth and computed altitude.

57 W=X: GOSUB 4: PRINT STR$ INT Z;" C.ALT"; USING "###.###";W: GOTO 55 [for another attempt to enter a sext alt]

Line 58 restricts the size of the intercept so that it can't exceed the display.

58 IF ABS W>166 LET W=166* SGN W

F(7) and F(0) hold latest intercept and azimuth

59 F(7)=W:F(0)=Z:P=1: GOSUB 82 [subroutine 82 updates the fix/NP]
61 V$="T": IF W<0 LET V$="A
62 PRINT STR$ INT (Z+.5);" INT "+V$; USING "#####.#";60W: GOTO 32
[to enter the next sight]

A holds LHA Aries, G holds GMT in h.mmss

64 A=A+15G+O:A=A-360* INT (A/360):G= DMS G: RETURN
65 INPUT "SEXT ALT? ";H: LPRINT USING ;"H",H:W=H: GOSUB 5: GOTO 68
67 GOTO W
[if no input of sext alt. Seems W is always 56. This illegally busts out of a subroutine]
68 IF F(8)=0 LET F(8)=T [F(8) holds the time of the first sight entered after DEF S]

In line 69 W is the sextant altitude and Y is the refraction correction at standard temp & pressure

69 V= DEG T- DEG F(8):V=V+(V<-12)*24:Y=I/60-.03*โˆšE-.0167/ TAN (W+7.31/(W+4.4))

Line 70: Y becomes sum of refraction corr and passage corr plus hor parallax in case of moon

70 Y=Y- COS (C-Z)*V*S/60*(B<>0): IF B=93 OR B=94 LET Y=Y+I(4)* COS W
72 W=W+Y: RETURN
[W is now fully corrected observed alt; return to line 55]

F(1) to F(6) are summations for fix/NP

82 RESTORE 84: FOR V=1 TO 6: READ Q:F(V)=F(V)+PQ: NEXT V:RETURN
84 DATA SIN 2Z, COS 2Z,W* COS Z,W* SIN Z,1,WW

88 to 95 get ecliptic star coordinates out of machine memory

88 V=7713+4N:Z=( PEEK V*256+ PEEK (V+1))/182:Y=( PEEK(V+2)*256+ PEEK (V+3))/364-90
92 W=Z-A:V=.35866๐”ผ-6P-.00655:Y=Y-.0057* SIN W* SIN Y+V* SIN Z:X=Q
95 Z=90-Z-.0057* COS W/ COS Y-106.6V+V* COS Z* TAN Y+S(1):S(0)=0: GOTO 50

Unknown star 180 to 192

180 Z=C+90: GOSUB 65:F(0)=V*S/60:M=W:I(0)=98:I(1)=99: FOR N=1 TO 59: GOSUB 88:W=M-X- COS (C-Z)*F(0)
185 IF ABS W< ABS I(0) LET I(1)=I(0):I(0)=W:I(3)=I(2):I(2)=N:I(5)=I(4):I(4)=Z: NEXT N
188 IF ABS W< ABS I(1) LET I(1)=W:I(3)=N:I(5)=Z
190 NEXT N
192 BEEP 2:W=I(-1-B):Z=I(3-B):B=I(1-B): GOTO 58

lines 280-284 replace lines 320-322 when DR clock is used instead of log and log corr

280 PRINT "DR.CLOCK "; STR$ R: INPUT R: GOTO 280
284 GOTO 323

DEF A

300 "A" LPRINT "":V=300: USING "###.####
301 F=F*(F<13)*(F>1): PRINT "MO.YEAR";F: INPUT F: GOTO 301
302 PRINT "DAY", STR$ D: INPUT D:D= ABS D:D= INT D*(D<32): GOTO 302
303 K=K*( ABS K<13):M$="": IF K>0 LET M$="+
304 Z$="": IF K<>0 AND K- INT K=0 LET Z$=" HOURS
305 PRINT "CLCOR "+M$; STR$ K;Z$: INPUT K: GOTO 303
306 PRINT "EYE", STR$ E+" M": INPUT E:E= ABS E: GOTO 306
309 M$="": IF I>0 LET M$="+
310 PRINT "INDEX COR ";M$; STR$ I: INPUT I: GOTO 309
311 GOTO 313

DEF Z

312 "Z"V=315: LPRINT "
313 GOSUB 1: USING "####.###
315 L(2)=L(2)*( ABS L(2)<91):M$="N": IF L(2)<0 LET M$="S
316 PRINT "DR.LAT "+M$;L(2): INPUT L(2): GOTO 315
317 L(3)=L(3)*( ABS L(3)<181):M$="E": IF L(3)<0 LET M$="W
318 PRINT "DR.LON "+M$;L(3): INPUT L(3): GOTO 317
319 IF PEEK 7954>4 THEN 280
320 PRINT "LOG", STR$ R: INPUT R:R= ABS R: GOTO 320
321 X= PEEK 7953-99:M$="": IF X>0 LET M$="+
322 PRINT "LOG COR",M$+ STR$ X+" %": INPUT X:X=X*( ABS X<99): POKE 7953,X+99: GOTO 321
323 PRINT "COURSE", STR$ C: INPUT C: GOTO 323
324 PRINT "SPEED", STR$ S: INPUT S: GOTO 324
325 L(0)=L(0)*( ABS L(0)<91):M$="N": IF L(0)<0 LET M$="S
326 PRINT "DEST. "+M$;L(0): INPUT L(0): GOTO 325
327 L(1)=L(1)*( ABS L(1)<181):M$="E": IF L(1)<0 LET M$="W
328 PRINT "DEST. "+M$;L(1): INPUT L(1): GOTO 327
329 GOTO V
[V is either 300 or 315]

340-344 Planet input

340 PRINT "ALMANAC "; STR$ INT G;".0000
342 INPUT "GHA?";W: LPRINT W:S(1)= INT G: GOSUB 5:A=W: INPUT "DEC?";W: LPRINT W: GOSUB 5:J=W: INPUT "V?";S(0): LPRINT USING;S(0)
344 U=A+(G-S(1))*(15+S(0)/60)+O:G= DMS G: GOTO 51

Extra star input 350-352

350 INPUT "SHA?";W: GOSUB 5:S(0)=W: INPUT "DEC?";W: GOSUB 5:I(0)=W
352 J=I(0):U=S(0)+A: GOTO 51

Line 390 along with lines 1 and 510 are irrelevant confusions

390 POKE 785,69,65: GOSUB PEEK 770: POKE 785,67,73: RETURN

400 to 440 are moon calculations

400 P=(P+G/24)/36525:P=P+22๐”ผ-9P:M=477198.849P-63.89
402 J=483202.025P+11.25:U=445267.114P-9.26: IF I(0)<>99 GOTO 430
406 IF ABS (P-I(1))>2๐”ผ-7 GOTO 430
420 Z=481267883.1P-89567+3/P+6289* SIN M-1274* SIN (M-2U)+658*SIN 2U-5* SIN (1934P+259)
422 Z=(Z+I(2)+214* SIN 2M)/๐”ผ3:Z=90-Z:Z=Z-360* INT (Z/360)
424 Y=(5128* SIN J+281* SIN (M+J)-278* SIN (J-M)+I(3))/๐”ผ3:S(0)=.2725I(4)* SGN (B-93.5):X=Q: GOTO 50
430 I(1)=P:N=35999.05P-1.52:W=0: FOR V=7480 TO 7615 STEP 5: GOSUB 440: NEXT V:I(2)=W
435 W=0: FOR V=7620 TO 7685 STEP 5: GOSUB 440: NEXT V:I(3)=W
437 I(4)=(949+52* COS M+10* COS (M-2U)+8* COS 2U+3* COS 2M+ COS (M+2U))/๐”ผ3:I(0)=99: GOTO 420
440 W=( PEEK V-200)* SIN (( PEEK (V+1)-5)*M+( PEEK (V+2)-5)*N+ PEEK (V+3)*J+( PEEK (V+4)-5)*U)+W: RETURN

DEF D dead reckoning lines 490 to 506

490 "D"N$=" +":Y= PEEK 7953-99:Z=L(2):X=L(3): IF Y<0 LET N$="
491 IF PEEK 7954<5 GOTO 496
492 INPUT "DR.CLOCK? ";M:Q= DEG M- DEG R:Q=Q+(Q<-12)*24:Q=Q*S: GOTO 494
493 GOTO 492
494 PRINT STR$ ( INT (10Q)/10);" @ "; STR$ C;" T":R=M: GOTO 500
496 INPUT "LOG? ";M: LPRINT USING ;"LOG",M:Q=M-R: PRINT STR$ Q;N$; STR$ Y;"% @ "; STR$ C;" T":R=M:Q=Q+Q*Y/100: GOTO 500
497 GOTO 496
500 GOSUB 505: GOSUB 502: GOSUB 8: GOTO 520
502 L(2)=Z:L(3)=X: WAIT 70: PRINT "**DR REPLACED**": WAIT : RETURN
505 M=5: GOSUB 3:N=Z+Q/60* COS C:X=X+Q* SIN C/ COS ((Z+N)/2)/60: IF ABS X>180 LET X=-(360- ABS X)* SGN X
506 Z=N:M=4: GOSUB 3: RETURN

Line 510 with lines 1 and 390 are irrelevant confusions.

510 Z=X-W+21:W=2W: POKE Z,X,W: RETURN

518 is `2 DEF L' spherical solution

518 W= ATN ( TAN J* COS W- SIN W/ COS J/ TAN Z): RETURN

DEF G for great circle and rhumb calculations to line 551

520 "G"Z=L(2):X=L(3)
522 M=5: GOSUB 3:J=Z:A=X:Z=L(0):X=L(1): GOSUB 3:N=X-A+๐”ผ-6: IF ABS N>180 LET N=( ABS N-360)* SGN N
524 P= LN TAN (45+Z/2)- LN TAN (45+J/2):Q=180- ATN (180P/N
ฮ )-90* SGN N
525 P= ABS (60N* COS ((Z+J)/2)): IF ABS COS Q>.0002 LET P=60*(Z-J)/ COS Q
527 M$=" RHUMB ": GOSUB 550:X=J:Y=Z:Z=-N: GOSUB 7:Q=Z:P=(90-W)*60:M$=" GCIRC ": GOSUB 550
529 Q= SGN SIN Z:P=5* INT (A/5): IF Q>0 LET P=P+5
530 W=A-P: GOSUB 518: GOSUB 4:M$=" E": IF P<0 LET M$=" W
531 N$=" N": IF W<0 LET N$=" S
532 PRINT STR$ P;M$;W;N$:P=P+5Q:P=P- SGN P*( ABS P>180)*360: GOTO 530
550 PRINT STR$ INT Q;M$; STR$ ( INT 10P/10): IF S<.1 RETURN
551 P=P/S:Q= INT (P/24):P=P-Q*24: PRINT STR$ Q;" DAYS"; USING "###.##"; DMS P: RETURN

DEF H Identification to line 663

658 "H" INPUT "APPROX TIME? ";Y:B=0: GOTO 39
659 GOTO 658
660 I(0)=O:O=L(3): GOSUB 64:O=I(0)
661 INPUT "APPROX AZ?";Z: LPRINT USING ;"AZ",Z:Z=Z+.1:W=65: GOSUB W:X=L(2):Y=W: GOSUB 7:U=Z:Z=U-A
663 Z=Z-360* INT (Z/360): PRINT "SHA "; STR$ INT Z;" DEC "; STR$ INT W: GOTO 661

DEF V visibility to line 755

750 "V" INPUT "HT OBJ?";P
751 USING : PRINT "EYE "; STR$ E;" OBJ "; STR$ P:X=2.08*(โˆšE+โˆšP):Y=(P-E)*(P>E):M$="VISIBLE
752 INPUT "SEXT ALT?";H:W=H: LPRINT "H",H: GOSUB 5:X=4065* TAN (W+I/60-โˆšE/34):X=โˆš(XX+4.39Y)-X:M$="DIST
755 PRINT USING "####.#";M$;X: GOTO 751

DEF B current to line 779

759 "B" INPUT "SET?";U,"DRIFT?";G
760 GOSUB 778
761 INPUT "CRS?";V,"SPD?";W: LPRINT USING ;V,W: GOTO 763
762 GOTO 761
763 Q=U-V-.01:Z=G* COS Q+W:Y=G* SIN Q: GOSUB 776
764 Z=V+Q:Z=Z-360* INT (Z/360):Y=A-W: USING "###.#":Q=Q-360*(Q>180):N$="+": IF Q<0 LET N$="
765 Y= INT (100Y/W):M$="+": IF Y<0 LET M$="
766 PRINT "T CRS "; STR$ INT (Z+.5);" : ";N$; STR$ INT (Q+.5)
767 PRINT "T SPD";A+.05;": ";M$; STR$ Y;"%": GOTO 761
776 A=โˆš(Z*Z+Y*Y):Q=( ACS (Z/A)-180)* SGN Y+180: RETURN
778 PRINT "SET "; STR$ INT U;" DRI "; STR$ G: RETURN
779 LPRINT "": USING "###.##": PRINT STR$ F(5);" OBS,"+N$;F(8): RETURN

DEF N, F - actual calculation of fix/NP from prepared summations F(n) to line 786.

780 "N"N$=" NP": GOSUB 779:Z=F(3)/F(5):Y=F(4)/F(5):P=โˆš(F(6)/F(5))*60: GOTO 786
781 "F"N$="FIX": GOSUB 779: IF F(5)=1 GOTO 780
[F(5) is number of observations]

What gosub 5 is doing in line 782 I don't know. Apparently V can't be zero.

782 Y=F(1)/2:Z=(F(5)-F(2))/2:X=F(5)-Z: GOSUB 5:V=XZ-YY:Z=(ZF(3)-YF(4))/V:P=0
784 Y=(XF(4)-YF(3))/V: IF F(5)>2 LET P=(F(6)-ZF(3)-YF(4))/(F(5)-2):P=P*(P>0):P=โˆšP*60
786 GOSUB 776:Z=L+Z:X=O+Y/ COS Z:M=4: GOSUB 3: GOSUB 8: PRINT N$+" PREC "; STR$ ( INT 10P/10):U=Q
787 INPUT "TIME PREV FIX? ";M: LPRINT USING ;"PREV",M:M= DEG F(8)- DEG M:M=M+(M<0)*24:G= INT (600A/M)/10: GOSUB 778
789 INPUT "ADVANCE TO? ";M: LPRINT USING ;"ADV TO",M:Q= DEG M- DEG F(8):Q=Q+(Q<-12)*24:Q=Q*S: GOSUB 505: GOSUB 8
790 INPUT "REPLACE DR POS?";M$: GOTO 522
791 GOSUB 502: GOTO 522

DEF K: add a line

792 "K" WAIT 70: PRINT "ADD AZ/INT": WAIT : GOSUB 793:P=1: GOSUB 82: PAUSE "*ADDED*": GOTO 792
793 INPUT "AZ?";Z,"INT?";W: LPRINT USING ;Z,W:W=W/60:F(7)=W:F(0)=Z: RETURN
794 GOTO 793

DEF X: cross out a sight to 799

796 "X" WAIT 70: PRINT "*REJECT*": WAIT : IF F(7)<>0 THEN INPUT "REJ LAST SIGHT?";M$: GOTO 798
797 IF F(7)<>0 LET W=F(7):Z=F(0):F(8)=F(8)*(F(5)<>1): GOTO 799
798 GOSUB 793
799 P=-1: GOSUB 82:F(7)=0: PAUSE "*REJECTED*": GOTO 32
[ ~~~~~32 is to enter a new sight]

line 808 is the spherical transform 1 DEF L

808 X= ACS (( SIN W- SIN J* SIN Q)/ COS J/ COS Q): RETURN

DEF M to 830: meridian passage, twilights when sun is -6ยบ. This should be changed to -9ยบ (W=-6 in line 823).

810 "M"W=L(3): GOSUB 5:B=91:M=-1:G=12-W/15:I(0)=O:O=W: GOSUB 41:O=I(0):T= DEG G-U/15- DEG K
820 T=T-24* INT (T/24):T= DMS T:W=L(2): GOSUB 5:A=A-U:Q=W:W=90- ABS (Q-J): GOSUB 4:M=A:B=90
823 USING "####.##": PRINT "NOON TIME";T: PRINT "NOON ALT";W:W=-6: GOSUB 808:N$="M
826 A=M-X:A=A-360* INT (A/360):W= DMS A:Z= DEG T-X/15:Z=Z-24*INT (Z/24):Z= DMS Z
829 PRINT "CIV TWI "+N$;Z: PRINT "ARIES "+N$;W:X=-X: IF N$="M" LET N$="E": GOTO 826
830 N$="M": GOTO 826

5 DEF L tide interpolator

950 INPUT "REQ.HT?";V:Y= ACS (2*(V-W)/(X-W)-1)*( DEG Q- DEG Z)/180+ DEG Z
954 USING "###.##": PRINT V;" @"; DMS Y: GOTO 950

0 DEF L - speed from timed distance

960 INPUT "MILES?";N,"H.MMSS?";M:V= DEG M:P=N: GOTO 968
961 INPUT "FEET?";N:P=N/6076: GOTO 966
962 INPUT "METRES?";N:P=N/1852: GOTO 966
964 GOTO 960
966 INPUT "S.S?";M:V=M/3600: GOTO 968
967 GOTO 966
968 PRINT STR$ ( INT (100P/V)/100);" KNOTS": GOTO 960

6 DEF L, DR switch clock/log

970 PAUSE "DR SWITCH": POKE 7954,5*(PEEK 7954<5): RETURN
983 "L" AREAD V: PRINT = LPRINT : PAUSE "LP ON": ON V+1 GOSUB 960,808,518,7,987,950,970: END

4 DEF L computer check

987 GOSUB 1:W=0: FOR N=770 TO 7347:W=W+ PEEK N: NEXT N
990 V=0: FOR N=7480 TO 7689:V=V+ PEEK N: NEXT N: FOR N=7717 TO 7952:V=V+ PEEK N: NEXT N
992 FOR N=7955 TO 7999:V=V+ PEEK N: NEXT N: BEEP 1: USING : PRINT W+V-548472

If you have a query I will do my best to answer.

mike.pepperday@gmail.com