home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / mbug / mbug049.arc / TOD.MAC < prev    next >
Text File  |  1979-12-31  |  5KB  |  191 lines

  1. ;assemble with macro 80.
  2.  
  3.     aseg
  4.     org    100h
  5. .z80
  6.  
  7. bios    equ    5        ;bios
  8.  
  9. ;show time function for microbee with RTC kit
  10. ;
  11. ;register      contents        range
  12. ;
  13. ;0        seconds        0-60
  14. ;1        alarm seconds    0-60
  15. ;2        minutes        0-60
  16. ;3        alarm minutes    0-60
  17. ;4        hours        0-23
  18. ;5        alarm hours    0-23
  19. ;6        day of week    1-7
  20. ;7        day of month    1-30,31,29,28
  21. ;8        month        1-12
  22. ;9        year        0-99
  23. ;
  24. ;all outputs are in bcd
  25.  
  26.     JP    START
  27. DATA:    DB    1EH,1BH,'Y Time Of Day.COM D.BREEZE 18/12/85 ',01AH     
  28.                 ;bit of a wank if file is 'typed'    
  29.  
  30. ;===================================================================
  31. ;main line of program for where all other routines are called
  32.  
  33. start:    ld    a,0ah        ;point to clock register 0A
  34.     out    (4),a        ;set clock ale
  35.     in    a,(7)        ;read register
  36.     bit    7,a        ;if bit 7 =1 then update in progress
  37.     jr    nz,start    ;wait for end of update
  38.  
  39.  
  40.     ld    c,04        ;point to hours register
  41.     call    input        ;get hours
  42.     call    numbers        ;print hours
  43.     ld    a,':'        ;print ':'
  44.     call    output        ;/
  45.     ld    c,02        ;point to minutes reg
  46.     call    input        ;get minutes
  47.     call    numbers        ;print minutes
  48.     ld    a,':'        ;print ':'
  49.     call    output        ;/
  50.     ld    c,00        ;point to seconds reg
  51.     call    input        ;get seconds
  52.     call    numbers        ;print seconds
  53.     ld    a,' '        ;print ' '
  54.     call    output        ;/
  55.     ld    c,06        ;point to day of week
  56.     call    input        ;get day of week
  57.     ld    hl,day        ;point to day: table
  58.     call    calcstr        ;print day
  59.     ld       A,' '        ;print ' '
  60.     call    output         ;/
  61.     ld    c,07        ;point to date reg
  62.     call    input        ;get date
  63.     call    numbers        ;print date
  64.     ld    a,' '        ;print ' '
  65.     call    output        ;/
  66.     ld    c,08        ;point to month reg
  67.     call    input        ;get date
  68.     ld    hl,month    ;point hl to month: table    
  69.     call    calcstr        ;print month
  70.     ld    hl,year        ;point to ' 19'
  71.     call    outstr        ;print it
  72.     ld    c,09        ;point to year reg    
  73.     call    input        ;get year
  74.     call    numbers        ;print year
  75.     ld    hl,crlf        ;print a crlf
  76.     call    outstr
  77.     jp     0        ;exit
  78.  
  79. ;===================================================================
  80. ;enters with b='tens' c='units' hl points to start of table
  81. ;required
  82.    
  83. calcstr:ld    a,c        ;put units in a
  84.     bit    0,b        ;test for greater than ten (months only)
  85.     jr    z,lessten    ;if more than ten then 
  86.     add    a,0ah        ;add ten to count
  87. lessten:ld    b,a        ;ld b with binary of count    
  88.     dec    b        ;dec it by 1
  89.     xor    a        ;clear a
  90. repeat:    add    a,0ah        ;table entry length 10 chars
  91.     djnz    repeat        ;repeat until a=table offset
  92. print:    ld    d,0        ;clear d
  93.     ld    e,a        ;put offset in e
  94.     add    hl,de        ;find address off table entry
  95.     call    outstr        ;send to con:
  96.     ret
  97.  
  98. ;===================================================================
  99. ;enters with hl pointing to start of string to be sent
  100.  
  101. outstr:    push    de
  102.     push    bc
  103.     ex    de,hl    ;point de to string
  104.     ld    c,9    ;bios fuction 'print string'        
  105.     call    bios    ;go and do it
  106.     pop    bc
  107.     pop    de
  108.     ret
  109.  
  110. ;===================================================================
  111. ;enters with b='tens' c='units' 
  112.  
  113. numbers:ld    hl,digits    ;point to '0'
  114.     ld    D,0        ;clear d
  115.     ld    e,b        ;put 'tens' in e
  116.     add    hl,de        ;point to first digit
  117.     ld    a,(hl)        ;get the char
  118.     call    output        ;output it           
  119.     ld    hl,digits    ;point to '0'        
  120.     ld    e,c             ;put 'tens' in e               
  121.     add    hl,de           ;point to second digit
  122.     ld    a,(hl)          ;get the char        
  123.     call    output          ;output it           
  124.     ret                     
  125.  
  126. ;===================================================================
  127. ;enters with char in a
  128.  
  129. output: push    bc
  130.     push    de
  131.     ld    c,02h    ;bios function
  132.     ld    e,a    ;char in e to con:
  133.     call    bios    ;do that
  134.     pop    de
  135.     pop    bc
  136.     ret
  137.  
  138. ;===================================================================
  139. ;enters with c containing address of clock register to read
  140. ;and sets up bc to contain the bcd result
  141. ;b contains the upper nibble
  142. ;c contains the lower nibble
  143.  
  144. input:    ld    a,c    ;put register num in a
  145.     out    (4),a    ;set register address in ale of clock
  146.     in    a,(7)    ;read desired register
  147.     push    af    ;save it on stack
  148.     and    0f0h    ;scrub lower nibble
  149.     rra        ;shift upper nibble down to lower nibble
  150.     rra        ;  /
  151.     rra        ; /
  152.     rra        ;/
  153.     ld    b,a    ;store in b
  154.     pop    af    ;restore a from stack
  155.     and    0fh    ;scrub upper nibble
  156.     ld    c,a    ;store in c
  157.     ret
  158.     
  159. ;===================================================================
  160. ;asci tables
  161.  
  162. digits:    db    '0123456789'
  163.  
  164. day:    db    'Sunday$000'
  165.     db    'Monday$000'
  166.     db    'Tuesday$00'
  167.     db    'Wednesday$'
  168.     db    'Thursday$0'
  169.     db    'Friday$000'
  170.     db    'Saturday$0'
  171.  
  172.  
  173. month:    db    'January$00'
  174.     db    'February$0'
  175.     db    'March$0000'
  176.     db    'April$0000'
  177.     db    'May$000000'
  178.     db    'June$00000'
  179.     db    'July$00000'
  180.     db    'August$000'
  181.     db    'September$'
  182.     db    'October$00'
  183.     db    'November$0'
  184.     db    'December$0'
  185.  
  186. year:    db    ' 19$'
  187. crlf:    db    0dh,0ah,'$'
  188.  
  189. end
  190.  
  191.