
; Storm C Compiler
; Work2:Mesa3/Mesa-3.0/src/colortab.c
	mc68030
	mc68881
	XREF	_gl_error
	XREF	_gl_problem
	XREF	_q_memcpy
	XREF	_CC

	SECTION "_power_of_two:0",CODE


;static GLboolean power_of_two( GLint k )
_power_of_two
	movem.l	d2/d3,-(a7)
	move.l	$C(a7),d2
L59
;   GLint i, m = 1;
	moveq	#1,d1
;   for (i=0;
	moveq	#0,d0
	bra.b	L63
L60
;      if (k == m)
	cmp.l	d1,d2
	bne.b	L62
L61
	moveq	#1,d0
	movem.l	(a7)+,d2/d3
	rts
L62
;      m = m << 1;
	moveq	#1,d3
	asl.l	d3,d1
	addq.l	#1,d0
L63
	cmp.l	#$20,d0
	blt.b	L60
L64
	moveq	#0,d0
	movem.l	(a7)+,d2/d3
	rts

	SECTION "_decode_internal_format:0",CODE

	rts

;static GLint decode_internal_format( GLint format )
_decode_internal_format
	move.l	4(a7),d0
L65
;   switch (format)
	cmp.l	#$8046,d0
	beq	L68
	bgt	L73
	cmp.l	#$803B,d0
	beq	L66
	bgt	L74
	cmp.l	#$1907,d0
	beq	L70
	bgt.b	L75
	cmp.l	#3,d0
	beq	L70
	bgt.b	L76
	cmp.l	#1,d0
	beq	L67
	cmp.l	#2,d0
	beq	L68
	bra	L72
L76
	cmp.l	#4,d0
	beq	L71
	cmp.l	#$1906,d0
	beq	L66
	bra	L72
L75
	cmp.l	#$190A,d0
	beq	L68
	bgt.b	L77
	cmp.l	#$1908,d0
	beq	L71
	cmp.l	#$1909,d0
	beq	L67
	bra	L72
L77
	cmp.l	#$2A10,d0
	beq	L70
	bra	L72
L74
	sub.l	#$803C,d0
	cmp.l	#$9,d0
	bhi	L72
	move.l	L78(pc,d0.l*4),a0
	jmp	(a0)
L78
	dc.l	L66
	dc.l	L66
	dc.l	L66
	dc.l	L67
	dc.l	L67
	dc.l	L67
	dc.l	L67
	dc.l	L68
	dc.l	L68
	dc.l	L68
L73
	sub.l	#$8047,d0
	cmp.l	#$14,d0
	bhi	L72
	move.l	L79(pc,d0.l*4),a0
	jmp	(a0)
L79
	dc.l	L68
	dc.l	L68
	dc.l	L69
	dc.l	L69
	dc.l	L69
	dc.l	L69
	dc.l	L69
	dc.l	L72
	dc.l	L70
	dc.l	L70
	dc.l	L70
	dc.l	L70
	dc.l	L70
	dc.l	L70
	dc.l	L71
	dc.l	L71
	dc.l	L71
	dc.l	L71
	dc.l	L71
	dc.l	L71
	dc.l	L71
;      
L66
	move.l	#$1906,d0
	rts
L67
	move.l	#$1909,d0
	rts
L68
	move.l	#$190A,d0
	rts
L69
	move.l	#$8049,d0
	rts
L70
	move.l	#$1907,d0
	rts
L71
	move.l	#$1908,d0
	rts
L72
	moveq	#-1,d0
	rts

	SECTION "_gl_ColorTable:0",CODE


;void gl_ColorTable( GLcontext *ctx, GLenum target,
	XDEF	_gl_ColorTable
_gl_ColorTable
	movem.l	d2-d4/a2-a4,-(a7)
	movem.l	$24(a7),d3/a4
	move.l	$20(a7),d4
	move.l	$1C(a7),a2
L84
;   struct gl_texture_set *texSet = &ctx->Texture.Set[ctx->Texture
	move.l	a2,a1
	add.l	#$DEC6,a1
	move.l	a2,a0
	add.l	#$DEBA,a0
	move.l	(a0),d0
	muls.l	#$BC,d0
	add.l	a1,d0
	move.l	d0,a3
;   GLboolean proxy = GL_FALSE;
	moveq	#0,d2
;   if (INSIDE_BEGIN_END(ctx)) 
	move.l	a2,a0
	add.l	#$E968,a0
	move.l	(a0),d0
	cmp.l	#$1A00,d0
	beq.b	L86
L85
;      gl_error( ctx, GL_INVALID_OPERATION, "glColorTable" );
	move.l	#L80,-(a7)
	pea	$502.w
	move.l	a2,-(a7)
	jsr	_gl_error
	add.w	#$C,a7
	movem.l	(a7)+,d2-d4/a2-a4
	rts
L86
;   if (decode_internal_format(internalFormat) < 0) 
	move.l	d3,-(a7)
	jsr	_decode_internal_format
	addq.w	#4,a7
	tst.l	d0
	bpl.b	L88
L87
;      gl_error( ctx, GL_INVALID_ENUM, "glColorTable(internalFo
	move.l	#L81,-(a7)
	pea	$500.w
	move.l	a2,-(a7)
	jsr	_gl_error
	add.w	#$C,a7
	movem.l	(a7)+,d2-d4/a2-a4
	rts
L88
;   switch (target)
	cmp.l	#$8064,d4
	beq.b	L93
	bgt.b	L111
	cmp.l	#$DE1,d4
	beq.b	L90
	bgt.b	L112
	cmp.l	#$DE0,d4
	beq.b	L89
	bra	L96
L112
	cmp.l	#$8063,d4
	beq.b	L92
	bra.b	L96
L111
	cmp.l	#$8070,d4
	beq.b	L94
	bgt.b	L113
	cmp.l	#$806F,d4
	beq.b	L91
	bra.b	L96
L113
	cmp.l	#$81FB,d4
	beq.b	L95
	bra.b	L96
;      
L89
;         texObj = texSet->Current1D;
	move.l	a3,a0
	move.l	$A8(a0),a3
;         
	bra.b	L97
L90
;         texObj = texSet->Current2D;
	move.l	a3,a0
	move.l	$AC(a0),a3
;         
	bra.b	L97
L91
;         texObj = texSet->Current3D;
	move.l	a3,a0
	move.l	$B0(a0),a3
;         
	bra.b	L97
L92
;         texObj = ctx->Texture.Proxy1D;
	move.l	a2,a0
	add.l	#$DEBA,a0
	move.l	$186(a0),a3
;         proxy = GL_TRUE;
	moveq	#1,d2
;         
	bra.b	L97
L93
;         texObj = ctx->Texture.Proxy2D;
	move.l	a2,a0
	add.l	#$DEBA,a0
	move.l	$18A(a0),a3
;         proxy = GL_TRUE;
	moveq	#1,d2
;         
	bra.b	L97
L94
;         texObj = ctx->Texture.Proxy3D;
	move.l	a2,a0
	add.l	#$DEBA,a0
	move.l	$18E(a0),a3
;         proxy = GL_TRUE;
	moveq	#1,d2
;         
	bra.b	L97
L95
;         texObj = NULL;
	sub.l	a3,a3
;         
	bra.b	L97
L96
;         gl_error(ctx, GL_INVALID_ENUM, "glColorTableEXT(ta
	move.l	#L82,-(a7)
	pea	$500.w
	move.l	a2,-(a7)
	jsr	_gl_error
	add.w	#$C,a7
	movem.l	(a7)+,d2-d4/a2-a4
	rts
L97
;         return;
;   if (table->Width < 1 || table->Width > MAX_TEXTURE_PALETTE_SIZ
	move.l	a4,a0
	move.l	(a0),d0
	cmp.l	#1,d0
	blt.b	L100
L98
	move.l	a4,a0
	move.l	(a0),d0
	cmp.l	#$100,d0
	bgt.b	L100
L99
	move.l	a4,a0
	move.l	(a0),-(a7)
	jsr	_power_of_two
	addq.w	#4,a7
	tst.b	d0
	bne.b	L103
L100
;      gl_error(ctx, GL_INVALID_VALUE, "glColorTableEXT(width)")
	move.l	#L83,-(a7)
	pea	$501.w
	move.l	a2,-(a7)
	jsr	_gl_error
	add.w	#$C,a7
;      if (proxy) 
	tst.b	d2
	beq.b	L102
L101
;         texObj->PaletteSize = 0;
	move.l	a3,a0
	clr.l	$47C(a0)
;         texObj->PaletteIntFormat = (GLenum) 0;
	move.l	a3,a0
	clr.l	$480(a0)
;         texObj->PaletteFormat = (GLenum) 0;
	move.l	a3,a0
	clr.l	$484(a0)
L102
	movem.l	(a7)+,d2-d4/a2-a4
	rts
L103
;   if (texObj) 
	cmp.w	#0,a3
	beq.b	L108
L104
;      texObj->PaletteSize = table->Width;
	move.l	a4,a0
	move.l	(a0),d0
	move.l	a3,a0
	move.l	d0,$47C(a0)
;      texObj->PaletteIntFormat = internalFormat;
	move.l	a3,a0
	move.l	d3,$480(a0)
;      texObj->PaletteFormat = (GLenum) decode_internal_format(
	move.l	d3,-(a7)
	jsr	_decode_internal_format
	addq.w	#4,a7
	move.l	a3,a0
	move.l	d0,$484(a0)
;      if (!proxy) 
	tst.b	d2
	bne.b	L107
L105
;alette, table->Da
	move.l	a4,a0
	move.l	(a0),d0
	move.l	a4,a0
	muls.l	$C(a0),d0
	move.l	d0,-(a7)
	move.l	a4,a1
	move.l	$18(a1),-(a7)
	pea	$7C(a3)
	jsr	_q_memcpy
	add.w	#$C,a7
;         if (ctx->Driver.UpdateTexturePalette) 
	tst.l	$9DC(a2)
	beq.b	L107
L106
;            (*ctx->Driver.UpdateTexturePalette)( ctx, te
	move.l	a3,-(a7)
	move.l	a2,-(a7)
	move.l	$9DC(a2),a0
	jsr	(a0)
	addq.w	#$8,a7
L107
	bra.b	L110
L108
;      ctx->Texture.PaletteSize = table->Width;
	move.l	a4,a0
	move.l	(a0),d0
	move.l	a2,a0
	add.l	#$E44E,a0
	move.l	d0,(a0)
;      ctx->Texture.PaletteIntFormat = internalFormat;
	move.l	a2,a0
	add.l	#$E452,a0
	move.l	d3,(a0)
;      ctx->Texture.PaletteFormat = (GLenum) decode_internal_fo
	move.l	d3,-(a7)
	jsr	_decode_internal_format
	addq.w	#4,a7
	move.l	a2,a0
	add.l	#$E456,a0
	move.l	d0,(a0)
;alette, table->Da
	move.l	a4,a0
	move.l	(a0),d0
	move.l	a4,a0
	muls.l	$C(a0),d0
	move.l	d0,-(a7)
	move.l	a4,a1
	move.l	$18(a1),-(a7)
	move.l	a2,a0
	add.l	#$E04D,a0
	pea	(a0)
	jsr	_q_memcpy
	add.w	#$C,a7
;      if (ctx->Driver.UpdateTexturePalette) 
	tst.l	$9DC(a2)
	beq.b	L110
L109
;         (*ctx->Driver.UpdateTexturePalette)( ctx, NULL );
	clr.l	-(a7)
	move.l	a2,-(a7)
	move.l	$9DC(a2),a0
	jsr	(a0)
	addq.w	#$8,a7
L110
	movem.l	(a7)+,d2-d4/a2-a4
	rts

L80
	dc.b	'glColorTable',0
L81
	dc.b	'glColorTable(internalFormat)',0
L82
	dc.b	'glColorTableEXT(target)',0
L83
	dc.b	'glColorTableEXT(width)',0

	SECTION "_gl_ColorSubTable:0",CODE


;void gl_ColorSubTable( GLcontext *ctx, GLenum target,
	XDEF	_gl_ColorSubTable
_gl_ColorSubTable
	move.l	4(a7),a0
L115
;   gl_problem(ctx, "glColorSubTableEXT not implemented");
	move.l	#L114,-(a7)
	move.l	a0,-(a7)
	jsr	_gl_problem
	addq.w	#$8,a7
;   (void) target;
;   (void) start;
;   (void) data;
	rts

L114
	dc.b	'glColorSubTableEXT not implemented',0

	SECTION "_gl_GetColorTable:0",CODE


;void gl_GetColorTable( GLcontext *ctx, GLenum target, GLenum format,
	XDEF	_gl_GetColorTable
_gl_GetColorTable
	move.l	$8(a7),d1
	move.l	4(a7),a0
L119
;   if (INSIDE_BEGIN_END(ctx)) 
	move.l	a0,a1
	add.l	#$E968,a1
	move.l	(a1),d0
	cmp.l	#$1A00,d0
	beq.b	L121
L120
;      gl_error( ctx, GL_INVALID_OPERATION, "glGetBooleanv" );
	move.l	#L116,-(a7)
	pea	$502.w
	move.l	a0,-(a7)
	jsr	_gl_error
	add.w	#$C,a7
	rts
L121
;   switch (target)
	cmp.l	#$806F,d1
	beq.b	L124
	bgt.b	L128
	cmp.l	#$DE0,d1
	beq.b	L122
	cmp.l	#$DE1,d1
	beq.b	L123
	bra.b	L126
L128
	cmp.l	#$81FB,d1
	beq.b	L125
	bra.b	L126
;      
L122
;         
	bra.b	L127
L123
;         
	bra.b	L127
L124
;         
	bra.b	L127
L125
;         
	bra.b	L127
L126
;         gl_error(ctx, GL_INVALID_ENUM, "glGetColorTableEXT
	move.l	#L117,-(a7)
	pea	$500.w
	move.l	a0,-(a7)
	jsr	_gl_error
	add.w	#$C,a7
	rts
L127
;         return;
;   gl_problem(ctx, "glGetColorTableEXT not implemented!");
	move.l	#L118,-(a7)
	move.l	a0,-(a7)
	jsr	_gl_problem
	addq.w	#$8,a7
;   (void) format;
;   (void) type;
;   (void) table;
	rts

L116
	dc.b	'glGetBooleanv',0
L118
	dc.b	'glGetColorTableEXT not implemented!',0
L117
	dc.b	'glGetColorTableEXT(target)',0

	SECTION "_gl_GetColorTableParameterfv:0",CODE


;void gl_GetColorTableParameterfv( GLcontext *ctx, GLenum target,
	XDEF	_gl_GetColorTableParameterfv
_gl_GetColorTableParameterfv
L130	EQU	-$28
	link	a5,#L130
	move.l	a2,-(a7)
	movem.l	$C(a5),d0/d1/a2
	move.l	$8(a5),a1
L129
;   gl_GetColorTableParameteriv( ctx, target, pname, iparams );
	pea	-$28(a5)
	move.l	d1,-(a7)
	move.l	d0,-(a7)
	move.l	a1,-(a7)
	jsr	_gl_GetColorTableParameteriv
	add.w	#$10,a7
;   *params = (GLfloat) iparams[0];
	fmove.l	-$28(a5),fp0
	fmove.s	fp0,(a2)
	move.l	(a7)+,a2
	unlk	a5
	rts

	SECTION "_gl_GetColorTableParameteriv:0",CODE


;void gl_GetColorTableParameteriv( GLcontext *ctx, GLenum target,
	XDEF	_gl_GetColorTableParameteriv
_gl_GetColorTableParameteriv
	movem.l	d2/d3/a2/a3,-(a7)
	movem.l	$1C(a7),d1/a0
	move.l	$18(a7),d2
	move.l	$14(a7),a2
L133
;   struct gl_texture_set *texSet = &ctx->Texture.Set[ctx->Texture
	move.l	#$DEC6,d0
	add.l	a2,d0
	move.l	d0,a3
	move.l	a2,a1
	add.l	#$DEBA,a1
	move.l	(a1),d0
	muls.l	#$BC,d0
	lea	0(a3,d0.l),a1
;   if (INSIDE_BEGIN_END(ctx)) 
	move.l	a2,a3
	add.l	#$E968,a3
	move.l	(a3),d0
	cmp.l	#$1A00,d0
	beq.b	L135
L134
;      gl_error( ctx, GL_INVALID_OPERATION, "glGetColorTablePar
	move.l	#L131,-(a7)
	pea	$502.w
	move.l	a2,-(a7)
	jsr	_gl_error
	add.w	#$C,a7
	movem.l	(a7)+,d2/d3/a2/a3
	rts
L135
;   switch (target)
	cmp.l	#$806F,d2
	beq.b	L138
	bgt.b	L158
	cmp.l	#$DE0,d2
	beq.b	L136
	cmp.l	#$DE1,d2
	beq.b	L137
	bra.b	L140
L158
	cmp.l	#$81FB,d2
	beq.b	L139
	bra.b	L140
;      
L136
;         texObj = texSet->Current1D;
	move.l	$A8(a1),a1
;         
	bra.b	L141
L137
;         texObj = texSet->Current2D;
	move.l	$AC(a1),a1
;         
	bra.b	L141
L138
;         texObj = texSet->Current3D;
	move.l	$B0(a1),a1
;         
	bra.b	L141
L139
;         texObj = NULL;
	sub.l	a1,a1
;         
	bra.b	L141
L140
;         gl_error(ctx, GL_INVALID_ENUM, "glGetColorTablePar
	move.l	#L132,-(a7)
	pea	$500.w
	move.l	a2,-(a7)
	jsr	_gl_error
	add.w	#$C,a7
	movem.l	(a7)+,d2/d3/a2/a3
	rts
L141
;         return;
;   switch (pname)
	sub.l	#$80D8,d1
	cmp.l	#7,d1
	bhi	L156
	move.l	L159(pc,d1.l*4),a3
	jmp	(a3)
L159
	dc.l	L142
	dc.l	L146
	dc.l	L150
	dc.l	L151
	dc.l	L152
	dc.l	L153
	dc.l	L154
	dc.l	L155
;      
L142
;         if (texObj)
	cmp.w	#0,a1
	beq.b	L144
L143
;            *params = texObj->PaletteIntFormat;
	move.l	$480(a1),(a0)
	bra.b	L145
L144
;            *params = ctx->Texture.PaletteIntFormat;
	move.l	a2,a1
	add.l	#$DEBA,a1
	move.l	$598(a1),(a0)
L145
;         
	bra.b	L157
L146
;         if (texObj)
	cmp.w	#0,a1
	beq.b	L148
L147
;            *params = texObj->PaletteSize;
	move.l	$47C(a1),(a0)
	bra.b	L149
L148
;            *params = ctx->Texture.PaletteSize;
	move.l	a2,a1
	add.l	#$DEBA,a1
	move.l	$594(a1),(a0)
L149
;         
	bra.b	L157
L150
;         *params = 8;
	move.l	#$8,(a0)
;         
	bra.b	L157
L151
;         *params = 8;
	move.l	#$8,(a0)
;         
	bra.b	L157
L152
;         *params = 8;
	move.l	#$8,(a0)
;         
	bra.b	L157
L153
;         *params = 8;
	move.l	#$8,(a0)
;         
	bra.b	L157
L154
;         *params = 8;
	move.l	#$8,(a0)
;         
	bra.b	L157
L155
;         *params = 8;
	move.l	#$8,(a0)
;         
	bra.b	L157
L156
;         gl_error(ctx, GL_INVALID_ENUM, "glGetColorTablePar
	move.l	#L131,-(a7)
	pea	$500.w
	move.l	a2,-(a7)
	jsr	_gl_error
	add.w	#$C,a7
	movem.l	(a7)+,d2/d3/a2/a3
	rts
L157
;         return;
	movem.l	(a7)+,d2/d3/a2/a3
	rts

L131
	dc.b	'glGetColorTableParameter',0
L132
	dc.b	'glGetColorTableParameter(target)',0

	END
