IntKeyBody 61.9 KB
Newer Older
Neil Turton's avatar
Neil Turton committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
; > adfs::TimsWini.arm.SourceDisc.!IKHG.Source.IntKeyBody

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

; Date       Description
; ----       -----------
; 17-Feb-88  Modified Norway/Denmark, Sweden/Finland
; 19-Feb-88  Modified InkeyTran so that INKEY(-95) returns state of new key
;             next to left shift key on international keyboards
; 19-Feb-88  Added code to select configured keyboard on initialisation
; 16-Mar-88  Conditional versioning between 1.20 and 2.00
;            Started modify AltCharTable mechanism
; 13-Apr-88  Fixed pound/backtick problem
; 14-Apr-88  Attempt to fix initialisation problem on A500s
; 28-Apr-88  Changed version string to "Int'l Keyboard"
; 20-Jul-88  Allow kbids from 1-31
; 24-Oct-88  Modify for International Keyboard Handler Generator
; 18-Jul-89  Started to modify to allow Alt+key to give dead accents
; 31-Jul-89  Changed 'Dir', 'Hdr' etc to 'IKHG$Dir', 'IKHG$Hdr' etc
; 18-Oct-89  Corrected entry for shift-2 in TopBitSetTable1
; 02-Feb-90  Added entries to IDD table, and changed Esperanto to 1100
; 22-Nov-91  TMD Changed selection of keyboard structure to use ID rather
;            than current keyboard country number, changed list of headers
; 26-Nov-91  TMD Changed initialisation to set keyboard to current keyboard,
;            rather than default, so that it doesn't override what the
;            Territory manager says.
; 16-Dec-91  OSS Corrected burnt in UK keyboard to match the spec.
;            Added Mexico (and Israel) to IDD table.
; 22-Jan-92  OSS Corrected Perth layout to match Tim Caspell's spec, made
;            ID 3 (PC) use Perth layout, enabled "WwYy" circumflex (Welsh).
; 16-Feb-92  OSS Added Tim's corrected Letters.Latin1, which tells !IKHG
;            how to uppercase y and w circumflex. The module binary is
;            unaffected.
; 04-Mar-92  TMD Removed Arthur120 conditionals.
;            Removed references to non-existent keyboard id 3 (was PC at one stage).
;            Tidied it up a bit.
;            Made it not hang up if no keyboard attached (bug RP-1355).
; 27-Jun-94  Sorted out sources for international build.
;            Added offsets in key structure so that keypad chars can be changed.
Kevin Bracey's avatar
Kevin Bracey committed
42 43 44 45
; 10-Aug-98  BJGA Added PC-style delete capability and Ursula service call table.
; 18-Aug-98  BJGA Fixed numerous layout bugs
; 31-Aug-98  Internals fully revised to use new UCS layout structures created
;            by keygen. Alphabet adaptive, including UTF-8.
46 47 48 49
; 02-Sep-98  Hexadecimal keypad selection added. If the first digit is 0,
;            then the number entered is read as hex. (Physical) keypad keys
;            "/", "*", "-", "+", "." and "Enter" stand for digits A-F respectively.
;            Also, logical keys A-F will work.
50 51 52 53 54 55
; 28-Sep-98  BJGA Merged in 10-Sep-98 and 24-Sep-98 changes to Ursula branch
;            viz: updated layout drawfiles; added dialling codes for Wales, Wales2,
;            DvorakUK and DvorakUSA; introduced quoted characters to !IKHG.Source.Chars;
;            layout changes to Belgium, Denmark, France, Germany, Greece, Israel,
;            LatinAm, Russia, Switzerland and Turkey; and Ctrl-Alt-F1/F2 use a callback.
;            Also fixed Japan delete key to be special.
Kevin Bracey's avatar
Kevin Bracey committed
56
; 26-Aug-99  Software support for "FN" key.
57
; 21-Nov-00  Support for South African keyboard (identical to USA) added
Neil Turton's avatar
Neil Turton committed
58 59
;

Kevin Bracey's avatar
Kevin Bracey committed
60
        GBLL    PCDel           ; option to have Delete key return &8B (Copy) instead
Ben Avison's avatar
Ben Avison committed
61
PCDel   SETL    {FALSE}
Kevin Bracey's avatar
Kevin Bracey committed
62 63 64 65

        GBLL    Ursula          ; add Ursula service call table
Ursula  SETL    {TRUE}

66 67 68 69 70 71
        GET     Global/ListOpts
        GET     Global/Macros
        GET     Global/System
        GET     Interface/ModHand
        GET     Global/Services
        GET     Global/Proc
72
        GET     Hdr:OSRSI6
Neil Turton's avatar
Neil Turton committed
73 74 75 76 77 78 79

OsbyteSetCountry * &46
OsbyteSetAlphKey * &47
OsbyteFindOsbyteVars * &A6
OsbyteTABch     * &DB
OsbyteKeyBase   * &EE
OsbyteKeyOpt    * &FE
Kevin Bracey's avatar
Kevin Bracey committed
80 81 82 83 84
 [ PCDel
OsbyteReadCmos  * &A1
CmosDelByte     * &C3
CmosDelBit      * 1
 ]
Neil Turton's avatar
Neil Turton committed
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111

Country_UK      * 1
Country_Master  * 2
Country_Compact * 3
Country_Italy   * 4
Country_Spain   * 5
Country_France  * 6
Country_Germany * 7
Country_Portugal * 8
Country_Esperanto * 9
Country_Greece  * 10
Country_Sweden  * 11
Country_Finland * 12
Country_Denmark * 14
Country_Norway  * 15
Country_Iceland * 16
Country_Canada1 * 17
Country_Canada2 * 18
Country_Canada  * 19
Country_Turkey  * 20
Country_Arabic  * 21
Country_Ireland * 22
Country_HongKong * 23
Country_Russia  * 24
Country_Russia2 * 25
Country_Israel  * 26
Country_Mexico  * 27
112 113 114 115 116 117 118 119 120
Country_LatinAm * 28
Country_Australia * 29
Country_Austria * 30
Country_Belgium * 31
Country_Japan   * 32
Country_MiddleEast * 33
Country_Netherlands * 34
Country_Switzerland * 35
Country_Wales   * 36
Neil Turton's avatar
Neil Turton committed
121 122

Country_USA     * 48
123 124 125
Country_Wales2  * 49
Country_China   * 50
Country_Brazil  * 51
126
Country_SAfrica2 * 52
127
Country_Korea   * 53
128
Country_Taiwan  * 54
129

Neil Turton's avatar
Neil Turton committed
130 131 132 133 134 135 136 137 138 139
Country_ISO1    * 80
Country_ISO2    * 81
Country_ISO3    * 82
Country_ISO4    * 83
Country_ISO5    * 84
Country_ISO6    * 85
Country_ISO7    * 86
Country_ISO8    * 87
Country_ISO9    * 88

140 141 142
Country_DvorakUK  * 70
Country_DvorakUSA * 71

Neil Turton's avatar
Neil Turton committed
143 144 145 146 147 148 149 150 151
Alphabet_Latin1 * 101
Alphabet_Latin2 * 102
Alphabet_Latin3 * 103
Alphabet_Latin4 * 104
Alphabet_Cyrillic * 105
Alphabet_Arabic * 106
Alphabet_Greek  * 107
Alphabet_Hebrew * 108
Alphabet_Latin5 * 109
Kevin Bracey's avatar
Kevin Bracey committed
152 153 154 155
Alphabet_Welsh  * 110
Alphabet_UTF8   * 111
Alphabet_Latin9 * 112
Alphabet_Latin6 * 113
Neil Turton's avatar
Neil Turton committed
156 157 158 159

Keyboard_A500   * 0
Keyboard_A1     * 1
Keyboard_Perth  * 2
Kevin Bracey's avatar
Kevin Bracey committed
160
Keyboard_RCMM   * 3
Neil Turton's avatar
Neil Turton committed
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269
Keyboard_None   * &FF

        MACRO
        IKT     $A, $B, $C, $D, $E, $F, $G, $H
        IKT2    $A
        IKT2    $B
        IKT2    $C
        IKT2    $D
        IKT2    $E
        IKT2    $F
        IKT2    $G
        IKT2    $H
        MEND

        MACRO
        IKT2    $TE
        LCLA    T
T       SETA    $TE
        [ (T :AND: &FF00) = 0
T       SETA    T :OR: &FF00
        ]
        [ (T :AND: &FF0000) = 0
T       SETA    T :OR: &FF0000
        ]
        [ (T :AND: &FF000000) = 0
T       SETA    T :OR: &FF000000
        ]
        &       T
        MEND

; UK Keyboard keys

K1Escape        * &00
K1Function1     * &01
K1Function2     * &02
K1Function3     * &03
K1Function4     * &04
K1Function5     * &05
K1Function6     * &06
K1Function7     * &07
K1Function8     * &08
K1Function9     * &09
K1Function10    * &0A
K1Function11    * &0B
K1Function12    * &0C
K1Print         * &0D
K1ScrollLock    * &0E
K1Break         * &0F
K1BackTick      * &10
K1Digit1        * &11
K1Digit2        * &12
K1Digit3        * &13
K1Digit4        * &14
K1Digit5        * &15
K1Digit6        * &16
K1Digit7        * &17
K1Digit8        * &18
K1Digit9        * &19
K1Digit0        * &1A
K1Minus         * &1B
K1Equals        * &1C
K1Pound         * &1D
K1BackSpace     * &1E
K1Insert        * &1F
K1Home          * &20
K1PageUp        * &21
K1NumLock       * &22
K1NumPadSlash   * &23
K1NumPadStar    * &24
K1NumPadHash    * &25
K1Tab           * &26
K1LetterQ       * &27
K1LetterW       * &28
K1LetterE       * &29
K1LetterR       * &2A
K1LetterT       * &2B
K1LetterY       * &2C
K1LetterU       * &2D
K1LetterI       * &2E
K1LetterO       * &2F
K1LetterP       * &30
K1OpenSquare    * &31
K1CloseSquare   * &32
K1BackSlash     * &33
K1Delete        * &34
K1Copy          * &35
K1PageDown      * &36
K1NumPad7       * &37
K1NumPad8       * &38
K1NumPad9       * &39
K1NumPadMinus   * &3A
K1CtrlLeft      * &3B
K1LetterA       * &3C
K1LetterS       * &3D
K1LetterD       * &3E
K1LetterF       * &3F
K1LetterG       * &40
K1LetterH       * &41
K1LetterJ       * &42
K1LetterK       * &43
K1LetterL       * &44
K1SemiColon     * &45
K1Tick          * &46
K1Return        * &47
K1NumPad4       * &48
K1NumPad5       * &49
K1NumPad6       * &4A
K1NumPadPlus    * &4B
K1ShiftLeft     * &4C
Kevin Bracey's avatar
Kevin Bracey committed
270
K1NotFittedLeft * &4D
Neil Turton's avatar
Neil Turton committed
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296
K1LetterZ       * &4E
K1LetterX       * &4F
K1LetterC       * &50
K1LetterV       * &51
K1LetterB       * &52
K1LetterN       * &53
K1LetterM       * &54
K1Comma         * &55
K1Dot           * &56
K1Slash         * &57
K1ShiftRight    * &58
K1CursorUp      * &59
K1NumPad1       * &5A
K1NumPad2       * &5B
K1NumPad3       * &5C
K1CapsLock      * &5D
K1AltLeft       * &5E
K1Space         * &5F
K1AltRight      * &60
K1CtrlRight     * &61
K1CursorLeft    * &62
K1CursorDown    * &63
K1CursorRight   * &64
K1NumPad0       * &65
K1NumPadDot     * &66
K1NumPadEnter   * &67
Kevin Bracey's avatar
Kevin Bracey committed
297 298 299 300 301 302 303
K1AcornLeft     * &68
K1AcornRight    * &69
K1Menu          * &6A
K1NoConvert     * &6B
K1Convert       * &6C
K1Kana          * &6D
K1NotFittedRight * &6E
Kevin Bracey's avatar
Kevin Bracey committed
304
K1FN            * &6F
Neil Turton's avatar
Neil Turton committed
305 306 307 308 309 310 311 312 313 314 315 316
K1LeftMouse     * &70
K1CentreMouse   * &71
K1RightMouse    * &72

; Bits in pending ALT flag

KBAlt_AccentMask  * 31

KBAlt_AltDown        * (1 :SHL: 5)
KBAlt_DigitsPresent  * (1 :SHL: 6)
KBAlt_SelectKeyboard * (1 :SHL: 7)      ; set after CTRL-ALT-F12

Kevin Bracey's avatar
Kevin Bracey committed
317 318 319 320 321 322 323 324 325 326 327 328
; Kernel-referenced entries
KVKeyTran            * &0
KVKeyTranSize        * &4
KVInkeyTran          * &8
KVShiftingList       * &C
KVSpecialList        * &10
KVSpecialCodeTable   * &14
KVInit               * &18
KVPendingAltCode     * &1C
; Private entries
KVPadNumTran         * &20 ; offset from structure to new entry for keypad numerics
KVPadCurTran         * &24 ; offset from structure to new entry for keypad non-numerics
Kevin Bracey's avatar
Kevin Bracey committed
329 330 331 332
KVFNTable            * &28
KVUCSTable0          * &2C
KVUCSTable1          * &30
KVSize               * &34 ; size of key structure header
Kevin Bracey's avatar
Kevin Bracey committed
333 334

KBStat_NoKanaLock    * KBStat_NoShiftLock  ; we've reassigned this bit
Neil Turton's avatar
Neil Turton committed
335 336 337 338 339 340 341 342 343 344

; Module workspace allocation

        ^ 0, R12

NewKeyStructWP  # KVSize        ; key structure header, must be first thing
OldKeyHandler   # 4
CurrentKeyboard # 4     ; current keyboard setting
OsbyteVars      # 4
AltDigitValue   # 4
Kevin Bracey's avatar
Kevin Bracey committed
345 346 347 348
CurrentAlphabet # 4
AlphabetTable   # 4
FallbackCode    # 4
DeleteChar      # 1
349
HexDigits       # 1
Neil Turton's avatar
Neil Turton committed
350 351 352 353 354 355 356 357

A1Key_WorkspaceSize * :INDEX: @

        ^ :INDEX: CurrentKeyboard, R0

R0CurrentKeyboard # 4
R0OsbyteVars    # 4
R0AltDigitValue # 4     ; value of ALT+digits so far
Kevin Bracey's avatar
Kevin Bracey committed
358 359 360 361
R0CurrentAlphabet # 4
R0AlphabetTable # 4
R0FallbackCode  # 4
R0DeleteChar    # 1
362
R0HexDigits     # 1
Neil Turton's avatar
Neil Turton committed
363 364 365 366 367 368 369 370

; User key workspace allocation

        ^ 0, R12

ShiftCount      # 1
CtrlCount       # 1
AltCount        # 1
371
AltLeftDown     # 1     ; for layouts where Left-Alt + Shift toggles layers
Kevin Bracey's avatar
Kevin Bracey committed
372
FNDown          # 1
Neil Turton's avatar
Neil Turton committed
373
MyMouseButtons  # 1     ; bit0=R, bit1=C, bit2=L
Kevin Bracey's avatar
Kevin Bracey committed
374
TempAction      # 1     ; to remember the action in ProcessUCS
Neil Turton's avatar
Neil Turton committed
375 376 377
KeyReturn       # 2     ; length byte (1), value byte
KeyNULReturn    # 3     ; length byte (2), NUL, value byte
NowtReturn      * KeyNULReturn +1 ; zero length list
Kevin Bracey's avatar
Kevin Bracey committed
378 379
KeyUTFReturn    # 13    ; length byte (up to 12), 6 * (NUL, value)
KeyUTFReturnEnd # 0
Neil Turton's avatar
Neil Turton committed
380

Kevin Bracey's avatar
Kevin Bracey committed
381
; Handy macro to do the FN processing. Good for any non-modifier key.
Kevin Bracey's avatar
Kevin Bracey committed
382
; Corrupts R8 - always corruptible, and undefined on entry.
Kevin Bracey's avatar
Kevin Bracey committed
383

Kevin Bracey's avatar
Kevin Bracey committed
384
        GBLA    HandleFNsize
385

Kevin Bracey's avatar
Kevin Bracey committed
386 387
        MACRO
        HandleFN
Kevin Bracey's avatar
Kevin Bracey committed
388 389 390 391 392 393 394
01      LDRB    R8, FNDown              ; is FN down?
        TEQ     R8, #0                  ; if not, process as normal
        BEQ     %FT02
        Push    "R14"
        BL      FindFN
        Pull    "R14"
02
395
HandleFNsize    SETA    . - %BT01
Kevin Bracey's avatar
Kevin Bracey committed
396 397
        MEND

Neil Turton's avatar
Neil Turton committed
398 399
; **************** Module code starts here **********************

400 401
        AREA    |!!!Module|,CODE,READONLY

Neil Turton's avatar
Neil Turton committed
402 403 404 405 406 407 408 409 410
Module_BaseAddr

        DCD     0
        DCD     A1Key_Init    -Module_BaseAddr
        DCD     A1Key_Die     -Module_BaseAddr
        DCD     A1Key_Service -Module_BaseAddr
        DCD     A1Key_Title   -Module_BaseAddr
        DCD     A1Key_HelpStr -Module_BaseAddr
        DCD     A1Key_HC_Table-Module_BaseAddr
Kevin Bracey's avatar
Kevin Bracey committed
411 412 413 414 415 416 417 418
 [ :LNOT:No32bitCode
        DCD     0
        DCD     0
        DCD     0
        DCD     0
        DCD     0
        DCD     A1Key_Flags   -Module_BaseAddr
 ]
Neil Turton's avatar
Neil Turton committed
419 420 421 422 423

A1Key_Title
        =       "InternationalKeyboard", 0

A1Key_HelpStr
424 425 426 427
        =       "Int'l Keyboard", 9, "$Module_MajorVersion ($Module_Date)"
 [ Module_MinorVersion <> ""
        =       " $Module_MinorVersion"
 ]
428 429 430 431
 [ Keyboard <> "All"
        =       " $Keyboard"
 ]
        =       0
Neil Turton's avatar
Neil Turton committed
432 433
        ALIGN

Kevin Bracey's avatar
Kevin Bracey committed
434 435 436 437 438
 [ :LNOT:No32bitCode
A1Key_Flags
        DCD     1       ; 32-bit compatible
 ]

Neil Turton's avatar
Neil Turton committed
439 440 441 442 443 444 445 446 447
; **************************************************************************

A1Key_HC_Table * Module_BaseAddr

; **************************************************************************
;
;       A1Key_Init - Initialisation routine
;

448
A1Key_Init Entry
Neil Turton's avatar
Neil Turton committed
449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478
        LDR     r2, [r12]               ; have we got workspace yet ?
        TEQ     r2, #0
        BNE     %FT05

        MOV     r0, #ModHandReason_Claim
        MOV     r3, #A1Key_WorkspaceSize
        SWI     XOS_Module
        EXIT    VS

; r2 -> workspace

        STR     r2, [r12]               ; save address in my workspace pointer,
                                        ; so Tutu can free it for me when I die
05
        MOV     wp, r2

        MOV     r0, #OsbyteSetAlphKey
        MOV     r1, #&FF                ; read current keyboard (as determined by Territory Mgr)
        SWI     XOS_Byte
        ORRVC   r1, r1, #128            ; and set current keyboard to that, to cause a kbd reset
        SWIVC   XOS_Byte

        BLVC    SetUpKeyStructureAndHandlerIfUs
        EXIT

; **************************************************************************
;
;       A1Key_Die - Die entry
;

479
A1Key_Die Entry
Neil Turton's avatar
Neil Turton committed
480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508
        LDR     wp, [r12]
        PHPSEI                          ; disable interrupts round this bit
        Push    r14                     ; (r14 contains previous I_bit status)

        MOV     r0, #0                  ; read current handler address
        SWI     XOS_InstallKeyHandler
        TEQ     r0, r12
        BNE     %FT10                   ; key handler isn't us, so exit

        LDR     r0, OldKeyHandler
        SWI     XOS_InstallKeyHandler

10
        Pull    r14
        PLP                             ; restore old IRQ state
        CLRV
        EXIT

; **************************************************************************
;
;       A1Key_Service - Main entry point for services
;
; in:   R1 = service reason code
;       R2 = parameter
;
; out:  R1 = 0 if we claimed it
;       R2 preserved
;

Kevin Bracey's avatar
Kevin Bracey committed
509 510 511 512 513 514 515 516 517
 [ Ursula
ServiceTable
        DCD     0 ; flags
        DCD     Service2 - Module_BaseAddr
        DCD     Service_Reset         ; &27
        DCD     Service_International ; &43
        DCD     Service_KeyHandler    ; &44
        DCD     0 ; terminator
        DCD     ServiceTable - Module_BaseAddr
Neil Turton's avatar
Neil Turton committed
518
A1Key_Service ROUT
Kevin Bracey's avatar
Kevin Bracey committed
519 520 521 522
        MOV     R0, R0
 |
A1Key_Service ROUT
 ]
Neil Turton's avatar
Neil Turton committed
523 524 525
        TEQ     r1, #Service_Reset
        TEQNE   r1, #Service_KeyHandler
        TEQNE   r1, #Service_International
Kevin Bracey's avatar
Kevin Bracey committed
526
        MOVNE   pc, lr
Kevin Bracey's avatar
Kevin Bracey committed
527 528 529
 [ Ursula
Service2
 ]
Neil Turton's avatar
Neil Turton committed
530

531
        Entry   "r1"
Neil Turton's avatar
Neil Turton committed
532 533 534 535 536 537 538 539
        LDR     wp, [r12]                       ; point to workspace
        TEQ     r1, #Service_KeyHandler         ; if Service_KeyHandler
        BEQ     %FT10                           ; then branch

        TEQ     r1, #Service_Reset              ; else if Service_Reset
        TEQNE   r2, #Inter_Keyboard             ; or (the only other option) Service_International
                                                ; with reason code NewKeyboard
        BLEQ    SetUpKeyStructureAndHandlerIfUs ; then call routine
Kevin Bracey's avatar
Kevin Bracey committed
540
        EXIT
Neil Turton's avatar
Neil Turton committed
541 542 543 544 545 546

; it's Service_KeyHandler, so claim service if kbid recognised

10
        BL      SetUpKeyStructureAndHandlerIfUs ; call setup routine
        STR     r1, [sp]                        ; r1 on exit = 0 if it was us, else preserved
Kevin Bracey's avatar
Kevin Bracey committed
547
        EXIT
Neil Turton's avatar
Neil Turton committed
548 549 550 551 552 553 554 555 556 557 558 559 560

; **************************************************************************
;
;       SetUpKeyStructureAndHandlerIfUs - If suitable keyboard ID, set up
;       the keyboard structure and claim handler
;
; in:   r12 -> workspace
;       SVC or IRQ mode
;
; out:  r1 = 0 if we now own the handler
;       Otherwise r1 preserved
;

561
SetUpKeyStructureAndHandlerIfUs Entry "r0,r1"
Neil Turton's avatar
Neil Turton committed
562

Kevin Bracey's avatar
Kevin Bracey committed
563 564
        SavePSR r0
        SETPSR  SVC_mode, r1            ; switch into SVC mode so we can issue
Neil Turton's avatar
Neil Turton committed
565 566 567 568 569 570 571
        NOP

        Push    "r0-r4,lr"
        MOV     r0, #1
        SWI     XOS_InstallKeyHandler
        TEQ     r0, #Keyboard_A1
        TEQNE   r0, #Keyboard_Perth
Kevin Bracey's avatar
Kevin Bracey committed
572
        TEQNE   r0, #Keyboard_RCMM
Neil Turton's avatar
Neil Turton committed
573 574 575
        TEQNE   r0, #Keyboard_None
        BNE     %FT50

576 577 578 579 580 581 582 583
        MOV     r0, #6
        MOV     r1, #0
        MOV     r2, #OSRSI6_OSByteVars
        SWI     XOS_ReadSysInfo
        MOVVS   r2, #0
        CMP     r2, #0
        BNE     %FT01

Neil Turton's avatar
Neil Turton committed
584 585 586 587
        MOV     r0, #OsbyteFindOsbyteVars
        MOV     r1, #0
        MOV     r2, #&FF
        SWI     XOS_Byte
588 589 590
        ORR     r2, r1, r2, LSL #8
01
        STR     r2, OsbyteVars          ; set up osbyte vars address
Neil Turton's avatar
Neil Turton committed
591 592 593 594 595 596

        MOV     r0, #OsbyteSetAlphKey
        MOV     r1, #&FF                ; read keyboard number
        SWI     XOS_Byte
        STR     r1, CurrentKeyboard

Kevin Bracey's avatar
Kevin Bracey committed
597 598 599 600 601 602
        MOV     r0, #-1
        STR     r0, CurrentAlphabet
        STR     r0, FallbackCode

        MOV     r0, r12
        BL      GetAlphabetTable
Neil Turton's avatar
Neil Turton committed
603

Neil Turton's avatar
Neil Turton committed
604 605 606 607 608 609 610 611
        ADRL    R0, KeyStructureTable
        MOV     R4, R0
05
        LDMIA   R4!,{R2,R3}             ; load keyboard number, offset pair
        CMP     R2, #-1                 ; if end of table
        TEQNE   R1, R2                  ; or numbers match then drop through
        BNE     %BT05                   ; else try next
        ADD     R0, R0, R3              ; point to found table or default
Neil Turton's avatar
Neil Turton committed
612

Kevin Bracey's avatar
Kevin Bracey committed
613
        WritePSRc SVC_mode + I_bit, r2  ; disable IRQs round this bit
Neil Turton's avatar
Neil Turton committed
614 615

        MOV     r2, #KVSize-4
Kevin Bracey's avatar
Kevin Bracey committed
616
        SUB     r1, r0, r12             ; offset from workspace to structure
Neil Turton's avatar
Neil Turton committed
617 618
10
        LDR     r3, [r0, r2]
Kevin Bracey's avatar
Kevin Bracey committed
619 620
        TEQ     r2, #KVKeyTranSize      ; is it KeyTranSize ?
        TEQNE   r3, #0                  ; or is it 0
Neil Turton's avatar
Neil Turton committed
621 622 623 624 625 626 627 628 629 630 631 632 633 634
        ADDNE   r3, r3, r1              ; if not then relative offset
        STR     r3, [r12, r2]
        SUBS    r2, r2, #4
        BCS     %BT10

; now set up key handler to point to us, if it doesn't already

        MOV     r0, #0
        SWI     XOS_InstallKeyHandler
        TEQ     r0, r12
        STRNE   r0, OldKeyHandler
        MOVNE   r0, r12
        SWINE   XOS_InstallKeyHandler

Kevin Bracey's avatar
Kevin Bracey committed
635 636 637 638 639 640 641 642 643 644 645
 [ PCDel
; scan CMOS to determine delete type
        MOV     r0, #OsbyteReadCmos
        MOV     r1, #CmosDelByte
        SWI     XOS_Byte
        TST     r2, #1 :SHL: CmosDelBit
        MOVEQ   r0, #&7F
        MOVNE   r0, #&8B
        STRB    r0, DeleteChar
 ]

Neil Turton's avatar
Neil Turton committed
646
        Pull    "r0-r4,lr"
Kevin Bracey's avatar
Kevin Bracey committed
647
        RestPSR r0                      ; return to original mode and IRQ state
Neil Turton's avatar
Neil Turton committed
648 649 650

        MOV     r0, #0
        STR     r0, [sp, #4]            ; set stacked r1 to 0, so we claim the service
Kevin Bracey's avatar
Kevin Bracey committed
651
        EXIT
Neil Turton's avatar
Neil Turton committed
652 653 654 655 656 657 658 659 660 661 662 663

; the keyboard id is not recognised by us, so put back old handler if it's
; set to us at the moment

50
        MOV     r0, #0
        SWI     XOS_InstallKeyHandler
        TEQ     r0, r12                 ; if it's us
        LDREQ   r0, OldKeyHandler       ; then put back old one
        SWIEQ   XOS_InstallKeyHandler

        Pull    "r0-r4,lr"
Kevin Bracey's avatar
Kevin Bracey committed
664
        RestPSR r0                      ; return to original mode and IRQ state
Neil Turton's avatar
Neil Turton committed
665
        NOP
Kevin Bracey's avatar
Kevin Bracey committed
666
        EXIT
Neil Turton's avatar
Neil Turton committed
667 668 669

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

Kevin Bracey's avatar
Kevin Bracey committed
670 671 672 673 674 675 676 677 678
; Find out what alphabet the system is using
;
; on entry: r0 -> my workspace
; on exit: r3 = CurrentAlphabet = alphabet number
;          r4 = AlphabetTable = alphabet table or 0

GetAlphabetTable ROUT
        Entry   "r0,r1,r12"
        MOV     r12, r0
Kevin Bracey's avatar
Kevin Bracey committed
679 680
        SavePSR r0
        SETPSR  SVC_mode, r1            ; switch into SVC mode so we can issue SWIs
Kevin Bracey's avatar
Kevin Bracey committed
681 682 683 684 685 686 687 688 689 690 691 692
        NOP

        Push    "r0-r2,lr"
        MOV     r0, #OsbyteSetAlphKey
        MOV     r1, #&7F                ; read alphabet number
        SWI     XOS_Byte
        LDR     r3, CurrentAlphabet
        TEQ     r1, r3
        BNE     %FT50
        LDR     r4, AlphabetTable
20
        Pull    "r0-r2,lr"
Kevin Bracey's avatar
Kevin Bracey committed
693
        RestPSR r0                      ; return to original mode and IRQ state
Kevin Bracey's avatar
Kevin Bracey committed
694
        NOP
Kevin Bracey's avatar
Kevin Bracey committed
695
        EXIT
Kevin Bracey's avatar
Kevin Bracey committed
696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711

50      MOV     r3, r1
        STR     r3, CurrentAlphabet
        TEQ     r3, #Alphabet_UTF8
        BEQ     %BT20

        MOV     r4, #0
        MOV     r1, #Service_International
        MOV     r2, #Inter_UCSTable
        SWI     XOS_ServiceCall
        STR     r4, AlphabetTable
        B       %BT20


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

Neil Turton's avatar
Neil Turton committed
712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729
; Now the code to handle it

; Initialise keyboard table handler
;
; in:   R0 -> KeyStruct
;       R1 = keyboard id
;       R5 = KeyBdStatus
;       R7 = PendingAltType
;       R12 -> my workspace
;
; out:  R5 = new KeyBdStatus
;       R7 = new PendingAltType

KeyStructInit ROUT
        MOV     R0, #0                  ; no shift or ctrl keys down
        STRB    R0, ShiftCount
        STRB    R0, CtrlCount
        STRB    R0, AltCount
730
        STRB    R0, AltLeftDown
Kevin Bracey's avatar
Kevin Bracey committed
731
        STRB    R0, FNDown
Neil Turton's avatar
Neil Turton committed
732 733 734 735 736 737 738 739
        STRB    R0, MyMouseButtons
        STRB    R0, KeyNULReturn+1      ; NUL for NUL char return
        MOV     R0, #1                  ; string length for single key return
        STRB    R0, KeyReturn+0
        MOV     R0, #2                  ; length for NUL char return
        STRB    R0, KeyNULReturn+0

        BIC     R5, R5, #(KBStat_ShiftEngaged :OR: KBStat_CtrlEngaged :OR: KBStat_PendingAlt)
Kevin Bracey's avatar
Kevin Bracey committed
740
        ORR     R5, R5, #KBStat_NoKanaLock
Neil Turton's avatar
Neil Turton committed
741 742 743 744
        MOV     R7, #0                  ; 0 pending ALT
        MOV     PC, R14

ProcessKShift ROUT
745 746 747 748 749 750 751
        LDRB    R0, AltLeftDown         ; is Left Alt down (where it switches layers?)
        TEQ     R0, #1
        LDREQB  R0, ShiftCount
        TEQEQ   R0, #0                  ; if so, is Shift going down for the first time?
        TEQEQ   R1, #1
        EOREQ   R5, R5, #KBStat_NoKanaLock ; if so, toggle layers, then proceed as normal

Neil Turton's avatar
Neil Turton committed
752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768
        ADR     R0, ShiftCount
        MOV     R2, #KBStat_ShiftEngaged
ProcessShiftOrCtrl
        TEQ     R1, #0                  ; R1=1 => down, R1=0 => up
        LDRB    R3, [R0]
        ADDNE   R3, R3, #1              ; if down then increment (still NE)
        SUBEQS  R3, R3, #1              ; if up then decrement and setup Z
        STRB    R3, [R0]
        ORRNE   R5, R5, R2              ; one or more shift/ctrl keys down
        BICEQ   R5, R5, R2              ; zero shift/ctrl keys down
        MOV     PC, R14

ProcessKCtrl ROUT
        ADR     R0, CtrlCount
        MOV     R2, #KBStat_CtrlEngaged
        B       ProcessShiftOrCtrl

Kevin Bracey's avatar
Kevin Bracey committed
769 770 771 772
ProcessKFN ROUT
        STRB    R1, FNDown
        MOV     PC, R14

Neil Turton's avatar
Neil Turton committed
773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790
ProcessKRight ROUT
        MOV     R2, #1
ProcessMouseButton
        TEQ     R1, #0
        LDRB    R0, MyMouseButtons
        ORRNE   R0, R0, R2              ; button going down
        BICEQ   R0, R0, R2              ; button going up
        STRB    R0, MyMouseButtons
        MOV     PC, R3                  ; call his routine and exit

ProcessKCentre ROUT
        MOV     R2, #2
        B       ProcessMouseButton

ProcessKLeft ROUT
        MOV     R2, #4
        B       ProcessMouseButton

791 792 793 794 795 796 797
ProcessKAltLeft ROUT
        STRB    R1, AltLeftDown                 ; note new state of Left Alt
        TEQ     R1, #0                          ; are we going down?
        TSTNE   R5, #KBStat_ShiftEngaged        ; and is either Shift already down?
        EORNE   R5, R5, #KBStat_NoKanaLock      ; if so, toggle layers
        MOV     PC, R14

Neil Turton's avatar
Neil Turton committed
798 799 800 801 802
ProcessKAlt ROUT
        LDRB    R3, AltCount
        TEQ     R3, #0                  ; if no ALTs down so far, then must be

        STREQ   R3, R0AltDigitValue     ; going down, so zero cumulative digits
803
        STREQB  R3, R0HexDigits
Neil Turton's avatar
Neil Turton committed
804 805 806 807 808 809 810 811 812 813

        TEQ     R1, #0                  ; 0 => up, 1 => down
        ADDNE   R3, R3, #1              ; if down then increment
        SUBEQS  R3, R3, #1              ; if up then decrement and setup Z
        STRB    R3, AltCount
        BNE     %FT10

        TST     R7, #KBAlt_DigitsPresent ; if no digits present
        BEQ     %FT05                   ; then skip

Kevin Bracey's avatar
Kevin Bracey committed
814
        LDR     R1, R0AltDigitValue     ; load digits
Neil Turton's avatar
Neil Turton committed
815
        TST     R7, #KBAlt_SelectKeyboard ; selecting keyboard (CTRL-ALT-F12)?
Kevin Bracey's avatar
Kevin Bracey committed
816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834
        BNE     SelectIDDKeyboard

; return either byte, or UCS character

        Push    R14
        BL      GetAlphabetTable
        Pull    R14
        TEQ     R3, #Alphabet_UTF8
        BNE     %FT02

        BIC     R1, R1, #&80000000      ; strip down to 31 bits
        BICS    R7, R7, #(KBAlt_AltDown :OR: KBAlt_DigitsPresent)
        BICEQ   R5, R5, #KBStat_PendingAlt
        B       ReturnUCS

02
        ADR     R6, KeyNULReturn        ; return 0 then byte
        STRB    R1, [R6, #2]
        B       %FT05
Neil Turton's avatar
Neil Turton committed
835

Kevin Bracey's avatar
Kevin Bracey committed
836 837
SelectIDDKeyboard
        ADR     R0, IDDTable
Neil Turton's avatar
Neil Turton committed
838
03
Kevin Bracey's avatar
Kevin Bracey committed
839
        LDMIA   R0!, {R2, R3}           ; load IDD number, country number
Neil Turton's avatar
Neil Turton committed
840 841
        CMP     R2, #-1                 ; end of table ?
        BEQ     %FT05                   ; then not recognised, so do nothing
Kevin Bracey's avatar
Kevin Bracey committed
842
        TEQ     R2, R1                  ; found match ?
Neil Turton's avatar
Neil Turton committed
843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860
        BNE     %BT03

        ORR     R1, R3, #&80
        Push    R14
        BL      SelectKeyboard
        Pull    R14

05
        BICS    R7, R7, #(KBAlt_AltDown :OR: KBAlt_DigitsPresent :OR: KBAlt_SelectKeyboard)
        B       %FT15
10
        ORRS    R7, R7, #KBAlt_AltDown
15
        ORRNE   R5, R5, #KBStat_PendingAlt ; if NZ then still need bit set
        BICEQ   R5, R5, #KBStat_PendingAlt ; else clear bit
        MOV     PC, R14

IDDTable
861 862 863 864 865
        &        44, Country_UK
        &        39, Country_Italy
        &        34, Country_Spain
        &        33, Country_France
        &        49, Country_Germany
Neil Turton's avatar
Neil Turton committed
866 867
        &       351, Country_Portugal
        &      1100, Country_Esperanto
868 869
        &        30, Country_Greece
        &        46, Country_Sweden
Neil Turton's avatar
Neil Turton committed
870
        &       358, Country_Finland
871 872
        &        45, Country_Denmark
        &        47, Country_Norway
Neil Turton's avatar
Neil Turton committed
873
        &       354, Country_Iceland
Kevin Bracey's avatar
Kevin Bracey committed
874
        &        90, Country_Turkey
875
        &       353, Country_Ireland
Neil Turton's avatar
Neil Turton committed
876
        &       852, Country_HongKong
877
        &         7, Country_Russia
Neil Turton's avatar
Neil Turton committed
878
        &       972, Country_Israel
879
        &        52, Country_Mexico
Kevin Bracey's avatar
Kevin Bracey committed
880 881 882 883 884 885
        &        61, Country_Australia
        &        43, Country_Austria
        &        32, Country_Belgium
        &        81, Country_Japan
        &        31, Country_Netherlands
        &        41, Country_Switzerland
886
        &      1222, Country_Wales
887
        &         1, Country_USA
888
        &      2222, Country_Wales2
889
;        &        86, Country_China
Kevin Bracey's avatar
Kevin Bracey committed
890
;        &        55, Country_Brazil
891
        &        27, Country_SAfrica2
892 893 894

        &      9944, Country_DvorakUK
        &       991, Country_DvorakUSA
Neil Turton's avatar
Neil Turton committed
895 896 897 898 899 900 901 902 903 904 905 906 907

        &      1001, Country_ISO1
        &      1002, Country_ISO2
        &      1003, Country_ISO3
        &      1004, Country_ISO4
        &      1005, Country_ISO5
        &      1006, Country_ISO6
        &      1007, Country_ISO7
        &      1008, Country_ISO8
        &      1009, Country_ISO9
        &       -1, -1

ProcessKCaps ROUT
Kevin Bracey's avatar
Kevin Bracey committed
908 909
        HandleFN
HandleKCaps
Neil Turton's avatar
Neil Turton committed
910 911 912 913 914 915 916 917 918 919 920 921
        TEQ     R1, #2                          ; is it first press ?
        MOVNE   PC, R14                         ; don't auto-repeat

        TST     R5, #KBStat_ShiftEngaged        ; if shift down
        BICNE   R5, R5, #KBStat_NoCapsLock      ; then force CAPS on
        ORRNE   R5, R5, #KBStat_ShiftEnable     ; and SHIFT CAPS state
        EOREQ   R5, R5, #KBStat_NoCapsLock      ; else toggle caps lock state
        BICEQ   R5, R5, #KBStat_ShiftEnable     ; and cancel shift enable

        MOV     PC, R14

ProcessKTab ROUT
Kevin Bracey's avatar
Kevin Bracey committed
922 923
        HandleFN
HandleKTab
Kevin Bracey's avatar
Kevin Bracey committed
924 925 926
        LDR     R3, R0OsbyteVars
        LDRB    R3, [R3, #OsbyteTABch]          ; TAB key code
        TST     R3, #&80                        ; top bit set ?
Neil Turton's avatar
Neil Turton committed
927 928
        BEQ     ReturnOneCharAlt                ; no, don't shift or ctrl it
        TST     R5, #KBStat_ShiftEngaged
Kevin Bracey's avatar
Kevin Bracey committed
929
        EORNE   R3, R3, #&10                    ; modify for shift
Neil Turton's avatar
Neil Turton committed
930
        TST     R5, #KBStat_CtrlEngaged
Kevin Bracey's avatar
Kevin Bracey committed
931
        EORNE   R3, R3, #&20                    ; modify for ctrl
Neil Turton's avatar
Neil Turton committed
932 933 934
ReturnOneCharAlt
        TST     R5, #KBStat_PendingAlt          ; if no pending alt
        TSTNE   R7, #KBAlt_AccentMask           ; or its not an accent
Kevin Bracey's avatar
Kevin Bracey committed
935 936 937 938
        ADREQ   R6, KeyReturn
        STREQB  R3, [R6, #1]                    ; then return this
        MOVEQ   PC, R14
        LDR     R4, [R0, #KVPendingAltCode]
939
        ADD     PC, R0, R4                      ; call PendingAltCode, as the Kernel would
Kevin Bracey's avatar
Kevin Bracey committed
940 941 942


ProcessKDelete ROUT
Kevin Bracey's avatar
Kevin Bracey committed
943 944
        HandleFN
HandleKDelete
Kevin Bracey's avatar
Kevin Bracey committed
945
 [ PCDel
946
        LDRB    R1, R0DeleteChar                ; get configured delete character
Kevin Bracey's avatar
Kevin Bracey committed
947 948 949 950
 |
        MOV     R1, #&7F
 ]
        B       ReturnOneChar
Neil Turton's avatar
Neil Turton committed
951 952

ProcessKNum ROUT
Kevin Bracey's avatar
Kevin Bracey committed
953 954
        HandleFN
HandleKNum
Neil Turton's avatar
Neil Turton committed
955 956 957 958 959
        TEQ     R1, #2                          ; is it first press ?
        EOREQ   R5, R5, #KBStat_NoNumLock       ; yes, then toggle num lock
        MOV     PC, R14                         ; (don't auto-repeat)

ProcessKScroll ROUT
Kevin Bracey's avatar
Kevin Bracey committed
960 961
        HandleFN
HandleKScroll
Neil Turton's avatar
Neil Turton committed
962 963 964 965
        TEQ     R1, #2                          ; is it first press ?
        EOREQ   R5, R5, #KBStat_ScrollLock      ; yes, then toggle scroll lock
        MOV     PC, R14                         ; (don't auto-repeat)

Kevin Bracey's avatar
Kevin Bracey committed
966
ProcessKKana ROUT
Kevin Bracey's avatar
Kevin Bracey committed
967 968
        HandleFN
HandleKKana
Kevin Bracey's avatar
Kevin Bracey committed
969 970 971 972 973
        TEQ     R1, #2                          ; is it first press ?
        EOREQ   R5, R5, #KBStat_NoKanaLock      ; yes, then toggle kana lock
        MOV     PC, R14                         ; (don't auto-repeat)

ProcessKShiftCaps ROUT
Kevin Bracey's avatar
Kevin Bracey committed
974 975
        HandleFN
HandleKShiftCaps
Kevin Bracey's avatar
Kevin Bracey committed
976 977 978 979 980 981 982 983
        TEQ     R1, #2                          ; is it first press ?
        MOVNE   PC, R14                         ; (don't auto-repeat)
        EOR     R5, R5, #KBStat_NoCapsLock      ; toggle caps lock
        TST     R5, #KBStat_NoCapsLock
        ORREQ   R5, R5, #KBStat_ShiftEnable     ; set shift enable if caps lock on
        BICNE   R5, R5, #KBStat_ShiftEnable
        MOV     PC, R14

Neil Turton's avatar
Neil Turton committed
984
ProcessKBreak ROUT
Kevin Bracey's avatar
Kevin Bracey committed
985
        HandleFN
Neil Turton's avatar
Neil Turton committed
986 987 988
        ADD     PC, R3, #4                      ; offset for break routine

ProcessK1Pad ROUT
Kevin Bracey's avatar
Kevin Bracey committed
989
        HandleFN
Neil Turton's avatar
Neil Turton committed
990 991 992 993 994 995 996
        TST     R7, #KBAlt_AltDown
        BNE     AltKeyPad

        BICS    R7, R7, #KBAlt_AccentMask       ; cancel accents
        BICEQ   R5, R5, #KBStat_PendingAlt

        TST     R5, #KBStat_NoNumLock           ; test num lock
997 998 999
        LDREQ   R3, [R0, #KVPadNumTran]         ; num lock on
        LDRNE   R3, [R0, #KVPadCurTran]         ; num lock off
        ADD     R3, R3, R0
Kevin Bracey's avatar
Kevin Bracey committed
1000 1001
        LDRB    R1, [R3, R4]                    ; get table entry
        TEQ     R1, #&FF                        ; dummy key ?
Neil Turton's avatar
Neil Turton committed
1002 1003
        MOVEQ   PC, R14                         ; then exit

1004
        LDR     R6, R0OsbyteVars
Kevin Bracey's avatar
Kevin Bracey committed
1005 1006 1007
        LDRB    R2, [R6, #OsbyteKeyBase]        ; add on numeric key base
        SUB     R1, R1, #"0"
        ADD     R1, R1, R2
Neil Turton's avatar
Neil Turton committed
1008

Kevin Bracey's avatar
Kevin Bracey committed
1009
        LDRB    R2, [R6, #OsbyteKeyOpt]         ; zero => ctrl/shift modifies
Neil Turton's avatar
Neil Turton committed
1010 1011 1012
        TEQ     R2, #0
        BNE     %FT10                           ; [don't modify]

Kevin Bracey's avatar
Kevin Bracey committed
1013
        TST     R1, #&80                        ; top bit set ?
Neil Turton's avatar
Neil Turton committed
1014 1015 1016
        BEQ     %FT10                           ; no, then don't modify

        TST     R5, #KBStat_ShiftEngaged
Kevin Bracey's avatar
Kevin Bracey committed
1017
        EORNE   R1, R1, #&10                    ; modify for shift
Neil Turton's avatar
Neil Turton committed
1018
        TST     R5, #KBStat_CtrlEngaged
Kevin Bracey's avatar
Kevin Bracey committed
1019
        EORNE   R1, R1, #&20                    ; modify for ctrl
Neil Turton's avatar
Neil Turton committed
1020 1021 1022
10
ReturnOneChar
        ADR     R6, KeyReturn                   ; pass pointer back to MOS
Kevin Bracey's avatar
Kevin Bracey committed
1023
        STRB    R1, [R6, #1]                    ; having poked byte in
Neil Turton's avatar
Neil Turton committed
1024 1025 1026
        MOV     PC, R14

AltKeyPad ROUT
1027
        LDR     R3, [R0, #KVPadNumTran]
1028
        LDRB    R1, R0HexDigits                 ; are we doing hex?
1029
        ADD     R3, R3, R0
1030 1031
        TEQ     R1, #0
        BNE     AltKeyPadHex
Neil Turton's avatar
Neil Turton committed
1032 1033 1034
        LDRB    R3, [R3, R4]                    ; get value from PadK1NumTran
        SUB     R3, R3, #"0"
        CMP     R3, #10                         ; if not in range 0-9
1035
        BICHS   R7, R7, #(KBAlt_DigitsPresent :OR: KBAlt_SelectKeyboard)
Neil Turton's avatar
Neil Turton committed
1036
                                                ; then get rid of digs + select
1037 1038 1039 1040
        ORRLO   R7, R7, #KBAlt_DigitsPresent    ; else indicate we have digits
        MOVHS   R2, #0                          ; if no digits
        STRHS   R2, R0AltDigitValue             ; then zero digits
        MOVHS   PC, R14                         ; and exit
Neil Turton's avatar
Neil Turton committed
1041 1042 1043

        LDR     R2, R0AltDigitValue
        MOV     R1, #10
1044 1045 1046
        MLAS    R3, R2, R1, R3                  ; digits = digits*10+new digit
        TSTEQ   R7, #KBAlt_SelectKeyboard
        STREQB  R1, R0HexDigits                 ; 0 pressed first - switch to hex (not IDD)
Neil Turton's avatar
Neil Turton committed
1047 1048 1049
        STR     R3, R0AltDigitValue
        MOV     PC, R14

1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080
AltKeyPadHex
        LDRB    R1, [R3, R4]
        SUB     R1, R1, #"0"                    ; check digits first - they're logical
        CMP     R1, #10
        BLO     GotHex

        ADR     R4, HexPadTable                 ; scan table of physical codes
05      LDRB    R1, [R4], #2
        TEQ     R2, R1
        LDREQB  R1, [R4, #-1]
        BEQ     GotHex
        TEQ     R1, #0
        BNE     %BT05

GotHex
        LDR     R2, R0AltDigitValue
        ADD     R2, R1, R2, LSL #4              ; digits = digits*16+new digit
        STR     R2, R0AltDigitValue
        MOV     PC, R14

HexPadTable
        =       K1NumPadSlash, &A
        =       K1NumPadStar,  &B
        =       K1NumPadHash,  &C
        =       K1NumPadMinus, &C
        =       K1NumPadPlus,  &D
        =       K1NumPadDot,   &E
        =       K1NumPadEnter, &F
        =       0
        ALIGN

Neil Turton's avatar
Neil Turton committed
1081 1082
ReturnNULChar
        ADR     R6, KeyNULReturn
Kevin Bracey's avatar
Kevin Bracey committed
1083
        STRB    R1, [R6, #2]
Neil Turton's avatar
Neil Turton committed
1084 1085
        MOV     PC, R14

Kevin Bracey's avatar
Kevin Bracey committed
1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097
; **************************************************************************
;
; In:  R0->handler
;      R1=action (shifting key:0,1=up,down;  non-shifting:2=first,3=autorepeat)
;      R2=low-level key number
;      R3->table of exit points
;      R4=special key number (eg 1 for first special key)
;      R5=KeyBdStatus
;      R6->a zero byte (so left unmodified -> no output)
;      R7=PendingAltType
;      R12->fixed workspace (allocated by kernel) - approx 170 bytes, not aligned
;
Kevin Bracey's avatar
Kevin Bracey committed
1098
; Out: R0-R4 corrupted
Kevin Bracey's avatar
Kevin Bracey committed
1099 1100 1101 1102 1103
;      R5 updated
;      R6->output (first byte=length, subsequent bytes to insert into buffer)
;      R7 updated

ProcessUCS ROUT
Kevin Bracey's avatar
Kevin Bracey committed
1104 1105
        HandleFN

Kevin Bracey's avatar
Kevin Bracey committed
1106 1107 1108 1109 1110 1111 1112
        TST     R5, #KBStat_NoKanaLock
        LDRNE   R2, [R0, #KVUCSTable0]
        LDREQ   R2, [R0, #KVUCSTable1]
        ADD     R4, R4, R4, LSL #3      ; R4 = key * 9
        ADD     R2, R0, R2
        ADD     R2, R2, R4, LSL #2      ; R2 -> 36-byte entry for key

1113
        TST     R7, #KBAlt_DigitsPresent
1114
        BNE     CheckHexAtoF_ucs
1115

Kevin Bracey's avatar
Kevin Bracey committed
1116 1117 1118
; select the correct Shift/Ctrl/Alt variant.
        STRB    R1, TempAction
        MOV     R1, #0
Neil Turton's avatar
Neil Turton committed
1119
        TST     R5, #KBStat_ShiftEngaged
Kevin Bracey's avatar
Kevin Bracey committed
1120
        ORRNE   R1, R1, #4
Neil Turton's avatar
Neil Turton committed
1121
        TST     R5, #KBStat_CtrlEngaged
Kevin Bracey's avatar
Kevin Bracey committed
1122
        ORRNE   R1, R1, #8
Neil Turton's avatar
Neil Turton committed
1123
        TST     R7, #KBAlt_AltDown
Kevin Bracey's avatar
Kevin Bracey committed
1124
        ORRNE   R1, R1, #16
Neil Turton's avatar
Neil Turton committed
1125

1126
02      TST     R5, #KBStat_NoCapsLock
Kevin Bracey's avatar
Kevin Bracey committed
1127
        BNE     %FT05
Neil Turton's avatar
Neil Turton committed
1128

Kevin Bracey's avatar
Kevin Bracey committed
1129 1130 1131 1132 1133 1134
; process Caps Lock
        LDR     R4, [R2, #32]           ; get the capital-mapping word
        MOV     R4, R4, LSR R1
        AND     R4, R4, #&F             ; R4=alternate form for this character
        TST     R4, #8                  ; bit 3 of R4 set if only Shift-Caps changes
        BEQ     %FT03
Neil Turton's avatar
Neil Turton committed
1135 1136

        TST     R5, #KBStat_ShiftEnable
Kevin Bracey's avatar
Kevin Bracey committed
1137
        BEQ     %FT05
Neil Turton's avatar
Neil Turton committed
1138

Kevin Bracey's avatar
Kevin Bracey committed
1139 1140 1141 1142 1143
        AND     R4, R4, #7
03      MOV     R1, R4, LSL #2

05      LDR     R1, [R2, R1]

1144
06      TST     R1, #&80000000
Kevin Bracey's avatar
Kevin Bracey committed
1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262
        BNE     FunnyUCS

ReturnUCSAlt
        ANDS    R2, R7, #KBAlt_AccentMask   ; Check if we've got a pending accent
        MOVEQ   R2, #-1
        STREQ   R2, R0FallbackCode          ; clear "fallback" character
        BEQ     ReturnUCS

; We have to apply a dead accent now.

        ADRL    R4, AccentTable
        LDR     R2, [R4, R2, LSL #2]    ; offset to appropriate accent
        ADD     R4, R4, R2              ; R4 now points to accent list

        BICS    R7, R7, #KBAlt_AccentMask ; no more accents
        BICEQ   R5, R5, #KBStat_PendingAlt ; if no more then zero status bit
07
        LDR     R3, [R4], #8            ; R3 = base character
        CMP     R3, R1
        BHI     ReturnUCS               ; we're not in the list - return char unmodified
        BNE     %BT07                   ; not found it yet

        STR     R1, R0FallbackCode      ; remember unaccented form, in case accented form
                                        ; not available
        LDR     R1, [R4, #-4]           ; R1 = accented form

;       R1 = real UCS code
ReturnUCS
        CMP     R1, #&80
        BLO     ReturnOneOrNUL          ; 00-7F always the same

        Push    R14
        BL      GetAlphabetTable
        Pull    R14

        TEQ     R3, #Alphabet_UTF8
        BNE     ReturnUCSForAlphabet

; Create the UTF-8 sequence
        Push    R5
        ADR     R6, KeyUTFReturnEnd
        MOV     R5, #2
        MOV     R4, #2_00100000
10
        AND     R2, R1, #2_00111111     ; continuation byte
        ORR     R2, R2, #2_10000000
        STRB    R2, [R6, #-1]!
        MOV     R2, #0                  ; don't forget the 0 padding...
        STRB    R2, [R6, #-1]!
        MOV     R1, R1, LSR #6
        CMP     R1, R4
        MOVHS   R4, R4, LSR #1
        ADDHS   R5, R5, #1
        BHS     %BT10

; and the leading byte...
        MOV     R4, #&FF00
        ORR     R2, R1, R4, LSR R5
        STRB    R2, [R6, #-1]!
        MOV     R2, #0                  ; don't forget the 0 padding...
        STRB    R2, [R6, #-1]!
        MOV     R5, R5, LSL #1
        STRB    R5, [R6, #-1]!
        Pull    R5
        MOV     PC, R14

ReturnUCSForAlphabet
        MOVS    R3, R4                  ; alphabet table
        BEQ     ReturnUCSForNoAlphabet

; find which (if any) of codes &80-&FF is what we want
        MOV     R6, #&80

13      LDR     R2, [R3, R6, LSL #2]
        TEQ     R1, R2
        MOVEQ   R1, R6
        BEQ     ReturnNULChar
        ADD     R6, R6, #1
        CMP     R6, #&FF
        BLS     %BT13

; can't find it - do we have a fallback?
15      LDR     R1, R0FallbackCode
        CMP     R1, #-1
        MOVNE   R6, #-1
        STRNE   R6, R0FallbackCode    ; clear fallback, else infinite loop
        BNE     ReturnUCS

; give up - output nothing
        ADR     R6, NowtReturn
        MOV     PC, R14

ReturnUCSForNoAlphabet                  ; Assume pure ISO Latin 1
        CMP     R1, #&FF
        BHI     %BT15
        B       ReturnNULChar

FunnyUCS
        CMN     R1, #1                 ; Check for &FFFFFFFF - nothing
        ADREQ   R6, NowtReturn

        BIC     R1, R1, #&80000000     ; &800000xx - a raw buffer code
        CMP     R1, #&100
        ADRLO   R6, KeyReturn
        STRLOB  R1, [R6, #1]
        MOVLO   PC, R14

; Oooh - it's summat special
        CMP     R1, #&10000
        BLO     %FT40                  ; &8000xxxx - daft
        CMP     R1, #&20000
        BLO     SpecialKey             ; &8001xxxx - special key
        CMP     R1, #&30000
        BLO     DeadKey                ; &8002xxxx - dead key

40      ADRHI   R6, NowtReturn
        MOV     PC, R14

1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273
CheckHexAtoF_simple
        LDR     R4, [R0, #KVKeyTran]
        ADD     R4, R0, R4
        LDRB    R4, [R4, R2, LSL #2]    ; get the base symbol for this key
        B       CheckHexAtoF_common

CheckHexAtoF_ucs
        LDR     R4, [R2, #0]            ; get the base symbol for this key
        B       CheckHexAtoF_common

CheckHexAtoF_common
1274 1275 1276 1277 1278
; We're doing something digitty - if it's hex we need to check for A-F.
; If it's not hex or A-F, we return immediately - it's not sensible to
; be outputting standard Alt symbols while doing a keypad sequence, although
; this is what pre 0.50 versions did.

1279 1280
        LDRB    R2, R0HexDigits         ; are we doing hex?
        TEQ     R2, #0
1281 1282 1283 1284 1285 1286 1287 1288 1289
        MOVEQ   PC, R14
        BIC     R4, R4, #&20            ; upper case the codes that matter
        CMP     R4, #"A"
        MOVLO   PC, R14
        CMP     R4, #"F"
        MOVHI   PC, R14
        SUB     R1, R4, #"A"-10
        B       GotHex

Kevin Bracey's avatar
Kevin Bracey committed
1290 1291 1292 1293 1294 1295
SpecialKey
        SUB     R4, R1, #&10000
        CMP     R4, #10
        LDRB    R1, TempAction
        ADDLO   PC, PC, R4, LSL #2
        B       %BT40
Kevin Bracey's avatar
Kevin Bracey committed
1296 1297 1298 1299 1300 1301 1302 1303 1304 1305
        B       HandleKScroll
        B       HandleKNum
        B       HandleKTab
        B       HandleKCaps
        B       HandleKKana
        B       HandleKShiftCaps
        B       HandleKDefaultKeyboard
        B       HandleKConfiguredKeyboard
        B       HandleKDialKeyboard
        B       HandleKDelete
Kevin Bracey's avatar
Kevin Bracey committed
1306 1307 1308 1309 1310 1311

DeadKey
        SUB     R1, R1, #&20000
        BIC     R7, R7, #KBAlt_AccentMask  ; clear accents
        ORR     R7, R7, R1                 ; put in new accent
        ORR     R5, R5, #KBStat_PendingAlt ; and indicate it
Neil Turton's avatar
Neil Turton committed
1312 1313
        MOV     PC, R14

Kevin Bracey's avatar
Kevin Bracey committed
1314
; Silly entry conditions here. Can return normally,
Kevin Bracey's avatar
Kevin Bracey committed
1315
; to carry on as normal, can pull PC from the stack
Kevin Bracey's avatar
Kevin Bracey committed
1316 1317 1318
; to ignore the keypress altogether, or can call a new handler
; in the special table.
;
Kevin Bracey's avatar
Kevin Bracey committed
1319
; Note that as in the HandleFN macro we're merrily scrambling R8.
Kevin Bracey's avatar
Kevin Bracey committed
1320 1321
;
FindFN  ROUT
Kevin Bracey's avatar
Kevin Bracey committed
1322 1323 1324
        LDR     R8, [R0, #KVFNTable]    ; if no FN table at all
        TEQ     R8, #0
        MOVEQ   PC,R14
Kevin Bracey's avatar
Kevin Bracey committed
1325 1326

        Push    "R1,R3"
Kevin Bracey's avatar
Kevin Bracey committed
1327 1328 1329
        ADD     R3, R0, R8
        LDRB    R8, [R3], #1            ; R2 = number of FN entries
        TEQ     R8, #0
Kevin Bracey's avatar
Kevin Bracey committed
1330 1331 1332 1333 1334 1335
        BEQ     NoFN
FNLoop  LDRB    R1, [R3], #2            ; R1 = base FN key, advance R3 to next entry
        CMP     R1, R4
        LDREQB  R4, [R3, #-1]           ; if R1 = this key, change R4 to new key
        BEQ     FNContinue
        BHI     NoFN                    ; if R1 > this key, its not there
Kevin Bracey's avatar
Kevin Bracey committed
1336
        SUBS    R8, R8, #1
Kevin Bracey's avatar
Kevin Bracey committed
1337 1338 1339 1340 1341 1342
        BNE     FNLoop
NoFN
        Pull    "R1,R3,PC"              ; no FN entry - output nothing

FNContinue
; Need to call the correct handler...
Kevin Bracey's avatar
Kevin Bracey committed
1343 1344 1345
        LDR     R8, [R0, #KVSpecialCodeTable]
        ADD     R8, R8, R0              ; R2 -> special code table
        SUB     R1, R8, #4              ; 0th entry is for 1st special
Kevin Bracey's avatar
Kevin Bracey committed
1346
        LDR     R1, [R1, R4, LSL #2]    ; R1 = offset to code
Kevin Bracey's avatar
Kevin Bracey committed
1347 1348
        ADD     R8, R1, R8              ; R2 = address of code
        ADD     R8, R8, #HandleFNsize   ; Skip past the FN handling code :)
Kevin Bracey's avatar
Kevin Bracey committed
1349
        Pull    "R1,R3,LR"
Kevin Bracey's avatar
Kevin Bracey committed
1350
        MOV     PC, R8
Kevin Bracey's avatar
Kevin Bracey committed
1351

Neil Turton's avatar
Neil Turton committed
1352 1353 1354
; **************************************************************************
;
; in:   R0 -> key structure
Kevin Bracey's avatar
Kevin Bracey committed
1355
;       R1 = action (2=first,3=autorepeat)
Neil Turton's avatar
Neil Turton committed
1356
;       R2 = internal key number for char
Kevin Bracey's avatar
Kevin Bracey committed
1357
;       R3 = character which would be returned if not an ALT
Neil Turton's avatar
Neil Turton committed
1358
;       R5 = keyboard status
Kevin Bracey's avatar
Kevin Bracey committed
1359
;       R6 -> a zero byte
Neil Turton's avatar
Neil Turton committed
1360 1361
;       R7 = pending alt type

Kevin Bracey's avatar
Kevin Bracey committed
1362
PendingAltCode ROUT
1363 1364 1365
        TST     R7, #KBAlt_DigitsPresent; is it because of keyboard selection?
        BNE     CheckHexAtoF_simple     ; if so, then nip off to deal with it

Neil Turton's avatar
Neil Turton committed
1366
        TST     R7, #KBAlt_AccentMask   ; is it due to dead accent ?
Kevin Bracey's avatar
Kevin Bracey committed
1367 1368
        MOVEQ   PC, R14                 ; no, then must be Alt down - any real Alts are
                                        ; special - simple keys return nothing.
Neil Turton's avatar
Neil Turton committed
1369 1370 1371

; called because of accented char

Kevin Bracey's avatar
Kevin Bracey committed
1372 1373 1374 1375 1376 1377
        MOV     R1, R3
        CMP     R1, #&80                ; is it a Basic Latin character?
        BLO     ReturnUCSAlt            ; if so - get ProcessUCS to add the accent

; Boring - it's just a function key. Remove the dead accent and
; output the function key.
Neil Turton's avatar
Neil Turton committed
1378 1379 1380 1381

        BICS    R7, R7, #KBAlt_AccentMask ; no more accents
        BICEQ   R5, R5, #KBStat_PendingAlt ; if no more then zero status bit

Kevin Bracey's avatar
Kevin Bracey committed
1382
        B       ReturnOneChar
Neil Turton's avatar
Neil Turton committed
1383 1384

ReturnOneOrNUL
Kevin Bracey's avatar
Kevin Bracey committed
1385 1386
        CMP     R1, #0                  ; if 0 then return 0 0 (C=1)
        CMPNE   R1, #&80                ; elif -ve return 0 char
Neil Turton's avatar
Neil Turton committed
1387 1388 1389
        BCS     ReturnNULChar
        B       ReturnOneChar           ; else return 0 char

Kevin Bracey's avatar
Kevin Bracey committed
1390
HandleKDialKeyboard
Kevin Bracey's avatar
Kevin Bracey committed
1391 1392 1393
        TST     R7, #KBAlt_AltDown              ; ensure Alt is down...
        ORRNE   R7, R7, #KBAlt_SelectKeyboard   ; set IDD selection flag
        MOV     PC, R14
Neil Turton's avatar
Neil Turton committed
1394

Kevin Bracey's avatar
Kevin Bracey committed
1395
HandleKConfiguredKeyboard ROUT
Neil Turton's avatar
Neil Turton committed
1396 1397
        MOV     R1, #&80                        ; select default keyboard
        B       SelectKeyboard
Kevin Bracey's avatar
Kevin Bracey committed
1398
HandleKDefaultKeyboard
Neil Turton's avatar
Neil Turton committed
1399 1400
        MOV     R1, #&81                        ; select UK keyboard
SelectKeyboard
Kevin Bracey's avatar
Kevin Bracey committed
1401 1402
        SavePSR R3
        SETPSR  SVC_mode, R0                    ; select SVC mode
1403
        NOP                                     ; wait for it to happen
Neil Turton's avatar
Neil Turton committed
1404 1405

        Push    R14
1406 1407
        ADR     R0, CallBack_SelectKeyboard
        SWI     XOS_AddCallBack                 ; R1 already set up
Neil Turton's avatar
Neil Turton committed
1408 1409
        Pull    R14

Kevin Bracey's avatar
Kevin Bracey committed
1410
        RestPSR R3                              ; reenter previous mode
1411
        NOP                                     ; wait for it to happen
Neil Turton's avatar
Neil Turton committed
1412 1413 1414 1415
ReturnNowt
        ADR     R6, NowtReturn                  ; return nowt
        MOV     PC, R14

1416 1417 1418 1419 1420 1421 1422
CallBack_SelectKeyboard
        Push    "R0-R2,R14"
        MOV     R0, #OsbyteSetAlphKey
        MOV     R1, R12                         ; R12 used to pass keyboard + &80
        SWI     XOS_Byte
        Pull    "R0-R2,PC"

Neil Turton's avatar
Neil Turton committed
1423 1424 1425 1426 1427
; **************************************************************************
;
;       Reverse table lookup for INKEY(-ve)
;

Kevin Bracey's avatar
Kevin Bracey committed
1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450
; For reference, here is the definitive internal key list. A number of codes
; are for BBC compatibility. For example, code 71 was the "@" key on the
; BBC micro - there was no separate @ key on the Archimedes UK layout,
; so the 2 key (Shift-2 was @) generates this internal code. These compatibility
; codes should not be used by new programs.
;
; Don't forget that these codes are supposed to be for _physical_ keys -
; the code for the key to the left of backspace never changes, no matter
; how it is marked.
;
; Internal code    Key                Low-level codes
; 0                Shift              4C or 58
; 1                Ctrl               3B or 61
; 2                Alt                5E or 60
; 3                Left Shift         4C
; 4                Left Ctrl          3B
; 5                Left Alt           5E
; 6                Right Shift        58
; 7                Right Ctrl         61
; 8                Right Alt          60
; 9                Select             70
; 10               Menu               71
; 11               Adjust             72
Kevin Bracey's avatar
Kevin Bracey committed
1451
; 12               FN                 6F
Kevin Bracey's avatar
Kevin Bracey committed
1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567
; 13               (not defined)
; 14               (not defined)
; 15               (not defined)
; 16               Q                  27
; 17               3                  13
; 18               4                  14
; 19               5                  15
; 20               F4                 04
; 21               8                  18
; 22               F7                 07
; 23               -                  1B
; 24               ^                  16 (BBC compatibility - see 52)
; 25               Left Arrow         62
; 26               Keypad 6           4A
; 27               Keypad 7           37
; 28               F11                0B
; 29               F12                0C
; 30               F10                0A
; 31               Scroll Lock        0E
; 32               Print              0D
; 33               W                  28
; 34               E                  29
; 35               T                  2B
; 36               7                  17
; 37               I                  2E
; 38               9                  19
; 39               0                  1A
; 40               _                  1B (BBC compatibility - see 23)
; 41               Down Arrow         63
; 42               Keypad 8           38
; 43               Keypad 9           39
; 44               Break              0F
; 45               `                  10
; 46               Pound              1D (not fitted)
; 47               Backspace          1E
; 48               1                  11
; 49               2                  12
; 50               D                  3E
; 51               R                  2A
; 52               6                  16
; 53               U                  2D
; 54               O                  2F
; 55               P                  30
; 56               [                  31
; 57               Up Arrow           59
; 58               Keypad +           4B
; 59               Keypad -           39
; 60               Keypad Enter       67
; 61               Insert             1F
; 62               Home               20
; 63               Page Up            21
; 64               Caps Lock          5D
; 65               A                  3C
; 66               X                  4F
; 67               F                  3F
; 68               Y                  2C
; 69               J                  42
; 70               K                  43
; 71               @                  12 (BBC compatibility - see 49)
; 72               :                  45
; 73               Enter              47
; 74               Keypad /           23
; 75               Keypad Delete      (not mapped)
; 76               Keypad .           66
; 77               Num Lock           22
; 78               Page Down          36
; 79               '                  46
; 80               Shift Lock         (not mapped)
; 81               S                  3D
; 82               C                  50
; 83               G                  40
; 84               H                  41
; 85               N                  53
; 86               L                  44
; 87               ;                  45 (BBC compatibility - see 72)
; 88               ]                  32
; 89               Delete             34
; 90               Keypad #           25 (not normally fitted)
; 91               Keypad *           24
; 92               Keypad ,           (not mapped)
; 93               =                  1C
; 94               \                  4D
; 95               Not fitted (R)     6E (between / and Shift on Japanese keyboard)
; 96               Tab                26
; 97               Z                  4E
; 98               Space              5F
; 99               V                  51
; 100              B                  52
; 101              M                  54
; 102              ,                  55
; 103              .                  56
; 104              /                  57
; 105              End                35
; 106              Keypad 0           65
; 107              Keypad 1           5A
; 108              Keypad 3           5C
; 109              No Convert         6B
; 110              Convert            6C
; 111              Kana               6D
; 112              Escape             00
; 113              F1                 01
; 114              F2                 02
; 115              F3                 03
; 116              F5                 05
; 117              F6                 06
; 118              F8                 08
; 119              F9                 09
; 120              # (\ on BBC+Arch)  33
; 121              Right Arrow        64
; 122              Keypad 4           48
; 123              Keypad 5           49
; 124              Keypad 2           5B
; 125              Left Acorn         68
; 126              Right Acorn        69
; 127              Menu               6A

Neil Turton's avatar
Neil Turton committed
1568
InkeyTran
1569
        IKT     &6A, &69, &68, &5B, &49, &48, &64, &33          ; 80-87
Neil Turton's avatar
Neil Turton committed
1570
        IKT     &09, &08, &06, &05, &03, &02, &01, &00          ; 88-8F
1571
        IKT     &6D, &6C, &6B, &5C, &5A, &65, &35, &57          ; 90-97
Neil Turton's avatar
Neil Turton committed
1572
        IKT     &56, &55, &54, &52, &51, &5F, &4E, &26          ; 98-9F
1573
        IKT     &6E, &4D, &1C, &FF, &24, &25, &34, &32          ; A0-A7
Neil Turton's avatar
Neil Turton committed
1574 1575 1576 1577 1578 1579 1580 1581 1582
        IKT     &45, &44, &53, &41, &40, &50, &3D, &FF          ; A8-AF
        IKT     &46, &36, &22, &66, &FF, &23, &47, &45          ; B0-B7
        IKT     &12, &43, &42, &2C, &3F, &4F, &3C, &5D          ; B8-BF
        IKT     &21, &20, &1F, &67, &3A, &4B, &59, &31          ; C0-C7
        IKT     &30, &2F, &2D, &16, &2A, &3E, &12, &11          ; C8-CF
        IKT     &1E, &1D, &10, &0F, &39, &38, &63, &1B          ; D0-D7
        IKT     &1A, &19, &2E, &17, &2B, &29, &28, &0D          ; D8-DF
        IKT     &0E, &0A, &0C, &0B, &37, &4A, &62, &16          ; E0-E7
        IKT     &1B, &07, &18, &04, &15, &14, &13, &27          ; E8-EF
Kevin Bracey's avatar
Kevin Bracey committed
1583
        IKT     &FF, &FF, &FF, &6F, &72, &71, &70, &60          ; F0-F7
Neil Turton's avatar
Neil Turton committed
1584 1585 1586 1587 1588 1589 1590
        IKT     &61, &58, &5E, &3B, &4C, &5E60, &3B61, &4C58    ; F8-FF

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

ShiftingKeyList
        =       ShiftingKeyListEnd-ShiftingKeyList-1
        =       K1ShiftLeft, K1ShiftRight, K1CtrlLeft, K1CtrlRight
Kevin Bracey's avatar
Kevin Bracey committed
1591
        =       K1AltLeft, K1AltRight, K1FN
Neil Turton's avatar
Neil Turton committed
1592 1593 1594 1595
        =       K1RightMouse, K1CentreMouse, K1LeftMouse, K1Break
ShiftingKeyListEnd
        ALIGN

Kevin Bracey's avatar
Kevin Bracey committed
1596 1597 1598
; **************************************************************************
;
; A general purpose special code list used by most UCS keyboard drivers -
1599
; long enough for lots of keys, every one special.
Kevin Bracey's avatar
Kevin Bracey committed
1600 1601 1602 1603 1604 1605 1606 1607
;
SpecialCodeTable
        &       ProcessKShift - SpecialCodeTable
        &       ProcessKShift - SpecialCodeTable
        &       ProcessKCtrl - SpecialCodeTable
        &       ProcessKCtrl - SpecialCodeTable
        &       ProcessKAlt - SpecialCodeTable
        &       ProcessKAlt - SpecialCodeTable
Kevin Bracey's avatar
Kevin Bracey committed
1608
        &       ProcessKFN - SpecialCodeTable
Kevin Bracey's avatar
Kevin Bracey committed
1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646
        &       ProcessKLeft - SpecialCodeTable
        &       ProcessKCentre - SpecialCodeTable
        &       ProcessKRight - SpecialCodeTable
        &       ProcessKBreak - SpecialCodeTable
        &       ProcessK1Pad - SpecialCodeTable
        &       ProcessK1Pad - SpecialCodeTable
        &       ProcessK1Pad - SpecialCodeTable
        &       ProcessK1Pad - SpecialCodeTable
        &       ProcessK1Pad - SpecialCodeTable
        &       ProcessK1Pad - SpecialCodeTable
        &       ProcessK1Pad - SpecialCodeTable
        &       ProcessK1Pad - SpecialCodeTable
        &       ProcessK1Pad - SpecialCodeTable
        &       ProcessK1Pad - SpecialCodeTable
        &       ProcessK1Pad - SpecialCodeTable
        &       ProcessK1Pad - SpecialCodeTable
        &       ProcessK1Pad - SpecialCodeTable
        &       ProcessK1Pad - SpecialCodeTable
        &       ProcessK1Pad - SpecialCodeTable
        &       ProcessK1Pad - SpecialCodeTable
        &       ProcessK1Pad - SpecialCodeTable
        &       ProcessKScroll - SpecialCodeTable
        &       ProcessKNum - SpecialCodeTable
        &       ProcessKTab - SpecialCodeTable
        &       ProcessKCaps - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
Kevin Bracey's avatar
Kevin Bracey committed
1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
        &       ProcessUCS - SpecialCodeTable
SpecialCodeTableEnd

; And the default keypad layout.

PadKNumTran
        =       "/*#789-456+1230.",&0D
PadKCurTran
        =       "/*#",&1E,&8F,&9F,"-",&8C,&FF,&8D,"+",&8B,&8E,&9E,&CD,&7F,&0D
        ALIGN

Neil Turton's avatar
Neil Turton committed
1838
        END