It looks like you are correct, it is possible for this variable to be uninitialized when this code reads it. However, it appears this only causes a small cosmetic difference in the first attract sequence after power on.
After the system is powered up, if you let it advance to the demo without inserting any coins...
- If the uninitialized state of this variable is not zero, the demo does not display the number of ships remaining in the bottom-left corner, and it remains missing for the rest of this attract sequence.
- If the uninitialized state of this variable happens to be zero, then it gets rewritten with the number of ships for one credit and the screen is updated to display the number of ships remaining in the bottom left corner, which remains on the screen during the rest of this attract sequence.
This uninitialized variable doesn't seem to affect normal gameplay:
- As soon as you insert coins and start a game, this ships remaining variable will get rewritten with the number of ships for one credit, so the actual game play proceeds correctly.
- Once you get a game over, this variable will be zero, so it seems like every other time the demo plays after the game has been played at least once after power on, this part of the code will always update the screen to display the normal starting amount of ships when the demo starts.
(The comment in this code snippet that says this variable "counts down between demos" appears to be incorrect. The RemoveShip routine appears to only get called if the variable was zero at this point in the code. This can only happen once each attract sequence.)
Testing method
I tested using MAME's debug mode to do things like catch when that address was written or read, and to change the value at that address to a non-zero value before the emulation started and then observe what happened. Here are some example ways to repeat the test yourself.
If you start MAME normally, it will clear all of RAM to zeros. If you let the machine show the demo before inserting coins and playing a game, you will see it shows the remaining ships display.
To change the address to a non-zero value before the emulation starts, start MAME with this command line:
mame -debug invaders
Then in the debug window, enter the following commands:
b@21ff = aa
g
Or alternatively, to fill all of the RAM with non-zero values before the emulation starts, you can enter commands like this:
fill 2000,400,aa,bb,cc,dd
g
If you let the machine show the demo before inserting coins and playing a game, you will see the remaing ships display is missing.
Real hardware
Here is a YouTube video of an actual Space Invaders arcade cabinet: Space Invaders Arcade Machine (Taito, 1978). The beginning of the video includes brief shots of the demo mode and you can see the remaining ship display in the bottom left corner is missing, presumably because the machine hasn't yet had any coins inserted or a game played since it was turned on, it started up with a non-zero value at the address for the player 1 ships remaining amount, and it behaves the same way I observed in my emulation tests.
