home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS 1992 September / Simtel20_Sept92.cdr / msdos / sysutl / autodate.arc / AUTODATE.ASM < prev    next >
Assembly Source File  |  1984-04-28  |  8KB  |  417 lines

  1. Title    AUTODATE --- Display and reset Date and    Time
  2.     Page    63,132
  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. ;    Revised 01-01-84 to fix some bugs.
  15. ;=====================================================================
  16. ;
  17. Cseg    Segment    Para Public 'CODE'
  18.     Assume    CS:Cseg,DS:Cseg,ES:Cseg
  19.     Org    100h
  20. Autodate    Proc    Far
  21.     Push    DS            ;save for linkage
  22.     Xor    AX,AX            ;clear for return
  23.     Push    AX            ;put in    stack
  24.  
  25.     Push    DS            ;Modify    diskette parameters
  26.     Mov    DS,AX            ;Offset    into disk table
  27.     Lds    DI,Dword Ptr DS:78h    ;Addr of disk table
  28.     Mov    Byte Ptr [DI],239    ;Modify    step rate
  29.     Mov    Byte Ptr [DI+2],80    ;And motor stop    delay
  30.     Int    13h            ;Reset diskette    system
  31.     Pop    DS
  32.  
  33.     Call    Open            ;open for input/output
  34.  
  35.     Call    Getdate            ;get current date
  36.  
  37. ; If the current date is 01-01-1980, power was turned off
  38.  
  39.     Mov    SI,Offset Ipldate    ;date if new boot
  40.     Mov    CX,10            ; its length
  41.     Mov    DI,Offset Month        ;the current date
  42.     Rep    Cmpsb
  43.     Jne    Print1            ;no, display date/time
  44.  
  45.     Call    Read            ;Read DAT file
  46.  
  47.     Jmp    Print2            ;now prompt
  48.  
  49. Print1:    Call    Gettime            ;current time if not read
  50.  
  51. Print2:    Mov    DX,Offset Pr_date    ;prompt    for date
  52.     Lea    BX,Month        ;where to reply
  53.     Call    Console            ;Read the DATE
  54.  
  55.     Call    Setdate            ;Set the date
  56.  
  57.     Mov    DX,Offset Pr_time    ;prompt    for TIME
  58.     Lea    BX,Hour            ;overlay with reply
  59.     Call    Console            ;Read the TIME
  60.  
  61.     Call    Settime            ;Set the time
  62.     Page
  63.  
  64. ;     Re-write Date/Time Records
  65.  
  66.     Mov    AX,0D0Ah        ;End-of-record
  67.     Mov    Word Ptr End_date,AX
  68.     Mov    Word Ptr End_time,AX
  69.  
  70.     Sub    CX,CX            ;new file offset of zero
  71.     Sub    DX,DX
  72.     Mov    AL,0            ;to use    CX:DX offset
  73.     Mov    BX,Handle        ;supply    file handle
  74.     Mov    AH,42h            ;To move file pointer
  75.     Int    21h
  76.  
  77.     Call    Write            ;Re-write DATE and TIME
  78.  
  79.     Mov    AH,3Eh            ;CLOSE the file
  80.     Mov    BX,Handle
  81.     Int    21h
  82.     Ret
  83.     Page
  84.  
  85. ;     GET CURRENT DATE
  86. ;
  87. Getdate    Proc    Near
  88.     Push    AX
  89.     Push    CX
  90.     Push    DX
  91.     Mov    AH,2Ah            ;DOS DATE function
  92.     Int    21h
  93.  
  94.     Mov    AX,CX            ;Get Year(19xx)
  95.     Sub    AX,1900
  96.     Aam
  97.     Xchg    AL,AH
  98.     Or    Year,AX
  99.     Mov    AL,DH            ;get month
  100.     Aam
  101.     Xchg    AL,AH
  102.     Or    Month,AX
  103.     Mov    AL,DL            ;get day
  104.     Aam
  105.     Xchg    AL,AH
  106.     Or    Day,AX
  107.     Pop    DX
  108.     Pop    CX
  109.     Pop    AX
  110.     Ret
  111. Getdate    Endp
  112.     Page
  113.  
  114. ;     GET CURRENT TIME
  115.  
  116. Gettime    Proc    Near
  117.     Push    AX
  118.     Push    CX
  119.     Push    DX
  120.     Mov    AH,2Ch            ;DOS time function
  121.     Int    21h
  122.  
  123.     Mov    AL,CH            ;get hours
  124.     Aam
  125.     Xchg    AL,AH
  126.     Or    Hour,AX
  127.     Mov    AL,CL            ;get minutes
  128.     Aam
  129.     Xchg    AL,AH
  130.     Or    Minute,AX
  131.     Mov    AL,DH            ;get seconds
  132.     Aam
  133.     Xchg    AL,AH
  134.     Or    Second,AX
  135.  
  136.     Pop    DX
  137.     Pop    CX
  138.     Pop    AX
  139.     Ret
  140. Gettime    Endp
  141.     Page
  142.  
  143. ;     SETTIME
  144.  
  145. Settime    Proc    Near
  146.     Push    AX
  147.     Push    BX
  148.     Push    CX
  149.     Push    DX
  150.  
  151. Settimer:
  152.     Sub    CX,CX            ;Clear AF flag
  153.     Mov    AX,Word    Ptr Hour    ;get ASCII hours
  154.     Aaa                ;adjust    AL to ASCII
  155.     Xchg    AL,AH            ;switch    to other byte
  156.     Aaa                ;adjust    other byte
  157.     Aad                ;Convert to binary
  158.     Add    CH,AL            ;copy hours
  159.     Mov    AX,Word    Ptr Minute    ;get ASCII minutes
  160.     Aaa
  161.     Xchg    AL,AH
  162.     Aaa
  163.     Aad
  164.     Add    Cl,AL            ;copy minutes
  165.     Mov    AX,Word    Ptr Second    ;get ASCII seconds
  166.     Aaa
  167.     Xchg    AL,AH
  168.     Aaa
  169.     Aad
  170.     Sub    DX,DX            ;no hundreths
  171.     Mov    DH,AL
  172.  
  173.     Mov    AH,2Dh            ;Set time
  174.     Int    21h
  175.  
  176.     Cmp    AL,0            ;Set okay?
  177.     Je    Timeset            ;yes, all done
  178.  
  179. Timebad:
  180.     Mov    AH,9            ;no, print message
  181.     Mov    DX,Offset Timemsg
  182.     Int    21h
  183.     Mov    DX,Offset Pr_time    ;prompt    for TIME
  184.     Lea    BX,Hour            ;overlay with reply
  185.     Call    Console            ;Read the TIME
  186.     Jmp    Settimer        ;try again
  187.  
  188. Timeset:
  189.     Pop    DX
  190.     Pop    CX
  191.     Pop    BX
  192.     Pop    AX
  193.     Ret
  194. Settime    Endp
  195.     Page
  196.  
  197. ;     SETDATE
  198.  
  199. Setdate    Proc    near
  200.     Push    AX
  201.     Push    BX
  202.     Push    CX
  203.     Push    DX
  204.  
  205. Setdates:
  206.     Cmp    Byte Ptr Month[2],'-'    ;proper    delimiter?
  207.     Jne    datebad            ;no, prompt again
  208.     Cmp    Byte Ptr Day[2],'-'
  209.     Jne    Datebad
  210.  
  211.     Sub    DX,DX            ;Clears    AF for AAA
  212.     Mov    AX,Word    Ptr Month    ;get ASCII month
  213.     Aaa
  214.     Xchg    AL,AH
  215.     Aaa
  216.     Aad
  217.     Add    DH,AL            ;put month in DH,clear AF
  218.     Mov    AX,Word    Ptr Day        ;get ASCII day
  219.     Aaa
  220.     Xchg    AL,AH
  221.     Aaa
  222.     Aad
  223.     Add    Dl,AL            ;put day in DL,clear AF
  224.     Mov    AX,Word    Ptr Year    ;get ASCII year
  225.     Aaa
  226.     Xchg    AL,AH
  227.     Aaa
  228.     Aad
  229.     Mov    CX,1900            ;adjust    date
  230.     Add    CL,AL            ;put year in CL
  231.  
  232.     Mov    AH,2Bh            ;Set date function
  233.     Int    21h
  234.  
  235.     Cmp    AL,0            ;Set okay?
  236.     Je    Dateset            ;yes, all done
  237. datebad:
  238.     Mov    AH,9            ;no, print message
  239.     Mov    DX,Offset Datemsg
  240.     Int    21h
  241.  
  242.     Mov    DX,Offset Pr_date    ;prompt    for DATE
  243.     Lea    BX,Month        ;where to reply
  244.     Call    Console            ;Read the DATE
  245.  
  246.     Jmp    Setdates        ;and try it again
  247.  
  248. Dateset:
  249.     Pop    DX
  250.     Pop    CX
  251.     Pop    BX
  252.     Pop    AX
  253.     Ret
  254. Setdate    Endp
  255.     Page
  256. ;    CONSOLE
  257. ;
  258. ; Input:  DX, offset to    prompt
  259. ;      BX, LEA of reply
  260. ; Output: field    at BX has text
  261. ; Notes:  no editing performed
  262.  
  263. Console    Proc    Near
  264.     Push    AX
  265.     Push    CX
  266.  
  267.     Mov    AH,9
  268.     Int    21h            ;prompt    for response
  269. Cons1:
  270.     Mov    AH,1            ;Read console character
  271.     Int    21h
  272.  
  273.     Cmp    AL,0            ;extended code?
  274.     Jne    Cons2            ;no, have one character
  275.     Mov    AH,1Ch            ;yes, get next code
  276.     Int    21h
  277.     jmp    Cons1            ;ignore    it
  278. Cons2:
  279.     Cmp    AL,8            ;is it BackSpace?
  280.     Jne    Cons3
  281.     Dec    BX            ;yes, decr buffer ptr
  282.     Jmp    Cons1            ;and read next char
  283. Cons3:    Cmp    AL,13            ;is it ENTER?
  284.     Je    Consend            ;yes, all over
  285.     Mov    [BX],AL            ;copy inputted character
  286.     Inc    BX            ;increment target offset
  287.     Jmp    Cons1            ;and get next character
  288.  
  289. Consend:
  290.     Pop    CX
  291.     Pop    AX
  292.     Ret
  293. Console    Endp
  294.     Page
  295. Open    Proc    Near
  296.     Push    AX
  297.     Push    CX
  298.  
  299.     Mov    AL,2            ;for read/write
  300.     Mov    AH,3Dh            ;open a    file
  301.     Mov    DX,Offset Filename    ;file to open
  302.     Int    21h
  303.     Mov    Handle,AX        ;save file handle
  304.  
  305.     Jnc    Openend
  306.     Aam                ;format error code
  307.     Xchg    AL,AH
  308.     Or    Opencode,AX
  309.     Mov    DX,Offset Openmsg
  310.     Mov    AH,9
  311.     Int    21h
  312.  
  313.     Mov    AH,3Ch            ;So make a new one
  314.     Sub    CX,CX
  315.     Mov    DX,Offset FileName
  316.     Int    21h
  317.     Jc    OpenEnd            ;Oops, now what?
  318.     Mov    Handle,AX
  319.     Call    Write
  320. Openend:
  321.     Pop    CX
  322.     Pop    AX
  323.     Ret
  324. Open    Endp
  325.     Page
  326.  
  327.     ;  Read DAT file date and time    ;
  328.  
  329. Read    Proc    Near
  330.     Push    AX
  331.     Push    DX
  332.  
  333.     Mov    CX,12            ;Read date record
  334.     Mov    DX,Offset Month
  335.     Mov    BX,Handle
  336.     Mov    AH,3Fh
  337.     Int    21h
  338.  
  339.     Mov    CX,10            ;Read time record
  340.     Mov    DX,Offset Hour
  341.     Mov    BX,Handle
  342.     Mov    AH,3Fh
  343.     Int    21h
  344.  
  345. Readend:
  346.     Pop    DX
  347.     Pop    AX
  348.     Ret
  349. Read    Endp
  350.  
  351.     ; Write date and time to DAT file ;
  352.  
  353. Write    Proc    Near
  354.     Push    AX
  355.     Push    DX
  356.  
  357.     Mov    DX,Offset Month        ;Re-write date
  358.     Mov    BX,Handle
  359.     Mov    CX,12
  360.     Mov    AH,40h
  361.     Int    21h
  362.  
  363.     Mov    DX,Offset Hour        ;Re-write time
  364.     Mov    BX,Handle
  365.     Mov    CX,10
  366.     Mov    AH,40h
  367.     Int    21h
  368.  
  369.     Pop    DX
  370.     Pop    AX
  371.     Ret
  372. Write    Endp
  373.     Page
  374. ;        Constants and work areas
  375.  
  376. Pr_date    Db    27,'[2J'
  377.     Db    'Current date is: '
  378. Month    Dw    '00'
  379.     Db    '-'
  380. Day    Dw    '00'
  381.     Db    '-19'
  382. Year    Dw    '00'
  383. End_date Dw    2020h
  384.     Db    27,'[2;1H','Enter new date: '
  385.     Db    '$'
  386. Pr_time    Db    27,'[3;1H'
  387.     Db    'Current time is: '
  388. Hour    Dw    '00'
  389.     Db    ':'
  390. Minute    Dw    '00'
  391.     Db    ':'
  392. Second    Dw    '00'
  393. End_time    Dw    0
  394.     Db    27,'[4;1H','Enter new time: '
  395.     Db    '$'
  396.  
  397. Ipldate    Db    '01-01-1980'
  398. Datemsg    Db    27,'[3;1H','Date invalid',7,'$'
  399. Timemsg    Db    27,'[5;1H','Time invalid',7,'$'
  400. Ten    Db    10
  401.  
  402. Filename Db    'a:autodate.dat',0    ;drive:filename.ext
  403. Handle    Dw    0            ;file handle from open
  404.  
  405. Openmsg    Db    'Open failed, RC='
  406. Opencode Dw    '00'
  407.     Db    ' $'
  408. Numbytes Dw    0            ;bytes to read
  409. Bytes    Dw    0            ;bytes read
  410. Recaddr    Dw    0            ;addr of i/o area
  411. Rec    Db    80 dup(0)        ;file record area
  412.  
  413. Autodate    Endp
  414.  
  415. Cseg    Ends
  416.     End    Autodate
  417.