Polygons Another World: Sega Genesis
Translation the fifth article in the series from Fabien Sanglard , this time about Another World port on Sega Genesis .
MegaDrive/Genesis began immediately after Sega launched its Master System in 1987. At that time, Sega's goal was to create something that surpasses the PC Engine from NEC and Famicom from Nintendo.
Series of articles
- Another World Polygons .
- Another World: Amiga 500 landfills .
- Another World: Atari ST polygons .
- Another World Polygons: IBM PC .
- Another World: Sega Genesis.
Under the leadership of Masami Ishikawa, the team took only a year to create a 16-bit system. The console, launched on October 29, 1988 in Japan, didn’t work very well; 400,000 devices were sold in the first year. Despite releasing numerous peripherals and an entire generation ahead of NES, MegaDrive did not find its audience.
The release in the USA (January 1989) and Europe (September 1990) was not the best  . Salvation came in mid-1990 when Tom Kalinsk became CEO of Sega America. Lower prices, a dedicated US development team, an aggressive television ad campaign (Genesis does what Nintendon't), and replacing the bundled Altered Beast game with Sonic the Hedgehog put Genesis at the top of the charts.
Combined with the late Nintendo SNES and the troubled NEC TurboGrafx-16, Sega controlled 65% of the 16-bit console market in January 1992 and surpassed Nintendo in four consecutive Christmas seasons from 1990 to 1994. 39.7 million units were sold worldwide  .
From a technical point of view, Genesis has an impressive Motorola 68000 (7.61 MHz), up to 8 MB of ROM, 64 KB of RAM, 64 KB of video memory, ASIC video processor (13 MHz) and Z-80 (3.58 MHz) with 8 KB for TI 76489 and YM 2612 audio controls.
The component responsible for generating the video signal is called VDP (Video Display Processor). It manages VRAM and CRAM, where the palettes are stored.
Please note that the 68000 processor cannot address VRAM, it can only "communicate" with VDP through registers mapped into RAM. Data transfer is usually done using a DMA video processor that has access to RAM and VRAM. VDP also has registers for allowing VRAM read/write operations, but they are pretty slow.
68000 stops during DMA transfer, but Z-80 can continue to work until there is no need for access to RAM.
DMA is pretty fast during BLANK and runs twice as fast as the 68000 loop. It's as fast as 68000 during an active scan.
- Genesis Developer Manual
The color system is similar to Atari ST with 3 bits per channel, totaling 9 bits per color.
Video Processor (VDP)
VDP is the graphics core of the ASIC system. It is based on a sprite engine, which means there is no frame buffer. It works with four layers of  called Scroll B, Scroll A, Windows and Sprites.
Scroll A and Scroll B are scrollfields. They can be larger than the screen and move independently of each other to create a parallax effect. Scroll A can also be used as a “Window”, which cannot be scrolled and therefore is well suited for displaying HUD elements.
All layer elements use 4-bit indexes in the palette of their layers (therefore, there are only four palettes). Palette index 0 is always considered transparent in all four palettes. This gives 15 colors per layer  . All palettes are stored in 128 bytes called CRAM.
When VDP generates scan lines for a TV, for each pixel, the priority system tells you in which order the layers should be selected. There is no support for blending (transparency) between layers, but transparency can be achieved (using index 0). To simplify, a convenient analogy for understanding priority is the Z-component with Scroll B located at the rear and Sprite at the front. As long as VDP falls into transparent pixels, it continues to move on to the next level.
Scrollfields consist of 8x8 cells. The cell layer consists of 32 bytes, represented as 8 nibble lines.
Scrollfield content is defined by entries in its "name table"  .
A sprite layer can display up to 80 sprites regardless of the contents of two scrolls. Sprites can be larger than Cells, from 8x8 to 32x32. Properties (position in the virtual space 512x512, priority and much more) of a sprite are set by writing in the "sprite table"  .
Two modes are available: "H32" with cells 32x28 (256x224 pixels) and "H40" with cells 40x28 (320x224 pixels).
NTSC vs PAL
There is a difference between American TVs and European TVs. PAL has 576 visible lines, while NTSC has 486 visible lines. Genesis solved this by providing PAL mode with 30 horizontal cells (two more than NTSC 28). Additional cells made it possible to avoid large black bars at the top and bottom of the screen. However, this was a significant burden for the developer, and it seems like they never really steamed on this subject.
To add fuel to the fire, early games on MegaDrive, such as Sonic The Hedgehog, worked 17% slower on European consoles (even music was slower). Developers in Japan and the United States did not follow best practices and believed that the VBLANK signal used to measure time was triggered every 16 ms. Since PAL is updated at a frequency of 50 Hz, and NTSC is updated at a frequency of 60 Hz, VBLANK in Europe is triggered every 20 ms, not 16.
Another World on Genesis
The Genesis port is the first port in this series that was not made by Delphine Software. Interplay has taken care of many ports besides Genesis, including the Macintosh, Super Nintendo, and even Apple IIGS.
The task of porting to Sega fell on Michael Burton, and Rebecca Heinemann took care of three other platforms.Since Genesis is based on 68,000, most of the code from the Atari ST version could be reused to implement the virtual machine.
For the North American release, Interplay was concerned that customers would confuse the game with the TV series  . The game has been renamed Out Of This World. It's funny that the series called Out Of This World was released in 1991  , but it was too late to change the name of the game again.
Interplay was also concerned that the game packaging was too beautiful, so they fixed the bug.
Michael did not immediately respond to inquiries by e-mail, so the rest of this article is based on observations made with GenS and Exodus emulators, as well as the results of disassembly.
Genesis Software Guide  is a miracle that even contains thoroughly documented DMA timings. Having studied it, Fabien hoped to see that VDP is widely used, as it stands out for the two things that Another World needs most.
First of all, a huge amount of VRAM is needed. Placing all four 320x200 framebuffers in VRAM is too much for 64K. This was not the end, as the frame buffer could be packed and the resolution reduced to reduce video memory consumption.
Secondly, DMA FILL write operations are performed with 16-bit granularity, which is fast, but when a separate nibble was required, reading from VRAM with VDP registers, setting a mask, and writing back would reduce the frame rate.
Finally, the cell layer is incompatible with the way DMA FILL works. For Another World, it is necessary to write long lines of pixels, but the line is divided into two words (4 bytes) in increments of 28 bytes. Since DMA FILL does not have a step, this would require a lot of requests, and the overhead would kill the frame rate.
This impossible design was confirmed by tracking VDP registers # 17  in the Exodus emulator, which showed that DMA COPY and DMA FILL never not used.
Another World Architecture on Genesis
Unable to build a VDP-based rendering engine in his VRAM, Another World went the hard way for 68,000, similar to what we saw on Atari ST.
Three frame buffers, two BKGDs and a “working” buffer are stored in RAM. There 68000 performs all the rendering and copying operations.
Once the frame is completed, it is written by DMA to an unused double buffer in VRAM. On the next VBLANK, the “active" VRAM buffer flips.
All layers are disabled except for Scroll A, according to Gens. The original Scroll A changes depending on which of the double buffers was last written.
Compared to Atari ST, the only optimization seems to be the implementation of COPY, which now uses the movem instruction. The performance gain is unclear (5%?).
There are no frame buffers for rendering in VAM VRAM, but there is a way around this by covering the entire screen with Cells and translating the screen space coordinates into cell coordinates.
For the pixel perfect port, you can use H40 mode to get a resolution of 320x224 pixels.Removing three lines of Cells would result in a resolution of 320x200, which was necessary.
At 320x200, the frame buffer will have a size of 320 * 300/2=32,000 bytes. If we look at the VDP DMA bandwidth  , then we will see that for the NTSC system it will take 32000/11556=2.7 frames, and on a PAL system 32000/21654=1.4 frames.
Note: Note that the PAL system is superior to NTSC when it comes to transferring from RAM to VRAM. That is why most demo groups work with PAL MegaDrive instead of NTSC Genesis.
If you look at the diagram and take into account the game logic of the virtual machine and the rendering of polygons on top of the transfer from RAM to VRAM, we will see that the game will produce only 12-15 frames per second on NTSC, which was unacceptable.
To reduce the load on the bandwidth, VDP is installed in the "H32" mode with a resolution of 32x28. Some columns and rows are configured to use the Black Cell and are never used again. These extra black cells further reduce resolution and also keep the aspect ratio of 1.3.
Only 28x22 Cells are actively rendered, which gives a resolution of 224x176 and a frame buffer of 224 * 176/2=19.712 bytes.
This lower resolution accelerated the execution of opcodes for copying, filling, and rendering polygons, and also reduced the cost of transferring from RAM to VRAM. In the NTSC system, 19,712/9702=2 skipped frames. Add another one for rendering/copying/filling, and you will get 15-12 frames per second, which seems to be confirmed by real frames  .
In the PAL system, the transmission cost is 19712/17913=1.1 frames. This probably led to skipping 2 vsync and a better frame rate than on NTSC, close to 16-12fps.
Notice the extra facial features and how Lester looks more worried. Clipping is visible below (Leicester's right hand). The difference in color depth is noticeable, but this is not a problem.
Talk about color
Something that might interest you earlier in describing the video system - VDP supports transparency for each pixel. This is achieved by the fact that the zero color index on all layers is considered as transparent. This effectively reduces the number of colors available per layer to 15. But Another World needs 16. This is a problem.
Fabien imagined the decision to use Plane B and fill it with a repeating cell with color index 0x01. When loading the palette, color 0 from plane A is also copied to the palette of plane B at index 0x01. Then playback can continue as usual. Since plane B is behind plane A, any color set to 0x0 will instead be set to 0x1 of plane B.
But it turned out that none of this was needed. Running the game on Exodus and looking at the palettes in real time, Fabien noticed that all the palettes use the same black color with index 0. All that the developer had to do was set BACKGROUND COLOR (the color that is used when all layers transparent) black and do away with it.
It was, without a doubt, the most difficult of the ports studied. Despite the powerful processor and VDP, MegaDrive seemed to sag during the RAM/VRAM transmission, which, frankly, was never designed for full-screen output.
Perhaps something could be done with the Cell caching system to transmit only dirty data, to reduce the amount of data transferred, but most likely, the developer was simply not given enough time for the port.
The lower resolution is not particularly noticeable, but cells intentionally left black added stripes. In NTSC, this was not a big problem, but on a PAL TV, the black frame buffer cells added even more to the “natural” black bars.
Were the players of that time soaring about this? Hardly. StarFox on SNES has the same frame rate/extra black bars, but it is still remembered as a great game. Fabien believes that this is true for Out of This World/Another world on Genesis/MegaDrive.
- Wikipedia: Sega Genesis, Launch .
- Sales Mega Drive .
- Genesis Software Manual: VDP 315-5313 .
- There are many tricks for displaying more colors, such as changing the palette in HBLANK or streaming colors in BACKGROUND REGISTER, but they are not relevant here.
- VDP, name tables .
- VDP, sprite table
- Another world (television series, 1964) .
- Fantastic girl (television series 1981) .
- Genesis Software Manual. .
- VDP DMA FILL .
- VDP DMA COPY .
- VDP Registers 0x17 .
- segaretro.org, MegaDrive DMA Bandwidth .
- Out of This World on US Model 2 Sega Genesis through S-Video .