CheckMem proc min:DWORD
LOCAL memsize:DWORD, textlen:DWORD
cmp min, 100
jg @F
mov min, 100
@@:
mov eax, MemStart
sub CurrentPos, eax <<<<<<<<<<<<<
sub TxtEnd, eax
mov eax, TxtEnd
add eax, min
cmp eax, MemEnd
jl @F
push eax
invoke MessageBox, hwnd, ADDR StrReAlloc, ADDR sPad, 0
pop eax
mov eax, MemEnd
sub eax, MemPtr
mov memsize, eax
add memsize, ALLOCSIZE
invoke HeapReAlloc,heap,HEAP_ZERO_MEMORY or HEAP_NO_SERIALIZE,MemPtr,memsize
mov MemPtr, eax
add eax, 30
mov MemStart, eax
add CurrentPos, eax
add TxtEnd, eax
add eax, memsize
sub eax, 30
mov MemEnd, eax
@@:
ret
CheckMem endp

This proc is suppose to check if I have enough memory and if not, it allocate some more space.
The problem is that it fucks up here : <<<<<<<<
I don't even know how this line can be wrong ???
I need help here !

(s)
Posted on 2001-07-27 13:26:32 by (scalp)
It a bit strange what goes on here. Is MemEnd an offset to the end of the memory or is it just the lenght. If its an offset then this code won't work as the following
mov eax, MemStart
sub CurrentPos, eax <<<<<<<<<<<<<
sub TxtEnd, eax
mov eax, TxtEnd
add eax, min
cmp eax, MemEnd
will result in eax contaiinng the lenght of the memory used (I think) + min to the offset. Perhaps it should be compared to MemEnd-MemStart. Or it probably easier to just cmp TextEnd or CurrentPos (I don't know which one you use, CurrentPos doesn't seem to be used just modified) + min to MemEnd.

Also when you call
sub TxtEnd, eax
mov eax, TxtEnd
I believe your converting TxtEnd from a global Offset to a relative one. Perhaps you shjould convert it back.
Posted on 2001-07-27 14:11:38 by Eóin
damn, when I looked back my code, I realized that it's completly wrong...
I've so much change it that I forgot what it was supposed to do....

Here is it :

CheckMem proc min:DWORD
LOCAL memsize:DWORD, textlen:DWORD
cmp min, 100
jg @F
mov min, 100
@@:
mov eax, MemStart
sub CurrentPos, eax ;CurrentPos is now relative
push TxtEnd
pop textlen
sub textlen, eax
mov eax, TxtEnd
add eax, min
cmp eax, MemEnd
jl @F
mov eax, MemEnd
sub eax, MemPtr
mov memsize, eax
add memsize, ALLOCSIZE
invoke HeapReAlloc,heap,HEAP_ZERO_MEMORY or HEAP_NO_SERIALIZE,MemPtr,memsize
mov MemPtr, eax
add eax, 30
mov MemStart, eax
add eax, textlen
mov TxtEnd, eax
add eax, memsize
sub eax, 30
mov MemEnd, eax
@@:
mov eax, MemStart
add CurrentPos, eax
ret
CheckMem endp

Now, it works, but I didn't change the bad line ?!?!?
Strange !

(s)
Posted on 2001-07-27 14:36:34 by (scalp)
I'm sure its the add CurrentPos, eax at the end that corrected the code. Otherwise you were altering CurrentPos and not undoing the changes whenever there was enough memory.

Which also explains why it was that line that messd up the code in the first place.
Posted on 2001-07-27 14:47:13 by Eóin