CapCLI: Variables

Variables are little stores of data, some are implicitly created for you, and some you can create for yourself

To create a variable

CapCLI> var <variable name> <value>

For example, to create the variable MYVAR, with the value “Today is Friday” (the quotes are important if you have spaces).

CapCLI> var MYVAR "Today is Friday"

To display a variable

CapCLI> echo <variable name>

For example;

CapCLI> echo $MYVAR
Today is Friday

To create a variable from data in your current ROM

You can grab chunks of the ROM and it will store the data in the variable as a hexadecimal string

CapCLI> var <aliasname> romdata <start> <size>

For example, to grab four bytes from the ROM at position 0x0C (position 12 holds the kickstart version; you can use hex start/size or decimal numbers)
Note: the start position starts at zero (i.e. the first byte is byte 0).

CapCLI> loadrom "ROMs/TOSEC.Firmware/Kickstart v2.05 r37.350 (1992-04)(Commodore)(A600HD)[!].rom"
CapCLI> var FRED romdata 0x0C 4
CapCLI> echo $FRED
0x0025015E

To take chunks out of a variable: midstring()

var <varname> mid <start> <size> 

For example, reduce the variable FRED to just two bytes starting from position three, this command changes the actual variable
Note: string positions start at 0

CapCLI> var FRED 0x0025012c 
CapCLI> var FRED mid 3 2 
CapCLI> echo $FRED
02

To add/subtract from variables

var <varname> add <value>
var <varname> subtract <value>

These commands will directly affect the variable value, you can change number variables or hex values, if you’re using hex values it will treat it as a four-byte integer, so numbers will wrap round from 0xffffffff to 0x00000000 if you add 1 (and from 0x00000000 to 0xffffffff if you subtract 1), if will also pad the result to four bytes, and if you attempt to use a longer hex number it will only take the first four bytes, e.g. if you add 1 to 0x112233445566 will be taken as 0x11223344 and result in 0x11223345 – and it will do it without any warning, attempting maths on invalid numbers will give unpredictable results.

CapCLI> var FRED 77
CapCLI> var FRED add 0xD
CapCLI> echo $FRED
90
CapCLI> var FRED 0x0025
CapCLI> var FRED subtract 16
CapCLI> echo $FRED
0x00000015
Scroll to Top