************************************
convert:
	lea	pnt,a1
	lea	pic1,a0
	move.l	a0,a6
	cmp.w	#'RA',(a0)
	bne	notttraw
	cmpi.b	#3,rawrez(a0)
	bne.s	isttmed
	move.w	#256,icolors(a1)	;set up pnt header for this res
	move.w	#8,iplanes(a1)
	move.w	#320,iwidth(a1)
	move.w	#480,iheight(a1)
	bsr	dopntcolors
	bra	movescreen
isttmed:
	move.w	#16,icolors(a1)	;set up pnt header for this res
	move.w	#4,iplanes(a1)
	move.w	#640,iwidth(a1)
	move.w	#480,iheight(a1)
	bsr	dopntcolors
movescreen:
	lea	rawscreen(a0),a0
	lea	pntscreen,a1
	move.l	#479,d7
msloop:
	rept	80
	move.l	(a0)+,(a1)+
	endr
	dbf	d7,msloop
	rts


notttraw:
	addq.l	#4,sp
	jmp	looper

dopntcolors:
	movem.l	a0-a1,-(sp)

	lea	pnt,a6
	cmpi.w	#16,icolors(a6)	;Bloody hell this format suckssss
	beq	skipi		;aaaarrrghh, I'm going mad.
*	lea	pic1+rawpal,a0
*	move.w	510(a0),d0
*	move.w	2(a0),510(a0)
*	MOVE.W	D0,2(A0)
skipi:
	lea	gemtable,a2
	lea	pntpal2,a1
	lea	pic1+rawpal,a0
	bsr	convertbank

	cmpi.w	#16,icolors(a6)	;Bloody hell this format suckssss
	beq	skipii		;aaaarrrghh, I'm going mad.
	lea	pic1+rawpal,a0
	move.w	510(a0),d0
	move.w	2(a0),510(a0)
	MOVE.W	D0,2(A0)
skipii:

	lea	pnt,a2
	cmpi.w	#16,icolors(a2)
	beq	noextras
	lea	pic1+rawpal+32,a0
	lea	pntpal2+32,a1
	rept	240/2
	move.l	(a0)+,(a1)+
	endr

noextras:
	lea	pntpal2,a0	;no convert the rearranged colors
	lea	pntpal,a1	;to rgb 0-1000
	lea	pnt,a2
	move.w	icolors(a2),d7
	lea	transtable,a3
	subq.w	#1,d7
neloop:
	moveq	#0,d0
	moveq	#0,d1
	moveq	#0,d2
	move.w	(a0)+,d0
	move.w	d0,d1
	move.w	d1,d2
	and.w	#$000f,d2
	and.w	#$00f0,d1
	and.w	#$0f00,d0
	lsr.w	#4,d1
	lsr.w	#8,d0
	add.w	d0,d0
	add.w	d1,d1
	add.w	d2,d2
	move.w	(a3,d0.w),d0
	move.w	(a3,d1.w),d1
	move.w	(a3,d2.w),d2


	move.w	d0,(a1)+
	move.w	d1,(a1)+
	move.w	d2,(a1)+
	dbf	d7,neloop
	movem.l	(sp)+,a0-a1
	rts

transtable:
	dc.w	$0000,$0043,$0085,$00c8,$010b,$014d,$0190,$01d3
	dc.w	$0215,$0258,$029b,$02dd,$0320,$0363,$03a5,$03e8
pntpal1:	ds.w	256
pntpal2:	ds.w	256

gemtable:
	DC.W	$0000,$000F,$0001,$0002,$0004,$0006,$0003,$0005,$0007,$0008
	DC.W	$0009,$000A,$000C,$000E,$000B,$000D

*****************************************
*	Gemtable in a2			*
*	pcolbuf in a0 (pointing at appr	*
*	bank)				*
*	pcolbuf2 in a1			*
*****************************************
convertbank:
*	moveq	#15,d7		;banks of 16
*	moveq	#0,d0
*dcl:
*	move.w	d0,d1
*	add.w	d1,d1		;d1*2
*	move.w	(a0,d1.w),d3	;get the color
*	move.w	(a2,d1.w),d4
*	add.w	d4,d4
*	move.w	d3,(a1,d4.w)
*	addq.w	#1,d0
*	dbf	d7,dcl		;now pcolbuf2 has proper format

	move.w	(a0),(a1)		;0->0
	move.w	1*2(a0),2*2(a1)		;1->2
	move.w	2*2(a0),3*2(a1)		;1->2
	move.w	3*2(a0),6*2(a1)		;1->2
	move.w	4*2(a0),4*2(a1)		;1->2
	move.w	5*2(a0),7*2(a1)		;1->2
	move.w	6*2(a0),5*2(a1)		;1->2
	move.w	7*2(a0),8*2(a1)		;1->2
	move.w	8*2(a0),9*2(a1)		;1->2
	move.w	9*2(a0),10*2(a1)		;1->2
	move.w	10*2(a0),11*2(a1)	;1->2
	move.w	11*2(a0),14*2(a1)	;1->2
	move.w	12*2(a0),12*2(a1)	;1->2
	move.w	13*2(a0),15*2(a1)	;1->2
	move.w	14*2(a0),13*2(a1)	;1->2
	move.w	15*2(a0),1*2(a1)	;1->2

	rts


*****************************************************************
*	This is the save file bit, it'll handle all warnings	*
*	about overwriting existing files etc, so it should be	*
*	fairly user friendly.					*
*	Call like this...SAVEFILE(data.L,length.L)		*
*								*
*	Returns:	0.L	for user decided not to		*
*				overwrite an existing file	*
*				or not correct an error		*
*				either way the file did not	*
*				get written			*
*			1.L	for complete success		*
*			-1.L	for some general error		*
*								*
*	I'll handle most general errors such as disk write	*
*	protected by asking if they wanna try again.		*
*****************************************************************
savefile:
	movem.l	d1-d7/a0-a6,-(sp)
retry:
	move    #1,-(SP)        ;Open file for write
	move.l  #myfp,-(SP) 	;Address of filename
	move    #$3d,-(SP)
	trap    #1              ;Get handle number in D0
	addq.l  #8,SP
	cmpi.w	#-33,d0		;doesn't exist
	beq	create
	tst.w	d0		;other error
	bmi	docn2
	move.w	d0,-(sp)
cb:
	move.w	(sp),d0
	pea	pnt
	move.l  #128,-(sp)	;length to write in
	move    D0,-(SP)	;Handle
	move    #$40,-(SP)	;bios number
	trap    #1		;write file
	add.l   #12,SP
	lea	pnt,a0
	move.w	icolors(a0),d1
	mulu	#6,d1
	move.w	(sp),d0
	pea	pntpal
	move.l  d1,-(sp)	;length to write in
	move    D0,-(SP)	;Handle
	move    #$40,-(SP)	;bios number
	trap    #1		;write file
	add.l   #12,SP
	move.w	(sp),d0
	pea	pntscreen
	move.l  #153600,-(sp)	;length to write in
	move    D0,-(SP)	;Handle
	move    #$40,-(SP)	;bios number
	trap    #1		;write file
	add.l   #12,SP
	bra	closeit

closeit:
	move    #$3E,-(SP)      ;Handle already on stack
	trap    #1              ;Close file
	addq.l  #4,SP
	moveq	#1,d0
saveback:
	movem.l	(sp)+,d1-d7/a0-a6
	rts



PNT:
	dc.b	'PNT',0
	dc.w	$0100		;version number
	dc.w	0		;number of colors
	dc.w	0		;image width
	dc.w	0		;image height
	dc.w	0		;image planes
	dc.w	0		;indicate uncompressed
	dc.l	153600		;size of image data
	rept	54
	dc.w	0		;reserved must be zero's
	endr
	section bss
pntpal:
	ds.w	256*3		;this should be either 16*3 or 256*3
pntscreen:			;depending on resolution
	ds.b	153600

