On 5-Jun-2012, Michael <
michael...@gmail.com> wrote:
> David:
>
> I agree, the backwards thing did bug me a little, but as they worked -
> > "If it ain't broke, dont fix it"
>
The problem is that it *is* broke. It's a hangover form the original BBC
6502 Basic and exixts only because with a 6502 and limited RAM code could be
faster and more compact it you counted down to 0 instead of up to a certain
number. Hence starting at the end of a string and working down the the start
was 'better'. The trouble is that it makes the data effectively unreadable
for anything except BBC Basic. If you use BPUT# instead of PRINT# and then
GET$# to retrieve a string then the strings are just put into the file
'normally' so they can be read by any other method, including simply
visually.
> As I am using arrays of strings and integers, how would I arrange my
> memory into a block and save/read that? I have always steered away
> from looking into this, as my system has worked until now, and in case
> I bugger something up ;@)
>
Create a byte array big enough to hold your data eg. DIM array% 8000 for
8000 (actually 8001) bytes. You now need a pointer to the data, eg. ptr%.
Assuming you've got a Basic string and 2 integers you could use -
ptr%=array% :REM set ptr% to start of data block
$ptr%=name$ :REM insert string at ptr%
ptr%=ptr%+LEN(name$)+1 :REM point to next byte after end of string
ptr%=(ptr%+3) AND NOT 3 :REM word align ptr%
!ptr%=data1%:ptr%+=4 :REM insert 1st data word and inc ptr%
!ptr%=data2%:ptr%+=4 :REM insert 2nd data word and inc ptr%
repeat until done (obviously without the 1st line for subsequent records).
It would also be sensible to leave (say) 4 bytes empty at the start and keep
a count of the number of records as you go then put this into the start of
the data so you know how many records there are when you relieve it; eg.,
start out with ptr%=array%+4, then before you save !array%=count%
Note. It's not strictly necessary to word align the integers in a Basic
array but it's neater and would make it easier for another language to
retrieve the data from the file.
If the names are longer than 255 characters then instead of just inserting
Basic strings you'd have to copy them. If (as you say) you've used OS_GBPB
to get the names then set a pointer (name%) to point to the name returned by
OS_GBPB and instead of lines 2 and 3 above use -
WHILE ?name% >13 :REM repeat until end of name found
?ptr%=?name% :REM copy a character
ptr%+=1:name%+=1 :REM inc pointers
ENDWHILE
?ptr%=0:ptr%+=1 :REM terminate string and inc ptr%
To save the data it's best to use the appropriate OS_File command but you
could just use -
OSCLI "save "+filename$+" "+STR$~array%+" "+STR$~ptr%
Retrieving the data is the reverse of the above.
> Last thought, should the Wimp Message System be pointing to a byte
> array as well to overcome this? (not knowing anything really about
> it) :)
All text passed to and from the Wimp message system *is* passed in that way.
Basic will hide this from you by letting you put a Basic string as a
parameter but it converts it to a 0 terminated string before passing it to
the SWI.
The limitation is because the Wimp message system itself passes only 256
bytes. Some of these are used for various parameters so any text will be
limited to about 240. Of course, this won't matter if you're not using the
Wimp message system, eg. to load/save data by dragging.