32X Devkit

Discussion on development for other consoles. Interest may result in the creation of new forums.

Moderators: cheriff, gilligan

Post Reply
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

32X Devkit

Post by J.F. »

I've been doing a little work on the SEGA 32X recently, and had to put together a devkit to do homebrew. Now I'm sharing this with others. The programs developed by this work in a 32X emulator (Gens and Kega so far). I plan on getting a flash cart to get it working on a real 32X. When I do, this will get updated. (EDIT: I've gotten one report that this DOES work with a real 32X using the TotoTek MD-Pro flash cart!)

This is for linux. The SH2 toolchain is gcc from KPIT, and the 68000 toolchain is gcc from the uclinux project. You can get a Windows toolchain for the SH2 from KPIT, but you'd need a Windows 68000 assembler like asmx to get this devkit working in Windows. I leave that to the reader as an exercise. :D

Just copy the gendev directory from the archive to wherever you keep your toolchains (usually /usr/local). You'll need a couple exports:

Code: Select all

export GENDEV=/usr/local/gendev
export PATH=$GENDEV/sh2/bin:$GENDEV/m68k/bin:$GENDEV/bin:$PATH
The project-src directory in the archive has the files needed to get your 32X program running. You should only need to add to the OBJS list in the makefile and change the name from "example" to whatever you want.

The makefile assembles the two m68k files into binary, then compiles all the rest, linking the result into a binary suitable to running with your 32X emulator. The entry for your code is main(), just like normal. If you wish to use the second SH2 in your program, comment out the _slave function in sh2_crt0.s, then add a slave() entry in your code.

One of the funny things about the KPIT toolchain for the SH2 is you can't compile the code as SH2. It seems when they built the toolchain, they enabled hardware floating point for all SH2 variants, not just the A and E variants. As such, you have to compile as SH1. The toolchain included here includes the SH1 libraries. You can still do SH2 specific code via inline assembly or separate assembly files.

The debug code should look familiar - it's based on the PSP homebrew SDK debug code. It's VERY handy for seeing whats going on in the 32X. It could also be used for simple interfaces like people often do on the PSP. One issue is the SH libraries don't seem to do varargs properly, so don't use Debug32xScreenPrintf() - sprintf to a string and use Debug32xScreenPuts() instead.

DevKit32X-20090203.7z
User avatar
hardhat
Posts: 17
Joined: Thu Mar 02, 2006 9:42 am
Contact:

Post by hardhat »

Hi there,

This is just the sort of thing that I'd like to have up and running. I gave it a try, but there are some problems with this version. I am wondering if you can help me with them.

First, a minor thing: the Makefile expects some files to be in Src/ when they aren't. After trying a few things the simplest change is to get rid of the Src/ references in the makefile.

Second, example.c is missing. I made my own, so that should be fine.

Third, the distro includes two gcc cross-compilers, but they are made without a prefix such as 68k-gcc or sh-elf-gcc. A a result, if I put them at the beginning of the path like you suggest then it'll take over from regular gcc.

Now for the big one: when I compile debug_32x.c which contains some functions that I'd really like to have access to, it fails with this error:

Code: Select all

tinkerbell:~/packages/DevKit32X/project-src$ make
/home/hardhat/packages/DevKit32X/gendev/sh2/bin/gcc -m1 -mb -O2 -Wall -g -fomit-frame-pointer -I. -I/home/hardhat/packages/DevKit32X/gendev/sh2/include -c debug_32x.c -o debug_32x.o
debug_32x.c: In function ‘Debug32xInit’:
debug_32x.c:330: internal compiler error: Illegal instruction
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL&#58;http&#58;//www.kpitgnutools.com> for instructions.
make&#58; *** &#91;debug_32x.o&#93; Error 1
Is that related to the third problem? Before I changed my path, it couldn't find cc1. It should be correct now.
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

This package is a little old. I've made some changes since then, so I'll update the package today some time. The example makefile is just that - an example. It's not meant to compile as is - just show how one would be done. If you want an "example" that actually compiles, you should try my Wolf32X project... which I'll also post the latest code to here at the same time I post the updated toolchain. I'm not sure about the third issue, but try it again with the updated toolchain and Wolf32X code once I post it.

I keep everything relative to gendev to keep it all organized. Within gendev, I make a bin directory for non-gcc related stuff, then a directory each for the m68k and sh2 toolchains. Sometimes that means being more specific in the makefile about which gcc you're using for things, or perhaps splitting the makefile into pieces and doing make -f file or make -C dir. I'll have an example of that when I finish the CD 32X example I'm working on (another week or two on that).

Well, I am glad someone is at least trying this. :)
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

Okay, here's an update to DevKit32X and the latest Wolf32X code.

DevKit32X-090526.7z
Wolf32X-090526.7z

To make Wolf3D Shareware, do the exports mentioned in the first post, then "make -f Makefile-wsw". The Spear of Destiny Demo is "make -f Makefile-sdm".
User avatar
hardhat
Posts: 17
Joined: Thu Mar 02, 2006 9:42 am
Contact:

Post by hardhat »

Thanks for your effort to update this package. I'll defiantly keep my eye out for the update. It could come in quite useful for me with an upcoming project. I don't mind having multiple makefiles if it all works in the end. Coding for multiple CPUs in one executable is always a nuisance.
User avatar
hardhat
Posts: 17
Joined: Thu Mar 02, 2006 9:42 am
Contact:

Post by hardhat »

Great. I got it to work, once I switched to a computer with a Dual Core cpu. The other computer's Atom core CPU doesn't do all of the 686 instructions I guess. Thanks again for posting the update for me.
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

hardhat wrote:Great. I got it to work, once I switched to a computer with a Dual Core cpu. The other computer's Atom core CPU doesn't do all of the 686 instructions I guess. Thanks again for posting the update for me.
Yeah, I'm not sure what CPU the uclinux (m68k) or KPIT (sh2) compilers are compiled for beyond generic 686. Never even crossed my mind that some CPUs might not like them. :)

Glad you could get it working. Hopefully, it helps us see more 32X homebrew.
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

Okay, here's archives for my latest gendev toolchain and "SDK". The SDK is the source for bin2c, libheap, libmd, libromfs, and zasm. The binaries are all in the toolchain archive in the proper place. Note that this arc, unlike previous ones, is entirely 32 bit. Most 64 bit linux distros can handle that, but you may need 32 bit compatibility libraries installed. The SH compiler has been updated to the latest KPIT 902 release.

gendev-20090925.7z
gendev-sdk-20090925.7z

Notes: libheap is a basic allocator library that would be underneath a malloc library. libmd is Stef's MiniDevKit support files all made into a library for convenience. libromfs is a library for reading romfs generated rom files (genromfs included). bin2c and zasm are used for making Z80 programs that can be included in programs. See the musicdemo example for details.

Please note the exports needed for Genesis or 32X compiling:
MD
export GENDEV=/home/jlfenton/Tools/gendev
export PATH=$GENDEV/m68k/bin:$GENDEV/bin:$PATH

MARS
export GENDEV=/home/jlfenton/Tools/gendev
export PATH=$GENDEV/sh2/bin:$GENDEV/m68k/bin:$GENDEV/bin:$PATH

Wolf32X serves as the example of 32X programming, while any of the musicdemo apps serve as a demonstration of Genesis programming.

w3d-sod-sw-b5.zip
musicdemo4.7z
Post Reply