Hi,
I have a problem, it this code. It's 6 (realy 7) loops, one for briting up a text and one for darken a text. The problem occurs when running, at first, before "the 7th loop" (red text) was added, the first loop executed alright, but after it faded in the first text the text disapeared in black before appearing again (in full intensity) and fade away. After a few tests I tried to add "the 7th loop", then the first (and the second text) faded in and out , without the 'black hole syndrome' between them. But, between the 5th and 6th the 'black holw syndrom' apeared.

Why?!?!? :confused:

BTW I must have done something wrong when push-/poping, sine I had to add the "mov ebp,esp / push ebp" and "pop ebp / mov esp,ebp" to avoid Execption Access Violation.

BTW2 Any help optimizing this pice of #######-code would be apriciated



the_PROC PROC
mov ebp, esp
push ebp

[COLOR=red]
xor ecx, ecx
xor edi, edi
push ecx
$zhd: cmp ecx, 255
je SHORT $zdh
pop ecx
inc ecx
push ecx
jmp SHORT $zhd
$zdh: ; end for shade
$zdg: cmp ecx, -127
je SHORT $zgd
pop ecx
dec ecx
push ecx
jmp SHORT $zdg
$zgd: ; end for shade
push 2000
call Sleep
[/COLOR]

[B];[LOOP PAIR 1 START][/B]
xor ecx, ecx
xor edi, edi
push ecx
lea esi, szCOMP
$zhs: cmp ecx, 255 ;for (shade=0; shade < 256; shade++)
je SHORT $zsh
; draw text in shades
push lpddsprimary
add edi, 00000101h ; increase the "light" of the text.
push edi
push 240
push esi
call lstrlen
mov ebx, 320
shr eax, 2
sub ebx,eax
push ebx
push esi
call Draw_Text_GDIc
push 1
call Sleep
invoke GetAsyncKeyState,VK_ESCAPE ; is user trying to bail
shl ax, 1
jc $456
pop ecx
inc ecx
push ecx
jmp SHORT $zhs
$zsh: ; end for shade
push 2000
call Sleep
$zsg: cmp ecx, -127 ;<- -127 == 255 ] for (shade=0; shade < 256; shade++)
je SHORT $zgs
; draw text in shades
push lpddsprimary
sub edi, 00000101h
push edi
push 240
push esi
call lstrlen
mov ebx, 320
shr eax, 2
sub ebx,eax
push ebx
push esi
call Draw_Text_GDIc
push 1
call Sleep
invoke GetAsyncKeyState,VK_ESCAPE ; is user trying to bail
shl ax, 1
jc $456
pop ecx
dec ecx
push ecx
jmp SHORT $zsg
$zgs: ; end for shade
push 2000
call Sleep
[B];[LOOP PAIR 1 END][/B]

[B];[LOOP PAIR 2 START][/B]
xor ecx, ecx
xor edi, edi
push ecx
lea esi, szPRESENTS
$zhu: cmp ecx, 255 ;for (shade=0; shade < 256; shade++)
je SHORT $zuh
; draw text in shades
push lpddsprimary
add edi, 00010001h
push edi
push 240
push esi
call lstrlen
mov ebx, 320
shr eax, 2
sub ebx,eax
push ebx
push esi
call Draw_Text_GDIc
push 1
call Sleep
invoke GetAsyncKeyState,VK_ESCAPE ; is user trying to bail
shl ax, 1
jc $456
pop ecx
inc ecx
push ecx
jmp SHORT $zhu
$zuh: ; end for shade
push 2000
call Sleep
$zhg: cmp ecx, -127 ;<- -127 == 255 ] for (shade=0; shade < 256; shade++)
je SHORT $zgh
; draw text in shades
push lpddsprimary
sub edi, 00010001h
push edi
push 240
push esi
call lstrlen
mov ebx, 320
shr eax, 2
sub ebx,eax
push ebx
push esi
call Draw_Text_GDIc
push 1
call Sleep
invoke GetAsyncKeyState,VK_ESCAPE ; is user trying to bail
shl ax, 1
jc $456
pop ecx
dec ecx
push ecx
jmp SHORT $zhg
$zgh: ; end for shade
push 2000
call Sleep
[B];[LOOP PAIR 2 END][/B]

[B];[LOOP PAIR 3 START][/B]
xor ecx, ecx
xor edi, edi
lea esi, szGAME
$xhu: cmp ecx, 255 ;for (shade=0; shade < 256; shade++)
je SHORT $xuh
; draw text in shades
push lpddsprimary
add edi, 00010101h
push edi
push 240
push esi
call lstrlen
mov ebx, 320
shr eax, 2
sub ebx,eax
push ebx
push esi
call Draw_Text_GDIc
push 1
call Sleep
invoke GetAsyncKeyState,VK_ESCAPE ; is user trying to bail
shl ax, 1
jc $456
pop ecx
inc ecx
push ecx
jmp SHORT $xhu
$xuh: ; end for shade
push 2000
call Sleep
$xhg: cmp ecx, -127 ;<--127 == 255 ] for (shade=0; shade < 256; shade++)
je SHORT $xgh
; draw text in shades
push lpddsprimary
sub edi, 00010101h
push edi
push 240
push esi
call lstrlen
mov ebx, 320
shr eax, 2
sub ebx,eax
push ebx
push esi
call Draw_Text_GDIc
push 1
call Sleep
invoke GetAsyncKeyState,VK_ESCAPE ; is user trying to bail
shl ax, 1
jc $456
pop ecx
dec ecx
push ecx
jmp SHORT $xhg
$xgh: ; end for shade
pop ebp
mov esp, ebp
push 2000
call Sleep
[B];[LOOP PAIR 3 END][/B]
ret
$456: pop ebp
mov esp, ebp
ret
the_PROC ENDP
Posted on 2002-07-06 14:40:46 by scientica
you should push ebp
before mov ebp,esp


and in the end
just pop ebp

bye

eko
Posted on 2002-07-06 15:01:55 by eko

you should push ebp
before mov ebp,esp


and in the end
just pop ebp

bye

eko


eko, I tried that. But I only got an exception. And the 'black hole syndrome' presists.
I must admit I donnot realy understand the stack, just know that it's like a pile of plates <- a push (or pop) wrong and a plate smash.. :(
Posted on 2002-07-06 15:15:19 by scientica
Well, uh, there's no pointing in shoving EBP back and forth, when you don't use EBP. Also, you forgot a "POP ECX" after the "$456:"
Posted on 2002-07-06 15:57:19 by Sephiroth3
I'm not sure, but it looks like an inline C function called 3 times with different string pointers.
The function seems to do something like :



TheProc(sz, lpdd)
{
for (shade = 0, light = 0; shade < 256; shade++, light += 0x101)
{
Draw_Text_GDIc(szMemCOMP, 320-lstrlen
(szMemCOMP)/4, 240, light, lpddsprimary, shade)
Sleep(1);
}
Sleep(2000);
for (; shade >= 0; shade--, light -= 0x101)
{
Draw_Text_GDIc(szMemCOMP, 320-lstrlen
(szMemCOMP)/4, 240, light, lpddsprimary, shade)
Sleep(1);
// test GetAsync...
}
}


Some simple optimizations : if Draw_Text doesn't change the
string there is no need call lstrlen in each iteration.
Also the loops are very similar except for the shade and light
increment. The C code could become :


TheProc(sz, lpdd)
{
shade = 0;
light = 0;
delta_light = 0x101;
delta_shade = -1;
n = 320-lstrlen(szMemCOMP)/4;
Loop :
do
{
Draw_Text_GDIc(szMemCOMP, n, 240, light,
lpddsprimary, shade)
Sleep(1);
// test GetAsync...
light += delta_light;
shade += delta_shade;
} while (shade > 0 && shade < 256);
delta_light = -delta_light;
delta_shade = -delta_shade
if (delta_light < 0)
goto Loop
}


It could be translated to :


Func sz:DWORD, lp:DWORD

LOCAL n:DWORD
LOCAL shade:DWORD

push ebx
push edi
push esi

light TEXTEQU <ebx>
delta_light TEXTEQU <edi>
delta_shade TEXTEQU <esi>

;// init value
xor light, light
mov delta_light, 0101h
mov shade, light
mov delta_shade, 1

;// compute n = 320 - lstrlen(sz)/4
push sz
call lstrlen
mov n, 320
shr eax, 2
sub n, eax

;// start brightening loop
$zhs:

add shade, delta_shade
add light, delta_light

push shade
push 240
push lpdd
push light
push n
push sz
call Draw_Text_GDIc

push 1
call Sleep

invoke GetAsyncKeyState,VK_ESCAPE ; is user trying to bail
shl ax, 1
jnz $456

;// exit loop when shade == 256 or -1
test shade, 0100h
jz $zhs

push 2000
call Sleep

;// invert delta_light and delta_shade
neg delta_shade
neg delta_light

;// exit when delta_light becomes positive again
js $zhs

pop esi
pop edi
pop ebx

ret

Func ENDP
Posted on 2002-07-07 02:06:17 by Dr. Manhattan
I think I know why this syndrom appears, at least I found a cure.

My gues is that the 2 sec sleep (push 2000 / call sleep), didn't stop DX from uppdating the screen (I use dubble buffering), so I replaced it with a GetTickCount solution. And now it fades in and out smoothly.
Posted on 2002-07-07 12:28:56 by scientica