- Top Stats

Top Posters Top Topic Starters Top Topics
NewsBot 1453
Gryzor 738
TFM 649
TotO 500
MacDeath 221
NewsBot 1117
Gryzor 19
Border_7 11
SyX 9
eliot 9
X-MASS, a mass... - 156814 Views TotO 19:32, 14 December 14
X-MEM, a new m... - 99849 Views TotO 22:41, 26 April 14
Amstrad CPC 16... - 79813 Views SyX 21:31, 01 January 13
*FR* - FenixIn... - 44852 Views NewsBot 01:01, 13 January 11
Pac-Man emulat... - 28259 Views TotO 01:01, 02 April 12


Author Topic: Genesis8 - C Programming on Amstrad (SDCC, Z88dk and CCZ80)  (Read 4631 times)

0 Members and 1 Guest are viewing this topic.

Offline NewsBot

  • Your friendly news-fetching robot
  • 6128 Plus
  • ******
  • Posts: 2.293
  • Country: gr
  • Liked: 256
C Programming on Amstrad (SDCC, Z88dk and CCZ80)
25 December 2011, 2:06 am

C Programming on Amstrad (SDCC, Z88dk and CCZ80)

Source: Genesis8 Amstrad Page

This content has been fetched from a third-party page feed.

Offline mr_lou

  • 6128 Plus
  • ******
  • Posts: 2.833
  • Country: dk
    • index.php?action=treasury
    • 8-bit Memoirs - a Blu-ray diskmag-like eBook about the 8-bit era
  • Liked: 1043
Re: Genesis8 - C Programming on Amstrad (SDCC, Z88dk and CCZ80)
« Reply #1 on: 18:07, 25 December 11 »
Quote
First,the windows C compiler SDCC v3.1.0 targetting Z80 is out.

Not true. SDCC is not a "windows" C compiler. It's just a C compiler, and is available for multiple platforms. It's part of the repository of Ubuntu for example.

(Just thought it should be mentioned).

Offline genesis8

  • CPC6128
  • ****
  • Posts: 174
  • Country: fr
    • Genesis8 Amstrad Page
  • Liked: 44
Re: Genesis8 - C Programming on Amstrad (SDCC, Z88dk and CCZ80)
« Reply #2 on: 18:17, 25 December 11 »
Not true. SDCC is not a "windows" C compiler. It's just a C compiler, and is available for multiple platforms. It's part of the repository of Ubuntu for example.

Thanks, I corrected this mistake.
____________
Amstrad news site at Genesis8 Amstrad Page

Offline mr_lou

  • 6128 Plus
  • ******
  • Posts: 2.833
  • Country: dk
    • index.php?action=treasury
    • 8-bit Memoirs - a Blu-ray diskmag-like eBook about the 8-bit era
  • Liked: 1043
Re: Genesis8 - C Programming on Amstrad (SDCC, Z88dk and CCZ80)
« Reply #3 on: 10:42, 26 December 11 »
I didn't know we had 3 different C compilers to choose from. Never heard of CCZ80 before.

As far as I can see, SDCC seems to be the preferred choice with most CPC coders. But it would be nice to hear from experiences from people using the different compilers. (I know this has been talked about earlier, and I'd use the search if there was one, but there's no search-button anymore in the dark theme I'm using).

I've used Z88DK myself earlier with CPCRSlib and found it to be a good solution for what I needed at the time. I'm looking forward to digging deeper into SDCC with my current sMIDP2lib project though.
Anyone used CCZ80?

I know arnoldemu used Z88DK for some projects, but I don't remember how he liked it.
« Last Edit: 11:17, 26 December 11 by mr_lou »

Offline TFM

  • Visit the mysteries of the CPC at www.futureos.de
  • Supporter
  • 6128 Plus
  • *
  • Posts: 9.899
  • Country: aq
  • Space Chicken for FutureOS is free!
    • index.php?action=treasury
    • FutureOS - The revolution on CPC!
  • Liked: 1977
Re: Genesis8 - C Programming on Amstrad (SDCC, Z88dk and CCZ80)
« Reply #4 on: 11:21, 26 December 11 »
How strange is that? Not a single C compiler for the CPC was mentioned, and there are a lot: Small-C, Aztec-C, Arnor-C, Hitech-C, FrozenC and much more...
TFM of FutureSoft
Also visit the CPC and Plus users favorite OS: FutureOS - The Revolution on CPC6128 and 6128Plus

Offline mr_lou

  • 6128 Plus
  • ******
  • Posts: 2.833
  • Country: dk
    • index.php?action=treasury
    • 8-bit Memoirs - a Blu-ray diskmag-like eBook about the 8-bit era
  • Liked: 1043
Re: Genesis8 - C Programming on Amstrad (SDCC, Z88dk and CCZ80)
« Reply #5 on: 11:29, 26 December 11 »
How strange is that? Not a single C compiler for the CPC was mentioned, and there are a lot: Small-C, Aztec-C, Arnor-C, Hitech-C, FrozenC and much more...

Yea, the title is somewhat misleading, since it's not really about C programming on the CPC, but rather for the CPC.

Offline TFM

  • Visit the mysteries of the CPC at www.futureos.de
  • Supporter
  • 6128 Plus
  • *
  • Posts: 9.899
  • Country: aq
  • Space Chicken for FutureOS is free!
    • index.php?action=treasury
    • FutureOS - The revolution on CPC!
  • Liked: 1977
Re: Genesis8 - C Programming on Amstrad (SDCC, Z88dk and CCZ80)
« Reply #6 on: 22:01, 26 December 11 »
On the one hand I think it's quite amazing that todays supercomputers can be used to create machine code from C language source code including all kind of "modern" constructions.
 
On the other hand I always have a strange feeling when I depend on another machine to use "my" machine. The logical consequence of using a supercomputer (and yes, the PC in one, since it's CPU has roughly 100.000 times more power than the Z80 with 4 MHz) would be: Create the code on it, and also for it! Because there it will run faster.
 
So in a way I prefer to have it ALL on a CPC.
 
Funny thing is: There are some CPC users creating whole software environments on PC targetting the CPC, but the same persons refuse hardware expansions on a CPC.
 
Well, I'm sorry for getting offtopic here, it's X-mas, we got time ;-)
 
TFM of FutureSoft
Also visit the CPC and Plus users favorite OS: FutureOS - The Revolution on CPC6128 and 6128Plus

Offline ervin

  • Supporter
  • 6128 Plus
  • *
  • Posts: 1.261
  • Country: au
    • index.php?action=treasury
  • Liked: 932
Re: Genesis8 - C Programming on Amstrad (SDCC, Z88dk and CCZ80)
« Reply #7 on: 06:03, 27 December 11 »
I didn't know we had 3 different C compilers to choose from. Never heard of CCZ80 before.

As far as I can see, SDCC seems to be the preferred choice with most CPC coders. But it would be nice to hear from experiences from people using the different compilers. (I know this has been talked about earlier, and I'd use the search if there was one, but there's no search-button anymore in the dark theme I'm using).

I've used Z88DK myself earlier with CPCRSlib and found it to be a good solution for what I needed at the time. I'm looking forward to digging deeper into SDCC with my current sMIDP2lib project though.
Anyone used CCZ80?

I know arnoldemu used Z88DK for some projects, but I don't remember how he liked it.

I've used ccz80 a lot over the last 2 years or so.
I absolutely love it.

C-syntax, without all the faffing about with header files and other such nonsense.
And it produces fast binaries.

In-line assembler is easy to incorporate, although you have to put quotes around each machine code instruction.
eg.

LD A,1
ADD A,A
ADD A,B

would be written as

asm
{
"LD A,1",
 "ADD A,A",
 "ADD A,B",
 }

This is initally a bit annoying, but it soon becomes second nature.

Also, it is really easy to incorporate the compiled BIN file into a DSK, or to simply load it into WinAPE via the assembler.
And (like the other compilers, I presume?) you can export the compiled machine code to an asm file. I do that all the time in order to get a base for further optimisation. Fantastic stuff.

My Chunky Pixel Collision project is being written in ccz80.
I can't imagine producing a cpc program without it.

If anyone feels like playing with ccz80 and needs help getting it going (it's not hard), I'm happy to help.
 :)
« Last Edit: 06:06, 27 December 11 by ervin »
My (cancelled) entry for the CPCRetroDev 2017 Competition http://www.cpcwiki.eu/forum/programming/my-cpcretrodev-2017-entry/
FAST line drawing in CPCtelera http://www.cpcwiki.eu/forum/programming/drawing-lines-with-cpctelera-sdcc/
RUNCPC My entry for the CPCRetroDev 2015 Competition http://www.cpc-power.com/index.php?page=detail&num=12494

Offline mr_lou

  • 6128 Plus
  • ******
  • Posts: 2.833
  • Country: dk
    • index.php?action=treasury
    • 8-bit Memoirs - a Blu-ray diskmag-like eBook about the 8-bit era
  • Liked: 1043
Re: Genesis8 - C Programming on Amstrad (SDCC, Z88dk and CCZ80)
« Reply #8 on: 10:20, 27 December 11 »
@ervin, what about assembler syntax?
SDCC requires us to use ASxxxx. (Although we can have SDCC just compile into assembler, and then use NoRecess' translator before using Pasmo to compile, expect it doesn't always work).
And I think Z88DK uses Maxam syntax.

Offline ervin

  • Supporter
  • 6128 Plus
  • *
  • Posts: 1.261
  • Country: au
    • index.php?action=treasury
  • Liked: 932
Re: Genesis8 - C Programming on Amstrad (SDCC, Z88dk and CCZ80)
« Reply #9 on: 12:46, 27 December 11 »
@ervin, what about assembler syntax?
SDCC requires us to use ASxxxx. (Although we can have SDCC just compile into assembler, and then use NoRecess' translator before using Pasmo to compile, expect it doesn't always work).
And I think Z88DK uses Maxam syntax.

Unfortunately I am a bit clueless with differences in assembler syntax.
The only assembly code I've ever tried is within ccz80, so I don't know what other syntaxes look like.  :-[

I've attached some ccz80-generated assembly code, in case that helps.
It's also worth noting that ccz80 seems to be really good regarding undocumented z80 instructions, although I haven't tried all of them.  :)

EDIT: It seems that attachments are a bit wonky on cpcwiki at the moment.
Here is a link to the example assembly code:
http://dl.dropbox.com/u/339282/dbuffer.asm
« Last Edit: 12:55, 27 December 11 by ervin »
My (cancelled) entry for the CPCRetroDev 2017 Competition http://www.cpcwiki.eu/forum/programming/my-cpcretrodev-2017-entry/
FAST line drawing in CPCtelera http://www.cpcwiki.eu/forum/programming/drawing-lines-with-cpctelera-sdcc/
RUNCPC My entry for the CPCRetroDev 2015 Competition http://www.cpc-power.com/index.php?page=detail&num=12494

Offline fano

  • Supporter
  • 6128 Plus
  • *
  • Posts: 830
  • Country: fr
  • Easter Egg Programmer
    • Easter Egg
  • Liked: 267
Re: Genesis8 - C Programming on Amstrad (SDCC, Z88dk and CCZ80)
« Reply #10 on: 19:40, 27 December 11 »

Funny thing is: There are some CPC users creating whole software environments on PC targetting the CPC, but the same persons refuse hardware expansions on a CPC.
But that may change if some become very popular  ;D
"NOP" is the perfect program : short , fast and (known) bug free

Follow Easter Egg products on Facebook !

Offline TFM

  • Visit the mysteries of the CPC at www.futureos.de
  • Supporter
  • 6128 Plus
  • *
  • Posts: 9.899
  • Country: aq
  • Space Chicken for FutureOS is free!
    • index.php?action=treasury
    • FutureOS - The revolution on CPC!
  • Liked: 1977
Re: Genesis8 - C Programming on Amstrad (SDCC, Z88dk and CCZ80)
« Reply #11 on: 00:22, 28 December 11 »
But that may change if some become very popular  ;D

Thanks' for that X-Mas gift. It brings back hope to me :)
TFM of FutureSoft
Also visit the CPC and Plus users favorite OS: FutureOS - The Revolution on CPC6128 and 6128Plus

Offline genesis8

  • CPC6128
  • ****
  • Posts: 174
  • Country: fr
    • Genesis8 Amstrad Page
  • Liked: 44
Re: Genesis8 - C Programming on Amstrad (SDCC, Z88dk and CCZ80)
« Reply #12 on: 20:38, 04 January 12 »
Yea, the title is somewhat misleading, since it's not really about C programming on the CPC, but rather for the CPC.

I corrected the title and the news according to what TFM and you wrote (a few days ago).
____________
Amstrad news site at Genesis8 Amstrad Page

Offline MacDeath

  • Chaotic post writer and mock-up specialist
  • Supporter
  • 6128 Plus
  • *
  • Posts: 4.038
  • Country: fr
  • Liked: 1108
Re: Genesis8 - C Programming on Amstrad (SDCC, Z88dk and CCZ80)
« Reply #13 on: 22:09, 13 January 12 »
Quote
On the one hand I think it's quite amazing that todays supercomputers can be used to create machine code from C language source code including all kind of "modern" constructions.
 
On the other hand I always have a strange feeling when I depend on another machine to use "my" machine. The logical consequence of using a supercomputer (and yes, the PC in one, since it's CPU has roughly 100.000 times more power than the Z80 with 4 MHz) would be: Create the code on it, and also for it! Because there it will run faster.
 
So in a way I prefer to have it ALL on a CPC.
 
Funny thing is: There are some CPC users creating whole software environments on PC targetting the CPC, but the same persons refuse hardware expansions on a CPC.
:D

Sadly most stuff like good old CPC C compilers do have outdated interface and few of the modern commodities like copypast, automatic words, GUI debugger and so on.
Or am I wrong ?

Also you have to often save on disk (or whatever you have) and can't run a MP3 or porn while coding. :)


Anyway, now I have Hardware extensions, I hope your new FutureOS will be top notch.


 
when will we have Java for CPC too ?

philip

  • Guest
Hi guys! I'm new about assembler programming and now I found this page and I wish to know more about C programming but on a real cpc464, is there a tape or an mp3 file  containing a C compiler for the cpc...and where can I find one? Thanks for your help!

Offline AMSDOS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.584
  • Country: au
    • index.php?action=treasury
    • Programs for Turbo Pascal 3
  • Liked: 845
Hi guys! I'm new about assembler programming and now I found this page and I wish to know more about C programming but on a real cpc464, is there a tape or an mp3 file  containing a C compiler for the cpc...and where can I find one? Thanks for your help!


Hi Phillip,


Initially I thought Hisoft C might of been made for Tape and Disc, but now it appears it's a Disc only. The Languages on offer here (SDCC, Z88DK and CCZ80) are languages you run through your Windows, Linux, MacOS(?) Box, which then compile the programs that you can run through your CPC or Emulator.


So there doesn't appear to be any C Language available on tape, which leaves you with Pascal, Forth, or some BASIC compiler. This page lists all the Languages (which also includes the PC based ones which only create programs for CPC), any of those which include AMSOFT will most likely have a Tape.
Personally I use Hisoft Pascal 4T which exists on Tape, which has an online manual on here and have made a thread of stuff here, though much of it is rewritten programs from BASIC type-ins and some of that 10-Liner BASIC stuff easily becomes 100 Lines of Pascal Code, but it's probably the closest thing to C like language that exists on Tape. Hisoft Pascal 4T also allows for easy Integration of Firmware, which is the BASICs of using Assembly and I've also integrated RSXs into that as well.


I haven't had much to do with Forth, there seems to be Forth and Fig-Forth and have only really played around with it as a System Language on a Jupiter Ace emulator, though it's supposed to be powerful language when a combination of routines are applied.

BASIC wise I'm only familiar with the Laser BASIC Compiler which is available on Tape
* Using some of the hardly used Amstrad compilers :D
* I use Firmware in my Assembly code :P
* Have interpreted some BASIC 1.1 programs for BASIC 1.0. :)

Offline AMSDOS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.584
  • Country: au
    • index.php?action=treasury
    • Programs for Turbo Pascal 3
  • Liked: 845
Re: Genesis8 - C Programming on Amstrad (SDCC, Z88dk and CCZ80)
« Reply #16 on: 08:50, 27 November 15 »
Initially I thought Hisoft C might of been made for Tape and Disc, but now it appears it's a Disc only.


I know it's been ages since Phillip wrote in asking about a C Compiler for his 464, and no reply was ever made, but there seems to be evidence contrary to what I've quoted earlier...





...So the burning question is where to find a Tape Copy of Hisoft C?
* Using some of the hardly used Amstrad compilers :D
* I use Firmware in my Assembly code :P
* Have interpreted some BASIC 1.1 programs for BASIC 1.0. :)

Offline reidrac

  • Supporter
  • 6128 Plus
  • *
  • Posts: 658
  • Country: gb
  • Trying to gamedev!
    • index.php?action=treasury
    • usebox.net
  • Liked: 1161
Re: Genesis8 - C Programming on Amstrad (SDCC, Z88dk and CCZ80)
« Reply #17 on: 10:05, 27 November 15 »
I don't know how usable it was or what "C" would it be.

My experience with my first PC (8086, 512KB RAM, DOS 3.0, no HDD) was that running "make" to compile a "hello world" in C required changing diskette 3 times. It was not usable without a hard disk.

Nice finding though.
Released The Return of Traxtor, Golden Tail, Magica and The Dawn of Kernel for the CPC.

If you like my games and want to show some appreciation, you can always buy me a coffee.

Offline AMSDOS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.584
  • Country: au
    • index.php?action=treasury
    • Programs for Turbo Pascal 3
  • Liked: 845
Re: Genesis8 - C Programming on Amstrad (SDCC, Z88dk and CCZ80)
« Reply #18 on: 10:46, 27 November 15 »
I don't know how usable it was or what "C" would it be.


It's Hisoft C, 3rd program down under their Amstrad CPC software. This particular language was available for AMSDOS as well as CP/M. If I correctly recall, @arnoldemu suggested this compiler was used once to write the Ocean game Miami Vice, if that's any indication on how usable it was, though while I've played Miami Vice, it's a very frustrating game to play.  :D


Quote
My experience with my first PC (8086, 512KB RAM, DOS 3.0, no HDD) was that running "make" to compile a "hello world" in C required changing diskette 3 times. It was not usable without a hard disk.


Not Turbo C by any chance? Usually when I saw a system like that it had 2 x 5.25" drives.


Quote
Nice finding though.


This was the other Hisoft ad I initially saw. While it's clearing stating it's on Tape/Disk & CP/M, no mention regarding if it's 464 friendly, maybe it's like Advance Art Studio, which was available on Tape, though 128kb required?

EDIT: Sorry having problems uploading image! :(
« Last Edit: 11:06, 27 November 15 by AMSDOS »
* Using some of the hardly used Amstrad compilers :D
* I use Firmware in my Assembly code :P
* Have interpreted some BASIC 1.1 programs for BASIC 1.0. :)

Offline reidrac

  • Supporter
  • 6128 Plus
  • *
  • Posts: 658
  • Country: gb
  • Trying to gamedev!
    • index.php?action=treasury
    • usebox.net
  • Liked: 1161
Re: Genesis8 - C Programming on Amstrad (SDCC, Z88dk and CCZ80)
« Reply #19 on: 10:55, 27 November 15 »
It's Hisoft C, 3rd program down under their Amstrad CPC software. This particular language was available for AMSDOS as well as CP/M. If I correctly recall, @arnoldemu suggested this compiler was used once to write the Ocean game Miami Vice, if that's any indication on how usable it was, though while I've played Miami Vice, it's a very frustrating game to play.  :D

It mentions "C integer K&R"; don't know what that "integer" means but my experience with Kernighan & Ritchie is that... you want ANSI C :)

(EDIT: I see "with the exception of float point support", so that's the "integer" part of it)

Not Turbo C by any chance? Usually when I saw a system like that it had 2 x 5.25" drives.

Yes, I think it was Turbo C. I had only a 730K diskette drive, that was OK for GWBASIC or RMI Cobol (both had IDE + interpreter self-contained in one single program).

This was the other Hisoft ad I initially saw. While it's clearing stating it's on Tape/Disk & CP/M, no mention regarding if it's 464 friendly, maybe it's like Advance Art Studio, which was available on Tape, though 128kb required?

Yep, that "tape" is interesting. The 6128 was a great machine for development back then, but I believe it was mostly because the disk drive was amazing :)
« Last Edit: 11:06, 27 November 15 by reidrac »
Released The Return of Traxtor, Golden Tail, Magica and The Dawn of Kernel for the CPC.

If you like my games and want to show some appreciation, you can always buy me a coffee.

Offline AMSDOS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.584
  • Country: au
    • index.php?action=treasury
    • Programs for Turbo Pascal 3
  • Liked: 845
Re: Genesis8 - C Programming on Amstrad (SDCC, Z88dk and CCZ80)
« Reply #20 on: 11:24, 27 November 15 »
It mentions "C integer K&R"; don't know what that "integer" means but my experience with Kernighan & Ritchie is that... you want ANSI C :)


Hmmm  ::)  Cannot get image up, be faster typing in Hisoft's Description of their C.


Quote
AMSTRAD   
£34.95 
tape


£39.95
[/size]disc


All our versions of C adhere very closely to the Kernighan & Ritchie definition of the language with the exception of floating-point. The Amstrad and Spectrum versions come with libraries supporting the sound and graphics of these machines (including GSX for Amstrad CPC6128 and PCW8256/8512!). Thew compilers are very fast, produce quick, compact code and come with interactive editors which make error correction a natural part of the programming process. See the reviews in this issue for details.

The integer they mention in their case means their language only supports Integer, more or less a step backwards from their earlier AMSOFT Hisoft Pascal 4T, which supports Floating Numbers, Integers, Char, but no Byte.

ANSI I understand is the implementation of standardizing C. K&R I presume means to prepare for the unexpected.

Quote
Yes, I think it was Turbo C. I had only a 730K diskette drive, that was OK for GWBASIC or RMI Cobol (both had IDE + interpreter self-contained in one single program).


I don't know much about Turbo C, and for some reason I thought I had something like 2 files for the whole thing, though that can't be right if C is based on being a collection of Library Files to compile the program, a 720Kb disk probably isn't much if compiled programs were large.

Quote
Yep, that "tape" is interesting. The 6128 was a great machine for development back then, but I believe it was mostly because the disk drive was amazing :)


Well the quote I posted above simply goes into detail about the CP/M version.  ???
* Using some of the hardly used Amstrad compilers :D
* I use Firmware in my Assembly code :P
* Have interpreted some BASIC 1.1 programs for BASIC 1.0. :)

Offline Munchausen

  • 6128 Plus
  • ******
  • Posts: 771
  • Country: gb
  • Liked: 211
Re: Genesis8 - C Programming on Amstrad (SDCC, Z88dk and CCZ80)
« Reply #21 on: 12:32, 29 November 15 »
I think it would be nice to have a C compiler that runs on the CPC and can use the RAM expansions. There should be much more room for running optimisations.

However I've also spotted an LLVM backend for the Z80. I don't think it's completely finished, but appears to work fairly well. It would be interesting to see what sort of code a heavy duty modern C compiler can generate for the CPC. earl1k/llvm-z80 · GitHub

Offline Alcoholics Anonymous

  • CPC664
  • ***
  • Posts: 51
  • Country: ca
  • Liked: 44
Re: Genesis8 - C Programming on Amstrad (SDCC, Z88dk and CCZ80)
« Reply #22 on: 00:14, 30 November 15 »
I think it would be nice to have a C compiler that runs on the CPC and can use the RAM expansions. There should be much more room for running optimisations.

Hitech C v3.09 for cp/m is actually fairly good.  It supports ANSI-C, has reasonably complete libraries and the quality of code output is fairly high.  The other native compilers I have seen are missing quite a lot and the code generation isn't too great.  I think with Hitech C you may be able to target a generic z80 device but otherwise getting it to target something other than cp/m may be a problem.  For that maybe the only reasonable alternative is to use something like mess-c that at least is being developed now for the cpc specifically.

In terms of optimizations, a native z80 compiler has no chance in comparison to the cross-compilers.  Maybe you can fit all the data space you need on hard disks or floppies but compile time would make it unusable.  But even without fancy optimizations you can still get reasonably good results, as hitech C shows, particularly if the library is written in assembly language.  Asm libraries are more important than C code generation quality when it comes to program size and speed.  With a native C compiler it's probably much more important to focus on small code generation and rely on the libraries to deliver performance.

Quote
However I've also spotted an LLVM backend for the Z80. I don't think it's completely finished, but appears to work fairly well. It would be interesting to see what sort of code a heavy duty modern C compiler can generate for the CPC. earl1k/llvm-z80 · GitHub

I looked at that some time ago.  It's in a very early stage and looks abandoned.

I don't think a front end generated by llvm is going to be much better than the front end in sdcc, eg.  When I look at the code output from sdcc, it doesn't often do things in an unoptimal way.  The problems are coming from how it does those things.  I think the main problem right now is that the z80 is treated as an 8-bit processor and opportunities to do things in 16-bits are missed.  Most of these problems can be fixed with peephole rules.

Have a look at a before and after here:

eilza.zip - Google Drive

"eliza_so2.opt" is the output generated by sdcc on its own.
"eliza_so3.opt" is the output corrected by additional peephole rules.

The resulting code quality is fairly high.

Because the z80 is treated as 8-bit sometimes code cannot be corrected.. there are times when sdcc actually reverses the endianness of numbers (eg loading a 16-bit quantity into "ED" rather than "DE") which makes it difficult to correct to 16-bit in an isolated manner because isolated changes need extra register moves to undo the reversed endiannes and that's not free.

Using only peephole rules like the above, sdcc's output was sped up 24% in the Drhystone2.1 benchmark.  After the speed up, it beat Hitech C v7.50 (MSDOS cross-compiler with good reputation) by 17%.  I wish I had access to IAR's compiler for comparison as that one is supposed to generate the best results.

This is an (old) synthetic benchmark that was meant to be representative of typical integer programs.  Looking at the code output, the generated code wasn't bad but not as good as hand-assembly largely because of stack frame use.  llvm is not going to solve that; that's up to the programmer to use statics instead of locals where it makes sense.

The integer they mention in their case means their language only supports Integer, more or less a step backwards from their earlier AMSOFT Hisoft Pascal 4T, which supports Floating Numbers, Integers, Char, but no Byte.

OTOH, very few programs need floating point :)  If the implementation is only a 32-bit float, you probably can't do financial calculations with it either.

Quote
ANSI I understand is the implementation of standardizing C. K&R I presume means to prepare for the unexpected.

The first ANSI standard is C89 (or C90 if you prefer that name).  This is the C most people are familiar with.  Before this it was K&R C, referring to the original C and described in K&R's C book.  Prototypes are not there, much of the standard library is not standard yet, and you have that weird function syntax with parameter types listed after the function and before the opening '{'.  I find it quite frustrating to use and read but that's because I'm used to how nice everything is starting with C89.
« Last Edit: 00:16, 30 November 15 by Alcoholics Anonymous »

Offline AMSDOS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.584
  • Country: au
    • index.php?action=treasury
    • Programs for Turbo Pascal 3
  • Liked: 845
Re: Genesis8 - C Programming on Amstrad (SDCC, Z88dk and CCZ80)
« Reply #23 on: 08:53, 30 November 15 »

Hitech C v3.09 for cp/m is actually fairly good.  It supports ANSI-C, has reasonably complete libraries and the quality of code output is fairly high.  The other native compilers I have seen are missing quite a lot and the code generation isn't too great.  I think with Hitech C you may be able to target a generic z80 device but otherwise getting it to target something other than cp/m may be a problem.  For that maybe the only reasonable alternative is to use something like mess-c that at least is being developed now for the cpc specifically.


I noticed Phrozen C is a CPC implementation, though it's based on Small-C. Small-C itself operates under CP/M, though you're probably aware it can compile code for a number of operating systems. I guess if Hitech C produces assembly source, that is at least better than having some compiler produce some COM file. 


Fair enough though I wouldn't have considered Small-C being K&R.


Quote
OTOH, very few programs need floating point


I seem to be using it a bit then in Random Number Generators & Calculating the Cosine & Sine for Drawing/Plotting a circle, do you have an integer based approach for those problems?


Quote
If the implementation is only a 32-bit float, you probably can't do financial calculations with it either.


It's not something I've considered, even though I've got books on the topic.


Quote
The first ANSI standard is C89 (or C90 if you prefer that name).  This is the C most people are familiar with.  Before this it was K&R C, referring to the original C and described in K&R's C book.  Prototypes are not there, much of the standard library is not standard yet, and you have that weird function syntax with parameter types listed after the function and before the opening '{'.  I find it quite frustrating to use and read but that's because I'm used to how nice everything is starting with C89.


So the original C was used to write Unix wasn't it? Or was it BCPL? I just would of thought that C would of been standardised for such a large scale project.
* Using some of the hardly used Amstrad compilers :D
* I use Firmware in my Assembly code :P
* Have interpreted some BASIC 1.1 programs for BASIC 1.0. :)

Offline Executioner

  • Supporter
  • 6128 Plus
  • *
  • Posts: 783
  • Country: au
  • WinAPE Developer
    • WinAPE
  • Liked: 390
Re: Genesis8 - C Programming on Amstrad (SDCC, Z88dk and CCZ80)
« Reply #24 on: 10:26, 30 November 15 »
I seem to be using it a bit then in Random Number Generators & Calculating the Cosine & Sine for Drawing/Plotting a circle, do you have an integer based approach for those problems?

Yes, you can draw circles much faster using Bresneham integer methods and random numbers don't usually have much to do with floats when used in practice (eg. random 0..3 for direction, 10..20 for speed, 0..27 for colours etc). Most times when you use the random functions in BASIC/Pascal/Java etc you do things like x = (int)(Math.random() * 10), and for pure sine/cosine usage I find the most efficient implementation is X * sin(angle), as I've used it in assembler etc. (eg. 65536 * SIN(deg * 256 / 360)) in a table.