Skip to content

rinonvolatilelib

This library lets a program use the system’s nonvolatile.library, which keeps small items of data across a power cycle: in the nonvolatile memory of a CD32, or, on other Amigas, in a place on disk that the library uses instead.

Each item is named by two names, the name of the application and the name of the item, so one program can keep several items, for example several saved games. StoreNVData stores an item, GetCopyNV reads a copy of it, GetNVList lists the items of an application, and FreeNVData frees what the last two returned.

The library opens nonvolatile.library (any version) when the program starts; IsNonvolatile tells whether that worked. Without it every command does nothing and returns 0. StoreNVData and GetCopyNV work in Amiga mode only.

level.l=5
If IsNonvolatile
  r=StoreNVData("MyGame","Level",&level,4)
  a.l=GetCopyNV("MyGame","Level")
  If a
    NPrint "level ",Peek.l(a)
    FreeNVData a
  EndIf
EndIf

The fixed bugs of the library are listed in Fixes in rinonvolatilelib.

Based on the RI NonVolatile Lib guide by Red When Excited.

Library number 35.

Commands

FreeNVData

Frees the memory returned by GetCopyNV or GetNVList.

Statement. Help text: APTR
Arguments: .l

GetCopyNV

The address of a copy of the item ItemName of the application AppName, or 0 if there is no such item. Free the copy with FreeNVData when done.

Function, result .l. Help text: AppName,ItemName
Arguments: any, any

Amiga mode only.

GetNVList

The address of a list of the items that the application appname has stored, or 0. Free it with FreeNVData when done.

Function, result .l. Help text: appname
Arguments: any

The list is an exec list (a MinList) of the NVEntry structures of nonvolatile.library, each with the item’s name, size and protection.

IsNonvolatile

Returns -1 if nonvolatile.library could be opened when the program started, else 0. Without it, the other commands of the library do nothing.

Function, result .w. Help text: -- returns true if library is open
No arguments.

StoreNVData

Stores byte_length bytes from the address data as the item ItemName of the application AppName. As a function it returns -1 (True) if the item was stored, else 0 (False).

Statement or function, result .w. Help text: AppName,ItemName,data,byte_length
Arguments: any, any, .l, .l

Amiga mode only. The memory is reserved in units of 10 bytes, so the length is rounded up to the next multiple of 10.

The item is deleted before it is stored again, which makes room in a small nonvolatile memory such as the CD32’s; if storing fails, the old item is lost as well.