	.TITLE	RPFind
	.IDENT	/MRHV01/
	.SBTTL	INTRO PAGE
	.LIST	MEB
;
;This program is designed to search a full rp disk to search for a given
;bit pattern of a given word of each block
;
;MCR>RPF XXX,YYY
;
;WHERE:	XXXXXX is the work one wishes to search for
;       YYYYYY is the bye offset in the block to check
;
;
;
;
MASK:	.word	0		;mask for word search
OFFSET:	.word	0		;byte offset into block
;
;
	.MCALL	QIOW$,DIR$,EXIT$S,GMCR$
.PAGE
.SBTTL	THE CODE
;
;FIRST SET THINGS UP
;
START:	DIR$	#GETMCR		;SO WE RECALL THE CALLER
	MOV	#GETMCR+G.MCRB+4,R0	;POINT TO ASCII BUFFER
	JSR	PC,$COTB	;CONVERT ASCII NUMBER TO BINARY
	MOV	R1,MASK		;save search mask
	JSR	PC,$COTB	;CONVERT 2nd number
	MOV	R1,OFFSET	;save byte offset into buffer
;
				;NOW START SEEKING
	CLR	REAQIO+Q.IOPL+6	;Start at block 0
	CLR	REAQIO+Q.IOPL+10 ;Start at block 0
1$:	DIR$	#REAQIO		;read block
	TSTB	IOSB		;Did the read go ok ?
	BPL	2$		;Br if it did
	JSR	PC,ERROR	;report error
	BR	3$		;and skip check
2$:	MOV	OFFSET,R5	;compare words
	ADD	#READBF,R5
	CMP	(R5),MASK	;found the word ?
	BNE	3$		;no such luck
	JSR	PC,FOUND	;yes, report it
3$:	CMP	REAQIO+Q.IOPL+6,#BLOCKH ;end of disk ?
	BNE	4$		;no, go again
	CMP	REAQIO+Q.IOPL+10,#BLOCKL ;end of disk ?
	BNE	4$		;no
	EXIT$S			;YES ALL DONE
4$:	ADD	#1,REAQIO+Q.IOPL+10 ;can't use INC it doesnt set C bit
	ADC	REAQIO+Q.IOPL+6
	BR	1$		;AND LOOP
.page
.sbttl	Reporting Subroutines
;
;SUB TO REPORT found word
;
FOUND:	MOV	#P1,R0		;POINT TO BUFFER
	MOV	REAQIO+Q.IOPL+6,R1 ;GET HIGH PART OF BLOCK NUMBER
	CLR	R2		;INDICATE 0 SUPPRESSION
	JSR	PC,$CBOMG	;CONVERT NUMBER
	MOVB	#',,(R0)+	;PUT IN A COMMA
	MOV	REAQIO+Q.IOPL+10,R1 ;GET LOW PART OF BLOCK NUMBER
	INC	R2		;MAKE THIS 6 DIGITS
	JSR	PC,$CBOMG	;CONVERT IT
	MOV	#P2,R0		;POINT TO BUFFER
	MOV	MASK,R1		;GET mask word
	JSR	PC,$CBOMG	;CONVERT IT
	MOV	#P3,R0		;POINT TO BUFFER
	MOV	OFFSET,R1	;get offset
	JSR	PC,$CBOMG	;CONVERT byte offset
	MOV	#FOUNDM,QIO+Q.IOPL ;FILL IN MESSAGE START IN DPB
	MOV	#FOUNDL,QIO+Q.IOPL+2 ;AND LENGTH
	DIR$	#QIO		;AND REPORT ERROR
	RTS	PC		;AND RETURN
;
;SUB TO REPORT Read error
;
ERROR:	MOV	#E1,R0		;POINT TO BUFFER
	MOV	REAQIO+Q.IOPL+6,R1 ;GET HIGH PART OF BLOCK NUMBER
	CLR	R2		;INDICATE 0 SUPPRESSION
	JSR	PC,$CBOMG	;CONVERT NUMBER
	MOVB	#',,(R0)+	;PUT IN A COMMA
	MOV	REAQIO+Q.IOPL+10,R1 ;GET LOW PART OF BLOCK NUMBER
	INC	R2		;MAKE THIS 6 DIGITS
	JSR	PC,$CBOMG	;CONVERT IT
	MOV	#REAERR,QIO+Q.IOPL ;FILL IN MESSAGE START IN DPB
	MOV	#REALEN,QIO+Q.IOPL+2 ;AND LENGTH
	DIR$	#QIO		;AND REPORT ERROR
	RTS	PC		;AND RETURN
.PAGE
.SBTTL	DATA AREAS
;
;DEFINE SOME NEEDED VARIABLES
;
READSZ=1000			;READ ONE BLOCK
;				;MAX BLOCK #
BLOCKH=2
BLOCKL=1137			;THESE TAKEN FROM PUD OF DP DEVICE
;
;
;QIO FOR MESSAGES TO TI
;
QIO:	QIOW$	IO.WVB,5,1,,,,<0,0,40>
;
;NOW POSSIBLE MESSAGES
;
FOUNDM:	.ASCII	/At Block Number /
P1:	.ASCII	/N,NNNNNN Found /
P2:	.ASCII	/NNNNNN At offset /
P3:	.ASCII	/NNNNNN/
	FOUNDL=.-FOUNDM
;
;
REAERR:	.ASCII	/Read error at block Number /
E1:	.ASCII	/N,NNNNNN/
	REALEN=.-REAERR
	.even
;
;THE DISK READ QIO
;
REAQIO:	QIOW$	IO.RLB,2,1,,IOSB,,<READBF,READSZ,0,0,0>
;
IOSB:	.WORD	0,0		;RETURNED STATUS
;
GETMCR:	GMCR$			;GET MCR DPB
;
;MISC VARIABLES
;
READBF:	.BLKB	READSZ		;BUFFER FOR READING 1. BLOCK
	.END	START
