Using App Keys - FujiNetWIFI/fujinet-firmware GitHub Wiki

App Keys

App keys are small bits of data that an application can use to persist state on the FujiNet.

Since the 8 bit client machines can sometimes freeze/need to be rebooted, it's important to be able to pick up where you left off. You could save the "key" details in an app key and retrieve it on app start to store in memory.

An app key is a small file on the SD Card in the FujiNet, of (currently) up to 64 bytes.

Any app key can be read by any program, so to avoid using other program's appkeys, each appkey name is composed of:

  • [2 byte creator id prefix] - [app id] - [key id]

The idea is, the creator ID points to who wrote the program using the app key, and the [app id] is your own number you assigned to your program, and [key id] to allow multiple keys to be associated with the same program.

For example, Eric Carr's creator ID is E41C (hex).

For the 5 Card Stud game's internal preferences I use these two app keys to store gamer preferences:

  • E41C-01-01 - Have they seen the help screen? Shown first run only
  • E41C-01-02 - What theme/color did they select?

So, the 5CS client can use that same theme the next time they start the game.

You can register your own creator ID, so others do not use it, by editing the wiki here

The Lobby has a reserved creator ID 1 (0001). It stores the player name in 0001-01-00, which your game can read, or optionally set.

Other examples are fujinet-config-ng by Fenrock, showing an example of versioning your appkeys for future proofing against changes in your app where you may need to persist new state.

This is using the details:

#define FNC_CREATOR_ID 0xfe0c
#define FNC_APP_ID     0x01
#define FNC_KEY_ID     0x01

Thus the key written to SD is fe0c-01-01 for config-ng preferences, including colour schemes, UK/US time settings, using banked memory, and scrolling delays in the application. Basically anything you need to persist.

Technical details

The SIO command documentation contains technical details of how to interact with the FujiNet to create and read App Keys.

FujiNet Lib

fujinet-lib contains functions for using appkeys in C, see header file here.

An example is in the fujinet-lib-examples repo: Example C code