*******************************************************************************
* SaveRGBxPal.s 0.0.0
*******************************************************************************
* INFO	this little tool saves to file the IFF palette of the desired
*	RGBx mode; optionally, you can assign the RGB value you prefer
*	to the color that would look bad in Dual Cross Playfield mode,
*	given a certain transparent color;
* NOTE	- for command line arguments look at the template definition
*	  at the bottom
*******************************************************************************

	machine	68020

	include	INCLUDES:libraries/tcs.i
	include	INCLUDES:libraries/tcs_lib.i

	macro	CALLTCS
	movea.l	_TCSBase,a6
	jsr	(_LVOTCS_\1,a6)
	endm



	code

*******************************************************************************
* open libs / command line parsing

	movea.l	4.w,a6
	lea.l	DOSNm,a1
	moveq.l	#37,d0
	jsr	(-552,a6)	;OpenLibrary(...)
	move.l	d0,_DOSBase
	beq	.exit
	lea.l	GfxNm,a1
	moveq.l	#37,d0
	jsr	(-552,a6)	;OpenLibrary(...)
	move.l	d0,_GfxBase
	beq	.ClsDOS
	lea.l	TCSNm,a1
	moveq.l	#1,d0
	jsr	(-552,a6)	;OpenLibrary(...)
	move.l	d0,_TCSBase
	beq.s	.ClsGfx

	move.l	#tmplt,d1
	move.l	#CmdLnArgs,d2
	moveq.l	#0,d3
	movea.l	_DOSBase,a6
	jsr	(-798,a6)	;ReadArgs(tmplt,CmdLnArgs,0)
	move.l	d0,_RDArgs
	beq	.ClsLibs

*******************************************************************************
* main

	lea.l	CmdLnArgs,a1
	moveq.l	#0,d1
	moveq.l	#0,d2	;no Dual Cross Playfield
	moveq.l	#0,d3	;palette as default
	movea.l	(a1),a0	;file name pointer
	move.l	([4.w,a1]),d0	;RGBx mode
	tst.l	(8,a1)
	sne.b	d1	;set flag for Dual
	extb.l	d1	;Cross Playfield palette
	beq.s	.SvPal	;if no transparent color...
	move.l	([8.w,a1]),d2	;get transparent color
	move.l	([12.w,a1]),d3	;get dummy RGB value

.SvPal	CALLTCS	SvIFFRGBxPal	;save IFF palette
	beq.s	.out

*******************************************************************************
* cleanup / exit

.out	move.l	_RDArgs,d1
	movea.l	_DOSBase,a6
	jsr	(-858,a6)	;FreeArgs(_RDArgs)

.ClsLibs	movea.l	4.w,a6
	movea.l	_TCSBase,a1
	jsr	(-414,a6)	;CloseLibrary(...)
.ClsGfx	movea.l	4.w,a6
	movea.l	_GfxBase,a1
	jsr	(-414,a6)	;CloseLibrary(...)
.ClsDOS	movea.l	4.w,a6
	movea.l	_DOSBase,a1
	jsr	(-414,a6)	;CloseLibrary(...)

.exit	moveq.l	#0,d0
	rts



*******************************************************************************
* data

	cnop	0,4

_DOSBase	dc.l	0
_GfxBase	dc.l	0
_TCSBase	dc.l	0
_RDArgs	dc.l	0

CmdLnArgs	ds.l	4	;command line arguments pointers

DOSNm	dc.b	"dos.library",0
GfxNm	dc.b	"graphics.library",0
TCSNm	TCSNAME

tmplt	dc.b	"IFF=I/A,RGBxMODE=R/A/N,TRNSPCOL=T/K/N,DUMMYRGB=D/K/N",0
