home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / sigm / vol157 / settime.a86 < prev    next >
Encoding:
Text File  |  1985-03-14  |  4.2 KB  |  181 lines

  1. ; DATE 12/07/83  17:20         last revision
  2.  
  3.     TITLE    'Set System Time v1.0'
  4. ; SETTIME.A86
  5. ; H. M. Van Tassell 120 Hill Hollow Road, Watchung, NJ 07060 201-755-5372
  6. ; A program to set the MP/M or CP/M Plus clock and print time on screen
  7. ; Intended to be run at system start-up.
  8.  
  9. ; This program reads the Compupro System Support Clock but can
  10. ; be used with any similar clock. The hard part is the date conversion
  11. ; to Julian.
  12.  
  13. ; This get time routine was first written to be included in the
  14. ; BIOS or XIOS to set system clock and keep time using a one sec tick
  15. ; interrupt from a timer or some other tick generator
  16.  
  17. ; RASM86 SETTIME $SZPZ
  18. ; LINK86 SETTIME
  19.  
  20. ; if you dont have RASM86 you may use ASM86 and GENCMD.
  21.  
  22.  
  23. CR        equ    0Dh
  24. LF        equ    0Ah
  25.  
  26. PORT_BASE    equ    050h
  27. CLKCMD        equ    PORT_BASE + 10
  28. CLKDATA        equ    PORT_BASE + 11
  29.  
  30.     
  31.     CSEG
  32.  
  33.     call gettime        ;read system support clock
  34.     mov dx,offset ascii_str ;print time on the screen
  35.     mov cl,9
  36.     int 224
  37.     mov dx,offset bin_str    ;send time to system storage
  38.     mov cl,104
  39.     int 224
  40.     mov cl,0        ;quit
  41.     mov dl,0
  42.     int 224
  43.  
  44. ;****************************************
  45. ;*                    *
  46. ;*    Routine to get    time        *
  47. ;*                    *
  48. ;****************************************
  49. ;-------
  50. gettime:
  51. ;-------
  52. ;
  53. ; read time from system support clock and put into both
  54. ; a date string in ascii and the sysdata block
  55. ; the datestr can be used to print time on console
  56.     mov    si,0        ;start reading at seconds
  57.     mov    di,17        ; into datestr
  58.     call    rtwo
  59.     mov    tod_sec,ah
  60. ;    cmp    ah,0        ;is sec=0?
  61. ;    jne    get_exit
  62. ;    call    rtwo
  63. ;    mov    tod_min,ah
  64. ;    cmp    ah,0        ;is min=0?
  65. ;    jne    get_exit
  66. ;    call    rtwo
  67. ;    mov    tod_hr,ah
  68. ;    cmp    ah,0        ;if hr=0 it's midnite
  69. ;    jne    get_exit
  70. ;
  71. ; get date into date string and convert calender
  72. ; date to julian date (1/1/78)
  73. ;
  74. set_date:
  75.     mov    si,2        ;ptr to min in digtab
  76.     mov    di,14        ;ptr to min in datestr
  77.     call    rtwo        ;set min & hr for init. call
  78.     mov    tod_min,ah
  79.     call    rtwo
  80.     mov    tod_hr,ah
  81.     dec    di        ;skip over space
  82. ctoj:    call    rtwo        ;convert date to julian
  83.     mov    bh,0        ;get yr as bin in al
  84.     mov    bl,al        ;bx=year-1900
  85.     mov    di,1        ;point to month
  86.     call    rtwo        ;get month into al
  87.     sub    al,3        ;is month in mar-feb of "year"
  88.     jnc    ctoj1
  89.     add    al,12        ;jan or feb become 10,11
  90.     dec    bx        ;...of prior year
  91. ctoj1:    xor    ah,ah        ;bx="year"
  92.     push    ax        ;ax="month",save it
  93.     mov    ax,1461        ;mult "year" by leap year cycle
  94.     mul    bx        ;bx*ax=[dx,ax]
  95.     mov    cx,4        ;divide by 4
  96.     xor    dh,dh
  97.     div    cx        ;[dx,ax]/cx=ax (quotient)
  98.     mov    bx,ax        ;save quotient in bx
  99.     pop    ax        ;restore "month"
  100.     push    bx        ;save ("year"*1461)/4
  101.     mov    bx,153        ;mult "month" by 153
  102.     mul    bx        ;bx*ax=[dx,ax]
  103.     inc    ax
  104.     inc    ax        ;add 2 to low order bits
  105.     mov    cx,5        ;divide by 5
  106.     xor    dh,dh
  107.     div    cx        ;ax=("month"*153+2)/5
  108.     pop    bx        ;bx=("year"*1461)/4
  109.     add    bx,ax        ;add em
  110.     mov    di,4        ;point to days
  111.     call    rtwo        ;get days into al
  112.     mov    ah,0
  113.     add    ax,bx        ;add days
  114.     sub    ax,28429+1    ;convert to 1/1/78
  115.     mov    tod_day,ax    ;stash it away
  116. get_exit: ret
  117.  
  118. ;
  119. ; get 2 bcd clock digits and update string
  120. ; and convert to binary & bcd time digits
  121. ;
  122. rtwo:    call    rone        ;get lo order digit in al
  123.     mov    dl,al        ;save it in reg dl
  124.     add    al,'0'        ;convert to ascii
  125.     mov    datestr[di],al ;and put in buffer
  126.     dec    di        ;backup in string
  127.     call    rone        ;get hi order digit
  128.     mov    dh,al        ;save it in dh
  129.     add    al,'0'
  130.     mov    datestr[di],al
  131.     dec di! dec di        ;backup over sepr
  132.     mov    al,dh        ;recover hi digit
  133.     mov    cl,10        ;mult by 10
  134.     mul    cl        ;al=10*digit
  135.     add    al,dl        ;add lo digit
  136.     mov    cl,4        ;rotate hi order bcd
  137.     rol    dh,cl        ;...into hi nibble
  138.     add    dh,dl        ;and add low order bcd
  139.     mov    ah,dh        ;ah=bcd time digit
  140.     ret            ;al=binary time digit
  141. ;
  142. ; get a bcd clock digit into al
  143. ; enter: si  point to digtab
  144. ;
  145. rone:    mov    al,digtab[si]        ;get the digit number
  146.     inc    si            ;bump to next digit
  147.     add    al,10h            ;add read mask
  148.     out    clkcmd,al    
  149.     cmp    al,15h            ;is it hours 10 digit
  150.     in    al,clkdata
  151.     jnz    rone9
  152.     sub    al,08h            ;yes-kill 24 hour bit
  153. rone9:    and    al,0fh            ;strip irrelevant bits
  154.     ret                ;al=bcd clock digit
  155.  
  156.  
  157.     eject
  158.     DSEG
  159. ;********************************
  160. ;*                *
  161. ;*    data for routine    *
  162. ;*                *
  163. ;********************************
  164.  
  165. bin_str        rs    0
  166. tod_day        rw    1
  167. tod_hr        rb    1
  168. tod_min        rb    1
  169. tod_sec        db    0
  170.  
  171. ascii_str    db    CR,LF
  172.         db    'System time set '
  173. datestr        db    'MM/DD/YY  '     ;date string
  174. timestr        db    'HH:MM:00'     ;time string
  175.         db    CR,LF,'$'
  176.  
  177. digtab    db    0,1,2,3,4,5,11,12,9,10,7,8
  178. ;        ss  mm  hh   yy   mm   dd
  179.  
  180.     end