File: machine_dreamcast.html

package info (click to toggle)
gxemul 0.7.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 12,152 kB
  • sloc: ansic: 111,065; sh: 972; exp: 354; makefile: 118
file content (423 lines) | stat: -rw-r--r-- 17,023 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <title>GXemul: Dreamcast emulation</title>
  <meta name="robots" content="noarchive,nofollow,noindex">
</head>
<body style="font-family : sans-serif;">

<!-- 10 lines header.  -->

<h1>GXemul: Dreamcast emulation</h1>
<p>

<a href="./">Back to the index.</a>

<!--

Copyright (C) 2006-2019  Anders Gavare.  All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright
   notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
   notice, this list of conditions and the following disclaimer in the
   documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
   derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.

-->


<p>This page contains information about the <a 
href="http://en.wikipedia.org/wiki/Dreamcast">Dreamcast</a> emulation mode 
in GXemul.
My main goal with Dreamcast emulation is to let <a 
href="http://www.netbsd.org/ports/dreamcast/">NetBSD/dreamcast</a> run, 
similar to how it runs on a real machine. I am also experimenting with 
other programs, such as Linux and simple demo programs that use
<a href="http://gamedev.allusion.net/softprj/kos/">KOS</a>, and 
<a href="http://mc.pp.se/dc/sw.html">Marcus Comstedt's tutorial programs</a>.
These sometimes work to a certain degree.

<p>Games (especially commercial games) are very unlikely to run.





<p><br>
<a name="binaries"></a>
<h3>Running raw binaries (IP.BIN and 1ST_READ.BIN):</h3>

<p><i>(<b>Note:</b> This is very experimental, as GXemul's Dreamcast emulation is very incomplete,
but in principle it could be used as a help when you are developing your own
code to run on the Dreamcast. For example, it may be easier to debug things
in the emulator than on the real Dreamcast.)</i>

<p>According to <a href="http://mc.pp.se/dc/ip.bin.html">http://mc.pp.se/dc/ip.bin.html</a>,
the Dreamcast loads files from the last data track (from track session 2?). The
data track should be an ISO9660 file system, with the first 0x8000 bytes used
by a Dreamcast-specific boot block.

<p>When a Dreamcast boots up, the ROM loads the boot block and first file
as follows:

<ul>
  <li>The first 0x8000 bytes from the data track (usually called IP.BIN, but
  	it has no name on the actual CD) is a boot block, which is loaded to virtual address 0x8c008000.
	This contains executable SH4 boot code, but also some
	text strings, and the name of the first file to run, usually "1ST_READ.BIN".
  <li>1ST_READ.BIN (or whatever the boot block said) is loaded from the regular ISO9660 file system
  	on the CD, to virtual address 0x8c010000. For CDs (note: not GD-ROMs), the
  	file is block-scrambled in a specific way.
</ul>

<p>Execution first starts at 0x8c008300, 0x300 bytes into the boot block,
and the code here displays the SEGA logo and waits for a while. The code then
returns to the ROM, using a system call. The ROM code then calls 0x8c00b800.
In GXemul, this is currently only done when booting from a CDROM image (or
by forcing this mode by jumping to 0x8c000140),
so to boot manually, it's easier to skip the SEGA logo display.

<p>When loading files directly from the host's file system, the examples below assume that
the binary TEST.BIN is an <i>unscrambled</i> binary, since it is read straight into 
GXemul's emulated memory. If you have a scrambled binary, 1ST_READ.BIN,
making a complete ISO may be the best way to go. This can then be booted
(or attempted to be booted) in GXemul using the <tt>-d name_of_image.iso</tt> option.)

<p>There are several ways to start running binaries:

<p>
To manually start at 0x8c008300, i.e. show the logo:
<pre>
	gxemul -XEdreamcast 0xac010000:TEST.BIN 0x8c008000:0:0x8c008300:IP.BIN
</pre>

<p>
To manually start at 0x8c00b800 (Bootstrap 1), i.e. skip the logo and allow bootstrap code to jump to 0x8c010000:
<pre>
	gxemul -XEdreamcast 0xac010000:TEST.BIN 0x8c008000:0:0x8c00b800:IP.BIN
</pre>

<p>
Starting at 0x8c000140 fakes a boot from CDROM, i.e. the emulated ROM calls
0x8c008300 first, and then when that code returns, it calls 0x8c00b800:
<pre>
	gxemul -XEdreamcast 0xac010000:TEST.BIN 0x8c008000:0:0x8c000140:IP.BIN
</pre>

<p>This does not always work very well, though, because graphics may be initialized
in a way which is not understood by GXemul yet.

<p>Note that IP.BIN is loaded last, because that also sets the initial program
counter.

<p>And last, but not least, skip the IP.BIN part alltogether and just run the
binary you are interested in:
<pre>
	gxemul -XEdreamcast 0xac010000:TEST.BIN
</pre>

<p>
See <a href="http://mc.pp.se/dc/ip.bin.html">http://mc.pp.se/dc/ip.bin.html</a>
for more details on IP.BIN and 1ST_READ.BIN

<p>
Almost none of the Dreamcast's hardware is actually emulated by GXemul so far
(sound, textured graphics, etc), but a simple 256-byte demo works:

<p><a href="20110606-dreamcast-roto.png"><img src="20110606-dreamcast-roto-small.png"></a>

<p>To run the roto demo:
<ul>
  <li>Go to <a href="http://www.pouet.net/prod.php?which=7050">http://www.pouet.net/prod.php?which=7050</a>
  	and download <a href="http://www.boob.co.uk/files/roto.zip">http://www.boob.co.uk/files/roto.zip</a>.
  <li>Extract roto.bin from the zip file.
  <li>Start GXemul like this:
<pre>
	# Starting using bootstrap code in IP.BIN:
	gxemul -XEdreamcast 0xac010000:roto.bin 0x8c008000:0:0x8c00b800:IP.BIN

	# or easier: starting the raw binary by itself:
	gxemul -XEdreamcast 0xac010000:roto.bin
</pre>
</ul>

<p>
Another example is <a href="http://mc.pp.se/dc/serslave.html">Marcus Comstedt's
"Serial upload slave"</a> program. Extract IP.BIN from
<a href="http://mc.pp.se/dc/files/serial_slave.tar.gz">http://mc.pp.se/dc/files/serial_slave.tar.gz</a>.
Then launch it in the emulator like this:
<pre>
	gxemul -X Edreamcast 0x8c008000:0:0x8c000140:IP.BIN
</pre>

<p>According to Marcus' page, <tt>?</tt> prints out the version number (V103 in
this case), and it handles <tt>S0</tt>, <tt>S3</tt>, and <tt>S7</tt>
<a href="https://en.wikipedia.org/wiki/SREC_%28file_format%29#mediaviewer/File:Motorola_SREC_Chart.png">SREC
line entries</a>. <tt>S7</tt> causes it to print <tt>OK</tt> and start the uploaded
program. Here is a screenshot where a hobby operating system kernel
(<a href="http://gavare.se/ycx5/">YCX5/dreamcast</a>) is launched this way,
by pasting the SREC entries into the window called "SH4 SCIF":

<p>
<a href="20140803-serial-upload-slave.png"><img src="20140803-serial-upload-slave-small.png"></a>

<p>
Here is another example with a 3D test program ("gltest.bin") from the
KOS examples, which more or less works:

<p>
<a href="20110624-dreamcast-gltest.png"><img src="20110624-dreamcast-gltest-small.png"></a>
&nbsp;&nbsp;
<a href="20110703-dreamcast-gltest.png"><img src="20110703-dreamcast-gltest-small.png"></a>
&nbsp;&nbsp;
<a href="20140803-dreamcast-gltest.png"><img src="20140803-dreamcast-gltest-small.png"></a>






<p><br>
<a name="rom"></a>
<h3>Experimenting with ROM dumps from your own machine:</h3>

<p>As mentioned above under the <a href="#binaries">Running raw binaries</a> section,
the emulation of Dreamcast hardware is not correct enough to run things that
really rely on the hardware functioning properly such as games. Even more
picky about the hardware is the original ROM itself. Even though running an
original Dreamcast ROM in the emulator <b>does not really work</b>, it can be fun and/or
interesting to experiment with.

<p>
The first step is to dump the ROM contents (and possibly flash memory) of your
Dreamcast.

<ul>
	<li><tt>0x00000000 - 0x001fffff</tt>: ROM bios (2 MB)
	<li><tt>0x00200000 - 0x003fffff</tt>: Flash (256 KB) (128 KB according to <a href="http://mc.pp.se/dc/flashmem.html">http://mc.pp.se/dc/flashmem.html</a>)
</ul>

<p>There are several ways to dump these. I wrote a simple program which displayed
memory contents as white and black squares on the screen, and recorded it
with a web cam, and then wrote another program to look at those images and
dump the resulting bytes into a file:

<p>
<a href="20131109-displayDreamcastMemory.png"><img src="20131109-displayDreamcastMemory-small.png"></a>

<p><small>(Here shown running in the emulator rather than on real hardware.)</small>

<p>If you don't feel like writing your own dumping program, there are programs
already written by others that can e.g. send the contents of memory
over http over ethernet (see <a href="https://www.youtube.com/watch?v=DVowfmrifN8">https://www.youtube.com/watch?v=DVowfmrifN8</a>
for an example).
Nomatter how you dump your Dreamcast's ROM bios and flash memory, they should end
up in two files. Common names on the Internet seem to be <tt>dc_bios.bin</tt> and
<tt>dc_flash.bin</tt>, so let's call them that.

<p>In principle, to start GXemul and load your BIOS and Flash memory images,
the following command line should be used (-Q means to not do PROM emulation
in software):
<pre>
	<b>gxemul -X -Q -E dreamcast 0x200000:dc_flash.bin 0x0:dc_bios.bin</b>
</pre>

<p>
Unsurprisingly, one of the first things the ROM BIOS boot code does is to copy itself
from ROM (physical address range <tt>0x00000000 - 0x001fffff</tt>) into RAM
(virtual address range <tt>0x8c000000 - 0x8c1fffff</tt>).
However, some of the ROM memory range (<tt>0x00004300 - 0x000052fc</tt> I think)
is still accessed later on.
 
<p>It is also possible to attempt to launch a BIOS in RAM only, skipping the ROM-to-RAM
copying, by setting the initial PC to use after loading the BIOS image.
For the specific BIOS image in my Dreamcast, the PC to use is 0x8c000120.
GXemul does not currently emulate the hardware well enough to get past a never ending
loop at the start, so I also have to use the following <tt>put</tt> command
to patch the BIOS in memory to get past that point.
<pre>
	<b>gxemul -X -Q -E dreamcast -c 'put h 0x8c0d7df6,0x8800' 0x8c000000:0:0x8c000120:dc_bios.bin</b>
</pre>

<p>After getting past the never ending loop, the "set date/time" dialog
appears. Presumably it finds a mismatch between what it sees in the Flash
memory (stored date/time) and the emulated RTC chip's date/time.
After pressing "U" (for "left") and "A" on the keyboard, the main
menu is reached.

<p>
<a href="20140802-dreamcast-bios-test1.png"><img src="20140802-dreamcast-bios-test1-small.png"></a>
&nbsp;&nbsp;
<a href="20140802-dreamcast-bios-test2.png"><img src="20140802-dreamcast-bios-test2-small.png"></a>
&nbsp;&nbsp;
<a href="20140802-dreamcast-bios-test3.png"><img src="20140802-dreamcast-bios-test3-small.png"></a>
&nbsp;&nbsp;
<a href="20140803-dreamcast-bios-test4.png"><img src="20140803-dreamcast-bios-test4-small.png"></a>

<p>The graphics is wrong; it is a work in progress, everything has to be
reverse-engineered and double-checked both with the BIOS and with homebrew
programs and developer examples.
Wire-frames can be turned on by defining <tt>DEBUG_RENDER_AS_WIRE_FRAME</tt>
in <tt>dev_pvr.cc</tt>.
It is also exceedingly slow, since it is done in software. (A possible
future enhancement could be to make use of the host's OpenGL hardware.)

<p>The following keyboard keys correspond to controller inputs:
<pre>
	             <b>8</b> <font color="#a00000">Up</font>                          <b>A B C D X Y Z</b> = Buttons
	<b>4</b> or <b>U</b> <font color="#a00000">Left</font>               <b>6</b> or <b>O</b> <font color="#a00000">Right</font>     <b>S</b>             = Start button
	             <b>2</b> or <b>K</b> <font color="#a00000">Down</font>
</pre>

<p>There are no analog inputs yet.






<p><br>
<a name="netbsd_generic_md"></a>
<h3>NetBSD/dreamcast GENERIC_MD:</h3>

<p>It is possible to run <a 
href="http://www.netbsd.org/ports/dreamcast/">NetBSD/dreamcast</a> in 
GXemul. A NetBSD ramdisk kernel can reach userland, however, no network
interface is emulated yet, so root-on-nfs is not possible.

<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href="20061029-netbsd-dreamcast.png"><img src="20061029-netbsd-dreamcast_small.png"></a>
&nbsp;&nbsp;&nbsp;
<a href="20061104-netbsd-dreamcast-real.jpg"><img src="20061104-netbsd-dreamcast-real_small.png"></a>

<p>The photo on the right shows NetBSD/dreamcast running both on a real 
Dreamcast, and in the emulator. Unfortunately without a keyboard...

<p>Download the kernel here:<pre>
	<a href="ftp://ftp.netbsd.org/pub/NetBSD/NetBSD-8.0/dreamcast/binary/kernel/netbsd-GENERIC_MD.gz">ftp://ftp.netbsd.org/pub/NetBSD/NetBSD-8.0/dreamcast/binary/kernel/netbsd-GENERIC_MD.gz</a>
	<a href="ftp://ftp.netbsd.org/pub/NetBSD/NetBSD-8.0/dreamcast/binary/kernel/netbsd-GENERIC_MD.symbols.gz">ftp://ftp.netbsd.org/pub/NetBSD/NetBSD-8.0/dreamcast/binary/kernel/netbsd-GENERIC_MD.symbols.gz</a> (optional)
</pre>

<p>If you downloaded the symbols, gunzip them before proceeding.

<p>Start NetBSD/dreamcast using the following command line:<pre>
	# Without symbols:
	<b>gxemul -XEdreamcast netbsd-GENERIC_MD.gz</b>

	# With symbols (makes single-stepping and tracing more meaningful):
	<b>gxemul -XEdreamcast netbsd-GENERIC_MD.symbols.gz netbsd-GENERIC_MD.gz</b>

</pre>









<p><br>
<a name="netbsd_live_cd"></a>
<h3>NetBSD/dreamcast Live CD:</h3>

<p>According to <a href="http://mail-index.netbsd.org/port-dreamcast/2005/04/25/0000.html">http://mail-index.netbsd.org/port-dreamcast/2005/04/25/0000.html</a>,
Rui Paulo has made available a NetBSD/dreamcast Live CD. It can run in
GXemul:

<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href="20070128-netbsd-dreamcast-livecd-1.png"><img src="20070128-netbsd-dreamcast-livecd-1_small.png"></a>
&nbsp;&nbsp;&nbsp;
<a href="20070128-netbsd-dreamcast-livecd-2.png"><img src="20070128-netbsd-dreamcast-livecd-2_small.png"></a>

<p>The image is available here:<pre>
	<a href="http://netbsd.student.utwente.nl/rpaulo/">http://netbsd.student.utwente.nl/rpaulo/</a>
</pre>

<p><i><font color="#ff0000">NOTE (February 2007):</font>
The ISO image seems to have been removed from the server,
but you should be able to create one from scratch using
instructions available at various locations on the Internet.</i>

<p>Only the ISO9660 filesystem image is needed:<pre>
	<a href="http://netbsd.student.utwente.nl/rpaulo/livecd.raw.bz2">http://netbsd.student.utwente.nl/rpaulo/livecd.raw.bz2</a>
</pre>

<p>Uncompress the CD image (using bunzip2), and type the following command 
to attempt to boot directly from the image:<pre>
	<b>gxemul -XEdreamcast -d co23965696:livecd.raw</b>
</pre>

<p>(The <tt><b>c</b></tt> disk image option is necessary to treat the raw
file as a CDROM image, and the <tt><b>o</b></tt> part is needed because
the ISO9660 filesystem in the image is offset by 11702 sectors, i.e. 2048
bytes each, and GXemul was unable to guess the offset by looking at
the ISO header.)

<p>At the <b><tt>root device:</tt></b> prompt, type 
<b><tt>gdrom0</tt></b>. For <b><tt>dump device</tt></b>,
<b><tt>file system</tt></b>, and <b><tt>init path</tt></b>, just press 
Enter.







<p><br>
<a name="linux_live_cd"></a>
<h3>Linux/dreamcast Live CD:</h3>

<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href="20070308-linux-dreamcast-1.png"><img src="20070308-linux-dreamcast-1_small.png"></a>
&nbsp;&nbsp;&nbsp;
<a href="20070308-linux-dreamcast-2.png"><img src="20070308-linux-dreamcast-2_small.png"></a>

<p>A Linux/dreamcast Live CD ISO image can be found here:<pre>
	<a href="http://ftp.riken.go.jp/pub/misc/Japan/m17n.org/super-h/CD-R/lc2000.iso">http://ftp.riken.go.jp/pub/misc/Japan/m17n.org/super-h/CD-R/lc2000.iso</a>
</pre>

<p><i><font color="#ff0000">NOTE (August 2014):</font>
The ISO image seems to have been removed from the server!</i>

<p>Once you have downloaded the ISO image, type the following command to 
boot directly from the image:<pre>
	<b>gxemul -XEdreamcast -d lc2000.iso</b>
</pre>

<p>(It seems that this specific iso image was built using instructions
from <a href="http://www.anytux.org/doc.php?doc_id=1">http://www.anytux.org/doc.php?doc_id=1</a>.)








<p><br>



</body>
</html>