----------------------------
The Directory Object
----------------------------
(analysis by Matthew Mastracci: mmas...@acs.ucalgary.ca)
Directory objects (ram/rom pairs, abbreviated rrp) are composed of a ram
part and a rom part. Regular directories, however, are simply a ram part.
These objects are highly optimized to be modular, for adding new variables
to the end and for traversing them from end to beginning. They are
interpreted by the HP48 by displaying a directory with the variables near
the end of the directory object being displayed at the beginning of the
variable list.
The format of the object is:
DORRP (five nibbles)
- value is 02a96h
ROMPART (three nibbles)
- ties a directory to a library, regular dir's have 7ffh here
RAMPART: (reverse "linked" list of variable names, made of...)
LAST-OBJECT (five nibbles)
- forward-relative pointer to start of last directory entry block
DIRECTORY-ENTRY-BLOCKs:
PREVIOUS-OBJECT (five nibbles)
- reverse-relative pointer to start of previous directory entry block
VARIABLE-NAME
- First two nibbles are length (in bytes)
- Variable name data-bytes
- Last two nibbles are length again (in bytes)
VARIABLE-DATA
- Normal variable object data
Note: The variable data must be valid and of *exactly* the length
specified by the following pointer. If it isn't, funny things seem to
happen with the directory. You may find that you can't actually delete
the directory and if you use ON-A-F (no), followed by ON-A-F (yes), it may
actually come back!
Here's a short example:
The object:
DIR
A "B"
B "BB"
C "B"
END
is represented by the following nibbles (check with \->ASC):
"69A20FF7A300000000103410C2A20700002421000102410C2A2090000242441000
101410C2A207000024C668"
When we break it down, we see:
69A20 (DORRP)
FF7 (ROMPART, regular dir)
A3000 (pointer to last object relative to start of this word, 3ah=58d)
1st block:
00000 (pointer to previous block, 0 for start of directory)
103410 (length 1, 'A', length 1)
C2A20 (02A2C=DOCSTR)
70000 (length 7 nibbles, including length field)
24 (0x42="B")
21000 (pointer to previous block, 18 nibbles backward)
102410 (length 1, 'B', length 1)
C2A20 (DOCSTR)
90000 (9 nibbles, including this)
2424 ("BB")
41000 (pointer backwards, 20 nibbles)
104110 ("A")
C2A20 (DOCSTR)
70000 (same as before)
24 ("B")
(no backward pointer, as we're at the end)
C668 (CRC=866C, check with BYTES)
From this example, it's easy to see that directories were meant to be
traversed backwards. Otherwise, you need to store a lot of information
about where the last object is and figure out exactly how long the current
object is. Although not very difficult, it's not my cup of tea. ;)
Comments, suggestions, compliments or complaints are gratiously accepted.
/\/\att /\/\astracci mmas...@acs.ucalgary.ca
"Tout choses sont dites deja, mais comme personne n'ecoute, il faut
toujours recommencer."