Skip to content

avwohl/ucow

Repository files navigation

ucow

A Python-based Cowgol compiler targeting Z80 CP/M.

Usage

Single File Compilation

# Compile a Cowgol source file to Z80 assembly
python3 -m src.main source.cow -o output.mac

# Assemble with um80
um80 output.mac

# Link with ul80
ul80 output.rel -o output.com

Multi-File Compilation

Compile multiple Cowgol source files together in a single compiler run:

# Compile all modules together into one assembly file
python3 -m src.main main.cow utils.cow math.cow -o program.mac

# Assemble and link
um80 program.mac
ul80 program.rel -o program.com

This approach enables workspace optimization: the compiler analyzes the call graph across all modules to determine which subroutines can never be active simultaneously. Subroutines that don't overlap in the call tree share local variable storage, significantly reducing data segment size.

For example, if sub_a and sub_b each use 100 bytes of locals but never call each other, they share the same 100 bytes instead of using 200 bytes total.

Use --graph-debug to see the call graph analysis:

python3 -m src.main --graph-debug main.cow lib.cow -o output.mac

Include Paths

Use -I to add directories to the include search path:

python3 -m src.main -I ./lib -I ./include source.cow -o output.mac

Compiler Options

Option Description
-o OUTPUT Output assembly file name
-I PATH Add include search path
-O0 Disable optimization
--no-post-opt Disable post-assembly optimization
--graph-debug Show call graph analysis
--tokens Dump tokens and exit
--ast Dump AST and exit

Requirements

  • Python 3
  • um80 (Z80 assembler)
  • ul80 (linker)
  • cpmemu (for testing)

Related Projects

  • 80un - Unpacker for CP/M compression and archive formats (LBR, ARC, squeeze, crunch, CrLZH)
  • cpmdroid - Z80/CP/M emulator for Android with RomWBW HBIOS compatibility and VT100 terminal
  • cpmemu - CP/M 2.2 emulator with Z80/8080 CPU emulation and BDOS/BIOS translation to Unix filesystem
  • ioscpm - Z80/CP/M emulator for iOS and macOS with RomWBW HBIOS compatibility
  • learn-ada-z80 - Ada programming examples for the uada80 compiler targeting Z80/CP/M
  • mbasic - Modern MBASIC 5.21 Interpreter & Compilers
  • mbasic2025 - MBASIC 5.21 source code reconstruction - byte-for-byte match with original binary
  • mbasicc - C++ implementation of MBASIC 5.21
  • mbasicc_web - WebAssembly MBASIC 5.21
  • mpm2 - MP/M II multi-user CP/M emulator with SSH terminal access and SFTP file transfer
  • romwbw_emu - Hardware-level Z80 emulator for RomWBW with 512KB ROM + 512KB RAM banking and HBIOS support
  • scelbal - SCELBAL BASIC interpreter - 8008 to 8080 translation
  • uada80 - Ada compiler targeting Z80 processor and CP/M 2.2 operating system
  • um80_and_friends - Microsoft MACRO-80 compatible toolchain for Linux: assembler, linker, librarian, disassembler
  • upeepz80 - Universal peephole optimizer for Z80 compilers
  • uplm80 - PL/M-80 compiler targeting Intel 8080 and Zilog Z80 assembly language
  • z80cpmw - Z80 CP/M emulator for Windows (RomWBW)

About

unix (linux) cowgol to z80 compiler

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors