Tera Term macro for Forth

A macro that paces uploads by waiting for ‘ok.’ 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’t just be spurted out at a constant, say, 115200 baud – the Forth compiler can’t keep up, so its input buffer fills and characters are lost, causing errors.

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 – 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.

Forths generally echo back ‘ok.’ after they compile each line, so by waiting for that after each line (and possibly some other error messages or timeouts) there’s no need for any delays, and the upload happens as fast as possible.

Tera Term has a macro language – 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’s executable directory.

Here’s the file, upload.ttl

filenamebox 'Select file to upload'
if result=0 goto end
fileopen fhandle inputstr 0
timeout = 1

:loop
filereadln fhandle line
if result goto fclose
sendln line
wait 'not found.' 'ok.'
if result=0 goto timedout
if result=1 goto fclose
goto loop

:timedout
messagebox 'Upload aborted' 'Timed out'
:fclose
fileclose fhandle
:end

Here’s the addition to put at the end of your KEYBOARD.CNF file

[User keys]
; Ctrl + u key: upload a Forth file (wait for 'ok.' after each line)
User1=1046,2,upload.ttl

When you press Ctrl + u, a file requester pops up allowing you to select the Forth file, e.g. myfile.fth, to ‘include’. Tera Term remembers the folder you selected your Forth file from, even between sessions.

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.


Posted

in

by

Tags:

Comments

2 responses to “Tera Term macro for Forth”

  1. Jesse Gordon avatar

    Hi: Haven’t even thought about Forth in years. But, I did find some of your work that I wanted to talk to you about so, when I noted the title ‘Forth…’ I thought that it would be as good a place as any to send a question. I have been playing with your composite video output from arduino. Firstly, my heartiest congratulations. Yours is the FIRST arduino project I have pulled down from the web that compiled and ran first try. That has never happened to me before.
    What I want to do is use your code to make a serial terminal, ala 1970’s to which I plan to connect an ESP32 running runCPM, thereby making the smallest 1979 minicomputer ever. I have the ESP happily running emulated Z80 progs like dBase II and SuperCalc. I also have a 7″ LCD composite NTSC display showing your demo code in a mostly readable way.
    What I need is some advice on how to create a control structure in Arduino C to place individual characters on the screen in the next position and handle things like word wrap, escape sequences and special characters like we used to have on the VT100 or Adcom M50 terminals. Any help you can direct my way will be very greatly appreciated. :0)

    1. ceptimus avatar

      Did you watch this video?
      https://youtu.be/gG3mlhy88GE?si=bZZ4nsAvgPBIEmkO
      You might be better off looking at using an ESP32, or a Pi Pico, as the ‘video chip’ for your system. Both of those can produce colour displays at higher resolution than an Atmel Mega328 (or similar) chip can manage, and can drive VGA or DVI (HDMI) displays rather than needing a composite video input. They don’t cost any more than an ATmega 328, and are much more capable.

Leave a Reply

Your email address will not be published. Required fields are marked *