Shop Learn
MULPIX D,{#}S Syntax question — Parallax Forums

MULPIX D,{#}S Syntax question

if D=d4d3d2d1 and S =s3s2s1s0 then Multipy DxS by should be d3=d3s3 d2=d2s2 d1=d1s1 d0=d0s0
but that doeesn' happen and the nomenclature $FF = 1.0 and $00= 0.0 I am not sure what that means

the ADDPIx d3= d3+s3 d2=d2+s2 d1= d1+s1 d0 = d0+s0 works so not sure what MULPIX is doing

Regards
Bob (WRD)

Comments

  • AJLAJL Posts: 427

    What result are you expecting, and what are you seeing?

    From the instruction description, with $FF = 1.0 and $00 = 0.0 then with D of $0080FFFF and S of $008080FF I would expect a result of something like $004080FF.

    That’s:
    $00 x $00 = 0.0 x 0.0 = 0.0 = $00
    $80 x $80 = 0.5 x 0.5 = 0.25 = $40
    $80 x $FF = 0,5 x 1.0 = 0.5 = $80
    $FF x $FF = 1.0 x 1.0 = 1.0 = $FF

    I’m not in a position to test my interpretation.

  • AJL
    Will test.
    Thanks
    Bob (WRD)

  • AribaAriba Posts: 2,504

    It's multiplying with scaling, maybe SCLPIX, or SCAPIX would have been a better name.
    So if D=d3d2d1d0 and S=s3s2s1s0 the result should be:

      d3 = d3*s3/255
      d2 = d2*s2/255
      d1 = d1*s1/255
      d0 = d0*s0/255
    

    Andy

  • AJL
    Tested and you are correct. Thanks
    Ariba
    I will modify notes about scaling and rounding to bit
    Regards
    Bob (WRD)

  • AJLAJL Posts: 427

    Glad to be of assistance :-)

  • JonnyMacJonnyMac Posts: 7,708
    edited 2021-09-09 16:38

    I didn't know about mulpix, and I'm glad you pointed it out. I had this routine in my pixel driver which is a direct port from the P1.

    pub colorx(r, g, b, w, level) : result | m
    
    '' Packs r-g-b-w bytes into long
    '' -- r, g, b, and w are element levels, 0..255
    '' -- level is brightness, 0..255 (0..100%)
    
      if (level <= 0)
        result := $00_00_00_00
    
      elseif (level >= 255)
        result := color(r, g, b, w)
    
      else
        r := r * level / 255                                        ' apply level to rgbw
        g := g * level / 255
        b := b * level / 255
        w := w * level / 255
        result := color(r, g, b, w)
    

    I upgraded the method in my P2 object to this, and save a little more than 9 microseconds at 200MHz.

    pub p2_colorx(r, g, b, w, level) : result 
    
    '' Packs r-g-b-w bytes into long
    '' -- r, g, b, and w are element levels, 0..255
    '' -- level is brightness, 0..255 (0..100%)
    
      org
                    cmps      level, #0                     wcz     ' at or below 0?
        if_be       jmp       #.done                                '  yes, done
    
                    setbyte   result, r, #3                         ' make 32-bit color
                    setbyte   result, g, #2
                    setbyte   result, b, #1
                    setbyte   result, w, #0
    
                    cmps      level, #255                   wcz     ' at or above 255?
        if_ae       jmp       #.done                                '  yes, done
    
                    rep       #1, #3                                ' make multiplier
                     rolbyte  level, level, #0
    
                    mulpix    result, level                         ' scale the color
    
    .done
      end
    
  • Wuerfel_21Wuerfel_21 Posts: 1,871
    edited 2021-09-09 16:50
                    rep       #1, #3                                ' make multiplier
                     rolbyte  level, level, #0
    

    You can do this to the same effect:

                     movbyts level, #%%0000
    

    Or, alternatively, instead of

                     movbyts level, #%%0000
                     mulpix result,level
    

    you can use

                     setpiv level
                     blnpix result,#0
    
  • JonnyMacJonnyMac Posts: 7,708

    Thank you!

Sign In or Register to comment.