home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / jsage / znode3 / uploads / zf11src.lbr / ZFSUBS5.ZZ0 / ZFSUBS5.Z80
Encoding:
Text File  |  1992-09-09  |  8.9 KB  |  322 lines

  1. .printx    Reading ZFSUBS5.Z80
  2. ;===========================================================================
  3. ;
  4. ; ZFSUBS5.Z80 - DateStamper Routines
  5. ;
  6. ;===========================================================================
  7.  
  8. rndoff    equ    33            ; FCB offset to random record number
  9.                     ; BDOS function numbers
  10. getvrs    equ    12            ; Get version
  11. setusr    equ    32            ; Get/set user number
  12. setatt    equ    30            ; Set attributes
  13. readrnd    equ    33            ; read-random
  14. writernd equ    34            ; write-random
  15.  
  16. ;-----------------------------------------------------------------------------
  17.  
  18. ; This routine copies the time stamp from the source file (at SOURCE fcb
  19. ; to the destination file (at DEST fcb).
  20.  
  21. tdname:
  22.     db    0            ; Drive
  23.     db    '!!!TIME&'        ; Name
  24.     db    'DAT'            ; Type
  25.  
  26. copydate:
  27.     call    checkds            ; Check and initialize DatStamper code
  28.     ret    z            ; If not installed, return now
  29.  
  30.     ld    hl,tdname        ; Initialize the T&D FCB with name
  31.     ld    de,tdfcb
  32.     ld    bc,12            ; Copy 12 characters
  33.     ldir
  34.  
  35.     ld    bc,(du$req)        ; Log into source drive
  36.     ld    c,0            ; ..but user 0
  37.     call    logud
  38.     ld    hl,(ssector)        ; Get sector/offset info for source
  39.     ld    a,(sindex)
  40.     call    setindex        ; Set TDSECTOR and TDINDEX values
  41.  
  42.     xor    a            ; Flag for getting time stamp
  43.     call    getset            ; Get or set the time stamp
  44.  
  45.     ld    bc,(du$dest)        ; Log into destination drive
  46.     ld    c,0            ; ..but user 0
  47.     call    logud
  48.     ld    hl,(dsector)        ; Get sector/offset info for destination
  49.     ld    a,(dindex)
  50.     call    setindex
  51.  
  52.     xor    a            ; Set flag for
  53.     dec    a            ; ..setting time stamp
  54.     call    getset            ; Set destination time stamp
  55.     ret    z            ; Return now if error
  56.  
  57.     ld    hl,msg119        ; "(date)"
  58.     jp    pstri            ; Note successful date copy
  59.  
  60. ; Subroutine to get or set the time/date stamp for a file.
  61. ; NOTE: on error this routine pops the original return address and
  62. ; returns one level higher, thereby aborting the date copy routine.
  63. ;
  64. ; Entry:    A = 0 and Z set if read
  65. ;        A = FF and NZ if write
  66. ;        TDSECTOR, TDINDEX, and the T&D FCB must be set
  67.  
  68. getset:
  69.     push    af            ; Save read/write flag
  70.     call    tdopen            ; Open source T&D file
  71.     jr    z,fferror        ; Return two levels if error
  72.     pop    af            ; Get read/write flag again
  73.     push    af            ; ..and save it again
  74.     call    rwtd            ; Read or write T&D info
  75.     jr    z,fferror        ; Return two levels if error
  76.     pop    af
  77.     call    nz,tdclose        ; Close the T&D file if written to
  78.     ret
  79. fferror:
  80.     pop    af            ; Pop registers pushed above
  81.     pop    hl            ; Pop address of calling program
  82.     ret                ; Return to level above that
  83.  
  84. ;-----------------------------------------------------------------------------
  85.  
  86. ; Routine to see if DateStamper is loaded.
  87. ;
  88. ; Entry:    nothing
  89. ; Return:    if DateStamper not loaded: A=0 and Z 
  90. ;        if loaded, A<>0, NZ, and HL has address of DS clock routine.
  91.  
  92. checkds:
  93.     ld    hl,tdfcb        ; Initialize time/date FCB
  94.     ld    de,tdfcb+1
  95.     ld    (hl),0            ; Seed with 0
  96.     ld    bc,35            ; Propagate to 35 more bytes
  97.     ldir
  98.     ld    e,'D'            ; DS identifier request
  99.     ld    c,getvrs        ; Get CP/M version
  100.     call    bdosptr
  101.     cp    22h            ; Must be 2.2
  102.     jr    nz,checkds1        ; Branch if not
  103.     ld    a,h            ; See if DS ID returned
  104.     cp    'D'
  105.     jr    nz,checkds1        ; Branch if not
  106.     ex    de,hl            ; Get clock routine address into HL
  107.     ld    a,h            ; Make sure there is a clock
  108.     or    l
  109.     ret
  110. checkds1:
  111.     xor    a            ; Return Z to show no DS
  112.     ret
  113.  
  114. ;-----------------------------------------------------------------------------
  115.  
  116. ; Computes checksum of first 127 bytes of the T&D sector loaded at TDBUFF.
  117. ;
  118. ; Entry:    nothing
  119. ; Exit:        A = sum of 127 bytes
  120. ;        HL -> 128th byte
  121.  
  122. checksum:
  123.     ld    hl,tdbuff        ; Point to T&D buffer
  124.     ld    b,127            ; Bytes to sum
  125.     xor    a            ; Initialize sum
  126. checksum1:
  127.     add    a,(hl)            ; Add in byte
  128.     inc    hl            ; Advance to next
  129.     djnz    checksum1        ; Loop through them all
  130.     ret
  131.  
  132. ;-----------------------------------------------------------------------------
  133.  
  134. ; Set DMA to the address of the T&D buffer
  135. ;
  136. ; Entry:    nothing
  137. ; Exit:        nothing
  138.  
  139. settddma:
  140.     ld    de,tdbuff        ; Point to T&D buffer
  141.     ld    c,setdma
  142.     jr    bdossave
  143.  
  144. ;-----------------------------------------------------------------------------
  145.  
  146. ; BDOS call acting on T&D file control block
  147. ;
  148. ; Entry:    normal BDOS information less DE
  149. ; Exit:        normal BDOS output information
  150. ;        DE return code saved in BDOSDE
  151.  
  152. bdostd:
  153.     ld    de,tdfcb        ; Set FCB pointer
  154.                     ; Fall through to bdossave
  155.  
  156. ;-----------------------------------------------------------------------------
  157.  
  158. ; Routine to call BDOS and save the value returned by DateStamper in DE
  159. ; in BDOSDE.  (Do not move this routine -- one above falls into it.)
  160. ;
  161. ; Entry:    normal BDOS information
  162. ; Exit:        normal BDOS output information
  163. ;        DE return code saved in BDOSDE
  164.  
  165. bdossave:
  166.     call    bdosptr
  167.     ld    (bdosde),de
  168.     ret
  169.  
  170. ;-----------------------------------------------------------------------------
  171.  
  172. ; Open the time and date file.  We must already be in user 0.
  173. ;
  174. ; Entry:    A=0 for reading
  175. ;        A=FF for writing (routine clears R/O status)
  176. ; Exit;        Z set if error
  177.  
  178. tdopen:
  179.     ld    (rwflag),a        ; Save read/write flag
  180.     ld    c,open            ; Open-file function
  181.     call    bdostd            ; BDOS call on T&D FCB
  182.     inc    a            ; Error FF -> 0
  183.     ret    z            ; Return with Z if error
  184.     ld    a,(rwflag)        ; Check function
  185.     or    a
  186.     jr    z,openret        ; If reading, we can return now
  187.     ld    hl,tdfcb        ; Point to T&D FCB
  188.     ld    de,9            ; Offset to R/O attribute byte
  189.     add    hl,de
  190.     res    7,(hl)            ; Mark file R/W
  191.  
  192. attrset:                ; Entry point for setting file attrib.
  193.     ld    c,setatt
  194.     call    bdostd
  195.  
  196. openret:                ; Entry point for no attribute change
  197.     push    af            ; Save error flag
  198.     pop    af
  199.     inc    a            ; Error FF -> 0
  200.     ret
  201.  
  202. ;-----------------------------------------------------------------------------
  203.  
  204. ; Close time and date file.  We must be in user 0 when this is called.
  205. ;
  206. ; Entry:    nothing
  207. ; Exit:        Z is set if there is an error
  208.  
  209. tdclose:
  210.     ld    de,tdfcb        ; Get FCB pointer
  211.     ld    hl,9            ; Offset to R/O attribute byte
  212.     add    hl,de
  213.     set    7,(hl)            ; Set file to R/O for ATTRSET
  214.     ld    c,close            ; Close the file
  215.     call    bdostd
  216.     inc    a            ; Error code FF -> 0
  217.     ret    z            ; Return Z if error
  218.     jr    attrset            ; Set file attributes
  219.     ret
  220.  
  221. ;-----------------------------------------------------------------------------
  222.  
  223. ; Read or write a time and date sector.  This routine will change the DMA
  224. ; address, and the calling code must reset it.  Since the T&D file is never
  225. ; more than one extent, the code does not bother setting and resetting the
  226. ; user number.  On reading, the 15-byte time stamp string is copied to the
  227. ; buffer pointed to by HL on entry.  On writing, the contents of the buffer
  228. ; pointed to by HL are copied to the disk sector.
  229. ;
  230. ; On entry:    A=0 to read or A=FF to write
  231. ;        TDSECTOR and TDINDEX data must have been set up
  232. ;        T&D file must be open in R/W mode
  233. ;
  234. ; On exit:    T&D file is open
  235. ;        with reading, data is in buffer
  236. ;        on writing, data is in sector buffer
  237.  
  238. rwtd:
  239.     ld    (rwflag),a        ; Save the read/write flag
  240.     ld    de,tdfcb        ; Get FCB pointer
  241.     ld    hl,rndoff        ; Offset to random record value
  242.     add    hl,de
  243.     ld    de,(tdsector)        ; Get sector offset in T&D file
  244.     ld    (hl),e            ; Store it in FCB
  245.     inc    hl
  246.     ld    (hl),d
  247.     call    settddma        ; Set DMA for T&D operation
  248.     ld    c,readrnd        ; Read the sector
  249.     call    bdostd
  250.     or    a            ; Errors are > 0
  251.     jr    nz,rwerror
  252.     call    checksum        ; Compute the checksum
  253.     cp    (hl)            ; Is file OK?
  254.     jr    nz,rwerror
  255.     ld    a,(tdindex)        ; Get index into the sector
  256.     add    a,a            ; Multiply by 16
  257.     add    a,a
  258.     add    a,a
  259.     add    a,a
  260.     ld    hl,tdbuff        ; Address of start of buffer
  261.     add    a,l            ; Add offset
  262.     ld    l,a
  263.     jr    nc,rwtd1        ; If no carry, we are all set
  264.     inc    h            ; Otherwise increment H
  265. rwtd1:
  266.     ld    a,(rwflag)        ; See if read or write
  267.     or    a
  268.     jr    nz,rwtd2        ; If nonzero, we have more to do
  269.  
  270.         ; Reading date stamp
  271.  
  272.     ld    de,timestr        ; Get data buffer as destination
  273.     ld    bc,15            ; Bytes to copy
  274.     ldir
  275.     xor    a
  276.     inc    a            ; Make nonzero (since no error)
  277.     ret                ; ..and return (just reading)
  278. rwtd2:
  279.     ex    de,hl            ; DE is destination
  280.     ld    hl,timestr        ; Get pointer to data to write
  281.     ld    bc,15            ; Write 15 bytes
  282.     ldir
  283.     call    checksum        ; Compute the new checksum
  284.     ld    (hl),a            ; ..and store it in sector
  285.     ld    c,writernd        ; Write the sector out
  286.     call    bdostd
  287.     or    a            ; Check for error
  288.     jr    nz,rwerror
  289.     inc    a            ; Make A nonzero to show no error
  290.     ret
  291. rwerror:
  292.     xor    a            ; Make A zero to show error
  293.     ret
  294.  
  295. ;-----------------------------------------------------------------------------
  296.  
  297. ; Calculate the sector number in the T&D file and the index within that sector.
  298. ;
  299. ; Entry;    A = directory index for file
  300. ;        HL = sector index returned by DateStamper in DE
  301. ; Exit:        T&D sector number stored in TDSECTOR
  302. ;        T&D index stored in TDINDEX
  303.  
  304. setindex:
  305.     ld    b,a            ; Save directory index in B
  306.     or    a            ; Clear carry for arithmetic below
  307.     ld    a,h            ; Calculate HL/2
  308.     rra
  309.     ld    h,a
  310.     ld    a,l
  311.     rra
  312.     ld    l,a
  313.     ld    (tdsector),hl        ; Save T&D sector number
  314.     ld    a,b            ; Get partial index back
  315.     jr    nc,setindex1        ; If no carry, we are all set
  316.     add    a,4            ; If HL was odd, add 4 to offset
  317. setindex1:
  318.     ld    (tdindex),a        ; Store result
  319.     ret
  320.  
  321. ; End of ZFSUBS5.Z80
  322.