Dreamcast GameDev with KOS and Bash on Windows

Posted August 1, 2016 10:00 AM Categories: Dreamcast | GameDev | Gaming | Windows 10

Many years ago, an open-source Sega Dreamcast SDK known as KallistiOS (KOS) was started and is still being updated today.  I used this SDK awhile ago to create a few emulators that were published, and a variety of unfinished games that were not...

KOS is easy to get up and running on a variety of platforms, but on Windows this always required setting up Cygwin.  But, with the addition of the Linux Subsystem for Windows (LXSS) in Windows 10 Anniversary Update, one can now run Ubuntu and the Bash shell natively in Windows 10, and that means one can easily setup KOS, the SH4 toolchain and (almost) everything else required to develop and deploy apps to a Sega Dreamcast.  Here's how…

Requirements

  • A Sega Dreamcast capable of booting MIL-CDs...this is any machine manufactured prior to October 2000.
  • A Dreamcast Broadband Adapter (HIT-0300 or HIT-0400 both work)
  • The Dreamcast plugged into your network via Ethernet
  • The Linux Subsystem for Windows installed and configured

Updating LXSS

Make sure you upgrade the subsystem by issuing these two commands:

sudo apt-get update
sudo apt-get upgrade

Downloading and Building the Toolchain and KOS

Once completed, you will need to install a few packages required to retrieve and build the SDK and tools:

sudo apt-get -y install git make gcc texinfo libjpeg-dev libpng-dev subversion genromfs libelf-dev

Now that the appropriate packages are installed, make sure you're in your home directory and then download the KOS repos:

git clone git://git.code.sf.net/p/cadcdev/kallistios kos
git clone git://git.code.sf.net/p/cadcdev/kos-ports

Next, you need to download and unpack the toolchain bits used to build the Dreamcast toolchain:

cd ~/kos/utils/dc-chain/
./download.sh
./unpack.sh

That unpacking process will not display any output and may take a long time, so don't cancel!

With the packages unpacked, you can now build the toolchain.  This process builds a compatible compiler (gcc) and other tools for the Dreamcast's SH4 CPU.  While in the same directory as above, run:

sudo make

This will take a while, so be patient...

With that complete, you now need to setup your Bash environment so the SDK and tools can be found and used.  First, copy the following file and change its permissions:

cp ~/kos/doc/environ.sh.sample ~/kos/environ.sh
chmod 777 ~/kos/environ.sh

Next, edit the environ.sh file we just copied to point it at the tool location.  To do this, I use use nano, but any other text editor is fine:

nano ~/kos/environ.sh

Look for the entry exporting KOS_BASE and set it to the following:

/home/YOUR_USERNAME/kos

Obviously, replace YOUR_USERNAME with your username.  Mine looks like this:

export KOS_BASE="/home/brian/kos"

Next, look for the entry exporting KOS_LOADER and add the following prior to the -x argument:

-t IP_ADDRESS

...where IP_ADDRESS is a valid, unused IP address on your network.  Mine looks like this:

export KOS_LOADER="dc-tool -t 192.168.2.250 -x"

A note on the IP address:  You cannot choose any IP in the world...it must be valid in your own subnet (probably 192.168.X.X or 10.X.X.X or similar), and it must not be used by any other device on your network.  Check your router for valid choices and more information.

Finally, edit the .bashrc file in your home directory:

nano ~/.bashrc

...and at the very bottom, add this line so the environ.sh file you just edited gets run at login:

. ~/kos/environ.sh

Don't forget the period as the first character!

Now, exit and restart Bash on Windows.  To make sure the environment is setup, use the printenv command and you should see a variety of environment variables listed starting with KOS_ listed.

Next, KOS itself needs to be built.  To do this, change into the kos directory and run the make command:

cd ~/kos
make

Once completed, build the kos-ports project:

cd ~/kos-ports/utils/
./build-all.sh

And finally, build the KOS example projects:

cd ~/kos/examples
make

A few of these examples may not build but don't worry about that for now.

Downloading and Building dcload-ip

Next up, you will need to download and build the dcload-ip tool.  This is what will allow you to deploy a game to a retail Dreamcast over the Broadband Adapter (BBA).  Change back to your home directory, run the following:

cd ~
git clone git://git.code.sf.net/p/cadcdev/dcload-ip
cd dcload-ip
sudo make install

You may see an error about /usr/local/bin existing on the final step, which is safe to ignore.

Now, you will need to burn the host dcload program to a CD so we can run it on the physical Dreamcast machine and upload our binary.  But, here we have to cheat.  Because the Linux Subsystem for Windows doesn't yet have hardware support, it can't talk to a CD-R drive.  But, I have put together a quick package that contains the required tools and the cygwin libraries to run them.  You can download that package here:

dcload-disc.zip (1.42 mb)

Unzip this somewhere on your machine, then open an admin Windows command prompt (not Bash) and navigate to the files.  Then, run the following:

wodim -scanbus

This will return some information about every drive it finds.  In the output, look for your recordable drive in the list and make a note of the 3 comma-delimited digits that identify the bus and location of the drive.  Mine looks like this:

scsibus0:
        0,0,0     0) 'HL-DT-ST' 'BD-RE  WH16NS40 ' '1.02' Removable CD-ROM
        0,1,0     1) *
        0,2,0     2) *
        0,3,0     3) *
        0,4,0     4) *
        0,5,0     5) *
        0,6,0     6) *
        0,7,0     7) HOST ADAPTOR

So, the 3 digits for me are "0,0,0".  For these next steps, replace the X,X,X with your values.

Insert a blank CD-R into your drive and burn the first part of the disc, the audio track, as follows:

wodim dev=X,X,X -multi -audio -tao audio.raw

Now, burn the data track:

wodim dev=X,X,X -xa -tao -multi data.raw

With those two items burned, you now be able to eject the CD, pop it in your Dreamcast, and it will run.

Running a Sample

With dcload-ip running on your Dreamcast, you should see a MAC address displayed.

WP_20160731_01_40_04_Pro

We need to tell our Windows machine how to find that device by an IP address.  If you recall, earlier you selected an IP for your Dreamcast.  You will need that here.

Open an admin command prompt (not Bash, but standard command prompt) and run the arp command as follows:

arp -s IP_ADDRESS MAC_ADDRESS

Replace IP_ADDRESS with the one selected above, and MAC_ADDRESS with the one seen on screen, but use hyphens instead of colons.  Here's an example:

arp -s 192.168.2.250 00-d0-f1-02-3f-07

This command must be run after every reboot...it will not be saved by Windows.

You may need to exit and restart the Bash on Windows after running this command so it will know about the change.

Now, you can run the 2ndmix (or any other) sample:

cd ~/kos/examples/dreamcast/2ndmix
make run

If all goes to plan, this should build, deploy, and execute the 2ndmix demo on your Dreamcast!

WP_20160731_01_40_30_Pro

Next Steps

Now that you have a configured and working toolchain and SDK, you can start building your own Dreamcast games.  Take a look at all of the examples in the kos directory to learn more about the API.  Additionally, here are a few links with more information:

Game Developers: Get the Most Out of Windows 10

Posted May 13, 2015 9:53 PM Categories: Events | Gaming | Build 2015

I had the opportunity to co-present a session at Build 2015 focusing on building games for Windows 10Jaime Rodriguez and I spent an hour talking about the new Windows 10 features related to gaming, including Xbox Live, ID@Xbox, the new GamePad API, windowing, and the various middlewares and engines like MonoGame and Marmalade that are supporting Windows 10 at present.  If you care about games and are excited about Windows 10, have a look!

Visual Studio Live! - Las Vegas

Posted January 27, 2015 2:31 PM Categories: VSLive Vegas | Events | Gaming | Windows 8.1 | Windows Phone

It’s that time again…another Visual Studio Live!  I will be presenting 2 sessions at Visual Studio Live! in Las Vegas this March 16-20.  The conference is a full 5 day event and there’s still time to register.  For this event, I’ll be presenting:

W23 Building Games for Windows and Windows Phone Using Unity and Other Frameworks
Date: Wednesday, March 18, 2015
Time: 3:00pm – 4:15pm
Level: Introductory

There are a variety of platforms and frameworks which can be used to build games on both Windows and Windows Phone depending on the complexity of the game and the developer's skill level. In this session, we will delve into the many options available to developers, including DirectX, Unity, MonoGame, and more!

VSH10 Building Your First Universal Application for Windows Phone and Windows Store
Date: Wednesday, March 18, 2015
Time: 1:30pm - 2:45pm
Level: Introductory

Universal Apps enable developers to build apps for Windows Store and Windows Phone simultaneously while sharing code, controls, and other assets between them. In this session, you will learn how Universal Apps work as we build a simple app from start to finish using this new project type. We will cover what can and can't be shared, and how to best structure your project for maximum re-use.

LVSPK25Get more information on the conference at:

Visual Studio Live! - Orlando

Posted October 13, 2014 11:13 PM Categories: Gaming | VSLive Orlando | Windows 8.1 | Windows Phone | Async | Events

I will be presenting 3 sessions at Visual Studio Live! in Orlando this November 17-21.  The conference is a full 5 day event, and part of the Live! 360 conference, covering SharePoint, SQL Server, Modern Apps and more.  Plus, there’s still time to register and save $600 if you register before 10/15/14!  For this event, I’ll be presenting:

VSH03 Games Development with Unity and Other Frameworks for Windows and Windows Phone
Date: Thursday, November 20, 2014
Time: 8:00am – 9:15pm
Level: Introductory

There are a variety of platforms and frameworks which can be used to build games on both Windows and Windows Phone depending on the complexity of the game and the developer's skill level. In this session, we will delve into the many options available to developers, including DirectX, Unity, MonoGame, and more!

VSH08 Writing Asynchronous Code using .NET 4.5 and C# 5.0
Date: Thursday, November 20, 2014
Time: 9:30am – 10:45pm
Level: Introductory

A variety of new features were added to the .NET 4.5 Framework, including support for easily writing asynchronous code. This session will introduce the concepts of asynchronous programming, .NET Tasks, how to ensure your UI remains responsive, and how to do all of this properly in your own applications using the new "async"and "await" keywords. If you're looking for ways to provide a better, smoother experience for your users, don't miss this session!

VSH10 Building Your First Universal Application for Windows Phone and Windows Store
Date: Thursday, November 20, 2014
Time: 11:00am – 12:15pm
Level: Introductory

Universal Apps enable developers to build apps for Windows Store and Windows Phone simultaneously while sharing code, controls, and other assets between them. In this session, you will learn how Universal Apps work as we build a simple app from start to finish using this new project type. We will cover what can and can't be shared, and how to best structure your project for maximum re-use.

LSPK61

Get more information on the conference at:

Visual Studio Live! – Washington DC

Posted September 8, 2014 1:43 PM Categories: Gaming | VSLive | Events | Windows Phone | Windows Runtime

I will be presenting 2 sessions at Visual Studio Live! in Washington DC this October 6-9.  The conference is a full 4 day event and there’s still time to register and save $400 if you register before 9/10/14!  For this event, I’ll be presenting:

TH07 Building Your First Windows Phone 8.1 Application
Date: Thursday, October 9, 2014
Time: 9:30am – 10:45pm
Level: Introductory

Expand your mobile horizons with Windows Phone! Developing applications for the phone is quite similar to building XAML applications for other platforms. In this session, Brian will demonstrate the fundamentals of Windows Phone development while building a very simple application which covers all of the important points of the new platform's architecture, including the developer tools, device emulator and touch input. We will also discuss what's new with the Windows Phone 8.1 update and how you can use it to build better apps.

TH11 Building Games for Windows and Windows Phone
Date: Thursday, October 9, 2014
Time: 11:00am – 12:15pm
Level: Introductory

There are a variety of platforms and frameworks which can be used to build games on both Windows and Windows Phone depending on the complexity of the game and the developer's skill level. In this session, we will delve into the many options available to developers, including DirectX, Unity, MonoGame, and more!

DCSPK22

Get more information on the conference at:

My Info

  • View Brian Peek's profile on LinkedIn

Sponsored Ad

My Book

Sponsored Ad