📄 bitmaps.asm
字号:
include ..\cwlib.inc
scode
;-------------------------------------------------------------------------
;
;Blit a bitmap into another bitmap.
;
;On Entry:
;
;C style stack parameters as follows:
;
;Flags - Flags, bit significant if set, may be combined.
; 0-Reserved.
; 1-OR the bitmap, "Chroma" contains transparent colour.
; 2-Scaled blit, DWide & DDepth contain destination sizes.
;SBitmap -Pointer to source bitmap.
;DBitmap -Pointer to destination bitmap.
;XCoord -X co-ord in destination to blit to.
;YCoord -Y co-ord in destination to blit to.
;XOff -X offset within source to blit from.
;YOff -Y offset within source to blit from.
;Wide -Width to blit, -1 for entire source width.
;Depth -Depth to blit, -1 for entire destination width.
;DWide -Destination width of blit when scaleing.
;DDepth -Destination depth of blit when scaleing.
;Chroma -Transparent colour when OR'ing.
;
;On Exit:
;
;ALL registers preserved.
;
BitmapBlitBitmap:
_BitmapBlitBitmap proc syscall flags:dword, SBitmap:dword, DBitmap:dword, \
XCoord:dword, YCoord:dword, XOff:dword, YOff:dword, \
Wide:dword, Depth:dword, DWide:dword, DDepth:dword, \
Chroma:dword
pushm _BBB_Source, _BBB_Dest, _BBB_Chroma
pushad
;
mov eax,Chroma
mov _BBB_Chroma,eax
;
mov esi,SBitmap
cmp Wide,-1
jnz @@8
mov eax,BM_Wide[esi]
mov Wide,eax
@@8: cmp Depth,-1
jnz @@9
mov eax,BM_Depth[esi]
mov Depth,eax
;
;Check for daft width/depth.
;
@@9: cmp Wide,0
js @@BlitFinished
jz @@BlitFinished
cmp Depth,0
js @@BlitFinished
jz @@BlitFinished
;
;Clip offsets/width/depth to fit bitmap.
;
cmp XOff,0
jns @@0
mov eax,XOff
neg eax
sub Wide,eax
js @@BlitFinished
jz @@BlitFinished
add XCoord,eax
mov XOff,0
;
@@0: cmp YOff,0
jns @@1
mov eax,YOff
neg eax
sub Depth,eax
js @@BlitFinished
jz @@BlitFinished
add YCoord,eax
mov YOff,0
;
@@1: mov eax,XOff
add eax,Wide
cmp eax,BM_Wide[esi]
jl @@2
sub eax,BM_Wide[esi]
sub Wide,eax
js @@BlitFinished
jz @@BlitFinished
;
@@2: mov eax,YOff
add eax,Depth
cmp eax,BM_Depth[esi]
jl @@3
sub eax,BM_Depth[esi]
sub Depth,eax
js @@BlitFinished
jz @@BlitFinished
;
;If scaleing, work out scale values needed.
;
@@3: test Flags,4
jz @@11
mov eax,Wide
shl eax,16
xor edx,edx
mov ebx,DWide
div ebx
movzx edx,ax
shl edx,16
mov _BBB_wfrac,edx
shr eax,16
mov _BBB_wwhole,eax
;
mov eax,Depth
shl eax,16
xor edx,edx
mov ebx,DDepth
div ebx
movzx edx,ax
shl edx,16
mov _BBB_dfrac,edx
shr eax,16
mov _BBB_dwhole,eax
;
mov _BBB_dacc,0
;
;Clip coords/width/depth to fit the destination.
;
@@11: mov edi,DBitmap
cmp XCoord,0
jns @@4
mov eax,XCoord
neg eax
test Flags,4
jz @@3_0
sub DWide,eax
jmp @@3_1
@@3_0: sub Wide,eax
@@3_1: js @@BlitFinished
jz @@BlitFinished
add XOff,eax
mov XCoord,0
;
@@4: cmp YCoord,0
jns @@5
mov eax,YCoord
neg eax
test Flags,4
jz @@4_0
sub DDepth,eax
jmp @@4_1
@@4_0: sub Depth,eax
@@4_1: js @@BlitFinished
jz @@BlitFinished
add YOff,eax
mov YCoord,0
;
@@5: test Flags,4
jz @@5_0
mov eax,XCoord
add eax,DWide
cmp eax,BM_Wide[edi]
jl @@6
sub eax,BM_Wide[edi]
sub DWide,eax
js @@BlitFinished
jz @@BlitFinished
jmp @@6
@@5_0: mov eax,XCoord
add eax,Wide
cmp eax,BM_Wide[edi]
jl @@6
sub eax,BM_Wide[edi]
sub Wide,eax
js @@BlitFinished
jz @@BlitFinished
;
@@6: test Flags,4
jz @@6_0
mov eax,YCoord
add eax,DDepth
cmp eax,BM_Depth[edi]
jl @@7
sub eax,BM_Depth[edi]
sub DDepth,eax
js @@BlitFinished
jz @@BlitFinished
jmp @@7
@@6_0: mov eax,YCoord
add eax,Depth
cmp eax,BM_Depth[edi]
jl @@7
sub eax,BM_Depth[edi]
sub Depth,eax
js @@BlitFinished
jz @@BlitFinished
;
;Now work out the source address and width.
;
@@7: mov eax,esi
add eax,size BM
mov _BBB_Source,eax
mov eax,YOff
mul BM_PWide[esi]
mul BM_Wide[esi]
add _BBB_Source,eax
mov eax,XOff
mul BM_PWide[esi]
add _BBB_Source,eax
;
;Work out the destination address.
;
mov eax,edi
add eax,size BM
mov _BBB_Dest,eax
mov eax,YCoord
mul BM_PWide[edi]
mul BM_Wide[edi]
add _BBB_Dest,eax
mov eax,XCoord
mul BM_PWide[edi]
add _BBB_Dest,eax
;
;Get on with it.
;
mov ebx,SBitmap
mov eax,BM_Flags[edi]
and eax,15
mov esi,_BBB_Source
mov edi,_BBB_Dest
mov ecx,Wide
mov edx,Depth
test Flags,4
jz @@Put
;
;Put it on with scaleing.
;
push eax
mov ebx,SBitmap
mov eax,BM_PWide[ebx]
mul BM_Wide[ebx]
mov ebx,eax
pop eax
mov ecx,DWide
mov edx,DDepth
@@Puts0: push edx
push eax
pushm esi,edi,ebx,ecx
mov ebx,SBitmap
test Flags,2
jnz @@Puts1
call [PutScaleRoutines+eax*4]
jmp @@Puts2
@@Puts1: call [PutORScaleRoutines+eax*4]
@@Puts2: mov edi,DBitmap
mov eax,BM_PWide[edi]
mul BM_Wide[edi]
popm esi,edi,ebx,ecx
add edi,eax
mov eax,_BBB_dfrac
add _BBB_dacc,eax
mov eax,0
adc eax,_BBB_dwhole
mul ebx
add esi,eax
pop eax
pop edx
dec edx
jnz @@Puts0
jmp @@BlitFinished
;
;Put it on as normal.
;
@@Put: push ebp
test Flags,2
mov ebp,DBitmap
jnz @@PutOR
call [PutRoutines+eax*4]
pop ebp
jmp @@BlitFinished
;
;Or it on.
;
@@PutOR: call [PutORRoutines+eax*4]
pop ebp
@@BlitFinished: ;
popad
popm _BBB_Source, _BBB_Dest, _BBB_Chroma
ret
_BitmapBlitBitmap endp
;-------------------------------------------------------------------------
PutBitmap256 proc near
mov eax,BM_Flags[ebx]
and eax,15
jz @@256
dec eax
jz @@32k
dec eax
jz @@64k
dec eax
jz @@16m
jmp @@9
;
;256 to 256 blit.
;
@@256: mov ebx,BM_Wide[ebx]
mov ebp,BM_Wide[ebp]
@@256_0: pushm ecx,esi,edi
rep_movsb
popm ecx,esi,edi
add esi,ebx
add edi,ebp
dec edx
jnz @@256_0
jmp @@9
;
;32k to 256 blit.
;
@@32k: mov ebx,BM_Wide[ebx]
mov ebp,BM_Wide[ebp]
shl ebx,1
@@32k_0: pushm ebx,ecx,esi,edi
@@32k_1: lodsw
mov ebx,eax
shl ebx,16+1
shld eax,ebx,5
shl eax,3
shl ebx,5
shld eax,ebx,5
shl eax,3
shl ebx,5
shld eax,ebx,5
shl eax,3
call SearchRGB
stosb
loop @@32k_1
popm ebx,ecx,esi,edi
add esi,ebx
add edi,ebp
dec edx
jnz @@32k_0
jmp @@9
;
;64k to 256 blit.
;
@@64k: mov ebx,BM_Wide[ebx]
mov ebp,BM_Wide[ebp]
shl ebx,1
@@64k_0: pushm ebx,ecx,esi,edi
@@64k_1: lodsw
mov ebx,eax
shl ebx,16
shld eax,ebx,5
shl eax,3
shl ebx,5
shld eax,ebx,6
shl eax,2
shl ebx,6
shld eax,ebx,5
shl eax,3
call SearchRGB
stosb
loop @@64k_1
popm ebx,ecx,esi,edi
add esi,ebx
add edi,ebp
dec edx
jnz @@64k_0
jmp @@9
;
;16m to 256 blit.
;
@@16m: mov ebx,BM_Wide[ebx]
mov ebp,BM_Wide[ebp]
mov eax,ebx
shl ebx,1
add ebx,eax
@@16m_0: pushm ecx,esi,edi
@@16m_1: mov eax,[esi]
add esi,3
and eax,0FFFFFFh
call SearchRGB
stosb
loop @@16m_1
popm ecx,esi,edi
add esi,ebx
add edi,ebp
dec edx
jnz @@16m_0
;
@@9: ret
PutBitmap256 endp
;-------------------------------------------------------------------------
PutBitmap32k proc near
mov eax,BM_Flags[ebx]
and eax,15
jz @@256
dec eax
jz @@32k
dec eax
jz @@64k
dec eax
jz @@16m
jmp @@9
;
;256 to 32k blit.
;
@@256: mov ebx,BM_Wide[ebx]
mov ebp,BM_Wide[ebp]
shl ebp,1
@@256_0: pushm ebx,ecx,esi,edi
@@256_1: xor eax,eax
lodsb
mov eax,d[HardwarePalette+eax+eax*2]
mov bl,al
shr eax,8
xchg ah,bl
shl eax,8
mov al,bl
mov ebx,eax
shl ebx,2+8 ;Convert 0-63 value to 0-255 value.
xor eax,eax
shld eax,ebx,5
shl ebx,8
shld eax,ebx,5
shl ebx,8
shld eax,ebx,5
stosw
loop @@256_1
popm ebx,ecx,esi,edi
add esi,ebx
add edi,ebp
dec edx
jnz @@256_0
jmp @@9
;
;32k to 32k blit.
;
@@32k: mov ebx,BM_Wide[ebx]
shl ebx,1
mov ebp,BM_Wide[ebp]
shl ebp,1
@@32k_0: pushm ecx,esi,edi
rep_movsw
popm ecx,esi,edi
add esi,ebx
add edi,ebp
dec edx
jnz @@32k_0
jmp @@9
;
;64k to 32k blit.
;
@@64k: mov ebx,BM_Wide[ebx]
shl ebx,1
mov ebp,BM_Wide[ebp]
shl ebp,1
@@64k_0: pushm ebx,ecx,esi,edi
@@64k_1: lodsw
movzx ebx,ax
xor eax,eax
shl ebx,16
shld eax,ebx,5
shl ebx,5
shld eax,ebx,5
shl ebx,6
shld eax,ebx,5
stosw
loop @@64k_1
popm ebx,ecx,esi,edi
add esi,ebx
add edi,ebp
dec edx
jnz @@64k_0
jmp @@9
;
;16m to 32k blit.
;
@@16m: mov ebx,BM_Wide[ebx]
mov eax,ebx
shl ebx,1
add ebx,eax
mov ebp,BM_Wide[ebp]
shl ebp,1
@@16m_0: pushm ebx,ecx,esi,edi
@@16m_1: lodsd
dec esi
shl eax,8
mov ebx,eax
xor eax,eax
shld eax,ebx,5
shl ebx,8
shld eax,ebx,5
shl ebx,8
shld eax,ebx,5
stosw
loop @@16m_1
popm ebx,ecx,esi,edi
add esi,ebx
add edi,ebp
dec edx
jnz @@16m_0
;
@@9: ret
PutBitmap32k endp
;-------------------------------------------------------------------------
PutBitmap64k proc near
mov eax,BM_Flags[ebx]
and eax,15
jz @@256
dec eax
jz @@32k
dec eax
jz @@64k
dec eax
jz @@16m
jmp @@9
;
;256 to 64k blit.
;
@@256: mov ebx,BM_Wide[ebx]
mov ebp,BM_Wide[ebp]
shl ebp,1
@@256_0: pushm ebx,ecx,esi,edi
@@256_1: xor eax,eax
lodsb
mov eax,d[HardwarePalette+eax+eax*2]
shl eax,2
mov bl,al
shr eax,8
xchg ah,bl
shl eax,8
mov al,bl
mov ebx,eax
shl ebx,8
xor eax,eax
shld eax,ebx,5
shl ebx,8
shld eax,ebx,6
shl ebx,8
shld eax,ebx,5
stosw
loop @@256_1
popm ebx,ecx,esi,edi
add esi,ebx
add edi,ebp
dec edx
jnz @@256_0
jmp @@9
;
;32k to 64k blit.
;
@@32k: mov ebx,BM_Wide[ebx]
shl ebx,1
mov ebp,BM_Wide[ebp]
shl ebp,1
@@32k_0: pushm ebx,ecx,esi,edi
@@32k_1: lodsw
movzx ebx,ax
xor eax,eax
shl ebx,16+1
shld eax,ebx,5
shl ebx,5
shld eax,ebx,5
shl eax,1
shl ebx,5
shld eax,ebx,5
stosw
loop @@32k_1
popm ebx,ecx,esi,edi
add esi,ebx
add edi,ebp
dec edx
jnz @@32k_0
jmp @@9
;
;64k to 64k blit.
;
@@64k: mov ebx,BM_Wide[ebx]
shl ebx,1
mov ebp,BM_Wide[ebp]
shl ebp,1
@@64k_0: pushm ecx,esi,edi
rep_movsw
popm ecx,esi,edi
add esi,ebx
add edi,ebp
dec edx
jnz @@64k_0
jmp @@9
;
;16m to 64k blit.
;
@@16m: mov ebx,BM_Wide[ebx]
mov eax,ebx
shl ebx,1
add ebx,eax
mov ebp,BM_Wide[ebp]
shl ebp,1
@@16m_0: pushm ebx,ecx,esi,edi
@@16m_1: lodsd
dec esi
shl eax,8
mov ebx,eax
xor eax,eax
shld eax,ebx,5
shl ebx,8
shld eax,ebx,6
shl ebx,8
shld eax,ebx,5
stosw
loop @@16m_1
popm ebx,ecx,esi,edi
add esi,ebx
add edi,ebp
dec edx
jnz @@16m_0
;
@@9: ret
PutBitmap64k endp
;-------------------------------------------------------------------------
PutBitmap16m proc near
mov eax,BM_Flags[ebx]
and eax,15
jz @@256
dec eax
jz @@32k
dec eax
jz @@64k
dec eax
jz @@16m
jmp @@9
;
;256 to 16m blit.
;
@@256: mov ebx,BM_Wide[ebx]
mov ebp,BM_Wide[ebp]
mov eax,ebp
shl ebp,1
add ebp,eax
@@256_0: pushm ebx,ecx,esi,edi
@@256_1: lodsb
movzx eax,al
mov eax,d[HardwarePalette+eax][eax*2]
shl eax,2
mov bl,al
shr eax,8
xchg ah,bl
shl eax,8
mov al,bl
stosw
shr eax,16
stosb
loop @@256_1
popm ebx,ecx,esi,edi
add esi,ebx
add edi,ebp
dec edx
jnz @@256_0
jmp @@9
;
;32k to 16m blit.
;
@@32k: mov ebx,BM_Wide[ebx]
shl ebx,1
mov ebp,BM_Wide[ebp]
mov eax,ebp
shl ebp,1
add ebp,eax
@@32k_0: pushm ebx,ecx,esi,edi
@@32k_1: lodsw
movzx ebx,ax
shl ebx,1+16
xor eax,eax
shld eax,ebx,5
shl eax,3
shl ebx,5
shld eax,ebx,5
shl eax,3
shl ebx,5
shld eax,ebx,5
shl eax,3
stosw
shr eax,16
stosb
loop @@32k_1
popm ebx,ecx,esi,edi
add esi,ebx
add edi,ebp
dec edx
jnz @@32k_0
jmp @@9
;
;64k to 16m blit.
;
@@64k: mov ebx,BM_Wide[ebx]
shl ebx,1
mov ebp,BM_Wide[ebp]
mov eax,ebp
shl ebp,1
add ebp,eax
@@64k_0: pushm ebx,ecx,esi,edi
@@64k_1: lodsw
movzx ebx,ax
xor eax,eax
shl ebx,16
shld eax,ebx,5
shl eax,3
shl ebx,5
shld eax,ebx,6
shl eax,2
shl ebx,6
shld eax,ebx,5
shl eax,3
stosw
shr eax,16
stosb
loop @@64k_1
popm ebx,ecx,esi,edi
add esi,ebx
add edi,ebp
dec edx
jnz @@64k_0
jmp @@9
;
;16m to 16m blit.
;
@@16m: mov ebx,BM_Wide[ebx]
mov eax,ebx
shl ebx,1
add ebx,eax
mov ebp,BM_Wide[ebp]
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -