Little hline routine

Before I start, a little background info so you don't treat me as a run-of-the-mill newbie..


I'm comfortable with MIPS asm, and since all asm rely on the same foundations, I already know a fair bit of x86 asm before I even started.. so, please don't tell me "ax is a 16bit register! mov moves op1 to op2!" or something.. what I need help with is simply the syntax and register usage conventions of x86, which is what I'm having a little trouble with (MIPs asm in contrast seems almost angelic)


Here is a hline function as I came up with, but it does not work as expected...


void GFX_HLine (int x1, int x2, int y, char color)

{

/***

long offset = y*SCR_X;


memset(&vscr[offset+x1], color, x2-x1);

***/


asm {

mov ax, seg vscr // point es:di to vscr

mov es, ax

mov di, offset vscr


mov ax, y // calculate offset

shl ax, 6

mov bx, ax

shl ax, 2

add ax, bx

add ax, x1 // done calculating offset

add di, ax // add the offset to di


mov cx, x2 // get width

sub cx, x1

inc cx // add 1 to get real width (101-100 = 2 pixels)


mov ah, color

mov al, color


mov bx, cx

shr cx, 1 // use words instead of bytes

rep stosw


and bx, 1 // LSB set?

cmp bx, 1

jne done


isodd:

stosb // copy last odd byte


done:

}

}


FooFighter


Comments

  • Damn, it doesn't preserve formatting. oh well, hope it doesn't look so horrible.


  • Hey, maybe i can help, but before i do... you said mov moves op1 to op2, actually it moves op2 to op1, anyways... HAH HAH... sorry... ;)

    All my added lines will be started with a asterick(*)

    : Before I start, a little background info so you don't treat me as a run-of-the-mill newbie..


    : I'm comfortable with MIPS asm, and since all asm rely on the same foundations, I already know a fair bit of x86 asm before I even started.. so, please don't tell me "ax is a 16bit register! mov moves op1 to op2!" or something.. what I need help with is simply the syntax and register usage conventions of x86, which is what I'm having a little trouble with (MIPs asm in contrast seems almost angelic)


    : Here is a hline function as I came up with, but it does not work as expected...

    *First of all, make sure x2 is always more than x1

    *The added lines could be muchly optimized assuming that the virt screen is allocated on a word boundary, but we won't go into that

    : void GFX_HLine (int x1, int x2, int y, char color)

    : {

    : /***

    : long offset = y*SCR_X;


    : memset(&vscr[offset+x1], color, x2-x1);

    : ***/


    asm{

    mov ax, seg vscr

    mov es, ax

    mov di, offset vscr


    mov ax, y

    shl ax, 6

    mov bx, ax

    shl ax, 2

    add ax, bx

    mov bx, ax

    add bx, x2

    add bx, di //es:bx now points to x2's offset

    add ax, x1

    add di, ax //es:di now points to x1's offset


    mov ah, color

    mov al, ah

    test di, 1 // tests the last bit

    jz skip_first_odd_byte_blit

    stosb

    skip_first_odd_byte_blit:

    test bx, 1 // tests the last bit, this one

    //should be 1 if its on a word

    // boundary because

    //the last part of a word is on a

    //offset not

    //divisible by 2.... geez... can't

    //think of how

    //to explain...

    JUST LIVE WITH IT!

    jnz skip_last_byte_blit

    mov es:[bx], al

    dec bx // bx must be decremented to make it

    //on a word boundary

    skip_last_byte_blit:

    inc bx

    sub bx, di

    mov cx, bx

    shr cx, 1

    rep stosw

    }

    }

    I think that should be it, i finally got so sick of asterick stuff i just rewrote it all, if that doesn't work... send me what it does to nilesferrier@hotmail.com and i'll fix it, i probably made some stupid error since i didn't test that up there!






Sign In or Register to comment.

Howdy, Stranger!

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

Categories