🧠 Design Philosophy
- Minimal C subset, suitable for an 8-bit Harvard-architecture CPU
- No dynamic memory, structs, or complex types
- No real call stack or recursion beyond what you implement via
CALL/RET
- Output = compiled DCPU-8 machine code or assembly
📜 Supported C Subset (JohnC v0.1)
Feature | Status | Notes |
---|---|---|
main() | ✅ | Program entry point |
void functions | ✅ | Only global, no recursion yet |
uint8_t types | ✅ | 8-bit integer only |
if / while | ✅ | Basic control flow |
`+ – & | ^` ops | ✅ |
return | ✅ | Via RET instruction |
mem[address] | ✅ | Direct memory access |
push(a) / pop(&a) | ✅ | For manual stack handling |
📘 Sample JohnC Code
cCopyEdit// Add two memory values and store the result
uint8_t add(uint8_t x, uint8_t y) {
return x + y;
}
void main() {
uint8_t a = mem[0x10];
uint8_t b = mem[0x11];
uint8_t c = add(a, b);
mem[0x12] = c;
halt();
}
🏗️ Compiler Strategy
You’ll create a C → DCPU-8 assembler in phases:
- Parser: Build a recursive descent parser or a lexer/parser pair (Flex+Bison, or hand-coded in Python)
- Intermediate Representation (IR): Create a flat representation of code flow
- Code Generator: Emit DCPU-8 assembly or direct machine code
- Linker/ROM Image Builder: Convert into EEPROM-loadable format
🎯 Output Example (From main()
above)
assemblyCopyEdit; load mem[0x10] to B
01 10 ; LOAD B, [0x10]
; load mem[0x11] to A
00 11 ; LOAD A, [0x11]
; A = A + B
40 ; ADD A, B
; store result to [0x12]
20 12 ; STORE A, [0x12]
; HALT
FF
🛠️ Tools You Can Use
Tool | Use |
---|---|
Python | Ideal for writing a mini compiler |
VS Code | Syntax highlighting + debug |
KiCad / Hardware | For memory mapping and stack layout |
EEPROM burner | To upload compiled code |
✅ Next Steps
Would you like to:
- Get a working Python-based JohnC → DCPU-8 assembler/compiler?
- Start with a predefined example (
add(a, b)
and generate full assembly)? - Define a standard memory map for variables, stack, function table, etc.?