home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / sigm / vol165 / bincom.asn < prev    next >
Encoding:
Text File  |  1984-07-09  |  6.7 KB  |  395 lines

  1.  
  2.  
  3. ;    --------------------------------------------------------
  4. ;    BINCOM.CMD is a program which can be used to compare
  5. ;    two files, which will probably be binary, to find the
  6. ;    differences between them. The files are compared byte
  7. ;    for byte. No attempt is made to vary the match points
  8. ;    to establish a different synchronization if a prolonged
  9. ;    mismatch is found, as would be done for ASCII files.
  10. ;    The command line is:
  11. ;
  12. ;          BINCOM [X:]FILE1.CMD,[Y:]FILE2.CMD
  13. ;
  14. ;    Discrepancies will be noted at the console in a line
  15. ;    of the form
  16. ;            XXXX YY ZZ
  17. ;    where XXXX is the number of the discrepant byte, YY in
  18. ;    FILE1 but ZZ in FILE2. Pressing any key at the console
  19. ;    will stop the comparison, but in any event there will
  20. ;    be a final total shown of the bytes compared and the
  21. ;    number of mismatches encountered.
  22. ;
  23. ;            BINCOM.ASN  Copyright (C) 1983
  24. ;            Universidad Autonoma de Puebla
  25. ;              September 16, 1983
  26. ;
  27. ;    [Harold    V. McIntosh, 16 September 1983]
  28. ;    --------------------------------------------------------
  29.  
  30.  
  31. LF    EQU    0AH        ;line feed
  32. CR    EQU    0DH        ;carriage return
  33.  
  34. BDOS    EQU    224        ;CP/M interrupt to BDOS
  35.  
  36. TFCB    EQU    005CH        ;DDT's file control block
  37. TSIZ    EQU    0080H        ;size of record buffer
  38.  
  39.  
  40. ;    -------------
  41.     org    0100H
  42. ;    -------------
  43.  
  44.  
  45. BEGN:    ld    bx,#LOGO    ;"BINCOM/UAP"
  46.     call    MSSG
  47.     ld    al,TFCB+1    ;file name
  48.     cmp    al,#' '
  49.     jnz    NNUL
  50.     ld    bx,#TUTO
  51. CMSS:    call    MSSG
  52.     jmp    GBYE
  53.  
  54. NNUL:    call    SETUP
  55.  
  56.     ld    cl,#15        ;(0F) open file
  57.     ld    dx,#FCB1
  58.     int    BDOS
  59.     inc    al
  60.     jnz    OKF1
  61.     ld    bx,#ER1
  62.     jmp    CMSS
  63.  
  64. OKF1:    ld    cl,#15        ;(0F) open file
  65.     ld    dx,#FCB2
  66.     int    BDOS
  67.     inc    al
  68.     jnz    OKF2
  69.     ld    bx,#ER2
  70.     jmp    CMSS
  71.  
  72. OKF2:    xor    al,al
  73.     sto    al,FCB1+32
  74.     sto    al,FCB2+32
  75.     sto    al,BYCT
  76.     sto    al,NEQL
  77.     stob    #1,RECT
  78.     stob    #4,CLMN
  79.  
  80.     sto    #0000,ERCT
  81.  
  82.     ld    cx,#0000    ;count of bytes compared
  83.  
  84. LOOP:    ld    ah,BYCT
  85.     and    ah,#07FH
  86.     jnz    RNB        ;bytes in the buffer
  87.     ld    ah,RECT
  88.     dec    ah
  89.     jnz    RNA
  90.     push    cx
  91.  
  92.     ld    cx,#0008H    ;eight-sector buffer
  93.     ld    dx,#BUF1
  94.     ld    bx,#FCB1
  95.     call    FILB
  96.  
  97.     push    cx
  98.     ld    cx,#0008H    ;eight-sector buffer
  99.     ld    dx,#BUF2
  100.     ld    bx,#FCB2
  101.     call    FILB
  102.  
  103.     pop    ax
  104.     cmp    ah,ch
  105.     jz    EQL
  106.     ld    bx,#NEQL
  107.     jc    NEQ
  108.     mov    ah,ch
  109.     stob    #'2',[bx]
  110.     jmp    EQL
  111. NEQ:    stob    #'1',[bx]
  112. EQL:    pop    cx
  113.     cmp    ah,#00
  114.     jz    ENFI        ;end of record
  115.     ld    dx,#BUF1
  116.     ld    bx,#BUF2
  117. RNA:    sto    ah,RECT
  118.     ld    ah,#80H
  119. RNB:    dec    ah        ;read next pair of bytes
  120.     sto    ah,BYCT
  121.     xchg    bx,dx
  122.     ld    al,[bx]
  123.     xchg    bx,dx
  124.     cmp    al,[bx]
  125.     jz    NRPT
  126.     call    RPRT        ;report discrepancy
  127. NRPT:    call    BREAK
  128.     ror    al
  129.     jc    QUIT
  130.     inc    cx
  131.     inc    dx
  132.     inc    bx
  133.     jmp    LOOP
  134.  
  135. ;    Type summary message at the end of the run. The summary
  136. ;    includes the number of bytes compared, the number of bytes
  137. ;    that were different, and an indication of which file was
  138. ;    shorter in the case that their lengths were not equal.
  139.  
  140. QUIT:    call    CRLF
  141.     ld    bx,#ME3
  142.     call    MSSG
  143. ENFI:    push    cx
  144.     call    CRLF
  145.     ld    bx,#ME1
  146.     call    MSSG
  147.     pop    bx
  148.     call    WORD
  149.     ld    al,#'H'
  150.     call    AOUT
  151.     call    CRLF
  152.     ld    bx,#ME2
  153.     call    MSSG
  154.     ld    bx,ERCT
  155.     call    WORD
  156.     ld    al,#'H'
  157.     call    AOUT
  158.     call    CRLF
  159.     ld    al,NEQL
  160.     or    al,al
  161.     jz    GBYE
  162.     ld    bx,#FCB1+1
  163.     cmp    al,#'1'
  164.     jz    ENF
  165.     ld    bx,#FCB2+1
  166. ENF:    call    MSSG
  167.     ld    bx,#ME4
  168.     call    MSSG
  169. GBYE:    ld    dl,#00
  170.     ld    cl,#00
  171.     int    bdos
  172.  
  173. ;    Copy the file names into the corresponding file
  174. ;    control blocks, check whether or not the files
  175. ;    are present and issue an error message if they
  176. ;    are not, and insert the default extension .CMD
  177. ;    if it is required.
  178.  
  179. SETUP:    ld    ch,#16
  180.     ld    dx,#TFCB
  181.     ld    bx,#FCB1
  182.     call    MOOV
  183.  
  184.     ld    bx,#ME5
  185.     call    MSSG
  186.     ld    bx,#FCB1+1
  187.     call    MSSG
  188.     call    CRLF
  189.  
  190.     ld    ch,#16
  191.     ld    dx,#TFCB+16
  192.     ld    bx,#FCB2
  193.     call    MOOV
  194.  
  195.     ld    bx,#ME6
  196.     call    MSSG
  197.     ld    bx,#FCB2+1
  198.     call    MSSG
  199.     call    CRLF
  200.     jmp    CRLF
  201.  
  202. MOOV:    xchg    bx,dx
  203.     ld    al,[bx]
  204.     xchg    bx,dx
  205.     sto    al,[bx]
  206.     inc    dx
  207.     inc    bx
  208.     dec    ch
  209.     jnz    MOOV
  210.     ld    dx,#-7
  211.     add    bx,dx
  212.     ld    al,[bx]
  213.     cmp    al,#' '
  214.     jnz    MOOZ
  215.     stob    #'C',[bx]
  216.     inc    bx
  217.     stob    #'M',[bx]
  218.     inc    bx
  219.     stob    #'D',[bx]
  220. MOOZ:    ret
  221.  
  222. ;    Fill buffer DE using FCB HL. On return, B = # sectors read.
  223. ;    It will be used to determine whether the files were of the
  224. ;    same length or not.
  225.  
  226. FILB:    push    cx
  227.     push    dx
  228.     push    bx
  229.     ld    cl,#26        ;(1A) set DMA address
  230.     int    BDOS
  231.     pop    dx
  232.     push    dx
  233.     ld    cl,#20        ;(14) read one record
  234.     int    BDOS
  235.     pop    dx
  236.     pop    bx
  237.     ld    cx,#TSIZ
  238.     add    bx,cx
  239.     xchg    bx,dx
  240.     pop    cx
  241.     cmp    al,#00
  242.     jnz    FIC
  243.     inc    ch
  244.     dec    cl
  245.     jnz    FILB
  246.     ret
  247. FIC:    cmp    al,#01
  248.     jnz    FID
  249.     ret
  250. FID:    ret
  251.  
  252. ;    Type CR,LF.
  253.  
  254. CRLF:    ld    al,#CR
  255.     call    AOUT        ;A to console
  256.     ld    al,#LF
  257.     jmp    AOUT        ;A to console
  258.  
  259. ;    Type one, two, or four spaces.
  260.  
  261. QUAD:    call    DUBL
  262. DUBL:    call    SNGL
  263. SNGL:    ld    al,#' '
  264.  
  265. ;    A to console
  266.  
  267. AOUT:    push    bx
  268.     push    dx
  269.     push    cx
  270.     mov    dl,al
  271.     ld    cl,#02        ;(02) A to console
  272.     int    BDOS
  273.     pop    cx
  274.     pop    dx
  275.     pop    bx
  276.     ret
  277.  
  278. ;    Read console status: 1/0 = char waiting/not.
  279.  
  280. BREAK:    push    cx
  281.     push    dx
  282.     push    bx
  283.     ld    cl,#11        ;(0B) read console status
  284.     int    BDOS
  285.     push    ax
  286.     ror    al
  287.     jnc    BRK
  288.     ld    cl,#1        ;(01) read console
  289.     int    BDOS
  290. BRK:    pop    ax
  291.     pop    bx
  292.     pop    dx
  293.     pop    cx
  294.     ret
  295.  
  296. ;    Type A as two nibbles
  297.  
  298. WORD:    mov    al,bh
  299.     call    BYTE
  300.     mov    al,bl
  301. BYTE:    push    ax
  302.     rcr    al
  303.     rcr    al
  304.     rcr    al
  305.     rcr    al
  306.     call    NYBL
  307.     pop    ax
  308. NYBL:    and    al,#0FH
  309.     add    al,#90H
  310.     daa
  311.     adc    al,#40H
  312.     daa
  313.     jmp    AOUT        ;A to console
  314.  
  315. ;    Type discrepancy report.
  316.  
  317. RPRT:    push    bx
  318.     push    cx
  319.     ld    bx,ERCT
  320.     inc    bx
  321.     sto    bx,ERCT
  322.     pop    bx
  323.     call    WORD
  324.     call    DUBL
  325.     pop    bx
  326.     ld    al,[bx]
  327.     call    BYTE
  328.     call    SNGL
  329.     xchg    bx,dx
  330.     ld    al,[bx]
  331.     xchg    bx,dx
  332.     call    BYTE
  333.     call    SNGL
  334.     call    QUAD
  335.     ld    al,CLMN
  336.     dec    al
  337.     jnz    RPR
  338.     call    CRLF
  339.     ld    al,#4
  340. RPR:    sto    al,CLMN
  341.     ret
  342.  
  343. ;    Message terminated by zero to console
  344.  
  345. MSSG:    ld    al,[bx]
  346.     or    al,al
  347.     jz    MSS
  348.     call    AOUT        ;A to console
  349.     inc    bx
  350.     jmp    MSSG
  351. MSS:    ret
  352.  
  353. ;    ---------------------------------------------------------
  354.  
  355. LOGO:    db    '         BINCOM/ICUAP',CR,LF
  356.     db    'Universidad Autonoma de Puebla',CR,LF
  357.     db    '      September 16, 1983',CR,LF,CR,LF,00
  358.  
  359. ER1:    db    'Cannot open first file.',00
  360. ER2:    db    'Cannot open second file.',00
  361. ME1:    db    'Number of bytes compared:   ',00
  362. ME2:    db    'Number of mismatches found: ',00
  363. ME3:    db    'Comparison interrupted...',00
  364. ME4:    db    ' was shorter.',CR,LF,00
  365. ME5:    db    'File 1:  ',00
  366. ME6:    db    'File 2:  ',00
  367. TUTO:    db    'BINCOM.CMD is a program which can be used to compare',CR,LF
  368.     db    'two files, which will probably be binary, to find the',CR,LF
  369.     db    'differences between them. The files are compared byte',CR,LF
  370.     db    'for byte. No attempt is made to vary the match points',CR,LF
  371.     db    'to establish a different synchronization if a prolonged',CR,LF
  372.     db    'mismatch is found, as would be done for ASCII files.',CR,LF
  373.     db    'The command line is:',CR,LF,CR,LF
  374.     db    '      BINCOM [X:]FILE1.CMD,[Y:]FILE2.CMD',CR,LF,CR,LF
  375.     db    'Discrepancies will be noted in the form',CR,LF,CR,LF
  376.     db    '        XXXX YY ZZ',CR,LF,CR,LF
  377.     db    'where XXXX is the discrepant byte, YY in FILE1 but ZZ',CR,LF
  378.     db    'in FILE2. Use any key to halt the comparison. Final',CR,LF
  379.     db    'totals - of bytes compared and mismatches found - will',CR,LF
  380.     db    'always be shown.',CR,LF
  381.     db    00
  382.  
  383. FCB1:    ds    33
  384. FCB2:    ds    33
  385. BYCT:    ds    1        ;byte count
  386. RECT:    ds    1        ;record count
  387. ERCT:    ds    2
  388. NEQL:    ds    1        ;FF=different file lengths
  389. CLMN:    ds    1        ;coumn counter
  390. BORG:    ds    2
  391. BUF1:    ds    400H        ;eight-sector buffer
  392. BUF2:    ds    400H        ;eight-sector buffer
  393.  
  394.     end
  395.