;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; 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:    coreSvMc.h
;
; Macro Names: 
;
;       CORE_SET_HL_TO_ACB_USING_AREG           - Set HLReg register to the begining of ACB block 
;       CORE_SET_HL_TO_ASD_ADDRESS              - Return the Application System Data start address
;       CORE_SET_HL_TO_ADD_ADDRESS              - Return the Application Database Data start address
;       CORE_SET_HL_TO_STATE_MANAGER_ADDRESS    - Return the State Manager start address 
;       CORE_SET_HL_TO_BACKGROUND_HANDLER_ADDRESS  - Return the Background Handler start address 
;       CORE_SET_HL_TO_MODE_NAME_ADDRESS        - Return the Mode Name start address 
;       CORE_SET_HL_TO_APP_CONFIG_DATA_LIST     - Return the address to the application configuration data byte
;       CORE_SET_HL_TO_CODE_EXTERNAL_ADDRESS    - Return the absolute address in external memory where the code
;                                                 block is located.
;       
;       CORE_APP_ID_PRESENT                     - Check if the application is already present in the ACD list 
;       CORE_GET_APP_INDEX                      - Check if the application is already present in the ACD list 
;       CORE_GET_APP_INDEX_FROM_APP_TYPE        - Check if we have an application of specific type
;
;       CORE_GET_MODE_LIST_INDEX                - Get index in Mode List Table
;       
;       CORE_CHECK_HEAP_SIZE                    - Check if a given heap requirement it fits the free memory
;       CORE_ALLOCATE_APP                       - Allocate an Application
;       CORE_DELETE_ALL_APP                     - Delete all the applications except TOD and Comm
;       
;       
; Purpose:      Services and utilities provided by the core to the Applications.
;
; File Change History:
;
;               05/27/2000 HSB - Created coreSvMc.h
;
; M851 - Development:
;
;               11/20/2001 NLS - Modified for M851
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Macro Name:   CORE_SET_HL_TO_ACB_USING_AREG
;
; Description:  Set HLReg register to the begining of ACB block 
;               using AReg as the Application Index input
;
; Assumptions:  None
;
; Usage:        CORE_SET_HL_TO_ACB_USING_AREG
;
; Input(s):     AReg=Application Index
;
; Output(s):    HLReg = Points to the begining of ACB block
;
; Destroyed:    HLReg
;
; Macro Change History:
;
;               05/11/2000 HSB - Created Macro     
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

CORE_SET_HL_TO_ACB_USING_AREG   MACRO

                car coreSetHLtoACBUsingAReg

        CALLS   SUBROUTINE , 'coreSetHLtoACBUsingAReg'

        ENDM


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Macro Name:   CORE_SET_HL_TO_ASD_ADDRESS
;
; Description:  Return the Application System Data start address
;
; Assumptions:  NONE
;
; Usage:        CORE_SET_HL_TO_ASD_ADDRESS
;
; Input(s):     AReg=Application Index
;
; Output(s):    HLReg->Points to the begining of ASD
;
; Destroyed:    HLReg
;
; Macro Change History:
;
;               05/31/2000 HSB - Created Macro     
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

CORE_SET_HL_TO_ASD_ADDRESS  MACRO

                car coreSetHLtoASDAddress

        CALLS   SUBROUTINE , 'coreSetHLtoASDAddress'

        ENDM


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Macro Name:   CORE_SET_HL_TO_ADD_ADDRESS 
;
; Description:  Return the Application Database Data start address
;
; Assumptions:  NONE
;
; Usage:        CORE_SET_HL_TO_ADD_ADDRESS
;
; Input(s):     AReg=Application Index
;
; Output(s):    HLReg-> Points to the begining of ADD
;
; Destroyed:    HLReg
;
; Macro Change History:
;
;               05/31/2000 HSB - Created Macro     
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

CORE_SET_HL_TO_ADD_ADDRESS  MACRO

                car coreSetHLtoADDAddress

        CALLS   SUBROUTINE , 'coreSetHLtoADDAddress'

        ENDM


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Macro Name:   CORE_SET_HL_TO_STATE_MANAGER_ADDRESS
;
; Description:  Return the State Manager start address 
;
; Assumptions:  NONE
;
; Usage:        CORE_SET_HL_TO_STATE_MANAGER_ADDRESS
;
; Input(s):     AReg=Application Index
;
; Output(s):    HLReg-> Points to the begining of the State Manager
;
; Destroyed:    HLReg
;
; Macro Change History:
;
;               05/31/2000 HSB - Created Macro     
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

CORE_SET_HL_TO_STATE_MANAGER_ADDRESS    MACRO

                car coreSetHLtoStateManAddress

        CALLS   SUBROUTINE , 'coreSetHLtoStateManAddress'

        ENDM


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Macro Name:   CORE_SET_HL_TO_BACKGROUND_HANDLER_ADDRESS
;
; Description:  Return the Background Handler start address 
;
; Assumptions:  NONE
;
; Usage:        CORE_SET_HL_TO_BACKGROUND_HANDLER_ADDRESS
;
; Input(s):     AReg=Application Index
;
; Output(s):    HLReg = Points to the begining of the Background Handler
;
; Destroyed:    HLReg
;
; Macro Change History:
;
;               05/31/2000 HSB - Created Macro     
;
; M851 - Development:
;
;               11/20/2001 NLS - Modified for M851
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

CORE_SET_HL_TO_BACKGROUND_HANDLER_ADDRESS  MACRO

                car coreSetHLtoBackgroundHandlerAddress

        CALLS   SUBROUTINE , 'coreSetHLtoBackgroundHandlerAddress'

        ENDM


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Macro Name:   CORE_SET_HL_TO_MODE_NAME_ADDRESS
;
; Description:  Return the Mode Name start address 
;
; Assumptions:  NONE
;
; Usage:        CORE_SET_HL_TO_MODE_NAME_ADDRESS
;
; Input(s):     AReg=Application Index
;
; Output(s):    HLReg = Points to the begining of the Mode Name
;
; Destroyed:    HLReg
;
; Macro Change History:
;
;               05/31/2000 HSB - Created Macro     
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

CORE_SET_HL_TO_MODE_NAME_ADDRESS    MACRO

                car coreSetHLtoModeNameAddress

        CALLS   SUBROUTINE , 'coreSetHLtoModeNameAddress'

        ENDM



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Macro Name:   CORE_SET_HL_TO_CODE_EXTERNAL_ADDRESS
;
; Description:  Return the absolute address in external memory where the code block is located.
;
; Assumptions:  NONE
;
; Usage:        CORE_SET_HL_TO_CODE_EXTERNAL_ADDRESS
;
; Input(s):     AReg=Application Index
;
; Output(s):    HLReg = Points to the absolute external address of code block
;
; Destroyed:    HLReg
;
; Macro Change History:
;
;               05/31/2000 HSB - Created Macro     
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

CORE_SET_HL_TO_CODE_EXTERNAL_ADDRESS    MACRO

                car coreSetHLtoCodeAddress

        CALLS   SUBROUTINE , 'coreSetHLtoCodeAddress'

        ENDM


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Macro Name:   CORE_SET_HL_TO_APP_CONFIG_DATA_LIST
;
; Description:  Given the app index, return the address pointing to the
;               application configuration data byte
;
; Assumptions:  NONE
;
; Usage:        CORE_SET_HL_TO_APP_CONFIG_DATA_LIST
;
; Input(s):     AReg=Application Index
;
; Output(s):    HLReg = Points to the correspondent application Config data byte
;
; Destroyed:    HLReg
;
; Macro Change History:
;
;               07/13/2000 HSB - Created Macro     
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

CORE_SET_HL_TO_APP_CONFIG_DATA_LIST MACRO

                car coreSetHLtoAppConfigDataList

        CALLS   SUBROUTINE , 'coreSetHLtoAppConfigDataList'

        ENDM


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Macro Name:   CORE_APP_ID_PRESENT
;
; Description:  Given an App ID (2 bytes) check if 
;               the application is already present in the ACD list 
;               Returns the App index if present otherwise 0xFF
;
; Assumptions:  None
;
; Usage:        CORE_APP_ID_PRESENT
;
; Input(s):     IXReg = Application ID (2 Bytes)
;                   LOW(IXReg) = Application Type
;                   HIGH(IXReg)= Application Instance
;
; Output(s):    Success: AReg=App Index
;               Fail   : AReg=0FFH 
;
; Destroyed:    AReg,IXReg,IYReg,HLReg
;
; Macro Change History:
;
;               05/28/2000 HSB - Created Macro
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

CORE_APP_ID_PRESENT MACRO

                car coreAppIdPresent

        CALLS   SUBROUTINE , 'coreAppIdPresent'

        ENDM



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Macro Name:   CORE_GET_APP_INDEX
;
; Description:  Given an App ID (2 bytes) check if 
;               the application is already present in the ACD list 
;               Returns the App index if present otherwise 0xFF
;
; Assumptions:  None
;
; Usage:        CORE_GET_APP_INDEX
;
; Input(s):     IXReg = Application ID (2 Bytes)
;                   LOW(IXReg) = Application Type
;                   HIGH(IXReg)= Application Instance
;
; Output(s):    Success: AReg=App Index
;               Fail   : AReg=0FFH 
;
; Destroyed:    AReg,IXReg,IYReg,HLReg
;
; Macro Change History:
;
;               05/28/2000 HSB - Created Macro
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

CORE_GET_APP_INDEX  MACRO

                car coreGetAppIndex

        CALLS   SUBROUTINE , 'coreGetAppIndex'

        ENDM


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Macro Name:  CORE_GET_APP_INDEX_FROM_APP_TYPE
;
; Description:  Given an App Type (1 bytes) check if we have an application with that type.
;               If more than one application matches the same type, the first application
;               found based on the mode list table will be selected.
;
;               Returns the App index if present otherwise 0xFF.
;               
;
; Assumptions:  None
;
; Usage:        CORE_GET_APP_INDEX_FROM_APP_TYPE
;
; Input(s):     AReg = Application Type
;
; Output(s):    Success: AReg=App Index
;               Fail   : AReg=0FFH 
;
; Destroyed:    AReg,BReg,IYReg,HLReg
;
; Macro Change History:
;
;               06/08/2000 HSB - Created Macro
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

CORE_GET_APP_INDEX_FROM_APP_TYPE    MACRO

                car coreGetAppIndexFromAppType

        CALLS   SUBROUTINE , 'coreGetAppIndexFromAppType'

        ENDM


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Macro Name:   CORE_ALLOCATE_ACD
;
; Description:  Given an App ID Allocate a new entry in ACD
;
; Assumptions:  None
;
; Usage:        CORE_ALLOCATE_ACD
;
; Input(s):     IXReg = Application ID of the new application to initialize
;                       LOW(IXReg)  = Application Type
;                       HIGH(IXReg) = Application Instance
;
; Output(s):    Success: AReg = Application Index
;               Fail   : AReg = COREERRORCODE
;
; Destroyed:    AReg,BReg,IXReg,IYReg,HLReg
;
; Macro Change History:
;
;               05/28/2000 HSB - Created Macro
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

CORE_ALLOCATE_ACD   MACRO

                car coreAllocateACD

        CALLS   SUBROUTINE , 'coreAllocateACD'

        ENDM



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Macro Name:   CORE_GET_MODE_LIST_INDEX 
;
; Description:  Given an App Index, get index in Mode list
;
; Assumptions:  None
;
; Usage:        CORE_GET_MODE_LIST_INDEX
;
; Input(s):     AReg=Application Index
;
; Output(s):    Success: AReg=the index in mode list
;               Fail   : AReg=COREERRORCODE
;
; Destroyed Registers (AReg,BReg,HLReg)
;
; Macro Change History:
;
;               05/28/2000 HSB - Created Macro
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

CORE_GET_MODE_LIST_INDEX    MACRO

                car coreGetModeListIndex

        CALLS   SUBROUTINE , 'coreGetModeListIndex'

        ENDM



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Macro Name:   CORE_CHECK_HEAP_SIZE        
;
; Description:  Given a Heap requirement, Check if it fits the free memory
;
; Assumptions:  None
;
; Usage:        CORE_CHECK_HEAP_SIZE
;
; Input(s):     IYReg= Heap requirement first byte (Heap requirement 2 bytes)
;
; Output(s):    CarryFlag=0 : means that the required memory is available
;       CarryFlag=1 : means that the required memory is NOT available
;
; Destroyed:    AReg,BReg,HLReg
;
; Macro Change History:
;
;               05/29/2000 HSB - Created Macro
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

CORE_CHECK_HEAP_SIZE    MACRO

                car coreChkHeapSize

        CALLS   SUBROUTINE , 'coreChkHeapSize'

        ENDM



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Macro Name:   CORE_ALLOCATE_APP
;
; Description:  Allocate an Application
;               - Reserve an ACD and ACB. Set the ACB addresses 
;               - Allocate Requested Resources
;               - Allocate Requested Heap Space
;
; Assumptions:  - The Application does not exist in the ACBs
;               - Note that for the EEPROM application they will have 0 in the
;                 required heap size location
;
; Usage:        CORE_ALLOCATE_APP
;
; Input(s):     IXReg - Pointer to the Application Initialization Parameter Table.  This table defines how
;                       the application is setup and its requirements.
;
; Output(s):    Pass:   AReg = CORENULL
;               Fail:   AReg = COREERRORCODE
;
; Macro Change History:
;
;               05/11/2000 HSB - Created Macro     
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

CORE_ALLOCATE_APP   MACRO

                car coreAllocateApp

        CALLS   SUBROUTINE , 'coreAllocateApp'

        ENDM



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Macro Name:   CORE_DELETE_ALL_APP
;
; Description:  Delete all the applications except TOD and Comm
;
; Assumptions:  This is called only from the Communication mode
;
; Usage:        CORE_DELETE_ALL_APP
;
; Input(s):     None
;
; Output(s):    None
;
; Macro Change History:
;
;               05/11/2000 HSB - Created Macro     
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

CORE_DELETE_ALL_APP MACRO

                car coreDeleteAllApp

        CALLS   SUBROUTINE , 'coreDeleteAllApp'

        ENDM





