2018-01-28 19:00:23 +00:00
|
|
|
Block Memory Functions
|
|
|
|
|
2021-12-05 00:14:41 +00:00
|
|
|
This library contains functions and variables for accessing data in
|
|
|
|
blocks of memory. A block consists of up to 65,535 contiguous bytes.
|
|
|
|
This allows for the storage, retrieval, and manipulation of data
|
|
|
|
exceeding the maximum array length of 255.
|
2018-01-28 19:00:23 +00:00
|
|
|
|
|
|
|
These functions assume that a block is divided into equally sized segments
|
|
|
|
of up to 255 bytes in length. Data in the block is accessed by copying
|
|
|
|
data into and out of arrays with the same length as the segment size.
|
|
|
|
|
2021-12-05 00:14:41 +00:00
|
|
|
A segment typically consists of a string field, which is used as a key,
|
|
|
|
followed by a number of mixed type fields. For example, the segments in a
|
|
|
|
variable table might be 9 bytes long, consisting of a 7 byte variable name
|
|
|
|
string (6 characters plus a terminator), the variable type (at index 7)
|
|
|
|
and the variable length (at index 8).
|
2018-01-28 19:00:23 +00:00
|
|
|
|
|
|
|
Usage: at the beginning of the program use the directives
|
|
|
|
|
2018-07-31 00:03:56 +00:00
|
|
|
#include <stddef.h02>
|
2018-01-28 19:00:23 +00:00
|
|
|
#include <memory.h02>
|
|
|
|
#include <string.h02>
|
|
|
|
#include <block.h02>
|
|
|
|
|
2021-12-05 00:14:41 +00:00
|
|
|
The following application variables are defined:
|
2018-01-28 19:00:23 +00:00
|
|
|
|
2021-12-05 00:14:41 +00:00
|
|
|
int blkbgn; Start address of the block.
|
|
|
|
int blkend; End address of the block.
|
|
|
|
int blklen: Size of Segments in the block.
|
|
|
|
|
|
|
|
These variables must be assigned before calling
|
|
|
|
any of the functions in this module. They may be
|
|
|
|
reassigned at any time, allowing the program to
|
|
|
|
access different blocks.
|
2018-01-28 19:00:23 +00:00
|
|
|
|
2021-12-05 00:14:41 +00:00
|
|
|
Note: Although a block usually begins and ends
|
|
|
|
on a 256 byte boundary, this is not required.
|
|
|
|
|
|
|
|
int blkptr; Pointer to the next segment. This can be reset
|
|
|
|
to blkbgn using the blkrst() function.
|
2018-01-28 19:00:23 +00:00
|
|
|
|
2021-12-05 00:14:41 +00:00
|
|
|
To preserve the segment position, this value must
|
|
|
|
be saved before reassigning to another block, then r
|
|
|
|
estored when reassigning back to the original block.
|
2018-01-28 19:00:23 +00:00
|
|
|
|
2021-12-05 00:14:41 +00:00
|
|
|
The following application functions are defined:
|
2018-01-28 19:00:23 +00:00
|
|
|
|
2021-12-05 00:14:41 +00:00
|
|
|
|
2018-07-31 00:03:56 +00:00
|
|
|
blkset(c); Block Set: Fills entire block with character c,
|
2018-01-28 19:00:23 +00:00
|
|
|
leaving block pointer at end of block.
|
|
|
|
|
2018-07-31 00:03:56 +00:00
|
|
|
Should be called with an argument of 0, to initialize
|
|
|
|
a block before use.
|
2018-01-28 19:00:23 +00:00
|
|
|
|
2021-12-05 00:14:41 +00:00
|
|
|
blkrst(); Block Reset: Sets block pointer to first segment.
|
2018-01-28 19:00:23 +00:00
|
|
|
|
|
|
|
This routine is called before populating a block with
|
2018-07-31 00:03:56 +00:00
|
|
|
calls to the blkput function.
|
|
|
|
|
2021-12-05 00:14:41 +00:00
|
|
|
blknxt(); Block Next: Moves the block pointer to the bext
|
|
|
|
segment.
|
2018-01-28 19:00:23 +00:00
|
|
|
|
|
|
|
If the block pointer is moved past the end of the
|
2021-12-05 00:14:41 +00:00
|
|
|
block, or the segment length is set to 0, a value of
|
2018-07-31 00:03:56 +00:00
|
|
|
#TRUE is returned. Otherwise, a value of #FALSE is
|
|
|
|
returned.
|
|
|
|
|
2021-12-05 00:14:41 +00:00
|
|
|
|
|
|
|
|
2018-07-31 00:03:56 +00:00
|
|
|
blkprv(); Block Previous: Moves block pointer backward by the
|
|
|
|
segment length set by a prior blkseg call.
|
|
|
|
|
|
|
|
If the block pointer is moved past the beginning of
|
2021-12-05 00:14:41 +00:00
|
|
|
the block, or the segment length is set to 0, a value
|
2018-07-31 00:03:56 +00:00
|
|
|
of #TRUE is returned. Otherwise, a value of #FALSE is
|
|
|
|
returned.
|
2018-01-28 19:00:23 +00:00
|
|
|
|
2018-07-31 00:03:56 +00:00
|
|
|
blkput(n ,&m); Block Put: Copies n bytes of array m to a block at the
|
|
|
|
current pointer location, and moves block the pointer
|
2018-01-28 19:00:23 +00:00
|
|
|
forward by the segment length set by a prior blkseg
|
|
|
|
call.
|
|
|
|
|
|
|
|
If the appended bytes would overflow the end of the
|
2018-07-31 00:03:56 +00:00
|
|
|
block, no bytes are copied and a value of #FALSE is
|
|
|
|
returned. Otherwise, the bytes are copied and a value
|
|
|
|
of #TRUE is returned.
|
2018-01-28 19:00:23 +00:00
|
|
|
|
2018-07-31 00:03:56 +00:00
|
|
|
Note: Sets dstlo and dsthi to blklo and blkhi prior
|
|
|
|
to the copy, updates blklo and blkhi, then calls
|
2018-01-28 19:00:23 +00:00
|
|
|
the memcpy function.
|
|
|
|
|
2018-07-31 00:03:56 +00:00
|
|
|
blkget(n ,&m); Block Get: Copies n bytes from a block at the current
|
|
|
|
pointer location to array m, and moves the pointer
|
2018-01-28 19:00:23 +00:00
|
|
|
forward by the segment length set by a prior blkseg
|
|
|
|
call.
|
|
|
|
|
|
|
|
If the copied bytes would overflow the end of the
|
2018-07-31 00:03:56 +00:00
|
|
|
block, no bytes are copied and a value #FALSE is
|
|
|
|
returned. Otherwise, the bytes are copied and a value
|
|
|
|
of #TRUE is returned.
|
2018-01-28 19:00:23 +00:00
|
|
|
|
|
|
|
Note: Sets dstlo and dsthi to the address of m,
|
2018-07-31 00:03:56 +00:00
|
|
|
srclo and srchi to blklo and blkhi prior to the
|
2018-01-28 19:00:23 +00:00
|
|
|
copy, updates blkslo and blkshi, then calls the
|
|
|
|
memcpy function.
|
|
|
|
|
2018-07-31 00:03:56 +00:00
|
|
|
blkswp(n); Block Swap: Swaps n bytes of array m with the current
|
|
|
|
block segment (pointed to by the block pointer. The
|
|
|
|
block pointer is not changed.
|
|
|
|
|
|
|
|
Requires a prior call to the memdst function specifying
|
|
|
|
an array at least n bytes long, which is used for
|
|
|
|
temporary storage.
|
|
|
|
|
|
|
|
Note: Sets temp0 to n, copies blklo and blkhi to dstlo,
|
|
|
|
and dsthi, and calls memswp.
|
|
|
|
|
2018-01-28 19:00:23 +00:00
|
|
|
blkmem(n ,&m); Block Memory search: Search block for n byte long
|
|
|
|
segment matching array m.
|
|
|
|
|
2018-07-31 00:03:56 +00:00
|
|
|
If a matching segment is found, the value #TRUE is
|
|
|
|
returned and the destination pointer is set to the
|
2018-01-28 19:00:23 +00:00
|
|
|
address of the matching segment, allowing it to be
|
|
|
|
overwritten with a subsequent memcpy call. Otherwise,
|
2018-07-31 00:03:56 +00:00
|
|
|
the value #FALSE is returned.
|
|
|
|
|
2018-01-28 19:00:23 +00:00
|
|
|
Note: Sets srclo and srchi to the address of m,
|
|
|
|
dstlo and dsthi to the address of the matching segment,
|
|
|
|
and temp0 to n. Does not change the block pointer.
|
|
|
|
|
|
|
|
blkstr(n ,&s); Block String Search: Search block for n byte long
|
|
|
|
segments beginning with string s.
|
|
|
|
|
|
|
|
If a matching segment is found, the value 255 (true)
|
|
|
|
is returned and the segment is copied to the array set
|
|
|
|
by a prior memdst call. Otherwise, the value 0 (false)
|
|
|
|
is returned.
|
|
|
|
|
|
|
|
Note: Sets srclo and srchi to the address of the
|
|
|
|
segment, temp0 to n, and copies dstlo and dsthi to
|
|
|
|
temp1 and temp2. Does not change the block pointer.
|
|
|
|
|
|
|
|
blksrt(&m); Block Sort: Sort segments in block by initial string,
|
|
|
|
using array m as temporary storage.
|
|
|
|
|
|
|
|
Segments are sorted in alphabetical order, with segment
|
|
|
|
length set by a prior blkseg call, and sorting stops at
|
|
|
|
the first segment that begins with an empty string (the
|
|
|
|
first byte is 0), leaving the block pointer at that
|
|
|
|
segment.
|
|
|
|
|
|
|
|
Note: Uses the selection sort algorithm. Sets temp1
|
|
|
|
and temp2 to the address of array m.
|
|
|
|
|
2018-07-31 00:03:56 +00:00
|
|
|
blkdst(); Block Destination: Sets the destination pointer to the
|
|
|
|
block segment pointer.
|
|
|
|
|
|
|
|
This is a utility function called by other functions in
|
|
|
|
this module.
|
|
|
|
|
|
|
|
Note: Sets dstlo and dsthi to blklo and blkhi.
|
|
|
|
|
2018-01-28 19:00:23 +00:00
|
|
|
Note: This library expects the following functions to be defined
|
|
|
|
|
|
|
|
setdst(&s); Set destination string pointer
|
|
|
|
setsrc(&s); Set source string pointer and initialize index
|
|
|
|
memcmp Compare memory
|
|
|
|
memcpy Copy memory
|
|
|
|
memsrc Set memory source and count
|
|
|
|
strcml Compare string (alternate entry point)
|
|
|
|
|
|
|
|
along with the zero page variable pairs
|
|
|
|
|
|
|
|
srclo, srchi Source String Pointer
|
|
|
|
dstlo, dsthi Destination String Pointer
|
|
|
|
blklo, blkhi Block Pointer
|
|
|
|
|
|
|
|
the static variable
|
|
|
|
|
|
|
|
blkslo, blkshi Block Start Address
|
|
|
|
blkelo, blkehi Block End Address
|
|
|
|
blklen Block Segment Length
|
|
|
|
|
|
|
|
as well as the transient variables
|
|
|
|
|
|
|
|
temp0, temp1, temp2 Temporary storage
|