### Scripting

Options like `-icmd`, `-menu` and `-cmd` take a command or list of commands as a parameter. A command may be a single word like `reset` which will reset the emulator. Or it can be a list, for example `[ poke 3c00 45 ]` which puts an "A" in the top left of the Model 1 screen. The square brackets may also be used to create a list of commands. For instance, `[ [ poke 3c00 45 ] [ poke 3fff 5b ] ]` is two commands which put "A" in the top left of the Model 1 screen and "Z" in the bottom right.

The `-ib file` option takes a script file which is a series of commands, one per line. Here are the two `poke` commands in a file:

         poke 3c00 45
         poke 3fff 5b

If the file starts with `#!` then it will be recognized as a script and its commands will run if passed directly on the command line or dragged and dropped onto the main window.

On Linux and MacOS trs80gp can be used as a script processor using the usual `#!` (hash bang) file start. For example, if trs80gp is in /user/george/trs80gp then this script will launch it emulating the Color Computer and have the software keyboard and debugger start up.

        #!/user/george/trs80gp -mc
        postmsg debug
        postmsg soft_keyboard

Unix only allows a single command line argument which we use up specifying the model to emulate. A mechanism to provide more command line arguments in this case is planned.

Generally speaking commands will alter the state of the emulator machine or the emulator itself. Here is a list of all the commands for reference each linked to their full description.

- feed - sent automated input
- load - load /CMD, .cas and other files
- input - change automated input injection method
- poke - put byte data into memory
- pokew - put word data into memory
- pokestr - put strings into memory
- pokefile - put raw file data into memory
- postmsg - operate the emulator user interface
- reset - reset the emulated machine
- run - run /CMD, .cas and other files
- sleep - wait for frames to pass

#### input command

`input`

Changes the input mode for automated input.

#### feed command

`feed` input1 .. inputN

Sends its arguments as automated input to the emulator (just like `-i` does on the command line). A single space is sent between each argument.

#### sleep command

`sleep` N

Waits for N frames to pass by before continuing. A frame is usually 1/60th of a second but varies depening on which emulator is running. Just like the `-id` command line option.

#### load command

`load` file1 .. fileN

Load one or more program files into the emulator. This is essentially identical to the File → Load... menu.

#### poke command

`poke`
address-set value1 .. valueN

Set one or more memory locations to the given values. If address-set can be a single memory location values are put there and in following addresses until they are used up. If it is a range then the values are repeated until the entire range is filled. If there are no values then the entire range is filled with zeros. The address-set can be multiple comma-separated ranges. Values may be hexadecimal or symbol names. By default data is put into the memory space view of the main processor. The optional argument can select different memory spaces like `-ram` for the main random access memory or `-vram` for the display.

`poke 3c00 21` will put a `!` in the top left of the Model 1 or 3 screen.
`poke 3c00:3fff 21` will fill the screen with `!`.
`poke -vram 0:200 41` will fill the top half of the screen with `A`

#### pokew command

`pokew`
address-set value1 .. valueN

The same as the poke command except that two byte word values are poked into memory. These values will be poked with the correct endian for the CPU the TRS-80 uses. Little endian for Z-80, Z-180 and 8080, Big endian for 6800, 6803, 6809 and 68000.

#### pokestr command

`pokestr`
address-set string1 .. stringN

The same as the poke command except that the strings are poked into memory. The strings can have escape codes such as `\xFF`.

`poke -vram 0:3ff Hey!`

fills the screen with `Hey!`

#### pokefile command

`pokefile`
address-set file1 .. fileN

As with poke but the contents of one or more files are put into memory. The files are loaded as raw data unlike the `load` command which interprets `/CMD` files and other binary executable formats.

#### postmsg command

`postmsg`

Sends a message to the user interface. Messages have various effects, usually popping up a dialog box or choosing a setting.

Ultimately this command should be replaced with sets of better controlled commands to trigger the various UI elements and settings. But it is too irresistable as it is easy to implement and powerful.

A full reference needs to be written up but some of the more useful ones are:

- soft_keyboard - bring up the software keyboard
- debug - bring up the debugger window
- exit - exit trs80gp
- copy - copy the screen to the clipboard
- paste - paste the clipboard as input
- printer - bring up the printer window
- source_code - bring up the source code window

#### reset command

`reset`

Causes a warm restart of the TRS-80. Or a cold restart with `-cold` or presses the reset button with `-button`.

#### run command

`run` file1 .. fileN

Load and run one or more program files on the emulator. This is essentially identical to the File → Run... menu.