/OCOMP--OCTAL COMPARE AND DUMP

/BY:
/	DENNIS MCGHIE
/	DIVISION OF CARDIOVASCULAR SURGERY
/	STANFORD MEDICAL CENTER
/	STANFORD, CALIF. 94305

/MODIFIED BY:
/
/	JIM CRAPUCHETTES
/	FRELAN ASSOCIATES
/	P.O. BOX 298
/	MENLO PARK, CALIF. 94025

/	OCOMP IS AN OS/8 UTILITY PROGRAM USED TO
/  COMPARE OR DUMP OS/8 FILES.  BOTH MASKING AND
/  SEARCHING ARE ALLOWED.  THE MASK IS ENTERED BY
/  THE "=" OPTION (ONLY THE LEAST SIGNIFICANT 12
/  BITS ARE USED).  THE SEARCH FEATURE IS SPECIFIED
/  BY THE "/S" OPTION.  ALL OUTPUT IS IN OCTAL.
/
/	THE THREE MODES OF OPERATION ARE:
/
/  1.	COMPARE:  TWO INPUT FILES SPECIFIED AND ARE
/	COMPARED WORD-FOR-WORD UNDER THE MASK IF
/	ANY IS SPECIFIED (IF NONE IS SPECIFIED, ALL
/	BITS ARE COMPARED).  ANY DIFFERENCES CAUSE
/	THE WORD FROM FILE #1 (IN OCTAL) TO BE PUT
/	IN THE OUTPUT FILE.
/
/  2.	DUMP:  ONLY ONE INPUT FILE IS SPECIFIED AND
/	IT IS DUMPED (IN OCTAL) ON THE OUTPUT FILE.
/	IF A MASK IS SPECIFIED, ONLY THOSE WORDS
/	WITH ALL MASKED BITS IN THE 1 STATE ARE
/	OUTPUT.
/
/  3.	SEARCH:  ONLY ONE INPUT FILE IS SPECIFIED,
/	ALONG WITH "/S".  ONLY THOSE WORDS EQUAL TO
/	THE MASK ARE DUMPED ON THE OUTPUT FILE.
	EJECT


/OTHER PROGRAM ACTIONS:
/
/  A.	SPECIFYING NO INPUT AND/OR OUTPUT FILES
/	WILL CAUSE A RETURN TO THE COMMAND DECODER.
/
/  B.	"USER ERROR ..." MESSAGES WILL BE OUTPUT
/	UNDER THE FOLLOWING CONDITIONS:
/
/	ERROR		CONDITION
/	  1	MORE THAN TWO INPUT FILES.
/	  2	OUTPUT FILE TOO SMALL.
/	  3	OUTPUT HANDLER FETCH OR OUTPUT FILE
/		  ENTER FAILED.
/	  4	INPUT HANDLER FETCH FAILED.
/	  5	INPUT FILE #1 ERROR.
/	  6	INPUT FILE #2 ERROR.
/	  7	OUTPUT FILE ERROR.
/	  8	OUTPUT FILE CLOSE FAILED.
/
/  C.	"FILE 2 IS LONGER THAN FILE 1" WILL BE OUTPUT
/	IN THE OUTPUT FILE IF THIS IS TRUE.  IF FILE
/	#1 IS LONGER THAN FILE #2, THE REMAINDER OF
/	FILE #1 WILL BE DUMPED TO THE OUTPUT FILE.
/
/  D.	"NOTHING OUTPUT" WILL BE PUT IN THE OUTPUT
/	FILE IF NOTHING ELSE IS OUTPUT.
/
/  E.	THE PROGRAM LEAVES THE USR IN CORE AFTER IT
/	IS CALLED IN.
/
/  F.	THE DEFAULT INPUT EXTENSION IS ".SV".
/
/  G.	THE PROGRAM IS NOT RESTARTABLE.

/COMMAND DECODER USAGE:
/
/	.R OCOMP
/	*OFILE<IFILE1[,IFILE2] [/S] [=NNNN]
/
/	ITEMS IN [...] ARE OPTIONAL.


/ASSEMBLY INFORMATION:
/
/	.R PAL8
/	*OCOMP<OCOMP/L/8/9=12000$
/	.SAVE ... OCOMP
/(OCOMP) OCTAL COMPARE AND DUMP 

/PAGE 0 DEFINITIONS:

IWD1=	1
IWD2=	2
MASK=	3

XR11=	11
TMP=	12
XR13=	13

BLEFT1=	16
BLEFT2=	17
DUMPSW=	20
OWD=	21
OCNT=	22
RELBLK=	23
LNCNT=	24

IBUF1=	2000	/2000-3777 IN FIELD 0
IBUF2=	4000	/4000-5777 IN FIELD 0
OBUF=	4000	/4000-5777 IN FIELD 1

LBUF=	6000	/LINE BUFFER--IN FIELD 1

/	THE OUTPUT AND TWO INPUT HANDLERS CAN ALL
/  BE 2 PAGE HANDLERS.  ALLOCATION AS FOLLOWS:
/
/  OUTPUT	06200-06577
/  INPUT #1	06600-07177
/  INPUT #1	07200-07577


	FIELD 1
	*2000

A7600=	.

START,	7600		/(OPR2 CLA)
	JMS I (7700	/CALL USR
	10		/USRIN
STAR1,	JMS I (200	/CALL USR
	5		/DECODE
	2326		/"SV"
	TAD I A7600
	SZA CLA
	TAD I A7617
	SNA CLA
	JMP STAR1	/NO OUTPUT &/OR INPUT FILE
	JMS SETUP	/SET NO-RESTART BIT, ETC.
	TAD I A7600
	JMS I (200
	1		/FETCH
OHANA,	6201		/BECOMES ENTRY POINT
	JMP ERROR3	/FETCH FAILED
	TAD I A7600
	JMS I (200
	3		/ENTER
STBLK,	7601		/NAME POINTER(BECOMES ST BLK)
MLEN,	0		/BECOMES -LENGTH OF FILE
	JMP ERROR3	/ENTER FAILED
	TAD STBLK
	DCA OBLK
	TAD I A7617
	JMS I (200
	1		/FETCH
INHAN1,	6601		/BECOMES ENTRY POINT
	JMP ERROR4	/FETCH FAILED
	TAD (LBUF-1
	DCA XR13	/LINE BUFFER POINTER
	JMS BLGET
A7617,	  7617
	DCA BLEFT1
	TAD I (7620
	DCA INBLK1
	TAD I A7621
	SNA
	JMP DUMP	/NO 2ND, JUST DUMP
	JMS I (200
	1		/FETCH
INHAN2,	7201		/BECOMES ENTRY POINT
	JMP ERROR4	/FETCH FAILED
	JMS BLGET
A7621,	  7621
	DCA BLEFT2
	TAD I (7622
	DCA INBLK2
	JMP DOIT


READ,	0
	CIF 0
	JMS I INHAN1
	1000	/FUNCTION (INPUT, 10 PAGES, FIELD 0)
IBUFA1,	IBUF1
INBLK1,	0
	JMP ERROR5	/INPUT #1 ERROR
	TAD IBUFA1
	DCA IWD1
	TAD IBUFA2
	DCA IWD2
	TAD (4
	TAD INBLK1
	DCA INBLK1
	TAD DUMPSW
	SZA CLA
	JMP I READ	/ONLY ONE INPUT
	CIF 0
	JMS I INHAN2
	1000
IBUFA2,	IBUF2
INBLK2,	0
	JMP ERROR6	/INPUT #2 ERROR
	TAD (4
	TAD INBLK2
	DCA INBLK2
	JMP I READ


WRITE,	0
	CLA CLL
	TAD (4
	TAD MLEN
	DCA MLEN
	SZL
	JMP ERROR2	/NO MORE ROOM
	CIF 0
	JMS I OHANA
	5010		/FUNCT. (OUTPUT,10 PAGES,FIELD 1)
OBUFA,	OBUF		/BUFFER ADDRESS
OBLK,	0
	JMP ERROR7	/OUTPUT ERROR
	TAD (4
	TAD OBLK
	DCA OBLK
	JMS OINIT
	JMP I WRITE


PAGE
/IF CURRENT LINE IS NON-BLANK (NONBL NOT 0)
/  OR PREVIOUS LINE WAS NON-BLANK (PREBL NOT 0)
/  THEN PACK CURRENT LINE BUFFER INTO OUTPUT BUFFER

CRLF2,	0
	TAD NONBL
	SNA CLA
	JMP CR5		/BLANK LINE
	TAD HOUT
	SNA CLA
	JMS HEADER
	TAD NONBL
	CMA
	TAD (LBUF-1	/BUFFER STARTS AT 6000
	DCA CHCNT
	TAD (LBUF-1
	DCA XR13
	JMP CR2
CR1,	TAD I XR13
	JMS PACK
CR2,	ISZ CHCNT
	JMP CR1
	JMS CRLF
CR5,	TAD (LBUF-1
	DCA XR13	/RESET POINTER
	DCA NONBL
	JMP I CRLF2

HOUT,	0
NONBL,	0		/NON-BLANK LINE SW
CHCNT,	0


OCTOUT,	0
	DCA TEMP
	TAD I OCTOUT
	DCA WPAK
	TAD (-4
	DCA DIGCNT
Q6,	TAD TEMP
	RTL
	RAL
	DCA TEMP
	TAD TEMP
	RAL
	AND (7
	TAD (260
	JMS I WPAK
	ISZ DIGCNT
	JMP Q6
	ISZ OCTOUT
	JMP I OCTOUT

WPAK,	0
TEMP,	0
DIGCNT,	0


MESOUT,	0
	TAD I MESOUT
	ISZ MESOUT
	DCA XR11
MESO1,	TAD I XR11
	SNA
	JMP I MESOUT
	JMS PACK
	JMP MESO1


PACK,	0	/OS/8 OUTPUT PACKING ROUTINE
	AND (377
	JMP I PSW
PSW,	.+2
	JMP I PACK
	DCA I OWD	/1ST OF TRIP
	JMS PSW
	DCA PSAV	/2ND OF TRIP
	JMS PSW
	DCA PSW		/3RD OF TRIP
	TAD PSW
	CLL RTL
	RTL
	AND (7400
	TAD I OWD
	DCA I OWD	/PACK 1ST HALF OF PAIR
	ISZ OWD
	TAD PSW
	CLL RTR
	RTR
	RAR
	AND (7400
	TAD PSAV
	DCA I OWD	/PACK 2ND HALF
	ISZ OWD
	ISZ OCNT
	JMP PBACK
	JMS WRITE	/BUFFER FULL
PBACK,	JMS PSW
	JMP PSW+2

PSAV,	0


LINOUT,	0
	TAD (-3
	DCA BUNCH
	TAD IWD1
	AND (377
	JMS OCTOUT
	LPACK
LIN5,	TAD (-4
	DCA GROUP
	TAD (240
	DCA I XR13	/LPACK
LIN6,	TAD (240
	DCA I XR13	/LPACK
	JMS COMPAR
	ISZ GROUP
	JMP LIN6
	ISZ BUNCH
	JMP LIN5
	JMP I LINOUT

BUNCH,	0
GROUP,	0


PAGE
DUMP,	ISZ DUMPSW
	TAD I (7646
	DCA MASK
	TAD I (7644	/CHECK FOR /S
	AND (40
	SNA CLA
	JMP DOIT
	ISZ CDMP+1	/MAKE THE "CMA" A "CIA"
	TAD (TAD MASK	/ & CHANGE THE "AND" TO A
	DCA CDMP+2	/ "TAD".
DOIT,	TAD RELBLK	/IS IT A MULTIPLE OF 4?
	AND (3
	SNA CLA		/NO, SKIP THE READ
	JMS READ	/YES, REFILL BUFFERS
DO1,	DCA HOUT	/=0 HEADER NOT YET OUT
	TAD (-25
	DCA LNCNT
DO2,	JMS LINOUT
	JMS CRLF2
	ISZ LNCNT
	JMP DO2
	CLA STL RTL
	JMS LINOUT
	JMS CRLF2
	ISZ BLEFT2
	JMP DO3
	ISZ DUMPSW	/2ND FILE EMPTY
	TAD I (7646
	DCA MASK
DO3,	ISZ RELBLK	/BUMP RELATIVE BLK #
	ISZ BLEFT1
	JMP DOIT
	TAD DUMPSW	/1ST FILE EMPTY
	SZA CLA
	JMP DONE
	JMS MESOUT	/2ND LONGER THAN 1ST
	MESE-1
	JMS CRLF
DONE,	TAD ANYOUT
	SZA CLA
	JMP DONE1-1
	JMS MESOUT
	MESN-1		/'NOTHING OUTPUT'
	JMS CRLF
	TAD (232	/^Z
DONE1,	JMS PACK
	TAD OWD
	CIA
	TAD OBUFA
	SZA CLA		/DUMPED BUFFER YET?
	JMP DONE1	/NO--FILL WITH 0'S
	TAD STBLK
	CIA
	TAD OBLK
	DCA NOUT
	TAD I (7600
	JMS I (200
	4		/CLOSE
	7601		/NAME PTR
NOUT,	0		/# BLKS IN OUTPUT
	JMP ERROR8	/CLOSE FAILED!!
GIVEUP,	CDF CIF 0
	JMP I (7600	/RETN TO OS/8


COMPAR,	0
	CDF 0
	TAD DUMPSW
	SZA CLA
	JMP CDMP
	TAD I IWD1
	AND MASK
	DCA TMP
	TAD I IWD2
	AND MASK
	CIA
	TAD TMP
	SZA CLA
	JMP COMB	/DIDN'T MATCH, DUMP IT
/
COMC,	CDF 10
	TAD (240
	DCA I XR13	/LPACK
	TAD (240
	DCA I XR13
	TAD (240
	DCA I XR13
	TAD (240
	DCA I XR13
COMA,	ISZ IWD1
	ISZ IWD2
	JMP I COMPAR
/
/IN SEARCH ("/S" SPECIFIED), THE "CMA" IS CHANGED
/  TO "CIA", THE "AND" IS CHANGED TO A "TAD", AND
/  THE WORD MUST BE EQUAL TO THE MASK TO MATCH.
/
CDMP,	TAD I IWD1	/IN DUMP, MASK BITS MUST BE
	CMA
	AND MASK	/ ON IN DATA.
	SZA CLA		/SAME, DUMP IT
	JMP COMC	/DIFF, SPACE IT
COMB,	TAD I IWD1
	CDF 10
	JMS OCTOUT
	LPACK
	TAD XR13	/NOT 0 IF NON-BLANK OUTPUT
	DCA NONBL	/ ON THIS LINE.
	JMP COMA


PAGE
CRLF,	0
	TAD (215
	JMS PACK
	TAD (212
	JMS PACK
	ISZ LINES
	JMP I CRLF
	TAD (214	/FORM FEED
	JMS PACK
	TAD (-70
	DCA LINES
	JMP I CRLF
LINES,	-70


LPACK,	0
	DCA I 13
	JMP I LPACK


OINIT,	0
	TAD OBUFA
	DCA OWD
	TAD (-1000
	DCA OCNT
	JMP I OINIT


BLGET,	0
	TAD I BLGET	/GET ADDR
	ISZ BLGET
	DCA OINIT
	TAD I OINIT	/GET DATA FROM ADDR
	RTR
	RTR
	AND (377
	SZA
	TAD (7400
	JMP I BLGET


/ROUTINE TO SET NO-RESTART BIT IN JSW AND SET UP
/  THE MASK.

SETUP,	0
	TAD I (7623	/A 3RD INPUT SPECIFIED?
	SZA CLA
	JMP ERROR1	/YES, BAD!
	JMS OINIT	/OK, SET UP POINTERS
	CDF 0
	TAD I (7746
	CMA
	AND (6777
	CMA
	DCA I (7746
	CDF 10		/RESET D.F.
	TAD I (7646	/GET 1ST "=" WORD
	SNA		/USE AS IS IF NON-0
	CMA		/ OTHERWISE USE ALL 1'S.
	DCA MASK	/SET UP THE MASK
	DCA RELBLK	/SET THESE TO 0
	DCA DUMPSW
	JMP I SETUP


HEADER,	0
	JMS CRLF
	JMS CRLF
	JMS MESOUT
	MESB-1		/'RELATIVE BLOCK '
	TAD RELBLK
	JMS OCTOUT
	PACK
	JMS MESOUT
	MESL-1		/'   ( ABSOLUTE BLOCK '
	TAD RELBLK	/ABS. BLK= REL. BLK
	TAD I (7620	/ + START BLK.
	JMS OCTOUT
	PACK
	TAD DUMPSW
	SZA CLA
	JMP HE1		/ONLY ONE FILE
	JMS MESOUT
	MESS-1		/' AND '
	TAD RELBLK
	TAD I (7622	/AS ABOVE
	JMS OCTOUT
	PACK
HE1,	JMS MESOUT
	MESR-1		/' )'
	JMS CRLF
	ISZ HOUT	/NOT 0, HEADER OUTPUT
	ISZ ANYOUT	/0, NOTHING OUTPUT
	JMP I HEADER
ANYOUT,	0


PAGE
ERROR8,	ISZ ERROR
ERROR7,	ISZ ERROR
ERROR6,	ISZ ERROR
ERROR5,	ISZ ERROR
ERROR4,	ISZ ERROR
ERROR3,	ISZ ERROR
ERROR2,	ISZ ERROR
ERROR1,	ISZ ERROR
ERROR0,	JMS I (200
	7	/ERROR
ERROR,	0	/ERROR NUMBER
	CDF CIF 0
	JMP I (7600	/ALWAYS RETURN TO SYSTEM.


MESB,	322	/'RELATIVE BLOCK '
	305
	314
	301
	324
	311
	326
	305
	240
	302
	314
	317
	303
	313
	240
	0


MESE,	306	/'FILE 2 IS LONGER THAN FILE 1!'
	311
	314
	305
	240
	262
	240
	311
	323
	240
	314
	317
	316
	307
	305
	322
	240
	324
	310
	301
	316
	240
	306
	311
	314
	305
	240
	261
	241
	0


MESL,	240	/'   ( ABSOLUTE BLOCK '
	240
	240
	250
	240
	301
	302
	323
	317
	314
	325
	324
	305
	240
	302
	314
	317
	303
	313
	240
	0


MESN,	316	/'NOTHING OUTPUT'
	317
	324
	310
	311
	316
	307
	240
	317
	325
	324
	320
	325
	324
	0


MESR,	240	/' )'
	251
	0


MESS,	240	/' AND '
	301
	316
	304
	240
	0

$$$$$
