home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / cpm / utils / filutl / comp13.lbr / COMP13.AZM / COMP13.ASM
Encoding:
Assembly Source File  |  1987-10-30  |  9.3 KB  |  473 lines

  1. ;
  2. ; COMP13 ASM - CP/M file comparison program - 10/27/87
  3. ;
  4. VER    EQU    13        ; Current version number
  5. MONTH    EQU    10        ; Month last modified
  6. DAY    EQU    27        ; Day
  7. YEAR    EQU    87        ; Year
  8. ;
  9. ;    NOTE:    This program starts the display of any discrepancies
  10. ;        at page 1 (0100H) rather than at page 0 (0000H).  This
  11. ;        gives absolute addresses for normal CP/M files which
  12. ;        permits easy use of DDT or SID or an assembled print
  13. ;        copy to check the discrepancies.  Relative addresses
  14. ;        are relatively worthless for this purpose.
  15. ;
  16. ;        If for some reason you want relative addresses, change
  17. ;        the label area    RPRT1: INR H  to  RPRT1: DB 0  instead.
  18. ;        Then reassemble and reload.
  19. ;                    - Irv Hoff
  20. ;
  21. ;-----------------------------------------------------------------------
  22. ; 10/27/87  Fixed a incorrect address display.
  23. ;   v13     (Cleared register BC in initialization routine.)
  24. ;                    - Bill Duerr
  25. ;
  26. ; 05/06/85  Fixed a problem if the length of the two files are unequal.
  27. ;   v12     (Took the comment out of the "JMP  EOF" which made program
  28. ;        fall into SETUP routine).    - Bill Duerr
  29. ;
  30. ; 09/07/84  Fixed a major error.  Values for FILE1 and FILE2 were being
  31. ;   v11     exchanged on the display.  Changed to start display on page
  32. ;        1 (0100H) rather than page 0 (0000H).  Read note, above, for
  33. ;        reason.  Changed totals at end for characters checked and
  34. ;        number of errors encountered to read in decimal rather than
  35. ;        in hex, which was rather useless.  Added an equate to select
  36. ;        total columns in display (now set to 5 rather than 4.)  Some
  37. ;        other minor changes in the display.  Changed buffer size to
  38. ;        16k each rather than 1k.  (The disk system runs a fraction
  39. ;        as much, now.)  Re-enamed the program to COMP11, to protect
  40. ;        the original BINCOM version in case the author does not care
  41. ;        for these changes.    Alphabetized subroutines.  Rewrote the
  42. ;        help guide.  Standardized the format - the source code was
  43. ;        nearly all in lower case.    - Irv Hoff
  44. ;
  45. ; 09/16/83  Original version BINCOM.ASM - Harold McIntosh
  46. ;
  47. ;-----------------------------------------------------------------------
  48. ;
  49. ; COMP12 is a program which can be used to compare two CP/M files (which
  50. ; will usually binary .COM object code files) to find any differences
  51. ; between them.  The files are compared byte for byte.    No attempt is
  52. ; made to vary the match points to establish a different synchronization
  53. ; if a prolonged mismatch is found, as would be done for ASCII files
  54. ; when using DIF2, etc.
  55. ;
  56. ; The command line is:
  57. ;
  58. ;          COMP B:FILE1.COM A:FILE2.COM
  59. ;
  60. ; Discrepancies will be noted at the console in a line of the form:
  61. ;
  62. ;            XXXX YY ZZ
  63. ;
  64. ; where XXXX is the number of the discrepant byte, YY in FILE1, ZZ in
  65. ; FILE2.  Pressing any key at the console will stop the comparison, but
  66. ; in any event there will be a final total shown of the bytes compared
  67. ; and the number of mismatches encountered.
  68. ;
  69. ;-----------------------------------------------------------------------
  70. ;
  71. ; This program is modified from BINCOM.ASM written by Harold McIntosh
  72. ;
  73. ;        BINCOM.ASM  Copyright (C) 1983
  74. ;        Universidad Autonoma de Puebla
  75. ;              September 16, 1983
  76. ;
  77. ;=======================================================================
  78. ;
  79. LF    EQU    0AH        ; Line feed
  80. CR    EQU    0DH        ; Carriage return
  81. NOCLMN    EQU    5        ; Number of columns across page
  82. ;
  83. BDOS    EQU    0005H        ; Jump to BDOS
  84. TFCB    EQU    005CH        ; CCP's file control block
  85. TSIZ    EQU    0080H        ; Size of record buffer
  86. ;
  87.     ORG    0100H
  88. ;
  89. BEGIN:    LXI    H,0
  90.     DAD    SP
  91.     SHLD    STACK
  92.     LXI    SP,STACK
  93. ;
  94.     LXI    H,LOGO
  95.     CALL    MSSG
  96.     LDA    TFCB+1        ; File name
  97.     CPI    ' '
  98.     JZ    TUTO
  99.     CPI    '?'
  100.     JZ    TUTO
  101.     CALL    SETUP
  102.     MVI    C,15        ; Open file
  103.     LXI    D,FCB1
  104.     CALL    BDOS
  105.     INR    A
  106.     JZ    ERR1
  107.     MVI    C,15        ; Open file
  108.     LXI    D,FCB2
  109.     CALL    BDOS
  110.     INR    A
  111.     JZ    ERR2
  112.     XRA    A
  113.     STA    FCB1+32
  114.     STA    FCB2+32
  115.     STA    BYCT
  116.     STA    NEQL
  117.     INR    A
  118.     STA    RECT
  119.     MVI    A,NOCLMN
  120.     STA    CLMN
  121.     LXI    H,0000
  122.     PUSH    H
  123.     POP    B        ; Initialize "BC" to zeros
  124. ;
  125. LOOP:    LDA    BYCT
  126.     ANI    07FH
  127.     JNZ    RNB        ; Bytes in the buffer
  128.     LDA    RECT
  129.     DCR    A
  130.     JNZ    RNA
  131.     PUSH    B
  132.     LXI    B,0080H        ; 16k buffer
  133.     LXI    D,BUF1
  134.     LXI    H,FCB1
  135.     CALL    FILB
  136.     PUSH    B
  137.     LXI    B,0080H        ; 16k buffer
  138.     LXI    D,BUF2
  139.     LXI    H,FCB2
  140.     CALL    FILB
  141.     POP    PSW
  142.     CMP    B
  143.     JZ    EQL
  144.     LXI    H,NEQL
  145.     JC    NEQ
  146.     MOV    A,B
  147.     MVI    M,'2'
  148.     JMP    EQL
  149. ;
  150. NEQ:    MVI    M,'1'
  151. ;
  152. EQL:    POP    B
  153.     CPI    00
  154.     JZ    ENFI        ; End of record
  155.     LXI    D,BUF1
  156.     LXI    H,BUF2
  157. ;
  158. RNA:    STA    RECT
  159.     MVI    A,80H
  160. ;
  161. RNB:    DCR    A        ; Read next pair of bytes
  162.     STA    BYCT
  163.     LDAX    D
  164.     CMP    M
  165.     CNZ    RPRT        ; Report discrepancy
  166.     CALL    RECS
  167.     JNZ    QUIT
  168.     CALL    CHCNT
  169.     INX    B
  170.     INX    D
  171.     INX    H
  172.     JMP    LOOP
  173. ;
  174. ;=======================================================================
  175. ;
  176. ;                ROUTINES
  177. ;
  178. ; "A" to console
  179. ;
  180. AOUT:    PUSH    H
  181.     PUSH    D
  182.     PUSH    B
  183.     MOV    E,A
  184.     MVI    C,2
  185.     CALL    BDOS
  186.     POP    B
  187.     POP    D
  188.     POP    H
  189.     RET
  190. ;
  191. ; Character count
  192. ;
  193. CHCNT:    PUSH    H
  194.     LXI    H,ME11+5
  195.     JMP    COUNT
  196. ;
  197. ; Count events in decimal, by incrementing a buffer
  198. ;
  199. COUNT:    PUSH    D        ; Save the register values
  200.     PUSH    B
  201.     MVI    C,6
  202. ;
  203. COUNT1:    CALL    COUNT2        ; Increment the storage count
  204.     JNZ    COUNT4        ; Finished if not going any further
  205.     DCX    H
  206.     DCR    C
  207.     JNZ    COUNT1
  208.     JMP    COUNT4
  209. ;
  210. COUNT2:    MOV    A,M
  211.     CPI    ' '
  212.     JNZ    COUNT3
  213.     MVI    A,'0'
  214. ;
  215. COUNT3:    INR    A
  216.     MOV    M,A
  217.     CPI    '9'+1
  218.     RNZ
  219.     MVI    A,'0'
  220.     MOV    M,A
  221.     RET
  222. ;
  223. COUNT4:    POP    B
  224.     POP    D
  225.     POP    H
  226.     RET
  227. ;
  228. ENF:    CALL    MSSG
  229.     CALL    CRLF        ; Turn up an extra line
  230.     JMP    EXIT
  231. ;
  232. ; Error count
  233. ;
  234. ERCNT:    PUSH    H
  235.     LXI    H,ME22+5
  236.     JMP    COUNT
  237. ;
  238. ERR1:    LXI    H,ER1
  239.     JMP    CMSS
  240. ;
  241. ERR2:    LXI    H,ER2
  242.     JMP    CMSS
  243. ;
  244. EXIT:    LHLD    STACK
  245.     SPHL
  246.     RET
  247. ;
  248. ; Fill buffer DE using FCB HL. On return, B = number of sectors read.
  249. ;
  250. FILB:    PUSH    B
  251.     PUSH    D
  252.     PUSH    H
  253.     MVI    C,26        ; Set DMA address
  254.     CALL    BDOS
  255.     POP    D
  256.     PUSH    D
  257.     MVI    C,20        ; Read one record
  258.     CALL    BDOS
  259.     POP    D
  260.     POP    H
  261.     LXI    B,TSIZ
  262.     DAD    B
  263.     XCHG
  264.     POP    B
  265.     CPI    00
  266.     JNZ    FIC
  267.     INR    B
  268.     DCR    C
  269.     JNZ    FILB
  270.     RET
  271. ;
  272. FIC:    CPI    01
  273.     RZ
  274.     RET
  275. ;
  276. MOOV:    LDAX    D
  277.     MOV    M,A
  278.     INX    D
  279.     INX    H
  280.     DCR    B
  281.     JNZ    MOOV
  282.     LXI    D,-7
  283.     DAD    D
  284.     MOV    A,M
  285.     CPI    ' '
  286.     RNZ
  287.     MVI    M,'C'
  288.     INX    H
  289.     MVI    M,'O'
  290.     INX    H
  291.     MVI    M,'M'
  292.     RET
  293. ;
  294. ; Message terminated by zero to console
  295. ;
  296. MSSG:    MOV    A,M
  297.     ORA    A
  298.     RZ
  299.     CALL    AOUT        ; "A" to console
  300.     INX    H
  301.     JMP    MSSG
  302. ;
  303. ; Read console status: nz/z = character waiting/not
  304. ;
  305. RECS:    PUSH    B
  306.     PUSH    D
  307.     PUSH    H
  308.     MVI    C,11
  309.     CALL    BDOS
  310.     ANI    01
  311.     PUSH    PSW
  312.     JZ    RCS
  313.     MVI    C,1
  314.     CALL    BDOS
  315. ;
  316. RCS:    POP    PSW
  317.     POP    H
  318.     POP    D
  319.     POP    B
  320.     RET
  321. ;
  322. ; Type discrepancy report.
  323. ;
  324. RPRT:    PUSH    H        ; Save address
  325.     PUSH    B        ; Save record count
  326.     CALL    ERCNT        ; Increment the error count
  327.     POP    H        ; Get "BC" into "HL"
  328. ;
  329. RPRT1:    INR    H        ; Output starts on page 1 (0100H)
  330.     CALL    WORD
  331.     CALL    DUBL
  332.     LDAX    D        ; Show FILE1 byte
  333.     CALL    BYTE
  334.     CALL    SNGL
  335.     POP    H        ; Get original address back
  336.     MOV    A,M        ; Show FILE2 byte
  337.     CALL    BYTE
  338. ;;;;    CALL    SNGL
  339.     CALL    QUAD
  340.     LDA    CLMN
  341.     DCR    A
  342.     JNZ    RPR
  343.     CALL    CRLF
  344.     MVI    A,NOCLMN
  345. ;
  346. RPR:    STA    CLMN
  347.     RET
  348. ;
  349. ; Type one, two, or four spaces.
  350. ;
  351. QUAD:    CALL    DUBL        ; Sends two spaces
  352. DUBL:    CALL    SNGL        ; Sends a space, then the next below
  353. SNGL:    MVI    A,' '        ; Sends a space
  354.     JMP    AOUT
  355. ;
  356. ; Type summary message at the end of the run.
  357. ;
  358. QUIT:    CALL    CRLF
  359.     LXI    H,ME3
  360.     CALL    MSSG
  361. ;
  362. ENFI:    PUSH    B        ; Save the number of bytes counted
  363.     CALL    CRLF
  364.     LXI    H,ME1
  365.     CALL    MSSG
  366.     LXI    H,ME2
  367.     CALL    MSSG
  368.     LDA    NEQL
  369.     ORA    A
  370.     JZ    EXIT
  371. ;
  372.     LXI    H,ME4
  373.     CALL    MSSG
  374.     LXI    H,FCB1+1    ; Address of first file
  375.     LDA    NEQL        ; Get back length indicator
  376.     CPI    '1'        ; If first was shorter, exit
  377.     JZ    ENF        ; If not, get.
  378.     LXI    H,FCB2+1    ; Address of second file
  379.     JMP    ENF
  380. ;
  381. SETUP:    MVI    B,16
  382.     LXI    D,TFCB
  383.     LXI    H,FCB1
  384.     CALL    MOOV
  385.     LXI    H,ME5
  386.     CALL    MSSG
  387.     LXI    H,FCB1+1
  388.     CALL    MSSG
  389.     CALL    CRLF
  390.     MVI    B,16
  391.     LXI    D,TFCB+16
  392.     LXI    H,FCB2
  393.     CALL    MOOV
  394.     LXI    H,ME6
  395.     CALL    MSSG
  396.     LXI    H,FCB2+1
  397.     CALL    MSSG
  398.     CALL    CRLF        ; Fall through
  399. ;
  400. ; Send CR,LF
  401. ;
  402. CRLF:    MVI    A,CR
  403.     CALL    AOUT        ; "A" to console
  404.     MVI    A,LF
  405.     JMP    AOUT        ; "A" to console
  406. ;
  407. TUTO:    LXI    H,SCRP
  408. ;
  409. CMSS:    CALL    MSSG
  410.     JMP    EXIT
  411. ;
  412. ; Type A as two nibbles
  413. ;
  414. WORD:    MOV    A,H
  415.     CALL    BYTE
  416.     MOV    A,L
  417. ;
  418. BYTE:    PUSH    PSW
  419.     RAR
  420.     RAR
  421.     RAR
  422.     RAR
  423.     CALL    NYBL
  424.     POP    PSW
  425. ;
  426. NYBL:    ANI    0FH
  427.     ADI    90H
  428.     DAA
  429.     ACI    40H
  430.     DAA
  431.     JMP    AOUT        ; "A" to console
  432. ;
  433. ;-----------------------------------------------------------------------
  434. ;
  435. LOGO:    DB    'COMP Version ',VER / 10 + '0','.',VER    MOD 10 + '0',' -- '
  436.     DB    MONTH/10+'0',MONTH MOD 10+'0','/'
  437.     DB    DAY/10+'0',DAY MOD 10+'0','/'
  438.     DB    YEAR/10+'0',YEAR MOD 10+'0',CR,LF,CR,LF,0
  439. ER1:    DB    '++ Cannot open first file ++',CR,LF,0
  440. ER2:    DB    '++ Cannot open second file ++',CR,LF,0
  441. ME1:    DB    CR,LF,'Number of bytes compared  : '
  442. ME11:    DB    '     0',CR,LF,0
  443. ME2:    DB    'Number of mismatches found: '
  444. ME22:    DB    '     0',CR,LF,0
  445. ME3:    DB    CR,LF,'Comparison interrupted.',0
  446. ME4:    DB    CR,LF,'Shorter of the two is: ',0
  447. ME5:    DB    'File 1:  ',0
  448. ME6:    DB    'File 2:  ',0
  449. ;
  450. SCRP:    DB    'Compares the length and content of two files (usually .COM',CR,LF
  451.     DB    'files).  Mismatches, along with the address are displayed.',CR,LF
  452.     DB    CR,LF,'To use:',CR,LF,CR,LF
  453.     DB    '      B>COMP FILE1.COM A:FILE2.COM',CR,LF,CR,LF
  454. ;
  455. FCB1:    DS    33
  456. FCB2:    DS    33
  457. BYCT:    DS    1        ; Byte count
  458. RECT:    DS    1        ; Record count
  459. NEQL:    DS    1        ; FF=different file lengths
  460. CLMN:    DS    1        ; Column counter
  461. BORG:    DS    2
  462.     DS    32        ; Minimum stack size
  463. ;
  464. EVEN    EQU    ($+256-1)/256*256 ; To start on an even page
  465. ;
  466.     ORG    EVEN
  467. ;
  468. STACK    EQU    EVEN-2        ; Save two bytes for original CCP return
  469. BUF1:    DS    4000H        ; 16k buffer
  470. BUF2:    DS    4000H        ; 16k buffer
  471. ;
  472.     END
  473. ╨