Get DOS Date

From CometWiki

Jump to: navigation, search

Get DOS Date

Syntax:

 DOSMS(AX-value,BX-value,CX-value,DX-value) EXCP=statement-label  

Entry:

 AX-value = "@2A00@"
 BX-value = "@0000@"
 CX-value = "@0000@"
 DX-value = "@0000@"

Return:

 The CX register contains the year (1980 to 2099; in hex -- see conversion note below).
                                                                                                                        .
 Byte 2 of the DX register (i.e., the DH byte) contains the month (1 to 12; in hex).
                                                                                                                         .
 Byte 1 of the DX register (i.e., the DL byte) contains the day (1 to 31; in hex).
                                                                                                                         .
 Byte 1 of the AX register (i.e., the AL byte) contains the weekday number (0 = Sunday, 1 = Monday, 2 = Tuesday, etc.; in
 hex).

Discussion:
The DOSMS function call can be used to get the DOS system date. This function requires that the AX-value be set to "@2A00@", and that the other entry values be set to null.
After the function is executed, the DOS date is returned in the registers as described above. Note that the values are returned in hex and must be converted to decimal for meaningful use.

Special note:
The CX register returns the year portion of the DOS system date. In order to get the correct year, you must first reverse the order of the bytes in the CX register, and then convert to decimal. This is demonstrated in the following sample program.

Example:

 ! S SDATE,DSK
 ! O DATE,DSK
 ! L T00,E
 ! R QMONITOR
 !
 !==========  GET DOS DATE =======================================
 !
 LENGTH 2 & LOCAL AX$,BX$,CX$,DX$          ! Define registers
            LOCAL MONTH$,DAYNUM$,WEEKDAY$  ! Define date variables
 LENGTH 4 & LOCAL YEAR$                    ! Define year
 LENGTH 1 & LOCAL AL$,CH$,CL$,DH$,DL$      ! Define sub-registers
 LENGTH 4.0 & LOCAL YEAR                   ! Define numeric year
 LENGTH 2.0 & LOCAL MONTH,DAYNUM,WEEKDAY   ! Define numeric dates
 !
 100 FORMAT (ET)                           ! Screen format
 !
 CLEAR                        ! Initialize all variables
 !
 AX$="@2A00@"                 ! Set AX register for "GET DATE"
 BX$="@0000@"                 ! Set BX register to null
 CX$="@0000@"                 ! Set CX register to null
 DX$="@0000@"                 ! Set DX register to null
 !
 DOSMS(AX$,BX$,CX$,DX$)       ! Perform DOSMS system call
 !
 YEAR$ = CX$                  ! Year (hex) = CX register
 MONTH$= SUB(DX$,2,1)         ! Month (hex) = DH byte of DX
 DAYNUM$= SUB(DX$,1,1)        ! Day (hex) = DL byte of DX register
 WEEKDAY$=SUB(AX$,1,1)        ! Weekday (hex) = AL byte of AX
 !
 CH$ = SUB(CX$,2,1)           ! Get CH byte from CX (year)
 CL$ = SUB(CX$,1,1)           ! Get CL byte from CX (year)
 YEAR$ = CH$ + CL$            ! Recombine CH and CL bytes
 !
 MONTH$   = "@00@" + MONTH$   ! Add leading null byte to MONTH$
 DAYNUM$  = "@00@" + DAYNUM$  ! Add leading null byte to DAYNUM$
 WEEKDAY$ = "@00@" + WEEKDAY$ ! Add leading null byte to WEEKDAY$
 !
 YEAR = HEXDEC(YEAR$)         ! Convert hex YEAR$ to decimal YEAR
 MONTH= HEXDEC(MONTH$)        ! Convert hex MONTH$ to decimal
 DAYNUM = HEXDEC(DAYNUM$)     ! Convert hex DAYNUM$ to decimal
 WEEKDAY= HEXDEC(WEEKDAY$)    ! Convert hex WEEKDAY$ to decimal
 !
 PRINT (0,100)                ! Set typewriter mode
 !
 PRINT (0) "YEAR:      ";YEAR
 PRINT (0) "MONTH:     ";MONTH
 PRINT (0) "DAY        ";DAYNUM
 PRINT (0) "WEEKDAY # :";WEEKDAY
 INPUT (0) ""
 RUN "QMONITOR"
 END
Personal tools