home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / jsage / znode3 / modem / mxc-ds10.z80 < prev    next >
Encoding:
Text File  |  1994-09-02  |  4.9 KB  |  186 lines

  1.  
  2. ; MXC-DS10.ASM    DateStamper Overlay  rev 1.0
  3. ;
  4. ; MEXplus Clock Overlay for Plu*Perfect's DateStamper(tm)
  5. ;
  6. ; Usage: any Z80 computer using DateStamper (version after 6/85)
  7. ;        Otherwise, this code is HARDWARE INDEPENDENT as it gets
  8. ;        date via DateStamper rather than directly from clock.
  9. ;
  10. ;------------------------------------------------------------------------
  11. ; revision |  date  |            description        |    author
  12. ;----------+-------------------------------------------------------------
  13. ;   1.0    | 8Mar87 | created original, some code from     | Jim Lill
  14. ;          |        | MXC-MC10.ASM, DATE.ASM, HSHBGPAT.Z80 |
  15. ;------------------------------------------------------------------------
  16. bdos    equ    0005h
  17. cent    equ    1900        ;DS doesn't supply century, change this
  18.                 ;in a few years!
  19. ;...............................
  20. ;
  21. ; Prtval macro prints text and value during assembly
  22. ;
  23. prtval    macro msg,n
  24.     .printx    msg n
  25.     endm
  26. ;...............................
  27. ;
  28. ; start of MEX stuff....
  29.  
  30.     org    0100h
  31.     db    0C3h        ; this is for 8080 processor
  32. ;...............................
  33. ;
  34. ; JMP table for clock overlay
  35. ;
  36.     org    0E00h        ;start of clock overlay
  37.  
  38. start:    jp    gettim        ;get time
  39.     jp    getdat        ;get date
  40.     ret            ;cset processor
  41.     nop
  42.     nop
  43.     ret            ;clock overlay init
  44.     nop
  45.     nop
  46.     ret            ;clock overlay de-init
  47.     nop
  48.     nop
  49. ;...............................
  50. ;
  51. ; gettim, this routine gets the time in clktbl and readies it for MEX
  52. ;
  53. ;    B - hours (0-23)
  54. ;    C - minutes (0-59)
  55. ;    D - seconds (0-59)
  56. ;    E - hundredths of sec (0-99)
  57. ;
  58. gettim:
  59.     call    dschk        ; see if DS is running
  60.     jr    z,cont1        ; jump to cont1 if it is
  61.     ld    DE,0        ; \__ make things zero if not 
  62.     ld    BC,0        ; / 
  63.     ret            ; report back to MEX
  64.  
  65. cont1:    call    putdat        ; get date and put BCD data in CLKTBL
  66.     
  67.     ld     A,(hrs)        ; load packed BCD hours into A
  68.     call    bcd2bin        ; \__ place bin hours in B
  69.     ld    B,A        ; /
  70.     
  71.     ld    A,(mins)    ; load packed BCD mins into A
  72.     call    bcd2bin        ; \__ place bin mins in C
  73.     ld    C,A        ; /
  74.  
  75.     ld    A,(secs)    ; loaded packed BCD secs into A
  76.     call    bcd2bin        ; \__ place bin secs in D
  77.     ld    D,A        ; /
  78.  
  79.     ld    E,0        ; we don't have sec/100, so zero
  80.  
  81.     ret            ; back to MEX
  82. ;................................
  83. ;
  84. ; getdat, this routine gets the date in clktbl and readies it for MEX
  85. ;
  86. ;    BC - year (1985-2099)
  87. ;    D - month (1=jan, 2=feb, etc)
  88. ;    E - day of month (1-31)
  89. ;
  90. getdat:
  91.     call    dschk        ; see if DS is running
  92.     jr    z,cont2        ; jump to cont2 if it is
  93.     ld    E,1        ; if not make day 1     ----\  Legal
  94.     ld    D,1        ;  "  "   "   month 1        + Values
  95.     ld    BC,1999        ;  "  "   "   year  1999  --/  for MEX
  96.     ret            ; report back to MEX
  97.  
  98. cont2:    call    putdat        ; get date and put BCD data in CLKTBL
  99.                 ;
  100.     ld     A,(day)        ; load packed BCD day into A
  101.     call    bcd2bin        ; \__ place bin day in E
  102.     ld    E,A        ; /
  103.  
  104.     ld    A,(mon)        ; load packed BCD mon into A
  105.     call    bcd2bin        ; \__ place bin mon in D
  106.     ld    D,A        ; /
  107.  
  108.     ld    A,(year)    ; load packed BCD year (00-99) into A
  109.     call    bcd2bin        ; \__ place bin year in C
  110.     ld    C,A        ; /
  111.     ld    B,0        ; make a whole year value
  112.     ld    HL,cent        ; by adding cent (eg 1900)
  113.     add    HL,BC        ; to partial year
  114.     ld    C,L        ; move answer into BC
  115.     ld    B,H        ; "     "      "  "
  116.  
  117.     ret            ; back to MEX
  118. ;...............................
  119. ;
  120. ; bcd2bin --> packed BCD (A) converted to Binary (A)
  121. ;
  122. bcd2bin:
  123.     push    BC        ; be safe
  124.     ld    C,A        ; load in value from A
  125.     and    0F0h        ; mask off lower nibble
  126.     rra            ; \
  127.     rra               ;  \_/ move upper nibble
  128.     rra              ;  / \ into lower nibble 
  129.     rra            ; /
  130.     ld    B,A        ; store value *1 
  131.     add    A        ; \__ *4 
  132.     add    A        ; /  
  133.     add    B        ; now *5 
  134.     add    A        ; finally *10
  135.     ld    B,A        ; store 10's digit in B
  136.     ld    A,C        ; \__ load lower digit into A    
  137.     and    00Fh        ; /
  138.     add    B        ; combine both digs. into single byte
  139.     pop    BC        ; restore register
  140.     ret            ; 
  141. ;...............................
  142. ;
  143. ; Check for DateStamper running and set up code for getting time string.
  144. ; The routine returns Z if DS is running and NZ if not.
  145.  
  146. dschk:
  147.     ld    e,'D'        ; DateStamper ID character
  148.     ld    c,0ch        ; Return version function
  149.     call    bdos
  150.     cp    22h        ; Must be CP/M 2.2
  151.     ret    nz        ; If not, return NZ
  152.     ld    a,h        ; Check for return of ID
  153.     cp    'D'
  154.     ret    nz        ; If not, return NZ
  155.     ex    de,hl        ; Get time subroutine addr into HL
  156.     ld    (time),hl    ; Modify code in next routine
  157.     ret            ; Return Z showing success
  158. ;................................
  159.  
  160. ; Get the time string from DateStamper and put it in CLKTBL
  161.  
  162. putdat:
  163.     ld    hl,clktbl    ; Point to time string
  164. time    equ    $+1        ; Address for code modification
  165.     jp      0        ; Filled in by DSCHK
  166.                 ;
  167. clktbl:                ; Storage for packed BCD values 
  168. year:    ds    1        ; 00 - 99
  169. mon:    ds    1        ;  1 - 12
  170. day:    ds    1        ;  1 - 31
  171. hrs:    ds    1        ; 00 - 23
  172. mins:    ds    1        ; 00 - 59
  173. secs:    ds    1        ; 00 - 59
  174. ;................................
  175. ;
  176. ; Assembly-time only, MEX modules have space restrictions
  177. ;
  178.     if1
  179.       .radix 16
  180.       prtval <ending address = >,%($)
  181.       prtval <  overlay size = >,%($ - start)
  182.     endif
  183. ;................................
  184.  
  185.     end            ; MXC-DSnn
  186.