Metropoli BBS
VIEWER: trystd.asm MODE: TEXT (ASCII)
        name    trystd
        title   TRYSTD --- time & date conversion demo
        page    55,132
;
; TRYSTD.ASM -- demonstrate use of time and date
;               conversion routines in SCANTD.ASM
;               and TD.ASM.
;
; Prompts user for date and time, converts input
; to binary and checks it for validity, then
; converts binary date and time back to ASCII
; for display.
;
; To exit from this demo program just press <Enter>
; alone at the prompt.
;
; Ray Duncan * PC Magazine * February 1988
;

cr      equ     0dh             ; ASCII carriage return
lf      equ     0ah             ; ASCII line feed

stdin   equ     0               ; standard input handle
stdout  equ     1               ; standard output handle
stderr  equ     2               ; standard error handle


DGROUP  group   _DATA


_TEXT   segment word public 'CODE'

        assume  cs:_TEXT,ds:_DATA

        extrn   scantime:near   ; convert time to binary
        extrn   scandate:near   ; convert date to binary
        extrn   tcvt:near       ; convert time to ASCII
        extrn   dcvt:near       ; convert date to ASCII

main    proc    near

        mov     ax,_DATA        ; make our data segment
        mov     ds,ax           ; addressable...
        mov     es,ax

main1:                          ; display "Enter date"
        mov     dx,offset DGROUP:msg1
        mov     cx,msg1_len
        call    pmsg

        call    gline           ; get date from user
        cmp     ax,2            ; empty line?
        je      main9           ; yes, exit

                                ; convert the date
        mov     si,offset DGROUP:ibuff
        call    scandate

        jc      main2           ; jump if bad date

                                ; convert date for output
        mov     si,offset DGROUP:msg2a
        mov     bx,8
        call    dcvt

                                ; now display date
        mov     dx,offset DGROUP:msg2
        mov     cx,msg2_len
        call    pmsg
        jmp     main3           ; now do time

main2:                          ; display "Bad date!"
        mov     dx,offset DGROUP:msg5
        mov     cx,msg5_len
        call    pmsg

main3:                          ; display "Enter time"
        mov     dx,offset DGROUP:msg3
        mov     cx,msg3_len
        call    pmsg

        call    gline           ; get time from user
        cmp     ax,2            ; empty line?
        je      main9           ; yes, exit

                                ; convert the time
        mov     si,offset DGROUP:ibuff
        call    scantime

        jc      main4           ; jump if bad time

                                ; convert time for output
        mov     si,offset DGROUP:msg4a
        mov     bx,8
        call    tcvt

                                ; now display time
        mov     dx,offset DGROUP:msg4
        mov     cx,msg4_len
        call    pmsg
        jmp     main1           ; go do date again

main4:                          ; display "Bad time!"
        mov     dx,offset DGROUP:msg6
        mov     cx,msg6_len
        call    pmsg
        jmp     main1           ; go do date again

main9:  mov     ax,4c00h        ; final exit to MS-DOS
        int     21h             ; with return code=0

main    endp


pmsg    proc    near            ; display a message
                                ; call with
                                ; DS:DX = message
                                ; CX = length

        mov     bx,stdout       ; standard output handle
        mov     ah,40h          ; function 40H = write
        int     21h             ; transfer to MS-DOS
        ret                     ; back to caller

pmsg    endp


gline   proc    near            ; get line from user

                                ; set DS:DX = buffer
        mov     dx,offset DGROUP:ibuff
        mov     cx,80           ; CX = maximum length
        mov     bx,stdin        ; standard input handle
        mov     ah,3fh          ; function 3FH = read
        int     21h             ; transfer to MS-DOS
        ret                     ; back to caller

gline   endp

_TEXT   ends


_DATA   segment word public 'DATA'

msg1    db      cr,lf,lf
        db      "Enter a date:   "
msg1_len equ $-msg1

msg2    db      cr,lf
        db      "You entered:    "
msg2a   db      "XX/XX/XX"
msg2_len equ $-msg2

msg3    db      cr,lf,lf
        db      "Enter a time:   "
msg3_len equ $-msg3

msg4    db      cr,lf
        db      "You entered:    "
msg4a   db      "XX:XX:XX"
msg4_len equ $-msg4

msg5    db      cr,lf
        db      "Bad date!"
msg5_len equ $-msg5

msg6    db      cr,lf
        db      "Bad time!"
msg6_len equ $-msg6

ibuff   db      80 dup (?)              ; input buffer

_DATA   ends


STACK   segment para stack 'STACK'

        db      128 dup (?)

STACK   ends

        end     main
[ RETURN TO DIRECTORY ]