CTF Specifications and User Guide


By Tom Wheeley
Portions Tom Lynn
Magnus Werner
Roy Maclean

Last updated: 23 Jan 1997


INTRODUCTION



Rationale

One of the main problems with Casio calculator programs is that they are hard to represent on a normal computer. Although some of the special symbols available on the calculator can be represented on some systems (for example the squared symbol is in DOS), these are not compatible with all systems. Hence, a standard for writing programs should stick to the basic printable ASCII character set.

Other formats

Other standards used to represent programs are often not designed for reading by machines, as most programs were expected to be laboriously typed in by hand. Some formats are similar to the CTF format but with ambiguous symbols (for example 'e' meaning 'lower case e' as well as 'exponential'). Other people have released programs as pictures of the code, often created as a series of screenshots from the calculator. This method is especially unsuitable as it is very difficult for a computer to understand the picture, and cannot be viewed on text-only terminals.

The format used by Casio's original CASIOLINK software is the .CAS format which is effectively a dump of the serial transmission. This is easy for machines to read, but is unreadable for humans without special software.

History

Casio Text Format is the format I developed to use with my software CaS, (which converts between various formats, and communicates with the calculator) and has changed with improved versions of CaS. The standard has since been improved through discussion on the mailing list set up by Roy Maclean and now maintained by Magnus Werner.



PROGRAM TEXT SPECIFICATION AND USE



Casio Text Format files should have the extension .ctf

Word tokens

Generally, Casio Text Format files should be written exactly as they would appear on the calculator. This is true for all symbols (hereafter referred to as tokens) such as 'Plot','Line','Cls' and so on.

In the Casio calculator, all the 'functions' such as Plot and Line etc are not spelled out as 'P', 'l', 'o', 't'; but instead are referred to by a single number (henceforth called a ctoken). Thus the text 'P', 'l','o', 't' is interpreted to mean 'Plot'.

Symbolic tokens

For many common tokens, there is no direct ASCII equivalent, e.g. the sign for assigning a value to a variable. In these cases, the Casio Text Format uses a token which either appears similar to the calculator symbol or which denotes the meaning of the symbol. For example, the arrow used to assign a value to a variable is represented by `->'.

Common symbolic representations are:

-> assignment
=> 'then' in comparison statements
_ - Disp - triangle thing (at end of line)
>= greater than or equal to
<= less than or equal to
<> not equal to
* multiplication
/ division
% fraction delimiter (a%b%c=a+b/c)
^ power (x^y)

Descriptive tokens

Where a symbolic representation of a symbol is not possible without confusion of meanings, it is represented by a token which defines its action, rather than its appearance. These are usually preceded by a backslash `\' character.

Common representations of tokens in this way include:

\sqrtsquare root
\cbrtcube root
\nrtnth root (xth root on calc)
\^-1reciprocal
\sqr or \^2squared
\f1function memory 1
\A to \Fhexadecimal digits A to F
\rvariable `r' (meaning radius)
\thvariable `theta' (meaning angle)

Examples:

Pythagorus's theorem: \sqrt (A\sqr + B\^2) -> C
Odd or Even : A/2 = Int(A/2) => "Even"

Note that variables (except r and theta) must be in upper case, but you can use lower case letters in text strings. Text strings containing lower case can only be used in program mode when sent to the calculator from the computer via a cable, as lower case characters can only be entered manually to calculators in editor mode. However, even when using a fx7700 which does not allow user-entered lower case at all, it is possible to use lower case when using a cable.

Separating tokens

It is always possible that a combination of tokens will be meaningful as a third token, and interpreted as such when the two separate tokens are what is desired. In these cases, tokens may be separated using a pipe character | . eg asin is the arcsin function, but 'a|sin' is 'a','sin'.

Comments

As well as standard Casio ' comments, it is possible to enter comments into Casio Text Format files. Unlike Casio comments, these are not parsed and sent to the calculator, and can therefore be longer without using valuable memory.

Comments are delimited using either the hash '#' or semi-colon `;' after a space, newline or tab, and may be placed in most places. Note that as both are valid tokens in their own right, there are a couple of nuances:

Note also that all whitespace at the end of a line is stripped, including that in text. If you need <space><newline> in text, use the '\n' token to denote where the spaces end. (CTF allows both '<newline>' and '\n<newline>' to mean a single newline).

Spaces, cases and strings

Parsing of Casio Text Format files changes in many ways depending on the basic context of the text. This is to allow plenty of leeway for programs, whilst enabling exact formatting in text strings.

Bypassing tokens

Sometimes, power Casio users may need to specify the exact code for a token, rather than the token itself. This is posible using ctokens special codes used to refer to every possible token. Casio calculators support up to 767 such ctokens, depending on version (7700, 9700 and 9800 only support up to 511), and these can be specified in decimal, hexadecimal or octal using the @ sign.

eg: @d208 would insert a pi symbol (π) into the program (as 208 is the ctoken number for \pi)

To use either octal or hexadecimal in the number, replace the 'd' with 'o' or 'x' respectively. The actual number must consist of 3 digits, so it should be padded with leading zeros where necessary.

This feature is needed for the '@' and '|' tokens (@d064 and @d124), both of which have special meanings in CTF. This will not confound people entering programs by hand, as neither '@' nor '|' can be entered into the calculator!


SETTING THE FILE TYPE


The Casio calculator supports many different modes of data to be sent via the serial cable, and all of these can be stored in Casio Text Format files.

Program modes

The default file type in a Casio Text Format file is a standard COMP Single Program file. (NB. This type is not compatible with the fx9850 or fx9950 calculators)

To specify the program type, a program header is placed before the program:

@@ Prog (sd ssto)

The words in the parentheses specify the program type:

Base-NBase-n program (mode 2)
SDSingle variable statistics (mode 3)
LRBivariate statistics (mode 4)
MatrixMatrix mode (mode 5)
SStoStore statistics data (option)
SDrawDraw statistics graph (option)

Capitalisation is not important.

Multiple program files

To specify a multiple program file, precede each program with a program header, specifying a name:

@@ Prog A ()

"Hello"
Prog B

@@ Prog B (Base-n)

"World"

If you specify the same program twice in a file, the result is implementation dependant.

Editor files and 9850 programs

For even a single 9700/9800 Editor file or a 9850/9950 program, a filename and an optional password are specified:

@@Prog "filename" (password)

The filename is parsed as a set of tokens, as some of the characters used in filenames (eg '+', '-' and theta) are either not their ASCII equivalents or are more than one character long (eg '\th') in CTF.

More than one editor file can be placed in a single text file, by simply putting a new editor file header in front of each 'file'.

You can mix any type of data in a CTF file, be be warned that not all combinations can be transmitted to the calculator, depending on the software used. The next version of CaS will certainly be far more flexible in this matter than 1.0.x. currently is.

Preprocessor

Although not defined yet, various pieces syntax for a preprocessor are built into the CTF format. Modelled basically on the C and Turbo Pascal preprocessors, it will include such commands as:

$include "filename.ctf"
$define variable value
$ifdef variable
$endif

Defines can be accessed in code similarly to Makefiles and shell variables:


Range 1,${scrwidth},0,1,63,0

is an example which would allow portability between 7700 and 9700 graphical programs. (with other drawing code, obviously). The $ifdef will allow things like

$ifdef _9750+
  0->A~Z
$else
  Mcl
$endif

Various predefines (with leading underscore) should also be included in the software used, eg:

This is the section of CTF I am most uncertain about as I have not implemented it in software myself, so I haven't run into any problems in the standard which might require changing.

The main aim behind the preprocessor segment of CTF is to encourage portable programs which will instantly transfer to the widest range of calculators.


STYLE GUIDE



EPILOGUE


Tokens

The canonical list of Casio Text Format tokens is in the file 'ctf_tkns.txt'. A complete list of tokens supported by CaS is in the file 'ascii.tok'

Notes for implementors

CTF is a free standard, and anyone is welcome to write a program which uses it for any purpose. I will field any detailed questions regarding the format, and programmers are welcome to use the files token.c and ftxt.c from the CaS distribution if they comply with the CaS license (GPL).

It is essential when machine-reading CTF to specify the target calculator, as the codes used to send the data to the calculator are sometimes reused or renamed between models.

Credits