C64/C16/Plus4-hosted Small C compiler cc64

Programming the 6502 microprocessor and its relatives in assembly and other languages.
Post Reply
pzembrod
Posts: 22
Joined: 05 Sep 2020
Contact:

C64/C16/Plus4-hosted Small C compiler cc64

Post by pzembrod »

Hi all,

I would like to share an old university years project of mine,
a Small C compiler written in Forth, running on C64 or Plus4 and
targeting the 6502. It had hibernated for ~25 years in almost
working form. Recently I have picked it up again and open-sourced it.
It lives here: https://github.com/pzembrod/cc64

I won't advertise this yet as a full tool for C programming, since
a real library is still on the todo list, as well as ANSI style
function definitions (so far it's K&R only).
But apart from that, for coding
locally on the Commodore machines, as an alternative to
cross-development, cc64 should already be a practical option.

I would love to hear some feedback if anyone wants to try it out.

Cheers
/Philip
User avatar
BigEd
Posts: 11463
Joined: 11 Dec 2008
Location: England
Contact:

Re: C64/C16/Plus4-hosted Small C compiler cc64

Post by BigEd »

Welcome! Can I suggest we use this thread, in Programming, to discuss the usage of this compiler? We can use the other thread, in Forth, to discuss the implementation.
pzembrod
Posts: 22
Joined: 05 Sep 2020
Contact:

Re: C64/C16/Plus4-hosted Small C compiler cc64

Post by pzembrod »

An update on this: I've recently gotten cc64 to run on the Commander X16:
https://www.commanderx16.com/forum/inde ... -cc64-x16/
Gurft
Posts: 17
Joined: 06 May 2005
Location: Limerick, PA

Re: C64/C16/Plus4-hosted Small C compiler cc64

Post by Gurft »

Now I’m much more incentivized to get my Plus4 working properly again!
pzembrod
Posts: 22
Joined: 05 Sep 2020
Contact:

Re: C64/C16/Plus4-hosted Small C compiler cc64

Post by pzembrod »

Gurft wrote:
Now I’m much more incentivized to get my Plus4 working properly again!
Glad to hear that! :-)

The latest release brought a decent compile speed increase (https://github.com/pzembrod/cc64/releases/tag/v0.9), and I'm currently working on enabling ANSI-style function definitions.
pzembrod
Posts: 22
Joined: 05 Sep 2020
Contact:

Re: C64/C16/Plus4-hosted Small C compiler cc64

Post by pzembrod »

Just before Christmas I released v0.10 (https://github.com/pzembrod/cc64/releases/tag/v0.10) which brings the mentioned ANSI syntax for function definitions (no type check between formal and actual params, though), better support for fastcall functions, and a basic libc, partially written in C, ported from https://pdclib.rootdirectory.de/, and partially rewritten in 6502 assembly. Of course, only a subset of functions was feasible and made sense due to limitations of both the compiler and the target platforms (C64, C16, X16).
A piece of code that I was initially most scared off was printf(). I thought it would need to turn into a monster in size and complexity. But surprisingly it was rather enjoyable, both to decide on a limit for features, and to squeeze those features into as compact and efficient code as I could. I even had fun sacrificing readability for efficiency in a few places, something I usually avoid, and instead tried to mollify my future self with extensive code comments where it seemed useful.
The code lives at https://github.com/pzembrod/cc64/blob/m ... e/printf.a if anyone wants to take a look.
xlar54
Posts: 28
Joined: 18 Oct 2017

Re: C64/C16/Plus4-hosted Small C compiler cc64

Post by xlar54 »

This is great. Thank you!
Post Reply