;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Copyright (c) 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    : cntdisp.asm
; Purpose      : Counter Common Display Routines
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Module Name : cntDisplayArrowOnSDM
; Description : Displays an arrow on the small dot matrix.  The position will
;                 depend on the count direction.
; Assumptions : IYReg - Counter ASD Address.
; Input(s)    : None
; Output(s)   : None
;               ( Destroyed: BAReg, HLReg, IXReg )
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

        IF @DEF('SUBROUTINE')
            UNDEF SUBROUTINE
        ENDIF
        DEFINE  SUBROUTINE      "'cntDisplayArrowOnSDM'"

        GLOBAL  cntDisplayArrowOnSDM
        GLOBAL  cntDisplayArrowDownOnSDM
        GLOBAL  cntDisplayArrowUpOnSDM

cntDisplayArrowOnSDM:

                ; Get the status flags.
                ld      A, [IY + CNTFLAGSOFFSET]
                
                ; Check the counting direction.
                bit     A, #bCNTCountDown
                jr      Z, cntDisplayArrowUpOnSDM
                
cntDisplayArrowDownOnSDM:

                ; Load the character to be displayed.
                ld      L, #DM5_DOWNARROW

                jr      cntDispArrowOnSDMDisplay

cntDisplayArrowUpOnSDM:

                ; Load the character to be displayed.
                ld      L, #DM5_UPARROW

cntDispArrowOnSDMDisplay:

                ;--------------------------------------------------------------
                ; Display proportional width character.
                ; Destroys BAReg, HLReg, IXReg.
                ; Input: LReg - Characer to be displayed.
                ;        IXReg- Starting DM column.
                ;--------------------------------------------------------------
                ld      IX, #LCDUPPERDMCOL1
                LCD_DISP_SMALL_PROP_WIDTH_DM_CHAR

                ret


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Module Name : cntDisplayCounterData
; Description : Displays the counter data on the main dot matrix using large fonts.
; Assumptions : None
; Input(s)    : None
; Output(s)   : None
;               ( Destroyed: HLReg, IXReg, BAReg )
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

        IF @DEF('SUBROUTINE')
            UNDEF SUBROUTINE
        ENDIF
        DEFINE  SUBROUTINE      "'cntDisplayCounterData'"

        GLOBAL  cntDisplayCounterData

cntDisplayCounterData:

                ;--------------------------------------------------------------
                ; Display a large-font, 3-digit DM data with zero suppression 
                ;   on leading digit positions.
                ; Destroys BAReg, HLReg, IXReg.
                ; Input:  BReg - 100's digit BCD data.
                ;         AReg - Packed 10's and 1's digit BCD data.
                ;         IXReg- Starting DM column.
                ;--------------------------------------------------------------
                ld      IY, [CORECurrentASDAddress]
                ld      A, [IY + CNTDATALOOFFSET]
                ld      B, [IY + CNTDATAHIOFFSET]
                ld      IX, #LCDBIGCHARDMCOL8
                LCD_DISP_BIG_3DIGIT_DM_DATA_NO_LSD_SUP

                ret


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Module Name : cntDisplayCountDirection
; Description : Display "COUNT DOWN" or "COUNT UP" and "Arrow Down" or "Arrow Up" 
;                 on main DM and SDM respectively.
; Assumptions : None
; Input(s)    : None
; Output(s)   : None
;               ( Destroyed: HLReg, IXReg, BAReg )
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

        IF @DEF('SUBROUTINE')
            UNDEF SUBROUTINE
        ENDIF
        DEFINE  SUBROUTINE      "'cntDisplayCountDirection'"

        GLOBAL  cntDisplayCountDirection

cntDisplayCountDirection:

                ; Get the status flags and check the counting direction.
                ld      IY, [CORECurrentASDAddress]
                ld      A, [IY + CNTFLAGSOFFSET]
                bit     A, #bCNTCountDown
                jr      Z, cntDisplayDirectionArrowUp

                ; Display "COUNT DOWN" on the main DM.
                LCD_DISP_SMALL_DM_MSG_COUNT_DOWN

                ; Display arrow down on SDM.
                jr      cntDisplayArrowDownOnSDM    ; **EXTERNAL JUMP

cntDisplayDirectionArrowUp:

                ; Display "COUNT UP" on the main DM.
                LCD_DISP_SMALL_DM_MSG_COUNT_UP
                    
                ; Display arrow up on SDM.
                jr      cntDisplayArrowUpOnSDM      ; **EXTERNAL JUMP
                

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Module Name : cntClearL2AndSDM
; Description : Clears the display in Line 2 and SDM.
; Assumptions : None
; Input(s)    : None
; Output(s)   : None
;               ( Destroyed: HLReg, IXReg, BAReg )
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

        IF @DEF('SUBROUTINE')
            UNDEF SUBROUTINE
        ENDIF
        DEFINE  SUBROUTINE      "'cntClearL2AndSDM'"

        GLOBAL  cntClearL2AndSDM

cntClearL2AndSDM:

                ; Clear SDM.
                LCD_CLEAR_UPPER_DM
                
                ; Clear line 2.
                LCD_CLR_MAIN_DM_LINE2

                ret


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Module Name : cntSetRedisplayAndReqBlink
; Description : Redisplay everything and request blinking on the editable field.
;                 Used only in set state.
; Assumptions : IYReg - Counter ASD Address.
; Input(s)    : None
; Output(s)   : None
;               ( Destroyed: HLReg, IXReg, BAReg )
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

        IF @DEF('SUBROUTINE')
            UNDEF SUBROUTINE
        ENDIF
        DEFINE  SUBROUTINE      "'cntSetRedisplayAndReqBlink'"

        GLOBAL  cntSetRedisplayAndReqBlink

cntSetRedisplayAndReqBlink:

                CORE_REQ_BLINK_4HZ

                ; Load the data that contains the current setting item.
                ld      A, [CNTTempFlags]
                bit     A, #bCNTSetDirection
                jr      Z, cntSetDispAndReqBlinkSetData

                ; Change the couting direction.

                ; Display "COUNT DOWN" or "COUNT UP" and "Arrow Down" or 
                ;   "Arrow Up" on main DM and SDM respectively.
                car     cntDisplayCountDirection

                ; Setup the routines to be called for blinking.
                LCD_WRITE_4HZ_GEN_BLINK_DISP_ROUTINE_ADDR   cntDisplayCountDirection
                LCD_WRITE_4HZ_GEN_BLINK_CLR_ROUTINE_ADDR    cntClearL2AndSDM

                ret


cntSetDispAndReqBlinkSetData:

                ; Change the counter value.
                
                ; Displays the counter data on the main dot matrix using large
                ;   fonts.
                car     cntDisplayCounterData

                ; Display "SET" on 9 segment.
                LCD_DISP_SEG_MSG_SET
        
                ; Setup the routines to be called for blinking.
                LCD_WRITE_4HZ_GEN_BLINK_DISP_ROUTINE_ADDR   cntDisplayCounterData
                LCD_WRITE_4HZ_GEN_BLINK_CLR_ROUTINE_ADDR    lcdClearMainDM

                ret
