* CMPF PTDOS command by TMQ 4/7/79 * format: CMPF original file name,duplicate file name * compares two files for identical contents * not safe ORG 100H load address XEQ 100H start address CR EQU 0DH carriage return LF EQU 0AH line feed BYTBZ EQU 256 # of bytes in block transfer COPY NPTDEFS get system definitions LXI SP,STACK initialize stack * Open both files CALL PASCN open the original file CPI ',' comma JNZ ERRNC file name missing MOV A,E get file # STA FINU1 store its file # CALL PASCN open duplicate file MOV A,E get file # STA FINU2 store its file # * Initialize parameters before comparison COMP CALL READ read a block or less of bytes from both files * subtract remaining transfer count from block size LXI B,BLKSZ point to block size (BYTBZ) LXI H,TRFCT point to transfer count remaining (usually 0) XRA A clear carry bit LDAX B get block size low byte SBB M subtract transfer count remaining MOV E,A save low transfer count in E INX B point to high byte INX H same LDAX B get block size high byte SBB M subtract transfer count remaining MOV D,A save high transfer count in D * DE now holds actual transfer count LXI B,MBUF1 BC points to start of original file buffer LXI H,MBUF2 HL points to start of duplicate file buffer * comparison begins here AGNM PUSH H save addr LHLD COUNT get comparison counter (starts at 0) INX H increase count by one SHLD COUNT put count back POP H restore addr LDAX B get original data byte CMP M compare with duplicate data byte JNZ NOMATCH if not the same INX B point to next original file addr INX H point to next duplicate file addr DCX D decrease block count by one MOV A,E inclusive OR the low ORA D and the high count JNZ AGNM look some more if not zero LDA EOFG get end of file flag CPI EREOF does it match EOF error byte JZ MATCH yes, files must be the same JMP COMP not at EOF so get another block and compare again * Files match routine MATCH LXI D,MESM point to 'files are identical' message CALL PRTMSG print it CALL CLOSE close files * Return to PTDOS routine SYRET CALL SYS system call DB RETOP return to system * Files do not match routine NOMATCH LXI D,MESNM point to 'files are different' message CALL PRTMSG print it and 'check byte at:' CALL ADOUT convert comparison counter to hex & print LXI D,MESE point to 'H' message CALL PRTMSG print it CALL CLOSE close files JMP SYRET and return to system * Parameter scanner routine PASCN MVI A,PSOP open file LXI D,BUFPS point to buffer CALL PSCAN parameter scanner JC ERRPS field syntax error JZ ERRNC no file name found RET done * Transfer a block of data to memory for both files READ LDA FINU1 get original file # LXI D,MBUF1 point to its buffer LXI B,BYTBZ load transfer count CALL SYS system call DB RBLOP read data STA EOFG error return, set EOF flag MOV H,B normal return, BC holds the MOV L,C remaining unsucessful transfer count (normally 0) SHLD TRFCT store here LDA FINU2 get duplicate file # LXI D,MBUF2 point to its buffer LXI B,BYTBZ load transfer count CALL SYS system call DB RBLOP read data STA EOFG error return, set EOF flag RET normal return, done * Close files routine CLOSE MVI A,-1 close all open files CALL SYS system call DB CAOP close all open files DB 0,0,0 error return, not used RET done * Print string message till delimiter (0) PRTMSG MVI A,1 console file # MVI L,0 let delimiter be 0 LXI B,38 max transfer count CALL SYS system call DB DWROP delimited write DB 0,0,0 error return RET normal return, done * Convert comparison count to hex and print ADOUT LHLD COUNT get comparison count MOV A,H move high byte CALL HEXOT convert it and print MOV A,L get low byte CALL HEXOT convert it and print RET done * Binary byte to hex and print subroutine HEXOT PUSH PSW save byte for later RRC prepare RRC upper RRC four RRC bits CALL HASCI convert them to a hex chr CALL CONOUT print the higher hex chr POP PSW retrieve the lower four bits CALL HASCI convert them to a hex chr CALL CONOUT print the lower hex byte RET done * convert four bits to a ASC hex chr HASCI ANI 0FH mask off upper four bits ADI 90H DAA ACI 40H DAA RET done * No file name error handler ERRNC CALL CLOSE close any open files LXI D,MNOF point to 'file name missing' message CALL PRTMSG print it JMP ABORT abort & return to system * Parameter scanner error handler ERRPS MOV A,E move error code STA ERRCD store it * Utility error handler UTILEP CALL CLOSE close any open files MVI A,0 control word LXI H,-1 no 2nd line message CALL UTIL system utility call DB UXOP explain error JMP ABORT error return ERROP DB -1 no operation code ERRCD DB 0 error code storage * Abort all ABORT CALL SYS system call DB RESOP abort and return * Message area MESM ASC 'Files are identical' DB CR,LF,0 MESNM ASC 'Files are different' DB CR,LF ASCZ 'Check byte at : ' MESE ASC 'H' DB CR,LF,0 MNOF ASC 'File name missing' DB CR,LF,0 * Storage area BLKSZ DW BYTBZ block transfer size COUNT DW -1 comparisons made counter TRFCT DW 0 incomplete transfer count FINU1 DB 0 original file # assigned FINU2 DB 0 duplicate file # assigned EOFG DB 0 end of file flag (set=high) BUFPS DS 20 parameter scanner buffer MBUF1 DS BYTBZ+2 original file buffer MBUF2 DS BYTBZ+2 duplicate file buffer STACK EQU $+32 program stack END