;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Copyright (c) 2001-2002 TIMEX Corporation.
; 
; This document is the property of, and contains information proprietary to
; TIMEX Corporation.  It is to be returned upon request.  Reproduction by any
; means, disclosure, or use of its contents for other than the expressed
; purpose for which it is loaned, without the written consent of TIMEX
; Corporation, is strictly prohibited.
;
; File Name:    dbmacro.h
;
; Purpose:      Database macro File
;
; Macro Names:
;   
;   DB_WRITE_EXTERNAL_MEMORY                - Writes a block of data from internal memory to external memory.
;   DB_READ_EXTERNAL_MEMORY                 - Reads a block of data from external memory to internal memory.
;
;   DB_WRITE_DATABASE_HEADER                - Writes the database header information from internal memory
;                                             to external memory.  This function will handle powering up/down
;                                             the EEPROM.
;
;   DB_OPEN_FILE                            - Open a database file in external memory for read/write access.
;   DB_CLOSE_FILE                           - Close the opened database file.
;   DB_OPEN_FILE_LINK_LIST                  - Open a database file in external memory for read/write access
;                                             to be used for link list structures.
;
;   DB_WRITE_RECORD                         - Writes a specified record data to database in external memory
;                                             starting at the start address of record.
;   DB_WRITE_RECORD_WITHOFFSET              - Writes a specified record data to database in external memory
;                                             starting at an offset from start address of record.
;
;   DB_READ_RECORD                          - Reads a specified record data to database in external memory
;                                             starting at the start address of record.
;   DB_READ_RECORD_WITHOFFSET               - Reads a specified record data to database in external memory
;                                             starting at an offset from the start address of record.
;
;   DB_WRITE_RECORD_RANDOMFIX               - Writes to a specific record in a fixed-sized random access
;                                             database in external memory starting at the start address of record.
;   DB_WRITE_RECORD_WITHOFFSET_RANDOMFIX    - Writes to a specific record in a fixed-sized random access
;                                             databasein external memory starting at a specified offset from the
;                                             start address of record.
;
;   DB_READ_RECORD_RANDOMFIX                - Read from a specific record in a fixed-sized random access
;                                             database in external memory starting at the start address of record.
;   DB_READ_RECORD_WITHOFFSET_RANDOMFIX     - Reads a specific record in a fixed-sized random access database
;                                             in external memory starting at a specified offset from the start
;                                             address of record.
;
;   DB_WRITE_RECORD_RANDOMVAR               - Writes to a specific record in a variable-sized random access
;                                             database in external memory starting at the start address of record.
;   DB_WRITE_RECORD_WITHOFFSET_RANDOMVAR    - Writes to a specific record in a variable-sized random access
;                                             database in external memory starting at a specified offset from
;                                             the start address of record.
;
;   DB_READ_RECORD_RANDOMVAR                - Read from a specific record in a fixed-sized random access
;                                             database in external memory starting at the start address of record.
;   DB_READ_RECORD_WITHOFFSET_RANDOMVAR     - Reads a specific record in a variable-sized random access database
;                                             in external memory starting at a specified offset from the start
;                                             address of record.
;
;   DB_READ_CODE_BLOCK                      - Reads a code block from external memory.
;
;   DB_READ_APPLICATION_INFOHEADER          - Reads the application specific data from a database header.
;   DB_WRITE_APPLICATION_INFOHEADER         - Updates the data in the application specific header fo the database.
;
;   DB_LOCATE_INSERTION_BYSIZE_LINKLIST     - Call all the refresh resource handlers of all the available apps
;   DB_REMOVE_RECORD_LINKLIST               - Removes a record from a link list
;   DB_INSERT_RECORD_LINKLIST               - Inserts a record into a link list after a specified record
;
;   DB_GET_ABSOLUTE_ADDRESS_OF_RECORD_RANDOMVAR - Returns the absolute address of a record in a variable-sized
;                                                 random access database.
;   DB_GET_ABSOLUTE_ADDRESS_OF_RECORD_RANDOMFIX - Returns the absolute address of a record in a fixed-sized
;                                                 random access database.
;   
; File Change History:
;
;               11/23/2001 NLS Modified for M851
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Macro Name :  DB_WRITE_EXTERNAL_MEMORY
;
; Description:  Writes a block of data from internal memory to external memory.
;
; Assumptions:  EEPROM is already powered up.
;
; Usage      :  DB_WRITE_EXTERNAL_MEMORY
;       
; Input(s):     DBInternalMemoryAddress - source base address in internal memory (16-bit)
;               DBExternalMemoryAddress - destination base address in external memory (16-bit)
;               DBLength                - number of bytes to copy (16-bit)
;
; Output(s):    None
;
; Destroyed:    None
;
; Macro Change History:
;
;               11/20/2001 NLS - Created macro for m851
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

DB_WRITE_EXTERNAL_MEMORY     MACRO

                car     dbWriteExternalMemory

        CALLS   SUBROUTINE , 'dbWriteExternalMemory'

        ENDM


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Macro Name :  DB_READ_EXTERNAL_MEMORY
;
; Description:  Reads a block of data from external memory to internal memory.
;
; Assumptions:  EEPROM is already powered up.
;
; Usage      :  DB_READ_EXTERNAL_MEMORY
;       
; Input(s):     DBInternalMemoryAddress - destination base address in internal memory (16-bit)
;               DBExternalMemoryAddress - source base address in external memory (16-bit)
;               DBLength                - number of bytes to copy (16-bit)
;
; Output(s):    None
;
; Destroyed:    None
;
; Macro Change History:
;
;               11/20/2001 NLS - Created macro for m851
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

DB_READ_EXTERNAL_MEMORY     MACRO

                car     dbReadExternalMemory

        CALLS   SUBROUTINE , 'dbReadExternalMemory'

        ENDM



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Macro Name :  DB_WRITE_DATABASE_HEADER
;
; Description:  Writes the database header information from internal memory
;               to external memory.  This function will handle powering up/down the EEPROM.
;
; Assumptions:  None
;
; Usage      :  DB_WRITE_DATABASE_HEADER
;       
; Input(s):     DBExternalMemoryAddress - absolute address of database in external memory (16-bit)
;               DBInternalMemoryAddress - source address in internal memory (16-bit)
;               DBLengthLo              - number of bytes to write (8-bit)
;
; Output(s):    None
;
; Destroyed:    None
;
; Macro Change History:
;
;               11/20/2001 NLS - Created macro for m851
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

DB_WRITE_DATABASE_HEADER     MACRO

                car     dbWriteDatabaseHeader

        CALLS   SUBROUTINE , 'dbWriteDatabaseHeader'

        ENDM


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Macro Name :  DB_OPEN_FILE
;
; Description:  Open a database file in external memory for read/write access.
;               The EEPROM is powered up before the file is opened.
;
; Assumptions:  None
;
; Usage      :  DB_OPEN_FILE
;       
; Input(s):     DBExternalMemoryAddress - absolute address of the database file in external memory (16-bit)
;
; Output(s):    DBExternalBaseAddress   - Base address of database use to convert offsets to absolute address (16-bit)
;               DBNumberOfRecords       - Number of records for the current database (16-bit)
;               DBSizePerRecord         - Size per record of database (only for fixed-size random access) (8-bit)
;
; Destroyed:    None
;
; Macro Change History:
;
;               11/20/2001 NLS - Created macro for m851
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

DB_OPEN_FILE     MACRO

                car     dbOpenFile

        CALLS   SUBROUTINE , 'dbOpenFile'

        ENDM


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Macro Name :  DB_CLOSE_FILE
;
; Description:  Close the opened database file.
;               The EEPROM is powered down.
;
; Assumptions:  None
;
; Usage      :  DB_CLOSE_FILE
;       
; Input(s)   :  None
;
; Output(s)  :  None
;
; Destroyed:    None
;
; Macro Change History:
;
;               11/20/2001 NLS - Created macro for m851
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

DB_CLOSE_FILE     MACRO

                car     dbCloseFile

        CALLS   SUBROUTINE , 'dbCloseFile'

        ENDM



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Macro Name :  DB_OPEN_FILE_LINK_LIST
;
; Description:  Open a database file in external memory for read/write access
;               to be used for link list structures.
;
;               The EEPROM is powered up.
;
; Assumptions:  None
;
; Usage      :  DB_OPEN_FILE_LINK_LIST
;       
; Input(s)   :  None
;
; Output(s)  :  None
;
; Destroyed:    None
;
; Macro Change History:
;
;               11/21/2001 NLS - Created macro for M851
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

DB_OPEN_FILE_LINK_LIST     MACRO

                car     dbOpenFileForLinkList

        CALLS   SUBROUTINE , 'dbOpenFileForLinkList'

        ENDM



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Macro Name :  DB_WRITE_RECORD
;
; Description:  Writes a specified record data to database in external memory
;               starting at the start address of record.
;               
; Assumptions:  The database file has been previously opened.
;               Record size is limited to 256 bytes.
;
; Usage      :  DB_WRITE_RECORD
;       
; Input(s):     DBInternalMemoryAddress - source base address in internal memory (16-bit)
;               DBExternalMemoryAddress - destination record offset in external memory (16-bit)
;               DBLengthLo              - number of bytes to write (8-bit)
;
; Output(s):    None
;
; Destroyed:    None
;
; Macro Change History:
;
;               11/20/2001 NLS - Created macro for m851
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

DB_WRITE_RECORD     MACRO

                car     dbWriteRecord

        CALLS   SUBROUTINE , 'dbWriteRecord'

        ENDM


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Macro Name :  DB_WRITE_RECORD_WITHOFFSET
;
; Description:  Writes a specified record data to database in external memory
;               starting at an offset from start address of record.
;               
; Assumptions:  The database file has been previously opened.
;               Record size is limited to 256 bytes.
;
; Usage      :  DB_WRITE_RECORD_WITHOFFSET
;       
; Input(s):     DBInternalMemoryAddress - source base address in internal memory (16-bit)
;               DBExternalMemoryAddress - destination record offset from DBExternalBaseAddress (16-bit)
;               DBLengthLo              - number of bytes to write (8-bit)
;               DBRecordOffset          - offset from start address of record to begin writing
;
; Output(s):    None
;
; Destroyed:    None
;
; Macro Change History:
;
;               11/20/2001 NLS - Created macro for m851
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

DB_WRITE_RECORD_WITHOFFSET     MACRO

                car     dbWriteRecordWithOffset

        CALLS   SUBROUTINE , 'dbWriteRecordWithOffset'

        ENDM


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Macro Name :  DB_READ_RECORD
;
; Description:  Reads a specified record data to database in external memory
;               starting at the start address of record.
;               
; Assumptions:  The database file has been previously opened.
;               Record size is limited to 256 bytes.
;
; Usage      :  DB_READ_RECORD
;       
; Input(s):     DBInternalMemoryAddress - destination base address in internal memory (16-bit)
;               DBExternalMemoryAddress - source record offset in external memory (16-bit)
;               DBLengthLo              - number of bytes to read (8-bit)
;
; Output(s):    None
;
; Destroyed:    None
;
; Macro Change History:
;
;               11/20/2001 NLS - Created macro for m851
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

DB_READ_RECORD     MACRO

                car     dbReadRecord

        CALLS   SUBROUTINE , 'dbReadRecord'

        ENDM


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Macro Name :  DB_READ_RECORD_WITHOFFSET
;
; Description:  Reads a specified record data to database in external memory
;               starting at an offset from the start address of record.
;               
; Assumptions:  The database file has been previously opened.
;               Record size is limited to 256 bytes.
;
; Usage      :  DB_READ_RECORD_WITHOFFSET
;       
; Input(s):     DBInternalMemoryAddress - destination base address in internal memory (16-bit)
;               DBExternalMemoryAddress - record offset in external memory (16-bit)
;               DBLengthLo              - number of bytes to read (8-bit)
;               DBRecordOffset          - offset from start address of record to begin reading
;
; Output(s):    None
;
; Destroyed:    None
;
; Macro Change History:
;
;               11/20/2001 NLS - Created macro for m851
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

DB_READ_RECORD_WITHOFFSET     MACRO

                car     dbReadRecordWithOffset

        CALLS   SUBROUTINE , 'dbReadRecordWithOffset'

        ENDM


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Macro Name :  DB_WRITE_RECORD_RANDOMFIX
;
; Description:  Writes to a specific record in a fixed-sized random access database in external memory
;               starting at the start address of record.
;               
; Assumptions:  The database file has been previously opened.
;               Record size is limited to 256 bytes.
;
; Usage      :  DB_WRITE_RECORD_RANDOMFIX
;       
; Input(s):     DBInternalMemoryAddress - source base address in internal memory (16-bit)
;               DBRecordNumber          - record number (16-bit)
;               DBLengthLo              - number of bytes to write (8-bit)
;
; Output(s):    None
;
; Destroyed:    None
;
; Macro Change History:
;
;               11/20/2001 NLS - Created macro for m851
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

DB_WRITE_RECORD_RANDOMFIX     MACRO

                car     dbWriteRecordRandomFix

        CALLS   SUBROUTINE , 'dbWriteRecordRandomFix'

        ENDM


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Macro Name :  DB_WRITE_RECORD_WITHOFFSET_RANDOMFIX
;
; Description:  Writes to a specific record in a fixed-sized random access database in external memory
;               starting at a specified offset from the start address of record.
;               
; Assumptions:  The database file has been previously opened.
;               Record size is limited to 256 bytes.
;
; Usage      :  DB_WRITE_RECORD_WITHOFFSET_RANDOMFIX
;       
; Input(s):     DBInternalMemoryAddress - source base address in internal memory (16-bit)
;               DBRecordNumber          - record number (16-bit)
;               DBLengthLo              - number of bytes to write (8-bit)
;               DBRecordOffset          - offset from start of record to begin writing
;
; Output(s):    None
;
; Destroyed:    None
;
; Macro Change History:
;
;               11/20/2001 NLS - Created macro for m851
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

DB_WRITE_RECORD_WITHOFFSET_RANDOMFIX     MACRO

                car     dbWriteRecordOffsetRandomFix

        CALLS   SUBROUTINE , 'dbWriteRecordOffsetRandomFix'

        ENDM


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Macro Name :  DB_READ_RECORD_RANDOMFIX
;
; Description:  Read from a specific record in a fixed-sized random access database in external memory
;               starting at the start address of record.
;               
; Assumptions:  The database file has been previously opened.
;               Record size is limited to 256 bytes.
;
; Usage      :  DB_READ_RECORD_RANDOMFIX
;       
; Input(s):     DBInternalMemoryAddress - destination address in internal memory (16-bit)
;               DBRecordNumber          - record number (16-bit)
;               DBLengthLo              - number of bytes to read (8-bit)
;
; Output(s):    None
;
; Destroyed:    None
;
; Macro Change History:
;
;               11/20/2001 NLS - Created macro for m851
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

DB_READ_RECORD_RANDOMFIX     MACRO

                car     dbReadRecordRandomFix

        CALLS   SUBROUTINE , 'dbReadRecordRandomFix'

        ENDM


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Macro Name :  DB_READ_RECORD_WITHOFFSET_RANDOMFIX
;
; Description:  Reads a specific record in a fixed-sized random access database in external memory
;               starting at a specified offset from the start address of record.
;               
; Assumptions:  The database file has been previously opened.
;               Record size is limited to 256 bytes.
;
; Usage      :  DB_READ_RECORD_WITHOFFSET_RANDOMFIX
;       
; Input(s):     DBInternalMemoryAddress - destination address in internal (16-bit)
;               DBRecordNumber          - record number (16-bit)
;               DBLengthLo              - number of bytes to read (8-bit)
;               DBRecordOffset          - offset from start of record to begin reading
;
; Output(s):    None
;
; Destroyed:    None
;
; Macro Change History:
;
;               11/20/2001 NLS - Created macro for m851
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

DB_READ_RECORD_WITHOFFSET_RANDOMFIX     MACRO

                car     dbReadRecordOffsetRandomFix

        CALLS   SUBROUTINE , 'dbReadRecordOffsetRandomFix'

        ENDM


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Macro Name :  DB_WRITE_RECORD_RANDOMVAR
;
; Description:  Writes to a specific record in a variable-sized random access database in external memory
;               starting at the start address of record.
;               
; Assumptions:  The database file has been previously opened.
;               Record size is limited to 256 bytes.
;
; Usage      :  DB_WRITE_RECORD_RANDOMVAR
;       
; Input(s):     DBInternalMemoryAddress - source base address in internal memory (16-bit)
;               DBRecordNumber          - record number (16-bit)
;               DBLengthLo              - number of bytes to write (8-bit)
;
; Output(s):    None
;
; Destroyed:    None
;
; Macro Change History:
;
;               11/20/2001 NLS - Created macro for m851
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

DB_WRITE_RECORD_RANDOMVAR     MACRO

                car     dbWriteRecordRandomVar

        CALLS   SUBROUTINE , 'dbWriteRecordRandomVar'

        ENDM


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Macro Name :  DB_WRITE_RECORD_WITHOFFSET_RANDOMVAR
;
; Description:  Writes to a specific record in a variable-sized random access database in external memory
;               starting at a specified offset from the start address of record.
;               
; Assumptions:  The database file has been previously opened.
;               Record size is limited to 256 bytes.
;
; Usage      :  DB_WRITE_RECORD_WITHOFFSET_RANDOMVAR
;       
; Input(s):     DBInternalMemoryAddress - source base address in internal memory (16-bit)
;               DBRecordNumber          - record number (16-bit)
;               DBLengthLo              - number of bytes to write (8-bit)
;               DBRecordOffset          - offset from start of record to being writing
;
; Output(s):    None
;
; Destroyed:    None
;
; Macro Change History:
;
;               11/20/2001 NLS - Created macro for m851
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

DB_WRITE_RECORD_WITHOFFSET_RANDOMVAR     MACRO

                car     dbWriteRecordOffsetRandomVar

        CALLS   SUBROUTINE , 'dbWriteRecordOffsetRandomVar'

        ENDM

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Macro Name :  DB_READ_RECORD_RANDOMVAR
;
; Description:  Read from a specific record in a fixed-sized random access database in external memory
;               starting at the start address of record.
;               
; Assumptions:  The database file has been previously opened.
;               Record size is limited to 256 bytes.
;
; Usage      :  DB_READ_RECORD_RANDOMVAR
;       
; Input(s):     DBInternalMemoryAddress - destination address in internal memory (16-bit)
;               DBRecordNumber          - record number (16-bit)
;               DBLengthLo              - number of bytes to read (8-bit)
;
; Output(s):    None
;
; Destroyed:    None
;
; Macro Change History:
;
;               11/20/2001 NLS - Created macro for m851
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

DB_READ_RECORD_RANDOMVAR     MACRO

                car     dbReadRecordRandomVar

        CALLS   SUBROUTINE , 'dbReadRecordRandomVar'

        ENDM


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Macro Name :  DB_READ_RECORD_WITHOFFSET_RANDOMVAR
;
; Description:  Reads a specific record in a variable-sized random access database in external memory
;               starting at a specified offset from the start address of record.
;               
; Assumptions:  The database file has been previously opened.
;               Record size is limited to 256 bytes.
;
; Usage      :  DB_READ_RECORD_WITHOFFSET_RANDOMVAR
;       
; Input(s):     DBInternalMemoryAddress - destination address in internal memory (16-bit)
;               DBRecordNumber          - record number (16-bit)
;               DBLengthLo              - number of bytes to read (8-bit)
;               DBRecordOffset          - offset from start of record to begin reading
;
; Output(s):    None
;
; Destroyed:    BAReg
;
; Macro Change History:
;
;               11/20/2001 NLS - Created macro for m851
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

DB_READ_RECORD_WITHOFFSET_RANDOMVAR     MACRO

                car     dbReadRecordOffsetRandomVar

        CALLS   SUBROUTINE , 'dbReadRecordOffsetRandomVar'

        ENDM


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Macro Name :  DB_READ_CODE_BLOCK
;
; Description:  Reads a code block from external memory.
;               
; Assumptions:  The code file has been previously opened.
;
; Usage      :  DB_READ_CODE_BLOCK
;       
; Input(s):     DBInternalMemoryAddress - destination address in internal memory to copy (16-bit)
;               DBRecordNumber          - record number (16-bit)
;                                       -   0x01 for common code
;                                       -   0x02 for state 0 code,
;                                       -   0x03 for state 1 code, ... etc.
;
; Output(s):    None
;
; Destroyed:    BAReg, HLReg
;
; Macro Change History:
;
;               11/20/2001 NLS - Created macro for m851
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

DB_READ_CODE_BLOCK     MACRO

                car     dbReadCodeBlock

        CALLS   SUBROUTINE , 'dbReadCodeBlock'

        ENDM


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Macro Name :  DB_READ_APPLICATION_INFOHEADER
;
; Description:  Reads the application specific data from a database header.
;               
; Assumptions:  This macro will powerup and powerdown the eeprom.
;
; Usage      :  DB_READ_APPLICATION_INFOHEADER
;       
; Input(s):     DBExternalMemoryAddress - absolute address of database in external memory (16-bit)
;               DBInternalMemoryAddress - destination address in internal memory (16-bit)
;               DBLengthLo              - number of bytes to read (8-bit)
;               DBRecordOffset          - offset from start of app specific header to begin reading (8-bit)
;
; Output(s):    None
;
; Destroyed:    None
;
; Macro Change History:
;
;               11/20/2001 NLS - Created macro for m851
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

DB_READ_APPLICATION_INFOHEADER     MACRO

                car     dbReadApplicationInfoHeader

        CALLS   SUBROUTINE , 'dbReadApplicationInfoHeader'

        ENDM



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Macro Name :  DB_WRITE_APPLICATION_INFOHEADER
;
; Description:  Updates the data in the application specific header of the database.
;               
; Assumptions:  None
;
; Usage      :  DB_WRITE_APPLICATION_INFOHEADER
;       
; Input(s):     DBExternalMemoryAddress - absolute address of database in external memory (16-bit)
;               DBInternalMemoryAddress - source address in internal memory (16-bit)
;               DBLengthLo              - number of bytes to write (8-bit)
;               DBRecordOffset          - offset from start of app specific header to begin writing (8-bit)
;
; Output(s):    None
;
; Destroyed:    None
;
; Macro Change History:
;
;               11/20/2001 NLS - Created macro for m851
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

DB_WRITE_APPLICATION_INFOHEADER     MACRO

                car     dbWriteApplicationInfoHeader

        CALLS   SUBROUTINE , 'dbWriteApplicationInfoHeader'

        ENDM


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Macro Name :  DB_LOCATE_INSERTION_BYSIZE_LINKLIST
;
; Description:  Locates the record where a new record can be inserted.  The new record will be inserted
;               to sort the list database according to size of the record.  The new record is inserted
;               after the specified record.
;
; Assumptions:  Double Linked list database has been previously opened.
;
; Usage      :  DB_LOCATE_INSERTION_BYSIZE_LINKLIST
;       
; Input(s):     HLReg        - record offset to begin searching for a record
;               DBRecordSize - search criteria to locate where to insert a record in the list
;
; Output(s):    BAReg != DBNULLRECORDOFFSET - record address offset where a new record can be inserted after.
;               BAReg == DBNULLRECORDOFFSET - record should be located as the first record in the list
;
; Destroyed:    All Registers
;
; Macro Change History:
;
;               11/20/2001 NLS - Created macro for m851
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

DB_LOCATE_INSERTION_BYSIZE_LINKLIST     MACRO

                car     dbLocateInsertionBySizeLinkList

        CALLS   SUBROUTINE , 'dbLocateInsertionBySizeLinkList'

        ENDM


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Macro Name :  DB_REMOVE_RECORD_LINKLIST
;
; Description:  Removes a record from a link list
;
; Assumptions:  Double Linked list database has been previously opened.
;
; Usage      :  DB_REMOVE_RECORD_LINKLIST
;       
; Input(s):     HLReg             - Absolute Address (internal memory) Link List Head Pointer
;               DBRecordAddress   - Address offset of record to remove from the link list structure
;
; Output(s):    *HLReg - updated with the new record address offset if removing first record in list.
;
; Destroyed:    None
;
; Macro Change History:
;
;               11/20/2001 NLS - Created macro for m851
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

DB_REMOVE_RECORD_LINKLIST     MACRO

                car     dbRemoveRecordLinkList

        CALLS   SUBROUTINE , 'dbRemoveRecordLinkList'

        ENDM


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Macro Name :  DB_INSERT_RECORD_LINKLIST
;
; Description:  Inserts a record into a link list after a specified record
;
; Assumptions:  Double Linked list database has been previously opened.
;
; Usage      :  DB_INSERT_RECORD_LINKLIST
;       
; Input(s):     HLReg                 - Absolute Address (internal memory) Link List Head Pointer
;               DBRecordAddress       - Address offset of record to add into the link list structure
;               DBInsertRecordAddress - Address offset of record where the new record is to be appended.
;                                       (If DBNULLRECORDOFFSET, then new record is first record in list.)
;
; Output(s):    *HLReg - updated with the new record address offset if the new record is the first record in list.
;
; Destroyed:    All Registers
;
; Macro Change History:
;
;               11/20/2001 NLS - Created macro for m851
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

DB_INSERT_RECORD_LINKLIST     MACRO

                car     dbInsertRecordLinkList

        CALLS   SUBROUTINE , 'dbInsertRecordLinkList'

        ENDM


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Macro Name :  DB_GET_ABSOLUTE_ADDRESS_OF_RECORD_RANDOMVAR
;
; Description:  Returns the absolute address of a record in a variable-sized random access database.
;               
; Assumptions:  The database file has been previously opened.
;               Record size is limited to 256 bytes.
;
; Usage      :  DB_GET_ABSOLUTE_ADDRESS_OF_RECORD_RANDOMVAR
;       
; Input(s):     DBRecordNumber          - record number to read (16-bit)
;
; Output(s):    BAReg                   - absolute address of specified record in EEPROM
;               DBExternalMemoryAddress - absolute address of specified record in EEPROM
;
; Destroyed:    None
;
; Macro Change History:
;
;               11/20/2001 NLS - Created macro for m851
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

DB_GET_ABSOLUTE_ADDRESS_OF_RECORD_RANDOMVAR     MACRO

                car     dbGetAbsoluteAddressOfRecordRandomVar

        CALLS   SUBROUTINE , 'dbGetAbsoluteAddressOfRecordRandomVar'

        ENDM


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Macro Name :  DB_GET_ABSOLUTE_ADDRESS_OF_RECORD_RANDOMFIX
;
; Description:  Returns the absolute address of a record in a fixed-sized random access database.
;               
; Assumptions:  The database file has been previously opened.
;               Record size is limited to 256 bytes.
;
; Usage      :  DB_GET_ABSOLUTE_ADDRESS_OF_RECORD_RANDOMFIX
;       
; Input(s):     DBRecordNumber          - record number to read (16-bit)
;
; Output(s):    BAReg                   - Absolute address of specified record in EEPROM
;               DBExternalMemoryAddress - Same as BAReg. Absolute address of specified record in EEPROM
;
; Destroyed:    None
;
; Macro Change History:
;
;               11/20/2001 NLS - Created macro for m851
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

DB_GET_ABSOLUTE_ADDRESS_OF_RECORD_RANDOMFIX     MACRO

                car     dbGetAbsoluteAddressOfRecordRandomFix

        CALLS   SUBROUTINE , 'dbGetAbsoluteAddressOfRecordRandomFix'

        ENDM
