Page 1 of 1

C64/C16/Plus4-hosted Small C compiler cc64

Posted: Wed Nov 11, 2020 9:46 am
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

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

Posted: Wed Nov 11, 2020 10:52 am
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.

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

Posted: Mon Jan 25, 2021 11:01 pm
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/

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

Posted: Wed May 12, 2021 10:55 pm
by Gurft
Now I’m much more incentivized to get my Plus4 working properly again!

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

Posted: Fri May 14, 2021 10:10 pm
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.

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

Posted: Wed Jan 05, 2022 7:12 pm
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.

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

Posted: Mon Feb 07, 2022 3:35 am
by xlar54
This is great. Thank you!