CALC Command Menu

Numeric Mathematical Calculation

IFIND-Loc of Case Insensitive text > BLEN-Get Buffer Length - number of bytes >
+ , - , /, *, %, |, & , ^, ++, -- > ILFIND-Last Loc of Case Insensitive text > BTRIM-Buffer Trim bytes start and end >
ABS, EXP, LOG, LOG10, POW, SQRT, CBRT, RND > REM-Remove text > BLTRIM-Buffer Trim bytes from start >
COS, SIN, TAN, ACOS, ASIN, ATAN, ATAN2 > IREM-Remove Case Insensitive text > BRTRIM-Buffer Trim bytes from end >
COSH, SINH, TANH, ACOSH, ASINH, ATANH > SPLIT-Split Text at Char or String > BREM-Buffer Remove bytes >
PIXX-Get Width of Entity > BCNV-Convert hex data in buffer to number >

Text Manipulation and search 

PIXY-Get Height of Entity >
POS-Move Cursor to Absolute Position > PCOPY-Pointer Copy >

Checksum Create or test checksums

REL-Move Cursor to Relative Position > SHIFT-Array Data Shift > MCHK-Make checksum >
INS-Insert / Overwrite Text at Cursor > MIN-Find minimum value in array > TCHK-Test checksum >
DEL-Delete Text at Cursor > MAX-Find maximum value in array > CRC16-16 support >
TRIM-Trim Chars off Start and End of Text > MSPLIT-User Protocol Split > CRC32-32 support >
LTRIM-Trim Chars from Start of Text String > CFLT-Calc float to/from U32 >
RTRIM-Trim Chars from End of Text String >

File Search and Read

UPPER-Convert Text to Uppercase >

 Buffer Manipulation and Search

FEXISTS-Checks for existence of file >
LOWER-Convert Text to Lowercase > BCOPY-Buffer Copy  n bytes > FREAD-Read Text File into Text buffer >
BEF-Get Chars from Before Cursor > BCUT-Buffer Cut n bytes > DIR-Directory Listing >
AFT-Get Chars from After Cursor > BCUTB-Cut chars from start of buffer > FINFO-Get file Info >
CUR-Change Cursor Type > BCUTBI-Cut chars from end of buffer >
LEN-Get Text Length > BBINS-Buffer Insert bytes at position >

Sort Array Contents/Check entity info 

LOC-Get Cursor Location > BREP-Buffer Replace bytes at position > ASORT-Sort Array >
TYPE-Get Cursor Type > BREPB-Replace buffer with another buffer > ASORTR-Sort Array >
FIND-Find Location of text > BFIND-Buffer Find  > ENTITYINFO-Find entity Information >
LFIND-Find Last Location of text > BLFIND-Buffer Find Last > ENTITY EXISTS-Test if entity exists >
Command CALC - Numeric Handling
 
Description This provides a fast simple calculation placed in the Result variable according to the type
of Method using + , - , / , *, %(modulus) or logical functions | (OR)  & (AND) ^ (EXOR) for non float.
The source parameters can be text, numeric, variables or pointers as appropriate.
More complex calculation methods for maths, trigs, text and buffers are described below.
 
Syntax/Parameters CALC(Result,VarA,VarB,Method)

+ - Add
- - Minus
/ - Divide
* - Multiply
% - Modulus
| - OR (Logical) non float
& - AND (logical) non float
^ -EXOR (logical) non float
> - shift bits
< - shift bits

eg
CALC(varIndex,varIndex,1,"+"); // Buffer wrapping: varIndex = varIndex + 1
CALC(varX2,DISPX,2,"*"); // Centre of display: varX2 = DISPX * 2
CALC(hours_f,Time.mins,60,"/"); // Fractional hours: hours_f = Time.mins / 60

20 Combined CALC() Functions ''/-'', ''+/'', ''*+'', ''+%'', ''++'', etc - v49.48
* Added 20 "combined" CALC() functions:
CALC( varD, varX, varY, varZ, "/-" ); // varD = ( varX / varY ) - varZ
CALC( varD, varX, varY, varZ, "/+" ); // varD = ( varX / varY ) + varZ
CALC( varD, varX, varY, varZ, "-/" ); // varD = ( varX - varY ) / varZ
CALC( varD, varX, varY, varZ, "+/" ); // varD = ( varX + varY ) / varZ
CALC( varD, varX, varY, varZ, "*-" ); // varD = ( varX * varY ) - varZ
CALC( varD, varX, varY, varZ, "*+" ); // varD = ( varX * varY ) + varZ
CALC( varD, varX, varY, varZ, "-*" ); // varD = ( varX - varY ) * varZ
CALC( varD, varX, varY, varZ, "+*" ); // varD = ( varX + varY ) * varZ
CALC( varD, varX, varY, varZ, "%-" ); // varD = ( varX % varY ) - varZ
CALC( varD, varX, varY, varZ, "%+" ); // varD = ( varX % varY ) + varZ
CALC( varD, varX, varY, varZ, "-%" ); // varD = ( varX - varY ) % varZ
CALC( varD, varX, varY, varZ, "+%" ); // varD = ( varX + varY ) % varZ
CALC( varD, varX, varY, varZ, "++" ); // varD = ( varX + varY ) + varZ
CALC( varD, varX, varY, varZ, "+-" ); // varD = ( varX + varY ) - varZ
CALC( varD, varX, varY, varZ, "-+" ); // varD = ( varX - varY ) + varZ
CALC( varD, varX, varY, varZ, "--" ); // varD = ( varX - varY ) - varZ
CALC( varD, varX, varY, varZ, "**" ); // varD = ( varX * varY ) * varZ
CALC( varD, varX, varY, varZ, "*/" ); // varD = ( varX * varY ) / varZ
CALC( varD, varX, varY, varZ, "/*" ); // varD = ( varX / varY ) * varZ
CALC( varD, varX, varY, varZ, "//" ); // varD = ( varX / varY ) / varZ
* varX operator1 varY is always performed first followed by operator2 varZ

eg
CALC(varIndex,varIndex,1,128,"+%"); // Buffer wrapping: varIndex = ( varIndex + 1 ) % 128
CALC(varX2,DISPX,2,1,"/-"); // Centre of display: varX2 = ( DISPX / 2 ) - 1
CALC(hours_f,Time.mins,60,Time.hours,"/+"); // Fractional hours: hours_f = ( Time.mins / 60 ) + Time.hours
 

Command CALC - ++ / -- Increment/Decrement - v49.51
 
Description CALC(num,''++''); and CALC(num,''--'');

Added:
CALC( dst, "++" ); // dst = dst + 1;
CALC( dst, src, "++" ); // dst = src + 1;
CALC( dst, "--" ); // dst = dst - 1;
CALC( dst, src, "--" ); // dst = src - 1;
 
Syntax/Parameters VAR(a,0,U8);
VAR(b,0,U8);

CALC(a,"++");
a=1
CALC(a,"++");
a = 2
CALC(b,a,"++");
b=3
CALC(b,"--");
b=2
 

Command CALC -Maths Functions
 
Description This provides a fast simple calculation placed in the Result variable according to the type
of Method using + , - , / , *, %(modulus) or logical functions | (OR)  & (AND) ^ (EXOR) for non float.
 
Syntax/Parameters CALC(Result,VarA,VarB,Method)

ABS - Absolute Value of varX - CALC( varD, varX, "ABS" );
EXP  - Exponential Function of varX - CALC( varD, varX, "EXP" );
LOG  - Natural Logarithm of varX - CALC( varD, varX, "LOG" );
LOG10 - Base-Ten Logarithm of varX - CALC( varD, varX, "LOG10" );
POW - varX Raised to the Power of vary - CALC( varD, varX, varY,"POW");
SQRT - Non-Negative Square Root of varX - CALC( varD, varX, "SQRT" );
CBRT - Cube Root of varX - CALC( varD, varX, "CBRT" );
 
RND - Random Number Generation - CALC( varD, varX, "RND" ); - v49.08     
 

Command CALC - Trigonometric Functions
 
Description This provides a fast simple calculation placed in the Result variable according to the type
of Method using + , - , / , *, %(modulus) or logical functions | (OR)  & (AND) ^ (EXOR) for non float.
 
Syntax/Parameters varD is result, varX is source, set system parameter angle=degres or radians;
COS - Cosine of varX - CALC( varD, varX, "COS" );
SIN - Sine of varX - CALC( varD, varX, "SIN" );
TAN - Tangent of varX - CALC( varD, varX, "TAN" );

ACOS - Arc Cosine of varX - CALC( varD, varX, "ACOS" );
ASIN - Arc Sine of varX - CALC( varD, varX, "ASIN" );
ATAN - Arc Tangent of varX - CALC( varD, varX, "ATAN" );
ATAN2 - Arc Tangent of varX/varY - CALC( varD, varX, varY, "ATAN2" );

COSH - Hyperbolic Cosine of varX - CALC( varD, varX, "COSH" );
SINH - Hyperbolic Sine of varX - CALC( varD, varX, "SINH" );
TANH - Hyperbolic Tangent of varX - CALC( varD, varX, "TANH" );
ACOSH - Hyperbolic Arc Cosine of varX - CALC( varD, varX, "ACOSH" );
ASINH - Hyperbolic Arc Sine of varX - CALC( varD, varX, "ASINH" );
ATANH - Hyperbolic Arc Tangent of varX - CALC( varD, varX, "ATANH
" );
 

Command CALC - RND - Random Number Generation
 
Description Gives varD equal to a Random number (0 to 0.999999) multiplied by varX.
 
Syntax/Parameters CALC( varD, varX, "RND" );
 

Topic

Text and Cursor Handling

 
Description Calc can be used for text and cursor manipulation where editable text is to be placed on the screen as in a calculator or editable text field. Various methods allow cursor movement and type, text insertion and deletion, find or delete text, cursor position and length.
VarA contains the existing text and VarB the modifier text, cursor position or a text length.
   Example: CALC(EditBox,EditBox, "A","INS"); Inserts the letter 'A' into the text at the cursor position
 
Cursor and Text Types
\\01 defines the text as a PASSWORD so that only ***** are shown until another \\01 or end;.
\\02 defines a hidden cursor with over write and \\03 a hidden cursor with insert ON
\\04 defines an underline cursor with over write and \\05 an underline cursor with insert ON
\\06 defines a block cursor with over write and \\07 a ertical cursor with insert ON

A detailed description follows for each method.
'dst' and 'src' can be the same text variable.
'src' is unmodified unless same text variable as 'dst'.
Supported data types:
The parameters can be text, numeric, variables or pointers as appropriate

   
Command CALC - POS - Move Cursor to Absolute Position
 
Description Moves cursor in text 'src' to absolute position 'pos' and stores result text in 'dst'.
If 'pos' is less than zero, then cursor is put before first character ('pos'=0). If 'pos' is greater than
the length of 'src' then the cursor is placed after the last character.
 
Syntax/Parameters CALC( dst, src, pos, "POS" );
 

Command CALC - REL - Move Cursor to Relative Position
 
Description Moves cursor in text 'src' by displacement specified in 'mov' and stores result text in 'dst'.
Positive values of 'mov' move the cursor to the right and negative values of 'mov' move the cursor to the left. If the move results in a cursor position of less than zero, then the cursor is put before first character. If the move results in a cursor position greater than the length of 'src' then the cursor is placed after the last character.
 
Syntax/Parameters CALC( dst, src, mov, "REL" );
 

Command CALC - INS - Insert / Overwrite Text at Cursor
 
Description  Puts text from 'src2' into 'src1' at the cursor and stores the result text in 'dst'.
 The text will either be overwritten or inserted depending on the cursor type in 'src1'.
 If no cursor is present then the text is appended to the end of 'src1'.
'src1' and 'src2' are unmodified unless same text variable as 'dst'
 
Syntax/Parameters CALC( dst, src1, src2, "INS" );
 

Command CALC - DEL - Delete Text at Cursor
 
Description Deletes 'num' characters from text 'src' at the cursor and stores the result text in 'dst'.
If 'num' is positive, then 'num' characters will be deleted after cursor. If 'num' is negative, then -'num' characters will be deleted before cursor (backspace).
If no cursor is present and 'num' is negative, then -'num' characters will be deleted from the end of the text in 'src'. If no cursor is present and 'num' is positive, then 'num' characters will be deleted from the start of the text in 'src'.
 
Syntax/Parameters CALC( dst, src, num, "DEL" );
 

Command CALC - TRIM - Trim Characters from Start and End of Text String
 
Description Removes all text characters found in 'list' from the start and end of text in 'src' and stores the result text in 'dst'. If 'list' is "" (empty string) then spaces (20hex), tabs (09hex), line feeds (0Ahex), and carriage returns (0Dhex) are removed.
 
Syntax/Parameters CALC( dst, src, list, "TRIM" );
 

Command CALC - LTRIM - Trim Characters from Start of Text String
 
Description Removes all text characters found in 'list' from the start of text in 'src' and stores the result text in 'dst'. If 'list' is "" (empty string) then spaces (20hex), tabs (09hex), line feeds (0Ahex), and carriage returns (0Dhex) are removed.
 
Syntax/Parameters CALC( dst, src, list, "LTRIM" );
 

Command CALC - RTRIM - Trim Characters from End of Text String
 
Description Removes all text characters found in 'list' from the end of text in 'src' and stores the result text in 'dst'. If 'list' is "" (empty string) then spaces (20hex), tabs (09hex), line feeds (0Ahex), and carriage returns (0Dhex) are removed.
 
Syntax/Parameters CALC( dst, src, list, "LTRIM" );
 

Command CALC - UPPER - Convert Text to Uppercase
 
Description Converts the characters 'a'-'z' to uppercase 'A'-'Z' in text 'src' and stores result text in 'dst'.
 
Syntax/Parameters CALC( dst, src, 0, "UPPER" );
 

Command CALC - LOWER - Convert Text to Lowercase
 
Description Converts the characters 'A'-'Z' to lowercase 'a'-'z' in text 'src' and stores result text in 'dst'.
 
Syntax/Parameters CALC( dst, src, 0, "LOWER" );
 

Command CALC - BEF - Get Characters from Before Cursor
 
Description 'num' characters are copied from before the cursor in text 'src' and stored in text 'dst'.
If no cursor in present then 'num' characters are copied from the end of 'src'.
If 'num' is larger than the number of characters available in 'src' then only the available characters are copied. If 'num' is negative, then the function performs as "AFT".
 
Syntax/Parameters CALC( dst, src, num, "BEF" );
 

Command CALC - AFT - Get Characters from After Cursor
 
Description 'num' characters are copied from after the cursor in text 'src' and stored in text 'dst'.
If no cursor in present then 'num' characters are copied from the start of 'src'.
If 'num' is larger than the number of characters available in 'src' then only the available characters are copied. If 'num' is negative, then the function performs as "BEF".
 
Syntax/Parameters CALC( dst, src, num, "AFT" );
 

Command CALC -CUR - Change Cursor Type
 
Description The cursor in text 'src' is changed to type 'type' and the result is stored in text 'dst'.
If no cursor is present, then the new cursor is appended to the end.
 If 'type' is a string then the first character is taken as the cursor type.
'type' => integer variable | pointer to integer variable | integer | text variable | pointer to text variable | "string" 
 
Syntax/Parameters CALC( dst, src, type, "CUR" );
 

Command CALC - LEN - Get Text Length
 
Description The length of text 'src' plus 'num' is stored in variable 'len'.
Cursor characters are not included in the length.
 
Syntax/Parameters CALC( len, src, num, "LEN" );
 

Command CALC - LOC - Get Cursor Location
 
Description The location of the cursor in text 'src' plus 'num' is stored in variable 'loc'.
If no cursor is present then a value of 0 is used.
 
Syntax/Parameters CALC( loc, src, num, "LOC" );
 

Command CALC - TYPE - Get Cursor Type
 
Description The cursor type in text 'src' is stored in variable 'type'.
If no cursor is present then a value of 0 is used.
 
Syntax/Parameters CALC( type, src, 0, "TYPE" );
 

Command CALC - FIND - Find Location of Text1 in Text2
 
Description The first location of the match of text 'src2' (needle) in text 'src1' (haystack) is returned in 'loc'.
If no matches are found then -1 is returned in 'loc'.
Cursor characters are not included in the calculation.
 
Syntax/Parameters CALC( loc, src1, src2, "FIND" );
 

Command CALC - LFIND - Find Location of last Text1 in Text2
 
Description The last location of the match of text 'src2' (needle) in text 'src1' (haystack) is returned in 'loc'.
If no matches are found then -1 is returned in 'loc'.
Cursor characters are not included in the calculation. 
 
Syntax/Parameters CALC( loc, src1, src2, "LFIND" );
 

Command CALC - IFIND - Find Location of Case Insensitive Text1 in Text2
 
Description The first location of the case insensitive match of text 'src2' (needle) in text 'src1' (haystack) is returned in 'loc'
If no case insensitive matches are found then -1 is returned in 'loc'.
Cursor characters are not included in the calculation.
 
Syntax/Parameters CALC( loc, src1, src2, "FIND" );
 

Command CALC - ILFIND - Find Location of last Case Insensitive Text1 in Text2
 
Description The last location of the case insensitive match of text 'src2' (needle) in text 'src1' (haystack) is returned in 'loc'
If no case insensitive matches are found then -1 is returned in 'loc'.
Cursor characters are not included in the calculation.
 
Syntax/Parameters CALC( loc, src1, src2, "FIND" );
 

Command CALC - REM - Remove Every Text1 in Text2
 
Description Remove every occurrence of text 'src2' (needle) from text 'src1' (haystack) and store the result
text in 'dst'.
 
Syntax/Parameters CALC( dst, src1, src2, "REM" );
 

Command CALC - IREM - Remove Every Case Insensitive Text1 in Text2
 
Description Remove every case insensitive occurrence of text 'src2' (needle) from text 'src1' (haystack) and store the result text in 'dst'.
 
Syntax/Parameters CALC( dst, src1, src2, "IREM" );
 

Command CALC - SPLIT - Split Text at Character or String
 
Description Split the text 'src' at the character 'char' or string 'str' storing the text after 'char' or 'str' back into 'src' and storing the text
before 'char' or 'str' into 'dst' or converting to number 'num'. If no 'char' or 'str' are present then the whole of 'src' is processed.
If we have string 'str' then the first character is taken as the split character. 'src' is modified during this operation.
See BCUT for similar function where length is used instead of delimiter.

Added count option to split after nth occurrence of split string.
If n is positive then split at nth occurrence from start of src.
If n is negative then split at nth occurrence from end of src.
CALC( dst, src, str, n, "SPLIT" );
 
Syntax/Parameters CALC( dst, src, char, "SPLIT" );
CALC( num, src, char, "SPLIT" );
CALC( dst, src, str, "SPLIT" );

CALC( dst, src, str, n, "SPLIT" );
Examples (assuming 's' is set each time):
VAR(s,"Theheshethee",TXT);
VAR(d,"",TXT);
     CALC(d,s,"e","SPLIT"); // d="Th"; s="heshethee"
     CALC(d,s,"she","SPLIT"); // d="Thehe"; s="thee"
     CALC(d,s,\\65,"SPLIT"); // d="Th"; s="heshethee"
     CALC(d,s,"e",2,"SPLIT"); // d="Theh"; s="shethee"
     CALC(d,s,"e",20,"SPLIT"); // d="Theheshethee"; s=""
     CALC(d,s,"p",2,"SPLIT"); // d="Theheshethee"; s=""
     CALC(d,s,"e",-2,"SPLIT"); // d="Thehesheth"; s="e"
     CALC(d,s,"e",-20,"SPLIT"); // d="Theheshethee"; s=""
     CALC(d,s,"she",-1,"SPLIT"); // d="Thehe"; s="thee"
     CALC(d,s,"he",-1,"SPLIT"); // d="Theheshet"; s="e"
     CALC(d,s,"he",-2,"SPLIT"); // d="Thehes"; s="thee"
 

Command CALC - PIXX - Get Width of Entity
 
Description The display width in pixels of entity 'ent' plus 'num' is stored in 'size'.
Note, variables do not have a size and return 0. Text, image, draw, touch keys, and pages do have sizes.
 
Syntax/Parameters CALC( size, ent, num, "PIXX" );
 

Command CALC - PIXY - Get Height of Entity
 
Description The display height in pixels of entity 'ent' plus 'num' is stored in 'size'.
Note, variables do not have a size and return 0. Text, image, draw, touch keys, and pages do have sizes.
 
Syntax/Parameters CALC( size, ent, num, "PIXY" );
 

Command CALC - PCOPY - Pointer Copy
 
Description Pointers can be copied using CALC(dst,src,"PCOPY");
 
Syntax/Parameters CALC(dst,src,"PCOPY");
Example:
     VAR( v1 > "v3", PTR );
     VAR( v2 > "v4", PTR );
     VAR( v3, "alpha", TXT );
     VAR( v4, "beta", TXT );
     gives: v1>v3; v2>v4; v1=alpha; v2=beta; v3=alpha; v4=beta      CALC( v1, v2, "PCOPY" );
     gives: v1>v4; v2>v4; v1=beta; v2=beta; v3=alpha; v4=beta
 

Command CALC - SHIFT - Array Data Shift
 
Description Function shifts the values in an array up or down its indices.
> CALC( array, carry, shift, "SHIFT" );
> CALC( array, shift, "SHIFT" );
- 'array' is shifted by 'shift' places, one shift at a time.
- If 'shift' is positive then array.1 -> array.2; array.0 -> array.1 etc
- If 'shift' is negative then array.1 -> array.0; array.2 -> array.1 etc
- The shift is 'circular', so the shifted out value is shifted in the other end.
- If 'carry' is specified then the shift passes through the carry, ie the carry is shifted in and a new carry is shifted out.
 
Syntax/Parameters CALC( array, carry, shift, "SHIFT" );
CALC( array, shift, "SHIFT" );
 

Command CALC - MIN
 
Description Function obtains the minimum values stored in an array.
The minimum value in the 'array' is stored in 'val'

CALC(...''MIN''); - v49.48
* The minimum of 2 or 3 numbers can now be calculated
* CALC( varD, varX, varY, [varZ,] "MIN" ); // varD = MINIMUM of varX and varY (and varZ if present)
eg
CALC( varD, 10, 20, "MIN" ); // varD = 10
CALC( varD, 100, -69, 5, "MIN" ); // varD = -69
 
Syntax/Parameters CALC( val, array, "MIN" );
 

Command CALC - MAX
 
Description Function obtains the maximum values stored in an array.
The maximum value in the 'array' is stored in 'val'

CALC(...''MAX''); - v49.48

* The maximum of 2 or 3 numbers can now be calculated
* CALC( varD, varX, varY, [varZ,] "MAX" ); // varD = MAXIMUM of varX and varY (and varZ if present)
eg
CALC( varD, 100, -69, 5, "MAX" ); // varD = 5
CALC( varD, 29.345, -200.4, "MAX" ); // varD = 29.345
 
Syntax/Parameters CALC( val, array, "MAX" );
 

Command CALC - BCOPY - Buffer Copy - Copy n bytes
 
Description Copy length from start of src or if length negative, from end
Copy length from posn of src or if length negative, before posn 
 
Syntax/Parameters CALC(dst,src,len,"BCOPY"); 
CALC(dst,sc,pos,len,"BCOPY");
 

Command CALC - BCUT - Buffer Cut - Cut n bytes
 
Description Cut length from start of src or if length negative, from end and put in dst. src is modified
Cut length from posn of src or if length negative, before posn and put in dst. src is modified 
 
Syntax/Parameters CALC(dst,src,len,"BCUT");
CALC(dst,src,pos,len,"BCUT"); 
 

Command CALC -BBINS - Buffer Insert - Insert bytes at position
 
Description Insert insvar at posn of src 
 
Syntax/Parameters CALC(dst,src,insvar,pos,"BINS"); 
 

Command CALC - BREP - Buffer Replace - Replace bytes at position
 
Description Replace from pos of src insvar content and save in dest
 
Syntax/Parameters CALC(dst,src,insvar,pos,"BREP");
 

Command CALC - BFIND - Buffer Find - Locate data from position
 
Description Find first location of fvar content from pos of src. Returns -1 if not exist
 
Syntax/Parameters CALC(dst,src,fvar,"BFIND"); 
 

Command CALC - BLFIND - Buffer Find Last - Locate last data from position
 
Description Find last location of fvar content from pos of src. Returns -1 if not exist  
 
Syntax/Parameters CALC(dst,src,fvar,"BLFIND"); 
 

Command CALC - BLEN - Get Buffer Length - Calculate number of bytes
 
Description Dst is length of src + num
 
Syntax/Parameters CALC(dst,src,num,"BLEN"); 
 

Command CALC - BTRIM - Buffer Trim Start and End - Remove bytes beginning and end 
 
Description Remove bytes in trimvar from front and end of src
 
Syntax/Parameters CALC(dst,src,trimvar,"BTRIM");
 

Command CALC - BLTRIM - Buffer Trim Start - Remove bytes from start 
 
Description Remove bytes in trimvar from front of src
 
Syntax/Parameters CALC(dst,src,trimvar,"BLTRIM");  
 

Command CALC - BRTRIM - Buffer Trim End - Remove bytes from end
 
Description Remove bytes in trimvar from end of src
 
Syntax/Parameters CALC(dst,src,trimvar,"BRTRIM"); 
 

Command CALC - BREM - Buffer Remove - Find and remove bytes
 
Description Remove every occurance of remvar from src
 
Syntax/Parameters CALC(dst,src,remvar,"BREM");
 

Command CALC - BCNV - Convert hex data in buffer to number
 
Description Ability to convert hex data in buffer to number.
 
Syntax/Parameters CALC( dstVar, srcTxtVar, "HEX8A", "BCNV" ); // Convert 2 ASCII hex chars
CALC( dstVar, srcTxtVar, "HEX8D", "BCNV" ); // Convert 1 Binary char
CALC( dstVar, srcTxtVar, "HEX16A", "BCNV" ); // Convert 4 ASCII hex chars
CALC( dstVar, srcTxtVar, "HEX16D", "BCNV" ); // Convert 2 Binary chars
CALC( dstVar, srcTxtVar, "HEX24A", "BCNV" ); // Convert 6 ASCII hex chars
CALC( dstVar, srcTxtVar, "HEX24D", "BCNV" ); // Convert 3 Binary chars
CALC( dstVar, srcTxtVar, "HEX32A", "BCNV" ); // Convert 8 ASCII hex chars
CALC( dstVar, srcTxtVar, "HEX32D", "BCNV" ); // Convert 4 Binary chars
Example
     VAR( varSrc, "12AB0123", TXT );
     VAR( varU32, 0, U32 );
     CALC( varU32, varSrc, "HEX32A", "BCNV" );
     LOAD( RS2, varU32 ); \\ Outputs 313196835
     LOAD( RS2, %h08%varU32 ); \\ Outputs 12ab0123
 

Command CALC - BREPB - Buffer Replace - Replace all occurrences of one string (buffer) with another (buffer)
 
Description Function to replace all occurrences of one string (buffer) with another (buffer)
CALC( dst, src, search, replace, "BREPB" );
All occurrences of 'search' in 'src' are replaced with 'replace' and the result is stored in 'dst'
dst and src can be the same variable.
 
Syntax/Parameters Examples
     VAR(s,"Theheshethee",TXT); VAR(d,"",TXT);
     CALC(d,s,"e","","BREPB"); // d="Thhshth"; s="Theheshethee"
     CALC(d,s,"e","ABC","BREPB"); // d="ThABChABCshABCthABCABC"; s="Theheshethee"
     CALC(d,s,"she","ABC","BREPB"); // d="TheheABCthee"; s="Theheshethee"
     CALC(d,s,"SHE","ABC","BREPB"); // d="Theheshethee"; s="Theheshethee"
     CALC(s,s,"e","ABC","BREPB"); // d=""; s="ThABChABCshABCthABCABC"
 

Command CALC - BCUTB - Buffer Cut - Cut chars from start of string (buffer)
 
Description Functions to cut chars from start of string (buffer)
CALC( dst, src, "str", n, "BCUTB" ); // cut up to "str" in src
CALC( dst, src, "str", "BCUTB" ); // cut up to 1st "str" in src
If n is positive then cut at nth occurrence from start of src
If n is negative then cut at nth occurrence from end of src
dst and src can be the same variable.
 
Syntax/Parameters Examples
     VAR(s,"Theheshethee",TXT); VAR(d,"",TXT);
     CALC(d,s,"e","BCUTB"); // d="eheshethee"; s="Theheshethee"
     CALC(d,s,"she","BCUTB"); // d="shethee"; s="Theheshethee"
     CALC(d,s,\\65,"BCUTB"); // d="eheshethee"; s="Theheshethee"
     CALC(d,s,"e",2,"BCUTB"); // d="eshethee"; s="Theheshethee"
     CALC(d,s,"e",20,"BCUTB"); // d=""; s="Theheshethee"
     CALC(d,s,"p",2,"BCUTB"); // d=""; s="Theheshethee"
     CALC(d,s,"e",-2,"BCUTB"); // d="Theheshethe"; s="Theheshethee"
     CALC(d,s,"e",-20,"BCUTB"); // d=""; s="Theheshethee"
     CALC(d,s,"she",-1,"BCUTB"); // d="Theheshe"; s="Theheshethee"
     CALC(d,s,"he",-1,"BCUTB"); // d="Theheshethe"; s="Theheshethee"
     CALC(d,s,"he",-2,"BCUTB"); // d="Theheshe"; s="Theheshethee"
     CALC(s,s,"e",2,"BCUTB"); // d=""; s="eshethee"
 

Command CALC - BCUTBI - Buffer Cut - Cut chars from end of string(buffer)
 
Description Functions to cut chars from end of string (buffer)
CALC( dst, src, "str", n, "BCUTBI" ); // cut up to and including "str" in src
CALC( dst, src, "str", "BCUTBI" ); // cut up to and including 1st "str" in src
If n is positive then cut at nth occurrence from start of src
If n is negative then cut at nth occurrence from end of src
* dst and src can be the same variable.
 
Syntax/Parameters * Examples
     VAR(s,"Theheshethee",TXT); VAR(d,"",TXT);
     CALC(d,s,"e","BCUTBI"); // d="heshethee"; s="Theheshethee"
     CALC(d,s,"she","BCUTBI"); // d="thee"; s="Theheshethee"
     CALC(d,s,\\65,"BCUTBI"); // d="heshethee"; s="Theheshethee"
     CALC(d,s,"e",2,"BCUTBI"); // d="shethee"; s="Theheshethee"
     CALC(d,s,"e",20,"BCUTBI"); // d=""; s="Theheshethee"
     CALC(d,s,"p",2,"BCUTBI"); // d=""; s="Theheshethee"
     CALC(d,s,"e",-2,"BCUTBI"); // d="Thehesheth"; s="Theheshethee"
     CALC(d,s,"e",-20,"BCUTBI"); // d=""; s="Theheshethee"
     CALC(d,s,"she",-1,"BCUTBI"); // d="Thehe"; s="Theheshethee"
     CALC(d,s,"he",-1,"BCUTBI"); // d="Theheshet"; s="Theheshethee"
     CALC(d,s,"he",-2,"BCUTBI"); // d="Thehes"; s="Theheshethee"
     CALC(s,s,"e",2,"BCUTBI"); // d=""; s="shethee"
 

Command CALC - FEXISTS
 
Description Checks for existence of file in NAND or on SDHC card using CALC(dstVar, src, "FEXISTS");
Returns dstVar=0 if file 'src' does not exist, or dstVar=1 if the file 'src' exists
 
Syntax/Parameters CALC(dstVar, src, "FEXISTS");
 

Command CALC - FREAD
 
Description A text file can be read into a text buffer using CALC(dstTxtVar, src, "FREAD");
The buffer must be bigger than the file size
 
Syntax/Parameters CALC(dstTxtVar, src, "FREAD");
 

Command CALC - DIR - directory listing
 
Description Text variable can be populated with filenames in NAND:
 
Syntax/Parameters CALC( dstTxtVar, src, filter, sep, "DIR" );
CALC( dstTxtVar, src, filter, "DIR" );
CALC( dstTxtVar, src, "DIR" );

dstTxtVar is a text variable and will contain number of files and subdirectories in list followed by specified separator between each filename. src is "nand" (in quotes). sep is separator character for filenames and subdirectories in string (must be in quotes),
if not included then "," assumed

filter is types of files to list, supported filters:
"*/" - list all files and subdirectories
"*.*", "*",
"*.bmp", "*.jpg", "*.png" (or "img" to get all image files)
"*.wav", "*.mp3", "*.wma" (or "snd" to get all sound files)
"*.fnt",
"*.txt",
"*.mnu",
"*.bin", 
"*.tft", 
"*.log", 
"*.ppf", 
"*.tri"
If not specified then "*" assumed.
Multiple filters can be included, separated by commas: "*.bmp,*.jpg,*.fnt"

Examples: (nand contains 1.bmp, 2.bmp, x.mnu)
     CALC( txtVar, "nand", "*.bmp", ",", "DIR" ); // list all bitmap image files
     > txtVar = "2,1.bmp,2.bmp";
     CALC( txtVar, "nand", "*.fnt", "DIR" ); // list all font files
     > txtVar = "0";
     CALC( txtVar, "nand", "*.mnu", "DIR" ); // list all menu files
     > txtVar = "1,x.mnu";
     CALC( txtVar, "nand", "DIR" ); // list all files
     CALC( txtVar, "nand", "*", "DIR" ); // same
     CALC( txtVar, "nand", "*", ",", "DIR" ); // same
     > txtVar = "3,x.mnu,1.bmp,2.bmp";
 

Command CALC - FINFO - Get Info
 
Description Get info Function -
Fills dest string with the following :
filename, title, artist, length, samplerate, bitspersample, numchannels
 
Syntax/Parameters CALC( dest, filename, "FINFO" );
 

Command CALC -Checksums - "MCHK", "TCHK"
 
Description Add a checksum and check for a checksum error
 
Syntax/Parameters CALC( dst, src, "type", "MCHK" ); // Copy src buf to dst buf, make checksum of "type" and append to dst buf
CALC( res, src, "type", "TCHK" ); // Test checksum of "type" in src buf and set res to 1 if checksums same, else 0.

where "type" is:
"SUM8ZA" - Sum all data in src as type U8, checksum is two's complement of the sum, stored as two ASCII hexadecimal characters
                                                                           (when sum added to checksum is zero, res is 1)
"SUM8ZD" - Sum all data in src as type U8, checksum is two's complement of sum, stored as single U8
                                                                          (when sum added to checksum is zero, res is 1)
"SUM8A" - Sum all data in src as type U8, checksum is sum, stored as two ASCII hexadecimal characters
                                                                           (when sum is same as checksum, res is 1)
"SUM8D" - Sum all data in src as type U8, checksum is sum, stored as single U8
                                                                           (when sum is same as checksum, res is 1)
"XOR8A" - Exclusive-OR (XOR) of all data in src as type U8, checksum is XOR, stored as two ASCII hexadecimal characters
                                                                          (when XOR of src with checksum is zero, res is 1)
"XOR8D" - Exclusive-OR (XOR) of all data in src as type U8, checksum is XOR, stored as single U8
                                                                           (when XOR of src with checksum is zero, res is 1)
Example:
     LOAD(txData,"1234");
     FUNC(SendData)
     {
     CALC(txData,txData,"SUM8ZA","MCHK"); // Add checksum (txData="123436")
     LOAD(RS2,txData); // Send data
     }

     FUNC(ReceiveData)
     {
     LOAD(rxData,RS2); // Read data
     CALC(res,rxData,"SUM8ZA","TCHK"); // Check for checksum error
     IF(res=1?ProcessData:DataError);
     }
 

Command CALC - CRC16 - 16 support
 
Description * Support for additional CRC-16 algorithms.
> Note CALC( dst32, srcBuf, length, "", "CRC16" ); will use the MODBUS ("modbus") algorithm
 
CALC() "type" Poly-nominal Initial  Value Reflect
In
Reflect Out XOR Out Value Names and aliases
"arc" 0x8005 0x0000 Yes Yes 0x0000 "ARC", "CRC-16", "CRC-IBM", "CRC-16/ARC", "CRC-16/LHA"
"kermit" 0x1021 0x0000 Yes Yes 0x0000 "KERMIT" "CRC-16/CCITT", "CRC-16/CCITT-TRUE", "CRC-CCITT"
"modbus" 0x8005 0xFFFF, Yes Yes 0x0000 "MODBUS"
"x-25" 0x1021 0xFFFF Yes Yes 0xFFFF "X-25", "CRC-16/IBM-SDLC", "CRC-16/ISO-HDLC", "CRC-B"
"xmodem" 0x1021 0x0000 No No 0x0000 "XMODEM", "ZMODEM", "CRC-16/ACORN"
"ccitt-f" 0x1021 0xFFFF No No 0x0000 "CRC-16/CCITT-FALSE"
"usb" 0x8005 0xFFFF Yes Yes 0xFFFF, "CRC-16/USB"
"spi" 0x1021 0x1D0F No No 0x0000 "CRC-16/SPI-FUJITSU", "CRC-16/AUG-CCITT"
"buypass" 0x8005 0x0000 No No 0x0000 "CRC-16/BUYPASS", "CRC-16/VERIFONE"
"dds-110" 0x8005 0x800D No No 0x0000 "CRC-16/DDS-110"
"dect-r" 0x0589 0x0000 No No 0x0001 "CRC-16/DECT-R"
"dect-x" 0x0589 0x0000 No No 0x0000 "CRC-16/DECT-X"
"dnp" 0x3D65 0x0000 Yes Yes 0xFFFF "CRC-16/DNP"
"en13757" 0x3D65 0x0000 No No 0xFFFF "CRC-16/EN-13757"
"genibus" 0x1021 0xFFFF No No 0xFFFF "CRC-16/GENIBUS", "CRC-16/EPC", "CRC-16/I-CODE", "CRC-16/DARC"
"maxim" 0x8005 0x0000 Yes Yes 0xFFFF "CRC-16/MAXIM"
"mcrf4xx" 0x1021 0xFFFF Yes Yes 0x0000 "CRC-16/MCRF4XX"
"riello", 0x1021 0xB2AA Yes Yes 0x0000 "CRC-16/RIELLO"
"t10-dif", 0x8BB7 0x0000 No No 0x0000 "CRC-16/T10-DIF"
"teledsk" 0xA097 0x0000 No No 0x0000 "CRC-16/TELEDISK"
"tms371x" 0x1021 0x89EC Yes Yes 0x0000 "CRC-16/TMS37157"
"a" 0x1021 0xC6C6 Yes Yes 0x0000 "CRC-A"

* Results have been confirmed using the "123456789" test with the values at http://regregex.bbcmicro.net/crc-catalogue.htm

 
Syntax/Parameters CALC( dst16, srcBuf, length, "type", "CRC16" );
 

Command CALC - CRC32 -32 support
 
Description

* Support for CRC-32 algorithms
> Note CALC( dst32, srcBuf, length, "", "CRC32" ); will use the CRC-32 ("adcpp") algorithm

CALC()
"type"
Poly-nominal Initial  Value Reflect
In
Reflect Out XOR Out Value Names and aliases
"adcpp" 0x04C11DB7 0xFFFFFFFF Yes Yes 0xFFFFFFFF "CRC-32", "CRC-32/ADCCP", "PKZIP"
"bzip2" 0x04C11DB7 0xFFFFFFFF No No 0xFFFFFFFF "CRC-32/BZIP2", "CRC-32/AAL5", "CRC-32/DECT-B", "B-CRC-32"
"c" 0x1EDC6F41 0xFFFFFFFF Yes Yes 0xFFFFFFFF "CRC-32C", "CRC-32/ISCSI", "CRC-32/CASTAGNOLI"
"d" 0xA833982B 0xFFFFFFFF Yes Yes 0xFFFFFFFF "CRC-32D"
"mpeg-2" 0x04C11DB7 0xFFFFFFFF No No 0x00000000 "CRC-32/MPEG-2"
"posix" 0x04C11DB7 0x00000000 No No 0xFFFFFFFF "CRC-32/POSIX", "CKSUM"
"q" 0x814141AB 0x00000000 No No 0x00000000 "CRC-32Q"
"jamcrc" 0x04C11DB7 0xFFFFFFFF Yes Yes 0x00000000 "JAMCRC"
"xfer" 0x000000AF 0x00000000 No No 0x00000000 "XFER"

* Results have been confirmed using the "123456789" test with the values at http://regregex.bbcmicro.net/crc-catalogue.htm

 
Syntax/Parameters CALC( dst32, srcBuf, length, "type", "CRC32" );
 

Command CALC - MSPLIT -User Protocol Split
 
Description

Perform a multiple split of a buffer to a series of variables.
  >>> CALC( dstPtr, srcBuf, char, "MSPLIT" );

- The buffer 'srcBuf' is split at each 'char' and each result is stored in an incrementing series of variables prefixed with the name in 'dstPtr'.
- If 'dstPtr' contains "svar", the first variable will be 'svar0', then 'svar1', 'svar2', ..., 'svar9', 'svar10' etc.
- If a particular svarN is not defined then the result is not stored for that split.
- The data is stored in the format specified in each 'svarN' allowing the buffer to be split into text, unsigned/signed integers and floats.
Example
     VAR( dst > "svar", PTR );
     VAR( svar0, 0, U8 );
     VAR( svar1, 0, S32 );
     VAR( svar2, 0.0, FLT4 );
     VAR( svar3, "", TXT );
     VAR( buf, "123,-67,3.14,Hi", TXT );
     CALC( dst, buf, ",", "MSPLIT" );   // Gives: svar0 = 123, svar1 = -67, svar2 = 3.14, svar3 = "Hi"
   >>> CALC( dstPtrArray, srcBuf, char, "MSPLIT" );

- The buffer 'srcBuf' is split at each 'char' and each result is stored in the variables pointed to by  successive subscripts of the Pointer Array 'dstPtrArray'.
- The first variable will be the variable name stored in 'dstPtrArray.0', then 'dstPtrArray.1', 'dstPtrArray.2',
- If a particular 'dstPtrArray.N' is not a variable or not defined then the result is not stored for that split.
- The data is stored in the format specified in each 'dstPtrArray.N' variable allowing the buffer to be split into text, unsigned/signed integers and floats.
Example
     VAR( arr > "", PTR, 4 );
     VAR( alpha, 0, U8 );        LOAD( arr.0 > "alpha" );
     VAR( bravo, 0, S32 );       LOAD( arr.1 > "bravo" );
     VAR( charlie, 0.0, FLT4 );  LOAD( arr.2 > "charlie" );
     VAR( delta, "", TXT );      LOAD( arr.3 > "delta" );
     VAR( buf, "123,-67,3.14,Hi", TXT );
     CALC( arr, buf, ",", "MSPLIT" );
     // Gives: alpha = 123, bravo = -67, charlie = 3.14, delta = "Hi"

- Using this method with arrays of pointers, testing found the time to split 64 parameters using "MSPLIT"
  was 8ms compared to 64 individual "SPLIT"s which took 30ms.

 
Syntax/Parameters CALC( ... "MSPLIT" )
 

Command CALC - CFLT - Calc float to/from U32
 
Description Added function to convert a U32 containing a IEEE 754 binary 32 formatted float into a float and vice versa.
Action depends on source and destination types.
  > CALC( flt, u32, "CFLT" );  // Converts a float to IEEE 754 binary 32 formatted float
  > CALC( u32, flt, "CFLT" );  // Converts an IEEE 754 binary 32 formatted float to a float
 
Syntax/Parameters VALC( flt, u32, "CFLT" );
CALC( u32, flt, "CFLT" );

Example 1:
     var(f,0,FLT4);
     var(u,0,U32);
     load(f,68.123);
     calc(u,f,"cflt");
     load(rs2,"f=",f,"; u=",%H08%u,"\\0d\\0a");
     > f=68.1230; u=42883EFA

Example 2
     load(u,\\41460000);
     calc(f,u,"cflt");
     load(rs2,"f=",f,"; u=",%H08%u,"\\0d\\0a");
     > f=12.3750; u=41460000
 

Command CALC - Entity Information
 
Description * More Calc commands added to obtain entity information
> CALC(var,ename,"ESIZE"); -> returns allocated display size in bytes
> CALC(var,ename,"EDEL"); -> returns 1 if entity has been deleted, else 0
> CALC(var,ename,"EVIS"); -> returns 1 if entity is visible, else 0
> CALC(var,ename,"EALIGN"); -> returns value representing alignment:
0 = Top Left, 1 = Top Centre, 2 = Top Right,
3 = Centre Left, 4 = Centre Centre, 5 = Centre Right,
6 = Bottom Left, 7 = Bottom Centre, 8 = Bottom Right
 
Syntax/Parameters > CALC(var,ename,"ESIZE");
> CALC(var,ename,"EDEL");
> CALC(var,ename,"EVIS"); -
> CALC(var,ename,"EALIGN");
 
 
Command CALC(result,name,''EXISTS''); - v49.46
 
Description Entity Exists Test
* Added CALC(dst,name,"EXISTS"); to test whether entity "name" exists.
 
Syntax/Parameters VAR(varRes,0,U8);
VAR(varAlpha,0,U8);
CALC(varRes,varAlpha,"EXISTS"); // varRes = 1
CALC(varRes,varBeta,"EXISTS"); // varRes = 0
 

Command Array Sort - CALC(..."ASORT"); and CALC(..."ASORTR");
 
Description Added functions to sort arrays
CALC(arrname, "ASORT|ASORTR");
CALC(arrname.index, "ASORT|ASORTR");
Examples :-
VAR(arrname, 0, U8, 10);
LOAD(arrname, 9, 34, 2, 42, 102, 33, 52, 1, 67, 19);
CALC(arrname, "ASORT");
Results :-
arrname.0 = 1
arrname.1 = 2
arrname.2 = 9
arrname.3 = 19
arrname.4 = 33
arrname.5 = 34
arrname.6 = 42
arrname.7 = 52
arrname.8 = 67
arrname.9 = 102

VAR(arrname, 0, U8, 3, 4);
LOAD(arrname.0, 34, 2, 67, 4);
LOAD(arrname.1, 123, 45, 6, 127);
LOAD(arrname.2, 3, 109, 16, 5);
CALC(arrname, "ASORT");
Results :-
arrname.0 = 3, 109, 16, 5
arrname.1 = 34, 2, 67, 4
arrname.2 = 123, 45, 6, 127

VAR(arrname, 0, U8, 3, 4);
LOAD(arrname.0, 34, 2, 67, 4);
LOAD(arrname.1, 123, 45, 6, 127);
LOAD(arrname.2, 3, 109, 16, 5);
CALC(arrname.1, "ASORT");
Results :-
arrname.0 = 34, 2, 67, 4
arrname.1 = 6, 45, 123, 127
arrname.2 = 3, 109, 16, 5

Additional Len parameter added to sort only a specified number of elements

Array Sort - CALC(...''ASORT''); and CALC(...''ASORTR''); - Improvements - v49.39
* Added optional length parameter to sort only a specified number of elements :-
CALC(Arr [, len], "ASORT|ASORTR");
Renamed "RASORT" to "ASORTR".
 
Syntax/Parameters CALC(arrname, "ASORT");
CALC(arrname.index, "ASORT");
CALC(arrname, "ASORTR");
CALC(arrname.index, "ASORTR");

CALC(arrname,len, "ASORT");
CALC(arrname.index,len, "ASORT");
CALC(arrname,len, "ASORTR");
CALC(arrname.index,len, "ASORTR");