C compiler

bbc micro/electron/atom/risc os coding queries and routines
Post Reply
marcelaj1
Posts: 442
Joined: Wed Apr 29, 2020 5:07 pm
Location: Surrey
Contact:

C compiler

Post by marcelaj1 »

In my former life I used to write software for a large telecomunications company, mainly in C and Oracle, with a bit of java, c++, and laterley VBA and .net thrown in.
Wanting to keep the little grey cells active and get back into it, I have been looking around the interwebs and there seem to be a number of C compilers around for the 6502 and the beeb specifically. The favourite seems to be "Small-C compiler for the BBC Micro", but people running Linux swear by (or at) 4corn cc65 anyone with experiance/wise words?
Ashley.
cmorley
Posts: 1867
Joined: Sat Jul 30, 2016 8:11 pm
Location: Oxford
Contact:

Re: C compiler

Post by cmorley »

I use itzor's gcc port (latest is gcc8). It kinda needs some backend work to be truely useful as the pointer dereferencing in particular produces some terribly clunky code. He hasn't touched the repo on githhub for a couple of years now though :(

I have looked at the backend but they are flipping complicated. It isn't something you can tinker with unless you're very much up to speed on that stuff. I've also considered making it more BBC friendly with runtime library ROMs but lack a motivating project to kickstart me into action.
User avatar
tricky
Posts: 7698
Joined: Tue Jun 21, 2011 9:25 am
Contact:

Re: C compiler

Post by tricky »

I'm pretty sure http://www.pouet.net/ uses a C cross-compiler with gcc frontend and maybe cc65 backend.
Flibble on here is using some gcc+? (probably cc65 again) C cross-compiler to write a Final Fantasy like game in C.

I think it is the backend, optionally plus a ROM, that is really needed to make C a general purpose language on the beeb.
I also think that it shouldn't be a cut down C unless you are planning on doing the compiling on the beeb.

Having said that, lots of projects here are not general purpose, but the authors still enjoy themselves creating them.

You might find this interesting: https://dwheeler.com/6502/.

I have had a few goes at writing a C cross-compiler for the beeb, but always end up creating a new C like language and then never getting anywhere on the compiler.

In general, if it is a cross-compiler, why stop at C, why not support C++ (C++98 would be fine for me ;) ?)
User avatar
Lardo Boffin
Posts: 2977
Joined: Thu Aug 06, 2015 7:47 am
Contact:

Re: C compiler

Post by Lardo Boffin »

Probably a little off topic but I used the Norcroft C compiler on the Arm Co-processor (raspberry Pi, not original sadly) and then used Twin as the text editor. All run directly on my Master.
It produces native ARM code I believe.
Adventure Language on GitHub
Atom, issue 5, YARRB + video noise killer
Elk
A number of econetted (is that a word?) Beebs
BBC Master, Datacentre + HDD, pi co-proc, econet, NULA
User avatar
flibble
Posts: 886
Joined: Tue Sep 22, 2009 11:29 am
Contact:

Re: C compiler

Post by flibble »

tricky wrote: Sat Jan 23, 2021 1:31 pm Flibble on here is using some gcc+? (probably cc65 again) C cross-compiler to write a Final Fantasy like game in C.
I'm using the Itzor branch of gcc (not cc65) that cmorley mentioned above, I wrote some instructions and helper library stuff you can find here.

http://www.4corn.co.uk/articles/gccforbbc/
User avatar
Ragster
Posts: 53
Joined: Fri May 12, 2023 10:42 am
Location: Buckinghamshire
Contact:

Re: C compiler

Post by Ragster »

flibble wrote: Sat Jan 23, 2021 8:02 pm
tricky wrote: Sat Jan 23, 2021 1:31 pm Flibble on here is using some gcc+? (probably cc65 again) C cross-compiler to write a Final Fantasy like game in C.
I'm using the Itzor branch of gcc (not cc65) that cmorley mentioned above, I wrote some instructions and helper library stuff you can find here.

http://www.4corn.co.uk/articles/gccforbbc/
Anyone tried getting this to work recently?

I tried pulling it, following the instructions, and it was all going swimmingly, until I got to:

Code: Select all

git clone --recursive https://github.com/itszor/gcc-6502-bits.git
It was pulling fine, until it got to gcc-src.
It exited with:
fatal: clone of 'http://www.github.com/itszor/gcc-6502' into submodule path '/home/rgodi/gcc-6502-bits/gcc-src' failed
Failed to clone 'gcc-src' a second time, aborting
I pulled the zip of a gcc-src directory from the history, and managed to get the first stage of build.sh to run (having corrected permissions), but it failed on the second stage..

Code: Select all

config.status: executing default commands
make[1]: Leaving directory '/home/rgodi/gcc-6502-bits/gcc-build'
make: *** [Makefile:883: all] Error 2
I could blow away the install and try again (a definition of madness being trying the same thing repeatedly and expecting different results), but if there's a simple solution, or something obvious I'm missing, it would be good to know.
User avatar
egrath
Posts: 76
Joined: Thu Feb 03, 2022 7:49 pm
Location: Steyr, Austria
Contact:

Re: C compiler

Post by egrath »

Lardo Boffin wrote: Sat Jan 23, 2021 6:34 pm Probably a little off topic but I used the Norcroft C compiler on the Arm Co-processor (raspberry Pi, not original sadly) and then used Twin as the text editor. All run directly on my Master.
It produces native ARM code I believe.
Which version of Norcroft you used? The one from the RISCOS DDE?
>>>>>>>>>>>Lets go
User avatar
Lardo Boffin
Posts: 2977
Joined: Thu Aug 06, 2015 7:47 am
Contact:

Re: C compiler

Post by Lardo Boffin »

I’m not sure to be honest. The disc image was provided by someone on here. I will have to have a look back and see.
Adventure Language on GitHub
Atom, issue 5, YARRB + video noise killer
Elk
A number of econetted (is that a word?) Beebs
BBC Master, Datacentre + HDD, pi co-proc, econet, NULA
User avatar
egrath
Posts: 76
Joined: Thu Feb 03, 2022 7:49 pm
Location: Steyr, Austria
Contact:

Re: C compiler

Post by egrath »

If you could provide the image, that would be great. I’m a registered DDE developer, so licensing should be no issue.
>>>>>>>>>>>Lets go
nicolagiacobbe
Posts: 215
Joined: Tue Jul 03, 2007 10:40 am
Location: italy
Contact:

Re: C compiler

Post by nicolagiacobbe »

In case anyone would be interested, SDCC (Small Devices C Compiler) latest version emits code for 65XX processors. I have not given a full turn to the compiler, just a few snippets here and there and the generated code is at least at cc65 level (maybe a little better but cannot swear for it).
User avatar
gordonDrogon
Posts: 94
Joined: Fri Nov 23, 2018 12:39 pm
Location: Scottish Borders
Contact:

Re: C compiler

Post by gordonDrogon »

C seems to be a holy grail of sorts for older systems - the 6502 being no exception.

My own ventures were aimed at making a 6502 SCB "self hosting" - so making it run the languages natively rather than cross compiling.. Basic was easy but when it came to C... Harder. I did use Aztec C on the Apple II before my Beeb exposure but early on, C for the Beeb? Not really and I ended up doing a big (university) Industrial control/Factory automation project on an Econeted network of many Beebs in BCPL, but that's a story for another day...

Latterly I made a 6502 SBC that is vaguely Acorn MOS compatible and created a port of cc65 for it with a target and startup/run time library that let me compile C as a "language ROM" and run it on my SBC. I never tried it on a real Beeb though.

I could refresh that project but ...

The biggest thing I write in C for it was a port of my small editor (a nano-like thing written in C) - it's about 1500 lines of code and whitespace and compiles to some 14KB of 6502, so fits inside a sideways ROM and worked very well.

Downsides - no floating point and having to cross compile under Linux.

I changed tack somewhat a few years back and moved to something else where I could compile and run directly on my SBC and haven't looked back at C (on the 6502) since.

There are a few other C compilers for the 6502 now - VBCC and Calypsi

http://www.compilers.de/vbcc.html
https://www.calypsi.cc/

There is also work on-going on LLVM

https://llvm-mos.org/wiki/Welcome



I wonder if someone could write a C to BBC Basic translator...

-Gordon
User avatar
Lardo Boffin
Posts: 2977
Joined: Thu Aug 06, 2015 7:47 am
Contact:

Re: C compiler

Post by Lardo Boffin »

egrath wrote: Sun Apr 07, 2024 10:52 am If you could provide the image, that would be great. I’m a registered DDE developer, so licensing should be no issue.
I will do but I need to remember who I got the original files from, ask them if I can pass them on and then extract them onto an image.
Adventure Language on GitHub
Atom, issue 5, YARRB + video noise killer
Elk
A number of econetted (is that a word?) Beebs
BBC Master, Datacentre + HDD, pi co-proc, econet, NULA
Post Reply

Return to “programming”