$GDTIM - GET DATE AND TIME FROM	MACRO M1110  21-AUG-78 21:26  PAGE 3





      1						.TITLE	$GDTIM - GET DATE AND TIME FROM SYSTEM

      2

      3						.IDENT	"X0001"

      4

      5					;

      6					; COPYRIGHT (C) 1976 BY DIGITAL EQUIPMENT CORPORATION,

      7					; MAYNARD, MASSACHUSETTS

      8					;

      9					; THIS SOFTWARE IS FURNISHED UNDER A LICENSE FOR USE ONLY ON A

     10					; SINGLE  COMPUTER  SYSTEM AND MAY BE COPIED ONLY WITH THE IN-

     11					; CLUSION OF THE ABOVE COPYRIGHT NOTICE.   THIS  SOFTWARE,  OR

     12					; ANY  OTHER  COPIES THEREOF, MAY NOT BE PROVIDED OR OTHERWISE

     13					; MADE AVAILABLE TO ANY OTHER PERSON EXCEPT FOR  USE  ON  SUCH

     14					; SYSTEM  AND TO ONE WHO AGREES TO THESE LICENSE TERMS.  TITLE

     15					; TO AND OWNERSHIP OF THE SOFTWARE SHALL AT ALL  TIMES  REMAIN

     16					; IN DIGITAL.

     17					;

     18					; THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE  WITH-

     19					; OUT  NOTICE  AND  SHOULD NOT BE CONSTRUED AS A COMMITMENT BY

     20					; DIGITAL EQUIPMENT CORPORATION.

     21					;

     22					; DIGITAL EQUIPMENT CORPORATION ASSUMES NO RESPONSIBILITY  FOR

     23					; THE USE OR RELIABILITY OF ITS SOFTWARE ON EQUIPMENT WHICH IS

     24					; NOT SUPPLIED BY DIGITAL.

     25					;

     26					; ANDREW C. GOLDSTEIN  17 JUN 76  17:17

     27

     28	000000					SMACIT

     29

     30						.MACRO	$SAVRG

     31						JSR	R5,$SAVRG

     32						.ENDM	$SAVRG

     33

     34						.MCALL	GTIM$S

     35

     36

     37

     38						.MACRO	.QUAD	WORD

     39						$$$B1=0

     40						$$$B2=0

     41						$$$B3=0

     42						$$$B4=0

     43						$$$B5=0

     44						$$$B6=0

     45						$$$B7=0

     46						$$$B8=0

     47						.IRPC	D,WORD

     48						$$$B1=$$$B1*10.+D'.

     49						$$$C=$$$B1/256.

     50						$$$B1=$$$B1&^O377

     51						$$$B2=$$$B2*10.+$$$C

     52						$$$C=$$$B2/256.

     53						$$$B2=$$$B2&^O377

     54						$$$B3=$$$B3*10.+$$$C

     55						$$$C=$$$B3/256.

     56						$$$B3=$$$B3&^O377

     57						$$$B4=$$$B4*10.+$$$C

$GDTIM - GET DATE AND TIME FROM	MACRO M1110  21-AUG-78 21:26  PAGE 3-1





     58						$$$C=$$$B4/256.

     59						$$$B4=$$$B4&^O377

     60						$$$B5=$$$B5*10.+$$$C

     61						$$$C=$$$B5/256.

     62						$$$B5=$$$B5&^O377

     63						$$$B6=$$$B6*10.+$$$C

     64						$$$C=$$$B6/256.

     65						$$$B6=$$$B6&^O377

     66						$$$B7=$$$B7*10.+$$$C

     67						$$$C=$$$B7/256.

     68						$$$B7=$$$B7&^O377

     69						$$$B8=$$$B8*10.+$$$C

     70						$$$C=$$$B8/256.

     71						$$$B8=$$$B8&^O377

     72						.ENDM

     73						$$$W1=$$$B2*256.+$$$B1

     74						$$$W2=$$$B4*256.+$$$B3

     75						$$$W3=$$$B6*256.+$$$B5

     76						$$$W4=$$$B8*256.+$$$B7

     77						.LIST	MEB

     78						.WORD	$$$W1,$$$W2

     79						.WORD	$$$W3,$$$W4

     80						.NLIST	MEB

     81						.ENDM	.QUAD

$GDTIM - GET DATE AND TIME FROM	MACRO M1110  21-AUG-78 21:26  PAGE 4





     83					;

     84					; SOME CONSTANTS

     85					;

     86

     87		000012 				.RADIX	10

     88

     89	000000				Q24:	.QUAD	24		; HOURS IN A DAY

	000000	000030 	000000 			.WORD	$$$W1,$$$W2

	000004	000000 	000000 			.WORD	$$$W3,$$$W4

     90	000010				Q60:	.QUAD	60		; MINUTES PER HOUR AND SECONDS PER MINUTE

	000010	000074 	000000 			.WORD	$$$W1,$$$W2

	000014	000000 	000000 			.WORD	$$$W3,$$$W4

     91	000020				QNS:	.QUAD	10000000	; TENTHS OF MICROSECONDS IN A SECOND

	000020	113200 	000230 			.WORD	$$$W1,$$$W2

	000024	000000 	000000 			.WORD	$$$W3,$$$W4

     92

     93		002665 			FDAYS = 365*4+1			; NUMBER OF DAYS IN 4 YEARS

     94		107254 			CDAYS = FDAYS*25-1		; NUMBER OF DAYS IN A CENTURY

     95		035261 			QDAYL = 15025			; NUMBER OF DAYS IN QUADRICENTURY, LOW

     96		000002 			QDAYH = 2			; NUMBER OF DAYS IN QUADRICENTURY, HIGH

     97		067754 			DS16L = 28652			; NUMBER OF DAYS BETWEEN 1-JAN-1601 AND

     98		000001 			DS16H = 1			; 17-NOV-1858, LOW AND HIGH

     99

    100

    101		000010 				.RADIX

$GDTIM - GET DATE AND TIME FROM	MACRO M1110  21-AUG-78 21:26  PAGE 5





    103					;+

    104					;

    105					; *** - $GDTIM	GET DATE AND TIME FROM SYSTEM

    106					;

    107					; THIS ROUTINE RETURNS THE CURRENT DATE AND TIME OBTAINED FROM

    108					; THE OPERATING SYSTEM IN THE STANDARD DATE/TIME FORMAT - 64 BITS

    109					; OF TENS OF NANO-SECONDS ELAPSED SINCE 17-NOV-1858.

    110					;

    111					; INPUTS:

    112					;

    113					;	R1 = ADDRESS OF 8 BYTE BUFFER FOR DATE/TIME

    114					;

    115					; OUTPUTS:

    116					;

    117					;	DATE/TIME IN SPECIFIED BUFFER

    118					;	R2 = 0

    119					;	ALL OTHER REGISTERS PRESERVED

    120					;

    121					;-

    122

    123	000030				$GDTIM::

    124	000030					$SAVRG				; SAVE REGISTERS

    125	000034					PUSH R0,R1,#0

    126	000044					LET SP := SP - #16.		; ALLOCATE DATE/TIME BUFFER ON STACK

    127	000050					LET R1 := SP

    128	000052					GTIM$S R1			; GET DATE AND TIME FROM SYSTEM

    129	000062					LET (SP) := (SP) + #1900.	; PUT IN TRUE YEAR

    130

    131

    132					;+

    133					;

    134					; *** - $CBDDT	CONVERT TO STANDARD DATE AND TIME

    135					;

    136					; THIS ALTERNATE ENTRY POINT IS USED BY THE ROUTINE $CATDT TO COMPLETE

    137					; ITS CONVERSION. $CATDT PARSES THE ASCII DATE/TIME STRING INTO THE

    138					; SAME FORMAT AS THAT RETURNED ABOVE, AND FALLS INTO THIS CODE FOR THE

    139					; FINAL CONVERSION. THIS ENTRY IS JUMPED TO. ON ENTRY, THE STACK CONTAINS:

    140					;

    141					;	00(SP) - CALENDAR YEAR

    142					;	02(SP) - MONTH (NUMBERED 1 - 12)

    143					;	04(SP) - DAY (NUMBERED 1 - 31)

    144					;	06(SP) - HOUR OF DAY

    145					;	10(SP) - MINUTE OF HOUR

    146					;	12(SP) - SECOND OF MINUTE

    147					;	14(SP) - TICK OF SECOND

    148					;	16(SP) - CLOCK RATE (TICKS PER SECOND)

    149					;	20(SP) - SAVED R2

    150					;	22(SP) - SAVED R1

    151					;	24(SP) - SAVED R0

    152					;	26(SP) - RETURN PC (TO $SAVRG ROUTINE)

    153					;

    154					; BASIC THEORY OF OPERATION:

    155					;

    156					; THIS ROUTINE ACCOUNTS FOR THE BASIC LEAP YEAR CYCLES - EVERY FOURTH

    157					; YEAR IS, EXCEPT EVERY 100TH ISN'T, EXCEPT EVERY 400TH IS. YEAR

    158					; 2000 IS A LEAP YEAR. THE CALENDAR YEAR IS CONVERTED TO YEARS SINCE

    159					; 1601, MAKING THE LEAP YEAR UNDER DISPUTE THE LAST YEAR OF EACH OF

$GDTIM - GET DATE AND TIME FROM	MACRO M1110  21-AUG-78 21:26  PAGE 5-1





    160					; THE 4, 100, AND 400 YEAR CYCLES. BY DIVIDING DOWN, WE COMPUTE THE

    161					; INTEGER NUMBER OF EACH TYPE OF CYCLE ELAPSED SINCE 1601. EACH VALUE

    162					; IS THEN MULTIPLIED BY THE EXACT NUMBER OF DAYS IN THAT CYCLE. THE

    163					; SUM, REDUCED BY THE EXACT NUMBER OF DAYS FROM 1-JAN-1601 TO

    164					; 17-NOV-1858, YIELDS THE NUMBER OF DAYS ELAPSED SINCE 17-NOV-1858.

    165					;

    166					;-

    167

    168	000066				$CBDDT::

    169	000066					LET R5 := 22(SP)		; POINT TO LOCATION OF DATE/TIME

    170	000072					LET R3 := R5

    171	000074					LET (R3)+ := #0			; INIT BUFFER CONTENTS

    172	000076					LET (R3)+ := #0

    173	000100					LET (R3)+ := #0

    174	000102					LET (R3)+ := #0

    175

    176	000104					IF #1 OFF.IN 20(SP)		; SKIP DATE CONVERSION IF NONE

    177	000114					  LET R4 := #1			; INIT LEAP YEAR FLAG TO NO

    178	000120					  $CALL $DIV <(SP),#400.>	; EVERY 400TH IS A LEAP YEAR

    179	000132					  IF R1 EQ #0

    180	000136					    LET R4 := #0

    181	000140					  ELSE

    182	000142					    $CALL $DIV <(SP),#100.>	; EVERY 100TH IS NOT

    183	000154					    IF R1 NE #0

    184	000160					      $CALL $DIV <(SP),#4>	; AND EVERY 4TH IS

    185	000172					      IF R1 EQ #0 THEN LET R4 := #0

    186	000200					    END

    187	000200					  END

    188

    189	000200					  LET R0 := (SP)+ - #1601.	; GET YEAR SINCE 1601

    190	000206					  $CALL $DIV <R0,#400.>		; COMPUTE NUMBER OF QUADRICENTURIES

    191	000216					  PUSH R0			; AND SAVE THAT

    192	000220					  $CALL $DIV <R1,#100.>		; COMPUTE NUMBER OF CENTURIES

    193	000232					  PUSH R0			; AND SAVE

    194	000234					  $CALL $DIV <R1,#4.>		; COMPUTE NUMBER OF QUAD YEARS

    195	000246					  PUSH R0			; AND SAVE

    196

    197	000250					  $CALL $MUL <#365.,R1>		; NUMBER OF DAYS SINCE LAST LEAP YEAR

    198	000260					  LET (R5) := R1

    199	000262					  $CALL $MUL <#FDAYS,(SP)+>	; NUMBER OF DAYS IN CENTURY

    200	000274					  LET (R5) := (R5) + R1

    201	000276					  $CALL $MUL <#CDAYS,(SP)+>	; NUMBER OF DAYS IN QUAD CENT

    202	000310					  LET (R5) := (R5) + R1

    203	000312					  LET 2(R5) := R0 + CARRY

    204	000322					  $CALL $MUL <#CDAYS,(SP)>	; COMPUTE DAYS IN FULL QUAD CENT

    205	000334	006301 				  ASL R1			; WHICH IS 4X DAYS IN CENTURY

    206	000336	006100 				  ROL R0			; PLUS ONE

    207	000340	006301 				  ASL R1			; THE FULL NUMBER OF DAYS IN A

    208	000342	006100 				  ROL R0			; QUADRICENTURY IS BIGGER THAN

    209	000344	062601 				  ADD (SP)+,R1			; 16 BITS, SO WE DO THIS KLUGE

    210	000346	005500 				  ADC R0			; RATHER THAN PULL IN A DOUBLE MUL

    211	000350					  LET (R5) := (R5) + R1

    212	000352					  LET 2(R5) := 2(R5) + CARRY + R0

    213					;

    214					; NOW ADD IN THE DAYS IN THE MONTHS OF THE CURRENT YEAR AND THE DAY OF

    215					; THE MONTH.

    216					;

$GDTIM - GET DATE AND TIME FROM	MACRO M1110  21-AUG-78 21:26  PAGE 5-2





    217	000362					  POP R0			; GET MONTHS

    218	000364					  LET R1 := #1

    219	000370					  REPEAT

    220	000370					    LET R2 :B= $DAYTB-1(R1)	; GET # DAYS IN MONTHS

    221	000374					    IF R1 EQ #2 THEN LET R2 := R2 - R4 ; ADJUST FEBRUARY

    222	000404					    IF R1 HIS R0 LEAVE LOOP

    223	000410					    LET (R5) := (R5) + R2

    224	000412					    LET 2(R5) := 2(R5) + CARRY	; AND ACCUMULATE

    225	000416					    LET R1 := R1 + #1		; BUMP TO NEXT MONTH

    226	000420					  END LOOP

    227	000422					  IF (SP) HI R2 GOTO ERROR	; CHECK DAY AGAINST SIZE OF MONTH

    228	000426					  LET (R5) := (R5) + (SP)+	; ADD DAY OF MONTH

    229	000430					  LET 2(R5) := 2(R5) + CARRY

    230					;

    231					; ADJUST TO NUMBER OF DAYS SINCE 17-NOV-1858

    232					;

    233	000434					  LET (R5) := (R5) - #DS16L

    234	000440					  LET 2(R5) := 2(R5) - CARRY - #DS16H

    235	000452					ELSE				; IF NO DATE CONVERSION

    236	000454					  LET SP := SP + #6		; CLEAN DATE WORDS OFF STACK

    237	000460					END

    238					;

    239					; NOW SCALE UP BY THE TIME UNITS AND ADD IN TIME OF DAY

    240					;

    241	000460					LET R4 := SP			; POINT TO REST OF PARAMETERS

    242	000462					LET SP := SP - #8.		; ALLOCATE 64 BIT SCRATCH

    243	000466					$CALL $MULQ <#Q24,R5,SP>	; CONVERT DAYS TO HOURS

    244	000502					LET R3 := SP

    245	000504	062423 				ADD (R4)+,(R3)+			; ADD IN HOURS OF DAY

    246	000506	005523 				ADC (R3)+

    247	000510	005523 				ADC (R3)+

    248	000512	005523 				ADC (R3)+

    249	000514					$CALL $MULQ <#Q60,SP,R5>	; CONVERT HOURS TO MINUTES

    250	000530					LET R3 := R5

    251	000532	062423 				ADD (R4)+,(R3)+			; ADD IN MINUTES OF HOUR

    252	000534	005523 				ADC (R3)+

    253	000536	005523 				ADC (R3)+

    254	000540	005523 				ADC (R3)+

    255	000542					$CALL $MULQ <R0,R5,SP>		; CONVERT MINUTES TO SECONDS

    256	000552					LET R3 := SP

    257	000554	062423 				ADD (R4)+,(R3)+			; ADD IN SECONDS OF MINUTE

    258	000556	005523 				ADC (R3)+

    259	000560	005523 				ADC (R3)+

    260	000562	005523 				ADC (R3)+

    261	000564					$CALL $MULQ <#QNS,SP,R5>	; CONVERT SECONDS TO 100 NS

    262	000600					LET SP := SP + #18.		; CLEAN ALL JUNK OFF STACK

    263	000604					POP R2,R1,R0			; RESTORE REGISTERS

    264	000612					RETURN

    265					;

    266					; TO HERE IF THE DAY IS GREATER THAN THE NUMBER OF DAYS IN THE MONTH.

    267					;

    268	000614				ERROR:	LET SP := SP + #14.		; CLEAN THE STACK

    269	000620					LET R2 := #100000		; SET ERROR FLAG

    270	000624					POP R1,R0

    271	000630					RETURN ERROR

    272

    273

$GDTIM - GET DATE AND TIME FROM	MACRO M1110  21-AUG-78 21:26  PAGE 5-3





    274

    275		000001 				.END

$GDTIM - GET DATE AND TIME FROM	MACRO M1110  21-AUG-78 21:26  PAGE 5-4

SYMBOL TABLE



B0      000370R  	LBLS0 = 000006   	TYPS0 = 000000   	$L$   = 000000   	$$$B1 = 000200

CDAYS = 107254   	LBLS1 = 000006   	TYPS1 = 000000   	$MUL  = ****** GX	$$$B2 = 000226

DS16H = 000001   	LBLS2 = 000006   	TYPS2 = 000000   	$MULQ = ****** GX	$$$B3 = 000230

DS16L = 067754   	LBLS3 = 000004   	TYPS3 = 000000   	$O$   = 000000   	$$$B4 = 000000

ERROR   000614R  	L0      000454R  	$CBDDT  000066RG 	$R    = 177777   	$$$B5 = 000000

E0      000422R  	L1      000142R  	$DAYTB= ****** GX	$SAVRG= ****** GX	$$$B6 = 000000

FDAYS = 002665   	L2      000200R  	$DIDDO= 000000   	$SUPMC= 000043   	$$$B7 = 000000

G.TICP= 000016   	L3      000200R  	$DIV  = ****** GX	$T    = 000007   	$$$B8 = 000000

G.TICT= 000014   	L4      000200R  	$EF$  = 000000   	$T1   = 000000   	$$$C  = 000000

G.TIDA= 000004   	L5      000404R  	$E$   = 000001   	$T2   = 000006   	$$$OST= 000020

G.TIHR= 000006   	L6      000460R  	$GDTIM  000030RG 	$XXX$ = 000001   	$$$W1 = 113200

G.TIMI= 000010   	QDAYH = 000002   	$I$   = 000001   	$Y$   = 000000   	$$$W2 = 000230

G.TIMO= 000002   	QDAYL = 035261   	$K$   = 000000   	$Z$   = 000000   	$$$W3 = 000000

G.TISC= 000012   	QNS     000020R  	$K$L  = 000000   	$$T   = 000005   	$$$W4 = 000000

G.TIYR= 000000   	Q24     000000R  	$K$T  = 000005   	$$TT  = 000006   	.$T   = 000003

IIII  = 177777   	Q60     000010R  	$L    = 000001



. ABS.	000000	   000

      	000634	   001

ERRORS DETECTED:  0



VIRTUAL MEMORY USED:  12360 WORDS  ( 49 PAGES)

DYNAMIC MEMORY:  13332 WORDS  ( 51 PAGES)

ELAPSED TIME:  00:01:53

EXE$:GDTIM,LIS$:GDTIM/-SP=SRC$:SMAC/PA:1,DSCPRE,GDTIM

