Overview
DevCPC supports C compilation using SDCC (Small Device C Compiler), allowing you to write game logic in C while leveraging the 8BP library or direct firmware calls.Requirements
Configuration Options
Directory containing C source files
Main C source file to compile (e.g.,
main.c)Memory address where compiled code will be loaded (must be < 23999)
Memory Limits
The compiled C code must not exceed address 23999 (0x5DBF) to avoid destroying the 8BP library:Using 8BP from C
DevCPC includes an 8BP wrapper header for calling 8BP functions from C:C/main.c
Compilation Process
When you rundevcpc build, the C compilation process:
- Compiles C source with SDCC targeting Z80
- Generates Intel HEX file (.ihx)
- Converts HEX to binary with hex2bin
- Places binary in
obj/directory - Adds binary to DSK with correct load address
- Verifies memory limits (< 23999)
Loading from BASIC
Load and execute your C code from BASIC:The CALL address matches your
C_CODE_LOC setting.Project Structure
Example Project
See C Project Example for a complete working example with C and 8BP integration.Troubleshooting
Error: Memory limit exceeded
Error: Memory limit exceeded
Your compiled code is too large. Solutions:
- Use a lower
C_CODE_LOCvalue - Reduce BASIC MEMORY accordingly
- Optimize C code (remove unused functions)
- Compile with
-Wl-rflag for position-independent code
SDCC not found
SDCC not found
Install SDCC:
8BP functions not working
8BP functions not working
Ensure:
- 8BP library is loaded first in BASIC
- CALL &6B78 executed before loading C code
- Memory limits respected (< 23999)
Related
C Project Example
Complete C project with SDCC and 8BP
8BP Library
Learn about the 8BP game library