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 / CPM / ZCPR33 / S-Z / ZTIME23.LBR / ZTIME23.MAC < prev   
Text File  |  2000-06-30  |  11KB  |  375 lines

  1. ;************************************************************************
  2. ;
  3. ; Version 2.3   Fixed buffer pointer to year to properly
  4. ;               increment and update YEAR latch at new year.
  5. ;
  6. ;               Included .Z80 pseudo-op for Microsoft M80
  7. ;               assembler.
  8. ;
  9. ;                       Chan Webb -- October 20, 1987
  10. ;
  11. ;************************************************************************
  12. ;
  13. ; Version 2.1   Fixed days table to include Tuesday and indexing
  14. ;               offset into days table.
  15. ;
  16. ;                       Richard Jacobson June 30, 1987
  17. ;
  18. ;************************************************************************
  19. ;
  20. ; Version 2.0    Fixed stack set-up error, moved stack and string
  21. ;        buffers to DSEG at end, print "1987" rather than
  22. ;        "'87", broke out console output stuff to subroutines
  23. ;        and formatted as ZCPR33 type 3 COMfile.  Will still
  24. ;        work on non-Z33/BGii systems if linked at 100H (use
  25. ;        ZT0100.COM, ZT8000.COM is linked at 8000H and is for
  26. ;        for ZCPR33 or BGii - 1.13 or later - only).
  27. ;
  28. ;            Bruce Morgen @11:01:11 June 25, 1987
  29. ;
  30. ;************************************************************************
  31. ;*                                    *
  32. ;*        Written by Fred Maxwell and released into the        *
  33. ;*        public domain in January of 1987.  Do whatever        *
  34. ;*        you want with it, but please give credit where        *
  35. ;*        credit is due.                        *
  36. ;*                                    *
  37. ;*    ZTIME.MAC - This program reads the time from the Kenmore    *
  38. ;*        Computer Technologies Ztime-I calendar/clock for    *
  39. ;*        Z80 based systems.  It is assumed that the clock    *
  40. ;*        is addressed to I/O address E0h.  If not, edit        *
  41. ;*        this source file and change BASE to the address     *
  42. ;*        that you have your clock addressed to.    There        *
  43. ;*        has been no attempt to optimize this program        *
  44. ;*        due to its inherently small size and fast speed.    *
  45. ;*        It was written with legibility in mind.  To        *
  46. ;*        compile this program, use Z80ASM or Z80ASMP(+)        *
  47. ;*        from SLR systems.  This is THE BEST Z80 assembler    *
  48. ;*        available and it's from a company that is still     *
  49. ;*        actively supporting CP/M users.  Let's support        *
  50. ;*        them by buying their products.                *
  51. ;*                                    *
  52. ;*            This program will print the date out as     *
  53. ;*        shown below:                        *
  54. ;*                                    *
  55. ;*        Sunday    January 18, '87  07:43:26            *
  56. ;*                                    *
  57. ;*        * * * * * * * * SPECIAL FEATURE * * * * * * * *     *
  58. ;*                                    *
  59. ;*        This program will keep the year correct as long     *
  60. ;*        as it is run at least once every 5 months.  It        *
  61. ;*        does this by storing the year in a latch in the     *
  62. ;*        58167 clock chip.  It also stores the month in        *
  63. ;*        another latch.    When the time is read, the        *
  64. ;*        current month is compared to the month stored        *
  65. ;*        in the latch.  If the current month number is        *
  66. ;*        lower than the month number in the latch, the        *
  67. ;*        year is incremented by one and stored back in        *
  68. ;*        the latch.                        *
  69. ;*                                    *
  70. ;************************************************************************
  71.  
  72. .Z80
  73.  
  74. BASE    EQU    0E0H        ; This is the base address of the 58167.
  75.  
  76. SEC    EQU    BASE+02H    ; Second counter.
  77. MIN    EQU    BASE+03H    ; Minute counter.
  78. HOUR    EQU    BASE+04H    ; Hour counter.
  79. DAY    EQU    BASE+05H    ; Day of week counter.
  80. DATE    EQU    BASE+06H    ; Date of month counter.
  81. MONTH    EQU    BASE+07H    ; Month counter.
  82.  
  83. YEAR    EQU    BASE+09H    ; 11s latch where we store year.
  84. PRVMON    EQU    BASE+0FH    ; Month on last clock access.
  85.  
  86. BDOS    EQU    00005H        ; Address of BDOS entry point.
  87.  
  88. ZTIME:
  89.     JP    START
  90.     DB    'Z3ENV',3
  91.     DW    00
  92.     DW    ZTIME
  93. DAYS:                ; 7 Days x 12 bytes per day (84 bytes).
  94.     DB    'Sunday  $   '
  95.     DB    'Monday  $   '
  96.     DB    'Tuesday  $  '
  97.     DB    'Wednesday  $'
  98.     DB    'Thursday  $ '
  99.     DB    'Friday  $   '
  100.     DB    'Saturday  $ '
  101.  
  102. MONTHS:                ; 12 months x 11 bytes per month (132 bytes).
  103.     DB    'January $  '
  104.     DB    'February $ '
  105.     DB    'March $    '
  106.     DB    'April $    '
  107.     DB    'May $      '
  108.     DB    'June $     '
  109.     DB    'July $     '
  110.     DB    'August $   '
  111.     DB    'September $'
  112.     DB    'October $  '
  113.     DB    'November $ '
  114.     DB    'December $ '
  115.  
  116. SEPARATER:
  117.     DB    ', 19$'        ; Between day of month and year.
  118.  
  119. SPACES:
  120.     DB    ' - $'        ; Between date and time.
  121.  
  122. CRLF:
  123.     DB    0DH,0AH,'$'    ; Carriage Return, Linefeed.
  124.  
  125. START:
  126.     LD    (STACK),SP
  127.     LD    SP,STACK    ; Use internal stack.
  128.  
  129.     CALL    CRLFST
  130.  
  131.     LD    HL,BUFFER    ; <HL> ----> Date buffer (7 bytes)
  132.     CALL    RDCLOK        ; Get date & time into buffer in packed BCD.
  133.  
  134. DAY_PRINT:
  135.     LD    A,(HL)        ; Get day number into <A>
  136.  
  137.     INC    HL        ; Point to month
  138.     PUSH    HL
  139.  
  140.     DEC    A        ; 0 = Sunday, 1 = Monday, ..., 6 = Saturday.
  141.     LD    B,A        ; <B> = day x 1
  142.     ADD    A,A        ; X 2
  143.     ADD    A,A        ; X 4
  144.     ADD    A,B        ; X 5
  145.     ADD    A,A        ; X 10
  146.     ADD    A,B        ; X 11
  147.     ADD    A,B        ; X 12
  148.     LD    E,A        ; <E> = Day x 12 = offset into day name table.
  149.     LD    D,0        ; <DE> = Offset
  150.     LD    HL,DAYS        ; <HL> points to table of days.
  151.     ADD    HL,DE        ; <HL> points to name of day.
  152.     EX    DE,HL        ; <DE> points to name of day.
  153.     CALL    BPSTR
  154.  
  155. MONTH_PRINT:
  156.     POP    HL        ; Get pointer to month.
  157.     XOR    A        ; Zero accumulator.
  158.     LD    B,A        ; Zero register <B>.
  159.     RLD            ; Get tens digit.
  160.     JR    Z,BINARY    ; It's less than 10 if digit is 0
  161.  
  162.     LD    B,10        ; Add this to low nibble to make binary.
  163.  
  164. BINARY:
  165.     RLD            ; Get ones digit into <A>.
  166.     ADD    A,B        ; Add tens digit.
  167.  
  168.     INC    HL        ; Point to date.
  169.     PUSH    HL        ; Save pointer
  170.  
  171.     LD    B,A        ; Save Packed BCD month number.
  172.  
  173.     DEC    A        ; 0 = Jan., 1 = Feb, ..., 11 = Dec.
  174.     LD    B,A        ; <B> = month x 1
  175.     ADD    A,A        ; X 2
  176.     ADD    A,A        ; X 4
  177.     ADD    A,B        ; X 5
  178.     ADD    A,A        ; X 10
  179.       ADD    A,B        ; X 11
  180.  
  181.     LD    E,A        ; <E> = Day x 11 = offset into month table.
  182.     LD    D,0        ; <DE> = Offset
  183.     LD    HL,MONTHS    ; <HL> points to table of months.
  184.     ADD    HL,DE        ; <HL> points to name of month.
  185.     EX    DE,HL        ; <DE> points to name of month.
  186.     CALL    BPSTR
  187.  
  188. DATE_PRINT:
  189.     POP    HL        ; Get pointer to date (packed BCD).
  190.     LD    A,(HL)        ; Get packed BCD into <A>.
  191.  
  192.     INC    HL        ; Point to year.
  193.     PUSH    HL        ; Save pointer.
  194.  
  195.     CALL    BCD_PRINT    ; Print 2 digits of date.
  196.     LD    DE,SEPARATER    ; Print ', 19'.
  197.     CALL    BPSTR
  198.  
  199. YEAR_PRINT:
  200.     POP    HL        ; Get pointer to year (packed BCD).
  201.     LD    A,(HL)        ; Get packed BCD into <A>.
  202.  
  203.     INC    HL        ; Point to hour.
  204.     PUSH    HL        ; Save pointer.
  205.  
  206.     CALL    BCD_PRINT    ; Print 2 digits of year.
  207.     LD    DE,SPACES    ; Print "   " (3 spaces).
  208.     CALL    BPSTR
  209.  
  210. HOUR_PRINT:
  211.     POP    HL        ; Get pointer to hour (packed BCD).
  212.     LD    A,(HL)        ; Get packed BCD into <A>.
  213.  
  214.     INC    HL        ; Point to minutes
  215.     PUSH    HL        ; Save pointer.
  216.  
  217.     CALL    BCD_PRINT    ; Print 2 digits of date.
  218.     LD    E,':'        ; Print ":" (colon).
  219.     CALL    BPCHAR
  220.  
  221. MIN_PRINT:
  222.     POP    HL        ; Get pointer to minutes (packed BCD).
  223.     LD    A,(HL)        ; Get packed BCD into <A>.
  224.  
  225.     INC    HL        ; Point to seconds.
  226.     PUSH    HL        ; Save pointer.
  227.  
  228.     CALL    BCD_PRINT    ; Print 2 digits of minutes.
  229.     LD    E,'.'        ; Print ":" (colon).
  230.     CALL    BPCHAR
  231.  
  232. SEC_PRINT:
  233.     POP    HL        ; Get pointer to seconds (packed BCD).
  234.     LD    A,(HL)        ; Get packed BCD into <A>.
  235.  
  236.     CALL    BCD_PRINT    ; Print 2 digits of seconds.
  237.     LD    DE,CRLF        ; Print CR,LF
  238.     CALL    BPSTR
  239.  
  240.     LD    SP,(STACK)    ; Restore it.
  241.     RET            ; All done.
  242.  
  243. ;************************************************************************
  244. ;*                                    *
  245. ;*    BCD_PRINT - this subroutine prints the two digit packed     *
  246. ;*        BCD number in <A> to the console.            *
  247. ;*                                    *
  248. ;*    ON ENTRY:    <A> contains packed BCD number.         *
  249. ;*                                    *
  250. ;*    ON EXIT:    All registers to be considered trashed.     *
  251. ;*                                    *
  252. ;************************************************************************
  253.  
  254. BCD_PRINT:
  255.     PUSH    AF        ; Save packed BCD number
  256.     SRL    A        ; Get tens digit in low nibble...
  257.     SRL    A        ; And high nibble zeroed.
  258.     SRL    A
  259.     SRL    A
  260.     ADD    A,030H        ; Make it ASCII.
  261.     LD    E,A
  262.     CALL    BPCHAR
  263.  
  264.     POP    AF        ; Get packed BCD back in <A>.
  265.     AND    0FH        ; Strip tens digit.
  266.     ADD    A,030H        ; Make ASCII.
  267.     LD    E,A
  268.     JP    BPCHAR
  269.  
  270. ;    RET        ; All done.
  271.  
  272.  
  273. ;************************************************************************
  274. ;*                                    *
  275. ;*    RDCLOK - This routine reads the day (1-7), year (00-99),    *
  276. ;*        month (1-12), date (1-31), hours (0-23), minutes    *
  277. ;*        (0-59), and seconds (0-59).  These values are        *
  278. ;*        returned as packed BCD in a buffer pointed to        *
  279. ;*        by <HL> in the format:                    *
  280. ;*                                    *
  281. ;*        BYTE        CONTENTS                *
  282. ;*        ----        --------                *
  283. ;*        1        Day                    *
  284. ;*        2        Month                    *
  285. ;*        3        Date                    *
  286. ;*        4        Year                    *
  287. ;*        5        Hours                    *
  288. ;*        6        Minutes                 *
  289. ;*        7        Seconds                 *
  290. ;*                                    *
  291. ;*    NOTE: Since the year is stored in a static location in        *
  292. ;*        the clock, it is incremented whenever the current    *
  293. ;*        month is less than the previous month (also stored    *
  294. ;*        in a static location in the clock).            *
  295. ;*                                    *
  296. ;*    ON ENTRY: <HL> points to buffer.                *
  297. ;*                                    *
  298. ;*    ON EXIT : <HL> points to buffer.                *
  299. ;*                                    *
  300. ;*    NOTE:  The seconds are read at the beginning and end of the    *
  301. ;*        clock read.  They must be the same to guarantee     *
  302. ;*        that the clock hasn't changed during the read.    The    *
  303. ;*        status bit which indicates roll-over is basically    *
  304. ;*        worthless, since the clock can roll over between    *
  305. ;*        reading minutes and hours without ever setting the    *
  306. ;*        bit.  This can lead to times like 11:00:00 when it    *
  307. ;*        really just turned to 12 o'clock.            *
  308. ;*                                    *
  309. ;************************************************************************
  310.  
  311. RDCLOK:    PUSH    HL        ; Save address of buffer.
  312.  
  313.     IN    A,(SEC)        ; Read seconds first and verify
  314.     LD    E,A        ; That they don't change.
  315.  
  316.     LD    C,DAY        ; Get the day first.
  317.     INI            ; Read it and store in buffer.
  318.     LD    C,MONTH        ; Now read the month into buffer.
  319.     INI
  320.     LD    C,DATE        ; Read date into buffer.
  321.     INI
  322.     LD    C,YEAR        ; Point to the year.
  323.     INI            ; Read it into the buffer.
  324.     LD    C,HOUR        ; Now, read the hour.
  325.     INI
  326.     LD    C,MIN        ; Read minutes into buffer.
  327.     INI
  328.     IN    A,(SEC)        ; And finally, read seconds.
  329.  
  330.     CP    E        ; Did clock change during read?
  331.     JR    Z,AOK        ; We're OK if seconds match.
  332.     POP    HL        ; Restore buffer address.
  333.     JR    RDCLOK        ; Try again.
  334.  
  335. AOK:    LD    (HL),A        ; Store seconds in buffer.
  336.  
  337. ;    Now, adjust the year if current month is less than month at last
  338. ;        clock read.
  339.  
  340.     POP    HL        ; HL=start buffer address.
  341.     PUSH    HL
  342.     INC    HL        ; Point to month storage.
  343.     IN    A,(PRVMON)    ; Month at last clock read.
  344.     LD    B,A        ; <B> = Previous Month
  345.     LD    A,(HL)        ; <A> = Current Month
  346.     OUT    (PRVMON),A    ; Update previous month storage.
  347.     CP    B        ; Is Current < Previous?
  348.     JR    NC,DONE        ; If not, we're done.
  349.         INC     HL
  350.     INC    HL        ; Point back to year storage.
  351.     LD    A,(HL)        ; <A> = Year.
  352.     ADD    A,1        ; Year <-- Year + 1
  353.     DAA            ; Adjust for packed BCD.
  354.     LD    (HL),A        ; Store Year.
  355.     OUT    (YEAR),A    ; In chip, too.
  356.  
  357. DONE:    POP    HL        ; Restore pointer to buffer.
  358.     RET            ; All done.
  359.  
  360. BPCHAR:    LD    C,2
  361.     JR    BDJP
  362.  
  363. CRLFST:    LD    DE,CRLF
  364. BPSTR:    LD    C,9
  365. BDJP:    JP    BDOS
  366.  
  367.     DSEG
  368.  
  369. BUFFER:    DS    7        ; Storage for date and time in packed BCD.
  370.  
  371.     DS    30        ; 15 level stack.
  372. STACK:    DS    2
  373.  
  374.     END
  375.