home *** CD-ROM | disk | FTP | other *** search
/ ftp.update.uu.se / ftp.update.uu.se.2014.03.zip / ftp.update.uu.se / pub / rainbow / msdos / decus / RB140 / grlib03a.arj / VECT.ASM < prev    next >
Assembly Source File  |  1988-12-08  |  13KB  |  382 lines

  1. PAGE ,132
  2. ;VECT.ASM
  3. ;UPDATE HISTORY
  4. ;==============
  5. ; 15 nov 1984       Convert to CI86 V2.2
  6.  
  7.     include    asmc.h
  8.     SEGEND    CODE
  9.     SEGDEF    DATA
  10.  
  11. EXTRN    l_col:BYTE, l_wid:BYTE, gbmod:BYTE, ymax:WORD
  12. EXTRN    x_start:WORD, y_start:WORD, p1:BYTE, gp_buff:BYTE
  13.  
  14. Lx_st   DW      1
  15. Ly_st   DW      1
  16. Lx_sp   DW      1
  17. Ly_sp   DW      1
  18. Lflag   DB      1
  19.  
  20. Oct    DW    Oct0, Oct1, Oct2, Oct3, Oct4, Oct5, Oct6, Oct7
  21.  
  22.     SEGEND    DATA
  23.  
  24.     SEGDEF    CODE
  25.  
  26. PUBLIC     polyline, line, point, rectangle
  27.  
  28.     IF    @bigmodel
  29. EXTRN    gdc_nb:FAR, chk_col:FAR, a_mode:FAR, cxy2cp:FAR
  30. EXTRN    a_patrn:FAR, fifo_mt:FAR, eseg_sav:NEAR
  31.     ELSE
  32. EXTRN    gdc_nb:NEAR, chk_col:NEAR, a_mode:NEAR, cxy2cp:NEAR
  33. EXTRN    a_patrn:NEAR, fifo_mt:NEAR, eseg_sav:NEAR
  34.     ENDIF
  35.  
  36. ;******************************************************************************
  37. ;*                                                                            *
  38. ;*      F U N C T I O N     polyline(pnts, array)                            *
  39. ;*                          int pnts, *array;                                 *
  40. ;*                                                                            *
  41. ;*      purpose:        Draw a line joining the points defined in 'array'     *
  42. ;*                                                                            *
  43. ;*      entry:            6[bp] number of points to join                      *
  44. ;*                        8[bp] array containing 'xy' points                  *
  45. ;*                                                                            *
  46. ;******************************************************************************
  47.  
  48.  
  49.     PROCDEF    polyline
  50.     push    si
  51.         push    bp
  52.         mov     bp,sp
  53.  
  54.         call    gdc_nb
  55.         call    a_patrn        ;set up pat_reg & pat_mult for current line
  56.                                 ;type as held in l_type.
  57.  
  58.         mov     al,BYTE PTR l_col       ;check for correct colour.
  59.         call    chk_col
  60.  
  61.         test    BYTE PTR gbmod,2
  62.         jnz     L11             ;skip if already in vector mode.
  63.         or      BYTE PTR gbmod,12H      ;enable vector mode and writes.
  64.         call    a_mode
  65. L11:    mov    al,78H
  66.         out    57H,al          ;set pramDBs 8 and 9
  67.         mov    al,0FFH
  68.         out    56H,al
  69.         out    56H,al
  70.  
  71. L0:     mov     cx,6[bp]      ;get count.
  72.     dec    cx        ;# lines = 1 less than # points.
  73.     js    L2
  74.         mov     si,8[bp]      ;get pointer to array
  75.  
  76. L1:     push    cx              ;we don't want it corupted
  77.         push    si              ;send array pointer to line_
  78.         call    line
  79.     add    sp,2
  80.         pop     cx
  81.         add     si,4    ;point to last point plotted
  82.         loop    L1              ;keep going until array is exhausted
  83.  
  84. L2:     pop     bp
  85.     pop    si
  86.         ret
  87.     PROCEND    polyline
  88.  
  89. ;******************************************************************************
  90. ;                                                                             *
  91. ;        F U N C T I O N    line(array)    int *array;                       *
  92. ;                                                                             *
  93. ;        purpose:        Draw a vector                                        *
  94. ;                                                                             *
  95. ;        entry:          8[bp] points to xy array layed out as:               *
  96. ;                                                                             *
  97. ;                        Lx_st = starting x location                          *
  98. ;                        Ly_st = starting y location                          *
  99. ;                        Lx_sp= ending x location                             *
  100. ;                        Ly_sp= ending y location                             *
  101. ;                                                                             *
  102. ;******************************************************************************
  103.  
  104.     PROCDEF    line
  105.         push    di
  106.         push    si
  107.         push    bp
  108.         mov     bp,sp
  109.     sub    sp,2        ;local l_wid.
  110.  
  111.         mov     ax,cs:WORD PTR eseg_sav  ;reclaim ES just in case !!!!!
  112.         mov     es,ax
  113.         mov     si,8[bp]      ;get the array pointer
  114.         lea     di, Lx_st
  115.         cld
  116.         mov     cx,4
  117.         rep     movsw           ;move to the local variable area.
  118.     mov    al, BYTE PTR l_wid
  119.     xor    ah,ah
  120.     mov    -2[bp],ax
  121.  
  122.         mov     ax,Lx_st       ;is this a single point draw?
  123.         cmp     Lx_sp,ax      ;if yes then start=stop coordinates.
  124.         jnz     L10                     ;jump if definitely not.
  125.         mov     ax,Ly_st       ;maybe. check y coordinates.
  126.         cmp     Ly_sp,ax
  127.         jnz     L10                     ;jump if definitely not.
  128.         jmp     L14
  129.  
  130. ;Convert the starting x,y coordinate pair into a cursor positionDW value.
  131.  
  132. L10:    mov     ax,WORD PTR ymax  ;convert 'y' values from bottom left origin
  133.         sub     ax,Ly_sp      ;to top left origin.
  134.         mov     Ly_sp,ax
  135.  
  136.         mov     ax,WORD PTR ymax
  137.         sub     ax,Ly_st      ;upper 16 bits
  138.         mov     Ly_st,ax
  139.  
  140. L12:    mov     ax,Lx_st
  141.         mov     WORD PTR x_start,ax
  142.         mov     ax,Ly_st
  143.         mov     WORD PTR y_start,ax
  144.         call    cxy2cp
  145.  
  146.     mov     bx,Ly_sp        ;compute delta y
  147.     sub     bx,Ly_st        ;delta y negative now?
  148.     jns     Lquad34         ;jump if not [must be either quad 3 or 4]
  149. Lquad12:
  150.     neg     bx              ;delta y is negative, make absolute
  151.     mov     ax,Lx_sp        ;compute delta x
  152.     sub     ax,Lx_st        ;delta x negative?
  153.     js      Lquad2          ;jump if yes
  154. Lquad1:
  155.     cmp     ax,bx           ;octant 2?
  156.     jbe     Loct3           ;jump if not
  157. Loct2:  mov    dl,2           ;direction of write
  158.     jmp    Lvxind   ;abs[deltax]>abs[deltay], independent axis=x-axis
  159. Loct3:  or    ax,ax
  160.     jz    Loct4
  161.     mov    dl,3           ;direction of write
  162.     jmp    Lvyind   ;abs[deltax]=<abs[deltay], independent axis=y-axis
  163. Lquad2:
  164.     neg     ax              ;delta x is negative, make absolute
  165.     cmp     ax,bx           ;octant 4?
  166.     jae     Loct5           ;jump if not
  167. Loct4:  mov    dl,4           ;direction of write
  168.     jmp    Lvyind   ;abs[deltax]=<abs[deltay], independent axis=y-axis
  169. Loct5:  mov    dl,5           ;direction of write
  170.     jmp    Lvxind   ;abs[deltax]>abs[deltay], independent axis=x-axis
  171. Lquad34:
  172.     mov     ax,Lx_sp        ;compute delta x
  173.     sub     ax,Lx_st
  174.     jns     Lquad4          ;jump if delta x is positive
  175. Lquad3:
  176.     neg     ax              ;make delta x absolute instead of negative
  177.     cmp     ax,bx           ;octant 6?
  178.     jbe     Loct7           ;jump if not
  179. Loct6:  mov    dl,6           ;direction of write
  180.     jmp    Lvxind   ;abs[deltax]>abs[deltay], independent axis=x-axis
  181. Loct7:  mov    dl,7           ;direction of write
  182.     jmp    Lvyind   ;abs[deltax]<=abs[deltay], independent axis=y-axis
  183. Lquad4:
  184.     cmp     ax,bx           ;octant 0?
  185.     jae     Loct1           ;jump if not
  186. Loct0:  mov    dl,0           ;direction of write
  187.     jmp    Lvyind   ;abs[deltax]<abs[deltay], independent axis=y-axis
  188. Loct1:  or    bx,bx
  189.     jz    Loct2
  190.     mov    dl,1           ;direction of write
  191.     jmp    Lvxind   ;abs[deltax]=>[deltay], independent axis=x-axis
  192.  
  193. Lvyind: xchg    ax,bx           ;put independent axis in ax, dependent in bx
  194. Lvxind: and     ax,03FFFH       ;limit to 14 bits
  195.     mov    BYTE PTR p1, dl
  196.         mov     dx,bx
  197.         mov     WORD PTR p1+1,ax        ;DC=abs[delta x]-1
  198.         shl     bx,1            ;multiply delta y by two
  199.         sub     bx,ax
  200.         and     bx,03FFFH       ;limit to 14 bits
  201.         mov     WORD PTR p1+3,bx        ;D=2*abs[delta y]-abs[delta x]
  202.         mov     bx,dx           ;restore [abs[delta y]
  203.         sub     bx,ax
  204.         shl     bx,1
  205.         and     bx,03FFFH       ;limit to 14 bits
  206.         mov     WORD PTR p1+5,bx        ;D2=2*[abs[delta y]-abs[delta x]]
  207.         mov     bx,dx
  208.         shl     bx,1
  209.         dec     bx
  210.         and     bx,03FFFH       ;limit to 14 bits
  211.         mov     WORD PTR p1+7,bx        ;D1=2*abs[delta y]-1
  212.         call    fifo_mt        ;check the FIFO just in case we're too quick.
  213.         mov    al,4CH  ;issue the FIGS command
  214.         out    57H,al
  215.         lea     si,  p1
  216.         lodsb                   ;send p1_ parameter.
  217.         or      al,8
  218.         out    56H,al          ;issue a parameterDB
  219.         mov     cx,8            ;issue the 8DBs of DC,D,D2,D1
  220. L13:    lodsb                   ;fetchDB
  221.         out    56H,al          ;issue to the GDC
  222.         loop    L13             ;loop until all 8 done
  223.         mov    al,6CH  ;start the drawing process in motion
  224.         out    57H,al          ;by issuing FIGD
  225.  
  226.     dec    WORD PTR -2[bp]
  227.     jz    L14
  228.     mov    al, BYTE PTR p1
  229.     xor    ah,ah
  230.     shl    ax,1
  231.     lea    bx,Oct
  232.     add    bx,ax
  233.     call    [bx]
  234.     jmp    L12
  235.  
  236. L14:    mov    sp,bp
  237.     pop     bp
  238.         pop     si
  239.         pop     di
  240.         ret
  241.  
  242. Oct0:
  243.     dec    WORD PTR Lx_st
  244.     dec    WORD PTR Lx_sp
  245.     ret
  246. Oct1:
  247.     dec    WORD PTR Lx_st
  248.     inc    WORD PTR Ly_st
  249.     dec    WORD PTR Lx_sp
  250.     inc    WORD PTR Ly_sp
  251.     ret
  252. Oct2:
  253.     inc    WORD PTR Ly_st
  254.     inc    WORD PTR Ly_sp
  255.     ret
  256. Oct3:
  257.     inc    WORD PTR Lx_st
  258.     inc    WORD PTR Ly_st
  259.     inc    WORD PTR Lx_sp
  260.     inc    WORD PTR Ly_sp
  261.     ret
  262. Oct4:
  263.     inc    WORD PTR Lx_st
  264.     inc    WORD PTR Lx_sp
  265.     ret
  266. Oct5:
  267.     inc    WORD PTR Lx_st
  268.     dec    WORD PTR Ly_st
  269.     inc    WORD PTR Lx_sp
  270.     dec    WORD PTR Ly_sp
  271.     ret
  272. Oct6:
  273.     dec    WORD PTR Ly_st
  274.     dec    WORD PTR Ly_sp
  275.     ret
  276. Oct7:
  277.     dec    WORD PTR Lx_st
  278.     dec    WORD PTR Ly_st
  279.     dec    WORD PTR Lx_sp
  280.     dec    WORD PTR Ly_sp
  281.     ret
  282.  
  283.     PROCEND    line
  284.  
  285. ;*****************************************************************************
  286. ;*                                                                           *
  287. ;*      F U N C T I O N    point(x, y)                                       *
  288. ;*                                                                           *
  289. ;*      purpose:        Draw a pixel                                         *
  290. ;*                                                                           *
  291. ;*      entry:          4[bp] x location                                     *
  292. ;*                      6[bp] y location                                     *
  293. ;*                                                                           *
  294. ;*****************************************************************************
  295.  
  296.     PROCDEF    point
  297.         push    bp
  298.         mov     bp,sp
  299.  
  300.         call    gdc_nb
  301.         mov     al,BYTE PTR l_col       ;check that colour is OK
  302.         call    chk_col
  303.  
  304.         test    BYTE PTR gbmod,2
  305.         jnz     Lp0
  306.         or      BYTE PTR gbmod,12H
  307.         call    a_mode
  308. Lp0:    mov     ax,4[bp]
  309.         mov     WORD PTR x_start,ax
  310.         mov     ax,WORD PTR ymax
  311.         sub     ax,6[bp]
  312.         mov     WORD PTR y_start,ax
  313.         call    cxy2cp         ;convert 'xy' to cursor pos. & send to GDC.
  314.  
  315.         mov    al,4CH        ;assert the FIGS command
  316.         out    57H,al
  317.         mov    al,2            ;line drawn to the right.
  318.         out    56H,al
  319.         mov    al,6CH        ;tell the GDC to draw the pixel when ready.
  320.         out    57H,al
  321.  
  322.         pop     bp
  323.         ret
  324.     PROCEND    point
  325.  
  326. ;************************************************************************
  327. ;*                                                                      *
  328. ;*              F U N C T I O N    rectangle(array)  int *array;        *
  329. ;*                                                                      *
  330. ;*  purpose:    draw a rectangle by defining the top right and          *
  331. ;*              bottom left points.                                     *
  332. ;*  entry:      6[bp] has the pointer to the 'xy' array                 *
  333. ;*                                                                      *
  334. ;*              0[array] bottom left 'x'                                *
  335. ;*              2[array] bottom left 'y'                                *
  336. ;*              4[array] top right 'x'                                  *
  337. ;*              6[array] top right 'y'                                  *
  338. ;*                                                                      *
  339. ;*      NOTE:   both 'y' values are relative to a bottom left origin    *
  340. ;*                                                                      *
  341. ;************************************************************************
  342.  
  343.     PROCDEF    rectangle
  344.         push    si
  345.         push    bp
  346.         mov     bp,sp
  347.  
  348.     mov    ax,cs:WORD PTR eseg_sav    ;cautious as ever
  349.     mov    es,ax
  350.     cld
  351.         mov     si,6[bp]        ;point SI to the source array.
  352.         lea     bx, gp_buff      ;point BX to gen. purpose buffer area.
  353.         lodsw                   ;get X1
  354.         mov     [bx],ax             ;bot_lft 'x'
  355.         mov     12[bx],ax           ;top_lft 'x'
  356.         mov     16[bx],ax           ;bot_lft 'x'
  357.         lodsw                   ;get Y1
  358.         mov     2[bx],ax            ;bot_lft 'y'
  359.         mov     6[bx],ax            ;bot_rgt 'y'
  360.         mov     18[bx],ax           ;bot_lft 'y'
  361.         lodsw                   ;get X2
  362.         mov     4[bx],ax            ;bot_rgt 'x'
  363.         mov     8[bx],ax            ;top_rgt 'x'
  364.         lodsw                   ;get Y2
  365.         mov     10[bx],ax           ;top_rgt 'y'
  366.         mov     14[bx],ax           ;top_lft 'y'
  367.  
  368.         push    bx
  369.         mov     ax,5
  370.         push    ax
  371.         call    polyline
  372.         add     sp,4
  373.  
  374.         pop     bp
  375.         pop     si
  376.         ret
  377.     PROCEND    rectangle
  378.  
  379.     include    epilogue.h
  380.     END
  381. 
  382.