perm filename TIMES.FAI[S,NET]1 blob sn#715328 filedate 1983-06-12 generic text, type C, neo UTF8
COMMENT ⊗   VALID 00006 PAGES
C REC  PAGE   DESCRIPTION
C00001 00001
C00002 00002	 GMTDIF A B C D E N N1 P PDLLEN PDL
C00003 00003	 GO LUP LUPNXT NTMTAB NTHSTS
C00012 00004	 IOIMPM IODERR IODTER IOBKTL IODEND ERRBTS NETIM TIME CONBLK CONSTS CONLSK CONHST
C00015 00005	 TIMCAS TIMCA2 TIMCA3 TM$SEC TM$DAY TM$MON TM$YR TMONTB
C00019 00006	 TIMOUT DEC2OU DECOUT
C00021 ENDMK
C⊗;
;⊗ GMTDIF A B C D E N N1 P PDLLEN PDL

TITLE TIMES

; Time Sites
; Hack courtesy of KLH
; Hacked for SAIL by MRC

GMTDIF←←=8

A←1
B←2
C←3
D←4
E←5
N←10
N1←11
P←17

PDLLEN←←20
PDL:	BLOCK PDLLEN
	0
;⊗ GO LUP LUPNXT NTMTAB NTHSTS

GO:	CAI
	RESET
	MSTIME
	MOVEM TSTART#
	MOVEI 261
	PEEK
	PEEK
	MOVEM DAYLIT#
	MOVE P,[-PDLLEN,,PDL]
	OUTSTR [ASCIZ/ Site	Greenwich Mean Time	Local Time
/]
	; Now loop thru sites in table...
	MOVSI C,-NTHSTS
LUP:	HRRZ A,NTMTAB(C)
	OUTSTR (A)		; Type site name.
	HLRZ A,NTMTAB(C)	; Get ptr to site # to hack, and
	MOVE A,(A)		; get IP host number
	PUSHJ P,NETIM		; Get net time for foreign site.
	 JRST [	OUTSTR [ASCIZ/'s time is unavailable.
/]
		JRST LUPNXT]

	; Here, have net time in A.  Print out...
	MOVE B,A		; save
	PUSHJ P,TIMCAS		; Convert one as GMT,
	EXCH A,B		; get saved value,
	SUBI A,GMTDIF*=3600	; and use to get local-time value,
	SKIPE DAYLIT
	 ADDI A,=3600		; daylight losing time
	PUSHJ P,TIMCAS		; converted thereto.
	OUTSTR [ASCIZ/	/]
	MOVE D,B
	PUSHJ P,TIMOUT
	OUTSTR [ASCIZ/  ->  /]
	MOVE D,A
	PUSHJ P,TIMOUT
	SKIPE DAYLIT
	 JRST [	OUTSTR [ASCIZ/ PDT.
/]
		JRST LUPNXT]
	OUTSTR [ASCIZ/ PST.
/]
LUPNXT:	AOBJN C,LUP
	MSTIME A,			; Get sys time at end.
	SUB A,TSTART			; Find total 1000'ths we ran in real time.
	IDIVI A,=1000			; # secs in A, rem in B
	IDIVI B,=10			; Get 2 digits after decimal pt.
	OUTSTR [ASCIZ/Realtime used: /]
	MOVEI N,(A)
	PUSHJ P,DECOUT
	OUTCHR ["."]
	MOVEI N,(B)
	PUSHJ P,DECOUT
	OUTSTR [ASCIZ/ secs
/]
	EXIT

NTMTAB:
repeat 0,<
	 20000,,[ASCIZ /AMES-67/]
	  6002,,[ASCIZ /MIT-AI/]
	  6003,,[ASCIZ /MIT-ML/]
	  6001,,[ASCIZ /MIT-DM/]
	 54003,,[ASCIZ /MIT-MC/]
	 13000,,[ASCIZ /SU-AI/]
	111001,,[ASCIZ /SRIWARF/]
>;repeat 0

DEFINE HOST (H1,H2,H3,H4,HNAME)<
	[BYTE (4)0 (8)H1,H2,H3,H4],,[ASCIZ /HNAME/]
>;DEFINE HOST

radix 5+5

HOST(10,0,0,11,SU-AI)
HOST(8,0,0,2,BBNCCA)
HOST(8,1,0,2,BBNCCB)
HOST(8,2,0,2,BBNCCC)
HOST(8,3,0,2,BBNCCD)
HOST(8,0,0,3,BBNCCG)
HOST(8,0,0,4,BBNCCF)
HOST(8,3,0,4,BBNCCI)
HOST(8,1,0,5,BBN-CD)
;HOST(8,1,0,6,BBN-ADMIN)
;HOST(8,2,0,6,BBN-INOC)
HOST(8,3,0,6,BBNW)
HOST(8,0,0,7,BBNS)
HOST(8,1,0,7,BBNZ)
HOST(8,2,0,7,BBNQ)
HOST(8,0,0,8,BBNX)
HOST(8,2,0,8,BBNY)
;HOST(8,0,0,14,CSNET-CIC)
HOST(8,1,0,14,BBN-NOC)
HOST(10,0,0,5,BBNF)
HOST(10,1,0,5,BBNG)
HOST(10,3,0,5,BBNA)
HOST(10,1,0,6,MIT-DMS)
HOST(10,3,0,6,MIT-ML)
HOST(10,0,0,29,BRL)
HOST(10,0,0,44,MIT-XX)
HOST(10,3,0,44,MIT-MC)
HOST(10,0,0,51,ST-NIC)
;HOST(10,1,0,72,BBN-UNIX)
HOST(10,2,0,72,BBNP)
HOST(10,0,0,73,SRI-NIC)
;HOST(10,1,0,77,MIT-DEVMULTICS)
;HOST(10,0,0,80,HI-MULTICS)
HOST(10,0,0,82,BBNT)
HOST(10,3,0,82,DDN1)
;HOST(10,6,0,82,BBN-NOC2)
;HOST(128,20,1,2,BRL-HEP)
HOST(192,5,21,1,BRL-BMD)
HOST(192,5,21,2,BRL-VLD)
;HOST(192,5,25,3,BRL-HEL)
;HOST(192,5,21,6,BRL-VGR)
NTHSTS←←.-NTMTAB

radix 4+4
;⊗ IOIMPM IODERR IODTER IOBKTL IODEND ERRBTS NETIM TIME CONBLK CONSTS CONLSK CONHST

; NETIM - Hack to pluck 32-bit Network-time word from site
;	specified by A.  Returns value in A and skips,
;	doesn't skip if couldn't get.

; I/O status word error bits

↑IOIMPM←←400000				; improper mode
↑IODERR←←200000				; hard device error
↑IODTER←←100000				; soft device error
↑IOBKTL←←040000				; block number out of bounds
↑IODEND←←020000				; end of file

ERRBTS←←<IOIMPM!IODERR!IODTER!IOBKTL!IODEND>

NETIM:	MOVEM A,CONHST
	INIT 17				; open in dump mode
	 'IMP',,			; device IMP:
	 0				; no buffers
	 JRST 4,.
	MTAPE [17 ↔ BYTE (6)1,0,0,3,3,0]; set timeouts
	SETOM CONLSK			; gensym socket to use
	MTAPE CONBLK			; connect → foreign logger
	MOVE CONSTS			; check for MTAPE error
	TRNE 77
	 POPJ P,
	STATZ ERRBTS
	 POPJ P,
	TLC 300000			; for next instruction to win
	TLCE 300000			; legal socket state?
	 POPJ P,
	HRROI A,TIME-1			; get ready to get a socket
	SETZ B,				; stop code for dump mode
	IN A				; get socket from logger
	 AOS (P)			; won
	LDB A,[044000,,TIME]
	RELEASE
	POPJ P,

TIME:	BLOCK 1				; time

CONBLK:	0				; CONNECT
CONSTS:	BLOCK 1				; returned status bits
CONLSK:	BLOCK 1				; local socket
	-1				; ≠ 0 → wait for connection until timeout
	BLOCK 1				; byte size
	45				; foreign socket
CONHST:	BLOCK 1				; foreign host
;⊗ TIMCAS TIMCA2 TIMCA3 TM$SEC TM$DAY TM$MON TM$YR TMONTB

; TIMCAS - Converts Absolute Seconds to time word.
;	Argument in A (# secs since 1/1/00), returns time wd in A.

TIMCAS:	PUSH P,B
	PUSH P,C
	IDIVI A,=24*=60*=60	; Get remainder of # secs in day
	PUSH P,B
	IDIVI A,=365		;find # "normal" years.
	JUMPE A,TIMCA2		; Avoid 1900 lossage.
	MOVEI C,-1(A)		;now see how many leap years covered (not incl current)
	LSH C,-2		;divide by 4 to get # leap yrs
	SUBI B,(C)		;adjust cnt of remaining days
	JUMPGE B,TIMCA2
	SUBI A,1		;backed past year boundary? bump down # yrs
	ADDI B,=365		;if negative, must adjust again
	TRNN A,3		;if in leap year,
	 ADDI B,1		;add one more since 366. days in LY
TIMCA2:	MOVEI C,=12
	CAMGE B,TMONTB(C)	;compare # days in year with # days after each month
	 SOJG C,.-1		;loop (#1 index has 0 value, so it will stop)
	TRNN A,3		;leap year?
	 CAIGE C,3		;ugh, yes. but if in jan or feb,
	  JRST TIMCA3		;saved.  else it's after feb and must hack it.
	SUBI B,1		;lower value
	CAMGE B,TMONTB(C) 	;still wins?
	 SUBI C,1		;if not, bump month down.
	CAIN C,2		;if now in Feb,
	 AOJA B,.+1		;restore value so subtracting TMONTB gives 29, not 28.
TIMCA3:	SUB B,TMONTB(C)		;get # of day within month
	DPB A,[TM$YR,,A]	;deposit year
	DPB C,[TM$MON,,A]	;and month
	MOVEI B,1(B)		; First day of month is day 1, not day 0.
	DPB B,[TM$DAY,,A]	;and day.
	ANDCMI A,-1		;Zap RH to start of day.
	POP P,B
	LSH B,1
	ADDI A,(B)		; Add in # half secs.
	POP P,C
	POP P,B
	POPJ P,

; Mask    Field     Bits	Range	Var.    Variable range

;TM%SEC== 777776    ; 2.9-1.2	0-131K	seconds	0-86399.
;TM%DAY==     37,,0 ; 3.5-3.1	0-31	days	1-31
;TM%MON==    740,,0 ; 3.9-3.6	0-15	months	1-12
;TM%YR==  177000,,0 ; 4.7-4.1	0-127	years	0-127 relative to 1900 (1900-2027)
TM$SEC←←<(<POINT 17,0,34>)>	; Define BP LH's into each field.
TM$DAY←←<(<POINT 5,0,17>)>
TM$MON←←<(<POINT 4,0,12>)>
TM$YR←←<(<POINT 7,0,8>)>

	; Special table to allow figuring how many days so far
	; in this year.  Indexed by month # (1-12) gives # days
	; taken up by months preceding it.  Assumes non-leap year.
TMONTB:	0
	0
	=31	;+jan
	=59	;+jan+feb
	=90	;+jan+feb+mar...
	=120	;...+apr
	=151	;...+may
	=181	;...+jun
	=212	;...+jul
	=243	;...+aug
	=273	;...+sep
	=304	;...+oct
	=334	;...+nov
;⊗ TIMOUT DEC2OU DECOUT

; TIMOUT - Output date/time in D

TIMOUT:	LDB N,[TM$MON,,D]
	PUSHJ P,DEC2OU
	OUTCHR ["/"]
	LDB N,[TM$DAY,,D]
	PUSHJ P,DEC2OU
	OUTCHR ["/"]
	LDB N,[TM$YR,,D]
	PUSHJ P,DEC2OU
	OUTCHR [" "]
	LDB N,[TM$SEC,,D]
	IDIVI N,=60*=60
	PUSH P,N1
	PUSHJ P,DEC2OU
	OUTCHR [":"]
	POP P,N
	IDIVI N,=60
	PUSH P,N1
	PUSHJ P,DEC2OU
	OUTCHR [":"]
	POP P,N
;	JRST DEC2OU

; DEC2OU - Output two-digit decimal number in N

DEC2OU:	IDIVI N,=10
	ADDI N,"0"
	OUTCHR N
	ADDI N1,"0"
	OUTCHR N1
	POPJ P,

; DECOUT - Output decimal number in N

DECOUT:	IDIVI N,=10
	PUSH P,N1
	SKIPE N
	 PUSHJ P,DECOUT
	POP P,N
	ADDI N,"0"
	OUTCHR N
	POPJ P,

END GO