


;these routines are used to convert the YAFA frames to 24Bit RGB
;which is then used as input for WritePixelArray()



;-------------------------------------------------------------------------
; 15bit-Truecolor to 24bit-Truecolor  by Smack/Infect! 23-Aug-97
;
;  input   0rrrrrgg gggbbbbb
;  output  rrrrrrrr gggggggg bbbbbbbb
;
; parameters on stack:
;  00  APTR    source
;  04  APTR    dest
;  08  ULONG   number_of_pixels
;
_color15to24
	movem.l	d0-a6,-(a7)	;15*4+4=64
	move.l	(64+00,a7),a5	;source
	move.l	(64+04,a7),a6	;dest
	move.l	(64+08,a7),d7	;pixels
	lsr.l	#2,d7
	moveq	#19,d6
	moveq	#10,d5
	moveq	#18,d4
	moveq	#11,d3
.loop	move.l	(a5)+,d0	;two pixels
	move.l	d0,d1
	lsr.l	d5,d0		;#10
	lsl.b	#3,d0
	move.b	d0,d2
	lsr	#3,d0
	lsr.b	#3,d0
	lsl.l	d3,d0		;#11
	move.b	d2,d0		;RGBr
	move.l	d0,(a6)+
	lsl	#3,d1
	move.l	(a5)+,d0	;two pixels
	lsr.b	#3,d1
	move.l	d0,d2
	lsl.l	d6,d1		;#19  gb__
	lsr.l	d4,d0		;#18
	lsr.b	#3,d0
	lsl	#3,d0
	move	d0,d1		;gbRG
	move.l	d1,(a6)+
	move.l	d2,d0
	lsr	#2,d2
	lsl.b	#3,d0
	lsr.b	#3,d2
	lsl.l	d3,d2		;#11
	move.b	d0,d2		;Brgb
	move.l	d2,(a6)+
	subq.l	#1,d7
	bgt.b	.loop
	movem.l	(a7)+,d0-a6
	rts
;-------------------------------------------------------------------------
LUT		ds.l	256
;-------------------------------------------------------------------------
; 8bit-ChunkyPixels to 24bit-Truecolor  by Smack/Infect! 08-Aug-97
;
;  input   all 8 bits are used here,
;          this requires unused bits (if depth<8) to be cleared (ZER0)!
;  output  rrrrrrrr gggggggg bbbbbbbb
;
; parameters on stack:
;  00  APTR            source
;  04  APTR            dest
;  08  ULONG           number_of_pixels
;  12  struct loadrgb* palette 
;
_chunkyto24
	movem.l	d0-a6,-(a7)	;15*4+4=64

	move.l	(64+12,a7),a0
	move	(a0),d7
	subq	#1,d7		;count
	addq.l	#4,a0
	lea	(LUT,pc),a4
	move.l	a4,a1
.makLUT	move.l	(a0)+,d1
	move.l	(a0)+,d2
	move.l	(a0)+,d3
	moveq	#0,d0
	rol.l	#8,d1
	rol.l	#8,d2
	rol.l	#8,d3
	move.b	d1,d0	;R
	lsl.l	#8,d0
	move.b	d2,d0	;G
	lsl.l	#8,d0
	move.b	d3,d0	;B
	move.l	d0,(a1)+
	dbf	d7,.makLUT

	move.l	(64+00,a7),a5	;source
	move.l	(64+04,a7),a6	;dest
	move.l	(64+08,a7),d7	;pixels
	lsr.l	#2,d7
	moveq	#24,d6
	moveq	#0,d0
	moveq	#0,d1
.loop	move.b	(a5)+,d0
	move.b	(a5)+,d1
	move.l	(a4,d0.l*4),d2
	move.l	(a4,d1.l*4),d3
	lsl.l	#8,d2		;RGB_
	swap	d3		;gb_r
	move.b	d3,d2		;RGBr
	move.l	d2,(a6)+
	move.b	(a5)+,d0
	move.b	(a5)+,d1
	move.l	(a4,d0.l*4),d4
	move.l	d4,d2
	lsr.l	#8,d4
	lsl.l	d6,d2		;B___
	move	d4,d3		;gbRG
	move.l	d3,(a6)+
	or.l	(a4,d1.l*4),d2	;Brgb
	move.l	d2,(a6)+
	subq.l	#1,d7
	bgt.b	.loop

	movem.l	(a7)+,d0-a6
	rts
;-------------------------------------------------------------------------
; 8bit-ChunkyPixels HAM8 to 24bit-Truecolor  by Smack/Infect! 08-Aug-97
;
;  input   76543210 (bits 6 and 7 are the HAM8 control codes)
;  output  rrrrrrrr gggggggg bbbbbbbb
;
; parameters on stack:
;  00  APTR            source
;  04  APTR            dest
;  08  ULONG           number_of_pixels
;  12  struct loadrgb* palette 
;
_ham8to24
	movem.l	d0-a6,-(a7)	;15*4+4=64

	move.l	(64+12,a7),a0
	move	(a0),d7
	subq	#1,d7		;count
	addq.l	#4,a0
	lea	(LUT,pc),a4
	move.l	a4,a1
.makLUT	move.l	(a0)+,d1
	move.l	(a0)+,d2
	move.l	(a0)+,d3
	moveq	#0,d0
	rol.l	#8,d1
	rol.l	#8,d2
	rol.l	#8,d3
	move.b	d1,d0	;R
	lsl.l	#8,d0
	move.b	d2,d0	;G
	lsl.l	#8,d0
	move.b	d3,d0	;B
	move.l	d0,(a1)+
	dbf	d7,.makLUT

	move.l	(64+00,a7),a5	;source
	move.l	(64+04,a7),a6	;dest
	move.l	(64+08,a7),d7	;pixels
	move.b	#%00000011,d6
	moveq	#0,d0
	moveq	#0,d2
	moveq	#0,d3
	moveq	#0,d4
.loop	move.b	(a5)+,d0
	move.b	d0,d1
	lsr.b	#6,d1		;control code
	bne.b	.ham
	;-------select new base register
	move.l	(a4,d0.l*4),d2
	move.b	d2,d4		;Blue
	lsr.l	#8,d2
	move.b	d2,d3		;Green
	lsr.l	#8,d2		;Red
	move.b	d2,(a6)+
	move.b	d3,(a6)+
	move.b	d4,(a6)+
	subq.l	#1,d7
	bgt.b	.loop
	bra.b	.end
.ham	;-------hold and modify
	lsl.b	#2,d0
	subq.b	#1,d1
	bne.b	.not_b
	;-------modify Blue
	and.b	d6,d4
	or.b	d0,d4		;keep old 2 LSB
	move.b	d2,(a6)+
	move.b	d3,(a6)+
	move.b	d4,(a6)+
	subq.l	#1,d7
	bgt.b	.loop
	bra.b	.end
.not_b	subq.b	#1,d1
	bne.b	.not_r
	;-------modify Red
	and.b	d6,d2
	or.b	d0,d2		;keep old 2 LSB
	move.b	d2,(a6)+
	move.b	d3,(a6)+
	move.b	d4,(a6)+
	subq.l	#1,d7
	bgt.b	.loop
	bra.b	.end
.not_r	;-------modify Green
	and.b	d6,d3
	or.b	d0,d3		;keep old 2 LSB
	move.b	d2,(a6)+
	move.b	d3,(a6)+
	move.b	d4,(a6)+
	subq.l	#1,d7
	bgt.b	.loop
.end	movem.l	(a7)+,d0-a6
	rts
;-------------------------------------------------------------------------
; 8bit-ChunkyPixels HAM6 to 24bit-Truecolor  by Smack/Infect! 08-Aug-97
;
;  input   __543210 (bits 4 and 5 are the HAM6 control codes,
;                    the unused bits 6 and 7 _MUST_ be cleared!)
;  output  rrrrrrrr gggggggg bbbbbbbb
;
; parameters on stack:
;  00  APTR            source
;  04  APTR            dest
;  08  ULONG           number_of_pixels
;  12  struct loadrgb* palette 
;
_ham6to24
	movem.l	d0-a6,-(a7)	;15*4+4=64

	move.l	(64+12,a7),a0
	move	(a0),d7
	subq	#1,d7		;count
	addq.l	#4,a0
	lea	(LUT,pc),a4
	move.l	a4,a1
.makLUT	move.l	(a0)+,d1
	move.l	(a0)+,d2
	move.l	(a0)+,d3
	moveq	#0,d0
	rol.l	#8,d1
	rol.l	#8,d2
	rol.l	#8,d3
	move.b	d1,d0	;R
	lsl.l	#8,d0
	move.b	d2,d0	;G
	lsl.l	#8,d0
	move.b	d3,d0	;B
	move.l	d0,(a1)+
	dbf	d7,.makLUT

	move.l	(64+00,a7),a5	;source
	move.l	(64+04,a7),a6	;dest
	move.l	(64+08,a7),d7	;pixels
	moveq	#%00001111,d5
	moveq	#0,d0
	moveq	#0,d2
	moveq	#0,d3
	moveq	#0,d4
.loop	move.b	(a5)+,d0
	move.b	d0,d1
	lsr.b	#4,d1		;control code
	bne.b	.ham
	;-------select new base register
	move.l	(a4,d0.l*4),d2
	move.b	d2,d4		;Blue
	lsr.l	#8,d2
	move.b	d2,d3		;Green
	lsr.l	#8,d2		;Red
	move.b	d2,(a6)+
	move.b	d3,(a6)+
	move.b	d4,(a6)+
	subq.l	#1,d7
	bgt.b	.loop
	bra.b	.end
.ham	;-------hold and modify
	lsl.b	#4,d0		;modify the 4 MSB
	subq.b	#1,d1
	bne.b	.not_b
	;-------modify Blue
	and.b	d5,d4
	or.b	d0,d4		;keep old 4 LSB
	move.b	d2,(a6)+
	move.b	d3,(a6)+
	move.b	d4,(a6)+
	subq.l	#1,d7
	bgt.b	.loop
	bra.b	.end
.not_b	subq.b	#1,d1
	bne.b	.not_r
	;-------modify Red
	and.b	d5,d2
	or.b	d0,d2		;keep old 4 LSB
	move.b	d2,(a6)+
	move.b	d3,(a6)+
	move.b	d4,(a6)+
	subq.l	#1,d7
	bgt.b	.loop
	bra.b	.end
.not_r	;-------modify Green
	and.b	d5,d3
	or.b	d0,d3		;keep old 4 LSB
	move.b	d2,(a6)+
	move.b	d3,(a6)+
	move.b	d4,(a6)+
	subq.l	#1,d7
	bgt.b	.loop
.end	movem.l	(a7)+,d0-a6
	rts



_WPA_STUB
	movem.l	d1-a6,-(a7)	;14*4+4=60

	lea	(60,a7),a2

	move.l	(a2)+,a0	;srcrect
	move.l	(a2)+,d0	;srcx
	move.l	(a2)+,d1	;srcy
	move.l	(a2)+,d2	;srcmod
	move.l	(a2)+,a1	;rastport
	move.l	(a2)+,d3	;destx
	move.l	(a2)+,d4	;desty
	move.l	(a2)+,d5	;sizex
	move.l	(a2)+,d6	;sizey
	move.l	(a2)+,d7	;srcformat
	move.l	(a2),a6		;cybergfxbase
	jsr	(-$7e,a6)	;WritePixelArray

	movem.l	(a7)+,d1-a6
	rts
