[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Virtual String Memory for Applesoft
- Subject: Virtual String Memory for Applesoft
- From: "ict@ccess" <gids.rs@sasktel.net>
- Date: Fri, 13 Jan 2012 22:48:36 -0800 (PST)
- Complaints-to: groups-abuse@google.com
- Injection-info: kg1g2000pbb.googlegroups.com; posting-host=142.165.85.139; posting-account=U4TNXwoAAABP4nIJHynAJZ69O_f3LY2g
- Newsgroups: comp.sys.apple2
- Organization: http://groups.google.com
- User-agent: G2/1.0
If one really thinks about it, text files are a kind of virtual
memory. You can add strings, retrieve strings. And if the strings
are of a fixed length, then you can even replace strings in a text
file.
But I found the text file commands of DOS3.3 and Basic.system very
slow. Some recommendations were to save your strings to a BIN file
instead. So I combined the two and created a sort of semi-Virtual
memory for strings
Applesoft is limited with what it can do with variables. The maximum
value for any dimension is 32767, and the actual string space
available for strings is far less.
Using my virtual string array add on, you can define up to 65536
strings including string zero. And the maximum length of any string
is 255 characters (not 256 because string zero cannot be used since it
is used as an end of string marker)
Strings used this way can reach Prodos's maximum file size of 16 Mb
limit (65536 x 255 = 16711680)
Advantages -
Only one virtual string array variable is created in memory with 255
characters, one master block and one single byte block is also loaded
with the pointers (the 1 block that is loaded with the actual text
uses basic.systems buffer so does not take any additional space. If
the string spans 2 blocks, then the first part of the string is moved
to the string space, then the 2nd block is loaded)
Text files of Prodos's maximum files size can be created
Multiple Virtual String Array files can be created and used within the
same program
Virtual Array Text files can be created using any Word Processor that
can create large files (I wrote a short applesoft program that
creates a header from the text files so any string can be jumped to
automatically as if it were the first string in the list)
Disadvantages - every string must be retrieved from disk although with
the advent of flash cards has made the speed of drives more tolerable.
One extra file is created for the pointers.
The commands to use
& DEF VA$(0) - creates a virtual string variable and sets its length
to $FF (255) and makes space in string space
& GET VA$(0-65535),"Virtual String Array filename" - gets string from
file
& STORE X$,"Virtual String Array filename" - appends the string X$ to
the end of the file. If file does not exist then create it. If file
is not a Virtual Array file then return with error
Also a separate short applesoft program was created to make a header
for the pointers to every string. I used a pretty neat trick to
compress the header so that only one byte is needed to point to each
string instead of three and a one block master header to point to the
start of each string block.
Long story short, hopefully. One block can point to 512 strings. so
only 128 blocks would be needed to point to 65535 strings plus one
master block. The master block holds the two high bytes of the start
of each of the 128 blocks so only one master block is needed. Once
one of the 128 blocks has been chosen by a little math (# of the
string divided by 512 gives one of the 128 blocks)(coincidently, this
same result also points to the hi bytes in the master block), a short
search is then made in the found block so that each time the next byte
is less than the preceding byte, a counter advances the high bytes
until the start of the correct string is found. Remember, these
blocks can point to 512 strings of 255 characters, so the master
pointers may also need to be incremented. There, short and sweet.
A three byte pointer header would take 384 blocks to point to each
string to reach the 16 MB limit.
One last thought for a use of Virtual String Arrays. One String Array
can have 65535 strings and multiple Virtual files can be created.
Each file can be designated as a column. Strings can become
formulas. Are you getting the picture.
A Virtual Spreadsheet with 65535 columns by 65535 rows. There is a
good program in Nibble magazine Vol6 No8. Dynamic functions. It puts
formulas into a string and then uses redefined DEF and VAL commands to
evaluate the formula.
Allowing Applesoft to play with the big boys.
Rob