Getting Started with Dreamcast development
This article is incomplete -- actively being worked on!
BEWARE: THIS ARTICLE IS CURRENTLY A WIP
This article will cover the entire beginning process: starting from zero to having a working dev environment with debug link and self-booting CD-R.
- Steps required for Windows 10/WSL, macOS/Intel, macOS/Apple Silicon, Debian/Ubuntu Linux, and Fedora Linux
- Steps should be pretty similar for the *nix OSs besides package managers and dependencies
- Setting up KOS and compiling an example program
- Executing the sample program using a debug link
- Include up-to-date ready made CDIs for dcload-serial and dcload-ip
- Burning a project to CD and preparing for distribution
Introduction
This article will cover the entire beginning process: starting from zero to having a working dev environment with debug link (serial or IP) and self-booting CD-R. This guide will cover the process for the following platforms:
- Microsoft Windows 10 via Windows Subsystem for Linux
- macOS on Intel or Apple Silicon systems with the Homebrew package manager installed
- Debian- and Ubuntu-based Linux distributions using the default apt package manager
- Fedora-based Linux distributions using the default dnf package manager
- Arch-based Linux distributions using the default pacman package manager
Need help?
Important note: This guide aims to remain up to date and work on all of the above platforms, but keeping instructions for such a variety of platforms up-to-date can be difficult. If you run into any errors or other challenges while following this tutorial, or simply need clarification on any of the steps, feel free to ask for assistance on the message board and we would be happy to aid you and update the guide for the benefit of future readers and others in the community.
Terms
Before we get started, let's define several terms:
The toolchain is a set of programs which turns your code into an executable file for your Dreamcast console. The toolchain includes:
- GCC, a C/C++/Objective-C compiler
- binutils, an assembler and linker
- newlib, a C library
- gdb, a debugger
The toolchain includes compilers for both the Dreamcast's main SH4 CPU as well as the ARM-based AICA sound processor. Your operating system may already have versions of these programs installed to compile code for your computer, but we will need to build a "cross-compiler" for compiling specifically for the Dreamcast.
KallistiOS or KOS is an open source development library and pseudo-operating system for the Dreamcast console. It is the best documented and most widely used development kit in the homebrew community. KallistiOS's very flexible license allows both homebrew and commercial use with no restrictions other than a requirement to include credit for its use in your project, and indeed almost all commercially sold indie Dreamcast titles use it. There are others in existence, like libronin and libdream, as well as the older development kits Katana and Windows CE created by Sega and Microsoft for use in retail games, but this guide will only cover the setup and use of KallistiOS.
kos-ports is a repository including various libraries which integrate with KallistiOS. We will download and compile these libraries as well.
The debug link is a generic term referring to a hardware accessory to facilitate quickly running and debugging your programs. IP-based links include the Dreamcast's Broadband adapter and LAN adapter accessories, and serial-based links include the Coder's cable, which is a cable that can connect the Dreamcast's serial port to your computer via USB or serial. This guide includes instructions for setting up and using the the Broadband adapter and a USB-based coder's cable.
dc-tool and dcload are a pair of programs to facilitate using a debug link. dc-tool runs on your computer and links to a Dreamcast running dcload-ip or dcload-serial. With this setup, you can quickly load programs, read console feedback, load assets, transfer data, redirect I/O, handle exceptions, debug problems, and so forth.
Choosing a debug link solution
If you are building the toolchain for the purpose of building existing programs from source with little to no modifications, then a debug link setup might not be necessary for you. You may simply build programs to burn directly to CD-R. However, if you are planning to actively develop for the Dreamcast, then a debug link is a critical component. While Dreamcast emulators are mature and accurate enough to play the vast majority of the system's games library without issue, many critical bugs may show up on a real Dreamcast system, but not on a Dreamcast emulator. Therefore, it is highly recommended to test on a real system as much as possible. It's also possible to load software off of a Serial SD card adapter, but without an active link to a computer, debugging and stepping through programs as they execute is significantly more challenging.
Presented below is a table comparing the different options available for a debug link. Due to the cost, potential buyers may want to factor in the ability to play multiplayer games with their purchase. Thus, for comparison, we have included information about the Modem with DreamPi as well, but understand that the Modem with DreamPi cannot be used as a debug link.
Comparison of various Dreamcast connectivity options | |||||
---|---|---|---|---|---|
Device: | Broadband adapter (HIT-400 or HIT-401) Realtek RTL8139C chipset |
LAN adapter (HIT-300) Fujitsu MB86967 chipset |
Modem with DreamPi | USB Coder's cable | Serial Coder's cable |
Useful for dev? | Yes, supports dcload-ip | Yes, supports dcload-ip, but BBA is superior and cheaper |
No, only useful for online multiplayer gaming | Yes, supports dcload-serial | Yes, supports dcload-serial |
Cost | $100 - $200 and up on used markets | $200 and up on used markets, due to extreme rarity |
Kit prices vary, around $100 | Varies on used markets, uncommonly sold RetroOnyx sells for $85 |
Varies on used markets, uncommonly sold |
Can make DIY? | No | No | Yes | Yes | Yes |
Performance | Up to 100 megabits/s | Up to 10 megabits/s | Up to 56 kilobits/s | Up to 1500 kilobits/s | Up to 120 kilobits/s |
Games support | Some games: Phantasy Star Online, Quake III Arena, Toy Racer, POD SpeedZone, Propellor Arena, Unreal Tournament Some browsers: Broadband Passport, PlanetWeb 3.0 |
No games One browser: Dream Passport for LAN |
All multiplayer games with network support All web browsers |
NO multiplayer games support | NO multiplayer games support |
Homebrew support | Homebrew utilities like dcload-ip | Homebrew utilities like dcload-ip | Homebrew utilities don't support, only multiplayer games | Homebrew utilities like dcload-serial | Homebrew utilities like dcload-serial |
Setting up and compiling the toolchain with the dc-chain script
Dependencies
First, we'll need to install dependencies before building the toolchain. Below we have provided commands to install these dependencies on various systems. Many of the packages will likely already be installed on your system, but we have provided an exhaustive list for good measure.
macOS Ventura on an Intel or Apple Silicon processor
First, make sure you install Apple Xcode, including the Command Line tools. You will also need to install several other packages for which we'll include instructions assuming you have installed the Homebrew package manager on your system.
brew install wget gettext texinfo gmp mpfr libmpc libelf jpeg libpng
Debian/Ubuntu-based Linux
sudo apt install gawk patch bzip2 tar make libgmp-dev libmpfr-dev libmpc-dev gettext wget libelf-dev texinfo bison flex sed git build-essential diffutils curl libjpeg-dev libpng-dev python3
Fedora-based Linux
sudo dnf install gawk patch bzip2 tar make gmp-devel mpfr-devel libmpc-devel gettext wget elfutils-libelf-devel texinfo bison flex sed git diffutils curl libjpeg-turbo-devel libpng-devel gcc-c++ python3
Arch-based Linux
sudo pacman -S --needed gawk patch bzip2 tar make gmp mpfr libmpc gettext wget libelf texinfo bison flex sed git diffutils curl libjpeg-turbo libpng python3
Other Linux distributions
If you're using a different Linux- or Unix-based system besides the one above, you may need to reference your distribution's package database and package manager documentation for the equivalent package names and commands necessary for your system.
Creating a space for your toolchain installation
Create the path where we'll install the toolchain and KOS, and grant it the proper permissions:
sudo mkdir -p /opt/toolchains/dc sudo chmod -R 755 /opt/toolchains/dc sudo chown -R $(id -u):$(id -g) /opt/toolchains/dc
Cloning the KOS git repository
Clone the KOS git repository to your system:
git clone git://git.code.sf.net/p/cadcdev/kallistios /opt/toolchains/dc/kos
Configuring the dc-chain script
Enter the dc-chain directory:
cd /opt/toolchains/dc/kos/utils/dc-chain
You'll need to choose one of the following pre-made toolchain configurations. The testing version uses GCC 9.3.0 and Newlib 3.3.0, whereas the stable version uses GCC 4.7.4 and Newlib 2.2.0. We suggest trying to use the testing version unless you run into an issue. Run one of the following two commands to make your choice:
mv config.mk.stable.sample config.mk mv config.mk.testing.sample config.mk
Now, configure config.mk options to your liking by using a text editor. It is highly recommended to set makeopts=-j1, as on some operating systems the toolchain may fail to build with a higher setting.
Finally, compiling the toolchain
Run the download and unpack scripts:
./download.sh ./unpack.sh
macOS Apple Silicon Toolchain Patches
If you are on macOS on Apple Silicon, there are several patches that must be applied in order for the toolchain to build correctly. These patches most be applied to both the GCC 9 (SH4) and GCC 8 (AICA) directories.
In gcc/config.host, find the following two lines and comment them out by adding a # character to the beginning.
out_host_hook_obj=host-darwin.o host_xmake_file="${host_xmake_file} x-darwin"
will become
#out_host_hook_obj=host-darwin.o #host_xmake_file="${host_xmake_file} x-darwin"
and in gcc/gcc/config/host-darwin.c, below the existing #include declarations, add:
#include "hosthooks.h" #include "hosthooks-def.h" const struct host_hooks host_hooks = HOST_HOOKS_INITIALIZER;
Starting the compilation
Compile the toolchain:
make
Toolchain is now built.
Configuring and compiling KOS and kos-ports
Setting up the environment settings
Enter the KOS directory:
cd /opt/toolchains/dc/kos
Copy the pre-made environment script into place:
cp doc/environ.sh.sample environ.sh
For most users, the default settings will suffice. However, advanced users may the environ.sh to your liking if you'd like to change compile flags or alter paths. If you'd like to have multiple KOS versions installed or multiple toolchain versions installed, you can set up different environ.sh files corresponding to these different configurations by altering the paths. Run the source command on the desired environ.sh file to select that configuration prior to compiling your project.
You will need to run the source command to apply the KOS environment settings to your currently running shell. Run the following now, and whenever you open a new shell to work on Dreamcast projects:
source /opt/toolchains/dc/kos/environ.sh
macOS AS Patches
The Makefiles for the following utils need to be modified to properly build on macOS using Homebrew's installed libs.
In utils/dcbumpgen/Makefile, after the existing CFLAGS and LDFLAGS lines, add:
CFLAGS += -I/opt/homebrew/opt/jpeg/include -I/opt/homebrew/opt/libpng/include LDFLAGS += -L/opt/homebrew/opt/jpeg/lib -L/opt/homebrew/opt/libpng/lib
In utils/kmgenc/Makefile, after the existing CFLAGS and LDFLAGS lines, add:
CFLAGS += -I/opt/homebrew/opt/jpeg/include -I/opt/homebrew/opt/libpng/include LDFLAGS += -L/opt/homebrew/opt/jpeg/lib -L/opt/homebrew/opt/libpng/lib
In utils/makeip/src/Makefile, after the existing CFLAGS and LDFLAGS lines, add:
CFLAGS += -I/opt/homebrew/opt/libpng/include LDFLAGS += -L/opt/homebrew/opt/libpng/lib
macOS Intel Patches
In utils/dcbumpgen/Makefile, after the existing CFLAGS and LDFLAGS lines, add:
CFLAGS += -I/usr/local/opt/jpeg/include -I/usr/local/opt/libpng/include LDFLAGS += -L/usr/local/opt/jpeg/lib -L/usr/local/opt/libpng/lib
In utils/kmgenc/Makefile, after the existing CFLAGS and LDFLAGS lines, add:
CFLAGS += -I/usr/local/opt/jpeg/include -I/usr/local/opt/libpng/include LDFLAGS += -L/usr/local/opt/jpeg/lib -L/usr/local/opt/libpng/lib
In utils/makeip/src/Makefile, after the existing CFLAGS and LDFLAGS lines, add:
CFLAGS += -I/usr/local/opt/libpng/include LDFLAGS += -L/usr/local/opt/libpng/lib
In utils/vqenc/Makefile, add:
CFLAGS += -I/usr/local/opt/jpeg/include LDFLAGS += -L/usr/local/opt/jpeg/lib
Building KOS
Build KOS:
make
KOS is now built.
Building kos-ports
Clone the kos-ports repository to your system:
git clone --recursive git://git.code.sf.net/p/cadcdev/kos-ports /opt/toolchains/dc/kos-ports
Run the script to build all of the included ports:
/opt/toolchains/dc/kos-ports/utils/build-all.sh
kos-ports is now built.
Building the KOS examples
Enter the KOS examples directory:
cd /opt/toolchains/dc/kos/examples/dreamcast
Build the examples:
make
All of the example programs provided with KallistiOS are now built.
Compiling and running an example program
Give a tutorial on writing and compiling very basic helloworld-style C program, configuring serial or IP link, and running the example
Burning your project to CD and distributing
Explain how to compile a CD project using mkdcdisc or similar tools, and how to package it for distribution.
Further reading
Links to articles for using gdb, integrating the dev setup with an IDE, etc.