0001 * LOOK Byte match program for disk file or memory 0000 * Part of this program is based upon an article in 0000 * Interface Age (May 78) & letter (Aug 78) 0002 * rewritten by Tom M Quinn 1/1/79 0003 * This program will search thru a specified section of 0004 * of memory or disk file looking for a match of 1 to 9 0005 * bytes some of which may be unspecified (,,) 0006 * Command format : 0007 * for disk file : LOOK D,file name,d1,d2,d3,,,d9 0008 * for memory : LOOK M,st addr,end addr,d1,d2,d3,,,d9 0009 * addresses or data may be in any base 0010 * examples: 234:Q, 01101:B, 14950:D, hex is default 0011 * start addr defaults to 0 0012 * end addr defaults to FFFF 0013 * data may be hex or #:base (Q,B,D,H) or unspecified (,,) 0014 ORG 0D000H load address 0015 XEQ 0D000H start address 0016 COPY PTDEFS get system definitions 0017 CR EQU 0DH carriage return 0018 LF EQU 0AH line feed 0019 BLKSZ EQU 256 # of bytes in block transfer 0020 * Initialization 0021 LXI SP,STACK establish stack 0022 * Determine if search is to be on disk file or memory 0023 MVI A,PSOPT read characters until delimiter 0024 CALL PSCNN scanner routine 0025 JZ ERRSY command syntax error 0026 CPI ',' next only valid delimiter 0027 JNZ ERRSY if not must be syntax error 0028 MOV A,C get # of chrs scanned 0029 CPI 1 is it one 0030 JNZ ERRSY no, error in syntax 0031 LDA BUFPS get chr scanned 0032 CPI 'M' is it a M 0033 JZ MEMLK yes, go to memory initialization routine 0034 CPI 'D' is it a D 0035 JZ DFILE yes, go to disk file initialization routine 0036 JMP ERRSY must be a syntax error 0037 * parameter scanner error handler 0038 ERRPS MOV A,E move error code 0039 ORA A is it zero 0040 JZ ERRSY yes, use syntax error message 0041 STA ERRCD no, patch error code 0042 * syntax error handler 0043 ERRSY CALL CLOSE close file if open 0044 * Utility error handler 0045 MVI A,0 control word 0046 LXI H,-1 no 2nd line message 0047 CALL UTIL system utility call 0048 DB UXOP explain error 0049 JMP ABORT error return 0050 DB -1 no operation code 0051 ERRCD DB 2AH error code, command syntax error unless patch 0052 * Drastic error handler 0053 ABORT CALL SYS system call, normal return, not used 0054 DB RESOP return to DOS & reset all 0055 * close file routine 0056 CLOSE LDA FINU get file # 0057 ORA A is file # 0 (indicates no files are open) 0058 RZ return if none are open 0059 CALL SYS system call 0060 DB CLOOP close file 0061 DB 0,0,0 error return, not used 0062 RET done 0063 * Parameter scanner routine 0064 PSCNN LXI D,BUFPS point to its buffer 0065 CALL PSCAN parameter scanner 0066 JC ERRPS scanner error 0067 RET done 0068 * address default and delimit checker 0069 ADDF CPI ',' only valid next delimiter 0070 JNZ ERRSY if not must be syntax error 0071 MOV A,C get # of chracters scanned 0072 CPI 0 if zero use 0073 RET . done 0074 * Memory look routine 0075 MEMLK MVI A,PSV convert numeric value 0076 CALL PSCNN scanner routine 0077 CALL ADDF check for proper delimit and default 0078 JZ ADR2 default start addr, get finish addr 0079 XCHG HL holds start addr in binary 0080 SHLD SA store start addr 0081 * get finish address 0082 ADR2 MVI A,PSV convert numeric value 0083 CALL PSCNN scanner routine 0084 CALL ADDF check for proper delimit and default 0085 JZ DBN default finish addr 0086 XCHG HL holds finish addr in binary 0087 SHLD FA store finish addr 0088 * go to it 0089 DBN CALL DBNXT get data to be matched 0090 CALL LOOK look for match 0000 CALL ENDMES print end message 0091 * Normal return to PTDOS 0092 RETN CALL SYS system call 0093 DB RETOP return to system 0094 * Disk file look routine 0095 DFILE MVI A,PSOP open file 0096 CALL PSCNN scanner routine 0097 MOV A,E move file # 0098 STA FINU store it 0099 CALL DBNXT get data to be matched 0100 * go to it 0101 LOPFB CALL READB read a file block from disk 0102 CALL LOOK look for matches 0103 LDA EOFG get end of file flag 0104 CPI EREOF does it match EOF error byte 0105 JNZ LOPFB no, loop again 0000 CALL ENDMES print end message 0106 CALL CLOSE close file if open 0107 JMP RETN all done, return to DOS 0108 * Get data to be matched and store it 0109 DBNXT LXI H,BYTE point to storage area 0110 LOOP PUSH H save addr 0111 MVI A,PSV convert numeric value 0112 CALL PSCNN scanner routine 0113 STA ENDF save delimiter 0114 PUSH PSW save flags 0115 LXI H,NBR point to counter storage 0116 MVI A,9 maximum next to last count 0117 CMP M same as present count 0118 JZ ERRSY error if more than 9 bytes 0119 INR M bump data count 0120 POP PSW retrieve flags 0121 POP H retrieve current storage area addr 0122 JZ DEFG default data 0123 MOV A,D get binary high byte 0124 ORA D is it zero 0125 JNZ ERRSY no, syntax error 0126 MVI M,0 reset data flag 0127 INX H point to data storage location 0128 MOV M,E move data 0129 JMP EDCHK check for end of data 0130 DEFG MVI M,-1 set default data flag 0131 INX H point to data storage location 0132 * check for end of data 0133 EDCHK INX H point to next flag storage location 0134 LDA ENDF get end of data flag 0135 CPI ',' is it a comma? 0136 JZ LOOP yes, more data follows 0137 CPI CR is it a CR 0138 JZ RETD yes, done 0139 CPI ';' is it a semicolon? 0140 JNZ ERRSY no, must be syntax error 0141 RETD LDA NBR done, get last count 0142 STA NM store it here 0143 RET done 0144 * Transfer a file block to memory 0145 READB LDA FINU get file # 0146 LXI D,MBUF point to its buffer 0147 LXI B,BLKSZ load transfer count 0148 CALL SYS system call 0149 DB RBLOP read data 0150 STA EOFG error return, set EOF flag 0151 MOV H,B normal return, BC holds the remaining 0152 MOV L,C unsucessful transfer count (normally 0) 0153 SHLD TRFCT store it 0154 * Determine end addr of data transfered to buffer 0155 * subtract remaining transfer count from block size 0156 LXI B,BLKST point to block size storage 0157 LXI H,TRFCT point to remaining transfer count, normally 0 0158 XRA A clear carry bit 0159 LDAX B get low block size byte 0160 SBB M subtract transfer count remaining 0161 MOV E,A save low transfer count 0162 INX B point to high byte 0163 INX H same 0164 LDAX B get high block size byte 0165 SBB M subtract transfer count remaining 0166 MOV D,A save high transfer count 0167 LXI H,MBUF get start addr of file buffer 0168 SHLD SA store it 0169 DAD D add actual transfer count and start addr 0170 SHLD FA store end address 0171 RET done 0172 * set up look parameters 0173 LOOK LHLD FA get finish addr 0174 PUSH H transfer finish 0175 POP B address to BC 0176 * find first byte of match 0177 LOOK1 LXI D,BYTE DE point to flag-data buffer 0178 LHLD SA HL holds start addr 0179 LDAX D get flag for next data byte 0180 STA FLAG save flag byte for later 0181 INX D point to data byte 0182 LDAX D hex data, ignore if preceeding flag is set high 0183 STA DBST save data in case we want it (flag=0) 0184 LDA NBR get total # of bytes to be matched 0185 STA NUM store here 0186 CALL ENCK check for finish 0000 RZ . search is complete (address match) 0187 LDA FLAG get flag byte back 0188 ORA A is it high 0189 JNZ LOOK2 high? then ignore hex data & jump 0190 LDA DBST retrieve data byte to be matched 0191 CMP M compare with that located at SA 0192 JZ LOOK2 yes? match look at next memory byte 0193 INX H no match so check next memory location 0194 SHLD SA store next addr 0195 CALL INCT increase disk byte 0196 JMP LOOK1 start over with one addr higher 0197 * set up for next check 0199 LOOK2 CALL INCT increase disk byte count 0200 INX H point to next memory location 0201 SHLD SA store next addr 0202 DCX H restore addr pointer to start of match 0203 * check following data bytes for complete match 0204 LOOK3 CALL FIN chk for complete match & print? 0205 INX H point to next memory location 0206 INX D point to next flag byte 0207 LDAX D fetch flag byte 0208 INX D point to next data 0209 ORA A see if flag is high 0210 JNZ LOOK3 yes, hex data following is a forced match 0211 LDAX D no, so fetch data byte 0212 CMP M same as that in memory? 0213 JZ LOOK3 yes, loop checking for a complete match 0214 JMP LOOK1 no, so start over one addr higher 0215 * disk byte count routine 0216 INCT PUSH H save start address temporarily 0217 LHLD COUNT get count of bytes looked at 0218 INX H increase count by one 0219 SHLD COUNT store updated count 0220 POP H restore start address 0221 RET . done 0222 * Print addr & matched bytes routine 0223 PRT LHLD SA get start address of match + 1 0224 DCX H addr of ok byte 0225 SHLD SA store start addr of match 0226 LDA FINU get disk file # 0227 ORA A is it a zero 0228 JZ MEMAD yes, must match in memory 0229 LHLD COUNT no, load disk file counter 0230 MEMAD MOV A,H get high addr byte 0231 PUSH H save low for later 0232 CALL HOUT convert high addr byte to hex & print 0233 POP H retrieve low addr byte 0234 MOV A,L get ready to 0235 CALL HOUT convert low addr byte to hex & print 0236 MVI B,' ' space 0237 CALL CHOUT print it 0238 LXI H,NBR get # of matched bytes 0239 MOV C,M store in C 0240 LHLD SA point to start addr of found matched data 0241 * print hex data found there 0242 PRT1 MOV A,M get first byte 0243 PUSH H save addr 0244 CALL HOUT convert & print hex byte 0245 MVI B,' ' space 0246 CALL CHOUT print it 0247 DCR C decrease matched byte count by 1 0248 LXI H,NM point to # of matched bytes print counter 0249 MOV M,C update counter 0250 POP H retrieve memory address 0251 XRA A zero A 0252 CMP C counter zero yet 0253 JZ PRT2 yes, chk print position 0254 INX H point to next memory location 0255 JMP PRT1 loop again 0256 * chk print position 0257 PRT2 LHLD SA get matched addr 0258 INX H point to next start chk location 0259 SHLD SA store it 0260 CALL POS check print position for CR,LF if needed 0261 JMP LOOK done printing, look for more matches 0262 * Message area 0263 MESNOM ASC 'No matches found' 0264 DB CR 0265 MSYNE ASC 'Command syntax error' 0266 DB CR 0267 * This routine checks for HL equal to finish address 0268 ENCK MOV A,B finish addr high byte 0269 CMP H compare with checked addr high byte 0270 RNZ return if not complete 0271 MOV A,C finish addr low byte 0272 CMP L compare with checked addr low byte 0273 RNZ return if not complete 0000 RET . zero set indicates address match 0275 ENDMES LDA NM get # of matched bytes print counter 0276 CPI 0 zero? must have found a match 0277 JZ FINZ yes, return with zero set 0278 LXI H,MESNOM point to 'no match message' 0279 CALL STOUT print message 0280 FINZ CALL CRLF print CR & LF 0281 RET . return with zero set 0282 * Check for completion of byte match 0283 FIN LDA NUM get # of bytes matched counter 0284 DCR A decrease by one 0285 STA NUM replace # in memory 0286 RNZ return if not zero 0287 POP PSW complete match so get rid of return addr on stack 0288 JMP PRT print it, then look some more 0289 * Output routine, ASC chr in B & in A on return 0290 CHOUT LDA PPOS get print position 0291 INR A increase by 1 0292 STA PPOS put it back 0293 MOV A,B get character to print 0294 CALL CONOUT print it via DOS chr out routine 0295 RET done 0296 * Print carriage return & line feed 0297 CRLF XRA A zero A 0298 STA PPOS set print position counter back to zero 0299 MVI B,CR carriage return 0300 CALL CHOUT print CR 0301 MVI B,LF line feed 0302 CALL CHOUT print LF 0303 RET done 0304 * Keep track of print column routine 0305 POS LDA PPOS what is print position 0306 CPI 54 if over 54 places 0307 JP CRLF then we need a CR LF & reset print position 0308 MVI B,' ' otherwise we will print 2 spaces 0309 CALL CHOUT print it 0311 JMP CHOUT etc 0312 * Binary to ASC hex conversion & print routine 0313 HOUT CALL BINH convert A to hex & store in HCON 0314 LXI H,HCON point to hex chr storage 0315 CHOT MOV B,M get first hex chr 0316 CALL CHOUT print it 0317 INX H point to next hex chr 0318 MOV B,M get it 0319 CALL CHOUT print it 0320 RET done 0321 * Binary (in A) to hex conversion subroutine 0322 BINH LXI H,HCON point to storage 0323 MOV B,A store binary # for later 0324 RAR set up 0325 RAR to convert 0326 RAR upper 0327 RAR 4 bits 0328 CALL BIN1 convert them to hex 0329 MOV M,A store first hex chr at HCON 0330 INX H point to next storage location 0331 MOV A,B set up to convert lower 4 bits 0332 CALL BIN1 convert them to hex 0333 MOV M,A store last hex chr at HCON+1 0334 RET done 0335 BIN1 ANI 0FH mask off upper 4 for bits 0336 ADI 30H add ASC bias 0337 CPI 3AH 9 or less 0338 RC yes, done 0339 ADI 7 add bias for letters A thru F 0340 RET done 0341 * String print routine until CR delimiter 0342 STOUT MOV B,M fetch chr 0343 MVI A,CR carriage return, delimiter 0344 CMP B chk for delimit 0345 RZ yes, done 0346 CALL CHOUT print chr 0347 INX H point to next chr 0348 JMP STOUT loop 0349 * Storage area 0350 NBR DB 0 # of bytes to match 0351 NUM DB 0 # of bytes matched counter 0352 HCON DW 0 temporary hex hyte storage area for HOUT 0353 NM DB 0 # of matched bytes print counter 0354 SA DW 0 start addr storage 0355 FA DW 0FFFFH finish addr storage 0356 FLAG DB 0 temporary flag byte storage 0000 DBST DB 0 temporary data byte storage location 0357 PPOS DB 0 print position storage, zero after CR LF 0358 EOFG DB 0 end of file flag 0359 TRFCT DW 0 transfer file count storage 0360 BLKST DW BLKSZ file block size storage 0361 ENDF DB 0 field delimiter storage 0362 FINU DB 0 disk file # storage, also indicates disk search 0363 COUNT DW -1 disk file position counter 0364 BYTE DS 19 9 flag bytes, interspaced with 9 hex bytes 1ext 0365 BUFPS DS 20 parameter scanner buffer 0366 MBUF DS BLKSZ 0367 STACK EQU $+32 0368 END