News:

Printed Amstrad Addict magazine announced, check it out here!

Main Menu
avatar_NewsBot

Genesis8 - C Programming on Amstrad (SDCC, Z88dk and CCZ80)

Started by NewsBot, 13:00, 25 December 11

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

NewsBot

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

mr_lou

QuoteFirst,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).

genesis8

Quote from: mr_lou on 17:07, 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

mr_lou

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.

TFM

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

mr_lou

Quote from: TFM/FS on 10: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...

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

TFM

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

ervin

Quote from: mr_lou on 09: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.

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.
:)

mr_lou

@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.

ervin

Quote from: mr_lou on 09: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.

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

fano

Quote from: TFM/FS on 21:01, 26 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 !

TFM

Quote from: fano on 18:40, 27 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

genesis8

Quote from: mr_lou on 10:29, 26 December 11
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

MacDeath

QuoteOn 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

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!

AMSDOS

Quote from: philip on 06:45, 26 April 15
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 the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

AMSDOS

Quote from: AMSDOS on 12:13, 26 April 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 the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

reidrac

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, The Dawn of Kernel, Kitsune`s Curse, Brick Rick and Hyperdrive for the CPC.

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

AMSDOS

Quote from: reidrac on 09:05, 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! :(
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

reidrac

Quote from: AMSDOS on 09:46, 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)

Quote from: AMSDOS on 09:46, 27 November 15
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).

Quote from: AMSDOS on 09:46, 27 November 15
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 :)
Released The Return of Traxtor, Golden Tail, Magica, The Dawn of Kernel, Kitsune`s Curse, Brick Rick and Hyperdrive for the CPC.

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

AMSDOS

Quote from: reidrac on 09:55, 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 the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

Munchausen

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

Alcoholics Anonymous

#22
Quote from: Munchausen on 11: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.

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.

Quote from: AMSDOS on 10:24, 27 November 15
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.

AMSDOS


Quote from: Alcoholics Anonymous on 23:14, 29 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.


QuoteOTOH, 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?


QuoteIf 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.


QuoteThe 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 the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

Executioner

Quote from: AMSDOS on 07:53, 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.

Powered by SMFPacks Menu Editor Mod