• Please review our updated Terms and Rules here

Programming in C with Mike Stump's ZC 2.0

jrd

Member
Joined
Apr 29, 2015
Messages
37
While this may be more of a programming question, it's specific to the TRS-80 so this seems to be the place to ask.

Has anyone here every used Mike Stump's shareware ZC from 1987 for C programming?

Aside from being in disk collections, I can't find any mention of it anywhere: not on comp.sys.tandy, and not here. The only other versions of C for the TRS-80 are Alcor C, which creates p-code (!), and Misosys LC, which requires LDOS.

Anyway, I downloaded it and have been playing with it on an emulator, and I think it's a really interesting system, especially for a shareware one. It consists of zc, the K&R C compiler, zas, a very simple assembler, zlink the linker, and a bunch of /lnk library files.

Some notes:

Most of the instructions are spent explaining what it can't do rather than what it can. But I found that actually it's reasonably complete, and find it easy to write file-based programs that run on any DOS without much problems. A sample program is included, and that program (a RS-232 terminal) is sophisticated enough to show off its capabilities. (And that source is the ONLY clue to some of them.) All the C file redirection of standard i/o seems to work. No direct float support, but there are libraries that use the ROM's.

Mike Stump clearly wrote it on a Model III: not only does it come on a TRSDOS 1.3 disk, but all executables use many Model III-specific RAM addresses like the top-of-memory and the command line. But I was able to make a Model I version by patching all "4411" bytes to "4049" and "4225" to "4318" (in zc/cmd, zas/cmd, zlink/cmd, and stdio/lnk, which is the C runtime.)

The linker is hilarious: whenever it hits an external function, it just asks YOU what the name of the library file is! The whereisz/doc file lists where each function is in which library. Note that some functions are in multiple libraries--you have alternates to choose from. And even then it expects you to PATCH (or SUPERZAP) in the end-of-program address.

But anyway it's a really neat system to make TRS-80 programs with C. For instance, I used ZC to write TRS-80 version of tenox's "aclock" program, which draws a live clock in text mode. I submitted it, and tenox accepted it!

You can find the source here:
https://github.com/tenox7/aclock/blob/master/sources/aclockm1-trs80-model1.c
https://github.com/tenox7/aclock/blob/master/sources/aclockm3-trs80-model3.c

And cmd files here:
https://github.com/tenox7/aclock/blob/master/binaries/z80/aclockm1-trs80-model1.cmd
https://github.com/tenox7/aclock/blob/master/binaries/z80/aclockm3-trs80-model3.cmd

One thing I would love to see would be the original source of the compiler, since it was clearly self-hosted. I wonder if anyone knows Mr. Stump and can ask him?

John D.
 
I haven't heard of ZC before -- quite interesting.

Being curious about the code generation I did a quick disassembly of the Model III aclock. Some of the small subroutines jumped out at me, especially this one:

Code:
_595b:		ld	a,e	
		rla			
		ld	e,a			
		ld	a,d			
		rla			
		ld	d,a			
		or	e		
		ret

The Z-80 can do it a little better (rl e; rl d; ld a,d; or e; ret) but mostly because it is the same subroutine I saw diassembling a Model II program called diag68. There were two little subroutines just before it that are identical. Could be just a coincidence, but I do wonder if the Model II program was built with ZC or if they share some common heritage. Which might only be a set of 8080 subroutines from CP/M or something.

Except for the pain of pointing things out to the linker it looks to be a lighter-weight alternative to the larger C compilers.
 
no I could not find any references aside software deposit (online & mine) about the C program for TRS-80, I wonder if I could use it to rework a source code I have for a BBS.. humm thanks for the heads up
 
In case this is the only place on the entire web that mentions ZC, I should mention this here.

ZC has at least one serious bug: the pre- and post-increment/decrement operators, ++a / a--, do not work on global variables. They do work on function parameters and local variables, but not global.

I found this as I've tried more C source in it. On looking at the assembly output, I can see what's happening, but the issue is a missing instruction, so it's not easy to patch the compiler. Without the source it can't be fixed. So you have to work around it and insert an extra a=+1; before or after instead.

But the rest of it continues to work. Got the AES256 Encryption and Decryption from http://www.z80.eu/c-compiler.html and many other things working. With luck I can build a TRS-80 version of rswier's C4 C compiler and make C in C. :)
 
Back
Top