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 / FILL.ASM < prev    next >
Assembly Source File  |  1988-12-08  |  11KB  |  476 lines

  1. PAGE ,132
  2. title FILL.ASM
  3. ;UPDATE HISTORY
  4. ;==============
  5. ; 14 nov 84    Convert to CI86 V2.2
  6. ;  4 Dec 84     New version to correct idiosyncrosy in graphics option
  7. ;               in which REPlace & COMPlement modes didn't work properly.
  8. ;               The pattern write is now done external to the Graphics option.
  9. ; 11 Dec 84     Bugfix - free memory after single point or hollow fill.
  10.     include    asmc.h
  11.  
  12.     SEGEND    CODE
  13.  
  14. RELEASE MACRO   addr
  15.     mov    ax,addr
  16.     push    ax
  17.     call    free
  18.     add    sp,2
  19.     ENDM
  20.  
  21.     SEGDEF    DATA
  22.  
  23. EXTRN    f_col:BYTE, f_type:BYTE, f_patrn:BYTE, f_style:BYTE
  24. EXTRN    gbmod:BYTE, ymax:WORD, gp_buff:WORD, y_start:WORD
  25. EXTRN    x_start:WORD, x_stop:WORD, y_stop:WORD, l_type:BYTE
  26. EXTRN    l_col:BYTE, sh_p_lin:BYTE, curl0:BYTE, nmritl:BYTE, gbmskl:BYTE
  27.  
  28. Lymin    DW      0
  29. Lymin1    DW      0
  30. Lymax    DW      0
  31. Lydif    DW      0
  32. Lcntr    DW      0
  33. Lcnt1    DW      0
  34. Lnpnt    DW      0
  35. Lfpat    DW      0
  36. Lbuff    DW      0
  37.  
  38.     SEGEND    DATA
  39.  
  40.     SEGDEF    CODE
  41.  
  42. PUBLIC    polyfill, bar
  43.  
  44.     IF    @bigmodel
  45. EXTRN    gdc_nb:FAR, a_mode:FAR, malloc:FAR, cxy2cp:FAR, fifo_mt:FAR
  46. EXTRN    free:FAR, polyline:FAR, line:FAR, a_gbmsk:FAR, a_cur:FAR
  47. EXTRN    chk_col:FAR, a_patrn:FAR, eseg_sav:FAR
  48.     ELSE
  49. EXTRN    gdc_nb:NEAR, a_mode:NEAR, malloc:NEAR, cxy2cp:NEAR, fifo_mt:NEAR
  50. EXTRN    free:NEAR, polyline:NEAR, line:NEAR, a_gbmsk:NEAR, a_cur:NEAR
  51. EXTRN    chk_col:NEAR, a_patrn:NEAR, eseg_sav:NEAR
  52.     ENDIF
  53.  
  54. ;************************************************************************
  55. ;*                                    *
  56. ;*    F U N C T I O N     polyfill(count, array)            *
  57. ;*                int count, *array;                *
  58. ;*                                    *
  59. ;*    purpose:    Fill an area with a pattern specified by    *
  60. ;*            f_type and f_style which is defined as a    *
  61. ;*            series of 'xy' points [array] whose length    *
  62. ;*            is 'count' 'xy' pairs.                *
  63. ;*                                    *
  64. ;*    entry:        8[bp] number of 'xy' pairs in 'array'.        *
  65. ;*            A[bp] pointer to the 'xy' pairs.        *
  66. ;*                                    *
  67. ;************************************************************************
  68.  
  69.     PROCDEF    polyfill
  70.     push    si
  71.     push    di
  72.     push    bp
  73.     mov    bp,sp
  74.  
  75.     mov    ax,cs:WORD PTR eseg_sav
  76.     mov    es,ax
  77.  
  78.     mov    ax,0400H    ;allocate a 1k area for temporary storage.
  79.     push    ax
  80.     call    malloc
  81.     add    sp,2
  82.     or    ax,ax
  83.     jnz    Lv
  84.     jmp    Lexit1
  85. Lv:
  86.     mov    Lbuff,ax
  87.  
  88.     call    gdc_nb
  89.     mov    al,BYTE PTR f_col  ;change the colour to that specified for
  90.     call    chk_col        ;area filling.
  91.  
  92.     test    BYTE PTR gbmod,2    ;are we in vector mode ?
  93.     jnz    Lv1
  94.     or    BYTE PTR gbmod,12H
  95.     call    a_mode
  96.  
  97. Lv1:    mov    cx,8[bp]
  98.     dec    cx
  99.     jnz    L0a        ;finished if it is a single point.
  100.     RELEASE Lbuff
  101.     jmp    Lexit
  102. L0a:    mov    Lnpnt,cx
  103.  
  104.     mov    al,BYTE PTR f_type    ;get the fill type.
  105.     xor    ah,ah
  106.     cmp    ax,0        ;is it HOLLOW ?
  107.     jnz    L0b
  108.     RELEASE Lbuff
  109.     jmp    L9        ;finished if yes.
  110. L0b:    lea    dx, f_patrn
  111.     mov    bx,0
  112.     cmp    ax,1        ;fill_type solid ?
  113.     jz    L0c
  114.     add    dx,8
  115.     mov    bl,BYTE PTR f_style
  116.     cmp    ax,2        ;fill_type PATTERN ?
  117.     jz    L0c
  118.     add    bx,8        ;offset f_style for HATCH.
  119. L0c:    mov    cl,3
  120.     shl    bx,cl
  121.     add    dx,bx
  122.     mov    Lfpat,dx
  123.  
  124.     mov    bx,WORD PTR ymax
  125.     mov    si,10[bp]
  126.     lea    di, gp_buff
  127.     mov    cx,8[bp]
  128. L0d:    lodsw            ;move all the 'xy' pairs to temporary storage
  129.     stosw            ;in 'gp_buff' and convert all 'y' values to a
  130.     mov    ax,bx        ;bottom left origin.
  131.     sub    ax,[si]
  132.     stosw
  133.     add    si,2
  134.     loop    L0d
  135.  
  136.     mov    Lymin,3E8H
  137.     mov    Lymax,0
  138.     lea    si, gp_buff
  139.     mov    cx,8[bp]
  140. L1:    add    si,2
  141.     lodsw
  142.     cmp    ax,Lymin
  143.     jnl    L2
  144.     mov    Lymin,ax
  145. L2:    cmp    ax,Lymax
  146.     jle    L2a
  147.     mov    Lymax,ax
  148. L2a:    loop    L1
  149.  
  150.     mov    ax,Lymin
  151.     mov    Lymin1,ax
  152.     mov    bx,Lymax
  153.     sub    bx,ax
  154.     mov    Lydif,bx
  155.     jnz    L2b
  156.     jmp    L7
  157.  
  158. L2b:    mov    al,78H
  159.     out    57H,al
  160.     mov    al,0ffH
  161.     out    56H,al
  162.     out    56H,al
  163.  
  164. L3:    mov    Lcntr,0
  165.     mov    cx,Lnpnt
  166.     lea    si, gp_buff
  167. L4:    push    cx
  168.     mov    di,si
  169.     add    di,4
  170.     push    si
  171.     call    L10
  172.     pop    si
  173.     add    si,4
  174.     pop    cx
  175.     loop    L4
  176.  
  177.     lea    di, gp_buff
  178.     call    L10
  179.     mov    ax,Lcntr
  180.     shr    ax,1
  181.     jnz    L4a
  182.     jmp    L6
  183. L4a:    mov    Lcnt1,ax
  184.     mov    si,Lymin1
  185.     mov    WORD PTR y_start,si
  186.     and    si,7
  187.     neg    si
  188.     add    si,7
  189.     add    si,Lfpat
  190.     mov    al,BYTE PTR [si]
  191.     mov    ah,al
  192.     mov    bx,Lbuff
  193. L5:    push    ax
  194.     push    bx
  195.     mov    cx,[bx]
  196.     mov    WORD PTR x_start,cx
  197.     push    cx
  198.     push    ax
  199.     call    gdc_nb
  200.     call    cxy2cp
  201.     mov    al,0fdH        ;select the PATTERN MULTIPLIER.
  202.     out    53H,al
  203.     mov    al,0fH        ;x1 pattern.
  204.     out    51H,al
  205.     mov    al,0fbH    ;select the PATTERN REGISTER.
  206.     out    53H,al
  207.     pop    ax
  208.     pop    cx
  209.     and    cx,000fH
  210.     ror    ax,cl
  211.     out    51H,al
  212.  
  213.     mov    al,4CH        ;issue the FIGS command.
  214.     out    57H,al
  215.     mov    al,02H
  216.     out    56H,al
  217.     mov    ax,2[bx]
  218.     sub    ax,WORD PTR x_start
  219.     out    56H,al
  220.     xchg    al,ah
  221.     out    56H,al
  222.     xchg    al,ah
  223.     neg    ax
  224.     out    56H,al
  225.     xchg    al,ah
  226.     out    56H,al
  227.     xchg    al,ah
  228.     shl    ax,1
  229.     out    56H,al
  230.     xchg    al,ah
  231.     out    56H,al
  232.  
  233.     mov    al,6CH        ;issue the DRAW command.
  234.     out    57H,al
  235.  
  236.     pop    bx
  237.     pop    ax
  238.     add    bx,4
  239.     dec    Lcnt1
  240.     jz    L6
  241.     jmp    L5
  242.  
  243. L6:    inc    Lymin1
  244.     dec    Lydif
  245.     jz    L7
  246.     jmp    L3
  247.  
  248. L7:    RELEASE Lbuff
  249.  
  250.     mov    bx,WORD PTR ymax
  251.     lea    di, gp_buff+2
  252.     mov    si,di
  253.     mov    cx,8[bp]
  254. L8:    mov    ax,bx
  255.     sub    ax,[si]
  256.     stosw
  257.     add    si,4
  258.     add    di,2
  259.     loop    L8
  260.  
  261. L9:    call    gdc_nb
  262.     mov    al,BYTE PTR l_type    ;get current line type.
  263.     push    ax
  264.     mov    BYTE PTR l_type,0    ;make it a solid line.
  265.     call    a_patrn        ;assert it.
  266.     mov    al,BYTE PTR l_col
  267.     call    chk_col
  268.     pop    ax
  269.     mov    BYTE PTR l_type,al    ;restore the old line type.
  270.  
  271.     mov    ax,10[bp]    ;join all the points with a polyline.
  272.     push    ax
  273.     mov    ax,8[bp]
  274.     push    ax
  275.     call    polyline
  276.     pop    cx
  277.     pop    si
  278.  
  279.     lodsw            ;now join the first point to the last point.
  280.     mov    WORD PTR x_start,ax
  281.     lodsw
  282.     mov    WORD PTR y_start,ax
  283.     sub    cx,2
  284.     jz    Lexit        ;finished if it was a straight line.
  285.     shl    cx,1
  286.     shl    cx,1
  287.     add    si,cx
  288.     lodsw
  289.     mov    WORD PTR x_stop,ax
  290.     lodsw
  291.     mov    WORD PTR y_stop,ax
  292.     lea    ax, x_start
  293.     push    ax
  294.     call    line
  295.     add    sp,2
  296.  
  297. Lexit:    mov    ax,0001H
  298. Lexit1:    pop    bp
  299.     pop    di
  300.     pop    si
  301.     ret
  302.  
  303. L10:    mov    bx,2[di]
  304.     sub    bx,2[si]
  305.     jz    L17
  306.     mov    ax,Lymin1
  307.     mov    cx,ax
  308.     sub    cx,2[si]
  309.     sub    ax,2[di]
  310.     xor    ax,cx
  311.     jns    L17
  312.     mov    ax,[di]
  313.     sub    ax,[si]
  314.     shl    cx,1
  315.     imul    cx
  316.     idiv    bx
  317.     inc    ax
  318.     sar    ax,1
  319.     add    ax,[si]
  320.     
  321.     mov    bx,[si]
  322.     mov    cx,[di]
  323.     cmp    bx,cx
  324.     jle    L11
  325.     xchg    bx,cx
  326. L11:    cmp    ax,bx
  327.     jnl    L12
  328.     mov    ax,bx
  329. L12:    cmp    ax,cx
  330.     jle    L13
  331.     mov    ax,cx
  332. L13:    mov    di,Lbuff
  333.     mov    cx,Lcntr
  334.     jcxz    L16
  335. L14:    scasw
  336.     jl    L15
  337.     loop    L14
  338.     jmp    L16
  339. L15:    mov    di,Lcntr
  340.     shl    di,1
  341.     add    di,Lbuff
  342.     mov    si,di
  343.     sub    si,2
  344.     std
  345.     rep movsw
  346.     cld
  347. L16:    stosw
  348.     inc    Lcntr
  349. L17:    ret
  350.     PROCEND    polyfill
  351.  
  352. ;************************************************************************
  353. ;*                                                                      *
  354. ;*              F U N C T I O N    bar[array]  int *array;              *
  355. ;*                                                                      *
  356. ;*  purpose:    set a user defined screen rectangle to a user           *
  357. ;*              defined color.                                          *
  358. ;*  entry:      0x06[bp] has the pointer to the 'xy' array              *
  359. ;*                                    *
  360. ;*        0[array] has the start x in pixels            *
  361. ;*              6[array] has the start y in scan lines                  *
  362. ;*              4[array] has the stop x in pixels                       *
  363. ;*              2[array] has the stop y in scan lines                   *
  364. ;*              f_col is the color to fill the bar with.                *
  365. ;*                                                                      *
  366. ;*    NOTE:    both 'y' values are relative to a bottom left origin    *
  367. ;*                                    *
  368. ;************************************************************************
  369.  
  370.     PROCDEF    bar
  371.     push    si
  372.     push    bp
  373.     mov    bp,sp
  374.     sub    sp,4    ;make room for local y start and y stop
  375.  
  376.     mov    si,6[bp]    ;get the array pointer
  377.     mov    ax,WORD PTR ymax ;adjust both 'y' values for top left origin
  378.     sub    ax,2[si]
  379.     mov    -2[bp],ax
  380.  
  381.     mov    ax,WORD PTR ymax
  382.     sub    ax,6[si]
  383.     mov    -4[bp],ax
  384.  
  385.     mov     ax,[si]     ;turn bl_x address into word address.
  386.         mov    cl,4
  387.         shr     ax,cl
  388.         mov     dx,-4[bp]     ;turn tr_y into words per line * y.
  389.     mov    cx,WORD PTR sh_p_lin    ;high res = 6,  medium res = 5.
  390.     shl     dx,cl
  391.         add     dx,ax           ;combine x and y word addresses.
  392.         mov     WORD PTR curl0,dx       ;first curl0.
  393.         mov     ax,-2[bp]     ;find number of lines to write by:
  394.         sub     ax,-4[bp]    ;   bl_y - tr_y
  395.         mov     WORD PTR nmritl,ax
  396.  
  397.     call    gdc_nb
  398.         mov    al,BYTE PTR f_col       ;check for correct colour.
  399.     call    chk_col
  400.     test    BYTE PTR gbmod,2
  401.     jz    Lb0
  402.     and     BYTE PTR gbmod,0fdH    ;put into word mode.
  403.         or      BYTE PTR gbmod,010H    ;put into write-enable mode.
  404.     call    a_mode
  405.  
  406. Lb0:    mov    al,0FEH    ;reset write buffer counter.
  407.     out    53H,al
  408.     out    51H,al
  409.     mov    cx,10H
  410.     xor    al,al
  411. Lba:    out    52H,al        ;fill buffer with zero's.
  412.     loop    Lba
  413. ;
  414. ;program the text mask:
  415. ;there are four possible write conditions: 
  416. ;a]partially write disabled to theleft 
  417. ;b]completely write enabled 
  418. ;c]partially write disabled to the right 
  419. ;d]partially write disabled to both left and right
  420.  
  421. Lb1:    mov     bx,0ffffH      ;calculate the current write mask.
  422.         mov     cx,[si]        ;get bl_x
  423.         and     cx,0fH        ;eliminate all but pixel information.
  424.         shr     bx,cl           ;shift in a 0 for each left pixel to disable.
  425.  
  426.         mov     ax,[si]        ;test to see if word tr_x is equal
  427.         and     ax,0fff0H      ;to word bl_x.
  428.         mov     cx,4[si]
  429.         and     cx,0fff0H
  430.         cmp     ax,cx           ;below?
  431.     jb    Lb3        ;jump if yes.
  432.     je    Lb2        ;jump if equal. do last write.
  433.  
  434.     add    sp,4
  435.     pop    bp        ;exit.
  436.     pop    si
  437.     ret
  438.  
  439. Lb2:    mov     cx,4[si]     ;get pixel info out of tr_x.
  440.         and     cx,0fH
  441.         inc     cx              ;make endpoint inclusive of write.
  442.         mov     ax,0ffffH      ;shift the disable mask.
  443.         shr     ax,cl           ;wherever there is a one, we want to
  444.         xor     ax,0ffffH      ;enable writes.
  445.     and    bx,ax           ;combine right and left masks.
  446.  
  447. Lb3:    xor     bx,0ffffH      ;invert so where there is a 1 we write disable.
  448.     mov    WORD PTR gbmskl,bx      ;make sure that the GDC isn't busy
  449.     call    gdc_nb
  450.     call    a_gbmsk        ;and assert the write mask.
  451.     call    a_cur        ;assert the GDC cursor address.
  452.  
  453.         mov    al,4cH        ;assert figs to GDC.
  454.         out    57H,al
  455.         xor    al,al           ;direction is down.
  456.         out    56H,al
  457.         mov    ax,WORD PTR nmritl
  458.         out    56H,al         ;assert number of write operations to perform.
  459.         mov    al,ah
  460.         out    56H,al
  461.         mov    al,22H        ;assert write data command.
  462.         out    57H,al
  463.         mov    al,0ffH
  464.         out    56H,al
  465.         out    56H,al
  466.  
  467.         and     [si],0fff0H  ;strip off pixel info.
  468.         add     WORD PTR [si],16    ;address the next word.
  469.         inc     WORD PTR curl0
  470.     jmp    Lb1        ;check for another column to clear.
  471.     PROCEND    bar
  472.  
  473. include epilogue.h
  474.     END
  475. 
  476.