Monday, May 14, 2018

Making NEXT Lemmings: Part 3

Now that I knew things were actually possible, it was time to start thinking about the levels themselves. I started reading up on the level format, a text file by someone called "rt"... (Thank you whoever that is!!)

                    BY rt

document revision 0.0

thanks to TalveSturges for the original alt.lemmings posting which got me
started on decoding the .lvl format

if you liked lemmings you should give CLONES a try. go to
for more information. 

this document will explain how to interpret the lemmings .lvl level
file for the windows version of lemmings (directly saved levels in LemEdit).

This document is also on my Github repository.

As it happens, I was flying off to LA for a holiday with my daughter, so an 11 hour flight was just the thing I needed to blitz this chunk of code...

I first converted and exported the level brush .SPR files into a large set of sprite banks, with a table at the start that held start addresses, banks, widths and heights, followed by bitmap data. Once I had this, I was able to start writing a "level bob" routine, something that would draw these into my 1600x160 level bitmap (which is the size of a level in Lemmings - 5x320x160 screens).

This immediately turned nasty, as working out the "Y" coordinate was horrible - this was before the MUL instruction appeared. I created a large "line" table that held the address of each line and the bank it started in, and started to use that to index down into the level.

This was "okay", but it was ugly... and the table wasn't exactly small either. It also had a problem that a single line could cross a bank, which wouldn't do at all. I could get round this by not filling the last 384 bytes of each 16K bank, but still....

So, I decided to scrap all this, and burn some of this lovely new memory the NEXT had. I change the background level bitmap into a 2048x160 screen, burning an extra 70K+ of RAM. However... this now meant that the line addresses was just the Y coordinate shifted a couple of times and stuck in H (of HL), and the base of the bank ($C000) added on. It also meant that by banking in 16K at a time, if bit 6 of H reset to 0, I needed to swap bank. This was much nicer...

Doing the basic draw routine was fairly simple, I just had to clip top and bottom. I decided (one again) to cheat like mad and not actually clip things. As this was just being used at level creation time, I simply looked at the Y coordinate, and if it was off screen i didn't draw it, and moved onto the next one. Ideally you'd work out how much you need to clip and only draw that, but for this case, performance wasn't the number one goal, so i though "Sod it".

I also realised with my longer level, I didn't actually have to clip on X either, i could just start drawing 16 pixels further on. That was fortunate. .

With a simple draw blob in place, I looped through all the brushes to draw, and built the screen.

For a first version, this was pretty good I though. You can see what it's supposed to be, and looked pretty close to the actual level. It wasn't perfect though. Lemmings background brushes can have a few special draw modes: Flip on Y, Behind and Remove. Each of these modes can be combined giving 8 different draw modes in total.

While on the Las Vegas leg of our trip I finished off the level loading and added the missing modes...

It took me a while to figure out what was wrong with the image that has the corruption, especially as it was the correct shape - very odd. But turns out the brush I was drawing from was overflowing the bank it was in, so I'd need to do a check on exporting to make sure each line of the sprite is inside the same bank. I can't make the whole sprite fit, as the brushes can get really quite large and won't fit. I've yet to fix this bug... but I'll get around to it one day.

As you can see, I'd gotten most levels now loading fine. After this, I set about actually finishing off the export of all the lemmings as code that I could call, and actually use

This took a little longer than I expected. I had to make sure the generated code wasn't going to cross a bank, and make the offset table that went before it all. But once I finally got it all together, I was able to flick through the different graphics inside the game (above).

It was getting to the point i wanted to have the objects in the level. This was really the last major item missing, not just in terms of level components, but that would show me how fast things would run. Lots of the levels have a load of objects, and they would take up a lot of rendering time, so I really needed to see if it would still be fast enough once I added them.

I managed to get the sprites exported okay, but the colours just weren't right. I ended up having to load new palette files, one for each style and convert them into the NEXT RRRGGGBB format. once I had that, exporting the objects was just the same as the level brushes.

Once I'd exported this, i suddenly remembered those arrows.... damn it. They appear "inside" the background, so this meant I wouldn't be able to use the LDIX instruction, but have to do it long hand. Worse yet, there was always lots of these on a level, meaning I'd have to draw loads of these objects using very slow code.... Bugger.  Well, that was one I would look to address later.

With objects I needed "standard" sprite rendering code as the objects must be clipped right/left and top/bottom, and they have similar drawing modes to the background - normal, behind and inside.
In this case, I opted for a tower of LDIX instructions, and then jumped into the middle of them depending on how many pixels on X I was drawing. I then looped around this on Y, checking for bank swapping as I went. This give me this image below....

After how fast I got the Lemming rendering, I was a little disappointed at the speed of this, especially as I know there are levels with water all over the place. damn. It wasn't the end of the world, but it may well be the beginning of the end.... Each sprite in this case takes about it's own height to render, and if I have several on screen at once, that's easily going to chew up a frame or so.

Still, I knew I still had some tricks up my sleeves so I cracked on. To give me a little break and some thinking time, I decided to start drawing the Lemming font. Time away from actual code is important, as it gives your mind time to chew over some problems. Most coders I know will come up with solutions to things at the funniest times; In the shower, having a poo, out for a walk - all of them away from the computer.

I used the image editor in GameMaker Studio 2, as it's a great pixel editor, and very like D-Paint ( can't for the life of me think why! ).

The Amiga font was 16x8, but due to the smaller screen, I decided to reduce it down to just 8x8. This works pretty well, and as you can see I've "mostly" managed to keep the feel of the original.

I've still to do the numbers, but this gave me a welcome break and let me know i was on a good track for my screen layouts.


Neil said...

"Most coders I know will come up with solutions to things at the funniest times"

Fortunately my wife is forgiving. SQL and sex is a combination that shouldn't be attempted too often.

Many years ago, the woman I was dating came around right in the middle of a hugely complex program I was struggling with, but making great headway (this was at my apartment, fortunately). Several minutes later, I had to make the intensely unappealing choice of continuing with the code or paying attention to nude girlfriend. I chose girlfriend, and the code quality seemed better afterwards, too.

Unknown said...

About those sprite drawings... did take a quick peek at Amiga longplay youtube video, and indeed, some levels contain large portion of arrows+water, may get tricky.

Depending on how hard you are going after Amiga-fidelity, I've few dirty ideas what you may try if you give up on perfect port.

Water and arrows and other objects:

- get some "NEXT" artist (or old-school DOS 256 indexed colour one) and make him/her draw the water (arrows too?) as static-pixel brushes being animated by palette rotation, instead of redrawing pixels. (colour cycling: ... with arrows something similar like this: )

- put ULA screen above layer2 and switch to low-res, draw water and/or arrows there, you can use X/Y LowRes offset registers for fast scroll and/or animation, but thinking about it a bit longer, it still doesn't sound fast enough, as it would require lot of extra cases/adjustments (I was thinking about the arrows animation mostly, and nope, no simple shortcut there). As the arrows are monochromatic, maybe it would make sense even to draw them in classic ZX screen, but still just pushing the new animation frame over 1/3 of screen + masking it to stay it "inside" background sounds very challenging, especially as you have to mask by the 256 colour bitmap, not bit data. This idea doesn't sound very good.

- Some animated objects may be resolved with sprites maybe (flamethrowers, torches, etc), not bothering with clipping manually and having rendering for "free" (but the above/under layer2 will cause issues, some sprites would be perfect fit for "above", some for "under", but "under" sounds more usable to me).

BTW, you can use layer2 hw scroll to shake the screen (+-1..2px) upon nuking them, or single boom? Feels so good in many games.

About burning RAM: that bitmap ram is still available for other things, you can store sprite graphics there or other data, it's almost 400B every chunk (not that bad even as continuous block), plus if you put there sprite data like font/etc at +2048 lines, it may fit OK-ish. The banking will be somewhat PITA, it's only 8 lines per 16k bank, but I still think you can salvage quite some of those 70k.

Mike said...

Colour cycling won't work, as it'll leave black shapes on screen. On top of that, it'll remove colours needed for the game itself (RRRGGGBB)

The ULA screen would be slower to work with, and I'd still need to check the Layer2 in order to put it inside.
As to using LowRes, I don't want to have anything in block res, I want it to look as good as the Amiga one.

Yeah... i did think of this, But they'd have to be behind the Lemmings, and in front of layer 2, which you can't do.

yeah... I can do. but need the game done first :)

I've plenty memory left (it's a 2Mb game). I'm not fussed about 1Mb. It's such a cheap upgrade, I don't see any reason not to have it - same as Amiga users did. hardly anyone had a 512K Amiga

I'll probably end up doing auto generated "arrows" so they draw as quickly as possible.

Unknown said...

What do you mean by colour cycling leaving black shapes on screen and need of colours?

ad need of colours: Amiga version was 32 colours I guess, wasn't it? So you have still about 224 free colours in the palette. You don't have to use index=RRRGGGBB palette layout, it's ordinary 256 element palette on NEXT and you can set each colour to anything you wish from the 9 bit RRRGGGBBB, I don't think Amiga-like lemmings graphic needs to use the index in "3:3:2 RGB" way, I would rather use indexed palette, which also then gives you the option to add some special effects by modifying palette real time, like fade in/out, etc.

ad black shapes: probably some misunderstanding, I meant to draw the liquid (water, etc) area and the arrows only once on the background (upon level load), so their position will be static (no animation of pixel data), and use the colour cycling in the palette definition to make it "animated" for the cheap price of setting only few palette items, not redrawing any pixel data anywhere. It would look completely different from Amiga, where the liquid surface is animated on pixel level a lot, far beyond what the palette animation may achieve, then again animating few lines of surface (usually like 256x4 at most in visible area) sounds somewhat doable, but it's the whole "body" of liquid to be redrawn each time which sounds to me as too much. Also the arrows would not move, only the colour cycling animation would be used to make them "alive", but on pixel level they would be drawn just once, upon generating the level bitmap - no black shapes anywhere.

About generating arrows: if you compile some "from->to per line" list of areas to cover with arrows, you can then crop that with viewport and draw the remaining areas with per-line code chunks, drawing single line of arrows is probably like doing few (1..8 times) `ld (hl),e` `inc l` and then `add hl,bc` with `bc=` instruction (oh, not even in NEXT extended set, that's a bit unfortunate), so the compiled way with 11T to write pixel (~14T per arrow pixel including the `add hl,bc` empty area skip) is probably optimal.

You can use sprites behind layer 2, if you keep "hole" in the layer2 bitmap, the grinders are for example always in black area, or above background somewhere? But it sounds like per-item decision + one would have to check all level definitions, if it will not break in one of them.

Unknown said...

the comment got a bit butchered by the wrong HTML tag removal, as I used stack-overflow way of writing comments, so some text was written like HTML tag, while not meant to be... ouch. Anyway, if you ever want some more details about particular idea or some code review, you can probably reply in facebook under that longer discussion in the older post, I will get notification quickly, and we can eventually establish other means of communication.

Ruby said...

I was very interested in the article , it’s quite inspiring I should admit. I like visiting your site since I always come across interesting articles like this one. Keep sharing! Regards. Read more about
Offshore software testing services
software testing services company
software testing services
Software Qa Services
quality assurance service providers
Performance testing services
Security testing services
software testing Companies

anand said...

nice post
Software Testing Training in Chennai | Certification | Online Courses

Software Testing Training in Chennai | Certification | Online Training Course | Software Testing Training in Bangalore | Certification | Online Training Course | Software Testing Training in Hyderabad | Certification | Online Training Course | Software Testing Training in Coimbatore | Certification | Online Training Course | Software Testing Training in Online | Certification | Online Training Course

sathya said...

I like visiting your site since I always come across interesting articles like this one.
Selenium Training in Chennai | Certification | Online Courses

selenium training in chennai

selenium training in chennai

selenium online training in chennai

selenium training in bangalore

selenium training in hyderabad

selenium training in coimbatore

selenium online training

Chad said...

Great!! Thank you for sharing this post on software testing. Software testing outsourcing services are in great demand these days. Good to see such nice articulated post.
Software testing companies in USA
Software testing companies in New York
Software testing company in India
Software testing services in USA
Software testing services company
Software testing services company in India

James David said...

Freelance maintenance technicians also benefit from establishing relationships with multiple clients. Working as a freelancer, you’ll gain employment experience with a variety of businesses, boosting your overall skill set and providing you with more work opportunities in the future.

maintenance technician

Verify Customer Identity said...

The requirement for id verification service is much greater these days. There are lots of id verification methods that anyone can get on a dependable site known as Trust Swiftly, and a company can implement the methods to safe their own ecommerce site effortlessly. By addressing this excellent site, you can grab more knowledge about id verification service.

lucifer1413 said...

Nice post! You are sharing amazing information through your blog. I am a big fan of your excellent writing skills. And for more information and technical Support services about
PayPal login | | activate |
Xfinity Login |
DirecTV login |
Zoom login
Cox login

PaypalLogin said...

Nice blog with full of information,Thanks for sharing with us.if you face any kind of trouble using Paypal Account click the link Paypal login and get resolved with your issue.

Unknown said...

This is very important Post, absolutely fantastic & very useful i really appreciate thanks for this Great Information. know about Paypal login Click the Link and Visit

Bella Johansson said...

My wife and I really enjoyed our time with this vehicle. We have a Harley trike back home but I have wanted to drive a Slingshot once. Lots of fun and my wife likes it better than our trike. Easy to rent and pick up. I recommend highly and hope to do it again. Thanks Sarasota slingshot rentals

Unknown said...

Are you facing login problems with your PayPal login account? If yes! Then refer to the solutions that are mentioned below. paypal prepaid log in
So, stay with us. We are a self-dependent technical help service provider for Computer and other devices related issues. Our experienced & certified experts are available 24*7 for you. Our technicians will be always there to help you.
If you are having trouble while using canon printer on your device and you have tried every solution to fix the issue, then the last thing you are left with is to uninstall and re-install the Canon Printer driver. So, in this article, we have clearly discussed how to uninstall the printer on a Mac. This will be followed by a discussion on the re-installation process that can be easily done via canon,com/ijsetup 5255 and drivers on each mobile device or computer you want to print from. Add the printer to the new device.
The streaming of video content online is trendy today as people move to modern entertainment. They subscribe to various streaming services like Netflix, Hulu, etc. Among other things, Amazon Prime is one such streaming service. This service not only allows you to stream videos but also allows you to utilise many other features. And this is all possible by getting and redeeming it. how to use amazon discount code and redeeming it.
However, to carry on with this process, you must be assured that it is not more than 7 days since you have aol sign in now. In case it is more than 7 days, then you will not be able to get your hands on those emails. Follow the simple procedure given below to offical
There are lots of secure services provided by Google that users can use whenever they use their account. But sometimes users also face numerous problems when trying to sign in to their Google account and forgetting the password is one of those. In this article, you will learn about the step-by-step process to Google Account Recovery.
However, there is one necessary that plays an important role here is that without having a Cash App account and without doing square cash app login, you will not be able to move ahead in the process. So, in today's post, we shall learn the ways to create as well as do cash app support.
You will need to locate the wps pin hp printer in order to connect to any other device.

Shiva said...

The information given above is really useful. Thanks a lot for providing all the information here. To know details on AOL mail service, visit us:
oreo tv for pc
thoptv for pc

Arlo Oops Director said...

When coupled with an Arlo base station, Arlo cameras do not require a subscription to operate and can save footage locally. If you pay for Arlo Smart, though, you'll receive more AI-powered motion detection choices, cloud storage, and customised motion zones.
For more info go to Arlo Customer Service

Link Roku Activation said...

To activate your Roku streaming device for free then you will need a Roku Account. There are two options to making your free Roku account through the Roku Com Link . To get those steps to contact the expert technicians anytime through the live chat process. Get in touch with us.

Unknown said...

Sign-in to your Roku with your Amazon username, password, or a code that you have received from Amazon. You will receive a code to enter when you register on The code will be automatically entered by the Roku channel to log you in to your account.

Unknown said...

We all noticed a dramatic shift in viewer preferences with the rise in OTT platforms. Movies have stopped going to the theaters due to the pandemic. They simply made it possible to access the OTT platforms from anywhere in the world. You can register, verify, and activate the MyTV app via to become one of the most well-known web show distributors.

news said...

I really like your post, I always like to read a quality content having accurate information regarding the subject. Thanks for sharing. It is such a very amazing post.


arlo login my account said...

Follow easy steps for my arlo login, arlo account sign in, reset password through arlo app. Fix arlo netgear login issues via
arlo login my account

Unknown said...

Users can stream the best online movies and shows via If a user does not have an account they will need to create one and complete the activation process. All users are advised to read this information regarding how to activate and create an account on
amazon code

Link Roku Activation said...

Link activation Roku is a team of experts that can help you to provide services to activate Roku streaming devices using the Roku com link enter code.
roku com link
afrikastv roku

Unknown said...

Google giftcard may be useful for purchasing a variety of services and products or in earning in-app purchases. Once you've redeemed your Google Play Donation Card is redeemed to your Google Account, then you can get programs, songs, novels, movies and a number of different activities from Google Play store.
google play redeem code

Link Roku Activation said...

Now get easy steps to activate Roku streaming device using the Roku com link enter code.
roku com link
afrikastv roku activate

Unknown said... is Amazon's paid subscription. It gives you unlimited access to many services, including fast delivery, unlimited streaming and exclusive deals. Unlimited streaming of TV shows and movies is available to Prime subscribers. Amazon Instant Video offers most of its content free of charge.Amazon Prime Membership.
primevideo/mytv check balance check balance

Emily Blunt said...

Very efficiently written information. It will be valuable to everyone who utilizes it, please Keep doing what you are doing and keep sharing amazing information like this, it means so much if you can checkout some of mine, Uphold Login | Uphold Login | Uphold Login | Ronin Wallet | Ronin Wallet | Ronin Wallet | Kucoin login | Kucoin login | Kucoin login

HP Printer Assistant said...

Thanks for Sharing with nice Information. If you are HP print and scan doctor windows 10 and Mac without any interruptions is a simple tool that connects, scans, finds, and fixes a connection problem, ink issue, etc. The program only functions with Microsoft .Make sure you follow the instructions carefully to avoid errors.

Rosi smith said...

Visit on the Coinbase sign-in page and type in the email and password. You'll be asked to complete the 2-step verification.
coinbase login
coinbase pro login
paypal login

ravi said...

thanks for sharing nice blog keep posting

Canon Setup said...

In the field of printing devices, the first and the most used brand in the United States is Canon provides some drivers for the so-called printing which makes the process easier and more familiar to the user. The steps of the installation are easy and simple. To install the drivers of canon one needs a canon printer and the cord joining the laptop or Pc. If the printer supports the wireless medium one can go with the Wi-Fi printing service. We have explained the steps from the beginning i.e. from the wired setup to the installation of the drivers in this article.
canon ij setup
Canon Printer WirelessSetup
Canon Printer Drivers
Canon MX492 Printer Setup

Unknown said...

IO Autoclicker.

Venkatesh said...

Gain great knowledge of IT for a better future. Get AWS Training in Chennai, the best software training institute from Infycle Technologies. Amazing software training institute and Placement centre in Chennai. And afford courses like Oracle, Java, Data Science, Big data, Python, Manual and Automation Testing, DevOps, Medical Coding, Power BI, Digital Marketing, Data Science, etc. With the excellence of training from best trainers for freshers, experience, and Tech professionals of any field. After the completion of the course, the student will be able to crack interviews from top MNC’s. For further enquiry approach us through 7504633633 / 7502633633 and get a free demo class.

youtubeactivity said...
To the start, Youtube Tv is simply restricted to some piece of the USA, in the wake of seeing its notoriety it is presently accessible in the majority of the nations all over the planet. Youtube is currently hoping to extend it considerably more. The principal purpose for the outcome of Youtube television is reasonableness with a tremendous rundown of premium Tv stations.
A membership to Youtube television can be purchased at $64.99 each month at the authority youtube site. Whenever you are finished with the membership you are all set, and from here onward you can observe any of your #1 shows whenever you need.

Monica said...

Thank you for this blog. I am glad after reading this article. It is very helpful to me. I hope you more article written on the same topic. ij start cannon here you can learn about canon printer's setup.

Let2know said...

I later this message,and that i wager that they having a laugh to log on this say,they shall proclamation you'll a satisfying web site to make a advocate,thank you for sharing it to me... Avast Secureline VPN License

trublogger said...

this is such a nice useful resource that you are supplying and also you meet the price of it away for forgive. I hero reward seeing Websites that take at the value of supplying a setting useful resource for set wandering. it's far the primeval what goes on the order of comes almost about recurring..... Grammarly Premium Crack

Cyberz Pc said...

thank you for taking the duration to proclamation this find the maintain for an opinion totally beneficial!.... Beautiful Happy Sunday