home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / BEEHIVE / UTILITYS / BEERTC.ARC / TIME.MAC < prev   
Text File  |  1990-07-21  |  2KB  |  167 lines

  1. ;02.05.87, age
  2.     TITLE    'Show MicroBee RTC values'
  3.  
  4.     .Z80
  5.     ASEG
  6.     page    80        ;() sets compressed print, 8 lines/inch
  7.  
  8.     org    100h
  9.     .phase    100h
  10.  
  11. addr_port    equ    04h    ;register selection port
  12. data_out    equ    06h    ;data output port to rtc
  13. data_in        equ    07h    ;data input port to read data from rtc
  14.  
  15. bdos    equ    005h
  16. coninf    equ    001h
  17. cnoutf    equ    002h
  18. printf    equ    009h
  19.  
  20. bell    equ    007h
  21. tab    equ    009h
  22. lf    equ    00ah
  23. cr    equ    00dh
  24. clr    equ    01ah
  25.  
  26. ; registers
  27. hour    equ    4
  28. min    equ    2
  29. sec    equ    0
  30. day    equ    7
  31. month    equ    8
  32. year    equ    9    
  33.  
  34. ;macros
  35. rdport    macro
  36.     out    (addr_port),a
  37.     in    a,(data_in)
  38.     endm
  39.  
  40. ; hide the cursor and clear screen
  41. start:    ld    b,00fh
  42.     ld    a,000h
  43.     ld    hl,0fa00h
  44. hide:    ld    (hl),a
  45.     inc    hl
  46.     djnz    hide
  47.     ld    a,clr
  48.     call    con
  49.  
  50. ; signon
  51.     ld    de,signon
  52.     ld    c,printf
  53.     call    bdos
  54.     
  55. ; show the time incrementing
  56.  
  57.     ld    a,lf
  58.     call    con
  59.     ld    a,lf
  60.     call    con
  61.  
  62. ;read the data from the rtc
  63. read_rtc:
  64.     ld    de,space
  65.     ld    c,printf
  66.     call    bdos
  67.     ld    a,hour
  68.     rdport        ;get value for hours
  69.     call    split    ;convert to msb and lsb in H, L
  70.     ld    (hours),hl
  71.  
  72.     ld    a,min
  73.     rdport    
  74.     call    split
  75.     ld    (mins),hl
  76.  
  77.     ld    a,sec
  78.     rdport    
  79.     call    split
  80.     ld    (secs),hl
  81.  
  82.     ld    a,day
  83.     rdport    
  84.     call    split
  85.     ld    (days),hl
  86.  
  87.     ld    a,month
  88.     rdport    
  89.     call    split
  90.     ld    (months),hl
  91.  
  92.     ld    a,year
  93.     rdport    
  94.     call    split
  95.     ld    (years),hl
  96.  
  97. pr_time:
  98.     ld    hl,hours
  99.     ld    b,15h
  100. pr1:    ld    a,(hl)
  101.     call    con
  102.     inc    hl
  103.     djnz    pr1
  104.  
  105. ; wait for next 1 second
  106. loop:    ld    a,00ch            ; status register
  107.     rdport    
  108.     and    010h            ; update bit
  109.     jp    nz,read_rtc
  110.     ld    c,06h            ; swallow key
  111.     ld    e,0ffh
  112.     call    bdos
  113.     or    a
  114.     jp    nz,cpm
  115.     jr    loop
  116.  
  117. ; return to CP/M
  118. cpm:    jp    0            ; warm boot
  119.  
  120. ;subroutines
  121. ;subroutine to take the packed BCD number in A and split it into a tens and
  122. ;a units digit in L and H.
  123. split:    push    af
  124.     and    0f0h    ;mask out units
  125.     ld    l,a    ;L contains tens
  126.     pop    af
  127.     sub    l
  128.     add    a,'0'    ;convert to ascii
  129.     ld    h,a    ;get units into H
  130.     srl    l    ;divide by 16 to get true 0-9 value
  131.     srl    l
  132.     srl    l
  133.     srl    l
  134.     ld    a,l
  135.     add    a,'0'    ;convert to ascii
  136.     ld    l,a
  137.     ret
  138.  
  139. ;console print subroutine
  140. con:    push    af
  141.     push    bc
  142.     push    hl
  143.     ld    e,a
  144.     ld    c,cnoutf
  145.     call    bdos
  146.     pop    hl
  147.     pop    bc
  148.     pop    af
  149.     ret
  150.  
  151. ;messages
  152. signon:    db    clr,lf,lf,lf,tab,'MicroBee Real Time Clock'
  153.     db    '  (press any key to abort)','$'
  154.  
  155. space:    db    cr,'        ','$'
  156.  
  157. ;data storage
  158. hours:    db    '00:'
  159. mins:    db    '00:'
  160. secs:    db    '00   '
  161. days:    db    '00/'
  162. months:    db    '00/19'
  163. years:    db    '00'
  164. temp:    ds    1
  165.  
  166.     end
  167.