        page    80,132                  ;0
        title   TIME - time and date functions

;
; System Calls and low level routines for DATE and TIME
;
;   $GET_DATE
;   $SET_DATE
;   $GET_TIME
;   $SET_TIME
;   DATE16
;   READTIME
;   DSLIDE
;   SETYEAR
;   DODATE
;   DSUM
;
;   Modification history:
;
;       Created: ARR 30 March 1983
;       Modified for MVDM by danno 16-Feb-1989
;

.xlist
include v86seg.inc              ; get the appropriate segment definitions
.xcref
include basemaca.inc
include osmaca.inc
include demmac.inc
include dossymc.inc
include mvdmexp.inc
include demsvc.inc
include struc30.inc                                                     ;56427;
.cref
.list


        CpuMode 386

V86TABLE SEGMENT
        EXTRN   DosDseg: word
V86TABLE ENDS

V86CODE SEGMENT
        ASSUME  CS:V86GROUP,DS:NOTHING,ES:NOTHING,SS:NOTHING

        EXTRN   Get_User_Stack:NEAR


;-----------------------------------------------------------------------
subttl DATE AND TIME - SYSTEM CALLS 42,43,44,45
page
; Inputs:
;       None
; Function:
;       Return current date
; Returns:
;       Date in CX:DX

public  $GET_DATE
$GET_DATE proc near
        ASSUME  ds:NOTHING,es:NOTHING

        ;entry: none
        SVC     SVC_DEMQUERYDATE        ; Get the date
        ;exit:  DH=month 1..12
        ;       DL=day 1..31
        ;       CX=year 1980..2099
        ;       AL=weekday 0..6

        call    get_user_stack          ;Get pointer to user registers
        mov     [si].user_DX,dx         ;DH=month, DL=day
        mov     [si].user_CX,cx         ;CX=year
        ret
$GET_DATE endp
;-----------------------------------------------------------------------




;-----------------------------------------------------------------------
public $SET_DATE
$SET_DATE proc NEAR
        ASSUME  DS:NOTHING,ES:NOTHING

; Inputs:
;       CX:DX valid date
; Function:
;       Set current date
; Returns:
;       AL = -1 date bad, = 0 OK\

        SVC     SVC_DEMSETDATE

        ret
$SET_DATE endp
;-----------------------------------------------------------------------




;-----------------------------------------------------------------------
public $GET_TIME
$GET_TIME proc NEAR
        ASSUME  DS:NOTHING,ES:NOTHING

; Inputs:
;       None
; Function:
;       Get current time
; Returns:
;       Time in CX:DX

        SVC     SVC_DEMQUERYTIME
        call    get_user_stack          ;Get pointer to user registers
        mov     [SI.user_DX],DX
        mov     [SI.user_CX],CX
        xor     AL,AL
        ret
$GET_TIME endp
;-----------------------------------------------------------------------



;-----------------------------------------------------------------------
public $SET_TIME
$SET_TIME proc NEAR
        ASSUME  CS:V86GROUP,DS:NOTHING,ES:NOTHING,SS:NOTHING

; Inputs:
;       CX:DX = Time
; Function:
;       Set time
; Returns:
;       AL = -1 time bad, = 0 OK

        SVC     SVC_DEMSETTIME
        ret
$SET_TIME endp
;-----------------------------------------------------------------------


subttl Int 2Fh, ax=120Dh, Get packed date and time
page
;-----------------------------------------------------------------------
;Int 2Fh 120Dh - Get packed date and time
;entry: SS=V86GROUP (DOS data) <--this is no longer true
;exit:  AX=packed date
;       DX=packed time
;       DS=V86GROUP (DOS data)
;       CX,ES=unchanged
;       BX,SI,DI,BP=?
;
public  DATE16
DATE16  proc    near
        assume  cs:V86GROUP,ds:NOTHING,es:NOTHING,ss:NOTHING

;------ establish DS Addressability, we don't need it, but do for compatibility
        mov     ds,cs:[DosDseg]
        assume  ds:V86GROUP

;------ save registers
        push    cx

;------ get the date and pack it
        SVC     SVC_DEMQUERYDATE        ; Get the date
        ;exit:  DH=month 1..12
        ;       DL=day 1..31
        ;       CX=year 1980..2099
        ;       AL=weekday 0..6
        ;AX packed date form:
        ;       YYYY YYYm mmmD DDDD

        sub     CX,1980                 ;year is 1980..(+127)
        shl     CL,1                    ;packed year in CL
        shl     DL,3                    ;month and day are now adjacent
        shr     DX,3                    ;move mon|day to low end
        or      DH,CL                   ;DX now has packed date

        push    dx                      ;save packed date

;------ get the time and pack it
        SVC     SVC_DEMQUERYTIME
        ;exit:  CH=hour      (0..23)
        ;       CL=Minute    (0..59)
        ;       DH=Second    (0..59)
        ;       DL=Hundredth (0..99)
        ;       AX=0
        ;DX packed time form:
        ;       HHHH Hmmm mmmS SSSS

        shl     CL,2                    ;move minutes next to hours
        shl     CX,3                    ;move hr|min to high end of CX
        shr     DH,1                    ;throw away low bit
        or      CL,DH                   ;packed it all into CX
        mov     DX,CX

        pop     ax                      ;restore packed date

;------ restore registers
        pop     cx

        ret
DATE16  endp
;-----------------------------------------------------------------------


V86CODE ENDS
        END
