home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / sigm / vol281 / cmpcode.zq0 / CMPCODE.Z80
Encoding:
Text File  |  1986-06-11  |  3.5 KB  |  271 lines

  1. ;            "Compare"
  2. ;
  3. ;         File comparison utility
  4. ;
  5. ;           (C) P.F.Ridler 1983
  6. ;
  7. ;
  8. ;    Original     5 Apr 83
  9. ;            11 Oct 83  for Decision Mate
  10. ;
  11. ;
  12. ;
  13. warm    equ    0000H
  14. bdos    equ    0005H
  15. dfcb1    equ    005CH
  16. dfcb2    equ    006CH
  17. ;
  18. lf    equ    10
  19. cr    equ    13
  20. esc    equ    27
  21. del    equ    127
  22. ;
  23. errmax    equ    20
  24. ;
  25.     org    100H
  26. ;
  27. cmp    ld    sp,stack
  28.     call    clrscr
  29.     call    dspnxt
  30.     db    esc,'=',8+32,25+32,'File comparison utility'
  31.     db    esc,'=',10+32,26+32,'(C)  P.F.Ridler  1983',0
  32.     call    row22
  33.     ld    hl,dfcb1
  34.     ld    de,fcb1
  35.     ld    bc,16
  36.     ldir
  37.     xor    a,a
  38.     ld    (fcb1+32),a
  39.     ;
  40.     ld    hl,dfcb2
  41.     ld    de,fcb2
  42.     ld    bc,16
  43.     ldir
  44.     xor    a,a
  45.     ld    (fcb2+32),a
  46.     ;
  47.     ld    de,fcb1
  48.     call    exist
  49.     jr    nz,cmp3
  50.     call    crlf
  51.     call    doesnt
  52.     jp    warm
  53. cmp3    ld    de,fcb2
  54.     call    exist
  55.     jr    nz,cmp4
  56.     call    crlf
  57.     call    doesnt
  58.     jp    warm
  59. cmp4    ld    hl,100H            ;address
  60. cmp5    call    read1
  61.     call    read2
  62.     ld    a,(flag1)
  63.     or    a,a
  64.     jr    nz,exit1
  65.     ld    a,(flag2)
  66.     or    a,a
  67.     jr    nz,exit2
  68.     ld    b,128
  69.     ld    ix,buff1
  70.     ld    iy,buff2
  71. cmp6    ld    a,(ix)
  72.     cp    a,(iy)
  73.     jr    z,cmp9
  74.     call    dspadd
  75.     call    space
  76.     ld    a,(ix)
  77.     call    dsphex
  78.     call    space
  79.     call    dspasc
  80.     call    space
  81.     call    space
  82.     ld    a,(iy)
  83.     call    dsphex
  84.     call    space
  85.     call    dspasc
  86.     call    incerr
  87.     ld    a,(nerrs)
  88.     cp    a,errmax
  89.     jr    z,exit4
  90. cmp9    inc    ix
  91.     inc    iy
  92.     inc    hl
  93.     djnz    cmp6
  94.     jr    cmp5
  95. ;
  96. ;
  97. exit1    ld    a,(nerrs)
  98.     or    a,a
  99.     jr    nz,exit4
  100.     ld    a,(flag2)        ;file1 at eof
  101.     or    a,a
  102.     jr    nz,exit3        ;file2 too
  103.     call    dspnxt            ;file1 finished but not file2
  104.     db    cr,lf,'File1 < file2',0
  105.     jr    exit4
  106. exit2    ld    a,(nerrs)
  107.     or    a,a
  108.     jr    nz,exit4
  109.     ld    a,(flag1)        ;file2 finished, test file1
  110.     or    a,a
  111.     jr    nz,exit3        ;file1 at eof
  112.     call    dspnxt
  113.     db    cr,lf,'File2 < file1',0
  114.     jr    exit4
  115. exit3    call    dspnxt
  116.     db    cr,lf,'Files are identical',0
  117. exit4    jp    warm
  118. ;
  119. ;
  120. incerr    push    hl
  121.     ld    hl,nerrs
  122.     inc    (hl)
  123.     pop    hl
  124.     ret
  125. ;
  126. ;
  127. read1    push    af
  128.     exx
  129. ;    call    dspnxt
  130. ;    db    cr,lf,'reading file1',0
  131.     ld    de,buff1        ;set transfer address
  132.     ld    c,26
  133.     call    bdos
  134.     ld    de,fcb1            ;read next sector
  135.     ld    c,20
  136.     call    bdos
  137.     ld    (flag1),a
  138.     exx
  139.     pop    af
  140.     ret
  141. ;
  142. ;
  143. read2    push    af
  144.     exx
  145. ;    call    dspnxt
  146. ;    db    cr,lf,'reading file2',0
  147.     ld    de,buff2
  148.     ld    c,26
  149.     call    bdos
  150.     ld    de,fcb2
  151.     ld    c,20
  152.     call    bdos
  153.     ld    (flag2),a
  154.     exx
  155.     pop    af
  156.     ret
  157. ;
  158. ;
  159. dspadd    call    crlf
  160.     ld    a,h
  161.     call    dsphex
  162.     ld    a,l
  163.     call    dsphex
  164.     ret
  165. ;
  166. ;
  167. dsphex    push    af
  168.     push    af        ;needed later
  169.     srl    a        ;high nibble
  170.     srl    a
  171.     srl    a
  172.     srl    a
  173.     cp    a,10
  174.     jp    p,dsphx1
  175.     add    a,30H        ;0..9
  176.     jr    dsphx2
  177. dsphx1    add    a,37H        ;A..F
  178. dsphx2    call    conout
  179.     pop    af
  180.     and    a,0FH        ;low nibble
  181.     cp    a,10
  182.     jp    p,dsphx3
  183.     add    a,30H
  184.     jr    dsphx4
  185. dsphx3    add    a,37H
  186. dsphx4    call    conout
  187.     pop    af
  188.     ret
  189. ;
  190. ;
  191. exist    push    hl        ;DE holds fcb
  192.     push    de
  193.     push    bc
  194.     ld    c,15
  195.     call    bdos
  196.     inc    a        ;holds 0 if nbg
  197.     pop    bc
  198.     pop    de
  199.     pop    hl
  200.     ret
  201. ;
  202. ;
  203. conout    exx
  204.     ld    e,a
  205.     ld    c,2
  206.     call    bdos
  207.     exx
  208.     ret
  209. ;
  210. ;
  211. dspasc    push    af
  212.     cp    a,del
  213.     jp    p,dspsc1
  214.     cp    a,' '
  215.     jp    p,dspsc2
  216. dspsc1    ld    a,'.'
  217. dspsc2    call    conout
  218.     pop    af
  219.     ret
  220. ;
  221. ;
  222. space    call    dspnxt
  223.     db    '  ',0
  224.     ret
  225. ;
  226. ;
  227. crlf    call    dspnxt
  228.     db    cr,lf,0
  229.     ret
  230. ;
  231. ;
  232. doesnt    call    dspnxt
  233.     db    cr,lf,'File doesn''t exist',0
  234.     ret
  235. ;
  236. ;
  237. row22    call    dspnxt            ;position cursor at row=22, col=0
  238.     db    esc,'=',22+32,0+32,0
  239.     ret
  240. ;
  241. ;
  242. clrscr    call    dspnxt            ;for Decision Mate
  243.     db    esc,':',0
  244.     ret
  245. ;
  246. ;
  247. dspnxt    ex    (sp),hl
  248.     push    af
  249. dspnx1    ld    a,(hl)
  250.     inc    hl
  251.     or    a,a
  252.     jr    z,dspnx2
  253.     call    conout
  254.     jr    dspnx1
  255. dspnx2    pop    af
  256.     ex    (sp),hl
  257.     ret
  258. ;
  259. ;
  260. nerrs    db    0
  261. flag1    db    0
  262. flag2    db    0
  263. addrss    dw    100H
  264. fcb1    ds    35
  265. fcb2    ds    35
  266. buff1    ds    128
  267. buff2    ds    128
  268. stack    equ    $+100H
  269. ;
  270.     end    cmp
  271.