home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / jsage / znode3 / util / dyowk01.z80 < prev    next >
Encoding:
Text File  |  1994-09-02  |  3.0 KB  |  122 lines

  1. ; Module:    DAYOWEEK derives day of week from month/day/year
  2. ; Author:    Bill Elliot
  3. ; Date:        30 March 1990
  4. ;
  5. ;HISTORY:
  6. ;
  7. ; Version .01 (30 March 1990)
  8. ;
  9. ; This is just a module that can be modified for different uses.  My
  10. ;    particular use is for setting the RTC in the ON! computer and the 
  11. ;    ONEAC ONEGRAPH (power line monitor).
  12. ;
  13. ; As presented here the module only obtains the byte value needed for
  14. ;    setting into the clock register for day of week (Sunday = 0).
  15. ;    Obviously some other code will need to be written for display etc.
  16. ;
  17. ; This module makes several assumptions:
  18. ;
  19. ;    - Earliest date is 1/1/88
  20. ;    - It will only be used until 12/31/2087
  21. ;
  22. ; (These assumptions could be removed with a little more code.)
  23. ;
  24. ;
  25. bench:    equ    88        ; Benchmark year
  26. ;
  27. entry:    jp    start
  28.     ds    13,0        ; Fill rest of line with 0
  29. clock:    db    0,0        ; Seconds
  30. mins:    db    2,5
  31. hours:    db    3,1
  32. dayw:    db    0
  33. date:    db    6,0
  34. month:    db    8,0
  35. year:    db    0,9
  36. ;
  37. ;
  38. start:    ld    hl,year+1
  39.     ld    a,(hl)        ; Get tens of years in A
  40.     call    atim10        ; Return with A=A*10
  41.     dec    hl
  42.     ld    b,(hl)
  43.     add    a,b        ; A now has number of years
  44.     cp    bench        ; Compare against benchmark
  45.     jr    nc,dodays
  46.     add    a,100
  47. dodays:    sub    bench        ; Subtract out benchmark years
  48.     ld    e,a        ; E has number of days due to years
  49.     ld    b,-1        ; Clear counter
  50.     ld    c,0        ; Clear exact leap year flag
  51.     jr    z,stleap    ; Current year must be 1988
  52.     inc    e        ; Up one for 1988 leap year
  53.     ld    d,4        ; Leap year occurs every four years
  54. ckleap:    sub    d        ; Divide by 4
  55.     jr    z,stleap    ; Do exact leap year stuff
  56.     inc    b        ; Increment leap year day counter
  57.     jr    nc,ckleap
  58.     jp    doleap
  59. stleap:    inc    b
  60.     inc    c        ; Set exact leap year flag
  61. ;
  62. doleap:    ld    a,e
  63.     add    a,b        ; Total number year and leap offset days
  64.     ld    l,a        ; Put it into L for now
  65.     ld    h,0        ; Go for 16 bits now
  66.     ld    de,(month)    ; Get tens of month value
  67.     ld    a,d
  68.     call    atim10
  69. mtadd:    add    a,e        ; A now has month value
  70.     dec    c        ; Check for exact leap year (In C)
  71.     jp    m,noleap    ; If M, not an exact leap year
  72.     cp    3        ; Check for >= 3/1
  73.     jr    c,noleap    ; Do not add leap day
  74.     inc    hl        ; Add leap day
  75. noleap:    dec    a
  76.     jr    z,adddte
  77.     ld    b,a
  78.     ld    de,dmonth
  79. mnthlp:    ld    a,(de)        ; Get number of days in month
  80.     add    a,l
  81.     ld    l,a        ; Put new number in L
  82.     ld    a,h        ; Put H into A
  83.     adc    a,0        ; Get carry into H value
  84.     ld    h,a        ; Put H back
  85.     inc    de        ; Bump the pointer
  86.     djnz    mnthlp
  87. ;
  88. adddte:    ld    de,(date)
  89.     ld    a,d
  90.     call    atim10
  91.     add    a,e        ; x10 + units
  92.     ld    e,a
  93.     ld    d,0
  94.     add    hl,de        ; Finally, total number of days
  95.     ld    de,7        ; Determine remainder after # of weeks
  96.     xor    a        ; Clear carry
  97. dropwk:    sbc    hl,de
  98.     jr    nc,dropwk
  99.     add    hl,de
  100.     ld    e,l        ; L has remainder
  101.     ld    d,0
  102.     dec    e
  103.     jp    p,dayok
  104.     ld    e,6
  105. dayok:    ld    hl,day
  106.     add    hl,de        ; Offset to correct day of week
  107.     ld    a,(hl)
  108.     ld    (dayw),a
  109.     ret            ; All done
  110. ;
  111. atim10:    add    a,a        ; x2
  112.     ld    b,a        ; Save x2 value
  113.     add    a,a        ; x4
  114.     add    a,a        ; x8
  115.     add    a,b        ; x10
  116.     ret
  117. ;
  118. ;
  119. day:    db    5,6,0,1,2,3,4    ; Day order FSSMTWT
  120. dmonth:    db    31,28,31,30,31,30,31,31,30,31,30,31
  121. ;
  122.