Author Topic: Dotted Line... and the .while thing  (Read 58 times)

HSE

  • Member
  • *****
  • Posts: 1130
  • <AMD>< 7-32>
Dotted Line... and the .while thing
« on: November 09, 2019, 06:03:00 AM »
Hi!

I found an algorithm for a dotted line. And I thought the problem was solved, but not.

The author write loops:
Code: [Select]
.while (x != x2) but that work if you are lucky, other way you have an infinite loop.
The correct code is:
Code: [Select]
.while (abs(x-x2)>2)
Here a code extended to other point separations (using ObjAsm for 32 and 64) tested in 32 bit:
Code: [Select]
if TARGET_BITNESS EQ 32
sxword textequ <sdword>
else
sxword textequ <sqword>
endif
Method Pixelmap2.DottedLine, uses xsi, x1:sxword,y1:sxword,x2:sxword,y2:sxword, espaciado:xword, dColor:xword
    local x:sxword,y:sxword,dxx:sxword,dyy:sxword,i:sxword,e:sxword
local xinc:sxword,yinc:sxword
SetObject xsi
    mov xax, x2
    sub xax, x1
    mov dxx, xax
    mov xax, y2
    sub xax, y1
    mov dyy, xax
    mov xax, x1
    .if (xax < x2)
        mov xinc , 1
    .else
        mov xinc , -1
    .endif
    mov xax, y1   
    .if (xax < y2)
        mov yinc, 1
    .else
        mov yinc, -1
    .endif
  ; Macros ------------------------------------------
salta macro var
            mov xax , &var&inc
            mov xcx , espaciado
            imul xcx
            add xax , &var
            mov &var , xax
        endm
proceso_dot macro v1, v2
    mov xax, d&v2&&v2
    mov xcx, espaciado
    imul xcx
    sub xax, d&v1&&v1
    mov e, xax
        ;.while (eax != x2)
        .while (xax > espaciado)
            .if ( e < 0)
    mov xax, d&v2&&v2
    mov xcx, espaciado
    imul xcx
                add xax, e
                mov e, xax
            .else
            mov xax, d&v2&&v2
            sub xax, d&v1&&v1
    mov xcx, espaciado
    imul xcx
                add xax, e
                mov e, xax
                salta &v2
          .endif
          salta &v1
  OCall xsi.BlendPixel, x, y, dColor
  ; -----------------
  mov xax , &v1
  sub xax , &v1&2
  cdq
  xor xax , xdx
  sub xax , xdx
        .endw
endm

; Algorithm ------------------------------------------
    m2m x, x1;
    m2m y, y1;
    mov xax, dxx
    .if xax >= dyy
    proceso_dot x, y
    .else
    proceso_dot y, x
    .endif
MethodEnd

Look nice horizontal and vertical, but don't look well in angles.

I have to try other thing :eusa_boohoo:

Regards. HSE

jj2007

  • Member
  • *****
  • Posts: 9743
  • Assembler is fun ;-)
    • MasmBasic
Re: Dotted Line... and the .while thing
« Reply #1 on: November 09, 2019, 07:06:01 AM »
.while (abs(x-x2)>2)

Beware of macro expansion before the .while - check in the debugger

Use instead:
Code: [Select]
.While 1
  .Break .if abs(x-x2)<=2
  ...
.Endw

HSE

  • Member
  • *****
  • Posts: 1130
  • <AMD>< 7-32>
Re: Dotted Line... and the .while thing
« Reply #2 on: November 09, 2019, 07:22:50 AM »
Yesterday I forget that for a moment  :biggrin:

Now is:
Code: [Select]
.while (xax > espaciado)
  ; -----------------
  code here
                  ; ----------------- 
  mov xax , &v1       ; this is abs(x-x2)       
  sub xax , &v1&2
  cdq
  xor xax , xdx
  sub xax , xdx
        .endw