Scripting - jedimatt42/fcmd GitHub Wiki

Scripts are sequences of commands for Force Command organized in a text file. The TI must be able to open the file in DISPLAY VARIABLE 80 format, such as files created by the editor bundled with Texas Instruments Editor/Assembler package.

Scripts are invoked by specifying the name of a script on the PATH, or the fully qualified filename. Scripts may invoke other scripts and should return to the calling script when completed.

PATH is a special environment variable that defines what directories should be searched for scripts and binary extension to ForceCommand. By default PATH is not set. It can be set to a ; semicolon separated list of device and directory names. Path entries should end in a ..

For example, to have TIPI.BIN. on your path, and DSK5. issue the command:

PATH=TIPI.BIN.;DSK5.

Script names are case sensitive, and they cannot be found on the PATH if they coincide with built-in command names.

This simple example script will set the color to black on cyan, clear the screen, and then display the contents of a text file:

color 1 7
cls
type TIPI.MENU.WELCOME/TXT

Scripts can interact with the user if you want using the readkey command. And then you can utilize the conditional command if to take an alternative action.

BEGIN:
echo How are you? 1: happy, 2: sad
readkey K
if $K == 1 then goto HAPPY
if $K == 2 then goto SAD
echo Now I am mad
goto BEGIN
HAPPY:
echo Glad to hear that!
goto BEGIN
SAD:
echo Sorry to hear that.
goto BEGIN

In the above example a prompt is displayed to the user with the echo command. The script then waits for a keypress, and stores the value in the variable K. 2 conditional statements check for expected keys, and if matched, invoke a command. In this case they goto a label that is defined later in the file. If the conditionals don't change the code flow, then the program says it is mad, and goes back to the beginning.

You may press ALT-4 to break out of a script.

AUTOCMD - Running a script on startup

If the first device on your system has a file named AUTOCMD then this script will be run immediately instead of the display of the Force Command banner and tipibeeps.

The drives command will list all the devices in their search order. The first one in that list is the device AUTOCMD must reside on for it to be detected.

Script Example

This example of a MENU script can be saved to a D/V80 file and run in Force Command. It shows a number of things:

  1. setting color
  2. defining variables
  3. using ANSI escape codes in 'echo' statements
  4. reading a keypress into a variable
  5. using variables and if statements
  6. switching cartridge images
  7. goto statements
  8. loading EA5 programs
  9. setting DSK1 mapping on TIPI
  10. looping
color 1 7
cls
CLA=2
CLB=25
CLC=50
echo \e[2;20HJedimatt's TI-99/4A
echo \e[4;$(CLA)HX - Extended Basic
echo \e[6;$(CLA)HF - fbForth
echo \e[8;$(CLA)HT - Telnet
echo \e[4;$(CLB)HP - Parsec
echo \e[6;$(CLB)HD - Tunnels of Doom
echo \e[8;$(CLB)HC - Old Dark Caves
echo \e[4;$(CLC)HA - TI Artist Plus
echo \e[20;$(CLC)HQ - Quit
INPUT:
echo /n \e[24;1H
readkey K
if $(K) == X then fg99 TIXB_G
if $(K) == F then goto LFB
if $(K) == T then load TIPI.NET.TELNET
if $(K) == P then load TIPI.GAMES.EA5.PARSEC1
if $(K) == D then goto TOD
if $(K) == A then goto ARTIST
if $(K) == C then goto CAVES
if $(K) == Q then goto END
goto INPUT

LFB:
tipimap DSK1 TIPI.FB4TH210
fg99 FBFORTH

TOD:
tipimap DSK1 TIPI.GAMES.TOD
load TIPI.GAMES.TODM.TOD:1

ARTIST:
tipimap DSK1 TIPI.DISKS.INSCEBOT
fg99 TIXB_G

CAVES:
tipimap DSK1 TIPI.DISKS.CAVES
fg99 TIXB_G

END:
color 15 4
cls
ver