home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / enterprs / c128 / text / examples.arc / COMP.A < prev    next >
Text File  |  1989-12-01  |  10KB  |  257 lines

  1. ;comp.asm
  2. ;============================
  3. ; Command:  comp file1 file2
  4. ;============================
  5. ; Program to compare two files.
  6.                                   
  7. status      = $0090               
  8. stkey       = $0091               
  9. imparm      = $00ce               ; temp
  10. int04       = $1704               ; get 1st char of %x
  11. int05       = $1705               ; get next char of %x
  12. int08       = $1708               ; open file %x for read
  13. int0d       = $170d               ; print ds$ after int08 or int0c
  14. int0e       = $170e               ; terminate program
  15. hexa        = $b8c2               
  16. primm       = $ff7d               
  17. chkin       = $ffc6               
  18. clrchn      = $ffcc               
  19. chrin       = $ffcf               
  20. chrout      = $ffd2               
  21.                                   
  22.                                   
  23. star        = $0b00               
  24.             .wor star             
  25.             * = star              
  26.  
  27.             jmp comp
  28.             dw Date
  29.                       
  30. comp        ldx #1                ; open %1 for read
  31.             jsr ppc               ; 1st display the filename
  32.             ldx #1                ; now open it
  33.             lda #0                ; don't care what type
  34.             jsr int08             ; open it
  35.             bcc comp0             ; open went ok
  36. compx       jsr int0d             ; open error...print ds$
  37.             jmp int0e             ; and terminate program
  38.                                   
  39. comp0       stx la1               ; save 1st la
  40.             ldx #2                ; repeat for second file
  41.             jsr ppc               ; dislay name
  42.             ldx #2                
  43.             lda #0                
  44.             jsr int08             ; open it
  45.             bcs compx             ; error..quit
  46.             stx la2               ; save la
  47.             lda #13               
  48.             jsr chrout            
  49.             ldx la1               
  50.             jsr chkin             ; get 1st file's load address
  51.             jsr chrin             
  52.             sta ad1               
  53.             jsr chrin             
  54.             sta ad1+1             
  55.             jsr clrchn            
  56.             ldx la2               ; get 1st file's load address
  57.             jsr chkin             
  58.             jsr chrin             
  59.             sta ad2               
  60.             jsr chrin             
  61.             sta ad2+1             
  62.             jsr clrchn            
  63.             jsr primm             
  64.             .asc "------------------------------",13
  65.             .asc "offset  addr1   addr2   match?",13
  66.             .asc "------------------------------",13
  67.             .byt 0                
  68.             lda #0                
  69.             sta offset            
  70.             sta offset+1          
  71.             sta offset+2          
  72.             sta ad2+2             
  73.             sta ad1+2             
  74.             sta stat2             
  75.             sta stat1             
  76.             sta match             ; 0=bytes match, non-zero = don't match
  77.             sta oldm              
  78.             lda ad1               
  79.             eor ad1+1             
  80.             sta byte1             
  81.             lda ad2               
  82.             eor ad2+1             
  83.             sta byte2             
  84.             cmp byte1             ; do they match?
  85.             beq comp2             ; yes
  86.             dec match             
  87. comp2       jsr disp              ; disp current status
  88.             lda match             
  89.             sta oldm              
  90.             lda #2                ; make offset 2
  91.             sta offset            
  92. comp3       jsr get2              ; get byte from each file
  93.             bne comp4             ; no match
  94.             lda #0                ; 0=match
  95.             .byt $2c              
  96. comp4       lda #$ff              
  97.             sta match             
  98.             cmp oldm              
  99.             beq compa             ; same as previous...don't display
  100. comp5       jsr disp              
  101.             lda match             
  102.             sta oldm              
  103. compa       inc offset            
  104.             bne comp6             
  105.             inc offset+1          
  106.             bne comp6             
  107.             inc offset+2          
  108. comp6       inc ad1               
  109.             bne comp7             
  110.             inc ad1+1             
  111.             bne comp7             
  112.             inc ad1+2             
  113. comp7       inc ad2               
  114.             bne comp8             
  115.             inc ad2+1             
  116.             bne comp8             
  117.             inc ad2+1             
  118. comp8       lda stat1             
  119.             beq comp99            
  120.             lda stat2             
  121.             bne comp9             
  122. comp99      bit stkey             
  123.             bpl comp9             
  124.             jmp comp3             
  125.                                   
  126. comp9       jmp int0e             
  127.                                   
  128.                                   
  129. ;-------------------------------------------------
  130. ; Subroutine...print %x and abort if its not there
  131. ;-------------------------------------------------
  132.                                   
  133. ppc         jsr int04             ; get 1st byte of %x
  134.             bcc ppc0              ; its ok..continue
  135.             pla                   ; kill RTS
  136.             pla                   
  137.             jsr primm             ; and display proper syntax
  138.             .asc 13,"Syntax:  comp [d:]file [d:]file",13
  139.             .asc 13,"Purpose: To compare two files.",13, 0
  140.             jmp int0e             ; and abort
  141.                                   
  142. ppc0        ldx #0                ; count length
  143. ppc1        jsr chrout            
  144.             inx                   
  145.             jsr int05             
  146.             bcc ppc1              
  147. ppc2        lda #" "              ; make it 16 chars
  148.             jsr chrout            
  149.             inx                   
  150.             cpx #18               
  151.             bne ppc2              
  152.             rts                   
  153.                                   
  154. ;------------------------------------------
  155. ; Subroutine: compare next byte from files
  156. ;------------------------------------------
  157.                                   
  158. get2        lda stat1             
  159.             bne get3              
  160.             ldx la1               
  161.             jsr chkin             
  162.             jsr chrin             
  163.             sta byte1             
  164.             lda status            
  165.             sta stat1             
  166.             beq get7              
  167.             lda #0                
  168.             sta oldm              
  169. get7        jsr clrchn            
  170. get3        lda stat2             
  171.             bne get4              
  172.             ldx la2               
  173.             jsr chkin             
  174.             jsr chrin             
  175.             sta byte2             
  176.             lda status            
  177.             sta stat2             
  178.             beq get6              
  179.             lda #0                
  180.             sta oldm              
  181. get6        jsr clrchn            
  182.             lda byte1             
  183.             cmp byte2             
  184. get4        php                   
  185.             lda stat1             
  186.             ora stat2             
  187.             bne get5              
  188.             plp                   
  189.             rts                   
  190.                                   
  191. get5        pla                   
  192.             lda #1                
  193.             rts                   
  194.                                   
  195. ;------------------------------------------
  196. ; Subroutine: display results of compare
  197. ;------------------------------------------
  198.                                   
  199. disp        lda offset+2          
  200.             ldy offset+1          
  201.             ldx offset            
  202.             jsr disphx            
  203.             lda stat1             
  204.             beq disp2             
  205.             jsr primm             
  206.             .asc "eof     ", 0    
  207.             jmp disp3             
  208.                                   
  209. disp2       lda ad1+2             
  210.             ldy ad1+1             
  211.             ldx ad1               
  212.             jsr disphx            
  213. disp3       lda stat2             
  214.             beq disp4             
  215.             jsr primm             
  216.             .asc "eof     ", 0    
  217.             jmp disp5             
  218.                                   
  219. disp4       lda ad2+2             
  220.             ldy ad2+1             
  221.             ldx ad2               
  222.             jsr disphx            
  223. disp5       lda match             
  224.             bne disp1             
  225.             jsr primm             
  226.             .asc "yes.",13, 0
  227.             rts                   
  228.                                   
  229. disp1       jsr primm             
  230.             .asc "no.",13, 0
  231.             rts                   
  232.                                   
  233. disphx      stx imparm            
  234.             sty imparm+1          
  235.             jsr hexa              
  236.             lda imparm+1          
  237.             jsr hexa              
  238.             lda imparm            
  239.             jsr hexa              
  240.             lda #" "              
  241.             jsr chrout            
  242.             jmp chrout            
  243.                                   
  244. oldm        *=*+1                 
  245. match       *=*+1                 
  246. stat1       *=*+1                 
  247. stat2       *=*+1                 
  248. ad1         *=*+3                 
  249. ad2         *=*+3                 
  250. offset      *=*+3                 
  251. byte1       *=*+1                 
  252. byte2       *=*+1                 
  253. la1         *=*+1                 
  254. la2         *=*+1                 
  255.                                   
  256.             .end                  
  257.