Page 1 of 1

Setting and getting the Data Pointer...

Posted: Wed Jan 23, 2008 4:42 pm
by DoubleDutch
This routine allows you to save/restore the data pointer. A useful function of it is that you can set the data pointer to an area of allocated memory and use the read commands rather than the peek commands (no need to increment a pointer). This is really useful if reading in a file that has a header with data in it. Another advantage when using this over the traditional "Restore" command is that you can use an expression to set the address.

If you use the commands to read from an area of allocated memory you need to disable and then enable the debugger as it has a slight conflict.

The syntax is:
OriginalPointer=RestorePointer([new address])

Code: Select all

Procedure RestorePointer(position=0)
	!MOV eax,dword [PB_DataPointer]
	!MOV edx,dword [p.v_position]
	!CMP edx,0
	!JE	@f
	!MOV dword [PB_DataPointer],edx
!@@:
	ProcedureReturn
EndProcedure

Debug("Uninitialised restore pointer: "+Hex(RestorePointer()))

Restore MyData

Debug("MyData address: "+Hex(?MyData))
Debug("Current restore pointer: "+Hex(RestorePointer()))

Read var
Debug("Restore pointer after read: "+Hex(RestorePointer(?MyData)))
Debug("Restore pointer after optional setting: "+Hex(RestorePointer()))

Read var2
Debug("Result from 2nd read: "+Str(var2))


memtest=AllocateMemory(100)
PokeL(memtest,456)
l1=PokeS(memtest+4,"blah blah blah")+1
l2=PokeS(memtest+4+l1,"second string")+1
PokeL(memtest+4+l1+l2,789)

RestorePointer(memtest)
DisableDebugger
Read var3
Read string$
Read string2$
Read var4
EnableDebugger
Debug("Result from read from memory: "+Str(var3)+"  "+string$+"   "+string2$+"   "+Str(var4))

DataSection
MyData:
	Data.l	123
EndDataSection

Posted: Wed Jan 23, 2008 9:50 pm
by Psychophanta
Very good, and useful of course.
I hope it is implemented as native. I mean the posibility of put an expression and not a constant value :)

Posted: Wed Jan 23, 2008 11:31 pm
by DoubleDutch
Yep - This should keep us going until it's native, I did some tests and it seems to cope ok. :)

The best side effect was that you can now use the READ commands to do a psuedo auto-incrementing PEEK. It's great for reading preloaded bin files.

Posted: Wed Jan 23, 2008 11:35 pm
by SFSxOI
Thank You Double Dutch, I think I can put this to use in a project. :)

Re: Setting and getting the Data Pointer...

Posted: Mon Feb 14, 2022 10:57 pm
by skywalk
Hi DoubleDutch.
Do you mind moving this to Feature Requests?
It has worked great but now we have the C backend.
Here is my post on RestoreX(?mylabel) workaround..

Re: Setting and getting the Data Pointer...

Posted: Tue Feb 15, 2022 12:09 am
by DoubleDutch
I would do, but i I don't know how to get it moved to feature requests? Maybe an admin can do this?

Shame it hasn't been made native yet, coded it almost 15 years ago...

Re: Setting and getting the Data Pointer...

Posted: Tue Feb 15, 2022 2:29 am
by skywalk
Statute of limitation has long expired :lol: