cgautils.asm
来自「开放源码的编译器open watcom 1.6.0版的源代码」· 汇编 代码 · 共 792 行 · 第 1/3 页
ASM
792 行
;*****************************************************************************
;*
;* Open Watcom Project
;*
;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
;*
;* ========================================================================
;*
;* This file contains Original Code and/or Modifications of Original
;* Code as defined in and that are subject to the Sybase Open Watcom
;* Public License version 1.0 (the 'License'). You may not use this file
;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
;* provided with the Original Code and Modifications, and is also
;* available at www.sybase.com/developer/opensource.
;*
;* The Original Code and all software distributed under the License are
;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
;* NON-INFRINGEMENT. Please see the License for the specific language
;* governing rights and limitations under the License.
;*
;* ========================================================================
;*
;* Description: Graphics library CGA specific code.
;*
;*****************************************************************************
include graph.inc
xref BitCopy
xref BitReplace
xref BitAnd
xref BitOr
xref BitXor
extrn __PlotAct : word
extrn __Transparent : word
modstart cgautils,WORD
xdefp _CoRep_
xdefp _CoXor_
xdefp _CoAnd_
xdefp _CoOr_
xdefp _MoveUp_
xdefp _MoveDown_
xdefp _Move1Left_
xdefp _Move2Left_
xdefp _Move1Right_
xdefp _Move2Right_
xdefp _Get1Dot_
xdefp _Get2Dot_
xdefp _Pix1Zap_
xdefp _Pix2Zap_
xdefp _Pix1Fill_
xdefp _Pix2Fill_
xdefp _Pix1Copy_
xdefp _Pix2Copy_
xdefp _Pix1Read_
xdefp _Pix2Read_
xdefp _CGAScanLeft_
xdefp _CGAScan1Right_
xdefp _CGAScan2Right_
;=========================================================================
;
; Plotting primitives
;
; Input ES:_EDI screen memory
; AL colour
; CH mask
;
;=========================================================================
db E_CoXor-_CoXor_
_CoXor_: ; xor in new pixel
xor es:0[_edi],al
E_CoXor:
ret
db E_CoAnd-_CoAnd_
_CoAnd_: ; and in new pixel
or al,ch ; mask on other bits
and es:0[_edi],al ; do and with memory
xor al,ch ; restore al
E_CoAnd:
ret
db E_CoRep-_CoRep_
_CoRep_: ; replace pixel
mov ah,es:[_edi] ; get current byte
and ah,ch ; mask out current colour
or ah,al ; OR in new colour
mov es:[_edi],ah ; replace byte
E_CoRep:
ret
db E_CoOr-_CoOr_
_CoOr_: ; or in new pixel
or es:0[_edi],al
E_CoOr:
ret
;=========================================================================
;
; Movement primitives
;
; Input ES:_EDI screen memory
; AL colour
; CH mask
;
; Output same altered as per move
;
;=========================================================================
db E_Move2Right-_Move2Right_
_Move2Right_: ; move right in m_edium-res mode
ror al,cl ; shift colour pattern to the right
ror ch,cl ; shift mask to the right
sbb _edi,-1 ; increment di if start of new byte
E_Move2Right:
ret ; return
db E_Move1Right-_Move1Right_
_Move1Right_: ; move right in high-res mode
ror al,1 ; shift colour pattern to the right
ror ch,1 ; shift mask to the right
sbb _edi,-1 ; move to next byte if it is time
E_Move1Right:
ret ; return
db E_Move2Left-_Move2Left_
_Move2Left_: ; move left in m_edium-res mode
rol al,cl ; shift colour pattern to the left
rol ch,cl ; shift mask to the left
adc _edi,-1 ; decrement di if start of new byte
E_Move2Left:
ret ; return
db E_Move1Left-_Move1Left_
_Move1Left_: ; move left in high-res mode
rol al,1 ; shift colour pattern to the left
rol ch,1 ; shift mask to the left
adc _edi,-1 ; move to next byte if it is time
E_Move1Left:
ret ; return
db E_MoveUp-_MoveUp_
_MoveUp_: ; move up 1 dot
ifdef __386__ ; can't use other method since with DOS4GW
push _ebx ; ... the segment is part of _EDI
mov bx,di
and bx,8000h ; keep high bit
and di,7fffh
endif
sub di,2000h ; assume di >= 2000h
_if b ; if di < 0
add di,2000h+2000h-80 ; add back 2000h + enough for next row
_endif ; endif
ifdef __386__
or di,bx
pop _ebx
endif
E_MoveUp:
ret ; return
db E_MoveDown-_MoveDown_
_MoveDown_: ; move down 1 dot
ifdef __386__ ; can't use other method since with DOS4GW
push _ebx ; ... the segment is part of _EDI
mov bx,di
and bx,8000h ; keep high bit
and di,7fffh
endif
sub di,2000h-80 ; assume di > $2000 (odd scan row)
_if b ; if not
add di,2000h-80+2000h ; compensate for mistake & add $2000
_endif ; endif
ifdef __386__
or di,bx
pop _ebx
endif
E_MoveDown:
ret ; return
;=========================================================================
;
; GetDot routines
;
; Input ES:_EDI screen memory
; CL bit position
;
; Output AX colour of pixel at location
;
;=========================================================================
_Get1Dot_:
mov al,es:[_edi] ; get byte
sub cl,7 ; shift byte by ( 7 - bit_position )
neg cl ; . . .
shr al,cl ; right align pixel
and al,1 ; keep only 1 bit (1 bit per pixel)
xor ah,ah ; clear high byte
ret
_Get2Dot_:
mov al,es:[_edi] ; get byte
sub cl,6 ; shift byte by ( 6 - bit_position )
neg cl ; . . .
shr al,cl ; right align pixel
and al,3 ; keep only 2 bits (2 bits per pixel)
xor ah,ah ; clear high byte
ret
;=========================================================================
;
; PixCopy routines
;
; Input ES:_EDI,DH screen memory
; SI:_EAX,DL buffer to copy from
; CX number of pixels to copy
;
;=========================================================================
_Pix2Copy_:
shl _ecx,1 ; # bits = 2 * # pixels
_Pix1Copy_:
push ds ; save DS
mov ds,si ; get SI:AX into DS:SI
mov _esi,_eax
docall SetupAction
docall BitCopy
docall BitReplace
pop ds
ret
;=========================================================================
;
; ReadRow routines
;
; Input ES:_EDI buffer to copy into
; SI:_EAX,DL screen memory
; CX number of pixels to copy
;
;=========================================================================
_Pix2Read_:
shl _ecx,1
_Pix1Read_:
push ds ; save DS
mov ds,si ; get SI:AX into DS:SI
mov _esi,_eax
docall BitCopy
pop ds
ret
ifdef __386__
PlotJmp dd BitReplace,BitXor,BitAnd,BitOr
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?