Please note, I did not write any of these tools, this is simplified and specific tutorial aimed at helping people get started on C coding on the BBC Micro using the tools that I have been using for my own game.
These instructions were written for Ubuntu 19.10/20.04, but should work unaltered on several Debian based linux distributions such as Debian, Ubuntu, Mint etc. It should be possible to use other Linux distributions and even Cygwin under Windows, but that's beyond the scope of this document.
We are basically following the instructions on;
https://github.com/itszor/gcc-6502-bits.git
Oddly one of the first things you need to do is install another C compiler for the 6502, cc65, this is because gcc uses its linker.
sudo apt-get install cc65
You compile up the 6502 compiler using your local machine's compiler, make sure it is installed, also grab a few extra tools and libraries.
sudo apt-get install build-essential flex git libboost-dev libboost-regex-dev dejagnu libgmp-dev libmpfr-dev libmpc-dev
Change to your home directory
cd ~
Checkout the code (this is about 6.3 GB so will take a while)
git clone --recursive https://github.com/itszor/gcc-6502-bits.git
Choose which version of gcc to build
cd gcc-6502-bits/gcc-src git checkout remotes/origin/m65x-gcc6-virt
Build the compiler, this takes an age, make a cup of tea, a four course meal and learn a language
cd .. (into the gcc-6502-bits directory) ./build.sh 2>&1 | tee build.log
Check that the compiler built
cd prefix/bin ls
You should see the following files here
6502-cpp 6502-gcc-6.4.1 6502-gcc-nm 6502-gcov 6502-gcov-tool 6502-gcc 6502-gcc-ar 6502-gcc-ranlib 6502-gcov-dump
Download this example Hello World program and uncompress it somewhere.
You will need to edit the Makefile to change the path to the gcc compiler to the one in your home directory (unless you are also called peter).
The Makefile creates BBC model B compatible programs by default (which also work on the BBC Master). If you want BBC Master compatibility only (to make use of more memory), edit the Makefile and change the LDFLAGS line from bbcb to bbcmaster, also use the hellow.inf.master in the next section.
When compiling programs the default is to compile programs suitable for MODE 7 (where more RAM is available), to compile programs for other modes, change the value of __STACKTOP__ in LDFLAGS in the Makefile to;
After tweaking the Makefile, build the program with;
make
Copy the hellow output file to your machine of choice and set the LOAD/EXEC addresses to &1900 or &E00 (for bbcb or bbcmaster compiled programs repectively), and run with *RUN HELLOW or *HELLOW.
Alternatively import the files with the .inf file to the emulator or disk image editor of your choice (rename the .inf.master to .inf if you compiled up a master version).
These are some extra wrappers I have written that you may find useful.
Click here for libraries README
Click here for the online API documentation
The main limitation on the BBC is memory as such most optimisations should be targetted to size rather than speed (but smaller code has less instructions so will likely be reasonably fast as well).