Cart

Your cart is empty

Browse documentation/Write Programs

How to Write and Build Programs

This guide explains how to write, compile, and build programs for rosco_m68k in a bare-metal environment.

This page assumes that you already have a working toolchain installed. A separate guide covers toolchain installation and setup.


Prerequisites

Before you start, make sure you have:

  • rosco-cli with Docker, or a local m68k toolchain — see Toolchain Setup
  • A board and UART adapter for hardware uploads, or an emulator for testing without hardware
  • A FAT32 SD card only if you choose SD boot

Execution Environment

Programs for rosco_m68k run in a bare-metal environment. This means:

  • No operating system by default
  • Direct access to hardware
  • Program execution starts at kmain

It is possible to run an operating system (for example, one targeting Motorola 68010), but this guide focuses only on bare-metal development.


Supported Languages

rosco_m68k supports development in:

  • Assembly (vasm)
  • C

For C programs, the project provides an adapted standard library suitable for bare-metal environments.

Examples:

  • printf() outputs text to the serial (UART) console
  • No host OS is required

For Assembly, there is also an adapted library with similar functions.


Quick Start with rosco-cli

Install the CLI and Docker using Toolchain Setup, then create a C program:

rosco init hello --board rosco_m68k --language c --docker --target emulator --emulator-docker --yes
cd hello
rosco build
rosco run --emulator

For Assembly, use --language asm and a different project name. The first build prepares the bundled libraries automatically; edit kmain.c or kmain.asm and run rosco build again. Project settings are saved in rosco.toml.

To run on your board instead, first select the firmware's Kermit loader (LOAD where available), then run:

rosco ports
rosco run --hardware --port /dev/ttyUSB0 --baud 38400

On Windows, replace the port with e.g. COM3. Use 38400 baud for this kit. See Running Programs for saved settings, serial uploads, SD boot, and emulator options.

Manual Workflow with the ZIP Template

The following sections describe the downloadable template and manual Makefile workflow. They are an alternative to the CLI; a CLI build already prepares its own libraries.

Download the starter template for the manual workflow:

Download starter template: rosco_start.zip

This archive contains:

rosco_start/
├── starter_c/          # C project template
│   ├── kmain.c         # Example C program
│   ├── Makefile
│   └── libs/           # Standard libraries (need to be built)
│
└── starter_asm/        # Assembly project template
    ├── kmain.asm       # Example Assembly program
    ├── Makefile
    └── libs/           # Standard libraries (need to be built)

Getting Started Steps:

  1. Download and extract the archive
  2. Build the standard libraries first:
   cd rosco_start/starter_c/libs/    # or starter_asm/libs/
   make install
   cd ..
  1. Choose your language:
    • For C: navigate to starter_c/
    • For Assembly: navigate to starter_asm/
  2. Build your program:
   make clean all
  1. Deploy to SD card:
    • Copy the generated .bin file to your FAT32-formatted SD card
    • Rename it to ROSCODE1.bin
    • Insert the SD card into your ROSCO M68K
    • Power on and connect via UART to see the output

Important: You must compile the standard libraries with make install before building your first program. Repeat this step after changing the libraries or toolchain.


Project Structure

The ZIP template’s C and Assembly skeletons follow the same minimal structure:

project/
├── kmain.c          # or kmain.asm (your main program)
├── Makefile         # Build configuration
└── libs/            # rosco_m68k standard libraries

Key Files:

  • kmain.c / kmain.asm — Your program's entry point. Execution starts here.
  • Makefile — Defines how to compile and link your program.
  • libs/ — Contains the standard libraries for bare-metal development (must be compiled first).

Compiling the Standard Libraries

For the manual ZIP workflow, compile the standard libraries before your first program. With rosco-cli, rosco build does this automatically.

Navigate to the libs/ directory and run:

cd libs/
make install
cd ..

This will build all necessary library files that your programs will link against. Repeat this when the libraries or toolchain change; otherwise, you only need to do this once after downloading the starter template.


Writing Your Program

C Development

When writing C programs:

  • Use #include <stdio.h> for functions like printf()
  • The printf() function outputs to UART (serial console)
  • Your program starts at the kmain() function
  • Returning from kmain() will reboot the machine

Example structure:

#include <stdio.h>

void kmain() {
    // Your code here
    printf("Hello from ROSCO!\r\n");

    // Returning will cause a reboot
}

Assembly Development

When writing Assembly programs:

  • Use the machine library functions like mcPrintln
  • Always clean up the stack after function calls
  • Entry point is the kmain:: label
  • Returning from kmain will reboot the machine

Example structure:

    section .text

kmain::
    ; Your code here
    lea.l   MESSAGE,A0
    move.l  A0,-(A7)
    jsr     mcPrintln
    addq.l  #4,A7
    rts

MESSAGE:
    dc.b    "Hello from ROSCO!", 0

Building Your Program

From your project directory (either starter_c/ or starter_asm/), run:

make clean all

This will:

  1. Clean previous build artifacts
  2. Compile your program
  3. Link it with the standard libraries
  4. Generate the executable (.bin file)

Deploying to ROSCO M68K

After building your program, you need to copy it to an SD card:

  1. Format your SD card as FAT32 (if not already formatted)
  2. Copy the generated .bin file to the SD card
  3. Rename it to ROSCODE1.bin — this is the filename the bootloader looks for
  4. Insert the SD card into your ROSCO M68K
  5. Connect via UART to see the output (38400 baud)
  6. Power on the board

Successful Boot Example

When everything works correctly, you should see output similar to this via UART:


Makefile Overview

The template's Makefile selects the libraries and build rules. Keep the Makefile bundled with your template: its paths and compiler prefix must agree with that template's library layout.

Current upstream build rules include $(ROSCO_M68K_DIR)/code/software/software.mk, where ROSCO_M68K_DIR is the root of a complete upstream checkout. A directory containing only libs/ is not that root. The current rules use m68k-elf-rosco-gcc; older archives may expect m68k-elf-gcc.

Use EXTRA_CFLAGS and EXTRA_LIBS for project-specific compiler flags and libraries. For CLI projects, keep the generated Makefile and use rosco.toml to configure the build backend.


Notes and Common Pitfalls

  • Manual builds need compiled libraries — run make install in the template’s libs/ directory; rosco build handles this for CLI projects
  • Use FAT32 for the SD workflow in this guide — it is the recommended, more thoroughly tested FAT format; exFAT is not supported by this workflow
  • Use ROSCODE1.bin for direct binary SD boot — programs launched through SD FAT Menu keep their own names; firmware 2.4 also added ELF boot support (see Running Programs)
  • Returning from kmain reboots the machine — if you want your program to keep running, use an infinite loop instead
  • In Assembly, always clean up the stack after function calls (e.g., addq.l #4,A7)
  • Make sure libraries are in libs/ — the starter template includes them
  • An incorrect ROSCO_M68K_DIR path will cause build errors

Advanced: Building Libraries from Source

If you need to rebuild the standard libraries or want to get the latest version:

Library sources: Available on GitHub.

Use a complete upstream checkout matching your firmware, rather than replacing only a ZIP template’s libraries. From the checkout root, run:

cd code/software/libs
make clean install

Then rebuild your program against those same headers and libraries. See the upstream build guide.