home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS 1992 September / Simtel20_Sept92.cdr / msdos / sysutl / autodate.arc / AUTODAT1.ASM next >
Assembly Source File  |  1985-09-17  |  15KB  |  445 lines

  1.          page    63,132
  2.          title   AUTODATE --- Display and reset Date and Time
  3. ;=====================================================================
  4. ; Name:     AUTODATE, automatic date routine.
  5. ; Function: Set the date and time from user or file input.
  6. ; Input:    1) after re-boot, the date and time are read
  7. ;              from "AUTODATE.DAT",
  8. ;           2) otherwise, DOS functions return current date and time.
  9. ; Output:   1) the date and time are set via DOS function calls,
  10. ;           2) the date and time are saved in file "AUTODATE.DAT".
  11. ; Notes:
  12. ;           Written for the IBM PC by Vernon Buerg, October 1983,
  13. ;           and is supplied for public domain use.
  14. ;
  15. ; Rev   11-01-84
  16. ;                Revised console routine to remove ansi mode dependency.
  17. ;               Changed to buffered input to permit editing. (pete mack).
  18. ;=====================================================================
  19. ;
  20. ;
  21. cseg     segment PARA public 'CODE'
  22.          assume  cs:cseg,ds:cseg,es:cseg
  23.          org     100h
  24. autodate PROC    FAR
  25.          push    ds                      ;save for linkage
  26.          xor     ax,ax                   ;clear for return
  27.          push    ax                      ;put in stack
  28. ;
  29.          mov     dx,offset filename      ;file to open
  30.          call    open                    ;open for input/output
  31. ;
  32.          call    getdate
  33. ;
  34. ; If the current date is 01-01-1980, power was turned off
  35. ;
  36.          mov     si,offset ipldate       ;date if new boot
  37.          mov     di,offset month         ;the current date
  38.          cmps    ds:byte ptr[si],es:[di]
  39.          jne     print1                  ;no, display date/time
  40. ;
  41.          mov     cx,12                   ;length for date record
  42.          lea     bx,month                ;buffer address
  43.          call    read                    ;get a record
  44. ;
  45.          mov     cx,10                   ;length for time record
  46.          lea     bx,hour                 ;buffer address
  47.          call    read                    ;get a record
  48. ;
  49.          jmp     print2                  ;now prompt
  50. ;
  51. print1:
  52.          call    gettime                 ;current time if not read
  53. print2:
  54.          mov     dx,offset pr_date       ;prompt for DATE
  55.          lea     bx,month                ;where to reply
  56.          call    console                 ;read the DATE
  57. ;
  58.          call    setdate                 ;set the date
  59. ;
  60.          mov     dx,offset pr_time       ;prompt for TIME
  61.          lea     bx,hour                 ;overlay with reply
  62.          call    console                 ;read the TIME
  63. ;
  64.          call    settime                 ;set the time
  65.          page
  66. ;============================;
  67. ; Re-write Date/Time Records ;
  68. ;============================;
  69.          mov     byte ptr end_date,13    ;for end of record
  70.          mov     byte ptr end_date[1],10
  71.          mov     byte ptr end_time,13    ;for end of record
  72.          mov     byte ptr end_time[1],10
  73. ;
  74.          mov     cx,0                    ;new file offset of zero
  75.          mov     dx,cx
  76.          mov     al,0                    ;to use CX:DX offset
  77.          mov     bx,handle               ;supply file handle
  78.          mov     ah,42h                  ;to move file pointer
  79.          int     21h
  80.          mov     cx,12                   ;length of date record
  81.          lea     bx,month                ;addr of data
  82.          call    write                   ;re-write date record
  83. ;
  84.          mov     cx,10                   ;length of time record
  85.          lea     bx,hour                 ;addr of time
  86.          call    write                   ;re-write time data
  87. ;
  88.          mov     bx,handle               ;file handle
  89.          call    close                   ;all done
  90.          RET
  91.          page
  92.          subttl  Get current date
  93. ;===================;
  94. ; GET CURRENT DATE  ;
  95. ;===================;
  96. getdate  proc    near
  97.          push    ax
  98.          push    cx
  99.          push    dx
  100.          mov     ah,2Ah ;DOS DATE function
  101.          int     21h    ;issue request
  102. ;
  103.          mov     ax,cx ;get year(19xx)
  104.          sub     ax,1900
  105.          aam
  106.          xchg    al,ah
  107.          or      year,ax
  108.          mov     al,dh ;get month
  109.          aam
  110.          xchg    al,ah
  111.          or      month,ax
  112.          mov     al,dl ;get day
  113.          aam
  114.          xchg    al,ah
  115.          or      day,ax
  116.          pop     dx
  117.          pop     cx
  118.          pop     ax
  119.          ret
  120. getdate  endp
  121.          page
  122.          subttl  Display current time
  123. ;==================;
  124. ; GET CURRENT TIME ;
  125. ;==================;
  126. gettime  proc    near
  127.          push    ax
  128.          push    cx
  129.          push    dx
  130.          mov     ah,2ch ;DOS time function
  131.          int     21h    ;issue request
  132. ;
  133.          mov     al,ch ;get hours
  134.          aam
  135.          xchg    al,ah
  136.          or      hour,ax
  137.          mov     al,cl ;get minutes
  138.          aam
  139.          xchg    al,ah
  140.          or      minute,ax
  141.          mov     al,dh ;get seconds
  142.          aam
  143.          xchg    al,ah
  144.          or      second,ax
  145. ;
  146.          pop     dx
  147.          pop     CX
  148.          pop     ax
  149.          ret
  150. gettime  endp
  151.          page
  152.          subttl  SETTIME - set time from user input
  153. ;===========================;
  154. ;        SETTIME            ;
  155. ;===========================;
  156. settime  proc    near
  157.          push    ax
  158.          push    bx
  159.          push    cx
  160.          push    dx
  161. ;
  162. settimer:
  163.          sub     cx,cx                   ;clear AF flag
  164.          mov     ax,word ptr hour        ;get ASCII hours
  165.          aaa                             ;adjust AL to ASCII
  166.          xchg    al,ah                   ;switch to other byte
  167.          aaa                             ;adjust other byte
  168.          aad                             ;convert to binary
  169.          add     ch,al                   ;copy hours
  170.          mov     ax,word ptr minute      ;get ASCII minutes
  171.          aaa                             ;adjust AL to ASCII
  172.          xchg    al,ah                   ;switch to other byte
  173.          aaa                             ;adjust other byte
  174.          aad                             ;convert to binary
  175.          add     cl,al                   ;copy minutes
  176.          mov     ax,word ptr second      ;get ASCII seconds
  177.          aaa                             ;adjust AL to ASCII
  178.          xchg    al,ah                   ;switch to other byte
  179.          aaa                             ;adjust other byte
  180.          aad                             ;convert to binary
  181.          sub     dx,dx                   ;no hundreths
  182.          mov     dh,al
  183. ;
  184.          mov     ah,2dh                  ;set time
  185.          int     21h
  186. ;
  187.          cmp     al,0                    ;set okay?
  188.          je      timeset                 ;yes, all done
  189. ;
  190. timebad:
  191.          mov     ah,9                    ;no, print message
  192.          mov     dx,offset timemsg
  193.          int     21h
  194.          mov     dx,offset pr_time       ;prompt for TIME
  195.          lea     bx,hour                 ;overlay with reply
  196.          call    console                 ;read the TIME
  197.          jmp     settimer                ;try again
  198. ;
  199. timeset:
  200.          pop     dx
  201.          pop     cx
  202.          pop     bx
  203.          pop     ax
  204.          ret
  205. settime  endp
  206.          page
  207.          subttl  SETDATE - set DATE from user input
  208. ;==========================;
  209. ;        SETDATE           ;
  210. ;==========================;
  211. setdate  proc    near
  212.          push    ax
  213.          push    bx
  214.          push    cx
  215.          push    dx
  216. ;
  217. setdates:
  218.          cmp     byte ptr month[2],'-'  ;proper delimiter?
  219.          jne     datebad                ;no, prompt again
  220.          cmp     byte ptr day[2],'-'
  221.          jne     datebad
  222. ;
  223.          sub     dx,dx                  ;clears AF for AAA
  224.          mov     ax,word ptr month      ;get ASCII month
  225.          aaa                            ;adjust AL to ASCII
  226.          xchg    al,ah                  ;switch to other byte
  227.          aaa                            ;adjust other byte
  228.          aad                            ;convert to binary
  229.          add     dh,al                  ;put month in dh,clear AF
  230.          mov     ax,word ptr day        ;get ASCII day
  231.          aaa
  232.          xchg    al,ah
  233.          aaa
  234.          aad
  235.          add     dl,al                  ;put day in DL,clear AF
  236.          mov     ax,word ptr year       ;get ASCII year
  237.          aaa
  238.          xchg    al,ah
  239.          aaa
  240.          aad
  241.          mov     cl,al                  ;put year in CL
  242.          add     cx,1900                ;still this century
  243. ;
  244.          mov     ah,2bh                 ;set date function
  245.          int     21h
  246. ;
  247.          cmp     al,0                   ;set okay?
  248.          je      dateset                ;yes, all done
  249. datebad:
  250.          mov     ah,9                   ;no, print message
  251.          mov     dx,offset datemsg
  252.          int     21h
  253. ;
  254.          mov     dx,offset pr_date       ;prompt for DATE
  255.          lea     bx,month                ;where to reply
  256.          call    console                 ;read the DATE
  257. ;
  258.          jmp     setdates                ;and try it again
  259. ;
  260. dateset:
  261.          pop     dx
  262.          pop     cx
  263.          pop     bx
  264.          pop     ax
  265.          ret
  266. setdate  endp
  267.          page
  268.          subttl  CONSOLE - Read console input
  269. ;=====================================;
  270. ;        CONSOLE                      ;
  271. ; INPUT:  DX, offset to prompt        ;
  272. ;         BX, LEA of reply            ;
  273. ; OUTPUT: field at BX has text        ;
  274. ; NOTES:  no editing performed        ;
  275. ;=====================================;
  276. console  proc    near
  277.          push    ax
  278.          push    cx
  279.          push    dx
  280. ;
  281.          mov     ah,9            ;print function
  282.          int     21h             ;prompt for response
  283. cons1:
  284.         lea        dx,ibuf       ;point input buffer
  285.         mov        ah,0ah        ;console string input call
  286.         int        21h
  287.         lea        si,ibuf1      ;point to first character.
  288. cons1a:
  289.         mov        al,[si]       ;get a character
  290.         inc        si
  291. cons2:
  292.          cmp     al,13      ;is it ENTER?
  293.          je      consend    ;yes, all over
  294.          mov     [bx],al    ;copy inputted character
  295.          inc     bx         ;increment target offset
  296.          jmp     cons1a      ;and get next character
  297. ;
  298. consend:
  299.         pop        dx
  300.          pop     cx
  301.          pop     ax
  302.          ret
  303. console  endp
  304.          page
  305.          subttl  OPEN - Open file given filename
  306. ;===================================;
  307. ;        OPEN                       ;
  308. ; input:  DX has offset to filename ;
  309. ; output: BX has handle             ;
  310. ;         field HANDLE has handle   ;
  311. ;===================================;
  312. open     proc    near
  313.          push    ax
  314.          push    cx
  315. ;
  316.          mov     ax,2            ;for read/write
  317.          mov     ah,3dh          ;open a file
  318.          int     21h
  319.          mov     handle,ax       ;save file handle
  320. ;
  321.          jnc     openend
  322.          aam
  323.          xchg    al,ah
  324.          or      opencode,ax
  325.          mov     dx,offset openmsg
  326.          mov     ah,9
  327.          int     21h
  328. ;
  329. openend:
  330.          pop     cx
  331.          pop     ax
  332.          ret
  333. open     endp
  334.          page
  335.          subttl  CLOSE - Close file given handle from open
  336. ;=======================;
  337. ;        CLOSE          ;
  338. ; input:  BX has handle ;
  339. ;=======================;
  340. close    proc    near
  341.          push    ax
  342.          mov     ah,3eh          ;close a file handle
  343.          int     21h
  344.          pop     ax
  345.          ret
  346. close    endp
  347.          page
  348.          subttl  READ - Read disk record
  349. ;================================;
  350. ;        READ                    ;
  351. ; input:  CX has length          ;
  352. ;         BX has addr rec        ;
  353. ;         HANDLE has file handle ;
  354. ;================================;
  355. read     proc    near
  356.          push    ax
  357.          push    dx
  358.          mov     recaddr,bx      ;save record address
  359.          mov     numbytes,cx     ;length to clear
  360. readclr: mov     bx,0            ;clear to zero
  361.          inc     bx              ;increment to next byte
  362.          loop    readclr         ;for entire record
  363. ;
  364.          mov     bx,handle       ;get file handle from open
  365.          mov     dx,recaddr      ;offset to record buffer
  366.          mov     cx,numbytes     ;number of bytes to read
  367. ;
  368.          mov     ah,3fh          ;read from a file
  369.          int     21h
  370. ;
  371. readend:
  372.          pop     dx
  373.          pop     ax
  374.          ret
  375. read     endp
  376.          page
  377.          subttl  WRITE - Read disk record
  378. ;================================;
  379. ;        WRITE                   ;
  380. ; input:  CX has length          ;
  381. ;         BX has addr rec        ;
  382. ;         HANDLE has file handle ;
  383. ;================================;
  384. write    proc    near
  385.          push    ax
  386.          push    dx
  387.          mov     dx,bx           ;set record address
  388.          mov     bx,handle       ;set file handle
  389. ;
  390.          mov     ah,40h          ;write to file
  391.          int     21h
  392. ;
  393. writend:
  394.          pop     dx
  395.          pop     ax
  396.          ret
  397. write    endp
  398.          page
  399.          subttl  Constants and work areas
  400. pr_date  db      0dh,0ah
  401.          db      'Current date is: '
  402. month    dw      '00'
  403.          db      '-'
  404. day      dw      '00'
  405.          db      '-19'
  406. year     dw      '00'
  407. end_date dw      2020h
  408.          db      '   Enter new date: '
  409.          db      '$'
  410. pr_time  db      0dh,0ah
  411.          db      'Current time is: '
  412. hour     dw      '00'
  413.          db      ':'
  414. minute   dw      '00'
  415.          db      ':'
  416. second   dw      '00'
  417. end_time dw      0
  418.          db      '     Enter new time: '
  419.          db      '$'
  420. ;
  421. ibuf     db      15
  422.          db      0
  423. ibuf1    db      15 dup (0)
  424. ;
  425. ipldate  db      '01-01-1980'
  426. datemsg  db      0dh,0ah,'Date invalid',7,'$'
  427. timemsg  db      0dh,0ah,'Time invalid',7,'$'
  428. ten      db      10
  429. ;
  430. filename db      'a:autodate.dat',0  ;drive:filename.ext
  431. handle   dw      0                   ;file handle from open
  432. ;
  433. openmsg  db      'Open code: '
  434. opencode dw      '00'
  435.          db      '  $'
  436. numbytes dw      0                   ;bytes to read
  437. bytes    dw      0                   ;bytes read
  438. recaddr  dw      0                   ;addr of i/o area
  439. rec      db      80 dup(0)           ;file record area
  440. ;
  441. autodate ENDP
  442. cseg     ends
  443.          end     autodate
  444.