home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / sigm / vol165 / bincom.asm < prev    next >
Encoding:
Assembly Source File  |  1984-07-09  |  5.8 KB  |  380 lines

  1.  
  2. ;    --------------------------------------------------------
  3. ;    BINCOM.COM is a program which can be used to compare
  4. ;    two files, which will probably be binary, to find the
  5. ;    differences between them. The files are compared byte
  6. ;    for byte. No attempt is made to vary the match points
  7. ;    to establish a different synchronization if a prolonged
  8. ;    mismatch is found, as would be done for ASCII files.
  9. ;    The command line is:
  10. ;
  11. ;          BINCOM [X:]FILE1.COM,[Y:]FILE2.COM
  12. ;
  13. ;    Discrepancies will be noted at the console in a line
  14. ;    of the form
  15. ;            XXXX YY ZZ
  16. ;    where XXXX is the number of the discrepant byte, YY in
  17. ;    FILE1 but ZZ in FILE2. Pressing any key at the console
  18. ;    will stop the comparison, but in any event there will
  19. ;    be a final total shown of the bytes compared and the
  20. ;    number of mismatches encountered.
  21. ;
  22. ;            BINCOM .ASM Copyright (C) 1983
  23. ;            Universidad Autonoma de Puebla
  24. ;              September 16, 1983
  25. ;
  26. ;    [Harold V. McIntosh, 16 September 1983]
  27. ;    --------------------------------------------------------
  28.  
  29.  
  30. LF    equ    0AH    ;line feed
  31. CR    equ    0DH    ;carriage return
  32.  
  33. BDOS    equ    0005H    ;jump to BDOS
  34. TFCB    equ    005CH    ;DDT's file control block
  35. TSIZ    equ    0080H    ;size of record buffer
  36.  
  37. ;    -------------
  38.     org    0100H
  39. ;    -------------
  40.  
  41. begn:    lxi    h,0000
  42.     dad    sp
  43.     shld    stak
  44.     lxi    sp,stak
  45.     lxi    h,logo        ;"BINCOM/UAP"
  46.     call    mssg
  47.     lda    TFCB+1        ;file name
  48.     cpi    ' '
  49.     jz    tuto
  50.     call    setup
  51.  
  52.     mvi    c,15    ;(0F) open file
  53.     lxi    d,fcb1
  54.     call    BDOS
  55.     inr    a
  56.     jz    err1
  57.     mvi    c,15    ;(0F) open file
  58.     lxi    d,fcb2
  59.     call    BDOS
  60.     inr    a
  61.     jz    err2
  62.  
  63.     xra    a
  64.     sta    fcb1+32
  65.     sta    fcb2+32
  66.     sta    byct
  67.     sta    neql
  68.     inr    a
  69.     sta    rect
  70.     mvi    a,4
  71.     sta    clmn
  72.  
  73.     lxi    h,0000
  74.     shld    erct
  75.  
  76.     lxi    b,0000
  77.  
  78. loop:    lda    byct
  79.     ani    07FH
  80.     jnz    rnb    ;bytes in the buffer
  81.     lda    rect
  82.     dcr    a
  83.     jnz    rna
  84.     push    b
  85.  
  86.     lxi    b,0008H    ;eight-sector buffer
  87.     lxi    d,buf1
  88.     lxi    h,fcb1
  89.     call    filb
  90.  
  91.     push    b
  92.     lxi    b,0008H    ;eight-sector buffer
  93.     lxi    d,buf2
  94.     lxi    h,fcb2
  95.     call    filb
  96.  
  97.     pop    psw
  98.     cmp    b
  99.     jz    eql
  100.     lxi    h,neql
  101.     jc    neq
  102.     mov    a,b
  103.     mvi    m,'2'
  104.     jmp    eql
  105. neq:    mvi    m,'1'
  106. eql:    pop    b
  107.     cpi    00
  108.     jz    enfi    ;end of record
  109.     lxi    d,buf1
  110.     lxi    h,buf2
  111. rna:    sta    rect
  112.     mvi    a,80H
  113. rnb:    dcr    a    ;read next pair of bytes
  114.     sta    byct
  115.     ldax    d
  116.     cmp    m
  117.     cnz    rprt    ;report discrepancy
  118.     call    recs
  119.     jnz    quit
  120.     inx    b
  121.     inx    d
  122.     inx    h
  123.     jmp    loop
  124.  
  125. ;    Type summary message at the end of the run.
  126.  
  127. quit:    call    crlf
  128.     lxi    h,me3
  129.     call    mssg
  130. enfi:    push    b
  131.     call    crlf
  132.     lxi    h,me1
  133.     call    mssg
  134.     pop    h
  135.     call    word
  136.     mvi    a,'H'
  137.     call    aout
  138.     call    crlf
  139.     lxi    h,me2
  140.     call    mssg
  141.     lhld    erct
  142.     call    word
  143.     mvi    a,'H'
  144.     call    aout
  145.     call    crlf
  146.     lda    neql
  147.     ora    a
  148.     jz    gbye
  149.     lxi    h,fcb1+1
  150.     cpi    '1'
  151.     jz    enf
  152.     lxi    h,fcb2+1
  153. enf:    call    mssg
  154.     lxi    h,me4
  155.     call    mssg
  156. gbye:    lhld    stak
  157.     sphl
  158.     ret
  159.  
  160. setup:    mvi    b,16
  161.     lxi    d,TFCB
  162.     lxi    h,fcb1
  163.     call    moov
  164.  
  165.     lxi    h,me5
  166.     call    mssg
  167.     lxi    h,fcb1+1
  168.     call    mssg
  169.     call    crlf
  170.  
  171.     mvi    b,16
  172.     lxi    d,TFCB+16
  173.     lxi    h,fcb2
  174.     call    moov
  175.  
  176.     lxi    h,me6
  177.     call    mssg
  178.     lxi    h,fcb2+1
  179.     call    mssg
  180.     call    crlf
  181.     jmp    crlf
  182.  
  183. moov:    ldax    d
  184.     mov    m,a
  185.     inx    d
  186.     inx    h
  187.     dcr    b
  188.     jnz    moov
  189.     lxi    d,-7
  190.     dad    d
  191.     mov    a,m
  192.     cpi    ' '
  193.     rnz
  194.     mvi    m,'C'
  195.     inx    h
  196.     mvi    m,'O'
  197.     inx    h
  198.     mvi    m,'M'
  199.     ret
  200.  
  201. ;    Fill buffer DE using FCB HL. On return, B = # sectors read.
  202.  
  203. filb:    push    b
  204.     push    d
  205.     push    h
  206.     mvi    c,26    ;(1A) set DMA address
  207.     call    BDOS
  208.     pop    d
  209.     push    d
  210.     mvi    c,20    ;(14) read one record
  211.     call    BDOS
  212.     pop    d
  213.     pop    h
  214.     lxi    b,TSIZ
  215.     dad    b
  216.     xchg
  217.     pop    b
  218.     cpi    00
  219.     jnz    fic
  220.     inr    b
  221.     dcr    c
  222.     jnz    filb
  223.     ret
  224. fic:    cpi    01
  225.     rz
  226.     ret
  227.  
  228. ;    Type CR,LF.
  229.  
  230. crlf:    mvi    a,CR
  231.     call    aout    ;A to console
  232.     mvi    a,LF
  233.     jmp    aout    ;A to console
  234.  
  235. ;    Type one, two, or four spaces.
  236.  
  237. quad:    call    dubl
  238. dubl:    call    sngl
  239. sngl:    mvi    a,' '
  240.  
  241. ;    A to console
  242.  
  243. aout:    push    h
  244.     push    d
  245.     push    b
  246.     mov    e,a
  247.     mvi    c,02    ;(02) A to console
  248.     call    BDOS
  249.     pop    b
  250.     pop    d
  251.     pop    h
  252.     ret    
  253.  
  254. ;    Read console status: nz/z = char waiting/not.
  255.  
  256. recs:    push    b
  257.     push    d
  258.     push    h
  259.     mvi    c,11    ;(0B) read console status
  260.     call    BDOS
  261.     ani    01
  262.     push    psw
  263.     jz    rcs
  264.     mvi    c,1    ;(01) read console
  265.     call    BDOS
  266. rcs:    pop    psw
  267.     pop    h
  268.     pop    d
  269.     pop    b
  270.     ret
  271.  
  272. ;    Type A as two nibbles
  273.  
  274. word:    mov    a,h
  275.     call    byte
  276.     mov    a,l
  277. byte:    push    psw    
  278.     rar    
  279.     rar    
  280.     rar    
  281.     rar    
  282.     call    nybl
  283.     pop    psw
  284. nybl:    ani    0FH
  285.     adi    90H
  286.     daa
  287.     aci    40H
  288.     daa
  289.     jmp    aout    ;A to console
  290.  
  291. ;    Type discrepancy report.
  292.  
  293. rprt:    push    h
  294.     push    b
  295.     lhld    erct
  296.     inx    h
  297.     shld    erct
  298.     pop    h
  299.     call    word
  300.     call    dubl
  301.     pop    h
  302.     mov    a,m
  303.     call    byte
  304.     call    sngl
  305.     ldax    d
  306.     call    byte
  307.     call    sngl
  308.     call    quad
  309.     lda    clmn
  310.     dcr    a
  311.     jnz    rpr
  312.     call    crlf
  313.     mvi    a,4
  314. rpr:    sta    clmn
  315.     ret
  316.  
  317. ;    Message terminated by zero to console
  318.  
  319. mssg:    mov    a,m
  320.     ora    a
  321.     rz
  322.     call    aout    ;A to console
  323.     inx    h
  324.     jmp    mssg
  325.  
  326. err1:    lxi    h,er1
  327.     jmp    cmss
  328.  
  329. err2:    lxi    h,er2
  330.     jmp    cmss
  331.  
  332. tuto:    lxi    h,scrp
  333. cmss:    call    mssg
  334.     jmp    gbye
  335.  
  336. ;    ---------------------------------------------------------
  337.  
  338. logo:    db    '         BINCOM/ICUAP',CR,LF
  339.     db    'Universidad Autonoma de Puebla',CR,LF
  340.     db    '      September 16, 1983',CR,LF,CR,LF,00
  341.  
  342. er1:    db    'Cannot open first file.',00
  343. er2:    db    'Cannot open second file.',00
  344. me1:    db    'Number of bytes compared:   ',00
  345. me2:    db    'Number of mismatches found: ',00
  346. me3:    db    'Comparison interrupted...',00
  347. me4:    db    ' was shorter.',CR,LF,00
  348. me5:    db    'File 1:  ',00
  349. me6:    db    'File 2:  ',00
  350. scrp:    db    'BINCOM.COM is a program which can be used to compare',CR,LF
  351.     db    'two files, which will probably be binary, to find the',CR,LF
  352.     db    'differences between them. The files are compared byte',CR,LF
  353.     db    'for byte. No attempt is made to vary the match points',CR,LF
  354.     db    'to establish a different synchronization if a prolonged',CR,LF
  355.     db    'mismatch is found, as would be done for ASCII files.',CR,LF
  356.     db    'The command line is:',CR,LF,CR,LF
  357.     db    '      BINCOM [X:]FILE1.COM,[Y:]FILE2.COM',CR,LF,CR,LF
  358.     db    'Discrepancies will be noted in the form',CR,LF,CR,LF
  359.     db    '        XXXX YY ZZ',CR,LF,CR,LF
  360.     db    'where XXXX is the discrepant byte, YY in FILE1 but ZZ',CR,LF
  361.     db    'in FILE2. Use any key to halt the comparison. Final',CR,LF
  362.     db    'totals - of bytes compared and mismatches found - will',CR,LF
  363.     db    'always be shown.',CR,LF
  364.     db    00
  365.  
  366.     ds    20
  367. stak:    ds    2
  368. fcb1:    ds    33
  369. fcb2:    ds    33
  370. byct:    ds    1    ;byte count
  371. rect:    ds    1    ;record count
  372. erct:    ds    2
  373. neql:    ds    1    ;FF=different file lengths
  374. clmn:    ds    1    ;coumn counter
  375. borg:    ds    2
  376. buf1:    ds    400H    ;eight-sector buffer
  377. buf2:    ds    400H    ;eight-sector buffer
  378.  
  379.     end
  380.