{"id":897,"date":"2025-06-20T14:15:16","date_gmt":"2025-06-20T13:15:16","guid":{"rendered":"http:\/\/capitoline.twocatsblack.com\/?page_id=897"},"modified":"2025-06-23T15:34:14","modified_gmt":"2025-06-23T14:34:14","slug":"capcli-variables","status":"publish","type":"page","link":"http:\/\/capitoline.twocatsblack.com\/index.php\/capcli-variables\/","title":{"rendered":"CapCLI: Variables"},"content":{"rendered":"\n<p>Variables are little stores of data, some are implicitly created for you, and some you can create for yourself<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">To create a variable<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>var &lt;variable name> &lt;value><\/strong><\/code><\/pre>\n\n\n\n<p>For example, to create the variable MYVAR, with the value &#8220;Today is Friday&#8221;  (the quotes are important if you have spaces).<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CapCLI&gt;<strong> var MYVAR \"Today is Friday\"<\/strong><\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">To display a variable<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>echo &lt;variable name><\/strong><\/code><\/pre>\n\n\n\n<p>For example;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CapCLI&gt; <strong>echo $MYVAR<\/strong>\nToday is Friday<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">To create a variable from data in your current ROM<\/h4>\n\n\n\n<p>You can grab chunks of the ROM and it will store the data in the variable as a hexadecimal string<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><em>CapCLI&gt; <\/em><strong><em>var &lt;aliasname&gt; romdata &lt;start&gt; &lt;size&gt;<\/em><\/strong><\/code><\/pre>\n\n\n\n<p>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)<br>Note: the start position starts at zero (i.e. the first byte is byte 0).<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CapCLI&gt; <strong>loadrom \"ROMs\/TOSEC.Firmware\/Kickstart v2.05 r37.350 (1992-04)(Commodore)(A600HD)&#91;!].rom\"<\/strong>\nCapCLI&gt; <strong>var FRED romdata 0x0C 4<\/strong>\nCapCLI&gt; <strong>echo $FRED<\/strong>\n0x0025015E<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">To take chunks out of a variable: midstring()<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code><strong><em>var &lt;varname&gt; mid &lt;start&gt; &lt;size&gt;<\/em><\/strong> <\/code><\/pre>\n\n\n\n<p>For example, reduce the variable FRED to just two bytes starting from position three, <em>this command changes the actual variable<\/em><br>Note: string positions start at 0<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CapCLI&gt; <strong>var FRED 0x0025012c<\/strong> \nCapCLI&gt; <strong>var FRED mid 3 2<\/strong> \nCapCLI&gt; <strong>echo $FRED<\/strong>\n02<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">To add\/subtract from variables<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code><strong><em>var &lt;varname&gt; add &lt;value&gt;<\/em><\/strong>\n<strong><em>var &lt;varname&gt; subtract &lt;value&gt;<\/em><\/strong><\/code><\/pre>\n\n\n\n<p>These commands will directly affect the variable value, you can change number variables or hex values, if you&#8217;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 &#8211; and it will do it without any warning, attempting maths on invalid numbers will give unpredictable results.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CapCLI&gt; <strong>var FRED 77<\/strong>\nCapCLI&gt; <strong>var FRED add 0xD<\/strong>\nCapCLI&gt; <strong>echo $FRED<\/strong>\n90\nCapCLI&gt; <strong>var FRED 0x0025<\/strong>\nCapCLI&gt; <strong>var FRED subtract 16<\/strong>\nCapCLI&gt; <strong>echo $FRED<\/strong>\n0x00000015<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">To convert variables<\/h4>\n\n\n\n<p>You can convert the representation of variables, by default, all variables are strings, even though some are implicitly numbers or hex strings, you cannot store binary values in a variable unless you store it as the hex representation &#8211; so converting between them may lose data!<br>Using one of these functions on a variable will change the variable<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>var &lt;varname> stringtohex<\/strong>\nCapCLI> var MYVAR \"Hello World\"\nCapCLI> var MYVAR stringtohex\nCapCLI> echo $MYVAR\n0x48656c6c6f20576f726c64\nNote: No end-of-line markers are added (i.e. 0x00 is not added to the string).<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>var &lt;varname> <strong>hextostring<\/strong><\/strong>\nCapCLI> var MYVAR 0x3238205965617273204c61746572\nCapCLI> var MYVAR hextostring\nCapCLI> echo $MYVAR\n28 Years Later\nNote: If you have a null byte in the middle of the hex, the string will truncate there.<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>var &lt;varname> inttohex\n<\/strong>CapCLI> var MYVAR 300\nCapCLI> var MYVAR inttohex\nCapCLI> echo $MYVAR\n0x0000012c\nNote: The output is always a four-byte hex number (UINT), you can convert a negative number, but it will assume the resulting hex value is positive.<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>var &lt;varname> hextoint<\/strong>\nCapCLI> var MYVAR 0x0ff\nCapCLI> var MYVAR hextoint\nCapCLI> echo $MYVAR\n255\nNote: The output is always a positive number (assumes unsigned hex value)<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Variables are little stores of data, some are implicitly created for you, and some you can create for yourself To create a variable For example, to create the variable MYVAR, with the value &#8220;Today is Friday&#8221; (the quotes are important if you have spaces). To display a variable For example; To create a variable from &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"\" href=\"http:\/\/capitoline.twocatsblack.com\/index.php\/capcli-variables\/\"> <span class=\"screen-reader-text\">CapCLI: Variables<\/span> Read More &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"site-sidebar-layout":"default","site-content-layout":"default","ast-global-header-display":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","footnotes":""},"class_list":["post-897","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"http:\/\/capitoline.twocatsblack.com\/index.php\/wp-json\/wp\/v2\/pages\/897","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/capitoline.twocatsblack.com\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"http:\/\/capitoline.twocatsblack.com\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"http:\/\/capitoline.twocatsblack.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/capitoline.twocatsblack.com\/index.php\/wp-json\/wp\/v2\/comments?post=897"}],"version-history":[{"count":5,"href":"http:\/\/capitoline.twocatsblack.com\/index.php\/wp-json\/wp\/v2\/pages\/897\/revisions"}],"predecessor-version":[{"id":919,"href":"http:\/\/capitoline.twocatsblack.com\/index.php\/wp-json\/wp\/v2\/pages\/897\/revisions\/919"}],"wp:attachment":[{"href":"http:\/\/capitoline.twocatsblack.com\/index.php\/wp-json\/wp\/v2\/media?parent=897"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}