M EQU Byte Ptr 0[BX] TITLE 'DRAW - POLYLINE DRAWING ROUTINES' ; **************************************************************************** ; * * ; * DRAWIT : RASTER CONVERT A POLYLINE INTO THE PRINTER BITMAP BUFFER, * ; * CLIPPING EACH LINE SEGMENT BETWEEN THE CURRENT PLOT STRIP * ; * * ; **************************************************************************** ; * ; Revision : June 08, 1983 File "DRAW.A86" Version 1.0 * ; * ; * ;***** MODE NOTES : ********************************************************* ; * ; 1) BITMAP BUFFER EMPTY FLAG 11/3 * ; 2) SET EMPTY FLAG IN ADDRXY indicating Bitmap Used * ; 3) Rotate LINE STYLE pattern Mask : SPECIL to set bit * ; 4) New Pieces : Drawit, textit = Drawpl, Textit, Drawxy, Getadr * ; 5) Special Line Style Support : * ; .Drawit Stores Line Start Point X0, Y0 for Swapping * ; .Clipit Returns ABOVE flag : 0=inside, 1=Y2 above, 2=Y1 above * ; .Drawxy Swaps Line Endpoints : Line Direction Ymax to Ymin * ; Filters Y0 to TOPY and Sets Y0 inside flag for ADDRXY * ; and SETBIT Rontines to start Setting Bit in BITMAP * ; 6) Restore the Line Style Pattern After Rasterization * ; 7) delete Module LINETY, use rol specil,1 * ; * ;***** MODE NOTES : ********************************************************* ; * ; POLYLINE DRAWING ROUTINES * ; * ; Drawit (npt,x1,y1,x2,y2,...xnpt,ynpt,cindex) * ; * ; Function : For each line segment .. * ; Clip the endpoints of the line to the current plot strip and * ; Scan convert the line into raster pixel values mapped * ; into the bitmap buffer * ; * ; Get x1, y1 * ; do i = 1, npt * ; Get x2, y2 * ; Call Clipit * ; Call Drawxy * ; x1 = x2 * ; y1 = y2 * ; end; * ; * ; Input : NPT - No. of Vertices in the Ployline * ; XP - Array of X-coordinates * ; YP - Array of Y-coordinates * ; LSTPTR - Object List Buffer Pointer, where xp ans yp arrays * ; are stored * ; MPTY - Bitmap Buffer Set Indicator * ; * ; Output : Returns Pointer to the next entry in OBJLST in * ; * ; Calls : GETXY - Get the x,y coordinates of the next point in OBJLST * ; CLIPIT - Clip line to printer plot strip (ystart, yend) * ; DRAWXY - Raster convert vector to pixel values, maps pixel * ; to bitmap address and 'sets' the bit * ; * ; Raster Variables : * ; X0 - Line start point coord. * ; XN - Line end point coord. * ; Line Style Support Variables * ; ABOVE - Which Line EndPoint ABOVE Strip Flag * ; SPECIL - Special Line Style Bit Pattern for the Current NDLNTY * ; INSIDE - Line EndPoints INSIDE Strip Flag * ; * ;----------------------------------------------------------------------------* PUBLIC DRAWIT, SWAPY EXTRN GETXY:near, CLIPIT:near, DRAWXY:near EXTRN ABSHL:near, NEGHL:near, CMPDH:near, CMPS:near, SUBDH:near EXTRN MIDH:near, DIDH:near, IMOD:near dseg ;EXTRN BITMAP:word Extrn NBIT:byte, NBYT:word, MPTY:word EXTRN COLOR:byte, XMAX:word, YMAX:word EXTRN XW:word, TOPY:word, BOTY:word, BOTTY:word EXTRN LSTYLE:word, NDLNTY:byte, NDLNCO:byte EXTRN X:word, X1:word, Y:word, Y1:word, X2:word, Y2:word EXTRN DX1:word, DY:word, XDIR:word, YDIR:word EXTRN X0:word, Y0:word, XN:word, YN:word EXTRN doxy:byte, ABOVE:byte, INSIDE:word, SPECIL:word cseg ;----------------------------------------------------------------------------+ ; + ; CALL DRAWIT + ; = npt + ; = current OBJLST pointer : LSTPTR + ; RET + ; + ; Get x1, y1 + ; do i = 1, npt + ; Get x2, y2 + ; Call Clipit + ; Call Drawxy + ; x1 = x2 + ; y1 = y2 + ; end; + ;----------------------------------------------------------------------------+ DRAWIT: ;Stack = npt PUSH AX ; Set Current Color Index to PolyLine Color Index MOV AL,Byte Ptr NDLNCO MOV Byte Ptr COLOR,AL ; Get x1, y1 CALL GETXY ;Returns : = x, = y, MOV Word Ptr X0,DX MOV Word Ptr X1,DX MOV Word Ptr Y0,CX MOV Word Ptr Y1,CX ; (npt - 1) = 0 ? DRAL01: POP AX DEC AL ;npt = npt - 1 JZ DRAJ99 ;DONE PUSH AX ; ; Get x2, y2 ; CALL GETXY ;Returns = x, = y, MOV Word Ptr X2,DX MOV Word Ptr XN,DX ;Save Uncliped x2, y2 for next line segment MOV Word Ptr Y2,CX MOV Word Ptr YN,CX MOV BX,Word Ptr LSTYLE ;Current Line Style Bit Pattern MOV Word Ptr SPECIL,BX ;16 Bit Line Pattern for Drawxy routine CALL CLIPIT ;Clip line to inside current Plot Strip ; ; Zero = Off, if Line object lies entirely outside current Plot Strip ; JNZ L@1 CALL DRAWXY ;Draw line if not entirely clipped L@1: ; Draw to point, x1 = x2, y1 = y2 MOV BX,Word Ptr XN MOV Word Ptr X0,BX MOV Word Ptr X1,BX ;x1 = x2 MOV BX,Word Ptr YN MOV Word Ptr Y0,BX MOV Word Ptr Y1,BX ;y1 = y2 JMPS DRAL01 ;Draw next line segment DRAJ99: RET ;*** Mode Note : June 10, 1983 ; Instead of Standardize the line direction and rasterize the ; line from x0, y0 to xn, yn, to handle the special linestyle, ; rotate the line pattern mask, according to line direction ; and the delta x, delta y value to process specil linestyles. ; if dx > dy, then : ; rotate the pattern mask by delta x mod 16, where ; delta x = x1, if line direction is from 0 to xmax, x0 --> x1 ; delta x = xmax - x1, if line direction is from xmax to 0, x1 <-- x0 ; else if dy > dx, then : ; rotate the pattern mask by delta y mod 16, where ; delta y = y1, if line direction is from 0 to ymax, (up) ; delta y = ymax - y1, if line direction is from ymax to 0, (down) swapy : ; check dx > dy ? mov al, byte ptr doxy or al, al jnz swapjx ; doxy = 1, dx > dy ; doxy = 0, dy > dx, rotate pattern mask by delta y mod 16 ; compute delta y mod 16 ; check line direction, ydir = 0(down), y2 < y1, delta y = ymax - y1 ; ydir > 0(up), y1 < y2, delta y = y1 mov al, byte ptr ydir or al, al jnz swapy1 ; delta y = y1 ; rotate pattern by ymax - y1 mod 16 mov cx, word ptr ymax sub cx, word ptr y1 ; ax = delta y jmp swarol swapy1: mov cx, word ptr y1 jmp swarol ; check line direction, xdir = 0, x2 < x1, delta x = xmax - x1 ; xdir > 0, x1 < x2, delta x = x1 swapjx: ; IF DY = 0, (YDIR = 1), HORIZONTAL LINE, DO NOT ROTATE THE PATTERN MASK CMP BYTE PTR YDIR, 1 JZ NOROLL mov al, byte ptr xdir or al, al jnz swapx1 mov cx, word ptr xmax ; DELTA X = XMAX - X1 sub cx, word ptr x1 jmp swarol swapx1: mov cx, word ptr x1 swarol: and cx, 0FH ; rotate count = delta mod 16 rol specil, cl ; left rotate the line style pattern mask NOROLL: ret ; this replace the following section of swapy code. June 10, 1983 ;----------------------------------------------------------------------------+ ; SWAPY - Standardize Line direction to always go from Ymax to Ymin + ; So the line Rasterization Routine can stop at bottom of + ; the current Plot strip + ; ABOVE - 0 = Both endpoints are either inside or below the Current + ; Plot strip, + ; 1 = Y2 is above the Current Plot Strip + ; -1 = Y1 is above the Current Plot Strip, Direction ok + ;----------------------------------------------------------------------------+ ;SWAPY: ; MOV AL,Byte Ptr ABOVE ;Get Position Flag for endpoints ; Above : 0 : no swap, both point inside strip ; 1 : change line direction, and make line start from XN, YN ; Y2 = Y1, X2 = X1, Y1 = YN, X1 = XN ; -1 : make line start from X0, Y0 ; OR AL,AL ; JNZ L@2 ; RET ;L@2: ; JS SWAJ01 ;-1 : Y1 is above Top y ; Y2 is above Strip ; MOV BX,Word Ptr X1 ; MOV Word Ptr X2,BX ; MOV BX,Word Ptr Y1 ; MOV Word Ptr Y2,BX ;Change Y2 to lower point ; MOV BX,Word Ptr YN ; MOV Word Ptr Y1,BX ; MOV BX,Word Ptr XN ;Line was trimmed to Top y ; MOV Word Ptr X1,BX ;Change Y1 to the original end point ; RET ;SWAJ01: ; MOV BX,Word Ptr Y0 ;Y1 was clipped to Top y ; MOV Word Ptr Y1,BX ;Change Y1 to the Original Start point ; MOV BX,Word Ptr X0 ; MOV Word Ptr X1,BX ; RET ;***************************************************************************** ; * ; LINETY : GET CURRENT PATTERN FROM PATTERN WORD : LSTYLE * ; ROTATE NEXT BIT : ON/OFF, RETURN SET BIT FLAG ACCORDINGLY * ; * ;***************************************************************************** ; * ;LINETY: ;PUSH BX ;PUSH CX ;MOV BX,Word Ptr SPECIL ;Get the Pattern ;SHL BX,1 ;Rotate out next bit ;JNB LSTY09 ;bit not set : carry off ;INC BX ;STC ;set bit flaga ;LSTY09: ;MOV Word Ptr SPECIL,BX ;POP CX ;POP BX ;RET ; SPECIL is the Pattern Mask ;linety: ; rol Word Ptr specil, 1 ;Rotate Out Next bit into Carry END