
Awhile ago I talked about how to build the Dreamcast development tools on Windows which allowed you to compile Dreamcast code. Today, I'll be going over how to execute that code on the Dreamcast itself.
Prerequisites
First, start up the Cygwin.exe setup installer. Run through it until you get to “Select Packages” and search for “cdrecord” and “mkisofs”. Select them both and continue with the installer.
Next up, we'll need a tool called “scramble.” We'll need to build it from source. Thanks to this tutorial on dotdotcomorg.net for pointing out where this was.
$ cd ~/Tools/dreamcast/
$ mkdir scramble
$ cd scramble/
$ wget http://mc.pp.se/dc/files/scramble.c
$ gcc scramble.c -o scramble
$ mv scramble.exe /usr/local/bin/
Check that you have “cdrecord”, “mkisofs”, and “scramble” available on the command line.
Building Dc-Tool / DcLoad-IP
Next, we're going to build the tools that allow the PC and Dreamcast to communicate over the oh-so-expensive BBA.
The PC tool is called “dc-tool”, while the actual CD we create that runs on the Dreamcast is “dcload-ip.” Because places to find binaries of this stuff is becoming rare, we'll build from source.
Start a Cygwin prompt, and source your kos script (I called mine dcdev_environ.sh). After that, follow these steps:
$ cd ~/Tools/dreamcast
$ git clone git://cadcdev.git.sourceforge.net/gitroot/cadcdev/dcload-ip
$ cd dcload-ip
Now open up the file Makefile.cfg.
Remove the comments in front of “HOSTCFLAGS= -O2 -D_WIN32” and “EXECUTABLEEXTENSION” since we'll be compiling on Windows.
After the line “# sh-elf-stuff”, add “TARGETCCVER = 4”.
Now, execute “make” and dcload-ip should build.
Next, we need to burn the CD that the Dreamcast will play. This entails actually burning a CD and is the worst part of the process, since throwing away a screwed-up CDR each time something goes wrong is no fun. But alas, there is no other way.
Before we proceed, I want to point out some things. First, the program we're supposed to use is called “cdrecord”, but in Cygwin “cdrecord” is just a symlink to “wodim”, the man pages for which you can read here. Certain commands are different in wodim than cdrecord- in particular, I had to use the xa flag instead of xa1 to burn anything useful.
If you want to know exactly what goes into burning a Dreamcast CD, Marcus Comstedt's site on Dreamcast programming has a great write-up on the topic.
The dcload-ip source directory has a sub directory called make-cd with a makefile in it. This uses the programs cdrecord, mkisofs and scramble that we downloaded earlier.
First, open up the makefile in the makecd directory and look where the variable “CDRECORD” is defined. It'll have an argument “dev=0,0,0” which tells cdrecord which device on your system to use. You probably don't want that to be pointing to your main hard drive (although I think nothing bad happens; feel free to research that if you must!). To figure out the correct arguments, run “cdrecord -scanbus” from the Cygwin prompt. You want to select the three numbers which are before the name of your CD drive. For me, I get this:
$ cdrecord -scanbus
scsibus0:
0,0,0 0) 'ASUS ' 'DRW-24B3ST c ' '1.01' 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
This says 0,0,0 (the default) is correct on my system. If your numbers vary, update the makefile where it says “wodim dev= 0,0,0”.
Next, if you're on Windows like I said earlier you're actually using wodim, not cdrecord, so look for the flag “-xa1” and change it to “-xa” (update: looks like the makefile was updated to do this recently). xa1 in wodim expect 2056 bytes per sector, not 2048. See Marcus Comstedt's write-up and the wodim docs for more info.
Another note about drive speed. Burning Dreamcast discs at high speeds makes it harder from the Dreamcast to read the resulting CD and wear down the motor. Because of this, the “speed” argument to cdrecord in the makefile should be taken down to as low as you can get it. I've had success with 2- if I try “1” the disc never plays. However, if you can go to 1 try that as well. The speed argument is defined on the first line of the makefile.
Aside from speed, the next thing you'll need to make sure of is CDR quality. Cheap crappy CDRs will be less likely to work. I've had instances where I've had to burn multiple discs before getting the Dreamcast to read it (figuring that out wasn't exactly intuitive). This old DC emulation topic has more info on that.
Now, insert a blank CDR (make sure you're in a properly ventilated room before you blow the dust off first - after all, assuming you have CDRs, when was the last time you used one?) and then run the makefile by typing “make” in the make-cd directory. If everything goes well, you should hear the CD getting written and be able to play it on the Dreamcast, where you'll be greated with a screen showing the Dreamcast's IP info.
If it doesn't work:
Unfortunately, you're dealing with an old system and an outdated form of media, so it's highly likely you can hit problems. I burnt discs before that I thought were 100% broken, only to find they did work… 1 out of three times (or worse). Most of these “semi-working” discs were made before I cranked down the burning speed to “2”.
Understand that if you burn discs too fast, or recognize your Dreamcast is having issues reading them, be sure to retire the CD. Reading poorly burned homebrewed CDs can tire the Dreamcast's motor and eventually make it difficult to ever read a homebrew disc. This happened to my original Dreamcast which is why I now own a second one just for homebrew.
Running Code with dcload-ip

Now, we need to figure out what the Dreamcast's IP is on from the PC. In other words, we need to ensure we can ping the Dreamcast before we get any further.
To do that, the PC and Dreamcast need to be in the same IP range. To do that, you'll need to make your PC's ethernet IP static.
Go to Control Panel -> Network Connections. Find your ethernet (mine is “Local Area Connection.”) Right click and select properties.
In the box in the middle, select “Internet Protocol Version 4 (TCP / IPv4)” and select properties.
By default, the setting will be “Obtain an IP address automatically.” Change it to “Use the following IP Address:” I changed this to 10.0.0.2.
Reading through a past tutorial on how to do this, I said to execute “arp -h” to clear arp. But this time it didn't seem to do anything.
Anyway, execute “ping 10.0.0.2” and make sure something comes back and your PC can ping itself from that address.
Next, we need to assign the Dreamcast an IP from our machine.
The Dreamcast should be on and you should see the blue screen with the words “dcload-ip 1.0.5” etc. The second line is the Dreamcast’s MAC address. For me, its 00:d0:f1:02:9a:f3.
You need Admin privileges to do this, so hit the start button, in the Run box type “cmd” and then hold CTRL and Shift while pressing entre to get an admin console.
To assign the DC an IP, type:
arp -s 10.0.0.1 00-d0-f1-02-9a-f3
(where the last argument is your Dreamcast's IP).
After this, pinging 10.0.0.1 should work.
Finally, go back to the Cygwin prompt. You're going to run the “pvrmark_strips_direct” example that was compiled in the previous tutorial.
From the dcload-ip route directory (the root of the git clone) do this:
$ ./host-src/tool/dc-tool.exe -x ~/Tools/dreamcast/KallistiOS/examples/dreamcast/pvr/pvrmark_strips_direct/pvrmark_strips_direct.elf -t 10.0.0.1
Congrats! You're now running code on the Dreamcast!