home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 14 / CDACTUAL.iso / cdactual / demobin / share / program / asm / RTGRAF.ZIP / SOURCE.ZIP / ESOLBOX.ASM < prev    next >
Encoding:
Assembly Source File  |  1990-06-30  |  7.6 KB  |  237 lines

  1.  
  2. ;************************************************************************
  3. ; solid_box(x0,y0,x1,y1,color)   fill a rectangle defined by            *
  4. ;       upper-left 'x0,y0', and lower-right 'x1,y1'                     *
  5. ;       with the specified color 'Color'.                               *
  6. ;************************************************************************
  7. ;  large model parms
  8. px0      EQU     [BP+6]
  9. py0      EQU     [BP+8]
  10. px1      EQU     [BP+10]
  11. py1      EQU     [BP+12]
  12. pColor   EQU     [BP+14]
  13.  
  14. ;  small model parms
  15. ;px0      EQU     [BP+4]
  16. ;py0      EQU     [BP+6]
  17. ;px1      EQU     [BP+8]
  18. ;py1      EQU     [BP+10]
  19. ;pColor   EQU     [BP+12]
  20.  
  21. byte_rng  equ     word ptr [bp-2]
  22. depth     equ     word ptr [bp-4]
  23. lBwide    equ     word ptr [bp-6]
  24.  
  25.         PUBLIC  _solid_box
  26.  
  27. _solid_box      proc far
  28.         push    bp
  29.         mov     bp,sp
  30.         sub     sp,8        ;protect local storage
  31.         pushf
  32.         cld
  33.         push    di
  34.         push    si
  35.         push    ds
  36.         push    es
  37.  
  38. ;      We want the definition arranged so that [0] is the top-left
  39. ;      corner, and [1] is the bottom right
  40.  
  41.         mov     ax,py1
  42.         mov     bx,py0
  43.         cmp     ax,bx
  44.         jge     y_in_order
  45.  
  46.         mov     py0,ax      ;swap y coordinates
  47.         mov     py1,bx
  48. y_in_order:
  49.         mov     ax,px1                   ; make px0 < px1
  50.         mov     bx,px0
  51.         cmp     ax,bx
  52.         jge     x_in_order
  53.  
  54.         mov     px0,ax      ;swap x coordinates
  55.         mov     px1,bx
  56. x_in_order:
  57.  
  58. ;      determine the distance spanned by the rectangle. Possible cases
  59. ;      are 0) both ends in one byte
  60. ;          1) each end in adjacent bytes
  61. ;         >1) end in different bytes with full bytes in between
  62.  
  63.        mov     cl,3         ;divide by 8  - find byte addr
  64.        mov     ax,px0
  65.        shr     ax,cl        ;byte value is left
  66.        mov     bx,px1
  67.        shr     bx,cl        ;byte value is left
  68.        sub     bx,ax        ;difference
  69.        dec     bx           ;moves range to -1,0,>0
  70. ;
  71. ;      Shift it down by one for easier testing
  72. ;          -1) both ends in one byte
  73. ;           0) each end in adjacent bytes
  74. ;          >0) end in different bytes with full bytes in between
  75. ;
  76.        mov     byte_rng,bx
  77.  
  78. ;      Compute the byte offset in the video memory for the
  79. ;          top left corner
  80.  
  81.         mov     cx,px0
  82.         mov     bx,py0
  83.         call    emapxy
  84.  
  85. ;
  86. ;       enable set/reset mode
  87. ;       then load reset register
  88. ;
  89.         mov     dx,GRAPHIC12
  90.         mov     al,SETRESET ;set SET/RESET register
  91.         out     dx,al
  92.         inc     dx          ;now data register
  93.  
  94.         mov     al,pCOLOR   ;what color was requested?
  95.         out     dx,al       ;Set the active (set) bits
  96.                             ; that loaded the color into the SETRESET reg.
  97.         dec     dx          ;now back to control register
  98.  
  99.         mov     al,ENABLERESET ;defines which planes will be modified
  100.                                ; from the SETRESET register
  101.         out     dx,al       ;
  102.         inc     dx          ;and back to data register
  103.  
  104.         mov     al,0ffh     ;work with all 4 planes
  105.         out     dx,al       ;0ffh should activate all planes
  106.         dec     dx          ;back to control
  107.         ;
  108.         mov     ax,_bytes_per_line
  109.         mov     lBwide,ax   ; save befor we destroy DS
  110.  
  111.         mov     dx,_curr_vid_seg
  112.         mov     es,dx
  113.         mov     ds,dx       ; so that 'rep stosb' will work
  114.  
  115. ;------------------- FILL LEADING PARTIAL BYTES ------------------------
  116. ; in this section first strip of the rectangle is drawn
  117.  
  118.         mov     cx,px0      ;determine the bit position of the top left
  119.         and     cx,07h      ;corner within the video byte
  120.  
  121.         mov     ax,px0      ;reset rectangle to be at next byte aligned x val
  122.         add     ax,8        ;advance to next byte
  123.         sub     ax,cx       ;subtract bit count in leading partial byte
  124.         mov     px0,ax      ;save for next phase
  125.  
  126.         mov     bx,0ffh     ;build a bit map for new partial
  127.         shr     bx,cl       ;shift down to start of block
  128.  
  129.         cmp     byte_rng,0  ;does it stop in this byte
  130.         jge     full_left   ;spans beyond this simple byte
  131.  
  132. ;      Full rectangle in this single byte
  133. ;      set the right end of the mask as well
  134.  
  135.         mov     cx,px1
  136.         and     cx,07h      ;last bit position
  137.         sub     cx,7
  138.         neg     cx          ;number of bits empty to the right
  139.         shr     bx,cl
  140.         shl     bx,cl
  141.  
  142. full_left:
  143.         GR12_BITMASK bl     ; set the mask for the first strip
  144.  
  145.         mov     cx,py1      ;compute # of rasters lines to fill
  146.         sub     cx,py0
  147.         inc     cx          ;CX = (y1 - y0) + 1
  148.         mov     depth,cx    ;save the depth of the box
  149.         mov     bx,lBwide   ;constant to go to next raster
  150.         push    di          ;save the starting video byte
  151. loop1:
  152.         mov     ah,[di]     ;fetch the video byte
  153.         mov     [di],al     ;store new color through bit mask, saving old
  154.         add     di,bx       ;move on to next raster line
  155.         loop    loop1       ;loop while CX >=0
  156.  
  157.         pop     di          ;restore starting video byte addr
  158.         inc     di          ;move to next byte, one after what we filled
  159.  
  160.  
  161. ;  Here we work with only full bytes that are in the middle of the
  162. ;  the raster line
  163. ;
  164.         cmp     byte_rng,0  ;are there any middle bytes?
  165.         jl      end_process ;everything in lead byte - all done
  166.         jz      right_mask  ;just bits in trailing mask byte
  167.  
  168.                             ;middle full bytes
  169.  
  170.         mov     cx,byte_rng ;count of middle bytes
  171.  
  172.         GR12_BITMASK 0ffh   ; set the mask for full bytes
  173.  
  174.         mov     bx,depth
  175.         mov     dx,lBwide   ;constant to go to next raster
  176.         push    di          ;save the starting video byte
  177. loop2:
  178.         push    cx          ;save # of bytes to fill
  179.         push    di          ;save starting address
  180.  
  181.         rep     stosb       ; set CX bytes in this raster
  182.  
  183.         pop     di          ;get base addr back
  184.         add     di,dx       ;addr of next raster start
  185.         pop     cx          ;reset the byte count per line
  186.         dec     bx          ;one raster in depth
  187.         jg      loop2       ;more rasters to fill
  188.  
  189.         pop     di          ;base addressfor full rectangle
  190.         add     di,cx       ;add full bytes to start position
  191.  
  192.  
  193. ;------------------- FILL TRAILING PARTIAL BYTES -----------------------
  194. right_mask:
  195.  
  196.         mov     cx,px1      ;ending pixel
  197.         not     cx          ;invert bits
  198.         and     cx,07h      ;keep low 3 bits
  199.  
  200.         mov     bx,00ffh    ;figure right bit mask
  201.         rol     bx,cl       ;move mask to top of bl
  202.  
  203.  
  204.         GR12_BITMASK bl
  205.  
  206.         mov     cx,depth
  207.         mov     bx,lBwide   ;constant to go to next raster
  208. loop3:
  209.         mov     al,[di]     ;latch data - save beyong end of rect
  210.         mov     [di],al     ;set color through bitmask
  211.         add     di,bx       ;move to next raster
  212.         loop    loop3       ;while CX >0
  213.  
  214.         ;--- Restore PLANE ENABLE and BIT MASK registers
  215.  
  216. end_process:
  217.         GR12_BITMASK 0ffh   ;open all planes
  218.  
  219.         dec     dx          ;turn off SET/RESET
  220.         mov     al,1
  221.         out     dx,al
  222.         inc     dx
  223.         xor     ax,ax
  224.         out     dx,al
  225.  
  226. ;------------- CLEAN UP AND EXIT ------------------------------------------
  227.  
  228.         pop     es
  229.         pop     ds
  230.         pop     si
  231.         pop     di
  232.         popf
  233.         mov     sp,bp
  234.         pop     bp
  235.         ret
  236. _solid_box      endp
  237.