Abandoned! Yes No Maybe... no!

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Andrew Davie

This morning I was thinking a bit more about what has to happen in a Lemmings game. One of those hard-to-do things is how to allow modifications of background, but more specifically how to remember the stuff that's started onscreen, scrolls offscreen, and then at some later point scrolls onscreen again.

Because of memory limitiations, this version only keeps the visible screen in RAM.  That is, a grid of "characters". Each character is 5 pixels wide and 30 scanlines high (10 trixels). That means that the screen itself requires 8 (horizontal) x 7 (vertical) characters in RAM (each character referenced by a byte character number).  So, that's 56 bytes of RAM for the screen.

Now, as we scroll, those 56 bytes are refreshed from the ROM.  Specifically, a background appears as (effectively) a much larger x,y matrix of character numbers. ROM is relatively cheap - at least compared to RAM, so it's fine to copy the 'visible area' into the RAM screen character grid every frame. To allow fine-scrolling, there's a spare character horizontally and vertically that lets us do the fine pixel scroll rather than blocky character scroll.

However, when (say) a Lemming starts digging, then that character in the whole level sense is modified. The ROM data is no longer correct - it needs to be a different shape than what the ROM says is there. But we don't have stuff in RAM (except the visible screen). So, when the modified character (say, a hole being dug) scrolls offscreen, it's gone - the next time we scroll back we get the character from the ROM and it's not a hole anymore.

This had me kinda stumped for a bit - and I figured there's no way I'd have the RAM to keep a complete copy of the whole level in. Boulder Dash and other games using that engine had a predefined 40 x 22 RAM grid; and so modifications somehwere on that grid would always be available.  But Lemmings uses a much larger virtual world - way bigger than we have RAM for.

Then I realised - there aren't actually all that many things that happen on a level. Yes, the lemmings do stuff and modify their surroundings. But not a lot. They might dig a hole or two. Or even a few score holes. But their effects upon the world are minmal, compared to the total level/world size.

So I got to thinking - if I kept a separate list of "modifications" to the world (i.e., "a hole here", "a ramp there"), then I could slot in a "draw the modifications" step just after the grid for the visible screen is copied from ROM to RAM. It's effectively a slap-the-modifications-on-top post-process of the screen buffer fill.  It should work just fine, and actually use minimal RAM.  And not a huge amount of CPU.

So I went from, this morning, "OK that's a showstopper, I'm going to stop the project".... to "Ah! I can fix that, let's keep going!".  So, project is still going and I'll have some fun implementing the above-described solution to modifications to the background "sticking around" when they're offscreen.

Andrew Davie

The fundamentals of this system are now installed and working.
The numbered "blocks" that appear over the background are "modification overlays" to the ROM data drawn onscreen. Think of one of those blocks as a hole being dug. The numbers just indicate different frames of animation (=characters). I can put anything there I want, in an animation sequence or static. They persist even though we are actually retrieving the screen background from a ROM matrix instead of RAM.

Well, actually... a bit of both. It's RAM when it's visible, but anything that goes offscreen is lost permanently from RAM and needs to be rebuilt from the ROM matrix. That's why I've added the modification overlays; those are things that must persist even though the screen buffer is completely lost. These are stored elsewhere and placed back in the screen buffer just after the copy is made from ROM.

It will work well in the game.


Bomberman94

Cool that you found a solution for ,,how to remember the out of screen stuff". And: you catched the background graphics and colors better than I expected! Looks promising - excited to see how to deal with the big(ger) lemmings.