z88dk - C cross-compiler for Z80

Started by nikoniko, September 16, 2007, 03:00 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

nikoniko

I wasn't aware that any Z80 cross-compilers supported the C128 as a target, but this one does. The capabilities are very rudimentary, however, being limited to 40 columns and not allowing more than 64K.

Quotez88dk is a z80 C cross compiler supplied with an assembler/linker and a set of libraries implementing the C standard library for a number of different z80 based machines. The name z88dk originates from the time when the project was founded and targetted only the Cambridge z88 portable.

The compiler featured in z88dk is a much enhanced Small C compiler; the compiler accepts many features of ANSI C and is only deficient in a few areas where implementation on a z80 processor might prove inefficient. The compiler performs simple optimisations, but the bulk of the optimisation is achieved by a set of peep-hole rules, which will typically reduce the size of a large project by up to a third.

The libraries supplied with z88dk are designed to be as generic as possible, indeed it is possible to port to a new machine simply by supplying two library routines and some startup code. It is hoped that one day z88dk will support as many z80 based machines as there is information available and sufficient interest in. Currently z88dk supports more than twenty z80 targets with the level of library support for each target varying with interest shown by users.

z88dk is known to run on a wide variety of platforms including: Linux, MacOS X, Solaris, Win32, Win16 and MSDOS. Binary releases are available for Win32 and MacOS X, additionally, packages are available for many Linux distributions. On BSD machines, GNU make should be used instead of the native make program.
http://www.z88dk.org/

Not sure why anyone would choose this over cc65, but there it is.

hydrophilic

Thanks for the link!

I would think the Z80 a lot better at C due to its 'unlimited' stack size.  Of course our C128's Z80 is crippled in the speed department.  I just hope z88dk doesn't rely on CP/M... that would REALLY slow it down!

Edit
Looking at the stdlib console implementation reveals CP/M is not used :)  On the other hand, the output routines are limited to the VIC screen :(  I haven't dug around enough to see how fileio is implemented, if at all.  It seems to be running in bank 0 which would limit the RAM due to the Z80 ROM and VIC color RAM being in context.

That said, it shows some potential and I'll do some experiments.

airship

I forget - if you're not using any I/O - including keyboard and display, of course - is it possible to block out the 8510 and run the Z80 at full 4 MHz speed? This would be great for sorting, filling big arrays, performing complex calculations, and other CPU-intensive functions.

I'm thinking fractals, of course. deep, Deep, DEEP iterations! :)
Serving up content-free posts on the Interwebs since 1983.
History of INFO Magazine

nikoniko

Rossmöller, producers of the 4Mhz TurboProcessor card for the C64, put out an 8Mhz Z80 upgrade for the 128 (pic). Not sure if it had the same limitations as Commodore's original design, being halted for half the time thus ending up with half-speed, but even so it would still be twice as fast as the original and could be useful to someone who wants to make the most of Z80 development on the 128.

QuoteI'm thinking fractals, of course. deep, Deep, DEEP iterations! :)
And don't forget that many Commodore 8-bits come with an extra coprocessor or two that no one takes advantage of -- inside the disk drive(s). Given the limited RAM of the 154x/157x series they're probably not too useful, but the 1581's extra memory makes it somewhat more viable for general use, and I believe the RAM in most Commodore drives can be expanded to some degree. So, get together a bunch of 1581s and start crunching! Actually, since fractal computations don't necessarily require much memory, perhaps you could even get by with 1571s or 1541s. :)

hydrophilic

I looked into this package some more and unfortunately it doesn't offer file i/o either.  On the fractal side, it does support floats!  AFAIK, cc65 doesn't support floats -- correct me if I'm wrong, but last time I looked it did not so I never got interested.

Maybe we could get Bil Herd to tell us the magic behind the 4MHz Z80?  I read somewhere there was a working prototype (i.e., full speed).  If it doesn't involve changes to the VIC or PLA, it might be something a hacker could do -- look out my dear 128, I have ideas of a soldering iron for you, mwa ha ha ha ha :P

BilHerd

Hi all,

Hydrophilic pointed me at this, in turn I have sent a flaming bag of 8563s to be placed on his doorstep with the accompyinging doorbell ring and the snickering from the bushes.

Basically the thing that set the Z80 speed for us was the fact that the Z80 can ask for a memory cycle  at different times as compared to the lockstep of a 1 mhz 650s.  The Z80 can take between 3,4 cycles (probably others) to finish an operation whereas the 1mhs 6502 finishes an operation once each cycle.  If the memory could respond to the Z80's request on any one of the 4 clock cycles that relate to the 1mhs bus then it could go full speed.  In the Vic-mastered bus of the CBM architecture, there are only two memory windows, one during clock low and one during clock high.  DRAM signals come out (if your lucky) at prescribed times, either you are waiting for the cycle to occur or you are not.

We started the project doing a clock-clock-pause-pause cycle where the theory was that you would always get a dram cycle in during the minimum 3 clocks of an instructions.  

We found that if you stopped the Z80 between the wrong two clocks on certain cycles that the addr/data out bus would be floating and would cause illegal data states, oscillation's and other havoc, so a guy named Frank Palia devised the logic that looks at teh ready and attention and acknowledge kind of things so if the Z80 didn't need a memory cycle it wouldn't necessarily stop and would do another clock.  I imagine this increase it in the neighborhood of 10% but have no proof sitting hear 20 years in the future.

The cool thing about the wacked-out jungle logic that Frank did was we did it withe spare gates.  We didn't want to start the FCC cycle over or risk boards in time for CES and a PAL (like 16L8) was completely out of the question as it costs more than $2 back then, maybe even as much as $4 which would have made it almost as expensive as some of the custom IC's.  If you look at the old 128 schematic, check out the jumble of chops between the '02 and the z80, it's a work of art if you take into account the situation and our ability to throw pride out the window in order to make it work ion time.

As far speeding up a Z80 now?  If you insulate the Z80 from the bus and let it access local memory and cache or pause teh Z80 only when it needs to write to system memory you could get some gains.  Basically it would be a mini computer plugged into the Z80 slot that "thought more than it talked".

If someone has an example of what an accelerator looks like in design I could comment on why it works beyond bus/memory caching.

I remember being hard pressed to get every thing done at 1mhz, jeez that was 1000ms, hell a computer these days can read War and Peace in 1000ms.

Hope this helps,

Bil Herd

nikoniko

Bil,
Aside from this picture, the only other information I've been able to find on the 8Mhz upgrade is a post to the cbm-hackers mailing list:

Quote from: Nicolas Welte (welte_at_chemie.uni-konstanz.deDate: 2002-07-09 12:33:44

Recently I got something that might be quite interesting: a small PCB that
boosts the Z80 in the C128 to 8MHz. It has the name Rossmöller on it, this is
the same company that made the C64 Turboprocess 4MHz card.

The PCB has a GAL on it, and it has two wires: one gets the 8MHz dotclock
from the 8701, the other an 1MHz signal from one of the bus buffers (I guess
for synchronisation of memory accesses). The GAL also connects to the
previously unused Z80 signals that control memory access and wait states. So
it can run at 8MHz unless it needs memory access, while in the original C128
it uses 4MHz during one half of a 1MHz cycle (does anyone know if it can use
both 1MHz cycles in fast mode?).

airship

The Z80 worked in the C128, which is more than you can say for the one in the C64 cartridge. I owned that sucker and it was little more than a curiosity, though I suppose it was a wonder it worked at all. Bil, the fact that you guys included it in the base unit when Apple was charging $200 for their add-on Z80 card was the cool part.

The days of the great hardware hacks in PC development are over. How elegant do you have to be if your system has a dual-core 64-bit processor and a couple of gigabytes of RAM? Who cares about clock cycles anymore? That's why I've come back to the Commodore 8-bit machines. They're elegant designs, and to squeeze the most out of them you've got to be clever and conservative with your resources.

The C128 was the best computer ever built for someone who truly loves and appreciates computers. I really believe that.

*EDIT* That little board sounds a bit like voodoo to me. I can get how it might run at 8MHz when not accessing memory, but the memory in the C128 wouldn't stand for 4MHz accesses, would it? Isn't it running at 2MHz? That being said, does anyone have the board layout and GAL code for it? :D
Serving up content-free posts on the Interwebs since 1983.
History of INFO Magazine

hydrophilic

A flamming bag of 8563s!  So THAT is what is on the bottom of my shoes :lol:

Thanks Bil for your insight, although I am disappointed the mod was only a 10% increase.  I've looked, carefully, at the schematics and am quite amazed it works.  Apparently the Z80 doesn't mind stopping in the middle of a 3-cycle read/write.  What's weird is the Z80 can change the address after the buffer has grabbed memory (in the middle of the 2 cycles it runs).  But I guess that doesn't matter because it won't look at the buffer (for the new address) until at least another 2 cycles.  Just amazing.

I guess I won't be modding my 128 for now.  If I come across another I'll see what I can break.

BillBuckels

#9
I just took a look at the z88dk compiler. Someone has gone to lots of work.

However CP/M and the C128 seems to be pretty well absent from this.

The Aztec C CP/M 80 Cross Compiler that I am getting ready for download has everything as far as I can see. I just want to write a few more examples but overlays and all that are working fine.

Admittedly, the compiler source is not available, but the library source is and a math library is available.

Here's the listing from the libraries:

C.LIB

**DIR**     scanf       fscanf      sscanf      scan        printf     
fprintf     sprintf     format      fmtcvt      fopen       fdopen     
fread       fwrite      fseek       gets        fgets       getchar     
agetc       getw        getc        puts        fputs       putchar     
puterr      aputc       putw        putc        ungetc      getbuff     
setbuf      begin       croot       open        ioctl       read       
write       lseek       posit       ceof        find        isatty     
blkio       rename      unlink      close       execl       exec       
loader      calloc      malloc      bdos        bios        fcbinit     
sbrk        qsort       user        setjmp      strcmp      strcpy     
strncpy     strcat      **DIR**     index       rindex      strlen     
setmem      movmem      swapmem     toupper     atol        atoi       
ctype       csave       lsubs       divide      shifts      bitopr     
support     port       

T.LIB

**DIR**     begin       croot       fprintf     printf      fopen       

M.LIB

**DIR**     sin         tan         asin        atan        sinh       
tanh        pow         sqrt        log         random      exp         
floor       fscanf      scanf       sscanf      fscan       fprintf     
printf      sprintf     fformat     atof        ftoa        frexp       
fsubs       

ROM.LIB

**DIR**     rom         sprintf     format      fmtcvt      atol       
atoi        qsort       setjmp      toupper     strcmp      strcpy     
strncpy     strcat      index       rindex      strlen      setmem     
movmem      swapmem     csave       lsubs       divide      shifts     
bitopr      support     **DIR**     port       


Moderator's note: I took the liberty of editing Bill's listing so it would be columnized and a bit easier to read.