; > adfs::TimSource.!Inter.InterBody

; ************************************************************
; ***    C h a n g e   L i s t  (better late than never!)  ***
; ************************************************************

; Date       Description
; ----       -----------
; 16-Mar-88  Set UseWriteN option, removed "(WriteN version)" in module help
;            string, changed service code so it could be reassembled now that
;            Inter_Highest has changed.
; 28-Apr-88  Message compression technology added (involving splitting into
;            two versions)
; 04-May-88  Fixed bug in service code which stopped the DefineFont service
;            being claimed, due to SWI OS_WriteN call using R1.
; 11-May-88  Added *Alphabets, *Countries
; 12-May-88  Compressed "*Alphabets" in *Alphabet help
; 09-Sep-88  Removed ' supported' from *Alphabets and *Countries
;            Added Canada1, Canada2, Canada, ISO1
;            Apostrophe now vertical in Latin1-4, Greek
;            Currency symbol now a windmill in Latin1-4
; 27-Nov-89  Added GET <Hdr>.File, so it assembles again
;            (no change to object code)
; 31-Jan-90  Added first iteration of Cyrillic (ISO) and Cyrillic2 (IBM) alphabets
; 01-Feb-90  Added DBell corrections to Cyrillic(2) characters.
; 05-Mar-90  Added Hebrew alphabet / country Israel (26).
; 20-Jun-91  TMD Changed <Hdr> to Hdr:
; 08-Jul-91  ECN Message extraction
; 04-Oct-91  TMD Fixed bug G-RR-2396 - character &B9 in Latin3 (Turkish i)
;                 should not have dot
;            TMD Added Acorn extensions (characters &8C to &9F) to Latin1-4.
; 10-Oct-91  OSS Added country Mexico.
; 18-Nov-91  OSS Added country LatinAm. Also note that the Mexican Risc OS 2
;            version of this module is version 1.15, even though there
;            has been a different 1.15 in the past.
; 19-Feb-92  TMD 1.20: corrected characters &FB, &FD in Greek font (bug G-RR-2358)
;                      added Welsh characters to Latin1
; 19-Feb-92  TMD 1.21: removed use of <Hdr> in make sequence
; 19-Feb-92  TMD 1.22: removed use of <Hdr> from IntHelpBod as well!
; 21-Apr-92  RM  1.23: corrected Hebrew Final Zade character
; 22-Apr-92  TMD 1.24: removed wild cards from message filename

        GET     Hdr:ListOpts
        GET     Hdr:Macros
        GET     Hdr:System
        GET     Hdr:CMOS
        GET     Hdr:ModHand
        GET     Hdr:Services
        GET     Hdr:Proc
        GET     Hdr:File
        GET     Hdr:NewErrors
        GET     Hdr:MsgTrans

        LEADR   Module_LoadAddr

        GBLL    UseWriteN
UseWriteN SETL {TRUE}

TAB     *       9
LF      *       10
FF      *       12
CR      *       13

OsbyteSetCountry * &46
OsbyteSetAlphKey * &47

NameBufferSize * 16     ; no countries that long

        GBLA    TableAddress
        GBLS    TableName

        MACRO
$label  InterTable $name
$label
TableAddress SETA $label-Module_BaseAddr
TableName SETS "$name"
        MEND

        MACRO
        InterEntry $value, $name
        [ "$name"<> "UNK001"
        DCW     ($TableName.$name-Module_BaseAddr-TableAddress):AND:&FFFF
        =       ($TableName.$name-Module_BaseAddr-TableAddress):SHR:16
        =       $value
        ]
        MEND

        MACRO
        InterEnd
        &       0
        MEND

        ^       0, wp

MessageFile_Block #     16              ; File handle for MessageTrans
MessageFile_Open  #     4               ; Opened message file flag

; No workspace needed yet

Inter_WorkspaceSize * :INDEX: @

; **************** Test Module code starts here **********************

Module_BaseAddr

        DCD     0
        DCD     Inter_Init    -Module_BaseAddr
        DCD     Inter_Die     -Module_BaseAddr
        DCD     Inter_Service -Module_BaseAddr
        DCD     Inter_Title   -Module_BaseAddr
        DCD     Inter_HelpStr -Module_BaseAddr
        DCD     Inter_HC_Table-Module_BaseAddr

Inter_Title
        =       "International", 0

Inter_HelpStr
        =       "International"
        [ UseWriteN :LAND: {FALSE}
        =       " (WriteN version)"
        ]
        =       TAB
        =       "1.24"
        =       " (22 Apr 1992)"
        [ Arthur120
        =       " (Arthur 1.20 version)"
        ]
        =       0
        ALIGN

Inter_HC_Table
        Command Alphabet, 1, 0
        Command Country, 1, 0
        Command Keyboard, 1, 0
        Command Country, 0, 0, Status_Keyword_Flag, ConCountry
        Command Alphabets, 0, 0
        Command Countries, 0, 0
        &       0


; *****************************************************************************

        GBLS    HelpFile
        [ Arthur120
HelpFile SETS   "<Dir>.IntHelp"
        |
HelpFile SETS   "<Dir>.IntHelpTok"
        ]
        GET     "$HelpFile"

Inter_Init
        STMDB   sp!, {lr}

        LDR     r2, [r12]               ; Hard or soft init ?
        TEQ     r2, #0
        BNE     %FT00

; Hard init

        LDR     r3, =Inter_WorkspaceSize
        MOV     r0, #ModHandReason_Claim
        SWI     XOS_Module
        LDMVSIA sp!, {pc}

        STR     r2, [r12]

00      MOV     r12, r2

        MOV     r14, #0
        STR     r14, MessageFile_Open

        LDMIA   sp!, {pc}^

Inter_Die
        STMDB   sp!, {lr}
        LDR     r12, [r12]
        LDR     r0, MessageFile_Open
        CMP     r0, #0
        ADRNE   r0, MessageFile_Block
        SWINE   XMessageTrans_CloseFile
        LDMIA   sp!, {pc}^

; *****************************************************************************
;
;       Alphabets_Code - Process *ALPHABETS command
;
; in:   R0 -> rest of line
;       R1 = number of parameters
;
; out:  R0-R6, R12 corrupted
;

Alphabets_Code ENTRY
        LDR     r12, [r12]
        ADRL    R0, AlphabetsString     ; R0 -> "Alphabets",0
        MOV     R2, #Inter_ANoToANa
        BL      PrintInfo
        EXIT

AlphabetsString
        DCB     "M06", 0

; *****************************************************************************
;
;       Countries_Code - Process *COUNTRIES command
;
; in:   R0 -> rest of line
;       R1 = number of parameters
;
; out:  R0-R6, R12 corrupted
;

Countries_Code ENTRY
        LDR     r12, [r12]
        ADRL    R0, CountriesString     ; R0 -> "Countries",0
        MOV     R2, #Inter_CNoToCNa
        BL      PrintInfo
        EXIT

CountriesString
        DCB     "M07", 0

; *****************************************************************************
;
;       PrintInfo - Print list of alphabets/countries
;
; in:   R0 -> string to print first
;       R2 = international service sub-reason code
;

InfoBufferSize * 512

PrintInfo ROUT
        Push    R14
        BL      message_write0
        SWIVC   XOS_WriteS
        =       ":", 10, 13, 0
        ALIGN
        Pull    PC, VS
        SUB     R6, R13, #1                     ; buffer limit (allow for term)
        SUB     R13, R13, #InfoBufferSize       ; allocate buffer on stack
        MOV     R4, R13                         ; start of buffer
        MOV     R3, #0                          ; country number starts at zero
10
        SUBS    R5, R6, R4                      ; R5 = buffer length
        BCC     %FT20                           ; [buffer full]
        BL      OfferInterService               ; offer service
        MOVEQ   R1, #TAB                        ; if claimed, store TAB after
        STREQB  R1, [R4, R5]!                   ; string, then move on one more
        ADDEQ   R4, R4, #1                      ; to skip TAB character

        ADD     R3, R3, #1                      ; try next number
        EORS    R0, R3, #128                    ; do 0..127 (R0 := 0 at end)
        BNE     %BT10
20
        STREQB  R0, [R4, #-1]                   ; put zero terminator on string
        MOV     R0, R13
        SWI     XOS_PrettyPrint                 ; print out buffer
        SWIVC   XOS_NewLine
        ADD     R13, R13, #InfoBufferSize       ; junk buffer
        Pull    PC

; *****************************************************************************
;
;       Alphabet_Code - Process *ALPHABET command
;
; in:   R0 -> rest of line
;       R1 = number of parameters
;
; out:  R0-R6, R12 corrupted
;

Alphabet_Code ENTRY
        LDR     r12, [r12]
        TEQ     R1, #0                  ; just *ALPHABET ?
        BNE     %FT10                   ; [no, so a setting of alphabet]

; print current alphabet to screen

        MOV     R1, #&7F                ; indicate just read alphabet
        MOV     R3, #Inter_ANoToANa     ; for later

; and drop thru to ...

PrintAValue                             ; used by *ALPHABET and *KEYBOARD
        MOV     R0, #OsbyteSetAlphKey
PrintAValue2                            ; used by *COUNTRY
        SWI     XOS_Byte
        EXIT    VS

; R1 = current alphabet/country number

        MOV     R2, R3                  ; appropriate reason code
        MOV     R3, R1                  ; alphabet/country no. in R3
PrintAValue3
        SUB     R13, R13, #NameBufferSize ; make room for name buffer
        MOV     R4, R13                 ; R4 -> buffer
        MOV     R5, #NameBufferSize-1
        BL      OfferInterService
        STREQB  R1, [R4, R5]            ; if claimed, terminate name with zero
        MOVEQ   R0, R4                  ; R0 -> string
        ADRNE   R0, UnknownString       ; else print unknown
        BNE     PrintAValue4
        SWI     XOS_Write0
        B       PrintAValue5
PrintAValue4
        BL      message_write0
PrintAValue5
        SWIVC   XOS_NewLine
        ADD     R13, R13, #NameBufferSize ; restore stack pointer
        EXIT

UnknownString
        =       "M03", 0
        ALIGN

; set alphabet from name pointed to by R0

10
        MOV     R3, R0                  ; R3 -> name
        MOV     R2, #Inter_ANaToANo     ; try an alphabet name first
        BL      OfferInterService

; if not an alphabet name, try a country name

        MOVNE   R2, #Inter_CNaToCNo     ; is it a country name ?
        BLNE    OfferInterService
        BNE     DoAlphabetError

; now R4 = alphabet number or country number

        MOV     R1, R4
        MOV     R0, #OsbyteSetAlphKey
        SWI     XOS_Byte
        EXIT

DoAlphabetError
        ADR     R0, AlphabetError
        BL      CopyError
        EXIT

AlphabetError MakeInternatErrorBlock UnknownAlphabet,,M00

; *****************************************************************************
;
;       Keyboard_Code - Process *KEYBOARD command
;
; in:   R0 -> rest of line
;       R1 = number of parameters
;
; out:  R0-R6, R12 corrupted
;

Keyboard_Code ENTRY
        LDR     r12, [r12]
        TEQ     R1, #0                  ; just *KEYBOARD ?
        BNE     %FT10                   ; [no, so a setting of keyboard]

; print current keyboard to screen

        MOV     R1, #&FF                ; indicate just read keyboard
        MOV     R3, #Inter_CNoToCNa     ; for later
        B       PrintAValue

; set keyboard from name pointed to by R0

10
        MOV     R3, R0                  ; R3 -> name
        MOV     R2, #Inter_CNaToCNo     ; only allow country names
        BL      OfferInterService
        BNE     DoKeyboardError         ; unknown keyboard

; now R4 = alphabet number

        ORR     R1, R4, #&80            ; top bit set => set keyboard
        MOV     R0, #OsbyteSetAlphKey
        SWI     XOS_Byte
        EXIT

DoKeyboardError
        ADR     R0, KeyboardError
        BL      CopyError
        EXIT

KeyboardError MakeInternatErrorBlock UnknownKeyboard,,M01

; *****************************************************************************
;
;       Country_Code - Process *COUNTRY command
;
; in:   R0 -> rest of line
;       R1 = number of parameters
;
; out:  R0-R6, R12 corrupted
;

Country_Code ENTRY
        LDR     r12, [r12]
        TEQ     R1, #0                  ; just *COUNTRY ?
        BNE     %FT10                   ; [no, so a setting of country]

; print current country to screen

        MOV     R1, #&7F                ; indicate just read keyboard
        MOV     R3, #Inter_CNoToCNa     ; for later
        MOV     R0, #OsbyteSetCountry
        B       PrintAValue2

; set country from name pointed to by R0

10
        MOV     R3, R0                  ; R3 -> name
        MOV     R2, #Inter_CNaToCNo     ; only allow country names
        BL      OfferInterService
        BNE     DoCountryError          ; unknown keyboard

; now R4 = country number

        MOV     R1, R4                  ; country number to set
        MOV     R0, #OsbyteSetCountry
        SWI     XOS_Byte
        EXIT

DoCountryError
        ADR     R0, CountryError
        BL      CopyError
        EXIT

CountryError MakeInternatErrorBlock UnknownCountry,,M02


; *****************************************************************************

OfferInterService
        Push    R14
        MOV     R1, #Service_International
        SWI     XOS_ServiceCall
        TEQ     R1, #0                  ; NB preserves V
        Pull    PC

; *****************************************************************************
;
;       ConCountry_Code - Handle *CONFIGURE and *STATUS
;
; in:   R0 = 0 => *Configure nowt
;       R0 = 1 => *Status
;       R0 > 1 => R0 -> command tail
;
; out:  V=0 => ok
;       V=1 => error
;               R0 = 0 => Bad Configure Option error
;               R0 = 1 => Numeric Parameter Needed
;               R0 = 2 => Configure parameter too big
;               R0 = 3 => R0 -> error block
;

ConCountry_Code ENTRY
        LDR     r12, [r12]
        CMP     R0, #1
        BEQ     %FT10                   ; *Status
        BHI     %FT20                   ; *Configure Country something

; *Configure nowt

        BL      message_writes
        =       "M04", 0
        SWIVC   XOS_NewLine
        EXIT

space4  DCB     "    ", 0
        ALIGN

; *Status

10
        MOV     R0, #&A1                ; read from CMOS RAM
        MOV     R1, #CountryCMOS
        SWI     XOS_Byte
        EXIT    VS

        BL      message_writes
        =       "M05", 0
        ADRVC   r0, space4
        SWIVC   XOS_Write0
        EXIT    VS

        MOV     R3, R2                  ; R3 = configured country number
        MOV     R2, #Inter_CNoToCNa
        B       PrintAValue3

; *Configure Country <country name>

20
        MOV     R3, R0                  ; R3 -> name
        MOV     R2, #Inter_CNaToCNo     ; only allow country names
        BL      OfferInterService
        BNE     DoCountryError          ; unknown keyboard

; now R4 = country number

        MOV     R2, R4
        MOV     R0, #&A2                ; write to CMOS RAM
        MOV     R1, #CountryCMOS
        SWI     XOS_Byte
        EXIT

; *****************************************************************************
;
;       Inter_Service - Main entry point for services
;
; in:   R1 = service reason code
;       R2 = sub reason code
;       R3-R5 parameters
;
; out:  R1 = 0 if we claimed it
;       R2 preserved
;       R3-R5 = ???
;

Inter_Service ROUT
        TEQ     R1, #Service_International      ; is it our service ?
        MOVNE   PC, R14                         ; no, then exit
        CMP     R2, #Inter_Highest              ; is it one we know ?
        ADDCC   PC, PC, R2, LSL #2              ; yes, go thru despatch
        MOV     PC, R14                         ; no, then exit

        B       DoCNaToCNo
        B       DoANaToANo
        B       DoCNoToCNa
        B       DoANoToANa
        B       DoCNoToANo
        B       DoDefine
        MOV     PC, R14                 ; new keyboard service is ignored by us

        ASSERT Inter_CNaToCNo = 0
        ASSERT Inter_ANaToANo = 1
        ASSERT Inter_CNoToCNa = 2
        ASSERT Inter_ANoToANa = 3
        ASSERT Inter_CNoToANo = 4
        ASSERT Inter_Define   = 5
        ASSERT Inter_Keyboard = 6
        ASSERT Inter_Highest = 7

; *****************************************************************************
;
;       DoDefine - Define a set of chars from a particular alphabet
;
; in:   R3 = alphabet number
;       R4 = min char to define
;       R5 = max char to define
;

DoDefine ENTRY "R0,R2,R6,R7"
        ADR     R6, FontPointers
        BL      LookupNumber
        TEQ     R1, #0
        EXIT    NE

; R7 now points to start of pointers for this font

        MOV     R6, R7                  ; save base pointer
10
        LDR     R0, [R7], #4            ; load data word
        TEQ     R0, #0                  ; end of table ?
        EXIT    EQ
        CMP     R5, R0, LSR #24         ; test if table char > max char
        EXIT    CC                      ; if so then finished
        CMP     R4, R0, LSR #24         ; test if table char < min char
        BHI     %BT10                   ; loop if so

; we have found a valid char to define

        SWI     XOS_WriteI+23
        BICVC   R2, R0, #&FF000000      ; R2 = offset to font bytes
        MOVVC   R0, R0, LSR #24         ; R0 = char to define
        SWIVC   XOS_WriteC
        [ UseWriteN
        ADDVC   R0, R2, R6              ; R0 now points to 8 bytes of font
        MOVVC   R1, #8
        SWIVC   XOS_WriteN
        MOV     R1, #0                  ; set R1 back to zero ALWAYS!
        BVC     %BT10
        |
        ADDVC   R2, R2, R6              ; R2 now points to 8 bytes of font
        LDMVCIA R2, {R0,R2}

        SWIVC   XOS_WriteC
        MOVVC   R0, R0, LSR #8
        SWIVC   XOS_WriteC
        MOVVC   R0, R0, LSR #8
        SWIVC   XOS_WriteC
        MOVVC   R0, R0, LSR #8
        SWIVC   XOS_WriteC

        MOVVC   R0, R2
        SWIVC   XOS_WriteC
        MOVVC   R0, R0, LSR #8
        SWIVC   XOS_WriteC
        MOVVC   R0, R0, LSR #8
        SWIVC   XOS_WriteC
        MOVVC   R0, R0, LSR #8
        SWIVC   XOS_WriteC
        BVC     %BT10
        ]
        EXIT

FontPointers InterTable
        InterEntry 100, Bfont
        InterEntry 101, Latin1
        InterEntry 102, Latin2
        InterEntry 103, Latin3
        InterEntry 104, Latin4
        InterEntry 105, Cyrillic
        InterEntry 107, Greek
        InterEntry 108, Hebrew
        InterEntry 120, Cyrillic2
        InterEnd

; *****************************************************************************
;
;       DoCNoToANo - Convert country number to alphabet number
;
; in:   R3 = country number
;
; out:  R4 = alphabet number
;       R1 = 0 if recognised
;

DoCNoToANo ENTRY "R0,R2"
        ADR     R2, CToATable
10
        LDRB    R0, [R2], #2
        TEQ     R0, #0
        EXIT    EQ
        TEQ     R0, R3
        BNE     %BT10

        LDRB    R4, [R2, #-1]
        MOV     R1, #0
        EXIT

CToATable
        =       1,101, 2,100, 3,100, 4,101
        =       5,101, 6,101, 7,101, 8,101
        =       9,103, 10,107, 11,101, 12,101
        =       14,101, 15,101, 16,101
        =       17,101, 18,101, 19,101
        =       24,105, 25,120, 26,108
        =       27,101, 28,101
        =       80,101
        =       0
        ALIGN

; *****************************************************************************
;
;       DoCNaToCNo - Convert country name to country number
;
; in:   R3 -> name
;
; out:  R4 = number
;       R1 = 0 if recognised
;

DoCNaToCNo ENTRY "R0,R2,R5,R6"
        ADR     R6, CountryStrings
ConvertNameToNumber
10
        MOV     R2, R3
        LDRB    R0, [R6], #1            ; get char from table
        TEQ     R0, #0                  ; if zero then end of table
        EXIT    EQ
20
        LDRB    R5, [R2], #1
        CMP     R5, #" "
        BLS     %FT50                   ; end of search name, so no match
        TEQ     R5, #"."
        BEQ     %FT40                   ; abbreviated
        EOR     R5, R5, R0
        BICS    R5, R5, #&20
        BNE     %FT50                   ; no match
        LDRB    R0, [R6], #1
        TEQ     R0, #0
        BNE     %BT20

; end of table name

        LDRB    R5, [R2]
        CMP     R5, #" "                ; if not end of search name
        BHI     %FT55                   ; then no match (and we're already
                                        ; pointing to byte after 0 in our
                                        ; table)
        B       %FT60

40
        LDRB    R0, [R6], #1
        TEQ     R0, #0
        BNE     %BT40
60
        LDRB    R4, [R6], #1            ; R4 = number
        MOV     R1, #0
        EXIT

; no match, so skip to end of this table name

50
        LDRB    R0, [R6], #1
        TEQ     R0, #0
        BNE     %BT50
55
        ADD     R6, R6, #1              ; move to first char of new name
        B       %BT10

; *****************************************************************************
;
;       DoANaToANo - Convert alphabet name to alphabet number
;
; in:   R3 -> name
;
; out:  R4 = number
;       R1 = 0 if recognised
;

DoANaToANo ALTENTRY
        ADRL    R6, AlphabetStrings
        B       ConvertNameToNumber

; *****************************************************************************
;
;       DoCNoToCNa - Convert country number to country name
;
; in:   R3 = number
;       R4 -> buffer for name
;       R5 = buffer size
;
; out:  R1 = 0 if recognised
;

DoCNoToCNa ENTRY "R0,R6,R7"
        ADR     R6, CountryList
10
        BL      LookupNumber
        TEQ     R1, #0
        BLEQ    CopyName
        EXIT

; *****************************************************************************
;
;       DoANoToANa - Convert alphabet number to alphabet name
;
; in:   R3 = number
;       R4 -> buffer for name
;       R5 = buffer size
;
; out:  R1 = 0 if recognised
;

DoANoToANa ALTENTRY
        ADR     R6, AlphabetList
        BNE     %BT10

; *****************************************************************************

CountryList InterTable String
        InterEntry      0, Default
        InterEntry      1, UK
        InterEntry      2, Master
        InterEntry      3, Compact
        InterEntry      4, Italy
        InterEntry      5, Spain
        InterEntry      6, France
        InterEntry      7, Germany
        InterEntry      8, Portugal
        InterEntry      9, Esperanto
        InterEntry      10, Greece
        InterEntry      11, Sweden
        InterEntry      12, Finland
        InterEntry      14, Denmark
        InterEntry      15, Norway
        InterEntry      16, Iceland
        InterEntry      17, Canada1
        InterEntry      18, Canada2
        InterEntry      19, Canada
        InterEntry      24, Russia
        InterEntry      25, Russia2
        InterEntry      26, Israel
        InterEntry      27, Mexico
        InterEntry      28, LatinAm
        InterEntry      80, ISO1
        InterEnd

AlphabetList InterTable String
        InterEntry      100, Bfont
        InterEntry      101, Latin1
        InterEntry      102, Latin2
        InterEntry      103, Latin3
        InterEntry      104, Latin4
        InterEntry      105, Cyrillic
        InterEntry      107, Greek
        InterEntry      108, Hebrew
        InterEntry      120, Cyrillic2
        InterEnd

CountryStrings
StringDefault   =       "Default",0,0
StringUK        =       "UK",0,1
StringMaster    =       "Master",0,2
StringCompact   =       "Compact",0,3
StringItaly     =       "Italy",0,4
StringSpain     =       "Spain",0,5
StringFrance    =       "France",0,6
StringGermany   =       "Germany",0,7
StringPortugal  =       "Portugal",0,8
StringEsperanto =       "Esperanto",0,9
StringGreece    =       "Greece",0,10
StringSweden    =       "Sweden",0,11
StringFinland   =       "Finland",0,12
StringDenmark   =       "Denmark",0,14
StringNorway    =       "Norway",0,15
StringIceland   =       "Iceland",0,16
StringCanada1   =       "Canada1",0,17
StringCanada2   =       "Canada2",0,18
StringCanada    =       "Canada",0,19
StringRussia    =       "Russia",0,24
StringRussia2   =       "Russia2",0,25
StringIsrael    =       "Israel",0,26
StringMexico    =       "Mexico",0,27
StringLatinAm   =       "LatinAm",0,28
StringISO1      =       "ISO1",0,80
                =       0
AlphabetStrings
StringBfont     =       "Bfont",0,100
StringLatin1    =       "Latin1",0,101
StringLatin2    =       "Latin2",0,102
StringLatin3    =       "Latin3",0,103
StringLatin4    =       "Latin4",0,104
StringCyrillic  =       "Cyrillic",0,105
StringGreek     =       "Greek",0,107
StringHebrew    =       "Hebrew",0,108
StringCyrillic2 =       "Cyrillic2",0,120
                =       0
        ALIGN



LookupNumber ROUT
        MOV     R7, R6
10
        LDR     R0, [R7], #4            ; get next word
        TEQ     R0, #0                  ; 0 => end of table
        MOVEQ   PC, R14                 ; so didn't find it
        TEQ     R3, R0, LSR #24         ; does R3 match top byte of word ?
        BNE     %BT10                   ; no, so loop
        BIC     R0, R0, #&FF000000      ; knock out top byte
        ADD     R7, R0, R6              ; and add offset to base
        MOV     R1, #0                  ; indicate found
        MOV     PC, R14



CopyName ROUT
        MOV     R6, #0                  ; start at offset 0
10
        TEQ     R6, R5                  ; if not off limits
        LDRNEB  R0, [R7, R6]            ; load byte from source
        TEQNE   R0, #0
        STRNEB  R0, [R4, R6]            ; if non-zero store to dest
        ADDNE   R6, R6, #1              ; and increment offset
        BNE     %BT10                   ; then exit loop

        MOV     R5, R6                  ; R5 = number of chars put in buffer
        MOV     PC, R14

message_writes
        ENTRY   r0-r7
        BIC     r0, lr, #&fc000003
        MOV     r2, r0
10      LDRB    r1, [r2], #1
        CMP     r1, #0
        BNE     %B10
        SUB     r2, r2, r0
        ADD     r2, r2, #3
        BIC     r2, r2, #3
        ADD     lr, lr, r2
        STR     lr, [sp, #8 * 4]
        B       message_write0_tail

message_write0 ENTRY r0-r7
message_write0_tail
        BL      open_messagefile
        STRVS   r0, [sp]
        EXIT    VS
        MOV     r1, r0
        ADR     r0, MessageFile_Block
        MOV     r2, #0
        MOV     r4, #0
        MOV     r5, #0
        MOV     r6, #0
        MOV     r7, #0
        SWI     XMessageTrans_Lookup
        STRVS   r0, [sp]
        EXIT    VS
10      LDRB    r0, [r2], #1
        CMP     r0, #32
        SWICS   XOS_WriteC
        STRVS   r0, [sp]
        EXIT    VS
        BCS     %B10
        EXIT

CopyError ENTRY r1-r7
        BL      open_messagefile
        EXIT    VS
        MOV     R4, #0
CopyError0
        ADR     R1, MessageFile_Block
        MOV     R2, #0
        MOV     R5, #0
        MOV     R6, #0
        MOV     R7, #0
        SWI     XMessageTrans_ErrorLookup
        EXIT

message_filename
        DCB     "Resources:$.Resources.Internatio.Messages", 0

        ALIGN

open_messagefile ENTRY r0-r2
        LDR     r0, MessageFile_Open
        CMP     r0, #0
        EXIT    NE
        ADR     R0, MessageFile_Block
        ADR     R1, message_filename
        MOV     r2, #0
        SWI     XMessageTrans_OpenFile
        STRVS   r0, [sp]
        EXIT    VS
        MOV     r0, #1
        STR     r0, MessageFile_Open
        EXIT

        LNK     <Dir>.InterFonts
