Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Drawing Lines :O

jjj999jjj999 Member Posts: 4
According to some paper i read the following code will draw a red horizontal line:MAIN SEGMENT
ASSUME CS:MAIN,ES:MAIN,DS:MAIN,SS:MAIN

ORG 100h

START:
MOV AH,00h ;get into video mode. 00 = Set Video Mode
MOV AL,13h ;13h = 320x240x16
INT 10h

SET_VSEGMENT: ;set up video segment
MOV AX,0A000h ;point ES to VGA segment
MOV ES,AX

VALUES: ;various values used for plotting later on
MOV AX,100 ;X location
MOV BX,100 ;Y location
MOV CX,120 ;length of line. used for REP

GET_OFFSET: ;get offset of pixel location using X,Y
MOV DI,AX ;put X location into DI
MOV DX,BX ;and Y into DX
SHL BX,8 ;Y * 2^8. same as saying Y * 256
SHL DX,6 ;Y * 2^8. same as sayinh Y * 64
ADD DX,BX ;add the two together
ADD DI,BX ;and add the X location
;this whole thing gives us the offset location of the pixel

MOV AL,4 ;set color attributes
REP STOSB ;and store 100 bytes, decrementing CX and
;incrementing DI

XOR AX,AX ;wait for keypress
INT 16h

MOV AX,0003h ;switch to text mode
INT 10h

INT 20h ;and exit

END START
MAIN ENDS

My question is
1) why does he put the REP STOSB for?
2) How can i Draw a Vertical line?

thnx


Comments

  • angelusMortisangelusMortis Member Posts: 141
    : My question is
    : 1) why does he put the REP STOSB for?
    : 2) How can i Draw a Vertical line?
    :
    : thnx


    STOSB is the same as :

    mov es:[di],al
    inc di

    REP repeats these instructions as often as the value
    in CX tells. in this case 120 times.

    u can draw vertical lines if u increase DI by 320,
    because the width of the display in mode 13h is 320
    pixels wide. thus the next vertical pixel will be
    320 pixels further.

    mov ax,13h
    int 10h
    mov ax,0a000h
    mov es,ax
    mov di,160
    mov cx,200
    mov al,15
    lp:
    mov es:[di],al
    add di,320
    loop lp

    this should draw a vertical line through the middle of
    the screen. i haven't tried it :)




  • DariusDarius Member Posts: 1,666
    : MOV AL,13h ;13h = 320x240x16

    mode 13h is not 320x240x16, it is 320x200x256

  • AsmGuru62AsmGuru62 Member Posts: 6,519
    : : MOV AL,13h ;13h = 320x240x16
    :
    : mode 13h is not 320x240x16, it is 320x200x256
    :

    There is also CLD missing, sometimes the direction flag is 1, so DI will decrement instead of increment:

    CLD
    REP STOSB


  • angelusMortisangelusMortis Member Posts: 141
    i have never seen my direction flag being set before :)

Sign In or Register to comment.