;
; IFFMaster Pro v0.99n - Release 2
;
; The Original Release 1 had corrupted source, this version is now 100%
; (This version now assembles correctly with ASM-One v1.25)
;
; ©1994 REbEL
;
; This program and its source may be freely distributed but the copyright
; remains at all times with myself. The code may not be altered in any
; manner, and no person may claim responsibility for writing this program.
; This source is provided purely as an insight into IFF ILBM handling and
; system coding in assembler.
;
; An IFF to RAW converter which is based upon IFFMASTER but with the
; inclusion of AGA compatibility.
;
; Requires my system.gs file (included in this archive) and system
; includes revision 3.1 (v40).
;
;
; OPTIMAL TAB SIZE = 12
;	opt	o+,w-

	incdir	coding:os3.1/include/
	include	gst:os3_gst.i
	include	intuition/icclass.i
	include	libraries/gadtools.i
	
	easystart			* automatic WB startup code macro..
	
;file read macro
;call with fileread filehandle,buffer,length

fileread	MACRO
	movem.l	d1-d7/a0-a5,-(sp)
	move.l	\1,d1
	move.l	\2,d2
	move.l	\3,d3
	jsr	_LVORead(a6)
	movem.l	(sp)+,d1-d7/a0-a5
	cmp.l	\3,d0
	bne	readerr
	ENDM

;file write macro
;call with filewrite filehandle,buffer,length
filewrite	MACRO
	movem.l	d1-d6/a0-a5,-(sp)
	move.l	\1,d1
	move.l	\2,d2
	move.l	\3,d3
	move.l	d3,d7
	jsr	_LVOWrite(a6)
	movem.l	(sp)+,d1-d6/a0-a5
	cmp.l	d7,d0
	bne	writeerr
	ENDM

;file skip macro
;call with fileskip handle,skip_amount
;note also that current seek position (after operation) is returned in D0

fileskip	MACRO
	move.l	\1,d1
	move.l	\2,d2
	move.l	\2,d7
	move.l	#OFFSET_CURRENT,d3
	jsr	_LVOSeek(a6)
	add.l	d7,d0
	ENDM

;file move macro
;call with filemove handle,offset

filemove	MACRO
	move.l	dosbase,a6
	move.l	\1,d1
	move.l	\2,d2
	move.l	#-1,d3
	jsr	_LVOSeek(a6)
	ENDM

;	opt	o+,w-

	move.l	4.w,a6
	lea	dosname,a1
	jsr	_LVOOldOpenLibrary(a6)
	move.l	d0,dosbase
	beq.w	nodos
	
	move.l	dosbase,a6
	jsr	_LVOOutput(a6)
	move.l	d0,stdout
	
	move.l	4.w,a6
	move.w	LIB_VERSION(a6),d0
	cmp.w	#36,d0
	blt.w	noks2
	
	move.l	4.w,a6
	lea	intuiname,a1
	move.l	#36,d0
	jsr	_LVOOpenLibrary(a6)
	move.l	d0,intuibase
	beq.w	nointui
	
	move.l	4.w,a6
	lea	gfxname,a1
	move.l	#39,d0
	jsr	_LVOOpenLibrary(a6)
	move.l	d0,gfx39base

	move.l	4.w,a6
	lea	gfxname,a1
	move.l	#36,d0
	jsr	_LVOOpenLibrary(a6)
	move.l	d0,gfxbase
	beq.w	nogfx
	
	lea	gadname,a1
	move.l	#36,d0
	jsr	_LVOOpenLibrary(a6)
	move.l	d0,gadbase
	beq.w	nogadt
	
	lea	dtname,a1
	move.l	#36,d0
	jsr	_LVOOpenLibrary(a6)
	move.l	d0,dtbase
	
	move.l	4.w,a6
	lea	reqtname,a1
	moveq	#0,d0
	jsr	_LVOOpenLibrary(a6)
	move.l	d0,reqtbase
	beq.w	noreqt
	
	move.w	#0,a0
	moveq	#0,d0
	move.l	reqtbase,a6
	jsr	_LVOrtAllocRequestA(a6)
	move.l	d0,req1
	beq.w	noreqa1
	
	move.w	#0,a0
	moveq	#0,d0
	move.l	reqtbase,a6
	jsr	_LVOrtAllocRequestA(a6)
	move.l	d0,req2
	beq.w	noreqa2
	
	move.l	#prefsname,d1
	move.l	#MODE_OLDFILE,d2
	move.l	dosbase,a6
	jsr	_LVOOpen(a6)
	tst.l	d0
	beq.b	noprefs
	
	move.l	d0,d1
	move.l	d0,d6
	move.l	#oldprefs,d2
	move.l	#endnewprefs-newprefs,d3
	jsr	_LVORead(a6)
	move.l	d0,d5
	move.l	d6,d1
	jsr	_LVOClose(a6)
	
	cmp.l	#endnewprefs-newprefs,d5
	bne.b	noprefs
	
	lea	oldprefs,a0
	lea	newprefs,a1
	move.w	#endnewprefs-newprefs-1,d0
copyprefs	move.b	(a0)+,(a1)+
	dbf	d0,copyprefs
	
noprefs	move.l	reqtbase,a6
	move.l	req1,a1
	lea	loadtags,a0
	jsr	_LVOrtChangeReqAttrA(a6)
	
	move.l	req2,a1
	lea	savetags,a0
	jsr	_LVOrtChangeReqAttrA(a6)
	
	move.l	#80*256*2,d0
	move.l	#MEMF_CHIP|MEMF_CLEAR,d1
	move.l	4.w,a6
	jsr	_LVOAllocMem(a6)
	tst.l	d0
	beq.w	noram
	
	move.l	d0,pladdr
	move.l	#80*256*2,plsize
	move.w	#80,bytewid1
	move.w	#640,pagewid
	move.w	#256,pageht
	move.w	#640,iffwidth
	move.w	#256,iffheight
	move.w	#2,iffdepth
	move.b	#2,lightest
	move.b	#1,darkest

	move.w	#2,d2
	move.w	#80*256,d1
	move.l	pladdr,d0
	lea	bplptr,a1
modi1	move.l	d0,(a1)+
	add.l	d1,d0
	sub.w	#1,d2
	bne.b	modi1

	lea	newscreen,a0
	move.l	intuibase,a6
	jsr	_LVOOpenScreen(a6)
	tst.l	d0
	beq.w	noram
	move.l	d0,scrpt1
	move.l	d0,scrpt2
	move.l	d0,scrpt3
	move.l	d0,scrpt4
	;move.l	d0,scrpt5
	
	move.w	iffdepth,cdepth
	move.w	cdepth,d0
	move.w	#1,d1
	lea	depthASCII,a0
	bsr.w	numtohexasc
	
	move.l	#1,d0
	move.w	iffdepth,d1
	lsl.l	d1,d0
	move.w	d0,d7
	sub.w	#1,d7
	lea	palstore1,a0
	lea	palstore2,a1

pal	moveq	#0,d2
	move.b	(a0)+,d1
	and.b	#$F0,d1
	lsr.b	#4,d1
	or.b	d1,d2
	lsl.w	#4,d2
	move.b	(a0)+,d1
	and.b	#$F0,d1
	lsr.b	#4,d1
	or.b	d1,d2
	lsl.w	#4,d2
	move.b	(a0)+,d1
	and.b	#$F0,d1
	lsr.b	#4,d1
	or.b	d1,d2
	move.w	d2,(a1)+
	dbf	d7,pal
	
	lea	palstore2,a1
	move.l	scrpt1,a0
	lea	sc_ViewPort(a0),a0
	move.l	gfxbase,a6
	jsr	_LVOLoadRGB4(a6)
	
	lea	newwindow,a0
	move.l	intuibase,a6
	jsr	_LVOOpenWindow(a6)
	move.l	d0,winpt1
	move.l	d0,winpt2
	move.l	d0,winpt3
	move.l	d0,winpt4
	beq.w	noram
	
	move.l	winpt1,a0
	lea	menu1,a1
	move.l	intuibase,a6
	jsr	_LVOSetMenuStrip(a6)
	
	move.l	winpt1,a0
	lea	mousept,a1
	move.w	#15,d0
	move.w	#15,d1
	move.w	#-7,d2
	move.w	#-7,d3
	jsr	_LVOSetPointer(a6)
	
	move.l	winpt1,a1
	move.l	wd_RPort(a1),a1
	move.b	#RP_COMPLEMENT,d0
	move.l	gfxbase,a6
	jsr	_LVOSetDrMd(a6)
	
	lea	bitmap,a0
	moveq	#0,d0
	moveq	#0,d1
	move.l	winpt1,a1
	move.l	wd_RPort(a1),a1
	clr.w	d2
	clr.w	d3
	
	move.w	pagewid,d4
	cmp.w	iffwidth,d4
	blt.b	thinpic
	move.w	iffwidth,d4
	
thinpic	move.w	pageht,d5
	cmp.w	iffheight,d5
	blt.b	shortpic
	move.w	iffheight,d5
	add.w	#$16,d5
	
shortpic	sub.w	#$16,d5
	move.b	#$C0,d6
	move.l	gfxbase,a6
	jsr	_LVOBltBitMapRastPort(a6)
	
	clr.w	scrollx
	clr.w	scrolly
portwait	move.l	4.w,a6
	move.l	winpt1,a0
	move.l	wd_UserPort(a0),a0
	jsr	_LVOWaitPort(a6)
	
nomessage1	move.l	winpt1,a0
	move.l	wd_UserPort(a0),a0
	move.l	4.w,a6
	jsr	_LVOGetMsg(a6)
	tst.l	d0
	beq.b	portwait
	
	move.l	d0,message
	move.l	d0,a1
	jsr	_LVOReplyMsg(a6)
	
	move.l	message,a0
	move.l	$14(a0),d0

	cmp.l	#MENUVERIFY,d0
	beq.w	menuon

	cmp.l	#MENUPICK,d0
	beq.w	menu
	
	cmp.l	#RAWKEY,d0
	beq.w	rawkey
	
	cmp.l	#MOUSEMOVE,d0
	beq.w	mousemove
	
	cmp.l	#MOUSEBUTTONS,d0
	beq.b	mousebut
	 
	bra.b	nomessage1

mousebut	not.b	lmbpress
	beq.w	mouserel
	tst.b	brushon
	bne.w	brushset
	tst.w	mousey
	bge.b	mouseok
	st	intopborder
	bra.b	brushset

mouseok	sf	intopborder
	tst.w	brtlx
	bge.b	brushset
	tst.w	brtly
	bge.b	brushset
	tst.w	brbrx
	bge.b	brushset
	tst.w	brbry
	bge.b	brushset
	move.w	mousex,brtlx
	move.w	mousey,brtly
	move.w	mousex,brbrx
	move.w	mousey,brbry
	move.w	scrollx,d0
	move.w	scrolly,d1
	add.w	d0,brtlx
	add.w	d0,brbrx
	add.w	d1,brtly
	add.w	d1,brbry
	bsr.w	updatecoords
	bsr.w	drawbrushgrid
brushset	bra.w	nomessage1

mouserel	tst.b	intopborder
	bne.w	nomessage1
	st	brushon
	bra.w	nomessage1

mousemove	move.w	$20(a0),d6
	move.w	$22(a0),d7
	tst.w	mousex
	bge.b	undrawcrosshair
	tst.w	mousey
	bge.b	undrawcrosshair
	bra.b	noundraw

undrawcrosshair
	bsr.w	drawcrosshair
	move.w	#$FFFF,mousex
	move.w	#$FFFF,mousey
noundraw	tst.w	d7
	blt.w	inborder
	move.w	d7,d5
	cmp.w	iffwidth,d6
	bgt.w	inborder
	cmp.w	iffheight,d5
	bgt.w	inborder
	move.w	d6,mousex
	move.w	d7,mousey
	tst.b	lmbpress
	beq.b	nobrush
	tst.b	intopborder
	bne.b	nobrush
	tst.b	brushon
	bne.b	nobrush
	bsr.w	drawbrushgrid

nobrush	lea	widASCII,a0
	move.w	iffwidth,d0
	bsr.w	numtoascii
	lea	heightASCII,a0
	move.w	iffheight,d0
	bsr.w	numtoascii
	lea	xASCII,a0
	move.w	mousex,d0
	add.w	scrollx,d0
	bsr.w	numtoascii
	lea	yASCII,a0
	move.w	mousey,d0
	add.w	scrolly,d0
	bsr.w	numtoascii
	
	move.w	mousey,d1
	add.w	scrolly,d1
	mulu	bytewid1,d1

	move.b	#"A",addrmod-1
	
	cmp.b	#2,coordtype
	bne.b	notilcoordtype
	
	move.b	#"I",addrmod-1
	moveq	#0,d2
	move.w	cdepth,d2
	
	move.l	d0,-(sp)
	moveq	#0,d0
mulu9	add.l	d2,d0
	sub.l	#1,d1
	bne.b	mulu9
	move.l	d0,d1
	move.l	(sp)+,d0
	;mulu.l	d2,d1	68000 cannot do this
	
notilcoordtype
	moveq	#0,d0
	move.w	mousex,d0
	add.w	scrollx,d0
	lsr.w	#3,d0
	add.l	d0,d1
	move.l	d1,d0
	lea	addrmod,a0
	bsr.w	numtoascii2
	
	bsr.w	writecoords
	bsr.w	drawcrosshair
	tst.b	lmbpress
	beq.b	inborder
	tst.b	brushon
	bne.b	inborder
	tst.b	intopborder
	bne.b	inborder
	move.w	mousex,brbrx
	move.w	mousey,brbry
	move.w	scrollx,d0
	move.w	scrolly,d1
	add.w	d0,brbrx
	add.w	d1,brbry
	bsr.b	drawbrushgrid
	bsr.w	updatecoords
inborder	bra.w	nomessage1

drawbrushgrid
	move.w	brtlx,d0
	sub.w	scrollx,d0
	move.w	d0,brtlxoff
	move.w	brbrx,d0
	sub.w	scrollx,d0
	move.w	d0,brbrxoff
	move.w	brtly,d0
	sub.w	scrolly,d0
	move.w	d0,brtlyoff
	move.w	brbry,d0
	sub.w	scrolly,d0
	move.w	d0,brbryoff
	move.w	brtlxoff,d0
	move.w	brtlyoff,d1
	move.l	winpt1,a1
	
	move.l	wd_RPort(a1),a1
	move.l	gfxbase,a6
	jsr	_LVOMove(a6)
	
	move.w	brbrxoff,d0
	move.w	brtlyoff,d1
	move.l	winpt1,a1
	move.l	wd_RPort(a1),a1
	jsr	_LVODraw(a6)
	
	move.w	brbrxoff,d0
	move.w	brbryoff,d1
	move.l	winpt1,a1
	move.l	wd_RPort(a1),a1
	jsr	_LVODraw(a6)
	
	move.w	brtlxoff,d0
	move.w	brbryoff,d1
	move.l	winpt1,a1
	move.l	wd_RPort(a1),a1
	jsr	_LVODraw(a6)
	
	move.w	brtlxoff,d0
	move.w	brtlyoff,d1
	move.l	winpt1,a1
	move.l	wd_RPort(a1),a1
	jsr	_LVODraw(a6)
	
	move.w	brtlx,d6
	sub.w	scrollx,d6
	move.w	brbrx,d7
	sub.w	scrollx,d7
	
	cmp.w	d6,d7
	bge.b	noswap
	exg	d6,d7
	
noswap	sub.w	#1,d6
drawgrid	add.w	#$10,d6
	cmp.w	d7,d6
	bge.b	drawdone
	move.w	d6,d0
	move.w	brtlyoff,d1
	move.l	winpt1,a1
	move.l	wd_RPort(a1),a1
	jsr	_LVOMove(a6)
	
	move.w	d6,d0
	move.w	brbryoff,d1
	move.l	winpt1,a1
	move.l	wd_RPort(a1),a1
	jsr	_LVODraw(a6)
	bra.b	drawgrid
drawdone	rts

drawcrosshair
	move.l	gfxbase,a6
	clr.w	d0
	move.w	mousey,d1
	move.l	winpt1,a1
	move.l	wd_RPort(a1),a1
	jsr	_LVOMove(a6)
	
	move.w	pagewid,d0
	move.w	mousey,d1
	move.l	winpt1,a1
	move.l	wd_RPort(a1),a1
	jsr	_LVODraw(a6)
	
	move.w	mousex,d0
	clr.w	d1
	move.l	winpt1,a1
	move.l	wd_RPort(a1),a1
	jsr	_LVOMove(a6)
	
	move.w	mousex,d0
	move.w	pageht,d1
	move.l	winpt1,a1
	move.l	wd_RPort(a1),a1
	jsr	_LVODraw(a6)
	rts

updatecoords
	tst.w	brtlx
	bmi.b	clearbrushtxt
	tst.w	brtly
	bmi.b	clearbrushtxt
	tst.w	brbrx
	bmi.b	clearbrushtxt
	tst.w	brbry
	bmi.b	clearbrushtxt
	bra.b	updatebrtxt

clearbrushtxt
	move.b	#' ',brwidASCII
	move.b	#' ',brwidASCII+1
	move.b	#' ',brwidASCII+2
	move.b	#' ',brwidASCII+3
	move.b	#' ',brhtASCII
	move.b	#' ',brhtASCII+1
	move.b	#' ',brhtASCII+2
	move.b	#' ',brhtASCII+3
	bra.b	updatedone

updatebrtxt	move.w	brtlx,d0
	sub.w	brbrx,d0
	bpl.b	noswap1
	neg.w	d0
noswap1	add.w	#1,d0
	lea	brwidASCII,a0
	bsr.w	numtoascii
	move.w	brtly,d0
	sub.w	brbry,d0
	bpl.b	noswap2
	neg.w	d0
noswap2	add.w	#1,d0
	lea	brhtASCII,a0
	bsr.w	numtoascii
updatedone	bsr.w	writecoords
	rts

rawkey	move.w	$18(a0),d0
	lea	keytable,a0
getroutine	move.w	(a0)+,d1
	cmp.w	#$FFFF,d1
	beq.b	cantfind
	cmp.w	d0,d1
	bne.b	notroutine
	move.l	(a0),a1
	movem.l	d0/a0,-(sp)
	jsr	(a1)
	movem.l	(sp)+,d0/a0
notroutine	add.l	#4,a0
	bra.b	getroutine
cantfind	bra.w	nomessage1

altkey	not.b	altpressed
	rts

ctrlkey	not.b	ctrlpressed
	rts

scrollrt	tst.b	ctrlpressed
	bne.w	farright
	
	tst.b	altpressed
	bne.w	pageright
	
	move.w	iffwidth,d0
	sub.w	pagewid,d0
	sub.w	scrollx,d0
	ble.b	noscroll2
	move.w	#4,d1
	cmp.w	#4,d0
	bge.b	noscroll1
	move.w	d0,d1
noscroll1	add.w	d1,scrollx
	bra.w	redraw
noscroll2	rts

scrolllt	tst.b	ctrlpressed
	bne.w	farleft
	
	tst.b	altpressed
	bne.w	pageleft
	
	tst.w	scrollx
	beq.b	noscroll4
	move.w	#4,d1
	cmp.w	#4,scrollx
	bge.b	noscroll3
	move.w	scrollx,d1
noscroll3	sub.w	d1,scrollx
	bra.w	redraw
noscroll4	rts

scrolldn	tst.b	ctrlpressed
	bne.w	verybottom
	
	tst.b	altpressed
	bne.w	pagedown
	
	move.w	iffheight,d0
	sub.w	pageht,d0
	add.w	#$16,d0
	sub.w	scrolly,d0
	ble.b	noscroll6
	move.w	#4,d1
	cmp.w	#4,d0
	bge.b	noscroll5
	move.w	d0,d1
noscroll5	add.w	d1,scrolly
	bra.w	redraw
noscroll6	rts

scrollup	tst.b	ctrlpressed
	bne.b	verytop
	
	tst.b	altpressed
	bne.w	pageup
	
	tst.w	scrolly
	beq.b	noscroll8
	move.w	#4,d1
	cmp.w	#4,scrolly
	bge.b	noscroll7
	move.w	scrolly,d1
noscroll7	sub.w	d1,scrolly
	bra.w	redraw
noscroll8	rts

farleft	tst.w	scrollx
	beq.b	noscroll9
	clr.w	scrollx
	bra.w	redraw
noscroll9	rts
	
verytop	tst.w	scrolly
	beq.b	noscroll10
	clr.w	scrolly
	bra.w	redraw
noscroll10	rts
	
farright	move.w	iffwidth,d0
	sub.w	pagewid,d0
	cmp.w	scrollx,d0
	beq.b	noscroll11
	move.w	d0,scrollx
	bra.w	redraw
noscroll11	rts

verybottom	move.w	iffheight,d0
	sub.w	pageht,d0
	add.w	#$16,d0
	cmp.w	scrolly,d0
	beq.b	noscroll12
	move.w	d0,scrolly
	bra.w	redraw
noscroll12	rts

pageleft	tst.w	scrollx
	beq.b	noscroll13
	move.w	scrollx,d0
	sub.w	pagewid,d0
	bge.b	notle

	clr.w	d0

notle	move.w	d0,scrollx
	bra.w	redraw
noscroll13	rts


pageright	move.w	iffwidth,d0
	sub.w	pagewid,d0
	cmp.w	scrollx,d0
	beq.b	noscroll14
	
	move.w	scrollx,d0
	add.w	pagewid,d0
	move.w	d0,d1
	add.w	pagewid,d1
	cmp.w	iffwidth,d1
	blt.b	notre
	
	move.w	iffwidth,d0
	sub.w	pagewid,d0

notre	move.w	d0,scrollx
	bra.b	redraw
noscroll14	rts

pageup	tst.w	scrolly
	beq.b	noscroll15
	move.w	scrolly,d0
	sub.w	pageht,d0
	add.w	#$16,d0
	bge.b	notte

	clr.w	d0

notte	move.w	d0,scrolly
	bra.b	redraw
noscroll15	rts

pagedown	move.w	iffheight,d0
	sub.w	pageht,d0
	add.w	#$16,d0
	cmp.w	scrolly,d0
	beq.b	noscroll16
	
	move.w	scrolly,d0
	add.w	pageht,d0
	sub.w	#$16,d0
	move.w	d0,d1
	add.w	pageht,d1
	sub.w	#$16,d1
	cmp.w	iffheight,d1
	blt.b	notbe
	
	move.w	iffheight,d0
	sub.w	pageht,d0
	add.w	#$16,d0

notbe	move.w	d0,scrolly
	bra.b	redraw
noscroll16	rts


redraw	tst.w	brtlx
	bge.b	clearbr
	tst.w	brtly
	bge.b	clearbr
	tst.w	brbrx
	bge.b	clearbr
	tst.w	brbry
	bge.b	clearbr
	bra.b	noclearbr

clearbr	bsr.w	drawbrushgrid
noclearbr	bsr.w	drawcrosshair

	lea	bitmap,a0
	moveq	#0,d0
	move.w	scrollx,d0
	moveq	#0,d1
	move.w	scrolly,d1
	move.l	winpt1,a1
	move.l	wd_RPort(a1),a1
	clr.w	d2
	clr.w	d3
	move.w	pagewid,d4
	cmp.w	iffwidth,d4
	blt.b	notwide
	
	move.w	iffwidth,d4
	
notwide	move.w	pageht,d5
	cmp.w	iffheight,d5
	blt.b	nottall
	
	move.w	iffheight,d5
	add.w	#$16,d5
	
nottall	sub.w	#$16,d5
	move.b	#$C0,d6
	move.l	gfxbase,a6
	jsr	_LVOBltBitMapRastPort(a6)
	
	tst.w	brtlx
	bge.b	putbr
	tst.w	brtly
	bge.b	putbr
	tst.w	brbrx
	bge.b	putbr
	tst.w	brbry
	bge.b	putbr
	bra.b	noputbr

putbr	tst.b	brushon
	bne.b	brushlocked
	move.w	mousex,brbrx
	move.w	mousey,brbry
	move.w	scrollx,d0
	move.w	scrolly,d1
	add.w	d0,brbrx
	add.w	d1,brbry

brushlocked	bsr.w	drawbrushgrid
noputbr	bsr.w	drawcrosshair

	lea	widASCII,a0
	move.w	iffwidth,d0
	bsr.w	numtoascii
	lea	heightASCII,a0
	move.w	iffheight,d0
	bsr.w	numtoascii
	lea	xASCII,a0
	move.w	mousex,d0
	add.w	scrollx,d0
	bsr.w	numtoascii
	lea	yASCII,a0
	move.w	mousey,d0
	add.w	scrolly,d0
	bsr.w	numtoascii
	bsr.w	writecoords
	rts

menuon	lea	menupal,a1
	move.l	scrpt1,a0
	lea	sc_ViewPort(a0),a0
	move.l	#4,d0
	move.l	gfxbase,a6
	jsr	_LVOLoadRGB4(a6)
	bra.w	nomessage1
	
menu	bsr.w	fakebpl
	move.l	message,a0
	move.w	$18(a0),d0
	move.w	d0,d1
	and.w	#%0000000000000001,d1
	move.w	d0,d2
	and.w	#%0000000111100000,d2
	lsr.w	#5,d2
	and.w	#%1111111100000000,d0
	lsr.w	#8,d0
	lsr.w	#3,d0
	
	cmp.w	#0,d1
	bne.b	menu2sel
	tst.w	d2
	beq.b	load
	cmp.w	#1,d2
	beq.w	savepic
	cmp.w	#2,d2
	beq.w	savebr
	cmp.w	#3,d2
	beq.w	savesprite
	cmp.w	#5,d2
	beq.w	screenmode
	cmp.w	#6,d2
	beq.w	prefs
	cmp.w	#7,d2
	beq.w	about
	cmp.w	#9,d2
	beq.w	close
	bra.w	nomessage1

menu2sel	tst.w	d2
	beq.w	brush
	cmp.w	#1,d2
	beq.w	palette
	cmp.w	#3,d2
	beq.w	savepal
	cmp.w	#4,d2
	beq.w	savebrmask
	cmp.w	#5,d2
	beq.w	savepicmask
	bra.w	nomessage1

load	clr.b	filename
	move.l	req1,a1
	lea	filename,a2
	lea	loadtxt,a3
	lea	tags2,a0
	move.l	reqtbase,a6
	jsr	_LVOrtFileRequestA(a6)
	tst.l	d0
	beq.w	nomessage1
	
	move.l	req1,a1
	move.l	rtfi_Dir(a1),d1
	move.l	#SHARED_LOCK,d2
	move.l	dosbase,a6
	jsr	_LVOLock(a6)
	move.l	d0,filelock
	beq.w	readerr
	
	move.l	d0,d1
	jsr	_LVOCurrentDir(a6)
	move.l	d0,olddirlock
	
	move.l	#filename,d1
	move.l	#MODE_OLDFILE,d2
	move.l	dosbase,a6
	jsr	_LVOOpen(a6)
	tst.l	d0
	beq.w	readerr
	move.l	d0,handle1
	
	fileread	handle1,#store1,#4
	cmp.l	#'FORM',store1
	bne.w	notiff
	
	fileread	handle1,#store1,#4
	sub.l	#4,store1
	move.l	store1,iffend
	
	fileread	handle1,#store1,#4
	cmp.l	#'ILBM',store1
	bne.w	notiff
	
findbmhd	fileread	handle1,#store1,#4
	cmp.l	#'BMHD',store1
	beq.w	bmhdfound
	
	fileread	handle1,#store1,#4
	fileskip	handle1,store1
	move.l	d0,seekpos
	
	move.l	d0,d1
	add.l	#1,d0
	and.l	#$FFFFFFFE,d0
	sub.l	d1,d0
	beq.b	nopad
	
	fileskip	handle1,#1
	
nopad	move.l	seekpos,d0
	sub.l	#12,d0
	cmp.l	iffend,d0
	beq.w	notiff
	bra.w	findbmhd

bmhdfound	fileskip	handle1,#4

	fileread	handle1,#store1,#2
	move.w	store1,iffwidth
	
	fileread	handle1,#store1,#2
	move.w	store1,iffheight
	
	fileskip	handle1,#4
	moveq	#0,d0
	
	fileread	handle1,#store1,#1
	move.b	store1,d0
	move.w	d0,iffdepth
	
	fileread	handle1,#store1,#1
	move.b	store1,mask
	
	fileread	handle1,#store1,#1
	move.b	store1,comp
	move.l	handle1,d1
	
	fileskip	handle1,#1
	fileskip	handle1,#2
	
	fileread	handle1,#store1,#2
	move.w	store1,aspects
	
	fileread	handle1,#store1,#2
	move.w	store1,pagewid
	
	fileread	handle1,#store1,#2
	move.w	store1,pageht
	
	moveq	#0,d0
	move.w	iffwidth,d0
	add.w	#15,d0
	divu	#16,d0
	add.w	d0,d0
	move.w	d0,bytewid1
	
	moveq	#0,d0
	move.w	iffwidth,d0
	move.w	d0,width
	add.w	#15,d0
	divu	#16,d0
	add.w	d0,d0
	move.w	d0,bytewid2
	
	move.w	bytewid2,d0
	move.w	iffheight,d1
	move.w	d1,height
	mulu	d1,d0
	moveq	#0,d1
	move.w	iffdepth,d1
	
	move.l	d2,-(sp)
	moveq	#0,d2
mulu1	add.l	d0,d2
	sub.l	#1,d1
	bne.b	mulu1
	move.l	d2,d0
	move.l	(sp)+,d2
	;mulu.l	d1,d0	68000 cannot do this
	
	move.l	plsize,oldplsize
	move.l	d0,plsize
	
	filemove	handle1,#12

findcamg	fileread	handle1,#store1,#4
	cmp.l	#'CAMG',store1
	beq.w	camgfound
	
	fileread	handle1,#store1,#4
	fileskip	handle1,store1
	move.l	d0,seekpos
	
	move.l	d0,d1
	add.l	#1,d0
	and.l	#$FFFFFFFE,d0
	sub.l	d1,d0
	beq.b	nopad3
	move.l	handle1,d1
	
	fileskip	handle1,#1
	
nopad3	move.l	seekpos,d0
	sub.l	#12,d0
	cmp.l	iffend,d0
	beq.b	nocamg
	bra.w	findcamg

nocamg	move.l	#0,iffcamg	;standard lores 320x256
	bra.b	camgdone

camgfound	fileskip	handle1,#4

	fileread	handle1,#iffcamg,#4

camgdone	filemove	handle1,#12


findcmap	fileread	handle1,#store1,#4
	cmp.l	#'CMAP',store1
	beq.w	cmapfound
	
	fileread	handle1,#store1,#4
	fileskip	handle1,store1
	move.l	d0,seekpos
	
	move.l	d0,d1
	add.l	#1,d0
	and.l	#$FFFFFFFE,d0
	sub.l	d1,d0
	beq.b	nopad2
	
	fileskip	handle1,#1
	
nopad2	move.l	seekpos,d0
	sub.l	#12,d0
	cmp.l	iffend,d0
	beq.w	notiff
	bra.w	findcmap

cmapfound	fileread	handle1,#store1,#4

	move.l	store1,d7
	lea	palstore1,a5
	moveq	#0,d5
	moveq	#0,d2
	move.l	#$7fff,d4

copypal	fileread	handle1,#store1,#3
	move.b	store1,(a5)+
	move.b	store1+1,(a5)+
	move.b	store1+2,(a5)+
	moveq	#0,d6
	clr.w	d3
	move.b	store1,d6
	move.b	store1+1,d3
	add.w	d3,d6
	move.b	store1+2,d3
	add.w	d3,d6
	
	move.w	iffdepth,d1
	
	move.l	iffcamg,d0
	and.l	#$800,d0
	beq.b	notham
	
	sub.w	#2,d1
	
notham	and.l	#$80,d0
	beq.b	nothbr
	
	sub.w	#1,d1

nothbr	move.l	#1,d0
	lsl.w	d1,d0
	
	cmp.w	d0,d2
	bge.b	outofrange
	
	cmp.w	d6,d5
	bge.b	notlight
	
	move.w	d6,d5
	move.b	d2,lightest
	
notlight	cmp.w	d6,d4
	ble.b	notdark
	
	move.w	d6,d4
	move.b	d2,darkest

outofrange
notdark	add.l	#1,d2
	sub.w	#3,d7
	bne.w	copypal
	
	move.l	intuibase,a6
	move.l	winpt1,a0
	jsr	_LVOClearMenuStrip(a6)
	
	move.l	winpt1,a0
	jsr	_LVOCloseWindow(a6)
	clr.l	winpt1
	
	move.l	scrpt1,a0
	jsr	_LVOCloseScreen(a6)

	clr.l	scrpt1

	tst.l	pladdr
	beq.b	nobplns1
	
	move.l	pladdr,a1
	move.l	oldplsize,d0
	move.l	4.w,a6
	jsr	_LVOFreeMem(a6)
	clr.l	pladdr
	
nobplns1	move.w	bytewid2,bytesperrow
	move.w	height,height2
	move.w	iffdepth,d0
	move.b	d0,scdepth

	move.l	plsize,d0
	move.l	#MEMF_CHIP|MEMF_CLEAR,d1
	move.l	4.w,a6
	jsr	_LVOAllocMem(a6)
	tst.l	d0
	beq.w	noplram
	move.l	d0,pladdr

	move.w	iffdepth,d2
	move.w	bytewid2,d1
	mulu	height,d1
	move.l	pladdr,d0
	lea	bplptr,a1
	
modibpl1	move.l	d0,(a1)+
	add.l	d1,d0
	sub.w	#1,d2
	bne.b	modibpl1
	
	move.w	pagewid,scrwid
	move.w	pagewid,winwidth
	move.w	pageht,scrht
	move.w	pageht,winheight
	sub.w	#22,winheight

	move.w	iffdepth,scrdepth
	move.l	iffcamg,d0

camgmask	equ	~(V_SPRITES|V_VP_HIDE|GENLOCK_AUDIO|GENLOCK_VIDEO|MONITOR_ID_MASK)

	and.l	#camgmask,d0
	move.l	d0,scrvmodes
	
	move.l	intuibase,a6
	lea	newscreen,a0
	jsr	_LVOOpenScreen(a6)
	tst.l	d0
	beq.w	noram
	move.l	d0,scrpt1
	move.l	d0,scrpt2
	move.l	d0,scrpt3
	move.l	d0,scrpt4
	;move.l	d0,scrpt5
	
	move.w	iffdepth,cdepth
	move.w	cdepth,d0
	move.w	#1,d1
	lea	depthASCII,a0
	bsr.w	numtohexasc
	
	lea	newwindow,a0
	move.l	intuibase,a6
	jsr	_LVOOpenWindow(a6)
	move.l	d0,winpt1
	move.l	d0,winpt2
	move.l	d0,winpt3
	move.l	d0,winpt4
	beq.w	noram

	move.w	pageht,d0
	sub.w	#50,d0
	lsr.w	#1,d0
	move.w	d0,loadwiny
	move.w	pagewid,d0
	sub.w	#280,d0
	lsr.w	#1,d0
	move.w	d0,loadwinx
	move.l	#lwintitle,windowtitle
	
	lea	newloadwin,a0
	move.l	intuibase,a6
	jsr	_LVOOpenWindow(a6)
	move.l	d0,lswindow
	bsr.w	drawLSwin
	
	move.l	winpt1,a0
	lea	menu1,a1
	move.l	intuibase,a6
	jsr	_LVOSetMenuStrip(a6)
	
	move.l	winpt1,a0
	lea	mousept,a1
	move.w	#15,d0
	move.w	#15,d1
	move.w	#-8,d2
	move.w	#-7,d3
	jsr	_LVOSetPointer(a6)
	
	move.l	winpt1,a1
	move.l	wd_RPort(a1),a1
	move.b	#RP_COMPLEMENT,d0
	move.l	gfxbase,a6
	jsr	_LVOSetDrMd(a6)
	
	move.w	#$FFFF,brtlx
	move.w	#$FFFF,brtly
	move.w	#$FFFF,brbrx
	move.w	#$FFFF,brbry
	sf	brushon
	bsr.w	updatecoords
	
	filemove	handle1,#12
	
findbody	fileread	handle1,#store1,#4
	cmp.l	#'BODY',store1
	beq.w	bodyfound
	
	fileread	handle1,#store1,#4
	fileskip	handle1,store1
	move.l	d0,seekpos
	
	move.l	d0,d1
	add.l	#1,d0
	and.l	#$FFFFFFFE,d0
	sub.l	d1,d0
	beq.b	nopad4
	
	fileskip	handle1,#1
	
nopad4	move.l	seekpos,d0
	sub.l	#12,d0
	cmp.l	iffend,d0
	beq.w	notiff
	bra.w	findbody

bodyfound	tst.b	comp
	beq.w	nocomp
	
	fileread	handle1,#store1,#4
	move.l	store1,bodylen
	
	move.l	#copybuffend,buffptr
	moveq	#0,d3
	move.l	pladdr,a1
	moveq	#0,d2
	move.w	iffheight,d2

	cmp.b	#1,mask
	bne.b	nomaskpl
	
	add.w	#1,iffdepth
nomaskpl
nextline	move.w	iffheight,maxline
	move.w	d2,lineno
	bsr.w	updateLSwin

	move.w	iffdepth,d1
	sub.w	#1,d1
nextplane	move.w	bytewid1,d4
	sub.w	#1,d4

next	move.l	buffptr,a0
	cmp.l	#copybuffend,a0
	bne.b	notend1

	movem.l	d1-d7/a0-a5,-(sp)
	move.l	handle1,d1
	move.l	#copybuff,d2
	move.l	#1024*8,d3
	cmp.l	#1024*8,bodylen
	bge.b	noeof1
	move.l	bodylen,d3
noeof1	sub.l	d3,bodylen
	move.l	d3,lenstore
	
	jsr	_LVORead(a6)
	movem.l	(sp)+,d1-d7/a0-a5
	cmp.l	lenstore,d0
	bne.w	readerr
	lea	copybuff,a0

notend1	move.b	(a0)+,d7
	move.l	a0,buffptr
	tst.b	d7
	bpl.w	copy
	
	move.l	buffptr,a0
	cmp.l	#copybuffend,a0
	bne.b	notend2

	movem.l	d1-d7/a0-a5,-(sp)
	move.l	handle1,d1
	move.l	#copybuff,d2
	move.l	#1024*8,d3
	cmp.l	#1024*8,bodylen
	bge.b	noeof2
	move.l	bodylen,d3
noeof2	sub.l	d3,bodylen
	move.l	d3,lenstore
	
	jsr	_LVORead(a6)
	movem.l	(sp)+,d1-d7/a0-a5
	cmp.l	lenstore,d0
	bne.w	readerr
	lea	copybuff,a0

notend2	move.b	(a0)+,d6
	move.l	a0,buffptr
	
	ext.w	d7
	neg.w	d7
	add.w	#1,d7
	sub.w	d7,d4
	sub.w	#1,d7
	
replicate	tst.w	d1
	bne.b	nolastpl
	cmp.b	#1,mask
	bne.b	nolastpl
	add	#1,a1
	bra.b	nop1
		
nolastpl	move.b	d6,(a1)+
nop1	dbf	d7,replicate
	bra.w	testend

copy	ext.w	d7
	and.l	#$FFFF,d7
	add.w	#1,d7
	sub.w	d7,d4
	
	sub.l	#1,d7
	move.l	buffptr,a0
	
copybyte	cmp.l	#copybuffend,a0
	bne.b	notend3

	movem.l	d1-d7/a0-a5,-(sp)
	move.l	handle1,d1
	move.l	#copybuff,d2
	move.l	#1024*8,d3
	cmp.l	#1024*8,bodylen
	bge.b	noeof3
	move.l	bodylen,d3
noeof3	sub.l	d3,bodylen
	move.l	d3,lenstore
	
	jsr	_LVORead(a6)
	movem.l	(sp)+,d1-d7/a0-a5
	cmp.l	lenstore,d0
	bne.w	readerr
	lea	copybuff,a0
	
notend3	tst.w	d1
	bne.b	notlastpl2
	
	cmp.b	#1,mask
	bne.b	notlastpl2
	add.l	#1,a0
	add.l	#1,a1
	bra.b	nop2
	
notlastpl2	move.b	(a0)+,(a1)+
nop2	dbf	d7,copybyte
	move.l	a0,buffptr

testend	tst.w	d4
	bge.w	next
	cmp.w	#$FFFF,d4
	beq.b	noerr
	bra.w	corrupterr

noerr	moveq	#0,d7
	move.w	bytewid1,d7
	sub.l	d7,a1
	move.w	bytewid2,d7
	mulu	height,d7
	add.l	d7,a1
	dbf	d1,nextplane

	move.w	bytewid2,d7
	mulu	height,d7
	
	move.l	d1,-(sp)
	moveq	#0,d1
	move.w	iffdepth,d1
	
	move.l	d2,-(sp)
	moveq	#0,d2
mulu2	add.l	d7,d2
	sub.l	#1,d1
	bne.b	mulu2
	move.l	d2,d7
	move.l	(sp)+,d2
	;mulu.l	d1,d7	68000 cannot do this
	
	move.l	(sp)+,d1
	
	sub.l	d7,a1
	move.w	bytewid2,d4
	lea	0(a1,d4.w),a1
	
	sub.l	#1,d2
	bne.w	nextline
	
	cmp.b	#1,mask
	bne.b	nomaskpl2
	sub.w	#1,iffdepth
	
nomaskpl2	bra.w	bodydone


nocomp	fileread	handle1,#store1,#4
	move.l	store1,bodylen
	
	move.l	pladdr,a1
	moveq	#0,d5
	moveq	#0,d2
	move.w	iffheight,d2
nextline2	move.w	d2,lineno
	move.w	iffheight,maxline
	bsr.w	updateLSwin

	move.w	iffdepth,d1
	sub.w	#1,d1
	
nextplane2	move.w	bytewid1,d3
	fileread	handle1,a1,d3
	
	move.w	bytewid2,d7
	mulu	height,d7
	add.l	d7,a1
	dbf	d1,nextplane2
	
	cmp.b	#1,mask
	bne.b	nomask2
	
	fileskip	handle1,bytewid1
	
nomask2	move.w	bytewid2,d7
	mulu	height,d7
	
	moveq	#0,d1
	move.w	iffdepth,d1
	move.l	d2,-(sp)
	moveq	#0,d2
mulu3	add.l	d7,d2
	sub.l	#1,d1
	bne.b	mulu3
	move.l	d2,d7
	move.l	(sp)+,d2
	;mulu.l	d1,d7	68000 cannot do this
	
	move.l	handle1,d1
	sub.l	d7,a1
	
	move.w	bytewid2,d4
	lea	0(a1,d4.w),a1
	
	sub.l	#1,d2
	bne.w	nextline2
	
bodydone	bsr.w	closeLSwin
	bsr.w	closefile

	lea	pal32,a0
	move.w	#258-1,d0
clearpal	clr.l	(a0)+
	dbf	d0,clearpal
	
	tst.l	gfx39base
	beq.b	nogfx39
	
	move.l	gfx39base,a6
	move.l	#1,d0
	move.w	iffdepth,d1
	
	lsl.l	d1,d0
	lea	pal32,a1
	move.w	d0,d7
	mulu	#3,d7
	sub.w	#1,d7
	
	move.w	d0,(a1)+
	clr.w	(a1)+
	lea	palstore1,a0
	
convpal	move.b	(a0)+,d0
	and.l	#$FF,d0
	swap	d0
	lsl.l	#8,d0
	move.l	d0,(a1)+
	dbf	d7,convpal
	
	clr.l	(a1)+
	lea	pal32,a1
	move.l	scrpt1,a0
	lea	sc_ViewPort(a0),a0
	jsr	_LVOLoadRGB32(a6)
	bra.b	doblit

nogfx39	move.l	gfxbase,a6
	
	move.l	#1,d0
	move.w	iffdepth,d1
	
	lsl.l	d1,d0
	move.w	d0,d7
	sub.w	#1,d7
	
	lea	palstore1,a0
	lea	palstore2,a1
	
convpal2	moveq	#0,d2
	move.b	(a0)+,d1
	and.b	#$F0,d1
	lsr.b	#4,d1
	or.b	d1,d2
	lsl.w	#4,d2
	move.b	(a0)+,d1
	and.b	#$F0,d1
	lsr.b	#4,d1
	or.b	d1,d2
	lsl.w	#4,d2
	move.b	(a0)+,d1
	and.b	#$F0,d1
	lsr.b	#4,d1
	or.b	d1,d2
	move.w	d2,(a1)+
	dbf	d7,convpal2
	
	lea	palstore2,a1
	move.l	scrpt1,a0
	lea	sc_ViewPort(a0),a0
	jsr	_LVOLoadRGB4(a6)
	
doblit	lea	bitmap,a0
	moveq	#0,d0
	moveq	#0,d1
	move.l	winpt1,a1
	move.l	wd_RPort(a1),a1
	clr.w	d2
	clr.w	d3
	move.w	pagewid,d4
	cmp.w	iffwidth,d4
	blt.b	notwide1
	
	move.w	iffwidth,d4
	
notwide1	move.w	pageht,d5
	cmp.w	iffheight,d5
	blt.b	nothigh1
	
	move.w	iffheight,d5
	add.w	#$16,d5
	
nothigh1	sub.w	#$16,d5
	move.b	#$C0,d6
	jsr	_LVOBltBitMapRastPort(a6)

	clr.w	scrollx
	clr.w	scrolly
	move.w	#$FFFF,mousey
	move.w	#$FFFF,mousex
	bra.w	nomessage1

corrupterr	lea	bodyfmt5,a1
	lea	gadfmt5,a2
	lea	taglist,a0
	lea	0,a3
	lea	0,a4
	move.l	reqtbase,a6
	jsr	_LVOrtEZRequestA(a6)
	bra.w	bodydone

readerr	bsr.w	closeLSwin
	bsr.w	closefile

	lea	bodyfmt2,a1
	lea	gadfmt2,a2
	lea	taglist,a0
	lea	0,a3
	lea	0,a4
	move.l	reqtbase,a6
	jsr	_LVOrtEZRequestA(a6)
	bra.w	nomessage1

noplram	tst.l	dtobject
	beq.b	nodtobj2
	move.l	winpt1,a0
	move.l	dtobject,a1
	jsr	_LVORemoveDTObject(a6)
	
	move.l	dtobject,a0
	jsr	_LVODisposeDTObject(a6)

nodtobj2	bsr.w	closeLSwin

	lea	bodyfmt4,a1
	lea	gadfmt4,a2
	lea	taglist,a0
	lea	0,a3
	lea	0,a4
	move.l	reqtbase,a6
	jsr	_LVOrtEZRequestA(a6)
	bra.w	nomessage1

notiff	tst.l	dtbase
	beq.w	unknowntype
	
	move.l	dtbase,a6
	move.l	#filename,d0
	lea	dttags,a0
	jsr	_LVONewDTObjectA(a6)
	tst.l	d0
	beq.w	unknowntype
	move.l	d0,dtobject
	
	move.l	dtobject,a0
	lea	dtattrs,a2
	jsr	_LVOGetDTAttrsA(a6)
	
	move.l	dtwidth,d0
	move.w	d0,iffwidth
	move.l	d0,dtwidmod
	move.l	dtheight,d0
	move.w	d0,iffheight
	move.l	d0,dthtmod
	sub.l	#22,dthtmod
	
	move.l	bmhdaddr,a0	;get address of BMHD
	
	moveq	#0,d0
	move.b	bmh_Depth(a0),d0
	move.w	d0,iffdepth
	move.w	bmh_XAspect(a0),aspects
	move.w	bmh_PageWidth(a0),pagewid
	move.w	bmh_PageHeight(a0),pageht
	
	moveq	#0,d0
	move.w	iffwidth,d0
	add.w	#15,d0
	divu	#16,d0
	add.w	d0,d0
	move.w	d0,bytewid1
	
	moveq	#0,d0
	move.w	iffwidth,d0
	move.w	d0,width
	add.w	#15,d0
	divu	#16,d0
	add.w	d0,d0
	move.w	d0,bytewid2
	
	move.w	bytewid2,d0
	move.w	iffheight,d1
	move.w	d1,height
	mulu	d1,d0
	moveq	#0,d1
	move.w	iffdepth,d1
	
	move.l	d2,-(sp)
	moveq	#0,d2
mulu8	add.l	d0,d2
	sub.l	#1,d1
	bne.b	mulu8
	move.l	d2,d0
	move.l	(sp)+,d2
	;mulu.l	d1,d0	68000 cannot do this
	
	move.l	plsize,oldplsize
	move.l	d0,plsize
	

	move.l	colortable,a0
	lea	pal32,a1
	lea	palstore1,a2

	move.l	#1,d0
	move.w	iffdepth,d1
	lsl.l	d1,d0
	move.w	d0,(a1)+
	clr.w	(a1)+
	mulu	#3,d0
	
copypal3	move.l	(a0),d1
	rol.l	#8,d1
	move.b	d1,(a2)+
	move.l	(a0)+,(a1)+
	sub.w	#1,d0
	bne.b	copypal3

	move.l	intuibase,a6
	move.l	winpt1,a0
	jsr	_LVOClearMenuStrip(a6)
	
	move.l	winpt1,a0
	jsr	_LVOCloseWindow(a6)
	clr.l	winpt1
	
	move.l	scrpt1,a0
	jsr	_LVOCloseScreen(a6)
	clr.l	scrpt1
	
	tst.l	pladdr
	beq.b	nobplns2
	
	move.l	pladdr,a1
	move.l	oldplsize,d0
	move.l	4.w,a6
	jsr	_LVOFreeMem(a6)
	clr.l	pladdr
	
nobplns2	move.w	bytewid2,bytesperrow
	move.w	height,height2
	move.w	iffdepth,d0
	move.b	d0,scdepth

	move.l	plsize,d0
	move.l	#MEMF_CHIP|MEMF_CLEAR,d1
	move.l	4.w,a6
	jsr	_LVOAllocMem(a6)
	tst.l	d0
	beq.w	noplram
	move.l	d0,pladdr

	move.w	iffdepth,d2
	move.w	bytewid2,d1
	mulu	height,d1
	move.l	pladdr,d0
	lea	bplptr,a1
	
modibpl2	move.l	d0,(a1)+
	add.l	d1,d0
	sub.w	#1,d2
	bne.b	modibpl2

	move.w	pagewid,scrwid
	move.w	pagewid,winwidth
	move.w	pageht,scrht
	move.w	pageht,winheight
	sub.w	#22,winheight

	move.w	iffdepth,scrdepth
	move.l	iffcamg,d0

	and.l	#camgmask,d0
	move.l	d0,scrvmodes
	
	move.l	intuibase,a6
	lea	newscreen,a0
	jsr	_LVOOpenScreen(a6)
	tst.l	d0
	beq.w	noram
	move.l	d0,scrpt1
	move.l	d0,scrpt2
	move.l	d0,scrpt3
	move.l	d0,scrpt4
	;move.l	d0,scrpt5
	
	move.w	iffdepth,cdepth
	move.w	cdepth,d0
	move.w	#1,d1
	lea	depthASCII,a0
	bsr.w	numtohexasc
	
	lea	newwindow,a0
	move.l	intuibase,a6
	jsr	_LVOOpenWindow(a6)
	move.l	d0,winpt1
	move.l	d0,winpt2
	move.l	d0,winpt3
	move.l	d0,winpt4
	beq.w	noram
	
	move.l	winpt1,a0
	lea	menu1,a1
	move.l	intuibase,a6
	jsr	_LVOSetMenuStrip(a6)
	
	move.l	winpt1,a0
	lea	mousept,a1
	move.w	#15,d0
	move.w	#15,d1
	move.w	#-8,d2
	move.w	#-7,d3
	jsr	_LVOSetPointer(a6)
	
	move.l	winpt1,a1
	move.l	wd_RPort(a1),a1
	move.b	#RP_COMPLEMENT,d0
	move.l	gfxbase,a6
	jsr	_LVOSetDrMd(a6)
	
	move.w	#$FFFF,brtlx
	move.w	#$FFFF,brtly
	move.w	#$FFFF,brbrx
	move.w	#$FFFF,brbry
	sf	brushon
	bsr.w	updatecoords
	bsr.w	fakebpl

	move.l	dtbase,a6
	move.l	dtobject,a0
	sub.l	a1,a1
	sub.l	a2,a2
	lea	dtattrs2,a3
	jsr	_LVOSetDTAttrsA(a6)

	move.l	winpt1,a0
	sub.l	a1,a1
	move.l	dtobject,a2
	move.l	#-1,d0
	jsr	_LVOAddDTObject(a6)
	
debug 	move.l	dtobject,a0
	lea	dtattrs,a2
	jsr	_LVOGetDTAttrsA(a6)
	
	tst.l	bitmapaddr
	beq.b	debug
	
	move.l	bitmapaddr,a0
	move.l	#bitmap,a1
	moveq	#0,d0
	moveq	#0,d1
	moveq	#0,d2
	moveq	#0,d3
	move.w	iffwidth,d4
	move.w	iffheight,d5
	move.l	#$c0,d6
	move.l	#-1,d7
	move.l	gfxbase,a6
	jsr	_LVOBltBitMap(a6)

	move.l	dtbase,a6	
	move.l	dtobject,a0
	move.l	winpt1,a1
	sub.l	a2,a2
	sub.l	a3,a3
	jsr	_LVORefreshDTObjectA(a6)

	move.l	winpt1,a0
	move.l	dtobject,a1
	jsr	_LVORemoveDTObject(a6)
	
	move.l	dtobject,a0
	jsr	_LVODisposeDTObject(a6)
	bsr	closefile
	bra	nomessage1

unknowntype	;lea	menupal,a1
	;move.l	scrpt1,a0
	;lea	sc_ViewPort(a0),a0
	;move.l	#4,d0
	;move.l	gfxbase,a6
	;jsr	_LVOLoadRGB4(a6)
	
	;lea	rawloadwin,a0
	;move.l	intuibase,a6
	;jsr	_LVOOpenWindow(a6)
	;move.l	d0,winpt1
	
	bsr	closefile
	lea	bodyfmt3,a1
	lea	gadfmt3,a2
	lea	taglist,a0
	lea	0,a3
	lea	0,a4
	move.l	reqtbase,a6
	jsr	_LVOrtEZRequestA(a6)
	bra	nomessage1

closefile	tst.l	handle1
	beq	nofileopen
	
	move.l	dosbase,a6
	move.l	handle1,d1
	jsr	_LVOClose(a6)
	clr.l	handle1
	
nofileopen	tst.l	olddirlock
	beq	noolddir
	
	move.l	dosbase,a6
	move.l	olddirlock,d1
	jsr	_LVOCurrentDir(a6)
	
noolddir	tst.l	filelock
	beq	nofilelock
	
	move.l	filelock,d1
	move.l	dosbase,a6
	jsr	_LVOUnLock(a6)
	clr.l	filelock
nofilelock	rts

savepic	clr.b	filename
	tst.l	pladdr
	beq	nomessage1
	
	;move.l	scrpt1,a0
	;sub.l	a1,a1
	;move.l	gadbase,a6
	;jsr	_LVOGetVisualInfoA(a6)
	;move.l	d0,visinfo
	;beq	novisinfo
	;move.l	d0,visinfo2
	
	;move.l	gadbase,a6
	;lea	gads,a0
	;jsr	_LVOCreateContext(a6)
	;tst.l	d0
	;beq	nocontext
	;move.l	d0,a0
	
	;move.l	#MX_KIND,d0
	;lea	picsavegad1,a1
	;lea	gadtags1,a2
	;jsr	_LVOCreateGadgetA(a6)
	;move.l	d0,gadtgad1
	;beq	nogadtgad

	;move.w	pageht,d0
	;sub.w	#200,d0
	;lsr.w	#1,d0
	;move.w	d0,spwiny
	;move.w	pagewid,d0
	;sub.w	#200,d0
	;lsr.w	#1,d0
	;move.w	d0,spwinx

	;move.l	gads,spwingads
	
	;lea	saveprefswin,a0
	;move.l	intuibase,a6
	;jsr	_LVOOpenWindow(a6)
	;move.l	d0,tempwinptr
	
	;move.l	tempwinptr,a0
	;sub.l	a1,a1
	;move.l	gadbase,a6
	;jsr	_LVOGT_RefreshWindow(a6)

	;move.l	intuibase,a6
	;move.l	tempwinptr,a0
	;jsr	_LVOCloseWindow(a6)

nogadtgad
nocontext	;move.l	visinfo,a0
	;move.l	gadbase,a6
	;jsr	_LVOFreeVisualInfo(a6)

novisinfo	tst.b	d0
	bne	iffsave
		
	move.l	req2,a1
	lea	filename,a2
	lea	savetxt,a3
	lea	tags2,a0
	move.l	reqtbase,a6
	jsr	_LVOrtFileRequestA(a6)
	tst.l	d0
	beq	nomessage1
	
	lea	menupal,a1
	move.l	scrpt1,a0
	lea	sc_ViewPort(a0),a0
	move.l	#4,d0
	move.l	gfxbase,a6
	jsr	_LVOLoadRGB4(a6)

	move.l	#srawtitle,windowtitle
	
	lea	newloadwin,a0
	move.l	intuibase,a6
	jsr	_LVOOpenWindow(a6)
	move.l	d0,lswindow
	bsr	drawLSwin
	
	move.l	req2,a1
	move.l	rtfi_Dir(a1),d1
	move.l	#SHARED_LOCK,d2
	move.l	dosbase,a6
	jsr	_LVOLock(a6)
	move.l	d0,filelock
	beq	writeerr
	
	move.l	d0,d1
	jsr	_LVOCurrentDir(a6)
	move.l	d0,olddirlock
	
	move.l	#filename,d1
	move.l	#MODE_NEWFILE,d2
	move.l	dosbase,a6
	jsr	_LVOOpen(a6)
	tst.l	d0
	beq	writeerr
	
	move.l	d0,handle1
	cmp.b	#2,palinfo
	bne	nopalbefore1
	
	bsr	savepalbin
	bne	writeerr

nopalbefore1
	move.l	pladdr,a0
	cmp.b	#1,bplmeth
	beq	savebinil
	
	move.w	iffheight,d1
	mulu	cdepth,d1
	move.w	d1,maxline
nextline3	move.w	d1,lineno
	bsr	updateLSwin

	cmp.b	#1,extrablit
	bne	noblitL1
	
	clr.w	store1
	filewrite	handle1,#store1,#2
	
noblitL1	moveq	#0,d0
	move.w	bytewid1,d0
	
	filewrite	handle1,a0,d0
	
	cmp.b	#2,extrablit
	bne	noblitR1
	
	clr.w	store1
	filewrite	handle1,#store1,#2
	
noblitR1	moveq	#0,d0
	move.w	bytewid1,d0
	lea	0(a0,d0.w),a0
	
	sub.l	#1,d1
	bne	nextline3
	
	cmp.b	#1,palinfo
	bne	nopalafter1
	
	bsr	savepalbin
	bne	writeerr
	
nopalafter1	bsr	closeLSwin
	bsr	closefile
	bra	nomessage1

savebinil	moveq	#0,d1
	move.w	iffheight,d1
nextline4	move.w	d1,lineno
	move.w	iffheight,maxline
	bsr	updateLSwin

	move.w	#1,d2
nextpl1	cmp.w	cdepth,d2
	bgt	noplwrite
	
	cmp.b	#1,extrablit
	bne	noblitL2
	
	clr.w	store1
	filewrite	handle1,#store1,#2
	
noblitL2	moveq	#0,d0
	move.w	bytewid1,d0
	
	filewrite	handle1,a0,d0
	
	cmp.b	#2,extrablit
	bne	noblitR2
	
	clr.w	store1
	filewrite	handle1,#store1,#2

noplwrite
noblitR2	move.w	bytewid1,d0
	mulu	iffheight,d0
	
	lea	0(a0,d0.l),a0
	add.w	#1,d2
	cmp.w	iffdepth,d2
	ble	nextpl1
	
	move.w	bytewid1,d0
	mulu	iffheight,d0
	
	move.l	d1,-(sp)
	moveq	#0,d1
	move.w	iffdepth,d1
	move.l	d2,-(sp)
	moveq	#0,d2
mulu4	add.l	d0,d2
	sub.l	#1,d1
	bne	mulu4
	move.l	d2,d0
	move.l	(sp)+,d2
	;mulu.l	d1,d0	68000 cannot do this
	
	move.l	(sp)+,d1
	
	sub.l	d0,a0
	move.w	bytewid1,d0
	
	lea	0(a0,d0.w),a0
	
	sub.l	#1,d1
	bne	nextline4
	
	cmp.b	#1,palinfo
	bne	nopalafter2
	
	bsr	savepalbin
	bne	writeerr
	
nopalafter2	bsr	closeLSwin
	bsr	closefile
	bsr	fakebpl
	bra	nomessage1

iffsave	move.l	req2,a1
	lea	filename,a2
	lea	savetxt,a3
	lea	tags2,a0
	move.l	reqtbase,a6
	jsr	_LVOrtFileRequestA(a6)
	tst.l	d0
	beq	nomessage1
	
	lea	menupal,a1
	move.l	scrpt1,a0
	lea	sc_ViewPort(a0),a0
	move.l	#4,d0
	move.l	gfxbase,a6
	jsr	_LVOLoadRGB4(a6)
	
	move.l	#swintitle,windowtitle
	lea	newloadwin,a0
	move.l	intuibase,a6
	jsr	_LVOOpenWindow(a6)
	move.l	d0,lswindow
	bsr	drawLSwin
	
	move.l	req2,a1
	move.l	rtfi_Dir(a1),d1
	move.l	#SHARED_LOCK,d2
	move.l	dosbase,a6
	jsr	_LVOLock(a6)
	move.l	d0,filelock
	beq	writeerr
	
	move.l	d0,d1
	jsr	_LVOCurrentDir(a6)
	move.l	d0,olddirlock
	
	move.l	#filename,d1
	move.l	#MODE_NEWFILE,d2
	move.l	dosbase,a6
	jsr	_LVOOpen(a6)
	tst.l	d0
	beq	writeerr
	move.l	d0,handle1
	
	move.l	#'FORM',store1
	filewrite	handle1,#store1,#4
	
	clr.l	store1
	filewrite	handle1,#store1,#4

	moveq	#0,d5
	move.l	#'ILBM',store1
	filewrite	handle1,#store1,#4
	add.l	#4,d5
	
	move.l	#'BMHD',store1
	filewrite	handle1,#store1,#4
	add.l	#4,d5
	
	move.l	#20,store1
	filewrite	handle1,#store1,#4
	add.l	#4,d5
	
	move.w	iffwidth,store1
	filewrite	handle1,#store1,#2
	add.l	#2,d5
	
	move.w	iffheight,store1
	filewrite	handle1,#store1,#2
	add.l	#2,d5
	
	clr.l	store1
	filewrite	handle1,#store1,#4
	add.l	#4,d5
	
	move.w	cdepth,d0
	move.b	d0,store1
	filewrite	handle1,#store1,#1
	add.l	#1,d5
	
	clr.b	store1
	filewrite	handle1,#store1,#1
	add.l	#1,d5
	
	move.b	iffcomp,store1
	filewrite	handle1,#store1,#1
	add.l	#1,d5
	
	clr.b	store1
	filewrite	handle1,#store1,#1
	add.l	#1,d5
	
	clr.w	store1
	filewrite	handle1,#store1,#2
	add.l	#2,d5
	
	filewrite	handle1,#aspects,#2
	add.l	#2,d5
	
	move.w	pagewid,store1
	filewrite	handle1,#store1,#2
	add.l	#2,d5
	
	move.w	pageht,store1
	filewrite	handle1,#store1,#2
	add.l	#2,d5
	
	move.l	#'CMAP',store1
	filewrite	handle1,#store1,#4
	add.l	#4,d5
	
	move.w	#1,d0
	move.w	cdepth,d1
	lsl.w	d1,d0
	mulu	#3,d0
	move.l	d0,d6
	move.l	d0,store1
	
	filewrite	handle1,#store1,#4
	add.l	#4,d5
	
	lea	palstore1,a0
writepal	move.b	(a0)+,store1
	move.b	(a0)+,store1+1
	move.b	(a0)+,store1+2
	
	filewrite	handle1,#store1,#3
	add.l	#3,d5
	
	sub.l	#3,d6
	bne	writepal
	
	btst	#0,d5
	beq	nopad1
	
	clr.b	store1
	filewrite	handle1,#store1,#1
	add.l	#1,d5
	
nopad1	move.l	#'CAMG',store1
	filewrite	handle1,#store1,#4
	add.l	#4,d5
	
	move.l	#4,store1
	filewrite	handle1,#store1,#4
	add.l	#4,d5
	
	move.l	iffcamg,store1
	and.l	#camgmask,store1
	filewrite	handle1,#store1,#4
	add.l	#4,d5
	
	move.l	#'BODY',store1
	filewrite	handle1,#store1,#4
	add.l	#4,d5
	move.l	d5,blenpos
	
	move.w	bytewid1,d0
	mulu	iffheight,d0
	
	move.l	d1,-(sp)
	moveq	#0,d1
	move.w	cdepth,d1
	move.l	d2,-(sp)
	moveq	#0,d2
mulu5	add.l	d0,d2
	sub.l	#1,d1
	bne	mulu5
	move.l	d2,d0
	move.l	(sp)+,d2
	;mulu.l	d1,d0	68000 cannot do this
	
	move.l	(sp)+,d1
	
	move.l	d0,store1
	filewrite	handle1,#store1,#4
	add.l	#4,d5
	
	move.l	pladdr,a0
	moveq	#0,d1
	move.w	iffheight,d1
nextline5	move.w	d1,lineno
	move.w	iffheight,maxline
	bsr	updateLSwin

	move.w	#1,d2
nextplane3	cmp.w	cdepth,d2
	bgt	planesdone
	
	tst.b	iffcomp
	beq	nocomp1
	
	move.l     a0,buffptr2
	move.l     #copybuff,buffptr1
	
	movem.l	d0-d7/a0-a6,-(sp)
	moveq	#0,d0
	move.w	bytewid1,d0
	move.l	d0,-(sp)	;store length
	move.l	#buffptr1,-(sp);store dest
	move.l	#buffptr2,-(sp);store source
	bsr	packrow      
	move.l	d0,store1
	
	lea	12(sp),sp
	movem.l	(sp)+,d0-d7/a0-a6
	add.l	store1,d5
	filewrite	handle1,#copybuff,store1
	bra	planesdone


nocomp1	moveq	#0,d0
	move.w	bytewid1,d0
	filewrite	handle1,a0,d0
	add.l	d0,d5
	
planesdone	move.w	bytewid1,d0
	mulu	iffheight,d0
	
	lea	0(a0,d0.l),a0
	add.w	#1,d2
	
	cmp.w	iffdepth,d2
	ble	nextplane3
	
	move.w	bytewid1,d0
	mulu	iffheight,d0
	
	move.l	d1,-(sp)
	moveq	#0,d1
	move.w	iffdepth,d1
	move.l	d2,-(sp)
	moveq	#0,d2
mulu6	add.l	d0,d2
	sub.l	#1,d1
	bne	mulu6
	move.l	d2,d0
	move.l	(sp)+,d2
	;mulu.l	d1,d0	68000 cannot do this
	
	move.l	(sp)+,d1
	
	sub.l	d0,a0
	
	move.w	bytewid1,d0
	lea	0(a0,d0.w),a0
	
	sub.l	#1,d1
	bne	nextline5
	
	filemove	handle1,#4
	
	move.l	d5,store1
	filewrite	handle1,#store1,#4
	
	tst.b	iffcomp
	beq	nocomp2
	
	filemove	handle1,blenpos
	fileskip	handle1,#8
	
	sub.l	blenpos,d5
	sub.l	#4,d5
	move.l	d5,store1
	filewrite	handle1,#store1,#4

nocomp2	bsr	closeLSwin
	bsr	closefile
	bsr	fakebpl
	bra	nomessage1

savebr	tst.b	d0
	beq	brrawsave
	tst.w	brtlx
	bge	brushset1
	tst.w	brbrx
	bge	brushset1
	tst.w	brtly
	bge	brushset1
	tst.w	brbry
	bge	brushset1
	bra	nomessage1

brushset1	move.w	brtlx,d0
	move.w	brbrx,d1
	cmp.w	d0,d1
	bge	noswap3
	
	exg	d0,d1
	
noswap3	move.w	d0,brtlx
	move.w	d1,brbrx
	move.w	brtly,d0
	move.w	brbry,d1
	cmp.w	d0,d1
	bge	noswap4
	
	exg	d0,d1
	
noswap4	move.w	d0,brtly
	move.w	d1,brbry
	move.w	brtlx,d0
	move.w	brbrx,d1
	sub.w	d1,d0
	
	clr.b	filename
	move.l	req2,a1
	lea	filename,a2
	lea	savetxt,a3
	lea	tags2,a0
	move.l	reqtbase,a6
	jsr	_LVOrtFileRequestA(a6)
	tst.l	d0
	beq	nomessage1
	
	lea	menupal,a1
	move.l	scrpt1,a0
	lea	sc_ViewPort(a0),a0
	move.l	#4,d0
	move.l	gfxbase,a6
	jsr	_LVOLoadRGB4(a6)

	move.l	#swintitle,windowtitle
	lea	newloadwin,a0
	move.l	intuibase,a6
	jsr	_LVOOpenWindow(a6)
	move.l	d0,lswindow
	
	bsr	drawLSwin

	move.l	req2,a1
	move.l	rtfi_Dir(a1),d1
	move.l	#SHARED_LOCK,d2
	move.l	dosbase,a6
	jsr	_LVOLock(a6)
	move.l	d0,filelock
	beq	writeerr
	
	move.l	d0,d1
	jsr	_LVOCurrentDir(a6)
	move.l	d0,olddirlock
	
	move.l	#filename,d1
	move.l	#MODE_NEWFILE,d2
	move.l	dosbase,a6
	jsr	_LVOOpen(a6)
	tst.l	d0
	beq	writeerr
	move.l	d0,handle1
	
	move.l	#'FORM',store1
	filewrite	handle1,#store1,#4
	
	clr.l	store1
	filewrite	handle1,#store1,#4
	
	moveq	#0,d4
	move.l	#'ILBM',store1
	filewrite	handle1,#store1,#4
	add.l	#4,d4
	
	move.l	#'BMHD',store1
	filewrite	handle1,#store1,#4
	add.l	#4,d4
	
	move.l	#20,store1
	filewrite	handle1,#store1,#4
	add.l	#4,d4
	
	move.w	brbrx,d0
	sub.w	brtlx,d0
	tst.b	extrablit
	beq	noxblit
	add.w	#16,d0
noxblit	add.w	#1,d0
	
	move.w	d0,store1
	filewrite	handle1,#store1,#2
	add.l	#2,d4
	
	move.w	brbry,d0
	sub.w	brtly,d0
	add.w	#1,d0
	move.w	d0,store1
	filewrite	handle1,#store1,#2
	add.l	#2,d4
	
	clr.l	store1
	filewrite	handle1,#store1,#4
	add.l	#4,d4
	
	move.w	cdepth,d0
	move.b	d0,store1
	filewrite	handle1,#store1,#1
	add.l	#1,d4
	
	clr.b	store1
	filewrite	handle1,#store1,#1
	add.l	#1,d4
	
	move.b	iffcomp,store1
	filewrite	handle1,#store1,#1
	add.l	#1,d4
	
	clr.b	store1
	filewrite	handle1,#store1,#1
	add.l	#1,d4
	
	clr.w	store1
	filewrite	handle1,#store1,#2
	add.l	#2,d4
	
	filewrite	handle1,#aspects,#2
	add.l	#2,d4
	
	move.w	pagewid,store1
	filewrite	handle1,#store1,#2
	add.l	#2,d4
	
	move.w	pageht,store1
	filewrite	handle1,#store1,#2
	add.l	#2,d4
	
	move.l	#'CMAP',store1
	filewrite	handle1,#store1,#4
	add.l	#4,d4
	
	move.w	#1,d0
	move.w	cdepth,d1
	lsl.w	d1,d0
	mulu	#3,d0
	move.l	d0,d6
	move.l	d0,store1
	filewrite	handle1,#store1,#4
	add.l	#4,d4
	
	lea	palstore1,a0
	
savepal1	move.b	(a0)+,store1
	move.b	(a0)+,store1+1
	move.b	(a0)+,store1+2
	filewrite	handle1,#store1,#3
	add.l	#3,d4
	sub.l	#3,d6
	bne	savepal1
	
	btst	#0,d4
	beq	nopad5
	clr.b	store1
	filewrite	handle1,#store1,#1
	add.l	#1,d4
	
nopad5	move.l	#'CAMG',store1
	filewrite	handle1,#store1,#4
	add.l	#4,d4
	
	move.l	#4,store1
	filewrite	handle1,#store1,#4
	add.l	#4,d4
	
	move.l	iffcamg,store1
	and.l	#camgmask,store1
	filewrite	handle1,#store1,#4
	add.l	#4,d4
	
	move.l	#'BODY',store1
	filewrite	handle1,#store1,#4
	add.l	#4,d4
	move.l	d4,blenpos
	
	move.w	brbrx,d0
	sub.w	brtlx,d0
	add.w	#1,d0
	add.w	#15,d0
	divu	#16,d0
	
	add.w	d0,d0
	
	move.w	brbry,d1
	sub.w	brtly,d1
	add.w	#1,d1
	mulu	d1,d0
	
	move.l	d1,-(sp)
	moveq	#0,d1
	move.w	cdepth,d1
	move.l	d2,-(sp)
	moveq	#0,d2
mulu7	add.l	d0,d2
	sub.l	#1,d1
	bne	mulu7
	move.l	d2,d0
	move.l	(sp)+,d2
	;mulu.l	d1,d0	68000 cannot do this
	
	move.l	(sp)+,d1
	
	move.l	d0,store1
	filewrite	handle1,#store1,#4
	add.l	#4,d4
	
	move.l	pladdr,a0
	lea	copybuff,a1
	move.w	brtly,d5
	move.l	a0,a4
nextline6	move.w	brbry,lineno
	sub.w	d5,lineno
	move.w	brbry,maxline
	
	move.w	brtly,d2
	sub.w	d2,maxline
	bsr	updateLSwin

	move.w	#1,d2
	move.w	d5,d3
	
	mulu	bytewid1,d3
	
	lea	0(a0,d3.l),a0
	
nextplane4	cmp.b	#1,extrablit
	bne	noblitL3
	
	clr.w	(a1)+
	
noblitL3	move.w	brtlx,d1
nextbyte	move.w	#7,d3
	clr.b	(a1)
nextbit	move.w	d1,d6
	move.w	d1,d7
	not.w	d7
	and.w	#7,d7
	and.w	#$FFF8,d6
	lsr.w	#3,d6
	
	btst	d7,0(a0,d6.w)
	beq	bitclear
	
	bset	d3,(a1)
	
bitclear	add.w	#1,d1
	cmp.w	brbrx,d1
	bgt	linedone
	
	sub.w	#1,d3
	bpl	nextbit
	
	add.w	#1,a1
	bra	nextbyte

linedone	add.w	#1,a1
	clr.b	(a1)

	cmp.b	#2,extrablit
	bne	noblitR3
	
	clr.w	(a1)+
noblitR3	
	cmp.w	cdepth,d2
	bgt	noplanes2
	
	sub.l	#copybuff,a1
	move.l	a1,d0
	add.l	#1,d0
	and.l	#$fffffffe,d0
	
	tst.b	iffcomp
	beq	nocomp3
	
	move.l	#copybuff,buffptr2
	move.l	#copybuff2,buffptr1
	
	movem.l	d0-d7/a0-a6,-(sp)
	move.l	d0,-(sp)	;store length
	move.l	#buffptr1,-(sp);store dest
	move.l	#buffptr2,-(sp);store source
	bsr	packrow      
	move.l	d0,store1
	
	lea	12(sp),sp
	movem.l	(sp)+,d0-d7/a0-a6
	add.l	store1,d4
	filewrite	handle1,#copybuff2,store1
	bra	planesdone2
	
nocomp3	filewrite	handle1,#copybuff,d0
	add.l	a1,d4
noplanes2
planesdone2	lea	copybuff,a1
	move.w	iffheight,d0
	mulu	bytewid1,d0
	
	lea	0(a0,d0.l),a0
	
	add.w	#1,d2
	
	cmp.w	iffdepth,d2
	ble	nextplane4
	
	move.l	a4,a0
	add.w	#1,d5
	cmp.w	brbry,d5
	ble	nextline6
	
	filemove	handle1,#4
	
	move.l	d4,store1
	filewrite	handle1,#store1,#4
	
	tst.b	iffcomp
	beq	nocomp4
	
	filemove	handle1,blenpos
	fileskip	handle1,#8
	
	sub.l	blenpos,d4
	sub.l	#4,d4
	move.l	d4,store1
	filewrite	handle1,#store1,#4

nocomp4	bsr	closeLSwin
	bsr	closefile
	bsr	fakebpl
	bra	nomessage1

brrawsave	tst.w	brtlx
	bge	brushset2
	tst.w	brbrx
	bge	brushset2
	tst.w	brtly
	bge	brushset2
	tst.w	brbry
	bge	brushset2
	bra	nomessage1

brushset2	move.w	brtlx,d0
	move.w	brbrx,d1
	cmp.w	d0,d1
	bge	noswap5
	
	exg	d0,d1
	
noswap5	move.w	d0,brtlx
	move.w	d1,brbrx
	move.w	brtly,d0
	move.w	brbry,d1
	cmp.w	d0,d1
	bge	noswap6
	
	exg	d0,d1
	
noswap6	move.w	d0,brtly
	move.w	d1,brbry
	move.w	brtlx,d0
	move.w	brbrx,d1
	sub.w	d1,d0
	
	clr.b	filename
	move.l	req2,a1
	lea	filename,a2
	lea	savetxt,a3
	lea	tags2,a0
	move.l	reqtbase,a6
	jsr	_LVOrtFileRequestA(a6)
	tst.l	d0
	beq	nomessage1
	
	lea	menupal,a1
	move.l	scrpt1,a0
	lea	sc_ViewPort(a0),a0
	move.l	#4,d0
	move.l	gfxbase,a6
	jsr	_LVOLoadRGB4(a6)

	move.l	#srawtitle,windowtitle
	lea	newloadwin,a0
	move.l	intuibase,a6
	jsr	_LVOOpenWindow(a6)
	move.l	d0,lswindow
	bsr	drawLSwin

	move.l	req2,a1
	move.l	rtfi_Dir(a1),d1
	move.l	#SHARED_LOCK,d2
	move.l	dosbase,a6
	jsr	_LVOLock(a6)
	move.l	d0,filelock
	beq	writeerr
	
	move.l	d0,d1
	jsr	_LVOCurrentDir(a6)
	move.l	d0,olddirlock
	
	move.l	#filename,d1
	move.l	#MODE_NEWFILE,d2
	move.l	dosbase,a6
	jsr	_LVOOpen(a6)
	tst.l	d0
	beq	writeerr
	move.l	d0,handle1
	
	cmp.b	#2,palinfo
	bne	nopalbefore2
	
	bsr	savepalbin
	bne	writeerr

nopalbefore2
	tst.b	bplmeth
	bne	brsaverawil
	
	move.l	pladdr,a0
	lea	copybuff,a1
	move.w	#1,d2
	
nextplane5	move.l	a0,a4
	move.w	brtly,d5
nextline7	move.l	d7,-(sp)
	move.w	brbry,d7
	sub.w	brtly,d7
	mulu	iffdepth,d7
	move.w	d7,lineno
	
	move.w	brbry,d7
	sub.w	brtly,d7
	sub.w	#1,d2
	mulu	d2,d7
	add.w	#1,d2
	
	sub.w	brtly,d7
	add.w	d5,d7
	sub.w	d7,lineno
	move.l	(sp)+,d7
	
	move.w	brbry,maxline
	move.w	brtly,d1
	sub.w	d1,maxline
	move.w	maxline,d1
	mulu	iffdepth,d1
	move.w	d1,maxline
	bsr	updateLSwin

	move.w	brtlx,d1
	move.w	d5,d3
	
	mulu	bytewid1,d3
	lea	0(a0,d3.l),a0
nextbyte2	move.w	#7,d3
	clr.b	(a1)
	
nextbit2	move.w	d1,d6
	move.w	d1,d7
	not.w	d7
	and.w	#7,d7
	and.w	#$FFF8,d6
	lsr.w	#3,d6
	btst	d7,0(a0,d6.w)
	beq	bitclear2
	
	bset	d3,(a1)
	
bitclear2	add.w	#1,d1
	cmp.w	brbrx,d1
	bgt	linedone2
	
	sub.w	#1,d3
	bpl	nextbit2
	
	add.w	#1,a1
	bra	nextbyte2

linedone2	add.w	#1,a1
	cmp.w	cdepth,d2
	bgt	noplanes3
	
	cmp.b	#1,extrablit
	bne	noblitL4
	
	clr.w	store1
	filewrite	handle1,#store1,#2
	
noblitL4	clr.b	(a1)
	sub.l	#copybuff,a1
	move.l	a1,d0
	add.l	#1,d0
	and.l	#$fffffffe,d0
	filewrite	handle1,#copybuff,d0
	
	cmp.b	#2,extrablit
	bne	noblitR4
	
	clr.w	store1
	filewrite	handle1,#store1,#2
	
noplanes3
noblitR4	lea	copybuff,a1
	move.l	a4,a0
	add.w	#1,d5
	cmp.w	brbry,d5
	ble	nextline7
	
	move.l	a4,a0
	move.w	iffheight,d0
	mulu	bytewid1,d0
	
	lea	0(a0,d0.l),a0
	
	add.w	#1,d2
	cmp.w	iffdepth,d2
	ble	nextplane5
	
	cmp.b	#1,palinfo
	bne	nopalafter3
	
	bsr	savepalbin
	bne	writeerr
	
nopalafter3	bsr	closeLSwin
	bsr	closefile
	bsr	fakebpl
	bra	nomessage1

brsaverawil	move.l	pladdr,a0
	lea	copybuff,a1
	move.w	brtly,d5
	move.l	a0,a4
	
nextline8	move.w	brbry,lineno
	sub.w	d5,lineno
	move.w	brbry,maxline
	move.w	brtly,d2
	sub.w	d2,maxline
	bsr	updateLSwin

	move.w	#1,d2
	move.w	d5,d3
	mulu	bytewid1,d3
	lea	0(a0,d3.l),a0
	
nextplane6	move.w	brtlx,d1
nextbyte3	move.w	#7,d3
	clr.b	(a1)
	
nextbit3	move.w	d1,d6
	move.w	d1,d7
	not.w	d7
	and.w	#7,d7
	and.w	#$FFF8,d6
	lsr.w	#3,d6
	btst	d7,0(a0,d6.w)
	
	beq	bitclear3
	
	cmp.w	cdepth,d2
	bgt	noplanes4
	
	bset	d3,(a1)
	
noplanes4
bitclear3	add.w	#1,d1
	cmp.w	brbrx,d1
	bgt	linedone3
	
	sub.w	#1,d3
	bpl	nextbit3
	
	add.w	#1,a1
	bra	nextbyte3

linedone3	add.w	#1,a1
	cmp.b	#1,extrablit
	bne	noblitL5
	
	clr.w	store1
	filewrite	handle1,#store1,#2
	
noblitL5	clr.b	(a1)
	sub.l	#copybuff,a1
	move.l	a1,d0
	add.l	#1,d0
	and.l	#$fffffffe,d0
	filewrite	handle1,#copybuff,d0
	
	cmp.b	#2,extrablit
	bne	noblitR5
	
	clr.w	store1
	filewrite	handle1,#store1,#2
	
noblitR5	lea	copybuff,a1
	move.w	iffheight,d0
	mulu	bytewid1,d0
	
	lea	0(a0,d0.l),a0
	
	add.w	#1,d2
	
	cmp.w	cdepth,d2
	ble	nextplane6
	
	move.l	a4,a0
	add.w	#1,d5
	
	cmp.w	brbry,d5
	ble	nextline8
	
	cmp.b	#1,palinfo
	bne	nopalafter4
	
	bsr	savepalbin
	bne	writeerr
	
nopalafter4	bsr	closeLSwin
	bsr	closefile
	bsr	fakebpl
	bra	nomessage1

savesprite	cmp.b	#0,d0
	bne	notwid16
	
	move.l	#16,d1
	
notwid16	cmp.b	#1,d0
	bne	notwid32
	
	move.l	#32,d1
	
notwid32	cmp.b	#2,d0
	bne	notwid64
	
	move.l	#64,d1
	
notwid64	move.l	d1,sprwid

	tst.w	brtlx
	bge	brushset3
	tst.w	brbrx
	bge	brushset3
	tst.w	brtly
	bge	brushset3
	tst.w	brbry
	bge	brushset3
	bra	nomessage1

brushset3	move.w	brtlx,d0
	move.w	brbrx,d1
	cmp.w	d0,d1
	bge	noswap7
	
	exg	d0,d1
	
noswap7	move.w	d0,brtlx
	move.w	d1,brbrx
	move.w	brtly,d0
	move.w	brbry,d1
	cmp.w	d0,d1
	bge	noswap8
	
	exg	d0,d1
	
noswap8	move.w	d0,brtly
	move.w	d1,brbry
	
	clr.b	filename
	move.l	req2,a1
	lea	filename,a2
	lea	savetxt,a3
	lea	tags2,a0
	move.l	reqtbase,a6
	jsr	_LVOrtFileRequestA(a6)
	tst.l	d0
	beq	nomessage1
	
	move.l	req2,a1
	move.l	rtfi_Dir(a1),d1
	move.l	#SHARED_LOCK,d2
	move.l	dosbase,a6
	jsr	_LVOLock(a6)
	move.l	d0,filelock
	beq	writeerr
	
	move.l	d0,d1
	jsr	_LVOCurrentDir(a6)
	move.l	d0,olddirlock
	
	move.l	#filename,d1
	move.l	#MODE_NEWFILE,d2
	move.l	dosbase,a6
	jsr	_LVOOpen(a6)
	tst.l	d0
	beq	writeerr
	move.l	d0,handle1
	
	tst.b	sprctrl
	beq	noctrl
	
	tst.b	sprmeth
	bne	sprbinctrl
	
	cmp.l	#16,sprwid
	bne	sprwid32
	
	move.b	#'1',spr16ctrl+3
	filewrite	handle1,#spr16ctrl,#end16save-spr16ctrl
	bra	noctrl

sprwid32	cmp.l	#32,sprwid
	bne	sprwid64
	
	move.b	#'1',spr32ctrl+3
	filewrite	handle1,#spr32ctrl,#end32save-spr32ctrl
	bra	noctrl

sprwid64	move.b	#'1',spr64ctrl+3
	filewrite	handle1,#spr64ctrl,#end64save-spr64ctrl
	bra	noctrl

sprbinctrl	move.l	sprwid,d6
	divu	#8,d6
	and.l	#$FFFF,d6
	add.w	d6,d6
	clr.l	copybuff
	clr.l	copybuff+4
	
	filewrite	handle1,#copybuff,d6
	
noctrl	move.l	pladdr,a0
	lea	copybuff,a1
	move.w	brtly,d5
	move.l	a0,a4
	
nextline9	move.w	#1,d2
	move.w	d5,d3
	mulu	bytewid1,d3
	
	lea	0(a0,d3.l),a0
	
	clr.l	copybuff
	clr.l	copybuff+4
	clr.l	copybuff+8
	clr.l	copybuff+12
	
nextplane7	move.w	brtlx,d1

	cmp.w	cdepth,d2
	bgt	planeblank
	
nextbyte1	move.w	#7,d3
	clr.b	(a1)
	
nextbit1	move.w	d1,d6
	move.w	d1,d7
	not.w	d7
	and.w	#7,d7
	and.w	#$FFF8,d6
	lsr.w	#3,d6
	btst	d7,0(a0,d6.w)
	beq	bitclear1
	
	bset	d3,(a1)
	
bitclear1	add.w	#1,d1
	move.w	brtlx,d4
	add.l	sprwid,d4
	cmp.w	d4,d1
	bge	linedone4
	
	cmp.w	brbrx,d1
	bgt	linedone4
	
	sub.w	#1,d3
	bpl	nextbit1
	
	add.w	#1,a1
	bra	nextbyte1

linedone4	add.w	#1,a1
planeblank	move.w	iffheight,d0
	mulu	bytewid1,d0
	lea	0(a0,d0.l),a0
	
	add.w	#1,d2
	cmp.w	#3,d2
	bne	nextplane7
	
	tst.b	sprmeth
	bne	sprsavebin
	
	cmp.l	#16,sprwid
	beq	sprwid16a
	
	cmp.l	#32,sprwid
	beq	sprwid32a
	
	move.w	copybuff+14,d0
	move.w	#4,d1
	lea	sprtxt10,a0
	bsr	numtohexasc
	
	move.w	copybuff+12,d0
	move.w	#4,d1
	lea	sprtxt9,a0
	bsr	numtohexasc
	
	move.w	copybuff+10,d0
	move.w	#4,d1
	lea	sprtxt8,a0
	bsr	numtohexasc
	
	move.w	copybuff+8,d0
	move.w	#4,d1
	lea	sprtxt7,a0
	bsr	numtohexasc
	
sprwid32a	move.w	copybuff+6,d0
	move.w	#4,d1
	lea	sprtxt6,a0
	bsr	numtohexasc
	
	move.w	copybuff+4,d0
	move.w	#4,d1
	lea	sprtxt5,a0
	bsr	numtohexasc
	
sprwid16a	move.w	copybuff+2,d0
	move.w	#4,d1
	lea	sprtxt4,a0
	bsr	numtohexasc
	
	move.w	copybuff,d0
	move.w	#4,d1
	lea	sprtxt3,a0
	bsr	numtohexasc
	
	lea	sprtxt2,a0
	
	move.l	sprwid,d0
	divu	#$10,d0
	mulu	#12,d0
	lea	0(a0,d0.l),a0
	
	move.b	(a0),d6
	move.b	#10,(a0)+
	
	move.l	a0,a2
	sub.l	#sprtxt1,a2
	
	filewrite	handle1,#sprtxt1,a2
	
	move.b	d6,-(a0)
	bra	writeline


sprsavebin	move.l	sprwid,d6
	divu	#8,d6
	and.l	#$FFFF,d6
	add.w	d6,d6
	
	filewrite	handle1,#copybuff,d6
	
writeline	lea	copybuff,a1
	move.l	a4,a0
	add.w	#1,d5
	cmp.w	brbry,d5
	ble	nextline9

	tst.b	sprctrl
	beq	noendctrl
	
	tst.b	sprmeth
	bne	writebin
	
	cmp.l	#16,sprwid
	bne	notwid16a
	
	filewrite	handle1,#sprsaveA,#end16save-sprsaveA
	bra	noendctrl

notwid16a	cmp.l	#32,sprwid
	bne	notwid32a
	
	filewrite	handle1,#sprsaveB,#end32save-sprsaveB
	bra	noendctrl

notwid32a	filewrite	handle1,#sprsaveC,#end64save-sprsaveC
	bra	noendctrl

writebin	move.l	sprwid,d6
	divu	#8,d6
	and.l	#$FFFF,d6
	add.w	d6,d6
	clr.l	copybuff
	clr.l	copybuff+4
	
	filewrite	handle1,#copybuff,d6

noendctrl	tst.b	sprdepth
	beq	no4plspr
	
	tst.b	sprctrl
	beq	noctrl2
	
	tst.b	sprmeth
	bne	savectrlbin
	
	cmp.l	#16,sprwid
	bne	notwid16b
	
	move.b	#'2',spr16ctrl+3
	filewrite	handle1,#spr16ctrl,#end16save-spr16ctrl
	bra	noctrl2

notwid16b	cmp.l	#32,sprwid
	bne	notwid32b
	
	move.b	#'2',spr32ctrl+3
	filewrite	handle1,#spr32ctrl,#end32save-spr32ctrl
	bra	noctrl2

notwid32b	move.b	#'2',spr64ctrl+3
	filewrite	handle1,#spr64ctrl,#end64save-spr64ctrl
	bra	noctrl2

savectrlbin	move.l	sprwid,d6
	divu	#8,d6
	and.l	#$FFFF,d6
	add.w	d6,d6
	clr.l	copybuff
	clr.l	copybuff+4
	
	filewrite	handle1,#copybuff,d6
	
noctrl2	move.l	pladdr,a0
	move.w	bytewid1,d6
	mulu	iffheight,d6
	add.l	d6,a0
	add.l	d6,a0
	lea	copybuff,a1
	move.w	brtly,d5
	move.l	a0,a4

nextline10	move.w	#3,d2
	move.w	d5,d3
	mulu	bytewid1,d3
	lea	0(a0,d3.l),a0

	clr.l	copybuff
	clr.l	copybuff+4
	clr.l	copybuff+8
	clr.l	copybuff+12

nextplane8	move.w	brtlx,d1
	cmp.w	cdepth,d2
	bgt	planeblank2

nextbyte4	move.w	#7,d3
	clr.b	(a1)

nextbit4	move.w	d1,d6
	move.w	d1,d7
	not.w	d7
	and.w	#7,d7
	and.w	#$FFF8,d6
	lsr.w	#3,d6

	btst	d7,0(a0,d6.w)
	beq	bitclear4

	bset	d3,(a1)

bitclear4	add.w	#1,d1
	move.w	brtlx,d4
	add.l	sprwid,d4
	cmp.w	d4,d1
	bge	linedone5

	cmp.w	brbrx,d1
	bgt	linedone5

	sub.w	#1,d3
	bpl	nextbit4

	add.w	#1,a1
	bra	nextbyte4

linedone5	add.w	#1,a1

planeblank2	move.w	iffheight,d0
	mulu	bytewid1,d0
	lea	0(a0,d0.l),a0
	
	sub.w	#1,d2
	bne	nextplane8

	tst.b	sprmeth
	bne	binsave

	cmp.l	#16,sprwid
	beq	sprwid16c
	
	cmp.l	#32,sprwid
	beq	sprwid32c
	
	move.w	copybuff+14,d0
	move.w	#4,d1
	lea	sprtxt10,a0
	bsr	numtohexasc
	
	move.w	copybuff+12,d0
	move.w	#4,d1
	lea	sprtxt9,a0
	bsr	numtohexasc
	
	move.w	copybuff+10,d0
	move.w	#4,d1
	lea	sprtxt8,a0
	bsr	numtohexasc
	
	move.w	copybuff+8,d0
	move.w	#4,d1
	lea	sprtxt7,a0
	bsr	numtohexasc
	
sprwid32c	move.w	copybuff+6,d0
	move.w	#4,d1
	lea	sprtxt6,a0
	bsr	numtohexasc
	
	move.w	copybuff+4,d0
	move.w	#4,d1
	lea	sprtxt5,a0
	bsr	numtohexasc
	
sprwid16c	move.w	copybuff+2,d0
	move.w	#4,d1
	lea	sprtxt4,a0
	bsr	numtohexasc
	
	move.w	copybuff,d0
	move.w	#4,d1
	lea	sprtxt3,a0
	bsr	numtohexasc
	
	lea	sprtxt2,a0
	move.l	sprwid,d0
	divu	#$10,d0
	mulu	#12,d0
	lea	0(a0,d0.l),a0
	move.b	(a0),d6
	move.b	#10,(a0)+
	move.l	a0,a2
	sub.l	#sprtxt1,a2
	
	filewrite	handle1,#sprtxt1,a2
	move.b	d6,-(a0)
	bra	linewrote

binsave	move.l	sprwid,d6
	divu	#8,d6
	and.l	#$FFFF,d6
	add.w	d6,d6
	
	filewrite	handle1,#copybuff,d6
	
linewrote	lea	copybuff,a1
	move.l	a4,a0
	add.w	#1,d5
	cmp.w	brbry,d5
	ble	nextline10
	
	tst.b	sprctrl
	beq	noctrlend2
	
	tst.b	sprmeth
	bne	sprbinsave2
	
	cmp.l	#16,sprwid
	bne	notwid16c
	
	filewrite	handle1,#sprsaveA,#end16save-sprsaveA
	bra	no4plspr

notwid16c	cmp.l	#32,sprwid
	bne	notwid32c
	
	filewrite	handle1,#sprsaveB,#end32save-sprsaveB
	bra	no4plspr

notwid32c	filewrite	handle1,#sprsaveC,#end64save-sprsaveC
	bra	no4plspr

sprbinsave2	move.l	sprwid,d6
	divu	#8,d6
	and.l	#$FFFF,d6
	add.w	d6,d6
	clr.l	copybuff
	clr.l	copybuff+4
	
	filewrite	handle1,#copybuff,d6

noctrlend2
no4plspr	bsr	closefile
	bra	nomessage1

savepalbin	tst.b	paltype
	beq	pal12bit
	
	move.w	#1,d0
	move.w	cdepth,d1
	lsl.w	d1,d0
	mulu	#3,d0
	move.l	handle1,d1
	move.l	#palstore1,d2
	move.l	d0,d3
	move.l	d3,d7
	jsr	_LVOWrite(a6)
	cmp.l	d7,d0
	rts

pal12bit	move.w	#1,d6
	move.w	cdepth,d5
	lsl.w	d5,d6
	sub.w	#1,d6
	lea	palstore1,a5
	
save12pal	clr.w	d2
	move.b	(a5)+,d2
	and.b	#$F0,d2
	lsl.w	#4,d2
	or.b	(a5)+,d2
	and.w	#$FF0,d2
	lsl.w	#4,d2
	or.b	(a5)+,d2
	and.w	#$FFF0,d2
	lsr.w	#4,d2
	move.w	d2,store1
	
	move.l	handle1,d1
	move.l	#store1,d2
	move.l	#2,d3
	jsr	_LVOWrite(a6)
	cmp.l	#2,d0
	bne	palsaveerr
	
	dbf	d6,save12pal
	
	moveq	#0,d0
	rts

palsaveerr	move.l	#-1,d0
	rts

palsavesrc	tst.b	paltype
	beq	pal12bit2
	
	move.w	#1,d6
	move.w	cdepth,d5
	lsl.w	d5,d6
	sub.w	#1,d6
	lea	palstore1,a5
	
palwrite	lea	pal24mod1,a0
	move.b	(a5)+,d0
	move.w	#2,d1
	bsr	numtohexasc
	
	lea	pal24mod2,a0
	move.b	(a5)+,d0
	move.w	#2,d1
	bsr	numtohexasc
	
	lea	pal24mod3,a0
	move.b	(a5)+,d0
	move.w	#2,d1
	bsr	numtohexasc
	
	move.l	handle1,d1
	move.l	#pal24src,d2
	move.l	#endpal24-pal24src,d3
	jsr	_LVOWrite(a6)
	cmp.l	#endpal24-pal24src,d0
	bne	palsaveerr
	
	dbf	d6,palwrite
	
	moveq	#0,d0
	rts

pal12bit2	move.w	#1,d6
	move.w	cdepth,d5
	lsl.w	d5,d6
	sub.w	#1,d6
	lea	palstore1,a5
	
palwrite2	clr.w	d2
	move.b	(a5)+,d2
	and.b	#$F0,d2
	lsl.w	#4,d2
	or.b	(a5)+,d2
	and.w	#$FF0,d2
	lsl.w	#4,d2
	or.b	(a5)+,d2
	and.w	#$FFF0,d2
	lsr.w	#4,d2
	
	move.w	d2,d0
	move.w	#4,d1
	lea	pal12mod1,a0
	bsr	numtohexasc
	
	move.l	handle1,d1
	move.l	#pal12src,d2
	move.l	#endpal12-pal12src,d3
	jsr	_LVOWrite(a6)
	cmp.l	#endpal12-pal12src,d0
	bne	palsaveerr
	
	dbf	d6,palwrite2
	moveq	#0,d0
	rts

palsavecop	move.l	#1,d4
	move.w	cdepth,d1
	lsl.l	d1,d4
	move.w	#$180,d7
	clr.w	d6
	clr.w	d5
	lea	palstore1,a5
	
palwrite3	lea	copmod2,a0
	move.w	d5,d0
	move.w	#4,d1
	bsr	numtohexasc
	
	lea	copmod1,a0
	move.w	#3,d1
	move.w	#$106,d0
	bsr	numtohexasc
	
	move.l	handle1,d1
	move.l	#copsrc1,d2
	move.l	#endcop1-copsrc1,d3
	jsr	_LVOWrite(a6)
	cmp.l	#endcop1-copsrc1,d0
	bne	writeerr
	
palwrite4	clr.w	d0
	move.b	(a5)+,d0
	and.b	#$F0,d0
	lsl.w	#4,d0
	or.b	(a5)+,d0
	and.b	#$F0,d0
	lsl.w	#4,d0
	or.b	(a5)+,d0
	
	lsr.w	#4,d0
	lea	copmod2,a0
	move.w	#4,d1
	bsr	numtohexasc
	
	lea	copmod1,a0
	move.w	#3,d1
	move.w	d7,d0
	bsr	numtohexasc
	
	move.l	handle1,d1
	move.l	#copsrc1,d2
	move.l	#endcop1-copsrc1,d3
	jsr	_LVOWrite(a6)
	cmp.l	#endcop1-copsrc1,d0
	bne	writeerr
	
	add.w	#2,d7
	add.w	#1,d6
	sub.w	#1,d4
	beq	palwrote
	
	and.w	#$1F,d6
	bne	palwrite4
	
	move.w	#$180,d7
	clr.w	d6
	add.w	#$2000,d5
	bra	palwrite3

palwrote	tst.b	paltype
	beq	palsaved
	
	move.l	#1,d4
	move.w	cdepth,d1
	lsl.l	d1,d4
	move.w	#$180,d7
	move.w	#$200,d5
	clr.w	d6
	lea	palstore1,a5
	
palwrite5	lea	copmod2,a0
	move.w	d5,d0
	move.w	#4,d1
	bsr	numtohexasc
	
	lea	copmod1,a0
	move.w	#3,d1
	move.w	#$106,d0
	bsr	numtohexasc
	
	move.l	handle1,d1
	move.l	#copsrc1,d2
	move.l	#endcop1-copsrc1,d3
	jsr	_LVOWrite(a6)
	cmp.l	#endcop1-copsrc1,d0
	bne	writeerr
	
palwrite6	clr.w	d0
	move.b	(a5)+,d0
	and.b	#15,d0
	lsl.w	#8,d0
	or.b	(a5)+,d0
	and.b	#15,d0
	lsl.b	#4,d0
	lsl.w	#4,d0
	or.b	(a5)+,d0
	lsl.b	#4,d0
	lsr.w	#4,d0
	
	lea	copmod2,a0
	move.w	#4,d1
	bsr	numtohexasc
	
	lea	copmod1,a0
	move.w	#3,d1
	move.w	d7,d0
	bsr	numtohexasc
	
	move.l	handle1,d1
	move.l	#copsrc1,d2
	move.l	#endcop1-copsrc1,d3
	jsr	_LVOWrite(a6)
	cmp.l	#endcop1-copsrc1,d0
	bne	writeerr
	
	add.w	#2,d7
	add.w	#1,d6
	sub.w	#1,d4
	beq	palsaved
	
	and.w	#$1F,d6
	bne	palwrite6
	
	move.w	#$180,d7
	clr.w	d6
	add.w	#$2000,d5
	bra	palwrite5

palsaved	bsr	closefile
	rts

writeerr	bsr	closeLSwin
	bsr	closefile

	lea	bodyfmt6,a1
	lea	gadfmt6,a2
	lea	taglist,a0
	lea	0,a3
	lea	0,a4
	move.l	reqtbase,a6
	jsr	_LVOrtEZRequestA(a6)
	bsr	fakebpl
	bra	nomessage1


prefs	move.l	intuibase,a6
	jsr	_LVOWBenchToFront(a6)
	
	lea	newprefswin,a0
	jsr	_LVOOpenWindow(a6)
	move.l	d0,prefswin
	beq	noprefswin
	
	moveq	#0,d0
	bsr	settxt
	
	lea	newprefs,a0
	lea	oldprefs,a1
	move.w	#endnewprefs-newprefs-1,d0
storeprefs	move.b	(a0)+,(a1)+
	dbf	d0,storeprefs
	
nomessage2	move.l	#1,d1
	move.l	dosbase,a6
	jsr	_LVODelay(a6)
	
	move.l	prefswin,a0
	move.l	wd_UserPort(a0),a0
	move.l	4.w,a6
	jsr	_LVOGetMsg(a6)
	tst.l	d0
	beq	nomessage2
	
	move.l	d0,message
	move.l	d0,a1
	jsr	_LVOReplyMsg(a6)
	
	move.l	message,a0
	move.l	$14(a0),d0
	cmp.l	#CLOSEWINDOW,d0
	beq	prefsclose
	
	cmp.l	#GADGETUP,d0
	bne	nomessage2
	
	move.l	$1C(a0),a1

	lea	prefstable,a0
findrout	cmp.l	(a0)+,a1
	beq	foundrout
	add.l	#4,a0
	tst.l	(a0)
	bne	findrout
	bra	nomessage2

foundrout	move.l	(a0)+,a0
	jsr	(a0)
	bra	nomessage2

prefsclose	move.l	scrpt1,a0
	move.l	intuibase,a6
	jsr	_LVOScreenToFront(a6)
	
	move.l	prefswin,a0
	jsr	_LVOCloseWindow(a6)
	bra	nomessage1

prefsbplmeth
	add.b	#1,bplmeth
	and.b	#1,bplmeth
	move.l	#1,d0
	bsr	settxt
	rts

prefspalinfo
	add.b	#1,palinfo
	cmp.b	#3,palinfo
	blt	noloop1
	clr.b	palinfo
noloop1	move.l	#2,d0
	bsr	settxt
	rts

prefspaltype
	add.b	#1,paltype
	and.b	#1,paltype
	move.l	#3,d0
	bsr	settxt
	rts

prefspalmeth
	add.b	#1,palmeth
	cmp.b	#3,palmeth
	blt	noloop2
	clr.b	palmeth
noloop2	move.l	#4,d0
	bsr	settxt
	rts

prefssprmeth
	add.b	#1,sprmeth
	and.b	#1,sprmeth
	move.l	#5,d0
	bsr	settxt
	rts

prefssprctrl
	add.b	#1,sprctrl
	and.b	#1,sprctrl
	move.l	#6,d0
	bsr	settxt
	rts

prefssprdepth
	add.b	#1,sprdepth
	and.b	#1,sprdepth
	move.l	#7,d0
	bsr	settxt
	rts

prefsextrablit
	add.b	#1,extrablit
	cmp.b	#3,extrablit
	blt	noloop3
	clr.b	extrablit
noloop3	move.l	#8,d0
	bsr	settxt
	rts

prefscomp	add.b	#1,iffcomp
	and.b	#1,iffcomp
	move.l	#9,d0
	bsr	settxt
	rts

undoprefs	lea	oldprefs,a0
	lea	newprefs,a1
	move.w	#endnewprefs-newprefs-1,d0
undoloop	move.b	(a0)+,(a1)+
	dbf	d0,undoloop
	moveq	#0,d0
	bsr	settxt
prefsquit	move.l	(sp)+,d0
	bra	prefsclose

prefssave	move.l	req1,a0
	move.l	rtfi_Dir(a0),a0
	
	lea	loaddir,a1
	move.w	#256-1,d0
copy1	move.b	(a0)+,(a1)+
	dbf	d0,copy1
	
	move.l	req2,a0
	move.l	rtfi_Dir(a0),a0
	
	lea	savedir,a1
	move.w	#256-1,d0
copy2	move.b	(a0)+,(a1)+
	dbf	d0,copy2
	
	move.l	#prefsname,d1
	move.l	#MODE_NEWFILE,d2
	move.l	dosbase,a6
	jsr	_LVOOpen(a6)
	tst.l	d0
	beq	noprefssave
	
	move.l	d0,d1
	move.l	d0,d6
	move.l	#newprefs,d2
	move.l	#endnewprefs-newprefs,d3
	jsr	_LVOWrite(a6)
	
	move.l	d0,d5
	move.l	d6,d1
	jsr	_LVOClose(a6)
	
	cmp.l	#endnewprefs-newprefs,d5
	bne	noprefssave
	
	move.l	(sp)+,d0
	bra	prefsclose

noprefssave	lea	bodyfmt8,a1
	lea	gadfmt8,a2
	lea	taglist,a0
	lea	0,a3
	lea	0,a4
	move.l	reqtbase,a6
	jsr	_LVOrtEZRequestA(a6)
	move.l	(sp)+,d0
	bra	prefsclose

settxt	move.l	d0,-(sp)
	lea	savemethtxt,a0
	move.b	bplmeth,d0
	ext.w	d0
	lsl.w	#2,d0
	move.l	0(a0,d0.w),a0
	lea	ptxt1a,a1
	rept	11
	move.b	(a0)+,(a1)+
	endr
	
	lea	palinfotxt,a0
	move.b	palinfo,d0
	ext.w	d0
	lsl.w	#2,d0
	move.l	0(a0,d0.w),a0
	lea	ptxt2a,a1

	rept	6
	move.b	(a0)+,(a1)+
	endr
	
	lea	paltypetxt,a0
	move.b	paltype,d0
	ext.w	d0
	lsl.w	#2,d0
	move.l	0(a0,d0.w),a0
	lea	ptxt3a,a1
	
	rept	6
	move.b	(a0)+,(a1)+
	endr
	
	lea	palmethtxt,a0
	move.b	palmeth,d0
	ext.w	d0
	lsl.w	#2,d0
	move.l	0(a0,d0.w),a0
	lea	ptxt4a,a1
	
	rept	13
	move.b	(a0)+,(a1)+
	endr
	
	lea	sprmethtxt,a0
	move.b	sprmeth,d0
	ext.w	d0
	lsl.w	#2,d0
	move.l	0(a0,d0.w),a0
	lea	ptxt5a,a1
	
	rept	6
	move.b	(a0)+,(a1)+
	endr
	
	lea	sprctrltxt,a0
	move.b	sprctrl,d0
	ext.w	d0
	lsl.w	#2,d0
	move.l	0(a0,d0.w),a0
	lea	ptxt6a,a1
	
	rept	3
	move.b	(a0)+,(a1)+
	endr
	
	lea	sprdeptxt,a0
	move.b	sprdepth,d0
	ext.w	d0
	lsl.w	#2,d0
	move.l	0(a0,d0.w),a0
	lea	ptxt7a,a1
	
	rept	10
	move.b	(a0)+,(a1)+
	endr
	
	lea	xtrablittxt,a0
	move.b	extrablit,d0
	ext.w	d0
	lsl.w	#2,d0
	move.l	0(a0,d0.w),a0
	lea	ptxt8a,a1
	
	rept	5
	move.b	(a0)+,(a1)+
	endr
	
	lea	iffcomptxt,a0
	move.b	iffcomp,d0
	ext.w	d0
	lsl.w	#2,d0
	move.l	0(a0,d0.w),a0
	lea	ptxt9a,a1
	
	rept	10
	move.b	(a0)+,(a1)+
	endr
	
	move.l	(sp)+,d0
	bne	updategad
	
	move.l	gfxbase,a6
	move.l	scrpt1,a0
	lea	sc_ViewPort(a0),a0
	jsr	_LVOWaitBOVP(a6)
	move.l	intuibase,a6
	lea	prefsgad1,a0
	move.l	prefswin,a1
	sub.l	a2,a2
	jsr	_LVORefreshGadgets(a6)
	rts

updategad	lea	prefsgad1,a0
findpgad	sub.l	#1,d0
	beq	pgadfound
	move.l	(a0),a0
	bra	findpgad

pgadfound	move.l	a0,-(sp)
	move.l	gfxbase,a6
	move.l	scrpt1,a0
	lea	sc_ViewPort(a0),a0
	jsr	_LVOWaitBOVP(a6)
	
	move.l	(sp)+,a0
	
	move.l	intuibase,a6
	move.l	prefswin,a1
	sub.l	a2,a2
	move.l	#1,d0
	jsr	_LVORefreshGList(a6)
	rts

noprefswin	lea	bodyfmt7,a1
	lea	gadfmt7,a2
	lea	taglist,a0
	lea	0,a3
	lea	0,a4
	move.l	reqtbase,a6
	jsr	_LVOrtEZRequestA(a6)
	bra	nomessage1

about	lea	menupal,a1
	move.l	scrpt1,a0
	lea	sc_ViewPort(a0),a0
	move.l	#4,d0
	move.l	gfxbase,a6
	jsr	_LVOLoadRGB4(a6)
	
	lea	bodyfmt1,a1
	lea	gadfmt1,a2
	lea	taglist,a0
	lea	0,a3
	lea	0,a4
	move.l	reqtbase,a6
	jsr	_LVOrtEZRequestA(a6)
	
	bsr	fakebpl
	bra	nomessage1

initbrush	tst.w	brtlx
	bge	brushset4
	tst.w	brtly
	bge	brushset4
	tst.w	brbrx
	bge	brushset4
	tst.w	brbry
	bge	brushset4
	rts

brushset4	bsr	drawbrushgrid
	move.w	#$FFFF,brtlx
	move.w	#$FFFF,brtly
	move.w	#$FFFF,brbrx
	move.w	#$FFFF,brbry
	sf	brushon
	bsr	updatecoords
	rts

brush	bsr	initbrush
	bra	nomessage1

setpalette	lea	taglist2,a0
	lea	palreqtxt,a2
	sub.l	a3,a3
	move.l	reqtbase,a6
	jsr	_LVOrtPaletteRequestA(a6)
	
	tst.l	gfx39base
	beq	nogfx39c
	move.l	scrpt1,a0
	lea	sc_ViewPort(a0),a0
	move.l	vp_ColorMap(a0),a0	;get color map address
	moveq	#0,d0		;first color
	move.l	#1,d1
	move.w	iffdepth,d2
	lsl.l	d2,d1
	lea	palstore2,a1
	move.l	gfx39base,a6
	jsr	_LVOGetRGB32(a6)
	bra	gotpalette

nogfx39c	move.l	gfxbase,a6
	moveq	#0,d5
	move.l	#1,d6
	move.w	iffdepth,d7
	lsl.l	d7,d6
	sub.l	#1,d6
	lea	palstore2,a5
	
getpalette	move.l	scrpt1,a0
	lea	sc_ViewPort(a0),a0
	move.l	vp_ColorMap(a0),a0	;get color map address
	move.l	d5,d0
	jsr	_LVOGetRGB4(a6)
	move.w	d0,d1

	and.l	#$f00,d1
	lsl.w	#4,d1
	move.w	d1,d2
	rept	3
	lsr.w	#4,d2
	or.w	d2,d1
	endr
	move.w	d1,d2
	swap	d2
	clr.w	d2
	or.l	d2,d1
	move.l	d1,(a5)+

	move.w	d0,d1
	and.l	#$0f0,d1
	lsl.w	#8,d1
	move.w	d1,d2
	rept	3
	lsr.w	#4,d2
	or.w	d2,d1
	endr
	move.w	d1,d2
	swap	d2
	clr.w	d2
	or.l	d2,d1
	move.l	d1,(a5)+

	move.w	d0,d1
	and.l	#$00f,d1
	ror.w	#4,d1
	move.w	d1,d2
	rept	3
	lsr.w	#4,d2
	or.w	d2,d1
	endr
	move.w	d1,d2
	swap	d2
	clr.w	d2
	or.l	d2,d1
	move.l	d1,(a5)+
	
	add.l	#1,d5
	dbf	d6,getpalette

gotpalette	lea	palstore2,a0
	lea	palstore1,a1
	move.l	#1,d0
	move.w	iffdepth,d1
	lsl.l	d1,d0
	mulu	#3,d0
	sub.l	#1,d0
	
remakepal1	move.l	(a0)+,d2
	swap	d2
	lsr.w	#8,d2
	move.b	d2,(a1)+
	dbf	d0,remakepal1

	bsr	fakebpl	
	rts

palette	bsr	setpalette
	bra	nomessage1

savepal	clr.b	filename
	move.l	req2,a1
	lea	filename,a2
	lea	savpaltxt,a3
	lea	tags2,a0
	move.l	reqtbase,a6
	jsr	_LVOrtFileRequestA(a6)
	tst.l	d0
	beq	nomessage1
	
	move.l	req2,a1
	move.l	rtfi_Dir(a1),d1
	move.l	#SHARED_LOCK,d2
	move.l	dosbase,a6
	jsr	_LVOLock(a6)
	move.l	d0,filelock
	beq	writeerr
	
	move.l	d0,d1
	jsr	_LVOCurrentDir(a6)
	move.l	d0,olddirlock
	
	move.l	#filename,d1
	move.l	#MODE_NEWFILE,d2
	move.l	dosbase,a6
	jsr	_LVOOpen(a6)
	move.l	d0,handle1
	tst.l	d0
	beq	writeerr
	move.l	d0,handle1
	
	tst.b	palmeth
	bne	notsrcsave
	
	bsr	palsavesrc
	bne	writeerr
	
	bra	palsaved2

notsrcsave	cmp.b	#1,palmeth
	bne	notcopsave
	
	bsr	palsavecop
	bne	writeerr
	
	bra	palsaved2

notcopsave	bsr	savepalbin
	bne	writeerr
	
palsaved2	bsr	closefile
	bra	nomessage1


savepicmask	clr.b	filename
	move.l	req2,a1
	lea	filename,a2
	lea	savmasktxt,a3
	lea	tags2,a0
	move.l	reqtbase,a6
	jsr	_LVOrtFileRequestA(a6)
	tst.l	d0
	beq	nomessage1
	
	lea	menupal,a1
	move.l	scrpt1,a0
	lea	sc_ViewPort(a0),a0
	move.l	#4,d0
	move.l	gfxbase,a6
	jsr	_LVOLoadRGB4(a6)

	move.l	#mwintitle,windowtitle
	lea	newloadwin,a0
	move.l	intuibase,a6
	jsr	_LVOOpenWindow(a6)
	move.l	d0,lswindow
	
	bsr	drawLSwin

	move.l	req2,a1
	move.l	rtfi_Dir(a1),d1
	move.l	#SHARED_LOCK,d2
	move.l	dosbase,a6
	jsr	_LVOLock(a6)
	move.l	d0,filelock
	beq	writeerr
	
	move.l	d0,d1
	jsr	_LVOCurrentDir(a6)
	move.l	d0,olddirlock
	
	move.l	#filename,d1
	move.l	#MODE_NEWFILE,d2
	move.l	dosbase,a6
	jsr	_LVOOpen(a6)
	tst.l	d0
	beq	writeerr
	move.l	d0,handle1
	
	move.l	pladdr,a0
	move.w	iffheight,d0
	mulu	bytewid1,d0
	move.w	iffheight,d4
	lea	copybuff,a5
	
nextline11	move.w	d4,lineno
	move.w	iffheight,maxline
	bsr	updateLSwin

	move.w	bytewid1,d2
	lsr.l	#1,d2
	cmp.b	#1,extrablit
	bne	nobuffend1
	
	clr.w	(a5)+
	cmp.l	#copybuffend,a5
	bne	nobuffend1
	
	lea	copybuff,a5
	movem.l	d0/d2/a0,-(sp)
	move.l	handle1,d1
	move.l	#copybuff,d2
	move.l	#copybuffend-copybuff,d3
	jsr	_LVOWrite(a6)
	movem.l	(sp)+,d1/d2/a0
	cmp.l	#copybuffend-copybuff,d0
	bne	writeerr
	move.w	d1,d0
	
nobuffend1	move.w	cdepth,d1
	sub.w	#1,d1
	clr.w	d7
	move.l	a0,-(sp)
	
skipplanes	or.w	(a0),d7
	lea	0(a0,d0.l),a0
	dbf	d1,skipplanes
	
	move.l	(sp)+,a0
	
	add.l	#2,a0
	not.w	d7
	move.w	d7,(a5)+
	cmp.l	#copybuffend,a5
	bne	nobuffend2
	
	lea	copybuff,a5
	movem.l	d0/d2/a0,-(sp)
	move.l	handle1,d1
	move.l	#copybuff,d2
	move.l	#copybuffend-copybuff,d3
	jsr	_LVOWrite(a6)
	movem.l	(sp)+,d1/d2/a0
	cmp.l	#copybuffend-copybuff,d0
	bne	writeerr
	move.w	d1,d0
	
nobuffend2	sub.l	#1,d2
	bne	nobuffend1
	
	cmp.b	#2,extrablit
	bne	nobuffend3
	
	clr.w	(a5)+
	cmp.l	#copybuffend,a5
	bne	nobuffend3
	
	lea	copybuff,a5
	movem.l	d0/d2/a0,-(sp)
	move.l	handle1,d1
	move.l	#copybuff,d2
	move.l	#copybuffend-copybuff,d3
	jsr	_LVOWrite(a6)
	movem.l	(sp)+,d1/d2/a0
	cmp.l	#copybuffend-copybuff,d0
	bne	writeerr
	move.w	d1,d0
	
nobuffend3	sub.w	#1,d4
	bne	nextline11
	
	movem.l	d0/d2/a0,-(sp)
	move.l	handle1,d1
	move.l	#copybuff,d2
	move.l	a5,d3
	sub.l	#copybuff,d3
	move.l	d3,d6
	jsr	_LVOWrite(a6)
	movem.l	(sp)+,d1/d2/a0
	cmp.l	d6,d0
	bne	writeerr
	
	bsr	closeLSwin
	bsr	closefile
	bsr	fakebpl
	bra	nomessage1

savebrmask	tst.w	brtlx
	bge	brushset5
	tst.w	brbrx
	bge	brushset5
	tst.w	brtly
	bge	brushset5
	tst.w	brbry
	bge	brushset5
	bra	nomessage1

brushset5	clr.b	filename
	move.l	req2,a1
	lea	filename,a2
	lea	savmasktxt,a3
	lea	tags2,a0
	move.l	reqtbase,a6
	jsr	_LVOrtFileRequestA(a6)
	tst.l	d0
	beq	nomessage1
	
	lea	menupal,a1
	move.l	scrpt1,a0
	lea	sc_ViewPort(a0),a0
	move.l	#4,d0
	move.l	gfxbase,a6
	jsr	_LVOLoadRGB4(a6)

	move.l	#mwintitle,windowtitle
	lea	newloadwin,a0
	move.l	intuibase,a6
	jsr	_LVOOpenWindow(a6)
	move.l	d0,lswindow
	
	bsr	drawLSwin

	move.l	req2,a1
	move.l	rtfi_Dir(a1),d1
	move.l	#SHARED_LOCK,d2
	move.l	dosbase,a6
	jsr	_LVOLock(a6)
	move.l	d0,filelock
	beq	writeerr
	
	move.l	d0,d1
	jsr	_LVOCurrentDir(a6)
	move.l	d0,olddirlock
	
	move.l	#filename,d1
	move.l	#MODE_NEWFILE,d2
	move.l	dosbase,a6
	jsr	_LVOOpen(a6)
	tst.l	d0
	beq	writeerr
	move.l	d0,handle1
	
	move.l	pladdr,a0
	lea	copybuff,a1
	move.w	brtly,d5
	move.l	a0,a4
	
nextline12	move.w	brbry,lineno
	sub.w	d5,lineno
	move.w	brbry,maxline
	move.w	brtly,d7
	sub.w	d7,maxline
	bsr	updateLSwin

	lea	copybuff,a2
	move.w	#$FF,d7
clear1	clr.l	(a2)+
	dbf	d7,clear1
	
	move.w	cdepth,d2
	move.w	d5,d3
	mulu	bytewid1,d3
	lea	0(a0,d3.w),a0
	
nextplane10	lea	copybuff,a1
	move.w	brtlx,d1
nextbyte5	move.w	#7,d3
nextbit5	move.w	d1,d6
	move.w	d1,d7
	not.w	d7
	and.w	#7,d7
	and.w	#$FFF8,d6
	lsr.w	#3,d6
	btst	d7,0(a0,d6.w)
	beq	bitclear5
	
	bset	d3,(a1)
	
bitclear5	add.w	#1,d1

	cmp.w	brbrx,d1
	bgt	linedone6
	
	sub.w	#1,d3
	bpl	nextbit5
	
	add.w	#1,a1
	bra	nextbyte5

linedone6	move.w	iffheight,d0
	mulu	bytewid1,d0
	lea	0(a0,d0.w),a0
	
	sub.w	#1,d2
	bne	nextplane10
	
	cmp.b	#1,extrablit
	bne	noblitL6
	
	clr.w	store1
	filewrite	handle1,#store1,#2
	
noblitL6	add.l	#1,a1
	clr.b	(a1)
	sub.l	#copybuff,a1
	move.l	a1,d0
	add.l	#1,d0
	and.l	#$fffffffe,d0
	
	filewrite	handle1,#copybuff,d0
	
	cmp.b	#2,extrablit
	bne	noblitR6

	clr.w	store1
	filewrite	handle1,#store1,#2
	
noblitR6	move.l	a4,a0
	add.w	#1,d5
	cmp.w	brbry,d5
	ble	nextline12
	
	bsr	closeLSwin
	bsr	closefile
	bsr	fakebpl
	bra	nomessage1

screenmode	lea	menupal,a1
	move.l	scrpt1,a0
	lea	sc_ViewPort(a0),a0
	move.l	#4,d0
	move.l	gfxbase,a6
	jsr	_LVOLoadRGB4(a6)
	
	move.l	reqtbase,a6
	move.l	#RT_SCREENMODEREQ,d0
	sub.l	a0,a0
	;lea	sc_tags1,a0
	jsr	_LVOrtAllocRequestA(a6)
	move.l	d0,d7
	beq	noscreq
	
	move.l	d7,a1
	lea	sc_tags3,a0
	jsr	_LVOrtChangeReqAttrA(a6)
	
	move.l	d7,a1
	lea	wintit,a3
	lea	sc_tags2,a0
	jsr	_LVOrtScreenModeRequestA(a6)
	
	tst.l	d0
	beq	noscreq
	
screntry	move.l	d7,a0
	move.l	rtsc_DisplayID(a0),d0
	move.l	d0,scrvmodes
	move.l	d0,iffcamg

	move.w	rtsc_DisplayWidth(a0),scrwid
	move.w	scrwid,winwidth
	move.w	scrwid,pagewid
	move.w	rtsc_DisplayHeight(a0),scrht
	move.w	scrht,winheight
	move.w	scrht,pageht
	sub.w	#22,winheight
	
	move.l	d7,a1
	jsr	_LVOrtFreeRequest(a6)
	
	tst.l	winpt1
	beq	nowin
	
	move.l	intuibase,a6
	move.l	winpt1,a0
	jsr	_LVOClearMenuStrip(a6)
	
	move.l	winpt1,a0
	jsr	_LVOCloseWindow(a6)
	clr.l	winpt1
	
nowin	tst.l	scrpt1
	beq	noscr
	move.l	scrpt1,a0
	jsr	_LVOCloseScreen(a6)
	clr.l	scrpt1
	
noscr	move.l	intuibase,a6
	lea	newscreen,a0
	jsr	_LVOOpenScreen(a6)
	tst.l	d0
	beq	noram
	move.l	d0,scrpt1
	move.l	d0,scrpt2
	move.l	d0,scrpt3
	move.l	d0,scrpt4
	;move.l	d0,scrpt5
	
	move.w	iffdepth,cdepth
	move.w	cdepth,d0
	move.w	#1,d1
	lea	depthASCII,a0
	bsr	numtohexasc
	
	lea	newwindow,a0
	move.l	intuibase,a6
	jsr	_LVOOpenWindow(a6)
	move.l	d0,winpt1
	move.l	d0,winpt2
	move.l	d0,winpt3
	move.l	d0,winpt4
	beq	noram
	
	move.w	pageht,d0
	sub.w	#$32,d0
	lsr.w	#1,d0
	move.w	d0,loadwiny
	move.w	pagewid,d0
	sub.w	#$118,d0
	lsr.w	#1,d0
	move.w	d0,loadwinx
	
	move.l	winpt1,a0
	lea	menu1,a1
	move.l	intuibase,a6
	jsr	_LVOSetMenuStrip(a6)
	
	move.l	winpt1,a0
	lea	mousept,a1
	move.w	#15,d0
	move.w	#15,d1
	move.w	#-8,d2
	move.w	#-7,d3
	jsr	_LVOSetPointer(a6)
	
	move.l	winpt1,a1
	move.l	wd_RPort(a1),a1
	move.b	#RP_COMPLEMENT,d0
	move.l	gfxbase,a6
	jsr	_LVOSetDrMd(a6)
	
	move.w	#$FFFF,brtlx
	move.w	#$FFFF,brtly
	move.w	#$FFFF,brbrx
	move.w	#$FFFF,brbry
	sf	brushon
	bsr	updatecoords
	bsr	fakebpl
	bra	doblit
noscreq	bsr	fakebpl
	bra	nomessage1

filterfunc	move.l	iffcamg,d0
	move.l	a1,d1
	
	and.l	#~MONITOR_ID_MASK,d0
	and.l	#~MONITOR_ID_MASK,d1
	
	move.l	d0,d2
	move.l	d1,d3
	and.l	#HAM_KEY,d2
	and.l	#HAM_KEY,d3
	cmp.l	d2,d3
	bne	exclude
	
	move.l	d0,d2
	move.l	d1,d3
	and.l	#EXTRAHALFBRITE_KEY,d2
	and.l	#EXTRAHALFBRITE_KEY,d3
	cmp.l	d2,d3
	bne	exclude
	bra	include
	
exclude	moveq	#0,d0
	rts
	
include	move.l	#-1,d0
	rts

;----------------------------------------------------------

drawLSwin	move.l	lswindow,d0
	tst.l	d0
	beq	noLSwin00
	move.l	d0,a1
	
	move.l	wd_RPort(a1),a1
	move.l	#2,d0
	move.l	gfxbase,a6
	jsr	_LVOSetAPen(a6)
	
	move.l	lswindow,a0
	move.l	wd_RPort(a0),a0
	lea	intuiloadtxt,a1
	move.l	#11,d0
	move.l	#20,d1
	move.l	intuibase,a6
	jsr	_LVOPrintIText(a6)
	
	move.l	lswindow,a1
	move.l	wd_RPort(a1),a1
	move.l	#11,d0
	move.l	#30,d1
	move.l	#269,d2
	move.l	#40,d3
	move.l	gfxbase,a6
	jsr	_LVORectFill(a6)
	
	move.l	lswindow,a1
	move.l	wd_RPort(a1),a1
	moveq	#0,d0
	jsr	_LVOSetAPen(a6)
	
	move.l	lswindow,a1
	move.l	wd_RPort(a1),a1
	move.l	#12,d0
	move.l	#31,d1
	move.l	#268,d2
	move.l	#39,d3
	jsr	_LVORectFill(a6)
noLSwin00	rts

updateLSwin	tst.l	lswindow
	beq	noLSwin01
	
	movem.l	d0-d7/a0-a6,-(sp)
	
	move.l	lswindow,a1
	move.l	wd_RPort(a1),a1
	move.l	#3,d0
	move.l	gfxbase,a6
	jsr	_LVOSetAPen(a6)
	
	move.l	lswindow,a1
	move.l	wd_RPort(a1),a1
	move.l	#12,d0
	move.l	#31,d1
	move.l	#256,d3
	mulu	lineno,d3
	divu	maxline,d3
	
	and.l	#$FFFF,d3
	move.l	#268,d2
	sub.w	d3,d2
	move.l	#39,d3
	jsr	_LVORectFill(a6)
	
	movem.l	(sp)+,d0-d7/a0-a6
noLSwin01	rts

closeLSwin	tst.l	lswindow
	beq	noLSwin02
	
	move.l	intuibase,a6
	move.l	lswindow,a0
	jsr	_LVOCloseWindow(a6)
	clr.l	lswindow
noLSwin02	rts

close	tst.l	winpt1
	beq	nowin1
	move.l	winpt1,a0
	move.l	intuibase,a6
	jsr	_LVOClearMenuStrip(a6)
	
	move.l	winpt1,a0
	jsr	_LVOCloseWindow(a6)
	clr.l	winpt1
	
nowin1	tst.l	scrpt1
	beq	noscr1
	move.l	scrpt1,a0
	move.l	intuibase,a6
	jsr	_LVOCloseScreen(a6)
	clr.l	scrpt1
	
noscr1	tst.l	pladdr
	beq	nobpl1
	move.l	pladdr,a1
	move.l	plsize,d0
	move.l	4.w,a6
	jsr	_LVOFreeMem(a6)
	clr.l	pladdr
	
nobpl1	tst.l	req1
	beq	noreq1
	move.l	reqtbase,a6
	move.l	req1,a1
	jsr	_LVOrtFreeRequest(a6)
	clr.l	req1
	
noreq1	tst.l	req2
	beq	noreq2
	move.l	reqtbase,a6
	move.l	req2,a1
	jsr	_LVOrtFreeRequest(a6)
	clr.l	req2
	
noreq2	tst.l	dtbase
	beq	nodtlib
	move.l	dtbase,a1
	move.l	4.w,a6
	jsr	_LVOCloseLibrary(a6)
	clr.l	dtbase
	
nodtlib	tst.l	reqtbase
	beq	norqtlib
	move.l	reqtbase,a1
	move.l	4.w,a6
	jsr	_LVOCloseLibrary(a6)
	clr.l	reqtbase
	
norqtlib	tst.l	gadbase
	beq	nogadtlib
	move.l	gadbase,a1
	move.l	4.w,a6
	jsr	_LVOCloseLibrary(a6)
		clr.l	gadbase
	
nogadtlib	tst.l	gfx39base
	beq	nogfx39lib
	move.l	gfx39base,a1
	move.l	4.w,a6
	jsr	_LVOCloseLibrary(a6)
	clr.l	gfx39base
	
nogfx39lib	tst.l	gfxbase
	beq	nogfxlib
	move.l	gfxbase,a1
	move.l	4.w,a6
	jsr	_LVOCloseLibrary(a6)
	clr.l	gfxbase
	
nogfxlib	tst.l	intuibase
	beq	nointlib
	move.l	intuibase,a1
	move.l	4.w,a6
	jsr	_LVOCloseLibrary(a6)
	clr.l	intuibase
	
nointlib	move.l	dosbase,a1
	move.l	4.w,a6
	jsr	_LVOCloseLibrary(a6)
	clr.l	dosbase
	
	moveq	#0,d0
	rts

coordchange	add.b	#1,coordtype
	cmp.b	#3,coordtype
	bne	notwrapct
	move.b	#0,coordtype
notwrapct	rts

decbpl	cmp.w	#1,cdepth
	beq	minbpl
	
	move.l	iffcamg,d0
	and.l	#$880,d0
	bne	minbpl
	
	sub.w	#1,cdepth
	bsr	fakebpl
	move.w	cdepth,d0
	move.w	#1,d1
	lea	depthASCII,a0
	bsr	numtohexasc
	bsr	writecoords
minbpl	rts

incbpl	move.w	cdepth,d0
	cmp.w	iffdepth,d0
	beq	maxbpl
	
	move.l	iffcamg,d0
	and.l	#$880,d0
	bne	maxbpl
	add.w	#1,cdepth
	bsr	fakebpl
	move.w	cdepth,d0
	move.w	#1,d1
	lea	depthASCII,a0
	bsr	numtohexasc
	bsr	writecoords
maxbpl	rts

fakebpl	tst.l	gfx39base
	beq	nogfx39b
	
	move.l	gfx39base,a6
	move.l	#1,d0
	move.w	iffdepth,d1
	lsl.l	d1,d0
	move.l	#1,d2
	move.w	cdepth,d3
	lsl.l	d3,d2
	divu	d2,d0
	move.w	d0,d6
	sub.w	#1,d6
	lea	pal32,a1
	move.l	#1,d0
	move.w	iffdepth,d1
	lsl.l	d1,d0
	move.w	d0,(a1)+
	clr.w	(a1)+
	
nextlot	move.l	#1,d7
	move.w	cdepth,d1
	lsl.l	d1,d7
	sub.w	#1,d7
	lea	palstore1,a0
	
	moveq	#0,d1
	move.l	#$7fff,d2
	clr.b	d4
	
copycols	moveq	#0,d3
	move.b	(a0)+,d0
	and.l	#$FF,d0
	add.l	d0,d3
	swap	d0
	lsl.l	#8,d0
	move.l	d0,(a1)+
	move.b	(a0)+,d0
	and.l	#$FF,d0
	add.l	d0,d3
	swap	d0
	lsl.l	#8,d0
	move.l	d0,(a1)+
	move.b	(a0)+,d0
	and.l	#$FF,d0
	add.l	d0,d3
	swap	d0
	lsl.l	#8,d0
	
	cmp.w	d3,d1
	bge	notlight3
	
	move.w	d3,d1
	move.b	d4,lightest
	
notlight3	cmp.w	d3,d2
	ble	notdark3
	
	move.w	d3,d2
	move.b	d4,darkest

notdark3	move.l	d0,(a1)+
	addq.b	#1,d4
	dbf	d7,copycols
	dbf	d6,nextlot
	
	clr.l	(a1)+
	lea	pal32,a1
	move.l	scrpt1,a0
	lea	sc_ViewPort(a0),a0
	jsr	_LVOLoadRGB32(a6)
	rts

nogfx39b	move.l	gfxbase,a6
	moveq	#1,d0
	move.w	iffdepth,d1
	lsl.l	d1,d0
	move.w	d0,d7
	subq.w	#1,d7
	lea	palstore1,a0
	lea	palstore2,a1
	
copypal2	moveq	#0,d2
	move.b	(a0)+,d1
	and.b	#$F0,d1
	lsr.b	#4,d1
	or.b	d1,d2
	lsl.w	#4,d2
	move.b	(a0)+,d1
	and.b	#$F0,d1
	lsr.b	#4,d1
	or.b	d1,d2
	lsl.w	#4,d2
	move.b	(a0)+,d1
	and.b	#$F0,d1
	lsr.b	#4,d1
	or.b	d1,d2
	move.w	d2,(a1)+
	dbf	d7,copypal2
	
	lea	palstore2,a1
	move.l	scrpt1,a0
	lea	sc_ViewPort(a0),a0
	jsr	_LVOLoadRGB4(a6)
	rts

writecoords	move.l	winpt1,a1
	move.l	wd_RPort(a1),a1
	move.b	#RP_JAM2,d0
	move.l	gfxbase,a6
	jsr	_LVOSetDrMd(a6)
	
	move.l	scrpt1,a1
	lea	sc_RastPort(a1),a1
	moveq	#0,d0
	move.b	darkest,d0
	jsr	_LVOSetAPen(a6)
	
	move.l	scrpt1,a1
	lea	sc_RastPort(a1),a1
	move.l	#320,d0
	move.l	#12,d1
	move.w	pagewid,d2
	move.l	#19,d3
	jsr	_LVORectFill(a6)
	
	move.l	winpt1,a1
	move.l	wd_RPort(a1),a1
	move.b	#RP_COMPLEMENT,d0
	jsr	_LVOSetDrMd(a6)
	
	
	lea	statmod,a0
	lea	coordtxt,a1
	tst.b	coordtype
	beq	coordstype
	
	lea	addrtxt,a1
coordstype	move.b	(a1)+,(a0)+
	bne	coordstype
		
	move.b	lightest,statbfg
	move.b	darkest,statbbg
	move.l	scrpt1,a0
	lea	sc_RastPort(a0),a0
	lea	statbartxt,a1
	clr.w	d0
	move.w	#12,d1
	move.l	intuibase,a6
	jsr	_LVOPrintIText(a6)
	rts

numtoascii2	add.l	#6,a0
	lea	numbers,a1
	move.w	#6-1,d7
	bra	convert

numtoascii	and.l	#$FFFF,d0
	tst.w	d0
	bpl	notminus
	
	clr.w	d0
	
notminus	add.l	#4,a0
	lea	numbers,a1
	move.w	#4-1,d7
convert	divs	#10,d0
	swap	d0
	move.b	0(a1,d0.w),-(a0)
	clr.w	d0
	swap	d0
	dbf	d7,convert
	rts

numbers	dc.b	'0123456789'

numtohexasc	move.l	d7,-(sp)
	and.l	#$FFFF,d0
	and.l	#$FFFF,d1
	add.l	d1,a0
	lea	hexnums,a1
	move.w	d1,d7
	sub.w	#1,d7
convert2	divs	#$10,d0
	swap	d0
	move.b	0(a1,d0.w),-(a0)
	clr.w	d0
	swap	d0
	dbf	d7,convert2
	
	move.l	(sp)+,d7
	rts

hexnums	dc.b	'0123456789ABCDEF'

**************************************************************** 
* 
*  Copyright 1988 by CREATIVE FOCUS.  This code is freely 
*  distributable as long as this notice is retained and no 
*  other conditions are imposed upon its redistribution. 
* 
* 
*  APACK.ASM --  
* 
*  A fully compatible replacement for Electronic Arts' PACKER.C 
*  routine.  Converts data according to the IFF ILBM cmpByteRun1 
*  compression protocol: 
* 
*     control bytes: 
* 
*        n =  0.. 127:   followed by n+1 bytes of data; 
*        n = -1..-127:   followed by byte to be repeated -n+1 times; 
*        n =     -128:   don't do no nada. 
* 
*     calling format: 
* 
*        long packrow(from, too, amt) 
*           char **from, /* pointer to source data pointer */ 
*                **too;  /* pointer to destination data pointer */ 
*           long amt;    /* number of bytes to compress */ 
* 
*        return(number of bytes written to destination); 
* 
*     effects: 
* 
*         *from = *from + amt, and *too = *too + return; 
*         return is "smart," that is, not greater than 
*         MaxPackedSize = amt + ((amt+127) >> 7). 
* 
*     By commenting out CHECK (below) you disable checking for runs 
*     exceeding 128 bytes.  That CHECK is not needed if you are sure 
*     the amt to be compressed is always 128 or less. 
* 
*  !!! DISCLAIMER !!!  You use this code entirely at your own 
*  risk.  I don't warrantee its fitness for any purpose.  I 
*  can't even guarantee the accuracy of anything I've said 
*  about it, though I've tried my damndest to get it right. 
*  I may, in fact, be completely out of my tiny little mind :-). 
* 
*  That being said, I can be reached for questions, comments, 
*  or concerns at: 
* 
*        Dr. Gerald Hull 
*        CREATIVE FOCUS 
*        12 White Street 
*        Binghamton, N.Y.  13901 
*        (607) 648-4082 
* 
*        bix:    ghull 
*        PLink:  DRJERRY 
* 
*************************************************************** 
FRM   equ   8                 input line address 
TOO   equ   12                output line address 
AMT   equ   16                length of input line 
 
MAX   equ   128               maximum encodable output run 
CHECK equ   1                 turns on maximum row checking 
 
packrow 
 
 
***************     CASE 0:   GRAB PARAMS & INITIALIZE 
CAS0 
      link     a6,#0 
      movem.l  d2/d3/a2/a3/a4,-(a7) 
      movea.l  FRM(a6),a2 
      movea.l  (a2),a2        a2 = *from 
      movea.l  a2,a3          a3 = a2 
      movea.l  a3,a1 
      adda.l   AMT(a6),a1     a1 = a2 + amt 
      movea.l  TOO(a6),a4 
      movea.l  (a4),a4        a4 = *too 
 
 
***************     CASE 1:   LITERAL RUN 
CAS1 
      movea.l  a3,a0          adjust a0 (no replicates yet!) 
      move.b   (a3)+,d3       grab character 
      cmpa.l   a3,a1          if input is finished 
      beq.s    CAS5              branch to case 5 
 
      ifd      CHECK 
      move.l   a3,d1 
      sub.l    a2,d1 
      cmpi     #MAX,d1        if run has reached MAX 
      beq.s    CAS6              branch to case 6 
      endc 
 
      cmp.b    (a3),d3        if next character != CH 
      bne.s    CAS1              stay in case 1 

      move.b	(a3)+,d3
      cmp.l	a3,a1
      beq.b	CAS7

      move.l	a3,d1
      sub.l	a2,d1
      cmp.w	#MAX,d1
      beq.b	CAS6

      cmp.b	(a3),d3
      bne.b	CAS1
  
***************     CASE 3:   REPLICATE RUN 
CAS3 
      move.b   (a3)+,d3       grab character 
      cmpa.l   a3,a1          if input is finished 
      beq.s    CAS7              branch to case 7 
 
      ifd      CHECK 
      move.l   a3,d1 
      sub.l    a0,d1 
      cmpi     #MAX,d1        if run has reached MAX 
      beq.s    CAS4              branch to case 4 
      endc 
 
      cmp.b    (a3),d3        if next character = CH 
      beq.s    CAS3              stay in case 3 
 
*                             else fall into case 4 
 
 
***************     CASE 4:   LIT AND/OR REP DUMP & CONTINUE 
CAS4 
      move.l   a0,d2 
      sub.l    a2,d2          d2 = a0 - a2 
*                             if no literal run 
      beq.s    C41               branch to replicate run 
 
      subq     #1,d2          d2 = d2 - 1 
      move.b   d2,(a4)+       output literal control byte 
 
C40   move.b   (a2)+,(a4)+    output literal run 
      dbra     d2,C40 
 
C41   move.l   a0,d2 
      sub.l    a3,d2          d2 = a0 - a3 (negative result!) 
      addq     #1,d2          d2 = d2 + 1 
      move.b   d2,(a4)+       output replicate control byte 
      move.b   d3,(a4)+       output repeated character 
      movea.l  a3,a2          reset a2 
      bra.s    CAS1           branch to case 1 (not done) 
 
 
***************     CASE 5:   LITERAL DUMP & QUIT 
CAS5 
      move.l   a3,d2 
      sub.l    a2,d2          d2 = a3 - a2 (positive result > 0) 
      subq     #1,d2          d2 = d2 - 1 
      move.b   d2,(a4)+       output literal control byte 
 
C50   move.b   (a2)+,(a4)+    output literal run 
      dbra     d2,C50 
 
      bra.s    CAS8           branch to case 8 (done) 
 
 
      ifd      CHECK 
 
***************     CASE 6:   LITERAL DUMP & CONTINUE 
CAS6 
      move.l   a3,d2 
      sub.l    a2,d2          d2 = a3 - a2 (positive result > 0) 
      subq     #1,d2          d2 = d2 - 1 
      move.b   d2,(a4)+       output literal control byte 
 
C60   move.b   (a2)+,(a4)+    output literal run 
      dbra     d2,C60 
 
      bra      CAS1           branch to case 1 (not done) 
 
      endc 
 
 
***************     CASE 7:   LIT AND/OR REP DUMP & FINISH 
CAS7 
      move.l   a0,d2 
      sub.l    a2,d2          d2 = a0 - a2 (positive result > 0) 
*                             if no literal run 
      beq.s    C71               branch to replicate run 
 
      subq     #1,d2          d2 = d2 - 1 
      move.b   d2,(a4)+       output literal control byte 
 
C70   move.b   (a2)+,(a4)+    output literal run 
      dbra     d2,C70 
 
C71   move.l   a0,d2 
      sub.l    a3,d2          d2 = a0 - a3 (negative result) 
      addq     #1,d2          d2 = d2 + 1 
      move.b   d2,(a4)+       output replicate control byte 
      move.b   d3,(a4)+       output repeated character 
 
*                             fall into case 8 
 
 
***************     CASE 8:   ADJUST PARAMS & RETURN VALUE 
CAS8 
      movea.l  FRM(a6),a0     a0 = **from 
      move.l   a3,(a0)        *from = *from + amt 
      movea.l  TOO(a6),a0     a0 = **too 
 
      move.l   a4,d0 
      sub.l    (a0),d0      return = a4 - *too  
 
      move.l   a4,(a0)       *too = *too + return 
      movem.l  (a7)+,d2/d3/a2/a3/a4 
      UNLK     a6
      rts


nodos	move.l	#-1,d0
	rts

nogfx	move.l	dosbase,a6
	move.l	stdout,d1
	move.l	#nogfxtxt,d2
	move.l	#nogfxend-nogfxtxt,d3
	jsr	_LVOWrite(a6)
	bra	close

nointui	move.l	dosbase,a6
	move.l	stdout,d1
	move.l	#nointuitxt,d2
	move.l	#nointuiend-nointuitxt,d3
	jsr	_LVOWrite(a6)
	bra	close

nogadt	move.l	dosbase,a6
	move.l	stdout,d1
	move.l	#nogadttxt,d2
	move.l	#nogadtend-nogadttxt,d3
	jsr	_LVOWrite(a6)
	bra	close

noreqt	move.l	dosbase,a6
	move.l	stdout,d1
	move.l	#noreqttxt,d2
	move.l	#noreqtend-noreqttxt,d3
	jsr	_LVOWrite(a6)
	bra	close

noreqa1	move.l	dosbase,a6
	move.l	stdout,d1
	move.l	#noreqatxt,d2
	move.l	#noreqaend-noreqatxt,d3
	jsr	_LVOWrite(a6)
	bra	close

noreqa2	move.l	dosbase,a6
	move.l	stdout,d1
	move.l	#noreqatxt,d2
	move.l	#noreqaend-noreqatxt,d3
	jsr	_LVOWrite(a6)
	bra	close

noram	tst.l	dtobject
	beq	nodtobj1
	move.l	winpt1,a0
	move.l	dtobject,a1
	jsr	_LVORemoveDTObject(a6)
	
	move.l	dtobject,a0
	jsr	_LVODisposeDTObject(a6)

nodtobj1	move.l	dosbase,a6
	move.l	stdout,d1
	move.l	#noscreentxt,d2
	move.l	#noscreenend-noscreentxt,d3
	jsr	_LVOWrite(a6)
	bra	close

noks2	move.l	dosbase,a6
	move.l	stdout,d1
	move.l	#noks2txt,d2
	move.l	#noks2end-noks2txt,d3
	jsr	_LVOWrite(a6)
	bra	close

	SECTION	maindata,DATA

	dc.b	'$VER:IFFMaster Pro v0.99n (25/09/94)',0
	
	even
newloadwin
loadwinx	dc.w	0		;x position
loadwiny	dc.w	11		;y position
	dc.w	280		;width
	dc.w	50		;height
	dc.b	0		;block pen
	dc.b	1		;detail pen
	dc.l	0		;easy IDCMP
	dc.l	(WINDOWDRAG|WINDOWDEPTH|SIMPLE_REFRESH|ACTIVATE);flags
	dc.l	0		;gadgets
	dc.l	0		;checkmark
windowtitle	dc.l	lwintitle		;title
scrpt3	dc.l	0		;screen ptr
	dc.l	0		;bitmap
	dc.w	0		;min width
	dc.w	0		;min height
	dc.w	0		;max width
	dc.w	0		;max height
	dc.w	CUSTOMSCREEN	;type

newwindow	dc.w	0		;x position
	dc.w	22		;y position
winwidth	dc.w	640		;width
winheight	dc.w	234		;height
	dc.b	1		;block pen
	dc.b	2		;detail pen
	dc.l	(MOUSEBUTTONS|MOUSEMOVE|MENUPICK|MENUVERIFY|RAWKEY);easy IDCMP
	dc.l	(SMART_REFRESH|ACTIVATE|REPORTMOUSE|BORDERLESS|GIMMEZEROZERO|BACKDROP|WFLG_NEWLOOKMENUS);flags
	dc.l	0		;gadgets
	dc.l	0		;checkmark
	dc.l	0		;title
scrpt2	dc.l	0		;screen ptr	
	dc.l	0		;bitmap
	dc.w	0		;min width
	dc.w	0		;min height
	dc.w	0		;max width
	dc.w	0		;max height
	dc.w	CUSTOMSCREEN	;type

newscreen	dc.w	0		;left edge
	dc.w	0		;top edge
scrwid	dc.w	640		;width
scrht	dc.w	256		;height
scrdepth	dc.w	2		;depth
	dc.b	0		;detail pen
	dc.b	1		;block pen
	dc.w	V_HIRES		;view modes
	dc.w	CUSTOMSCREEN|NS_EXTENDED;type
	dc.l	0		;font
	dc.l	scrtitle		;title
	dc.l	0		;gadgets
	dc.l	0		;custom bitmap
	dc.l	scrtags		;ens extension

scrtags	dc.l	SA_DisplayID
scrvmodes	dc.l	HIRES_KEY
	dc.l	SA_Pens
	dc.l	pensdata
	dc.l	TAG_DONE

pensdata	dc.w	-1

bitmap
bytesperrow	dc.w	80		;bytes per row
height2	dc.w	256		;rows
	dc.b	0		;flags
scdepth	dc.b	2		;depth
	dc.w	0		;pad
bplptr	dc.l	0		;planes ptrs 0 - 7
	dc.l	0
	dc.l	0
	dc.l	0
	dc.l	0
	dc.l	0
	dc.l	0
	dc.l	0

;saveprefswin
;spwinx	dc.w	0		;x position
;spwiny	dc.w	0		;y position
;	dc.w	200		;width
;	dc.w	200		;height
;	dc.b	1		;block pen
;	dc.b	2		;detail pen
;	dc.l	(MOUSEBUTTONS|MOUSEMOVE|MENUPICK|MENUVERIFY|RAWKEY);easy IDCMP
;	dc.l	(SMART_REFRESH|ACTIVATE|WINDOWDRAG);flags
;spwingads	dc.l	0		;gadgets
;	dc.l	0		;checkmark
;	dc.l	0		;title
;scrpt5	dc.l	0		;screen ptr	
;	dc.l	0		;bitmap
;	dc.w	0		;min width
;	dc.w	0		;min height
;	dc.w	0		;max width
;	dc.w	0		;max height
;	dc.w	CUSTOMSCREEN	;type
;
newprefswin	dc.w	0		;x position
	dc.w	0		;y position
	dc.w	640		;width
	dc.w	200		;height
	dc.b	1		;detail pen
	dc.b	2		;block pen
	dc.l	(GADGETUP|CLOSEWINDOW)	;easy IDCMP
	dc.l	(WINDOWDRAG|WINDOWDEPTH|WINDOWCLOSE|SMART_REFRESH|ACTIVATE)	;flags
	dc.l	prefsgad1		;gadgets
	dc.l	0		;checkmark
	dc.l	prefstitle		;title
	dc.l	0		;screen
	dc.l	0		;bitmap
	dc.w	0		;min width
	dc.w	0		;min height
	dc.w	0		;max width
	dc.w	0		;max height
	dc.w	WBENCHSCREEN	;type

keytable	dc.w	ALTLT
	dc.l	altkey
	dc.w	ALTLT+$80
	dc.l	altkey
	dc.w	ALTRT
	dc.l	altkey
	dc.w	ALTRT+$80
	dc.l	altkey
	dc.w	CTRL
	dc.l	ctrlkey
	dc.w	CTRL+$80
	dc.l	ctrlkey
	dc.w	CSRLT
	dc.l	scrolllt
	dc.w	CSRRT
	dc.l	scrollrt
	dc.w	CSRUP
	dc.l	scrollup
	dc.w	CSRDN
	dc.l	scrolldn
	dc.w	B
	dc.l	initbrush
	dc.w	P
	dc.l	setpalette
	dc.w	MINUS
	dc.l	decbpl
	dc.w	EQUALS
	dc.l	incbpl
	dc.w	SPACE
	dc.l	coordchange
	dc.w	$FFFF
	dc.l	$FFFFFFFF

prefstable	dc.l	prefsgad1
	dc.l	prefsbplmeth
	dc.l	prefsgad2
	dc.l	prefspalinfo
	dc.l	prefsgad3
	dc.l	prefspaltype
	dc.l	prefsgad4
	dc.l	prefspalmeth
	dc.l	prefsgad5
	dc.l	prefssprmeth
	dc.l	prefsgad6
	dc.l	prefssprctrl
	dc.l	prefsgad7
	dc.l	prefssprdepth
	dc.l	prefsgad8
	dc.l	prefsextrablit
	dc.l	prefsgad9
	dc.l	prefscomp
	dc.l	prefsgad11
	dc.l	undoprefs
	dc.l	prefsgad13
	dc.l	prefsquit
	dc.l	prefsgad14
	dc.l	prefssave
	dc.l	0
	dc.l	0

prefsgad1	dc.l	prefsgad2		;next gadget
	dc.w	4		;left edge
	dc.w	30		;top edge
	dc.w	632		;width
	dc.w	12		;height
	dc.w	GFLG_GADGIMAGE|GFLG_GADGHIMAGE;flags
	dc.w	GACT_RELVERIFY	;activation
	dc.w	GTYP_BOOLGADGET	;type
	dc.l	pgad1a		;gadget render
	dc.l	0		;select render
	dc.l	pgadtxt1		;gadget text
	dc.l	0		;mutual exclude
	dc.l	0		;special info
	dc.w	0		;gadget id
	dc.l	0		;user data ptr

prefsgad2	dc.l	prefsgad3		;next gadget
	dc.w	4		;left edge
	dc.w	42		;top edge
	dc.w	632		;width
	dc.w	12		;height
	dc.w	GFLG_GADGIMAGE|GFLG_GADGHIMAGE;flags
	dc.w	GACT_RELVERIFY	;activation
	dc.w	GTYP_BOOLGADGET	;type
	dc.l	pgad1a		;gadget render
	dc.l	0		;select render
	dc.l	pgadtxt2		;gadget text
	dc.l	0		;mutual exclude
	dc.l	0		;special info
	dc.w	0		;gadget id
	dc.l	0		;use data ptr

prefsgad3	dc.l	prefsgad4		;next gadget
	dc.w	4		;left edge
	dc.w	54		;top edge
	dc.w	632		;width
	dc.w	12		;height
	dc.w	GFLG_GADGIMAGE|GFLG_GADGHIMAGE;flags
	dc.w	GACT_RELVERIFY	;activation
	dc.w	GTYP_BOOLGADGET	;type
	dc.l	pgad1a		;select render
	dc.l	0		;gadget render
	dc.l	pgadtxt3		;gadget text
	dc.l	0		;mutual exclude
	dc.l	0		;special info
	dc.w	0		;gadget id
	dc.l	0		;use data ptr

prefsgad4	dc.l	prefsgad5		;next gadget
	dc.w	4		;left edge
	dc.w	66		;top edge
	dc.w	632		;width
	dc.w	12		;height
	dc.w	GFLG_GADGIMAGE|GFLG_GADGHIMAGE;flags
	dc.w	GACT_RELVERIFY	;activation
	dc.w	GTYP_BOOLGADGET	;type
	dc.l	pgad1a		;select render
	dc.l	0		;gadget render
	dc.l	pgadtxt4		;gadget text
	dc.l	0		;mutual exclude
	dc.l	0		;special info
	dc.w	0		;gadget id
	dc.l	0		;use data ptr
	
prefsgad5	dc.l	prefsgad6		;next gadget
	dc.w	4		;left edge
	dc.w	78		;top edge
	dc.w	632		;width
	dc.w	12		;height
	dc.w	GFLG_GADGIMAGE|GFLG_GADGHIMAGE;flags
	dc.w	GACT_RELVERIFY	;activation
	dc.w	GTYP_BOOLGADGET	;type
	dc.l	pgad1a		;select render
	dc.l	0		;gadget render
	dc.l	pgadtxt5		;gadget text
	dc.l	0		;mutual exclude
	dc.l	0		;special info
	dc.w	0		;gadget id
	dc.l	0		;use data ptr

prefsgad6	dc.l	prefsgad7		;next gadget
	dc.w	4		;left edge
	dc.w	90		;top edge
	dc.w	632		;width
	dc.w	12		;height
	dc.w	GFLG_GADGIMAGE|GFLG_GADGHIMAGE;flags
	dc.w	GACT_RELVERIFY	;activation
	dc.w	GTYP_BOOLGADGET	;type
	dc.l	pgad1a		;select render
	dc.l	0		;gadget render
	dc.l	pgadtxt6		;gadget text
	dc.l	0		;mutual exclude
	dc.l	0		;special info
	dc.w	0		;gadget id
	dc.l	0		;use data ptr

prefsgad7	dc.l	prefsgad8		;next gadget
	dc.w	4		;left edge
	dc.w	102		;top edge
	dc.w	632		;width
	dc.w	12
	dc.w	GFLG_GADGIMAGE|GFLG_GADGHIMAGE;flags
	dc.w	GACT_RELVERIFY	;activation
	dc.w	GTYP_BOOLGADGET	;type
	dc.l	pgad1a		;select render
	dc.l	0		;gadget render
	dc.l	pgadtxt7		;gadget text
	dc.l	0		;mutual exclude
	dc.l	0		;special info
	dc.w	0		;gadget id
	dc.l	0		;use data ptr

prefsgad8	dc.l	prefsgad9		;next gadget
	dc.w	4		;left edge
	dc.w	114		;top edge
	dc.w	632		;width
	dc.w	12		;height
	dc.w	GFLG_GADGIMAGE|GFLG_GADGHIMAGE;flags
	dc.w	GACT_RELVERIFY	;activation
	dc.w	GTYP_BOOLGADGET	;type
	dc.l	pgad1a		;select render
	dc.l	0		;gadget render
	dc.l	pgadtxt8		;gadget text
	dc.l	0		;mutual exclude
	dc.l	0		;special info
	dc.w	0		;gadget id
	dc.l	0		;use data ptr

prefsgad9	dc.l	prefsgad10		;next gadget
	dc.w	4		;left edge
	dc.w	126		;top edge
	dc.w	632		;width
	dc.w	12		;height
	dc.w	GFLG_GADGIMAGE|GFLG_GADGHIMAGE;flags
	dc.w	GACT_RELVERIFY	;activation
	dc.w	GTYP_BOOLGADGET	;type
	dc.l	pgad1a		;select render
	dc.l	0		;gadget render
	dc.l	pgadtxt9		;gadget text
	dc.l	0		;mutual exclude
	dc.l	0		;special info
	dc.w	0		;gadget id
	dc.l	0		;use data ptr

prefsgad10	dc.l	prefsgad11		;next gadget
	dc.w	4		;left edge
	dc.w	138		;top edge
	dc.w	632		;width
	dc.w	12		;height
	dc.w	GFLG_GADGIMAGE|GFLG_GADGHIMAGE;flags
	dc.w	GACT_RELVERIFY	;activation
	dc.w	GTYP_BOOLGADGET	;type
	dc.l	pgad1a		;select render
	dc.l	0		;gadget render
	dc.l	0		;gadget text
	dc.l	0		;mutual exclude
	dc.l	0		;special info
	dc.w	0		;gadget id
	dc.l	0		;use data ptr

prefsgad11	dc.l	prefsgad12		;next gadget
	dc.w	4		;left edge
	dc.w	150		;top edge
	dc.w	632		;width
	dc.w	12		;height
	dc.w	GFLG_GADGIMAGE|GFLG_GADGHIMAGE;flags
	dc.w	GACT_RELVERIFY	;activation
	dc.w	GTYP_BOOLGADGET	;type
	dc.l	pgad1a		;select render
	dc.l	0		;gadget render
	dc.l	pgadtxt10		;gadget text
	dc.l	0		;mutual exclude
	dc.l	0		;special info
	dc.w	0		;gadget id
	dc.l	0		;use data ptr

prefsgad12	dc.l	prefsgad13		;next gadget
	dc.w	4		;left edge
	dc.w	162		;top edge
	dc.w	632		;width
	dc.w	12		;height
	dc.w	GFLG_GADGIMAGE|GFLG_GADGHIMAGE;flags
	dc.w	GACT_RELVERIFY	;activation
	dc.w	GTYP_BOOLGADGET	;type
	dc.l	pgad1a		;select render
	dc.l	0		;gadget render
	dc.l	0		;gadget text
	dc.l	0		;mutual exclude
	dc.l	0		;special info
	dc.w	0		;gadget id
	dc.l	0		;use data ptr
	
prefsgad13	dc.l	prefsgad14		;next gadget
	dc.w	4		;left edge
	dc.w	174		;top edge
	dc.w	632		;width
	dc.w	12		;height
	dc.w	GFLG_GADGIMAGE|GFLG_GADGHIMAGE;flags
	dc.w	GACT_RELVERIFY	;activation
	dc.w	GTYP_BOOLGADGET	;type
	dc.l	pgad1a		;select render
	dc.l	0		;gadget render
	dc.l	pgadtxt11		;gadget text
	dc.l	0		;mutual exclude
	dc.l	0		;special info
	dc.w	0		;gadget id
	dc.l	0		;use data ptr

prefsgad14	dc.l	0		;next gadget
	dc.w	4		;left edge
	dc.w	186		;top edge
	dc.w	632		;width
	dc.w	12		;height
	dc.w	GFLG_GADGIMAGE|GFLG_GADGHIMAGE;flags
	dc.w	GACT_RELVERIFY	;activation
	dc.w	GTYP_BOOLGADGET	;type
	dc.l	pgad1a		;select render
	dc.l	0		;gadget render
	dc.l	pgadtxt12		;gadget text
	dc.l	0		;mutual exclude
	dc.l	0		;special info
	dc.w	0		;gadget id
	dc.l	0		;use data ptr

pgad1a	dc.w	0		;left edge
	dc.w	0		;top edge
	dc.w	632		;width
	dc.w	12		;height
	dc.w	1		;depth
	dc.l	gadgetimage		;image data
	dc.b	2		;planepick
	dc.b	0		;plane on/off
	dc.l	0		;next image

pgadtxt1	dc.b	1		;front pen
	dc.b	0		;back pen
	dc.b	RP_JAM2		;draw mode
	dc.b	0		;pad byte
	dc.w	29		;left edge
	dc.w	2		;top edge
	dc.l	0		;font
	dc.l	ptxt1		;text
	dc.l	0		;next intuitext

pgadtxt2	dc.b	1		;front pen
	dc.b	0		;back pen
	dc.b	RP_JAM2		;draw mode
	dc.b	0		;pad byte
	dc.w	29		;left edge
	dc.w	2		;top edge
	dc.l	0		;font
	dc.l	ptxt2		;text
	dc.l	0		;next intuitext

pgadtxt3	dc.b	1		;front pen
	dc.b	0		;back pen
	dc.b	RP_JAM2		;draw mode
	dc.b	0		;pad byte
	dc.w	29		;left edge
	dc.w	2		;top edge
	dc.l	0		;font
	dc.l	ptxt3		;text
	dc.l	0		;next intuitext

pgadtxt4	dc.b	1		;front pen
	dc.b	0		;back pen
	dc.b	RP_JAM2		;draw mode
	dc.b	0		;pad byte
	dc.w	29		;left edge
	dc.w	2		;top edge
	dc.l	0		;font
	dc.l	ptxt4		;text
	dc.l	0		;next intuitext

pgadtxt5	dc.b	1		;front pen
	dc.b	0		;back pen
	dc.b	RP_JAM2		;draw mode
	dc.b	0		;pad byte
	dc.w	29		;left edge
	dc.w	2		;top edge
	dc.l	0		;font
	dc.l	ptxt5		;text
	dc.l	0		;next intuitext

pgadtxt6	dc.b	1		;front pen
	dc.b	0		;back pen
	dc.b	RP_JAM2		;draw mode
	dc.b	0		;pad byte
	dc.w	29		;left edge
	dc.w	2		;top edge
	dc.l	0		;font
	dc.l	ptxt6		;text
	dc.l	0		;next intuitext

pgadtxt7	dc.b	1		;front pen
	dc.b	0		;back pen
	dc.b	RP_JAM2		;draw mode
	dc.b	0		;pad byte
	dc.w	29		;left edge
	dc.w	2		;top edge
	dc.l	0		;font
	dc.l	ptxt7		;text
	dc.l	0		;next intuitext

pgadtxt8	dc.b	1		;front pen
	dc.b	0		;back pen
	dc.b	RP_JAM2		;draw mode
	dc.b	0		;pad byte
	dc.w	29		;left edge
	dc.w	2		;top edge
	dc.l	0		;font
	dc.l	ptxt8		;text
	dc.l	0		;next intuitext

pgadtxt9	dc.b	1		;front pen
	dc.b	0		;back pen
	dc.b	RP_JAM2		;draw mode
	dc.b	0		;pad byte
	dc.w	29		;left edge
	dc.w	2		;top edge
	dc.l	0		;font
	dc.l	ptxt9		;text
	dc.l	0		;next intuitext

pgadtxt10	dc.b	1		;front pen
	dc.b	0		;back pen
	dc.b	RP_JAM2		;draw mode
	dc.b	0		;pad byte
	dc.w	29		;left edge
	dc.w	2		;top edge
	dc.l	0		;font
	dc.l	ptxt10		;text
	dc.l	0		;next intuitext

pgadtxt11	dc.b	1		;front pen
	dc.b	0		;back pen
	dc.b	RP_JAM2		;draw mode
	dc.b	0		;pad byte
	dc.w	29		;left edge
	dc.w	2		;top edge
	dc.l	0		;font
	dc.l	ptxt11		;text
	dc.l	0		;next intuitext

pgadtxt12	dc.b	1		;front pen
	dc.b	0		;back pen
	dc.b	RP_JAM2		;draw mode
	dc.b	0		;pad byte
	dc.w	29		;left edge
	dc.w	2		;top edge
	dc.l	0		;font
	dc.l	ptxt12		;text
	dc.l	0		;next intuitext

;picsavegad1	dc.w	150,50		;left,top
;	dc.w	150,50		;width,height
;	dc.l	psgad1title		;gadget text
;	dc.l	textattr		;text attr
;	dc.w	1		;gadget id
;	dc.l	0		;flags
;visinfo2	dc.l	0		;visual info
;	dc.l	0		;user data
;psgad1title	dc.b	'Image Save Format',0
;
;textattr	dc.l	topazname
;	dc.w	8
;	dc.b	FS_NORMAL
;	dc.b	FPF_ROMFONT
;topazname	dc.b	"Topaz",0
;
statbartxt
statbfg	dc.b	1		;front pen
statbbg	dc.b	0		;back pen
	dc.b	RP_JAM2		;draw mode
	dc.b	0		;pad byte
	dc.w	0		;left edge
	dc.w	0		;top edge
	dc.l	0		;font
	dc.l	stattxt		;text
	dc.l	0		;next intuitext

intuiloadtxt
blkpen1	dc.b	1		;front pen
detpen1	dc.b	0		;back pen
	dc.b	RP_JAM2		;draw mode
	dc.b	0		;pad byte
	dc.w	0		;left edge
	dc.w	0		;top edge
	dc.l	0		;font
	dc.l	loadtxt2		;text
	dc.l	0		;next intuitext

menu1	dc.l	menu2		;next menu
	dc.w	5		;left edge
	dc.w	0		;top edge
	dc.w	63		;width
	dc.w	10		;height
	dc.w	MENUENABLED		;flags
	dc.l	menu1txt		;menu name
	dc.l	m1option1		;first item
	dc.w	0		;jazz x
	dc.w	0		;jaxx y
	dc.w	0		;beat x
	dc.w	0		;beat y
	
menu1txt	dc.b	'Project',0

m1option1	dc.l	m1option2		;next item
	dc.w	0		;left edge
	dc.w	0		;top edge
	dc.w	150		;width
	dc.w	10		;height
	dc.w	HIGHCOMP|ITEMENABLED|COMMSEQ|ITEMTEXT;flags
	dc.l	0		;mutual exclude
	dc.l	m1opt1itext		;item fill
	dc.l	0		;select fill
	dc.b	'L'		;command
	dc.b	0		;pad byte
	dc.l	0		;sub item
	dc.w	0		;next select
	
m1opt1itext	dc.b	1		;front pen
	dc.b	2		;back pen
	dc.b	RP_JAM2		;draw mode
	dc.b	0		;pad byte
	dc.w	0		;left edge
	dc.w	1		;top edge
	dc.l	0		;font
	dc.l	m1opt1txt		;text
	dc.l	0		;next intuitext

m1opt1txt	dc.b	'Load Image',0

m1option2	dc.l	m1option3		;next item
	dc.w	0		;top edge
	dc.w	10		;left edge
	dc.w	150		;width
	dc.w	10		;height
	dc.w	HIGHCOMP|ITEMENABLED|ITEMTEXT;flags
	dc.l	0		;mutual exclude
	dc.l	m1opt2itext		;item fill
	dc.l	0		;select fill
	dc.b	0		;command
	dc.b	0		;pad byte
	dc.l	m1option2s1		;sub item
	dc.w	0		;next select

m1opt2itext	dc.b	1		;front pen
	dc.b	2		;back pen
	dc.b	RP_JAM2		;draw mode
	dc.b	0		;pad byte
	dc.w	0		;left edge
	dc.w	1		;top edge
	dc.l	0		;font
	dc.l	m1opt2txt		;text
	dc.l	0		;next intuitext
	
m1opt2txt	dc.b	'Save Image',0

m1option2s1	dc.l	m1option2s2		;next item
	dc.w	100		;left edge
	dc.w	-5		;top edge
	dc.w	150		;width
	dc.w	10		;height
	dc.w	HIGHCOMP|ITEMENABLED|COMMSEQ|ITEMTEXT;flags
	dc.l	0		;mutual exclude
	dc.l	m1o2s1itext		;item fill
	dc.l	0		;select fill
	dc.b	'R'		;command
	dc.b	0		;pad byte
	dc.l	0		;sub item
	dc.w	0		;next select

m1o2s1itext	dc.b	1		;front pen
	dc.b	2		;back pen
	dc.b	RP_JAM2		;draw mode
	dc.b	0		;pad byte
	dc.w	0		;left edge
	dc.w	1		;top edge
	dc.l	0		;font
	dc.l	m1o2s1txt		;text
	dc.l	0		;next intuitext

m1o2s1txt	dc.b	'as raw data',0

m1option2s2	dc.l	0		;next item
	dc.w	100		;left edge
	dc.w	5		;top edge
	dc.w	150		;width
	dc.w	10		;height
	dc.w	HIGHCOMP|ITEMENABLED|COMMSEQ|ITEMTEXT;flags
	dc.l	0		;mutual exclude
	dc.l	m1o2s2itext		;item fill
	dc.l	0		;select fill
	dc.b	'I'		;command
	dc.b	0		;pad byte
	dc.l	0		;sub item
	dc.w	0		;next select

m1o2s2itext	dc.b	1		;front pen
	dc.b	2		;back pen
	dc.b	RP_JAM2		;draw mode
	dc.b	0		;pad byte
	dc.w	0		;left edge
	dc.w	1		;top edge
	dc.l	0		;font
	dc.l	m1o2s2txt		;text
	dc.l	0		;next intuitext
	
m1o2s2txt	dc.b	'as IFF/ILBM',0

m1option3	dc.l	m1option4		;next item
	dc.w	0		;left edge
	dc.w	20		;top edge
	dc.w	150		;width
	dc.w	10		;height
	dc.w	HIGHCOMP|ITEMENABLED|ITEMTEXT;flags
	dc.l	0		;mutual exclude
	dc.l	m1opt3itext		;item fill
	dc.l	0		;select fill
	dc.b	0		;command
	dc.b	0		;pad byte
	dc.l	m1opt3sub1		;sub item
	dc.w	0		;next select

m1opt3itext	dc.b	1		;front pen
	dc.b	2		;back pen
	dc.b	RP_JAM2		;draw mode
	dc.b	0		;pad byte
	dc.w	0		;left edge
	dc.w	1		;top edge
	dc.l	0		;font
	dc.l	m1opt3txt		;text
	dc.l	0		;next intuitext

m1opt3txt	dc.b	'Save Brush',0

m1opt3sub1	dc.l	m1opt3sub2		;next item
	dc.w	100		;left edge
	dc.w	-5		;top edge
	dc.w	150		;width
	dc.w	10		;height
	dc.w	HIGHCOMP|ITEMENABLED|COMMSEQ|ITEMTEXT;flags
	dc.l	0		;mutual exclude
	dc.l	m1o3s1itext		;item fill
	dc.l	0		;select fill
	dc.b	'A'		;command
	dc.b	0		;pad byte
	dc.l	0		;sub item
	dc.w	0		;next select

m1o3s1itext	dc.b	1		;front pen
	dc.b	2		;back pen
	dc.b	RP_JAM2		;draw mode
	dc.b	0		;pad byte
	dc.w	0		;left edge
	dc.w	1		;top edge
	dc.l	0		;font
	dc.l	m1o3s1txt		;text
	dc.l	0		;next intuitext

m1o3s1txt	dc.b	'as raw data',0
	
m1opt3sub2	dc.l	0		;next item
	dc.w	100		;left edge
	dc.w	5		;top edge
	dc.w	150		;width
	dc.w	10		;height
	dc.w	HIGHCOMP|ITEMENABLED|COMMSEQ|ITEMTEXT;flags
	dc.l	0		;mutual exclude
	dc.l	m1o3s2itext		;item fill
	dc.l	0		;select fill
	dc.b	'F'		;command
	dc.b	0		;pad byte
	dc.l	0		;sub item
	dc.w	0		;next select

m1o3s2itext	dc.b	1		;front pen
	dc.b	2		;back pen
	dc.b	RP_JAM2		;draw mode
	dc.b	0		;pad byte
	dc.w	0		;left edge
	dc.w	1		;top edge
	dc.l	0		;font
	dc.l	m1o3s2txt		;text
	dc.l	0		;next intuitext

m1o3s2txt	dc.b	'as IFF/ILBM',0

m1option4	dc.l	m1option5		;next item
	dc.w	0		;left edge
	dc.w	30		;top edge
	dc.w	150		;width
	dc.w	10		;height
	dc.w	HIGHCOMP|ITEMENABLED|ITEMTEXT;flags
	dc.l	0		;mutual exclude
	dc.l	m1opt4itext		;item fill
	dc.l	0		;select fill
	dc.b	0		;command
	dc.b	0		;pad byte
	dc.l	m1opt4sub1		;sub item
	dc.w	0		;next select

m1opt4itext	dc.b	1		;front pen
	dc.b	2		;back pen
	dc.b	RP_JAM2		;draw mode
	dc.b	0		;pad byte
	dc.w	0		;top edge
	dc.w	1		;left edge
	dc.l	0		;font
	dc.l	m1opt4txt		;text
	dc.l	0		;next intuitext
	
m1opt4txt	dc.b	'Save Sprite',0

m1opt4sub1	dc.l	m1opt4sub2		;next item
	dc.w	100		;left edge
	dc.w	-10		;top edge
	dc.w	120		;width
	dc.w	10		;height
	dc.w	HIGHCOMP|ITEMENABLED|COMMSEQ|ITEMTEXT;flags
	dc.l	0		;mutual exclude
	dc.l	m1o4s1itext		;item fill
	dc.l	0		;select fill
	dc.b	'1'		;command
	dc.b	0		;pad byte
	dc.l	0		;sub item
	dc.w	0		;next select

m1o4s1itext	dc.b	1		;front pen
	dc.b	2		;back pen
	dc.b	RP_JAM2		;draw mode
	dc.b	0		;pad byte
	dc.w	0		;left edge
	dc.w	1		;top edge
	dc.l	0		;font
	dc.l	m1o4s1txt		;text
	dc.l	0		;next intuitext

m1o4s1txt	dc.b	'16 pa1el',0

m1opt4sub2	dc.l	m1opt4sub3		;next item
	dc.w	100		;left edge
	dc.w	0		;top edge
	dc.w	120		;width
	dc.w	10		;height
	dc.w	HIGHCOMP|ITEMENABLED|COMMSEQ|ITEMTEXT;flags
	dc.l	0		;mutual exclude
	dc.l	m1o4s2itext		;item fill
	dc.l	0		;select fill
	dc.b	'3'		;command
	dc.b	0		;pad byte
	dc.l	0		;sub item
	dc.w	0		;next select
	
m1o4s2itext	dc.b	1		;front pen
	dc.b	2		;back pen
	dc.b	1		;draw mode
	dc.b	0		;pad byte
	dc.w	0		;left edge
	dc.w	1		;top edge
	dc.l	0		;font
	dc.l	m1o4s2txt		;text
	dc.l	0		;next intuitext

m1o4s2txt	dc.b	'32 pa1el',0

m1opt4sub3	dc.l	0		;next item
	dc.w	100		;left edge
	dc.w	10		;top edge
	dc.w	120		;width
	dc.w	10		;height
	dc.w	HIGHCOMP|ITEMENABLED|COMMSEQ|ITEMTEXT;flags
	dc.l	0		;mutual exclude
	dc.l	m1o4s3itext		;item fill
	dc.l	0		;select fill
	dc.b	'6'		;command
	dc.b	0		;pad byte
	dc.l	0		;sub item
	dc.w	0		;next select

m1o4s3itext	dc.b	1		;front pen
	dc.b	2		;back pen
	dc.b	RP_JAM2		;draw mode
	dc.b	0		;pad byte
	dc.w	0		;left edge
	dc.w	1		;top edge
	dc.l	0		;font
	dc.l	m1o4s3txt		;text
	dc.l	0		;next intuitext

m1o4s3txt	dc.b	'64 pa1el',0

m1option5	dc.l	m1option6		;next item
	dc.w	0		;left edge
	dc.w	40		;top edge
	dc.w	150		;width
	dc.w	10		;height
	dc.w	0		;flags
	dc.l	0		;mutual exclude
	dc.l	m1o5image		;item fill
	dc.l	0		;select fill
	dc.b	0		;command
	dc.b	0		;pad byte
	dc.l	0		;sub item
	dc.w	0		;next select

m1o5image	dc.w	0		;left edge
	dc.w	4		;top edge
	dc.w	150		;width
	dc.w	2		;height
	dc.w	0		;depth
	dc.l	0		;image data
	dc.b	0		;plane pick
	dc.b	0		;plane on off
	dc.l	0		;next image

m1option6	dc.l	m1option7		;next item
	dc.w	0		;left edge
	dc.w	50		;top edge
	dc.w	150		;width
	dc.w	10		;height
	dc.w	HIGHCOMP|ITEMENABLED|COMMSEQ|ITEMTEXT;flags
	dc.l	0		;mutual exclude
	dc.l	m1opt6itext		;item fill
	dc.l	0		;select fill
	dc.b	'S'		;command
	dc.b	0		;pad byte
	dc.l	0		;sub item
	dc.w	0		;next select

m1opt6itext	dc.b	1		;front pen
	dc.b	2		;back pen
	dc.b	RP_JAM2		;draw mode
	dc.b	0		;pad byte
	dc.w	0		;left edge
	dc.w	1		;top edge
	dc.l	0		;font
	dc.l	m1opt6txt		;text
	dc.l	0		;next intuitext

m1opt6txt	dc.b	'Screen Mode',0


m1option7	dc.l	m1option8		;next item
	dc.w	0		;left edge
	dc.w	60		;top edge
	dc.w	150		;width
	dc.w	10		;height
	dc.w	HIGHCOMP|ITEMENABLED|COMMSEQ|ITEMTEXT;flags
	dc.l	0		;mutual exclude
	dc.l	m1opt7itext		;item fill
	dc.l	0		;select fill
	dc.b	'P'		;command
	dc.b	0		;pad byte
	dc.l	0		;sub item
	dc.w	0		;next select

m1opt7itext	dc.b	1		;front pen
	dc.b	2		;back pen
	dc.b	RP_JAM2		;draw mode
	dc.b	0		;pad byte
	dc.w	0		;left edge
	dc.w	1		;top edge
	dc.l	0		;font
	dc.l	m1opt7txt		;text
	dc.l	0		;next intuitext

m1opt7txt	dc.b	'Preferences',0

m1option8	dc.l	m1option9		;next item
	dc.w	0		;left edge
	dc.w	70		;top edge
	dc.w	150		;width
	dc.w	10		;height
	dc.w	HIGHCOMP|ITEMENABLED|COMMSEQ|ITEMTEXT;flags
	dc.l	0		;mutual exclude
	dc.l	m1opt8itext		;item fill
	dc.l	0		;select fill
	dc.b	'!'		;command
	dc.b	0		;pad byte
	dc.l	0		;sub item
	dc.w	0		;next select

m1opt8itext	dc.b	1		;front pen
	dc.b	2		;back pen
	dc.b	1		;draw mode
	dc.b	0		;pad byte
	dc.w	0		;left edge
	dc.w	1		;top edge
	dc.l	0		;font
	dc.l	m1opt8txt		;text
	dc.l	0		;next intuitext

m1opt8txt	dc.b	'About',0

m1option9	dc.l	m1option10		;next item
	dc.w	0		;left edge
	dc.w	80		;top edge
	dc.w	150		;width
	dc.w	10		;height
	dc.w	0		;flags
	dc.l	0		;mutual exclude
	dc.l	m1o5image		;item fill
	dc.l	0		;select fill
	dc.b	0		;command
	dc.b	0		;pad byte
	dc.l	0		;sub item
	dc.w	0		;next select

m1option10	dc.l	0		;next item
	dc.w	0		;left edge
	dc.w	90		;top edge
	dc.w	150		;width
	dc.w	10		;height
	dc.w	HIGHCOMP|ITEMENABLED|COMMSEQ|ITEMTEXT;flags
	dc.l	0		;mutual exclude
	dc.l	m1opt10itext	;item fill
	dc.l	0		;select fill
	dc.b	$51		;command
	dc.b	0		;pad byte
	dc.l	0		;sub item
	dc.w	0		;next select

m1opt10itext
	dc.b	1		;front pen
	dc.b	2		;back pen
	dc.b	1		;draw mode
	dc.b	0		;pad byte
	dc.w	0		;left edge
	dc.w	1		;top edge
	dc.l	0		;font
	dc.l	m1opt10txt		;text
	dc.l	0		;next intuitext

m1opt10txt	dc.b	'Quit',0,0


menu2	dc.l	0		;next menu
	dc.w	80		;left edge
	dc.w	0		;top edge
	dc.w	63		;width
	dc.w	10		;height
	dc.w	MENUENABLED		;flags
	dc.l	menu2txt		;menu name
	dc.l	m2option1		;first item
	dc.w	0		;jazz x
	dc.w	0		;jazz y
	dc.w	0		;beat x
	dc.w	0		;beat y
	
menu2txt	dc.b	'Toolbox',0

m2option1	dc.l	m2option2		;next item
	dc.w	0		;left edge
	dc.w	0		;top edge
	dc.w	178		;width
	dc.w	10		;height
	dc.w	HIGHCOMP|ITEMENABLED|ITEMTEXT;flags
	dc.l	0		;mutual exclude
	dc.l	m2opt1itext		;item fill
	dc.l	0		;select fill
	dc.b	0		;command
	dc.b	0		;pad byte
	dc.l	0		;sub item
	dc.w	0		;next select

m2opt1itext	dc.b	1		;front pen
	dc.b	2		;back pen
	dc.b	RP_JAM2		;draw mode
	dc.b	0		;pad byte
	dc.w	0		;left edge
	dc.w	1		;top edge
	dc.l	0		;font
	dc.l	m2opt1txt		;text
	dc.l	0		;next intuitext

m2opt1txt	dc.b	'Cut Brush            b',0

m2option2	dc.l	m2option3		;next item
	dc.w	0		;left edge
	dc.w	10		;top edge
	dc.w	178		;width
	dc.w	10		;height
	dc.w	HIGHCOMP|ITEMENABLED|ITEMTEXT;flags
	dc.l	0		;mutual exclude
	dc.l	m2opt2itext		;item fill
	dc.l	0		;select fill
	dc.b	0		;command
	dc.b	0		;pad byte
	dc.l	0		;sub item
	dc.w	0		;next select

m2opt2itext	dc.b	1		;front pen
	dc.b	2		;back pen
	dc.b	RP_JAM2		;draw mode
	dc.b	0		;pad byte
	dc.w	0		;left edge
	dc.w	1		;top edge
	dc.l	0		;font
	dc.l	m2opt2txt		;text
	dc.l	0		;next intuitext

m2opt2txt	dc.b	'Set Palette          p',0

m2option3	dc.l	m2option4		;next item
	dc.w	0		;left edge
	dc.w	20		;top edge
	dc.w	178		;width
	dc.w	10		;height
	dc.w	0		;flags
	dc.l	0		;mutual exclude
	dc.l	m2opt3image		;item fill
	dc.l	0		;select fill
	dc.b	0		;command
	dc.b	0		;pad byte
	dc.l	0		;sub item
	dc.w	0		;next select

m2opt3image	dc.w	0		;left edge
	dc.w	4		;top edge
	dc.w	178		;width
	dc.w	2		;height
	dc.w	0		;depth
	dc.l	0		;image data
	dc.b	0		;plane pick
	dc.b	0		;plane on/off
	dc.l	0		;next image

m2option4	dc.l	m2option5		;next item
	dc.w	0		;left edge
	dc.w	30		;top edge
	dc.w	178		;width
	dc.w	10		;height
	dc.w	HIGHCOMP|ITEMENABLED|COMMSEQ|ITEMTEXT;flags
	dc.l	0		;mutual exclude
	dc.l	m2opt4itext		;item fill
	dc.l	0		;select fill
	dc.b	'G'		;command
	dc.b	0		;pad byte
	dc.l	0		;sub item
	dc.w	0		;next item

m2opt4itext	dc.b	1		;front pen
	dc.b	2		;back pen
	dc.b	RP_JAM2		;draw mode
	dc.b	0		;pad byte
	dc.w	0		;left edge
	dc.w	1		;top edge
	dc.l	0		;font
	dc.l	m2opt4txt		;text
	dc.l	0		;next intuitext

m2opt4txt	dc.b	'Generate Palette',0

m2option5	dc.l	m2option6		;next item
	dc.w	0		;left edge
	dc.w	40		;top edge
	dc.w	178		;width
	dc.w	10		;height
	dc.w	HIGHCOMP|ITEMENABLED|COMMSEQ|ITEMTEXT;flags
	dc.l	0		;mutual exclude
	dc.l	m2opt5itext		;item fill
	dc.l	0		;select fill
	dc.b	'B'		;command
	dc.b	0		;pad byte
	dc.l	0		;sub item
	dc.w	0		;next select

m2opt5itext	dc.b	1		;front pen
	dc.b	2		;back pen
	dc.b	RP_JAM2		;draw mode
	dc.b	0		;pad byte
	dc.w	0		;left edge
	dc.w	1		;top edge
	dc.l	0		;font
	dc.l	m2opt5txt		;text
	dc.l	0		;next intuitext

m2opt5txt	dc.b	'Save Brush Mask',0

m2option6	dc.l	0		;next item
	dc.w	0		;left edge
	dc.w	50		;top edge
	dc.w	178		;width
	dc.w	10		;height
	dc.w	HIGHCOMP|ITEMENABLED|COMMSEQ|ITEMTEXT;flags
	dc.l	0		;mutual exclude
	dc.l	m2opt6itext		;item fill
	dc.l	0		;select fill
	dc.b	'M'		;command
	dc.b	0		;pad byte
	dc.l	0		;sub item
	dc.w	0		;next select

m2opt6itext	dc.b	1		;front pen
	dc.b	2		;back pen
	dc.b	RP_JAM2		;draw mode
	dc.b	0		;pad byte
	dc.w	0		;left edge
	dc.w	1		;top edge
	dc.l	0		;font
	dc.l	m2opt6txt		;text
	dc.l	0		;next intuitext

m2opt6txt	dc.b	'Save Picture Mask',0

loadtags	dc.l	RTFI_Dir
	dc.l	loaddir
	dc.l	TAG_DONE
	
savetags	dc.l	RTFI_Dir
	dc.l	savedir
	dc.l	TAG_DONE
	
tags2	dc.l	RT_ReqPos
	dc.l	1
	dc.l	TAG_DONE
	
taglist	dc.l	RT_ReqPos
	dc.l	1
	dc.l	RTEZ_Flags
	dc.l	7
	dc.l	RT_Window
winpt2	dc.l	0
	dc.l	TAG_DONE

taglist2	dc.l	RT_Window
winpt3	dc.l	0
	dc.l	RT_ReqPos
	dc.l	1
	dc.l	TAG_DONE

sc_tags2	dc.l	RTSC_Flags
	dc.l	SCREQF_NONSTDMODES
	dc.l	RT_Window
winpt4	dc.l	0
	dc.l	RTSC_FilterFunc
	dc.l	hook
	dc.l	TAG_DONE

hook	dc.l	filterfunc
	dc.l	filterfunc
	dc.l	filterfunc

sc_tags3	dc.l	RTSC_ModeFromScreen
scrpt4	dc.l	0
	dc.l	RTSC_OverscanType
	dc.l	0
	dc.l	TAG_DONE

dttags	dc.l	PDTA_Remap
	dc.l	0
	dc.l	DTA_GroupID
	dc.l	GID_PICTURE
	dc.l	TAG_DONE

dtattrs	dc.l	DTA_NominalHoriz
	dc.l	dtwidth
	dc.l	DTA_NominalVert
	dc.l	dtheight
	dc.l	PDTA_ModeID
	dc.l	iffcamg
	dc.l	PDTA_BitMapHeader
	dc.l	bmhdaddr
	dc.l	PDTA_BitMap
	dc.l	bitmapaddr
	dc.l	PDTA_CRegs
	dc.l	colortable
	dc.l	TAG_DONE

dtattrs2	dc.l	GA_Left
	dc.l	0
	dc.l	GA_Top
	dc.l	0
	dc.l	GA_Width
dtwidmod	dc.l	0
	dc.l	GA_Height
dthtmod	dc.l	0
	dc.l	TAG_DONE

;gadtags1	dc.l	GTMX_Labels
;	dc.l	labels
;	dc.l	GTMX_TitlePlace
;	dc.l	PLACETEXT_ABOVE
;	dc.l	TAG_DONE
;
;labels	dc.l	iffsavetxt
;	dc.l	rawsavetxt
;	dc.l	irawsavetxt
;	dc.l	0
;
;iffsavetxt	dc.b	'IFF ILBM',0
;rawsavetxt	dc.b	'Raw',0
;irawsavetxt	dc.b	'Interleaved Raw',0
;
palreqtxt	dc.b	'Change Colours',0

bodyfmt1	dc.b	'IFFMaster Pro (v0.99n)',$A
	dc.b	'by Rebel',$A
	dc.b	'This IFF Converter is very closely',$A
	dc.b	'based on ARCANEs IFFMaster (v1.0)',$A
	dc.b	'but with the inclusion of AGA',$A
	dc.b	'compatibility and some other small',$A
	dc.b	'enhancements.',$A,$A
	dc.b	'Personal greets to Lampwick, Neil',$A
	dc.b	'Richard, Richard, Fossil & Tweeky.',$A,$A
	dc.b	'This utility was written in 100%%',$A
	dc.b	'pure assembler using Devpac 3.',$A,$A
	dc.b	'Many thanks also to Lampwick for',$A
	dc.b	'lots of testing and suggestions',$A
	dc.b	'during the development of this',$A
	dc.b	'project.',$A,$A,0
gadfmt1	dc.b	'Continue',0


bodyfmt2	dc.b	'File Read Error, Load Aborted.',$A,0
gadfmt2	dc.b	'Abort',0

bodyfmt3	dc.b	'This file is not an ILBM file and',$A
	dc.b	'is not recognised by the',$A
	dc.b	'datatypes.library (if available)',$A,0
gadfmt3	dc.b	'Abort',0

bodyfmt4	dc.b	'There Is Not Enough Free Memory',$A
	dc.b	'To Load The Picture',$A,0
gadfmt4	dc.b	'Abort',0

bodyfmt5	dc.b	'IFF File is corrupt and has not',$A
	dc.b	'been completely loaded.',$A,0
gadfmt5	dc.b	'Continue',0

bodyfmt6	dc.b	'File Write Error, Save Aborted.',$A,0
gadfmt6	dc.b	'Abort',0

bodyfmt7	dc.b	'Unable to open preferences window.',$A,0
gadfmt7	dc.b	'Abort',0

bodyfmt8	dc.b	'Error while saving preferences file.',$A,0
gadfmt8	dc.b	'Continue',0

dosname	dc.b	'dos.library',0

intuiname	dc.b	'intuition.library',0
reqtname	dc.b	'reqtools.library',0
gfxname	dc.b	'graphics.library',0
gadname	dc.b	'gadtools.library',0
dtname	dc.b	'datatypes.library',0

dosbase	ds.l	1
intuibase	ds.l	1
reqtbase	ds.l	1
gfx39base	ds.l	1
gfxbase	ds.l	1
gadbase	ds.l	1
dtbase	ds.l	1

filename	ds.b	108

loadtxt	dc.b	'Choose Picture To Load',0
savetxt	dc.b	'Choose Filename For Save',0
savpaltxt	dc.b	'Choose Saved Palette Name',0
savmasktxt	dc.b	'Choose Mask File Name',0
savcoptxt	dc.b	'Choose Copper List File Name',0,0
wintit	dc.b	"choose screen mode",0
lwintitle	dc.b	'        Loading ILBM Image',0
swintitle	dc.b	'         Saving ILBM Image',0
srawtitle	dc.b	'          Saving RAW Image',0
mwintitle	dc.b	'         Saving Mask Image',0
scrtitle	dc.b	'IFF Master Pro v0.99 by Rebel',0,0
prefstitle	dc.b	'IFFMaster Pro Preferences',0
loadtxt2	dc.b	'0%                          100%',0
ptxt1	dc.b	'Bitplane Save Method         :  '
ptxt1a	dc.b	'Normal     ',0
ptxt2	dc.b	'Palette Info                 :  '
ptxt2a	dc.b	'None  ',0
ptxt3	dc.b	'Palette Type                 :  '
ptxt3a	dc.b	'12 Bit',0
ptxt4	dc.b	'Palette Save Method          :  '
ptxt4a	dc.b	'Source       ',0
ptxt5	dc.b	'Sprites Save Method          :  '
ptxt5a	dc.b	'Source',0
ptxt6	dc.b	'Sprite Control Words         :  '
ptxt6a	dc.b	'Off',0
ptxt7	dc.b	'Sprite Depth                 :  '
ptxt7a	dc.b	'4 Colours ',0
ptxt8	dc.b	'Extra Blitter Words          :  '
ptxt8a	dc.b	'None ',0
ptxt9	dc.b	'ILBM Compression             :  '
ptxt9a	dc.b	'Byte Run 1',0
ptxt10	dc.b	'Cancel Preferences',0
ptxt11	dc.b	'Use these Prefs',0
ptxt12	dc.b	'Save and use these prefs',0
prefsname	dc.b	'S:IFFMasterPro.prefs',0
stattxt	dc.b	'D'
depthASCII	dc.b	'  BW'
brwidASCII	dc.b	'     BH'
brhtASCII	dc.b	'     W'
widASCII	dc.b	'0000 H'
heightASCII	dc.b	'0000 '

statmod	dc.b	'           ',0

coordtxt	dc.b	'X'
xASCII	dc.b	'0000 Y'
yASCII	dc.b	'0000',0

addrtxt	dc.b	'A'
addrmod	dc.b	'000000     ',0

savemethtxt	dc.l	savemthtxt1
	dc.l	savemthtxt2
	
palinfotxt	dc.l	palinfotxt1
	dc.l	palinfotxt2
	dc.l	palinfotxt3
	
paltypetxt	dc.l	paltypetxt1
	dc.l	paltypetxt2
	
palmethtxt	dc.l	palmthtxt1
	dc.l	palmthtxt2
	dc.l	palmthtxt3
	
sprmethtxt	dc.l	sprmthtxt1
	dc.l	sprmthtxt2
	
sprctrltxt	dc.l	sprctrltxt1
	dc.l	sprctrltxt2
	
sprdeptxt	dc.l	sprdeptxt1
	dc.l	sprdeptxt2
	
xtrablittxt	dc.l	xtrablttxt1
	dc.l	xtrablttxt2
	dc.l	xtrablttxt3
	
iffcomptxt	dc.l	iffcomptxt1
	dc.l	iffcomptxt2
	
savemthtxt1	dc.b	'Normal     '
savemthtxt2	dc.b	'Interleaved'

palinfotxt1	dc.b	'None  '
palinfotxt2	dc.b	'After '
palinfotxt3	dc.b	'Before'

paltypetxt1	dc.b	'12 Bit'
paltypetxt2	dc.b	'24 Bit'

palmthtxt1	dc.b	'Source       '
palmthtxt2	dc.b	'Copper Source'
palmthtxt3	dc.b	'Binary       '

sprmthtxt1	dc.b	'Source'
sprmthtxt2	dc.b	'Binary'

sprctrltxt1	dc.b	'Off'
sprctrltxt2	dc.b	'On '

sprdeptxt1	dc.b	'4 Colours '
sprdeptxt2	dc.b	'16 Colours'

xtrablttxt1	dc.b	'None '
xtrablttxt2	dc.b	'Left '
xtrablttxt3	dc.b	'Right'

iffcomptxt1	dc.b	'None      '
iffcomptxt2	dc.b	'Byte Run 1'

filelock	ds.l	1
olddirlock	ds.l	1
store1	ds.l	1
iffend	ds.l	1
seekpos	ds.l	1
handle1	ds.l	1
bodylen	ds.l	1
buffptr	ds.l	1
lenstore	ds.l	1
stdout	ds.l	1
req1	ds.l	1
req2	ds.l	1
message	ds.l	1
blenpos	ds.l	1
pladdr	ds.l	1
plsize	ds.l	1
oldplsize	ds.l	1
scrpt1	ds.l	1
winpt1	ds.l	1
lswindow	ds.l	1
prefswin	ds.l	1
;tempwinptr	ds.l	1
;visinfo	ds.l	1
;gadtgad1	ds.l	1

iffwidth	ds.w	1
iffheight	ds.w	1
pagewid	ds.w	1
pageht	ds.w	1
iffdepth	ds.w	1
mask	ds.b	1
comp	ds.b	1
height	ds.w	1
width	ds.w	1
scrollx	ds.w	1
scrolly	ds.w	1
aspects	ds.b	1
	ds.b	1
sprwid	ds.l	1
cdepth	ds.w	1
mousex	dc.w	$FFFF
mousey	dc.w	$FFFF
brtlx	dc.w	$FFFF
brtly	dc.w	$FFFF
brbrx	dc.w	$FFFF
brbry	dc.w	$FFFF
brtlxoff	dc.w	$FFFF
brtlyoff	dc.w	$FFFF
brbrxoff	dc.w	$FFFF
brbryoff	dc.w	$FFFF
brushon	ds.b	1
intopborder	ds.b	1
bytewid1	ds.w	1
bytewid2	ds.w	1
iffcamg	ds.l	1
lightest	ds.b	1
darkest	ds.b	1
lineno	ds.w	1
maxline	ds.w	1
lmbpress	ds.b	1
altpressed	ds.b	1
ctrlpressed	ds.b	1
coordtype	ds.b	1
dtobject	ds.l	1
dtwidth	ds.l	1
dtheight	ds.l	1
bmhdaddr	ds.l	1
bitmapaddr	ds.l	1
colortable	ds.l	1
gads	ds.l	1
palstore1	dc.l	$AAAAAA00
	dc.l	$0000FFFF
	dc.l	$FF6688BB
	ds.l	63*3

pal32	ds.l	1
palstore2	ds.l	257*3

menupal	dc.w	$aaa
	dc.w	$000
	dc.w	$fff
	dc.w	$68b

newprefs
bplmeth	dc.b	0
palinfo	dc.b	1
paltype	dc.b	0
palmeth	dc.b	0
sprmeth	dc.b	0
sprctrl	dc.b	1
sprdepth	dc.b	0
extrablit	dc.b	0
iffcomp	dc.b	1
	;pad byte
buffptr1	ds.l	1
buffptr2	ds.l	1

loaddir	ds.b	256
savedir	ds.b	256
endnewprefs

oldprefs	ds.b	endnewprefs-newprefs

pal12src	dc.b	'	DC.W	$'
pal12mod1	dc.b	'0000',$A
endpal12

pal24src	dc.b	'	DC.B	$'
pal24mod1	dc.b	'00,$'
pal24mod2	dc.b	'00,$'
pal24mod3	dc.b	'00',$A,'	DC.W	$106,$0000',$A
endpal24

copsrc1	dc.b	'	DC.W	$'
copmod1	dc.b	'180,$'
copmod2	dc.b	'0000',$A
endcop1

spr16ctrl	dc.b	'spr1'
sprsaveA	dc.b	'	DC.W	$0000,$0000',$A
end16save

spr32ctrl	dc.b	'spr1'
sprsaveB	dc.b	'	DC.W	$0000,$0000,$0000,$0000',$A
end32save

spr64ctrl	dc.b	'spr1'
sprsaveC	dc.b	'	DC.W	$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000',$A
end64save

sprtxt1	dc.b	'	DC.W'
sprtxt2	dc.b	'	$'
sprtxt3	dc.b	'0000,$'
sprtxt4	dc.b	'0000,$'
sprtxt5	dc.b	'0000,$'
sprtxt6	dc.b	'0000,$'
sprtxt7	dc.b	'0000,$'
sprtxt8	dc.b	'0000,$'
sprtxt9	dc.b	'0000,$'
sprtxt10	dc.b	'0000',$A

nointuitxt	dc.b	'The intuition.library v36 or higher could not be opened,',$a
	dc.b	'either there is a very serious fault with your Amiga, or you are ',$a
	dc.b	'simply running out of free memory.',$a,$a
nointuiend

nogfxtxt	dc.b	'The graphics.library v36 or higher could not be opened, ',$a
	dc.b	'either there is a very serious fault with your Amiga, or you are ',$a
	dc.b	'simply running out of free memory.',$a,$a
nogfxend

nogadttxt	dc.b	'The gadtools.library v36 or higher could not be opened, this library',$a
	dc.b	'is required to run this program',$a,$a
nogadtend
	
noreqttxt	dc.b	'The reqtools.library could not be opened, to run this program you',$a
	dc.b	'need this library by Nico Francois, copy it to your LIBS: drawer',$a
	dc.b	'before you attempt to run this program again.',$a,$a
noreqtend

noreqatxt	dc.b	'The reqtools.library could not allocate a file requester, the most',$a
	dc.b	'likely reason for this is lack of free RAM',$a,$a
noreqaend

noscreentxt	dc.b	'This program could not open the necessary screen, you must be running',$a
	dc.b	'out of memory or this computer is not capabable of displaying the required.',$a
	dc.b	'screen.',$a,$a
noscreenend

noks2txt	dc.b	'This program needs Kickstart 2 (v36) or better',$a
	dc.b	'to function and you do not appear to have it',$a,$a
noks2end

	section	buffer,bss

copybuff	ds.l	1024*2
copybuffend	ds.b	100	;extra buffer area 
			;in case of compression <0% when picture
			;is 65535 pixels wide
			
copybuff2	ds.l	1024*2
	ds.b	100	;extra buffer area 
			;in case of compression <0% when picture
			;is 65535 pixels wide



	SECTION	Chipdata,DATA_C
mousept	dc.w	%0000000000000000,%0000000000000000
	dc.w	%0000000100000000,%0000000000000000
	dc.w	%0000000000000000,%0000000000000000
	dc.w	%0000000100000000,%0000000000000000
	dc.w	%0000000000000000,%0000000000000000
	dc.w	%0000000100000000,%0000000000000000
	dc.w	%0000000000000000,%0000000000000000
	dc.w	%0000000000000000,%0000000000000000
	dc.w	%1010101110101010,%0000000100000000
	dc.w	%0000000000000000,%0000000000000000
	dc.w	%0000000000000000,%0000000000000000
	dc.w	%0000000100000000,%0000000000000000
	dc.w	%0000000000000000,%0000000000000000
	dc.w	%0000000100000000,%0000000000000000
	dc.w	%0000000000000000,%0000000000000000
	dc.w	%0000000100000000,%0000000000000000
	dc.w	%0000000000000000,%0000000000000000

gadgetimage	dc.l	$FFFFFFFF
	dc.l	$FFFFFFFF
	dc.l	$FFFFFFFF
	dc.l	$FFFFFFFF
	dc.l	$FFFFFFFF
	dc.l	$FFFFFFFF
	dc.l	$FFFFFFFF
	dc.l	$FFFFFFFF
	dc.l	$FFFFFFFF
	dc.l	$FFFFFFFF
	dc.l	$FFFFFFFF
	dc.l	$FFFFFFFF
	dc.l	$FFFFFFFF
	dc.l	$FFFFFFFF
	dc.l	$FFFFFFFF
	dc.l	$FFFFFFFF
	dc.l	$FFFFFFFF
	dc.l	$FFFFFFFF
	dc.l	$FFFFFFFF
	dc.l	$FFFFFF00
	ds.l	220
	end
