8

In Pokémon Red/Blue (USA, I'm assuming in other gen 1 releases as well), you can carry 6 pocket monsters with you at once. Extra ones are stored in "boxes" on the computer. If you have 6 and catch a wild monster, it is sent to the box automatically. However, each box can hold only a few Pokémon. After the box is full, when you catch a wild one, the game gives an error message that you can't catch this one because the box is full. If you go switch to another box, the game says it has to save before switching.

Why is this?

I assume there is some kind of hardware limitation related to writing to the SRAM, or in the bankable RAM where data is loaded, but I would appreciate a more detailed explanation.

9

The boxes are indeed in different Saved RAM banks, as shown in this memory map; boxes 1-6 are in SRAM bank 2, with boxes 7-12 in bank 3.

The memory map also notes that there are individual checksum addresses for each box, as well as a global checksum for each bank.

Banks 2 and 3 are not accessed directly during gameplay. Instead, the data from the current box is copied into the working area of Bank 1. As described on Bulbapedia's page:

when a box is selected its contents are copied and cached in bank 1. Think of bank 2 and 3 as warehouses where information is copied over to the more important areas when needed, and only updated on save in case anything changed in the copied versions.

As only one box at a time is stored in Bank 1, changing boxes on the PC requires the following procedure:

  • Copy current box contents from Bank 1 to Bank 2 or3
  • Calculate checksum for current box, update box checksum in Bank 2 or 3
  • Calculate and update global checksum for Bank 2 or 3
  • Copy new box contents from Bank 2/3 to Bank 1

If we decided not to calculate box checksums when they're copied back to bank 2/3 (to save time), they would have to be calculated later on while saving your game. Unless you keept track of which boxes had been touched, you'd have to recalculate each box's checksum, as well as the two global checksums. This would make saving your game an even slower task than it already is on Pokémon Red/Blue.

Additionally, switching the power off after a non-save box swap (and before saving) would leave an old checksum that didn't match the box data, and the game would think it had a corrupted save when it was next turned on.

It would reasonable for a user to switch their game off without saving at times (if they want to replay a battle), and expect their game to resume from their last save. Corrupting a box in this scenario would be unacceptable, so checksums are updated on every box change.

On the other hand, if box checksums were updated without saving the rest of the game data, you could have a box checksum that is newer than the rest of the save data. This could lead to situations where individual Pokémon end up being duplicated or lost when you load old save data, similar to how Pokémon can be cloned by switching off during a link-cable trade. The linked page notes that this can indeed be done to clone Pokémon in boxes, by switching the game off while saving. In fairness, it requires precise timing, and disobeying the DO NOT SWITCH OFF message, so shouldn't happen by accident.

The fact that the Game Boy is a battery-powered platform, where power outages are to be expected, means that it is all the more imperative to make sure all save data (game, boxes, and checksums) are updated coherently, at the same time.

So the long and the short of it is: if you want to have checksums on your box storage to avoid data corruption, that means you have to save the game whenever you update a checksum as you swap boxes, to keep everything consistent.

4
  • Note that bank-switching is pretty fast. There's no reason the user would need to decide when to bank-switch, it happens maybe a hundred times per frame already.
    – user253751
    Feb 16 at 9:29
  • Does that apply to battery-backed SRAM too?
    – Kaz
    Feb 16 at 11:05
  • Well the game doesn't bank-switch SRAM very often. Usually it bank-switches ROM. But it's the same process and equally fast. The bank-switch has nothing to do with the actual SRAM chip, it just changes some of the address bits.
    – user253751
    Feb 16 at 12:48
  • @user253751 Following the prompting of your comment, I've re-evaluated my old answer, significantly expanded it, and revised the conclusion.
    – Kaz
    Feb 16 at 13:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.