]>
wirehaze git hosting - MS-DOS.git/blob - v2.0/source/TIME.ASM
2 ; Time and date functions for MSDOS
7 CODE SEGMENT BYTE PUBLIC 'CODE'
8 ASSUME
SS:DOSGROUP
,CS:DOSGROUP
17 TITLE TIME
- time
and date functions
31 FOURYEARS
= 3*365 + 366
33 SUBTTL DATE16
, READTIME
, DODATE
-- GUTS OF TIME
AND DATE
36 ; Date16 returns the current date in AX, current time in DX
37 ; AX - YYYYYYYMMMMDDDDD years months days
38 ; DX - HHHHHMMMMMMSSSSS hours minutes seconds/2
41 ASSUME
DS:DOSGROUP
,ES:NOTHING
46 SHL CL,1 ;Minutes to left part of byte
48 SHL CX,1 ;Push hours and minutes to left end
51 SHR DH,1 ;Count every two seconds
52 OR CL,DH ;Combine seconds with hours and minutes
54 MOV AX,WORD PTR [MONTH
] ;Fetch month and year
56 SHL AL,CL ;Push month to left to make room for day
63 procedure READTIME
,NEAR
65 ASSUME
DS:DOSGROUP
,ES:NOTHING
66 ;Gets time in CX:DX. Figures new date if it has changed.
71 MOV BX,OFFSET DOSGROUP
:TIMEBUF
79 invoke DEVIOCALL2
;Get correct date and time
84 MOV AX,WORD PTR [TIMEBUF
]
85 MOV CX,WORD PTR [TIMEBUF
+2]
86 MOV DX,WORD PTR [TIMEBUF
+4]
87 CMP AX,[DAYCNT
] ;See if day count is the same
89 CMP AX,FOURYEARS
*30 ;Number of days in 120 years
90 JAE RET22
;Ignore if too large
96 MOV CX,FOURYEARS
;Number of days in 4 years
97 DIV CX ;Compute number of 4-year units
100 SHL AX,1 ;Multiply by 8 (no. of half-years)
101 MOV CX,AX ;<240 implies AH=0
102 MOV SI,OFFSET DOSGROUP
:YRTAB
;Table of days in each year
103 CALL DSLIDE
;Find out which of four years we're in
104 SHR CX,1 ;Convert half-years to whole years
105 JNC SK
;Extra half-year?
109 MOV CL,1 ;At least at first month in year
110 MOV SI,OFFSET DOSGROUP
:MONTAB
;Table of days in each month
111 CALL DSLIDE
;Find out which month we're in
113 INC DX ;Remainder is day of month (start with one)
115 CALL WKDAY
;Set day of week
122 procedure DSLIDE
,NEAR
125 LODSB ;Get count of days
126 CMP DX,AX ;See if it will fit
127 JB RET23
;If not, done
129 INC CX ;Count one more month/year
133 procedure SETYEAR
,NEAR
134 ;Set year with value in CX. Adjust length of February for this year.
135 MOV BYTE PTR [YEAR
],CL
138 TEST CL,3 ;Check for leap year
140 JNZ SAVFEB
;28 days if no leap year
143 MOV [MONTAB
+1],AL ;Store for February
147 procedure DODATE
,NEAR
148 ASSUME
DS:DOSGROUP
,ES:NOTHING
149 CALL CHKYR
;Set Feb. up for new year
151 MOV BX,OFFSET DOSGROUP
:MONTAB
-1
152 XLAT ;Look up days in month
154 MOV AL,-1 ;Restore error flag, just in case
155 JB RET25
;Error if too many days
157 MOV WORD PTR [DAY
],DX ;Set both day and month
163 MOV CL,BYTE PTR [YEAR
]
165 MOV SI,OFFSET DOSGROUP
:YRTAB
167 SHL CX,1 ;Two entries per year, so double count
168 CALL DSUM
;Add up the days in each year
169 MOV CL,BH ;Month of year
170 MOV SI,OFFSET DOSGROUP
:MONTAB
171 DEC CX ;Account for months starting with one
172 CALL DSUM
;Add up days in each month
173 MOV CL,BL ;Day of month
174 DEC CX ;Account for days starting with one
175 ADD DX,CX ;Add in to day total
176 XCHG AX,DX ;Get day count in AX
181 MOV BX,OFFSET DOSGROUP
:TIMEBUF
191 invoke DEVIOCALL2
;Get correct date and time
196 POP WORD PTR [TIMEBUF
]
200 invoke DEVIOCALL2
;Set the date
210 INC AX ;First day was Tuesday
211 DIV CX ;Compute day of week