Can this be sped up, besides using MMX, 3DNOW, and other stuff which might be incompatible with other pc's?
DrawMap proc sprno:DWORD
LOCAL e:DWORD,f:DWORD
mov e,0
mov f,0
LT600:
mov e,0
LT800:
mov eax, [mapptr]
mov ecx, DWORD PTR [eax]
cmp ecx,0
je skipme
invoke Sprite2,sprno,e,f,ecx
skipme:
add mapptr,dword
mov eax,WND.tilex
add e,eax
mov ebx,WND.mapx
cmp e,ebx; 800
jl LT800
mov eax,WND.tiley
add f,eax
mov ebx,WND.mapy
cmp f,ebx; 600
jl LT600
ret
DrawMap endp
Maybe like this:
If WND.tilex, WND.mapx and WND.tiley are powers of 2, then it can be further optimized.
Have you made sure that Sprite2 is as fast as possible?
DrawMap:
push esi
push edi
push ebp
xor ebp,ebp
LT600:
xor edi,edi
LT800:
mov esi,mapptr
mov eax,[esi]
test eax,eax
jz skipme
invoke Sprite2,dword ptr [esp+28],edi,ebp,eax
skipme:
add edi,WND.tilex
add esi,4
cmp edi,WND.mapx
jl LT800
add ebp,WND.tiley
cmp ebp,WND.mapy
jl LT600
mov mapptr,esi
pop ebp
pop edi
pop esi
ret 4
If WND.tilex, WND.mapx and WND.tiley are powers of 2, then it can be further optimized.
Have you made sure that Sprite2 is as fast as possible?
Thanks, I'll try that, Sprite2 is below - using prebuilt masks and rectangles
for anyone who wants to use SHL/SHR and the powers of 2, below is a chart I use - maybe someone
should add it to their tutorial site?
To divide by 64:
SHR ecx,6
To multiply by 8:
SHL ecx,3
for anyone who wants to use SHL/SHR and the powers of 2, below is a chart I use - maybe someone
should add it to their tutorial site?
;1 2 4 8 16 32 64 128 256 512 1024
;0 1 2 3 4 5 6 7 8 9 10
To divide by 64:
SHR ecx,6
To multiply by 8:
SHL ecx,3
Sprite2 proc sprbnkno:DWORD, x:DWORD, y:DWORD, imgno:DWORD
LOCAL e:DWORD,f:DWORD,e2:DWORD,f2:DWORD
;this is straight-forward, no background saving at all
mov edx,SPRPTR
mov ecx,imgno
shl ecx,5 ;32 (5 dwords) is size of basic sprite rect and shouldn't have to change
mov ebx,sprbnkno
shl ebx,9 ;imul ebx,512 (9 dwords) - each block is 512, see heapallocate function
add ecx,ebx
m2m e,[edx+ecx].MSPR.SPX
m2m f,[edx+ecx].MSPR.SPY
m2m e2,[edx+ecx].MSPR.SXZ
m2m f2,[edx+ecx].MSPR.SYZ
mov ecx,sprbnkno
shl ecx,5 ;imul ecx, MAINBMPSZ ;MAINBMP SZ (sizeof..) = 32 DWORDS or 5
push ecx
invoke SelectObject,WND.maskDC,[MAINBMP.MSKBMP + ecx]
invoke BitBlt,WND.backDC,x,y,e2,f2,WND.maskDC,e,f,SRCPAINT
pop ecx
invoke SelectObject,WND.memDC,[MAINBMP.HBMP + ecx]
invoke BitBlt,WND.backDC,x,y,e2,f2,WND.memDC,e,f,SRCAND
ret
Sprite2 endp
I'm getting a crash on the second call into the Sprite2 function.. on this call:
m2m e,.MSPR.SPX
and why ret 4? returning value of 4 or something else?
m2m e,.MSPR.SPX
and why ret 4? returning value of 4 or something else?
DrawMapTest proc
push esi
push edi
push ebp
xor ebp,ebp
szText text1,"dibstuff",0
LT600:
xor edi,edi
LT800:
mov esi,mapptr
mov eax,[esi]
test eax,eax
jz skipme
pushad
invoke MessageBox,NULL,ADDR text1, ADDR text1,MB_OK
invoke Sprite2,dword ptr [esp+28],edi,ebp,eax
popad
skipme:
add edi,WND.tilex
add esi,4
cmp edi,WND.mapx
jl LT800
add ebp,WND.tiley
cmp ebp,WND.mapy
jl LT600
mov mapptr,esi
pop ebp
pop edi
pop esi
ret 4
DrawMapTest endp
Sorry, the "mov esi,mapptr" should have been right above "LT600:". In your code, you probably meant to put the popad right after the MessageBox call.
thanks but still crashing, moved popad to right place, it goes down on 5th messagebox display.