Monday, June 2, 2014

Adventures in 32X Homebrew - Part 1

I have not been posting a lot recently, one of the reasons has been a project that I started in early 2012, which as it never quite reached completion I did not want to let the cat out of the bag with premature posts, more importantly I was a novice in the areas that contributed to this project so to write a bunch of posts without knowing a thing about what I was writing would have been fruitless exercise. This mysterious project consumed my nights and weekends, on and off for at least a year and although I think what I originally intended to do is feasible, I do believe I have learned enough that sharing this knowledge may be useful to someone else, at least as a cautionary tale of things not to do.

As you may conclude from the title of this piece, the subject of my project was the Sega 32X game console, and specifically developing "homebrew" games for it. For the sake of brevity I will refer to all consoles and games by their U.S. titles, for example the Sega Genesis was titled Sega Megadrive in other markets.

Background

Sega 32X

Sega 32X ( was released in 1994 as an add-on unit for the Sega Genesis/Megadrive video game console. The 32X was considered as a way to "upgrade" the 16-bit Genesis to be a 32-bit console without having to buy an entire new console that were starting to enter the market, such as the 3DO, Atari Jaguar and even NeoGeo, this would have been nice for the millions of owners of Genesis unit's with large libraries of existing games that would still be playable on the 32X expansion. In addition, at the time, Sega was already being edged out in the 16-bit console wars by the Super Nintendo (SNES) where games like Donkey Kong Counter, Starfox, Killer Instinct and Final Fantasy 3/VI were beginning to eclipse the Genesis titles visually and even in other areas like game sound and the sheer amount of content. Whether the concept was sound or not, the result was 32-bit capable system that was less powerful than the other 32-bit consoles on the market or the next generation that was coming, the so-called "fifth generation" consoles, of Sega Saturn, Sony Playstation or Nintendo 64.  The result of the release of this console was that while initially popular with American genesis owners, the lack of third party development support and poor quality titles crippled the platform, sales fell when people realized that this wasn't going to get the games that were coming out for the real 32-bit systems. Sega ended up completely pulling the plug on the 32X in 1996 with no new games being released. The saga of the development and release of the 32X in this context is a fascinating story by itself, and excellent accounting of that can be found in Project Mars: Anatomy of a Failure.

I will out myself by admitting to owning the 32X (and still do), and in my blind brand loyalty to Sega I had at the time, tried as hard as I could to like the 32X and the games that were released for it. Looking back with almost 20 years of hindsight, I was rather naive over the state of the market at the time. for one thing, I did not have any subscriptions to gaming magazines at the time, so I really did not have any critical analysis of the 32X, it's expected game library or system specifications and capabilities. I did not recall that the Sega Saturn and Sony Playstation came out so soon after the 32X did. I also remember believing some things initially, don't know where I heard it, such as that the Sega 32X + Sega CD add-ons would create a combined system "equivalent" to the Saturn, even that the games would physically be compatible, or that there was some kind of hardware acceleration for 3D games. I was in school at the time, and couldn't have afforded a Saturn in any case, with my meager part-time home chore income, the idea we could have a 32-bit system instead of a 16-bit one, was very appealing. The initial lineup of games that were released were promising as well, Doom being of the biggest titles, probably one of the biggest PC games at the time, Star Wars Arcade looked incredible, and it was Star Wars! Virtua Racing was another cool 3D polygonal car racing game, that was pretty impressive for the time. Both of these Sega titles I had actually played a few times in Arcades around '94. Again I was not a very educated consumer, I did not go to arcades all that often, while in the 8-bit era, it seemed pretty obvious that arcade games were far superior, as 32-bit era approached, it wasn't clear that the arcades still had far better graphics than what we were going to be getting at home. Even for 16-bit, at the time I was not really sophisticated enough to realize that the Mortal Kombat I played at home was a different experience to the one in the arcades. In any case, the games looked "good enough" and surely, more and better games would be coming out?

Its a trap: Repetitive arcade game play from one of
the best 32X games
Now, I loved Sega at the time, but overall, my impression of the 32X was a major let down, even if I didn't want to admit it. In my opinion, the games were generally just boring, it's hard to pin-point why, I think mainly the game play was lacking, and the 3d effects and fairly limited worlds were underwhelming after a while. For example Virtua Racing Deluxe, had really nice, crisp polygonal graphics in true 3d world with multiple camera angles, decent sound and music, but it in the end, it lacked the rush and thunder of the arcade version, especially after going around the same tracks 2-3 times, there isn't much else going on. I've never been a fan of racing games, but there was only so much you could drive around, and you could never get outside the track and explore. Motocross Championship, was basically like EA's Road Rash series, except the graphics were barely better, the locations were always the same dusty dirt track and the sound effects were particularly terrible. The best 32X game was Star Wars arcade, which again, as an arcade port, was repetitive, fly through hyperspace to an area and chase TIE fighters in circles. Now it was beautiful 3d space environment with asteroid fields and star destroyers, but it did lose it's edge after the 15th tie fighter blew up in a small yellow virtua-explosion off in the distance after 20 other similar laser shots failed to do any damage. I don't think I ever actually made it to the Death Star trench run level. I was also disappointed that you couldn't damage the star destroyers, it was my dream to  blow up their deflector shield domes, ala Return of the Jedi (Intensify forward firepower!....Too Late!!!). I don't think I actually had any other 32X games. I probably played Sonic & Knuckles alone twice as much as all those games combined while I owned that system.

Making Dreams a Reality

So money spent, dreams shattered, I always wished that they made better games for the 32X. Many years later, I had heard that one of the reasons that the games weren't that impressive was due to the developers not utilizing the hardware to it's fullest. Now being a developer myself, I wondered, what if I made the next great 32X game? The context is that I have been interested in gaming and computer programming all my life, I have made some game-ish programs for university courses and I briefly dabbled in libSDL programming on Unix. I have a few game ideas I have been kicking around in notebooks and in my head for years, and it was always a dream to someday put them down into reality. Why the 32X, well it just so happens that the genre's of games I want to make are generally side-scrolling, 2D affairs. For me and probably a generation of gamers, there is nostalgia for games that look and act like the ones we grew up immersing ourselves in on our old sega's and nintendo's. My grand vision was to take some of game story ideas, using genre's that were mostly done in the 16-bit era, and make even better versions of those for the 32X! Not only would these retro games be good in their own-right, they would be unique for being released for one of the most maligned and obscure platforms ever, nobody would be able to compete with me! I own a Sega Genesis and 32X although it had been sitting in a box in my parent's basement for 10 years or so, I planned to eventually resurect it and play my homebrew masterpieces on it one day. So I set out to "teach myself" how to program for 32X and make the best darn game anyone had ever played on that system.

Hardware and Development Environment

The 32X is an interesting piece of hardware, the overall system combined with the Genesis (+ Sega CD) is a complex multi-processor machine with heterogeneous CPU architectures, video processing capabilities, memory spaces, but sharing the main inputs/outputs (Cartridge ROM, controllers, video and audio out). Unfortunately to learn the 32X you have to know at least a little about the way the Genesis works and some of the ways it differs. This is a crucial point to keep in mind for later, because often you'll be amazed by things that Genesis games could do with apparent ease which seem to require vast computing power in the 32X.

There is relatively scant documentation on the internet, and most of it, that does exist is useful as background reading, rather than being actionable step-by-step guides to do anything. There is a small community of homebrew developers who are mostly self-taught, extremely technical and interested in all the bits and bytes of hardware in both the Genesis and 32X. Without their help and guidance I would never have been able to get a Hello World to run on the 32X.

Specifications

CPUs: Dual Hitachi SuperH RISC processers (SH-2, SH7064)
Clock Speed: 23 Mhz
Main Memory: 256Kb SDRAM

Video:
Video Memory: 256Kb (two 128 Kb framebuffers) 

Screen Resolution: 320x224 or 320x240 (PAL)
Color depth: Up to 15 bits, 32768 unique colors, two-bytes per pixel, can use paletted color mode, using up to 256 on-screen colors with one byte per pixel to save memory.

Sound: 

Stereo 2-channel PWM (Pulse Wave Modulation mixer)

And that's about it for the 32X. As I mentioned the 32X combines with the Genesis base, and a 32X game can actually leverage the Genesis hardware in addition to just the 32X components (as well as Sega CD). The Genesis specs are:

CPUs: Motorola 68000
Clock Speed: 7.67 MHz
Main Memory: 64Kb RAM
 

Video:
CPU: Dedicated "Video Display Processor" based on Texas Instruments TMS9918
Video Memory: 64Kb and 64 x 9-bits of CRAM (Color RAM)
Resolution:
Maximum same as 32X, 320x224, 256x224, 320x240 (PAL only), 256x240 (PAL only)
Supports 3 planes, 2 background layers and 1 sprite layer

Sound:
CPU: Z80 @ 4 MHz (Not Present in MK-1631)
Controls PSG (Programmable Sound Generator, TI 76489) & FM (Yamaha YM 2612) Chips
Sound Memory: 8Kb

Cartridge

32X cartridges although physically different are essentially the same as Genesis carts, and can hold typically 4Mb of ROM data although the size of ROM could be larger if used with bank switching capability to access a larger memory space.


Development

  Game software can either be developed in assembly language (a mix of SH2 assembly plus 68000 assembly for Genesis in the same game) or a higher level language such as C that is compiled into machine code for one or the other processor architecture. An "art" of the 32X development is being able to write software for both the Genesis and 32X that can coexist peacefully on the shared hardware.

There are no IDEs, there really isn't a standard SDK, toolkit or any libraries for the 32X available, other than a few home brew examples that are out there. If you can set up an IDE and configure a custom tool chain you may be able to use it to build your C source code into your game. There are appears to be more of a homebrew community for the Genesis. I used a combination of text editors with syntax highlighting and various command line tools and shell scripts for my own build environment which I will cover in Part 2 (coming soon)


Background Resources & Reading


It helps to have an overview of the hardware and reference material handy, there isn't much documentation or specific resources on the web for 32X development, so what is out there is gold.

Collection of Sega 32X Manuals including the most important "32X Hardware Manual".

Reverse engineered introduction to 32X capabilities and hardware.

Devster's site also has a few other documents, example homebrew ROMs and utilities.


"Project Mars: Anatomy of a Failure" – a good overview of the development, marketing and failure of the 32X and the impact it had on Sega.

"Hitachi SH7604 Hardware Manual" – The manufacturers manual for the main RISC CPUs used in the 32X aka SH2, Super-H. Has the details for all of the assembly language instructions for the processors.

Gallery: 32X Development – includes some utilities, assemblers and 32X BIOS files as well as more Hitachi SH2 documentation.



Places to get support


The only places to ask questions about 32X development are a few Sega/gamer enthusiast sites' forums where there is still a small homebrew scene of people who have taught themselves how to program.


1 comment:

  1. "CPU: Z80 @ 4 MHz (Not Present in MK-1631)"

    This is not true. First of all there are a number of different "MK-1631" units. It doesn't mean much by itself. Second, they ALL have the Z80 and I don't know why anyone would think otherwise. Games actually use the Z80. I think what started this rumor was there are a couple late revisions of the Genesis board (VA4 found in late-gen Model 2) and the Genesis 3 that integrated the Z80 into the GOAC.

    ReplyDelete