	*************************************************
	*						*
	*	  GIN'S MEGA OBJECT EDITOR V3.1!	*
	*						*
	*	Written by Sean Scaplehorn 28/3/90	*
	*						*
	*	    (c) 1990 Amiga Computing		*
	*						*
	*************************************************


LoadRGB4	equ	$ffffff40	;graphics.library equates
SetRGB4		equ	$fffffee0
Draw		equ	$ffffff0a
Move		equ	$ffffff10
RectFill	equ	$fffffece
SetAPen		equ	$fffffeaa
SetDrMd		equ	$fffffe9e
WritePixel	equ	$fffffebc
ReadPixel	equ	$fffffec2
PolyDraw	equ	$fffffeb0
ScrollRaster	equ	-396

OpenScreen	equ	$ffffff3a	;intuition.library equates
CloseScreen	equ	$ffffffbe
OpenWindow	equ	$ffffff34
CloseWindow	equ	$ffffffb8
PrintIText	equ	$ffffff28
AddGadget	equ	$ffffffd6
OffGadget	equ	$ffffff52
OnGadget	equ	$ffffff46
RefreshGadgets	equ	$ffffff22
RemoveGadget	equ	$ffffff1c
SetMenuStrip	equ	$fffffef8
ClearMenuStrip	equ	$ffffffca
OffMenu		equ	$ffffff4c
OnMenu		equ	$ffffff40
ActivateGadget	equ	-462
AllocRemember	equ	$fffffe74
FreeRemember	equ	$fffffe68

OpenLibrary	equ	$fffffdd8	;exec.library equates
CloseLibrary	equ	$fffffe62
GetMsg		equ	$fffffe8c
ReplyMsg	equ	$fffffe86
WaitPort	equ	$fffffe80
AllocMem	equ	$ffffff3a
FreeMem		equ	$ffffff2e

SpFix		equ	$ffffffe2	;mathffp.library equates
SpFlt		equ	$ffffffdc
SpNeg		equ	$ffffffc4
SpAdd		equ	$ffffffbe
SpSub		equ	$ffffffb8
SpMul		equ	$ffffffb2
SpDiv		equ	$ffffffac
SpCmp		equ	$ffffffd6
SpAbs		equ	$ffffffca

Open		equ	$ffffffe2	;dos.library. d0=file handle
Close		equ	$ffffffdc	;dos.library. d0=file handle
Read		equ	$ffffffd6
Write		equ	$ffffffd0
Delay		equ	$ffffff3a

CUSTOMSCREEN	equ	$f
WINDOWBITS	equ	$1000+$0800+$0100	;ACTIVATE+BORDERLESS+BACKDROP
GADGBITS	equ	$0		;$80=SELECTED
BOOLGADGET	equ	1
PROPGADGET	equ	3
STRINGGADGET	EQU	4
GADGACTIVE	equ	$100+$2+$1		;TOGGLESELECT+GADGIMMEDIATE+RELVERIFY

	incdir	"df0:include/"		;This is the include directory on the
	include	"exec/exec_lib.i"	;DevPac v2 disk
	include	"misc/easystart.i"

	move.l	#intname,a1		;get library name
	moveq	#0,d0
	CALLEXEC	OpenLibrary	;open intuition library
	move.l	d0,_IntuitionBase	;store base address
	beq	_error			;something went wrong

	move.l	#gfxname,a1
	moveq	#0,d0
	CALLEXEC	OpenLibrary	;open graphics library
	move.l	d0,_GfxBase		;store base address
	beq	_closeint

	move.l	#mathname,a1
	moveq	#0,d0
	CALLEXEC	OpenLibrary
	move.l	d0,_MathBase
	beq	_closegfx

	move.l	#dosname,a1
	moveq	#0,d0
	CALLEXEC	OpenLibrary
	move.l	d0,_DosBase
	beq	_closemath

	move.l	#newscreen,a0		;get address of newscreen structure
	move.l	_IntuitionBase,a6	;get intuition base
	JSR		OpenScreen(a6)	;Open screen
	move.l	d0,scrnbase		;store address of new structure
	beq	_closedos

	move.l	scrnbase,a0		;get screen base
	lea	44(a0),a0		;get viewport
	move.l	a0,viewport		;save it for later
	lea.l	palette,a1		;palette address
	moveq	#numcols,d0		;number of colours to load
	move.l	_GfxBase,a6		;get graphics base
	JSR		LoadRGB4(a6)	;set palette colours

	lea	newwindow,a0		;Get address of newwindow structure
	move.l	scrnbase,d0		;Get scrnbase
	move.l	d0,30(a0)		;Store in newwindow structure
	move.l	_IntuitionBase,a6	;Get intuition base
	JSR	OpenWindow(a6)		;Open new window
	move.l	d0,windowbase		;store window base
	tst.l	d0
	beq	_closescreen		;Something went wrong!

	move.l	windowbase,a0		;Use window base
	move.l	50(a0),rastport		;Save window's rastport
	move.l	$56(a0),userport	;Save window's userport

	bsr	drawcols		;draw colour selector
	move.w	#1,d0			;outline colour
	bsr	setcolour		;set colour
	move.l	#9,d0
	move.l	#31,d2
	move.l	#157,d1
	move.l	#191,d3
	move.l	#0,d4
	bsr	rectangle
	move.w	#2,col			;default start colour
	bsr	newcolour		;draw current colour square

	lea	R,a2			;label colour sliders
	move.l	#308,d0
	move.l	#156,d1
	move.l	#1,d2
	move.l	#0,d3
	bsr	printtext
	lea	G,a2
	move.l	#308,d0
	move.l	#168,d1
	bsr	printtext
	lea	B,a2
	move.l	#308,d0
	move.l	#180,d1
	bsr	printtext
	lea	objecttitle,a2
	move.l	#272,d0
	move.l	#25,d1
	bsr	printtext
	lea	widftext,a2
	move.l	#276,d0
	move.l	#45,d1
	bsr	printtext
	lea	heighttext,a2
	move.l	#272,d0
	move.l	#65,d1
	bsr	printtext
	lea	desttext,a2
	move.l	#272,d0
	move.l	#120,d1
	bsr	printtext

	bsr	findaddresses		;get bitplane addresses etc.
	bsr	drawgrid

	lea	gadget,a0		;Get address of gadget structure
	move.l	windowbase,a1		;get window base
	move.l	_IntuitionBase,a6	;get intuition base
	JSR	RefreshGadgets(a6)	;Refresh gadgets

	move.l	windowbase,a0		;Get windowbase
	lea	projectmenu,a1		;Get address of menu structure
	move.l	_IntuitionBase,a6	;Get intuition base
	JSR	SetMenuStrip(a6)	;Set Menu up

	move.l	windowbase,a0		;Get windowbase
	move.l	#$ffff,d0		;Specify all menus
	move.l	_IntuitionBase,a6	;Get intuition base
	JSR	OnMenu(a6)		;Activate menus

wloop	move.l	userport,a0		;Get windows userport
	CALLEXEC	WaitPort	;Call waitport
	move.l	userport,a0		;Get userport again
	CALLEXEC	GetMsg		;Get IDCMP message (if any)
	tst.l	d0			;Was there a message?
	beq.s	wloop			;No, so loop back
	move.l	d0,a1			;Get address of message
	move.l	20(a1),d2	;Im.class (contains type of message. e.g. CLOSEWINDOW,GADGETUP)
	move.w	24(a1),d3	;Im.code (contains menu selection numbers etc.)
	move.w	26(a1),d4	;Im.qualifier (keyboard info lives here)
	CALLEXEC	ReplyMsg	;Say ta to intuition
	move.l	(a0),a0			;Get message pointer in a0

ChGadg	cmp.l	#$40,d2			;check class for GADGETUP
	bne.s	ChMenu			;If yes, nip on to next bit
	bra	DoGadg
ChMenu	cmp.l	#$100,d2		;Is it MENUPICK?
	bne.s	ChMouse			;No, so try again
	bra	DoMenu
ChMouse	cmp.l	#$8,d2			;Is it MOUSEBUTTONS?
	bne.s	ChKey
	bra	DoMouse
ChKey	cmp.l	#$400,d2		;Is it RAWKEY?
	bne.s	wloop			;No
	bra	DoKeys
	
_closedown	;Neat exit to CLI/Workbench

	move.w	objecttotal,d2
	cmp.w	#1,d2
	beq.s	_closemenu
	lea	rememberkey,a0
	moveq.l	#1,d0
	move.l	_IntuitionBase,a6
	JSR	FreeRemember(a6)

_closemenu
	move.l	windowbase,a0
	move.l	_IntuitionBase,a6
	JSR	ClearMenuStrip(a6)

_closewindow 
	move.l	windowbase,a0		;get window base
	move.l	_IntuitionBase,a6	;get intuition base
	JSR	CloseWindow(a6)		;Close Window

_closescreen
	move.l	scrnbase,a0		;Get screen address
	move.l	_IntuitionBase,a6
	JSR		CloseScreen(a6)	;Do as it says!

_closedos
	move.l	_DosBase,a1
	CALLEXEC	CloseLibrary
_closemath
	move.l	_MathBase,a1
	CALLEXEC	CloseLibrary

_closegfx
	move.l	_GfxBase,a1		;get graphics base
	CALLEXEC	CloseLibrary	;Close graphics library

_closeint
	move.l	_IntuitionBase,a1	;get intuition base
	CALLEXEC	CloseLibrary	;close library

_error	move.l	#0,d0			;Tell CLI error message
	rts				;return to easystart code

; GADGET routines follow

DoGadg	move.l	28(a0),a0		;Get address of hit gadget
	move.w	38(a0),d0		;Get id of gadget
	cmp.w	#1,d0			;Is it the QUIT gadget?
	bne	NotQuit			;No
	bra	_closedown		;Yes, so tidy up and exit
NotQuit	cmp.w	#2,d0			;Is it Red slider?
	bne.s	NotR
	bsr	getsliderpos
	bsr	splitRGB
	move.w	d5,d1			;Red was changed
	bsr	setonecolour
	bra	wloop	
NotR	cmp.w	#3,d0			;is it green slider?
	bne.s	NotG
	bsr	getsliderpos
	bsr	splitRGB
	move.w	d5,d2			;Green was changed
	bsr	setonecolour
	bra	wloop
NotG	cmp.w	#4,d0			;is it blue slider?
	beq.s	IsB
	bra	wloop
IsB	bsr	getsliderpos
	bsr	splitRGB
	move.w	d5,d3			;Blue was changed
	bsr	setonecolour
	bra	wloop

getsliderpos	move.l	34(a0),a0	;get special info
		clr.l	d5
		clr.l	d0
		move.w	2(a0),d5	;HORIZPOT
		move.w	14(a0),d0	;HPOTRES
		divu	d0,d5		;numerical position
		and.w	#$f,d5		;only last 4 bits needed
		rts

splitRGB	clr.l	d0
		clr.l	d1
		clr.l	d2
		clr.l	d3
		move.w	col,d0
		ext.l	d0
		asl.l	#1,d0		;get word offset
		move.l	#palette,d1	;get start address of palette
		add.l	d0,d1		;get offset to palette
		move.l	d1,a0
		move.w	(a0),d1		;get RGB value from palette
		move.w	d1,d2
		move.w	d2,d3
		and.w	#$f00,d1	;Get Red
		asr.w	#4,d1
		asr.w	#4,d1		;put into low 4 bits
		and.w	#$f0,d2		;Get Green
		asr.w	#4,d2		;put into low 4 bits
		and.w	#$f,d3		;Get Blue
		rts

setonecolour	movem.l	d0-d3,-(SP)
		move.w	col,d0		;colour to change
		move.l	viewport,a0	;viewport
		move.l	_GfxBase,a6	;gfxbase
		JSR	SetRGB4(a6)	;set colour
		movem.l	(SP)+,d0-d3

writenewRGB	lsl.w	#4,d1
		lsl.w	#4,d1		;get red in right place
		lsl.w	#4,d2		;and green
		move.w	col,d0
		ext.l	d0
		asl.l	#1,d0
		or.w	d2,d3		;combine blue and green
		or.w	d1,d3		;and red
		move.l	#palette,d1	;get palette address
		add.l	d0,d1		;get correct address in palette
		move.l	d1,a0		;store it as an address
		move.w	d3,(a0)		;store new RGB value
		rts

; MENU routines follow

DoMenu	move.l	d3,d0			;transfer menu selection to d0
	move.l	d0,d1			;and d1
	andi.w	#31,d0			;Extract menu number into d0
	lsr.w	#5,d1
	andi.w	#63,d1			;and item number into d1
	tst.w	d0			;Was it the project menu?
	bne.s	NotProjectMenu		;No
	cmp.w	#7,d1			;Was quit selected?
	bne	NotMQuit		;No
	bra	_closedown		;Quit selected, so exit
NotMQuit
	cmp.w	#1,d1			;Open
	bne.s	NotOpen
	bra	openfile
NotOpen	cmp.w	#0,d1			;New
	bne.s	NotNew
	bra	newobj
NotNew	cmp.w	#3,d1			;Save
	bne.s	NotSave
	bra	savefile
NotSave	cmp.w	#6,d1
	bne.s	notabt
	bra	aboutprog
notabt	cmp.w	#4,d1
	bne.s	notsd
	bra	savedatafile
notsd	cmp.w	#2,d1
	bne.s	notoa		;open anim
	bra	openanimfile
notoa	cmp.w	#5,d1
	bne.s	notsaf		;save anim
	bra	saveanimfile
notsaf	bra	wloop

NotProjectMenu
	cmp.w	#1,d0			;Is it palette menu?
	bne.s	NotPaletteMenu
	tst.w	d1			;Copy selected?
	bne.s	NotCopy			;No
	bra	copypalette
NotCopy	cmp.w	#1,d1			;Mix selected?
	bne.s	NotMix			;No
	bra	mixpalette
NotMix	cmp.w	#2,d1			;Range selected?
	bne.s	NotRange		;No
	bra	rangepalette
NotRange cmp.w	#3,d1			;Store selected?
	bne.s	NotStor			;No
	bra	storepalette
NotStor	cmp.w	#4,d1			;Restore selected?
	bne.s	NotReSt			;No
	bra	restorepalette
NotReSt	cmp.w	#5,d1			;Brush selected?
	bne.s	Notbrsh
	bra	loadbrushpal
Notbrsh	bra	wloop

NotPaletteMenu
	cmp.w	#2,d0			;Is it object menu?
	bne.s	NotObjectMenu
	tst.w	d1			;Store?
	bne.s	NotStore		;No
	move.w	#0,d7
	move.b	#0,flag
	bra	storeobject
NotStore
	cmp.w	#4,d1			;Insert
	bne.s	Notins
	bra	insert
Notins	cmp.w	#3,d1			;delete
	bne.s	Notdel
	bra	delete
Notdel	cmp.w	#1,d1
	bne.s	notcopy
	bra	copy
notcopy	cmp.w	#5,d1
	bne.s	notani
	bra	animate
notani	cmp.w	#2,d1		;copy last
	bne.s	notcpyl
	bra	copylast
notcpyl cmp.w	#6,d1		;jump to buffer
	bne.s	notjump
	bra	jumptobuffer
notjump	cmp.w	#7,d1		;jump 1st
	bne.s	notjump1
	bra	jumptofirst
notjump1
	cmp.w	#8,d1		;jump last
	bne.s	notjump2
	bra	jumptolast
notjump2
	bra	wloop

NotObjectMenu
	cmp.w	#3,d0
	bne	wloop		;no known menu
	cmp.w	#0,d1		;scroll left
	bne.s	Notsl
	move.l	#1,d0
	move.l	#0,d1
	bra	doscroll
Notsl	cmp.w	#1,d1		;right
	bne.s	notsr
	move.l	#-1,d0
	move.l	#0,d1
	bra	doscroll
notsr	cmp.w	#2,d1
	bne.s	notsu
	move.l	#0,d0
	move.l	#1,d1
	bra	doscroll
notsu	cmp.w	#3,d1
	bne.s	notsdn
	move.l	#0,d0
	move.l	#-1,d1
	bra	doscroll
notsdn	cmp.w	#4,d1
	bne.s	notfx
	bra	flipx
notfx	cmp.w	#5,d1
	bne.s	notfy
	bra	flipy
notfy
	bra	wloop			;No known menu, so return to wloop

newobj		bsr	clearobject
		move.w	#0,sx
		move.w	#0,sy
		move.w	#16,across
		move.w	#16,widf
		move.w	#16,down
		move.w	#16,height
		move.w	#8,xgap
		move.w	#8,ygap
		bsr	drawgrid
		move.b	#0,picchanged
		bra	wloop

copypalette	bsr	splitRGB	;Get current colours RGB values
		movem.w	d1-d3,-(sp)	;Remember RGB values
		bsr	notinpalette	;Get copy colour
		movem.w	(sp)+,d1-d3	;get RGB values back
		bsr	setonecolour	;and write new RGB
		bsr	drawcols
		bsr	newcolour
		bra	wloop

mixpalette	bsr	splitRGB	;split RGB
		movem.w	d1-d3,-(sp)	;store RGB values
		bsr	notinpalette	;Get colour to mix with
		bsr	splitRGB	;split new RGB
		movem.w	(sp)+,d4-d6	;reload old RGB
		add.w	d4,d1		;average red
		asr.w	#1,d1
		add.w	d5,d2		;average green
		asr.w	#1,d2
		add.w	d6,d3		;average blue
		asr.w	#1,d3
		bsr	setonecolour
		bsr	drawcols
		bsr	newcolour
		bra	wloop

waitforrbutton	btst	#10,$dff016
		bne.s	waitforrbutton
		rts

dohex	andi.b	#$0f,d0
	addi.b	#$30,d0
	cmp.b	#$3a,d0
	blt	hexdone
	add.b	#$07,d0
hexdone	rts

hexword	move.b	d1,d0
	bsr	dohex
	move.b	d0,hexstring+3
	lsr.w	#4,d1
	move.b	d1,d0
	bsr	dohex
	move.b	d0,hexstring+2
	lsr.w	#4,d1
	move.b	d1,d0
	bsr	dohex
	move.b	d0,hexstring+1
	lsr.w	#4,d1
	move.b	d1,d0
	bsr	dohex
	move.b	d0,hexstring
	rts

hexstring	dc.b	'ffff',0
	even

printhex	bsr	hexword
		lea	hexstring,a2
		move.l	d7,d0
		move.l	#100,d1
		move.l	#1,d2
		move.l	#0,d3
		bsr	printtext
		rts

rangepalette	move.w	col,startcol
		bsr	splitRGB
		move.w	d1,startred
		move.w	d2,startgreen
		move.w	d3,startblue

		bsr	notinpalette
		move.w	startcol,d0
		cmp.w	col,d0
		bne.s	different
		bra	wloop

different	move.w	col,endcol
		bsr	splitRGB
		move.w	d1,endred
		move.w	d2,endgreen
		move.w	d3,endblue

		move.w	startcol,d0
		move.w	endcol,d1
		cmp.w	d0,d1
		bgt.s	inorder
		move.w	d1,startcol
		move.w	d0,endcol
		move.w	startred,d0
		move.w	startgreen,d1
		move.w	startblue,d2
		move.w	endred,startred
		move.w	endgreen,startgreen
		move.w	endblue,startblue
		move.w	d0,endred
		move.w	d1,endgreen
		move.w	d2,endblue

inorder		move.w	endcol,d0
		sub.w	startcol,d0
		move.w	d0,number

		move.w	startred,d0
		ext.l	d0
		move.l	_MathBase,a6
		JSR	SpFlt(a6)
		move.l	d0,d2

		move.w	endred,d0
		ext.l	d0
		move.l	_MathBase,a6
		JSR	SpFlt(a6)
		move.l	d0,d1

		move.l	d2,d1
		move.l	_MathBase,a6
		JSR	SpSub(a6)

		move.l	d0,redinc

		move.w	number,d0
		ext.l	d0
		JSR	SpFlt(a6)
		move.l	d0,d1
		move.l	redinc,d0
		JSR	SpDiv(a6)
		move.l	d0,redinc

		move.w	startgreen,d0
		ext.l	d0
		move.l	_MathBase,a6
		JSR	SpFlt(a6)
		move.l	d0,d2

		move.w	endgreen,d0
		ext.l	d0
		move.l	_MathBase,a6
		JSR	SpFlt(a6)
		move.l	d0,d1

		move.l	d2,d1
		move.l	_MathBase,a6
		JSR	SpSub(a6)

		move.l	d0,greeninc

		move.w	number,d0
		ext.l	d0
		JSR	SpFlt(a6)
		move.l	d0,d1
		move.l	greeninc,d0
		JSR	SpDiv(a6)
		move.l	d0,greeninc

		move.w	startblue,d0
		ext.l	d0
		move.l	_MathBase,a6
		JSR	SpFlt(a6)
		move.l	d0,d2

		move.w	endblue,d0
		ext.l	d0
		move.l	_MathBase,a6
		JSR	SpFlt(a6)
		move.l	d0,d1

		move.l	d2,d1
		move.l	_MathBase,a6
		JSR	SpSub(a6)

		move.l	d0,blueinc

		move.w	number,d0
		ext.l	d0
		JSR	SpFlt(a6)
		move.l	d0,d1
		move.l	blueinc,d0
		JSR	SpDiv(a6)
		move.l	d0,blueinc


		move.w	startcol,d2
		add.w	#1,d2
		move.w	d2,col

		move.w	startred,d0
		ext.l	d0
		JSR	SpFlt(a6)
		move.l	d0,d4

		move.w	startgreen,d0
		ext.l	d0
		JSR	SpFlt(a6)
		move.l	d0,d5

		move.w	startblue,d0
		ext.l	d0
		JSR	SpFlt(a6)
		move.l	d0,d6

rangeloop	move.l	d4,d0
		move.l	redinc,d1
		move.l	_MathBase,a6
		JSR	SpAdd(a6)
		move.l	d0,d4
		JSR	SpAbs(a6)
		JSR	SpFix(a6)
		move.w	d0,endred

		move.l	d5,d0
		move.l	greeninc,d1
		move.l	_MathBase,a6
		JSR	SpAdd(a6)
		move.l	d0,d5
		JSR	SpAbs(a6)
		JSR	SpFix(a6)
		move.w	d0,endgreen

		move.l	d6,d0
		move.l	blueinc,d1
		move.l	_MathBase,a6
		JSR	SpAdd(a6)
		move.l	d0,d6
		JSR	SpAbs(a6)
		JSR	SpFix(a6)
		move.w	d0,endblue

		move.w	endred,d1
		move.w	endgreen,d2
		move.w	endblue,d3
		bsr	setonecolour
		add.w	#1,col
		move.w	col,d2
		cmp.w	endcol,d2
		bne	rangeloop

loadpal	move.l	viewport,a0		;save it for later
	lea.l	palette,a1		;palette address
	moveq	#numcols,d0		;number of colours to load
	move.l	_GfxBase,a6		;get graphics base
	JSR		LoadRGB4(a6)	;set palette colours

		bsr	drawcols
		bsr	newcolour
		bra	wloop

storepalette	move.w	#31,d0		;Number of colours
		lea	palette,a0	;Address of working palette
		lea	backuppalette,a1	;Address of backup palette
storeloop	move.w	(a0)+,(a1)+	;copy RGB across
		dbra	d0,storeloop	;do all colours
		bra	wloop

restorepalette	move.w	#31,d0		;Number of colours
		lea	palette,a0	;Address of working palette
		lea	backuppalette,a1	;Address of backup palette
restoreloop	move.w	(a1)+,(a0)+	;copy RGB across
		dbra	d0,restoreloop	;do all colours
		move.l	viewport,a0	;save it for later
		lea.l	palette,a1	;palette address
		moveq	#numcols,d0	;number of colours to load
		move.l	_GfxBase,a6	;get graphics base
		JSR		LoadRGB4(a6)	;set palette colours
		bsr	newcolour	;update sliders
		bra	wloop

loadbrushpal	move.w	#31,d0		;Number of colours
		lea	palette,a0	;Address of working palette
		lea	brushpalette,a1	;Address of brush palette
		lea	backuppalette,a2
brushpalloop	move.w	(a0),(a2)+
		move.w	(a1)+,(a0)+	;copy RGB across
		dbra	d0,brushpalloop	;do all colours
		move.l	viewport,a0	;save it for later
		lea.l	palette,a1	;palette address
		moveq	#numcols,d0	;number of colours to load
		move.l	_GfxBase,a6	;get graphics base
		JSR		LoadRGB4(a6)	;set palette colours
		bsr	newcolour	;update sliders
		bra	wloop


notinpalette	bsr	waitforbutton	;wait to button pressed
		bsr	getmousepos	;get mouse position
		cmp.w	#38,d0		;In palette area?
		blt.s	notinpalette
		cmp.w	#198,d0
		bgt.s	notinpalette
		cmp.w	#158,d1
		blt.s	notinpalette
		move.l	rastport,a1
		move.l	_GfxBase,a6
		JSR	ReadPixel(a6)	;find colour to copy to
		move.w	d0,col
		rts

openfile	move.l	windowbase,a0		;Get windowbase
		move.l	#$ffff,d0		;Specify all menus
		move.l	_IntuitionBase,a6	;Get intuition base
		JSR	OffMenu(a6)		;Activate menus

		lea	wtitle,a0
		move.l	#title2,(a0)

		lea	newwindow2,a0
		move.l	scrnbase,d0
		move.l	d0,30(a0)
		move.l	_IntuitionBase,a6
		JSR	OpenWindow(a6)
		move.l	d0,windowbase2
		tst.l	d0
		bne.s	windowopened
		bra	wloop

windowopened	lea	strgadget,a0		;Get address of gadget structure
		move.l	windowbase2,a1		;get window base
		move.l	_IntuitionBase,a6	;get intuition base
		JSR	RefreshGadgets(a6)	;Refresh gadgets

		move.l	strgadget,a0
		move.l	_IntuitionBase,a6
		JSR	ActivateGadget(a6)

	move.l	windowbase2,a0		;Use window base
	move.l	$56(a0),userport2	;Save window's userport

owloop	move.l	userport2,a0		;Get windows userport
	CALLEXEC	WaitPort	;Call waitport
	move.l	userport2,a0		;Get userport again
	CALLEXEC	GetMsg		;Get IDCMP message (if any)
	tst.l	d0			;Was there a message?
	beq.s	owloop			;No, so loop back
	move.l	d0,a1			;Get address of message
	move.l	20(a1),d2	;Im.class (contains type of message. e.g. CLOSEWINDOW,GADGETUP)
	move.w	24(a1),d3	;Im.code (contains menu selection numbers etc.)
	move.w	26(a1),d4	;Im.qualifier (keyboard info lives here)
	CALLEXEC	ReplyMsg	;Say ta to intuition
	move.l	(a0),a0			;Get message pointer in a0

	cmp.l	#$40,d2			;check class for GADGETUP
	bne.s	owloop			;If yes, nip on to next bit

	move.l	28(a0),a0		;Get address of hit gadget
	move.w	38(a0),d0		;Get id of gadget
	move.w	d0,form
	cmp.w	#11,d0		;Cancel?
	beq.s	doneopen
	cmp.w	#12,d0		;OK?
	beq.s	doneopen
	cmp.w	#13,d0
	bne.s	owloop

doneopen	move.l	windowbase2,a0
		move.l	_IntuitionBase,a6
		JSR	CloseWindow(a6)

		move.w	form,d0
		cmp.w	#11,d0
		beq.s	cancels
		cmp.w	#13,d0
		beq.s	dorawbit
		bsr	loadbrush
		bra.s	cancels
dorawbit	bsr	openrawobj
cancels		bsr	drawgrid
		bsr	redraw

	move.l	windowbase,a0		;Get windowbase
	move.l	#$ffff,d0		;Specify all menus
	move.l	_IntuitionBase,a6	;Get intuition base
	JSR	OnMenu(a6)		;Activate menus

		bra	wloop

savefile	move.l	windowbase,a0		;Get windowbase
		move.l	#$ffff,d0		;Specify all menus
		move.l	_IntuitionBase,a6	;Get intuition base
		JSR	OffMenu(a6)		;Activate menus

		lea	wtitle,a0
		move.l	#title3,(a0)

		lea	newwindow2,a0
		move.l	scrnbase,d0
		move.l	d0,30(a0)
		move.l	_IntuitionBase,a6
		JSR	OpenWindow(a6)
		move.l	d0,windowbase2
		tst.l	d0
		bne.s	swindowopened
		bra	wloop

swindowopened	lea	strgadget,a0		;Get address of gadget structure
		move.l	windowbase2,a1		;get window base
		move.l	_IntuitionBase,a6	;get intuition base
		JSR	RefreshGadgets(a6)	;Refresh gadgets

		move.l	strgadget,a0
		move.l	_IntuitionBase,a6
		JSR	ActivateGadget(a6)

	move.l	windowbase2,a0		;Use window base
	move.l	$56(a0),userport2	;Save window's userport

sowloop	move.l	userport2,a0		;Get windows userport
	CALLEXEC	WaitPort	;Call waitport
	move.l	userport2,a0		;Get userport again
	CALLEXEC	GetMsg		;Get IDCMP message (if any)
	tst.l	d0			;Was there a message?
	beq.s	sowloop			;No, so loop back
	move.l	d0,a1			;Get address of message
	move.l	20(a1),d2	;Im.class (contains type of message. e.g. CLOSEWINDOW,GADGETUP)
	move.w	24(a1),d3	;Im.code (contains menu selection numbers etc.)
	move.w	26(a1),d4	;Im.qualifier (keyboard info lives here)
	CALLEXEC	ReplyMsg	;Say ta to intuition
	move.l	(a0),a0			;Get message pointer in a0

	cmp.l	#$40,d2			;check class for GADGETUP
	bne.s	sowloop			;If yes, nip on to next bit

	move.l	28(a0),a0		;Get address of hit gadget
	move.w	38(a0),d0		;Get id of gadget
	move.w	d0,form
	cmp.w	#11,d0		;Cancel?
	beq.s	donesave
	cmp.w	#12,d0		;OK?
	beq.s	donesave
	cmp.w	#13,d0
	bne.s	sowloop

donesave	move.l	windowbase2,a0
		move.l	_IntuitionBase,a6
		JSR	CloseWindow(a6)


		move.w	form,d0
		cmp.w	#11,d0
		beq.s	scancels
		cmp.w	#12,d0
		bne.s	saveraw
		bsr	savebrush
		bra.s	scancels

saveraw		bsr	saverawobj

scancels	bsr	drawgrid
		bsr	redraw

	move.l	windowbase,a0		;Get windowbase
	move.l	#$ffff,d0		;Specify all menus
	move.l	_IntuitionBase,a6	;Get intuition base
	JSR	OnMenu(a6)		;Activate menus

		bra	wloop

saverawobj	bsr	workoutxw
rnotasmallone	move.l	#stringtext,d1
		move.l	#MODE_NEWFILE,d2
		move.l	_DosBase,a6
		JSR	Open(a6)
		tst.l	d0
		beq	rcantopen
		move.l	d0,filehandle

		lea	form,a0
		move.w	widf,(a0)+
		move.w	height,(a0)+
		move.w	#5,(a0)+

		move.l	filehandle,d1
		move.l	#form,d2
		move.l	#6,d3
		move.l	_DosBase,a6
		JSR	Write(a6)

		bsr	saverawbody

		move.l	#150,d1
		move.l	_DosBase,a6
		JSR	Delay(a6)
		move.l	filehandle,d1	;pointer to file
		move.l	_DosBase,a6	;dos.library
		JSR	Close(a6)	;close file

		cmp.b	#1,icons
		bne.s	src

		move.l	#rawbrushsize,form+4
		lea	rawbrushinfo,a0
		move.l	a0,d0
		move.l	d0,form
		bsr	makeinfoname

src		rts			;and exit

rcantopen	lea	error12,a2
		move.l	a2,form+4
		bsr	errorreport
		rts

saverawbody	move.w	xw,d0
		mulu	height,d0
		mulu	#5,d0
		add.w	#10,d0
		ext.l	d0
		move.l	d0,size
		move.l	#$10001,d1	;public, and cleared
		CALLEXEC	AllocMem	;allocmem
		tst.l	d0
		bne.s	roksofar
		rts
roksofar	move.l	d0,MemfBase
		move.l	MemfBase,a3

		bsr	getbody

		move.l	size,d3
		move.l	filehandle,d1
		move.l	MemfBase,d2
		move.l	_DosBase,a6
		JSR	Write(a6)

		move.l	size,d0
		move.l	MemfBase,a1
		CALLEXEC	FreeMem	;deallocatemem

		rts

openrawobj	move.l	#stringtext,d1
		move.l	#MODE_OLDFILE,d2
		move.l	_DosBase,a6
		JSR	Open(a6)
		tst.l	d0
		beq	orcantopen
		move.l	d0,filehandle

		move.l	filehandle,d1
		move.l	#form,d2
		move.l	#6,d3
		move.l	_DosBase,a6
		JSR	Read(a6)

		lea	form,a0
		move.w	(a0)+,bwidf

		cmp.w	#112,bwidf
		ble.s	orwidfok

		lea	error7,a2
		move.l	a2,form+4
		bsr	errorreport
		bra	orcloseup

orwidfok	move.w	(a0)+,bheight
		cmp.w	#120,bheight
		ble.s	orheightok

		lea	error8,a2
		move.l	a2,form+4
		bsr	errorreport
		bra	orcloseup

orheightok	move.w	(a0)+,bdepth
		cmp.w	#5,bdepth
		beq	ordepthok

		lea	error9,a2
		move.l	a2,form+4
		bsr	errorreport
		bra	orcloseup

ordepthok	move.w	bdepth,depth
		move.w	bwidf,widf
		move.w	bheight,height

		bsr	workoutxw
ornotasmallone	bsr	openrawbody

orcloseup	move.l	#150,d1
		move.l	_DosBase,a6
		JSR	Delay(a6)
		move.l	filehandle,d1	;pointer to file
		move.l	_DosBase,a6	;dos.library
		JSR	Close(a6)	;close file

		move.w	#0,d0
		bsr	setcolour
		move.w	#144,d0
		add.w	widf,d0
		move.w	#12,d1
		move.w	#270,d2
		move.w	#142,d3
		move.l	#1,d4
		bsr	rectangle
		move.w	#144,d0
		move.w	#12,d1
		add.w	height,d1
		move.w	#270,d2
		move.w	#142,d3
		bsr	rectangle
		bsr	cleargrid
		bsr	drawgrid
		bsr	redraw
		move.w	#0,sx
		move.w	#0,sy
		rts			;and exit

orcantopen	lea	error12,a2
		move.l	a2,form+4
		bsr	errorreport
		rts

openrawbody	move.w	xw,d0
		mulu	height,d0
		mulu	#5,d0
		add.w	#10,d0
		ext.l	d0
		move.l	d0,form
		move.l	#$10001,d1	;public, and cleared
		CALLEXEC	AllocMem	;allocmem
		tst.l	d0
		bne.s	oroksofar
		rts
oroksofar	move.l	d0,MemfBase

		move.l	form,d3
		move.l	filehandle,d1
		move.l	MemfBase,d2
		move.l	_DosBase,a6
		JSR	Read(a6)

		move.l	MemfBase,a0
justopen
		move.w	#0,d4	;row
		move.w	#0,d5	;plane
		move.w	#0,d6	;column

onextrow	bsr	workoutpos
onextbyte	move.b	(a0)+,(a1)+
		add.w	#1,d6
		cmp.w	xw,d6
		bne.s	onextbyte
		move.w	#0,d6
		add.w	#1,d4
		cmp.w	height,d4
		bne.s	onextrow
		move.w	#0,d4
		add.w	#1,d5
		cmp.w	#5,d5
		bne.s	onextrow
		cmp.w	#1,d7
		bne.s	dea
		rts

dea		move.l	form,d0
		move.l	MemfBase,a1
		CALLEXEC	FreeMem	;deallocatemem

		rts

savedatafile	move.l	windowbase,a0		;Get windowbase
		move.l	#$ffff,d0		;Specify all menus
		move.l	_IntuitionBase,a6	;Get intuition base
		JSR	OffMenu(a6)		;Activate menus

		lea	wtitle,a0
		move.l	#sdtitle,(a0)
		move.w	#36,width2
		move.w	#36,width3
		move.w	#36,buttonlines2+4
		move.w	#36,buttonlines2+8
		move.w	#36,buttonlines3+4
		move.w	#36,buttonlines3+8
		move.w	#272,gx2
		move.w	#228,gx3
		move.l	#text1,d0
		move.l	d0,gtext2
		move.l	#text2,d0
		move.l	d0,g3title

		lea	newwindow2,a0
		move.l	scrnbase,d0
		move.l	d0,30(a0)
		move.l	_IntuitionBase,a6
		JSR	OpenWindow(a6)
		move.l	d0,windowbase2
		tst.l	d0
		bne.s	twindowopened
		bra	wloop

twindowopened	lea	strgadget,a0		;Get address of gadget structure
		move.l	windowbase2,a1		;get window base
		move.l	_IntuitionBase,a6	;get intuition base
		JSR	RefreshGadgets(a6)	;Refresh gadgets

		move.l	strgadget,a0
		move.l	_IntuitionBase,a6
		JSR	ActivateGadget(a6)

	move.l	windowbase2,a0		;Use window base
	move.l	$56(a0),userport2	;Save window's userport

towloop	move.l	userport2,a0		;Get windows userport
	CALLEXEC	WaitPort	;Call waitport
	move.l	userport2,a0		;Get userport again
	CALLEXEC	GetMsg		;Get IDCMP message (if any)
	tst.l	d0			;Was there a message?
	beq.s	towloop			;No, so loop back
	move.l	d0,a1			;Get address of message
	move.l	20(a1),d2	;Im.class (contains type of message. e.g. CLOSEWINDOW,GADGETUP)
	move.w	24(a1),d3	;Im.code (contains menu selection numbers etc.)
	move.w	26(a1),d4	;Im.qualifier (keyboard info lives here)
	CALLEXEC	ReplyMsg	;Say ta to intuition
	move.l	(a0),a0			;Get message pointer in a0

	cmp.l	#$40,d2			;check class for GADGETUP
	bne.s	towloop			;If yes, nip on to next bit

	move.l	28(a0),a0		;Get address of hit gadget
	move.w	38(a0),d0		;Get id of gadget
	move.w	d0,form
	cmp.w	#11,d0		;Cancel?
	beq.s	dosavedata
	cmp.w	#12,d0		;OK?
	beq.s	dosavedata
	cmp.w	#13,d0
	bne.s	towloop

dosavedata	move.w	d0,form
		move.l	windowbase2,a0
		move.l	_IntuitionBase,a6
		JSR	CloseWindow(a6)

		move.w	#28,width2
		move.w	#28,width3
		move.w	#28,buttonlines2+4
		move.w	#28,buttonlines2+8
		move.w	#28,buttonlines3+4
		move.w	#28,buttonlines3+8
		move.w	#280,gx2
		move.w	#244,gx3
		move.l	#gadg2text,d1
		move.l	d1,gtext2
		move.l	#gadg3text,d1
		move.l	d1,g3title

		cmp.w	#11,form
		bne.s	dosavedata3
		move.l	windowbase,a0		;Get windowbase
		move.l	#$ffff,d0		;Specify all menus
		move.l	_IntuitionBase,a6	;Get intuition base
		JSR	OnMenu(a6)		;Activate menus

		bra	wloop

dosavedata3	cmp.w	#12,form
		bne.s	notdcb
		move.l	#'dc.w',d7
		bra	dosavedata2
notdcb		move.l	#'data',d7

dosavedata2	bsr	workoutxw

		move.l	#stringtext,d1
		move.l	#MODE_NEWFILE,d2
		move.l	_DosBase,a6
		JSR	Open(a6)
		tst.l	d0
		beq	canneeopen
		move.l	d0,filehandle

		clr.l	d4
		clr.l	d5
		clr.l	d6
		move.w	#0,d4	;row
		move.b	#0,d5	;plane
		move.w	#0,d6	;column
		move.w	#0,d3	;size of text
nextrowdata	lea	form,a0

makeuparow	move.w	#'  ',(a0)+
		move.l	d7,(a0)+
		move.w	#'  ',(a0)+
		move.w	#8,d3
		bsr	workoutpos

newword		clr.l	d1
		move.w	(a1)+,d1
		bsr	hexword
		lea	hexstring,a2

		cmp.l	#'data',d7
		beq.s	putinah
		move.w	#' $',(a0)+
		bra.s	doneprefix
putinah		move.w	#'&h',(a0)+
doneprefix	add.w	#2,d3
		move.l	(a2),(a0)+
		add.w	#4,d3

		add.w	#2,d6
		cmp.w	xw,d6
		beq.s	finishedline
		move.w	#', ',(a0)+
		add.w	#2,d3
		bra.s	newword

finishedline	move.b	#10,(a0)+
		add.w	#1,d4
		cmp.w	height,d4
		bne.s	dontaddline
		move.b	#10,(a0)+
		add.w	#1,d3

dontaddline	move.b	#0,(a0)+
		add.w	#1,d3
		ext.l	d3
		move.l	filehandle,d1
		move.l	#form,d2
		move.l	_DosBase,a6
		JSR	Write(a6)

		move.w	#0,d6
		move.w	#0,d3

		cmp.w	height,d4
		bne	nextrowdata

		move.w	#0,d4
		add.b	#1,d5
		cmp.b	#5,d5
		bne	nextrowdata

cmapdata	lea	form,a0
		move.l	#';Col',(a0)+
		move.l	#'our ',(a0)+
		move.l	#'Data',(a0)+
		move.l	#$0a0a0000,(a0)+
		move.l	#14,d3
		move.l	filehandle,d1
		move.l	#form,d2
		move.l	_DosBase,a6
		JSR	Write(a6)

		move.w	#0,d4
		move.w	#0,d3
		move.w	#0,d6
		lea	palette,a3
nextcmapdata	lea	form,a0

makeuparowd	move.w	#'  ',(a0)+
		move.l	d7,(a0)+
		move.w	#'  ',(a0)+
		move.w	#8,d3

newwordd	clr.l	d1
		move.w	(a3)+,d1
		bsr	hexword
		lea	hexstring,a2

		cmp.l	#'data',d7
		beq.s	putinahd
		move.w	#' $',(a0)+
		bra.s	doneprefixd
putinahd	move.w	#'&h',(a0)+
doneprefixd	add.w	#2,d3
		move.l	(a2),(a0)+
		add.w	#4,d3

		add.w	#1,d6
		cmp.w	#8,d6
		beq.s	finisheddline
		move.w	#', ',(a0)+
		add.w	#2,d3
		bra.s	newwordd

finisheddline	move.b	#10,(a0)+
		add.w	#1,d4
		move.b	#0,(a0)+
		add.w	#1,d3
		ext.l	d3
		move.l	filehandle,d1
		move.l	#form,d2
		move.l	_DosBase,a6
		JSR	Write(a6)

		move.w	#0,d6
		move.w	#0,d3

		cmp.w	#4,d4
		bne	nextcmapdata

		move.l	#150,d1
		move.l	_DosBase,a6
		JSR	Delay(a6)
		move.l	filehandle,d1	;pointer to file
		move.l	_DosBase,a6	;dos.library
		JSR	Close(a6)	;close file

		cmp.b	#1,icons
		bne.s	reenablemenus

		move.l	#datasize,form+4
		move.l	#datainfo,form
		bsr	makeinfoname

		bra.s	reenablemenus

canneeopen	lea	error12,a2
		move.l	a2,form+4
		bsr	errorreport

reenablemenus	move.l	windowbase,a0		;Get windowbase
		move.l	#$ffff,d0		;Specify all menus
		move.l	_IntuitionBase,a6	;Get intuition base
		JSR	OnMenu(a6)		;Activate menus

donesavedata	bra	wloop

DoMouse	bsr	getmousepos
	cmp.w	#38,d0
	blt.s	notcol
	cmp.w	#198,d0
	bgt.s	notcol
	cmp.w	#158,d1
	blt.s	notcol
	move.w	col,d7
	bsr	clearcol
	bsr	getmousepos
	move.l	rastport,a1
	move.l	_GfxBase,a6
	JSR	ReadPixel(a6)
	move.w	d0,col
	move.w	#1,d7
	bsr	clearcol
	bsr	newcolour
	bra	wloop
notcol	cmp.w	#10,d0
	blt.s	notgrid
	cmp.w	#10,d1
	blt.s	notgrid
	cmp.w	fx,d0
	bge.s	notgrid
	cmp.w	fy,d1
	bge.s	notgrid
	bsr	ingrid
	bsr	getmousepos
	btst	#6,$bfe001	;button still in?
	beq.s	notcol
notgrid	cmp.w	#10,d0		;in colour register?
	blt.s	notpick
	cmp.w	#30,d0
	bgt.s	notpick
	cmp.w	#158,d1
	blt.s	notpick
	bsr	pickcolour
notpick	bra	wloop

pickcolour	btst	#6,$bfe001
		beq.s	pickcolour

		move.w	col,d7
		bsr	clearcol

		bsr	waitforbutton
		bsr	getmousepos
		move.l	rastport,a1
		move.l	_GfxBase,a6
		JSR	ReadPixel(a6)
		move.w	d0,col

		move.w	#1,d7
		bsr	clearcol

		bsr	newcolour
		rts

DoKeys		cmp.w	#$4e,d3
		bne.s	notrightarrow
		move.w	widf,d4
		sub.w	sx,d4
		cmp.w	across,d4
		beq.s	doner
		add.w	#1,sx
		bsr	redraw
doner		bra	wloop
		
notrightarrow	cmp.w	#$4f,d3
		bne.s	notleftarrow
		cmp.w	#0,sx
		beq.s	donel
		sub.w	#1,sx
		bsr	redraw
donel		bra	wloop

notleftarrow	cmp.w	#$4d,d3
		bne.s	notdownarrow
		move.w	height,d4
		sub.w	sy,d4
		cmp.w	down,d4
		beq.s	doned
		add.w	#1,sy
		bsr	redraw
doned		bra	wloop

notdownarrow	cmp.w	#$4c,d3
		bne.s	notuparrow
		cmp.w	#0,sy
		beq.s	doneu
		sub.w	#1,sy
doneu		bsr	redraw
		bra	wloop

notuparrow	cmp.w	#$2f,d3
		bne.s	notsrightarrow
		move.w	sx,d5
		add.w	#8,d5
		move.w	widf,d4
		sub.w	d5,d4
		cmp.w	across,d4
		bhs.s	donesr
		move.w	widf,d5
		sub.w	across,d5
donesr		move.w	d5,sx
		bsr	redraw
		bra	wloop

notsrightarrow	cmp.w	#$2d,d3
		bne.s	notsleftarrow
		move.w	sx,d5
		sub.w	#8,d5
		tst.w	d5
		bpl.s	donesl
		move.w	#0,d5
donesl		move.w	d5,sx
		bsr	redraw
		bra	wloop

notsleftarrow	cmp.w	#$1e,d3
		bne.s	notsdownarrow
		move.w	sy,d5
		add.w	#8,d5
		move.w	height,d4
		sub.w	d5,d4
		cmp.w	down,d4
		bhs.s	donesd
		move.w	height,d5
		sub.w	down,d5
donesd		move.w	d5,sy
		bsr	redraw
		bra	wloop

notsdownarrow	cmp.w	#$3e,d3
		bne.s	notsuparrow
		move.w	sy,d5
		sub.w	#8,d5
		tst.w	d5
		bpl.s	donesu
		move.w	#0,d5
donesu		move.w	d5,sy
		bsr	redraw
		bra	wloop

notsuparrow	cmp.w	#$50,d3
		bne.w	notf1
		cmp.w	#2,xgap
		beq.w	donef1
		move.w	across,d4
		asl.w	#1,d4
		move.w	d4,across
		move.w	xgap,d4
		asr.w	#1,d4
		move.w	d4,xgap
		move.w	down,d4
		asl.w	#1,d4
		move.w	d4,down
		move.w	ygap,d4
		asr.w	#1,d4
		move.w	d4,ygap

		bsr	cleargrid
		bsr	drawgrid

		move.w	widf,d4
		sub.w	across,d4
		cmp.w	sx,d4
		bhs.s	dontchangex
		move.w	d4,sx

dontchangex	move.w	height,d4
		sub.w	down,d4
		cmp.w	sy,d4
		bhs.s	dontchangey
		move.w	d4,sy
dontchangey	bsr	redraw
donef1		bra	wloop

notf1		cmp.w	#$51,d3
		bne.s	notf2
		cmp.w	#16,xgap
		beq.s	donef2
		move.w	across,d4
		asr.w	#1,d4
		move.w	d4,across
		move.w	xgap,d4
		asl.w	#1,d4
		move.w	d4,xgap
		move.w	down,d4
		asr.w	#1,d4
		move.w	d4,down
		move.w	ygap,d4
		asl.w	#1,d4
		move.w	d4,ygap
		bsr	cleargrid
		bsr	drawgrid
		bsr	redraw
donef2		bra	wloop

notf2		cmp.w	#$52,d3
		bne.s	notf3
		bchg.b	#0,gridcol
		bsr	drawgrid
		bra	wloop

notf3		cmp.w	#$53,d3
		bne.s	notf4
		cmp.w	#112,widf
		beq.s	quitf3
		add.w	#1,widf
		bsr	newdimensions
quitf3		bra	wloop

notf4		cmp.w	#$54,d3
		bne.s	notf5
		cmp.w	#1,widf
		beq.s	quitf4
		sub.w	#1,widf
		bsr	newdimensions
quitf4		bra	wloop

notf5		cmp.w	#$55,d3
		bne.s	notf6
		cmp.w	#120,height
		beq.s	quitf6
		add.w	#1,height
		bsr	newdimensions
quitf6		bra	wloop

notf6		cmp.w	#$56,d3
		bne.s	notf7
		cmp.w	#1,height
		beq.s	quitf7
		sub.w	#1,height
		bsr	newdimensions
quitf7		bra	wloop

notf7		cmp.w	#$5f,d3
		bne.s	nothelp
		move.w	#0,d0
		bsr	setcolour
		move.w	#144,d0
		add.w	widf,d0
		move.w	#12,d1
		move.w	#270,d2
		move.w	#142,d3
		move.l	#1,d4
		bsr	rectangle
		move.w	#144,d0
		move.w	#12,d1
		add.w	height,d1
		move.w	#270,d2
		move.w	#142,d3
		bsr	rectangle
		bsr	cleargrid
		bsr	drawgrid
		bsr	redraw
		move.w	#0,sx
		move.w	#0,sy
		bra	wloop

nothelp		cmp.w	#$38,d3
		bne	notlessthan
		move.b	#1,flag
		move.w	objectnumber,d0
		cmp.w	#1,d0
		bne.s	twiddlybit
		move.b	#0,flag
		bra	wloop
twiddlybit	cmp.w	objecttotal,d0
		bne.s	notwholething
		move.w	#1,d7
		bsr	storeobject
		sub.w	#1,objectnumber	;take care of adding in storeobject
		cmp.b	#0,picchanged
		bne	donestorage
		cmp.b	#1,flag
		bne	blagher
		add.w	#1,objectnumber
		bra	donestorage
blagher		sub.w	#1,objecttotal
		bra	donestorage
notwholething	move.w	#1,d7
		move.b	#0,flag

		move.w	objectnumber,d2
		sub.w	#1,d2
		mulu	#4,d2
		and.l	#$ffff,d2
		move.l	#objectmem,d3
		ext.l	d2
		add.l	d2,d3
		move.l	d3,a3
		move.l	(a3),a3		;address
		bsr	juststore

donestorage	bsr	clearobject
		sub.w	#1,objectnumber
		move.w	objectnumber,d2
		sub.w	#1,d2
		mulu	#4,d2
		and.l	#$ffff,d2
		move.l	#objectmem,d3
		ext.l	d2
		add.l	d2,d3
		move.l	d3,a3
		move.l	(a3),a0		;address
		move.w	#0,widf
		move.w	#0,height
		move.w	(a0)+,widf
		move.w	(a0)+,height
		and.w	#$ff,widf
		and.w	#$ff,height
		bsr	workoutxw
		bsr	justopen
		;move.w	#0,sx
		;move.w	#0,sy
		clr.l	d2
		clr.l	d3
		clr.l	d4
		bsr	drawgrid
		bsr	redraw
		move.b	#0,flag
		bra	wloop

notlessthan	cmp.w	#$39,d3
		bne	notbigthan
		move.w	objectnumber,d0
		cmp.w	objecttotal,d0
		beq	wloop
		move.w	objecttotal,d1
		sub.w	#1,d1
		cmp.w	d0,d1
		bne.s	notlastone

		move.w	objectnumber,d2
		sub.w	#1,d2
		mulu	#4,d2
		and.l	#$ffff,d2
		move.l	#objectmem,d3
		ext.l	d2
		add.l	d2,d3
		move.l	d3,a3
		move.l	(a3),a3		;address
		bsr	workoutxw
		move.w	#1,d7
		bsr	juststore

		add.w	#1,objectnumber
		bra	newobj

notlastone	move.w	objectnumber,d2
		sub.w	#1,d2
		mulu	#4,d2
		and.l	#$ffff,d2
		move.l	#objectmem,d3
		ext.l	d2
		add.l	d2,d3
		move.l	d3,a3
		move.l	(a3),a3		;address
		bsr	workoutxw
		move.w	#1,d7
		bsr	juststore
		add.w	#1,objectnumber

		bsr	clearobject
		move.w	objectnumber,d2
		sub.w	#1,d2
		mulu	#4,d2
		and.l	#$ffff,d2
		move.l	#objectmem,d3
		ext.l	d2
		add.l	d2,d3
		move.l	d3,a3
		move.l	(a3),a0		;address
		move.w	#0,widf
		move.w	#0,height
		move.w	(a0)+,widf
		move.w	(a0)+,height
		and.w	#$ff,widf
		and.w	#$ff,height
		bsr	workoutxw
		move.w	#1,d7
		bsr	justopen
		clr.l	d2
		clr.l	d3
		clr.l	d4
		;move.w	#0,sx
		;move.w	#0,sy
		bsr	drawgrid
		bsr	redraw
		bra	wloop

notbigthan	cmp.w	#$59,d3
		bne.s	notf10
		move.w	objectnumber,objectbuffer
		bsr	newdimensions
		bra	wloop

notf10		cmp.w	#$58,d3
		bne.s	notf9
		bchg.b	#0,icons
		lea	icontext,a2
		move.l	#276,d0
		move.l	#100,d1
		move.b	icons,d2
		ext.w	d2
		ext.l	d2
		move.l	#0,d3
		bsr	printtext
		bra	wloop

notf9		bra	wloop

clearobject	move.w	#0,d0
		bsr	setcolour
		move.l	#0,d0
		move.l	#0,d1
		move.l	#150,d3
		move.l	#270,d2
		move.l	#1,d4
		bsr	rectangle
		move.w	col,d0
		bsr	setcolour
		rts

cleargrid	move.w	#0,d0
		bsr	setcolour
		move.w	#0,d0
		move.w	#0,d1
		move.w	#150,d3
		move.w	#140,d2
		move.l	#1,d4
		bsr	rectangle
		move.w	col,d0
		bsr	setcolour
		rts

storeobject	move.w	objecttotal,d0
		cmp.w	#255,d0
		bne.s	so2

		lea	error11,a2
		move.l	a2,form+4
		bsr	errorreport
		cmp.b	#1,d7
		bne	wloop
		rts

so2		move.w	objectnumber,d1
		cmp.w	d0,d1
		beq.s	attheend

		move.w	objectnumber,d2
		sub.w	#1,d2
		mulu	#4,d2
		and.l	#$ffff,d2
		move.l	#objectmem,d3
		ext.l	d2
		add.l	d2,d3
		move.l	d3,a3
		move.l	(a3),a3		;address

		move.w	widf,(a3)+
		move.w	height,(a3)+
		bsr	getbody
		cmp.w	#1,d7
		bne.s	fbranchhome
		rts
fbranchhome	bra	wloop

attheend	bsr	workoutxw

		lea	rememberkey,a0
		move.l	#8404,d0	;enough for 112x120 brush
		move.l	#$10001,d1
		move.l	_IntuitionBase,a6
		JSR	AllocRemember(a6)

		tst.l	d0
		bne.s	enoughmem
		cmp.b	#1,flag		;flag=1 < pressed
		bne.s	displayerror
		rts

displayerror	lea	error13,a2
		move.l	a2,form+4
		bsr	errorreport
		move.b	#0,flag
		bra	wloop

enoughmem	move.w	objectnumber,d2
		sub.w	#1,d2
		mulu	#4,d2
		and.l	#$ffff,d2
		move.l	#objectmem,d3
		ext.l	d2
		add.l	d2,d3
		move.l	d3,a3
		move.l	d0,(a3)+	;address

		add.w	#1,objecttotal
		move.w	objecttotal,d1
		move.w	d1,objectnumber

		move.l	d0,a3
juststore	move.w	widf,(a3)+
		move.w	height,(a3)+
		bsr	getbody
		cmp.w	#1,d7
		bne.s	branchhome
		move.b	#0,flag
		rts
branchhome	bra	newobj

workoutxw	clr.l	d0
		move.w	d0,xw
		move.w	widf,d0
		and.w	#$ff,d0
		asr.w	#3,d0
		move.w	d0,xw

		move.w	widf,d1
		and.w	#7,d1
		tst.w	d1
		beq.s	wxawhole
		add.w	#1,xw
		add.w	#1,d0

wxawhole	btst	#0,d0
		beq.s	wxaitseven
		add.w	#1,xw
wxaitseven	cmp.w	#0,xw
		bne.s	wxanotasmallone
		move.w	#2,xw
wxanotasmallone	movem.l	d0-d7/a0-a6,-(sp)
		move.w	xw,d2
		move.l	#280,d0
		move.l	#100,d1
		;bsr	printdecimal
		movem.l	(sp)+,d0-d7/a0-a6
		rts

getbody		clr.l	d4
		clr.l	d5
		clr.l	d6

		move.w	#0,d4	;row
		move.w	#0,d5	;plane
		move.w	#0,d6	;column

nextrow		bsr	workoutpos
nextbyte	move.b	(a1)+,(a3)+
		add.w	#1,d6
		cmp.w	xw,d6
		bne.s	nextbyte
		move.w	#0,d6
		add.w	#1,d4
		cmp.w	height,d4
		bne.s	nextrow
		move.w	#0,d4
		add.w	#1,d5
		cmp.w	#5,d5
		bne.s	nextrow
		rts

insert		move.w	objectnumber,d0
		cmp.w	objecttotal,d0
		beq	wloop

		lea	rememberkey,a0
		move.l	#8404,d0	;enough for 112x120 brush
		move.l	#$10001,d1
		move.l	_IntuitionBase,a6
		JSR	AllocRemember(a6)
		move.l	d0,form
		tst.l	d0
		bne.s	insertmem
		bra	wloop

insertmem	move.w	objectnumber,d2
		sub.w	#1,d2
		mulu	#4,d2
		and.l	#$ffff,d2
		move.l	#objectmem,d3
		ext.l	d2
		add.l	d2,d3
		move.l	d3,a5

		move.l	(a5),a3
		move.w	#1,d7
		bsr	workoutxw
		bsr	juststore

		move.w	objecttotal,d2
		sub.w	#1,d2
		mulu	#4,d2
		and.l	#$ffff,d2
		move.l	#objectmem,d3
		ext.l	d2
		add.l	d2,d3
		add.l	#4,d3
		move.l	d3,a2	;source
		add.l	#4,d3
		move.l	d3,a4	;dest

		move.w	objecttotal,d1
		add.w	#1,d1
nextaddressmove	move.l	-(a2),-(a4)
		sub.w	#1,d1
		cmp.w	objectnumber,d1
		bne.s	nextaddressmove
		add.w	#1,objecttotal
		move.l	form,(a5)

		bra	newobj

delete		move.w	objecttotal,d0
		cmp.w	objectnumber,d0
		beq	wloop
		cmp.w	#1,d0
		beq	wloop

		bsr	clearobject
		move.w	objectnumber,d2
		sub.w	#1,d2
		mulu	#4,d2
		and.l	#$ffff,d2
		move.l	#objectmem,d3
		ext.l	d2
		add.l	d2,d3
		move.l	d3,a0
		move.l	(a0),d1		;remember address
		add.l	#4,d3
		move.l	d3,a1
		move.w	objectnumber,d0
deladdressmove	move.l	(a1)+,(a0)+
		add.w	#1,d0
		cmp.w	objecttotal,d0
		bne.s	deladdressmove
		move.l	a0,d2
		sub.w	#4,d2
		move.l	d2,a0
		move.l	d1,(a0)		;store 'deleted' object

		move.l	d1,a4
		move.w	#16,(a4)+	;new widf
		move.w	#16,(a4)+	;new height
		move.w	#2099,d0
clearloop	move.l	#0,(a4)+
		dbra	d0,clearloop

		sub.l	#4,d3
		move.l	d3,a0
		move.l	(a0),a0
		move.w	(a0)+,widf
		move.w	(a0)+,height
		bsr	workoutxw
		move.w	#1,d7
		bsr	justopen
		clr.l	d2
		clr.l	d3
		clr.l	d4
		move.w	#0,sx
		move.w	#0,sy
		bsr	drawgrid
		bsr	redraw
		bra	wloop

copy		move.w	objectnumber,d0
		cmp.w	objectbuffer,d0
		beq	wloop

		bsr	clearobject
		move.w	objectbuffer,d2
		sub.w	#1,d2
		mulu	#4,d2
		and.l	#$ffff,d2
		move.l	#objectmem,d3
		ext.l	d2
		add.l	d2,d3
		move.l	d3,a0
		move.l	(a0),a0		;remember address

nottoworry	move.w	(a0)+,widf
		move.w	(a0)+,height
		bsr	workoutxw
		move.w	#1,d7
		bsr	justopen
		clr.l	d2
		clr.l	d3
		clr.l	d4
		move.w	#0,sx
		move.w	#0,sy
		bsr	drawgrid
		bsr	redraw
		move.b	#1,picchanged
		bra	wloop

clearcol	move.w	d7,d0
		cmp.w	#0,d0
		bne.s	ccl
		move.w	#1,d0
ccl		bsr	setcolour
		move.l	#158,d1		;y0
		move.l	#174,d3		;y1
		move.w	col,d0		;colour number
		and.w	#15,d0
		ext.l	d0
		move.w	colx,d6		;multiple
		mulu	d6,d0		;offset in x direction
		and.l	#$ffff,d0
		add.l	#38,d0		;x0
		move.l	d0,d2		;get x1
		move.w	colx,d6		;get increment
		ext.l	d6
		add.l	d6,d2		;x1+1
		sub.l	#1,d2		;x1
		move.l	#0,d4		;filled rectangle
		cmp.w	#16,col
		blt.s	ccl2
		move.l	#190,d3
		move.l	#175,d1
ccl2		bsr	rectangle	;draw rectangle
		rts

copylast	move.w	objectnumber,d0
		cmp.w	#1,d0
		beq	wloop

		bsr	clearobject
		move.w	objectnumber,d2
		sub.w	#2,d2
		mulu	#4,d2
		and.l	#$ffff,d2
		move.l	#objectmem,d3
		ext.l	d2
		add.l	d2,d3
		move.l	d3,a0
		move.l	(a0),a0		;remember address

		bra	nottoworry

animate		move.w	objectnumber,d5
		move.w	#14,delaytime
		cmp.w	objecttotal,d5
		bne.s	storelimit
		bra	wloop
storelimit	move.w	d5,form
		move.w	objectbuffer,d6
		cmp.w	objecttotal,d6
		beq	wloop

		cmp.w	d5,d6
		beq	wloop
		blt	backwards

forwards	bsr	commontoboth

		move.w	form,d0
		cmp.w	objectbuffer,d0
		bne.s	for2
		move.w	objectnumber,d0
		move.w	d0,form
		bra	for3
for2		add.w	#1,form
for3		btst	#6,$bfe001
		bne	forwards
		bra	leaveitnicely

backwards	bsr	commontoboth

		move.w	form,d0
		cmp.w	objectbuffer,d0
		bne.s	back2
		move.w	objectnumber,d0
		move.w	d0,form
		bra	back3
back2		sub.w	#1,form
back3		btst	#6,$bfe001
		bne	backwards

leaveitnicely	bsr	clearobject
		move.w	objectnumber,d2
		bsr	ogetaddress
		move.l	d1,a0
		move.w	(a0)+,widf
		move.w	(a0)+,height
		bsr	workoutxw
		move.w	#1,d7
		bsr	justopen
		clr.l	d2
		clr.l	d3
		clr.l	d4
		bsr	drawgrid
		bsr	redraw
		bra	wloop

pauseabit	move.w	delaytime,d1
		ext.l	d1
		move.l	_DosBase,a6
		JSR	Delay(a6)
		move.b	$bfec01,d0
		cmp.b	#231,d0
		beq	addpause
		cmp.b	#233,d0
		beq	subpause
		rts
addpause	move.w	delaytime,d0
		add.w	#2,d0
		cmp.w	#52,d0
		bne.s	addstore
		move.w	#50,d0
addstore	move.w	d0,delaytime
		rts
subpause	move.w	delaytime,d0
		sub.w	#2,d0
		cmp.w	#0,d0
		bne.s	substore
		move.w	#2,d0
substore	move.w	d0,delaytime
		rts

commontoboth	bsr	clearobject
		move.w	form,d2
		bsr	ogetaddress
		move.l	d1,a0
		move.w	(a0)+,widf
		move.w	(a0)+,height
		clr.l	d2
		clr.l	d3
		clr.l	d4
		bsr	workoutxw
		move.w	#1,d7
		bsr	justopen

		bsr	pauseabit
		rts

ogetaddress	sub.w	#1,d2	;d2=objectnumber
		mulu	#4,d2
		and.l	#$ffff,d2
		move.l	#objectmem,d3
		ext.l	d2
		add.l	d2,d3
		move.l	d3,a0
		move.l	(a0),d1		;remember address
		rts

doscroll	move.l	rastport,a1
		move.l	#144,d2
		move.l	#12,d3
		move.l	#255,d4
		move.l	#131,d5
		move.l	_GfxBase,a6
		JSR	ScrollRaster(a6)
		bsr	redraw
		bra	wloop

flipx		move.w	#0,form
		move.w	widf,d0
		sub.w	#1,d0
		move.w	d0,form+2
		add.w	#1,d0
		asr.w	#1,d0
		move.w	d0,form+4

fxloop2		move.w	#0,d6
fxloop		move.w	form,d0
		move.w	d6,d1
		bsr	workoutpixel

		move.l	rastport,a1
		move.l	_GfxBase,a6
		JSR	ReadPixel(a6)
		move.l	d0,d5

		move.w	form+2,d0
		move.w	d6,d1
		bsr	workoutpixel

		move.l	rastport,a1
		move.l	_GfxBase,a6
		JSR	ReadPixel(a6)
		bsr	setcolour

		move.w	form,d0
		move.w	d6,d1
		bsr	workoutpixel
		bsr	plot

		move.l	d5,d0
		bsr	setcolour
		move.w	form+2,d0
		move.w	d6,d1
		bsr	workoutpixel
		bsr	plot

		add.w	#1,d6
		cmp.w	height,d6
		bne	fxloop
		add.w	#1,form
		sub.w	#1,form+2
		sub.w	#1,form+4
		cmp.w	#0,form+4
		bne	fxloop2

		bsr	redraw
		bra	wloop

flipy		move.w	#0,form
		move.w	height,d0
		sub.w	#1,d0
		move.w	d0,form+2
		add.w	#1,d0
		asr.w	#1,d0
		move.w	d0,form+4

fyloop2		move.w	#0,d6
fyloop		move.w	d6,d0
		move.w	form,d1
		bsr	workoutpixel

		move.l	rastport,a1
		move.l	_GfxBase,a6
		JSR	ReadPixel(a6)
		move.l	d0,d5

		move.w	form+2,d1
		move.w	d6,d0
		bsr	workoutpixel

		move.l	rastport,a1
		move.l	_GfxBase,a6
		JSR	ReadPixel(a6)
		bsr	setcolour

		move.w	form,d1
		move.w	d6,d0
		bsr	workoutpixel
		bsr	plot

		move.l	d5,d0
		bsr	setcolour
		move.w	form+2,d1
		move.w	d6,d0
		bsr	workoutpixel
		bsr	plot

		add.w	#1,d6
		cmp.w	widf,d6
		bne	fyloop
		add.w	#1,form
		sub.w	#1,form+2
		sub.w	#1,form+4
		cmp.w	#0,form+4
		bne	fyloop2

		bsr	redraw
		bra	wloop

workoutpixel	ext.l	d0
		ext.l	d1
		add.l	#144,d0
		add.l	#12,d1
		rts

aboutprog	lea	aboutwindow,a0
		move.l	scrnbase,d0
		move.l	d0,30(a0)
		move.l	_IntuitionBase,a6
		JSR	OpenWindow(a6)
		move.l	d0,windowbase2
		tst.l	d0
		bne.s	about2
		bra	wloop

about2		move.l	windowbase2,a0		;Use window base
		move.l	rastport,a2
		move.l	a2,form
		move.l	50(a0),rastport		;Save window's rastport

		move.l	#0,d0
		move.l	#0,d1
		move.l	#300,d2
		move.l	#184,d3
		move.l	#1,d4
		bsr	rectangle
		move.l	#2,d0
		bsr	setcolour
		move.l	#2,d0
		move.l	#2,d1
		move.l	#297,d2
		move.l	#181,d3
		move.l	#0,d4
		bsr	rectangle

		move.w	#0,d2
		move.w	#1,d3

		lea	xlist,a4
		lea	ylist,a5
		lea	alist,a6

nexttext	move.w	(a4)+,d0
		move.w	(a5)+,d1
		move.l	(a6)+,a2
		cmp.w	#-1,d0
		beq.s	about3
		movem.l	a4-a6,-(sp)
		bsr	printtext
		movem.l	(sp)+,a4-a6
		bra.s	nexttext

about3		bsr	waitforbutton

		move.l	windowbase2,a0
		move.l	_IntuitionBase,a6
		JSR	CloseWindow(a6)
		move.l	form,a2
		move.l	a2,rastport
		bra	wloop

errorreport	lea	errorwindow,a0
		move.l	scrnbase,d0
		move.l	d0,30(a0)
		move.l	_IntuitionBase,a6
		JSR	OpenWindow(a6)
		move.l	d0,windowbase2
		tst.l	d0
		bne.s	errorr2
		rts

errorr2		move.l	windowbase2,a0		;Use window base
		move.l	rastport,a3
		move.l	a3,form
		move.l	50(a0),rastport		;Save window's rastport

		move.l	#0,d0
		move.l	#0,d1
		move.l	#320,d2
		move.l	#20,d3
		move.l	#1,d4
		bsr	rectangle
		move.l	#2,d0
		bsr	setcolour
		move.l	#2,d0
		move.l	#2,d1
		move.l	#317,d2
		move.l	#17,d3
		move.l	#0,d4
		bsr	rectangle

		move.l	#6,d0
		move.l	#3,d1
		move.l	#0,d2
		move.l	#1,d3
		move.l	form+4,a2
		bsr	printtext
		bsr	waitforbutton

waiterror	btst	#6,$bfe001
		beq.s	waiterror

		move.l	windowbase2,a0
		move.l	_IntuitionBase,a6
		JSR	CloseWindow(a6)
		move.l	form,a2
		move.l	a2,rastport
		rts

jumptobuffer	move.w	objectnumber,d0
		cmp.w	objectbuffer,d0
		beq	wloop
		cmp.w	objecttotal,d0
		bne	jnotwholething

		move.w	#1,d7
		move.b	#1,flag
		bsr	storeobject
		bra	jdonestorage

jnotwholething	move.w	#1,d7
		move.b	#0,flag

		move.w	objectnumber,d2
		sub.w	#1,d2
		mulu	#4,d2
		and.l	#$ffff,d2
		move.l	#objectmem,d3
		ext.l	d2
		add.l	d2,d3
		move.l	d3,a3
		move.l	(a3),a3		;address
		bsr	juststore

jdonestorage	bsr	clearobject
		move.w	objectbuffer,d0
		move.w	d0,objectnumber
		cmp.w	objecttotal,d0
		beq	newobj
displaytheobject
		move.w	objectnumber,d2
		sub.w	#1,d2
		mulu	#4,d2
		and.l	#$ffff,d2
		move.l	#objectmem,d3
		ext.l	d2
		add.l	d2,d3
		move.l	d3,a3
		move.l	(a3),a0		;address
		move.w	(a0)+,widf
		move.w	(a0)+,height
		bsr	workoutxw
		bsr	justopen
		move.w	#0,sx
		move.w	#0,sy
		clr.l	d2
		clr.l	d3
		clr.l	d4
		bsr	drawgrid
		bsr	redraw
		move.b	#0,flag
		bra	wloop

jumptofirst	move.w	objectnumber,d0
		cmp.w	#1,d0
		beq	wloop
		cmp.w	objecttotal,d0
		bne	j1notwholething

		move.w	#1,d7
		move.b	#1,flag
		bsr	storeobject
		bra	j1donestorage

j1notwholething	move.w	#1,d7
		move.b	#0,flag

		move.w	objectnumber,d2
		sub.w	#1,d2
		mulu	#4,d2
		and.l	#$ffff,d2
		move.l	#objectmem,d3
		ext.l	d2
		add.l	d2,d3
		move.l	d3,a3
		move.l	(a3),a3		;address
		bsr	juststore

j1donestorage	bsr	clearobject
		move.w	#1,objectnumber
		cmp.w	#1,objecttotal
		beq	newobj
		bra	displaytheobject

jumptolast	move.w	objectnumber,d0
		cmp.w	objecttotal,d0
		beq	wloop

j2notwholething	move.w	#1,d7
		move.b	#0,flag

		move.w	objectnumber,d2
		sub.w	#1,d2
		mulu	#4,d2
		and.l	#$ffff,d2
		move.l	#objectmem,d3
		ext.l	d2
		add.l	d2,d3
		move.l	d3,a3
		move.l	(a3),a3		;address
		bsr	juststore

j2donestorage	bsr	clearobject
		move.w	objecttotal,d0
		move.w	d0,objectnumber
		bra	newobj

getanimfile	move.l	windowbase,a0		;Get windowbase
		move.l	#$ffff,d0		;Specify all menus
		move.l	_IntuitionBase,a6	;Get intuition base
		JSR	OffMenu(a6)		;Activate menus

		lea	wtitle,a0
		move.l	#oawtitle,(a0)
		lea	gadget2,a0
		move.l	#0,(a0)
		lea	gtext2,a0
		move.l	#ok,(a0)

		lea	newwindow2,a0
		move.l	scrnbase,d0
		move.l	d0,30(a0)
		move.l	_IntuitionBase,a6
		JSR	OpenWindow(a6)
		move.l	d0,windowbase2
		tst.l	d0
		bne.s	awindowopened
		bra	wloop

awindowopened	lea	strgadget,a0		;Get address of gadget structure
		move.l	windowbase2,a1		;get window base
		move.l	_IntuitionBase,a6	;get intuition base
		JSR	RefreshGadgets(a6)	;Refresh gadgets

		move.l	strgadget,a0
		move.l	_IntuitionBase,a6
		JSR	ActivateGadget(a6)

	move.l	windowbase2,a0		;Use window base
	move.l	$56(a0),userport2	;Save window's userport

aowloop	move.l	userport2,a0		;Get windows userport
	CALLEXEC	WaitPort	;Call waitport
	move.l	userport2,a0		;Get userport again
	CALLEXEC	GetMsg		;Get IDCMP message (if any)
	tst.l	d0			;Was there a message?
	beq.s	aowloop			;No, so loop back
	move.l	d0,a1			;Get address of message
	move.l	20(a1),d2	;Im.class (contains type of message. e.g. CLOSEWINDOW,GADGETUP)
	move.w	24(a1),d3	;Im.code (contains menu selection numbers etc.)
	move.w	26(a1),d4	;Im.qualifier (keyboard info lives here)
	CALLEXEC	ReplyMsg	;Say ta to intuition
	move.l	(a0),a0			;Get message pointer in a0

	cmp.l	#$40,d2			;check class for GADGETUP
	bne.s	aowloop			;If yes, nip on to next bit

	move.l	28(a0),a0		;Get address of hit gadget
	move.w	38(a0),d0		;Get id of gadget
	move.w	d0,form
	cmp.w	#11,d0		;Cancel?
	beq.s	adoneopen
	cmp.w	#12,d0		;OK?
	bne.s	aowloop

adoneopen	move.l	windowbase2,a0
		move.l	_IntuitionBase,a6
		JSR	CloseWindow(a6)

		lea	gadget2,a0
		move.l	#gadget3,(a0)
		lea	gtext2,a0
		move.l	#gadg2text,(a0)

		rts

openanimfile	move.l	#'Open',oawtitle

		bsr	getanimfile

		move.w	form,d0		;11=cancel 12=ok
		cmp.w	#11,d0
		beq	oacancels

		move.w	objectnumber,d0
		cmp.w	objecttotal,d0
		beq	noneedtostore

		move.w	#1,d7
		move.b	#0,flag

		move.w	objectnumber,d2
		sub.w	#1,d2
		mulu	#4,d2
		and.l	#$ffff,d2
		move.l	#objectmem,d3
		ext.l	d2
		add.l	d2,d3
		move.l	d3,a3
		move.l	(a3),a3		;address
		bsr	juststore

noneedtostore	move.l	#stringtext,d1	;address of filename
		move.l	#MODE_OLDFILE,d2	;type of file
		move.l	_DosBase,a6	;A dos.library routine
		JSR	Open(a6)	;attempt open of file
		tst.l	d0		;did it work
		bne	oaopenok	;No

		lea	error12,a2
		move.l	a2,form+4
		bsr	errorreport
		bra	oacancels

oaopenok	move.l	d0,filehandle	;store pointer to file

		move.l	filehandle,d1
		move.l	#form,d2
		move.l	#4,d3
		move.l	_DosBase,a6
		JSR	Read(a6)
		cmp.l	#'GMOE',form
		beq.s	getnumofobjs

		lea	error17,a2
		move.l	a2,form+4
		bsr	errorreport
		add.w	#1,objectnumber
		bra	oaclosefile

getnumofobjs	move.l	filehandle,d1	;pointer to file
		move.l	#numofobjects,d2	;address of buffer
		move.l	#2,d3		;length of read
		move.l	_DosBase,a6
		JSR	Read(a6)	;do the read

		move.w	objecttotal,objectnumber

oaforwards	bsr	clearobject
		move.l	filehandle,d1
		move.l	#bwidf,d2
		move.l	#4,d3
		move.l	_DosBase,a6
		JSR	Read(a6)

		cmp.w	#112,bwidf
		ble.s	oawidfok

		lea	error7,a2
		move.l	a2,form+4
		bsr	errorreport
		bra	oaclosefile

oawidfok	cmp.w	#120,bheight
		ble.s	oaheightok

		lea	error8,a2
		move.l	a2,form+4
		bsr	errorreport
		bra	oaclosefile

oaheightok	move.w	bheight,height
		move.w	bwidf,widf
		bsr	workoutxw
		move.w	#0,d7
		bsr	openrawbody

		move.w	#1,d7
		move.b	#1,flag
		bsr	attheend	;stores object
		cmp.b	#1,flag
		beq	oaclosefile	;not enuf mem

		sub.w	#1,numofobjects
		move.w	numofobjects,d0
		tst.w	d0
		bne	oaforwards

oaclosefile	move.l	#150,d1
		move.l	_DosBase,a6
		JSR	Delay(a6)
		move.l	filehandle,d1	;pointer to file
		move.l	_DosBase,a6	;dos.library
		JSR	Close(a6)	;close file
		move.b	#0,flag
		sub.w	#1,objectnumber

oacancels	move.l	windowbase,a0		;Get windowbase
		move.l	#$ffff,d0		;Specify all menus
		move.l	_IntuitionBase,a6	;Get intuition base
		JSR	OnMenu(a6)		;Activate menus

		move.w	objectnumber,d0
		cmp.w	objecttotal,d0
		beq	newobj
		bra	leaveitnicely

saveanimfile	move.l	#'Save',oawtitle

		move.w	objectbuffer,d0
		cmp.w	objecttotal,d0
		bne.s	notatend1

		lea	error15,a2
		move.l	a2,form+4
		bsr	errorreport
		bra	wloop

notatend1	move.w	objectnumber,d1
		cmp.w	objecttotal,d1
		bne.s	notatendatall

		lea	error15,a2
		move.l	a2,form+4
		bsr	errorreport
		bra	wloop

notatendatall	cmp.w	d0,d1
		bne.s	theyarediff
		lea	error14,a2
		move.l	a2,form+4
		bsr	errorreport
		bra	wloop

theyarediff	blo.s	totherway
		move.w	d0,startobject	;first object
		sub.w	d0,d1
		add.w	#1,d1
		move.w	d1,numofobjects	;number of objects
		bra.s	gimmename
totherway	move.w	d1,startobject
		sub.w	d1,d0
		add.w	#1,d0
		move.w	d0,numofobjects

gimmename	bsr	getanimfile

		move.w	form,d0
		cmp.w	#11,d0
		beq	sacancels

		move.l	#stringtext,d1	;address of filename
		move.l	#MODE_NEWFILE,d2	;type of file
		move.l	_DosBase,a6	;A dos.library routine
		JSR	Open(a6)	;attempt open of file
		tst.l	d0		;did it work
		bne	saopenok	;No

		lea	error12,a2
		move.l	a2,form+4
		bsr	errorreport
		bra	sacancels

saopenok	move.l	d0,filehandle	;store pointer to file

		move.l	#4,d3
		move.l	filehandle,d1
		move.l	#animidentify,d2
		move.l	_DosBase,a6
		JSR	Write(a6)

		move.l	#2,d3
		move.l	filehandle,d1
		move.l	#numofobjects,d2
		move.l	_DosBase,a6	;stores number of objects
		JSR	Write(a6)

		move.w	startobject,d0
		move.w	d0,form

saforwards	bsr	commontoboth

		move.l	#4,d3
		move.l	filehandle,d1
		move.l	#widf,d2
		move.l	_DosBase,a6
		JSR	Write(a6)	;widf,height

		bsr	workoutxw
		bsr	saverawbody

		add.w	#1,form
		sub.w	#1,numofobjects
		move.w	numofobjects,d0
		tst.w	d0
		bne.s	saforwards

		move.l	#150,d1
		move.l	_DosBase,a6
		JSR	Delay(a6)
		move.l	filehandle,d1	;pointer to file
		move.l	_DosBase,a6	;dos.library
		JSR	Close(a6)	;close file

		cmp.b	#1,icons
		bne.s	sacancels

		move.l	#animsize,form+4
		move.l	#animinfo,form
		bsr	makeinfoname

sacancels	move.l	windowbase,a0		;Get windowbase
		move.l	#$ffff,d0		;Specify all menus
		move.l	_IntuitionBase,a6	;Get intuition base
		JSR	OnMenu(a6)		;Activate menus

		bra	leaveitnicely

		move.l	#2,d3
		move.l	#numofobjects,d2

makeinfoname	lea	stringtext,a0
		lea	infotext,a1
creationloop	move.b	(a0)+,d0
		cmp.b	#0,d0
		beq.s	endofname
		move.b	d0,(a1)+
		bra.s	creationloop

endofname	move.b	#'.',(a1)+
		move.b	#'i',(a1)+
		move.b	#'n',(a1)+
		move.b	#'f',(a1)+
		move.b	#'o',(a1)+
		move.b	#0,(a1)+

		move.l	#infotext,d1	;address of filename
		move.l	#MODE_NEWFILE,d2	;type of file
		move.l	_DosBase,a6	;A dos.library routine
		JSR	Open(a6)	;attempt open of file
		tst.l	d0		;did it work
		bne	infook	;No

		lea	error16,a2
		move.l	a2,form+4
		bsr	errorreport
		rts

infook		move.l	d0,filehandle
		move.l	filehandle,d1
		move.l	form,d2
		move.l	form+4,d3
		move.l	_DosBase,a6	;stores number of objects
		JSR	Write(a6)

		move.l	#150,d1
		move.l	_DosBase,a6
		JSR	Delay(a6)
		move.l	filehandle,d1	;pointer to file
		move.l	_DosBase,a6	;dos.library
		JSR	Close(a6)	;close file
		rts

; General routines follow

;Waitforbutton usage - bra waitforbutton

waitforbutton	btst	#6,$bfe001	;btst #10,$dff016 for right button
		bne.s	waitforbutton
		rts

; Format for line subroutine. d0=x1,d1=y1,d2=x2,d3=y2

line	move.l	_GfxBase,a6		;Get gfxbase
	move.l	rastport,a1		;get rastport
	JSR	Move(a6)		;Move to x,y (d0,d1)
	move.l	d2,d0			;Get new X
	move.l	d3,d1			;Get new Y
	JSR	Draw(a6)		;Draw to new point
	rts

; Format for plot subroutine. d0=x,d1=y

plot	move.l	_GfxBase,a6		;Get gfxbase
	move.l	rastport,a1		;get rastport
	JSR	WritePixel(a6)		;Plot point
	rts

; Getmousepos returns x,y of mouse in d0,d1

getmousepos	move.l	windowbase,a0	;Window base
		move.w	14(a0),d0	;get x co-ordinate
		move.w	12(a0),d1	;get y co-ordinate
		ext.l	d0		;make long word
		ext.l	d1		; ditto for d1
		rts

; Format for printtext : a2=address of text,0 d0=x d1=y d2=colour d3=back col

printtext	move.l	rastport,a0	;get window rastport
		lea	text,a1		;get address of text structure
		move.l	a2,12(a1)	;move address of null text into structure
		move.b	d2,(a1)		;move colour to structure
		move.b	d3,1(a1)	;move background colour to structure
		move.l	_IntuitionBase,a6 ;get intuition base
		JSR	PrintIText(a6)	  ;print text
		rts

; Format for rectangle : d0=x1 d1=y1 d2=x2 d3=y2 d4- 1=filled 0=outline

rectangle	move.l	rastport,a1	;get window rastport
		move.l	_GfxBase,a6	;get graphics base
		cmp.w	#1,d4		;Is a filled rectangle required?
		bne	unfilled	;no
		JSR	RectFill(a6)	;draw rectangle
		rts			;and return
unfilled	lea	rectlist,a2	;Get address of rectlist
		move.w	d0,(a2)+	;store corner points in turn
		move.w	d1,(a2)+
		move.w	d0,(a2)+
		move.w	d3,(a2)+
		move.w	d2,(a2)+
		move.w	d3,(a2)+
		move.w	d2,(a2)+
		move.w	d1,(a2)+
		move.w	d0,(a2)+
		move.w	d1,(a2)+
		JSR	Move(a6)
		move.w	#5,d0		;number of pairs of co-ordinates
		lea	rectlist,a0	;reload address of list
		JSR	PolyDraw(a6)	;draw rectangle
		rts			;and exit

rectlist	dc.w	0,0,0,0,0,0,0,0,0,0

;Usage of setcolour : d0=colour

setcolour	move.l	rastport,a1
		move.l	_GfxBase,a6
		JSR	SetAPen(a6)
		rts

;Usage of printdecimal : d0=x d1=y d2=number to print

decimalstr	dc.b	'000',0

printdecimal	move.w	d2,d3
		divu	#100,d3
		and.l	#$ff,d3
		add.b	#48,d3
		cmp.b	#48,d3
		bne.s	hundok
		move.b	#32,d3
hundok		move.b	d3,decimalstr
		cmp.b	#32,d3
		beq.s	skipsub
		sub.b	#48,d3
		bra.s	skipzero
skipsub		move.b	#0,d3
skipzero	ext.w	d3
		mulu	#100,d3
		sub.w	d3,d2
		move.w	d2,d4
		divu	#10,d4
		and.l	#$ff,d4
		add.b	#48,d4
		cmp.b	#48,d4
		bne.s	tenok
		lea	decimalstr,a0
		cmp.b	#32,(a0)
		bne.s	tenok
		move.b	#32,d4
tenok		move.b	d4,decimalstr+1
		cmp.b	#32,d4
		beq.s	skipsub2
		sub.b	#48,d4
		bra.s	skipzero2
skipsub2	move.b	#0,d4
skipzero2	ext.w	d4
		mulu	#10,d4
		sub.w	d4,d2
		and.l	#$ff,d2
		add.b	#48,d2
		move.b	d2,decimalstr+2
		lea	decimalstr,a2
		move.w	#1,d2
		move.w	#0,d3
		bsr	printtext
		rts

;Program routines

findaddresses	move.l	windowbase,a0
		move.l	46(a0),d0	;scren
		add.l	#84,d0		;rastport
		move.l	d0,a0
		move.l	4(a0),d0	;sbitmap
		add.l	#8,d0		;start of bitplane addresses

		move.w	#0,d1
		lea	bitplane1,a1
		move.l	d0,a0
getaddress	move.l	(a0)+,d0
		add.l	#818,d0		;add offset
		move.l	d0,(a1)+
		add.w	#1,d1
		cmp.w	#5,d1
		bne.s	getaddress
		rts

drawcols	move.w	#5,d6	;depth
		move.w	#1,d5		;base2
		asl.w	d6,d5		;get number of colours
		subq	#1,d5		;colours-1
		cmp.w	#31,d5		;are there 31?
		bne.s	workoutboxes	;no
		move.w	#15,d5		;set number of colours to 15	
workoutboxes	move.l	#160,d0		;width of colour area
		move.w	d5,d6
		addq	#1,d6
		divu	d6,d0		;get increment
		move.w	d0,colx		;store value		
column1		move.w	d5,d0		;colour number
		bsr	setcolour	;set colour
		move.l	#158,d1		;y0
		move.l	#190,d3		;y1
		move.l	d5,d0		;colour number
		move.w	colx,d6		;multiple
		mulu	d6,d0		;offset in x direction
		add.l	#38,d0		;x0
		move.l	d0,d2		;get x1
		move.w	colx,d6		;get increment
		add.l	d6,d2		;x1+1
		subq	#1,d2		;x1
		move.l	#1,d4		;filled rectangle
		bsr	rectangle	;draw rectangle

		move.w	#5,d6	;number of bitplanes
		cmp.w	#5,d6		;Are there 5?
		bne.s	Lessthan5	;no

		move.w	d5,d0		;get colour again
		add.w	#16,d0		;second set of 16 cols
		bsr	setcolour	;set colour
		move.l	d2,d0		;get x1 into x0
		sub.l	#9,d0		;get x1 proper
		move.l	#175,d1		;y0
		move.l	#190,d3		;y1
		bsr	rectangle	;draw rectangle
Lessthan5	dbra	d5,column1	;repeat for other rectangles
		move.w	#1,d0		;highlight colour
		bsr	setcolour	;set colour
		move.l	#38,d0		;x0
		move.l	d0,d2		;x1
		move.w	colx,d6
		add.l	d6,d2		;x1 proper
		sub.l	#1,d2
		move.l	#158,d1		;y0
		move.l	#190,d3		;y1
		move.w	#5,d6	;get depth
		cmp.w	#5,depth	;5 planes?
		bne.s	drawback	;no
		move.l	#174,d3		;new y1
drawback	move.w	#0,d4		;outline
		bsr	rectangle	;outline background colour
		rts

newcolour	move.w	col,d0		;current drawing colour
		bsr	setcolour	;set colour
		move.l	#10,d0		;x0
		move.l	#30,d2		;x1
		move.l	#158,d1		;y0
		move.l	#190,d3		;y1
		move.l	#1,d4		;filled
		bsr	rectangle
		bsr	splitRGB	;get RGB values

		lea	gadgetR,a0	;address of red slider
		move.l	34(a0),a0	;address of red special info
		move.w	14(a0),d0	;HPOTRES
		mulu	d1,d0		;new value for HORIZPOT
		move.w	d0,2(a0)	;store new HORIZPOT

		lea	gadgetG,a0	;address of green slider
		move.l	34(a0),a0	;address of green special info
		move.w	14(a0),d0	;HPOTRES
		mulu	d2,d0		;new value for HORIZPOT
		move.w	d0,2(a0)	;store new HORIZPOT

		lea	gadgetB,a0	;address of blue slider
		move.l	34(a0),a0	;address of blue special info
		move.w	14(a0),d0	;HPOTRES
		mulu	d3,d0		;new value for HORIZPOT
		move.w	d0,2(a0)	;store new HORIZPOT

		move.l	_IntuitionBase,a6	;use intuiton library
		move.l	windowbase,a1		;and window base
		lea	gadget,a0	;and address of 1st gadget
		JSR	RefreshGadgets(a6)	;to use sliders
		rts

drawgrid	move.b	gridcol,d0
		ext.w	d0
		bsr	setcolour
		move.l	#128,d5
		move.w	xgap,d4
		ext.l	d4
		divu	d4,d5
		move.w	d5,across
		move.l	#128,d5
		move.w	ygap,d4
		ext.l	d4
		divu	d4,d5
		move.w	d5,down
		move.w	across,d4
		cmp.w	widf,d4
		ble.s	xok
		move.w	widf,across
xok		move.w	down,d4
		cmp.w	height,d4
		ble.s	yok
		move.w	height,down
yok		move.w	across,d4	;pixels across
		move.w	xgap,d5		;zoom gap
		mulu	d5,d4		;x increment
		move.w	d4,fx
		move.w	down,d5		;pixels down
		move.w	ygap,d6		;zoom gap
		mulu	d6,d5		;y increment
		move.w	d5,fy
		move.w	#1,d6		;current square
nextlinex	move.w	#9,d0		;x corner
		add.l	d6,d0		;add offset
		move.w	d0,d2		;x end
		move.w	#10,d1		;y start
		move.w	d1,d3		;y end
		move.w	fy,d5
		add.l	d5,d3		;y end proper
		bsr	line		;draw line
		move.w	xgap,d0
		add.w	d0,d6		;next corner
		move.w	fx,d0
		addq	#2,d0
		cmp.w	d0,d6		;last line?
		blt.s	nextlinex	;not yet
		move.w	#1,d6		;current line
nextliney	move.w	#9,d1		;y corner
		add.l	d6,d1		;add offset
		move.w	d1,d3		;y end
		move.w	#10,d0		;x start
		move.w	d0,d2		;x end
		move.w	fx,d4
		add.l	d4,d2		;x end proper
		bsr	line		;draw line
		move.w	ygap,d0
		add.w	d0,d6		;next line
		move.w	fy,d0
		addq	#2,d0
		cmp.w	d0,d6		;last line?
		blt.s	nextliney	;not yet
		move.w	col,d0
		bsr	setcolour
		add.w	#10,fx
		add.w	#10,fy
newdimensions	move.l	#280,d0
		move.l	#54,d1
		move.w	widf,d2
		bsr	printdecimal
		move.l	#280,d0
		move.l	#74,d1
		move.w	height,d2
		bsr	printdecimal
justobject	move.l	#264,d0		;280
		move.l	#34,d1
		move.w	objectnumber,d2
		bsr	printdecimal

		move.l	#296,d0
		move.l	#34,d1
		move.w	objecttotal,d2
		bsr	printdecimal
		move.l	#280,d0
		move.l	#129,d1
		move.w	objectbuffer,d2
		bsr	printdecimal
		move.l	#288,d0
		move.l	#34,d1
		lea	slash,a2
		bsr	printtext
		bsr	workoutxw
		rts

ingrid		sub.w	#10,d0		;account for start of grid
		sub.w	#10,d1
		divu	xgap,d0		;get actual position in grid
		divu	ygap,d1
		move.w	d0,x2		;backup
		move.w	d1,y2
		mulu	xgap,d0		;and multiply back to get exact position of corner
		mulu	ygap,d1
		add.w	#11,d0		;corner of square
		add.w	#11,d1
		move.w	d0,d2
		move.w	d1,d3
		add.w	xgap,d2		;start of next square
		add.w	ygap,d3
		subq	#2,d2		;bottom corner of square
		subq	#2,d3
		move.w	#1,d4		;filled
		bsr	rectangle
		move.w	#144,d0		;top corner of real size image
		move.w	#12,d1
		add.w	x2,d0		;add square number
		add.w	y2,d1
		add.w	sx,d0
		add.w	sy,d1
		bsr	plot
		move.b	#1,picchanged
		rts

loadbrush	move.l	#stringtext,d1	;address of filename
		move.l	#MODE_OLDFILE,d2	;type of file
		move.l	_DosBase,a6	;A dos.library routine
		JSR	Open(a6)	;attempt open of file
		tst.l	d0		;did it work
		beq	cantopen	;No
		move.l	d0,filehandle	;store pointer to file

		bra	findFORM
formok		bra	findBMHD
bmhdok		bra	findCMAP
cmapok		bra	findGRAB
grabok		bsr	clearobject
		bra	findBODY
bodyok

finishedload
		move.l	#150,d1
		move.l	_DosBase,a6
		JSR	Delay(a6)
		move.l	filehandle,d1	;pointer to file
		move.l	_DosBase,a6	;dos.library
		JSR	Close(a6)	;close file
		rts			;and exit

cantopen	lea	error12,a2
		move.l	a2,form+4
		bsr	errorreport
		rts

findFORM	move.l	filehandle,d1	;pointer to file
		move.l	#form,d2	;buffer to receive data
		move.l	#12,d3		;length of read (in bytes)
		move.l	_DosBase,a6
		JSR	Read(a6)	;do the read

		lea	form,a0
		cmp.l	#'FORM',(a0)	;was FORM read?
		beq.s	checkILBM

		lea	error1,a2
		move.l	a2,form+4
		bsr	errorreport

		bra	finishedload
checkILBM	lea	form+8,a0
		cmp.l	#'ILBM',(a0)	;was ILBM read?
		beq.s	ILBMok

		lea	error2,a2
		move.l	a2,form+4
		bsr	errorreport

		bra	finishedload
ILBMok		bra	formok

findBMHD	move.l	filehandle,d1	;pointer to file
		move.l	#form,d2	;address of buffer
		move.l	#8,d3		;length of read
		move.l	_DosBase,a6
		JSR	Read(a6)	;do the read

		lea	form,a0
		cmp.l	#'BMHD',(a0)	;was BMHD read?
		beq.s	bmhdfound

		lea	error3,a2
		move.l	a2,form+4
		bsr	errorreport

		bra	finishedload	;not found
bmhdfound	lea	form+4,a0
		move.l	(a0),d0		;get MKL$(number)
		bsr	CVL		;convert to real number
		cmp.l	#20,d0		;is BMHD right size?
		beq.s	bmhdright	;Yes

		lea	error4,a2
		move.l	a2,form+4
		bsr	errorreport

		bra	finishedload	;No

bmhdright	move.w	widf,bwidf
		move.w	height,bheight

		lea	widf,a0
		bsr	readinteger
		lea	height,a0
		bsr	readinteger
		lea	xpos,a0
		bsr	readinteger
		lea	ypos,a0
		bsr	readinteger
		lea	bitplanes,a0
		bsr	readascii
		lea	masking,a0
		bsr	readascii
		lea	compression,a0
		bsr	readascii
		lea	pad,a0
		bsr	readascii
		lea	transcol,a0
		bsr	readinteger
		lea	xAspect,a0
		bsr	readascii
		lea	yAspect,a0
		bsr	readascii
		lea	xpixel,a0
		bsr	readinteger
		lea	ypixel,a0
		bsr	readinteger
		cmp.b	#1,compression
		ble.s	compok

		lea	error5,a2
		move.l	a2,form+4
		bsr	errorreport

		bra	finishedload

compok		cmp.w	#0,transcol
		beq.s	transok

		lea	error6,a2
		move.l	a2,form+4
		bsr	errorreport

		bra	finishedload

transok		cmp.w	#112,widf
		ble.s	widfok

		lea	error7,a2
		move.l	a2,form+4
		bsr	errorreport
		move.w	bwidf,widf
		move.w	bheight,height

		bra	finishedload

widfok		cmp.w	#120,height
		ble.s	heightok

		lea	error8,a2
		move.l	a2,form+4
		bsr	errorreport
		move.w	bheight,height
		move.w	bwidf,widf

		bra	finishedload

heightok	cmp.b	#6,bitplanes
		bne.s	planesok

		lea	error9,a2
		move.l	a2,form+4
		bsr	errorreport

		bra	finishedload

planesok	bra	bmhdok

findCMAP	move.l	filehandle,d1	;pointer to file
		move.l	#form,d2	;address of buffer
		move.l	#8,d3		;length of read
		move.l	_DosBase,a6
		JSR	Read(a6)	;do the read

		lea	form,a0
		cmp.l	#'CMAP',(a0)+	;was cmap read?
		beq.s	cmapfound
		lea	form,a0
		cmp.l	#'BODY',(a0)
		bne	findGRAB
		beq	findBODY

cmapfound	move.l	(a0),d0		;get chunk size
		bsr	CVL		;convert it
		divu	#3,d0		;divide by 3
		move.w	d0,loadnumber	;store

		move.w	#0,count		;count

loadpalette	lea	form,a0
		bsr	readascii	;get red value
		lea	form,a0
		move.b	(a0),d0
		lsr.b	#4,d0		;divide by 16
		move.b	d0,d5		;store red

		lea	form,a0
		bsr	readascii	;get green value
		lea	form,a0
		move.b	(a0),d0
		lsr.b	#4,d0		;divide by 16
		move.b	d0,d6		;store green

		lea	form,a0
		bsr	readascii	;get blue value
		lea	form,a0
		move.b	(a0),d0
		lsr.b	#4,d0		;divide by 16
		move.b	d0,d7		;store blue

		ext.w	d5		;red
		ext.w	d6		;green
		ext.w	d7		;blue

		lsl.w	#4,d6	;position green
		lsl.w	#4,d5
		lsl.w	#4,d5	;position red

		add.w	d6,d7
		add.w	d5,d7	;combine red,green and blue

		move.w	count,d5	;get palette offset
		move.l	#brushpalette,d0
		ext.l	d5
		asl.l	#1,d5
		add.l	d5,d0
		move.l	d0,a0
		move.w	d7,(a0)

		move.w	count,d4
		add.w	#1,d4
		move.w	d4,count
		cmp.w	loadnumber,d4
		bne.s	loadpalette

		bra	cmapok

findGRAB	move.l	#form,d2
		move.l	filehandle,d1
		move.l	#4,d3
		move.l	_DosBase,a6
		JSR	Read(a6)
		tst	d0
		beq.s	quitgrab
		lea	form,a0
		cmp.l	#'BODY',(a0)
		beq.s	bodyfound
		bra	findGRAB

		lea	error10,a2
		move.l	a2,form+4
		bsr	errorreport

quitgrab	bra	finishedload

bodyfound	bra	grabok


findBODY	move.w	widf,d0
		lsr.w	#3,d0
		move.w	d0,xw

		cmp.b	#1,compression
		beq.s	whole

		move.w	widf,d1
		and.w	#7,d1
		tst.w	d1
		beq.s	whole
		add.w	#1,xw
		add.w	#1,d0

whole		btst	#0,d0
		beq.s	itseven
		add.w	#1,xw
itseven		cmp.w	#0,xw
		bne.s	notasmallone
		move.w	#2,xw
	
notasmallone	move.l	#form,d2
		move.l	filehandle,d1
		move.l	#4,d3
		move.l	_DosBase,a6
		JSR	Read(a6)
		lea	form,a0
		move.l	(a0),d0
		bsr	CVL
		move.l	d0,chunk

		move.l	#$10001,d1	;public, and cleared
		CALLEXEC	AllocMem	;allocmem
		tst.l	d0
		bne.s	oksofar
		bra	finishedload
oksofar		move.l	d0,MemfBase

		move.l	#100,d1
		move.l	_DosBase,a6
		JSR	Delay(a6)

		move.l	filehandle,d1
		move.l	MemfBase,d2
		move.l	chunk,d3
		move.l	_DosBase,a6
		JSR	Read(a6)

		cmp.b	#1,compression
		beq.s	compressed

		bsr	notcompressed
		bra	bodyloaded

compressed	bsr	decompress

bodyloaded	move.l	chunk,d0
		move.l	MemfBase,a1
		CALLEXEC	FreeMem	;deallocatemem

		bra	bodyok

notcompressed	move.w	#0,d4	;d4=row
		move.l	MemfBase,a0
		clr.l	d5
rloop		move.b	#0,d5	;plane
ploop		move.w	#0,d6	;column

cloop		move.b	(a0)+,d0		;byte

		bsr	workoutpos

		move.b	d0,(a1)		;poke

		add.w	#1,d6
		cmp.w	xw,d6
		bne.s	cloop

		add.b	#1,d5
		cmp.b	bitplanes,d5
		bne.s	ploop	
		
		add.w	#1,d4
		cmp.w	height,d4
		bne.s	rloop

		rts

decompress	move.w	#0,d4	;row
		move.l	MemfBase,a0
		clr.l	d5
		move.b	#0,d5
		move.w	#0,d6
		move.l	#0,d7	;main

deloop		cmp.l	chunk,d7
		bhs	decompdone

		move.b	(a0)+,d0
		add.l	#1,d7
		move.b	d0,d1
		and.b	#128,d1
		lsl.b	#1,d1
		sub.b	d1,d0	;header

		cmp.b	#-128,d0
		beq.s	deloop
		cmp.b	#128,d0
		blo.s	strcopy

		bsr	duplicate
		bra	deloop2
strcopy		bsr	samebyte

deloop2		cmp.w	xw,d6
		bls.s	deloop3

		move.w	#0,d6
		add.b	#1,d5
deloop3		cmp.b	bitplanes,d5
		bne.s	deloop4
		move.b	#0,d5
		add.w	#1,d4
deloop4		bra	deloop

decompdone	rts

duplicate	move.b	(a0)+,form
		add.l	#1,d7
		move.b	#0,d3
		eor.b	#255,d0
		add.b	#2,d0	;make header +ve

duploop		bsr	workoutpos
		move.b	form,(a1)
		add.w	#1,d6
		add.b	#1,d3
		cmp.b	d3,d0
		bne.s	duploop

		rts

samebyte	move.b	#0,d3
		add.b	#1,d0
sameloop	move.b	(a0)+,form
		bsr	workoutpos
		move.b	form,(a1)
		add.w	#1,d6
		add.l	#1,d7
		add.b	#1,d3
		cmp.b	d3,d0
		bne.s	sameloop
		rts


workoutpos	move.l	#bitplane1,d2
		move.b	d5,d1
		ext.w	d1
		ext.l	d1
		asl.l	#2,d1
		add.l	d1,d2
		move.l	d2,a1
		move.l	(a1),d2		;start of plane

		move.w	d4,d1
		mulu	#40,d1		;row offset
		ext.l	d1
		add.l	d1,d2

		move.w	d6,d1
		ext.l	d1
		add.l	d1,d2		;column offset

		move.l	d2,a1
		rts

savebrush	move.l	#stringtext,d1	;address of filename
		move.l	#MODE_NEWFILE,d2	;type of file
		move.l	_DosBase,a6	;A dos.library routine
		JSR	Open(a6)	;attempt open of file
		tst.l	d0		;did it work
		beq	sbcantopen	;No
		move.l	d0,filehandle	;store pointer to file

		move.w	widf,d0
		lsr.w	#3,d0
		move.w	d0,xw

		move.w	widf,d1
		and.w	#7,d1
		tst.w	d1
		beq.s	sbwhole
		add.w	#1,xw
		add.w	#1,d0

sbwhole		btst	#0,d0
		beq.s	sbitseven
		add.w	#1,xw
sbitseven	cmp.w	#0,xw
		bne.s	sbnotasmallone
		move.w	#2,xw

sbnotasmallone	move.w	xw,d0
		mulu	height,d0
		mulu	#5,d0
		move.w	d0,form		;save body length
		move.w	#96,d0
cmaplength	move.w	d0,form+2	;cmap length
		move.w	form,d1
		add.w	d1,d0
		add.w	#60,d0
		move.w	d0,form+4	;file length

		ext.l	d0
		add.l	#8,d0
		move.l	#$10001,d1	;public, and cleared
		CALLEXEC	AllocMem	;allocmem
		tst.l	d0
		bne.s	sboksofar
		bra	finishedsave
sboksofar	move.l	d0,MemfBase

		move.l	MemfBase,a3
		move.l	#'FORM',(a3)+
		move.w	form+4,d0
		ext.l	d0

		move.l	d0,(a3)+
		move.l	#'ILBM',(a3)+
		move.l	#'BMHD',(a3)+
		move.l	#20,d0

		move.l	d0,(a3)+
		move.w	widf,d0

		move.w	d0,(a3)+
		move.w	height,d0

		move.w	d0,(a3)+
		move.w	#0,d0

		move.w	d0,(a3)+
		move.w	d0,(a3)+
		move.w	#5,d0
		and.w	#$ff,d0
		move.b	d0,(a3)+
		move.b	#2,(a3)+
		move.b	#0,(a3)+
		move.b	#0,(a3)+
		move.w	#0,d0

		move.w	d0,(a3)+
		move.b	#$a,(a3)+
		move.b	#$b,(a3)+
		move.w	#320,d0

		move.w	d0,(a3)+
		move.w	#200,d0

		move.w	d0,(a3)+
		move.l	#'CMAP',(a3)+
		move.w	form+2,d0
		ext.l	d0

		move.l	d0,(a3)+

		lea	palette,a2
		move.w	#0,d0
nextcol		move.w	(a2)+,d1
		move.w	d1,d2
		move.w	d2,d3
		asr.w	#4,d1
		and.w	#$f0,d1
		and.w	#$f0,d2
		asl.w	#4,d3
		and.w	#$f0,d3
		move.b	d1,(a3)+
		move.b	d2,(a3)+
		move.b	d3,(a3)+
		add.w	#1,d0
		cmp.w	#32,d0
		bne.s	nextcol

		move.l	#'GRAB',(a3)+
		move.l	#4,d0

		move.l	d0,(a3)+
		move.w	#1,d0

		move.w	d0,(a3)+
		move.w	d0,(a3)+

		move.l	#'BODY',(a3)+
		move.w	form,d0
		ext.l	d0

		move.l	d0,(a3)+

		move.w	form+4,d0
		ext.l	d0
		add.l	#8,d0
		move.l	d0,form

sbgetbody	move.w	#0,d4	;row
		move.w	#0,d5	;plane
		move.w	#0,d6	;column

sbnextrow	bsr	workoutpos
sbnextbyte	move.b	(a1)+,(a3)+
		add.w	#1,d6
		cmp.w	xw,d6
		bne.s	sbnextbyte
		move.w	#0,d6

		add.w	#1,d5
		cmp.w	#5,d5
		bne.s	sbnextrow
		move.w	#0,d5

		add.w	#1,d4
		cmp.w	height,d4
		bne.s	sbnextrow

		move.l	form,d3
		move.l	filehandle,d1
		move.l	MemfBase,d2
		move.l	_DosBase,a6
		JSR	Write(a6)

		move.l	form,d0
		move.l	MemfBase,a1
		CALLEXEC	FreeMem	;deallocatemem

finishedsave		
		move.l	#150,d1
		move.l	_DosBase,a6
		JSR	Delay(a6)
		move.l	filehandle,d1	;pointer to file
		move.l	_DosBase,a6	;dos.library
		JSR	Close(a6)	;close file

		cmp.b	#1,icons
		bne.s	siffrc

		move.l	#iffbrushsize,form+4
		move.l	#iffbrushinfo,form
		bsr	makeinfoname

siffrc		rts			;and exit

sbcantopen	lea	error12,a2
		move.l	a2,form+4
		bsr	errorreport
		rts

;-------

readinteger	move.l	a0,d2
		move.l	filehandle,d1
		move.l	#2,d3
		move.l	_DosBase,a6
		JSR	Read(a6)
		move.w	(a0),d0
		bsr	CVI
		move.w	d0,(a0)
		rts

readascii	move.l	a0,d2
		move.l	filehandle,d1
		move.l	#1,d3
		move.l	_DosBase,a6
		JSR	Read(a6)
		rts

CVL	move.l	d0,d1	;d0=first byte to d3=4th byte
	move.l	d1,d2
	move.l	d2,d3

	asr.l	#7,d0	;move bits right
	asr.l	#7,d0
	asr.l	#7,d0
	asr.l	#3,d0	;last 8 bits needed
	and.l	#$ff,d0

	asr.l	#7,d1	;move bits right
	asr.l	#7,d1
	asr.l	#2,d1	;2nd to last 8 needed
	and.l	#$ff,d1	;get rid of top 8

	asr.l	#7,d2	;move bits
	asr.l	#1,d2	;3rd to last 8
	and.l	#$ff,d2	;get rid of top 16

	and.l	#$ff,d3	;bottom 8 needed

	ext.l	d0
	ext.l	d1
	ext.l	d2
	ext.l	d3

	asl.l	#7,d2		;multiply 3rd char by 256
	asl.l	#1,d2
	asl.l	#7,d1
	asl.l	#7,d1		;multiply 2nd char by 65536
	asl.l	#2,d1
	asl.l	#7,d0
	asl.l	#7,d0
	asl.l	#7,d0		;multiply 1st char by 16777216!
	asl.l	#3,d0

	add.l	d1,d0
	add.l	d2,d0
	add.l	d3,d0	;create full total

	rts

CVI	move.l	d0,d1	;d0=first byte to d1=2nd byte

	lsr.l	#7,d0	;move bits
	lsr.l	#1,d0	;3rd to last 8
	and.l	#$ff,d0	;get rid of top 16

	and.l	#$ff,d1	;bottom 8 needed

	mulu	#$100,d0	;multiply 2nd char by 256

	add.l	d1,d0	;create full total

	rts

MKI	move.w	d0,d1	;backup of value
	asr.w	#7,d1	;divide by 256 for total
	asr.w	#1,d1
	and.w	#$ff,d0
	and.w	#$ff,d1
	move.b	d1,mkstring
	move.b	d0,mkstring+1
	move.b	#0,mkstring+2

	rts

MKL	move.l	d0,d1
	and.l	#$ffff,d0
	move.w	d0,d2
	asr.w	#7,d2
	asr.w	#1,d2
	and.w	#$ff,d0
	and.w	#$ff,d2
	move.b	d0,mkstring+3
	move.b	d2,mkstring+2
	swap	d1
	and.l	#$ffff,d1
	move.w	d1,d0
	asr.w	#7,d1
	asr.w	#1,d1
	and.w	#$ff,d1
	and.w	#$ff,d0
	move.b	d0,mkstring+1
	move.b	d1,mkstring

	rts

mkstring	dc.b	'0000',0
		even

redraw	move.w	sx,d5
	move.w	widf,d6
	sub.w	across,d6
	cmp.w	d5,d6
	bhi.s	sxok
	move.w	d6,sx
sxok	move.w	sy,d5
	move.w	height,d6
	sub.w	down,d6
	cmp.w	d5,d6
	bhi.s	syok
	move.w	d6,sy
syok
	move.w	across,d5	;end x
	move.w	down,d6		;end y
	add.w	sx,d5
	add.w	sy,d6
	move.w	d5,ex
	move.w	d6,ey
	move.l	#1,d4
	move.w	sx,d5
	move.w	#11,rx
	move.w	#11,d7
	add.w	xgap,d7
	sub.w	#2,d7
	move.w	d7,rx1
rloop1	move.w	sy,d6
	move.w	#11,ry
	move.w	#11,d7
	add.w	ygap,d7
	sub.w	#2,d7
	move.w	d7,ry1
rloop2	move.w	#144,d0
	add.w	d5,d0
	move.w	#12,d1
	add.w	d6,d1
	ext.l	d0
	ext.l	d1
	move.l	rastport,a1
	move.l	_GfxBase,a6
	JSR	ReadPixel(a6)
	bsr	setcolour
	move.w	rx,d0
	move.w	rx1,d2
	move.w	ry1,d3
	move.w	ry,d1
	bsr	rectangle
	move.w	ygap,d7
	add.w	d7,ry
	add.w	d7,ry1
	add.w	#1,d6
	cmp.w	ey,d6
	bne	rloop2
	move.w	xgap,d7
	add.w	d7,rx
	add.w	d7,rx1
	add.w	#1,d5
	cmp.w	ex,d5
	bne	rloop1
	move.w	col,d0
	move.l	_GfxBase,a6
	move.l	rastport,a1
	JSR	SetAPen(a6)
	rts



; Screen, window, gadget, menu etc. structures follow

newscreen	dc.w	0		;leftedge (should be 0)
		dc.w	0		;topedge (number of pixels from top)
		dc.w	320,200		;width, height
		dc.w	5		;number of bitplanes
		dc.b	2		;detail pen
		dc.b	1		;block pen
		dc.w	0		;viewmodes
		dc.w	CUSTOMSCREEN	;Workbench/custom
		dc.l	0		;pointer to font
		dc.l	mytitle		;pointer to screen title
		dc.l	0		;gadgets
		dc.l	0		;pointer to custom bitmap

scrnbase	dc.l	0

mytitle	dc.b	'Gin',39,'s Mega Object Edita V3.1',0
	even

newwindow	dc.w	0		;leftedge
		dc.w	8		;topedge
		dc.w	320,192		;width,height
		dc.b	2		;detail pen
		dc.b	1		;block pen
		dc.l	$548		;IDCMP flags(MENUPICK+GADGETUP+MOUSEBUTTONS+RAWKEY)
		dc.l	WINDOWBITS	;Standard Gadgets (e.g closewindow)
		dc.l	gadget		;pointer to first gadget structure
		dc.l	0		;pointer to custom menu tick
		dc.l	0		;pointer to title text,0
 		dc.l	0		;pointer to custom screen
		dc.l	0		;pointer to custom bitmap
		dc.w	320,192		;minimum width,height
		dc.w	320,192		;maximum width,height
		dc.w	CUSTOMSCREEN	;type of screen

windowbase	dc.l	0
rastport	dc.l	0
userport	dc.l	0
viewport	dc.l	0

newwindow2	dc.w	0		;leftedge
		dc.w	10		;topedge
		dc.w	320,50		;width,height
		dc.b	2		;detail pen
		dc.b	1		;block pen
		dc.l	$40		;IDCMP flags(GADGETUP)
		dc.l	$1040		;Standard Gadgets (e.g closewindow)
		dc.l	strgadget	;pointer to first gadget structure
		dc.l	0		;pointer to custom menu tick
wtitle		dc.l	title2		;pointer to title text,0
 		dc.l	0		;pointer to custom screen
		dc.l	0		;pointer to custom bitmap
		dc.w	320,40		;minimum width,height
		dc.w	320,40		;maximum width,height
		dc.w	CUSTOMSCREEN	;type of screen

windowbase2	dc.l	0

title2	dc.b	'Open File..',0
	even

title3	dc.b	'Save File..',0
	even

sdtitle	dc.b	'Save Data..',0
	even

intname	dc.b	'intuition.library',0
	even

_IntuitionBase	dc.l	0

gfxname	dc.b	'graphics.library',0
	even

_GfxBase	dc.l	0

mathname	dc.b	'mathffp.library',0
		even

_MathBase	dc.l	0

palette		dc.w	$000,$fff,$f00,$800,$f80,$ff0,$0f0,$080
		dc.w	$088,$0ff,$00f,$008,$f0f,$f08,$80f,$841
		dc.w	$520,$e52,$a52,$fca,$444,$555,$666,$777
		dc.w	$888,$999,$aaa,$bbb,$ccc,$ddd,$eee,$fff

numcols		equ	*-palette

backuppalette	dc.w	$000,$fff,$f00,$800,$f80,$ff0,$0f0,$080
		dc.w	$088,$0ff,$00f,$008,$f0f,$f08,$80f,$841
		dc.w	$520,$e52,$a52,$fca,$444,$555,$666,$777
		dc.w	$888,$999,$aaa,$bbb,$ccc,$ddd,$eee,$fff

brushpalette	dc.w	$000,$fff,$f00,$800,$f80,$ff0,$0f0,$080
		dc.w	$088,$0ff,$00f,$008,$f0f,$f08,$80f,$841
		dc.w	$520,$e52,$a52,$fca,$444,$555,$666,$777
		dc.w	$888,$999,$aaa,$bbb,$ccc,$ddd,$eee,$fff

mytext	dc.b	'A Longer String! ##@@##',0
	even

text		dc.b	2		;foreground colour
		dc.b	3		;background colour
		dc.b	1		;draw mode (JAM2)
		dc.b	0		;pad
		dc.w	0,3		;x,y position
		dc.l	0		;pointer to font
		dc.l	mytext		;pointer to text string
		dc.l	0		;pointer to next intuitext structure

gadget		dc.l	gadgetR		;pointer to next gadget structure
		dc.w	275,5		;x,y position of gadget
		dc.w	36,10		;width,height of gadget
		dc.w	GADGBITS	;highlighting and rendering flags
		dc.w	GADGACTIVE	;event communication flags
		dc.w	BOOLGADGET	;type of gadget
		dc.l	border		;pointer to custom image/border
		dc.l	0		;pointer to custom selected image/border
		dc.l	gadgettext	;pointer to gadget text (intuitext structure)
		dc.l	0		;mutual excludes for gadget activation
		dc.l	0		;special info
		dc.w	1		;user definable data word
		dc.l	0		;pointer to user data area

gadgettext	dc.b	6		;foreground colour
		dc.b	0		;background colour
		dc.b	0		;draw mode (JAM1)
		dc.b	0		;pad
		dc.w	2,1		;x,y position
		dc.l	0		;pointer to font
		dc.l	gadgtext	;pointer to text string
		dc.l	0		;pointer to next intuitext structure

border		dc.w	0		;leftedge
		dc.w	0		;topedge
		dc.b	8		;frontpen
		dc.b	0		;backpen
		dc.b	0		;draw mode
		dc.b	5		;no. of points in co-ord list
		dc.l	buttonlines	;pointer to co-ord list
		dc.l	0		;next border

buttonlines	dc.w	-1,-1,36,-1,36,10,-1,10,-1,-1	;x0,y0 x1,y1 etc

gadgtext	dc.b	'Quit',0
		even

R	dc.b	'R',0
	even
G	dc.b	'G',0
	even
B	dc.b	'B',0
	even

objecttitle	dc.b	'Object',0
		even

gadgetR		dc.l	gadgetG		;pointer to next gadget structure
		dc.w	205,158		;x,y position of gadget
		dc.w	100,10		;width,height of gadget
		dc.w	0		;GADGHNONE (No activation change)
		dc.w	1		;event communication flags (Relverify)
		dc.w	PROPGADGET	;type of gadget
		dc.l	imageR		;pointer to custom image/border
		dc.l	0		;pointer to custom selected image/border
		dc.l	0		;pointer to gadget text (intuitext structure)
		dc.l	0		;mutual excludes for gadget activation
		dc.l	gadgRspecinfo	;special info
		dc.w	2		;user definable data word
		dc.l	0		;pointer to user data area

gadgRspecinfo	dc.w	3		;AUTOKNOB+FREEHORIZ
		dc.w	0,-1		;Horizontal,vertical pot values
		dc.w	($FFFF/16),-1	;Horizontal,vertical body values (i.e range)
		dc.w	0		;container width
		dc.w	0		;container height
		dc.w	0		;HPotRes, X increments
		dc.w	0		;YPotRes, Y increments
		dc.w	0		;left border
		dc.w	0		;top border

imageR		dc.w	0,0		;x,y origin
		dc.w	11,6		;width,height
		dc.w	0		;number of bitplanes
		dc.l	0		;pointer to image data
		dc.b	0,0		;planepick,planeonoff
		dc.l	imageG		;next image structure

gadgetG		dc.l	gadgetB		;pointer to next gadget structure
		dc.w	205,170		;x,y position of gadget
		dc.w	100,10		;width,height of gadget
		dc.w	3		;GADGHNONE (No activation change)
		dc.w	1		;event communication flags (Relverify)
		dc.w	PROPGADGET	;type of gadget
		dc.l	imageG		;pointer to custom image/border
		dc.l	0		;pointer to custom selected image/border
		dc.l	0		;pointer to gadget text (intuitext structure)
		dc.l	0		;mutual excludes for gadget activation
		dc.l	gadgGspecinfo	;special info
		dc.w	3		;user definable data word
		dc.l	0		;pointer to user data area

gadgGspecinfo	dc.w	3		;AUTOKNOB+FREEHORIZ
		dc.w	0,-1		;Horizontal,vertical pot values
		dc.w	($FFFF/16),-1	;Horizontal,vertical body values (i.e range)
		dc.w	0		;container width
		dc.w	0		;container height
		dc.w	0		;HPotRes, X increments
		dc.w	0		;YPotRes, Y increments
		dc.w	0		;left border
		dc.w	0		;top border

imageG		dc.w	0,0		;x,y origin
		dc.w	11,6		;width,height
		dc.w	0		;number of bitplanes
		dc.l	0		;pointer to image data
		dc.b	0,0		;planepick,planeonoff
		dc.l	imageB		;next image structure
		
gadgetB		dc.l	0		;pointer to next gadget structure
		dc.w	205,182		;x,y position of gadget
		dc.w	100,10		;width,height of gadget
		dc.w	3		;GADGHNONE (No activation change)
		dc.w	1		;event communication flags (Relverify)
		dc.w	PROPGADGET	;type of gadget
		dc.l	imageB		;pointer to custom image/border
		dc.l	0		;pointer to custom selected image/border
		dc.l	0		;pointer to gadget text (intuitext structure)
		dc.l	0		;mutual excludes for gadget activation
		dc.l	gadgBspecinfo	;special info
		dc.w	4		;user definable data word
		dc.l	0		;pointer to user data area

gadgBspecinfo	dc.w	3		;AUTOKNOB+FREEHORIZ
		dc.w	0,-1		;Horizontal,vertical pot values
		dc.w	($FFFF/16),-1	;Horizontal,vertical body values (i.e range)
		dc.w	0		;container width
		dc.w	0		;container height
		dc.w	0		;HPotRes, X increments
		dc.w	0		;YPotRes, Y increments
		dc.w	0		;left border
		dc.w	0		;top border

imageB		dc.w	0,0		;x,y origin
		dc.w	11,6		;width,height
		dc.w	0		;number of bitplanes
		dc.l	0		;pointer to image data
		dc.b	0,0		;planepick,planeonoff
		dc.l	0		;next image structure

projectmenu	dc.l	palettemenu	;pointer to next menu
		dc.w	2,0		;leftedge,topedge
		dc.w	72		;width of menu
		dc.w	8		;height of each item
		dc.w	1		;MENUENABLED
		dc.l	projectname	;menu name,0
		dc.l	new		;Pointer to first MENUITEM structure
		dc.w	0,0		;JAZZX,JAZZY
		dc.w	0,0		;BEATX,BEATY

projectname	dc.b	'PROJECT',0
		even

new		dc.l	open		;Pointer to next menuitem structure
		dc.w	0,0		;leftedge,topedge
		dc.w	72,8		;width,height
		dc.w	$52		;flags (HIGHCOMP+ITEMENABLED+ITEMTEXT)
		dc.l	0		;mutual excludes
		dc.l	newname		;pointer to INTUITEXT structure for name
		dc.l	0		;pointer to select text or image
		dc.b	0		;command key
		dc.b	0		;pad
		dc.l	0		;pointer to subitem MENUITEM structure
		dc.w	0		;menu number of simultaneous selection

newname		dc.b	2		;foreground colour
		dc.b	1		;background colour
		dc.b	1		;draw mode (JAM2)
		dc.b	0		;pad
		dc.w	0,0		;x,y position
		dc.l	0		;pointer to font
		dc.l	newtext		;pointer to text string
		dc.l	0		;pointer to next intuitext structure

newtext		dc.b	'New',0
		even

open		dc.l	openanim	;Pointer to next menuitem structure
		dc.w	0,9		;leftedge,topedge
		dc.w	72,8		;width,height
		dc.w	$52		;flags (HIGHCOMP+ITEMENABLED+ITEMTEXT)
		dc.l	0		;mutual excludes
		dc.l	openname	;pointer to INTUITEXT structure for name
		dc.l	0		;pointer to select text or image
		dc.b	0		;command key
		dc.b	0		;pad
		dc.l	0		;pointer to subitem MENUITEM structure
		dc.w	0		;menu number of simultaneous selection

openname	dc.b	2		;foreground colour
		dc.b	1		;background colour
		dc.b	1		;draw mode (JAM2)
		dc.b	0		;pad
		dc.w	0,0		;x,y position
		dc.l	0		;pointer to font
		dc.l	opentext	;pointer to text string
		dc.l	0		;pointer to next intuitext structure

opentext	dc.b	'Open',0
		even

openanim	dc.l	save		;Pointer to next menuitem structure
		dc.w	0,18		;leftedge,topedge
		dc.w	72,8		;width,height
		dc.w	$52		;flags (HIGHCOMP+ITEMENABLED+ITEMTEXT)
		dc.l	0		;mutual excludes
		dc.l	openanimname	;pointer to INTUITEXT structure for name
		dc.l	0		;pointer to select text or image
		dc.b	0		;command key
		dc.b	0		;pad
		dc.l	0		;pointer to subitem MENUITEM structure
		dc.w	0		;menu number of simultaneous selection

openanimname	dc.b	2		;foreground colour
		dc.b	1		;background colour
		dc.b	1		;draw mode (JAM2)
		dc.b	0		;pad
		dc.w	0,0		;x,y position
		dc.l	0		;pointer to font
		dc.l	openanimtext	;pointer to text string
		dc.l	0		;pointer to next intuitext structure

openanimtext	dc.b	'Open Anim',0
		even

save		dc.l	savedata	;Pointer to next menuitem structure
		dc.w	0,27		;leftedge,topedge
		dc.w	72,8		;width,height
		dc.w	$52		;flags (HIGHCOMP+ITEMENABLED+ITEMTEXT)
		dc.l	0		;mutual excludes
		dc.l	savename	;pointer to INTUITEXT structure for name
		dc.l	0		;pointer to select text or image
		dc.b	0		;command key
		dc.b	0		;pad
		dc.l	0		;pointer to subitem MENUITEM structure
		dc.w	0		;menu number of simultaneous selection

savename	dc.b	2		;foreground colour
		dc.b	1		;background colour
		dc.b	1		;draw mode (JAM2)
		dc.b	0		;pad
		dc.w	0,0		;x,y position
		dc.l	0		;pointer to font
		dc.l	savetext	;pointer to text string
		dc.l	0		;pointer to next intuitext structure

savetext	dc.b	'Save',0
		even

savedata	dc.l	saveanim	;Pointer to next menuitem structure
		dc.w	0,36	 	;leftedge,topedge
		dc.w	72,8		;width,height
		dc.w	$52		;flags (HIGHCOMP+ITEMENABLED+ITEMTEXT)
		dc.l	0		;mutual excludes
		dc.l	savedataname	;pointer to INTUITEXT structure for name
		dc.l	0		;pointer to select text or image
		dc.b	0		;command key
		dc.b	0		;pad
		dc.l	0		;pointer to subitem MENUITEM structure
		dc.w	0		;menu number of simultaneous selection

savedataname	dc.b	2		;foreground colour
		dc.b	1		;background colour
		dc.b	1		;draw mode (JAM2)
		dc.b	0		;pad
		dc.w	0,0		;x,y position
		dc.l	0		;pointer to font
		dc.l	savedatatext	;pointer to text string
		dc.l	0		;pointer to next intuitext structure

savedatatext	dc.b	'Save Data',0
		even

saveanim	dc.l	about		;Pointer to next menuitem structure
		dc.w	0,45	 	;leftedge,topedge
		dc.w	72,8		;width,height
		dc.w	$52		;flags (HIGHCOMP+ITEMENABLED+ITEMTEXT)
		dc.l	0		;mutual excludes
		dc.l	saveanimname	;pointer to INTUITEXT structure for name
		dc.l	0		;pointer to select text or image
		dc.b	0		;command key
		dc.b	0		;pad
		dc.l	0		;pointer to subitem MENUITEM structure
		dc.w	0		;menu number of simultaneous selection

saveanimname	dc.b	2		;foreground colour
		dc.b	1		;background colour
		dc.b	1		;draw mode (JAM2)
		dc.b	0		;pad
		dc.w	0,0		;x,y position
		dc.l	0		;pointer to font
		dc.l	saveanimtext	;pointer to text string
		dc.l	0		;pointer to next intuitext structure

saveanimtext	dc.b	'Save Anim',0
		even

about		dc.l	quit		;Pointer to next menuitem structure
		dc.w	0,54		;leftedge,topedge
		dc.w	72,8		;width,height
		dc.w	$52		;flags (HIGHCOMP+ITEMENABLED+ITEMTEXT)
		dc.l	0		;mutual excludes
		dc.l	aboutname	;pointer to INTUITEXT structure for name
		dc.l	0		;pointer to select text or image
		dc.b	0		;command key
		dc.b	0		;pad
		dc.l	0		;pointer to subitem MENUITEM structure
		dc.w	0		;menu number of simultaneous selection

aboutname	dc.b	2		;foreground colour
		dc.b	1		;background colour
		dc.b	1		;draw mode (JAM2)
		dc.b	0		;pad
		dc.w	0,0		;x,y position
		dc.l	0		;pointer to font
		dc.l	abouttext	;pointer to text string
		dc.l	0		;pointer to next intuitext structure

abouttext	dc.b	'About',0
		even

quit		dc.l	0		;Pointer to next menuitem structure
		dc.w	0,66		;leftedge,topedge
		dc.w	72,8		;width,height
		dc.w	$52		;flags (HIGHCOMP+ITEMENABLED+ITEMTEXT)
		dc.l	0		;mutual excludes
		dc.l	quitname	;pointer to INTUITEXT structure for name
		dc.l	0		;pointer to select text or image
		dc.b	0		;command key
		dc.b	0		;pad
		dc.l	0		;pointer to subitem MENUITEM structure
		dc.w	0		;menu number of simultaneous selection

quitname	dc.b	2		;foreground colour
		dc.b	1		;background colour
		dc.b	1		;draw mode (JAM2)
		dc.b	0		;pad
		dc.w	0,0		;x,y position
		dc.l	0		;pointer to font
		dc.l	quittext	;pointer to text string
		dc.l	0		;pointer to next intuitext structure

quittext	dc.b	'Quit!',0
		even

palettemenu	dc.l	objectmenu	;pointer to next menu
		dc.w	76,0		;leftedge,topedge
		dc.w	72		;width of menu
		dc.w	8		;height of each item
		dc.w	1		;MENUENABLED
		dc.l	palettename	;menu name,0
		dc.l	mcopy		;Pointer to first MENUITEM structure
		dc.w	0,0		;JAZZX,JAZZY
		dc.w	0,0		;BEATX,BEATY

palettename	dc.b	'PALETTE',0
		even

mcopy		dc.l	mix		;Pointer to next menuitem structure
		dc.w	0,0		;leftedge,topedge
		dc.w	72,8		;width,height
		dc.w	$52		;flags (HIGHCOMP+ITEMENABLED+ITEMTEXT)
		dc.l	0		;mutual excludes
		dc.l	copyname	;pointer to INTUITEXT structure for name
		dc.l	0		;pointer to select text or image
		dc.b	0		;command key
		dc.b	0		;pad
		dc.l	0		;pointer to subitem MENUITEM structure
		dc.w	0		;menu number of simultaneous selection

copyname	dc.b	2		;foreground colour
		dc.b	1		;background colour
		dc.b	1		;draw mode (JAM2)
		dc.b	0		;pad
		dc.w	0,0		;x,y position
		dc.l	0		;pointer to font
		dc.l	copytext	;pointer to text string
		dc.l	0		;pointer to next intuitext structure

copytext	dc.b	'Copy',0
		even

mix		dc.l	range		;Pointer to next menuitem structure
		dc.w	0,9		;leftedge,topedge
		dc.w	72,8		;width,height
		dc.w	$52		;flags (HIGHCOMP+ITEMENABLED+ITEMTEXT)
		dc.l	0		;mutual excludes
		dc.l	mixname		;pointer to INTUITEXT structure for name
		dc.l	0		;pointer to select text or image
		dc.b	0		;command key
		dc.b	0		;pad
		dc.l	0		;pointer to subitem MENUITEM structure
		dc.w	0		;menu number of simultaneous selection

mixname		dc.b	2		;foreground colour
		dc.b	1		;background colour
		dc.b	1		;draw mode (JAM2)
		dc.b	0		;pad
		dc.w	0,0		;x,y position
		dc.l	0		;pointer to font
		dc.l	mixtext		;pointer to text string
		dc.l	0		;pointer to next intuitext structure

mixtext		dc.b	'Mix',0
		even

range		dc.l	store		;Pointer to next menuitem structure
		dc.w	0,18		;leftedge,topedge
		dc.w	72,8		;width,height
		dc.w	$52		;flags (HIGHCOMP+ITEMENABLED+ITEMTEXT)
		dc.l	0		;mutual excludes
		dc.l	rangename	;pointer to INTUITEXT structure for name
		dc.l	0		;pointer to select text or image
		dc.b	0		;command key
		dc.b	0		;pad
		dc.l	0		;pointer to subitem MENUITEM structure
		dc.w	0		;menu number of simultaneous selection

rangename	dc.b	2		;foreground colour
		dc.b	1		;background colour
		dc.b	1		;draw mode (JAM2)
		dc.b	0		;pad
		dc.w	0,0		;x,y position
		dc.l	0		;pointer to font
		dc.l	rangetext	;pointer to text string
		dc.l	0		;pointer to next intuitext structure

rangetext	dc.b	'Range',0
		even

store		dc.l	restore		;Pointer to next menuitem structure
		dc.w	0,32		;leftedge,topedge
		dc.w	72,8		;width,height
		dc.w	$52		;flags (HIGHCOMP+ITEMENABLED+ITEMTEXT)
		dc.l	0		;mutual excludes
		dc.l	storename	;pointer to INTUITEXT structure for name
		dc.l	0		;pointer to select text or image
		dc.b	0		;command key
		dc.b	0		;pad
		dc.l	0		;pointer to subitem MENUITEM structure
		dc.w	0		;menu number of simultaneous selection

storename	dc.b	2		;foreground colour
		dc.b	1		;background colour
		dc.b	1		;draw mode (JAM2)
		dc.b	0		;pad
		dc.w	0,0		;x,y position
		dc.l	0		;pointer to font
		dc.l	storetext	;pointer to text string
		dc.l	0		;pointer to next intuitext structure

storetext	dc.b	'Store',0
		even

restore		dc.l	brushp		;Pointer to next menuitem structure
		dc.w	0,41		;leftedge,topedge
		dc.w	72,8		;width,height
		dc.w	$52		;flags (HIGHCOMP+ITEMENABLED+ITEMTEXT)
		dc.l	0		;mutual excludes
		dc.l	restorename	;pointer to INTUITEXT structure for name
		dc.l	0		;pointer to select text or image
		dc.b	0		;command key
		dc.b	0		;pad
		dc.l	0		;pointer to subitem MENUITEM structure
		dc.w	0		;menu number of simultaneous selection

restorename	dc.b	2		;foreground colour
		dc.b	1		;background colour
		dc.b	1		;draw mode (JAM2)
		dc.b	0		;pad
		dc.w	0,0		;x,y position
		dc.l	0		;pointer to font
		dc.l	restoretext	;pointer to text string
		dc.l	0		;pointer to next intuitext structure

restoretext	dc.b	'Restore',0
		even

brushp		dc.l	0		;Pointer to next menuitem structure
		dc.w	0,50		;leftedge,topedge
		dc.w	72,8		;width,height
		dc.w	$52		;flags (HIGHCOMP+ITEMENABLED+ITEMTEXT)
		dc.l	0		;mutual excludes
		dc.l	brushname	;pointer to INTUITEXT structure for name
		dc.l	0		;pointer to select text or image
		dc.b	0		;command key
		dc.b	0		;pad
		dc.l	0		;pointer to subitem MENUITEM structure
		dc.w	0		;menu number of simultaneous selection

brushname	dc.b	2		;foreground colour
		dc.b	1		;background colour
		dc.b	1		;draw mode (JAM2)
		dc.b	0		;pad
		dc.w	0,0		;x,y position
		dc.l	0		;pointer to font
		dc.l	brushtext	;pointer to text string
		dc.l	0		;pointer to next intuitext structure

brushtext	dc.b	'Brush',0
		even

objectmenu	dc.l	specialmenu	;pointer to next menu
		dc.w	148,0		;leftedge,topedge
		dc.w	72		;width of menu
		dc.w	8		;height of each item
		dc.w	1		;MENUENABLED
		dc.l	objectname	;menu name,0
		dc.l	objstore	;Pointer to first MENUITEM structure
		dc.w	0,0		;JAZZX,JAZZY
		dc.w	0,0		;BEATX,BEATY

objectname	dc.b	'OBJECT',0
		even

objstore	dc.l	objcopy		;Pointer to next menuitem structure
		dc.w	0,0		;leftedge,topedge
		dc.w	72,8		;width,height
		dc.w	$52		;flags (HIGHCOMP+ITEMENABLED+ITEMTEXT)
		dc.l	0		;mutual excludes
		dc.l	ostorename	;pointer to INTUITEXT structure for name
		dc.l	0		;pointer to select text or image
		dc.b	0		;command key
		dc.b	0		;pad
		dc.l	0		;pointer to subitem MENUITEM structure
		dc.w	0		;menu number of simultaneous selection

ostorename	dc.b	2		;foreground colour
		dc.b	1		;background colour
		dc.b	1		;draw mode (JAM2)
		dc.b	0		;pad
		dc.w	0,0		;x,y position
		dc.l	0		;pointer to font
		dc.l	ostoretext	;pointer to text string
		dc.l	0		;pointer to next intuitext structure

ostoretext	dc.b	'Store',0
		even

objcopy		dc.l	objcopyl	;Pointer to next menuitem structure
		dc.w	0,9		;leftedge,topedge
		dc.w	72,8		;width,height
		dc.w	$52		;flags (HIGHCOMP+ITEMENABLED+ITEMTEXT)
		dc.l	0		;mutual excludes
		dc.l	ocopyname	;pointer to INTUITEXT structure for name
		dc.l	0		;pointer to select text or image
		dc.b	0		;command key
		dc.b	0		;pad
		dc.l	0		;pointer to subitem MENUITEM structure
		dc.w	0		;menu number of simultaneous selection

ocopyname	dc.b	2		;foreground colour
		dc.b	1		;background colour
		dc.b	1		;draw mode (JAM2)
		dc.b	0		;pad
		dc.w	0,0		;x,y position
		dc.l	0		;pointer to font
		dc.l	ocopytext	;pointer to text string
		dc.l	0		;pointer to next intuitext structure

ocopytext	dc.b	'Copy',0
		even

objcopyl	dc.l	objdelete	;Pointer to next menuitem structure
		dc.w	0,18		;leftedge,topedge
		dc.w	72,8		;width,height
		dc.w	$52		;flags (HIGHCOMP+ITEMENABLED+ITEMTEXT)
		dc.l	0		;mutual excludes
		dc.l	ocopylname	;pointer to INTUITEXT structure for name
		dc.l	0		;pointer to select text or image
		dc.b	0		;command key
		dc.b	0		;pad
		dc.l	0		;pointer to subitem MENUITEM structure
		dc.w	0		;menu number of simultaneous selection

ocopylname	dc.b	2		;foreground colour
		dc.b	1		;background colour
		dc.b	1		;draw mode (JAM2)
		dc.b	0		;pad
		dc.w	0,0		;x,y position
		dc.l	0		;pointer to font
		dc.l	ocopyltext	;pointer to text string
		dc.l	0		;pointer to next intuitext structure

ocopyltext	dc.b	'Copy Last',0
		even

objdelete	dc.l	objinsert	;Pointer to next menuitem structure
		dc.w	0,27		;leftedge,topedge
		dc.w	72,8		;width,height
		dc.w	$52		;flags (HIGHCOMP+ITEMENABLED+ITEMTEXT)
		dc.l	0		;mutual excludes
		dc.l	odeletename	;pointer to INTUITEXT structure for name
		dc.l	0		;pointer to select text or image
		dc.b	0		;command key
		dc.b	0		;pad
		dc.l	0		;pointer to subitem MENUITEM structure
		dc.w	0		;menu number of simultaneous selection

odeletename	dc.b	2		;foreground colour
		dc.b	1		;background colour
		dc.b	1		;draw mode (JAM2)
		dc.b	0		;pad
		dc.w	0,0		;x,y position
		dc.l	0		;pointer to font
		dc.l	odeletetext	;pointer to text string
		dc.l	0		;pointer to next intuitext structure

odeletetext	dc.b	'Delete',0
		even

objinsert	dc.l	objanimate	;Pointer to next menuitem structure
		dc.w	0,36		;leftedge,topedge
		dc.w	72,8		;width,height
		dc.w	$52		;flags (HIGHCOMP+ITEMENABLED+ITEMTEXT)
		dc.l	0		;mutual excludes
		dc.l	oinsertname	;pointer to INTUITEXT structure for name
		dc.l	0		;pointer to select text or image
		dc.b	0		;command key
		dc.b	0		;pad
		dc.l	0		;pointer to subitem MENUITEM structure
		dc.w	0		;menu number of simultaneous selection

oinsertname	dc.b	2		;foreground colour
		dc.b	1		;background colour
		dc.b	1		;draw mode (JAM2)
		dc.b	0		;pad
		dc.w	0,0		;x,y position
		dc.l	0		;pointer to font
		dc.l	oinserttext	;pointer to text string
		dc.l	0		;pointer to next intuitext structure

oinserttext	dc.b	'Insert',0
		even

objanimate	dc.l	objjumpto	;Pointer to next menuitem structure
		dc.w	0,49		;leftedge,topedge
		dc.w	72,8		;width,height
		dc.w	$52		;flags (HIGHCOMP+ITEMENABLED+ITEMTEXT)
		dc.l	0		;mutual excludes
		dc.l	oanimatename	;pointer to INTUITEXT structure for name
		dc.l	0		;pointer to select text or image
		dc.b	0		;command key
		dc.b	0		;pad
		dc.l	0		;pointer to subitem MENUITEM structure
		dc.w	0		;menu number of simultaneous selection

oanimatename	dc.b	2		;foreground colour
		dc.b	1		;background colour
		dc.b	1		;draw mode (JAM2)
		dc.b	0		;pad
		dc.w	0,0		;x,y position
		dc.l	0		;pointer to font
		dc.l	oanimatetext	;pointer to text string
		dc.l	0		;pointer to next intuitext structure

oanimatetext	dc.b	'Animate',0
		even

objjumpto	dc.l	objjumpfst	;Pointer to next menuitem structure
		dc.w	0,60		;leftedge,topedge
		dc.w	72,8		;width,height
		dc.w	$52		;flags (HIGHCOMP+ITEMENABLED+ITEMTEXT)
		dc.l	0		;mutual excludes
		dc.l	ojumpname	;pointer to INTUITEXT structure for name
		dc.l	0		;pointer to select text or image
		dc.b	0		;command key
		dc.b	0		;pad
		dc.l	0		;pointer to subitem MENUITEM structure
		dc.w	0		;menu number of simultaneous selection

ojumpname	dc.b	2		;foreground colour
		dc.b	1		;background colour
		dc.b	1		;draw mode (JAM2)
		dc.b	0		;pad
		dc.w	0,0		;x,y position
		dc.l	0		;pointer to font
		dc.l	ojumptext	;pointer to text string
		dc.l	0		;pointer to next intuitext structure

ojumptext	dc.b	'Jump Bfr',0
		even

objjumpfst	dc.l	objjumplst	;Pointer to next menuitem structure
		dc.w	0,69		;leftedge,topedge
		dc.w	72,8		;width,height
		dc.w	$52		;flags (HIGHCOMP+ITEMENABLED+ITEMTEXT)
		dc.l	0		;mutual excludes
		dc.l	ojump1name	;pointer to INTUITEXT structure for name
		dc.l	0		;pointer to select text or image
		dc.b	0		;command key
		dc.b	0		;pad
		dc.l	0		;pointer to subitem MENUITEM structure
		dc.w	0		;menu number of simultaneous selection

ojump1name	dc.b	2		;foreground colour
		dc.b	1		;background colour
		dc.b	1		;draw mode (JAM2)
		dc.b	0		;pad
		dc.w	0,0		;x,y position
		dc.l	0		;pointer to font
		dc.l	ojump1text	;pointer to text string
		dc.l	0		;pointer to next intuitext structure

ojump1text	dc.b	'Jump 1st',0
		even

objjumplst	dc.l	0		;Pointer to next menuitem structure
		dc.w	0,78		;leftedge,topedge
		dc.w	72,8		;width,height
		dc.w	$52		;flags (HIGHCOMP+ITEMENABLED+ITEMTEXT)
		dc.l	0		;mutual excludes
		dc.l	ojump2name	;pointer to INTUITEXT structure for name
		dc.l	0		;pointer to select text or image
		dc.b	0		;command key
		dc.b	0		;pad
		dc.l	0		;pointer to subitem MENUITEM structure
		dc.w	0		;menu number of simultaneous selection

ojump2name	dc.b	2		;foreground colour
		dc.b	1		;background colour
		dc.b	1		;draw mode (JAM2)
		dc.b	0		;pad
		dc.w	0,0		;x,y position
		dc.l	0		;pointer to font
		dc.l	ojump2text	;pointer to text string
		dc.l	0		;pointer to next intuitext structure

ojump2text	dc.b	'Jump Last',0
		even

specialmenu	dc.l	0		;pointer to next menu
		dc.w	220,0		;leftedge,topedge
		dc.w	72		;width of menu
		dc.w	8		;height of each item
		dc.w	1		;MENUENABLED
		dc.l	specialname	;menu name,0
		dc.l	spcleft		;Pointer to first MENUITEM structure
		dc.w	0,0		;JAZZX,JAZZY
		dc.w	0,0		;BEATX,BEATY

specialname	dc.b	'SPECIAL',0
		even

spcleft		dc.l	spcright	;Pointer to next menuitem structure
		dc.w	0,0		;leftedge,topedge
		dc.w	72,8		;width,height
		dc.w	$52		;flags (HIGHCOMP+ITEMENABLED+ITEMTEXT)
		dc.l	0		;mutual excludes
		dc.l	sleftname	;pointer to INTUITEXT structure for name
		dc.l	0		;pointer to select text or image
		dc.b	0		;command key
		dc.b	0		;pad
		dc.l	0		;pointer to subitem MENUITEM structure
		dc.w	0		;menu number of simultaneous selection

sleftname	dc.b	2		;foreground colour
		dc.b	1		;background colour
		dc.b	1		;draw mode (JAM2)
		dc.b	0		;pad
		dc.w	0,0		;x,y position
		dc.l	0		;pointer to font
		dc.l	slefttext	;pointer to text string
		dc.l	0		;pointer to next intuitext structure

slefttext	dc.b	'Left',0
		even

spcright	dc.l	spcup		;Pointer to next menuitem structure
		dc.w	0,9		;leftedge,topedge
		dc.w	72,8		;width,height
		dc.w	$52		;flags (HIGHCOMP+ITEMENABLED+ITEMTEXT)
		dc.l	0		;mutual excludes
		dc.l	srightname	;pointer to INTUITEXT structure for name
		dc.l	0		;pointer to select text or image
		dc.b	0		;command key
		dc.b	0		;pad
		dc.l	0		;pointer to subitem MENUITEM structure
		dc.w	0		;menu number of simultaneous selection

srightname	dc.b	2		;foreground colour
		dc.b	1		;background colour
		dc.b	1		;draw mode (JAM2)
		dc.b	0		;pad
		dc.w	0,0		;x,y position
		dc.l	0		;pointer to font
		dc.l	srighttext	;pointer to text string
		dc.l	0		;pointer to next intuitext structure

srighttext	dc.b	'Right',0
		even

spcup		dc.l	spcdown		;Pointer to next menuitem structure
		dc.w	0,18		;leftedge,topedge
		dc.w	72,8		;width,height
		dc.w	$52		;flags (HIGHCOMP+ITEMENABLED+ITEMTEXT)
		dc.l	0		;mutual excludes
		dc.l	supname		;pointer to INTUITEXT structure for name
		dc.l	0		;pointer to select text or image
		dc.b	0		;command key
		dc.b	0		;pad
		dc.l	0		;pointer to subitem MENUITEM structure
		dc.w	0		;menu number of simultaneous selection

supname		dc.b	2		;foreground colour
		dc.b	1		;background colour
		dc.b	1		;draw mode (JAM2)
		dc.b	0		;pad
		dc.w	0,0		;x,y position
		dc.l	0		;pointer to font
		dc.l	suptext		;pointer to text string
		dc.l	0		;pointer to next intuitext structure

suptext		dc.b	'Up',0
		even

spcdown		dc.l	spcx		;Pointer to next menuitem structure
		dc.w	0,27		;leftedge,topedge
		dc.w	72,8		;width,height
		dc.w	$52		;flags (HIGHCOMP+ITEMENABLED+ITEMTEXT)
		dc.l	0		;mutual excludes
		dc.l	sdownname	;pointer to INTUITEXT structure for name
		dc.l	0		;pointer to select text or image
		dc.b	0		;command key
		dc.b	0		;pad
		dc.l	0		;pointer to subitem MENUITEM structure
		dc.w	0		;menu number of simultaneous selection

sdownname	dc.b	2		;foreground colour
		dc.b	1		;background colour
		dc.b	1		;draw mode (JAM2)
		dc.b	0		;pad
		dc.w	0,0		;x,y position
		dc.l	0		;pointer to font
		dc.l	sdowntext	;pointer to text string
		dc.l	0		;pointer to next intuitext structure

sdowntext	dc.b	'Down',0
		even

spcx		dc.l	spcy		;Pointer to next menuitem structure
		dc.w	0,40		;leftedge,topedge
		dc.w	72,8		;width,height
		dc.w	$52		;flags (HIGHCOMP+ITEMENABLED+ITEMTEXT)
		dc.l	0		;mutual excludes
		dc.l	sxname		;pointer to INTUITEXT structure for name
		dc.l	0		;pointer to select text or image
		dc.b	0		;command key
		dc.b	0		;pad
		dc.l	0		;pointer to subitem MENUITEM structure
		dc.w	0		;menu number of simultaneous selection

sxname		dc.b	2		;foreground colour
		dc.b	1		;background colour
		dc.b	1		;draw mode (JAM2)
		dc.b	0		;pad
		dc.w	0,0		;x,y position
		dc.l	0		;pointer to font
		dc.l	sxtext		;pointer to text string
		dc.l	0		;pointer to next intuitext structure

sxtext		dc.b	'Flip X',0
		even

spcy		dc.l	0		;Pointer to next menuitem structure
		dc.w	0,49		;leftedge,topedge
		dc.w	72,8		;width,height
		dc.w	$52		;flags (HIGHCOMP+ITEMENABLED+ITEMTEXT)
		dc.l	0		;mutual excludes
		dc.l	syname		;pointer to INTUITEXT structure for name
		dc.l	0		;pointer to select text or image
		dc.b	0		;command key
		dc.b	0		;pad
		dc.l	0		;pointer to subitem MENUITEM structure
		dc.w	0		;menu number of simultaneous selection

syname		dc.b	2		;foreground colour
		dc.b	1		;background colour
		dc.b	1		;draw mode (JAM2)
		dc.b	0		;pad
		dc.w	0,0		;x,y position
		dc.l	0		;pointer to font
		dc.l	sytext		;pointer to text string
		dc.l	0		;pointer to next intuitext structure

sytext		dc.b	'Flip Y',0
		even

;variables

xwid		dc.w	320	;Width of screen
ywid		dc.w	192	;Height of screen
depth		dc.w	5	;number of bitplanes
col		dc.w	1	;current colour
across		dc.w	16
down		dc.w	16
xgap		dc.w	8	;Width of zoom boxes
ygap		dc.w	8	;Height "   "     "
fx		dc.w	0
fy		dc.w	0
bp		dc.w	0
scrwd		dc.w	35
sx		dc.w	0
sy		dc.w	0
colx		dc.w	0
x2		dc.w	0
y2		dc.w	0
startcol	dc.w	0
startpal	dc.w	0
endpal		dc.w	0
increment	dc.w	0
number		dc.w	0
palinc		dc.l	0
startred	dc.w	0
startgreen	dc.w	0
startblue	dc.w	0
endred		dc.w	0
endgreen	dc.w	0
endblue		dc.w	0
endcol		dc.w	0
redinc		dc.l	0
greeninc	dc.l	0
blueinc		dc.l	0
bitplane1	dc.l	0
bitplane2	dc.l	0
bitplane3	dc.l	0
bitplane4	dc.l	0
bitplane5	dc.l	0
rx		dc.w	0
ry		dc.w	0
rx1		dc.w	0
ry1		dc.w	0
gridcol		dc.b	1
picchanged	dc.b	0
objectnumber	dc.w	1
objecttotal	dc.w	1
objectbuffer	dc.w	1
objectmem	dcb.l	256,0	;enough room for 40 memory pointers
				;in address,size order

strgadget	dc.l	gadget1		;pointer to next gadget structure
		dc.w	38,15		;x,y position of gadget
		dc.w	242,10		;width,height of gadget
		dc.w	$80		;highlighting and rendering flags
		dc.w	$303		;event communication flags
		dc.w	STRINGGADGET	;type of gadget
		dc.l	sborder		;pointer to custom image/border
		dc.l	0		;pointer to custom selected image/border
		dc.l	0		;pointer to gadget text (intuitext structure)
		dc.l	0		;mutual excludes for gadget activation
		dc.l	stringinfo	;special info
		dc.w	10		;user definable data word
		dc.l	0		;pointer to user data area

stringtext	dcb.b	80,0
undotext	dcb.b	80,0
infotext	dcb.b	86,0
		even

stringinfo	dc.l	stringtext	;buffer
		dc.l	undotext	;undo buffer
		dc.w	0		;position in buffer
		dc.w	79		;max chars
		dc.w	0		;first display position
		dc.w	0		;position in undo buffer
		dc.w	0		;number of chars currently in buffer
		dc.w	30		;number of visible chars
		dc.w	2		;number of pixels from left edge
		dc.w	3		;number from top
		dc.l	0		;pointer to rastport
		dc.l	0		;typed in integer value
		dc.l	0		;alternate keymap

sborder		dc.w	0		;leftedge
		dc.w	0		;topedge
		dc.b	8		;frontpen
		dc.b	0		;backpen
		dc.b	0		;draw mode
		dc.b	5		;no. of points in co-ord list
		dc.l	sbuttonlines	;pointer to co-ord list
		dc.l	0		;next border

sbuttonlines	dc.w	-1,-1,242,-1,242,8,-1,8,-1,-1	;x0,y0 x1,y1 etc

gadget1		dc.l	gadget2		;pointer to next gadget structure
		dc.w	10,30		;x,y position of gadget
		dc.w	52,10		;width,height of gadget
bit1		dc.w	GADGBITS	;highlighting and rendering flags
ac1		dc.w	3		;event communication flags
		dc.w	BOOLGADGET	;type of gadget
		dc.l	border1		;pointer to custom image/border
		dc.l	0		;pointer to custom selected image/border
		dc.l	gadget1text	;pointer to gadget text (intuitext structure)
		dc.l	0		;mutual excludes for gadget activation
		dc.l	0		;special info
		dc.w	11		;user definable data word
		dc.l	0		;pointer to user data area

gadget1text	dc.b	6		;foreground colour
		dc.b	0		;background colour
		dc.b	0		;draw mode (JAM1)
		dc.b	0		;pad
		dc.w	2,1		;x,y position
		dc.l	0		;pointer to font
		dc.l	gadg1text	;pointer to text string
		dc.l	0		;pointer to next intuitext structure

border1		dc.w	0		;leftedge
		dc.w	0		;topedge
		dc.b	8		;frontpen
		dc.b	0		;backpen
		dc.b	0		;draw mode
		dc.b	5		;no. of points in co-ord list
		dc.l	buttonlines1	;pointer to co-ord list
		dc.l	0		;next border

buttonlines1	dc.w	-1,-1,52,-1,52,10,-1,10,-1,-1	;x0,y0 x1,y1 etc

gadg1text	dc.b	'Cancel',0
		even

gadget2		dc.l	gadget3		;pointer to next gadget structure
gx2		dc.w	280,30		;x,y position of gadget
width2		dc.w	28,10		;width,height of gadget
		dc.w	GADGBITS	;highlighting and rendering flags
		dc.w	3		;event communication flags
		dc.w	BOOLGADGET	;type of gadget
		dc.l	border2		;pointer to custom image/border
		dc.l	0		;pointer to custom selected image/border
		dc.l	gadget2text	;pointer to gadget text (intuitext structure)
		dc.l	0		;mutual excludes for gadget activation
		dc.l	0		;special info
		dc.w	12		;user definable data word
		dc.l	0		;pointer to user data area

gadget2text	dc.b	6		;foreground colour
		dc.b	0		;background colour
		dc.b	0		;draw mode (JAM1)
		dc.b	0		;pad
		dc.w	2,1		;x,y position
		dc.l	0		;pointer to font
gtext2		dc.l	gadg2text	;pointer to text string
		dc.l	0		;pointer to next intuitext structure

border2		dc.w	0		;leftedge
		dc.w	0		;topedge
		dc.b	8		;frontpen
		dc.b	0		;backpen
		dc.b	0		;draw mode
		dc.b	5		;no. of points in co-ord list
		dc.l	buttonlines2	;pointer to co-ord list
		dc.l	0		;next border

buttonlines2	dc.w	-1,-1,28,-1,28,10,-1,10,-1,-1	;x0,y0 x1,y1 etc

gadg2text	dc.b	'IFF',0
		even

gadget3		dc.l	0		;pointer to next gadget structure
gx3		dc.w	244,30		;x,y position of gadget
width3		dc.w	28,10		;width,height of gadget
		dc.w	GADGBITS	;highlighting and rendering flags
		dc.w	3		;event communication flags
		dc.w	BOOLGADGET	;type of gadget
		dc.l	border3		;pointer to custom image/border
		dc.l	0		;pointer to custom selected image/border
		dc.l	gadget3text	;pointer to gadget text (intuitext structure)
		dc.l	0		;mutual excludes for gadget activation
		dc.l	0		;special info
		dc.w	13		;user definable data word
		dc.l	0		;pointer to user data area

gadget3text	dc.b	6		;foreground colour
		dc.b	0		;background colour
		dc.b	0		;draw mode (JAM1)
		dc.b	0		;pad
		dc.w	2,1		;x,y position
		dc.l	0		;pointer to font
g3title		dc.l	gadg3text	;pointer to text string
		dc.l	0		;pointer to next intuitext structure

border3		dc.w	0		;leftedge
		dc.w	0		;topedge
		dc.b	8		;frontpen
		dc.b	0		;backpen
		dc.b	0		;draw mode
		dc.b	5		;no. of points in co-ord list
		dc.l	buttonlines3	;pointer to co-ord list
		dc.l	0		;next border

buttonlines3	dc.w	-1,-1,28,-1,28,10,-1,10,-1,-1	;x0,y0 x1,y1 etc

gadg3text	dc.b	'RAW',0
		even

userport2	dc.l	0

filename	dcb.b	80,0
		even

filehandle	dc.l	0
_DosBase	dc.l	0
dosname		dc.b	'dos.library',0
		even
form		ds.b	120
		even

count		dc.w	0
xw		dc.w	0
widf		dc.w	16
height		dc.w	16
xpos		dc.w	0
ypos		dc.w	0
bitplanes	dc.b	0
masking		dc.b	0
compression	dc.b	0
pad		dc.b	0
transcol	dc.w	0
xAspect		dc.b	0
yAspect		dc.b	0
xpixel		dc.w	0
ypixel		dc.w	0
MemfBase	dc.l	0
loadnumber	dc.w	0
chunk		dc.l	0
ex		dc.w	0
ey		dc.w	0
delaytime	dc.w	10
widftext	dc.b	'Width',0
		even
heighttext	dc.b	'Height',0
		even
rememberkey	dc.l	0
desttext	dc.b	'Buffer',0
		even
slash		dc.b	'/',0
		even

aboutwindow	dc.w	10		;leftedge
		dc.w	12		;topedge
		dc.w	300,184		;width,height
		dc.b	2		;detail pen
		dc.b	1		;block pen
		dc.l	0		;IDCMP flags(GADGETUP)
		dc.l	$800		;Standard Gadgets (e.g closewindow)
		dc.l	0		;pointer to first gadget structure
		dc.l	0		;pointer to custom menu tick
		dc.l	0		;pointer to title text,0
 		dc.l	0		;pointer to custom screen
		dc.l	0		;pointer to custom bitmap
		dc.w	300,184		;minimum width,height
		dc.w	300,184		;maximum width,height
		dc.w	CUSTOMSCREEN	;type of screen

at1	dc.b	'GINS OBJECT EDITOR V3.1!',0
	even
at2	dc.b	'========================',0
	even
at3	dc.b	169,' 1990 Amiga Computing',0
	even
at4	dc.b	'F1-2 = Zoom Out/In',0
	even
at5	dc.b	'F3   = Toggle Grid On/Off',0
	even
at6	dc.b	'F4-5 = Change Width',0
	even
at7	dc.b	'F6-7 = Change Height',0
	even
at15	dc.b	'F9   = Toggle Icons On/Off',0
	even
at17	dc.b	'F10  = Set Object Buffer',0
	even
at8	dc.b	'HELP = Set New Dimensions',0
	even
at9	dc.b	'+/-  = Animation Speed',0
	even
at10	dc.b	'Use Arrows/Numeric Pad to move Zoom',0
	even
at11	dc.b	'Written by Sean Scaplehorn',0
	even
at12	dc.b	'29 Bartlemy Road',0
	even
at13	dc.b	'Newbury',0
	even
at14	dc.b	'Berkshire',0
	even
at16	dc.b	'< >  = Change Object',0
	even

xlist	dc.w	56,56,62,50,50,50,50,50,50,50,50,50,10,10,98,98,98,-1
ylist	dc.w	5,13,25,44,53,62,71,80,89,98,107,116,128,139,148,157,166,-1
alist	dc.l	at1,at2,at3,at4,at5,at6,at7,at15,at17,at8,at9,at16,at10,at11
	dc.l	at12,at13,at14,-1
text1	dc.b	'DC.W',0
	even
text2	dc.b	'DATA',0
	even

errorwindow	dc.w	0		;leftedge
		dc.w	12		;topedge
		dc.w	320,20		;width,height
		dc.b	2		;detail pen
		dc.b	1		;block pen
		dc.l	0		;IDCMP flags(GADGETUP)
		dc.l	$800		;Standard Gadgets (e.g closewindow)
		dc.l	0		;pointer to first gadget structure
		dc.l	0		;pointer to custom menu tick
		dc.l	0		;pointer to title text,0
 		dc.l	0		;pointer to custom screen
		dc.l	0		;pointer to custom bitmap
		dc.w	320,20		;minimum width,height
		dc.w	320,20		;maximum width,height
		dc.w	CUSTOMSCREEN	;type of screen

		;0123456789012345678901234567890123456789
error1	dc.b	'Error! Not an IFF ILBM file..',0
	even
error2	dc.b	'Error! No ILBM Chunk..',0
	even
error3	dc.b	'Error! No BMHD Chunk..',0
	even
error4	dc.b	'Error! BMHD Chunk Wrong Size..',0
	even
error5	dc.b	'Error! Unknown Compression Used..',0
	even
error6	dc.b	'Error! Colour 0 Not Transparent..',0
	even
error7	dc.b	'Error! Object Too Wide..',0
	even
error8	dc.b	'Error! Object Too High..',0
	even
error9	dc.b	'Error! Brush EHB or HAM..',0
	even
error10	dc.b	'Error! Can',39,'t Find BODY Chunk..',0
	even
error11 dc.b	'No Room to Store Object..',0
	even
error12	dc.b	'Disk Error! Aborting!',0
	even
error13	dc.b	'Not Enough Memory to Store Object!',0
	even
error14	dc.b	'Use Save. Only 1 Object Used.',0
	even
error15	dc.b	'Last Object Not Stored..',0
	even
error16	dc.b	'Unable to Create Icon File..',0
	even
error17	dc.b	'Error! Not a GMOE Animation File..',0
	even

bwidf	dc.w	0
bheight	dc.w	0
bdepth	dc.w	0
flag	dc.b	0
icons	dc.b	0
icontext	dc.b	'ICONS',0
		even
oawtitle	dc.b	'Open Animation..',0
		even
ok		dc.b	'O.K',0
		even
startobject	dc.w	0
numofobjects	dc.w	0
size		dc.l	0

rawbrushinfo	incbin	"rawbrush.info"
rawbrushsize	equ	*-rawbrushinfo
	even
iffbrushinfo	incbin	"iffbrush.info"
iffbrushsize	equ	*-iffbrushinfo
	even
datainfo	incbin	"data.info"
datasize	equ	*-datainfo
	even
animinfo	incbin	"anim.info"
animsize	equ	*-animinfo
	even
animidentify	dc.b	'GMOE',0
	even

	end

