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 / DEMON / CRRPATCH.COM / CRRTIM.Z < prev    next >
Text File  |  1979-11-30  |  8KB  |  413 lines

  1. ; CRR Time overlay (c) 1993 Paul Martin, version 1.60
  2. ; ================
  3. ; Last update 14 Nov 93
  4. ;
  5. ; This is the standard overlay which works for standard CP/M 2.2
  6. ; CP/M 3.1 (Plus) and ZSDOS/ZDDOS.
  7. ;
  8. ; Under CP/M 3.1 the time is obtained using BDOS function 105.
  9. ; Under CP/M 2.2 the time is "fudged"
  10. ;
  11. ; This file should be assembled using David Goodenough's ZSM23,
  12. ;
  13. ;    ZSM CRRTIM
  14. ;
  15. ; and applied to CRR using his ZPATCH
  16. ;
  17. ;    ZPATCH CRR CRRTIM
  18. ;
  19. ;
  20. .org    0x2100
  21.  
  22. entry:
  23.     jp    gettad
  24.  
  25. ; table starts at 0x2103
  26.  
  27. year:    dw    0    ; Year
  28. month:    db    0    ; Month 1=Jan, 2=Feb, .. 12=Dec
  29. day:    db    0    ; Day of month
  30. dow:    db    0    ; Day of week 1=Sun, 2=Mon,.., 7=Sat
  31. hour:    db    0    ; Hour in 24h format 0=midnight, 13=1pm
  32. mins:    db    0    ; Minute
  33. secs:    db    0    ; Second (if supported, zero otherwise)
  34. rtc:    db    0    ; non-zero if rtc present
  35.  
  36. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  37. ;;;;;;;;;;  DO NOT CHANGE ANYTHING ABOVE THIS LINE  ;;;;;;;;;;;;
  38. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  39. ;
  40. ; The space 0x2100 to 0x22ff (512 bytes) has been set aside for
  41. ; real time clock overlays.
  42. ;
  43. ; You may freely modify this overlay for use as a CRR time
  44. ; overlay. The single condition of its use is that if you modify
  45. ; it, you should make public your modifications so that other
  46. ; people with similar equipment may be able to use it.
  47. ;
  48. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  49.  
  50.  
  51. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  52. ; Jul2Day
  53. ;  - Day of year -> year,month,day converter
  54. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  55. jul2day:
  56. ;
  57. ; Entry:
  58. ;  HL = Day of year
  59. ;  BC = Year
  60. ; Exit:
  61. ;  E = Month
  62. ;  D = Day
  63. ;  BC = Year
  64. ;       all other registers and flags preserved
  65. ;
  66.         push    af      ; save registers
  67.     push    ix
  68.     push    hl
  69.     push    bc
  70.  
  71.     ld    de,1    ; month = 1
  72.     ld    ix,dayinmo
  73. jullp:  ld      b,(ix)  ; how many days in month(e)
  74.         ld      a,e     ; a=month
  75.     cp    2
  76.         jr      nz,jntlp ; not February
  77.         ld      a,c     ; a=year mod 256  (no check for 2100AD)
  78.     and    3
  79.         jr      nz,jntlp ; not leap year
  80.         inc     b       ; 29 days in Feb in leap yr
  81. jntlp:
  82.         ld      a,l     ; a=lsb end of "day of year"
  83.         sub     b       ; subtract length of month
  84.         ld      l,a     ; l=result (mod 256)
  85.         jr      c,jcarry   ; b>l
  86.         or      a
  87.         jr      nz,jncrry  ; l<>0
  88.         or      h       ; h==0?
  89.         jr      z,jfin
  90.  
  91. jncrry: inc     e       ; next month
  92.     inc    ix
  93.     jr    jullp
  94.  
  95. jcarry:
  96.         inc     h
  97.         dec     h
  98.         jr      z,jfin
  99.         dec     h
  100.         jr      jncrry
  101.  
  102. jfin:   ld      a,l
  103.     add    a,b
  104.     ld    d,a
  105.     pop    bc
  106.     pop    hl
  107.     pop    ix
  108.     pop    af
  109.     ret
  110.  
  111. dayinmo:    ; data for jul2day
  112.     db    31,28,31,30,31,30,31,31,30,31,30,31
  113.  
  114.  
  115. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  116. ; BCD2Bin
  117. ; - BCD to Binary converter
  118. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  119. bcd2bin:
  120. ;
  121. ; Entry:
  122. ;   A = BCD number
  123. ; Exit:
  124. ;   A = binary number
  125. ; flags corrupted
  126. ;   
  127.     push    bc
  128.     ld    b,a    ;save a
  129.     and    0xf0    ; mask off lower bits
  130.     srl    a    ;x8
  131.     ld    c,a    ; store a*8
  132.     srl    a    ;x4
  133.     srl    a    ;x2
  134.     add    a,c    ;x2 + x8 = x10
  135.     ld    c,a
  136.     ld    a,b
  137.     and    0x0f
  138.     add    a,c
  139.     pop    bc
  140.     ret
  141.  
  142.  
  143. ;;;;;;;;;;
  144. ; CPM2Jul
  145. ;  CPMDate (days since Jan 1 1978) -> year, dayofyear
  146. ;;;;;;;;;;
  147. cpm2jul:
  148. ;
  149. ;
  150. ; Entry:
  151. ;  HL = CPMdate
  152. ; Exit:
  153. ;  BC = year
  154. ;  HL = dayofyear
  155. ;  all other registers and flags preserved
  156. ;
  157.     push    af
  158.     push    de
  159.     ld    de,1978        ; Base year = 1978
  160. c2jl:    ld    bc,365        ; yearlen = 365 days
  161.     ld    a,e        ; is leap year?
  162.     and    3
  163.     jr    nz,c2j1
  164.     inc    bc        ; Yes, year = 366 days
  165.     and    a        ; clear carry
  166. c2j1:    sbc    hl,bc        ; cpmdate -= yearlen.
  167.     jr    c,c2j2
  168.         jr      z,c2j2
  169.     inc    de        ; not this year
  170.     jr    c2jl        ; go round again
  171. c2j2:    add    hl,bc        ; restore days
  172.     ld    b,d
  173.     ld    c,e
  174.     pop    de
  175.     pop    af
  176.     ret            ; get out
  177.  
  178.  
  179. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  180. ; Zeller
  181. ;  -  Zeller's congruence for dates later than 1978
  182. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  183. zeller:
  184. ;
  185. ; Entry conditions:
  186. ;  year, month and day contain legal values
  187. ;
  188. ; Exit:
  189. ;  dow is set correctly
  190. ;
  191. ;  all registers and flags preserved
  192. ;
  193.     push    af
  194.     push    hl
  195.     push    de
  196.     push    bc
  197.     ld    bc,(year)
  198.     ld    de,(month)
  199.  
  200.     push    bc    ; save for later
  201.     push    de    ; ditto
  202.     ld    h,b
  203.     ld    l,c    ; HL = year
  204.  
  205.     push    hl
  206.         ld      bc,1978
  207.     or    a
  208.     sbc    hl,bc    ; HL = year - 1978
  209.         jr      nc,zdateok
  210.         ld      bc,1900 ; done too much
  211.         add     hl,bc   ; add it back
  212. zdateok:
  213.     ex    (sp),hl    ; (SP) = year-1978,   HL=year
  214.  
  215.     ld    bc,1976
  216.     or    a
  217.     sbc    hl,bc    ; HL=year-1976
  218.         jr      nc,zdate2
  219.         ld      bc,1900 ; done too much
  220.         add     hl,bc   ; add it back
  221. zdate2:
  222.     srl    h
  223.     rr    l    ; div 2
  224.     srl    h
  225.     rr    l    ; div 4
  226.     ex    de,hl
  227.     pop    hl    ; HL = (year-78), DE=(year-76)div 4
  228.     add    hl,de    ; HL = HL+DE
  229.  
  230.     pop    de    ; D = day, E = month
  231.     push    de    ; save again
  232.  
  233.     push    hl    ; save this, too
  234.     ld    hl,monmod
  235.     dec    e
  236.     ld    d,0
  237.     add    hl,de
  238.     ld    e,(hl)    ; table lookup, de = month correction
  239.     pop    hl
  240.     add    hl,de    ; add correction
  241.  
  242.     pop    de    ; D/E=day/month
  243.     ld    c,d
  244.     ld    b,0    ; BC = day
  245.     add    hl,bc    ; HL = accum+day
  246.     dec    hl
  247.  
  248.     pop    bc    ; BC = year
  249.     ld    a,c
  250.     and    3
  251.     jr    nz,zncorr    ; not a leap year
  252.     ld    a,e
  253.     cp    3
  254.     jr    nc,zncorr    ; March or later
  255.     dec    hl        ; take off a day
  256.  
  257. zncorr:            ; Using repeated subtraction for space, not speed
  258.     ld    bc,7    ; mod 7
  259.     or    a    ; clear carry
  260. znl:    sbc    hl,bc    ; subtract
  261.     jr    nc,znl    ; until carry
  262.  
  263.     add    hl,bc    ; add it back on
  264.     ld    a,l    ; a = day(0-6)
  265.     inc     a    ; (1-7)
  266.     ld    (dow),a
  267.     pop    bc
  268.     pop    de    ; restore registers
  269.     pop    hl
  270.     pop    af
  271.     ret
  272.  
  273. monmod:        ;data for zeller
  274.     db    0,3,3,6,1,4,6,2,5,0,3,5
  275.     
  276.  
  277. .var    bdos    0x0005    ; a handy definition
  278.  
  279. ;;;;;;;;;;;;;;;;;;;;;;;;
  280. ; This routine gets called by CRR
  281. ;;;;
  282. gettad:
  283. ;
  284. ; Entry:
  285. ;  no special conditions
  286. ;
  287. ; Exit:
  288. ;  year, month, day, dow, hour, mins, secs, and rtc
  289. ;    should contain valid information.
  290. ;
  291. ; AF,BC,DE,HL may be changed on return
  292. ; Suggest IX,IY be unchanged (unsure)
  293. ;
  294. ;
  295.         ld      a,(0x010a)
  296.         or      a
  297.         jr      z,notzcpr
  298.         ld      c,48
  299.         call    bdos
  300.         ld      a,h
  301.         cp      'S'
  302.         jr      z,iszcpr
  303.         cp      'D'
  304.         jr      z,iszcpr
  305.  
  306. notzcpr:ld      c,12
  307.         call    bdos    ; get CP/M version number.
  308.     ld    a,l
  309.     cp    0x31    ; are we running under CP/M Plus?
  310.     jr    nc,cpmplus
  311.     call    zeller
  312.     xor    a
  313.     ld    (rtc),a    ; Under this environment, there is no RTC
  314.     ld    hl,mins
  315.     inc    (hl)    ; bump minutes
  316.     ld    a,59
  317.     cp    (hl)
  318.     ret    nc    ; mins less than or equal to 59
  319.     ld    (hl),0    ; mins = 0
  320.     dec    hl    ; point to hour
  321.     inc    (hl)    ; bump hour
  322.     ld    a,23
  323.     cp    (hl)
  324.     ret    nc    ; hour is less than or equal to 23
  325.     ld    (hl),23    ; can't be bothered with days
  326.     inc    hl
  327.     inc    hl
  328.     inc    (hl)    ; bump seconds, so that MSGIDs are OK
  329.     ret
  330. cpmplus:
  331.     ld    c,105
  332.     ld    de,datrec
  333.     call    bdos
  334.     call    bcd2bin
  335.     ld    (secs),a
  336.     ld    a,(datmn)
  337.     call    bcd2bin
  338.     ld    (mins),a
  339.     ld    a,(dathr)
  340.     call    bcd2bin
  341.     ld    (hour),a
  342.     ld    hl,(datint)
  343.     call    cpm2jul
  344.     call    jul2day
  345.     ld    (year),bc
  346.     ld    (month),de    ; this sets day as well
  347.     call    zeller
  348.     ld    a,1
  349.     ld    (rtc),a
  350.     ret
  351. ;
  352.  
  353.  
  354. iszcpr:
  355.         ld      c,98
  356.     ld    de,datrec
  357.     call    bdos
  358.         ld      a,(zcsec)
  359.     call    bcd2bin
  360.     ld    (secs),a
  361.         ld      a,(zcmin)
  362.     call    bcd2bin
  363.     ld    (mins),a
  364.         ld      a,(zchour)
  365.     call    bcd2bin
  366.     ld    (hour),a
  367.         ld      a,(zcday)
  368.         or      a               ; Test for zero day
  369.         jp      z,notzcpr       ; (no DOS clock) b/m 6/11/93
  370.         call    bcd2bin
  371.         ld      (day),a
  372.         ld      a,(zcmonth)
  373.     call    bcd2bin
  374.         ld      (month),a
  375.         ld      a,(zcyear)
  376.     call    bcd2bin
  377.         ld      h,0
  378.         ld      l,a
  379.         ld      de,1900
  380.         add     hl,de
  381.         cp      77
  382.         jr      nc,zc1
  383.         ld      de,100
  384.         add     hl,de
  385. zc1:    ld      (year),hl
  386.     call    zeller
  387.     ld    a,1
  388.     ld    (rtc),a
  389.     ret
  390.     
  391.  
  392. datrec:        ; CP/M time record
  393. zcyear:
  394. datint: db      0
  395. zcmonth:
  396.         db      0
  397. zcday:
  398. dathr:    db    0
  399. zchour:
  400. datmn:    db    0
  401. zcmin:  db      0
  402. zcsec:  db      0
  403.  
  404. ;
  405. ; Many thanks to Bruce Morgen for pointing out a bug and a "gotcha" in 
  406. ; the original version of the ZCPR ZSDOS and ZDDOS time support.
  407. ;
  408. ;-----
  409. ; 14-Nov-93
  410. ;  Fixed bug which caused translation of 14 Oct 93 to 0 Feb 93
  411. ;  Fixed bug which caused translation of 31 Dec xx to 0 Jan xx
  412. ;
  413.