This code was used in the final version of the firmware and unlike my state machine based attempt, it is incredibly compact taking only 71 words in program memory (for comparison, that's about 0.9%). As it happens, I wasn't short of memory because I'd deliberately chosen the biggest device in that family, but I wanted to keep the code small so I could use the smallest device in production, thus maximizing profit (memory costs in these devices). The final firmware took a little over 1000 program words meaning I could use the 2K device. You could argue that maybe I should have stuck with my state-machine driven attempt, but it was the first thing I wrote because I needed feedback straight away, the thought of spending over 300 words just driving the LED made me panic a little... if the LED driver is that big, how big is the rest of it going to be?

I'm sure you're wondering what has this got to do with Pascal or developing games?
Well, the article isn't really about the code (although there is an explanation of that little block of C), it's more about thinking outside the box on things like this. Ask yourself... Do I really need a scripting engine? Can I do this without that complexity? Is there a simpler way of doing this?
If you want a visual indicator in game that has simple things to indicate, can you do it simply with this sort of approach? For the PC it's even better as we have 32 and 64 bit numbers, I only had 8 bits to play with. We also have much bigger chunks of memory knocking around that we can use for storing our 'programs'.
As I say, this isn't really about Pascal or games, and I'd go as fas as to say it's not really a tutorial, just a little story that one day may help you think outside the box and solve a problem using a method that is nice, clean and simple.
vBulletin Message