Wednesday, March 7, 2012

More MegaDrive MegaFun

Last post was my notes for the build-your-own-Sega-Genesis-gcc-cross-compiler. Alternative is a pre-built kit if you are running on Windows. This one is actually much more than just the toolchain, as it is a library built around an SDK which has been in the works for a while.

Even though the sgdk is hosted in Windows, it is way easier to work with in Cygwin because the whole DOS environment is such an unwieldy piece of crap.

Now,  after unzipping the download, run the following commands in your Cygwin shell:

export PATH=$PATH:/cygdrive/d/mYJUNK/sgdk/bin
cd /cygdrive/d/mYJUNK/sgdk/sample/cube_flat
make GDK="d:/mYJUNK/sgdk" -f ../../makefile.gen

The GDK environment variable will be propagated into the makefile. Note that it uses the DOS letter, but Unix-style forward slashes.

One clever thing about this is how he used make wild-carding to use the same makefile for all the examples.

Now, go get Quest for Money and compile it. This is a very nice game with beautiful graphics and sound layers, with all the source code included and detailed descriptions of how it was developed. Thanks to Shiru for promptly answering my questions!

Friday, March 2, 2012

--target=m68k-elf

More nerd-notes. Setting up m68k cross compiler in gcc under Cygwin to build some code for Sega Genesis.

I installed the dgen Genesis emulator in the MinGW environment by building it and SDL-1.2.15 from sources. I am interested in experimenting with using the GNU debugger, with the Genesis emulator as the target, by integrating dgen with the modified Musashi 68k core.

Building the m68k-gcc may be a problem in MinGW - my gcc build for --target=m68k-elf failed with errors on 'pipe' 'fork' 'sleep' 'fcntl' etc. I don't know enough about MinGW to know if there is a workaround. It could be that I need to download newer sources for gcc ... I am using binutils-2.20.1.tar.bz2 and  gcc-core-3.4.6.tar.bz2. Why? because I did this about 2 years ago in Ubuntu and those were the files that worked for me then.

Alternatively, I should be able to run the m68k tools in Cygwin. My first binutils build in Cygwin blew up, but one update fixed it.

Here's a link to the setup that I followed, abeit with the file versions identified above, and changed coff to elf.

In addition, I found that the code I was building needed some standard C libraries and headers ... more on that later. I had a copy of newlib-1.12.0.tar.gz laying around so I built that with the same settings as binutils and gcc, i.e.

cd newlib-1.12.0/ ; ./configure --prefix=/usr/local/m68k --target=m68k-elf

So having done all that, the build is very close to complete, but there is one more error:


/usr/local/m68k/m68k-elf/lib/m68000//libmvme135.a(lseek.o): In function `lseek':
/cygdrive/d/tmp/m68k_cyg/newlib-1.12.0/m68k-elf/m68000/libgloss/m68k/../../../.././libgloss/m68k/../lseek.c:28: undefined reference to `__errno'

I hunted around for a second and did not find a tight solution, so I simply improvised and added the necessary definition to one of the C files in my sources:

int __errno;

... and now the make completes!