DiscoC is a custom systems programming language and complete toolchain (Compiler, Assembler, and Linker) targeting the Super Nintendo's SuperFX (GSU) RISC co-processor.
Written in Modern C++ (C++23), this project aims to bring modern development practices to legacy hardware constraints. It features a custom Relocatable Object File format, a dedicated Linker for memory mapping resolution, and hardware-specific optimizations.
Status: Pre-Alpha / Experimental This project is currently a work-in-progress. While fully functional (compiles and links binaries), the generated assembly focuses on correctness over speed. Advanced register allocation is on the roadmap. Also, it does not produce buidable ROMs, you must binclude the binary.
- C-like syntax (
if,for,while, variables, functions) word(16-bit) andbyte(8-bit) integer types- Full 24-bit pointer support with or without
farkeywords structdefinitions with member accessrom constfor placing data directly into the ROM- Direct hardware access via special keywords (
plot,set_color, etc.)
- Two-Stage Build Process: A separate compiler (
discc) and linker (discld) for multi-file projects. - Assembly Export: Inspect the compiler's output with the
--emit-asmflag. - Hardware-Specific Optimizations:
- Recognizes
forloops and converts them to the ultra-fastLOOPinstruction. - Optimizes small integer arithmetic into single-byte immediate instructions.
- Recognizes
- Custom Object File Format for relocatable code.
This is not just a parser; it is a full-stack compiler implementation including:
- Custom Object File Format: Designed a binary format supporting code/data sections, symbol tables, and relocation entries (patching
JALtargets and global variable addresses at link-time). - The
discldLinker: A custom linker built from scratch to handle symbol resolution, memory placement, and binary patching across multiple compilation units. - Peephole Optimization: The compiler analyzes the AST to detect high-level patterns (like decrementing
whileloops) and emits specialized hardware instructions (LOOPopcode) for zero-overhead looping. - Manual ABI Management: Implements a full stack frame convention (Frame Pointer
R9, Stack PointerR10) to support recursion and local scope management. - Software-Defined Arithmetic: Implementation of BF16 (Brain Float 16) and FP16 logic purely in software to enable modern numerics on a 16-bit integer chip.
Here is a simple example of a DiscoC program with two functions.
// main.dc
// Forward declare the function from another file.
word add(word a, word b);
void main() {
word result = add(30, 12);
// After this, R0 would hold the value 42.
}// math.dc
word add(word a, word b) {
return a + b;
}This project uses C++23 and CMake.
# 1. Clone the repository
git clone https://github.com/DiscoManOfficial/DiscoC.git
cd DiscoC
# 2. Configure the build using CMake
mkdir build
cd build
cmake ..
# 3. Build the executables (discc and discld)
cmake --build .After a successful build, the discc and discld executables will be located in the build/Debug or build directory.
The DiscoC toolchain uses a two-step compile-and-link process.
1. Compile: Use discc to compile each .dc source file into an intermediate .o object file.
# Compile main.dc into main.o
./discc ../main.dc -o main.o
# Compile math.dc into math.o
./discc ../math.dc -o math.o2. Link: Use discld to link all your .o files into a final .bin ROM.
# Link main.o and math.o into the final ROM
./discld main.o math.o -o my_game.binYou now have a complete, runnable my_game.bin file!
This project is not as actively developed. You can view our grand roadmap and upcoming features in the ROADMAP.md file.
DiscoC is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be a useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/.