{"id":648,"date":"2022-08-25T18:35:01","date_gmt":"2022-08-25T17:35:01","guid":{"rendered":"https:\/\/ceptimus.co.uk\/?p=648"},"modified":"2022-09-17T00:36:05","modified_gmt":"2022-09-16T23:36:05","slug":"tera-term-macro-for-forth","status":"publish","type":"post","link":"https:\/\/ceptimus.co.uk\/index.php\/2022\/08\/25\/tera-term-macro-for-forth\/","title":{"rendered":"Tera Term macro for Forth"},"content":{"rendered":"\n<p>A macro that paces uploads by waiting for &#8216;ok.&#8217; at the end of each line, before continuing.<\/p>\n\n\n\n<p>When uploading files to Forth running on a microcontroller (Mecrisp is a good choice for the MSP430 chips), the characters can&#8217;t just be spurted out at a constant, say, 115200 baud &#8211; the Forth compiler can&#8217;t keep up, so its input buffer fills and characters are lost, causing errors.<\/p>\n\n\n\n<p>The traditional solution, with Tera Term, was to specify inter-character delays (not usually needed) or end of line delays.  Determining the necessary end of line delay is an empirical process &#8211; upload a complicated-to-compile file, and adjust the delay to be as low as possible without causing any errors.  Problem is, you have to set the delay high enough for the worst case, maybe 200mS, and then it slows down the whole upload, even though 99% of the time, the Forth compiler can easily keep up.<\/p>\n\n\n\n<p>Forths generally echo back &#8216;ok.&#8217; after they compile each line, so by waiting for that after each line (and possibly some other error messages or timeouts) there&#8217;s no need for any delays, and the upload happens as fast as possible.<\/p>\n\n\n\n<p>Tera Term has a macro language &#8211; you create files with the extension .ttl (for Tera Term Language), and put them in the same folder as the Tera Term executable.  I wrote one named upload.ttl.  You can call macros from the menu, but you can also assign a key (such as Ctrl+u) to invoke the upload macro.  You specify the key to use by editing KEYBOARD.CNF, which is another file in Tera Term&#8217;s executable directory.<\/p>\n\n\n\n<p>Here&#8217;s the file, upload.ttl<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>filenamebox 'Select file to upload'\nif result=0 goto end\nfileopen fhandle inputstr 0\ntimeout = 1\n\n:loop\nfilereadln fhandle line\nif result goto fclose\nsendln line\nwait 'not found.' 'ok.'\nif result=0 goto timedout\nif result=1 goto fclose\ngoto loop\n\n:timedout\nmessagebox 'Upload aborted' 'Timed out'\n:fclose\nfileclose fhandle\n:end<\/code><\/pre>\n\n\n\n<p>Here&#8217;s the addition to put at the end of your KEYBOARD.CNF file<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;User keys]\n; Ctrl + u key: upload a Forth file (wait for 'ok.' after each line)\nUser1=1046,2,upload.ttl<\/code><\/pre>\n\n\n\n<p>When you press Ctrl + u, a file requester pops up allowing you to select the Forth file,  e.g. myfile.fth, to &#8216;include&#8217;.  Tera Term remembers the folder you selected your Forth file from, even between sessions.<\/p>\n\n\n\n<p>There are better alternatives to Tera Term for this job (e.g. Escom, which is a Windows port of the excellent Linux E4thcom), but some Windows users love Tera Term, which is a great terminal program for many other tasks besides just interacting with a Forth microcontroller.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A macro that paces uploads by waiting for &#8216;ok.&#8217; at the end of each line, before continuing. When uploading files to Forth running on a microcontroller (Mecrisp is a good choice for the MSP430 chips), the characters can&#8217;t just be spurted out at a constant, say, 115200 baud &#8211; the Forth compiler can&#8217;t keep up, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-648","post","type-post","status-publish","format-standard","hentry","category-programming"],"_links":{"self":[{"href":"https:\/\/ceptimus.co.uk\/index.php\/wp-json\/wp\/v2\/posts\/648","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ceptimus.co.uk\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ceptimus.co.uk\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ceptimus.co.uk\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ceptimus.co.uk\/index.php\/wp-json\/wp\/v2\/comments?post=648"}],"version-history":[{"count":5,"href":"https:\/\/ceptimus.co.uk\/index.php\/wp-json\/wp\/v2\/posts\/648\/revisions"}],"predecessor-version":[{"id":656,"href":"https:\/\/ceptimus.co.uk\/index.php\/wp-json\/wp\/v2\/posts\/648\/revisions\/656"}],"wp:attachment":[{"href":"https:\/\/ceptimus.co.uk\/index.php\/wp-json\/wp\/v2\/media?parent=648"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ceptimus.co.uk\/index.php\/wp-json\/wp\/v2\/categories?post=648"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ceptimus.co.uk\/index.php\/wp-json\/wp\/v2\/tags?post=648"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}