Close

"Memory Card" (Non-volatile memory)

A project log for Micro:Gamer

Portable game console based on the Micro:Bit

fabien-chouteauFabien-Chouteau 03/14/2018 at 01:280 Comments

Most of the games I ported from Arduboy to the Micro:Gamer use EEPROM to save high score or game state when the console is powered off. I think this is must have feature for a game console so I implemented it for the Micro:Gamer.

There is no EEPROM on the micro:bit board and I don't want to add it as an extra component on my hardware design, so I had to use the flash memory inside the micro-controller.

The interface to use the flash as persistent storage is provided by the MicroGamerMemoryCard class. This class uses two different memory areas:

Here is an example of how it looks like in the code:

// Create a memory card of one 32bit word
MicroGamerMemoryCard mem(1);

// Load the content of the flash page to the temporary RAM buffer
mem.load();

// Read a value from the temporary RAM buffer
if (mem.read(0) != 42) {

  // Write a value to the temporary RAM buffer
  mem.write(0, 42);

  // Permanently save the RAM buffer into flash memory
  mem.save();
}

And here is a demo with the game Micro City:

Discussions