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 / KAYPRO / KPARKPAT.ARK / KPARK02P.AZM < prev    next >
Text File  |  1988-06-04  |  6KB  |  226 lines

  1. ; ARK02PAT.AZM
  2. ; ----------
  3. ;  This is a patch file for ARK02.COM that will set the date and time on all 
  4. ;  members to be added or updated to the system date and time.  To install for 
  5. ;  your system, write a routine at SYSDT: which fills the bytes at
  6. ;  MONTH,DAY,YEAR,HOUR,MIN, and SEC with the appropriate values.  (If,
  7. ;  for instance, you have system date but not time, just fill in the date;
  8. ;  the time will default to midnight.)  As it stands this file is configured
  9. ;  to make a CP/M 3 "get date and time" BDOS call.
  10. ;
  11. ;  When you're ready to do the patch, assemble with Z1 (included) or some other
  12. ;  assembler:
  13. ;    Z1 ARKPAT
  14. ;  and overlay with DDT, or (better) Ron Fowler's MLOAD:
  15. ;    MLOAD ARK02.COM,ARKPAT
  16. ;  And et voila! ARK will now fill in the system date & time.
  17. ;
  18. ;  Acknowledgements:
  19. ;    First of all, of course, Thom Henderson for inventing the MSDOS ARC format!
  20. ;    Brian Moore for porting and hand-optimizing (ugh!!) ARK02.
  21. ;    Tom P. Douglas for digging into ARK02 and locating ARKDATE:, and
  22. ;      releasing ARKDATER.LBR.  This program patched ARK to permanently
  23. ;      change the default date and time.
  24. ;    Steven G. Greenberg, for his LDIR-B library directory program, from
  25. ;      which the code to interpret a DRI date was lifted almost unchanged.
  26. ;
  27. ;---------------------------------------------------------------------------
  28. ;
  29.     ORG    100h
  30.     JP    GETDT        ;get date before beginning program
  31.  
  32. START:    EQU    2A21H        ;ARK has a JP 2A21H at 100h, which we overlaid
  33. ENDPRG:    EQU    4901H        ;This is 1 byte after the last page of ARK
  34. ARKDATE: EQU    453EH        ;Address of default date-and-time within ARK
  35.  
  36. ;
  37. ; KAYPRO RTC EQUATES
  38. ;
  39.  
  40. PIOADD    EQU    0FH        ; pio address
  41. CLKADD    EQU    20H        ; rtc register select
  42. CLKCTL    EQU    22H        ; rtc mode control
  43. CLKDAT    EQU    24H        ; rtc data
  44. MONRTC    EQU    07H        ; rtc months register
  45. DAYRTC    EQU    06H        ; rtc days register
  46. HRSRTC    EQU    04H        ; rtc hours register
  47. MINRTC    EQU    03H        ; rtc minutes register
  48. SECRTC    EQU    02H        ; rtc seconds register
  49.  
  50.     ORG    ENDPRG
  51.  
  52. MONTBL: DB    31        ;This is the table of month lengths used
  53. FEB:    DB    28,31,30,31,30,31,31,30,31,30,31
  54.                 ;in the SYSDAT routine.  Note!!! If the
  55.                 ;SYSDAT routine in the original ARKPAT.AZM
  56.                 ;is used, MONTBL MUST BEGIN AT xx01h (i.e.
  57.                 ;1 byte after a page boundary).
  58.  
  59. MONTH:    DB    0        ;these values will be filled in by SYSDT
  60. DAY:    DB    0
  61. YEAR:    DB    0
  62. HOUR:    DB    0
  63. MIN:    DB    0
  64. SEC:    DB    0
  65.  
  66. ADDIT:        ;subroutine to add A to HL &shift B bits right
  67.     ADD    A,L        ;low byte
  68.     LD    L,A        ;save it
  69.     LD    A,H        ;high byte
  70.     ADC    A,0        ;include possible carry
  71.     LD    H,A        ;save it
  72.     INC    B        ;is B zero?
  73.     DEC    B
  74.     RET    Z        ;yes, don't shift
  75. SHIFTR:    ADD    HL,HL        ;shift left one bit
  76.     DJNZ    SHIFTR        ;loop B times
  77.     RET            ;return
  78.  
  79. GETDT:    CALL    SYSDT        ;fill in date and time
  80.     LD    HL,0        ;clean slate
  81.     LD    A,(YEAR)    ;get year
  82.     SUB    80        ;MSDOS dates begin with 1980
  83.     LD    B,4        ;shift 4 bits
  84.     CALL    ADDIT        ;do it
  85.     LD    A,(MONTH)    ;get month
  86.     LD    B,5        ;shift 5 more bits
  87.     CALL    ADDIT        ;do it
  88.     LD    A,(DAY)        ;get day
  89.     CALL    ADDIT        ;shift zero bits
  90.     LD    (ARKDATE),HL    ;save into ARK
  91.     LD    HL,0        ;clean slate
  92.     LD    A,(HOUR)    ;get hour
  93.     LD    B,6        ;shift 6 bits
  94.     CALL    ADDIT        ;do it
  95.     LD    A,(MIN)        ;get minute
  96.     LD    B,4        ;shift 4 bits
  97.     CALL    ADDIT        ;do it
  98.     LD    A,(SEC)        ;get second
  99.     LD    B,1        ;shift 1 bit
  100.     CALL    ADDIT        ;do it
  101.     LD    (ARKDATE+2),HL    ;save into ARK
  102.     JP    START        ;continue with ARK program
  103. ;
  104. BCD2BIN:    ;subroutine to convert from BCD to binary
  105.     LD    B,0        ;zero counter
  106.     OR    A        ;if BCD is zero, get out
  107.     RET    Z
  108. BBLOOP: INC    B        ;count one 
  109.     DEC    A        ;dec one (BCD)
  110.     DAA
  111.     JR    NZ,BBLOOP    ;continue if not done
  112.     LD    A,B        ;load binary value
  113.     RET            ;done
  114. ;
  115. CPM3DT:        ;data area filled by BDOS
  116. CJUL:    DW    0        ;days since 31 Dec 79
  117. CHR:    DB    0        ;hour (BCD)
  118. CMIN:    DB    0        ;min (BCD)
  119. CSEC:    DB    0        ;sec (BCD)
  120.  
  121. SYSDT:
  122.  
  123. ;
  124. ; FETCH RTC DATA
  125. ;
  126.  
  127.     LD    A,PIOADD    ; set rtc status
  128.     OUT    CLKCTL,A
  129.  
  130.     LD    A,88H        ; year for kaypro
  131.     CALL    BCD2BIN
  132.     LD    (YEAR),A
  133.  
  134.     LD    A,MONRTC    ; get month
  135.     CALL    GETDRI
  136.     CALL    BCD2BIN
  137.     LD    (MONTH),A
  138.  
  139.     LD    A,DAYRTC    ; get day
  140.     CALL    GETDRI
  141.     CALL    BCD2BIN
  142.     LD    (DAY),A
  143.  
  144.     LD    A,HRSRTC    ; get hour
  145.     CALL    GETDRI
  146.     CALL    BCD2BIN
  147.     LD    (HOUR),A
  148.  
  149.     LD    A,MINRTC    ; get minute
  150.     CALL    GETDRI
  151.     CALL    BCD2BIN
  152.     LD    (MIN),A
  153.  
  154.     LD    A,SECRTC    ; get second
  155.     CALL    GETDRI
  156.     CALL    BCD2BIN
  157.     LD    (SEC),A
  158.  
  159. ;
  160. ; GET DATE/TIME FROM RTC SUBROUTINE
  161. ;
  162. èGETDRI:    OUT    CLKADD,A    ; output rtc address
  163.     IN    A,CLKDAT    ; input rtc data
  164.     RET
  165.  
  166. ;----------------------------
  167. ; The rest of the code is lifted almost without change from Steven G. 
  168. ; Greenberg's LDIR-B utility (release 1.2).  Many thanks.
  169.     LD    A,78        ; Init to 1978
  170.     LD    DE,365        ; Amount to subtract per year (except leap)
  171.     LD    B,28        ; # of days in Feb for current year
  172. ;
  173. YRLP:    AND    A        ; Clear carry
  174.     SBC    HL,DE        ; Subtract 1 year
  175.     JR    Z,GOTYR
  176.     JR    C,GOTYR        ; If carry, we've gone too far
  177.     INC    A        ; Else incr year by one 
  178.     AND    A
  179.     SBC    HL,DE        ; Repeat for the following [non-leap] year
  180.     JR    Z,GOTYR
  181.     JR    C,GOTYR
  182.     INC    A
  183.     INC    B        ; The following year IS a leap year
  184.     INC    DE        ; So use 366 for DE and flag B with a "29"
  185.     AND    A
  186.     SBC    HL,DE
  187.     JR    Z,GOTYR
  188.     JR    C,GOTYR
  189.     INC    A
  190.     DEC    DE        ; Put year and # of Feb days back to normal
  191.     DEC    B
  192.     AND    A
  193.     SBC    HL,DE        ; Repeat for one more [non-leap] year
  194.     JR    Z,GOTYR
  195.     JR    C,GOTYR
  196.     INC    A
  197.     JR    YRLP        ; And loop
  198. ;
  199. ;............................................................................
  200. ;
  201. GOTYR:    ADD    HL,DE        ; Reverse the last subtraction with current val
  202.     LD    (YEAR),A    ; The correct year value
  203.     LD    A,B        ; And save current Feb val for future ref
  204.     LD    (FEB),A
  205.     LD    BC,MONTBL    ; Table of # of days/month
  206. ;
  207. MNTHLP:    LD    A,(BC)        ; Get # of days
  208.     LD    E,A        ; Put it in DE
  209.     LD    D,0
  210.     AND    A
  211.     SBC    HL,DE        ; Subtract
  212.     JR    Z,GOTMON
  213.     JR    C,GOTMON    ; If carry, we've gone too far again
  214.     INC    BC        ; Else move ahead to the next month
  215.     LD    A,C
  216.     CP    13        ; (table is <256 bytes, so this is OK)
  217.     JR    NZ,MNTHLP
  218. ;
  219. GOTMON:    ADD    HL,DE        ; Once again, add back in
  220.     LD    A,C        ; month #
  221.     LD    (MONTH),A
  222.     LD    A,L        ; The remainder should be the day#
  223. OKD:    LD    (DAY),A
  224.     RET            ; And that's it!
  225. ;
  226.