Trailing-Edge
-
PDP-10 Archives
-
decuslib10-11
-
43,50527/date.mac
There is 1 other file named date.mac in the archive. Click here to see a list.
Title Date - Universal date/time conversion routines
; These routines were stolen from SCAN.MAC, Copyright Digital Equiptment
; These routines convert from system date/time format to universal date/time and back.
Twoseg
Reloc 400000
Reloc
T1=1
T2=2
T3=3
T4=4
P1=5
P=0
Entry Dattouni,Unitodat
TMP: Z
SP1: Z ; Save P1
Subttl Actual routines
Reloc ;Hiseg
;SUBROUTINE TO CONVERT FROM UNIVERSAL DATE.TIME WORD IN T3 TO 15 BIT
;RETURNS T1=MILLISECOND TIME (SINCE MIDNIGHT), T2= 15 BIT DATE.
;
UNITODAT::
.CNTDT: MOVE T1,T3 ;DEC VERSION NEEDS IT IN T1
MOVEM T1,TMP ;SAVE TIME FOR LATER
JUMPL T1,CNTDT6 ;DEFEND AGAINST JUNK INPUT
HLRZ T1,T1 ;GET DATE PORTION (DAYS SINCE 1858)
RADIX 10 ;**** NOTE WELL ****
ADDI T1,365*400+24*4-<2001-1859>*365-<2001-1859>/4-31-30+17 ;MAKE INTO DAYS SINCE JAN 1, 1601
IDIVI T1,365*400+24*4+1 ;SEPARATE UNITS OF 400
LSH T1,2 ;MULT ANSWER BY 4
IDIVI T2,365*100+24 ;SEPARATE CENTURIES
CAIN T2,4 ;SEE IF LAST ONE
SOSA T2 ;YES--BACK OFF
JRST .+2 ;CONTINUE SKIP
MOVEI T3,365*100+24 ;SET TO FULL (LEAP) CENTURY
ADD T1,T2 ;INCLUDE CENTURIES IN RESULT
IMULI T1,25 ;MULT ANSWER BY 25
IDIVI T3,365*4+1 ;SEPARATE UNITS OF 4
ADD T1,T3 ;INCLUDE IN ANSWER
LSH T1,2 ;MULT ANSWER BY 4
MOVE T3,T4 ;PROMOTE AC
IDIVI T3,365 ;SEPARATE YEARS
CAIN T3,4 ;SEE IF END OF LEAP YEAR
SOSA T3 ;YES--BACK OFF YEAR
JRST .+2 ;CONTINUE SKIP
MOVEI T4,365 ;SET FOR END OF YEAR
ADDI T1,1601(T3) ;GET REAL YEAR
;T1 HAS YEAR, T4 HAS DAY IN YEAR
MOVE T2,T1 ;COPY YEAR TO SEE IF LEAP YEAR
IDIVI T2,400 ;SEE IF MULT OF 400
JUMPE T3,CNTDT1 ;YES--PROCEED
MOVE T2,T1 ;GET NEW COPY
IDIVI T2,100 ;SEE IF MULT OF 100
JUMPE T3,[MOVEI T3,1 ;YES--FLAG AS NO L.Y.
JRST CNTDT1] ;AND PROCEED
MOVE T2,T1 ;GET NEW COPY
IDIVI T2,4 ;SEE IF MULT OF 4
;T3 IS 0 IF LEAP YEAR
;UNDER RADIX 10 **** NOTE WELL ****
CNTDT1: SUBI T1,1964 ;SET TO SYSTEM ORIGIN
IMULI T1,31*12 ;CHANGE TO SYSTEM PSEUDO DAYS
JUMPN T3,CNTDT2 ;IF NOT LEAP YEAR, PROCEED
CAIGE T4,31+29 ;LEAP YEAR--SEE IF BEYOND FEB 29
JRST CNTDT5 ;NO--JUST INCLUDE IN ANSWER
SOS T4 ;YES--BACK OFF ONE DAY
CNTDT2: MOVSI T2,-11 ;LOOP FOR 11 MONTHS
CNTDT3: CAMGE T4,.MNTAB+1(T2) ;SEE IF BEYOND THIS MONTH
JRST CNTDT4 ;YES--GO FINISH UP
ADDI T1,31 ;NO--COUNT SYSTEM MONTH
AOBJN T2,CNTDT3 ;LOOP THROUGH NOVEMBER
CNTDT4: SUB T4,.MNTAB(T2) ;GET DAYS IN THIS MONTH
CNTDT5: ADD T1,T4 ;INCLUDE IN FINAL RESULT
CNTDT6: EXCH T1,TMP ;SAVE ANSWER, GET TIME
TLZ T1,-1 ;CLEAR DATE
MUL T1,[24*60*60*1000] ;CONVERT TO MILLI-SEC.
ASHC T1,17 ;POSITION RESULT
MOVE T2,TMP ;RECOVER DATE
POPJ P, ;RETURN
;UNDER RADIX 10 **** NOTE WELL ****
;.CNVDT -- CONVERT 12 OR 15 BIT DATE TO UNIVERSAL DATE
;CALL: MOVE T1,TIME IN MILLISEC.
; MOVE T2,DATE IN 12 OR 15 BIT FORMAT
; PUSHJ P,.CNVDT
;RETURNS WITH RESULT IN T3 (.GT.0; OR -1 IF BEYOND SEPT. 27,2217)
DATTOUNI::
.CNVDT: MOVEM T1,TMP ;SAVE TIME FOR LATER
IDIVI T2,12*31 ;T2=YEARS-1964
CAILE T2,2217-1964 ;SEE IF BEYOND 2217
JRST GETNW2 ;YES--RETURN -1
IDIVI T3,31 ;T3=MONTHS-JAN, T4=DAYS-1
ADD T4,.MNTAB(T3) ;T4=DAYS-JAN 1
MOVEM P1,SP1 ;save P1
MOVEI P1,0 ;LEAP YEAR ADDITIVE IF JAN, FEB
CAIL T3,2 ;CHECK MONTH
MOVEI P1,1 ;ADDITIVE IF MAR-DEC
MOVE T1,T2 ;SAVE YEARS FOR REUSE
ADDI T2,3 ;OFFSET SINCE LEAP YEAR DOES NOT GET COUNTED
IDIVI T2,4 ;HANDLE REGULAR LEAP YEARS
CAIE T3,3 ;SEE IF THIS IS LEAP YEAR
MOVEI P1,0 ;NO--WIPE OUT ADDITIVE
ADDI T4,<1964-1859>*365+<1964-1859>/4+<31-18>+31(T2)
;T4=DAYS BEFORE JAN 1,1964 +SINCE JAN 1
; +ALLOWANCE FOR ALL LEAP YEARS SINCE 64
MOVE T2,T1 ;RESTORE YEARS SINCE 1964
IMULI T2,365 ;DAYS SINCE 1964
ADD T4,T2 ;T4=DAYS EXCEPT FOR 100 YR. FUDGE
HRREI T2,64-100-1(T1) ;T2=YEARS SINCE 2001
JUMPLE T2,GETNW1 ;ALL DONE IF NOT YET 2001
IDIVI T2,100 ;GET CENTURIES SINCE 2001
SUB T4,T2 ;ALLOW FOR LOST LEAP YEARS
CAIE T3,99 ;SEE IF THIS IS A LOST L.Y.
GETNW1: ADD T4,P1 ;ALLOW FOR LEAP YEAR THIS YEAR
MOVE P1,SP1 ; Restore P1
CAILE T4,^O377777 ;SEE IF TOO BIG
GETNW2: SETOM T4 ;YES--SET -1
MOVE T1,TMP
MOVEI T2,0 ;CLEAR OTHER HALF
ASHC T1,-17 ;POSITION
DIV T1,[24*60*60*1000] ;CONVERT TO 1/2**18 DAYS
HRL T1,T4 ;INCLUDE DATE
MOVE T3,T1 ;DEC VERSION RETURNS NOW, DATE,,TIME IN T1
;RIPOFF NEEDS IT IN T3..
POPJ P, ;RETURN
;UNDER RADIX 10 **** NOTE WELL ****
.MNTAB: EXP 0,31,59,90,120,151,181,212,243,273,304,334,365
RADIX 8
End