Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ASM Macro Question...
#1
I was trying to make a Flattriangle routine but Im having errors regarding macros.

1. How do I use macros with parameters?
2. Why can't macros use @@ and @ in labels?
3. any Macro tutorial for TASM you know?

I'm using TASM.

Thanks!!!


Here's the unassemblable code:

Code:
.Model Medium, BASIC
.386
.Code

align 2

Public  RelTriF


Hline  Macro  x1: word, y: word, x2: word , clr: byte

            Local  @PostSwapX, @PostclipLeft, @PostclipRight, @swapx, @clipLeft, @clipRight, @exit

            push ax
            push bx
            push cx
            push dx
            mov cx, y
            cmp cx, 199
            jg @exit
            cmp cx, 0
            jl @exit
            ;; calc offset
            xchg ch, cl
            mov di, cx
            shr di, 2
            add di,cx           ;di=320*y1

            ;;
            ;;

            mov ax, x1
            mov bx, x2
            cmp ax, bx
            jg @swapx
    @PostSwapX:
            cmp ax, 319
            jg @exit
            cmp ax, 0
            jl @clipLeft
    @PostclipLeft:
            cmp bx, 0
            jl @exit
            cmp bx, 319
            jg @clipRight
    @PostclipRight:
            sub bx,ax
            inc bx              ;bx=width,ax=X1

            ;;;
            ;;;
            add di,ax           ;di=320*y+x

            ;;ax=free
            ;;bx=width
            ;;cx=free

            ;store color
            mov ax, clr
            mov ah, al
            mov cx, ax
            shl eax, 16
            mov ax,cx           ;eax=color(all the bytes)

            mov cx, bx
            shr cx,2            ;w\4
            and bx,3            ;remainder
            ;;
            ;;
            ;;;;mov es, Layer

            rep stosd
            mov cx, bx
            rep stosb

            Jmp Hexit
;;;;;;Subs
;;;;;;
@swapx:
    xchg ax, bx
    Jmp @PostSwapX

@clipLeft:
    mov cx, bx
    sub cx,ax
    add ax, cx
    cmp ax, 0
    jl @exit
    xor ax,ax
    Jmp @PostclipLeft

@clipRight:
    mov bx, 319
    Jmp @PostclipRight

@exit:

            Pop dx
            pop cx
            pop bx
            pop ax
    EndM

;***************************************************************************
    

RelTriF     Proc  Uses es di,\
            Layer:word, x1:word, y1:word, x2:word, y2:word, x3:word, y3:word, clr:word

            Local tx1           : word
            Local ty1           : word
            Local tx2           : word
            Local ty2           : word
            Local tx3           : word
            Local ty3           : word
            Local d1            : dword
            Local d2            : dword
            Local d3            : dword
            Local Hei           : word

            Mov d1, 0
            Mov d2, 0
            Mov d3, 0
mov ax, y1
mov bx, y2
mov cx, x1
mov dx, x2

    cmp ax, bx
    jle @NoSwap1
    xchg ax, bx
    xchg cx, dx
@Noswap1:
    mov ty1, ax
    mov ty2, bx
    mov tx1, cx
    mov tx2, dx

                            ;ax=y1  , bx= y2 , cx= x1 , dx = x2
mov bx, y3
mov dx, x3

cmp ax, bx
jle @Noswap2
xchg ax, bx
xchg cx, dx
@Noswap2:
    mov ty1, ax
    mov ty3, bx
    mov tx1, cx
    mov tx3, dx

                            ;ax=y1  , bx= y3 , cx= x1 , dx = x3
mov ax, ty2
mov cx, tx2

cmp ax, bx
jle @NoSwap3
xchg ax, bx
xchg cx, dx
@Noswap3:
    mov ty2, ax
    mov ty3, bx
    mov tx2, cx
    mov tx3, dx


mov ax, ty2
sub ax, ty1
cwde                  ;eax = ydiffa
mov ebx, eax

or ebx,ebx
jz @NoDiv1
    mov ax, tx2
    sub ax, tx1
    cwde
    xor edx, edx
    sal eax, 16
    idev ebx
    mov d1, eax
@NoDiv1:
                                          
                                      


mov ax, ty3
sub ax, ty2
cwde
mov ebx, eax
or ebx, ebx
jz @NoDiv2
    mov ax, tx3
    sub ax, tx2
    cwde
    xor edx, edx
    sal eax, 16
    idiv ebx
    mov d2, eax
@NoDiv2:



mov ax, ty3
sub ax, ty1
cwde
mov ebx, eax
or ebx, ebx
jz @NoDiv3
    mov ax, tx3
    sub ax, tx1
    cwde
    xor edx, edx
    sal ax, 16
    idiv ebx
    mov d3, eax
@NoDiv3:



xor eax, eax
mov ax, tx1
sal eax, 16
mov ebx, eax

mov es, Layer

mov dx, ty1
mov hei, dx
@yloop1:
    mov ecx, eax
    sar ecx, 16
    mov edx, ebx
    sar edx, 16
    Hline cx, hei, dx, clr
    add eax, d1
    add ebx, d2
    mov cx, ty3
    inc hei
    cmp hei, cx
  jl @yloop1



mov ax, tx2
sal eax, 16

mov dx, ty2
mov hei, dx
@yloop2:
    mov ecx, eax
    sar ecx, 16
    mov edx, ebx
    sar edx, 16
    Hline cx, hei, dx, clr
    
    add eax, d2
    add ebx, d3
    mov cx, ty3
    inc hei
    cmp hei, cx
    jl @yloop2

endp

END
y smiley is 24 bit.
[Image: anya2.jpg]

Genso's Junkyard:
http://rel.betterwebber.com/
Reply
#2
Hey rel. don't you think it's unessary to replicate the color to 32 bits in the outerloop? And forget macros for the scanline filler, a near call won't be noticable even on a 286. Also, why calculate the dst addres each time? Just calc it outside the loops and add 320 to it add the end of the outerloop. Plus a bunch of other things, blah blah

Don't be afraid to use heavy instructions outside the loops. Like mul which is only 3 clocks on p6 and later by the way. 98% of the time is spent in the innerloop, saving 50 clocks outside the loops out of 50,000 for the whole routine won't help anyone.
oship me and i will give you lots of guurrls and beeea
Reply
#3
Heres an example file with macro's in it that comes with TASM found in the EXAMPLES folder.

http://www.hybd.net/~mms/Temp/IMACROS.MAC

maybe that'l help. not sure.
use nasm anyway, macro's own in nasm. so piss easy. documents are great. compiles to dos, win, linux. works with gcc, qb, and probably more. woot.
Reply
#4
Yo blitz!!! thanks!!!!

Nex: Good doc!!! I'll try to see more of NASM. :*)
y smiley is 24 bit.
[Image: anya2.jpg]

Genso's Junkyard:
http://rel.betterwebber.com/
Reply
#5
Btw, here's the masm reference http://badlogic.bad-logic.com/files/masm.zip and http://webster.cs.ucr.edu/Page_TechDocs/MASMDoc/

But take my advice, it's good advice Smile
oship me and i will give you lots of guurrls and beeea
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)