4 ; Translating key codes to strings (MDW)
6 ; © 1994-1998 Straylight
9 ;----- Licensing note -------------------------------------------------------
11 ; This file is part of Straylight's Sapphire library.
13 ; Sapphire is free software; you can redistribute it and/or modify
14 ; it under the terms of the GNU General Public License as published by
15 ; the Free Software Foundation; either version 2, or (at your option)
18 ; Sapphire is distributed in the hope that it will be useful,
19 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ; GNU General Public License for more details.
23 ; You should have received a copy of the GNU General Public License
24 ; along with Sapphire. If not, write to the Free Software Foundation,
25 ; 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 ;----- Standard header ------------------------------------------------------
32 ;----- External dependencies ------------------------------------------------
38 ;----- Constants ------------------------------------------------------------
40 kstr__shift EQU (1<<8)
42 kstr__keypad EQU (1<<10)
43 kstr__func EQU (1<<11)
45 ;----- Macros ---------------------------------------------------------------
48 $label KENTRY $char,$shift,$ctrl,$keypad,$func
50 DCB ($shift<<0)+($ctrl<<1)+($keypad<<2)+($func<<3)
53 ;----- KeyString tables -----------------------------------------------------
55 AREA |Sapphire$$Code|,CODE,READONLY
59 kstr__lower KENTRY ' ', 0,1,0,0
97 kstr__upper KENTRY ' ', 1,1,0,0
114 ; --- &110 - &11F ---
133 ; --- &120 - &12F ---
152 ; --- &130 - &13F ---
171 ; --- &140 - &14F ---
190 ; --- &150 - &15F ---
209 ; --- &160 - &16F ---
228 ; --- &170 - &17F ---
247 ; --- &180 - &18F ---
266 ; --- &190 - &19F ---
285 ; --- &1A0 - &1AF ---
304 ; --- &1B0 - &1BF ---
323 ; --- &1C0 - &1CF ---
342 ; --- &1D0 - &1DF ---
361 ; --- &1E0 - &1EF ---
380 ; --- &1F0 - &1FF ---
399 ;----- Main code ------------------------------------------------------------
403 ; On entry: R0 == key number, from Straylight extended keymap
404 ; R1 == 0 => return full shortcuts (for e.g. writable icons)
405 ; 1 => return abbreviated shortcuts (for e.g. menus)
407 ; On exit: CS if key number was recognised, and
408 ; R0 == pointer to short cut string
412 ; Use: Translates a key number into a string suitable for
413 ; displaying to a user, and returns a pointer to the
420 STMFD R13!,{R1-R5,R14} ;Save some registers
422 ; --- Find the correct entry in the tables ---
424 CMP R0,#' ' ;Is it a control key?
425 ADRLT R2,kstr__lower ;Yes -- point to low table
426 ADDLT R2,R2,R0,LSL #1 ;And find the entry
427 BLT %10keyString ;Skip ahead after this
429 CMP R0,#&FF ;Is it in the upper half?
430 ADRGT R2,kstr__upper ;Yes -- point to high table
431 BICGT R0,R0,#&100 ;Chop off the top bit
432 ADDGT R2,R2,R0,LSL #1 ;And find the entry again
433 BGT %10keyString ;Skip ahead after this
435 CMP R0,#&7F ;Is it a delete?
436 ADREQ R2,kstr__delete ;Yes -- point to delete entry
437 LDMNEFD R13!,{R1-R5,PC}^ ;No -- return to caller
439 ; --- Load the entry from the table ---
441 10keyString AND R14,R2,#3 ;Get bottom two bits of R2
442 LDR R2,[R2,-R14] ;Load the word properly
443 MOV R14,R14,LSL #3 ;Get the correct shift value
444 MOV R2,R2,LSR R14 ;And shift R2 nicely
446 TST R2,#&FF ;Make sure bottom byte non-0
447 TSTEQ R2,#kstr__func ;Or is it a function key?
448 LDMEQFD R13!,{R1-R5,PC}^ ;Return to caller if neither
450 ; --- Find the base key name ---
452 TST R2,#kstr__func ;Is it really a function key?
453 BEQ %20keyString ;No -- skip this bit
454 AND R4,R2,#&ff ;Get the key byte out
455 CMP R4,#12 ;Is it F12?
456 LDMEQFD R13!,{R1-R5,PC}^ ;Yes -- always ignore F12
458 ADR R3,kstr__fkeys ;Point to key names table
459 LDR R0,[R3,R4,LSL #2] ;Get the correct entry out
460 CMP R0,#0 ;Is it a null pointer?
461 BLNE msgs_lookup ;No -- lookup message
462 BNE %30keyString ;And skip ahead nicely
464 ADR R0,kstr__fmsg ;Point to `kstrF:F%i2'
465 BL msgs_lookup ;Lookup the message
466 ADD R1,R11,#50 ;Point to scratchpad
467 BL str_subst ;And fill the string in
468 B %30keyString ;Now do the rest of it all
470 kstr__delete KENTRY &7F, 0,0,0,0 ;Dummy entry for delete
472 kstr__fkeys DCD kstr__print
485 kstr__fmsg DCB "kstrF",0
486 kstr__print DCB "kstrPRT",0
487 kstr__tab DCB "kstrTAB",0
488 kstr__copy DCB "kstrCOPY",0
489 kstr__left DCB "kstrLEFT",0
490 kstr__right DCB "kstrRIGHT",0
491 kstr__down DCB "kstrDOWN",0
492 kstr__up DCB "kstrUP",0
493 kstr__insert DCB "kstrINS",0
494 kstr__pageDown DCB "kstrPDN",0
495 kstr__pageUp DCB "kstrPUP",0
497 ; --- Handle strange keys in lower map ---
499 20keyString AND R4,R2,#&ff ;Get the key byte out
500 CMP R4,#key_Return ;Is it the return code?
501 BNE %21keyString ;No -- skip
502 TST R2,#kstr__keypad ;Is it on the keypad?
503 BNE %22keyString ;Yes -- handle it
505 21keyString CMP R4,#key_Delete ;Is it a delete key?
506 BEQ %23keyString ;Yes -- handle that too
507 CMP R4,#' ' ;Is it a space?
508 BEQ %24keyString ;Yes -- handle that too
509 SUB R14,R4,#&1B ;Is it a strange one?
510 CMP R14,#4 ;Is it one of the four?
511 BLO %25keyString ;Yes -- handle that
513 ADD R0,R11,#50 ;Point to spare bit of buffer
514 STRB R4,[R0,#0] ;Store character in buffer
515 MOV R3,#0 ;Terminate the string
516 STRB R3,[R0,#1] ;Store that in buffer too
517 B %30keyString ;Skip to final processing
519 ; --- Handle various special cases ---
521 22keyString BIC R2,R2,#kstr__keypad ;Yes -- remove keypad flag
522 ADR R0,kstr__enter ;Yes -- point to string
523 BL msgs_lookup ;Translate it as usual
524 B %30 ;We've got a base string
526 kstr__enter DCB "kstrENTER",0
528 23keyString ADR R0,kstr__delmsg ;Point to the string
529 BL msgs_lookup ;Translate it as usual
530 B %30 ;We've got a base string
532 kstr__delmsg DCB "kstrDEL",0
534 24keyString ADR R0,kstr__space ;Point to the string
535 BL msgs_lookup ;Translate it as usual
536 B %30 ;We've got a base string
538 kstr__space DCB "kstrSPC",0
540 25keyString ADR R0,kstr__lowtbl ;Point to the table
541 LDR R0,[R0,R14,LSL #2] ;Load the correct entry
542 BL msgs_lookup ;Translate it as usual
543 B %30 ;We've got a base string
545 kstr__lowtbl DCD kstr__escape
550 kstr__escape DCB "kstrESC",0
551 kstr__backspc DCB "kstrBSP",0
552 kstr__return DCB "kstrRET",0
553 kstr__home DCB "kstrHOME",0
555 ; --- Finally, handle modifier strings ---
557 30keyString MOV R5,R0 ;Keep pointer to base key
558 LDR R4,[R13,#0] ;Get shortcut style wanted
559 MOV R0,R11 ;Point to the scratchpad
561 TST R2,#kstr__shift ;Is shift held down?
562 MOVNE R1,#'
\8b' ;Yes -- short character
563 ADRNE R3,kstr__shmod ;And long message
564 BLNE %80keyString ;Sort everything out
566 TST R2,#kstr__ctrl ;Is shift held down?
567 MOVNE R1,#'^' ;Yes -- short character
568 ADRNE R3,kstr__ctmod ;And long message
569 BLNE %80keyString ;Sort everything out
571 TST R2,#kstr__keypad ;Is shift held down?
572 MOVNE R1,#'k' ;Yes -- short character
573 ADRNE R3,kstr__kpmod ;And long message
574 BLNE %80keyString ;Sort everything out
576 MOV R1,R5 ;Point to base string
577 BL str_cpy ;Copy the last string in
578 MOV R0,R11 ;Point to string in buffer
579 LDMFD R13!,{R1-R5,R14} ;Load the registers
580 ORRS PC,R14,#C_flag ;We handled it (eventually)
582 kstr__shmod DCB "kstrSH",0
583 kstr__ctmod DCB "kstrCTL",0
584 kstr__kpmod DCB "kstrKPD",0
586 ; --- Work out what a modifier should look like ---
588 80keyString CMP R4,#0 ;Do we want short mod chars?
589 STRNEB R1,[R0],#1 ;Yes -- store char nicely
590 MOVNES PC,R14 ;And return to caller
591 STMFD R13!,{R0,R14} ;Save some registers
592 MOV R0,R3 ;Point to message tag
593 BL msgs_lookup ;Translate the string
594 MOV R1,R0 ;Keep pointer to message
595 LDMFD R13!,{R0} ;Restore a register
596 BL str_cpy ;Attach string to end
597 LDMFD R13!,{PC}^ ;Return to caller
601 ;----- That's all, folks ----------------------------------------------------