C-like programming language for John’s DCPU-8 computer

🧠 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)

FeatureStatusNotes
main()Program entry point
void functionsOnly global, no recursion yet
uint8_t types8-bit integer only
if / whileBasic control flow
`+ – &^` ops
returnVia 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:

  1. Parser: Build a recursive descent parser or a lexer/parser pair (Flex+Bison, or hand-coded in Python)
  2. Intermediate Representation (IR): Create a flat representation of code flow
  3. Code Generator: Emit DCPU-8 assembly or direct machine code
  4. 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

ToolUse
PythonIdeal for writing a mini compiler
VS CodeSyntax highlighting + debug
KiCad / HardwareFor memory mapping and stack layout
EEPROM burnerTo upload compiled code

✅ Next Steps

Would you like to:

  1. Get a working Python-based JohnC → DCPU-8 assembler/compiler?
  2. Start with a predefined example (add(a, b) and generate full assembly)?
  3. Define a standard memory map for variables, stack, function table, etc.?