BBC BASIC (Z80) has a number of file-related functions that are accessible in this version. As the calculator OS does not have a traditional file system, there are some important rules to bear in mind.
The extension of the file is used to determine the type of file. If no extension is specified a default of .PRG is assumed. Filenames are case sensitive. If an invalid filename is specified, a 'Bad name' error is triggered.
Program variables are variable-length, random-access, general-purpose files that are listed on the PRGM menu on the TI-OS. They can have any filename up to 8 characters in length, which means that you can use BBC BASIC to create program variables that are not accessible via the TI-OS. For this reason it is strongly recommended that you only create program variables with UPPERCASE names and only use alphanumeric characters, with the exception of the first character which cannot be a number.
Here are some examples of good names:
Here are some examples of bad names:
- snake (lowercase characters)
- 3DCUBE.PRG (first character is a number)
- MY_MAZE.PRG (non-alphanumeric)
Here are some examples of invalid names:
- BATTLESHIPS.PRG (too long)
- Pong.prg (lowercase extension)
Application variables, or AppVars, follow the same rules as program variables. The main difference between the two types is that the TI-OS only allows access to application variables via the memory management menu; consider using application variables for resources or related data files for your program.
BBC BASIC allows you to work with the TI-OS picture variables Pic1 to Pic9 and Pic0. They have a fixed size (756 bytes) and support random access. You must specify their filename in the form PICn.PIC, where n is the number of the variable to access.
The following example program copies the top 63 rows of data from the graph buffer to Pic1.
10 S%=OPENOUT"PIC1.PIC" 20 GBUF%=&9340 30 FOR P%=0 TO 755 40 D%=GBUF%?P% 50 BPUT#S%,D% 60 NEXT 70 CLOSE#S%
BBC BASIC (Z80) lets you access certain hardware devices using the standard file manipulation routines. In these cases the supplied filename has .DEV as its extension.
The block copy routines do not work with hardware devices; you are only able to access them byte-by-byte.
Sony Serial Infrared Remote Control System (SIRCS.DEV)
By attaching a suitable adapter to the calculator's data port you can send and receive commands to and from SIRCS-compatible devices.
Most of the hard work is done in software so the adapter is very easy to build. No responsibility is accepted for any damage to your calculator as a result of using an adapter built from the above diagram.
Receiving command codes from a remote control is straightforwards. Each command code is 7 bits and can be read using BGET#:
Program execution will pause at BGET# until a command has been received.
A SIRCS remote control will transmit a device code along with the command code to tie the remote control to the device it is meant to be controlling. You can get or set the device code via PTR#.
The SIRCS protocol exists in 12-, 15- and 20-bit variations. Most common devices use the 12-bit variant. The PlayStation 2 console, however, uses the 20-bit variation. You can get or set the number of bits using EXT#.
The following program will wait for a command to be received from a remote control then display information on the screen about the data received.
sircs%=OPENIN"SIRCS.DEV" REPEAT C%=BGET#sircs% CLS PRINT "Command",~C% PRINT "Device ",~PTR#sircs% PRINT "Size ",EXT#sircs% UNTIL FALSE
To send a "cross" command (&5E) to a PlayStation 2 console (a 20-bit device with the code &1B5A) you could do the following:
sircs%=OPENOUT"SIRCS.DEV" EXT#sircs%=20 : REM Sending 20-bit commands. PTR#sircs%=&1B5A : REM PS/2 console has a device code of &1BFA BPUT#sircs%,&5E : REM &5E is the command code for "X".
Each command is transmitted six times in rapid succession for reliability.
See the SIRCS Command and Device Codes appendix for more information.