A
A
Alertoso2021-04-29 23:22:39
assembler
Alertoso, 2021-04-29 23:22:39

Can you please comment on the code?

Can you please help me figure out how to draw a circle?

;-----------------------------Рисуем вертикальные линии-------------------------------------

proc drawHorLine uses es di cx ax,\
                  x1, x2, y, color

        mov     ax, $A000
        mov     es, ax

        mov     al, byte[y]
        mov     cx, 320
        mul     cx
        mov     di, ax
        add     di, [x1]
        mov     cx, [x2]
        sub     cx, [x1]

        mov     al, byte[color]
        rep     stosb

        ret
endp

;-------------------------------------------------------------------------------------------

;----------------------------Рисуем окружность-----------------------------------------------

proc drawCircleSim uses bx si di ax,\
               x,y,xc,yc,color, mode

        mov     ax, [x]
        add     ax, [xc]
        mov     bx, [y]
        add     bx, [yc]

        stdcall putpixel, ax, bx,[color]
        cmp     [mode], Mode_NoBorder
        je      @F
        mov     dx, [xc]
        sub     dx, [x]
        push    ax
        push    dx
        push    bx
        stdcall drawHorLine, dx, ax, bx, [color]
        pop     bx
        pop     dx
        pop     ax
        add     ax, 2
        dec     dx
        dec     bx
        stdcall drawHorLine, dx, ax, bx, [color]
@@:
        mov     ax, [x]
        add     ax, [xc]
        mov     bx, [yc]
        sub     bx, [y]
        stdcall putpixel, ax,bx,[color]
        cmp     [mode], Mode_NoBorder
        je      @F
        mov     dx, [xc]
        sub     dx, [x]
        push    ax
        push    dx
        push    bx
        stdcall drawHorLine, dx, ax, bx, [color]
        pop     bx
        pop     dx
        pop     ax
        add     ax, 2
        dec     dx
        add     bx, 1
        stdcall drawHorLine, dx, ax, bx, [color]
 @@:
        mov     ax, [xc]
        sub     ax, [x]
        mov     bx, [yc]
        sub     bx, [y]

        stdcall putpixel, ax,bx,[color]

        mov     ax, [xc]
        sub     ax, [x]
        mov     bx, [y]
        add     bx, [yc]

        stdcall putpixel, ax,bx,[color]


        mov     ax, [y]
        add     ax, [xc]
        mov     bx, [x]
        add     bx, [yc]

        stdcall putpixel, ax,bx,[color]

        cmp     [mode], Mode_NoBorder
        je      @F
        mov     dx, [xc]
        sub     dx, [x]
        stdcall drawHorLine, dx, ax, bx, [color]
@@:
        mov     ax, [y]
        add     ax, [xc]
        mov     bx, [yc]
        sub     bx, [x]


        stdcall putpixel, ax,bx,[color]

        cmp     [mode], Mode_NoBorder
        je      @F
        mov     dx, [xc]
        sub     dx, [x]
        stdcall drawHorLine, dx, ax, bx, [color]
@@:
        mov     ax, [xc]
        sub     ax, [y]
        mov     bx, [yc]
        sub     bx, [x]

        stdcall putpixel, ax,bx,[color]

        cmp     [mode], Mode_NoBorder
        je      @F

        mov     dx, [xc]
        sub     dx, [x]
        stdcall drawHorLine, ax, dx, bx, [color]
@@:
        mov     ax, [xc]
        sub     ax, [y]
        mov     bx, [x]
        add     bx, [yc]

        stdcall putpixel, ax,bx,[color]

        cmp     [mode], Mode_NoBorder
        je      @F
        mov     dx, [xc]
        sub     dx, [x]
        stdcall drawHorLine, ax, dx, bx, [color]
@@:
        ret
endp

;-------------------------------------------------------------------------------------------

;-------------------------Рисуем круг-------------------------------------------------------

proc drawCircle uses es si ax cx bx dx,\
                 xc, yc, r, color, mode

        mov     ax, [y]
        add     ax, [y]
        mov     dx, 3
        sub     dx, ax ; d = dx
        mov     [d], dx
        mov     [x], 0
        mov     si, [r]
        mov     [y], si

.While:
        stdcall drawCircleSim, [x], [y], [xc], [yc], [color], [mode]
        mov     dx, [d]
        cmp     dx, 0  ;if d<0
        js      .Minus

        mov     ax, [x]  ; else begin
        sub     ax, [y]  ;d:=d+4*(x-y)+10;
        mov     cx, ax
        add     ax, cx
        add     ax, cx
        add     ax, cx

        add     ax, 10
        add     [d], ax
        dec     [y]
        jmp     .Skip
.Minus:            ;then d:=d+4*x+6
        mov     ax, [x]
        add     ax, [x]
        add     ax, [x]
        add     ax, [x]

        add     ax, 6

        add     [d], ax

.Skip:

        inc     [x]
        mov     ax, [y]
        cmp     [x],ax

        js      .While

        ret
endp

;-------------------------------------------------------------------------------------------

;--------------------------Рисуем попиксельно-----------------------------------------------

proc putpixel uses es di bx ax cx,\
                        x,y, color

        mov     ax, $A000
        mov     es, ax

        mov     al, byte[y]
        mov     cx, 320
        mul     cx
        mov     di, ax
        add     di, [x]

        mov     al, byte[color]
        mov     [es:di], al

        ret
endp

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
AK, 2021-05-01
@andk

What exactly do you want to understand?
In the text above, there are 4 subroutines for low-level drawing.
"drawHorLine" draws a horizontal line of length x1 to x2, second coordinate y, color color.
"putpixel" outputs a single pixel at x,y coordinates and color
"drawCircleSim" draws a circle using the two previous subroutines
"drawCircle" draws a circle? using the three previous subroutines
Roughly like this.
The dimension of the parameters and the hardware under which it all works is not clear from the code.
Offhand, something from a series of old CGA-EGA with a resolution of 320x240. I can be wrong.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question