	.title IMGSUB
;
	.ident /color/	;small subs for IMG
;
;	3-dec-79 SMASH consolodated
;	27-nov-79 add MOVBITS to move graphic bit from BUFT1>BUF
;	modified 9-nov-79 to use TRILOG printer /CP switch
;	modified 9-nov-79 to include /MO:* as multiply bytes
;
;	macro library calls
	.mcall CSI$
	.mcall READ$,QIO$S,WTSE$S
	CSI$			;define CSI control blk offsets
;
;ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss
;	small service codes
;sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss
;	this code test switches and increases number of lines buffered
;	during xfer accordingly.
;no speed up possible when convolving kernel used
;some speed up when modify used
;full speed up when simple switches like /bs are used
FASTER::			;
	jsr pc,$SAVAL	;save all regs
	mov BUFIN,BYTSIN	;load bytes to be xfered normally
;
;
	CMP NLINES,#8.	;TST TO SEE IF TOTAL NUMBER OF LINES IS GT THAN 8
	BLT 130$	;DONT SPEED UP IF ITS COLOR OR FUNCTION MEMORY
;
;
;			if tape drive is used no multiple buffering
;			is posssible because only one raster line per 
;			record is used.
	cmp LUNIN,DEVIC3	;tape drive ?
	beq 130$
	cmp LUNOUT,DEVIC3	;tape drive ?
	beq 130$
;			tst for any switches used ?
	tst $SWTHO	;is any output switch used ?
	bne 80$		;if so dont multiply data xfer size
	tst $SWTHI	;is any input switch used ?
	bne 80$		;if so dont multiply data xfer size
	br 100$		;no switches go use max buffer sizes
80$:			;here test switches ,some prevent increaseing 
			;the size of the buffer.
	BIT #GRAMSK,$SWTHO		;TMP DONT ALLOW BIG BUFFS FOR GR'S
	BNE 105$
	BIT #GRAMSK,$SWTHI		;TMP DONT ALLOW BIG BUFFS FOR GR'S
	BNE 105$
;
	BIT #SPLMSK!CPTMSK,$SWTHO		;DONT MULT BUF SIZE IF SPOOL
	BNE 130$
	bit #YINMSK!NUMMSK,$SWTHO		;tset for not powerzs of 2
	bne 130$				;if not then no speedup
	bit #YINMSK!NUMMSK,$SWTHI		;tset for not powerzs of 2
	bne 130$				;if not then no speedup
	bit #CVLMSK!DSKMSK!KERMSK,$SWTHI	;test CONVOLVER ?
	bne 130$				;if so no speed up possible
;
	bit #MODMSK,$SWTHO			;tst MODIFY ?
	bne 105$				;if so then only half
						;speed up possible
100$:			;
;			set up for multiple raster lines per xfer
	mov #8.,LINES	;load # of lines to xfer in one blk
	br 110$		;go mult every thing by LINES
			;this number of raster lines may vary from machine
			;to machine .
105$:			;speed up only half as much with MODIFY
	mov #4.,LINES
	br 110$
;
110$:			;
	mov SINCYO,R5		;load start value
	mul LINES,R5	;multiply variable by # of lines per xfer
	mov R5,SINCYO
;
	mov YINX,R5		;load start value
	mul LINES,R5	;multiply variable by # of lines per xfer
	mov R5,YINX
;
	mov BUFSIZ,R5		;load start value
	mul LINES,R5	;multiply variable by # of lines per xfer
	mov R5,BUFSIZ
;
	mov BYTSOT,R5		;load start value
	mul LINES,R5	;multiply variable by # of lines per xfer
	mov R5,BYTSOT
;
	mov BYTSIN,R5		;load start value
	mul LINES,R5	;multiply variable by # of lines per xfer
	mov R5,BYTSIN
;
130$:				;
	rts pc
;
;*********************************************************************
;
REDLIN::			;read in a raster line from input file
				;uses BYTSIN,YIN and a buffer address
				;
	cmp LUNIN,DEVIC1	;tst for special devices that are treat
	beq 106$		;with care
	cmp LUNIN,DEVIC3	;tst for MAG TAPE that are treat
	beq 104$		;with care
	cmp LUNIN,DEVIC2		;need to have special cases here
	bne 110$		;not special go assume = disk
;
103$:				;CD: device
	QIO$S #IO.RLB,#4,#4,,#IOSB4,,<#BUF,BYTSIN,,,YIN,X>
	bcs 120$		;if directive error 
	bcc 130$		;go wait for done
;
104$:				;MT: device
	QIO$S #IO.RLB,#4,#4,,#IOSB4,,<#BUF,520.,,,YIN,X>
			;always read for 520 bytes ignore small rec err
	bcs 120$		;if directive error 
	bcc 130$		;go wait for done
;
106$:				;BM: deviceS
	QIO$S #IO.RLB,#4,#4,,#IOSB4,,<#BUF,BUFSIZ,,,YIN,X>
	bcs 120$		;if directive error 
	bcc 130$		;go wait for done
;
110$:	READ$ #TTLDMY,#BUF,BUFSIZ,#INVBN,,#IOSB4	;read virtual blk
	bcc 130$
;
;
120$:	call $ERMSG
	INQERR			;read error on QUEUING  input
	jmp 300$		;if error go do output any way!
;
125$:				;error in actual Input XFER
	call $ERMSG
	INPERR			;input error
	jmp 300$
;
130$:	WTSE$S #4		;wait for I/O to complete
	bcs 125$		; failed go report or success ?
;
140$:	tst INFILE		;tst for files-11 or not
	beq 141$		;if not
	movb F.ERR(R0),IOSB4	;bastards dont init IOSB as documented
;
141$:	cmpb IOSB4,#IS.SUC		;success ?
	beq 150$
	cmpb IOSB4,#IE.EOF	;test for end of file on input?
	beq 142$		;if not its just an error
	cmpb IOSB4,#IE.EOV	;test for end of file on input?
	bne 145$		;if not its just an error
;				;found END OF FILE ON INPUT
142$:	call $ERMSG
	INPEOF		;read END OF FILE on input
	jmp 300$		;go report EOF on input
;
145$:	call $ERMSG
	INPERR		;read error on input
;
150$:	CLC		;clear carry signal all OK read on to caller
	rts pc
;
300$:	SEC		;signal error abort this file to user
	rts pc
;
;
;	DOTLIN is USED by PRINTRONIX to build a single row of dots
;		is used by TRILOG to build 1st row of dots
;
DOTLIN::		;code to take MAXPXL bits and create output for lp:
			;PRINTRONIX type only
	jsr pc,$SAVAL
			;
	mov PC,R5
	add #10,R5		;load addr of arg list
	jsr pc,GRAPHL		;call code to convert bits to ascii bits
	br 5$		; skip over args
	BUFT1		;input dot bits
	BUFTMP		;output printer byte cmds
	MAXPXL		;max number of bits/pixels in raster line
	MAXCHR		;max number of printable characters back out
;
5$:	mov MAXCHR,R0		;load count of printing chars
	mov #BUFTMP,R1
	mov #BUFT1,R2	;store out printer cmds in tmp buffer

10$:	movb (R1)+,(R2)+
	sob R0,10$
;
	mov MAXCHR,RECOUT		;load bytes to output
;
	rts pc
;
;	SECLIN must be called after DOTLIN, for second line, works with it
;
SECLIN::		;code to take MAXPXL bits and create output for lp:
			;2nd LINE of dots called only for TRILOG -1024 rows
			;PRINTRONIX or TRILOG only
	jsr pc,$SAVAL
			;
	mov PC,R5
	add #10,R5		;load addr of arg list
	jsr pc,GRAPHL		;call code to convert bits to ascii bits
	br 5$		; skip over args
	BUFT2		;2nd line is built from same data
	BUFTMP		;2nd line is built in tmp buff
	MAXPXL		;max number of bits/pixels in raster line
	MAXCHR		;max number of printable characters back out
;
5$:	mov MAXCHR,R0		;load count of printing chars
	mov #BUFTMP,R1		;use TMP as input of cmds
	mov #BUFT2,R2		;use another bufer for cmd string

10$:	movb (R1)+,(R2)+
	sob R0,10$
				;recout already loaded by DOTLIN
	rts pc
;
;	IREVRS called by GRAPHL to order bits for LINE PRINTER
;
IREVRS::	TST (R5)+	;SKIP ARG COUNT
	MOVB @(R5)+,R0		;LOAD BYTE TO BE REVERSED
	CLR R1			;CLR HI/LO BIT MASK
	BIT #1,R0		;TST LO BIT
	BEQ 5$
	BIS #40,R1		;SWAP INTO MASK
5$:	BIT #40,R0	;TST HI BYTE
	BEQ 6$
	INC R1			;SET LO BIT ON
6$:	BIC #177741,R0		;CLR OLD HI/LO BITS
	MOV TABL(R0),R0		;GET OUR NEW 4 BIT PATTERN
	BIS R1,R0		;LOAD IN HI/LO BITS
	RTS PC			;RETURN TO FORTRAN
;
TABL:	0,20,10,30,4,24
	14,34,2,22,12,32
	6,26,16,36
;
;
UPPER::			;code to modify input to be upper case
	cmpb #141,R5		;tst for little a
	bgt 10$			;exit
	cmpb #172,R5		;tst little z
	blt 10$
	bic #40,R5
10$:	rts pc
;
;=======================================================================
;
TSTMOD::			;coed to test modtyp letter for legality
				;and store word index in MODIDX
	jsr pc,$SAVAL
	bit #MODMSK,$SWTHO
	beq 100$		;safe exit no switch
	mov MODTYP,R5
	jsr pc,UPPER		;get char to upper case
	mov R5,MODTYP
;
	mov #NUMCHR,R0
	clr R1			;start at table top
	;
10$:	cmpb MODCHR(R1),MODTYP	;tst type
	beq 100$		;if equal exit ok
	inc R1			;pt to next char
	sob R0,10$
20$:	sec			;set carry for wrror 
	rts pc
;
100$:	asl R1			;get byte to word index
	mov R1,MODIDX		;store word index for MODIFY action later
	clc
	rts pc
;
;	LEGAL /MO:switch args
;
MODCHR:	.ascii .|&+-AXE<>*/R.
NUMCHR=.-MODCHR
	.even			;get back to word addresses
;
MODCOD:		MOR	;bit wise or in each pixel
		MAND	;  "   " and    "
		MADD	; 8 bit add
		MSUB
		MAVG	;8 bit avg to 16 then divde
		MXOR	;exclusive bit wise pixel XOR
		MEQ	;keep pixel only if input = output
		MLT
		MGT
		MMUL	;8 bit X 8 bit mult take 8 of 16
		MDIV	;8 bit divide
		MREP	;pixel replace non-zero from in to out
		0
;
;
MODIFY::			;code to use BUFTMP & BUF to create new 
				;modified BUF
	jsr pc,$SAVAL
	mov BASE,R5		;load R5 with BASE,ie /MO:x:base
	mov #BUF,R2
	mov #BUFTMP,R1		;load addr of buffers
	mov BUFSIZ,R0		;load count of bytes to process
10$:	mov MODIDX,R3			;get byte index to word index
	jmp @MODCOD(R3)		;jump to modify code below
;
;
;
			;NOTE: MUST USE | NOT ! BECAUSE !TREATS ALL
			; AS COMMENTS !!!!! VS ||||||||
MOR:			;OR
11$:	bisb (R1)+,(R2)+	;set bits from input byte into output
	sob R0,11$		;decr byte count
	RTS PC			;when done exit
;
MAND:			;and
21$:	comb (R1)		;complement it
	bicb (R1)+,(R2)+	;clr bits from input byte into output
	sob R0,21$		;decr byte count
	RTS PC			;when done exit
;
MADD:		;add
31$:	movb (R1)+,R3	;get byte
	bic #177400,R3	;treat as unsigned byte
	movb (R2),R4
	bic #177400,R4
	add R3,R4		;add bytes
	add R5,R4	;add in BASE,/MO:+:base
;		cmp R4,#255.	;tst for overflow ?
;		bgt 32$		;if so enter 255.
	movb R4,(R2)+	;store byte away
	sob R0,31$		;decr byte count
	RTS PC			;when done exit
;
32$:	movb #255.,(R2)+	;store byte away
	sob R0,31$		;decr byte count
	RTS PC			;when done exit
;
MSUB:			;sub
41$:	movb (R1)+,R3	;get byte
	bic #177400,R3	;treat as unsigned byte
	movb (R2),R4
	bic #177400,R4
	SUB R3,R4		;add bytes
	add R5,R4	;add in BASE,/MO:-:base
;		cmp R4,#255.	;tst for overflow ?
;		bgt 42$		;if so enter 255.
	movb R4,(R2)+	;store byte away
	sob R0,41$		;decr byte count
	RTS PC			;when done exit
;
42$:	movb #255.,(R2)+	;store byte away
	sob R0,41$		;decr byte count
	RTS PC			;when done exit
;
MAVG:	;average
51$:	movb (R1)+,R3	;get byte
	bic #177400,R3	;treat as unsigned byte
	movb (R2),R4
	bic #177400,R4
	add R3,R4		;add bytes
	asr R4		;divide by 2 to get average
	add R5,R4	;add in BASE,/MO:A:base
;		cmp R4,#255.	;tst for overflow ?
;		bgt 52$		;if so enter 255.
	movb R4,(R2)+	;store byte away
	sob R0,51$		;decr byte count
	RTS PC			;when done exit
;
52$:	movb #255.,(R2)+	;store byte away
	sob R0,51$		;decr byte count
	RTS PC			;when done exit
;
MXOR:			;XOR
61$:	movb (R1)+,R3	;get byte
	bic #177400,R3	;treat as unsigned byte
	movb (R2),R4
	bic #177400,R4
	XOR R3,R4		;XOR bytes
	MOVB R4,(R2)+	;STORE XORED BYTE
	sob R0,61$		;decr byte count
	RTS PC			;when done exit
;
;
MEQ:		;EQUAL?
71$:	CMPB (R1)+,(R2)		;CMP bytes
	BEQ 72$			;IF EQUAL THEN LEAVE SAME BYTE
	CLRB (R2)		;IF NOT EQUAL KILL BYTES
72$:	INC R2			;INCR R2 TO NEXT BYTE
	sob R0,71$		;decr byte count
	RTS PC			;when done exit
;
MGT:			;TST > 
81$:	CMPB (R1)+,(R2)		;CMP bytes
	BHI 82$			;IF EQUAL THEN LEAVE SAME BYTE
	CLRB (R2)		;IF NOT EQUAL KILL BYTES
82$:	INC R2			;INCR R2 TO NEXT BYTE
	sob R0,81$		;decr byte count
	RTS PC			;when done exit
;
;
MLT:		;tst <<<<<<<<<<<<
91$:	CMPB (R1)+,(R2)		;CMP bytes
	BLO 92$			;IF EQUAL THEN LEAVE SAME BYTE
	CLRB (R2)		;IF NOT EQUAL KILL BYTES
92$:	INC R2			;INCR R2 TO NEXT BYTE
	sob R0,91$		;decr byte count
	RTS PC			;when done exit
;
;
MMUL:			;* MULT
111$:	movb (R1)+,R3		;get a byte
	bic #177400,R3		;treat as unsigned byte
	movb (R2),R4		;get other byte
	bic #177400,R4		;unsigned also
	MUL R4,R3		;multiply 8 bits each
				;keep only least significant 16 bits
				;of 32 bit product. USE only upper 8 of
				;the low 16 bits.
	add R5,R3		;add in optional base,/MO:*:BASE
				;the base allows the user to see low 8
				;bits of 16 bit product.
	swab R3			;put upper 8 to store back in image
	movb R3,(R2)+		;store 
	sob R0,111$		;decr byte count
	RTS PC			;when done exit
;
MDIV:				;divide operator here
;*******************
;
;	DIVIDE NOT IMPLEMENTED
;
;*************************
	RTS PC			;when done exit
;
MREP:		;PIXEL REPLACE
131$:	tstb (R2)	;is input file zero ?
	bne 132$		;if so keep value from output file
	movb (R1),(R2)		;if input nonzero move ti to output
132$:	INC R2			;INCR R2 TO NEXT BYTE
	INC R1
	sob R0,131$		;decr byte count
	RTS PC			;when done exit
;
;====================================================================
;
;
FILTER::			;filter data thru notch filter or spike
	mov BUFSIZ,R3		;load size
	mov #BUF,R2		;start addr
161$:	cmpb (R2),BYTEIH	;tst hi limit ?
	BHI 162$		;if too hi zero it
	cmpb (R2),BYTEIL	;tst lo lim ?
	bhis 163$		;if within limits keep it
162$:	clrb (R2)		;out of limits clr it
163$:	inc R2			;incr to next byte
	sob R3,161$		;decr counter of bytes
	rts pc
;
;
SWAPB::			;swap bytes in buffer
;
	jsr pc,$SAVAL
153$:	mov BUFSIZ,R3		;load buffer size
	asr R3			;get to words
	mov #BUF,R2		;load buff addr
154$:	swab (R2)+		;swap bytes
	sob R3,154$		;done?
	rts pc
;
;
;	code added here to test for special devices BM: & CD:
;
TSTDEV::	bitb #CS.DVF,C.STAT(R0)	;tst for device name string
	beq 57$			;if none assume that its DISK default!
;
	mov C.DEVD(R0),R1	;load length in bytes of device string
	mov C.DEVD+2(R0),R2	;load addr of device string
	movb (R2)+,R3		;ASCII device string ie , BM , CD
	movb (R2)+,R4		;ASCII device string ie , BM , CD
	swab R4			;get 2nd char to hi byte
	bis R4,R3		;or in hi byte 
	clr R4		;if no unit # given use zero
	sub #2,R1
	beq 52$
50$:	movb (R2)+,R4		;get device # to binary
	sub #60,R4
51$:	dec R1
	bgt 50$		;if more than 1 digit use last digit
;
52$:	cmp DEVIC3,R3		;tst for 3rd device type ?
	bne 54$
	bitb #CS.NMF,C.STAT(R0)		;tst filename string?
	bne 57$		;if it has filename & MT: then files-11
;
54$:;	allow any device name string to be treated as special device
;	this will allow IM1:,IM2:,IM3:,GR1:,GR2:,GR3:,GR4:
;			FU1:,FU2:,FU3:,RE:,GR:,BL: to be used as device 
;		names and each addressesd independently.
;
	bitb #CS.NMF,C.STAT(R0)		;tst filename string?
	bne 57$		;if it has filename then files-11
56$:	SEC		;SET CARRY FOR BM: & CD:
	RTS PC
57$:	bit #CPTMSK,$SWTHO	;tst for color plt switch
	beq 59$			;no
	mov #"LP,R3		;load LP1: directly RSX-11M 3.2 we spool
	mov #1,R4		;but now use LP1: explicitly
;
59$:	CLC		;CLEAR CARRY FOR DISK TYPE DEVICES
			;FILES-11 type i/o
	RTS PC
;
;
BLDSCL::			;BUILD INCREMENTING pattern in BUF
	jsr pc,$SAVAL		;save regs
	mov BUFSIZ,R3		;load byte count
	asl R3		;byte count , load 2 at a time
	mov #BUF,R2		;starting address of data to translate
	clr R0		;clr start of scale = 0
10$:	movb R0,(R2)+	;replace with new value
	movb R0,(R2)+	;replace with new value
	inc R0		;get next value 0 to 255
	sob R3,10$		;get next byte
	rts PC
;
;
;	TRANSL -- translate 8 bits to 8 bits in BUF
;
;
TRANSL::			;this code translates 8 bits to 8 bits inplace
	jsr pc,$SAVAL		;save regs
	mov BUFSIZ,R3		;load byte count
	mov #BUF,R2		;starting address of data to translate
	mov COLOR,R0		;load index of translation table,0,1,2,3
	asl R0			;get as byte offset 0,2,4,6
	mov TABLE(R0),COLTAB+2	;load coltab with start of table
;
TRANS2:	movb (R2),R1		;get a byte
	bic #177400,R1		;save low 8 bits
COLTAB:	movb 2(R1),(R2)+	;replace with new value
	sob R3,TRANS2		;get next byte
	rts PC
;
;
;	SMASH --- convert 3 bit value into 2 bits in buffer like COMPRS
;	SMASH1 for 1st line of print
;	SMASH2 for 2nd raster line of print ----- TRILOG printer
;
SMASH::		;take 8 bit value 0,1,2,3,etc. and put bits in raster line
;
	jsr pc,$SAVAL
;
	mov #BUF,R1		;load pointer to buffer of INPUT BYTE data
	clr R2			;clr byte pointer for output
;	mov #BUFT1,R2		;load pointer to output buffer 1st dot row
;
;	mov BUFSIZ,R3		;load counter of bytes
;	asr R3			;compute num of words ,from bytes
;	asr R3			;get 16 bits to 16 bytes
;	asr R3
;
156$:	mov #8.,R4		;bit PAIRs in word counter
	clr R0			;clr 16 bit working reg
	clr R3			;clear second line working reg
				;now pack selected bytes to bits
157$:	ASL R0			;rotate output reg
	ASL R0			;shift in 2 bits
	ASL R3			;rotate output reg
	ASL R3			;shift in 2 bits
	movb 1(R1),R5		;get byte of 8 bits
;				;swap bytes here
	bic #177770,R5		;keep low 3 bits only
	bisB BITS1(R5),R0	;set 2 bits on in work reg
	bisB BITS2(R5),R3	;set 2 bits on in work reg
	dec R4			;dec bit pair counter by 1
;
	ASL R0			;rotate output reg
	ASL R0			;shift in 2 bits
	ASL R3			;rotate output reg
	ASL R3			;shift in 2 bits
				;implied BYTE SWAP here
	movb (R1),R5		;get byte of 8 bits
;				;swap bytes here
	bic #177770,R5		;low 3 kept
	bisB BITS1(R5),R0	;set 2 bits on in work reg
	bisB BITS2(R5),R3	;set 2 bits on in work reg
;
	tst (R1)+		;get to next BYTE pair
	sob R4,157$		;decr count of bits
;
	mov R0,BUFT1(R2)		;store working reg into output bits buf
	mov R3,BUFT2(R2)		;store working reg into output bits buf
	add #2,R2		;point to next word of output buff
	cmp R2,BUFSIZ		;tst if done yet ???
	blt 156$		;if not done repeat loop
;
	rts PC
;
;1=upper left
;2=upper left  & lower right
;3=same as 2 but add upper right
;4=upper right only
;5=lower right only
;6=lower left only
;7=all 4 dots on --- use rarely ,save ribbon and paper
;
;	these tables are addressed by 3 bits stored in a byte
BITS1:	.byte 0,2,2,3,1,0,0,3	;low 2 bits
BITS2:	.byte 0,0,1,1,0,1,2,3	;low 2 bits bottom line
;
;
MOVBIT::		;code to move compressed bits to BUF
;
	jsr pc,$SAVAL
;
	mov #BUFT1,R1		;load pointer to buffer of INPUT BYTE data
	mov #BUF,R2		;load pointer to output buffer 1st dot row
;
	mov BYTSOT,R3		;load counter of bytes
	asr R3			;compute num of words ,from bytes
;
156$:	mov (R1)+,(R2)+		;move bits from default BUFT1 to BUF
	sob R3,156$		;go do next word
;
	rts PC
;
;
;	COMPRS----- convert 8 bits to 1 bit using BYTEHI/BYTELO
;
COMPRS::		;code to compress bytes to bits using BYTE
;
	jsr pc,$SAVAL
;
	mov #BUF,R1		;load pointer to buffer of INPUT BYTE data
	mov #BUFT1,R2		;load pointer to output buffer 1st dot row
;
	mov BUFSIZ,R3		;load counter of bytes
	asr R3			;compute num of words ,from bytes
	asr R3			;get 16 bits to 16 bytes
	asr R3
	asr R3
;
156$:	mov #16.,R4		;bits in word counter
	clr R0			;clr 16 bit working reg
				;now pack selected bytes to bits
157$:	mov (R1)+,R5		;get word of 16 bits
	swab R5			;get straight from Comtal
	cmpb R5,BYTEIH		;compare input byte with pattern
	bhi 159$
	cmpb R5,BYTEIL		;compare input byte with pattern
	blo 159$
	SEC			;set bit on if = byteI
	BR 158$
159$:	CLC
158$:	roL R0			;rotate output reg
	dec R4			;dec 16 bit counter by 1
;
	swab R5			;get straight from Comtal
	cmpb R5,BYTEIH		;compare input byte with pattern
	bhi 168$
	cmpb R5,BYTEIL		;compare input byte with pattern
	blo 168$
	SEC			;set bit on if = byteI
	BR 169$
168$:	CLC
169$:	roL R0			;rotate output reg
	sob R4,157$		;decr count of bits
;
	mov R0,(R2)+		;store working reg into bits buf
	sob R3,156$		;go do next word
;
;
;
;
	rts PC
;************************************************************************
;
;	this code is shared by EXAPND & EXPANo
;
EXPAND::			;code to expand bits to bytes using BYTE
;
	jsr pc,$SAVAL
;
	mov #BUF,R0		;load pointer to buffer of graphic data
	mov R0,R2		;get copy of input buf address
	mov R2,R1		;get copy of BUF addr
	add BYTSIN,R1
	mov BUFSIZ,R3		;load counter of bytes
EXPX:	add R3,R2		;set pointer to end of buffer /inplace
	asr R3			;compute num of words ,from bytes
	asr R3			;get 16 bits to 16 bytes
	asr R3
	asr R3
;
156$:	mov #16.,R4		;bits in word counter
;				;now unpack bits from graphics to bytes
	mov -(R1),R5		;get word of 16 bits
;		swab R5			;get straight from Comtal
157$:	ROR R5			;get LO bit to carry
	bcc 158$
	movb BYTEO,-(R2)	;store graphics bit out as byte val
	br 159$
158$:	clrb -(R2)		;zero byte  when bit not set
159$:	sob R4,157$		;decr count of bits
;
	sob R3,156$		;go do next word
;
	MOV R0,R2		;MOV data back to input buffer
	MOV BUFSIZ,R3
	ASR R3			;GET WORD COUNT ONLY
160$:	SWAB (R2)+
	SOB R3,160$		;BYTE SWAP RESULT FOR COMTAL
;
;
;
	rts PC
;

	;CODE TO EXPAND UP BIT DATA TO BYTE DATA ON MODIFY
EXPANO::			;code to expand bits to bytes using BYTE
;
	jsr pc,$SAVAL
;
	mov #BUFTMP,R0		;load poINter to buffer of graphic data
	mov R0,R2
	mov R2,R1		;get copy of BUF addr
	add BYTSOT,R1
	mov BUFSIZ,R3		;load counter of bytes
	br EXPX			;go to general code.
;
	.END 
