home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DP Tool Club 19
/
CD_ASCQ_19_010295.iso
/
dos
/
prg
/
bas
/
asilib11
/
data.doc
< prev
next >
Wrap
Text File
|
1994-10-22
|
18KB
|
524 lines
******************************* DATA *************************************
ASILIB data manipulation subroutines Copyright (C) 1994 Douglas Herr
all rights reserved
ASIC string data is restricted to a maximum of 80 bytes per string, and
each ASIC string uses 80 bytes plus one string terminating NUL byte.
ASILIB's string subroutines work perfetly well with ASIC strings, and
most permit any other data space in ASIC's data area to be used as
though it were a text string. For example, if your program is reading a
text file with each line as ling as 132 characters, you would have trouble
fitting each line into an ASIC string. However, you may dimension an
array of 132 bytes (plus one terminating byte) as an integer array:
DIM reallyastring(67)
(Recall that each integer is 2 bytes)
By passing reallyastring(1) to FGetStr (for example) in place of the string
parameter, you can safely read lines up to 132 characters long. There are
a few ASILIB subroutines that will work ONLY with ASIC strings; this fact
is clearly stated in the documentation for each applicable subroutine.
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
GET2: Get 2 bytes from far memory
Parameters: data segment, data offset&, twobytes
Read 2 bytes from data in far memory. Note that in order
to access the upper 32k of a large data block you need to
use a long integer as your offset, even with the normal
ASILIB.LIB library. Get2 in ASIHUGE.LIB works properly with
data blocks over 64k. In either case, the data segment used
to access the data is the base segment returned by ASILIB's
ALLOCDOS or other ASILIB subroutines that allocate far
memory and return a segment address.
Example:
REM My program has a data block in far memory and I want to retrieve
REM an integer from it
REM 50th integer
REM remember that the first integer is at offset 0
dataoffset&=98
call sub "get2", datasegment, dataoffset&, twobytes
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
GET4: Get 4 bytes from far memory
Parameters: data segment, data offset&, fourbytes&
Read 4 bytes from data in far memory. Note that in order
to access the upper 32k of a large data block you need to
use a long integer as your offset, even with the normal
ASILIB.LIB library. Get4 in ASIHUGE.LIB works properly with
data blocks over 64k. In either case, the data segment used
to access the data is the base segment returned by ASILIB's
ALLOCDOS or other ASILIB subroutines that allocate far
memory and return a segment address.
Example:
REM My program has a data block in far memory and I want to retrieve
REM a long integer from it
REM 50th integer
REM remember that the first integer is at offset 0
dataoffset&=196
call sub "get4", datasegment, dataoffset&, fourbytes&
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
I2TOSTR: convert an integer value to a string
I4TOSTR: convert a long integer value to a string
Parameters: (i2tostr) number, nstring$
(i4tostr) number&, nstring$
ASILIB's TPrint, GPrint and other 'print' subroutines require
a string argument. Numeric data must be converted to a string
before printing. NString$ is where the string form of the
number is placed. Note that i4tostr number& is a long integer
which requires ASIC's Extended math option. If you use an
ASILIB string, the string must be at least 7 bytes for i2tostr
or 12 bytes for i4tostr. If you use an ASIC string, you don't
need to consider the string length because all ASIC strings
are 80 bytes.
Example:
REM using ASIC string
n=12345
call sub "i2tostr", n, nstring$
REM using ASILIB string
REM a 6-integer array is 12 bytes
DIM n(6)
n&=1234567&
call sub "i4tostr", n&, n(1)
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
LTRIM: removes leading blanks from an ASIC or ASILIB string
Parameters: inputstring$
LTRIM removes leading blanks from a string.
LTRIM does NOT copy the resulting string to a new area: the
previous string is modified. LTRIM is handy when using
ASILIB's I2TOSTR and I4TOSTR subroutines.
Example:
oldstring$=" unrealistic example"
call sub "ltrim", oldstring$
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
PUT2: copy 2 bytes to a far memory block
Parameters: data segment, data offset&, twobytes
Copies 2 bytes to far memory. Note that in order
to access the upper 32k of a large data block you need to
use a long integer as your offset, even with the normal
ASILIB.LIB library. Put2 in ASIHUGE.LIB works properly with
data blocks over 64k. In either case, the data segment used
to access the data is the base segment returned by ASILIB's
ALLOCDOS or other ASILIB subroutines that allocate far
memory and return a segment address.
Example:
REM My program has a data block in far memory and I want to copy
REM an integer to it
REM 50th integer
REM remember that the first integer is at offset 0
dataoffset&=98
call sub "put2", datasegment, dataoffset&, twobytes&
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
PUT4: copy 4 bytes to a far memory block
Parameters: data segment, data offset&, fourbytes&
Copy 4 bytes to far memory. Note that in order
to access the upper 32k of a large data block you need to
use a long integer as your offset, even with the normal
ASILIB.LIB library. Put4 in ASIHUGE.LIB works properly with
data blocks over 64k. In either case, the data segment used
to access the data is the base segment returned by ASILIB's
ALLOCDOS or other ASILIB subroutines that allocate far
memory and return a segment address.
Example:
REM My program has a data block in far memory and I want to copy
REM a long integer to it
REM 50th integer
REM remember that the first integer is at offset 0
dataoffset&=196
call sub "put4", datasegment, dataoffset&, fourbytes&
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
RTRIM: removes trailing blanks from an ASIC or ASILIB string
Parameters: inputstring$
RTRIM removes trailing blanks from the end of a string.
RTRIM does NOT copy the resulting string to a new area: the
previous string is modified.
Example:
oldstring$="unrealistic example "
call sub "rtrim", oldstring$
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
STRCHR: find the first matching character in a string, case-sensetive
Parameters: String to search, character to find, character offset
Given an ASIC or ASILIB string, STRCHR finds the first
character in the string matching a specified character,
returning the offset of the character in the string.
If the character offset is returned = -1, the character
was not found in the string. Note that the offset of the
first character in the string = 0.
Example:
REM search for the first " " in a string
call sub "strchr", anyoldstring$, ASC(" "), charoffset
if charoffset = -1 then
print "Can't find it"
endif
See also:
STRRCHR, STRICHR
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
SORTI2HI: Sort integer array, highest first
SORTI2LO: Sort integer array, lowest first
SORTI4HI: Sort long integer array, highest first
SORTI4LO: Sort long integer array, lowest first
Parameters: array segment, array offset, array elements
Beginning at the array element at the specified segment:offset
address, these subroutines sort the specified number of array
elements. These subroutines use the Shell sort algorithm.
Example:
REM My program is using a long integer array abd I want to sort the
REM entire array, lowest first.
dim longdata&(1000)
REM program establishes vaules for array elements
.
.
.
REM get array address
call sub "asicds", arraysegment
arrayoffset=VARPTR(longdata&(1))
arrayelements=1000
call sub "sorti4lo", arraysegment, arrayoffset, arrayelements
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
STRICHR: find the first matching character in a string, case-insensetive
Parameters: String to search, charater to find, character offset
Given an ASIC or ASILIB string, STRICHR finds the first
character in the string matching a specified character,
returning the offset of the character in the string.
If the character offset is returned = -1, the character
was not found in the string. Note that the offset of the
first character in the string = 0.
Example:
REM search for the first "h" or "H" in a string
call sub "strichr", anyoldstring$, ASC("h"), charoffset
if charoffset = -1 then
print "Can't find it"
endif
See also:
STRCHR, STRRCHR
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
STRIPCHR: remove all occurances of a character from a string.
Parameters: inputstring$, character
STRIPCHR removes all occurances of character from the
input string.
Example:
REM remove commas from a numeric string
n$="123,456,789"
ch=ASC(",")
call sub "stripchr", n$, ch
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
STRISTR: search string for substring, case-insensetive
Parameters: source string, target string, string offset
Similar to ASIC's INSTR, STRISTR searches either an ASIC
string or an ASILIB string (source string) for a matching
substring (target string). Note that STRISTR, unlike INSTR,
considers the first character in the source string to be at
string offset = 0. If the target string is not found in the
source string, string offset = -1. Source string and target
string may either be an ASIC string or an ASILIB string.
STRISTR is NOT case-sensetive: "AAA" = "aaa" = "AaA".
Example:
a$="Greased lightning"
b$="grease"
call sub "stristr",a$, b$, i
REM in this example i = 0
See also:
STRSTR, STRRSTR, STRCHR, STRRCHR
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
STRLEN: finds length of an ASILIB string
Parameters: stringaddress, stringlength
Determines length of ASIC or ASILIB string. ASIC strings
are limited to 80 characters; ASILIB strings may be as long
as ASIC's DIM statements allow.
Example:
REM use ASIC numeric array to create ASILIB string space
REM later in the program the string has been used and I need to determine
REM its exact length.
REM allow space for 2000-byte string
DIM ASILIBstring(1000)
.
.
.
stringaddress=VARPTR(ASILIBstring(1))
call sub "strlen", stringaddress, stringlength
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
STRLWR: Convert string to lower case
Parameters: string to convert
STRLWR converts any ASILB or ASIC string to lower case.
Example:
a$="ThIs iS A MiXeD-CaSe sTrInG"
call sub "strlwr", a$
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
STRREV: reverses all characters in a string
Parameters: rev$
Reverses all characters in a string, regardless of length.
works with ASIC strings and ASILIB strings up to 32767 bytes.
Example:
a$="123456789"
call sub "strrev", a$
print a$ REM prints '987654321'
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
STRRCHR: find the last matching character in a string
Parameters: String to search, charater to find, character offset
Given an ASIC or ASILIB string, STRRCHR finds the last
character in the string matching a specified character,
returning the offset of the character in the string.
If the character offset is returned = -1, the character
was not found in the string. Note that the offset of the
first character in the string = 0.
Example:
REM search for the last "\" in a full filename
filename$ = "C:\ASIC\LIB\ASILIB.LIB"
call sub "strrchr", filename$, ASC("\"), charoffset
if charoffset = -1 then
print "Can't find it"
endif
See also:
STRCHR, STRICHR
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
STRRSTR: search string for last substring
Parameters: source string, target string, string offset
Similar to ASIC's INSTR, STRRSTR searches a source string
for a matching substring (target string). STRRSTR searches
for the LAST occurance of the target in the source. Note that
STRRSTR, unlike INSTR, considers the first character in the
source string to be at string offset = 0. If the target string
is not found in the source string, string offset = -1. Source
string and target string may either be an ASIC string or an
ASILIB string.
Example:
a$="Software & Hardware"
b$="ware"
call sub "strrstr",a$, b$, i
REM in this case i = 15
See also:
STRSTR, STRISTR, STRCHR, STRRCHR
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
STRSTR: search string for substring
Parameters: source string, target string, string offset
Similar to ASIC's INSTR, STRSTR searches either an ASIC
string or an ASILIB string (source string) for a matching
substring (target string). Note that STRSTR, unlike INSTR,
considers the first character in the source string to be at
string offset = 0. If the target string is not found in the
source string, string offset = -1. Source string and target
string may either be an ASIC string or an ASILIB string.
Example:
a$="Greased lightning"
b$="light"
call sub "strstr",a$, b$, i
REM in this example i = 8
See also:
STRRSTR, STRISTR, STRCHR, STRRCHR
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
STRUPR: Convert string to upper case
Parameters: string to convert
STRUPR converts any ASILB or ASIC string to upper case.
Example:
a$="This is a mixed-case string, mostly lower case"
call sub "strupr", a$
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
SWAPB: swaps specified number of bytes
Parameters: (64k library) seg0, offset0, seg1, offset1, bytes
(huge library) seg0, offset0&, seg1, offset1&, bytes&
SWAPB exchanges data between two regions of memory, region0
and region1. You supply the base segment and starting offset
of each region, and the number of bytes to swap. Note that
the huge-data library requires long integer offsets and bytes.
With the 64k-data library, bytes is limited to 65535. Normally
ASIC assumes that integers are in the range of -32768 to +32767
but you may pass long integers up to 65535 using ASIC long
integers.
Example:
REM I want to swap the first 150 elements of arrays a() and b()
dim a(1000)
dim b(2000)
REM program fills in the arrays
.
.
.
REM get ASIC's default data segment
call sub "ASICDS", defaultseg
aptr=VARPTR(a(1))
bptr=VARPTR(b(1))
REM remember that each integer is 2 bytes
bytes=300
call sub "swapb", defaultseg, aptr, defaultseg, bptr, bytes
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
TODAY: Get today's date from system clock
Parameters: No input parameters; returns month, date, year, dayofweek
Returns integer values for month (1 - 12), date of month
(1 - 31), year (1980 - 2099), and day of week (1 - 7, Sunday
through Saturday) from the system clock.
Example:
call sub "today", month, date, year, dayofweek