NES Games & State Machines

A couple of years ago gamedev channel NesHacker did a video on how everything in your typical NES game is really a pile of state machines, concurrent ones, nested ones, bunches and bunches of them. If you have any interest in NES coding at all, it’s worth a look. (8½ minutes)

The chief difference between normal, sequential programming and game programming is that most video games have to make a framerate target, and have to split their processes between frames. Lots of little things are usually happening concurrently, and you can’t rely on normal program flow to keep track of things. Instead, each of those little processes has to remember what it’s doing between frames, and that memory takes the form of state machines, reminders of what each routine is in the middle of doing.

Drawing it out with circles like in this video I think makes it seem a bit more complicated than it actually is, but it does require a different way of thinking about your code than you may be used to in other programming disciplines.

Wherefore Commando’s Jank?

Displaced Gamers’ Behind the Code series is back, with an under-the-hood look at another NES Capcom game, following their examinations of Ghosts & Goblins and Strider, links are to our previous pointers to their peerless product.

G&G was implemented by popular early NES anonymous developer and target of player recrimination Micronics, but Commando can’t use them as an excuse, as it was developed in-house at Capcom. They were still learning the ropes of the NES at the time (Strider has no such excuse), and it shows. Displaced Gamers thinks that the game was shipped while the programmers were still working on optimizing it. As they do sometimes, DG implemented their own optimizations, improving the game substantially. You can see the product of their work in a 31-minute video they made about it, here. There is a substantial amount of 6502 assembly code involved, but if you skip around I think you might be able to get the gist of why the glitches happen, and how Displaced Gamers fixes them.

As was often the case with your jankier NES games, the scroll stutters and character chaos were caused by the game failing to make its VBLANK timing targets. Thing is, despite the glitches, NES Commando is arguably the best version of the game! Characters sometimes disappear from the screen and backgrounds turn into garbage, but there’s so many cool secrets and things to find in it that I can forgive Capcom for it.

Note that Displaced Gamers doesn’t release patches with their fixes, preferring to focus on making videos. Their code is presented on-screen though, so it’s possible for others to insert the changed programming on their own. I hope someone does this soon, as a fixed version of NES Commando would be nice to play.

A Deep Dive into ASCII Image Rendering

Via Kottke on Mastodon.* Alex Harri wrote an image-to-ASCII renderer that can translate generated 3D models in realtime, and on this page they explain how it works and some of the finer points of that conversion, specifically how not to make the rendered images seem blurry, instead giving edges clean outlines. It’s worth a look even if you’re not a programmer, and just want to see how the process is done. While it does descend into pretty heavy math later on, it starts out pretty approachable, and has interactive demonstrations throughout.

Image
Render captured from the interactive toy on the linked site.

* Bluesky has a lot more users, but Mastodon is used by a good number of highly interested and knowledgeable people, especially people who care about the health of the web, although that’s also because I follow a lot of people like that on Mastodon. Overall I find it a good idea to read both.

Retro Game Coders

This is a pretty nifty website that covers a variety of retro-coding topics. Here I link to three recent posts.

#1: CP/M working in a browser

I’ve mentioned before my fondness for CP/M, the first widely-used microcomputer OS, the DOS-before-DOS. My attempts to try to emulate machines using it, however, have mostly gotten snagged on one thing or another. Well they have a post about getting in-browser CP/M working, with information on some of its commands. Here you can run it yourself,

Image

People familiar with MS-DOS should be right at home, although some commands are different. (That’s because MS-DOS changed them; it was originally made as a CP/M clone.) One major difference is the absence, in this version, of disk directories. Instead there were up to 16 numbered “user areas,” each its own individual region on the disk, kept separate from the others. CP/M was an amazingly compact system, a single floppy disk could host a half-dozen compilers and have room to spare.

#2: Speeding Up PETSCII

Commodore BASIC was notoriously slow, but also feature-poor. A version of the same Microsoft BASIC that was co-written by Bill Gates himself, and was later ported to MS-DOS as QuickBasic. This page is a collection of different ways to speed up printing PETSCII characters, covering several optimization techniques, one of them, avoiding IF statements, being non-obvious.

#3 Online Retro IDE

Image

The linked page is actually about a recent update for it that adds support for DOSBox and BBC BASIC. It supports loading your code directly into a Javascript emulator. It supports many other computers and consoles. The IDE itself is here. The update page claims that FreeDOS is available as a platform, and with it another runnable version of Rogue, but I couldn’t figure out how to get into it before posting.

Games From Scratch’s Recommended Free Tools

Games From Scratch is a prolific Youtube channel dedicated to helping solo and small team gamedevs with tutorials and tools. They really do post frequently, so if I linked to everything they made it’d overwhelm the blog, but it’s been a while since I referred to them, and they just made a nice omnibus video of free tools. There is a sponsored section in it, but if that kind of thing bothers you I suggest using the browser extension SponsorBlock, which shows time-wasting sections on the Youtube timeline in different colors.

Here is the video (13 minutes):

Here are the tools recommended, along with links (which the video maker neglected to provide):

Blender (3D modelling)
Godot (game engine)
O3DE (game engine)
Krita (raster art)
GNU Image Manipulation Program (raster art)
Audacity (audio editing)
Tiled (map creation)
Inkscape (vector art)
Pixelorama (pixel art & animation, can be run in browser)
DPaint.JS (pixel art, in-browser, recreation of Deluxe Paint for Amiga)
GraphicsGale (pixel art)
Material Maker (procedural texture creation)
Ucupaint (texture painting extension to Blender)
MagicaVoxel (voxel-based painting, Windows & Mac only)
SculptGL (browser-based sculpting)
LDtk (2D level editor)

Polygon Treehouse’s “No AI” Seal

Indie studio Polygon Treehouse (which doesn’t seem related to the news site Polygon) has created a seal for indie devs to use to indicate that no AI-generated assets were used in the construction of their game. This is it:

Image
Polygon Treehouse’s NO GEN AI seal.

Generative AI is a blight upon all the creative industries, but few are affected as keenly as small team game development, which is under constant pressure to produce, and as easily and cheaply as possible.

There is an animus among the clueless game-buying public against “asset flips,” games that use premade resources made by others and obtained in packs or bundles. If I might speak directly to people who do this, ahem:

While you can find egregious examples, sure, generally this attitude harms a lot of indie devs, who often don’t have the personpower or energy to create large amounts of assets themselves. If you’re going to be upset at people who use cheaply-acquired material, then aim your ire toward people who use generative AI, which isn’t sustainable, and cribs off the websites of literally millions of internet users who didn’t consent to their use in its training.

And if, deep in your musty heart, you’re mumbling to yourself that they’re doing this for publicity: sure! I’m glad! Why not? What else can they do to make people aware of this issue, other than not using generative AI themselves? The real power to change things is in the hands of the people who use gen AI (which, if they are, have already indicated they don’t care about the issues involved) and those of consumers who have the option to buy games from them. Which is you. So, don’t do that!

Eschew the generative AI trend! Help prevent a future full of content slop! Don’t roll over and accept it! Tell the awful moneymen of the field this is wrong! (Not all, but so many of them are men.) And don’t forget about your stance the moment a game in a series you really like uses it for assets. This is about something bigger than games-yes, such things exist. Open your damned eyes. Things are moving around you, and they’re making the world worse, for artists, for you, for everyone. You don’t have to accept it.

And tell others! You don’t have to become loud and annoying about it. (Unless you really want to, join our team!) A quiet word of support, a positive comment on a thread, in the aggregate it can make a difference, but only if lots of people do it.

There, that’s said. Don’t forget now! I don’t bring up these issues often here, there are so many other fun and interesting things to show you. We’ll move on, for now….

Displaced Gamers Reprograms Ghosts & Goblins to Overcome Jankiness

Displaced Gamers is one of the best NES gaming channels on Youtube. They do sterling work diving into the very code of the games, to figure out what they are like they are. We link to nearly every video they do. Here’s a recap:

Well here’s another, and it actually is a follow-up to a video that I don’t think we linked to before. So here’s that video first, on Micronics’ port of Ghosts n’ Goblins to NES. (32 minutes)

Pretty long already, exquisitely geeky! Well its successor is even more geeky, as they actually reprogrammed the game to have a more optimized sprite engine. Although it’s a shorter video, at 24 minutes!

Ghost n’ Goblins is designed around being a 20fps game, so no amount of optimization will change that, it requires more substantial modification. But the time visualizations they use indicate that it may be possible to change that to 30fps, and with other changes 60fps may be possible. Mind you, the logic for the player, enemies and weapons all assume 20fps, so unless they’re changed to account moving to 60 frames per second will triple the speed of the game, so that obviously would need to be changed as well. I look forward to seeing the next chapter in this retrocoding saga.

GB Studio & BB Studio

GB Studio, by Chris Maltby, is fairly well-known now, isn’t it? It’s a free and open source solution to fairly easily making Gameboy roms on your own, that are properly termed not romhacks but homebrew. It has its own website and it’s available on itch.io. It was what Grimace’s Birthday, which we linked to last year, was made with.

Image
GB Studio, from its platformer template

Now there’s a heavily-modified version of GB Studio, called BB Studio, that produces NES roms in a similar manner! It’s made by Michel Iwaniec, and can be gotten from Github here. It’s recommended that you be familiar with GB Studio first, and to read the list of caveats on the page. Particularly, the NES supports fewer sprites per scanline than the Gameboy hardware does, and runs at a slower clock speed. BB Studio is also “early alpha software,” meaning, it might or might not work well for you at the moment.

While we’re on the topic I should also mention NES Maker, which isn’t free, but it also isn’t “early alpha software,” and at $36 isn’t expensive either, and is custom-built for generating runnable NES games.

Score Keeping on the NES

Sometimes I feel like I should put a content warning here when the technical level of a post is higher than usual. This one would probably be a five out of five for geekery. It’s a video from NESHacker on counting score on the Nintendo Entertainment System. But I don’t want to discourage you from watching it! It’s nine minutes long, and it contains a definition of the term double dabble.

Human-readable numbers are tracked by computers in a number of different ways. Nowadays we basically just do a printf or some version of it, but on a 1 megahertz platform, optimization really matters. It’s easy to think of computers as being impossibly fast, but in truth speed only ever counts relative to the efficiency of the algorithm you use. Computers are fast, but they aren’t all that fast.

One of the big tradeoffs in processor design is, fewer complex instructions that do a lot but take a lot of cycles, and processor complexity, to execute, or many simple instructions, each doing little and being relatively simple, and not needing a complex processor design to implement.

The 6502 microprocessor generally follows the latter design philosophy. It made some important tradeoffs to keep costs down. For example, it doesn’t have hardware that can multiply arbitrary numbers together. It relies on the programmer, or else a library author, to use the instructions given to code their own multiplication algorithm, if they need one. The result is going to be slower, probably, that if the chip had the circuits to do this automatically in silicon, but it reduced the cost of the chip, basically allowing more to be made, or else increasing the profits for the manufacturer.

Personally I’m a fan of just storing the score as a series of digits that match up to their positions in the character set. Gain 1,000 points? Just bump the 1000s-place up by one, and if it goes past 9, subtract 10 and bump the 10,000s place. That’s a tried-and-true system that many games use, and works well if all you ever have to do is add numbers. Comparing values, like for detecting extra life award levels, make things slightly more complex, but not by much. There’s sometimes other factors involved though, and that may explain why Super Mario Bros. uses different systems for its counters, as explained by NESHacker.

The End of Masahiro Sakurai on Creating Games

He mentions that it’s possible that he might dust off the channel from time to time, but that he feels it has accomplished its mission. Here it is (46 minutes):

To remind everyone: Sakurai is the famed creator of Kirby, Meteos and Smash Bros. In the video, he relates the surprising fact that no only did he write out nearly every script, 256 in all, before the first episode even aired, but he also filmed them all in advance too! That’s why he looks older in this video: it’s the first time he’s been before the camera, with just three exceptions, since it started. The video, in fact, is mostly about how the series itself was made, which as it turns out was done without a camera crew, and in a residence of his too, outside of a recording studio and without soundproofing, so production had to pause if am ambulance drove by outside, and couldn’t happen at all if it was raining.

I have no doubt that these videos will be an important document in the coming years, not just as a guide to making video games, but also preserving the processes of current-day game development, and the words and thoughts off one of the foremost game designers of our age. BTW, note the split second of Rogue at 18:58!

The video has always had a feel like maybe Nintendo was helping out with it, but as it turns out, other than approving the use of their game footage, they weren’t greatly involved. The similar feel may be due to the use to HIKE, a.k.a. QBIST, a production company that Nintendo also uses for some of their videos.

To close this out, I’ll link a short bit from earlier on, at a mere 2 1/2 minutes, the video about Sakurai’s cat, Fukurashi. Meow, or perhaps, nya!

Ed Logg on Creating Gauntet

Recently I’ve been working on a getting-started guide on what I think is one of the most interesting games in UFO 50, Pilot Quest. (Other games I’ve really enjoyed, though I’ve by no means tried every game in the collection yet: Magic Garden, Waldorf’s Journey, Planet Zoldath, Attactics, Kick Club, Onion Delivery, Porgy, Valbrace, Grimstone and Mini & Max.)

Guides take time, so in the meantime here’s an hour-long talk by Ed Logg on the creation of Gauntlet, from GDC 2012!