• Please review our updated Terms and Rules here

Programming in C on a Z80 64K?

rjcroy

Member
Joined
Nov 28, 2009
Messages
13
Location
Hamilton, New Zealand
Is it practical/worthwhile to program in C on a 64K Z80 (Osborne 1)? I have begun to look around at compilers, but what I have seen so far seem mostly like partial implementations of K&R and very limited. Reading a thread on this forum discussing Assembly Language it was noted that C was not commonly used on microcomputers until 16 bit and 32 bit machines was available in the mid 80's.

Are C compilers for 8-bit anymore efficient that BASIC?

Is assembly the only way to go for fast code on a Z80?
 
Interesting question, rjcroy.

Even though it would never be as fast as direct hand-optimized assembly code, a well written C compiler should definitely be able to generate code that easily beats the performance of interpreted BASIC code.

I'm sure there are decent C compilers out there for the Z80, since it is still commonly used in embedded systems.

Anyone care to shed more light on this?
 
SDCC works with the Z80... and it's open source!:D (Small Device C Compiler)

That's what I plan to use when I try to start programming my homebrew system for more complex things that would really be impractical in assembly.

Edit: I fixed it. (Impractical)
 
Last edited:
I assume that you mean "impractical".

There is also Tiny C and a few commercial implementations (e.g. Zilog's eZ80 ZDS II suite and even Rabbit's Rational C.

If you're doing something for general distribution, however, remember that there are people out there with 8085- and 8080-based vintage gear. If you write for Z80 only, you'll be closing them out.

The problem that I recall with C and the Z80 for doing anything ambitious was that stack addressing is very limited, necessitating some rather inefficient code generation to address procedure-local storage. Static variable allocation usually turns out to be significantly more efficient on the x80 platforms.

If you're writing general utilities and such, C can be a good solution. Just remember that you'll also be carrying around the C runtime library routines with your code, adding to the size.

HLLs for system-level programming have a long history in x80 culture. Intel and DRI used PL/M, a small subset of PL/I, to implement much of their code. I believe that some parts of SuperCalc 2 are written in Pascal/M. Numerous applications in CBASIC abound. DRI tried to get an ISV program going with their PL/M compiler. FORTH enjoyed a dedicated following also.
 
I like the idea of programming using a cross compiler. I don't think you would want to write a program with 50,000 lines of code on an Osborne. If you try programming on the Osborne, you won't have nice debugging tools (one of my "must haves") since they take up a lot of resources. Back in the day, inserting lines of code in your program to display register contents and variables was all you had to work with. Still, programs that did real and useful work were written for these machines with those primitive tools.
That said, I would rather work with a C compiler with limited functionality than use Basic. Compared to C, I find programming in Basic boring as hell!
 
I've been using BDS C. All open source now and compiles and runs just fine on a 64k CP/M machine. http://www.bdsoft.com/resources/bdsc.html

Also available as an emulation http://www.schorn.ch/cpm/intro.php package is available about 2/3 of the way down the page.

You can either compile on a real machine (slow compiles but no download delay) or compile on the simh (instant compiles but then 30 secs to download). I use both.

Can you transfer files easily?
 
Can you transfer files easily?

This is one of the issues I have only begun to think about! At the moment I have no method for transferring data to/from the Osborne 1 to other computers. I don't have another computer with a 5.25 inch floppy drive. (To date I have only been physically mailing disks to Tezza in the post, and he writing data to my disks!)

I was thinking my options are:
1) Using a Serial Cable to attach to a modern Linux or WinXP computer. (I've no idea about what software I would use for this yet.)
2) Obtaining a working 5.25" drive to attach to a PC in place of the current 3.5" floppy drive.

Which method would you recommend? the Serial cable option would be less to-ing and fro-ing? And easier to get a working serial cable than a 5.25 floppy drive, I would think? Software for doing the transfers?

It has also occured to me that C will be a little difficult to write on an Osborne because the keyboard has no curly braces! haha
 
No curly braces? That will be tricky.

Re file transfers, I use xmodem at the CP/M end and any number of terminal programs (teraterm, hyperterminal, even one I wrote in vb.net as the xmodem protocol is pretty simple). Xmodem source and compiled files are around and if you have problems I have these.

The big issue is customising xmodem to work on a particular machine. xmodem bypasses the bdos calls that CP/M uses to send and receive bytes, and it does this to get the speed up but the downside is you have to hack the system a bit. At the simplest level, you need 4 machine code instructions - output a byte to the serial port, input, is a byte ready to read in, and is the uart ready to send a byte out. These are Z80 IN and OUT instructions, and they will be to a particular port. You can get a clue from the CONIN and CONOUT sections of CP/M but only if you have the source code for your particular version of CP/M. Tezza or someone who has an Osborne will know the answer to that.
 
Thanks Dr_Acula. I will have a look into xmodem. That is encouraging :)
And I will look more carefully at the BDS C compiler and the SIMH emulator.

hmbrew: Cheers for the SDCC link. I had not come across this compiler before and it looks very helpful too. Current, active development, decent documentation, features like floats.
 
You are correct in asserting that most of the native Z80 C compilers out their are based on a subset of K&R, however HI-TECH are offering their Z80 C compiler for free from their site. It is virtually ANSI compliant and I have found that it works very well for those wanting to develop on CP/M.

I have written a short article on it: Installing the HI-TECH Z80 C Compiler for CP/M
 
It has also occured to me that C will be a little difficult to write on an Osborne because the keyboard has no curly braces! haha

You can use ??< and ??> instead of { and } on most compilers. Some newer ones (not sure how new we're talking) may also let you use <% and %>
 
Xmodem source and compiled files are around and if you have problems I have these.

hmm...I am looking for IMP or MEX? I have found MEX for CP/M on a C128... but not source... It's getting complicated.
If you could email me the source you have it would be much appreciated! (I'll PM you my email).
 
hmbrew: Cheers for the SDCC link. I had not come across this compiler before and it looks

SDCC creates very bulky code. ld r,(iy+n) etc (4 bytes) all the time with local variables.
Something to keep in mind with the 64kB.
It's quite usable, I'm not denying that. But you have to watch out for compiler bugs.


Juha
 
Even though it would never be as fast as direct hand-optimized assembly code, a well written C compiler should definitely be able to generate code that easily beats the performance of interpreted BASIC code.

There's little or nothing to be gained by compiling BASIC on the x80 platform to machine code. Indeed, it can even be counter-productive.

This stems from BASIC's requirement to keep all variables in floating-point representation by default (Integer typing is a nonstandard extension to the language.) So the program degenerates to a big list of subroutine calls.

An incrementally-compiled (e.g. to p-code) BASIC program can be just as fast or faster than a compiled-to-machine code version. And much smaller.

For application programs on an x80 platform, BASIC is probably the best choice overall.

For sheer efficiency in generated code with a higher-level language, it's hard to beat FORTH, if you want to call FORTH a "language", that is.

I programmed a couple of system utilities for x80 in FORTRAN and they worked out pretty well.
 
It looks like you've gotten some good options for C so far. I used BDS C and Aztec C back in the day, and they both worked well, and supported limited keyboards (I remember being totally stumped the first time I sat down at an Apple II to port a program using Aztec on it.)

Nearly all BASIC compilers (and several of the interpreters) allow you to type your variables, so the thing about all vars being floating point isn't true. Most would speed of code really well compared to interpreted BASIC, what the code was doing was more of a determinant than the fact that the code had started out as BASIC.

My favorite compiler back in the day was the FTL Modula-2 compiler. I found the separately compiled modules to be far more convenient than managing large code projects in C, as well as for breaking coding projects into pieces, whether it was a group project or just something I was doing myself.
 
Back
Top