;/**************************************************************************** ;** MODULE: avidpoly.asm ;** AUTHOR: Sami Tammilehto / Fennosoftec OY ;** DOCUMENT: ? ;** VERSION: 1.0 ;** REFERENCE: - ;** REVISED BY: - ;***************************************************************************** ;** ;** Assembler / Video (polygon drawing) ;** ;****************************************************************************/ ;borders - can be found in asm.asm at the tmp work area (size 8K = 1024 rows) ALIGN 4 polysides dw 0 ;polygon sides polyxy dw MAXPOLYSIDES dup(0,0) ;x1,y1,x2,y2,... polycolor db 1 ALIGN 4 leftside db 1111b,1110b,1100b,1000b rightside db 0001b,0011b,0111b,1111b middledot db 0001b,0010b,0100b,1000b poly PROC NEAR ;NOTE Changes about all! push ds call vidstart mov ax,cs:polysides cmp ax,3 jb polret call polyf polret: pop ds ret poly ENDP ;*** POLYF / POLYFT ALIGN 4 feax dd 0 fedx dd 0 fleftaddl dd 0 ;+0 fleftaddh dw 0 ;+4 fleftrown dw 0 ;+6 fleftzb dd 0 ;+8 fleftze dd 0 ;+12 flefttx0 dw 0 ;+16 fleftty0 dw 0 ;+18 flefttxa dw 0 ;+20 flefttya dw 0 ;+22 fleftcnt dw 0 ;+24 fleftcnta dw 0 ;+26 fleftd3a dw 0 ;+28 frightaddl dd 0 ;+0 frightaddh dw 0 ;+4 frightrown dw 0 ;+6 frightzb dd 0 ;+8 frightze dd 0 ;+12 frighttx0 dw 0 ;+16 frightty0 dw 0 ;+18 frighttxa dw 0 ;+20 frighttya dw 0 ;+22 frightcnt dw 0 ;+24 frightcnta dw 0 ;+26 frightd3a dw 0 ;+28 finfolen dw 0 finfo0 dw 0 finfo1 dw 0 fwmaxy1 dw 0 finfo dw 32 dup(0,0,0,0,0,0,0,0) ;x,y,zlo,zhi,tx,ty,0,0 polyf PROC NEAR ;ONLY CONVEX POLYGONS - FAST? ;input: polysides/polyxy ;requirements: vidstart ;cpolysides>=3 (not checked) ;**COPY/SEEK UPPERMOST** mov ax,ds mov gs,ax mov ax,cs mov ds,ax mov cx,ds:polysides mov ax,cx shl ax,4 ;*16 mov ds:finfolen,ax add ax,OFFSET finfo mov ds:finfo1,ax mov ax,word ptr gs:_projclipy[CLIPMAX] inc ax mov ds:fwmaxy1,ax mov edx,077770000h xor bx,bx mov si,OFFSET polyxy mov di,OFFSET finfo mov ds:finfo0,di pfn1: mov eax,dword ptr ds:[si] cmp eax,edx jg pfn2 mov edx,eax mov bx,di pfn2: mov dword ptr ds:[di],eax add si,4 add di,16 loop pfn1 ;[bx]=uppermost ;**SETUP REGS** mov ds:fleftrown,-32767 mov ds:frightrown,-32767 mov si,bx mov di,bx mov bp,ds:[si+2] mov bx,OFFSET _borders mov ax,bp cmp ax,word ptr gs:_projclipy[CLIPMIN] jge pfn35 mov ax,word ptr gs:_projclipy[CLIPMIN] pfn35: mov gs:[bx],ax add bx,2 mov cx,16 ;max tmp count to avoid hanging on illegal polygons ;eax=left ;bx=pointer to borders[] ;cx=count ;edx=right ;si=left ;di=right ;bp=y pfn63: push cx push bx cmp bp,ds:fleftrown jl pfn42 push edx push di mov di,si sub di,16 cmp di,ds:finfo0 jae pfn41 add di,ds:finfolen pfn41: mov bx,OFFSET fleftaddl call polyfcalc add cx,bp mov ds:fleftrown,cx movzx eax,word ptr ds:[si+0] mov ebx,ds:fleftaddl mov dx,ds:fleftaddh sar dx,1 rcr ebx,1 xor bx,bx sub eax,ebx sbb ax,dx mov si,di pop di pop edx pfn42: cmp bp,ds:frightrown jl pfn52 push eax push si mov si,di add di,16 cmp di,ds:finfo1 jb pfn51 sub di,ds:finfolen pfn51: mov bx,OFFSET frightaddl call polyfcalc add cx,bp mov ds:frightrown,cx movzx edx,word ptr ds:[si+0] mov ebx,ds:frightaddl mov ax,ds:frightaddh sar ax,1 rcr ebx,1 xor bx,bx sub edx,ebx sbb dx,ax pop si pop eax pfn52: mov bx,ds:fleftrown mov cx,ds:frightrown cmp cx,bx jl pfn61 mov cx,bx pfn61: sub cx,bp pop bx cmp cx,0 jg pfn71 pfn6: pop cx cmp bp,ds:fwmaxy1 jg pfn64 cmp si,di je pfn64 dec cx jz pfn64 jmp pfn63 pfn64: mov word ptr gs:[bx],-32767 mov si,OFFSET _borders LOADDS call doborders ret pfn65: ;above screen ;entering screen, cut. add bp,cx push bp push cx cmp bp,word ptr gs:_projclipy[CLIPMIN] jl pfn66 sub bp,cx mov cx,word ptr gs:_projclipy[CLIPMIN] sub cx,bp pfn66: ; movsx ecx,cx ror eax,16 mov ds:feax,eax ror edx,16 mov ds:fedx,edx ; mov ax,ds:fleftaddh shl eax,16 mov ax,word ptr ds:fleftaddl[2] imul ecx add ds:feax,eax ; mov ax,ds:frightaddh shl eax,16 mov ax,word ptr ds:frightaddl[2] imul ecx add ds:fedx,eax ; mov eax,ds:feax ror eax,16 mov edx,ds:fedx ror edx,16 mov bp,cx pop cx sub cx,bp pop bp cmp cx,0 jne pfn6b jmp pfn6 pfn6b: mov bp,word ptr gs:_projclipy[CLIPMIN] pfn71: ;process segment cmp bp,word ptr gs:_projclipy[CLIPMIN] jl pfn65 ;above screen still add bp,cx ;clip max to maxy cmp bp,ds:fwmaxy1 jle pfn72 sub bp,cx mov cx,ds:fwmaxy1 sub cx,bp mov bp,ds:fwmaxy1 pfn72: cmp cx,0 jle pfn6 push si push di push bp ror ebx,16 neg cx mov bx,cx ror ebx,16 mov esi,ds:fleftaddl mov edi,ds:frightaddl mov bp,ds:fleftaddh mov cx,ds:frightaddh pfn7: add eax,esi adc ax,bp add edx,edi adc dx,cx mov gs:[bx],ax mov gs:[bx+2],dx add ebx,10004h jnc pfn7 pop bp pop di pop si jmp pfn6 polyfcalc: ;**** subroutine **** ;calc slope for line [SI]->[DI] to [BX], returns CX=len mov cx,ds:[di+2] sub cx,bp ;ds:[si+2] jle pfc1 mov ax,ds:[di+0] sub ax,ds:[si+0] jl pfc2 xor dx,dx div cx mov ds:[bx+4],ax xor ax,ax div cx mov ds:[bx+2],ax ;dec cx ret pfc1: xor cx,cx ret pfc2: neg ax xor dx,dx div cx push ax xor ax,ax div cx pop dx neg ax adc dx,0 neg dx mov ds:[bx+4],dx mov ds:[bx+2],ax ;dec cx ret polyf ENDP doborders PROC NEAR push bp mov bx,ds:[si] add si,2 dec bx push bx hlg92: pop bx inc bx push bx mov ax,ds:[si] add si,2 cmp ax,-32767 jne hlg91 pop bx pop bp ret hlg91: mov dx,ax mov ax,ds:[si] add si,2 cmp ax,dx jl hlg1 xchg ax,dx hlg1: cmp ax,word ptr ds:_projclipx[CLIPMIN] jnl hlg2 cmp dx,word ptr ds:_projclipx[CLIPMIN] jl hlg0 mov ax,word ptr ds:_projclipx[CLIPMIN] hlg2: cmp dx,word ptr ds:_projclipx[CLIPMAX] jng hlg21 cmp ax,word ptr ds:_projclipx[CLIPMAX] jg hlg0 mov dx,word ptr ds:_projclipx[CLIPMAX] hlg21: mov di,ax sar di,2 mov cx,dx sar cx,2 sub cx,di shl bx,1 add di,ds:_rows[bx] mov bp,3 and bp,ax mov bh,cs:leftside[bp] mov bp,3 and bp,dx mov bl,cs:rightside[bp] mov dx,3c5h ;(di..si,bx) cmp cx,0 je hlg30 ;left side mov al,bh out dx,al mov al,cs:polycolor stosb dec cx mov ah,al ;middle jcxz hlg33 mov al,0fh out dx,al cmp cx,8 jae @@long mov al,ah shr cx,1 rep stosw adc cx,cx rep stosb jmp hlg33 @@long: mov al,ah mov bp,ax shl eax,16 mov ax,bp ;align test di,3 jz hlg32 stosb dec cx test di,3 jz hlg32 stosb dec cx test di,3 jz hlg32 stosb dec cx hlg32: mov bp,cx shr cx,2 rep stosd ;fill mov cx,3 and cx,bp rep stosb ;fill rest hlg33: ;right side mov al,bl out dx,al mov al,ah mov es:[di],al hlg0: jmp hlg92 hlg30: ;end and beg in same byte mov al,bl and al,bh out dx,al mov al,cs:polycolor mov es:[di],al jmp hlg92 doborders ENDP