Project Structure
Configuration (devcpc.conf)
C Source Code (main.c)
8BP Wrapper Header (8BP.h)
Mini BASIC Header (minibasic.h)
BASIC Loader (loader.bas)
Loader Explanation
Line 20:MEMORY 23599
- Reserve memory for 8BP library (BUILD_LEVEL 0)
- C code loads at 20000, safely above this
8BP0.BINcontains the full libraryCALL &6B78initializes 8BP
MAIN.BINcompiled frommain.cby SDCC- Loads at address 20000 (C_CODE_LOC)
&56B0is the address of_main(check .map file)- Control passes to C code
Build Process
Compile Everything
Run in Emulator
Memory Layout
Critical: C Code Size Limit
- Optimize code: Remove unused functions
- Lower C_CODE_LOC:
- Use higher BUILD_LEVEL: Smaller 8BP library
SDCC Compilation Options
DevCPC uses these SDCC flags:--code-loc: Where to place code (C_CODE_LOC)--data-loc 0: Data at address 0--no-std-crt0: No standard C runtime (use custom)
Advanced: Custom CRT0
For full control, create a custom startup file:crt0.s (Custom Startup)
Mixing C and Assembly
Inline Assembly in C
Calling C from Assembly
Calling Assembly from C
Debugging C Code
Print Debug Values
Check Memory Usage
After build, check the .map file:Common Pitfalls
1. Memory Overlap
Problem: C code overwrites 8BP library Solution:2. Stack Collision
Problem: Stack grows down into code Solution: Initialize stack above screen:3. Wrong Call Address
Problem:CALL &56B0 doesn’t work
Solution: Check .map file for actual _main address:
Performance Tips
1. Use Fastcall Convention
2. Inline Critical Functions
3. Use Assembly for Speed
Next Steps
- Optimize Code: Profile and optimize critical sections
- Add Features: Enemies, collectibles, levels
- Better Graphics: Create more sprites
- Add Music: Integrate WYZ player
- Test on Hardware: Use M4 board or real CPC
Related
- 8BP Game Example - Full 8BP project
- ASM Project Example - Pure assembly
- Multi-File Projects - Organizing code