BLACK: equ 200		;gray-scale table offset
WHITE: equ 300		;white-scale table offset
start:
	MOVE.L	4(A7),A0
	MOVE.L	#5000,D6
	ADD.L	$C(A0),D6
	ADD.L	$14(A0),D6
	ADD.L	$1C(A0),D6
	MOVE.L	D6,-(A7)

	move.w	#0,-(sp)
	move.l	#infopath,-(sp)
	move.w	#$47,-(sp)
	trap	#1
	addq.l	#8,sp
	lea	infopath,a0
	lea	info,a1
infloop:
	tst.b	(a0)+
	bne.s	infloop
	subq.l	#1,a0
infloop2:
	move.b	(a1)+,d0
	beq.s	infloop3
	move.b	d0,(a0)+
	bra.s	infloop2
infloop3:
	move.b	d0,(a0)+

	move.l	#0,-(sp)
	move.w	#$20,-(sp)
	trap	#1
	addq.l	#6,sp
	move.l	d0,savesup
loadinfo:
	move    #0,-(SP)        ;Open file
	move.l  #infopath,-(SP) ;Address of filename
	move    #$3D,-(SP)
	trap    #1              ;Get handle number in D0
	addq.l  #8,SP
	tst.w	d0
	bmi.s	noinfo
	move.w	d0,-(sp)
	move.w	(sp),d0
	move.l  #defs,-(SP)	;load it straight onto screen
	move.l  #6,-(SP)	;length to read in
	move	D0,-(SP)	;Handle
	move	#$3F,-(SP)	;bios number
	trap	#1		;Read file in
	addi.l	#12,SP
	move	#$3E,-(SP)      ;Handle already on stack
	trap	#1              ;Close file
	addq.l	#4,SP
noinfo:
	MOVE.L	#message,-(A7)	;print my message
	MOVE.W	#9,-(A7)
	TRAP	#1
	ADDQ.L	#6,A7
inloop1:
	MOVE.L	#sizemsg,-(A7)	;print my message
	MOVE.W	#9,-(A7)
	TRAP	#1
	ADDQ.L	#6,A7
	move.w	#1,-(sp)
	trap	#1
	addq.l	#2,sp
	move.l	d0,d1
	swap	d1
	cmpi.b	#13,d0
	beq	bydefault
	cmpi.b	#$21,d1
	beq.s	isfull
	cmpi.b	#$23,d1
	beq.s	ishalf
	bra.s	inloop1
isfull:
	move.w	#1,usermode
	bra	pinsinput
ishalf:
	move.w	#-1,usermode
pinsinput:
	MOVE.L	#pinsmsg,-(A7)	;print my message
	MOVE.W	#9,-(A7)
	TRAP	#1
	ADDQ.L	#6,A7
	move.w	#1,-(sp)
	trap	#1
	addq.l	#2,sp
	move.l	d0,d1
	swap	d1
	cmpi.b	#57,d0		;is 9 for nine
	beq.s	is8
	cmpi.b	#50,d0		;is 2 for 24
	beq.s	is24
	bra.s	pinsinput
is8:
	move.w	#40,userpins
	bra.s	dobright
is24:
	move.w	#0,userpins
dobright:
	MOVE.L	#brightmsg,-(A7)	;print my message
	MOVE.W	#9,-(A7)
	TRAP	#1
	ADDQ.L	#6,A7
	move.w	#1,-(sp)
	trap	#1
	addq.l	#2,sp
	move.l	d0,d1
	cmpi.b	#13,d0
	beq	bydefault
	cmpi.b	#48,d0
	blt.s	dobright
	cmpi.b	#52,d0
	bgt.s	dobright
	sub.b	#48,d0
	and.l	#$ff,d0
	add.w	d0,d0		;*2
	lea	brightlist,a0
	move.w	(a0,d0.w),userexposure
dosavedefs:
	MOVE.L	#savemsg,-(A7)	;print my message
	MOVE.W	#9,-(A7)
	TRAP	#1
	ADDQ.L	#6,A7
	move.w	#1,-(sp)
	trap	#1
	addq.l	#2,sp
	swap	d0
	cmpi.b	#$15,d0
	beq.s	saveinfo
	cmpi.b	#$31,d0
	beq.s	bydefault
	bra.s	dosavedefs
saveinfo:
	move    #1,-(SP)        ;Open file for write
	move.l  #infopath,-(SP)	;Address of filename
	move    #$3d,-(SP)
	trap    #1	;Get handle number in D0
	addq.l  #8,SP
	cmpi.w	#-33,d0		;doesn't exist
	beq	create
	tst.w	d0		;other error
	bmi	docn2
	move.w	d0,-(sp)
cb:
	move.w	(sp),d0
	move.l  #defs,-(SP)
	move.l  #6,-(SP)	;length to write in
	move    D0,-(SP)	;Handle
	move    #$40,-(SP)	;bios number
	trap    #1		;write file
	addi.l   #12,SP
	move    #$3E,-(SP)      ;Handle already on stack
	trap    #1              ;Close file
	addq.l  #4,SP
bydefault:
	move.l	$502,ishigh+2
	move.l	#mydump,$502
	move.l	savesup,-(sp)
	move.w	#$20,-(sp)
	trap	#1
	addq.l	#6,sp

	MOVE.L	(A7)+,D0	;that d6 thing
	CLR.W	-(A7)		;no error code
	MOVE.L	D0,-(A7)	;protect this much
	MOVE.W	#$31,-(A7)	;keep process
	TRAP	#1

create:
	move.w	#$0,-(sp)
	move.l	#infopath,-(sp)
	move.w	#$3c,-(sp)
	trap	#1
	addq.l	#8,sp
	tst.w	d0
	bmi.s	docn
	move.w	d0,-(sp)	;put the handle on the stack
	bra	cb
docn:
	MOVE.L	#errormsg1,-(A7)	;print my message
	MOVE.W	#9,-(A7)
	TRAP	#1
	ADDQ.L	#6,A7
	move.l	#520000,d0
dl:
	sub.l	#1,d0
	bpl	dl
	bra	bydefault

docn2:
	MOVE.L	#errormsg2,-(A7)	;print my message
	MOVE.W	#9,-(A7)
	TRAP	#1
	ADDQ.L	#6,A7
	move.l	#530000,d0
dl2:
	sub.l	#1,d0
	bpl	dl2
	bra	bydefault


mydump:
	movem.l	d0-d7/a0-a6,-(sp)
	move.w	#2,-(sp)
	trap	#14
	addq.l	#2,sp
	move.l	d0,screenad
	move.w	#4,-(sp)
	trap	#14
	addq.l	#2,sp
	move.w	d0,screenrez
	cmpi.w	#0,screenrez
	beq.s	islow
	cmpi.w	#1,screenrez
	beq.s	ismed
ishigh:
	jmp	$0			;jump to existing routine
ismed:
	moveq	#20,d7
	bra.s	putvals
islow:
	moveq	#0,d7
putvals:
	tst.w	usermode
	bgt	fulldump
	lea	grm2,a0
	bra.s	dostuff
fulldump:
	lea	grm1,a0
dostuff:
	add.w	d7,a0
	move.w	userpins,d7
	add.w	d7,a0
	lea	grmode,a1
	move.l	(a0)+,(a1)+	;get ginit string
	move.w	(a0)+,(a1)+	;xp1
	move.w	(a0)+,(a1)+	;xp2
	move.w	(a0)+,(a1)+	;ypixels
	move.w	(a0)+,(a1)+	;yp
	move.w	(a0)+,(a1)+	;pins
	move.l	(a0)+,(a1)+	;linefeedstring
	move.w	(a0)+,(a1)+	;bytestosend

	lea	palette,a0
	lea	$ff8240,a1
	move.w	userexposure,d6		;brightener
*	move.w	#$0700,$ff8240+6
	moveq	#15,d7
spl:
	move.w	(a1)+,d0
	and.w	#$0777,d0
	move.w	d0,d1
	beq.s	noneed		;is black
	move.w	d1,d2
	move.w	d2,d3
	and.w	#$0007,d1	;get blue
	move.w	d6,d5
	and.w	#$0007,d5	;get brightener
	add.w	d5,d1
	cmpi.w	#$0007,d1
	ble.s	blok
	move.w	#$0007,d1
blok:
	and.w	#$0070,d2	;get blue
	move.w	d6,d5
	and.w	#$0070,d5	;get brightener
	add.w	d5,d2
	cmpi.w	#$0070,d2
	ble.s	grok
	move.w	#$0070,d2
grok:
	and.w	#$0700,d3	;get blue
	move.w	d6,d5
	and.w	#$0700,d5	;get brightener
	add.w	d5,d3
	cmpi.w	#$0700,d3
	ble.s	reok
	move.w	#$0700,d3
reok:
	or.w	d3,d2
	or.w	d2,d1
noneed:
	move.w	d1,(a0)+
	dbf	d7,spl
bp1:
	move.l	#workarea,-(sp)
	move.l	#palette,-(sp)
	move.l	screenad,-(sp)
	move.w	screenrez,-(sp)
	move.w	#0,-(sp)
	bsr	a_dumper
	add.l	#16,sp

	move.l	#workarea,-(sp)
	move.l	#palette,-(sp)
	move.l	screenad,-(sp)
	move.w	screenrez,-(sp)
	move.w	#1,-(sp)
	bsr	a_dumper
	add.l	#16,sp
	movem.l	(sp)+,d0-d7/a0-a6
	rts
illegal
a_dumper:
	move.l	a0,d0		;save A0
	move.l	16(a7),a0	;point A0 at the work area start
	movem.l	d0-d7/a0-a7,(a0);save all registers
	move.l	8(a7),a1	;point A1 to screen base
	move.l	12(a7),a2	;point A2 to palette start address
	tst.w	4(a7)		;initialize command (0)?
	bne process		;no, dump it!
* reset & initialize printer *
init:

* BUILD BLACK PIXEL TABLE *

	move.w	#%1111111111111111,200(a0)	;Black...
	move.w	#%1111011011110110,202(a0)
	move.w	#%1011011010110110,204(a0)
	move.w	#%1001011010010110,206(a0)
	move.w	#%1000011010000110,208(a0)
	move.w	#%1000001010000010,210(a0)
	move.w	#%1000000010000000,212(a0)
	move.w	#%0000000000000000,214(a0)	;...to white

* BUILD WHITE PIXEL TABLE *

	move.w	#%1000000000000000,300(a0)	;low white...
	move.w	#%1000000010000000,302(a0)
	move.w	#%1000001010000000,304(a0)	
	move.w	#%1000001010000010,306(a0)
	move.w	#%1000011010000010,308(a0)
	move.w	#%1000011010000110,310(a0)
	move.w	#%1001011010000110,312(a0)
	move.w	#%1001011010010110,314(a0)
	move.w	#%1011011010010110,316(a0)
	move.w	#%1011011010110110,318(a0)
	move.w	#%1111011010110110,320(a0)
	move.w	#%1111011011110110,322(a0)
	move.w	#%1111111011110110,324(a0)
	move.w	#%1111111011110111,326(a0)	;...to high white

* set init string *

fininit:
	bsr	preset			;reset printer
	tst.w	d0			;reset successful?
	bmi	error			;no!
	move.l	linefeedstring,150(a0)	;reset, set linefeed to 8 dots
	moveq	#3,d2			;3 bytes in init string
	lea	150(a0),a3		;point to init string
	bsr	printit			;and print it!
	clr.l	150(a0)			;clear that portion of work area
	tst.w	d0			;was print OK?
	bpl	exit			;yes!
* exit w/error condition (0) *

error:
	movem.l	(a0),d0-d7/a0-a7	;restore registers
	move.l	d0,a0			;restore old A0
	clr.w	d0			;set error condition
	rts

* exit the subroutine (no error) *

exit:
	movem.l	(a0),d0-d7/a0-a7	;restore registers
	move.l	d0,a0			;restore old A0
	move.w	#1,d0			;set OK condition
	rts

* exit w/abort condition (2) *

abort:
	movem.l	(a0),d0-d7/a0-a7	;restore registers
	move.l	d0,a0			;restore old A0
	move.w	#2,d0			;set abort condition
	rts

* process the pixels and send to printer *

process:
	move.w	6(a7),rez		;save resolution
	tst.w	6(a7)			;was it 0 (low)?
	beq	lowvert			;yes!
	cmp.w	#1,6(a7)		;was it 1 (medium)?
	beq	medvert			;yes!
	bra	abort			;can't dump hires with this dumper!

* MEDIUM-REZ PROCESSOR *

medvert:
	move.w	#640,xmax		;set X maximum
	bra	ALLDUMP			;and dump it!

* LOW-REZ PROCESSOR *

lowvert:
	move.w	#320,xmax		;set X maximum

ALLDUMP:
	clr.w	pixely			;start at Y=0
	clr.w	prty			;and printer Y=0
	move.l	#$800000,masknew		;init pin mask

* GET PIXEL *

newpass:
	move.b	#%100100,color		;start with yellow pass
nx0strt:
	bsr	linestrt		;start off the print operation
	clr.w	pixelx			;set screen X coord to 0
	clr.w	prtx		;set printer X coord to 0
nx0yel:
	move.w	pixelx,d1		;grab screen X
	and.w	#1,d1			;is is even?
	beq.s	onex2			;yes, that gets only 1 printer dot
	move.w	xexpander1,xtime	;it's odd, make it 2 printer dots.
	bra.s	doppix			;do convert on pixel
onex2:
	move.w	xexpander2,xtime		;set up 1 printer dot
	bra.s	doppix
doppix:
	bsr	procit			;process the pixel
	bmi	error			;if error, return.
	addq.w	#1,pixelx		;increment screen X coord
	move.w	pixelx,d1		;get the X coord
	cmp.w	xmax,d1		;end of screen scan line?
	bne	nx0yel			;nope, loop for more!

	move.b	#$0D,150(a0)		;new color, send CR
	moveq	#1,d2			;1 byte to print
	lea	150(a0),a3		;point to the CR
	bsr	printit			;and print it!
	clr.l	150(a0)			;clear that part of the work area
	bsr	pabchk			;check for abort (UNDO)
	tst.w	d0			;abort?
	beq	NOabort			;no!
	bsr	preset			;they bailed out, reset printer
	bra	abort			;and exit w/abort condition

NOabort:
	move.b	color,d1		;get color mask
	lsr.b	#1,d1			;shift right one bit
	move.b	d1,color		;and put back in the mask
	and.b	#%111000,d1		;done with all 3 colors?
	bne	nx0strt			;no, loop for next color

	move.b	#$0a,150(a0)		;new line, send LF
	moveq	#1,d2			;a LF is just 1 byte,
	lea	150(a0),a3		;point to LF
	bsr	printit			;and print it!
	clr.l	150(a0)			;clear that area
	move.w	ypixels,d7
	add.w	d7,pixely		;increment screen Y by 4 (4 lines per pass)
	move.w	pins,d7
	add.w	d7,prty			;add 8 to printer's Y (8 pins per pass)
	cmpi.w	#200,pixely		;end of screen?
	bmi	newpass			;no!
	bsr	preset			;all done, reset printer
	bra	exit			;and exit!

preset:
	move.w	#$1b40,150(a0)		;set up printer reset codes
	moveq	#2,d2			;it's 2 bytes
	lea	150(a0),a3		;point to string
	bsr	printit			;reset printer!
	clr.l	150(a0)			;clean up print buffer
	moveq	#0,d0
	rts				;and exit!

linestrt:
	move.l	#$1B72001B,150(a0)	;set up start of color set string
	cmpi.b	#%100100,color		;yellow pass?
	bne.s	notyel			;no, try magenta
	move.b	#$4,152(a0)		;it's yellow, set ribbon color
	bra.s	setcolor		;and do it.
notyel:
	cmpi.b	#%010010,color		;magenta?
	bne.s	notmag			;no, it's cyan!
	move.b	#$1,152(a0)		;set ribbon color to magenta
	bra.s	setcolor		;and do it.
notmag:
	move.b	#$2,152(a0)		;set ribbon color to cyan!
setcolor:
	move.l	grmode,154(a0)	;set up end of string (dots per line = 960)
	move	bytestosend,d2		;7 bytes to print
	lea	150(a0),a3			;point to string
	bsr	printit			;and print them!
	clr.l	150(a0)			;clear print area
	clr.l	154(a0)
	rts

procit:
	move.w	ypixels,ycount		;do 4 screen pixels per head pass
proc2:
	bsr	getpixel	;get a pixel!
*	move.b	#1,d0
	move.w	yexpander,ytime	;each pixel repeated 2X (8 pins/4 pixels)
	bsr	ppix		;convert pixel & send to printer
	bmi	procx		;exit if error
	addq.w	#1,pixely	;next screen Y coord
	subq.w	#1,ycount	;1 less pixel to do
	bne	proc2		;loop if more
	addq.w	#1,prtx		;increment printer X count
	move.w	ypixels,d7
	sub.w	d7,pixely	;reverse Y coord to top of print head
	move.w	pins,d7
	sub.w	d7,prty		;and printer Y as well
	subq.w	#1,xtime	;decrement X repeat counter
	bne	procit		;loop if more
	clr.w	d0		;clear error flag
procx:
	rts				;and return

****************************
* print string to printer  *
*--------------------------*
* input:                   *
* d2.L # of bytes to print *
* a3: address of 1st byte  *
* returns:                 *
* d0 = -1: error!          *
* d0 =  0: OK!             *
****************************

printit:
	move.l	#270000,d1	;timeout count (works out to +/- 30 secs.)

statloop:
				;save registers on stack
	movem.l	a0-a2/d1-d2,-(sp)
				;Request printer
	clr.w	-(sp)		;output status
	move.w	#8,-(sp)
	trap	#13
	addq.l	#4,sp
	movem.l	(sp)+,a0-a2/d1-d2
	tst.l	d0		;printer ready?
	bmi	prtrdy		;yes!
	subq.l	#1,d1		;decrement timeout counter
	bpl	statloop		;and try again
	move.w	#-1,d0		;printer error!
	rts

prtrdy:
	movem.l	a0-a2/d1-d2,-(sp)
	move.b	(a3),d0		;get byte to print
	andi.w	#$00FF,d0	;mask off to be safe
	move.w	d0,-(sp)		;put on stack
	clr.w	-(sp)		;device #0 (printer)
	move.w	#3,-(sp)		;conout
	trap	#13		;send to printer!
	addq.l	#6,sp
	movem.l	(sp)+,a0-a2/d1-d2
	addq.l	#1,a3		;point to next byte
	subq.w	#1,d2		;decrement counter
	bne	printit		;loop if more bytes
	clr.w	d0		;OK!
	rts

* CHECK FOR UNDO KEY ABORT *

pabchk:
	movem.l	a0-a2/d1-d2,-(sp)
	move.w	#2,-(sp)	;(returns with D0 = 0 if no characters)
	move.w	#1,-(sp)
	trap	#13
	addq.l	#4,sp
	tst.w	d0		;any keys?
	beq	abcexit		;no!
	move.w	#2,-(sp)	;don't make it wait!
	move.w	#2,-(sp)	;test for keypress
	trap	#13		;get key...
	addq.l	#4,sp
	cmp.l	#$00610000,d0	;UNDO?
	bne	nobort		;no!
	move.w	#1,d0		;yes, set abort flag
abcexit:
	movem.l	(sp)+,a0-a2/d1-d2
	rts
nobort:
	clr.w	d0		;clear D0 (no abort)
	bra	abcexit		;and go to exit point

getpixel:
	cmpi	#200,pixely		;Y beyond end of screen?
	bmi	getit		;no, get the pixel
	move.b	#-1,d0		;return -1 for color
	rts			;and exit

getit:
	tst.w rez		;low rez?
	beq get0		;yes, get low-rez pixel!
get1:
	movem.l	a0-a2/d1-d3,-(sp)
	clr.w d0		;zero result register
	move.w pixely,d3		;grab Y coordinate
	and.l #$0000ffff,d3	;mask it off
	mulu #160,d3		;multiply by 160 (# of bytes per scan line)
	adda.l d3,a1		;add to screen base address
	move.w pixelx,d1		;get X coordinate
	move.w d1,d2		;duplicate in D2
	lsr.w #2,d1		;divide it by 4
	and.w #$00fc,d1		;turn off lower 3 bits
	adda.w d1,a1		;add to screen address
	move.w (a1),d3		;get the screen word
	and.l #15,d2		;mask X to 0-15 (index within group)
	move.w #$8000,d1	;set up a bit mask
	lsr.w d2,d1		;shift it by the group index
	and.w d1,d3		;get low-order color bit
	beq bit1b		;it's off, go to next color bit
	move.w #1,d0		;set bit in result register
bit1b:
	move.w 2(a1),d3		;get second pixel group from screen
	and.w d1,d3		;get high-order color bit
	beq getx1		;it's off, go exit.
	or.w #2,d0		;it's on, turn on appropriate color bit in result
getx1:
	movem.l	(sp)+,a0-a2/d1-d3
	rts

* get low-rez pixel *

get0:
	movem.l	a0-a2/d1-d3,-(sp)
	clr.w d0		;zero result register
	move.w pixely,d3		;get Y coordinate
	and.l #$0000ffff,d3	;mask off for multiply
	mulu #160,d3		;multiply by 160 (# of bytes per scan line)
	adda.l d3,a1		;add to screen base address
	move.w pixelx,d1		;get X coordinate
	move.w d1,d2		;duplicate it in D2
	lsr.w #1,d1		;divide it by 2
	and.w #$00f8,d1		;turn off lower 3 bits
	adda.w d1,a1		;add to screen address register

	move.w (a1),d3		;grab screen word
	and.l #15,d2		;mask X to 0-15
	move.w #$8000,d1	;set up bit mask
	lsr.w d2,d1		;shift bit mask 0-15 bits
	and.w d1,d3		;mask off bit 0
	beq bit0b		;bit's off, go get next color bit
	move.w #1,d0		;turn on bit 0 in result

bit0b:
	move.w 2(a1),d3		;get screen word for bit 1 of color
	and.w d1,d3		;get bit 1
	beq bit0c		;it's off, try bit 2
	or.w #2,d0		;turn on bit 1 in result

bit0c:
	move.w 4(a1),d3		;get screen word for bit 2
	and.w d1,d3		;get bit 2
	beq bit0d		;it's off, try bit 3
	or.w #4,d0		;turn on bit 2 in result

bit0d:
	move.w 6(a1),d3		;get word for bit 3
	and.w d1,d3		;get bit 3
	beq getx0		;it's off!
	or.w #8,d0		;turn on bit 3 in result

getx0:
	movem.l	(sp)+,a0-a2/d1-d3
	rts

* CHANGE COLOR TO PRINTER FORMAT *
* AND PUT IN PRINT LINE          *

ppix:
	move.w	prtx,d1		;get printer X coordinate
	move.w	prty,d2		;get printer Y coordinate
	and.w	#3,d1		;mask X to 0-3
	and.w	#3,d2		;mask Y to 0-3
	lsl.w	#2,d2		;multiply Y by 4
	add.w	d2,d1		
;add them for index of 0-15 for printer pixel table
	move.w	d1,phase	
;got printer black/white phase index, put in PHASE
	move.b	d0,save		;save the color for repeat use
	tst.b	d0		;is color >= 0?
	bpl	d0OK		;yes!
	clr.w	d0		;no, change it to 0
d0OK:
	move.b	d0,d1		;duplicate color in D1
	andi.l	#$000000ff,d1	;mask it
	lsl.l	#1,d1		;multiply by 2 for index into palette
	add.l	a2,d1		;add to palette base address
	move.l	d1,a5		;and put in an address register
	move.w	(a5),d0		;got color 000-777
	move.w	d0,d2		;duplicate it...
	and.w	#7,d2		;get blue index
	move.w	d0,d1		;duplicate again...
	and.w	#$0070,d1		;get green index
	lsr.w	#1,d1		;shift the green index right 1 bit
	add.w	d1,d2		;and add to total
	move.w	d0,d1		;duplicate again!!
	and.w	#$0700,d1		;get red index
	lsr.w	#2,d1		;shift right 2 bits
	add.w	d1,d2		;now we have a color # of 0-511
	lea	cvalues,a5	;get color bit table addr in a5
	move.w	d0,d3		;not AGAIN?? (gotta save it for next operation)
	move.b	0(a5,d2.w),d0	;load color bits

* calc color brightness total *

	move.w	d3,d1		;put color in D1
	and.w	#7,d1		;mask blue brite
	move.w	d3,d2		;put color in D2
	lsr.w	#4,d2		;divide by 4 and...
	and.w	#7,d2		;mask green brite
	add.w	d2,d1		;add to total brite
	lsr.w	#8,d3		;now shift color 8 bits right...
	and.w	#7,d3		;mask red brite
	add.w	d3,d1		;add to total brite
	tst.b	d0		;table color bits = %000000 (gray scale)?
	beq	grayit		;yes!
	cmp.w	#7,d1		;total brite < 7?
	bmi	blakck		;yes, add some black!
	beq	normal		;brightness = 7, it's a solid color!
whitck:
	move.w	phase,d2	;get printer pixel phase (0-15)
	sub.w	#8,d1		;decrement pixel brightness by 8
	lsl.w	#1,d1		;and multiply by 2 for index
	lea	0(a0,d1.w),a5	;generate a table offset using brightness
	adda.l	#WHITE,a5	;index into WHITE table
	move.w	(a5),d3		;get white addition word
	btst	d2,d3		;and check bit indicated by PHASE
	bne	nobitson	;if bit is on, make it white!
	bra	normal		;otherwise, make it normal color
grayit:
	and.l	#$000000FF,d1	;mask in preparation for divide
	divu	#3,d1		;divide brightness by 3
	move.w	phase,d2	;get printer phase
	lsl.w	#1,d1		;multiply brightness by 2 for index
	lea	0(a0,d1.w),a5	;generate a table offset using brightness / 3
	adda.l	#BLACK,a5	;index into BLACK table
	move.w	(a5),d3		;get black addition word
	btst	d2,d3		;check bit indicated by PHASE
	bne	turnbitson		;if it's on, add black!
	bra	nobitson		;otherwise, it's white!

blakck:
	move.w	phase,d2	;get printer pixel phase
	lsl.w	#1,d1		;multiply brightness by 2 for index
	lea	0(a0,d1.w),a5	;generate an offset using brightness
	adda.l	#BLACK,a5	;index into BLACK table
	move.w	(a5),d3		;grab black addition word
	btst	d2,d3		;if it's on, add black
	bne	turnbitson		;otherwise, it's normal color

normal:
	and.b	color,d0	;mask the table color with color pass bits (y, m or c)
	move.w	prtx,d1		;get printer X coord
	add.w	prty,d1		;add printer Y coord
	and.w	#1,d1		;is it an even pixel?
	beq	evenpix		;yes!

* ODD pixel on printer, use color 2

	lsr.b	#3,d0		;shift so color #2 is used
	bra	orit		;and go put in printer byte

evenpix:
	and.b	#7,d0		;use color #1
orit:
	tst.b	d0		;any bits on?
	beq	nobitson		;no!

turnbitson:
	tst.b	save			;is original pixel on screen?
	bmi	nobitson		;no, leave white!
	move.l	150(a0),d0	;get printer byte
	or.l	masknew,d0	;OR on the appropriate bit
	move.l	d0,150(a0)	;and put byte back

nobitson:
	move.l masknew,d2	;get printer pin mask
	lsr.l #1,d2		;move to next pin
	move.l d2,masknew	;save mask
	tst.l d2		;any more pins left?
	bne noprtyet		;yes!

	move.l	#$800000,masknew	;reset pin mask to top pin
	moveq	#3,d2		;1 byte to print
	lea	151(a0),a3	;point to byte
	bsr	printit		;and print the byte!
	bmi	ppixout		;branch if error
	clr.l	150(a0)		;clear print work area

noprtyet:
	addq.w #1,prty		;increment printer Y coordinate
	move.b save,d0		;restore color to D0
	subq.w #1,ytime		;decrement Y repeat counter
	bne ppix		;loop back if more
	clr.w d0		;zero D0 to report success
ppixout:
	rts
***************************************************************
* The CVALUES table is a 512-byte table (one byte per color   *
* combination possible on the ST.)  Each byte is made up of   *
* two color indicator bit groups.  Bits 0-2 are termed        *
* color 1, and are used when the printer pixel X and Y        *
* coordinates add to an even value.  Bits 3-5 are termed      *
* color 2, and are used when the printer pixel X and Y        *
* coordinates add to an odd value.  The three bits in each    *
* color represent (from high bit to low bit) yellow, magenta  *
* and cyan.  That is, 100 is yellow, 010 is magenta, 001 is   *
* cyan.  These bits are combined to make: 011=blue, 101=green,*
* 110=red, 111=black, 000=white.  Gray scales are represented *
* by 000, and are automatically shaded by the color routine.  *
***************************************************************
cvalues:
* 000-077 *
dc.b %000000,%011001,%011001,%011001,%011001,%011001,%011001,%011001
dc.b %101101,%001001,%011101,%011101,%011001,%011001,%011001,%011001
dc.b %101101,%101011,%001001,%011101,%011101,%011001,%011001,%011001
dc.b %101101,%101101,%101001,%001001,%001001,%011001,%011101,%011101
dc.b %101101,%101101,%101011,%101001,%001001,%001001,%011101,%011101
dc.b %101101,%101101,%101101,%101011,%101011,%001001,%011001,%011001
dc.b %101101,%101101,%101011,%101011,%101011,%101011,%001001,%011001
dc.b %101101,%101101,%101101,%101011,%101011,%101011,%101001,%001001

* 100-177 *

dc.b %110110,%010010,%011010,%011010,%011001,%011001,%011001,%011001
dc.b %100100,%000000,%011001,%011001,%011001,%011001,%011001,%011001
dc.b %101100,%101101,%001001,%011001,%011001,%011001,%011001,%011001
dc.b %101101,%101011,%101001,%001001,%011001,%011101,%011001,%011001
dc.b %101101,%101101,%101011,%101001,%001001,%011001,%011101,%011001
dc.b %101101,%101101,%101101,%101011,%101001,%001001,%011001,%011001
dc.b %101101,%101101,%101101,%101011,%101011,%101001,%001001,%011001
dc.b %101101,%101101,%101101,%101101,%101011,%101011,%101001,%001001

* 200-277 *

dc.b %110110,%110010,%010010,%011010,%011010,%011001,%011001,%011001
dc.b %110100,%110110,%010010,%011010,%011010,%011001,%011001,%011001
dc.b %100100,%100100,%000000,%011001,%011001,%011001,%011001,%011001
dc.b %100100,%100100,%100101,%001001,%011001,%011001,%011001,%011001
dc.b %101100,%101100,%101101,%101001,%001001,%011001,%011001,%011001
dc.b %101101,%101101,%101101,%101101,%101001,%001001,%011001,%011001
dc.b %101101,%101101,%101101,%101101,%101101,%101001,%001001,%011001
dc.b %101101,%101101,%101101,%101101,%101101,%101101,%101001,%001001

* 300-377 *

dc.b %110110,%110110,%110010,%010010,%011010,%011001,%011001,%011001
dc.b %110110,%110010,%110010,%010010,%011010,%011010,%011001,%011001
dc.b %110100,%110100,%110110,%010010,%011010,%011001,%011001,%011001
dc.b %100100,%100100,%100100,%000000,%011001,%011001,%011001,%011001
dc.b %101100,%101100,%101100,%101001,%001001,%011001,%011001,%011001
dc.b %101101,%101101,%101101,%101101,%101001,%001001,%011001,%011001
dc.b %101101,%101101,%101101,%101101,%101011,%101001,%001001,%011001
dc.b %101101,%101101,%101101,%101101,%101101,%101101,%101001,%001001

* 400-477 *

dc.b %110110,%110110,%110010,%110010,%010010,%011010,%011001,%011001
dc.b %110110,%110110,%110110,%110010,%010010,%011010,%011001,%011001
dc.b %110110,%110110,%110110,%110010,%010010,%011010,%011001,%011001
dc.b %110100,%110100,%110110,%110110,%010010,%011010,%011010,%011001
dc.b %100100,%100100,%100100,%100100,%000000,%011001,%011001,%011001
dc.b %101100,%101100,%101100,%101101,%101101,%001001,%011001,%011001
dc.b %101101,%101101,%101101,%101011,%101011,%101001,%001001,%011001
dc.b %101101,%101101,%101101,%101101,%101011,%101011,%101001,%001001
* 500-577 *

dc.b %110110,%110110,%110110,%110110,%110010,%010010,%011010,%011010
dc.b %110110,%110110,%110110,%110110,%110010,%010010,%011010,%011010
dc.b %110110,%110110,%110110,%110110,%110010,%010010,%011010,%011010
dc.b %110100,%110100,%110110,%110110,%110010,%010010,%011010,%011010
dc.b %110100,%110100,%110100,%110110,%110010,%010010,%011010,%011010
dc.b %100100,%100100,%100100,%100100,%100100,%000000,%011001,%011001
dc.b %101100,%101100,%101100,%101100,%101101,%101001,%001001,%011001
dc.b %101100,%101100,%101100,%101101,%101011,%101001,%101001,%001001

* 600-677 *

dc.b %110110,%110110,%110110,%110110,%110010,%110010,%010010,%011010
dc.b %110110,%110110,%110110,%110110,%110010,%110010,%010010,%011010
dc.b %110100,%110110,%110110,%110110,%110010,%110010,%010010,%011010
dc.b %110100,%110100,%110100,%110110,%110010,%110010,%010010,%011010
dc.b %110100,%110100,%110110,%110110,%110110,%110010,%010010,%011010
dc.b %110100,%110100,%110100,%110100,%110100,%110110,%010010,%011010
dc.b %100100,%100100,%100100,%100100,%100100,%100100,%000000,%011001
dc.b %101100,%101100,%101100,%101100,%101100,%101100,%101101,%001001

* 700-777 *

dc.b %110110,%110110,%110110,%110110,%110010,%110010,%110010,%010010
dc.b %110110,%110110,%110110,%110110,%110010,%110010,%110010,%010010
dc.b %110110,%110110,%110110,%110110,%110010,%110010,%110010,%010010
dc.b %110110,%110110,%110110,%110110,%110010,%110010,%110010,%010010
dc.b %110100,%110100,%110100,%110100,%110110,%110010,%110010,%010010
dc.b %110100,%110100,%110100,%110100,%110100,%110110,%110010,%010010
dc.b %110100,%110100,%110100,%110100,%110100,%110100,%110110,%010010
dc.b %100100,%100100,%100100,%100100,%100100,%100100,%100100,%000000

workarea:
	blk.l	400,0
palette:
	blk.w	16
savesup:
	dc.l	0
masknew:
	dc.l	0
pixelx:
	dc.w	0
pixely:
	dc.w	0
rez:	dc.w	0
prty:	dc.w	0
prtx:	dc.w	0
xtime:	dc.w	0
ytime:	dc.w	0
color:	dc.w	0
save:	dc.w	0
phase:	dc.w	0
xmax:	dc.w	0
ycount:	dc.w	0
screenad:	dc.l	0
screenrez:	dc.w	0
grmode:		dc.l	0
xexpander1:	dc.w	0
xexpander2:	dc.w	0
ypixels:	dc.w	0		;y pixels per head pass
yexpander:	dc.w	0
pins:		dc.w	0
linefeedstring:	dc.l	0
bytestosend:	dc.w	0
*************************************************
*	all the values for half size print	*
*	grmode,xexpander1,xexpander2,ypixels	*
*	yexpander	followed by the med res	*
*			versions in same format	*
*************************************************
grm1:		dc.l	$2a270005	;triple density 1280 dpl
		dc.w	4,4,6,4
		dc.w	24
		dc.l	$1b331800
		dc.w	8
grm1med:	dc.l	$2a270005	;triple density 1280 dpl
		dc.w	2,2,6,4
		dc.w	24
		dc.l	$1b331800
		dc.w	8
grm18:		dc.l	$4cc00300	;double density 960 dpl
		dc.w	3,3,4,2
		dc.w	8
		dc.l	$1b410800
		dc.w	7
grm1med8:	dc.l	$4cc00300	;quad density 960 dpl
		dc.w	2,1,4,2
		dc.w	8
		dc.l	$1b410800
		dc.w	7

grm2:		dc.l	$2a278002	;double density 480 dpl
		dc.w	2,2,12,2
		dc.w	24
		dc.l	$1b331800
		dc.w	8
grm2med:	dc.l	$2a278002	;quad density 960 dpl
		dc.w	1,1,12,2
		dc.w	24
		dc.l	$1b331800
		dc.w	8
grm28:		dc.l	$4ce00100	;double density 480 dpl
		dc.w	2,1,8,1
		dc.w	8
		dc.l	$1b410800
		dc.w	7
grm2med8:	dc.l	$5ac00300	;quad density 960 dpl
		dc.w	2,1,8,1
		dc.w	8
		dc.l	$1b410800
		dc.w	7

defs:
usermode:	dc.w	1		;full
userexposure:	dc.w	$0000		;no brightener
userpins:	dc.w	0
brightlist:
	dc.w	$0000,$0111,$0222,$0333,$0444
infopath:
	blk.b	64,0
info:
	dc.b	'\gsx140.inf',0
savemsg:
	dc.b	$0d,$0a,'Do you wish to save these settings ?',$0d,$0a
	dc.b	'(Y/N)',$0d,$0a,0
errormsg1:
	dc.b	$0d,$0a,'ERROR! Could not create info file.',0
errormsg2:
	dc.b	$0d,$0a,'ERROR! Could not save defaults.',0
MESSAGE:
	dc.b	$0d,$0a,'GSX 140 COLOR GRAPHICS DUMP.',$0d,$0a
	dc.b	'Copyright 1990 PanTek',$0d,$0a
	DC.B	'Programmed by T.Barker.',$0d,$0a
	dc.b	'Return for defaults.',$0d,$0a,0
sizemsg:
	dc.b	'What size dump would you like',$0d,$0a
	dc.b	27,'p','F',27,'q','ull or '
	dc.b	27,'p','H',27,'q','alf ? ',$0d,$0a,0
brightmsg:
	dc.b	$0d,$0a,'What exposure would you like',$0d,$0a
	dc.b	'Normal.....Bright',$0d,$0a
	dc.b	27,'p'
	dc.b	'0   1   2   3   4 ',27,'q','? ',$0d,$0a,0
pinsmsg:
	dc.b	$0d,$0a,'What resolution dump would you like ?',$0d,$0a
	dc.b	27,'p','9',27,'q',' or ',27,'p','2',27,'q','4 ?',$0d,$0a
	dc.b	0
