\ memo 05.1.23 NAB

needs core-ext
needs toolkit
needs zstrings
needs DataMgr

ID DATA    ID memo
2variable _MemoDBR
: MemoDBR  _MemoDBR 2@ ;
variable index

: OpenMemoDB ( -- )
  dmModeReadWrite memo DATA DmOpenDatabaseByTypeCreator
  2dup or 0= throw  _MemoDBR 2! ;

: CloseMemoDB ( -- )
  MemoDBR DmCloseDatabase throw ;

: WriteNewMemo ( zstring length -- )
  0 index !   1+ s>d  2dup  index >abs
    MemoDBR  ( len. &index. DBR. )
      DmNewRecord  ( handle. )
  MemHandleLock 2>r ( R: pointer. )
    rot >abs  0.  2r@
    ( length. &data. offset. DBR. )
      DmWrite throw
  2r> MemPtrUnlock throw
  true  index @  MemoDBR DmReleaseRecord throw ;
