
*
*   palette.s - palette handling
*   Copyright (C) 1997 Aki Laukkanen
*
*   This program is free software; you can redistribute it and/or modify
*   it under the terms of the GNU General Public License as published by
*   the Free Software Foundation; either version 2 of the License, or
*   (at your option) any later version.
*
*   This program is distributed in the hope that it will be useful,
*   but WITHOUT ANY WARRANTY; without even the implied warranty of
*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*   GNU General Public License for more details.
*
*   You should have received a copy of the GNU General Public License
*   along with this program; if not, write to the Free Software Foundation,
*   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*

	XDEF    _internal_palette
	XDEF    _evd_loadrgb32
	XDEF    _evd_loadham8

	include "exec/types.i"
	include "utility/tagitem.i"

	include "lvo/utility_lib.i"
	include "lvo/graphics_lib.i"

	include "shapeextvideo.i"
	include "evd_context.i"

; a0: colortab
; a2: context

_evd_loadham8
	movem.l a5/a6,-(sp)                         ; used registers

	move.l  sp,a5                               ; save old stack
	clr.l   -(sp)                               ; termination

	moveq   #64-1,d1                            ; 16 colors
	adda.l  #64*4,a0

.loop
	subq.l  #1,a0
	move.w  (a0),d0                            ; 0xBBBBBBBB
	move.b  (a0),d0
	swap    d0
	move.w  (a0),d0
	move.b  (a0),d0
	move.l  d0,-(sp)
	subq.l  #1,a0
	move.w  (a0),d0                            ; 0xBBBBBBBB
	move.b  (a0),d0
	swap    d0
	move.w  (a0),d0
	move.b  (a0),d0
	move.l  d0,-(sp)
	subq.l  #1,a0
	move.w  (a0),d0                            ; 0xBBBBBBBB
	move.b  (a0),d0
	swap    d0
	move.w  (a0),d0
	move.b  (a0),d0
	move.l  d0,-(sp)
	subq.l  #1,a0
	dbf     d1,.loop

	moveq   #64,d0
	swap    d0

	move.l  d0,-(sp)
	move.l  (ct_GfxBase,a2),a6
	move.l  sp,a1
	move.l  (ct_ViewPort,a2),a0
	jsr     (_LVOLoadRGB32,a6)

	move.l  a5,sp                               ; restore the stack pointer
	movem.l (sp)+,a5/a6
	rts

*
* ULONG __asm evd_loadrgb32(    register __a0 struct TagList* input,
*                               register __a1 struct TagList* output,
*                               register __a2 APTR,
*                               register __a6 struct Library* UtilityBase);
*

_evd_loadrgb32
	movem.l a5/a6,-(sp)                         ; used registers
	move.l  #SHEV_ColorTable,d0
	moveq   #0,d1
	jsr     (_LVOGetTagData,a6)
	tst.l   d0                                  ; ColorArray
	beq     .error
	move.l  d0,a0

	move.l  sp,a5                               ; save old stack
	clr.l   -(sp)                               ; termination

	move.l  (ct_VideoMode,a2),d1

	cmp.l   #VMODE_8BIT,d1                      ; 256 colors
	bne.s   .not_8bit
	moveq   #0,d1
	st      d1
	adda.l  #256*3*4,a0
	move.l  #$01000000,d0
	bra.s   .loop
.not_8bit
	cmp.l   #VMODE_4BIT,d1
	bne.s   .not_4bit
	moveq   #16-1,d1                            ; 16 colors
	adda.l  #16*3*4,a0
	moveq   #16,d0
	swap    d0
	bra.s   .loop

.not_4bit
	cmp.l   #VMODE_2BIT,d1
	bne.s   .not_2bit
	moveq   #4-1,d1                             ; 4 colors
	adda.l  #4*3*4,a0
	moveq   #4,d0
	swap    d0
	bra.s   .loop

.not_2bit
	moveq   #2-1,d1                             ; 2 colors
	adda.l  #2*3*4,a0
	moveq   #2,d0
	swap    d0
.loop
	move.l  -(a0),-(sp)                         ; copy the array to a temporary
	move.l  -(a0),-(sp)                         ; storage
	move.l  -(a0),-(sp)
	dbf     d1,.loop
	move.l  d0,-(sp)
	move.l  (ct_GfxBase,a2),a6
	move.l  sp,a1
	move.l  (ct_ViewPort,a2),a0
	jsr     (_LVOLoadRGB32,a6)

	move.l  a5,sp                               ; restore the stack pointer

	movem.l (sp)+,a5/a6
	moveq   #EVD_OK,d0
	rts
.error
	movem.l (sp)+,a5/a6
	moveq   #EVD_ERROR,d0
	rts

	section __MERGED,data

_internal_palette                               ; const data
	dc.l    cached_name
	dc.l    pal_name
	dc.l    10
	incbin  "/palettes/agaevd.pal"

cached_name
	dc.b    'PROGDIR:agaevd.cached',0

pal_name
	dc.b    'agaevd.pal',0

