Get started with C cross-development for the TRS-80 Model 1 and 3!

Get started with C cross-development for the TRS-80 Model 1 and 3!

My first computer ever was a TRS-80 clone called JR Sysdata which I, like many of us, regrettably sold when I wanted to upgrade to something else. Today this Brazilian clone is rarer than flying cows and worth a good amount of money.

Of course, we are here not to talk about childhood computers but about cross-development for the TRS-80 Model 1/3!

When I was listening to the awesome TRS80 Trash Talk podcast, I’ve learned that the TRS-80 gods are holding a software development competition giving excellent prizes so I decided to try my luck and snag one of these prizes. Please, don’t enter the contest to increase my chances!

It’s been 35 years since I programmed on the TRS-80 and at that time mostly BASIC programs and the deepest I got into Assembly language was to create small BASIC extensions. That said, I don’t think I will have enough time to be good at Z80 assembler and create something competitive until the deadline, next November. I certainly could create something in BASIC which is very capable to be used in something fun, albeit rather slowly, but my current idea for the competition wouldn’t match well the BASIC capabilities.

With that in mind, my focus went to check high level compiled languages. First I looked at native compilers released for the machines back in the 80s. I was going with Pascal, just so I could un-dust my years of Borland Delphi programming but later on I realized that using native software for the TRS-80 wouldn’t help me to speed up the development.

Since I also had some experience in C, I started looking at Z88DK, “a collection of software development tools that target the 8080 and z80 family of machines. It allows the development of programs in C, assembly language or any mixture of the two”. Thankfully, the TRS-80 Model 1 and 3 are among the supported machines!

Emulators

There are several options of TRS-80 emulators. Most of the more recent ones are native Windows applications, but other operating systems can still use them under Wine, or relying on some that are multi-platform.

My choice is trs80gp, a very complete emulator created by George Philips which development is still very active. trs80gp emulates the “gray” line of TRS-80 computers made by Tandy in the late 1970s and early 1980s, including the Model I, Model II, Model III, Model 4, Model 4P, Model 4D, Model 12, Model 16 and Model 6000.

The current version (2.3.2) ZIP file contains the Windows executable and the macOS app bundle, which made my life easier. I downloaded the archive from here and copied the trs80gp.app to my Applications/Emulators folder. Windows users can also copy the .EXE to any folder and run it from there. I recommend finding someplace that would be easier to access from the command line/terminal (short, no spaces, for example), though, since this is the way we are going to call the emulator to execute our programs.

At this point, you can run the emulator and play with it to make sure it is working properly. Since we are using the emulator via command line/terminal, try also to execute it from there, using the following command (replace the folder name with yours):

/Applications/Emulators/trs80gp.app/Contents/MacOS/trs80gp -m1
or
c:\Users\pgarcia\Emulators\trs80gp.exe -m1

z88DK – C Compiler for the TRS-80

Since I am a macOS user, my examples will reflect that. Linux users will be at home and those using Windows won’t have any difficulty to understand and translate the paths and commands to be used. If you feel any difficulty, please ask in the comments section. More detailed instructions can be found here, but at a glance, your job is to download the tool zip file and set a couple of environment variables.

For convenience, the developers generate nightly builds for the three major OSes. For Windows and macOS, the archives already contain the binaries, and for Linux only the source code which you will have to compile yourself.

In my case, I’ve downloaded and installed in the folder /Users/pgarcia/z88dk. After doing so, you will need to create/update two environment variables:

ZCCCFG/Users/pgarcia/z88dk/lib/config
PATH: ${PATH}:/Users/pgarcia/z88dk/bin

I should mention that all steps I will be showing will happen on a terminal window (or command line). Of course, while editing files, you can use any editor of your preference (I suggest Visual Studio Code).

After setting the variables (you should probably open a new terminal window or make sure the two variables are up to date in your sessions (e.g. source ~/.bash_profile). To make sure everything is right, simply type zcc and if everything is correct, you should see:

zcc - Frontend for the z88dk Cross-C Compiler - v16905-8b62708-20200825 Usage: zcc +[target] {options} {files}

`Options:

-z80-verb Make the assembler more verbose
-cleanup (default) Cleanup temporary files
... (and many more options)`

If you see a message saying something like zcc is not recognized, review the steps above or read carefully the complete instructions I mentioned above.

Your first TRS-80 C Program

Here we start the fun part. The program below is a beefed up Hello World showing the use of functions, pointers and conio library functions.


#include <stdio.h>
#include <conio.h>

void drawLine(int row, char ch) {
   int i;
   char *scr=15360 + (row*64); /* Start of video RAM plus the number of lines indicated in the row parameter */

   /* using pointers for fun to set characters on screen */
   for (i=0;i<64;i++) {
     *scr = ch;
     scr++;
   }
}

int main()
{

   clrscr();  /* clear screen */

   gotoxy(10,5);   /* column 10, line 5 */
   cprintf("Hello World from Vintage is The New Old!\n");

   drawLine(1, 172);
   drawLine(9, 182);

   gotoxy(35,15);  /* column 35, line 15 */
   cprintf("Press <ENTER> to finish...");

   getch();  /* wait for ENTER to be pressed */
   return 0;
}

You can copy the program in your text editor and save it using the very original name test.c.

Now, go back to the terminal and let’s compile it. The command below will compile the C program for the TRS-80, automatically creating a /CMD file that is executable on the emulator using L-DOS.

zcc +trs80 -vn test.c -create-app -subtype=disk -lndos -lm -o test

After typing the command above from the folder where your test.c program is placed, the program will compile and generate the executable. If everything went well, the cursor will just move to the next line with no messages or anything. Nothing is good here!

If you see errors, it is probably because your program contains error or your installation is not ok. If that is the case, please review the steps above and ask in the comments section.

After the compiler finishes (which should take a split second), if you list the folder contests, you should see now a test/cmd file there.

To test it, we simply call the emulator from the terminal, passing test/cmd as parameter (update emulator path as needed):

/Applications/Emulators/trs80gp.app/Contents/MacOS/trs80gp -m1 test.cmd -ld

The -m1 parameter indicates we are using a model 1 emulation. The same example will work if we use -m3 (model 3) as well.

As a result of the command above, you will see your program running on all its glory:

The emulator will stay running until you close it, even after you finish the program.

Conclusion

This is basically what you would need to get starting coding in C for the TRS-80 model 1 or 3. As you can see, the steps are very manual but the idea is to show the basics. You can take a step further and automate the tasks using scripts or code editor extensions. If you do so, make sure to let us know!