home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / lambda / utils / fixt-d.lbr / FIXT&D.ASM next >
Assembly Source File  |  1993-10-25  |  4KB  |  185 lines

  1.     title    FIXT&D.ASM
  2.  
  3. vers    equ    0
  4. rev    equ    2
  5.  
  6. ; vers 0.2
  7. ; Bridger Mitchell, 7/18/89
  8. ; vers 0.1
  9. ; Al Hawley, 10 Apr 89
  10. ; Ladera Z-Node, (213) 670-9465
  11.  
  12. ; Quick & dirty pgm to recalculate, verify,
  13. ; and if incorrect and store the checksum bytes in a !!!TIME&.DAT file.
  14. ;
  15. ;======================================================
  16.  
  17. ;External references:
  18.  
  19. ;for versions of SYSLIB that are limited to 6 char symbols
  20. ;and if your assembler emits >6 char symbols
  21. ; note strange bug in SLR assembler:
  22. ; a ".request " line cannot contain a comment! 
  23. ; for SLR format:
  24.     .request syslibs
  25. ; for MS format:
  26. ;    .request syslib
  27.  
  28. ;    ext    r$read,r$writ,f$open,f$clos,print,padc
  29.  
  30. ;for SYSLIB versions which use 7 char symbols,use:
  31.     ext    r$read,r$write,f$open,f$close,print,padc
  32. ;
  33. ;and change the calls to these routines accordingly
  34.  
  35. ;======================================================
  36. ;data definitions
  37.  
  38. dfcb    equ    5ch
  39. tbuf    equ    80h
  40. bdos    equ    0005h
  41. cr    equ    0dh
  42. lf    equ    0ah
  43. ;======================================================
  44. ;start of pgm code. Symbols are public only for use
  45. ;by a symbolic debugger like DSD or ZSID or Z8E
  46.  
  47. start::    ld    (stack),sp
  48.     ld    sp,stack
  49.     call    signon
  50.     ld    a,(dfcb+1)    ; check for help or drive:
  51.     cp    '/'
  52.     jp    z,help
  53.     ld    a,(dfcb)
  54.     or    a
  55.     jr    z,go        ; ..default drive
  56.     ld    (tdfcb),a    ; set explicit drive
  57. ;
  58. go::    ld    e,0FFh        ; save user #
  59.     call    user
  60.     ld    (origusr),a
  61.     ld    e,0        ; set user #0
  62.     call    user
  63.     xor    a        ; initialize
  64.     ld    (count),a
  65.     ld    de,tdfcb    ;open the file
  66.     call    f$open        ;de is assumed preserved in all routines
  67.     ld    hl,tdfcb+9
  68.     res    7,(hl)        ; set file r/w
  69.     ld    c,30
  70.     call    xbdos
  71.     ld    a,(rc)        ;size of the !!!TIME&.DAT file
  72.     ld    b,a        ;..in B for stepping through the file
  73.     ld    c,0        ; initialize counter
  74. ;
  75. ;for recs 0-(B-1), adjust the checsum for each record
  76. rrloop::
  77.     push    bc
  78.     call    r$read        ;read a record to tbuf
  79.     jr    nz,finish
  80.     call    docsum        ;calculate & store 127 byte cksum
  81.     jr    z,ok
  82.     ld    hl,(rrecno)    ;bump the random record number
  83.     call    r$write        ;restore the record to the file
  84.     pop    bc
  85.     push    bc
  86.     ld    a,c        ; get sector #
  87.     call    sayfixed
  88. ok::    ld    hl,(rrecno)    ;bump the random record number
  89.     inc    hl
  90.     ld    (rrecno),hl
  91.  
  92.     pop    bc
  93.     inc    c        ; bump counter
  94.     djnz    rrloop
  95.  
  96. finish::
  97.     call    f$close        ;close the file
  98.     ld    hl,tdfcb+9
  99.     set    7,(hl)        ; set r/o
  100.     ld    c,30
  101.     call    xbdos
  102.     ld    a,(count)
  103.     or    a,a
  104.     call    z,saynone
  105.     ld    a,(origusr)    ; restore user #
  106.     ld    e,a
  107.     call    user
  108. ;
  109. exit::    ld    sp,(stack)
  110.     ret            ;return to CCP quietly.
  111.  
  112. ;======================================================
  113. signon::
  114.     call    print
  115.     db    cr,lf,'FIXT&D v. '
  116. vbyte:    db    vers+'0','.',rev+'0'
  117.     db    ' - verify/correct the checksums in !!!TIME&.DAT file.',0
  118.     ret
  119.  
  120. sayfixed::
  121.     push    af
  122.     call    print
  123.     db    cr,lf,'fixed T&D record #',0
  124.     pop    af
  125.     call    padc
  126.     ld    hl,count
  127.     inc    (hl)
  128.     ret
  129.  
  130. saynone::
  131.     call    print
  132.     db    cr,lf,'No changes required.',0
  133.     ret
  134.  
  135. help::
  136.     call    print
  137.     db    cr,lf,'  usage:  FIXT&D [d:]'
  138.     db    cr,lf,'  to verify and correct checksums on drive [d:]',0
  139.     jp    exit
  140.  
  141. ;routine to calculate checksum for one record (128 bytes)
  142. ; return Z if ok, else update, return NZ 
  143.  
  144. docsum::    ;cksum first 127 bytes, store in 128th byte
  145.     ld    hl,tbuf        ;where the record exists
  146.     ld    b,127
  147.     xor    a        ;initial val for cksum
  148. csloop::
  149.     add    (hl)        ;accumulate the checksum
  150.     inc    hl        ;bump the pointer
  151.     djnz    csloop
  152.     cp    a,(hl)        ; if matches stored value
  153.     ret    z        ; ..return ok
  154.     ld    (hl),a        ; else update the checksum byte
  155.     ret
  156.  
  157. user::    ld    c,32
  158. xbdos::    push    de
  159.     call    bdos
  160.     pop    de
  161.     ret    
  162.  
  163. ;======================================================
  164. ;    DATA AREA
  165.  
  166. tdfcb::    ds    1,0        ;uses default user
  167.     db    '!!!TIME&DAT'    ;11 character file name&typ
  168.     ds    3        ;ext,user,data module number
  169. rc::    ds    1
  170.     ds    16,0        ;allocation map
  171.     ds    1        ;current record
  172. rrecno::ds    3,0
  173.  
  174. count::    ds    1
  175.  
  176. origusr::ds    1
  177.  
  178. ;======================================================
  179.  
  180. stktop::    ds    50
  181. stack::    ds    2
  182.  
  183.     end
  184. nt
  185.     db    cr,lf,'  usage:  FIXT&D [d:]