;------------------------------------------------------------------------------
;	FYEO
;       Frank Lyonnet 1994
;       Module RGB to RGB
;       Author : Frank Lyonnet
;------------------------------------------------------------------------------

                GET     h.ASMRegs
                GET     h.SWInames

                AREA |C$$code|, CODE, READONLY

		IMPORT	|RangeLimitTable|

R		RN	0
G		RN	1
B		RN	2
Out		RN	3
Length		RN	4
RangeLimit	RN	5
Data1		RN	6
DataOut		RN	7
Cpt		RN	14

SCALEBITS       EQU     16

;------------------------------------------------------------------------------
;       rgb_to_16bpp_convert
;------------------------------------------------------------------------------
;       char * R, char * B, char * B, char * Out, long int Length,
;------------------------------------------------------------------------------

                EXPORT  |rgb_to_16bpp_convert|

|rgb_to_16bpp_convert|

                ;Sauve  4 reg et r14 , r13 preserve par le code
                STMFD   sp!, {Length,RangeLimit,Data1,DataOut,r14} 	;5 regs

                ;Recup des parms sur la pile
                LDR     Length,[sp,#((5)*4+0*4)]   	;Longueur

		;Range
		LDR	RangeLimit,=|RangeLimitTable|
		LDR	RangeLimit,[RangeLimit]

		;Compteur a zero
		MOV	Cpt,#0

loop_16
		;Do the Red
		LDRB	Data1,[R,Cpt]
		ADD	Data1,Data1,#2_100		;Arrondi
                LDRB    Data1,[RangeLimit,Data1]     	;Range limit
		MOV	Data1,Data1,LSR#3		;5 bits par comp
                MOV     DataOut,Data1             	;Red comp

		;Do the green
		LDRB	Data1,[G,Cpt]
		ADD	Data1,Data1,#2_100		;Arrondi
                LDRB    Data1,[RangeLimit,Data1]     	;Range limit
		MOV	Data1,Data1,LSR#3		;5 bits par comp
                ORR     DataOut,DataOut,Data1,LSL#5     ;Green comp

		;Do the blue
		LDRB	Data1,[B,Cpt]
		ADD	Data1,Data1,#2_100		;Arrondi
                LDRB    Data1,[RangeLimit,Data1]     	;Range limit
		MOV	Data1,Data1,LSR#3		;5 bits par comp
                ORR     DataOut,DataOut,Data1,LSL#10    ;Blue comp

		;Store 16 bits result
		ADD	Data1,Out,Cpt,ASL#1		;Compute adr
		STRB	DataOut,[Data1]			;Store Low bits
		MOV	DataOut,DataOut,LSR#8		;High bits
		ADD	Data1,Data1,#1			;Compute adr
		STRB	DataOut,[Data1]			;Store High bits

		;Loop
                ADD     Cpt,Cpt,#1
                CMPS    Cpt,Length
                BLO     loop_16

		;Restauration contexte, retour
                LDMFD   sp!,{Length,RangeLimit,Data1,DataOut,r15} ; RICK 2004/01/29 removed '^'

;------------------------------------------------------------------------------
;       rgb_to_32bpp_convert
;------------------------------------------------------------------------------
;       char * Red, char * Green, char * Blue, char * Out, long int Length
;------------------------------------------------------------------------------

                EXPORT  |rgb_to_32bpp_convert|

|rgb_to_32bpp_convert|

                ;Sauve  3 reg et r14 , r13 preserve par le code
                STMFD   sp!, {Length,Data1,DataOut,r14}	;4 regs

                ;Recup des parms sur la pile
                LDR     Length,[sp,#((4)*4+0*4)]   	;Longueur

		;Compteur a zero
		MOV	Cpt,#0

loop_32

		;Do the Red
		LDRB	Data1,[R,Cpt]
                MOV     DataOut,Data1           	;Red comp

		;Do the green
		LDRB	Data1,[G,Cpt]
                ORR     DataOut,DataOut,Data1,LSL#8    	;Green comp

		;Do the blue
		LDRB	Data1,[B,Cpt]
                ORR     DataOut,DataOut,Data1,LSL#16    ;Blue comp

		;Store 32 bits result 0 ... 32 = RGB0

		STR	DataOut,[Out,Cpt,ASL#2]

		;Loop
                ADD     Cpt,Cpt,#1
                CMPS    Cpt,Length
                BLO     loop_32

		;Restauration contexte, retour
                LDMFD   sp!,{Length,Data1,DataOut,r15} ; RICK 2004/01/29 removed '^'

sp_save
                DCD     0

		END



