home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / PPOS2.ZIP / TRYTD.ASM < prev    next >
Assembly Source File  |  1988-10-07  |  5KB  |  162 lines

  1.         title   TRYTD --- time & date demo
  2.         page    55,132
  3.     .286
  4.  
  5. ; TRYTD.ASM -- Demonstrate use of time and date routines
  6. ;              OS/2 version
  7. ;
  8. ; by Ray Duncan, Copyright (C) 1988 Ziff Davis
  9.  
  10. cr      equ     0dh             ; ASCII carriage return
  11. lf      equ     0ah             ; ASCII line feed
  12.  
  13. stdin   equ     0               ; standard input handle
  14. stdout  equ     1               ; standard output handle
  15.  
  16.         extrn    DosClose:far    ; OS/2 API functions
  17.         extrn    DosExit:far 
  18.     extrn    DosOpen:far
  19.     extrn    DosQFileInfo:far
  20.     extrn    DosWrite:far
  21.  
  22. DGROUP  group   _DATA
  23.  
  24. _DATA   segment word public 'DATA'
  25.  
  26. finfo    label    byte        ; receives file info
  27. cdate    dw    ?        ; date of creation
  28. ctime    dw    ?            ; time of creation
  29. adate    dw    ?            ; date of last access
  30. atime    dw    ?            ; time of last access
  31. wdate    dw    ?           ; date of last write
  32. wtime    dw    ?            ; time of last write
  33. fsize    dd    ?            ; file size
  34. falloc    dd    ?            ; file allocation
  35. fattr    dw    ?            ; file attribute
  36. fi_len    equ    $-finfo        ; length of info buffer
  37.  
  38. msg1    db      cr,lf                           
  39.         db      'The current time and date are: '
  40. msg1a   db      12 dup (' ')    ; time formatted here
  41. msg1b   db      8 dup  (' ')    ; date formatted here
  42.         db      cr,lf,lf
  43.         db      'The TRYTD.EXE file time and date are: '
  44. msg1c   db      12 dup (' ')    ; time formatted here
  45. msg1d   db      8 dup  (' ')    ; date formatted here
  46.         db      cr,lf
  47. msg1_len equ $-msg1
  48.  
  49. msg2    db      cr,lf
  50.         db      'Can''t open TRYTD.EXE'
  51.         db      cr,lf
  52. msg2_len equ $-msg2
  53.  
  54. fname   db      'TRYTD.EXE',0   ; name of this file
  55. fhandle dw      0               ; handle for this file
  56. faction    dw    0        ; receives DosOpen action
  57.  
  58. wlen    dw    ?        ; receives actual number
  59.                 ; of bytes written
  60.  
  61. _DATA   ends
  62.  
  63.  
  64. _TEXT   segment word public 'CODE'
  65.  
  66.         assume  cs:_TEXT,ds:DGROUP
  67.  
  68.         extrn   systcvt:near    ; format system time
  69.         extrn   sysdcvt:near    ; format system date
  70.         extrn   dirtcvt:near    ; format directory time
  71.         extrn   dirdcvt:near    ; format directory date
  72.  
  73. main    proc    near
  74.                                 
  75.                                 ; format system time...
  76.         mov     si,offset msg1a ; buffer address
  77.         mov     bx,11           ; buffer length (max 11)
  78.         call    systcvt
  79.  
  80.                                 ; format system date
  81.         mov     si,offset msg1b ; buffer address
  82.         mov     bx,8            ; buffer length (max 8)
  83.         call    sysdcvt
  84.  
  85.                 ; open TRYTD.EXE file...
  86.         push    ds        ; address of filename
  87.         push    offset DGROUP:fname
  88.         push    ds        ; receives file handle
  89.         push    offset DGROUP:fhandle
  90.         push    ds        ; receives DosOpen action
  91.         push    offset DGROUP:faction
  92.         push    0        ; initial allocation (N/A)
  93.         push    0
  94.         push    0        ; file attribute (N/A)
  95.         push    1        ; open if exists, do
  96.                     ; not create file
  97.         push    40h        ; deny none, read-only
  98.         push    0        ; DWORD reserved
  99.         push    0
  100.         call    DosOpen        ; transfer to OS/2
  101.     or    ax,ax        ; did open succeed?
  102.         jnz    main1        ; jump if open failed
  103.  
  104.                 ; get file date/time...
  105.     push    fhandle        ; file handle
  106.         push    1        ; info level (always 1)
  107.         push    ds            ; receives file info
  108.         push    offset DGROUP:finfo
  109.     push    fi_len        ; length of buffer
  110.         call    DosQFileInfo    ; transfer to OS/2
  111.  
  112.         mov    ax,wtime    ; format file time
  113.         mov     bx,11           ; buffer length
  114.         mov     si,offset msg1c ; buffer address
  115.         call    dirtcvt
  116.  
  117.     mov    ax,wdate    ; format file date
  118.         mov     bx,8            ; buffer length
  119.         mov     si,offset msg1d ; buffer address
  120.         call    dirdcvt
  121.  
  122.                 ; now close file...
  123.     push    fhandle        ; file handle
  124.     call    DosClose    ; transfer to OS/2
  125.  
  126.                                 ; display formatted
  127.                                 ; date and time...
  128.     push    stdout        ; standard output handle
  129.         push    ds        ; address of message
  130.         push    offset DGROUP:msg1
  131.         push    msg1_len    ; length of message
  132.         push    ds            ; receives write count
  133.         push    offset DGROUP:wlen
  134.     call    DosWrite    ; transfer to OS/2
  135.  
  136.                 ; final exit to OS/2
  137.         push    1        ; terminate all threads
  138.         push    0        ; return code = 0 (success)
  139.         call    DosExit        ; transfer to OS/2
  140.  
  141. main1:              ; open failed, display
  142.                 ; "Can't open TRYTD.EXE"
  143.     push    stdout        ; standard output handle
  144.         push    ds        ; address of message
  145.         push    offset DGROUP:msg2
  146.         push    msg2_len    ; length of message
  147.         push    ds            ; receives write count
  148.         push    offset DGROUP:wlen
  149.     call    DosWrite    ; transfer to OS/2
  150.  
  151.                 ; final exit to OS/2
  152.         push    1        ; terminate all threads
  153.         push    1        ; return code = 1 (error)
  154.         call    DosExit            ; transfer to OS/2
  155.                     
  156. main    endp
  157.  
  158. _TEXT   ends
  159.  
  160.         end     main        ; defines entry point
  161.  
  162.