home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_200 / 287_03 / vhln.asm < prev    next >
Assembly Source File  |  1989-05-25  |  9KB  |  306 lines

  1.         TITLE   VHLN of GDS
  2.         page    60,132
  3.         .SFCOND
  4. ;
  5. ; *==========================================================*
  6. ; * This file contain level 1 horizontal line, vertical line *
  7. ; * drawing and dot plotting routines                        *
  8. ; *==========================================================*
  9.  
  10. IFDEF   COLOR
  11.   IFDEF HERC
  12.    .err both display type defined
  13.   ENDIF
  14. else
  15.   IFNDEF HERC
  16.     HERC equ 0
  17.   ENDIF
  18. ENDIF
  19.  
  20. smo     equ     4       ; small model offset value
  21.  
  22. DGROUP  group   _DATA
  23. _DATA   segment word public 'DATA'
  24.         assume  ds:DGROUP
  25.         extrn   _STYLE:word
  26.         extrn   _DOTVALUE:word,_LEFTWORD:word,_RIGHTWORD:word
  27.         extrn   _LASTX:word, _LASTY:word
  28.  
  29.         extrn   wrtvec:word
  30.  
  31. tlen    dw      ?       ; temporary length
  32. vlpw    dw      ?       ; vertical line plot word
  33. vlsty   dw      ?       ; vertical line style
  34. wid     dw      ?       ; width
  35. voa     dw      ?       ; vertical line offset address
  36. vsa     dw      ?       ; vertical line segment address
  37. _DATA   ends
  38.  
  39. _TEXT   segment byte public 'CODE'
  40.         assume  cs:_TEXT,ds:DGROUP
  41.         public  _plot, _horzl,_SetStyle,_vertl
  42.         public  $dot,_vert1l
  43.  
  44.         extrn  $calc:near, downln:near
  45.  
  46. ; routine to plot a single dot
  47. ; input : x,y-coordinates in ax and bx
  48. $dot    proc    near    ; public routine
  49.         push    di
  50.         mov     di,ax
  51.         and     di,0fh
  52.         call    $calc           ; calculate the word address
  53.         mov     es,ax
  54.         shl     di,1
  55.         mov     ax,_DOTVALUE[di] ; get dot position
  56.         pop     di
  57.         jmp     wrtvec          ; go and write it
  58. $dot    endp
  59.  
  60. ; A C callable routine
  61. ;       ret=plot(x,y);
  62. ;       int ret,x,y;
  63. ;
  64. ;       x and y are the x and y coordintaes
  65. ;       return value is the plot word, usually not useful
  66. _plot   proc    near    ;public routine
  67.         push    bp
  68.         mov     bp,sp
  69.         mov     ax,[bp+smo]     ; get x coordinate
  70.         mov     bx,[bp+smo+2]   ; get y coordinate
  71.         pop     bp
  72.         jmp    short $dot
  73. _plot   endp
  74.  
  75. ; A C callable routine
  76. ;       horzl(x,y,length);
  77. ;       int     x,y,length
  78. ;
  79. ;       no checking for correct x,y coordinate and length
  80. ;               and no clipping too.
  81. _horzl  proc    near    ;public routine
  82.         push    bp
  83.         mov     bp,sp
  84.         push    si
  85.         push    di
  86.         mov     ax,[bp+smo]     ; get x coordinate
  87.         mov     bx,[bp+smo+2]   ; get y coordinate
  88.         mov     di,ax
  89.         call    $calc           ; calculate word address
  90.         mov     es,ax           ; segment number in es
  91.         and     di,0fh          ; get dot position within word
  92.         mov     si,di
  93.         add     di,[bp+smo+4]
  94.         shl     si,1
  95.         mov     ax,_LEFTWORD[si]
  96.         cmp     di,16           ; di > 16 if the line is not within the
  97.         ja      hl1             ; same word
  98.         shl     di,1            ; othwise the line is in the same word
  99.         xor     ax,_LEFTWORD[di]
  100.         pop     di
  101.         pop     si
  102.         pop     bp
  103.         and     ax,_STYLE       ; write with the setting in _STYLE
  104.         jmp     wrtvec          ; write the line
  105. ; line span across more than 1 word
  106. hl1:    and     ax,_STYLE       ; write the first portion
  107.         call    wrtvec
  108.         mov     cl,4            ; get the number of full words
  109.         mov     si,di           ; between first and last word
  110.         shr     si,cl
  111.         dec     si
  112.         jz      short hl2
  113.         mov     cx,si
  114.         mov     ax,_STYLE
  115. hl3:    inc     bx              ; repeat writing with the setting in _STYLE
  116.         inc     bx
  117.         call    wrtvec
  118.         loop    short hl3
  119. hl2:    inc     bx              ; point to next word
  120.         inc     bx
  121.         and     di,0fh
  122.         shl     di,1
  123.         mov     ax,_RIGHTWORD[di]       ; set up last word
  124.         pop     di
  125.         pop     si
  126.         pop     bp
  127.         and     ax,_STYLE       ; use STYLE
  128.         jmp     word ptr wrtvec
  129. _horzl  endp
  130.  
  131. ; *-------------------------------------------------------------*
  132. ; * This routine is quite long and complicated because it trys  *
  133. ; * to optimize the speed in drawing a wide vertical line.      *
  134. ; * The program is not difficult to understand if you know      *
  135. ; * what it is trying to do. Understand horzl above is helpful  *
  136. ; *-------------------------------------------------------------*
  137. ; A C callable routine
  138. ;       vertl(x,y,length,width);
  139. ;       int     x,y,length
  140. ;
  141. ;       no checking for correct x,y coordinate and length
  142. ;               and no clipping too.
  143.  
  144. _vertl  proc    near    ;public routine
  145.         push    bp
  146.         mov     bp,sp
  147.         push    si
  148.         push    di
  149.         mov     ax,[bp+smo]     ; get x coordinate
  150.         mov     bx,[bp+smo+2]   ; get y coordinate
  151.         call    $calc           ; calculate starting address
  152.         mov     voa,bx          ; save it in vsa and voa
  153.         mov     vsa,ax
  154.         mov     es,ax
  155.         mov     cx,[bp+smo+2]   ; get y coordinate
  156.         mov     dx,_STYLE
  157.         xchg    dh,dl
  158.         and     cl,0fh          ; adjust _STYLE for different y coordinate
  159.         mov     ch,cl
  160.         jz      short vl2
  161.         rol     dx,cl
  162. vl2:    mov     vlsty,dx
  163.         mov     ax,[bp+smo]
  164.         and     ax,0fh
  165.         mov     di,ax
  166.         shl     di,1
  167.         mov     dx,_LEFTWORD[di]
  168.         add     ax,[bp+smo+6]   ; get width
  169.         cmp     ax,16           ; <=16 if the width of the line is in 1 word
  170.         ja      short vl1
  171.         mov     di,ax           ; within 1 word
  172.         shl     di,1
  173.         xor     dx,_LEFTWORD[di]        ; set up the word that should
  174.         mov     vlpw,dx                 ; be in drawing
  175.         mov     cx,[bp+smo+4]   ; get length
  176.         mov     tlen,cx
  177.         mov     cx,[bp+smo+2]
  178.         mov     dx,vlsty
  179.         call    $vertl          ; draw the line
  180.         pop     di
  181.         pop     si
  182.         pop     bp
  183.         ret
  184. ;
  185. ; not within 1 word
  186. vl1:    mov     di,ax
  187.         and     di,0fh
  188.         shl     di,1
  189.         mov     cx,_RIGHTWORD[di]
  190.         push    cx
  191.         mov     cl,4
  192.         shr     ax,cl
  193.         mov     wid,ax
  194.         mov     vlpw,dx         ; set up the plot word
  195.         mov     cx,[bp+smo+4]
  196.         mov     tlen,cx
  197.         mov     cx,[bp+smo+2]
  198.         mov     dx,vlsty
  199.         call    $vertl          ; draw first portion
  200.         mov     vlpw,0ffffh     ; repeat drawing with whole word
  201.         dec     wid             ; (no style for width)
  202.         jz      short vl3
  203. vl4:    add     voa,2           ; move to next horizontal word
  204.         mov     bx,voa          ; restore starting address
  205.         mov     es,vsa
  206.         mov     cx,[bp+smo+4]   ; get length
  207.         mov     tlen,cx
  208.         mov     cx,[bp+smo+2]   ; get y coordinate
  209.         mov     dx,vlsty        ; set style
  210.         call    $vertl          ; draw it
  211.         dec     wid
  212.         jnz     short vl4
  213. vl3:    add     voa,2           ; move to last word
  214.         mov     bx,voa
  215.         mov     es,vsa
  216.         pop     cx
  217.         test    cx,cx
  218.         jz      vl5
  219.         mov     vlpw,cx
  220.         mov     cx,[bp+smo+4]
  221.         mov     tlen,cx
  222.         mov     cx,[bp+smo+2]
  223.         mov     dx,vlsty
  224.         call    $vertl    ; draw last word
  225. vl5:    pop     di
  226.         pop     si
  227.         pop     bp
  228.         ret
  229. _vertl  endp
  230.  
  231. ; A C callable routine but it is not public now
  232. ;       vert1l(x,y,length);
  233. ;       int x,y,length;
  234. ; the width is always 1
  235. _vert1l proc    near
  236.         push    bp
  237.         mov     bp,sp
  238.         push    si
  239.         push    di
  240.         mov     ax,[bp+smo]     ; get x coordinate
  241.         mov     bx,[bp+smo+2]   ; get y coordinate
  242.         call    $calc
  243.         mov     es,ax
  244.         push    bx
  245.         mov     bx,[bp+smo]
  246.         and     bx,0fh
  247.         shl     bx,1
  248.         mov     cx,_DOTVALUE[bx] ; get the plot word
  249.         mov     vlpw,cx
  250.         pop     bx
  251.         mov     cx,[bp+smo+4]   ; get length
  252.         mov     tlen,cx
  253.         mov     cx,[bp+smo+2]
  254.         mov     dx,_STYLE
  255.         xchg    dh,dl           ; adjust style for different starting y
  256.         and     cl,0fh
  257.         jz      short v1l1
  258.         rol     dx,cl
  259. v1l1:   mov     cx,[bp+smo+2]
  260.         call    $vertl    ; draw 1 line
  261.         pop     di
  262.         pop     si
  263.         pop     bp
  264.         ret
  265. _vert1l endp
  266.  
  267. ; input : es:bx starting address
  268. ;         dx    style
  269. ;         vlpw  plot word (word to be stored)
  270. ;         tlen  length of the line
  271. ; this routine affects si
  272. $vertl  proc    near
  273.         mov     _LASTY,cx
  274.         mov     ax,vlpw
  275.         mov     cx,tlen
  276. v$l1:   rol     dx,1
  277.         jnc     short v$l2
  278.         call    wrtvec
  279. v$l2:   call    downln
  280.         loop    short v$l1
  281.         ret
  282. $vertl  endp
  283.  
  284. ; A C callable routine
  285. ;       SetStyle(style);
  286. ;
  287. _SetStyle proc   near    ;public routine
  288.         mov     bx,sp
  289.         mov     ax,ss:[bx+smo-2]
  290.         test    ax,ax
  291.         jnz     short   ss1     ; if style is 0
  292.         mov     ax,_STYLE
  293.         xchg    ah,al
  294.         not     word ptr _STYLE ; reverse the old style
  295.         ret
  296. ss1:    xchg    ah,al
  297.         xchg    _STYLE,ax
  298.         xchg    ah,al
  299.         ret
  300. _SetStyle endp
  301.  
  302. _TEXT   ends
  303.         end
  304.  
  305.