Thursday, May 18, 2017

Direct Memory Access

DMA is a feature that allows the VDP to very quickly copy a large amount of data to an arbitrary location in VRAM. It is the method by which the sprite and background tables are written to VRAM every frame, but it can just as well be used to dynamically load tiles.


One of the main uses of DMA in Sonic games is to load the main character graphics as they're needed. Since only one of Sonic's sprites is ever visible at a time, new tiles can be loaded over the old ones, saving VRAM. Special Stage rings temporarily overwrite other graphics when they appear; using DMA minimizes the number of affected tiles.

DMA is also used to animate the background planes. By periodically writing new tiles over specific regions of the main level art, static elements such as the plants in Angel Island Zone and the mesh cylinders in Flying Battery Zone can be made to move. The same principle is used to achieve the extra background layer trick we previously saw.


One drawback of using DMA is that the source tile data must be uncompressed, which takes up a lot of storage space. As an example, Knuckles' sprites alone take up a whopping 1/16 of the 2 megabyte Sonic & Knuckles cartridge. In fact, uncompressed art takes up almost 20% of the combined S3&K ROM!

The rolling jump Bonus Stage is pretty smart about this. The graphics for its complex animated background are actually compressed within the ROM, but the game first decompresses them to 68k RAM, from where they can then be DMA'd to the appropriate location in VRAM.

5 comments:

  1. The player character graphics are loaded this way, but I assume the numbers in the HUD are loaded the same way, since there are videos where debug glitches and other things cause the graphics to become garbled but yet the numbers in the time look fine the very next second...

    ReplyDelete
    Replies
    1. Yes! HUD numerals do in fact use DMA, but on a surprising note, level result numerals do *not*! Instead, all 10 digits are decompressed from a Kos archive at the start of the results sequence, and then the results object puts a bunch of sprites together to draw the long score counts.

      Delete
    2. That's an interesting inconsistency. I wonder why SEGA didn't just do that with the HUD counters. Storing the ten numbers shouldn't take up too much RAM and would reduce having to constantly load from the cartridge.

      (I don't know if that slowly damages it or not, but I guess SEGA wouldn't do something that would affect their own cartridges or console badly.)

      Delete
    3. They did that to avoid hitting the sprite limit. Seven score digits would be seven sprites lined up horizontally, but with DMA they can get away with just three sprites for the entire SCOR E123 4567 string.

      What's puzzling is why they didn't do that with the result counters. Even with both bonuses at 50000, that's still 10 digits, so it wasn't due to VRAM limitations. (Yes, I am aware of the 100000 time bonus but I hardly think that would be the catalyst for such a decision.)

      Delete
  2. sonic 3 air game is so POPULAR

    ReplyDelete