home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-386-Vol-2of3.iso / b / bgi256-3.zip / SBIT.INC < prev    next >
Text File  |  1992-12-27  |  9KB  |  308 lines

  1. ;SBIT.INC - Copyright 1991,1992 Knight Software
  2. ;  History:
  3. ;     17 May 1991 - First release 
  4. ;     22 Nov 1992 - Adapted for protected mode
  5. ;     15 Dec 1992 - Fixed bug in WriteLineFill 
  6. ;                    non-pattern fill was always doing MoveWrite
  7. ;
  8. ;-----------------------------------------------------------
  9. ;Assume:  DS = data segment
  10. ;Entry:   DX = Count - number bytes to write
  11. ;Return:  N/A
  12. ;Destroy: None
  13.  
  14. WriteClear PROC  NEAR
  15.     OR    DX,DX             ;if nothing to write stop this
  16.     JNZ    @WriteClearEnter
  17.     RET
  18.  
  19. @WriteClearEnter:
  20.     PUSH    ES
  21.     PUSH    DI
  22.     PUSH    CX
  23.     PUSH    AX
  24.     MOV    ES,DS:[VideoSegment] ;video is at segment 0a000h
  25.     MOV    DI,DS:[PixelAddress] ;destination offset address
  26.     MOV    AL,DS:[InitColor]    ;preload init color
  27.     MOV    CX,DX             ;copy length in bytes to CX
  28.     SHR    CX,1             ;and convert to words
  29.     JNC    @WriteClearEven      ;if odd count do the odd byte
  30.     STOSB                 ;ES:DI = dest array          
  31.     JZ    @WriteClearDone      ;nothing else to write if done
  32. @WriteClearEven:
  33.     MOV    AH,AL             ;extend color for word write
  34.     REP    STOSW             ;fast write to the screen
  35. @WriteClearDone:
  36.     POP    AX
  37.     POP    CX
  38.     POP    DI
  39.     POP    ES
  40.     RET
  41. WriteClear ENDP
  42.  
  43. ;-----------------------------------------------------------
  44. ;Assume:  DS       = data segment
  45. ;Entry:   DX       = Count - number bytes to write
  46. ;         [PixelX] = offset into scan line to fill (X)
  47. ;         [PixelY] = scan line to fill (Y)
  48. ;Return:  N/A
  49. ;Destroy: None
  50.  
  51. WriteFillLine PROC  NEAR
  52.     OR    DX,DX             ;if nothing to write stop this
  53.     JNZ    @WriteFillLineEnter
  54.     RET
  55.  
  56. @WriteFillLineEnter:
  57.     PUSH    DS
  58.     PUSH    ES
  59.     PUSH    SI
  60.     PUSH    DI
  61.     PUSH    DX
  62.     PUSH    CX
  63.     PUSH    BX
  64.     PUSH    AX
  65.  
  66.     MOV    ES,DS:[VideoSegment]  ;video is at segment 0a000h
  67.     MOV    DI,DS:[PixelAddress]  ;destination offset address
  68.     LEA    SI,FillPattern        ;point to fill pattern table
  69.     MOV    AX,DS:[PixelY]
  70.     AND    AX,07H
  71.     ADD    SI,AX              ;can we do it fast?
  72.     MOV    AL,DS:[FillForeColor] ;preload foreground color
  73.     MOV    AH,DS:[FillBackColor] ;preload background color
  74.  
  75.     MOV    CL,DS:[FillPixelWriteMode] ;preload fill write mode
  76.     TEST    CL,03H              ;not a fast type fill
  77.     JNZ    @WriteSlowFillLine    ;so we gotta do it the slow way
  78.     MOV    CH,DS:[SI]          ;get pattern to use
  79.     INC    CH              ;if pattern = 0FFH, do fast
  80.     JZ    @WriteForeFastFillLine
  81.     DEC    CH              ;if pattern = 00H, do fast
  82.     JZ    @WriteBackFastFillLine;if not fast pattern, do it slow
  83.  
  84. @WriteSlowFillLine:
  85.     MOV    CX,DS:[PixelX]          ;gotta do it slow 
  86.     MOV    CH,8              ;get PixelX location
  87.     AND    CL,07H              ;and sync pattern to it
  88.     SUB    CH,CL
  89.     MOV    BL,DS:[SI]
  90.     SHL    BL,CL
  91.     MOV    CL,BL              ;copy pattern to CL
  92. ;    MOV    AL,DS:[FillForeColor] ;preload foreground color
  93. ;    MOV    AH,DS:[FillBackColor] ;preload background color
  94.     MOV    BX,DS:[FillPixelProc] ;load pixel calling routine
  95.  
  96. @WriteAltFillLineLp:
  97.     TEST    CL,80H              ;set flags for call
  98.     CALL    BX              ;via table proc pointer
  99.     INC    DI              ;and loop till done
  100.     DEC    DX
  101.     JZ    @WriteFillLineDone
  102.     SHL    CL,1
  103.     DEC    CH              ;do next pattern bit
  104.     JNZ    @WriteAltFillLineLp
  105.     MOV    CL,DS:[SI]          ;reload pattern byte
  106.     MOV    CH,8              ;and count length
  107.     JMP    SHORT @WriteAltFillLineLp ;and do again
  108.  
  109. @WriteForeFastFillLine:           ;AH:AL has color to write
  110.     TEST    CL,04H
  111.     JZ    @WriteForeFastFill2
  112.     NOT    AL           ;invert color if NOT write
  113. @WriteForeFastFill2:
  114.     TEST    CL,10H           ;ok to write foreground?
  115.     JZ    @WriteFastFillLine ;yes, go do it
  116.     JMP    @WriteFillLineDone ;nope, so nothing to do
  117.  
  118. @WriteBackFastFillLine:           ;AH:AL has color to write
  119.     TEST    CL,04H
  120.     JZ    @WriteBackFastFill2
  121.     NOT    AH           ;invert color if NOT write
  122. @WriteBackFastFill2:
  123.     MOV    AL,AH           ;we will be writing back color
  124.     TEST    CL,08H           ;ok to write background?
  125.     JZ    @WriteFastFillLine ;yes, go do it
  126.     JMP    @WriteFillLineDone ;nope, so do nothing
  127.  
  128. @WriteFastFillLine:
  129.     MOV    CX,DX           ;copy length in bytes to CX
  130.     SHR    CX,1           ;and convert to words
  131.     JNC    @WriteFillLineEven ;if odd count do the odd byte
  132.     STOSB               ;ES:DI = dest array          
  133.     JZ    @WriteFillLineDone ;nothing else to write if done
  134. @WriteFillLineEven:
  135.     MOV    AH,AL           ;extend color for word write
  136.     REP    STOSW           ;fast fill write to the screen
  137. @WriteFillLineDone:
  138.     POP    AX
  139.     POP    BX
  140.     POP    CX
  141.     POP    DX
  142.     POP    DI
  143.     POP    SI
  144.     POP    ES
  145.     POP    DS
  146.     RET
  147. WriteFillLine ENDP
  148.  
  149. ;-----------------------------------------------------------
  150. ;Assume:   DS    = data segment
  151. ;Entry:    DX    = Count - number bytes to read
  152. ;       ES:SI = Pointer to cpu memory 
  153. ;Return:   N/A
  154. ;Destorys: None
  155.  
  156. ReadBitMap PROC  NEAR
  157.     OR    DX,DX
  158.     JNZ    @ReadBitMapEnter     ;if nothing to read stop this
  159.     RET
  160.  
  161. @ReadBitMapEnter:
  162.     PUSH    DS
  163.     PUSH    SI
  164.     PUSH    DI
  165.     PUSH    CX
  166.     MOV    CX,DX
  167.     MOV    DI,SI
  168.     MOV    SI,DS:[PixelAddress] ;DS:SI = source array
  169.     MOV    DS,DS:[VideoSegment] ;video is at segment 0a000h
  170.     SHR    CX,1             ;ES:DI = dest array
  171.     JNC    @ReadBitMapEven
  172.     MOVSB                 ;if odd count do the odd byte
  173.     JZ    @ReadBitMapDone         ;nothing else to draw if done
  174. @ReadBitMapEven:
  175.     REP    MOVSW             ;read it from the screen
  176. @ReadBitMapDone:
  177.     POP    CX
  178.     POP    DI
  179.     POP    SI
  180.     POP    DS
  181.     RET
  182. ReadBitMap ENDP
  183.  
  184. ;-----------------------------------------------------------
  185. ;Assume: DS    = data segment
  186. ;Entry:  DX    = Count - number bytes to write
  187. ;     ES:SI = Pointer to cpu memory 
  188.  
  189. WriteBitMap PROC  NEAR
  190.     OR    DX,DX
  191.     JNZ    @WriteBitMapEnter       ;if nothing to write stop this
  192.     RET
  193.  
  194. @WriteBitMapEnter:
  195.     PUSH    DS
  196.     PUSH    ES
  197.     PUSH    SI
  198.     PUSH    DI
  199.     PUSH    DX
  200.     PUSH    CX
  201.     PUSH    BX
  202.     PUSH    AX
  203.     MOV    CX,DX
  204.     MOV    AL,DS:[BitMapPixelWriteMode]
  205.     MOV    AH,DS:[BitMapBackColor]  ;preload background color
  206.     MOV    BX,DS:[BitMapPixelProc]
  207.     MOV    DI,DS:[PixelAddress]     ;destination offset address
  208.     PUSH    AX
  209.     MOV    AX,ES
  210.     MOV    ES,DS:[VideoSegment]     ;video is at segment 0a000h
  211.     MOV    DS,AX                 ;DS:SI = source array
  212.     POP    AX
  213.     OR    AL,AL
  214.     JZ    @WriteBitMapFast         ;if mode zero, use fast move
  215. @WriteAltBitMapLp:
  216.     MOV    AL,DS:[SI]      ;get next pixel from buffer
  217.     CMP    AL,AH          ;is this bitmap background color?
  218.     CALL    BX          ;if other style write mode (ES:DI^)
  219.     INC    SI          ;use long call process
  220.     INC    DI          ;via table proc pointer
  221.     LOOP    @WriteAltBitMapLp ;loop til done
  222.     JMP    SHORT @WriteBitMapDone
  223. @WriteBitMapFast:
  224.     SHR    CX,1         ;ES:DI = dest array
  225.     JNC    @WriteBitMapEven ;DS:SI = source array
  226.     MOVSB             ;if odd count do the odd byte
  227.     JZ    @WriteBitMapDone ;if nothing else to write all done
  228. @WriteBitMapEven:
  229.     REP    MOVSW        ;fast block write to the screen
  230. @WriteBitMapDone:
  231.     POP    AX
  232.     POP    BX
  233.     POP    CX
  234.     POP    DX
  235.     POP    DI
  236.     POP    SI
  237.     POP    ES
  238.     POP    DS
  239.     RET
  240. WriteBitMap  ENDP
  241.  
  242. ;-------------------------------------------------------
  243. ;Bit map read/write entry code
  244. ;BitMapProc ptr = pointer to read/write procedure to call
  245. ;To write blockfill, call as: LEA DI,WriteFillLine; CALL DoBitMap
  246. ;To write bit map, call as:   LEA DI,WriteBitMap;   CALL DoBitMap
  247. ;To read bit map, call as:    LEA DI,ReadBitMap;    CALL DoBitMap
  248. ;To clear bit map, call as:   LEA DI,WriteClear;    CALL DoBitMap
  249. ;Assume:   DS    = data segment
  250. ;Enter:    ES:SI = cpu memory pointer (not needed for WriteFillLine)
  251. ;       DS:DI = operation procedure pointer
  252. ;          CX    = start X location
  253. ;          DX    = start Y location
  254. ;          AX    = image width (x size)
  255. ;          BX    = image height (y size)
  256. ;Return:   N/A
  257. ;Destroys: None
  258.  
  259. DoBitMap PROC NEAR
  260.     PUSH    ES
  261.     PUSH    DI
  262.     PUSH    SI
  263.     PUSH    DX
  264.     PUSH    CX
  265.     PUSH    BX
  266.     PUSH    AX
  267.  
  268.     MOV    DS:[BitMapProc],DI ;save proc ptr
  269.     MOV    DS:[PixelX2],AX
  270.     MOV    DS:[PixelX1],CX       ;CX= PixelX1
  271.     MOV    DI,DX           ;DI= PixelY1
  272.     MOV    CX,BX
  273.  
  274. @DoBitMapLp:
  275.     MOV    DS:[PixelY],DI           ;get this scan line #
  276.     MOV    AX,DS:[PixelX1]
  277.     MOV    DS:[PixelX],AX              ;start at left edge 
  278.  
  279.     MOV    DX,DS:[PixelX2]
  280.     CALL    GetPixelAddress           ;locate the start adr
  281.     CMP    DX,DS:[PixelSegmentLength] ;if larger than segment
  282.     JC     @SingleBitScan           ;split the scan line op
  283.     MOV    DX,DS:[PixelSegmentLength] ;do the first part
  284.     CALL    WORD PTR DS:[BitMapProc]   ;of the scan line
  285.     MOV    AX,DS:[PixelSegmentLength] ;start where we left off
  286.     ADD    DS:[PixelX],AX           ;on the screen
  287.     MOV    DX,DS:[PixelX2]           ;reduce count by previous
  288.     SUB    DX,AX               ;amount processed
  289.     ADD    SI,AX               ;adj cpu memory pointer
  290.     CALL    GetPixelAddress           ;get the new start adr
  291. @SingleBitScan:
  292.     CALL    WORD PTR DS:[BitMapProc]   ;process the scan line
  293.     ADD    SI,DX                   ;adj cpu memory pointer
  294.     INC    DI               ;adj PixelY pointer
  295.     LOOP    @DoBitMapLp           ;loop til all are done
  296.  
  297.     POP    AX
  298.     POP    BX
  299.     POP    CX
  300.     POP    DX
  301.     POP    SI
  302.     POP    DI
  303.     POP    ES
  304.     RET
  305. DoBitMap ENDP
  306.  
  307.  
  308.