;------------------------------------------------------------------------------
;       FYEO
;       Frank Lyonnet 1993
;       Fonctions de scaling ( reduction , expansion )
;       Author : Frank Lyonnet
;------------------------------------------------------------------------------

                GET     h.ASMRegs
                GET     h.SWInames

                AREA    |C$$code|, CODE, READONLY


Input           RN      0
Output          RN      1
Num             RN      2
Div             RN      3
OutLineLength   RN      4
Pixel           RN      5
Reste           RN      6
Virt            RN      7
Tmp1            RN      8
Tmp2            RN      9
BorneSup        RN      10
BaseOut         RN      11
BaseOutSup      RN      12
BaseIn          RN      14


                ;--------------------------------------------------------------------
                ; DIVISION MACRO
                ;--------------------------------------------------------------------
                ; Input : Ra = dividend , Rb = divisor , Rc , Rd = ...
                ; Output : Ra = remainder , Rb = divisor , Rc = quotient , Rd = ...
                ;--------------------------------------------------------------------
                MACRO
$Label          DIV     $Ra,$Rb,$Rc,$Rd

$Label
                MOV     $Rd,$Rb
                CMP     $Rd,$Ra,LSR#1
10
                MOVLS   $Rd,$Rd,LSL#1
                CMP     $Rd,$Ra,LSR#1
                BLS     %b10
                MOV     $Rc,#0
11
                CMP     $Ra,$Rd
                SUBCS   $Ra,$Ra,$Rd
                ADC     $Rc,$Rc,$Rc
                MOV     $Rd,$Rd,LSR#1
                CMP     $Rd,$Rb
                BHS     %b11

                MEND

;------------------------------------------------------------------------------
; Cas standard
;------------------------------------------------------------------------------

;------------------------------------------------------------------------------
;       FYEO_hcomponent_reduction
;------------------------------------------------------------------------------
;       parametre no 1 : char * Input
;       parametre no 2 : char * Output
;       parametre no 3 : int Num
;       parametre no 4 : int Div
;       parametre no 5 : int OutLineLength
;------------------------------------------------------------------------------


                EXPORT  |FYEO_hcomponent_reduction|
|FYEO_hcomponent_reduction|
                STMFD   sp!, {r0-r12,r14}

                LDR     OutLineLength,[sp,#((13+1)*4)]          ;Longueur ligne

                CMP     Div,#2                                  ;Take the best
                BEQ     start_hred2

                CMP     Div,#4                                  ;Take the best
                BEQ     start_hred4

                CMP     Div,#8                                  ;Take the best
                BEQ     start_hred8

                CMP     Div,#16                                 ;Take the best
                BEQ     start_hred16

                MOV     Reste,Num                               ;Reste = Num
                MOV     Virt,Div                                ;Virt = Div
                MOV     Pixel,#0                                ;Pixel = 0
                ADD     BorneSup,OutLineLength,Output           ;BorneSup = Output + OutLineLength
boucle_hred
                CMP     Output,BorneSup                         ;While Ouput < BorneSup
                BGE     fin_hred

                CMP     Virt,Num                                ;if ( Virt < = Num )
                BGT     else_hred

                LDRB    Tmp1,[Input]                            ;Tmp1 = * Input
                MLA     Pixel,Tmp1,Virt,Pixel                   ;Pixel = Tmp1 * Virt + Pixel
                DIV     Pixel,Div,Tmp1,Tmp2                     ;Tmp1 = Pixel / Div , Div preserve only
                STRB    Tmp1,[Output],#1                        ;* Output++ = Tmp1
                MOV     Pixel,#0                                ;Pixel = 0
                SUB     Reste,Num,Virt                          ;Reste = Num - Virt
                MOV     Virt,Div                                ;Virt = Div
                B       boucle_hred
else_hred
                LDRB    Tmp1,[Input],#1                         ;Tmp1 = * Input++
                MLA     Pixel,Tmp1,Reste,Pixel                  ;Pixel = Tmp1 * Reste + Pixel
                SUB     Virt,Virt,Reste                         ;Virt = Virt - Reste
                MOV     Reste,Num                               ;Reste = Num
                B       boucle_hred
fin_hred
                LDMFD   sp!, {r0-r12,r15} ; RICK 2004/01/29 removed '^'

;------------------------------------------------------------------------------
;       FYEO_hcomponent_reduction
;------------------------------------------------------------------------------
;       parametre no 1 : char * Input
;       parametre no 2 : char * Output
;       parametre no 3 : int Num
;       parametre no 4 : int Div
;       parametre no 5 : int OutLineLength
;------------------------------------------------------------------------------


                EXPORT  |FYEO_hcomponent_expansion|
|FYEO_hcomponent_expansion|
                STMFD   sp!, {r0-r12,r14}
                LDR     OutLineLength,[sp,#((13+1)*4)]          ;Longueur ligne

                CMP     Div,#2                                  ;Take the best
                BEQ     start_hexp2

                CMP     Div,#4                                  ;Take the best
                BEQ     start_hexp4

                CMP     Div,#8                                  ;Take the best
                BEQ     start_hexp8

                CMP     Div,#16                                 ;Take the best
                BEQ     start_hexp16

                MOV     Reste,Div                               ;Reste = Div
                MOV     Virt,Num                                ;Virt = Num
                MOV     Pixel,#0                                ;Pixel = 0
                ADD     BorneSup,OutLineLength,Output           ;BorneSup = Output + OutLineLength
boucle_hexp
                CMP     Output,BorneSup                         ;While Ouput < BorneSup
                BGE     fin_hexp

                CMP     Virt,Div                                ;if ( Virt < = Div )
                BGT     else_hexp

                LDRB    Tmp1,[Input],#1                         ;Tmp1 = * Input ++
                MLA     Pixel,Tmp1,Virt,Pixel                   ;Pixel = Tmp1 * Virt + Pixel
                SUB     Reste,Div,Virt                          ;Reste = Div - Virt
                MOV     Virt,Num                                ;Virt = Num
                B       boucle_hexp
else_hexp
                LDRB    Tmp1,[Input]                            ;Tmp1 = * Input
                MLA     Pixel,Tmp1,Reste,Pixel                  ;Pixel = Tmp1 * Reste + Pixel
                DIV     Pixel,Div,Tmp1,Tmp2                     ;Tmp1 = Pixel / Div , Div preserve only
                STRB    Tmp1,[Output],#1                        ;* Output++ = Tmp1
                MOV     Pixel,#0                                ;Pixel = 0
                SUB     Virt,Virt,Reste                         ;Virt = Virt - Reste
                MOV     Reste,Div                               ;Reste = Div
                B       boucle_hexp
fin_hexp
                LDMFD   sp!, {r0-r12,r15} ; RICK 2004/01/29 removed '^'

;------------------------------------------------------------------------------
;       FYEO_hcomponent_reduction
;------------------------------------------------------------------------------
;       parametre no 1 : char * Input
;       parametre no 2 : char * Output
;       parametre no 3 : int Num
;       parametre no 4 : int Div
;       parametre no 5 : int OutLineLength
;------------------------------------------------------------------------------


                EXPORT  |FYEO_vcomponent_reduction|
|FYEO_vcomponent_reduction|
                STMFD   sp!, {r0-r12,r14}
                LDR     OutLineLength,[sp,#((13+1)*4)]          ;Longueur ligne

                CMP     Div,#2                                  ;Take the best
                BEQ     start_vred2

                CMP     Div,#4                                  ;Take the best
                BEQ     start_vred4

                CMP     Div,#8                                  ;Take the best
                BEQ     start_vred8

                CMP     Div,#16                                 ;Take the best
                BEQ     start_vred16


                LDR     Tmp1 ,= Savelr                          ;Sauve lr
                STR     lr,[Tmp1]


                MOV     BaseOut,Output                          ;BaseOut = Output
                MOV     BaseIn,Input                            ;BaseIn = Input
                ADD     BaseOutSup,BaseOut,OutLineLength        ;BaseOutSup = BaseOut + OutLineLength
boucle_vred_col
                CMP     BaseOut,BaseOutSup                      ;While ( BaseOut < BaseOutSup )
                BGE     fin_vred_col

                MOV     Reste,Num                               ;Reste = Num
                MOV     Virt,Div                                ;Virt = Div
                MOV     Pixel,#0                                ;Pixel = 0

                MOV     Output,BaseOut                          ;Output = BaseOut
                MOV     Input,BaseIn                            ;Input = BaseIn

                MLA     BorneSup,OutLineLength,Num,Output       ;BorneSup = Num * OutLineLength + Output
boucle_vred
                CMP     Output,BorneSup                         ;While Ouput < BorneSup
                BGE     fin_vred

                CMP     Virt,Num                                ;if ( Virt < = Num )
                BGT     else_vred

                LDRB    Tmp1,[Input]                            ;Tmp1 = * Input
                MLA     Pixel,Tmp1,Virt,Pixel                   ;Pixel = Tmp1 * Virt + Pixel
                DIV     Pixel,Div,Tmp1,Tmp2                     ;Tmp1 = Pixel / Div , Div preserve only
                STRB    Tmp1,[Output],OutLineLength             ;* Output = Tmp1 , Output += OutLineLength
                MOV     Pixel,#0                                ;Pixel = 0
                SUB     Reste,Num,Virt                          ;Reste = Num - Virt
                MOV     Virt,Div                                ;Virt = Div
                B       boucle_vred
else_vred
                LDRB    Tmp1,[Input],OutLineLength              ;Tmp1 = * Input , Input +=OutLineLength
                MLA     Pixel,Tmp1,Reste,Pixel                  ;Pixel = Tmp1 * Reste + Pixel
                SUB     Virt,Virt,Reste                         ;Virt = Virt - Reste
                MOV     Reste,Num                               ;Reste = Num
                B       boucle_vred
fin_vred
                ADD     BaseIn,BaseIn,#1                        ;Base = Base + 1 , colonne suivante
                ADD     BaseOut,BaseOut,#1                      ;Base = Base + 1 , colonne suivante

                B       boucle_vred_col
fin_vred_col

                LDR     Tmp1 ,= Savelr                          ;Restaure lr
                LDR     lr,[Tmp1]

                LDMFD   sp!, {r0-r12,r15} ; RICK 2004/01/29 removed '^'

;------------------------------------------------------------------------------
;       FYEO_hcomponent_reduction
;------------------------------------------------------------------------------
;       parametre no 1 : char * Input
;       parametre no 2 : char * Output
;       parametre no 3 : int Num
;       parametre no 4 : int Div
;       parametre no 5 : int OutLineLength
;------------------------------------------------------------------------------


                EXPORT  |FYEO_vcomponent_expansion|
|FYEO_vcomponent_expansion|
                STMFD   sp!, {r0-r12,r14}
                LDR     OutLineLength,[sp,#((13+1)*4)]          ;Longueur ligne

                LDR     Tmp1 ,= Savelr                          ;Sauve lr
                STR     lr,[Tmp1]

                CMP     Div,#2                                  ;Take the best
                BEQ     start_vexp2

                CMP     Div,#4                                  ;Take the best
                BEQ     start_vexp4

                CMP     Div,#8                                  ;Take the best
                BEQ     start_vexp8

                CMP     Div,#16                                 ;Take the best
                BEQ     start_vexp16


                MOV     BaseOut,Output                          ;BaseOut = Output
                MOV     BaseIn,Input                            ;BaseIn = Input
                ADD     BaseOutSup,BaseOut,OutLineLength        ;BaseOutSup = BaseOut + OutLineLength
boucle_vexp_col
                CMP     BaseOut,BaseOutSup                      ;While ( BaseOut < BaseOutSup )
                BGE     fin_vexp_col

                MOV     Reste,Div                               ;Reste = Div
                MOV     Virt,Num                                ;Virt = Num
                MOV     Pixel,#0                                ;Pixel = 0

                MOV     Output,BaseOut                          ;Output = BaseOut
                MOV     Input,BaseIn                            ;Input = BaseIn

                MLA     BorneSup,OutLineLength,Num,Output       ;BorneSup = Num * OutLineLength + Output

boucle_vexp
                CMP     Output,BorneSup                         ;While Ouput < BorneSup
                BGE     fin_vexp

                CMP     Virt,Div                                ;if ( Virt < = Div )
                BGT     else_vexp

                LDRB    Tmp1,[Input],OutLineLength              ;Tmp1 = * Input , Input += OutLineLength
                MLA     Pixel,Tmp1,Virt,Pixel                   ;Pixel = Tmp1 * Virt + Pixel
                SUB     Reste,Div,Virt                          ;Reste = Div - Virt
                MOV     Virt,Num                                ;Virt = Num
                B       boucle_vexp
else_vexp
                LDRB    Tmp1,[Input]                            ;Tmp1 = * Input
                MLA     Pixel,Tmp1,Reste,Pixel                  ;Pixel = Tmp1 * Reste + Pixel
                DIV     Pixel,Div,Tmp1,Tmp2                     ;Tmp1 = Pixel / Div , Div preserve only
                STRB    Tmp1,[Output],OutLineLength             ;* Output = Tmp1 , Output += OutLineLength
                MOV     Pixel,#0                                ;Pixel = 0
                SUB     Virt,Virt,Reste                         ;Virt = Virt - Reste
                MOV     Reste,Div                               ;Reste = Div
                B       boucle_vexp
fin_vexp
                ADD     BaseIn,BaseIn,#1                        ;Base = Base + 1 , colonne suivante
                ADD     BaseOut,BaseOut,#1                      ;Base = Base + 1 , colonne suivante

                B       boucle_vexp_col
fin_vexp_col

                LDR     Tmp1 ,= Savelr                          ;Restaure lr
                LDR     lr,[Tmp1]

                LDMFD   sp!, {r0-r12,r15} ; RICK 2004/01/29 removed '^'


;------------------------------------------------------------------------------
; Cas Div = 2
;------------------------------------------------------------------------------

                ;--------------------------
                ; hred2
                ;--------------------------

start_hred2
                MOV     Reste,Num                               ;Reste = Num
                MOV     Virt,Div                                ;Virt = Div
                MOV     Pixel,#0                                ;Pixel = 0
                ADD     BorneSup,OutLineLength,Output           ;BorneSup = Output + OutLineLength
boucle_hred2
                CMP     Output,BorneSup                         ;While Ouput < BorneSup
                BGE     fin_hred2

                CMP     Virt,Num                                ;if ( Virt < = Num )
                BGT     else_hred2

                LDRB    Tmp1,[Input]                            ;Tmp1 = * Input
                MLA     Pixel,Tmp1,Virt,Pixel                   ;Pixel = Tmp1 * Virt + Pixel
                MOV     Tmp1,Pixel,ASR#1                        ;Tmp1 = Pixel / Div , Div preserve only
                STRB    Tmp1,[Output],#1                        ;* Output++ = Tmp1
                MOV     Pixel,#0                                ;Pixel = 0
                SUB     Reste,Num,Virt                          ;Reste = Num - Virt
                MOV     Virt,Div                                ;Virt = Div
                B       boucle_hred2
else_hred2
                LDRB    Tmp1,[Input],#1                         ;Tmp1 = * Input++
                MLA     Pixel,Tmp1,Reste,Pixel                  ;Pixel = Tmp1 * Reste + Pixel
                SUB     Virt,Virt,Reste                         ;Virt = Virt - Reste
                MOV     Reste,Num                               ;Reste = Num
                B       boucle_hred2
fin_hred2
                LDMFD   sp!, {r0-r12,r15} ; RICK 2004/01/29 removed '^'

                ;--------------------------
                ; hexp2
                ;--------------------------

start_hexp2

                MOV     Reste,Div                               ;Reste = Div
                MOV     Virt,Num                                ;Virt = Num
                MOV     Pixel,#0                                ;Pixel = 0
                ADD     BorneSup,OutLineLength,Output           ;BorneSup = Output + OutLineLength
boucle_hexp2
                CMP     Output,BorneSup                         ;While Ouput < BorneSup
                BGE     fin_hexp2

                CMP     Virt,Div                                ;if ( Virt < = Div )
                BGT     else_hexp2

                LDRB    Tmp1,[Input],#1                         ;Tmp1 = * Input ++
                MLA     Pixel,Tmp1,Virt,Pixel                   ;Pixel = Tmp1 * Virt + Pixel
                SUB     Reste,Div,Virt                          ;Reste = Div - Virt
                MOV     Virt,Num                                ;Virt = Num
                B       boucle_hexp2
else_hexp2
                LDRB    Tmp1,[Input]                            ;Tmp1 = * Input
                MLA     Pixel,Tmp1,Reste,Pixel                  ;Pixel = Tmp1 * Reste + Pixel
                MOV     Tmp1,Pixel,ASR#1                        ;Tmp1 = Pixel / Div , Div preserve only
                STRB    Tmp1,[Output],#1                        ;* Output++ = Tmp1
                MOV     Pixel,#0                                ;Pixel = 0
                SUB     Virt,Virt,Reste                         ;Virt = Virt - Reste
                MOV     Reste,Div                               ;Reste = Div
                B       boucle_hexp2
fin_hexp2
                LDMFD   sp!, {r0-r12,r15} ; RICK 2004/01/29 removed '^'


                ;--------------------------
                ; vred2
                ;--------------------------

start_vred2

                MOV     BaseOut,Output                          ;BaseOut = Output
                MOV     BaseIn,Input                            ;BaseIn = Input
                ADD     BaseOutSup,BaseOut,OutLineLength        ;BaseOutSup = BaseOut + OutLineLength
boucle_vred2_col
                CMP     BaseOut,BaseOutSup                      ;While ( BaseOut < BaseOutSup )
                BGE     fin_vred2_col

                MOV     Reste,Num                               ;Reste = Num
                MOV     Virt,Div                                ;Virt = Div
                MOV     Pixel,#0                                ;Pixel = 0

                MOV     Output,BaseOut                          ;Output = BaseOut
                MOV     Input,BaseIn                            ;Input = BaseIn

                MLA     BorneSup,OutLineLength,Num,Output       ;BorneSup = Num * OutLineLength + Output
boucle_vred2
                CMP     Output,BorneSup                         ;While Ouput < BorneSup
                BGE     fin_vred2

                CMP     Virt,Num                                ;if ( Virt < = Num )
                BGT     else_vred2

                LDRB    Tmp1,[Input]                            ;Tmp1 = * Input
                MLA     Pixel,Tmp1,Virt,Pixel                   ;Pixel = Tmp1 * Virt + Pixel
                MOV     Tmp1,Pixel,ASR#1                        ;Tmp1 = Pixel / Div , Div preserve only
                STRB    Tmp1,[Output],OutLineLength             ;* Output = Tmp1 , Output += OutLineLength
                MOV     Pixel,#0                                ;Pixel = 0
                SUB     Reste,Num,Virt                          ;Reste = Num - Virt
                MOV     Virt,Div                                ;Virt = Div
                B       boucle_vred2
else_vred2
                LDRB    Tmp1,[Input],OutLineLength              ;Tmp1 = * Input , Input +=OutLineLength
                MLA     Pixel,Tmp1,Reste,Pixel                  ;Pixel = Tmp1 * Reste + Pixel
                SUB     Virt,Virt,Reste                         ;Virt = Virt - Reste
                MOV     Reste,Num                               ;Reste = Num
                B       boucle_vred2
fin_vred2
                ADD     BaseIn,BaseIn,#1                        ;Base = Base + 1 , colonne suivante
                ADD     BaseOut,BaseOut,#1                      ;Base = Base + 1 , colonne suivante

                B       boucle_vred2_col
fin_vred2_col

                LDR     Tmp1 ,= Savelr                          ;Restaure lr
                LDR     lr,[Tmp1]

                LDMFD   sp!, {r0-r12,r15} ; RICK 2004/01/29 removed '^'

                ;--------------------------
                ; vexp2
                ;--------------------------
start_vexp2
                MOV     BaseOut,Output                          ;BaseOut = Output
                MOV     BaseIn,Input                            ;BaseIn = Input
                ADD     BaseOutSup,BaseOut,OutLineLength        ;BaseOutSup = BaseOut + OutLineLength
boucle_vexp2_col
                CMP     BaseOut,BaseOutSup                      ;While ( BaseOut < BaseOutSup )
                BGE     fin_vexp2_col

                MOV     Reste,Div                               ;Reste = Div
                MOV     Virt,Num                                ;Virt = Num
                MOV     Pixel,#0                                ;Pixel = 0

                MOV     Output,BaseOut                          ;Output = BaseOut
                MOV     Input,BaseIn                            ;Input = BaseIn

                MLA     BorneSup,OutLineLength,Num,Output       ;BorneSup = Num * OutLineLength + Output

boucle_vexp2
                CMP     Output,BorneSup                         ;While Ouput < BorneSup
                BGE     fin_vexp2

                CMP     Virt,Div                                ;if ( Virt < = Div )
                BGT     else_vexp2

                LDRB    Tmp1,[Input],OutLineLength              ;Tmp1 = * Input , Input += OutLineLength
                MLA     Pixel,Tmp1,Virt,Pixel                   ;Pixel = Tmp1 * Virt + Pixel
                SUB     Reste,Div,Virt                          ;Reste = Div - Virt
                MOV     Virt,Num                                ;Virt = Num
                B       boucle_vexp2
else_vexp2
                LDRB    Tmp1,[Input]                            ;Tmp1 = * Input
                MLA     Pixel,Tmp1,Reste,Pixel                  ;Pixel = Tmp1 * Reste + Pixel
                MOV     Tmp1,Pixel,ASR#1                        ;Tmp1 = Pixel / Div , Div preserve only
                STRB    Tmp1,[Output],OutLineLength             ;* Output = Tmp1 , Output += OutLineLength
                MOV     Pixel,#0                                ;Pixel = 0
                SUB     Virt,Virt,Reste                         ;Virt = Virt - Reste
                MOV     Reste,Div                               ;Reste = Div
                B       boucle_vexp2
fin_vexp2
                ADD     BaseIn,BaseIn,#1                        ;Base = Base + 1 , colonne suivante
                ADD     BaseOut,BaseOut,#1                      ;Base = Base + 1 , colonne suivante

                B       boucle_vexp2_col
fin_vexp2_col

                LDR     Tmp1 ,= Savelr                          ;Restaure lr
                LDR     lr,[Tmp1]

                LDMFD   sp!, {r0-r12,r15} ; RICK 2004/01/29 removed '^'

;------------------------------------------------------------------------------
; Cas Div = 4
;------------------------------------------------------------------------------

                ;--------------------------
                ; hred4
                ;--------------------------

start_hred4
                MOV     Reste,Num                               ;Reste = Num
                MOV     Virt,Div                                ;Virt = Div
                MOV     Pixel,#0                                ;Pixel = 0
                ADD     BorneSup,OutLineLength,Output           ;BorneSup = Output + OutLineLength
boucle_hred4
                CMP     Output,BorneSup                         ;While Ouput < BorneSup
                BGE     fin_hred4

                CMP     Virt,Num                                ;if ( Virt < = Num )
                BGT     else_hred4

                LDRB    Tmp1,[Input]                            ;Tmp1 = * Input
                MLA     Pixel,Tmp1,Virt,Pixel                   ;Pixel = Tmp1 * Virt + Pixel
                MOV     Tmp1,Pixel,ASR#2                        ;Tmp1 = Pixel / Div , Div preserve only
                STRB    Tmp1,[Output],#1                        ;* Output++ = Tmp1
                MOV     Pixel,#0                                ;Pixel = 0
                SUB     Reste,Num,Virt                          ;Reste = Num - Virt
                MOV     Virt,Div                                ;Virt = Div
                B       boucle_hred4
else_hred4
                LDRB    Tmp1,[Input],#1                         ;Tmp1 = * Input++
                MLA     Pixel,Tmp1,Reste,Pixel                  ;Pixel = Tmp1 * Reste + Pixel
                SUB     Virt,Virt,Reste                         ;Virt = Virt - Reste
                MOV     Reste,Num                               ;Reste = Num
                B       boucle_hred4
fin_hred4
                LDMFD   sp!, {r0-r12,r15} ; RICK 2004/01/29 removed '^'

                ;--------------------------
                ; hexp4
                ;--------------------------

start_hexp4

                MOV     Reste,Div                               ;Reste = Div
                MOV     Virt,Num                                ;Virt = Num
                MOV     Pixel,#0                                ;Pixel = 0
                ADD     BorneSup,OutLineLength,Output           ;BorneSup = Output + OutLineLength
boucle_hexp4
                CMP     Output,BorneSup                         ;While Ouput < BorneSup
                BGE     fin_hexp4

                CMP     Virt,Div                                ;if ( Virt < = Div )
                BGT     else_hexp4

                LDRB    Tmp1,[Input],#1                         ;Tmp1 = * Input ++
                MLA     Pixel,Tmp1,Virt,Pixel                   ;Pixel = Tmp1 * Virt + Pixel
                SUB     Reste,Div,Virt                          ;Reste = Div - Virt
                MOV     Virt,Num                                ;Virt = Num
                B       boucle_hexp4
else_hexp4
                LDRB    Tmp1,[Input]                            ;Tmp1 = * Input
                MLA     Pixel,Tmp1,Reste,Pixel                  ;Pixel = Tmp1 * Reste + Pixel
                MOV     Tmp1,Pixel,ASR#2                        ;Tmp1 = Pixel / Div , Div preserve only
                STRB    Tmp1,[Output],#1                        ;* Output++ = Tmp1
                MOV     Pixel,#0                                ;Pixel = 0
                SUB     Virt,Virt,Reste                         ;Virt = Virt - Reste
                MOV     Reste,Div                               ;Reste = Div
                B       boucle_hexp4
fin_hexp4
                LDMFD   sp!, {r0-r12,r15} ; RICK 2004/01/29 removed '^'


                ;--------------------------
                ; vred4
                ;--------------------------

start_vred4

                MOV     BaseOut,Output                          ;BaseOut = Output
                MOV     BaseIn,Input                            ;BaseIn = Input
                ADD     BaseOutSup,BaseOut,OutLineLength        ;BaseOutSup = BaseOut + OutLineLength
boucle_vred4_col
                CMP     BaseOut,BaseOutSup                      ;While ( BaseOut < BaseOutSup )
                BGE     fin_vred4_col

                MOV     Reste,Num                               ;Reste = Num
                MOV     Virt,Div                                ;Virt = Div
                MOV     Pixel,#0                                ;Pixel = 0

                MOV     Output,BaseOut                          ;Output = BaseOut
                MOV     Input,BaseIn                            ;Input = BaseIn

                MLA     BorneSup,OutLineLength,Num,Output       ;BorneSup = Num * OutLineLength + Output
boucle_vred4
                CMP     Output,BorneSup                         ;While Ouput < BorneSup
                BGE     fin_vred4

                CMP     Virt,Num                                ;if ( Virt < = Num )
                BGT     else_vred4

                LDRB    Tmp1,[Input]                            ;Tmp1 = * Input
                MLA     Pixel,Tmp1,Virt,Pixel                   ;Pixel = Tmp1 * Virt + Pixel
                MOV     Tmp1,Pixel,ASR#2                        ;Tmp1 = Pixel / Div , Div preserve only
                STRB    Tmp1,[Output],OutLineLength             ;* Output = Tmp1 , Output += OutLineLength
                MOV     Pixel,#0                                ;Pixel = 0
                SUB     Reste,Num,Virt                          ;Reste = Num - Virt
                MOV     Virt,Div                                ;Virt = Div
                B       boucle_vred4
else_vred4
                LDRB    Tmp1,[Input],OutLineLength              ;Tmp1 = * Input , Input +=OutLineLength
                MLA     Pixel,Tmp1,Reste,Pixel                  ;Pixel = Tmp1 * Reste + Pixel
                SUB     Virt,Virt,Reste                         ;Virt = Virt - Reste
                MOV     Reste,Num                               ;Reste = Num
                B       boucle_vred4
fin_vred4
                ADD     BaseIn,BaseIn,#1                        ;Base = Base + 1 , colonne suivante
                ADD     BaseOut,BaseOut,#1                      ;Base = Base + 1 , colonne suivante

                B       boucle_vred4_col
fin_vred4_col

                LDR     Tmp1 ,= Savelr                          ;Restaure lr
                LDR     lr,[Tmp1]

                LDMFD   sp!, {r0-r12,r15} ; RICK 2004/01/29 removed '^'

                ;--------------------------
                ; vexp4
                ;--------------------------
start_vexp4
                MOV     BaseOut,Output                          ;BaseOut = Output
                MOV     BaseIn,Input                            ;BaseIn = Input
                ADD     BaseOutSup,BaseOut,OutLineLength        ;BaseOutSup = BaseOut + OutLineLength
boucle_vexp4_col
                CMP     BaseOut,BaseOutSup                      ;While ( BaseOut < BaseOutSup )
                BGE     fin_vexp4_col

                MOV     Reste,Div                               ;Reste = Div
                MOV     Virt,Num                                ;Virt = Num
                MOV     Pixel,#0                                ;Pixel = 0

                MOV     Output,BaseOut                          ;Output = BaseOut
                MOV     Input,BaseIn                            ;Input = BaseIn

                MLA     BorneSup,OutLineLength,Num,Output       ;BorneSup = Num * OutLineLength + Output

boucle_vexp4
                CMP     Output,BorneSup                         ;While Ouput < BorneSup
                BGE     fin_vexp4

                CMP     Virt,Div                                ;if ( Virt < = Div )
                BGT     else_vexp4

                LDRB    Tmp1,[Input],OutLineLength              ;Tmp1 = * Input , Input += OutLineLength
                MLA     Pixel,Tmp1,Virt,Pixel                   ;Pixel = Tmp1 * Virt + Pixel
                SUB     Reste,Div,Virt                          ;Reste = Div - Virt
                MOV     Virt,Num                                ;Virt = Num
                B       boucle_vexp4
else_vexp4
                LDRB    Tmp1,[Input]                            ;Tmp1 = * Input
                MLA     Pixel,Tmp1,Reste,Pixel                  ;Pixel = Tmp1 * Reste + Pixel
                MOV     Tmp1,Pixel,ASR#2                        ;Tmp1 = Pixel / Div , Div preserve only
                STRB    Tmp1,[Output],OutLineLength             ;* Output = Tmp1 , Output += OutLineLength
                MOV     Pixel,#0                                ;Pixel = 0
                SUB     Virt,Virt,Reste                         ;Virt = Virt - Reste
                MOV     Reste,Div                               ;Reste = Div
                B       boucle_vexp4
fin_vexp4
                ADD     BaseIn,BaseIn,#1                        ;Base = Base + 1 , colonne suivante
                ADD     BaseOut,BaseOut,#1                      ;Base = Base + 1 , colonne suivante

                B       boucle_vexp4_col
fin_vexp4_col

                LDR     Tmp1 ,= Savelr                          ;Restaure lr
                LDR     lr,[Tmp1]

                LDMFD   sp!, {r0-r12,r15} ; RICK 2004/01/29 removed '^'

;------------------------------------------------------------------------------
; Cas Div = 8
;------------------------------------------------------------------------------

                ;--------------------------
                ; hred8
                ;--------------------------

start_hred8
                MOV     Reste,Num                               ;Reste = Num
                MOV     Virt,Div                                ;Virt = Div
                MOV     Pixel,#0                                ;Pixel = 0
                ADD     BorneSup,OutLineLength,Output           ;BorneSup = Output + OutLineLength
boucle_hred8
                CMP     Output,BorneSup                         ;While Ouput < BorneSup
                BGE     fin_hred8

                CMP     Virt,Num                                ;if ( Virt < = Num )
                BGT     else_hred8

                LDRB    Tmp1,[Input]                            ;Tmp1 = * Input
                MLA     Pixel,Tmp1,Virt,Pixel                   ;Pixel = Tmp1 * Virt + Pixel
                MOV     Tmp1,Pixel,ASR#3                        ;Tmp1 = Pixel / Div , Div preserve only
                STRB    Tmp1,[Output],#1                        ;* Output++ = Tmp1
                MOV     Pixel,#0                                ;Pixel = 0
                SUB     Reste,Num,Virt                          ;Reste = Num - Virt
                MOV     Virt,Div                                ;Virt = Div
                B       boucle_hred8
else_hred8
                LDRB    Tmp1,[Input],#1                         ;Tmp1 = * Input++
                MLA     Pixel,Tmp1,Reste,Pixel                  ;Pixel = Tmp1 * Reste + Pixel
                SUB     Virt,Virt,Reste                         ;Virt = Virt - Reste
                MOV     Reste,Num                               ;Reste = Num
                B       boucle_hred8
fin_hred8
                LDMFD   sp!, {r0-r12,r15} ; RICK 2004/01/29 removed '^'

                ;--------------------------
                ; hexp8
                ;--------------------------

start_hexp8

                MOV     Reste,Div                               ;Reste = Div
                MOV     Virt,Num                                ;Virt = Num
                MOV     Pixel,#0                                ;Pixel = 0
                ADD     BorneSup,OutLineLength,Output           ;BorneSup = Output + OutLineLength
boucle_hexp8
                CMP     Output,BorneSup                         ;While Ouput < BorneSup
                BGE     fin_hexp8

                CMP     Virt,Div                                ;if ( Virt < = Div )
                BGT     else_hexp8

                LDRB    Tmp1,[Input],#1                         ;Tmp1 = * Input ++
                MLA     Pixel,Tmp1,Virt,Pixel                   ;Pixel = Tmp1 * Virt + Pixel
                SUB     Reste,Div,Virt                          ;Reste = Div - Virt
                MOV     Virt,Num                                ;Virt = Num
                B       boucle_hexp8
else_hexp8
                LDRB    Tmp1,[Input]                            ;Tmp1 = * Input
                MLA     Pixel,Tmp1,Reste,Pixel                  ;Pixel = Tmp1 * Reste + Pixel
                MOV     Tmp1,Pixel,ASR#3                        ;Tmp1 = Pixel / Div , Div preserve only
                STRB    Tmp1,[Output],#1                        ;* Output++ = Tmp1
                MOV     Pixel,#0                                ;Pixel = 0
                SUB     Virt,Virt,Reste                         ;Virt = Virt - Reste
                MOV     Reste,Div                               ;Reste = Div
                B       boucle_hexp8
fin_hexp8
                LDMFD   sp!, {r0-r12,r15} ; RICK 2004/01/29 removed '^'


                ;--------------------------
                ; vred8
                ;--------------------------

start_vred8

                MOV     BaseOut,Output                          ;BaseOut = Output
                MOV     BaseIn,Input                            ;BaseIn = Input
                ADD     BaseOutSup,BaseOut,OutLineLength        ;BaseOutSup = BaseOut + OutLineLength
boucle_vred8_col
                CMP     BaseOut,BaseOutSup                      ;While ( BaseOut < BaseOutSup )
                BGE     fin_vred8_col

                MOV     Reste,Num                               ;Reste = Num
                MOV     Virt,Div                                ;Virt = Div
                MOV     Pixel,#0                                ;Pixel = 0

                MOV     Output,BaseOut                          ;Output = BaseOut
                MOV     Input,BaseIn                            ;Input = BaseIn

                MLA     BorneSup,OutLineLength,Num,Output       ;BorneSup = Num * OutLineLength + Output
boucle_vred8
                CMP     Output,BorneSup                         ;While Ouput < BorneSup
                BGE     fin_vred8

                CMP     Virt,Num                                ;if ( Virt < = Num )
                BGT     else_vred8

                LDRB    Tmp1,[Input]                            ;Tmp1 = * Input
                MLA     Pixel,Tmp1,Virt,Pixel                   ;Pixel = Tmp1 * Virt + Pixel
                MOV     Tmp1,Pixel,ASR#3                        ;Tmp1 = Pixel / Div , Div preserve only
                STRB    Tmp1,[Output],OutLineLength             ;* Output = Tmp1 , Output += OutLineLength
                MOV     Pixel,#0                                ;Pixel = 0
                SUB     Reste,Num,Virt                          ;Reste = Num - Virt
                MOV     Virt,Div                                ;Virt = Div
                B       boucle_vred8
else_vred8
                LDRB    Tmp1,[Input],OutLineLength              ;Tmp1 = * Input , Input +=OutLineLength
                MLA     Pixel,Tmp1,Reste,Pixel                  ;Pixel = Tmp1 * Reste + Pixel
                SUB     Virt,Virt,Reste                         ;Virt = Virt - Reste
                MOV     Reste,Num                               ;Reste = Num
                B       boucle_vred8
fin_vred8
                ADD     BaseIn,BaseIn,#1                        ;Base = Base + 1 , colonne suivante
                ADD     BaseOut,BaseOut,#1                      ;Base = Base + 1 , colonne suivante

                B       boucle_vred8_col
fin_vred8_col

                LDR     Tmp1 ,= Savelr                          ;Restaure lr
                LDR     lr,[Tmp1]

                LDMFD   sp!, {r0-r12,r15} ; RICK 2004/01/29 removed '^'

                ;--------------------------
                ; vexp8
                ;--------------------------
start_vexp8
                MOV     BaseOut,Output                          ;BaseOut = Output
                MOV     BaseIn,Input                            ;BaseIn = Input
                ADD     BaseOutSup,BaseOut,OutLineLength        ;BaseOutSup = BaseOut + OutLineLength
boucle_vexp8_col
                CMP     BaseOut,BaseOutSup                      ;While ( BaseOut < BaseOutSup )
                BGE     fin_vexp8_col

                MOV     Reste,Div                               ;Reste = Div
                MOV     Virt,Num                                ;Virt = Num
                MOV     Pixel,#0                                ;Pixel = 0

                MOV     Output,BaseOut                          ;Output = BaseOut
                MOV     Input,BaseIn                            ;Input = BaseIn

                MLA     BorneSup,OutLineLength,Num,Output       ;BorneSup = Num * OutLineLength + Output

boucle_vexp8
                CMP     Output,BorneSup                         ;While Ouput < BorneSup
                BGE     fin_vexp8

                CMP     Virt,Div                                ;if ( Virt < = Div )
                BGT     else_vexp8

                LDRB    Tmp1,[Input],OutLineLength              ;Tmp1 = * Input , Input += OutLineLength
                MLA     Pixel,Tmp1,Virt,Pixel                   ;Pixel = Tmp1 * Virt + Pixel
                SUB     Reste,Div,Virt                          ;Reste = Div - Virt
                MOV     Virt,Num                                ;Virt = Num
                B       boucle_vexp8
else_vexp8
                LDRB    Tmp1,[Input]                            ;Tmp1 = * Input
                MLA     Pixel,Tmp1,Reste,Pixel                  ;Pixel = Tmp1 * Reste + Pixel
                MOV     Tmp1,Pixel,ASR#3                        ;Tmp1 = Pixel / Div , Div preserve only
                STRB    Tmp1,[Output],OutLineLength             ;* Output = Tmp1 , Output += OutLineLength
                MOV     Pixel,#0                                ;Pixel = 0
                SUB     Virt,Virt,Reste                         ;Virt = Virt - Reste
                MOV     Reste,Div                               ;Reste = Div
                B       boucle_vexp8
fin_vexp8
                ADD     BaseIn,BaseIn,#1                        ;Base = Base + 1 , colonne suivante
                ADD     BaseOut,BaseOut,#1                      ;Base = Base + 1 , colonne suivante

                B       boucle_vexp8_col
fin_vexp8_col

                LDR     Tmp1 ,= Savelr                          ;Restaure lr
                LDR     lr,[Tmp1]

                LDMFD   sp!, {r0-r12,r15} ; RICK 2004/01/29 removed '^'

;------------------------------------------------------------------------------
; Cas Div = 16
;------------------------------------------------------------------------------

                ;--------------------------
                ; hred16
                ;--------------------------

start_hred16
                MOV     Reste,Num                               ;Reste = Num
                MOV     Virt,Div                                ;Virt = Div
                MOV     Pixel,#0                                ;Pixel = 0
                ADD     BorneSup,OutLineLength,Output           ;BorneSup = Output + OutLineLength
boucle_hred16
                CMP     Output,BorneSup                         ;While Ouput < BorneSup
                BGE     fin_hred16

                CMP     Virt,Num                                ;if ( Virt < = Num )
                BGT     else_hred16

                LDRB    Tmp1,[Input]                            ;Tmp1 = * Input
                MLA     Pixel,Tmp1,Virt,Pixel                   ;Pixel = Tmp1 * Virt + Pixel
                MOV     Tmp1,Pixel,ASR#4                        ;Tmp1 = Pixel / Div , Div preserve only
                STRB    Tmp1,[Output],#1                        ;* Output++ = Tmp1
                MOV     Pixel,#0                                ;Pixel = 0
                SUB     Reste,Num,Virt                          ;Reste = Num - Virt
                MOV     Virt,Div                                ;Virt = Div
                B       boucle_hred16
else_hred16
                LDRB    Tmp1,[Input],#1                         ;Tmp1 = * Input++
                MLA     Pixel,Tmp1,Reste,Pixel                  ;Pixel = Tmp1 * Reste + Pixel
                SUB     Virt,Virt,Reste                         ;Virt = Virt - Reste
                MOV     Reste,Num                               ;Reste = Num
                B       boucle_hred16
fin_hred16
                LDMFD   sp!, {r0-r12,r15} ; RICK 2004/01/29 removed '^'

                ;--------------------------
                ; hexp16
                ;--------------------------

start_hexp16

                MOV     Reste,Div                               ;Reste = Div
                MOV     Virt,Num                                ;Virt = Num
                MOV     Pixel,#0                                ;Pixel = 0
                ADD     BorneSup,OutLineLength,Output           ;BorneSup = Output + OutLineLength
boucle_hexp16
                CMP     Output,BorneSup                         ;While Ouput < BorneSup
                BGE     fin_hexp16

                CMP     Virt,Div                                ;if ( Virt < = Div )
                BGT     else_hexp16

                LDRB    Tmp1,[Input],#1                         ;Tmp1 = * Input ++
                MLA     Pixel,Tmp1,Virt,Pixel                   ;Pixel = Tmp1 * Virt + Pixel
                SUB     Reste,Div,Virt                          ;Reste = Div - Virt
                MOV     Virt,Num                                ;Virt = Num
                B       boucle_hexp16
else_hexp16
                LDRB    Tmp1,[Input]                            ;Tmp1 = * Input
                MLA     Pixel,Tmp1,Reste,Pixel                  ;Pixel = Tmp1 * Reste + Pixel
                MOV     Tmp1,Pixel,ASR#4                        ;Tmp1 = Pixel / Div , Div preserve only
                STRB    Tmp1,[Output],#1                        ;* Output++ = Tmp1
                MOV     Pixel,#0                                ;Pixel = 0
                SUB     Virt,Virt,Reste                         ;Virt = Virt - Reste
                MOV     Reste,Div                               ;Reste = Div
                B       boucle_hexp16
fin_hexp16
                LDMFD   sp!, {r0-r12,r15} ; RICK 2004/01/29 removed '^'


                ;--------------------------
                ; vred16
                ;--------------------------

start_vred16

                MOV     BaseOut,Output                          ;BaseOut = Output
                MOV     BaseIn,Input                            ;BaseIn = Input
                ADD     BaseOutSup,BaseOut,OutLineLength        ;BaseOutSup = BaseOut + OutLineLength
boucle_vred16_col
                CMP     BaseOut,BaseOutSup                      ;While ( BaseOut < BaseOutSup )
                BGE     fin_vred16_col

                MOV     Reste,Num                               ;Reste = Num
                MOV     Virt,Div                                ;Virt = Div
                MOV     Pixel,#0                                ;Pixel = 0

                MOV     Output,BaseOut                          ;Output = BaseOut
                MOV     Input,BaseIn                            ;Input = BaseIn

                MLA     BorneSup,OutLineLength,Num,Output       ;BorneSup = Num * OutLineLength + Output
boucle_vred16
                CMP     Output,BorneSup                         ;While Ouput < BorneSup
                BGE     fin_vred16

                CMP     Virt,Num                                ;if ( Virt < = Num )
                BGT     else_vred16

                LDRB    Tmp1,[Input]                            ;Tmp1 = * Input
                MLA     Pixel,Tmp1,Virt,Pixel                   ;Pixel = Tmp1 * Virt + Pixel
                MOV     Tmp1,Pixel,ASR#4                        ;Tmp1 = Pixel / Div , Div preserve only
                STRB    Tmp1,[Output],OutLineLength             ;* Output = Tmp1 , Output += OutLineLength
                MOV     Pixel,#0                                ;Pixel = 0
                SUB     Reste,Num,Virt                          ;Reste = Num - Virt
                MOV     Virt,Div                                ;Virt = Div
                B       boucle_vred16
else_vred16
                LDRB    Tmp1,[Input],OutLineLength              ;Tmp1 = * Input , Input +=OutLineLength
                MLA     Pixel,Tmp1,Reste,Pixel                  ;Pixel = Tmp1 * Reste + Pixel
                SUB     Virt,Virt,Reste                         ;Virt = Virt - Reste
                MOV     Reste,Num                               ;Reste = Num
                B       boucle_vred16
fin_vred16
                ADD     BaseIn,BaseIn,#1                        ;Base = Base + 1 , colonne suivante
                ADD     BaseOut,BaseOut,#1                      ;Base = Base + 1 , colonne suivante

                B       boucle_vred16_col
fin_vred16_col

                LDR     Tmp1 ,= Savelr                          ;Restaure lr
                LDR     lr,[Tmp1]

                LDMFD   sp!, {r0-r12,r15} ; RICK 2004/01/29 removed '^'

                ;--------------------------
                ; vexp16
                ;--------------------------
start_vexp16
                MOV     BaseOut,Output                          ;BaseOut = Output
                MOV     BaseIn,Input                            ;BaseIn = Input
                ADD     BaseOutSup,BaseOut,OutLineLength        ;BaseOutSup = BaseOut + OutLineLength
boucle_vexp16_col
                CMP     BaseOut,BaseOutSup                      ;While ( BaseOut < BaseOutSup )
                BGE     fin_vexp16_col

                MOV     Reste,Div                               ;Reste = Div
                MOV     Virt,Num                                ;Virt = Num
                MOV     Pixel,#0                                ;Pixel = 0

                MOV     Output,BaseOut                          ;Output = BaseOut
                MOV     Input,BaseIn                            ;Input = BaseIn

                MLA     BorneSup,OutLineLength,Num,Output       ;BorneSup = Num * OutLineLength + Output

boucle_vexp16
                CMP     Output,BorneSup                         ;While Ouput < BorneSup
                BGE     fin_vexp16

                CMP     Virt,Div                                ;if ( Virt < = Div )
                BGT     else_vexp16

                LDRB    Tmp1,[Input],OutLineLength              ;Tmp1 = * Input , Input += OutLineLength
                MLA     Pixel,Tmp1,Virt,Pixel                   ;Pixel = Tmp1 * Virt + Pixel
                SUB     Reste,Div,Virt                          ;Reste = Div - Virt
                MOV     Virt,Num                                ;Virt = Num
                B       boucle_vexp16
else_vexp16
                LDRB    Tmp1,[Input]                            ;Tmp1 = * Input
                MLA     Pixel,Tmp1,Reste,Pixel                  ;Pixel = Tmp1 * Reste + Pixel
                MOV     Tmp1,Pixel,ASR#4                        ;Tmp1 = Pixel / Div , Div preserve only
                STRB    Tmp1,[Output],OutLineLength             ;* Output = Tmp1 , Output += OutLineLength
                MOV     Pixel,#0                                ;Pixel = 0
                SUB     Virt,Virt,Reste                         ;Virt = Virt - Reste
                MOV     Reste,Div                               ;Reste = Div
                B       boucle_vexp16
fin_vexp16
                ADD     BaseIn,BaseIn,#1                        ;Base = Base + 1 , colonne suivante
                ADD     BaseOut,BaseOut,#1                      ;Base = Base + 1 , colonne suivante

                B       boucle_vexp16_col
fin_vexp16_col

                LDR     Tmp1 ,= Savelr                          ;Restaure lr
                LDR     lr,[Tmp1]

                LDMFD   sp!, {r0-r12,r15} ; RICK 2004/01/29 removed '^'

                AREA    |C$$data|

Savelr          DCD     0

                END
