{"id":35,"date":"2022-12-30T12:45:11","date_gmt":"2022-12-30T12:45:11","guid":{"rendered":"http:\/\/192.168.1.222\/Capitoline\/?page_id=35"},"modified":"2023-03-20T16:58:16","modified_gmt":"2023-03-20T16:58:16","slug":"patcher","status":"publish","type":"page","link":"http:\/\/capitoline.twocatsblack.com\/index.php\/patcher\/","title":{"rendered":"Patcher"},"content":{"rendered":"\n<h2 class=\"has-medium-font-size wp-block-heading\">Patch a position<\/h2>\n\n\n\n<p>The most important patcher command is the &#8220;patch&#8221; command, with this you overwrite (never insert) bytes<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong><em>patch &lt;position&gt; 0x&lt;value&gt;<\/em><\/strong>\n\n# Patch position 12 (0x0C) with the four bytes 0x0025015E - changes the ROM version number to r37.350\nCapCLI&gt; patch 0x0C 0x0025015E<\/code><\/pre>\n\n\n\n<h2 class=\"has-medium-font-size wp-block-heading\">Create\/set alias<\/h2>\n\n\n\n<p>Within Cap you can create variables (for some reason, I started using the word alias, now its stuck), but it&#8217;s just a variable, you can directly assign values to aliases, grab a chunk of the ROM and put it into an alias (to patch somewhere else or change), if the alias looks like it could be a number, you can add to or subtract from it, and you can treat it like a string and chop it up using the mid function.<br><br>I&#8217;ll probably add some extra functions here, like conversion between hex, int and strings, as it&#8217;s a little limited at the mo.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong><em>alias &lt;aliasname&gt; &lt;value&gt;<\/em><\/strong>\n\nCapCLI&gt; alias FRED 0x01020304\nCapCLI&gt; echo $FRED\n0x01020304\n\n<strong><em>alias &lt;aliasname&gt; romdata &lt;start&gt; &lt;size&gt;<\/em><\/strong>\n\nCapCLI&gt; loadrom \"ROMs\/TOSEC.Firmware\/Kickstart v2.05 r37.350 (1992-04)(Commodore)(A600HD)&#91;!].rom\"\nCapCLI&gt; alias FRED romdata 0x0C 0x04\nCapCLI&gt; echo $FRED\n0x0025015E\n\n<strong><em>alias &lt;aliasname&gt; add &lt;value&gt;<\/em><\/strong>\n\nCapCLI&gt; echo $FRED\n0x0025015e\nCapCLI&gt; alias FRED add 1\nCapCLI&gt; echo $FRED\n0x0025015f\n\nNote, add and subtract only work properly on hex values, i.e. they must begin 0x (I might change this later)\n\n<strong><em>alias &lt;aliasname&gt; subtract &lt;value&gt;<\/em><\/strong>\n\nCapCLI&gt; echo $FRED\n0x0025015f\nCapCLI&gt; alias FRED subtract 51\nCapCLI&gt; echo $FRED\n0x0025012c\n\n\n<strong><em>alias &lt;aliasname&gt; mid &lt;start&gt; &lt;size&gt;<\/em><\/strong>\n\nCapCLI&gt; echo $FRED\n0x0025012c\nCapCLI&gt; alias FRED mid 3 2\nCapCLI&gt; echo $FRED\n02\n\nNote, the alias has 0x at the start of it, this is <em>included <\/em>in the length, so position 0 is \"0\", position 1 is \"x\" etc.<\/code><\/pre>\n\n\n\n<h2 class=\"has-medium-font-size wp-block-heading\">Inbuilt aliases<\/h2>\n\n\n\n<p>For your delectation, I have created some inbuilt aliases that help you access\/modify ROM and library information, you (almost) only ever change data with the <strong>patch <\/strong>command.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>ROM things<\/strong>\n\nThe ROMBASE calculated from the ROM\n<strong><em>$ROMBASE<\/em><\/strong>\n\nCapCLI> echo $ROMBASE\n0x00f80000\n\nThe Commodore checksum (not CRC32)\n<em><strong>$CALCCHECKSUM<\/strong><\/em>\n\nCapCLI> echo $CALCCHECKSUM\n0xba5d5fa4\n\nThe location within the ROM of the kickstart version (usually 12, 0x0C)\n<em><strong>$(KICKSTARTVERSION)<\/strong><\/em>\n\nCapCLI> echo $(KICKSTARTVERSION)\n0x0000000c\n\nNote the use of brackets, to say \"location of\" rather than the actual kickstart version.\n\n# read the kickstart version into the KSV alias\nCapCLI> alias KSV romdata $(KICKSTARTVERSION) 4\nCapCLI> echo $KSV\n0x0025015E\n\n<strong>Locations of library things<\/strong>\n\nThese will give you the location of things that relate to specific libraries, so you can read or manipulate them - remember, the brackets mean \"give me the location\" not the value stored at that location\n\n<em><strong>$libraryname.(START)\n$libraryname.(END)\n$libraryname.(ROMTAG)\n$libraryname.(ROMTAG.MATCHTAG)\n$libraryname.(ROMTAG.ENDSKIP)\n$libraryname.(ROMTAG.FLAGS)\n$libraryname.(ROMTAG.VERSION)\n$libraryname.(ROMTAG.TYPE)\n$libraryname.(ROMTAG.PRI)\n$libraryname.(ROMTAG.NAME)\n$libraryname.(ROMTAG.IDSTRING)\n$libraryname.(ROMTAG.INIT)<\/strong><\/em>\n\nIf you want the start and end location of a library, then you can simply use the name;\n\n<strong><em>$libraryname<\/em><\/strong>\n\nCapCLI> echo $cia.resource\n274624 275640\n<\/code><\/pre>\n\n\n\n<h2 class=\"has-medium-font-size wp-block-heading\">Hash aliases<\/h2>\n\n\n\n<p>You can find and refer to files by their hash value, but only if you have previously done an &#8220;auditfiles&#8221; command, the auditfiles command hashes every file under the named directory and creates an alias for every file based upon it&#8217;s hash value &#8211; as you can guess, scanning an entire directory tree is very CPU and disk intensive, so don&#8217;t do this on gigs or data, it&#8217;s only really worthwhile on ROMs or Components.<br>This is used extensively in the &#8220;Recipes and Tests&#8221; to load a specific ROM or component (without having to know the exact name).<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong><em>Scan all files under a directory and evaluate the hash value<\/em><\/strong>\n<strong><em>auditfiles &lt;dirname&gt;\n<\/em><\/strong>\nCapCLI&gt; auditfiles ROMs\nCapCLI&gt; echo \"$0x43b0df7b\"\nROMs\/TOSEC.Firmware\/Kickstart v2.05 r37.350 (1992-04)(Commodore)(A600HD)&#91;!].rom<\/code><\/pre>\n\n\n\n<h2 class=\"has-medium-font-size wp-block-heading\">Patching the checksum<\/h2>\n\n\n\n<p>If you have altered the ROM, you will need to update the C= checksum, there&#8217;s a hard way and an easy way, but the hard way isn&#8217;t that hard.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Using the location of the start of the checksum, patch it with a newly calculated value\n<strong><em>patch $Checksum.(START) $CALCCHECKSUM<\/em><\/strong>\n\nThe \"checksum\" command does this for you\n<strong><em>checksum <\/em><\/strong><\/code><\/pre>\n\n\n\n<h2 class=\"has-medium-font-size wp-block-heading\">Finding data<\/h2>\n\n\n\n<p>If you want to scan the ROM (or just a library) for the location of things, I have a command for that&#8230; the unusually named find command, if the find is successful then the alias $FIND is set to the position that it found it, if it&#8217;s not found then $FIND is not updated and you just get &#8220;Not found&#8221; (I might change this to reset $FIND).<br><br>You can search for binary text using hex representation (so searching for strings is a bit laborious) or you can search for 68000 opcodes<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong><em>find &lt;from&gt; &lt;to&gt; &lt;what&gt;<\/em><\/strong>\n\nCapCLI&gt; find 0 262143 0x6C696272617279\nCapCLI&gt; echo $FIND\n0x00000038\n\nCapCLI&gt; find 0 262143 0x112233445566778899aa\n<strong>Not found<\/strong>\nCapCLI&gt; echo $FIND\n0x00000038\n\n<strong><em>findopcode &lt;from&gt; &lt;to&gt; &lt;what&gt;<\/em><\/strong>\n\nCapCLI&gt; findopcode $0x75094a7b.scsidisk_40.12_(21.12.93) \"JSR FCD6(A6)\"\nCapCLI&gt; echo $FIND\n0x00000090<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Patch a position The most important patcher command is the &#8220;patch&#8221; command, with this you overwrite (never insert) bytes Create\/set alias Within Cap you can create variables (for some reason, I started using the word alias, now its stuck), but it&#8217;s just a variable, you can directly assign values to aliases, grab a chunk of &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"\" href=\"http:\/\/capitoline.twocatsblack.com\/index.php\/patcher\/\"> <span class=\"screen-reader-text\">Patcher<\/span> Read More &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":50,"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-35","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"http:\/\/capitoline.twocatsblack.com\/index.php\/wp-json\/wp\/v2\/pages\/35","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=35"}],"version-history":[{"count":1,"href":"http:\/\/capitoline.twocatsblack.com\/index.php\/wp-json\/wp\/v2\/pages\/35\/revisions"}],"predecessor-version":[{"id":665,"href":"http:\/\/capitoline.twocatsblack.com\/index.php\/wp-json\/wp\/v2\/pages\/35\/revisions\/665"}],"wp:attachment":[{"href":"http:\/\/capitoline.twocatsblack.com\/index.php\/wp-json\/wp\/v2\/media?parent=35"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}