home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / cpm / bye5 / b5-clock.lbr / B5C-MTN2.IQS / B5C-MTN2.INS
Encoding:
Text File  |  1986-03-08  |  4.8 KB  |  181 lines

  1. ; B5C-MTN2.INS   -   Clock routine for Mountain Hardware 100,000 day clock
  2. ;            Dennis Recla    9/15/85
  3. ;
  4. ;    This version does not take into account the number of days
  5. ;    since some far off starting point (Jan 1, 1978), but begins
  6. ;    from January 1 of the current year.  This way only a running
  7. ;    count of days since the beginning of the year needed to be
  8. ;    calculated.  When you set the days on the clock be sure you
  9. ;    use the Julian day for the current year.
  10. ;
  11. ;    Remember to set CLOCK, BCD2BIN, and BIN2BCD to YES.
  12. ;
  13. ;    Real - Time clock buffer is organized as HH:MM:SS YYY/MM/DD
  14. ;
  15. ;    RTCBUF:
  16. ;        DB    99H,99H,99H    ;HH:MM:SS (BCD 24 Hr Time)
  17. ;        DB    19H,85H,01H,31H ;YYYY/MM/DD (BCD ISO Date)
  18. ;
  19. ;
  20. ;-------------------------------------------------------------------------
  21. ;
  22. ;
  23. CENTURY:EQU    019H        ;Current century (19xx) in BCD
  24. ;
  25. CLKADR:    EQU    0E0H        ;Starting address of Clock board
  26. CLKMSK:    EQU    0FH        ;Mask for high nibble 
  27. CYEAR:    EQU    085H        ;Update this once a year (Current Year)
  28. ;
  29. ;
  30. ;
  31. TIME:    IN    CLKADR+8    ;Read in the hour value
  32.     ANI    CLKMSK        ;Remove the high nibble status
  33.     MOV    B,A        ;Put the value in B to hold
  34.     IN    CLKADR+9    ;Read in the 10's of hours
  35.     ANI    CLKMSK        ;Remove the high nibble status
  36.     CALL    ROTADD        ;Combine the two values
  37.     STA    RTCBUF        ;Put the hours value in 
  38.     CALL    BCDBIN        ;Convert the value to binary
  39.     STA    CCHOUR        ;Store it in the hour value
  40. ;
  41.     IN    CLKADR+6    ;Read in the Minute value
  42.     ANI    CLKMSK        ;Remove the high nibble status
  43.     MOV    B,A        ;Put the value in B to hold
  44.     IN    CLKADR+7    ;Read in the 10's of Minutes
  45.     ANI    CLKMSK        ;Remove the high nibble status
  46.     CALL    ROTADD        ;Combine the two values
  47.     STA    RTCBUF+1    ;Put the minutes value in
  48.     CALL    BCDBIN        ;Convert the value to binary
  49.     STA    CCMIN        ;Store it in the Minutes value
  50. ;
  51.     IN    CLKADR+4    ;Read in the Seconds value
  52.     ANI    CLKMSK        ;Remove the high nibble status
  53.     MOV    B,A        ;Put the value in B to hold
  54.     IN    CLKADR+5    ;Read in the 10's of Seconds
  55.     ANI    CLKMSK        ;Remove the high nibble status
  56.     CALL    ROTADD        ;Combine the two values
  57.     STA    RTCBUF+2    ;Put the seconds value in
  58. ;
  59. ;    Put Century in the right place
  60. ;
  61.     MVI    A,CENTURY    ;Put Century value in A
  62.     STA    RTCBUF+3
  63. ;
  64.     MVI    A,CYEAR        ;Put Years value in A
  65.     STA    RTCBUF+4
  66. ;
  67. ;    Now to calculate the month and days since Jan 1st
  68. ;
  69.     IN    CLKADR+10    ;Get the days digit
  70.     ANI    CLKMSK        ;Remove the high nibble status
  71.     MOV    B,A        ;Store the value in B
  72.     IN    CLKADR+11    ;Get the 10's days digit
  73.     ANI    CLKMSK        ;Remove the high nibble status
  74.     CALL    ROTADD        ;Rotate and Add the values
  75.     CALL    BCDBIN        ;Convert the value to Binary
  76.     MOV    E,A        ;Store it in E
  77.     MVI    D,0        ;Clear out the D register
  78.                 ;I'll use it later
  79. ;
  80.     IN    CLKADR+12    ;Get the 100's days digit
  81.     ANI    CLKMSK        ;Remove the high nibble status
  82.     MOV    C,A        ;Store the value in C
  83.     RLC            ; X2
  84.     RLC            ; X4
  85.     RLC            ; X8
  86.     MOV    B,A        ; Store the X8 value in B
  87.     RLC            ; X16
  88.     ADD    B        ; Add the X16 and the X8
  89.     ADD    C        ; Add the X1 value
  90.                 ; This is a total of X25
  91. ;
  92.     LXI    H,00        ; Clear the H register
  93.     RLC            ; X2
  94.     ORA    A        ; Clear the Carry
  95.     RAL            ; X4 with carry
  96.     JNC    LOADHL        ; If no carry jump
  97.     MVI    H,1        ; Put a 1 in H register
  98. LOADHL: MOV    L,A        ; Put a value in the low byte
  99.     DAD    D        ; Add H&L to D&E
  100.     SHLD    TIMEPB        ; Store the number of days here
  101. ;
  102.     MVI    A,CYEAR        ; Put the Years value in A
  103.     CALL    CKLEAP        ; Check if leap year
  104.     MVI    A,-28
  105.     JNZ    FEBNO        ; February not 29 days
  106.     MVI    A,-29        ; Leap year
  107. ;
  108. FEBNO:    STA    FEB        ; Set february
  109.     LHLD    TIMEPB        ; Get days count
  110.     LXI    D,MTABLE    ; Point to months table
  111.     MVI    B,0FFH        ; Set up 'B' for subtract
  112.     MVI    A,0        ; Set a for # of months
  113. ;
  114. MLOOP:    PUSH    PSW
  115.     LDAX    D        ; Get month
  116.     MOV    C,A        ; Put in 'C' for subtract
  117.     POP    PSW
  118.     SHLD    TIMEPB        ; Save days count
  119.     DAD    B        ; Subtract
  120.     INX    D        ; Increment months counter
  121.     INR    A
  122.     JC    MLOOP        ; Loop for next month
  123. ;
  124. ;
  125. ; The months are finished, days count is on stack.  First, calculate
  126. ; month.
  127. ;
  128. MDONE:    MOV    B,A        ; Save months
  129.     LHLD    TIMEPB
  130.     MOV    A,H
  131.     ORA    L
  132.     JNZ    NZD
  133.     DCX    D
  134.     DCX    D
  135.     LDAX    D
  136.     CMA
  137.     INR    A
  138.     MOV    L,A
  139.     DCR    B
  140. ;
  141. NZD:    MOV    A,B        ; Retrieve the binary month
  142.     CALL    BINBCD        ; Convert binary month to BCD
  143.     STA    RTCBUF+5    ; Store BCD month in RTCBUF
  144.     MOV    A,L        ; Retrieve binary day of month
  145.     CALL    BINBCD        ; Convert to BCD
  146.     STA    RTCBUF+6    ; Store BCD day of month in RTCBUF
  147. ;
  148.     RET
  149. ;.....
  150. ;
  151. ;
  152. ; This routine checks for leap years.
  153. ;
  154. CKLEAP:    MOV    B,A
  155.     ANI    0FCH
  156.     CMP    B
  157.     RET
  158. ;.....
  159. ;
  160. ;                ;Rotate left and Add the B register
  161. ROTADD: RLC            ;Shift the BCD value from low nibble
  162.     RLC            ;to the high nibble
  163.     RLC
  164.     RLC            ;done shifted it 4 bits left
  165.     ANI    0F0H        ;Mask off the high nibble
  166.     ORA    B        ;add the low nibble and high nibble
  167.     RET
  168. ;
  169. ;
  170. ;
  171. ; This is the month's table
  172. ;
  173. MTABLE:    DB    -31        ;January
  174. FEB:    DB    -28        ;February
  175.     DB    -31,-30,-31,-30    ;Mar-Jun
  176.     DB    -31,-31,-30    ;Jul-Sep
  177.     DB    -31,-30,-31    ;Oct-Dec
  178. ;
  179. TIMEPB:    DW    0        ; Temporary storage
  180. ;
  181.