Page 1 of 1
Enhanced Restore/Goto/Gosub commands
Posted: Mon Oct 01, 2007 10:05 am
by DoubleDutch
Having the restore/goto/gosub commands enhanced to support expressions would be good.
I know it would break compatibility, as existing code would have to be changed from something like:
to:
But changing the commands would be *very* useful and make it overall a lot more consistant.
You could possibly add different commands to keep existing code working, the new commands could be:
Code: Select all
Restore(expression)
Goto(expression)
Gosub(expression)
Posted: Mon Oct 01, 2007 3:50 pm
by Psychophanta
I have been searching through the forum a request i made for that in the past, but i don't find it :roll: It was only for Restore.
So i second that.
Restore <Expression>
Goto <Expression>
Gosub <Expression>
In fact i would request for defined labels to be treated as common long typed variables. So the feature requested in this thread would automatically done.

Posted: Tue Oct 02, 2007 12:55 pm
by DoubleDutch
Another good feature would be to be able to discover the current pointer memory position. So you could save it for later restoration. Having multiple 'Read' parameters would also be good.
eg:
Code: Select all
Position=Data()
.
.
Read this, that, blah$
.
.
Restore Position
Posted: Tue Oct 02, 2007 1:45 pm
by Derek
DoubleDutch wrote:Having multiple 'Read' parameters would also be good.
eg:
Code: Select all
Position=Data()
.
.
Read this, that, blah$
.
.
Restore Position
Definately a good idea, old basics used to allow this.
Posted: Tue Oct 02, 2007 2:55 pm
by DoubleDutch
It would also be good if PureBasic "knew" that data type from the actual data, rather from the Data command itself.
eg:
Code: Select all
Data "string", 90, 4.b, "string again"
Would have a string, a long, a byte and then another string.
If all these enhancements were made then a nice side effect would be that you could load a binary file into memory then:
Code: Select all
Restore memoryaddr
Read String$, check, flag.b
Instead of having to peek through memory and keep updating pointers like:
Code: Select all
position=memoryaddr
String$=PeekS(position)
position+len(String$)+1
check=PeekL(position)
position+4
flag=PeekB(position)&$ff
position+1
The enhanced solution looks nicer and is easier to follow.
Posted: Tue Oct 02, 2007 3:01 pm
by Psychophanta
DoubleDutch wrote:Another good feature would be to be able to discover the current pointer memory position. So you could save it for later restoration. Having multiple 'Read' parameters would also be good.
eg:
Code: Select all
Position=Data()
.
.
Read this, that, blah$
.
.
Restore Position
Oops! I believed the multiple 'Read' parameters feature was already implemented
What about this syntax for the 'Read' word?
Read [From <position>,] <variable1> [,variable2, variable3...]
BTW: there is a bug in the PB manual (dunno if already reported). It wrote:
Syntax
Read
and it is wrong because the syntax requires a variable as parameter, i.e. The word 'Read' alone is a syntax error

.
Posted: Tue Oct 02, 2007 3:15 pm
by DoubleDutch
Oops! I believed the multiple 'Read' parameters feature was already implemented
Really, thats good.
All I see in the help on Read syntax is:
Syntax
Read
Description
Read the next available data. The next available data can be changed by using the Restore command. By default, the next available data is the first data declared.
Which is of course (as you mentioned) incorrect.
I did a quick look for other infor on read but all the examples (with restore/data) imply that its single parameters.
Edit:
I just did a quick test and:
Code: Select all
Read id,flags,x.w,y.w,w.w,h.w,text$
results in a garbage at end of line error.
Posted: Wed Jan 23, 2008 2:31 pm
by DoubleDutch
This code will allow you to read the current data pointer easily...
Code: Select all
Procedure RestorePointer()
!MOV eax,dword [PB_DataPointer]
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()))
DataSection
MyData:
Data.l 123
EndDataSection
I tried to extend this with:
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()))
DataSection
MyData:
Data.l 123
EndDataSection
But I get an error on compilation with the
!@@ line, purebasic insists that it is an illegal instruction, but it's actually a way of doing anonymous labels in fasm.
Fasm documentation wrote:The @@ name means anonymous label, you can have defined many of them in the source. Symbol @b (or equivalent @r) references the nearest preceding anonymous label, symbol @f references the nearest following anonymous label. These special symbol are case-insensitive.
Is this a bug in the PureBasic compiler? I thought that
! would pass anything following (on the same line) direct to fasm without checks or interference.
Posted: Wed Jan 23, 2008 3:53 pm
by Trond
When you define a label you need to put a : after it.
Posted: Wed Jan 23, 2008 4:42 pm
by DoubleDutch
Oops! It was staring me in the face!
I've added this to tricks n tips:
http://www.purebasic.fr/english/viewtop ... 372#229372
Here is a post with info on how to goto/gosub a variable and a psuedo on goto/gosub:
http://www.purebasic.fr/english/viewtop ... 381#229381