home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / jsage / znode3 / uploads / sdiff15.lbr / SDIFF15.ZZ0 / SDIFF15.Z80
Encoding:
Text File  |  1992-06-28  |  11.3 KB  |  655 lines

  1. ; Program: SDIFF - Size Difference
  2. ; Author:  Rob Friefeld
  3. ; Version: 1.5
  4. ; Date:    28 Jun 1992
  5.  
  6. .comment \
  7.  
  8. Displays file size in records, kbytes and bytes.
  9. If two files named, shows size difference in bytes.
  10. Byte count does not include any trailing 0's or ^Z's.
  11. Byte count OK to 65534 record file size.
  12.  
  13. Version 1.5 (Rob Friefeld)                      6/28/92
  14.     Corrected error in decimal output routine.
  15.     New COUT routine in v1.4 did not filter high bits.
  16.     Under CP/M, user number is not displayed.
  17.  
  18.  
  19. Version 1.4 release by Bruce Morgen        6/17/92
  20.     Altered help screen to reflect whether
  21.     "DU:|DIR:" or only "D:" will work in the current
  22.     environment as suggested by Howard Goldstein.
  23.  
  24. Version 1.4 beta by Bruce Morgen        6/2/92
  25.     Fixed program so it would run sensibly under
  26.     non-ZCPR3 systems, albeit sans DU: support.
  27.     Shortened and simplified code in several
  28.     places to cut a record from the COMfile size.
  29.     Altered filename display to show both DU: and
  30.     DIR: when appropriate.  Made source M80-
  31.     compatible for the SLR/ZMAC-impaired.
  32.  
  33. Version 1.3
  34.     Uses more elegant decimal conversion routine
  35.     adapted from Gene Pizzetta's work on ZSLIB36.
  36.     Size is about the same as "brute force" method.
  37.  
  38. Version 1.2
  39.     Byte count does not include trailing ^Z's.
  40.     Accepts afn on command line.
  41.  
  42. Version 1.1
  43.     More robust command line parsing, thanks to warnings from
  44.     Howard Goldstein.
  45.  
  46. \
  47.  
  48. ; -----    Externals ---------------
  49.  
  50.  
  51.     .request b24tdc
  52.     ext    b24tdc        ; Convert 24-bit quantity to ASCII decimal
  53.  
  54.     .request z3lib,syslib
  55.     ext    z3init,dutdir
  56.     ext    retud,logud,initfcb,bdos
  57.     ext    phldc,pafdc
  58.  
  59.     public    cout,cout7    ; Internal routines use BDOS
  60.  
  61.  
  62. ; -----    Equates -----------------
  63.  
  64. vers    equ    15
  65.  
  66. bdose    equ    5
  67. fcb1    equ    5ch
  68. fcb2    equ    6ch
  69. tbuf    equ    80h
  70. sfirst    equ    17
  71.  
  72. bell    equ    7
  73. cr    equ    0dh
  74. lf    equ    0ah
  75.  
  76.  
  77. ; Move 3 byte quantity
  78. mov24    macro    dest,src
  79.     exx
  80.     ld    hl,src
  81.     ld    de,dest
  82.     ld    bc,3
  83.     ldir
  84.     exx
  85.     endm
  86.  
  87.  
  88. ; -----    Type 1 Header -----------
  89.  
  90. entry:
  91.     jp    start
  92.     db    'Z3ENV',1
  93. z3eadr:    dw    0
  94.  
  95.  
  96. ; -----    Program Start -----------
  97.  
  98. start:
  99.     sub    a        ; Test for z80 cpu
  100.     jp    pe,notz80    ; 8080, 8085 set parity flag Even
  101.  
  102.     ld    (stack),sp
  103.     ld    sp,stack
  104.  
  105. ; -----    Inits -------------------
  106.  
  107.     ld    hl,(z3eadr)    ; ENV address installed?
  108.     ld    a,h
  109.     or    l
  110.     ld    (zcprflg),a    ; If not, don't call DUTDIR later.
  111.  
  112.     call    Z3INIT
  113.  
  114.  
  115. ; -----    Command Line Parse ------
  116.  
  117. optchk:
  118.     ld    hl,(fcb1+1)
  119.     ld    a,l
  120.     ld    de,'//'
  121.     sbc    hl,de        ; carry already clear from above
  122.     jr    z,jzinfo    ; // = help
  123.     
  124.     cp    ' '        ; FCB1 blank?
  125. jzinfo:    jp    z,info        ; No file name
  126.  
  127.  
  128. ; -----    Init file system --------
  129.  
  130. ; Command line possibilities are:
  131. ;    1 filespec     (where filespec = [du|dir]afn) 
  132. ;    2 filespecs
  133. ;    1 filespec and 2nd DU only
  134.  
  135. file_init:
  136.     ld    de,fcb1        ; Extract DU from FCB1
  137.     call    ducvrt
  138.     ld    (du1),bc
  139.  
  140.     ld    e,fcb2        ; Extract DU from FCB2 (D =0)
  141.     call    ducvrt
  142.     ld    (du2),bc
  143.     ld    hl,tbuf        ; Point to TBUFF character count
  144.     ld    b,h        ; B = H = 0
  145.     ld    c,(hl)        ; Count in BC
  146.     add    hl,bc        ; Point to last character
  147.     ld    c,b        ; C = B = 0
  148. endlp:    ld    a,(hl)        ; Get character
  149.     dec    hl        ; Point to previous one
  150.     cp    ' '+1        ; Blank or control character?
  151.     jr    c,endlp        ; Loop if so
  152.     cp    ':'        ; Make a colon a 255, else zero
  153.     jr    nz,colon
  154.     dec    c        ; Result of colon search in C
  155. colon:    inc    de        ; If no file2 name, copy 1st name
  156.     ld    a,(de)
  157.     sub    ' '
  158.     push    af        ; save 2nd file result on stack
  159.     jr    nz,got2
  160.     or    c        ; Result of colon search in C
  161. got2:    ld    (fflag),a    ; Set files flag, Z = 1 file  NZ = 2 files
  162.     pop    af
  163.     jr    nz,finit1    ; 2nd name was entered
  164.     ld    l,fcb1+1    ; H = 0
  165.     ld    c,11        ; B = 0
  166.     ldir
  167. finit1:
  168.     ld    l,fcb2+1    ; Keep 2nd file name (H =0)
  169.     ld    de,fbuf
  170.     ld    c,11        ; B = 0
  171.     ldir
  172.  
  173.  
  174. ; -----    Main --------------------
  175.  
  176. sdiff:
  177.     call    logdu1        ; Log in 1st file du
  178.     call    pentry        ; Print it's info
  179.     mov24    b1,bcount    ; Save byte count for comparison
  180.     call    print24bq    ; Print byte count
  181.  
  182.     ld    a,(fflag)    ; 2 files?
  183.     or    a
  184.     jp    z,exit        ; No, done
  185.     
  186.     ld    hl,fbuf        ; Recover 2nd file name
  187.     ld    bc,11
  188.     ld    de,fcb1+1
  189.     ldir
  190.     call    logdu2        ; Log in 2nd file DU
  191.     call    pentry        ; Print it's stuff
  192.     mov24    b2,bcount
  193.     call    print24bq
  194.  
  195.     call    print
  196.     dc    cr,lf,lf,'      Difference:'
  197.  
  198.     mov24    bcount,b2    ; Subtract byte counts
  199.     ld    hl,b1
  200.     ld    de,bcount
  201.     call    sub24bq
  202.     jr    nc,sdiff2    ; F2-F1 >= 0
  203.     mov24    bcount,b1    ; Else, reverse subtraction
  204.     ld    hl,b2
  205.     call    sub24bq
  206. sdiff2:
  207.     call    print24bq
  208.     jp    exit
  209.  
  210.  
  211. ; -----    Print info for file -----
  212.  
  213. pentry:
  214.     ld    de,fcb1
  215.     call    wildcvrt    ; Convert possible afn
  216.  
  217.     call    crlf
  218.     call    pfile        ; Print file name
  219.     call    crlf
  220.     call    readend        ; Read last record
  221.     jr    nz,filesize
  222.     jp    nofile        ; Bad read
  223.  
  224.  
  225. ; ----- Read last record 
  226.  
  227. ; EXIT: Z if no file
  228. ;
  229. ; DOS Function 23H is used. It returns the record number after the last
  230. ; record of the file in FCB+21H. If the last record was 0FFFFh, an ovfl
  231. ; bit is set. This routine does not make use of that fact.
  232.  
  233. readend:
  234.     ld    de,fcb1        ; Init FCB1
  235.     call    INITFCB
  236.  
  237.     ld    c,0fh        ; Open file
  238.     call    BDOS
  239.     inc    a
  240.     ret    z        ; Couldn't open for some reason
  241.  
  242.     ld    c,23h        ; Get end address
  243.     call    BDOS
  244.     ld    hl,(7dh)    ; Record past end
  245.     ld    (recnt),hl
  246.     dec    hl        ; -1
  247.     ld    (7dh),hl    ; ..now last record
  248.     ld    c,21h        ; Read random
  249.     call    BDOS
  250.     ld    c,10h        ; Close file
  251.     call    BDOS
  252.     or    -1        ; Ret NZ
  253.     ret
  254.  
  255.  
  256. ; ----- Display file size
  257.  
  258. filesize:
  259.     ld    hl,bcount    ; Init byte count
  260.     xor    a
  261.     ld    b,3
  262.     ld    (hl),a
  263.     inc    hl
  264.     djnz    $-2
  265.  
  266.     ld    hl,(recnt)    ; Get file end address
  267.     ld    a,h        ; If 0 length or 8meg, this will be 0
  268.     or    l
  269.     jr    z,filemin
  270.  
  271.     call    PHLDC        ; Print RECORDS
  272.     call    print
  273.     dc    ' Rec'
  274.  
  275.     ld    e,0        ; Compute KBYTES (HL was saved)
  276.     ld    b,3        ; /8
  277. files2:
  278.     srl    h        ; /2
  279.     rr    l
  280.     rr    e        ; Track CY
  281.     djnz    files2
  282. files3:
  283.     ld    a,h        ; Less than 1k?
  284.     or    l
  285.     jr    z,files5
  286.  
  287.     xor    a
  288.     cp    e
  289.     jr    z,files4
  290.     inc    hl
  291. files4:
  292.     call    PHLDC        ; Print KBYTES
  293.     call    print
  294.     dc    'k'
  295.     jr    files6
  296. files5:
  297.     call    print
  298.     dc    '   <1k'
  299.     jr    files6
  300.  
  301. filemin:
  302.     ld    a,(recnt+2)    ; Check ovfl
  303.     or    a
  304.     jr    nz,filemax
  305.     call    print
  306.     dc    '   0 length file.'
  307.     ret
  308. filemax:
  309.     call    print
  310.     dc    ' 8 megabyte file.'
  311.     ret
  312.  
  313. files6:
  314.     call    print
  315.     dc    '  '
  316.  
  317. ; Compute byte count from # records and examination of last record
  318.  
  319. getbytes:
  320.     ld    hl,tbuf+80h    ; Point to end of last record
  321.     ld    b,80h
  322. gbytes1:
  323.     dec    hl        ; Now backscan for nulls or ^Z's
  324.     ld    a,(hl)
  325.     or    a
  326.     jr    z,gbytes2
  327.     cp    'Z'-'@'
  328.     jr    nz,saveby
  329. gbytes2:
  330.     djnz    gbytes1
  331.  
  332. saveby:
  333.     ld    a,b        ; Count of terminal 0's
  334.     ld    hl,(recnt)    ; Convert records to bytes (*128)
  335.     dec    hl        ; Compute 1 less
  336.     or    a        ; Clear CY
  337.     ld    bc,7*256+0    ; 2**7 in B, mult ovfl in C
  338. savebylp:
  339.     sla    l
  340.     rl    h
  341.     rl    c        ; If CY, move it into C
  342.     djnz    savebylp
  343.  
  344.     add    a,l        ; Now add back portion of last rec filled
  345.     ld    l,a
  346.     ld    a,b        ; A = B = 0
  347.     adc    a,h
  348.     ld    h,a
  349.     ld    a,b        ; A = B = 0
  350.     adc    a,c
  351.     ld    (bcount),hl    ; Save 24-bit count
  352.     ld    (bcount+2),a    ; High byte
  353.     ret
  354.  
  355.  
  356. ; -----    Exits -------------------
  357.  
  358. info:
  359.     call    print
  360.     db    'SDIFF, Vers ',vers/10+'0','.',vers mod 10+'0'
  361.     db    ' - Show Size Difference of Two Files',cr,lf
  362.     dc    ' Syntax:  SDIFF [d'
  363.     call    zdudir
  364.     call    print
  365.     dc    ':]ufn1 [d'
  366.     call    zdudir
  367.     call    print
  368.     dc    ':][ufn2]'
  369. exit:
  370.     call    crlf
  371.     ld    sp,(stack)
  372.     ret
  373.  
  374. zdudir:
  375.     ld    a,(zcprflg)
  376.     or    a
  377.     ret    z
  378.     call    print
  379.     dc    'u|dir'
  380.     ret
  381.  
  382. nofile:
  383.     call    print
  384.     dc    '  No file'
  385.     jr    exit
  386.  
  387.  
  388. notz80:    ld    de,nz80msg
  389.     ld    c,9        ; Bdos print function
  390.     jp    bdose        ; Exit with a return to ccp from dos
  391. nz80msg:
  392.     db    'Need Z80/Z180 CPU$'
  393.  
  394.  
  395. ; -----    Print 24-bit Number -----
  396.  
  397. print24bq:
  398.     ld    hl,bcount    ; 3 byte number
  399.     ld    de,asbuf    ; ASCII string destination
  400.     call    B24TDC        ; Convert number
  401.     call    print24        ; Print string, formatted
  402.     call    print
  403.     dc    ' bytes'
  404.     ret
  405.  
  406.  
  407. ; Print 8 digit ASCII string
  408. ;  Output is right justified in 10 char field:  dd,ddd,ddd
  409. ;  Enter: DE -> string
  410.  
  411. print24:
  412.     push    hl
  413.     push    de
  414.     push    bc
  415.  
  416.     ex    de,hl        ; HL -> string
  417.     ld    bc,7*256+0    ; Loop through 7 digits; C is 0 suppression flg
  418. p24loop:
  419.     ld    a,(hl)
  420.     call    printdec
  421.     ld    a,b        ; Print "," when B = 6,3
  422.     cp    6
  423.     call    z,comma
  424.     cp    3
  425.     call    z,comma
  426.     inc    hl
  427.     djnz    p24loop
  428.     ld    a,(hl)
  429.     pop    bc
  430.     pop    de
  431.     pop    hl
  432.     jr    chrout        ; Print 8th digit no matter what,
  433.                 ; then return to caller.
  434.  
  435. ; Print ASCII digit in A. Print space if leading '0'.
  436. ;   C = '0' suppression flag (Z = ON)
  437.  
  438. printdec:
  439.     cp    '0'        ; Print digit <> '0'
  440.     jr    nz,printdec1
  441.     inc    c        ; Else, check suppression flag first
  442.     dec    c
  443.     jr    z,comma1    ; Flag ON, print space
  444. printdec1:
  445.     inc    c        ; Make suppression flag NZ
  446.     jr    chrout
  447.     
  448. ;  Print comma if suppression flag off, else print space
  449.  
  450. comma:    xor    a
  451.     or    c
  452.     ld    a,','
  453.     jr    nz,chrout
  454. comma1:
  455.     ld    a,' '
  456. chrout:    jp    cout7
  457.  
  458.  
  459. ;
  460. ; Subtract one 24-bit quantity from another. Store result in subtrahend.
  461. ;   Entry:  HL -> minuend
  462. ;        DE -> subtrahend - remainder
  463.  
  464. sub24bq:
  465.     push    hl
  466.     push    de
  467.     push    bc
  468.     ld    b,3
  469.     xor    a
  470. s24lp:
  471.     ld    a,(de)
  472.     sbc    a,(hl)
  473.     ld    (de),a
  474.     inc    de
  475.     inc    hl
  476.     djnz    s24lp
  477.     pop    bc
  478.     pop    de
  479.     pop    hl
  480.     ret
  481.  
  482.  
  483. ; Log in 1st user/disk
  484. ;
  485. logdu1:    ld    bc,(du1)
  486.     jr    jlogud
  487. ;
  488. ; Log in 2nd user/disk
  489. ;
  490. logdu2:    ld    bc,(du2)
  491. jlogud:    jp    LOGUD
  492.  
  493.  
  494. ; ----- Convert DU
  495.  
  496. ; Convert Z3FCB DU into DU in BC
  497. ;
  498. ; Enter:  DE -> fcb
  499. ; Exit:   BC = DU
  500. ; Uses:   BC,AF 
  501.  
  502. ducvrt:
  503.     call    RETUD        ; Get current disk/user
  504.     ld    a,(zcprflg)
  505.     or    a
  506.     jr    z,ducv1        ; only Z3 has user at code FCB+13
  507.     push    hl
  508.     ld    hl,13
  509.     add    hl,de
  510.     ld    c,(hl)        ; User
  511.     pop    hl
  512. ducv1:    ld    a,(de)        ; Drive
  513.     dec    a
  514.     ret    m
  515.     ld    b,a
  516.     ret
  517.  
  518. ; WILDCVRT - convert afn to first match ufn (assumes DOS DMA = 80h)
  519. ;
  520. ; Enter: DE -> afn fcb
  521. ; Exit:  Z flag set if error
  522. ; Uses:  AF,HL,BC
  523.  
  524. wildcvrt:
  525.     push    hl
  526.     push    bc
  527.  
  528.     ld    c,sfirst
  529.     call    BDOS
  530.     cp    0ffh
  531.     jr    z,wldcx        ; Nothing found -- error
  532.  
  533.     push    de        ; Move name to .DE+1
  534.     inc    de
  535.     rrca
  536.     rrca
  537.     rrca
  538.     add    a,81h
  539.     ld    l,a
  540.     ld    bc,11        ; Move 11 chars
  541.     ld    h,b
  542.     ldir
  543.     pop    de
  544. wldcx:    pop    bc
  545.     pop    hl
  546.     ret
  547.  
  548.  
  549. ; -----    Print File Name
  550.  
  551. pfile:
  552.     call    RETUD        ; Get logged DU
  553.     ld    a,b        ; Drive in B 0..15
  554.     add    a,'A'
  555.     call    cout7
  556.     ld    a,(zcprflg)    ; If no ZCPR, don't print user
  557.     or    a
  558.     jr    z,pfile3
  559.     ld    a,c        ; User in C
  560.     call    PAFDC
  561.     call    DUTDIR        ; Is there an NDR entry for this DU?
  562.     jr    z,pfile3    ; No
  563. pfile2:
  564.     call    print        ; DU/DIR divider
  565.     dc    '/'
  566.     call    pfile4
  567. pfile3:
  568.     call    print
  569.     dc    ':'
  570.     ld    hl,fcb1+1    ; Point to file name
  571.     call    pfile4        ; Print FILENAME
  572.     ld    a,(hl)        ; Quit if no TYP
  573.     cp    ' '
  574.     ret    z
  575.     call    print
  576.     dc    '.'
  577.     ld    b,3
  578.     jr    pfile4a
  579.  
  580. pfile4:
  581.     ld    b,8        ; Loop counter
  582. pfile4a:
  583.     ld    a,(hl)        ; Print non-blanks
  584.     inc    hl
  585.     cp    ' '
  586.     call    nz,cout7
  587.     djnz    pfile4a
  588.     ret
  589.  
  590.  
  591. ; -----    Console Output
  592.  
  593. cout7:
  594.     push    af
  595.     and    7fh
  596.     jr    cout1
  597. cout:                ; Print char in A
  598.     push    af
  599. cout1:    push    hl
  600.     push    de
  601.     push    bc
  602.     ld    e,a
  603.     ld    c,6        ; Use BDOS function
  604.     call    bdose
  605.     pop    bc
  606.     pop    de
  607.     pop    hl
  608.     pop    af
  609.     ret
  610.  
  611.  
  612. ; -----    In-line string print
  613.  
  614. print:
  615.     ex    (sp),hl
  616.     ld    a,(hl)
  617.     inc    hl
  618.     ex    (sp),hl
  619.     or    a
  620.     ret    z
  621.     call    cout7
  622.     ret    m
  623.     jr    print
  624.  
  625.  
  626. crlf:
  627.     call    print
  628.     dc    cr,lf
  629.     ret
  630.     
  631.  
  632. ; -----    Data --------------------
  633.  
  634.     dseg
  635.  
  636.     ds    60    ; Stack
  637. stack:    ds    2
  638.  
  639. zcprflg:
  640.     ds    1    ; ZCPR running flag
  641. du1:    ds    2    ; DU for file 1
  642. du2:    ds    2    ; DU for file 2
  643. fbuf:    ds    11    ; File name storage
  644. fflag:    ds    1    ; Files flag
  645.  
  646. recnt:    ds    2    ; Temp - record count
  647. freeby:    ds    1    ; Free bytes
  648. bcount:    ds    3    ; 24-bit byte count
  649. b1:    ds    3    ; File 1 count
  650. b2:    ds    3    ; File 2 count
  651. asbuf:    ds    8    ; Decimal count ASCII string
  652.  
  653.     end
  654.  
  655.