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 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:

  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.?