home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CP/M
/
CPM_CDROM.iso
/
enterprs
/
c128
/
text
/
examples.arc
/
COMP.A
< prev
next >
Wrap
Text File
|
1989-12-01
|
10KB
|
257 lines
;comp.asm
;============================
; Command: comp file1 file2
;============================
; Program to compare two files.
status = $0090
stkey = $0091
imparm = $00ce ; temp
int04 = $1704 ; get 1st char of %x
int05 = $1705 ; get next char of %x
int08 = $1708 ; open file %x for read
int0d = $170d ; print ds$ after int08 or int0c
int0e = $170e ; terminate program
hexa = $b8c2
primm = $ff7d
chkin = $ffc6
clrchn = $ffcc
chrin = $ffcf
chrout = $ffd2
star = $0b00
.wor star
* = star
jmp comp
dw Date
comp ldx #1 ; open %1 for read
jsr ppc ; 1st display the filename
ldx #1 ; now open it
lda #0 ; don't care what type
jsr int08 ; open it
bcc comp0 ; open went ok
compx jsr int0d ; open error...print ds$
jmp int0e ; and terminate program
comp0 stx la1 ; save 1st la
ldx #2 ; repeat for second file
jsr ppc ; dislay name
ldx #2
lda #0
jsr int08 ; open it
bcs compx ; error..quit
stx la2 ; save la
lda #13
jsr chrout
ldx la1
jsr chkin ; get 1st file's load address
jsr chrin
sta ad1
jsr chrin
sta ad1+1
jsr clrchn
ldx la2 ; get 1st file's load address
jsr chkin
jsr chrin
sta ad2
jsr chrin
sta ad2+1
jsr clrchn
jsr primm
.asc "------------------------------",13
.asc "offset addr1 addr2 match?",13
.asc "------------------------------",13
.byt 0
lda #0
sta offset
sta offset+1
sta offset+2
sta ad2+2
sta ad1+2
sta stat2
sta stat1
sta match ; 0=bytes match, non-zero = don't match
sta oldm
lda ad1
eor ad1+1
sta byte1
lda ad2
eor ad2+1
sta byte2
cmp byte1 ; do they match?
beq comp2 ; yes
dec match
comp2 jsr disp ; disp current status
lda match
sta oldm
lda #2 ; make offset 2
sta offset
comp3 jsr get2 ; get byte from each file
bne comp4 ; no match
lda #0 ; 0=match
.byt $2c
comp4 lda #$ff
sta match
cmp oldm
beq compa ; same as previous...don't display
comp5 jsr disp
lda match
sta oldm
compa inc offset
bne comp6
inc offset+1
bne comp6
inc offset+2
comp6 inc ad1
bne comp7
inc ad1+1
bne comp7
inc ad1+2
comp7 inc ad2
bne comp8
inc ad2+1
bne comp8
inc ad2+1
comp8 lda stat1
beq comp99
lda stat2
bne comp9
comp99 bit stkey
bpl comp9
jmp comp3
comp9 jmp int0e
;-------------------------------------------------
; Subroutine...print %x and abort if its not there
;-------------------------------------------------
ppc jsr int04 ; get 1st byte of %x
bcc ppc0 ; its ok..continue
pla ; kill RTS
pla
jsr primm ; and display proper syntax
.asc 13,"Syntax: comp [d:]file [d:]file",13
.asc 13,"Purpose: To compare two files.",13, 0
jmp int0e ; and abort
ppc0 ldx #0 ; count length
ppc1 jsr chrout
inx
jsr int05
bcc ppc1
ppc2 lda #" " ; make it 16 chars
jsr chrout
inx
cpx #18
bne ppc2
rts
;------------------------------------------
; Subroutine: compare next byte from files
;------------------------------------------
get2 lda stat1
bne get3
ldx la1
jsr chkin
jsr chrin
sta byte1
lda status
sta stat1
beq get7
lda #0
sta oldm
get7 jsr clrchn
get3 lda stat2
bne get4
ldx la2
jsr chkin
jsr chrin
sta byte2
lda status
sta stat2
beq get6
lda #0
sta oldm
get6 jsr clrchn
lda byte1
cmp byte2
get4 php
lda stat1
ora stat2
bne get5
plp
rts
get5 pla
lda #1
rts
;------------------------------------------
; Subroutine: display results of compare
;------------------------------------------
disp lda offset+2
ldy offset+1
ldx offset
jsr disphx
lda stat1
beq disp2
jsr primm
.asc "eof ", 0
jmp disp3
disp2 lda ad1+2
ldy ad1+1
ldx ad1
jsr disphx
disp3 lda stat2
beq disp4
jsr primm
.asc "eof ", 0
jmp disp5
disp4 lda ad2+2
ldy ad2+1
ldx ad2
jsr disphx
disp5 lda match
bne disp1
jsr primm
.asc "yes.",13, 0
rts
disp1 jsr primm
.asc "no.",13, 0
rts
disphx stx imparm
sty imparm+1
jsr hexa
lda imparm+1
jsr hexa
lda imparm
jsr hexa
lda #" "
jsr chrout
jmp chrout
oldm *=*+1
match *=*+1
stat1 *=*+1
stat2 *=*+1
ad1 *=*+3
ad2 *=*+3
offset *=*+3
byte1 *=*+1
byte2 *=*+1
la1 *=*+1
la2 *=*+1
.end