Backup RAM.

Description

The Tennokoe 2, IFU-30 and DUO systems provided an extra 2KB of battery powered back up memory.

The backup ram (BRAM for short) “file system” is organized as follows :

BRAM Header (16 bytes)

00-03Header tag (equals to “HUBM”)
04-05Pointer to the first byte after BRAM.
06-07Pointer to the next available BRAM slot (first unused byte).
08-0fReserved (set to 0).

BRAM Entry Header

00-01Entry size.  This size includes the $10 bytes of the entry header.
02-03Checksum.  The checksum is the sum of the entry bytes starting from byte #4 (i.e all bytes except the entry size and checksum).  The value stored is the opposite of the computed checksum.  This way the consistency check only consists in adding the ssum the stored checksum and the newly computed one.  If this sum is 0, the entry is valid.
04-0fEntry name.

BRAM Entry name

00-01Unique ID.
02-0bASCII name (padded with spaces).

BRAM Entry Data

Miscenalleous data which size is given in the BRAM Entry Header.

BRAM Entry Trailer (2 bytes)

This 2 bytes are set to zeroes.  They are not part of the BRAM “used area”.  It is used as a linked list terminator.

For CD-ROM programs, the following BRAM routines are provided from the System Card:

  • bm_format
  • bm_free
  • bm_read
  • bm_write
  • bm_delete
  • bm_files
Summary
Backup RAM.The Tennokoe 2, IFU-30 and DUO systems provided an extra 2KB of battery powered back up memory.
Functions
bm_bindUnlock and map BRAM to mpr #4.
bm_unbindLock BRAM and restore mpr #4.
bm_testTest if data can safely be written to BRAM.
bm_check_headerChecks if the BRAM header is valid.
bm_detectDetect if a BRAM is present on the system.
bm_sizeGet the storage capacity in bytes of the backup RAM.
bm_formatInitialize backup memory.
bm_freeReturns the number of free bytes.
bm_checksumCompute checksum.
bm_openFinds the BRAM entry whose name is given as argument.
bm_adjust_pointer
bm_readRead entry data.
bm_writeUpdate entry data.
bm_deleteDelete the specified entry.
bm_filesGet file by index and store the information in a buffer.
bm_getptr.2Given a pointer to the BRAM, obtain the name of the entry and the pointer to the next entry.
bm_createCreate a new entry at the end of current storage.
bm_existsCheck if there is an entry which name matches the one given as parameter.

Functions

bm_bind

Unlock and map BRAM to mpr #4.

Warning

This routine switches the CPU to slow mode.

bm_unbind

Lock BRAM and restore mpr #4.

Warning

This routines switches the CPU to fast mode.

bm_test

Test if data can safely be written to BRAM.

Warning

bm_bind must have been previously called.

Return

The carry flag is cleared if the backup RAM storage is valid.

bm_check_header

Checks if the BRAM header is valid.

Warning

bm_bind must have been previously called.

Return

The carry flag is cleared and A is set to 0 if the header is valid.  Otherwise the carry flag is set and A is set to $ff.

bm_detect

Detect if a BRAM is present on the system.

Return

The carry flag is set if an error occured and the value of bm_error is set as follow: 0 - BRAM is present and fully formated.  1 - BRAM is present but not formatted.  2 - no BRAM was found.

bm_size

Get the storage capacity in bytes of the backup RAM.  Standard value is 2KB, but it can go up to 8KB.

Return

_cxBRAM total storage size (in bytes).
bm_errorError code.

Error value

$00Success.
$ffBRAM not formatted.

bm_format

Initialize backup memory.  Set header info and and limit of BRAM to the maximum amount of memory available on this hardware.

bm_free

Returns the number of free bytes.

Returns

carry flag1 upon success or 0 if an error occured.
_cxNumber of free bytes.
bm_errorError code.

Error Value

$00Success.
$ffError.

bm_checksum

Compute checksum.  The checksum is the sum of all entry bytes except the first 4 ones (file size and checksum).

Parameters

_siBRAM file entry pointer.

Return

_dxchecksum

bm_open

Finds the BRAM entry whose name is given as argument.

Parameters

_bxpointer to the BRAM entry name.

Return

carry flag1 upon success or 0 if an error occured.
bm_errorError code.
_siPointer to the beginning of the first matching BRAM entry.
_dxPointer to the next BRAM entry.
_cxEntry size.

Error code values

$01File not found
$03Directory is corrupted.
$04Empty file
$ffBRAM is not formatted

bm_adjust_pointer

Parameters

_sipointer to BRAM entry.
_bpoffset (in bytes) in BRAM entry data.
_axnumber of byte to read from BRAM.

Return

The carry flag is cleared is the BRAM pointer was succesfully adjusted to point to the requested BRAM entry data area.  It is set if the requested size is zero or if the requested area to read is out the entry bounds.

<_ax, <_cxadjusted size
<_dxentry pointer

bm_read

Read entry data.

Parameters

_dipointer to the output buffer.
_bxpointer to the BRAM entry name.
_bpoffset (in bytes) in BRAM entry data.
_axnumber of bytes to read from BRAM.

Return

_axnumber of bytes to read from BRAM.
_dxentry pointer
bm_errorError code.

Error values

$02invalid checksum.

bm_write

Update entry data.

Warning

The entry will not be resized if the offset and size exceed the current entry area.

Parameters

_dipointer to the input buffer.
_bxpointer to the BRAM entry name.
_bpoffset (in bytes) in BRAM entry data.
_axnumber of bytes to write BRAM.

Return

bm_errorError code.

Error values

$01File not found
$03Directory is corrupted.
$04Empty file
$ffBRAM is not formatted

bm_delete

Delete the specified entry.

Parameters

_bxpointer to the BRAM entry name.

bm_files

Get file by index and store the information in a buffer.

Entry format

00-01User ID.
02-0fEntry name.
10-11Entry size.

Parameters

_bxAddress to the buffer where the entry informations will be stored.
_alFile index (starts at 1).

Return

_siEntry address
bm_errorError code.

Error values

$00Success.
$01Cannot find file.
$ffBRAM is not formatted.

bm_getptr.2

Given a pointer to the BRAM, obtain the name of the entry and the pointer to the next entry.

Set _bp to bm_entry for the first entry.

Parameters

_bpAddress of the current entry.
AMSB of the destination address for the entry name.
XLSB of the destination address for the entry name.

Return

AMSB of the next entry address.
XLSB of the next entry address.
_cxEntry size.
bm_errorError code.
carry flagSet if an error occured.

Error values

$00Success.
$01Cannot find file.  _bp is past the last entry.
$ffBRAM is not formatted.

bm_create

Create a new entry at the end of current storage.

Parameters

_bxpointer to the entry name.
_axentry size.

Return

bm_errorError code.
carry flagSet if an error occured.

Error values

$00Success.
$01Cannot find file.  _bp is past the last entry.
$05Not enough space for entry.
$ffBRAM is not formatted.

bm_exists

Check if there is an entry which name matches the one given as parameter.

Parameters

_bxpointer to the entry name.

Return

X1 if a matching entry exists, 0 otherwise.
carry flagCleared if a matching entry exists.
bm_errorError code.

Error values

$00Success.
$01Cannot find file.  _bp is past the last entry.
$ffBRAM is not formatted.
Close