; Sources.Entries

        GET     Sources.Ident
;--------------------------------------------------------
Alphabet
        Debug   xx,"English : Alphabet entry"

        MOV     r0,#Alphabet_IDENT
        MOV     PC,LR

;--------------------------------------------------------
AlphabetIdent
        Debug   xx,"English : AlphabetIdentifier entry"

        ADR     r0,Alphabet_IdentString
        MOV     PC,LR





;--------------------------------------------------------
SelectKeyboardHandler

        Push    "r0,LR"

        ADR     r0,keyboard_command
        SWI     XOS_CLI
        STRVS   r0,[SP]

        Pull    "r0,PC"


;--------------------------------------------------------
WriteDirection

        MOV     r0,#(WriteDirection_LeftToRight :OR: WriteDirection_UpToDown :OR: WriteDirection_HorizontalLines)
        MOV     PC,LR

;--------------------------------------------------------

 
CharacterPropertyTable

        TEQ     r1,#Property_Control
        ADREQL  r0,ControlTable
        MOVEQ   PC,LR
        TEQ     r1,#Property_Uppercase
        ADREQL  r0,UppercaseTable
        MOVEQ   PC,LR
        TEQ     r1,#Property_Lowercase
        ADREQL  r0,LowercaseTable
        MOVEQ   PC,LR
        TEQ     r1,#Property_Alpha
        ADREQL  r0,AlphaTable
        MOVEQ   PC,LR
        TEQ     r1,#Property_Punctuation
        ADREQL  r0,PunctuationTable
        MOVEQ   PC,LR
        TEQ     r1,#Property_Space
        ADREQL  r0,SpaceTable
        MOVEQ   PC,LR
        TEQ     r1,#Property_Digit
        ADREQL  r0,DigitTable
        MOVEQ   PC,LR
        TEQ     r1,#Property_XDigit
        ADREQL  r0,XDigitTable
        MOVEQ   PC,LR
        TEQ     r1,#Property_Accented
        ADREQL  r0,AccentedTable
        MOVEQ   PC,LR
        TEQ     r1,#Property_ForwardFlow
        ADREQL  r0,ForwardFlowTable
        MOVEQ   PC,LR
        TEQ     r1,#Property_BackwardFlow
        ADREQL  r0,BackwardFlowTable
        MOVEQ   PC,LR

        ADR     r0,ErrorBlock_UnknownProperty
        B       message_errorlookup

ErrorBlock_UnknownProperty
        DCD     0
        DCB     "UnkProp",0
        ALIGN

;--------------------------------------------------------
GetLowerCaseTable
        
        ADRL    r0,ToLowerTable
        MOV     PC,LR

;--------------------------------------------------------
GetUpperCaseTable

        ADRL    r0,ToUpperTable
        MOV     PC,LR

;--------------------------------------------------------
GetControlTable

        ADRL    r0,ToControlTable
        MOV     PC,LR

;--------------------------------------------------------
GetPlainTable

        ADRL    r0,ToPlainTable
        MOV     PC,LR

;--------------------------------------------------------
GetValueTable

        ADRL    r0,ToValueTable
        MOV     PC,LR

;--------------------------------------------------------
GetRepresentationTable

        ADRL    r0,ToRepresentationTable
        MOV     PC,LR

;--------------------------------------------------------
; Collate
;     Entry:
;             R1 -> String 1   (0 terminated)
;             R2 -> String 2   (0 terminated)
;             R3 = flags
;                        bit 0 - Ignore case.
;                        bit 1 - Ignore accents
;     Exit:
;             R0   <0 if S1 < S2 
;                  =0 if S1 = S2
;                  >0 if S1 > S2 
;             Other registers preserved.
;
;             Z set if equal (EQ).
;             C set and Z clear if S1 > S2 (HI)
;             N set and V clear if S1 < S2 (LT)
;
;             V set if error.
    
Collate

        Push    "r1-r7,LR"

        TST     r3,#Collate_IgnoreCase
        ADRNEL  r4,ToLowerTable
        TST     r3,#Collate_IgnoreAccent
        ADRNEL  r5,ToPlainTable
        ADRL    r7,SortValueTable

01
        LDRB    r14,[r1],#1
        LDRB    r6 ,[r2],#1

        Debug   xx,"r14,r6",r14,r6

        TST     r3,#Collate_IgnoreAccent
        LDRNEB  r14,[r5,r14]
        LDRNEB  r6 ,[r5,r6]

        Debug   xx,"r14,r6",r14,r6

        TST     r3,#Collate_IgnoreCase
        LDRNEB  r14,[r4,r14]
        LDRNEB  r6 ,[r4,r6]

        Debug   xx,"r14,r6",r14,r6

        LDRB    r14,[r7,r14]
        LDRB    r6 ,[r7,r6]

        Debug   xx,"r14,r6",r14,r6

        SUBS    r0,r14,r6
        Pull    "r1-r7,PC",NE           ; Not equal, result is result of compare.
        TEQ     r14,#0
        Pull    "r1-r7,PC",EQ           ; Both 0 -> Strings equal.

        B       %BT01                   ; Equal but not 0, get next char.


; ------------------------------------------------------------------------
; ReadTimeZones
;
; In: 
;       -
; Out:
;       R0 - Pointer to name of standard TZ
;       R1 - Pointer to name of summer TZ.
;       R2 - Offser from UTC to standard time
;       R3 - Offset from UTC to summer time.
; 
ReadTimeZones
        STMDB   sp!, {lr}

        MOV     r0, #ReadCMOS
        MOV     r1, #TimeZoneCMOS
        SWI     XOS_Byte

        MOVVC   r2, r2, LSL #24
        MOVVC   r2, r2, ASR #24

        ADDVC   r0, r2, r2, ASL #1
        ADDVC   r0, r2, r0, ASL #3
        RSBVC   r0, r0, r0, ASL #4
        RSBVC   r0, r0, r0, ASL #4

        LDRVC   R2,=NODSTOffset
        LDRVC   R3,=DSTOffset

        ADDVC   r2, r2, r0, ASL #4
        ADDVC   r3, r3, r0, ASL #4

        ADRVC   R0,NODSTName
        ADRVC   R1,DSTName

        LDMIA   sp!, {pc}

        GET     Sources.TimeZones
        ALIGN

; ------------------------------------------------------------------------
; ReadSymbols
;
; In: 
;       R1 - Reason code:
;               0 Return pointer to 0 terminated decimal point string.
;               1 Return pointer to 0 terminated thousands separator
;               2 Return pointer byte list containing the size of each
;                 group of digits in formatted nonmonetary quantities.
;                 255   = No further grouping
;                   0   = Repeat last grouping for rest of number
;                 other = Size of current group, the next byte contains
;                         the size of the next group of dogits before the
;                          current group.
;               3 Return pointer to 0 terminated international currency symbol.
;               4 Return pointer to 0 terminated currency symbol in local alphabet.
;               5 Return pointer to 0 terminated decimal point used for monetary quantities
;               6 Return pointer to 0 terminated thousands separator for monetary quantities
;               7 Return pointer byte list containing the size of each
;                 group of digits in formatted monetary quantities.
;               8 Return pointer to 0 terminated positive sign used for monetary quantities
;               9 Return pointer to 0 terminated negative sign used for monetary quantities
;              10 Return number of fractional digits to be displayed in an internationally
;                 formatted monetay quantity
;              11 Return number of fractional digits to be displayed in a formatted monetay
;                 quantity
;              12 Return 1 If the currency symbol precedes the value for a nonnegative
;                          formatted monetary quantity
;                        0 If the currency symbol succeeds the value for a nonnegative
;                          formatted monetary quantity
;              13 Return 1 If the currency symbol is separated by a space from the value for a
;                          nonnegative formatted monetary quantity
;                        0 If the currency symbol is not separated by a space from the value for a
;                          nonnegative formatted monetary quantity
;              14 Return 1 If the currency symbol precedes the value for a negative
;                          formatted monetary quantity
;                        0 If the currency symbol succeeds the value for a negative
;                          formatted monetary quantity
;              15 Return 1 If the currency symbol is separated by a space from the value for a
;                          negative formatted monetary quantity
;                        0 If the currency symbol is not separated by a space from the value for a
;                          negative formatted monetary quantity
;
;              16 Return for a nonnegative formatted monetary quantity
;                        0 If there are parentheses arround the quantity and currency symbol.
;                        1 If the sign string precedes the quantity and currency symbol.
;                        2 If the sign string succeeds the quantity and currency symbol.
;                        3 If the sign string immediately precedes the currency symbol.
;                        4 If the sign string immediately succeeds the  currency symbol.
;              17 Return for a negative formatted monetary quantity
;                        0 If there are parentheses arround the quantity and currency symbol.
;                        1 If the sign string precedes the quantity and currency symbol.
;                        2 If the sign string succeeds the quantity and currency symbol.
;                        3 If the sign string immediately precedes the currency symbol.
;                        4 If the sign string immediately succeeds the  currency symbol.
;              18 Return pointer to 0 terminated list separator 
; Out:
;       R0 - Requested value.
ReadSymbols
        Push    "LR"        

        ADR     R14,SymbolTable
        ADD     R0,R14,R1,ASL #2
        LDR     R0,[R0]
        CMP     R0,#20
        ADDGE   R0,R0,R14

        Pull    "PC"

SymbolTable      
        DCD     decimal_point           - SymbolTable
        DCD     thousands_sep           - SymbolTable
        DCD     grouping                - SymbolTable
        DCD     int_curr_symbol         - SymbolTable
        DCD     currency_symbol         - SymbolTable
        DCD     mon_decimal_point       - SymbolTable
        DCD     mon_thousands_sep       - SymbolTable
        DCD     mon_grouping            - SymbolTable
        DCD     positive_sign           - SymbolTable
        DCD     negative_sign           - SymbolTable
        DCD     int_frac_digits          
        DCD     frac_digits             
        DCD     p_cs_precedes
        DCD     p_sep_by_space
        DCD     n_cs_precedes
        DCD     n_sep_by_space
        DCD     p_sign_posn
        DCD     n_sign_posn
        DCD     list_symbol             - SymbolTable

        GET     Sources.Symbols
        ALIGN

;---------------------------------------------------------------------------------
;ReadCalendarInformation
;
;In:
;   R1 = Pointer to 5 byte UTC time value.
;   R2 = Pointer to an 11 word buffer
;
;Out:
;
;   R1,R2 Preserved.
;
;   [R2]    = Number of first working day in the week.
;   [R2+4]  = Number of last working day in the week.
;   [R2+8]  = Number of months in the current year.  
;                 (current = one in which given time falls)
;   [R2+12] = Number of days in the current month.
;
;   [R2+16] = Max length of AM/PM string. 
;   [R2+20] = Max length of WE string.
;   [R2+24] = Max length of W3 string.
;   [R2+28] = Max length of DY string.
;   [R2+32] = Max length of ST string (May be 0).
;   [R2+36] = Max length of MO string.
;   [R2+40] = Max length of M3 string.
;   [R2+44] = Max length of TZ string.
;
GetCalendarInformation
        Push    "r0-r11,LR"

        LDR     R0,FirstWorkDay         ; First working day in week 1=Sunday 7=Saturday
        STR     R0,[R2,#0]
        LDR     R0,LastWorkDay          ; Last  working day in week 1=Sunday 7=Saturday
        STR     R0,[R2,#4]
        LDR     R0,NumberOfMonths       ; Number of month in a year
        STR     R0,[R2,#8]

        LDR     R0,MaxAMPMLength        ; Max length of AM PM String
        STR     R0,[R2,#16]
        LDR     R0,MaxWELength          ; Max length of full day name
        STR     R0,[R2,#20]
        LDR     R0,MaxW3Length          ; Max length of short day name
        STR     R0,[R2,#24]
        LDR     R0,MaxDYLength          ; Max length of day in month
        STR     R0,[R2,#28]
        LDR     R0,MaxSTLength          ; Max length of st nd rd th ... string
        STR     R0,[R2,#32]
        LDR     R0,MaxMOLength          ; Max length of full month name.
        STR     R0,[R2,#36]
        LDR     R0,MaxM3Length          ; Max length of short month name.
        STR     R0,[R2,#40]
        LDR     R0,MaxTZLength          ; Max length of short month name.
        STR     R0,[R2,#44]   

        BL      GetTimeValues
        BVS     %FT02
        ADRL    R0,MonthLengths
        LDRB    R0,[R0,R1]              ; Get length of month
        CMP     R1,#2                   ; Is Feb ?
        BNE     %FT01

        TST     R6, #3                  ; is year multiple of 4
        MOVNE   R0,#28                  ; no, then 29 Feb is bad
        BNE     %FT01

        TEQ     R6, #0                  ; is it a century year ?
        BNE     %FT01                   ; no, then 29 Feb is good

        TST     R5, #3                  ; is it a multiple of 400 ?
        MOVNE   R0,#28                  ; no, then 29 Feb is bad
01
        LDR     R2,[SP,#2*4]
        STR     R0,[R2,#12]
02
        STRVS   r0,[SP]
        Pull    "r0-r11,PC"


        GET     Sources.Calendar
        ALIGN

;---------------------------------------------------------------------------------
;NameToNumber
;
;In:
;   R1 = Pointer to territory name. 
;
;Out:
;   R0 = 0 - Unknown territory
;        Else territory number.
NameToNumber     ROUT
        Push    "r1-r7,LR"

        BL      open_messages_file

; Enumerate all territory name tokens (TRnn)
        ADR     r0,message_file_block+4
        MOV     R4,#0                   ; First call
        MOV     R7,#1                   ; Territory 1 is first.
        
01
        ADR     R1,territory_token
        SUB     SP,SP,#8                ; We know tokens aren't long.
        MOV     R2,SP
        MOV     R3,#8
        SWI     XMessageTrans_EnumerateTokens
        ADDVS   SP,SP,#8                ; junk stack frame
        Pull    "r1-r7,PC",VS
        CMP     R2,#0
        ADDEQ   SP,SP,#8
        MOVEQ   r0,#0
        Pull    "r1-r7,PC",EQ

; Get Message

        DebugS  xx,"Next token is ",R2
        MOV     R1,R2                   ; Token.
        MOV     R2,#0                   ; Don't copy message !
        SWI     XMessageTrans_Lookup
        ADD     SP,SP,#8                ; Junk token.
        Pull    "r1-r7,PC",VS
        
; Got message, now compare with territory name in string.

        LDR     R1,[SP,#0]              ; get user R1
02
        LDRB    R14,[R2],#1
        CMP     R14,#10
        BEQ     %FT03                   ; End of message
        ORR     R14,R14,#&20

        LDRB    R10,[R1],#1
        CMP     R10,#0
        MOVEQ   r0,#0
        Pull    "r1-r7,PC",EQ
        ORR     R10,R10,#&20

        CMP     R14,R10
        BEQ     %BT02                   ; Try next character.
        ADD     r7,r7,#1
        B       %BT01                   ; Try next month.
03
        LDRB    R10,[R1],#1
        CMP     R10,#" "
        BGE     %BT01                   ; Not end of user input !
                            
        MOV     r0,r7
        Pull    "r1-r7,PC"

territory_token
        DCB     "TR*",0
        ALIGN

        LNK     Sources.Tables


