Faster Mode-X Sprite Rendering
Back in June, I made a sprite rendering system for DOS/VGA Mode-X. Running it on a pcem 386 showed that the sprite clipping code was hella slow.
So I decided to rip out the clipping code. To allow sprites to overlap the screen boundary, I set up the VGA display registers to have a 32px off-screen border around the display.
The system still splits the sprite into separate planes, and it still works by skipping some pixels then drawing some.
It works across a scanline (within a single plane) so I can use rep movsb. It also hard-codes the scanline width into the number of pixel bytes to skip - that's so I don't have to multiply the display width by the number of scan-lines to skip. That means my game can only run in a single screen resolution, but it's only going to run in Mode-X so that's not a problem.
Another tweak is that as much as possible, it loads 16-bits of data at a time. This should make better use of the bus, which can be an issue with the 386SX.
The command buffer format:
- number of skip/draw pairs (word) - used as a loop counter
- for each skip/draw pair:
- numToSkip/numToDraw (word)
- top 3 bits are numToDraw-1 (min 1, max 8)
- bottom 13 bits are numToSkip (can include multiple scan-lines)
- numToDraw * pixel bytes
- 0 or 1 bytes to pad to 2-byte boundary
The asm code to render a plane is this:
Comments
Post a Comment